##// END OF EJS Templates
Add saveEvent action
perrinel -
r1280:17a909168f5d
parent child
Show More
@@ -1,338 +1,329
1 #include <Catalogue/CatalogueController.h>
1 #include <Catalogue/CatalogueController.h>
2
2
3 #include <Variable/Variable.h>
3 #include <Variable/Variable.h>
4
4
5 #include <CatalogueDao.h>
5 #include <CatalogueDao.h>
6
6
7 #include <ComparaisonPredicate.h>
7 #include <ComparaisonPredicate.h>
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 <DBEventProduct.h>
12 #include <DBTag.h>
12 #include <DBTag.h>
13 #include <IRequestPredicate.h>
13 #include <IRequestPredicate.h>
14
14
15 #include <QMutex>
15 #include <QMutex>
16 #include <QThread>
16 #include <QThread>
17
17
18 #include <QDir>
18 #include <QDir>
19 #include <QStandardPaths>
19 #include <QStandardPaths>
20
20
21 Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController")
21 Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController")
22
22
23 namespace {
23 namespace {
24
24
25 static QString REPOSITORY_WORK_SUFFIX = QString{"_work"};
25 static QString REPOSITORY_WORK_SUFFIX = QString{"_work"};
26 static QString REPOSITORY_TRASH_SUFFIX = QString{"_trash"};
26 static QString REPOSITORY_TRASH_SUFFIX = QString{"_trash"};
27 }
27 }
28
28
29 class CatalogueController::CatalogueControllerPrivate {
29 class CatalogueController::CatalogueControllerPrivate {
30
30
31 public:
31 public:
32 explicit CatalogueControllerPrivate(CatalogueController *parent) : m_Q{parent} {}
32 explicit CatalogueControllerPrivate(CatalogueController *parent) : m_Q{parent} {}
33
33
34 QMutex m_WorkingMutex;
34 QMutex m_WorkingMutex;
35 CatalogueDao m_CatalogueDao;
35 CatalogueDao m_CatalogueDao;
36
36
37 QStringList m_RepositoryList;
37 QStringList m_RepositoryList;
38 CatalogueController *m_Q;
38 CatalogueController *m_Q;
39
39
40 void copyDBtoDB(const QString &dbFrom, const QString &dbTo);
40 void copyDBtoDB(const QString &dbFrom, const QString &dbTo);
41 QString toWorkRepository(QString repository);
41 QString toWorkRepository(QString repository);
42 QString toSyncRepository(QString repository);
42 QString toSyncRepository(QString repository);
43 void savAllDB();
43 void savAllDB();
44
44
45 void saveEvent(std::shared_ptr<DBEvent> event, bool persist = true);
45 void saveEvent(std::shared_ptr<DBEvent> event, bool persist = true);
46 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool persist = true);
46 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool persist = true);
47 };
47 };
48
48
49 CatalogueController::CatalogueController(QObject *parent)
49 CatalogueController::CatalogueController(QObject *parent)
50 : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>(this)}
50 : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>(this)}
51 {
51 {
52 qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction")
52 qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction")
53 << QThread::currentThread();
53 << QThread::currentThread();
54 }
54 }
55
55
56 CatalogueController::~CatalogueController()
56 CatalogueController::~CatalogueController()
57 {
57 {
58 qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction")
58 qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction")
59 << QThread::currentThread();
59 << QThread::currentThread();
60 this->waitForFinish();
60 this->waitForFinish();
61 }
61 }
62
62
63 QStringList CatalogueController::getRepositories() const
63 QStringList CatalogueController::getRepositories() const
64 {
64 {
65 return impl->m_RepositoryList;
65 return impl->m_RepositoryList;
66 }
66 }
67
67
68 void CatalogueController::addDB(const QString &dbPath)
68 void CatalogueController::addDB(const QString &dbPath)
69 {
69 {
70 QDir dbDir(dbPath);
70 QDir dbDir(dbPath);
71 if (dbDir.exists()) {
71 if (dbDir.exists()) {
72 auto dirName = dbDir.dirName();
72 auto dirName = dbDir.dirName();
73
73
74 if (std::find(impl->m_RepositoryList.cbegin(), impl->m_RepositoryList.cend(), dirName)
74 if (std::find(impl->m_RepositoryList.cbegin(), impl->m_RepositoryList.cend(), dirName)
75 != impl->m_RepositoryList.cend()) {
75 != impl->m_RepositoryList.cend()) {
76 qCCritical(LOG_CatalogueController())
76 qCCritical(LOG_CatalogueController())
77 << tr("Impossible to addDB that is already loaded");
77 << tr("Impossible to addDB that is already loaded");
78 }
78 }
79
79
80 if (!impl->m_CatalogueDao.addDB(dbPath, dirName)) {
80 if (!impl->m_CatalogueDao.addDB(dbPath, dirName)) {
81 qCCritical(LOG_CatalogueController())
81 qCCritical(LOG_CatalogueController())
82 << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath);
82 << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath);
83 }
83 }
84 else {
84 else {
85 impl->m_RepositoryList << dirName;
85 impl->m_RepositoryList << dirName;
86 impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName));
86 impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName));
87 }
87 }
88 }
88 }
89 else {
89 else {
90 qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ")
90 qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ")
91 << dbPath;
91 << dbPath;
92 }
92 }
93 }
93 }
94
94
95 void CatalogueController::saveDB(const QString &destinationPath, const QString &repository)
95 void CatalogueController::saveDB(const QString &destinationPath, const QString &repository)
96 {
96 {
97 if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) {
97 if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) {
98 qCCritical(LOG_CatalogueController())
98 qCCritical(LOG_CatalogueController())
99 << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath);
99 << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath);
100 }
100 }
101 }
101 }
102
102
103 std::list<std::shared_ptr<DBEvent> >
103 std::list<std::shared_ptr<DBEvent> >
104 CatalogueController::retrieveEvents(const QString &repository) const
104 CatalogueController::retrieveEvents(const QString &repository) const
105 {
105 {
106 QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository;
106 QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository;
107
107
108 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
108 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
109 auto events = impl->m_CatalogueDao.getEvents(impl->toWorkRepository(dbDireName));
109 auto events = impl->m_CatalogueDao.getEvents(impl->toWorkRepository(dbDireName));
110 for (auto event : events) {
110 for (auto event : events) {
111 eventsShared.push_back(std::make_shared<DBEvent>(event));
111 eventsShared.push_back(std::make_shared<DBEvent>(event));
112 }
112 }
113 return eventsShared;
113 return eventsShared;
114 }
114 }
115
115
116 std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() const
116 std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() const
117 {
117 {
118 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
118 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
119 for (auto repository : impl->m_RepositoryList) {
119 for (auto repository : impl->m_RepositoryList) {
120 eventsShared.splice(eventsShared.end(), retrieveEvents(repository));
120 eventsShared.splice(eventsShared.end(), retrieveEvents(repository));
121 }
121 }
122
122
123 return eventsShared;
123 return eventsShared;
124 }
124 }
125
125
126 std::list<std::shared_ptr<DBEvent> >
126 std::list<std::shared_ptr<DBEvent> >
127 CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const
127 CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const
128 {
128 {
129 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
129 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
130 auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue);
130 auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue);
131 for (auto event : events) {
131 for (auto event : events) {
132 eventsShared.push_back(std::make_shared<DBEvent>(event));
132 eventsShared.push_back(std::make_shared<DBEvent>(event));
133 }
133 }
134 return eventsShared;
134 return eventsShared;
135 }
135 }
136
136
137 void CatalogueController::updateEvent(std::shared_ptr<DBEvent> event)
137 void CatalogueController::updateEvent(std::shared_ptr<DBEvent> event)
138 {
138 {
139 event->setRepository(impl->toWorkRepository(event->getRepository()));
139 event->setRepository(impl->toWorkRepository(event->getRepository()));
140
140
141 impl->m_CatalogueDao.updateEvent(*event);
141 impl->m_CatalogueDao.updateEvent(*event);
142 }
142 }
143
143
144 void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event)
144 void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event)
145 {
145 {
146 // Remove it from both repository and repository_work
146 // Remove it from both repository and repository_work
147 event->setRepository(impl->toWorkRepository(event->getRepository()));
147 event->setRepository(impl->toWorkRepository(event->getRepository()));
148 impl->m_CatalogueDao.removeEvent(*event);
148 impl->m_CatalogueDao.removeEvent(*event);
149 event->setRepository(impl->toSyncRepository(event->getRepository()));
149 event->setRepository(impl->toSyncRepository(event->getRepository()));
150 impl->m_CatalogueDao.removeEvent(*event);
150 impl->m_CatalogueDao.removeEvent(*event);
151 }
151 }
152
152
153 void CatalogueController::addEvent(std::shared_ptr<DBEvent> event)
153 void CatalogueController::addEvent(std::shared_ptr<DBEvent> event)
154 {
154 {
155 event->setRepository(impl->toWorkRepository(event->getRepository()));
155 event->setRepository(impl->toWorkRepository(event->getRepository()));
156
156
157 auto eventTemp = *event;
157 auto eventTemp = *event;
158 impl->m_CatalogueDao.addEvent(eventTemp);
158 impl->m_CatalogueDao.addEvent(eventTemp);
159
159
160 // Call update is necessary at the creation of add Event if it has some tags or some event
160 // Call update is necessary at the creation of add Event if it has some tags or some event
161 // products
161 // products
162 if (!event->getEventProducts().empty() || !event->getTags().empty()) {
162 if (!event->getEventProducts().empty() || !event->getTags().empty()) {
163
163
164 auto eventProductsTemp = eventTemp.getEventProducts();
164 auto eventProductsTemp = eventTemp.getEventProducts();
165 auto eventProductTempUpdated = std::list<DBEventProduct>{};
165 auto eventProductTempUpdated = std::list<DBEventProduct>{};
166 for (auto eventProductTemp : eventProductsTemp) {
166 for (auto eventProductTemp : eventProductsTemp) {
167 eventProductTemp.setEvent(eventTemp);
167 eventProductTemp.setEvent(eventTemp);
168 eventProductTempUpdated.push_back(eventProductTemp);
168 eventProductTempUpdated.push_back(eventProductTemp);
169 }
169 }
170 eventTemp.setEventProducts(eventProductTempUpdated);
170 eventTemp.setEventProducts(eventProductTempUpdated);
171
171
172 impl->m_CatalogueDao.updateEvent(eventTemp);
172 impl->m_CatalogueDao.updateEvent(eventTemp);
173 }
173 }
174 }
174 }
175
175
176 void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event)
176 void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event)
177 {
177 {
178 impl->saveEvent(event, true);
178 impl->saveEvent(event, true);
179 }
179 }
180
180
181 std::list<std::shared_ptr<DBCatalogue> >
181 std::list<std::shared_ptr<DBCatalogue> >
182 CatalogueController::retrieveCatalogues(const QString &repository) const
182 CatalogueController::retrieveCatalogues(const QString &repository) const
183 {
183 {
184 QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository;
184 QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository;
185
185
186 auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
186 auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
187 auto catalogues = impl->m_CatalogueDao.getCatalogues(impl->toWorkRepository(dbDireName));
187 auto catalogues = impl->m_CatalogueDao.getCatalogues(impl->toWorkRepository(dbDireName));
188 for (auto catalogue : catalogues) {
188 for (auto catalogue : catalogues) {
189 cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue));
189 cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue));
190 }
190 }
191 return cataloguesShared;
191 return cataloguesShared;
192 }
192 }
193
193
194 void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue)
194 void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue)
195 {
195 {
196 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
196 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
197
197
198 impl->m_CatalogueDao.updateCatalogue(*catalogue);
198 impl->m_CatalogueDao.updateCatalogue(*catalogue);
199 }
199 }
200
200
201 void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue)
201 void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue)
202 {
202 {
203 // Remove it from both repository and repository_work
203 // Remove it from both repository and repository_work
204 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
204 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
205 impl->m_CatalogueDao.removeCatalogue(*catalogue);
205 impl->m_CatalogueDao.removeCatalogue(*catalogue);
206 catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository()));
206 catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository()));
207 impl->m_CatalogueDao.removeCatalogue(*catalogue);
207 impl->m_CatalogueDao.removeCatalogue(*catalogue);
208 }
208 }
209
209
210 void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue)
210 void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue)
211 {
211 {
212 impl->saveCatalogue(catalogue, true);
212 impl->saveCatalogue(catalogue, true);
213 }
213 }
214
214
215 void CatalogueController::saveAll()
215 void CatalogueController::saveAll()
216 {
216 {
217 for (auto repository : impl->m_RepositoryList) {
217 for (auto repository : impl->m_RepositoryList) {
218 // Save Event
218 // Save Event
219 auto events = this->retrieveEvents(repository);
219 auto events = this->retrieveEvents(repository);
220 for (auto event : events) {
220 for (auto event : events) {
221 impl->saveEvent(event, false);
221 impl->saveEvent(event, false);
222 }
222 }
223
223
224 // Save Catalogue
224 // Save Catalogue
225 auto catalogues = this->retrieveCatalogues(repository);
225 auto catalogues = this->retrieveCatalogues(repository);
226 for (auto catalogue : catalogues) {
226 for (auto catalogue : catalogues) {
227 impl->saveCatalogue(catalogue, false);
227 impl->saveCatalogue(catalogue, false);
228 }
228 }
229 }
229 }
230
230
231 impl->savAllDB();
231 impl->savAllDB();
232 }
232 }
233
233
234 void CatalogueController::initialize()
234 void CatalogueController::initialize()
235 {
235 {
236 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
236 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
237 << QThread::currentThread();
237 << QThread::currentThread();
238 impl->m_WorkingMutex.lock();
238 impl->m_WorkingMutex.lock();
239 impl->m_CatalogueDao.initialize();
239 impl->m_CatalogueDao.initialize();
240 auto defaultRepositoryLocation
240 auto defaultRepositoryLocation
241 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
241 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
242
242
243 QDir defaultRepositoryLocationDir;
243 QDir defaultRepositoryLocationDir;
244 if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) {
244 if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) {
245 defaultRepositoryLocationDir.cd(defaultRepositoryLocation);
245 defaultRepositoryLocationDir.cd(defaultRepositoryLocation);
246 auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT);
246 auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT);
247 qCInfo(LOG_CatalogueController()) << tr("Persistant data loading from: ")
247 qCInfo(LOG_CatalogueController()) << tr("Persistant data loading from: ")
248 << defaultRepository;
248 << defaultRepository;
249 this->addDB(defaultRepository);
249 this->addDB(defaultRepository);
250 }
250 }
251 else {
251 else {
252 qCWarning(LOG_CatalogueController())
252 qCWarning(LOG_CatalogueController())
253 << tr("Cannot load the persistent default repository from ")
253 << tr("Cannot load the persistent default repository from ")
254 << defaultRepositoryLocation;
254 << defaultRepositoryLocation;
255 }
255 }
256
256
257 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END");
257 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END");
258 }
258 }
259
259
260 void CatalogueController::finalize()
260 void CatalogueController::finalize()
261 {
261 {
262 impl->m_WorkingMutex.unlock();
262 impl->m_WorkingMutex.unlock();
263 }
263 }
264
264
265 void CatalogueController::waitForFinish()
265 void CatalogueController::waitForFinish()
266 {
266 {
267 QMutexLocker locker{&impl->m_WorkingMutex};
267 QMutexLocker locker{&impl->m_WorkingMutex};
268 }
268 }
269
269
270 void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom,
270 void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom,
271 const QString &dbTo)
271 const QString &dbTo)
272 {
272 {
273 auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
273 // auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
274 auto catalogues = m_CatalogueDao.getCatalogues(dbFrom);
274 auto catalogues = m_CatalogueDao.getCatalogues(dbFrom);
275 auto events = m_CatalogueDao.getEvents(dbFrom);
275 for (auto catalogue : catalogues) {
276 for (auto catalogue : catalogues) {
276 cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue));
277 m_CatalogueDao.copyCatalogue(catalogue, dbTo, true);
277 }
278 }
278
279
279 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
280 auto events = m_CatalogueDao.getEvents(dbFrom);
281 for (auto event : events) {
280 for (auto event : events) {
282 eventsShared.push_back(std::make_shared<DBEvent>(event));
281 m_CatalogueDao.copyEvent(event, dbTo, true);
283 }
284
285 for (auto catalogue : cataloguesShared) {
286 m_CatalogueDao.copyCatalogue(*catalogue, dbTo, true);
287 }
288
289 for (auto event : eventsShared) {
290 m_CatalogueDao.copyEvent(*event, dbTo, true);
291 }
282 }
292 }
283 }
293
284
294 QString CatalogueController::CatalogueControllerPrivate::toWorkRepository(QString repository)
285 QString CatalogueController::CatalogueControllerPrivate::toWorkRepository(QString repository)
295 {
286 {
296 auto syncRepository = toSyncRepository(repository);
287 auto syncRepository = toSyncRepository(repository);
297
288
298 return QString("%1%2").arg(syncRepository, REPOSITORY_WORK_SUFFIX);
289 return QString("%1%2").arg(syncRepository, REPOSITORY_WORK_SUFFIX);
299 }
290 }
300
291
301 QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QString repository)
292 QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QString repository)
302 {
293 {
303 auto syncRepository = repository;
294 auto syncRepository = repository;
304 if (repository.endsWith(REPOSITORY_WORK_SUFFIX)) {
295 if (repository.endsWith(REPOSITORY_WORK_SUFFIX)) {
305 syncRepository.remove(REPOSITORY_WORK_SUFFIX);
296 syncRepository.remove(REPOSITORY_WORK_SUFFIX);
306 }
297 }
307 else if (repository.endsWith(REPOSITORY_TRASH_SUFFIX)) {
298 else if (repository.endsWith(REPOSITORY_TRASH_SUFFIX)) {
308 syncRepository.remove(REPOSITORY_TRASH_SUFFIX);
299 syncRepository.remove(REPOSITORY_TRASH_SUFFIX);
309 }
300 }
310 return syncRepository;
301 return syncRepository;
311 }
302 }
312
303
313 void CatalogueController::CatalogueControllerPrivate::savAllDB()
304 void CatalogueController::CatalogueControllerPrivate::savAllDB()
314 {
305 {
315 for (auto repository : m_RepositoryList) {
306 for (auto repository : m_RepositoryList) {
316 auto defaultRepositoryLocation
307 auto defaultRepositoryLocation
317 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
308 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
318 m_CatalogueDao.saveDB(defaultRepositoryLocation, repository);
309 m_CatalogueDao.saveDB(defaultRepositoryLocation, repository);
319 }
310 }
320 }
311 }
321
312
322 void CatalogueController::CatalogueControllerPrivate::saveEvent(std::shared_ptr<DBEvent> event,
313 void CatalogueController::CatalogueControllerPrivate::saveEvent(std::shared_ptr<DBEvent> event,
323 bool persist)
314 bool persist)
324 {
315 {
325 m_CatalogueDao.moveEvent(*event, toSyncRepository(event->getRepository()), true);
316 m_CatalogueDao.copyEvent(*event, toSyncRepository(event->getRepository()), true);
326 if (persist) {
317 if (persist) {
327 savAllDB();
318 savAllDB();
328 }
319 }
329 }
320 }
330
321
331 void CatalogueController::CatalogueControllerPrivate::saveCatalogue(
322 void CatalogueController::CatalogueControllerPrivate::saveCatalogue(
332 std::shared_ptr<DBCatalogue> catalogue, bool persist)
323 std::shared_ptr<DBCatalogue> catalogue, bool persist)
333 {
324 {
334 m_CatalogueDao.moveCatalogue(*catalogue, toSyncRepository(catalogue->getRepository()), true);
325 m_CatalogueDao.copyCatalogue(*catalogue, toSyncRepository(catalogue->getRepository()), true);
335 if (persist) {
326 if (persist) {
336 savAllDB();
327 savAllDB();
337 }
328 }
338 }
329 }
@@ -1,360 +1,364
1 #include "Catalogue/CatalogueEventsWidget.h"
1 #include "Catalogue/CatalogueEventsWidget.h"
2 #include "ui_CatalogueEventsWidget.h"
2 #include "ui_CatalogueEventsWidget.h"
3
3
4 #include <Catalogue/CatalogueController.h>
4 #include <Catalogue/CatalogueController.h>
5 #include <Catalogue/CatalogueEventsModel.h>
5 #include <Catalogue/CatalogueEventsModel.h>
6 #include <Catalogue/CatalogueExplorerHelper.h>
6 #include <Catalogue/CatalogueExplorerHelper.h>
7 #include <CatalogueDao.h>
7 #include <CatalogueDao.h>
8 #include <DBCatalogue.h>
8 #include <DBCatalogue.h>
9 #include <SqpApplication.h>
9 #include <SqpApplication.h>
10 #include <Visualization/VisualizationTabWidget.h>
10 #include <Visualization/VisualizationTabWidget.h>
11 #include <Visualization/VisualizationWidget.h>
11 #include <Visualization/VisualizationWidget.h>
12 #include <Visualization/VisualizationZoneWidget.h>
12 #include <Visualization/VisualizationZoneWidget.h>
13
13
14 #include <QDialog>
14 #include <QDialog>
15 #include <QDialogButtonBox>
15 #include <QDialogButtonBox>
16 #include <QListWidget>
16 #include <QListWidget>
17
17
18 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
18 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
19
19
20 /// Fixed size of the validation column
20 /// Fixed size of the validation column
21 const auto VALIDATION_COLUMN_SIZE = 35;
21 const auto VALIDATION_COLUMN_SIZE = 35;
22
22
23 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
23 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
24
24
25 CatalogueEventsModel *m_Model = nullptr;
25 CatalogueEventsModel *m_Model = nullptr;
26 QStringList m_ZonesForTimeMode;
26 QStringList m_ZonesForTimeMode;
27 QString m_ZoneForGraphMode;
27 QString m_ZoneForGraphMode;
28
28
29 VisualizationWidget *m_VisualizationWidget = nullptr;
29 VisualizationWidget *m_VisualizationWidget = nullptr;
30
30
31 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, QTreeView *treeView)
31 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, QTreeView *treeView)
32 {
32 {
33 treeView->setSortingEnabled(false);
33 treeView->setSortingEnabled(false);
34 m_Model->setEvents(events);
34 m_Model->setEvents(events);
35 treeView->setSortingEnabled(true);
35 treeView->setSortingEnabled(true);
36 }
36 }
37
37
38 void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
38 void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
39 {
39 {
40 treeView->setSortingEnabled(false);
40 treeView->setSortingEnabled(false);
41 m_Model->addEvent(event);
41 m_Model->addEvent(event);
42 treeView->setSortingEnabled(true);
42 treeView->setSortingEnabled(true);
43 }
43 }
44
44
45 void removeEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
45 void removeEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
46 {
46 {
47 treeView->setSortingEnabled(false);
47 treeView->setSortingEnabled(false);
48 m_Model->removeEvent(event);
48 m_Model->removeEvent(event);
49 treeView->setSortingEnabled(true);
49 treeView->setSortingEnabled(true);
50 }
50 }
51
51
52 QStringList getAvailableVisualizationZoneList() const
52 QStringList getAvailableVisualizationZoneList() const
53 {
53 {
54 if (m_VisualizationWidget) {
54 if (m_VisualizationWidget) {
55 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
55 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
56 return tab->availableZoneWidgets();
56 return tab->availableZoneWidgets();
57 }
57 }
58 }
58 }
59
59
60 return QStringList{};
60 return QStringList{};
61 }
61 }
62
62
63 QStringList selectZone(QWidget *parent, const QStringList &selectedZones,
63 QStringList selectZone(QWidget *parent, const QStringList &selectedZones,
64 bool allowMultiSelection, const QPoint &location)
64 bool allowMultiSelection, const QPoint &location)
65 {
65 {
66 auto availableZones = getAvailableVisualizationZoneList();
66 auto availableZones = getAvailableVisualizationZoneList();
67 if (availableZones.isEmpty()) {
67 if (availableZones.isEmpty()) {
68 return QStringList{};
68 return QStringList{};
69 }
69 }
70
70
71 QDialog d(parent, Qt::Tool);
71 QDialog d(parent, Qt::Tool);
72 d.setWindowTitle("Choose a zone");
72 d.setWindowTitle("Choose a zone");
73 auto layout = new QVBoxLayout{&d};
73 auto layout = new QVBoxLayout{&d};
74 layout->setContentsMargins(0, 0, 0, 0);
74 layout->setContentsMargins(0, 0, 0, 0);
75 auto listWidget = new QListWidget{&d};
75 auto listWidget = new QListWidget{&d};
76 layout->addWidget(listWidget);
76 layout->addWidget(listWidget);
77
77
78 QSet<QListWidgetItem *> checkedItems;
78 QSet<QListWidgetItem *> checkedItems;
79 for (auto zone : availableZones) {
79 for (auto zone : availableZones) {
80 auto item = new QListWidgetItem{zone};
80 auto item = new QListWidgetItem{zone};
81 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
81 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
82 if (selectedZones.contains(zone)) {
82 if (selectedZones.contains(zone)) {
83 item->setCheckState(Qt::Checked);
83 item->setCheckState(Qt::Checked);
84 checkedItems << item;
84 checkedItems << item;
85 }
85 }
86 else {
86 else {
87 item->setCheckState(Qt::Unchecked);
87 item->setCheckState(Qt::Unchecked);
88 }
88 }
89
89
90 listWidget->addItem(item);
90 listWidget->addItem(item);
91 }
91 }
92
92
93 auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d};
93 auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d};
94 layout->addWidget(buttonBox);
94 layout->addWidget(buttonBox);
95
95
96 QObject::connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept);
96 QObject::connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept);
97 QObject::connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject);
97 QObject::connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject);
98
98
99 QObject::connect(listWidget, &QListWidget::itemChanged,
99 QObject::connect(listWidget, &QListWidget::itemChanged,
100 [&checkedItems, allowMultiSelection, listWidget](auto item) {
100 [&checkedItems, allowMultiSelection, listWidget](auto item) {
101 if (item->checkState() == Qt::Checked) {
101 if (item->checkState() == Qt::Checked) {
102 if (!allowMultiSelection) {
102 if (!allowMultiSelection) {
103 for (auto checkedItem : checkedItems) {
103 for (auto checkedItem : checkedItems) {
104 listWidget->blockSignals(true);
104 listWidget->blockSignals(true);
105 checkedItem->setCheckState(Qt::Unchecked);
105 checkedItem->setCheckState(Qt::Unchecked);
106 listWidget->blockSignals(false);
106 listWidget->blockSignals(false);
107 }
107 }
108
108
109 checkedItems.clear();
109 checkedItems.clear();
110 }
110 }
111 checkedItems << item;
111 checkedItems << item;
112 }
112 }
113 else {
113 else {
114 checkedItems.remove(item);
114 checkedItems.remove(item);
115 }
115 }
116 });
116 });
117
117
118 QStringList result;
118 QStringList result;
119
119
120 d.setMinimumWidth(120);
120 d.setMinimumWidth(120);
121 d.resize(d.minimumSizeHint());
121 d.resize(d.minimumSizeHint());
122 d.move(location);
122 d.move(location);
123 if (d.exec() == QDialog::Accepted) {
123 if (d.exec() == QDialog::Accepted) {
124 for (auto item : checkedItems) {
124 for (auto item : checkedItems) {
125 result += item->text();
125 result += item->text();
126 }
126 }
127 }
127 }
128 else {
128 else {
129 result = selectedZones;
129 result = selectedZones;
130 }
130 }
131
131
132 return result;
132 return result;
133 }
133 }
134
134
135 void updateForTimeMode(QTreeView *treeView)
135 void updateForTimeMode(QTreeView *treeView)
136 {
136 {
137 auto selectedRows = treeView->selectionModel()->selectedRows();
137 auto selectedRows = treeView->selectionModel()->selectedRows();
138
138
139 if (selectedRows.count() == 1) {
139 if (selectedRows.count() == 1) {
140 auto event = m_Model->getEvent(selectedRows.first());
140 auto event = m_Model->getEvent(selectedRows.first());
141 if (event) {
141 if (event) {
142 if (m_VisualizationWidget) {
142 if (m_VisualizationWidget) {
143 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
143 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
144
144
145 for (auto zoneName : m_ZonesForTimeMode) {
145 for (auto zoneName : m_ZonesForTimeMode) {
146 if (auto zone = tab->getZoneWithName(zoneName)) {
146 if (auto zone = tab->getZoneWithName(zoneName)) {
147 SqpRange eventRange;
147 SqpRange eventRange;
148 eventRange.m_TStart = event->getTStart();
148 eventRange.m_TStart = event->getTStart();
149 eventRange.m_TEnd = event->getTEnd();
149 eventRange.m_TEnd = event->getTEnd();
150 zone->setZoneRange(eventRange);
150 zone->setZoneRange(eventRange);
151 }
151 }
152 }
152 }
153 }
153 }
154 else {
154 else {
155 qCWarning(LOG_CatalogueEventsWidget())
155 qCWarning(LOG_CatalogueEventsWidget())
156 << "updateTimeZone: no tab found in the visualization";
156 << "updateTimeZone: no tab found in the visualization";
157 }
157 }
158 }
158 }
159 else {
159 else {
160 qCWarning(LOG_CatalogueEventsWidget())
160 qCWarning(LOG_CatalogueEventsWidget())
161 << "updateTimeZone: visualization widget not found";
161 << "updateTimeZone: visualization widget not found";
162 }
162 }
163 }
163 }
164 }
164 }
165 else {
165 else {
166 qCWarning(LOG_CatalogueEventsWidget())
166 qCWarning(LOG_CatalogueEventsWidget())
167 << "updateTimeZone: not compatible with multiple events selected";
167 << "updateTimeZone: not compatible with multiple events selected";
168 }
168 }
169 }
169 }
170
170
171 void updateForGraphMode(QTreeView *treeView)
171 void updateForGraphMode(QTreeView *treeView)
172 {
172 {
173 auto selectedRows = treeView->selectionModel()->selectedRows();
173 auto selectedRows = treeView->selectionModel()->selectedRows();
174
174
175 if (selectedRows.count() == 1) {
175 if (selectedRows.count() == 1) {
176 auto event = m_Model->getEvent(selectedRows.first());
176 auto event = m_Model->getEvent(selectedRows.first());
177 if (m_VisualizationWidget) {
177 if (m_VisualizationWidget) {
178 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
178 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
179 if (auto zone = tab->getZoneWithName(m_ZoneForGraphMode)) {
179 if (auto zone = tab->getZoneWithName(m_ZoneForGraphMode)) {
180 // TODO
180 // TODO
181 }
181 }
182 }
182 }
183 else {
183 else {
184 qCWarning(LOG_CatalogueEventsWidget())
184 qCWarning(LOG_CatalogueEventsWidget())
185 << "updateGraphMode: no tab found in the visualization";
185 << "updateGraphMode: no tab found in the visualization";
186 }
186 }
187 }
187 }
188 else {
188 else {
189 qCWarning(LOG_CatalogueEventsWidget())
189 qCWarning(LOG_CatalogueEventsWidget())
190 << "updateGraphMode: visualization widget not found";
190 << "updateGraphMode: visualization widget not found";
191 }
191 }
192 }
192 }
193 else {
193 else {
194 qCWarning(LOG_CatalogueEventsWidget())
194 qCWarning(LOG_CatalogueEventsWidget())
195 << "updateGraphMode: not compatible with multiple events selected";
195 << "updateGraphMode: not compatible with multiple events selected";
196 }
196 }
197 }
197 }
198 };
198 };
199
199
200 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
200 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
201 : QWidget(parent),
201 : QWidget(parent),
202 ui(new Ui::CatalogueEventsWidget),
202 ui(new Ui::CatalogueEventsWidget),
203 impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()}
203 impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()}
204 {
204 {
205 ui->setupUi(this);
205 ui->setupUi(this);
206
206
207 impl->m_Model = new CatalogueEventsModel{this};
207 impl->m_Model = new CatalogueEventsModel{this};
208 ui->treeView->setModel(impl->m_Model);
208 ui->treeView->setModel(impl->m_Model);
209
209
210 ui->treeView->setSortingEnabled(true);
210 ui->treeView->setSortingEnabled(true);
211 ui->treeView->setDragDropMode(QAbstractItemView::DragDrop);
211 ui->treeView->setDragDropMode(QAbstractItemView::DragDrop);
212 ui->treeView->setDragEnabled(true);
212 ui->treeView->setDragEnabled(true);
213
213
214 connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) {
214 connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) {
215 if (checked) {
215 if (checked) {
216 ui->btnChart->setChecked(false);
216 ui->btnChart->setChecked(false);
217 impl->m_ZonesForTimeMode
217 impl->m_ZonesForTimeMode
218 = impl->selectZone(this, impl->m_ZonesForTimeMode, true,
218 = impl->selectZone(this, impl->m_ZonesForTimeMode, true,
219 this->mapToGlobal(ui->btnTime->frameGeometry().center()));
219 this->mapToGlobal(ui->btnTime->frameGeometry().center()));
220
220
221 impl->updateForTimeMode(ui->treeView);
221 impl->updateForTimeMode(ui->treeView);
222 }
222 }
223 });
223 });
224
224
225 connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) {
225 connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) {
226 if (checked) {
226 if (checked) {
227 ui->btnTime->setChecked(false);
227 ui->btnTime->setChecked(false);
228 impl->m_ZoneForGraphMode
228 impl->m_ZoneForGraphMode
229 = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false,
229 = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false,
230 this->mapToGlobal(ui->btnChart->frameGeometry().center()))
230 this->mapToGlobal(ui->btnChart->frameGeometry().center()))
231 .value(0);
231 .value(0);
232
232
233 impl->updateForGraphMode(ui->treeView);
233 impl->updateForGraphMode(ui->treeView);
234 }
234 }
235 });
235 });
236
236
237 auto emitSelection = [this]() {
237 auto emitSelection = [this]() {
238 QVector<std::shared_ptr<DBEvent> > events;
238 QVector<std::shared_ptr<DBEvent> > events;
239 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
239 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
240
240
241 for (auto rowIndex : ui->treeView->selectionModel()->selectedRows()) {
241 for (auto rowIndex : ui->treeView->selectionModel()->selectedRows()) {
242
242
243 auto itemType = impl->m_Model->itemTypeOf(rowIndex);
243 auto itemType = impl->m_Model->itemTypeOf(rowIndex);
244 if (itemType == CatalogueEventsModel::ItemType::Event) {
244 if (itemType == CatalogueEventsModel::ItemType::Event) {
245 events << impl->m_Model->getEvent(rowIndex);
245 events << impl->m_Model->getEvent(rowIndex);
246 }
246 }
247 else if (itemType == CatalogueEventsModel::ItemType::EventProduct) {
247 else if (itemType == CatalogueEventsModel::ItemType::EventProduct) {
248 eventProducts << qMakePair(impl->m_Model->getParentEvent(rowIndex),
248 eventProducts << qMakePair(impl->m_Model->getParentEvent(rowIndex),
249 impl->m_Model->getEventProduct(rowIndex));
249 impl->m_Model->getEventProduct(rowIndex));
250 }
250 }
251 }
251 }
252
252
253 if (!events.isEmpty() && eventProducts.isEmpty()) {
253 if (!events.isEmpty() && eventProducts.isEmpty()) {
254 emit this->eventsSelected(events);
254 emit this->eventsSelected(events);
255 }
255 }
256 else if (events.isEmpty() && !eventProducts.isEmpty()) {
256 else if (events.isEmpty() && !eventProducts.isEmpty()) {
257 emit this->eventProductsSelected(eventProducts);
257 emit this->eventProductsSelected(eventProducts);
258 }
258 }
259 else {
259 else {
260 emit this->selectionCleared();
260 emit this->selectionCleared();
261 }
261 }
262 };
262 };
263
263
264 connect(ui->treeView, &QTreeView::clicked, emitSelection);
264 connect(ui->treeView, &QTreeView::clicked, emitSelection);
265 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection);
265 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection);
266
266
267 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
267 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
268 auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1;
268 auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1;
269 ui->btnChart->setEnabled(isNotMultiSelection);
269 ui->btnChart->setEnabled(isNotMultiSelection);
270 ui->btnTime->setEnabled(isNotMultiSelection);
270 ui->btnTime->setEnabled(isNotMultiSelection);
271
271
272 if (isNotMultiSelection && ui->btnTime->isChecked()) {
272 if (isNotMultiSelection && ui->btnTime->isChecked()) {
273 impl->updateForTimeMode(ui->treeView);
273 impl->updateForTimeMode(ui->treeView);
274 }
274 }
275 else if (isNotMultiSelection && ui->btnChart->isChecked()) {
275 else if (isNotMultiSelection && ui->btnChart->isChecked()) {
276 impl->updateForGraphMode(ui->treeView);
276 impl->updateForGraphMode(ui->treeView);
277 }
277 }
278 });
278 });
279
279
280 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
280 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
281 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Name,
281 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Name,
282 QHeaderView::Stretch);
282 QHeaderView::Stretch);
283 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Validation,
283 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Validation,
284 QHeaderView::Fixed);
284 QHeaderView::Fixed);
285 ui->treeView->header()->resizeSection((int)CatalogueEventsModel::Column::Validation,
285 ui->treeView->header()->resizeSection((int)CatalogueEventsModel::Column::Validation,
286 VALIDATION_COLUMN_SIZE);
286 VALIDATION_COLUMN_SIZE);
287 ui->treeView->header()->setSortIndicatorShown(true);
287 ui->treeView->header()->setSortIndicatorShown(true);
288
288
289 connect(impl->m_Model, &CatalogueEventsModel::modelSorted, [this]() {
289 connect(impl->m_Model, &CatalogueEventsModel::modelSorted, [this]() {
290 auto allEvents = impl->m_Model->events();
290 auto allEvents = impl->m_Model->events();
291 for (auto event : allEvents) {
291 for (auto event : allEvents) {
292 setEventChanges(event, impl->m_Model->eventsHasChanges(event));
292 setEventChanges(event, impl->m_Model->eventsHasChanges(event));
293 }
293 }
294 });
294 });
295 }
295 }
296
296
297 CatalogueEventsWidget::~CatalogueEventsWidget()
297 CatalogueEventsWidget::~CatalogueEventsWidget()
298 {
298 {
299 delete ui;
299 delete ui;
300 }
300 }
301
301
302 void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualization)
302 void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualization)
303 {
303 {
304 impl->m_VisualizationWidget = visualization;
304 impl->m_VisualizationWidget = visualization;
305 }
305 }
306
306
307 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges)
307 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges)
308 {
308 {
309 impl->m_Model->refreshEvent(event);
309 impl->m_Model->refreshEvent(event);
310
310
311 auto eventIndex = impl->m_Model->indexOf(event);
311 auto eventIndex = impl->m_Model->indexOf(event);
312 auto validationIndex
312 auto validationIndex
313 = eventIndex.sibling(eventIndex.row(), (int)CatalogueEventsModel::Column::Validation);
313 = eventIndex.sibling(eventIndex.row(), (int)CatalogueEventsModel::Column::Validation);
314
314
315 if (hasChanges) {
315 if (hasChanges) {
316 if (ui->treeView->indexWidget(validationIndex) == nullptr) {
316 if (ui->treeView->indexWidget(validationIndex) == nullptr) {
317 auto widget = CatalogueExplorerHelper::buildValidationWidget(
317 auto widget = CatalogueExplorerHelper::buildValidationWidget(
318 ui->treeView, [this, event]() { setEventChanges(event, false); },
318 ui->treeView,
319 [this, event]() {
320 sqpApp->catalogueController().saveEvent(event);
321 setEventChanges(event, false);
322 },
319 [this, event]() { setEventChanges(event, false); });
323 [this, event]() { setEventChanges(event, false); });
320 ui->treeView->setIndexWidget(validationIndex, widget);
324 ui->treeView->setIndexWidget(validationIndex, widget);
321 }
325 }
322 }
326 }
323 else {
327 else {
324 // Note: the widget is destroyed
328 // Note: the widget is destroyed
325 ui->treeView->setIndexWidget(validationIndex, nullptr);
329 ui->treeView->setIndexWidget(validationIndex, nullptr);
326 }
330 }
327
331
328 impl->m_Model->setEventHasChanges(event, hasChanges);
332 impl->m_Model->setEventHasChanges(event, hasChanges);
329 }
333 }
330
334
331 void CatalogueEventsWidget::populateWithCatalogues(
335 void CatalogueEventsWidget::populateWithCatalogues(
332 const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
336 const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
333 {
337 {
334 QSet<QUuid> eventIds;
338 QSet<QUuid> eventIds;
335 QVector<std::shared_ptr<DBEvent> > events;
339 QVector<std::shared_ptr<DBEvent> > events;
336
340
337 for (auto catalogue : catalogues) {
341 for (auto catalogue : catalogues) {
338 auto catalogueEvents = sqpApp->catalogueController().retrieveEventsFromCatalogue(catalogue);
342 auto catalogueEvents = sqpApp->catalogueController().retrieveEventsFromCatalogue(catalogue);
339 for (auto event : catalogueEvents) {
343 for (auto event : catalogueEvents) {
340 if (!eventIds.contains(event->getUniqId())) {
344 if (!eventIds.contains(event->getUniqId())) {
341 events << event;
345 events << event;
342 eventIds.insert(event->getUniqId());
346 eventIds.insert(event->getUniqId());
343 }
347 }
344 }
348 }
345 }
349 }
346
350
347 impl->setEvents(events, ui->treeView);
351 impl->setEvents(events, ui->treeView);
348 }
352 }
349
353
350 void CatalogueEventsWidget::populateWithAllEvents()
354 void CatalogueEventsWidget::populateWithAllEvents()
351 {
355 {
352 auto allEvents = sqpApp->catalogueController().retrieveAllEvents();
356 auto allEvents = sqpApp->catalogueController().retrieveAllEvents();
353
357
354 QVector<std::shared_ptr<DBEvent> > events;
358 QVector<std::shared_ptr<DBEvent> > events;
355 for (auto event : allEvents) {
359 for (auto event : allEvents) {
356 events << event;
360 events << event;
357 }
361 }
358
362
359 impl->setEvents(events, ui->treeView);
363 impl->setEvents(events, ui->treeView);
360 }
364 }
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved
author

Status change > Approved

You need to be logged in to leave comments. Login now