1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File: LightApp_DataModel.cxx
23 // Created: 10/25/2004 10:36:06 AM
24 // Author: Sergey LITONIN
26 #include "LightApp_DataModel.h"
27 #include "LightApp_Study.h"
28 #include "LightApp_DataObject.h"
29 #include "LightApp_Module.h"
30 #include "LightApp_Application.h"
32 #include <SUIT_TreeModel.h>
33 #include <SUIT_DataBrowser.h>
34 #include <SUIT_DataObject.h>
39 LightApp_DataModel::LightApp_DataModel( CAM_Module* theModule )
40 : CAM_DataModel( theModule )
44 myGroupId = qHash( module()->name() );
50 LightApp_DataModel::~LightApp_DataModel()
57 bool LightApp_DataModel::open( const QString&, CAM_Study* study, QStringList )
59 emit opened(); //TODO: is it really needed? to be removed maybe...
66 bool LightApp_DataModel::save( QStringList& )
75 bool LightApp_DataModel::saveAs( const QString&, CAM_Study*, QStringList& )
84 bool LightApp_DataModel::close()
91 Build whole data model tree
93 void LightApp_DataModel::build()
98 Updates data model presentation in some widgets (for example, in object browser
100 void LightApp_DataModel::updateWidgets()
102 LightApp_Application* app = dynamic_cast<LightApp_Application*>( module()->application() );
104 app->objectBrowser()->updateTree( 0, false );
108 Default behaviour of data model update for light modules
110 void LightApp_DataModel::update( LightApp_DataObject*, LightApp_Study* )
112 LightApp_ModuleObject* modelRoot = dynamic_cast<LightApp_ModuleObject*>( root() );
114 QMap<SUIT_DataObject*,int> aMap;
117 ch = modelRoot->children();
118 QListIterator<SUIT_DataObject*> it( ch );
119 while ( it.hasNext() )
120 it.next()->setParent( 0 );
125 modelRoot = dynamic_cast<LightApp_ModuleObject*>( root() );
128 DataObjectList new_ch = modelRoot->children();
129 QListIterator<SUIT_DataObject*> it1( new_ch );
130 while ( it1.hasNext() )
131 aMap.insert( it1.next(), 0 );
136 QListIterator<SUIT_DataObject*> it( ch );
137 while ( it.hasNext() ) {
138 SUIT_DataObject* aDO = it.next();
139 if( !aMap.contains( aDO ) )
145 \return corresponding module
147 LightApp_Module* LightApp_DataModel::getModule() const
149 return dynamic_cast<LightApp_Module*>( module() );
153 \return corresponding study
155 LightApp_Study* LightApp_DataModel::getStudy() const
157 LightApp_RootObject* aRoot = dynamic_cast<LightApp_RootObject*>( root()->root() );
160 return aRoot->study();
164 default implementation, always returns false so as not to mask study's isModified()
166 bool LightApp_DataModel::isModified() const
172 default implementation, always returns true so as not to mask study's isSaved()
174 bool LightApp_DataModel::isSaved() const
180 \return data model group id used for custom columns creation
182 int LightApp_DataModel::groupId() const
188 Register custom column in the object browser
189 \param browser - object browser where new column should be created
190 \param name - translated column name
191 \param custom_id - custom column identificator passed into data object's methods text(), icon() etc
193 void LightApp_DataModel::registerColumn( SUIT_DataBrowser* browser, const QString& name, const int custom_id )
195 SUIT_AbstractModel* m = dynamic_cast<SUIT_AbstractModel*>( browser ? browser->model() : 0 );
197 m->registerColumn( groupId(), name, custom_id );
201 Remove registered custom column from the object browser
202 \param browser - object browser where new column should be created
203 \param name - translated column name
205 void LightApp_DataModel::unregisterColumn( SUIT_DataBrowser* browser, const QString& name )
207 SUIT_AbstractModel* m = dynamic_cast<SUIT_AbstractModel*>( browser ? browser->model() : 0 );
209 m->unregisterColumn( groupId(), name );