diff --git a/core/include/Catalogue/CatalogueController.h b/core/include/Catalogue/CatalogueController.h index 4cc36ae..3218d28 100644 --- a/core/include/Catalogue/CatalogueController.h +++ b/core/include/Catalogue/CatalogueController.h @@ -55,13 +55,15 @@ public: // Catalogue std::list > retrieveEventsFromCatalogue(std::shared_ptr catalogue) const; - // bool createCatalogue(const QString &name, QVector eventList); + /// retrieveEvents with empty repository retrieve them from the default repository std::list > retrieveCatalogues(const QString &repository = QString()) const; + void addCatalogue(std::shared_ptr catalogue); void updateCatalogue(std::shared_ptr catalogue); void removeCatalogue(std::shared_ptr catalogue); void saveCatalogue(std::shared_ptr catalogue); + void discardCatalogue(std::shared_ptr catalogue, bool &removed); void saveAll(); bool hasChanges() const; diff --git a/core/src/Catalogue/CatalogueController.cpp b/core/src/Catalogue/CatalogueController.cpp index cf5d9e9..95607ca 100644 --- a/core/src/Catalogue/CatalogueController.cpp +++ b/core/src/Catalogue/CatalogueController.cpp @@ -27,6 +27,10 @@ static QString REPOSITORY_WORK_SUFFIX = QString{"_work"}; static QString REPOSITORY_TRASH_SUFFIX = QString{"_trash"}; } +/** + * Possible types of an repository + */ +enum class DBType { SYNC, WORK, TRASH }; class CatalogueController::CatalogueControllerPrivate { public: @@ -37,9 +41,10 @@ public: QStringList m_RepositoryList; CatalogueController *m_Q; - QSet m_EventKeysWithChanges; + QSet m_KeysWithChanges; QString eventUniqueKey(const std::shared_ptr &event) const; + QString catalogueUniqueKey(const std::shared_ptr &catalogue) const; void copyDBtoDB(const QString &dbFrom, const QString &dbTo); QString toWorkRepository(QString repository); @@ -48,6 +53,9 @@ public: void saveEvent(std::shared_ptr event, bool persist = true); void saveCatalogue(std::shared_ptr catalogue, bool persist = true); + + std::shared_ptr createFinder(const QUuid &uniqId, const QString &repository, + DBType type); }; CatalogueController::CatalogueController(QObject *parent) @@ -142,7 +150,7 @@ void CatalogueController::updateEvent(std::shared_ptr event) event->setRepository(impl->toWorkRepository(event->getRepository())); auto uniqueId = impl->eventUniqueKey(event); - impl->m_EventKeysWithChanges.insert(uniqueId); + impl->m_KeysWithChanges.insert(uniqueId); impl->m_CatalogueDao.updateEvent(*event); } @@ -184,53 +192,26 @@ void CatalogueController::addEvent(std::shared_ptr event) impl->m_CatalogueDao.updateEvent(eventTemp); } - // update event parameter - auto uniqIdPredicate = std::make_shared( - QString{"uniqId"}, event->getUniqId(), ComparaisonOperation::EQUALEQUAL); - - auto workRepositoryPredicate = std::make_shared( - QString{"repository"}, impl->toWorkRepository(event->getRepository()), - ComparaisonOperation::EQUALEQUAL); - - auto workPred = std::make_shared(CompoundOperation::AND); - workPred->AddRequestPredicate(uniqIdPredicate); - workPred->AddRequestPredicate(workRepositoryPredicate); + auto workPred = impl->createFinder(event->getUniqId(), event->getRepository(), DBType::WORK); auto workEvent = impl->m_CatalogueDao.getEvent(workPred); *event = workEvent; + auto uniqueId = impl->eventUniqueKey(event); - impl->m_EventKeysWithChanges.insert(uniqueId); + impl->m_KeysWithChanges.insert(uniqueId); } void CatalogueController::saveEvent(std::shared_ptr event) { impl->saveEvent(event, true); - impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event)); + impl->m_KeysWithChanges.remove(impl->eventUniqueKey(event)); } void CatalogueController::discardEvent(std::shared_ptr event, bool &removed) { - auto uniqIdPredicate = std::make_shared( - QString{"uniqId"}, event->getUniqId(), ComparaisonOperation::EQUALEQUAL); - - auto syncRepositoryPredicate = std::make_shared( - QString{"repository"}, impl->toSyncRepository(event->getRepository()), - ComparaisonOperation::EQUALEQUAL); - - auto syncPred = std::make_shared(CompoundOperation::AND); - syncPred->AddRequestPredicate(uniqIdPredicate); - syncPred->AddRequestPredicate(syncRepositoryPredicate); - - - auto workRepositoryPredicate = std::make_shared( - QString{"repository"}, impl->toWorkRepository(event->getRepository()), - ComparaisonOperation::EQUALEQUAL); - - auto workPred = std::make_shared(CompoundOperation::AND); - workPred->AddRequestPredicate(uniqIdPredicate); - workPred->AddRequestPredicate(workRepositoryPredicate); - + auto syncPred = impl->createFinder(event->getUniqId(), event->getRepository(), DBType::SYNC); + auto workPred = impl->createFinder(event->getUniqId(), event->getRepository(), DBType::WORK); auto syncEvent = impl->m_CatalogueDao.getEvent(syncPred); if (!syncEvent.getUniqId().isNull()) { @@ -240,7 +221,7 @@ void CatalogueController::discardEvent(std::shared_ptr event, bool &rem auto workEvent = impl->m_CatalogueDao.getEvent(workPred); *event = workEvent; - impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event)); + impl->m_KeysWithChanges.remove(impl->eventUniqueKey(event)); } else { removed = true; @@ -252,7 +233,7 @@ void CatalogueController::discardEvent(std::shared_ptr event, bool &rem bool CatalogueController::eventHasChanges(std::shared_ptr event) const { - return impl->m_EventKeysWithChanges.contains(impl->eventUniqueKey(event)); + return impl->m_KeysWithChanges.contains(impl->eventUniqueKey(event)); } std::list > @@ -268,10 +249,30 @@ CatalogueController::retrieveCatalogues(const QString &repository) const return cataloguesShared; } +void CatalogueController::addCatalogue(std::shared_ptr catalogue) +{ + catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); + + auto catalogueTemp = *catalogue; + impl->m_CatalogueDao.addCatalogue(catalogueTemp); + + auto workPred + = impl->createFinder(catalogue->getUniqId(), catalogue->getRepository(), DBType::WORK); + + auto workCatalogue = impl->m_CatalogueDao.getCatalogue(workPred); + *catalogue = workCatalogue; + + auto uniqueId = impl->catalogueUniqueKey(catalogue); + impl->m_KeysWithChanges.insert(uniqueId); +} + void CatalogueController::updateCatalogue(std::shared_ptr catalogue) { catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); + auto uniqueId = impl->catalogueUniqueKey(catalogue); + impl->m_KeysWithChanges.insert(uniqueId); + impl->m_CatalogueDao.updateCatalogue(*catalogue); } @@ -282,11 +283,38 @@ void CatalogueController::removeCatalogue(std::shared_ptr catalogue impl->m_CatalogueDao.removeCatalogue(*catalogue); catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository())); impl->m_CatalogueDao.removeCatalogue(*catalogue); + impl->savAllDB(); } void CatalogueController::saveCatalogue(std::shared_ptr catalogue) { impl->saveCatalogue(catalogue, true); + impl->m_KeysWithChanges.remove(impl->catalogueUniqueKey(catalogue)); +} + +void CatalogueController::discardCatalogue(std::shared_ptr catalogue, bool &removed) +{ + auto syncPred + = impl->createFinder(catalogue->getUniqId(), catalogue->getRepository(), DBType::SYNC); + auto workPred + = impl->createFinder(catalogue->getUniqId(), catalogue->getRepository(), DBType::WORK); + + auto syncCatalogue = impl->m_CatalogueDao.getCatalogue(syncPred); + if (!syncCatalogue.getUniqId().isNull()) { + removed = false; + impl->m_CatalogueDao.copyCatalogue( + syncCatalogue, impl->toWorkRepository(catalogue->getRepository()), true); + + auto workCatalogue = impl->m_CatalogueDao.getCatalogue(workPred); + *catalogue = workCatalogue; + impl->m_KeysWithChanges.remove(impl->catalogueUniqueKey(catalogue)); + } + else { + removed = true; + // Since the element wasn't in sync repository. Discard it means remove it + catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); + impl->m_CatalogueDao.removeCatalogue(*catalogue); + } } void CatalogueController::saveAll() @@ -306,12 +334,12 @@ void CatalogueController::saveAll() } impl->savAllDB(); - impl->m_EventKeysWithChanges.clear(); + impl->m_KeysWithChanges.clear(); } bool CatalogueController::hasChanges() const { - return !impl->m_EventKeysWithChanges.isEmpty(); // TODO: catalogues + return !impl->m_KeysWithChanges.isEmpty(); } QByteArray @@ -400,6 +428,12 @@ QString CatalogueController::CatalogueControllerPrivate::eventUniqueKey( return event->getUniqId().toString().append(event->getRepository()); } +QString CatalogueController::CatalogueControllerPrivate::catalogueUniqueKey( + const std::shared_ptr &catalogue) const +{ + return catalogue->getUniqId().toString().append(catalogue->getRepository()); +} + void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom, const QString &dbTo) { @@ -460,3 +494,33 @@ void CatalogueController::CatalogueControllerPrivate::saveCatalogue( savAllDB(); } } + +std::shared_ptr CatalogueController::CatalogueControllerPrivate::createFinder( + const QUuid &uniqId, const QString &repository, DBType type) +{ + // update catalogue parameter + auto uniqIdPredicate = std::make_shared(QString{"uniqId"}, uniqId, + ComparaisonOperation::EQUALEQUAL); + + auto repositoryType = repository; + switch (type) { + case DBType::SYNC: + repositoryType = toSyncRepository(repositoryType); + break; + case DBType::WORK: + repositoryType = toWorkRepository(repositoryType); + break; + case DBType::TRASH: + default: + break; + } + + auto repositoryPredicate = std::make_shared( + QString{"repository"}, repositoryType, ComparaisonOperation::EQUALEQUAL); + + auto finderPred = std::make_shared(CompoundOperation::AND); + finderPred->AddRequestPredicate(uniqIdPredicate); + finderPred->AddRequestPredicate(repositoryPredicate); + + return finderPred; +} diff --git a/gui/include/Catalogue/CatalogueSideBarWidget.h b/gui/include/Catalogue/CatalogueSideBarWidget.h index 1d578a8..f4b8c07 100644 --- a/gui/include/Catalogue/CatalogueSideBarWidget.h +++ b/gui/include/Catalogue/CatalogueSideBarWidget.h @@ -6,6 +6,7 @@ #include #include +class CatalogueAbstractTreeItem; class DBCatalogue; namespace Ui { @@ -28,11 +29,15 @@ public: explicit CatalogueSideBarWidget(QWidget *parent = 0); virtual ~CatalogueSideBarWidget(); - void addCatalogue(const std::shared_ptr &catalogue, const QString &repository); + CatalogueAbstractTreeItem *addCatalogue(const std::shared_ptr &catalogue, + const QString &repository); void setCatalogueChanges(const std::shared_ptr &catalogue, bool hasChanges); QVector > getCatalogues(const QString &repository) const; +private slots: + void emitSelection(); + private: Ui::CatalogueSideBarWidget *ui; diff --git a/gui/include/Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.h b/gui/include/Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.h index 7fc10fc..0135a5b 100644 --- a/gui/include/Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.h +++ b/gui/include/Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.h @@ -15,6 +15,7 @@ public: virtual ~CatalogueAbstractTreeItem(); void addChild(CatalogueAbstractTreeItem *child); + void removeChild(CatalogueAbstractTreeItem *child); QVector children() const; CatalogueAbstractTreeItem *parent() const; diff --git a/gui/include/Catalogue/CatalogueTreeModel.h b/gui/include/Catalogue/CatalogueTreeModel.h index ac14836..bc49d0d 100644 --- a/gui/include/Catalogue/CatalogueTreeModel.h +++ b/gui/include/Catalogue/CatalogueTreeModel.h @@ -27,6 +27,9 @@ public: QVector topLevelItems() const; void addChildItem(CatalogueAbstractTreeItem *child, const QModelIndex &parentIndex); + void removeChildItem(CatalogueAbstractTreeItem *child, const QModelIndex &parentIndex); + /// Refresh the data for the specified index + void refresh(const QModelIndex &index); CatalogueAbstractTreeItem *item(const QModelIndex &index) const; QModelIndex indexOf(CatalogueAbstractTreeItem *item, int column = 0) const; diff --git a/gui/src/Catalogue/CatalogueActionManager.cpp b/gui/src/Catalogue/CatalogueActionManager.cpp index 0521df5..197dfc5 100644 --- a/gui/src/Catalogue/CatalogueActionManager.cpp +++ b/gui/src/Catalogue/CatalogueActionManager.cpp @@ -69,8 +69,8 @@ struct CatalogueActionManager::CatalogueActionManagerPrivate { if (catalogue) { - // TODO - // catalogue->addEvent(event); + catalogue->addEvent(event->getUniqId()); + sqpApp->catalogueController().updateCatalogue(catalogue); m_CatalogueExplorer->sideBarWidget().setCatalogueChanges(catalogue, true); if (m_CatalogueExplorer->eventsWidget().displayedCatalogues().contains(catalogue)) { m_CatalogueExplorer->eventsWidget().addEvent(event); @@ -135,7 +135,7 @@ void CatalogueActionManager::installSelectionZoneActions() if (!selectedCatalogue) { selectedCatalogue = std::make_shared(); selectedCatalogue->setName(dialog.catalogueName()); - // sqpApp->catalogueController().addCatalogue(selectedCatalogue); TODO + sqpApp->catalogueController().addCatalogue(selectedCatalogue); impl->m_CatalogueExplorer->sideBarWidget().addCatalogue(selectedCatalogue, REPOSITORY_DEFAULT); } diff --git a/gui/src/Catalogue/CatalogueSideBarWidget.cpp b/gui/src/Catalogue/CatalogueSideBarWidget.cpp index 06db478..e38c8ab 100644 --- a/gui/src/Catalogue/CatalogueSideBarWidget.cpp +++ b/gui/src/Catalogue/CatalogueSideBarWidget.cpp @@ -12,6 +12,7 @@ #include #include +#include Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget") @@ -29,11 +30,11 @@ struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate { void configureTreeWidget(QTreeView *treeView); QModelIndex addDatabaseItem(const QString &name); CatalogueAbstractTreeItem *getDatabaseItem(const QString &name); - void addCatalogueItem(const std::shared_ptr &catalogue, - const QModelIndex &databaseIndex); + CatalogueAbstractTreeItem *addCatalogueItem(const std::shared_ptr &catalogue, + const QModelIndex &databaseIndex); CatalogueTreeItem *getCatalogueItem(const std::shared_ptr &catalogue) const; - void setHasChanges(bool value, const QModelIndex &index, QTreeView *treeView); + void setHasChanges(bool value, const QModelIndex &index, CatalogueSideBarWidget *sideBarWidget); bool hasChanges(const QModelIndex &index, QTreeView *treeView); int selectionType(QTreeView *treeView) const @@ -109,39 +110,66 @@ CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent) ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); ui->treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch); - auto emitSelection = [this]() { - - auto selectionType = impl->selectionType(ui->treeView); - - switch (selectionType) { - case CATALOGUE_ITEM_TYPE: - emit this->catalogueSelected(impl->selectedCatalogues(ui->treeView)); - break; - case DATABASE_ITEM_TYPE: - emit this->databaseSelected(impl->selectedRepositories(ui->treeView)); - break; - case ALL_EVENT_ITEM_TYPE: - emit this->allEventsSelected(); - break; - case TRASH_ITEM_TYPE: - emit this->trashSelected(); - break; - default: - emit this->selectionCleared(); - break; + connect(ui->treeView, &QTreeView::clicked, this, &CatalogueSideBarWidget::emitSelection); + connect(ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, this, + &CatalogueSideBarWidget::emitSelection); + + + connect(ui->btnAdd, &QToolButton::clicked, [this]() { + auto catalogue = std::make_shared(); + catalogue->setName(QString("Cat")); + sqpApp->catalogueController().addCatalogue(catalogue); + auto item = this->addCatalogue(catalogue, REPOSITORY_DEFAULT); + this->setCatalogueChanges(catalogue, true); + ui->treeView->edit(impl->m_TreeModel->indexOf(item)); + + }); + + + connect(impl->m_TreeModel, &CatalogueTreeModel::itemDropped, [this](auto index) { + auto item = impl->m_TreeModel->item(index); + if (item && item->type() == CATALOGUE_ITEM_TYPE) { + auto catalogue = static_cast(item)->catalogue(); + this->setCatalogueChanges(catalogue, true); + } + }); + connect(ui->btnRemove, &QToolButton::clicked, [this]() { + QVector, CatalogueAbstractTreeItem *> > + cataloguesToItems; + auto selectedIndexes = ui->treeView->selectionModel()->selectedRows(); + + for (auto index : selectedIndexes) { + auto item = impl->m_TreeModel->item(index); + if (item && item->type() == CATALOGUE_ITEM_TYPE) { + auto catalogue = static_cast(item)->catalogue(); + cataloguesToItems << qMakePair(catalogue, item); + } } - }; - connect(ui->treeView, &QTreeView::clicked, emitSelection); - connect(ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, emitSelection); - connect(impl->m_TreeModel, &CatalogueTreeModel::itemRenamed, [emitSelection, this](auto index) { + if (!cataloguesToItems.isEmpty()) { + + if (QMessageBox::warning(this, tr("Remove Catalogue(s)"), + tr("The selected catalogues(s) will be completly removed " + "from the repository!\nAre you sure you want to continue?"), + QMessageBox::Yes | QMessageBox::No, QMessageBox::No) + == QMessageBox::Yes) { + + for (auto catalogueToItem : cataloguesToItems) { + sqpApp->catalogueController().removeCatalogue(catalogueToItem.first); + impl->m_TreeModel->removeChildItem( + catalogueToItem.second, + impl->m_TreeModel->indexOf(catalogueToItem.second->parent())); + } + } + } + }); + + connect(impl->m_TreeModel, &CatalogueTreeModel::itemRenamed, [this](auto index) { auto selectedIndexes = ui->treeView->selectionModel()->selectedRows(); if (selectedIndexes.contains(index)) { - emitSelection(); + this->emitSelection(); } - - auto item = impl->m_TreeModel->item(index); - impl->setHasChanges(true, index, ui->treeView); + impl->setHasChanges(true, index, this); }); ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu); @@ -154,11 +182,12 @@ CatalogueSideBarWidget::~CatalogueSideBarWidget() delete ui; } -void CatalogueSideBarWidget::addCatalogue(const std::shared_ptr &catalogue, - const QString &repository) +CatalogueAbstractTreeItem * +CatalogueSideBarWidget::addCatalogue(const std::shared_ptr &catalogue, + const QString &repository) { auto repositoryItem = impl->getDatabaseItem(repository); - impl->addCatalogueItem(catalogue, impl->m_TreeModel->indexOf(repositoryItem)); + return impl->addCatalogueItem(catalogue, impl->m_TreeModel->indexOf(repositoryItem)); } void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr &catalogue, @@ -166,7 +195,7 @@ void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptrgetCatalogueItem(catalogue)) { auto index = impl->m_TreeModel->indexOf(catalogueItem); - impl->setHasChanges(hasChanges, index, ui->treeView); + impl->setHasChanges(hasChanges, index, this); // catalogueItem->refresh(); } } @@ -189,6 +218,29 @@ CatalogueSideBarWidget::getCatalogues(const QString &repository) const return result; } +void CatalogueSideBarWidget::emitSelection() +{ + auto selectionType = impl->selectionType(ui->treeView); + + switch (selectionType) { + case CATALOGUE_ITEM_TYPE: + emit this->catalogueSelected(impl->selectedCatalogues(ui->treeView)); + break; + case DATABASE_ITEM_TYPE: + emit this->databaseSelected(impl->selectedRepositories(ui->treeView)); + break; + case ALL_EVENT_ITEM_TYPE: + emit this->allEventsSelected(); + break; + case TRASH_ITEM_TYPE: + emit this->trashSelected(); + break; + default: + emit this->selectionCleared(); + break; + } +} + void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos) { QMenu menu{this}; @@ -274,12 +326,14 @@ CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QSt return nullptr; } -void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem( +CatalogueAbstractTreeItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem( const std::shared_ptr &catalogue, const QModelIndex &databaseIndex) { auto catalogueItem = new CatalogueTreeItem{catalogue, QIcon{":/icones/catalogue.png"}, CATALOGUE_ITEM_TYPE}; m_TreeModel->addChildItem(catalogueItem, databaseIndex); + + return catalogueItem; } CatalogueTreeItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCatalogueItem( @@ -307,25 +361,48 @@ CatalogueTreeItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCat return nullptr; } -void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::setHasChanges(bool value, - const QModelIndex &index, - QTreeView *treeView) +void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::setHasChanges( + bool value, const QModelIndex &index, CatalogueSideBarWidget *sideBarWidget) { + std::shared_ptr catalogue = nullptr; + auto item = m_TreeModel->item(index); + if (item && item->type() == CATALOGUE_ITEM_TYPE) { + catalogue = static_cast(item)->catalogue(); + } + auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation); if (value) { - if (!hasChanges(validationIndex, treeView)) { + if (!hasChanges(validationIndex, sideBarWidget->ui->treeView)) { auto widget = CatalogueExplorerHelper::buildValidationWidget( - treeView, [this, validationIndex, - treeView]() { setHasChanges(false, validationIndex, treeView); }, - [this, validationIndex, treeView]() { - setHasChanges(false, validationIndex, treeView); + sideBarWidget->ui->treeView, + [this, validationIndex, sideBarWidget, catalogue]() { + if (catalogue) { + sqpApp->catalogueController().saveCatalogue(catalogue); + } + setHasChanges(false, validationIndex, sideBarWidget); + }, + [this, validationIndex, sideBarWidget, catalogue, item]() { + if (catalogue) { + bool removed; + sqpApp->catalogueController().discardCatalogue(catalogue, removed); + + if (removed) { + m_TreeModel->removeChildItem(item, + m_TreeModel->indexOf(item->parent())); + } + else { + m_TreeModel->refresh(m_TreeModel->indexOf(item)); + setHasChanges(false, validationIndex, sideBarWidget); + } + sideBarWidget->emitSelection(); + } }); - treeView->setIndexWidget(validationIndex, widget); + sideBarWidget->ui->treeView->setIndexWidget(validationIndex, widget); } } else { // Note: the widget is destroyed - treeView->setIndexWidget(validationIndex, nullptr); + sideBarWidget->ui->treeView->setIndexWidget(validationIndex, nullptr); } } diff --git a/gui/src/Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.cpp b/gui/src/Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.cpp index 3fb084c..60cd390 100644 --- a/gui/src/Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.cpp +++ b/gui/src/Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.cpp @@ -24,6 +24,12 @@ void CatalogueAbstractTreeItem::addChild(CatalogueAbstractTreeItem *child) child->impl->m_Parent = this; } +void CatalogueAbstractTreeItem::removeChild(CatalogueAbstractTreeItem *child) +{ + impl->m_Children.removeAll(child); + delete child; +} + QVector CatalogueAbstractTreeItem::children() const { return impl->m_Children; diff --git a/gui/src/Catalogue/CatalogueTreeItems/CatalogueTreeItem.cpp b/gui/src/Catalogue/CatalogueTreeItems/CatalogueTreeItem.cpp index 78bcd4b..e4fc8b7 100644 --- a/gui/src/Catalogue/CatalogueTreeItems/CatalogueTreeItem.cpp +++ b/gui/src/Catalogue/CatalogueTreeItems/CatalogueTreeItem.cpp @@ -76,17 +76,27 @@ Qt::ItemFlags CatalogueTreeItem::flags(int column) const bool CatalogueTreeItem::canDropMimeData(const QMimeData *data, Qt::DropAction action) { - return data->hasFormat(MIME_TYPE_EVENT_LIST); + auto events = sqpApp->catalogueController().eventsForMimeData(data->data(MIME_TYPE_EVENT_LIST)); + auto canDrop = data->hasFormat(MIME_TYPE_EVENT_LIST); + + for (auto event : events) { + canDrop &= (event->getRepository() == impl->m_Catalogue->getRepository()); + } + return canDrop; } bool CatalogueTreeItem::dropMimeData(const QMimeData *data, Qt::DropAction action) { Q_ASSERT(canDropMimeData(data, action)); - - auto events = sqpApp->catalogueController().eventsForMimeData(data->data(MIME_TYPE_EVENT_LIST)); - // impl->m_Catalogue->addEvents(events); TODO: move events in the new catalogue // Warning: Check that the events aren't already in the catalogue // Also check for the repository !!! + + auto events = sqpApp->catalogueController().eventsForMimeData(data->data(MIME_TYPE_EVENT_LIST)); + + for (auto event : events) { + impl->m_Catalogue->addEvent(event->getUniqId()); + sqpApp->catalogueController().updateCatalogue(impl->m_Catalogue); + } } std::shared_ptr CatalogueTreeItem::catalogue() const diff --git a/gui/src/Catalogue/CatalogueTreeModel.cpp b/gui/src/Catalogue/CatalogueTreeModel.cpp index 86ac456..2708821 100644 --- a/gui/src/Catalogue/CatalogueTreeModel.cpp +++ b/gui/src/Catalogue/CatalogueTreeModel.cpp @@ -46,6 +46,23 @@ void CatalogueTreeModel::addChildItem(CatalogueAbstractTreeItem *child, emit dataChanged(parentIndex, parentIndex); } +void CatalogueTreeModel::removeChildItem(CatalogueAbstractTreeItem *child, + const QModelIndex &parentIndex) +{ + auto parentItem = item(parentIndex); + int i = parentItem->children().indexOf(child); + beginRemoveRows(parentIndex, i, i); + parentItem->removeChild(child); + endRemoveRows(); + + emit dataChanged(parentIndex, parentIndex); +} + +void CatalogueTreeModel::refresh(const QModelIndex &index) +{ + emit dataChanged(index, index); +} + CatalogueAbstractTreeItem *CatalogueTreeModel::item(const QModelIndex &index) const { return static_cast(index.internalPointer()); diff --git a/gui/src/Visualization/VisualizationGraphWidget.cpp b/gui/src/Visualization/VisualizationGraphWidget.cpp index 204224e..ae5f28d 100644 --- a/gui/src/Visualization/VisualizationGraphWidget.cpp +++ b/gui/src/Visualization/VisualizationGraphWidget.cpp @@ -303,7 +303,6 @@ void VisualizationGraphWidget::addVariable(std::shared_ptr variable, S this->setFlags(GraphFlag::DisableAll); setGraphRange(range); this->setFlags(GraphFlag::EnableAll); - emit requestDataLoading({variable}, range, false); }; diff --git a/gui/ui/Catalogue/CatalogueSideBarWidget.ui b/gui/ui/Catalogue/CatalogueSideBarWidget.ui index 7c99893..b097960 100644 --- a/gui/ui/Catalogue/CatalogueSideBarWidget.ui +++ b/gui/ui/Catalogue/CatalogueSideBarWidget.ui @@ -31,7 +31,7 @@ - false + true + @@ -48,7 +48,7 @@ - false + true - @@ -100,7 +100,6 @@ -