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

Method moveTreeModelInteraction

tests/backend/Worksheet/WorksheetElementTest.cpp:849–895  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

847}
848
849void WorksheetElementTest::moveTreeModelInteraction() {
850 Project project;
851 AspectTreeModel aspectTreeModel(&project, this);
852
853 std::unique_ptr<ProjectExplorer> projectExplorer = std::make_unique<ProjectExplorer>(nullptr);
854 projectExplorer->setModel(&aspectTreeModel);
855 projectExplorer->setProject(&project);
856 projectExplorer->setCurrentAspect(&project);
857
858 auto* ws = new Worksheet(QStringLiteral("Worksheet"));
859 project.addChild(ws);
860
861 auto* lFirst = new TextLabel(QStringLiteral("first"));
862 ws->addChild(lFirst);
863
864 auto* lSecond = new TextLabel(QStringLiteral("second"));
865 ws->addChild(lSecond);
866
867 auto* lThird = new TextLabel(QStringLiteral("third"));
868 ws->addChild(lThird);
869
870 auto children = ws->children<AbstractAspect>(AbstractAspect::ChildIndexFlag::IncludeHidden);
871
872 // First is background
873 QCOMPARE(children.at(1)->name(), lFirst->name());
874 QCOMPARE(children.at(2)->name(), lSecond->name());
875 QCOMPARE(children.at(3)->name(), lThird->name());
876
877 QAction action;
878 action.setData(1);
879 lThird->execMoveBehind(&action);
880
881 ws->setItemSelectedInView(lFirst->graphicsItem(), false);
882 ws->setItemSelectedInView(lThird->graphicsItem(), true);
883 const auto& indices = projectExplorer->m_treeView->selectionModel()->selectedIndexes();
884 QCOMPARE(indices.length(), 4);
885 const auto& aspectIndex = indices.at(0);
886 const auto* selectedAspect = static_cast<AbstractAspect*>(aspectIndex.internalPointer());
887 QCOMPARE(selectedAspect->name(), lThird->name()); // The selectionModel() got updated correctly
888
889 children = ws->children<AbstractAspect>(AbstractAspect::ChildIndexFlag::IncludeHidden);
890 // DEBUG_ELEMENT_NAMES(children);
891 lThird->createContextMenu();
892 lThird->prepareDrawingOrderMenu();
893 QCOMPARE(lThird->m_moveBehindMenu->actions().count(), 0);
894 QCOMPARE(lThird->m_moveInFrontOfMenu->actions().count(), 2);
895}
896
897// relative positioning
898

Callers

nothing calls this directly

Calls 14

setCurrentAspectMethod · 0.80
execMoveBehindMethod · 0.80
setItemSelectedInViewMethod · 0.80
selectionModelMethod · 0.80
lengthMethod · 0.80
setModelMethod · 0.45
setProjectMethod · 0.45
addChildMethod · 0.45
nameMethod · 0.45
setDataMethod · 0.45
graphicsItemMethod · 0.45

Tested by

no test coverage detected