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 QStringList XGUI_OperationMgr::operationList()
63 foreach(ModuleBase_Operation* eachOperation, myOperations) {
64 result << eachOperation->id();
69 void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation)
71 theOperation->resume();
74 bool XGUI_OperationMgr::canStartOperation(ModuleBase_Operation* theOperation)
76 bool aCanStart = true;
77 ModuleBase_Operation* aCurrentOp = currentOperation();
78 if (aCurrentOp && !theOperation->isGranted(aCurrentOp))
80 if (canStopOperation()) {
89 bool XGUI_OperationMgr::canStopOperation()
91 int anAnswer = QMessageBox::question(0, tr("Operation launch"),
92 tr("Previous operation is not finished and will be aborted"),
93 QMessageBox::Ok, QMessageBox::Cancel);
94 return anAnswer == QMessageBox::Ok;
97 void XGUI_OperationMgr::onCommitOperation()
99 ModuleBase_Operation* anOperation = currentOperation();
101 anOperation->commit();
104 void XGUI_OperationMgr::onAbortOperation()
106 ModuleBase_Operation* anOperation = currentOperation();
108 anOperation->abort();
111 void XGUI_OperationMgr::onOperationStopped()
113 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
114 ModuleBase_Operation* anOperation = currentOperation();
115 if (!aSenderOperation || !anOperation || aSenderOperation != anOperation )
118 myOperations.removeAll(anOperation);
119 anOperation->deleteLater();
121 emit operationStopped(anOperation);
123 // get last operation which can be resumed
124 ModuleBase_Operation* aResultOp = 0;
125 QListIterator<ModuleBase_Operation*> anIt(myOperations);
127 while(anIt.hasPrevious())
129 ModuleBase_Operation* anOp = anIt.previous();
136 resumeOperation(aResultOp);