1 #include "SUIT_Study.h"
3 #include "SUIT_Desktop.h"
4 #include "SUIT_Operation.h"
5 #include "SUIT_DataObject.h"
6 #include "SUIT_MessageBox.h"
7 #include "SUIT_Application.h"
8 #include <qvaluevector.h>
11 * Support study management. Object management. Operation management.
15 SUIT_Study::SUIT_Study( SUIT_Application* app )
19 myIsModified( false ),
21 myBlockChangeState( false )
27 myRoot = new SUIT_DataObject();
28 myOperations.setAutoDelete( false );
29 myOperations.setAutoDelete( false );
33 SUIT_Study::~SUIT_Study()
42 int SUIT_Study::id() const
48 *\retval root data object.
50 SUIT_DataObject* SUIT_Study::root() const
58 SUIT_Application* SUIT_Study::application() const
66 QString SUIT_Study::studyName() const
72 *\retval active operation.
74 SUIT_Operation* SUIT_Study::activeOperation() const
76 return myOperations.count() > 0 ? myOperations.getLast() : 0;
80 *\retval TRUE - if study saved, else FALSE.
82 bool SUIT_Study::isSaved() const
88 *\retval TRUE - if study modified, else FALSE.
90 bool SUIT_Study::isModified() const
96 *Close document. NOT IMPLEMENTED.
98 void SUIT_Study::closeDocument(bool permanently)
102 void SUIT_Study::createDocument()
104 /*! Custom document initialization to be performed \n
105 * within onNewDoc() handler can be put here
110 * Open document. Sets file name. return true.
112 bool SUIT_Study::openDocument( const QString& fileName )
116 myIsModified = false;
122 * Save document as \a fileName. Set file name.
124 bool SUIT_Study::saveDocumentAs( const QString& fileName )
128 myIsModified = false;
134 *\retval TRUE - if document saved successful, else FALSE.
136 bool SUIT_Study::saveDocument()
138 return saveDocumentAs( myName );
142 *Abort all operations.
144 void SUIT_Study::abortAllOperations()
146 myBlockChangeState = true;
147 for( SUIT_Operation* op = myOperations.first(); op; op = myOperations.next() )
149 myBlockChangeState = false;
150 myOperations.clear();
154 Update study. NOT IMPLEMENTED HERE.
156 void SUIT_Study::update()
163 void SUIT_Study::sendChangesNotification()
165 emit studyModified( this );
169 Set study saved to \a on.
171 void SUIT_Study::setIsSaved( const bool on )
177 Set study modified to \a on.
179 void SUIT_Study::setIsModified( const bool on )
187 void SUIT_Study::setRoot( SUIT_DataObject* obj )
192 // This is necessary in order not to destroy the complete tree of objects
194 obj->reparentChildren( myRoot );
203 void SUIT_Study::setStudyName( const QString& name )
209 * \brief Verifies whether operation can be activated above already started ones
210 * \param theOp - operation to be checked
211 * \return NULL if operation can be activated, pointer to operation which denies
212 * starting tested operation
214 * Verifies whether operation can be activated above already started ones. This method
215 * is called from SUIT_Study::start() and SUIT_Study::resume() methods.
217 SUIT_Operation* SUIT_Study::blockingOperation( SUIT_Operation* theOp ) const
219 if( theOp->isGranted() )
222 Operations tmpOps( myOperations );
223 SUIT_Operation* anOp = 0;
224 for ( anOp = tmpOps.last(); anOp; anOp = tmpOps.prev() )
226 if ( anOp != 0 && anOp!= theOp && !anOp->isValid( theOp ) )
234 * \brief Starts operation
235 * \param theOp - operation to be started
236 * \param toCheck - if parameters is equal TRUE then checking performed whether
237 * all already started operations allow to start this operation above them (default
239 * \return TRUE if operation is started, FALSE otherwise
241 * Verifies whether theOp operation can be started above already started ones (if toCheck
242 * parameter is equal TRUE) and starts it
244 bool SUIT_Study::start( SUIT_Operation* theOp, const bool toCheck )
246 if ( !theOp || myOperations.find( theOp ) >= 0 )
249 theOp->setExecStatus( SUIT_Operation::Rejected );
250 theOp->setStudy( this );
252 if ( !theOp->isReadyToStart() )
257 while( SUIT_Operation* anOp = blockingOperation( theOp ) )
259 int anAnsw = SUIT_MessageBox::warn2( application()->desktop(),
260 tr( "OPERATION_LAUNCH" ), tr( "PREVIOUS_NOT_FINISHED" ),
261 tr( "CONTINUE" ), tr( "CANCEL" ), 0, 1, 1 );
270 SUIT_Operation* anOp = activeOperation();
273 activeOperation()->suspendOperation();
274 anOp->setState( SUIT_Operation::Suspended );
277 theOp->setState( SUIT_Operation::Running );
278 myOperations.append( theOp );
280 emit theOp->started( theOp );
281 operationStarted( theOp );
282 theOp->startOperation();
288 * \brief Aborts operation
289 * \param theOp - operation to be aborted
290 * \return TRUE if operation is aborted successfully
292 * Verifies whether operation already started and aborts it in this case (sets execution
293 * status to Rejected and stops operation)
295 bool SUIT_Study::abort( SUIT_Operation* theOp )
297 if ( !theOp || myOperations.find( theOp ) == -1 )
300 theOp->setExecStatus( SUIT_Operation::Rejected );
302 theOp->abortOperation();
303 operationAborted( theOp );
304 emit theOp->aborted( theOp );
312 * \brief Commits operation
313 * \param theOp - operation to be committed
314 * \return TRUE if operation is committed successfully
316 * Verifies whether operation already started and commits it in this case (sets execution
317 * status to Accepted and stops operation)
319 bool SUIT_Study::commit( SUIT_Operation* theOp )
321 if ( !theOp || myOperations.find( theOp ) == -1 )
324 theOp->setExecStatus( SUIT_Operation::Accepted );
326 theOp->commitOperation();
327 operationCommited( theOp );
328 emit theOp->committed( theOp );
332 emit studyModified( this );
338 * \brief Commits operation
339 * \param theOp - operation to be committed
340 * \return TRUE if operation is suspended successfully
342 * Verifies whether operation already started and suspends it in this case. Operations
343 * ususlly are suspended to start other one above them.
345 bool SUIT_Study::suspend( SUIT_Operation* theOp )
347 if ( !theOp || myOperations.find( theOp ) == -1 || theOp->state() == SUIT_Operation::Suspended )
350 theOp->setState( SUIT_Operation::Suspended );
351 theOp->suspendOperation();
352 emit theOp->suspended( theOp );
358 * \brief Resumes operation
359 * \param theOp - operation to be resumed
360 * \return TRUE if operation is aborted successfully
362 * Verifies whether operation already started but suspended and resumesit in this case.
364 bool SUIT_Study::resume( SUIT_Operation* theOp )
366 if ( !theOp || myOperations.find( theOp ) == -1 ||
367 theOp->state() == SUIT_Operation::Running ||
368 blockingOperation( theOp ) != 0 )
371 if ( myOperations.count() > 0 )
372 suspend( myOperations.last() );
374 theOp->setState( SUIT_Operation::Running );
375 theOp->resumeOperation();
377 // Move operation at the end of list in order to sort it in the order of activation.
378 // As result active operation is a last operation of list, operation which was active
379 // before currently active operation is located before it and so on
380 myOperations.remove( theOp );
381 myOperations.append( theOp );
383 emit theOp->resumed( theOp );
388 * \brief Stops operation
389 * \param theOp - operation to be stopped
391 * Stops operation. This private method is called from abort() and commit() ones to perform
392 * common actions when operation is stopped
394 void SUIT_Study::stop( SUIT_Operation* theOp )
396 theOp->setState( SUIT_Operation::Waiting );
397 myOperations.remove( theOp );
399 // get last operation which can be resumed
400 SUIT_Operation* anOp, *aResultOp = 0;
401 for ( anOp = myOperations.last(); anOp; anOp = myOperations.prev() )
403 if ( anOp && anOp != theOp && blockingOperation( anOp ) == 0 )
410 theOp->stopOperation();
411 operationStopped( theOp );
412 emit theOp->stopped( theOp );
419 * \brief Get all started operations
420 * \return List of all started operations
422 const QPtrList<SUIT_Operation>& SUIT_Study::operations() const
428 * \brief Perform some actions when operation starting
430 void SUIT_Study::operationStarted( SUIT_Operation* op )
435 if ( op->testFlags( SUIT_Operation::Transaction ) )
436 op->openTransaction();
440 * \brief Perform some actions when operation aborted
442 void SUIT_Study::operationAborted( SUIT_Operation* op )
444 if ( op->testFlags( SUIT_Operation::Transaction ) )
445 op->abortTransaction();
449 * \brief Perform some actions when operation commited
451 void SUIT_Study::operationCommited( SUIT_Operation* op )
453 if ( op->testFlags( SUIT_Operation::Transaction ) )
454 op->commitTransaction( op->operationName() );
458 * \brief Perform some actions when operation stopped
460 void SUIT_Study::operationStopped( SUIT_Operation* )
465 * \brief Opens transaction for data modifications.
467 bool SUIT_Study::openTransaction()
473 * \brief Aborts transaction and all performed data modifications.
475 bool SUIT_Study::abortTransaction()
481 * \brief Commits transaction and all performed data modifications.
483 bool SUIT_Study::commitTransaction( const QString& )
489 * \brief Returns TRUE if transaction is opened.
491 bool SUIT_Study::hasTransaction() const