Remove the selected items from the playlist tree widget and delete them
| 636 | |
| 637 | // Remove the selected items from the playlist tree widget and delete them |
| 638 | void PlaylistTreeWidget::deletePlaylistItems(bool deleteAllItems) |
| 639 | { |
| 640 | // First get all the items to process (top level or selected) |
| 641 | QList<playlistItem *> itemList; |
| 642 | if (deleteAllItems) |
| 643 | { |
| 644 | // Get all top level items |
| 645 | for (int i = 0; i < topLevelItemCount(); i++) |
| 646 | itemList.append(dynamic_cast<playlistItem *>(topLevelItem(i))); |
| 647 | } |
| 648 | else |
| 649 | { |
| 650 | // Get the selected items |
| 651 | QList<QTreeWidgetItem *> itemsList = selectedItems(); |
| 652 | for (QTreeWidgetItem *item : itemsList) |
| 653 | itemList.append(dynamic_cast<playlistItem *>(item)); |
| 654 | } |
| 655 | |
| 656 | // For all items, expand the items that contain children. However, do not add an item twice. |
| 657 | QList<playlistItem *> unfoldedItemList; |
| 658 | for (playlistItem *plItem : itemList) |
| 659 | { |
| 660 | playlistItemContainer *containerItem = dynamic_cast<playlistItemContainer *>(plItem); |
| 661 | if (containerItem) |
| 662 | { |
| 663 | // Add all children (if not yet in the list) |
| 664 | QList<playlistItem *> children = containerItem->takeAllChildItemsRecursive(); |
| 665 | for (playlistItem *child : children) |
| 666 | if (!unfoldedItemList.contains(child)) |
| 667 | unfoldedItemList.append(child); |
| 668 | } |
| 669 | |
| 670 | // Add the item itself (if not yet in the list) |
| 671 | if (!unfoldedItemList.contains(plItem)) |
| 672 | unfoldedItemList.append(plItem); |
| 673 | } |
| 674 | |
| 675 | // Is there anything to delete? |
| 676 | if (unfoldedItemList.count() == 0) |
| 677 | return; |
| 678 | |
| 679 | // Actually delete the items in the unfolded list |
| 680 | for (playlistItem *plItem : unfoldedItemList) |
| 681 | { |
| 682 | // Tag the item for deletion. This will disable loading/caching of the item. |
| 683 | plItem->tagItemForDeletion(); |
| 684 | |
| 685 | // If the item is in a container item we have to inform the container that the item will be |
| 686 | // deleted. |
| 687 | playlistItem *parentItem = plItem->parentPlaylistItem(); |
| 688 | if (parentItem) |
| 689 | parentItem->itemAboutToBeDeleted(plItem); |
| 690 | else |
| 691 | { |
| 692 | // The item has no parent. It is a top level item. |
| 693 | int topIdx = indexOfTopLevelItem(plItem); |
| 694 | if (topIdx != -1) |
| 695 | takeTopLevelItem(topIdx); |
no test coverage detected