Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
fix for issue #98: ensure ids of deleted subgraphs are freed/restored…
Browse files Browse the repository at this point in the history
… when a graph is in undo/redo state
  • Loading branch information
p-mary committed Apr 23, 2019
1 parent c1799bc commit a8ff578
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
19 changes: 17 additions & 2 deletions library/tulip-core/src/GraphAbstract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ void GraphAbstract::clear() {
void GraphAbstract::restoreSubGraph(Graph *sg) {
subgraphs.push_back(sg);
sg->setSuperGraph(this);
if (sg == subGraphToKeep) {
static_cast<GraphImpl *>(getRoot())->getSubGraphId(sg->getId());
subGraphToKeep = nullptr;
}
}
//=========================================================================
void GraphAbstract::setSubGraphToKeep(Graph *sg) {
Expand Down Expand Up @@ -142,12 +146,17 @@ void GraphAbstract::delSubGraph(Graph *toRemove) {
// avoid deletion of toRemove subgraphs
toRemove->clearSubGraphs();
delete toRemove;
} else
} else {
// toRemove is not deleted,
// and its subgraphs list is not erased;
// beacause it is registered into a GraphUpdatesRecorder
// because it is registered into a GraphUpdatesRecorder
// in order it can be restored on undo or redo
toRemove->notifyDestroy();
// free subgraph id which will be restored in case of undo
// see restoreSubGraph
static_cast<GraphImpl *>(getRoot())->freeSubGraphId(toRemove->getId());
subGraphToKeep = nullptr;
}
}
}
//=========================================================================
Expand All @@ -157,6 +166,12 @@ void GraphAbstract::removeSubGraph(Graph *toRemove) {
if (it != subgraphs.end()) {
subgraphs.erase(it);
}
if (toRemove == subGraphToKeep) {
// free subgraph id which will be restored in case of undo
// see restoreSubGraph
static_cast<GraphImpl *>(getRoot())->freeSubGraphId(toRemove->getId());
subGraphToKeep = nullptr;
}
}
//=========================================================================
void GraphAbstract::delAllSubGraphs() {
Expand Down
3 changes: 3 additions & 0 deletions library/tulip-core/src/GraphUpdatesRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ void GraphUpdatesRecorder::doUpdates(GraphImpl *g, bool undo) {

// remove from list of subgraphs + notify observers
g->notifyBeforeDelSubGraph(sg);
g->setSubGraphToKeep(sg);
g->removeSubGraph(sg);

if (!undo) {
Expand Down Expand Up @@ -683,6 +684,8 @@ void GraphUpdatesRecorder::doUpdates(GraphImpl *g, bool undo) {
// notify its addition
g->notifyBeforeAddSubGraph(sg);
// restore sg as subgraph of g
if (undo)
g->setSubGraphToKeep(sg);
g->restoreSubGraph(sg);

// and sg subgraphs are no longer subgraphs of g
Expand Down

0 comments on commit a8ff578

Please sign in to comment.