MCPcopy Create free account
hub / github.com/KDE/labplot / deleteSelected

Method deleteSelected

src/frontend/ProjectExplorer.cpp:900–955  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

898}
899
900void ProjectExplorer::deleteSelected() {
901 const auto& items = m_treeView->selectionModel()->selectedIndexes();
902 if (!items.size())
903 return;
904
905 // determine all selected aspects
906 QVector<AbstractAspect*> aspects;
907 const auto columnCount = m_treeView->model()->columnCount();
908 for (int i = 0; i < items.size() / columnCount; ++i) {
909 const QModelIndex& index = items.at(i * columnCount);
910 auto* aspect = static_cast<AbstractAspect*>(index.internalPointer());
911 aspects << aspect;
912 }
913
914 QString msg;
915 if (aspects.size() > 1)
916 msg = i18n("Do you really want to delete the selected %1 objects?", aspects.size());
917 else
918 msg = i18n("Do you really want to delete %1?", aspects.constFirst()->name());
919
920 auto status = KMessageBox::warningTwoActions(this,
921 msg,
922 i18np("Delete selected object", "Delete selected objects", aspects.size()),
923 KStandardGuiItem::del(),
924 KStandardGuiItem::cancel());
925 if (status == KMessageBox::SecondaryAction)
926 return;
927
928 m_project->beginMacro(i18np("Project Explorer: delete %1 selected object", "Project Explorer: delete %1 selected objects", items.size() / 4));
929
930 // determine aspects to be deleted:
931 // it's enough to delete parent items in the selection only,
932 // skip all selected aspects where one of the parents is also in the selection
933 // for example selected columns of a selected spreadsheet, etc.
934 QVector<AbstractAspect*> aspectsToDelete;
935 for (auto* aspect : aspects) {
936 auto* parent = aspect->parentAspect();
937 int parentSelected = false;
938 while (parent) {
939 if (aspects.indexOf(parent) != -1) {
940 parentSelected = true;
941 break;
942 }
943
944 parent = parent->parentAspect();
945 }
946
947 if (!parentSelected)
948 aspectsToDelete << aspect; // parent is not in the selection
949 }
950
951 for (auto* aspect : aspectsToDelete)
952 aspect->remove();
953
954 m_project->endMacro();
955}
956
957// ##############################################################################

Callers

nothing calls this directly

Calls 10

selectionModelMethod · 0.80
beginMacroMethod · 0.80
parentAspectMethod · 0.80
endMacroMethod · 0.80
sizeMethod · 0.45
columnCountMethod · 0.45
modelMethod · 0.45
nameMethod · 0.45
indexOfMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected