From 65f269f30a3f4124cbc78a2426cc5ca2ec2fb060 Mon Sep 17 00:00:00 2001 From: mpv Date: Tue, 13 Mar 2012 04:28:46 +0000 Subject: [PATCH] Optimization of Object Browser update: on setAutoUpdate flag to true for tree of 30000 elements "updateItem" emits "changeLayout" signal for each item (evn for not-updated), that updated whole widget. Now it may be prevented by the autoUpdateLayout flag. --- src/SUIT/SUIT_DataBrowser.cxx | 27 +++++++++++++++ src/SUIT/SUIT_DataBrowser.h | 2 ++ src/SUIT/SUIT_TreeModel.cxx | 63 ++++++++++++++++++++++++++++++++++- src/SUIT/SUIT_TreeModel.h | 7 ++++ 4 files changed, 98 insertions(+), 1 deletion(-) diff --git a/src/SUIT/SUIT_DataBrowser.cxx b/src/SUIT/SUIT_DataBrowser.cxx index f470f6397..439a84601 100644 --- a/src/SUIT/SUIT_DataBrowser.cxx +++ b/src/SUIT/SUIT_DataBrowser.cxx @@ -116,6 +116,33 @@ void SUIT_DataBrowser::setAutoUpdate( const bool on ) m->setAutoUpdate( on ); } +/*! + \brief Get 'auto-update layout tree' flag value. + \return 'auto-update layout tree' flag value + \sa setAutoUpdateLayout(), updateTree() +*/ +bool SUIT_DataBrowser::autoUpdateLayout() const +{ + SUIT_ProxyModel* m = qobject_cast( model() ); + return m ? m->autoUpdateLayout() : false; +} + +/*! + \brief Set 'auto-update layout tree' flag value. + + If this flag is set to \c true (by default), the 'layoutChanged' signal is emitted + for each item update automatically. + + \param on 'auto-update layout tree' flag value + \sa autoUpdateLayout(), updateTree() +*/ +void SUIT_DataBrowser::setAutoUpdateLayout( const bool on ) +{ + SUIT_ProxyModel* m = qobject_cast( model() ); + if ( m ) + m->setAutoUpdateLayout( on ); +} + /*! \brief Get 'updateModified' flag value. \return 'updateModified' flag value diff --git a/src/SUIT/SUIT_DataBrowser.h b/src/SUIT/SUIT_DataBrowser.h index c7976283e..84ba5116b 100644 --- a/src/SUIT/SUIT_DataBrowser.h +++ b/src/SUIT/SUIT_DataBrowser.h @@ -48,6 +48,8 @@ public: bool autoUpdate() const; void setAutoUpdate( const bool ); + bool autoUpdateLayout() const; + void setAutoUpdateLayout( const bool ); bool updateModified() const; void setUpdateModified( const bool ); diff --git a/src/SUIT/SUIT_TreeModel.cxx b/src/SUIT/SUIT_TreeModel.cxx index a6ff0c455..060502d01 100755 --- a/src/SUIT/SUIT_TreeModel.cxx +++ b/src/SUIT/SUIT_TreeModel.cxx @@ -451,6 +451,7 @@ SUIT_TreeModel::SUIT_TreeModel( QObject* parent ) myRootItem( 0 ), myAutoDeleteTree( false ), myAutoUpdate( true ), + myAutoUpdateLayout( true ), myUpdateModified( false ) { initialize(); @@ -467,6 +468,7 @@ SUIT_TreeModel::SUIT_TreeModel( SUIT_DataObject* root, QObject* parent ) myRootItem( 0 ), myAutoDeleteTree( false ), myAutoUpdate( true ), + myAutoUpdateLayout( true ), myUpdateModified( false ) { initialize(); @@ -1231,6 +1233,16 @@ bool SUIT_TreeModel::autoUpdate() const return myAutoUpdate; } +/*! + \brief Get 'auto-update layout tree' flag value. + \return 'auto-update layout tree' flag value + \sa setAutoUpdateLayout(), updateItem() +*/ +bool SUIT_TreeModel::autoUpdateLayout() const +{ + return myAutoUpdateLayout; +} + /*! \brief Set 'auto-update tree' flag value. @@ -1259,6 +1271,28 @@ void SUIT_TreeModel::setAutoUpdate( const bool on ) updateTree(); } + +} + +/*! + \brief Set 'auto-update layout tree' flag value. + + If this flag is set to \c true (by default), the 'layoutChanged' signal is emitted + for each item update automatically. + + \param on 'auto-update layout tree' flag value + \sa autoUpdateLayout(), updateItem() +*/ +void SUIT_TreeModel::setAutoUpdateLayout( const bool on ) +{ + if ( myAutoUpdateLayout == on ) + return; + + myAutoUpdateLayout = on; + + if (myAutoUpdateLayout) { + emit layoutChanged(); + } } /*! @@ -1608,7 +1642,9 @@ void SUIT_TreeModel::updateItem( SUIT_TreeModel::TreeItem* item ) QModelIndex lastIdx = index( obj, columnCount() - 1 ); emit dataChanged( firstIdx, lastIdx ); obj->setModified(false); - emit layoutChanged(); + if (myAutoUpdateLayout) { // MPV 12/03/2012: update whole layout for each item is bad for performance + emit layoutChanged(); + } } /*! @@ -1866,6 +1902,16 @@ bool SUIT_ProxyModel::autoUpdate() const return treeModel() ? treeModel()->autoUpdate() : false; } +/*! + \brief Get 'auto-update layout tree' flag value. + \return 'auto-update layout tree' flag value + \sa setAutoUpdateLayout(), updateItem() +*/ +bool SUIT_ProxyModel::autoUpdateLayout() const +{ + return treeModel() ? treeModel()->autoUpdateLayout() : false; +} + /*! \brief Get 'updateModified' flag value. \return 'updateModified' flag value @@ -1903,6 +1949,21 @@ void SUIT_ProxyModel::setAutoUpdate( const bool on ) treeModel()->setAutoUpdate( on ); } +/*! + \brief Set 'auto-update layout tree' flag value. + + If this flag is set to \c true (by default), the 'layoutChanged' signal is emitted + for each item update automatically. + + \param on 'auto-update layout tree' flag value + \sa autoUpdateLayout(), updateItem() +*/ +void SUIT_ProxyModel::setAutoUpdateLayout( const bool on ) +{ + if ( treeModel() ) + treeModel()->setAutoUpdateLayout( on ); +} + /*! \brief Check if sorting is enabled. \return \c true if sorting is enabled diff --git a/src/SUIT/SUIT_TreeModel.h b/src/SUIT/SUIT_TreeModel.h index 8a259da3b..435bfc92d 100755 --- a/src/SUIT/SUIT_TreeModel.h +++ b/src/SUIT/SUIT_TreeModel.h @@ -66,6 +66,8 @@ public: virtual void setAutoDeleteTree( const bool ) = 0; virtual bool autoUpdate() const = 0; virtual void setAutoUpdate( const bool ) = 0; + virtual bool autoUpdateLayout() const = 0; + virtual void setAutoUpdateLayout( const bool ) = 0; virtual bool updateModified() const = 0; virtual void setUpdateModified( const bool ) = 0; virtual QAbstractItemDelegate* delegate() const = 0; @@ -167,6 +169,8 @@ public: bool autoUpdate() const; void setAutoUpdate( const bool ); + bool autoUpdateLayout() const; + void setAutoUpdateLayout( const bool ); bool updateModified() const; void setUpdateModified( const bool ); @@ -230,6 +234,7 @@ private: VisibilityMap myVisibilityMap; bool myAutoDeleteTree; bool myAutoUpdate; + bool myAutoUpdateLayout; bool myUpdateModified; QVector myColumns; @@ -257,6 +262,8 @@ public: bool autoUpdate() const; void setAutoUpdate( const bool ); + bool autoUpdateLayout() const; + void setAutoUpdateLayout( const bool ); bool updateModified() const; void setUpdateModified( const bool ); -- 2.39.2