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