Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/pageview.cpp
Show First 20 Lines • Show All 346 Lines • ▼ Show 20 Line(s) | |||||
347 | } | 347 | } | ||
348 | 348 | | |||
349 | void PageView::onRemoveItemRequested() | 349 | void PageView::onRemoveItemRequested() | ||
350 | { | 350 | { | ||
351 | const QModelIndexList ¤tIndexes = m_centralView->selectionModel()->selectedIndexes(); | 351 | const QModelIndexList ¤tIndexes = m_centralView->selectionModel()->selectedIndexes(); | ||
352 | if (currentIndexes.isEmpty()) | 352 | if (currentIndexes.isEmpty()) | ||
353 | return; | 353 | return; | ||
354 | 354 | | |||
355 | QString text; | 355 | auto indexHasChildren = [](QModelIndex index) { | ||
356 | if (currentIndexes.size() > 1) { | 356 | if (const QAbstractProxyModel *proxy = qobject_cast<const QAbstractProxyModel *>(index.model())) { | ||
357 | bool hasDescendants = false; | 357 | index = proxy->mapToSource(index); | ||
358 | foreach (const QModelIndex ¤tIndex, currentIndexes) { | | |||
359 | if (!currentIndex.isValid()) | | |||
360 | continue; | | |||
361 | | ||||
362 | if (currentIndex.model()->rowCount(currentIndex) > 0) { | | |||
363 | hasDescendants = true; | | |||
364 | break; | | |||
365 | } | | |||
366 | } | 358 | } | ||
359 | return index.model()->rowCount(index) > 0; | ||||
360 | }; | ||||
367 | 361 | | |||
362 | QString text; | ||||
363 | if (currentIndexes.size() > 1) { | ||||
364 | const bool hasDescendants = std::any_of(currentIndexes.constBegin(), currentIndexes.constEnd(), [&](const QModelIndex ¤tIndex) { | ||||
365 | return currentIndex.isValid() && indexHasChildren(currentIndex); }); | ||||
368 | if (hasDescendants) | 366 | if (hasDescendants) | ||
369 | text = i18n("Do you really want to delete the selected items and their children?"); | 367 | text = i18n("Do you really want to delete the selected items and their children?"); | ||
370 | else | 368 | else | ||
371 | text = i18n("Do you really want to delete the selected items?"); | 369 | text = i18n("Do you really want to delete the selected items?"); | ||
372 | 370 | | |||
373 | } else { | 371 | } else { | ||
374 | const QModelIndex ¤tIndex = currentIndexes.first(); | 372 | const QModelIndex ¤tIndex = currentIndexes.first(); | ||
375 | if (!currentIndex.isValid()) | 373 | if (!currentIndex.isValid()) | ||
376 | return; | 374 | return; | ||
377 | 375 | | |||
378 | if (currentIndex.model()->rowCount(currentIndex) > 0) | 376 | if (indexHasChildren(currentIndex)) | ||
379 | text = i18n("Do you really want to delete the selected task and all its children?"); | 377 | text = i18n("Do you really want to delete the selected task and all its children?"); | ||
380 | } | 378 | } | ||
381 | 379 | | |||
382 | if (!text.isEmpty()) { | 380 | if (!text.isEmpty()) { | ||
383 | QMessageBox::Button button = m_messageBoxInterface->askConfirmation(this, i18n("Delete Tasks"), text); | 381 | QMessageBox::Button button = m_messageBoxInterface->askConfirmation(this, i18n("Delete Tasks"), text); | ||
384 | bool canRemove = (button == QMessageBox::Yes); | 382 | bool canRemove = (button == QMessageBox::Yes); | ||
385 | 383 | | |||
386 | if (!canRemove) | 384 | if (!canRemove) | ||
▲ Show 20 Lines • Show All 102 Lines • Show Last 20 Lines |