##// END OF EJS Templates
Remove old graph from selected zones
trabillard -
r1345:4139acc0b06b
parent child
Show More
@@ -48,26 +48,6 public:
48 48 */
49 49 std::shared_ptr<Variable> cloneVariable(std::shared_ptr<Variable> variable) noexcept;
50 50
51 /**
52 * Deletes from the controller the variable passed in parameter.
53 *
54 * Delete a variable includes:
55 * - the deletion of the various references to the variable in SciQlop
56 * - the deletion of the model variable
57 * - the deletion of the provider associated with the variable
58 * - removing the cache associated with the variable
59 *
60 * @param variable the variable to delete from the controller.
61 */
62 void deleteVariable(std::shared_ptr<Variable> variable) noexcept;
63
64 /**
65 * Deletes from the controller the variables passed in parameter.
66 * @param variables the variables to delete from the controller.
67 * @sa deleteVariable()
68 */
69 void deleteVariables(const QVector<std::shared_ptr<Variable> > &variables) noexcept;
70
71 51 /// Returns the MIME data associated to a list of variables
72 52 QByteArray mimeDataForVariables(const QList<std::shared_ptr<Variable> > &variables) const;
73 53
@@ -92,6 +72,26 signals:
92 72 void variableAdded(const std::shared_ptr<Variable> &variable);
93 73
94 74 public slots:
75 /**
76 * Deletes from the controller the variable passed in parameter.
77 *
78 * Delete a variable includes:
79 * - the deletion of the various references to the variable in SciQlop
80 * - the deletion of the model variable
81 * - the deletion of the provider associated with the variable
82 * - removing the cache associated with the variable
83 *
84 * @param variable the variable to delete from the controller.
85 */
86 void deleteVariable(std::shared_ptr<Variable> variable) noexcept;
87
88 /**
89 * Deletes from the controller the variables passed in parameter.
90 * @param variables the variables to delete from the controller.
91 * @sa deleteVariable()
92 */
93 void deleteVariables(const QVector<std::shared_ptr<Variable> > &variables) noexcept;
94
95 95 /// Request the data loading of the variable whithin range
96 96 void onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables, const SqpRange &range,
97 97 bool synchronise);
@@ -69,7 +69,7 public:
69 69 /// Sets the y-axis range based on the data of a variable
70 70 void setYRange(std::shared_ptr<Variable> variable);
71 71 SqpRange graphRange() const noexcept;
72 void setGraphRange(const SqpRange &range);
72 void setGraphRange(const SqpRange &range, bool calibration = false);
73 73
74 74 // Zones
75 75 /// Returns the ranges of all the selection zones on the graph
@@ -8,13 +8,14
8 8 #include <DBCatalogue.h>
9 9 #include <DBEventProduct.h>
10 10 #include <DataSource/DataSourceController.h>
11 #include <DataSource/DataSourceItem.h>
11 12 #include <SqpApplication.h>
12 13 #include <Variable/Variable.h>
13 14 #include <Variable/VariableController.h>
15 #include <Visualization/VisualizationGraphWidget.h>
14 16 #include <Visualization/VisualizationTabWidget.h>
15 17 #include <Visualization/VisualizationWidget.h>
16 18 #include <Visualization/VisualizationZoneWidget.h>
17 #include <Visualization/VisualizationGraphWidget.h>
18 19
19 20 #include <QDialog>
20 21 #include <QDialogButtonBox>
@@ -190,27 +191,73 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
190 191
191 192 if (selectedRows.count() == 1) {
192 193 auto event = m_Model->getEvent(selectedRows.first());
193 if (m_VisualizationWidget) {
194 if (m_VisualizationWidget && event) {
194 195 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
195 196 if (auto zone = tab->getZoneWithName(m_ZoneForGraphMode)) {
196 197
197 198 for (auto graph : m_CustomGraphs) {
198 199 graph->close();
200 auto variables = graph->variables().toVector();
201
202 QMetaObject::invokeMethod(
203 &sqpApp->variableController(), "deleteVariables",
204 Qt::QueuedConnection,
205 Q_ARG(QVector<std::shared_ptr<Variable> >, variables));
199 206 }
200 207 m_CustomGraphs.clear();
201 208
209 QVector<SqpRange> graphRanges;
210 double maxDt = 0;
211 for (auto eventProduct : event->getEventProducts()) {
212 SqpRange eventRange;
213 eventRange.m_TStart = eventProduct.getTStart();
214 eventRange.m_TEnd = eventProduct.getTEnd();
215 graphRanges << eventRange;
216
217 auto dt = eventRange.m_TEnd - eventRange.m_TStart;
218 if (dt > maxDt) {
219 maxDt = dt;
220 }
221 }
222
223 QVector<SqpRange> correctedGraphRanges;
224 for (auto range : graphRanges) {
225 auto dt = range.m_TEnd - range.m_TStart;
226 auto diff = qAbs((maxDt - dt) / 2.0);
227
228 SqpRange correctedRange;
229 correctedRange.m_TStart = range.m_TStart - diff;
230 correctedRange.m_TEnd = range.m_TEnd + diff;
231
232 correctedGraphRanges << correctedRange;
233 }
234
235 auto itRange = correctedGraphRanges.cbegin();
202 236 for (auto eventProduct : event->getEventProducts()) {
203 237 auto productId = eventProduct.getProductId();
204 238
239 auto range = *itRange;
240 ++itRange;
241
205 242 auto context = new QObject{treeView};
206 QObject::connect(&sqpApp->variableController(),
207 &VariableController::variableAdded, context,
208 [this, zone, context](auto variable) {
209 auto graph = zone->createGraph(variable);
210 m_CustomGraphs << graph;
211 delete context; // removes the connection
212 },
213 Qt::QueuedConnection);
243 QObject::connect(
244 &sqpApp->variableController(), &VariableController::variableAdded,
245 context,
246 [this, zone, context, range, productId](auto variable) {
247
248 if (variable->metadata()
249 .value(DataSourceItem::ID_DATA_KEY, "UnknownID")
250 .toString()
251 == productId) {
252 auto graph = zone->createGraph(variable);
253 m_CustomGraphs << graph;
254
255 graph->setGraphRange(range, true);
256
257 delete context; // removes the connection
258 }
259 },
260 Qt::QueuedConnection);
214 261
215 262 QMetaObject::invokeMethod(
216 263 &sqpApp->dataSourceController(), "requestVariableFromProductIdKey",
@@ -388,11 +388,21 SqpRange VisualizationGraphWidget::graphRange() const noexcept
388 388 return SqpRange{graphRange.lower, graphRange.upper};
389 389 }
390 390
391 void VisualizationGraphWidget::setGraphRange(const SqpRange &range)
391 void VisualizationGraphWidget::setGraphRange(const SqpRange &range, bool calibration)
392 392 {
393 393 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START");
394
395 if (calibration) {
396 impl->m_IsCalibration = true;
397 }
398
394 399 ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd);
395 400 ui->widget->replot();
401
402 if (calibration) {
403 impl->m_IsCalibration = false;
404 }
405
396 406 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END");
397 407 }
398 408
General Comments 0
You need to be logged in to leave comments. Login now