##// END OF EJS Templates
Refresh catalogue menu when the catalogue list changed
trabillard -
r1327:07b2554d7734
parent child
Show More
@@ -19,6 +19,8 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
22 private:
24 private:
23 class ActionsGuiControllerPrivate;
25 class ActionsGuiControllerPrivate;
24 spimpl::unique_impl_ptr<ActionsGuiControllerPrivate> impl;
26 spimpl::unique_impl_ptr<ActionsGuiControllerPrivate> impl;
@@ -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);
@@ -34,3 +34,8 QVector<std::shared_ptr<SelectionZoneAction> > ActionsGuiController::selectionZo
34 {
34 {
35 return impl->m_SelectionZoneActions;
35 return impl->m_SelectionZoneActions;
36 }
36 }
37
38 void ActionsGuiController::removeAction(const std::shared_ptr<SelectionZoneAction> &action)
39 {
40 impl->m_SelectionZoneActions.removeAll(action);
41 }
@@ -25,14 +25,15
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("New Event");
30 const auto DEFAULT_EVENT_NAME = QObject::tr("Event");
31 const auto DEFAULT_CATALOGUE_NAME = QObject::tr("New 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
37
37 CatalogueActionManagerPrivate(CatalogueExplorer *catalogueExplorer)
38 CatalogueActionManagerPrivate(CatalogueExplorer *catalogueExplorer)
38 : m_CatalogueExplorer(catalogueExplorer)
39 : m_CatalogueExplorer(catalogueExplorer)
@@ -85,6 +86,32 struct CatalogueActionManager::CatalogueActionManagerPrivate {
85 m_CatalogueExplorer->eventsWidget().setEventChanges(event, true);
86 m_CatalogueExplorer->eventsWidget().setEventChanges(event, true);
86 }
87 }
87 }
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 }
88 };
115 };
89
116
90 CatalogueActionManager::CatalogueActionManager(CatalogueExplorer *catalogueExplorer)
117 CatalogueActionManager::CatalogueActionManager(CatalogueExplorer *catalogueExplorer)
@@ -96,33 +123,10 void CatalogueActionManager::installSelectionZoneActions()
96 {
123 {
97 auto &actionController = sqpApp->actionsGuiController();
124 auto &actionController = sqpApp->actionsGuiController();
98
125
99 auto createEventEnableFuntion = [](auto zones) {
100
101 // Checks that all variables in the zones doesn't refer to the same product
102 QSet<QString> usedDatasource;
103 for (auto zone : zones) {
104 auto graph = zone->parentGraphWidget();
105 auto variables = graph->variables();
106
107 for (auto var : variables) {
108 auto datasourceId = var->metadata().value(DataSourceItem::ID_DATA_KEY).toString();
109 if (!usedDatasource.contains(datasourceId)) {
110 usedDatasource.insert(datasourceId);
111 }
112 else {
113 return false;
114 }
115 }
116 }
117
118 return true;
119 };
120
121
122 auto createEventAction = actionController.addSectionZoneAction(
126 auto createEventAction = actionController.addSectionZoneAction(
123 {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"),
124 [this](auto zones) { impl->createEventFromZones(DEFAULT_EVENT_NAME, zones); });
128 [this](auto zones) { impl->createEventFromZones(DEFAULT_EVENT_NAME, zones); });
125 createEventAction->setEnableFunction(createEventEnableFuntion);
129 createEventAction->setEnableFunction(impl->createEventEnableFuntion());
126
130
127 auto createEventInNewCatalogueAction = actionController.addSectionZoneAction(
131 auto createEventInNewCatalogueAction = actionController.addSectionZoneAction(
128 {CATALOGUE_MENU_NAME, CATALOGUE_CREATE_EVENT_MENU_NAME}, QObject::tr("In New Catalogue"),
132 {CATALOGUE_MENU_NAME, CATALOGUE_CREATE_EVENT_MENU_NAME}, QObject::tr("In New Catalogue"),
@@ -136,18 +140,32 void CatalogueActionManager::installSelectionZoneActions()
136
140
137 impl->createEventFromZones(DEFAULT_EVENT_NAME, zones, newCatalogue);
141 impl->createEventFromZones(DEFAULT_EVENT_NAME, zones, newCatalogue);
138 });
142 });
139 createEventInNewCatalogueAction->setEnableFunction(createEventEnableFuntion);
143 createEventInNewCatalogueAction->setEnableFunction(impl->createEventEnableFuntion());
144
145
146 refreshCreateInCatalogueAction();
147 }
148
149 void CatalogueActionManager::refreshCreateInCatalogueAction()
150 {
151 auto &actionController = sqpApp->actionsGuiController();
140
152
153 for (auto action : impl->m_CreateInCatalogueActions) {
154 actionController.removeAction(action);
155 }
156 impl->m_CreateInCatalogueActions.clear();
141
157
142 auto allCatalogues
158 auto allCatalogues
143 = impl->m_CatalogueExplorer->sideBarWidget().getCatalogues(REPOSITORY_DEFAULT);
159 = impl->m_CatalogueExplorer->sideBarWidget().getCatalogues(REPOSITORY_DEFAULT);
160
144 for (auto catalogue : allCatalogues) {
161 for (auto catalogue : allCatalogues) {
145 auto catalogueName = catalogue->getName();
162 auto catalogueName = catalogue->getName();
146 auto createEventInCatalogueAction = actionController.addSectionZoneAction(
163 auto createEventInCatalogueAction = actionController.addSectionZoneAction(
147 {CATALOGUE_MENU_NAME, CATALOGUE_CREATE_EVENT_MENU_NAME},
164 {CATALOGUE_MENU_NAME, CATALOGUE_CREATE_EVENT_MENU_NAME},
148 QObject::tr("In ").append(catalogueName), [this, catalogue](auto zones) {
165 QObject::tr("In \"").append(catalogueName).append("\""), [this, catalogue](auto zones) {
149 impl->createEventFromZones(DEFAULT_EVENT_NAME, zones, catalogue);
166 impl->createEventFromZones(DEFAULT_EVENT_NAME, zones, catalogue);
150 });
167 });
151 createEventInCatalogueAction->setEnableFunction(createEventEnableFuntion);
168 createEventInCatalogueAction->setEnableFunction(impl->createEventEnableFuntion());
169 impl->m_CreateInCatalogueActions << createEventInCatalogueAction;
152 }
170 }
153 }
171 }
@@ -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);
@@ -182,6 +185,7 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
182 impl->m_TreeModel->indexOf(catalogueToItem.second->parent()));
185 impl->m_TreeModel->indexOf(catalogueToItem.second->parent()));
183 }
186 }
184 emitSelection();
187 emitSelection();
188 emit catalogueListChanged();
185 }
189 }
186 }
190 }
187 });
191 });
@@ -192,6 +196,7 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
192 this->emitSelection();
196 this->emitSelection();
193 }
197 }
194 impl->setHasChanges(true, index, this);
198 impl->setHasChanges(true, index, this);
199 emit this->catalogueListChanged();
195 });
200 });
196
201
197 ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
202 ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -209,7 +214,12 CatalogueSideBarWidget::addCatalogue(const std::shared_ptr<DBCatalogue> &catalog
209 const QString &repository)
214 const QString &repository)
210 {
215 {
211 auto repositoryItem = impl->getDatabaseItem(repository);
216 auto repositoryItem = impl->getDatabaseItem(repository);
212 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;
213 }
223 }
214
224
215 void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue,
225 void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue,
General Comments 0
You need to be logged in to leave comments. Login now