1 // File: XGUI_OperationMgr.h
2 // Created: 20 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include "XGUI_OperationMgr.h"
7 #include "ModuleBase_Operation.h"
11 XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent)
16 XGUI_OperationMgr::~XGUI_OperationMgr()
20 ModuleBase_Operation* XGUI_OperationMgr::currentOperation() const
22 return myOperations.count() > 0 ? myOperations.last() : 0;
25 bool XGUI_OperationMgr::hasOperation() const
27 return (myOperations.count() > 0) && (myOperations.last() != NULL);
30 int XGUI_OperationMgr::operationsCount() const
32 return myOperations.count();
35 bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation)
37 if (!canStartOperation(theOperation))
40 myOperations.append(theOperation);
42 connect(theOperation, SIGNAL(stopped()), this, SLOT(onOperationStopped()));
43 connect(theOperation, SIGNAL(started()), this, SIGNAL(operationStarted()));
44 connect(theOperation, SIGNAL(resumed()), this, SIGNAL(operationResumed()));
46 theOperation->start();
50 bool XGUI_OperationMgr::abortOperation()
52 ModuleBase_Operation* aCurrentOp = currentOperation();
53 if (!aCurrentOp || !canStopOperation())
60 void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation)
62 theOperation->resume();
65 bool XGUI_OperationMgr::canStartOperation(ModuleBase_Operation* theOperation)
67 bool aCanStart = true;
68 ModuleBase_Operation* aCurrentOp = currentOperation();
69 if (aCurrentOp && !theOperation->isGranted(aCurrentOp))
71 if (canStopOperation()) {
80 bool XGUI_OperationMgr::canStopOperation()
82 int anAnswer = QMessageBox::question(0, tr("Operation launch"),
83 tr("Previous operation is not finished and will be aborted"),
84 QMessageBox::Ok, QMessageBox::Cancel);
85 return anAnswer == QMessageBox::Ok;
88 void XGUI_OperationMgr::onCommitOperation()
90 ModuleBase_Operation* anOperation = currentOperation();
92 anOperation->commit();
95 void XGUI_OperationMgr::onAbortOperation()
97 ModuleBase_Operation* anOperation = currentOperation();
102 void XGUI_OperationMgr::onOperationStopped()
104 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
105 ModuleBase_Operation* anOperation = currentOperation();
106 if (!aSenderOperation || !anOperation || aSenderOperation != anOperation )
109 emit operationStopped(anOperation);
111 myOperations.removeAll(anOperation);
112 anOperation->deleteLater();
114 // get last operation which can be resumed
115 ModuleBase_Operation* aResultOp = 0;
116 QListIterator<ModuleBase_Operation*> anIt(myOperations);
118 while(anIt.hasPrevious())
120 ModuleBase_Operation* anOp = anIt.previous();
127 resumeOperation(aResultOp);