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 bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation)
32 if (!canStartOperation(theOperation))
35 myOperations.append(theOperation);
37 connect(theOperation, SIGNAL(stopped()), this, SLOT(onOperationStopped()));
38 connect(theOperation, SIGNAL(started()), this, SIGNAL(operationStarted()));
40 theOperation->start();
44 void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation)
46 connect(theOperation, SIGNAL(stopped()), this, SLOT(onOperationStopped()));
47 connect(theOperation, SIGNAL(started()), this, SIGNAL(operationStarted()));
49 theOperation->resume();
52 bool XGUI_OperationMgr::canStartOperation(ModuleBase_Operation* theOperation)
54 bool aCanStart = true;
55 ModuleBase_Operation* aCurrentOp = currentOperation();
56 if (aCurrentOp && !theOperation->isGranted())
58 int anAnswer = QMessageBox::question(0, tr("Operation launch"),
59 tr("Previous operation is not finished and will be aborted"),
60 QMessageBox::Ok, QMessageBox::Cancel);
61 if (anAnswer == QMessageBox::Ok) {
70 void XGUI_OperationMgr::onOperationStopped()
72 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
73 ModuleBase_Operation* anOperation = currentOperation();
74 if (!aSenderOperation || !anOperation || aSenderOperation != anOperation )
77 emit operationStopped(anOperation);
79 myOperations.removeAll(anOperation);
80 anOperation->deleteLater();
82 // get last operation which can be resumed
83 ModuleBase_Operation* aResultOp = 0;
84 QListIterator<ModuleBase_Operation*> anIt(myOperations);
86 while(anIt.hasPrevious())
88 ModuleBase_Operation* anOp = anIt.previous();
95 resumeOperation(aResultOp);