Expose transaction events to document observer

This commit is contained in:
Stefan Tröger
2017-03-09 08:05:21 +01:00
committed by wmayer
parent e571a6e07a
commit e338fe6b70
6 changed files with 108 additions and 0 deletions

View File

@@ -425,6 +425,9 @@ Document* Application::newDocument(const char * Name, const char * UserName)
_pActiveDoc->signalRedo.connect(boost::bind(&App::Application::slotRedoDocument, this, _1));
_pActiveDoc->signalRecomputedObject.connect(boost::bind(&App::Application::slotRecomputedObject, this, _1));
_pActiveDoc->signalRecomputed.connect(boost::bind(&App::Application::slotRecomputed, this, _1));
_pActiveDoc->signalOpenTransaction.connect(boost::bind(&App::Application::slotOpenTransaction, this, _1, _2));
_pActiveDoc->signalCommitTransaction.connect(boost::bind(&App::Application::slotCommitTransaction, this, _1));
_pActiveDoc->signalAbortTransaction.connect(boost::bind(&App::Application::slotAbortTransaction, this, _1));
// make sure that the active document is set in case no GUI is up
{
@@ -1018,6 +1021,21 @@ void Application::slotRecomputed(const Document& doc)
this->signalRecomputed(doc);
}
void Application::slotOpenTransaction(const Document& d, string s)
{
this->signalOpenTransaction(d, s);
}
void Application::slotCommitTransaction(const Document& d)
{
this->signalCommitTransaction(d);
}
void Application::slotAbortTransaction(const Document& d)
{
this->signalAbortTransaction(d);
}
//**************************************************************************
// Init, Destruct and singleton

View File

@@ -143,6 +143,12 @@ public:
boost::signal<void (const App::Document&)> signalRecomputed;
/// signal on recomputed document object
boost::signal<void (const App::DocumentObject&)> signalObjectRecomputed;
// signal on opened transaction
boost::signal<void (const App::Document&, std::string)> signalOpenTransaction;
// signal a commited transaction
boost::signal<void (const App::Document&)> signalCommitTransaction;
// signal an aborted transaction
boost::signal<void (const App::Document&)> signalAbortTransaction;
//@}
/** @name Signals of property changes
@@ -277,6 +283,9 @@ protected:
void slotRedoDocument(const App::Document&);
void slotRecomputedObject(const App::DocumentObject&);
void slotRecomputed(const App::Document&);
void slotOpenTransaction(const App::Document&, std::string);
void slotCommitTransaction(const App::Document&);
void slotAbortTransaction(const App::Document&);
//@}
private:

View File

@@ -961,6 +961,8 @@ void Document::openTransaction(const char* name)
d->activeUndoTransaction->Name = name;
else
d->activeUndoTransaction->Name = "<empty>";
signalOpenTransaction(*this, name);
}
}
@@ -1000,6 +1002,7 @@ void Document::commitTransaction()
delete mUndoTransactions.front();
mUndoTransactions.pop_front();
}
signalCommitTransaction(*this);
}
}
@@ -1014,6 +1017,7 @@ void Document::abortTransaction()
// destroy the undo
delete d->activeUndoTransaction;
d->activeUndoTransaction = 0;
signalAbortTransaction(*this);
}
}

View File

@@ -148,6 +148,12 @@ public:
const std::map<std::string, std::string>&)> signalImportViewObjects;
boost::signal<void (const App::Document&)> signalRecomputed;
boost::signal<void (const App::DocumentObject&)> signalRecomputedObject;
//signal a new opened transaction
boost::signal<void (const App::Document&, std::string)> signalOpenTransaction;
// signal a commited transaction
boost::signal<void (const App::Document&)> signalCommitTransaction;
// signal an aborted transaction
boost::signal<void (const App::Document&)> signalAbortTransaction;
//@}
/** @name File handling of the document */

View File

