##// END OF EJS Templates
Merge branch 'feature/CataloguePart7' into develop
trabillard -
r1383:4dfca649988f merge
parent child
Show More
@@ -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 }
@@ -19,6 +19,14 public:
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);
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
22 private:
30 private:
23 class ActionsGuiControllerPrivate;
31 class ActionsGuiControllerPrivate;
24 spimpl::unique_impl_ptr<ActionsGuiControllerPrivate> impl;
32 spimpl::unique_impl_ptr<ActionsGuiControllerPrivate> impl;
@@ -60,6 +60,13 public:
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);
@@ -10,6 +10,7 public:
10 CatalogueActionManager(CatalogueExplorer *catalogueExplorer);
10 CatalogueActionManager(CatalogueExplorer *catalogueExplorer);
11
11
12 void installSelectionZoneActions();
12 void installSelectionZoneActions();
13 void refreshCreateInCatalogueAction();
13
14
14 private:
15 private:
15 class CatalogueActionManagerPrivate;
16 class CatalogueActionManagerPrivate;
@@ -25,6 +25,7 signals:
25 void trashSelected();
25 void trashSelected();
26 void selectionCleared();
26 void selectionCleared();
27 void catalogueSaved(const std::shared_ptr<DBCatalogue> &catalogue);
27 void catalogueSaved(const std::shared_ptr<DBCatalogue> &catalogue);
28 void catalogueListChanged();
28
29
29 public:
30 public:
30 explicit CatalogueSideBarWidget(QWidget *parent = 0);
31 explicit CatalogueSideBarWidget(QWidget *parent = 0);
@@ -19,6 +19,7 public:
19
19
20 /// Returns the catalogue represented by the item
20 /// Returns the catalogue represented by the item
21 std::shared_ptr<DBCatalogue> catalogue() const;
21 std::shared_ptr<DBCatalogue> catalogue() const;
22 void replaceCatalogue(const std::shared_ptr<DBCatalogue> &catalogue);
22
23
23 private:
24 private:
24 class CatalogueTreeItemPrivate;
25 class CatalogueTreeItemPrivate;
@@ -28,8 +28,8 gui_moc_headers = [
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/CreateEventDialog.h',
31 'include/Catalogue/CatalogueTreeModel.h',
32 'include/Catalogue/CatalogueTreeModel.h'
32 'include/Actions/FilteringAction.h'
33 ]
33 ]
34
34
35 gui_ui_files = [
35 gui_ui_files = [
@@ -50,8 +50,7 gui_ui_files = [
50 'ui/Catalogue/CatalogueExplorer.ui',
50 'ui/Catalogue/CatalogueExplorer.ui',
51 'ui/Catalogue/CatalogueEventsWidget.ui',
51 'ui/Catalogue/CatalogueEventsWidget.ui',
52 'ui/Catalogue/CatalogueSideBarWidget.ui',
52 'ui/Catalogue/CatalogueSideBarWidget.ui',
53 'ui/Catalogue/CatalogueInspectorWidget.ui',
53 'ui/Catalogue/CatalogueInspectorWidget.ui'
54 'ui/Catalogue/CreateEventDialog.ui'
55 ]
54 ]
56
55
57 gui_qresources = ['resources/sqpguiresources.qrc']
56 gui_qresources = ['resources/sqpguiresources.qrc']
@@ -114,6 +113,7 gui_sources = [
114 'src/Visualization/VisualizationSelectionZoneManager.cpp',
113 'src/Visualization/VisualizationSelectionZoneManager.cpp',
115 'src/Actions/SelectionZoneAction.cpp',
114 'src/Actions/SelectionZoneAction.cpp',
116 'src/Actions/ActionsGuiController.cpp',
115 'src/Actions/ActionsGuiController.cpp',
116 'src/Actions/FilteringAction.cpp',
117 'src/Visualization/VisualizationActionManager.cpp',
117 'src/Visualization/VisualizationActionManager.cpp',
118 'src/Visualization/VisualizationMultiZoneSelectionDialog.cpp',
118 'src/Visualization/VisualizationMultiZoneSelectionDialog.cpp',
119 'src/Catalogue/CatalogueExplorer.cpp',
119 'src/Catalogue/CatalogueExplorer.cpp',
@@ -126,7 +126,6 gui_sources = [
126 'src/Catalogue/CatalogueEventsModel.cpp',
126 'src/Catalogue/CatalogueEventsModel.cpp',
127 'src/Catalogue/CatalogueExplorerHelper.cpp',
127 'src/Catalogue/CatalogueExplorerHelper.cpp',
128 'src/Catalogue/CatalogueActionManager.cpp',
128 'src/Catalogue/CatalogueActionManager.cpp',
129 'src/Catalogue/CreateEventDialog.cpp',
130 'src/Catalogue/CatalogueTreeModel.cpp'
129 'src/Catalogue/CatalogueTreeModel.cpp'
131 ]
130 ]
132
131
@@ -3,6 +3,7
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()
@@ -34,3 +35,18 QVector<std::shared_ptr<SelectionZoneAction> > ActionsGuiController::selectionZo
34 {
35 {
35 return impl->m_SelectionZoneActions;
36 return impl->m_SelectionZoneActions;
36 }
37 }
38
39 void ActionsGuiController::removeAction(const std::shared_ptr<SelectionZoneAction> &action)
40 {
41 impl->m_SelectionZoneActions.removeAll(action);
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 }
@@ -15,6 +15,7 struct SelectionZoneAction::SelectionZoneActionPrivate {
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)
@@ -55,6 +56,16 QStringList SelectionZoneAction::subMenuList() const noexcept
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);
@@ -11,7 +11,6
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 #include <Catalogue/CreateEventDialog.h>
15
14
16 #include <CatalogueDao.h>
15 #include <CatalogueDao.h>
17 #include <DBCatalogue.h>
16 #include <DBCatalogue.h>
@@ -25,9 +24,16
25 #include <QLineEdit>
24 #include <QLineEdit>
26 #include <memory>
25 #include <memory>
27
26
27 const auto CATALOGUE_MENU_NAME = QObject::tr("Catalogues");
28 const auto CATALOGUE_CREATE_EVENT_MENU_NAME = QObject::tr("New Event...");
29
30 const auto DEFAULT_EVENT_NAME = QObject::tr("Event");
31 const auto DEFAULT_CATALOGUE_NAME = QObject::tr("Catalogue");
32
28 struct CatalogueActionManager::CatalogueActionManagerPrivate {
33 struct CatalogueActionManager::CatalogueActionManagerPrivate {
29
34
30 CatalogueExplorer *m_CatalogueExplorer = nullptr;
35 CatalogueExplorer *m_CatalogueExplorer = nullptr;
36 QVector<std::shared_ptr<SelectionZoneAction> > m_CreateInCatalogueActions;
31
37
32 CatalogueActionManagerPrivate(CatalogueExplorer *catalogueExplorer)
38 CatalogueActionManagerPrivate(CatalogueExplorer *catalogueExplorer)
33 : m_CatalogueExplorer(catalogueExplorer)
39 : m_CatalogueExplorer(catalogueExplorer)
@@ -80,6 +86,32 struct CatalogueActionManager::CatalogueActionManagerPrivate {
80 m_CatalogueExplorer->eventsWidget().setEventChanges(event, true);
86 m_CatalogueExplorer->eventsWidget().setEventChanges(event, true);
81 }
87 }
82 }
88 }
89
90 SelectionZoneAction::EnableFunction createEventEnableFuntion() const
91 {
92 return [](auto zones) {
93
94 // Checks that all variables in the zones doesn't refer to the same product
95 QSet<QString> usedDatasource;
96 for (auto zone : zones) {
97 auto graph = zone->parentGraphWidget();
98 auto variables = graph->variables();
99
100 for (auto var : variables) {
101 auto datasourceId
102 = var->metadata().value(DataSourceItem::ID_DATA_KEY).toString();
103 if (!usedDatasource.contains(datasourceId)) {
104 usedDatasource.insert(datasourceId);
105 }
106 else {
107 return false;
108 }
109 }
110 }
111
112 return true;
113 };
114 }
83 };
115 };
84
116
85 CatalogueActionManager::CatalogueActionManager(CatalogueExplorer *catalogueExplorer)
117 CatalogueActionManager::CatalogueActionManager(CatalogueExplorer *catalogueExplorer)
@@ -91,55 +123,52 void CatalogueActionManager::installSelectionZoneActions()
91 {
123 {
92 auto &actionController = sqpApp->actionsGuiController();
124 auto &actionController = sqpApp->actionsGuiController();
93
125
94 auto createEventEnableFuntion = [](auto zones) {
126 auto createEventAction = actionController.addSectionZoneAction(
95
127 {CATALOGUE_MENU_NAME, CATALOGUE_CREATE_EVENT_MENU_NAME}, QObject::tr("Without Catalogue"),
96 // Checks that all variables in the zones doesn't refer to the same product
128 [this](auto zones) { impl->createEventFromZones(DEFAULT_EVENT_NAME, zones); });
97 QSet<QString> usedDatasource;
129 createEventAction->setEnableFunction(impl->createEventEnableFuntion());
98 for (auto zone : zones) {
130 createEventAction->setAllowedFiltering(false);
99 auto graph = zone->parentGraphWidget();
131
100 auto variables = graph->variables();
132 auto createEventInNewCatalogueAction = actionController.addSectionZoneAction(
133 {CATALOGUE_MENU_NAME, CATALOGUE_CREATE_EVENT_MENU_NAME}, QObject::tr("In New Catalogue"),
134 [this](auto zones) {
135
136 auto newCatalogue = std::make_shared<DBCatalogue>();
137 newCatalogue->setName(DEFAULT_CATALOGUE_NAME);
138 sqpApp->catalogueController().addCatalogue(newCatalogue);
139 impl->m_CatalogueExplorer->sideBarWidget().addCatalogue(newCatalogue,
140 REPOSITORY_DEFAULT);
141
142 impl->createEventFromZones(DEFAULT_EVENT_NAME, zones, newCatalogue);
143 });
144 createEventInNewCatalogueAction->setEnableFunction(impl->createEventEnableFuntion());
145 createEventInNewCatalogueAction->setAllowedFiltering(false);
101
146
102 for (auto var : variables) {
147 refreshCreateInCatalogueAction();
103 auto datasourceId = var->metadata().value(DataSourceItem::ID_DATA_KEY).toString();
104 if (!usedDatasource.contains(datasourceId)) {
105 usedDatasource.insert(datasourceId);
106 }
107 else {
108 return false;
109 }
110 }
111 }
112
148
113 return true;
149 actionController.addFilterForMenu({CATALOGUE_MENU_NAME, CATALOGUE_CREATE_EVENT_MENU_NAME});
114 };
150 }
115
151
116 auto createEventAction = actionController.addSectionZoneAction(
152 void CatalogueActionManager::refreshCreateInCatalogueAction()
117 {QObject::tr("Catalogues")}, QObject::tr("New Event..."), [this](auto zones) {
153 {
118 CreateEventDialog dialog(
154 auto &actionController = sqpApp->actionsGuiController();
119 impl->m_CatalogueExplorer->sideBarWidget().getCatalogues(REPOSITORY_DEFAULT));
120 dialog.hideCatalogueChoice();
121 if (dialog.exec() == QDialog::Accepted) {
122 impl->createEventFromZones(dialog.eventName(), zones);
123 }
124 });
125 createEventAction->setEnableFunction(createEventEnableFuntion);
126
127 auto createEventInCatalogueAction = actionController.addSectionZoneAction(
128 {QObject::tr("Catalogues")}, QObject::tr("New Event in Catalogue..."), [this](auto zones) {
129 CreateEventDialog dialog(
130 impl->m_CatalogueExplorer->sideBarWidget().getCatalogues(REPOSITORY_DEFAULT));
131 if (dialog.exec() == QDialog::Accepted) {
132 auto selectedCatalogue = dialog.selectedCatalogue();
133 if (!selectedCatalogue) {
134 selectedCatalogue = std::make_shared<DBCatalogue>();
135 selectedCatalogue->setName(dialog.catalogueName());
136 sqpApp->catalogueController().addCatalogue(selectedCatalogue);
137 impl->m_CatalogueExplorer->sideBarWidget().addCatalogue(selectedCatalogue,
138 REPOSITORY_DEFAULT);
139 }
140
155
141 impl->createEventFromZones(dialog.eventName(), zones, selectedCatalogue);
156 for (auto action : impl->m_CreateInCatalogueActions) {
142 }
157 actionController.removeAction(action);
143 });
158 }
144 createEventInCatalogueAction->setEnableFunction(createEventEnableFuntion);
159 impl->m_CreateInCatalogueActions.clear();
160
161 auto allCatalogues
162 = impl->m_CatalogueExplorer->sideBarWidget().getCatalogues(REPOSITORY_DEFAULT);
163
164 for (auto catalogue : allCatalogues) {
165 auto catalogueName = catalogue->getName();
166 auto createEventInCatalogueAction = actionController.addSectionZoneAction(
167 {CATALOGUE_MENU_NAME, CATALOGUE_CREATE_EVENT_MENU_NAME},
168 QObject::tr("In \"").append(catalogueName).append("\""), [this, catalogue](auto zones) {
169 impl->createEventFromZones(DEFAULT_EVENT_NAME, zones, catalogue);
170 });
171 createEventInCatalogueAction->setEnableFunction(impl->createEventEnableFuntion());
172 impl->m_CreateInCatalogueActions << createEventInCatalogueAction;
173 }
145 }
174 }
@@ -17,10 +17,12
17 #include <Visualization/VisualizationWidget.h>
17 #include <Visualization/VisualizationWidget.h>
18 #include <Visualization/VisualizationZoneWidget.h>
18 #include <Visualization/VisualizationZoneWidget.h>
19
19
20 #include <QActionGroup>
20 #include <QDialog>
21 #include <QDialog>
21 #include <QDialogButtonBox>
22 #include <QDialogButtonBox>
22 #include <QKeyEvent>
23 #include <QKeyEvent>
23 #include <QListWidget>
24 #include <QListWidget>
25 #include <QMenu>
24 #include <QMessageBox>
26 #include <QMessageBox>
25
27
26 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
28 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
@@ -28,6 +30,8 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
28 /// Percentage added to the range of a event when it is displayed
30 /// Percentage added to the range of a event when it is displayed
29 const auto EVENT_RANGE_MARGE = 30; // in %
31 const auto EVENT_RANGE_MARGE = 30; // in %
30
32
33 const QString NEW_ZONE_TEXT = QStringLiteral("New Zone");
34
31 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
35 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
32
36
33 CatalogueEventsModel *m_Model = nullptr;
37 CatalogueEventsModel *m_Model = nullptr;
@@ -80,72 +84,46 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
80 }
84 }
81
85
82 QStringList selectZone(QWidget *parent, const QStringList &selectedZones,
86 QStringList selectZone(QWidget *parent, const QStringList &selectedZones,
83 bool allowMultiSelection, const QPoint &location)
87 bool allowMultiSelection, bool addNewZoneOption, const QPoint &location)
84 {
88 {
85 auto availableZones = getAvailableVisualizationZoneList();
89 auto availableZones = getAvailableVisualizationZoneList();
86 if (availableZones.isEmpty()) {
90 if (!addNewZoneOption && availableZones.isEmpty()) {
87 return QStringList{};
91 return QStringList{};
88 }
92 }
89
93
90 QDialog d(parent, Qt::Tool);
94 QActionGroup actionGroup{parent};
91 d.setWindowTitle("Choose a zone");
95 actionGroup.setExclusive(!allowMultiSelection);
92 auto layout = new QVBoxLayout{&d};
93 layout->setContentsMargins(0, 0, 0, 0);
94 auto listWidget = new QListWidget{&d};
95 layout->addWidget(listWidget);
96
96
97 QSet<QListWidgetItem *> checkedItems;
97 QVector<QAction *> zoneActions;
98 for (auto zone : availableZones) {
98
99 auto item = new QListWidgetItem{zone};
99 QMenu selectionMenu{parent};
100 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
101 if (selectedZones.contains(zone)) {
102 item->setCheckState(Qt::Checked);
103 checkedItems << item;
104 }
105 else {
106 item->setCheckState(Qt::Unchecked);
107 }
108
100
109 listWidget->addItem(item);
101 if (addNewZoneOption) {
102 availableZones.prepend(NEW_ZONE_TEXT);
110 }
103 }
111
104
112 auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d};
105 selectionMenu.addSeparator();
113 layout->addWidget(buttonBox);
106 for (auto zone : availableZones) {
114
107 auto zoneAction = selectionMenu.addAction(zone);
115 QObject::connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept);
108 zoneAction->setCheckable(true);
116 QObject::connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject);
109 zoneAction->setChecked(selectedZones.contains(zone));
117
110 actionGroup.addAction(zoneAction);
118 QObject::connect(listWidget, &QListWidget::itemChanged,
111 zoneActions << zoneAction;
119 [&checkedItems, allowMultiSelection, listWidget](auto item) {
112 }
120 if (item->checkState() == Qt::Checked) {
113
121 if (!allowMultiSelection) {
114 auto resultAction = selectionMenu.exec(QCursor::pos());
122 for (auto checkedItem : checkedItems) {
123 listWidget->blockSignals(true);
124 checkedItem->setCheckState(Qt::Unchecked);
125 listWidget->blockSignals(false);
126 }
127
128 checkedItems.clear();
129 }
130 checkedItems << item;
131 }
132 else {
133 checkedItems.remove(item);
134 }
135 });
136
115
137 QStringList result;
116 QStringList result;
138
117
139 d.setMinimumWidth(120);
118 if (resultAction == nullptr) {
140 d.resize(d.minimumSizeHint());
119 result = selectedZones;
141 d.move(location);
142 if (d.exec() == QDialog::Accepted) {
143 for (auto item : checkedItems) {
144 result += item->text();
145 }
146 }
120 }
147 else {
121 else {
148 result = selectedZones;
122 for (auto zoneAction : zoneActions) {
123 if (zoneAction->isChecked()) {
124 result << zoneAction->text();
125 }
126 }
149 }
127 }
150
128
151 return result;
129 return result;
@@ -252,8 +230,9 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
252 return;
230 return;
253 }
231 }
254
232
233 auto isNewZone = m_ZoneForGraphMode == NEW_ZONE_TEXT;
255 auto zone = tab->getZoneWithName(m_ZoneForGraphMode);
234 auto zone = tab->getZoneWithName(m_ZoneForGraphMode);
256 if (!zone) {
235 if (!isNewZone && !zone) {
257 qCWarning(LOG_CatalogueEventsWidget()) << "updateGraphMode: zone not found";
236 qCWarning(LOG_CatalogueEventsWidget()) << "updateGraphMode: zone not found";
258 return;
237 return;
259 }
238 }
@@ -270,7 +249,15 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
270 m_CustomGraphs.clear();
249 m_CustomGraphs.clear();
271
250
272 // Closes the remaining graphs inside the zone
251 // Closes the remaining graphs inside the zone
273 zone->closeAllGraphs();
252 if (zone) {
253 zone->closeAllGraphs();
254 }
255
256 // Creates the zone if needed
257 if (isNewZone) {
258 zone = tab->createEmptyZone(0);
259 m_ZoneForGraphMode = zone->name();
260 }
274
261
275 // Calculates the range of each graph which will be created
262 // Calculates the range of each graph which will be created
276 auto graphRange = getGraphRanges(event);
263 auto graphRange = getGraphRanges(event);
@@ -357,7 +344,7 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
357 if (checked) {
344 if (checked) {
358 ui->btnChart->setChecked(false);
345 ui->btnChart->setChecked(false);
359 impl->m_ZonesForTimeMode
346 impl->m_ZonesForTimeMode
360 = impl->selectZone(this, impl->m_ZonesForTimeMode, true,
347 = impl->selectZone(this, impl->m_ZonesForTimeMode, true, false,
361 this->mapToGlobal(ui->btnTime->frameGeometry().center()));
348 this->mapToGlobal(ui->btnTime->frameGeometry().center()));
362
349
363 impl->updateForTimeMode(ui->treeView);
350 impl->updateForTimeMode(ui->treeView);
@@ -367,8 +354,9 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
367 connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) {
354 connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) {
368 if (checked) {
355 if (checked) {
369 ui->btnTime->setChecked(false);
356 ui->btnTime->setChecked(false);
357
370 impl->m_ZoneForGraphMode
358 impl->m_ZoneForGraphMode
371 = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false,
359 = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false, true,
372 this->mapToGlobal(ui->btnChart->frameGeometry().center()))
360 this->mapToGlobal(ui->btnChart->frameGeometry().center()))
373 .value(0);
361 .value(0);
374
362
@@ -79,6 +79,9 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
79 connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSaved, ui->events,
79 connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSaved, ui->events,
80 &CatalogueEventsWidget::refresh);
80 &CatalogueEventsWidget::refresh);
81
81
82 connect(ui->catalogues, &CatalogueSideBarWidget::catalogueListChanged,
83 [this]() { impl->m_ActionManager.refreshCreateInCatalogueAction(); });
84
82 // Updates the inspectot when something is selected in the events
85 // Updates the inspectot when something is selected in the events
83 connect(ui->events, &CatalogueEventsWidget::eventsSelected, [this](auto events) {
86 connect(ui->events, &CatalogueEventsWidget::eventsSelected, [this](auto events) {
84 if (events.count() == 1) {
87 if (events.count() == 1) {
@@ -126,6 +129,7 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
126 connect(ui->inspector, &CatalogueInspectorWidget::catalogueUpdated, [this](auto catalogue) {
129 connect(ui->inspector, &CatalogueInspectorWidget::catalogueUpdated, [this](auto catalogue) {
127 sqpApp->catalogueController().updateCatalogue(catalogue);
130 sqpApp->catalogueController().updateCatalogue(catalogue);
128 ui->catalogues->setCatalogueChanges(catalogue, true);
131 ui->catalogues->setCatalogueChanges(catalogue, true);
132 impl->m_ActionManager.refreshCreateInCatalogueAction();
129 });
133 });
130
134
131 connect(ui->inspector, &CatalogueInspectorWidget::eventUpdated, [this](auto event) {
135 connect(ui->inspector, &CatalogueInspectorWidget::eventUpdated, [this](auto event) {
@@ -25,6 +25,8 constexpr auto TRASH_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 2;
25 constexpr auto CATALOGUE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 3;
25 constexpr auto CATALOGUE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 3;
26 constexpr auto DATABASE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 4;
26 constexpr auto DATABASE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 4;
27
27
28 const auto DEFAULT_CATALOGUE_NAME = QObject::tr("Catalogue");
29
28
30
29 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate {
31 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate {
30
32
@@ -108,6 +110,7 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
108 ui->treeView->setModel(impl->m_TreeModel);
110 ui->treeView->setModel(impl->m_TreeModel);
109
111
110 impl->configureTreeWidget(ui->treeView);
112 impl->configureTreeWidget(ui->treeView);
113 emit catalogueListChanged();
111
114
112 ui->treeView->header()->setStretchLastSection(false);
115 ui->treeView->header()->setStretchLastSection(false);
113 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
116 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
@@ -121,7 +124,7 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
121
124
122 connect(ui->btnAdd, &QToolButton::clicked, [this]() {
125 connect(ui->btnAdd, &QToolButton::clicked, [this]() {
123 auto catalogue = std::make_shared<DBCatalogue>();
126 auto catalogue = std::make_shared<DBCatalogue>();
124 catalogue->setName(QString("Cat"));
127 catalogue->setName(DEFAULT_CATALOGUE_NAME);
125 sqpApp->catalogueController().addCatalogue(catalogue);
128 sqpApp->catalogueController().addCatalogue(catalogue);
126 auto item = this->addCatalogue(catalogue, REPOSITORY_DEFAULT);
129 auto item = this->addCatalogue(catalogue, REPOSITORY_DEFAULT);
127 this->setCatalogueChanges(catalogue, true);
130 this->setCatalogueChanges(catalogue, true);
@@ -133,6 +136,7 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
133 connect(impl->m_TreeModel, &CatalogueTreeModel::itemDropped,
136 connect(impl->m_TreeModel, &CatalogueTreeModel::itemDropped,
134 [this](auto index, auto mimeData, auto action) {
137 [this](auto index, auto mimeData, auto action) {
135 auto item = impl->m_TreeModel->item(index);
138 auto item = impl->m_TreeModel->item(index);
139
136 if (item && item->type() == CATALOGUE_ITEM_TYPE) {
140 if (item && item->type() == CATALOGUE_ITEM_TYPE) {
137 auto catalogue = static_cast<CatalogueTreeItem *>(item)->catalogue();
141 auto catalogue = static_cast<CatalogueTreeItem *>(item)->catalogue();
138 this->setCatalogueChanges(catalogue, true);
142 this->setCatalogueChanges(catalogue, true);
@@ -144,9 +148,12 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
144 mimeData->data(MIME_TYPE_SOURCE_CATALOGUE_LIST));
148 mimeData->data(MIME_TYPE_SOURCE_CATALOGUE_LIST));
145 for (auto catalogue : sourceCatalogues) {
149 for (auto catalogue : sourceCatalogues) {
146 if (auto catalogueItem = impl->getCatalogueItem(catalogue)) {
150 if (auto catalogueItem = impl->getCatalogueItem(catalogue)) {
151 catalogueItem->replaceCatalogue(catalogue);
147 this->setCatalogueChanges(catalogue, true);
152 this->setCatalogueChanges(catalogue, true);
148 }
153 }
149 }
154 }
155
156 this->emitSelection();
150 }
157 }
151 });
158 });
152
159
@@ -178,6 +185,7 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
178 impl->m_TreeModel->indexOf(catalogueToItem.second->parent()));
185 impl->m_TreeModel->indexOf(catalogueToItem.second->parent()));
179 }
186 }
180 emitSelection();
187 emitSelection();
188 emit catalogueListChanged();
181 }
189 }
182 }
190 }
183 });
191 });
@@ -188,6 +196,7 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
188 this->emitSelection();
196 this->emitSelection();
189 }
197 }
190 impl->setHasChanges(true, index, this);
198 impl->setHasChanges(true, index, this);
199 emit this->catalogueListChanged();
191 });
200 });
192
201
193 ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
202 ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -205,7 +214,12 CatalogueSideBarWidget::addCatalogue(const std::shared_ptr<DBCatalogue> &catalog
205 const QString &repository)
214 const QString &repository)
206 {
215 {
207 auto repositoryItem = impl->getDatabaseItem(repository);
216 auto repositoryItem = impl->getDatabaseItem(repository);
208 return impl->addCatalogueItem(catalogue, impl->m_TreeModel->indexOf(repositoryItem));
217 auto catalogueItem
218 = impl->addCatalogueItem(catalogue, impl->m_TreeModel->indexOf(repositoryItem));
219
220 emit catalogueListChanged();
221
222 return catalogueItem;
209 }
223 }
210
224
211 void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue,
225 void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue,
@@ -124,3 +124,8 std::shared_ptr<DBCatalogue> CatalogueTreeItem::catalogue() const
124 {
124 {
125 return impl->m_Catalogue;
125 return impl->m_Catalogue;
126 }
126 }
127
128 void CatalogueTreeItem::replaceCatalogue(const std::shared_ptr<DBCatalogue> &catalogue)
129 {
130 impl->m_Catalogue = catalogue;
131 }
@@ -12,6 +12,7
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>
@@ -245,7 +246,7 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget
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 this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection);
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);
@@ -633,6 +634,10 void VisualizationGraphWidget::closeEvent(QCloseEvent *event)
633 {
634 {
634 Q_UNUSED(event);
635 Q_UNUSED(event);
635
636
637 for (auto i : impl->m_SelectionZones) {
638 parentVisualizationWidget()->selectionZoneManager().setSelected(i, false);
639 }
640
636 // 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
637 for (auto &variableEntry : impl->m_VariableToPlotMultiMap) {
642 for (auto &variableEntry : impl->m_VariableToPlotMultiMap) {
638 emit variableAboutToBeRemoved(variableEntry.first);
643 emit variableAboutToBeRemoved(variableEntry.first);
@@ -703,32 +708,51 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
703
708
704 QHash<QString, QMenu *> subMenus;
709 QHash<QString, QMenu *> subMenus;
705 QHash<QString, bool> subMenusEnabled;
710 QHash<QString, bool> subMenusEnabled;
711 QHash<QString, FilteringAction *> filteredMenu;
706
712
707 for (auto zoneAction : zoneActions) {
713 for (auto zoneAction : zoneActions) {
708
714
709 auto isEnabled = zoneAction->isEnabled(selectedItems);
715 auto isEnabled = zoneAction->isEnabled(selectedItems);
710
716
711 auto menu = &graphMenu;
717 auto menu = &graphMenu;
718 QString menuPath;
712 for (auto subMenuName : zoneAction->subMenuList()) {
719 for (auto subMenuName : zoneAction->subMenuList()) {
713 if (!subMenus.contains(subMenuName)) {
720 menuPath += '/';
721 menuPath += subMenuName;
722
723 if (!subMenus.contains(menuPath)) {
714 menu = menu->addMenu(subMenuName);
724 menu = menu->addMenu(subMenuName);
715 subMenus[subMenuName] = menu;
725 subMenus[menuPath] = menu;
716 subMenusEnabled[subMenuName] = isEnabled;
726 subMenusEnabled[menuPath] = isEnabled;
717 }
727 }
718 else {
728 else {
719 menu = subMenus.value(subMenuName);
729 menu = subMenus.value(menuPath);
720 if (isEnabled) {
730 if (isEnabled) {
721 // 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
722 subMenusEnabled[subMenuName] = true;
732 subMenusEnabled[menuPath] = true;
723 }
733 }
724 }
734 }
725 }
735 }
726
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);
744 }
745 }
746
727 auto action = menu->addAction(zoneAction->name());
747 auto action = menu->addAction(zoneAction->name());
728 action->setEnabled(isEnabled);
748 action->setEnabled(isEnabled);
729 action->setShortcut(zoneAction->displayedShortcut());
749 action->setShortcut(zoneAction->displayedShortcut());
730 QObject::connect(action, &QAction::triggered,
750 QObject::connect(action, &QAction::triggered,
731 [zoneAction, selectedItems]() { zoneAction->execute(selectedItems); });
751 [zoneAction, selectedItems]() { zoneAction->execute(selectedItems); });
752
753 if (filterAction && zoneAction->isFilteringAllowed()) {
754 filterAction->addActionToFilter(action);
755 }
732 }
756 }
733
757
734 for (auto it = subMenus.cbegin(); it != subMenus.cend(); ++it) {
758 for (auto it = subMenus.cbegin(); it != subMenus.cend(); ++it) {
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now