#9023 Performance : Optionally avoid emitting update signals during update

Do not notify editors when building tree in PdmUiTreeViewQModel::setPdmItemRoot()
This commit is contained in:
Magne Sjaastad
2022-06-07 15:26:31 +02:00
parent 5b4434439e
commit 5eafa98038
8 changed files with 29 additions and 19 deletions

View File

@@ -61,14 +61,14 @@ public:
void setPdmItemRoot( PdmUiItem* root ); void setPdmItemRoot( PdmUiItem* root );
PdmUiItem* pdmItemRoot(); PdmUiItem* pdmItemRoot();
void updateSubTree( PdmUiItem* root ) { this->updateMySubTree( root ); } void updateSubTree( PdmUiItem* root, bool notifyEditors ) { this->updateMySubTree( root, notifyEditors ); }
protected: protected:
virtual QWidget* createWidget( QWidget* parent ) = 0; virtual QWidget* createWidget( QWidget* parent ) = 0;
/// Supposed to update the representation of the tree from root and downwards, as gracefully as possible. /// Supposed to update the representation of the tree from root and downwards, as gracefully as possible.
/// Will be called when the content of root might have been changed /// Will be called when the content of root might have been changed
virtual void updateMySubTree( PdmUiItem* root ) = 0; virtual void updateMySubTree( PdmUiItem* root, bool notifyEditors ) = 0;
protected: protected:
QPointer<QWidget> m_widget; QPointer<QWidget> m_widget;

View File

@@ -55,7 +55,8 @@ void PdmUiTreeItemEditor::configureAndUpdateUi( const QString& uiConfigName )
{ {
if ( m_treeViewEditor ) if ( m_treeViewEditor )
{ {
m_treeViewEditor->updateSubTree( this->pdmItem() ); bool notifyEditors = true;
m_treeViewEditor->updateSubTree( this->pdmItem(), notifyEditors );
} }
} }

View File

@@ -284,7 +284,8 @@ void PdmUiTreeView::updateSubTree( const QModelIndex& index )
auto uiItem = uiItemFromModelIndex( index ); auto uiItem = uiItemFromModelIndex( index );
if ( uiItem ) if ( uiItem )
{ {
m_treeViewEditor->updateSubTree( uiItem ); bool notifyEditors = true;
m_treeViewEditor->updateSubTree( uiItem, notifyEditors );
} }
} }

View File

@@ -306,7 +306,7 @@ void PdmUiTreeViewEditor::selectedUiItems( std::vector<PdmUiItem*>& objects )
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void PdmUiTreeViewEditor::updateMySubTree( PdmUiItem* uiItem ) void PdmUiTreeViewEditor::updateMySubTree( PdmUiItem* uiItem, bool notifyEditors )
{ {
if ( m_treeViewModel ) if ( m_treeViewModel )
{ {
@@ -324,7 +324,7 @@ void PdmUiTreeViewEditor::updateMySubTree( PdmUiItem* uiItem )
} }
} }
m_treeViewModel->updateSubTree( itemToUpdate ); m_treeViewModel->updateSubTree( itemToUpdate, notifyEditors );
QModelIndex itemIndex = m_treeViewModel->findModelIndex( itemToUpdate ); QModelIndex itemIndex = m_treeViewModel->findModelIndex( itemToUpdate );
updateItemDelegateForSubTree( itemIndex ); updateItemDelegateForSubTree( itemIndex );
} }

View File

@@ -139,7 +139,7 @@ signals:
protected: protected:
void configureAndUpdateUi( const QString& uiConfigName ) override; void configureAndUpdateUi( const QString& uiConfigName ) override;
void updateMySubTree( PdmUiItem* uiItem ) override; void updateMySubTree( PdmUiItem* uiItem, bool notifyEditors ) override;
void updateContextMenuSignals(); void updateContextMenuSignals();
private slots: private slots:

View File

