Skip to content
Snippets Groups Projects
Commit a8f7e12e authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

UpdateTimer plugged in finally to ColorMapPlot.

parent 39255dea
No related branches found
No related tags found
No related merge requests found
...@@ -16,9 +16,10 @@ ...@@ -16,9 +16,10 @@
#include "UpdateTimer.h" #include "UpdateTimer.h"
#include <QTimer> #include <QTimer>
#include <QDebug>
namespace { namespace {
const int default_timer_interval_in_msec = 10; const int default_timer_interval_in_msec = 2;
} }
UpdateTimer::UpdateTimer(int accumulateDuring, QObject *parent) UpdateTimer::UpdateTimer(int accumulateDuring, QObject *parent)
...@@ -35,19 +36,51 @@ 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) void UpdateTimer::setAccumulateDuring(int accumulateDuring)
{ {
m_accumulate_updates_during = 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() void UpdateTimer::onTimerTimeout()
{ {
m_remaining_time_to_update -= m_timer_interval; 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(); m_timer->stop();
qDebug() << " TTT onTimerTimeout() -- stopping -- m_remaining_time_to_update" << m_remaining_time_to_update;
processUpdates(); processUpdates();
} }
...@@ -57,10 +90,13 @@ void UpdateTimer::processUpdates() ...@@ -57,10 +90,13 @@ void UpdateTimer::processUpdates()
{ {
Q_ASSERT(!m_timer->isActive()); 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) { if(m_update_request_count > 0) {
qDebug() << " TTT processUpdates() --- emiting";
emit timeToUpdate(); emit timeToUpdate();
} }
m_remaining_time_to_update = m_accumulate_updates_during;
m_update_request_count = 0; m_update_request_count = 0;
} }
...@@ -34,11 +34,14 @@ public: ...@@ -34,11 +34,14 @@ public:
explicit UpdateTimer(int accumulateDuring, QObject *parent = 0); explicit UpdateTimer(int accumulateDuring, QObject *parent = 0);
void setAccumulateDuring(int accumulateDuring); void setAccumulateDuring(int accumulateDuring);
void setTimerInterval(int timerInterval);
signals: signals:
void timeToUpdate(); void timeToUpdate();
public slots:
void scheduleUpdate();
private slots: private slots:
void onTimerTimeout(); void onTimerTimeout();
...@@ -54,11 +57,10 @@ private: ...@@ -54,11 +57,10 @@ private:
//!< Timer interval to check what is going on. //!< Timer interval to check what is going on.
int m_timer_interval; int m_timer_interval;
//!< Remaining time to //!< Remaining time to to emit timeToUpdate signal
int m_remaining_time_to_update; int m_remaining_time_to_update;
QTimer *m_timer; QTimer *m_timer;
}; };
#endif #endif
...@@ -19,12 +19,22 @@ ...@@ -19,12 +19,22 @@
#include "IntensityDataItem.h" #include "IntensityDataItem.h"
#include "AxesItems.h" #include "AxesItems.h"
#include "GUIHelpers.h" #include "GUIHelpers.h"
#include "UpdateTimer.h"
#include "Units.h" #include "Units.h"
#include <QDebug> #include <QDebug>
namespace {
const int replot_update_interval = 10;
}
ColorMapPlot::ColorMapPlot(QWidget *parent) ColorMapPlot::ColorMapPlot(QWidget *parent)
: QWidget(parent), m_customPlot(0), m_colorMap(0), m_colorScale(0), m_item(0), : QWidget(parent)
m_block_update(true) , 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(); initColorMap();
...@@ -82,6 +92,7 @@ void ColorMapPlot::setItem(IntensityDataItem *item) ...@@ -82,6 +92,7 @@ void ColorMapPlot::setItem(IntensityDataItem *item)
m_item = 0; m_item = 0;
}, this); }, this);
setConnected(true);
} }
...@@ -135,7 +146,7 @@ void ColorMapPlot::drawLinesOverTheMap() ...@@ -135,7 +146,7 @@ void ColorMapPlot::drawLinesOverTheMap()
} }
m_customPlot->graph(1)->setData(x2, y2); m_customPlot->graph(1)->setData(x2, y2);
m_customPlot->replot(); replot();
} }
//! switches visibility of two crossed lines //! switches visibility of two crossed lines
...@@ -144,7 +155,7 @@ void ColorMapPlot::showLinesOverTheMap(bool isVisible) ...@@ -144,7 +155,7 @@ void ColorMapPlot::showLinesOverTheMap(bool isVisible)
if (m_customPlot->graph(0) && m_customPlot->graph(1)) { if (m_customPlot->graph(0) && m_customPlot->graph(1)) {
m_customPlot->graph(0)->setVisible(isVisible); m_customPlot->graph(0)->setVisible(isVisible);
m_customPlot->graph(1)->setVisible(isVisible); m_customPlot->graph(1)->setVisible(isVisible);
m_customPlot->replot(); replot();
} }
} }
...@@ -214,7 +225,7 @@ void ColorMapPlot::resetView() ...@@ -214,7 +225,7 @@ void ColorMapPlot::resetView()
if(!m_item->isZAxisLocked()) { if(!m_item->isZAxisLocked()) {
m_colorMap->setDataRange(ColorMapHelper::itemDataRange(m_item)); m_colorMap->setDataRange(ColorMapHelper::itemDataRange(m_item));
} }
m_customPlot->replot(); replot();
m_block_update = false; m_block_update = false;
} }
...@@ -297,7 +308,7 @@ void ColorMapPlot::onIntensityModified() ...@@ -297,7 +308,7 @@ void ColorMapPlot::onIntensityModified()
{ {
qDebug() << "ColorMapPlot::onIntensityModified()"; qDebug() << "ColorMapPlot::onIntensityModified()";
setDataFromItem(m_item); setDataFromItem(m_item);
m_customPlot->replot(); replot();
} }
//! updates color map depending on IntensityDataItem properties //! updates color map depending on IntensityDataItem properties
...@@ -308,10 +319,10 @@ void ColorMapPlot::onPropertyChanged(const QString &property_name) ...@@ -308,10 +319,10 @@ void ColorMapPlot::onPropertyChanged(const QString &property_name)
if (property_name == IntensityDataItem::P_GRADIENT) { if (property_name == IntensityDataItem::P_GRADIENT) {
m_colorMap->setGradient(ColorMapHelper::itemGradient(m_item)); m_colorMap->setGradient(ColorMapHelper::itemGradient(m_item));
m_customPlot->replot(); replot();
} else if (property_name == IntensityDataItem::P_IS_INTERPOLATED) { } else if (property_name == IntensityDataItem::P_IS_INTERPOLATED) {
m_colorMap->setInterpolate(m_item->isInterpolated()); m_colorMap->setInterpolate(m_item->isInterpolated());
m_customPlot->replot(); replot();
} else if (property_name == IntensityDataItem::P_PROJECTIONS_FLAG) { } else if (property_name == IntensityDataItem::P_PROJECTIONS_FLAG) {
showLinesOverTheMap( showLinesOverTheMap(
m_item->getItemValue(IntensityDataItem::P_PROJECTIONS_FLAG).toBool()); m_item->getItemValue(IntensityDataItem::P_PROJECTIONS_FLAG).toBool());
...@@ -334,30 +345,30 @@ void ColorMapPlot::onSubItemPropertyChanged(const QString &property_group, ...@@ -334,30 +345,30 @@ void ColorMapPlot::onSubItemPropertyChanged(const QString &property_group,
QCPRange range = m_customPlot->xAxis->range(); QCPRange range = m_customPlot->xAxis->range();
range.lower = m_item->getLowerX(); range.lower = m_item->getLowerX();
m_customPlot->xAxis->setRange(range); m_customPlot->xAxis->setRange(range);
m_customPlot->replot(); replot();
} else if (property_name == BasicAxisItem::P_MAX) { } else if (property_name == BasicAxisItem::P_MAX) {
QCPRange range = m_customPlot->xAxis->range(); QCPRange range = m_customPlot->xAxis->range();
range.upper = m_item->getUpperX(); range.upper = m_item->getUpperX();
m_customPlot->xAxis->setRange(range); m_customPlot->xAxis->setRange(range);
m_customPlot->replot(); replot();
} else if (property_name == BasicAxisItem::P_TITLE) { } else if (property_name == BasicAxisItem::P_TITLE) {
m_customPlot->xAxis->setLabel(m_item->getXaxisTitle()); m_customPlot->xAxis->setLabel(m_item->getXaxisTitle());
m_customPlot->replot(); replot();
} }
} else if (property_group == IntensityDataItem::P_YAXIS) { } else if (property_group == IntensityDataItem::P_YAXIS) {
if (property_name == BasicAxisItem::P_MIN) { if (property_name == BasicAxisItem::P_MIN) {
QCPRange range = m_customPlot->yAxis->range(); QCPRange range = m_customPlot->yAxis->range();
range.lower = m_item->getLowerY(); range.lower = m_item->getLowerY();
m_customPlot->yAxis->setRange(range); m_customPlot->yAxis->setRange(range);
m_customPlot->replot(); replot();
} else if (property_name == BasicAxisItem::P_MAX) { } else if (property_name == BasicAxisItem::P_MAX) {
QCPRange range = m_customPlot->yAxis->range(); QCPRange range = m_customPlot->yAxis->range();
range.upper = m_item->getUpperY(); range.upper = m_item->getUpperY();
m_customPlot->yAxis->setRange(range); m_customPlot->yAxis->setRange(range);
m_customPlot->replot(); replot();
} else if (property_name == BasicAxisItem::P_TITLE) { } else if (property_name == BasicAxisItem::P_TITLE) {
m_customPlot->yAxis->setLabel(m_item->getYaxisTitle()); m_customPlot->yAxis->setLabel(m_item->getYaxisTitle());
m_customPlot->replot(); replot();
} }
} }
...@@ -377,16 +388,16 @@ void ColorMapPlot::onSubItemPropertyChanged(const QString &property_group, ...@@ -377,16 +388,16 @@ void ColorMapPlot::onSubItemPropertyChanged(const QString &property_group,
if (zmax != range.upper) { if (zmax != range.upper) {
range.upper = zmax; range.upper = zmax;
m_colorMap->setDataRange(range); m_colorMap->setDataRange(range);
m_customPlot->replot(); replot();
} }
} else if (property_name == AmplitudeAxisItem::P_IS_LOGSCALE) { } else if (property_name == AmplitudeAxisItem::P_IS_LOGSCALE) {
setLogz(m_item->isLogz()); setLogz(m_item->isLogz());
m_customPlot->replot(); replot();
} else if (property_name == BasicAxisItem::P_IS_VISIBLE) { } else if (property_name == BasicAxisItem::P_IS_VISIBLE) {
setColorScaleVisible(m_item->getItem(IntensityDataItem::P_ZAXIS) setColorScaleVisible(m_item->getItem(IntensityDataItem::P_ZAXIS)
->getItemValue(BasicAxisItem::P_IS_VISIBLE).toBool()); ->getItemValue(BasicAxisItem::P_IS_VISIBLE).toBool());
m_customPlot->replot(); replot();
} }
} }
} }
...@@ -394,6 +405,7 @@ void ColorMapPlot::onSubItemPropertyChanged(const QString &property_group, ...@@ -394,6 +405,7 @@ void ColorMapPlot::onSubItemPropertyChanged(const QString &property_group,
//! Propagate zmin, zmax back to IntensityDataItem //! Propagate zmin, zmax back to IntensityDataItem
void ColorMapPlot::onDataRangeChanged(QCPRange newRange) void ColorMapPlot::onDataRangeChanged(QCPRange newRange)
{ {
qDebug() << "ColorMapPlot::onDataRangeChanged";
m_block_update = true; m_block_update = true;
m_item->setLowerAndUpperZ(newRange.lower, newRange.upper); m_item->setLowerAndUpperZ(newRange.lower, newRange.upper);
m_block_update = false; m_block_update = false;
...@@ -417,6 +429,22 @@ void ColorMapPlot::onYaxisRangeChanged(QCPRange newRange) ...@@ -417,6 +429,22 @@ void ColorMapPlot::onYaxisRangeChanged(QCPRange newRange)
m_block_update = false; 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 //! creates and initializes the color map
void ColorMapPlot::initColorMap() void ColorMapPlot::initColorMap()
{ {
...@@ -443,7 +471,7 @@ void ColorMapPlot::initColorMap() ...@@ -443,7 +471,7 @@ void ColorMapPlot::initColorMap()
m_customPlot->addGraph(); m_customPlot->addGraph();
m_customPlot->graph(1)->setPen(pen); m_customPlot->graph(1)->setPen(pen);
setConnected(true); //setConnected(true);
} }
...@@ -452,6 +480,7 @@ void ColorMapPlot::setConnected(bool isConnected) ...@@ -452,6 +480,7 @@ void ColorMapPlot::setConnected(bool isConnected)
setAxesRangeConnected(isConnected); setAxesRangeConnected(isConnected);
setDataRangeConnected(isConnected); setDataRangeConnected(isConnected);
setMouseMoveConnected(isConnected); setMouseMoveConnected(isConnected);
setUpdateTimerConnected(isConnected);
} }
//! Connects/disconnects signals related to ColorMap's X,Y axes rectangle change. //! Connects/disconnects signals related to ColorMap's X,Y axes rectangle change.
...@@ -501,6 +530,17 @@ void ColorMapPlot::setMouseMoveConnected(bool isConnected) ...@@ -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) //! to make fixed margins for whole colormap (change in axes labels wont affect axes rectangle)
void ColorMapPlot::setFixedColorMapMargins() void ColorMapPlot::setFixedColorMapMargins()
......
...@@ -28,6 +28,7 @@ class IntensityDataItem; ...@@ -28,6 +28,7 @@ class IntensityDataItem;
class QCustomPlot; class QCustomPlot;
class QCPColorMap; class QCPColorMap;
class QCPColorScale; class QCPColorScale;
class UpdateTimer;
//! 2D color map widget for IntensityData //! 2D color map widget for IntensityData
class BA_CORE_API_ ColorMapPlot : public QWidget class BA_CORE_API_ ColorMapPlot : public QWidget
...@@ -81,6 +82,8 @@ private slots: ...@@ -81,6 +82,8 @@ private slots:
void onDataRangeChanged(QCPRange newRange); void onDataRangeChanged(QCPRange newRange);
void onXaxisRangeChanged(QCPRange newRange); void onXaxisRangeChanged(QCPRange newRange);
void onYaxisRangeChanged(QCPRange newRange); void onYaxisRangeChanged(QCPRange newRange);
void replot();
void onTimeToReplot();
private: private:
...@@ -109,6 +112,7 @@ private: ...@@ -109,6 +112,7 @@ private:
void setAxesRangeConnected(bool isConnected); void setAxesRangeConnected(bool isConnected);
void setDataRangeConnected(bool isConnected); void setDataRangeConnected(bool isConnected);
void setMouseMoveConnected(bool isConnected); void setMouseMoveConnected(bool isConnected);
void setUpdateTimerConnected(bool isConnected);
void setFixedColorMapMargins(); void setFixedColorMapMargins();
...@@ -132,6 +136,8 @@ private: ...@@ -132,6 +136,8 @@ private:
bool m_block_update; bool m_block_update;
PositionData m_posData; PositionData m_posData;
UpdateTimer *m_updateTimer;
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment