@@ -159,6 +159,7 void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event) | |||||
159 | impl->m_CatalogueDao.removeEvent(*event); |
|
159 | impl->m_CatalogueDao.removeEvent(*event); | |
160 | event->setRepository(impl->toSyncRepository(event->getRepository())); |
|
160 | event->setRepository(impl->toSyncRepository(event->getRepository())); | |
161 | impl->m_CatalogueDao.removeEvent(*event); |
|
161 | impl->m_CatalogueDao.removeEvent(*event); | |
|
162 | impl->savAllDB(); | |||
162 | } |
|
163 | } | |
163 |
|
164 | |||
164 | void CatalogueController::addEvent(std::shared_ptr<DBEvent> event) |
|
165 | void CatalogueController::addEvent(std::shared_ptr<DBEvent> event) |
@@ -14,6 +14,7 | |||||
14 | #include <QDialog> |
|
14 | #include <QDialog> | |
15 | #include <QDialogButtonBox> |
|
15 | #include <QDialogButtonBox> | |
16 | #include <QListWidget> |
|
16 | #include <QListWidget> | |
|
17 | #include <QMessageBox> | |||
17 |
|
18 | |||
18 | Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget") |
|
19 | Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget") | |
19 |
|
20 | |||
@@ -203,6 +204,22 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate { | |||||
203 | << "updateGraphMode: not compatible with multiple events selected"; |
|
204 | << "updateGraphMode: not compatible with multiple events selected"; | |
204 | } |
|
205 | } | |
205 | } |
|
206 | } | |
|
207 | ||||
|
208 | void getSelectedItems( | |||
|
209 | QTreeView *treeView, QVector<std::shared_ptr<DBEvent> > &events, | |||
|
210 | QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > &eventProducts) | |||
|
211 | { | |||
|
212 | for (auto rowIndex : treeView->selectionModel()->selectedRows()) { | |||
|
213 | auto itemType = m_Model->itemTypeOf(rowIndex); | |||
|
214 | if (itemType == CatalogueEventsModel::ItemType::Event) { | |||
|
215 | events << m_Model->getEvent(rowIndex); | |||
|
216 | } | |||
|
217 | else if (itemType == CatalogueEventsModel::ItemType::EventProduct) { | |||
|
218 | eventProducts << qMakePair(m_Model->getParentEvent(rowIndex), | |||
|
219 | m_Model->getEventProduct(rowIndex)); | |||
|
220 | } | |||
|
221 | } | |||
|
222 | } | |||
206 | }; |
|
223 | }; | |
207 |
|
224 | |||
208 | CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent) |
|
225 | CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent) | |
@@ -242,21 +259,31 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent) | |||||
242 | } |
|
259 | } | |
243 | }); |
|
260 | }); | |
244 |
|
261 | |||
245 | auto emitSelection = [this]() { |
|
262 | connect(ui->btnRemove, &QToolButton::clicked, [this]() { | |
246 | QVector<std::shared_ptr<DBEvent> > events; |
|
263 | QVector<std::shared_ptr<DBEvent> > events; | |
247 | QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts; |
|
264 | QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts; | |
|
265 | impl->getSelectedItems(ui->treeView, events, eventProducts); | |||
248 |
|
266 | |||
249 | for (auto rowIndex : ui->treeView->selectionModel()->selectedRows()) { |
|
267 | if (!events.isEmpty() && eventProducts.isEmpty()) { | |
250 |
|
268 | |||
251 | auto itemType = impl->m_Model->itemTypeOf(rowIndex); |
|
269 | if (QMessageBox::warning(this, tr("Remove Event(s)"), | |
252 | if (itemType == CatalogueEventsModel::ItemType::Event) { |
|
270 | tr("The selected event(s) will be completly removed " | |
253 | events << impl->m_Model->getEvent(rowIndex); |
|
271 | "from the repository!\nAre you sure you want to continue?"), | |
254 | } |
|
272 | QMessageBox::Yes | QMessageBox::No, QMessageBox::No) | |
255 | else if (itemType == CatalogueEventsModel::ItemType::EventProduct) { |
|
273 | == QMessageBox::Yes) { | |
256 | eventProducts << qMakePair(impl->m_Model->getParentEvent(rowIndex), |
|
274 | ||
257 | impl->m_Model->getEventProduct(rowIndex)); |
|
275 | for (auto event : events) { | |
|
276 | sqpApp->catalogueController().removeEvent(event); | |||
|
277 | impl->removeEvent(event, ui->treeView); | |||
|
278 | } | |||
258 | } |
|
279 | } | |
259 | } |
|
280 | } | |
|
281 | }); | |||
|
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); | |||
260 |
|
287 | |||
261 | if (!events.isEmpty() && eventProducts.isEmpty()) { |
|
288 | if (!events.isEmpty() && eventProducts.isEmpty()) { | |
262 | emit this->eventsSelected(events); |
|
289 | emit this->eventsSelected(events); | |
@@ -272,6 +299,7 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent) | |||||
272 | connect(ui->treeView, &QTreeView::clicked, emitSelection); |
|
299 | connect(ui->treeView, &QTreeView::clicked, emitSelection); | |
273 | connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection); |
|
300 | connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection); | |
274 |
|
301 | |||
|
302 | ui->btnRemove->setEnabled(false); // Disabled by default when nothing is selected | |||
275 | connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() { |
|
303 | connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() { | |
276 | auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1; |
|
304 | auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1; | |
277 | ui->btnChart->setEnabled(isNotMultiSelection); |
|
305 | ui->btnChart->setEnabled(isNotMultiSelection); | |
@@ -283,6 +311,11 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent) | |||||
283 | else if (isNotMultiSelection && ui->btnChart->isChecked()) { |
|
311 | else if (isNotMultiSelection && ui->btnChart->isChecked()) { | |
284 | impl->updateForGraphMode(ui->treeView); |
|
312 | impl->updateForGraphMode(ui->treeView); | |
285 | } |
|
313 | } | |
|
314 | ||||
|
315 | QVector<std::shared_ptr<DBEvent> > events; | |||
|
316 | QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts; | |||
|
317 | impl->getSelectedItems(ui->treeView, events, eventProducts); | |||
|
318 | ui->btnRemove->setEnabled(!events.isEmpty() && eventProducts.isEmpty()); | |||
286 | }); |
|
319 | }); | |
287 |
|
320 | |||
288 | ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); |
|
321 | ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); |
General Comments 0
You need to be logged in to leave comments.
Login now