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()));
45 theOperation->start();
49 void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation)
51 connect(theOperation, SIGNAL(stopped()), this, SLOT(onOperationStopped()));
52 connect(theOperation, SIGNAL(started()), this, SIGNAL(operationStarted()));
54 theOperation->resume();
57 bool XGUI_OperationMgr::canStartOperation(ModuleBase_Operation* theOperation)
59 bool aCanStart = true;
60 ModuleBase_Operation* aCurrentOp = currentOperation();
61 if (aCurrentOp && !theOperation->isGranted())
63 int anAnswer = QMessageBox::question(0, tr("Operation launch"),
64 tr("Previous operation is not finished and will be aborted"),
65 QMessageBox::Ok, QMessageBox::Cancel);
66 if (anAnswer == QMessageBox::Ok) {
75 void XGUI_OperationMgr::onOperationStopped()
77 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
78 ModuleBase_Operation* anOperation = currentOperation();
79 if (!aSenderOperation || !anOperation || aSenderOperation != anOperation )
82 emit operationStopped(anOperation);
84 myOperations.removeAll(anOperation);
85 anOperation->deleteLater();
87 // get last operation which can be resumed
88 ModuleBase_Operation* aResultOp = 0;
89 QListIterator<ModuleBase_Operation*> anIt(myOperations);
91 while(anIt.hasPrevious())
93 ModuleBase_Operation* anOp = anIt.previous();
100 resumeOperation(aResultOp);