##// END OF EJS Templates
connect remove event button
trabillard -
r1296:8d5a04adee81
parent child
Show More
@@ -159,6 +159,7 void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event)
159 159 impl->m_CatalogueDao.removeEvent(*event);
160 160 event->setRepository(impl->toSyncRepository(event->getRepository()));
161 161 impl->m_CatalogueDao.removeEvent(*event);
162 impl->savAllDB();
162 163 }
163 164
164 165 void CatalogueController::addEvent(std::shared_ptr<DBEvent> event)
@@ -14,6 +14,7
14 14 #include <QDialog>
15 15 #include <QDialogButtonBox>
16 16 #include <QListWidget>
17 #include <QMessageBox>
17 18
18 19 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
19 20
@@ -203,6 +204,22 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
203 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 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 263 QVector<std::shared_ptr<DBEvent> > events;
247 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);
252 if (itemType == CatalogueEventsModel::ItemType::Event) {
253 events << impl->m_Model->getEvent(rowIndex);
254 }
255 else if (itemType == CatalogueEventsModel::ItemType::EventProduct) {
256 eventProducts << qMakePair(impl->m_Model->getParentEvent(rowIndex),
257 impl->m_Model->getEventProduct(rowIndex));
269 if (QMessageBox::warning(this, tr("Remove Event(s)"),
270 tr("The selected event(s) will be completly removed "
271 "from the repository!\nAre you sure you want to continue?"),
272 QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
273 == QMessageBox::Yes) {
274
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 288 if (!events.isEmpty() && eventProducts.isEmpty()) {
262 289 emit this->eventsSelected(events);
@@ -272,6 +299,7 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
272 299 connect(ui->treeView, &QTreeView::clicked, emitSelection);
273 300 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection);
274 301
302 ui->btnRemove->setEnabled(false); // Disabled by default when nothing is selected
275 303 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
276 304 auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1;
277 305 ui->btnChart->setEnabled(isNotMultiSelection);
@@ -283,6 +311,11 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
283 311 else if (isNotMultiSelection && ui->btnChart->isChecked()) {
284 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 321 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
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