26
26
#include " qgsunittypes.h"
27
27
#include " qgssettings.h"
28
28
#include " qgsvectorfilewriter.h"
29
+ #include " qgsfeaturelistmodel.h"
29
30
30
31
#include " qgstest.h"
31
32
@@ -49,6 +50,7 @@ class TestQgsAttributeTable : public QObject
49
50
void testFieldCalculationArea ();
50
51
void testNoGeom ();
51
52
void testSelected ();
53
+ void testSortByDisplayExpression ();
52
54
53
55
private:
54
56
QgisApp *mQgisApp = nullptr ;
@@ -208,8 +210,6 @@ void TestQgsAttributeTable::testNoGeom()
208
210
void TestQgsAttributeTable::testSelected ()
209
211
{
210
212
// test attribute table opening in show selected mode
211
- QgsSettings s;
212
-
213
213
std::unique_ptr< QgsVectorLayer> tempLayer ( new QgsVectorLayer ( QStringLiteral ( " LineString?crs=epsg:3111&field=pk:int&field=col1:double" ), QStringLiteral ( " vl" ), QStringLiteral ( " memory" ) ) );
214
214
QVERIFY ( tempLayer->isValid () );
215
215
@@ -241,6 +241,38 @@ void TestQgsAttributeTable::testSelected()
241
241
QVERIFY ( dlg->mMainView ->masterModel ()->request ().filterFids ().isEmpty () );
242
242
}
243
243
244
+ void TestQgsAttributeTable::testSortByDisplayExpression ()
245
+ {
246
+ std::unique_ptr< QgsVectorLayer> tempLayer ( new QgsVectorLayer ( QStringLiteral ( " LineString?crs=epsg:3111&field=pk:int&field=col1:double" ), QStringLiteral ( " vl" ), QStringLiteral ( " memory" ) ) );
247
+ QVERIFY ( tempLayer->isValid () );
248
+
249
+ QgsFeature f1 ( tempLayer->dataProvider ()->fields (), 1 );
250
+ f1.setAttribute ( 0 , 1 );
251
+ f1.setAttribute ( 1 , 3.2 );
252
+ QgsFeature f2 ( tempLayer->dataProvider ()->fields (), 2 );
253
+ f2.setAttribute ( 0 , 2 );
254
+ f2.setAttribute ( 1 , 1.8 );
255
+ QgsFeature f3 ( tempLayer->dataProvider ()->fields (), 3 );
256
+ f3.setAttribute ( 0 , 3 );
257
+ f3.setAttribute ( 1 , 5.0 );
258
+ QVERIFY ( tempLayer->dataProvider ()->addFeatures ( QgsFeatureList () << f1 << f2 << f3 ) );
259
+
260
+ std::unique_ptr< QgsAttributeTableDialog > dlg ( new QgsAttributeTableDialog ( tempLayer.get () ) );
261
+
262
+ dlg->mMainView ->mFeatureList ->setDisplayExpression ( " pk" );
263
+ QgsFeatureListModel *listModel = dlg->mMainView ->mFeatureListModel ;
264
+ QCOMPARE ( listModel->rowCount (), 3 );
265
+
266
+ QCOMPARE ( listModel->index ( 0 , 0 ).data ( Qt::DisplayRole ), QVariant ( 1 ) );
267
+ QCOMPARE ( listModel->index ( 1 , 0 ).data ( Qt::DisplayRole ), QVariant ( 2 ) );
268
+ QCOMPARE ( listModel->index ( 2 , 0 ).data ( Qt::DisplayRole ), QVariant ( 3 ) );
269
+
270
+ dlg->mMainView ->mFeatureList ->setDisplayExpression ( " col1" );
271
+ QCOMPARE ( listModel->index ( 0 , 0 ).data ( Qt::DisplayRole ), QVariant ( 1.8 ) );
272
+ QCOMPARE ( listModel->index ( 1 , 0 ).data ( Qt::DisplayRole ), QVariant ( 3.2 ) );
273
+ QCOMPARE ( listModel->index ( 2 , 0 ).data ( Qt::DisplayRole ), QVariant ( 5.0 ) );
274
+ }
275
+
244
276
void TestQgsAttributeTable::testRegression15974 ()
245
277
{
246
278
// Test duplicated rows in attribute table + two crashes.
0 commit comments