@@ -0,0 +1,17 | |||||
|
1 | #ifndef SCIQLOP_CATALOGUEACTIONMANAGER_H | |||
|
2 | #define SCIQLOP_CATALOGUEACTIONMANAGER_H | |||
|
3 | ||||
|
4 | #include <Common/spimpl.h> | |||
|
5 | ||||
|
6 | class CatalogueActionManager { | |||
|
7 | public: | |||
|
8 | CatalogueActionManager(); | |||
|
9 | ||||
|
10 | void installSelectionZoneActions(); | |||
|
11 | ||||
|
12 | private: | |||
|
13 | class CatalogueActionManagerPrivate; | |||
|
14 | spimpl::unique_impl_ptr<CatalogueActionManagerPrivate> impl; | |||
|
15 | }; | |||
|
16 | ||||
|
17 | #endif // SCIQLOP_CATALOGUEACTIONMANAGER_H |
@@ -0,0 +1,13 | |||||
|
1 | #ifndef SCIQLOP_CATALOGUEEXPLORERHELPER_H | |||
|
2 | #define SCIQLOP_CATALOGUEEXPLORERHELPER_H | |||
|
3 | ||||
|
4 | #include <QWidget> | |||
|
5 | ||||
|
6 | #include <functional> | |||
|
7 | ||||
|
8 | struct CatalogueExplorerHelper { | |||
|
9 | static QWidget *buildValidationWidget(QWidget *parent, std::function<void()> save, | |||
|
10 | std::function<void()> discard); | |||
|
11 | }; | |||
|
12 | ||||
|
13 | #endif // SCIQLOP_CATALOGUEEXPLORERHELPER_H |
@@ -0,0 +1,35 | |||||
|
1 | #ifndef SCIQLOP_CREATEEVENTDIALOG_H | |||
|
2 | #define SCIQLOP_CREATEEVENTDIALOG_H | |||
|
3 | ||||
|
4 | #include <Common/spimpl.h> | |||
|
5 | #include <QDialog> | |||
|
6 | #include <memory> | |||
|
7 | ||||
|
8 | namespace Ui { | |||
|
9 | class CreateEventDialog; | |||
|
10 | } | |||
|
11 | ||||
|
12 | class DBCatalogue; | |||
|
13 | ||||
|
14 | class CreateEventDialog : public QDialog { | |||
|
15 | Q_OBJECT | |||
|
16 | ||||
|
17 | public: | |||
|
18 | explicit CreateEventDialog(QWidget *parent = 0); | |||
|
19 | virtual ~CreateEventDialog(); | |||
|
20 | ||||
|
21 | void hideCatalogueChoice(); | |||
|
22 | ||||
|
23 | QString eventName() const; | |||
|
24 | ||||
|
25 | std::shared_ptr<DBCatalogue> selectedCatalogue() const; | |||
|
26 | QString catalogueName() const; | |||
|
27 | ||||
|
28 | private: | |||
|
29 | Ui::CreateEventDialog *ui; | |||
|
30 | ||||
|
31 | class CreateEventDialogPrivate; | |||
|
32 | spimpl::unique_impl_ptr<CreateEventDialogPrivate> impl; | |||
|
33 | }; | |||
|
34 | ||||
|
35 | #endif // SCIQLOP_CREATEEVENTDIALOG_H |
@@ -0,0 +1,107 | |||||
|
1 | #include "Catalogue/CatalogueActionManager.h" | |||
|
2 | ||||
|
3 | #include <Actions/ActionsGuiController.h> | |||
|
4 | #include <Catalogue/CatalogueController.h> | |||
|
5 | #include <SqpApplication.h> | |||
|
6 | #include <Variable/Variable.h> | |||
|
7 | #include <Visualization/VisualizationGraphWidget.h> | |||
|
8 | #include <Visualization/VisualizationSelectionZoneItem.h> | |||
|
9 | ||||
|
10 | #include <Catalogue/CreateEventDialog.h> | |||
|
11 | ||||
|
12 | #include <DBCatalogue.h> | |||
|
13 | #include <DBEvent.h> | |||
|
14 | #include <DBEventProduct.h> | |||
|
15 | ||||
|
16 | #include <QBoxLayout> | |||
|
17 | #include <QComboBox> | |||
|
18 | #include <QDialog> | |||
|
19 | #include <QDialogButtonBox> | |||
|
20 | #include <QLineEdit> | |||
|
21 | #include <memory> | |||
|
22 | ||||
|
23 | struct CatalogueActionManager::CatalogueActionManagerPrivate { | |||
|
24 | void createEventFromZones(const QString &eventName, | |||
|
25 | const QVector<VisualizationSelectionZoneItem *> &zones, | |||
|
26 | const std::shared_ptr<DBCatalogue> &catalogue = nullptr) | |||
|
27 | { | |||
|
28 | auto event = std::make_shared<DBEvent>(); | |||
|
29 | event->setName(eventName); | |||
|
30 | ||||
|
31 | std::list<DBEventProduct> productList; | |||
|
32 | for (auto zone : zones) { | |||
|
33 | auto graph = zone->parentGraphWidget(); | |||
|
34 | for (auto var : graph->variables()) { | |||
|
35 | auto eventProduct = std::make_shared<DBEventProduct>(); | |||
|
36 | eventProduct->setEvent(*event); | |||
|
37 | ||||
|
38 | auto zoneRange = zone->range(); | |||
|
39 | eventProduct->setTStart(zoneRange.m_TStart); | |||
|
40 | eventProduct->setTEnd(zoneRange.m_TEnd); | |||
|
41 | ||||
|
42 | eventProduct->setProductId(var->metadata().value("id", "TODO").toString()); // todo | |||
|
43 | ||||
|
44 | productList.push_back(*eventProduct); | |||
|
45 | } | |||
|
46 | } | |||
|
47 | ||||
|
48 | event->setEventProducts(productList); | |||
|
49 | ||||
|
50 | sqpApp->catalogueController().addEvent(event); | |||
|
51 | ||||
|
52 | if (catalogue) { | |||
|
53 | // TODO | |||
|
54 | // catalogue->addEvent(event); | |||
|
55 | } | |||
|
56 | } | |||
|
57 | }; | |||
|
58 | ||||
|
59 | CatalogueActionManager::CatalogueActionManager() | |||
|
60 | : impl{spimpl::make_unique_impl<CatalogueActionManagerPrivate>()} | |||
|
61 | { | |||
|
62 | } | |||
|
63 | ||||
|
64 | void CatalogueActionManager::installSelectionZoneActions() | |||
|
65 | { | |||
|
66 | auto &actionController = sqpApp->actionsGuiController(); | |||
|
67 | ||||
|
68 | auto createEventEnableFuntion = [](auto zones) { | |||
|
69 | QSet<VisualizationGraphWidget *> usedGraphs; | |||
|
70 | for (auto zone : zones) { | |||
|
71 | auto graph = zone->parentGraphWidget(); | |||
|
72 | if (!usedGraphs.contains(graph)) { | |||
|
73 | usedGraphs.insert(graph); | |||
|
74 | } | |||
|
75 | else { | |||
|
76 | return false; | |||
|
77 | } | |||
|
78 | } | |||
|
79 | ||||
|
80 | return true; | |||
|
81 | }; | |||
|
82 | ||||
|
83 | auto createEventAction = actionController.addSectionZoneAction( | |||
|
84 | {QObject::tr("Catalogues")}, QObject::tr("New Event..."), [this](auto zones) { | |||
|
85 | CreateEventDialog dialog; | |||
|
86 | dialog.hideCatalogueChoice(); | |||
|
87 | if (dialog.exec() == QDialog::Accepted) { | |||
|
88 | impl->createEventFromZones(dialog.eventName(), zones); | |||
|
89 | } | |||
|
90 | }); | |||
|
91 | createEventAction->setEnableFunction(createEventEnableFuntion); | |||
|
92 | ||||
|
93 | auto createEventInCatalogueAction = actionController.addSectionZoneAction( | |||
|
94 | {QObject::tr("Catalogues")}, QObject::tr("New Event in Catalogue..."), [this](auto zones) { | |||
|
95 | CreateEventDialog dialog; | |||
|
96 | if (dialog.exec() == QDialog::Accepted) { | |||
|
97 | auto selectedCatalogue = dialog.selectedCatalogue(); | |||
|
98 | if (!selectedCatalogue) { | |||
|
99 | selectedCatalogue = std::make_shared<DBCatalogue>(); | |||
|
100 | selectedCatalogue->setName(dialog.catalogueName()); | |||
|
101 | } | |||
|
102 | ||||
|
103 | impl->createEventFromZones(dialog.eventName(), zones, selectedCatalogue); | |||
|
104 | } | |||
|
105 | }); | |||
|
106 | createEventInCatalogueAction->setEnableFunction(createEventEnableFuntion); | |||
|
107 | } |
@@ -0,0 +1,32 | |||||
|
1 | #include "Catalogue/CatalogueExplorerHelper.h" | |||
|
2 | ||||
|
3 | #include <QBoxLayout> | |||
|
4 | #include <QToolButton> | |||
|
5 | ||||
|
6 | const auto VALIDATION_BUTTON_ICON_SIZE = 12; | |||
|
7 | ||||
|
8 | QWidget *CatalogueExplorerHelper::buildValidationWidget(QWidget *parent, std::function<void()> save, | |||
|
9 | std::function<void()> discard) | |||
|
10 | { | |||
|
11 | auto widget = new QWidget{parent}; | |||
|
12 | ||||
|
13 | auto layout = new QHBoxLayout{widget}; | |||
|
14 | layout->setContentsMargins(0, 0, 0, 0); | |||
|
15 | layout->setSpacing(0); | |||
|
16 | ||||
|
17 | auto btnValid = new QToolButton{widget}; | |||
|
18 | btnValid->setIcon(QIcon{":/icones/save"}); | |||
|
19 | btnValid->setIconSize(QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE}); | |||
|
20 | btnValid->setAutoRaise(true); | |||
|
21 | QObject::connect(btnValid, &QToolButton::clicked, save); | |||
|
22 | layout->addWidget(btnValid); | |||
|
23 | ||||
|
24 | auto btnDiscard = new QToolButton{widget}; | |||
|
25 | btnDiscard->setIcon(QIcon{":/icones/discard"}); | |||
|
26 | btnDiscard->setIconSize(QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE}); | |||
|
27 | btnDiscard->setAutoRaise(true); | |||
|
28 | QObject::connect(btnDiscard, &QToolButton::clicked, discard); | |||
|
29 | layout->addWidget(btnDiscard); | |||
|
30 | ||||
|
31 | return widget; | |||
|
32 | } |
@@ -0,0 +1,59 | |||||
|
1 | #include "Catalogue/CreateEventDialog.h" | |||
|
2 | #include "ui_CreateEventDialog.h" | |||
|
3 | ||||
|
4 | #include <Catalogue/CatalogueController.h> | |||
|
5 | #include <SqpApplication.h> | |||
|
6 | ||||
|
7 | #include <DBCatalogue.h> | |||
|
8 | ||||
|
9 | struct CreateEventDialog::CreateEventDialogPrivate { | |||
|
10 | QVector<std::shared_ptr<DBCatalogue> > m_DisplayedCatalogues; | |||
|
11 | }; | |||
|
12 | ||||
|
13 | CreateEventDialog::CreateEventDialog(QWidget *parent) | |||
|
14 | : QDialog(parent), | |||
|
15 | ui(new Ui::CreateEventDialog), | |||
|
16 | impl{spimpl::make_unique_impl<CreateEventDialogPrivate>()} | |||
|
17 | { | |||
|
18 | ui->setupUi(this); | |||
|
19 | ||||
|
20 | connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); | |||
|
21 | connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); | |||
|
22 | ||||
|
23 | auto catalogues = sqpApp->catalogueController().retrieveCatalogues(); | |||
|
24 | for (auto cat : catalogues) { | |||
|
25 | ui->cbCatalogue->addItem(cat->getName()); | |||
|
26 | impl->m_DisplayedCatalogues << cat; | |||
|
27 | } | |||
|
28 | } | |||
|
29 | ||||
|
30 | CreateEventDialog::~CreateEventDialog() | |||
|
31 | { | |||
|
32 | delete ui; | |||
|
33 | } | |||
|
34 | ||||
|
35 | void CreateEventDialog::hideCatalogueChoice() | |||
|
36 | { | |||
|
37 | ui->cbCatalogue->hide(); | |||
|
38 | ui->lblCatalogue->hide(); | |||
|
39 | } | |||
|
40 | ||||
|
41 | QString CreateEventDialog::eventName() const | |||
|
42 | { | |||
|
43 | return ui->leEvent->text(); | |||
|
44 | } | |||
|
45 | ||||
|
46 | std::shared_ptr<DBCatalogue> CreateEventDialog::selectedCatalogue() const | |||
|
47 | { | |||
|
48 | auto catalogue = impl->m_DisplayedCatalogues.value(ui->cbCatalogue->currentIndex()); | |||
|
49 | if (!catalogue || catalogue->getName() != catalogueName()) { | |||
|
50 | return nullptr; | |||
|
51 | } | |||
|
52 | ||||
|
53 | return catalogue; | |||
|
54 | } | |||
|
55 | ||||
|
56 | QString CreateEventDialog::catalogueName() const | |||
|
57 | { | |||
|
58 | return ui->cbCatalogue->currentText(); | |||
|
59 | } |
@@ -0,0 +1,55 | |||||
|
1 | <?xml version="1.0" encoding="UTF-8"?> | |||
|
2 | <ui version="4.0"> | |||
|
3 | <class>CreateEventDialog</class> | |||
|
4 | <widget class="QDialog" name="CreateEventDialog"> | |||
|
5 | <property name="geometry"> | |||
|
6 | <rect> | |||
|
7 | <x>0</x> | |||
|
8 | <y>0</y> | |||
|
9 | <width>324</width> | |||
|
10 | <height>93</height> | |||
|
11 | </rect> | |||
|
12 | </property> | |||
|
13 | <property name="windowTitle"> | |||
|
14 | <string>New Event</string> | |||
|
15 | </property> | |||
|
16 | <layout class="QGridLayout" name="gridLayout"> | |||
|
17 | <item row="0" column="0"> | |||
|
18 | <widget class="QLabel" name="label"> | |||
|
19 | <property name="text"> | |||
|
20 | <string>Event Name</string> | |||
|
21 | </property> | |||
|
22 | </widget> | |||
|
23 | </item> | |||
|
24 | <item row="0" column="1"> | |||
|
25 | <widget class="QLineEdit" name="leEvent"/> | |||
|
26 | </item> | |||
|
27 | <item row="1" column="0"> | |||
|
28 | <widget class="QLabel" name="lblCatalogue"> | |||
|
29 | <property name="text"> | |||
|
30 | <string>Catalogue</string> | |||
|
31 | </property> | |||
|
32 | </widget> | |||
|
33 | </item> | |||
|
34 | <item row="1" column="1"> | |||
|
35 | <widget class="QComboBox" name="cbCatalogue"> | |||
|
36 | <property name="editable"> | |||
|
37 | <bool>true</bool> | |||
|
38 | </property> | |||
|
39 | <property name="insertPolicy"> | |||
|
40 | <enum>QComboBox::NoInsert</enum> | |||
|
41 | </property> | |||
|
42 | </widget> | |||
|
43 | </item> | |||
|
44 | <item row="2" column="0" colspan="2"> | |||
|
45 | <widget class="QDialogButtonBox" name="buttonBox"> | |||
|
46 | <property name="standardButtons"> | |||
|
47 | <set>QDialogButtonBox::Ok</set> | |||
|
48 | </property> | |||
|
49 | </widget> | |||
|
50 | </item> | |||
|
51 | </layout> | |||
|
52 | </widget> | |||
|
53 | <resources/> | |||
|
54 | <connections/> | |||
|
55 | </ui> |
@@ -1,89 +1,89 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the QLop Software |
|
2 | -- This file is a part of the QLop Software | |
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 2 of the License, or |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #include "MainWindow.h" |
|
22 | #include "MainWindow.h" | |
23 | #include <QProcessEnvironment> |
|
23 | #include <QProcessEnvironment> | |
24 | #include <QThread> |
|
24 | #include <QThread> | |
25 | #include <SqpApplication.h> |
|
25 | #include <SqpApplication.h> | |
26 | #include <qglobal.h> |
|
26 | #include <qglobal.h> | |
27 |
|
27 | |||
28 | #include <QtPlugin> |
|
|||
29 | #include <Plugin/PluginManager.h> |
|
28 | #include <Plugin/PluginManager.h> | |
30 | #include <QDir> |
|
29 | #include <QDir> | |
|
30 | #include <QtPlugin> | |||
31 |
|
31 | |||
32 | #include <QLoggingCategory> |
|
32 | #include <QLoggingCategory> | |
33 |
|
33 | |||
34 | Q_LOGGING_CATEGORY(LOG_Main, "Main") |
|
34 | Q_LOGGING_CATEGORY(LOG_Main, "Main") | |
35 |
|
35 | |||
36 | namespace { |
|
36 | namespace { | |
37 |
|
37 | |||
38 | const auto PLUGIN_DIRECTORY_NAME = QStringLiteral("plugins"); |
|
38 | const auto PLUGIN_DIRECTORY_NAME = QStringLiteral("plugins"); | |
39 |
|
39 | |||
40 |
|
40 | |||
41 | } // namespace |
|
41 | } // namespace | |
42 |
|
42 | |||
43 | int main(int argc, char *argv[]) |
|
43 | int main(int argc, char *argv[]) | |
44 | { |
|
44 | { | |
45 | #ifdef QT_STATICPLUGIN |
|
45 | #ifdef QT_STATICPLUGIN | |
46 | Q_IMPORT_PLUGIN(MockPlugin) |
|
46 | Q_IMPORT_PLUGIN(MockPlugin) | |
47 | Q_IMPORT_PLUGIN(AmdaPlugin) |
|
47 | Q_IMPORT_PLUGIN(AmdaPlugin) | |
48 | Q_INIT_RESOURCE(amdaresources); |
|
48 | Q_INIT_RESOURCE(amdaresources); | |
49 | #endif |
|
49 | #endif | |
50 | Q_INIT_RESOURCE(sqpguiresources); |
|
50 | Q_INIT_RESOURCE(sqpguiresources); | |
51 |
|
51 | |||
52 | SqpApplication a{argc, argv}; |
|
52 | SqpApplication a{argc, argv}; | |
53 | SqpApplication::setOrganizationName("LPP"); |
|
53 | SqpApplication::setOrganizationName("LPP"); | |
54 | SqpApplication::setOrganizationDomain("lpp.fr"); |
|
54 | SqpApplication::setOrganizationDomain("lpp.fr"); | |
55 | SqpApplication::setApplicationName("SciQLop"); |
|
55 | SqpApplication::setApplicationName("SciQLop"); | |
56 | MainWindow w; |
|
56 | MainWindow w; | |
57 | w.show(); |
|
57 | w.show(); | |
58 |
|
58 | |||
59 | // Loads plugins |
|
59 | // Loads plugins | |
60 | auto pluginDir = QDir{a.applicationDirPath()}; |
|
60 | auto pluginDir = QDir{a.applicationDirPath()}; | |
61 | auto pluginLookupPath = { |
|
61 | auto pluginLookupPath = { | |
62 | a.applicationDirPath(), |
|
62 | a.applicationDirPath(), | |
63 | a.applicationDirPath() + "/" + PLUGIN_DIRECTORY_NAME, |
|
63 | a.applicationDirPath() + "/" + PLUGIN_DIRECTORY_NAME, | |
64 | a.applicationDirPath() + "/../lib64/SciQlop", |
|
64 | a.applicationDirPath() + "/../lib64/SciQlop", | |
65 | a.applicationDirPath() + "/../lib64/sciqlop", |
|
65 | a.applicationDirPath() + "/../lib64/sciqlop", | |
66 | a.applicationDirPath() + "/../lib/SciQlop", |
|
66 | a.applicationDirPath() + "/../lib/SciQlop", | |
67 | a.applicationDirPath() + "/../lib/sciqlop", |
|
67 | a.applicationDirPath() + "/../lib/sciqlop", | |
68 | a.applicationDirPath() + "/../plugins", |
|
68 | a.applicationDirPath() + "/../plugins", | |
69 | }; |
|
69 | }; | |
70 |
|
70 | |||
71 | #if _WIN32 || _WIN64 |
|
71 | #if _WIN32 || _WIN64 | |
72 | pluginDir.mkdir(PLUGIN_DIRECTORY_NAME); |
|
72 | pluginDir.mkdir(PLUGIN_DIRECTORY_NAME); | |
73 | pluginDir.cd(PLUGIN_DIRECTORY_NAME); |
|
73 | pluginDir.cd(PLUGIN_DIRECTORY_NAME); | |
74 | #endif |
|
74 | #endif | |
75 |
|
75 | |||
76 | PluginManager pluginManager{}; |
|
76 | PluginManager pluginManager{}; | |
77 |
|
77 | |||
78 | for (auto &&path : pluginLookupPath) { |
|
78 | for (auto &&path : pluginLookupPath) { | |
79 | QDir directory{path}; |
|
79 | QDir directory{path}; | |
80 | if (directory.exists()) { |
|
80 | if (directory.exists()) { | |
81 | qCDebug(LOG_Main()) |
|
81 | qCDebug(LOG_Main()) | |
82 | << QObject::tr("Plugin directory: %1").arg(directory.absolutePath()); |
|
82 | << QObject::tr("Plugin directory: %1").arg(directory.absolutePath()); | |
83 | pluginManager.loadPlugins(directory); |
|
83 | pluginManager.loadPlugins(directory); | |
84 | } |
|
84 | } | |
85 | } |
|
85 | } | |
86 | pluginManager.loadStaticPlugins(); |
|
86 | pluginManager.loadStaticPlugins(); | |
87 |
|
87 | |||
88 | return a.exec(); |
|
88 | return a.exec(); | |
89 | } |
|
89 | } |
@@ -1,69 +1,75 | |||||
1 | #ifndef SCIQLOP_CATALOGUECONTROLLER_H |
|
1 | #ifndef SCIQLOP_CATALOGUECONTROLLER_H | |
2 | #define SCIQLOP_CATALOGUECONTROLLER_H |
|
2 | #define SCIQLOP_CATALOGUECONTROLLER_H | |
3 |
|
3 | |||
4 | #include "CoreGlobal.h" |
|
4 | #include "CoreGlobal.h" | |
5 |
|
5 | |||
6 | #include <Data/SqpRange.h> |
|
6 | #include <Data/SqpRange.h> | |
7 |
|
7 | |||
8 | #include <QLoggingCategory> |
|
8 | #include <QLoggingCategory> | |
9 | #include <QObject> |
|
9 | #include <QObject> | |
10 | #include <QUuid> |
|
10 | #include <QUuid> | |
11 |
|
11 | |||
12 | #include <Common/spimpl.h> |
|
12 | #include <Common/spimpl.h> | |
13 |
|
13 | |||
14 | #include <memory> |
|
14 | #include <memory> | |
15 |
|
15 | |||
16 | class DBCatalogue; |
|
16 | class DBCatalogue; | |
17 | class DBEvent; |
|
17 | class DBEvent; | |
18 |
|
18 | |||
19 | Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController) |
|
19 | Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController) | |
20 |
|
20 | |||
21 | class DataSourceItem; |
|
21 | class DataSourceItem; | |
22 | class Variable; |
|
22 | class Variable; | |
23 |
|
23 | |||
24 | /** |
|
24 | /** | |
25 | * @brief The CatalogueController class aims to handle catalogues and event using the CatalogueAPI |
|
25 | * @brief The CatalogueController class aims to handle catalogues and event using the CatalogueAPI | |
26 | * library. |
|
26 | * library. | |
27 | */ |
|
27 | */ | |
28 | class SCIQLOP_CORE_EXPORT CatalogueController : public QObject { |
|
28 | class SCIQLOP_CORE_EXPORT CatalogueController : public QObject { | |
29 | Q_OBJECT |
|
29 | Q_OBJECT | |
30 | public: |
|
30 | public: | |
31 | explicit CatalogueController(QObject *parent = 0); |
|
31 | explicit CatalogueController(QObject *parent = 0); | |
32 | virtual ~CatalogueController(); |
|
32 | virtual ~CatalogueController(); | |
33 |
|
33 | |||
34 | // DB |
|
34 | // DB | |
35 |
|
|
35 | QStringList getRepositories() const; | |
36 | void addDB(const QString &dbPath); |
|
36 | void addDB(const QString &dbPath); | |
37 | void saveDB(const QString &destinationPath, const QString &repository); |
|
37 | void saveDB(const QString &destinationPath, const QString &repository); | |
38 |
|
38 | |||
39 | // Event |
|
39 | // Event | |
40 | // bool createEvent(const QString &name); |
|
40 | /// retrieveEvents with empty repository retrieve them from the default repository | |
41 | std::list<std::shared_ptr<DBEvent> > retrieveEvents(const QString &repository) const; |
|
41 | std::list<std::shared_ptr<DBEvent> > retrieveEvents(const QString &repository) const; | |
42 | std::list<std::shared_ptr<DBEvent> > retrieveAllEvents() const; |
|
42 | std::list<std::shared_ptr<DBEvent> > retrieveAllEvents() const; | |
43 | std::list<std::shared_ptr<DBEvent> > |
|
43 | std::list<std::shared_ptr<DBEvent> > | |
44 | retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const; |
|
44 | retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const; | |
45 |
|
|
45 | void addEvent(std::shared_ptr<DBEvent> event); | |
|
46 | void updateEvent(std::shared_ptr<DBEvent> event); | |||
|
47 | void removeEvent(std::shared_ptr<DBEvent> event); | |||
46 | // void trashEvent(std::shared_ptr<DBEvent> event); |
|
48 | // void trashEvent(std::shared_ptr<DBEvent> event); | |
47 | // void removeEvent(std::shared_ptr<DBEvent> event); |
|
|||
48 | // void restore(QUuid eventId); |
|
49 | // void restore(QUuid eventId); | |
49 |
|
|
50 | void saveEvent(std::shared_ptr<DBEvent> event); | |
50 |
|
51 | |||
51 | // Catalogue |
|
52 | // Catalogue | |
52 | // bool createCatalogue(const QString &name, QVector<QUuid> eventList); |
|
53 | // bool createCatalogue(const QString &name, QVector<QUuid> eventList); | |
53 | std::list<std::shared_ptr<DBCatalogue> > getCatalogues(const QString &repository) const; |
|
54 | /// retrieveEvents with empty repository retrieve them from the default repository | |
54 | // void removeEvent(QUuid catalogueId, const QString &repository); |
|
55 | std::list<std::shared_ptr<DBCatalogue> > retrieveCatalogues(const QString &repository | |
55 | // void saveCatalogue(std::shared_ptr<DBEvent> event); |
|
56 | = QString()) const; | |
|
57 | void updateCatalogue(std::shared_ptr<DBCatalogue> catalogue); | |||
|
58 | void removeCatalogue(std::shared_ptr<DBCatalogue> catalogue); | |||
|
59 | void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue); | |||
|
60 | ||||
|
61 | void saveAll(); | |||
56 |
|
62 | |||
57 | public slots: |
|
63 | public slots: | |
58 | /// Manage init/end of the controller |
|
64 | /// Manage init/end of the controller | |
59 | void initialize(); |
|
65 | void initialize(); | |
60 | void finalize(); |
|
66 | void finalize(); | |
61 |
|
67 | |||
62 | private: |
|
68 | private: | |
63 | void waitForFinish(); |
|
69 | void waitForFinish(); | |
64 |
|
70 | |||
65 | class CatalogueControllerPrivate; |
|
71 | class CatalogueControllerPrivate; | |
66 | spimpl::unique_impl_ptr<CatalogueControllerPrivate> impl; |
|
72 | spimpl::unique_impl_ptr<CatalogueControllerPrivate> impl; | |
67 | }; |
|
73 | }; | |
68 |
|
74 | |||
69 | #endif // SCIQLOP_CATALOGUECONTROLLER_H |
|
75 | #endif // SCIQLOP_CATALOGUECONTROLLER_H |
@@ -1,161 +1,296 | |||||
1 | #include <Catalogue/CatalogueController.h> |
|
1 | #include <Catalogue/CatalogueController.h> | |
2 |
|
2 | |||
3 | #include <Variable/Variable.h> |
|
3 | #include <Variable/Variable.h> | |
4 |
|
4 | |||
5 | #include <CatalogueDao.h> |
|
5 | #include <CatalogueDao.h> | |
6 |
|
6 | |||
7 | #include <ComparaisonPredicate.h> |
|
7 | #include <ComparaisonPredicate.h> | |
8 | #include <CompoundPredicate.h> |
|
8 | #include <CompoundPredicate.h> | |
9 | #include <DBCatalogue.h> |
|
9 | #include <DBCatalogue.h> | |
10 | #include <DBEvent.h> |
|
10 | #include <DBEvent.h> | |
|
11 | #include <DBEventProduct.h> | |||
11 | #include <DBTag.h> |
|
12 | #include <DBTag.h> | |
12 | #include <IRequestPredicate.h> |
|
13 | #include <IRequestPredicate.h> | |
13 |
|
14 | |||
14 | #include <QMutex> |
|
15 | #include <QMutex> | |
15 | #include <QThread> |
|
16 | #include <QThread> | |
16 |
|
17 | |||
17 | #include <QDir> |
|
18 | #include <QDir> | |
18 | #include <QStandardPaths> |
|
19 | #include <QStandardPaths> | |
19 |
|
20 | |||
20 | Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController") |
|
21 | Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController") | |
21 |
|
22 | |||
22 | namespace { |
|
23 | namespace { | |
23 |
|
24 | |||
24 |
static QString REPOSITORY_WORK_SUFFIX = QString{" |
|
25 | static QString REPOSITORY_WORK_SUFFIX = QString{"work"}; | |
25 |
|
26 | static QString REPOSITORY_TRASH_SUFFIX = QString{"trash"}; | ||
26 | } |
|
27 | } | |
27 |
|
28 | |||
28 | class CatalogueController::CatalogueControllerPrivate { |
|
29 | class CatalogueController::CatalogueControllerPrivate { | |
|
30 | ||||
29 | public: |
|
31 | public: | |
|
32 | explicit CatalogueControllerPrivate(CatalogueController *parent) : m_Q{parent} {} | |||
|
33 | ||||
30 | QMutex m_WorkingMutex; |
|
34 | QMutex m_WorkingMutex; | |
31 | CatalogueDao m_CatalogueDao; |
|
35 | CatalogueDao m_CatalogueDao; | |
32 |
|
36 | |||
33 |
|
|
37 | QStringList m_RepositoryList; | |
|
38 | CatalogueController *m_Q; | |||
|
39 | ||||
|
40 | void copyDBtoDB(const QString &dbFrom, const QString &dbTo); | |||
|
41 | QString toWorkRepository(QString repository); | |||
|
42 | QString toSyncRepository(QString repository); | |||
34 | }; |
|
43 | }; | |
35 |
|
44 | |||
36 | CatalogueController::CatalogueController(QObject *parent) |
|
45 | CatalogueController::CatalogueController(QObject *parent) | |
37 | : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>()} |
|
46 | : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>(this)} | |
38 | { |
|
47 | { | |
39 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction") |
|
48 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction") | |
40 | << QThread::currentThread(); |
|
49 | << QThread::currentThread(); | |
41 | } |
|
50 | } | |
42 |
|
51 | |||
43 | CatalogueController::~CatalogueController() |
|
52 | CatalogueController::~CatalogueController() | |
44 | { |
|
53 | { | |
45 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction") |
|
54 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction") | |
46 | << QThread::currentThread(); |
|
55 | << QThread::currentThread(); | |
47 | this->waitForFinish(); |
|
56 | this->waitForFinish(); | |
48 | } |
|
57 | } | |
49 |
|
58 | |||
|
59 | QStringList CatalogueController::getRepositories() const | |||
|
60 | { | |||
|
61 | return impl->m_RepositoryList; | |||
|
62 | } | |||
|
63 | ||||
50 | void CatalogueController::addDB(const QString &dbPath) |
|
64 | void CatalogueController::addDB(const QString &dbPath) | |
51 | { |
|
65 | { | |
52 | QDir dbDir(dbPath); |
|
66 | QDir dbDir(dbPath); | |
53 | if (dbDir.exists()) { |
|
67 | if (dbDir.exists()) { | |
54 | auto dirName = dbDir.dirName(); |
|
68 | auto dirName = dbDir.dirName(); | |
55 |
|
69 | |||
56 | if (std::find(impl->m_RepositoryList.cbegin(), impl->m_RepositoryList.cend(), dirName) |
|
70 | if (std::find(impl->m_RepositoryList.cbegin(), impl->m_RepositoryList.cend(), dirName) | |
57 | != impl->m_RepositoryList.cend()) { |
|
71 | != impl->m_RepositoryList.cend()) { | |
58 | qCCritical(LOG_CatalogueController()) |
|
72 | qCCritical(LOG_CatalogueController()) | |
59 | << tr("Impossible to addDB that is already loaded"); |
|
73 | << tr("Impossible to addDB that is already loaded"); | |
60 | } |
|
74 | } | |
61 |
|
75 | |||
62 | if (!impl->m_CatalogueDao.addDB(dbPath, dirName)) { |
|
76 | if (!impl->m_CatalogueDao.addDB(dbPath, dirName)) { | |
63 | qCCritical(LOG_CatalogueController()) |
|
77 | qCCritical(LOG_CatalogueController()) | |
64 | << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath); |
|
78 | << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath); | |
65 | } |
|
79 | } | |
66 | else { |
|
80 | else { | |
67 |
impl->m_RepositoryList |
|
81 | impl->m_RepositoryList << dirName; | |
|
82 | impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName)); | |||
68 | } |
|
83 | } | |
69 | } |
|
84 | } | |
70 | else { |
|
85 | else { | |
71 | qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ") |
|
86 | qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ") | |
72 | << dbPath; |
|
87 | << dbPath; | |
73 | } |
|
88 | } | |
74 | } |
|
89 | } | |
75 |
|
90 | |||
76 | void CatalogueController::saveDB(const QString &destinationPath, const QString &repository) |
|
91 | void CatalogueController::saveDB(const QString &destinationPath, const QString &repository) | |
77 | { |
|
92 | { | |
78 | if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) { |
|
93 | if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) { | |
79 | qCCritical(LOG_CatalogueController()) |
|
94 | qCCritical(LOG_CatalogueController()) | |
80 | << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath); |
|
95 | << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath); | |
81 | } |
|
96 | } | |
82 | } |
|
97 | } | |
83 |
|
98 | |||
84 | std::list<std::shared_ptr<DBEvent> > |
|
99 | std::list<std::shared_ptr<DBEvent> > | |
85 | CatalogueController::retrieveEvents(const QString &repository) const |
|
100 | CatalogueController::retrieveEvents(const QString &repository) const | |
86 | { |
|
101 | { | |
|
102 | QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository; | |||
|
103 | ||||
87 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; |
|
104 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; | |
88 | auto events = impl->m_CatalogueDao.getEvents(repository); |
|
105 | auto events = impl->m_CatalogueDao.getEvents(impl->toWorkRepository(dbDireName)); | |
89 | for (auto event : events) { |
|
106 | for (auto event : events) { | |
90 | eventsShared.push_back(std::make_shared<DBEvent>(event)); |
|
107 | eventsShared.push_back(std::make_shared<DBEvent>(event)); | |
91 | } |
|
108 | } | |
92 | return eventsShared; |
|
109 | return eventsShared; | |
93 | } |
|
110 | } | |
94 |
|
111 | |||
95 | std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() const |
|
112 | std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() const | |
96 | { |
|
113 | { | |
97 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; |
|
114 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; | |
98 | for (auto repository : impl->m_RepositoryList) { |
|
115 | for (auto repository : impl->m_RepositoryList) { | |
99 | eventsShared.splice(eventsShared.end(), retrieveEvents(repository)); |
|
116 | eventsShared.splice(eventsShared.end(), retrieveEvents(repository)); | |
100 | } |
|
117 | } | |
101 |
|
118 | |||
102 | return eventsShared; |
|
119 | return eventsShared; | |
103 | } |
|
120 | } | |
104 |
|
121 | |||
105 | std::list<std::shared_ptr<DBEvent> > |
|
122 | std::list<std::shared_ptr<DBEvent> > | |
106 | CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const |
|
123 | CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const | |
107 | { |
|
124 | { | |
108 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; |
|
125 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; | |
109 | auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue); |
|
126 | auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue); | |
110 | for (auto event : events) { |
|
127 | for (auto event : events) { | |
111 | eventsShared.push_back(std::make_shared<DBEvent>(event)); |
|
128 | eventsShared.push_back(std::make_shared<DBEvent>(event)); | |
112 | } |
|
129 | } | |
113 | return eventsShared; |
|
130 | return eventsShared; | |
114 | } |
|
131 | } | |
115 |
|
132 | |||
|
133 | void CatalogueController::updateEvent(std::shared_ptr<DBEvent> event) | |||
|
134 | { | |||
|
135 | event->setRepository(impl->toSyncRepository(event->getRepository())); | |||
|
136 | ||||
|
137 | impl->m_CatalogueDao.updateEvent(*event); | |||
|
138 | } | |||
|
139 | ||||
|
140 | void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event) | |||
|
141 | { | |||
|
142 | // Remove it from both repository and repository_work | |||
|
143 | event->setRepository(impl->toWorkRepository(event->getRepository())); | |||
|
144 | impl->m_CatalogueDao.removeEvent(*event); | |||
|
145 | event->setRepository(impl->toSyncRepository(event->getRepository())); | |||
|
146 | impl->m_CatalogueDao.removeEvent(*event); | |||
|
147 | } | |||
|
148 | ||||
|
149 | void CatalogueController::addEvent(std::shared_ptr<DBEvent> event) | |||
|
150 | { | |||
|
151 | event->setRepository(impl->toWorkRepository(event->getRepository())); | |||
|
152 | ||||
|
153 | impl->m_CatalogueDao.addEvent(*event); | |||
|
154 | ||||
|
155 | // Call update is necessary at the creation of add Event if it has some tags or some event | |||
|
156 | // products | |||
|
157 | if (!event->getEventProducts().empty() || !event->getTags().empty()) { | |||
|
158 | impl->m_CatalogueDao.updateEvent(*event); | |||
|
159 | } | |||
|
160 | } | |||
|
161 | ||||
|
162 | void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event) | |||
|
163 | { | |||
|
164 | impl->m_CatalogueDao.moveEvent(*event, impl->toSyncRepository(event->getRepository()), true); | |||
|
165 | } | |||
|
166 | ||||
116 | std::list<std::shared_ptr<DBCatalogue> > |
|
167 | std::list<std::shared_ptr<DBCatalogue> > | |
117 |
CatalogueController:: |
|
168 | CatalogueController::retrieveCatalogues(const QString &repository) const | |
118 | { |
|
169 | { | |
|
170 | QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository; | |||
|
171 | ||||
119 | auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{}; |
|
172 | auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{}; | |
120 | auto catalogues = impl->m_CatalogueDao.getCatalogues(repository); |
|
173 | auto catalogues = impl->m_CatalogueDao.getCatalogues(impl->toWorkRepository(dbDireName)); | |
121 | for (auto catalogue : catalogues) { |
|
174 | for (auto catalogue : catalogues) { | |
122 | cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue)); |
|
175 | cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue)); | |
123 | } |
|
176 | } | |
124 | return cataloguesShared; |
|
177 | return cataloguesShared; | |
125 | } |
|
178 | } | |
126 |
|
179 | |||
|
180 | void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue) | |||
|
181 | { | |||
|
182 | catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository())); | |||
|
183 | ||||
|
184 | impl->m_CatalogueDao.updateCatalogue(*catalogue); | |||
|
185 | } | |||
|
186 | ||||
|
187 | void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue) | |||
|
188 | { | |||
|
189 | // Remove it from both repository and repository_work | |||
|
190 | catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); | |||
|
191 | impl->m_CatalogueDao.removeCatalogue(*catalogue); | |||
|
192 | catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository())); | |||
|
193 | impl->m_CatalogueDao.removeCatalogue(*catalogue); | |||
|
194 | } | |||
|
195 | ||||
|
196 | void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue) | |||
|
197 | { | |||
|
198 | impl->m_CatalogueDao.moveCatalogue(*catalogue, | |||
|
199 | impl->toSyncRepository(catalogue->getRepository()), true); | |||
|
200 | } | |||
|
201 | ||||
|
202 | void CatalogueController::saveAll() | |||
|
203 | { | |||
|
204 | for (auto repository : impl->m_RepositoryList) { | |||
|
205 | // Save Event | |||
|
206 | auto events = this->retrieveEvents(repository); | |||
|
207 | for (auto event : events) { | |||
|
208 | this->saveEvent(event); | |||
|
209 | } | |||
|
210 | ||||
|
211 | // Save Catalogue | |||
|
212 | auto catalogues = this->retrieveCatalogues(repository); | |||
|
213 | for (auto catalogue : catalogues) { | |||
|
214 | this->saveCatalogue(catalogue); | |||
|
215 | } | |||
|
216 | } | |||
|
217 | } | |||
|
218 | ||||
127 | void CatalogueController::initialize() |
|
219 | void CatalogueController::initialize() | |
128 | { |
|
220 | { | |
129 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController init") |
|
221 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController init") | |
130 | << QThread::currentThread(); |
|
222 | << QThread::currentThread(); | |
131 | impl->m_WorkingMutex.lock(); |
|
223 | impl->m_WorkingMutex.lock(); | |
132 | impl->m_CatalogueDao.initialize(); |
|
224 | impl->m_CatalogueDao.initialize(); | |
133 | auto defaultRepositoryLocation |
|
225 | auto defaultRepositoryLocation | |
134 | = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); |
|
226 | = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); | |
135 |
|
227 | |||
136 | QDir defaultRepositoryLocationDir; |
|
228 | QDir defaultRepositoryLocationDir; | |
137 | if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) { |
|
229 | if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) { | |
138 | defaultRepositoryLocationDir.cd(defaultRepositoryLocation); |
|
230 | defaultRepositoryLocationDir.cd(defaultRepositoryLocation); | |
139 | auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT); |
|
231 | auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT); | |
140 | qCInfo(LOG_CatalogueController()) |
|
232 | qCInfo(LOG_CatalogueController()) << tr("Persistant data loading from: ") | |
141 | << tr("Persistant data loading from: ") << defaultRepository; |
|
233 | << defaultRepository; | |
142 | this->addDB(defaultRepository); |
|
234 | this->addDB(defaultRepository); | |
143 | } |
|
235 | } | |
144 | else { |
|
236 | else { | |
145 | qCWarning(LOG_CatalogueController()) |
|
237 | qCWarning(LOG_CatalogueController()) | |
146 | << tr("Cannot load the persistent default repository from ") |
|
238 | << tr("Cannot load the persistent default repository from ") | |
147 | << defaultRepositoryLocation; |
|
239 | << defaultRepositoryLocation; | |
148 | } |
|
240 | } | |
149 |
|
241 | |||
150 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END"); |
|
242 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END"); | |
151 | } |
|
243 | } | |
152 |
|
244 | |||
153 | void CatalogueController::finalize() |
|
245 | void CatalogueController::finalize() | |
154 | { |
|
246 | { | |
155 | impl->m_WorkingMutex.unlock(); |
|
247 | impl->m_WorkingMutex.unlock(); | |
156 | } |
|
248 | } | |
157 |
|
249 | |||
158 | void CatalogueController::waitForFinish() |
|
250 | void CatalogueController::waitForFinish() | |
159 | { |
|
251 | { | |
160 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
252 | QMutexLocker locker{&impl->m_WorkingMutex}; | |
161 | } |
|
253 | } | |
|
254 | ||||
|
255 | void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom, | |||
|
256 | const QString &dbTo) | |||
|
257 | { | |||
|
258 | auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{}; | |||
|
259 | auto catalogues = m_CatalogueDao.getCatalogues(dbFrom); | |||
|
260 | for (auto catalogue : catalogues) { | |||
|
261 | cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue)); | |||
|
262 | } | |||
|
263 | ||||
|
264 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; | |||
|
265 | auto events = m_CatalogueDao.getEvents(dbFrom); | |||
|
266 | for (auto event : events) { | |||
|
267 | eventsShared.push_back(std::make_shared<DBEvent>(event)); | |||
|
268 | } | |||
|
269 | ||||
|
270 | for (auto catalogue : cataloguesShared) { | |||
|
271 | m_CatalogueDao.copyCatalogue(*catalogue, dbTo, true); | |||
|
272 | } | |||
|
273 | ||||
|
274 | for (auto event : eventsShared) { | |||
|
275 | m_CatalogueDao.copyEvent(*event, dbTo, true); | |||
|
276 | } | |||
|
277 | } | |||
|
278 | ||||
|
279 | QString CatalogueController::CatalogueControllerPrivate::toWorkRepository(QString repository) | |||
|
280 | { | |||
|
281 | auto syncRepository = toSyncRepository(repository); | |||
|
282 | ||||
|
283 | return QString("%1_%2").arg(syncRepository, REPOSITORY_WORK_SUFFIX); | |||
|
284 | } | |||
|
285 | ||||
|
286 | QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QString repository) | |||
|
287 | { | |||
|
288 | auto syncRepository = repository; | |||
|
289 | if (repository.endsWith(REPOSITORY_WORK_SUFFIX)) { | |||
|
290 | syncRepository.remove(REPOSITORY_WORK_SUFFIX); | |||
|
291 | } | |||
|
292 | else if (repository.endsWith(REPOSITORY_TRASH_SUFFIX)) { | |||
|
293 | syncRepository.remove(REPOSITORY_TRASH_SUFFIX); | |||
|
294 | } | |||
|
295 | return syncRepository; | |||
|
296 | } |
@@ -1,138 +1,137 | |||||
1 | #include <Plugin/PluginManager.h> |
|
1 | #include <Plugin/PluginManager.h> | |
2 |
|
2 | |||
3 | #include <Plugin/IPlugin.h> |
|
3 | #include <Plugin/IPlugin.h> | |
4 |
|
4 | |||
5 | #include <QDir> |
|
5 | #include <QDir> | |
6 | #include <QLibrary> |
|
6 | #include <QLibrary> | |
7 | #include <QPluginLoader> |
|
7 | #include <QPluginLoader> | |
8 |
|
8 | |||
9 | Q_LOGGING_CATEGORY(LOG_PluginManager, "PluginManager") |
|
9 | Q_LOGGING_CATEGORY(LOG_PluginManager, "PluginManager") | |
10 |
|
10 | |||
11 | namespace { |
|
11 | namespace { | |
12 |
|
12 | |||
13 | /// Key for retrieving metadata of the plugin |
|
13 | /// Key for retrieving metadata of the plugin | |
14 | const auto PLUGIN_METADATA_KEY = QStringLiteral("MetaData"); |
|
14 | const auto PLUGIN_METADATA_KEY = QStringLiteral("MetaData"); | |
15 |
|
15 | |||
16 | /// Key for retrieving the name of the plugin in its metadata |
|
16 | /// Key for retrieving the name of the plugin in its metadata | |
17 | const auto PLUGIN_NAME_KEY = QStringLiteral("name"); |
|
17 | const auto PLUGIN_NAME_KEY = QStringLiteral("name"); | |
18 |
|
18 | |||
19 | /// Helper to state the plugin loading operation |
|
19 | /// Helper to state the plugin loading operation | |
20 | struct LoadPluginState { |
|
20 | struct LoadPluginState { | |
21 | explicit LoadPluginState(const QString &pluginPath) |
|
21 | explicit LoadPluginState(const QString &pluginPath) | |
22 | : m_PluginPath{pluginPath}, m_Valid{true}, m_ErrorMessage{} |
|
22 | : m_PluginPath{pluginPath}, m_Valid{true}, m_ErrorMessage{} | |
23 | { |
|
23 | { | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | void log() const |
|
26 | void log() const | |
27 | { |
|
27 | { | |
28 | if (m_Valid) { |
|
28 | if (m_Valid) { | |
29 | qCDebug(LOG_PluginManager()) |
|
29 | qCDebug(LOG_PluginManager()) | |
30 | << QObject::tr("File '%1' has been loaded as a plugin").arg(m_PluginPath); |
|
30 | << QObject::tr("File '%1' has been loaded as a plugin").arg(m_PluginPath); | |
31 | } |
|
31 | } | |
32 | else { |
|
32 | else { | |
33 | qCWarning(LOG_PluginManager()) |
|
33 | qCWarning(LOG_PluginManager()) | |
34 | << QObject::tr("File '%1' can't be loaded as a plugin: %2") |
|
34 | << QObject::tr("File '%1' can't be loaded as a plugin: %2") | |
35 | .arg(m_PluginPath) |
|
35 | .arg(m_PluginPath) | |
36 | .arg(m_ErrorMessage); |
|
36 | .arg(m_ErrorMessage); | |
37 | } |
|
37 | } | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | void setError(const QString &errorMessage) |
|
40 | void setError(const QString &errorMessage) | |
41 | { |
|
41 | { | |
42 | m_Valid = false; |
|
42 | m_Valid = false; | |
43 | m_ErrorMessage = errorMessage; |
|
43 | m_ErrorMessage = errorMessage; | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | QString m_PluginPath; |
|
46 | QString m_PluginPath; | |
47 | bool m_Valid; |
|
47 | bool m_Valid; | |
48 | QString m_ErrorMessage; |
|
48 | QString m_ErrorMessage; | |
49 | }; |
|
49 | }; | |
50 |
|
50 | |||
51 | } // namespace |
|
51 | } // namespace | |
52 |
|
52 | |||
53 | struct PluginManager::PluginManagerPrivate { |
|
53 | struct PluginManager::PluginManagerPrivate { | |
54 | /** |
|
54 | /** | |
55 | * Loads a single plugin into SciQlop. The method has no effect if the plugin is malformed (e.g. |
|
55 | * Loads a single plugin into SciQlop. The method has no effect if the plugin is malformed (e.g. | |
56 | * wrong library type, missing metadata, etc.) |
|
56 | * wrong library type, missing metadata, etc.) | |
57 | * @param pluginPath the path to the plugin library. |
|
57 | * @param pluginPath the path to the plugin library. | |
58 | */ |
|
58 | */ | |
59 | void loadPlugin(const QString &pluginPath) |
|
59 | void loadPlugin(const QString &pluginPath) | |
60 | { |
|
60 | { | |
61 | qCDebug(LOG_PluginManager()) |
|
61 | qCDebug(LOG_PluginManager()) | |
62 | << QObject::tr("Attempting to load file '%1' as a plugin").arg(pluginPath); |
|
62 | << QObject::tr("Attempting to load file '%1' as a plugin").arg(pluginPath); | |
63 |
|
63 | |||
64 | LoadPluginState loadState{pluginPath}; |
|
64 | LoadPluginState loadState{pluginPath}; | |
65 |
|
65 | |||
66 | if (QLibrary::isLibrary(pluginPath)) { |
|
66 | if (QLibrary::isLibrary(pluginPath)) { | |
67 | QPluginLoader pluginLoader{pluginPath}; |
|
67 | QPluginLoader pluginLoader{pluginPath}; | |
68 |
|
68 | |||
69 | // Retrieving the plugin name to check if it can be loaded (i.e. no plugin with the same |
|
69 | // Retrieving the plugin name to check if it can be loaded (i.e. no plugin with the same | |
70 | // name has been registered yet) |
|
70 | // name has been registered yet) | |
71 | auto metadata = pluginLoader.metaData().value(PLUGIN_METADATA_KEY).toObject(); |
|
71 | auto metadata = pluginLoader.metaData().value(PLUGIN_METADATA_KEY).toObject(); | |
72 | auto pluginName = metadata.value(PLUGIN_NAME_KEY).toString(); |
|
72 | auto pluginName = metadata.value(PLUGIN_NAME_KEY).toString(); | |
73 |
|
73 | |||
74 | if (pluginName.isEmpty()) { |
|
74 | if (pluginName.isEmpty()) { | |
75 | loadState.setError(QObject::tr("empty file name")); |
|
75 | loadState.setError(QObject::tr("empty file name")); | |
76 | } |
|
76 | } | |
77 | else if (m_RegisteredPlugins.contains(pluginName)) { |
|
77 | else if (m_RegisteredPlugins.contains(pluginName)) { | |
78 | loadState.setError(QObject::tr("name '%1' already registered").arg(pluginName)); |
|
78 | loadState.setError(QObject::tr("name '%1' already registered").arg(pluginName)); | |
79 | } |
|
79 | } | |
80 | else { |
|
80 | else { | |
81 | if (auto pluginInstance = qobject_cast<IPlugin *>(pluginLoader.instance())) { |
|
81 | if (auto pluginInstance = qobject_cast<IPlugin *>(pluginLoader.instance())) { | |
82 | pluginInstance->initialize(); |
|
82 | pluginInstance->initialize(); | |
83 | m_RegisteredPlugins.insert(pluginName, pluginPath); |
|
83 | m_RegisteredPlugins.insert(pluginName, pluginPath); | |
84 | } |
|
84 | } | |
85 | else { |
|
85 | else { | |
86 | loadState.setError(QObject::tr("the file is not a Sciqlop plugin")); |
|
86 | loadState.setError(QObject::tr("the file is not a Sciqlop plugin")); | |
87 | } |
|
87 | } | |
88 | } |
|
88 | } | |
89 | } |
|
89 | } | |
90 | else { |
|
90 | else { | |
91 | loadState.setError(QObject::tr("the file is not a library")); |
|
91 | loadState.setError(QObject::tr("the file is not a library")); | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | // Log loading result |
|
94 | // Log loading result | |
95 | loadState.log(); |
|
95 | loadState.log(); | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | void loadStaticPlugins() |
|
98 | void loadStaticPlugins() | |
99 | { |
|
99 | { | |
100 | for (QObject *plugin : QPluginLoader::staticInstances()) |
|
100 | for (QObject *plugin : QPluginLoader::staticInstances()) { | |
101 | { |
|
|||
102 | qobject_cast<IPlugin *>(plugin)->initialize(); |
|
101 | qobject_cast<IPlugin *>(plugin)->initialize(); | |
103 | m_RegisteredPlugins.insert(plugin->metaObject()->className(), "StaticPlugin"); |
|
102 | m_RegisteredPlugins.insert(plugin->metaObject()->className(), "StaticPlugin"); | |
104 | } |
|
103 | } | |
105 | } |
|
104 | } | |
106 |
|
105 | |||
107 | /// Registered plugins (key: plugin name, value: plugin path) |
|
106 | /// Registered plugins (key: plugin name, value: plugin path) | |
108 | QHash<QString, QString> m_RegisteredPlugins; |
|
107 | QHash<QString, QString> m_RegisteredPlugins; | |
109 | }; |
|
108 | }; | |
110 |
|
109 | |||
111 | PluginManager::PluginManager() : impl{spimpl::make_unique_impl<PluginManagerPrivate>()} |
|
110 | PluginManager::PluginManager() : impl{spimpl::make_unique_impl<PluginManagerPrivate>()} | |
112 | { |
|
111 | { | |
113 | } |
|
112 | } | |
114 |
|
113 | |||
115 | void PluginManager::loadPlugins(const QDir &pluginDir) |
|
114 | void PluginManager::loadPlugins(const QDir &pluginDir) | |
116 | { |
|
115 | { | |
117 | // Load plugins |
|
116 | // Load plugins | |
118 | auto pluginInfoList |
|
117 | auto pluginInfoList | |
119 | = pluginDir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name); |
|
118 | = pluginDir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name); | |
120 | for (auto entryInfo : qAsConst(pluginInfoList)) { |
|
119 | for (auto entryInfo : qAsConst(pluginInfoList)) { | |
121 | if (entryInfo.isDir()) { |
|
120 | if (entryInfo.isDir()) { | |
122 | this->loadPlugins(QDir{entryInfo.absoluteFilePath()}); |
|
121 | this->loadPlugins(QDir{entryInfo.absoluteFilePath()}); | |
123 | } |
|
122 | } | |
124 | else if (QLibrary::isLibrary(entryInfo.absoluteFilePath())) { |
|
123 | else if (QLibrary::isLibrary(entryInfo.absoluteFilePath())) { | |
125 | impl->loadPlugin(entryInfo.absoluteFilePath()); |
|
124 | impl->loadPlugin(entryInfo.absoluteFilePath()); | |
126 | } |
|
125 | } | |
127 | } |
|
126 | } | |
128 | } |
|
127 | } | |
129 |
|
128 | |||
130 | void PluginManager::loadStaticPlugins() |
|
129 | void PluginManager::loadStaticPlugins() | |
131 | { |
|
130 | { | |
132 | impl->loadStaticPlugins(); |
|
131 | impl->loadStaticPlugins(); | |
133 | } |
|
132 | } | |
134 |
|
133 | |||
135 | int PluginManager::nbPluginsLoaded() const noexcept |
|
134 | int PluginManager::nbPluginsLoaded() const noexcept | |
136 | { |
|
135 | { | |
137 | return impl->m_RegisteredPlugins.size(); |
|
136 | return impl->m_RegisteredPlugins.size(); | |
138 | } |
|
137 | } |
@@ -1,206 +1,206 | |||||
1 | #include <Data/DataSeriesUtils.h> |
|
1 | #include <Data/DataSeriesUtils.h> | |
2 |
|
2 | |||
3 | #include <QObject> |
|
3 | #include <QObject> | |
4 | #include <QtTest> |
|
4 | #include <QtTest> | |
5 |
|
5 | |||
6 | namespace { |
|
6 | namespace { | |
7 |
|
7 | |||
8 | /// Path for resources |
|
8 | /// Path for resources | |
9 | const auto TESTS_RESOURCES_PATH |
|
9 | const auto TESTS_RESOURCES_PATH | |
10 | = QFileInfo{QString{CORE_TESTS_RESOURCES_DIR}, "TestDataSeriesUtils"}.absoluteFilePath(); |
|
10 | = QFileInfo{QString{CORE_TESTS_RESOURCES_DIR}, "TestDataSeriesUtils"}.absoluteFilePath(); | |
11 |
|
11 | |||
12 | QString inputFilePath(const QString &inputFileName) |
|
12 | QString inputFilePath(const QString &inputFileName) | |
13 | { |
|
13 | { | |
14 | return QFileInfo{TESTS_RESOURCES_PATH, inputFileName}.absoluteFilePath(); |
|
14 | return QFileInfo{TESTS_RESOURCES_PATH, inputFileName}.absoluteFilePath(); | |
15 | } |
|
15 | } | |
16 |
|
16 | |||
17 | } // namespace |
|
17 | } // namespace | |
18 |
|
18 | |||
19 | class TestDataSeriesUtils : public QObject { |
|
19 | class TestDataSeriesUtils : public QObject { | |
20 | Q_OBJECT |
|
20 | Q_OBJECT | |
21 |
|
21 | |||
22 | private slots: |
|
22 | private slots: | |
23 | /// Tests @sa DataSeriesUtils::thresholds() method |
|
23 | /// Tests @sa DataSeriesUtils::thresholds() method | |
24 | void testThresholds_data(); |
|
24 | void testThresholds_data(); | |
25 | void testThresholds(); |
|
25 | void testThresholds(); | |
26 |
|
26 | |||
27 | /// Tests @sa DataSeriesUtils::fillDataHoles() method |
|
27 | /// Tests @sa DataSeriesUtils::fillDataHoles() method | |
28 | void testFillDataHoles_data(); |
|
28 | void testFillDataHoles_data(); | |
29 | void testFillDataHoles(); |
|
29 | void testFillDataHoles(); | |
30 | }; |
|
30 | }; | |
31 |
|
31 | |||
32 | void TestDataSeriesUtils::testFillDataHoles_data() |
|
32 | void TestDataSeriesUtils::testFillDataHoles_data() | |
33 | { |
|
33 | { | |
34 | QTest::addColumn<std::vector<double> >("xAxisData"); |
|
34 | QTest::addColumn<std::vector<double> >("xAxisData"); | |
35 | QTest::addColumn<std::vector<double> >("valuesData"); |
|
35 | QTest::addColumn<std::vector<double> >("valuesData"); | |
36 | QTest::addColumn<double>("resolution"); |
|
36 | QTest::addColumn<double>("resolution"); | |
37 | QTest::addColumn<double>("fillValue"); |
|
37 | QTest::addColumn<double>("fillValue"); | |
38 | QTest::addColumn<double>("minBound"); |
|
38 | QTest::addColumn<double>("minBound"); | |
39 | QTest::addColumn<double>("maxBound"); |
|
39 | QTest::addColumn<double>("maxBound"); | |
40 | QTest::addColumn<std::vector<double> >( |
|
40 | QTest::addColumn<std::vector<double> >( | |
41 | "expectedXAxisData"); // expected x-axis data after filling holes |
|
41 | "expectedXAxisData"); // expected x-axis data after filling holes | |
42 | QTest::addColumn<std::vector<double> >( |
|
42 | QTest::addColumn<std::vector<double> >( | |
43 | "expectedValuesData"); // expected values data after filling holes |
|
43 | "expectedValuesData"); // expected values data after filling holes | |
44 |
|
44 | |||
45 | auto nan = std::numeric_limits<double>::quiet_NaN(); |
|
45 | auto nan = std::numeric_limits<double>::quiet_NaN(); | |
46 |
|
46 | |||
47 | QTest::newRow("fillDataHoles (basic case)") |
|
47 | QTest::newRow("fillDataHoles (basic case)") | |
48 | << std::vector<double>{0., 1., 5., 7., 14.} << std::vector<double>{0., 1., 2., 3., 4.} << 2. |
|
48 | << std::vector<double>{0., 1., 5., 7., 14.} << std::vector<double>{0., 1., 2., 3., 4.} << 2. | |
49 | << nan << nan << nan << std::vector<double>{0., 1., 3., 5., 7., 9., 11., 13., 14.} |
|
49 | << nan << nan << nan << std::vector<double>{0., 1., 3., 5., 7., 9., 11., 13., 14.} | |
50 | << std::vector<double>{0., 1., nan, 2., 3., nan, nan, nan, 4.}; |
|
50 | << std::vector<double>{0., 1., nan, 2., 3., nan, nan, nan, 4.}; | |
51 |
|
51 | |||
52 | QTest::newRow("fillDataHoles (change nb components)") |
|
52 | QTest::newRow("fillDataHoles (change nb components)") | |
53 | << std::vector<double>{0., 1., 5., 7., 14.} |
|
53 | << std::vector<double>{0., 1., 5., 7., 14.} | |
54 | << std::vector<double>{0., 1., 2., 3., 4., 5., 6., 7., 8., 9.} << 2. << nan << nan << nan |
|
54 | << std::vector<double>{0., 1., 2., 3., 4., 5., 6., 7., 8., 9.} << 2. << nan << nan << nan | |
55 | << std::vector<double>{0., 1., 3., 5., 7., 9., 11., 13., 14.} |
|
55 | << std::vector<double>{0., 1., 3., 5., 7., 9., 11., 13., 14.} | |
56 | << std::vector<double>{0., 1., 2., 3., nan, nan, 4., 5., 6., |
|
56 | << std::vector<double>{0., 1., 2., 3., nan, nan, 4., 5., 6., | |
57 | 7., nan, nan, nan, nan, nan, nan, 8., 9.}; |
|
57 | 7., nan, nan, nan, nan, nan, nan, 8., 9.}; | |
58 |
|
58 | |||
59 | QTest::newRow("fillDataHoles (change resolution)") |
|
59 | QTest::newRow("fillDataHoles (change resolution)") | |
60 | << std::vector<double>{0., 1., 5., 7., 14.} << std::vector<double>{0., 1., 2., 3., 4.} |
|
60 | << std::vector<double>{0., 1., 5., 7., 14.} << std::vector<double>{0., 1., 2., 3., 4.} | |
61 | << 1.5 << nan << nan << nan |
|
61 | << 1.5 << nan << nan << nan | |
62 | << std::vector<double>{0., 1., 2.5, 4., 5., 6.5, 7., 8.5, 10., 11.5, 13., 14.} |
|
62 | << std::vector<double>{0., 1., 2.5, 4., 5., 6.5, 7., 8.5, 10., 11.5, 13., 14.} | |
63 | << std::vector<double>{0., 1., nan, nan, 2., nan, 3., nan, nan, nan, nan, 4.}; |
|
63 | << std::vector<double>{0., 1., nan, nan, 2., nan, 3., nan, nan, nan, nan, 4.}; | |
64 |
|
64 | |||
65 | QTest::newRow("fillDataHoles (with no data (no changes made))") |
|
65 | QTest::newRow("fillDataHoles (with no data (no changes made))") | |
66 | << std::vector<double>{} << std::vector<double>{} << 2. << nan << nan << nan |
|
66 | << std::vector<double>{} << std::vector<double>{} << 2. << nan << nan << nan | |
67 | << std::vector<double>{} << std::vector<double>{}; |
|
67 | << std::vector<double>{} << std::vector<double>{}; | |
68 |
|
68 | |||
69 | QTest::newRow("fillDataHoles (with no resolution (no changes made))") |
|
69 | QTest::newRow("fillDataHoles (with no resolution (no changes made))") | |
70 | << std::vector<double>{0., 1., 5., 7., 14.} << std::vector<double>{0., 1., 2., 3., 4.} << 0. |
|
70 | << std::vector<double>{0., 1., 5., 7., 14.} << std::vector<double>{0., 1., 2., 3., 4.} << 0. | |
71 | << nan << nan << nan << std::vector<double>{0., 1., 5., 7., 14.} |
|
71 | << nan << nan << nan << std::vector<double>{0., 1., 5., 7., 14.} | |
72 | << std::vector<double>{0., 1., 2., 3., 4.}; |
|
72 | << std::vector<double>{0., 1., 2., 3., 4.}; | |
73 |
|
73 | |||
74 | QTest::newRow("fillDataHoles (change fill value)") |
|
74 | QTest::newRow("fillDataHoles (change fill value)") | |
75 | << std::vector<double>{0., 1., 5., 7., 14.} << std::vector<double>{0., 1., 2., 3., 4.} << 2. |
|
75 | << std::vector<double>{0., 1., 5., 7., 14.} << std::vector<double>{0., 1., 2., 3., 4.} << 2. | |
76 | << -1. << nan << nan << std::vector<double>{0., 1., 3., 5., 7., 9., 11., 13., 14.} |
|
76 | << -1. << nan << nan << std::vector<double>{0., 1., 3., 5., 7., 9., 11., 13., 14.} | |
77 | << std::vector<double>{0., 1., -1., 2., 3., -1., -1., -1., 4.}; |
|
77 | << std::vector<double>{0., 1., -1., 2., 3., -1., -1., -1., 4.}; | |
78 |
|
78 | |||
79 | QTest::newRow("fillDataHoles (add data holes to the beginning)") |
|
79 | QTest::newRow("fillDataHoles (add data holes to the beginning)") | |
80 | << std::vector<double>{5., 7., 9., 11., 13.} << std::vector<double>{0., 1., 2., 3., 4.} |
|
80 | << std::vector<double>{5., 7., 9., 11., 13.} << std::vector<double>{0., 1., 2., 3., 4.} | |
81 | << 2. << nan << 0. << nan << std::vector<double>{1., 3., 5., 7., 9., 11., 13.} |
|
81 | << 2. << nan << 0. << nan << std::vector<double>{1., 3., 5., 7., 9., 11., 13.} | |
82 | << std::vector<double>{nan, nan, 0., 1., 2., 3., 4.}; |
|
82 | << std::vector<double>{nan, nan, 0., 1., 2., 3., 4.}; | |
83 |
|
83 | |||
84 | QTest::newRow("fillDataHoles (add data holes to the end)") |
|
84 | QTest::newRow("fillDataHoles (add data holes to the end)") | |
85 | << std::vector<double>{5., 7., 9., 11., 13.} << std::vector<double>{0., 1., 2., 3., 4.} |
|
85 | << std::vector<double>{5., 7., 9., 11., 13.} << std::vector<double>{0., 1., 2., 3., 4.} | |
86 | << 2. << nan << nan << 21. << std::vector<double>{5., 7., 9., 11., 13., 15., 17., 19., 21.} |
|
86 | << 2. << nan << nan << 21. << std::vector<double>{5., 7., 9., 11., 13., 15., 17., 19., 21.} | |
87 | << std::vector<double>{0., 1., 2., 3., 4., nan, nan, nan, nan}; |
|
87 | << std::vector<double>{0., 1., 2., 3., 4., nan, nan, nan, nan}; | |
88 |
|
88 | |||
89 | QTest::newRow("fillDataHoles (invalid min/max bounds (no changes made))") |
|
89 | QTest::newRow("fillDataHoles (invalid min/max bounds (no changes made))") | |
90 | << std::vector<double>{5., 7., 9., 11., 13.} << std::vector<double>{0., 1., 2., 3., 4.} |
|
90 | << std::vector<double>{5., 7., 9., 11., 13.} << std::vector<double>{0., 1., 2., 3., 4.} | |
91 | << 2. << nan << 8. << 13. << std::vector<double>{5., 7., 9., 11., 13.} |
|
91 | << 2. << nan << 8. << 13. << std::vector<double>{5., 7., 9., 11., 13.} | |
92 | << std::vector<double>{0., 1., 2., 3., 4.}; |
|
92 | << std::vector<double>{0., 1., 2., 3., 4.}; | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | void TestDataSeriesUtils::testFillDataHoles() |
|
95 | void TestDataSeriesUtils::testFillDataHoles() | |
96 | { |
|
96 | { | |
97 | QFETCH(std::vector<double>, xAxisData); |
|
97 | QFETCH(std::vector<double>, xAxisData); | |
98 | QFETCH(std::vector<double>, valuesData); |
|
98 | QFETCH(std::vector<double>, valuesData); | |
99 | QFETCH(double, resolution); |
|
99 | QFETCH(double, resolution); | |
100 | QFETCH(double, fillValue); |
|
100 | QFETCH(double, fillValue); | |
101 | QFETCH(double, minBound); |
|
101 | QFETCH(double, minBound); | |
102 | QFETCH(double, maxBound); |
|
102 | QFETCH(double, maxBound); | |
103 |
|
103 | |||
104 | QFETCH(std::vector<double>, expectedXAxisData); |
|
104 | QFETCH(std::vector<double>, expectedXAxisData); | |
105 | QFETCH(std::vector<double>, expectedValuesData); |
|
105 | QFETCH(std::vector<double>, expectedValuesData); | |
106 |
|
106 | |||
107 | // Executes method (xAxisData and valuesData are modified) |
|
107 | // Executes method (xAxisData and valuesData are modified) | |
108 | DataSeriesUtils::fillDataHoles(xAxisData, valuesData, resolution, fillValue, minBound, |
|
108 | DataSeriesUtils::fillDataHoles(xAxisData, valuesData, resolution, fillValue, minBound, | |
109 | maxBound); |
|
109 | maxBound); | |
110 |
|
110 | |||
111 | // Checks results |
|
111 | // Checks results | |
112 | auto equal = [](const auto &data, const auto &expectedData) { |
|
112 | auto equal = [](const auto &data, const auto &expectedData) { | |
113 | // Compares with NaN values |
|
113 | // Compares with NaN values | |
114 | return std::equal(data.begin(), data.end(), expectedData.begin(), expectedData.end(), |
|
114 | return std::equal(data.begin(), data.end(), expectedData.begin(), expectedData.end(), | |
115 | [](const auto &val, const auto &expectedVal) { |
|
115 | [](const auto &val, const auto &expectedVal) { | |
116 | return (std::isnan(val) && std::isnan(expectedVal)) |
|
116 | return (std::isnan(val) && std::isnan(expectedVal)) | |
117 | || val == expectedVal; |
|
117 | || val == expectedVal; | |
118 | }); |
|
118 | }); | |
119 | }; |
|
119 | }; | |
120 | QVERIFY(equal(xAxisData, expectedXAxisData)); |
|
120 | QVERIFY(equal(xAxisData, expectedXAxisData)); | |
121 | QVERIFY(equal(valuesData, expectedValuesData)); |
|
121 | QVERIFY(equal(valuesData, expectedValuesData)); | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | namespace { |
|
124 | namespace { | |
125 |
|
125 | |||
126 | const auto LINE_SEP = QRegularExpression{QStringLiteral("\\s+")}; |
|
126 | const auto LINE_SEP = QRegularExpression{QStringLiteral("\\s+")}; | |
127 |
|
127 | |||
128 | std::vector<double> fromFile(const QString &filePath) |
|
128 | std::vector<double> fromFile(const QString &filePath) | |
129 | { |
|
129 | { | |
130 | QFile file{filePath}; |
|
130 | QFile file{filePath}; | |
131 |
|
131 | |||
132 | if (!file.open(QFile::ReadOnly | QIODevice::Text)) { |
|
132 | if (!file.open(QFile::ReadOnly | QIODevice::Text)) { | |
133 | return {}; |
|
133 | return {}; | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | std::vector<double> result{}; |
|
136 | std::vector<double> result{}; | |
137 |
|
137 | |||
138 | QTextStream stream{&file}; |
|
138 | QTextStream stream{&file}; | |
139 | QString line{}; |
|
139 | QString line{}; | |
140 |
|
140 | |||
141 | while (stream.readLineInto(&line)) { |
|
141 | while (stream.readLineInto(&line)) { | |
142 | auto lineData = line.split(LINE_SEP, QString::SkipEmptyParts); |
|
142 | auto lineData = line.split(LINE_SEP, QString::SkipEmptyParts); | |
143 |
|
143 | |||
144 | for (auto data : lineData) { |
|
144 | for (auto data : lineData) { | |
145 | bool valueOk; |
|
145 | bool valueOk; | |
146 | auto value = data.toDouble(&valueOk); |
|
146 | auto value = data.toDouble(&valueOk); | |
147 |
|
147 | |||
148 | result.push_back(valueOk ? value : std::numeric_limits<double>::quiet_NaN()); |
|
148 | result.push_back(valueOk ? value : std::numeric_limits<double>::quiet_NaN()); | |
149 | } |
|
149 | } | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | return result; |
|
152 | return result; | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | } // namespace |
|
155 | } // namespace | |
156 |
|
156 | |||
157 | void TestDataSeriesUtils::testThresholds_data() |
|
157 | void TestDataSeriesUtils::testThresholds_data() | |
158 | { |
|
158 | { | |
159 | QTest::addColumn<std::vector<double> >("input"); |
|
159 | QTest::addColumn<std::vector<double> >("input"); | |
160 | QTest::addColumn<bool>("logarithmic"); |
|
160 | QTest::addColumn<bool>("logarithmic"); | |
161 | QTest::addColumn<double>("expectedMinThreshold"); |
|
161 | QTest::addColumn<double>("expectedMinThreshold"); | |
162 | QTest::addColumn<double>("expectedMaxThreshold"); |
|
162 | QTest::addColumn<double>("expectedMaxThreshold"); | |
163 |
|
163 | |||
164 | auto nan = std::numeric_limits<double>::quiet_NaN(); |
|
164 | auto nan = std::numeric_limits<double>::quiet_NaN(); | |
165 |
|
165 | |||
166 | QTest::newRow("thresholds (basic case)") |
|
166 | QTest::newRow("thresholds (basic case)") | |
167 | << std::vector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.} << false << 1. << 10.; |
|
167 | << std::vector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.} << false << 1. << 10.; | |
168 |
|
168 | |||
169 | QTest::newRow("thresholds (with nan values)") |
|
169 | QTest::newRow("thresholds (with nan values)") | |
170 | << std::vector<double>{nan, 2., 3., 4., 5., 6., 7., 8., 9., nan} << false << 2. << 9.; |
|
170 | << std::vector<double>{nan, 2., 3., 4., 5., 6., 7., 8., 9., nan} << false << 2. << 9.; | |
171 |
|
171 | |||
172 | QTest::newRow("thresholds (case with low values and aberrant value)") |
|
172 | QTest::newRow("thresholds (case with low values and aberrant value)") | |
173 | << std::vector<double>{1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 2., |
|
173 | << std::vector<double>{1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 2., | |
174 | 2., 2., 2., 2., 2., 2., 2., 2., 2., 2., 2., 2., 2., 2., 3., 3., |
|
174 | 2., 2., 2., 2., 2., 2., 2., 2., 2., 2., 2., 2., 2., 2., 3., 3., | |
175 | 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 100.} |
|
175 | 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 100.} | |
176 | << false << 1. << 47.073; |
|
176 | << false << 1. << 47.073; | |
177 |
|
177 | |||
178 | QTest::newRow("thresholds (empty data)") << std::vector<double>{} << false << nan << nan; |
|
178 | QTest::newRow("thresholds (empty data)") << std::vector<double>{} << false << nan << nan; | |
179 | QTest::newRow("thresholds (only nan values)") |
|
179 | QTest::newRow("thresholds (only nan values)") << std::vector<double>{nan, nan, nan, nan, nan} | |
180 | << std::vector<double>{nan, nan, nan, nan, nan} << false << nan << nan; |
|
180 | << false << nan << nan; | |
181 |
|
181 | |||
182 | QTest::newRow("thresholds (from file with logarithmic scale)") |
|
182 | QTest::newRow("thresholds (from file with logarithmic scale)") | |
183 | << fromFile(inputFilePath("TestThresholds.txt")) << true << 832.005 << 17655064.730; |
|
183 | << fromFile(inputFilePath("TestThresholds.txt")) << true << 832.005 << 17655064.730; | |
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 | void TestDataSeriesUtils::testThresholds() |
|
186 | void TestDataSeriesUtils::testThresholds() | |
187 | { |
|
187 | { | |
188 | QFETCH(std::vector<double>, input); |
|
188 | QFETCH(std::vector<double>, input); | |
189 | QFETCH(bool, logarithmic); |
|
189 | QFETCH(bool, logarithmic); | |
190 | QFETCH(double, expectedMinThreshold); |
|
190 | QFETCH(double, expectedMinThreshold); | |
191 | QFETCH(double, expectedMaxThreshold); |
|
191 | QFETCH(double, expectedMaxThreshold); | |
192 |
|
192 | |||
193 | double minThreshold, maxThreshold; |
|
193 | double minThreshold, maxThreshold; | |
194 | std::tie(minThreshold, maxThreshold) |
|
194 | std::tie(minThreshold, maxThreshold) | |
195 | = DataSeriesUtils::thresholds(input.begin(), input.end(), logarithmic); |
|
195 | = DataSeriesUtils::thresholds(input.begin(), input.end(), logarithmic); | |
196 |
|
196 | |||
197 | auto compareWithNaN = [](const auto &v1, const auto &v2) { |
|
197 | auto compareWithNaN = [](const auto &v1, const auto &v2) { | |
198 | return (std::isnan(v1) && std::isnan(v2)) || std::abs(v1 - v2) < 1e-3; |
|
198 | return (std::isnan(v1) && std::isnan(v2)) || std::abs(v1 - v2) < 1e-3; | |
199 | }; |
|
199 | }; | |
200 |
|
200 | |||
201 | QVERIFY(compareWithNaN(minThreshold, expectedMinThreshold)); |
|
201 | QVERIFY(compareWithNaN(minThreshold, expectedMinThreshold)); | |
202 | QVERIFY(compareWithNaN(maxThreshold, expectedMaxThreshold)); |
|
202 | QVERIFY(compareWithNaN(maxThreshold, expectedMaxThreshold)); | |
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 | QTEST_MAIN(TestDataSeriesUtils) |
|
205 | QTEST_MAIN(TestDataSeriesUtils) | |
206 | #include "TestDataSeriesUtils.moc" |
|
206 | #include "TestDataSeriesUtils.moc" |
@@ -1,46 +1,68 | |||||
1 | #ifndef SCIQLOP_CATALOGUEEVENTSMODEL_H |
|
1 | #ifndef SCIQLOP_CATALOGUEEVENTSMODEL_H | |
2 | #define SCIQLOP_CATALOGUEEVENTSMODEL_H |
|
2 | #define SCIQLOP_CATALOGUEEVENTSMODEL_H | |
3 |
|
3 | |||
4 | #include <Common/spimpl.h> |
|
4 | #include <Common/spimpl.h> | |
5 | #include <QAbstractItemModel> |
|
5 | #include <QAbstractItemModel> | |
|
6 | #include <QLoggingCategory> | |||
|
7 | #include <unordered_set> | |||
6 |
|
8 | |||
7 | class DBEvent; |
|
9 | class DBEvent; | |
8 | class DBEventProduct; |
|
10 | class DBEventProduct; | |
9 |
|
11 | |||
|
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueEventsModel) | |||
|
13 | ||||
10 | class CatalogueEventsModel : public QAbstractItemModel { |
|
14 | class CatalogueEventsModel : public QAbstractItemModel { | |
|
15 | Q_OBJECT | |||
|
16 | ||||
|
17 | signals: | |||
|
18 | void modelSorted(); | |||
|
19 | ||||
11 | public: |
|
20 | public: | |
12 | CatalogueEventsModel(QObject *parent = nullptr); |
|
21 | CatalogueEventsModel(QObject *parent = nullptr); | |
13 |
|
22 | |||
|
23 | enum class Column { Name, TStart, TEnd, Tags, Product, Validation, NbColumn }; | |||
|
24 | ||||
14 | void setEvents(const QVector<std::shared_ptr<DBEvent> > &events); |
|
25 | void setEvents(const QVector<std::shared_ptr<DBEvent> > &events); | |
15 | void addEvent(const std::shared_ptr<DBEvent> &event); |
|
26 | void addEvent(const std::shared_ptr<DBEvent> &event); | |
16 | void removeEvent(const std::shared_ptr<DBEvent> &event); |
|
27 | void removeEvent(const std::shared_ptr<DBEvent> &event); | |
|
28 | QVector<std::shared_ptr<DBEvent> > events() const; | |||
17 |
|
29 | |||
18 | enum class ItemType { Root, Event, EventProduct }; |
|
30 | enum class ItemType { Root, Event, EventProduct }; | |
19 | ItemType itemTypeOf(const QModelIndex &index) const; |
|
31 | ItemType itemTypeOf(const QModelIndex &index) const; | |
20 | std::shared_ptr<DBEvent> getEvent(const QModelIndex &index) const; |
|
32 | std::shared_ptr<DBEvent> getEvent(const QModelIndex &index) const; | |
21 | std::shared_ptr<DBEvent> getParentEvent(const QModelIndex &index) const; |
|
33 | std::shared_ptr<DBEvent> getParentEvent(const QModelIndex &index) const; | |
22 | std::shared_ptr<DBEventProduct> getEventProduct(const QModelIndex &index) const; |
|
34 | std::shared_ptr<DBEventProduct> getEventProduct(const QModelIndex &index) const; | |
23 |
|
35 | |||
|
36 | /// Refresh the data for the specified event | |||
24 | void refreshEvent(const std::shared_ptr<DBEvent> &event); |
|
37 | void refreshEvent(const std::shared_ptr<DBEvent> &event); | |
25 |
|
38 | |||
|
39 | /// Returns a QModelIndex which represent the specified event | |||
|
40 | QModelIndex indexOf(const std::shared_ptr<DBEvent> &event) const; | |||
|
41 | ||||
|
42 | /// Marks a change flag on the specified event to allow sorting on the validation column | |||
|
43 | void setEventHasChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges); | |||
|
44 | ||||
|
45 | /// Returns true if the specified event has unsaved changes | |||
|
46 | bool eventsHasChanges(const std::shared_ptr<DBEvent> &event) const; | |||
|
47 | ||||
26 | // Model |
|
48 | // Model | |
27 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; |
|
49 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; | |
28 | QModelIndex parent(const QModelIndex &index) const; |
|
50 | QModelIndex parent(const QModelIndex &index) const; | |
29 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
|
51 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; | |
30 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; |
|
52 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; | |
31 | Qt::ItemFlags flags(const QModelIndex &index) const override; |
|
53 | Qt::ItemFlags flags(const QModelIndex &index) const override; | |
32 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
|
54 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | |
33 | QVariant headerData(int section, Qt::Orientation orientation, |
|
55 | QVariant headerData(int section, Qt::Orientation orientation, | |
34 | int role = Qt::DisplayRole) const override; |
|
56 | int role = Qt::DisplayRole) const override; | |
35 | void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override; |
|
57 | void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override; | |
36 |
|
58 | |||
37 | Qt::DropActions supportedDragActions() const override; |
|
59 | Qt::DropActions supportedDragActions() const override; | |
38 | QStringList mimeTypes() const override; |
|
60 | QStringList mimeTypes() const override; | |
39 | QMimeData *mimeData(const QModelIndexList &indexes) const override; |
|
61 | QMimeData *mimeData(const QModelIndexList &indexes) const override; | |
40 |
|
62 | |||
41 | private: |
|
63 | private: | |
42 | class CatalogueEventsModelPrivate; |
|
64 | class CatalogueEventsModelPrivate; | |
43 | spimpl::unique_impl_ptr<CatalogueEventsModelPrivate> impl; |
|
65 | spimpl::unique_impl_ptr<CatalogueEventsModelPrivate> impl; | |
44 | }; |
|
66 | }; | |
45 |
|
67 | |||
46 | #endif // SCIQLOP_CATALOGUEEVENTSMODEL_H |
|
68 | #endif // SCIQLOP_CATALOGUEEVENTSMODEL_H |
@@ -1,47 +1,48 | |||||
1 | #ifndef SCIQLOP_CATALOGUEEVENTSWIDGET_H |
|
1 | #ifndef SCIQLOP_CATALOGUEEVENTSWIDGET_H | |
2 | #define SCIQLOP_CATALOGUEEVENTSWIDGET_H |
|
2 | #define SCIQLOP_CATALOGUEEVENTSWIDGET_H | |
3 |
|
3 | |||
4 | #include <Common/spimpl.h> |
|
4 | #include <Common/spimpl.h> | |
5 | #include <QLoggingCategory> |
|
5 | #include <QLoggingCategory> | |
6 | #include <QWidget> |
|
6 | #include <QWidget> | |
7 |
|
7 | |||
8 | class DBCatalogue; |
|
8 | class DBCatalogue; | |
9 | class DBEvent; |
|
9 | class DBEvent; | |
10 | class DBEventProduct; |
|
10 | class DBEventProduct; | |
11 | class VisualizationWidget; |
|
11 | class VisualizationWidget; | |
12 |
|
12 | |||
13 | namespace Ui { |
|
13 | namespace Ui { | |
14 | class CatalogueEventsWidget; |
|
14 | class CatalogueEventsWidget; | |
15 | } |
|
15 | } | |
16 |
|
16 | |||
17 | Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueEventsWidget) |
|
17 | Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueEventsWidget) | |
18 |
|
18 | |||
19 | class CatalogueEventsWidget : public QWidget { |
|
19 | class CatalogueEventsWidget : public QWidget { | |
20 | Q_OBJECT |
|
20 | Q_OBJECT | |
21 |
|
21 | |||
22 | signals: |
|
22 | signals: | |
23 | void eventsSelected(const QVector<std::shared_ptr<DBEvent> > &event); |
|
23 | void eventsSelected(const QVector<std::shared_ptr<DBEvent> > &event); | |
24 | void eventProductsSelected( |
|
24 | void eventProductsSelected( | |
25 | const QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > |
|
25 | const QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > | |
26 | &eventproducts); |
|
26 | &eventproducts); | |
27 | void selectionCleared(); |
|
27 | void selectionCleared(); | |
28 |
|
28 | |||
29 | public: |
|
29 | public: | |
30 | explicit CatalogueEventsWidget(QWidget *parent = 0); |
|
30 | explicit CatalogueEventsWidget(QWidget *parent = 0); | |
31 | virtual ~CatalogueEventsWidget(); |
|
31 | virtual ~CatalogueEventsWidget(); | |
32 |
|
32 | |||
33 | void setVisualizationWidget(VisualizationWidget *visualization); |
|
33 | void setVisualizationWidget(VisualizationWidget *visualization); | |
34 |
|
34 | |||
35 | void setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges); |
|
35 | void setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges); | |
36 |
|
36 | |||
37 | public slots: |
|
37 | public slots: | |
38 | void populateWithCatalogues(const QVector<std::shared_ptr<DBCatalogue> > &catalogues); |
|
38 | void populateWithCatalogues(const QVector<std::shared_ptr<DBCatalogue> > &catalogues); | |
|
39 | void populateWithAllEvents(); | |||
39 |
|
40 | |||
40 | private: |
|
41 | private: | |
41 | Ui::CatalogueEventsWidget *ui; |
|
42 | Ui::CatalogueEventsWidget *ui; | |
42 |
|
43 | |||
43 | class CatalogueEventsWidgetPrivate; |
|
44 | class CatalogueEventsWidgetPrivate; | |
44 | spimpl::unique_impl_ptr<CatalogueEventsWidgetPrivate> impl; |
|
45 | spimpl::unique_impl_ptr<CatalogueEventsWidgetPrivate> impl; | |
45 | }; |
|
46 | }; | |
46 |
|
47 | |||
47 | #endif // SCIQLOP_CATALOGUEEVENTSWIDGET_H |
|
48 | #endif // SCIQLOP_CATALOGUEEVENTSWIDGET_H |
@@ -1,33 +1,36 | |||||
1 | #ifndef SCIQLOP_CATALOGUETREEWIDGETITEM_H |
|
1 | #ifndef SCIQLOP_CATALOGUETREEWIDGETITEM_H | |
2 | #define SCIQLOP_CATALOGUETREEWIDGETITEM_H |
|
2 | #define SCIQLOP_CATALOGUETREEWIDGETITEM_H | |
3 |
|
3 | |||
4 | #include <Common/spimpl.h> |
|
4 | #include <Common/spimpl.h> | |
5 | #include <QTreeWidgetItem> |
|
5 | #include <QTreeWidgetItem> | |
6 |
|
6 | |||
7 | class DBCatalogue; |
|
7 | class DBCatalogue; | |
8 |
|
8 | |||
9 |
|
9 | |||
10 | class CatalogueTreeWidgetItem : public QTreeWidgetItem { |
|
10 | class CatalogueTreeWidgetItem : public QTreeWidgetItem { | |
11 | public: |
|
11 | public: | |
12 | CatalogueTreeWidgetItem(std::shared_ptr<DBCatalogue> catalogue, |
|
12 | CatalogueTreeWidgetItem(std::shared_ptr<DBCatalogue> catalogue, | |
13 | int type = QTreeWidgetItem::Type); |
|
13 | int type = QTreeWidgetItem::Type); | |
14 |
|
14 | |||
15 | QVariant data(int column, int role) const override; |
|
15 | QVariant data(int column, int role) const override; | |
16 | void setData(int column, int role, const QVariant &value) override; |
|
16 | void setData(int column, int role, const QVariant &value) override; | |
17 |
|
17 | |||
18 | /// Returns the catalogue represented by the item |
|
18 | /// Returns the catalogue represented by the item | |
19 | std::shared_ptr<DBCatalogue> catalogue() const; |
|
19 | std::shared_ptr<DBCatalogue> catalogue() const; | |
20 |
|
20 | |||
21 | /// Displays or hides the save and cancel buttons indicating that the catalogue has unsaved |
|
21 | /// Displays or hides the save and cancel buttons indicating that the catalogue has unsaved | |
22 | /// changes |
|
22 | /// changes | |
23 | void setHasChanges(bool value); |
|
23 | void setHasChanges(bool value); | |
24 |
|
24 | |||
|
25 | /// Returns true if the widget indicating the event has unsaved changes is displayed | |||
|
26 | bool hasChanges(); | |||
|
27 | ||||
25 | /// Refreshes the data displayed by the item from the catalogue |
|
28 | /// Refreshes the data displayed by the item from the catalogue | |
26 | void refresh(); |
|
29 | void refresh(); | |
27 |
|
30 | |||
28 | private: |
|
31 | private: | |
29 | class CatalogueTreeWidgetItemPrivate; |
|
32 | class CatalogueTreeWidgetItemPrivate; | |
30 | spimpl::unique_impl_ptr<CatalogueTreeWidgetItemPrivate> impl; |
|
33 | spimpl::unique_impl_ptr<CatalogueTreeWidgetItemPrivate> impl; | |
31 | }; |
|
34 | }; | |
32 |
|
35 | |||
33 | #endif // SCIQLOP_CATALOGUETREEWIDGETITEM_H |
|
36 | #endif // SCIQLOP_CATALOGUETREEWIDGETITEM_H |
@@ -1,127 +1,143 | |||||
1 |
|
||||
2 | qxorm_dep = dependency('QxOrm', required : true, fallback:['QxOrm','qxorm_dep']) |
|
1 | qxorm_dep = dependency('QxOrm', required : true, fallback:['QxOrm','qxorm_dep']) | |
3 | catalogueapi_dep = dependency('CatalogueAPI', required : true, fallback:['CatalogueAPI','CatalogueAPI_dep']) |
|
2 | catalogueapi_dep = dependency('CatalogueAPI', required : true, fallback:['CatalogueAPI','CatalogueAPI_dep']) | |
4 |
|
3 | |||
5 | gui_moc_headers = [ |
|
4 | gui_moc_headers = [ | |
6 | 'include/DataSource/DataSourceWidget.h', |
|
5 | 'include/DataSource/DataSourceWidget.h', | |
7 | 'include/Settings/SqpSettingsDialog.h', |
|
6 | 'include/Settings/SqpSettingsDialog.h', | |
8 | 'include/Settings/SqpSettingsGeneralWidget.h', |
|
7 | 'include/Settings/SqpSettingsGeneralWidget.h', | |
9 | 'include/SidePane/SqpSidePane.h', |
|
8 | 'include/SidePane/SqpSidePane.h', | |
10 | 'include/SqpApplication.h', |
|
9 | 'include/SqpApplication.h', | |
11 | 'include/DragAndDrop/DragDropScroller.h', |
|
10 | 'include/DragAndDrop/DragDropScroller.h', | |
12 | 'include/DragAndDrop/DragDropTabSwitcher.h', |
|
11 | 'include/DragAndDrop/DragDropTabSwitcher.h', | |
13 | 'include/TimeWidget/TimeWidget.h', |
|
12 | 'include/TimeWidget/TimeWidget.h', | |
14 | 'include/Variable/VariableInspectorWidget.h', |
|
13 | 'include/Variable/VariableInspectorWidget.h', | |
15 | 'include/Variable/RenameVariableDialog.h', |
|
14 | 'include/Variable/RenameVariableDialog.h', | |
16 | 'include/Visualization/qcustomplot.h', |
|
15 | 'include/Visualization/qcustomplot.h', | |
17 | 'include/Visualization/VisualizationGraphWidget.h', |
|
16 | 'include/Visualization/VisualizationGraphWidget.h', | |
18 | 'include/Visualization/VisualizationTabWidget.h', |
|
17 | 'include/Visualization/VisualizationTabWidget.h', | |
19 | 'include/Visualization/VisualizationWidget.h', |
|
18 | 'include/Visualization/VisualizationWidget.h', | |
20 | 'include/Visualization/VisualizationZoneWidget.h', |
|
19 | 'include/Visualization/VisualizationZoneWidget.h', | |
21 | 'include/Visualization/VisualizationDragDropContainer.h', |
|
20 | 'include/Visualization/VisualizationDragDropContainer.h', | |
22 | 'include/Visualization/VisualizationDragWidget.h', |
|
21 | 'include/Visualization/VisualizationDragWidget.h', | |
23 | 'include/Visualization/ColorScaleEditor.h', |
|
22 | 'include/Visualization/ColorScaleEditor.h', | |
24 | 'include/Actions/SelectionZoneAction.h', |
|
23 | 'include/Actions/SelectionZoneAction.h', | |
25 | 'include/Visualization/VisualizationMultiZoneSelectionDialog.h', |
|
24 | 'include/Visualization/VisualizationMultiZoneSelectionDialog.h', | |
26 | 'include/Catalogue/CatalogueExplorer.h', |
|
25 | 'include/Catalogue/CatalogueExplorer.h', | |
27 | 'include/Catalogue/CatalogueEventsWidget.h', |
|
26 | 'include/Catalogue/CatalogueEventsWidget.h', | |
28 | 'include/Catalogue/CatalogueSideBarWidget.h', |
|
27 | 'include/Catalogue/CatalogueSideBarWidget.h', | |
29 | 'include/Catalogue/CatalogueInspectorWidget.h' |
|
28 | 'include/Catalogue/CatalogueInspectorWidget.h', | |
|
29 | 'include/Catalogue/CatalogueEventsModel.h', | |||
|
30 | 'include/Catalogue/CreateEventDialog.h' | |||
30 | ] |
|
31 | ] | |
31 |
|
32 | |||
32 | gui_ui_files = [ |
|
33 | gui_ui_files = [ | |
33 | 'ui/DataSource/DataSourceWidget.ui', |
|
34 | 'ui/DataSource/DataSourceWidget.ui', | |
34 | 'ui/Settings/SqpSettingsDialog.ui', |
|
35 | 'ui/Settings/SqpSettingsDialog.ui', | |
35 | 'ui/Settings/SqpSettingsGeneralWidget.ui', |
|
36 | 'ui/Settings/SqpSettingsGeneralWidget.ui', | |
36 | 'ui/SidePane/SqpSidePane.ui', |
|
37 | 'ui/SidePane/SqpSidePane.ui', | |
37 | 'ui/TimeWidget/TimeWidget.ui', |
|
38 | 'ui/TimeWidget/TimeWidget.ui', | |
38 | 'ui/Variable/VariableInspectorWidget.ui', |
|
39 | 'ui/Variable/VariableInspectorWidget.ui', | |
39 | 'ui/Variable/RenameVariableDialog.ui', |
|
40 | 'ui/Variable/RenameVariableDialog.ui', | |
40 | 'ui/Variable/VariableMenuHeaderWidget.ui', |
|
41 | 'ui/Variable/VariableMenuHeaderWidget.ui', | |
41 | 'ui/Visualization/VisualizationGraphWidget.ui', |
|
42 | 'ui/Visualization/VisualizationGraphWidget.ui', | |
42 | 'ui/Visualization/VisualizationTabWidget.ui', |
|
43 | 'ui/Visualization/VisualizationTabWidget.ui', | |
43 | 'ui/Visualization/VisualizationWidget.ui', |
|
44 | 'ui/Visualization/VisualizationWidget.ui', | |
44 | 'ui/Visualization/VisualizationZoneWidget.ui', |
|
45 | 'ui/Visualization/VisualizationZoneWidget.ui', | |
45 | 'ui/Visualization/ColorScaleEditor.ui', |
|
46 | 'ui/Visualization/ColorScaleEditor.ui', | |
46 | 'ui/Visualization/VisualizationMultiZoneSelectionDialog.ui', |
|
47 | 'ui/Visualization/VisualizationMultiZoneSelectionDialog.ui', | |
47 | 'ui/Catalogue/CatalogueExplorer.ui', |
|
48 | 'ui/Catalogue/CatalogueExplorer.ui', | |
48 | 'ui/Catalogue/CatalogueEventsWidget.ui', |
|
49 | 'ui/Catalogue/CatalogueEventsWidget.ui', | |
49 | 'ui/Catalogue/CatalogueSideBarWidget.ui', |
|
50 | 'ui/Catalogue/CatalogueSideBarWidget.ui', | |
50 | 'ui/Catalogue/CatalogueInspectorWidget.ui' |
|
51 | 'ui/Catalogue/CatalogueInspectorWidget.ui', | |
|
52 | 'ui/Catalogue/CreateEventDialog.ui' | |||
51 | ] |
|
53 | ] | |
52 |
|
54 | |||
53 | gui_qresources = ['resources/sqpguiresources.qrc'] |
|
55 | gui_qresources = ['resources/sqpguiresources.qrc'] | |
54 |
|
56 | |||
|
57 | rcc_gen = generator(rcc, | |||
|
58 | output : 'qrc_@BASENAME@.cpp', | |||
|
59 | arguments : [ | |||
|
60 | '--output', | |||
|
61 | '@OUTPUT@', | |||
|
62 | '@INPUT@', | |||
|
63 | '@EXTRA_ARGS@']) | |||
|
64 | ||||
|
65 | rcc_files = rcc_gen.process(gui_qresources, extra_args : ['-name', 'sqpguiresources']) | |||
|
66 | ||||
55 | gui_moc_files = qt5.preprocess(moc_headers : gui_moc_headers, |
|
67 | gui_moc_files = qt5.preprocess(moc_headers : gui_moc_headers, | |
56 |
ui_files : gui_ui_files |
|
68 | ui_files : gui_ui_files) | |
57 | qresources : gui_qresources) |
|
|||
58 |
|
69 | |||
59 | gui_sources = [ |
|
70 | gui_sources = [ | |
60 | 'src/SqpApplication.cpp', |
|
71 | 'src/SqpApplication.cpp', | |
61 | 'src/DragAndDrop/DragDropGuiController.cpp', |
|
72 | 'src/DragAndDrop/DragDropGuiController.cpp', | |
62 | 'src/DragAndDrop/DragDropScroller.cpp', |
|
73 | 'src/DragAndDrop/DragDropScroller.cpp', | |
63 | 'src/DragAndDrop/DragDropTabSwitcher.cpp', |
|
74 | 'src/DragAndDrop/DragDropTabSwitcher.cpp', | |
64 | 'src/Common/ColorUtils.cpp', |
|
75 | 'src/Common/ColorUtils.cpp', | |
65 | 'src/Common/VisualizationDef.cpp', |
|
76 | 'src/Common/VisualizationDef.cpp', | |
66 | 'src/DataSource/DataSourceTreeWidgetItem.cpp', |
|
77 | 'src/DataSource/DataSourceTreeWidgetItem.cpp', | |
67 | 'src/DataSource/DataSourceTreeWidgetHelper.cpp', |
|
78 | 'src/DataSource/DataSourceTreeWidgetHelper.cpp', | |
68 | 'src/DataSource/DataSourceWidget.cpp', |
|
79 | 'src/DataSource/DataSourceWidget.cpp', | |
69 | 'src/DataSource/DataSourceTreeWidget.cpp', |
|
80 | 'src/DataSource/DataSourceTreeWidget.cpp', | |
70 | 'src/Settings/SqpSettingsDialog.cpp', |
|
81 | 'src/Settings/SqpSettingsDialog.cpp', | |
71 | 'src/Settings/SqpSettingsGeneralWidget.cpp', |
|
82 | 'src/Settings/SqpSettingsGeneralWidget.cpp', | |
72 | 'src/SidePane/SqpSidePane.cpp', |
|
83 | 'src/SidePane/SqpSidePane.cpp', | |
73 | 'src/TimeWidget/TimeWidget.cpp', |
|
84 | 'src/TimeWidget/TimeWidget.cpp', | |
74 | 'src/Variable/VariableInspectorWidget.cpp', |
|
85 | 'src/Variable/VariableInspectorWidget.cpp', | |
75 | 'src/Variable/VariableInspectorTableView.cpp', |
|
86 | 'src/Variable/VariableInspectorTableView.cpp', | |
76 | 'src/Variable/VariableMenuHeaderWidget.cpp', |
|
87 | 'src/Variable/VariableMenuHeaderWidget.cpp', | |
77 | 'src/Variable/RenameVariableDialog.cpp', |
|
88 | 'src/Variable/RenameVariableDialog.cpp', | |
78 | 'src/Visualization/VisualizationGraphHelper.cpp', |
|
89 | 'src/Visualization/VisualizationGraphHelper.cpp', | |
79 | 'src/Visualization/VisualizationGraphRenderingDelegate.cpp', |
|
90 | 'src/Visualization/VisualizationGraphRenderingDelegate.cpp', | |
80 | 'src/Visualization/VisualizationGraphWidget.cpp', |
|
91 | 'src/Visualization/VisualizationGraphWidget.cpp', | |
81 | 'src/Visualization/VisualizationTabWidget.cpp', |
|
92 | 'src/Visualization/VisualizationTabWidget.cpp', | |
82 | 'src/Visualization/VisualizationWidget.cpp', |
|
93 | 'src/Visualization/VisualizationWidget.cpp', | |
83 | 'src/Visualization/VisualizationZoneWidget.cpp', |
|
94 | 'src/Visualization/VisualizationZoneWidget.cpp', | |
84 | 'src/Visualization/qcustomplot.cpp', |
|
95 | 'src/Visualization/qcustomplot.cpp', | |
85 | 'src/Visualization/QCustomPlotSynchronizer.cpp', |
|
96 | 'src/Visualization/QCustomPlotSynchronizer.cpp', | |
86 | 'src/Visualization/operations/FindVariableOperation.cpp', |
|
97 | 'src/Visualization/operations/FindVariableOperation.cpp', | |
87 | 'src/Visualization/operations/GenerateVariableMenuOperation.cpp', |
|
98 | 'src/Visualization/operations/GenerateVariableMenuOperation.cpp', | |
88 | 'src/Visualization/operations/MenuBuilder.cpp', |
|
99 | 'src/Visualization/operations/MenuBuilder.cpp', | |
89 | 'src/Visualization/operations/RemoveVariableOperation.cpp', |
|
100 | 'src/Visualization/operations/RemoveVariableOperation.cpp', | |
90 | 'src/Visualization/operations/RescaleAxeOperation.cpp', |
|
101 | 'src/Visualization/operations/RescaleAxeOperation.cpp', | |
91 | 'src/Visualization/VisualizationDragDropContainer.cpp', |
|
102 | 'src/Visualization/VisualizationDragDropContainer.cpp', | |
92 | 'src/Visualization/VisualizationDragWidget.cpp', |
|
103 | 'src/Visualization/VisualizationDragWidget.cpp', | |
93 | 'src/Visualization/AxisRenderingUtils.cpp', |
|
104 | 'src/Visualization/AxisRenderingUtils.cpp', | |
94 | 'src/Visualization/PlottablesRenderingUtils.cpp', |
|
105 | 'src/Visualization/PlottablesRenderingUtils.cpp', | |
95 | 'src/Visualization/MacScrollBarStyle.cpp', |
|
106 | 'src/Visualization/MacScrollBarStyle.cpp', | |
96 | 'src/Visualization/VisualizationCursorItem.cpp', |
|
107 | 'src/Visualization/VisualizationCursorItem.cpp', | |
97 | 'src/Visualization/ColorScaleEditor.cpp', |
|
108 | 'src/Visualization/ColorScaleEditor.cpp', | |
98 | 'src/Visualization/SqpColorScale.cpp', |
|
109 | 'src/Visualization/SqpColorScale.cpp', | |
99 | 'src/Visualization/QCPColorMapIterator.cpp', |
|
110 | 'src/Visualization/QCPColorMapIterator.cpp', | |
100 | 'src/Visualization/VisualizationSelectionZoneItem.cpp', |
|
111 | 'src/Visualization/VisualizationSelectionZoneItem.cpp', | |
101 | 'src/Visualization/VisualizationSelectionZoneManager.cpp', |
|
112 | 'src/Visualization/VisualizationSelectionZoneManager.cpp', | |
102 | 'src/Actions/SelectionZoneAction.cpp', |
|
113 | 'src/Actions/SelectionZoneAction.cpp', | |
103 | 'src/Actions/ActionsGuiController.cpp', |
|
114 | 'src/Actions/ActionsGuiController.cpp', | |
104 | 'src/Visualization/VisualizationActionManager.cpp', |
|
115 | 'src/Visualization/VisualizationActionManager.cpp', | |
105 | 'src/Visualization/VisualizationMultiZoneSelectionDialog.cpp', |
|
116 | 'src/Visualization/VisualizationMultiZoneSelectionDialog.cpp', | |
106 | 'src/Catalogue/CatalogueExplorer.cpp', |
|
117 | 'src/Catalogue/CatalogueExplorer.cpp', | |
107 | 'src/Catalogue/CatalogueEventsWidget.cpp', |
|
118 | 'src/Catalogue/CatalogueEventsWidget.cpp', | |
108 | 'src/Catalogue/CatalogueSideBarWidget.cpp', |
|
119 | 'src/Catalogue/CatalogueSideBarWidget.cpp', | |
109 | 'src/Catalogue/CatalogueInspectorWidget.cpp', |
|
120 | 'src/Catalogue/CatalogueInspectorWidget.cpp', | |
110 | 'src/Catalogue/CatalogueTreeWidgetItem.cpp', |
|
121 | 'src/Catalogue/CatalogueTreeWidgetItem.cpp', | |
111 | 'src/Catalogue/CatalogueEventsModel.cpp' |
|
122 | 'src/Catalogue/CatalogueEventsModel.cpp', | |
|
123 | 'src/Catalogue/CatalogueExplorerHelper.cpp', | |||
|
124 | 'src/Catalogue/CatalogueActionManager.cpp', | |||
|
125 | 'src/Catalogue/CreateEventDialog.cpp' | |||
112 | ] |
|
126 | ] | |
113 |
|
127 | |||
114 | gui_inc = include_directories(['include']) |
|
128 | gui_inc = include_directories(['include']) | |
115 |
|
129 | |||
116 | sciqlop_gui_lib = library('sciqlopgui', |
|
130 | sciqlop_gui_lib = library('sciqlopgui', | |
117 | gui_sources, |
|
131 | gui_sources, | |
118 | gui_moc_files, |
|
132 | gui_moc_files, | |
|
133 | rcc_files, | |||
119 | include_directories : [gui_inc], |
|
134 | include_directories : [gui_inc], | |
120 | dependencies : [ qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core, catalogueapi_dep], |
|
135 | dependencies : [ qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core, catalogueapi_dep], | |
121 | install : true |
|
136 | install : true | |
122 | ) |
|
137 | ) | |
123 |
|
138 | |||
124 | sciqlop_gui = declare_dependency(link_with : sciqlop_gui_lib, |
|
139 | sciqlop_gui = declare_dependency(link_with : sciqlop_gui_lib, | |
125 | include_directories : gui_inc, |
|
140 | include_directories : gui_inc, | |
126 | dependencies : [qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core, catalogueapi_dep]) |
|
141 | dependencies : [qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core, catalogueapi_dep]) | |
127 |
|
142 | |||
|
143 |
@@ -1,381 +1,442 | |||||
1 | #include "Catalogue/CatalogueEventsModel.h" |
|
1 | #include "Catalogue/CatalogueEventsModel.h" | |
2 |
|
2 | |||
3 | #include <Common/DateUtils.h> |
|
3 | #include <Common/DateUtils.h> | |
4 | #include <Common/MimeTypesDef.h> |
|
4 | #include <Common/MimeTypesDef.h> | |
5 | #include <DBEvent.h> |
|
5 | #include <DBEvent.h> | |
6 | #include <DBEventProduct.h> |
|
6 | #include <DBEventProduct.h> | |
7 | #include <DBTag.h> |
|
7 | #include <DBTag.h> | |
8 | #include <Data/SqpRange.h> |
|
8 | #include <Data/SqpRange.h> | |
9 | #include <SqpApplication.h> |
|
9 | #include <SqpApplication.h> | |
10 | #include <Time/TimeController.h> |
|
10 | #include <Time/TimeController.h> | |
11 |
|
11 | |||
12 | #include <list> |
|
12 | #include <list> | |
13 | #include <unordered_map> |
|
13 | #include <unordered_map> | |
14 |
|
14 | |||
15 | #include <QHash> |
|
15 | #include <QHash> | |
16 | #include <QMimeData> |
|
16 | #include <QMimeData> | |
17 |
|
17 | |||
|
18 | Q_LOGGING_CATEGORY(LOG_CatalogueEventsModel, "CatalogueEventsModel") | |||
|
19 | ||||
18 | const auto EVENT_ITEM_TYPE = 1; |
|
20 | const auto EVENT_ITEM_TYPE = 1; | |
19 | const auto EVENT_PRODUCT_ITEM_TYPE = 2; |
|
21 | const auto EVENT_PRODUCT_ITEM_TYPE = 2; | |
20 |
|
22 | |||
21 | struct CatalogueEventsModel::CatalogueEventsModelPrivate { |
|
23 | struct CatalogueEventsModel::CatalogueEventsModelPrivate { | |
22 | QVector<std::shared_ptr<DBEvent> > m_Events; |
|
24 | QVector<std::shared_ptr<DBEvent> > m_Events; | |
23 | std::unordered_map<DBEvent *, QVector<std::shared_ptr<DBEventProduct> > > m_EventProducts; |
|
25 | std::unordered_map<DBEvent *, QVector<std::shared_ptr<DBEventProduct> > > m_EventProducts; | |
|
26 | std::unordered_set<std::shared_ptr<DBEvent> > m_EventsWithChanges; | |||
24 |
|
27 | |||
25 | enum class Column { Name, TStart, TEnd, Tags, Product, NbColumn }; |
|
|||
26 | QStringList columnNames() |
|
28 | QStringList columnNames() | |
27 | { |
|
29 | { | |
28 |
return QStringList{tr("Event"), tr("TStart"), tr("TEnd"), |
|
30 | return QStringList{tr("Event"), tr("TStart"), tr("TEnd"), | |
|
31 | tr("Tags"), tr("Product"), tr("")}; | |||
|
32 | } | |||
|
33 | ||||
|
34 | QVariant sortData(int col, const std::shared_ptr<DBEvent> &event) const | |||
|
35 | { | |||
|
36 | if (col == (int)CatalogueEventsModel::Column::Validation) { | |||
|
37 | return m_EventsWithChanges.find(event) != m_EventsWithChanges.cend() ? true | |||
|
38 | : QVariant(); | |||
|
39 | } | |||
|
40 | ||||
|
41 | return eventData(col, event); | |||
29 | } |
|
42 | } | |
30 |
|
43 | |||
31 | QVariant eventData(int col, const std::shared_ptr<DBEvent> &event) const |
|
44 | QVariant eventData(int col, const std::shared_ptr<DBEvent> &event) const | |
32 | { |
|
45 | { | |
33 | switch (static_cast<Column>(col)) { |
|
46 | switch (static_cast<Column>(col)) { | |
34 | case Column::Name: |
|
47 | case CatalogueEventsModel::Column::Name: | |
35 | return event->getName(); |
|
48 | return event->getName(); | |
36 | case Column::TStart: |
|
49 | case CatalogueEventsModel::Column::TStart: | |
37 |
return DateUtils::dateTime(event->getTStart()) |
|
50 | return nbEventProducts(event) > 0 ? DateUtils::dateTime(event->getTStart()) | |
38 | case Column::TEnd: |
|
51 | : QVariant{}; | |
39 | return DateUtils::dateTime(event->getTEnd()); |
|
52 | case CatalogueEventsModel::Column::TEnd: | |
40 | case Column::Product: { |
|
53 | return nbEventProducts(event) > 0 ? DateUtils::dateTime(event->getTEnd()) | |
41 | auto eventProductsIt = m_EventProducts.find(event.get()); |
|
54 | : QVariant{}; | |
42 | if (eventProductsIt != m_EventProducts.cend()) { |
|
55 | case CatalogueEventsModel::Column::Product: | |
43 |
|
|
56 | return QString::number(nbEventProducts(event)) + " product(s)"; | |
44 | } |
|
57 | case CatalogueEventsModel::Column::Tags: { | |
45 | else { |
|
|||
46 | return "0 product"; |
|
|||
47 | } |
|
|||
48 | } |
|
|||
49 | case Column::Tags: { |
|
|||
50 | QString tagList; |
|
58 | QString tagList; | |
51 | auto tags = event->getTags(); |
|
59 | auto tags = event->getTags(); | |
52 | for (auto tag : tags) { |
|
60 | for (auto tag : tags) { | |
53 | tagList += tag.getName(); |
|
61 | tagList += tag.getName(); | |
54 | tagList += ' '; |
|
62 | tagList += ' '; | |
55 | } |
|
63 | } | |
56 |
|
64 | |||
57 | return tagList; |
|
65 | return tagList; | |
58 | } |
|
66 | } | |
|
67 | case CatalogueEventsModel::Column::Validation: | |||
|
68 | return QVariant(); | |||
59 | default: |
|
69 | default: | |
60 | break; |
|
70 | break; | |
61 | } |
|
71 | } | |
62 |
|
72 | |||
63 | Q_ASSERT(false); |
|
73 | Q_ASSERT(false); | |
64 | return QStringLiteral("Unknown Data"); |
|
74 | return QStringLiteral("Unknown Data"); | |
65 | } |
|
75 | } | |
66 |
|
76 | |||
67 | void parseEventProduct(const std::shared_ptr<DBEvent> &event) |
|
77 | void parseEventProduct(const std::shared_ptr<DBEvent> &event) | |
68 | { |
|
78 | { | |
69 | for (auto product : event->getEventProducts()) { |
|
79 | for (auto product : event->getEventProducts()) { | |
70 | m_EventProducts[event.get()].append(std::make_shared<DBEventProduct>(product)); |
|
80 | m_EventProducts[event.get()].append(std::make_shared<DBEventProduct>(product)); | |
71 | } |
|
81 | } | |
72 | } |
|
82 | } | |
73 |
|
83 | |||
|
84 | int nbEventProducts(const std::shared_ptr<DBEvent> &event) const | |||
|
85 | { | |||
|
86 | auto eventProductsIt = m_EventProducts.find(event.get()); | |||
|
87 | if (eventProductsIt != m_EventProducts.cend()) { | |||
|
88 | return m_EventProducts.at(event.get()).count(); | |||
|
89 | } | |||
|
90 | else { | |||
|
91 | return 0; | |||
|
92 | } | |||
|
93 | } | |||
|
94 | ||||
74 | QVariant eventProductData(int col, const std::shared_ptr<DBEventProduct> &eventProduct) const |
|
95 | QVariant eventProductData(int col, const std::shared_ptr<DBEventProduct> &eventProduct) const | |
75 | { |
|
96 | { | |
76 | switch (static_cast<Column>(col)) { |
|
97 | switch (static_cast<Column>(col)) { | |
77 | case Column::Name: |
|
98 | case CatalogueEventsModel::Column::Name: | |
78 | return eventProduct->getProductId(); |
|
99 | return eventProduct->getProductId(); | |
79 | case Column::TStart: |
|
100 | case CatalogueEventsModel::Column::TStart: | |
80 | return DateUtils::dateTime(eventProduct->getTStart()); |
|
101 | return DateUtils::dateTime(eventProduct->getTStart()); | |
81 | case Column::TEnd: |
|
102 | case CatalogueEventsModel::Column::TEnd: | |
82 | return DateUtils::dateTime(eventProduct->getTEnd()); |
|
103 | return DateUtils::dateTime(eventProduct->getTEnd()); | |
83 | case Column::Product: |
|
104 | case CatalogueEventsModel::Column::Product: | |
84 | return eventProduct->getProductId(); |
|
105 | return eventProduct->getProductId(); | |
85 |
case Column::Tags: |
|
106 | case CatalogueEventsModel::Column::Tags: | |
86 | return QString(); |
|
107 | return QString(); | |
87 | } |
|
108 | case CatalogueEventsModel::Column::Validation: | |
|
109 | return QVariant(); | |||
88 | default: |
|
110 | default: | |
89 | break; |
|
111 | break; | |
90 | } |
|
112 | } | |
91 |
|
113 | |||
92 | Q_ASSERT(false); |
|
114 | Q_ASSERT(false); | |
93 | return QStringLiteral("Unknown Data"); |
|
115 | return QStringLiteral("Unknown Data"); | |
94 | } |
|
116 | } | |
95 | }; |
|
117 | }; | |
96 |
|
118 | |||
97 | CatalogueEventsModel::CatalogueEventsModel(QObject *parent) |
|
119 | CatalogueEventsModel::CatalogueEventsModel(QObject *parent) | |
98 | : QAbstractItemModel(parent), impl{spimpl::make_unique_impl<CatalogueEventsModelPrivate>()} |
|
120 | : QAbstractItemModel(parent), impl{spimpl::make_unique_impl<CatalogueEventsModelPrivate>()} | |
99 | { |
|
121 | { | |
100 | } |
|
122 | } | |
101 |
|
123 | |||
102 | void CatalogueEventsModel::setEvents(const QVector<std::shared_ptr<DBEvent> > &events) |
|
124 | void CatalogueEventsModel::setEvents(const QVector<std::shared_ptr<DBEvent> > &events) | |
103 | { |
|
125 | { | |
104 | beginResetModel(); |
|
126 | beginResetModel(); | |
105 |
|
127 | |||
106 | impl->m_Events = events; |
|
128 | impl->m_Events = events; | |
107 | impl->m_EventProducts.clear(); |
|
129 | impl->m_EventProducts.clear(); | |
|
130 | impl->m_EventsWithChanges.clear(); | |||
108 | for (auto event : events) { |
|
131 | for (auto event : events) { | |
109 | impl->parseEventProduct(event); |
|
132 | impl->parseEventProduct(event); | |
110 | } |
|
133 | } | |
111 |
|
134 | |||
112 | endResetModel(); |
|
135 | endResetModel(); | |
113 | } |
|
136 | } | |
114 |
|
137 | |||
115 | std::shared_ptr<DBEvent> CatalogueEventsModel::getEvent(const QModelIndex &index) const |
|
138 | std::shared_ptr<DBEvent> CatalogueEventsModel::getEvent(const QModelIndex &index) const | |
116 | { |
|
139 | { | |
117 | if (itemTypeOf(index) == CatalogueEventsModel::ItemType::Event) { |
|
140 | if (itemTypeOf(index) == CatalogueEventsModel::ItemType::Event) { | |
118 | return impl->m_Events.value(index.row()); |
|
141 | return impl->m_Events.value(index.row()); | |
119 | } |
|
142 | } | |
120 | else { |
|
143 | else { | |
121 | return nullptr; |
|
144 | return nullptr; | |
122 | } |
|
145 | } | |
123 | } |
|
146 | } | |
124 |
|
147 | |||
125 | std::shared_ptr<DBEvent> CatalogueEventsModel::getParentEvent(const QModelIndex &index) const |
|
148 | std::shared_ptr<DBEvent> CatalogueEventsModel::getParentEvent(const QModelIndex &index) const | |
126 | { |
|
149 | { | |
127 | if (itemTypeOf(index) == CatalogueEventsModel::ItemType::EventProduct) { |
|
150 | if (itemTypeOf(index) == CatalogueEventsModel::ItemType::EventProduct) { | |
128 | return getEvent(index.parent()); |
|
151 | return getEvent(index.parent()); | |
129 | } |
|
152 | } | |
130 | else { |
|
153 | else { | |
131 | return nullptr; |
|
154 | return nullptr; | |
132 | } |
|
155 | } | |
133 | } |
|
156 | } | |
134 |
|
157 | |||
135 | std::shared_ptr<DBEventProduct> |
|
158 | std::shared_ptr<DBEventProduct> | |
136 | CatalogueEventsModel::getEventProduct(const QModelIndex &index) const |
|
159 | CatalogueEventsModel::getEventProduct(const QModelIndex &index) const | |
137 | { |
|
160 | { | |
138 | if (itemTypeOf(index) == CatalogueEventsModel::ItemType::EventProduct) { |
|
161 | if (itemTypeOf(index) == CatalogueEventsModel::ItemType::EventProduct) { | |
139 | auto event = static_cast<DBEvent *>(index.internalPointer()); |
|
162 | auto event = static_cast<DBEvent *>(index.internalPointer()); | |
140 | return impl->m_EventProducts.at(event).value(index.row()); |
|
163 | return impl->m_EventProducts.at(event).value(index.row()); | |
141 | } |
|
164 | } | |
142 | else { |
|
165 | else { | |
143 | return nullptr; |
|
166 | return nullptr; | |
144 | } |
|
167 | } | |
145 | } |
|
168 | } | |
146 |
|
169 | |||
147 | void CatalogueEventsModel::addEvent(const std::shared_ptr<DBEvent> &event) |
|
170 | void CatalogueEventsModel::addEvent(const std::shared_ptr<DBEvent> &event) | |
148 | { |
|
171 | { | |
149 | beginInsertRows(QModelIndex(), impl->m_Events.count() - 1, impl->m_Events.count() - 1); |
|
172 | beginInsertRows(QModelIndex(), impl->m_Events.count() - 1, impl->m_Events.count() - 1); | |
150 | impl->m_Events.append(event); |
|
173 | impl->m_Events.append(event); | |
151 | impl->parseEventProduct(event); |
|
174 | impl->parseEventProduct(event); | |
152 | endInsertRows(); |
|
175 | endInsertRows(); | |
153 | } |
|
176 | } | |
154 |
|
177 | |||
155 | void CatalogueEventsModel::removeEvent(const std::shared_ptr<DBEvent> &event) |
|
178 | void CatalogueEventsModel::removeEvent(const std::shared_ptr<DBEvent> &event) | |
156 | { |
|
179 | { | |
157 | auto index = impl->m_Events.indexOf(event); |
|
180 | auto index = impl->m_Events.indexOf(event); | |
158 | if (index >= 0) { |
|
181 | if (index >= 0) { | |
159 | beginRemoveRows(QModelIndex(), index, index); |
|
182 | beginRemoveRows(QModelIndex(), index, index); | |
160 | impl->m_Events.removeAt(index); |
|
183 | impl->m_Events.removeAt(index); | |
161 | impl->m_EventProducts.erase(event.get()); |
|
184 | impl->m_EventProducts.erase(event.get()); | |
|
185 | impl->m_EventsWithChanges.erase(event); | |||
162 | endRemoveRows(); |
|
186 | endRemoveRows(); | |
163 | } |
|
187 | } | |
164 | } |
|
188 | } | |
165 |
|
189 | |||
|
190 | QVector<std::shared_ptr<DBEvent> > CatalogueEventsModel::events() const | |||
|
191 | { | |||
|
192 | return impl->m_Events; | |||
|
193 | } | |||
|
194 | ||||
166 | void CatalogueEventsModel::refreshEvent(const std::shared_ptr<DBEvent> &event) |
|
195 | void CatalogueEventsModel::refreshEvent(const std::shared_ptr<DBEvent> &event) | |
167 | { |
|
196 | { | |
168 |
auto |
|
197 | auto eventIndex = indexOf(event); | |
169 | if (i >= 0) { |
|
198 | if (eventIndex.isValid()) { | |
170 | auto eventIndex = index(i, 0); |
|
199 | ||
|
200 | // Refreshes the event line | |||
171 | auto colCount = columnCount(); |
|
201 | auto colCount = columnCount(); | |
172 |
emit dataChanged(eventIndex, index( |
|
202 | emit dataChanged(eventIndex, index(eventIndex.row(), colCount)); | |
173 |
|
203 | |||
|
204 | // Also refreshes its children event products | |||
174 | auto childCount = rowCount(eventIndex); |
|
205 | auto childCount = rowCount(eventIndex); | |
175 | emit dataChanged(index(0, 0, eventIndex), index(childCount, colCount, eventIndex)); |
|
206 | emit dataChanged(index(0, 0, eventIndex), index(childCount, colCount, eventIndex)); | |
176 | } |
|
207 | } | |
|
208 | else { | |||
|
209 | qCWarning(LOG_CatalogueEventsModel()) << "refreshEvent: event not found."; | |||
|
210 | } | |||
|
211 | } | |||
|
212 | ||||
|
213 | QModelIndex CatalogueEventsModel::indexOf(const std::shared_ptr<DBEvent> &event) const | |||
|
214 | { | |||
|
215 | auto row = impl->m_Events.indexOf(event); | |||
|
216 | if (row >= 0) { | |||
|
217 | return index(row, 0); | |||
|
218 | } | |||
|
219 | ||||
|
220 | return QModelIndex(); | |||
|
221 | } | |||
|
222 | ||||
|
223 | void CatalogueEventsModel::setEventHasChanges(const std::shared_ptr<DBEvent> &event, | |||
|
224 | bool hasChanges) | |||
|
225 | { | |||
|
226 | if (hasChanges) { | |||
|
227 | impl->m_EventsWithChanges.insert(event); | |||
|
228 | } | |||
|
229 | else { | |||
|
230 | impl->m_EventsWithChanges.erase(event); | |||
|
231 | } | |||
|
232 | } | |||
|
233 | ||||
|
234 | bool CatalogueEventsModel::eventsHasChanges(const std::shared_ptr<DBEvent> &event) const | |||
|
235 | { | |||
|
236 | return impl->m_EventsWithChanges.find(event) != impl->m_EventsWithChanges.cend(); | |||
177 | } |
|
237 | } | |
178 |
|
238 | |||
179 | QModelIndex CatalogueEventsModel::index(int row, int column, const QModelIndex &parent) const |
|
239 | QModelIndex CatalogueEventsModel::index(int row, int column, const QModelIndex &parent) const | |
180 | { |
|
240 | { | |
181 | if (!hasIndex(row, column, parent)) { |
|
241 | if (!hasIndex(row, column, parent)) { | |
182 | return QModelIndex(); |
|
242 | return QModelIndex(); | |
183 | } |
|
243 | } | |
184 |
|
244 | |||
185 | switch (itemTypeOf(parent)) { |
|
245 | switch (itemTypeOf(parent)) { | |
186 | case CatalogueEventsModel::ItemType::Root: |
|
246 | case CatalogueEventsModel::ItemType::Root: | |
187 | return createIndex(row, column); |
|
247 | return createIndex(row, column); | |
188 | case CatalogueEventsModel::ItemType::Event: { |
|
248 | case CatalogueEventsModel::ItemType::Event: { | |
189 | auto event = getEvent(parent); |
|
249 | auto event = getEvent(parent); | |
190 | return createIndex(row, column, event.get()); |
|
250 | return createIndex(row, column, event.get()); | |
191 | } |
|
251 | } | |
192 | case CatalogueEventsModel::ItemType::EventProduct: |
|
252 | case CatalogueEventsModel::ItemType::EventProduct: | |
193 | break; |
|
253 | break; | |
194 | default: |
|
254 | default: | |
195 | break; |
|
255 | break; | |
196 | } |
|
256 | } | |
197 |
|
257 | |||
198 | return QModelIndex(); |
|
258 | return QModelIndex(); | |
199 | } |
|
259 | } | |
200 |
|
260 | |||
201 | QModelIndex CatalogueEventsModel::parent(const QModelIndex &index) const |
|
261 | QModelIndex CatalogueEventsModel::parent(const QModelIndex &index) const | |
202 | { |
|
262 | { | |
203 | switch (itemTypeOf(index)) { |
|
263 | switch (itemTypeOf(index)) { | |
204 | case CatalogueEventsModel::ItemType::EventProduct: { |
|
264 | case CatalogueEventsModel::ItemType::EventProduct: { | |
205 | auto parentEvent = static_cast<DBEvent *>(index.internalPointer()); |
|
265 | auto parentEvent = static_cast<DBEvent *>(index.internalPointer()); | |
206 | auto it |
|
266 | auto it | |
207 | = std::find_if(impl->m_Events.cbegin(), impl->m_Events.cend(), |
|
267 | = std::find_if(impl->m_Events.cbegin(), impl->m_Events.cend(), | |
208 | [parentEvent](auto event) { return event.get() == parentEvent; }); |
|
268 | [parentEvent](auto event) { return event.get() == parentEvent; }); | |
209 |
|
269 | |||
210 | if (it != impl->m_Events.cend()) { |
|
270 | if (it != impl->m_Events.cend()) { | |
211 | return createIndex(it - impl->m_Events.cbegin(), 0); |
|
271 | return createIndex(it - impl->m_Events.cbegin(), 0); | |
212 | } |
|
272 | } | |
213 | else { |
|
273 | else { | |
214 | return QModelIndex(); |
|
274 | return QModelIndex(); | |
215 | } |
|
275 | } | |
216 | } |
|
276 | } | |
217 | case CatalogueEventsModel::ItemType::Root: |
|
277 | case CatalogueEventsModel::ItemType::Root: | |
218 | break; |
|
278 | break; | |
219 | case CatalogueEventsModel::ItemType::Event: |
|
279 | case CatalogueEventsModel::ItemType::Event: | |
220 | break; |
|
280 | break; | |
221 | default: |
|
281 | default: | |
222 | break; |
|
282 | break; | |
223 | } |
|
283 | } | |
224 |
|
284 | |||
225 | return QModelIndex(); |
|
285 | return QModelIndex(); | |
226 | } |
|
286 | } | |
227 |
|
287 | |||
228 | int CatalogueEventsModel::rowCount(const QModelIndex &parent) const |
|
288 | int CatalogueEventsModel::rowCount(const QModelIndex &parent) const | |
229 | { |
|
289 | { | |
230 | if (parent.column() > 0) { |
|
290 | if (parent.column() > 0) { | |
231 | return 0; |
|
291 | return 0; | |
232 | } |
|
292 | } | |
233 |
|
293 | |||
234 | switch (itemTypeOf(parent)) { |
|
294 | switch (itemTypeOf(parent)) { | |
235 | case CatalogueEventsModel::ItemType::Root: |
|
295 | case CatalogueEventsModel::ItemType::Root: | |
236 | return impl->m_Events.count(); |
|
296 | return impl->m_Events.count(); | |
237 | case CatalogueEventsModel::ItemType::Event: { |
|
297 | case CatalogueEventsModel::ItemType::Event: { | |
238 | auto event = getEvent(parent); |
|
298 | auto event = getEvent(parent); | |
239 | return impl->m_EventProducts[event.get()].count(); |
|
299 | return impl->m_EventProducts[event.get()].count(); | |
240 | } |
|
300 | } | |
241 | case CatalogueEventsModel::ItemType::EventProduct: |
|
301 | case CatalogueEventsModel::ItemType::EventProduct: | |
242 | break; |
|
302 | break; | |
243 | default: |
|
303 | default: | |
244 | break; |
|
304 | break; | |
245 | } |
|
305 | } | |
246 |
|
306 | |||
247 | return 0; |
|
307 | return 0; | |
248 | } |
|
308 | } | |
249 |
|
309 | |||
250 | int CatalogueEventsModel::columnCount(const QModelIndex &parent) const |
|
310 | int CatalogueEventsModel::columnCount(const QModelIndex &parent) const | |
251 | { |
|
311 | { | |
252 |
return static_cast<int>(CatalogueEventsModel |
|
312 | return static_cast<int>(CatalogueEventsModel::Column::NbColumn); | |
253 | } |
|
313 | } | |
254 |
|
314 | |||
255 | Qt::ItemFlags CatalogueEventsModel::flags(const QModelIndex &index) const |
|
315 | Qt::ItemFlags CatalogueEventsModel::flags(const QModelIndex &index) const | |
256 | { |
|
316 | { | |
257 | return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled; |
|
317 | return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled; | |
258 | } |
|
318 | } | |
259 |
|
319 | |||
260 | QVariant CatalogueEventsModel::data(const QModelIndex &index, int role) const |
|
320 | QVariant CatalogueEventsModel::data(const QModelIndex &index, int role) const | |
261 | { |
|
321 | { | |
262 | if (index.isValid()) { |
|
322 | if (index.isValid()) { | |
263 |
|
323 | |||
264 | auto type = itemTypeOf(index); |
|
324 | auto type = itemTypeOf(index); | |
265 | if (type == CatalogueEventsModel::ItemType::Event) { |
|
325 | if (type == CatalogueEventsModel::ItemType::Event) { | |
266 | auto event = getEvent(index); |
|
326 | auto event = getEvent(index); | |
267 | switch (role) { |
|
327 | switch (role) { | |
268 | case Qt::DisplayRole: |
|
328 | case Qt::DisplayRole: | |
269 | return impl->eventData(index.column(), event); |
|
329 | return impl->eventData(index.column(), event); | |
270 | break; |
|
330 | break; | |
271 | } |
|
331 | } | |
272 | } |
|
332 | } | |
273 | else if (type == CatalogueEventsModel::ItemType::EventProduct) { |
|
333 | else if (type == CatalogueEventsModel::ItemType::EventProduct) { | |
274 | auto product = getEventProduct(index); |
|
334 | auto product = getEventProduct(index); | |
275 | switch (role) { |
|
335 | switch (role) { | |
276 | case Qt::DisplayRole: |
|
336 | case Qt::DisplayRole: | |
277 | return impl->eventProductData(index.column(), product); |
|
337 | return impl->eventProductData(index.column(), product); | |
278 | break; |
|
338 | break; | |
279 | } |
|
339 | } | |
280 | } |
|
340 | } | |
281 | } |
|
341 | } | |
282 |
|
342 | |||
283 | return QVariant{}; |
|
343 | return QVariant{}; | |
284 | } |
|
344 | } | |
285 |
|
345 | |||
286 | QVariant CatalogueEventsModel::headerData(int section, Qt::Orientation orientation, int role) const |
|
346 | QVariant CatalogueEventsModel::headerData(int section, Qt::Orientation orientation, int role) const | |
287 | { |
|
347 | { | |
288 | if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { |
|
348 | if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { | |
289 | return impl->columnNames().value(section); |
|
349 | return impl->columnNames().value(section); | |
290 | } |
|
350 | } | |
291 |
|
351 | |||
292 | return QVariant(); |
|
352 | return QVariant(); | |
293 | } |
|
353 | } | |
294 |
|
354 | |||
295 | void CatalogueEventsModel::sort(int column, Qt::SortOrder order) |
|
355 | void CatalogueEventsModel::sort(int column, Qt::SortOrder order) | |
296 | { |
|
356 | { | |
297 | std::sort(impl->m_Events.begin(), impl->m_Events.end(), |
|
357 | std::sort(impl->m_Events.begin(), impl->m_Events.end(), | |
298 | [this, column, order](auto e1, auto e2) { |
|
358 | [this, column, order](auto e1, auto e2) { | |
299 |
auto data1 = impl-> |
|
359 | auto data1 = impl->sortData(column, e1); | |
300 |
auto data2 = impl-> |
|
360 | auto data2 = impl->sortData(column, e2); | |
301 |
|
361 | |||
302 | auto result = data1.toString() < data2.toString(); |
|
362 | auto result = data1.toString() < data2.toString(); | |
303 |
|
363 | |||
304 | return order == Qt::AscendingOrder ? result : !result; |
|
364 | return order == Qt::AscendingOrder ? result : !result; | |
305 | }); |
|
365 | }); | |
306 |
|
366 | |||
307 | emit dataChanged(QModelIndex(), QModelIndex()); |
|
367 | emit dataChanged(QModelIndex(), QModelIndex()); | |
|
368 | emit modelSorted(); | |||
308 | } |
|
369 | } | |
309 |
|
370 | |||
310 | Qt::DropActions CatalogueEventsModel::supportedDragActions() const |
|
371 | Qt::DropActions CatalogueEventsModel::supportedDragActions() const | |
311 | { |
|
372 | { | |
312 | return Qt::CopyAction | Qt::MoveAction; |
|
373 | return Qt::CopyAction | Qt::MoveAction; | |
313 | } |
|
374 | } | |
314 |
|
375 | |||
315 | QStringList CatalogueEventsModel::mimeTypes() const |
|
376 | QStringList CatalogueEventsModel::mimeTypes() const | |
316 | { |
|
377 | { | |
317 | return {MIME_TYPE_EVENT_LIST, MIME_TYPE_TIME_RANGE}; |
|
378 | return {MIME_TYPE_EVENT_LIST, MIME_TYPE_TIME_RANGE}; | |
318 | } |
|
379 | } | |
319 |
|
380 | |||
320 | QMimeData *CatalogueEventsModel::mimeData(const QModelIndexList &indexes) const |
|
381 | QMimeData *CatalogueEventsModel::mimeData(const QModelIndexList &indexes) const | |
321 | { |
|
382 | { | |
322 | auto mimeData = new QMimeData; |
|
383 | auto mimeData = new QMimeData; | |
323 |
|
384 | |||
324 | bool isFirst = true; |
|
385 | bool isFirst = true; | |
325 |
|
386 | |||
326 | QVector<std::shared_ptr<DBEvent> > eventList; |
|
387 | QVector<std::shared_ptr<DBEvent> > eventList; | |
327 | QVector<std::shared_ptr<DBEventProduct> > eventProductList; |
|
388 | QVector<std::shared_ptr<DBEventProduct> > eventProductList; | |
328 |
|
389 | |||
329 | SqpRange firstTimeRange; |
|
390 | SqpRange firstTimeRange; | |
330 | for (const auto &index : indexes) { |
|
391 | for (const auto &index : indexes) { | |
331 | if (index.column() == 0) { // only the first column |
|
392 | if (index.column() == 0) { // only the first column | |
332 |
|
393 | |||
333 | auto type = itemTypeOf(index); |
|
394 | auto type = itemTypeOf(index); | |
334 | if (type == ItemType::Event) { |
|
395 | if (type == ItemType::Event) { | |
335 | auto event = getEvent(index); |
|
396 | auto event = getEvent(index); | |
336 | eventList << event; |
|
397 | eventList << event; | |
337 |
|
398 | |||
338 | if (isFirst) { |
|
399 | if (isFirst) { | |
339 | isFirst = false; |
|
400 | isFirst = false; | |
340 | firstTimeRange.m_TStart = event->getTStart(); |
|
401 | firstTimeRange.m_TStart = event->getTStart(); | |
341 | firstTimeRange.m_TEnd = event->getTEnd(); |
|
402 | firstTimeRange.m_TEnd = event->getTEnd(); | |
342 | } |
|
403 | } | |
343 | } |
|
404 | } | |
344 | else if (type == ItemType::EventProduct) { |
|
405 | else if (type == ItemType::EventProduct) { | |
345 | auto product = getEventProduct(index); |
|
406 | auto product = getEventProduct(index); | |
346 | eventProductList << product; |
|
407 | eventProductList << product; | |
347 |
|
408 | |||
348 | if (isFirst) { |
|
409 | if (isFirst) { | |
349 | isFirst = false; |
|
410 | isFirst = false; | |
350 | firstTimeRange.m_TStart = product->getTStart(); |
|
411 | firstTimeRange.m_TStart = product->getTStart(); | |
351 | firstTimeRange.m_TEnd = product->getTEnd(); |
|
412 | firstTimeRange.m_TEnd = product->getTEnd(); | |
352 | } |
|
413 | } | |
353 | } |
|
414 | } | |
354 | } |
|
415 | } | |
355 | } |
|
416 | } | |
356 |
|
417 | |||
357 | auto eventsEncodedData |
|
418 | auto eventsEncodedData | |
358 | = QByteArray{}; // sqpApp->catalogueController().->mimeDataForEvents(eventList); //TODO |
|
419 | = QByteArray{}; // sqpApp->catalogueController().->mimeDataForEvents(eventList); //TODO | |
359 | mimeData->setData(MIME_TYPE_EVENT_LIST, eventsEncodedData); |
|
420 | mimeData->setData(MIME_TYPE_EVENT_LIST, eventsEncodedData); | |
360 |
|
421 | |||
361 | if (eventList.count() + eventProductList.count() == 1) { |
|
422 | if (eventList.count() + eventProductList.count() == 1) { | |
362 | // No time range MIME data if multiple events are dragged |
|
423 | // No time range MIME data if multiple events are dragged | |
363 | auto timeEncodedData = TimeController::mimeDataForTimeRange(firstTimeRange); |
|
424 | auto timeEncodedData = TimeController::mimeDataForTimeRange(firstTimeRange); | |
364 | mimeData->setData(MIME_TYPE_TIME_RANGE, timeEncodedData); |
|
425 | mimeData->setData(MIME_TYPE_TIME_RANGE, timeEncodedData); | |
365 | } |
|
426 | } | |
366 |
|
427 | |||
367 | return mimeData; |
|
428 | return mimeData; | |
368 | } |
|
429 | } | |
369 |
|
430 | |||
370 | CatalogueEventsModel::ItemType CatalogueEventsModel::itemTypeOf(const QModelIndex &index) const |
|
431 | CatalogueEventsModel::ItemType CatalogueEventsModel::itemTypeOf(const QModelIndex &index) const | |
371 | { |
|
432 | { | |
372 | if (!index.isValid()) { |
|
433 | if (!index.isValid()) { | |
373 | return ItemType::Root; |
|
434 | return ItemType::Root; | |
374 | } |
|
435 | } | |
375 | else if (index.internalPointer() == nullptr) { |
|
436 | else if (index.internalPointer() == nullptr) { | |
376 | return ItemType::Event; |
|
437 | return ItemType::Event; | |
377 | } |
|
438 | } | |
378 | else { |
|
439 | else { | |
379 | return ItemType::EventProduct; |
|
440 | return ItemType::EventProduct; | |
380 | } |
|
441 | } | |
381 | } |
|
442 | } |
@@ -1,316 +1,360 | |||||
1 | #include "Catalogue/CatalogueEventsWidget.h" |
|
1 | #include "Catalogue/CatalogueEventsWidget.h" | |
2 | #include "ui_CatalogueEventsWidget.h" |
|
2 | #include "ui_CatalogueEventsWidget.h" | |
3 |
|
3 | |||
4 | #include <Catalogue/CatalogueController.h> |
|
4 | #include <Catalogue/CatalogueController.h> | |
5 | #include <Catalogue/CatalogueEventsModel.h> |
|
5 | #include <Catalogue/CatalogueEventsModel.h> | |
|
6 | #include <Catalogue/CatalogueExplorerHelper.h> | |||
6 | #include <CatalogueDao.h> |
|
7 | #include <CatalogueDao.h> | |
7 | #include <DBCatalogue.h> |
|
8 | #include <DBCatalogue.h> | |
8 | #include <SqpApplication.h> |
|
9 | #include <SqpApplication.h> | |
9 | #include <Visualization/VisualizationTabWidget.h> |
|
10 | #include <Visualization/VisualizationTabWidget.h> | |
10 | #include <Visualization/VisualizationWidget.h> |
|
11 | #include <Visualization/VisualizationWidget.h> | |
11 | #include <Visualization/VisualizationZoneWidget.h> |
|
12 | #include <Visualization/VisualizationZoneWidget.h> | |
12 |
|
13 | |||
13 | #include <QDialog> |
|
14 | #include <QDialog> | |
14 | #include <QDialogButtonBox> |
|
15 | #include <QDialogButtonBox> | |
15 | #include <QListWidget> |
|
16 | #include <QListWidget> | |
16 |
|
17 | |||
17 | Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget") |
|
18 | Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget") | |
18 |
|
19 | |||
19 | /// Format of the dates appearing in the label of a cursor |
|
20 | /// Fixed size of the validation column | |
20 | const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss"); |
|
21 | const auto VALIDATION_COLUMN_SIZE = 35; | |
21 |
|
22 | |||
22 | struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate { |
|
23 | struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate { | |
23 |
|
24 | |||
24 | CatalogueEventsModel *m_Model = nullptr; |
|
25 | CatalogueEventsModel *m_Model = nullptr; | |
25 | QStringList m_ZonesForTimeMode; |
|
26 | QStringList m_ZonesForTimeMode; | |
26 | QString m_ZoneForGraphMode; |
|
27 | QString m_ZoneForGraphMode; | |
27 |
|
28 | |||
28 | VisualizationWidget *m_VisualizationWidget = nullptr; |
|
29 | VisualizationWidget *m_VisualizationWidget = nullptr; | |
29 |
|
30 | |||
30 | void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, QTreeView *treeView) |
|
31 | void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, QTreeView *treeView) | |
31 | { |
|
32 | { | |
32 | treeView->setSortingEnabled(false); |
|
33 | treeView->setSortingEnabled(false); | |
33 | m_Model->setEvents(events); |
|
34 | m_Model->setEvents(events); | |
34 | treeView->setSortingEnabled(true); |
|
35 | treeView->setSortingEnabled(true); | |
35 | } |
|
36 | } | |
36 |
|
37 | |||
37 | void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView) |
|
38 | void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView) | |
38 | { |
|
39 | { | |
39 | treeView->setSortingEnabled(false); |
|
40 | treeView->setSortingEnabled(false); | |
40 | m_Model->addEvent(event); |
|
41 | m_Model->addEvent(event); | |
41 | treeView->setSortingEnabled(true); |
|
42 | treeView->setSortingEnabled(true); | |
42 | } |
|
43 | } | |
43 |
|
44 | |||
44 | void removeEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView) |
|
45 | void removeEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView) | |
45 | { |
|
46 | { | |
46 | treeView->setSortingEnabled(false); |
|
47 | treeView->setSortingEnabled(false); | |
47 | m_Model->removeEvent(event); |
|
48 | m_Model->removeEvent(event); | |
48 | treeView->setSortingEnabled(true); |
|
49 | treeView->setSortingEnabled(true); | |
49 | } |
|
50 | } | |
50 |
|
51 | |||
51 | QStringList getAvailableVisualizationZoneList() const |
|
52 | QStringList getAvailableVisualizationZoneList() const | |
52 | { |
|
53 | { | |
53 | if (m_VisualizationWidget) { |
|
54 | if (m_VisualizationWidget) { | |
54 | if (auto tab = m_VisualizationWidget->currentTabWidget()) { |
|
55 | if (auto tab = m_VisualizationWidget->currentTabWidget()) { | |
55 | return tab->availableZoneWidgets(); |
|
56 | return tab->availableZoneWidgets(); | |
56 | } |
|
57 | } | |
57 | } |
|
58 | } | |
58 |
|
59 | |||
59 | return QStringList{}; |
|
60 | return QStringList{}; | |
60 | } |
|
61 | } | |
61 |
|
62 | |||
62 | QStringList selectZone(QWidget *parent, const QStringList &selectedZones, |
|
63 | QStringList selectZone(QWidget *parent, const QStringList &selectedZones, | |
63 | bool allowMultiSelection, const QPoint &location) |
|
64 | bool allowMultiSelection, const QPoint &location) | |
64 | { |
|
65 | { | |
65 | auto availableZones = getAvailableVisualizationZoneList(); |
|
66 | auto availableZones = getAvailableVisualizationZoneList(); | |
66 | if (availableZones.isEmpty()) { |
|
67 | if (availableZones.isEmpty()) { | |
67 | return QStringList{}; |
|
68 | return QStringList{}; | |
68 | } |
|
69 | } | |
69 |
|
70 | |||
70 | QDialog d(parent, Qt::Tool); |
|
71 | QDialog d(parent, Qt::Tool); | |
71 | d.setWindowTitle("Choose a zone"); |
|
72 | d.setWindowTitle("Choose a zone"); | |
72 | auto layout = new QVBoxLayout{&d}; |
|
73 | auto layout = new QVBoxLayout{&d}; | |
73 | layout->setContentsMargins(0, 0, 0, 0); |
|
74 | layout->setContentsMargins(0, 0, 0, 0); | |
74 | auto listWidget = new QListWidget{&d}; |
|
75 | auto listWidget = new QListWidget{&d}; | |
75 | layout->addWidget(listWidget); |
|
76 | layout->addWidget(listWidget); | |
76 |
|
77 | |||
77 | QSet<QListWidgetItem *> checkedItems; |
|
78 | QSet<QListWidgetItem *> checkedItems; | |
78 | for (auto zone : availableZones) { |
|
79 | for (auto zone : availableZones) { | |
79 | auto item = new QListWidgetItem{zone}; |
|
80 | auto item = new QListWidgetItem{zone}; | |
80 | item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable); |
|
81 | item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable); | |
81 | if (selectedZones.contains(zone)) { |
|
82 | if (selectedZones.contains(zone)) { | |
82 | item->setCheckState(Qt::Checked); |
|
83 | item->setCheckState(Qt::Checked); | |
83 | checkedItems << item; |
|
84 | checkedItems << item; | |
84 | } |
|
85 | } | |
85 | else { |
|
86 | else { | |
86 | item->setCheckState(Qt::Unchecked); |
|
87 | item->setCheckState(Qt::Unchecked); | |
87 | } |
|
88 | } | |
88 |
|
89 | |||
89 | listWidget->addItem(item); |
|
90 | listWidget->addItem(item); | |
90 | } |
|
91 | } | |
91 |
|
92 | |||
92 | auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d}; |
|
93 | auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d}; | |
93 | layout->addWidget(buttonBox); |
|
94 | layout->addWidget(buttonBox); | |
94 |
|
95 | |||
95 | QObject::connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept); |
|
96 | QObject::connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept); | |
96 | QObject::connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject); |
|
97 | QObject::connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject); | |
97 |
|
98 | |||
98 | QObject::connect(listWidget, &QListWidget::itemChanged, |
|
99 | QObject::connect(listWidget, &QListWidget::itemChanged, | |
99 | [&checkedItems, allowMultiSelection, listWidget](auto item) { |
|
100 | [&checkedItems, allowMultiSelection, listWidget](auto item) { | |
100 | if (item->checkState() == Qt::Checked) { |
|
101 | if (item->checkState() == Qt::Checked) { | |
101 | if (!allowMultiSelection) { |
|
102 | if (!allowMultiSelection) { | |
102 | for (auto checkedItem : checkedItems) { |
|
103 | for (auto checkedItem : checkedItems) { | |
103 | listWidget->blockSignals(true); |
|
104 | listWidget->blockSignals(true); | |
104 | checkedItem->setCheckState(Qt::Unchecked); |
|
105 | checkedItem->setCheckState(Qt::Unchecked); | |
105 | listWidget->blockSignals(false); |
|
106 | listWidget->blockSignals(false); | |
106 | } |
|
107 | } | |
107 |
|
108 | |||
108 | checkedItems.clear(); |
|
109 | checkedItems.clear(); | |
109 | } |
|
110 | } | |
110 | checkedItems << item; |
|
111 | checkedItems << item; | |
111 | } |
|
112 | } | |
112 | else { |
|
113 | else { | |
113 | checkedItems.remove(item); |
|
114 | checkedItems.remove(item); | |
114 | } |
|
115 | } | |
115 | }); |
|
116 | }); | |
116 |
|
117 | |||
117 | QStringList result; |
|
118 | QStringList result; | |
118 |
|
119 | |||
119 | d.setMinimumWidth(120); |
|
120 | d.setMinimumWidth(120); | |
120 | d.resize(d.minimumSizeHint()); |
|
121 | d.resize(d.minimumSizeHint()); | |
121 | d.move(location); |
|
122 | d.move(location); | |
122 | if (d.exec() == QDialog::Accepted) { |
|
123 | if (d.exec() == QDialog::Accepted) { | |
123 | for (auto item : checkedItems) { |
|
124 | for (auto item : checkedItems) { | |
124 | result += item->text(); |
|
125 | result += item->text(); | |
125 | } |
|
126 | } | |
126 | } |
|
127 | } | |
127 | else { |
|
128 | else { | |
128 | result = selectedZones; |
|
129 | result = selectedZones; | |
129 | } |
|
130 | } | |
130 |
|
131 | |||
131 | return result; |
|
132 | return result; | |
132 | } |
|
133 | } | |
133 |
|
134 | |||
134 | void updateForTimeMode(QTreeView *treeView) |
|
135 | void updateForTimeMode(QTreeView *treeView) | |
135 | { |
|
136 | { | |
136 | auto selectedRows = treeView->selectionModel()->selectedRows(); |
|
137 | auto selectedRows = treeView->selectionModel()->selectedRows(); | |
137 |
|
138 | |||
138 | if (selectedRows.count() == 1) { |
|
139 | if (selectedRows.count() == 1) { | |
139 | auto event = m_Model->getEvent(selectedRows.first()); |
|
140 | auto event = m_Model->getEvent(selectedRows.first()); | |
140 | if (event) { |
|
141 | if (event) { | |
141 | if (m_VisualizationWidget) { |
|
142 | if (m_VisualizationWidget) { | |
142 | if (auto tab = m_VisualizationWidget->currentTabWidget()) { |
|
143 | if (auto tab = m_VisualizationWidget->currentTabWidget()) { | |
143 |
|
144 | |||
144 | for (auto zoneName : m_ZonesForTimeMode) { |
|
145 | for (auto zoneName : m_ZonesForTimeMode) { | |
145 | if (auto zone = tab->getZoneWithName(zoneName)) { |
|
146 | if (auto zone = tab->getZoneWithName(zoneName)) { | |
146 | SqpRange eventRange; |
|
147 | SqpRange eventRange; | |
147 | eventRange.m_TStart = event->getTStart(); |
|
148 | eventRange.m_TStart = event->getTStart(); | |
148 | eventRange.m_TEnd = event->getTEnd(); |
|
149 | eventRange.m_TEnd = event->getTEnd(); | |
149 | zone->setZoneRange(eventRange); |
|
150 | zone->setZoneRange(eventRange); | |
150 | } |
|
151 | } | |
151 | } |
|
152 | } | |
152 | } |
|
153 | } | |
153 | else { |
|
154 | else { | |
154 | qCWarning(LOG_CatalogueEventsWidget()) |
|
155 | qCWarning(LOG_CatalogueEventsWidget()) | |
155 | << "updateTimeZone: no tab found in the visualization"; |
|
156 | << "updateTimeZone: no tab found in the visualization"; | |
156 | } |
|
157 | } | |
157 | } |
|
158 | } | |
158 | else { |
|
159 | else { | |
159 | qCWarning(LOG_CatalogueEventsWidget()) |
|
160 | qCWarning(LOG_CatalogueEventsWidget()) | |
160 | << "updateTimeZone: visualization widget not found"; |
|
161 | << "updateTimeZone: visualization widget not found"; | |
161 | } |
|
162 | } | |
162 | } |
|
163 | } | |
163 | } |
|
164 | } | |
164 | else { |
|
165 | else { | |
165 | qCWarning(LOG_CatalogueEventsWidget()) |
|
166 | qCWarning(LOG_CatalogueEventsWidget()) | |
166 | << "updateTimeZone: not compatible with multiple events selected"; |
|
167 | << "updateTimeZone: not compatible with multiple events selected"; | |
167 | } |
|
168 | } | |
168 | } |
|
169 | } | |
169 |
|
170 | |||
170 | void updateForGraphMode(QTreeView *treeView) |
|
171 | void updateForGraphMode(QTreeView *treeView) | |
171 | { |
|
172 | { | |
172 | auto selectedRows = treeView->selectionModel()->selectedRows(); |
|
173 | auto selectedRows = treeView->selectionModel()->selectedRows(); | |
173 |
|
174 | |||
174 | if (selectedRows.count() == 1) { |
|
175 | if (selectedRows.count() == 1) { | |
175 | auto event = m_Model->getEvent(selectedRows.first()); |
|
176 | auto event = m_Model->getEvent(selectedRows.first()); | |
176 | if (m_VisualizationWidget) { |
|
177 | if (m_VisualizationWidget) { | |
177 | if (auto tab = m_VisualizationWidget->currentTabWidget()) { |
|
178 | if (auto tab = m_VisualizationWidget->currentTabWidget()) { | |
178 | if (auto zone = tab->getZoneWithName(m_ZoneForGraphMode)) { |
|
179 | if (auto zone = tab->getZoneWithName(m_ZoneForGraphMode)) { | |
179 | // TODO |
|
180 | // TODO | |
180 | } |
|
181 | } | |
181 | } |
|
182 | } | |
182 | else { |
|
183 | else { | |
183 | qCWarning(LOG_CatalogueEventsWidget()) |
|
184 | qCWarning(LOG_CatalogueEventsWidget()) | |
184 | << "updateGraphMode: no tab found in the visualization"; |
|
185 | << "updateGraphMode: no tab found in the visualization"; | |
185 | } |
|
186 | } | |
186 | } |
|
187 | } | |
187 | else { |
|
188 | else { | |
188 | qCWarning(LOG_CatalogueEventsWidget()) |
|
189 | qCWarning(LOG_CatalogueEventsWidget()) | |
189 | << "updateGraphMode: visualization widget not found"; |
|
190 | << "updateGraphMode: visualization widget not found"; | |
190 | } |
|
191 | } | |
191 | } |
|
192 | } | |
192 | else { |
|
193 | else { | |
193 | qCWarning(LOG_CatalogueEventsWidget()) |
|
194 | qCWarning(LOG_CatalogueEventsWidget()) | |
194 | << "updateGraphMode: not compatible with multiple events selected"; |
|
195 | << "updateGraphMode: not compatible with multiple events selected"; | |
195 | } |
|
196 | } | |
196 | } |
|
197 | } | |
197 | }; |
|
198 | }; | |
198 |
|
199 | |||
199 | CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent) |
|
200 | CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent) | |
200 | : QWidget(parent), |
|
201 | : QWidget(parent), | |
201 | ui(new Ui::CatalogueEventsWidget), |
|
202 | ui(new Ui::CatalogueEventsWidget), | |
202 | impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()} |
|
203 | impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()} | |
203 | { |
|
204 | { | |
204 | ui->setupUi(this); |
|
205 | ui->setupUi(this); | |
205 |
|
206 | |||
206 | impl->m_Model = new CatalogueEventsModel{this}; |
|
207 | impl->m_Model = new CatalogueEventsModel{this}; | |
207 | ui->treeView->setModel(impl->m_Model); |
|
208 | ui->treeView->setModel(impl->m_Model); | |
208 |
|
209 | |||
209 | ui->treeView->setSortingEnabled(true); |
|
210 | ui->treeView->setSortingEnabled(true); | |
210 | ui->treeView->setDragDropMode(QAbstractItemView::DragDrop); |
|
211 | ui->treeView->setDragDropMode(QAbstractItemView::DragDrop); | |
211 | ui->treeView->setDragEnabled(true); |
|
212 | ui->treeView->setDragEnabled(true); | |
212 |
|
213 | |||
213 | connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) { |
|
214 | connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) { | |
214 | if (checked) { |
|
215 | if (checked) { | |
215 | ui->btnChart->setChecked(false); |
|
216 | ui->btnChart->setChecked(false); | |
216 | impl->m_ZonesForTimeMode |
|
217 | impl->m_ZonesForTimeMode | |
217 | = impl->selectZone(this, impl->m_ZonesForTimeMode, true, |
|
218 | = impl->selectZone(this, impl->m_ZonesForTimeMode, true, | |
218 | this->mapToGlobal(ui->btnTime->frameGeometry().center())); |
|
219 | this->mapToGlobal(ui->btnTime->frameGeometry().center())); | |
219 |
|
220 | |||
220 | impl->updateForTimeMode(ui->treeView); |
|
221 | impl->updateForTimeMode(ui->treeView); | |
221 | } |
|
222 | } | |
222 | }); |
|
223 | }); | |
223 |
|
224 | |||
224 | connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) { |
|
225 | connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) { | |
225 | if (checked) { |
|
226 | if (checked) { | |
226 | ui->btnTime->setChecked(false); |
|
227 | ui->btnTime->setChecked(false); | |
227 | impl->m_ZoneForGraphMode |
|
228 | impl->m_ZoneForGraphMode | |
228 | = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false, |
|
229 | = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false, | |
229 | this->mapToGlobal(ui->btnChart->frameGeometry().center())) |
|
230 | this->mapToGlobal(ui->btnChart->frameGeometry().center())) | |
230 | .value(0); |
|
231 | .value(0); | |
231 |
|
232 | |||
232 | impl->updateForGraphMode(ui->treeView); |
|
233 | impl->updateForGraphMode(ui->treeView); | |
233 | } |
|
234 | } | |
234 | }); |
|
235 | }); | |
235 |
|
236 | |||
236 | auto emitSelection = [this]() { |
|
237 | auto emitSelection = [this]() { | |
237 | QVector<std::shared_ptr<DBEvent> > events; |
|
238 | QVector<std::shared_ptr<DBEvent> > events; | |
238 | QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts; |
|
239 | QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts; | |
239 |
|
240 | |||
240 | for (auto rowIndex : ui->treeView->selectionModel()->selectedRows()) { |
|
241 | for (auto rowIndex : ui->treeView->selectionModel()->selectedRows()) { | |
241 |
|
242 | |||
242 | auto itemType = impl->m_Model->itemTypeOf(rowIndex); |
|
243 | auto itemType = impl->m_Model->itemTypeOf(rowIndex); | |
243 | if (itemType == CatalogueEventsModel::ItemType::Event) { |
|
244 | if (itemType == CatalogueEventsModel::ItemType::Event) { | |
244 | events << impl->m_Model->getEvent(rowIndex); |
|
245 | events << impl->m_Model->getEvent(rowIndex); | |
245 | } |
|
246 | } | |
246 | else if (itemType == CatalogueEventsModel::ItemType::EventProduct) { |
|
247 | else if (itemType == CatalogueEventsModel::ItemType::EventProduct) { | |
247 | eventProducts << qMakePair(impl->m_Model->getParentEvent(rowIndex), |
|
248 | eventProducts << qMakePair(impl->m_Model->getParentEvent(rowIndex), | |
248 | impl->m_Model->getEventProduct(rowIndex)); |
|
249 | impl->m_Model->getEventProduct(rowIndex)); | |
249 | } |
|
250 | } | |
250 | } |
|
251 | } | |
251 |
|
252 | |||
252 | if (!events.isEmpty() && eventProducts.isEmpty()) { |
|
253 | if (!events.isEmpty() && eventProducts.isEmpty()) { | |
253 | emit this->eventsSelected(events); |
|
254 | emit this->eventsSelected(events); | |
254 | } |
|
255 | } | |
255 | else if (events.isEmpty() && !eventProducts.isEmpty()) { |
|
256 | else if (events.isEmpty() && !eventProducts.isEmpty()) { | |
256 | emit this->eventProductsSelected(eventProducts); |
|
257 | emit this->eventProductsSelected(eventProducts); | |
257 | } |
|
258 | } | |
258 | else { |
|
259 | else { | |
259 | emit this->selectionCleared(); |
|
260 | emit this->selectionCleared(); | |
260 | } |
|
261 | } | |
261 | }; |
|
262 | }; | |
262 |
|
263 | |||
263 | connect(ui->treeView, &QTreeView::clicked, emitSelection); |
|
264 | connect(ui->treeView, &QTreeView::clicked, emitSelection); | |
264 | connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection); |
|
265 | connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection); | |
265 |
|
266 | |||
266 | connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() { |
|
267 | connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() { | |
267 | auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1; |
|
268 | auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1; | |
268 | ui->btnChart->setEnabled(isNotMultiSelection); |
|
269 | ui->btnChart->setEnabled(isNotMultiSelection); | |
269 | ui->btnTime->setEnabled(isNotMultiSelection); |
|
270 | ui->btnTime->setEnabled(isNotMultiSelection); | |
270 |
|
271 | |||
271 | if (isNotMultiSelection && ui->btnTime->isChecked()) { |
|
272 | if (isNotMultiSelection && ui->btnTime->isChecked()) { | |
272 | impl->updateForTimeMode(ui->treeView); |
|
273 | impl->updateForTimeMode(ui->treeView); | |
273 | } |
|
274 | } | |
274 | else if (isNotMultiSelection && ui->btnChart->isChecked()) { |
|
275 | else if (isNotMultiSelection && ui->btnChart->isChecked()) { | |
275 | impl->updateForGraphMode(ui->treeView); |
|
276 | impl->updateForGraphMode(ui->treeView); | |
276 | } |
|
277 | } | |
277 | }); |
|
278 | }); | |
278 |
|
279 | |||
279 | ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); |
|
280 | ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); | |
280 |
ui->treeView->header()->setSectionResizeMode( |
|
281 | ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Name, | |
|
282 | QHeaderView::Stretch); | |||
|
283 | ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Validation, | |||
|
284 | QHeaderView::Fixed); | |||
|
285 | ui->treeView->header()->resizeSection((int)CatalogueEventsModel::Column::Validation, | |||
|
286 | VALIDATION_COLUMN_SIZE); | |||
281 | ui->treeView->header()->setSortIndicatorShown(true); |
|
287 | ui->treeView->header()->setSortIndicatorShown(true); | |
|
288 | ||||
|
289 | connect(impl->m_Model, &CatalogueEventsModel::modelSorted, [this]() { | |||
|
290 | auto allEvents = impl->m_Model->events(); | |||
|
291 | for (auto event : allEvents) { | |||
|
292 | setEventChanges(event, impl->m_Model->eventsHasChanges(event)); | |||
|
293 | } | |||
|
294 | }); | |||
282 | } |
|
295 | } | |
283 |
|
296 | |||
284 | CatalogueEventsWidget::~CatalogueEventsWidget() |
|
297 | CatalogueEventsWidget::~CatalogueEventsWidget() | |
285 | { |
|
298 | { | |
286 | delete ui; |
|
299 | delete ui; | |
287 | } |
|
300 | } | |
288 |
|
301 | |||
289 | void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualization) |
|
302 | void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualization) | |
290 | { |
|
303 | { | |
291 | impl->m_VisualizationWidget = visualization; |
|
304 | impl->m_VisualizationWidget = visualization; | |
292 | } |
|
305 | } | |
293 |
|
306 | |||
294 | void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges) |
|
307 | void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges) | |
295 | { |
|
308 | { | |
296 | impl->m_Model->refreshEvent(event); |
|
309 | impl->m_Model->refreshEvent(event); | |
|
310 | ||||
|
311 | auto eventIndex = impl->m_Model->indexOf(event); | |||
|
312 | auto validationIndex | |||
|
313 | = eventIndex.sibling(eventIndex.row(), (int)CatalogueEventsModel::Column::Validation); | |||
|
314 | ||||
|
315 | if (hasChanges) { | |||
|
316 | if (ui->treeView->indexWidget(validationIndex) == nullptr) { | |||
|
317 | auto widget = CatalogueExplorerHelper::buildValidationWidget( | |||
|
318 | ui->treeView, [this, event]() { setEventChanges(event, false); }, | |||
|
319 | [this, event]() { setEventChanges(event, false); }); | |||
|
320 | ui->treeView->setIndexWidget(validationIndex, widget); | |||
|
321 | } | |||
|
322 | } | |||
|
323 | else { | |||
|
324 | // Note: the widget is destroyed | |||
|
325 | ui->treeView->setIndexWidget(validationIndex, nullptr); | |||
|
326 | } | |||
|
327 | ||||
|
328 | impl->m_Model->setEventHasChanges(event, hasChanges); | |||
297 | } |
|
329 | } | |
298 |
|
330 | |||
299 | void CatalogueEventsWidget::populateWithCatalogues( |
|
331 | void CatalogueEventsWidget::populateWithCatalogues( | |
300 | const QVector<std::shared_ptr<DBCatalogue> > &catalogues) |
|
332 | const QVector<std::shared_ptr<DBCatalogue> > &catalogues) | |
301 | { |
|
333 | { | |
302 | QSet<QUuid> eventIds; |
|
334 | QSet<QUuid> eventIds; | |
303 | QVector<std::shared_ptr<DBEvent> > events; |
|
335 | QVector<std::shared_ptr<DBEvent> > events; | |
304 |
|
336 | |||
305 | for (auto catalogue : catalogues) { |
|
337 | for (auto catalogue : catalogues) { | |
306 | auto catalogueEvents = sqpApp->catalogueController().retrieveEventsFromCatalogue(catalogue); |
|
338 | auto catalogueEvents = sqpApp->catalogueController().retrieveEventsFromCatalogue(catalogue); | |
307 | for (auto event : catalogueEvents) { |
|
339 | for (auto event : catalogueEvents) { | |
308 | if (!eventIds.contains(event->getUniqId())) { |
|
340 | if (!eventIds.contains(event->getUniqId())) { | |
309 | events << event; |
|
341 | events << event; | |
310 | eventIds.insert(event->getUniqId()); |
|
342 | eventIds.insert(event->getUniqId()); | |
311 | } |
|
343 | } | |
312 | } |
|
344 | } | |
313 | } |
|
345 | } | |
314 |
|
346 | |||
315 | impl->setEvents(events, ui->treeView); |
|
347 | impl->setEvents(events, ui->treeView); | |
316 | } |
|
348 | } | |
|
349 | ||||
|
350 | void CatalogueEventsWidget::populateWithAllEvents() | |||
|
351 | { | |||
|
352 | auto allEvents = sqpApp->catalogueController().retrieveAllEvents(); | |||
|
353 | ||||
|
354 | QVector<std::shared_ptr<DBEvent> > events; | |||
|
355 | for (auto event : allEvents) { | |||
|
356 | events << event; | |||
|
357 | } | |||
|
358 | ||||
|
359 | impl->setEvents(events, ui->treeView); | |||
|
360 | } |
@@ -1,83 +1,95 | |||||
1 | #include "Catalogue/CatalogueExplorer.h" |
|
1 | #include "Catalogue/CatalogueExplorer.h" | |
2 | #include "ui_CatalogueExplorer.h" |
|
2 | #include "ui_CatalogueExplorer.h" | |
3 |
|
3 | |||
|
4 | #include <Catalogue/CatalogueActionManager.h> | |||
|
5 | #include <Catalogue/CatalogueController.h> | |||
|
6 | #include <SqpApplication.h> | |||
4 | #include <Visualization/VisualizationWidget.h> |
|
7 | #include <Visualization/VisualizationWidget.h> | |
5 |
|
8 | |||
6 | #include <DBCatalogue.h> |
|
9 | #include <DBCatalogue.h> | |
7 | #include <DBEvent.h> |
|
10 | #include <DBEvent.h> | |
8 |
|
11 | |||
9 | struct CatalogueExplorer::CatalogueExplorerPrivate { |
|
12 | struct CatalogueExplorer::CatalogueExplorerPrivate { | |
|
13 | CatalogueActionManager m_ActionManager; | |||
10 | }; |
|
14 | }; | |
11 |
|
15 | |||
12 | CatalogueExplorer::CatalogueExplorer(QWidget *parent) |
|
16 | CatalogueExplorer::CatalogueExplorer(QWidget *parent) | |
13 | : QDialog(parent, Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint), |
|
17 | : QDialog(parent, Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint), | |
14 | ui(new Ui::CatalogueExplorer), |
|
18 | ui(new Ui::CatalogueExplorer), | |
15 | impl{spimpl::make_unique_impl<CatalogueExplorerPrivate>()} |
|
19 | impl{spimpl::make_unique_impl<CatalogueExplorerPrivate>()} | |
16 | { |
|
20 | { | |
17 | ui->setupUi(this); |
|
21 | ui->setupUi(this); | |
18 |
|
22 | |||
|
23 | impl->m_ActionManager.installSelectionZoneActions(); | |||
|
24 | ||||
19 | connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSelected, [this](auto catalogues) { |
|
25 | connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSelected, [this](auto catalogues) { | |
20 | if (catalogues.count() == 1) { |
|
26 | if (catalogues.count() == 1) { | |
21 | ui->inspector->setCatalogue(catalogues.first()); |
|
27 | ui->inspector->setCatalogue(catalogues.first()); | |
22 | } |
|
28 | } | |
23 | else { |
|
29 | else { | |
24 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); |
|
30 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); | |
25 | } |
|
31 | } | |
26 |
|
32 | |||
27 | ui->events->populateWithCatalogues(catalogues); |
|
33 | ui->events->populateWithCatalogues(catalogues); | |
28 | }); |
|
34 | }); | |
29 |
|
35 | |||
30 | connect(ui->catalogues, &CatalogueSideBarWidget::databaseSelected, [this](auto databases) { |
|
36 | connect(ui->catalogues, &CatalogueSideBarWidget::databaseSelected, [this](auto databases) { | |
31 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); |
|
37 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); | |
32 | }); |
|
38 | }); | |
33 |
|
39 | |||
34 | connect(ui->catalogues, &CatalogueSideBarWidget::trashSelected, |
|
40 | connect(ui->catalogues, &CatalogueSideBarWidget::trashSelected, | |
35 | [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); }); |
|
41 | [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); }); | |
36 |
|
42 | |||
37 | connect(ui->catalogues, &CatalogueSideBarWidget::allEventsSelected, |
|
43 | connect(ui->catalogues, &CatalogueSideBarWidget::allEventsSelected, [this]() { | |
38 |
|
|
44 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); | |
|
45 | ui->events->populateWithAllEvents(); | |||
|
46 | }); | |||
39 |
|
47 | |||
40 | connect(ui->catalogues, &CatalogueSideBarWidget::selectionCleared, |
|
48 | connect(ui->catalogues, &CatalogueSideBarWidget::selectionCleared, | |
41 | [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); }); |
|
49 | [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); }); | |
42 |
|
50 | |||
43 | connect(ui->events, &CatalogueEventsWidget::eventsSelected, [this](auto events) { |
|
51 | connect(ui->events, &CatalogueEventsWidget::eventsSelected, [this](auto events) { | |
44 | if (events.count() == 1) { |
|
52 | if (events.count() == 1) { | |
45 | ui->inspector->setEvent(events.first()); |
|
53 | ui->inspector->setEvent(events.first()); | |
46 | } |
|
54 | } | |
47 | else { |
|
55 | else { | |
48 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); |
|
56 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); | |
49 | } |
|
57 | } | |
50 | }); |
|
58 | }); | |
51 |
|
59 | |||
52 | connect(ui->events, &CatalogueEventsWidget::eventProductsSelected, [this](auto eventProducts) { |
|
60 | connect(ui->events, &CatalogueEventsWidget::eventProductsSelected, [this](auto eventProducts) { | |
53 | if (eventProducts.count() == 1) { |
|
61 | if (eventProducts.count() == 1) { | |
54 | ui->inspector->setEventProduct(eventProducts.first().first, |
|
62 | ui->inspector->setEventProduct(eventProducts.first().first, | |
55 | eventProducts.first().second); |
|
63 | eventProducts.first().second); | |
56 | } |
|
64 | } | |
57 | else { |
|
65 | else { | |
58 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); |
|
66 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); | |
59 | } |
|
67 | } | |
60 | }); |
|
68 | }); | |
61 |
|
69 | |||
62 | connect(ui->events, &CatalogueEventsWidget::selectionCleared, |
|
70 | connect(ui->events, &CatalogueEventsWidget::selectionCleared, | |
63 | [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); }); |
|
71 | [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); }); | |
64 |
|
72 | |||
65 | connect(ui->inspector, &CatalogueInspectorWidget::catalogueUpdated, |
|
73 | connect(ui->inspector, &CatalogueInspectorWidget::catalogueUpdated, [this](auto catalogue) { | |
66 | [this](auto catalogue) { ui->catalogues->setCatalogueChanges(catalogue, true); }); |
|
74 | sqpApp->catalogueController().updateCatalogue(catalogue); | |
|
75 | ui->catalogues->setCatalogueChanges(catalogue, true); | |||
|
76 | }); | |||
67 |
|
77 | |||
68 | connect(ui->inspector, &CatalogueInspectorWidget::eventUpdated, |
|
78 | connect(ui->inspector, &CatalogueInspectorWidget::eventUpdated, [this](auto event) { | |
69 | [this](auto event) { ui->events->setEventChanges(event, true); }); |
|
79 | sqpApp->catalogueController().updateEvent(event); | |
|
80 | ui->events->setEventChanges(event, true); | |||
|
81 | }); | |||
70 |
|
82 | |||
71 | connect(ui->inspector, &CatalogueInspectorWidget::eventProductUpdated, |
|
83 | connect(ui->inspector, &CatalogueInspectorWidget::eventProductUpdated, | |
72 | [this](auto event, auto eventProduct) { ui->events->setEventChanges(event, true); }); |
|
84 | [this](auto event, auto eventProduct) { ui->events->setEventChanges(event, true); }); | |
73 | } |
|
85 | } | |
74 |
|
86 | |||
75 | CatalogueExplorer::~CatalogueExplorer() |
|
87 | CatalogueExplorer::~CatalogueExplorer() | |
76 | { |
|
88 | { | |
77 | delete ui; |
|
89 | delete ui; | |
78 | } |
|
90 | } | |
79 |
|
91 | |||
80 | void CatalogueExplorer::setVisualizationWidget(VisualizationWidget *visualization) |
|
92 | void CatalogueExplorer::setVisualizationWidget(VisualizationWidget *visualization) | |
81 | { |
|
93 | { | |
82 | ui->events->setVisualizationWidget(visualization); |
|
94 | ui->events->setVisualizationWidget(visualization); | |
83 | } |
|
95 | } |
@@ -1,247 +1,250 | |||||
1 | #include "Catalogue/CatalogueSideBarWidget.h" |
|
1 | #include "Catalogue/CatalogueSideBarWidget.h" | |
2 | #include "ui_CatalogueSideBarWidget.h" |
|
2 | #include "ui_CatalogueSideBarWidget.h" | |
3 | #include <SqpApplication.h> |
|
3 | #include <SqpApplication.h> | |
4 |
|
4 | |||
5 | #include <Catalogue/CatalogueController.h> |
|
5 | #include <Catalogue/CatalogueController.h> | |
6 | #include <Catalogue/CatalogueTreeWidgetItem.h> |
|
6 | #include <Catalogue/CatalogueTreeWidgetItem.h> | |
7 | #include <CatalogueDao.h> |
|
7 | #include <CatalogueDao.h> | |
8 | #include <ComparaisonPredicate.h> |
|
8 | #include <ComparaisonPredicate.h> | |
9 | #include <DBCatalogue.h> |
|
9 | #include <DBCatalogue.h> | |
10 |
|
10 | |||
11 | #include <QMenu> |
|
11 | #include <QMenu> | |
12 |
|
12 | |||
13 | Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget") |
|
13 | Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget") | |
14 |
|
14 | |||
15 |
|
15 | |||
16 | constexpr auto ALL_EVENT_ITEM_TYPE = QTreeWidgetItem::UserType; |
|
16 | constexpr auto ALL_EVENT_ITEM_TYPE = QTreeWidgetItem::UserType; | |
17 | constexpr auto TRASH_ITEM_TYPE = QTreeWidgetItem::UserType + 1; |
|
17 | constexpr auto TRASH_ITEM_TYPE = QTreeWidgetItem::UserType + 1; | |
18 | constexpr auto CATALOGUE_ITEM_TYPE = QTreeWidgetItem::UserType + 2; |
|
18 | constexpr auto CATALOGUE_ITEM_TYPE = QTreeWidgetItem::UserType + 2; | |
19 | constexpr auto DATABASE_ITEM_TYPE = QTreeWidgetItem::UserType + 3; |
|
19 | constexpr auto DATABASE_ITEM_TYPE = QTreeWidgetItem::UserType + 3; | |
20 |
|
20 | |||
21 |
|
21 | |||
22 | struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate { |
|
22 | struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate { | |
23 |
|
23 | |||
24 | void configureTreeWidget(QTreeWidget *treeWidget); |
|
24 | void configureTreeWidget(QTreeWidget *treeWidget); | |
25 | QTreeWidgetItem *addDatabaseItem(const QString &name, QTreeWidget *treeWidget); |
|
25 | QTreeWidgetItem *addDatabaseItem(const QString &name, QTreeWidget *treeWidget); | |
26 | QTreeWidgetItem *getDatabaseItem(const QString &name, QTreeWidget *treeWidget); |
|
26 | QTreeWidgetItem *getDatabaseItem(const QString &name, QTreeWidget *treeWidget); | |
27 | void addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue, |
|
27 | void addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue, | |
28 | QTreeWidgetItem *parentDatabaseItem); |
|
28 | QTreeWidgetItem *parentDatabaseItem); | |
29 |
|
29 | |||
30 | CatalogueTreeWidgetItem *getCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue, |
|
30 | CatalogueTreeWidgetItem *getCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue, | |
31 | QTreeWidget *treeWidget) const; |
|
31 | QTreeWidget *treeWidget) const; | |
32 | }; |
|
32 | }; | |
33 |
|
33 | |||
34 | CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent) |
|
34 | CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent) | |
35 | : QWidget(parent), |
|
35 | : QWidget(parent), | |
36 | ui(new Ui::CatalogueSideBarWidget), |
|
36 | ui(new Ui::CatalogueSideBarWidget), | |
37 | impl{spimpl::make_unique_impl<CatalogueSideBarWidgetPrivate>()} |
|
37 | impl{spimpl::make_unique_impl<CatalogueSideBarWidgetPrivate>()} | |
38 | { |
|
38 | { | |
39 | ui->setupUi(this); |
|
39 | ui->setupUi(this); | |
40 | impl->configureTreeWidget(ui->treeWidget); |
|
40 | impl->configureTreeWidget(ui->treeWidget); | |
41 |
|
41 | |||
42 | ui->treeWidget->setColumnCount(2); |
|
42 | ui->treeWidget->setColumnCount(2); | |
43 | ui->treeWidget->header()->setStretchLastSection(false); |
|
43 | ui->treeWidget->header()->setStretchLastSection(false); | |
44 | ui->treeWidget->header()->setSectionResizeMode(QHeaderView::ResizeToContents); |
|
44 | ui->treeWidget->header()->setSectionResizeMode(QHeaderView::ResizeToContents); | |
45 | ui->treeWidget->header()->setSectionResizeMode(0, QHeaderView::Stretch); |
|
45 | ui->treeWidget->header()->setSectionResizeMode(0, QHeaderView::Stretch); | |
46 |
|
46 | |||
47 | auto emitSelection = [this]() { |
|
47 | auto emitSelection = [this]() { | |
48 |
|
48 | |||
49 | auto selectedItems = ui->treeWidget->selectedItems(); |
|
49 | auto selectedItems = ui->treeWidget->selectedItems(); | |
50 | if (selectedItems.isEmpty()) { |
|
50 | if (selectedItems.isEmpty()) { | |
51 | emit this->selectionCleared(); |
|
51 | emit this->selectionCleared(); | |
52 | } |
|
52 | } | |
53 | else { |
|
53 | else { | |
54 | QVector<std::shared_ptr<DBCatalogue> > catalogues; |
|
54 | QVector<std::shared_ptr<DBCatalogue> > catalogues; | |
55 | QStringList databases; |
|
55 | QStringList databases; | |
56 | int selectionType = selectedItems.first()->type(); |
|
56 | int selectionType = selectedItems.first()->type(); | |
57 |
|
57 | |||
58 | for (auto item : ui->treeWidget->selectedItems()) { |
|
58 | for (auto item : ui->treeWidget->selectedItems()) { | |
59 | if (item->type() == selectionType) { |
|
59 | if (item->type() == selectionType) { | |
60 | switch (selectionType) { |
|
60 | switch (selectionType) { | |
61 | case CATALOGUE_ITEM_TYPE: |
|
61 | case CATALOGUE_ITEM_TYPE: | |
62 | catalogues.append( |
|
62 | catalogues.append( | |
63 | static_cast<CatalogueTreeWidgetItem *>(item)->catalogue()); |
|
63 | static_cast<CatalogueTreeWidgetItem *>(item)->catalogue()); | |
64 | break; |
|
64 | break; | |
65 | case DATABASE_ITEM_TYPE: |
|
65 | case DATABASE_ITEM_TYPE: | |
66 | selectionType = DATABASE_ITEM_TYPE; |
|
66 | selectionType = DATABASE_ITEM_TYPE; | |
67 | databases.append(item->text(0)); |
|
67 | databases.append(item->text(0)); | |
68 | case ALL_EVENT_ITEM_TYPE: // fallthrough |
|
68 | case ALL_EVENT_ITEM_TYPE: // fallthrough | |
69 | case TRASH_ITEM_TYPE: // fallthrough |
|
69 | case TRASH_ITEM_TYPE: // fallthrough | |
70 | default: |
|
70 | default: | |
71 | break; |
|
71 | break; | |
72 | } |
|
72 | } | |
73 | } |
|
73 | } | |
74 | else { |
|
74 | else { | |
75 | // Incoherent multi selection |
|
75 | // Incoherent multi selection | |
76 | selectionType = -1; |
|
76 | selectionType = -1; | |
77 | break; |
|
77 | break; | |
78 | } |
|
78 | } | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | switch (selectionType) { |
|
81 | switch (selectionType) { | |
82 | case CATALOGUE_ITEM_TYPE: |
|
82 | case CATALOGUE_ITEM_TYPE: | |
83 | emit this->catalogueSelected(catalogues); |
|
83 | emit this->catalogueSelected(catalogues); | |
84 | break; |
|
84 | break; | |
85 | case DATABASE_ITEM_TYPE: |
|
85 | case DATABASE_ITEM_TYPE: | |
86 | emit this->databaseSelected(databases); |
|
86 | emit this->databaseSelected(databases); | |
87 | break; |
|
87 | break; | |
88 | case ALL_EVENT_ITEM_TYPE: |
|
88 | case ALL_EVENT_ITEM_TYPE: | |
89 | emit this->allEventsSelected(); |
|
89 | emit this->allEventsSelected(); | |
90 | break; |
|
90 | break; | |
91 | case TRASH_ITEM_TYPE: |
|
91 | case TRASH_ITEM_TYPE: | |
92 | emit this->trashSelected(); |
|
92 | emit this->trashSelected(); | |
93 | break; |
|
93 | break; | |
94 | default: |
|
94 | default: | |
95 | emit this->selectionCleared(); |
|
95 | emit this->selectionCleared(); | |
96 | break; |
|
96 | break; | |
97 | } |
|
97 | } | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 |
|
100 | |||
101 | }; |
|
101 | }; | |
102 |
|
102 | |||
103 | connect(ui->treeWidget, &QTreeWidget::itemClicked, emitSelection); |
|
103 | connect(ui->treeWidget, &QTreeWidget::itemClicked, emitSelection); | |
104 | connect(ui->treeWidget, &QTreeWidget::currentItemChanged, emitSelection); |
|
104 | connect(ui->treeWidget, &QTreeWidget::currentItemChanged, emitSelection); | |
105 | connect(ui->treeWidget, &QTreeWidget::itemChanged, |
|
105 | connect(ui->treeWidget, &QTreeWidget::itemChanged, | |
106 | [emitSelection, this](auto item, auto column) { |
|
106 | [emitSelection, this](auto item, auto column) { | |
107 | auto selectedItems = ui->treeWidget->selectedItems(); |
|
107 | auto selectedItems = ui->treeWidget->selectedItems(); | |
108 | qDebug() << "ITEM CHANGED" << column; |
|
108 | qDebug() << "ITEM CHANGED" << column; | |
109 | if (selectedItems.contains(item) && column == 0) { |
|
109 | if (selectedItems.contains(item) && column == 0) { | |
110 | emitSelection(); |
|
110 | emitSelection(); | |
111 | } |
|
111 | } | |
112 | }); |
|
112 | }); | |
113 |
|
113 | |||
114 | ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu); |
|
114 | ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu); | |
115 | connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this, |
|
115 | connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this, | |
116 | &CatalogueSideBarWidget::onContextMenuRequested); |
|
116 | &CatalogueSideBarWidget::onContextMenuRequested); | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 | CatalogueSideBarWidget::~CatalogueSideBarWidget() |
|
119 | CatalogueSideBarWidget::~CatalogueSideBarWidget() | |
120 | { |
|
120 | { | |
121 | delete ui; |
|
121 | delete ui; | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue, |
|
124 | void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue, | |
125 | bool hasChanges) |
|
125 | bool hasChanges) | |
126 | { |
|
126 | { | |
127 | if (auto catalogueItem = impl->getCatalogueItem(catalogue, ui->treeWidget)) { |
|
127 | if (auto catalogueItem = impl->getCatalogueItem(catalogue, ui->treeWidget)) { | |
128 | catalogueItem->setHasChanges(hasChanges); |
|
128 | catalogueItem->setHasChanges(hasChanges); | |
129 | catalogueItem->refresh(); |
|
129 | catalogueItem->refresh(); | |
130 | } |
|
130 | } | |
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 | void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos) |
|
133 | void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos) | |
134 | { |
|
134 | { | |
135 | QMenu menu{this}; |
|
135 | QMenu menu{this}; | |
136 |
|
136 | |||
137 | auto currentItem = ui->treeWidget->currentItem(); |
|
137 | auto currentItem = ui->treeWidget->currentItem(); | |
138 | switch (currentItem->type()) { |
|
138 | switch (currentItem->type()) { | |
139 | case CATALOGUE_ITEM_TYPE: |
|
139 | case CATALOGUE_ITEM_TYPE: | |
140 | menu.addAction("Rename", |
|
140 | menu.addAction("Rename", | |
141 | [this, currentItem]() { ui->treeWidget->editItem(currentItem); }); |
|
141 | [this, currentItem]() { ui->treeWidget->editItem(currentItem); }); | |
142 | break; |
|
142 | break; | |
143 | case DATABASE_ITEM_TYPE: |
|
143 | case DATABASE_ITEM_TYPE: | |
144 | break; |
|
144 | break; | |
145 | case ALL_EVENT_ITEM_TYPE: |
|
145 | case ALL_EVENT_ITEM_TYPE: | |
146 | break; |
|
146 | break; | |
147 | case TRASH_ITEM_TYPE: |
|
147 | case TRASH_ITEM_TYPE: | |
148 | menu.addAction("Empty Trash", []() { |
|
148 | menu.addAction("Empty Trash", []() { | |
149 | // TODO |
|
149 | // TODO | |
150 | }); |
|
150 | }); | |
151 | break; |
|
151 | break; | |
152 | default: |
|
152 | default: | |
153 | break; |
|
153 | break; | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | if (!menu.isEmpty()) { |
|
156 | if (!menu.isEmpty()) { | |
157 | menu.exec(ui->treeWidget->mapToGlobal(pos)); |
|
157 | menu.exec(ui->treeWidget->mapToGlobal(pos)); | |
158 | } |
|
158 | } | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget( |
|
161 | void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget( | |
162 | QTreeWidget *treeWidget) |
|
162 | QTreeWidget *treeWidget) | |
163 | { |
|
163 | { | |
164 | auto allEventsItem = new QTreeWidgetItem{{"All Events"}, ALL_EVENT_ITEM_TYPE}; |
|
164 | auto allEventsItem = new QTreeWidgetItem{{"All Events"}, ALL_EVENT_ITEM_TYPE}; | |
165 | allEventsItem->setIcon(0, QIcon(":/icones/allEvents.png")); |
|
165 | allEventsItem->setIcon(0, QIcon(":/icones/allEvents.png")); | |
166 | treeWidget->addTopLevelItem(allEventsItem); |
|
166 | treeWidget->addTopLevelItem(allEventsItem); | |
167 |
|
167 | |||
168 | auto trashItem = new QTreeWidgetItem{{"Trash"}, TRASH_ITEM_TYPE}; |
|
168 | auto trashItem = new QTreeWidgetItem{{"Trash"}, TRASH_ITEM_TYPE}; | |
169 | trashItem->setIcon(0, QIcon(":/icones/trash.png")); |
|
169 | trashItem->setIcon(0, QIcon(":/icones/trash.png")); | |
170 | treeWidget->addTopLevelItem(trashItem); |
|
170 | treeWidget->addTopLevelItem(trashItem); | |
171 |
|
171 | |||
172 | auto separator = new QFrame{treeWidget}; |
|
172 | auto separator = new QFrame{treeWidget}; | |
173 | separator->setFrameShape(QFrame::HLine); |
|
173 | separator->setFrameShape(QFrame::HLine); | |
174 | auto separatorItem = new QTreeWidgetItem{}; |
|
174 | auto separatorItem = new QTreeWidgetItem{}; | |
175 | separatorItem->setFlags(Qt::NoItemFlags); |
|
175 | separatorItem->setFlags(Qt::NoItemFlags); | |
176 | treeWidget->addTopLevelItem(separatorItem); |
|
176 | treeWidget->addTopLevelItem(separatorItem); | |
177 | treeWidget->setItemWidget(separatorItem, 0, separator); |
|
177 | treeWidget->setItemWidget(separatorItem, 0, separator); | |
178 |
|
178 | |||
179 | auto db = addDatabaseItem("Default", treeWidget); |
|
179 | auto repositories = sqpApp->catalogueController().getRepositories(); | |
|
180 | for (auto dbname : repositories) { | |||
|
181 | auto db = addDatabaseItem(dbname, treeWidget); | |||
180 |
|
182 | |||
181 |
auto catalogues = sqpApp->catalogueController(). |
|
183 | auto catalogues = sqpApp->catalogueController().retrieveCatalogues(dbname); | |
182 | for (auto catalogue : catalogues) { |
|
184 | for (auto catalogue : catalogues) { | |
183 | addCatalogueItem(catalogue, db); |
|
185 | addCatalogueItem(catalogue, db); | |
184 | } |
|
186 | } | |
|
187 | } | |||
185 |
|
188 | |||
186 | treeWidget->expandAll(); |
|
189 | treeWidget->expandAll(); | |
187 | } |
|
190 | } | |
188 |
|
191 | |||
189 | QTreeWidgetItem * |
|
192 | QTreeWidgetItem * | |
190 | CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name, |
|
193 | CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name, | |
191 | QTreeWidget *treeWidget) |
|
194 | QTreeWidget *treeWidget) | |
192 | { |
|
195 | { | |
193 | auto databaseItem = new QTreeWidgetItem{{name}, DATABASE_ITEM_TYPE}; |
|
196 | auto databaseItem = new QTreeWidgetItem{{name}, DATABASE_ITEM_TYPE}; | |
194 | databaseItem->setIcon(0, QIcon{":/icones/database.png"}); |
|
197 | databaseItem->setIcon(0, QIcon{":/icones/database.png"}); | |
195 | treeWidget->addTopLevelItem(databaseItem); |
|
198 | treeWidget->addTopLevelItem(databaseItem); | |
196 |
|
199 | |||
197 | return databaseItem; |
|
200 | return databaseItem; | |
198 | } |
|
201 | } | |
199 |
|
202 | |||
200 | QTreeWidgetItem * |
|
203 | QTreeWidgetItem * | |
201 | CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QString &name, |
|
204 | CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QString &name, | |
202 | QTreeWidget *treeWidget) |
|
205 | QTreeWidget *treeWidget) | |
203 | { |
|
206 | { | |
204 | for (auto i = 0; i < treeWidget->topLevelItemCount(); ++i) { |
|
207 | for (auto i = 0; i < treeWidget->topLevelItemCount(); ++i) { | |
205 | auto item = treeWidget->topLevelItem(i); |
|
208 | auto item = treeWidget->topLevelItem(i); | |
206 | if (item->type() == DATABASE_ITEM_TYPE && item->text(0) == name) { |
|
209 | if (item->type() == DATABASE_ITEM_TYPE && item->text(0) == name) { | |
207 | return item; |
|
210 | return item; | |
208 | } |
|
211 | } | |
209 | } |
|
212 | } | |
210 |
|
213 | |||
211 | return nullptr; |
|
214 | return nullptr; | |
212 | } |
|
215 | } | |
213 |
|
216 | |||
214 | void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem( |
|
217 | void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem( | |
215 | const std::shared_ptr<DBCatalogue> &catalogue, QTreeWidgetItem *parentDatabaseItem) |
|
218 | const std::shared_ptr<DBCatalogue> &catalogue, QTreeWidgetItem *parentDatabaseItem) | |
216 | { |
|
219 | { | |
217 | auto catalogueItem = new CatalogueTreeWidgetItem{catalogue, CATALOGUE_ITEM_TYPE}; |
|
220 | auto catalogueItem = new CatalogueTreeWidgetItem{catalogue, CATALOGUE_ITEM_TYPE}; | |
218 | catalogueItem->setIcon(0, QIcon{":/icones/catalogue.png"}); |
|
221 | catalogueItem->setIcon(0, QIcon{":/icones/catalogue.png"}); | |
219 | parentDatabaseItem->addChild(catalogueItem); |
|
222 | parentDatabaseItem->addChild(catalogueItem); | |
220 | } |
|
223 | } | |
221 |
|
224 | |||
222 | CatalogueTreeWidgetItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCatalogueItem( |
|
225 | CatalogueTreeWidgetItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCatalogueItem( | |
223 | const std::shared_ptr<DBCatalogue> &catalogue, QTreeWidget *treeWidget) const |
|
226 | const std::shared_ptr<DBCatalogue> &catalogue, QTreeWidget *treeWidget) const | |
224 | { |
|
227 | { | |
225 | for (auto i = 0; i < treeWidget->topLevelItemCount(); ++i) { |
|
228 | for (auto i = 0; i < treeWidget->topLevelItemCount(); ++i) { | |
226 | auto item = treeWidget->topLevelItem(i); |
|
229 | auto item = treeWidget->topLevelItem(i); | |
227 | if (item->type() == DATABASE_ITEM_TYPE) { |
|
230 | if (item->type() == DATABASE_ITEM_TYPE) { | |
228 | for (auto j = 0; j < item->childCount(); ++j) { |
|
231 | for (auto j = 0; j < item->childCount(); ++j) { | |
229 | auto childItem = item->child(j); |
|
232 | auto childItem = item->child(j); | |
230 | if (childItem->type() == CATALOGUE_ITEM_TYPE) { |
|
233 | if (childItem->type() == CATALOGUE_ITEM_TYPE) { | |
231 | auto catalogueItem = static_cast<CatalogueTreeWidgetItem *>(childItem); |
|
234 | auto catalogueItem = static_cast<CatalogueTreeWidgetItem *>(childItem); | |
232 | if (catalogueItem->catalogue() == catalogue) { |
|
235 | if (catalogueItem->catalogue() == catalogue) { | |
233 | return catalogueItem; |
|
236 | return catalogueItem; | |
234 | } |
|
237 | } | |
235 | } |
|
238 | } | |
236 | else { |
|
239 | else { | |
237 | qCWarning(LOG_CatalogueSideBarWidget()) << "getCatalogueItem: Invalid tree " |
|
240 | qCWarning(LOG_CatalogueSideBarWidget()) << "getCatalogueItem: Invalid tree " | |
238 | "structure. A database item should " |
|
241 | "structure. A database item should " | |
239 | "only contain catalogues."; |
|
242 | "only contain catalogues."; | |
240 | Q_ASSERT(false); |
|
243 | Q_ASSERT(false); | |
241 | } |
|
244 | } | |
242 | } |
|
245 | } | |
243 | } |
|
246 | } | |
244 | } |
|
247 | } | |
245 |
|
248 | |||
246 | return nullptr; |
|
249 | return nullptr; | |
247 | } |
|
250 | } |
@@ -1,103 +1,91 | |||||
1 | #include "Catalogue/CatalogueTreeWidgetItem.h" |
|
1 | #include "Catalogue/CatalogueTreeWidgetItem.h" | |
|
2 | #include <Catalogue/CatalogueExplorerHelper.h> | |||
|
3 | ||||
|
4 | #include <Catalogue/CatalogueController.h> | |||
|
5 | #include <SqpApplication.h> | |||
2 |
|
6 | |||
3 | #include <memory> |
|
7 | #include <memory> | |
4 |
|
8 | |||
5 | #include <DBCatalogue.h> |
|
9 | #include <DBCatalogue.h> | |
6 | #include <QBoxLayout> |
|
|||
7 | #include <QToolButton> |
|
|||
8 |
|
||||
9 | const auto VALIDATION_BUTTON_ICON_SIZE = 12; |
|
|||
10 |
|
10 | |||
11 | /// Column in the tree widget where the apply and cancel buttons must appear |
|
11 | /// Column in the tree widget where the apply and cancel buttons must appear | |
12 | const auto APPLY_CANCEL_BUTTONS_COLUMN = 1; |
|
12 | const auto APPLY_CANCEL_BUTTONS_COLUMN = 1; | |
13 |
|
13 | |||
14 | struct CatalogueTreeWidgetItem::CatalogueTreeWidgetItemPrivate { |
|
14 | struct CatalogueTreeWidgetItem::CatalogueTreeWidgetItemPrivate { | |
15 |
|
15 | |||
16 | std::shared_ptr<DBCatalogue> m_Catalogue; |
|
16 | std::shared_ptr<DBCatalogue> m_Catalogue; | |
17 |
|
17 | |||
18 | CatalogueTreeWidgetItemPrivate(std::shared_ptr<DBCatalogue> catalogue) : m_Catalogue(catalogue) |
|
18 | CatalogueTreeWidgetItemPrivate(std::shared_ptr<DBCatalogue> catalogue) : m_Catalogue(catalogue) | |
19 | { |
|
19 | { | |
20 | } |
|
20 | } | |
21 | }; |
|
21 | }; | |
22 |
|
22 | |||
23 |
|
23 | |||
24 | CatalogueTreeWidgetItem::CatalogueTreeWidgetItem(std::shared_ptr<DBCatalogue> catalogue, int type) |
|
24 | CatalogueTreeWidgetItem::CatalogueTreeWidgetItem(std::shared_ptr<DBCatalogue> catalogue, int type) | |
25 | : QTreeWidgetItem(type), |
|
25 | : QTreeWidgetItem(type), | |
26 | impl{spimpl::make_unique_impl<CatalogueTreeWidgetItemPrivate>(catalogue)} |
|
26 | impl{spimpl::make_unique_impl<CatalogueTreeWidgetItemPrivate>(catalogue)} | |
27 | { |
|
27 | { | |
28 | setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable); |
|
28 | setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable); | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 | QVariant CatalogueTreeWidgetItem::data(int column, int role) const |
|
31 | QVariant CatalogueTreeWidgetItem::data(int column, int role) const | |
32 | { |
|
32 | { | |
33 | if (column == 0) { |
|
33 | if (column == 0) { | |
34 | switch (role) { |
|
34 | switch (role) { | |
35 | case Qt::EditRole: // fallthrough |
|
35 | case Qt::EditRole: // fallthrough | |
36 | case Qt::DisplayRole: |
|
36 | case Qt::DisplayRole: | |
37 | return impl->m_Catalogue->getName(); |
|
37 | return impl->m_Catalogue->getName(); | |
38 | default: |
|
38 | default: | |
39 | break; |
|
39 | break; | |
40 | } |
|
40 | } | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | return QTreeWidgetItem::data(column, role); |
|
43 | return QTreeWidgetItem::data(column, role); | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | void CatalogueTreeWidgetItem::setData(int column, int role, const QVariant &value) |
|
46 | void CatalogueTreeWidgetItem::setData(int column, int role, const QVariant &value) | |
47 | { |
|
47 | { | |
48 | if (role == Qt::EditRole && column == 0) { |
|
48 | if (role == Qt::EditRole && column == 0) { | |
49 | auto newName = value.toString(); |
|
49 | auto newName = value.toString(); | |
50 | if (newName != impl->m_Catalogue->getName()) { |
|
50 | if (newName != impl->m_Catalogue->getName()) { | |
51 | setText(0, newName); |
|
51 | setText(0, newName); | |
52 | impl->m_Catalogue->setName(newName); |
|
52 | impl->m_Catalogue->setName(newName); | |
|
53 | sqpApp->catalogueController().updateCatalogue(impl->m_Catalogue); | |||
53 | setHasChanges(true); |
|
54 | setHasChanges(true); | |
54 | } |
|
55 | } | |
55 | } |
|
56 | } | |
56 | else { |
|
57 | else { | |
57 | QTreeWidgetItem::setData(column, role, value); |
|
58 | QTreeWidgetItem::setData(column, role, value); | |
58 | } |
|
59 | } | |
59 | } |
|
60 | } | |
60 |
|
61 | |||
61 | std::shared_ptr<DBCatalogue> CatalogueTreeWidgetItem::catalogue() const |
|
62 | std::shared_ptr<DBCatalogue> CatalogueTreeWidgetItem::catalogue() const | |
62 | { |
|
63 | { | |
63 | return impl->m_Catalogue; |
|
64 | return impl->m_Catalogue; | |
64 | } |
|
65 | } | |
65 |
|
66 | |||
66 | void CatalogueTreeWidgetItem::setHasChanges(bool value) |
|
67 | void CatalogueTreeWidgetItem::setHasChanges(bool value) | |
67 | { |
|
68 | { | |
68 | if (value) { |
|
69 | if (value) { | |
69 | if (treeWidget()->itemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN) == nullptr) { |
|
70 | if (!hasChanges()) { | |
70 | auto widet = new QWidget{treeWidget()}; |
|
71 | auto widget = CatalogueExplorerHelper::buildValidationWidget( | |
71 |
|
72 | treeWidget(), [this]() { setHasChanges(false); }, | ||
72 | auto layout = new QHBoxLayout{widet}; |
|
73 | [this]() { setHasChanges(false); }); | |
73 | layout->setContentsMargins(0, 0, 0, 0); |
|
74 | treeWidget()->setItemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN, widget); | |
74 | layout->setSpacing(0); |
|
|||
75 |
|
||||
76 | auto btnValid = new QToolButton{widet}; |
|
|||
77 | btnValid->setIcon(QIcon{":/icones/save"}); |
|
|||
78 | btnValid->setIconSize(QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE}); |
|
|||
79 | btnValid->setAutoRaise(true); |
|
|||
80 | QObject::connect(btnValid, &QToolButton::clicked, [this]() { setHasChanges(false); }); |
|
|||
81 | layout->addWidget(btnValid); |
|
|||
82 |
|
||||
83 | auto btnDiscard = new QToolButton{widet}; |
|
|||
84 | btnDiscard->setIcon(QIcon{":/icones/discard"}); |
|
|||
85 | btnDiscard->setIconSize( |
|
|||
86 | QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE}); |
|
|||
87 | btnDiscard->setAutoRaise(true); |
|
|||
88 | QObject::connect(btnDiscard, &QToolButton::clicked, [this]() { setHasChanges(false); }); |
|
|||
89 | layout->addWidget(btnDiscard); |
|
|||
90 |
|
||||
91 | treeWidget()->setItemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN, {widet}); |
|
|||
92 | } |
|
75 | } | |
93 | } |
|
76 | } | |
94 | else { |
|
77 | else { | |
95 | // Note: the widget is destroyed |
|
78 | // Note: the widget is destroyed | |
96 | treeWidget()->setItemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN, nullptr); |
|
79 | treeWidget()->setItemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN, nullptr); | |
97 | } |
|
80 | } | |
98 | } |
|
81 | } | |
99 |
|
82 | |||
|
83 | bool CatalogueTreeWidgetItem::hasChanges() | |||
|
84 | { | |||
|
85 | return treeWidget()->itemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN) != nullptr; | |||
|
86 | } | |||
|
87 | ||||
100 | void CatalogueTreeWidgetItem::refresh() |
|
88 | void CatalogueTreeWidgetItem::refresh() | |
101 | { |
|
89 | { | |
102 | emitDataChanged(); |
|
90 | emitDataChanged(); | |
103 | } |
|
91 | } |
@@ -1,109 +1,111 | |||||
1 | #include "Visualization/VisualizationActionManager.h" |
|
1 | #include "Visualization/VisualizationActionManager.h" | |
2 | #include "Visualization/VisualizationGraphWidget.h" |
|
2 | #include "Visualization/VisualizationGraphWidget.h" | |
3 | #include "Visualization/VisualizationSelectionZoneItem.h" |
|
3 | #include "Visualization/VisualizationSelectionZoneItem.h" | |
4 |
|
4 | |||
5 | #include <Actions/ActionsGuiController.h> |
|
5 | #include <Actions/ActionsGuiController.h> | |
6 | #include <SqpApplication.h> |
|
6 | #include <SqpApplication.h> | |
7 |
|
7 | |||
8 |
VisualizationActionManager::VisualizationActionManager() |
|
8 | VisualizationActionManager::VisualizationActionManager() | |
|
9 | { | |||
|
10 | } | |||
9 |
|
11 | |||
10 | void VisualizationActionManager::installSelectionZoneActions() |
|
12 | void VisualizationActionManager::installSelectionZoneActions() | |
11 | { |
|
13 | { | |
12 | auto &actionController = sqpApp->actionsGuiController(); |
|
14 | auto &actionController = sqpApp->actionsGuiController(); | |
13 |
|
15 | |||
14 | auto removeZonesAction |
|
16 | auto removeZonesAction | |
15 | = actionController.addSectionZoneAction("Remove Selected Zone(s)", [](auto zones) { |
|
17 | = actionController.addSectionZoneAction("Remove Selected Zone(s)", [](auto zones) { | |
16 | for (auto selectionZone : zones) { |
|
18 | for (auto selectionZone : zones) { | |
17 | if (auto graph = selectionZone->parentGraphWidget()) { |
|
19 | if (auto graph = selectionZone->parentGraphWidget()) { | |
18 | graph->removeSelectionZone(selectionZone); |
|
20 | graph->removeSelectionZone(selectionZone); | |
19 | } |
|
21 | } | |
20 | } |
|
22 | } | |
21 | }); |
|
23 | }); | |
22 | removeZonesAction->setDisplayedShortcut(QKeySequence::Delete); |
|
24 | removeZonesAction->setDisplayedShortcut(QKeySequence::Delete); | |
23 |
|
25 | |||
24 | auto alignEnableFuntion = [](auto items) { return items.count() > 1; }; |
|
26 | auto alignEnableFuntion = [](auto items) { return items.count() > 1; }; | |
25 |
|
27 | |||
26 | // Vertical alignment actions |
|
28 | // Vertical alignment actions | |
27 | auto alignLeftAction = actionController.addSectionZoneAction( |
|
29 | auto alignLeftAction = actionController.addSectionZoneAction( | |
28 | QStringList{"Align Vertically"}, "Left", [](auto zones) { |
|
30 | QStringList{"Align Vertically"}, "Left", [](auto zones) { | |
29 | Q_ASSERT(zones.count() > 1); |
|
31 | Q_ASSERT(zones.count() > 1); | |
30 | auto ref = zones.takeFirst(); |
|
32 | auto ref = zones.takeFirst(); | |
31 | ref->alignZonesVerticallyOnLeft(zones, false); |
|
33 | ref->alignZonesVerticallyOnLeft(zones, false); | |
32 | }); |
|
34 | }); | |
33 | alignLeftAction->setEnableFunction(alignEnableFuntion); |
|
35 | alignLeftAction->setEnableFunction(alignEnableFuntion); | |
34 |
|
36 | |||
35 | auto alignLeftBorderAction = actionController.addSectionZoneAction( |
|
37 | auto alignLeftBorderAction = actionController.addSectionZoneAction( | |
36 | QStringList{"Align Vertically"}, "Left Borders", [](auto zones) { |
|
38 | QStringList{"Align Vertically"}, "Left Borders", [](auto zones) { | |
37 | Q_ASSERT(zones.count() > 1); |
|
39 | Q_ASSERT(zones.count() > 1); | |
38 | auto ref = zones.takeFirst(); |
|
40 | auto ref = zones.takeFirst(); | |
39 | ref->alignZonesVerticallyOnLeft(zones, true); |
|
41 | ref->alignZonesVerticallyOnLeft(zones, true); | |
40 | }); |
|
42 | }); | |
41 | alignLeftBorderAction->setEnableFunction(alignEnableFuntion); |
|
43 | alignLeftBorderAction->setEnableFunction(alignEnableFuntion); | |
42 |
|
44 | |||
43 | auto alignRightAction = actionController.addSectionZoneAction( |
|
45 | auto alignRightAction = actionController.addSectionZoneAction( | |
44 | QStringList{"Align Vertically"}, "Right", [](auto zones) { |
|
46 | QStringList{"Align Vertically"}, "Right", [](auto zones) { | |
45 | Q_ASSERT(zones.count() > 1); |
|
47 | Q_ASSERT(zones.count() > 1); | |
46 | auto ref = zones.takeFirst(); |
|
48 | auto ref = zones.takeFirst(); | |
47 | ref->alignZonesVerticallyOnRight(zones, false); |
|
49 | ref->alignZonesVerticallyOnRight(zones, false); | |
48 | }); |
|
50 | }); | |
49 | alignRightAction->setEnableFunction(alignEnableFuntion); |
|
51 | alignRightAction->setEnableFunction(alignEnableFuntion); | |
50 |
|
52 | |||
51 | auto alignRightBorderAction = actionController.addSectionZoneAction( |
|
53 | auto alignRightBorderAction = actionController.addSectionZoneAction( | |
52 | QStringList{"Align Vertically"}, "Right Borders", [](auto zones) { |
|
54 | QStringList{"Align Vertically"}, "Right Borders", [](auto zones) { | |
53 | Q_ASSERT(zones.count() > 1); |
|
55 | Q_ASSERT(zones.count() > 1); | |
54 | auto ref = zones.takeFirst(); |
|
56 | auto ref = zones.takeFirst(); | |
55 | ref->alignZonesVerticallyOnRight(zones, true); |
|
57 | ref->alignZonesVerticallyOnRight(zones, true); | |
56 | }); |
|
58 | }); | |
57 | alignRightBorderAction->setEnableFunction(alignEnableFuntion); |
|
59 | alignRightBorderAction->setEnableFunction(alignEnableFuntion); | |
58 |
|
60 | |||
59 | auto alignLeftAndRightAction = actionController.addSectionZoneAction( |
|
61 | auto alignLeftAndRightAction = actionController.addSectionZoneAction( | |
60 | QStringList{"Align Vertically"}, "Left and Right", [](auto zones) { |
|
62 | QStringList{"Align Vertically"}, "Left and Right", [](auto zones) { | |
61 | Q_ASSERT(zones.count() > 1); |
|
63 | Q_ASSERT(zones.count() > 1); | |
62 | auto ref = zones.takeFirst(); |
|
64 | auto ref = zones.takeFirst(); | |
63 | ref->alignZonesVerticallyOnLeft(zones, false); |
|
65 | ref->alignZonesVerticallyOnLeft(zones, false); | |
64 | ref->alignZonesVerticallyOnRight(zones, true); |
|
66 | ref->alignZonesVerticallyOnRight(zones, true); | |
65 | }); |
|
67 | }); | |
66 | alignLeftAndRightAction->setEnableFunction(alignEnableFuntion); |
|
68 | alignLeftAndRightAction->setEnableFunction(alignEnableFuntion); | |
67 |
|
69 | |||
68 | // Temporal alignment actions |
|
70 | // Temporal alignment actions | |
69 | auto alignLeftTemporallyAction = actionController.addSectionZoneAction( |
|
71 | auto alignLeftTemporallyAction = actionController.addSectionZoneAction( | |
70 | QStringList{"Align Temporally"}, "Left", [](auto zones) { |
|
72 | QStringList{"Align Temporally"}, "Left", [](auto zones) { | |
71 | Q_ASSERT(zones.count() > 1); |
|
73 | Q_ASSERT(zones.count() > 1); | |
72 | auto ref = zones.takeFirst(); |
|
74 | auto ref = zones.takeFirst(); | |
73 | ref->alignZonesTemporallyOnLeft(zones, false); |
|
75 | ref->alignZonesTemporallyOnLeft(zones, false); | |
74 | }); |
|
76 | }); | |
75 | alignLeftTemporallyAction->setEnableFunction(alignEnableFuntion); |
|
77 | alignLeftTemporallyAction->setEnableFunction(alignEnableFuntion); | |
76 |
|
78 | |||
77 | auto alignLeftBorderTemporallyAction = actionController.addSectionZoneAction( |
|
79 | auto alignLeftBorderTemporallyAction = actionController.addSectionZoneAction( | |
78 | QStringList{"Align Temporally"}, "Left Borders", [](auto zones) { |
|
80 | QStringList{"Align Temporally"}, "Left Borders", [](auto zones) { | |
79 | Q_ASSERT(zones.count() > 1); |
|
81 | Q_ASSERT(zones.count() > 1); | |
80 | auto ref = zones.takeFirst(); |
|
82 | auto ref = zones.takeFirst(); | |
81 | ref->alignZonesTemporallyOnLeft(zones, true); |
|
83 | ref->alignZonesTemporallyOnLeft(zones, true); | |
82 | }); |
|
84 | }); | |
83 | alignLeftBorderTemporallyAction->setEnableFunction(alignEnableFuntion); |
|
85 | alignLeftBorderTemporallyAction->setEnableFunction(alignEnableFuntion); | |
84 |
|
86 | |||
85 | auto alignRightTemporallyAction = actionController.addSectionZoneAction( |
|
87 | auto alignRightTemporallyAction = actionController.addSectionZoneAction( | |
86 | QStringList{"Align Temporally"}, "Right", [](auto zones) { |
|
88 | QStringList{"Align Temporally"}, "Right", [](auto zones) { | |
87 | Q_ASSERT(zones.count() > 1); |
|
89 | Q_ASSERT(zones.count() > 1); | |
88 | auto ref = zones.takeFirst(); |
|
90 | auto ref = zones.takeFirst(); | |
89 | ref->alignZonesTemporallyOnRight(zones, false); |
|
91 | ref->alignZonesTemporallyOnRight(zones, false); | |
90 | }); |
|
92 | }); | |
91 | alignRightTemporallyAction->setEnableFunction(alignEnableFuntion); |
|
93 | alignRightTemporallyAction->setEnableFunction(alignEnableFuntion); | |
92 |
|
94 | |||
93 | auto alignRightBorderTemporallyAction = actionController.addSectionZoneAction( |
|
95 | auto alignRightBorderTemporallyAction = actionController.addSectionZoneAction( | |
94 | QStringList{"Align Temporally"}, "Right Borders", [](auto zones) { |
|
96 | QStringList{"Align Temporally"}, "Right Borders", [](auto zones) { | |
95 | Q_ASSERT(zones.count() > 1); |
|
97 | Q_ASSERT(zones.count() > 1); | |
96 | auto ref = zones.takeFirst(); |
|
98 | auto ref = zones.takeFirst(); | |
97 | ref->alignZonesTemporallyOnRight(zones, true); |
|
99 | ref->alignZonesTemporallyOnRight(zones, true); | |
98 | }); |
|
100 | }); | |
99 | alignRightBorderTemporallyAction->setEnableFunction(alignEnableFuntion); |
|
101 | alignRightBorderTemporallyAction->setEnableFunction(alignEnableFuntion); | |
100 |
|
102 | |||
101 | auto alignLeftAndRightTemporallyAction = actionController.addSectionZoneAction( |
|
103 | auto alignLeftAndRightTemporallyAction = actionController.addSectionZoneAction( | |
102 | QStringList{"Align Temporally"}, "Left and Right", [](auto zones) { |
|
104 | QStringList{"Align Temporally"}, "Left and Right", [](auto zones) { | |
103 | Q_ASSERT(zones.count() > 1); |
|
105 | Q_ASSERT(zones.count() > 1); | |
104 | auto ref = zones.takeFirst(); |
|
106 | auto ref = zones.takeFirst(); | |
105 | ref->alignZonesTemporallyOnLeft(zones, false); |
|
107 | ref->alignZonesTemporallyOnLeft(zones, false); | |
106 | ref->alignZonesTemporallyOnRight(zones, true); |
|
108 | ref->alignZonesTemporallyOnRight(zones, true); | |
107 | }); |
|
109 | }); | |
108 | alignLeftAndRightTemporallyAction->setEnableFunction(alignEnableFuntion); |
|
110 | alignLeftAndRightTemporallyAction->setEnableFunction(alignEnableFuntion); | |
109 | } |
|
111 | } |
@@ -1,1004 +1,1003 | |||||
1 | #include "Visualization/VisualizationGraphWidget.h" |
|
1 | #include "Visualization/VisualizationGraphWidget.h" | |
2 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
2 | #include "Visualization/IVisualizationWidgetVisitor.h" | |
3 | #include "Visualization/VisualizationCursorItem.h" |
|
3 | #include "Visualization/VisualizationCursorItem.h" | |
4 | #include "Visualization/VisualizationDefs.h" |
|
4 | #include "Visualization/VisualizationDefs.h" | |
5 | #include "Visualization/VisualizationGraphHelper.h" |
|
5 | #include "Visualization/VisualizationGraphHelper.h" | |
6 | #include "Visualization/VisualizationGraphRenderingDelegate.h" |
|
6 | #include "Visualization/VisualizationGraphRenderingDelegate.h" | |
7 | #include "Visualization/VisualizationMultiZoneSelectionDialog.h" |
|
7 | #include "Visualization/VisualizationMultiZoneSelectionDialog.h" | |
8 | #include "Visualization/VisualizationSelectionZoneItem.h" |
|
8 | #include "Visualization/VisualizationSelectionZoneItem.h" | |
9 | #include "Visualization/VisualizationSelectionZoneManager.h" |
|
9 | #include "Visualization/VisualizationSelectionZoneManager.h" | |
10 | #include "Visualization/VisualizationWidget.h" |
|
10 | #include "Visualization/VisualizationWidget.h" | |
11 | #include "Visualization/VisualizationZoneWidget.h" |
|
11 | #include "Visualization/VisualizationZoneWidget.h" | |
12 | #include "ui_VisualizationGraphWidget.h" |
|
12 | #include "ui_VisualizationGraphWidget.h" | |
13 |
|
13 | |||
14 | #include <Actions/ActionsGuiController.h> |
|
14 | #include <Actions/ActionsGuiController.h> | |
15 | #include <Common/MimeTypesDef.h> |
|
15 | #include <Common/MimeTypesDef.h> | |
16 | #include <Data/ArrayData.h> |
|
16 | #include <Data/ArrayData.h> | |
17 | #include <Data/IDataSeries.h> |
|
17 | #include <Data/IDataSeries.h> | |
18 | #include <Data/SpectrogramSeries.h> |
|
18 | #include <Data/SpectrogramSeries.h> | |
19 | #include <DragAndDrop/DragDropGuiController.h> |
|
19 | #include <DragAndDrop/DragDropGuiController.h> | |
20 | #include <Settings/SqpSettingsDefs.h> |
|
20 | #include <Settings/SqpSettingsDefs.h> | |
21 | #include <SqpApplication.h> |
|
21 | #include <SqpApplication.h> | |
22 | #include <Time/TimeController.h> |
|
22 | #include <Time/TimeController.h> | |
23 | #include <Variable/Variable.h> |
|
23 | #include <Variable/Variable.h> | |
24 | #include <Variable/VariableController.h> |
|
24 | #include <Variable/VariableController.h> | |
25 |
|
25 | |||
26 | #include <unordered_map> |
|
26 | #include <unordered_map> | |
27 |
|
27 | |||
28 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget") |
|
28 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget") | |
29 |
|
29 | |||
30 | namespace { |
|
30 | namespace { | |
31 |
|
31 | |||
32 | /// Key pressed to enable drag&drop in all modes |
|
32 | /// Key pressed to enable drag&drop in all modes | |
33 | const auto DRAG_DROP_MODIFIER = Qt::AltModifier; |
|
33 | const auto DRAG_DROP_MODIFIER = Qt::AltModifier; | |
34 |
|
34 | |||
35 | /// Key pressed to enable zoom on horizontal axis |
|
35 | /// Key pressed to enable zoom on horizontal axis | |
36 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::ControlModifier; |
|
36 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::ControlModifier; | |
37 |
|
37 | |||
38 | /// Key pressed to enable zoom on vertical axis |
|
38 | /// Key pressed to enable zoom on vertical axis | |
39 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ShiftModifier; |
|
39 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ShiftModifier; | |
40 |
|
40 | |||
41 | /// Speed of a step of a wheel event for a pan, in percentage of the axis range |
|
41 | /// Speed of a step of a wheel event for a pan, in percentage of the axis range | |
42 | const auto PAN_SPEED = 5; |
|
42 | const auto PAN_SPEED = 5; | |
43 |
|
43 | |||
44 | /// Key pressed to enable a calibration pan |
|
44 | /// Key pressed to enable a calibration pan | |
45 | const auto VERTICAL_PAN_MODIFIER = Qt::AltModifier; |
|
45 | const auto VERTICAL_PAN_MODIFIER = Qt::AltModifier; | |
46 |
|
46 | |||
47 | /// Key pressed to enable multi selection of selection zones |
|
47 | /// Key pressed to enable multi selection of selection zones | |
48 | const auto MULTI_ZONE_SELECTION_MODIFIER = Qt::ControlModifier; |
|
48 | const auto MULTI_ZONE_SELECTION_MODIFIER = Qt::ControlModifier; | |
49 |
|
49 | |||
50 | /// Minimum size for the zoom box, in percentage of the axis range |
|
50 | /// Minimum size for the zoom box, in percentage of the axis range | |
51 | const auto ZOOM_BOX_MIN_SIZE = 0.8; |
|
51 | const auto ZOOM_BOX_MIN_SIZE = 0.8; | |
52 |
|
52 | |||
53 | /// Format of the dates appearing in the label of a cursor |
|
53 | /// Format of the dates appearing in the label of a cursor | |
54 | const auto CURSOR_LABELS_DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd\nhh:mm:ss:zzz"); |
|
54 | const auto CURSOR_LABELS_DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd\nhh:mm:ss:zzz"); | |
55 |
|
55 | |||
56 | } // namespace |
|
56 | } // namespace | |
57 |
|
57 | |||
58 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { |
|
58 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { | |
59 |
|
59 | |||
60 | explicit VisualizationGraphWidgetPrivate(const QString &name) |
|
60 | explicit VisualizationGraphWidgetPrivate(const QString &name) | |
61 | : m_Name{name}, |
|
61 | : m_Name{name}, | |
62 | m_DoAcquisition{true}, |
|
62 | m_DoAcquisition{true}, | |
63 | m_IsCalibration{false}, |
|
63 | m_IsCalibration{false}, | |
64 | m_RenderingDelegate{nullptr} |
|
64 | m_RenderingDelegate{nullptr} | |
65 | { |
|
65 | { | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | void updateData(PlottablesMap &plottables, std::shared_ptr<IDataSeries> dataSeries, |
|
68 | void updateData(PlottablesMap &plottables, std::shared_ptr<IDataSeries> dataSeries, | |
69 | const SqpRange &range) |
|
69 | const SqpRange &range) | |
70 | { |
|
70 | { | |
71 | VisualizationGraphHelper::updateData(plottables, dataSeries, range); |
|
71 | VisualizationGraphHelper::updateData(plottables, dataSeries, range); | |
72 |
|
72 | |||
73 | // Prevents that data has changed to update rendering |
|
73 | // Prevents that data has changed to update rendering | |
74 | m_RenderingDelegate->onPlotUpdated(); |
|
74 | m_RenderingDelegate->onPlotUpdated(); | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | QString m_Name; |
|
77 | QString m_Name; | |
78 | // 1 variable -> n qcpplot |
|
78 | // 1 variable -> n qcpplot | |
79 | std::map<std::shared_ptr<Variable>, PlottablesMap> m_VariableToPlotMultiMap; |
|
79 | std::map<std::shared_ptr<Variable>, PlottablesMap> m_VariableToPlotMultiMap; | |
80 | bool m_DoAcquisition; |
|
80 | bool m_DoAcquisition; | |
81 | bool m_IsCalibration; |
|
81 | bool m_IsCalibration; | |
82 | /// Delegate used to attach rendering features to the plot |
|
82 | /// Delegate used to attach rendering features to the plot | |
83 | std::unique_ptr<VisualizationGraphRenderingDelegate> m_RenderingDelegate; |
|
83 | std::unique_ptr<VisualizationGraphRenderingDelegate> m_RenderingDelegate; | |
84 |
|
84 | |||
85 | QCPItemRect *m_DrawingZoomRect = nullptr; |
|
85 | QCPItemRect *m_DrawingZoomRect = nullptr; | |
86 | QStack<QPair<QCPRange, QCPRange> > m_ZoomStack; |
|
86 | QStack<QPair<QCPRange, QCPRange> > m_ZoomStack; | |
87 |
|
87 | |||
88 | std::unique_ptr<VisualizationCursorItem> m_HorizontalCursor = nullptr; |
|
88 | std::unique_ptr<VisualizationCursorItem> m_HorizontalCursor = nullptr; | |
89 | std::unique_ptr<VisualizationCursorItem> m_VerticalCursor = nullptr; |
|
89 | std::unique_ptr<VisualizationCursorItem> m_VerticalCursor = nullptr; | |
90 |
|
90 | |||
91 | VisualizationSelectionZoneItem *m_DrawingZone = nullptr; |
|
91 | VisualizationSelectionZoneItem *m_DrawingZone = nullptr; | |
92 | VisualizationSelectionZoneItem *m_HoveredZone = nullptr; |
|
92 | VisualizationSelectionZoneItem *m_HoveredZone = nullptr; | |
93 | QVector<VisualizationSelectionZoneItem *> m_SelectionZones; |
|
93 | QVector<VisualizationSelectionZoneItem *> m_SelectionZones; | |
94 |
|
94 | |||
95 | bool m_HasMovedMouse = false; // Indicates if the mouse moved in a releaseMouse even |
|
95 | bool m_HasMovedMouse = false; // Indicates if the mouse moved in a releaseMouse even | |
96 |
|
96 | |||
97 | void startDrawingRect(const QPoint &pos, QCustomPlot &plot) |
|
97 | void startDrawingRect(const QPoint &pos, QCustomPlot &plot) | |
98 | { |
|
98 | { | |
99 | removeDrawingRect(plot); |
|
99 | removeDrawingRect(plot); | |
100 |
|
100 | |||
101 | auto axisPos = posToAxisPos(pos, plot); |
|
101 | auto axisPos = posToAxisPos(pos, plot); | |
102 |
|
102 | |||
103 | m_DrawingZoomRect = new QCPItemRect{&plot}; |
|
103 | m_DrawingZoomRect = new QCPItemRect{&plot}; | |
104 | QPen p; |
|
104 | QPen p; | |
105 | p.setWidth(2); |
|
105 | p.setWidth(2); | |
106 | m_DrawingZoomRect->setPen(p); |
|
106 | m_DrawingZoomRect->setPen(p); | |
107 |
|
107 | |||
108 | m_DrawingZoomRect->topLeft->setCoords(axisPos); |
|
108 | m_DrawingZoomRect->topLeft->setCoords(axisPos); | |
109 | m_DrawingZoomRect->bottomRight->setCoords(axisPos); |
|
109 | m_DrawingZoomRect->bottomRight->setCoords(axisPos); | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | void removeDrawingRect(QCustomPlot &plot) |
|
112 | void removeDrawingRect(QCustomPlot &plot) | |
113 | { |
|
113 | { | |
114 | if (m_DrawingZoomRect) { |
|
114 | if (m_DrawingZoomRect) { | |
115 | plot.removeItem(m_DrawingZoomRect); // the item is deleted by QCustomPlot |
|
115 | plot.removeItem(m_DrawingZoomRect); // the item is deleted by QCustomPlot | |
116 | m_DrawingZoomRect = nullptr; |
|
116 | m_DrawingZoomRect = nullptr; | |
117 | plot.replot(QCustomPlot::rpQueuedReplot); |
|
117 | plot.replot(QCustomPlot::rpQueuedReplot); | |
118 | } |
|
118 | } | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | void startDrawingZone(const QPoint &pos, VisualizationGraphWidget *graph) |
|
121 | void startDrawingZone(const QPoint &pos, VisualizationGraphWidget *graph) | |
122 | { |
|
122 | { | |
123 | endDrawingZone(graph); |
|
123 | endDrawingZone(graph); | |
124 |
|
124 | |||
125 | auto axisPos = posToAxisPos(pos, graph->plot()); |
|
125 | auto axisPos = posToAxisPos(pos, graph->plot()); | |
126 |
|
126 | |||
127 | m_DrawingZone = new VisualizationSelectionZoneItem{&graph->plot()}; |
|
127 | m_DrawingZone = new VisualizationSelectionZoneItem{&graph->plot()}; | |
128 | m_DrawingZone->setRange(axisPos.x(), axisPos.x()); |
|
128 | m_DrawingZone->setRange(axisPos.x(), axisPos.x()); | |
129 | m_DrawingZone->setEditionEnabled(false); |
|
129 | m_DrawingZone->setEditionEnabled(false); | |
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | void endDrawingZone(VisualizationGraphWidget *graph) |
|
132 | void endDrawingZone(VisualizationGraphWidget *graph) | |
133 | { |
|
133 | { | |
134 | if (m_DrawingZone) { |
|
134 | if (m_DrawingZone) { | |
135 | auto drawingZoneRange = m_DrawingZone->range(); |
|
135 | auto drawingZoneRange = m_DrawingZone->range(); | |
136 | if (qAbs(drawingZoneRange.m_TEnd - drawingZoneRange.m_TStart) > 0) { |
|
136 | if (qAbs(drawingZoneRange.m_TEnd - drawingZoneRange.m_TStart) > 0) { | |
137 | m_DrawingZone->setEditionEnabled(true); |
|
137 | m_DrawingZone->setEditionEnabled(true); | |
138 | addSelectionZone(m_DrawingZone); |
|
138 | addSelectionZone(m_DrawingZone); | |
139 | } |
|
139 | } | |
140 | else { |
|
140 | else { | |
141 | graph->plot().removeItem(m_DrawingZone); // the item is deleted by QCustomPlot |
|
141 | graph->plot().removeItem(m_DrawingZone); // the item is deleted by QCustomPlot | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | graph->plot().replot(QCustomPlot::rpQueuedReplot); |
|
144 | graph->plot().replot(QCustomPlot::rpQueuedReplot); | |
145 | m_DrawingZone = nullptr; |
|
145 | m_DrawingZone = nullptr; | |
146 | } |
|
146 | } | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | void setSelectionZonesEditionEnabled(bool value) |
|
149 | void setSelectionZonesEditionEnabled(bool value) | |
150 | { |
|
150 | { | |
151 | for (auto s : m_SelectionZones) { |
|
151 | for (auto s : m_SelectionZones) { | |
152 | s->setEditionEnabled(value); |
|
152 | s->setEditionEnabled(value); | |
153 | } |
|
153 | } | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | void addSelectionZone(VisualizationSelectionZoneItem *zone) { m_SelectionZones << zone; } |
|
156 | void addSelectionZone(VisualizationSelectionZoneItem *zone) { m_SelectionZones << zone; } | |
157 |
|
157 | |||
158 | VisualizationSelectionZoneItem *selectionZoneAt(const QPoint &pos, |
|
158 | VisualizationSelectionZoneItem *selectionZoneAt(const QPoint &pos, | |
159 | const QCustomPlot &plot) const |
|
159 | const QCustomPlot &plot) const | |
160 | { |
|
160 | { | |
161 | VisualizationSelectionZoneItem *selectionZoneItemUnderCursor = nullptr; |
|
161 | VisualizationSelectionZoneItem *selectionZoneItemUnderCursor = nullptr; | |
162 | auto minDistanceToZone = -1; |
|
162 | auto minDistanceToZone = -1; | |
163 | for (auto zone : m_SelectionZones) { |
|
163 | for (auto zone : m_SelectionZones) { | |
164 | auto distanceToZone = zone->selectTest(pos, false); |
|
164 | auto distanceToZone = zone->selectTest(pos, false); | |
165 | if ((minDistanceToZone < 0 || distanceToZone <= minDistanceToZone) |
|
165 | if ((minDistanceToZone < 0 || distanceToZone <= minDistanceToZone) | |
166 | && distanceToZone >= 0 && distanceToZone < plot.selectionTolerance()) { |
|
166 | && distanceToZone >= 0 && distanceToZone < plot.selectionTolerance()) { | |
167 | selectionZoneItemUnderCursor = zone; |
|
167 | selectionZoneItemUnderCursor = zone; | |
168 | } |
|
168 | } | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | return selectionZoneItemUnderCursor; |
|
171 | return selectionZoneItemUnderCursor; | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | QVector<VisualizationSelectionZoneItem *> selectionZonesAt(const QPoint &pos, |
|
174 | QVector<VisualizationSelectionZoneItem *> selectionZonesAt(const QPoint &pos, | |
175 | const QCustomPlot &plot) const |
|
175 | const QCustomPlot &plot) const | |
176 | { |
|
176 | { | |
177 | QVector<VisualizationSelectionZoneItem *> zones; |
|
177 | QVector<VisualizationSelectionZoneItem *> zones; | |
178 | for (auto zone : m_SelectionZones) { |
|
178 | for (auto zone : m_SelectionZones) { | |
179 | auto distanceToZone = zone->selectTest(pos, false); |
|
179 | auto distanceToZone = zone->selectTest(pos, false); | |
180 | if (distanceToZone >= 0 && distanceToZone < plot.selectionTolerance()) { |
|
180 | if (distanceToZone >= 0 && distanceToZone < plot.selectionTolerance()) { | |
181 | zones << zone; |
|
181 | zones << zone; | |
182 | } |
|
182 | } | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | return zones; |
|
185 | return zones; | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | void moveSelectionZoneOnTop(VisualizationSelectionZoneItem *zone, QCustomPlot &plot) |
|
188 | void moveSelectionZoneOnTop(VisualizationSelectionZoneItem *zone, QCustomPlot &plot) | |
189 | { |
|
189 | { | |
190 | if (!m_SelectionZones.isEmpty() && m_SelectionZones.last() != zone) { |
|
190 | if (!m_SelectionZones.isEmpty() && m_SelectionZones.last() != zone) { | |
191 | zone->moveToTop(); |
|
191 | zone->moveToTop(); | |
192 | m_SelectionZones.removeAll(zone); |
|
192 | m_SelectionZones.removeAll(zone); | |
193 | m_SelectionZones.append(zone); |
|
193 | m_SelectionZones.append(zone); | |
194 | } |
|
194 | } | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | QPointF posToAxisPos(const QPoint &pos, QCustomPlot &plot) const |
|
197 | QPointF posToAxisPos(const QPoint &pos, QCustomPlot &plot) const | |
198 | { |
|
198 | { | |
199 | auto axisX = plot.axisRect()->axis(QCPAxis::atBottom); |
|
199 | auto axisX = plot.axisRect()->axis(QCPAxis::atBottom); | |
200 | auto axisY = plot.axisRect()->axis(QCPAxis::atLeft); |
|
200 | auto axisY = plot.axisRect()->axis(QCPAxis::atLeft); | |
201 | return QPointF{axisX->pixelToCoord(pos.x()), axisY->pixelToCoord(pos.y())}; |
|
201 | return QPointF{axisX->pixelToCoord(pos.x()), axisY->pixelToCoord(pos.y())}; | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | bool pointIsInAxisRect(const QPointF &axisPoint, QCustomPlot &plot) const |
|
204 | bool pointIsInAxisRect(const QPointF &axisPoint, QCustomPlot &plot) const | |
205 | { |
|
205 | { | |
206 | auto axisX = plot.axisRect()->axis(QCPAxis::atBottom); |
|
206 | auto axisX = plot.axisRect()->axis(QCPAxis::atBottom); | |
207 | auto axisY = plot.axisRect()->axis(QCPAxis::atLeft); |
|
207 | auto axisY = plot.axisRect()->axis(QCPAxis::atLeft); | |
208 | return axisX->range().contains(axisPoint.x()) && axisY->range().contains(axisPoint.y()); |
|
208 | return axisX->range().contains(axisPoint.x()) && axisY->range().contains(axisPoint.y()); | |
209 | } |
|
209 | } | |
210 | }; |
|
210 | }; | |
211 |
|
211 | |||
212 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) |
|
212 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) | |
213 | : VisualizationDragWidget{parent}, |
|
213 | : VisualizationDragWidget{parent}, | |
214 | ui{new Ui::VisualizationGraphWidget}, |
|
214 | ui{new Ui::VisualizationGraphWidget}, | |
215 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>(name)} |
|
215 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>(name)} | |
216 | { |
|
216 | { | |
217 | ui->setupUi(this); |
|
217 | ui->setupUi(this); | |
218 |
|
218 | |||
219 | // 'Close' options : widget is deleted when closed |
|
219 | // 'Close' options : widget is deleted when closed | |
220 | setAttribute(Qt::WA_DeleteOnClose); |
|
220 | setAttribute(Qt::WA_DeleteOnClose); | |
221 |
|
221 | |||
222 | // Set qcpplot properties : |
|
222 | // Set qcpplot properties : | |
223 | // - zoom is enabled |
|
223 | // - zoom is enabled | |
224 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation |
|
224 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation | |
225 | ui->widget->setInteractions(QCP::iRangeZoom); |
|
225 | ui->widget->setInteractions(QCP::iRangeZoom); | |
226 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal | Qt::Vertical); |
|
226 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal | Qt::Vertical); | |
227 |
|
227 | |||
228 | // The delegate must be initialized after the ui as it uses the plot |
|
228 | // The delegate must be initialized after the ui as it uses the plot | |
229 | impl->m_RenderingDelegate = std::make_unique<VisualizationGraphRenderingDelegate>(*this); |
|
229 | impl->m_RenderingDelegate = std::make_unique<VisualizationGraphRenderingDelegate>(*this); | |
230 |
|
230 | |||
231 | // Init the cursors |
|
231 | // Init the cursors | |
232 | impl->m_HorizontalCursor = std::make_unique<VisualizationCursorItem>(&plot()); |
|
232 | impl->m_HorizontalCursor = std::make_unique<VisualizationCursorItem>(&plot()); | |
233 | impl->m_HorizontalCursor->setOrientation(Qt::Horizontal); |
|
233 | impl->m_HorizontalCursor->setOrientation(Qt::Horizontal); | |
234 | impl->m_VerticalCursor = std::make_unique<VisualizationCursorItem>(&plot()); |
|
234 | impl->m_VerticalCursor = std::make_unique<VisualizationCursorItem>(&plot()); | |
235 | impl->m_VerticalCursor->setOrientation(Qt::Vertical); |
|
235 | impl->m_VerticalCursor->setOrientation(Qt::Vertical); | |
236 |
|
236 | |||
237 | connect(ui->widget, &QCustomPlot::mousePress, this, &VisualizationGraphWidget::onMousePress); |
|
237 | connect(ui->widget, &QCustomPlot::mousePress, this, &VisualizationGraphWidget::onMousePress); | |
238 | connect(ui->widget, &QCustomPlot::mouseRelease, this, |
|
238 | connect(ui->widget, &QCustomPlot::mouseRelease, this, | |
239 | &VisualizationGraphWidget::onMouseRelease); |
|
239 | &VisualizationGraphWidget::onMouseRelease); | |
240 | connect(ui->widget, &QCustomPlot::mouseMove, this, &VisualizationGraphWidget::onMouseMove); |
|
240 | connect(ui->widget, &QCustomPlot::mouseMove, this, &VisualizationGraphWidget::onMouseMove); | |
241 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); |
|
241 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); | |
242 | connect(ui->widget, &QCustomPlot::mouseDoubleClick, this, |
|
242 | connect(ui->widget, &QCustomPlot::mouseDoubleClick, this, | |
243 | &VisualizationGraphWidget::onMouseDoubleClick); |
|
243 | &VisualizationGraphWidget::onMouseDoubleClick); | |
244 | connect( |
|
244 | connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>( | |
245 | ui->widget->xAxis, |
|
245 | &QCPAxis::rangeChanged), | |
246 | static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(&QCPAxis::rangeChanged), |
|
|||
247 | this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection); |
|
246 | this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection); | |
248 |
|
247 | |||
249 | // Activates menu when right clicking on the graph |
|
248 | // Activates menu when right clicking on the graph | |
250 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); |
|
249 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); | |
251 | connect(ui->widget, &QCustomPlot::customContextMenuRequested, this, |
|
250 | connect(ui->widget, &QCustomPlot::customContextMenuRequested, this, | |
252 | &VisualizationGraphWidget::onGraphMenuRequested); |
|
251 | &VisualizationGraphWidget::onGraphMenuRequested); | |
253 |
|
252 | |||
254 | connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(), |
|
253 | connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(), | |
255 | &VariableController::onRequestDataLoading); |
|
254 | &VariableController::onRequestDataLoading); | |
256 |
|
255 | |||
257 | connect(&sqpApp->variableController(), &VariableController::updateVarDisplaying, this, |
|
256 | connect(&sqpApp->variableController(), &VariableController::updateVarDisplaying, this, | |
258 | &VisualizationGraphWidget::onUpdateVarDisplaying); |
|
257 | &VisualizationGraphWidget::onUpdateVarDisplaying); | |
259 |
|
258 | |||
260 | #ifdef Q_OS_MAC |
|
259 | #ifdef Q_OS_MAC | |
261 | plot().setPlottingHint(QCP::phFastPolylines, true); |
|
260 | plot().setPlottingHint(QCP::phFastPolylines, true); | |
262 | #endif |
|
261 | #endif | |
263 | } |
|
262 | } | |
264 |
|
263 | |||
265 |
|
264 | |||
266 | VisualizationGraphWidget::~VisualizationGraphWidget() |
|
265 | VisualizationGraphWidget::~VisualizationGraphWidget() | |
267 | { |
|
266 | { | |
268 | delete ui; |
|
267 | delete ui; | |
269 | } |
|
268 | } | |
270 |
|
269 | |||
271 | VisualizationZoneWidget *VisualizationGraphWidget::parentZoneWidget() const noexcept |
|
270 | VisualizationZoneWidget *VisualizationGraphWidget::parentZoneWidget() const noexcept | |
272 | { |
|
271 | { | |
273 | auto parent = parentWidget(); |
|
272 | auto parent = parentWidget(); | |
274 | while (parent != nullptr && !qobject_cast<VisualizationZoneWidget *>(parent)) { |
|
273 | while (parent != nullptr && !qobject_cast<VisualizationZoneWidget *>(parent)) { | |
275 | parent = parent->parentWidget(); |
|
274 | parent = parent->parentWidget(); | |
276 | } |
|
275 | } | |
277 |
|
276 | |||
278 | return qobject_cast<VisualizationZoneWidget *>(parent); |
|
277 | return qobject_cast<VisualizationZoneWidget *>(parent); | |
279 | } |
|
278 | } | |
280 |
|
279 | |||
281 | VisualizationWidget *VisualizationGraphWidget::parentVisualizationWidget() const |
|
280 | VisualizationWidget *VisualizationGraphWidget::parentVisualizationWidget() const | |
282 | { |
|
281 | { | |
283 | auto parent = parentWidget(); |
|
282 | auto parent = parentWidget(); | |
284 | while (parent != nullptr && !qobject_cast<VisualizationWidget *>(parent)) { |
|
283 | while (parent != nullptr && !qobject_cast<VisualizationWidget *>(parent)) { | |
285 | parent = parent->parentWidget(); |
|
284 | parent = parent->parentWidget(); | |
286 | } |
|
285 | } | |
287 |
|
286 | |||
288 | return qobject_cast<VisualizationWidget *>(parent); |
|
287 | return qobject_cast<VisualizationWidget *>(parent); | |
289 | } |
|
288 | } | |
290 |
|
289 | |||
291 | void VisualizationGraphWidget::enableAcquisition(bool enable) |
|
290 | void VisualizationGraphWidget::enableAcquisition(bool enable) | |
292 | { |
|
291 | { | |
293 | impl->m_DoAcquisition = enable; |
|
292 | impl->m_DoAcquisition = enable; | |
294 | } |
|
293 | } | |
295 |
|
294 | |||
296 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, SqpRange range) |
|
295 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, SqpRange range) | |
297 | { |
|
296 | { | |
298 | // Uses delegate to create the qcpplot components according to the variable |
|
297 | // Uses delegate to create the qcpplot components according to the variable | |
299 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); |
|
298 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); | |
300 |
|
299 | |||
301 | if (auto dataSeries = variable->dataSeries()) { |
|
300 | if (auto dataSeries = variable->dataSeries()) { | |
302 | // Set axes properties according to the units of the data series |
|
301 | // Set axes properties according to the units of the data series | |
303 | impl->m_RenderingDelegate->setAxesProperties(dataSeries); |
|
302 | impl->m_RenderingDelegate->setAxesProperties(dataSeries); | |
304 |
|
303 | |||
305 | // Sets rendering properties for the new plottables |
|
304 | // Sets rendering properties for the new plottables | |
306 | // Warning: this method must be called after setAxesProperties(), as it can access to some |
|
305 | // Warning: this method must be called after setAxesProperties(), as it can access to some | |
307 | // axes properties that have to be initialized |
|
306 | // axes properties that have to be initialized | |
308 | impl->m_RenderingDelegate->setPlottablesProperties(dataSeries, createdPlottables); |
|
307 | impl->m_RenderingDelegate->setPlottablesProperties(dataSeries, createdPlottables); | |
309 | } |
|
308 | } | |
310 |
|
309 | |||
311 | impl->m_VariableToPlotMultiMap.insert({variable, std::move(createdPlottables)}); |
|
310 | impl->m_VariableToPlotMultiMap.insert({variable, std::move(createdPlottables)}); | |
312 |
|
311 | |||
313 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); |
|
312 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); | |
314 |
|
313 | |||
315 | this->enableAcquisition(false); |
|
314 | this->enableAcquisition(false); | |
316 | this->setGraphRange(range); |
|
315 | this->setGraphRange(range); | |
317 | this->enableAcquisition(true); |
|
316 | this->enableAcquisition(true); | |
318 |
|
317 | |||
319 | emit requestDataLoading(QVector<std::shared_ptr<Variable> >() << variable, range, false); |
|
318 | emit requestDataLoading(QVector<std::shared_ptr<Variable> >() << variable, range, false); | |
320 |
|
319 | |||
321 | emit variableAdded(variable); |
|
320 | emit variableAdded(variable); | |
322 | } |
|
321 | } | |
323 |
|
322 | |||
324 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept |
|
323 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept | |
325 | { |
|
324 | { | |
326 | // Each component associated to the variable : |
|
325 | // Each component associated to the variable : | |
327 | // - is removed from qcpplot (which deletes it) |
|
326 | // - is removed from qcpplot (which deletes it) | |
328 | // - is no longer referenced in the map |
|
327 | // - is no longer referenced in the map | |
329 | auto variableIt = impl->m_VariableToPlotMultiMap.find(variable); |
|
328 | auto variableIt = impl->m_VariableToPlotMultiMap.find(variable); | |
330 | if (variableIt != impl->m_VariableToPlotMultiMap.cend()) { |
|
329 | if (variableIt != impl->m_VariableToPlotMultiMap.cend()) { | |
331 | emit variableAboutToBeRemoved(variable); |
|
330 | emit variableAboutToBeRemoved(variable); | |
332 |
|
331 | |||
333 | auto &plottablesMap = variableIt->second; |
|
332 | auto &plottablesMap = variableIt->second; | |
334 |
|
333 | |||
335 | for (auto plottableIt = plottablesMap.cbegin(), plottableEnd = plottablesMap.cend(); |
|
334 | for (auto plottableIt = plottablesMap.cbegin(), plottableEnd = plottablesMap.cend(); | |
336 | plottableIt != plottableEnd;) { |
|
335 | plottableIt != plottableEnd;) { | |
337 | ui->widget->removePlottable(plottableIt->second); |
|
336 | ui->widget->removePlottable(plottableIt->second); | |
338 | plottableIt = plottablesMap.erase(plottableIt); |
|
337 | plottableIt = plottablesMap.erase(plottableIt); | |
339 | } |
|
338 | } | |
340 |
|
339 | |||
341 | impl->m_VariableToPlotMultiMap.erase(variableIt); |
|
340 | impl->m_VariableToPlotMultiMap.erase(variableIt); | |
342 | } |
|
341 | } | |
343 |
|
342 | |||
344 | // Updates graph |
|
343 | // Updates graph | |
345 | ui->widget->replot(); |
|
344 | ui->widget->replot(); | |
346 | } |
|
345 | } | |
347 |
|
346 | |||
348 | QList<std::shared_ptr<Variable> > VisualizationGraphWidget::variables() const |
|
347 | QList<std::shared_ptr<Variable> > VisualizationGraphWidget::variables() const | |
349 | { |
|
348 | { | |
350 | auto variables = QList<std::shared_ptr<Variable> >{}; |
|
349 | auto variables = QList<std::shared_ptr<Variable> >{}; | |
351 | for (auto it = std::cbegin(impl->m_VariableToPlotMultiMap); |
|
350 | for (auto it = std::cbegin(impl->m_VariableToPlotMultiMap); | |
352 | it != std::cend(impl->m_VariableToPlotMultiMap); ++it) { |
|
351 | it != std::cend(impl->m_VariableToPlotMultiMap); ++it) { | |
353 | variables << it->first; |
|
352 | variables << it->first; | |
354 | } |
|
353 | } | |
355 |
|
354 | |||
356 | return variables; |
|
355 | return variables; | |
357 | } |
|
356 | } | |
358 |
|
357 | |||
359 | void VisualizationGraphWidget::setYRange(std::shared_ptr<Variable> variable) |
|
358 | void VisualizationGraphWidget::setYRange(std::shared_ptr<Variable> variable) | |
360 | { |
|
359 | { | |
361 | if (!variable) { |
|
360 | if (!variable) { | |
362 | qCCritical(LOG_VisualizationGraphWidget()) << "Can't set y-axis range: variable is null"; |
|
361 | qCCritical(LOG_VisualizationGraphWidget()) << "Can't set y-axis range: variable is null"; | |
363 | return; |
|
362 | return; | |
364 | } |
|
363 | } | |
365 |
|
364 | |||
366 | VisualizationGraphHelper::setYAxisRange(variable, *ui->widget); |
|
365 | VisualizationGraphHelper::setYAxisRange(variable, *ui->widget); | |
367 | } |
|
366 | } | |
368 |
|
367 | |||
369 | SqpRange VisualizationGraphWidget::graphRange() const noexcept |
|
368 | SqpRange VisualizationGraphWidget::graphRange() const noexcept | |
370 | { |
|
369 | { | |
371 | auto graphRange = ui->widget->xAxis->range(); |
|
370 | auto graphRange = ui->widget->xAxis->range(); | |
372 | return SqpRange{graphRange.lower, graphRange.upper}; |
|
371 | return SqpRange{graphRange.lower, graphRange.upper}; | |
373 | } |
|
372 | } | |
374 |
|
373 | |||
375 | void VisualizationGraphWidget::setGraphRange(const SqpRange &range) |
|
374 | void VisualizationGraphWidget::setGraphRange(const SqpRange &range) | |
376 | { |
|
375 | { | |
377 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START"); |
|
376 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START"); | |
378 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); |
|
377 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); | |
379 | ui->widget->replot(); |
|
378 | ui->widget->replot(); | |
380 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END"); |
|
379 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END"); | |
381 | } |
|
380 | } | |
382 |
|
381 | |||
383 | QVector<SqpRange> VisualizationGraphWidget::selectionZoneRanges() const |
|
382 | QVector<SqpRange> VisualizationGraphWidget::selectionZoneRanges() const | |
384 | { |
|
383 | { | |
385 | QVector<SqpRange> ranges; |
|
384 | QVector<SqpRange> ranges; | |
386 | for (auto zone : impl->m_SelectionZones) { |
|
385 | for (auto zone : impl->m_SelectionZones) { | |
387 | ranges << zone->range(); |
|
386 | ranges << zone->range(); | |
388 | } |
|
387 | } | |
389 |
|
388 | |||
390 | return ranges; |
|
389 | return ranges; | |
391 | } |
|
390 | } | |
392 |
|
391 | |||
393 | void VisualizationGraphWidget::addSelectionZones(const QVector<SqpRange> &ranges) |
|
392 | void VisualizationGraphWidget::addSelectionZones(const QVector<SqpRange> &ranges) | |
394 | { |
|
393 | { | |
395 | for (const auto &range : ranges) { |
|
394 | for (const auto &range : ranges) { | |
396 | // note: ownership is transfered to QCustomPlot |
|
395 | // note: ownership is transfered to QCustomPlot | |
397 | auto zone = new VisualizationSelectionZoneItem(&plot()); |
|
396 | auto zone = new VisualizationSelectionZoneItem(&plot()); | |
398 | zone->setRange(range.m_TStart, range.m_TEnd); |
|
397 | zone->setRange(range.m_TStart, range.m_TEnd); | |
399 | impl->addSelectionZone(zone); |
|
398 | impl->addSelectionZone(zone); | |
400 | } |
|
399 | } | |
401 |
|
400 | |||
402 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
401 | plot().replot(QCustomPlot::rpQueuedReplot); | |
403 | } |
|
402 | } | |
404 |
|
403 | |||
405 | void VisualizationGraphWidget::removeSelectionZone(VisualizationSelectionZoneItem *selectionZone) |
|
404 | void VisualizationGraphWidget::removeSelectionZone(VisualizationSelectionZoneItem *selectionZone) | |
406 | { |
|
405 | { | |
407 | parentVisualizationWidget()->selectionZoneManager().setSelected(selectionZone, false); |
|
406 | parentVisualizationWidget()->selectionZoneManager().setSelected(selectionZone, false); | |
408 |
|
407 | |||
409 | if (impl->m_HoveredZone == selectionZone) { |
|
408 | if (impl->m_HoveredZone == selectionZone) { | |
410 | impl->m_HoveredZone = nullptr; |
|
409 | impl->m_HoveredZone = nullptr; | |
411 | setCursor(Qt::ArrowCursor); |
|
410 | setCursor(Qt::ArrowCursor); | |
412 | } |
|
411 | } | |
413 |
|
412 | |||
414 | impl->m_SelectionZones.removeAll(selectionZone); |
|
413 | impl->m_SelectionZones.removeAll(selectionZone); | |
415 | plot().removeItem(selectionZone); |
|
414 | plot().removeItem(selectionZone); | |
416 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
415 | plot().replot(QCustomPlot::rpQueuedReplot); | |
417 | } |
|
416 | } | |
418 |
|
417 | |||
419 | void VisualizationGraphWidget::undoZoom() |
|
418 | void VisualizationGraphWidget::undoZoom() | |
420 | { |
|
419 | { | |
421 | auto zoom = impl->m_ZoomStack.pop(); |
|
420 | auto zoom = impl->m_ZoomStack.pop(); | |
422 | auto axisX = plot().axisRect()->axis(QCPAxis::atBottom); |
|
421 | auto axisX = plot().axisRect()->axis(QCPAxis::atBottom); | |
423 | auto axisY = plot().axisRect()->axis(QCPAxis::atLeft); |
|
422 | auto axisY = plot().axisRect()->axis(QCPAxis::atLeft); | |
424 |
|
423 | |||
425 | axisX->setRange(zoom.first); |
|
424 | axisX->setRange(zoom.first); | |
426 | axisY->setRange(zoom.second); |
|
425 | axisY->setRange(zoom.second); | |
427 |
|
426 | |||
428 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
427 | plot().replot(QCustomPlot::rpQueuedReplot); | |
429 | } |
|
428 | } | |
430 |
|
429 | |||
431 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
430 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) | |
432 | { |
|
431 | { | |
433 | if (visitor) { |
|
432 | if (visitor) { | |
434 | visitor->visit(this); |
|
433 | visitor->visit(this); | |
435 | } |
|
434 | } | |
436 | else { |
|
435 | else { | |
437 | qCCritical(LOG_VisualizationGraphWidget()) |
|
436 | qCCritical(LOG_VisualizationGraphWidget()) | |
438 | << tr("Can't visit widget : the visitor is null"); |
|
437 | << tr("Can't visit widget : the visitor is null"); | |
439 | } |
|
438 | } | |
440 | } |
|
439 | } | |
441 |
|
440 | |||
442 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const |
|
441 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const | |
443 | { |
|
442 | { | |
444 | auto isSpectrogram = [](const auto &variable) { |
|
443 | auto isSpectrogram = [](const auto &variable) { | |
445 | return std::dynamic_pointer_cast<SpectrogramSeries>(variable.dataSeries()) != nullptr; |
|
444 | return std::dynamic_pointer_cast<SpectrogramSeries>(variable.dataSeries()) != nullptr; | |
446 | }; |
|
445 | }; | |
447 |
|
446 | |||
448 | // - A spectrogram series can't be dropped on graph with existing plottables |
|
447 | // - A spectrogram series can't be dropped on graph with existing plottables | |
449 | // - No data series can be dropped on graph with existing spectrogram series |
|
448 | // - No data series can be dropped on graph with existing spectrogram series | |
450 | return isSpectrogram(variable) |
|
449 | return isSpectrogram(variable) | |
451 | ? impl->m_VariableToPlotMultiMap.empty() |
|
450 | ? impl->m_VariableToPlotMultiMap.empty() | |
452 | : std::none_of( |
|
451 | : std::none_of( | |
453 | impl->m_VariableToPlotMultiMap.cbegin(), impl->m_VariableToPlotMultiMap.cend(), |
|
452 | impl->m_VariableToPlotMultiMap.cbegin(), impl->m_VariableToPlotMultiMap.cend(), | |
454 | [isSpectrogram](const auto &entry) { return isSpectrogram(*entry.first); }); |
|
453 | [isSpectrogram](const auto &entry) { return isSpectrogram(*entry.first); }); | |
455 | } |
|
454 | } | |
456 |
|
455 | |||
457 | bool VisualizationGraphWidget::contains(const Variable &variable) const |
|
456 | bool VisualizationGraphWidget::contains(const Variable &variable) const | |
458 | { |
|
457 | { | |
459 | // Finds the variable among the keys of the map |
|
458 | // Finds the variable among the keys of the map | |
460 | auto variablePtr = &variable; |
|
459 | auto variablePtr = &variable; | |
461 | auto findVariable |
|
460 | auto findVariable | |
462 | = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); }; |
|
461 | = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); }; | |
463 |
|
462 | |||
464 | auto end = impl->m_VariableToPlotMultiMap.cend(); |
|
463 | auto end = impl->m_VariableToPlotMultiMap.cend(); | |
465 | auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable); |
|
464 | auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable); | |
466 | return it != end; |
|
465 | return it != end; | |
467 | } |
|
466 | } | |
468 |
|
467 | |||
469 | QString VisualizationGraphWidget::name() const |
|
468 | QString VisualizationGraphWidget::name() const | |
470 | { |
|
469 | { | |
471 | return impl->m_Name; |
|
470 | return impl->m_Name; | |
472 | } |
|
471 | } | |
473 |
|
472 | |||
474 | QMimeData *VisualizationGraphWidget::mimeData(const QPoint &position) const |
|
473 | QMimeData *VisualizationGraphWidget::mimeData(const QPoint &position) const | |
475 | { |
|
474 | { | |
476 | auto mimeData = new QMimeData; |
|
475 | auto mimeData = new QMimeData; | |
477 |
|
476 | |||
478 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(position, plot()); |
|
477 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(position, plot()); | |
479 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones |
|
478 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones | |
480 | && selectionZoneItemUnderCursor) { |
|
479 | && selectionZoneItemUnderCursor) { | |
481 | mimeData->setData(MIME_TYPE_TIME_RANGE, TimeController::mimeDataForTimeRange( |
|
480 | mimeData->setData(MIME_TYPE_TIME_RANGE, TimeController::mimeDataForTimeRange( | |
482 | selectionZoneItemUnderCursor->range())); |
|
481 | selectionZoneItemUnderCursor->range())); | |
483 | mimeData->setData(MIME_TYPE_SELECTION_ZONE, TimeController::mimeDataForTimeRange( |
|
482 | mimeData->setData(MIME_TYPE_SELECTION_ZONE, TimeController::mimeDataForTimeRange( | |
484 | selectionZoneItemUnderCursor->range())); |
|
483 | selectionZoneItemUnderCursor->range())); | |
485 | } |
|
484 | } | |
486 | else { |
|
485 | else { | |
487 | mimeData->setData(MIME_TYPE_GRAPH, QByteArray{}); |
|
486 | mimeData->setData(MIME_TYPE_GRAPH, QByteArray{}); | |
488 |
|
487 | |||
489 | auto timeRangeData = TimeController::mimeDataForTimeRange(graphRange()); |
|
488 | auto timeRangeData = TimeController::mimeDataForTimeRange(graphRange()); | |
490 | mimeData->setData(MIME_TYPE_TIME_RANGE, timeRangeData); |
|
489 | mimeData->setData(MIME_TYPE_TIME_RANGE, timeRangeData); | |
491 | } |
|
490 | } | |
492 |
|
491 | |||
493 | return mimeData; |
|
492 | return mimeData; | |
494 | } |
|
493 | } | |
495 |
|
494 | |||
496 | QPixmap VisualizationGraphWidget::customDragPixmap(const QPoint &dragPosition) |
|
495 | QPixmap VisualizationGraphWidget::customDragPixmap(const QPoint &dragPosition) | |
497 | { |
|
496 | { | |
498 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(dragPosition, plot()); |
|
497 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(dragPosition, plot()); | |
499 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones |
|
498 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones | |
500 | && selectionZoneItemUnderCursor) { |
|
499 | && selectionZoneItemUnderCursor) { | |
501 |
|
500 | |||
502 | auto zoneTopLeft = selectionZoneItemUnderCursor->topLeft->pixelPosition(); |
|
501 | auto zoneTopLeft = selectionZoneItemUnderCursor->topLeft->pixelPosition(); | |
503 | auto zoneBottomRight = selectionZoneItemUnderCursor->bottomRight->pixelPosition(); |
|
502 | auto zoneBottomRight = selectionZoneItemUnderCursor->bottomRight->pixelPosition(); | |
504 |
|
503 | |||
505 | auto zoneSize = QSizeF{qAbs(zoneBottomRight.x() - zoneTopLeft.x()), |
|
504 | auto zoneSize = QSizeF{qAbs(zoneBottomRight.x() - zoneTopLeft.x()), | |
506 | qAbs(zoneBottomRight.y() - zoneTopLeft.y())} |
|
505 | qAbs(zoneBottomRight.y() - zoneTopLeft.y())} | |
507 | .toSize(); |
|
506 | .toSize(); | |
508 |
|
507 | |||
509 | auto pixmap = QPixmap(zoneSize); |
|
508 | auto pixmap = QPixmap(zoneSize); | |
510 | render(&pixmap, QPoint(), QRegion{QRect{zoneTopLeft.toPoint(), zoneSize}}); |
|
509 | render(&pixmap, QPoint(), QRegion{QRect{zoneTopLeft.toPoint(), zoneSize}}); | |
511 |
|
510 | |||
512 | return pixmap; |
|
511 | return pixmap; | |
513 | } |
|
512 | } | |
514 |
|
513 | |||
515 | return QPixmap(); |
|
514 | return QPixmap(); | |
516 | } |
|
515 | } | |
517 |
|
516 | |||
518 | bool VisualizationGraphWidget::isDragAllowed() const |
|
517 | bool VisualizationGraphWidget::isDragAllowed() const | |
519 | { |
|
518 | { | |
520 | return true; |
|
519 | return true; | |
521 | } |
|
520 | } | |
522 |
|
521 | |||
523 | void VisualizationGraphWidget::highlightForMerge(bool highlighted) |
|
522 | void VisualizationGraphWidget::highlightForMerge(bool highlighted) | |
524 | { |
|
523 | { | |
525 | if (highlighted) { |
|
524 | if (highlighted) { | |
526 | plot().setBackground(QBrush(QColor("#BBD5EE"))); |
|
525 | plot().setBackground(QBrush(QColor("#BBD5EE"))); | |
527 | } |
|
526 | } | |
528 | else { |
|
527 | else { | |
529 | plot().setBackground(QBrush(Qt::white)); |
|
528 | plot().setBackground(QBrush(Qt::white)); | |
530 | } |
|
529 | } | |
531 |
|
530 | |||
532 | plot().update(); |
|
531 | plot().update(); | |
533 | } |
|
532 | } | |
534 |
|
533 | |||
535 | void VisualizationGraphWidget::addVerticalCursor(double time) |
|
534 | void VisualizationGraphWidget::addVerticalCursor(double time) | |
536 | { |
|
535 | { | |
537 | impl->m_VerticalCursor->setPosition(time); |
|
536 | impl->m_VerticalCursor->setPosition(time); | |
538 | impl->m_VerticalCursor->setVisible(true); |
|
537 | impl->m_VerticalCursor->setVisible(true); | |
539 |
|
538 | |||
540 | auto text |
|
539 | auto text | |
541 | = DateUtils::dateTime(time).toString(CURSOR_LABELS_DATETIME_FORMAT).replace(' ', '\n'); |
|
540 | = DateUtils::dateTime(time).toString(CURSOR_LABELS_DATETIME_FORMAT).replace(' ', '\n'); | |
542 | impl->m_VerticalCursor->setLabelText(text); |
|
541 | impl->m_VerticalCursor->setLabelText(text); | |
543 | } |
|
542 | } | |
544 |
|
543 | |||
545 | void VisualizationGraphWidget::addVerticalCursorAtViewportPosition(double position) |
|
544 | void VisualizationGraphWidget::addVerticalCursorAtViewportPosition(double position) | |
546 | { |
|
545 | { | |
547 | impl->m_VerticalCursor->setAbsolutePosition(position); |
|
546 | impl->m_VerticalCursor->setAbsolutePosition(position); | |
548 | impl->m_VerticalCursor->setVisible(true); |
|
547 | impl->m_VerticalCursor->setVisible(true); | |
549 |
|
548 | |||
550 | auto axis = plot().axisRect()->axis(QCPAxis::atBottom); |
|
549 | auto axis = plot().axisRect()->axis(QCPAxis::atBottom); | |
551 | auto text |
|
550 | auto text | |
552 | = DateUtils::dateTime(axis->pixelToCoord(position)).toString(CURSOR_LABELS_DATETIME_FORMAT); |
|
551 | = DateUtils::dateTime(axis->pixelToCoord(position)).toString(CURSOR_LABELS_DATETIME_FORMAT); | |
553 | impl->m_VerticalCursor->setLabelText(text); |
|
552 | impl->m_VerticalCursor->setLabelText(text); | |
554 | } |
|
553 | } | |
555 |
|
554 | |||
556 | void VisualizationGraphWidget::removeVerticalCursor() |
|
555 | void VisualizationGraphWidget::removeVerticalCursor() | |
557 | { |
|
556 | { | |
558 | impl->m_VerticalCursor->setVisible(false); |
|
557 | impl->m_VerticalCursor->setVisible(false); | |
559 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
558 | plot().replot(QCustomPlot::rpQueuedReplot); | |
560 | } |
|
559 | } | |
561 |
|
560 | |||
562 | void VisualizationGraphWidget::addHorizontalCursor(double value) |
|
561 | void VisualizationGraphWidget::addHorizontalCursor(double value) | |
563 | { |
|
562 | { | |
564 | impl->m_HorizontalCursor->setPosition(value); |
|
563 | impl->m_HorizontalCursor->setPosition(value); | |
565 | impl->m_HorizontalCursor->setVisible(true); |
|
564 | impl->m_HorizontalCursor->setVisible(true); | |
566 | impl->m_HorizontalCursor->setLabelText(QString::number(value)); |
|
565 | impl->m_HorizontalCursor->setLabelText(QString::number(value)); | |
567 | } |
|
566 | } | |
568 |
|
567 | |||
569 | void VisualizationGraphWidget::addHorizontalCursorAtViewportPosition(double position) |
|
568 | void VisualizationGraphWidget::addHorizontalCursorAtViewportPosition(double position) | |
570 | { |
|
569 | { | |
571 | impl->m_HorizontalCursor->setAbsolutePosition(position); |
|
570 | impl->m_HorizontalCursor->setAbsolutePosition(position); | |
572 | impl->m_HorizontalCursor->setVisible(true); |
|
571 | impl->m_HorizontalCursor->setVisible(true); | |
573 |
|
572 | |||
574 | auto axis = plot().axisRect()->axis(QCPAxis::atLeft); |
|
573 | auto axis = plot().axisRect()->axis(QCPAxis::atLeft); | |
575 | impl->m_HorizontalCursor->setLabelText(QString::number(axis->pixelToCoord(position))); |
|
574 | impl->m_HorizontalCursor->setLabelText(QString::number(axis->pixelToCoord(position))); | |
576 | } |
|
575 | } | |
577 |
|
576 | |||
578 | void VisualizationGraphWidget::removeHorizontalCursor() |
|
577 | void VisualizationGraphWidget::removeHorizontalCursor() | |
579 | { |
|
578 | { | |
580 | impl->m_HorizontalCursor->setVisible(false); |
|
579 | impl->m_HorizontalCursor->setVisible(false); | |
581 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
580 | plot().replot(QCustomPlot::rpQueuedReplot); | |
582 | } |
|
581 | } | |
583 |
|
582 | |||
584 | void VisualizationGraphWidget::closeEvent(QCloseEvent *event) |
|
583 | void VisualizationGraphWidget::closeEvent(QCloseEvent *event) | |
585 | { |
|
584 | { | |
586 | Q_UNUSED(event); |
|
585 | Q_UNUSED(event); | |
587 |
|
586 | |||
588 | // Prevents that all variables will be removed from graph when it will be closed |
|
587 | // Prevents that all variables will be removed from graph when it will be closed | |
589 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { |
|
588 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { | |
590 | emit variableAboutToBeRemoved(variableEntry.first); |
|
589 | emit variableAboutToBeRemoved(variableEntry.first); | |
591 | } |
|
590 | } | |
592 | } |
|
591 | } | |
593 |
|
592 | |||
594 | void VisualizationGraphWidget::enterEvent(QEvent *event) |
|
593 | void VisualizationGraphWidget::enterEvent(QEvent *event) | |
595 | { |
|
594 | { | |
596 | Q_UNUSED(event); |
|
595 | Q_UNUSED(event); | |
597 | impl->m_RenderingDelegate->showGraphOverlay(true); |
|
596 | impl->m_RenderingDelegate->showGraphOverlay(true); | |
598 | } |
|
597 | } | |
599 |
|
598 | |||
600 | void VisualizationGraphWidget::leaveEvent(QEvent *event) |
|
599 | void VisualizationGraphWidget::leaveEvent(QEvent *event) | |
601 | { |
|
600 | { | |
602 | Q_UNUSED(event); |
|
601 | Q_UNUSED(event); | |
603 | impl->m_RenderingDelegate->showGraphOverlay(false); |
|
602 | impl->m_RenderingDelegate->showGraphOverlay(false); | |
604 |
|
603 | |||
605 | if (auto parentZone = parentZoneWidget()) { |
|
604 | if (auto parentZone = parentZoneWidget()) { | |
606 | parentZone->notifyMouseLeaveGraph(this); |
|
605 | parentZone->notifyMouseLeaveGraph(this); | |
607 | } |
|
606 | } | |
608 | else { |
|
607 | else { | |
609 | qCWarning(LOG_VisualizationGraphWidget()) << "leaveEvent: No parent zone widget"; |
|
608 | qCWarning(LOG_VisualizationGraphWidget()) << "leaveEvent: No parent zone widget"; | |
610 | } |
|
609 | } | |
611 |
|
610 | |||
612 | if (impl->m_HoveredZone) { |
|
611 | if (impl->m_HoveredZone) { | |
613 | impl->m_HoveredZone->setHovered(false); |
|
612 | impl->m_HoveredZone->setHovered(false); | |
614 | impl->m_HoveredZone = nullptr; |
|
613 | impl->m_HoveredZone = nullptr; | |
615 | } |
|
614 | } | |
616 | } |
|
615 | } | |
617 |
|
616 | |||
618 | QCustomPlot &VisualizationGraphWidget::plot() const noexcept |
|
617 | QCustomPlot &VisualizationGraphWidget::plot() const noexcept | |
619 | { |
|
618 | { | |
620 | return *ui->widget; |
|
619 | return *ui->widget; | |
621 | } |
|
620 | } | |
622 |
|
621 | |||
623 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept |
|
622 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept | |
624 | { |
|
623 | { | |
625 | QMenu graphMenu{}; |
|
624 | QMenu graphMenu{}; | |
626 |
|
625 | |||
627 | // Iterates on variables (unique keys) |
|
626 | // Iterates on variables (unique keys) | |
628 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(), |
|
627 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(), | |
629 | end = impl->m_VariableToPlotMultiMap.cend(); |
|
628 | end = impl->m_VariableToPlotMultiMap.cend(); | |
630 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { |
|
629 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { | |
631 | // 'Remove variable' action |
|
630 | // 'Remove variable' action | |
632 | graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()), |
|
631 | graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()), | |
633 | [ this, var = it->first ]() { removeVariable(var); }); |
|
632 | [ this, var = it->first ]() { removeVariable(var); }); | |
634 | } |
|
633 | } | |
635 |
|
634 | |||
636 | if (!impl->m_ZoomStack.isEmpty()) { |
|
635 | if (!impl->m_ZoomStack.isEmpty()) { | |
637 | if (!graphMenu.isEmpty()) { |
|
636 | if (!graphMenu.isEmpty()) { | |
638 | graphMenu.addSeparator(); |
|
637 | graphMenu.addSeparator(); | |
639 | } |
|
638 | } | |
640 |
|
639 | |||
641 | graphMenu.addAction(tr("Undo Zoom"), [this]() { undoZoom(); }); |
|
640 | graphMenu.addAction(tr("Undo Zoom"), [this]() { undoZoom(); }); | |
642 | } |
|
641 | } | |
643 |
|
642 | |||
644 | // Selection Zone Actions |
|
643 | // Selection Zone Actions | |
645 | auto selectionZoneItem = impl->selectionZoneAt(pos, plot()); |
|
644 | auto selectionZoneItem = impl->selectionZoneAt(pos, plot()); | |
646 | if (selectionZoneItem) { |
|
645 | if (selectionZoneItem) { | |
647 | auto selectedItems = parentVisualizationWidget()->selectionZoneManager().selectedItems(); |
|
646 | auto selectedItems = parentVisualizationWidget()->selectionZoneManager().selectedItems(); | |
648 | selectedItems.removeAll(selectionZoneItem); |
|
647 | selectedItems.removeAll(selectionZoneItem); | |
649 | selectedItems.prepend(selectionZoneItem); // Put the current selection zone first |
|
648 | selectedItems.prepend(selectionZoneItem); // Put the current selection zone first | |
650 |
|
649 | |||
651 | auto zoneActions = sqpApp->actionsGuiController().selectionZoneActions(); |
|
650 | auto zoneActions = sqpApp->actionsGuiController().selectionZoneActions(); | |
652 | if (!zoneActions.isEmpty() && !graphMenu.isEmpty()) { |
|
651 | if (!zoneActions.isEmpty() && !graphMenu.isEmpty()) { | |
653 | graphMenu.addSeparator(); |
|
652 | graphMenu.addSeparator(); | |
654 | } |
|
653 | } | |
655 |
|
654 | |||
656 | QHash<QString, QMenu *> subMenus; |
|
655 | QHash<QString, QMenu *> subMenus; | |
657 | QHash<QString, bool> subMenusEnabled; |
|
656 | QHash<QString, bool> subMenusEnabled; | |
658 |
|
657 | |||
659 | for (auto zoneAction : zoneActions) { |
|
658 | for (auto zoneAction : zoneActions) { | |
660 |
|
659 | |||
661 | auto isEnabled = zoneAction->isEnabled(selectedItems); |
|
660 | auto isEnabled = zoneAction->isEnabled(selectedItems); | |
662 |
|
661 | |||
663 | auto menu = &graphMenu; |
|
662 | auto menu = &graphMenu; | |
664 | for (auto subMenuName : zoneAction->subMenuList()) { |
|
663 | for (auto subMenuName : zoneAction->subMenuList()) { | |
665 | if (!subMenus.contains(subMenuName)) { |
|
664 | if (!subMenus.contains(subMenuName)) { | |
666 | menu = menu->addMenu(subMenuName); |
|
665 | menu = menu->addMenu(subMenuName); | |
667 | subMenus[subMenuName] = menu; |
|
666 | subMenus[subMenuName] = menu; | |
668 | subMenusEnabled[subMenuName] = isEnabled; |
|
667 | subMenusEnabled[subMenuName] = isEnabled; | |
669 | } |
|
668 | } | |
670 | else { |
|
669 | else { | |
671 | menu = subMenus.value(subMenuName); |
|
670 | menu = subMenus.value(subMenuName); | |
672 | if (isEnabled) { |
|
671 | if (isEnabled) { | |
673 | // The sub menu is enabled if at least one of its actions is enabled |
|
672 | // The sub menu is enabled if at least one of its actions is enabled | |
674 | subMenusEnabled[subMenuName] = true; |
|
673 | subMenusEnabled[subMenuName] = true; | |
675 | } |
|
674 | } | |
676 | } |
|
675 | } | |
677 | } |
|
676 | } | |
678 |
|
677 | |||
679 | auto action = menu->addAction(zoneAction->name()); |
|
678 | auto action = menu->addAction(zoneAction->name()); | |
680 | action->setEnabled(isEnabled); |
|
679 | action->setEnabled(isEnabled); | |
681 | action->setShortcut(zoneAction->displayedShortcut()); |
|
680 | action->setShortcut(zoneAction->displayedShortcut()); | |
682 | QObject::connect(action, &QAction::triggered, |
|
681 | QObject::connect(action, &QAction::triggered, | |
683 | [zoneAction, selectedItems]() { zoneAction->execute(selectedItems); }); |
|
682 | [zoneAction, selectedItems]() { zoneAction->execute(selectedItems); }); | |
684 | } |
|
683 | } | |
685 |
|
684 | |||
686 | for (auto it = subMenus.cbegin(); it != subMenus.cend(); ++it) { |
|
685 | for (auto it = subMenus.cbegin(); it != subMenus.cend(); ++it) { | |
687 | it.value()->setEnabled(subMenusEnabled[it.key()]); |
|
686 | it.value()->setEnabled(subMenusEnabled[it.key()]); | |
688 | } |
|
687 | } | |
689 | } |
|
688 | } | |
690 |
|
689 | |||
691 | if (!graphMenu.isEmpty()) { |
|
690 | if (!graphMenu.isEmpty()) { | |
692 | graphMenu.exec(QCursor::pos()); |
|
691 | graphMenu.exec(QCursor::pos()); | |
693 | } |
|
692 | } | |
694 | } |
|
693 | } | |
695 |
|
694 | |||
696 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) |
|
695 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) | |
697 | { |
|
696 | { | |
698 | qCDebug(LOG_VisualizationGraphWidget()) |
|
697 | qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::onRangeChanged") | |
699 | << tr("TORM: VisualizationGraphWidget::onRangeChanged") |
|
698 | << QThread::currentThread()->objectName() << "DoAcqui" | |
700 | << QThread::currentThread()->objectName() << "DoAcqui" << impl->m_DoAcquisition; |
|
699 | << impl->m_DoAcquisition; | |
701 |
|
700 | |||
702 | auto graphRange = SqpRange{t1.lower, t1.upper}; |
|
701 | auto graphRange = SqpRange{t1.lower, t1.upper}; | |
703 | auto oldGraphRange = SqpRange{t2.lower, t2.upper}; |
|
702 | auto oldGraphRange = SqpRange{t2.lower, t2.upper}; | |
704 |
|
703 | |||
705 | if (impl->m_DoAcquisition) { |
|
704 | if (impl->m_DoAcquisition) { | |
706 | QVector<std::shared_ptr<Variable> > variableUnderGraphVector; |
|
705 | QVector<std::shared_ptr<Variable> > variableUnderGraphVector; | |
707 |
|
706 | |||
708 | for (auto it = impl->m_VariableToPlotMultiMap.begin(), |
|
707 | for (auto it = impl->m_VariableToPlotMultiMap.begin(), | |
709 | end = impl->m_VariableToPlotMultiMap.end(); |
|
708 | end = impl->m_VariableToPlotMultiMap.end(); | |
710 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { |
|
709 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { | |
711 | variableUnderGraphVector.push_back(it->first); |
|
710 | variableUnderGraphVector.push_back(it->first); | |
712 | } |
|
711 | } | |
713 | emit requestDataLoading(std::move(variableUnderGraphVector), graphRange, |
|
712 | emit requestDataLoading(std::move(variableUnderGraphVector), graphRange, | |
714 | !impl->m_IsCalibration); |
|
713 | !impl->m_IsCalibration); | |
715 |
|
714 | |||
716 | if (!impl->m_IsCalibration) { |
|
715 | if (!impl->m_IsCalibration) { | |
717 | qCDebug(LOG_VisualizationGraphWidget()) |
|
716 | qCDebug(LOG_VisualizationGraphWidget()) | |
718 | << tr("TORM: VisualizationGraphWidget::Synchronize notify !!") |
|
717 | << tr("TORM: VisualizationGraphWidget::Synchronize notify !!") | |
719 | << QThread::currentThread()->objectName() << graphRange << oldGraphRange; |
|
718 | << QThread::currentThread()->objectName() << graphRange << oldGraphRange; | |
720 | emit synchronize(graphRange, oldGraphRange); |
|
719 | emit synchronize(graphRange, oldGraphRange); | |
721 | } |
|
720 | } | |
722 | } |
|
721 | } | |
723 |
|
722 | |||
724 | auto pos = mapFromGlobal(QCursor::pos()); |
|
723 | auto pos = mapFromGlobal(QCursor::pos()); | |
725 | auto axisPos = impl->posToAxisPos(pos, plot()); |
|
724 | auto axisPos = impl->posToAxisPos(pos, plot()); | |
726 | if (auto parentZone = parentZoneWidget()) { |
|
725 | if (auto parentZone = parentZoneWidget()) { | |
727 | if (impl->pointIsInAxisRect(axisPos, plot())) { |
|
726 | if (impl->pointIsInAxisRect(axisPos, plot())) { | |
728 | parentZone->notifyMouseMoveInGraph(pos, axisPos, this); |
|
727 | parentZone->notifyMouseMoveInGraph(pos, axisPos, this); | |
729 | } |
|
728 | } | |
730 | else { |
|
729 | else { | |
731 | parentZone->notifyMouseLeaveGraph(this); |
|
730 | parentZone->notifyMouseLeaveGraph(this); | |
732 | } |
|
731 | } | |
733 | } |
|
732 | } | |
734 | else { |
|
733 | else { | |
735 | qCWarning(LOG_VisualizationGraphWidget()) << "onMouseMove: No parent zone widget"; |
|
734 | qCWarning(LOG_VisualizationGraphWidget()) << "onMouseMove: No parent zone widget"; | |
736 | } |
|
735 | } | |
737 | } |
|
736 | } | |
738 |
|
737 | |||
739 | void VisualizationGraphWidget::onMouseDoubleClick(QMouseEvent *event) noexcept |
|
738 | void VisualizationGraphWidget::onMouseDoubleClick(QMouseEvent *event) noexcept | |
740 | { |
|
739 | { | |
741 | impl->m_RenderingDelegate->onMouseDoubleClick(event); |
|
740 | impl->m_RenderingDelegate->onMouseDoubleClick(event); | |
742 | } |
|
741 | } | |
743 |
|
742 | |||
744 | void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept |
|
743 | void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept | |
745 | { |
|
744 | { | |
746 | // Handles plot rendering when mouse is moving |
|
745 | // Handles plot rendering when mouse is moving | |
747 | impl->m_RenderingDelegate->onMouseMove(event); |
|
746 | impl->m_RenderingDelegate->onMouseMove(event); | |
748 |
|
747 | |||
749 | auto axisPos = impl->posToAxisPos(event->pos(), plot()); |
|
748 | auto axisPos = impl->posToAxisPos(event->pos(), plot()); | |
750 |
|
749 | |||
751 | // Zoom box and zone drawing |
|
750 | // Zoom box and zone drawing | |
752 | if (impl->m_DrawingZoomRect) { |
|
751 | if (impl->m_DrawingZoomRect) { | |
753 | impl->m_DrawingZoomRect->bottomRight->setCoords(axisPos); |
|
752 | impl->m_DrawingZoomRect->bottomRight->setCoords(axisPos); | |
754 | } |
|
753 | } | |
755 | else if (impl->m_DrawingZone) { |
|
754 | else if (impl->m_DrawingZone) { | |
756 | impl->m_DrawingZone->setEnd(axisPos.x()); |
|
755 | impl->m_DrawingZone->setEnd(axisPos.x()); | |
757 | } |
|
756 | } | |
758 |
|
757 | |||
759 | // Cursor |
|
758 | // Cursor | |
760 | if (auto parentZone = parentZoneWidget()) { |
|
759 | if (auto parentZone = parentZoneWidget()) { | |
761 | if (impl->pointIsInAxisRect(axisPos, plot())) { |
|
760 | if (impl->pointIsInAxisRect(axisPos, plot())) { | |
762 | parentZone->notifyMouseMoveInGraph(event->pos(), axisPos, this); |
|
761 | parentZone->notifyMouseMoveInGraph(event->pos(), axisPos, this); | |
763 | } |
|
762 | } | |
764 | else { |
|
763 | else { | |
765 | parentZone->notifyMouseLeaveGraph(this); |
|
764 | parentZone->notifyMouseLeaveGraph(this); | |
766 | } |
|
765 | } | |
767 | } |
|
766 | } | |
768 | else { |
|
767 | else { | |
769 | qCWarning(LOG_VisualizationGraphWidget()) << "onMouseMove: No parent zone widget"; |
|
768 | qCWarning(LOG_VisualizationGraphWidget()) << "onMouseMove: No parent zone widget"; | |
770 | } |
|
769 | } | |
771 |
|
770 | |||
772 | // Search for the selection zone under the mouse |
|
771 | // Search for the selection zone under the mouse | |
773 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); |
|
772 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); | |
774 | if (selectionZoneItemUnderCursor && !impl->m_DrawingZone |
|
773 | if (selectionZoneItemUnderCursor && !impl->m_DrawingZone | |
775 | && sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones) { |
|
774 | && sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones) { | |
776 |
|
775 | |||
777 | // Sets the appropriate cursor shape |
|
776 | // Sets the appropriate cursor shape | |
778 | auto cursorShape = selectionZoneItemUnderCursor->curshorShapeForPosition(event->pos()); |
|
777 | auto cursorShape = selectionZoneItemUnderCursor->curshorShapeForPosition(event->pos()); | |
779 | setCursor(cursorShape); |
|
778 | setCursor(cursorShape); | |
780 |
|
779 | |||
781 | // Manages the hovered zone |
|
780 | // Manages the hovered zone | |
782 | if (selectionZoneItemUnderCursor != impl->m_HoveredZone) { |
|
781 | if (selectionZoneItemUnderCursor != impl->m_HoveredZone) { | |
783 | if (impl->m_HoveredZone) { |
|
782 | if (impl->m_HoveredZone) { | |
784 | impl->m_HoveredZone->setHovered(false); |
|
783 | impl->m_HoveredZone->setHovered(false); | |
785 | } |
|
784 | } | |
786 | selectionZoneItemUnderCursor->setHovered(true); |
|
785 | selectionZoneItemUnderCursor->setHovered(true); | |
787 | impl->m_HoveredZone = selectionZoneItemUnderCursor; |
|
786 | impl->m_HoveredZone = selectionZoneItemUnderCursor; | |
788 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
787 | plot().replot(QCustomPlot::rpQueuedReplot); | |
789 | } |
|
788 | } | |
790 | } |
|
789 | } | |
791 | else { |
|
790 | else { | |
792 | // There is no zone under the mouse or the interaction mode is not "selection zones" |
|
791 | // There is no zone under the mouse or the interaction mode is not "selection zones" | |
793 | if (impl->m_HoveredZone) { |
|
792 | if (impl->m_HoveredZone) { | |
794 | impl->m_HoveredZone->setHovered(false); |
|
793 | impl->m_HoveredZone->setHovered(false); | |
795 | impl->m_HoveredZone = nullptr; |
|
794 | impl->m_HoveredZone = nullptr; | |
796 | } |
|
795 | } | |
797 |
|
796 | |||
798 | setCursor(Qt::ArrowCursor); |
|
797 | setCursor(Qt::ArrowCursor); | |
799 | } |
|
798 | } | |
800 |
|
799 | |||
801 | impl->m_HasMovedMouse = true; |
|
800 | impl->m_HasMovedMouse = true; | |
802 | VisualizationDragWidget::mouseMoveEvent(event); |
|
801 | VisualizationDragWidget::mouseMoveEvent(event); | |
803 | } |
|
802 | } | |
804 |
|
803 | |||
805 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept |
|
804 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept | |
806 | { |
|
805 | { | |
807 | auto value = event->angleDelta().x() + event->angleDelta().y(); |
|
806 | auto value = event->angleDelta().x() + event->angleDelta().y(); | |
808 | if (value != 0) { |
|
807 | if (value != 0) { | |
809 |
|
808 | |||
810 | auto direction = value > 0 ? 1.0 : -1.0; |
|
809 | auto direction = value > 0 ? 1.0 : -1.0; | |
811 | auto isZoomX = event->modifiers().testFlag(HORIZONTAL_ZOOM_MODIFIER); |
|
810 | auto isZoomX = event->modifiers().testFlag(HORIZONTAL_ZOOM_MODIFIER); | |
812 | auto isZoomY = event->modifiers().testFlag(VERTICAL_ZOOM_MODIFIER); |
|
811 | auto isZoomY = event->modifiers().testFlag(VERTICAL_ZOOM_MODIFIER); | |
813 | impl->m_IsCalibration = event->modifiers().testFlag(VERTICAL_PAN_MODIFIER); |
|
812 | impl->m_IsCalibration = event->modifiers().testFlag(VERTICAL_PAN_MODIFIER); | |
814 |
|
813 | |||
815 | auto zoomOrientations = QFlags<Qt::Orientation>{}; |
|
814 | auto zoomOrientations = QFlags<Qt::Orientation>{}; | |
816 | zoomOrientations.setFlag(Qt::Horizontal, isZoomX); |
|
815 | zoomOrientations.setFlag(Qt::Horizontal, isZoomX); | |
817 | zoomOrientations.setFlag(Qt::Vertical, isZoomY); |
|
816 | zoomOrientations.setFlag(Qt::Vertical, isZoomY); | |
818 |
|
817 | |||
819 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); |
|
818 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); | |
820 |
|
819 | |||
821 | if (!isZoomX && !isZoomY) { |
|
820 | if (!isZoomX && !isZoomY) { | |
822 | auto axis = plot().axisRect()->axis(QCPAxis::atBottom); |
|
821 | auto axis = plot().axisRect()->axis(QCPAxis::atBottom); | |
823 | auto diff = direction * (axis->range().size() * (PAN_SPEED / 100.0)); |
|
822 | auto diff = direction * (axis->range().size() * (PAN_SPEED / 100.0)); | |
824 |
|
823 | |||
825 | axis->setRange(axis->range() + diff); |
|
824 | axis->setRange(axis->range() + diff); | |
826 |
|
825 | |||
827 | if (plot().noAntialiasingOnDrag()) { |
|
826 | if (plot().noAntialiasingOnDrag()) { | |
828 | plot().setNotAntialiasedElements(QCP::aeAll); |
|
827 | plot().setNotAntialiasedElements(QCP::aeAll); | |
829 | } |
|
828 | } | |
830 |
|
829 | |||
831 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
830 | plot().replot(QCustomPlot::rpQueuedReplot); | |
832 | } |
|
831 | } | |
833 | } |
|
832 | } | |
834 | } |
|
833 | } | |
835 |
|
834 | |||
836 | void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept |
|
835 | void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept | |
837 | { |
|
836 | { | |
838 | auto isDragDropClick = event->modifiers().testFlag(DRAG_DROP_MODIFIER); |
|
837 | auto isDragDropClick = event->modifiers().testFlag(DRAG_DROP_MODIFIER); | |
839 | auto isSelectionZoneMode |
|
838 | auto isSelectionZoneMode | |
840 | = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones; |
|
839 | = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones; | |
841 | auto isLeftClick = event->buttons().testFlag(Qt::LeftButton); |
|
840 | auto isLeftClick = event->buttons().testFlag(Qt::LeftButton); | |
842 |
|
841 | |||
843 | if (!isDragDropClick && isLeftClick) { |
|
842 | if (!isDragDropClick && isLeftClick) { | |
844 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::ZoomBox) { |
|
843 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::ZoomBox) { | |
845 | // Starts a zoom box |
|
844 | // Starts a zoom box | |
846 | impl->startDrawingRect(event->pos(), plot()); |
|
845 | impl->startDrawingRect(event->pos(), plot()); | |
847 | } |
|
846 | } | |
848 | else if (isSelectionZoneMode && impl->m_DrawingZone == nullptr) { |
|
847 | else if (isSelectionZoneMode && impl->m_DrawingZone == nullptr) { | |
849 | // Starts a new selection zone |
|
848 | // Starts a new selection zone | |
850 | auto zoneAtPos = impl->selectionZoneAt(event->pos(), plot()); |
|
849 | auto zoneAtPos = impl->selectionZoneAt(event->pos(), plot()); | |
851 | if (!zoneAtPos) { |
|
850 | if (!zoneAtPos) { | |
852 | impl->startDrawingZone(event->pos(), this); |
|
851 | impl->startDrawingZone(event->pos(), this); | |
853 | } |
|
852 | } | |
854 | } |
|
853 | } | |
855 | } |
|
854 | } | |
856 |
|
855 | |||
857 | // Allows mouse panning only in default mode |
|
856 | // Allows mouse panning only in default mode | |
858 | plot().setInteraction(QCP::iRangeDrag, sqpApp->plotsInteractionMode() |
|
857 | plot().setInteraction(QCP::iRangeDrag, sqpApp->plotsInteractionMode() | |
859 | == SqpApplication::PlotsInteractionMode::None |
|
858 | == SqpApplication::PlotsInteractionMode::None | |
860 | && !isDragDropClick); |
|
859 | && !isDragDropClick); | |
861 |
|
860 | |||
862 | // Allows zone edition only in selection zone mode without drag&drop |
|
861 | // Allows zone edition only in selection zone mode without drag&drop | |
863 | impl->setSelectionZonesEditionEnabled(isSelectionZoneMode && !isDragDropClick); |
|
862 | impl->setSelectionZonesEditionEnabled(isSelectionZoneMode && !isDragDropClick); | |
864 |
|
863 | |||
865 | // Selection / Deselection |
|
864 | // Selection / Deselection | |
866 | if (isSelectionZoneMode) { |
|
865 | if (isSelectionZoneMode) { | |
867 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); |
|
866 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); | |
868 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); |
|
867 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); | |
869 |
|
868 | |||
870 |
|
869 | |||
871 | if (selectionZoneItemUnderCursor && !selectionZoneItemUnderCursor->selected() |
|
870 | if (selectionZoneItemUnderCursor && !selectionZoneItemUnderCursor->selected() | |
872 | && !isMultiSelectionClick) { |
|
871 | && !isMultiSelectionClick) { | |
873 | parentVisualizationWidget()->selectionZoneManager().select( |
|
872 | parentVisualizationWidget()->selectionZoneManager().select( | |
874 | {selectionZoneItemUnderCursor}); |
|
873 | {selectionZoneItemUnderCursor}); | |
875 | } |
|
874 | } | |
876 | else if (!selectionZoneItemUnderCursor && !isMultiSelectionClick && isLeftClick) { |
|
875 | else if (!selectionZoneItemUnderCursor && !isMultiSelectionClick && isLeftClick) { | |
877 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); |
|
876 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); | |
878 | } |
|
877 | } | |
879 | else { |
|
878 | else { | |
880 | // No selection change |
|
879 | // No selection change | |
881 | } |
|
880 | } | |
882 |
|
881 | |||
883 | if (selectionZoneItemUnderCursor && isLeftClick) { |
|
882 | if (selectionZoneItemUnderCursor && isLeftClick) { | |
884 | selectionZoneItemUnderCursor->setAssociatedEditedZones( |
|
883 | selectionZoneItemUnderCursor->setAssociatedEditedZones( | |
885 | parentVisualizationWidget()->selectionZoneManager().selectedItems()); |
|
884 | parentVisualizationWidget()->selectionZoneManager().selectedItems()); | |
886 | } |
|
885 | } | |
887 | } |
|
886 | } | |
888 |
|
887 | |||
889 |
|
888 | |||
890 | impl->m_HasMovedMouse = false; |
|
889 | impl->m_HasMovedMouse = false; | |
891 | VisualizationDragWidget::mousePressEvent(event); |
|
890 | VisualizationDragWidget::mousePressEvent(event); | |
892 | } |
|
891 | } | |
893 |
|
892 | |||
894 | void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept |
|
893 | void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept | |
895 | { |
|
894 | { | |
896 | if (impl->m_DrawingZoomRect) { |
|
895 | if (impl->m_DrawingZoomRect) { | |
897 |
|
896 | |||
898 | auto axisX = plot().axisRect()->axis(QCPAxis::atBottom); |
|
897 | auto axisX = plot().axisRect()->axis(QCPAxis::atBottom); | |
899 | auto axisY = plot().axisRect()->axis(QCPAxis::atLeft); |
|
898 | auto axisY = plot().axisRect()->axis(QCPAxis::atLeft); | |
900 |
|
899 | |||
901 | auto newAxisXRange = QCPRange{impl->m_DrawingZoomRect->topLeft->coords().x(), |
|
900 | auto newAxisXRange = QCPRange{impl->m_DrawingZoomRect->topLeft->coords().x(), | |
902 | impl->m_DrawingZoomRect->bottomRight->coords().x()}; |
|
901 | impl->m_DrawingZoomRect->bottomRight->coords().x()}; | |
903 |
|
902 | |||
904 | auto newAxisYRange = QCPRange{impl->m_DrawingZoomRect->topLeft->coords().y(), |
|
903 | auto newAxisYRange = QCPRange{impl->m_DrawingZoomRect->topLeft->coords().y(), | |
905 | impl->m_DrawingZoomRect->bottomRight->coords().y()}; |
|
904 | impl->m_DrawingZoomRect->bottomRight->coords().y()}; | |
906 |
|
905 | |||
907 | impl->removeDrawingRect(plot()); |
|
906 | impl->removeDrawingRect(plot()); | |
908 |
|
907 | |||
909 | if (newAxisXRange.size() > axisX->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0) |
|
908 | if (newAxisXRange.size() > axisX->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0) | |
910 | && newAxisYRange.size() > axisY->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0)) { |
|
909 | && newAxisYRange.size() > axisY->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0)) { | |
911 | impl->m_ZoomStack.push(qMakePair(axisX->range(), axisY->range())); |
|
910 | impl->m_ZoomStack.push(qMakePair(axisX->range(), axisY->range())); | |
912 | axisX->setRange(newAxisXRange); |
|
911 | axisX->setRange(newAxisXRange); | |
913 | axisY->setRange(newAxisYRange); |
|
912 | axisY->setRange(newAxisYRange); | |
914 |
|
913 | |||
915 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
914 | plot().replot(QCustomPlot::rpQueuedReplot); | |
916 | } |
|
915 | } | |
917 | } |
|
916 | } | |
918 |
|
917 | |||
919 | impl->endDrawingZone(this); |
|
918 | impl->endDrawingZone(this); | |
920 |
|
919 | |||
921 | impl->m_IsCalibration = false; |
|
920 | impl->m_IsCalibration = false; | |
922 |
|
921 | |||
923 | // Selection / Deselection |
|
922 | // Selection / Deselection | |
924 | auto isSelectionZoneMode |
|
923 | auto isSelectionZoneMode | |
925 | = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones; |
|
924 | = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones; | |
926 | if (isSelectionZoneMode) { |
|
925 | if (isSelectionZoneMode) { | |
927 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); |
|
926 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); | |
928 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); |
|
927 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); | |
929 | if (selectionZoneItemUnderCursor && event->button() == Qt::LeftButton |
|
928 | if (selectionZoneItemUnderCursor && event->button() == Qt::LeftButton | |
930 | && !impl->m_HasMovedMouse) { |
|
929 | && !impl->m_HasMovedMouse) { | |
931 |
|
930 | |||
932 | auto zonesUnderCursor = impl->selectionZonesAt(event->pos(), plot()); |
|
931 | auto zonesUnderCursor = impl->selectionZonesAt(event->pos(), plot()); | |
933 | if (zonesUnderCursor.count() > 1) { |
|
932 | if (zonesUnderCursor.count() > 1) { | |
934 | // There are multiple zones under the mouse. |
|
933 | // There are multiple zones under the mouse. | |
935 | // Performs the selection with a selection dialog. |
|
934 | // Performs the selection with a selection dialog. | |
936 | VisualizationMultiZoneSelectionDialog dialog{this}; |
|
935 | VisualizationMultiZoneSelectionDialog dialog{this}; | |
937 | dialog.setZones(zonesUnderCursor); |
|
936 | dialog.setZones(zonesUnderCursor); | |
938 | dialog.move(mapToGlobal(event->pos() - QPoint(dialog.width() / 2, 20))); |
|
937 | dialog.move(mapToGlobal(event->pos() - QPoint(dialog.width() / 2, 20))); | |
939 | dialog.activateWindow(); |
|
938 | dialog.activateWindow(); | |
940 | dialog.raise(); |
|
939 | dialog.raise(); | |
941 | if (dialog.exec() == QDialog::Accepted) { |
|
940 | if (dialog.exec() == QDialog::Accepted) { | |
942 | auto selection = dialog.selectedZones(); |
|
941 | auto selection = dialog.selectedZones(); | |
943 |
|
942 | |||
944 | if (!isMultiSelectionClick) { |
|
943 | if (!isMultiSelectionClick) { | |
945 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); |
|
944 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); | |
946 | } |
|
945 | } | |
947 |
|
946 | |||
948 | for (auto it = selection.cbegin(); it != selection.cend(); ++it) { |
|
947 | for (auto it = selection.cbegin(); it != selection.cend(); ++it) { | |
949 | auto zone = it.key(); |
|
948 | auto zone = it.key(); | |
950 | auto isSelected = it.value(); |
|
949 | auto isSelected = it.value(); | |
951 | parentVisualizationWidget()->selectionZoneManager().setSelected(zone, |
|
950 | parentVisualizationWidget()->selectionZoneManager().setSelected(zone, | |
952 | isSelected); |
|
951 | isSelected); | |
953 |
|
952 | |||
954 | if (isSelected) { |
|
953 | if (isSelected) { | |
955 | // Puts the zone on top of the stack so it can be moved or resized |
|
954 | // Puts the zone on top of the stack so it can be moved or resized | |
956 | impl->moveSelectionZoneOnTop(zone, plot()); |
|
955 | impl->moveSelectionZoneOnTop(zone, plot()); | |
957 | } |
|
956 | } | |
958 | } |
|
957 | } | |
959 | } |
|
958 | } | |
960 | } |
|
959 | } | |
961 | else { |
|
960 | else { | |
962 | if (!isMultiSelectionClick) { |
|
961 | if (!isMultiSelectionClick) { | |
963 | parentVisualizationWidget()->selectionZoneManager().select( |
|
962 | parentVisualizationWidget()->selectionZoneManager().select( | |
964 | {selectionZoneItemUnderCursor}); |
|
963 | {selectionZoneItemUnderCursor}); | |
965 | impl->moveSelectionZoneOnTop(selectionZoneItemUnderCursor, plot()); |
|
964 | impl->moveSelectionZoneOnTop(selectionZoneItemUnderCursor, plot()); | |
966 | } |
|
965 | } | |
967 | else { |
|
966 | else { | |
968 | parentVisualizationWidget()->selectionZoneManager().setSelected( |
|
967 | parentVisualizationWidget()->selectionZoneManager().setSelected( | |
969 | selectionZoneItemUnderCursor, !selectionZoneItemUnderCursor->selected() |
|
968 | selectionZoneItemUnderCursor, !selectionZoneItemUnderCursor->selected() | |
970 | || event->button() == Qt::RightButton); |
|
969 | || event->button() == Qt::RightButton); | |
971 | } |
|
970 | } | |
972 | } |
|
971 | } | |
973 | } |
|
972 | } | |
974 | else { |
|
973 | else { | |
975 | // No selection change |
|
974 | // No selection change | |
976 | } |
|
975 | } | |
977 | } |
|
976 | } | |
978 | } |
|
977 | } | |
979 |
|
978 | |||
980 | void VisualizationGraphWidget::onDataCacheVariableUpdated() |
|
979 | void VisualizationGraphWidget::onDataCacheVariableUpdated() | |
981 | { |
|
980 | { | |
982 | auto graphRange = ui->widget->xAxis->range(); |
|
981 | auto graphRange = ui->widget->xAxis->range(); | |
983 | auto dateTime = SqpRange{graphRange.lower, graphRange.upper}; |
|
982 | auto dateTime = SqpRange{graphRange.lower, graphRange.upper}; | |
984 |
|
983 | |||
985 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { |
|
984 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { | |
986 | auto variable = variableEntry.first; |
|
985 | auto variable = variableEntry.first; | |
987 | qCDebug(LOG_VisualizationGraphWidget()) |
|
986 | qCDebug(LOG_VisualizationGraphWidget()) | |
988 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range(); |
|
987 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range(); | |
989 | qCDebug(LOG_VisualizationGraphWidget()) |
|
988 | qCDebug(LOG_VisualizationGraphWidget()) | |
990 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime; |
|
989 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime; | |
991 | if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) { |
|
990 | if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) { | |
992 | impl->updateData(variableEntry.second, variable->dataSeries(), variable->range()); |
|
991 | impl->updateData(variableEntry.second, variable->dataSeries(), variable->range()); | |
993 | } |
|
992 | } | |
994 | } |
|
993 | } | |
995 | } |
|
994 | } | |
996 |
|
995 | |||
997 | void VisualizationGraphWidget::onUpdateVarDisplaying(std::shared_ptr<Variable> variable, |
|
996 | void VisualizationGraphWidget::onUpdateVarDisplaying(std::shared_ptr<Variable> variable, | |
998 | const SqpRange &range) |
|
997 | const SqpRange &range) | |
999 | { |
|
998 | { | |
1000 | auto it = impl->m_VariableToPlotMultiMap.find(variable); |
|
999 | auto it = impl->m_VariableToPlotMultiMap.find(variable); | |
1001 | if (it != impl->m_VariableToPlotMultiMap.end()) { |
|
1000 | if (it != impl->m_VariableToPlotMultiMap.end()) { | |
1002 | impl->updateData(it->second, variable->dataSeries(), range); |
|
1001 | impl->updateData(it->second, variable->dataSeries(), range); | |
1003 | } |
|
1002 | } | |
1004 | } |
|
1003 | } |
@@ -1,438 +1,440 | |||||
1 | #include "Visualization/VisualizationSelectionZoneItem.h" |
|
1 | #include "Visualization/VisualizationSelectionZoneItem.h" | |
2 | #include "Visualization/VisualizationGraphWidget.h" |
|
2 | #include "Visualization/VisualizationGraphWidget.h" | |
3 | #include "Visualization/VisualizationSelectionZoneManager.h" |
|
3 | #include "Visualization/VisualizationSelectionZoneManager.h" | |
4 | #include "Visualization/VisualizationWidget.h" |
|
4 | #include "Visualization/VisualizationWidget.h" | |
5 |
|
5 | |||
6 | const QString &DEFAULT_COLOR = QStringLiteral("#E79D41"); |
|
6 | const QString &DEFAULT_COLOR = QStringLiteral("#E79D41"); | |
7 |
|
7 | |||
8 | struct VisualizationSelectionZoneItem::VisualizationSelectionZoneItemPrivate { |
|
8 | struct VisualizationSelectionZoneItem::VisualizationSelectionZoneItemPrivate { | |
9 |
|
9 | |||
10 | QCustomPlot *m_Plot; |
|
10 | QCustomPlot *m_Plot; | |
11 | double m_T1 = 0; |
|
11 | double m_T1 = 0; | |
12 | double m_T2 = 0; |
|
12 | double m_T2 = 0; | |
13 | QColor m_Color; |
|
13 | QColor m_Color; | |
14 |
|
14 | |||
15 | bool m_IsEditionEnabled = true; |
|
15 | bool m_IsEditionEnabled = true; | |
16 | double m_MovedOrinalT1 = 0; |
|
16 | double m_MovedOrinalT1 = 0; | |
17 | double m_MovedOrinalT2 = 0; |
|
17 | double m_MovedOrinalT2 = 0; | |
18 |
|
18 | |||
19 | QCPItemStraightLine *m_LeftLine; |
|
19 | QCPItemStraightLine *m_LeftLine; | |
20 | QCPItemStraightLine *m_RightLine; |
|
20 | QCPItemStraightLine *m_RightLine; | |
21 | QCPItemText *m_NameLabelItem = nullptr; |
|
21 | QCPItemText *m_NameLabelItem = nullptr; | |
22 |
|
22 | |||
23 | enum class EditionMode { NoEdition, ResizeLeft, ResizeRight, Move }; |
|
23 | enum class EditionMode { NoEdition, ResizeLeft, ResizeRight, Move }; | |
24 | EditionMode m_CurrentEditionMode; |
|
24 | EditionMode m_CurrentEditionMode; | |
25 |
|
25 | |||
26 | QVector<VisualizationSelectionZoneItem *> m_AssociatedEditedZones; |
|
26 | QVector<VisualizationSelectionZoneItem *> m_AssociatedEditedZones; | |
27 |
|
27 | |||
28 | VisualizationSelectionZoneItemPrivate(QCustomPlot *plot) |
|
28 | VisualizationSelectionZoneItemPrivate(QCustomPlot *plot) | |
29 | : m_Plot(plot), m_Color(Qt::blue), m_CurrentEditionMode(EditionMode::NoEdition) |
|
29 | : m_Plot(plot), m_Color(Qt::blue), m_CurrentEditionMode(EditionMode::NoEdition) | |
30 | { |
|
30 | { | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | void updatePosition(VisualizationSelectionZoneItem *item) |
|
33 | void updatePosition(VisualizationSelectionZoneItem *item) | |
34 | { |
|
34 | { | |
35 | item->topLeft->setCoords(m_T1, 0); |
|
35 | item->topLeft->setCoords(m_T1, 0); | |
36 | item->bottomRight->setCoords(m_T2, 1); |
|
36 | item->bottomRight->setCoords(m_T2, 1); | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | EditionMode getEditionMode(const QPoint &pos, const VisualizationSelectionZoneItem *zoneItem) |
|
39 | EditionMode getEditionMode(const QPoint &pos, const VisualizationSelectionZoneItem *zoneItem) | |
40 | { |
|
40 | { | |
41 | auto distanceLeft = m_LeftLine->selectTest(pos, false); |
|
41 | auto distanceLeft = m_LeftLine->selectTest(pos, false); | |
42 | auto distanceRight = m_RightLine->selectTest(pos, false); |
|
42 | auto distanceRight = m_RightLine->selectTest(pos, false); | |
43 | auto distance = zoneItem->selectTest(pos, false); |
|
43 | auto distance = zoneItem->selectTest(pos, false); | |
44 |
|
44 | |||
45 | if (distanceRight <= distance) { |
|
45 | if (distanceRight <= distance) { | |
46 | return VisualizationSelectionZoneItemPrivate::EditionMode::ResizeRight; |
|
46 | return VisualizationSelectionZoneItemPrivate::EditionMode::ResizeRight; | |
47 | } |
|
47 | } | |
48 | else if (distanceLeft <= distance) { |
|
48 | else if (distanceLeft <= distance) { | |
49 | return VisualizationSelectionZoneItemPrivate::EditionMode::ResizeLeft; |
|
49 | return VisualizationSelectionZoneItemPrivate::EditionMode::ResizeLeft; | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | return VisualizationSelectionZoneItemPrivate::EditionMode::Move; |
|
52 | return VisualizationSelectionZoneItemPrivate::EditionMode::Move; | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | double pixelSizeToAxisXSize(double pixels) |
|
55 | double pixelSizeToAxisXSize(double pixels) | |
56 | { |
|
56 | { | |
57 | auto axis = m_Plot->axisRect()->axis(QCPAxis::atBottom); |
|
57 | auto axis = m_Plot->axisRect()->axis(QCPAxis::atBottom); | |
58 | return axis->pixelToCoord(pixels) - axis->pixelToCoord(0); |
|
58 | return axis->pixelToCoord(pixels) - axis->pixelToCoord(0); | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | bool alignZones(VisualizationSelectionZoneItem *referenceZone, |
|
61 | bool alignZones(VisualizationSelectionZoneItem *referenceZone, | |
62 | const QVector<VisualizationSelectionZoneItem *> &zonesToAlign, bool alignOnLeft, |
|
62 | const QVector<VisualizationSelectionZoneItem *> &zonesToAlign, bool alignOnLeft, | |
63 | bool allowResize, bool vertically) |
|
63 | bool allowResize, bool vertically) | |
64 | { |
|
64 | { | |
65 | auto result = false; |
|
65 | auto result = false; | |
66 |
|
66 | |||
67 | auto referenceTime |
|
67 | auto referenceTime | |
68 | = alignOnLeft ? referenceZone->range().m_TStart : referenceZone->range().m_TEnd; |
|
68 | = alignOnLeft ? referenceZone->range().m_TStart : referenceZone->range().m_TEnd; | |
69 |
|
69 | |||
70 | auto referenceBottomAxis = m_Plot->axisRect()->axis(QCPAxis::atBottom); |
|
70 | auto referenceBottomAxis = m_Plot->axisRect()->axis(QCPAxis::atBottom); | |
71 | auto referenceVerticalPosition = referenceBottomAxis->coordToPixel(referenceTime); |
|
71 | auto referenceVerticalPosition = referenceBottomAxis->coordToPixel(referenceTime); | |
72 |
|
72 | |||
73 | for (auto otherZone : zonesToAlign) { |
|
73 | for (auto otherZone : zonesToAlign) { | |
74 |
|
74 | |||
75 | auto otherZoneRange = otherZone->range(); |
|
75 | auto otherZoneRange = otherZone->range(); | |
76 | auto newZoneStart = otherZoneRange.m_TStart; |
|
76 | auto newZoneStart = otherZoneRange.m_TStart; | |
77 | auto newZoneEnd = otherZoneRange.m_TEnd; |
|
77 | auto newZoneEnd = otherZoneRange.m_TEnd; | |
78 |
|
78 | |||
79 | auto alignedTime = referenceTime; |
|
79 | auto alignedTime = referenceTime; | |
80 | if (vertically) { |
|
80 | if (vertically) { | |
81 | auto otherZoneAxis = otherZone->parentPlot()->axisRect()->axis(QCPAxis::atBottom); |
|
81 | auto otherZoneAxis = otherZone->parentPlot()->axisRect()->axis(QCPAxis::atBottom); | |
82 | alignedTime = otherZoneAxis->pixelToCoord(referenceVerticalPosition); |
|
82 | alignedTime = otherZoneAxis->pixelToCoord(referenceVerticalPosition); | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | if (alignOnLeft) { |
|
85 | if (alignOnLeft) { | |
86 | newZoneStart = alignedTime; |
|
86 | newZoneStart = alignedTime; | |
87 | if (!allowResize) { |
|
87 | if (!allowResize) { | |
88 | newZoneEnd = alignedTime + (otherZoneRange.m_TEnd - otherZoneRange.m_TStart); |
|
88 | newZoneEnd = alignedTime + (otherZoneRange.m_TEnd - otherZoneRange.m_TStart); | |
89 | } |
|
89 | } | |
90 | } |
|
90 | } | |
91 | else { // align on right |
|
91 | else { // align on right | |
92 | newZoneEnd = alignedTime; |
|
92 | newZoneEnd = alignedTime; | |
93 | if (!allowResize) { |
|
93 | if (!allowResize) { | |
94 | newZoneStart = alignedTime - (otherZoneRange.m_TEnd - otherZoneRange.m_TStart); |
|
94 | newZoneStart = alignedTime - (otherZoneRange.m_TEnd - otherZoneRange.m_TStart); | |
95 | } |
|
95 | } | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | if (newZoneStart < newZoneEnd) { |
|
98 | if (newZoneStart < newZoneEnd) { | |
99 | result = true; |
|
99 | result = true; | |
100 | otherZone->setRange(newZoneStart, newZoneEnd); |
|
100 | otherZone->setRange(newZoneStart, newZoneEnd); | |
101 | otherZone->parentPlot()->replot(); |
|
101 | otherZone->parentPlot()->replot(); | |
102 | } |
|
102 | } | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | return result; |
|
105 | return result; | |
106 | } |
|
106 | } | |
107 | }; |
|
107 | }; | |
108 |
|
108 | |||
109 | VisualizationSelectionZoneItem::VisualizationSelectionZoneItem(QCustomPlot *plot) |
|
109 | VisualizationSelectionZoneItem::VisualizationSelectionZoneItem(QCustomPlot *plot) | |
110 | : QCPItemRect(plot), |
|
110 | : QCPItemRect(plot), | |
111 | impl{spimpl::make_unique_impl<VisualizationSelectionZoneItemPrivate>(plot)} |
|
111 | impl{spimpl::make_unique_impl<VisualizationSelectionZoneItemPrivate>(plot)} | |
112 | { |
|
112 | { | |
113 | topLeft->setTypeX(QCPItemPosition::ptPlotCoords); |
|
113 | topLeft->setTypeX(QCPItemPosition::ptPlotCoords); | |
114 | topLeft->setTypeY(QCPItemPosition::ptAxisRectRatio); |
|
114 | topLeft->setTypeY(QCPItemPosition::ptAxisRectRatio); | |
115 | bottomRight->setTypeX(QCPItemPosition::ptPlotCoords); |
|
115 | bottomRight->setTypeX(QCPItemPosition::ptPlotCoords); | |
116 | bottomRight->setTypeY(QCPItemPosition::ptAxisRectRatio); |
|
116 | bottomRight->setTypeY(QCPItemPosition::ptAxisRectRatio); | |
117 | setSelectable(false); |
|
117 | setSelectable(false); | |
118 |
|
118 | |||
119 | impl->m_RightLine = new QCPItemStraightLine(plot); |
|
119 | impl->m_RightLine = new QCPItemStraightLine(plot); | |
120 | impl->m_RightLine->point1->setParentAnchor(topRight); |
|
120 | impl->m_RightLine->point1->setParentAnchor(topRight); | |
121 | impl->m_RightLine->point2->setParentAnchor(bottomRight); |
|
121 | impl->m_RightLine->point2->setParentAnchor(bottomRight); | |
122 | impl->m_RightLine->point1->setTypeX(QCPItemPosition::ptAbsolute); |
|
122 | impl->m_RightLine->point1->setTypeX(QCPItemPosition::ptAbsolute); | |
123 | impl->m_RightLine->point1->setTypeY(QCPItemPosition::ptAbsolute); |
|
123 | impl->m_RightLine->point1->setTypeY(QCPItemPosition::ptAbsolute); | |
124 | impl->m_RightLine->point2->setTypeX(QCPItemPosition::ptAbsolute); |
|
124 | impl->m_RightLine->point2->setTypeX(QCPItemPosition::ptAbsolute); | |
125 | impl->m_RightLine->point2->setTypeY(QCPItemPosition::ptAbsolute); |
|
125 | impl->m_RightLine->point2->setTypeY(QCPItemPosition::ptAbsolute); | |
126 | impl->m_RightLine->setSelectable(false); |
|
126 | impl->m_RightLine->setSelectable(false); | |
127 |
|
127 | |||
128 | impl->m_LeftLine = new QCPItemStraightLine(plot); |
|
128 | impl->m_LeftLine = new QCPItemStraightLine(plot); | |
129 | impl->m_LeftLine->point1->setParentAnchor(topLeft); |
|
129 | impl->m_LeftLine->point1->setParentAnchor(topLeft); | |
130 | impl->m_LeftLine->point2->setParentAnchor(bottomLeft); |
|
130 | impl->m_LeftLine->point2->setParentAnchor(bottomLeft); | |
131 | impl->m_LeftLine->point1->setTypeX(QCPItemPosition::ptAbsolute); |
|
131 | impl->m_LeftLine->point1->setTypeX(QCPItemPosition::ptAbsolute); | |
132 | impl->m_LeftLine->point1->setTypeY(QCPItemPosition::ptAbsolute); |
|
132 | impl->m_LeftLine->point1->setTypeY(QCPItemPosition::ptAbsolute); | |
133 | impl->m_LeftLine->point2->setTypeX(QCPItemPosition::ptAbsolute); |
|
133 | impl->m_LeftLine->point2->setTypeX(QCPItemPosition::ptAbsolute); | |
134 | impl->m_LeftLine->point2->setTypeY(QCPItemPosition::ptAbsolute); |
|
134 | impl->m_LeftLine->point2->setTypeY(QCPItemPosition::ptAbsolute); | |
135 | impl->m_LeftLine->setSelectable(false); |
|
135 | impl->m_LeftLine->setSelectable(false); | |
136 |
|
136 | |||
137 | connect(this, &VisualizationSelectionZoneItem::selectionChanged, impl->m_RightLine, |
|
137 | connect(this, &VisualizationSelectionZoneItem::selectionChanged, impl->m_RightLine, | |
138 | &QCPItemStraightLine::setSelected); |
|
138 | &QCPItemStraightLine::setSelected); | |
139 | connect(this, &VisualizationSelectionZoneItem::selectionChanged, impl->m_LeftLine, |
|
139 | connect(this, &VisualizationSelectionZoneItem::selectionChanged, impl->m_LeftLine, | |
140 | &QCPItemStraightLine::setSelected); |
|
140 | &QCPItemStraightLine::setSelected); | |
141 |
|
141 | |||
142 | setColor(QColor(DEFAULT_COLOR)); |
|
142 | setColor(QColor(DEFAULT_COLOR)); | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 |
VisualizationSelectionZoneItem::~VisualizationSelectionZoneItem() |
|
145 | VisualizationSelectionZoneItem::~VisualizationSelectionZoneItem() | |
|
146 | { | |||
|
147 | } | |||
146 |
|
148 | |||
147 | VisualizationGraphWidget *VisualizationSelectionZoneItem::parentGraphWidget() const noexcept |
|
149 | VisualizationGraphWidget *VisualizationSelectionZoneItem::parentGraphWidget() const noexcept | |
148 | { |
|
150 | { | |
149 | auto parent = impl->m_Plot->parentWidget(); |
|
151 | auto parent = impl->m_Plot->parentWidget(); | |
150 | while (parent != nullptr && !qobject_cast<VisualizationGraphWidget *>(parent)) { |
|
152 | while (parent != nullptr && !qobject_cast<VisualizationGraphWidget *>(parent)) { | |
151 | parent = parent->parentWidget(); |
|
153 | parent = parent->parentWidget(); | |
152 | } |
|
154 | } | |
153 |
|
155 | |||
154 | return qobject_cast<VisualizationGraphWidget *>(parent); |
|
156 | return qobject_cast<VisualizationGraphWidget *>(parent); | |
155 | } |
|
157 | } | |
156 |
|
158 | |||
157 | void VisualizationSelectionZoneItem::setName(const QString &name) |
|
159 | void VisualizationSelectionZoneItem::setName(const QString &name) | |
158 | { |
|
160 | { | |
159 | if (name.isEmpty() && impl->m_NameLabelItem) { |
|
161 | if (name.isEmpty() && impl->m_NameLabelItem) { | |
160 | impl->m_Plot->removeItem(impl->m_NameLabelItem); |
|
162 | impl->m_Plot->removeItem(impl->m_NameLabelItem); | |
161 | impl->m_NameLabelItem = nullptr; |
|
163 | impl->m_NameLabelItem = nullptr; | |
162 | } |
|
164 | } | |
163 | else if (!impl->m_NameLabelItem) { |
|
165 | else if (!impl->m_NameLabelItem) { | |
164 | impl->m_NameLabelItem = new QCPItemText(impl->m_Plot); |
|
166 | impl->m_NameLabelItem = new QCPItemText(impl->m_Plot); | |
165 | impl->m_NameLabelItem->setText(name); |
|
167 | impl->m_NameLabelItem->setText(name); | |
166 | impl->m_NameLabelItem->setPositionAlignment(Qt::AlignHCenter | Qt::AlignTop); |
|
168 | impl->m_NameLabelItem->setPositionAlignment(Qt::AlignHCenter | Qt::AlignTop); | |
167 | impl->m_NameLabelItem->setColor(impl->m_Color); |
|
169 | impl->m_NameLabelItem->setColor(impl->m_Color); | |
168 | impl->m_NameLabelItem->position->setParentAnchor(top); |
|
170 | impl->m_NameLabelItem->position->setParentAnchor(top); | |
169 | } |
|
171 | } | |
170 | } |
|
172 | } | |
171 |
|
173 | |||
172 | QString VisualizationSelectionZoneItem::name() const |
|
174 | QString VisualizationSelectionZoneItem::name() const | |
173 | { |
|
175 | { | |
174 | if (!impl->m_NameLabelItem) { |
|
176 | if (!impl->m_NameLabelItem) { | |
175 | return QString(); |
|
177 | return QString(); | |
176 | } |
|
178 | } | |
177 |
|
179 | |||
178 | return impl->m_NameLabelItem->text(); |
|
180 | return impl->m_NameLabelItem->text(); | |
179 | } |
|
181 | } | |
180 |
|
182 | |||
181 | SqpRange VisualizationSelectionZoneItem::range() const |
|
183 | SqpRange VisualizationSelectionZoneItem::range() const | |
182 | { |
|
184 | { | |
183 | SqpRange range; |
|
185 | SqpRange range; | |
184 | range.m_TStart = impl->m_T1 <= impl->m_T2 ? impl->m_T1 : impl->m_T2; |
|
186 | range.m_TStart = impl->m_T1 <= impl->m_T2 ? impl->m_T1 : impl->m_T2; | |
185 | range.m_TEnd = impl->m_T1 > impl->m_T2 ? impl->m_T1 : impl->m_T2; |
|
187 | range.m_TEnd = impl->m_T1 > impl->m_T2 ? impl->m_T1 : impl->m_T2; | |
186 | return range; |
|
188 | return range; | |
187 | } |
|
189 | } | |
188 |
|
190 | |||
189 | void VisualizationSelectionZoneItem::setRange(double tstart, double tend) |
|
191 | void VisualizationSelectionZoneItem::setRange(double tstart, double tend) | |
190 | { |
|
192 | { | |
191 | impl->m_T1 = tstart; |
|
193 | impl->m_T1 = tstart; | |
192 | impl->m_T2 = tend; |
|
194 | impl->m_T2 = tend; | |
193 | impl->updatePosition(this); |
|
195 | impl->updatePosition(this); | |
194 | } |
|
196 | } | |
195 |
|
197 | |||
196 | void VisualizationSelectionZoneItem::setStart(double tstart) |
|
198 | void VisualizationSelectionZoneItem::setStart(double tstart) | |
197 | { |
|
199 | { | |
198 | impl->m_T1 = tstart; |
|
200 | impl->m_T1 = tstart; | |
199 | impl->updatePosition(this); |
|
201 | impl->updatePosition(this); | |
200 | } |
|
202 | } | |
201 |
|
203 | |||
202 | void VisualizationSelectionZoneItem::setEnd(double tend) |
|
204 | void VisualizationSelectionZoneItem::setEnd(double tend) | |
203 | { |
|
205 | { | |
204 | impl->m_T2 = tend; |
|
206 | impl->m_T2 = tend; | |
205 | impl->updatePosition(this); |
|
207 | impl->updatePosition(this); | |
206 | } |
|
208 | } | |
207 |
|
209 | |||
208 | void VisualizationSelectionZoneItem::setColor(const QColor &color) |
|
210 | void VisualizationSelectionZoneItem::setColor(const QColor &color) | |
209 | { |
|
211 | { | |
210 | impl->m_Color = color; |
|
212 | impl->m_Color = color; | |
211 |
|
213 | |||
212 | auto brushColor = color; |
|
214 | auto brushColor = color; | |
213 | brushColor.setAlpha(80); |
|
215 | brushColor.setAlpha(80); | |
214 | setBrush(QBrush(brushColor)); |
|
216 | setBrush(QBrush(brushColor)); | |
215 | setPen(QPen(Qt::NoPen)); |
|
217 | setPen(QPen(Qt::NoPen)); | |
216 |
|
218 | |||
217 | auto selectedBrushColor = brushColor; |
|
219 | auto selectedBrushColor = brushColor; | |
218 | selectedBrushColor.setAlpha(150); |
|
220 | selectedBrushColor.setAlpha(150); | |
219 | setSelectedBrush(QBrush(selectedBrushColor)); |
|
221 | setSelectedBrush(QBrush(selectedBrushColor)); | |
220 | setSelectedPen(QPen(Qt::NoPen)); |
|
222 | setSelectedPen(QPen(Qt::NoPen)); | |
221 |
|
223 | |||
222 | auto linePen = QPen(color); |
|
224 | auto linePen = QPen(color); | |
223 | linePen.setStyle(Qt::SolidLine); |
|
225 | linePen.setStyle(Qt::SolidLine); | |
224 | linePen.setWidth(4); |
|
226 | linePen.setWidth(4); | |
225 |
|
227 | |||
226 | auto selectedLinePen = linePen; |
|
228 | auto selectedLinePen = linePen; | |
227 | selectedLinePen.setColor(color.darker(120)); |
|
229 | selectedLinePen.setColor(color.darker(120)); | |
228 | selectedLinePen.setWidth(4); |
|
230 | selectedLinePen.setWidth(4); | |
229 |
|
231 | |||
230 | impl->m_LeftLine->setPen(linePen); |
|
232 | impl->m_LeftLine->setPen(linePen); | |
231 | impl->m_RightLine->setPen(linePen); |
|
233 | impl->m_RightLine->setPen(linePen); | |
232 |
|
234 | |||
233 | impl->m_LeftLine->setSelectedPen(selectedLinePen); |
|
235 | impl->m_LeftLine->setSelectedPen(selectedLinePen); | |
234 | impl->m_RightLine->setSelectedPen(selectedLinePen); |
|
236 | impl->m_RightLine->setSelectedPen(selectedLinePen); | |
235 | } |
|
237 | } | |
236 |
|
238 | |||
237 | void VisualizationSelectionZoneItem::setEditionEnabled(bool value) |
|
239 | void VisualizationSelectionZoneItem::setEditionEnabled(bool value) | |
238 | { |
|
240 | { | |
239 | impl->m_IsEditionEnabled = value; |
|
241 | impl->m_IsEditionEnabled = value; | |
240 | setSelectable(value); |
|
242 | setSelectable(value); | |
241 | if (!value) { |
|
243 | if (!value) { | |
242 | setSelected(false); |
|
244 | setSelected(false); | |
243 | impl->m_CurrentEditionMode = VisualizationSelectionZoneItemPrivate::EditionMode::NoEdition; |
|
245 | impl->m_CurrentEditionMode = VisualizationSelectionZoneItemPrivate::EditionMode::NoEdition; | |
244 | } |
|
246 | } | |
245 | } |
|
247 | } | |
246 |
|
248 | |||
247 | bool VisualizationSelectionZoneItem::isEditionEnabled() const |
|
249 | bool VisualizationSelectionZoneItem::isEditionEnabled() const | |
248 | { |
|
250 | { | |
249 | return impl->m_IsEditionEnabled; |
|
251 | return impl->m_IsEditionEnabled; | |
250 | } |
|
252 | } | |
251 |
|
253 | |||
252 | void VisualizationSelectionZoneItem::moveToTop() |
|
254 | void VisualizationSelectionZoneItem::moveToTop() | |
253 | { |
|
255 | { | |
254 | moveToLayer(layer(), false); |
|
256 | moveToLayer(layer(), false); | |
255 | } |
|
257 | } | |
256 |
|
258 | |||
257 | Qt::CursorShape |
|
259 | Qt::CursorShape | |
258 | VisualizationSelectionZoneItem::curshorShapeForPosition(const QPoint &position) const |
|
260 | VisualizationSelectionZoneItem::curshorShapeForPosition(const QPoint &position) const | |
259 | { |
|
261 | { | |
260 | auto mode = impl->m_CurrentEditionMode |
|
262 | auto mode = impl->m_CurrentEditionMode | |
261 | == VisualizationSelectionZoneItemPrivate::EditionMode::NoEdition |
|
263 | == VisualizationSelectionZoneItemPrivate::EditionMode::NoEdition | |
262 | ? impl->getEditionMode(position, this) |
|
264 | ? impl->getEditionMode(position, this) | |
263 | : impl->m_CurrentEditionMode; |
|
265 | : impl->m_CurrentEditionMode; | |
264 | switch (mode) { |
|
266 | switch (mode) { | |
265 | case VisualizationSelectionZoneItemPrivate::EditionMode::Move: |
|
267 | case VisualizationSelectionZoneItemPrivate::EditionMode::Move: | |
266 | return Qt::SizeAllCursor; |
|
268 | return Qt::SizeAllCursor; | |
267 | case VisualizationSelectionZoneItemPrivate::EditionMode::ResizeLeft: |
|
269 | case VisualizationSelectionZoneItemPrivate::EditionMode::ResizeLeft: | |
268 | case VisualizationSelectionZoneItemPrivate::EditionMode::ResizeRight: // fallthrough |
|
270 | case VisualizationSelectionZoneItemPrivate::EditionMode::ResizeRight: // fallthrough | |
269 | return Qt::SizeHorCursor; |
|
271 | return Qt::SizeHorCursor; | |
270 | default: |
|
272 | default: | |
271 | return Qt::ArrowCursor; |
|
273 | return Qt::ArrowCursor; | |
272 | } |
|
274 | } | |
273 | } |
|
275 | } | |
274 |
|
276 | |||
275 | void VisualizationSelectionZoneItem::setHovered(bool value) |
|
277 | void VisualizationSelectionZoneItem::setHovered(bool value) | |
276 | { |
|
278 | { | |
277 | if (value) { |
|
279 | if (value) { | |
278 | auto linePen = impl->m_LeftLine->pen(); |
|
280 | auto linePen = impl->m_LeftLine->pen(); | |
279 | linePen.setStyle(Qt::DotLine); |
|
281 | linePen.setStyle(Qt::DotLine); | |
280 | linePen.setWidth(3); |
|
282 | linePen.setWidth(3); | |
281 |
|
283 | |||
282 | auto selectedLinePen = impl->m_LeftLine->selectedPen(); |
|
284 | auto selectedLinePen = impl->m_LeftLine->selectedPen(); | |
283 | ; |
|
285 | ; | |
284 | selectedLinePen.setStyle(Qt::DotLine); |
|
286 | selectedLinePen.setStyle(Qt::DotLine); | |
285 | selectedLinePen.setWidth(3); |
|
287 | selectedLinePen.setWidth(3); | |
286 |
|
288 | |||
287 | impl->m_LeftLine->setPen(linePen); |
|
289 | impl->m_LeftLine->setPen(linePen); | |
288 | impl->m_RightLine->setPen(linePen); |
|
290 | impl->m_RightLine->setPen(linePen); | |
289 |
|
291 | |||
290 | impl->m_LeftLine->setSelectedPen(selectedLinePen); |
|
292 | impl->m_LeftLine->setSelectedPen(selectedLinePen); | |
291 | impl->m_RightLine->setSelectedPen(selectedLinePen); |
|
293 | impl->m_RightLine->setSelectedPen(selectedLinePen); | |
292 | } |
|
294 | } | |
293 | else { |
|
295 | else { | |
294 | setColor(impl->m_Color); |
|
296 | setColor(impl->m_Color); | |
295 | } |
|
297 | } | |
296 | } |
|
298 | } | |
297 |
|
299 | |||
298 | void VisualizationSelectionZoneItem::setAssociatedEditedZones( |
|
300 | void VisualizationSelectionZoneItem::setAssociatedEditedZones( | |
299 | const QVector<VisualizationSelectionZoneItem *> &associatedZones) |
|
301 | const QVector<VisualizationSelectionZoneItem *> &associatedZones) | |
300 | { |
|
302 | { | |
301 | impl->m_AssociatedEditedZones = associatedZones; |
|
303 | impl->m_AssociatedEditedZones = associatedZones; | |
302 | impl->m_AssociatedEditedZones.removeAll(this); |
|
304 | impl->m_AssociatedEditedZones.removeAll(this); | |
303 | } |
|
305 | } | |
304 |
|
306 | |||
305 | bool VisualizationSelectionZoneItem::alignZonesVerticallyOnLeft( |
|
307 | bool VisualizationSelectionZoneItem::alignZonesVerticallyOnLeft( | |
306 | const QVector<VisualizationSelectionZoneItem *> &zonesToAlign, bool allowResize) |
|
308 | const QVector<VisualizationSelectionZoneItem *> &zonesToAlign, bool allowResize) | |
307 | { |
|
309 | { | |
308 | return impl->alignZones(this, zonesToAlign, true, allowResize, true); |
|
310 | return impl->alignZones(this, zonesToAlign, true, allowResize, true); | |
309 | } |
|
311 | } | |
310 |
|
312 | |||
311 | bool VisualizationSelectionZoneItem::alignZonesVerticallyOnRight( |
|
313 | bool VisualizationSelectionZoneItem::alignZonesVerticallyOnRight( | |
312 | const QVector<VisualizationSelectionZoneItem *> &zonesToAlign, bool allowResize) |
|
314 | const QVector<VisualizationSelectionZoneItem *> &zonesToAlign, bool allowResize) | |
313 | { |
|
315 | { | |
314 | return impl->alignZones(this, zonesToAlign, false, allowResize, true); |
|
316 | return impl->alignZones(this, zonesToAlign, false, allowResize, true); | |
315 | } |
|
317 | } | |
316 |
|
318 | |||
317 | bool VisualizationSelectionZoneItem::alignZonesTemporallyOnLeft( |
|
319 | bool VisualizationSelectionZoneItem::alignZonesTemporallyOnLeft( | |
318 | const QVector<VisualizationSelectionZoneItem *> &zonesToAlign, bool allowResize) |
|
320 | const QVector<VisualizationSelectionZoneItem *> &zonesToAlign, bool allowResize) | |
319 | { |
|
321 | { | |
320 | return impl->alignZones(this, zonesToAlign, true, allowResize, false); |
|
322 | return impl->alignZones(this, zonesToAlign, true, allowResize, false); | |
321 | } |
|
323 | } | |
322 |
|
324 | |||
323 | bool VisualizationSelectionZoneItem::alignZonesTemporallyOnRight( |
|
325 | bool VisualizationSelectionZoneItem::alignZonesTemporallyOnRight( | |
324 | const QVector<VisualizationSelectionZoneItem *> &zonesToAlign, bool allowResize) |
|
326 | const QVector<VisualizationSelectionZoneItem *> &zonesToAlign, bool allowResize) | |
325 | { |
|
327 | { | |
326 | return impl->alignZones(this, zonesToAlign, false, allowResize, false); |
|
328 | return impl->alignZones(this, zonesToAlign, false, allowResize, false); | |
327 | } |
|
329 | } | |
328 |
|
330 | |||
329 | void VisualizationSelectionZoneItem::mousePressEvent(QMouseEvent *event, const QVariant &details) |
|
331 | void VisualizationSelectionZoneItem::mousePressEvent(QMouseEvent *event, const QVariant &details) | |
330 | { |
|
332 | { | |
331 | Q_UNUSED(details); |
|
333 | Q_UNUSED(details); | |
332 |
|
334 | |||
333 | if (isEditionEnabled() && event->button() == Qt::LeftButton) { |
|
335 | if (isEditionEnabled() && event->button() == Qt::LeftButton) { | |
334 | impl->m_CurrentEditionMode = impl->getEditionMode(event->pos(), this); |
|
336 | impl->m_CurrentEditionMode = impl->getEditionMode(event->pos(), this); | |
335 |
|
337 | |||
336 | impl->m_MovedOrinalT1 = impl->m_T1; |
|
338 | impl->m_MovedOrinalT1 = impl->m_T1; | |
337 | impl->m_MovedOrinalT2 = impl->m_T2; |
|
339 | impl->m_MovedOrinalT2 = impl->m_T2; | |
338 | for (auto associatedZone : impl->m_AssociatedEditedZones) { |
|
340 | for (auto associatedZone : impl->m_AssociatedEditedZones) { | |
339 | associatedZone->impl->m_MovedOrinalT1 = associatedZone->impl->m_T1; |
|
341 | associatedZone->impl->m_MovedOrinalT1 = associatedZone->impl->m_T1; | |
340 | associatedZone->impl->m_MovedOrinalT2 = associatedZone->impl->m_T2; |
|
342 | associatedZone->impl->m_MovedOrinalT2 = associatedZone->impl->m_T2; | |
341 | } |
|
343 | } | |
342 | } |
|
344 | } | |
343 | else { |
|
345 | else { | |
344 | impl->m_CurrentEditionMode = VisualizationSelectionZoneItemPrivate::EditionMode::NoEdition; |
|
346 | impl->m_CurrentEditionMode = VisualizationSelectionZoneItemPrivate::EditionMode::NoEdition; | |
345 | event->ignore(); |
|
347 | event->ignore(); | |
346 | } |
|
348 | } | |
347 | } |
|
349 | } | |
348 |
|
350 | |||
349 | void VisualizationSelectionZoneItem::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) |
|
351 | void VisualizationSelectionZoneItem::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) | |
350 | { |
|
352 | { | |
351 | if (isEditionEnabled()) { |
|
353 | if (isEditionEnabled()) { | |
352 | if (!selected()) { |
|
354 | if (!selected()) { | |
353 | // Force the item to be selected during the edition |
|
355 | // Force the item to be selected during the edition | |
354 | parentGraphWidget()->parentVisualizationWidget()->selectionZoneManager().setSelected( |
|
356 | parentGraphWidget()->parentVisualizationWidget()->selectionZoneManager().setSelected( | |
355 | this, true); |
|
357 | this, true); | |
356 | } |
|
358 | } | |
357 |
|
359 | |||
358 | auto axis = impl->m_Plot->axisRect()->axis(QCPAxis::atBottom); |
|
360 | auto axis = impl->m_Plot->axisRect()->axis(QCPAxis::atBottom); | |
359 | auto pixelDiff = event->pos().x() - startPos.x(); |
|
361 | auto pixelDiff = event->pos().x() - startPos.x(); | |
360 | auto diff = impl->pixelSizeToAxisXSize(pixelDiff); |
|
362 | auto diff = impl->pixelSizeToAxisXSize(pixelDiff); | |
361 |
|
363 | |||
362 | switch (impl->m_CurrentEditionMode) { |
|
364 | switch (impl->m_CurrentEditionMode) { | |
363 | case VisualizationSelectionZoneItemPrivate::EditionMode::Move: |
|
365 | case VisualizationSelectionZoneItemPrivate::EditionMode::Move: | |
364 | setRange(impl->m_MovedOrinalT1 + diff, impl->m_MovedOrinalT2 + diff); |
|
366 | setRange(impl->m_MovedOrinalT1 + diff, impl->m_MovedOrinalT2 + diff); | |
365 | for (auto associatedZone : impl->m_AssociatedEditedZones) { |
|
367 | for (auto associatedZone : impl->m_AssociatedEditedZones) { | |
366 | associatedZone->move(pixelDiff); |
|
368 | associatedZone->move(pixelDiff); | |
367 | } |
|
369 | } | |
368 | break; |
|
370 | break; | |
369 | case VisualizationSelectionZoneItemPrivate::EditionMode::ResizeLeft: |
|
371 | case VisualizationSelectionZoneItemPrivate::EditionMode::ResizeLeft: | |
370 | setStart(impl->m_MovedOrinalT1 + diff); |
|
372 | setStart(impl->m_MovedOrinalT1 + diff); | |
371 | for (auto associatedZone : impl->m_AssociatedEditedZones) { |
|
373 | for (auto associatedZone : impl->m_AssociatedEditedZones) { | |
372 | impl->m_MovedOrinalT1 < impl->m_MovedOrinalT2 |
|
374 | impl->m_MovedOrinalT1 < impl->m_MovedOrinalT2 | |
373 | ? associatedZone->resizeLeft(pixelDiff) |
|
375 | ? associatedZone->resizeLeft(pixelDiff) | |
374 | : associatedZone->resizeRight(pixelDiff); |
|
376 | : associatedZone->resizeRight(pixelDiff); | |
375 | } |
|
377 | } | |
376 | break; |
|
378 | break; | |
377 | case VisualizationSelectionZoneItemPrivate::EditionMode::ResizeRight: |
|
379 | case VisualizationSelectionZoneItemPrivate::EditionMode::ResizeRight: | |
378 | setEnd(impl->m_MovedOrinalT2 + diff); |
|
380 | setEnd(impl->m_MovedOrinalT2 + diff); | |
379 | for (auto associatedZone : impl->m_AssociatedEditedZones) { |
|
381 | for (auto associatedZone : impl->m_AssociatedEditedZones) { | |
380 | impl->m_MovedOrinalT1 < impl->m_MovedOrinalT2 |
|
382 | impl->m_MovedOrinalT1 < impl->m_MovedOrinalT2 | |
381 | ? associatedZone->resizeRight(pixelDiff) |
|
383 | ? associatedZone->resizeRight(pixelDiff) | |
382 | : associatedZone->resizeLeft(pixelDiff); |
|
384 | : associatedZone->resizeLeft(pixelDiff); | |
383 | } |
|
385 | } | |
384 | break; |
|
386 | break; | |
385 | default: |
|
387 | default: | |
386 | break; |
|
388 | break; | |
387 | } |
|
389 | } | |
388 |
|
390 | |||
389 | for (auto associatedZone : impl->m_AssociatedEditedZones) { |
|
391 | for (auto associatedZone : impl->m_AssociatedEditedZones) { | |
390 | associatedZone->parentPlot()->replot(); |
|
392 | associatedZone->parentPlot()->replot(); | |
391 | } |
|
393 | } | |
392 | } |
|
394 | } | |
393 | else { |
|
395 | else { | |
394 | event->ignore(); |
|
396 | event->ignore(); | |
395 | } |
|
397 | } | |
396 | } |
|
398 | } | |
397 |
|
399 | |||
398 | void VisualizationSelectionZoneItem::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) |
|
400 | void VisualizationSelectionZoneItem::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) | |
399 | { |
|
401 | { | |
400 | Q_UNUSED(startPos); |
|
402 | Q_UNUSED(startPos); | |
401 |
|
403 | |||
402 | if (isEditionEnabled()) { |
|
404 | if (isEditionEnabled()) { | |
403 | impl->m_CurrentEditionMode = VisualizationSelectionZoneItemPrivate::EditionMode::NoEdition; |
|
405 | impl->m_CurrentEditionMode = VisualizationSelectionZoneItemPrivate::EditionMode::NoEdition; | |
404 | } |
|
406 | } | |
405 | else { |
|
407 | else { | |
406 | event->ignore(); |
|
408 | event->ignore(); | |
407 | } |
|
409 | } | |
408 |
|
410 | |||
409 | impl->m_AssociatedEditedZones.clear(); |
|
411 | impl->m_AssociatedEditedZones.clear(); | |
410 | } |
|
412 | } | |
411 |
|
413 | |||
412 | void VisualizationSelectionZoneItem::resizeLeft(double pixelDiff) |
|
414 | void VisualizationSelectionZoneItem::resizeLeft(double pixelDiff) | |
413 | { |
|
415 | { | |
414 | auto diff = impl->pixelSizeToAxisXSize(pixelDiff); |
|
416 | auto diff = impl->pixelSizeToAxisXSize(pixelDiff); | |
415 | if (impl->m_MovedOrinalT1 <= impl->m_MovedOrinalT2) { |
|
417 | if (impl->m_MovedOrinalT1 <= impl->m_MovedOrinalT2) { | |
416 | setStart(impl->m_MovedOrinalT1 + diff); |
|
418 | setStart(impl->m_MovedOrinalT1 + diff); | |
417 | } |
|
419 | } | |
418 | else { |
|
420 | else { | |
419 | setEnd(impl->m_MovedOrinalT2 + diff); |
|
421 | setEnd(impl->m_MovedOrinalT2 + diff); | |
420 | } |
|
422 | } | |
421 | } |
|
423 | } | |
422 |
|
424 | |||
423 | void VisualizationSelectionZoneItem::resizeRight(double pixelDiff) |
|
425 | void VisualizationSelectionZoneItem::resizeRight(double pixelDiff) | |
424 | { |
|
426 | { | |
425 | auto diff = impl->pixelSizeToAxisXSize(pixelDiff); |
|
427 | auto diff = impl->pixelSizeToAxisXSize(pixelDiff); | |
426 | if (impl->m_MovedOrinalT1 > impl->m_MovedOrinalT2) { |
|
428 | if (impl->m_MovedOrinalT1 > impl->m_MovedOrinalT2) { | |
427 | setStart(impl->m_MovedOrinalT1 + diff); |
|
429 | setStart(impl->m_MovedOrinalT1 + diff); | |
428 | } |
|
430 | } | |
429 | else { |
|
431 | else { | |
430 | setEnd(impl->m_MovedOrinalT2 + diff); |
|
432 | setEnd(impl->m_MovedOrinalT2 + diff); | |
431 | } |
|
433 | } | |
432 | } |
|
434 | } | |
433 |
|
435 | |||
434 | void VisualizationSelectionZoneItem::move(double pixelDiff) |
|
436 | void VisualizationSelectionZoneItem::move(double pixelDiff) | |
435 | { |
|
437 | { | |
436 | auto diff = impl->pixelSizeToAxisXSize(pixelDiff); |
|
438 | auto diff = impl->pixelSizeToAxisXSize(pixelDiff); | |
437 | setRange(impl->m_MovedOrinalT1 + diff, impl->m_MovedOrinalT2 + diff); |
|
439 | setRange(impl->m_MovedOrinalT1 + diff, impl->m_MovedOrinalT2 + diff); | |
438 | } |
|
440 | } |
@@ -1,579 +1,579 | |||||
1 | #include "AmdaResultParser.h" |
|
1 | #include "AmdaResultParser.h" | |
2 |
|
2 | |||
3 | #include <Data/ScalarSeries.h> |
|
3 | #include <Data/ScalarSeries.h> | |
4 | #include <Data/SpectrogramSeries.h> |
|
4 | #include <Data/SpectrogramSeries.h> | |
5 | #include <Data/VectorSeries.h> |
|
5 | #include <Data/VectorSeries.h> | |
6 |
|
6 | |||
7 | #include <QObject> |
|
7 | #include <QObject> | |
8 | #include <QtTest> |
|
8 | #include <QtTest> | |
9 |
|
9 | |||
10 | namespace { |
|
10 | namespace { | |
11 |
|
11 | |||
12 | /// Path for the tests |
|
12 | /// Path for the tests | |
13 | const auto TESTS_RESOURCES_PATH |
|
13 | const auto TESTS_RESOURCES_PATH | |
14 | = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaResultParser"}.absoluteFilePath(); |
|
14 | = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaResultParser"}.absoluteFilePath(); | |
15 |
|
15 | |||
16 | QDateTime dateTime(int year, int month, int day, int hours, int minutes, int seconds) |
|
16 | QDateTime dateTime(int year, int month, int day, int hours, int minutes, int seconds) | |
17 | { |
|
17 | { | |
18 | return QDateTime{{year, month, day}, {hours, minutes, seconds}, Qt::UTC}; |
|
18 | return QDateTime{{year, month, day}, {hours, minutes, seconds}, Qt::UTC}; | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 | QString inputFilePath(const QString &inputFileName) |
|
21 | QString inputFilePath(const QString &inputFileName) | |
22 | { |
|
22 | { | |
23 | return QFileInfo{TESTS_RESOURCES_PATH, inputFileName}.absoluteFilePath(); |
|
23 | return QFileInfo{TESTS_RESOURCES_PATH, inputFileName}.absoluteFilePath(); | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | template <typename T> |
|
26 | template <typename T> | |
27 | struct ExpectedResults { |
|
27 | struct ExpectedResults { | |
28 |
|
28 | |||
29 | ExpectedResults &setParsingOK(bool parsingOK) |
|
29 | ExpectedResults &setParsingOK(bool parsingOK) | |
30 | { |
|
30 | { | |
31 | m_ParsingOK = parsingOK; |
|
31 | m_ParsingOK = parsingOK; | |
32 | return *this; |
|
32 | return *this; | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | ExpectedResults &setXAxisUnit(Unit xAxisUnit) |
|
35 | ExpectedResults &setXAxisUnit(Unit xAxisUnit) | |
36 | { |
|
36 | { | |
37 | m_XAxisUnit = std::move(xAxisUnit); |
|
37 | m_XAxisUnit = std::move(xAxisUnit); | |
38 | return *this; |
|
38 | return *this; | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | ExpectedResults &setXAxisData(const QVector<QDateTime> &xAxisData) |
|
41 | ExpectedResults &setXAxisData(const QVector<QDateTime> &xAxisData) | |
42 | { |
|
42 | { | |
43 | m_XAxisData.clear(); |
|
43 | m_XAxisData.clear(); | |
44 |
|
44 | |||
45 | // Converts QVector<QDateTime> to QVector<double> |
|
45 | // Converts QVector<QDateTime> to QVector<double> | |
46 | std::transform(xAxisData.cbegin(), xAxisData.cend(), std::back_inserter(m_XAxisData), |
|
46 | std::transform(xAxisData.cbegin(), xAxisData.cend(), std::back_inserter(m_XAxisData), | |
47 | [](const auto &dateTime) { return dateTime.toMSecsSinceEpoch() / 1000.; }); |
|
47 | [](const auto &dateTime) { return dateTime.toMSecsSinceEpoch() / 1000.; }); | |
48 |
|
48 | |||
49 | return *this; |
|
49 | return *this; | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | ExpectedResults &setValuesUnit(Unit valuesUnit) |
|
52 | ExpectedResults &setValuesUnit(Unit valuesUnit) | |
53 | { |
|
53 | { | |
54 | m_ValuesUnit = std::move(valuesUnit); |
|
54 | m_ValuesUnit = std::move(valuesUnit); | |
55 | return *this; |
|
55 | return *this; | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | ExpectedResults &setValuesData(QVector<double> valuesData) |
|
58 | ExpectedResults &setValuesData(QVector<double> valuesData) | |
59 | { |
|
59 | { | |
60 | m_ValuesData.clear(); |
|
60 | m_ValuesData.clear(); | |
61 | m_ValuesData.push_back(std::move(valuesData)); |
|
61 | m_ValuesData.push_back(std::move(valuesData)); | |
62 | return *this; |
|
62 | return *this; | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | ExpectedResults &setValuesData(QVector<QVector<double> > valuesData) |
|
65 | ExpectedResults &setValuesData(QVector<QVector<double> > valuesData) | |
66 | { |
|
66 | { | |
67 | m_ValuesData = std::move(valuesData); |
|
67 | m_ValuesData = std::move(valuesData); | |
68 | return *this; |
|
68 | return *this; | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | ExpectedResults &setYAxisEnabled(bool yAxisEnabled) |
|
71 | ExpectedResults &setYAxisEnabled(bool yAxisEnabled) | |
72 | { |
|
72 | { | |
73 | m_YAxisEnabled = yAxisEnabled; |
|
73 | m_YAxisEnabled = yAxisEnabled; | |
74 | return *this; |
|
74 | return *this; | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | ExpectedResults &setYAxisUnit(Unit yAxisUnit) |
|
77 | ExpectedResults &setYAxisUnit(Unit yAxisUnit) | |
78 | { |
|
78 | { | |
79 | m_YAxisUnit = std::move(yAxisUnit); |
|
79 | m_YAxisUnit = std::move(yAxisUnit); | |
80 | return *this; |
|
80 | return *this; | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | ExpectedResults &setYAxisData(QVector<double> yAxisData) |
|
83 | ExpectedResults &setYAxisData(QVector<double> yAxisData) | |
84 | { |
|
84 | { | |
85 | m_YAxisData = std::move(yAxisData); |
|
85 | m_YAxisData = std::move(yAxisData); | |
86 | return *this; |
|
86 | return *this; | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | /** |
|
89 | /** | |
90 | * Validates a DataSeries compared to the expected results |
|
90 | * Validates a DataSeries compared to the expected results | |
91 | * @param results the DataSeries to validate |
|
91 | * @param results the DataSeries to validate | |
92 | */ |
|
92 | */ | |
93 | void validate(std::shared_ptr<IDataSeries> results) |
|
93 | void validate(std::shared_ptr<IDataSeries> results) | |
94 | { |
|
94 | { | |
95 | if (m_ParsingOK) { |
|
95 | if (m_ParsingOK) { | |
96 | auto dataSeries = dynamic_cast<T *>(results.get()); |
|
96 | auto dataSeries = dynamic_cast<T *>(results.get()); | |
97 | if (dataSeries == nullptr) { |
|
97 | if (dataSeries == nullptr) { | |
98 |
|
98 | |||
99 | // No unit detected, parsink ok but data is nullptr |
|
99 | // No unit detected, parsink ok but data is nullptr | |
100 | // TODO, improve the test to verify that the data is null |
|
100 | // TODO, improve the test to verify that the data is null | |
101 | return; |
|
101 | return; | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | // Checks units |
|
104 | // Checks units | |
105 | QVERIFY(dataSeries->xAxisUnit() == m_XAxisUnit); |
|
105 | QVERIFY(dataSeries->xAxisUnit() == m_XAxisUnit); | |
106 | QVERIFY(dataSeries->valuesUnit() == m_ValuesUnit); |
|
106 | QVERIFY(dataSeries->valuesUnit() == m_ValuesUnit); | |
107 |
|
107 | |||
108 | auto verifyRange = [dataSeries](const auto &expectedData, const auto &equalFun) { |
|
108 | auto verifyRange = [dataSeries](const auto &expectedData, const auto &equalFun) { | |
109 | QVERIFY(std::equal(dataSeries->cbegin(), dataSeries->cend(), expectedData.cbegin(), |
|
109 | QVERIFY(std::equal(dataSeries->cbegin(), dataSeries->cend(), expectedData.cbegin(), | |
110 | expectedData.cend(), |
|
110 | expectedData.cend(), | |
111 | [&equalFun](const auto &dataSeriesIt, const auto &expectedX) { |
|
111 | [&equalFun](const auto &dataSeriesIt, const auto &expectedX) { | |
112 | return equalFun(dataSeriesIt, expectedX); |
|
112 | return equalFun(dataSeriesIt, expectedX); | |
113 | })); |
|
113 | })); | |
114 | }; |
|
114 | }; | |
115 |
|
115 | |||
116 | // Checks x-axis data |
|
116 | // Checks x-axis data | |
117 | verifyRange(m_XAxisData, [](const auto &seriesIt, const auto &value) { |
|
117 | verifyRange(m_XAxisData, [](const auto &seriesIt, const auto &value) { | |
118 | return seriesIt.x() == value; |
|
118 | return seriesIt.x() == value; | |
119 | }); |
|
119 | }); | |
120 |
|
120 | |||
121 | // Checks values data of each component |
|
121 | // Checks values data of each component | |
122 | for (auto i = 0; i < m_ValuesData.size(); ++i) { |
|
122 | for (auto i = 0; i < m_ValuesData.size(); ++i) { | |
123 | verifyRange(m_ValuesData.at(i), [i](const auto &seriesIt, const auto &value) { |
|
123 | verifyRange(m_ValuesData.at(i), [i](const auto &seriesIt, const auto &value) { | |
124 | auto itValue = seriesIt.value(i); |
|
124 | auto itValue = seriesIt.value(i); | |
125 | return (std::isnan(itValue) && std::isnan(value)) || seriesIt.value(i) == value; |
|
125 | return (std::isnan(itValue) && std::isnan(value)) || seriesIt.value(i) == value; | |
126 | }); |
|
126 | }); | |
127 | } |
|
127 | } | |
128 |
|
128 | |||
129 | // Checks y-axis (if defined) |
|
129 | // Checks y-axis (if defined) | |
130 | auto yAxis = dataSeries->yAxis(); |
|
130 | auto yAxis = dataSeries->yAxis(); | |
131 | QCOMPARE(yAxis.isDefined(), m_YAxisEnabled); |
|
131 | QCOMPARE(yAxis.isDefined(), m_YAxisEnabled); | |
132 |
|
132 | |||
133 | if (m_YAxisEnabled) { |
|
133 | if (m_YAxisEnabled) { | |
134 | // Unit |
|
134 | // Unit | |
135 | QCOMPARE(yAxis.unit(), m_YAxisUnit); |
|
135 | QCOMPARE(yAxis.unit(), m_YAxisUnit); | |
136 |
|
136 | |||
137 | // Data |
|
137 | // Data | |
138 | QVERIFY(std::equal(yAxis.cbegin(), yAxis.cend(), m_YAxisData.cbegin(), |
|
138 | QVERIFY(std::equal(yAxis.cbegin(), yAxis.cend(), m_YAxisData.cbegin(), | |
139 | m_YAxisData.cend(), [](const auto &it, const auto &expectedVal) { |
|
139 | m_YAxisData.cend(), [](const auto &it, const auto &expectedVal) { | |
140 | return it.first() == expectedVal; |
|
140 | return it.first() == expectedVal; | |
141 | })); |
|
141 | })); | |
142 | } |
|
142 | } | |
143 | } |
|
143 | } | |
144 | else { |
|
144 | else { | |
145 | QVERIFY(results == nullptr); |
|
145 | QVERIFY(results == nullptr); | |
146 | } |
|
146 | } | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | // Parsing was successfully completed |
|
149 | // Parsing was successfully completed | |
150 | bool m_ParsingOK{false}; |
|
150 | bool m_ParsingOK{false}; | |
151 | // Expected x-axis unit |
|
151 | // Expected x-axis unit | |
152 | Unit m_XAxisUnit{}; |
|
152 | Unit m_XAxisUnit{}; | |
153 | // Expected x-axis data |
|
153 | // Expected x-axis data | |
154 | QVector<double> m_XAxisData{}; |
|
154 | QVector<double> m_XAxisData{}; | |
155 | // Expected values unit |
|
155 | // Expected values unit | |
156 | Unit m_ValuesUnit{}; |
|
156 | Unit m_ValuesUnit{}; | |
157 | // Expected values data |
|
157 | // Expected values data | |
158 | QVector<QVector<double> > m_ValuesData{}; |
|
158 | QVector<QVector<double> > m_ValuesData{}; | |
159 | // Expected data series has y-axis |
|
159 | // Expected data series has y-axis | |
160 | bool m_YAxisEnabled{false}; |
|
160 | bool m_YAxisEnabled{false}; | |
161 | // Expected y-axis unit (if axis defined) |
|
161 | // Expected y-axis unit (if axis defined) | |
162 | Unit m_YAxisUnit{}; |
|
162 | Unit m_YAxisUnit{}; | |
163 | // Expected y-axis data (if axis defined) |
|
163 | // Expected y-axis data (if axis defined) | |
164 | QVector<double> m_YAxisData{}; |
|
164 | QVector<double> m_YAxisData{}; | |
165 | }; |
|
165 | }; | |
166 |
|
166 | |||
167 | } // namespace |
|
167 | } // namespace | |
168 |
|
168 | |||
169 | Q_DECLARE_METATYPE(ExpectedResults<ScalarSeries>) |
|
169 | Q_DECLARE_METATYPE(ExpectedResults<ScalarSeries>) | |
170 | Q_DECLARE_METATYPE(ExpectedResults<SpectrogramSeries>) |
|
170 | Q_DECLARE_METATYPE(ExpectedResults<SpectrogramSeries>) | |
171 | Q_DECLARE_METATYPE(ExpectedResults<VectorSeries>) |
|
171 | Q_DECLARE_METATYPE(ExpectedResults<VectorSeries>) | |
172 |
|
172 | |||
173 | class TestAmdaResultParser : public QObject { |
|
173 | class TestAmdaResultParser : public QObject { | |
174 | Q_OBJECT |
|
174 | Q_OBJECT | |
175 | private: |
|
175 | private: | |
176 | template <typename T> |
|
176 | template <typename T> | |
177 | void testReadDataStructure() |
|
177 | void testReadDataStructure() | |
178 | { |
|
178 | { | |
179 | // ////////////// // |
|
179 | // ////////////// // | |
180 | // Test structure // |
|
180 | // Test structure // | |
181 | // ////////////// // |
|
181 | // ////////////// // | |
182 |
|
182 | |||
183 | // Name of TXT file to read |
|
183 | // Name of TXT file to read | |
184 | QTest::addColumn<QString>("inputFileName"); |
|
184 | QTest::addColumn<QString>("inputFileName"); | |
185 | // Expected results |
|
185 | // Expected results | |
186 | QTest::addColumn<ExpectedResults<T> >("expectedResults"); |
|
186 | QTest::addColumn<ExpectedResults<T> >("expectedResults"); | |
187 | } |
|
187 | } | |
188 |
|
188 | |||
189 | template <typename T> |
|
189 | template <typename T> | |
190 | void testRead(AmdaResultParser::ValueType valueType) |
|
190 | void testRead(AmdaResultParser::ValueType valueType) | |
191 | { |
|
191 | { | |
192 | QFETCH(QString, inputFileName); |
|
192 | QFETCH(QString, inputFileName); | |
193 | QFETCH(ExpectedResults<T>, expectedResults); |
|
193 | QFETCH(ExpectedResults<T>, expectedResults); | |
194 |
|
194 | |||
195 | // Parses file |
|
195 | // Parses file | |
196 | auto filePath = inputFilePath(inputFileName); |
|
196 | auto filePath = inputFilePath(inputFileName); | |
197 | auto results = AmdaResultParser::readTxt(filePath, valueType); |
|
197 | auto results = AmdaResultParser::readTxt(filePath, valueType); | |
198 |
|
198 | |||
199 | // ///////////////// // |
|
199 | // ///////////////// // | |
200 | // Validates results // |
|
200 | // Validates results // | |
201 | // ///////////////// // |
|
201 | // ///////////////// // | |
202 | expectedResults.validate(results); |
|
202 | expectedResults.validate(results); | |
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 | private slots: |
|
205 | private slots: | |
206 | /// Input test data |
|
206 | /// Input test data | |
207 | /// @sa testReadScalarTxt() |
|
207 | /// @sa testReadScalarTxt() | |
208 | void testReadScalarTxt_data(); |
|
208 | void testReadScalarTxt_data(); | |
209 |
|
209 | |||
210 | /// Tests parsing scalar series of a TXT file |
|
210 | /// Tests parsing scalar series of a TXT file | |
211 | void testReadScalarTxt(); |
|
211 | void testReadScalarTxt(); | |
212 |
|
212 | |||
213 | /// Input test data |
|
213 | /// Input test data | |
214 | /// @sa testReadSpectrogramTxt() |
|
214 | /// @sa testReadSpectrogramTxt() | |
215 | void testReadSpectrogramTxt_data(); |
|
215 | void testReadSpectrogramTxt_data(); | |
216 |
|
216 | |||
217 | /// Tests parsing spectrogram series of a TXT file |
|
217 | /// Tests parsing spectrogram series of a TXT file | |
218 | void testReadSpectrogramTxt(); |
|
218 | void testReadSpectrogramTxt(); | |
219 |
|
219 | |||
220 | /// Input test data |
|
220 | /// Input test data | |
221 | /// @sa testReadVectorTxt() |
|
221 | /// @sa testReadVectorTxt() | |
222 | void testReadVectorTxt_data(); |
|
222 | void testReadVectorTxt_data(); | |
223 |
|
223 | |||
224 | /// Tests parsing vector series of a TXT file |
|
224 | /// Tests parsing vector series of a TXT file | |
225 | void testReadVectorTxt(); |
|
225 | void testReadVectorTxt(); | |
226 | }; |
|
226 | }; | |
227 |
|
227 | |||
228 | void TestAmdaResultParser::testReadScalarTxt_data() |
|
228 | void TestAmdaResultParser::testReadScalarTxt_data() | |
229 | { |
|
229 | { | |
230 | testReadDataStructure<ScalarSeries>(); |
|
230 | testReadDataStructure<ScalarSeries>(); | |
231 |
|
231 | |||
232 | // ////////// // |
|
232 | // ////////// // | |
233 | // Test cases // |
|
233 | // Test cases // | |
234 | // ////////// // |
|
234 | // ////////// // | |
235 |
|
235 | |||
236 | // Valid files |
|
236 | // Valid files | |
237 | QTest::newRow("Valid file") |
|
237 | QTest::newRow("Valid file") | |
238 | << QStringLiteral("ValidScalar1.txt") |
|
238 | << QStringLiteral("ValidScalar1.txt") | |
239 | << ExpectedResults<ScalarSeries>{} |
|
239 | << ExpectedResults<ScalarSeries>{} | |
240 | .setParsingOK(true) |
|
240 | .setParsingOK(true) | |
241 | .setXAxisUnit(Unit{"nT", true}) |
|
241 | .setXAxisUnit(Unit{"nT", true}) | |
242 | .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), |
|
242 | .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), | |
243 | dateTime(2013, 9, 23, 9, 2, 30), dateTime(2013, 9, 23, 9, 3, 30), |
|
243 | dateTime(2013, 9, 23, 9, 2, 30), dateTime(2013, 9, 23, 9, 3, 30), | |
244 | dateTime(2013, 9, 23, 9, 4, 30), dateTime(2013, 9, 23, 9, 5, 30), |
|
244 | dateTime(2013, 9, 23, 9, 4, 30), dateTime(2013, 9, 23, 9, 5, 30), | |
245 | dateTime(2013, 9, 23, 9, 6, 30), dateTime(2013, 9, 23, 9, 7, 30), |
|
245 | dateTime(2013, 9, 23, 9, 6, 30), dateTime(2013, 9, 23, 9, 7, 30), | |
246 | dateTime(2013, 9, 23, 9, 8, 30), dateTime(2013, 9, 23, 9, 9, 30)}) |
|
246 | dateTime(2013, 9, 23, 9, 8, 30), dateTime(2013, 9, 23, 9, 9, 30)}) | |
247 | .setValuesData({-2.83950, -2.71850, -2.52150, -2.57633, -2.58050, -2.48325, -2.63025, |
|
247 | .setValuesData({-2.83950, -2.71850, -2.52150, -2.57633, -2.58050, -2.48325, -2.63025, | |
248 | -2.55800, -2.43250, -2.42200}); |
|
248 | -2.55800, -2.43250, -2.42200}); | |
249 |
|
249 | |||
250 | QTest::newRow("Valid file (value of first line is invalid but it is converted to NaN") |
|
250 | QTest::newRow("Valid file (value of first line is invalid but it is converted to NaN") | |
251 | << QStringLiteral("WrongValue.txt") |
|
251 | << QStringLiteral("WrongValue.txt") | |
252 | << ExpectedResults<ScalarSeries>{} |
|
252 | << ExpectedResults<ScalarSeries>{} | |
253 | .setParsingOK(true) |
|
253 | .setParsingOK(true) | |
254 | .setXAxisUnit(Unit{"nT", true}) |
|
254 | .setXAxisUnit(Unit{"nT", true}) | |
255 | .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), |
|
255 | .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), | |
256 | dateTime(2013, 9, 23, 9, 2, 30)}) |
|
256 | dateTime(2013, 9, 23, 9, 2, 30)}) | |
257 | .setValuesData({std::numeric_limits<double>::quiet_NaN(), -2.71850, -2.52150}); |
|
257 | .setValuesData({std::numeric_limits<double>::quiet_NaN(), -2.71850, -2.52150}); | |
258 |
|
258 | |||
259 | QTest::newRow("Valid file that contains NaN values") |
|
259 | QTest::newRow("Valid file that contains NaN values") | |
260 | << QStringLiteral("NaNValue.txt") |
|
260 | << QStringLiteral("NaNValue.txt") | |
261 | << ExpectedResults<ScalarSeries>{} |
|
261 | << ExpectedResults<ScalarSeries>{} | |
262 | .setParsingOK(true) |
|
262 | .setParsingOK(true) | |
263 | .setXAxisUnit(Unit{("nT"), true}) |
|
263 | .setXAxisUnit(Unit{("nT"), true}) | |
264 | .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), |
|
264 | .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), | |
265 | dateTime(2013, 9, 23, 9, 2, 30)}) |
|
265 | dateTime(2013, 9, 23, 9, 2, 30)}) | |
266 | .setValuesData({std::numeric_limits<double>::quiet_NaN(), -2.71850, -2.52150}); |
|
266 | .setValuesData({std::numeric_limits<double>::quiet_NaN(), -2.71850, -2.52150}); | |
267 |
|
267 | |||
268 | // Valid files but with some invalid lines (wrong unit, wrong values, etc.) |
|
268 | // Valid files but with some invalid lines (wrong unit, wrong values, etc.) | |
269 | QTest::newRow("No unit file") |
|
269 | QTest::newRow("No unit file") | |
270 | << QStringLiteral("NoUnit.txt") |
|
270 | << QStringLiteral("NoUnit.txt") | |
271 | << ExpectedResults<ScalarSeries>{}.setParsingOK(true).setXAxisUnit(Unit{"", true}); |
|
271 | << ExpectedResults<ScalarSeries>{}.setParsingOK(true).setXAxisUnit(Unit{"", true}); | |
272 |
|
272 | |||
273 | QTest::newRow("Wrong unit file") |
|
273 | QTest::newRow("Wrong unit file") | |
274 | << QStringLiteral("WrongUnit.txt") |
|
274 | << QStringLiteral("WrongUnit.txt") | |
275 | << ExpectedResults<ScalarSeries>{} |
|
275 | << ExpectedResults<ScalarSeries>{} | |
276 | .setParsingOK(true) |
|
276 | .setParsingOK(true) | |
277 | .setXAxisUnit(Unit{"", true}) |
|
277 | .setXAxisUnit(Unit{"", true}) | |
278 | .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), |
|
278 | .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), | |
279 | dateTime(2013, 9, 23, 9, 2, 30)}) |
|
279 | dateTime(2013, 9, 23, 9, 2, 30)}) | |
280 | .setValuesData({-2.83950, -2.71850, -2.52150}); |
|
280 | .setValuesData({-2.83950, -2.71850, -2.52150}); | |
281 |
|
281 | |||
282 | QTest::newRow("Wrong results file (date of first line is invalid") |
|
282 | QTest::newRow("Wrong results file (date of first line is invalid") | |
283 | << QStringLiteral("WrongDate.txt") |
|
283 | << QStringLiteral("WrongDate.txt") | |
284 | << ExpectedResults<ScalarSeries>{} |
|
284 | << ExpectedResults<ScalarSeries>{} | |
285 | .setParsingOK(true) |
|
285 | .setParsingOK(true) | |
286 | .setXAxisUnit(Unit{"nT", true}) |
|
286 | .setXAxisUnit(Unit{"nT", true}) | |
287 | .setXAxisData({dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}) |
|
287 | .setXAxisData({dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}) | |
288 | .setValuesData({-2.71850, -2.52150}); |
|
288 | .setValuesData({-2.71850, -2.52150}); | |
289 |
|
289 | |||
290 | QTest::newRow("Wrong results file (too many values for first line") |
|
290 | QTest::newRow("Wrong results file (too many values for first line") | |
291 | << QStringLiteral("TooManyValues.txt") |
|
291 | << QStringLiteral("TooManyValues.txt") | |
292 | << ExpectedResults<ScalarSeries>{} |
|
292 | << ExpectedResults<ScalarSeries>{} | |
293 | .setParsingOK(true) |
|
293 | .setParsingOK(true) | |
294 | .setXAxisUnit(Unit{"nT", true}) |
|
294 | .setXAxisUnit(Unit{"nT", true}) | |
295 | .setXAxisData({dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}) |
|
295 | .setXAxisData({dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}) | |
296 | .setValuesData({-2.71850, -2.52150}); |
|
296 | .setValuesData({-2.71850, -2.52150}); | |
297 |
|
297 | |||
298 | QTest::newRow("Wrong results file (x of first line is NaN") |
|
298 | QTest::newRow("Wrong results file (x of first line is NaN") | |
299 | << QStringLiteral("NaNX.txt") |
|
299 | << QStringLiteral("NaNX.txt") | |
300 | << ExpectedResults<ScalarSeries>{} |
|
300 | << ExpectedResults<ScalarSeries>{} | |
301 | .setParsingOK(true) |
|
301 | .setParsingOK(true) | |
302 | .setXAxisUnit(Unit{"nT", true}) |
|
302 | .setXAxisUnit(Unit{"nT", true}) | |
303 | .setXAxisData({dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}) |
|
303 | .setXAxisData({dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}) | |
304 | .setValuesData({-2.71850, -2.52150}); |
|
304 | .setValuesData({-2.71850, -2.52150}); | |
305 |
|
305 | |||
306 | QTest::newRow("Invalid file type (vector)") |
|
306 | QTest::newRow("Invalid file type (vector)") | |
307 | << QStringLiteral("ValidVector1.txt") |
|
307 | << QStringLiteral("ValidVector1.txt") | |
308 | << ExpectedResults<ScalarSeries>{}.setParsingOK(true).setXAxisUnit(Unit{"nT", true}); |
|
308 | << ExpectedResults<ScalarSeries>{}.setParsingOK(true).setXAxisUnit(Unit{"nT", true}); | |
309 |
|
309 | |||
310 | // Invalid files |
|
310 | // Invalid files | |
311 | QTest::newRow("Invalid file (unexisting file)") |
|
311 | QTest::newRow("Invalid file (unexisting file)") | |
312 | << QStringLiteral("UnexistingFile.txt") |
|
312 | << QStringLiteral("UnexistingFile.txt") | |
313 | << ExpectedResults<ScalarSeries>{}.setParsingOK(false); |
|
313 | << ExpectedResults<ScalarSeries>{}.setParsingOK(false); | |
314 |
|
314 | |||
315 | QTest::newRow("Invalid file (file not found on server)") |
|
315 | QTest::newRow("Invalid file (file not found on server)") | |
316 | << QStringLiteral("FileNotFound.txt") |
|
316 | << QStringLiteral("FileNotFound.txt") | |
317 | << ExpectedResults<ScalarSeries>{}.setParsingOK(false); |
|
317 | << ExpectedResults<ScalarSeries>{}.setParsingOK(false); | |
318 | } |
|
318 | } | |
319 |
|
319 | |||
320 | void TestAmdaResultParser::testReadScalarTxt() |
|
320 | void TestAmdaResultParser::testReadScalarTxt() | |
321 | { |
|
321 | { | |
322 | testRead<ScalarSeries>(AmdaResultParser::ValueType::SCALAR); |
|
322 | testRead<ScalarSeries>(AmdaResultParser::ValueType::SCALAR); | |
323 | } |
|
323 | } | |
324 |
|
324 | |||
325 | void TestAmdaResultParser::testReadSpectrogramTxt_data() |
|
325 | void TestAmdaResultParser::testReadSpectrogramTxt_data() | |
326 | { |
|
326 | { | |
327 | testReadDataStructure<SpectrogramSeries>(); |
|
327 | testReadDataStructure<SpectrogramSeries>(); | |
328 |
|
328 | |||
329 | // ////////// // |
|
329 | // ////////// // | |
330 | // Test cases // |
|
330 | // Test cases // | |
331 | // ////////// // |
|
331 | // ////////// // | |
332 |
|
332 | |||
333 | // Valid files |
|
333 | // Valid files | |
334 | QTest::newRow("Valid file (three bands)") |
|
334 | QTest::newRow("Valid file (three bands)") | |
335 | << QStringLiteral("spectro/ValidSpectrogram1.txt") |
|
335 | << QStringLiteral("spectro/ValidSpectrogram1.txt") | |
336 | << ExpectedResults<SpectrogramSeries>{} |
|
336 | << ExpectedResults<SpectrogramSeries>{} | |
337 | .setParsingOK(true) |
|
337 | .setParsingOK(true) | |
338 | .setXAxisUnit(Unit{"t", true}) |
|
338 | .setXAxisUnit(Unit{"t", true}) | |
339 | .setXAxisData({dateTime(2012, 11, 6, 9, 14, 35), dateTime(2012, 11, 6, 9, 16, 10), |
|
339 | .setXAxisData({dateTime(2012, 11, 6, 9, 14, 35), dateTime(2012, 11, 6, 9, 16, 10), | |
340 | dateTime(2012, 11, 6, 9, 17, 45), dateTime(2012, 11, 6, 9, 19, 20), |
|
340 | dateTime(2012, 11, 6, 9, 17, 45), dateTime(2012, 11, 6, 9, 19, 20), | |
341 | dateTime(2012, 11, 6, 9, 20, 55)}) |
|
341 | dateTime(2012, 11, 6, 9, 20, 55)}) | |
342 | .setYAxisEnabled(true) |
|
342 | .setYAxisEnabled(true) | |
343 | .setYAxisUnit(Unit{"eV"}) |
|
343 | .setYAxisUnit(Unit{"eV"}) | |
344 | .setYAxisData({5.75, 7.6, 10.05}) // middle of the intervals of each band |
|
344 | .setYAxisData({5.75, 7.6, 10.05}) // middle of the intervals of each band | |
345 | .setValuesUnit(Unit{"eV/(cm^2-s-sr-eV)"}) |
|
345 | .setValuesUnit(Unit{"eV/(cm^2-s-sr-eV)"}) | |
346 | .setValuesData(QVector<QVector<double> >{ |
|
346 | .setValuesData(QVector<QVector<double> >{ | |
347 | {16313.780, 12631.465, 8223.368, 27595.301, 12820.613}, |
|
347 | {16313.780, 12631.465, 8223.368, 27595.301, 12820.613}, | |
348 | {15405.838, 11957.925, 15026.249, 25617.533, 11179.109}, |
|
348 | {15405.838, 11957.925, 15026.249, 25617.533, 11179.109}, | |
349 | {8946.475, 18133.158, 10875.621, 24051.619, 19283.221}}); |
|
349 | {8946.475, 18133.158, 10875.621, 24051.619, 19283.221}}); | |
350 |
|
350 | |||
351 | auto fourBandsResult |
|
351 | auto fourBandsResult | |
352 | = ExpectedResults<SpectrogramSeries>{} |
|
352 | = ExpectedResults<SpectrogramSeries>{} | |
353 | .setParsingOK(true) |
|
353 | .setParsingOK(true) | |
354 | .setXAxisUnit(Unit{"t", true}) |
|
354 | .setXAxisUnit(Unit{"t", true}) | |
355 | .setXAxisData({dateTime(2012, 11, 6, 9, 14, 35), dateTime(2012, 11, 6, 9, 16, 10), |
|
355 | .setXAxisData({dateTime(2012, 11, 6, 9, 14, 35), dateTime(2012, 11, 6, 9, 16, 10), | |
356 | dateTime(2012, 11, 6, 9, 17, 45), dateTime(2012, 11, 6, 9, 19, 20), |
|
356 | dateTime(2012, 11, 6, 9, 17, 45), dateTime(2012, 11, 6, 9, 19, 20), | |
357 | dateTime(2012, 11, 6, 9, 20, 55)}) |
|
357 | dateTime(2012, 11, 6, 9, 20, 55)}) | |
358 | .setYAxisEnabled(true) |
|
358 | .setYAxisEnabled(true) | |
359 | .setYAxisUnit(Unit{"eV"}) |
|
359 | .setYAxisUnit(Unit{"eV"}) | |
360 | .setYAxisData({5.75, 7.6, 10.05, 13.}) // middle of the intervals of each band |
|
360 | .setYAxisData({5.75, 7.6, 10.05, 13.}) // middle of the intervals of each band | |
361 | .setValuesUnit(Unit{"eV/(cm^2-s-sr-eV)"}) |
|
361 | .setValuesUnit(Unit{"eV/(cm^2-s-sr-eV)"}) | |
362 | .setValuesData(QVector<QVector<double> >{ |
|
362 | .setValuesData(QVector<QVector<double> >{ | |
363 | {16313.780, 12631.465, 8223.368, 27595.301, 12820.613}, |
|
363 | {16313.780, 12631.465, 8223.368, 27595.301, 12820.613}, | |
364 | {15405.838, 11957.925, 15026.249, 25617.533, 11179.109}, |
|
364 | {15405.838, 11957.925, 15026.249, 25617.533, 11179.109}, | |
365 | {8946.475, 18133.158, 10875.621, 24051.619, 19283.221}, |
|
365 | {8946.475, 18133.158, 10875.621, 24051.619, 19283.221}, | |
366 | {20907.664, 32076.725, 13008.381, 13142.759, 23226.998}}); |
|
366 | {20907.664, 32076.725, 13008.381, 13142.759, 23226.998}}); | |
367 |
|
367 | |||
368 | QTest::newRow("Valid file (four bands)") |
|
368 | QTest::newRow("Valid file (four bands)") << QStringLiteral("spectro/ValidSpectrogram2.txt") | |
369 | << QStringLiteral("spectro/ValidSpectrogram2.txt") << fourBandsResult; |
|
369 | << fourBandsResult; | |
370 | QTest::newRow("Valid file (four unsorted bands)") |
|
370 | QTest::newRow("Valid file (four unsorted bands)") | |
371 | << QStringLiteral("spectro/ValidSpectrogram3.txt") |
|
371 | << QStringLiteral("spectro/ValidSpectrogram3.txt") | |
372 | << fourBandsResult; // Bands and values are sorted |
|
372 | << fourBandsResult; // Bands and values are sorted | |
373 |
|
373 | |||
374 | auto nan = std::numeric_limits<double>::quiet_NaN(); |
|
374 | auto nan = std::numeric_limits<double>::quiet_NaN(); | |
375 |
|
375 | |||
376 | auto nanValuesResult |
|
376 | auto nanValuesResult | |
377 | = ExpectedResults<SpectrogramSeries>{} |
|
377 | = ExpectedResults<SpectrogramSeries>{} | |
378 | .setParsingOK(true) |
|
378 | .setParsingOK(true) | |
379 | .setXAxisUnit(Unit{"t", true}) |
|
379 | .setXAxisUnit(Unit{"t", true}) | |
380 | .setXAxisData({dateTime(2012, 11, 6, 9, 14, 35), dateTime(2012, 11, 6, 9, 16, 10), |
|
380 | .setXAxisData({dateTime(2012, 11, 6, 9, 14, 35), dateTime(2012, 11, 6, 9, 16, 10), | |
381 | dateTime(2012, 11, 6, 9, 17, 45), dateTime(2012, 11, 6, 9, 19, 20), |
|
381 | dateTime(2012, 11, 6, 9, 17, 45), dateTime(2012, 11, 6, 9, 19, 20), | |
382 | dateTime(2012, 11, 6, 9, 20, 55)}) |
|
382 | dateTime(2012, 11, 6, 9, 20, 55)}) | |
383 | .setYAxisEnabled(true) |
|
383 | .setYAxisEnabled(true) | |
384 | .setYAxisUnit(Unit{"eV"}) |
|
384 | .setYAxisUnit(Unit{"eV"}) | |
385 | .setYAxisData({5.75, 7.6, 10.05, 13.}) // middle of the intervals of each band |
|
385 | .setYAxisData({5.75, 7.6, 10.05, 13.}) // middle of the intervals of each band | |
386 | .setValuesUnit(Unit{"eV/(cm^2-s-sr-eV)"}) |
|
386 | .setValuesUnit(Unit{"eV/(cm^2-s-sr-eV)"}) | |
387 | .setValuesData( |
|
387 | .setValuesData( | |
388 | QVector<QVector<double> >{{nan, 12631.465, 8223.368, 27595.301, 12820.613}, |
|
388 | QVector<QVector<double> >{{nan, 12631.465, 8223.368, 27595.301, 12820.613}, | |
389 | {15405.838, nan, nan, 25617.533, 11179.109}, |
|
389 | {15405.838, nan, nan, 25617.533, 11179.109}, | |
390 | {8946.475, 18133.158, 10875.621, 24051.619, 19283.221}, |
|
390 | {8946.475, 18133.158, 10875.621, 24051.619, 19283.221}, | |
391 | {nan, nan, nan, nan, nan}}); |
|
391 | {nan, nan, nan, nan, nan}}); | |
392 |
|
392 | |||
393 | QTest::newRow("Valid file (containing NaN values)") |
|
393 | QTest::newRow("Valid file (containing NaN values)") | |
394 | << QStringLiteral("spectro/ValidSpectrogramNaNValues.txt") << nanValuesResult; |
|
394 | << QStringLiteral("spectro/ValidSpectrogramNaNValues.txt") << nanValuesResult; | |
395 | QTest::newRow("Valid file (containing fill values)") |
|
395 | QTest::newRow("Valid file (containing fill values)") | |
396 | << QStringLiteral("spectro/ValidSpectrogramFillValues.txt") |
|
396 | << QStringLiteral("spectro/ValidSpectrogramFillValues.txt") | |
397 | << nanValuesResult; // Fill values are replaced by NaN values in the data series |
|
397 | << nanValuesResult; // Fill values are replaced by NaN values in the data series | |
398 |
|
398 | |||
399 | QTest::newRow("Valid file (containing data holes, resolution = 3 minutes)") |
|
399 | QTest::newRow("Valid file (containing data holes, resolution = 3 minutes)") | |
400 | << QStringLiteral("spectro/ValidSpectrogramDataHoles.txt") |
|
400 | << QStringLiteral("spectro/ValidSpectrogramDataHoles.txt") | |
401 | << ExpectedResults<SpectrogramSeries>{} |
|
401 | << ExpectedResults<SpectrogramSeries>{} | |
402 | .setParsingOK(true) |
|
402 | .setParsingOK(true) | |
403 | .setXAxisUnit(Unit{"t", true}) |
|
403 | .setXAxisUnit(Unit{"t", true}) | |
404 | .setXAxisData({dateTime(2011, 12, 10, 12, 10, 54), // |
|
404 | .setXAxisData({dateTime(2011, 12, 10, 12, 10, 54), // | |
405 | dateTime(2011, 12, 10, 12, 13, 54), // Data hole |
|
405 | dateTime(2011, 12, 10, 12, 13, 54), // Data hole | |
406 | dateTime(2011, 12, 10, 12, 16, 54), // Data hole |
|
406 | dateTime(2011, 12, 10, 12, 16, 54), // Data hole | |
407 | dateTime(2011, 12, 10, 12, 17, 23), // |
|
407 | dateTime(2011, 12, 10, 12, 17, 23), // | |
408 | dateTime(2011, 12, 10, 12, 20, 23), // Data hole |
|
408 | dateTime(2011, 12, 10, 12, 20, 23), // Data hole | |
409 | dateTime(2011, 12, 10, 12, 23, 23), // Data hole |
|
409 | dateTime(2011, 12, 10, 12, 23, 23), // Data hole | |
410 | dateTime(2011, 12, 10, 12, 23, 51), // |
|
410 | dateTime(2011, 12, 10, 12, 23, 51), // | |
411 | dateTime(2011, 12, 10, 12, 26, 51), // Data hole |
|
411 | dateTime(2011, 12, 10, 12, 26, 51), // Data hole | |
412 | dateTime(2011, 12, 10, 12, 29, 51), // Data hole |
|
412 | dateTime(2011, 12, 10, 12, 29, 51), // Data hole | |
413 | dateTime(2011, 12, 10, 12, 30, 19), // |
|
413 | dateTime(2011, 12, 10, 12, 30, 19), // | |
414 | dateTime(2011, 12, 10, 12, 33, 19), // Data hole |
|
414 | dateTime(2011, 12, 10, 12, 33, 19), // Data hole | |
415 | dateTime(2011, 12, 10, 12, 35, 04), // |
|
415 | dateTime(2011, 12, 10, 12, 35, 04), // | |
416 | dateTime(2011, 12, 10, 12, 36, 41), // |
|
416 | dateTime(2011, 12, 10, 12, 36, 41), // | |
417 | dateTime(2011, 12, 10, 12, 38, 18), // |
|
417 | dateTime(2011, 12, 10, 12, 38, 18), // | |
418 | dateTime(2011, 12, 10, 12, 39, 55)}) |
|
418 | dateTime(2011, 12, 10, 12, 39, 55)}) | |
419 | .setYAxisEnabled(true) |
|
419 | .setYAxisEnabled(true) | |
420 | .setYAxisUnit(Unit{"eV"}) |
|
420 | .setYAxisUnit(Unit{"eV"}) | |
421 | .setYAxisData({16485.85, 20996.1}) // middle of the intervals of each band |
|
421 | .setYAxisData({16485.85, 20996.1}) // middle of the intervals of each band | |
422 | .setValuesUnit(Unit{"eV/(cm^2-s-sr-eV)"}) |
|
422 | .setValuesUnit(Unit{"eV/(cm^2-s-sr-eV)"}) | |
423 | .setValuesData(QVector<QVector<double> >{{2577578.000, // |
|
423 | .setValuesData(QVector<QVector<double> >{{2577578.000, // | |
424 | nan, // Data hole |
|
424 | nan, // Data hole | |
425 | nan, // Data hole |
|
425 | nan, // Data hole | |
426 | 2314121.500, // |
|
426 | 2314121.500, // | |
427 | nan, // Data hole |
|
427 | nan, // Data hole | |
428 | nan, // Data hole |
|
428 | nan, // Data hole | |
429 | 2063608.750, // |
|
429 | 2063608.750, // | |
430 | nan, // Data hole |
|
430 | nan, // Data hole | |
431 | nan, // Data hole |
|
431 | nan, // Data hole | |
432 | 2234525.500, // |
|
432 | 2234525.500, // | |
433 | nan, // Data hole |
|
433 | nan, // Data hole | |
434 | 1670215.250, // |
|
434 | 1670215.250, // | |
435 | 1689243.250, // |
|
435 | 1689243.250, // | |
436 | 1654617.125, // |
|
436 | 1654617.125, // | |
437 | 1504983.750}, |
|
437 | 1504983.750}, | |
438 | {2336016.000, // |
|
438 | {2336016.000, // | |
439 | nan, // Data hole |
|
439 | nan, // Data hole | |
440 | nan, // Data hole |
|
440 | nan, // Data hole | |
441 | 1712093.125, // |
|
441 | 1712093.125, // | |
442 | nan, // Data hole |
|
442 | nan, // Data hole | |
443 | nan, // Data hole |
|
443 | nan, // Data hole | |
444 | 1614491.625, // |
|
444 | 1614491.625, // | |
445 | nan, // Data hole |
|
445 | nan, // Data hole | |
446 | nan, // Data hole |
|
446 | nan, // Data hole | |
447 | 1764516.500, // |
|
447 | 1764516.500, // | |
448 | nan, // Data hole |
|
448 | nan, // Data hole | |
449 | 1688078.500, // |
|
449 | 1688078.500, // | |
450 | 1743183.500, // |
|
450 | 1743183.500, // | |
451 | 1733603.250, // |
|
451 | 1733603.250, // | |
452 | 1708356.500}}); |
|
452 | 1708356.500}}); | |
453 |
|
453 | |||
454 | QTest::newRow( |
|
454 | QTest::newRow( | |
455 | "Valid file (containing data holes at the beginning and the end, resolution = 4 minutes)") |
|
455 | "Valid file (containing data holes at the beginning and the end, resolution = 4 minutes)") | |
456 | << QStringLiteral("spectro/ValidSpectrogramDataHoles2.txt") |
|
456 | << QStringLiteral("spectro/ValidSpectrogramDataHoles2.txt") | |
457 | << ExpectedResults<SpectrogramSeries>{} |
|
457 | << ExpectedResults<SpectrogramSeries>{} | |
458 | .setParsingOK(true) |
|
458 | .setParsingOK(true) | |
459 | .setXAxisUnit(Unit{"t", true}) |
|
459 | .setXAxisUnit(Unit{"t", true}) | |
460 | .setXAxisData({ |
|
460 | .setXAxisData({ | |
461 | dateTime(2011, 12, 10, 12, 2, 54), // Data hole |
|
461 | dateTime(2011, 12, 10, 12, 2, 54), // Data hole | |
462 | dateTime(2011, 12, 10, 12, 6, 54), // Data hole |
|
462 | dateTime(2011, 12, 10, 12, 6, 54), // Data hole | |
463 | dateTime(2011, 12, 10, 12, 10, 54), // |
|
463 | dateTime(2011, 12, 10, 12, 10, 54), // | |
464 | dateTime(2011, 12, 10, 12, 14, 54), // Data hole |
|
464 | dateTime(2011, 12, 10, 12, 14, 54), // Data hole | |
465 | dateTime(2011, 12, 10, 12, 17, 23), // |
|
465 | dateTime(2011, 12, 10, 12, 17, 23), // | |
466 | dateTime(2011, 12, 10, 12, 21, 23), // Data hole |
|
466 | dateTime(2011, 12, 10, 12, 21, 23), // Data hole | |
467 | dateTime(2011, 12, 10, 12, 23, 51), // |
|
467 | dateTime(2011, 12, 10, 12, 23, 51), // | |
468 | dateTime(2011, 12, 10, 12, 27, 51), // Data hole |
|
468 | dateTime(2011, 12, 10, 12, 27, 51), // Data hole | |
469 | dateTime(2011, 12, 10, 12, 30, 19), // |
|
469 | dateTime(2011, 12, 10, 12, 30, 19), // | |
470 | dateTime(2011, 12, 10, 12, 34, 19), // Data hole |
|
470 | dateTime(2011, 12, 10, 12, 34, 19), // Data hole | |
471 | dateTime(2011, 12, 10, 12, 35, 04), // |
|
471 | dateTime(2011, 12, 10, 12, 35, 04), // | |
472 | dateTime(2011, 12, 10, 12, 36, 41), // |
|
472 | dateTime(2011, 12, 10, 12, 36, 41), // | |
473 | dateTime(2011, 12, 10, 12, 38, 18), // |
|
473 | dateTime(2011, 12, 10, 12, 38, 18), // | |
474 | dateTime(2011, 12, 10, 12, 39, 55), |
|
474 | dateTime(2011, 12, 10, 12, 39, 55), | |
475 | dateTime(2011, 12, 10, 12, 43, 55), // Data hole |
|
475 | dateTime(2011, 12, 10, 12, 43, 55), // Data hole | |
476 | dateTime(2011, 12, 10, 12, 47, 55), // Data hole |
|
476 | dateTime(2011, 12, 10, 12, 47, 55), // Data hole | |
477 | dateTime(2011, 12, 10, 12, 51, 55), // Data hole |
|
477 | dateTime(2011, 12, 10, 12, 51, 55), // Data hole | |
478 | dateTime(2011, 12, 10, 12, 55, 55), // Data hole |
|
478 | dateTime(2011, 12, 10, 12, 55, 55), // Data hole | |
479 | dateTime(2011, 12, 10, 12, 59, 55) // Data hole |
|
479 | dateTime(2011, 12, 10, 12, 59, 55) // Data hole | |
480 | }) |
|
480 | }) | |
481 | .setYAxisEnabled(true) |
|
481 | .setYAxisEnabled(true) | |
482 | .setYAxisUnit(Unit{"eV"}) |
|
482 | .setYAxisUnit(Unit{"eV"}) | |
483 | .setYAxisData({16485.85, 20996.1}) // middle of the intervals of each band |
|
483 | .setYAxisData({16485.85, 20996.1}) // middle of the intervals of each band | |
484 | .setValuesUnit(Unit{"eV/(cm^2-s-sr-eV)"}) |
|
484 | .setValuesUnit(Unit{"eV/(cm^2-s-sr-eV)"}) | |
485 | .setValuesData(QVector<QVector<double> >{{ |
|
485 | .setValuesData(QVector<QVector<double> >{{ | |
486 | nan, // Data hole |
|
486 | nan, // Data hole | |
487 | nan, // Data hole |
|
487 | nan, // Data hole | |
488 | 2577578.000, // |
|
488 | 2577578.000, // | |
489 | nan, // Data hole |
|
489 | nan, // Data hole | |
490 | 2314121.500, // |
|
490 | 2314121.500, // | |
491 | nan, // Data hole |
|
491 | nan, // Data hole | |
492 | 2063608.750, // |
|
492 | 2063608.750, // | |
493 | nan, // Data hole |
|
493 | nan, // Data hole | |
494 | 2234525.500, // |
|
494 | 2234525.500, // | |
495 | nan, // Data hole |
|
495 | nan, // Data hole | |
496 | 1670215.250, // |
|
496 | 1670215.250, // | |
497 | 1689243.250, // |
|
497 | 1689243.250, // | |
498 | 1654617.125, // |
|
498 | 1654617.125, // | |
499 | 1504983.750, // |
|
499 | 1504983.750, // | |
500 | nan, // Data hole |
|
500 | nan, // Data hole | |
501 | nan, // Data hole |
|
501 | nan, // Data hole | |
502 | nan, // Data hole |
|
502 | nan, // Data hole | |
503 | nan, // Data hole |
|
503 | nan, // Data hole | |
504 | nan // Data hole |
|
504 | nan // Data hole | |
505 | }, |
|
505 | }, | |
506 | { |
|
506 | { | |
507 | nan, // Data hole |
|
507 | nan, // Data hole | |
508 | nan, // Data hole |
|
508 | nan, // Data hole | |
509 | 2336016.000, // |
|
509 | 2336016.000, // | |
510 | nan, // Data hole |
|
510 | nan, // Data hole | |
511 | 1712093.125, // |
|
511 | 1712093.125, // | |
512 | nan, // Data hole |
|
512 | nan, // Data hole | |
513 | 1614491.625, // |
|
513 | 1614491.625, // | |
514 | nan, // Data hole |
|
514 | nan, // Data hole | |
515 | 1764516.500, // |
|
515 | 1764516.500, // | |
516 | nan, // Data hole |
|
516 | nan, // Data hole | |
517 | 1688078.500, // |
|
517 | 1688078.500, // | |
518 | 1743183.500, // |
|
518 | 1743183.500, // | |
519 | 1733603.250, // |
|
519 | 1733603.250, // | |
520 | 1708356.500, // |
|
520 | 1708356.500, // | |
521 | nan, // Data hole |
|
521 | nan, // Data hole | |
522 | nan, // Data hole |
|
522 | nan, // Data hole | |
523 | nan, // Data hole |
|
523 | nan, // Data hole | |
524 | nan, // Data hole |
|
524 | nan, // Data hole | |
525 | nan // Data hole |
|
525 | nan // Data hole | |
526 | }}); |
|
526 | }}); | |
527 |
|
527 | |||
528 | // Invalid files |
|
528 | // Invalid files | |
529 | QTest::newRow("Invalid file (inconsistent bands)") |
|
529 | QTest::newRow("Invalid file (inconsistent bands)") | |
530 | << QStringLiteral("spectro/InvalidSpectrogramWrongBands.txt") |
|
530 | << QStringLiteral("spectro/InvalidSpectrogramWrongBands.txt") | |
531 | << ExpectedResults<SpectrogramSeries>{}.setParsingOK(false); |
|
531 | << ExpectedResults<SpectrogramSeries>{}.setParsingOK(false); | |
532 | } |
|
532 | } | |
533 |
|
533 | |||
534 | void TestAmdaResultParser::testReadSpectrogramTxt() |
|
534 | void TestAmdaResultParser::testReadSpectrogramTxt() | |
535 | { |
|
535 | { | |
536 | testRead<SpectrogramSeries>(AmdaResultParser::ValueType::SPECTROGRAM); |
|
536 | testRead<SpectrogramSeries>(AmdaResultParser::ValueType::SPECTROGRAM); | |
537 | } |
|
537 | } | |
538 |
|
538 | |||
539 | void TestAmdaResultParser::testReadVectorTxt_data() |
|
539 | void TestAmdaResultParser::testReadVectorTxt_data() | |
540 | { |
|
540 | { | |
541 | testReadDataStructure<VectorSeries>(); |
|
541 | testReadDataStructure<VectorSeries>(); | |
542 |
|
542 | |||
543 | // ////////// // |
|
543 | // ////////// // | |
544 | // Test cases // |
|
544 | // Test cases // | |
545 | // ////////// // |
|
545 | // ////////// // | |
546 |
|
546 | |||
547 | // Valid files |
|
547 | // Valid files | |
548 | QTest::newRow("Valid file") |
|
548 | QTest::newRow("Valid file") | |
549 | << QStringLiteral("ValidVector1.txt") |
|
549 | << QStringLiteral("ValidVector1.txt") | |
550 | << ExpectedResults<VectorSeries>{} |
|
550 | << ExpectedResults<VectorSeries>{} | |
551 | .setParsingOK(true) |
|
551 | .setParsingOK(true) | |
552 | .setXAxisUnit(Unit{"nT", true}) |
|
552 | .setXAxisUnit(Unit{"nT", true}) | |
553 | .setXAxisData({dateTime(2013, 7, 2, 9, 13, 50), dateTime(2013, 7, 2, 9, 14, 6), |
|
553 | .setXAxisData({dateTime(2013, 7, 2, 9, 13, 50), dateTime(2013, 7, 2, 9, 14, 6), | |
554 | dateTime(2013, 7, 2, 9, 14, 22), dateTime(2013, 7, 2, 9, 14, 38), |
|
554 | dateTime(2013, 7, 2, 9, 14, 22), dateTime(2013, 7, 2, 9, 14, 38), | |
555 | dateTime(2013, 7, 2, 9, 14, 54), dateTime(2013, 7, 2, 9, 15, 10), |
|
555 | dateTime(2013, 7, 2, 9, 14, 54), dateTime(2013, 7, 2, 9, 15, 10), | |
556 | dateTime(2013, 7, 2, 9, 15, 26), dateTime(2013, 7, 2, 9, 15, 42), |
|
556 | dateTime(2013, 7, 2, 9, 15, 26), dateTime(2013, 7, 2, 9, 15, 42), | |
557 | dateTime(2013, 7, 2, 9, 15, 58), dateTime(2013, 7, 2, 9, 16, 14)}) |
|
557 | dateTime(2013, 7, 2, 9, 15, 58), dateTime(2013, 7, 2, 9, 16, 14)}) | |
558 | .setValuesData( |
|
558 | .setValuesData( | |
559 | {{-0.332, -1.011, -1.457, -1.293, -1.217, -1.443, -1.278, -1.202, -1.22, -1.259}, |
|
559 | {{-0.332, -1.011, -1.457, -1.293, -1.217, -1.443, -1.278, -1.202, -1.22, -1.259}, | |
560 | {3.206, 2.999, 2.785, 2.736, 2.612, 2.564, 2.892, 2.862, 2.859, 2.764}, |
|
560 | {3.206, 2.999, 2.785, 2.736, 2.612, 2.564, 2.892, 2.862, 2.859, 2.764}, | |
561 | {0.058, 0.496, 1.018, 1.485, 1.662, 1.505, 1.168, 1.244, 1.15, 1.358}}); |
|
561 | {0.058, 0.496, 1.018, 1.485, 1.662, 1.505, 1.168, 1.244, 1.15, 1.358}}); | |
562 |
|
562 | |||
563 | // Valid files but with some invalid lines (wrong unit, wrong values, etc.) |
|
563 | // Valid files but with some invalid lines (wrong unit, wrong values, etc.) | |
564 | QTest::newRow("Invalid file type (scalar)") |
|
564 | QTest::newRow("Invalid file type (scalar)") | |
565 | << QStringLiteral("ValidScalar1.txt") |
|
565 | << QStringLiteral("ValidScalar1.txt") | |
566 | << ExpectedResults<VectorSeries>{} |
|
566 | << ExpectedResults<VectorSeries>{} | |
567 | .setParsingOK(true) |
|
567 | .setParsingOK(true) | |
568 | .setXAxisUnit(Unit{"nT", true}) |
|
568 | .setXAxisUnit(Unit{"nT", true}) | |
569 | .setXAxisData({}) |
|
569 | .setXAxisData({}) | |
570 | .setValuesData(QVector<QVector<double> >{{}, {}, {}}); |
|
570 | .setValuesData(QVector<QVector<double> >{{}, {}, {}}); | |
571 | } |
|
571 | } | |
572 |
|
572 | |||
573 | void TestAmdaResultParser::testReadVectorTxt() |
|
573 | void TestAmdaResultParser::testReadVectorTxt() | |
574 | { |
|
574 | { | |
575 | testRead<VectorSeries>(AmdaResultParser::ValueType::VECTOR); |
|
575 | testRead<VectorSeries>(AmdaResultParser::ValueType::VECTOR); | |
576 | } |
|
576 | } | |
577 |
|
577 | |||
578 | QTEST_MAIN(TestAmdaResultParser) |
|
578 | QTEST_MAIN(TestAmdaResultParser) | |
579 | #include "TestAmdaResultParser.moc" |
|
579 | #include "TestAmdaResultParser.moc" |
General Comments 0
You need to be logged in to leave comments.
Login now