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;
void emitDestroyed( SUIT_DataObject* );
void emitInserted( SUIT_DataObject*, SUIT_DataObject* );
void emitRemoved( SUIT_DataObject*, SUIT_DataObject* );
+ void emitModified( SUIT_DataObject* );
void deleteLater( SUIT_DataObject* );
void destroyed( SUIT_DataObject* );
void inserted( SUIT_DataObject*, SUIT_DataObject* );
void removed( SUIT_DataObject*, SUIT_DataObject* );
+ void modified( SUIT_DataObject* );
friend class SUIT_DataObject;
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;
}
\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 )
else {
needSignal = myVisibilityMap.remove( id ) > 0;
}
- if ( needSignal ) {
+ if ( emitChanged && needSignal ) {
QModelIndexList lst;
if ( searcher() ) {
SUIT_DataObject* o = searcher()->findObject( id );
/*!
\brief Set visibility state for all objects.
- \param id - column name
\param state - visible state
*/
void SUIT_TreeModel::setVisibilityStateForAll( Qtx::VisibilityState state )
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 ) {
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 ) {
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();
}
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
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.
*/
\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);
}
/*!
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;
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 );
private slots:
void onInserted( SUIT_DataObject*, SUIT_DataObject* );
void onRemoved( SUIT_DataObject*, SUIT_DataObject* );
+ void onModified( SUIT_DataObject* );
private:
typedef QMap<SUIT_DataObject*, TreeItem*> ItemMap;
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 );