MCPcopy Create free account
hub / github.com/BehaviorTree/Groot / undoRedo

Method undoRedo

test/editor_test.cpp:160–262  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

158}
159
160void EditorTest::undoRedo()
161{
162 QString file_xml = readFile(":/show_all.xml");
163 main_win->on_actionClear_triggered();
164 main_win->loadFromXML( file_xml );
165
166 //------------------------------------------
167 AbsBehaviorTree abs_tree_A, abs_tree_B;
168 {
169 auto container = main_win->currentTabInfo();
170 auto view = container->view();
171 abs_tree_A = getAbstractTree();
172
173 sleepAndRefresh( 500 );
174
175 auto pippo_node = abs_tree_A.findFirstNode("Pippo");
176 auto gui_node = pippo_node->graphic_node;
177 QPoint pippo_screen_pos = view->mapFromScene(pippo_node->pos);
178 const QPoint pos_offset(100,0);
179
180 QTest::mouseClick( view->viewport(), Qt::LeftButton, Qt::NoModifier, pippo_screen_pos );
181
182 QVERIFY2( gui_node->nodeGraphicsObject().isSelected(), "Pippo is not selected");
183
184 auto old_pos = view->mapFromScene( container->scene()->getNodePosition( *gui_node ) );
185 testDragObject(view, pippo_screen_pos, pos_offset);
186 QPoint new_pos = view->mapFromScene( container->scene()->getNodePosition( *gui_node ) );
187
188 QCOMPARE( old_pos + pos_offset, new_pos);
189 sleepAndRefresh( 500 );
190 }
191 //---------- test undo ----------
192 {
193 abs_tree_B = getAbstractTree();
194 main_win->onUndoInvoked();
195 sleepAndRefresh( 500 );
196
197 QCOMPARE( abs_tree_A, getAbstractTree() );
198 sleepAndRefresh( 500 );
199 }
200
201 {
202 main_win->onUndoInvoked();
203 sleepAndRefresh( 500 );
204 auto empty_abs_tree = getAbstractTree();
205 QCOMPARE( empty_abs_tree.nodesCount(), size_t(1) );
206
207 // nothing should happen
208 main_win->onUndoInvoked();
209 main_win->onUndoInvoked();
210 main_win->onUndoInvoked();
211 }
212
213 {
214 main_win->onRedoInvoked();
215 sleepAndRefresh( 500 );
216 QCOMPARE( getAbstractTree(), abs_tree_A);
217

Callers

nothing calls this directly

Calls 9

loadFromXMLMethod · 0.80
currentTabInfoMethod · 0.80
viewMethod · 0.80
findFirstNodeMethod · 0.80
sceneMethod · 0.80
onUndoInvokedMethod · 0.80
nodesCountMethod · 0.80
onRedoInvokedMethod · 0.80

Tested by

no test coverage detected