##// END OF EJS Templates
store events with changes in the catalogue controller
trabillard -
r1292:1ee6a92bae00
parent child
Show More
@@ -50,6 +50,7 public:
50 50 // void trashEvent(std::shared_ptr<DBEvent> event);
51 51 // void restore(QUuid eventId);
52 52 void saveEvent(std::shared_ptr<DBEvent> event);
53 bool eventHasChanges(std::shared_ptr<DBEvent> event) const;
53 54
54 55 // Catalogue
55 56 // bool createCatalogue(const QString &name, QVector<QUuid> eventList);
@@ -37,6 +37,10 public:
37 37 QStringList m_RepositoryList;
38 38 CatalogueController *m_Q;
39 39
40 QSet<QString> m_EventKeysWithChanges;
41
42 QString eventUniqueKey(const std::shared_ptr<DBEvent> &event) const;
43
40 44 void copyDBtoDB(const QString &dbFrom, const QString &dbTo);
41 45 QString toWorkRepository(QString repository);
42 46 QString toSyncRepository(QString repository);
@@ -137,6 +141,9 void CatalogueController::updateEvent(std::shared_ptr<DBEvent> event)
137 141 {
138 142 event->setRepository(impl->toWorkRepository(event->getRepository()));
139 143
144 auto uniqueId = impl->eventUniqueKey(event);
145 impl->m_EventKeysWithChanges.insert(uniqueId);
146
140 147 impl->m_CatalogueDao.updateEvent(*event);
141 148 }
142 149
@@ -180,6 +187,12 void CatalogueController::addEvent(std::shared_ptr<DBEvent> event)
180 187 void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event)
181 188 {
182 189 impl->saveEvent(event, true);
190 impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event));
191 }
192
193 bool CatalogueController::eventHasChanges(std::shared_ptr<DBEvent> event) const
194 {
195 return impl->m_EventKeysWithChanges.contains(impl->eventUniqueKey(event));
183 196 }
184 197
185 198 std::list<std::shared_ptr<DBCatalogue> >
@@ -233,6 +246,7 void CatalogueController::saveAll()
233 246 }
234 247
235 248 impl->savAllDB();
249 impl->m_EventKeysWithChanges.clear();
236 250 }
237 251
238 252 QByteArray
@@ -306,6 +320,12 void CatalogueController::initialize()
306 320 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END");
307 321 }
308 322
323 QString CatalogueController::CatalogueControllerPrivate::eventUniqueKey(
324 const std::shared_ptr<DBEvent> &event) const
325 {
326 return event->getUniqId().toString().append(event->getRepository());
327 }
328
309 329 void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom,
310 330 const QString &dbTo)
311 331 {
@@ -24,7 +24,6 const auto EVENT_PRODUCT_ITEM_TYPE = 2;
24 24 struct CatalogueEventsModel::CatalogueEventsModelPrivate {
25 25 QVector<std::shared_ptr<DBEvent> > m_Events;
26 26 std::unordered_map<DBEvent *, QVector<std::shared_ptr<DBEventProduct> > > m_EventProducts;
27 std::unordered_set<std::shared_ptr<DBEvent> > m_EventsWithChanges;
28 27
29 28 QStringList columnNames()
30 29 {
@@ -35,8 +34,8 struct CatalogueEventsModel::CatalogueEventsModelPrivate {
35 34 QVariant sortData(int col, const std::shared_ptr<DBEvent> &event) const
36 35 {
37 36 if (col == (int)CatalogueEventsModel::Column::Validation) {
38 return m_EventsWithChanges.find(event) != m_EventsWithChanges.cend() ? true
39 : QVariant();
37 auto hasChanges = sqpApp->catalogueController().eventHasChanges(event);
38 return hasChanges ? true : QVariant();
40 39 }
41 40
42 41 return eventData(col, event);
@@ -136,7 +135,6 void CatalogueEventsModel::setEvents(const QVector<std::shared_ptr<DBEvent> > &e
136 135
137 136 impl->m_Events = events;
138 137 impl->m_EventProducts.clear();
139 impl->m_EventsWithChanges.clear();
140 138 for (auto event : events) {
141 139 impl->parseEventProduct(event);
142 140 }
@@ -195,7 +193,6 void CatalogueEventsModel::removeEvent(const std::shared_ptr<DBEvent> &event)
195 193 beginRemoveRows(QModelIndex(), index, index);
196 194 impl->m_Events.removeAt(index);
197 195 impl->m_EventProducts.erase(event.get());
198 impl->m_EventsWithChanges.erase(event);
199 196 endRemoveRows();
200 197 }
201 198 }
@@ -232,22 +229,6 QModelIndex CatalogueEventsModel::indexOf(const std::shared_ptr<DBEvent> &event)
232 229 return QModelIndex();
233 230 }
234 231
235 void CatalogueEventsModel::setEventHasChanges(const std::shared_ptr<DBEvent> &event,
236 bool hasChanges)
237 {
238 if (hasChanges) {
239 impl->m_EventsWithChanges.insert(event);
240 }
241 else {
242 impl->m_EventsWithChanges.erase(event);
243 }
244 }
245
246 bool CatalogueEventsModel::eventsHasChanges(const std::shared_ptr<DBEvent> &event) const
247 {
248 return impl->m_EventsWithChanges.find(event) != impl->m_EventsWithChanges.cend();
249 }
250
251 232 QModelIndex CatalogueEventsModel::index(int row, int column, const QModelIndex &parent) const
252 233 {
253 234 if (!hasIndex(row, column, parent)) {
@@ -29,11 +29,18 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
29 29
30 30 VisualizationWidget *m_VisualizationWidget = nullptr;
31 31
32 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, QTreeView *treeView)
32 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, CatalogueEventsWidget *widget)
33 33 {
34 treeView->setSortingEnabled(false);
34 widget->ui->treeView->setSortingEnabled(false);
35 35 m_Model->setEvents(events);
36 treeView->setSortingEnabled(true);
36 widget->ui->treeView->setSortingEnabled(true);
37
38 for (auto event : events) {
39 if (sqpApp->catalogueController().eventHasChanges(event)) {
40 auto index = m_Model->indexOf(event);
41 widget->setEventChanges(event, true);
42 }
43 }
37 44 }
38 45
39 46 void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
@@ -290,7 +297,7 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
290 297 connect(impl->m_Model, &CatalogueEventsModel::modelSorted, [this]() {
291 298 auto allEvents = impl->m_Model->events();
292 299 for (auto event : allEvents) {
293 setEventChanges(event, impl->m_Model->eventsHasChanges(event));
300 setEventChanges(event, sqpApp->catalogueController().eventHasChanges(event));
294 301 }
295 302 });
296 303
@@ -332,8 +339,10 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &even
332 339 [this, event]() { setEventChanges(event, false); });
333 340 ui->treeView->setIndexWidget(validationIndex, widget);
334 341 }
335
336 impl->m_Model->setEventHasChanges(event, hasChanges);
342 }
343 else {
344 // Note: the widget is destroyed
345 ui->treeView->setIndexWidget(validationIndex, nullptr);
337 346 }
338 347 }
339 348 else {
@@ -375,7 +384,7 void CatalogueEventsWidget::populateWithCatalogues(
375 384 }
376 385 }
377 386
378 impl->setEvents(events, ui->treeView);
387 impl->setEvents(events, this);
379 388 }
380 389
381 390 void CatalogueEventsWidget::populateWithAllEvents()
@@ -389,13 +398,13 void CatalogueEventsWidget::populateWithAllEvents()
389 398 events << event;
390 399 }
391 400
392 impl->setEvents(events, ui->treeView);
401 impl->setEvents(events, this);
393 402 }
394 403
395 404 void CatalogueEventsWidget::clear()
396 405 {
397 406 impl->m_DisplayedCatalogues.clear();
398 impl->setEvents({}, ui->treeView);
407 impl->setEvents({}, this);
399 408 }
400 409
401 410 void CatalogueEventsWidget::refresh()
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved
author

Status change > Approved

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