##// END OF EJS Templates
New data sources system switch complete...
jeandet -
r1495:9c439b3d7daf
parent child
Show More
@@ -1,129 +1,130
1 1 #pragma once
2 2 #include <Data/DataProviderParameters.h>
3 3 #include <Data/DataSeriesType.h>
4 4 #include <Data/IDataProvider.h>
5 #include <DataSource/DataSourceController.h>
6 5 #include <DataSource/DataSourceItem.h>
7 6 #include <DataSource/DataSourceItemAction.h>
7 #include <DataSource/datasources.h>
8
8 9 #include <QPair>
9 10 #include <SqpApplication.h>
10 11 // must be included last because of Python/Qt definition of slots
11 12 #include "numpy_wrappers.h"
12 13
13 14 struct Product
14 15 {
15 16 QString path;
16 17 std::vector<std::string> components;
17 18 QMap<QString, QString> metadata;
18 19 Product() = default;
19 20 explicit Product(const QString& path, const std::vector<std::string>& components,
20 21 const QMap<QString, QString>& metadata)
21 22 : path { path }, components { components }, metadata { metadata }
22 23 {
23 24 }
24 25 ~Product() = default;
25 26 };
26 27
27 28 template <typename T>
28 29 ScalarTimeSerie* make_scalar(T& t, T& y)
29 30 {
30 31 return new ScalarTimeSerie { std::move(t.data), std::move(y.data) };
31 32 }
32 33
33 34 template <typename T>
34 35 VectorTimeSerie* make_vector(T& t, T& y)
35 36 {
36 37 return new VectorTimeSerie { std::move(t.data), y.to_std_vect_vect() };
37 38 }
38 39
39 40 template <typename T>
40 41 MultiComponentTimeSerie* make_multi_comp(T& t, T& y)
41 42 {
42 43 auto y_size = y.flat_size();
43 44 auto t_size = t.flat_size();
44 45 if (t_size && (y_size % t_size) == 0)
45 46 {
46 47 return new MultiComponentTimeSerie { std::move(t.data), std::move(y.data),
47 48 { t_size, y_size / t_size } };
48 49 }
49 50 return nullptr;
50 51 }
51 52
52 53 template <typename T>
53 54 SpectrogramTimeSerie* make_spectro(T& t, T& y)
54 55 {
55 56 auto y_size = y.flat_size();
56 57 auto t_size = t.flat_size();
57 58 if (t_size && (y_size % t_size) == 0)
58 59 {
59 60 return new SpectrogramTimeSerie { std::move(t.data), std::move(y.data),
60 61 { t_size, y_size / t_size } };
61 62 }
62 63 return nullptr;
63 64 }
64 65
65 66
66 67 class PyDataProvider : public IDataProvider
67 68 {
68 69 public:
69 70 PyDataProvider()
70 71 {
71 auto& dataSourceController = sqpApp->dataSourceController();
72 dataSourceController.registerProvider(this);
72 auto& dataSources = sqpApp->dataSources();
73 dataSources.addProvider(this);
73 74 }
74 75
75 76 virtual ~PyDataProvider() {}
76 77
77 78 virtual QPair<QPair<NpArray, NpArray>, DataSeriesType> get_data(
78 79 const QMap<QString, QString>& key, double start_time, double stop_time)
79 80 {
80 81 (void)key, (void)start_time, (void)stop_time;
81 82 return {};
82 83 }
83 84
84 85 virtual TimeSeries::ITimeSerie* getData(const DataProviderParameters& parameters) override
85 86 {
86 87 TimeSeries::ITimeSerie* ts = nullptr;
87 88 if (parameters.m_Data.contains("name"))
88 89 {
89 90 QMap<QString, QString> metadata;
90 91 std::for_each(parameters.m_Data.constKeyValueBegin(),
91 92 parameters.m_Data.constKeyValueEnd(),
92 93 [&metadata](const auto& item) { metadata[item.first] = item.second.toString(); });
93 94 auto [data, type]
94 95 = get_data(metadata, parameters.m_Range.m_TStart, parameters.m_Range.m_TEnd);
95 96
96 97 auto& [t, y] = data;
97 98 switch (type)
98 99 {
99 100 case DataSeriesType::SCALAR:
100 101 ts = make_scalar(t, y);
101 102 break;
102 103 case DataSeriesType::VECTOR:
103 104 ts = make_vector(t, y);
104 105 break;
105 106 case DataSeriesType::MULTICOMPONENT:
106 107 ts = make_multi_comp(t, y);
107 108 break;
108 109 case DataSeriesType::SPECTROGRAM:
109 110 ts = make_spectro(t, y);
110 111 break;
111 112 default:
112 113 break;
113 114 }
114 115 }
115 116 return ts;
116 117 }
117 118
118 119
119 120 inline void register_products(const QVector<Product*>& products)
120 121 {
121 auto& dataSourceController = sqpApp->dataSourceController();
122 auto& dataSources = sqpApp->dataSources();
122 123 auto id = this->id();
123 124 auto data_source_name = this->name();
124 125 std::for_each(std::cbegin(products), std::cend(products),
125 [&id, &dataSourceController](const Product* product) {
126 dataSourceController.setDataSourceItem(id, product->path, product->metadata);
126 [&id, &dataSources](const Product* product) {
127 dataSources.addDataSourceItem(id, product->path, product->metadata);
127 128 });
128 129 }
129 130 };
@@ -1,208 +1,203
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SciQLop Software
3 3 -- Copyright (C) 2017, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "MainWindow.h"
23 23 #include "ui_MainWindow.h"
24 24
25 25 #include <Catalogue/CatalogueController.h>
26 26 #include <Catalogue2/browser.h>
27 #include <DataSource/DataSourceController.h>
28 27 #include <DataSource/DataSourceItem.h>
29 28 #include <DataSource/DataSourceWidget.h>
30 29 #include <Settings/SqpSettingsDialog.h>
31 30 #include <Settings/SqpSettingsGeneralWidget.h>
32 31 #include <SidePane/SqpSidePane.h>
33 32 #include <SqpApplication.h>
34 33 #include <Time/TimeController.h>
35 34 #include <TimeWidget/TimeWidget.h>
36 35
37 36 #include "toolbar.h"
38 37
39 38 #include <QAction>
40 39 #include <QCloseEvent>
41 40 #include <QDate>
42 41 #include <QDir>
43 42 #include <QFileDialog>
44 43 #include <QMessageBox>
45 44 #include <QToolBar>
46 45 #include <QToolButton>
47 46 #include <memory.h>
48 47
49 48
50 49 Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow")
51 50
52 51 class MainWindow::MainWindowPrivate
53 52 {
54 53 public:
55 54 explicit MainWindowPrivate(MainWindow* mainWindow)
56 55 : m_GeneralSettingsWidget { new SqpSettingsGeneralWidget { mainWindow } }
57 56 , m_SettingsDialog { new SqpSettingsDialog { mainWindow } }
58 57 , m_CatalogExplorer { new CataloguesBrowser { mainWindow } }
59 58 {
60 59 }
61 60
62 61 /// General settings widget. MainWindow has the ownership
63 62 SqpSettingsGeneralWidget* m_GeneralSettingsWidget;
64 63 /// Settings dialog. MainWindow has the ownership
65 64 SqpSettingsDialog* m_SettingsDialog;
66 65 /// Catalogue dialog. MainWindow has the ownership
67 66 CataloguesBrowser* m_CatalogExplorer;
68 67
69 68 bool checkDataToSave(QWidget* parentWidget);
70 69 };
71 70
72 71 MainWindow::MainWindow(QWidget* parent)
73 72 : QMainWindow { parent }
74 73 , m_Ui { new Ui::MainWindow }
75 74 , impl { spimpl::make_unique_impl<MainWindowPrivate>(this) }
76 75 {
77 76 m_Ui->setupUi(this);
78 77 setWindowTitle(QString("SciQLop v%1").arg(SCIQLOP_VERSION));
79 78
80 79 // //////////////// //
81 80 // Menu and Toolbar //
82 81 // //////////////// //
83 82 this->menuBar()->addAction(tr("File"));
84 83 auto toolsMenu = this->menuBar()->addMenu(tr("Tools"));
85 84 toolsMenu->addAction(tr("Settings..."), [this]() {
86 85 // Loads settings
87 86 impl->m_SettingsDialog->loadSettings();
88 87
89 88 // Open settings dialog and save settings if the dialog is accepted
90 89 if (impl->m_SettingsDialog->exec() == QDialog::Accepted)
91 90 {
92 91 impl->m_SettingsDialog->saveSettings();
93 92 }
94 93 });
95 94 auto mainToolBar = new ToolBar(this);
96 95 this->addToolBar(mainToolBar);
97 96 connect(mainToolBar, &ToolBar::setPlotsInteractionMode, sqpApp,
98 97 &SqpApplication::setPlotsInteractionMode);
99 98 connect(mainToolBar, &ToolBar::setPlotsCursorMode, sqpApp, &SqpApplication::setPlotsCursorMode);
100 99 connect(mainToolBar, &ToolBar::showCataloguesBrowser,
101 100 [this]() { impl->m_CatalogExplorer->show(); });
102 101
103 102 // //////// //
104 103 // Settings //
105 104 // //////// //
106 105
107 106 // Registers "general settings" widget to the settings dialog
108 107 impl->m_SettingsDialog->registerWidget(
109 108 QStringLiteral("General"), impl->m_GeneralSettingsWidget);
110 109
111 110 // /////////// //
112 111 // Connections //
113 112 // /////////// //
114 113
115 114 // Widgets / controllers connections
116 115
117 // DataSource
118 connect(&sqpApp->dataSourceController(), &DataSourceController::dataSourceItemSet,
119 m_Ui->dataSourceWidget, &DataSourceWidget::addDataSource);
120
121 116 // Time
122 117 // connect(timeWidget, SIGNAL(timeUpdated(DateTimeRange)), &sqpApp->timeController(),
123 118 // SLOT(onTimeToUpdate(DateTimeRange)));
124 119 connect(mainToolBar, &ToolBar::timeUpdated, &sqpApp->timeController(),
125 120 &TimeController::setDateTimeRange);
126 121
127 122 // Widgets / widgets connections
128 123
129 124 // For the following connections, we use DirectConnection to allow each widget that can
130 125 // potentially attach a menu to the variable's menu to do so before this menu is displayed.
131 126 // The order of connections is also important, since it determines the order in which each
132 127 // widget will attach its menu
133 128 connect(m_Ui->variableInspectorWidget,
134 129 SIGNAL(tableMenuAboutToBeDisplayed(QMenu*, const QVector<std::shared_ptr<Variable>>&)),
135 130 m_Ui->view, SLOT(attachVariableMenu(QMenu*, const QVector<std::shared_ptr<Variable>>&)),
136 131 Qt::DirectConnection);
137 132 }
138 133
139 134 MainWindow::~MainWindow() {}
140 135
141 136 void MainWindow::changeEvent(QEvent* e)
142 137 {
143 138 QMainWindow::changeEvent(e);
144 139 switch (e->type())
145 140 {
146 141 case QEvent::LanguageChange:
147 142 m_Ui->retranslateUi(this);
148 143 break;
149 144 default:
150 145 break;
151 146 }
152 147 }
153 148
154 149 void MainWindow::closeEvent(QCloseEvent* event)
155 150 {
156 151 if (!impl->checkDataToSave(this))
157 152 {
158 153 event->ignore();
159 154 }
160 155 else
161 156 {
162 157 event->accept();
163 158 }
164 159 }
165 160
166 161 void MainWindow::keyPressEvent(QKeyEvent* event)
167 162 {
168 163 switch (event->key())
169 164 {
170 165 case Qt::Key_F11:
171 166 if (this->isFullScreen())
172 167 {
173 168 this->showNormal();
174 169 }
175 170 else
176 171 {
177 172 this->showFullScreen();
178 173 }
179 174 break;
180 175 default:
181 176 break;
182 177 }
183 178 }
184 179
185 180 bool MainWindow::MainWindowPrivate::checkDataToSave(QWidget* parentWidget)
186 181 {
187 182 // auto hasChanges = sqpApp->catalogueController().hasChanges();
188 183 // if (hasChanges)
189 184 // {
190 185 // // There are some unsaved changes
191 186 // switch (QMessageBox::question(parentWidget, tr("Save changes"),
192 187 // tr("The catalogue controller has unsaved changes.\nDo you want to save them ?"),
193 188 // QMessageBox::SaveAll | QMessageBox::Discard | QMessageBox::Cancel,
194 189 // QMessageBox::SaveAll))
195 190 // {
196 191 // case QMessageBox::SaveAll:
197 192 // sqpApp->catalogueController().saveAll();
198 193 // break;
199 194 // case QMessageBox::Discard:
200 195 // break;
201 196 // case QMessageBox::Cancel:
202 197 // default:
203 198 // return false;
204 199 // }
205 200 // }
206 201
207 202 return true;
208 203 }
@@ -1,1 +1,1
1 Subproject commit b081849458c211dcc59f72b11542959db2301162
1 Subproject commit 46467fb43b8d07fe4f4a45df949ec4ae858ccf9d
@@ -1,47 +1,35
1 1 #ifndef SCIQLOP_DATASOURCEWIDGET_H
2 2 #define SCIQLOP_DATASOURCEWIDGET_H
3 3
4 4 #include <QWidget>
5 5
6 #include <memory>
6 #include <QSortFilterProxyModel>
7 7
8 namespace Ui {
8 namespace Ui
9 {
9 10 class DataSourceWidget;
10 11 } // Ui
11 12
12 13 class DataSourceItem;
13 14
14 15 /**
15 16 * @brief The DataSourceWidget handles the graphical representation (as a tree) of the data sources
16 17 * attached to SciQlop.
17 18 */
18 class DataSourceWidget : public QWidget {
19 class DataSourceWidget : public QWidget
20 {
19 21 Q_OBJECT
20 22
21 23 public:
22 explicit DataSourceWidget(QWidget *parent = 0);
24 explicit DataSourceWidget(QWidget* parent = 0);
23 25 virtual ~DataSourceWidget() noexcept;
24 26
25 public slots:
26 /**
27 * Adds a data source. An item associated to the data source is created and then added to the
28 * representation tree
29 * @param dataSource the data source to add. The pointer has to be not null
30 */
31 void addDataSource(DataSourceItem *dataSource) noexcept;
32
33 27 private:
34 28 void updateTreeWidget() noexcept;
35 29
36 Ui::DataSourceWidget *ui;
37 std::unique_ptr<DataSourceItem> m_Root;
38
39 private slots:
40 /// Slot called when the filtering text has changed
41 void filterChanged(const QString &text) noexcept;
30 Ui::DataSourceWidget* ui;
31 QSortFilterProxyModel m_model_proxy;
42 32
43 /// Slot called when right clicking on an item in the tree (displays a menu)
44 void onTreeMenuRequested(const QPoint &pos) noexcept;
45 33 };
46 34
47 35 #endif // SCIQLOP_DATASOURCEWIDGET_H
@@ -1,118 +1,120
1 1 #ifndef SCIQLOP_SQPAPPLICATION_H
2 2 #define SCIQLOP_SQPAPPLICATION_H
3 3
4 4 #include "SqpApplication.h"
5 5
6 6 #include <QAction>
7 7 #include <QApplication>
8 8 #include <QLoggingCategory>
9 9 #include <QMenuBar>
10 10 #include <QProxyStyle>
11 11 #include <QStyleOption>
12 12 #include <QWidget>
13 13 #include <QWidgetAction>
14 14
15 15 #include <Common/spimpl.h>
16 16
17 17 Q_DECLARE_LOGGING_CATEGORY(LOG_SqpApplication)
18 18
19 19 #if defined(sqpApp)
20 20 #undef sqpApp
21 21 #endif
22 22 #define sqpApp (static_cast<SqpApplication*>(QCoreApplication::instance()))
23 23
24 24 class DataSourceController;
25 class DataSources;
25 26 class NetworkController;
26 27 class TimeController;
27 28 class VariableController;
28 29 class VariableController2;
29 30 class VariableModel2;
30 31 class DragDropGuiController;
31 32 class ActionsGuiController;
32 33 class CatalogueController;
33 34
34 35 /* stolen from here https://forum.qt.io/topic/90403/show-tooltip-immediatly/6 */
35 36 class MyProxyStyle : public QProxyStyle
36 37 {
37 38 public:
38 39 using QProxyStyle::QProxyStyle;
39 40
40 41 int styleHint(StyleHint hint, const QStyleOption* option = nullptr,
41 42 const QWidget* widget = nullptr, QStyleHintReturn* returnData = nullptr) const override
42 43 {
43 44 if (hint == QStyle::SH_ToolButton_PopupDelay && widget
44 45 /*&& widget->inherits(QWidgetAction::staticMetaObject.className())*/)
45 46 {
46 47 return 0;
47 48 }
48 49
49 50 return QProxyStyle::styleHint(hint, option, widget, returnData);
50 51 }
51 52 };
52 53
53 54 /**
54 55 * @brief The SqpApplication class aims to make the link between SciQlop
55 56 * and its plugins. This is the intermediate class that SciQlop has to use
56 57 * in the way to connect a data source. Please first use load method to initialize
57 58 * a plugin specified by its metadata name (JSON plugin source) then others specifics
58 59 * method will be able to access it.
59 60 * You can load a data source driver plugin then create a data source.
60 61 */
61 62
62 63 class SqpApplication : public QApplication
63 64 {
64 65 Q_OBJECT
65 66 public:
66 67 explicit SqpApplication(int& argc, char** argv);
67 68 ~SqpApplication() override;
68 69 void initialize();
69 70
70 71 /// Accessors for the differents sciqlop controllers
71 DataSourceController& dataSourceController() noexcept;
72 //DataSourceController& dataSourceController() noexcept;
73 DataSources& dataSources() noexcept;
72 74 NetworkController& networkController() noexcept;
73 75 TimeController& timeController() noexcept;
74 76 VariableController2& variableController() noexcept;
75 77 std::shared_ptr<VariableController2> variableControllerOwner() noexcept;
76 78 CatalogueController& catalogueController() noexcept;
77 79
78 80 /// Accessors for the differents sciqlop helpers, these helpers classes are like controllers but
79 81 /// doesn't live in a thread and access gui
80 82 DragDropGuiController& dragDropGuiController() noexcept;
81 83 ActionsGuiController& actionsGuiController() noexcept;
82 84
83 85 enum class PlotsInteractionMode
84 86 {
85 87 None,
86 88 ZoomBox,
87 89 DragAndDrop,
88 90 SelectionZones
89 91 };
90 92
91 93 enum class PlotsCursorMode
92 94 {
93 95 NoCursor,
94 96 Vertical,
95 97 Temporal,
96 98 Horizontal,
97 99 Cross
98 100 };
99 101
100 102 PlotsInteractionMode plotsInteractionMode() const;
101 103 void setPlotsInteractionMode(PlotsInteractionMode mode);
102 104
103 105 PlotsCursorMode plotsCursorMode() const;
104 106 void setPlotsCursorMode(PlotsCursorMode mode);
105 107
106 108 private:
107 109 class SqpApplicationPrivate;
108 110 spimpl::unique_impl_ptr<SqpApplicationPrivate> impl;
109 111 };
110 112
111 113 inline SqpApplication* SqpApplication_ctor()
112 114 {
113 115 static int argc;
114 116 static char** argv;
115 117 return new SqpApplication(argc, argv);
116 118 }
117 119
118 120 #endif // SCIQLOP_SQPAPPLICATION_H
@@ -1,179 +1,173
1 1
2 2 gui_moc_headers = [
3 3 './include/Common/VisualizationDef.h',
4 4 './include/Common/ColorUtils.h',
5 5 './include/DragAndDrop/DragDropGuiController.h',
6 6 './include/DragAndDrop/DragDropTabSwitcher.h',
7 7 './include/DragAndDrop/DragDropScroller.h',
8 8 './include/Settings/SqpSettingsDialog.h',
9 9 './include/Settings/SqpSettingsGeneralWidget.h',
10 './include/DataSource/DataSourceTreeWidgetHelper.h',
11 './include/DataSource/DataSourceTreeWidget.h',
12 './include/DataSource/DataSourceTreeWidgetItem.h',
13 10 './include/DataSource/DataSourceWidget.h',
14 11 './include/Catalogue2/repositoriestreeview.h',
15 12 './include/Catalogue2/browser.h',
16 13 './include/Catalogue2/eventeditor.h',
17 14 './include/Catalogue2/eventsmodel.h',
18 15 './include/Catalogue2/eventstreeview.h',
19 16 './include/Catalogue2/repositoriesmodel.h',
20 17 './include/TimeWidget/TimeWidget.h',
21 18 './include/SqpApplication.h',
22 19 './include/SidePane/SqpSidePane.h',
23 20 './include/Variable/RenameVariableDialog.h',
24 21 './include/Variable/VariableInspectorWidget.h',
25 22 './include/Variable/VariableInspectorTableView.h',
26 23 './include/Variable/VariableMenuHeaderWidget.h',
27 24 './include/Visualization/VisualizationDragWidget.h',
28 25 './include/Visualization/VisualizationZoneWidget.h',
29 26 './include/Visualization/operations/GenerateVariableMenuOperation.h',
30 27 './include/Visualization/operations/RescaleAxeOperation.h',
31 28 './include/Visualization/operations/RemoveVariableOperation.h',
32 29 './include/Visualization/operations/MenuBuilder.h',
33 30 './include/Visualization/operations/FindVariableOperation.h',
34 31 './include/Visualization/VisualizationDefs.h',
35 32 './include/Visualization/IVisualizationWidgetVisitor.h',
36 33 './include/Visualization/SqpColorScale.h',
37 34 './include/Visualization/VisualizationGraphRenderingDelegate.h',
38 35 './include/Visualization/VisualizationGraphWidget.h',
39 36 './include/Visualization/MacScrollBarStyle.h',
40 37 './include/Visualization/IVisualizationWidget.h',
41 38 './include/Visualization/qcustomplot.h',
42 39 './include/Visualization/IGraphSynchronizer.h',
43 40 './include/Visualization/QCPColorMapIterator.h',
44 41 './include/Visualization/VisualizationActionManager.h',
45 42 './include/Visualization/VisualizationTabWidget.h',
46 43 './include/Visualization/IVariableContainer.h',
47 44 './include/Visualization/AxisRenderingUtils.h',
48 45 './include/Visualization/VisualizationMultiZoneSelectionDialog.h',
49 46 './include/Visualization/VisualizationCursorItem.h',
50 47 './include/Visualization/VisualizationWidget.h',
51 48 './include/Visualization/PlottablesRenderingUtils.h',
52 49 './include/Visualization/VisualizationSelectionZoneManager.h',
53 50 './include/Visualization/QCustomPlotSynchronizer.h',
54 51 './include/Visualization/VisualizationSelectionZoneItem.h',
55 52 './include/Visualization/VisualizationDragDropContainer.h',
56 53 './include/Visualization/ColorScaleEditor.h',
57 54 './include/Visualization/VisualizationGraphHelper.h',
58 55 './include/Actions/ActionsGuiController.h',
59 56 './include/Actions/FilteringAction.h',
60 57 './include/Actions/SelectionZoneAction.h'
61 58 ]
62 59
63 60
64 61 gui_ui_files = [
65 62 './ui/Settings/SqpSettingsGeneralWidget.ui',
66 63 './ui/Settings/SqpSettingsDialog.ui',
67 64 './ui/DataSource/DataSourceWidget.ui',
68 65 './ui/Catalogue2/browser.ui',
69 66 './ui/Catalogue2/eventeditor.ui',
70 67 './ui/TimeWidget/TimeWidget.ui',
71 68 './ui/SidePane/SqpSidePane.ui',
72 69 './ui/Variable/RenameVariableDialog.ui',
73 70 './ui/Variable/VariableInspectorWidget.ui',
74 71 './ui/Variable/VariableMenuHeaderWidget.ui',
75 72 './ui/Visualization/ColorScaleEditor.ui',
76 73 './ui/Visualization/VisualizationZoneWidget.ui',
77 74 './ui/Visualization/VisualizationMultiZoneSelectionDialog.ui',
78 75 './ui/Visualization/VisualizationGraphWidget.ui',
79 76 './ui/Visualization/VisualizationWidget.ui',
80 77 './ui/Visualization/VisualizationTabWidget.ui'
81 78 ]
82 79
83 80 gui_qresources = ['resources/sqpguiresources.qrc']
84 81
85 82 rcc_gen = generator(rcc,
86 83 output : 'qrc_@BASENAME@.cpp',
87 84 arguments : [
88 85 '--output',
89 86 '@OUTPUT@',
90 87 '@INPUT@',
91 88 '@EXTRA_ARGS@'])
92 89
93 90 rcc_files = rcc_gen.process(gui_qresources, extra_args : ['-name', 'sqpguiresources'])
94 91
95 92 gui_moc_files = qt5.preprocess(moc_headers : gui_moc_headers,
96 93 ui_files : gui_ui_files)
97 94
98 95 gui_sources = [
99 96 './src/Common/ColorUtils.cpp',
100 97 './src/Common/VisualizationDef.cpp',
101 98 './src/SqpApplication.cpp',
102 99 './src/DragAndDrop/DragDropTabSwitcher.cpp',
103 100 './src/DragAndDrop/DragDropScroller.cpp',
104 101 './src/DragAndDrop/DragDropGuiController.cpp',
105 102 './src/Settings/SqpSettingsGeneralWidget.cpp',
106 103 './src/Settings/SqpSettingsDialog.cpp',
107 './src/DataSource/DataSourceTreeWidgetItem.cpp',
108 './src/DataSource/DataSourceTreeWidgetHelper.cpp',
109 104 './src/DataSource/DataSourceWidget.cpp',
110 './src/DataSource/DataSourceTreeWidget.cpp',
111 105 './src/Catalogue2/eventstreeview.cpp',
112 106 './src/Catalogue2/eventeditor.cpp',
113 107 './src/Catalogue2/repositoriestreeview.cpp',
114 108 './src/Catalogue2/browser.cpp',
115 109 './src/Catalogue2/eventsmodel.cpp',
116 110 './src/Catalogue2/repositoriesmodel.cpp',
117 111 './src/TimeWidget/TimeWidget.cpp',
118 112 './src/SidePane/SqpSidePane.cpp',
119 113 './src/Variable/VariableInspectorTableView.cpp',
120 114 './src/Variable/VariableInspectorWidget.cpp',
121 115 './src/Variable/RenameVariableDialog.cpp',
122 116 './src/Variable/VariableMenuHeaderWidget.cpp',
123 117 './src/Visualization/VisualizationGraphWidget.cpp',
124 118 './src/Visualization/PlottablesRenderingUtils.cpp',
125 119 './src/Visualization/AxisRenderingUtils.cpp',
126 120 './src/Visualization/VisualizationWidget.cpp',
127 121 './src/Visualization/qcustomplot.cpp',
128 122 './src/Visualization/VisualizationDragWidget.cpp',
129 123 './src/Visualization/VisualizationActionManager.cpp',
130 124 './src/Visualization/MacScrollBarStyle.cpp',
131 125 './src/Visualization/VisualizationSelectionZoneManager.cpp',
132 126 './src/Visualization/operations/FindVariableOperation.cpp',
133 127 './src/Visualization/operations/RescaleAxeOperation.cpp',
134 128 './src/Visualization/operations/MenuBuilder.cpp',
135 129 './src/Visualization/operations/GenerateVariableMenuOperation.cpp',
136 130 './src/Visualization/operations/RemoveVariableOperation.cpp',
137 131 './src/Visualization/VisualizationSelectionZoneItem.cpp',
138 132 './src/Visualization/VisualizationCursorItem.cpp',
139 133 './src/Visualization/QCPColorMapIterator.cpp',
140 134 './src/Visualization/QCustomPlotSynchronizer.cpp',
141 135 './src/Visualization/ColorScaleEditor.cpp',
142 136 './src/Visualization/VisualizationMultiZoneSelectionDialog.cpp',
143 137 './src/Visualization/VisualizationTabWidget.cpp',
144 138 './src/Visualization/VisualizationGraphHelper.cpp',
145 139 './src/Visualization/VisualizationGraphRenderingDelegate.cpp',
146 140 './src/Visualization/VisualizationDragDropContainer.cpp',
147 141 './src/Visualization/VisualizationZoneWidget.cpp',
148 142 './src/Visualization/SqpColorScale.cpp',
149 143 './src/Actions/FilteringAction.cpp',
150 144 './src/Actions/SelectionZoneAction.cpp',
151 145 './src/Actions/ActionsGuiController.cpp'
152 146 ]
153 147
154 148 gui_inc = include_directories(['include', 'include/Visualization'])
155 149
156 150 sciqlop_gui_lib = library('sciqlopgui',
157 151 gui_sources,
158 152 gui_moc_files,
159 153 rcc_files,
160 154 include_directories : [gui_inc],
161 155 dependencies : [ qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core],
162 156 install : true
163 157 )
164 158
165 159 sciqlop_gui = declare_dependency(link_with : sciqlop_gui_lib,
166 160 include_directories : gui_inc,
167 161 dependencies : [qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core])
168 162
169 163 gui_tests_inc = include_directories(['tests/GUITestUtils'])
170 164
171 165 catalogue_browser_moc_files = qt5.preprocess(moc_sources : 'tests/catalogue/browser/main.cpp')
172 166 catalogue_browser = executable('catalogue_browser', 'tests/catalogue/browser/main.cpp',catalogue_browser_moc_files,
173 167 include_directories : gui_tests_inc,
174 168 dependencies :[sciqlop_gui, qt5test])
175 169
176 170
177 171 if get_option('biuld_gui_tests')
178 172 subdir('tests')
179 173 endif
@@ -1,124 +1,42
1 1 #include <DataSource/DataSourceWidget.h>
2 2
3 3 #include <ui_DataSourceWidget.h>
4 4
5 #include <DataSource/DataSourceItem.h>
6 #include <DataSource/DataSourceTreeWidgetHelper.h>
7 #include <DataSource/DataSourceTreeWidgetItem.h>
5 #include <DataSource/datasources.h>
6
7 #include <SqpApplication.h>
8 8
9 #include <QMenu>
10 9
11 10 namespace
12 11 {
13 12
14 13 /// Number of columns displayed in the tree
15 14 const auto TREE_NB_COLUMNS = 1;
16 15
17 16 /// Header labels for the tree
18 17 const auto TREE_HEADER_LABELS = QStringList { QObject::tr("Name") };
19 18
20 /**
21 * Creates the item associated to a data source
22 * @param dataSource the data source for which to create the item
23 * @return the new item
24 */
25 DataSourceTreeWidgetItem* createTreeWidgetItem(DataSourceItem* dataSource)
26 {
27 // Creates item for the data source
28 auto item = new DataSourceTreeWidgetItem { dataSource };
29 // Generates items for the children of the data source
30 std::for_each(dataSource->cbegin(), dataSource->cend(),
31 [&item](const std::unique_ptr<DataSourceItem>& child) {
32 item->addChild(createTreeWidgetItem(child.get()));
33 });
34 return item;
35 }
36
37 19 } // namespace
38 20
39 21 DataSourceWidget::DataSourceWidget(QWidget* parent)
40 22 : QWidget { parent }
41 23 , ui { new Ui::DataSourceWidget }
42 , m_Root { std::make_unique<DataSourceItem>(
43 DataSourceItemType::NODE, QStringLiteral("Sources")) }
44 24 {
45 25 ui->setupUi(this);
46
47 // Set tree properties
48 ui->treeWidget->setColumnCount(TREE_NB_COLUMNS);
49 ui->treeWidget->setHeaderLabels(TREE_HEADER_LABELS);
50 ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
51
52 // Connection to show a menu when right clicking on the tree
53 connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this,
54 &DataSourceWidget::onTreeMenuRequested);
26 m_model_proxy.setSourceModel(&(sqpApp->dataSources()));
27 ui->treeView->setModel(&m_model_proxy);
28 ui->treeView->setDragEnabled(true);
29 m_model_proxy.setFilterRole(Qt::ToolTipRole);
30 m_model_proxy.setRecursiveFilteringEnabled(true);
55 31
56 32 // Connection to filter tree
57 connect(ui->filterLineEdit, &QLineEdit::textChanged, this, &DataSourceWidget::filterChanged);
33 connect(ui->filterLineEdit, &QLineEdit::textChanged, &m_model_proxy, static_cast<void (QSortFilterProxyModel::*)(const QString&)>(
34 &QSortFilterProxyModel::setFilterRegExp));
58 35
59 // First init
60 updateTreeWidget();
61 36 }
62 37
63 38 DataSourceWidget::~DataSourceWidget() noexcept
64 39 {
65 40 delete ui;
66 41 }
67 42
68 void DataSourceWidget::addDataSource(DataSourceItem* dataSource) noexcept
69 {
70 // Merges the data source (without taking its root)
71 if (dataSource)
72 {
73 std::for_each(std::cbegin(*dataSource), std::cend(*dataSource),
74 [this](const auto& child) { this->m_Root->merge(*child.get()); });
75 updateTreeWidget();
76 }
77 }
78
79 void DataSourceWidget::updateTreeWidget() noexcept
80 {
81 ui->treeWidget->clear();
82
83 auto rootItem = createTreeWidgetItem(m_Root.get());
84 ui->treeWidget->addTopLevelItem(rootItem);
85 rootItem->setExpanded(true);
86
87 // Sorts tree
88 ui->treeWidget->setSortingEnabled(true);
89 ui->treeWidget->sortByColumn(0, Qt::AscendingOrder);
90 }
91
92 void DataSourceWidget::filterChanged(const QString& text) noexcept
93 {
94 auto validateItem = [&text](const DataSourceTreeWidgetItem& item) {
95 auto regExp = QRegExp { text, Qt::CaseInsensitive, QRegExp::Wildcard };
96
97 // An item is valid if any of its metadata validates the text filter
98 auto itemMetadata = item.data()->data();
99 auto itemMetadataEnd = itemMetadata.cend();
100 auto acceptFilter
101 = [&regExp](const auto& variant) { return variant.toString().contains(regExp); };
102
103 return std::find_if(itemMetadata.cbegin(), itemMetadataEnd, acceptFilter)
104 != itemMetadataEnd;
105 };
106
107 // Applies filter on tree widget
108 DataSourceTreeWidgetHelper::filter(*ui->treeWidget, validateItem);
109 }
110
111 void DataSourceWidget::onTreeMenuRequested(const QPoint& pos) noexcept
112 {
113 // Retrieves the selected item in the tree, and build the menu from its actions
114 if (auto selectedItem = dynamic_cast<DataSourceTreeWidgetItem*>(ui->treeWidget->itemAt(pos)))
115 {
116 QMenu treeMenu {};
117 treeMenu.addActions(selectedItem->actions());
118
119 if (!treeMenu.isEmpty())
120 {
121 treeMenu.exec(QCursor::pos());
122 }
123 }
124 }
@@ -1,331 +1,330
1 1 #include "DragAndDrop/DragDropGuiController.h"
2 2 #include "DragAndDrop/DragDropScroller.h"
3 3 #include "DragAndDrop/DragDropTabSwitcher.h"
4 4 #include "SqpApplication.h"
5 5 #include "Visualization/VisualizationDragDropContainer.h"
6 6 #include "Visualization/VisualizationDragWidget.h"
7 7 #include "Visualization/VisualizationWidget.h"
8 8 #include "Visualization/operations/FindVariableOperation.h"
9 9
10 #include "DataSource/DataSourceController.h"
11 10 #include "Variable/VariableController2.h"
12 11
13 #include "Common/MimeTypesDef.h"
12 #include "MimeTypes/MimeTypes.h"
14 13 #include "Common/VisualizationDef.h"
15 14
16 15 #include <QDir>
17 16 #include <QLabel>
18 17 #include <QUrl>
19 18 #include <QVBoxLayout>
20 19
21 20
22 21 Q_LOGGING_CATEGORY(LOG_DragDropGuiController, "DragDropGuiController")
23 22
24 23
25 24 struct DragDropGuiController::DragDropGuiControllerPrivate
26 25 {
27 26
28 27 VisualizationDragWidget* m_CurrentDragWidget = nullptr;
29 28 std::unique_ptr<QWidget> m_PlaceHolder = nullptr;
30 29 QLabel* m_PlaceHolderLabel;
31 30 QWidget* m_PlaceBackground;
32 31 std::unique_ptr<DragDropScroller> m_DragDropScroller = nullptr;
33 32 std::unique_ptr<DragDropTabSwitcher> m_DragDropTabSwitcher = nullptr;
34 33 QString m_ImageTempUrl; // Temporary file for image url generated by the drag & drop. Not using
35 34 // QTemporaryFile to have a name which is not generated.
36 35
37 36 VisualizationDragWidget* m_HighlightedDragWidget = nullptr;
38 37
39 38 QMetaObject::Connection m_DragWidgetDestroyedConnection;
40 39 QMetaObject::Connection m_HighlightedWidgetDestroyedConnection;
41 40
42 41 QList<QWidget*> m_WidgetToClose;
43 42
44 43 explicit DragDropGuiControllerPrivate()
45 44 : m_PlaceHolder { std::make_unique<QWidget>() }
46 45 , m_DragDropScroller { std::make_unique<DragDropScroller>() }
47 46 , m_DragDropTabSwitcher { std::make_unique<DragDropTabSwitcher>() }
48 47 {
49 48
50 49 auto layout = new QVBoxLayout { m_PlaceHolder.get() };
51 50 layout->setSpacing(0);
52 51 layout->setContentsMargins(0, 0, 0, 0);
53 52
54 53 m_PlaceHolderLabel = new QLabel { "", m_PlaceHolder.get() };
55 54 m_PlaceHolderLabel->setMinimumHeight(25);
56 55 layout->addWidget(m_PlaceHolderLabel);
57 56
58 57 m_PlaceBackground = new QWidget { m_PlaceHolder.get() };
59 58 m_PlaceBackground->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
60 59 layout->addWidget(m_PlaceBackground);
61 60
62 61 sqpApp->installEventFilter(m_DragDropScroller.get());
63 62 sqpApp->installEventFilter(m_DragDropTabSwitcher.get());
64 63
65 64 m_ImageTempUrl = QDir::temp().absoluteFilePath("Sciqlop_graph.png");
66 65 }
67 66
68 67 void preparePlaceHolder(
69 68 DragDropGuiController::PlaceHolderType type, const QString& topLabelText) const
70 69 {
71 70 if (m_CurrentDragWidget)
72 71 {
73 72 m_PlaceHolder->setMinimumSize(m_CurrentDragWidget->size());
74 73 m_PlaceHolder->setSizePolicy(m_CurrentDragWidget->sizePolicy());
75 74 }
76 75 else
77 76 {
78 77 // Configuration of the placeHolder when there is no dragWidget
79 78 // (for instance with a drag from a variable)
80 79
81 80 m_PlaceHolder->setMinimumSize(0, GRAPH_MINIMUM_HEIGHT);
82 81 m_PlaceHolder->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
83 82 }
84 83
85 84 switch (type)
86 85 {
87 86 case DragDropGuiController::PlaceHolderType::Graph:
88 87 m_PlaceBackground->setStyleSheet(
89 88 "background-color: #BBD5EE; border: 1px solid #2A7FD4");
90 89 break;
91 90 case DragDropGuiController::PlaceHolderType::Zone:
92 91 case DragDropGuiController::PlaceHolderType::Default:
93 92 m_PlaceBackground->setStyleSheet(
94 93 "background-color: #BBD5EE; border: 2px solid #2A7FD4");
95 94 m_PlaceHolderLabel->setStyleSheet("color: #2A7FD4");
96 95 break;
97 96 }
98 97
99 98 m_PlaceHolderLabel->setText(topLabelText);
100 99 m_PlaceHolderLabel->setVisible(!topLabelText.isEmpty());
101 100 }
102 101 };
103 102
104 103
105 104 DragDropGuiController::DragDropGuiController()
106 105 : impl { spimpl::make_unique_impl<DragDropGuiControllerPrivate>() }
107 106 {
108 107 }
109 108
110 109 DragDropGuiController::~DragDropGuiController()
111 110 {
112 111 QFile::remove(impl->m_ImageTempUrl);
113 112 }
114 113
115 114 void DragDropGuiController::resetDragAndDrop()
116 115 {
117 116 setCurrentDragWidget(nullptr);
118 117 impl->m_HighlightedDragWidget = nullptr;
119 118 }
120 119
121 120 void DragDropGuiController::setCurrentDragWidget(VisualizationDragWidget* dragWidget)
122 121 {
123 122 if (impl->m_CurrentDragWidget)
124 123 {
125 124
126 125 QObject::disconnect(impl->m_DragWidgetDestroyedConnection);
127 126 }
128 127
129 128 if (dragWidget)
130 129 {
131 130 // ensures the impl->m_CurrentDragWidget is reset when the widget is destroyed
132 131 impl->m_DragWidgetDestroyedConnection = QObject::connect(dragWidget,
133 132 &VisualizationDragWidget::destroyed, [this]() { impl->m_CurrentDragWidget = nullptr; });
134 133 }
135 134
136 135 impl->m_CurrentDragWidget = dragWidget;
137 136 }
138 137
139 138 VisualizationDragWidget* DragDropGuiController::getCurrentDragWidget() const
140 139 {
141 140 return impl->m_CurrentDragWidget;
142 141 }
143 142
144 143 QWidget& DragDropGuiController::placeHolder() const
145 144 {
146 145 return *impl->m_PlaceHolder;
147 146 }
148 147
149 148 void DragDropGuiController::insertPlaceHolder(
150 149 QVBoxLayout* layout, int index, PlaceHolderType type, const QString& topLabelText)
151 150 {
152 151 removePlaceHolder();
153 152 impl->preparePlaceHolder(type, topLabelText);
154 153 layout->insertWidget(index, impl->m_PlaceHolder.get());
155 154 impl->m_PlaceHolder->show();
156 155 }
157 156
158 157 void DragDropGuiController::removePlaceHolder()
159 158 {
160 159 auto parentWidget = impl->m_PlaceHolder->parentWidget();
161 160 if (parentWidget)
162 161 {
163 162 parentWidget->layout()->removeWidget(impl->m_PlaceHolder.get());
164 163 impl->m_PlaceHolder->setParent(nullptr);
165 164 impl->m_PlaceHolder->hide();
166 165 }
167 166 }
168 167
169 168 bool DragDropGuiController::isPlaceHolderSet() const
170 169 {
171 170 return impl->m_PlaceHolder->parentWidget();
172 171 }
173 172
174 173 void DragDropGuiController::addDragDropScrollArea(QScrollArea* scrollArea)
175 174 {
176 175 impl->m_DragDropScroller->addScrollArea(scrollArea);
177 176 }
178 177
179 178 void DragDropGuiController::removeDragDropScrollArea(QScrollArea* scrollArea)
180 179 {
181 180 impl->m_DragDropScroller->removeScrollArea(scrollArea);
182 181 }
183 182
184 183 void DragDropGuiController::addDragDropTabBar(QTabBar* tabBar)
185 184 {
186 185 impl->m_DragDropTabSwitcher->addTabBar(tabBar);
187 186 }
188 187
189 188 void DragDropGuiController::removeDragDropTabBar(QTabBar* tabBar)
190 189 {
191 190 impl->m_DragDropTabSwitcher->removeTabBar(tabBar);
192 191 }
193 192
194 193 QUrl DragDropGuiController::imageTemporaryUrl(const QImage& image) const
195 194 {
196 195 image.save(impl->m_ImageTempUrl);
197 196 return QUrl::fromLocalFile(impl->m_ImageTempUrl);
198 197 }
199 198
200 199 void DragDropGuiController::setHightlightedDragWidget(VisualizationDragWidget* dragWidget)
201 200 {
202 201 if (impl->m_HighlightedDragWidget)
203 202 {
204 203 impl->m_HighlightedDragWidget->highlightForMerge(false);
205 204 QObject::disconnect(impl->m_HighlightedWidgetDestroyedConnection);
206 205 }
207 206
208 207 if (dragWidget)
209 208 {
210 209 dragWidget->highlightForMerge(true);
211 210
212 211 // ensures the impl->m_HighlightedDragWidget is reset when the widget is destroyed
213 212 impl->m_DragWidgetDestroyedConnection
214 213 = QObject::connect(dragWidget, &VisualizationDragWidget::destroyed,
215 214 [this]() { impl->m_HighlightedDragWidget = nullptr; });
216 215 }
217 216
218 217 impl->m_HighlightedDragWidget = dragWidget;
219 218 }
220 219
221 220 VisualizationDragWidget* DragDropGuiController::getHightlightedDragWidget() const
222 221 {
223 222 return impl->m_HighlightedDragWidget;
224 223 }
225 224
226 225 void DragDropGuiController::delayedCloseWidget(QWidget* widget)
227 226 {
228 227 widget->hide();
229 228 impl->m_WidgetToClose << widget;
230 229 }
231 230
232 231 void DragDropGuiController::doCloseWidgets()
233 232 {
234 233 for (auto widget : impl->m_WidgetToClose)
235 234 {
236 235 widget->close();
237 236 }
238 237
239 238 impl->m_WidgetToClose.clear();
240 239 }
241 240
242 241 bool DragDropGuiController::checkMimeDataForVisualization(
243 242 const QMimeData* mimeData, VisualizationDragDropContainer* dropContainer)
244 243 {
245 244 if (!mimeData || !dropContainer)
246 245 {
247 246 qCWarning(LOG_DragDropGuiController()) << QObject::tr(
248 247 "DragDropGuiController::checkMimeDataForVisualization, invalid input parameters.");
249 248 Q_ASSERT(false);
250 249 return false;
251 250 }
252 251
253 252 auto result = false;
254 253
255 if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST))
254 if (mimeData->hasFormat(MIME::MIME_TYPE_VARIABLE_LIST))
256 255 {
257 256 auto variables = sqpApp->variableController().variables(
258 Variable2::IDs(mimeData->data(MIME_TYPE_VARIABLE_LIST)));
257 Variable2::IDs(mimeData->data(MIME::MIME_TYPE_VARIABLE_LIST)));
259 258
260 259 if (variables.size() == 1)
261 260 {
262 261
263 262 auto variable = variables[0];
264 263 if (variable->data() != nullptr)
265 264 {
266 265
267 266 // Check that the variable is not already in a graph
268 267
269 268 auto parent = dropContainer->parentWidget();
270 269 while (parent && qobject_cast<VisualizationWidget*>(parent) == nullptr)
271 270 {
272 271 parent = parent->parentWidget(); // Search for the top level VisualizationWidget
273 272 }
274 273
275 274 if (parent)
276 275 {
277 276 auto visualizationWidget = static_cast<VisualizationWidget*>(parent);
278 277
279 278 FindVariableOperation findVariableOperation { variable };
280 279 visualizationWidget->accept(&findVariableOperation);
281 280 auto variableContainers = findVariableOperation.result();
282 281 if (variableContainers.empty())
283 282 {
284 283 result = true;
285 284 }
286 285 else
287 286 {
288 287 // result = false: the variable already exist in the visualisation
289 288 }
290 289 }
291 290 else
292 291 {
293 292 qCWarning(LOG_DragDropGuiController()) << QObject::tr(
294 293 "DragDropGuiController::checkMimeDataForVisualization, the parent "
295 294 "VisualizationWidget cannot be found. Cannot check if the variable is "
296 295 "already used or not.");
297 296 }
298 297 }
299 298 else
300 299 {
301 300 // result = false: the variable is not fully loaded
302 301 }
303 302 }
304 303 else
305 304 {
306 305 // result = false: cannot drop multiple variables in the visualisation
307 306 }
308 307 }
309 else if (mimeData->hasFormat(MIME_TYPE_PRODUCT_LIST))
308 else if (mimeData->hasFormat(MIME::MIME_TYPE_PRODUCT_LIST))
310 309 {
311 auto productDataList = sqpApp->dataSourceController().productsDataForMimeData(
312 mimeData->data(MIME_TYPE_PRODUCT_LIST));
310 auto productDataList = MIME::decode(
311 mimeData->data(MIME::MIME_TYPE_PRODUCT_LIST));
313 312 if (productDataList.count() == 1)
314 313 {
315 314 result = true;
316 315 }
317 316 else
318 317 {
319 318 // result = false: cannot drop multiple products in the visualisation
320 319 }
321 320 }
322 321 else
323 322 {
324 323 // Other MIME data
325 324 // no special rules, accepted by default
326 325 result = true;
327 326 }
328 327
329 328
330 329 return result;
331 330 }
@@ -1,156 +1,151
1 1 #include "SqpApplication.h"
2 2
3 3 #include <Actions/ActionsGuiController.h>
4 4 #include <Catalogue/CatalogueController.h>
5 5 #include <Data/IDataProvider.h>
6 #include <DataSource/DataSourceController.h>
6 #include <DataSource/datasources.h>
7 7 #include <DragAndDrop/DragDropGuiController.h>
8 8 #include <Network/NetworkController.h>
9 9 #include <QThread>
10 10 #include <Time/TimeController.h>
11 11 #include <Variable/VariableController2.h>
12 12 #include <Variable/VariableModel2.h>
13 13
14 14 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
15 15
16 16 class SqpApplication::SqpApplicationPrivate
17 17 {
18 18 public:
19 19 SqpApplicationPrivate()
20 20 : m_VariableController { std::make_shared<VariableController2>() }
21 21 , m_PlotInterractionMode(SqpApplication::PlotsInteractionMode::None)
22 22 , m_PlotCursorMode(SqpApplication::PlotsCursorMode::NoCursor)
23 23 {
24 24 // /////////////////////////////// //
25 25 // Connections between controllers //
26 26 // /////////////////////////////// //
27 27
28 28 // VariableController <-> DataSourceController
29 connect(&m_DataSourceController, &DataSourceController::createVariable,
29 connect(&m_DataSources, static_cast<void (DataSources::*)(const QString&, const QVariantHash&,
30 std::shared_ptr<IDataProvider>)>(&DataSources::createVariable),
30 31 [](const QString& variableName, const QVariantHash& variableMetadata,
31 32 std::shared_ptr<IDataProvider> variableProvider) {
32 33 sqpApp->variableController().createVariable(variableName, variableMetadata,
33 34 variableProvider, sqpApp->timeController().dateTime());
34 35 });
35 36
36 37
37 m_DataSourceController.moveToThread(&m_DataSourceControllerThread);
38 m_DataSourceControllerThread.setObjectName("DataSourceControllerThread");
39 38 m_NetworkController.moveToThread(&m_NetworkControllerThread);
40 39 m_NetworkControllerThread.setObjectName("NetworkControllerThread");
41 40
42 41 // Additionnal init
43 42 // m_VariableController->setTimeController(m_TimeController.get());
44 43 }
45 44
46 45 virtual ~SqpApplicationPrivate()
47 46 {
48 m_DataSourceControllerThread.quit();
49 m_DataSourceControllerThread.wait();
50 47
51 48 m_NetworkControllerThread.quit();
52 49 m_NetworkControllerThread.wait();
53 50 }
54 51
55 DataSourceController m_DataSourceController;
52 DataSources m_DataSources;
56 53 std::shared_ptr<VariableController2> m_VariableController;
57 54 TimeController m_TimeController;
58 55 NetworkController m_NetworkController;
59 56 CatalogueController m_CatalogueController;
60 57
61 QThread m_DataSourceControllerThread;
62 58 QThread m_NetworkControllerThread;
63 59
64 60 DragDropGuiController m_DragDropGuiController;
65 61 ActionsGuiController m_ActionsGuiController;
66 62
67 63 SqpApplication::PlotsInteractionMode m_PlotInterractionMode;
68 64 SqpApplication::PlotsCursorMode m_PlotCursorMode;
69 65 };
70 66
71 67
72 68 SqpApplication::SqpApplication(int& argc, char** argv)
73 69 : QApplication { argc, argv }, impl { spimpl::make_unique_impl<SqpApplicationPrivate>() }
74 70 {
75 71 this->setStyle(new MyProxyStyle(this->style()));
76 72 qCDebug(LOG_SqpApplication()) << tr("SqpApplication construction") << QThread::currentThread();
77 73
78 74 QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
79 75
80 connect(&impl->m_DataSourceControllerThread, &QThread::started, &impl->m_DataSourceController,
81 &DataSourceController::initialize);
82 connect(&impl->m_DataSourceControllerThread, &QThread::finished, &impl->m_DataSourceController,
83 &DataSourceController::finalize);
84
85 76 connect(&impl->m_NetworkControllerThread, &QThread::started, &impl->m_NetworkController,
86 77 &NetworkController::initialize);
87 78 connect(&impl->m_NetworkControllerThread, &QThread::finished, &impl->m_NetworkController,
88 79 &NetworkController::finalize);
89 80
90 impl->m_DataSourceControllerThread.start();
91 81 impl->m_NetworkControllerThread.start();
92 82 }
93 83
94 84 SqpApplication::~SqpApplication() {}
95 85
96 86 void SqpApplication::initialize() {}
97 87
98 DataSourceController& SqpApplication::dataSourceController() noexcept
88 //DataSourceController& SqpApplication::dataSourceController() noexcept
89 //{
90 // return impl->m_DataSourceController;
91 //}
92
93 DataSources& SqpApplication::dataSources() noexcept
99 94 {
100 return impl->m_DataSourceController;
95 return impl->m_DataSources;
101 96 }
102 97
103 98 NetworkController& SqpApplication::networkController() noexcept
104 99 {
105 100 return impl->m_NetworkController;
106 101 }
107 102
108 103 TimeController& SqpApplication::timeController() noexcept
109 104 {
110 105 return impl->m_TimeController;
111 106 }
112 107
113 108 VariableController2& SqpApplication::variableController() noexcept
114 109 {
115 110 return *impl->m_VariableController;
116 111 }
117 112
118 113 std::shared_ptr<VariableController2> SqpApplication::variableControllerOwner() noexcept
119 114 {
120 115 return impl->m_VariableController;
121 116 }
122 117
123 118 CatalogueController& SqpApplication::catalogueController() noexcept
124 119 {
125 120 return impl->m_CatalogueController;
126 121 }
127 122
128 123 DragDropGuiController& SqpApplication::dragDropGuiController() noexcept
129 124 {
130 125 return impl->m_DragDropGuiController;
131 126 }
132 127
133 128 ActionsGuiController& SqpApplication::actionsGuiController() noexcept
134 129 {
135 130 return impl->m_ActionsGuiController;
136 131 }
137 132
138 133 SqpApplication::PlotsInteractionMode SqpApplication::plotsInteractionMode() const
139 134 {
140 135 return impl->m_PlotInterractionMode;
141 136 }
142 137
143 138 void SqpApplication::setPlotsInteractionMode(SqpApplication::PlotsInteractionMode mode)
144 139 {
145 140 impl->m_PlotInterractionMode = mode;
146 141 }
147 142
148 143 SqpApplication::PlotsCursorMode SqpApplication::plotsCursorMode() const
149 144 {
150 145 return impl->m_PlotCursorMode;
151 146 }
152 147
153 148 void SqpApplication::setPlotsCursorMode(SqpApplication::PlotsCursorMode mode)
154 149 {
155 150 impl->m_PlotCursorMode = mode;
156 151 }
@@ -1,158 +1,158
1 1 #include "TimeWidget/TimeWidget.h"
2 2 #include "ui_TimeWidget.h"
3 3
4 4 #include <Common/DateUtils.h>
5 #include <Common/MimeTypesDef.h>
5 #include <MimeTypes/MimeTypes.h>
6 6
7 7 #include <DragAndDrop/DragDropGuiController.h>
8 8 #include <SqpApplication.h>
9 9 #include <Time/TimeController.h>
10 10
11 11 #include <QDrag>
12 12 #include <QDragEnterEvent>
13 13 #include <QDropEvent>
14 14 #include <QMimeData>
15 15 #include <QStyle>
16 16
17 17
18 18 struct TimeWidget::TimeWidgetPrivate
19 19 {
20 20
21 21 explicit TimeWidgetPrivate() {}
22 22
23 23 QPoint m_DragStartPosition;
24 24 };
25 25
26 26 TimeWidget::TimeWidget(QWidget* parent)
27 27 : QWidget { parent }
28 28 , ui { new Ui::TimeWidget }
29 29 , impl { spimpl::make_unique_impl<TimeWidgetPrivate>() }
30 30 {
31 31 ui->setupUi(this);
32 32
33 33 // Connection
34 34 connect(ui->startDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this,
35 35 &TimeWidget::onTimeUpdateRequested);
36 36
37 37 connect(ui->endDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this,
38 38 &TimeWidget::onTimeUpdateRequested);
39 39
40 40 // Initialisation
41 41 auto endDateTime = QDateTime::currentDateTimeUtc();
42 42 auto startDateTime = endDateTime.addSecs(-3600); // one hour before
43 43
44 44 ui->startDateTimeEdit->setDateTime(startDateTime);
45 45 ui->endDateTimeEdit->setDateTime(endDateTime);
46 46
47 47 auto dateTime = DateTimeRange { DateUtils::secondsSinceEpoch(startDateTime),
48 48 DateUtils::secondsSinceEpoch(endDateTime) };
49 49
50 50 sqpApp->timeController().setDateTimeRange(dateTime);
51 51 }
52 52
53 53
54 54 TimeWidget::~TimeWidget()
55 55 {
56 56 delete ui;
57 57 }
58 58
59 59 void TimeWidget::setTimeRange(DateTimeRange time)
60 60 {
61 61 auto startDateTime = DateUtils::dateTime(time.m_TStart);
62 62 auto endDateTime = DateUtils::dateTime(time.m_TEnd);
63 63
64 64 ui->startDateTimeEdit->setDateTime(startDateTime);
65 65 ui->endDateTimeEdit->setDateTime(endDateTime);
66 66 }
67 67
68 68 DateTimeRange TimeWidget::timeRange() const
69 69 {
70 70 return DateTimeRange { DateUtils::secondsSinceEpoch(ui->startDateTimeEdit->dateTime()),
71 71 DateUtils::secondsSinceEpoch(ui->endDateTimeEdit->dateTime()) };
72 72 }
73 73
74 74 void TimeWidget::onTimeUpdateRequested()
75 75 {
76 76 auto dateTime = timeRange();
77 77 emit timeUpdated(dateTime);
78 78 sqpApp->timeController().setDateTimeRange(dateTime);
79 79 }
80 80
81 81 void TimeWidget::dragEnterEvent(QDragEnterEvent* event)
82 82 {
83 if (event->mimeData()->hasFormat(MIME_TYPE_TIME_RANGE))
83 if (event->mimeData()->hasFormat(MIME::MIME_TYPE_TIME_RANGE))
84 84 {
85 85 event->acceptProposedAction();
86 86 setStyleSheet("QDateTimeEdit{background-color: #BBD5EE; border:2px solid #2A7FD4}");
87 87 }
88 88 else
89 89 {
90 90 event->ignore();
91 91 }
92 92 }
93 93
94 94 void TimeWidget::dragLeaveEvent(QDragLeaveEvent* event)
95 95 {
96 96 setStyleSheet(QString {});
97 97 }
98 98
99 99 void TimeWidget::dropEvent(QDropEvent* event)
100 100 {
101 if (event->mimeData()->hasFormat(MIME_TYPE_TIME_RANGE))
101 if (event->mimeData()->hasFormat(MIME::MIME_TYPE_TIME_RANGE))
102 102 {
103 auto mimeData = event->mimeData()->data(MIME_TYPE_TIME_RANGE);
103 auto mimeData = event->mimeData()->data(MIME::MIME_TYPE_TIME_RANGE);
104 104 auto timeRange = TimeController::timeRangeForMimeData(mimeData);
105 105
106 106 setTimeRange(timeRange);
107 107 }
108 108 else
109 109 {
110 110 event->ignore();
111 111 }
112 112
113 113 setStyleSheet(QString {});
114 114 }
115 115
116 116
117 117 void TimeWidget::mousePressEvent(QMouseEvent* event)
118 118 {
119 119 if (event->button() == Qt::LeftButton)
120 120 {
121 121 impl->m_DragStartPosition = event->pos();
122 122 }
123 123
124 124 QWidget::mousePressEvent(event);
125 125 }
126 126
127 127 void TimeWidget::mouseMoveEvent(QMouseEvent* event)
128 128 {
129 129 if (!(event->buttons() & Qt::LeftButton))
130 130 {
131 131 return;
132 132 }
133 133
134 134 if ((event->pos() - impl->m_DragStartPosition).manhattanLength()
135 135 < QApplication::startDragDistance())
136 136 {
137 137 return;
138 138 }
139 139
140 140 // Note: The management of the drag object is done by Qt
141 141 auto drag = new QDrag { this };
142 142
143 143 auto mimeData = new QMimeData;
144 144 auto timeData = TimeController::mimeDataForTimeRange(timeRange());
145 mimeData->setData(MIME_TYPE_TIME_RANGE, timeData);
145 mimeData->setData(MIME::MIME_TYPE_TIME_RANGE, timeData);
146 146
147 147 drag->setMimeData(mimeData);
148 148
149 149 auto pixmap = QPixmap { ":/icones/time.png" };
150 150 drag->setPixmap(pixmap.scaledToWidth(22));
151 151
152 152 sqpApp->dragDropGuiController().resetDragAndDrop();
153 153
154 154 // Note: The exec() is blocking on windows but not on linux and macOS
155 155 drag->exec(Qt::MoveAction | Qt::CopyAction);
156 156
157 157 QWidget::mouseMoveEvent(event);
158 158 }
@@ -1,265 +1,265
1 #include <DataSource/DataSourceController.h>
1 #include <DataSource/datasources.h>
2 2 #include <Variable/RenameVariableDialog.h>
3 3 #include <Variable/VariableController2.h>
4 4 #include <Variable/VariableInspectorWidget.h>
5 5 #include <Variable/VariableMenuHeaderWidget.h>
6 6 #include <Variable/VariableModel2.h>
7 7
8 8 #include <ui_VariableInspectorWidget.h>
9 9
10 10 #include <QMouseEvent>
11 11 #include <QSortFilterProxyModel>
12 12 #include <QStyledItemDelegate>
13 13 #include <QWidgetAction>
14 14
15 15 #include <DragAndDrop/DragDropGuiController.h>
16 16 #include <SqpApplication.h>
17 17
18 18 Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget")
19 19
20 20
21 21 class QProgressBarItemDelegate : public QStyledItemDelegate
22 22 {
23 23
24 24 public:
25 25 QProgressBarItemDelegate(QObject* parent) : QStyledItemDelegate { parent } {}
26 26
27 27 void paint(
28 28 QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
29 29 {
30 30 auto data = index.data(Qt::DisplayRole);
31 31 auto progressData = index.data(VariableRoles::ProgressRole);
32 32 if (data.isValid() && progressData.isValid())
33 33 {
34 34 auto name = data.value<QString>();
35 35 auto progress = progressData.value<double>();
36 36 if (progress > 0)
37 37 {
38 38 auto cancelButtonWidth = 20;
39 39 auto progressBarOption = QStyleOptionProgressBar {};
40 40 auto progressRect = option.rect;
41 41 progressRect.setWidth(progressRect.width() - cancelButtonWidth);
42 42 progressBarOption.rect = progressRect;
43 43 progressBarOption.minimum = 0;
44 44 progressBarOption.maximum = 100;
45 45 progressBarOption.progress = progress;
46 46 progressBarOption.text
47 47 = QString("%1 %2").arg(name).arg(QString::number(progress, 'f', 2) + "%");
48 48 progressBarOption.textVisible = true;
49 49 progressBarOption.textAlignment = Qt::AlignCenter;
50 50
51 51
52 52 QApplication::style()->drawControl(
53 53 QStyle::CE_ProgressBar, &progressBarOption, painter);
54 54
55 55 // Cancel button
56 56 auto buttonRect = QRect(progressRect.right(), option.rect.top(), cancelButtonWidth,
57 57 option.rect.height());
58 58 auto buttonOption = QStyleOptionButton {};
59 59 buttonOption.rect = buttonRect;
60 60 buttonOption.text = "X";
61 61
62 62 QApplication::style()->drawControl(QStyle::CE_PushButton, &buttonOption, painter);
63 63 }
64 64 else
65 65 {
66 66 QStyledItemDelegate::paint(painter, option, index);
67 67 }
68 68 }
69 69 else
70 70 {
71 71 QStyledItemDelegate::paint(painter, option, index);
72 72 }
73 73 }
74 74
75 75 bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option,
76 76 const QModelIndex& index)
77 77 {
78 78 if (event->type() == QEvent::MouseButtonRelease)
79 79 {
80 80 auto data = index.data(Qt::DisplayRole);
81 81 auto progressData = index.data(VariableRoles::ProgressRole);
82 82 if (data.isValid() && progressData.isValid())
83 83 {
84 84 auto cancelButtonWidth = 20;
85 85 auto progressRect = option.rect;
86 86 progressRect.setWidth(progressRect.width() - cancelButtonWidth);
87 87 // Cancel button
88 88 auto buttonRect = QRect(progressRect.right(), option.rect.top(), cancelButtonWidth,
89 89 option.rect.height());
90 90
91 91 auto e = (QMouseEvent*)event;
92 92 auto clickX = e->x();
93 93 auto clickY = e->y();
94 94
95 95 auto x = buttonRect.left(); // the X coordinate
96 96 auto y = buttonRect.top(); // the Y coordinate
97 97 auto w = buttonRect.width(); // button width
98 98 auto h = buttonRect.height(); // button height
99 99
100 100 if (clickX > x && clickX < x + w)
101 101 {
102 102 if (clickY > y && clickY < y + h)
103 103 {
104 104 // auto& variableModel = sqpApp->variableModel();
105 105 // variableModel->abortProgress(index);
106 106 }
107 107 return true;
108 108 }
109 109 else
110 110 {
111 111 return QStyledItemDelegate::editorEvent(event, model, option, index);
112 112 }
113 113 }
114 114 else
115 115 {
116 116 return QStyledItemDelegate::editorEvent(event, model, option, index);
117 117 }
118 118 }
119 119 else
120 120 {
121 121 return QStyledItemDelegate::editorEvent(event, model, option, index);
122 122 }
123 123
124 124
125 125 return QStyledItemDelegate::editorEvent(event, model, option, index);
126 126 }
127 127 };
128 128
129 129 VariableInspectorWidget::VariableInspectorWidget(QWidget* parent)
130 130 : QWidget { parent }
131 131 , ui { new Ui::VariableInspectorWidget }
132 132 , m_ProgressBarItemDelegate { new QProgressBarItemDelegate { this } }
133 133 {
134 134 ui->setupUi(this);
135 135
136 136 // Sets model for table
137 137 // auto sortFilterModel = new QSortFilterProxyModel{this};
138 138 // sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
139 139
140 140 m_model = new VariableModel2();
141 141 ui->tableView->setModel(m_model);
142 connect(m_model, &VariableModel2::createVariable, [](const QVariantHash& productData) {
143 sqpApp->dataSourceController().requestVariable(productData);
142 connect(m_model, &VariableModel2::createVariable, [](const QString& productPath) {
143 sqpApp->dataSources().createVariable(productPath);
144 144 });
145 145 auto vc = &(sqpApp->variableController());
146 146 connect(vc, &VariableController2::variableAdded, m_model, &VariableModel2::variableAdded);
147 147 connect(vc, &VariableController2::variableDeleted, m_model, &VariableModel2::variableDeleted);
148 148 connect(m_model, &VariableModel2::asyncChangeRange, vc, &VariableController2::asyncChangeRange);
149 149
150 150 // Adds extra signal/slot between view and model, so the view can be updated instantly when
151 151 // there is a change of data in the model
152 152 // connect(m_model, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this,
153 153 // SLOT(refresh()));
154 154
155 155 // ui->tableView->setSelectionModel(sqpApp->variableController().variableSelectionModel());
156 156 ui->tableView->setItemDelegateForColumn(0, m_ProgressBarItemDelegate);
157 157
158 158 // Fixes column sizes
159 159 auto model = ui->tableView->model();
160 160 const auto count = model->columnCount();
161 161 for (auto i = 0; i < count; ++i)
162 162 {
163 163 ui->tableView->setColumnWidth(
164 164 i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width());
165 165 }
166 166
167 167 // Sets selection options
168 168 ui->tableView->setSelectionBehavior(QTableView::SelectRows);
169 169 ui->tableView->setSelectionMode(QTableView::ExtendedSelection);
170 170
171 171 // Connection to show a menu when right clicking on the tree
172 172 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
173 173 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
174 174 &VariableInspectorWidget::onTableMenuRequested);
175 175 }
176 176
177 177 VariableInspectorWidget::~VariableInspectorWidget()
178 178 {
179 179 delete ui;
180 180 }
181 181
182 182 void VariableInspectorWidget::onTableMenuRequested(const QPoint& pos) noexcept
183 183 {
184 184 auto selectedRows = ui->tableView->selectionModel()->selectedRows();
185 185 auto selectedVariables = QVector<std::shared_ptr<Variable2>> {};
186 186 for (const auto& selectedRow : qAsConst(selectedRows))
187 187 {
188 188 if (auto selectedVariable = this->m_model->variables()[selectedRow.row()])
189 189 {
190 190 selectedVariables.push_back(selectedVariable);
191 191 }
192 192 }
193 193
194 194 QMenu tableMenu {};
195 195
196 196 // Emits a signal so that potential receivers can populate the menu before displaying it
197 197 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables);
198 198
199 199 // Adds menu-specific actions
200 200 if (!selectedVariables.isEmpty())
201 201 {
202 202 tableMenu.addSeparator();
203 203
204 204 // 'Rename' and 'Duplicate' actions (only if one variable selected)
205 205 if (selectedVariables.size() == 1)
206 206 {
207 207 auto selectedVariable = selectedVariables.front();
208 208
209 209 auto duplicateFun = [varW = std::weak_ptr<Variable2>(selectedVariable)]() {
210 210 if (auto var = varW.lock())
211 211 {
212 212 sqpApp->variableController().cloneVariable(var);
213 213 }
214 214 };
215 215
216 216 tableMenu.addAction(tr("Duplicate"), duplicateFun);
217 217
218 218 auto renameFun = [varW = std::weak_ptr<Variable2>(selectedVariable), this]() {
219 219 if (auto var = varW.lock())
220 220 {
221 221 // Generates forbidden names (names associated to existing variables)
222 222 auto allVariables = sqpApp->variableController().variables();
223 223 auto forbiddenNames = QVector<QString>(allVariables.size());
224 224 std::transform(allVariables.cbegin(), allVariables.cend(),
225 225 forbiddenNames.begin(),
226 226 [](const auto& variable) { return variable->name(); });
227 227
228 228 RenameVariableDialog dialog { var->name(), forbiddenNames, this };
229 229 if (dialog.exec() == QDialog::Accepted)
230 230 {
231 231 var->setName(dialog.name());
232 232 }
233 233 }
234 234 };
235 235
236 236 tableMenu.addAction(tr("Rename..."), renameFun);
237 237 }
238 238
239 239 // 'Delete' action
240 240 auto deleteFun = [&selectedVariables]() {
241 241 for (const auto& var : selectedVariables)
242 242 sqpApp->variableController().deleteVariable(var);
243 243 };
244 244
245 245 tableMenu.addAction(QIcon { ":/icones/delete.png" }, tr("Delete"), deleteFun);
246 246 }
247 247
248 248 if (!tableMenu.isEmpty())
249 249 {
250 250 // Generates menu header (inserted before first action)
251 251 auto firstAction = tableMenu.actions().first();
252 252 auto headerAction = new QWidgetAction { &tableMenu };
253 253 headerAction->setDefaultWidget(
254 254 new VariableMenuHeaderWidget { selectedVariables, &tableMenu });
255 255 tableMenu.insertAction(firstAction, headerAction);
256 256
257 257 // Displays menu
258 258 tableMenu.exec(QCursor::pos());
259 259 }
260 260 }
261 261
262 262 void VariableInspectorWidget::refresh() noexcept
263 263 {
264 264 ui->tableView->viewport()->update();
265 265 }
@@ -1,1578 +1,1578
1 1 #include "Visualization/VisualizationGraphWidget.h"
2 2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 3 #include "Visualization/VisualizationCursorItem.h"
4 4 #include "Visualization/VisualizationDefs.h"
5 5 #include "Visualization/VisualizationGraphHelper.h"
6 6 #include "Visualization/VisualizationGraphRenderingDelegate.h"
7 7 #include "Visualization/VisualizationMultiZoneSelectionDialog.h"
8 8 #include "Visualization/VisualizationSelectionZoneItem.h"
9 9 #include "Visualization/VisualizationSelectionZoneManager.h"
10 10 #include "Visualization/VisualizationWidget.h"
11 11 #include "Visualization/VisualizationZoneWidget.h"
12 12 #include "ui_VisualizationGraphWidget.h"
13 13
14 14 #include <Actions/ActionsGuiController.h>
15 15 #include <Actions/FilteringAction.h>
16 #include <Common/MimeTypesDef.h>
16 #include <MimeTypes/MimeTypes.h>
17 17 #include <cpp_utils_qt/cpp_utils_qt.hpp>
18 18 #include <containers/algorithms.hpp>
19 19 #include <Data/DateTimeRangeHelper.h>
20 20 #include <DragAndDrop/DragDropGuiController.h>
21 21 #include <Settings/SqpSettingsDefs.h>
22 22 #include <SqpApplication.h>
23 23 #include <Time/TimeController.h>
24 24 #include <Variable/Variable2.h>
25 25 #include <Variable/VariableController2.h>
26 26
27 27 #include <unordered_map>
28 28
29 29 Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget")
30 30
31 31 namespace
32 32 {
33 33
34 34 /// Key pressed to enable drag&drop in all modes
35 35 const auto DRAG_DROP_MODIFIER = Qt::AltModifier;
36 36
37 37 /// Key pressed to enable zoom on horizontal axis
38 38 const auto HORIZONTAL_ZOOM_MODIFIER = Qt::ControlModifier;
39 39
40 40 /// Key pressed to enable zoom on vertical axis
41 41 const auto VERTICAL_ZOOM_MODIFIER = Qt::ShiftModifier;
42 42
43 43 /// Speed of a step of a wheel event for a pan, in percentage of the axis range
44 44 const auto PAN_SPEED = 5;
45 45
46 46 /// Key pressed to enable a calibration pan
47 47 const auto VERTICAL_PAN_MODIFIER = Qt::AltModifier;
48 48
49 49 /// Key pressed to enable multi selection of selection zones
50 50 const auto MULTI_ZONE_SELECTION_MODIFIER = Qt::ControlModifier;
51 51
52 52 /// Minimum size for the zoom box, in percentage of the axis range
53 53 const auto ZOOM_BOX_MIN_SIZE = 0.8;
54 54
55 55 /// Format of the dates appearing in the label of a cursor
56 56 const auto CURSOR_LABELS_DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd\nhh:mm:ss:zzz");
57 57
58 58 } // namespace
59 59
60 60 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate
61 61 {
62 62
63 63 explicit VisualizationGraphWidgetPrivate(const QString& name)
64 64 : m_Name { name }
65 65 , m_Flags { GraphFlag::EnableAll }
66 66 , m_IsCalibration { false }
67 67 , m_RenderingDelegate { nullptr }
68 68 {
69 69 m_plot = new QCustomPlot();
70 70 // Necessary for all platform since Qt::AA_EnableHighDpiScaling is enable.
71 71 m_plot->setPlottingHint(QCP::phFastPolylines, true);
72 72 }
73 73
74 74 void updateData(
75 75 PlottablesMap& plottables, std::shared_ptr<Variable2> variable, const DateTimeRange& range)
76 76 {
77 77 VisualizationGraphHelper::updateData(plottables, variable, range);
78 78
79 79 // Prevents that data has changed to update rendering
80 80 m_RenderingDelegate->onPlotUpdated();
81 81 }
82 82
83 83 QString m_Name;
84 84 // 1 variable -> n qcpplot
85 85 std::map<std::shared_ptr<Variable2>, PlottablesMap> m_VariableToPlotMultiMap;
86 86 GraphFlags m_Flags;
87 87 bool m_IsCalibration;
88 88 QCustomPlot* m_plot;
89 89 QPoint m_lastMousePos;
90 90 QCPRange m_lastXRange;
91 91 QCPRange m_lastYRange;
92 92 /// Delegate used to attach rendering features to the plot
93 93 std::unique_ptr<VisualizationGraphRenderingDelegate> m_RenderingDelegate;
94 94
95 95 QCPItemRect* m_DrawingZoomRect = nullptr;
96 96 QStack<QPair<QCPRange, QCPRange>> m_ZoomStack;
97 97
98 98 std::unique_ptr<VisualizationCursorItem> m_HorizontalCursor = nullptr;
99 99 std::unique_ptr<VisualizationCursorItem> m_VerticalCursor = nullptr;
100 100
101 101 VisualizationSelectionZoneItem* m_DrawingZone = nullptr;
102 102 VisualizationSelectionZoneItem* m_HoveredZone = nullptr;
103 103 QVector<VisualizationSelectionZoneItem*> m_SelectionZones;
104 104
105 105 bool m_HasMovedMouse = false; // Indicates if the mouse moved in a releaseMouse even
106 106
107 107 bool m_VariableAutoRangeOnInit = true;
108 108
109 109 inline void enterPlotDrag(const QPoint& position)
110 110 {
111 111 m_lastMousePos = m_plot->mapFromParent(position);
112 112 m_lastXRange = m_plot->xAxis->range();
113 113 m_lastYRange = m_plot->yAxis->range();
114 114 }
115 115
116 116 inline bool isDrawingZoomRect() { return m_DrawingZoomRect != nullptr; }
117 117 void updateZoomRect(const QPoint& newPos)
118 118 {
119 119 QPointF pos { m_plot->xAxis->pixelToCoord(newPos.x()),
120 120 m_plot->yAxis->pixelToCoord(newPos.y()) };
121 121 m_DrawingZoomRect->bottomRight->setCoords(pos);
122 122 m_plot->replot(QCustomPlot::rpQueuedReplot);
123 123 }
124 124
125 125 void applyZoomRect()
126 126 {
127 127 auto axisX = m_plot->axisRect()->axis(QCPAxis::atBottom);
128 128 auto axisY = m_plot->axisRect()->axis(QCPAxis::atLeft);
129 129
130 130 auto newAxisXRange = QCPRange { m_DrawingZoomRect->topLeft->coords().x(),
131 131 m_DrawingZoomRect->bottomRight->coords().x() };
132 132
133 133 auto newAxisYRange = QCPRange { m_DrawingZoomRect->topLeft->coords().y(),
134 134 m_DrawingZoomRect->bottomRight->coords().y() };
135 135
136 136 removeDrawingRect();
137 137
138 138 if (newAxisXRange.size() > axisX->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0)
139 139 && newAxisYRange.size() > axisY->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0))
140 140 {
141 141 m_ZoomStack.push(qMakePair(axisX->range(), axisY->range()));
142 142 axisX->setRange(newAxisXRange);
143 143 axisY->setRange(newAxisYRange);
144 144
145 145 m_plot->replot(QCustomPlot::rpQueuedReplot);
146 146 }
147 147 }
148 148
149 149 inline bool isDrawingZoneRect() { return m_DrawingZone != nullptr; }
150 150 void updateZoneRect(const QPoint& newPos)
151 151 {
152 152 m_DrawingZone->setEnd(m_plot->xAxis->pixelToCoord(newPos.x()));
153 153 m_plot->replot(QCustomPlot::rpQueuedReplot);
154 154 }
155 155
156 156 void startDrawingRect(const QPoint& pos)
157 157 {
158 158 removeDrawingRect();
159 159
160 160 auto axisPos = posToAxisPos(pos);
161 161
162 162 m_DrawingZoomRect = new QCPItemRect { m_plot };
163 163 QPen p;
164 164 p.setWidth(2);
165 165 m_DrawingZoomRect->setPen(p);
166 166
167 167 m_DrawingZoomRect->topLeft->setCoords(axisPos);
168 168 m_DrawingZoomRect->bottomRight->setCoords(axisPos);
169 169 }
170 170
171 171 void removeDrawingRect()
172 172 {
173 173 if (m_DrawingZoomRect)
174 174 {
175 175 m_plot->removeItem(m_DrawingZoomRect); // the item is deleted by QCustomPlot
176 176 m_DrawingZoomRect = nullptr;
177 177 m_plot->replot(QCustomPlot::rpQueuedReplot);
178 178 }
179 179 }
180 180
181 181 void selectZone(const QPoint& pos)
182 182 {
183 183 auto zoneAtPos = selectionZoneAt(pos);
184 184 setSelectionZonesEditionEnabled(
185 185 sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones);
186 186 }
187 187
188 188 void startDrawingZone(const QPoint& pos)
189 189 {
190 190 endDrawingZone();
191 191
192 192 auto axisPos = posToAxisPos(pos);
193 193
194 194 m_DrawingZone = new VisualizationSelectionZoneItem { m_plot };
195 195 m_DrawingZone->setRange(axisPos.x(), axisPos.x());
196 196 m_DrawingZone->setEditionEnabled(false);
197 197 }
198 198
199 199 void endDrawingZone()
200 200 {
201 201 if (m_DrawingZone)
202 202 {
203 203 auto drawingZoneRange = m_DrawingZone->range();
204 204 if (qAbs(drawingZoneRange.m_TEnd - drawingZoneRange.m_TStart) > 0)
205 205 {
206 206 m_DrawingZone->setEditionEnabled(true);
207 207 addSelectionZone(m_DrawingZone);
208 208 }
209 209 else
210 210 {
211 211 m_plot->removeItem(m_DrawingZone);
212 212 }
213 213
214 214 m_plot->replot(QCustomPlot::rpQueuedReplot);
215 215 m_DrawingZone = nullptr;
216 216 }
217 217 }
218 218
219 219 void moveSelectionZone(const QPoint& destination)
220 220 {
221 221 /*
222 222 * I give up on this for now
223 223 * TODO implement this, the difficulty is that selection zones have their own
224 224 * event handling code which seems to rely on QCP GUI event handling propagation
225 225 * which was a realy bad design choice.
226 226 */
227 227 }
228 228
229 229 void setSelectionZonesEditionEnabled(bool value)
230 230 {
231 231 for (auto s : m_SelectionZones)
232 232 {
233 233 s->setEditionEnabled(value);
234 234 }
235 235 }
236 236
237 237 void addSelectionZone(VisualizationSelectionZoneItem* zone) { m_SelectionZones << zone; }
238 238
239 239 VisualizationSelectionZoneItem* selectionZoneAt(const QPoint& pos) const
240 240 {
241 241 VisualizationSelectionZoneItem* selectionZoneItemUnderCursor = nullptr;
242 242 auto minDistanceToZone = -1;
243 243 for (auto zone : m_SelectionZones)
244 244 {
245 245 auto distanceToZone = zone->selectTest(pos, false);
246 246 if ((minDistanceToZone < 0 || distanceToZone <= minDistanceToZone)
247 247 && distanceToZone >= 0 && distanceToZone < m_plot->selectionTolerance())
248 248 {
249 249 selectionZoneItemUnderCursor = zone;
250 250 }
251 251 }
252 252
253 253 return selectionZoneItemUnderCursor;
254 254 }
255 255
256 256 QVector<VisualizationSelectionZoneItem*> selectionZonesAt(
257 257 const QPoint& pos, const QCustomPlot& plot) const
258 258 {
259 259 QVector<VisualizationSelectionZoneItem*> zones;
260 260 for (auto zone : m_SelectionZones)
261 261 {
262 262 auto distanceToZone = zone->selectTest(pos, false);
263 263 if (distanceToZone >= 0 && distanceToZone < plot.selectionTolerance())
264 264 {
265 265 zones << zone;
266 266 }
267 267 }
268 268
269 269 return zones;
270 270 }
271 271
272 272 void moveSelectionZoneOnTop(VisualizationSelectionZoneItem* zone, QCustomPlot& plot)
273 273 {
274 274 if (!m_SelectionZones.isEmpty() && m_SelectionZones.last() != zone)
275 275 {
276 276 zone->moveToTop();
277 277 m_SelectionZones.removeAll(zone);
278 278 m_SelectionZones.append(zone);
279 279 }
280 280 }
281 281
282 282 QPointF posToAxisPos(const QPoint& pos) const
283 283 {
284 284 auto axisX = m_plot->axisRect()->axis(QCPAxis::atBottom);
285 285 auto axisY = m_plot->axisRect()->axis(QCPAxis::atLeft);
286 286 return QPointF { axisX->pixelToCoord(pos.x()), axisY->pixelToCoord(pos.y()) };
287 287 }
288 288
289 289 bool pointIsInAxisRect(const QPointF& axisPoint, QCustomPlot& plot) const
290 290 {
291 291 auto axisX = plot.axisRect()->axis(QCPAxis::atBottom);
292 292 auto axisY = plot.axisRect()->axis(QCPAxis::atLeft);
293 293 return axisX->range().contains(axisPoint.x()) && axisY->range().contains(axisPoint.y());
294 294 }
295 295
296 296 inline QCPRange _pixDistanceToRange(double pos1, double pos2, QCPAxis* axis)
297 297 {
298 298 if (axis->scaleType() == QCPAxis::stLinear)
299 299 {
300 300 auto diff = axis->pixelToCoord(pos1) - axis->pixelToCoord(pos2);
301 301 return QCPRange { axis->range().lower + diff, axis->range().upper + diff };
302 302 }
303 303 else
304 304 {
305 305 auto diff = axis->pixelToCoord(pos1) / axis->pixelToCoord(pos2);
306 306 return QCPRange { axis->range().lower * diff, axis->range().upper * diff };
307 307 }
308 308 }
309 309
310 310 void setRange(const DateTimeRange& newRange, bool updateVar = true)
311 311 {
312 312 this->m_plot->xAxis->setRange(newRange.m_TStart, newRange.m_TEnd);
313 313 if (updateVar)
314 314 {
315 315 for (auto it = m_VariableToPlotMultiMap.begin(), end = m_VariableToPlotMultiMap.end();
316 316 it != end; it = m_VariableToPlotMultiMap.upper_bound(it->first))
317 317 {
318 318 sqpApp->variableController().asyncChangeRange(it->first, newRange);
319 319 }
320 320 }
321 321 m_plot->replot(QCustomPlot::rpQueuedReplot);
322 322 }
323 323
324 324 void setRange(const QCPRange& newRange)
325 325 {
326 326 auto graphRange = DateTimeRange { newRange.lower, newRange.upper };
327 327 setRange(graphRange);
328 328 }
329 329
330 330 void rescaleY() { m_plot->yAxis->rescale(true); }
331 331
332 332 std::tuple<double, double> moveGraph(const QPoint& destination)
333 333 {
334 334 auto currentPos = m_plot->mapFromParent(destination);
335 335 auto xAxis = m_plot->axisRect()->rangeDragAxis(Qt::Horizontal);
336 336 auto yAxis = m_plot->axisRect()->rangeDragAxis(Qt::Vertical);
337 337 auto oldXRange = xAxis->range();
338 338 auto oldYRange = yAxis->range();
339 339 double dx = xAxis->pixelToCoord(m_lastMousePos.x()) - xAxis->pixelToCoord(currentPos.x());
340 340 xAxis->setRange(m_lastXRange.lower + dx, m_lastXRange.upper + dx);
341 341 if (yAxis->scaleType() == QCPAxis::stLinear)
342 342 {
343 343 double dy
344 344 = yAxis->pixelToCoord(m_lastMousePos.y()) - yAxis->pixelToCoord(currentPos.y());
345 345 yAxis->setRange(m_lastYRange.lower + dy, m_lastYRange.upper + dy);
346 346 }
347 347 else
348 348 {
349 349 double dy
350 350 = yAxis->pixelToCoord(m_lastMousePos.y()) / yAxis->pixelToCoord(currentPos.y());
351 351 yAxis->setRange(m_lastYRange.lower * dy, m_lastYRange.upper * dy);
352 352 }
353 353 auto newXRange = xAxis->range();
354 354 auto newYRange = yAxis->range();
355 355 setRange(xAxis->range());
356 356 // m_lastMousePos = currentPos;
357 357 return { newXRange.lower - oldXRange.lower, newYRange.lower - oldYRange.lower };
358 358 }
359 359
360 360 void zoom(double factor, int center, Qt::Orientation orientation)
361 361 {
362 362 QCPAxis* axis = m_plot->axisRect()->rangeZoomAxis(orientation);
363 363 axis->scaleRange(factor, axis->pixelToCoord(center));
364 364 if (orientation == Qt::Horizontal)
365 365 setRange(axis->range());
366 366 m_plot->replot(QCustomPlot::rpQueuedReplot);
367 367 }
368 368
369 369 void transform(const DateTimeRangeTransformation& tranformation)
370 370 {
371 371 auto graphRange = m_plot->xAxis->range();
372 372 DateTimeRange range { graphRange.lower, graphRange.upper };
373 373 range = range.transform(tranformation);
374 374 setRange(range);
375 375 m_plot->replot(QCustomPlot::rpQueuedReplot);
376 376 }
377 377
378 378 void move(double dx, double dy)
379 379 {
380 380 auto xAxis = m_plot->axisRect()->rangeDragAxis(Qt::Horizontal);
381 381 auto yAxis = m_plot->axisRect()->rangeDragAxis(Qt::Vertical);
382 382 xAxis->setRange(QCPRange(xAxis->range().lower + dx, xAxis->range().upper + dx));
383 383 yAxis->setRange(QCPRange(yAxis->range().lower + dy, yAxis->range().upper + dy));
384 384 setRange(xAxis->range());
385 385 m_plot->replot(QCustomPlot::rpQueuedReplot);
386 386 }
387 387
388 388 void move(double factor, Qt::Orientation orientation)
389 389 {
390 390 auto oldRange = m_plot->xAxis->range();
391 391 QCPAxis* axis = m_plot->axisRect()->rangeDragAxis(orientation);
392 392 if (m_plot->xAxis->scaleType() == QCPAxis::stLinear)
393 393 {
394 394 double rg = (axis->range().upper - axis->range().lower) * (factor / 10);
395 395 axis->setRange(axis->range().lower + (rg), axis->range().upper + (rg));
396 396 }
397 397 else if (m_plot->xAxis->scaleType() == QCPAxis::stLogarithmic)
398 398 {
399 399 int start = 0, stop = 0;
400 400 double diff = 0.;
401 401 if (factor > 0.0)
402 402 {
403 403 stop = m_plot->width() * factor / 10;
404 404 start = 2 * m_plot->width() * factor / 10;
405 405 }
406 406 if (factor < 0.0)
407 407 {
408 408 factor *= -1.0;
409 409 start = m_plot->width() * factor / 10;
410 410 stop = 2 * m_plot->width() * factor / 10;
411 411 }
412 412 diff = axis->pixelToCoord(start) / axis->pixelToCoord(stop);
413 413 axis->setRange(m_plot->axisRect()->rangeDragAxis(orientation)->range().lower * diff,
414 414 m_plot->axisRect()->rangeDragAxis(orientation)->range().upper * diff);
415 415 }
416 416 if (orientation == Qt::Horizontal)
417 417 setRange(axis->range());
418 418 m_plot->replot(QCustomPlot::rpQueuedReplot);
419 419 }
420 420 };
421 421
422 422 VisualizationGraphWidget::VisualizationGraphWidget(const QString& name, QWidget* parent)
423 423 : VisualizationDragWidget { parent }
424 424 , ui { new Ui::VisualizationGraphWidget }
425 425 , impl { spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>(name) }
426 426 {
427 427 ui->setupUi(this);
428 428 this->layout()->addWidget(impl->m_plot);
429 429 // 'Close' options : widget is deleted when closed
430 430 setAttribute(Qt::WA_DeleteOnClose);
431 431
432 432 // The delegate must be initialized after the ui as it uses the plot
433 433 impl->m_RenderingDelegate = std::make_unique<VisualizationGraphRenderingDelegate>(*this);
434 434
435 435 // Init the cursors
436 436 impl->m_HorizontalCursor = std::make_unique<VisualizationCursorItem>(&plot());
437 437 impl->m_HorizontalCursor->setOrientation(Qt::Horizontal);
438 438 impl->m_VerticalCursor = std::make_unique<VisualizationCursorItem>(&plot());
439 439 impl->m_VerticalCursor->setOrientation(Qt::Vertical);
440 440
441 441 this->setFocusPolicy(Qt::WheelFocus);
442 442 this->setMouseTracking(true);
443 443 impl->m_plot->setAttribute(Qt::WA_TransparentForMouseEvents);
444 444 impl->m_plot->setContextMenuPolicy(Qt::CustomContextMenu);
445 445 impl->m_plot->setParent(this);
446 446
447 447 connect(&sqpApp->variableController(), &VariableController2::variableDeleted, this,
448 448 &VisualizationGraphWidget::variableDeleted);
449 449 }
450 450
451 451
452 452 VisualizationGraphWidget::~VisualizationGraphWidget()
453 453 {
454 454 delete ui;
455 455 }
456 456
457 457 VisualizationZoneWidget* VisualizationGraphWidget::parentZoneWidget() const noexcept
458 458 {
459 459 auto parent = parentWidget();
460 460 while (parent != nullptr && !qobject_cast<VisualizationZoneWidget*>(parent))
461 461 {
462 462 parent = parent->parentWidget();
463 463 }
464 464
465 465 return qobject_cast<VisualizationZoneWidget*>(parent);
466 466 }
467 467
468 468 VisualizationWidget* VisualizationGraphWidget::parentVisualizationWidget() const
469 469 {
470 470 auto parent = parentWidget();
471 471 while (parent != nullptr && !qobject_cast<VisualizationWidget*>(parent))
472 472 {
473 473 parent = parent->parentWidget();
474 474 }
475 475
476 476 return qobject_cast<VisualizationWidget*>(parent);
477 477 }
478 478
479 479 void VisualizationGraphWidget::setFlags(GraphFlags flags)
480 480 {
481 481 impl->m_Flags = std::move(flags);
482 482 }
483 483
484 484 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable2> variable, DateTimeRange range)
485 485 {
486 486 // Uses delegate to create the qcpplot components according to the variable
487 487 auto createdPlottables = VisualizationGraphHelper::create(variable, *impl->m_plot);
488 488
489 489 // Sets graph properties
490 490 impl->m_RenderingDelegate->setGraphProperties(*variable, createdPlottables);
491 491
492 492 impl->m_VariableToPlotMultiMap.insert({ variable, std::move(createdPlottables) });
493 493
494 494 setGraphRange(range);
495 495 // If the variable already has its data loaded, load its units and its range in the graph
496 496 if (variable->data() != nullptr)
497 497 {
498 498 impl->m_RenderingDelegate->setAxesUnits(*variable);
499 499 }
500 500 else
501 501 {
502 502 auto context = new QObject { this };
503 503 connect(
504 504 variable.get(), &Variable2::updated, context, [this, variable, context, range](QUuid) {
505 505 this->impl->m_RenderingDelegate->setAxesUnits(*variable);
506 506 this->impl->m_plot->replot(QCustomPlot::rpQueuedReplot);
507 507 delete context;
508 508 });
509 509 }
510 510 //TODO this is bad! when variable is moved to another graph it still fires
511 511 // even if this has been deleted
512 512 connect(variable.get(), &Variable2::updated, this, &VisualizationGraphWidget::variableUpdated);
513 513 this->onUpdateVarDisplaying(variable, range); // My bullshit
514 514 emit variableAdded(variable);
515 515 }
516 516
517 517 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable2> variable) noexcept
518 518 {
519 519 // Each component associated to the variable :
520 520 // - is removed from qcpplot (which deletes it)
521 521 // - is no longer referenced in the map
522 522 auto variableIt = impl->m_VariableToPlotMultiMap.find(variable);
523 523 if (variableIt != impl->m_VariableToPlotMultiMap.cend())
524 524 {
525 525 emit variableAboutToBeRemoved(variable);
526 526
527 527 auto& plottablesMap = variableIt->second;
528 528
529 529 for (auto plottableIt = plottablesMap.cbegin(), plottableEnd = plottablesMap.cend();
530 530 plottableIt != plottableEnd;)
531 531 {
532 532 impl->m_plot->removePlottable(plottableIt->second);
533 533 plottableIt = plottablesMap.erase(plottableIt);
534 534 }
535 535
536 536 impl->m_VariableToPlotMultiMap.erase(variableIt);
537 537 }
538 538
539 539 // Updates graph
540 540 impl->m_plot->replot(QCustomPlot::rpQueuedReplot);
541 541 }
542 542
543 543 std::vector<std::shared_ptr<Variable2>> VisualizationGraphWidget::variables() const
544 544 {
545 545 auto variables = std::vector<std::shared_ptr<Variable2>> {};
546 546 for (auto it = std::cbegin(impl->m_VariableToPlotMultiMap);
547 547 it != std::cend(impl->m_VariableToPlotMultiMap); ++it)
548 548 {
549 549 variables.push_back(it->first);
550 550 }
551 551
552 552 return variables;
553 553 }
554 554
555 555 void VisualizationGraphWidget::setYRange(std::shared_ptr<Variable2> variable)
556 556 {
557 557 if (!variable)
558 558 {
559 559 qCCritical(LOG_VisualizationGraphWidget()) << "Can't set y-axis range: variable is null";
560 560 return;
561 561 }
562 562
563 563 VisualizationGraphHelper::setYAxisRange(variable, *impl->m_plot);
564 564 }
565 565
566 566 DateTimeRange VisualizationGraphWidget::graphRange() const noexcept
567 567 {
568 568 auto graphRange = impl->m_plot->xAxis->range();
569 569 return DateTimeRange { graphRange.lower, graphRange.upper };
570 570 }
571 571
572 572 void VisualizationGraphWidget::setGraphRange(
573 573 const DateTimeRange& range, bool updateVar, bool forward)
574 574 {
575 575 impl->setRange(range, updateVar);
576 576 if (forward)
577 577 {
578 578 emit this->setrange_sig(this->graphRange(), true, false);
579 579 }
580 580 }
581 581
582 582 void VisualizationGraphWidget::setAutoRangeOnVariableInitialization(bool value)
583 583 {
584 584 impl->m_VariableAutoRangeOnInit = value;
585 585 }
586 586
587 587 QVector<DateTimeRange> VisualizationGraphWidget::selectionZoneRanges() const
588 588 {
589 589 QVector<DateTimeRange> ranges;
590 590 for (auto zone : impl->m_SelectionZones)
591 591 {
592 592 ranges << zone->range();
593 593 }
594 594
595 595 return ranges;
596 596 }
597 597
598 598 void VisualizationGraphWidget::addSelectionZones(const QVector<DateTimeRange>& ranges)
599 599 {
600 600 for (const auto& range : ranges)
601 601 {
602 602 // note: ownership is transfered to QCustomPlot
603 603 auto zone = new VisualizationSelectionZoneItem(&plot());
604 604 zone->setRange(range.m_TStart, range.m_TEnd);
605 605 impl->addSelectionZone(zone);
606 606 }
607 607
608 608 plot().replot(QCustomPlot::rpQueuedReplot);
609 609 }
610 610
611 611 VisualizationSelectionZoneItem* VisualizationGraphWidget::addSelectionZone(
612 612 const QString& name, const DateTimeRange& range)
613 613 {
614 614 // note: ownership is transfered to QCustomPlot
615 615 auto zone = new VisualizationSelectionZoneItem(&plot());
616 616 zone->setName(name);
617 617 zone->setRange(range.m_TStart, range.m_TEnd);
618 618 impl->addSelectionZone(zone);
619 619
620 620 plot().replot(QCustomPlot::rpQueuedReplot);
621 621
622 622 return zone;
623 623 }
624 624
625 625 void VisualizationGraphWidget::removeSelectionZone(VisualizationSelectionZoneItem* selectionZone)
626 626 {
627 627 parentVisualizationWidget()->selectionZoneManager().setSelected(selectionZone, false);
628 628
629 629 if (impl->m_HoveredZone == selectionZone)
630 630 {
631 631 impl->m_HoveredZone = nullptr;
632 632 setCursor(Qt::ArrowCursor);
633 633 }
634 634
635 635 impl->m_SelectionZones.removeAll(selectionZone);
636 636 plot().removeItem(selectionZone);
637 637 plot().replot(QCustomPlot::rpQueuedReplot);
638 638 }
639 639
640 640 void VisualizationGraphWidget::undoZoom()
641 641 {
642 642 auto zoom = impl->m_ZoomStack.pop();
643 643 auto axisX = plot().axisRect()->axis(QCPAxis::atBottom);
644 644 auto axisY = plot().axisRect()->axis(QCPAxis::atLeft);
645 645
646 646 axisX->setRange(zoom.first);
647 647 axisY->setRange(zoom.second);
648 648
649 649 plot().replot(QCustomPlot::rpQueuedReplot);
650 650 }
651 651
652 652 void VisualizationGraphWidget::zoom(
653 653 double factor, int center, Qt::Orientation orientation, bool forward)
654 654 {
655 655 impl->zoom(factor, center, orientation);
656 656 if (forward && orientation == Qt::Horizontal)
657 657 emit this->setrange_sig(this->graphRange(), true, false);
658 658 }
659 659
660 660 void VisualizationGraphWidget::move(double factor, Qt::Orientation orientation, bool forward)
661 661 {
662 662 impl->move(factor, orientation);
663 663 if (forward)
664 664 emit this->setrange_sig(this->graphRange(), true, false);
665 665 }
666 666
667 667 void VisualizationGraphWidget::move(double dx, double dy, bool forward)
668 668 {
669 669 impl->move(dx, dy);
670 670 if (forward)
671 671 emit this->setrange_sig(this->graphRange(), true, false);
672 672 }
673 673
674 674 void VisualizationGraphWidget::transform(
675 675 const DateTimeRangeTransformation& tranformation, bool forward)
676 676 {
677 677 impl->transform(tranformation);
678 678 if (forward)
679 679 emit this->setrange_sig(this->graphRange(), true, false);
680 680 }
681 681
682 682 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor* visitor)
683 683 {
684 684 if (visitor)
685 685 {
686 686 visitor->visit(this);
687 687 }
688 688 else
689 689 {
690 690 qCCritical(LOG_VisualizationGraphWidget())
691 691 << tr("Can't visit widget : the visitor is null");
692 692 }
693 693 }
694 694
695 695 bool VisualizationGraphWidget::canDrop(Variable2& variable) const
696 696 {
697 697 auto isSpectrogram
698 698 = [](auto& variable) { return variable.type() == DataSeriesType::SPECTROGRAM; };
699 699
700 700 // - A spectrogram series can't be dropped on graph with existing plottables
701 701 // - No data series can be dropped on graph with existing spectrogram series
702 702 return isSpectrogram(variable)
703 703 ? impl->m_VariableToPlotMultiMap.empty()
704 704 : std::none_of(impl->m_VariableToPlotMultiMap.cbegin(),
705 705 impl->m_VariableToPlotMultiMap.cend(),
706 706 [isSpectrogram](const auto& entry) { return isSpectrogram(*entry.first); });
707 707 }
708 708
709 709 bool VisualizationGraphWidget::contains(Variable2& variable) const
710 710 {
711 711 // Finds the variable among the keys of the map
712 712 auto variablePtr = &variable;
713 713 auto findVariable
714 714 = [variablePtr](const auto& entry) { return variablePtr == entry.first.get(); };
715 715
716 716 auto end = impl->m_VariableToPlotMultiMap.cend();
717 717 auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable);
718 718 return it != end;
719 719 }
720 720
721 721 QString VisualizationGraphWidget::name() const
722 722 {
723 723 return impl->m_Name;
724 724 }
725 725
726 726 QMimeData* VisualizationGraphWidget::mimeData(const QPoint& position) const
727 727 {
728 728 auto mimeData = new QMimeData;
729 729
730 730 auto selectionZoneItemUnderCursor = impl->selectionZoneAt(position);
731 731 if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones
732 732 && selectionZoneItemUnderCursor)
733 733 {
734 mimeData->setData(MIME_TYPE_TIME_RANGE,
734 mimeData->setData(MIME::MIME_TYPE_TIME_RANGE,
735 735 TimeController::mimeDataForTimeRange(selectionZoneItemUnderCursor->range()));
736 mimeData->setData(MIME_TYPE_SELECTION_ZONE,
736 mimeData->setData(MIME::MIME_TYPE_SELECTION_ZONE,
737 737 TimeController::mimeDataForTimeRange(selectionZoneItemUnderCursor->range()));
738 738 }
739 739 else
740 740 {
741 mimeData->setData(MIME_TYPE_GRAPH, QByteArray {});
741 mimeData->setData(MIME::MIME_TYPE_GRAPH, QByteArray {});
742 742
743 743 auto timeRangeData = TimeController::mimeDataForTimeRange(graphRange());
744 mimeData->setData(MIME_TYPE_TIME_RANGE, timeRangeData);
744 mimeData->setData(MIME::MIME_TYPE_TIME_RANGE, timeRangeData);
745 745 }
746 746
747 747 return mimeData;
748 748 }
749 749
750 750 QPixmap VisualizationGraphWidget::customDragPixmap(const QPoint& dragPosition)
751 751 {
752 752 auto selectionZoneItemUnderCursor = impl->selectionZoneAt(dragPosition);
753 753 if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones
754 754 && selectionZoneItemUnderCursor)
755 755 {
756 756
757 757 auto zoneTopLeft = selectionZoneItemUnderCursor->topLeft->pixelPosition();
758 758 auto zoneBottomRight = selectionZoneItemUnderCursor->bottomRight->pixelPosition();
759 759
760 760 auto zoneSize = QSizeF { qAbs(zoneBottomRight.x() - zoneTopLeft.x()),
761 761 qAbs(zoneBottomRight.y() - zoneTopLeft.y()) }
762 762 .toSize();
763 763
764 764 auto pixmap = QPixmap(zoneSize);
765 765 render(&pixmap, QPoint(), QRegion { QRect { zoneTopLeft.toPoint(), zoneSize } });
766 766
767 767 return pixmap;
768 768 }
769 769
770 770 return QPixmap();
771 771 }
772 772
773 773 bool VisualizationGraphWidget::isDragAllowed() const
774 774 {
775 775 return true;
776 776 }
777 777
778 778 void VisualizationGraphWidget::highlightForMerge(bool highlighted)
779 779 {
780 780 if (highlighted)
781 781 {
782 782 plot().setBackground(QBrush(QColor("#BBD5EE")));
783 783 }
784 784 else
785 785 {
786 786 plot().setBackground(QBrush(Qt::white));
787 787 }
788 788
789 789 plot().update();
790 790 }
791 791
792 792 void VisualizationGraphWidget::addVerticalCursor(double time)
793 793 {
794 794 impl->m_VerticalCursor->setPosition(time);
795 795 impl->m_VerticalCursor->setVisible(true);
796 796
797 797 auto text
798 798 = DateUtils::dateTime(time).toString(CURSOR_LABELS_DATETIME_FORMAT).replace(' ', '\n');
799 799 impl->m_VerticalCursor->setLabelText(text);
800 800 }
801 801
802 802 void VisualizationGraphWidget::addVerticalCursorAtViewportPosition(double position)
803 803 {
804 804 impl->m_VerticalCursor->setAbsolutePosition(position);
805 805 impl->m_VerticalCursor->setVisible(true);
806 806
807 807 auto axis = plot().axisRect()->axis(QCPAxis::atBottom);
808 808 auto text
809 809 = DateUtils::dateTime(axis->pixelToCoord(position)).toString(CURSOR_LABELS_DATETIME_FORMAT);
810 810 impl->m_VerticalCursor->setLabelText(text);
811 811 }
812 812
813 813 void VisualizationGraphWidget::removeVerticalCursor()
814 814 {
815 815 impl->m_VerticalCursor->setVisible(false);
816 816 plot().replot(QCustomPlot::rpQueuedReplot);
817 817 }
818 818
819 819 void VisualizationGraphWidget::addHorizontalCursor(double value)
820 820 {
821 821 impl->m_HorizontalCursor->setPosition(value);
822 822 impl->m_HorizontalCursor->setVisible(true);
823 823 impl->m_HorizontalCursor->setLabelText(QString::number(value));
824 824 }
825 825
826 826 void VisualizationGraphWidget::addHorizontalCursorAtViewportPosition(double position)
827 827 {
828 828 impl->m_HorizontalCursor->setAbsolutePosition(position);
829 829 impl->m_HorizontalCursor->setVisible(true);
830 830
831 831 auto axis = plot().axisRect()->axis(QCPAxis::atLeft);
832 832 impl->m_HorizontalCursor->setLabelText(QString::number(axis->pixelToCoord(position)));
833 833 }
834 834
835 835 void VisualizationGraphWidget::removeHorizontalCursor()
836 836 {
837 837 impl->m_HorizontalCursor->setVisible(false);
838 838 plot().replot(QCustomPlot::rpQueuedReplot);
839 839 }
840 840
841 841 void VisualizationGraphWidget::closeEvent(QCloseEvent* event)
842 842 {
843 843 Q_UNUSED(event);
844 844
845 845 for (auto i : impl->m_SelectionZones)
846 846 {
847 847 parentVisualizationWidget()->selectionZoneManager().setSelected(i, false);
848 848 }
849 849
850 850 // Prevents that all variables will be removed from graph when it will be closed
851 851 for (auto& variableEntry : impl->m_VariableToPlotMultiMap)
852 852 {
853 853 emit variableAboutToBeRemoved(variableEntry.first);
854 854 }
855 855 }
856 856
857 857 void VisualizationGraphWidget::enterEvent(QEvent* event)
858 858 {
859 859 Q_UNUSED(event);
860 860 impl->m_RenderingDelegate->showGraphOverlay(true);
861 861 }
862 862
863 863 void VisualizationGraphWidget::leaveEvent(QEvent* event)
864 864 {
865 865 Q_UNUSED(event);
866 866 impl->m_RenderingDelegate->showGraphOverlay(false);
867 867
868 868 if (auto parentZone = parentZoneWidget())
869 869 {
870 870 parentZone->notifyMouseLeaveGraph(this);
871 871 }
872 872 else
873 873 {
874 874 qCWarning(LOG_VisualizationGraphWidget()) << "leaveEvent: No parent zone widget";
875 875 }
876 876
877 877 if (impl->m_HoveredZone)
878 878 {
879 879 impl->m_HoveredZone->setHovered(false);
880 880 impl->m_HoveredZone = nullptr;
881 881 }
882 882 }
883 883
884 884 void VisualizationGraphWidget::wheelEvent(QWheelEvent* event)
885 885 {
886 886 double factor;
887 887 double wheelSteps = event->delta() / 120.0; // a single step delta is +/-120 usually
888 888 if (event->modifiers() == Qt::ControlModifier)
889 889 {
890 890 if (event->orientation() == Qt::Vertical) // mRangeZoom.testFlag(Qt::Vertical))
891 891 {
892 892 setCursor(Qt::SizeVerCursor);
893 893 factor = pow(impl->m_plot->axisRect()->rangeZoomFactor(Qt::Vertical), wheelSteps);
894 894 zoom(factor, event->pos().y(), Qt::Vertical);
895 895 }
896 896 }
897 897 else if (event->modifiers() == Qt::ShiftModifier)
898 898 {
899 899 if (event->orientation() == Qt::Vertical) // mRangeZoom.testFlag(Qt::Vertical))
900 900 {
901 901 setCursor(Qt::SizeHorCursor);
902 902 factor = pow(impl->m_plot->axisRect()->rangeZoomFactor(Qt::Horizontal), wheelSteps);
903 903 zoom(factor, event->pos().x(), Qt::Horizontal);
904 904 }
905 905 }
906 906 else
907 907 {
908 908 move(wheelSteps, Qt::Horizontal);
909 909 }
910 910 event->accept();
911 911 }
912 912
913 913
914 914 void VisualizationGraphWidget::mouseMoveEvent(QMouseEvent* event)
915 915 {
916 916 if (impl->isDrawingZoomRect())
917 917 {
918 918 impl->updateZoomRect(event->pos());
919 919 }
920 920 else if (impl->isDrawingZoneRect())
921 921 {
922 922 impl->updateZoneRect(event->pos());
923 923 }
924 924 else if (event->buttons() == Qt::LeftButton)
925 925 {
926 926 if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::None)
927 927 {
928 928 auto [dx, dy] = impl->moveGraph(event->pos());
929 929 emit this->setrange_sig(this->graphRange(), true, false);
930 930 }
931 931 else if (sqpApp->plotsInteractionMode()
932 932 == SqpApplication::PlotsInteractionMode::SelectionZones)
933 933 {
934 934 auto posInPlot = this->impl->m_plot->mapFromParent(event->pos());
935 935 if (auto item = impl->m_plot->itemAt(posInPlot))
936 936 {
937 937 if (qobject_cast<VisualizationSelectionZoneItem*>(item))
938 938 {
939 939 QMouseEvent e { QEvent::MouseMove, posInPlot, event->button(), event->buttons(),
940 940 event->modifiers() };
941 941 sqpApp->sendEvent(this->impl->m_plot, &e);
942 942 this->impl->m_plot->replot(QCustomPlot::rpImmediateRefresh);
943 943 }
944 944 }
945 945 }
946 946 }
947 947 else
948 948 {
949 949 impl->m_RenderingDelegate->updateTooltip(event);
950 950 }
951 951 // event->accept();
952 952 QWidget::mouseMoveEvent(event);
953 953 }
954 954
955 955 void VisualizationGraphWidget::mouseReleaseEvent(QMouseEvent* event)
956 956 {
957 957 if (impl->isDrawingZoomRect())
958 958 {
959 959 auto oldRange = this->graphRange();
960 960 impl->applyZoomRect();
961 961 auto newRange = this->graphRange();
962 962 if (auto tf = DateTimeRangeHelper::computeTransformation(oldRange, newRange))
963 963 emit this->transform_sig(tf.value(), false);
964 964 }
965 965 else if (impl->isDrawingZoneRect())
966 966 {
967 967 impl->endDrawingZone();
968 968 }
969 969 else
970 970 {
971 971 setCursor(Qt::ArrowCursor);
972 972 }
973 973 auto posInPlot = this->impl->m_plot->mapFromParent(event->pos());
974 974 if (auto item = impl->m_plot->itemAt(posInPlot))
975 975 {
976 976 if (qobject_cast<VisualizationSelectionZoneItem*>(item))
977 977 {
978 978 QMouseEvent e { QEvent::MouseButtonRelease, posInPlot, event->button(),
979 979 event->buttons(), event->modifiers() };
980 980 sqpApp->sendEvent(this->impl->m_plot, &e);
981 981 }
982 982 }
983 983 event->accept();
984 984 }
985 985
986 986 void VisualizationGraphWidget::mousePressEvent(QMouseEvent* event)
987 987 {
988 988 if (event->button() == Qt::RightButton)
989 989 {
990 990 onGraphMenuRequested(event->pos());
991 991 }
992 992 else
993 993 {
994 994 auto selectedZone = impl->selectionZoneAt(event->pos());
995 995 switch (sqpApp->plotsInteractionMode())
996 996 {
997 997 case SqpApplication::PlotsInteractionMode::DragAndDrop:
998 998 break;
999 999 case SqpApplication::PlotsInteractionMode::SelectionZones:
1000 1000 impl->setSelectionZonesEditionEnabled(true);
1001 1001 if ((event->modifiers() == Qt::ControlModifier) && (selectedZone != nullptr))
1002 1002 {
1003 1003 auto alreadySelectedZones
1004 1004 = parentVisualizationWidget()->selectionZoneManager().selectedItems();
1005 1005 selectedZone->setAssociatedEditedZones(alreadySelectedZones);
1006 1006 if (cpp_utils::containers::contains(alreadySelectedZones, selectedZone))
1007 1007 {
1008 1008 alreadySelectedZones.removeOne(selectedZone);
1009 1009 }
1010 1010 else
1011 1011 {
1012 1012 alreadySelectedZones.append(selectedZone);
1013 1013 }
1014 1014 parentVisualizationWidget()->selectionZoneManager().select(
1015 1015 alreadySelectedZones);
1016 1016 }
1017 1017 else
1018 1018 {
1019 1019 if (!selectedZone)
1020 1020 {
1021 1021 parentVisualizationWidget()->selectionZoneManager().clearSelection();
1022 1022 impl->startDrawingZone(event->pos());
1023 1023 }
1024 1024 else
1025 1025 {
1026 1026 parentVisualizationWidget()->selectionZoneManager().select(
1027 1027 { selectedZone });
1028 1028 }
1029 1029 }
1030 1030 {
1031 1031 auto posInPlot = this->impl->m_plot->mapFromParent(event->pos());
1032 1032 if (auto item = impl->m_plot->itemAt(posInPlot))
1033 1033 {
1034 1034 if (qobject_cast<VisualizationSelectionZoneItem*>(item))
1035 1035 {
1036 1036 QMouseEvent e { QEvent::MouseButtonPress, posInPlot, event->button(),
1037 1037 event->buttons(), event->modifiers() };
1038 1038 sqpApp->sendEvent(this->impl->m_plot, &e);
1039 1039 }
1040 1040 }
1041 1041 }
1042 1042 break;
1043 1043 case SqpApplication::PlotsInteractionMode::ZoomBox:
1044 1044 impl->startDrawingRect(event->pos());
1045 1045 break;
1046 1046 default:
1047 1047 if (auto item = impl->m_plot->itemAt(event->pos()))
1048 1048 {
1049 1049 emit impl->m_plot->itemClick(item, event);
1050 1050 if (qobject_cast<VisualizationSelectionZoneItem*>(item))
1051 1051 {
1052 1052 setCursor(Qt::ClosedHandCursor);
1053 1053 impl->enterPlotDrag(event->pos());
1054 1054 }
1055 1055 }
1056 1056 else
1057 1057 {
1058 1058 setCursor(Qt::ClosedHandCursor);
1059 1059 impl->enterPlotDrag(event->pos());
1060 1060 }
1061 1061 }
1062 1062 }
1063 1063 // event->accept();
1064 1064 QWidget::mousePressEvent(event);
1065 1065 }
1066 1066
1067 1067 void VisualizationGraphWidget::mouseDoubleClickEvent(QMouseEvent* event)
1068 1068 {
1069 1069 impl->m_RenderingDelegate->onMouseDoubleClick(event);
1070 1070 }
1071 1071
1072 1072 void VisualizationGraphWidget::keyReleaseEvent(QKeyEvent* event)
1073 1073 {
1074 1074 switch (event->key())
1075 1075 {
1076 1076 case Qt::Key_Control:
1077 1077 event->accept();
1078 1078 break;
1079 1079 case Qt::Key_Shift:
1080 1080 event->accept();
1081 1081 break;
1082 1082 default:
1083 1083 QWidget::keyReleaseEvent(event);
1084 1084 break;
1085 1085 }
1086 1086 setCursor(Qt::ArrowCursor);
1087 1087 // event->accept();
1088 1088 }
1089 1089
1090 1090 void VisualizationGraphWidget::keyPressEvent(QKeyEvent* event)
1091 1091 {
1092 1092 switch (event->key())
1093 1093 {
1094 1094 case Qt::Key_Control:
1095 1095 setCursor(Qt::CrossCursor);
1096 1096 break;
1097 1097 case Qt::Key_Shift:
1098 1098 break;
1099 1099 case Qt::Key_M:
1100 1100 impl->rescaleY();
1101 1101 impl->m_plot->replot(QCustomPlot::rpQueuedReplot);
1102 1102 break;
1103 1103 case Qt::Key_Left:
1104 1104 if (event->modifiers() != Qt::ControlModifier)
1105 1105 {
1106 1106 move(-0.1, Qt::Horizontal);
1107 1107 }
1108 1108 else
1109 1109 {
1110 1110 zoom(2, this->width() / 2, Qt::Horizontal);
1111 1111 }
1112 1112 break;
1113 1113 case Qt::Key_Right:
1114 1114 if (event->modifiers() != Qt::ControlModifier)
1115 1115 {
1116 1116 move(0.1, Qt::Horizontal);
1117 1117 }
1118 1118 else
1119 1119 {
1120 1120 zoom(0.5, this->width() / 2, Qt::Horizontal);
1121 1121 }
1122 1122 break;
1123 1123 case Qt::Key_Up:
1124 1124 if (event->modifiers() != Qt::ControlModifier)
1125 1125 {
1126 1126 move(0.1, Qt::Vertical);
1127 1127 }
1128 1128 else
1129 1129 {
1130 1130 zoom(0.5, this->height() / 2, Qt::Vertical);
1131 1131 }
1132 1132 break;
1133 1133 case Qt::Key_Down:
1134 1134 if (event->modifiers() != Qt::ControlModifier)
1135 1135 {
1136 1136 move(-0.1, Qt::Vertical);
1137 1137 }
1138 1138 else
1139 1139 {
1140 1140 zoom(2, this->height() / 2, Qt::Vertical);
1141 1141 }
1142 1142 break;
1143 1143 default:
1144 1144 QWidget::keyPressEvent(event);
1145 1145 break;
1146 1146 }
1147 1147 }
1148 1148
1149 1149 QCustomPlot& VisualizationGraphWidget::plot() const noexcept
1150 1150 {
1151 1151 return *impl->m_plot;
1152 1152 }
1153 1153
1154 1154 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint& pos) noexcept
1155 1155 {
1156 1156 QMenu graphMenu {};
1157 1157
1158 1158 // Iterates on variables (unique keys)
1159 1159 for (auto it = impl->m_VariableToPlotMultiMap.cbegin(),
1160 1160 end = impl->m_VariableToPlotMultiMap.cend();
1161 1161 it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first))
1162 1162 {
1163 1163 // 'Remove variable' action
1164 1164 graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()),
1165 1165 [this, var = it->first]() { removeVariable(var); });
1166 1166 }
1167 1167
1168 1168 if (!impl->m_ZoomStack.isEmpty())
1169 1169 {
1170 1170 if (!graphMenu.isEmpty())
1171 1171 {
1172 1172 graphMenu.addSeparator();
1173 1173 }
1174 1174
1175 1175 graphMenu.addAction(tr("Undo Zoom"), [this]() { undoZoom(); });
1176 1176 }
1177 1177
1178 1178 // Selection Zone Actions
1179 1179 auto selectionZoneItem = impl->selectionZoneAt(pos);
1180 1180 if (selectionZoneItem)
1181 1181 {
1182 1182 auto selectedItems = parentVisualizationWidget()->selectionZoneManager().selectedItems();
1183 1183 selectedItems.removeAll(selectionZoneItem);
1184 1184 selectedItems.prepend(selectionZoneItem); // Put the current selection zone first
1185 1185
1186 1186 auto zoneActions = sqpApp->actionsGuiController().selectionZoneActions();
1187 1187 if (!zoneActions.isEmpty() && !graphMenu.isEmpty())
1188 1188 {
1189 1189 graphMenu.addSeparator();
1190 1190 }
1191 1191
1192 1192 QHash<QString, QMenu*> subMenus;
1193 1193 QHash<QString, bool> subMenusEnabled;
1194 1194 QHash<QString, FilteringAction*> filteredMenu;
1195 1195
1196 1196 for (auto zoneAction : zoneActions)
1197 1197 {
1198 1198
1199 1199 auto isEnabled = zoneAction->isEnabled(selectedItems);
1200 1200
1201 1201 auto menu = &graphMenu;
1202 1202 QString menuPath;
1203 1203 for (auto subMenuName : zoneAction->subMenuList())
1204 1204 {
1205 1205 menuPath += '/';
1206 1206 menuPath += subMenuName;
1207 1207
1208 1208 if (!subMenus.contains(menuPath))
1209 1209 {
1210 1210 menu = menu->addMenu(subMenuName);
1211 1211 subMenus[menuPath] = menu;
1212 1212 subMenusEnabled[menuPath] = isEnabled;
1213 1213 }
1214 1214 else
1215 1215 {
1216 1216 menu = subMenus.value(menuPath);
1217 1217 if (isEnabled)
1218 1218 {
1219 1219 // The sub menu is enabled if at least one of its actions is enabled
1220 1220 subMenusEnabled[menuPath] = true;
1221 1221 }
1222 1222 }
1223 1223 }
1224 1224
1225 1225 FilteringAction* filterAction = nullptr;
1226 1226 if (sqpApp->actionsGuiController().isMenuFiltered(zoneAction->subMenuList()))
1227 1227 {
1228 1228 filterAction = filteredMenu.value(menuPath);
1229 1229 if (!filterAction)
1230 1230 {
1231 1231 filterAction = new FilteringAction { this };
1232 1232 filteredMenu[menuPath] = filterAction;
1233 1233 menu->addAction(filterAction);
1234 1234 }
1235 1235 }
1236 1236
1237 1237 auto action = menu->addAction(zoneAction->name());
1238 1238 action->setEnabled(isEnabled);
1239 1239 action->setShortcut(zoneAction->displayedShortcut());
1240 1240 QObject::connect(action, &QAction::triggered,
1241 1241 [zoneAction, selectedItems]() { zoneAction->execute(selectedItems); });
1242 1242
1243 1243 if (filterAction && zoneAction->isFilteringAllowed())
1244 1244 {
1245 1245 filterAction->addActionToFilter(action);
1246 1246 }
1247 1247 }
1248 1248
1249 1249 for (auto it = subMenus.cbegin(); it != subMenus.cend(); ++it)
1250 1250 {
1251 1251 it.value()->setEnabled(subMenusEnabled[it.key()]);
1252 1252 }
1253 1253 }
1254 1254
1255 1255 if (!graphMenu.isEmpty())
1256 1256 {
1257 1257 graphMenu.exec(QCursor::pos());
1258 1258 }
1259 1259 }
1260 1260
1261 1261 void VisualizationGraphWidget::onMouseDoubleClick(QMouseEvent* event) noexcept
1262 1262 {
1263 1263 impl->m_RenderingDelegate->onMouseDoubleClick(event);
1264 1264 }
1265 1265
1266 1266 void VisualizationGraphWidget::onMouseMove(QMouseEvent* event) noexcept
1267 1267 {
1268 1268 // Handles plot rendering when mouse is moving
1269 1269 impl->m_RenderingDelegate->updateTooltip(event);
1270 1270
1271 1271 auto axisPos = impl->posToAxisPos(event->pos());
1272 1272
1273 1273 // Zoom box and zone drawing
1274 1274 if (impl->m_DrawingZoomRect)
1275 1275 {
1276 1276 impl->m_DrawingZoomRect->bottomRight->setCoords(axisPos);
1277 1277 }
1278 1278 else if (impl->m_DrawingZone)
1279 1279 {
1280 1280 impl->m_DrawingZone->setEnd(axisPos.x());
1281 1281 }
1282 1282
1283 1283 // Cursor
1284 1284 if (auto parentZone = parentZoneWidget())
1285 1285 {
1286 1286 if (impl->pointIsInAxisRect(axisPos, plot()))
1287 1287 {
1288 1288 parentZone->notifyMouseMoveInGraph(event->pos(), axisPos, this);
1289 1289 }
1290 1290 else
1291 1291 {
1292 1292 parentZone->notifyMouseLeaveGraph(this);
1293 1293 }
1294 1294 }
1295 1295
1296 1296 // Search for the selection zone under the mouse
1297 1297 auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos());
1298 1298 if (selectionZoneItemUnderCursor && !impl->m_DrawingZone
1299 1299 && sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones)
1300 1300 {
1301 1301
1302 1302 // Sets the appropriate cursor shape
1303 1303 auto cursorShape = selectionZoneItemUnderCursor->curshorShapeForPosition(event->pos());
1304 1304 setCursor(cursorShape);
1305 1305
1306 1306 // Manages the hovered zone
1307 1307 if (selectionZoneItemUnderCursor != impl->m_HoveredZone)
1308 1308 {
1309 1309 if (impl->m_HoveredZone)
1310 1310 {
1311 1311 impl->m_HoveredZone->setHovered(false);
1312 1312 }
1313 1313 selectionZoneItemUnderCursor->setHovered(true);
1314 1314 impl->m_HoveredZone = selectionZoneItemUnderCursor;
1315 1315 plot().replot(QCustomPlot::rpQueuedReplot);
1316 1316 }
1317 1317 }
1318 1318 else
1319 1319 {
1320 1320 // There is no zone under the mouse or the interaction mode is not "selection zones"
1321 1321 if (impl->m_HoveredZone)
1322 1322 {
1323 1323 impl->m_HoveredZone->setHovered(false);
1324 1324 impl->m_HoveredZone = nullptr;
1325 1325 }
1326 1326
1327 1327 setCursor(Qt::ArrowCursor);
1328 1328 }
1329 1329
1330 1330 impl->m_HasMovedMouse = true;
1331 1331 VisualizationDragWidget::mouseMoveEvent(event);
1332 1332 }
1333 1333
1334 1334 void VisualizationGraphWidget::onMouseWheel(QWheelEvent* event) noexcept
1335 1335 {
1336 1336 // Processes event only if the wheel occurs on axis rect
1337 1337 if (!dynamic_cast<QCPAxisRect*>(impl->m_plot->layoutElementAt(event->posF())))
1338 1338 {
1339 1339 return;
1340 1340 }
1341 1341
1342 1342 auto value = event->angleDelta().x() + event->angleDelta().y();
1343 1343 if (value != 0)
1344 1344 {
1345 1345
1346 1346 auto direction = value > 0 ? 1.0 : -1.0;
1347 1347 auto isZoomX = event->modifiers().testFlag(HORIZONTAL_ZOOM_MODIFIER);
1348 1348 auto isZoomY = event->modifiers().testFlag(VERTICAL_ZOOM_MODIFIER);
1349 1349 impl->m_IsCalibration = event->modifiers().testFlag(VERTICAL_PAN_MODIFIER);
1350 1350
1351 1351 auto zoomOrientations = QFlags<Qt::Orientation> {};
1352 1352 zoomOrientations.setFlag(Qt::Horizontal, isZoomX);
1353 1353 zoomOrientations.setFlag(Qt::Vertical, isZoomY);
1354 1354
1355 1355 impl->m_plot->axisRect()->setRangeZoom(zoomOrientations);
1356 1356
1357 1357 if (!isZoomX && !isZoomY)
1358 1358 {
1359 1359 auto axis = plot().axisRect()->axis(QCPAxis::atBottom);
1360 1360 auto diff = direction * (axis->range().size() * (PAN_SPEED / 100.0));
1361 1361
1362 1362 axis->setRange(axis->range() + diff);
1363 1363
1364 1364 if (plot().noAntialiasingOnDrag())
1365 1365 {
1366 1366 plot().setNotAntialiasedElements(QCP::aeAll);
1367 1367 }
1368 1368
1369 1369 // plot().replot(QCustomPlot::rpQueuedReplot);
1370 1370 }
1371 1371 }
1372 1372 }
1373 1373
1374 1374 void VisualizationGraphWidget::onMousePress(QMouseEvent* event) noexcept
1375 1375 {
1376 1376 auto isDragDropClick = event->modifiers().testFlag(DRAG_DROP_MODIFIER);
1377 1377 auto isSelectionZoneMode
1378 1378 = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones;
1379 1379 auto isLeftClick = event->buttons().testFlag(Qt::LeftButton);
1380 1380
1381 1381 if (!isDragDropClick && isLeftClick)
1382 1382 {
1383 1383 if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::ZoomBox)
1384 1384 {
1385 1385 // Starts a zoom box
1386 1386 impl->startDrawingRect(event->pos());
1387 1387 }
1388 1388 else if (isSelectionZoneMode && impl->m_DrawingZone == nullptr)
1389 1389 {
1390 1390 // Starts a new selection zone
1391 1391 auto zoneAtPos = impl->selectionZoneAt(event->pos());
1392 1392 if (!zoneAtPos)
1393 1393 {
1394 1394 impl->startDrawingZone(event->pos());
1395 1395 }
1396 1396 }
1397 1397 }
1398 1398
1399 1399
1400 1400 // Allows zone edition only in selection zone mode without drag&drop
1401 1401 impl->setSelectionZonesEditionEnabled(isSelectionZoneMode && !isDragDropClick);
1402 1402
1403 1403 // Selection / Deselection
1404 1404 if (isSelectionZoneMode)
1405 1405 {
1406 1406 auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER);
1407 1407 auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos());
1408 1408
1409 1409
1410 1410 if (selectionZoneItemUnderCursor && !selectionZoneItemUnderCursor->selected()
1411 1411 && !isMultiSelectionClick)
1412 1412 {
1413 1413 parentVisualizationWidget()->selectionZoneManager().select(
1414 1414 { selectionZoneItemUnderCursor });
1415 1415 }
1416 1416 else if (!selectionZoneItemUnderCursor && !isMultiSelectionClick && isLeftClick)
1417 1417 {
1418 1418 parentVisualizationWidget()->selectionZoneManager().clearSelection();
1419 1419 }
1420 1420 else
1421 1421 {
1422 1422 // No selection change
1423 1423 }
1424 1424
1425 1425 if (selectionZoneItemUnderCursor && isLeftClick)
1426 1426 {
1427 1427 selectionZoneItemUnderCursor->setAssociatedEditedZones(
1428 1428 parentVisualizationWidget()->selectionZoneManager().selectedItems());
1429 1429 }
1430 1430 }
1431 1431
1432 1432
1433 1433 impl->m_HasMovedMouse = false;
1434 1434 VisualizationDragWidget::mousePressEvent(event);
1435 1435 }
1436 1436
1437 1437 void VisualizationGraphWidget::onMouseRelease(QMouseEvent* event) noexcept
1438 1438 {
1439 1439 if (impl->m_DrawingZoomRect)
1440 1440 {
1441 1441
1442 1442 auto axisX = plot().axisRect()->axis(QCPAxis::atBottom);
1443 1443 auto axisY = plot().axisRect()->axis(QCPAxis::atLeft);
1444 1444
1445 1445 auto newAxisXRange = QCPRange { impl->m_DrawingZoomRect->topLeft->coords().x(),
1446 1446 impl->m_DrawingZoomRect->bottomRight->coords().x() };
1447 1447
1448 1448 auto newAxisYRange = QCPRange { impl->m_DrawingZoomRect->topLeft->coords().y(),
1449 1449 impl->m_DrawingZoomRect->bottomRight->coords().y() };
1450 1450
1451 1451 impl->removeDrawingRect();
1452 1452
1453 1453 if (newAxisXRange.size() > axisX->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0)
1454 1454 && newAxisYRange.size() > axisY->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0))
1455 1455 {
1456 1456 impl->m_ZoomStack.push(qMakePair(axisX->range(), axisY->range()));
1457 1457 axisX->setRange(newAxisXRange);
1458 1458 axisY->setRange(newAxisYRange);
1459 1459
1460 1460 plot().replot(QCustomPlot::rpQueuedReplot);
1461 1461 }
1462 1462 }
1463 1463
1464 1464 impl->endDrawingZone();
1465 1465
1466 1466 // Selection / Deselection
1467 1467 auto isSelectionZoneMode
1468 1468 = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones;
1469 1469 if (isSelectionZoneMode)
1470 1470 {
1471 1471 auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER);
1472 1472 auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos());
1473 1473 if (selectionZoneItemUnderCursor && event->button() == Qt::LeftButton
1474 1474 && !impl->m_HasMovedMouse)
1475 1475 {
1476 1476
1477 1477 auto zonesUnderCursor = impl->selectionZonesAt(event->pos(), plot());
1478 1478 if (zonesUnderCursor.count() > 1)
1479 1479 {
1480 1480 // There are multiple zones under the mouse.
1481 1481 // Performs the selection with a selection dialog.
1482 1482 VisualizationMultiZoneSelectionDialog dialog { this };
1483 1483 dialog.setZones(zonesUnderCursor);
1484 1484 dialog.move(mapToGlobal(event->pos() - QPoint(dialog.width() / 2, 20)));
1485 1485 dialog.activateWindow();
1486 1486 dialog.raise();
1487 1487 if (dialog.exec() == QDialog::Accepted)
1488 1488 {
1489 1489 auto selection = dialog.selectedZones();
1490 1490
1491 1491 if (!isMultiSelectionClick)
1492 1492 {
1493 1493 parentVisualizationWidget()->selectionZoneManager().clearSelection();
1494 1494 }
1495 1495
1496 1496 for (auto it = selection.cbegin(); it != selection.cend(); ++it)
1497 1497 {
1498 1498 auto zone = it.key();
1499 1499 auto isSelected = it.value();
1500 1500 parentVisualizationWidget()->selectionZoneManager().setSelected(
1501 1501 zone, isSelected);
1502 1502
1503 1503 if (isSelected)
1504 1504 {
1505 1505 // Puts the zone on top of the stack so it can be moved or resized
1506 1506 impl->moveSelectionZoneOnTop(zone, plot());
1507 1507 }
1508 1508 }
1509 1509 }
1510 1510 }
1511 1511 else
1512 1512 {
1513 1513 if (!isMultiSelectionClick)
1514 1514 {
1515 1515 parentVisualizationWidget()->selectionZoneManager().select(
1516 1516 { selectionZoneItemUnderCursor });
1517 1517 impl->moveSelectionZoneOnTop(selectionZoneItemUnderCursor, plot());
1518 1518 }
1519 1519 else
1520 1520 {
1521 1521 parentVisualizationWidget()->selectionZoneManager().setSelected(
1522 1522 selectionZoneItemUnderCursor,
1523 1523 !selectionZoneItemUnderCursor->selected()
1524 1524 || event->button() == Qt::RightButton);
1525 1525 }
1526 1526 }
1527 1527 }
1528 1528 else
1529 1529 {
1530 1530 // No selection change
1531 1531 }
1532 1532 }
1533 1533 }
1534 1534
1535 1535 void VisualizationGraphWidget::onDataCacheVariableUpdated()
1536 1536 {
1537 1537 auto graphRange = impl->m_plot->xAxis->range();
1538 1538 auto dateTime = DateTimeRange { graphRange.lower, graphRange.upper };
1539 1539
1540 1540 for (auto& variableEntry : impl->m_VariableToPlotMultiMap)
1541 1541 {
1542 1542 auto variable = variableEntry.first;
1543 1543 qCDebug(LOG_VisualizationGraphWidget())
1544 1544 << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range();
1545 1545 qCDebug(LOG_VisualizationGraphWidget())
1546 1546 << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime;
1547 1547 if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range()))
1548 1548 {
1549 1549 impl->updateData(variableEntry.second, variable, variable->range());
1550 1550 }
1551 1551 }
1552 1552 }
1553 1553
1554 1554 void VisualizationGraphWidget::onUpdateVarDisplaying(
1555 1555 std::shared_ptr<Variable2> variable, const DateTimeRange& range)
1556 1556 {
1557 1557 auto it = impl->m_VariableToPlotMultiMap.find(variable);
1558 1558 if (it != impl->m_VariableToPlotMultiMap.end())
1559 1559 {
1560 1560 impl->updateData(it->second, variable, range);
1561 1561 }
1562 1562 }
1563 1563
1564 1564 void VisualizationGraphWidget::variableUpdated(QUuid id)
1565 1565 {
1566 1566 for (auto& [var, plotables] : impl->m_VariableToPlotMultiMap)
1567 1567 {
1568 1568 if (var->ID() == id)
1569 1569 {
1570 1570 impl->updateData(plotables, var, this->graphRange());
1571 1571 }
1572 1572 }
1573 1573 }
1574 1574
1575 1575 void VisualizationGraphWidget::variableDeleted(const std::shared_ptr<Variable2>& variable)
1576 1576 {
1577 1577 this->removeVariable(variable);
1578 1578 }
@@ -1,415 +1,415
1 1 #include "Visualization/VisualizationTabWidget.h"
2 2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 3 #include "ui_VisualizationTabWidget.h"
4 4
5 5 #include "Visualization/VisualizationGraphWidget.h"
6 6 #include "Visualization/VisualizationZoneWidget.h"
7 7
8 8 #include "Visualization/MacScrollBarStyle.h"
9 9
10 #include "DataSource/DataSourceController.h"
10 #include "DataSource/datasources.h"
11 11 #include "Variable/VariableController2.h"
12 12
13 #include "Common/MimeTypesDef.h"
13 #include "MimeTypes/MimeTypes.h"
14 14
15 15 #include "DragAndDrop/DragDropGuiController.h"
16 16 #include "SqpApplication.h"
17 17
18 18 Q_LOGGING_CATEGORY(LOG_VisualizationTabWidget, "VisualizationTabWidget")
19 19
20 20 namespace
21 21 {
22 22
23 23 /**
24 24 * Applies a function to all zones of the tab represented by its layout
25 25 * @param layout the layout that contains zones
26 26 * @param fun the function to apply to each zone
27 27 */
28 28 template <typename Fun>
29 29 void processZones(QLayout& layout, Fun fun)
30 30 {
31 31 for (auto i = 0; i < layout.count(); ++i)
32 32 {
33 33 if (auto item = layout.itemAt(i))
34 34 {
35 35 if (auto visualizationZoneWidget
36 36 = qobject_cast<VisualizationZoneWidget*>(item->widget()))
37 37 {
38 38 fun(*visualizationZoneWidget);
39 39 }
40 40 }
41 41 }
42 42 }
43 43
44 44 /// Generates a default name for a new zone, according to the number of zones already displayed in
45 45 /// the tab
46 46 QString defaultZoneName(QLayout& layout)
47 47 {
48 48 QSet<QString> existingNames;
49 49 processZones(
50 50 layout, [&existingNames](auto& zoneWidget) { existingNames.insert(zoneWidget.name()); });
51 51
52 52 int zoneNum = 1;
53 53 QString name;
54 54 do
55 55 {
56 56 name = QObject::tr("Zone ").append(QString::number(zoneNum));
57 57 ++zoneNum;
58 58 } while (existingNames.contains(name));
59 59
60 60 return name;
61 61 }
62 62
63 63 } // namespace
64 64
65 65 struct VisualizationTabWidget::VisualizationTabWidgetPrivate
66 66 {
67 67 explicit VisualizationTabWidgetPrivate(const QString& name) : m_Name { name } {}
68 68
69 69 QString m_Name;
70 70
71 71 #ifdef Q_OS_MAC
72 72 std::unique_ptr<MacScrollBarStyle> m_MacScrollBarStyle = std::make_unique<MacScrollBarStyle>();
73 73 #endif
74 74
75 75 void dropGraph(int index, VisualizationTabWidget* tabWidget);
76 76 void dropZone(int index, VisualizationTabWidget* tabWidget);
77 77 void dropVariables(const std::vector<std::shared_ptr<Variable2>>& variables, int index,
78 78 VisualizationTabWidget* tabWidget);
79 79 void dropProducts(
80 80 const QVariantList& productsMetaData, int index, VisualizationTabWidget* tabWidget);
81 81 };
82 82
83 83 VisualizationTabWidget::VisualizationTabWidget(const QString& name, QWidget* parent)
84 84 : QWidget { parent }
85 85 , ui { new Ui::VisualizationTabWidget }
86 86 , impl { spimpl::make_unique_impl<VisualizationTabWidgetPrivate>(name) }
87 87 {
88 88 ui->setupUi(this);
89 89
90 90 #ifdef Q_OS_MAC
91 91 impl->m_MacScrollBarStyle->selfInstallOn(ui->scrollArea, true);
92 92 #endif
93 93
94 94 ui->dragDropContainer->setPlaceHolderType(DragDropGuiController::PlaceHolderType::Zone, "Zone");
95 95 ui->dragDropContainer->layout()->setContentsMargins(0, 0, 0, 12);
96 96 ui->dragDropContainer->layout()->setSpacing(0);
97 97 ui->dragDropContainer->setMimeType(
98 MIME_TYPE_GRAPH, VisualizationDragDropContainer::DropBehavior::Inserted);
98 MIME::MIME_TYPE_GRAPH, VisualizationDragDropContainer::DropBehavior::Inserted);
99 99 ui->dragDropContainer->setMimeType(
100 MIME_TYPE_ZONE, VisualizationDragDropContainer::DropBehavior::Inserted);
100 MIME::MIME_TYPE_ZONE, VisualizationDragDropContainer::DropBehavior::Inserted);
101 101 ui->dragDropContainer->setMimeType(
102 MIME_TYPE_VARIABLE_LIST, VisualizationDragDropContainer::DropBehavior::Inserted);
102 MIME::MIME_TYPE_VARIABLE_LIST, VisualizationDragDropContainer::DropBehavior::Inserted);
103 103 ui->dragDropContainer->setMimeType(
104 MIME_TYPE_PRODUCT_LIST, VisualizationDragDropContainer::DropBehavior::Inserted);
104 MIME::MIME_TYPE_PRODUCT_LIST, VisualizationDragDropContainer::DropBehavior::Inserted);
105 105
106 106 ui->dragDropContainer->setAcceptMimeDataFunction([this](auto mimeData) {
107 107 return sqpApp->dragDropGuiController().checkMimeDataForVisualization(
108 108 mimeData, ui->dragDropContainer);
109 109 });
110 110
111 111 connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccuredInContainer, this,
112 112 &VisualizationTabWidget::dropMimeData);
113 113
114 114 sqpApp->dragDropGuiController().addDragDropScrollArea(ui->scrollArea);
115 115
116 116 // Widget is deleted when closed
117 117 setAttribute(Qt::WA_DeleteOnClose);
118 118 }
119 119
120 120 VisualizationTabWidget::~VisualizationTabWidget()
121 121 {
122 122 sqpApp->dragDropGuiController().removeDragDropScrollArea(ui->scrollArea);
123 123 delete ui;
124 124 }
125 125
126 126 void VisualizationTabWidget::addZone(VisualizationZoneWidget* zoneWidget)
127 127 {
128 128 ui->dragDropContainer->addDragWidget(zoneWidget);
129 129 }
130 130
131 131 void VisualizationTabWidget::insertZone(int index, VisualizationZoneWidget* zoneWidget)
132 132 {
133 133 ui->dragDropContainer->insertDragWidget(index, zoneWidget);
134 134 }
135 135
136 136 QStringList VisualizationTabWidget::availableZoneWidgets() const
137 137 {
138 138 QStringList zones;
139 139 processZones(
140 140 tabLayout(), [&zones](VisualizationZoneWidget& zoneWidget) { zones << zoneWidget.name(); });
141 141
142 142 return zones;
143 143 }
144 144
145 145 VisualizationZoneWidget* VisualizationTabWidget::getZoneWithName(const QString& zoneName)
146 146 {
147 147 VisualizationZoneWidget* result = nullptr;
148 148 processZones(tabLayout(), [&zoneName, &result](VisualizationZoneWidget& zoneWidget) {
149 149 if (!result && zoneWidget.name() == zoneName)
150 150 {
151 151 result = &zoneWidget;
152 152 }
153 153 });
154 154
155 155 return result;
156 156 }
157 157
158 158 VisualizationZoneWidget* VisualizationTabWidget::createZone(std::shared_ptr<Variable2> variable)
159 159 {
160 160 return createZone({ variable }, -1);
161 161 }
162 162
163 163 VisualizationZoneWidget* VisualizationTabWidget::createZone(
164 164 const std::vector<std::shared_ptr<Variable2>>& variables, int index)
165 165 {
166 166 auto zoneWidget = createEmptyZone(index);
167 167
168 168 // Creates a new graph into the zone
169 169 zoneWidget->createGraph(variables, index);
170 170
171 171 return zoneWidget;
172 172 }
173 173
174 174 VisualizationZoneWidget* VisualizationTabWidget::createEmptyZone(int index)
175 175 {
176 176 auto zoneWidget
177 177 = new VisualizationZoneWidget { defaultZoneName(*ui->dragDropContainer->layout()), this };
178 178 this->insertZone(index, zoneWidget);
179 179
180 180 return zoneWidget;
181 181 }
182 182
183 183 void VisualizationTabWidget::accept(IVisualizationWidgetVisitor* visitor)
184 184 {
185 185 if (visitor)
186 186 {
187 187 visitor->visitEnter(this);
188 188
189 189 // Apply visitor to zone children: widgets different from zones are not visited (no action)
190 190 processZones(tabLayout(),
191 191 [visitor](VisualizationZoneWidget& zoneWidget) { zoneWidget.accept(visitor); });
192 192
193 193 visitor->visitLeave(this);
194 194 }
195 195 else
196 196 {
197 197 qCCritical(LOG_VisualizationTabWidget()) << tr("Can't visit widget : the visitor is null");
198 198 }
199 199 }
200 200
201 201 bool VisualizationTabWidget::canDrop(Variable2& variable) const
202 202 {
203 203 // A tab can always accomodate a variable
204 204 Q_UNUSED(variable);
205 205 return true;
206 206 }
207 207
208 208 bool VisualizationTabWidget::contains(Variable2& variable) const
209 209 {
210 210 Q_UNUSED(variable);
211 211 return false;
212 212 }
213 213
214 214 QString VisualizationTabWidget::name() const
215 215 {
216 216 return impl->m_Name;
217 217 }
218 218
219 219 void VisualizationTabWidget::closeEvent(QCloseEvent* event)
220 220 {
221 221 // Closes zones in the tab
222 222 processZones(tabLayout(), [](VisualizationZoneWidget& zoneWidget) { zoneWidget.close(); });
223 223
224 224 QWidget::closeEvent(event);
225 225 }
226 226
227 227 QLayout& VisualizationTabWidget::tabLayout() const noexcept
228 228 {
229 229 return *ui->dragDropContainer->layout();
230 230 }
231 231
232 232 void VisualizationTabWidget::dropMimeData(int index, const QMimeData* mimeData)
233 233 {
234 if (mimeData->hasFormat(MIME_TYPE_GRAPH))
234 if (mimeData->hasFormat(MIME::MIME_TYPE_GRAPH))
235 235 {
236 236 impl->dropGraph(index, this);
237 237 }
238 else if (mimeData->hasFormat(MIME_TYPE_ZONE))
238 else if (mimeData->hasFormat(MIME::MIME_TYPE_ZONE))
239 239 {
240 240 impl->dropZone(index, this);
241 241 }
242 else if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST))
242 else if (mimeData->hasFormat(MIME::MIME_TYPE_VARIABLE_LIST))
243 243 {
244 244 auto variables = sqpApp->variableController().variables(
245 Variable2::IDs(mimeData->data(MIME_TYPE_VARIABLE_LIST)));
245 Variable2::IDs(mimeData->data(MIME::MIME_TYPE_VARIABLE_LIST)));
246 246 impl->dropVariables(variables, index, this);
247 247 }
248 else if (mimeData->hasFormat(MIME_TYPE_PRODUCT_LIST))
248 else if (mimeData->hasFormat(MIME::MIME_TYPE_PRODUCT_LIST))
249 249 {
250 auto productsData = sqpApp->dataSourceController().productsDataForMimeData(
251 mimeData->data(MIME_TYPE_PRODUCT_LIST));
250 auto productsData = MIME::decode(
251 mimeData->data(MIME::MIME_TYPE_PRODUCT_LIST));
252 252 impl->dropProducts(productsData, index, this);
253 253 }
254 254 else
255 255 {
256 256 qCWarning(LOG_VisualizationZoneWidget())
257 257 << tr("VisualizationTabWidget::dropMimeData, unknown MIME data received.");
258 258 }
259 259 }
260 260
261 261 void VisualizationTabWidget::VisualizationTabWidgetPrivate::dropGraph(
262 262 int index, VisualizationTabWidget* tabWidget)
263 263 {
264 264 auto& helper = sqpApp->dragDropGuiController();
265 265
266 266 auto graphWidget = qobject_cast<VisualizationGraphWidget*>(helper.getCurrentDragWidget());
267 267 if (!graphWidget)
268 268 {
269 269 qCWarning(LOG_VisualizationZoneWidget())
270 270 << tr("VisualizationTabWidget::dropGraph, drop aborted, the dropped graph is not "
271 271 "found or invalid.");
272 272 Q_ASSERT(false);
273 273 return;
274 274 }
275 275
276 276 auto parentDragDropContainer
277 277 = qobject_cast<VisualizationDragDropContainer*>(graphWidget->parentWidget());
278 278 if (!parentDragDropContainer)
279 279 {
280 280 qCWarning(LOG_VisualizationZoneWidget())
281 281 << tr("VisualizationTabWidget::dropGraph, drop aborted, the parent container of "
282 282 "the dropped graph is not found.");
283 283 Q_ASSERT(false);
284 284 return;
285 285 }
286 286
287 287 auto nbGraph = parentDragDropContainer->countDragWidget();
288 288
289 289 const auto& variables = graphWidget->variables();
290 290
291 291 if (!variables.empty())
292 292 {
293 293 // Abort the requests for the variables (if any)
294 294 // Commented, because it's not sure if it's needed or not
295 295 // for (const auto& var : variables)
296 296 //{
297 297 // sqpApp->variableController().onAbortProgressRequested(var);
298 298 //}
299 299
300 300 if (nbGraph == 1)
301 301 {
302 302 // This is the only graph in the previous zone, close the zone
303 303 helper.delayedCloseWidget(graphWidget->parentZoneWidget());
304 304 }
305 305 else
306 306 {
307 307 // Close the graph
308 308 helper.delayedCloseWidget(graphWidget);
309 309 }
310 310
311 311 auto zoneWidget = tabWidget->createZone(variables, index);
312 312 auto firstGraph = zoneWidget->firstGraph();
313 313 if (firstGraph)
314 314 {
315 315 firstGraph->addSelectionZones(graphWidget->selectionZoneRanges());
316 316 }
317 317 else
318 318 {
319 319 qCWarning(LOG_VisualizationZoneWidget())
320 320 << tr("VisualizationTabWidget::dropGraph, no graph added in the widget.");
321 321 Q_ASSERT(false);
322 322 }
323 323 }
324 324 else
325 325 {
326 326 // The graph is empty, create an empty zone and move the graph inside
327 327
328 328 auto parentZoneWidget = graphWidget->parentZoneWidget();
329 329
330 330 parentDragDropContainer->layout()->removeWidget(graphWidget);
331 331
332 332 auto zoneWidget = tabWidget->createEmptyZone(index);
333 333 zoneWidget->addGraph(graphWidget);
334 334
335 335 // Close the old zone if it was the only graph inside
336 336 if (nbGraph == 1)
337 337 {
338 338 helper.delayedCloseWidget(parentZoneWidget);
339 339 }
340 340 }
341 341 }
342 342
343 343 void VisualizationTabWidget::VisualizationTabWidgetPrivate::dropZone(
344 344 int index, VisualizationTabWidget* tabWidget)
345 345 {
346 346 auto& helper = sqpApp->dragDropGuiController();
347 347
348 348 auto zoneWidget = qobject_cast<VisualizationZoneWidget*>(helper.getCurrentDragWidget());
349 349 if (!zoneWidget)
350 350 {
351 351 qCWarning(LOG_VisualizationZoneWidget())
352 352 << tr("VisualizationTabWidget::dropZone, drop aborted, the dropped zone is not "
353 353 "found or invalid.");
354 354 Q_ASSERT(false);
355 355 return;
356 356 }
357 357
358 358 auto parentDragDropContainer
359 359 = qobject_cast<VisualizationDragDropContainer*>(zoneWidget->parentWidget());
360 360 if (!parentDragDropContainer)
361 361 {
362 362 qCWarning(LOG_VisualizationZoneWidget())
363 363 << tr("VisualizationTabWidget::dropZone, drop aborted, the parent container of "
364 364 "the dropped zone is not found.");
365 365 Q_ASSERT(false);
366 366 return;
367 367 }
368 368
369 369 // Simple move of the zone, no variable operation associated
370 370 parentDragDropContainer->layout()->removeWidget(zoneWidget);
371 371 tabWidget->ui->dragDropContainer->insertDragWidget(index, zoneWidget);
372 372 }
373 373
374 374 void VisualizationTabWidget::VisualizationTabWidgetPrivate::dropVariables(
375 375 const std::vector<std::shared_ptr<Variable2>>& variables, int index,
376 376 VisualizationTabWidget* tabWidget)
377 377 {
378 378 // Note: the AcceptMimeDataFunction (set on the drop container) ensure there is a single and
379 379 // compatible variable here
380 380 if (variables.size() > 1)
381 381 {
382 382 qCWarning(LOG_VisualizationZoneWidget())
383 383 << tr("VisualizationTabWidget::dropVariables, dropping multiple variables, operation "
384 384 "aborted.");
385 385 return;
386 386 }
387 387
388 388 tabWidget->createZone(variables, index);
389 389 }
390 390
391 391 void VisualizationTabWidget::VisualizationTabWidgetPrivate::dropProducts(
392 392 const QVariantList& productsMetaData, int index, VisualizationTabWidget* tabWidget)
393 393 {
394 394 // Note: the AcceptMimeDataFunction (set on the drop container) ensure there is a single and
395 395 // compatible variable here
396 396 if (productsMetaData.count() != 1)
397 397 {
398 398 qCWarning(LOG_VisualizationZoneWidget())
399 399 << tr("VisualizationTabWidget::dropProducts, dropping multiple products, operation "
400 400 "aborted.");
401 401 return;
402 402 }
403 403
404 404 auto context = new QObject { tabWidget };
405 405 connect(&sqpApp->variableController(), &VariableController2::variableAdded, context,
406 406 [this, index, tabWidget, context](auto variable) {
407 407 tabWidget->createZone({ variable }, index);
408 408 delete context; // removes the connection
409 409 },
410 410 Qt::QueuedConnection);
411 411
412 auto productData = productsMetaData.first().toHash();
413 QMetaObject::invokeMethod(&sqpApp->dataSourceController(), "requestVariable",
414 Qt::QueuedConnection, Q_ARG(QVariantHash, productData));
412 auto productPath = productsMetaData.first().toString();
413 QMetaObject::invokeMethod(&sqpApp->dataSources(), "createVariable",
414 Qt::QueuedConnection, Q_ARG(QString, productPath));
415 415 }
@@ -1,695 +1,695
1 1 #include "Visualization/VisualizationZoneWidget.h"
2 2
3 3 #include "Visualization/IVisualizationWidgetVisitor.h"
4 4 #include "Visualization/QCustomPlotSynchronizer.h"
5 5 #include "Visualization/VisualizationGraphWidget.h"
6 6 #include "Visualization/VisualizationWidget.h"
7 7 #include "ui_VisualizationZoneWidget.h"
8 8
9 #include "Common/MimeTypesDef.h"
9 #include "MimeTypes/MimeTypes.h"
10 10 #include "Common/VisualizationDef.h"
11 11
12 12 #include <Data/DateTimeRange.h>
13 13 #include <Data/DateTimeRangeHelper.h>
14 #include <DataSource/DataSourceController.h>
14 #include <DataSource/datasources.h>
15 15 #include <Time/TimeController.h>
16 16 #include <Variable/Variable2.h>
17 17 #include <Variable/VariableController2.h>
18 18
19 19 #include <Visualization/operations/FindVariableOperation.h>
20 20
21 21 #include <DragAndDrop/DragDropGuiController.h>
22 22 #include <QUuid>
23 23 #include <SqpApplication.h>
24 24 #include <cmath>
25 25
26 26 #include <QLayout>
27 27 #include <QStyle>
28 28
29 29 Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget")
30 30
31 31 namespace
32 32 {
33 33
34 34 /**
35 35 * Applies a function to all graphs of the zone represented by its layout
36 36 * @param layout the layout that contains graphs
37 37 * @param fun the function to apply to each graph
38 38 */
39 39 template <typename Fun>
40 40 void processGraphs(QLayout& layout, Fun fun)
41 41 {
42 42 for (auto i = 0; i < layout.count(); ++i)
43 43 {
44 44 if (auto item = layout.itemAt(i))
45 45 {
46 46 if (auto visualizationGraphWidget
47 47 = qobject_cast<VisualizationGraphWidget*>(item->widget()))
48 48 {
49 49 fun(*visualizationGraphWidget);
50 50 }
51 51 }
52 52 }
53 53 }
54 54
55 55 /// Generates a default name for a new graph, according to the number of graphs already displayed in
56 56 /// the zone
57 57 QString defaultGraphName(QLayout& layout)
58 58 {
59 59 QSet<QString> existingNames;
60 60 processGraphs(
61 61 layout, [&existingNames](auto& graphWidget) { existingNames.insert(graphWidget.name()); });
62 62
63 63 int zoneNum = 1;
64 64 QString name;
65 65 do
66 66 {
67 67 name = QObject::tr("Graph ").append(QString::number(zoneNum));
68 68 ++zoneNum;
69 69 } while (existingNames.contains(name));
70 70
71 71 return name;
72 72 }
73 73
74 74 } // namespace
75 75
76 76 struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate
77 77 {
78 78
79 79 explicit VisualizationZoneWidgetPrivate()
80 80 : m_SynchronisationGroupId { QUuid::createUuid() }
81 81 , m_Synchronizer { std::make_unique<QCustomPlotSynchronizer>() }
82 82 {
83 83 }
84 84 QUuid m_SynchronisationGroupId;
85 85 std::unique_ptr<IGraphSynchronizer> m_Synchronizer;
86 86
87 87 void dropGraph(int index, VisualizationZoneWidget* zoneWidget);
88 88 void dropVariables(const std::vector<std::shared_ptr<Variable2>>& variables, int index,
89 89 VisualizationZoneWidget* zoneWidget);
90 90 void dropProducts(
91 91 const QVariantList& productsData, int index, VisualizationZoneWidget* zoneWidget);
92 92 };
93 93
94 94 VisualizationZoneWidget::VisualizationZoneWidget(const QString& name, QWidget* parent)
95 95 : VisualizationDragWidget { parent }
96 96 , ui { new Ui::VisualizationZoneWidget }
97 97 , impl { spimpl::make_unique_impl<VisualizationZoneWidgetPrivate>() }
98 98 {
99 99 ui->setupUi(this);
100 100
101 101 ui->zoneNameLabel->setText(name);
102 102
103 103 ui->dragDropContainer->setPlaceHolderType(DragDropGuiController::PlaceHolderType::Graph);
104 104 ui->dragDropContainer->setMimeType(
105 MIME_TYPE_GRAPH, VisualizationDragDropContainer::DropBehavior::Inserted);
105 MIME::MIME_TYPE_GRAPH, VisualizationDragDropContainer::DropBehavior::Inserted);
106 106 ui->dragDropContainer->setMimeType(
107 MIME_TYPE_VARIABLE_LIST, VisualizationDragDropContainer::DropBehavior::InsertedAndMerged);
107 MIME::MIME_TYPE_VARIABLE_LIST, VisualizationDragDropContainer::DropBehavior::InsertedAndMerged);
108 108 ui->dragDropContainer->setMimeType(
109 MIME_TYPE_PRODUCT_LIST, VisualizationDragDropContainer::DropBehavior::InsertedAndMerged);
109 MIME::MIME_TYPE_PRODUCT_LIST, VisualizationDragDropContainer::DropBehavior::InsertedAndMerged);
110 110 ui->dragDropContainer->setMimeType(
111 MIME_TYPE_TIME_RANGE, VisualizationDragDropContainer::DropBehavior::Merged);
111 MIME::MIME_TYPE_TIME_RANGE, VisualizationDragDropContainer::DropBehavior::Merged);
112 112 ui->dragDropContainer->setMimeType(
113 MIME_TYPE_ZONE, VisualizationDragDropContainer::DropBehavior::Forbidden);
113 MIME::MIME_TYPE_ZONE, VisualizationDragDropContainer::DropBehavior::Forbidden);
114 114 ui->dragDropContainer->setMimeType(
115 MIME_TYPE_SELECTION_ZONE, VisualizationDragDropContainer::DropBehavior::Forbidden);
115 MIME::MIME_TYPE_SELECTION_ZONE, VisualizationDragDropContainer::DropBehavior::Forbidden);
116 116 ui->dragDropContainer->setAcceptMimeDataFunction([this](auto mimeData) {
117 117 return sqpApp->dragDropGuiController().checkMimeDataForVisualization(
118 118 mimeData, ui->dragDropContainer);
119 119 });
120 120
121 121 auto acceptDragWidgetFun = [](auto dragWidget, auto mimeData) {
122 122 if (!mimeData)
123 123 {
124 124 return false;
125 125 }
126 126
127 if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST))
127 if (mimeData->hasFormat(MIME::MIME_TYPE_VARIABLE_LIST))
128 128 {
129 129 auto variables = sqpApp->variableController().variables(
130 Variable2::IDs(mimeData->data(MIME_TYPE_VARIABLE_LIST)));
130 Variable2::IDs(mimeData->data(MIME::MIME_TYPE_VARIABLE_LIST)));
131 131
132 132 if (variables.size() != 1)
133 133 {
134 134 return false;
135 135 }
136 136 auto variable = variables.front();
137 137
138 138 if (auto graphWidget = dynamic_cast<const VisualizationGraphWidget*>(dragWidget))
139 139 {
140 140 return graphWidget->canDrop(*variable);
141 141 }
142 142 }
143 143
144 144 return true;
145 145 };
146 146 ui->dragDropContainer->setAcceptDragWidgetFunction(acceptDragWidgetFun);
147 147
148 148 connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccuredInContainer, this,
149 149 &VisualizationZoneWidget::dropMimeData);
150 150 connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccuredOnWidget, this,
151 151 &VisualizationZoneWidget::dropMimeDataOnGraph);
152 152
153 153 // 'Close' options : widget is deleted when closed
154 154 setAttribute(Qt::WA_DeleteOnClose);
155 155 connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close);
156 156 ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
157 157
158 158 // Synchronisation id
159 159 // QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronizationGroupId",
160 160 // Qt::QueuedConnection, Q_ARG(QUuid, impl->m_SynchronisationGroupId));
161 161 }
162 162
163 163 VisualizationZoneWidget::~VisualizationZoneWidget()
164 164 {
165 165 delete ui;
166 166 }
167 167
168 168 void VisualizationZoneWidget::setZoneRange(const DateTimeRange& range)
169 169 {
170 170 if (auto graph = firstGraph())
171 171 {
172 172 graph->setGraphRange(range);
173 173 }
174 174 else
175 175 {
176 176 qCWarning(LOG_VisualizationZoneWidget())
177 177 << tr("setZoneRange:Cannot set the range of an empty zone.");
178 178 }
179 179 }
180 180
181 181 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget* graphWidget)
182 182 {
183 183 // Synchronize new graph with others in the zone
184 184 // impl->m_Synchronizer->addGraph(*graphWidget);
185 185
186 186 // ui->dragDropContainer->addDragWidget(graphWidget);
187 187 insertGraph(0, graphWidget);
188 188 }
189 189
190 190 void VisualizationZoneWidget::insertGraph(int index, VisualizationGraphWidget* graphWidget)
191 191 {
192 192 DEPRECATE(
193 193 auto layout = ui->dragDropContainer->layout(); for (int i = 0; i < layout->count(); i++) {
194 194 auto graph = qobject_cast<VisualizationGraphWidget*>(layout->itemAt(i)->widget());
195 195 connect(graphWidget, &VisualizationGraphWidget::setrange_sig, graph,
196 196 &VisualizationGraphWidget::setGraphRange);
197 197 connect(graph, &VisualizationGraphWidget::setrange_sig, graphWidget,
198 198 &VisualizationGraphWidget::setGraphRange);
199 199 } if (auto graph = firstGraph()) { graphWidget->setGraphRange(graph->graphRange(), true); })
200 200
201 201 // Synchronize new graph with others in the zone
202 202 impl->m_Synchronizer->addGraph(*graphWidget);
203 203
204 204 ui->dragDropContainer->insertDragWidget(index, graphWidget);
205 205 }
206 206
207 207 VisualizationGraphWidget* VisualizationZoneWidget::createGraph(std::shared_ptr<Variable2> variable)
208 208 {
209 209 return createGraph(variable, -1);
210 210 }
211 211
212 212 VisualizationGraphWidget* VisualizationZoneWidget::createGraph(
213 213 std::shared_ptr<Variable2> variable, int index)
214 214 {
215 215 auto graphWidget
216 216 = new VisualizationGraphWidget { defaultGraphName(*ui->dragDropContainer->layout()), this };
217 217
218 218
219 219 // Set graph properties
220 220 graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
221 221 graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT);
222 222
223 223
224 224 // Lambda to synchronize zone widget
225 225 // auto synchronizeZoneWidget = [this, graphWidget](const DateTimeRange &graphRange,
226 226 // const DateTimeRange &oldGraphRange) {
227 227
228 228 // auto zoomType = DateTimeRangeHelper::getTransformationType(oldGraphRange, graphRange);
229 229 // auto frameLayout = ui->dragDropContainer->layout();
230 230 // for (auto i = 0; i < frameLayout->count(); ++i) {
231 231 // auto graphChild
232 232 // = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget());
233 233 // if (graphChild && (graphChild != graphWidget)) {
234 234
235 235 // auto graphChildRange = graphChild->graphRange();
236 236 // switch (zoomType) {
237 237 // case TransformationType::ZoomIn: {
238 238 // auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
239 239 // auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
240 240 // graphChildRange.m_TStart += deltaLeft;
241 241 // graphChildRange.m_TEnd -= deltaRight;
242 242 // break;
243 243 // }
244 244
245 245 // case TransformationType::ZoomOut: {
246 246 // auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
247 247 // auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
248 248 // graphChildRange.m_TStart -= deltaLeft;
249 249 // graphChildRange.m_TEnd += deltaRight;
250 250 // break;
251 251 // }
252 252 // case TransformationType::PanRight: {
253 253 // auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
254 254 // auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
255 255 // graphChildRange.m_TStart += deltaLeft;
256 256 // graphChildRange.m_TEnd += deltaRight;
257 257 // break;
258 258 // }
259 259 // case TransformationType::PanLeft: {
260 260 // auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
261 261 // auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
262 262 // graphChildRange.m_TStart -= deltaLeft;
263 263 // graphChildRange.m_TEnd -= deltaRight;
264 264 // break;
265 265 // }
266 266 // case TransformationType::Unknown: {
267 267 // break;
268 268 // }
269 269 // default:
270 270 // qCCritical(LOG_VisualizationZoneWidget())
271 271 // << tr("Impossible to synchronize: zoom type not take into
272 272 // account");
273 273 // // No action
274 274 // break;
275 275 // }
276 276 // graphChild->setFlags(GraphFlag::DisableAll);
277 277 // graphChild->setGraphRange(graphChildRange, true);
278 278 // graphChild->setFlags(GraphFlag::EnableAll);
279 279 // }
280 280 // }
281 281 // };
282 282
283 283 // connection for synchronization
284 284 // connect(graphWidget, &VisualizationGraphWidget::synchronize, synchronizeZoneWidget);
285 285 connect(graphWidget, &VisualizationGraphWidget::variableAdded, this,
286 286 &VisualizationZoneWidget::onVariableAdded);
287 287 connect(graphWidget, &VisualizationGraphWidget::variableAboutToBeRemoved, this,
288 288 &VisualizationZoneWidget::onVariableAboutToBeRemoved);
289 289
290 290 auto range = DateTimeRange {};
291 291 if (auto firstGraph = this->firstGraph())
292 292 {
293 293 // Case of a new graph in a existant zone
294 294 range = firstGraph->graphRange();
295 295 }
296 296 else
297 297 {
298 298 // Case of a new graph as the first of the zone
299 299 range = variable->range();
300 300 }
301 301
302 302 this->insertGraph(index, graphWidget);
303 303
304 304 graphWidget->addVariable(variable, range);
305 305 graphWidget->setYRange(variable);
306 306
307 307 return graphWidget;
308 308 }
309 309
310 310 VisualizationGraphWidget* VisualizationZoneWidget::createGraph(
311 311 const std::vector<std::shared_ptr<Variable2>> variables, int index)
312 312 {
313 313 if (variables.empty())
314 314 {
315 315 return nullptr;
316 316 }
317 317
318 318 auto graphWidget = createGraph(variables.front(), index);
319 319 for (auto variableIt = variables.cbegin() + 1; variableIt != variables.cend(); ++variableIt)
320 320 {
321 321 graphWidget->addVariable(*variableIt, graphWidget->graphRange());
322 322 }
323 323
324 324 return graphWidget;
325 325 }
326 326
327 327 VisualizationGraphWidget* VisualizationZoneWidget::firstGraph() const
328 328 {
329 329 VisualizationGraphWidget* firstGraph = nullptr;
330 330 auto layout = ui->dragDropContainer->layout();
331 331 if (layout->count() > 0)
332 332 {
333 333 if (auto visualizationGraphWidget
334 334 = qobject_cast<VisualizationGraphWidget*>(layout->itemAt(0)->widget()))
335 335 {
336 336 firstGraph = visualizationGraphWidget;
337 337 }
338 338 }
339 339
340 340 return firstGraph;
341 341 }
342 342
343 343 void VisualizationZoneWidget::closeAllGraphs()
344 344 {
345 345 processGraphs(*ui->dragDropContainer->layout(),
346 346 [](VisualizationGraphWidget& graphWidget) { graphWidget.close(); });
347 347 }
348 348
349 349 void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor* visitor)
350 350 {
351 351 if (visitor)
352 352 {
353 353 visitor->visitEnter(this);
354 354
355 355 // Apply visitor to graph children: widgets different from graphs are not visited (no
356 356 // action)
357 357 processGraphs(*ui->dragDropContainer->layout(),
358 358 [visitor](VisualizationGraphWidget& graphWidget) { graphWidget.accept(visitor); });
359 359
360 360 visitor->visitLeave(this);
361 361 }
362 362 else
363 363 {
364 364 qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null");
365 365 }
366 366 }
367 367
368 368 bool VisualizationZoneWidget::canDrop(Variable2& variable) const
369 369 {
370 370 // A tab can always accomodate a variable
371 371 Q_UNUSED(variable);
372 372 return true;
373 373 }
374 374
375 375 bool VisualizationZoneWidget::contains(Variable2& variable) const
376 376 {
377 377 Q_UNUSED(variable);
378 378 return false;
379 379 }
380 380
381 381 QString VisualizationZoneWidget::name() const
382 382 {
383 383 return ui->zoneNameLabel->text();
384 384 }
385 385
386 386 QMimeData* VisualizationZoneWidget::mimeData(const QPoint& position) const
387 387 {
388 388 Q_UNUSED(position);
389 389
390 390 auto mimeData = new QMimeData;
391 mimeData->setData(MIME_TYPE_ZONE, QByteArray {});
391 mimeData->setData(MIME::MIME_TYPE_ZONE, QByteArray {});
392 392
393 393 if (auto firstGraph = this->firstGraph())
394 394 {
395 395 auto timeRangeData = TimeController::mimeDataForTimeRange(firstGraph->graphRange());
396 mimeData->setData(MIME_TYPE_TIME_RANGE, timeRangeData);
396 mimeData->setData(MIME::MIME_TYPE_TIME_RANGE, timeRangeData);
397 397 }
398 398
399 399 return mimeData;
400 400 }
401 401
402 402 bool VisualizationZoneWidget::isDragAllowed() const
403 403 {
404 404 return true;
405 405 }
406 406
407 407 void VisualizationZoneWidget::notifyMouseMoveInGraph(const QPointF& graphPosition,
408 408 const QPointF& plotPosition, VisualizationGraphWidget* graphWidget)
409 409 {
410 410 processGraphs(*ui->dragDropContainer->layout(),
411 411 [&graphPosition, &plotPosition, &graphWidget](VisualizationGraphWidget& processedGraph) {
412 412 switch (sqpApp->plotsCursorMode())
413 413 {
414 414 case SqpApplication::PlotsCursorMode::Vertical:
415 415 processedGraph.removeHorizontalCursor();
416 416 processedGraph.addVerticalCursorAtViewportPosition(graphPosition.x());
417 417 break;
418 418 case SqpApplication::PlotsCursorMode::Temporal:
419 419 processedGraph.addVerticalCursor(plotPosition.x());
420 420 processedGraph.removeHorizontalCursor();
421 421 break;
422 422 case SqpApplication::PlotsCursorMode::Horizontal:
423 423 processedGraph.removeVerticalCursor();
424 424 if (&processedGraph == graphWidget)
425 425 {
426 426 processedGraph.addHorizontalCursorAtViewportPosition(graphPosition.y());
427 427 }
428 428 else
429 429 {
430 430 processedGraph.removeHorizontalCursor();
431 431 }
432 432 break;
433 433 case SqpApplication::PlotsCursorMode::Cross:
434 434 if (&processedGraph == graphWidget)
435 435 {
436 436 processedGraph.addVerticalCursorAtViewportPosition(graphPosition.x());
437 437 processedGraph.addHorizontalCursorAtViewportPosition(graphPosition.y());
438 438 }
439 439 else
440 440 {
441 441 processedGraph.removeHorizontalCursor();
442 442 processedGraph.removeVerticalCursor();
443 443 }
444 444 break;
445 445 case SqpApplication::PlotsCursorMode::NoCursor:
446 446 processedGraph.removeHorizontalCursor();
447 447 processedGraph.removeVerticalCursor();
448 448 break;
449 449 }
450 450 });
451 451 }
452 452
453 453 void VisualizationZoneWidget::notifyMouseLeaveGraph(VisualizationGraphWidget* graphWidget)
454 454 {
455 455 processGraphs(*ui->dragDropContainer->layout(), [](VisualizationGraphWidget& processedGraph) {
456 456 processedGraph.removeHorizontalCursor();
457 457 processedGraph.removeVerticalCursor();
458 458 });
459 459 }
460 460
461 461 void VisualizationZoneWidget::closeEvent(QCloseEvent* event)
462 462 {
463 463 // Closes graphs in the zone
464 464 processGraphs(*ui->dragDropContainer->layout(),
465 465 [](VisualizationGraphWidget& graphWidget) { graphWidget.close(); });
466 466
467 467 // Delete synchronization group from variable controller
468 468 QMetaObject::invokeMethod(&sqpApp->variableController(), "onRemoveSynchronizationGroupId",
469 469 Qt::QueuedConnection, Q_ARG(QUuid, impl->m_SynchronisationGroupId));
470 470
471 471 QWidget::closeEvent(event);
472 472 }
473 473
474 474 void VisualizationZoneWidget::onVariableAdded(std::shared_ptr<Variable2> variable)
475 475 {
476 476 QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronized",
477 477 Qt::QueuedConnection, Q_ARG(std::shared_ptr<Variable2>, variable),
478 478 Q_ARG(QUuid, impl->m_SynchronisationGroupId));
479 479 }
480 480
481 481 void VisualizationZoneWidget::onVariableAboutToBeRemoved(std::shared_ptr<Variable2> variable)
482 482 {
483 483 QMetaObject::invokeMethod(&sqpApp->variableController(), "desynchronize", Qt::QueuedConnection,
484 484 Q_ARG(std::shared_ptr<Variable2>, variable), Q_ARG(QUuid, impl->m_SynchronisationGroupId));
485 485 }
486 486
487 487 void VisualizationZoneWidget::dropMimeData(int index, const QMimeData* mimeData)
488 488 {
489 if (mimeData->hasFormat(MIME_TYPE_GRAPH))
489 if (mimeData->hasFormat(MIME::MIME_TYPE_GRAPH))
490 490 {
491 491 impl->dropGraph(index, this);
492 492 }
493 else if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST))
493 else if (mimeData->hasFormat(MIME::MIME_TYPE_VARIABLE_LIST))
494 494 {
495 495 auto variables = sqpApp->variableController().variables(
496 Variable2::IDs(mimeData->data(MIME_TYPE_VARIABLE_LIST)));
496 Variable2::IDs(mimeData->data(MIME::MIME_TYPE_VARIABLE_LIST)));
497 497 impl->dropVariables(variables, index, this);
498 498 }
499 else if (mimeData->hasFormat(MIME_TYPE_PRODUCT_LIST))
499 else if (mimeData->hasFormat(MIME::MIME_TYPE_PRODUCT_LIST))
500 500 {
501 auto products = sqpApp->dataSourceController().productsDataForMimeData(
502 mimeData->data(MIME_TYPE_PRODUCT_LIST));
501 auto products = MIME::decode(
502 mimeData->data(MIME::MIME_TYPE_PRODUCT_LIST));
503 503 impl->dropProducts(products, index, this);
504 504 }
505 505 else
506 506 {
507 507 qCWarning(LOG_VisualizationZoneWidget())
508 508 << tr("VisualizationZoneWidget::dropMimeData, unknown MIME data received.");
509 509 }
510 510 }
511 511
512 512 void VisualizationZoneWidget::dropMimeDataOnGraph(
513 513 VisualizationDragWidget* dragWidget, const QMimeData* mimeData)
514 514 {
515 515 auto graphWidget = qobject_cast<VisualizationGraphWidget*>(dragWidget);
516 516 if (!graphWidget)
517 517 {
518 518 qCWarning(LOG_VisualizationZoneWidget())
519 519 << tr("VisualizationZoneWidget::dropMimeDataOnGraph, dropping in an unknown widget, "
520 520 "drop aborted");
521 521 Q_ASSERT(false);
522 522 return;
523 523 }
524 524
525 if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST))
525 if (mimeData->hasFormat(MIME::MIME_TYPE_VARIABLE_LIST))
526 526 {
527 527 auto variables = sqpApp->variableController().variables(
528 Variable2::IDs(mimeData->data(MIME_TYPE_VARIABLE_LIST)));
528 Variable2::IDs(mimeData->data(MIME::MIME_TYPE_VARIABLE_LIST)));
529 529 for (const auto& var : variables)
530 530 {
531 531 graphWidget->addVariable(var, graphWidget->graphRange());
532 532 }
533 533 }
534 else if (mimeData->hasFormat(MIME_TYPE_PRODUCT_LIST))
534 else if (mimeData->hasFormat(MIME::MIME_TYPE_PRODUCT_LIST))
535 535 {
536 auto products = sqpApp->dataSourceController().productsDataForMimeData(
537 mimeData->data(MIME_TYPE_PRODUCT_LIST));
536 auto products = MIME::decode(
537 mimeData->data(MIME::MIME_TYPE_PRODUCT_LIST));
538 538
539 539 auto context = new QObject { this };
540 auto range = TimeController::timeRangeForMimeData(mimeData->data(MIME_TYPE_TIME_RANGE));
540 auto range = TimeController::timeRangeForMimeData(mimeData->data(MIME::MIME_TYPE_TIME_RANGE));
541 541 // BTW this is really dangerous, this assumes the next created variable will be this one...
542 542 connect(&sqpApp->variableController(), &VariableController2::variableAdded, context,
543 543 [this, graphWidget, context, range](auto variable) {
544 544 if (sqpApp->variableController().isReady(variable))
545 545 {
546 546 graphWidget->addVariable(variable, range);
547 547 delete context;
548 548 }
549 549 else
550 550 {
551 551 // -> this is pure insanity! this is a workaround to make a bad design work
552 552 QObject::connect(variable.get(), &Variable2::updated, context,
553 553 [graphWidget, context, range, variable]() {
554 554 graphWidget->addVariable(variable, range);
555 555 delete context;
556 556 });
557 557 }
558 558 },
559 559 Qt::QueuedConnection);
560 560
561 auto productData = products.first().toHash();
562 QMetaObject::invokeMethod(&sqpApp->dataSourceController(), "requestVariable",
563 Qt::QueuedConnection, Q_ARG(QVariantHash, productData));
561 auto productPath = products.first().toString();
562 QMetaObject::invokeMethod(&sqpApp->dataSources(), "createVariable",
563 Qt::QueuedConnection, Q_ARG(QString, productPath));
564 564 }
565 else if (mimeData->hasFormat(MIME_TYPE_TIME_RANGE))
565 else if (mimeData->hasFormat(MIME::MIME_TYPE_TIME_RANGE))
566 566 {
567 auto range = TimeController::timeRangeForMimeData(mimeData->data(MIME_TYPE_TIME_RANGE));
567 auto range = TimeController::timeRangeForMimeData(mimeData->data(MIME::MIME_TYPE_TIME_RANGE));
568 568 graphWidget->setGraphRange(range, true, true);
569 569 }
570 570 else
571 571 {
572 572 qCWarning(LOG_VisualizationZoneWidget())
573 573 << tr("VisualizationZoneWidget::dropMimeDataOnGraph, unknown MIME data received.");
574 574 }
575 575 }
576 576
577 577 void VisualizationZoneWidget::VisualizationZoneWidgetPrivate::dropGraph(
578 578 int index, VisualizationZoneWidget* zoneWidget)
579 579 {
580 580 auto& helper = sqpApp->dragDropGuiController();
581 581
582 582 auto graphWidget = qobject_cast<VisualizationGraphWidget*>(helper.getCurrentDragWidget());
583 583 if (!graphWidget)
584 584 {
585 585 qCWarning(LOG_VisualizationZoneWidget())
586 586 << tr("VisualizationZoneWidget::dropGraph, drop aborted, the dropped graph is not "
587 587 "found or invalid.");
588 588 Q_ASSERT(false);
589 589 return;
590 590 }
591 591
592 592 auto parentDragDropContainer
593 593 = qobject_cast<VisualizationDragDropContainer*>(graphWidget->parentWidget());
594 594 if (!parentDragDropContainer)
595 595 {
596 596 qCWarning(LOG_VisualizationZoneWidget())
597 597 << tr("VisualizationZoneWidget::dropGraph, drop aborted, the parent container of "
598 598 "the dropped graph is not found.");
599 599 Q_ASSERT(false);
600 600 return;
601 601 }
602 602
603 603 const auto& variables = graphWidget->variables();
604 604
605 605 if (parentDragDropContainer != zoneWidget->ui->dragDropContainer && !variables.empty())
606 606 {
607 607 // The drop didn't occur in the same zone
608 608
609 609 // Abort the requests for the variables (if any)
610 610 // Commented, because it's not sure if it's needed or not
611 611 // for (const auto& var : variables)
612 612 //{
613 613 // sqpApp->variableController().onAbortProgressRequested(var);
614 614 //}
615 615
616 616 auto previousParentZoneWidget = graphWidget->parentZoneWidget();
617 617 auto nbGraph = parentDragDropContainer->countDragWidget();
618 618 if (nbGraph == 1)
619 619 {
620 620 // This is the only graph in the previous zone, close the zone
621 621 helper.delayedCloseWidget(previousParentZoneWidget);
622 622 }
623 623 else
624 624 {
625 625 // Close the graph
626 626 helper.delayedCloseWidget(graphWidget);
627 627 }
628 628
629 629 // Creates the new graph in the zone
630 630 auto newGraphWidget = zoneWidget->createGraph(variables, index);
631 631 newGraphWidget->addSelectionZones(graphWidget->selectionZoneRanges());
632 632 }
633 633 else
634 634 {
635 635 // The drop occurred in the same zone or the graph is empty
636 636 // Simple move of the graph, no variable operation associated
637 637 parentDragDropContainer->layout()->removeWidget(graphWidget);
638 638
639 639 if (variables.empty() && parentDragDropContainer != zoneWidget->ui->dragDropContainer)
640 640 {
641 641 // The graph is empty and dropped in a different zone.
642 642 // Take the range of the first graph in the zone (if existing).
643 643 auto layout = zoneWidget->ui->dragDropContainer->layout();
644 644 if (layout->count() > 0)
645 645 {
646 646 if (auto visualizationGraphWidget
647 647 = qobject_cast<VisualizationGraphWidget*>(layout->itemAt(0)->widget()))
648 648 {
649 649 graphWidget->setGraphRange(visualizationGraphWidget->graphRange());
650 650 }
651 651 }
652 652 }
653 653
654 654 zoneWidget->ui->dragDropContainer->insertDragWidget(index, graphWidget);
655 655 }
656 656 }
657 657
658 658 void VisualizationZoneWidget::VisualizationZoneWidgetPrivate::dropVariables(
659 659 const std::vector<std::shared_ptr<Variable2>>& variables, int index,
660 660 VisualizationZoneWidget* zoneWidget)
661 661 {
662 662 // Note: the AcceptMimeDataFunction (set on the drop container) ensure there is a single and
663 663 // compatible variable here
664 664 if (variables.size() > 1)
665 665 {
666 666 return;
667 667 }
668 668 zoneWidget->createGraph(variables, index);
669 669 }
670 670
671 671 void VisualizationZoneWidget::VisualizationZoneWidgetPrivate::dropProducts(
672 672 const QVariantList& productsData, int index, VisualizationZoneWidget* zoneWidget)
673 673 {
674 674 // Note: the AcceptMimeDataFunction (set on the drop container) ensure there is a single and
675 675 // compatible variable here
676 676 if (productsData.count() != 1)
677 677 {
678 678 qCWarning(LOG_VisualizationZoneWidget())
679 679 << tr("VisualizationTabWidget::dropProducts, dropping multiple products, operation "
680 680 "aborted.");
681 681 return;
682 682 }
683 683
684 684 auto context = new QObject { zoneWidget };
685 685 connect(&sqpApp->variableController(), &VariableController2::variableAdded, context,
686 686 [this, index, zoneWidget, context](auto variable) {
687 687 zoneWidget->createGraph(variable, index);
688 688 delete context; // removes the connection
689 689 },
690 690 Qt::QueuedConnection);
691 691
692 auto productData = productsData.first().toHash();
693 QMetaObject::invokeMethod(&sqpApp->dataSourceController(), "requestVariable",
694 Qt::QueuedConnection, Q_ARG(QVariantHash, productData));
692 auto productPath = productsData.first().toString();
693 QMetaObject::invokeMethod(&sqpApp->dataSources(), "createVariable",
694 Qt::QueuedConnection, Q_ARG(QString, productPath));
695 695 }
@@ -1,49 +1,37
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <ui version="4.0">
3 3 <class>DataSourceWidget</class>
4 4 <widget class="QWidget" name="DataSourceWidget">
5 5 <property name="geometry">
6 6 <rect>
7 7 <x>0</x>
8 8 <y>0</y>
9 9 <width>400</width>
10 10 <height>300</height>
11 11 </rect>
12 12 </property>
13 13 <property name="windowTitle">
14 14 <string>Data sources</string>
15 15 </property>
16 16 <layout class="QGridLayout" name="gridLayout">
17 17 <item row="0" column="0">
18 18 <widget class="QLineEdit" name="filterLineEdit"/>
19 19 </item>
20 20 <item row="1" column="0">
21 <widget class="DataSourceTreeWidget" name="treeWidget">
21 <widget class="QTreeView" name="treeView">
22 22 <property name="dragEnabled">
23 23 <bool>true</bool>
24 24 </property>
25 25 <property name="dragDropMode">
26 26 <enum>QAbstractItemView::DragOnly</enum>
27 27 </property>
28 28 <property name="selectionMode">
29 29 <enum>QAbstractItemView::ExtendedSelection</enum>
30 30 </property>
31 <column>
32 <property name="text">
33 <string notr="true">1</string>
34 </property>
35 </column>
36 31 </widget>
37 32 </item>
38 33 </layout>
39 34 </widget>
40 <customwidgets>
41 <customwidget>
42 <class>DataSourceTreeWidget</class>
43 <extends>QTreeWidget</extends>
44 <header>DataSource/DataSourceTreeWidget.h</header>
45 </customwidget>
46 </customwidgets>
47 35 <resources/>
48 36 <connections/>
49 37 </ui>
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now