mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#9023 Performance : Optionally avoid emitting update signals during update
Do not notify editors when building tree in PdmUiTreeViewQModel::setPdmItemRoot()
This commit is contained in:
@@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user