3 #include "CAM_DataModel.h"
4 #include "CAM_DataObject.h"
5 #include "CAM_RootObject.h"
6 #include "CAM_Module.h"
9 CAM_Study::CAM_Study( SUIT_Application* app )
15 CAM_Study::~CAM_Study()
19 /*!Closing all data models and close document permanently(if \a permanently = true.)
20 * \param permanently - flag
22 void CAM_Study::closeDocument(bool permanently)
24 for ( ModelListIterator it( myDataModels ); it.current(); ++it )
25 it.current()->close();
27 SUIT_Study::closeDocument(permanently);
30 /*!Append data model to list.
31 * \param dm - data model for adding
33 bool CAM_Study::appendDataModel( const CAM_DataModel* dm )
35 return insertDataModel( dm, myDataModels.count() );
38 /*!Insert data model \a dm after \a other
39 * \param dm - data model for adding
40 * \param other - previus data model for \a dm
42 bool CAM_Study::insertDataModel( const CAM_DataModel* dm, const CAM_DataModel* other )
44 int idx = myDataModels.findRef( other );
45 return insertDataModel( dm, idx < 0 ? idx : idx + 1 );
48 /*!Insert data model with index \a idx. \n
49 * \param dm - data model
50 * \param idx - index for inserting(must be no less zero)
51 * \retval true - if model added successful, else false.
53 bool CAM_Study::insertDataModel( const CAM_DataModel* dm, const int idx )
55 if ( !dm || myDataModels.findRef( dm ) != -1 )
58 int pos = idx < 0 ? myDataModels.count() : idx;
59 myDataModels.insert( QMIN( pos, (int)myDataModels.count() ), dm );
61 connect( dm, SIGNAL( rootChanged( const CAM_DataModel* ) ), SLOT( updateModelRoot( const CAM_DataModel* ) ) );
63 dataModelInserted( dm );
68 /*! Remove data model from list
69 * \param dm data model
70 * \retval true - if all ok, else false.
72 bool CAM_Study::removeDataModel( const CAM_DataModel* dm )
77 CAM_RootObject* aModelRoot = dynamic_cast<CAM_RootObject*>( dm->root() );
79 aModelRoot->setDataModel( 0 );
81 return myDataModels.remove( dm );
84 /*!Check data model contains in list.
85 * \param dm - data model
86 * \retval true - if data model in list, else false.
88 bool CAM_Study::containsDataModel( const CAM_DataModel* dm ) const
90 return myDataModels.contains( dm );
93 /*!Gets list of all data models.
94 * \param lst - output data model list.
96 void CAM_Study::dataModels( ModelList& lst ) const
99 for ( ModelListIterator it( myDataModels ); it.current(); ++it )
100 lst.append( it.current() );
103 /*! Open data model \a dModel, if it saved*/
104 void CAM_Study::dataModelInserted( const CAM_DataModel* dModel )
106 CAM_DataModel* dm = (CAM_DataModel*)dModel;
108 if ( isSaved() ) // need to load data model from an exisitng file?
109 openDataModel( studyName(), dm );
110 else // no, just need to update data model's connection to study tree
111 //(some application may want to show model's root in a study tree even if a model is empty)
114 updateModelRoot( dm );
119 bool CAM_Study::openDataModel( const QString&, CAM_DataModel* )
125 bool CAM_Study::saveDataModel( const QString&, CAM_DataModel* )
130 /*! Public slot. Update model root.*/
131 void CAM_Study::updateModelRoot( const CAM_DataModel* dm )
136 DataObjectList childList;
137 root()->children( childList );
138 CAM_DataObject* curRoot = 0;
139 QString aName = dm->root() ? dm->root()->name() : dm->module()->moduleName();
141 for ( int n = childList.count(); i < n; i++ ) {
142 if ( childList.at( i )->name() == aName ) {
143 curRoot = dynamic_cast<CAM_DataObject*>( childList.at( i ) );
148 if ( curRoot == dm->root() )
151 // replacing old data model root with a new one - old root deleted here !
153 root()->replaceChild( curRoot, dm->root(), true );
155 int idx = myDataModels.findRef( dm );
157 root()->insertChild( dm->root(), idx );