25
25
#include " qgsmapcanvas.h"
26
26
#include " qgsunittypes.h"
27
27
#include " qgssettings.h"
28
+ #include " qgsvectorfilewriter.h"
28
29
29
30
#include " qgstest.h"
30
31
@@ -42,6 +43,7 @@ class TestQgsAttributeTable : public QObject
42
43
void cleanupTestCase ();// will be called after the last testfunction was executed.
43
44
void init () {} // will be called before each testfunction is executed.
44
45
void cleanup () {} // will be called after every testfunction.
46
+ void testRegression15974 ();
45
47
void testFieldCalculation ();
46
48
void testFieldCalculationArea ();
47
49
void testNoGeom ();
@@ -247,6 +249,34 @@ void TestQgsAttributeTable::testSelected()
247
249
QVERIFY ( dlg->mMainView ->masterModel ()->request ().filterFids ().isEmpty () );
248
250
}
249
251
252
+ void TestQgsAttributeTable::testRegression15974 ()
253
+ {
254
+ QString path = QDir::tempPath () + " /testshp15974.shp" ;
255
+ std::unique_ptr< QgsVectorLayer> tempLayer ( new QgsVectorLayer ( QStringLiteral ( " polygon?crs=epsg:4326&field=id:integer" ), QStringLiteral ( " vl" ), QStringLiteral ( " memory" ) ) );
256
+ QVERIFY ( tempLayer->isValid () );
257
+ QgsVectorFileWriter::writeAsVectorFormat ( tempLayer.get ( ), path, " system" , QgsCoordinateReferenceSystem ( 4326 ), " ESRI Shapefile" );
258
+ std::unique_ptr< QgsVectorLayer> shpLayer ( new QgsVectorLayer ( path, QStringLiteral ( " test" ), QStringLiteral ( " ogr" ) ) );
259
+ QgsFeature f1 ( shpLayer->dataProvider ()->fields (), 1 );
260
+ f1.setGeometry ( QgsGeometry ().fromWkt ( QStringLiteral ( " polygon(0 0, 1 1, 1 2, 1 0, 0 0))" ) ) );
261
+ QgsFeature f2 ( shpLayer->dataProvider ()->fields (), 2 );
262
+ f2.setGeometry ( QgsGeometry ().fromWkt ( QStringLiteral ( " polygon(0 0, 1 1, 1 2, 1 0, 0 0))" ) ) );
263
+ QgsFeature f3 ( shpLayer->dataProvider ()->fields (), 3 );
264
+ f3.setGeometry ( QgsGeometry ().fromWkt ( QStringLiteral ( " polygon(0 0, 1 1, 1 2, 1 0, 0 0))" ) ) );
265
+ QVERIFY ( shpLayer->startEditing ( ) );
266
+ QVERIFY ( shpLayer->addFeatures ( QgsFeatureList () << f1 << f2 << f3 ) );
267
+ std::unique_ptr< QgsAttributeTableDialog > dlg ( new QgsAttributeTableDialog ( shpLayer.get () ) );
268
+ QCOMPARE ( shpLayer->featureCount ( ), 3L );
269
+ mQgisApp ->saveEdits ( shpLayer.get ( ) );
270
+ QCOMPARE ( shpLayer->featureCount ( ), 3L );
271
+ QCOMPARE ( dlg->mMainView ->masterModel ()->rowCount (), 3 );
272
+ QCOMPARE ( dlg->mMainView ->mLayerCache ->cachedFeatureIds ( ).count (), 3 );
273
+ QCOMPARE ( dlg->mMainView ->featureCount ( ), 3 );
274
+ // All the following instructions made the test pass, before the connections to invalidate()
275
+ // were introduced in QgsDualView::initModels
276
+ // dlg->mMainView->mFilterModel->setSourceModel( dlg->mMainView->masterModel() );
277
+ // dlg->mMainView->mFilterModel->invalidate();
278
+ QCOMPARE ( dlg->mMainView ->filteredFeatureCount ( ), 3 );
279
+ }
250
280
251
281
QGSTEST_MAIN ( TestQgsAttributeTable )
252
282
#include " testqgsattributetable.moc"
0 commit comments