connect(m_plotCurve
->axisWidget
(QwtPlot::xBottom),
&QwtScaleWidget
::scaleDivChanged,
this, &Waterfallplot::scaleDivChanged/*, Qt::QueuedConnection*/);
connect(m_plotSpectrogram
->axisWidget
(QwtPlot::xBottom),
&QwtScaleWidget
::scaleDivChanged,
this, &Waterfallplot::scaleDivChanged/*,Qt::QueuedConnection*/);
void Waterfallplot::scaleDivChanged()
{
// apparently, m_inScaleSync is a hack that can be replaced by
// blocking signals on a widget but that could be cumbersome
// or not possible as the Qwt API doesn't provide any mean to do that
if (m_inScaleSync)
{
return;
}
m_inScaleSync = true;
if (m_plotCurve
->axisWidget
(QwtPlot::xBottom) == sender
()) {
updatedPlot = m_plotCurve;
}
else if (m_plotSpectrogram
->axisWidget
(QwtPlot::xBottom) == sender
()) {
updatedPlot = m_plotSpectrogram;
}
else
{
updatedPlot = nullptr;
}
if (updatedPlot)
{
QwtPlot* plotToUpdate
= (updatedPlot
== m_plotCurve
) ? m_plotSpectrogram
: m_plotCurve;
plotToUpdate
->setAxisScaleDiv
(QwtPlot::xBottom,
updatedPlot
->axisScaleDiv
(QwtPlot::xBottom));
updateLayout();
}
m_inScaleSync = false;
}
void Waterfallplot::alignAxis(int axisId)
{
// 1. Align Vertical Axis (only left or right)
double maxExtent = 0;
{
sd->setMinimumExtent(0.0);
const double extent = sd->extent(scaleWidget->font());
if (extent > maxExtent)
{
maxExtent = extent;
}
}
{
sd->setMinimumExtent( 0.0 );
const double extent = sd->extent(scaleWidget->font());
if (extent > maxExtent)
{
maxExtent = extent;
}
}
{
scaleWidget->scaleDraw()->setMinimumExtent(maxExtent);
}
{
scaleWidget->scaleDraw()->setMinimumExtent(maxExtent);
}
}
void Waterfallplot::alignAxisForColorBar()
{
auto s1
= m_plotSpectrogram
->axisWidget
(QwtPlot::yRight);
auto s2
= m_plotCurve
->axisWidget
(QwtPlot::yRight);
s2->scaleDraw()->setMinimumExtent( 0.0 );
qreal extent = s1->scaleDraw()->extent(s1->font());
extent -= s2->scaleDraw()->extent(s2->font());
extent += s1->colorBarWidth() + s1->spacing();
s2->scaleDraw()->setMinimumExtent(extent);
}
void Waterfallplot::updateLayout()
{
// 1. Align Vertical Axis (only left or right)
alignAxisForColorBar();
// 2. Replot
m_plotCurve->replot();
m_plotSpectrogram->replot();
}
connect(m_plotCurve->axisWidget(QwtPlot::xBottom), &QwtScaleWidget::scaleDivChanged,
this, &Waterfallplot::scaleDivChanged/*, Qt::QueuedConnection*/);
connect(m_plotSpectrogram->axisWidget(QwtPlot::xBottom), &QwtScaleWidget::scaleDivChanged,
this, &Waterfallplot::scaleDivChanged/*,Qt::QueuedConnection*/);
void Waterfallplot::scaleDivChanged()
{
// apparently, m_inScaleSync is a hack that can be replaced by
// blocking signals on a widget but that could be cumbersome
// or not possible as the Qwt API doesn't provide any mean to do that
if (m_inScaleSync)
{
return;
}
m_inScaleSync = true;
QwtPlot* updatedPlot;
if (m_plotCurve->axisWidget(QwtPlot::xBottom) == sender())
{
updatedPlot = m_plotCurve;
}
else if (m_plotSpectrogram->axisWidget(QwtPlot::xBottom) == sender())
{
updatedPlot = m_plotSpectrogram;
}
else
{
updatedPlot = nullptr;
}
if (updatedPlot)
{
QwtPlot* plotToUpdate = (updatedPlot == m_plotCurve) ? m_plotSpectrogram : m_plotCurve;
plotToUpdate->setAxisScaleDiv(QwtPlot::xBottom,
updatedPlot->axisScaleDiv(QwtPlot::xBottom));
updateLayout();
}
m_inScaleSync = false;
}
void Waterfallplot::alignAxis(int axisId)
{
// 1. Align Vertical Axis (only left or right)
double maxExtent = 0;
{
QwtScaleWidget* scaleWidget = m_plotCurve->axisWidget(axisId);
QwtScaleDraw* sd = scaleWidget->scaleDraw();
sd->setMinimumExtent(0.0);
const double extent = sd->extent(scaleWidget->font());
if (extent > maxExtent)
{
maxExtent = extent;
}
}
{
QwtScaleWidget* scaleWidget = m_plotSpectrogram->axisWidget(axisId);
QwtScaleDraw* sd = scaleWidget->scaleDraw();
sd->setMinimumExtent( 0.0 );
const double extent = sd->extent(scaleWidget->font());
if (extent > maxExtent)
{
maxExtent = extent;
}
}
{
QwtScaleWidget* scaleWidget = m_plotCurve->axisWidget(axisId);
scaleWidget->scaleDraw()->setMinimumExtent(maxExtent);
}
{
QwtScaleWidget* scaleWidget = m_plotSpectrogram->axisWidget(axisId);
scaleWidget->scaleDraw()->setMinimumExtent(maxExtent);
}
}
void Waterfallplot::alignAxisForColorBar()
{
auto s1 = m_plotSpectrogram->axisWidget(QwtPlot::yRight);
auto s2 = m_plotCurve->axisWidget(QwtPlot::yRight);
s2->scaleDraw()->setMinimumExtent( 0.0 );
qreal extent = s1->scaleDraw()->extent(s1->font());
extent -= s2->scaleDraw()->extent(s2->font());
extent += s1->colorBarWidth() + s1->spacing();
s2->scaleDraw()->setMinimumExtent(extent);
}
void Waterfallplot::updateLayout()
{
// 1. Align Vertical Axis (only left or right)
alignAxis(QwtPlot::yLeft);
alignAxisForColorBar();
// 2. Replot
m_plotCurve->replot();
m_plotSpectrogram->replot();
}
To copy to clipboard, switch view to plain text mode
Bookmarks