##// END OF EJS Templates
Merge branch 'feature/CatalogueCatalogue' into develop
mperrinel -
r1359:2a3a8fe0212d merge
parent child
Show More
@@ -55,13 +55,15 public:
55 // Catalogue
55 // Catalogue
56 std::list<std::shared_ptr<DBEvent> >
56 std::list<std::shared_ptr<DBEvent> >
57 retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const;
57 retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const;
58 // bool createCatalogue(const QString &name, QVector<QUuid> eventList);
58
59 /// retrieveEvents with empty repository retrieve them from the default repository
59 /// retrieveEvents with empty repository retrieve them from the default repository
60 std::list<std::shared_ptr<DBCatalogue> > retrieveCatalogues(const QString &repository
60 std::list<std::shared_ptr<DBCatalogue> > retrieveCatalogues(const QString &repository
61 = QString()) const;
61 = QString()) const;
62 void addCatalogue(std::shared_ptr<DBCatalogue> catalogue);
62 void updateCatalogue(std::shared_ptr<DBCatalogue> catalogue);
63 void updateCatalogue(std::shared_ptr<DBCatalogue> catalogue);
63 void removeCatalogue(std::shared_ptr<DBCatalogue> catalogue);
64 void removeCatalogue(std::shared_ptr<DBCatalogue> catalogue);
64 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue);
65 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue);
66 void discardCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool &removed);
65
67
66 void saveAll();
68 void saveAll();
67 bool hasChanges() const;
69 bool hasChanges() const;
@@ -27,6 +27,10 static QString REPOSITORY_WORK_SUFFIX = QString{"_work"};
27 static QString REPOSITORY_TRASH_SUFFIX = QString{"_trash"};
27 static QString REPOSITORY_TRASH_SUFFIX = QString{"_trash"};
28 }
28 }
29
29
30 /**
31 * Possible types of an repository
32 */
33 enum class DBType { SYNC, WORK, TRASH };
30 class CatalogueController::CatalogueControllerPrivate {
34 class CatalogueController::CatalogueControllerPrivate {
31
35
32 public:
36 public:
@@ -37,9 +41,10 public:
37 QStringList m_RepositoryList;
41 QStringList m_RepositoryList;
38 CatalogueController *m_Q;
42 CatalogueController *m_Q;
39
43
40 QSet<QString> m_EventKeysWithChanges;
44 QSet<QString> m_KeysWithChanges;
41
45
42 QString eventUniqueKey(const std::shared_ptr<DBEvent> &event) const;
46 QString eventUniqueKey(const std::shared_ptr<DBEvent> &event) const;
47 QString catalogueUniqueKey(const std::shared_ptr<DBCatalogue> &catalogue) const;
43
48
44 void copyDBtoDB(const QString &dbFrom, const QString &dbTo);
49 void copyDBtoDB(const QString &dbFrom, const QString &dbTo);
45 QString toWorkRepository(QString repository);
50 QString toWorkRepository(QString repository);
@@ -48,6 +53,9 public:
48
53
49 void saveEvent(std::shared_ptr<DBEvent> event, bool persist = true);
54 void saveEvent(std::shared_ptr<DBEvent> event, bool persist = true);
50 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool persist = true);
55 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool persist = true);
56
57 std::shared_ptr<IRequestPredicate> createFinder(const QUuid &uniqId, const QString &repository,
58 DBType type);
51 };
59 };
52
60
53 CatalogueController::CatalogueController(QObject *parent)
61 CatalogueController::CatalogueController(QObject *parent)
@@ -142,7 +150,7 void CatalogueController::updateEvent(std::shared_ptr<DBEvent> event)
142 event->setRepository(impl->toWorkRepository(event->getRepository()));
150 event->setRepository(impl->toWorkRepository(event->getRepository()));
143
151
144 auto uniqueId = impl->eventUniqueKey(event);
152 auto uniqueId = impl->eventUniqueKey(event);
145 impl->m_EventKeysWithChanges.insert(uniqueId);
153 impl->m_KeysWithChanges.insert(uniqueId);
146
154
147 impl->m_CatalogueDao.updateEvent(*event);
155 impl->m_CatalogueDao.updateEvent(*event);
148 }
156 }
@@ -184,53 +192,26 void CatalogueController::addEvent(std::shared_ptr<DBEvent> event)
184 impl->m_CatalogueDao.updateEvent(eventTemp);
192 impl->m_CatalogueDao.updateEvent(eventTemp);
185 }
193 }
186
194
187 // update event parameter
195 auto workPred = impl->createFinder(event->getUniqId(), event->getRepository(), DBType::WORK);
188 auto uniqIdPredicate = std::make_shared<ComparaisonPredicate>(
189 QString{"uniqId"}, event->getUniqId(), ComparaisonOperation::EQUALEQUAL);
190
191 auto workRepositoryPredicate = std::make_shared<ComparaisonPredicate>(
192 QString{"repository"}, impl->toWorkRepository(event->getRepository()),
193 ComparaisonOperation::EQUALEQUAL);
194
195 auto workPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND);
196 workPred->AddRequestPredicate(uniqIdPredicate);
197 workPred->AddRequestPredicate(workRepositoryPredicate);
198
196
199 auto workEvent = impl->m_CatalogueDao.getEvent(workPred);
197 auto workEvent = impl->m_CatalogueDao.getEvent(workPred);
200 *event = workEvent;
198 *event = workEvent;
201
199
200
202 auto uniqueId = impl->eventUniqueKey(event);
201 auto uniqueId = impl->eventUniqueKey(event);
203 impl->m_EventKeysWithChanges.insert(uniqueId);
202 impl->m_KeysWithChanges.insert(uniqueId);
204 }
203 }
205
204
206 void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event)
205 void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event)
207 {
206 {
208 impl->saveEvent(event, true);
207 impl->saveEvent(event, true);
209 impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event));
208 impl->m_KeysWithChanges.remove(impl->eventUniqueKey(event));
210 }
209 }
211
210
212 void CatalogueController::discardEvent(std::shared_ptr<DBEvent> event, bool &removed)
211 void CatalogueController::discardEvent(std::shared_ptr<DBEvent> event, bool &removed)
213 {
212 {
214 auto uniqIdPredicate = std::make_shared<ComparaisonPredicate>(
213 auto syncPred = impl->createFinder(event->getUniqId(), event->getRepository(), DBType::SYNC);
215 QString{"uniqId"}, event->getUniqId(), ComparaisonOperation::EQUALEQUAL);
214 auto workPred = impl->createFinder(event->getUniqId(), event->getRepository(), DBType::WORK);
216
217 auto syncRepositoryPredicate = std::make_shared<ComparaisonPredicate>(
218 QString{"repository"}, impl->toSyncRepository(event->getRepository()),
219 ComparaisonOperation::EQUALEQUAL);
220
221 auto syncPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND);
222 syncPred->AddRequestPredicate(uniqIdPredicate);
223 syncPred->AddRequestPredicate(syncRepositoryPredicate);
224
225
226 auto workRepositoryPredicate = std::make_shared<ComparaisonPredicate>(
227 QString{"repository"}, impl->toWorkRepository(event->getRepository()),
228 ComparaisonOperation::EQUALEQUAL);
229
230 auto workPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND);
231 workPred->AddRequestPredicate(uniqIdPredicate);
232 workPred->AddRequestPredicate(workRepositoryPredicate);
233
234
215
235 auto syncEvent = impl->m_CatalogueDao.getEvent(syncPred);
216 auto syncEvent = impl->m_CatalogueDao.getEvent(syncPred);
236 if (!syncEvent.getUniqId().isNull()) {
217 if (!syncEvent.getUniqId().isNull()) {
@@ -240,7 +221,7 void CatalogueController::discardEvent(std::shared_ptr<DBEvent> event, bool &rem
240
221
241 auto workEvent = impl->m_CatalogueDao.getEvent(workPred);
222 auto workEvent = impl->m_CatalogueDao.getEvent(workPred);
242 *event = workEvent;
223 *event = workEvent;
243 impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event));
224 impl->m_KeysWithChanges.remove(impl->eventUniqueKey(event));
244 }
225 }
245 else {
226 else {
246 removed = true;
227 removed = true;
@@ -252,7 +233,7 void CatalogueController::discardEvent(std::shared_ptr<DBEvent> event, bool &rem
252
233
253 bool CatalogueController::eventHasChanges(std::shared_ptr<DBEvent> event) const
234 bool CatalogueController::eventHasChanges(std::shared_ptr<DBEvent> event) const
254 {
235 {
255 return impl->m_EventKeysWithChanges.contains(impl->eventUniqueKey(event));
236 return impl->m_KeysWithChanges.contains(impl->eventUniqueKey(event));
256 }
237 }
257
238
258 std::list<std::shared_ptr<DBCatalogue> >
239 std::list<std::shared_ptr<DBCatalogue> >
@@ -268,10 +249,30 CatalogueController::retrieveCatalogues(const QString &repository) const
268 return cataloguesShared;
249 return cataloguesShared;
269 }
250 }
270
251
252 void CatalogueController::addCatalogue(std::shared_ptr<DBCatalogue> catalogue)
253 {
254 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
255
256 auto catalogueTemp = *catalogue;
257 impl->m_CatalogueDao.addCatalogue(catalogueTemp);
258
259 auto workPred
260 = impl->createFinder(catalogue->getUniqId(), catalogue->getRepository(), DBType::WORK);
261
262 auto workCatalogue = impl->m_CatalogueDao.getCatalogue(workPred);
263 *catalogue = workCatalogue;
264
265 auto uniqueId = impl->catalogueUniqueKey(catalogue);
266 impl->m_KeysWithChanges.insert(uniqueId);
267 }
268
271 void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue)
269 void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue)
272 {
270 {
273 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
271 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
274
272
273 auto uniqueId = impl->catalogueUniqueKey(catalogue);
274 impl->m_KeysWithChanges.insert(uniqueId);
275
275 impl->m_CatalogueDao.updateCatalogue(*catalogue);
276 impl->m_CatalogueDao.updateCatalogue(*catalogue);
276 }
277 }
277
278
@@ -282,11 +283,38 void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue
282 impl->m_CatalogueDao.removeCatalogue(*catalogue);
283 impl->m_CatalogueDao.removeCatalogue(*catalogue);
283 catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository()));
284 catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository()));
284 impl->m_CatalogueDao.removeCatalogue(*catalogue);
285 impl->m_CatalogueDao.removeCatalogue(*catalogue);
286 impl->savAllDB();
285 }
287 }
286
288
287 void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue)
289 void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue)
288 {
290 {
289 impl->saveCatalogue(catalogue, true);
291 impl->saveCatalogue(catalogue, true);
292 impl->m_KeysWithChanges.remove(impl->catalogueUniqueKey(catalogue));
293 }
294
295 void CatalogueController::discardCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool &removed)
296 {
297 auto syncPred
298 = impl->createFinder(catalogue->getUniqId(), catalogue->getRepository(), DBType::SYNC);
299 auto workPred
300 = impl->createFinder(catalogue->getUniqId(), catalogue->getRepository(), DBType::WORK);
301
302 auto syncCatalogue = impl->m_CatalogueDao.getCatalogue(syncPred);
303 if (!syncCatalogue.getUniqId().isNull()) {
304 removed = false;
305 impl->m_CatalogueDao.copyCatalogue(
306 syncCatalogue, impl->toWorkRepository(catalogue->getRepository()), true);
307
308 auto workCatalogue = impl->m_CatalogueDao.getCatalogue(workPred);
309 *catalogue = workCatalogue;
310 impl->m_KeysWithChanges.remove(impl->catalogueUniqueKey(catalogue));
311 }
312 else {
313 removed = true;
314 // Since the element wasn't in sync repository. Discard it means remove it
315 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
316 impl->m_CatalogueDao.removeCatalogue(*catalogue);
317 }
290 }
318 }
291
319
292 void CatalogueController::saveAll()
320 void CatalogueController::saveAll()
@@ -306,12 +334,12 void CatalogueController::saveAll()
306 }
334 }
307
335
308 impl->savAllDB();
336 impl->savAllDB();
309 impl->m_EventKeysWithChanges.clear();
337 impl->m_KeysWithChanges.clear();
310 }
338 }
311
339
312 bool CatalogueController::hasChanges() const
340 bool CatalogueController::hasChanges() const
313 {
341 {
314 return !impl->m_EventKeysWithChanges.isEmpty(); // TODO: catalogues
342 return !impl->m_KeysWithChanges.isEmpty();
315 }
343 }
316
344
317 QByteArray
345 QByteArray
@@ -400,6 +428,12 QString CatalogueController::CatalogueControllerPrivate::eventUniqueKey(
400 return event->getUniqId().toString().append(event->getRepository());
428 return event->getUniqId().toString().append(event->getRepository());
401 }
429 }
402
430
431 QString CatalogueController::CatalogueControllerPrivate::catalogueUniqueKey(
432 const std::shared_ptr<DBCatalogue> &catalogue) const
433 {
434 return catalogue->getUniqId().toString().append(catalogue->getRepository());
435 }
436
403 void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom,
437 void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom,
404 const QString &dbTo)
438 const QString &dbTo)
405 {
439 {
@@ -460,3 +494,33 void CatalogueController::CatalogueControllerPrivate::saveCatalogue(
460 savAllDB();
494 savAllDB();
461 }
495 }
462 }
496 }
497
498 std::shared_ptr<IRequestPredicate> CatalogueController::CatalogueControllerPrivate::createFinder(
499 const QUuid &uniqId, const QString &repository, DBType type)
500 {
501 // update catalogue parameter
502 auto uniqIdPredicate = std::make_shared<ComparaisonPredicate>(QString{"uniqId"}, uniqId,
503 ComparaisonOperation::EQUALEQUAL);
504
505 auto repositoryType = repository;
506 switch (type) {
507 case DBType::SYNC:
508 repositoryType = toSyncRepository(repositoryType);
509 break;
510 case DBType::WORK:
511 repositoryType = toWorkRepository(repositoryType);
512 break;
513 case DBType::TRASH:
514 default:
515 break;
516 }
517
518 auto repositoryPredicate = std::make_shared<ComparaisonPredicate>(
519 QString{"repository"}, repositoryType, ComparaisonOperation::EQUALEQUAL);
520
521 auto finderPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND);
522 finderPred->AddRequestPredicate(uniqIdPredicate);
523 finderPred->AddRequestPredicate(repositoryPredicate);
524
525 return finderPred;
526 }
@@ -6,6 +6,7
6 #include <QTreeWidgetItem>
6 #include <QTreeWidgetItem>
7 #include <QWidget>
7 #include <QWidget>
8
8
9 class CatalogueAbstractTreeItem;
9 class DBCatalogue;
10 class DBCatalogue;
10
11
11 namespace Ui {
12 namespace Ui {
@@ -28,11 +29,15 public:
28 explicit CatalogueSideBarWidget(QWidget *parent = 0);
29 explicit CatalogueSideBarWidget(QWidget *parent = 0);
29 virtual ~CatalogueSideBarWidget();
30 virtual ~CatalogueSideBarWidget();
30
31
31 void addCatalogue(const std::shared_ptr<DBCatalogue> &catalogue, const QString &repository);
32 CatalogueAbstractTreeItem *addCatalogue(const std::shared_ptr<DBCatalogue> &catalogue,
33 const QString &repository);
32 void setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue, bool hasChanges);
34 void setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue, bool hasChanges);
33
35
34 QVector<std::shared_ptr<DBCatalogue> > getCatalogues(const QString &repository) const;
36 QVector<std::shared_ptr<DBCatalogue> > getCatalogues(const QString &repository) const;
35
37
38 private slots:
39 void emitSelection();
40
36 private:
41 private:
37 Ui::CatalogueSideBarWidget *ui;
42 Ui::CatalogueSideBarWidget *ui;
38
43
@@ -15,6 +15,7 public:
15 virtual ~CatalogueAbstractTreeItem();
15 virtual ~CatalogueAbstractTreeItem();
16
16
17 void addChild(CatalogueAbstractTreeItem *child);
17 void addChild(CatalogueAbstractTreeItem *child);
18 void removeChild(CatalogueAbstractTreeItem *child);
18 QVector<CatalogueAbstractTreeItem *> children() const;
19 QVector<CatalogueAbstractTreeItem *> children() const;
19 CatalogueAbstractTreeItem *parent() const;
20 CatalogueAbstractTreeItem *parent() const;
20
21
@@ -27,6 +27,9 public:
27 QVector<CatalogueAbstractTreeItem *> topLevelItems() const;
27 QVector<CatalogueAbstractTreeItem *> topLevelItems() const;
28
28
29 void addChildItem(CatalogueAbstractTreeItem *child, const QModelIndex &parentIndex);
29 void addChildItem(CatalogueAbstractTreeItem *child, const QModelIndex &parentIndex);
30 void removeChildItem(CatalogueAbstractTreeItem *child, const QModelIndex &parentIndex);
31 /// Refresh the data for the specified index
32 void refresh(const QModelIndex &index);
30
33
31 CatalogueAbstractTreeItem *item(const QModelIndex &index) const;
34 CatalogueAbstractTreeItem *item(const QModelIndex &index) const;
32 QModelIndex indexOf(CatalogueAbstractTreeItem *item, int column = 0) const;
35 QModelIndex indexOf(CatalogueAbstractTreeItem *item, int column = 0) const;
@@ -69,8 +69,8 struct CatalogueActionManager::CatalogueActionManagerPrivate {
69
69
70
70
71 if (catalogue) {
71 if (catalogue) {
72 // TODO
72 catalogue->addEvent(event->getUniqId());
73 // catalogue->addEvent(event);
73 sqpApp->catalogueController().updateCatalogue(catalogue);
74 m_CatalogueExplorer->sideBarWidget().setCatalogueChanges(catalogue, true);
74 m_CatalogueExplorer->sideBarWidget().setCatalogueChanges(catalogue, true);
75 if (m_CatalogueExplorer->eventsWidget().displayedCatalogues().contains(catalogue)) {
75 if (m_CatalogueExplorer->eventsWidget().displayedCatalogues().contains(catalogue)) {
76 m_CatalogueExplorer->eventsWidget().addEvent(event);
76 m_CatalogueExplorer->eventsWidget().addEvent(event);
@@ -135,7 +135,7 void CatalogueActionManager::installSelectionZoneActions()
135 if (!selectedCatalogue) {
135 if (!selectedCatalogue) {
136 selectedCatalogue = std::make_shared<DBCatalogue>();
136 selectedCatalogue = std::make_shared<DBCatalogue>();
137 selectedCatalogue->setName(dialog.catalogueName());
137 selectedCatalogue->setName(dialog.catalogueName());
138 // sqpApp->catalogueController().addCatalogue(selectedCatalogue); TODO
138 sqpApp->catalogueController().addCatalogue(selectedCatalogue);
139 impl->m_CatalogueExplorer->sideBarWidget().addCatalogue(selectedCatalogue,
139 impl->m_CatalogueExplorer->sideBarWidget().addCatalogue(selectedCatalogue,
140 REPOSITORY_DEFAULT);
140 REPOSITORY_DEFAULT);
141 }
141 }
@@ -12,6 +12,7
12 #include <DBCatalogue.h>
12 #include <DBCatalogue.h>
13
13
14 #include <QMenu>
14 #include <QMenu>
15 #include <QMessageBox>
15
16
16 Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget")
17 Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget")
17
18
@@ -29,11 +30,11 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate {
29 void configureTreeWidget(QTreeView *treeView);
30 void configureTreeWidget(QTreeView *treeView);
30 QModelIndex addDatabaseItem(const QString &name);
31 QModelIndex addDatabaseItem(const QString &name);
31 CatalogueAbstractTreeItem *getDatabaseItem(const QString &name);
32 CatalogueAbstractTreeItem *getDatabaseItem(const QString &name);
32 void addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
33 CatalogueAbstractTreeItem *addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
33 const QModelIndex &databaseIndex);
34 const QModelIndex &databaseIndex);
34
35
35 CatalogueTreeItem *getCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue) const;
36 CatalogueTreeItem *getCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue) const;
36 void setHasChanges(bool value, const QModelIndex &index, QTreeView *treeView);
37 void setHasChanges(bool value, const QModelIndex &index, CatalogueSideBarWidget *sideBarWidget);
37 bool hasChanges(const QModelIndex &index, QTreeView *treeView);
38 bool hasChanges(const QModelIndex &index, QTreeView *treeView);
38
39
39 int selectionType(QTreeView *treeView) const
40 int selectionType(QTreeView *treeView) const
@@ -109,39 +110,66 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
109 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
110 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
110 ui->treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
111 ui->treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
111
112
112 auto emitSelection = [this]() {
113 connect(ui->treeView, &QTreeView::clicked, this, &CatalogueSideBarWidget::emitSelection);
113
114 connect(ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, this,
114 auto selectionType = impl->selectionType(ui->treeView);
115 &CatalogueSideBarWidget::emitSelection);
115
116
116 switch (selectionType) {
117
117 case CATALOGUE_ITEM_TYPE:
118 connect(ui->btnAdd, &QToolButton::clicked, [this]() {
118 emit this->catalogueSelected(impl->selectedCatalogues(ui->treeView));
119 auto catalogue = std::make_shared<DBCatalogue>();
119 break;
120 catalogue->setName(QString("Cat"));
120 case DATABASE_ITEM_TYPE:
121 sqpApp->catalogueController().addCatalogue(catalogue);
121 emit this->databaseSelected(impl->selectedRepositories(ui->treeView));
122 auto item = this->addCatalogue(catalogue, REPOSITORY_DEFAULT);
122 break;
123 this->setCatalogueChanges(catalogue, true);
123 case ALL_EVENT_ITEM_TYPE:
124 ui->treeView->edit(impl->m_TreeModel->indexOf(item));
124 emit this->allEventsSelected();
125
125 break;
126 });
126 case TRASH_ITEM_TYPE:
127
127 emit this->trashSelected();
128
128 break;
129 connect(impl->m_TreeModel, &CatalogueTreeModel::itemDropped, [this](auto index) {
129 default:
130 auto item = impl->m_TreeModel->item(index);
130 emit this->selectionCleared();
131 if (item && item->type() == CATALOGUE_ITEM_TYPE) {
131 break;
132 auto catalogue = static_cast<CatalogueTreeItem *>(item)->catalogue();
133 this->setCatalogueChanges(catalogue, true);
134 }
135 });
136 connect(ui->btnRemove, &QToolButton::clicked, [this]() {
137 QVector<QPair<std::shared_ptr<DBCatalogue>, CatalogueAbstractTreeItem *> >
138 cataloguesToItems;
139 auto selectedIndexes = ui->treeView->selectionModel()->selectedRows();
140
141 for (auto index : selectedIndexes) {
142 auto item = impl->m_TreeModel->item(index);
143 if (item && item->type() == CATALOGUE_ITEM_TYPE) {
144 auto catalogue = static_cast<CatalogueTreeItem *>(item)->catalogue();
145 cataloguesToItems << qMakePair(catalogue, item);
146 }
132 }
147 }
133 };
134
148
135 connect(ui->treeView, &QTreeView::clicked, emitSelection);
149 if (!cataloguesToItems.isEmpty()) {
136 connect(ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, emitSelection);
150
137 connect(impl->m_TreeModel, &CatalogueTreeModel::itemRenamed, [emitSelection, this](auto index) {
151 if (QMessageBox::warning(this, tr("Remove Catalogue(s)"),
152 tr("The selected catalogues(s) will be completly removed "
153 "from the repository!\nAre you sure you want to continue?"),
154 QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
155 == QMessageBox::Yes) {
156
157 for (auto catalogueToItem : cataloguesToItems) {
158 sqpApp->catalogueController().removeCatalogue(catalogueToItem.first);
159 impl->m_TreeModel->removeChildItem(
160 catalogueToItem.second,
161 impl->m_TreeModel->indexOf(catalogueToItem.second->parent()));
162 }
163 }
164 }
165 });
166
167 connect(impl->m_TreeModel, &CatalogueTreeModel::itemRenamed, [this](auto index) {
138 auto selectedIndexes = ui->treeView->selectionModel()->selectedRows();
168 auto selectedIndexes = ui->treeView->selectionModel()->selectedRows();
139 if (selectedIndexes.contains(index)) {
169 if (selectedIndexes.contains(index)) {
140 emitSelection();
170 this->emitSelection();
141 }
171 }
142
172 impl->setHasChanges(true, index, this);
143 auto item = impl->m_TreeModel->item(index);
144 impl->setHasChanges(true, index, ui->treeView);
145 });
173 });
146
174
147 ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
175 ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -154,11 +182,12 CatalogueSideBarWidget::~CatalogueSideBarWidget()
154 delete ui;
182 delete ui;
155 }
183 }
156
184
157 void CatalogueSideBarWidget::addCatalogue(const std::shared_ptr<DBCatalogue> &catalogue,
185 CatalogueAbstractTreeItem *
158 const QString &repository)
186 CatalogueSideBarWidget::addCatalogue(const std::shared_ptr<DBCatalogue> &catalogue,
187 const QString &repository)
159 {
188 {
160 auto repositoryItem = impl->getDatabaseItem(repository);
189 auto repositoryItem = impl->getDatabaseItem(repository);
161 impl->addCatalogueItem(catalogue, impl->m_TreeModel->indexOf(repositoryItem));
190 return impl->addCatalogueItem(catalogue, impl->m_TreeModel->indexOf(repositoryItem));
162 }
191 }
163
192
164 void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue,
193 void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue,
@@ -166,7 +195,7 void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalog
166 {
195 {
167 if (auto catalogueItem = impl->getCatalogueItem(catalogue)) {
196 if (auto catalogueItem = impl->getCatalogueItem(catalogue)) {
168 auto index = impl->m_TreeModel->indexOf(catalogueItem);
197 auto index = impl->m_TreeModel->indexOf(catalogueItem);
169 impl->setHasChanges(hasChanges, index, ui->treeView);
198 impl->setHasChanges(hasChanges, index, this);
170 // catalogueItem->refresh();
199 // catalogueItem->refresh();
171 }
200 }
172 }
201 }
@@ -189,6 +218,29 CatalogueSideBarWidget::getCatalogues(const QString &repository) const
189 return result;
218 return result;
190 }
219 }
191
220
221 void CatalogueSideBarWidget::emitSelection()
222 {
223 auto selectionType = impl->selectionType(ui->treeView);
224
225 switch (selectionType) {
226 case CATALOGUE_ITEM_TYPE:
227 emit this->catalogueSelected(impl->selectedCatalogues(ui->treeView));
228 break;
229 case DATABASE_ITEM_TYPE:
230 emit this->databaseSelected(impl->selectedRepositories(ui->treeView));
231 break;
232 case ALL_EVENT_ITEM_TYPE:
233 emit this->allEventsSelected();
234 break;
235 case TRASH_ITEM_TYPE:
236 emit this->trashSelected();
237 break;
238 default:
239 emit this->selectionCleared();
240 break;
241 }
242 }
243
192 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
244 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
193 {
245 {
194 QMenu menu{this};
246 QMenu menu{this};
@@ -274,12 +326,14 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QSt
274 return nullptr;
326 return nullptr;
275 }
327 }
276
328
277 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem(
329 CatalogueAbstractTreeItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem(
278 const std::shared_ptr<DBCatalogue> &catalogue, const QModelIndex &databaseIndex)
330 const std::shared_ptr<DBCatalogue> &catalogue, const QModelIndex &databaseIndex)
279 {
331 {
280 auto catalogueItem
332 auto catalogueItem
281 = new CatalogueTreeItem{catalogue, QIcon{":/icones/catalogue.png"}, CATALOGUE_ITEM_TYPE};
333 = new CatalogueTreeItem{catalogue, QIcon{":/icones/catalogue.png"}, CATALOGUE_ITEM_TYPE};
282 m_TreeModel->addChildItem(catalogueItem, databaseIndex);
334 m_TreeModel->addChildItem(catalogueItem, databaseIndex);
335
336 return catalogueItem;
283 }
337 }
284
338
285 CatalogueTreeItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCatalogueItem(
339 CatalogueTreeItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCatalogueItem(
@@ -307,25 +361,48 CatalogueTreeItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCat
307 return nullptr;
361 return nullptr;
308 }
362 }
309
363
310 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::setHasChanges(bool value,
364 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::setHasChanges(
311 const QModelIndex &index,
365 bool value, const QModelIndex &index, CatalogueSideBarWidget *sideBarWidget)
312 QTreeView *treeView)
313 {
366 {
367 std::shared_ptr<DBCatalogue> catalogue = nullptr;
368 auto item = m_TreeModel->item(index);
369 if (item && item->type() == CATALOGUE_ITEM_TYPE) {
370 catalogue = static_cast<CatalogueTreeItem *>(item)->catalogue();
371 }
372
314 auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation);
373 auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation);
315 if (value) {
374 if (value) {
316 if (!hasChanges(validationIndex, treeView)) {
375 if (!hasChanges(validationIndex, sideBarWidget->ui->treeView)) {
317 auto widget = CatalogueExplorerHelper::buildValidationWidget(
376 auto widget = CatalogueExplorerHelper::buildValidationWidget(
318 treeView, [this, validationIndex,
377 sideBarWidget->ui->treeView,
319 treeView]() { setHasChanges(false, validationIndex, treeView); },
378 [this, validationIndex, sideBarWidget, catalogue]() {
320 [this, validationIndex, treeView]() {
379 if (catalogue) {
321 setHasChanges(false, validationIndex, treeView);
380 sqpApp->catalogueController().saveCatalogue(catalogue);
381 }
382 setHasChanges(false, validationIndex, sideBarWidget);
383 },
384 [this, validationIndex, sideBarWidget, catalogue, item]() {
385 if (catalogue) {
386 bool removed;
387 sqpApp->catalogueController().discardCatalogue(catalogue, removed);
388
389 if (removed) {
390 m_TreeModel->removeChildItem(item,
391 m_TreeModel->indexOf(item->parent()));
392 }
393 else {
394 m_TreeModel->refresh(m_TreeModel->indexOf(item));
395 setHasChanges(false, validationIndex, sideBarWidget);
396 }
397 sideBarWidget->emitSelection();
398 }
322 });
399 });
323 treeView->setIndexWidget(validationIndex, widget);
400 sideBarWidget->ui->treeView->setIndexWidget(validationIndex, widget);
324 }
401 }
325 }
402 }
326 else {
403 else {
327 // Note: the widget is destroyed
404 // Note: the widget is destroyed
328 treeView->setIndexWidget(validationIndex, nullptr);
405 sideBarWidget->ui->treeView->setIndexWidget(validationIndex, nullptr);
329 }
406 }
330 }
407 }
331
408
@@ -24,6 +24,12 void CatalogueAbstractTreeItem::addChild(CatalogueAbstractTreeItem *child)
24 child->impl->m_Parent = this;
24 child->impl->m_Parent = this;
25 }
25 }
26
26
27 void CatalogueAbstractTreeItem::removeChild(CatalogueAbstractTreeItem *child)
28 {
29 impl->m_Children.removeAll(child);
30 delete child;
31 }
32
27 QVector<CatalogueAbstractTreeItem *> CatalogueAbstractTreeItem::children() const
33 QVector<CatalogueAbstractTreeItem *> CatalogueAbstractTreeItem::children() const
28 {
34 {
29 return impl->m_Children;
35 return impl->m_Children;
@@ -76,17 +76,27 Qt::ItemFlags CatalogueTreeItem::flags(int column) const
76
76
77 bool CatalogueTreeItem::canDropMimeData(const QMimeData *data, Qt::DropAction action)
77 bool CatalogueTreeItem::canDropMimeData(const QMimeData *data, Qt::DropAction action)
78 {
78 {
79 return data->hasFormat(MIME_TYPE_EVENT_LIST);
79 auto events = sqpApp->catalogueController().eventsForMimeData(data->data(MIME_TYPE_EVENT_LIST));
80 auto canDrop = data->hasFormat(MIME_TYPE_EVENT_LIST);
81
82 for (auto event : events) {
83 canDrop &= (event->getRepository() == impl->m_Catalogue->getRepository());
84 }
85 return canDrop;
80 }
86 }
81
87
82 bool CatalogueTreeItem::dropMimeData(const QMimeData *data, Qt::DropAction action)
88 bool CatalogueTreeItem::dropMimeData(const QMimeData *data, Qt::DropAction action)
83 {
89 {
84 Q_ASSERT(canDropMimeData(data, action));
90 Q_ASSERT(canDropMimeData(data, action));
85
86 auto events = sqpApp->catalogueController().eventsForMimeData(data->data(MIME_TYPE_EVENT_LIST));
87 // impl->m_Catalogue->addEvents(events); TODO: move events in the new catalogue
88 // Warning: Check that the events aren't already in the catalogue
91 // Warning: Check that the events aren't already in the catalogue
89 // Also check for the repository !!!
92 // Also check for the repository !!!
93
94 auto events = sqpApp->catalogueController().eventsForMimeData(data->data(MIME_TYPE_EVENT_LIST));
95
96 for (auto event : events) {
97 impl->m_Catalogue->addEvent(event->getUniqId());
98 sqpApp->catalogueController().updateCatalogue(impl->m_Catalogue);
99 }
90 }
100 }
91
101
92 std::shared_ptr<DBCatalogue> CatalogueTreeItem::catalogue() const
102 std::shared_ptr<DBCatalogue> CatalogueTreeItem::catalogue() const
@@ -46,6 +46,23 void CatalogueTreeModel::addChildItem(CatalogueAbstractTreeItem *child,
46 emit dataChanged(parentIndex, parentIndex);
46 emit dataChanged(parentIndex, parentIndex);
47 }
47 }
48
48
49 void CatalogueTreeModel::removeChildItem(CatalogueAbstractTreeItem *child,
50 const QModelIndex &parentIndex)
51 {
52 auto parentItem = item(parentIndex);
53 int i = parentItem->children().indexOf(child);
54 beginRemoveRows(parentIndex, i, i);
55 parentItem->removeChild(child);
56 endRemoveRows();
57
58 emit dataChanged(parentIndex, parentIndex);
59 }
60
61 void CatalogueTreeModel::refresh(const QModelIndex &index)
62 {
63 emit dataChanged(index, index);
64 }
65
49 CatalogueAbstractTreeItem *CatalogueTreeModel::item(const QModelIndex &index) const
66 CatalogueAbstractTreeItem *CatalogueTreeModel::item(const QModelIndex &index) const
50 {
67 {
51 return static_cast<CatalogueAbstractTreeItem *>(index.internalPointer());
68 return static_cast<CatalogueAbstractTreeItem *>(index.internalPointer());
@@ -303,7 +303,6 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, S
303 this->setFlags(GraphFlag::DisableAll);
303 this->setFlags(GraphFlag::DisableAll);
304 setGraphRange(range);
304 setGraphRange(range);
305 this->setFlags(GraphFlag::EnableAll);
305 this->setFlags(GraphFlag::EnableAll);
306
307 emit requestDataLoading({variable}, range, false);
306 emit requestDataLoading({variable}, range, false);
308 };
307 };
309
308
@@ -31,7 +31,7
31 <item>
31 <item>
32 <widget class="QToolButton" name="btnAdd">
32 <widget class="QToolButton" name="btnAdd">
33 <property name="enabled">
33 <property name="enabled">
34 <bool>false</bool>
34 <bool>true</bool>
35 </property>
35 </property>
36 <property name="text">
36 <property name="text">
37 <string>+</string>
37 <string>+</string>
@@ -48,7 +48,7
48 <item>
48 <item>
49 <widget class="QToolButton" name="btnRemove">
49 <widget class="QToolButton" name="btnRemove">
50 <property name="enabled">
50 <property name="enabled">
51 <bool>false</bool>
51 <bool>true</bool>
52 </property>
52 </property>
53 <property name="text">
53 <property name="text">
54 <string> - </string>
54 <string> - </string>
@@ -100,7 +100,6
100 </widget>
100 </widget>
101 <resources>
101 <resources>
102 <include location="../../resources/sqpguiresources.qrc"/>
102 <include location="../../resources/sqpguiresources.qrc"/>
103 <include location="../../resources/sqpguiresources.qrc"/>
104 </resources>
103 </resources>
105 <connections/>
104 <connections/>
106 </ui>
105 </ui>
General Comments 0
You need to be logged in to leave comments. Login now