##// END OF EJS Templates
Discard an added event remove it now.
perrinel -
r1321:fba51a5eef20
parent child
Show More
@@ -1,84 +1,84
1 #ifndef SCIQLOP_CATALOGUECONTROLLER_H
1 #ifndef SCIQLOP_CATALOGUECONTROLLER_H
2 #define SCIQLOP_CATALOGUECONTROLLER_H
2 #define SCIQLOP_CATALOGUECONTROLLER_H
3
3
4 #include "CoreGlobal.h"
4 #include "CoreGlobal.h"
5
5
6 #include <Data/SqpRange.h>
6 #include <Data/SqpRange.h>
7
7
8 #include <QLoggingCategory>
8 #include <QLoggingCategory>
9 #include <QObject>
9 #include <QObject>
10 #include <QUuid>
10 #include <QUuid>
11
11
12 #include <Common/spimpl.h>
12 #include <Common/spimpl.h>
13
13
14 #include <memory>
14 #include <memory>
15
15
16 class DBCatalogue;
16 class DBCatalogue;
17 class DBEvent;
17 class DBEvent;
18 class DBEventProduct;
18 class DBEventProduct;
19
19
20 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController)
20 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController)
21
21
22 class DataSourceItem;
22 class DataSourceItem;
23 class Variable;
23 class Variable;
24
24
25 /**
25 /**
26 * @brief The CatalogueController class aims to handle catalogues and event using the CatalogueAPI
26 * @brief The CatalogueController class aims to handle catalogues and event using the CatalogueAPI
27 * library.
27 * library.
28 */
28 */
29 class SCIQLOP_CORE_EXPORT CatalogueController : public QObject {
29 class SCIQLOP_CORE_EXPORT CatalogueController : public QObject {
30 Q_OBJECT
30 Q_OBJECT
31 public:
31 public:
32 explicit CatalogueController(QObject *parent = 0);
32 explicit CatalogueController(QObject *parent = 0);
33 virtual ~CatalogueController();
33 virtual ~CatalogueController();
34
34
35 // DB
35 // DB
36 QStringList getRepositories() const;
36 QStringList getRepositories() const;
37 void addDB(const QString &dbPath);
37 void addDB(const QString &dbPath);
38 void saveDB(const QString &destinationPath, const QString &repository);
38 void saveDB(const QString &destinationPath, const QString &repository);
39
39
40 // Event
40 // Event
41 /// retrieveEvents with empty repository retrieve them from the default repository
41 /// retrieveEvents with empty repository retrieve them from the default repository
42 std::list<std::shared_ptr<DBEvent> > retrieveEvents(const QString &repository) const;
42 std::list<std::shared_ptr<DBEvent> > retrieveEvents(const QString &repository) const;
43 std::list<std::shared_ptr<DBEvent> > retrieveAllEvents() const;
43 std::list<std::shared_ptr<DBEvent> > retrieveAllEvents() const;
44
44
45 void addEvent(std::shared_ptr<DBEvent> event);
45 void addEvent(std::shared_ptr<DBEvent> event);
46 void updateEvent(std::shared_ptr<DBEvent> event);
46 void updateEvent(std::shared_ptr<DBEvent> event);
47 void updateEventProduct(std::shared_ptr<DBEventProduct> eventProduct);
47 void updateEventProduct(std::shared_ptr<DBEventProduct> eventProduct);
48 void removeEvent(std::shared_ptr<DBEvent> event);
48 void removeEvent(std::shared_ptr<DBEvent> event);
49 // void trashEvent(std::shared_ptr<DBEvent> event);
49 // void trashEvent(std::shared_ptr<DBEvent> event);
50 // void restore(std::shared_ptr<DBEvent> event);
50 // void restore(std::shared_ptr<DBEvent> event);
51 void saveEvent(std::shared_ptr<DBEvent> event);
51 void saveEvent(std::shared_ptr<DBEvent> event);
52 void discardEvent(std::shared_ptr<DBEvent> event);
52 void discardEvent(std::shared_ptr<DBEvent> event, bool &removed);
53 bool eventHasChanges(std::shared_ptr<DBEvent> event) const;
53 bool eventHasChanges(std::shared_ptr<DBEvent> event) const;
54
54
55 // Catalogue
55 // Catalogue
56 std::list<std::shared_ptr<DBEvent> >
56 std::list<std::shared_ptr<DBEvent> >
57 retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const;
57 retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const;
58 // bool createCatalogue(const QString &name, QVector<QUuid> eventList);
58 // bool createCatalogue(const QString &name, QVector<QUuid> eventList);
59 /// retrieveEvents with empty repository retrieve them from the default repository
59 /// retrieveEvents with empty repository retrieve them from the default repository
60 std::list<std::shared_ptr<DBCatalogue> > retrieveCatalogues(const QString &repository
60 std::list<std::shared_ptr<DBCatalogue> > retrieveCatalogues(const QString &repository
61 = QString()) const;
61 = QString()) const;
62 void updateCatalogue(std::shared_ptr<DBCatalogue> catalogue);
62 void updateCatalogue(std::shared_ptr<DBCatalogue> catalogue);
63 void removeCatalogue(std::shared_ptr<DBCatalogue> catalogue);
63 void removeCatalogue(std::shared_ptr<DBCatalogue> catalogue);
64 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue);
64 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue);
65
65
66 void saveAll();
66 void saveAll();
67 bool hasChanges() const;
67 bool hasChanges() const;
68
68
69 /// Returns the MIME data associated to a list of variables
69 /// Returns the MIME data associated to a list of variables
70 QByteArray mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const;
70 QByteArray mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const;
71
71
72 /// Returns the list of variables contained in a MIME data
72 /// Returns the list of variables contained in a MIME data
73 QVector<std::shared_ptr<DBEvent> > eventsForMimeData(const QByteArray &mimeData) const;
73 QVector<std::shared_ptr<DBEvent> > eventsForMimeData(const QByteArray &mimeData) const;
74
74
75 public slots:
75 public slots:
76 /// Manage init/end of the controller
76 /// Manage init/end of the controller
77 void initialize();
77 void initialize();
78
78
79 private:
79 private:
80 class CatalogueControllerPrivate;
80 class CatalogueControllerPrivate;
81 spimpl::unique_impl_ptr<CatalogueControllerPrivate> impl;
81 spimpl::unique_impl_ptr<CatalogueControllerPrivate> impl;
82 };
82 };
83
83
84 #endif // SCIQLOP_CATALOGUECONTROLLER_H
84 #endif // SCIQLOP_CATALOGUECONTROLLER_H
@@ -1,437 +1,466
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 <QDataStream>
15 #include <QDataStream>
16 #include <QMutex>
16 #include <QMutex>
17 #include <QThread>
17 #include <QThread>
18
18
19 #include <QDir>
19 #include <QDir>
20 #include <QStandardPaths>
20 #include <QStandardPaths>
21
21
22 Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController")
22 Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController")
23
23
24 namespace {
24 namespace {
25
25
26 static QString REPOSITORY_WORK_SUFFIX = QString{"_work"};
26 static QString REPOSITORY_WORK_SUFFIX = QString{"_work"};
27 static QString REPOSITORY_TRASH_SUFFIX = QString{"_trash"};
27 static QString REPOSITORY_TRASH_SUFFIX = QString{"_trash"};
28 }
28 }
29
29
30 class CatalogueController::CatalogueControllerPrivate {
30 class CatalogueController::CatalogueControllerPrivate {
31
31
32 public:
32 public:
33 explicit CatalogueControllerPrivate(CatalogueController *parent) : m_Q{parent} {}
33 explicit CatalogueControllerPrivate(CatalogueController *parent) : m_Q{parent} {}
34
34
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 QSet<QString> m_EventKeysWithChanges;
40 QSet<QString> m_EventKeysWithChanges;
41
41
42 QString eventUniqueKey(const std::shared_ptr<DBEvent> &event) const;
42 QString eventUniqueKey(const std::shared_ptr<DBEvent> &event) const;
43
43
44 void copyDBtoDB(const QString &dbFrom, const QString &dbTo);
44 void copyDBtoDB(const QString &dbFrom, const QString &dbTo);
45 QString toWorkRepository(QString repository);
45 QString toWorkRepository(QString repository);
46 QString toSyncRepository(QString repository);
46 QString toSyncRepository(QString repository);
47 void savAllDB();
47 void savAllDB();
48
48
49 void saveEvent(std::shared_ptr<DBEvent> event, bool persist = true);
49 void saveEvent(std::shared_ptr<DBEvent> event, bool persist = true);
50 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool persist = true);
50 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool persist = true);
51 };
51 };
52
52
53 CatalogueController::CatalogueController(QObject *parent)
53 CatalogueController::CatalogueController(QObject *parent)
54 : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>(this)}
54 : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>(this)}
55 {
55 {
56 qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction")
56 qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction")
57 << QThread::currentThread();
57 << QThread::currentThread();
58 }
58 }
59
59
60 CatalogueController::~CatalogueController()
60 CatalogueController::~CatalogueController()
61 {
61 {
62 qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction")
62 qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction")
63 << QThread::currentThread();
63 << QThread::currentThread();
64 }
64 }
65
65
66 QStringList CatalogueController::getRepositories() const
66 QStringList CatalogueController::getRepositories() const
67 {
67 {
68 return impl->m_RepositoryList;
68 return impl->m_RepositoryList;
69 }
69 }
70
70
71 void CatalogueController::addDB(const QString &dbPath)
71 void CatalogueController::addDB(const QString &dbPath)
72 {
72 {
73 QDir dbDir(dbPath);
73 QDir dbDir(dbPath);
74 if (dbDir.exists()) {
74 if (dbDir.exists()) {
75 auto dirName = dbDir.dirName();
75 auto dirName = dbDir.dirName();
76
76
77 if (std::find(impl->m_RepositoryList.cbegin(), impl->m_RepositoryList.cend(), dirName)
77 if (std::find(impl->m_RepositoryList.cbegin(), impl->m_RepositoryList.cend(), dirName)
78 != impl->m_RepositoryList.cend()) {
78 != impl->m_RepositoryList.cend()) {
79 qCCritical(LOG_CatalogueController())
79 qCCritical(LOG_CatalogueController())
80 << tr("Impossible to addDB that is already loaded");
80 << tr("Impossible to addDB that is already loaded");
81 }
81 }
82
82
83 if (!impl->m_CatalogueDao.addDB(dbPath, dirName)) {
83 if (!impl->m_CatalogueDao.addDB(dbPath, dirName)) {
84 qCCritical(LOG_CatalogueController())
84 qCCritical(LOG_CatalogueController())
85 << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath);
85 << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath);
86 }
86 }
87 else {
87 else {
88 impl->m_RepositoryList << dirName;
88 impl->m_RepositoryList << dirName;
89 impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName));
89 impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName));
90 }
90 }
91 }
91 }
92 else {
92 else {
93 qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ")
93 qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ")
94 << dbPath;
94 << dbPath;
95 }
95 }
96 }
96 }
97
97
98 void CatalogueController::saveDB(const QString &destinationPath, const QString &repository)
98 void CatalogueController::saveDB(const QString &destinationPath, const QString &repository)
99 {
99 {
100 if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) {
100 if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) {
101 qCCritical(LOG_CatalogueController())
101 qCCritical(LOG_CatalogueController())
102 << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath);
102 << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath);
103 }
103 }
104 }
104 }
105
105
106 std::list<std::shared_ptr<DBEvent> >
106 std::list<std::shared_ptr<DBEvent> >
107 CatalogueController::retrieveEvents(const QString &repository) const
107 CatalogueController::retrieveEvents(const QString &repository) const
108 {
108 {
109 QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository;
109 QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository;
110
110
111 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
111 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
112 auto events = impl->m_CatalogueDao.getEvents(impl->toWorkRepository(dbDireName));
112 auto events = impl->m_CatalogueDao.getEvents(impl->toWorkRepository(dbDireName));
113 for (auto event : events) {
113 for (auto event : events) {
114 eventsShared.push_back(std::make_shared<DBEvent>(event));
114 eventsShared.push_back(std::make_shared<DBEvent>(event));
115 }
115 }
116 return eventsShared;
116 return eventsShared;
117 }
117 }
118
118
119 std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() const
119 std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() const
120 {
120 {
121 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
121 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
122 for (auto repository : impl->m_RepositoryList) {
122 for (auto repository : impl->m_RepositoryList) {
123 eventsShared.splice(eventsShared.end(), retrieveEvents(repository));
123 eventsShared.splice(eventsShared.end(), retrieveEvents(repository));
124 }
124 }
125
125
126 return eventsShared;
126 return eventsShared;
127 }
127 }
128
128
129 std::list<std::shared_ptr<DBEvent> >
129 std::list<std::shared_ptr<DBEvent> >
130 CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const
130 CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const
131 {
131 {
132 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
132 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
133 auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue);
133 auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue);
134 for (auto event : events) {
134 for (auto event : events) {
135 eventsShared.push_back(std::make_shared<DBEvent>(event));
135 eventsShared.push_back(std::make_shared<DBEvent>(event));
136 }
136 }
137 return eventsShared;
137 return eventsShared;
138 }
138 }
139
139
140 void CatalogueController::updateEvent(std::shared_ptr<DBEvent> event)
140 void CatalogueController::updateEvent(std::shared_ptr<DBEvent> event)
141 {
141 {
142 event->setRepository(impl->toWorkRepository(event->getRepository()));
142 event->setRepository(impl->toWorkRepository(event->getRepository()));
143
143
144 auto uniqueId = impl->eventUniqueKey(event);
144 auto uniqueId = impl->eventUniqueKey(event);
145 impl->m_EventKeysWithChanges.insert(uniqueId);
145 impl->m_EventKeysWithChanges.insert(uniqueId);
146
146
147 impl->m_CatalogueDao.updateEvent(*event);
147 impl->m_CatalogueDao.updateEvent(*event);
148 }
148 }
149
149
150 void CatalogueController::updateEventProduct(std::shared_ptr<DBEventProduct> eventProduct)
150 void CatalogueController::updateEventProduct(std::shared_ptr<DBEventProduct> eventProduct)
151 {
151 {
152 impl->m_CatalogueDao.updateEventProduct(*eventProduct);
152 impl->m_CatalogueDao.updateEventProduct(*eventProduct);
153 }
153 }
154
154
155 void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event)
155 void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event)
156 {
156 {
157 // Remove it from both repository and repository_work
157 // Remove it from both repository and repository_work
158 event->setRepository(impl->toWorkRepository(event->getRepository()));
158 event->setRepository(impl->toWorkRepository(event->getRepository()));
159 impl->m_CatalogueDao.removeEvent(*event);
159 impl->m_CatalogueDao.removeEvent(*event);
160 event->setRepository(impl->toSyncRepository(event->getRepository()));
160 event->setRepository(impl->toSyncRepository(event->getRepository()));
161 impl->m_CatalogueDao.removeEvent(*event);
161 impl->m_CatalogueDao.removeEvent(*event);
162 impl->savAllDB();
162 impl->savAllDB();
163 }
163 }
164
164
165 void CatalogueController::addEvent(std::shared_ptr<DBEvent> event)
165 void CatalogueController::addEvent(std::shared_ptr<DBEvent> event)
166 {
166 {
167 event->setRepository(impl->toWorkRepository(event->getRepository()));
167 event->setRepository(impl->toWorkRepository(event->getRepository()));
168
168
169 auto eventTemp = *event;
169 auto eventTemp = *event;
170 impl->m_CatalogueDao.addEvent(eventTemp);
170 impl->m_CatalogueDao.addEvent(eventTemp);
171
171
172 // Call update is necessary at the creation of add Event if it has some tags or some event
172 // Call update is necessary at the creation of add Event if it has some tags or some event
173 // products
173 // products
174 if (!event->getEventProducts().empty() || !event->getTags().empty()) {
174 if (!event->getEventProducts().empty() || !event->getTags().empty()) {
175
175
176 auto eventProductsTemp = eventTemp.getEventProducts();
176 auto eventProductsTemp = eventTemp.getEventProducts();
177 auto eventProductTempUpdated = std::list<DBEventProduct>{};
177 auto eventProductTempUpdated = std::list<DBEventProduct>{};
178 for (auto eventProductTemp : eventProductsTemp) {
178 for (auto eventProductTemp : eventProductsTemp) {
179 eventProductTemp.setEvent(eventTemp);
179 eventProductTemp.setEvent(eventTemp);
180 eventProductTempUpdated.push_back(eventProductTemp);
180 eventProductTempUpdated.push_back(eventProductTemp);
181 }
181 }
182 eventTemp.setEventProducts(eventProductTempUpdated);
182 eventTemp.setEventProducts(eventProductTempUpdated);
183
183
184 impl->m_CatalogueDao.updateEvent(eventTemp);
184 impl->m_CatalogueDao.updateEvent(eventTemp);
185 }
185 }
186
186
187 <<<<<<< Upstream, based on feature/CatalogueDevelop2
187 auto uniqueId = impl->eventUniqueKey(event);
188 auto uniqueId = impl->eventUniqueKey(event);
188 impl->m_EventKeysWithChanges.insert(uniqueId);
189 impl->m_EventKeysWithChanges.insert(uniqueId);
190 =======
191
192 // update event parameter
193 auto uniqIdPredicate = std::make_shared<ComparaisonPredicate>(
194 QString{"uniqId"}, event->getUniqId(), ComparaisonOperation::EQUALEQUAL);
195
196 auto workRepositoryPredicate = std::make_shared<ComparaisonPredicate>(
197 QString{"repository"}, impl->toWorkRepository(event->getRepository()),
198 ComparaisonOperation::EQUALEQUAL);
199
200 auto workPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND);
201 workPred->AddRequestPredicate(uniqIdPredicate);
202 workPred->AddRequestPredicate(workRepositoryPredicate);
203
204
205 auto workEvent = impl->m_CatalogueDao.getEvent(workPred);
206 *event = workEvent;
207 >>>>>>> 575bb1a Discard an added event remove it now.
189 }
208 }
190
209
191 void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event)
210 void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event)
192 {
211 {
193 impl->saveEvent(event, true);
212 impl->saveEvent(event, true);
194 impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event));
213 impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event));
195 }
214 }
196
215
197 void CatalogueController::discardEvent(std::shared_ptr<DBEvent> event)
216 void CatalogueController::discardEvent(std::shared_ptr<DBEvent> event, bool &removed)
198 {
217 {
199 auto uniqIdPredicate = std::make_shared<ComparaisonPredicate>(
218 auto uniqIdPredicate = std::make_shared<ComparaisonPredicate>(
200 QString{"uniqId"}, event->getUniqId(), ComparaisonOperation::EQUALEQUAL);
219 QString{"uniqId"}, event->getUniqId(), ComparaisonOperation::EQUALEQUAL);
201
220
202 auto syncRepositoryPredicate = std::make_shared<ComparaisonPredicate>(
221 auto syncRepositoryPredicate = std::make_shared<ComparaisonPredicate>(
203 QString{"repository"}, impl->toSyncRepository(event->getRepository()),
222 QString{"repository"}, impl->toSyncRepository(event->getRepository()),
204 ComparaisonOperation::EQUALEQUAL);
223 ComparaisonOperation::EQUALEQUAL);
205
224
206 auto syncPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND);
225 auto syncPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND);
207 syncPred->AddRequestPredicate(uniqIdPredicate);
226 syncPred->AddRequestPredicate(uniqIdPredicate);
208 syncPred->AddRequestPredicate(syncRepositoryPredicate);
227 syncPred->AddRequestPredicate(syncRepositoryPredicate);
209
228
210
229
211 auto workRepositoryPredicate = std::make_shared<ComparaisonPredicate>(
230 auto workRepositoryPredicate = std::make_shared<ComparaisonPredicate>(
212 QString{"repository"}, impl->toWorkRepository(event->getRepository()),
231 QString{"repository"}, impl->toWorkRepository(event->getRepository()),
213 ComparaisonOperation::EQUALEQUAL);
232 ComparaisonOperation::EQUALEQUAL);
214
233
215 auto workPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND);
234 auto workPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND);
216 workPred->AddRequestPredicate(uniqIdPredicate);
235 workPred->AddRequestPredicate(uniqIdPredicate);
217 workPred->AddRequestPredicate(workRepositoryPredicate);
236 workPred->AddRequestPredicate(workRepositoryPredicate);
218
237
219
238
220 auto syncEvent = impl->m_CatalogueDao.getEvent(syncPred);
239 auto syncEvent = impl->m_CatalogueDao.getEvent(syncPred);
221 impl->m_CatalogueDao.copyEvent(syncEvent, impl->toWorkRepository(event->getRepository()), true);
240 if (!syncEvent.getUniqId().isNull()) {
222
241 removed = false;
223 auto workEvent = impl->m_CatalogueDao.getEvent(workPred);
242 impl->m_CatalogueDao.copyEvent(syncEvent, impl->toWorkRepository(event->getRepository()),
224 *event = workEvent;
243 true);
225 impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event));
244
245 auto workEvent = impl->m_CatalogueDao.getEvent(workPred);
246 *event = workEvent;
247 impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event));
248 }
249 else {
250 removed = true;
251 // Since the element wasn't in sync repository. Discard it means remove it
252 event->setRepository(impl->toWorkRepository(event->getRepository()));
253 impl->m_CatalogueDao.removeEvent(*event);
254 }
226 }
255 }
227
256
228 bool CatalogueController::eventHasChanges(std::shared_ptr<DBEvent> event) const
257 bool CatalogueController::eventHasChanges(std::shared_ptr<DBEvent> event) const
229 {
258 {
230 return impl->m_EventKeysWithChanges.contains(impl->eventUniqueKey(event));
259 return impl->m_EventKeysWithChanges.contains(impl->eventUniqueKey(event));
231 }
260 }
232
261
233 std::list<std::shared_ptr<DBCatalogue> >
262 std::list<std::shared_ptr<DBCatalogue> >
234 CatalogueController::retrieveCatalogues(const QString &repository) const
263 CatalogueController::retrieveCatalogues(const QString &repository) const
235 {
264 {
236 QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository;
265 QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository;
237
266
238 auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
267 auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
239 auto catalogues = impl->m_CatalogueDao.getCatalogues(impl->toWorkRepository(dbDireName));
268 auto catalogues = impl->m_CatalogueDao.getCatalogues(impl->toWorkRepository(dbDireName));
240 for (auto catalogue : catalogues) {
269 for (auto catalogue : catalogues) {
241 cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue));
270 cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue));
242 }
271 }
243 return cataloguesShared;
272 return cataloguesShared;
244 }
273 }
245
274
246 void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue)
275 void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue)
247 {
276 {
248 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
277 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
249
278
250 impl->m_CatalogueDao.updateCatalogue(*catalogue);
279 impl->m_CatalogueDao.updateCatalogue(*catalogue);
251 }
280 }
252
281
253 void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue)
282 void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue)
254 {
283 {
255 // Remove it from both repository and repository_work
284 // Remove it from both repository and repository_work
256 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
285 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
257 impl->m_CatalogueDao.removeCatalogue(*catalogue);
286 impl->m_CatalogueDao.removeCatalogue(*catalogue);
258 catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository()));
287 catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository()));
259 impl->m_CatalogueDao.removeCatalogue(*catalogue);
288 impl->m_CatalogueDao.removeCatalogue(*catalogue);
260 }
289 }
261
290
262 void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue)
291 void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue)
263 {
292 {
264 impl->saveCatalogue(catalogue, true);
293 impl->saveCatalogue(catalogue, true);
265 }
294 }
266
295
267 void CatalogueController::saveAll()
296 void CatalogueController::saveAll()
268 {
297 {
269 for (auto repository : impl->m_RepositoryList) {
298 for (auto repository : impl->m_RepositoryList) {
270 // Save Event
299 // Save Event
271 auto events = this->retrieveEvents(repository);
300 auto events = this->retrieveEvents(repository);
272 for (auto event : events) {
301 for (auto event : events) {
273 impl->saveEvent(event, false);
302 impl->saveEvent(event, false);
274 }
303 }
275
304
276 // Save Catalogue
305 // Save Catalogue
277 auto catalogues = this->retrieveCatalogues(repository);
306 auto catalogues = this->retrieveCatalogues(repository);
278 for (auto catalogue : catalogues) {
307 for (auto catalogue : catalogues) {
279 impl->saveCatalogue(catalogue, false);
308 impl->saveCatalogue(catalogue, false);
280 }
309 }
281 }
310 }
282
311
283 impl->savAllDB();
312 impl->savAllDB();
284 impl->m_EventKeysWithChanges.clear();
313 impl->m_EventKeysWithChanges.clear();
285 }
314 }
286
315
287 bool CatalogueController::hasChanges() const
316 bool CatalogueController::hasChanges() const
288 {
317 {
289 return !impl->m_EventKeysWithChanges.isEmpty(); // TODO: catalogues
318 return !impl->m_EventKeysWithChanges.isEmpty(); // TODO: catalogues
290 }
319 }
291
320
292 QByteArray
321 QByteArray
293 CatalogueController::mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const
322 CatalogueController::mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const
294 {
323 {
295 auto encodedData = QByteArray{};
324 auto encodedData = QByteArray{};
296
325
297 QMap<QString, QVariantList> idsPerRepository;
326 QMap<QString, QVariantList> idsPerRepository;
298 for (auto event : events) {
327 for (auto event : events) {
299 idsPerRepository[event->getRepository()] << event->getUniqId();
328 idsPerRepository[event->getRepository()] << event->getUniqId();
300 }
329 }
301
330
302 QDataStream stream{&encodedData, QIODevice::WriteOnly};
331 QDataStream stream{&encodedData, QIODevice::WriteOnly};
303 stream << idsPerRepository;
332 stream << idsPerRepository;
304
333
305 return encodedData;
334 return encodedData;
306 }
335 }
307
336
308 QVector<std::shared_ptr<DBEvent> >
337 QVector<std::shared_ptr<DBEvent> >
309 CatalogueController::eventsForMimeData(const QByteArray &mimeData) const
338 CatalogueController::eventsForMimeData(const QByteArray &mimeData) const
310 {
339 {
311 auto events = QVector<std::shared_ptr<DBEvent> >{};
340 auto events = QVector<std::shared_ptr<DBEvent> >{};
312 QDataStream stream{mimeData};
341 QDataStream stream{mimeData};
313
342
314 QMap<QString, QVariantList> idsPerRepository;
343 QMap<QString, QVariantList> idsPerRepository;
315 stream >> idsPerRepository;
344 stream >> idsPerRepository;
316
345
317 for (auto it = idsPerRepository.cbegin(); it != idsPerRepository.cend(); ++it) {
346 for (auto it = idsPerRepository.cbegin(); it != idsPerRepository.cend(); ++it) {
318 auto repository = it.key();
347 auto repository = it.key();
319 auto allRepositoryEvent = retrieveEvents(repository);
348 auto allRepositoryEvent = retrieveEvents(repository);
320 for (auto uuid : it.value()) {
349 for (auto uuid : it.value()) {
321 for (auto repositoryEvent : allRepositoryEvent) {
350 for (auto repositoryEvent : allRepositoryEvent) {
322 if (uuid.toUuid() == repositoryEvent->getUniqId()) {
351 if (uuid.toUuid() == repositoryEvent->getUniqId()) {
323 events << repositoryEvent;
352 events << repositoryEvent;
324 }
353 }
325 }
354 }
326 }
355 }
327 }
356 }
328
357
329 return events;
358 return events;
330 }
359 }
331
360
332 void CatalogueController::initialize()
361 void CatalogueController::initialize()
333 {
362 {
334 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
363 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
335 << QThread::currentThread();
364 << QThread::currentThread();
336
365
337 impl->m_CatalogueDao.initialize();
366 impl->m_CatalogueDao.initialize();
338 auto defaultRepositoryLocation
367 auto defaultRepositoryLocation
339 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
368 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
340
369
341 QDir defaultRepositoryLocationDir;
370 QDir defaultRepositoryLocationDir;
342 if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) {
371 if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) {
343 defaultRepositoryLocationDir.cd(defaultRepositoryLocation);
372 defaultRepositoryLocationDir.cd(defaultRepositoryLocation);
344 auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT);
373 auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT);
345
374
346 qCInfo(LOG_CatalogueController()) << tr("Persistant data loading from: ")
375 qCInfo(LOG_CatalogueController()) << tr("Persistant data loading from: ")
347 << defaultRepository;
376 << defaultRepository;
348
377
349 QDir dbDir(defaultRepository);
378 QDir dbDir(defaultRepository);
350 impl->m_RepositoryList << REPOSITORY_DEFAULT;
379 impl->m_RepositoryList << REPOSITORY_DEFAULT;
351 if (dbDir.exists()) {
380 if (dbDir.exists()) {
352 auto dirName = dbDir.dirName();
381 auto dirName = dbDir.dirName();
353
382
354 if (impl->m_CatalogueDao.addDB(defaultRepository, dirName)) {
383 if (impl->m_CatalogueDao.addDB(defaultRepository, dirName)) {
355 impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName));
384 impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName));
356 }
385 }
357 }
386 }
358 else {
387 else {
359 qCInfo(LOG_CatalogueController()) << tr("Initialisation of Default repository detected")
388 qCInfo(LOG_CatalogueController()) << tr("Initialisation of Default repository detected")
360 << defaultRepository;
389 << defaultRepository;
361 }
390 }
362 }
391 }
363 else {
392 else {
364 qCWarning(LOG_CatalogueController())
393 qCWarning(LOG_CatalogueController())
365 << tr("Cannot load the persistent default repository from ")
394 << tr("Cannot load the persistent default repository from ")
366 << defaultRepositoryLocation;
395 << defaultRepositoryLocation;
367 }
396 }
368
397
369 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END");
398 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END");
370 }
399 }
371
400
372 QString CatalogueController::CatalogueControllerPrivate::eventUniqueKey(
401 QString CatalogueController::CatalogueControllerPrivate::eventUniqueKey(
373 const std::shared_ptr<DBEvent> &event) const
402 const std::shared_ptr<DBEvent> &event) const
374 {
403 {
375 return event->getUniqId().toString().append(event->getRepository());
404 return event->getUniqId().toString().append(event->getRepository());
376 }
405 }
377
406
378 void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom,
407 void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom,
379 const QString &dbTo)
408 const QString &dbTo)
380 {
409 {
381 // auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
410 // auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
382 auto catalogues = m_CatalogueDao.getCatalogues(dbFrom);
411 auto catalogues = m_CatalogueDao.getCatalogues(dbFrom);
383 auto events = m_CatalogueDao.getEvents(dbFrom);
412 auto events = m_CatalogueDao.getEvents(dbFrom);
384 for (auto catalogue : catalogues) {
413 for (auto catalogue : catalogues) {
385 m_CatalogueDao.copyCatalogue(catalogue, dbTo, true);
414 m_CatalogueDao.copyCatalogue(catalogue, dbTo, true);
386 }
415 }
387
416
388 for (auto event : events) {
417 for (auto event : events) {
389 m_CatalogueDao.copyEvent(event, dbTo, true);
418 m_CatalogueDao.copyEvent(event, dbTo, true);
390 }
419 }
391 }
420 }
392
421
393 QString CatalogueController::CatalogueControllerPrivate::toWorkRepository(QString repository)
422 QString CatalogueController::CatalogueControllerPrivate::toWorkRepository(QString repository)
394 {
423 {
395 auto syncRepository = toSyncRepository(repository);
424 auto syncRepository = toSyncRepository(repository);
396
425
397 return QString("%1%2").arg(syncRepository, REPOSITORY_WORK_SUFFIX);
426 return QString("%1%2").arg(syncRepository, REPOSITORY_WORK_SUFFIX);
398 }
427 }
399
428
400 QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QString repository)
429 QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QString repository)
401 {
430 {
402 auto syncRepository = repository;
431 auto syncRepository = repository;
403 if (repository.endsWith(REPOSITORY_WORK_SUFFIX)) {
432 if (repository.endsWith(REPOSITORY_WORK_SUFFIX)) {
404 syncRepository.remove(REPOSITORY_WORK_SUFFIX);
433 syncRepository.remove(REPOSITORY_WORK_SUFFIX);
405 }
434 }
406 else if (repository.endsWith(REPOSITORY_TRASH_SUFFIX)) {
435 else if (repository.endsWith(REPOSITORY_TRASH_SUFFIX)) {
407 syncRepository.remove(REPOSITORY_TRASH_SUFFIX);
436 syncRepository.remove(REPOSITORY_TRASH_SUFFIX);
408 }
437 }
409 return syncRepository;
438 return syncRepository;
410 }
439 }
411
440
412 void CatalogueController::CatalogueControllerPrivate::savAllDB()
441 void CatalogueController::CatalogueControllerPrivate::savAllDB()
413 {
442 {
414 for (auto repository : m_RepositoryList) {
443 for (auto repository : m_RepositoryList) {
415 auto defaultRepositoryLocation
444 auto defaultRepositoryLocation
416 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
445 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
417 m_CatalogueDao.saveDB(defaultRepositoryLocation, repository);
446 m_CatalogueDao.saveDB(defaultRepositoryLocation, repository);
418 }
447 }
419 }
448 }
420
449
421 void CatalogueController::CatalogueControllerPrivate::saveEvent(std::shared_ptr<DBEvent> event,
450 void CatalogueController::CatalogueControllerPrivate::saveEvent(std::shared_ptr<DBEvent> event,
422 bool persist)
451 bool persist)
423 {
452 {
424 m_CatalogueDao.copyEvent(*event, toSyncRepository(event->getRepository()), true);
453 m_CatalogueDao.copyEvent(*event, toSyncRepository(event->getRepository()), true);
425 if (persist) {
454 if (persist) {
426 savAllDB();
455 savAllDB();
427 }
456 }
428 }
457 }
429
458
430 void CatalogueController::CatalogueControllerPrivate::saveCatalogue(
459 void CatalogueController::CatalogueControllerPrivate::saveCatalogue(
431 std::shared_ptr<DBCatalogue> catalogue, bool persist)
460 std::shared_ptr<DBCatalogue> catalogue, bool persist)
432 {
461 {
433 m_CatalogueDao.copyCatalogue(*catalogue, toSyncRepository(catalogue->getRepository()), true);
462 m_CatalogueDao.copyCatalogue(*catalogue, toSyncRepository(catalogue->getRepository()), true);
434 if (persist) {
463 if (persist) {
435 savAllDB();
464 savAllDB();
436 }
465 }
437 }
466 }
@@ -1,464 +1,470
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 #include <QMessageBox>
17 #include <QMessageBox>
18
18
19 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
19 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
20
20
21 /// Fixed size of the validation column
21 /// Fixed size of the validation column
22 const auto VALIDATION_COLUMN_SIZE = 35;
22 const auto VALIDATION_COLUMN_SIZE = 35;
23
23
24 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
24 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
25
25
26 CatalogueEventsModel *m_Model = nullptr;
26 CatalogueEventsModel *m_Model = nullptr;
27 QStringList m_ZonesForTimeMode;
27 QStringList m_ZonesForTimeMode;
28 QString m_ZoneForGraphMode;
28 QString m_ZoneForGraphMode;
29 QVector<std::shared_ptr<DBCatalogue> > m_DisplayedCatalogues;
29 QVector<std::shared_ptr<DBCatalogue> > m_DisplayedCatalogues;
30 bool m_AllEventDisplayed = false;
30 bool m_AllEventDisplayed = false;
31
31
32 VisualizationWidget *m_VisualizationWidget = nullptr;
32 VisualizationWidget *m_VisualizationWidget = nullptr;
33
33
34 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, CatalogueEventsWidget *widget)
34 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, CatalogueEventsWidget *widget)
35 {
35 {
36 widget->ui->treeView->setSortingEnabled(false);
36 widget->ui->treeView->setSortingEnabled(false);
37 m_Model->setEvents(events);
37 m_Model->setEvents(events);
38 widget->ui->treeView->setSortingEnabled(true);
38 widget->ui->treeView->setSortingEnabled(true);
39
39
40 for (auto event : events) {
40 for (auto event : events) {
41 if (sqpApp->catalogueController().eventHasChanges(event)) {
41 if (sqpApp->catalogueController().eventHasChanges(event)) {
42 auto index = m_Model->indexOf(event);
42 auto index = m_Model->indexOf(event);
43 widget->setEventChanges(event, true);
43 widget->setEventChanges(event, true);
44 }
44 }
45 }
45 }
46 }
46 }
47
47
48 void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
48 void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
49 {
49 {
50 treeView->setSortingEnabled(false);
50 treeView->setSortingEnabled(false);
51 m_Model->addEvent(event);
51 m_Model->addEvent(event);
52 treeView->setSortingEnabled(true);
52 treeView->setSortingEnabled(true);
53 }
53 }
54
54
55 void removeEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
55 void removeEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
56 {
56 {
57 treeView->setSortingEnabled(false);
57 treeView->setSortingEnabled(false);
58 m_Model->removeEvent(event);
58 m_Model->removeEvent(event);
59 treeView->setSortingEnabled(true);
59 treeView->setSortingEnabled(true);
60 }
60 }
61
61
62 QStringList getAvailableVisualizationZoneList() const
62 QStringList getAvailableVisualizationZoneList() const
63 {
63 {
64 if (m_VisualizationWidget) {
64 if (m_VisualizationWidget) {
65 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
65 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
66 return tab->availableZoneWidgets();
66 return tab->availableZoneWidgets();
67 }
67 }
68 }
68 }
69
69
70 return QStringList{};
70 return QStringList{};
71 }
71 }
72
72
73 QStringList selectZone(QWidget *parent, const QStringList &selectedZones,
73 QStringList selectZone(QWidget *parent, const QStringList &selectedZones,
74 bool allowMultiSelection, const QPoint &location)
74 bool allowMultiSelection, const QPoint &location)
75 {
75 {
76 auto availableZones = getAvailableVisualizationZoneList();
76 auto availableZones = getAvailableVisualizationZoneList();
77 if (availableZones.isEmpty()) {
77 if (availableZones.isEmpty()) {
78 return QStringList{};
78 return QStringList{};
79 }
79 }
80
80
81 QDialog d(parent, Qt::Tool);
81 QDialog d(parent, Qt::Tool);
82 d.setWindowTitle("Choose a zone");
82 d.setWindowTitle("Choose a zone");
83 auto layout = new QVBoxLayout{&d};
83 auto layout = new QVBoxLayout{&d};
84 layout->setContentsMargins(0, 0, 0, 0);
84 layout->setContentsMargins(0, 0, 0, 0);
85 auto listWidget = new QListWidget{&d};
85 auto listWidget = new QListWidget{&d};
86 layout->addWidget(listWidget);
86 layout->addWidget(listWidget);
87
87
88 QSet<QListWidgetItem *> checkedItems;
88 QSet<QListWidgetItem *> checkedItems;
89 for (auto zone : availableZones) {
89 for (auto zone : availableZones) {
90 auto item = new QListWidgetItem{zone};
90 auto item = new QListWidgetItem{zone};
91 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
91 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
92 if (selectedZones.contains(zone)) {
92 if (selectedZones.contains(zone)) {
93 item->setCheckState(Qt::Checked);
93 item->setCheckState(Qt::Checked);
94 checkedItems << item;
94 checkedItems << item;
95 }
95 }
96 else {
96 else {
97 item->setCheckState(Qt::Unchecked);
97 item->setCheckState(Qt::Unchecked);
98 }
98 }
99
99
100 listWidget->addItem(item);
100 listWidget->addItem(item);
101 }
101 }
102
102
103 auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d};
103 auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d};
104 layout->addWidget(buttonBox);
104 layout->addWidget(buttonBox);
105
105
106 QObject::connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept);
106 QObject::connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept);
107 QObject::connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject);
107 QObject::connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject);
108
108
109 QObject::connect(listWidget, &QListWidget::itemChanged,
109 QObject::connect(listWidget, &QListWidget::itemChanged,
110 [&checkedItems, allowMultiSelection, listWidget](auto item) {
110 [&checkedItems, allowMultiSelection, listWidget](auto item) {
111 if (item->checkState() == Qt::Checked) {
111 if (item->checkState() == Qt::Checked) {
112 if (!allowMultiSelection) {
112 if (!allowMultiSelection) {
113 for (auto checkedItem : checkedItems) {
113 for (auto checkedItem : checkedItems) {
114 listWidget->blockSignals(true);
114 listWidget->blockSignals(true);
115 checkedItem->setCheckState(Qt::Unchecked);
115 checkedItem->setCheckState(Qt::Unchecked);
116 listWidget->blockSignals(false);
116 listWidget->blockSignals(false);
117 }
117 }
118
118
119 checkedItems.clear();
119 checkedItems.clear();
120 }
120 }
121 checkedItems << item;
121 checkedItems << item;
122 }
122 }
123 else {
123 else {
124 checkedItems.remove(item);
124 checkedItems.remove(item);
125 }
125 }
126 });
126 });
127
127
128 QStringList result;
128 QStringList result;
129
129
130 d.setMinimumWidth(120);
130 d.setMinimumWidth(120);
131 d.resize(d.minimumSizeHint());
131 d.resize(d.minimumSizeHint());
132 d.move(location);
132 d.move(location);
133 if (d.exec() == QDialog::Accepted) {
133 if (d.exec() == QDialog::Accepted) {
134 for (auto item : checkedItems) {
134 for (auto item : checkedItems) {
135 result += item->text();
135 result += item->text();
136 }
136 }
137 }
137 }
138 else {
138 else {
139 result = selectedZones;
139 result = selectedZones;
140 }
140 }
141
141
142 return result;
142 return result;
143 }
143 }
144
144
145 void updateForTimeMode(QTreeView *treeView)
145 void updateForTimeMode(QTreeView *treeView)
146 {
146 {
147 auto selectedRows = treeView->selectionModel()->selectedRows();
147 auto selectedRows = treeView->selectionModel()->selectedRows();
148
148
149 if (selectedRows.count() == 1) {
149 if (selectedRows.count() == 1) {
150 auto event = m_Model->getEvent(selectedRows.first());
150 auto event = m_Model->getEvent(selectedRows.first());
151 if (event) {
151 if (event) {
152 if (m_VisualizationWidget) {
152 if (m_VisualizationWidget) {
153 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
153 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
154
154
155 for (auto zoneName : m_ZonesForTimeMode) {
155 for (auto zoneName : m_ZonesForTimeMode) {
156 if (auto zone = tab->getZoneWithName(zoneName)) {
156 if (auto zone = tab->getZoneWithName(zoneName)) {
157 SqpRange eventRange;
157 SqpRange eventRange;
158 eventRange.m_TStart = event->getTStart();
158 eventRange.m_TStart = event->getTStart();
159 eventRange.m_TEnd = event->getTEnd();
159 eventRange.m_TEnd = event->getTEnd();
160 zone->setZoneRange(eventRange);
160 zone->setZoneRange(eventRange);
161 }
161 }
162 }
162 }
163 }
163 }
164 else {
164 else {
165 qCWarning(LOG_CatalogueEventsWidget())
165 qCWarning(LOG_CatalogueEventsWidget())
166 << "updateTimeZone: no tab found in the visualization";
166 << "updateTimeZone: no tab found in the visualization";
167 }
167 }
168 }
168 }
169 else {
169 else {
170 qCWarning(LOG_CatalogueEventsWidget())
170 qCWarning(LOG_CatalogueEventsWidget())
171 << "updateTimeZone: visualization widget not found";
171 << "updateTimeZone: visualization widget not found";
172 }
172 }
173 }
173 }
174 }
174 }
175 else {
175 else {
176 qCWarning(LOG_CatalogueEventsWidget())
176 qCWarning(LOG_CatalogueEventsWidget())
177 << "updateTimeZone: not compatible with multiple events selected";
177 << "updateTimeZone: not compatible with multiple events selected";
178 }
178 }
179 }
179 }
180
180
181 void updateForGraphMode(QTreeView *treeView)
181 void updateForGraphMode(QTreeView *treeView)
182 {
182 {
183 auto selectedRows = treeView->selectionModel()->selectedRows();
183 auto selectedRows = treeView->selectionModel()->selectedRows();
184
184
185 if (selectedRows.count() == 1) {
185 if (selectedRows.count() == 1) {
186 auto event = m_Model->getEvent(selectedRows.first());
186 auto event = m_Model->getEvent(selectedRows.first());
187 if (m_VisualizationWidget) {
187 if (m_VisualizationWidget) {
188 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
188 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
189 if (auto zone = tab->getZoneWithName(m_ZoneForGraphMode)) {
189 if (auto zone = tab->getZoneWithName(m_ZoneForGraphMode)) {
190 // TODO
190 // TODO
191 }
191 }
192 }
192 }
193 else {
193 else {
194 qCWarning(LOG_CatalogueEventsWidget())
194 qCWarning(LOG_CatalogueEventsWidget())
195 << "updateGraphMode: no tab found in the visualization";
195 << "updateGraphMode: no tab found in the visualization";
196 }
196 }
197 }
197 }
198 else {
198 else {
199 qCWarning(LOG_CatalogueEventsWidget())
199 qCWarning(LOG_CatalogueEventsWidget())
200 << "updateGraphMode: visualization widget not found";
200 << "updateGraphMode: visualization widget not found";
201 }
201 }
202 }
202 }
203 else {
203 else {
204 qCWarning(LOG_CatalogueEventsWidget())
204 qCWarning(LOG_CatalogueEventsWidget())
205 << "updateGraphMode: not compatible with multiple events selected";
205 << "updateGraphMode: not compatible with multiple events selected";
206 }
206 }
207 }
207 }
208
208
209 void getSelectedItems(
209 void getSelectedItems(
210 QTreeView *treeView, QVector<std::shared_ptr<DBEvent> > &events,
210 QTreeView *treeView, QVector<std::shared_ptr<DBEvent> > &events,
211 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > &eventProducts)
211 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > &eventProducts)
212 {
212 {
213 for (auto rowIndex : treeView->selectionModel()->selectedRows()) {
213 for (auto rowIndex : treeView->selectionModel()->selectedRows()) {
214 auto itemType = m_Model->itemTypeOf(rowIndex);
214 auto itemType = m_Model->itemTypeOf(rowIndex);
215 if (itemType == CatalogueEventsModel::ItemType::Event) {
215 if (itemType == CatalogueEventsModel::ItemType::Event) {
216 events << m_Model->getEvent(rowIndex);
216 events << m_Model->getEvent(rowIndex);
217 }
217 }
218 else if (itemType == CatalogueEventsModel::ItemType::EventProduct) {
218 else if (itemType == CatalogueEventsModel::ItemType::EventProduct) {
219 eventProducts << qMakePair(m_Model->getParentEvent(rowIndex),
219 eventProducts << qMakePair(m_Model->getParentEvent(rowIndex),
220 m_Model->getEventProduct(rowIndex));
220 m_Model->getEventProduct(rowIndex));
221 }
221 }
222 }
222 }
223 }
223 }
224 };
224 };
225
225
226 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
226 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
227 : QWidget(parent),
227 : QWidget(parent),
228 ui(new Ui::CatalogueEventsWidget),
228 ui(new Ui::CatalogueEventsWidget),
229 impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()}
229 impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()}
230 {
230 {
231 ui->setupUi(this);
231 ui->setupUi(this);
232
232
233 impl->m_Model = new CatalogueEventsModel{this};
233 impl->m_Model = new CatalogueEventsModel{this};
234 ui->treeView->setModel(impl->m_Model);
234 ui->treeView->setModel(impl->m_Model);
235
235
236 ui->treeView->setSortingEnabled(true);
236 ui->treeView->setSortingEnabled(true);
237 ui->treeView->setDragDropMode(QAbstractItemView::DragDrop);
237 ui->treeView->setDragDropMode(QAbstractItemView::DragDrop);
238 ui->treeView->setDragEnabled(true);
238 ui->treeView->setDragEnabled(true);
239
239
240 connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) {
240 connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) {
241 if (checked) {
241 if (checked) {
242 ui->btnChart->setChecked(false);
242 ui->btnChart->setChecked(false);
243 impl->m_ZonesForTimeMode
243 impl->m_ZonesForTimeMode
244 = impl->selectZone(this, impl->m_ZonesForTimeMode, true,
244 = impl->selectZone(this, impl->m_ZonesForTimeMode, true,
245 this->mapToGlobal(ui->btnTime->frameGeometry().center()));
245 this->mapToGlobal(ui->btnTime->frameGeometry().center()));
246
246
247 impl->updateForTimeMode(ui->treeView);
247 impl->updateForTimeMode(ui->treeView);
248 }
248 }
249 });
249 });
250
250
251 connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) {
251 connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) {
252 if (checked) {
252 if (checked) {
253 ui->btnTime->setChecked(false);
253 ui->btnTime->setChecked(false);
254 impl->m_ZoneForGraphMode
254 impl->m_ZoneForGraphMode
255 = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false,
255 = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false,
256 this->mapToGlobal(ui->btnChart->frameGeometry().center()))
256 this->mapToGlobal(ui->btnChart->frameGeometry().center()))
257 .value(0);
257 .value(0);
258
258
259 impl->updateForGraphMode(ui->treeView);
259 impl->updateForGraphMode(ui->treeView);
260 }
260 }
261 });
261 });
262
262
263 connect(ui->btnRemove, &QToolButton::clicked, [this]() {
263 connect(ui->btnRemove, &QToolButton::clicked, [this]() {
264 QVector<std::shared_ptr<DBEvent> > events;
264 QVector<std::shared_ptr<DBEvent> > events;
265 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
265 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
266 impl->getSelectedItems(ui->treeView, events, eventProducts);
266 impl->getSelectedItems(ui->treeView, events, eventProducts);
267
267
268 if (!events.isEmpty() && eventProducts.isEmpty()) {
268 if (!events.isEmpty() && eventProducts.isEmpty()) {
269
269
270 if (QMessageBox::warning(this, tr("Remove Event(s)"),
270 if (QMessageBox::warning(this, tr("Remove Event(s)"),
271 tr("The selected event(s) will be completly removed "
271 tr("The selected event(s) will be completly removed "
272 "from the repository!\nAre you sure you want to continue?"),
272 "from the repository!\nAre you sure you want to continue?"),
273 QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
273 QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
274 == QMessageBox::Yes) {
274 == QMessageBox::Yes) {
275
275
276 for (auto event : events) {
276 for (auto event : events) {
277 sqpApp->catalogueController().removeEvent(event);
277 sqpApp->catalogueController().removeEvent(event);
278 impl->removeEvent(event, ui->treeView);
278 impl->removeEvent(event, ui->treeView);
279 }
279 }
280 }
280 }
281 }
281 }
282 });
282 });
283
283
284 connect(ui->treeView, &QTreeView::clicked, this, &CatalogueEventsWidget::emitSelection);
284 connect(ui->treeView, &QTreeView::clicked, this, &CatalogueEventsWidget::emitSelection);
285 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
285 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
286 &CatalogueEventsWidget::emitSelection);
286 &CatalogueEventsWidget::emitSelection);
287
287
288 ui->btnRemove->setEnabled(false); // Disabled by default when nothing is selected
288 ui->btnRemove->setEnabled(false); // Disabled by default when nothing is selected
289 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
289 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
290 auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1;
290 auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1;
291 ui->btnChart->setEnabled(isNotMultiSelection);
291 ui->btnChart->setEnabled(isNotMultiSelection);
292 ui->btnTime->setEnabled(isNotMultiSelection);
292 ui->btnTime->setEnabled(isNotMultiSelection);
293
293
294 if (isNotMultiSelection && ui->btnTime->isChecked()) {
294 if (isNotMultiSelection && ui->btnTime->isChecked()) {
295 impl->updateForTimeMode(ui->treeView);
295 impl->updateForTimeMode(ui->treeView);
296 }
296 }
297 else if (isNotMultiSelection && ui->btnChart->isChecked()) {
297 else if (isNotMultiSelection && ui->btnChart->isChecked()) {
298 impl->updateForGraphMode(ui->treeView);
298 impl->updateForGraphMode(ui->treeView);
299 }
299 }
300
300
301 QVector<std::shared_ptr<DBEvent> > events;
301 QVector<std::shared_ptr<DBEvent> > events;
302 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
302 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
303 impl->getSelectedItems(ui->treeView, events, eventProducts);
303 impl->getSelectedItems(ui->treeView, events, eventProducts);
304 ui->btnRemove->setEnabled(!events.isEmpty() && eventProducts.isEmpty());
304 ui->btnRemove->setEnabled(!events.isEmpty() && eventProducts.isEmpty());
305 });
305 });
306
306
307 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
307 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
308 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Tags,
308 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Tags,
309 QHeaderView::Stretch);
309 QHeaderView::Stretch);
310 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Validation,
310 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Validation,
311 QHeaderView::Fixed);
311 QHeaderView::Fixed);
312 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Name,
312 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Name,
313 QHeaderView::Interactive);
313 QHeaderView::Interactive);
314 ui->treeView->header()->resizeSection((int)CatalogueEventsModel::Column::Validation,
314 ui->treeView->header()->resizeSection((int)CatalogueEventsModel::Column::Validation,
315 VALIDATION_COLUMN_SIZE);
315 VALIDATION_COLUMN_SIZE);
316 ui->treeView->header()->setSortIndicatorShown(true);
316 ui->treeView->header()->setSortIndicatorShown(true);
317
317
318 connect(impl->m_Model, &CatalogueEventsModel::modelSorted, [this]() {
318 connect(impl->m_Model, &CatalogueEventsModel::modelSorted, [this]() {
319 auto allEvents = impl->m_Model->events();
319 auto allEvents = impl->m_Model->events();
320 for (auto event : allEvents) {
320 for (auto event : allEvents) {
321 setEventChanges(event, sqpApp->catalogueController().eventHasChanges(event));
321 setEventChanges(event, sqpApp->catalogueController().eventHasChanges(event));
322 }
322 }
323 });
323 });
324
324
325 populateWithAllEvents();
325 populateWithAllEvents();
326 }
326 }
327
327
328 CatalogueEventsWidget::~CatalogueEventsWidget()
328 CatalogueEventsWidget::~CatalogueEventsWidget()
329 {
329 {
330 delete ui;
330 delete ui;
331 }
331 }
332
332
333 void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualization)
333 void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualization)
334 {
334 {
335 impl->m_VisualizationWidget = visualization;
335 impl->m_VisualizationWidget = visualization;
336 }
336 }
337
337
338 void CatalogueEventsWidget::addEvent(const std::shared_ptr<DBEvent> &event)
338 void CatalogueEventsWidget::addEvent(const std::shared_ptr<DBEvent> &event)
339 {
339 {
340 impl->addEvent(event, ui->treeView);
340 impl->addEvent(event, ui->treeView);
341 }
341 }
342
342
343 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges)
343 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges)
344 {
344 {
345 impl->m_Model->refreshEvent(event);
345 impl->m_Model->refreshEvent(event);
346
346
347 auto eventIndex = impl->m_Model->indexOf(event);
347 auto eventIndex = impl->m_Model->indexOf(event);
348 auto validationIndex
348 auto validationIndex
349 = eventIndex.sibling(eventIndex.row(), (int)CatalogueEventsModel::Column::Validation);
349 = eventIndex.sibling(eventIndex.row(), (int)CatalogueEventsModel::Column::Validation);
350
350
351 if (validationIndex.isValid()) {
351 if (validationIndex.isValid()) {
352 if (hasChanges) {
352 if (hasChanges) {
353 if (ui->treeView->indexWidget(validationIndex) == nullptr) {
353 if (ui->treeView->indexWidget(validationIndex) == nullptr) {
354 auto widget = CatalogueExplorerHelper::buildValidationWidget(
354 auto widget = CatalogueExplorerHelper::buildValidationWidget(
355 ui->treeView,
355 ui->treeView,
356 [this, event]() {
356 [this, event]() {
357 sqpApp->catalogueController().saveEvent(event);
357 sqpApp->catalogueController().saveEvent(event);
358 setEventChanges(event, false);
358 setEventChanges(event, false);
359 },
359 },
360 [this, event]() {
360 [this, event]() {
361 sqpApp->catalogueController().discardEvent(event);
361 bool removed = false;
362 setEventChanges(event, false);
362 sqpApp->catalogueController().discardEvent(event, removed);
363 impl->m_Model->refreshEvent(event, true);
363 if (removed) {
364 impl->m_Model->removeEvent(event);
365 }
366 else {
367 setEventChanges(event, false);
368 impl->m_Model->refreshEvent(event, true);
369 }
364 emitSelection();
370 emitSelection();
365 });
371 });
366 ui->treeView->setIndexWidget(validationIndex, widget);
372 ui->treeView->setIndexWidget(validationIndex, widget);
367 }
373 }
368 }
374 }
369 else {
375 else {
370 // Note: the widget is destroyed
376 // Note: the widget is destroyed
371 ui->treeView->setIndexWidget(validationIndex, nullptr);
377 ui->treeView->setIndexWidget(validationIndex, nullptr);
372 }
378 }
373 }
379 }
374 else {
380 else {
375 qCWarning(LOG_CatalogueEventsWidget())
381 qCWarning(LOG_CatalogueEventsWidget())
376 << "setEventChanges: the event is not displayed in the model.";
382 << "setEventChanges: the event is not displayed in the model.";
377 }
383 }
378 }
384 }
379
385
380 QVector<std::shared_ptr<DBCatalogue> > CatalogueEventsWidget::displayedCatalogues() const
386 QVector<std::shared_ptr<DBCatalogue> > CatalogueEventsWidget::displayedCatalogues() const
381 {
387 {
382 return impl->m_DisplayedCatalogues;
388 return impl->m_DisplayedCatalogues;
383 }
389 }
384
390
385 bool CatalogueEventsWidget::isAllEventsDisplayed() const
391 bool CatalogueEventsWidget::isAllEventsDisplayed() const
386 {
392 {
387 return impl->m_AllEventDisplayed;
393 return impl->m_AllEventDisplayed;
388 }
394 }
389
395
390 bool CatalogueEventsWidget::isEventDisplayed(const std::shared_ptr<DBEvent> &event) const
396 bool CatalogueEventsWidget::isEventDisplayed(const std::shared_ptr<DBEvent> &event) const
391 {
397 {
392 return impl->m_Model->indexOf(event).isValid();
398 return impl->m_Model->indexOf(event).isValid();
393 }
399 }
394
400
395 void CatalogueEventsWidget::populateWithCatalogues(
401 void CatalogueEventsWidget::populateWithCatalogues(
396 const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
402 const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
397 {
403 {
398 impl->m_DisplayedCatalogues = catalogues;
404 impl->m_DisplayedCatalogues = catalogues;
399 impl->m_AllEventDisplayed = false;
405 impl->m_AllEventDisplayed = false;
400
406
401 QSet<QUuid> eventIds;
407 QSet<QUuid> eventIds;
402 QVector<std::shared_ptr<DBEvent> > events;
408 QVector<std::shared_ptr<DBEvent> > events;
403
409
404 for (auto catalogue : catalogues) {
410 for (auto catalogue : catalogues) {
405 auto catalogueEvents = sqpApp->catalogueController().retrieveEventsFromCatalogue(catalogue);
411 auto catalogueEvents = sqpApp->catalogueController().retrieveEventsFromCatalogue(catalogue);
406 for (auto event : catalogueEvents) {
412 for (auto event : catalogueEvents) {
407 if (!eventIds.contains(event->getUniqId())) {
413 if (!eventIds.contains(event->getUniqId())) {
408 events << event;
414 events << event;
409 eventIds.insert(event->getUniqId());
415 eventIds.insert(event->getUniqId());
410 }
416 }
411 }
417 }
412 }
418 }
413
419
414 impl->setEvents(events, this);
420 impl->setEvents(events, this);
415 }
421 }
416
422
417 void CatalogueEventsWidget::populateWithAllEvents()
423 void CatalogueEventsWidget::populateWithAllEvents()
418 {
424 {
419 impl->m_DisplayedCatalogues.clear();
425 impl->m_DisplayedCatalogues.clear();
420 impl->m_AllEventDisplayed = true;
426 impl->m_AllEventDisplayed = true;
421
427
422 auto allEvents = sqpApp->catalogueController().retrieveAllEvents();
428 auto allEvents = sqpApp->catalogueController().retrieveAllEvents();
423
429
424 QVector<std::shared_ptr<DBEvent> > events;
430 QVector<std::shared_ptr<DBEvent> > events;
425 for (auto event : allEvents) {
431 for (auto event : allEvents) {
426 events << event;
432 events << event;
427 }
433 }
428
434
429 impl->setEvents(events, this);
435 impl->setEvents(events, this);
430 }
436 }
431
437
432 void CatalogueEventsWidget::clear()
438 void CatalogueEventsWidget::clear()
433 {
439 {
434 impl->m_DisplayedCatalogues.clear();
440 impl->m_DisplayedCatalogues.clear();
435 impl->m_AllEventDisplayed = false;
441 impl->m_AllEventDisplayed = false;
436 impl->setEvents({}, this);
442 impl->setEvents({}, this);
437 }
443 }
438
444
439 void CatalogueEventsWidget::refresh()
445 void CatalogueEventsWidget::refresh()
440 {
446 {
441 if (isAllEventsDisplayed()) {
447 if (isAllEventsDisplayed()) {
442 populateWithAllEvents();
448 populateWithAllEvents();
443 }
449 }
444 else if (!impl->m_DisplayedCatalogues.isEmpty()) {
450 else if (!impl->m_DisplayedCatalogues.isEmpty()) {
445 populateWithCatalogues(impl->m_DisplayedCatalogues);
451 populateWithCatalogues(impl->m_DisplayedCatalogues);
446 }
452 }
447 }
453 }
448
454
449 void CatalogueEventsWidget::emitSelection()
455 void CatalogueEventsWidget::emitSelection()
450 {
456 {
451 QVector<std::shared_ptr<DBEvent> > events;
457 QVector<std::shared_ptr<DBEvent> > events;
452 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
458 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
453 impl->getSelectedItems(ui->treeView, events, eventProducts);
459 impl->getSelectedItems(ui->treeView, events, eventProducts);
454
460
455 if (!events.isEmpty() && eventProducts.isEmpty()) {
461 if (!events.isEmpty() && eventProducts.isEmpty()) {
456 emit eventsSelected(events);
462 emit eventsSelected(events);
457 }
463 }
458 else if (events.isEmpty() && !eventProducts.isEmpty()) {
464 else if (events.isEmpty() && !eventProducts.isEmpty()) {
459 emit eventProductsSelected(eventProducts);
465 emit eventProductsSelected(eventProducts);
460 }
466 }
461 else {
467 else {
462 emit selectionCleared();
468 emit selectionCleared();
463 }
469 }
464 }
470 }
@@ -1,211 +1,211
1 #include "Catalogue/CatalogueInspectorWidget.h"
1 #include "Catalogue/CatalogueInspectorWidget.h"
2 #include "ui_CatalogueInspectorWidget.h"
2 #include "ui_CatalogueInspectorWidget.h"
3
3
4 #include <Common/DateUtils.h>
4 #include <Common/DateUtils.h>
5 #include <DBCatalogue.h>
5 #include <DBCatalogue.h>
6 #include <DBEvent.h>
6 #include <DBEvent.h>
7 #include <DBEventProduct.h>
7 #include <DBEventProduct.h>
8 #include <DBTag.h>
8 #include <DBTag.h>
9
9
10 struct CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate {
10 struct CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate {
11 std::shared_ptr<DBCatalogue> m_DisplayedCatalogue = nullptr;
11 std::shared_ptr<DBCatalogue> m_DisplayedCatalogue = nullptr;
12 std::shared_ptr<DBEvent> m_DisplayedEvent = nullptr;
12 std::shared_ptr<DBEvent> m_DisplayedEvent = nullptr;
13 std::shared_ptr<DBEventProduct> m_DisplayedEventProduct = nullptr;
13 std::shared_ptr<DBEventProduct> m_DisplayedEventProduct = nullptr;
14
14
15 void connectCatalogueUpdateSignals(CatalogueInspectorWidget *inspector,
15 void connectCatalogueUpdateSignals(CatalogueInspectorWidget *inspector,
16 Ui::CatalogueInspectorWidget *ui);
16 Ui::CatalogueInspectorWidget *ui);
17 void connectEventUpdateSignals(CatalogueInspectorWidget *inspector,
17 void connectEventUpdateSignals(CatalogueInspectorWidget *inspector,
18 Ui::CatalogueInspectorWidget *ui);
18 Ui::CatalogueInspectorWidget *ui);
19 };
19 };
20
20
21 CatalogueInspectorWidget::CatalogueInspectorWidget(QWidget *parent)
21 CatalogueInspectorWidget::CatalogueInspectorWidget(QWidget *parent)
22 : QWidget(parent),
22 : QWidget(parent),
23 ui(new Ui::CatalogueInspectorWidget),
23 ui(new Ui::CatalogueInspectorWidget),
24 impl{spimpl::make_unique_impl<CatalogueInspectorWidgetPrivate>()}
24 impl{spimpl::make_unique_impl<CatalogueInspectorWidgetPrivate>()}
25 {
25 {
26 ui->setupUi(this);
26 ui->setupUi(this);
27 showPage(Page::Empty);
27 showPage(Page::Empty);
28
28
29 impl->connectCatalogueUpdateSignals(this, ui);
29 impl->connectCatalogueUpdateSignals(this, ui);
30 impl->connectEventUpdateSignals(this, ui);
30 impl->connectEventUpdateSignals(this, ui);
31 }
31 }
32
32
33 CatalogueInspectorWidget::~CatalogueInspectorWidget()
33 CatalogueInspectorWidget::~CatalogueInspectorWidget()
34 {
34 {
35 delete ui;
35 delete ui;
36 }
36 }
37
37
38 void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectCatalogueUpdateSignals(
38 void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectCatalogueUpdateSignals(
39 CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui)
39 CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui)
40 {
40 {
41 connect(ui->leCatalogueName, &QLineEdit::editingFinished, [ui, inspector, this]() {
41 connect(ui->leCatalogueName, &QLineEdit::editingFinished, [ui, inspector, this]() {
42 if (ui->leCatalogueName->text() != m_DisplayedCatalogue->getName()) {
42 if (ui->leCatalogueName->text() != m_DisplayedCatalogue->getName()) {
43 m_DisplayedCatalogue->setName(ui->leCatalogueName->text());
43 m_DisplayedCatalogue->setName(ui->leCatalogueName->text());
44 emit inspector->catalogueUpdated(m_DisplayedCatalogue);
44 emit inspector->catalogueUpdated(m_DisplayedCatalogue);
45 }
45 }
46 });
46 });
47
47
48 connect(ui->leCatalogueAuthor, &QLineEdit::editingFinished, [ui, inspector, this]() {
48 connect(ui->leCatalogueAuthor, &QLineEdit::editingFinished, [ui, inspector, this]() {
49 if (ui->leCatalogueAuthor->text() != m_DisplayedCatalogue->getAuthor()) {
49 if (ui->leCatalogueAuthor->text() != m_DisplayedCatalogue->getAuthor()) {
50 m_DisplayedCatalogue->setAuthor(ui->leCatalogueAuthor->text());
50 m_DisplayedCatalogue->setAuthor(ui->leCatalogueAuthor->text());
51 emit inspector->catalogueUpdated(m_DisplayedCatalogue);
51 emit inspector->catalogueUpdated(m_DisplayedCatalogue);
52 }
52 }
53 });
53 });
54 }
54 }
55
55
56 void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectEventUpdateSignals(
56 void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectEventUpdateSignals(
57 CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui)
57 CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui)
58 {
58 {
59 connect(ui->leEventName, &QLineEdit::editingFinished, [ui, inspector, this]() {
59 connect(ui->leEventName, &QLineEdit::editingFinished, [ui, inspector, this]() {
60 if (ui->leEventName->text() != m_DisplayedEvent->getName()) {
60 if (ui->leEventName->text() != m_DisplayedEvent->getName()) {
61 m_DisplayedEvent->setName(ui->leEventName->text());
61 m_DisplayedEvent->setName(ui->leEventName->text());
62 emit inspector->eventUpdated(m_DisplayedEvent);
62 emit inspector->eventUpdated(m_DisplayedEvent);
63 }
63 }
64 });
64 });
65
65
66 connect(ui->leEventTags, &QLineEdit::editingFinished, [ui, inspector, this]() {
66 connect(ui->leEventTags, &QLineEdit::editingFinished, [ui, inspector, this]() {
67 auto tags = ui->leEventTags->text().split(QRegExp("\\s+"));
67 auto tags = ui->leEventTags->text().split(QRegExp("\\s+"), QString::SkipEmptyParts);
68 std::list<QString> tagNames;
68 std::list<QString> tagNames;
69 for (auto tag : tags) {
69 for (auto tag : tags) {
70 tagNames.push_back(tag);
70 tagNames.push_back(tag);
71 }
71 }
72
72
73 if (m_DisplayedEvent->getTagsNames() != tagNames) {
73 if (m_DisplayedEvent->getTagsNames() != tagNames) {
74 m_DisplayedEvent->setTagsNames(tagNames);
74 m_DisplayedEvent->setTagsNames(tagNames);
75 emit inspector->eventUpdated(m_DisplayedEvent);
75 emit inspector->eventUpdated(m_DisplayedEvent);
76 }
76 }
77 });
77 });
78
78
79 connect(ui->leEventProduct, &QLineEdit::editingFinished, [ui, inspector, this]() {
79 connect(ui->leEventProduct, &QLineEdit::editingFinished, [ui, inspector, this]() {
80 if (ui->leEventProduct->text() != m_DisplayedEventProduct->getProductId()) {
80 if (ui->leEventProduct->text() != m_DisplayedEventProduct->getProductId()) {
81 auto oldProductId = m_DisplayedEventProduct->getProductId();
81 auto oldProductId = m_DisplayedEventProduct->getProductId();
82 m_DisplayedEventProduct->setProductId(ui->leEventProduct->text());
82 m_DisplayedEventProduct->setProductId(ui->leEventProduct->text());
83
83
84 auto eventProducts = m_DisplayedEvent->getEventProducts();
84 auto eventProducts = m_DisplayedEvent->getEventProducts();
85 for (auto &eventProduct : eventProducts) {
85 for (auto &eventProduct : eventProducts) {
86 if (eventProduct.getProductId() == oldProductId) {
86 if (eventProduct.getProductId() == oldProductId) {
87 eventProduct.setProductId(m_DisplayedEventProduct->getProductId());
87 eventProduct.setProductId(m_DisplayedEventProduct->getProductId());
88 }
88 }
89 }
89 }
90 m_DisplayedEvent->setEventProducts(eventProducts);
90 m_DisplayedEvent->setEventProducts(eventProducts);
91
91
92 emit inspector->eventUpdated(m_DisplayedEvent);
92 emit inspector->eventUpdated(m_DisplayedEvent);
93 }
93 }
94 });
94 });
95
95
96 connect(ui->dateTimeEventTStart, &QDateTimeEdit::editingFinished, [ui, inspector, this]() {
96 connect(ui->dateTimeEventTStart, &QDateTimeEdit::editingFinished, [ui, inspector, this]() {
97 auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTStart->dateTime());
97 auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTStart->dateTime());
98 if (time != m_DisplayedEventProduct->getTStart()) {
98 if (time != m_DisplayedEventProduct->getTStart()) {
99 m_DisplayedEventProduct->setTStart(time);
99 m_DisplayedEventProduct->setTStart(time);
100
100
101 auto eventProducts = m_DisplayedEvent->getEventProducts();
101 auto eventProducts = m_DisplayedEvent->getEventProducts();
102 for (auto &eventProduct : eventProducts) {
102 for (auto &eventProduct : eventProducts) {
103 if (eventProduct.getProductId() == m_DisplayedEventProduct->getProductId()) {
103 if (eventProduct.getProductId() == m_DisplayedEventProduct->getProductId()) {
104 eventProduct.setTStart(m_DisplayedEventProduct->getTStart());
104 eventProduct.setTStart(m_DisplayedEventProduct->getTStart());
105 }
105 }
106 }
106 }
107 m_DisplayedEvent->setEventProducts(eventProducts);
107 m_DisplayedEvent->setEventProducts(eventProducts);
108
108
109 emit inspector->eventUpdated(m_DisplayedEvent);
109 emit inspector->eventUpdated(m_DisplayedEvent);
110 }
110 }
111 });
111 });
112
112
113 connect(ui->dateTimeEventTEnd, &QDateTimeEdit::editingFinished, [ui, inspector, this]() {
113 connect(ui->dateTimeEventTEnd, &QDateTimeEdit::editingFinished, [ui, inspector, this]() {
114 auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTEnd->dateTime());
114 auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTEnd->dateTime());
115 if (time != m_DisplayedEventProduct->getTEnd()) {
115 if (time != m_DisplayedEventProduct->getTEnd()) {
116 m_DisplayedEventProduct->setTEnd(time);
116 m_DisplayedEventProduct->setTEnd(time);
117
117
118 auto eventProducts = m_DisplayedEvent->getEventProducts();
118 auto eventProducts = m_DisplayedEvent->getEventProducts();
119 for (auto &eventProduct : eventProducts) {
119 for (auto &eventProduct : eventProducts) {
120 if (eventProduct.getProductId() == m_DisplayedEventProduct->getProductId()) {
120 if (eventProduct.getProductId() == m_DisplayedEventProduct->getProductId()) {
121 eventProduct.setTEnd(m_DisplayedEventProduct->getTEnd());
121 eventProduct.setTEnd(m_DisplayedEventProduct->getTEnd());
122 }
122 }
123 }
123 }
124 m_DisplayedEvent->setEventProducts(eventProducts);
124 m_DisplayedEvent->setEventProducts(eventProducts);
125
125
126 emit inspector->eventUpdated(m_DisplayedEvent);
126 emit inspector->eventUpdated(m_DisplayedEvent);
127 }
127 }
128 });
128 });
129 }
129 }
130
130
131 void CatalogueInspectorWidget::showPage(CatalogueInspectorWidget::Page page)
131 void CatalogueInspectorWidget::showPage(CatalogueInspectorWidget::Page page)
132 {
132 {
133 ui->stackedWidget->setCurrentIndex(static_cast<int>(page));
133 ui->stackedWidget->setCurrentIndex(static_cast<int>(page));
134 }
134 }
135
135
136 CatalogueInspectorWidget::Page CatalogueInspectorWidget::currentPage() const
136 CatalogueInspectorWidget::Page CatalogueInspectorWidget::currentPage() const
137 {
137 {
138 return static_cast<Page>(ui->stackedWidget->currentIndex());
138 return static_cast<Page>(ui->stackedWidget->currentIndex());
139 }
139 }
140
140
141 void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event)
141 void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event)
142 {
142 {
143 impl->m_DisplayedEvent = event;
143 impl->m_DisplayedEvent = event;
144
144
145 blockSignals(true);
145 blockSignals(true);
146
146
147 showPage(Page::EventProperties);
147 showPage(Page::EventProperties);
148 ui->leEventName->setEnabled(true);
148 ui->leEventName->setEnabled(true);
149 ui->leEventName->setText(event->getName());
149 ui->leEventName->setText(event->getName());
150 ui->leEventProduct->setEnabled(false);
150 ui->leEventProduct->setEnabled(false);
151 ui->leEventProduct->setText(
151 ui->leEventProduct->setText(
152 QString::number(event->getEventProducts().size()).append(" product(s)"));
152 QString::number(event->getEventProducts().size()).append(" product(s)"));
153
153
154 QString tagList;
154 QString tagList;
155 auto tags = event->getTagsNames();
155 auto tags = event->getTagsNames();
156 for (auto tag : tags) {
156 for (auto tag : tags) {
157 tagList += tag;
157 tagList += tag;
158 tagList += ' ';
158 tagList += ' ';
159 }
159 }
160
160
161 ui->leEventTags->setEnabled(true);
161 ui->leEventTags->setEnabled(true);
162 ui->leEventTags->setText(tagList);
162 ui->leEventTags->setText(tagList);
163
163
164 ui->dateTimeEventTStart->setEnabled(false);
164 ui->dateTimeEventTStart->setEnabled(false);
165 ui->dateTimeEventTEnd->setEnabled(false);
165 ui->dateTimeEventTEnd->setEnabled(false);
166
166
167 ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart()));
167 ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart()));
168 ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd()));
168 ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd()));
169
169
170 blockSignals(false);
170 blockSignals(false);
171 }
171 }
172
172
173 void CatalogueInspectorWidget::setEventProduct(const std::shared_ptr<DBEvent> &event,
173 void CatalogueInspectorWidget::setEventProduct(const std::shared_ptr<DBEvent> &event,
174 const std::shared_ptr<DBEventProduct> &eventProduct)
174 const std::shared_ptr<DBEventProduct> &eventProduct)
175 {
175 {
176
176
177 impl->m_DisplayedEvent = event;
177 impl->m_DisplayedEvent = event;
178 impl->m_DisplayedEventProduct = eventProduct;
178 impl->m_DisplayedEventProduct = eventProduct;
179
179
180 blockSignals(true);
180 blockSignals(true);
181
181
182 showPage(Page::EventProperties);
182 showPage(Page::EventProperties);
183 ui->leEventName->setEnabled(false);
183 ui->leEventName->setEnabled(false);
184 ui->leEventName->setText(event->getName());
184 ui->leEventName->setText(event->getName());
185 ui->leEventProduct->setEnabled(false);
185 ui->leEventProduct->setEnabled(false);
186 ui->leEventProduct->setText(eventProduct->getProductId());
186 ui->leEventProduct->setText(eventProduct->getProductId());
187
187
188 ui->leEventTags->setEnabled(false);
188 ui->leEventTags->setEnabled(false);
189 ui->leEventTags->clear();
189 ui->leEventTags->clear();
190
190
191 ui->dateTimeEventTStart->setEnabled(true);
191 ui->dateTimeEventTStart->setEnabled(true);
192 ui->dateTimeEventTEnd->setEnabled(true);
192 ui->dateTimeEventTEnd->setEnabled(true);
193
193
194 ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(eventProduct->getTStart()));
194 ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(eventProduct->getTStart()));
195 ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(eventProduct->getTEnd()));
195 ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(eventProduct->getTEnd()));
196
196
197 blockSignals(false);
197 blockSignals(false);
198 }
198 }
199
199
200 void CatalogueInspectorWidget::setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue)
200 void CatalogueInspectorWidget::setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue)
201 {
201 {
202 impl->m_DisplayedCatalogue = catalogue;
202 impl->m_DisplayedCatalogue = catalogue;
203
203
204 blockSignals(true);
204 blockSignals(true);
205
205
206 showPage(Page::CatalogueProperties);
206 showPage(Page::CatalogueProperties);
207 ui->leCatalogueName->setText(catalogue->getName());
207 ui->leCatalogueName->setText(catalogue->getName());
208 ui->leCatalogueAuthor->setText(catalogue->getAuthor());
208 ui->leCatalogueAuthor->setText(catalogue->getAuthor());
209
209
210 blockSignals(false);
210 blockSignals(false);
211 }
211 }
General Comments 0
You need to be logged in to leave comments. Login now