From: san Date: Mon, 28 May 2012 17:24:39 +0000 (+0000) Subject: SUIT_DataObject::setModified() became virtual, it infroms the tree model about the... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=487b1c096c815985a350103e8cf06b14bad099c1;p=modules%2Fgui.git SUIT_DataObject::setModified() became virtual, it infroms the tree model about the data change with help of a new modified(SUIT_DataObject*) signal. SUIT_AbstractModel::setVisibilityState() got the 3rd argument that can be used to block dataChanged() signal --- diff --git a/src/SUIT/SUIT_DataObject.cxx b/src/SUIT/SUIT_DataObject.cxx index aa6e2bd29..a549917fa 100755 --- a/src/SUIT/SUIT_DataObject.cxx +++ b/src/SUIT/SUIT_DataObject.cxx @@ -398,6 +398,24 @@ void SUIT_DataObject::assignParent( SUIT_DataObject* p ) myParent = p; } +/*! + \brief Sets modification state of the object. + + When the object has been modified (modified is set to true) + a signal is emitted to notify the tree model and eventually redraw the data object. + + \param modified modified state +*/ +void SUIT_DataObject::setModified(bool modified) +{ + if ( _modified == modified ) + return; + + _modified = modified; + if ( _modified ) + signal()->emitModified( this ); +} + /*! \brief Get data object name. @@ -927,6 +945,15 @@ void SUIT_DataObject::Signal::emitRemoved( SUIT_DataObject* object, SUIT_DataObj emit( removed( object, parent ) ); } +/*! + \brief Emit a signal to notify that the data object has been modified. + \param object data object that has been modified +*/ +void SUIT_DataObject::Signal::emitModified( SUIT_DataObject* object ) +{ + emit( modified( object ) ); +} + /*! \brief Schedule data object for the late deleting. \param object data object to be deleted later diff --git a/src/SUIT/SUIT_DataObject.h b/src/SUIT/SUIT_DataObject.h index 8f35fb66e..a9968dd75 100755 --- a/src/SUIT/SUIT_DataObject.h +++ b/src/SUIT/SUIT_DataObject.h @@ -100,7 +100,7 @@ public: virtual void assignParent( SUIT_DataObject* ); void insertChildAtPos( SUIT_DataObject* obj, int position ); bool modified(){return _modified;}; - void setModified(bool modified){_modified = modified;}; + virtual void setModified(bool modified); virtual QString name() const; virtual QString text( const int = NameId ) const; @@ -172,6 +172,7 @@ private: void emitDestroyed( SUIT_DataObject* ); void emitInserted( SUIT_DataObject*, SUIT_DataObject* ); void emitRemoved( SUIT_DataObject*, SUIT_DataObject* ); + void emitModified( SUIT_DataObject* ); void deleteLater( SUIT_DataObject* ); @@ -180,6 +181,7 @@ signals: void destroyed( SUIT_DataObject* ); void inserted( SUIT_DataObject*, SUIT_DataObject* ); void removed( SUIT_DataObject*, SUIT_DataObject* ); + void modified( SUIT_DataObject* ); friend class SUIT_DataObject; diff --git a/src/SUIT/SUIT_TreeModel.cxx b/src/SUIT/SUIT_TreeModel.cxx index 3bab26044..fc6d98515 100755 --- a/src/SUIT/SUIT_TreeModel.cxx +++ b/src/SUIT/SUIT_TreeModel.cxx @@ -482,6 +482,8 @@ SUIT_TreeModel::~SUIT_TreeModel() this, SLOT( onInserted( SUIT_DataObject*, SUIT_DataObject* ) ) ); SUIT_DataObject::disconnect( SIGNAL( removed( SUIT_DataObject*, SUIT_DataObject* ) ), this, SLOT( onRemoved( SUIT_DataObject*, SUIT_DataObject* ) ) ); + SUIT_DataObject::disconnect( SIGNAL( modifed( SUIT_DataObject* ) ), + this, SLOT( onModified( SUIT_DataObject* ) ) ); delete myRoot; } @@ -668,8 +670,10 @@ Qtx::HeaderViewFlags SUIT_TreeModel::headerFlags( const QString& name ) const \param id - column name \param state - visible state + \param emitChanged - if set to false, blocks dataChanged() signal, this can be used to + prevent emitting dataChanged() several times for the same data object */ -void SUIT_TreeModel::setVisibilityState( const QString& id, Qtx::VisibilityState state ) +void SUIT_TreeModel::setVisibilityState( const QString& id, Qtx::VisibilityState state, bool emitChanged ) { VisibilityMap::const_iterator it = myVisibilityMap.find( id ); if ( it != myVisibilityMap.end() && it.value() == state ) @@ -683,7 +687,7 @@ void SUIT_TreeModel::setVisibilityState( const QString& id, Qtx::VisibilityState else { needSignal = myVisibilityMap.remove( id ) > 0; } - if ( needSignal ) { + if ( emitChanged && needSignal ) { QModelIndexList lst; if ( searcher() ) { SUIT_DataObject* o = searcher()->findObject( id ); @@ -702,7 +706,6 @@ void SUIT_TreeModel::setVisibilityState( const QString& id, Qtx::VisibilityState /*! \brief Set visibility state for all objects. - \param id - column name \param state - visible state */ void SUIT_TreeModel::setVisibilityStateForAll( Qtx::VisibilityState state ) @@ -774,6 +777,8 @@ void SUIT_TreeModel::setRoot( SUIT_DataObject* r ) this, SLOT( onInserted( SUIT_DataObject*, SUIT_DataObject* ) ) ); SUIT_DataObject::disconnect( SIGNAL( removed( SUIT_DataObject*, SUIT_DataObject* ) ), this, SLOT( onRemoved( SUIT_DataObject*, SUIT_DataObject* ) ) ); + SUIT_DataObject::disconnect( SIGNAL( modified( SUIT_DataObject* ) ), + this, SLOT( onModified( SUIT_DataObject* ) ) ); delete myRoot; if ( myRootItem ) { @@ -1255,6 +1260,8 @@ void SUIT_TreeModel::setAutoUpdate( const bool on ) this, SLOT( onInserted( SUIT_DataObject*, SUIT_DataObject* ) ) ); SUIT_DataObject::disconnect( SIGNAL( removed( SUIT_DataObject*, SUIT_DataObject* ) ), this, SLOT( onRemoved( SUIT_DataObject*, SUIT_DataObject* ) ) ); + SUIT_DataObject::disconnect( SIGNAL( modified( SUIT_DataObject* ) ), + this, SLOT( onModified( SUIT_DataObject* ) ) ); myAutoUpdate = on; if ( myAutoUpdate ) { @@ -1262,6 +1269,8 @@ void SUIT_TreeModel::setAutoUpdate( const bool on ) this, SLOT( onInserted( SUIT_DataObject*, SUIT_DataObject* ) ) ); SUIT_DataObject::connect( SIGNAL( removed( SUIT_DataObject*, SUIT_DataObject* ) ), this, SLOT( onRemoved( SUIT_DataObject*, SUIT_DataObject* ) ) ); + SUIT_DataObject::connect( SIGNAL( modified( SUIT_DataObject* ) ), + this, SLOT( onModified( SUIT_DataObject* ) ) ); updateTree(); } @@ -1452,11 +1461,15 @@ void SUIT_TreeModel::initialize() this, SLOT( onInserted( SUIT_DataObject*, SUIT_DataObject* ) ) ); SUIT_DataObject::disconnect( SIGNAL( removed( SUIT_DataObject*, SUIT_DataObject* ) ), this, SLOT( onRemoved( SUIT_DataObject*, SUIT_DataObject* ) ) ); + SUIT_DataObject::disconnect( SIGNAL( modified( SUIT_DataObject* ) ), + this, SLOT( onModified( SUIT_DataObject* ) ) ); if ( autoUpdate() ) { SUIT_DataObject::connect( SIGNAL( inserted( SUIT_DataObject*, SUIT_DataObject* ) ), this, SLOT( onInserted( SUIT_DataObject*, SUIT_DataObject* ) ) ); SUIT_DataObject::connect( SIGNAL( removed( SUIT_DataObject*, SUIT_DataObject* ) ), this, SLOT( onRemoved( SUIT_DataObject*, SUIT_DataObject* ) ) ); + SUIT_DataObject::connect( SIGNAL( modified( SUIT_DataObject* ) ), + this, SLOT( onModified( SUIT_DataObject* ) ) ); } myItems.clear(); // ????? is it really necessary @@ -1682,6 +1695,22 @@ void SUIT_TreeModel::onRemoved( SUIT_DataObject* /*object*/, SUIT_DataObject* pa updateTree( parent ); } +/*! + \brief Called when the data object is modified. TreeSync is not used here for maximum efficiency. + It is assumed that it is up to the application to decide when its data objects are modified. + \param obj data object that has been modified +*/ +void SUIT_TreeModel::onModified( SUIT_DataObject* obj ) +{ + if ( autoUpdate() ) + { + QModelIndex firstIdx = index( obj, 0 ); + QModelIndex lastIdx = index( obj, columnCount() - 1 ); + emit dataChanged( firstIdx, lastIdx ); + obj->setModified(false); + } +} + /*! \brief Drag and Drop support. */ @@ -2151,10 +2180,12 @@ Qtx::HeaderViewFlags SUIT_ProxyModel::headerFlags( const QString& name ) const { \param id - column name \param state - visible state + \param emitChanged - if set to false, blocks dataChanged() signal, this can be used to + prevent emitting dataChanged() several times for the same data object */ -void SUIT_ProxyModel::setVisibilityState(const QString& id, Qtx::VisibilityState state) { +void SUIT_ProxyModel::setVisibilityState(const QString& id, Qtx::VisibilityState state, bool emitChanged ) { if(treeModel()) - treeModel()->setVisibilityState(id,state); + treeModel()->setVisibilityState(id,state,emitChanged); } /*! diff --git a/src/SUIT/SUIT_TreeModel.h b/src/SUIT/SUIT_TreeModel.h index d8dd51a52..4d7812bab 100755 --- a/src/SUIT/SUIT_TreeModel.h +++ b/src/SUIT/SUIT_TreeModel.h @@ -81,7 +81,7 @@ public: virtual QPixmap columnIcon( const QString& name ) const = 0; virtual void setAppropriate( const QString& name, const Qtx::Appropriate appr ) = 0; virtual Qtx::Appropriate appropriate( const QString& name ) const = 0; - virtual void setVisibilityState(const QString& id, Qtx::VisibilityState state) = 0; + virtual void setVisibilityState(const QString& id, Qtx::VisibilityState state, bool emitChanged = true) = 0; virtual void setVisibilityStateForAll(Qtx::VisibilityState state) = 0; virtual Qtx::VisibilityState visibilityState(const QString& id) const = 0; virtual void setHeaderFlags( const QString& name, const Qtx::HeaderViewFlags flags ) = 0; @@ -151,7 +151,7 @@ public: virtual QPixmap columnIcon( const QString& name ) const; virtual void setAppropriate( const QString& name, const Qtx::Appropriate appr ); virtual Qtx::Appropriate appropriate( const QString& name ) const; - virtual void setVisibilityState(const QString& id, Qtx::VisibilityState state); + virtual void setVisibilityState(const QString& id, Qtx::VisibilityState state, bool emitChanged = true); virtual void setVisibilityStateForAll(Qtx::VisibilityState state); virtual Qtx::VisibilityState visibilityState(const QString& id) const; virtual void setHeaderFlags( const QString& name, const Qtx::HeaderViewFlags flags ); @@ -209,6 +209,7 @@ private: private slots: void onInserted( SUIT_DataObject*, SUIT_DataObject* ); void onRemoved( SUIT_DataObject*, SUIT_DataObject* ); + void onModified( SUIT_DataObject* ); private: typedef QMap ItemMap; @@ -271,7 +272,7 @@ public: virtual QPixmap columnIcon( const QString& name ) const; virtual void setAppropriate( const QString& name, const Qtx::Appropriate appr ); virtual Qtx::Appropriate appropriate( const QString& name ) const; - virtual void setVisibilityState(const QString& id, Qtx::VisibilityState state); + virtual void setVisibilityState(const QString& id, Qtx::VisibilityState state, bool emitChanged = true); virtual void setVisibilityStateForAll(Qtx::VisibilityState state); virtual Qtx::VisibilityState visibilityState(const QString& id) const; virtual void setHeaderFlags( const QString& name, const Qtx::HeaderViewFlags flags );