##// END OF EJS Templates
fix refresh of events after a discard
trabillard -
r1277:e816f2c2a04c feature/Catalogue...
parent child
Show More
@@ -34,7 +34,7 public:
34 std::shared_ptr<DBEventProduct> getEventProduct(const QModelIndex &index) const;
34 std::shared_ptr<DBEventProduct> getEventProduct(const QModelIndex &index) const;
35
35
36 /// Refresh the data for the specified event
36 /// Refresh the data for the specified event
37 void refreshEvent(const std::shared_ptr<DBEvent> &event);
37 void refreshEvent(const std::shared_ptr<DBEvent> &event, bool refreshEventProducts = false);
38
38
39 /// Returns a QModelIndex which represent the specified event
39 /// Returns a QModelIndex which represent the specified event
40 QModelIndex indexOf(const std::shared_ptr<DBEvent> &event) const;
40 QModelIndex indexOf(const std::shared_ptr<DBEvent> &event) const;
@@ -50,6 +50,9 private:
50
50
51 class CatalogueEventsWidgetPrivate;
51 class CatalogueEventsWidgetPrivate;
52 spimpl::unique_impl_ptr<CatalogueEventsWidgetPrivate> impl;
52 spimpl::unique_impl_ptr<CatalogueEventsWidgetPrivate> impl;
53
54 private slots:
55 void emitSelection();
53 };
56 };
54
57
55 #endif // SCIQLOP_CATALOGUEEVENTSWIDGET_H
58 #endif // SCIQLOP_CATALOGUEEVENTSWIDGET_H
@@ -202,11 +202,35 QVector<std::shared_ptr<DBEvent> > CatalogueEventsModel::events() const
202 return impl->m_Events;
202 return impl->m_Events;
203 }
203 }
204
204
205 void CatalogueEventsModel::refreshEvent(const std::shared_ptr<DBEvent> &event)
205 void CatalogueEventsModel::refreshEvent(const std::shared_ptr<DBEvent> &event,
206 bool refreshEventProducts)
206 {
207 {
207 auto eventIndex = indexOf(event);
208 auto eventIndex = indexOf(event);
208 if (eventIndex.isValid()) {
209 if (eventIndex.isValid()) {
209
210
211 if (refreshEventProducts) {
212 // Reparse the associated event products
213
214 auto nbEventProducts = impl->nbEventProducts(event);
215 auto newNbOfEventProducts = event->getEventProducts().size();
216 if (newNbOfEventProducts < nbEventProducts) {
217 beginRemoveRows(eventIndex, newNbOfEventProducts, nbEventProducts - 1);
218 impl->m_EventProducts.erase(event.get());
219 impl->parseEventProduct(event);
220 endRemoveRows();
221 }
222 else if (newNbOfEventProducts > nbEventProducts) {
223 beginInsertRows(eventIndex, nbEventProducts, newNbOfEventProducts - 1);
224 impl->m_EventProducts.erase(event.get());
225 impl->parseEventProduct(event);
226 endInsertRows();
227 }
228 else { // newNbOfEventProducts == nbEventProducts
229 impl->m_EventProducts.erase(event.get());
230 impl->parseEventProduct(event);
231 }
232 }
233
210 // Refreshes the event line
234 // Refreshes the event line
211 auto colCount = columnCount();
235 auto colCount = columnCount();
212 emit dataChanged(eventIndex, index(eventIndex.row(), colCount));
236 emit dataChanged(eventIndex, index(eventIndex.row(), colCount));
@@ -280,24 +280,9 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
280 }
280 }
281 });
281 });
282
282
283 auto emitSelection = [this]() {
283 connect(ui->treeView, &QTreeView::clicked, this, &CatalogueEventsWidget::emitSelection);
284 QVector<std::shared_ptr<DBEvent> > events;
284 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
285 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
285 &CatalogueEventsWidget::emitSelection);
286 impl->getSelectedItems(ui->treeView, events, eventProducts);
287
288 if (!events.isEmpty() && eventProducts.isEmpty()) {
289 emit this->eventsSelected(events);
290 }
291 else if (events.isEmpty() && !eventProducts.isEmpty()) {
292 emit this->eventProductsSelected(eventProducts);
293 }
294 else {
295 emit this->selectionCleared();
296 }
297 };
298
299 connect(ui->treeView, &QTreeView::clicked, emitSelection);
300 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection);
301
286
302 ui->btnRemove->setEnabled(false); // Disabled by default when nothing is selected
287 ui->btnRemove->setEnabled(false); // Disabled by default when nothing is selected
303 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
288 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
@@ -374,7 +359,8 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &even
374 [this, event]() {
359 [this, event]() {
375 sqpApp->catalogueController().discardEvent(event);
360 sqpApp->catalogueController().discardEvent(event);
376 setEventChanges(event, false);
361 setEventChanges(event, false);
377 impl->m_Model->refreshEvent(event);
362 impl->m_Model->refreshEvent(event, true);
363 emitSelection();
378 });
364 });
379 ui->treeView->setIndexWidget(validationIndex, widget);
365 ui->treeView->setIndexWidget(validationIndex, widget);
380 }
366 }
@@ -455,3 +441,20 void CatalogueEventsWidget::refresh()
455 populateWithCatalogues(impl->m_DisplayedCatalogues);
441 populateWithCatalogues(impl->m_DisplayedCatalogues);
456 }
442 }
457 }
443 }
444
445 void CatalogueEventsWidget::emitSelection()
446 {
447 QVector<std::shared_ptr<DBEvent> > events;
448 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
449 impl->getSelectedItems(ui->treeView, events, eventProducts);
450
451 if (!events.isEmpty() && eventProducts.isEmpty()) {
452 emit eventsSelected(events);
453 }
454 else if (events.isEmpty() && !eventProducts.isEmpty()) {
455 emit eventProductsSelected(eventProducts);
456 }
457 else {
458 emit selectionCleared();
459 }
460 }
General Comments 0
You need to be logged in to leave comments. Login now