| 847 | } |
| 848 | |
| 849 | void 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 |
nothing calls this directly
no test coverage detected