@@ -0,0 +1,19 | |||||
|
1 | #ifndef SCIQLOP_FILTERINGACTION_H | |||
|
2 | #define SCIQLOP_FILTERINGACTION_H | |||
|
3 | ||||
|
4 | #include <Common/spimpl.h> | |||
|
5 | #include <QWidgetAction> | |||
|
6 | ||||
|
7 | /// A LineEdit inside an action which is able to filter other actions | |||
|
8 | class FilteringAction : public QWidgetAction { | |||
|
9 | public: | |||
|
10 | FilteringAction(QWidget *parent); | |||
|
11 | ||||
|
12 | void addActionToFilter(QAction *action); | |||
|
13 | ||||
|
14 | private: | |||
|
15 | class FilteringActionPrivate; | |||
|
16 | spimpl::unique_impl_ptr<FilteringActionPrivate> impl; | |||
|
17 | }; | |||
|
18 | ||||
|
19 | #endif // SCIQLOP_FILTERINGACTION_H |
@@ -0,0 +1,27 | |||||
|
1 | #include "Actions/FilteringAction.h" | |||
|
2 | ||||
|
3 | #include <QLineEdit> | |||
|
4 | ||||
|
5 | struct FilteringAction::FilteringActionPrivate { | |||
|
6 | QLineEdit *m_FilterLineEdit; | |||
|
7 | QVector<QAction *> m_FilteredActions; | |||
|
8 | }; | |||
|
9 | ||||
|
10 | FilteringAction::FilteringAction(QWidget *parent) | |||
|
11 | : QWidgetAction(parent), impl{spimpl::make_unique_impl<FilteringActionPrivate>()} | |||
|
12 | { | |||
|
13 | impl->m_FilterLineEdit = new QLineEdit(parent); | |||
|
14 | setDefaultWidget(impl->m_FilterLineEdit); | |||
|
15 | ||||
|
16 | connect(impl->m_FilterLineEdit, &QLineEdit::textEdited, [this](auto text) { | |||
|
17 | for (auto action : impl->m_FilteredActions) { | |||
|
18 | auto match = action->text().contains(text, Qt::CaseInsensitive); | |||
|
19 | action->setVisible(match); | |||
|
20 | } | |||
|
21 | }); | |||
|
22 | } | |||
|
23 | ||||
|
24 | void FilteringAction::addActionToFilter(QAction *action) | |||
|
25 | { | |||
|
26 | impl->m_FilteredActions << action; | |||
|
27 | } |
@@ -1,29 +1,35 | |||||
1 | #ifndef SCIQLOP_ACTIONSGUICONTROLLER_H |
|
1 | #ifndef SCIQLOP_ACTIONSGUICONTROLLER_H | |
2 | #define SCIQLOP_ACTIONSGUICONTROLLER_H |
|
2 | #define SCIQLOP_ACTIONSGUICONTROLLER_H | |
3 |
|
3 | |||
4 | #include <Actions/SelectionZoneAction.h> |
|
4 | #include <Actions/SelectionZoneAction.h> | |
5 | #include <Common/spimpl.h> |
|
5 | #include <Common/spimpl.h> | |
6 |
|
6 | |||
7 | #include <memory> |
|
7 | #include <memory> | |
8 |
|
8 | |||
9 | class ActionsGuiController { |
|
9 | class ActionsGuiController { | |
10 | public: |
|
10 | public: | |
11 | ActionsGuiController(); |
|
11 | ActionsGuiController(); | |
12 |
|
12 | |||
13 | std::shared_ptr<SelectionZoneAction> |
|
13 | std::shared_ptr<SelectionZoneAction> | |
14 | addSectionZoneAction(const QString &name, SelectionZoneAction::ExecuteFunction function); |
|
14 | addSectionZoneAction(const QString &name, SelectionZoneAction::ExecuteFunction function); | |
15 |
|
15 | |||
16 | std::shared_ptr<SelectionZoneAction> |
|
16 | std::shared_ptr<SelectionZoneAction> | |
17 | addSectionZoneAction(const QStringList &subMenuList, const QString &name, |
|
17 | addSectionZoneAction(const QStringList &subMenuList, const QString &name, | |
18 | SelectionZoneAction::ExecuteFunction function); |
|
18 | SelectionZoneAction::ExecuteFunction function); | |
19 |
|
19 | |||
20 | QVector<std::shared_ptr<SelectionZoneAction> > selectionZoneActions() const; |
|
20 | QVector<std::shared_ptr<SelectionZoneAction> > selectionZoneActions() const; | |
21 |
|
21 | |||
22 | void removeAction(const std::shared_ptr<SelectionZoneAction> &action); |
|
22 | void removeAction(const std::shared_ptr<SelectionZoneAction> &action); | |
23 |
|
23 | |||
|
24 | /// Sets a flag to say that the specified menu can be filtered, usually via a FilteringAction | |||
|
25 | void addFilterForMenu(const QStringList &menuPath); | |||
|
26 | ||||
|
27 | /// Returns true if the menu can be filtered | |||
|
28 | bool isMenuFiltered(const QStringList &menuPath) const; | |||
|
29 | ||||
24 | private: |
|
30 | private: | |
25 | class ActionsGuiControllerPrivate; |
|
31 | class ActionsGuiControllerPrivate; | |
26 | spimpl::unique_impl_ptr<ActionsGuiControllerPrivate> impl; |
|
32 | spimpl::unique_impl_ptr<ActionsGuiControllerPrivate> impl; | |
27 | }; |
|
33 | }; | |
28 |
|
34 | |||
29 | #endif // SCIQLOP_ACTIONSGUICONTROLLER_H |
|
35 | #endif // SCIQLOP_ACTIONSGUICONTROLLER_H |
@@ -1,75 +1,82 | |||||
1 | #ifndef SCIQLOP_SELECTIONZONEACTION_H |
|
1 | #ifndef SCIQLOP_SELECTIONZONEACTION_H | |
2 | #define SCIQLOP_SELECTIONZONEACTION_H |
|
2 | #define SCIQLOP_SELECTIONZONEACTION_H | |
3 |
|
3 | |||
4 | #include <Common/spimpl.h> |
|
4 | #include <Common/spimpl.h> | |
5 |
|
5 | |||
6 | #include <QLoggingCategory> |
|
6 | #include <QLoggingCategory> | |
7 | #include <QObject> |
|
7 | #include <QObject> | |
8 |
|
8 | |||
9 | #include <functional> |
|
9 | #include <functional> | |
10 |
|
10 | |||
11 | class VisualizationSelectionZoneItem; |
|
11 | class VisualizationSelectionZoneItem; | |
12 |
|
12 | |||
13 | Q_DECLARE_LOGGING_CATEGORY(LOG_SelectionZoneAction) |
|
13 | Q_DECLARE_LOGGING_CATEGORY(LOG_SelectionZoneAction) | |
14 |
|
14 | |||
15 | /** |
|
15 | /** | |
16 | * @brief The SelectionZoneAction class represents an action on a selection zone in the |
|
16 | * @brief The SelectionZoneAction class represents an action on a selection zone in the | |
17 | * visualization. |
|
17 | * visualization. | |
18 | * |
|
18 | * | |
19 | * The action is a function that will be executed when the slot execute() is called. |
|
19 | * The action is a function that will be executed when the slot execute() is called. | |
20 | */ |
|
20 | */ | |
21 | class SelectionZoneAction : public QObject { |
|
21 | class SelectionZoneAction : public QObject { | |
22 |
|
22 | |||
23 | Q_OBJECT |
|
23 | Q_OBJECT | |
24 |
|
24 | |||
25 | public: |
|
25 | public: | |
26 | /// Signature of the function associated to the action |
|
26 | /// Signature of the function associated to the action | |
27 | using ExecuteFunction |
|
27 | using ExecuteFunction | |
28 | = std::function<void(const QVector<VisualizationSelectionZoneItem *> &item)>; |
|
28 | = std::function<void(const QVector<VisualizationSelectionZoneItem *> &item)>; | |
29 |
|
29 | |||
30 | using EnableFunction |
|
30 | using EnableFunction | |
31 | = std::function<bool(const QVector<VisualizationSelectionZoneItem *> &item)>; |
|
31 | = std::function<bool(const QVector<VisualizationSelectionZoneItem *> &item)>; | |
32 |
|
32 | |||
33 | /** |
|
33 | /** | |
34 | * @param name the name of the action, displayed to the user |
|
34 | * @param name the name of the action, displayed to the user | |
35 | * @param fun the function that will be called when the action is executed |
|
35 | * @param fun the function that will be called when the action is executed | |
36 | * @sa execute() |
|
36 | * @sa execute() | |
37 | */ |
|
37 | */ | |
38 | explicit SelectionZoneAction(const QString &name, ExecuteFunction fun); |
|
38 | explicit SelectionZoneAction(const QString &name, ExecuteFunction fun); | |
39 |
|
39 | |||
40 | /** |
|
40 | /** | |
41 | * @param name the name of the action, displayed to the user |
|
41 | * @param name the name of the action, displayed to the user | |
42 | * @param subMenusList the list of sub menus where the action should be inserted |
|
42 | * @param subMenusList the list of sub menus where the action should be inserted | |
43 | * @param fun the function that will be called when the action is executed |
|
43 | * @param fun the function that will be called when the action is executed | |
44 | * @sa execute() |
|
44 | * @sa execute() | |
45 | */ |
|
45 | */ | |
46 | explicit SelectionZoneAction(const QStringList &subMenuList, const QString &name, |
|
46 | explicit SelectionZoneAction(const QStringList &subMenuList, const QString &name, | |
47 | ExecuteFunction fun); |
|
47 | ExecuteFunction fun); | |
48 |
|
48 | |||
49 | /// Sets the function which determine if the action should be enabled or disabled |
|
49 | /// Sets the function which determine if the action should be enabled or disabled | |
50 | void setEnableFunction(EnableFunction fun); |
|
50 | void setEnableFunction(EnableFunction fun); | |
51 |
|
51 | |||
52 | /// Sets the shortcut displayed by the action. |
|
52 | /// Sets the shortcut displayed by the action. | |
53 | /// Note: The shortcut is only displayed and not active because it is not permanently stored |
|
53 | /// Note: The shortcut is only displayed and not active because it is not permanently stored | |
54 | void setDisplayedShortcut(const QKeySequence &shortcut); |
|
54 | void setDisplayedShortcut(const QKeySequence &shortcut); | |
55 | QKeySequence displayedShortcut() const; |
|
55 | QKeySequence displayedShortcut() const; | |
56 |
|
56 | |||
57 | /// The name of the action |
|
57 | /// The name of the action | |
58 | QString name() const noexcept; |
|
58 | QString name() const noexcept; | |
59 |
|
59 | |||
60 | /// The path in the sub menus, if any |
|
60 | /// The path in the sub menus, if any | |
61 | QStringList subMenuList() const noexcept; |
|
61 | QStringList subMenuList() const noexcept; | |
62 |
|
62 | |||
|
63 | /// Sets if filtering the action is allowed via a FilteringAction | |||
|
64 | void setAllowedFiltering(bool value); | |||
|
65 | ||||
|
66 | /// Returns true if filtering the action is allowed via a FilteringAction. By default it is | |||
|
67 | /// allowed. | |||
|
68 | bool isFilteringAllowed() const; | |||
|
69 | ||||
63 | public slots: |
|
70 | public slots: | |
64 | /// Executes the action |
|
71 | /// Executes the action | |
65 | void execute(const QVector<VisualizationSelectionZoneItem *> &item); |
|
72 | void execute(const QVector<VisualizationSelectionZoneItem *> &item); | |
66 |
|
73 | |||
67 | /// Returns true if the action is enabled |
|
74 | /// Returns true if the action is enabled | |
68 | bool isEnabled(const QVector<VisualizationSelectionZoneItem *> &item); |
|
75 | bool isEnabled(const QVector<VisualizationSelectionZoneItem *> &item); | |
69 |
|
76 | |||
70 | private: |
|
77 | private: | |
71 | class SelectionZoneActionPrivate; |
|
78 | class SelectionZoneActionPrivate; | |
72 | spimpl::unique_impl_ptr<SelectionZoneActionPrivate> impl; |
|
79 | spimpl::unique_impl_ptr<SelectionZoneActionPrivate> impl; | |
73 | }; |
|
80 | }; | |
74 |
|
81 | |||
75 | #endif // SCIQLOP_SELECTIONZONEACTION_H |
|
82 | #endif // SCIQLOP_SELECTIONZONEACTION_H |
@@ -1,145 +1,147 | |||||
1 | qxorm_dep = dependency('QxOrm', required : true, fallback:['QxOrm','qxorm_dep']) |
|
1 | qxorm_dep = dependency('QxOrm', required : true, fallback:['QxOrm','qxorm_dep']) | |
2 | catalogueapi_dep = dependency('CatalogueAPI', required : true, fallback:['CatalogueAPI','CatalogueAPI_dep']) |
|
2 | catalogueapi_dep = dependency('CatalogueAPI', required : true, fallback:['CatalogueAPI','CatalogueAPI_dep']) | |
3 |
|
3 | |||
4 | gui_moc_headers = [ |
|
4 | gui_moc_headers = [ | |
5 | 'include/DataSource/DataSourceWidget.h', |
|
5 | 'include/DataSource/DataSourceWidget.h', | |
6 | 'include/Settings/SqpSettingsDialog.h', |
|
6 | 'include/Settings/SqpSettingsDialog.h', | |
7 | 'include/Settings/SqpSettingsGeneralWidget.h', |
|
7 | 'include/Settings/SqpSettingsGeneralWidget.h', | |
8 | 'include/SidePane/SqpSidePane.h', |
|
8 | 'include/SidePane/SqpSidePane.h', | |
9 | 'include/SqpApplication.h', |
|
9 | 'include/SqpApplication.h', | |
10 | 'include/DragAndDrop/DragDropScroller.h', |
|
10 | 'include/DragAndDrop/DragDropScroller.h', | |
11 | 'include/DragAndDrop/DragDropTabSwitcher.h', |
|
11 | 'include/DragAndDrop/DragDropTabSwitcher.h', | |
12 | 'include/TimeWidget/TimeWidget.h', |
|
12 | 'include/TimeWidget/TimeWidget.h', | |
13 | 'include/Variable/VariableInspectorWidget.h', |
|
13 | 'include/Variable/VariableInspectorWidget.h', | |
14 | 'include/Variable/RenameVariableDialog.h', |
|
14 | 'include/Variable/RenameVariableDialog.h', | |
15 | 'include/Visualization/qcustomplot.h', |
|
15 | 'include/Visualization/qcustomplot.h', | |
16 | 'include/Visualization/VisualizationGraphWidget.h', |
|
16 | 'include/Visualization/VisualizationGraphWidget.h', | |
17 | 'include/Visualization/VisualizationTabWidget.h', |
|
17 | 'include/Visualization/VisualizationTabWidget.h', | |
18 | 'include/Visualization/VisualizationWidget.h', |
|
18 | 'include/Visualization/VisualizationWidget.h', | |
19 | 'include/Visualization/VisualizationZoneWidget.h', |
|
19 | 'include/Visualization/VisualizationZoneWidget.h', | |
20 | 'include/Visualization/VisualizationDragDropContainer.h', |
|
20 | 'include/Visualization/VisualizationDragDropContainer.h', | |
21 | 'include/Visualization/VisualizationDragWidget.h', |
|
21 | 'include/Visualization/VisualizationDragWidget.h', | |
22 | 'include/Visualization/ColorScaleEditor.h', |
|
22 | 'include/Visualization/ColorScaleEditor.h', | |
23 | 'include/Visualization/VisualizationSelectionZoneItem.h', |
|
23 | 'include/Visualization/VisualizationSelectionZoneItem.h', | |
24 | 'include/Actions/SelectionZoneAction.h', |
|
24 | 'include/Actions/SelectionZoneAction.h', | |
25 | 'include/Visualization/VisualizationMultiZoneSelectionDialog.h', |
|
25 | 'include/Visualization/VisualizationMultiZoneSelectionDialog.h', | |
26 | 'include/Catalogue/CatalogueExplorer.h', |
|
26 | 'include/Catalogue/CatalogueExplorer.h', | |
27 | 'include/Catalogue/CatalogueEventsWidget.h', |
|
27 | 'include/Catalogue/CatalogueEventsWidget.h', | |
28 | 'include/Catalogue/CatalogueSideBarWidget.h', |
|
28 | 'include/Catalogue/CatalogueSideBarWidget.h', | |
29 | 'include/Catalogue/CatalogueInspectorWidget.h', |
|
29 | 'include/Catalogue/CatalogueInspectorWidget.h', | |
30 | 'include/Catalogue/CatalogueEventsModel.h', |
|
30 | 'include/Catalogue/CatalogueEventsModel.h', | |
31 | 'include/Catalogue/CatalogueTreeModel.h' |
|
31 | 'include/Catalogue/CatalogueTreeModel.h', | |
|
32 | 'include/Actions/FilteringAction.h' | |||
32 | ] |
|
33 | ] | |
33 |
|
34 | |||
34 | gui_ui_files = [ |
|
35 | gui_ui_files = [ | |
35 | 'ui/DataSource/DataSourceWidget.ui', |
|
36 | 'ui/DataSource/DataSourceWidget.ui', | |
36 | 'ui/Settings/SqpSettingsDialog.ui', |
|
37 | 'ui/Settings/SqpSettingsDialog.ui', | |
37 | 'ui/Settings/SqpSettingsGeneralWidget.ui', |
|
38 | 'ui/Settings/SqpSettingsGeneralWidget.ui', | |
38 | 'ui/SidePane/SqpSidePane.ui', |
|
39 | 'ui/SidePane/SqpSidePane.ui', | |
39 | 'ui/TimeWidget/TimeWidget.ui', |
|
40 | 'ui/TimeWidget/TimeWidget.ui', | |
40 | 'ui/Variable/VariableInspectorWidget.ui', |
|
41 | 'ui/Variable/VariableInspectorWidget.ui', | |
41 | 'ui/Variable/RenameVariableDialog.ui', |
|
42 | 'ui/Variable/RenameVariableDialog.ui', | |
42 | 'ui/Variable/VariableMenuHeaderWidget.ui', |
|
43 | 'ui/Variable/VariableMenuHeaderWidget.ui', | |
43 | 'ui/Visualization/VisualizationGraphWidget.ui', |
|
44 | 'ui/Visualization/VisualizationGraphWidget.ui', | |
44 | 'ui/Visualization/VisualizationTabWidget.ui', |
|
45 | 'ui/Visualization/VisualizationTabWidget.ui', | |
45 | 'ui/Visualization/VisualizationWidget.ui', |
|
46 | 'ui/Visualization/VisualizationWidget.ui', | |
46 | 'ui/Visualization/VisualizationZoneWidget.ui', |
|
47 | 'ui/Visualization/VisualizationZoneWidget.ui', | |
47 | 'ui/Visualization/ColorScaleEditor.ui', |
|
48 | 'ui/Visualization/ColorScaleEditor.ui', | |
48 | 'ui/Visualization/VisualizationMultiZoneSelectionDialog.ui', |
|
49 | 'ui/Visualization/VisualizationMultiZoneSelectionDialog.ui', | |
49 | 'ui/Catalogue/CatalogueExplorer.ui', |
|
50 | 'ui/Catalogue/CatalogueExplorer.ui', | |
50 | 'ui/Catalogue/CatalogueEventsWidget.ui', |
|
51 | 'ui/Catalogue/CatalogueEventsWidget.ui', | |
51 | 'ui/Catalogue/CatalogueSideBarWidget.ui', |
|
52 | 'ui/Catalogue/CatalogueSideBarWidget.ui', | |
52 | 'ui/Catalogue/CatalogueInspectorWidget.ui' |
|
53 | 'ui/Catalogue/CatalogueInspectorWidget.ui' | |
53 | ] |
|
54 | ] | |
54 |
|
55 | |||
55 | gui_qresources = ['resources/sqpguiresources.qrc'] |
|
56 | gui_qresources = ['resources/sqpguiresources.qrc'] | |
56 |
|
57 | |||
57 | rcc_gen = generator(rcc, |
|
58 | rcc_gen = generator(rcc, | |
58 | output : 'qrc_@BASENAME@.cpp', |
|
59 | output : 'qrc_@BASENAME@.cpp', | |
59 | arguments : [ |
|
60 | arguments : [ | |
60 | '--output', |
|
61 | '--output', | |
61 | '@OUTPUT@', |
|
62 | '@OUTPUT@', | |
62 | '@INPUT@', |
|
63 | '@INPUT@', | |
63 | '@EXTRA_ARGS@']) |
|
64 | '@EXTRA_ARGS@']) | |
64 |
|
65 | |||
65 | rcc_files = rcc_gen.process(gui_qresources, extra_args : ['-name', 'sqpguiresources']) |
|
66 | rcc_files = rcc_gen.process(gui_qresources, extra_args : ['-name', 'sqpguiresources']) | |
66 |
|
67 | |||
67 | gui_moc_files = qt5.preprocess(moc_headers : gui_moc_headers, |
|
68 | gui_moc_files = qt5.preprocess(moc_headers : gui_moc_headers, | |
68 | ui_files : gui_ui_files) |
|
69 | ui_files : gui_ui_files) | |
69 |
|
70 | |||
70 | gui_sources = [ |
|
71 | gui_sources = [ | |
71 | 'src/SqpApplication.cpp', |
|
72 | 'src/SqpApplication.cpp', | |
72 | 'src/DragAndDrop/DragDropGuiController.cpp', |
|
73 | 'src/DragAndDrop/DragDropGuiController.cpp', | |
73 | 'src/DragAndDrop/DragDropScroller.cpp', |
|
74 | 'src/DragAndDrop/DragDropScroller.cpp', | |
74 | 'src/DragAndDrop/DragDropTabSwitcher.cpp', |
|
75 | 'src/DragAndDrop/DragDropTabSwitcher.cpp', | |
75 | 'src/Common/ColorUtils.cpp', |
|
76 | 'src/Common/ColorUtils.cpp', | |
76 | 'src/Common/VisualizationDef.cpp', |
|
77 | 'src/Common/VisualizationDef.cpp', | |
77 | 'src/DataSource/DataSourceTreeWidgetItem.cpp', |
|
78 | 'src/DataSource/DataSourceTreeWidgetItem.cpp', | |
78 | 'src/DataSource/DataSourceTreeWidgetHelper.cpp', |
|
79 | 'src/DataSource/DataSourceTreeWidgetHelper.cpp', | |
79 | 'src/DataSource/DataSourceWidget.cpp', |
|
80 | 'src/DataSource/DataSourceWidget.cpp', | |
80 | 'src/DataSource/DataSourceTreeWidget.cpp', |
|
81 | 'src/DataSource/DataSourceTreeWidget.cpp', | |
81 | 'src/Settings/SqpSettingsDialog.cpp', |
|
82 | 'src/Settings/SqpSettingsDialog.cpp', | |
82 | 'src/Settings/SqpSettingsGeneralWidget.cpp', |
|
83 | 'src/Settings/SqpSettingsGeneralWidget.cpp', | |
83 | 'src/SidePane/SqpSidePane.cpp', |
|
84 | 'src/SidePane/SqpSidePane.cpp', | |
84 | 'src/TimeWidget/TimeWidget.cpp', |
|
85 | 'src/TimeWidget/TimeWidget.cpp', | |
85 | 'src/Variable/VariableInspectorWidget.cpp', |
|
86 | 'src/Variable/VariableInspectorWidget.cpp', | |
86 | 'src/Variable/VariableInspectorTableView.cpp', |
|
87 | 'src/Variable/VariableInspectorTableView.cpp', | |
87 | 'src/Variable/VariableMenuHeaderWidget.cpp', |
|
88 | 'src/Variable/VariableMenuHeaderWidget.cpp', | |
88 | 'src/Variable/RenameVariableDialog.cpp', |
|
89 | 'src/Variable/RenameVariableDialog.cpp', | |
89 | 'src/Visualization/VisualizationGraphHelper.cpp', |
|
90 | 'src/Visualization/VisualizationGraphHelper.cpp', | |
90 | 'src/Visualization/VisualizationGraphRenderingDelegate.cpp', |
|
91 | 'src/Visualization/VisualizationGraphRenderingDelegate.cpp', | |
91 | 'src/Visualization/VisualizationGraphWidget.cpp', |
|
92 | 'src/Visualization/VisualizationGraphWidget.cpp', | |
92 | 'src/Visualization/VisualizationTabWidget.cpp', |
|
93 | 'src/Visualization/VisualizationTabWidget.cpp', | |
93 | 'src/Visualization/VisualizationWidget.cpp', |
|
94 | 'src/Visualization/VisualizationWidget.cpp', | |
94 | 'src/Visualization/VisualizationZoneWidget.cpp', |
|
95 | 'src/Visualization/VisualizationZoneWidget.cpp', | |
95 | 'src/Visualization/qcustomplot.cpp', |
|
96 | 'src/Visualization/qcustomplot.cpp', | |
96 | 'src/Visualization/QCustomPlotSynchronizer.cpp', |
|
97 | 'src/Visualization/QCustomPlotSynchronizer.cpp', | |
97 | 'src/Visualization/operations/FindVariableOperation.cpp', |
|
98 | 'src/Visualization/operations/FindVariableOperation.cpp', | |
98 | 'src/Visualization/operations/GenerateVariableMenuOperation.cpp', |
|
99 | 'src/Visualization/operations/GenerateVariableMenuOperation.cpp', | |
99 | 'src/Visualization/operations/MenuBuilder.cpp', |
|
100 | 'src/Visualization/operations/MenuBuilder.cpp', | |
100 | 'src/Visualization/operations/RemoveVariableOperation.cpp', |
|
101 | 'src/Visualization/operations/RemoveVariableOperation.cpp', | |
101 | 'src/Visualization/operations/RescaleAxeOperation.cpp', |
|
102 | 'src/Visualization/operations/RescaleAxeOperation.cpp', | |
102 | 'src/Visualization/VisualizationDragDropContainer.cpp', |
|
103 | 'src/Visualization/VisualizationDragDropContainer.cpp', | |
103 | 'src/Visualization/VisualizationDragWidget.cpp', |
|
104 | 'src/Visualization/VisualizationDragWidget.cpp', | |
104 | 'src/Visualization/AxisRenderingUtils.cpp', |
|
105 | 'src/Visualization/AxisRenderingUtils.cpp', | |
105 | 'src/Visualization/PlottablesRenderingUtils.cpp', |
|
106 | 'src/Visualization/PlottablesRenderingUtils.cpp', | |
106 | 'src/Visualization/MacScrollBarStyle.cpp', |
|
107 | 'src/Visualization/MacScrollBarStyle.cpp', | |
107 | 'src/Visualization/VisualizationCursorItem.cpp', |
|
108 | 'src/Visualization/VisualizationCursorItem.cpp', | |
108 | 'src/Visualization/ColorScaleEditor.cpp', |
|
109 | 'src/Visualization/ColorScaleEditor.cpp', | |
109 | 'src/Visualization/SqpColorScale.cpp', |
|
110 | 'src/Visualization/SqpColorScale.cpp', | |
110 | 'src/Visualization/QCPColorMapIterator.cpp', |
|
111 | 'src/Visualization/QCPColorMapIterator.cpp', | |
111 | 'src/Visualization/VisualizationSelectionZoneItem.cpp', |
|
112 | 'src/Visualization/VisualizationSelectionZoneItem.cpp', | |
112 | 'src/Visualization/VisualizationSelectionZoneManager.cpp', |
|
113 | 'src/Visualization/VisualizationSelectionZoneManager.cpp', | |
113 | 'src/Actions/SelectionZoneAction.cpp', |
|
114 | 'src/Actions/SelectionZoneAction.cpp', | |
114 | 'src/Actions/ActionsGuiController.cpp', |
|
115 | 'src/Actions/ActionsGuiController.cpp', | |
|
116 | 'src/Actions/FilteringAction.cpp', | |||
115 | 'src/Visualization/VisualizationActionManager.cpp', |
|
117 | 'src/Visualization/VisualizationActionManager.cpp', | |
116 | 'src/Visualization/VisualizationMultiZoneSelectionDialog.cpp', |
|
118 | 'src/Visualization/VisualizationMultiZoneSelectionDialog.cpp', | |
117 | 'src/Catalogue/CatalogueExplorer.cpp', |
|
119 | 'src/Catalogue/CatalogueExplorer.cpp', | |
118 | 'src/Catalogue/CatalogueEventsWidget.cpp', |
|
120 | 'src/Catalogue/CatalogueEventsWidget.cpp', | |
119 | 'src/Catalogue/CatalogueSideBarWidget.cpp', |
|
121 | 'src/Catalogue/CatalogueSideBarWidget.cpp', | |
120 | 'src/Catalogue/CatalogueInspectorWidget.cpp', |
|
122 | 'src/Catalogue/CatalogueInspectorWidget.cpp', | |
121 | 'src/Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.cpp', |
|
123 | 'src/Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.cpp', | |
122 | 'src/Catalogue/CatalogueTreeItems/CatalogueTreeItem.cpp', |
|
124 | 'src/Catalogue/CatalogueTreeItems/CatalogueTreeItem.cpp', | |
123 | 'src/Catalogue/CatalogueTreeItems/CatalogueTextTreeItem.cpp', |
|
125 | 'src/Catalogue/CatalogueTreeItems/CatalogueTextTreeItem.cpp', | |
124 | 'src/Catalogue/CatalogueEventsModel.cpp', |
|
126 | 'src/Catalogue/CatalogueEventsModel.cpp', | |
125 | 'src/Catalogue/CatalogueExplorerHelper.cpp', |
|
127 | 'src/Catalogue/CatalogueExplorerHelper.cpp', | |
126 | 'src/Catalogue/CatalogueActionManager.cpp', |
|
128 | 'src/Catalogue/CatalogueActionManager.cpp', | |
127 | 'src/Catalogue/CatalogueTreeModel.cpp' |
|
129 | 'src/Catalogue/CatalogueTreeModel.cpp' | |
128 | ] |
|
130 | ] | |
129 |
|
131 | |||
130 | gui_inc = include_directories(['include']) |
|
132 | gui_inc = include_directories(['include']) | |
131 |
|
133 | |||
132 | sciqlop_gui_lib = library('sciqlopgui', |
|
134 | sciqlop_gui_lib = library('sciqlopgui', | |
133 | gui_sources, |
|
135 | gui_sources, | |
134 | gui_moc_files, |
|
136 | gui_moc_files, | |
135 | rcc_files, |
|
137 | rcc_files, | |
136 | include_directories : [gui_inc], |
|
138 | include_directories : [gui_inc], | |
137 | dependencies : [ qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core, catalogueapi_dep], |
|
139 | dependencies : [ qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core, catalogueapi_dep], | |
138 | install : true |
|
140 | install : true | |
139 | ) |
|
141 | ) | |
140 |
|
142 | |||
141 | sciqlop_gui = declare_dependency(link_with : sciqlop_gui_lib, |
|
143 | sciqlop_gui = declare_dependency(link_with : sciqlop_gui_lib, | |
142 | include_directories : gui_inc, |
|
144 | include_directories : gui_inc, | |
143 | dependencies : [qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core, catalogueapi_dep]) |
|
145 | dependencies : [qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core, catalogueapi_dep]) | |
144 |
|
146 | |||
145 |
|
147 |
@@ -1,41 +1,52 | |||||
1 | #include "Actions/ActionsGuiController.h" |
|
1 | #include "Actions/ActionsGuiController.h" | |
2 |
|
2 | |||
3 | struct ActionsGuiController::ActionsGuiControllerPrivate { |
|
3 | struct ActionsGuiController::ActionsGuiControllerPrivate { | |
4 |
|
4 | |||
5 | QVector<std::shared_ptr<SelectionZoneAction> > m_SelectionZoneActions; |
|
5 | QVector<std::shared_ptr<SelectionZoneAction> > m_SelectionZoneActions; | |
|
6 | QSet<QStringList> m_FilteredMenu; | |||
6 | }; |
|
7 | }; | |
7 |
|
8 | |||
8 | ActionsGuiController::ActionsGuiController() |
|
9 | ActionsGuiController::ActionsGuiController() | |
9 | : impl{spimpl::make_unique_impl<ActionsGuiControllerPrivate>()} |
|
10 | : impl{spimpl::make_unique_impl<ActionsGuiControllerPrivate>()} | |
10 | { |
|
11 | { | |
11 | } |
|
12 | } | |
12 |
|
13 | |||
13 | std::shared_ptr<SelectionZoneAction> |
|
14 | std::shared_ptr<SelectionZoneAction> | |
14 | ActionsGuiController::addSectionZoneAction(const QString &name, |
|
15 | ActionsGuiController::addSectionZoneAction(const QString &name, | |
15 | SelectionZoneAction::ExecuteFunction function) |
|
16 | SelectionZoneAction::ExecuteFunction function) | |
16 | { |
|
17 | { | |
17 | auto action = std::make_shared<SelectionZoneAction>(name, function); |
|
18 | auto action = std::make_shared<SelectionZoneAction>(name, function); | |
18 | impl->m_SelectionZoneActions.push_back(action); |
|
19 | impl->m_SelectionZoneActions.push_back(action); | |
19 |
|
20 | |||
20 | return action; |
|
21 | return action; | |
21 | } |
|
22 | } | |
22 |
|
23 | |||
23 | std::shared_ptr<SelectionZoneAction> |
|
24 | std::shared_ptr<SelectionZoneAction> | |
24 | ActionsGuiController::addSectionZoneAction(const QStringList &subMenuList, const QString &name, |
|
25 | ActionsGuiController::addSectionZoneAction(const QStringList &subMenuList, const QString &name, | |
25 | SelectionZoneAction::ExecuteFunction function) |
|
26 | SelectionZoneAction::ExecuteFunction function) | |
26 | { |
|
27 | { | |
27 | auto action = std::make_shared<SelectionZoneAction>(subMenuList, name, function); |
|
28 | auto action = std::make_shared<SelectionZoneAction>(subMenuList, name, function); | |
28 | impl->m_SelectionZoneActions.push_back(action); |
|
29 | impl->m_SelectionZoneActions.push_back(action); | |
29 |
|
30 | |||
30 | return action; |
|
31 | return action; | |
31 | } |
|
32 | } | |
32 |
|
33 | |||
33 | QVector<std::shared_ptr<SelectionZoneAction> > ActionsGuiController::selectionZoneActions() const |
|
34 | QVector<std::shared_ptr<SelectionZoneAction> > ActionsGuiController::selectionZoneActions() const | |
34 | { |
|
35 | { | |
35 | return impl->m_SelectionZoneActions; |
|
36 | return impl->m_SelectionZoneActions; | |
36 | } |
|
37 | } | |
37 |
|
38 | |||
38 | void ActionsGuiController::removeAction(const std::shared_ptr<SelectionZoneAction> &action) |
|
39 | void ActionsGuiController::removeAction(const std::shared_ptr<SelectionZoneAction> &action) | |
39 | { |
|
40 | { | |
40 | impl->m_SelectionZoneActions.removeAll(action); |
|
41 | impl->m_SelectionZoneActions.removeAll(action); | |
41 | } |
|
42 | } | |
|
43 | ||||
|
44 | void ActionsGuiController::addFilterForMenu(const QStringList &menuPath) | |||
|
45 | { | |||
|
46 | impl->m_FilteredMenu.insert(menuPath); | |||
|
47 | } | |||
|
48 | ||||
|
49 | bool ActionsGuiController::isMenuFiltered(const QStringList &menuPath) const | |||
|
50 | { | |||
|
51 | return impl->m_FilteredMenu.contains(menuPath); | |||
|
52 | } |
@@ -1,66 +1,77 | |||||
1 | #include <Actions/SelectionZoneAction.h> |
|
1 | #include <Actions/SelectionZoneAction.h> | |
2 | #include <Visualization/VisualizationSelectionZoneItem.h> |
|
2 | #include <Visualization/VisualizationSelectionZoneItem.h> | |
3 |
|
3 | |||
4 | Q_LOGGING_CATEGORY(LOG_SelectionZoneAction, "SelectionZoneAction") |
|
4 | Q_LOGGING_CATEGORY(LOG_SelectionZoneAction, "SelectionZoneAction") | |
5 |
|
5 | |||
6 | struct SelectionZoneAction::SelectionZoneActionPrivate { |
|
6 | struct SelectionZoneAction::SelectionZoneActionPrivate { | |
7 | explicit SelectionZoneActionPrivate(const QString &name, const QStringList &subMenuList, |
|
7 | explicit SelectionZoneActionPrivate(const QString &name, const QStringList &subMenuList, | |
8 | SelectionZoneAction::ExecuteFunction fun) |
|
8 | SelectionZoneAction::ExecuteFunction fun) | |
9 | : m_Name{name}, m_SubMenuList{subMenuList}, m_Fun{std::move(fun)} |
|
9 | : m_Name{name}, m_SubMenuList{subMenuList}, m_Fun{std::move(fun)} | |
10 | { |
|
10 | { | |
11 | } |
|
11 | } | |
12 |
|
12 | |||
13 | QString m_Name; |
|
13 | QString m_Name; | |
14 | QStringList m_SubMenuList; |
|
14 | QStringList m_SubMenuList; | |
15 | QKeySequence m_DisplayedShortcut; |
|
15 | QKeySequence m_DisplayedShortcut; | |
16 | SelectionZoneAction::ExecuteFunction m_Fun; |
|
16 | SelectionZoneAction::ExecuteFunction m_Fun; | |
17 | SelectionZoneAction::EnableFunction m_EnableFun = [](auto zones) { return true; }; |
|
17 | SelectionZoneAction::EnableFunction m_EnableFun = [](auto zones) { return true; }; | |
|
18 | bool m_FilteringAllowed = true; | |||
18 | }; |
|
19 | }; | |
19 |
|
20 | |||
20 | SelectionZoneAction::SelectionZoneAction(const QString &name, ExecuteFunction fun) |
|
21 | SelectionZoneAction::SelectionZoneAction(const QString &name, ExecuteFunction fun) | |
21 | : impl{spimpl::make_unique_impl<SelectionZoneActionPrivate>(name, QStringList{}, |
|
22 | : impl{spimpl::make_unique_impl<SelectionZoneActionPrivate>(name, QStringList{}, | |
22 | std::move(fun))} |
|
23 | std::move(fun))} | |
23 | { |
|
24 | { | |
24 | } |
|
25 | } | |
25 |
|
26 | |||
26 | SelectionZoneAction::SelectionZoneAction(const QStringList &subMenuList, const QString &name, |
|
27 | SelectionZoneAction::SelectionZoneAction(const QStringList &subMenuList, const QString &name, | |
27 | SelectionZoneAction::ExecuteFunction fun) |
|
28 | SelectionZoneAction::ExecuteFunction fun) | |
28 | : impl{spimpl::make_unique_impl<SelectionZoneActionPrivate>(name, subMenuList, |
|
29 | : impl{spimpl::make_unique_impl<SelectionZoneActionPrivate>(name, subMenuList, | |
29 | std::move(fun))} |
|
30 | std::move(fun))} | |
30 | { |
|
31 | { | |
31 | } |
|
32 | } | |
32 |
|
33 | |||
33 | void SelectionZoneAction::setEnableFunction(EnableFunction fun) |
|
34 | void SelectionZoneAction::setEnableFunction(EnableFunction fun) | |
34 | { |
|
35 | { | |
35 | impl->m_EnableFun = std::move(fun); |
|
36 | impl->m_EnableFun = std::move(fun); | |
36 | } |
|
37 | } | |
37 |
|
38 | |||
38 | void SelectionZoneAction::setDisplayedShortcut(const QKeySequence &shortcut) |
|
39 | void SelectionZoneAction::setDisplayedShortcut(const QKeySequence &shortcut) | |
39 | { |
|
40 | { | |
40 | impl->m_DisplayedShortcut = shortcut; |
|
41 | impl->m_DisplayedShortcut = shortcut; | |
41 | } |
|
42 | } | |
42 |
|
43 | |||
43 | QKeySequence SelectionZoneAction::displayedShortcut() const |
|
44 | QKeySequence SelectionZoneAction::displayedShortcut() const | |
44 | { |
|
45 | { | |
45 | return impl->m_DisplayedShortcut; |
|
46 | return impl->m_DisplayedShortcut; | |
46 | } |
|
47 | } | |
47 |
|
48 | |||
48 | QString SelectionZoneAction::name() const noexcept |
|
49 | QString SelectionZoneAction::name() const noexcept | |
49 | { |
|
50 | { | |
50 | return impl->m_Name; |
|
51 | return impl->m_Name; | |
51 | } |
|
52 | } | |
52 |
|
53 | |||
53 | QStringList SelectionZoneAction::subMenuList() const noexcept |
|
54 | QStringList SelectionZoneAction::subMenuList() const noexcept | |
54 | { |
|
55 | { | |
55 | return impl->m_SubMenuList; |
|
56 | return impl->m_SubMenuList; | |
56 | } |
|
57 | } | |
57 |
|
58 | |||
|
59 | void SelectionZoneAction::setAllowedFiltering(bool value) | |||
|
60 | { | |||
|
61 | impl->m_FilteringAllowed = value; | |||
|
62 | } | |||
|
63 | ||||
|
64 | bool SelectionZoneAction::isFilteringAllowed() const | |||
|
65 | { | |||
|
66 | return impl->m_FilteringAllowed; | |||
|
67 | } | |||
|
68 | ||||
58 | void SelectionZoneAction::execute(const QVector<VisualizationSelectionZoneItem *> &item) |
|
69 | void SelectionZoneAction::execute(const QVector<VisualizationSelectionZoneItem *> &item) | |
59 | { |
|
70 | { | |
60 | impl->m_Fun(item); |
|
71 | impl->m_Fun(item); | |
61 | } |
|
72 | } | |
62 |
|
73 | |||
63 | bool SelectionZoneAction::isEnabled(const QVector<VisualizationSelectionZoneItem *> &item) |
|
74 | bool SelectionZoneAction::isEnabled(const QVector<VisualizationSelectionZoneItem *> &item) | |
64 | { |
|
75 | { | |
65 | return impl->m_EnableFun(item); |
|
76 | return impl->m_EnableFun(item); | |
66 | } |
|
77 | } |
@@ -1,171 +1,174 | |||||
1 | #include "Catalogue/CatalogueActionManager.h" |
|
1 | #include "Catalogue/CatalogueActionManager.h" | |
2 |
|
2 | |||
3 | #include <Actions/ActionsGuiController.h> |
|
3 | #include <Actions/ActionsGuiController.h> | |
4 | #include <Catalogue/CatalogueController.h> |
|
4 | #include <Catalogue/CatalogueController.h> | |
5 | #include <DataSource/DataSourceItem.h> |
|
5 | #include <DataSource/DataSourceItem.h> | |
6 | #include <SqpApplication.h> |
|
6 | #include <SqpApplication.h> | |
7 | #include <Variable/Variable.h> |
|
7 | #include <Variable/Variable.h> | |
8 | #include <Visualization/VisualizationGraphWidget.h> |
|
8 | #include <Visualization/VisualizationGraphWidget.h> | |
9 | #include <Visualization/VisualizationSelectionZoneItem.h> |
|
9 | #include <Visualization/VisualizationSelectionZoneItem.h> | |
10 |
|
10 | |||
11 | #include <Catalogue/CatalogueEventsWidget.h> |
|
11 | #include <Catalogue/CatalogueEventsWidget.h> | |
12 | #include <Catalogue/CatalogueExplorer.h> |
|
12 | #include <Catalogue/CatalogueExplorer.h> | |
13 | #include <Catalogue/CatalogueSideBarWidget.h> |
|
13 | #include <Catalogue/CatalogueSideBarWidget.h> | |
14 |
|
14 | |||
15 | #include <CatalogueDao.h> |
|
15 | #include <CatalogueDao.h> | |
16 | #include <DBCatalogue.h> |
|
16 | #include <DBCatalogue.h> | |
17 | #include <DBEvent.h> |
|
17 | #include <DBEvent.h> | |
18 | #include <DBEventProduct.h> |
|
18 | #include <DBEventProduct.h> | |
19 |
|
19 | |||
20 | #include <QBoxLayout> |
|
20 | #include <QBoxLayout> | |
21 | #include <QComboBox> |
|
21 | #include <QComboBox> | |
22 | #include <QDialog> |
|
22 | #include <QDialog> | |
23 | #include <QDialogButtonBox> |
|
23 | #include <QDialogButtonBox> | |
24 | #include <QLineEdit> |
|
24 | #include <QLineEdit> | |
25 | #include <memory> |
|
25 | #include <memory> | |
26 |
|
26 | |||
27 | const auto CATALOGUE_MENU_NAME = QObject::tr("Catalogues"); |
|
27 | const auto CATALOGUE_MENU_NAME = QObject::tr("Catalogues"); | |
28 | const auto CATALOGUE_CREATE_EVENT_MENU_NAME = QObject::tr("New Event..."); |
|
28 | const auto CATALOGUE_CREATE_EVENT_MENU_NAME = QObject::tr("New Event..."); | |
29 |
|
29 | |||
30 | const auto DEFAULT_EVENT_NAME = QObject::tr("Event"); |
|
30 | const auto DEFAULT_EVENT_NAME = QObject::tr("Event"); | |
31 | const auto DEFAULT_CATALOGUE_NAME = QObject::tr("Catalogue"); |
|
31 | const auto DEFAULT_CATALOGUE_NAME = QObject::tr("Catalogue"); | |
32 |
|
32 | |||
33 | struct CatalogueActionManager::CatalogueActionManagerPrivate { |
|
33 | struct CatalogueActionManager::CatalogueActionManagerPrivate { | |
34 |
|
34 | |||
35 | CatalogueExplorer *m_CatalogueExplorer = nullptr; |
|
35 | CatalogueExplorer *m_CatalogueExplorer = nullptr; | |
36 | QVector<std::shared_ptr<SelectionZoneAction> > m_CreateInCatalogueActions; |
|
36 | QVector<std::shared_ptr<SelectionZoneAction> > m_CreateInCatalogueActions; | |
37 |
|
37 | |||
38 | CatalogueActionManagerPrivate(CatalogueExplorer *catalogueExplorer) |
|
38 | CatalogueActionManagerPrivate(CatalogueExplorer *catalogueExplorer) | |
39 | : m_CatalogueExplorer(catalogueExplorer) |
|
39 | : m_CatalogueExplorer(catalogueExplorer) | |
40 | { |
|
40 | { | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | void createEventFromZones(const QString &eventName, |
|
43 | void createEventFromZones(const QString &eventName, | |
44 | const QVector<VisualizationSelectionZoneItem *> &zones, |
|
44 | const QVector<VisualizationSelectionZoneItem *> &zones, | |
45 | const std::shared_ptr<DBCatalogue> &catalogue = nullptr) |
|
45 | const std::shared_ptr<DBCatalogue> &catalogue = nullptr) | |
46 | { |
|
46 | { | |
47 | auto event = std::make_shared<DBEvent>(); |
|
47 | auto event = std::make_shared<DBEvent>(); | |
48 | event->setName(eventName); |
|
48 | event->setName(eventName); | |
49 |
|
49 | |||
50 | std::list<DBEventProduct> productList; |
|
50 | std::list<DBEventProduct> productList; | |
51 | for (auto zone : zones) { |
|
51 | for (auto zone : zones) { | |
52 | auto graph = zone->parentGraphWidget(); |
|
52 | auto graph = zone->parentGraphWidget(); | |
53 | for (auto var : graph->variables()) { |
|
53 | for (auto var : graph->variables()) { | |
54 | auto eventProduct = std::make_shared<DBEventProduct>(); |
|
54 | auto eventProduct = std::make_shared<DBEventProduct>(); | |
55 | eventProduct->setEvent(*event); |
|
55 | eventProduct->setEvent(*event); | |
56 |
|
56 | |||
57 | auto productId |
|
57 | auto productId | |
58 | = var->metadata().value(DataSourceItem::ID_DATA_KEY, "UnknownID").toString(); |
|
58 | = var->metadata().value(DataSourceItem::ID_DATA_KEY, "UnknownID").toString(); | |
59 |
|
59 | |||
60 | auto zoneRange = zone->range(); |
|
60 | auto zoneRange = zone->range(); | |
61 | eventProduct->setTStart(zoneRange.m_TStart); |
|
61 | eventProduct->setTStart(zoneRange.m_TStart); | |
62 | eventProduct->setTEnd(zoneRange.m_TEnd); |
|
62 | eventProduct->setTEnd(zoneRange.m_TEnd); | |
63 |
|
63 | |||
64 | eventProduct->setProductId(productId); |
|
64 | eventProduct->setProductId(productId); | |
65 |
|
65 | |||
66 | productList.push_back(*eventProduct); |
|
66 | productList.push_back(*eventProduct); | |
67 | } |
|
67 | } | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | event->setEventProducts(productList); |
|
70 | event->setEventProducts(productList); | |
71 |
|
71 | |||
72 | sqpApp->catalogueController().addEvent(event); |
|
72 | sqpApp->catalogueController().addEvent(event); | |
73 |
|
73 | |||
74 |
|
74 | |||
75 | if (catalogue) { |
|
75 | if (catalogue) { | |
76 | catalogue->addEvent(event->getUniqId()); |
|
76 | catalogue->addEvent(event->getUniqId()); | |
77 | sqpApp->catalogueController().updateCatalogue(catalogue); |
|
77 | sqpApp->catalogueController().updateCatalogue(catalogue); | |
78 | m_CatalogueExplorer->sideBarWidget().setCatalogueChanges(catalogue, true); |
|
78 | m_CatalogueExplorer->sideBarWidget().setCatalogueChanges(catalogue, true); | |
79 | if (m_CatalogueExplorer->eventsWidget().displayedCatalogues().contains(catalogue)) { |
|
79 | if (m_CatalogueExplorer->eventsWidget().displayedCatalogues().contains(catalogue)) { | |
80 | m_CatalogueExplorer->eventsWidget().addEvent(event); |
|
80 | m_CatalogueExplorer->eventsWidget().addEvent(event); | |
81 | m_CatalogueExplorer->eventsWidget().setEventChanges(event, true); |
|
81 | m_CatalogueExplorer->eventsWidget().setEventChanges(event, true); | |
82 | } |
|
82 | } | |
83 | } |
|
83 | } | |
84 | else if (m_CatalogueExplorer->eventsWidget().isAllEventsDisplayed()) { |
|
84 | else if (m_CatalogueExplorer->eventsWidget().isAllEventsDisplayed()) { | |
85 | m_CatalogueExplorer->eventsWidget().addEvent(event); |
|
85 | m_CatalogueExplorer->eventsWidget().addEvent(event); | |
86 | m_CatalogueExplorer->eventsWidget().setEventChanges(event, true); |
|
86 | m_CatalogueExplorer->eventsWidget().setEventChanges(event, true); | |
87 | } |
|
87 | } | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | SelectionZoneAction::EnableFunction createEventEnableFuntion() const |
|
90 | SelectionZoneAction::EnableFunction createEventEnableFuntion() const | |
91 | { |
|
91 | { | |
92 | return [](auto zones) { |
|
92 | return [](auto zones) { | |
93 |
|
93 | |||
94 | // Checks that all variables in the zones doesn't refer to the same product |
|
94 | // Checks that all variables in the zones doesn't refer to the same product | |
95 | QSet<QString> usedDatasource; |
|
95 | QSet<QString> usedDatasource; | |
96 | for (auto zone : zones) { |
|
96 | for (auto zone : zones) { | |
97 | auto graph = zone->parentGraphWidget(); |
|
97 | auto graph = zone->parentGraphWidget(); | |
98 | auto variables = graph->variables(); |
|
98 | auto variables = graph->variables(); | |
99 |
|
99 | |||
100 | for (auto var : variables) { |
|
100 | for (auto var : variables) { | |
101 | auto datasourceId |
|
101 | auto datasourceId | |
102 | = var->metadata().value(DataSourceItem::ID_DATA_KEY).toString(); |
|
102 | = var->metadata().value(DataSourceItem::ID_DATA_KEY).toString(); | |
103 | if (!usedDatasource.contains(datasourceId)) { |
|
103 | if (!usedDatasource.contains(datasourceId)) { | |
104 | usedDatasource.insert(datasourceId); |
|
104 | usedDatasource.insert(datasourceId); | |
105 | } |
|
105 | } | |
106 | else { |
|
106 | else { | |
107 | return false; |
|
107 | return false; | |
108 | } |
|
108 | } | |
109 | } |
|
109 | } | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | return true; |
|
112 | return true; | |
113 | }; |
|
113 | }; | |
114 | } |
|
114 | } | |
115 | }; |
|
115 | }; | |
116 |
|
116 | |||
117 | CatalogueActionManager::CatalogueActionManager(CatalogueExplorer *catalogueExplorer) |
|
117 | CatalogueActionManager::CatalogueActionManager(CatalogueExplorer *catalogueExplorer) | |
118 | : impl{spimpl::make_unique_impl<CatalogueActionManagerPrivate>(catalogueExplorer)} |
|
118 | : impl{spimpl::make_unique_impl<CatalogueActionManagerPrivate>(catalogueExplorer)} | |
119 | { |
|
119 | { | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | void CatalogueActionManager::installSelectionZoneActions() |
|
122 | void CatalogueActionManager::installSelectionZoneActions() | |
123 | { |
|
123 | { | |
124 | auto &actionController = sqpApp->actionsGuiController(); |
|
124 | auto &actionController = sqpApp->actionsGuiController(); | |
125 |
|
125 | |||
126 | auto createEventAction = actionController.addSectionZoneAction( |
|
126 | auto createEventAction = actionController.addSectionZoneAction( | |
127 | {CATALOGUE_MENU_NAME, CATALOGUE_CREATE_EVENT_MENU_NAME}, QObject::tr("Without Catalogue"), |
|
127 | {CATALOGUE_MENU_NAME, CATALOGUE_CREATE_EVENT_MENU_NAME}, QObject::tr("Without Catalogue"), | |
128 | [this](auto zones) { impl->createEventFromZones(DEFAULT_EVENT_NAME, zones); }); |
|
128 | [this](auto zones) { impl->createEventFromZones(DEFAULT_EVENT_NAME, zones); }); | |
129 | createEventAction->setEnableFunction(impl->createEventEnableFuntion()); |
|
129 | createEventAction->setEnableFunction(impl->createEventEnableFuntion()); | |
|
130 | createEventAction->setAllowedFiltering(false); | |||
130 |
|
131 | |||
131 | auto createEventInNewCatalogueAction = actionController.addSectionZoneAction( |
|
132 | auto createEventInNewCatalogueAction = actionController.addSectionZoneAction( | |
132 | {CATALOGUE_MENU_NAME, CATALOGUE_CREATE_EVENT_MENU_NAME}, QObject::tr("In New Catalogue"), |
|
133 | {CATALOGUE_MENU_NAME, CATALOGUE_CREATE_EVENT_MENU_NAME}, QObject::tr("In New Catalogue"), | |
133 | [this](auto zones) { |
|
134 | [this](auto zones) { | |
134 |
|
135 | |||
135 | auto newCatalogue = std::make_shared<DBCatalogue>(); |
|
136 | auto newCatalogue = std::make_shared<DBCatalogue>(); | |
136 | newCatalogue->setName(DEFAULT_CATALOGUE_NAME); |
|
137 | newCatalogue->setName(DEFAULT_CATALOGUE_NAME); | |
137 | sqpApp->catalogueController().addCatalogue(newCatalogue); |
|
138 | sqpApp->catalogueController().addCatalogue(newCatalogue); | |
138 | impl->m_CatalogueExplorer->sideBarWidget().addCatalogue(newCatalogue, |
|
139 | impl->m_CatalogueExplorer->sideBarWidget().addCatalogue(newCatalogue, | |
139 | REPOSITORY_DEFAULT); |
|
140 | REPOSITORY_DEFAULT); | |
140 |
|
141 | |||
141 | impl->createEventFromZones(DEFAULT_EVENT_NAME, zones, newCatalogue); |
|
142 | impl->createEventFromZones(DEFAULT_EVENT_NAME, zones, newCatalogue); | |
142 | }); |
|
143 | }); | |
143 | createEventInNewCatalogueAction->setEnableFunction(impl->createEventEnableFuntion()); |
|
144 | createEventInNewCatalogueAction->setEnableFunction(impl->createEventEnableFuntion()); | |
144 |
|
145 | createEventInNewCatalogueAction->setAllowedFiltering(false); | ||
145 |
|
146 | |||
146 | refreshCreateInCatalogueAction(); |
|
147 | refreshCreateInCatalogueAction(); | |
|
148 | ||||
|
149 | actionController.addFilterForMenu({CATALOGUE_MENU_NAME, CATALOGUE_CREATE_EVENT_MENU_NAME}); | |||
147 | } |
|
150 | } | |
148 |
|
151 | |||
149 | void CatalogueActionManager::refreshCreateInCatalogueAction() |
|
152 | void CatalogueActionManager::refreshCreateInCatalogueAction() | |
150 | { |
|
153 | { | |
151 | auto &actionController = sqpApp->actionsGuiController(); |
|
154 | auto &actionController = sqpApp->actionsGuiController(); | |
152 |
|
155 | |||
153 | for (auto action : impl->m_CreateInCatalogueActions) { |
|
156 | for (auto action : impl->m_CreateInCatalogueActions) { | |
154 | actionController.removeAction(action); |
|
157 | actionController.removeAction(action); | |
155 | } |
|
158 | } | |
156 | impl->m_CreateInCatalogueActions.clear(); |
|
159 | impl->m_CreateInCatalogueActions.clear(); | |
157 |
|
160 | |||
158 | auto allCatalogues |
|
161 | auto allCatalogues | |
159 | = impl->m_CatalogueExplorer->sideBarWidget().getCatalogues(REPOSITORY_DEFAULT); |
|
162 | = impl->m_CatalogueExplorer->sideBarWidget().getCatalogues(REPOSITORY_DEFAULT); | |
160 |
|
163 | |||
161 | for (auto catalogue : allCatalogues) { |
|
164 | for (auto catalogue : allCatalogues) { | |
162 | auto catalogueName = catalogue->getName(); |
|
165 | auto catalogueName = catalogue->getName(); | |
163 | auto createEventInCatalogueAction = actionController.addSectionZoneAction( |
|
166 | auto createEventInCatalogueAction = actionController.addSectionZoneAction( | |
164 | {CATALOGUE_MENU_NAME, CATALOGUE_CREATE_EVENT_MENU_NAME}, |
|
167 | {CATALOGUE_MENU_NAME, CATALOGUE_CREATE_EVENT_MENU_NAME}, | |
165 | QObject::tr("In \"").append(catalogueName).append("\""), [this, catalogue](auto zones) { |
|
168 | QObject::tr("In \"").append(catalogueName).append("\""), [this, catalogue](auto zones) { | |
166 | impl->createEventFromZones(DEFAULT_EVENT_NAME, zones, catalogue); |
|
169 | impl->createEventFromZones(DEFAULT_EVENT_NAME, zones, catalogue); | |
167 | }); |
|
170 | }); | |
168 | createEventInCatalogueAction->setEnableFunction(impl->createEventEnableFuntion()); |
|
171 | createEventInCatalogueAction->setEnableFunction(impl->createEventEnableFuntion()); | |
169 | impl->m_CreateInCatalogueActions << createEventInCatalogueAction; |
|
172 | impl->m_CreateInCatalogueActions << createEventInCatalogueAction; | |
170 | } |
|
173 | } | |
171 | } |
|
174 | } |
@@ -1,1057 +1,1077 | |||||
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 <Actions/FilteringAction.h> | |||
15 | #include <Common/MimeTypesDef.h> |
|
16 | #include <Common/MimeTypesDef.h> | |
16 | #include <Data/ArrayData.h> |
|
17 | #include <Data/ArrayData.h> | |
17 | #include <Data/IDataSeries.h> |
|
18 | #include <Data/IDataSeries.h> | |
18 | #include <Data/SpectrogramSeries.h> |
|
19 | #include <Data/SpectrogramSeries.h> | |
19 | #include <DragAndDrop/DragDropGuiController.h> |
|
20 | #include <DragAndDrop/DragDropGuiController.h> | |
20 | #include <Settings/SqpSettingsDefs.h> |
|
21 | #include <Settings/SqpSettingsDefs.h> | |
21 | #include <SqpApplication.h> |
|
22 | #include <SqpApplication.h> | |
22 | #include <Time/TimeController.h> |
|
23 | #include <Time/TimeController.h> | |
23 | #include <Variable/Variable.h> |
|
24 | #include <Variable/Variable.h> | |
24 | #include <Variable/VariableController.h> |
|
25 | #include <Variable/VariableController.h> | |
25 |
|
26 | |||
26 | #include <unordered_map> |
|
27 | #include <unordered_map> | |
27 |
|
28 | |||
28 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget") |
|
29 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget") | |
29 |
|
30 | |||
30 | namespace { |
|
31 | namespace { | |
31 |
|
32 | |||
32 | /// Key pressed to enable drag&drop in all modes |
|
33 | /// Key pressed to enable drag&drop in all modes | |
33 | const auto DRAG_DROP_MODIFIER = Qt::AltModifier; |
|
34 | const auto DRAG_DROP_MODIFIER = Qt::AltModifier; | |
34 |
|
35 | |||
35 | /// Key pressed to enable zoom on horizontal axis |
|
36 | /// Key pressed to enable zoom on horizontal axis | |
36 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::ControlModifier; |
|
37 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::ControlModifier; | |
37 |
|
38 | |||
38 | /// Key pressed to enable zoom on vertical axis |
|
39 | /// Key pressed to enable zoom on vertical axis | |
39 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ShiftModifier; |
|
40 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ShiftModifier; | |
40 |
|
41 | |||
41 | /// Speed of a step of a wheel event for a pan, in percentage of the axis range |
|
42 | /// Speed of a step of a wheel event for a pan, in percentage of the axis range | |
42 | const auto PAN_SPEED = 5; |
|
43 | const auto PAN_SPEED = 5; | |
43 |
|
44 | |||
44 | /// Key pressed to enable a calibration pan |
|
45 | /// Key pressed to enable a calibration pan | |
45 | const auto VERTICAL_PAN_MODIFIER = Qt::AltModifier; |
|
46 | const auto VERTICAL_PAN_MODIFIER = Qt::AltModifier; | |
46 |
|
47 | |||
47 | /// Key pressed to enable multi selection of selection zones |
|
48 | /// Key pressed to enable multi selection of selection zones | |
48 | const auto MULTI_ZONE_SELECTION_MODIFIER = Qt::ControlModifier; |
|
49 | const auto MULTI_ZONE_SELECTION_MODIFIER = Qt::ControlModifier; | |
49 |
|
50 | |||
50 | /// Minimum size for the zoom box, in percentage of the axis range |
|
51 | /// Minimum size for the zoom box, in percentage of the axis range | |
51 | const auto ZOOM_BOX_MIN_SIZE = 0.8; |
|
52 | const auto ZOOM_BOX_MIN_SIZE = 0.8; | |
52 |
|
53 | |||
53 | /// Format of the dates appearing in the label of a cursor |
|
54 | /// 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"); |
|
55 | const auto CURSOR_LABELS_DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd\nhh:mm:ss:zzz"); | |
55 |
|
56 | |||
56 | } // namespace |
|
57 | } // namespace | |
57 |
|
58 | |||
58 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { |
|
59 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { | |
59 |
|
60 | |||
60 | explicit VisualizationGraphWidgetPrivate(const QString &name) |
|
61 | explicit VisualizationGraphWidgetPrivate(const QString &name) | |
61 | : m_Name{name}, |
|
62 | : m_Name{name}, | |
62 | m_Flags{GraphFlag::EnableAll}, |
|
63 | m_Flags{GraphFlag::EnableAll}, | |
63 | m_IsCalibration{false}, |
|
64 | m_IsCalibration{false}, | |
64 | m_RenderingDelegate{nullptr} |
|
65 | m_RenderingDelegate{nullptr} | |
65 | { |
|
66 | { | |
66 | } |
|
67 | } | |
67 |
|
68 | |||
68 | void updateData(PlottablesMap &plottables, std::shared_ptr<Variable> variable, |
|
69 | void updateData(PlottablesMap &plottables, std::shared_ptr<Variable> variable, | |
69 | const SqpRange &range) |
|
70 | const SqpRange &range) | |
70 | { |
|
71 | { | |
71 | VisualizationGraphHelper::updateData(plottables, variable, range); |
|
72 | VisualizationGraphHelper::updateData(plottables, variable, range); | |
72 |
|
73 | |||
73 | // Prevents that data has changed to update rendering |
|
74 | // Prevents that data has changed to update rendering | |
74 | m_RenderingDelegate->onPlotUpdated(); |
|
75 | m_RenderingDelegate->onPlotUpdated(); | |
75 | } |
|
76 | } | |
76 |
|
77 | |||
77 | QString m_Name; |
|
78 | QString m_Name; | |
78 | // 1 variable -> n qcpplot |
|
79 | // 1 variable -> n qcpplot | |
79 | std::map<std::shared_ptr<Variable>, PlottablesMap> m_VariableToPlotMultiMap; |
|
80 | std::map<std::shared_ptr<Variable>, PlottablesMap> m_VariableToPlotMultiMap; | |
80 | GraphFlags m_Flags; |
|
81 | GraphFlags m_Flags; | |
81 | bool m_IsCalibration; |
|
82 | bool m_IsCalibration; | |
82 | /// Delegate used to attach rendering features to the plot |
|
83 | /// Delegate used to attach rendering features to the plot | |
83 | std::unique_ptr<VisualizationGraphRenderingDelegate> m_RenderingDelegate; |
|
84 | std::unique_ptr<VisualizationGraphRenderingDelegate> m_RenderingDelegate; | |
84 |
|
85 | |||
85 | QCPItemRect *m_DrawingZoomRect = nullptr; |
|
86 | QCPItemRect *m_DrawingZoomRect = nullptr; | |
86 | QStack<QPair<QCPRange, QCPRange> > m_ZoomStack; |
|
87 | QStack<QPair<QCPRange, QCPRange> > m_ZoomStack; | |
87 |
|
88 | |||
88 | std::unique_ptr<VisualizationCursorItem> m_HorizontalCursor = nullptr; |
|
89 | std::unique_ptr<VisualizationCursorItem> m_HorizontalCursor = nullptr; | |
89 | std::unique_ptr<VisualizationCursorItem> m_VerticalCursor = nullptr; |
|
90 | std::unique_ptr<VisualizationCursorItem> m_VerticalCursor = nullptr; | |
90 |
|
91 | |||
91 | VisualizationSelectionZoneItem *m_DrawingZone = nullptr; |
|
92 | VisualizationSelectionZoneItem *m_DrawingZone = nullptr; | |
92 | VisualizationSelectionZoneItem *m_HoveredZone = nullptr; |
|
93 | VisualizationSelectionZoneItem *m_HoveredZone = nullptr; | |
93 | QVector<VisualizationSelectionZoneItem *> m_SelectionZones; |
|
94 | QVector<VisualizationSelectionZoneItem *> m_SelectionZones; | |
94 |
|
95 | |||
95 | bool m_HasMovedMouse = false; // Indicates if the mouse moved in a releaseMouse even |
|
96 | bool m_HasMovedMouse = false; // Indicates if the mouse moved in a releaseMouse even | |
96 |
|
97 | |||
97 | bool m_VariableAutoRangeOnInit = true; |
|
98 | bool m_VariableAutoRangeOnInit = true; | |
98 |
|
99 | |||
99 | void startDrawingRect(const QPoint &pos, QCustomPlot &plot) |
|
100 | void startDrawingRect(const QPoint &pos, QCustomPlot &plot) | |
100 | { |
|
101 | { | |
101 | removeDrawingRect(plot); |
|
102 | removeDrawingRect(plot); | |
102 |
|
103 | |||
103 | auto axisPos = posToAxisPos(pos, plot); |
|
104 | auto axisPos = posToAxisPos(pos, plot); | |
104 |
|
105 | |||
105 | m_DrawingZoomRect = new QCPItemRect{&plot}; |
|
106 | m_DrawingZoomRect = new QCPItemRect{&plot}; | |
106 | QPen p; |
|
107 | QPen p; | |
107 | p.setWidth(2); |
|
108 | p.setWidth(2); | |
108 | m_DrawingZoomRect->setPen(p); |
|
109 | m_DrawingZoomRect->setPen(p); | |
109 |
|
110 | |||
110 | m_DrawingZoomRect->topLeft->setCoords(axisPos); |
|
111 | m_DrawingZoomRect->topLeft->setCoords(axisPos); | |
111 | m_DrawingZoomRect->bottomRight->setCoords(axisPos); |
|
112 | m_DrawingZoomRect->bottomRight->setCoords(axisPos); | |
112 | } |
|
113 | } | |
113 |
|
114 | |||
114 | void removeDrawingRect(QCustomPlot &plot) |
|
115 | void removeDrawingRect(QCustomPlot &plot) | |
115 | { |
|
116 | { | |
116 | if (m_DrawingZoomRect) { |
|
117 | if (m_DrawingZoomRect) { | |
117 | plot.removeItem(m_DrawingZoomRect); // the item is deleted by QCustomPlot |
|
118 | plot.removeItem(m_DrawingZoomRect); // the item is deleted by QCustomPlot | |
118 | m_DrawingZoomRect = nullptr; |
|
119 | m_DrawingZoomRect = nullptr; | |
119 | plot.replot(QCustomPlot::rpQueuedReplot); |
|
120 | plot.replot(QCustomPlot::rpQueuedReplot); | |
120 | } |
|
121 | } | |
121 | } |
|
122 | } | |
122 |
|
123 | |||
123 | void startDrawingZone(const QPoint &pos, VisualizationGraphWidget *graph) |
|
124 | void startDrawingZone(const QPoint &pos, VisualizationGraphWidget *graph) | |
124 | { |
|
125 | { | |
125 | endDrawingZone(graph); |
|
126 | endDrawingZone(graph); | |
126 |
|
127 | |||
127 | auto axisPos = posToAxisPos(pos, graph->plot()); |
|
128 | auto axisPos = posToAxisPos(pos, graph->plot()); | |
128 |
|
129 | |||
129 | m_DrawingZone = new VisualizationSelectionZoneItem{&graph->plot()}; |
|
130 | m_DrawingZone = new VisualizationSelectionZoneItem{&graph->plot()}; | |
130 | m_DrawingZone->setRange(axisPos.x(), axisPos.x()); |
|
131 | m_DrawingZone->setRange(axisPos.x(), axisPos.x()); | |
131 | m_DrawingZone->setEditionEnabled(false); |
|
132 | m_DrawingZone->setEditionEnabled(false); | |
132 | } |
|
133 | } | |
133 |
|
134 | |||
134 | void endDrawingZone(VisualizationGraphWidget *graph) |
|
135 | void endDrawingZone(VisualizationGraphWidget *graph) | |
135 | { |
|
136 | { | |
136 | if (m_DrawingZone) { |
|
137 | if (m_DrawingZone) { | |
137 | auto drawingZoneRange = m_DrawingZone->range(); |
|
138 | auto drawingZoneRange = m_DrawingZone->range(); | |
138 | if (qAbs(drawingZoneRange.m_TEnd - drawingZoneRange.m_TStart) > 0) { |
|
139 | if (qAbs(drawingZoneRange.m_TEnd - drawingZoneRange.m_TStart) > 0) { | |
139 | m_DrawingZone->setEditionEnabled(true); |
|
140 | m_DrawingZone->setEditionEnabled(true); | |
140 | addSelectionZone(m_DrawingZone); |
|
141 | addSelectionZone(m_DrawingZone); | |
141 | } |
|
142 | } | |
142 | else { |
|
143 | else { | |
143 | graph->plot().removeItem(m_DrawingZone); // the item is deleted by QCustomPlot |
|
144 | graph->plot().removeItem(m_DrawingZone); // the item is deleted by QCustomPlot | |
144 | } |
|
145 | } | |
145 |
|
146 | |||
146 | graph->plot().replot(QCustomPlot::rpQueuedReplot); |
|
147 | graph->plot().replot(QCustomPlot::rpQueuedReplot); | |
147 | m_DrawingZone = nullptr; |
|
148 | m_DrawingZone = nullptr; | |
148 | } |
|
149 | } | |
149 | } |
|
150 | } | |
150 |
|
151 | |||
151 | void setSelectionZonesEditionEnabled(bool value) |
|
152 | void setSelectionZonesEditionEnabled(bool value) | |
152 | { |
|
153 | { | |
153 | for (auto s : m_SelectionZones) { |
|
154 | for (auto s : m_SelectionZones) { | |
154 | s->setEditionEnabled(value); |
|
155 | s->setEditionEnabled(value); | |
155 | } |
|
156 | } | |
156 | } |
|
157 | } | |
157 |
|
158 | |||
158 | void addSelectionZone(VisualizationSelectionZoneItem *zone) { m_SelectionZones << zone; } |
|
159 | void addSelectionZone(VisualizationSelectionZoneItem *zone) { m_SelectionZones << zone; } | |
159 |
|
160 | |||
160 | VisualizationSelectionZoneItem *selectionZoneAt(const QPoint &pos, |
|
161 | VisualizationSelectionZoneItem *selectionZoneAt(const QPoint &pos, | |
161 | const QCustomPlot &plot) const |
|
162 | const QCustomPlot &plot) const | |
162 | { |
|
163 | { | |
163 | VisualizationSelectionZoneItem *selectionZoneItemUnderCursor = nullptr; |
|
164 | VisualizationSelectionZoneItem *selectionZoneItemUnderCursor = nullptr; | |
164 | auto minDistanceToZone = -1; |
|
165 | auto minDistanceToZone = -1; | |
165 | for (auto zone : m_SelectionZones) { |
|
166 | for (auto zone : m_SelectionZones) { | |
166 | auto distanceToZone = zone->selectTest(pos, false); |
|
167 | auto distanceToZone = zone->selectTest(pos, false); | |
167 | if ((minDistanceToZone < 0 || distanceToZone <= minDistanceToZone) |
|
168 | if ((minDistanceToZone < 0 || distanceToZone <= minDistanceToZone) | |
168 | && distanceToZone >= 0 && distanceToZone < plot.selectionTolerance()) { |
|
169 | && distanceToZone >= 0 && distanceToZone < plot.selectionTolerance()) { | |
169 | selectionZoneItemUnderCursor = zone; |
|
170 | selectionZoneItemUnderCursor = zone; | |
170 | } |
|
171 | } | |
171 | } |
|
172 | } | |
172 |
|
173 | |||
173 | return selectionZoneItemUnderCursor; |
|
174 | return selectionZoneItemUnderCursor; | |
174 | } |
|
175 | } | |
175 |
|
176 | |||
176 | QVector<VisualizationSelectionZoneItem *> selectionZonesAt(const QPoint &pos, |
|
177 | QVector<VisualizationSelectionZoneItem *> selectionZonesAt(const QPoint &pos, | |
177 | const QCustomPlot &plot) const |
|
178 | const QCustomPlot &plot) const | |
178 | { |
|
179 | { | |
179 | QVector<VisualizationSelectionZoneItem *> zones; |
|
180 | QVector<VisualizationSelectionZoneItem *> zones; | |
180 | for (auto zone : m_SelectionZones) { |
|
181 | for (auto zone : m_SelectionZones) { | |
181 | auto distanceToZone = zone->selectTest(pos, false); |
|
182 | auto distanceToZone = zone->selectTest(pos, false); | |
182 | if (distanceToZone >= 0 && distanceToZone < plot.selectionTolerance()) { |
|
183 | if (distanceToZone >= 0 && distanceToZone < plot.selectionTolerance()) { | |
183 | zones << zone; |
|
184 | zones << zone; | |
184 | } |
|
185 | } | |
185 | } |
|
186 | } | |
186 |
|
187 | |||
187 | return zones; |
|
188 | return zones; | |
188 | } |
|
189 | } | |
189 |
|
190 | |||
190 | void moveSelectionZoneOnTop(VisualizationSelectionZoneItem *zone, QCustomPlot &plot) |
|
191 | void moveSelectionZoneOnTop(VisualizationSelectionZoneItem *zone, QCustomPlot &plot) | |
191 | { |
|
192 | { | |
192 | if (!m_SelectionZones.isEmpty() && m_SelectionZones.last() != zone) { |
|
193 | if (!m_SelectionZones.isEmpty() && m_SelectionZones.last() != zone) { | |
193 | zone->moveToTop(); |
|
194 | zone->moveToTop(); | |
194 | m_SelectionZones.removeAll(zone); |
|
195 | m_SelectionZones.removeAll(zone); | |
195 | m_SelectionZones.append(zone); |
|
196 | m_SelectionZones.append(zone); | |
196 | } |
|
197 | } | |
197 | } |
|
198 | } | |
198 |
|
199 | |||
199 | QPointF posToAxisPos(const QPoint &pos, QCustomPlot &plot) const |
|
200 | QPointF posToAxisPos(const QPoint &pos, QCustomPlot &plot) const | |
200 | { |
|
201 | { | |
201 | auto axisX = plot.axisRect()->axis(QCPAxis::atBottom); |
|
202 | auto axisX = plot.axisRect()->axis(QCPAxis::atBottom); | |
202 | auto axisY = plot.axisRect()->axis(QCPAxis::atLeft); |
|
203 | auto axisY = plot.axisRect()->axis(QCPAxis::atLeft); | |
203 | return QPointF{axisX->pixelToCoord(pos.x()), axisY->pixelToCoord(pos.y())}; |
|
204 | return QPointF{axisX->pixelToCoord(pos.x()), axisY->pixelToCoord(pos.y())}; | |
204 | } |
|
205 | } | |
205 |
|
206 | |||
206 | bool pointIsInAxisRect(const QPointF &axisPoint, QCustomPlot &plot) const |
|
207 | bool pointIsInAxisRect(const QPointF &axisPoint, QCustomPlot &plot) const | |
207 | { |
|
208 | { | |
208 | auto axisX = plot.axisRect()->axis(QCPAxis::atBottom); |
|
209 | auto axisX = plot.axisRect()->axis(QCPAxis::atBottom); | |
209 | auto axisY = plot.axisRect()->axis(QCPAxis::atLeft); |
|
210 | auto axisY = plot.axisRect()->axis(QCPAxis::atLeft); | |
210 | return axisX->range().contains(axisPoint.x()) && axisY->range().contains(axisPoint.y()); |
|
211 | return axisX->range().contains(axisPoint.x()) && axisY->range().contains(axisPoint.y()); | |
211 | } |
|
212 | } | |
212 | }; |
|
213 | }; | |
213 |
|
214 | |||
214 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) |
|
215 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) | |
215 | : VisualizationDragWidget{parent}, |
|
216 | : VisualizationDragWidget{parent}, | |
216 | ui{new Ui::VisualizationGraphWidget}, |
|
217 | ui{new Ui::VisualizationGraphWidget}, | |
217 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>(name)} |
|
218 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>(name)} | |
218 | { |
|
219 | { | |
219 | ui->setupUi(this); |
|
220 | ui->setupUi(this); | |
220 |
|
221 | |||
221 | // 'Close' options : widget is deleted when closed |
|
222 | // 'Close' options : widget is deleted when closed | |
222 | setAttribute(Qt::WA_DeleteOnClose); |
|
223 | setAttribute(Qt::WA_DeleteOnClose); | |
223 |
|
224 | |||
224 | // Set qcpplot properties : |
|
225 | // Set qcpplot properties : | |
225 | // - zoom is enabled |
|
226 | // - zoom is enabled | |
226 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation |
|
227 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation | |
227 | ui->widget->setInteractions(QCP::iRangeZoom); |
|
228 | ui->widget->setInteractions(QCP::iRangeZoom); | |
228 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal | Qt::Vertical); |
|
229 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal | Qt::Vertical); | |
229 |
|
230 | |||
230 | // The delegate must be initialized after the ui as it uses the plot |
|
231 | // The delegate must be initialized after the ui as it uses the plot | |
231 | impl->m_RenderingDelegate = std::make_unique<VisualizationGraphRenderingDelegate>(*this); |
|
232 | impl->m_RenderingDelegate = std::make_unique<VisualizationGraphRenderingDelegate>(*this); | |
232 |
|
233 | |||
233 | // Init the cursors |
|
234 | // Init the cursors | |
234 | impl->m_HorizontalCursor = std::make_unique<VisualizationCursorItem>(&plot()); |
|
235 | impl->m_HorizontalCursor = std::make_unique<VisualizationCursorItem>(&plot()); | |
235 | impl->m_HorizontalCursor->setOrientation(Qt::Horizontal); |
|
236 | impl->m_HorizontalCursor->setOrientation(Qt::Horizontal); | |
236 | impl->m_VerticalCursor = std::make_unique<VisualizationCursorItem>(&plot()); |
|
237 | impl->m_VerticalCursor = std::make_unique<VisualizationCursorItem>(&plot()); | |
237 | impl->m_VerticalCursor->setOrientation(Qt::Vertical); |
|
238 | impl->m_VerticalCursor->setOrientation(Qt::Vertical); | |
238 |
|
239 | |||
239 | connect(ui->widget, &QCustomPlot::mousePress, this, &VisualizationGraphWidget::onMousePress); |
|
240 | connect(ui->widget, &QCustomPlot::mousePress, this, &VisualizationGraphWidget::onMousePress); | |
240 | connect(ui->widget, &QCustomPlot::mouseRelease, this, |
|
241 | connect(ui->widget, &QCustomPlot::mouseRelease, this, | |
241 | &VisualizationGraphWidget::onMouseRelease); |
|
242 | &VisualizationGraphWidget::onMouseRelease); | |
242 | connect(ui->widget, &QCustomPlot::mouseMove, this, &VisualizationGraphWidget::onMouseMove); |
|
243 | connect(ui->widget, &QCustomPlot::mouseMove, this, &VisualizationGraphWidget::onMouseMove); | |
243 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); |
|
244 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); | |
244 | connect(ui->widget, &QCustomPlot::mouseDoubleClick, this, |
|
245 | connect(ui->widget, &QCustomPlot::mouseDoubleClick, this, | |
245 | &VisualizationGraphWidget::onMouseDoubleClick); |
|
246 | &VisualizationGraphWidget::onMouseDoubleClick); | |
246 | connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>( |
|
247 | connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>( | |
247 | &QCPAxis::rangeChanged), |
|
248 | &QCPAxis::rangeChanged), | |
248 |
|
|
249 | this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection); | |
249 |
|
250 | |||
250 | // Activates menu when right clicking on the graph |
|
251 | // Activates menu when right clicking on the graph | |
251 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); |
|
252 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); | |
252 | connect(ui->widget, &QCustomPlot::customContextMenuRequested, this, |
|
253 | connect(ui->widget, &QCustomPlot::customContextMenuRequested, this, | |
253 | &VisualizationGraphWidget::onGraphMenuRequested); |
|
254 | &VisualizationGraphWidget::onGraphMenuRequested); | |
254 |
|
255 | |||
255 | connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(), |
|
256 | connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(), | |
256 | &VariableController::onRequestDataLoading); |
|
257 | &VariableController::onRequestDataLoading); | |
257 |
|
258 | |||
258 | connect(&sqpApp->variableController(), &VariableController::updateVarDisplaying, this, |
|
259 | connect(&sqpApp->variableController(), &VariableController::updateVarDisplaying, this, | |
259 | &VisualizationGraphWidget::onUpdateVarDisplaying); |
|
260 | &VisualizationGraphWidget::onUpdateVarDisplaying); | |
260 |
|
261 | |||
261 | // Necessary for all platform since Qt::AA_EnableHighDpiScaling is enable. |
|
262 | // Necessary for all platform since Qt::AA_EnableHighDpiScaling is enable. | |
262 | plot().setPlottingHint(QCP::phFastPolylines, true); |
|
263 | plot().setPlottingHint(QCP::phFastPolylines, true); | |
263 | } |
|
264 | } | |
264 |
|
265 | |||
265 |
|
266 | |||
266 | VisualizationGraphWidget::~VisualizationGraphWidget() |
|
267 | VisualizationGraphWidget::~VisualizationGraphWidget() | |
267 | { |
|
268 | { | |
268 | delete ui; |
|
269 | delete ui; | |
269 | } |
|
270 | } | |
270 |
|
271 | |||
271 | VisualizationZoneWidget *VisualizationGraphWidget::parentZoneWidget() const noexcept |
|
272 | VisualizationZoneWidget *VisualizationGraphWidget::parentZoneWidget() const noexcept | |
272 | { |
|
273 | { | |
273 | auto parent = parentWidget(); |
|
274 | auto parent = parentWidget(); | |
274 | while (parent != nullptr && !qobject_cast<VisualizationZoneWidget *>(parent)) { |
|
275 | while (parent != nullptr && !qobject_cast<VisualizationZoneWidget *>(parent)) { | |
275 | parent = parent->parentWidget(); |
|
276 | parent = parent->parentWidget(); | |
276 | } |
|
277 | } | |
277 |
|
278 | |||
278 | return qobject_cast<VisualizationZoneWidget *>(parent); |
|
279 | return qobject_cast<VisualizationZoneWidget *>(parent); | |
279 | } |
|
280 | } | |
280 |
|
281 | |||
281 | VisualizationWidget *VisualizationGraphWidget::parentVisualizationWidget() const |
|
282 | VisualizationWidget *VisualizationGraphWidget::parentVisualizationWidget() const | |
282 | { |
|
283 | { | |
283 | auto parent = parentWidget(); |
|
284 | auto parent = parentWidget(); | |
284 | while (parent != nullptr && !qobject_cast<VisualizationWidget *>(parent)) { |
|
285 | while (parent != nullptr && !qobject_cast<VisualizationWidget *>(parent)) { | |
285 | parent = parent->parentWidget(); |
|
286 | parent = parent->parentWidget(); | |
286 | } |
|
287 | } | |
287 |
|
288 | |||
288 | return qobject_cast<VisualizationWidget *>(parent); |
|
289 | return qobject_cast<VisualizationWidget *>(parent); | |
289 | } |
|
290 | } | |
290 |
|
291 | |||
291 | void VisualizationGraphWidget::setFlags(GraphFlags flags) |
|
292 | void VisualizationGraphWidget::setFlags(GraphFlags flags) | |
292 | { |
|
293 | { | |
293 | impl->m_Flags = std::move(flags); |
|
294 | impl->m_Flags = std::move(flags); | |
294 | } |
|
295 | } | |
295 |
|
296 | |||
296 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, SqpRange range) |
|
297 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, SqpRange range) | |
297 | { |
|
298 | { | |
298 | /// Lambda used to set graph's units and range according to the variable passed in parameter |
|
299 | /// Lambda used to set graph's units and range according to the variable passed in parameter | |
299 | auto loadRange = [this](std::shared_ptr<Variable> variable, const SqpRange &range) { |
|
300 | auto loadRange = [this](std::shared_ptr<Variable> variable, const SqpRange &range) { | |
300 | impl->m_RenderingDelegate->setAxesUnits(*variable); |
|
301 | impl->m_RenderingDelegate->setAxesUnits(*variable); | |
301 |
|
302 | |||
302 | this->setFlags(GraphFlag::DisableAll); |
|
303 | this->setFlags(GraphFlag::DisableAll); | |
303 | setGraphRange(range); |
|
304 | setGraphRange(range); | |
304 | this->setFlags(GraphFlag::EnableAll); |
|
305 | this->setFlags(GraphFlag::EnableAll); | |
305 | emit requestDataLoading({variable}, range, false); |
|
306 | emit requestDataLoading({variable}, range, false); | |
306 | }; |
|
307 | }; | |
307 |
|
308 | |||
308 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); |
|
309 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); | |
309 |
|
310 | |||
310 | // Calls update of graph's range and units when the data of the variable have been initialized. |
|
311 | // Calls update of graph's range and units when the data of the variable have been initialized. | |
311 | // Note: we use QueuedConnection here as the update event must be called in the UI thread |
|
312 | // Note: we use QueuedConnection here as the update event must be called in the UI thread | |
312 | connect(variable.get(), &Variable::dataInitialized, this, |
|
313 | connect(variable.get(), &Variable::dataInitialized, this, | |
313 | [ varW = std::weak_ptr<Variable>{variable}, range, loadRange, this ]() { |
|
314 | [ varW = std::weak_ptr<Variable>{variable}, range, loadRange, this ]() { | |
314 | if (auto var = varW.lock()) { |
|
315 | if (auto var = varW.lock()) { | |
315 | // If the variable is the first added in the graph, we load its range |
|
316 | // If the variable is the first added in the graph, we load its range | |
316 | auto firstVariableInGraph = range == INVALID_RANGE; |
|
317 | auto firstVariableInGraph = range == INVALID_RANGE; | |
317 | auto loadedRange = graphRange(); |
|
318 | auto loadedRange = graphRange(); | |
318 | if (impl->m_VariableAutoRangeOnInit) { |
|
319 | if (impl->m_VariableAutoRangeOnInit) { | |
319 | loadedRange = firstVariableInGraph ? var->range() : range; |
|
320 | loadedRange = firstVariableInGraph ? var->range() : range; | |
320 | } |
|
321 | } | |
321 | loadRange(var, loadedRange); |
|
322 | loadRange(var, loadedRange); | |
322 | setYRange(var); |
|
323 | setYRange(var); | |
323 | } |
|
324 | } | |
324 | }, |
|
325 | }, | |
325 | Qt::QueuedConnection); |
|
326 | Qt::QueuedConnection); | |
326 |
|
327 | |||
327 | // Uses delegate to create the qcpplot components according to the variable |
|
328 | // Uses delegate to create the qcpplot components according to the variable | |
328 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); |
|
329 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); | |
329 |
|
330 | |||
330 | // Sets graph properties |
|
331 | // Sets graph properties | |
331 | impl->m_RenderingDelegate->setGraphProperties(*variable, createdPlottables); |
|
332 | impl->m_RenderingDelegate->setGraphProperties(*variable, createdPlottables); | |
332 |
|
333 | |||
333 | impl->m_VariableToPlotMultiMap.insert({variable, std::move(createdPlottables)}); |
|
334 | impl->m_VariableToPlotMultiMap.insert({variable, std::move(createdPlottables)}); | |
334 |
|
335 | |||
335 | // If the variable already has its data loaded, load its units and its range in the graph |
|
336 | // If the variable already has its data loaded, load its units and its range in the graph | |
336 | if (variable->dataSeries() != nullptr) { |
|
337 | if (variable->dataSeries() != nullptr) { | |
337 | loadRange(variable, range); |
|
338 | loadRange(variable, range); | |
338 | } |
|
339 | } | |
339 |
|
340 | |||
340 | emit variableAdded(variable); |
|
341 | emit variableAdded(variable); | |
341 | } |
|
342 | } | |
342 |
|
343 | |||
343 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept |
|
344 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept | |
344 | { |
|
345 | { | |
345 | // Each component associated to the variable : |
|
346 | // Each component associated to the variable : | |
346 | // - is removed from qcpplot (which deletes it) |
|
347 | // - is removed from qcpplot (which deletes it) | |
347 | // - is no longer referenced in the map |
|
348 | // - is no longer referenced in the map | |
348 | auto variableIt = impl->m_VariableToPlotMultiMap.find(variable); |
|
349 | auto variableIt = impl->m_VariableToPlotMultiMap.find(variable); | |
349 | if (variableIt != impl->m_VariableToPlotMultiMap.cend()) { |
|
350 | if (variableIt != impl->m_VariableToPlotMultiMap.cend()) { | |
350 | emit variableAboutToBeRemoved(variable); |
|
351 | emit variableAboutToBeRemoved(variable); | |
351 |
|
352 | |||
352 | auto &plottablesMap = variableIt->second; |
|
353 | auto &plottablesMap = variableIt->second; | |
353 |
|
354 | |||
354 | for (auto plottableIt = plottablesMap.cbegin(), plottableEnd = plottablesMap.cend(); |
|
355 | for (auto plottableIt = plottablesMap.cbegin(), plottableEnd = plottablesMap.cend(); | |
355 | plottableIt != plottableEnd;) { |
|
356 | plottableIt != plottableEnd;) { | |
356 | ui->widget->removePlottable(plottableIt->second); |
|
357 | ui->widget->removePlottable(plottableIt->second); | |
357 | plottableIt = plottablesMap.erase(plottableIt); |
|
358 | plottableIt = plottablesMap.erase(plottableIt); | |
358 | } |
|
359 | } | |
359 |
|
360 | |||
360 | impl->m_VariableToPlotMultiMap.erase(variableIt); |
|
361 | impl->m_VariableToPlotMultiMap.erase(variableIt); | |
361 | } |
|
362 | } | |
362 |
|
363 | |||
363 | // Updates graph |
|
364 | // Updates graph | |
364 | ui->widget->replot(); |
|
365 | ui->widget->replot(); | |
365 | } |
|
366 | } | |
366 |
|
367 | |||
367 | QList<std::shared_ptr<Variable> > VisualizationGraphWidget::variables() const |
|
368 | QList<std::shared_ptr<Variable> > VisualizationGraphWidget::variables() const | |
368 | { |
|
369 | { | |
369 | auto variables = QList<std::shared_ptr<Variable> >{}; |
|
370 | auto variables = QList<std::shared_ptr<Variable> >{}; | |
370 | for (auto it = std::cbegin(impl->m_VariableToPlotMultiMap); |
|
371 | for (auto it = std::cbegin(impl->m_VariableToPlotMultiMap); | |
371 | it != std::cend(impl->m_VariableToPlotMultiMap); ++it) { |
|
372 | it != std::cend(impl->m_VariableToPlotMultiMap); ++it) { | |
372 | variables << it->first; |
|
373 | variables << it->first; | |
373 | } |
|
374 | } | |
374 |
|
375 | |||
375 | return variables; |
|
376 | return variables; | |
376 | } |
|
377 | } | |
377 |
|
378 | |||
378 | void VisualizationGraphWidget::setYRange(std::shared_ptr<Variable> variable) |
|
379 | void VisualizationGraphWidget::setYRange(std::shared_ptr<Variable> variable) | |
379 | { |
|
380 | { | |
380 | if (!variable) { |
|
381 | if (!variable) { | |
381 | qCCritical(LOG_VisualizationGraphWidget()) << "Can't set y-axis range: variable is null"; |
|
382 | qCCritical(LOG_VisualizationGraphWidget()) << "Can't set y-axis range: variable is null"; | |
382 | return; |
|
383 | return; | |
383 | } |
|
384 | } | |
384 |
|
385 | |||
385 | VisualizationGraphHelper::setYAxisRange(variable, *ui->widget); |
|
386 | VisualizationGraphHelper::setYAxisRange(variable, *ui->widget); | |
386 | } |
|
387 | } | |
387 |
|
388 | |||
388 | SqpRange VisualizationGraphWidget::graphRange() const noexcept |
|
389 | SqpRange VisualizationGraphWidget::graphRange() const noexcept | |
389 | { |
|
390 | { | |
390 | auto graphRange = ui->widget->xAxis->range(); |
|
391 | auto graphRange = ui->widget->xAxis->range(); | |
391 | return SqpRange{graphRange.lower, graphRange.upper}; |
|
392 | return SqpRange{graphRange.lower, graphRange.upper}; | |
392 | } |
|
393 | } | |
393 |
|
394 | |||
394 | void VisualizationGraphWidget::setGraphRange(const SqpRange &range, bool calibration) |
|
395 | void VisualizationGraphWidget::setGraphRange(const SqpRange &range, bool calibration) | |
395 | { |
|
396 | { | |
396 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START"); |
|
397 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START"); | |
397 |
|
398 | |||
398 | if (calibration) { |
|
399 | if (calibration) { | |
399 | impl->m_IsCalibration = true; |
|
400 | impl->m_IsCalibration = true; | |
400 | } |
|
401 | } | |
401 |
|
402 | |||
402 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); |
|
403 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); | |
403 | ui->widget->replot(); |
|
404 | ui->widget->replot(); | |
404 |
|
405 | |||
405 | if (calibration) { |
|
406 | if (calibration) { | |
406 | impl->m_IsCalibration = false; |
|
407 | impl->m_IsCalibration = false; | |
407 | } |
|
408 | } | |
408 |
|
409 | |||
409 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END"); |
|
410 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END"); | |
410 | } |
|
411 | } | |
411 |
|
412 | |||
412 | void VisualizationGraphWidget::setAutoRangeOnVariableInitialization(bool value) |
|
413 | void VisualizationGraphWidget::setAutoRangeOnVariableInitialization(bool value) | |
413 | { |
|
414 | { | |
414 | impl->m_VariableAutoRangeOnInit = value; |
|
415 | impl->m_VariableAutoRangeOnInit = value; | |
415 | } |
|
416 | } | |
416 |
|
417 | |||
417 | QVector<SqpRange> VisualizationGraphWidget::selectionZoneRanges() const |
|
418 | QVector<SqpRange> VisualizationGraphWidget::selectionZoneRanges() const | |
418 | { |
|
419 | { | |
419 | QVector<SqpRange> ranges; |
|
420 | QVector<SqpRange> ranges; | |
420 | for (auto zone : impl->m_SelectionZones) { |
|
421 | for (auto zone : impl->m_SelectionZones) { | |
421 | ranges << zone->range(); |
|
422 | ranges << zone->range(); | |
422 | } |
|
423 | } | |
423 |
|
424 | |||
424 | return ranges; |
|
425 | return ranges; | |
425 | } |
|
426 | } | |
426 |
|
427 | |||
427 | void VisualizationGraphWidget::addSelectionZones(const QVector<SqpRange> &ranges) |
|
428 | void VisualizationGraphWidget::addSelectionZones(const QVector<SqpRange> &ranges) | |
428 | { |
|
429 | { | |
429 | for (const auto &range : ranges) { |
|
430 | for (const auto &range : ranges) { | |
430 | // note: ownership is transfered to QCustomPlot |
|
431 | // note: ownership is transfered to QCustomPlot | |
431 | auto zone = new VisualizationSelectionZoneItem(&plot()); |
|
432 | auto zone = new VisualizationSelectionZoneItem(&plot()); | |
432 | zone->setRange(range.m_TStart, range.m_TEnd); |
|
433 | zone->setRange(range.m_TStart, range.m_TEnd); | |
433 | impl->addSelectionZone(zone); |
|
434 | impl->addSelectionZone(zone); | |
434 | } |
|
435 | } | |
435 |
|
436 | |||
436 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
437 | plot().replot(QCustomPlot::rpQueuedReplot); | |
437 | } |
|
438 | } | |
438 |
|
439 | |||
439 | VisualizationSelectionZoneItem *VisualizationGraphWidget::addSelectionZone(const QString &name, |
|
440 | VisualizationSelectionZoneItem *VisualizationGraphWidget::addSelectionZone(const QString &name, | |
440 | const SqpRange &range) |
|
441 | const SqpRange &range) | |
441 | { |
|
442 | { | |
442 | // note: ownership is transfered to QCustomPlot |
|
443 | // note: ownership is transfered to QCustomPlot | |
443 | auto zone = new VisualizationSelectionZoneItem(&plot()); |
|
444 | auto zone = new VisualizationSelectionZoneItem(&plot()); | |
444 | zone->setName(name); |
|
445 | zone->setName(name); | |
445 | zone->setRange(range.m_TStart, range.m_TEnd); |
|
446 | zone->setRange(range.m_TStart, range.m_TEnd); | |
446 | impl->addSelectionZone(zone); |
|
447 | impl->addSelectionZone(zone); | |
447 |
|
448 | |||
448 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
449 | plot().replot(QCustomPlot::rpQueuedReplot); | |
449 |
|
450 | |||
450 | return zone; |
|
451 | return zone; | |
451 | } |
|
452 | } | |
452 |
|
453 | |||
453 | void VisualizationGraphWidget::removeSelectionZone(VisualizationSelectionZoneItem *selectionZone) |
|
454 | void VisualizationGraphWidget::removeSelectionZone(VisualizationSelectionZoneItem *selectionZone) | |
454 | { |
|
455 | { | |
455 | parentVisualizationWidget()->selectionZoneManager().setSelected(selectionZone, false); |
|
456 | parentVisualizationWidget()->selectionZoneManager().setSelected(selectionZone, false); | |
456 |
|
457 | |||
457 | if (impl->m_HoveredZone == selectionZone) { |
|
458 | if (impl->m_HoveredZone == selectionZone) { | |
458 | impl->m_HoveredZone = nullptr; |
|
459 | impl->m_HoveredZone = nullptr; | |
459 | setCursor(Qt::ArrowCursor); |
|
460 | setCursor(Qt::ArrowCursor); | |
460 | } |
|
461 | } | |
461 |
|
462 | |||
462 | impl->m_SelectionZones.removeAll(selectionZone); |
|
463 | impl->m_SelectionZones.removeAll(selectionZone); | |
463 | plot().removeItem(selectionZone); |
|
464 | plot().removeItem(selectionZone); | |
464 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
465 | plot().replot(QCustomPlot::rpQueuedReplot); | |
465 | } |
|
466 | } | |
466 |
|
467 | |||
467 | void VisualizationGraphWidget::undoZoom() |
|
468 | void VisualizationGraphWidget::undoZoom() | |
468 | { |
|
469 | { | |
469 | auto zoom = impl->m_ZoomStack.pop(); |
|
470 | auto zoom = impl->m_ZoomStack.pop(); | |
470 | auto axisX = plot().axisRect()->axis(QCPAxis::atBottom); |
|
471 | auto axisX = plot().axisRect()->axis(QCPAxis::atBottom); | |
471 | auto axisY = plot().axisRect()->axis(QCPAxis::atLeft); |
|
472 | auto axisY = plot().axisRect()->axis(QCPAxis::atLeft); | |
472 |
|
473 | |||
473 | axisX->setRange(zoom.first); |
|
474 | axisX->setRange(zoom.first); | |
474 | axisY->setRange(zoom.second); |
|
475 | axisY->setRange(zoom.second); | |
475 |
|
476 | |||
476 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
477 | plot().replot(QCustomPlot::rpQueuedReplot); | |
477 | } |
|
478 | } | |
478 |
|
479 | |||
479 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
480 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) | |
480 | { |
|
481 | { | |
481 | if (visitor) { |
|
482 | if (visitor) { | |
482 | visitor->visit(this); |
|
483 | visitor->visit(this); | |
483 | } |
|
484 | } | |
484 | else { |
|
485 | else { | |
485 | qCCritical(LOG_VisualizationGraphWidget()) |
|
486 | qCCritical(LOG_VisualizationGraphWidget()) | |
486 | << tr("Can't visit widget : the visitor is null"); |
|
487 | << tr("Can't visit widget : the visitor is null"); | |
487 | } |
|
488 | } | |
488 | } |
|
489 | } | |
489 |
|
490 | |||
490 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const |
|
491 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const | |
491 | { |
|
492 | { | |
492 | auto isSpectrogram = [](const auto &variable) { |
|
493 | auto isSpectrogram = [](const auto &variable) { | |
493 | return std::dynamic_pointer_cast<SpectrogramSeries>(variable.dataSeries()) != nullptr; |
|
494 | return std::dynamic_pointer_cast<SpectrogramSeries>(variable.dataSeries()) != nullptr; | |
494 | }; |
|
495 | }; | |
495 |
|
496 | |||
496 | // - A spectrogram series can't be dropped on graph with existing plottables |
|
497 | // - A spectrogram series can't be dropped on graph with existing plottables | |
497 | // - No data series can be dropped on graph with existing spectrogram series |
|
498 | // - No data series can be dropped on graph with existing spectrogram series | |
498 | return isSpectrogram(variable) |
|
499 | return isSpectrogram(variable) | |
499 | ? impl->m_VariableToPlotMultiMap.empty() |
|
500 | ? impl->m_VariableToPlotMultiMap.empty() | |
500 | : std::none_of( |
|
501 | : std::none_of( | |
501 | impl->m_VariableToPlotMultiMap.cbegin(), impl->m_VariableToPlotMultiMap.cend(), |
|
502 | impl->m_VariableToPlotMultiMap.cbegin(), impl->m_VariableToPlotMultiMap.cend(), | |
502 | [isSpectrogram](const auto &entry) { return isSpectrogram(*entry.first); }); |
|
503 | [isSpectrogram](const auto &entry) { return isSpectrogram(*entry.first); }); | |
503 | } |
|
504 | } | |
504 |
|
505 | |||
505 | bool VisualizationGraphWidget::contains(const Variable &variable) const |
|
506 | bool VisualizationGraphWidget::contains(const Variable &variable) const | |
506 | { |
|
507 | { | |
507 | // Finds the variable among the keys of the map |
|
508 | // Finds the variable among the keys of the map | |
508 | auto variablePtr = &variable; |
|
509 | auto variablePtr = &variable; | |
509 | auto findVariable |
|
510 | auto findVariable | |
510 | = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); }; |
|
511 | = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); }; | |
511 |
|
512 | |||
512 | auto end = impl->m_VariableToPlotMultiMap.cend(); |
|
513 | auto end = impl->m_VariableToPlotMultiMap.cend(); | |
513 | auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable); |
|
514 | auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable); | |
514 | return it != end; |
|
515 | return it != end; | |
515 | } |
|
516 | } | |
516 |
|
517 | |||
517 | QString VisualizationGraphWidget::name() const |
|
518 | QString VisualizationGraphWidget::name() const | |
518 | { |
|
519 | { | |
519 | return impl->m_Name; |
|
520 | return impl->m_Name; | |
520 | } |
|
521 | } | |
521 |
|
522 | |||
522 | QMimeData *VisualizationGraphWidget::mimeData(const QPoint &position) const |
|
523 | QMimeData *VisualizationGraphWidget::mimeData(const QPoint &position) const | |
523 | { |
|
524 | { | |
524 | auto mimeData = new QMimeData; |
|
525 | auto mimeData = new QMimeData; | |
525 |
|
526 | |||
526 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(position, plot()); |
|
527 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(position, plot()); | |
527 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones |
|
528 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones | |
528 | && selectionZoneItemUnderCursor) { |
|
529 | && selectionZoneItemUnderCursor) { | |
529 | mimeData->setData(MIME_TYPE_TIME_RANGE, TimeController::mimeDataForTimeRange( |
|
530 | mimeData->setData(MIME_TYPE_TIME_RANGE, TimeController::mimeDataForTimeRange( | |
530 | selectionZoneItemUnderCursor->range())); |
|
531 | selectionZoneItemUnderCursor->range())); | |
531 | mimeData->setData(MIME_TYPE_SELECTION_ZONE, TimeController::mimeDataForTimeRange( |
|
532 | mimeData->setData(MIME_TYPE_SELECTION_ZONE, TimeController::mimeDataForTimeRange( | |
532 | selectionZoneItemUnderCursor->range())); |
|
533 | selectionZoneItemUnderCursor->range())); | |
533 | } |
|
534 | } | |
534 | else { |
|
535 | else { | |
535 | mimeData->setData(MIME_TYPE_GRAPH, QByteArray{}); |
|
536 | mimeData->setData(MIME_TYPE_GRAPH, QByteArray{}); | |
536 |
|
537 | |||
537 | auto timeRangeData = TimeController::mimeDataForTimeRange(graphRange()); |
|
538 | auto timeRangeData = TimeController::mimeDataForTimeRange(graphRange()); | |
538 | mimeData->setData(MIME_TYPE_TIME_RANGE, timeRangeData); |
|
539 | mimeData->setData(MIME_TYPE_TIME_RANGE, timeRangeData); | |
539 | } |
|
540 | } | |
540 |
|
541 | |||
541 | return mimeData; |
|
542 | return mimeData; | |
542 | } |
|
543 | } | |
543 |
|
544 | |||
544 | QPixmap VisualizationGraphWidget::customDragPixmap(const QPoint &dragPosition) |
|
545 | QPixmap VisualizationGraphWidget::customDragPixmap(const QPoint &dragPosition) | |
545 | { |
|
546 | { | |
546 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(dragPosition, plot()); |
|
547 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(dragPosition, plot()); | |
547 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones |
|
548 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones | |
548 | && selectionZoneItemUnderCursor) { |
|
549 | && selectionZoneItemUnderCursor) { | |
549 |
|
550 | |||
550 | auto zoneTopLeft = selectionZoneItemUnderCursor->topLeft->pixelPosition(); |
|
551 | auto zoneTopLeft = selectionZoneItemUnderCursor->topLeft->pixelPosition(); | |
551 | auto zoneBottomRight = selectionZoneItemUnderCursor->bottomRight->pixelPosition(); |
|
552 | auto zoneBottomRight = selectionZoneItemUnderCursor->bottomRight->pixelPosition(); | |
552 |
|
553 | |||
553 | auto zoneSize = QSizeF{qAbs(zoneBottomRight.x() - zoneTopLeft.x()), |
|
554 | auto zoneSize = QSizeF{qAbs(zoneBottomRight.x() - zoneTopLeft.x()), | |
554 | qAbs(zoneBottomRight.y() - zoneTopLeft.y())} |
|
555 | qAbs(zoneBottomRight.y() - zoneTopLeft.y())} | |
555 | .toSize(); |
|
556 | .toSize(); | |
556 |
|
557 | |||
557 | auto pixmap = QPixmap(zoneSize); |
|
558 | auto pixmap = QPixmap(zoneSize); | |
558 | render(&pixmap, QPoint(), QRegion{QRect{zoneTopLeft.toPoint(), zoneSize}}); |
|
559 | render(&pixmap, QPoint(), QRegion{QRect{zoneTopLeft.toPoint(), zoneSize}}); | |
559 |
|
560 | |||
560 | return pixmap; |
|
561 | return pixmap; | |
561 | } |
|
562 | } | |
562 |
|
563 | |||
563 | return QPixmap(); |
|
564 | return QPixmap(); | |
564 | } |
|
565 | } | |
565 |
|
566 | |||
566 | bool VisualizationGraphWidget::isDragAllowed() const |
|
567 | bool VisualizationGraphWidget::isDragAllowed() const | |
567 | { |
|
568 | { | |
568 | return true; |
|
569 | return true; | |
569 | } |
|
570 | } | |
570 |
|
571 | |||
571 | void VisualizationGraphWidget::highlightForMerge(bool highlighted) |
|
572 | void VisualizationGraphWidget::highlightForMerge(bool highlighted) | |
572 | { |
|
573 | { | |
573 | if (highlighted) { |
|
574 | if (highlighted) { | |
574 | plot().setBackground(QBrush(QColor("#BBD5EE"))); |
|
575 | plot().setBackground(QBrush(QColor("#BBD5EE"))); | |
575 | } |
|
576 | } | |
576 | else { |
|
577 | else { | |
577 | plot().setBackground(QBrush(Qt::white)); |
|
578 | plot().setBackground(QBrush(Qt::white)); | |
578 | } |
|
579 | } | |
579 |
|
580 | |||
580 | plot().update(); |
|
581 | plot().update(); | |
581 | } |
|
582 | } | |
582 |
|
583 | |||
583 | void VisualizationGraphWidget::addVerticalCursor(double time) |
|
584 | void VisualizationGraphWidget::addVerticalCursor(double time) | |
584 | { |
|
585 | { | |
585 | impl->m_VerticalCursor->setPosition(time); |
|
586 | impl->m_VerticalCursor->setPosition(time); | |
586 | impl->m_VerticalCursor->setVisible(true); |
|
587 | impl->m_VerticalCursor->setVisible(true); | |
587 |
|
588 | |||
588 | auto text |
|
589 | auto text | |
589 | = DateUtils::dateTime(time).toString(CURSOR_LABELS_DATETIME_FORMAT).replace(' ', '\n'); |
|
590 | = DateUtils::dateTime(time).toString(CURSOR_LABELS_DATETIME_FORMAT).replace(' ', '\n'); | |
590 | impl->m_VerticalCursor->setLabelText(text); |
|
591 | impl->m_VerticalCursor->setLabelText(text); | |
591 | } |
|
592 | } | |
592 |
|
593 | |||
593 | void VisualizationGraphWidget::addVerticalCursorAtViewportPosition(double position) |
|
594 | void VisualizationGraphWidget::addVerticalCursorAtViewportPosition(double position) | |
594 | { |
|
595 | { | |
595 | impl->m_VerticalCursor->setAbsolutePosition(position); |
|
596 | impl->m_VerticalCursor->setAbsolutePosition(position); | |
596 | impl->m_VerticalCursor->setVisible(true); |
|
597 | impl->m_VerticalCursor->setVisible(true); | |
597 |
|
598 | |||
598 | auto axis = plot().axisRect()->axis(QCPAxis::atBottom); |
|
599 | auto axis = plot().axisRect()->axis(QCPAxis::atBottom); | |
599 | auto text |
|
600 | auto text | |
600 | = DateUtils::dateTime(axis->pixelToCoord(position)).toString(CURSOR_LABELS_DATETIME_FORMAT); |
|
601 | = DateUtils::dateTime(axis->pixelToCoord(position)).toString(CURSOR_LABELS_DATETIME_FORMAT); | |
601 | impl->m_VerticalCursor->setLabelText(text); |
|
602 | impl->m_VerticalCursor->setLabelText(text); | |
602 | } |
|
603 | } | |
603 |
|
604 | |||
604 | void VisualizationGraphWidget::removeVerticalCursor() |
|
605 | void VisualizationGraphWidget::removeVerticalCursor() | |
605 | { |
|
606 | { | |
606 | impl->m_VerticalCursor->setVisible(false); |
|
607 | impl->m_VerticalCursor->setVisible(false); | |
607 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
608 | plot().replot(QCustomPlot::rpQueuedReplot); | |
608 | } |
|
609 | } | |
609 |
|
610 | |||
610 | void VisualizationGraphWidget::addHorizontalCursor(double value) |
|
611 | void VisualizationGraphWidget::addHorizontalCursor(double value) | |
611 | { |
|
612 | { | |
612 | impl->m_HorizontalCursor->setPosition(value); |
|
613 | impl->m_HorizontalCursor->setPosition(value); | |
613 | impl->m_HorizontalCursor->setVisible(true); |
|
614 | impl->m_HorizontalCursor->setVisible(true); | |
614 | impl->m_HorizontalCursor->setLabelText(QString::number(value)); |
|
615 | impl->m_HorizontalCursor->setLabelText(QString::number(value)); | |
615 | } |
|
616 | } | |
616 |
|
617 | |||
617 | void VisualizationGraphWidget::addHorizontalCursorAtViewportPosition(double position) |
|
618 | void VisualizationGraphWidget::addHorizontalCursorAtViewportPosition(double position) | |
618 | { |
|
619 | { | |
619 | impl->m_HorizontalCursor->setAbsolutePosition(position); |
|
620 | impl->m_HorizontalCursor->setAbsolutePosition(position); | |
620 | impl->m_HorizontalCursor->setVisible(true); |
|
621 | impl->m_HorizontalCursor->setVisible(true); | |
621 |
|
622 | |||
622 | auto axis = plot().axisRect()->axis(QCPAxis::atLeft); |
|
623 | auto axis = plot().axisRect()->axis(QCPAxis::atLeft); | |
623 | impl->m_HorizontalCursor->setLabelText(QString::number(axis->pixelToCoord(position))); |
|
624 | impl->m_HorizontalCursor->setLabelText(QString::number(axis->pixelToCoord(position))); | |
624 | } |
|
625 | } | |
625 |
|
626 | |||
626 | void VisualizationGraphWidget::removeHorizontalCursor() |
|
627 | void VisualizationGraphWidget::removeHorizontalCursor() | |
627 | { |
|
628 | { | |
628 | impl->m_HorizontalCursor->setVisible(false); |
|
629 | impl->m_HorizontalCursor->setVisible(false); | |
629 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
630 | plot().replot(QCustomPlot::rpQueuedReplot); | |
630 | } |
|
631 | } | |
631 |
|
632 | |||
632 | void VisualizationGraphWidget::closeEvent(QCloseEvent *event) |
|
633 | void VisualizationGraphWidget::closeEvent(QCloseEvent *event) | |
633 | { |
|
634 | { | |
634 | Q_UNUSED(event); |
|
635 | Q_UNUSED(event); | |
635 |
|
636 | |||
636 | for (auto i : impl->m_SelectionZones) { |
|
637 | for (auto i : impl->m_SelectionZones) { | |
637 | parentVisualizationWidget()->selectionZoneManager().setSelected(i, false); |
|
638 | parentVisualizationWidget()->selectionZoneManager().setSelected(i, false); | |
638 | } |
|
639 | } | |
639 |
|
640 | |||
640 | // Prevents that all variables will be removed from graph when it will be closed |
|
641 | // Prevents that all variables will be removed from graph when it will be closed | |
641 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { |
|
642 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { | |
642 | emit variableAboutToBeRemoved(variableEntry.first); |
|
643 | emit variableAboutToBeRemoved(variableEntry.first); | |
643 | } |
|
644 | } | |
644 | } |
|
645 | } | |
645 |
|
646 | |||
646 | void VisualizationGraphWidget::enterEvent(QEvent *event) |
|
647 | void VisualizationGraphWidget::enterEvent(QEvent *event) | |
647 | { |
|
648 | { | |
648 | Q_UNUSED(event); |
|
649 | Q_UNUSED(event); | |
649 | impl->m_RenderingDelegate->showGraphOverlay(true); |
|
650 | impl->m_RenderingDelegate->showGraphOverlay(true); | |
650 | } |
|
651 | } | |
651 |
|
652 | |||
652 | void VisualizationGraphWidget::leaveEvent(QEvent *event) |
|
653 | void VisualizationGraphWidget::leaveEvent(QEvent *event) | |
653 | { |
|
654 | { | |
654 | Q_UNUSED(event); |
|
655 | Q_UNUSED(event); | |
655 | impl->m_RenderingDelegate->showGraphOverlay(false); |
|
656 | impl->m_RenderingDelegate->showGraphOverlay(false); | |
656 |
|
657 | |||
657 | if (auto parentZone = parentZoneWidget()) { |
|
658 | if (auto parentZone = parentZoneWidget()) { | |
658 | parentZone->notifyMouseLeaveGraph(this); |
|
659 | parentZone->notifyMouseLeaveGraph(this); | |
659 | } |
|
660 | } | |
660 | else { |
|
661 | else { | |
661 | qCWarning(LOG_VisualizationGraphWidget()) << "leaveEvent: No parent zone widget"; |
|
662 | qCWarning(LOG_VisualizationGraphWidget()) << "leaveEvent: No parent zone widget"; | |
662 | } |
|
663 | } | |
663 |
|
664 | |||
664 | if (impl->m_HoveredZone) { |
|
665 | if (impl->m_HoveredZone) { | |
665 | impl->m_HoveredZone->setHovered(false); |
|
666 | impl->m_HoveredZone->setHovered(false); | |
666 | impl->m_HoveredZone = nullptr; |
|
667 | impl->m_HoveredZone = nullptr; | |
667 | } |
|
668 | } | |
668 | } |
|
669 | } | |
669 |
|
670 | |||
670 | QCustomPlot &VisualizationGraphWidget::plot() const noexcept |
|
671 | QCustomPlot &VisualizationGraphWidget::plot() const noexcept | |
671 | { |
|
672 | { | |
672 | return *ui->widget; |
|
673 | return *ui->widget; | |
673 | } |
|
674 | } | |
674 |
|
675 | |||
675 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept |
|
676 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept | |
676 | { |
|
677 | { | |
677 | QMenu graphMenu{}; |
|
678 | QMenu graphMenu{}; | |
678 |
|
679 | |||
679 | // Iterates on variables (unique keys) |
|
680 | // Iterates on variables (unique keys) | |
680 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(), |
|
681 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(), | |
681 | end = impl->m_VariableToPlotMultiMap.cend(); |
|
682 | end = impl->m_VariableToPlotMultiMap.cend(); | |
682 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { |
|
683 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { | |
683 | // 'Remove variable' action |
|
684 | // 'Remove variable' action | |
684 | graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()), |
|
685 | graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()), | |
685 | [ this, var = it->first ]() { removeVariable(var); }); |
|
686 | [ this, var = it->first ]() { removeVariable(var); }); | |
686 | } |
|
687 | } | |
687 |
|
688 | |||
688 | if (!impl->m_ZoomStack.isEmpty()) { |
|
689 | if (!impl->m_ZoomStack.isEmpty()) { | |
689 | if (!graphMenu.isEmpty()) { |
|
690 | if (!graphMenu.isEmpty()) { | |
690 | graphMenu.addSeparator(); |
|
691 | graphMenu.addSeparator(); | |
691 | } |
|
692 | } | |
692 |
|
693 | |||
693 | graphMenu.addAction(tr("Undo Zoom"), [this]() { undoZoom(); }); |
|
694 | graphMenu.addAction(tr("Undo Zoom"), [this]() { undoZoom(); }); | |
694 | } |
|
695 | } | |
695 |
|
696 | |||
696 | // Selection Zone Actions |
|
697 | // Selection Zone Actions | |
697 | auto selectionZoneItem = impl->selectionZoneAt(pos, plot()); |
|
698 | auto selectionZoneItem = impl->selectionZoneAt(pos, plot()); | |
698 | if (selectionZoneItem) { |
|
699 | if (selectionZoneItem) { | |
699 | auto selectedItems = parentVisualizationWidget()->selectionZoneManager().selectedItems(); |
|
700 | auto selectedItems = parentVisualizationWidget()->selectionZoneManager().selectedItems(); | |
700 | selectedItems.removeAll(selectionZoneItem); |
|
701 | selectedItems.removeAll(selectionZoneItem); | |
701 | selectedItems.prepend(selectionZoneItem); // Put the current selection zone first |
|
702 | selectedItems.prepend(selectionZoneItem); // Put the current selection zone first | |
702 |
|
703 | |||
703 | auto zoneActions = sqpApp->actionsGuiController().selectionZoneActions(); |
|
704 | auto zoneActions = sqpApp->actionsGuiController().selectionZoneActions(); | |
704 | if (!zoneActions.isEmpty() && !graphMenu.isEmpty()) { |
|
705 | if (!zoneActions.isEmpty() && !graphMenu.isEmpty()) { | |
705 | graphMenu.addSeparator(); |
|
706 | graphMenu.addSeparator(); | |
706 | } |
|
707 | } | |
707 |
|
708 | |||
708 | QHash<QString, QMenu *> subMenus; |
|
709 | QHash<QString, QMenu *> subMenus; | |
709 | QHash<QString, bool> subMenusEnabled; |
|
710 | QHash<QString, bool> subMenusEnabled; | |
|
711 | QHash<QString, FilteringAction *> filteredMenu; | |||
710 |
|
712 | |||
711 | for (auto zoneAction : zoneActions) { |
|
713 | for (auto zoneAction : zoneActions) { | |
712 |
|
714 | |||
713 | auto isEnabled = zoneAction->isEnabled(selectedItems); |
|
715 | auto isEnabled = zoneAction->isEnabled(selectedItems); | |
714 |
|
716 | |||
715 | auto menu = &graphMenu; |
|
717 | auto menu = &graphMenu; | |
|
718 | QString menuPath; | |||
716 | for (auto subMenuName : zoneAction->subMenuList()) { |
|
719 | for (auto subMenuName : zoneAction->subMenuList()) { | |
717 | if (!subMenus.contains(subMenuName)) { |
|
720 | menuPath += '/'; | |
|
721 | menuPath += subMenuName; | |||
|
722 | ||||
|
723 | if (!subMenus.contains(menuPath)) { | |||
718 | menu = menu->addMenu(subMenuName); |
|
724 | menu = menu->addMenu(subMenuName); | |
719 |
subMenus[ |
|
725 | subMenus[menuPath] = menu; | |
720 |
subMenusEnabled[ |
|
726 | subMenusEnabled[menuPath] = isEnabled; | |
721 | } |
|
727 | } | |
722 | else { |
|
728 | else { | |
723 |
menu = subMenus.value( |
|
729 | menu = subMenus.value(menuPath); | |
724 | if (isEnabled) { |
|
730 | if (isEnabled) { | |
725 | // The sub menu is enabled if at least one of its actions is enabled |
|
731 | // The sub menu is enabled if at least one of its actions is enabled | |
726 |
subMenusEnabled[ |
|
732 | subMenusEnabled[menuPath] = true; | |
|
733 | } | |||
|
734 | } | |||
727 |
|
|
735 | } | |
|
736 | ||||
|
737 | FilteringAction *filterAction = nullptr; | |||
|
738 | if (sqpApp->actionsGuiController().isMenuFiltered(zoneAction->subMenuList())) { | |||
|
739 | filterAction = filteredMenu.value(menuPath); | |||
|
740 | if (!filterAction) { | |||
|
741 | filterAction = new FilteringAction{this}; | |||
|
742 | filteredMenu[menuPath] = filterAction; | |||
|
743 | menu->addAction(filterAction); | |||
728 | } |
|
744 | } | |
729 | } |
|
745 | } | |
730 |
|
746 | |||
731 | auto action = menu->addAction(zoneAction->name()); |
|
747 | auto action = menu->addAction(zoneAction->name()); | |
732 | action->setEnabled(isEnabled); |
|
748 | action->setEnabled(isEnabled); | |
733 | action->setShortcut(zoneAction->displayedShortcut()); |
|
749 | action->setShortcut(zoneAction->displayedShortcut()); | |
734 | QObject::connect(action, &QAction::triggered, |
|
750 | QObject::connect(action, &QAction::triggered, | |
735 | [zoneAction, selectedItems]() { zoneAction->execute(selectedItems); }); |
|
751 | [zoneAction, selectedItems]() { zoneAction->execute(selectedItems); }); | |
|
752 | ||||
|
753 | if (filterAction && zoneAction->isFilteringAllowed()) { | |||
|
754 | filterAction->addActionToFilter(action); | |||
|
755 | } | |||
736 | } |
|
756 | } | |
737 |
|
757 | |||
738 | for (auto it = subMenus.cbegin(); it != subMenus.cend(); ++it) { |
|
758 | for (auto it = subMenus.cbegin(); it != subMenus.cend(); ++it) { | |
739 | it.value()->setEnabled(subMenusEnabled[it.key()]); |
|
759 | it.value()->setEnabled(subMenusEnabled[it.key()]); | |
740 | } |
|
760 | } | |
741 | } |
|
761 | } | |
742 |
|
762 | |||
743 | if (!graphMenu.isEmpty()) { |
|
763 | if (!graphMenu.isEmpty()) { | |
744 | graphMenu.exec(QCursor::pos()); |
|
764 | graphMenu.exec(QCursor::pos()); | |
745 | } |
|
765 | } | |
746 | } |
|
766 | } | |
747 |
|
767 | |||
748 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) |
|
768 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) | |
749 | { |
|
769 | { | |
750 | qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::onRangeChanged") |
|
770 | qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::onRangeChanged") | |
751 | << QThread::currentThread()->objectName() << "DoAcqui" |
|
771 | << QThread::currentThread()->objectName() << "DoAcqui" | |
752 | << impl->m_Flags.testFlag(GraphFlag::EnableAcquisition); |
|
772 | << impl->m_Flags.testFlag(GraphFlag::EnableAcquisition); | |
753 |
|
773 | |||
754 | auto graphRange = SqpRange{t1.lower, t1.upper}; |
|
774 | auto graphRange = SqpRange{t1.lower, t1.upper}; | |
755 | auto oldGraphRange = SqpRange{t2.lower, t2.upper}; |
|
775 | auto oldGraphRange = SqpRange{t2.lower, t2.upper}; | |
756 |
|
776 | |||
757 | if (impl->m_Flags.testFlag(GraphFlag::EnableAcquisition)) { |
|
777 | if (impl->m_Flags.testFlag(GraphFlag::EnableAcquisition)) { | |
758 | QVector<std::shared_ptr<Variable> > variableUnderGraphVector; |
|
778 | QVector<std::shared_ptr<Variable> > variableUnderGraphVector; | |
759 |
|
779 | |||
760 | for (auto it = impl->m_VariableToPlotMultiMap.begin(), |
|
780 | for (auto it = impl->m_VariableToPlotMultiMap.begin(), | |
761 | end = impl->m_VariableToPlotMultiMap.end(); |
|
781 | end = impl->m_VariableToPlotMultiMap.end(); | |
762 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { |
|
782 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { | |
763 | variableUnderGraphVector.push_back(it->first); |
|
783 | variableUnderGraphVector.push_back(it->first); | |
764 | } |
|
784 | } | |
765 | emit requestDataLoading(std::move(variableUnderGraphVector), graphRange, |
|
785 | emit requestDataLoading(std::move(variableUnderGraphVector), graphRange, | |
766 | !impl->m_IsCalibration); |
|
786 | !impl->m_IsCalibration); | |
767 | } |
|
787 | } | |
768 |
|
788 | |||
769 | if (impl->m_Flags.testFlag(GraphFlag::EnableSynchronization) && !impl->m_IsCalibration) { |
|
789 | if (impl->m_Flags.testFlag(GraphFlag::EnableSynchronization) && !impl->m_IsCalibration) { | |
770 | qCDebug(LOG_VisualizationGraphWidget()) |
|
790 | qCDebug(LOG_VisualizationGraphWidget()) | |
771 | << tr("TORM: VisualizationGraphWidget::Synchronize notify !!") |
|
791 | << tr("TORM: VisualizationGraphWidget::Synchronize notify !!") | |
772 | << QThread::currentThread()->objectName() << graphRange << oldGraphRange; |
|
792 | << QThread::currentThread()->objectName() << graphRange << oldGraphRange; | |
773 | emit synchronize(graphRange, oldGraphRange); |
|
793 | emit synchronize(graphRange, oldGraphRange); | |
774 | } |
|
794 | } | |
775 |
|
795 | |||
776 | auto pos = mapFromGlobal(QCursor::pos()); |
|
796 | auto pos = mapFromGlobal(QCursor::pos()); | |
777 | auto axisPos = impl->posToAxisPos(pos, plot()); |
|
797 | auto axisPos = impl->posToAxisPos(pos, plot()); | |
778 | if (auto parentZone = parentZoneWidget()) { |
|
798 | if (auto parentZone = parentZoneWidget()) { | |
779 | if (impl->pointIsInAxisRect(axisPos, plot())) { |
|
799 | if (impl->pointIsInAxisRect(axisPos, plot())) { | |
780 | parentZone->notifyMouseMoveInGraph(pos, axisPos, this); |
|
800 | parentZone->notifyMouseMoveInGraph(pos, axisPos, this); | |
781 | } |
|
801 | } | |
782 | else { |
|
802 | else { | |
783 | parentZone->notifyMouseLeaveGraph(this); |
|
803 | parentZone->notifyMouseLeaveGraph(this); | |
784 | } |
|
804 | } | |
785 | } |
|
805 | } | |
786 | else { |
|
806 | else { | |
787 | qCWarning(LOG_VisualizationGraphWidget()) << "onMouseMove: No parent zone widget"; |
|
807 | qCWarning(LOG_VisualizationGraphWidget()) << "onMouseMove: No parent zone widget"; | |
788 | } |
|
808 | } | |
789 |
|
809 | |||
790 | // Quits calibration |
|
810 | // Quits calibration | |
791 | impl->m_IsCalibration = false; |
|
811 | impl->m_IsCalibration = false; | |
792 | } |
|
812 | } | |
793 |
|
813 | |||
794 | void VisualizationGraphWidget::onMouseDoubleClick(QMouseEvent *event) noexcept |
|
814 | void VisualizationGraphWidget::onMouseDoubleClick(QMouseEvent *event) noexcept | |
795 | { |
|
815 | { | |
796 | impl->m_RenderingDelegate->onMouseDoubleClick(event); |
|
816 | impl->m_RenderingDelegate->onMouseDoubleClick(event); | |
797 | } |
|
817 | } | |
798 |
|
818 | |||
799 | void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept |
|
819 | void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept | |
800 | { |
|
820 | { | |
801 | // Handles plot rendering when mouse is moving |
|
821 | // Handles plot rendering when mouse is moving | |
802 | impl->m_RenderingDelegate->onMouseMove(event); |
|
822 | impl->m_RenderingDelegate->onMouseMove(event); | |
803 |
|
823 | |||
804 | auto axisPos = impl->posToAxisPos(event->pos(), plot()); |
|
824 | auto axisPos = impl->posToAxisPos(event->pos(), plot()); | |
805 |
|
825 | |||
806 | // Zoom box and zone drawing |
|
826 | // Zoom box and zone drawing | |
807 | if (impl->m_DrawingZoomRect) { |
|
827 | if (impl->m_DrawingZoomRect) { | |
808 | impl->m_DrawingZoomRect->bottomRight->setCoords(axisPos); |
|
828 | impl->m_DrawingZoomRect->bottomRight->setCoords(axisPos); | |
809 | } |
|
829 | } | |
810 | else if (impl->m_DrawingZone) { |
|
830 | else if (impl->m_DrawingZone) { | |
811 | impl->m_DrawingZone->setEnd(axisPos.x()); |
|
831 | impl->m_DrawingZone->setEnd(axisPos.x()); | |
812 | } |
|
832 | } | |
813 |
|
833 | |||
814 | // Cursor |
|
834 | // Cursor | |
815 | if (auto parentZone = parentZoneWidget()) { |
|
835 | if (auto parentZone = parentZoneWidget()) { | |
816 | if (impl->pointIsInAxisRect(axisPos, plot())) { |
|
836 | if (impl->pointIsInAxisRect(axisPos, plot())) { | |
817 | parentZone->notifyMouseMoveInGraph(event->pos(), axisPos, this); |
|
837 | parentZone->notifyMouseMoveInGraph(event->pos(), axisPos, this); | |
818 | } |
|
838 | } | |
819 | else { |
|
839 | else { | |
820 | parentZone->notifyMouseLeaveGraph(this); |
|
840 | parentZone->notifyMouseLeaveGraph(this); | |
821 | } |
|
841 | } | |
822 | } |
|
842 | } | |
823 | else { |
|
843 | else { | |
824 | qCWarning(LOG_VisualizationGraphWidget()) << "onMouseMove: No parent zone widget"; |
|
844 | qCWarning(LOG_VisualizationGraphWidget()) << "onMouseMove: No parent zone widget"; | |
825 | } |
|
845 | } | |
826 |
|
846 | |||
827 | // Search for the selection zone under the mouse |
|
847 | // Search for the selection zone under the mouse | |
828 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); |
|
848 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); | |
829 | if (selectionZoneItemUnderCursor && !impl->m_DrawingZone |
|
849 | if (selectionZoneItemUnderCursor && !impl->m_DrawingZone | |
830 | && sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones) { |
|
850 | && sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones) { | |
831 |
|
851 | |||
832 | // Sets the appropriate cursor shape |
|
852 | // Sets the appropriate cursor shape | |
833 | auto cursorShape = selectionZoneItemUnderCursor->curshorShapeForPosition(event->pos()); |
|
853 | auto cursorShape = selectionZoneItemUnderCursor->curshorShapeForPosition(event->pos()); | |
834 | setCursor(cursorShape); |
|
854 | setCursor(cursorShape); | |
835 |
|
855 | |||
836 | // Manages the hovered zone |
|
856 | // Manages the hovered zone | |
837 | if (selectionZoneItemUnderCursor != impl->m_HoveredZone) { |
|
857 | if (selectionZoneItemUnderCursor != impl->m_HoveredZone) { | |
838 | if (impl->m_HoveredZone) { |
|
858 | if (impl->m_HoveredZone) { | |
839 | impl->m_HoveredZone->setHovered(false); |
|
859 | impl->m_HoveredZone->setHovered(false); | |
840 | } |
|
860 | } | |
841 | selectionZoneItemUnderCursor->setHovered(true); |
|
861 | selectionZoneItemUnderCursor->setHovered(true); | |
842 | impl->m_HoveredZone = selectionZoneItemUnderCursor; |
|
862 | impl->m_HoveredZone = selectionZoneItemUnderCursor; | |
843 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
863 | plot().replot(QCustomPlot::rpQueuedReplot); | |
844 | } |
|
864 | } | |
845 | } |
|
865 | } | |
846 | else { |
|
866 | else { | |
847 | // There is no zone under the mouse or the interaction mode is not "selection zones" |
|
867 | // There is no zone under the mouse or the interaction mode is not "selection zones" | |
848 | if (impl->m_HoveredZone) { |
|
868 | if (impl->m_HoveredZone) { | |
849 | impl->m_HoveredZone->setHovered(false); |
|
869 | impl->m_HoveredZone->setHovered(false); | |
850 | impl->m_HoveredZone = nullptr; |
|
870 | impl->m_HoveredZone = nullptr; | |
851 | } |
|
871 | } | |
852 |
|
872 | |||
853 | setCursor(Qt::ArrowCursor); |
|
873 | setCursor(Qt::ArrowCursor); | |
854 | } |
|
874 | } | |
855 |
|
875 | |||
856 | impl->m_HasMovedMouse = true; |
|
876 | impl->m_HasMovedMouse = true; | |
857 | VisualizationDragWidget::mouseMoveEvent(event); |
|
877 | VisualizationDragWidget::mouseMoveEvent(event); | |
858 | } |
|
878 | } | |
859 |
|
879 | |||
860 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept |
|
880 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept | |
861 | { |
|
881 | { | |
862 | auto value = event->angleDelta().x() + event->angleDelta().y(); |
|
882 | auto value = event->angleDelta().x() + event->angleDelta().y(); | |
863 | if (value != 0) { |
|
883 | if (value != 0) { | |
864 |
|
884 | |||
865 | auto direction = value > 0 ? 1.0 : -1.0; |
|
885 | auto direction = value > 0 ? 1.0 : -1.0; | |
866 | auto isZoomX = event->modifiers().testFlag(HORIZONTAL_ZOOM_MODIFIER); |
|
886 | auto isZoomX = event->modifiers().testFlag(HORIZONTAL_ZOOM_MODIFIER); | |
867 | auto isZoomY = event->modifiers().testFlag(VERTICAL_ZOOM_MODIFIER); |
|
887 | auto isZoomY = event->modifiers().testFlag(VERTICAL_ZOOM_MODIFIER); | |
868 | impl->m_IsCalibration = event->modifiers().testFlag(VERTICAL_PAN_MODIFIER); |
|
888 | impl->m_IsCalibration = event->modifiers().testFlag(VERTICAL_PAN_MODIFIER); | |
869 |
|
889 | |||
870 | auto zoomOrientations = QFlags<Qt::Orientation>{}; |
|
890 | auto zoomOrientations = QFlags<Qt::Orientation>{}; | |
871 | zoomOrientations.setFlag(Qt::Horizontal, isZoomX); |
|
891 | zoomOrientations.setFlag(Qt::Horizontal, isZoomX); | |
872 | zoomOrientations.setFlag(Qt::Vertical, isZoomY); |
|
892 | zoomOrientations.setFlag(Qt::Vertical, isZoomY); | |
873 |
|
893 | |||
874 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); |
|
894 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); | |
875 |
|
895 | |||
876 | if (!isZoomX && !isZoomY) { |
|
896 | if (!isZoomX && !isZoomY) { | |
877 | auto axis = plot().axisRect()->axis(QCPAxis::atBottom); |
|
897 | auto axis = plot().axisRect()->axis(QCPAxis::atBottom); | |
878 | auto diff = direction * (axis->range().size() * (PAN_SPEED / 100.0)); |
|
898 | auto diff = direction * (axis->range().size() * (PAN_SPEED / 100.0)); | |
879 |
|
899 | |||
880 | axis->setRange(axis->range() + diff); |
|
900 | axis->setRange(axis->range() + diff); | |
881 |
|
901 | |||
882 | if (plot().noAntialiasingOnDrag()) { |
|
902 | if (plot().noAntialiasingOnDrag()) { | |
883 | plot().setNotAntialiasedElements(QCP::aeAll); |
|
903 | plot().setNotAntialiasedElements(QCP::aeAll); | |
884 | } |
|
904 | } | |
885 |
|
905 | |||
886 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
906 | plot().replot(QCustomPlot::rpQueuedReplot); | |
887 | } |
|
907 | } | |
888 | } |
|
908 | } | |
889 | } |
|
909 | } | |
890 |
|
910 | |||
891 | void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept |
|
911 | void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept | |
892 | { |
|
912 | { | |
893 | auto isDragDropClick = event->modifiers().testFlag(DRAG_DROP_MODIFIER); |
|
913 | auto isDragDropClick = event->modifiers().testFlag(DRAG_DROP_MODIFIER); | |
894 | auto isSelectionZoneMode |
|
914 | auto isSelectionZoneMode | |
895 | = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones; |
|
915 | = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones; | |
896 | auto isLeftClick = event->buttons().testFlag(Qt::LeftButton); |
|
916 | auto isLeftClick = event->buttons().testFlag(Qt::LeftButton); | |
897 |
|
917 | |||
898 | if (!isDragDropClick && isLeftClick) { |
|
918 | if (!isDragDropClick && isLeftClick) { | |
899 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::ZoomBox) { |
|
919 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::ZoomBox) { | |
900 | // Starts a zoom box |
|
920 | // Starts a zoom box | |
901 | impl->startDrawingRect(event->pos(), plot()); |
|
921 | impl->startDrawingRect(event->pos(), plot()); | |
902 | } |
|
922 | } | |
903 | else if (isSelectionZoneMode && impl->m_DrawingZone == nullptr) { |
|
923 | else if (isSelectionZoneMode && impl->m_DrawingZone == nullptr) { | |
904 | // Starts a new selection zone |
|
924 | // Starts a new selection zone | |
905 | auto zoneAtPos = impl->selectionZoneAt(event->pos(), plot()); |
|
925 | auto zoneAtPos = impl->selectionZoneAt(event->pos(), plot()); | |
906 | if (!zoneAtPos) { |
|
926 | if (!zoneAtPos) { | |
907 | impl->startDrawingZone(event->pos(), this); |
|
927 | impl->startDrawingZone(event->pos(), this); | |
908 | } |
|
928 | } | |
909 | } |
|
929 | } | |
910 | } |
|
930 | } | |
911 |
|
931 | |||
912 | // Allows mouse panning only in default mode |
|
932 | // Allows mouse panning only in default mode | |
913 | plot().setInteraction(QCP::iRangeDrag, sqpApp->plotsInteractionMode() |
|
933 | plot().setInteraction(QCP::iRangeDrag, sqpApp->plotsInteractionMode() | |
914 | == SqpApplication::PlotsInteractionMode::None |
|
934 | == SqpApplication::PlotsInteractionMode::None | |
915 | && !isDragDropClick); |
|
935 | && !isDragDropClick); | |
916 |
|
936 | |||
917 | // Allows zone edition only in selection zone mode without drag&drop |
|
937 | // Allows zone edition only in selection zone mode without drag&drop | |
918 | impl->setSelectionZonesEditionEnabled(isSelectionZoneMode && !isDragDropClick); |
|
938 | impl->setSelectionZonesEditionEnabled(isSelectionZoneMode && !isDragDropClick); | |
919 |
|
939 | |||
920 | // Selection / Deselection |
|
940 | // Selection / Deselection | |
921 | if (isSelectionZoneMode) { |
|
941 | if (isSelectionZoneMode) { | |
922 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); |
|
942 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); | |
923 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); |
|
943 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); | |
924 |
|
944 | |||
925 |
|
945 | |||
926 | if (selectionZoneItemUnderCursor && !selectionZoneItemUnderCursor->selected() |
|
946 | if (selectionZoneItemUnderCursor && !selectionZoneItemUnderCursor->selected() | |
927 | && !isMultiSelectionClick) { |
|
947 | && !isMultiSelectionClick) { | |
928 | parentVisualizationWidget()->selectionZoneManager().select( |
|
948 | parentVisualizationWidget()->selectionZoneManager().select( | |
929 | {selectionZoneItemUnderCursor}); |
|
949 | {selectionZoneItemUnderCursor}); | |
930 | } |
|
950 | } | |
931 | else if (!selectionZoneItemUnderCursor && !isMultiSelectionClick && isLeftClick) { |
|
951 | else if (!selectionZoneItemUnderCursor && !isMultiSelectionClick && isLeftClick) { | |
932 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); |
|
952 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); | |
933 | } |
|
953 | } | |
934 | else { |
|
954 | else { | |
935 | // No selection change |
|
955 | // No selection change | |
936 | } |
|
956 | } | |
937 |
|
957 | |||
938 | if (selectionZoneItemUnderCursor && isLeftClick) { |
|
958 | if (selectionZoneItemUnderCursor && isLeftClick) { | |
939 | selectionZoneItemUnderCursor->setAssociatedEditedZones( |
|
959 | selectionZoneItemUnderCursor->setAssociatedEditedZones( | |
940 | parentVisualizationWidget()->selectionZoneManager().selectedItems()); |
|
960 | parentVisualizationWidget()->selectionZoneManager().selectedItems()); | |
941 | } |
|
961 | } | |
942 | } |
|
962 | } | |
943 |
|
963 | |||
944 |
|
964 | |||
945 | impl->m_HasMovedMouse = false; |
|
965 | impl->m_HasMovedMouse = false; | |
946 | VisualizationDragWidget::mousePressEvent(event); |
|
966 | VisualizationDragWidget::mousePressEvent(event); | |
947 | } |
|
967 | } | |
948 |
|
968 | |||
949 | void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept |
|
969 | void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept | |
950 | { |
|
970 | { | |
951 | if (impl->m_DrawingZoomRect) { |
|
971 | if (impl->m_DrawingZoomRect) { | |
952 |
|
972 | |||
953 | auto axisX = plot().axisRect()->axis(QCPAxis::atBottom); |
|
973 | auto axisX = plot().axisRect()->axis(QCPAxis::atBottom); | |
954 | auto axisY = plot().axisRect()->axis(QCPAxis::atLeft); |
|
974 | auto axisY = plot().axisRect()->axis(QCPAxis::atLeft); | |
955 |
|
975 | |||
956 | auto newAxisXRange = QCPRange{impl->m_DrawingZoomRect->topLeft->coords().x(), |
|
976 | auto newAxisXRange = QCPRange{impl->m_DrawingZoomRect->topLeft->coords().x(), | |
957 | impl->m_DrawingZoomRect->bottomRight->coords().x()}; |
|
977 | impl->m_DrawingZoomRect->bottomRight->coords().x()}; | |
958 |
|
978 | |||
959 | auto newAxisYRange = QCPRange{impl->m_DrawingZoomRect->topLeft->coords().y(), |
|
979 | auto newAxisYRange = QCPRange{impl->m_DrawingZoomRect->topLeft->coords().y(), | |
960 | impl->m_DrawingZoomRect->bottomRight->coords().y()}; |
|
980 | impl->m_DrawingZoomRect->bottomRight->coords().y()}; | |
961 |
|
981 | |||
962 | impl->removeDrawingRect(plot()); |
|
982 | impl->removeDrawingRect(plot()); | |
963 |
|
983 | |||
964 | if (newAxisXRange.size() > axisX->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0) |
|
984 | if (newAxisXRange.size() > axisX->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0) | |
965 | && newAxisYRange.size() > axisY->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0)) { |
|
985 | && newAxisYRange.size() > axisY->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0)) { | |
966 | impl->m_ZoomStack.push(qMakePair(axisX->range(), axisY->range())); |
|
986 | impl->m_ZoomStack.push(qMakePair(axisX->range(), axisY->range())); | |
967 | axisX->setRange(newAxisXRange); |
|
987 | axisX->setRange(newAxisXRange); | |
968 | axisY->setRange(newAxisYRange); |
|
988 | axisY->setRange(newAxisYRange); | |
969 |
|
989 | |||
970 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
990 | plot().replot(QCustomPlot::rpQueuedReplot); | |
971 | } |
|
991 | } | |
972 | } |
|
992 | } | |
973 |
|
993 | |||
974 | impl->endDrawingZone(this); |
|
994 | impl->endDrawingZone(this); | |
975 |
|
995 | |||
976 | // Selection / Deselection |
|
996 | // Selection / Deselection | |
977 | auto isSelectionZoneMode |
|
997 | auto isSelectionZoneMode | |
978 | = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones; |
|
998 | = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones; | |
979 | if (isSelectionZoneMode) { |
|
999 | if (isSelectionZoneMode) { | |
980 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); |
|
1000 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); | |
981 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); |
|
1001 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); | |
982 | if (selectionZoneItemUnderCursor && event->button() == Qt::LeftButton |
|
1002 | if (selectionZoneItemUnderCursor && event->button() == Qt::LeftButton | |
983 | && !impl->m_HasMovedMouse) { |
|
1003 | && !impl->m_HasMovedMouse) { | |
984 |
|
1004 | |||
985 | auto zonesUnderCursor = impl->selectionZonesAt(event->pos(), plot()); |
|
1005 | auto zonesUnderCursor = impl->selectionZonesAt(event->pos(), plot()); | |
986 | if (zonesUnderCursor.count() > 1) { |
|
1006 | if (zonesUnderCursor.count() > 1) { | |
987 | // There are multiple zones under the mouse. |
|
1007 | // There are multiple zones under the mouse. | |
988 | // Performs the selection with a selection dialog. |
|
1008 | // Performs the selection with a selection dialog. | |
989 | VisualizationMultiZoneSelectionDialog dialog{this}; |
|
1009 | VisualizationMultiZoneSelectionDialog dialog{this}; | |
990 | dialog.setZones(zonesUnderCursor); |
|
1010 | dialog.setZones(zonesUnderCursor); | |
991 | dialog.move(mapToGlobal(event->pos() - QPoint(dialog.width() / 2, 20))); |
|
1011 | dialog.move(mapToGlobal(event->pos() - QPoint(dialog.width() / 2, 20))); | |
992 | dialog.activateWindow(); |
|
1012 | dialog.activateWindow(); | |
993 | dialog.raise(); |
|
1013 | dialog.raise(); | |
994 | if (dialog.exec() == QDialog::Accepted) { |
|
1014 | if (dialog.exec() == QDialog::Accepted) { | |
995 | auto selection = dialog.selectedZones(); |
|
1015 | auto selection = dialog.selectedZones(); | |
996 |
|
1016 | |||
997 | if (!isMultiSelectionClick) { |
|
1017 | if (!isMultiSelectionClick) { | |
998 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); |
|
1018 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); | |
999 | } |
|
1019 | } | |
1000 |
|
1020 | |||
1001 | for (auto it = selection.cbegin(); it != selection.cend(); ++it) { |
|
1021 | for (auto it = selection.cbegin(); it != selection.cend(); ++it) { | |
1002 | auto zone = it.key(); |
|
1022 | auto zone = it.key(); | |
1003 | auto isSelected = it.value(); |
|
1023 | auto isSelected = it.value(); | |
1004 | parentVisualizationWidget()->selectionZoneManager().setSelected(zone, |
|
1024 | parentVisualizationWidget()->selectionZoneManager().setSelected(zone, | |
1005 | isSelected); |
|
1025 | isSelected); | |
1006 |
|
1026 | |||
1007 | if (isSelected) { |
|
1027 | if (isSelected) { | |
1008 | // Puts the zone on top of the stack so it can be moved or resized |
|
1028 | // Puts the zone on top of the stack so it can be moved or resized | |
1009 | impl->moveSelectionZoneOnTop(zone, plot()); |
|
1029 | impl->moveSelectionZoneOnTop(zone, plot()); | |
1010 | } |
|
1030 | } | |
1011 | } |
|
1031 | } | |
1012 | } |
|
1032 | } | |
1013 | } |
|
1033 | } | |
1014 | else { |
|
1034 | else { | |
1015 | if (!isMultiSelectionClick) { |
|
1035 | if (!isMultiSelectionClick) { | |
1016 | parentVisualizationWidget()->selectionZoneManager().select( |
|
1036 | parentVisualizationWidget()->selectionZoneManager().select( | |
1017 | {selectionZoneItemUnderCursor}); |
|
1037 | {selectionZoneItemUnderCursor}); | |
1018 | impl->moveSelectionZoneOnTop(selectionZoneItemUnderCursor, plot()); |
|
1038 | impl->moveSelectionZoneOnTop(selectionZoneItemUnderCursor, plot()); | |
1019 | } |
|
1039 | } | |
1020 | else { |
|
1040 | else { | |
1021 | parentVisualizationWidget()->selectionZoneManager().setSelected( |
|
1041 | parentVisualizationWidget()->selectionZoneManager().setSelected( | |
1022 | selectionZoneItemUnderCursor, !selectionZoneItemUnderCursor->selected() |
|
1042 | selectionZoneItemUnderCursor, !selectionZoneItemUnderCursor->selected() | |
1023 | || event->button() == Qt::RightButton); |
|
1043 | || event->button() == Qt::RightButton); | |
1024 | } |
|
1044 | } | |
1025 | } |
|
1045 | } | |
1026 | } |
|
1046 | } | |
1027 | else { |
|
1047 | else { | |
1028 | // No selection change |
|
1048 | // No selection change | |
1029 | } |
|
1049 | } | |
1030 | } |
|
1050 | } | |
1031 | } |
|
1051 | } | |
1032 |
|
1052 | |||
1033 | void VisualizationGraphWidget::onDataCacheVariableUpdated() |
|
1053 | void VisualizationGraphWidget::onDataCacheVariableUpdated() | |
1034 | { |
|
1054 | { | |
1035 | auto graphRange = ui->widget->xAxis->range(); |
|
1055 | auto graphRange = ui->widget->xAxis->range(); | |
1036 | auto dateTime = SqpRange{graphRange.lower, graphRange.upper}; |
|
1056 | auto dateTime = SqpRange{graphRange.lower, graphRange.upper}; | |
1037 |
|
1057 | |||
1038 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { |
|
1058 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { | |
1039 | auto variable = variableEntry.first; |
|
1059 | auto variable = variableEntry.first; | |
1040 | qCDebug(LOG_VisualizationGraphWidget()) |
|
1060 | qCDebug(LOG_VisualizationGraphWidget()) | |
1041 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range(); |
|
1061 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range(); | |
1042 | qCDebug(LOG_VisualizationGraphWidget()) |
|
1062 | qCDebug(LOG_VisualizationGraphWidget()) | |
1043 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime; |
|
1063 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime; | |
1044 | if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) { |
|
1064 | if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) { | |
1045 | impl->updateData(variableEntry.second, variable, variable->range()); |
|
1065 | impl->updateData(variableEntry.second, variable, variable->range()); | |
1046 | } |
|
1066 | } | |
1047 | } |
|
1067 | } | |
1048 | } |
|
1068 | } | |
1049 |
|
1069 | |||
1050 | void VisualizationGraphWidget::onUpdateVarDisplaying(std::shared_ptr<Variable> variable, |
|
1070 | void VisualizationGraphWidget::onUpdateVarDisplaying(std::shared_ptr<Variable> variable, | |
1051 | const SqpRange &range) |
|
1071 | const SqpRange &range) | |
1052 | { |
|
1072 | { | |
1053 | auto it = impl->m_VariableToPlotMultiMap.find(variable); |
|
1073 | auto it = impl->m_VariableToPlotMultiMap.find(variable); | |
1054 | if (it != impl->m_VariableToPlotMultiMap.end()) { |
|
1074 | if (it != impl->m_VariableToPlotMultiMap.end()) { | |
1055 | impl->updateData(it->second, variable, range); |
|
1075 | impl->updateData(it->second, variable, range); | |
1056 | } |
|
1076 | } | |
1057 | } |
|
1077 | } |
General Comments 0
You need to be logged in to leave comments.
Login now