Skip to content
Permalink
Browse files

Avoid repeated update of edit selection

  • Loading branch information
m-kuhn committed Jul 24, 2018
1 parent 10a66da commit 99f8d4806abb00eb0957c518fdf17b177e1f61d5
Showing with 33 additions and 26 deletions.
  1. +32 −26 src/gui/attributetable/qgsfeaturelistview.cpp
  2. +1 −0 src/gui/attributetable/qgsfeaturelistview.h
@@ -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;

int rowToSelect = -1;

for ( int i = 0; i < rowCount; i++ )
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();
}
}

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

QTimer mUpdateEditSelectionTimer;
};

#endif

0 comments on commit 99f8d48

Please sign in to comment.
You can’t perform that action at this time.