@@ -1,566 +1,574 | |||||
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 | /** |
|
30 | /** | |
31 | * Possible types of an repository |
|
31 | * Possible types of an repository | |
32 | */ |
|
32 | */ | |
33 | enum class DBType { SYNC, WORK, TRASH }; |
|
33 | enum class DBType { SYNC, WORK, TRASH }; | |
34 | class CatalogueController::CatalogueControllerPrivate { |
|
34 | class CatalogueController::CatalogueControllerPrivate { | |
35 |
|
35 | |||
36 | public: |
|
36 | public: | |
37 | explicit CatalogueControllerPrivate(CatalogueController *parent) : m_Q{parent} {} |
|
37 | explicit CatalogueControllerPrivate(CatalogueController *parent) : m_Q{parent} {} | |
38 |
|
38 | |||
39 | CatalogueDao m_CatalogueDao; |
|
39 | CatalogueDao m_CatalogueDao; | |
40 |
|
40 | |||
41 | QStringList m_RepositoryList; |
|
41 | QStringList m_RepositoryList; | |
42 | CatalogueController *m_Q; |
|
42 | CatalogueController *m_Q; | |
43 |
|
43 | |||
44 | QSet<QString> m_KeysWithChanges; |
|
44 | QSet<QString> m_KeysWithChanges; | |
45 |
|
45 | |||
46 | QString eventUniqueKey(const std::shared_ptr<DBEvent> &event) const; |
|
46 | QString eventUniqueKey(const std::shared_ptr<DBEvent> &event) const; | |
47 | QString catalogueUniqueKey(const std::shared_ptr<DBCatalogue> &catalogue) const; |
|
47 | QString catalogueUniqueKey(const std::shared_ptr<DBCatalogue> &catalogue) const; | |
48 |
|
48 | |||
49 | void copyDBtoDB(const QString &dbFrom, const QString &dbTo); |
|
49 | void copyDBtoDB(const QString &dbFrom, const QString &dbTo); | |
50 | QString toWorkRepository(QString repository); |
|
50 | QString toWorkRepository(QString repository); | |
51 | QString toSyncRepository(QString repository); |
|
51 | QString toSyncRepository(QString repository); | |
52 | void savAllDB(); |
|
52 | void savAllDB(); | |
53 |
|
53 | |||
54 | void saveEvent(std::shared_ptr<DBEvent> event, bool persist = true); |
|
54 | void saveEvent(std::shared_ptr<DBEvent> event, bool persist = true); | |
55 | void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool persist = true); |
|
55 | void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool persist = true); | |
56 |
|
56 | |||
57 | std::shared_ptr<IRequestPredicate> createFinder(const QUuid &uniqId, const QString &repository, |
|
57 | std::shared_ptr<IRequestPredicate> createFinder(const QUuid &uniqId, const QString &repository, | |
58 | DBType type); |
|
58 | DBType type); | |
59 | }; |
|
59 | }; | |
60 |
|
60 | |||
61 | CatalogueController::CatalogueController(QObject *parent) |
|
61 | CatalogueController::CatalogueController(QObject *parent) | |
62 | : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>(this)} |
|
62 | : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>(this)} | |
63 | { |
|
63 | { | |
64 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction") |
|
64 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction") | |
65 | << QThread::currentThread(); |
|
65 | << QThread::currentThread(); | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | CatalogueController::~CatalogueController() |
|
68 | CatalogueController::~CatalogueController() | |
69 | { |
|
69 | { | |
70 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction") |
|
70 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction") | |
71 | << QThread::currentThread(); |
|
71 | << QThread::currentThread(); | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | QStringList CatalogueController::getRepositories() const |
|
74 | QStringList CatalogueController::getRepositories() const | |
75 | { |
|
75 | { | |
76 | return impl->m_RepositoryList; |
|
76 | return impl->m_RepositoryList; | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | void CatalogueController::addDB(const QString &dbPath) |
|
79 | void CatalogueController::addDB(const QString &dbPath) | |
80 | { |
|
80 | { | |
81 | QDir dbDir(dbPath); |
|
81 | QDir dbDir(dbPath); | |
82 | if (dbDir.exists()) { |
|
82 | if (dbDir.exists()) { | |
83 | auto dirName = dbDir.dirName(); |
|
83 | auto dirName = dbDir.dirName(); | |
84 |
|
84 | |||
85 | if (std::find(impl->m_RepositoryList.cbegin(), impl->m_RepositoryList.cend(), dirName) |
|
85 | if (std::find(impl->m_RepositoryList.cbegin(), impl->m_RepositoryList.cend(), dirName) | |
86 | != impl->m_RepositoryList.cend()) { |
|
86 | != impl->m_RepositoryList.cend()) { | |
87 | qCCritical(LOG_CatalogueController()) |
|
87 | qCCritical(LOG_CatalogueController()) | |
88 | << tr("Impossible to addDB that is already loaded"); |
|
88 | << tr("Impossible to addDB that is already loaded"); | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | if (!impl->m_CatalogueDao.addDB(dbPath, dirName)) { |
|
91 | if (!impl->m_CatalogueDao.addDB(dbPath, dirName)) { | |
92 | qCCritical(LOG_CatalogueController()) |
|
92 | qCCritical(LOG_CatalogueController()) | |
93 | << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath); |
|
93 | << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath); | |
94 | } |
|
94 | } | |
95 | else { |
|
95 | else { | |
96 | impl->m_RepositoryList << dirName; |
|
96 | impl->m_RepositoryList << dirName; | |
97 | impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName)); |
|
97 | impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName)); | |
98 | } |
|
98 | } | |
99 | } |
|
99 | } | |
100 | else { |
|
100 | else { | |
101 | qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ") |
|
101 | qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ") | |
102 | << dbPath; |
|
102 | << dbPath; | |
103 | } |
|
103 | } | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | void CatalogueController::saveDB(const QString &destinationPath, const QString &repository) |
|
106 | void CatalogueController::saveDB(const QString &destinationPath, const QString &repository) | |
107 | { |
|
107 | { | |
108 | if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) { |
|
108 | if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) { | |
109 | qCCritical(LOG_CatalogueController()) |
|
109 | qCCritical(LOG_CatalogueController()) | |
110 | << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath); |
|
110 | << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath); | |
111 | } |
|
111 | } | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | std::list<std::shared_ptr<DBEvent> > |
|
114 | std::list<std::shared_ptr<DBEvent> > | |
115 | CatalogueController::retrieveEvents(const QString &repository) const |
|
115 | CatalogueController::retrieveEvents(const QString &repository) const | |
116 | { |
|
116 | { | |
117 | QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository; |
|
117 | QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository; | |
118 |
|
118 | |||
119 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; |
|
119 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; | |
120 | auto events = impl->m_CatalogueDao.getEvents(impl->toWorkRepository(dbDireName)); |
|
120 | auto events = impl->m_CatalogueDao.getEvents(impl->toWorkRepository(dbDireName)); | |
121 | for (auto event : events) { |
|
121 | for (auto event : events) { | |
122 | eventsShared.push_back(std::make_shared<DBEvent>(event)); |
|
122 | eventsShared.push_back(std::make_shared<DBEvent>(event)); | |
123 | } |
|
123 | } | |
124 | return eventsShared; |
|
124 | return eventsShared; | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() const |
|
127 | std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() const | |
128 | { |
|
128 | { | |
129 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; |
|
129 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; | |
130 | for (auto repository : impl->m_RepositoryList) { |
|
130 | for (auto repository : impl->m_RepositoryList) { | |
131 | eventsShared.splice(eventsShared.end(), retrieveEvents(repository)); |
|
131 | eventsShared.splice(eventsShared.end(), retrieveEvents(repository)); | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | return eventsShared; |
|
134 | return eventsShared; | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | std::list<std::shared_ptr<DBEvent> > |
|
137 | std::list<std::shared_ptr<DBEvent> > | |
138 | CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const |
|
138 | CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const | |
139 | { |
|
139 | { | |
140 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; |
|
140 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; | |
141 | auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue); |
|
141 | auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue); | |
142 | for (auto event : events) { |
|
142 | for (auto event : events) { | |
143 | eventsShared.push_back(std::make_shared<DBEvent>(event)); |
|
143 | eventsShared.push_back(std::make_shared<DBEvent>(event)); | |
144 | } |
|
144 | } | |
145 | return eventsShared; |
|
145 | return eventsShared; | |
146 | } |
|
146 | } | |
147 |
|
147 | |||
148 | void CatalogueController::updateEvent(std::shared_ptr<DBEvent> event) |
|
148 | void CatalogueController::updateEvent(std::shared_ptr<DBEvent> event) | |
149 | { |
|
149 | { | |
150 | event->setRepository(impl->toWorkRepository(event->getRepository())); |
|
150 | event->setRepository(impl->toWorkRepository(event->getRepository())); | |
151 |
|
151 | |||
152 | auto uniqueId = impl->eventUniqueKey(event); |
|
152 | auto uniqueId = impl->eventUniqueKey(event); | |
153 | impl->m_KeysWithChanges.insert(uniqueId); |
|
153 | impl->m_KeysWithChanges.insert(uniqueId); | |
154 |
|
154 | |||
155 | impl->m_CatalogueDao.updateEvent(*event); |
|
155 | impl->m_CatalogueDao.updateEvent(*event); | |
156 | } |
|
156 | } | |
157 |
|
157 | |||
158 | void CatalogueController::updateEventProduct(std::shared_ptr<DBEventProduct> eventProduct) |
|
158 | void CatalogueController::updateEventProduct(std::shared_ptr<DBEventProduct> eventProduct) | |
159 | { |
|
159 | { | |
160 | impl->m_CatalogueDao.updateEventProduct(*eventProduct); |
|
160 | impl->m_CatalogueDao.updateEventProduct(*eventProduct); | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event) |
|
163 | void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event) | |
164 | { |
|
164 | { | |
165 | // Remove it from both repository and repository_work |
|
165 | // Remove it from both repository and repository_work | |
166 | event->setRepository(impl->toWorkRepository(event->getRepository())); |
|
166 | event->setRepository(impl->toWorkRepository(event->getRepository())); | |
167 | impl->m_CatalogueDao.removeEvent(*event); |
|
167 | impl->m_CatalogueDao.removeEvent(*event); | |
168 | event->setRepository(impl->toSyncRepository(event->getRepository())); |
|
168 | event->setRepository(impl->toSyncRepository(event->getRepository())); | |
169 | impl->m_CatalogueDao.removeEvent(*event); |
|
169 | impl->m_CatalogueDao.removeEvent(*event); | |
170 | impl->savAllDB(); |
|
170 | impl->savAllDB(); | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | void CatalogueController::addEvent(std::shared_ptr<DBEvent> event) |
|
173 | void CatalogueController::addEvent(std::shared_ptr<DBEvent> event) | |
174 | { |
|
174 | { | |
175 | event->setRepository(impl->toWorkRepository(event->getRepository())); |
|
175 | event->setRepository(impl->toWorkRepository(event->getRepository())); | |
176 |
|
176 | |||
177 | auto eventTemp = *event; |
|
177 | auto eventTemp = *event; | |
178 | impl->m_CatalogueDao.addEvent(eventTemp); |
|
178 | impl->m_CatalogueDao.addEvent(eventTemp); | |
179 |
|
179 | |||
180 | // Call update is necessary at the creation of add Event if it has some tags or some event |
|
180 | // Call update is necessary at the creation of add Event if it has some tags or some event | |
181 | // products |
|
181 | // products | |
182 | if (!event->getEventProducts().empty() || !event->getTags().empty()) { |
|
182 | if (!event->getEventProducts().empty() || !event->getTags().empty()) { | |
183 |
|
183 | |||
184 | auto eventProductsTemp = eventTemp.getEventProducts(); |
|
184 | auto eventProductsTemp = eventTemp.getEventProducts(); | |
185 | auto eventProductTempUpdated = std::list<DBEventProduct>{}; |
|
185 | auto eventProductTempUpdated = std::list<DBEventProduct>{}; | |
186 | for (auto eventProductTemp : eventProductsTemp) { |
|
186 | for (auto eventProductTemp : eventProductsTemp) { | |
187 | eventProductTemp.setEvent(eventTemp); |
|
187 | eventProductTemp.setEvent(eventTemp); | |
188 | eventProductTempUpdated.push_back(eventProductTemp); |
|
188 | eventProductTempUpdated.push_back(eventProductTemp); | |
189 | } |
|
189 | } | |
190 | eventTemp.setEventProducts(eventProductTempUpdated); |
|
190 | eventTemp.setEventProducts(eventProductTempUpdated); | |
191 |
|
191 | |||
192 | impl->m_CatalogueDao.updateEvent(eventTemp); |
|
192 | impl->m_CatalogueDao.updateEvent(eventTemp); | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | auto workPred = impl->createFinder(event->getUniqId(), event->getRepository(), DBType::WORK); |
|
195 | auto workPred = impl->createFinder(event->getUniqId(), event->getRepository(), DBType::WORK); | |
196 |
|
196 | |||
197 | auto workEvent = impl->m_CatalogueDao.getEvent(workPred); |
|
197 | auto workEvent = impl->m_CatalogueDao.getEvent(workPred); | |
198 | *event = workEvent; |
|
198 | *event = workEvent; | |
199 |
|
199 | |||
200 |
|
200 | |||
201 | auto uniqueId = impl->eventUniqueKey(event); |
|
201 | auto uniqueId = impl->eventUniqueKey(event); | |
202 | impl->m_KeysWithChanges.insert(uniqueId); |
|
202 | impl->m_KeysWithChanges.insert(uniqueId); | |
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 | void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event) |
|
205 | void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event) | |
206 | { |
|
206 | { | |
207 | impl->saveEvent(event, true); |
|
207 | impl->saveEvent(event, true); | |
208 | impl->m_KeysWithChanges.remove(impl->eventUniqueKey(event)); |
|
208 | impl->m_KeysWithChanges.remove(impl->eventUniqueKey(event)); | |
209 | } |
|
209 | } | |
210 |
|
210 | |||
211 | void CatalogueController::discardEvent(std::shared_ptr<DBEvent> event, bool &removed) |
|
211 | void CatalogueController::discardEvent(std::shared_ptr<DBEvent> event, bool &removed) | |
212 | { |
|
212 | { | |
213 | auto syncPred = impl->createFinder(event->getUniqId(), event->getRepository(), DBType::SYNC); |
|
213 | auto syncPred = impl->createFinder(event->getUniqId(), event->getRepository(), DBType::SYNC); | |
214 | auto workPred = impl->createFinder(event->getUniqId(), event->getRepository(), DBType::WORK); |
|
214 | auto workPred = impl->createFinder(event->getUniqId(), event->getRepository(), DBType::WORK); | |
215 |
|
215 | |||
216 | auto syncEvent = impl->m_CatalogueDao.getEvent(syncPred); |
|
216 | auto syncEvent = impl->m_CatalogueDao.getEvent(syncPred); | |
217 | if (!syncEvent.getUniqId().isNull()) { |
|
217 | if (!syncEvent.getUniqId().isNull()) { | |
218 | removed = false; |
|
218 | removed = false; | |
219 | impl->m_CatalogueDao.copyEvent(syncEvent, impl->toWorkRepository(event->getRepository()), |
|
219 | impl->m_CatalogueDao.copyEvent(syncEvent, impl->toWorkRepository(event->getRepository()), | |
220 | true); |
|
220 | true); | |
221 |
|
221 | |||
222 | auto workEvent = impl->m_CatalogueDao.getEvent(workPred); |
|
222 | auto workEvent = impl->m_CatalogueDao.getEvent(workPred); | |
223 | *event = workEvent; |
|
223 | *event = workEvent; | |
224 | impl->m_KeysWithChanges.remove(impl->eventUniqueKey(event)); |
|
224 | impl->m_KeysWithChanges.remove(impl->eventUniqueKey(event)); | |
225 | } |
|
225 | } | |
226 | else { |
|
226 | else { | |
227 | removed = true; |
|
227 | removed = true; | |
228 | // Since the element wasn't in sync repository. Discard it means remove it |
|
228 | // Since the element wasn't in sync repository. Discard it means remove it | |
229 | event->setRepository(impl->toWorkRepository(event->getRepository())); |
|
229 | event->setRepository(impl->toWorkRepository(event->getRepository())); | |
230 | impl->m_CatalogueDao.removeEvent(*event); |
|
230 | impl->m_CatalogueDao.removeEvent(*event); | |
231 | } |
|
231 | } | |
232 | } |
|
232 | } | |
233 |
|
233 | |||
234 | bool CatalogueController::eventHasChanges(std::shared_ptr<DBEvent> event) const |
|
234 | bool CatalogueController::eventHasChanges(std::shared_ptr<DBEvent> event) const | |
235 | { |
|
235 | { | |
236 | return impl->m_KeysWithChanges.contains(impl->eventUniqueKey(event)); |
|
236 | return impl->m_KeysWithChanges.contains(impl->eventUniqueKey(event)); | |
237 | } |
|
237 | } | |
238 |
|
238 | |||
239 | std::list<std::shared_ptr<DBCatalogue> > |
|
239 | std::list<std::shared_ptr<DBCatalogue> > | |
240 | CatalogueController::retrieveCatalogues(const QString &repository) const |
|
240 | CatalogueController::retrieveCatalogues(const QString &repository) const | |
241 | { |
|
241 | { | |
242 | QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository; |
|
242 | QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository; | |
243 |
|
243 | |||
244 | auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{}; |
|
244 | auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{}; | |
245 | auto catalogues = impl->m_CatalogueDao.getCatalogues(impl->toWorkRepository(dbDireName)); |
|
245 | auto catalogues = impl->m_CatalogueDao.getCatalogues(impl->toWorkRepository(dbDireName)); | |
246 | for (auto catalogue : catalogues) { |
|
246 | for (auto catalogue : catalogues) { | |
247 | cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue)); |
|
247 | cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue)); | |
248 | } |
|
248 | } | |
249 | return cataloguesShared; |
|
249 | return cataloguesShared; | |
250 | } |
|
250 | } | |
251 |
|
251 | |||
252 | void CatalogueController::addCatalogue(std::shared_ptr<DBCatalogue> catalogue) |
|
252 | void CatalogueController::addCatalogue(std::shared_ptr<DBCatalogue> catalogue) | |
253 | { |
|
253 | { | |
254 | catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); |
|
254 | catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); | |
255 |
|
255 | |||
256 | auto catalogueTemp = *catalogue; |
|
256 | auto catalogueTemp = *catalogue; | |
257 | impl->m_CatalogueDao.addCatalogue(catalogueTemp); |
|
257 | impl->m_CatalogueDao.addCatalogue(catalogueTemp); | |
258 |
|
258 | |||
259 | auto workPred |
|
259 | auto workPred | |
260 | = impl->createFinder(catalogue->getUniqId(), catalogue->getRepository(), DBType::WORK); |
|
260 | = impl->createFinder(catalogue->getUniqId(), catalogue->getRepository(), DBType::WORK); | |
261 |
|
261 | |||
262 | auto workCatalogue = impl->m_CatalogueDao.getCatalogue(workPred); |
|
262 | auto workCatalogue = impl->m_CatalogueDao.getCatalogue(workPred); | |
263 | *catalogue = workCatalogue; |
|
263 | *catalogue = workCatalogue; | |
264 |
|
264 | |||
265 | auto uniqueId = impl->catalogueUniqueKey(catalogue); |
|
265 | auto uniqueId = impl->catalogueUniqueKey(catalogue); | |
266 | impl->m_KeysWithChanges.insert(uniqueId); |
|
266 | impl->m_KeysWithChanges.insert(uniqueId); | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue) |
|
269 | void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue) | |
270 | { |
|
270 | { | |
271 | catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); |
|
271 | catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); | |
272 |
|
272 | |||
273 | auto uniqueId = impl->catalogueUniqueKey(catalogue); |
|
273 | auto uniqueId = impl->catalogueUniqueKey(catalogue); | |
274 | impl->m_KeysWithChanges.insert(uniqueId); |
|
274 | impl->m_KeysWithChanges.insert(uniqueId); | |
275 |
|
275 | |||
276 | impl->m_CatalogueDao.updateCatalogue(*catalogue); |
|
276 | impl->m_CatalogueDao.updateCatalogue(*catalogue); | |
277 | } |
|
277 | } | |
278 |
|
278 | |||
279 | void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue) |
|
279 | void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue) | |
280 | { |
|
280 | { | |
281 | // Remove it from both repository and repository_work |
|
281 | // Remove it from both repository and repository_work | |
282 | catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); |
|
282 | catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); | |
283 | impl->m_CatalogueDao.removeCatalogue(*catalogue); |
|
283 | impl->m_CatalogueDao.removeCatalogue(*catalogue); | |
284 | catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository())); |
|
284 | catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository())); | |
285 | impl->m_CatalogueDao.removeCatalogue(*catalogue); |
|
285 | impl->m_CatalogueDao.removeCatalogue(*catalogue); | |
286 | impl->savAllDB(); |
|
286 | impl->savAllDB(); | |
287 | } |
|
287 | } | |
288 |
|
288 | |||
289 | void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue) |
|
289 | void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue) | |
290 | { |
|
290 | { | |
291 | impl->saveCatalogue(catalogue, true); |
|
291 | impl->saveCatalogue(catalogue, true); | |
292 | impl->m_KeysWithChanges.remove(impl->catalogueUniqueKey(catalogue)); |
|
292 | impl->m_KeysWithChanges.remove(impl->catalogueUniqueKey(catalogue)); | |
|
293 | ||||
|
294 | // remove key of events of the catalogue | |||
|
295 | if (catalogue->getType() == CatalogueType::STATIC) { | |||
|
296 | auto events = this->retrieveEventsFromCatalogue(catalogue); | |||
|
297 | for (auto event : events) { | |||
|
298 | impl->m_KeysWithChanges.remove(impl->eventUniqueKey(event)); | |||
|
299 | } | |||
|
300 | } | |||
293 | } |
|
301 | } | |
294 |
|
302 | |||
295 | void CatalogueController::discardCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool &removed) |
|
303 | void CatalogueController::discardCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool &removed) | |
296 | { |
|
304 | { | |
297 | auto syncPred |
|
305 | auto syncPred | |
298 | = impl->createFinder(catalogue->getUniqId(), catalogue->getRepository(), DBType::SYNC); |
|
306 | = impl->createFinder(catalogue->getUniqId(), catalogue->getRepository(), DBType::SYNC); | |
299 | auto workPred |
|
307 | auto workPred | |
300 | = impl->createFinder(catalogue->getUniqId(), catalogue->getRepository(), DBType::WORK); |
|
308 | = impl->createFinder(catalogue->getUniqId(), catalogue->getRepository(), DBType::WORK); | |
301 |
|
309 | |||
302 | auto syncCatalogue = impl->m_CatalogueDao.getCatalogue(syncPred); |
|
310 | auto syncCatalogue = impl->m_CatalogueDao.getCatalogue(syncPred); | |
303 | if (!syncCatalogue.getUniqId().isNull()) { |
|
311 | if (!syncCatalogue.getUniqId().isNull()) { | |
304 | removed = false; |
|
312 | removed = false; | |
305 | impl->m_CatalogueDao.copyCatalogue( |
|
313 | impl->m_CatalogueDao.copyCatalogue( | |
306 | syncCatalogue, impl->toWorkRepository(catalogue->getRepository()), true); |
|
314 | syncCatalogue, impl->toWorkRepository(catalogue->getRepository()), true); | |
307 |
|
315 | |||
308 | auto workCatalogue = impl->m_CatalogueDao.getCatalogue(workPred); |
|
316 | auto workCatalogue = impl->m_CatalogueDao.getCatalogue(workPred); | |
309 | *catalogue = workCatalogue; |
|
317 | *catalogue = workCatalogue; | |
310 | impl->m_KeysWithChanges.remove(impl->catalogueUniqueKey(catalogue)); |
|
318 | impl->m_KeysWithChanges.remove(impl->catalogueUniqueKey(catalogue)); | |
311 | } |
|
319 | } | |
312 | else { |
|
320 | else { | |
313 | removed = true; |
|
321 | removed = true; | |
314 | // Since the element wasn't in sync repository. Discard it means remove it |
|
322 | // Since the element wasn't in sync repository. Discard it means remove it | |
315 | catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); |
|
323 | catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); | |
316 | impl->m_CatalogueDao.removeCatalogue(*catalogue); |
|
324 | impl->m_CatalogueDao.removeCatalogue(*catalogue); | |
317 | } |
|
325 | } | |
318 | } |
|
326 | } | |
319 |
|
327 | |||
320 | void CatalogueController::saveAll() |
|
328 | void CatalogueController::saveAll() | |
321 | { |
|
329 | { | |
322 | for (auto repository : impl->m_RepositoryList) { |
|
330 | for (auto repository : impl->m_RepositoryList) { | |
323 | // Save Event |
|
331 | // Save Event | |
324 | auto events = this->retrieveEvents(repository); |
|
332 | auto events = this->retrieveEvents(repository); | |
325 | for (auto event : events) { |
|
333 | for (auto event : events) { | |
326 | impl->saveEvent(event, false); |
|
334 | impl->saveEvent(event, false); | |
327 | } |
|
335 | } | |
328 |
|
336 | |||
329 | // Save Catalogue |
|
337 | // Save Catalogue | |
330 | auto catalogues = this->retrieveCatalogues(repository); |
|
338 | auto catalogues = this->retrieveCatalogues(repository); | |
331 | for (auto catalogue : catalogues) { |
|
339 | for (auto catalogue : catalogues) { | |
332 | impl->saveCatalogue(catalogue, false); |
|
340 | impl->saveCatalogue(catalogue, false); | |
333 | } |
|
341 | } | |
334 | } |
|
342 | } | |
335 |
|
343 | |||
336 | impl->savAllDB(); |
|
344 | impl->savAllDB(); | |
337 | impl->m_KeysWithChanges.clear(); |
|
345 | impl->m_KeysWithChanges.clear(); | |
338 | } |
|
346 | } | |
339 |
|
347 | |||
340 | bool CatalogueController::hasChanges() const |
|
348 | bool CatalogueController::hasChanges() const | |
341 | { |
|
349 | { | |
342 | return !impl->m_KeysWithChanges.isEmpty(); |
|
350 | return !impl->m_KeysWithChanges.isEmpty(); | |
343 | } |
|
351 | } | |
344 |
|
352 | |||
345 | QByteArray |
|
353 | QByteArray | |
346 | CatalogueController::mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const |
|
354 | CatalogueController::mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const | |
347 | { |
|
355 | { | |
348 | auto encodedData = QByteArray{}; |
|
356 | auto encodedData = QByteArray{}; | |
349 |
|
357 | |||
350 | QMap<QString, QVariantList> idsPerRepository; |
|
358 | QMap<QString, QVariantList> idsPerRepository; | |
351 | for (auto event : events) { |
|
359 | for (auto event : events) { | |
352 | idsPerRepository[event->getRepository()] << event->getUniqId(); |
|
360 | idsPerRepository[event->getRepository()] << event->getUniqId(); | |
353 | } |
|
361 | } | |
354 |
|
362 | |||
355 | QDataStream stream{&encodedData, QIODevice::WriteOnly}; |
|
363 | QDataStream stream{&encodedData, QIODevice::WriteOnly}; | |
356 | stream << idsPerRepository; |
|
364 | stream << idsPerRepository; | |
357 |
|
365 | |||
358 | return encodedData; |
|
366 | return encodedData; | |
359 | } |
|
367 | } | |
360 |
|
368 | |||
361 | QVector<std::shared_ptr<DBEvent> > |
|
369 | QVector<std::shared_ptr<DBEvent> > | |
362 | CatalogueController::eventsForMimeData(const QByteArray &mimeData) const |
|
370 | CatalogueController::eventsForMimeData(const QByteArray &mimeData) const | |
363 | { |
|
371 | { | |
364 | auto events = QVector<std::shared_ptr<DBEvent> >{}; |
|
372 | auto events = QVector<std::shared_ptr<DBEvent> >{}; | |
365 | QDataStream stream{mimeData}; |
|
373 | QDataStream stream{mimeData}; | |
366 |
|
374 | |||
367 | QMap<QString, QVariantList> idsPerRepository; |
|
375 | QMap<QString, QVariantList> idsPerRepository; | |
368 | stream >> idsPerRepository; |
|
376 | stream >> idsPerRepository; | |
369 |
|
377 | |||
370 | for (auto it = idsPerRepository.cbegin(); it != idsPerRepository.cend(); ++it) { |
|
378 | for (auto it = idsPerRepository.cbegin(); it != idsPerRepository.cend(); ++it) { | |
371 | auto repository = it.key(); |
|
379 | auto repository = it.key(); | |
372 | auto allRepositoryEvent = retrieveEvents(repository); |
|
380 | auto allRepositoryEvent = retrieveEvents(repository); | |
373 | for (auto uuid : it.value()) { |
|
381 | for (auto uuid : it.value()) { | |
374 | for (auto repositoryEvent : allRepositoryEvent) { |
|
382 | for (auto repositoryEvent : allRepositoryEvent) { | |
375 | if (uuid.toUuid() == repositoryEvent->getUniqId()) { |
|
383 | if (uuid.toUuid() == repositoryEvent->getUniqId()) { | |
376 | events << repositoryEvent; |
|
384 | events << repositoryEvent; | |
377 | } |
|
385 | } | |
378 | } |
|
386 | } | |
379 | } |
|
387 | } | |
380 | } |
|
388 | } | |
381 |
|
389 | |||
382 | return events; |
|
390 | return events; | |
383 | } |
|
391 | } | |
384 |
|
392 | |||
385 | QByteArray CatalogueController::mimeDataForCatalogues( |
|
393 | QByteArray CatalogueController::mimeDataForCatalogues( | |
386 | const QVector<std::shared_ptr<DBCatalogue> > &catalogues) const |
|
394 | const QVector<std::shared_ptr<DBCatalogue> > &catalogues) const | |
387 | { |
|
395 | { | |
388 | auto encodedData = QByteArray{}; |
|
396 | auto encodedData = QByteArray{}; | |
389 |
|
397 | |||
390 | QMap<QString, QVariantList> idsPerRepository; |
|
398 | QMap<QString, QVariantList> idsPerRepository; | |
391 | for (auto catalogue : catalogues) { |
|
399 | for (auto catalogue : catalogues) { | |
392 | idsPerRepository[catalogue->getRepository()] << catalogue->getUniqId(); |
|
400 | idsPerRepository[catalogue->getRepository()] << catalogue->getUniqId(); | |
393 | } |
|
401 | } | |
394 |
|
402 | |||
395 | QDataStream stream{&encodedData, QIODevice::WriteOnly}; |
|
403 | QDataStream stream{&encodedData, QIODevice::WriteOnly}; | |
396 | stream << idsPerRepository; |
|
404 | stream << idsPerRepository; | |
397 |
|
405 | |||
398 | return encodedData; |
|
406 | return encodedData; | |
399 | } |
|
407 | } | |
400 |
|
408 | |||
401 | QVector<std::shared_ptr<DBCatalogue> > |
|
409 | QVector<std::shared_ptr<DBCatalogue> > | |
402 | CatalogueController::cataloguesForMimeData(const QByteArray &mimeData) const |
|
410 | CatalogueController::cataloguesForMimeData(const QByteArray &mimeData) const | |
403 | { |
|
411 | { | |
404 | auto catalogues = QVector<std::shared_ptr<DBCatalogue> >{}; |
|
412 | auto catalogues = QVector<std::shared_ptr<DBCatalogue> >{}; | |
405 | QDataStream stream{mimeData}; |
|
413 | QDataStream stream{mimeData}; | |
406 |
|
414 | |||
407 | QMap<QString, QVariantList> idsPerRepository; |
|
415 | QMap<QString, QVariantList> idsPerRepository; | |
408 | stream >> idsPerRepository; |
|
416 | stream >> idsPerRepository; | |
409 |
|
417 | |||
410 | for (auto it = idsPerRepository.cbegin(); it != idsPerRepository.cend(); ++it) { |
|
418 | for (auto it = idsPerRepository.cbegin(); it != idsPerRepository.cend(); ++it) { | |
411 | auto repository = it.key(); |
|
419 | auto repository = it.key(); | |
412 | auto allRepositoryCatalogues = retrieveCatalogues(repository); |
|
420 | auto allRepositoryCatalogues = retrieveCatalogues(repository); | |
413 | for (auto uuid : it.value()) { |
|
421 | for (auto uuid : it.value()) { | |
414 | for (auto repositoryCatalogues : allRepositoryCatalogues) { |
|
422 | for (auto repositoryCatalogues : allRepositoryCatalogues) { | |
415 | if (uuid.toUuid() == repositoryCatalogues->getUniqId()) { |
|
423 | if (uuid.toUuid() == repositoryCatalogues->getUniqId()) { | |
416 | catalogues << repositoryCatalogues; |
|
424 | catalogues << repositoryCatalogues; | |
417 | } |
|
425 | } | |
418 | } |
|
426 | } | |
419 | } |
|
427 | } | |
420 | } |
|
428 | } | |
421 |
|
429 | |||
422 | return catalogues; |
|
430 | return catalogues; | |
423 | } |
|
431 | } | |
424 |
|
432 | |||
425 | void CatalogueController::initialize() |
|
433 | void CatalogueController::initialize() | |
426 | { |
|
434 | { | |
427 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController init") |
|
435 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController init") | |
428 | << QThread::currentThread(); |
|
436 | << QThread::currentThread(); | |
429 |
|
437 | |||
430 | impl->m_CatalogueDao.initialize(); |
|
438 | impl->m_CatalogueDao.initialize(); | |
431 | auto defaultRepositoryLocation |
|
439 | auto defaultRepositoryLocation | |
432 | = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); |
|
440 | = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); | |
433 |
|
441 | |||
434 | QDir defaultRepositoryLocationDir; |
|
442 | QDir defaultRepositoryLocationDir; | |
435 | if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) { |
|
443 | if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) { | |
436 | defaultRepositoryLocationDir.cd(defaultRepositoryLocation); |
|
444 | defaultRepositoryLocationDir.cd(defaultRepositoryLocation); | |
437 | auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT); |
|
445 | auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT); | |
438 |
|
446 | |||
439 | qCInfo(LOG_CatalogueController()) << tr("Persistant data loading from: ") |
|
447 | qCInfo(LOG_CatalogueController()) << tr("Persistant data loading from: ") | |
440 | << defaultRepository; |
|
448 | << defaultRepository; | |
441 |
|
449 | |||
442 | QDir dbDir(defaultRepository); |
|
450 | QDir dbDir(defaultRepository); | |
443 | impl->m_RepositoryList << REPOSITORY_DEFAULT; |
|
451 | impl->m_RepositoryList << REPOSITORY_DEFAULT; | |
444 | if (dbDir.exists()) { |
|
452 | if (dbDir.exists()) { | |
445 | auto dirName = dbDir.dirName(); |
|
453 | auto dirName = dbDir.dirName(); | |
446 |
|
454 | |||
447 | if (impl->m_CatalogueDao.addDB(defaultRepository, dirName)) { |
|
455 | if (impl->m_CatalogueDao.addDB(defaultRepository, dirName)) { | |
448 | impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName)); |
|
456 | impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName)); | |
449 | } |
|
457 | } | |
450 | } |
|
458 | } | |
451 | else { |
|
459 | else { | |
452 | qCInfo(LOG_CatalogueController()) << tr("Initialisation of Default repository detected") |
|
460 | qCInfo(LOG_CatalogueController()) << tr("Initialisation of Default repository detected") | |
453 | << defaultRepository; |
|
461 | << defaultRepository; | |
454 | } |
|
462 | } | |
455 | } |
|
463 | } | |
456 | else { |
|
464 | else { | |
457 | qCWarning(LOG_CatalogueController()) |
|
465 | qCWarning(LOG_CatalogueController()) | |
458 | << tr("Cannot load the persistent default repository from ") |
|
466 | << tr("Cannot load the persistent default repository from ") | |
459 | << defaultRepositoryLocation; |
|
467 | << defaultRepositoryLocation; | |
460 | } |
|
468 | } | |
461 |
|
469 | |||
462 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END"); |
|
470 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END"); | |
463 | } |
|
471 | } | |
464 |
|
472 | |||
465 | QString CatalogueController::CatalogueControllerPrivate::eventUniqueKey( |
|
473 | QString CatalogueController::CatalogueControllerPrivate::eventUniqueKey( | |
466 | const std::shared_ptr<DBEvent> &event) const |
|
474 | const std::shared_ptr<DBEvent> &event) const | |
467 | { |
|
475 | { | |
468 | return event->getUniqId().toString().append(event->getRepository()); |
|
476 | return event->getUniqId().toString().append(event->getRepository()); | |
469 | } |
|
477 | } | |
470 |
|
478 | |||
471 | QString CatalogueController::CatalogueControllerPrivate::catalogueUniqueKey( |
|
479 | QString CatalogueController::CatalogueControllerPrivate::catalogueUniqueKey( | |
472 | const std::shared_ptr<DBCatalogue> &catalogue) const |
|
480 | const std::shared_ptr<DBCatalogue> &catalogue) const | |
473 | { |
|
481 | { | |
474 | return catalogue->getUniqId().toString().append(catalogue->getRepository()); |
|
482 | return catalogue->getUniqId().toString().append(catalogue->getRepository()); | |
475 | } |
|
483 | } | |
476 |
|
484 | |||
477 | void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom, |
|
485 | void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom, | |
478 | const QString &dbTo) |
|
486 | const QString &dbTo) | |
479 | { |
|
487 | { | |
480 | // auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{}; |
|
488 | // auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{}; | |
481 | auto catalogues = m_CatalogueDao.getCatalogues(dbFrom); |
|
489 | auto catalogues = m_CatalogueDao.getCatalogues(dbFrom); | |
482 | auto events = m_CatalogueDao.getEvents(dbFrom); |
|
490 | auto events = m_CatalogueDao.getEvents(dbFrom); | |
483 | for (auto catalogue : catalogues) { |
|
491 | for (auto catalogue : catalogues) { | |
484 | m_CatalogueDao.copyCatalogue(catalogue, dbTo, true); |
|
492 | m_CatalogueDao.copyCatalogue(catalogue, dbTo, true); | |
485 | } |
|
493 | } | |
486 |
|
494 | |||
487 | for (auto event : events) { |
|
495 | for (auto event : events) { | |
488 | m_CatalogueDao.copyEvent(event, dbTo, true); |
|
496 | m_CatalogueDao.copyEvent(event, dbTo, true); | |
489 | } |
|
497 | } | |
490 | } |
|
498 | } | |
491 |
|
499 | |||
492 | QString CatalogueController::CatalogueControllerPrivate::toWorkRepository(QString repository) |
|
500 | QString CatalogueController::CatalogueControllerPrivate::toWorkRepository(QString repository) | |
493 | { |
|
501 | { | |
494 | auto syncRepository = toSyncRepository(repository); |
|
502 | auto syncRepository = toSyncRepository(repository); | |
495 |
|
503 | |||
496 | return QString("%1%2").arg(syncRepository, REPOSITORY_WORK_SUFFIX); |
|
504 | return QString("%1%2").arg(syncRepository, REPOSITORY_WORK_SUFFIX); | |
497 | } |
|
505 | } | |
498 |
|
506 | |||
499 | QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QString repository) |
|
507 | QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QString repository) | |
500 | { |
|
508 | { | |
501 | auto syncRepository = repository; |
|
509 | auto syncRepository = repository; | |
502 | if (repository.endsWith(REPOSITORY_WORK_SUFFIX)) { |
|
510 | if (repository.endsWith(REPOSITORY_WORK_SUFFIX)) { | |
503 | syncRepository.remove(REPOSITORY_WORK_SUFFIX); |
|
511 | syncRepository.remove(REPOSITORY_WORK_SUFFIX); | |
504 | } |
|
512 | } | |
505 | else if (repository.endsWith(REPOSITORY_TRASH_SUFFIX)) { |
|
513 | else if (repository.endsWith(REPOSITORY_TRASH_SUFFIX)) { | |
506 | syncRepository.remove(REPOSITORY_TRASH_SUFFIX); |
|
514 | syncRepository.remove(REPOSITORY_TRASH_SUFFIX); | |
507 | } |
|
515 | } | |
508 | return syncRepository; |
|
516 | return syncRepository; | |
509 | } |
|
517 | } | |
510 |
|
518 | |||
511 | void CatalogueController::CatalogueControllerPrivate::savAllDB() |
|
519 | void CatalogueController::CatalogueControllerPrivate::savAllDB() | |
512 | { |
|
520 | { | |
513 | for (auto repository : m_RepositoryList) { |
|
521 | for (auto repository : m_RepositoryList) { | |
514 | auto defaultRepositoryLocation |
|
522 | auto defaultRepositoryLocation | |
515 | = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); |
|
523 | = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); | |
516 | m_CatalogueDao.saveDB(defaultRepositoryLocation, repository); |
|
524 | m_CatalogueDao.saveDB(defaultRepositoryLocation, repository); | |
517 | } |
|
525 | } | |
518 | } |
|
526 | } | |
519 |
|
527 | |||
520 | void CatalogueController::CatalogueControllerPrivate::saveEvent(std::shared_ptr<DBEvent> event, |
|
528 | void CatalogueController::CatalogueControllerPrivate::saveEvent(std::shared_ptr<DBEvent> event, | |
521 | bool persist) |
|
529 | bool persist) | |
522 | { |
|
530 | { | |
523 | m_CatalogueDao.copyEvent(*event, toSyncRepository(event->getRepository()), true); |
|
531 | m_CatalogueDao.copyEvent(*event, toSyncRepository(event->getRepository()), true); | |
524 | if (persist) { |
|
532 | if (persist) { | |
525 | savAllDB(); |
|
533 | savAllDB(); | |
526 | } |
|
534 | } | |
527 | } |
|
535 | } | |
528 |
|
536 | |||
529 | void CatalogueController::CatalogueControllerPrivate::saveCatalogue( |
|
537 | void CatalogueController::CatalogueControllerPrivate::saveCatalogue( | |
530 | std::shared_ptr<DBCatalogue> catalogue, bool persist) |
|
538 | std::shared_ptr<DBCatalogue> catalogue, bool persist) | |
531 | { |
|
539 | { | |
532 | m_CatalogueDao.copyCatalogue(*catalogue, toSyncRepository(catalogue->getRepository()), true); |
|
540 | m_CatalogueDao.copyCatalogue(*catalogue, toSyncRepository(catalogue->getRepository()), true); | |
533 | if (persist) { |
|
541 | if (persist) { | |
534 | savAllDB(); |
|
542 | savAllDB(); | |
535 | } |
|
543 | } | |
536 | } |
|
544 | } | |
537 |
|
545 | |||
538 | std::shared_ptr<IRequestPredicate> CatalogueController::CatalogueControllerPrivate::createFinder( |
|
546 | std::shared_ptr<IRequestPredicate> CatalogueController::CatalogueControllerPrivate::createFinder( | |
539 | const QUuid &uniqId, const QString &repository, DBType type) |
|
547 | const QUuid &uniqId, const QString &repository, DBType type) | |
540 | { |
|
548 | { | |
541 | // update catalogue parameter |
|
549 | // update catalogue parameter | |
542 | auto uniqIdPredicate = std::make_shared<ComparaisonPredicate>(QString{"uniqId"}, uniqId, |
|
550 | auto uniqIdPredicate = std::make_shared<ComparaisonPredicate>(QString{"uniqId"}, uniqId, | |
543 | ComparaisonOperation::EQUALEQUAL); |
|
551 | ComparaisonOperation::EQUALEQUAL); | |
544 |
|
552 | |||
545 | auto repositoryType = repository; |
|
553 | auto repositoryType = repository; | |
546 | switch (type) { |
|
554 | switch (type) { | |
547 | case DBType::SYNC: |
|
555 | case DBType::SYNC: | |
548 | repositoryType = toSyncRepository(repositoryType); |
|
556 | repositoryType = toSyncRepository(repositoryType); | |
549 | break; |
|
557 | break; | |
550 | case DBType::WORK: |
|
558 | case DBType::WORK: | |
551 | repositoryType = toWorkRepository(repositoryType); |
|
559 | repositoryType = toWorkRepository(repositoryType); | |
552 | break; |
|
560 | break; | |
553 | case DBType::TRASH: |
|
561 | case DBType::TRASH: | |
554 | default: |
|
562 | default: | |
555 | break; |
|
563 | break; | |
556 | } |
|
564 | } | |
557 |
|
565 | |||
558 | auto repositoryPredicate = std::make_shared<ComparaisonPredicate>( |
|
566 | auto repositoryPredicate = std::make_shared<ComparaisonPredicate>( | |
559 | QString{"repository"}, repositoryType, ComparaisonOperation::EQUALEQUAL); |
|
567 | QString{"repository"}, repositoryType, ComparaisonOperation::EQUALEQUAL); | |
560 |
|
568 | |||
561 | auto finderPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND); |
|
569 | auto finderPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND); | |
562 | finderPred->AddRequestPredicate(uniqIdPredicate); |
|
570 | finderPred->AddRequestPredicate(uniqIdPredicate); | |
563 | finderPred->AddRequestPredicate(repositoryPredicate); |
|
571 | finderPred->AddRequestPredicate(repositoryPredicate); | |
564 |
|
572 | |||
565 | return finderPred; |
|
573 | return finderPred; | |
566 | } |
|
574 | } |
@@ -1,71 +1,72 | |||||
1 | #ifndef SCIQLOP_CATALOGUEEVENTSWIDGET_H |
|
1 | #ifndef SCIQLOP_CATALOGUEEVENTSWIDGET_H | |
2 | #define SCIQLOP_CATALOGUEEVENTSWIDGET_H |
|
2 | #define SCIQLOP_CATALOGUEEVENTSWIDGET_H | |
3 |
|
3 | |||
4 | #include <Common/spimpl.h> |
|
4 | #include <Common/spimpl.h> | |
5 | #include <QLoggingCategory> |
|
5 | #include <QLoggingCategory> | |
6 | #include <QWidget> |
|
6 | #include <QWidget> | |
7 |
|
7 | |||
8 | class DBCatalogue; |
|
8 | class DBCatalogue; | |
9 | class DBEvent; |
|
9 | class DBEvent; | |
10 | class DBEventProduct; |
|
10 | class DBEventProduct; | |
11 | class VisualizationWidget; |
|
11 | class VisualizationWidget; | |
12 | class VisualizationSelectionZoneItem; |
|
12 | class VisualizationSelectionZoneItem; | |
13 |
|
13 | |||
14 | namespace Ui { |
|
14 | namespace Ui { | |
15 | class CatalogueEventsWidget; |
|
15 | class CatalogueEventsWidget; | |
16 | } |
|
16 | } | |
17 |
|
17 | |||
18 | Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueEventsWidget) |
|
18 | Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueEventsWidget) | |
19 |
|
19 | |||
20 | class CatalogueEventsWidget : public QWidget { |
|
20 | class CatalogueEventsWidget : public QWidget { | |
21 | Q_OBJECT |
|
21 | Q_OBJECT | |
22 |
|
22 | |||
23 | signals: |
|
23 | signals: | |
24 | void eventsSelected(const QVector<std::shared_ptr<DBEvent> > &event); |
|
24 | void eventsSelected(const QVector<std::shared_ptr<DBEvent> > &event); | |
25 | void eventsRemoved(const QVector<std::shared_ptr<DBEvent> > &event); |
|
25 | void eventsRemoved(const QVector<std::shared_ptr<DBEvent> > &event); | |
26 | void eventProductsSelected( |
|
26 | void eventProductsSelected( | |
27 | const QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > |
|
27 | const QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > | |
28 | &eventproducts); |
|
28 | &eventproducts); | |
29 | void selectionCleared(); |
|
29 | void selectionCleared(); | |
30 | void selectionZoneAdded(const std::shared_ptr<DBEvent> &event, const QString &productId, |
|
30 | void selectionZoneAdded(const std::shared_ptr<DBEvent> &event, const QString &productId, | |
31 | VisualizationSelectionZoneItem *selectionZone); |
|
31 | VisualizationSelectionZoneItem *selectionZone); | |
32 |
|
32 | |||
33 | void eventCataloguesModified(const QVector<std::shared_ptr<DBCatalogue> > &catalogues); |
|
33 | void eventCataloguesModified(const QVector<std::shared_ptr<DBCatalogue> > &catalogues); | |
34 |
|
34 | |||
35 | public: |
|
35 | public: | |
36 | explicit CatalogueEventsWidget(QWidget *parent = 0); |
|
36 | explicit CatalogueEventsWidget(QWidget *parent = 0); | |
37 | virtual ~CatalogueEventsWidget(); |
|
37 | virtual ~CatalogueEventsWidget(); | |
38 |
|
38 | |||
39 | void setVisualizationWidget(VisualizationWidget *visualization); |
|
39 | void setVisualizationWidget(VisualizationWidget *visualization); | |
40 |
|
40 | |||
41 | void addEvent(const std::shared_ptr<DBEvent> &event); |
|
41 | void addEvent(const std::shared_ptr<DBEvent> &event); | |
42 | void setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges); |
|
42 | void setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges); | |
|
43 | void setEventsChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges); | |||
43 |
|
44 | |||
44 | QVector<std::shared_ptr<DBCatalogue> > displayedCatalogues() const; |
|
45 | QVector<std::shared_ptr<DBCatalogue> > displayedCatalogues() const; | |
45 | bool isAllEventsDisplayed() const; |
|
46 | bool isAllEventsDisplayed() const; | |
46 | bool isEventDisplayed(const std::shared_ptr<DBEvent> &event) const; |
|
47 | bool isEventDisplayed(const std::shared_ptr<DBEvent> &event) const; | |
47 |
|
48 | |||
48 | void refreshEvent(const std::shared_ptr<DBEvent> &event); |
|
49 | void refreshEvent(const std::shared_ptr<DBEvent> &event); | |
49 |
|
50 | |||
50 | public slots: |
|
51 | public slots: | |
51 | void populateWithCatalogues(const QVector<std::shared_ptr<DBCatalogue> > &catalogues); |
|
52 | void populateWithCatalogues(const QVector<std::shared_ptr<DBCatalogue> > &catalogues); | |
52 | void populateWithAllEvents(); |
|
53 | void populateWithAllEvents(); | |
53 | void clear(); |
|
54 | void clear(); | |
54 | void refresh(); |
|
55 | void refresh(); | |
55 |
|
56 | |||
56 | // QWidget interface |
|
57 | // QWidget interface | |
57 | protected: |
|
58 | protected: | |
58 | void keyPressEvent(QKeyEvent *event); |
|
59 | void keyPressEvent(QKeyEvent *event); | |
59 |
|
60 | |||
60 |
|
61 | |||
61 | private: |
|
62 | private: | |
62 | Ui::CatalogueEventsWidget *ui; |
|
63 | Ui::CatalogueEventsWidget *ui; | |
63 |
|
64 | |||
64 | class CatalogueEventsWidgetPrivate; |
|
65 | class CatalogueEventsWidgetPrivate; | |
65 | spimpl::unique_impl_ptr<CatalogueEventsWidgetPrivate> impl; |
|
66 | spimpl::unique_impl_ptr<CatalogueEventsWidgetPrivate> impl; | |
66 |
|
67 | |||
67 | private slots: |
|
68 | private slots: | |
68 | void emitSelection(); |
|
69 | void emitSelection(); | |
69 | }; |
|
70 | }; | |
70 |
|
71 | |||
71 | #endif // SCIQLOP_CATALOGUEEVENTSWIDGET_H |
|
72 | #endif // SCIQLOP_CATALOGUEEVENTSWIDGET_H |
@@ -1,55 +1,56 | |||||
1 | #ifndef SCIQLOP_CATALOGUESIDEBARWIDGET_H |
|
1 | #ifndef SCIQLOP_CATALOGUESIDEBARWIDGET_H | |
2 | #define SCIQLOP_CATALOGUESIDEBARWIDGET_H |
|
2 | #define SCIQLOP_CATALOGUESIDEBARWIDGET_H | |
3 |
|
3 | |||
4 | #include <Common/spimpl.h> |
|
4 | #include <Common/spimpl.h> | |
5 | #include <QLoggingCategory> |
|
5 | #include <QLoggingCategory> | |
6 | #include <QTreeWidgetItem> |
|
6 | #include <QTreeWidgetItem> | |
7 | #include <QWidget> |
|
7 | #include <QWidget> | |
8 |
|
8 | |||
9 | class CatalogueAbstractTreeItem; |
|
9 | class CatalogueAbstractTreeItem; | |
10 | class DBCatalogue; |
|
10 | class DBCatalogue; | |
11 |
|
11 | |||
12 | namespace Ui { |
|
12 | namespace Ui { | |
13 | class CatalogueSideBarWidget; |
|
13 | class CatalogueSideBarWidget; | |
14 | } |
|
14 | } | |
15 |
|
15 | |||
16 | Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget) |
|
16 | Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget) | |
17 |
|
17 | |||
18 | class CatalogueSideBarWidget : public QWidget { |
|
18 | class CatalogueSideBarWidget : public QWidget { | |
19 | Q_OBJECT |
|
19 | Q_OBJECT | |
20 |
|
20 | |||
21 | signals: |
|
21 | signals: | |
22 | void catalogueSelected(const QVector<std::shared_ptr<DBCatalogue> > &catalogues); |
|
22 | void catalogueSelected(const QVector<std::shared_ptr<DBCatalogue> > &catalogues); | |
23 | void databaseSelected(const QStringList &databases); |
|
23 | void databaseSelected(const QStringList &databases); | |
24 | void allEventsSelected(); |
|
24 | void allEventsSelected(); | |
25 | void trashSelected(); |
|
25 | void trashSelected(); | |
26 | void selectionCleared(); |
|
26 | void selectionCleared(); | |
|
27 | void catalogueSaved(const std::shared_ptr<DBCatalogue> &catalogue); | |||
27 |
|
28 | |||
28 | public: |
|
29 | public: | |
29 | explicit CatalogueSideBarWidget(QWidget *parent = 0); |
|
30 | explicit CatalogueSideBarWidget(QWidget *parent = 0); | |
30 | virtual ~CatalogueSideBarWidget(); |
|
31 | virtual ~CatalogueSideBarWidget(); | |
31 |
|
32 | |||
32 | CatalogueAbstractTreeItem *addCatalogue(const std::shared_ptr<DBCatalogue> &catalogue, |
|
33 | CatalogueAbstractTreeItem *addCatalogue(const std::shared_ptr<DBCatalogue> &catalogue, | |
33 | const QString &repository); |
|
34 | const QString &repository); | |
34 | void setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue, bool hasChanges); |
|
35 | void setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue, bool hasChanges); | |
35 |
|
36 | |||
36 | QVector<std::shared_ptr<DBCatalogue> > getCatalogues(const QString &repository) const; |
|
37 | QVector<std::shared_ptr<DBCatalogue> > getCatalogues(const QString &repository) const; | |
37 |
|
38 | |||
38 | // QWidget interface |
|
39 | // QWidget interface | |
39 | protected: |
|
40 | protected: | |
40 | void keyPressEvent(QKeyEvent *event); |
|
41 | void keyPressEvent(QKeyEvent *event); | |
41 |
|
42 | |||
42 | private slots: |
|
43 | private slots: | |
43 | void emitSelection(); |
|
44 | void emitSelection(); | |
44 |
|
45 | |||
45 | private: |
|
46 | private: | |
46 | Ui::CatalogueSideBarWidget *ui; |
|
47 | Ui::CatalogueSideBarWidget *ui; | |
47 |
|
48 | |||
48 | class CatalogueSideBarWidgetPrivate; |
|
49 | class CatalogueSideBarWidgetPrivate; | |
49 | spimpl::unique_impl_ptr<CatalogueSideBarWidgetPrivate> impl; |
|
50 | spimpl::unique_impl_ptr<CatalogueSideBarWidgetPrivate> impl; | |
50 |
|
51 | |||
51 | private slots: |
|
52 | private slots: | |
52 | void onContextMenuRequested(const QPoint &pos); |
|
53 | void onContextMenuRequested(const QPoint &pos); | |
53 | }; |
|
54 | }; | |
54 |
|
55 | |||
55 | #endif // SCIQLOP_CATALOGUESIDEBARWIDGET_H |
|
56 | #endif // SCIQLOP_CATALOGUESIDEBARWIDGET_H |
@@ -1,200 +1,203 | |||||
1 | #include "Catalogue/CatalogueExplorer.h" |
|
1 | #include "Catalogue/CatalogueExplorer.h" | |
2 | #include "ui_CatalogueExplorer.h" |
|
2 | #include "ui_CatalogueExplorer.h" | |
3 |
|
3 | |||
4 | #include <Catalogue/CatalogueActionManager.h> |
|
4 | #include <Catalogue/CatalogueActionManager.h> | |
5 | #include <Catalogue/CatalogueController.h> |
|
5 | #include <Catalogue/CatalogueController.h> | |
6 | #include <SqpApplication.h> |
|
6 | #include <SqpApplication.h> | |
7 | #include <Visualization/VisualizationGraphWidget.h> |
|
7 | #include <Visualization/VisualizationGraphWidget.h> | |
8 | #include <Visualization/VisualizationSelectionZoneItem.h> |
|
8 | #include <Visualization/VisualizationSelectionZoneItem.h> | |
9 | #include <Visualization/VisualizationWidget.h> |
|
9 | #include <Visualization/VisualizationWidget.h> | |
10 |
|
10 | |||
11 | #include <DBCatalogue.h> |
|
11 | #include <DBCatalogue.h> | |
12 | #include <DBEvent.h> |
|
12 | #include <DBEvent.h> | |
13 | #include <DBEventProduct.h> |
|
13 | #include <DBEventProduct.h> | |
14 |
|
14 | |||
15 | #include <unordered_map> |
|
15 | #include <unordered_map> | |
16 |
|
16 | |||
17 | struct CatalogueExplorer::CatalogueExplorerPrivate { |
|
17 | struct CatalogueExplorer::CatalogueExplorerPrivate { | |
18 | CatalogueActionManager m_ActionManager; |
|
18 | CatalogueActionManager m_ActionManager; | |
19 | std::unordered_map<std::shared_ptr<DBEvent>, QVector<VisualizationSelectionZoneItem *> > |
|
19 | std::unordered_map<std::shared_ptr<DBEvent>, QVector<VisualizationSelectionZoneItem *> > | |
20 | m_SelectionZonesPerEvents; |
|
20 | m_SelectionZonesPerEvents; | |
21 |
|
21 | |||
22 | QMetaObject::Connection m_Conn; |
|
22 | QMetaObject::Connection m_Conn; | |
23 |
|
23 | |||
24 | CatalogueExplorerPrivate(CatalogueExplorer *catalogueExplorer) |
|
24 | CatalogueExplorerPrivate(CatalogueExplorer *catalogueExplorer) | |
25 | : m_ActionManager(catalogueExplorer) |
|
25 | : m_ActionManager(catalogueExplorer) | |
26 | { |
|
26 | { | |
27 | } |
|
27 | } | |
28 | }; |
|
28 | }; | |
29 |
|
29 | |||
30 | CatalogueExplorer::CatalogueExplorer(QWidget *parent) |
|
30 | CatalogueExplorer::CatalogueExplorer(QWidget *parent) | |
31 | : QDialog(parent, Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint), |
|
31 | : QDialog(parent, Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint), | |
32 | ui(new Ui::CatalogueExplorer), |
|
32 | ui(new Ui::CatalogueExplorer), | |
33 | impl{spimpl::make_unique_impl<CatalogueExplorerPrivate>(this)} |
|
33 | impl{spimpl::make_unique_impl<CatalogueExplorerPrivate>(this)} | |
34 | { |
|
34 | { | |
35 | ui->setupUi(this); |
|
35 | ui->setupUi(this); | |
36 |
|
36 | |||
37 | impl->m_ActionManager.installSelectionZoneActions(); |
|
37 | impl->m_ActionManager.installSelectionZoneActions(); | |
38 |
|
38 | |||
39 | // Updates events and inspector when something is selected in the catalogue widget |
|
39 | // Updates events and inspector when something is selected in the catalogue widget | |
40 | connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSelected, [this](auto catalogues) { |
|
40 | connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSelected, [this](auto catalogues) { | |
41 | if (catalogues.count() == 1) { |
|
41 | if (catalogues.count() == 1) { | |
42 | ui->inspector->setCatalogue(catalogues.first()); |
|
42 | ui->inspector->setCatalogue(catalogues.first()); | |
43 | } |
|
43 | } | |
44 | else { |
|
44 | else { | |
45 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); |
|
45 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
48 | ui->events->populateWithCatalogues(catalogues); |
|
48 | ui->events->populateWithCatalogues(catalogues); | |
49 | }); |
|
49 | }); | |
50 |
|
50 | |||
51 | connect(ui->catalogues, &CatalogueSideBarWidget::databaseSelected, [this](auto databases) { |
|
51 | connect(ui->catalogues, &CatalogueSideBarWidget::databaseSelected, [this](auto databases) { | |
52 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); |
|
52 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); | |
53 | }); |
|
53 | }); | |
54 |
|
54 | |||
55 | connect(ui->catalogues, &CatalogueSideBarWidget::trashSelected, [this]() { |
|
55 | connect(ui->catalogues, &CatalogueSideBarWidget::trashSelected, [this]() { | |
56 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); |
|
56 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); | |
57 | ui->events->clear(); |
|
57 | ui->events->clear(); | |
58 | }); |
|
58 | }); | |
59 |
|
59 | |||
60 | connect(ui->catalogues, &CatalogueSideBarWidget::allEventsSelected, [this]() { |
|
60 | connect(ui->catalogues, &CatalogueSideBarWidget::allEventsSelected, [this]() { | |
61 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); |
|
61 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); | |
62 | ui->events->populateWithAllEvents(); |
|
62 | ui->events->populateWithAllEvents(); | |
63 | }); |
|
63 | }); | |
64 |
|
64 | |||
65 | connect(ui->catalogues, &CatalogueSideBarWidget::databaseSelected, [this](auto databaseList) { |
|
65 | connect(ui->catalogues, &CatalogueSideBarWidget::databaseSelected, [this](auto databaseList) { | |
66 | QVector<std::shared_ptr<DBCatalogue> > catalogueList; |
|
66 | QVector<std::shared_ptr<DBCatalogue> > catalogueList; | |
67 | for (auto database : databaseList) { |
|
67 | for (auto database : databaseList) { | |
68 | catalogueList.append(ui->catalogues->getCatalogues(database)); |
|
68 | catalogueList.append(ui->catalogues->getCatalogues(database)); | |
69 | } |
|
69 | } | |
70 | ui->events->populateWithCatalogues(catalogueList); |
|
70 | ui->events->populateWithCatalogues(catalogueList); | |
71 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); |
|
71 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); | |
72 | }); |
|
72 | }); | |
73 |
|
73 | |||
74 | connect(ui->catalogues, &CatalogueSideBarWidget::selectionCleared, [this]() { |
|
74 | connect(ui->catalogues, &CatalogueSideBarWidget::selectionCleared, [this]() { | |
75 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); |
|
75 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); | |
76 | ui->events->clear(); |
|
76 | ui->events->clear(); | |
77 | }); |
|
77 | }); | |
78 |
|
78 | |||
|
79 | connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSaved, ui->events, | |||
|
80 | &CatalogueEventsWidget::refresh); | |||
|
81 | ||||
79 | // Updates the inspectot when something is selected in the events |
|
82 | // Updates the inspectot when something is selected in the events | |
80 | connect(ui->events, &CatalogueEventsWidget::eventsSelected, [this](auto events) { |
|
83 | connect(ui->events, &CatalogueEventsWidget::eventsSelected, [this](auto events) { | |
81 | if (events.count() == 1) { |
|
84 | if (events.count() == 1) { | |
82 | ui->inspector->setEvent(events.first()); |
|
85 | ui->inspector->setEvent(events.first()); | |
83 | } |
|
86 | } | |
84 | else { |
|
87 | else { | |
85 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); |
|
88 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); | |
86 | } |
|
89 | } | |
87 | }); |
|
90 | }); | |
88 |
|
91 | |||
89 | connect(ui->events, &CatalogueEventsWidget::eventProductsSelected, [this](auto eventProducts) { |
|
92 | connect(ui->events, &CatalogueEventsWidget::eventProductsSelected, [this](auto eventProducts) { | |
90 | if (eventProducts.count() == 1) { |
|
93 | if (eventProducts.count() == 1) { | |
91 | ui->inspector->setEventProduct(eventProducts.first().first, |
|
94 | ui->inspector->setEventProduct(eventProducts.first().first, | |
92 | eventProducts.first().second); |
|
95 | eventProducts.first().second); | |
93 | } |
|
96 | } | |
94 | else { |
|
97 | else { | |
95 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); |
|
98 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); | |
96 | } |
|
99 | } | |
97 | }); |
|
100 | }); | |
98 |
|
101 | |||
99 | connect(ui->events, &CatalogueEventsWidget::selectionCleared, |
|
102 | connect(ui->events, &CatalogueEventsWidget::selectionCleared, | |
100 | [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); }); |
|
103 | [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); }); | |
101 |
|
104 | |||
102 | // Manage Selection Zones associated to events |
|
105 | // Manage Selection Zones associated to events | |
103 | connect(ui->events, &CatalogueEventsWidget::selectionZoneAdded, |
|
106 | connect(ui->events, &CatalogueEventsWidget::selectionZoneAdded, | |
104 | [this](auto event, auto productId, auto zone) { |
|
107 | [this](auto event, auto productId, auto zone) { | |
105 | this->addSelectionZoneItem(event, productId, zone); |
|
108 | this->addSelectionZoneItem(event, productId, zone); | |
106 | }); |
|
109 | }); | |
107 |
|
110 | |||
108 | connect(ui->events, &CatalogueEventsWidget::eventsRemoved, [this](auto events) { |
|
111 | connect(ui->events, &CatalogueEventsWidget::eventsRemoved, [this](auto events) { | |
109 | for (auto event : events) { |
|
112 | for (auto event : events) { | |
110 | auto associatedSelectionZonesIt = impl->m_SelectionZonesPerEvents.find(event); |
|
113 | auto associatedSelectionZonesIt = impl->m_SelectionZonesPerEvents.find(event); | |
111 | if (associatedSelectionZonesIt != impl->m_SelectionZonesPerEvents.cend()) { |
|
114 | if (associatedSelectionZonesIt != impl->m_SelectionZonesPerEvents.cend()) { | |
112 | for (auto selectionZone : associatedSelectionZonesIt->second) { |
|
115 | for (auto selectionZone : associatedSelectionZonesIt->second) { | |
113 | auto parentGraph = selectionZone->parentGraphWidget(); |
|
116 | auto parentGraph = selectionZone->parentGraphWidget(); | |
114 | parentGraph->removeSelectionZone(selectionZone); |
|
117 | parentGraph->removeSelectionZone(selectionZone); | |
115 | } |
|
118 | } | |
116 |
|
119 | |||
117 | impl->m_SelectionZonesPerEvents.erase(event); |
|
120 | impl->m_SelectionZonesPerEvents.erase(event); | |
118 | } |
|
121 | } | |
119 | } |
|
122 | } | |
120 | }); |
|
123 | }); | |
121 |
|
124 | |||
122 | // Updates changes from the inspector |
|
125 | // Updates changes from the inspector | |
123 | connect(ui->inspector, &CatalogueInspectorWidget::catalogueUpdated, [this](auto catalogue) { |
|
126 | connect(ui->inspector, &CatalogueInspectorWidget::catalogueUpdated, [this](auto catalogue) { | |
124 | sqpApp->catalogueController().updateCatalogue(catalogue); |
|
127 | sqpApp->catalogueController().updateCatalogue(catalogue); | |
125 | ui->catalogues->setCatalogueChanges(catalogue, true); |
|
128 | ui->catalogues->setCatalogueChanges(catalogue, true); | |
126 | }); |
|
129 | }); | |
127 |
|
130 | |||
128 | connect(ui->inspector, &CatalogueInspectorWidget::eventUpdated, [this](auto event) { |
|
131 | connect(ui->inspector, &CatalogueInspectorWidget::eventUpdated, [this](auto event) { | |
129 | sqpApp->catalogueController().updateEvent(event); |
|
132 | sqpApp->catalogueController().updateEvent(event); | |
130 | ui->events->setEventChanges(event, true); |
|
133 | ui->events->setEventChanges(event, true); | |
131 | }); |
|
134 | }); | |
132 |
|
135 | |||
133 | connect(ui->inspector, &CatalogueInspectorWidget::eventProductUpdated, |
|
136 | connect(ui->inspector, &CatalogueInspectorWidget::eventProductUpdated, | |
134 | [this](auto event, auto eventProduct) { |
|
137 | [this](auto event, auto eventProduct) { | |
135 | sqpApp->catalogueController().updateEventProduct(eventProduct); |
|
138 | sqpApp->catalogueController().updateEventProduct(eventProduct); | |
136 | ui->events->setEventChanges(event, true); |
|
139 | ui->events->setEventChanges(event, true); | |
137 | }); |
|
140 | }); | |
138 |
|
141 | |||
139 | connect(ui->events, &CatalogueEventsWidget::eventCataloguesModified, |
|
142 | connect(ui->events, &CatalogueEventsWidget::eventCataloguesModified, | |
140 | [this](const QVector<std::shared_ptr<DBCatalogue> > &catalogues) { |
|
143 | [this](const QVector<std::shared_ptr<DBCatalogue> > &catalogues) { | |
141 | for (auto catalogue : catalogues) { |
|
144 | for (auto catalogue : catalogues) { | |
142 | ui->catalogues->setCatalogueChanges(catalogue, true); |
|
145 | ui->catalogues->setCatalogueChanges(catalogue, true); | |
143 | } |
|
146 | } | |
144 | }); |
|
147 | }); | |
145 | } |
|
148 | } | |
146 |
|
149 | |||
147 | CatalogueExplorer::~CatalogueExplorer() |
|
150 | CatalogueExplorer::~CatalogueExplorer() | |
148 | { |
|
151 | { | |
149 | disconnect(impl->m_Conn); |
|
152 | disconnect(impl->m_Conn); | |
150 | delete ui; |
|
153 | delete ui; | |
151 | } |
|
154 | } | |
152 |
|
155 | |||
153 | void CatalogueExplorer::setVisualizationWidget(VisualizationWidget *visualization) |
|
156 | void CatalogueExplorer::setVisualizationWidget(VisualizationWidget *visualization) | |
154 | { |
|
157 | { | |
155 | ui->events->setVisualizationWidget(visualization); |
|
158 | ui->events->setVisualizationWidget(visualization); | |
156 | } |
|
159 | } | |
157 |
|
160 | |||
158 | CatalogueEventsWidget &CatalogueExplorer::eventsWidget() const |
|
161 | CatalogueEventsWidget &CatalogueExplorer::eventsWidget() const | |
159 | { |
|
162 | { | |
160 | return *ui->events; |
|
163 | return *ui->events; | |
161 | } |
|
164 | } | |
162 |
|
165 | |||
163 | CatalogueSideBarWidget &CatalogueExplorer::sideBarWidget() const |
|
166 | CatalogueSideBarWidget &CatalogueExplorer::sideBarWidget() const | |
164 | { |
|
167 | { | |
165 | return *ui->catalogues; |
|
168 | return *ui->catalogues; | |
166 | } |
|
169 | } | |
167 |
|
170 | |||
168 | void CatalogueExplorer::clearSelectionZones() |
|
171 | void CatalogueExplorer::clearSelectionZones() | |
169 | { |
|
172 | { | |
170 | impl->m_SelectionZonesPerEvents.clear(); |
|
173 | impl->m_SelectionZonesPerEvents.clear(); | |
171 | } |
|
174 | } | |
172 |
|
175 | |||
173 | void CatalogueExplorer::addSelectionZoneItem(const std::shared_ptr<DBEvent> &event, |
|
176 | void CatalogueExplorer::addSelectionZoneItem(const std::shared_ptr<DBEvent> &event, | |
174 | const QString &productId, |
|
177 | const QString &productId, | |
175 | VisualizationSelectionZoneItem *selectionZone) |
|
178 | VisualizationSelectionZoneItem *selectionZone) | |
176 | { |
|
179 | { | |
177 | impl->m_SelectionZonesPerEvents[event] << selectionZone; |
|
180 | impl->m_SelectionZonesPerEvents[event] << selectionZone; | |
178 | connect(selectionZone, &VisualizationSelectionZoneItem::rangeEdited, |
|
181 | connect(selectionZone, &VisualizationSelectionZoneItem::rangeEdited, | |
179 | [event, productId, this](auto range) { |
|
182 | [event, productId, this](auto range) { | |
180 | auto productList = event->getEventProducts(); |
|
183 | auto productList = event->getEventProducts(); | |
181 | for (auto &product : productList) { |
|
184 | for (auto &product : productList) { | |
182 | if (product.getProductId() == productId) { |
|
185 | if (product.getProductId() == productId) { | |
183 | product.setTStart(range.m_TStart); |
|
186 | product.setTStart(range.m_TStart); | |
184 | product.setTEnd(range.m_TEnd); |
|
187 | product.setTEnd(range.m_TEnd); | |
185 | } |
|
188 | } | |
186 | } |
|
189 | } | |
187 | event->setEventProducts(productList); |
|
190 | event->setEventProducts(productList); | |
188 | sqpApp->catalogueController().updateEvent(event); |
|
191 | sqpApp->catalogueController().updateEvent(event); | |
189 | ui->events->refreshEvent(event); |
|
192 | ui->events->refreshEvent(event); | |
190 | ui->events->setEventChanges(event, true); |
|
193 | ui->events->setEventChanges(event, true); | |
191 | ui->inspector->refresh(); |
|
194 | ui->inspector->refresh(); | |
192 | }); |
|
195 | }); | |
193 |
|
196 | |||
194 | impl->m_Conn = connect(selectionZone, &VisualizationSelectionZoneItem::destroyed, |
|
197 | impl->m_Conn = connect(selectionZone, &VisualizationSelectionZoneItem::destroyed, | |
195 | [event, selectionZone, this]() { |
|
198 | [event, selectionZone, this]() { | |
196 | if (!impl->m_SelectionZonesPerEvents.empty()) { |
|
199 | if (!impl->m_SelectionZonesPerEvents.empty()) { | |
197 | impl->m_SelectionZonesPerEvents[event].removeAll(selectionZone); |
|
200 | impl->m_SelectionZonesPerEvents[event].removeAll(selectionZone); | |
198 | } |
|
201 | } | |
199 | }); |
|
202 | }); | |
200 | } |
|
203 | } |
@@ -1,442 +1,443 | |||||
1 | #include "Catalogue/CatalogueSideBarWidget.h" |
|
1 | #include "Catalogue/CatalogueSideBarWidget.h" | |
2 | #include "ui_CatalogueSideBarWidget.h" |
|
2 | #include "ui_CatalogueSideBarWidget.h" | |
3 | #include <SqpApplication.h> |
|
3 | #include <SqpApplication.h> | |
4 |
|
4 | |||
5 | #include <Catalogue/CatalogueController.h> |
|
5 | #include <Catalogue/CatalogueController.h> | |
6 | #include <Catalogue/CatalogueExplorerHelper.h> |
|
6 | #include <Catalogue/CatalogueExplorerHelper.h> | |
7 | #include <Catalogue/CatalogueTreeItems/CatalogueTextTreeItem.h> |
|
7 | #include <Catalogue/CatalogueTreeItems/CatalogueTextTreeItem.h> | |
8 | #include <Catalogue/CatalogueTreeItems/CatalogueTreeItem.h> |
|
8 | #include <Catalogue/CatalogueTreeItems/CatalogueTreeItem.h> | |
9 | #include <Catalogue/CatalogueTreeModel.h> |
|
9 | #include <Catalogue/CatalogueTreeModel.h> | |
10 | #include <CatalogueDao.h> |
|
10 | #include <CatalogueDao.h> | |
11 | #include <Common/MimeTypesDef.h> |
|
11 | #include <Common/MimeTypesDef.h> | |
12 | #include <ComparaisonPredicate.h> |
|
12 | #include <ComparaisonPredicate.h> | |
13 | #include <DBCatalogue.h> |
|
13 | #include <DBCatalogue.h> | |
14 |
|
14 | |||
15 | #include <QKeyEvent> |
|
15 | #include <QKeyEvent> | |
16 | #include <QMenu> |
|
16 | #include <QMenu> | |
17 | #include <QMessageBox> |
|
17 | #include <QMessageBox> | |
18 | #include <QMimeData> |
|
18 | #include <QMimeData> | |
19 |
|
19 | |||
20 | Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget") |
|
20 | Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget") | |
21 |
|
21 | |||
22 |
|
22 | |||
23 | constexpr auto ALL_EVENT_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 1; |
|
23 | constexpr auto ALL_EVENT_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 1; | |
24 | constexpr auto TRASH_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 2; |
|
24 | constexpr auto TRASH_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 2; | |
25 | constexpr auto CATALOGUE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 3; |
|
25 | constexpr auto CATALOGUE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 3; | |
26 | constexpr auto DATABASE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 4; |
|
26 | constexpr auto DATABASE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 4; | |
27 |
|
27 | |||
28 |
|
28 | |||
29 | struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate { |
|
29 | struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate { | |
30 |
|
30 | |||
31 | CatalogueTreeModel *m_TreeModel = nullptr; |
|
31 | CatalogueTreeModel *m_TreeModel = nullptr; | |
32 |
|
32 | |||
33 | void configureTreeWidget(QTreeView *treeView); |
|
33 | void configureTreeWidget(QTreeView *treeView); | |
34 | QModelIndex addDatabaseItem(const QString &name); |
|
34 | QModelIndex addDatabaseItem(const QString &name); | |
35 | CatalogueAbstractTreeItem *getDatabaseItem(const QString &name); |
|
35 | CatalogueAbstractTreeItem *getDatabaseItem(const QString &name); | |
36 | CatalogueAbstractTreeItem *addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue, |
|
36 | CatalogueAbstractTreeItem *addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue, | |
37 | const QModelIndex &databaseIndex); |
|
37 | const QModelIndex &databaseIndex); | |
38 |
|
38 | |||
39 | CatalogueTreeItem *getCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue) const; |
|
39 | CatalogueTreeItem *getCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue) const; | |
40 | void setHasChanges(bool value, const QModelIndex &index, CatalogueSideBarWidget *sideBarWidget); |
|
40 | void setHasChanges(bool value, const QModelIndex &index, CatalogueSideBarWidget *sideBarWidget); | |
41 | bool hasChanges(const QModelIndex &index, QTreeView *treeView); |
|
41 | bool hasChanges(const QModelIndex &index, QTreeView *treeView); | |
42 |
|
42 | |||
43 | int selectionType(QTreeView *treeView) const |
|
43 | int selectionType(QTreeView *treeView) const | |
44 | { |
|
44 | { | |
45 | auto selectedItems = treeView->selectionModel()->selectedRows(); |
|
45 | auto selectedItems = treeView->selectionModel()->selectedRows(); | |
46 | if (selectedItems.isEmpty()) { |
|
46 | if (selectedItems.isEmpty()) { | |
47 | return CatalogueAbstractTreeItem::DEFAULT_TYPE; |
|
47 | return CatalogueAbstractTreeItem::DEFAULT_TYPE; | |
48 | } |
|
48 | } | |
49 | else { |
|
49 | else { | |
50 | auto firstIndex = selectedItems.first(); |
|
50 | auto firstIndex = selectedItems.first(); | |
51 | auto firstItem = m_TreeModel->item(firstIndex); |
|
51 | auto firstItem = m_TreeModel->item(firstIndex); | |
52 | if (!firstItem) { |
|
52 | if (!firstItem) { | |
53 | Q_ASSERT(false); |
|
53 | Q_ASSERT(false); | |
54 | return CatalogueAbstractTreeItem::DEFAULT_TYPE; |
|
54 | return CatalogueAbstractTreeItem::DEFAULT_TYPE; | |
55 | } |
|
55 | } | |
56 | auto selectionType = firstItem->type(); |
|
56 | auto selectionType = firstItem->type(); | |
57 |
|
57 | |||
58 | for (auto itemIndex : selectedItems) { |
|
58 | for (auto itemIndex : selectedItems) { | |
59 | auto item = m_TreeModel->item(itemIndex); |
|
59 | auto item = m_TreeModel->item(itemIndex); | |
60 | if (!item || item->type() != selectionType) { |
|
60 | if (!item || item->type() != selectionType) { | |
61 | // Incoherent multi selection |
|
61 | // Incoherent multi selection | |
62 | selectionType = CatalogueAbstractTreeItem::DEFAULT_TYPE; |
|
62 | selectionType = CatalogueAbstractTreeItem::DEFAULT_TYPE; | |
63 | break; |
|
63 | break; | |
64 | } |
|
64 | } | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | return selectionType; |
|
67 | return selectionType; | |
68 | } |
|
68 | } | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | QVector<std::shared_ptr<DBCatalogue> > selectedCatalogues(QTreeView *treeView) const |
|
71 | QVector<std::shared_ptr<DBCatalogue> > selectedCatalogues(QTreeView *treeView) const | |
72 | { |
|
72 | { | |
73 | QVector<std::shared_ptr<DBCatalogue> > catalogues; |
|
73 | QVector<std::shared_ptr<DBCatalogue> > catalogues; | |
74 | auto selectedItems = treeView->selectionModel()->selectedRows(); |
|
74 | auto selectedItems = treeView->selectionModel()->selectedRows(); | |
75 | for (auto itemIndex : selectedItems) { |
|
75 | for (auto itemIndex : selectedItems) { | |
76 | auto item = m_TreeModel->item(itemIndex); |
|
76 | auto item = m_TreeModel->item(itemIndex); | |
77 | if (item && item->type() == CATALOGUE_ITEM_TYPE) { |
|
77 | if (item && item->type() == CATALOGUE_ITEM_TYPE) { | |
78 | catalogues.append(static_cast<CatalogueTreeItem *>(item)->catalogue()); |
|
78 | catalogues.append(static_cast<CatalogueTreeItem *>(item)->catalogue()); | |
79 | } |
|
79 | } | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | return catalogues; |
|
82 | return catalogues; | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | QStringList selectedRepositories(QTreeView *treeView) const |
|
85 | QStringList selectedRepositories(QTreeView *treeView) const | |
86 | { |
|
86 | { | |
87 | QStringList repositories; |
|
87 | QStringList repositories; | |
88 | auto selectedItems = treeView->selectionModel()->selectedRows(); |
|
88 | auto selectedItems = treeView->selectionModel()->selectedRows(); | |
89 | for (auto itemIndex : selectedItems) { |
|
89 | for (auto itemIndex : selectedItems) { | |
90 | auto item = m_TreeModel->item(itemIndex); |
|
90 | auto item = m_TreeModel->item(itemIndex); | |
91 | if (item && item->type() == DATABASE_ITEM_TYPE) { |
|
91 | if (item && item->type() == DATABASE_ITEM_TYPE) { | |
92 | repositories.append(item->text()); |
|
92 | repositories.append(item->text()); | |
93 | } |
|
93 | } | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | return repositories; |
|
96 | return repositories; | |
97 | } |
|
97 | } | |
98 | }; |
|
98 | }; | |
99 |
|
99 | |||
100 | CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent) |
|
100 | CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent) | |
101 | : QWidget(parent), |
|
101 | : QWidget(parent), | |
102 | ui(new Ui::CatalogueSideBarWidget), |
|
102 | ui(new Ui::CatalogueSideBarWidget), | |
103 | impl{spimpl::make_unique_impl<CatalogueSideBarWidgetPrivate>()} |
|
103 | impl{spimpl::make_unique_impl<CatalogueSideBarWidgetPrivate>()} | |
104 | { |
|
104 | { | |
105 | ui->setupUi(this); |
|
105 | ui->setupUi(this); | |
106 |
|
106 | |||
107 | impl->m_TreeModel = new CatalogueTreeModel(this); |
|
107 | impl->m_TreeModel = new CatalogueTreeModel(this); | |
108 | ui->treeView->setModel(impl->m_TreeModel); |
|
108 | ui->treeView->setModel(impl->m_TreeModel); | |
109 |
|
109 | |||
110 | impl->configureTreeWidget(ui->treeView); |
|
110 | impl->configureTreeWidget(ui->treeView); | |
111 |
|
111 | |||
112 | ui->treeView->header()->setStretchLastSection(false); |
|
112 | ui->treeView->header()->setStretchLastSection(false); | |
113 | ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); |
|
113 | ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); | |
114 | ui->treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch); |
|
114 | ui->treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch); | |
115 |
|
115 | |||
116 | connect(ui->treeView, &QTreeView::clicked, this, &CatalogueSideBarWidget::emitSelection); |
|
116 | connect(ui->treeView, &QTreeView::clicked, this, &CatalogueSideBarWidget::emitSelection); | |
117 | connect(ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, this, |
|
117 | connect(ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, this, | |
118 | &CatalogueSideBarWidget::emitSelection); |
|
118 | &CatalogueSideBarWidget::emitSelection); | |
119 |
|
119 | |||
120 |
|
120 | |||
121 | connect(ui->btnAdd, &QToolButton::clicked, [this]() { |
|
121 | connect(ui->btnAdd, &QToolButton::clicked, [this]() { | |
122 | auto catalogue = std::make_shared<DBCatalogue>(); |
|
122 | auto catalogue = std::make_shared<DBCatalogue>(); | |
123 | catalogue->setName(QString("Cat")); |
|
123 | catalogue->setName(QString("Cat")); | |
124 | sqpApp->catalogueController().addCatalogue(catalogue); |
|
124 | sqpApp->catalogueController().addCatalogue(catalogue); | |
125 | auto item = this->addCatalogue(catalogue, REPOSITORY_DEFAULT); |
|
125 | auto item = this->addCatalogue(catalogue, REPOSITORY_DEFAULT); | |
126 | this->setCatalogueChanges(catalogue, true); |
|
126 | this->setCatalogueChanges(catalogue, true); | |
127 | ui->treeView->edit(impl->m_TreeModel->indexOf(item)); |
|
127 | ui->treeView->edit(impl->m_TreeModel->indexOf(item)); | |
128 |
|
128 | |||
129 | }); |
|
129 | }); | |
130 |
|
130 | |||
131 |
|
131 | |||
132 | connect(impl->m_TreeModel, &CatalogueTreeModel::itemDropped, |
|
132 | connect(impl->m_TreeModel, &CatalogueTreeModel::itemDropped, | |
133 | [this](auto index, auto mimeData, auto action) { |
|
133 | [this](auto index, auto mimeData, auto action) { | |
134 | auto item = impl->m_TreeModel->item(index); |
|
134 | auto item = impl->m_TreeModel->item(index); | |
135 | if (item && item->type() == CATALOGUE_ITEM_TYPE) { |
|
135 | if (item && item->type() == CATALOGUE_ITEM_TYPE) { | |
136 | auto catalogue = static_cast<CatalogueTreeItem *>(item)->catalogue(); |
|
136 | auto catalogue = static_cast<CatalogueTreeItem *>(item)->catalogue(); | |
137 | this->setCatalogueChanges(catalogue, true); |
|
137 | this->setCatalogueChanges(catalogue, true); | |
138 | } |
|
138 | } | |
139 |
|
139 | |||
140 | if (action == Qt::MoveAction) { |
|
140 | if (action == Qt::MoveAction) { | |
141 | /// Display a save button on source catalogues |
|
141 | /// Display a save button on source catalogues | |
142 | auto sourceCatalogues = sqpApp->catalogueController().cataloguesForMimeData( |
|
142 | auto sourceCatalogues = sqpApp->catalogueController().cataloguesForMimeData( | |
143 | mimeData->data(MIME_TYPE_SOURCE_CATALOGUE_LIST)); |
|
143 | mimeData->data(MIME_TYPE_SOURCE_CATALOGUE_LIST)); | |
144 | for (auto catalogue : sourceCatalogues) { |
|
144 | for (auto catalogue : sourceCatalogues) { | |
145 | if (auto catalogueItem = impl->getCatalogueItem(catalogue)) { |
|
145 | if (auto catalogueItem = impl->getCatalogueItem(catalogue)) { | |
146 | this->setCatalogueChanges(catalogue, true); |
|
146 | this->setCatalogueChanges(catalogue, true); | |
147 | } |
|
147 | } | |
148 | } |
|
148 | } | |
149 | } |
|
149 | } | |
150 | }); |
|
150 | }); | |
151 |
|
151 | |||
152 | connect(ui->btnRemove, &QToolButton::clicked, [this]() { |
|
152 | connect(ui->btnRemove, &QToolButton::clicked, [this]() { | |
153 | QVector<QPair<std::shared_ptr<DBCatalogue>, CatalogueAbstractTreeItem *> > |
|
153 | QVector<QPair<std::shared_ptr<DBCatalogue>, CatalogueAbstractTreeItem *> > | |
154 | cataloguesToItems; |
|
154 | cataloguesToItems; | |
155 | auto selectedIndexes = ui->treeView->selectionModel()->selectedRows(); |
|
155 | auto selectedIndexes = ui->treeView->selectionModel()->selectedRows(); | |
156 |
|
156 | |||
157 | for (auto index : selectedIndexes) { |
|
157 | for (auto index : selectedIndexes) { | |
158 | auto item = impl->m_TreeModel->item(index); |
|
158 | auto item = impl->m_TreeModel->item(index); | |
159 | if (item && item->type() == CATALOGUE_ITEM_TYPE) { |
|
159 | if (item && item->type() == CATALOGUE_ITEM_TYPE) { | |
160 | auto catalogue = static_cast<CatalogueTreeItem *>(item)->catalogue(); |
|
160 | auto catalogue = static_cast<CatalogueTreeItem *>(item)->catalogue(); | |
161 | cataloguesToItems << qMakePair(catalogue, item); |
|
161 | cataloguesToItems << qMakePair(catalogue, item); | |
162 | } |
|
162 | } | |
163 | } |
|
163 | } | |
164 |
|
164 | |||
165 | if (!cataloguesToItems.isEmpty()) { |
|
165 | if (!cataloguesToItems.isEmpty()) { | |
166 |
|
166 | |||
167 | if (QMessageBox::warning(this, tr("Remove Catalogue(s)"), |
|
167 | if (QMessageBox::warning(this, tr("Remove Catalogue(s)"), | |
168 | tr("The selected catalogues(s) will be completly removed " |
|
168 | tr("The selected catalogues(s) will be completly removed " | |
169 | "from the repository!\nAre you sure you want to continue?"), |
|
169 | "from the repository!\nAre you sure you want to continue?"), | |
170 | QMessageBox::Yes | QMessageBox::No, QMessageBox::No) |
|
170 | QMessageBox::Yes | QMessageBox::No, QMessageBox::No) | |
171 | == QMessageBox::Yes) { |
|
171 | == QMessageBox::Yes) { | |
172 |
|
172 | |||
173 | for (auto catalogueToItem : cataloguesToItems) { |
|
173 | for (auto catalogueToItem : cataloguesToItems) { | |
174 | sqpApp->catalogueController().removeCatalogue(catalogueToItem.first); |
|
174 | sqpApp->catalogueController().removeCatalogue(catalogueToItem.first); | |
175 | impl->m_TreeModel->removeChildItem( |
|
175 | impl->m_TreeModel->removeChildItem( | |
176 | catalogueToItem.second, |
|
176 | catalogueToItem.second, | |
177 | impl->m_TreeModel->indexOf(catalogueToItem.second->parent())); |
|
177 | impl->m_TreeModel->indexOf(catalogueToItem.second->parent())); | |
178 | } |
|
178 | } | |
179 | } |
|
179 | } | |
180 | } |
|
180 | } | |
181 | }); |
|
181 | }); | |
182 |
|
182 | |||
183 | connect(impl->m_TreeModel, &CatalogueTreeModel::itemRenamed, [this](auto index) { |
|
183 | connect(impl->m_TreeModel, &CatalogueTreeModel::itemRenamed, [this](auto index) { | |
184 | auto selectedIndexes = ui->treeView->selectionModel()->selectedRows(); |
|
184 | auto selectedIndexes = ui->treeView->selectionModel()->selectedRows(); | |
185 | if (selectedIndexes.contains(index)) { |
|
185 | if (selectedIndexes.contains(index)) { | |
186 | this->emitSelection(); |
|
186 | this->emitSelection(); | |
187 | } |
|
187 | } | |
188 | impl->setHasChanges(true, index, this); |
|
188 | impl->setHasChanges(true, index, this); | |
189 | }); |
|
189 | }); | |
190 |
|
190 | |||
191 | ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu); |
|
191 | ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu); | |
192 | connect(ui->treeView, &QTreeView::customContextMenuRequested, this, |
|
192 | connect(ui->treeView, &QTreeView::customContextMenuRequested, this, | |
193 | &CatalogueSideBarWidget::onContextMenuRequested); |
|
193 | &CatalogueSideBarWidget::onContextMenuRequested); | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | CatalogueSideBarWidget::~CatalogueSideBarWidget() |
|
196 | CatalogueSideBarWidget::~CatalogueSideBarWidget() | |
197 | { |
|
197 | { | |
198 | delete ui; |
|
198 | delete ui; | |
199 | } |
|
199 | } | |
200 |
|
200 | |||
201 | CatalogueAbstractTreeItem * |
|
201 | CatalogueAbstractTreeItem * | |
202 | CatalogueSideBarWidget::addCatalogue(const std::shared_ptr<DBCatalogue> &catalogue, |
|
202 | CatalogueSideBarWidget::addCatalogue(const std::shared_ptr<DBCatalogue> &catalogue, | |
203 | const QString &repository) |
|
203 | const QString &repository) | |
204 | { |
|
204 | { | |
205 | auto repositoryItem = impl->getDatabaseItem(repository); |
|
205 | auto repositoryItem = impl->getDatabaseItem(repository); | |
206 | return impl->addCatalogueItem(catalogue, impl->m_TreeModel->indexOf(repositoryItem)); |
|
206 | return impl->addCatalogueItem(catalogue, impl->m_TreeModel->indexOf(repositoryItem)); | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue, |
|
209 | void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue, | |
210 | bool hasChanges) |
|
210 | bool hasChanges) | |
211 | { |
|
211 | { | |
212 | if (auto catalogueItem = impl->getCatalogueItem(catalogue)) { |
|
212 | if (auto catalogueItem = impl->getCatalogueItem(catalogue)) { | |
213 | auto index = impl->m_TreeModel->indexOf(catalogueItem); |
|
213 | auto index = impl->m_TreeModel->indexOf(catalogueItem); | |
214 | impl->setHasChanges(hasChanges, index, this); |
|
214 | impl->setHasChanges(hasChanges, index, this); | |
215 | // catalogueItem->refresh(); |
|
215 | // catalogueItem->refresh(); | |
216 | } |
|
216 | } | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | QVector<std::shared_ptr<DBCatalogue> > |
|
219 | QVector<std::shared_ptr<DBCatalogue> > | |
220 | CatalogueSideBarWidget::getCatalogues(const QString &repository) const |
|
220 | CatalogueSideBarWidget::getCatalogues(const QString &repository) const | |
221 | { |
|
221 | { | |
222 | QVector<std::shared_ptr<DBCatalogue> > result; |
|
222 | QVector<std::shared_ptr<DBCatalogue> > result; | |
223 | auto repositoryItem = impl->getDatabaseItem(repository); |
|
223 | auto repositoryItem = impl->getDatabaseItem(repository); | |
224 | for (auto child : repositoryItem->children()) { |
|
224 | for (auto child : repositoryItem->children()) { | |
225 | if (child->type() == CATALOGUE_ITEM_TYPE) { |
|
225 | if (child->type() == CATALOGUE_ITEM_TYPE) { | |
226 | auto catalogueItem = static_cast<CatalogueTreeItem *>(child); |
|
226 | auto catalogueItem = static_cast<CatalogueTreeItem *>(child); | |
227 | result << catalogueItem->catalogue(); |
|
227 | result << catalogueItem->catalogue(); | |
228 | } |
|
228 | } | |
229 | else { |
|
229 | else { | |
230 | qCWarning(LOG_CatalogueSideBarWidget()) << "getCatalogues: invalid structure"; |
|
230 | qCWarning(LOG_CatalogueSideBarWidget()) << "getCatalogues: invalid structure"; | |
231 | } |
|
231 | } | |
232 | } |
|
232 | } | |
233 |
|
233 | |||
234 | return result; |
|
234 | return result; | |
235 | } |
|
235 | } | |
236 |
|
236 | |||
237 | void CatalogueSideBarWidget::emitSelection() |
|
237 | void CatalogueSideBarWidget::emitSelection() | |
238 | { |
|
238 | { | |
239 | auto selectionType = impl->selectionType(ui->treeView); |
|
239 | auto selectionType = impl->selectionType(ui->treeView); | |
240 |
|
240 | |||
241 | switch (selectionType) { |
|
241 | switch (selectionType) { | |
242 | case CATALOGUE_ITEM_TYPE: |
|
242 | case CATALOGUE_ITEM_TYPE: | |
243 | emit this->catalogueSelected(impl->selectedCatalogues(ui->treeView)); |
|
243 | emit this->catalogueSelected(impl->selectedCatalogues(ui->treeView)); | |
244 | break; |
|
244 | break; | |
245 | case DATABASE_ITEM_TYPE: |
|
245 | case DATABASE_ITEM_TYPE: | |
246 | emit this->databaseSelected(impl->selectedRepositories(ui->treeView)); |
|
246 | emit this->databaseSelected(impl->selectedRepositories(ui->treeView)); | |
247 | break; |
|
247 | break; | |
248 | case ALL_EVENT_ITEM_TYPE: |
|
248 | case ALL_EVENT_ITEM_TYPE: | |
249 | emit this->allEventsSelected(); |
|
249 | emit this->allEventsSelected(); | |
250 | break; |
|
250 | break; | |
251 | case TRASH_ITEM_TYPE: |
|
251 | case TRASH_ITEM_TYPE: | |
252 | emit this->trashSelected(); |
|
252 | emit this->trashSelected(); | |
253 | break; |
|
253 | break; | |
254 | default: |
|
254 | default: | |
255 | emit this->selectionCleared(); |
|
255 | emit this->selectionCleared(); | |
256 | break; |
|
256 | break; | |
257 | } |
|
257 | } | |
258 | } |
|
258 | } | |
259 |
|
259 | |||
260 | void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos) |
|
260 | void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos) | |
261 | { |
|
261 | { | |
262 | QMenu menu{this}; |
|
262 | QMenu menu{this}; | |
263 |
|
263 | |||
264 | auto currentIndex = ui->treeView->currentIndex(); |
|
264 | auto currentIndex = ui->treeView->currentIndex(); | |
265 | auto currentItem = impl->m_TreeModel->item(currentIndex); |
|
265 | auto currentItem = impl->m_TreeModel->item(currentIndex); | |
266 | if (!currentItem) { |
|
266 | if (!currentItem) { | |
267 | return; |
|
267 | return; | |
268 | } |
|
268 | } | |
269 |
|
269 | |||
270 | switch (currentItem->type()) { |
|
270 | switch (currentItem->type()) { | |
271 | case CATALOGUE_ITEM_TYPE: |
|
271 | case CATALOGUE_ITEM_TYPE: | |
272 | menu.addAction("Rename", [this, currentIndex]() { ui->treeView->edit(currentIndex); }); |
|
272 | menu.addAction("Rename", [this, currentIndex]() { ui->treeView->edit(currentIndex); }); | |
273 | break; |
|
273 | break; | |
274 | case DATABASE_ITEM_TYPE: |
|
274 | case DATABASE_ITEM_TYPE: | |
275 | break; |
|
275 | break; | |
276 | case ALL_EVENT_ITEM_TYPE: |
|
276 | case ALL_EVENT_ITEM_TYPE: | |
277 | break; |
|
277 | break; | |
278 | case TRASH_ITEM_TYPE: |
|
278 | case TRASH_ITEM_TYPE: | |
279 | menu.addAction("Empty Trash", []() { |
|
279 | menu.addAction("Empty Trash", []() { | |
280 | // TODO |
|
280 | // TODO | |
281 | }); |
|
281 | }); | |
282 | break; |
|
282 | break; | |
283 | default: |
|
283 | default: | |
284 | break; |
|
284 | break; | |
285 | } |
|
285 | } | |
286 |
|
286 | |||
287 | if (!menu.isEmpty()) { |
|
287 | if (!menu.isEmpty()) { | |
288 | menu.exec(ui->treeView->mapToGlobal(pos)); |
|
288 | menu.exec(ui->treeView->mapToGlobal(pos)); | |
289 | } |
|
289 | } | |
290 | } |
|
290 | } | |
291 |
|
291 | |||
292 | void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget(QTreeView *treeView) |
|
292 | void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget(QTreeView *treeView) | |
293 | { |
|
293 | { | |
294 | auto allEventsItem = new CatalogueTextTreeItem{QIcon{":/icones/allEvents.png"}, "All Events", |
|
294 | auto allEventsItem = new CatalogueTextTreeItem{QIcon{":/icones/allEvents.png"}, "All Events", | |
295 | ALL_EVENT_ITEM_TYPE}; |
|
295 | ALL_EVENT_ITEM_TYPE}; | |
296 | auto allEventIndex = m_TreeModel->addTopLevelItem(allEventsItem); |
|
296 | auto allEventIndex = m_TreeModel->addTopLevelItem(allEventsItem); | |
297 | treeView->setCurrentIndex(allEventIndex); |
|
297 | treeView->setCurrentIndex(allEventIndex); | |
298 |
|
298 | |||
299 | auto trashItem |
|
299 | auto trashItem | |
300 | = new CatalogueTextTreeItem{QIcon{":/icones/trash.png"}, "Trash", TRASH_ITEM_TYPE}; |
|
300 | = new CatalogueTextTreeItem{QIcon{":/icones/trash.png"}, "Trash", TRASH_ITEM_TYPE}; | |
301 | m_TreeModel->addTopLevelItem(trashItem); |
|
301 | m_TreeModel->addTopLevelItem(trashItem); | |
302 |
|
302 | |||
303 | auto separator = new QFrame{treeView}; |
|
303 | auto separator = new QFrame{treeView}; | |
304 | separator->setFrameShape(QFrame::HLine); |
|
304 | separator->setFrameShape(QFrame::HLine); | |
305 | auto separatorItem |
|
305 | auto separatorItem | |
306 | = new CatalogueTextTreeItem{QIcon{}, QString{}, CatalogueAbstractTreeItem::DEFAULT_TYPE}; |
|
306 | = new CatalogueTextTreeItem{QIcon{}, QString{}, CatalogueAbstractTreeItem::DEFAULT_TYPE}; | |
307 | separatorItem->setEnabled(false); |
|
307 | separatorItem->setEnabled(false); | |
308 | auto separatorIndex = m_TreeModel->addTopLevelItem(separatorItem); |
|
308 | auto separatorIndex = m_TreeModel->addTopLevelItem(separatorItem); | |
309 | treeView->setIndexWidget(separatorIndex, separator); |
|
309 | treeView->setIndexWidget(separatorIndex, separator); | |
310 |
|
310 | |||
311 | auto repositories = sqpApp->catalogueController().getRepositories(); |
|
311 | auto repositories = sqpApp->catalogueController().getRepositories(); | |
312 | for (auto dbname : repositories) { |
|
312 | for (auto dbname : repositories) { | |
313 | auto dbIndex = addDatabaseItem(dbname); |
|
313 | auto dbIndex = addDatabaseItem(dbname); | |
314 | auto catalogues = sqpApp->catalogueController().retrieveCatalogues(dbname); |
|
314 | auto catalogues = sqpApp->catalogueController().retrieveCatalogues(dbname); | |
315 | for (auto catalogue : catalogues) { |
|
315 | for (auto catalogue : catalogues) { | |
316 | addCatalogueItem(catalogue, dbIndex); |
|
316 | addCatalogueItem(catalogue, dbIndex); | |
317 | } |
|
317 | } | |
318 | } |
|
318 | } | |
319 |
|
319 | |||
320 | treeView->expandAll(); |
|
320 | treeView->expandAll(); | |
321 | } |
|
321 | } | |
322 |
|
322 | |||
323 | QModelIndex |
|
323 | QModelIndex | |
324 | CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name) |
|
324 | CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name) | |
325 | { |
|
325 | { | |
326 | auto databaseItem |
|
326 | auto databaseItem | |
327 | = new CatalogueTextTreeItem{QIcon{":/icones/database.png"}, {name}, DATABASE_ITEM_TYPE}; |
|
327 | = new CatalogueTextTreeItem{QIcon{":/icones/database.png"}, {name}, DATABASE_ITEM_TYPE}; | |
328 | auto databaseIndex = m_TreeModel->addTopLevelItem(databaseItem); |
|
328 | auto databaseIndex = m_TreeModel->addTopLevelItem(databaseItem); | |
329 |
|
329 | |||
330 | return databaseIndex; |
|
330 | return databaseIndex; | |
331 | } |
|
331 | } | |
332 |
|
332 | |||
333 | CatalogueAbstractTreeItem * |
|
333 | CatalogueAbstractTreeItem * | |
334 | CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QString &name) |
|
334 | CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QString &name) | |
335 | { |
|
335 | { | |
336 | for (auto item : m_TreeModel->topLevelItems()) { |
|
336 | for (auto item : m_TreeModel->topLevelItems()) { | |
337 | if (item->type() == DATABASE_ITEM_TYPE && item->text() == name) { |
|
337 | if (item->type() == DATABASE_ITEM_TYPE && item->text() == name) { | |
338 | return item; |
|
338 | return item; | |
339 | } |
|
339 | } | |
340 | } |
|
340 | } | |
341 |
|
341 | |||
342 | return nullptr; |
|
342 | return nullptr; | |
343 | } |
|
343 | } | |
344 |
|
344 | |||
345 | CatalogueAbstractTreeItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem( |
|
345 | CatalogueAbstractTreeItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem( | |
346 | const std::shared_ptr<DBCatalogue> &catalogue, const QModelIndex &databaseIndex) |
|
346 | const std::shared_ptr<DBCatalogue> &catalogue, const QModelIndex &databaseIndex) | |
347 | { |
|
347 | { | |
348 | auto catalogueItem |
|
348 | auto catalogueItem | |
349 | = new CatalogueTreeItem{catalogue, QIcon{":/icones/catalogue.png"}, CATALOGUE_ITEM_TYPE}; |
|
349 | = new CatalogueTreeItem{catalogue, QIcon{":/icones/catalogue.png"}, CATALOGUE_ITEM_TYPE}; | |
350 | m_TreeModel->addChildItem(catalogueItem, databaseIndex); |
|
350 | m_TreeModel->addChildItem(catalogueItem, databaseIndex); | |
351 |
|
351 | |||
352 | return catalogueItem; |
|
352 | return catalogueItem; | |
353 | } |
|
353 | } | |
354 |
|
354 | |||
355 | CatalogueTreeItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCatalogueItem( |
|
355 | CatalogueTreeItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCatalogueItem( | |
356 | const std::shared_ptr<DBCatalogue> &catalogue) const |
|
356 | const std::shared_ptr<DBCatalogue> &catalogue) const | |
357 | { |
|
357 | { | |
358 | for (auto item : m_TreeModel->topLevelItems()) { |
|
358 | for (auto item : m_TreeModel->topLevelItems()) { | |
359 | if (item->type() == DATABASE_ITEM_TYPE) { |
|
359 | if (item->type() == DATABASE_ITEM_TYPE) { | |
360 | for (auto childItem : item->children()) { |
|
360 | for (auto childItem : item->children()) { | |
361 | if (childItem->type() == CATALOGUE_ITEM_TYPE) { |
|
361 | if (childItem->type() == CATALOGUE_ITEM_TYPE) { | |
362 | auto catalogueItem = static_cast<CatalogueTreeItem *>(childItem); |
|
362 | auto catalogueItem = static_cast<CatalogueTreeItem *>(childItem); | |
363 | if (catalogueItem->catalogue()->getUniqId() == catalogue->getUniqId()) { |
|
363 | if (catalogueItem->catalogue()->getUniqId() == catalogue->getUniqId()) { | |
364 | return catalogueItem; |
|
364 | return catalogueItem; | |
365 | } |
|
365 | } | |
366 | } |
|
366 | } | |
367 | else { |
|
367 | else { | |
368 | qCWarning(LOG_CatalogueSideBarWidget()) << "getCatalogueItem: Invalid tree " |
|
368 | qCWarning(LOG_CatalogueSideBarWidget()) << "getCatalogueItem: Invalid tree " | |
369 | "structure. A database item should " |
|
369 | "structure. A database item should " | |
370 | "only contain catalogues."; |
|
370 | "only contain catalogues."; | |
371 | Q_ASSERT(false); |
|
371 | Q_ASSERT(false); | |
372 | } |
|
372 | } | |
373 | } |
|
373 | } | |
374 | } |
|
374 | } | |
375 | } |
|
375 | } | |
376 |
|
376 | |||
377 | return nullptr; |
|
377 | return nullptr; | |
378 | } |
|
378 | } | |
379 |
|
379 | |||
380 | void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::setHasChanges( |
|
380 | void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::setHasChanges( | |
381 | bool value, const QModelIndex &index, CatalogueSideBarWidget *sideBarWidget) |
|
381 | bool value, const QModelIndex &index, CatalogueSideBarWidget *sideBarWidget) | |
382 | { |
|
382 | { | |
383 | std::shared_ptr<DBCatalogue> catalogue = nullptr; |
|
383 | std::shared_ptr<DBCatalogue> catalogue = nullptr; | |
384 | auto item = m_TreeModel->item(index); |
|
384 | auto item = m_TreeModel->item(index); | |
385 | if (item && item->type() == CATALOGUE_ITEM_TYPE) { |
|
385 | if (item && item->type() == CATALOGUE_ITEM_TYPE) { | |
386 | catalogue = static_cast<CatalogueTreeItem *>(item)->catalogue(); |
|
386 | catalogue = static_cast<CatalogueTreeItem *>(item)->catalogue(); | |
387 | } |
|
387 | } | |
388 |
|
388 | |||
389 | auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation); |
|
389 | auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation); | |
390 | if (value) { |
|
390 | if (value) { | |
391 | if (!hasChanges(validationIndex, sideBarWidget->ui->treeView)) { |
|
391 | if (!hasChanges(validationIndex, sideBarWidget->ui->treeView)) { | |
392 | auto widget = CatalogueExplorerHelper::buildValidationWidget( |
|
392 | auto widget = CatalogueExplorerHelper::buildValidationWidget( | |
393 | sideBarWidget->ui->treeView, |
|
393 | sideBarWidget->ui->treeView, | |
394 | [this, validationIndex, sideBarWidget, catalogue]() { |
|
394 | [this, validationIndex, sideBarWidget, catalogue]() { | |
395 | if (catalogue) { |
|
395 | if (catalogue) { | |
396 | sqpApp->catalogueController().saveCatalogue(catalogue); |
|
396 | sqpApp->catalogueController().saveCatalogue(catalogue); | |
|
397 | emit sideBarWidget->catalogueSaved(catalogue); | |||
397 | } |
|
398 | } | |
398 | setHasChanges(false, validationIndex, sideBarWidget); |
|
399 | setHasChanges(false, validationIndex, sideBarWidget); | |
399 | }, |
|
400 | }, | |
400 | [this, validationIndex, sideBarWidget, catalogue, item]() { |
|
401 | [this, validationIndex, sideBarWidget, catalogue, item]() { | |
401 | if (catalogue) { |
|
402 | if (catalogue) { | |
402 | bool removed; |
|
403 | bool removed; | |
403 | sqpApp->catalogueController().discardCatalogue(catalogue, removed); |
|
404 | sqpApp->catalogueController().discardCatalogue(catalogue, removed); | |
404 |
|
405 | |||
405 | if (removed) { |
|
406 | if (removed) { | |
406 | m_TreeModel->removeChildItem(item, |
|
407 | m_TreeModel->removeChildItem(item, | |
407 | m_TreeModel->indexOf(item->parent())); |
|
408 | m_TreeModel->indexOf(item->parent())); | |
408 | } |
|
409 | } | |
409 | else { |
|
410 | else { | |
410 | m_TreeModel->refresh(m_TreeModel->indexOf(item)); |
|
411 | m_TreeModel->refresh(m_TreeModel->indexOf(item)); | |
411 | setHasChanges(false, validationIndex, sideBarWidget); |
|
412 | setHasChanges(false, validationIndex, sideBarWidget); | |
412 | } |
|
413 | } | |
413 | sideBarWidget->emitSelection(); |
|
414 | sideBarWidget->emitSelection(); | |
414 | } |
|
415 | } | |
415 | }); |
|
416 | }); | |
416 | sideBarWidget->ui->treeView->setIndexWidget(validationIndex, widget); |
|
417 | sideBarWidget->ui->treeView->setIndexWidget(validationIndex, widget); | |
417 | } |
|
418 | } | |
418 | } |
|
419 | } | |
419 | else { |
|
420 | else { | |
420 | // Note: the widget is destroyed |
|
421 | // Note: the widget is destroyed | |
421 | sideBarWidget->ui->treeView->setIndexWidget(validationIndex, nullptr); |
|
422 | sideBarWidget->ui->treeView->setIndexWidget(validationIndex, nullptr); | |
422 | } |
|
423 | } | |
423 | } |
|
424 | } | |
424 |
|
425 | |||
425 | bool CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::hasChanges(const QModelIndex &index, |
|
426 | bool CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::hasChanges(const QModelIndex &index, | |
426 | QTreeView *treeView) |
|
427 | QTreeView *treeView) | |
427 | { |
|
428 | { | |
428 | auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation); |
|
429 | auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation); | |
429 | return treeView->indexWidget(validationIndex) != nullptr; |
|
430 | return treeView->indexWidget(validationIndex) != nullptr; | |
430 | } |
|
431 | } | |
431 |
|
432 | |||
432 |
|
433 | |||
433 | void CatalogueSideBarWidget::keyPressEvent(QKeyEvent *event) |
|
434 | void CatalogueSideBarWidget::keyPressEvent(QKeyEvent *event) | |
434 | { |
|
435 | { | |
435 | switch (event->key()) { |
|
436 | switch (event->key()) { | |
436 | case Qt::Key_Delete: { |
|
437 | case Qt::Key_Delete: { | |
437 | ui->btnRemove->click(); |
|
438 | ui->btnRemove->click(); | |
438 | } |
|
439 | } | |
439 | default: |
|
440 | default: | |
440 | break; |
|
441 | break; | |
441 | } |
|
442 | } | |
442 | } |
|
443 | } |
General Comments 0
You need to be logged in to leave comments.
Login now