From 4139acc0b06bdd271be62336490f0bdbe55617b2 2017-12-21 16:44:40 From: Thibaud Rabillard Date: 2017-12-21 16:44:40 Subject: [PATCH] Remove old graph from selected zones --- diff --git a/core/include/Variable/VariableController.h b/core/include/Variable/VariableController.h index 26bb00b..9238f8a 100644 --- a/core/include/Variable/VariableController.h +++ b/core/include/Variable/VariableController.h @@ -48,26 +48,6 @@ public: */ std::shared_ptr cloneVariable(std::shared_ptr variable) noexcept; - /** - * Deletes from the controller the variable passed in parameter. - * - * Delete a variable includes: - * - the deletion of the various references to the variable in SciQlop - * - the deletion of the model variable - * - the deletion of the provider associated with the variable - * - removing the cache associated with the variable - * - * @param variable the variable to delete from the controller. - */ - void deleteVariable(std::shared_ptr variable) noexcept; - - /** - * Deletes from the controller the variables passed in parameter. - * @param variables the variables to delete from the controller. - * @sa deleteVariable() - */ - void deleteVariables(const QVector > &variables) noexcept; - /// Returns the MIME data associated to a list of variables QByteArray mimeDataForVariables(const QList > &variables) const; @@ -92,6 +72,26 @@ signals: void variableAdded(const std::shared_ptr &variable); public slots: + /** + * Deletes from the controller the variable passed in parameter. + * + * Delete a variable includes: + * - the deletion of the various references to the variable in SciQlop + * - the deletion of the model variable + * - the deletion of the provider associated with the variable + * - removing the cache associated with the variable + * + * @param variable the variable to delete from the controller. + */ + void deleteVariable(std::shared_ptr variable) noexcept; + + /** + * Deletes from the controller the variables passed in parameter. + * @param variables the variables to delete from the controller. + * @sa deleteVariable() + */ + void deleteVariables(const QVector > &variables) noexcept; + /// Request the data loading of the variable whithin range void onRequestDataLoading(QVector > variables, const SqpRange &range, bool synchronise); diff --git a/gui/include/Visualization/VisualizationGraphWidget.h b/gui/include/Visualization/VisualizationGraphWidget.h index efee1c9..bc96a90 100644 --- a/gui/include/Visualization/VisualizationGraphWidget.h +++ b/gui/include/Visualization/VisualizationGraphWidget.h @@ -69,7 +69,7 @@ public: /// Sets the y-axis range based on the data of a variable void setYRange(std::shared_ptr variable); SqpRange graphRange() const noexcept; - void setGraphRange(const SqpRange &range); + void setGraphRange(const SqpRange &range, bool calibration = false); // Zones /// Returns the ranges of all the selection zones on the graph diff --git a/gui/src/Catalogue/CatalogueEventsWidget.cpp b/gui/src/Catalogue/CatalogueEventsWidget.cpp index 6ed95d9..702cd0b 100644 --- a/gui/src/Catalogue/CatalogueEventsWidget.cpp +++ b/gui/src/Catalogue/CatalogueEventsWidget.cpp @@ -8,13 +8,14 @@ #include #include #include +#include #include #include #include +#include #include #include #include -#include #include #include @@ -190,27 +191,73 @@ struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate { if (selectedRows.count() == 1) { auto event = m_Model->getEvent(selectedRows.first()); - if (m_VisualizationWidget) { + if (m_VisualizationWidget && event) { if (auto tab = m_VisualizationWidget->currentTabWidget()) { if (auto zone = tab->getZoneWithName(m_ZoneForGraphMode)) { for (auto graph : m_CustomGraphs) { graph->close(); + auto variables = graph->variables().toVector(); + + QMetaObject::invokeMethod( + &sqpApp->variableController(), "deleteVariables", + Qt::QueuedConnection, + Q_ARG(QVector >, variables)); } m_CustomGraphs.clear(); + QVector graphRanges; + double maxDt = 0; + for (auto eventProduct : event->getEventProducts()) { + SqpRange eventRange; + eventRange.m_TStart = eventProduct.getTStart(); + eventRange.m_TEnd = eventProduct.getTEnd(); + graphRanges << eventRange; + + auto dt = eventRange.m_TEnd - eventRange.m_TStart; + if (dt > maxDt) { + maxDt = dt; + } + } + + QVector correctedGraphRanges; + for (auto range : graphRanges) { + auto dt = range.m_TEnd - range.m_TStart; + auto diff = qAbs((maxDt - dt) / 2.0); + + SqpRange correctedRange; + correctedRange.m_TStart = range.m_TStart - diff; + correctedRange.m_TEnd = range.m_TEnd + diff; + + correctedGraphRanges << correctedRange; + } + + auto itRange = correctedGraphRanges.cbegin(); for (auto eventProduct : event->getEventProducts()) { auto productId = eventProduct.getProductId(); + auto range = *itRange; + ++itRange; + auto context = new QObject{treeView}; - QObject::connect(&sqpApp->variableController(), - &VariableController::variableAdded, context, - [this, zone, context](auto variable) { - auto graph = zone->createGraph(variable); - m_CustomGraphs << graph; - delete context; // removes the connection - }, - Qt::QueuedConnection); + QObject::connect( + &sqpApp->variableController(), &VariableController::variableAdded, + context, + [this, zone, context, range, productId](auto variable) { + + if (variable->metadata() + .value(DataSourceItem::ID_DATA_KEY, "UnknownID") + .toString() + == productId) { + auto graph = zone->createGraph(variable); + m_CustomGraphs << graph; + + graph->setGraphRange(range, true); + + delete context; // removes the connection + } + }, + Qt::QueuedConnection); QMetaObject::invokeMethod( &sqpApp->dataSourceController(), "requestVariableFromProductIdKey", diff --git a/gui/src/Visualization/VisualizationGraphWidget.cpp b/gui/src/Visualization/VisualizationGraphWidget.cpp index f411eec..716e420 100644 --- a/gui/src/Visualization/VisualizationGraphWidget.cpp +++ b/gui/src/Visualization/VisualizationGraphWidget.cpp @@ -388,11 +388,21 @@ SqpRange VisualizationGraphWidget::graphRange() const noexcept return SqpRange{graphRange.lower, graphRange.upper}; } -void VisualizationGraphWidget::setGraphRange(const SqpRange &range) +void VisualizationGraphWidget::setGraphRange(const SqpRange &range, bool calibration) { qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START"); + + if (calibration) { + impl->m_IsCalibration = true; + } + ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); ui->widget->replot(); + + if (calibration) { + impl->m_IsCalibration = false; + } + qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END"); }