From f7fe3621eadcb0fd4a596e7ed3f6dd85e32c13e9 2017-12-13 11:18:42 From: Thibaud Rabillard Date: 2017-12-13 11:18:42 Subject: [PATCH] Time Zone Mode + prepare graph mode --- diff --git a/gui/include/Catalogue/CatalogueEventsWidget.h b/gui/include/Catalogue/CatalogueEventsWidget.h index 6a1025f..76fbb71 100644 --- a/gui/include/Catalogue/CatalogueEventsWidget.h +++ b/gui/include/Catalogue/CatalogueEventsWidget.h @@ -2,6 +2,7 @@ #define SCIQLOP_CATALOGUEEVENTSWIDGET_H #include +#include #include class DBCatalogue; @@ -12,6 +13,8 @@ namespace Ui { class CatalogueEventsWidget; } +Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueEventsWidget) + class CatalogueEventsWidget : public QWidget { Q_OBJECT diff --git a/gui/include/Visualization/VisualizationTabWidget.h b/gui/include/Visualization/VisualizationTabWidget.h index 0155bda..5299e6e 100644 --- a/gui/include/Visualization/VisualizationTabWidget.h +++ b/gui/include/Visualization/VisualizationTabWidget.h @@ -34,6 +34,10 @@ public: /// Returns the list of zone widget names in the order they are displayed QStringList availableZoneWidgets() const; + /// Returns the zone with the specified name. + /// If multiple zone with the same name exist, the first one is returned. + VisualizationZoneWidget *getZoneWithName(const QString &zoneName); + /** * Creates a zone using a variable. The variable will be displayed in a new graph of the new * zone. The zone is added at the end. diff --git a/gui/include/Visualization/VisualizationZoneWidget.h b/gui/include/Visualization/VisualizationZoneWidget.h index c13f26f..daa2525 100644 --- a/gui/include/Visualization/VisualizationZoneWidget.h +++ b/gui/include/Visualization/VisualizationZoneWidget.h @@ -1,6 +1,7 @@ #ifndef SCIQLOP_VISUALIZATIONZONEWIDGET_H #define SCIQLOP_VISUALIZATIONZONEWIDGET_H +#include "Data/SqpRange.h" #include "Visualization/IVisualizationWidget.h" #include "Visualization/VisualizationDragWidget.h" @@ -27,6 +28,10 @@ public: explicit VisualizationZoneWidget(const QString &name = {}, QWidget *parent = 0); virtual ~VisualizationZoneWidget(); + /// Sets the range of the zone, only works if there is at least one graph in the zone + /// Note: calibrations between graphs are lost. + void setZoneRange(const SqpRange &range); + /// Adds a graph widget void addGraph(VisualizationGraphWidget *graphWidget); diff --git a/gui/src/Catalogue/CatalogueEventsWidget.cpp b/gui/src/Catalogue/CatalogueEventsWidget.cpp index 5bd5e5d..fbd9f7a 100644 --- a/gui/src/Catalogue/CatalogueEventsWidget.cpp +++ b/gui/src/Catalogue/CatalogueEventsWidget.cpp @@ -8,11 +8,13 @@ #include #include #include +#include #include #include #include +Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget") /// Format of the dates appearing in the label of a cursor const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss"); @@ -20,7 +22,7 @@ const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss"); struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate { CatalogueEventsTableModel *m_Model = nullptr; - QString m_ZoneForTimeMode; + QStringList m_ZonesForTimeMode; QString m_ZoneForGraphMode; VisualizationWidget *m_VisualizationWidget = nullptr; @@ -128,6 +130,68 @@ struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate { return result; } + + void updateForTimeMode(QTableView *tableView) + { + auto selectedRows = tableView->selectionModel()->selectedRows(); + + if (selectedRows.count() == 1) { + auto event = m_Model->getEvent(selectedRows.first().row()); + if (m_VisualizationWidget) { + if (auto tab = m_VisualizationWidget->currentTabWidget()) { + + for (auto zoneName : m_ZonesForTimeMode) { + if (auto zone = tab->getZoneWithName(zoneName)) { + SqpRange eventRange; + eventRange.m_TStart = event.getTStart(); + eventRange.m_TEnd = event.getTEnd(); + zone->setZoneRange(eventRange); + } + } + } + else { + qCWarning(LOG_CatalogueEventsWidget()) + << "updateTimeZone: no tab found in the visualization"; + } + } + else { + qCWarning(LOG_CatalogueEventsWidget()) + << "updateTimeZone: visualization widget not found"; + } + } + else { + qCWarning(LOG_CatalogueEventsWidget()) + << "updateTimeZone: not compatible with multiple events selected"; + } + } + + void updateForGraphMode(QTableView *tableView) + { + auto selectedRows = tableView->selectionModel()->selectedRows(); + + if (selectedRows.count() == 1) { + auto event = m_Model->getEvent(selectedRows.first().row()); + if (m_VisualizationWidget) { + if (auto tab = m_VisualizationWidget->currentTabWidget()) { + if (auto zone = tab->getZoneWithName(m_ZoneForGraphMode)) { + // TODO + } + } + else { + qCWarning(LOG_CatalogueEventsWidget()) + << "updateGraphMode: no tab found in the visualization"; + } + } + else { + qCWarning(LOG_CatalogueEventsWidget()) + << "updateGraphMode: visualization widget not found"; + } + } + else { + qCWarning(LOG_CatalogueEventsWidget()) + << "updateGraphMode: not compatible with multiple events selected"; + } + } }; CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent) @@ -147,10 +211,11 @@ CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent) connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) { if (checked) { ui->btnChart->setChecked(false); - impl->m_ZoneForTimeMode - = impl->selectZone(this, {impl->m_ZoneForTimeMode}, false, - this->mapToGlobal(ui->btnTime->frameGeometry().center())) - .value(0); + impl->m_ZonesForTimeMode + = impl->selectZone(this, impl->m_ZonesForTimeMode, true, + this->mapToGlobal(ui->btnTime->frameGeometry().center())); + + impl->updateForTimeMode(ui->tableView); } }); @@ -161,6 +226,8 @@ CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent) = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false, this->mapToGlobal(ui->btnChart->frameGeometry().center())) .value(0); + + impl->updateForGraphMode(ui->tableView); } }); @@ -180,6 +247,13 @@ CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent) auto isNotMultiSelection = ui->tableView->selectionModel()->selectedRows().count() <= 1; ui->btnChart->setEnabled(isNotMultiSelection); ui->btnTime->setEnabled(isNotMultiSelection); + + if (isNotMultiSelection && ui->btnTime->isChecked()) { + impl->updateForTimeMode(ui->tableView); + } + else if (isNotMultiSelection && ui->btnChart->isChecked()) { + impl->updateForGraphMode(ui->tableView); + } }); ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); diff --git a/gui/src/Visualization/VisualizationTabWidget.cpp b/gui/src/Visualization/VisualizationTabWidget.cpp index 757fdef..957de0e 100644 --- a/gui/src/Visualization/VisualizationTabWidget.cpp +++ b/gui/src/Visualization/VisualizationTabWidget.cpp @@ -131,6 +131,18 @@ QStringList VisualizationTabWidget::availableZoneWidgets() const return zones; } +VisualizationZoneWidget *VisualizationTabWidget::getZoneWithName(const QString &zoneName) +{ + VisualizationZoneWidget *result = nullptr; + processZones(tabLayout(), [&zoneName, &result](VisualizationZoneWidget &zoneWidget) { + if (!result && zoneWidget.name() == zoneName) { + result = &zoneWidget; + } + }); + + return result; +} + VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr variable) { return createZone({variable}, -1); diff --git a/gui/src/Visualization/VisualizationZoneWidget.cpp b/gui/src/Visualization/VisualizationZoneWidget.cpp index 6c10a82..5f967a9 100644 --- a/gui/src/Visualization/VisualizationZoneWidget.cpp +++ b/gui/src/Visualization/VisualizationZoneWidget.cpp @@ -148,6 +148,17 @@ VisualizationZoneWidget::~VisualizationZoneWidget() delete ui; } +void VisualizationZoneWidget::setZoneRange(const SqpRange &range) +{ + if (auto graph = firstGraph()) { + graph->setGraphRange(range); + } + else { + qCWarning(LOG_VisualizationZoneWidget()) + << tr("setZoneRange:Cannot set the range of an empty zone."); + } +} + void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget) { // Synchronize new graph with others in the zone