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 );
30 connect( this, SIGNAL( changeOperationState( bool ) ), this, SLOT( onChangeOperationState( bool ) ) );
32 myOperations.setAutoDelete( false );
36 SUIT_Study::~SUIT_Study()
45 int SUIT_Study::id() const
51 *\retval root data object.
53 SUIT_DataObject* SUIT_Study::root() const
61 SUIT_Application* SUIT_Study::application() const
69 QString SUIT_Study::studyName() const
75 *\retval active operation.
77 SUIT_Operation* SUIT_Study::activeOperation() const
79 return myOperations.count() > 0 ? myOperations.getLast() : 0;
83 *\retval TRUE - if study saved, else FALSE.
85 bool SUIT_Study::isSaved() const
91 *\retval TRUE - if study modified, else FALSE.
93 bool SUIT_Study::isModified() const
99 *Close document. NOT IMPLEMENTED.
101 void SUIT_Study::closeDocument(bool permanently)
105 void SUIT_Study::createDocument()
107 /*! Custom document initialization to be performed \n
108 * within onNewDoc() handler can be put here
113 * Open document. Sets file name. return true.
115 bool SUIT_Study::openDocument( const QString& fileName )
119 myIsModified = false;
125 * Save document as \a fileName. Set file name.
127 bool SUIT_Study::saveDocumentAs( const QString& fileName )
131 myIsModified = false;
137 *\retval TRUE - if document saved successful, else FALSE.
139 bool SUIT_Study::saveDocument()
141 return saveDocumentAs( myName );
145 *Abort all operations.
147 void SUIT_Study::abortAllOperations()
149 myBlockChangeState = true;
150 for( SUIT_Operation* op = myOperations.first(); op; op = myOperations.next() )
152 myBlockChangeState = false;
153 myOperations.clear();
157 Update study. NOT IMPLEMENTED HERE.
159 void SUIT_Study::update()
166 void SUIT_Study::sendChangesNotification()
168 emit studyModified( this );
172 Set study saved to \a on.
174 void SUIT_Study::setIsSaved( const bool on )
180 Set study modified to \a on.
182 void SUIT_Study::setIsModified( const bool on )
190 void SUIT_Study::setRoot( SUIT_DataObject* obj )
202 void SUIT_Study::setStudyName( const QString& name )
208 * \brief Verifies whether operation can be activated above already started ones
209 * \param theOp - operation to be checked
210 * \return NULL if operation can be activated, pointer to operation which denies
211 * starting tested operation
213 * Verifies whether operation can be activated above already started ones. This method
214 * is called from SUIT_Study::start() and SUIT_Study::resume() methods.
216 SUIT_Operation* SUIT_Study::blockingOperation( SUIT_Operation* theOp ) const
218 if( theOp->isGranted() )
221 Operations tmpOps( myOperations );
222 SUIT_Operation* anOp = 0;
223 for ( anOp = tmpOps.last(); anOp; anOp = tmpOps.prev() )
225 if ( anOp != 0 && anOp!= theOp && !anOp->isValid( theOp ) )
233 * \brief Starts operation
234 * \param theOp - operation to be started
235 * \param toCheck - if parameters is equal TRUE then checking performed whether
236 * all already started operations allow to start this operation above them (default
238 * \return TRUE if operation is started, FALSE otherwise
240 * Verifies whether theOp operation can be started above already started ones (if toCheck
241 * parameter is equal TRUE) and starts it
243 bool SUIT_Study::start( SUIT_Operation* theOp, const bool toCheck )
245 if ( !theOp || myOperations.find( theOp ) >= 0 )
248 theOp->setExecStatus( SUIT_Operation::Rejected );
249 theOp->setStudy( this );
251 if ( !theOp->isReadyToStart() )
256 while( SUIT_Operation* anOp = blockingOperation( theOp ) )
258 int anAnsw = SUIT_MessageBox::warn2( application()->desktop(),
259 tr( "OPERATION_LAUNCH" ), tr( "PREVIOUS_NOT_FINISHED" ),
260 tr( "CONTINUE" ), tr( "CANCEL" ), 0, 1, 1 );
269 SUIT_Operation* anOp = activeOperation();
272 activeOperation()->suspendOperation();
273 anOp->setState( SUIT_Operation::Suspended );
276 theOp->setState( SUIT_Operation::Running );
277 myOperations.append( theOp );
278 emit theOp->started( theOp );
279 theOp->startOperation();
285 * \brief Aborts operation
286 * \param theOp - operation to be aborted
287 * \return TRUE if operation is aborted successfully
289 * Verifies whether operation already started and aborts it in this case (sets execution
290 * status to Rejected and stops operation)
292 bool SUIT_Study::abort( SUIT_Operation* theOp )
294 if ( !theOp || myOperations.find( theOp ) == -1 )
297 theOp->abortOperation();
298 theOp->setExecStatus( SUIT_Operation::Rejected );
299 emit theOp->aborted( theOp );
305 * \brief Commits operation
306 * \param theOp - operation to be committed
307 * \return TRUE if operation is committed successfully
309 * Verifies whether operation already started and commits it in this case (sets execution
310 * status to Accepted and stops operation)
312 bool SUIT_Study::commit( SUIT_Operation* theOp )
314 if ( !theOp || myOperations.find( theOp ) == -1 )
317 theOp->commitOperation();
318 theOp->setExecStatus( SUIT_Operation::Accepted );
319 emit theOp->committed( theOp );
321 emit studyModified( this );
326 * \brief Commits operation
327 * \param theOp - operation to be committed
328 * \return TRUE if operation is suspended successfully
330 * Verifies whether operation already started and suspends it in this case. Operations
331 * ususlly are suspended to start other one above them.
333 bool SUIT_Study::suspend( SUIT_Operation* theOp )
335 if ( !theOp || myOperations.find( theOp ) == -1 || theOp->state() == SUIT_Operation::Suspended )
338 theOp->setState( SUIT_Operation::Suspended );
339 theOp->suspendOperation();
340 emit theOp->suspended( theOp );
346 * \brief Resumes operation
347 * \param theOp - operation to be resumed
348 * \return TRUE if operation is aborted successfully
350 * Verifies whether operation already started but suspended and resumesit in this case.
352 bool SUIT_Study::resume( SUIT_Operation* theOp )
354 if ( !theOp || myOperations.find( theOp ) == -1 ||
355 theOp->state() == SUIT_Operation::Running ||
356 blockingOperation( theOp ) != 0 )
359 if ( myOperations.count() > 0 )
360 suspend( myOperations.last() );
362 theOp->setState( SUIT_Operation::Running );
363 theOp->resumeOperation();
365 // Move operation at the end of list in order to sort it in the order of activation.
366 // As result active operation is a last operation of list, operation which was active
367 // before currently active operation is located before it and so on
368 myOperations.remove( theOp );
369 myOperations.append( theOp );
371 emit theOp->resumed( theOp );
376 * \brief Stops operation
377 * \param theOp - operation to be stopped
379 * Stops operation. This private method is called from abort() and commit() ones to perform
380 * common actions when operation is stopped
382 void SUIT_Study::stop( SUIT_Operation* theOp )
384 theOp->setState( SUIT_Operation::Waiting );
385 myOperations.remove( theOp );
387 // get last operation which can be resumed
388 SUIT_Operation* anOp, *aResultOp = 0;
389 for( anOp = myOperations.last(); anOp; anOp = myOperations.prev() )
390 if ( anOp && anOp != theOp && blockingOperation( anOp ) == 0 )
396 emit theOp->stopped( theOp );
402 * \brief Get all started operations
403 * \return List of all started operations
405 const QPtrList<SUIT_Operation>& SUIT_Study::operations() const