diff --git a/app/src/Main.cpp b/app/src/Main.cpp index 9246498..bd42c5e 100644 --- a/app/src/Main.cpp +++ b/app/src/Main.cpp @@ -25,9 +25,9 @@ #include #include -#include #include #include +#include #include diff --git a/core/include/Catalogue/CatalogueController.h b/core/include/Catalogue/CatalogueController.h index 9d839af..7d12271 100644 --- a/core/include/Catalogue/CatalogueController.h +++ b/core/include/Catalogue/CatalogueController.h @@ -32,27 +32,32 @@ public: virtual ~CatalogueController(); // DB - // QStringList getRepositories() const; + QStringList getRepositories() const; void addDB(const QString &dbPath); void saveDB(const QString &destinationPath, const QString &repository); // Event - // bool createEvent(const QString &name); + /// retrieveEvents with empty repository retrieve them from the default repository std::list > retrieveEvents(const QString &repository) const; std::list > retrieveAllEvents() const; std::list > retrieveEventsFromCatalogue(std::shared_ptr catalogue) const; - // void updateEvent(std::shared_ptr event); + void addEvent(std::shared_ptr event); + void updateEvent(std::shared_ptr event); + void removeEvent(std::shared_ptr event); // void trashEvent(std::shared_ptr event); - // void removeEvent(std::shared_ptr event); // void restore(QUuid eventId); - // void saveEvent(std::shared_ptr event); + void saveEvent(std::shared_ptr event); // Catalogue // bool createCatalogue(const QString &name, QVector eventList); - std::list > getCatalogues(const QString &repository) const; - // void removeEvent(QUuid catalogueId, const QString &repository); - // void saveCatalogue(std::shared_ptr event); + /// retrieveEvents with empty repository retrieve them from the default repository + std::list > retrieveCatalogues(const QString &repository) const; + void updateCatalogue(std::shared_ptr catalogue); + void removeCatalogue(std::shared_ptr catalogue); + void saveCatalogue(std::shared_ptr catalogue); + + void saveAll(); public slots: /// Manage init/end of the controller diff --git a/core/src/Catalogue/CatalogueController.cpp b/core/src/Catalogue/CatalogueController.cpp index 9e2ad7c..f06adf5 100644 --- a/core/src/Catalogue/CatalogueController.cpp +++ b/core/src/Catalogue/CatalogueController.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -21,20 +22,28 @@ Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController") namespace { -static QString REPOSITORY_WORK_SUFFIX = QString{"Work"}; - +static QString REPOSITORY_WORK_SUFFIX = QString{"work"}; +static QString REPOSITORY_TRASH_SUFFIX = QString{"trash"}; } class CatalogueController::CatalogueControllerPrivate { + public: + explicit CatalogueControllerPrivate(CatalogueController *parent) : m_Q{parent} {} + QMutex m_WorkingMutex; CatalogueDao m_CatalogueDao; - std::list m_RepositoryList; + QStringList m_RepositoryList; + CatalogueController *m_Q; + + void copyDBtoDB(const QString &dbFrom, const QString &dbTo); + QString toWorkRepository(QString repository); + QString toSyncRepository(QString repository); }; CatalogueController::CatalogueController(QObject *parent) - : impl{spimpl::make_unique_impl()} + : impl{spimpl::make_unique_impl(this)} { qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction") << QThread::currentThread(); @@ -47,6 +56,11 @@ CatalogueController::~CatalogueController() this->waitForFinish(); } +QStringList CatalogueController::getRepositories() const +{ + return impl->m_RepositoryList; +} + void CatalogueController::addDB(const QString &dbPath) { QDir dbDir(dbPath); @@ -64,7 +78,8 @@ void CatalogueController::addDB(const QString &dbPath) << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath); } else { - impl->m_RepositoryList.push_back(dirName); + impl->m_RepositoryList << dirName; + impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName)); } } else { @@ -84,8 +99,10 @@ void CatalogueController::saveDB(const QString &destinationPath, const QString & std::list > CatalogueController::retrieveEvents(const QString &repository) const { + QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository; + auto eventsShared = std::list >{}; - auto events = impl->m_CatalogueDao.getEvents(repository); + auto events = impl->m_CatalogueDao.getEvents(impl->toWorkRepository(dbDireName)); for (auto event : events) { eventsShared.push_back(std::make_shared(event)); } @@ -113,17 +130,92 @@ CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr ca return eventsShared; } +void CatalogueController::updateEvent(std::shared_ptr event) +{ + event->setRepository(impl->toSyncRepository(event->getRepository())); + + impl->m_CatalogueDao.updateEvent(*event); +} + +void CatalogueController::removeEvent(std::shared_ptr event) +{ + // Remove it from both repository and repository_work + event->setRepository(impl->toWorkRepository(event->getRepository())); + impl->m_CatalogueDao.removeEvent(*event); + event->setRepository(impl->toSyncRepository(event->getRepository())); + impl->m_CatalogueDao.removeEvent(*event); +} + +void CatalogueController::addEvent(std::shared_ptr event) +{ + event->setRepository(impl->toSyncRepository(event->getRepository())); + + impl->m_CatalogueDao.addEvent(*event); + + // Call update is necessary at the creation of add Event if it has some tags or some event + // products + if (!event->getEventProducts().empty() || !event->getTags().empty()) { + impl->m_CatalogueDao.updateEvent(*event); + } +} + +void CatalogueController::saveEvent(std::shared_ptr event) +{ + impl->m_CatalogueDao.moveEvent(*event, impl->toSyncRepository(event->getRepository()), true); +} + std::list > -CatalogueController::getCatalogues(const QString &repository) const +CatalogueController::retrieveCatalogues(const QString &repository) const { + QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository; + auto cataloguesShared = std::list >{}; - auto catalogues = impl->m_CatalogueDao.getCatalogues(repository); + auto catalogues = impl->m_CatalogueDao.getCatalogues(impl->toWorkRepository(dbDireName)); for (auto catalogue : catalogues) { cataloguesShared.push_back(std::make_shared(catalogue)); } return cataloguesShared; } +void CatalogueController::updateCatalogue(std::shared_ptr catalogue) +{ + catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository())); + + impl->m_CatalogueDao.updateCatalogue(*catalogue); +} + +void CatalogueController::removeCatalogue(std::shared_ptr catalogue) +{ + // Remove it from both repository and repository_work + catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); + impl->m_CatalogueDao.removeCatalogue(*catalogue); + catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository())); + impl->m_CatalogueDao.removeCatalogue(*catalogue); +} + +void CatalogueController::saveCatalogue(std::shared_ptr catalogue) +{ + impl->m_CatalogueDao.moveCatalogue(*catalogue, + impl->toSyncRepository(catalogue->getRepository()), true); +} + +void CatalogueController::saveAll() +{ + for (auto repository : impl->m_RepositoryList) { + // Save Event + auto events = this->retrieveEvents(repository); + for (auto event : events) { + this->saveEvent(event); + } + + // Save Catalogue + auto catalogues = this->retrieveCatalogues(repository); + for (auto catalogue : catalogues) { + this->saveCatalogue(catalogue); + } + } +} + void CatalogueController::initialize() { qCDebug(LOG_CatalogueController()) << tr("CatalogueController init") @@ -137,8 +229,8 @@ void CatalogueController::initialize() if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) { defaultRepositoryLocationDir.cd(defaultRepositoryLocation); auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT); - qCInfo(LOG_CatalogueController()) - << tr("Persistant data loading from: ") << defaultRepository; + qCInfo(LOG_CatalogueController()) << tr("Persistant data loading from: ") + << defaultRepository; this->addDB(defaultRepository); } else { @@ -159,3 +251,37 @@ void CatalogueController::waitForFinish() { QMutexLocker locker{&impl->m_WorkingMutex}; } + +void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom, + const QString &dbTo) +{ + auto catalogues = m_Q->retrieveCatalogues(dbFrom); + auto events = m_Q->retrieveEvents(dbFrom); + + for (auto catalogue : catalogues) { + m_CatalogueDao.copyCatalogue(*catalogue, dbTo, true); + } + + for (auto event : events) { + m_CatalogueDao.copyEvent(*event, dbTo, true); + } +} + +QString CatalogueController::CatalogueControllerPrivate::toWorkRepository(QString repository) +{ + auto syncRepository = toSyncRepository(repository); + + return QString("%1_%2").arg(syncRepository, REPOSITORY_WORK_SUFFIX); +} + +QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QString repository) +{ + auto syncRepository = repository; + if (repository.endsWith(REPOSITORY_WORK_SUFFIX)) { + syncRepository.remove(REPOSITORY_WORK_SUFFIX); + } + else if (repository.endsWith(REPOSITORY_TRASH_SUFFIX)) { + syncRepository.remove(REPOSITORY_TRASH_SUFFIX); + } + return syncRepository; +} diff --git a/core/src/Plugin/PluginManager.cpp b/core/src/Plugin/PluginManager.cpp index 2f07645..6579f63 100644 --- a/core/src/Plugin/PluginManager.cpp +++ b/core/src/Plugin/PluginManager.cpp @@ -97,8 +97,7 @@ struct PluginManager::PluginManagerPrivate { void loadStaticPlugins() { - for (QObject *plugin : QPluginLoader::staticInstances()) - { + for (QObject *plugin : QPluginLoader::staticInstances()) { qobject_cast(plugin)->initialize(); m_RegisteredPlugins.insert(plugin->metaObject()->className(), "StaticPlugin"); } diff --git a/core/tests/Data/TestDataSeriesUtils.cpp b/core/tests/Data/TestDataSeriesUtils.cpp index 1801022..2e5850f 100644 --- a/core/tests/Data/TestDataSeriesUtils.cpp +++ b/core/tests/Data/TestDataSeriesUtils.cpp @@ -176,8 +176,8 @@ void TestDataSeriesUtils::testThresholds_data() << false << 1. << 47.073; QTest::newRow("thresholds (empty data)") << std::vector{} << false << nan << nan; - QTest::newRow("thresholds (only nan values)") - << std::vector{nan, nan, nan, nan, nan} << false << nan << nan; + QTest::newRow("thresholds (only nan values)") << std::vector{nan, nan, nan, nan, nan} + << false << nan << nan; QTest::newRow("thresholds (from file with logarithmic scale)") << fromFile(inputFilePath("TestThresholds.txt")) << true << 832.005 << 17655064.730; diff --git a/gui/src/Catalogue/CatalogueSideBarWidget.cpp b/gui/src/Catalogue/CatalogueSideBarWidget.cpp index 97850e5..0d64db1 100644 --- a/gui/src/Catalogue/CatalogueSideBarWidget.cpp +++ b/gui/src/Catalogue/CatalogueSideBarWidget.cpp @@ -178,7 +178,7 @@ void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget( auto db = addDatabaseItem("Default", treeWidget); - auto catalogues = sqpApp->catalogueController().getCatalogues("Default"); + auto catalogues = sqpApp->catalogueController().retrieveCatalogues("Default"); for (auto catalogue : catalogues) { addCatalogueItem(catalogue, db); } diff --git a/gui/src/Visualization/VisualizationActionManager.cpp b/gui/src/Visualization/VisualizationActionManager.cpp index cb84119..0de20a6 100644 --- a/gui/src/Visualization/VisualizationActionManager.cpp +++ b/gui/src/Visualization/VisualizationActionManager.cpp @@ -5,7 +5,9 @@ #include #include -VisualizationActionManager::VisualizationActionManager() {} +VisualizationActionManager::VisualizationActionManager() +{ +} void VisualizationActionManager::installSelectionZoneActions() { diff --git a/gui/src/Visualization/VisualizationGraphWidget.cpp b/gui/src/Visualization/VisualizationGraphWidget.cpp index 52484ae..b1e2048 100644 --- a/gui/src/Visualization/VisualizationGraphWidget.cpp +++ b/gui/src/Visualization/VisualizationGraphWidget.cpp @@ -241,10 +241,9 @@ VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); connect(ui->widget, &QCustomPlot::mouseDoubleClick, this, &VisualizationGraphWidget::onMouseDoubleClick); - connect( - ui->widget->xAxis, - static_cast(&QCPAxis::rangeChanged), - this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection); + connect(ui->widget->xAxis, static_cast( + &QCPAxis::rangeChanged), + this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection); // Activates menu when right clicking on the graph ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); @@ -695,9 +694,9 @@ void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) { - qCDebug(LOG_VisualizationGraphWidget()) - << tr("TORM: VisualizationGraphWidget::onRangeChanged") - << QThread::currentThread()->objectName() << "DoAcqui" << impl->m_DoAcquisition; + qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::onRangeChanged") + << QThread::currentThread()->objectName() << "DoAcqui" + << impl->m_DoAcquisition; auto graphRange = SqpRange{t1.lower, t1.upper}; auto oldGraphRange = SqpRange{t2.lower, t2.upper}; diff --git a/gui/src/Visualization/VisualizationSelectionZoneItem.cpp b/gui/src/Visualization/VisualizationSelectionZoneItem.cpp index 4d06164..2e5c5b2 100644 --- a/gui/src/Visualization/VisualizationSelectionZoneItem.cpp +++ b/gui/src/Visualization/VisualizationSelectionZoneItem.cpp @@ -142,7 +142,9 @@ VisualizationSelectionZoneItem::VisualizationSelectionZoneItem(QCustomPlot *plot setColor(QColor(DEFAULT_COLOR)); } -VisualizationSelectionZoneItem::~VisualizationSelectionZoneItem() {} +VisualizationSelectionZoneItem::~VisualizationSelectionZoneItem() +{ +} VisualizationGraphWidget *VisualizationSelectionZoneItem::parentGraphWidget() const noexcept { diff --git a/plugins/amda/tests/TestAmdaResultParser.cpp b/plugins/amda/tests/TestAmdaResultParser.cpp index ca76006..78d8bb3 100644 --- a/plugins/amda/tests/TestAmdaResultParser.cpp +++ b/plugins/amda/tests/TestAmdaResultParser.cpp @@ -365,8 +365,8 @@ void TestAmdaResultParser::testReadSpectrogramTxt_data() {8946.475, 18133.158, 10875.621, 24051.619, 19283.221}, {20907.664, 32076.725, 13008.381, 13142.759, 23226.998}}); - QTest::newRow("Valid file (four bands)") - << QStringLiteral("spectro/ValidSpectrogram2.txt") << fourBandsResult; + QTest::newRow("Valid file (four bands)") << QStringLiteral("spectro/ValidSpectrogram2.txt") + << fourBandsResult; QTest::newRow("Valid file (four unsorted bands)") << QStringLiteral("spectro/ValidSpectrogram3.txt") << fourBandsResult; // Bands and values are sorted