Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix select all features in attribute table #57140

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/qgsattributetabledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ void QgsAttributeTableDialog::mActionRemoveSelection_triggered()

void QgsAttributeTableDialog::mActionSelectAll_triggered()
{
mLayer->selectAll();
mLayer->selectByIds( mMainView->filteredFeatures(), Qgis::SelectBehavior::SetSelection );
}

void QgsAttributeTableDialog::mActionDeleteSelected_triggered()
Expand Down
35 changes: 35 additions & 0 deletions tests/src/app/testqgsattributetable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class TestQgsAttributeTable : public QObject
void testEnsureEditSelection();
private slots:
void testFetchAllAttributes();
void testSelectAll();

private:
QgisApp *mQgisApp = nullptr;
Expand Down Expand Up @@ -918,5 +919,39 @@ void TestQgsAttributeTable::testFetchAllAttributes()

}

void TestQgsAttributeTable::testSelectAll()
{
std::unique_ptr< QgsVectorLayer > layer = std::make_unique< QgsVectorLayer >( QStringLiteral( "Point?field=col0:integer&field=col1:integer" ), QStringLiteral( "test" ), QStringLiteral( "memory" ) );
QVERIFY( layer->isValid() );

QgsFeature ft1( layer->dataProvider()->fields(), 1 );
ft1.setAttributes( QgsAttributes() << 1 << 2 );
layer->dataProvider()->addFeature( ft1 );
QgsFeature ft2( layer->dataProvider()->fields(), 2 );
ft2.setAttributes( QgsAttributes() << 3 << 4 );
layer->dataProvider()->addFeature( ft2 );

layer->removeSelection();
std::unique_ptr< QgsAttributeTableDialog > dlg( new QgsAttributeTableDialog( layer.get() ) );

// select all
dlg->mActionSelectAll->trigger();
QCOMPARE( layer->selectedFeatures().size(), 2 );

// select all with expression matching single feature
const QString filterExpression = QStringLiteral( "col1 > 3" );
dlg->setFilterExpression( filterExpression, QgsAttributeForm::FilterType::ReplaceFilter );
dlg->mActionSelectAll->trigger();
const QList< QgsFeature > features = layer->selectedFeatures();
QCOMPARE( features.size(), 1 );
QCOMPARE( features[0].id(), 2 );

// select all with expression without matching features
dlg->setFilterExpression( QStringLiteral( "false" ), QgsAttributeForm::FilterType::ReplaceFilter );
dlg->mActionSelectAll->trigger();
QCOMPARE( layer->selectedFeatures().size(), 0 );

}

QGSTEST_MAIN( TestQgsAttributeTable )
#include "testqgsattributetable.moc"
Loading