3 #include "CAM_DataModel.h"
4 #include "CAM_DataObject.h"
5 #include "CAM_RootObject.h"
6 #include "CAM_Module.h"
8 CAM_Study::CAM_Study( SUIT_Application* app )
13 CAM_Study::~CAM_Study()
17 void CAM_Study::closeDocument()
19 for ( ModelListIterator it( myDataModels ); it.current(); ++it )
20 it.current()->close();
22 SUIT_Study::closeDocument();
25 bool CAM_Study::appendDataModel( const CAM_DataModel* dm )
27 return insertDataModel( dm, myDataModels.count() );
30 bool CAM_Study::insertDataModel( const CAM_DataModel* dm, const CAM_DataModel* other )
32 int idx = myDataModels.findRef( other );
33 return insertDataModel( dm, idx < 0 ? idx : idx + 1 );
36 bool CAM_Study::insertDataModel( const CAM_DataModel* dm, const int idx )
38 if ( !dm || myDataModels.findRef( dm ) != -1 )
41 int pos = idx < 0 ? myDataModels.count() : idx;
42 myDataModels.insert( QMIN( pos, (int)myDataModels.count() ), dm );
44 connect( dm, SIGNAL( rootChanged( const CAM_DataModel* ) ), SLOT( updateModelRoot( const CAM_DataModel* ) ) );
46 dataModelInserted( dm );
51 bool CAM_Study::removeDataModel( const CAM_DataModel* dm )
56 CAM_RootObject* aModelRoot = dynamic_cast<CAM_RootObject*>( dm->root() );
58 aModelRoot->setDataModel( 0 );
60 return myDataModels.remove( dm );
63 bool CAM_Study::containsDataModel( const CAM_DataModel* dm ) const
65 return myDataModels.contains( dm );
68 void CAM_Study::dataModels( ModelList& lst ) const
71 for ( ModelListIterator it( myDataModels ); it.current(); ++it )
72 lst.append( it.current() );
75 void CAM_Study::dataModelInserted( const CAM_DataModel* dModel )
77 CAM_DataModel* dm = (CAM_DataModel*)dModel;
79 if ( isSaved() ) // need to load data model from an exisitng file?
80 openDataModel( studyName(), dm );
81 else // no, just need to update data model's connection to study tree
82 //(some application may want to show model's root in a study tree even if a model is empty)
85 updateModelRoot( dm );
89 bool CAM_Study::openDataModel( const QString&, CAM_DataModel* )
94 bool CAM_Study::saveDataModel( const QString&, CAM_DataModel* )
99 void CAM_Study::updateModelRoot( const CAM_DataModel* dm )
104 DataObjectList childList;
105 root()->children( childList );
106 CAM_DataObject* curRoot = 0;
107 QString aName = dm->root() ? dm->root()->name() : dm->module()->moduleName();
109 for ( int n = childList.count(); i < n; i++ ) {
110 if ( childList.at( i )->name() == aName ) {
111 curRoot = dynamic_cast<CAM_DataObject*>( childList.at( i ) );
116 if ( curRoot == dm->root() )
119 // replacing old data model root with a new one - old root deleted here !
121 root()->replaceChild( curRoot, dm->root(), true );
123 int idx = myDataModels.findRef( dm );
125 root()->insertChild( dm->root(), idx );