Skip to content

Commit

Permalink
Avoid repeated update of edit selection
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Jul 24, 2018
1 parent 10a66da commit 99f8d48
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
58 changes: 32 additions & 26 deletions src/gui/attributetable/qgsfeaturelistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
1 change: 1 addition & 0 deletions src/gui/attributetable/qgsfeaturelistview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.