##// END OF EJS Templates
Add catalogue handling
perrinel -
r1356:3771be3f513d
parent child
Show More
@@ -63,6 +63,7 public:
63 void updateCatalogue(std::shared_ptr<DBCatalogue> catalogue);
63 void updateCatalogue(std::shared_ptr<DBCatalogue> catalogue);
64 void removeCatalogue(std::shared_ptr<DBCatalogue> catalogue);
64 void removeCatalogue(std::shared_ptr<DBCatalogue> catalogue);
65 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);
66
67
67 void saveAll();
68 void saveAll();
68 bool hasChanges() const;
69 bool hasChanges() const;
@@ -41,9 +41,10 public:
41 QStringList m_RepositoryList;
41 QStringList m_RepositoryList;
42 CatalogueController *m_Q;
42 CatalogueController *m_Q;
43
43
44 QSet<QString> m_EventKeysWithChanges;
44 QSet<QString> m_KeysWithChanges;
45
45
46 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;
47
48
48 void copyDBtoDB(const QString &dbFrom, const QString &dbTo);
49 void copyDBtoDB(const QString &dbFrom, const QString &dbTo);
49 QString toWorkRepository(QString repository);
50 QString toWorkRepository(QString repository);
@@ -53,7 +54,8 public:
53 void saveEvent(std::shared_ptr<DBEvent> event, bool persist = true);
54 void saveEvent(std::shared_ptr<DBEvent> event, bool persist = true);
54 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool persist = true);
55 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool persist = true);
55
56
56 std::shared_ptr<IRequestPredicate> createFinder(const QUuid& uniqId, const QString & repository, DBType type);
57 std::shared_ptr<IRequestPredicate> createFinder(const QUuid &uniqId, const QString &repository,
58 DBType type);
57 };
59 };
58
60
59 CatalogueController::CatalogueController(QObject *parent)
61 CatalogueController::CatalogueController(QObject *parent)
@@ -148,7 +150,7 void CatalogueController::updateEvent(std::shared_ptr<DBEvent> event)
148 event->setRepository(impl->toWorkRepository(event->getRepository()));
150 event->setRepository(impl->toWorkRepository(event->getRepository()));
149
151
150 auto uniqueId = impl->eventUniqueKey(event);
152 auto uniqueId = impl->eventUniqueKey(event);
151 impl->m_EventKeysWithChanges.insert(uniqueId);
153 impl->m_KeysWithChanges.insert(uniqueId);
152
154
153 impl->m_CatalogueDao.updateEvent(*event);
155 impl->m_CatalogueDao.updateEvent(*event);
154 }
156 }
@@ -197,13 +199,13 void CatalogueController::addEvent(std::shared_ptr<DBEvent> event)
197
199
198
200
199 auto uniqueId = impl->eventUniqueKey(event);
201 auto uniqueId = impl->eventUniqueKey(event);
200 impl->m_EventKeysWithChanges.insert(uniqueId);
202 impl->m_KeysWithChanges.insert(uniqueId);
201 }
203 }
202
204
203 void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event)
205 void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event)
204 {
206 {
205 impl->saveEvent(event, true);
207 impl->saveEvent(event, true);
206 impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event));
208 impl->m_KeysWithChanges.remove(impl->eventUniqueKey(event));
207 }
209 }
208
210
209 void CatalogueController::discardEvent(std::shared_ptr<DBEvent> event, bool &removed)
211 void CatalogueController::discardEvent(std::shared_ptr<DBEvent> event, bool &removed)
@@ -219,7 +221,7 void CatalogueController::discardEvent(std::shared_ptr<DBEvent> event, bool &rem
219
221
220 auto workEvent = impl->m_CatalogueDao.getEvent(workPred);
222 auto workEvent = impl->m_CatalogueDao.getEvent(workPred);
221 *event = workEvent;
223 *event = workEvent;
222 impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event));
224 impl->m_KeysWithChanges.remove(impl->eventUniqueKey(event));
223 }
225 }
224 else {
226 else {
225 removed = true;
227 removed = true;
@@ -231,7 +233,7 void CatalogueController::discardEvent(std::shared_ptr<DBEvent> event, bool &rem
231
233
232 bool CatalogueController::eventHasChanges(std::shared_ptr<DBEvent> event) const
234 bool CatalogueController::eventHasChanges(std::shared_ptr<DBEvent> event) const
233 {
235 {
234 return impl->m_EventKeysWithChanges.contains(impl->eventUniqueKey(event));
236 return impl->m_KeysWithChanges.contains(impl->eventUniqueKey(event));
235 }
237 }
236
238
237 std::list<std::shared_ptr<DBCatalogue> >
239 std::list<std::shared_ptr<DBCatalogue> >
@@ -254,21 +256,22 void CatalogueController::addCatalogue(std::shared_ptr<DBCatalogue> catalogue)
254 auto catalogueTemp = *catalogue;
256 auto catalogueTemp = *catalogue;
255 impl->m_CatalogueDao.addCatalogue(catalogueTemp);
257 impl->m_CatalogueDao.addCatalogue(catalogueTemp);
256
258
257 auto workPred = impl->createFinder(catalogue->getUniqId(), catalogue->getRepository(), DBType::WORK);
259 auto workPred
260 = impl->createFinder(catalogue->getUniqId(), catalogue->getRepository(), DBType::WORK);
258
261
259 auto workCatalogue = impl->m_CatalogueDao.getCatalogue(workPred);
262 auto workCatalogue = impl->m_CatalogueDao.getCatalogue(workPred);
260 *catalogue = workCatalogue;
263 *catalogue = workCatalogue;
261
264
262 // auto uniqueId = impl->eventUniqueKey(catalogue);
265 auto uniqueId = impl->catalogueUniqueKey(catalogue);
263 // impl->m_EventKeysWithChanges.insert(uniqueId);
266 impl->m_KeysWithChanges.insert(uniqueId);
264 }
267 }
265
268
266 void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue)
269 void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue)
267 {
270 {
268 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
271 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
269
272
270 // auto uniqueId = impl->eventUniqueKey(event);
273 auto uniqueId = impl->catalogueUniqueKey(catalogue);
271 // impl->m_EventKeysWithChanges.insert(uniqueId);
274 impl->m_KeysWithChanges.insert(uniqueId);
272
275
273 impl->m_CatalogueDao.updateCatalogue(*catalogue);
276 impl->m_CatalogueDao.updateCatalogue(*catalogue);
274 }
277 }
@@ -286,7 +289,32 void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue
286 void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue)
289 void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue)
287 {
290 {
288 impl->saveCatalogue(catalogue, true);
291 impl->saveCatalogue(catalogue, true);
289 // impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event));
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 {
@@ -461,11 +495,12 void CatalogueController::CatalogueControllerPrivate::saveCatalogue(
461 }
495 }
462 }
496 }
463
497
464 std::shared_ptr<IRequestPredicate> CatalogueController::CatalogueControllerPrivate::createFinder(const QUuid &uniqId, const QString &repository, DBType type)
498 std::shared_ptr<IRequestPredicate> CatalogueController::CatalogueControllerPrivate::createFinder(
499 const QUuid &uniqId, const QString &repository, DBType type)
465 {
500 {
466 // update catalogue parameter
501 // update catalogue parameter
467 auto uniqIdPredicate = std::make_shared<ComparaisonPredicate>(
502 auto uniqIdPredicate = std::make_shared<ComparaisonPredicate>(QString{"uniqId"}, uniqId,
468 QString{"uniqId"}, uniqId, ComparaisonOperation::EQUALEQUAL);
503 ComparaisonOperation::EQUALEQUAL);
469
504
470 auto repositoryType = repository;
505 auto repositoryType = repository;
471 switch (type) {
506 switch (type) {
@@ -481,8 +516,7 std::shared_ptr<IRequestPredicate> CatalogueController::CatalogueControllerPriva
481 }
516 }
482
517
483 auto repositoryPredicate = std::make_shared<ComparaisonPredicate>(
518 auto repositoryPredicate = std::make_shared<ComparaisonPredicate>(
484 QString{"repository"}, repositoryType,
519 QString{"repository"}, repositoryType, ComparaisonOperation::EQUALEQUAL);
485 ComparaisonOperation::EQUALEQUAL);
486
520
487 auto finderPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND);
521 auto finderPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND);
488 finderPred->AddRequestPredicate(uniqIdPredicate);
522 finderPred->AddRequestPredicate(uniqIdPredicate);
@@ -33,6 +33,9 public:
33
33
34 QVector<std::shared_ptr<DBCatalogue> > getCatalogues(const QString &repository) const;
34 QVector<std::shared_ptr<DBCatalogue> > getCatalogues(const QString &repository) const;
35
35
36 private slots:
37 void emitSelection();
38
36 private:
39 private:
37 Ui::CatalogueSideBarWidget *ui;
40 Ui::CatalogueSideBarWidget *ui;
38
41
@@ -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
@@ -33,7 +34,7 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate {
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,77 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);
114 connect(ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, this,
115 &CatalogueSideBarWidget::emitSelection);
113
116
114 auto selectionType = impl->selectionType(ui->treeView);
115
117
116 switch (selectionType) {
118 // connect(ui->btnAdd, &QToolButton::clicked, [this]() {
117 case CATALOGUE_ITEM_TYPE:
119 // QVector<std::shared_ptr<DBCatalogue> > catalogues;
118 emit this->catalogueSelected(impl->selectedCatalogues(ui->treeView));
120 // impl->getSelectedItems(ui->treeView, events, eventProducts);
119 break;
121
120 case DATABASE_ITEM_TYPE:
122 // if (!events.isEmpty() && eventProducts.isEmpty()) {
121 emit this->databaseSelected(impl->selectedRepositories(ui->treeView));
123
122 break;
124 // if (QMessageBox::warning(this, tr("Remove Event(s)"),
123 case ALL_EVENT_ITEM_TYPE:
125 // tr("The selected event(s) will be completly removed "
124 emit this->allEventsSelected();
126 // "from the repository!\nAre you sure you want to
125 break;
127 // continue?"),
126 case TRASH_ITEM_TYPE:
128 // QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
127 emit this->trashSelected();
129 // == QMessageBox::Yes) {
128 break;
130
129 default:
131 // for (auto event : events) {
130 emit this->selectionCleared();
132 // sqpApp->catalogueController().removeEvent(event);
131 break;
133 // impl->removeEvent(event, ui->treeView);
134 // }
135 // }
136 // }
137 // });
138
139
140 connect(impl->m_TreeModel, &CatalogueTreeModel::itemDropped, [this](auto index) {
141 auto item = impl->m_TreeModel->item(index);
142 if (item && item->type() == CATALOGUE_ITEM_TYPE) {
143 auto catalogue = static_cast<CatalogueTreeItem *>(item)->catalogue();
144 this->setCatalogueChanges(catalogue, true);
132 }
145 }
133 };
146 });
147 connect(ui->btnRemove, &QToolButton::clicked, [this]() {
148 QVector<QPair<std::shared_ptr<DBCatalogue>, CatalogueAbstractTreeItem *> >
149 cataloguesToItems;
150 auto selectedIndexes = ui->treeView->selectionModel()->selectedRows();
134
151
135 connect(ui->treeView, &QTreeView::clicked, emitSelection);
152 for (auto index : selectedIndexes) {
136 connect(ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, emitSelection);
153 auto item = impl->m_TreeModel->item(index);
137 connect(impl->m_TreeModel, &CatalogueTreeModel::itemRenamed, [emitSelection, this](auto index) {
154 if (item && item->type() == CATALOGUE_ITEM_TYPE) {
155 auto catalogue = static_cast<CatalogueTreeItem *>(item)->catalogue();
156 cataloguesToItems << qMakePair(catalogue, item);
157 }
158 }
159
160 if (!cataloguesToItems.isEmpty()) {
161
162 if (QMessageBox::warning(this, tr("Remove Catalogue(s)"),
163 tr("The selected catalogues(s) will be completly removed "
164 "from the repository!\nAre you sure you want to continue?"),
165 QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
166 == QMessageBox::Yes) {
167
168 for (auto catalogueToItem : cataloguesToItems) {
169 sqpApp->catalogueController().removeCatalogue(catalogueToItem.first);
170 impl->m_TreeModel->removeChildItem(
171 catalogueToItem.second,
172 impl->m_TreeModel->indexOf(catalogueToItem.second->parent()));
173 }
174 }
175 }
176 });
177
178 connect(impl->m_TreeModel, &CatalogueTreeModel::itemRenamed, [this](auto index) {
138 auto selectedIndexes = ui->treeView->selectionModel()->selectedRows();
179 auto selectedIndexes = ui->treeView->selectionModel()->selectedRows();
139 if (selectedIndexes.contains(index)) {
180 if (selectedIndexes.contains(index)) {
140 emitSelection();
181 this->emitSelection();
141 }
182 }
142
183 impl->setHasChanges(true, index, this);
143 auto item = impl->m_TreeModel->item(index);
144 impl->setHasChanges(true, index, ui->treeView);
145 });
184 });
146
185
147 ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
186 ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -166,7 +205,7 void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalog
166 {
205 {
167 if (auto catalogueItem = impl->getCatalogueItem(catalogue)) {
206 if (auto catalogueItem = impl->getCatalogueItem(catalogue)) {
168 auto index = impl->m_TreeModel->indexOf(catalogueItem);
207 auto index = impl->m_TreeModel->indexOf(catalogueItem);
169 impl->setHasChanges(hasChanges, index, ui->treeView);
208 impl->setHasChanges(hasChanges, index, this);
170 // catalogueItem->refresh();
209 // catalogueItem->refresh();
171 }
210 }
172 }
211 }
@@ -189,6 +228,29 CatalogueSideBarWidget::getCatalogues(const QString &repository) const
189 return result;
228 return result;
190 }
229 }
191
230
231 void CatalogueSideBarWidget::emitSelection()
232 {
233 auto selectionType = impl->selectionType(ui->treeView);
234
235 switch (selectionType) {
236 case CATALOGUE_ITEM_TYPE:
237 emit this->catalogueSelected(impl->selectedCatalogues(ui->treeView));
238 break;
239 case DATABASE_ITEM_TYPE:
240 emit this->databaseSelected(impl->selectedRepositories(ui->treeView));
241 break;
242 case ALL_EVENT_ITEM_TYPE:
243 emit this->allEventsSelected();
244 break;
245 case TRASH_ITEM_TYPE:
246 emit this->trashSelected();
247 break;
248 default:
249 emit this->selectionCleared();
250 break;
251 }
252 }
253
192 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
254 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
193 {
255 {
194 QMenu menu{this};
256 QMenu menu{this};
@@ -307,25 +369,48 CatalogueTreeItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCat
307 return nullptr;
369 return nullptr;
308 }
370 }
309
371
310 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::setHasChanges(bool value,
372 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::setHasChanges(
311 const QModelIndex &index,
373 bool value, const QModelIndex &index, CatalogueSideBarWidget *sideBarWidget)
312 QTreeView *treeView)
313 {
374 {
375 std::shared_ptr<DBCatalogue> catalogue = nullptr;
376 auto item = m_TreeModel->item(index);
377 if (item && item->type() == CATALOGUE_ITEM_TYPE) {
378 catalogue = static_cast<CatalogueTreeItem *>(item)->catalogue();
379 }
380
314 auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation);
381 auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation);
315 if (value) {
382 if (value) {
316 if (!hasChanges(validationIndex, treeView)) {
383 if (!hasChanges(validationIndex, sideBarWidget->ui->treeView)) {
317 auto widget = CatalogueExplorerHelper::buildValidationWidget(
384 auto widget = CatalogueExplorerHelper::buildValidationWidget(
318 treeView, [this, validationIndex,
385 sideBarWidget->ui->treeView,
319 treeView]() { setHasChanges(false, validationIndex, treeView); },
386 [this, validationIndex, sideBarWidget, catalogue]() {
320 [this, validationIndex, treeView]() {
387 if (catalogue) {
321 setHasChanges(false, validationIndex, treeView);
388 sqpApp->catalogueController().saveCatalogue(catalogue);
389 }
390 setHasChanges(false, validationIndex, sideBarWidget);
391 },
392 [this, validationIndex, sideBarWidget, catalogue, item]() {
393 if (catalogue) {
394 bool removed;
395 sqpApp->catalogueController().discardCatalogue(catalogue, removed);
396
397 if (removed) {
398 m_TreeModel->removeChildItem(item,
399 m_TreeModel->indexOf(item->parent()));
400 }
401 else {
402 m_TreeModel->refresh(m_TreeModel->indexOf(item));
403 setHasChanges(false, validationIndex, sideBarWidget);
404 }
405 sideBarWidget->emitSelection();
406 }
322 });
407 });
323 treeView->setIndexWidget(validationIndex, widget);
408 sideBarWidget->ui->treeView->setIndexWidget(validationIndex, widget);
324 }
409 }
325 }
410 }
326 else {
411 else {
327 // Note: the widget is destroyed
412 // Note: the widget is destroyed
328 treeView->setIndexWidget(validationIndex, nullptr);
413 sideBarWidget->ui->treeView->setIndexWidget(validationIndex, nullptr);
329 }
414 }
330 }
415 }
331
416
@@ -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());
@@ -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