##// END OF EJS Templates
Implementation of the cache feature : download before display needs
perrinel -
r433:a2e6652524d1
parent child
Show More
@@ -1,90 +1,90
1 1 #include "Variable/Variable.h"
2 2
3 3 #include <Data/IDataSeries.h>
4 4 #include <Data/SqpDateTime.h>
5 5
6 6 #include <QReadWriteLock>
7 7 #include <QThread>
8 8
9 9 Q_LOGGING_CATEGORY(LOG_Variable, "Variable")
10 10
11 11 struct Variable::VariablePrivate {
12 12 explicit VariablePrivate(const QString &name, const SqpDateTime &dateTime,
13 13 const QVariantHash &metadata)
14 14 : m_Name{name}, m_DateTime{dateTime}, m_Metadata{metadata}, m_DataSeries{nullptr}
15 15 {
16 16 }
17 17
18 18 QString m_Name;
19 19
20 20 SqpDateTime m_DateTime; // The dateTime available in the view and loaded. not the cache.
21 21 QVariantHash m_Metadata;
22 22 std::unique_ptr<IDataSeries> m_DataSeries;
23 23 };
24 24
25 25 Variable::Variable(const QString &name, const SqpDateTime &dateTime, const QVariantHash &metadata)
26 26 : impl{spimpl::make_unique_impl<VariablePrivate>(name, dateTime, metadata)}
27 27 {
28 28 }
29 29
30 30 QString Variable::name() const noexcept
31 31 {
32 32 return impl->m_Name;
33 33 }
34 34
35 35 SqpDateTime Variable::dateTime() const noexcept
36 36 {
37 37 return impl->m_DateTime;
38 38 }
39 39
40 40 void Variable::setDateTime(const SqpDateTime &dateTime) noexcept
41 41 {
42 42 impl->m_DateTime = dateTime;
43 43 }
44 44
45 45 void Variable::setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
46 46 {
47 47 qCDebug(LOG_Variable()) << "Variable::setDataSeries" << QThread::currentThread()->objectName();
48 48 if (!dataSeries) {
49 49 /// @todo ALX : log
50 50 return;
51 51 }
52 52
53 53 // Inits the data series of the variable
54 54 if (!impl->m_DataSeries) {
55 55 impl->m_DataSeries = dataSeries->clone();
56 56 }
57 57 else {
58 58 dataSeries->lockWrite();
59 59 impl->m_DataSeries->lockWrite();
60 60 impl->m_DataSeries->merge(dataSeries.get());
61 61 impl->m_DataSeries->unlock();
62 62 dataSeries->unlock();
63 emit updated();
63 // emit updated();
64 64 }
65 65 }
66 66
67 67 IDataSeries *Variable::dataSeries() const noexcept
68 68 {
69 69 return impl->m_DataSeries.get();
70 70 }
71 71
72 72 QVariantHash Variable::metadata() const noexcept
73 73 {
74 74 return impl->m_Metadata;
75 75 }
76 76
77 77 bool Variable::contains(const SqpDateTime &dateTime) const noexcept
78 78 {
79 79 return impl->m_DateTime.contains(dateTime);
80 80 }
81 81
82 82 bool Variable::intersect(const SqpDateTime &dateTime) const noexcept
83 83 {
84 84 return impl->m_DateTime.intersect(dateTime);
85 85 }
86 86
87 87 bool Variable::isInside(const SqpDateTime &dateTime) const noexcept
88 88 {
89 89 return dateTime.contains(SqpDateTime{impl->m_DateTime.m_TStart, impl->m_DateTime.m_TEnd});
90 90 }
@@ -1,240 +1,241
1 1 #include <Variable/Variable.h>
2 2 #include <Variable/VariableCacheController.h>
3 3 #include <Variable/VariableController.h>
4 4 #include <Variable/VariableModel.h>
5 5
6 6 #include <Data/DataProviderParameters.h>
7 7 #include <Data/IDataProvider.h>
8 8 #include <Data/IDataSeries.h>
9 9 #include <Time/TimeController.h>
10 10
11 11 #include <QDateTime>
12 12 #include <QMutex>
13 13 #include <QThread>
14 14 #include <QUuid>
15 15 #include <QtCore/QItemSelectionModel>
16 16
17 17 #include <unordered_map>
18 18
19 19 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
20 20
21 21 struct VariableController::VariableControllerPrivate {
22 22 explicit VariableControllerPrivate(VariableController *parent)
23 23 : m_WorkingMutex{},
24 24 m_VariableModel{new VariableModel{parent}},
25 25 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
26 26 m_VariableCacheController{std::make_unique<VariableCacheController>()}
27 27 {
28 28 }
29 29
30 30 QMutex m_WorkingMutex;
31 31 /// Variable model. The VariableController has the ownership
32 32 VariableModel *m_VariableModel;
33 33 QItemSelectionModel *m_VariableSelectionModel;
34 34
35 35
36 36 TimeController *m_TimeController{nullptr};
37 37 std::unique_ptr<VariableCacheController> m_VariableCacheController;
38 38
39 39 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
40 40 m_VariableToProviderMap;
41 41 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
42 42 };
43 43
44 44 VariableController::VariableController(QObject *parent)
45 45 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
46 46 {
47 47 qCDebug(LOG_VariableController()) << tr("VariableController construction")
48 48 << QThread::currentThread();
49 49
50 50 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
51 51 &VariableController::onAbortProgressRequested);
52 52 }
53 53
54 54 VariableController::~VariableController()
55 55 {
56 56 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
57 57 << QThread::currentThread();
58 58 this->waitForFinish();
59 59 }
60 60
61 61 VariableModel *VariableController::variableModel() noexcept
62 62 {
63 63 return impl->m_VariableModel;
64 64 }
65 65
66 66 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
67 67 {
68 68 return impl->m_VariableSelectionModel;
69 69 }
70 70
71 71 void VariableController::setTimeController(TimeController *timeController) noexcept
72 72 {
73 73 impl->m_TimeController = timeController;
74 74 }
75 75
76 76 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
77 77 {
78 78 if (!variable) {
79 79 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
80 80 return;
81 81 }
82 82
83 83 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
84 84 // make some treatments before the deletion
85 85 emit variableAboutToBeDeleted(variable);
86 86
87 87 // Deletes identifier
88 88 impl->m_VariableToIdentifierMap.erase(variable);
89 89
90 90 // Deletes provider
91 91 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
92 92 qCDebug(LOG_VariableController())
93 93 << tr("Number of providers deleted for variable %1: %2")
94 94 .arg(variable->name(), QString::number(nbProvidersDeleted));
95 95
96 96 // Clears cache
97 97 impl->m_VariableCacheController->clear(variable);
98 98
99 99 // Deletes from model
100 100 impl->m_VariableModel->deleteVariable(variable);
101 101 }
102 102
103 103 void VariableController::deleteVariables(
104 104 const QVector<std::shared_ptr<Variable> > &variables) noexcept
105 105 {
106 106 for (auto variable : qAsConst(variables)) {
107 107 deleteVariable(variable);
108 108 }
109 109 }
110 110
111 111 void VariableController::abortProgress(std::shared_ptr<Variable> variable)
112 112 {
113 113 }
114 114
115 115 void VariableController::createVariable(const QString &name, const QVariantHash &metadata,
116 116 std::shared_ptr<IDataProvider> provider) noexcept
117 117 {
118 118
119 119 if (!impl->m_TimeController) {
120 120 qCCritical(LOG_VariableController())
121 121 << tr("Impossible to create variable: The time controller is null");
122 122 return;
123 123 }
124 124
125 125 auto dateTime = impl->m_TimeController->dateTime();
126 126
127 127 if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime, metadata)) {
128 128 auto identifier = QUuid::createUuid();
129 129
130 130 // store the provider
131 131 impl->m_VariableToProviderMap[newVariable] = provider;
132 132 impl->m_VariableToIdentifierMap[newVariable] = identifier;
133 133
134 134 auto addDateTimeAcquired = [ this, varW = std::weak_ptr<Variable>{newVariable} ](
135 135 QUuid identifier, auto dataSeriesAcquired, auto dateTimeToPutInCache)
136 136 {
137 137 if (auto variable = varW.lock()) {
138 138 auto varIdentifier = impl->m_VariableToIdentifierMap.at(variable);
139 139 if (varIdentifier == identifier) {
140 140 impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache);
141 141 variable->setDataSeries(dataSeriesAcquired);
142 emit variable->updated();
142 143 }
143 144 }
144 145 };
145 146
146 147 connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired);
147 148 connect(provider.get(), &IDataProvider::dataProvidedProgress, this,
148 149 &VariableController::onVariableRetrieveDataInProgress);
149 150 this->onRequestDataLoading(newVariable, dateTime);
150 151 }
151 152 }
152 153
153 154 void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime)
154 155 {
155 156 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
156 157 << QThread::currentThread()->objectName();
157 158 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
158 159
159 160 for (const auto &selectedRow : qAsConst(selectedRows)) {
160 161 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
161 162 selectedVariable->setDateTime(dateTime);
162 163 this->onRequestDataLoading(selectedVariable, dateTime);
163 164 }
164 165 }
165 166 }
166 167
167 168 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
168 169 {
169 170 auto findReply = [identifier](const auto &entry) { return identifier == entry.second; };
170 171
171 172 auto end = impl->m_VariableToIdentifierMap.cend();
172 173 auto it = std::find_if(impl->m_VariableToIdentifierMap.cbegin(), end, findReply);
173 174 if (it != end) {
174 175 impl->m_VariableModel->setDataProgress(it->first, progress);
175 176 }
176 177 }
177 178
178 179 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
179 180 {
180 181 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested"
181 182 << QThread::currentThread()->objectName();
182 183
183 184 auto it = impl->m_VariableToIdentifierMap.find(variable);
184 185 if (it != impl->m_VariableToIdentifierMap.cend()) {
185 186 impl->m_VariableToProviderMap.at(variable)->requestDataAborting(it->second);
186 187 }
187 188 else {
188 189 qCWarning(LOG_VariableController())
189 190 << tr("Aborting progression of inexistant variable detected !!!")
190 191 << QThread::currentThread()->objectName();
191 192 }
192 193 }
193 194
194 195
195 196 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable,
196 197 const SqpDateTime &dateTime)
197 198 {
198 199 qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading"
199 200 << QThread::currentThread()->objectName();
200 201 // we want to load data of the variable for the dateTime.
201 202 // First we check if the cache contains some of them.
202 203 // For the other, we ask the provider to give them.
203 204 if (variable) {
204 205
205 206 auto dateTimeListNotInCache
206 207 = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime);
207 208
208 209 if (!dateTimeListNotInCache.empty()) {
209 210 // Ask the provider for each data on the dateTimeListNotInCache
210 211 auto identifier = impl->m_VariableToIdentifierMap.at(variable);
211 212 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
212 213 identifier,
213 214 DataProviderParameters{std::move(dateTimeListNotInCache), variable->metadata()});
214 215 }
215 216 else {
216 217 emit variable->updated();
217 218 }
218 219 }
219 220 else {
220 221 qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null");
221 222 }
222 223 }
223 224
224 225
225 226 void VariableController::initialize()
226 227 {
227 228 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
228 229 impl->m_WorkingMutex.lock();
229 230 qCDebug(LOG_VariableController()) << tr("VariableController init END");
230 231 }
231 232
232 233 void VariableController::finalize()
233 234 {
234 235 impl->m_WorkingMutex.unlock();
235 236 }
236 237
237 238 void VariableController::waitForFinish()
238 239 {
239 240 QMutexLocker locker{&impl->m_WorkingMutex};
240 241 }
@@ -1,285 +1,311
1 1 #include "Visualization/VisualizationGraphWidget.h"
2 2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 3 #include "Visualization/VisualizationGraphHelper.h"
4 4 #include "ui_VisualizationGraphWidget.h"
5 5
6 6 #include <Data/ArrayData.h>
7 7 #include <Data/IDataSeries.h>
8 8 #include <SqpApplication.h>
9 9 #include <Variable/Variable.h>
10 10 #include <Variable/VariableController.h>
11 11
12 12 #include <unordered_map>
13 13
14 14 Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget")
15 15
16 16 namespace {
17 17
18 18 /// Key pressed to enable zoom on horizontal axis
19 19 const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier;
20 20
21 21 /// Key pressed to enable zoom on vertical axis
22 22 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
23 23
24 24 } // namespace
25 25
26 26 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
27 27
28 28 // 1 variable -> n qcpplot
29 29 std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap;
30 30 };
31 31
32 32 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
33 33 : QWidget{parent},
34 34 ui{new Ui::VisualizationGraphWidget},
35 35 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()}
36 36 {
37 37 ui->setupUi(this);
38 38
39 39 ui->graphNameLabel->setText(name);
40 40
41 41 // 'Close' options : widget is deleted when closed
42 42 setAttribute(Qt::WA_DeleteOnClose);
43 43 connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationGraphWidget::close);
44 44 ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
45 45
46 46 // Set qcpplot properties :
47 47 // - Drag (on x-axis) and zoom are enabled
48 48 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
49 49 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
50 50 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
51 51 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
52 52 connect(ui->widget->xAxis,
53 53 static_cast<void (QCPAxis::*)(const QCPRange &)>(&QCPAxis::rangeChanged), this,
54 54 &VisualizationGraphWidget::onRangeChanged);
55 55
56 56 // Activates menu when right clicking on the graph
57 57 ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
58 58 connect(ui->widget, &QCustomPlot::customContextMenuRequested, this,
59 59 &VisualizationGraphWidget::onGraphMenuRequested);
60 60
61 61 connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(),
62 62 &VariableController::onRequestDataLoading);
63 63 }
64 64
65 65
66 66 VisualizationGraphWidget::~VisualizationGraphWidget()
67 67 {
68 68 delete ui;
69 69 }
70 70
71 71 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
72 72 {
73 73 // Uses delegate to create the qcpplot components according to the variable
74 74 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
75 75
76 76 for (auto createdPlottable : qAsConst(createdPlottables)) {
77 77 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
78 78 }
79 79
80 80 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
81 81 }
82 82 void VisualizationGraphWidget::addVariableUsingGraph(std::shared_ptr<Variable> variable)
83 83 {
84 84
85 85 // when adding a variable, we need to set its time range to the current graph range
86 86 auto grapheRange = ui->widget->xAxis->range();
87 87 auto dateTime = SqpDateTime{grapheRange.lower, grapheRange.upper};
88 88 variable->setDateTime(dateTime);
89 89
90 90 auto variableDateTimeWithTolerance = dateTime;
91 91
92 92 // add 10% tolerance for each side
93 93 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
94 94 variableDateTimeWithTolerance.m_TStart -= tolerance;
95 95 variableDateTimeWithTolerance.m_TEnd += tolerance;
96 96
97 97 // Uses delegate to create the qcpplot components according to the variable
98 98 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
99 99
100 100 for (auto createdPlottable : qAsConst(createdPlottables)) {
101 101 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
102 102 }
103 103
104 104 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
105 105
106 106 // CHangement detected, we need to ask controller to request data loading
107 107 emit requestDataLoading(variable, variableDateTimeWithTolerance);
108 108 }
109 109
110 110 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept
111 111 {
112 112 // Each component associated to the variable :
113 113 // - is removed from qcpplot (which deletes it)
114 114 // - is no longer referenced in the map
115 115 auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable);
116 116 for (auto it = componentsIt.first; it != componentsIt.second;) {
117 117 ui->widget->removePlottable(it->second);
118 118 it = impl->m_VariableToPlotMultiMap.erase(it);
119 119 }
120 120
121 121 // Updates graph
122 122 ui->widget->replot();
123 123 }
124 124
125 125 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
126 126 {
127 127 if (visitor) {
128 128 visitor->visit(this);
129 129 }
130 130 else {
131 131 qCCritical(LOG_VisualizationGraphWidget())
132 132 << tr("Can't visit widget : the visitor is null");
133 133 }
134 134 }
135 135
136 136 bool VisualizationGraphWidget::canDrop(const Variable &variable) const
137 137 {
138 138 /// @todo : for the moment, a graph can always accomodate a variable
139 139 Q_UNUSED(variable);
140 140 return true;
141 141 }
142 142
143 143 bool VisualizationGraphWidget::contains(const Variable &variable) const
144 144 {
145 145 // Finds the variable among the keys of the map
146 146 auto variablePtr = &variable;
147 147 auto findVariable
148 148 = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); };
149 149
150 150 auto end = impl->m_VariableToPlotMultiMap.cend();
151 151 auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable);
152 152 return it != end;
153 153 }
154 154
155 155 QString VisualizationGraphWidget::name() const
156 156 {
157 157 return ui->graphNameLabel->text();
158 158 }
159 159
160 160 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
161 161 {
162 162 QMenu graphMenu{};
163 163
164 164 // Iterates on variables (unique keys)
165 165 for (auto it = impl->m_VariableToPlotMultiMap.cbegin(),
166 166 end = impl->m_VariableToPlotMultiMap.cend();
167 167 it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) {
168 168 // 'Remove variable' action
169 169 graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()),
170 170 [ this, var = it->first ]() { removeVariable(var); });
171 171 }
172 172
173 173 if (!graphMenu.isEmpty()) {
174 174 graphMenu.exec(mapToGlobal(pos));
175 175 }
176 176 }
177 177
178 178 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1)
179 179 {
180 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged")
180 qCInfo(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged")
181 181 << QThread::currentThread()->objectName();
182 182
183 183 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
184 184 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
185 185
186 186 auto variable = it->first;
187 187 auto dateTime = SqpDateTime{t1.lower, t1.upper};
188 auto dateTimeRange = dateTime;
188 189
189 if (!variable->contains(dateTime)) {
190 auto tolerance = 0.2 * (dateTime.m_TEnd - dateTime.m_TStart);
191 auto variableDateTimeWithTolerance = dateTime;
192 variableDateTimeWithTolerance.m_TStart -= tolerance;
193 variableDateTimeWithTolerance.m_TEnd += tolerance;
194
195 qCInfo(LOG_VisualizationGraphWidget()) << "v" << dateTime;
196 qCInfo(LOG_VisualizationGraphWidget()) << "vtol" << variableDateTimeWithTolerance;
197 // If new range with tol is upper than variable datetime parameters. we need to request new
198 // data
199 if (!variable->contains(variableDateTimeWithTolerance)) {
190 200
191 201 auto variableDateTimeWithTolerance = dateTime;
192 202 if (!variable->isInside(dateTime)) {
193 203 auto variableDateTime = variable->dateTime();
194 204 if (variableDateTime.m_TStart < dateTime.m_TStart) {
195 qCDebug(LOG_VisualizationGraphWidget()) << tr("TDetection pan to right:");
205 qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to right:");
196 206
197 207 auto diffEndToKeepDelta = dateTime.m_TEnd - variableDateTime.m_TEnd;
198 208 dateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta;
199 209 // Tolerance have to be added to the right
200 210 // add 10% tolerance for right (end) side
201 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
211 // auto tolerance = 0.1 * (dateTime.m_TEnd -
212 // dateTime.m_TStart);
202 213 variableDateTimeWithTolerance.m_TEnd += tolerance;
203 214 }
204 215 else if (variableDateTime.m_TEnd > dateTime.m_TEnd) {
205 qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection pan to left: ");
216 qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to left: ");
206 217 auto diffStartToKeepDelta = variableDateTime.m_TStart - dateTime.m_TStart;
207 218 dateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta;
208 219 // Tolerance have to be added to the left
209 220 // add 10% tolerance for left (start) side
210 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
221 tolerance = 0.2 * (dateTime.m_TEnd - dateTime.m_TStart);
211 222 variableDateTimeWithTolerance.m_TStart -= tolerance;
212 223 }
213 224 else {
214 225 qCWarning(LOG_VisualizationGraphWidget())
215 226 << tr("Detection anormal zoom detection: ");
216 227 }
217 228 }
218 229 else {
219 qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection zoom out: ");
230 qCInfo(LOG_VisualizationGraphWidget()) << tr("Detection zoom out: ");
220 231 // add 10% tolerance for each side
221 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
232 tolerance = 0.2 * (dateTime.m_TEnd - dateTime.m_TStart);
222 233 variableDateTimeWithTolerance.m_TStart -= tolerance;
223 234 variableDateTimeWithTolerance.m_TEnd += tolerance;
224 235 }
236 if (!variable->contains(dateTimeRange)) {
237 qCInfo(LOG_VisualizationGraphWidget()) << "newv" << dateTime;
225 238 variable->setDateTime(dateTime);
239 }
226 240
241 qCInfo(LOG_VisualizationGraphWidget()) << tr("Request data detection: ");
227 242 // CHangement detected, we need to ask controller to request data loading
228 243 emit requestDataLoading(variable, variableDateTimeWithTolerance);
229 244 }
230 245 else {
231 qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection zoom in: ");
246 qCInfo(LOG_VisualizationGraphWidget()) << tr("Detection zoom in: ");
232 247 }
233 248 }
234 249 }
235 250
236 251 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
237 252 {
238 253 auto zoomOrientations = QFlags<Qt::Orientation>{};
239 254
240 255 // Lambda that enables a zoom orientation if the key modifier related to this orientation
241 256 // has
242 257 // been pressed
243 258 auto enableOrientation
244 259 = [&zoomOrientations, event](const auto &orientation, const auto &modifier) {
245 260 auto orientationEnabled = event->modifiers().testFlag(modifier);
246 261 zoomOrientations.setFlag(orientation, orientationEnabled);
247 262 };
248 263 enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER);
249 264 enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER);
250 265
251 266 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
252 267 }
253 268
254 269 void VisualizationGraphWidget::onDataCacheVariableUpdated()
255 270 {
256 271 // NOTE:
257 272 // We don't want to call the method for each component of a variable unitarily, but for
258 273 // all
259 274 // its components at once (eg its three components in the case of a vector).
260 275
261 276 // The unordered_multimap does not do this easily, so the question is whether to:
262 277 // - use an ordered_multimap and the algos of std to group the values by key
263 278 // - use a map (unique keys) and store as values directly the list of components
264 279
280 auto grapheRange = ui->widget->xAxis->range();
281 auto dateTime = SqpDateTime{grapheRange.lower, grapheRange.upper};
282
265 283 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
266 284 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
267 285 auto variable = it->first;
286 qCInfo(LOG_VisualizationGraphWidget())
287 << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S"
288 << variable->dateTime();
289 qCInfo(LOG_VisualizationGraphWidget())
290 << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime;
291 if (dateTime.contains(variable->dateTime()) || dateTime.intersect(variable->dateTime())) {
292
268 293 VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second,
269 294 variable->dataSeries(), variable->dateTime());
270 295 }
271 296 }
297 }
272 298
273 299 void VisualizationGraphWidget::updateDisplay(std::shared_ptr<Variable> variable)
274 300 {
275 301 auto abstractPlotableItPair = impl->m_VariableToPlotMultiMap.equal_range(variable);
276 302
277 303 auto abstractPlotableVect = QVector<QCPAbstractPlottable *>{};
278 304
279 305 for (auto it = abstractPlotableItPair.first; it != abstractPlotableItPair.second; ++it) {
280 306 abstractPlotableVect.push_back(it->second);
281 307 }
282 308
283 309 VisualizationGraphHelper::updateData(abstractPlotableVect, variable->dataSeries(),
284 310 variable->dateTime());
285 311 }
General Comments 0
You need to be logged in to leave comments. Login now