diff --git a/GUI/coregui/Views/CommonWidgets/UpdateTimer.cpp b/GUI/coregui/Views/CommonWidgets/UpdateTimer.cpp index a157683989d2b2adcfc4f7751a64cf246f9fa24c..7143a6fc6b5fd1287e19230440da58e1903f689b 100644 --- a/GUI/coregui/Views/CommonWidgets/UpdateTimer.cpp +++ b/GUI/coregui/Views/CommonWidgets/UpdateTimer.cpp @@ -16,9 +16,10 @@ #include "UpdateTimer.h" #include <QTimer> +#include <QDebug> namespace { -const int default_timer_interval_in_msec = 10; +const int default_timer_interval_in_msec = 2; } UpdateTimer::UpdateTimer(int accumulateDuring, QObject *parent) @@ -35,19 +36,51 @@ UpdateTimer::UpdateTimer(int accumulateDuring, QObject *parent) } -//! Sets the time interval in msec, during which updates will be accumulated. +//! Sets time period in msec, during which updates will be accumulated. void UpdateTimer::setAccumulateDuring(int accumulateDuring) { m_accumulate_updates_during = accumulateDuring; } +//! Sets timer interval in msec to check if it is time to propagate update requests back. + +void UpdateTimer::setTimerInterval(int timerInterval) +{ + m_timer_interval = timerInterval; +} + +//! Schedule subsequent update. + +#include <iostream> +void UpdateTimer::scheduleUpdate() +{ + ++m_update_request_count; + qDebug() << "TTT scheduleUpdate() m_update_request_count" + << m_update_request_count + << "m_remaining_time_to_update" << m_remaining_time_to_update; + + std::cout << "TTT scheduleUpdate() m_update_request_count" + << m_update_request_count + << "m_remaining_time_to_update" << m_remaining_time_to_update + << "XXX" << m_timer_interval << std::endl; + + if(!m_timer->isActive()) { + m_timer->start(m_timer_interval); + m_remaining_time_to_update = m_accumulate_updates_during; + qDebug() << " TTT scheduleUpdate() -- starting --- m_remaining_time_to_update" << m_remaining_time_to_update; + } +} + + void UpdateTimer::onTimerTimeout() { m_remaining_time_to_update -= m_timer_interval; + qDebug() << " TTT onTimerTimeout() m_remaining_time_to_update" << m_remaining_time_to_update; - if(m_remaining_time_to_update < 0) { + if(m_remaining_time_to_update <= 0) { m_timer->stop(); + qDebug() << " TTT onTimerTimeout() -- stopping -- m_remaining_time_to_update" << m_remaining_time_to_update; processUpdates(); } @@ -57,10 +90,13 @@ void UpdateTimer::processUpdates() { Q_ASSERT(!m_timer->isActive()); + qDebug() << " TTT processUpdates() m_update_request_count" << m_update_request_count; + std::cout << " TTT processUpdates() m_update_request_count" << m_update_request_count << std::endl; + if(m_update_request_count > 0) { + qDebug() << " TTT processUpdates() --- emiting"; emit timeToUpdate(); } - m_remaining_time_to_update = m_accumulate_updates_during; m_update_request_count = 0; } diff --git a/GUI/coregui/Views/CommonWidgets/UpdateTimer.h b/GUI/coregui/Views/CommonWidgets/UpdateTimer.h index c24162163559b7d9e7a17c7402bb49ded7491387..de678c7088129d090fdf07fac026b1de11f10674 100644 --- a/GUI/coregui/Views/CommonWidgets/UpdateTimer.h +++ b/GUI/coregui/Views/CommonWidgets/UpdateTimer.h @@ -34,11 +34,14 @@ public: explicit UpdateTimer(int accumulateDuring, QObject *parent = 0); void setAccumulateDuring(int accumulateDuring); - + void setTimerInterval(int timerInterval); signals: void timeToUpdate(); +public slots: + void scheduleUpdate(); + private slots: void onTimerTimeout(); @@ -54,11 +57,10 @@ private: //!< Timer interval to check what is going on. int m_timer_interval; - //!< Remaining time to + //!< Remaining time to to emit timeToUpdate signal int m_remaining_time_to_update; QTimer *m_timer; }; - #endif diff --git a/GUI/coregui/Views/IntensityDataWidgets/ColorMapPlot.cpp b/GUI/coregui/Views/IntensityDataWidgets/ColorMapPlot.cpp index 527e2432c4e5e722cd470c6366411b9676744302..51b768dcb660e8df600588a702d5143d3f04ba3a 100644 --- a/GUI/coregui/Views/IntensityDataWidgets/ColorMapPlot.cpp +++ b/GUI/coregui/Views/IntensityDataWidgets/ColorMapPlot.cpp @@ -19,12 +19,22 @@ #include "IntensityDataItem.h" #include "AxesItems.h" #include "GUIHelpers.h" +#include "UpdateTimer.h" #include "Units.h" #include <QDebug> +namespace { +const int replot_update_interval = 10; +} + ColorMapPlot::ColorMapPlot(QWidget *parent) - : QWidget(parent), m_customPlot(0), m_colorMap(0), m_colorScale(0), m_item(0), - m_block_update(true) + : QWidget(parent) + , m_customPlot(0) + , m_colorMap(0) + , m_colorScale(0) + , m_item(0) + , m_block_update(true) + , m_updateTimer(new UpdateTimer(replot_update_interval, this)) { initColorMap(); @@ -82,6 +92,7 @@ void ColorMapPlot::setItem(IntensityDataItem *item) m_item = 0; }, this); + setConnected(true); } @@ -135,7 +146,7 @@ void ColorMapPlot::drawLinesOverTheMap() } m_customPlot->graph(1)->setData(x2, y2); - m_customPlot->replot(); + replot(); } //! switches visibility of two crossed lines @@ -144,7 +155,7 @@ void ColorMapPlot::showLinesOverTheMap(bool isVisible) if (m_customPlot->graph(0) && m_customPlot->graph(1)) { m_customPlot->graph(0)->setVisible(isVisible); m_customPlot->graph(1)->setVisible(isVisible); - m_customPlot->replot(); + replot(); } } @@ -214,7 +225,7 @@ void ColorMapPlot::resetView() if(!m_item->isZAxisLocked()) { m_colorMap->setDataRange(ColorMapHelper::itemDataRange(m_item)); } - m_customPlot->replot(); + replot(); m_block_update = false; } @@ -297,7 +308,7 @@ void ColorMapPlot::onIntensityModified() { qDebug() << "ColorMapPlot::onIntensityModified()"; setDataFromItem(m_item); - m_customPlot->replot(); + replot(); } //! updates color map depending on IntensityDataItem properties @@ -308,10 +319,10 @@ void ColorMapPlot::onPropertyChanged(const QString &property_name) if (property_name == IntensityDataItem::P_GRADIENT) { m_colorMap->setGradient(ColorMapHelper::itemGradient(m_item)); - m_customPlot->replot(); + replot(); } else if (property_name == IntensityDataItem::P_IS_INTERPOLATED) { m_colorMap->setInterpolate(m_item->isInterpolated()); - m_customPlot->replot(); + replot(); } else if (property_name == IntensityDataItem::P_PROJECTIONS_FLAG) { showLinesOverTheMap( m_item->getItemValue(IntensityDataItem::P_PROJECTIONS_FLAG).toBool()); @@ -334,30 +345,30 @@ void ColorMapPlot::onSubItemPropertyChanged(const QString &property_group, QCPRange range = m_customPlot->xAxis->range(); range.lower = m_item->getLowerX(); m_customPlot->xAxis->setRange(range); - m_customPlot->replot(); + replot(); } else if (property_name == BasicAxisItem::P_MAX) { QCPRange range = m_customPlot->xAxis->range(); range.upper = m_item->getUpperX(); m_customPlot->xAxis->setRange(range); - m_customPlot->replot(); + replot(); } else if (property_name == BasicAxisItem::P_TITLE) { m_customPlot->xAxis->setLabel(m_item->getXaxisTitle()); - m_customPlot->replot(); + replot(); } } else if (property_group == IntensityDataItem::P_YAXIS) { if (property_name == BasicAxisItem::P_MIN) { QCPRange range = m_customPlot->yAxis->range(); range.lower = m_item->getLowerY(); m_customPlot->yAxis->setRange(range); - m_customPlot->replot(); + replot(); } else if (property_name == BasicAxisItem::P_MAX) { QCPRange range = m_customPlot->yAxis->range(); range.upper = m_item->getUpperY(); m_customPlot->yAxis->setRange(range); - m_customPlot->replot(); + replot(); } else if (property_name == BasicAxisItem::P_TITLE) { m_customPlot->yAxis->setLabel(m_item->getYaxisTitle()); - m_customPlot->replot(); + replot(); } } @@ -377,16 +388,16 @@ void ColorMapPlot::onSubItemPropertyChanged(const QString &property_group, if (zmax != range.upper) { range.upper = zmax; m_colorMap->setDataRange(range); - m_customPlot->replot(); + replot(); } } else if (property_name == AmplitudeAxisItem::P_IS_LOGSCALE) { setLogz(m_item->isLogz()); - m_customPlot->replot(); + replot(); } else if (property_name == BasicAxisItem::P_IS_VISIBLE) { setColorScaleVisible(m_item->getItem(IntensityDataItem::P_ZAXIS) ->getItemValue(BasicAxisItem::P_IS_VISIBLE).toBool()); - m_customPlot->replot(); + replot(); } } } @@ -394,6 +405,7 @@ void ColorMapPlot::onSubItemPropertyChanged(const QString &property_group, //! Propagate zmin, zmax back to IntensityDataItem void ColorMapPlot::onDataRangeChanged(QCPRange newRange) { + qDebug() << "ColorMapPlot::onDataRangeChanged"; m_block_update = true; m_item->setLowerAndUpperZ(newRange.lower, newRange.upper); m_block_update = false; @@ -417,6 +429,22 @@ void ColorMapPlot::onYaxisRangeChanged(QCPRange newRange) m_block_update = false; } +//! Schedule replot for later execution. + +void ColorMapPlot::replot() +{ + m_updateTimer->scheduleUpdate(); +// m_customPlot->replot(); +} + +//! Replots ColorMap. + +void ColorMapPlot::onTimeToReplot() +{ + qDebug() << "ColorMapPlot::onTimeToReplot()"; + m_customPlot->replot(); +} + //! creates and initializes the color map void ColorMapPlot::initColorMap() { @@ -443,7 +471,7 @@ void ColorMapPlot::initColorMap() m_customPlot->addGraph(); m_customPlot->graph(1)->setPen(pen); - setConnected(true); + //setConnected(true); } @@ -452,6 +480,7 @@ void ColorMapPlot::setConnected(bool isConnected) setAxesRangeConnected(isConnected); setDataRangeConnected(isConnected); setMouseMoveConnected(isConnected); + setUpdateTimerConnected(isConnected); } //! Connects/disconnects signals related to ColorMap's X,Y axes rectangle change. @@ -501,6 +530,17 @@ void ColorMapPlot::setMouseMoveConnected(bool isConnected) } } +void ColorMapPlot::setUpdateTimerConnected(bool isConnected) +{ + if(isConnected) { + connect(m_updateTimer, SIGNAL(timeToUpdate()), + this, SLOT(onTimeToReplot()), Qt::UniqueConnection); + } else { + disconnect(m_updateTimer, SIGNAL(timeToUpdate()), + this, SLOT(onTimeToReplot())); + } +} + //! to make fixed margins for whole colormap (change in axes labels wont affect axes rectangle) void ColorMapPlot::setFixedColorMapMargins() diff --git a/GUI/coregui/Views/IntensityDataWidgets/ColorMapPlot.h b/GUI/coregui/Views/IntensityDataWidgets/ColorMapPlot.h index fb6ddbc70bf07a52a75dfcca586938627dae7da6..c473e29f9f8d1f9fc0dd23ba0457610e92c54fad 100644 --- a/GUI/coregui/Views/IntensityDataWidgets/ColorMapPlot.h +++ b/GUI/coregui/Views/IntensityDataWidgets/ColorMapPlot.h @@ -28,6 +28,7 @@ class IntensityDataItem; class QCustomPlot; class QCPColorMap; class QCPColorScale; +class UpdateTimer; //! 2D color map widget for IntensityData class BA_CORE_API_ ColorMapPlot : public QWidget @@ -81,6 +82,8 @@ private slots: void onDataRangeChanged(QCPRange newRange); void onXaxisRangeChanged(QCPRange newRange); void onYaxisRangeChanged(QCPRange newRange); + void replot(); + void onTimeToReplot(); private: @@ -109,6 +112,7 @@ private: void setAxesRangeConnected(bool isConnected); void setDataRangeConnected(bool isConnected); void setMouseMoveConnected(bool isConnected); + void setUpdateTimerConnected(bool isConnected); void setFixedColorMapMargins(); @@ -132,6 +136,8 @@ private: bool m_block_update; PositionData m_posData; + + UpdateTimer *m_updateTimer; };