#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 );
PdmUiItem* pdmItemRoot();
void updateSubTree( PdmUiItem* root ) { this->updateMySubTree( root ); }
void updateSubTree( PdmUiItem* root, bool notifyEditors ) { this->updateMySubTree( root, notifyEditors ); }
protected:
virtual QWidget* createWidget( QWidget* parent ) = 0;
/// 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
virtual void updateMySubTree( PdmUiItem* root ) = 0;
virtual void updateMySubTree( PdmUiItem* root, bool notifyEditors ) = 0;
protected:
QPointer<QWidget> m_widget;

View File

@ -55,7 +55,8 @@ void PdmUiTreeItemEditor::configureAndUpdateUi( const QString& uiConfigName )
{
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 );
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 )
{
@ -324,7 +324,7 @@ void PdmUiTreeViewEditor::updateMySubTree( PdmUiItem* uiItem )
}
}
m_treeViewModel->updateSubTree( itemToUpdate );
m_treeViewModel->updateSubTree( itemToUpdate, notifyEditors );
QModelIndex itemIndex = m_treeViewModel->findModelIndex( itemToUpdate );
updateItemDelegateForSubTree( itemIndex );
}

View File

@ -139,7 +139,7 @@ signals:
protected:
void configureAndUpdateUi( const QString& uiConfigName ) override;
void updateMySubTree( PdmUiItem* uiItem ) override;
void updateMySubTree( PdmUiItem* uiItem, bool notifyEditors ) override;
void updateContextMenuSignals();
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 );
return true;

View File

@ -82,7 +82,8 @@ void PdmUiTreeViewQModel::setPdmItemRoot( PdmUiItem* rootItem )
// Check if we are already watching this root
if ( rootItem && m_treeOrderingRoot && m_treeOrderingRoot->activeItem() == rootItem )
{
this->updateSubTree( rootItem );
bool notifyEditors = false;
this->updateSubTree( rootItem, notifyEditors );
return;
}
@ -148,7 +149,7 @@ void PdmUiTreeViewQModel::emitDataChanged( const QModelIndex& index )
//--------------------------------------------------------------------------------------------------
/// 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
@ -193,7 +194,7 @@ void PdmUiTreeViewQModel::updateSubTree( PdmUiItem* pdmRoot )
existingSubTreeRoot->debugDump( 0 );
#endif
updateSubTreeRecursive( existingSubTreeRootModIdx, existingSubTreeRoot, newTreeRootTmp );
updateSubTreeRecursive( existingSubTreeRootModIdx, existingSubTreeRoot, newTreeRootTmp, notifyEditors );
delete newTreeRootTmp;
@ -225,7 +226,8 @@ public:
//--------------------------------------------------------------------------------------------------
void PdmUiTreeViewQModel::updateSubTreeRecursive( const QModelIndex& existingSubTreeRootModIdx,
PdmUiTreeOrdering* existingSubTreeRoot,
PdmUiTreeOrdering* sourceSubTreeRoot )
PdmUiTreeOrdering* sourceSubTreeRoot,
bool notifyEditors )
{
// Build map for source items
std::map<caf::PdmUiItem*, int> sourceTreeMap;
@ -296,14 +298,15 @@ void PdmUiTreeViewQModel::updateSubTreeRecursive( const QModelIndex& existingSub
if ( !anyChanges )
{
// 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
for ( int i = 0; i < existingSubTreeRoot->childCount(); ++i )
{
updateSubTreeRecursive( index( i, 0, existingSubTreeRootModIdx ),
existingSubTreeRoot->child( i ),
sourceSubTreeRoot->child( i ) );
sourceSubTreeRoot->child( i ),
notifyEditors );
}
}
else
@ -311,7 +314,7 @@ void PdmUiTreeViewQModel::updateSubTreeRecursive( const QModelIndex& existingSub
std::vector<RecursiveUpdateData> recursiveUpdateData;
std::vector<PdmUiTreeOrdering*> newMergedOrdering;
emit layoutAboutToBeChanged();
if ( notifyEditors ) emit layoutAboutToBeChanged();
{
// Detect items to be moved from source to existing
// 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
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 );
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();
void setPdmItemRoot( PdmUiItem* rootItem );
void updateSubTree( PdmUiItem* subTreeRoot );
void updateSubTree( PdmUiItem* subTreeRoot, bool notifyEditors );
void setColumnHeaders( const QStringList& columnHeaders );
void setUiConfigName( const QString& uiConfigName ) { m_uiConfigName = uiConfigName; }
@ -81,7 +81,8 @@ public:
private:
void updateSubTreeRecursive( const QModelIndex& uiSubTreeRootModelIdx,
PdmUiTreeOrdering* uiModelSubTreeRoot,
PdmUiTreeOrdering* updatedPdmSubTreeRoot );
PdmUiTreeOrdering* updatedPdmSubTreeRoot,
bool notifyEditors );
PdmUiTreeOrdering* treeItemFromIndex( const QModelIndex& index ) const;
QModelIndex findModelIndexRecursive( const QModelIndex& currentIndex, const PdmUiItem* object ) const;