1 #include "XGUI_OperationMgr.h"
3 #include "ModuleBase_Operation.h"
10 XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent)
18 XGUI_OperationMgr::~XGUI_OperationMgr()
23 \brief Returns the current operation or NULL
24 * \return the current operation
26 ModuleBase_Operation* XGUI_OperationMgr::currentOperation() const
28 return myOperations.count() > 0 ? myOperations.last() : 0;
32 \brief Sets the current operation or NULL
33 * \return the current operation
35 bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation)
37 if (!canStartOperation(theOperation))
40 myOperations.append(theOperation);
41 emit beforeOperationStart();
43 connect(theOperation, SIGNAL(stopped()), this, SLOT(onOperationStopped()));
44 theOperation->start();
46 emit afterOperationStart();
50 bool XGUI_OperationMgr::canStartOperation(ModuleBase_Operation* theOperation)
52 bool aCanStart = true;
53 ModuleBase_Operation* aCurrentOp = currentOperation();
54 if (aCurrentOp && !theOperation->isGranted())
56 int anAnswer = QMessageBox::question(0, tr("Operation launch"),
57 tr("Previous operation is not finished and will be aborted"),
58 QMessageBox::Ok, QMessageBox::Cancel);
59 if (anAnswer == QMessageBox::Ok)
67 void XGUI_OperationMgr::commitCurrentOperation()
69 ModuleBase_Operation* anOperation = currentOperation();
73 anOperation->commit();
76 void XGUI_OperationMgr::onOperationStopped()
78 ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
79 ModuleBase_Operation* anOperation = currentOperation();
80 if (!aSenderOperation || !anOperation || aSenderOperation != anOperation )
83 myOperations.removeAll(anOperation);
85 // get last operation which can be resumed
86 ModuleBase_Operation* aResultOp = 0;
87 QListIterator<ModuleBase_Operation*> anIt(myOperations);
89 while(anIt.hasPrevious())
91 ModuleBase_Operation* anOp = anIt.previous();
98 startOperation(aResultOp);