From f391af64cb6f20c6c1a0e883cd1e977614dd9842 Mon Sep 17 00:00:00 2001 From: asl Date: Wed, 5 Apr 2006 06:21:45 +0000 Subject: [PATCH] The standard way of update "Light" data models is provided. To use it, it is necessary to reimplement virtual method build and (if necessary) updateWidgets. By standard way, the children of first level are disconnected from parent (setParent(0)), after that new data model is created (using virtual method build), with help of updateWidgets all widgets are updated in order to show correct data model (by standard, this is only object browser) and after that all old objects are deleted. Method build must only create objects, it is forbidden to delete them there --- src/LightApp/LightApp_DataModel.cxx | 37 +++++++++++++++++++++++++++-- src/LightApp/LightApp_DataModel.h | 3 ++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/LightApp/LightApp_DataModel.cxx b/src/LightApp/LightApp_DataModel.cxx index 6ccba618b..3eee894b6 100644 --- a/src/LightApp/LightApp_DataModel.cxx +++ b/src/LightApp/LightApp_DataModel.cxx @@ -6,10 +6,11 @@ #include "LightApp_DataModel.h" #include "LightApp_Study.h" #include "LightApp_RootObject.h" +#include "LightApp_DataObject.h" #include "LightApp_Module.h" #include "LightApp_Application.h" -#include +#include #include #include @@ -73,12 +74,44 @@ bool LightApp_DataModel::close() return true; } +//================================================================ +// Function : build +/*! Purpose : Build whole data model tree */ +//================================================================ +void LightApp_DataModel::build() +{ +} + +//================================================================ +// Function : updateWidgets +/*! Purpose : Update data model presentation in some widgets + * (for example, in object browser*/ +//================================================================ +void LightApp_DataModel::updateWidgets() +{ + LightApp_Application* app = dynamic_cast( module()->application() ); + if( app ) + app->objectBrowser()->updateTree( 0, false ); +} + //================================================================ // Function : update /*! Purpose : Update application (empty virtual function).*/ //================================================================ -void LightApp_DataModel::update( LightApp_DataObject*, LightApp_Study* study ) +void LightApp_DataModel::update( LightApp_DataObject*, LightApp_Study* ) { + LightApp_ModuleObject* modelRoot = dynamic_cast( root() ); + DataObjectList ch; + if( modelRoot ) + { + ch = modelRoot->children(); + for ( DataObjectListIterator it( ch ); it.current(); ++it ) + it.current()->setParent( 0 ); + } + build(); + updateWidgets(); + for( DataObjectListIterator it( ch ); it.current(); ++it ) + delete it.current(); } //================================================================ diff --git a/src/LightApp/LightApp_DataModel.h b/src/LightApp/LightApp_DataModel.h index 7b1f92d6c..c0504a473 100644 --- a/src/LightApp/LightApp_DataModel.h +++ b/src/LightApp/LightApp_DataModel.h @@ -47,7 +47,8 @@ signals: protected: LightApp_Study* getStudy() const; - + virtual void build(); + virtual void updateWidgets(); }; #endif -- 2.39.2