1 #include "XGUI_OperationMgr.h"
3 #include "ModuleBase_Operation.h"
7 XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent)
12 XGUI_OperationMgr::~XGUI_OperationMgr()
16 ModuleBase_Operation* XGUI_OperationMgr::currentOperation() const
18 return myOperations.count() > 0 ? myOperations.last() : 0;
21 bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation)
23 if (!canStartOperation(theOperation))
26 myOperations.append(theOperation);
28 connect(theOperation, SIGNAL(stopped()), this, SLOT(onOperationStopped()));
29 connect(theOperation, SIGNAL(started()), this, SIGNAL(operationStarted()));
31 theOperation->start();
35 bool XGUI_OperationMgr::canStartOperation(ModuleBase_Operation* theOperation)
37 bool aCanStart = true;
38 ModuleBase_Operation* aCurrentOp = currentOperation();
39 if (aCurrentOp && !theOperation->isGranted())
41 int anAnswer = QMessageBox::question(0, tr("Operation launch"),
42 tr("Previous operation is not finished and will be aborted"),
43 QMessageBox::Ok, QMessageBox::Cancel);
44 if (anAnswer == QMessageBox::Ok)
52 void XGUI_OperationMgr::commitCurrentOperation()
54 ModuleBase_Operation* anOperation = currentOperation();
58 anOperation->commit();
61 void XGUI_OperationMgr::onOperationStopped()
63 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
64 ModuleBase_Operation* anOperation = currentOperation();
65 if (!aSenderOperation || !anOperation || aSenderOperation != anOperation )
68 emit operationStopped(anOperation);
70 myOperations.removeAll(anOperation);
71 anOperation->deleteLater();
73 // get last operation which can be resumed
74 ModuleBase_Operation* aResultOp = 0;
75 QListIterator<ModuleBase_Operation*> anIt(myOperations);
77 while(anIt.hasPrevious())
79 ModuleBase_Operation* anOp = anIt.previous();
86 startOperation(aResultOp);