#include "ModuleBase_Operation.h"
#include <QMessageBox>
+#include <QApplication>
+#include <QKeyEvent>
XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent)
: QObject(theParent)
{
+ // listen to Escape signal to stop the current operation
+ qApp->installEventFilter(this);
}
XGUI_OperationMgr::~XGUI_OperationMgr()
connect(theOperation, SIGNAL(stopped()), this, SLOT(onOperationStopped()));
connect(theOperation, SIGNAL(started()), this, SIGNAL(operationStarted()));
+ connect(theOperation, SIGNAL(resumed()), this, SIGNAL(operationResumed()));
theOperation->start();
return true;
return true;
}
-void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation)
+QStringList XGUI_OperationMgr::operationList()
{
- connect(theOperation, SIGNAL(stopped()), this, SLOT(onOperationStopped()));
- connect(theOperation, SIGNAL(started()), this, SIGNAL(operationStarted()));
+ QStringList result;
+ foreach(ModuleBase_Operation* eachOperation, myOperations) {
+ result << eachOperation->id();
+ }
+ return result;
+}
+
+bool XGUI_OperationMgr::eventFilter(QObject *theObject, QEvent *theEvent)
+{
+ if (theEvent->type() == QEvent::KeyRelease) {
+ QKeyEvent* aKeyEvent = (QKeyEvent*)theEvent;
+ if (aKeyEvent && aKeyEvent->key() == Qt::Key_Escape) {
+ // TODO: this is Escape button processing when the property panel has empty content,
+ // but the operation should be stopped by the Enter has been clicked
+ onKeyReleased("", aKeyEvent);
+ return true;
+ }
+ }
+ return QObject::eventFilter(theObject, theEvent);
+}
+void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation)
+{
theOperation->resume();
}
void XGUI_OperationMgr::onCommitOperation()
{
ModuleBase_Operation* anOperation = currentOperation();
- if (anOperation)
- anOperation->commit();
+ if (anOperation) {
+ if (anOperation->canBeCommitted())
+ anOperation->commit();
+ else
+ anOperation->abort();
+ }
}
void XGUI_OperationMgr::onAbortOperation()
if (!aSenderOperation || !anOperation || aSenderOperation != anOperation )
return;
- emit operationStopped(anOperation);
-
myOperations.removeAll(anOperation);
anOperation->deleteLater();
+ emit operationStopped(anOperation);
+
// get last operation which can be resumed
ModuleBase_Operation* aResultOp = 0;
QListIterator<ModuleBase_Operation*> anIt(myOperations);
if (aResultOp)
resumeOperation(aResultOp);
}
+
+void XGUI_OperationMgr::onKeyReleased(const std::string& theName, QKeyEvent* theEvent)
+{
+ ModuleBase_Operation* anOperation = currentOperation();
+ if (anOperation)
+ anOperation->keyReleased(theName, theEvent);
+}