Skip to content
Permalink
Browse files

prepare view provider for undo/redo

  • Loading branch information...
wwmayer committed Jun 20, 2016
1 parent 9ec06b4 commit 0f2db9061f8feae99223aad8ee5b53852a96a145
Showing with 43 additions and 16 deletions.
  1. +1 −0 src/App/Document.cpp
  2. +34 −11 src/App/Transactions.cpp
  3. +2 −1 src/App/Transactions.h
  4. +6 −4 src/Gui/ViewProviderDocumentObject.cpp
@@ -1415,6 +1415,7 @@ void Document::restore (void)
// and then clear everything in one go.
for (std::vector<DocumentObject*>::iterator obj = d->objectArray.begin(); obj != d->objectArray.end(); ++obj) {
signalDeletedObject(*(*obj));
signalTransactionRemove(*(*obj), 0);
}
for (std::vector<DocumentObject*>::iterator obj = d->objectArray.begin(); obj != d->objectArray.end(); ++obj) {
delete *obj;
@@ -61,7 +61,7 @@ Transaction::Transaction(int pos)
*/
Transaction::~Transaction()
{
std::map<const TransactionalObject*, TransactionObject*>::iterator It;
TransactionList::iterator It;
for (It= _Objects.begin();It!=_Objects.end();++It) {
if (It->second->status == TransactionObject::New) {
// If an object has been removed from the document the transaction
@@ -105,9 +105,13 @@ int Transaction::getPos(void) const

bool Transaction::hasObject(const TransactionalObject *Obj) const
{
std::map<const TransactionalObject*, TransactionObject*>::const_iterator it;
it = _Objects.find(Obj);
return (it != _Objects.end());
TransactionList::const_iterator it;
for (it = _Objects.begin(); it != _Objects.end(); ++it) {
if (it->first == Obj)
return true;
}

return false;
}

//**************************************************************************
@@ -116,7 +120,7 @@ bool Transaction::hasObject(const TransactionalObject *Obj) const

void Transaction::apply(Document &Doc, bool forward)
{
std::map<const TransactionalObject*, TransactionObject*>::iterator It;
TransactionList::iterator It;
//for (It= _Objects.begin();It!=_Objects.end();++It)
// It->second->apply(Doc,const_cast<DocumentObject*>(It->first));
for (It= _Objects.begin();It!=_Objects.end();++It)
@@ -129,7 +133,13 @@ void Transaction::apply(Document &Doc, bool forward)

void Transaction::addObjectNew(TransactionalObject *Obj)
{
std::map<const TransactionalObject*, TransactionObject*>::iterator pos = _Objects.find(Obj);
TransactionList::iterator pos = _Objects.end();
for (TransactionList::iterator it = _Objects.begin(); it != _Objects.end(); ++it) {
if (it->first == Obj) {
pos = it;
break;
}
}

if (pos != _Objects.end()) {
if (pos->second->status == TransactionObject::Del) {
@@ -146,13 +156,19 @@ void Transaction::addObjectNew(TransactionalObject *Obj)
TransactionObject *To = TransactionFactory::instance().createTransaction(Obj->getTypeId());
To->status = TransactionObject::New;
To->_NameInDocument = Obj->detachFromDocument();
_Objects[Obj] = To;
_Objects.push_back(std::make_pair(Obj, To));
}
}

void Transaction::addObjectDel(const TransactionalObject *Obj)
{
std::map<const TransactionalObject*, TransactionObject*>::iterator pos = _Objects.find(Obj);
TransactionList::iterator pos = _Objects.end();
for (TransactionList::iterator it = _Objects.begin(); it != _Objects.end(); ++it) {
if (it->first == Obj) {
pos = it;
break;
}
}

// is it created in this transaction ?
if (pos != _Objects.end() && pos->second->status == TransactionObject::New) {
@@ -165,22 +181,29 @@ void Transaction::addObjectDel(const TransactionalObject *Obj)
}
else {
TransactionObject *To = TransactionFactory::instance().createTransaction(Obj->getTypeId());
_Objects[Obj] = To;
_Objects.push_back(std::make_pair(Obj, To));
To->status = TransactionObject::Del;
}
}

void Transaction::addObjectChange(const TransactionalObject *Obj, const Property *Prop)
{
std::map<const TransactionalObject*, TransactionObject*>::iterator pos = _Objects.find(Obj);
TransactionList::iterator pos = _Objects.end();
for (TransactionList::iterator it = _Objects.begin(); it != _Objects.end(); ++it) {
if (it->first == Obj) {
pos = it;
break;
}
}

TransactionObject *To;

if (pos != _Objects.end()) {
To = pos->second;
}
else {
To = TransactionFactory::instance().createTransaction(Obj->getTypeId());
_Objects[Obj] = To;
_Objects.push_back(std::make_pair(Obj, To));
To->status = TransactionObject::Chn;
}

@@ -73,7 +73,8 @@ class AppExport Transaction : public Base::Persistence

private:
int iPos;
std::map<const TransactionalObject*, TransactionObject*> _Objects;
typedef std::list <std::pair<const TransactionalObject*, TransactionObject*> > TransactionList;
TransactionList _Objects;
};

/** Represents an entry for an object in a Transaction
@@ -94,10 +94,12 @@ const char* ViewProviderDocumentObject::detachFromDocument()

void ViewProviderDocumentObject::onBeforeChange(const App::Property* prop)
{
App::DocumentObject* obj = getObject();
App::Document* doc = obj ? obj->getDocument() : 0;
if (doc) {
onBeforeChangeProperty(doc, prop);
if (isAttachedToDocument()) {
App::DocumentObject* obj = getObject();
App::Document* doc = obj ? obj->getDocument() : 0;
if (doc) {
onBeforeChangeProperty(doc, prop);
}
}
}

0 comments on commit 0f2db90

Please sign in to comment.
You can’t perform that action at this time.