##// END OF EJS Templates
Add Catalogue methods
perrinel -
r1159:4c27015bd9c6
parent child
Show More
@@ -25,9 +25,9
25 #include <SqpApplication.h>
25 #include <SqpApplication.h>
26 #include <qglobal.h>
26 #include <qglobal.h>
27
27
28 #include <QtPlugin>
29 #include <Plugin/PluginManager.h>
28 #include <Plugin/PluginManager.h>
30 #include <QDir>
29 #include <QDir>
30 #include <QtPlugin>
31
31
32 #include <QLoggingCategory>
32 #include <QLoggingCategory>
33
33
@@ -32,27 +32,32 public:
32 virtual ~CatalogueController();
32 virtual ~CatalogueController();
33
33
34 // DB
34 // DB
35 // QStringList getRepositories() const;
35 QStringList getRepositories() const;
36 void addDB(const QString &dbPath);
36 void addDB(const QString &dbPath);
37 void saveDB(const QString &destinationPath, const QString &repository);
37 void saveDB(const QString &destinationPath, const QString &repository);
38
38
39 // Event
39 // Event
40 // bool createEvent(const QString &name);
40 /// retrieveEvents with empty repository retrieve them from the default repository
41 std::list<std::shared_ptr<DBEvent> > retrieveEvents(const QString &repository) const;
41 std::list<std::shared_ptr<DBEvent> > retrieveEvents(const QString &repository) const;
42 std::list<std::shared_ptr<DBEvent> > retrieveAllEvents() const;
42 std::list<std::shared_ptr<DBEvent> > retrieveAllEvents() const;
43 std::list<std::shared_ptr<DBEvent> >
43 std::list<std::shared_ptr<DBEvent> >
44 retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const;
44 retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const;
45 // void updateEvent(std::shared_ptr<DBEvent> event);
45 void addEvent(std::shared_ptr<DBEvent> event);
46 void updateEvent(std::shared_ptr<DBEvent> event);
47 void removeEvent(std::shared_ptr<DBEvent> event);
46 // void trashEvent(std::shared_ptr<DBEvent> event);
48 // void trashEvent(std::shared_ptr<DBEvent> event);
47 // void removeEvent(std::shared_ptr<DBEvent> event);
48 // void restore(QUuid eventId);
49 // void restore(QUuid eventId);
49 // void saveEvent(std::shared_ptr<DBEvent> event);
50 void saveEvent(std::shared_ptr<DBEvent> event);
50
51
51 // Catalogue
52 // Catalogue
52 // bool createCatalogue(const QString &name, QVector<QUuid> eventList);
53 // bool createCatalogue(const QString &name, QVector<QUuid> eventList);
53 std::list<std::shared_ptr<DBCatalogue> > getCatalogues(const QString &repository) const;
54 /// retrieveEvents with empty repository retrieve them from the default repository
54 // void removeEvent(QUuid catalogueId, const QString &repository);
55 std::list<std::shared_ptr<DBCatalogue> > retrieveCatalogues(const QString &repository) const;
55 // void saveCatalogue(std::shared_ptr<DBEvent> event);
56 void updateCatalogue(std::shared_ptr<DBCatalogue> catalogue);
57 void removeCatalogue(std::shared_ptr<DBCatalogue> catalogue);
58 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue);
59
60 void saveAll();
56
61
57 public slots:
62 public slots:
58 /// Manage init/end of the controller
63 /// Manage init/end of the controller
@@ -8,6 +8,7
8 #include <CompoundPredicate.h>
8 #include <CompoundPredicate.h>
9 #include <DBCatalogue.h>
9 #include <DBCatalogue.h>
10 #include <DBEvent.h>
10 #include <DBEvent.h>
11 #include <DBEventProduct.h>
11 #include <DBTag.h>
12 #include <DBTag.h>
12 #include <IRequestPredicate.h>
13 #include <IRequestPredicate.h>
13
14
@@ -21,20 +22,28 Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController")
21
22
22 namespace {
23 namespace {
23
24
24 static QString REPOSITORY_WORK_SUFFIX = QString{"Work"};
25 static QString REPOSITORY_WORK_SUFFIX = QString{"work"};
25
26 static QString REPOSITORY_TRASH_SUFFIX = QString{"trash"};
26 }
27 }
27
28
28 class CatalogueController::CatalogueControllerPrivate {
29 class CatalogueController::CatalogueControllerPrivate {
30
29 public:
31 public:
32 explicit CatalogueControllerPrivate(CatalogueController *parent) : m_Q{parent} {}
33
30 QMutex m_WorkingMutex;
34 QMutex m_WorkingMutex;
31 CatalogueDao m_CatalogueDao;
35 CatalogueDao m_CatalogueDao;
32
36
33 std::list<QString> m_RepositoryList;
37 QStringList m_RepositoryList;
38 CatalogueController *m_Q;
39
40 void copyDBtoDB(const QString &dbFrom, const QString &dbTo);
41 QString toWorkRepository(QString repository);
42 QString toSyncRepository(QString repository);
34 };
43 };
35
44
36 CatalogueController::CatalogueController(QObject *parent)
45 CatalogueController::CatalogueController(QObject *parent)
37 : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>()}
46 : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>(this)}
38 {
47 {
39 qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction")
48 qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction")
40 << QThread::currentThread();
49 << QThread::currentThread();
@@ -47,6 +56,11 CatalogueController::~CatalogueController()
47 this->waitForFinish();
56 this->waitForFinish();
48 }
57 }
49
58
59 QStringList CatalogueController::getRepositories() const
60 {
61 return impl->m_RepositoryList;
62 }
63
50 void CatalogueController::addDB(const QString &dbPath)
64 void CatalogueController::addDB(const QString &dbPath)
51 {
65 {
52 QDir dbDir(dbPath);
66 QDir dbDir(dbPath);
@@ -64,7 +78,8 void CatalogueController::addDB(const QString &dbPath)
64 << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath);
78 << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath);
65 }
79 }
66 else {
80 else {
67 impl->m_RepositoryList.push_back(dirName);
81 impl->m_RepositoryList << dirName;
82 impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName));
68 }
83 }
69 }
84 }
70 else {
85 else {
@@ -84,8 +99,10 void CatalogueController::saveDB(const QString &destinationPath, const QString &
84 std::list<std::shared_ptr<DBEvent> >
99 std::list<std::shared_ptr<DBEvent> >
85 CatalogueController::retrieveEvents(const QString &repository) const
100 CatalogueController::retrieveEvents(const QString &repository) const
86 {
101 {
102 QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository;
103
87 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
104 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
88 auto events = impl->m_CatalogueDao.getEvents(repository);
105 auto events = impl->m_CatalogueDao.getEvents(impl->toWorkRepository(dbDireName));
89 for (auto event : events) {
106 for (auto event : events) {
90 eventsShared.push_back(std::make_shared<DBEvent>(event));
107 eventsShared.push_back(std::make_shared<DBEvent>(event));
91 }
108 }
@@ -113,17 +130,92 CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> ca
113 return eventsShared;
130 return eventsShared;
114 }
131 }
115
132
133 void CatalogueController::updateEvent(std::shared_ptr<DBEvent> event)
134 {
135 event->setRepository(impl->toSyncRepository(event->getRepository()));
136
137 impl->m_CatalogueDao.updateEvent(*event);
138 }
139
140 void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event)
141 {
142 // Remove it from both repository and repository_work
143 event->setRepository(impl->toWorkRepository(event->getRepository()));
144 impl->m_CatalogueDao.removeEvent(*event);
145 event->setRepository(impl->toSyncRepository(event->getRepository()));
146 impl->m_CatalogueDao.removeEvent(*event);
147 }
148
149 void CatalogueController::addEvent(std::shared_ptr<DBEvent> event)
150 {
151 event->setRepository(impl->toSyncRepository(event->getRepository()));
152
153 impl->m_CatalogueDao.addEvent(*event);
154
155 // Call update is necessary at the creation of add Event if it has some tags or some event
156 // products
157 if (!event->getEventProducts().empty() || !event->getTags().empty()) {
158 impl->m_CatalogueDao.updateEvent(*event);
159 }
160 }
161
162 void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event)
163 {
164 impl->m_CatalogueDao.moveEvent(*event, impl->toSyncRepository(event->getRepository()), true);
165 }
166
116 std::list<std::shared_ptr<DBCatalogue> >
167 std::list<std::shared_ptr<DBCatalogue> >
117 CatalogueController::getCatalogues(const QString &repository) const
168 CatalogueController::retrieveCatalogues(const QString &repository) const
118 {
169 {
170 QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository;
171
119 auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
172 auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
120 auto catalogues = impl->m_CatalogueDao.getCatalogues(repository);
173 auto catalogues = impl->m_CatalogueDao.getCatalogues(impl->toWorkRepository(dbDireName));
121 for (auto catalogue : catalogues) {
174 for (auto catalogue : catalogues) {
122 cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue));
175 cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue));
123 }
176 }
124 return cataloguesShared;
177 return cataloguesShared;
125 }
178 }
126
179
180 void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue)
181 {
182 catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository()));
183
184 impl->m_CatalogueDao.updateCatalogue(*catalogue);
185 }
186
187 void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue)
188 {
189 // Remove it from both repository and repository_work
190 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
191 impl->m_CatalogueDao.removeCatalogue(*catalogue);
192 catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository()));
193 impl->m_CatalogueDao.removeCatalogue(*catalogue);
194 }
195
196 void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue)
197 {
198 impl->m_CatalogueDao.moveCatalogue(*catalogue,
199 impl->toSyncRepository(catalogue->getRepository()), true);
200 }
201
202 void CatalogueController::saveAll()
203 {
204 for (auto repository : impl->m_RepositoryList) {
205 // Save Event
206 auto events = this->retrieveEvents(repository);
207 for (auto event : events) {
208 this->saveEvent(event);
209 }
210
211 // Save Catalogue
212 auto catalogues = this->retrieveCatalogues(repository);
213 for (auto catalogue : catalogues) {
214 this->saveCatalogue(catalogue);
215 }
216 }
217 }
218
127 void CatalogueController::initialize()
219 void CatalogueController::initialize()
128 {
220 {
129 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
221 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
@@ -137,8 +229,8 void CatalogueController::initialize()
137 if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) {
229 if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) {
138 defaultRepositoryLocationDir.cd(defaultRepositoryLocation);
230 defaultRepositoryLocationDir.cd(defaultRepositoryLocation);
139 auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT);
231 auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT);
140 qCInfo(LOG_CatalogueController())
232 qCInfo(LOG_CatalogueController()) << tr("Persistant data loading from: ")
141 << tr("Persistant data loading from: ") << defaultRepository;
233 << defaultRepository;
142 this->addDB(defaultRepository);
234 this->addDB(defaultRepository);
143 }
235 }
144 else {
236 else {
@@ -159,3 +251,37 void CatalogueController::waitForFinish()
159 {
251 {
160 QMutexLocker locker{&impl->m_WorkingMutex};
252 QMutexLocker locker{&impl->m_WorkingMutex};
161 }
253 }
254
255 void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom,
256 const QString &dbTo)
257 {
258 auto catalogues = m_Q->retrieveCatalogues(dbFrom);
259 auto events = m_Q->retrieveEvents(dbFrom);
260
261 for (auto catalogue : catalogues) {
262 m_CatalogueDao.copyCatalogue(*catalogue, dbTo, true);
263 }
264
265 for (auto event : events) {
266 m_CatalogueDao.copyEvent(*event, dbTo, true);
267 }
268 }
269
270 QString CatalogueController::CatalogueControllerPrivate::toWorkRepository(QString repository)
271 {
272 auto syncRepository = toSyncRepository(repository);
273
274 return QString("%1_%2").arg(syncRepository, REPOSITORY_WORK_SUFFIX);
275 }
276
277 QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QString repository)
278 {
279 auto syncRepository = repository;
280 if (repository.endsWith(REPOSITORY_WORK_SUFFIX)) {
281 syncRepository.remove(REPOSITORY_WORK_SUFFIX);
282 }
283 else if (repository.endsWith(REPOSITORY_TRASH_SUFFIX)) {
284 syncRepository.remove(REPOSITORY_TRASH_SUFFIX);
285 }
286 return syncRepository;
287 }
@@ -97,8 +97,7 struct PluginManager::PluginManagerPrivate {
97
97
98 void loadStaticPlugins()
98 void loadStaticPlugins()
99 {
99 {
100 for (QObject *plugin : QPluginLoader::staticInstances())
100 for (QObject *plugin : QPluginLoader::staticInstances()) {
101 {
102 qobject_cast<IPlugin *>(plugin)->initialize();
101 qobject_cast<IPlugin *>(plugin)->initialize();
103 m_RegisteredPlugins.insert(plugin->metaObject()->className(), "StaticPlugin");
102 m_RegisteredPlugins.insert(plugin->metaObject()->className(), "StaticPlugin");
104 }
103 }
@@ -176,8 +176,8 void TestDataSeriesUtils::testThresholds_data()
176 << false << 1. << 47.073;
176 << false << 1. << 47.073;
177
177
178 QTest::newRow("thresholds (empty data)") << std::vector<double>{} << false << nan << nan;
178 QTest::newRow("thresholds (empty data)") << std::vector<double>{} << false << nan << nan;
179 QTest::newRow("thresholds (only nan values)")
179 QTest::newRow("thresholds (only nan values)") << std::vector<double>{nan, nan, nan, nan, nan}
180 << std::vector<double>{nan, nan, nan, nan, nan} << false << nan << nan;
180 << false << nan << nan;
181
181
182 QTest::newRow("thresholds (from file with logarithmic scale)")
182 QTest::newRow("thresholds (from file with logarithmic scale)")
183 << fromFile(inputFilePath("TestThresholds.txt")) << true << 832.005 << 17655064.730;
183 << fromFile(inputFilePath("TestThresholds.txt")) << true << 832.005 << 17655064.730;
@@ -178,7 +178,7 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget(
178
178
179 auto db = addDatabaseItem("Default", treeWidget);
179 auto db = addDatabaseItem("Default", treeWidget);
180
180
181 auto catalogues = sqpApp->catalogueController().getCatalogues("Default");
181 auto catalogues = sqpApp->catalogueController().retrieveCatalogues("Default");
182 for (auto catalogue : catalogues) {
182 for (auto catalogue : catalogues) {
183 addCatalogueItem(catalogue, db);
183 addCatalogueItem(catalogue, db);
184 }
184 }
@@ -5,7 +5,9
5 #include <Actions/ActionsGuiController.h>
5 #include <Actions/ActionsGuiController.h>
6 #include <SqpApplication.h>
6 #include <SqpApplication.h>
7
7
8 VisualizationActionManager::VisualizationActionManager() {}
8 VisualizationActionManager::VisualizationActionManager()
9 {
10 }
9
11
10 void VisualizationActionManager::installSelectionZoneActions()
12 void VisualizationActionManager::installSelectionZoneActions()
11 {
13 {
@@ -241,10 +241,9 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget
241 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
241 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
242 connect(ui->widget, &QCustomPlot::mouseDoubleClick, this,
242 connect(ui->widget, &QCustomPlot::mouseDoubleClick, this,
243 &VisualizationGraphWidget::onMouseDoubleClick);
243 &VisualizationGraphWidget::onMouseDoubleClick);
244 connect(
244 connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(
245 ui->widget->xAxis,
245 &QCPAxis::rangeChanged),
246 static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(&QCPAxis::rangeChanged),
246 this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection);
247 this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection);
248
247
249 // Activates menu when right clicking on the graph
248 // Activates menu when right clicking on the graph
250 ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
249 ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -695,9 +694,9 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
695
694
696 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
695 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
697 {
696 {
698 qCDebug(LOG_VisualizationGraphWidget())
697 qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::onRangeChanged")
699 << tr("TORM: VisualizationGraphWidget::onRangeChanged")
698 << QThread::currentThread()->objectName() << "DoAcqui"
700 << QThread::currentThread()->objectName() << "DoAcqui" << impl->m_DoAcquisition;
699 << impl->m_DoAcquisition;
701
700
702 auto graphRange = SqpRange{t1.lower, t1.upper};
701 auto graphRange = SqpRange{t1.lower, t1.upper};
703 auto oldGraphRange = SqpRange{t2.lower, t2.upper};
702 auto oldGraphRange = SqpRange{t2.lower, t2.upper};
@@ -142,7 +142,9 VisualizationSelectionZoneItem::VisualizationSelectionZoneItem(QCustomPlot *plot
142 setColor(QColor(DEFAULT_COLOR));
142 setColor(QColor(DEFAULT_COLOR));
143 }
143 }
144
144
145 VisualizationSelectionZoneItem::~VisualizationSelectionZoneItem() {}
145 VisualizationSelectionZoneItem::~VisualizationSelectionZoneItem()
146 {
147 }
146
148
147 VisualizationGraphWidget *VisualizationSelectionZoneItem::parentGraphWidget() const noexcept
149 VisualizationGraphWidget *VisualizationSelectionZoneItem::parentGraphWidget() const noexcept
148 {
150 {
@@ -365,8 +365,8 void TestAmdaResultParser::testReadSpectrogramTxt_data()
365 {8946.475, 18133.158, 10875.621, 24051.619, 19283.221},
365 {8946.475, 18133.158, 10875.621, 24051.619, 19283.221},
366 {20907.664, 32076.725, 13008.381, 13142.759, 23226.998}});
366 {20907.664, 32076.725, 13008.381, 13142.759, 23226.998}});
367
367
368 QTest::newRow("Valid file (four bands)")
368 QTest::newRow("Valid file (four bands)") << QStringLiteral("spectro/ValidSpectrogram2.txt")
369 << QStringLiteral("spectro/ValidSpectrogram2.txt") << fourBandsResult;
369 << fourBandsResult;
370 QTest::newRow("Valid file (four unsorted bands)")
370 QTest::newRow("Valid file (four unsorted bands)")
371 << QStringLiteral("spectro/ValidSpectrogram3.txt")
371 << QStringLiteral("spectro/ValidSpectrogram3.txt")
372 << fourBandsResult; // Bands and values are sorted
372 << fourBandsResult; // Bands and values are sorted
General Comments 0
You need to be logged in to leave comments. Login now