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::startOperation(ModuleBase_Operation* theOperation)
27 if (!canStartOperation(theOperation))
30 myOperations.append(theOperation);
32 connect(theOperation, SIGNAL(stopped()), this, SLOT(onOperationStopped()));
33 connect(theOperation, SIGNAL(started()), this, SIGNAL(operationStarted()));
35 theOperation->start();
39 bool XGUI_OperationMgr::canStartOperation(ModuleBase_Operation* theOperation)
41 bool aCanStart = true;
42 ModuleBase_Operation* aCurrentOp = currentOperation();
43 if (aCurrentOp && !theOperation->isGranted())
45 int anAnswer = QMessageBox::question(0, tr("Operation launch"),
46 tr("Previous operation is not finished and will be aborted"),
47 QMessageBox::Ok, QMessageBox::Cancel);
48 if (anAnswer == QMessageBox::Ok) {
57 void XGUI_OperationMgr::onOperationStopped()
59 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
60 ModuleBase_Operation* anOperation = currentOperation();
61 if (!aSenderOperation || !anOperation || aSenderOperation != anOperation )
64 emit operationStopped(anOperation);
66 myOperations.removeAll(anOperation);
67 anOperation->deleteLater();
69 // get last operation which can be resumed
70 ModuleBase_Operation* aResultOp = 0;
71 QListIterator<ModuleBase_Operation*> anIt(myOperations);
73 while(anIt.hasPrevious())
75 ModuleBase_Operation* anOp = anIt.previous();
82 startOperation(aResultOp);