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

Method zValueAfterAddMoveRemove

tests/backend/Worksheet/WorksheetTest.cpp:121–178  ·  view source on GitHub ↗

! * tests the handling of z-values on changes in the child hierarchy. */

Source from the content-addressed store, hash-verified

119 * tests the handling of z-values on changes in the child hierarchy.
120 */
121void WorksheetTest::zValueAfterAddMoveRemove() {
122 auto* worksheet = new Worksheet(QStringLiteral("Worksheet"));
123
124 auto* plot1 = new CartesianPlot(QStringLiteral("plot1"));
125 worksheet->addChild(plot1);
126
127 auto* plot2 = new CartesianPlot(QStringLiteral("plot2"));
128 worksheet->addChild(plot2);
129
130 auto* plot3 = new CartesianPlot(QStringLiteral("plot3"));
131 worksheet->addChild(plot3);
132
133 // after the objects were added, the order of children is
134 // * plot1
135 // * plot2
136 // * plot3
137 int zValuePlot1 = plot1->graphicsItem()->zValue();
138 int zValuePlot2 = plot2->graphicsItem()->zValue();
139 int zValuePlot3 = plot3->graphicsItem()->zValue();
140 QVERIFY(zValuePlot1 < zValuePlot2);
141 QVERIFY(zValuePlot2 < zValuePlot3);
142
143 // move plot2 up
144 worksheet->moveChild(plot2, -1);
145
146 // after the move, the order of children is
147 // * plot2
148 // * plot1
149 // * plot3
150 zValuePlot1 = plot1->graphicsItem()->zValue();
151 zValuePlot2 = plot2->graphicsItem()->zValue();
152 zValuePlot3 = plot3->graphicsItem()->zValue();
153 QVERIFY(zValuePlot2 < zValuePlot1);
154 QVERIFY(zValuePlot1 < zValuePlot3);
155
156 // move plot1 down
157 worksheet->moveChild(plot1, 1);
158
159 // after the move, the order of children is
160 // * plot2
161 // * plot3
162 // * plot1
163 zValuePlot1 = plot1->graphicsItem()->zValue();
164 zValuePlot2 = plot2->graphicsItem()->zValue();
165 zValuePlot3 = plot3->graphicsItem()->zValue();
166 QVERIFY(zValuePlot2 < zValuePlot3);
167 QVERIFY(zValuePlot3 < zValuePlot1);
168
169 // remove plot3
170 worksheet->removeChild(plot3);
171
172 // after the remove, the order of children is
173 // * plot2
174 // * plot1
175 zValuePlot1 = plot1->graphicsItem()->zValue();
176 zValuePlot2 = plot2->graphicsItem()->zValue();
177 QVERIFY(zValuePlot2 < zValuePlot1);
178}

Callers

nothing calls this directly

Calls 4

moveChildMethod · 0.80
addChildMethod · 0.45
graphicsItemMethod · 0.45
removeChildMethod · 0.45

Tested by

no test coverage detected