+
+/*!
+ * \brief Commits operation
+ * \param theOp - operation to be committed
+ * \return TRUE if operation is committed successfully
+*
+* Verifies whether operation already started and commits it in this case (sets execution
+* status to Accepted and stops operation)
+*/
+bool SUIT_Study::commit( SUIT_Operation* theOp )
+{
+ if ( !theOp || !myOperations.contains( theOp ) )
+ return false;
+
+ theOp->setExecStatus( SUIT_Operation::Accepted );
+
+ theOp->commitOperation();
+ operationCommited( theOp );
+ emit theOp->committed( theOp );
+
+ stop( theOp );
+
+ emit studyModified( this );
+
+ return true;
+}
+
+/*!
+ * \brief Commits operation
+ * \param theOp - operation to be committed
+ * \return TRUE if operation is suspended successfully
+*
+* Verifies whether operation already started and suspends it in this case. Operations
+* ususlly are suspended to start other one above them.
+*/
+bool SUIT_Study::suspend( SUIT_Operation* theOp )
+{
+ if ( !theOp || !myOperations.contains( theOp ) || theOp->state() == SUIT_Operation::Suspended )
+ return false;
+
+ theOp->setState( SUIT_Operation::Suspended );
+ theOp->suspendOperation();
+ emit theOp->suspended( theOp );
+ return true;
+}
+
+
+/*!
+ * \brief Resumes operation
+ * \param theOp - operation to be resumed
+ * \return TRUE if operation is aborted successfully
+*
+* Verifies whether operation already started but suspended and resumesit in this case.
+*/
+bool SUIT_Study::resume( SUIT_Operation* theOp )
+{
+ if ( !theOp || !myOperations.contains( theOp ) ||
+ theOp->state() == SUIT_Operation::Running ||
+ blockingOperation( theOp ) != 0 )
+ return false;
+
+ if ( myOperations.count() > 0 )
+ suspend( myOperations.last() );
+
+ theOp->setState( SUIT_Operation::Running );
+ theOp->resumeOperation();
+
+ // Move operation at the end of list in order to sort it in the order of activation.
+ // As result active operation is a last operation of list, operation which was active
+ // before currently active operation is located before it and so on
+ myOperations.removeAll( theOp );
+ myOperations.append( theOp );
+
+ emit theOp->resumed( theOp );
+ return true;
+}
+
+/*!
+ * \brief Stops operation
+ * \param theOp - operation to be stopped
+*
+* Stops operation. This private method is called from abort() and commit() ones to perform
+* common actions when operation is stopped
+*/
+void SUIT_Study::stop( SUIT_Operation* theOp )
+{
+ theOp->setState( SUIT_Operation::Waiting );
+ myOperations.removeAll( theOp );
+
+ // get last operation which can be resumed
+ SUIT_Operation* aResultOp = 0;
+
+ QListIterator<SUIT_Operation*> it (myOperations);
+ it.toBack();
+ while( it.hasPrevious() )
+ {
+ SUIT_Operation* anOp = it.previous();
+ if ( anOp && anOp != theOp && blockingOperation( anOp ) == 0 )
+ {
+ aResultOp = anOp;
+ break;
+ }
+ }
+
+ theOp->stopOperation();
+ operationStopped( theOp );
+ emit theOp->stopped( theOp );
+
+ if ( aResultOp )
+ resume( aResultOp );
+}
+
+/*!
+ * \brief Get all started operations
+ * \return List of all started operations
+*/
+const QList<SUIT_Operation*>& SUIT_Study::operations() const
+{
+ return myOperations;
+}
+
+/*!
+ * \brief Perform some actions when operation starting
+*/
+void SUIT_Study::operationStarted( SUIT_Operation* op )
+{
+ if ( !op )
+ return;
+
+ if ( op->testFlags( SUIT_Operation::Transaction ) )
+ op->openTransaction();
+}
+
+/*!
+ * \brief Perform some actions when operation aborted
+*/
+void SUIT_Study::operationAborted( SUIT_Operation* op )
+{
+ if ( op->testFlags( SUIT_Operation::Transaction ) )
+ op->abortTransaction();
+}
+
+/*!
+ * \brief Perform some actions when operation commited
+*/
+void SUIT_Study::operationCommited( SUIT_Operation* op )
+{
+ if ( op->testFlags( SUIT_Operation::Transaction ) )
+ op->commitTransaction( op->operationName() );
+}
+
+/*!
+ * \brief Perform some actions when operation stopped
+*/
+void SUIT_Study::operationStopped( SUIT_Operation* )
+{
+}
+
+/*!
+ * \brief Opens transaction for data modifications.
+*/
+bool SUIT_Study::openTransaction()
+{
+ return true;
+}
+
+/*!
+ * \brief Aborts transaction and all performed data modifications.
+*/
+bool SUIT_Study::abortTransaction()
+{
+ return true;
+}
+
+/*!
+ * \brief Commits transaction and all performed data modifications.
+*/
+bool SUIT_Study::commitTransaction( const QString& )
+{
+ return true;
+}
+
+/*!
+ * \brief Returns TRUE if transaction is opened.
+*/
+bool SUIT_Study::hasTransaction() const
+{
+ return false;
+}
+
+/*!
+ * \brief Restores the study state.
+ */
+void SUIT_Study::restoreState(int /*savePoint*/)
+{
+}