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