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 )
195 // This is necessary in order not to destroy the complete tree of objects
197 obj->reparentChildren( myRoot );
206 void SUIT_Study::setStudyName( const QString& name )
212 * \brief Verifies whether operation can be activated above already started ones
213 * \param theOp - operation to be checked
214 * \return NULL if operation can be activated, pointer to operation which denies
215 * starting tested operation
217 * Verifies whether operation can be activated above already started ones. This method
218 * is called from SUIT_Study::start() and SUIT_Study::resume() methods.
220 SUIT_Operation* SUIT_Study::blockingOperation( SUIT_Operation* theOp ) const
222 if( theOp->isGranted() )
225 Operations tmpOps( myOperations );
226 SUIT_Operation* anOp = 0;
227 for ( anOp = tmpOps.last(); anOp; anOp = tmpOps.prev() )
229 if ( anOp != 0 && anOp!= theOp && !anOp->isValid( theOp ) )
237 * \brief Starts operation
238 * \param theOp - operation to be started
239 * \param toCheck - if parameters is equal TRUE then checking performed whether
240 * all already started operations allow to start this operation above them (default
242 * \return TRUE if operation is started, FALSE otherwise
244 * Verifies whether theOp operation can be started above already started ones (if toCheck
245 * parameter is equal TRUE) and starts it
247 bool SUIT_Study::start( SUIT_Operation* theOp, const bool toCheck )
249 if ( !theOp || myOperations.find( theOp ) >= 0 )
252 theOp->setExecStatus( SUIT_Operation::Rejected );
253 theOp->setStudy( this );
255 if ( !theOp->isReadyToStart() )
260 while( SUIT_Operation* anOp = blockingOperation( theOp ) )
262 int anAnsw = SUIT_MessageBox::warn2( application()->desktop(),
263 tr( "OPERATION_LAUNCH" ), tr( "PREVIOUS_NOT_FINISHED" ),
264 tr( "CONTINUE" ), tr( "CANCEL" ), 0, 1, 1 );
273 SUIT_Operation* anOp = activeOperation();
276 activeOperation()->suspendOperation();
277 anOp->setState( SUIT_Operation::Suspended );
280 theOp->setState( SUIT_Operation::Running );
281 myOperations.append( theOp );
282 emit theOp->started( theOp );
283 theOp->startOperation();
289 * \brief Aborts operation
290 * \param theOp - operation to be aborted
291 * \return TRUE if operation is aborted successfully
293 * Verifies whether operation already started and aborts it in this case (sets execution
294 * status to Rejected and stops operation)
296 bool SUIT_Study::abort( SUIT_Operation* theOp )
298 if ( !theOp || myOperations.find( theOp ) == -1 )
301 theOp->abortOperation();
302 theOp->setExecStatus( SUIT_Operation::Rejected );
303 emit theOp->aborted( theOp );
309 * \brief Commits operation
310 * \param theOp - operation to be committed
311 * \return TRUE if operation is committed successfully
313 * Verifies whether operation already started and commits it in this case (sets execution
314 * status to Accepted and stops operation)
316 bool SUIT_Study::commit( SUIT_Operation* theOp )
318 if ( !theOp || myOperations.find( theOp ) == -1 )
321 theOp->commitOperation();
322 theOp->setExecStatus( SUIT_Operation::Accepted );
323 emit theOp->committed( theOp );
325 emit studyModified( this );
330 * \brief Commits operation
331 * \param theOp - operation to be committed
332 * \return TRUE if operation is suspended successfully
334 * Verifies whether operation already started and suspends it in this case. Operations
335 * ususlly are suspended to start other one above them.
337 bool SUIT_Study::suspend( SUIT_Operation* theOp )
339 if ( !theOp || myOperations.find( theOp ) == -1 || theOp->state() == SUIT_Operation::Suspended )
342 theOp->setState( SUIT_Operation::Suspended );
343 theOp->suspendOperation();
344 emit theOp->suspended( theOp );
350 * \brief Resumes operation
351 * \param theOp - operation to be resumed
352 * \return TRUE if operation is aborted successfully
354 * Verifies whether operation already started but suspended and resumesit in this case.
356 bool SUIT_Study::resume( SUIT_Operation* theOp )
358 if ( !theOp || myOperations.find( theOp ) == -1 ||
359 theOp->state() == SUIT_Operation::Running ||
360 blockingOperation( theOp ) != 0 )
363 if ( myOperations.count() > 0 )
364 suspend( myOperations.last() );
366 theOp->setState( SUIT_Operation::Running );
367 theOp->resumeOperation();
369 // Move operation at the end of list in order to sort it in the order of activation.
370 // As result active operation is a last operation of list, operation which was active
371 // before currently active operation is located before it and so on
372 myOperations.remove( theOp );
373 myOperations.append( theOp );
375 emit theOp->resumed( theOp );
380 * \brief Stops operation
381 * \param theOp - operation to be stopped
383 * Stops operation. This private method is called from abort() and commit() ones to perform
384 * common actions when operation is stopped
386 void SUIT_Study::stop( SUIT_Operation* theOp )
388 theOp->setState( SUIT_Operation::Waiting );
389 myOperations.remove( theOp );
391 // get last operation which can be resumed
392 SUIT_Operation* anOp, *aResultOp = 0;
393 for( anOp = myOperations.last(); anOp; anOp = myOperations.prev() )
394 if ( anOp && anOp != theOp && blockingOperation( anOp ) == 0 )
400 emit theOp->stopped( theOp );
406 * \brief Get all started operations
407 * \return List of all started operations
409 const QPtrList<SUIT_Operation>& SUIT_Study::operations() const