##// END OF EJS Templates
Removed unused log
perrinel -
r316:42fd44da8641
parent child
Show More
@@ -1,157 +1,157
1 #include "Visualization/VisualizationGraphHelper.h"
1 #include "Visualization/VisualizationGraphHelper.h"
2 #include "Visualization/qcustomplot.h"
2 #include "Visualization/qcustomplot.h"
3
3
4 #include <Data/ScalarSeries.h>
4 #include <Data/ScalarSeries.h>
5
5
6 #include <Variable/Variable.h>
6 #include <Variable/Variable.h>
7
7
8 #include <QElapsedTimer>
8 #include <QElapsedTimer>
9
9
10 Q_LOGGING_CATEGORY(LOG_VisualizationGraphHelper, "VisualizationGraphHelper")
10 Q_LOGGING_CATEGORY(LOG_VisualizationGraphHelper, "VisualizationGraphHelper")
11
11
12 namespace {
12 namespace {
13
13
14 /// Format for datetimes on a axis
14 /// Format for datetimes on a axis
15 const auto DATETIME_TICKER_FORMAT = QStringLiteral("yyyy/MM/dd \nhh:mm:ss");
15 const auto DATETIME_TICKER_FORMAT = QStringLiteral("yyyy/MM/dd \nhh:mm:ss");
16
16
17 /// Generates the appropriate ticker for an axis, depending on whether the axis displays time or
17 /// Generates the appropriate ticker for an axis, depending on whether the axis displays time or
18 /// non-time data
18 /// non-time data
19 QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis)
19 QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis)
20 {
20 {
21 if (isTimeAxis) {
21 if (isTimeAxis) {
22 auto dateTicker = QSharedPointer<QCPAxisTickerDateTime>::create();
22 auto dateTicker = QSharedPointer<QCPAxisTickerDateTime>::create();
23 dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT);
23 dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT);
24
24
25 return dateTicker;
25 return dateTicker;
26 }
26 }
27 else {
27 else {
28 // default ticker
28 // default ticker
29 return QSharedPointer<QCPAxisTicker>::create();
29 return QSharedPointer<QCPAxisTicker>::create();
30 }
30 }
31 }
31 }
32
32
33 void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSeries,
33 void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSeries,
34 const SqpDateTime &dateTime)
34 const SqpDateTime &dateTime)
35 {
35 {
36 QElapsedTimer timer;
36 QElapsedTimer timer;
37 timer.start();
37 timer.start();
38 if (auto qcpGraph = dynamic_cast<QCPGraph *>(component)) {
38 if (auto qcpGraph = dynamic_cast<QCPGraph *>(component)) {
39 // Clean the graph
39 // Clean the graph
40 // NAIVE approch
40 // NAIVE approch
41 const auto &xData = scalarSeries.xAxisData()->data();
41 const auto &xData = scalarSeries.xAxisData()->data();
42 const auto &valuesData = scalarSeries.valuesData()->data();
42 const auto &valuesData = scalarSeries.valuesData()->data();
43 const auto count = xData.count();
43 const auto count = xData.count();
44 qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points in cache" << xData.count();
44 qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points in cache" << xData.count();
45
45
46 auto xValue = QVector<double>(count);
46 auto xValue = QVector<double>(count);
47 auto vValue = QVector<double>(count);
47 auto vValue = QVector<double>(count);
48
48
49 int n = 0;
49 int n = 0;
50 for (auto i = 0; i < count; ++i) {
50 for (auto i = 0; i < count; ++i) {
51 const auto x = xData[i];
51 const auto x = xData[i];
52 if (x >= dateTime.m_TStart && x <= dateTime.m_TEnd) {
52 if (x >= dateTime.m_TStart && x <= dateTime.m_TEnd) {
53 xValue[n] = x;
53 xValue[n] = x;
54 vValue[n] = valuesData[i];
54 vValue[n] = valuesData[i];
55 ++n;
55 ++n;
56 }
56 }
57 }
57 }
58
58
59 xValue.resize(n);
59 xValue.resize(n);
60 vValue.resize(n);
60 vValue.resize(n);
61
61
62 qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points displayed" << xValue.count()
62 qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points displayed"
63 << dateTime;
63 << xValue.count();
64
64
65 qcpGraph->setData(xValue, vValue);
65 qcpGraph->setData(xValue, vValue);
66
66
67 // Display all data
67 // Display all data
68 // component->parentPlot()->xAxis->setRange(dateTime.m_TStart, dateTime.m_TEnd);
68 // component->parentPlot()->xAxis->setRange(dateTime.m_TStart, dateTime.m_TEnd);
69 component->rescaleAxes();
69 component->rescaleAxes();
70 component->parentPlot()->replot();
70 component->parentPlot()->replot();
71 }
71 }
72 else {
72 else {
73 /// @todo DEBUG
73 /// @todo DEBUG
74 }
74 }
75 }
75 }
76
76
77 QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot,
77 QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot,
78 const SqpDateTime &dateTime)
78 const SqpDateTime &dateTime)
79 {
79 {
80 auto component = plot.addGraph();
80 auto component = plot.addGraph();
81
81
82 if (component) {
82 if (component) {
83 // // Graph data
83 // // Graph data
84 component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(),
84 component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(),
85 true);
85 true);
86
86
87 updateScalarData(component, scalarSeries, dateTime);
87 updateScalarData(component, scalarSeries, dateTime);
88
88
89 // Axes properties
89 // Axes properties
90 /// @todo : for the moment, no control is performed on the axes: the units and the tickers
90 /// @todo : for the moment, no control is performed on the axes: the units and the tickers
91 /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph
91 /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph
92
92
93 auto setAxisProperties = [](auto axis, const auto &unit) {
93 auto setAxisProperties = [](auto axis, const auto &unit) {
94 // label (unit name)
94 // label (unit name)
95 axis->setLabel(unit.m_Name);
95 axis->setLabel(unit.m_Name);
96
96
97 // ticker (depending on the type of unit)
97 // ticker (depending on the type of unit)
98 axis->setTicker(axisTicker(unit.m_TimeUnit));
98 axis->setTicker(axisTicker(unit.m_TimeUnit));
99 };
99 };
100 setAxisProperties(plot.xAxis, scalarSeries.xAxisUnit());
100 setAxisProperties(plot.xAxis, scalarSeries.xAxisUnit());
101 setAxisProperties(plot.yAxis, scalarSeries.valuesUnit());
101 setAxisProperties(plot.yAxis, scalarSeries.valuesUnit());
102
102
103 // Display all data
103 // Display all data
104 component->rescaleAxes();
104 component->rescaleAxes();
105 plot.replot();
105 plot.replot();
106 }
106 }
107 else {
107 else {
108 qCDebug(LOG_VisualizationGraphHelper())
108 qCDebug(LOG_VisualizationGraphHelper())
109 << QObject::tr("Can't create graph for the scalar series");
109 << QObject::tr("Can't create graph for the scalar series");
110 }
110 }
111
111
112 return component;
112 return component;
113 }
113 }
114
114
115 } // namespace
115 } // namespace
116
116
117 QVector<QCPAbstractPlottable *> VisualizationGraphHelper::create(std::shared_ptr<Variable> variable,
117 QVector<QCPAbstractPlottable *> VisualizationGraphHelper::create(std::shared_ptr<Variable> variable,
118 QCustomPlot &plot) noexcept
118 QCustomPlot &plot) noexcept
119 {
119 {
120 auto result = QVector<QCPAbstractPlottable *>{};
120 auto result = QVector<QCPAbstractPlottable *>{};
121
121
122 if (variable) {
122 if (variable) {
123 // Gets the data series of the variable to call the creation of the right components
123 // Gets the data series of the variable to call the creation of the right components
124 // according to its type
124 // according to its type
125 if (auto scalarSeries = dynamic_cast<ScalarSeries *>(variable->dataSeries())) {
125 if (auto scalarSeries = dynamic_cast<ScalarSeries *>(variable->dataSeries())) {
126 result.append(createScalarSeriesComponent(*scalarSeries, plot, variable->dateTime()));
126 result.append(createScalarSeriesComponent(*scalarSeries, plot, variable->dateTime()));
127 }
127 }
128 else {
128 else {
129 qCDebug(LOG_VisualizationGraphHelper())
129 qCDebug(LOG_VisualizationGraphHelper())
130 << QObject::tr("Can't create graph plottables : unmanaged data series type");
130 << QObject::tr("Can't create graph plottables : unmanaged data series type");
131 }
131 }
132 }
132 }
133 else {
133 else {
134 qCDebug(LOG_VisualizationGraphHelper())
134 qCDebug(LOG_VisualizationGraphHelper())
135 << QObject::tr("Can't create graph plottables : the variable is null");
135 << QObject::tr("Can't create graph plottables : the variable is null");
136 }
136 }
137
137
138 return result;
138 return result;
139 }
139 }
140
140
141 void VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *> plotableVect,
141 void VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *> plotableVect,
142 IDataSeries *dataSeries, const SqpDateTime &dateTime)
142 IDataSeries *dataSeries, const SqpDateTime &dateTime)
143 {
143 {
144 if (auto scalarSeries = dynamic_cast<ScalarSeries *>(dataSeries)) {
144 if (auto scalarSeries = dynamic_cast<ScalarSeries *>(dataSeries)) {
145 if (plotableVect.size() == 1) {
145 if (plotableVect.size() == 1) {
146 updateScalarData(plotableVect.at(0), *scalarSeries, dateTime);
146 updateScalarData(plotableVect.at(0), *scalarSeries, dateTime);
147 }
147 }
148 else {
148 else {
149 qCCritical(LOG_VisualizationGraphHelper()) << QObject::tr(
149 qCCritical(LOG_VisualizationGraphHelper()) << QObject::tr(
150 "Can't update Data of a scalarSeries because there is not only one component "
150 "Can't update Data of a scalarSeries because there is not only one component "
151 "associated");
151 "associated");
152 }
152 }
153 }
153 }
154 else {
154 else {
155 /// @todo DEBUG
155 /// @todo DEBUG
156 }
156 }
157 }
157 }
@@ -1,269 +1,263
1 #include "Visualization/VisualizationGraphWidget.h"
1 #include "Visualization/VisualizationGraphWidget.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 #include "Visualization/VisualizationGraphHelper.h"
3 #include "Visualization/VisualizationGraphHelper.h"
4 #include "ui_VisualizationGraphWidget.h"
4 #include "ui_VisualizationGraphWidget.h"
5
5
6 #include <Data/ArrayData.h>
6 #include <Data/ArrayData.h>
7 #include <Data/IDataSeries.h>
7 #include <Data/IDataSeries.h>
8 #include <SqpApplication.h>
8 #include <SqpApplication.h>
9 #include <Variable/Variable.h>
9 #include <Variable/Variable.h>
10 #include <Variable/VariableController.h>
10 #include <Variable/VariableController.h>
11
11
12 #include <unordered_map>
12 #include <unordered_map>
13
13
14 Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget")
14 Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget")
15
15
16 namespace {
16 namespace {
17
17
18 /// Key pressed to enable zoom on horizontal axis
18 /// Key pressed to enable zoom on horizontal axis
19 const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier;
19 const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier;
20
20
21 /// Key pressed to enable zoom on vertical axis
21 /// Key pressed to enable zoom on vertical axis
22 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
22 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
23
23
24 } // namespace
24 } // namespace
25
25
26 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
26 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
27
27
28 // 1 variable -> n qcpplot
28 // 1 variable -> n qcpplot
29 std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap;
29 std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap;
30 };
30 };
31
31
32 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
32 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
33 : QWidget{parent},
33 : QWidget{parent},
34 ui{new Ui::VisualizationGraphWidget},
34 ui{new Ui::VisualizationGraphWidget},
35 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()}
35 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()}
36 {
36 {
37 ui->setupUi(this);
37 ui->setupUi(this);
38
38
39 ui->graphNameLabel->setText(name);
39 ui->graphNameLabel->setText(name);
40
40
41 // 'Close' options : widget is deleted when closed
41 // 'Close' options : widget is deleted when closed
42 setAttribute(Qt::WA_DeleteOnClose);
42 setAttribute(Qt::WA_DeleteOnClose);
43 connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationGraphWidget::close);
43 connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationGraphWidget::close);
44 ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
44 ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
45
45
46 // Set qcpplot properties :
46 // Set qcpplot properties :
47 // - Drag (on x-axis) and zoom are enabled
47 // - Drag (on x-axis) and zoom are enabled
48 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
48 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
49 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
49 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
50 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
50 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
51 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
51 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
52 connect(ui->widget->xAxis,
52 connect(ui->widget->xAxis,
53 static_cast<void (QCPAxis::*)(const QCPRange &)>(&QCPAxis::rangeChanged), this,
53 static_cast<void (QCPAxis::*)(const QCPRange &)>(&QCPAxis::rangeChanged), this,
54 &VisualizationGraphWidget::onRangeChanged);
54 &VisualizationGraphWidget::onRangeChanged);
55
55
56 // Activates menu when right clicking on the graph
56 // Activates menu when right clicking on the graph
57 ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
57 ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
58 connect(ui->widget, &QCustomPlot::customContextMenuRequested, this,
58 connect(ui->widget, &QCustomPlot::customContextMenuRequested, this,
59 &VisualizationGraphWidget::onGraphMenuRequested);
59 &VisualizationGraphWidget::onGraphMenuRequested);
60
60
61 connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(),
61 connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(),
62 &VariableController::onRequestDataLoading);
62 &VariableController::onRequestDataLoading);
63 }
63 }
64
64
65
65
66 VisualizationGraphWidget::~VisualizationGraphWidget()
66 VisualizationGraphWidget::~VisualizationGraphWidget()
67 {
67 {
68 delete ui;
68 delete ui;
69 }
69 }
70
70
71 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
71 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
72 {
72 {
73 // Uses delegate to create the qcpplot components according to the variable
73 // Uses delegate to create the qcpplot components according to the variable
74 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
74 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
75
75
76 for (auto createdPlottable : qAsConst(createdPlottables)) {
76 for (auto createdPlottable : qAsConst(createdPlottables)) {
77 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
77 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
78 }
78 }
79
79
80 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
80 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
81 }
81 }
82
82
83 void VisualizationGraphWidget::addVariableUsingGraph(std::shared_ptr<Variable> variable)
83 void VisualizationGraphWidget::addVariableUsingGraph(std::shared_ptr<Variable> variable)
84 {
84 {
85
85
86 // when adding a variable, we need to set its time range to the current graph range
86 // when adding a variable, we need to set its time range to the current graph range
87 auto grapheRange = ui->widget->xAxis->range();
87 auto grapheRange = ui->widget->xAxis->range();
88 auto dateTime = SqpDateTime{grapheRange.lower, grapheRange.upper};
88 auto dateTime = SqpDateTime{grapheRange.lower, grapheRange.upper};
89 variable->setDateTime(dateTime);
89 variable->setDateTime(dateTime);
90 qCInfo(LOG_VisualizationGraphWidget()) << "ADD Variable with range : " << dateTime;
91
90
92 auto variableDateTimeWithTolerance = dateTime;
91 auto variableDateTimeWithTolerance = dateTime;
93
92
94 // add 10% tolerance for each side
93 // add 10% tolerance for each side
95 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
94 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
96 variableDateTimeWithTolerance.m_TStart -= tolerance;
95 variableDateTimeWithTolerance.m_TStart -= tolerance;
97 variableDateTimeWithTolerance.m_TEnd += tolerance;
96 variableDateTimeWithTolerance.m_TEnd += tolerance;
98
97
99 qCInfo(LOG_VisualizationGraphWidget()) << "ADD Variable with range TOL: "
100 << variableDateTimeWithTolerance;
101
102 // Uses delegate to create the qcpplot components according to the variable
98 // Uses delegate to create the qcpplot components according to the variable
103 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
99 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
104
100
105 for (auto createdPlottable : qAsConst(createdPlottables)) {
101 for (auto createdPlottable : qAsConst(createdPlottables)) {
106 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
102 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
107 }
103 }
108
104
109 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
105 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
110
106
111 // CHangement detected, we need to ask controller to request data loading
107 // CHangement detected, we need to ask controller to request data loading
112 emit requestDataLoading(variable, variableDateTimeWithTolerance);
108 emit requestDataLoading(variable, variableDateTimeWithTolerance);
113 }
109 }
114
110
115 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept
111 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept
116 {
112 {
117 // Each component associated to the variable :
113 // Each component associated to the variable :
118 // - is removed from qcpplot (which deletes it)
114 // - is removed from qcpplot (which deletes it)
119 // - is no longer referenced in the map
115 // - is no longer referenced in the map
120 auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable);
116 auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable);
121 for (auto it = componentsIt.first; it != componentsIt.second;) {
117 for (auto it = componentsIt.first; it != componentsIt.second;) {
122 ui->widget->removePlottable(it->second);
118 ui->widget->removePlottable(it->second);
123 it = impl->m_VariableToPlotMultiMap.erase(it);
119 it = impl->m_VariableToPlotMultiMap.erase(it);
124 }
120 }
125
121
126 // Updates graph
122 // Updates graph
127 ui->widget->replot();
123 ui->widget->replot();
128 }
124 }
129
125
130 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
126 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
131 {
127 {
132 if (visitor) {
128 if (visitor) {
133 visitor->visit(this);
129 visitor->visit(this);
134 }
130 }
135 else {
131 else {
136 qCCritical(LOG_VisualizationGraphWidget())
132 qCCritical(LOG_VisualizationGraphWidget())
137 << tr("Can't visit widget : the visitor is null");
133 << tr("Can't visit widget : the visitor is null");
138 }
134 }
139 }
135 }
140
136
141 bool VisualizationGraphWidget::canDrop(const Variable &variable) const
137 bool VisualizationGraphWidget::canDrop(const Variable &variable) const
142 {
138 {
143 /// @todo : for the moment, a graph can always accomodate a variable
139 /// @todo : for the moment, a graph can always accomodate a variable
144 Q_UNUSED(variable);
140 Q_UNUSED(variable);
145 return true;
141 return true;
146 }
142 }
147
143
148 QString VisualizationGraphWidget::name() const
144 QString VisualizationGraphWidget::name() const
149 {
145 {
150 return ui->graphNameLabel->text();
146 return ui->graphNameLabel->text();
151 }
147 }
152
148
153 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
149 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
154 {
150 {
155 QMenu graphMenu{};
151 QMenu graphMenu{};
156
152
157 // Iterates on variables (unique keys)
153 // Iterates on variables (unique keys)
158 for (auto it = impl->m_VariableToPlotMultiMap.cbegin(),
154 for (auto it = impl->m_VariableToPlotMultiMap.cbegin(),
159 end = impl->m_VariableToPlotMultiMap.cend();
155 end = impl->m_VariableToPlotMultiMap.cend();
160 it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) {
156 it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) {
161 // 'Remove variable' action
157 // 'Remove variable' action
162 graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()),
158 graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()),
163 [ this, var = it->first ]() { removeVariable(var); });
159 [ this, var = it->first ]() { removeVariable(var); });
164 }
160 }
165
161
166 if (!graphMenu.isEmpty()) {
162 if (!graphMenu.isEmpty()) {
167 graphMenu.exec(mapToGlobal(pos));
163 graphMenu.exec(mapToGlobal(pos));
168 }
164 }
169 }
165 }
170
166
171 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1)
167 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1)
172 {
168 {
173
169 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged");
174 qCInfo(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged");
175
170
176 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
171 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
177 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
172 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
178
173
179 auto variable = it->first;
174 auto variable = it->first;
180 auto dateTime = SqpDateTime{t1.lower, t1.upper};
175 auto dateTime = SqpDateTime{t1.lower, t1.upper};
181
176
182 if (!variable->contains(dateTime)) {
177 if (!variable->contains(dateTime)) {
183 qCInfo(LOG_VisualizationGraphWidget()) << dateTime << variable->dateTime();
184
178
185 auto variableDateTimeWithTolerance = dateTime;
179 auto variableDateTimeWithTolerance = dateTime;
186 if (variable->intersect(dateTime)) {
180 if (variable->intersect(dateTime)) {
187 auto variableDateTime = variable->dateTime();
181 auto variableDateTime = variable->dateTime();
188 if (variableDateTime.m_TStart < dateTime.m_TStart) {
182 if (variableDateTime.m_TStart < dateTime.m_TStart) {
189
183
190 auto diffEndToKeepDelta = dateTime.m_TEnd - variableDateTime.m_TEnd;
184 auto diffEndToKeepDelta = dateTime.m_TEnd - variableDateTime.m_TEnd;
191 dateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta;
185 dateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta;
192 // Tolerance have to be added to the right
186 // Tolerance have to be added to the right
193 // add 10% tolerance for right (end) side
187 // add 10% tolerance for right (end) side
194 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
188 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
195 variableDateTimeWithTolerance.m_TEnd += tolerance;
189 variableDateTimeWithTolerance.m_TEnd += tolerance;
196 }
190 }
197 if (variableDateTime.m_TEnd > dateTime.m_TEnd) {
191 if (variableDateTime.m_TEnd > dateTime.m_TEnd) {
198 auto diffStartToKeepDelta = variableDateTime.m_TStart - dateTime.m_TStart;
192 auto diffStartToKeepDelta = variableDateTime.m_TStart - dateTime.m_TStart;
199 dateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta;
193 dateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta;
200 // Tolerance have to be added to the left
194 // Tolerance have to be added to the left
201 // add 10% tolerance for left (start) side
195 // add 10% tolerance for left (start) side
202 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
196 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
203 variableDateTimeWithTolerance.m_TStart -= tolerance;
197 variableDateTimeWithTolerance.m_TStart -= tolerance;
204 }
198 }
205 }
199 }
206 else {
200 else {
207 // add 10% tolerance for each side
201 // add 10% tolerance for each side
208 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
202 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
209 variableDateTimeWithTolerance.m_TStart -= tolerance;
203 variableDateTimeWithTolerance.m_TStart -= tolerance;
210 variableDateTimeWithTolerance.m_TEnd += tolerance;
204 variableDateTimeWithTolerance.m_TEnd += tolerance;
211 }
205 }
212 variable->setDateTime(dateTime);
206 variable->setDateTime(dateTime);
213
207
214 // CHangement detected, we need to ask controller to request data loading
208 // CHangement detected, we need to ask controller to request data loading
215 emit requestDataLoading(variable, variableDateTimeWithTolerance);
209 emit requestDataLoading(variable, variableDateTimeWithTolerance);
216 }
210 }
217 }
211 }
218 }
212 }
219
213
220 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
214 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
221 {
215 {
222 auto zoomOrientations = QFlags<Qt::Orientation>{};
216 auto zoomOrientations = QFlags<Qt::Orientation>{};
223
217
224 // Lambda that enables a zoom orientation if the key modifier related to this orientation
218 // Lambda that enables a zoom orientation if the key modifier related to this orientation
225 // has
219 // has
226 // been pressed
220 // been pressed
227 auto enableOrientation
221 auto enableOrientation
228 = [&zoomOrientations, event](const auto &orientation, const auto &modifier) {
222 = [&zoomOrientations, event](const auto &orientation, const auto &modifier) {
229 auto orientationEnabled = event->modifiers().testFlag(modifier);
223 auto orientationEnabled = event->modifiers().testFlag(modifier);
230 zoomOrientations.setFlag(orientation, orientationEnabled);
224 zoomOrientations.setFlag(orientation, orientationEnabled);
231 };
225 };
232 enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER);
226 enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER);
233 enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER);
227 enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER);
234
228
235 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
229 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
236 }
230 }
237
231
238 void VisualizationGraphWidget::onDataCacheVariableUpdated()
232 void VisualizationGraphWidget::onDataCacheVariableUpdated()
239 {
233 {
240 // NOTE:
234 // NOTE:
241 // We don't want to call the method for each component of a variable unitarily, but for
235 // We don't want to call the method for each component of a variable unitarily, but for
242 // all
236 // all
243 // its components at once (eg its three components in the case of a vector).
237 // its components at once (eg its three components in the case of a vector).
244
238
245 // The unordered_multimap does not do this easily, so the question is whether to:
239 // The unordered_multimap does not do this easily, so the question is whether to:
246 // - use an ordered_multimap and the algos of std to group the values by key
240 // - use an ordered_multimap and the algos of std to group the values by key
247 // - use a map (unique keys) and store as values directly the list of components
241 // - use a map (unique keys) and store as values directly the list of components
248
242
249 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
243 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
250 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
244 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
251 auto variable = it->first;
245 auto variable = it->first;
252 VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second,
246 VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second,
253 variable->dataSeries(), variable->dateTime());
247 variable->dataSeries(), variable->dateTime());
254 }
248 }
255 }
249 }
256
250
257 void VisualizationGraphWidget::updateDisplay(std::shared_ptr<Variable> variable)
251 void VisualizationGraphWidget::updateDisplay(std::shared_ptr<Variable> variable)
258 {
252 {
259 auto abstractPlotableItPair = impl->m_VariableToPlotMultiMap.equal_range(variable);
253 auto abstractPlotableItPair = impl->m_VariableToPlotMultiMap.equal_range(variable);
260
254
261 auto abstractPlotableVect = QVector<QCPAbstractPlottable *>{};
255 auto abstractPlotableVect = QVector<QCPAbstractPlottable *>{};
262
256
263 for (auto it = abstractPlotableItPair.first; it != abstractPlotableItPair.second; ++it) {
257 for (auto it = abstractPlotableItPair.first; it != abstractPlotableItPair.second; ++it) {
264 abstractPlotableVect.push_back(it->second);
258 abstractPlotableVect.push_back(it->second);
265 }
259 }
266
260
267 VisualizationGraphHelper::updateData(abstractPlotableVect, variable->dataSeries(),
261 VisualizationGraphHelper::updateData(abstractPlotableVect, variable->dataSeries(),
268 variable->dateTime());
262 variable->dateTime());
269 }
263 }
General Comments 0
You need to be logged in to leave comments. Login now