Skip to content

Commit ce403b1

Browse files
committedMay 17, 2018
Add tests for sorting feature list by display expression
1 parent 44bb21d commit ce403b1

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed
 

‎tests/src/app/testqgsattributetable.cpp

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "qgsunittypes.h"
2727
#include "qgssettings.h"
2828
#include "qgsvectorfilewriter.h"
29+
#include "qgsfeaturelistmodel.h"
2930

3031
#include "qgstest.h"
3132

@@ -49,6 +50,7 @@ class TestQgsAttributeTable : public QObject
4950
void testFieldCalculationArea();
5051
void testNoGeom();
5152
void testSelected();
53+
void testSortByDisplayExpression();
5254

5355
private:
5456
QgisApp *mQgisApp = nullptr;
@@ -208,8 +210,6 @@ void TestQgsAttributeTable::testNoGeom()
208210
void TestQgsAttributeTable::testSelected()
209211
{
210212
// test attribute table opening in show selected mode
211-
QgsSettings s;
212-
213213
std::unique_ptr< QgsVectorLayer> tempLayer( new QgsVectorLayer( QStringLiteral( "LineString?crs=epsg:3111&field=pk:int&field=col1:double" ), QStringLiteral( "vl" ), QStringLiteral( "memory" ) ) );
214214
QVERIFY( tempLayer->isValid() );
215215

@@ -241,6 +241,38 @@ void TestQgsAttributeTable::testSelected()
241241
QVERIFY( dlg->mMainView->masterModel()->request().filterFids().isEmpty() );
242242
}
243243

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+
244276
void TestQgsAttributeTable::testRegression15974()
245277
{
246278
// Test duplicated rows in attribute table + two crashes.

0 commit comments

Comments
 (0)
Please sign in to comment.