Skip to content
Permalink
Browse files

Add tests for sorting feature list by display expression

  • Loading branch information
m-kuhn committed May 17, 2018
1 parent 44bb21d commit ce403b14d14af60900c5be80f0c68b4251bafa4a
Showing with 34 additions and 2 deletions.
  1. +34 −2 tests/src/app/testqgsattributetable.cpp
@@ -26,6 +26,7 @@
#include "qgsunittypes.h"
#include "qgssettings.h"
#include "qgsvectorfilewriter.h"
#include "qgsfeaturelistmodel.h"

#include "qgstest.h"

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

private:
QgisApp *mQgisApp = nullptr;
@@ -208,8 +210,6 @@ void TestQgsAttributeTable::testNoGeom()
void TestQgsAttributeTable::testSelected()
{
// test attribute table opening in show selected mode
QgsSettings s;

std::unique_ptr< QgsVectorLayer> tempLayer( new QgsVectorLayer( QStringLiteral( "LineString?crs=epsg:3111&field=pk:int&field=col1:double" ), QStringLiteral( "vl" ), QStringLiteral( "memory" ) ) );
QVERIFY( tempLayer->isValid() );

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

void TestQgsAttributeTable::testSortByDisplayExpression()
{
std::unique_ptr< QgsVectorLayer> tempLayer( new QgsVectorLayer( QStringLiteral( "LineString?crs=epsg:3111&field=pk:int&field=col1:double" ), QStringLiteral( "vl" ), QStringLiteral( "memory" ) ) );
QVERIFY( tempLayer->isValid() );

QgsFeature f1( tempLayer->dataProvider()->fields(), 1 );
f1.setAttribute( 0, 1 );
f1.setAttribute( 1, 3.2 );
QgsFeature f2( tempLayer->dataProvider()->fields(), 2 );
f2.setAttribute( 0, 2 );
f2.setAttribute( 1, 1.8 );
QgsFeature f3( tempLayer->dataProvider()->fields(), 3 );
f3.setAttribute( 0, 3 );
f3.setAttribute( 1, 5.0 );
QVERIFY( tempLayer->dataProvider()->addFeatures( QgsFeatureList() << f1 << f2 << f3 ) );

std::unique_ptr< QgsAttributeTableDialog > dlg( new QgsAttributeTableDialog( tempLayer.get() ) );

dlg->mMainView->mFeatureList->setDisplayExpression( "pk" );
QgsFeatureListModel *listModel = dlg->mMainView->mFeatureListModel;
QCOMPARE( listModel->rowCount(), 3 );

QCOMPARE( listModel->index( 0, 0 ).data( Qt::DisplayRole ), QVariant( 1 ) );
QCOMPARE( listModel->index( 1, 0 ).data( Qt::DisplayRole ), QVariant( 2 ) );
QCOMPARE( listModel->index( 2, 0 ).data( Qt::DisplayRole ), QVariant( 3 ) );

dlg->mMainView->mFeatureList->setDisplayExpression( "col1" );
QCOMPARE( listModel->index( 0, 0 ).data( Qt::DisplayRole ), QVariant( 1.8 ) );
QCOMPARE( listModel->index( 1, 0 ).data( Qt::DisplayRole ), QVariant( 3.2 ) );
QCOMPARE( listModel->index( 2, 0 ).data( Qt::DisplayRole ), QVariant( 5.0 ) );
}

void TestQgsAttributeTable::testRegression15974()
{
// Test duplicated rows in attribute table + two crashes.

0 comments on commit ce403b1

Please sign in to comment.
You can’t perform that action at this time.