Skip to content

Commit

Permalink
Document/DocumentObject: onUndoRedoFinished()
Browse files Browse the repository at this point in the history
=============================================

New mechanism for on-demand signaling of undo/redo transaction finalisation.

The mechanism consists of:
1) A status bit that is set, when an object should receive this signaling (e.g. because changes during transaction have been inhibited)
2) The new function to be called by the Document undo/redo actions when the transaction is over (for those objects having the status bit set).

Note 1: The undo/redo signals are now outside the undoing FlagToggler, this means that:
1) a call to isPerformingTransaction will return false.
2) a recompute the slot of such a signal will not be inhibited.

Note 2: The undo/redo signals are called once the documentobjects that requested to be notified after the trasaction is over have been notified.
The consequence is that the viewprovider can rely on the documentobject having a correct status.

I think that the behaviour of Note and Note 2 is the wanted behaviour of this signals, I cannot rule out that other parts of FC rely on the old
implementation.
  • Loading branch information
abdullahtahiriyo authored and wwmayer committed Jun 14, 2020
1 parent c6c549c commit df4a8eb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/App/Document.cpp
Expand Up @@ -963,6 +963,7 @@ bool Document::undo(int id)
d->activeUndoTransaction = new Transaction(mUndoTransactions.back()->getID());
d->activeUndoTransaction->Name = mUndoTransactions.back()->Name;

{
Base::FlagToggler<bool> flag(d->undoing);
// applying the undo
mUndoTransactions.back()->apply(*this,false);
Expand All @@ -976,7 +977,17 @@ bool Document::undo(int id)
delete mUndoTransactions.back();
mUndoTransactions.pop_back();

signalUndo(*this);
}

for(auto & obj:d->objectArray) {
if(obj->testStatus(ObjectStatus::PendingTransactionUpdate)) {
obj->onUndoRedoFinished();
obj->setStatus(ObjectStatus::PendingTransactionUpdate,false);
}
}

signalUndo(*this); // now signal the undo

return true;
}

Expand Down Expand Up @@ -1004,6 +1015,7 @@ bool Document::redo(int id)
d->activeUndoTransaction->Name = mRedoTransactions.back()->Name;

// do the redo
{
Base::FlagToggler<bool> flag(d->undoing);
mRedoTransactions.back()->apply(*this,true);

Expand All @@ -1014,6 +1026,14 @@ bool Document::redo(int id)
mRedoMap.erase(mRedoTransactions.back()->getID());
delete mRedoTransactions.back();
mRedoTransactions.pop_back();
}

for(auto & obj:d->objectArray) {
if(obj->testStatus(ObjectStatus::PendingTransactionUpdate)) {
obj->onUndoRedoFinished();
obj->setStatus(ObjectStatus::PendingTransactionUpdate,false);
}
}

signalRedo(*this);
return true;
Expand Down
5 changes: 5 additions & 0 deletions src/App/DocumentObject.cpp
Expand Up @@ -936,6 +936,11 @@ void DocumentObject::onDocumentRestored()
Visibility.setStatus(Property::NoModify,true);
}

void DocumentObject::onUndoRedoFinished()
{

}

void DocumentObject::onSettingDocument()
{
//call all extensions
Expand Down
3 changes: 3 additions & 0 deletions src/App/DocumentObject.h
Expand Up @@ -64,6 +64,7 @@ enum ObjectStatus {
GeoExcluded = 15, // mark as a member but not claimed by GeoFeatureGroup
Expand = 16, // indicate the object's tree item expansion status
NoAutoExpand = 17, // disable tree item auto expand on selection for this object
PendingTransactionUpdate = 18, // mark that the object expects a call to onUndoRedoFinished() after transaction is finished.
};

/** Return object for feature execution
Expand Down Expand Up @@ -592,6 +593,8 @@ class AppExport DocumentObject: public App::TransactionalObject
virtual void onChanged(const Property* prop) override;
/// get called after a document has been fully restored
virtual void onDocumentRestored();
/// get called after an undo/redo transaction is finished
virtual void onUndoRedoFinished();
/// get called after setting the document
virtual void onSettingDocument();
/// get called after a brand new object was created
Expand Down

0 comments on commit df4a8eb

Please sign in to comment.