Auto status change to "Under Review"
@@ -34,7 +34,7 public: | |||
|
34 | 34 | std::shared_ptr<DBEventProduct> getEventProduct(const QModelIndex &index) const; |
|
35 | 35 | |
|
36 | 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 | 39 | /// Returns a QModelIndex which represent the specified event |
|
40 | 40 | QModelIndex indexOf(const std::shared_ptr<DBEvent> &event) const; |
@@ -50,6 +50,9 private: | |||
|
50 | 50 | |
|
51 | 51 | class CatalogueEventsWidgetPrivate; |
|
52 | 52 | spimpl::unique_impl_ptr<CatalogueEventsWidgetPrivate> impl; |
|
53 | ||
|
54 | private slots: | |
|
55 | void emitSelection(); | |
|
53 | 56 | }; |
|
54 | 57 | |
|
55 | 58 | #endif // SCIQLOP_CATALOGUEEVENTSWIDGET_H |
@@ -202,11 +202,35 QVector<std::shared_ptr<DBEvent> > CatalogueEventsModel::events() const | |||
|
202 | 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 | 208 | auto eventIndex = indexOf(event); |
|
208 | 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 | 234 | // Refreshes the event line |
|
211 | 235 | auto colCount = columnCount(); |
|
212 | 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]() { | |
|
284 | QVector<std::shared_ptr<DBEvent> > events; | |
|
285 | QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts; | |
|
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); | |
|
283 | connect(ui->treeView, &QTreeView::clicked, this, &CatalogueEventsWidget::emitSelection); | |
|
284 | connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, | |
|
285 | &CatalogueEventsWidget::emitSelection); | |
|
301 | 286 | |
|
302 | 287 | ui->btnRemove->setEnabled(false); // Disabled by default when nothing is selected |
|
303 | 288 | connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() { |
@@ -374,7 +359,8 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &even | |||
|
374 | 359 | [this, event]() { |
|
375 | 360 | sqpApp->catalogueController().discardEvent(event); |
|
376 | 361 | setEventChanges(event, false); |
|
377 | impl->m_Model->refreshEvent(event); | |
|
362 | impl->m_Model->refreshEvent(event, true); | |
|
363 | emitSelection(); | |
|
378 | 364 | }); |
|
379 | 365 | ui->treeView->setIndexWidget(validationIndex, widget); |
|
380 | 366 | } |
@@ -455,3 +441,20 void CatalogueEventsWidget::refresh() | |||
|
455 | 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 3
Status change > Approved
You need to be logged in to leave comments.
Login now