@@ -292,7 +292,8 @@ bool PdmUiTreeViewItemDelegate::editorEvent( QEvent* event,
} }
} }
m_treeView->updateSubTree( parentUiItem ); bool notifyEditors = true;
m_treeView->updateSubTree( parentUiItem, notifyEditors );
m_treeView->selectAsCurrentItem( uiItem ); m_treeView->selectAsCurrentItem( uiItem );
return true; return true;

View File

@@ -82,7 +82,8 @@ void PdmUiTreeViewQModel::setPdmItemRoot( PdmUiItem* rootItem )
// Check if we are already watching this root // Check if we are already watching this root
if ( rootItem && m_treeOrderingRoot && m_treeOrderingRoot->activeItem() == rootItem ) if ( rootItem && m_treeOrderingRoot && m_treeOrderingRoot->activeItem() == rootItem )
{ {
this->updateSubTree( rootItem ); bool notifyEditors = false;
this->updateSubTree( rootItem, notifyEditors );
return; return;
} }
@@ -148,7 +149,7 @@ void PdmUiTreeViewQModel::emitDataChanged( const QModelIndex& index )
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// Refreshes the UI-tree below the supplied root PdmUiItem /// Refreshes the UI-tree below the supplied root PdmUiItem
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void PdmUiTreeViewQModel::updateSubTree( PdmUiItem* pdmRoot ) void PdmUiTreeViewQModel::updateSubTree( PdmUiItem* pdmRoot, bool notifyEditors )
{ {
// Build the new "Correct" Tree // Build the new "Correct" Tree
@@ -193,7 +194,7 @@ void PdmUiTreeViewQModel::updateSubTree( PdmUiItem* pdmRoot )
existingSubTreeRoot->debugDump( 0 ); existingSubTreeRoot->debugDump( 0 );
#endif #endif
updateSubTreeRecursive( existingSubTreeRootModIdx, existingSubTreeRoot, newTreeRootTmp ); updateSubTreeRecursive( existingSubTreeRootModIdx, existingSubTreeRoot, newTreeRootTmp, notifyEditors );
delete newTreeRootTmp; delete newTreeRootTmp;
@@ -225,7 +226,8 @@ public:
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void PdmUiTreeViewQModel::updateSubTreeRecursive( const QModelIndex& existingSubTreeRootModIdx, void PdmUiTreeViewQModel::updateSubTreeRecursive( const QModelIndex& existingSubTreeRootModIdx,
PdmUiTreeOrdering* existingSubTreeRoot, PdmUiTreeOrdering* existingSubTreeRoot,
PdmUiTreeOrdering* sourceSubTreeRoot ) PdmUiTreeOrdering* sourceSubTreeRoot,
bool notifyEditors )
{ {
// Build map for source items // Build map for source items
std::map<caf::PdmUiItem*, int> sourceTreeMap; std::map<caf::PdmUiItem*, int> sourceTreeMap;
@@ -296,14 +298,15 @@ void PdmUiTreeViewQModel::updateSubTreeRecursive( const QModelIndex& existingSub
if ( !anyChanges ) if ( !anyChanges )
{ {
// Notify Qt that the toggle/name/icon etc might have been changed // Notify Qt that the toggle/name/icon etc might have been changed
emitDataChanged( existingSubTreeRootModIdx ); if ( notifyEditors ) emitDataChanged( existingSubTreeRootModIdx );
// No changes to list of children at this level, call update on all children // No changes to list of children at this level, call update on all children
for ( int i = 0; i < existingSubTreeRoot->childCount(); ++i ) for ( int i = 0; i < existingSubTreeRoot->childCount(); ++i )
{ {
updateSubTreeRecursive( index( i, 0, existingSubTreeRootModIdx ), updateSubTreeRecursive( index( i, 0, existingSubTreeRootModIdx ),
existingSubTreeRoot->child( i ), existingSubTreeRoot->child( i ),
sourceSubTreeRoot->child( i ) ); sourceSubTreeRoot->child( i ),
notifyEditors );
} }
} }
else else
@@ -311,7 +314,7 @@ void PdmUiTreeViewQModel::updateSubTreeRecursive( const QModelIndex& existingSub
std::vector<RecursiveUpdateData> recursiveUpdateData; std::vector<RecursiveUpdateData> recursiveUpdateData;
std::vector<PdmUiTreeOrdering*> newMergedOrdering; std::vector<PdmUiTreeOrdering*> newMergedOrdering;
emit layoutAboutToBeChanged(); if ( notifyEditors ) emit layoutAboutToBeChanged();
{ {
// Detect items to be moved from source to existing // Detect items to be moved from source to existing
// Merge items from existing and source into newMergedOrdering using order in sourceSubTreeRoot // Merge items from existing and source into newMergedOrdering using order in sourceSubTreeRoot
@@ -360,7 +363,7 @@ void PdmUiTreeViewQModel::updateSubTreeRecursive( const QModelIndex& existingSub
} }
} }
emit layoutChanged(); if ( notifyEditors ) emit layoutChanged();
// Insert new items into existingSubTreeRoot // Insert new items into existingSubTreeRoot
for ( size_t i = 0; i < newMergedOrdering.size(); i++ ) for ( size_t i = 0; i < newMergedOrdering.size(); i++ )
@@ -380,7 +383,10 @@ void PdmUiTreeViewQModel::updateSubTreeRecursive( const QModelIndex& existingSub
QModelIndex mi = index( recursiveUpdateData[i].m_row, 0, existingSubTreeRootModIdx ); QModelIndex mi = index( recursiveUpdateData[i].m_row, 0, existingSubTreeRootModIdx );
CAF_ASSERT( mi.isValid() ); CAF_ASSERT( mi.isValid() );
updateSubTreeRecursive( mi, recursiveUpdateData[i].m_existingChild, recursiveUpdateData[i].m_sourceChild ); updateSubTreeRecursive( mi,
recursiveUpdateData[i].m_existingChild,
recursiveUpdateData[i].m_sourceChild,
notifyEditors );
} }
} }
} }

