Merge pull request #7463 from m-kuhn/fixFreeze

Avoid repeated update of edit selection
This commit is contained in:
Matthias Kuhn 2018-07-25 07:48:47 +02:00 committed by GitHub
commit 263ce39c79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 26 deletions

View File

@ -398,40 +398,46 @@ void QgsFeatureListView::ensureEditSelection( bool inSelection )
if ( editSelectionUpdateRequested )
{
QTimer::singleShot( 0, this, [ this, inSelection, validEditSelectionAvailable ]()
if ( !mUpdateEditSelectionTimer.isSingleShot() )
{
// The layer might have been removed between timer start and timer triggered
// in this case there is nothing left for us to do.
if ( !layerCache() )
return;
int rowToSelect = -1;
if ( inSelection )
mUpdateEditSelectionTimer.setSingleShot( true );
connect( &mUpdateEditSelectionTimer, &QTimer::timeout, this, [ this, inSelection, validEditSelectionAvailable ]()
{
const QgsFeatureIds selectedFids = layerCache()->layer()->selectedFeatureIds();
const int rowCount = mModel->rowCount();
// The layer might have been removed between timer start and timer triggered
// in this case there is nothing left for us to do.
if ( !layerCache() )
return;
for ( int i = 0; i < rowCount; i++ )
int rowToSelect = -1;
if ( inSelection )
{
if ( selectedFids.contains( mModel->idxToFid( mModel->index( i, 0 ) ) ) )
const QgsFeatureIds selectedFids = layerCache()->layer()->selectedFeatureIds();
const int rowCount = mModel->rowCount();
for ( int i = 0; i < rowCount; i++ )
{
rowToSelect = i;
break;
if ( selectedFids.contains( mModel->idxToFid( mModel->index( i, 0 ) ) ) )
{
rowToSelect = i;
break;
}
if ( rowToSelect == -1 && !validEditSelectionAvailable )
rowToSelect = 0;
}
if ( rowToSelect == -1 && !validEditSelectionAvailable )
rowToSelect = 0;
}
}
else
rowToSelect = 0;
else
rowToSelect = 0;
if ( rowToSelect != -1 )
{
setEditSelection( mModel->mapToMaster( mModel->index( rowToSelect, 0 ) ), QItemSelectionModel::ClearAndSelect );
}
} );
if ( rowToSelect != -1 )
{
setEditSelection( mModel->mapToMaster( mModel->index( rowToSelect, 0 ) ), QItemSelectionModel::ClearAndSelect );
}
} );
mUpdateEditSelectionTimer.setInterval( 0 );
}
mUpdateEditSelectionTimer.start();
}
}

View File

@ -203,6 +203,7 @@ class GUI_EXPORT QgsFeatureListView : public QListView
int mRowAnchor = 0;
QItemSelectionModel::SelectionFlags mCtrlDragSelectionFlag;
QTimer mUpdateEditSelectionTimer;
};
#endif