@@ -83,6 +83,13 @@ DocumentObserverPython::DocumentObserverPython(const Py::Object& obj) : inst(obj
(&DocumentObserverPython::slotRecomputedObject, this, _1));
this->connectDocumentRecomputed = App::GetApplication().signalRecomputed.connect(boost::bind
(&DocumentObserverPython::slotRecomputedDocument, this, _1));
this->connectDocumentOpenTransaction = App::GetApplication().signalOpenTransaction.connect(boost::bind
(&DocumentObserverPython::slotOpenTransaction, this, _1, _2));
this->connectDocumentCommitTransaction = App::GetApplication().signalCommitTransaction.connect(boost::bind
(&DocumentObserverPython::slotCommitTransaction, this, _1));
this->connectDocumentAbortTransaction = App::GetApplication().signalAbortTransaction.connect(boost::bind
(&DocumentObserverPython::slotAbortTransaction, this, _1));
}
DocumentObserverPython::~DocumentObserverPython()
@@ -99,6 +106,9 @@ DocumentObserverPython::~DocumentObserverPython()
this->connectDocumentChangedObject.disconnect();
this->connectDocumentObjectRecomputed.disconnect();
this->connectDocumentRecomputed.disconnect();
this->connectDocumentOpenTransaction.disconnect();
this->connectDocumentCommitTransaction.disconnect();
this->connectDocumentAbortTransaction.disconnect();
}
void DocumentObserverPython::slotCreatedDocument(const App::Document& Doc)
@@ -293,4 +303,56 @@ void DocumentObserverPython::slotRecomputedDocument(const App::Document& doc)
Base::PyException e; // extract the Python error text
e.ReportException();
}
}
void DocumentObserverPython::slotOpenTransaction(const App::Document& doc, std::string str)
{
Base::PyGILStateLocker lock;
try {
if (this->inst.hasAttr(std::string("slotOpenTransaction"))) {
Py::Callable method(this->inst.getAttr(std::string("slotOpenTransaction")));
Py::Tuple args(2);
args.setItem(0, Py::Object(const_cast<App::Document&>(doc).getPyObject(), true));
args.setItem(1, Py::String(str));
method.apply(args);
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
}
}
void DocumentObserverPython::slotCommitTransaction(const App::Document& doc)
{
Base::PyGILStateLocker lock;
try {
if (this->inst.hasAttr(std::string("slotCommitTransaction"))) {
Py::Callable method(this->inst.getAttr(std::string("slotCommitTransaction")));
Py::Tuple args(1);
args.setItem(0, Py::Object(const_cast<App::Document&>(doc).getPyObject(), true));
method.apply(args);
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
}
}
void DocumentObserverPython::slotAbortTransaction(const App::Document& doc)
{
Base::PyGILStateLocker lock;
try {
if (this->inst.hasAttr(std::string("slotAbortTransaction"))) {
Py::Callable method(this->inst.getAttr(std::string("slotAbortTransaction")));
Py::Tuple args(1);
args.setItem(0, Py::Object(const_cast<App::Document&>(doc).getPyObject(), true));
method.apply(args);
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
}
}

View File

@@ -73,6 +73,12 @@ private:
void slotRecomputedObject(const App::DocumentObject& Obj);
/** Called when a observed document is recomputed */
void slotRecomputedDocument(const App::Document& Doc);
/** Called when a observed document opens a transaction */
void slotOpenTransaction(const App::Document& Doc, std::string str);
/** Called when a observed document commits a transaction */
void slotCommitTransaction(const App::Document& Doc);
/** Called when a observed document aborts a transaction */
void slotAbortTransaction(const App::Document& Doc);
private:
Py::Object inst;
@@ -90,6 +96,9 @@ private:
Connection connectDocumentChangedObject;
Connection connectDocumentObjectRecomputed;
Connection connectDocumentRecomputed;
Connection connectDocumentOpenTransaction;
Connection connectDocumentCommitTransaction;
Connection connectDocumentAbortTransaction;
};
} //namespace App