void UndoDeleteNodeCommand::undo() { // Deserialize the saved node. Graph* g = App::instance()->getGraph(); SceneDeserializer::Info ds; SceneDeserializer::deserializeNode(data, g, &ds); // Extract the node from the temporary root auto old_node = n; n = g->childNodes().back(); // Find the new lists of node and datum pointers auto new_datums = getDatums(); // Swap the node pointers! stack->swapPointer(old_node, n); for (auto a = datums.begin(); a != datums.end(); ++a) { Q_ASSERT(new_datums.contains(a.key())); stack->swapPointer(a.value(), new_datums[a.key()]); } App::instance()->getGraphScene()->setInspectorPositions(ds.inspectors); }
void UndoDeleteNodeCommand::undo() { // Deserialize the saved node. NodeRoot temp_root; SceneDeserializer ds(&temp_root); ds.run(data); // Extract the node from the temporary root n = temp_root.findChild<Node*>(); // Find the new lists of node and datum pointers auto new_nodes = getNodes(); auto new_datums = getDatums(); // Swap all the pointers! for (auto a = nodes.begin(), b = new_nodes.begin(); a != nodes.end() && b != new_nodes.end(); ++a, ++b) stack->swapPointer(*a, *b); for (auto a = datums.begin(); a != datums.end(); ++a) { Q_ASSERT(new_datums.contains(a.key())); stack->swapPointer(a.value(), new_datums[a.key()]); } if (app) { app->makeUI(&temp_root); app->getGraphScene()->setInspectorPositions(ds.inspectors); } }
void UndoDeleteNodeCommand::redo() { // Find and save flat lists of all nodes and datums that will be deleted // (so that we can do a pointer swap when they're re-created) datums = getDatums(); // Serialize n into data byte array data = SceneSerializer::serializeNode( n, App::instance()->getGraphScene()->inspectorPositions()); // Tell the system to delete the node n->parentGraph()->uninstall(n); }
void UndoDeleteNodeCommand::redo() { // Find and save flat lists of all nodes and datums that will be deleted // (so that we can do a pointer swap when they're re-created) nodes = getNodes(); datums = getDatums(); // Serialize n into data byte array NodeRoot temp_root; n->setParent(&temp_root); data = app ? SceneSerializer( &temp_root, app->getGraphScene()->inspectorPositions()).run( SceneSerializer::SERIALIZE_NODES) : SceneSerializer(&temp_root).run( SceneSerializer::SERIALIZE_NODES); // Tell the system to delete the node n->deleteLater(); }