View File

@@ -63,7 +63,7 @@ public:
virtual ~PdmUiTreeViewQModel(); virtual ~PdmUiTreeViewQModel();
void setPdmItemRoot( PdmUiItem* rootItem ); void setPdmItemRoot( PdmUiItem* rootItem );
void updateSubTree( PdmUiItem* subTreeRoot ); void updateSubTree( PdmUiItem* subTreeRoot, bool notifyEditors );
void setColumnHeaders( const QStringList& columnHeaders ); void setColumnHeaders( const QStringList& columnHeaders );
void setUiConfigName( const QString& uiConfigName ) { m_uiConfigName = uiConfigName; } void setUiConfigName( const QString& uiConfigName ) { m_uiConfigName = uiConfigName; }
@@ -81,7 +81,8 @@ public:
private: private:
void updateSubTreeRecursive( const QModelIndex& uiSubTreeRootModelIdx, void updateSubTreeRecursive( const QModelIndex& uiSubTreeRootModelIdx,
PdmUiTreeOrdering* uiModelSubTreeRoot, PdmUiTreeOrdering* uiModelSubTreeRoot,
PdmUiTreeOrdering* updatedPdmSubTreeRoot ); PdmUiTreeOrdering* updatedPdmSubTreeRoot,
bool notifyEditors );
PdmUiTreeOrdering* treeItemFromIndex( const QModelIndex& index ) const; PdmUiTreeOrdering* treeItemFromIndex( const QModelIndex& index ) const;
QModelIndex findModelIndexRecursive( const QModelIndex& currentIndex, const PdmUiItem* object ) const; QModelIndex findModelIndexRecursive( const QModelIndex& currentIndex, const PdmUiItem* object ) const;