@@ -45,6 +45,7 @@ class TestQgsAttributeTable : public QObject
45
45
void testFieldCalculation ();
46
46
void testFieldCalculationArea ();
47
47
void testNoGeom ();
48
+ void testSelected ();
48
49
49
50
private:
50
51
QgisApp *mQgisApp = nullptr ;
@@ -209,6 +210,43 @@ void TestQgsAttributeTable::testNoGeom()
209
210
210
211
}
211
212
213
+ void TestQgsAttributeTable::testSelected ()
214
+ {
215
+ // test attribute table opening in show selected mode
216
+ QgsSettings s;
217
+
218
+ std::unique_ptr< QgsVectorLayer> tempLayer ( new QgsVectorLayer ( QStringLiteral ( " LineString?crs=epsg:3111&field=pk:int&field=col1:double" ), QStringLiteral ( " vl" ), QStringLiteral ( " memory" ) ) );
219
+ QVERIFY ( tempLayer->isValid () );
220
+
221
+ QgsFeature f1 ( tempLayer->dataProvider ()->fields (), 1 );
222
+ QgsFeature f2 ( tempLayer->dataProvider ()->fields (), 2 );
223
+ QgsFeature f3 ( tempLayer->dataProvider ()->fields (), 3 );
224
+ QVERIFY ( tempLayer->dataProvider ()->addFeatures ( QgsFeatureList () << f1 << f2 << f3 ) );
225
+
226
+ s.setValue ( QStringLiteral ( " /qgis/attributeTableBehavior" ), QgsAttributeTableFilterModel::ShowSelected );
227
+ std::unique_ptr< QgsAttributeTableDialog > dlg ( new QgsAttributeTableDialog ( tempLayer.get () ) );
228
+
229
+ QVERIFY ( !dlg->mMainView ->masterModel ()->layerCache ()->cacheGeometry () );
230
+ // should be nothing - because no selection!
231
+ QCOMPARE ( dlg->mMainView ->masterModel ()->request ().filterType (), QgsFeatureRequest::FilterFids );
232
+ QVERIFY ( dlg->mMainView ->masterModel ()->request ().filterFids ().isEmpty () );
233
+
234
+ // make a selection
235
+ tempLayer->selectByIds ( QgsFeatureIds () << 1 << 3 );
236
+ QCOMPARE ( dlg->mMainView ->masterModel ()->request ().filterType (), QgsFeatureRequest::FilterFids );
237
+ QCOMPARE ( dlg->mMainView ->masterModel ()->request ().filterFids (), QgsFeatureIds () << 1 << 3 );
238
+
239
+ // another test - start with selection when dialog created
240
+ dlg.reset ( new QgsAttributeTableDialog ( tempLayer.get () ) );
241
+ QVERIFY ( !dlg->mMainView ->masterModel ()->layerCache ()->cacheGeometry () );
242
+ QCOMPARE ( dlg->mMainView ->masterModel ()->request ().filterType (), QgsFeatureRequest::FilterFids );
243
+ QCOMPARE ( dlg->mMainView ->masterModel ()->request ().filterFids (), QgsFeatureIds () << 1 << 3 );
244
+ // remove selection
245
+ tempLayer->removeSelection ();
246
+ QCOMPARE ( dlg->mMainView ->masterModel ()->request ().filterType (), QgsFeatureRequest::FilterFids );
247
+ QVERIFY ( dlg->mMainView ->masterModel ()->request ().filterFids ().isEmpty () );
248
+ }
249
+
212
250
213
251
QGSTEST_MAIN ( TestQgsAttributeTable )
214
252
#include " testqgsattributetable.moc"
0 commit comments