@@ -42,9 +42,11 @@ class TestQgsAttributeTable : public QObject
42
42
TestQgsAttributeTable ();
43
43
44
44
private slots:
45
+
45
46
void initTestCase ();// will be called before the first testfunction is executed.
46
47
void cleanupTestCase ();// will be called after the last testfunction was executed.
47
- void init () {} // will be called before each testfunction is executed.
48
+ void init ();
49
+ // will be called before each testfunction is executed.
48
50
void cleanup () {} // will be called after every testfunction.
49
51
void testRegression15974 ();
50
52
void testFieldCalculation ();
@@ -58,7 +60,7 @@ class TestQgsAttributeTable : public QObject
58
60
void testFilteredFeatures ();
59
61
void testVisibleTemporal ();
60
62
void testCopySelectedRows ();
61
-
63
+ void testSortNumbers ();
62
64
63
65
private:
64
66
QgisApp *mQgisApp = nullptr ;
@@ -87,6 +89,11 @@ void TestQgsAttributeTable::cleanupTestCase()
87
89
QgsApplication::exitQgis ();
88
90
}
89
91
92
+ void TestQgsAttributeTable::init ()
93
+ {
94
+ QLocale::setDefault ( QLocale::c () );
95
+ }
96
+
90
97
void TestQgsAttributeTable::testFieldCalculation ()
91
98
{
92
99
// test field calculation
@@ -411,6 +418,54 @@ void TestQgsAttributeTable::testSortByDisplayExpression()
411
418
QCOMPARE ( listModel->index ( 2 , 0 ).data ( Qt::DisplayRole ), QVariant ( 5.0 ) );
412
419
}
413
420
421
+ void TestQgsAttributeTable::testSortNumbers ()
422
+ {
423
+
424
+ QLocale::setDefault ( QLocale::Italian );
425
+
426
+ std::unique_ptr< QgsVectorLayer> tempLayer ( new QgsVectorLayer ( QStringLiteral ( " LineString?crs=epsg:3111&field=pk:int&field=col1:double" ), QStringLiteral ( " vl" ), QStringLiteral ( " memory" ) ) );
427
+ QVERIFY ( tempLayer->isValid () );
428
+
429
+ QgsFeature f1 ( tempLayer->dataProvider ()->fields (), 1 );
430
+ f1.setAttribute ( 0 , 1 );
431
+ f1.setAttribute ( 1 , 2.001 );
432
+ QgsFeature f2 ( tempLayer->dataProvider ()->fields (), 2 );
433
+ f2.setAttribute ( 0 , 2 );
434
+ f2.setAttribute ( 1 , 1001 );
435
+ QgsFeature f3 ( tempLayer->dataProvider ()->fields (), 3 );
436
+ f3.setAttribute ( 0 , 3 );
437
+ f3.setAttribute ( 1 , 10.0001 );
438
+ QVERIFY ( tempLayer->dataProvider ()->addFeatures ( QgsFeatureList () << f1 << f2 << f3 ) );
439
+
440
+ std::unique_ptr< QgsAttributeTableDialog > dlg ( new QgsAttributeTableDialog ( tempLayer.get () ) );
441
+
442
+ QgsAttributeTableConfig cfg;
443
+ cfg.setSortExpression ( QStringLiteral ( R"( "col1")" ) );
444
+ cfg.setSortOrder ( Qt::SortOrder::DescendingOrder );
445
+ QgsAttributeTableConfig::ColumnConfig cfg1;
446
+ QgsAttributeTableConfig::ColumnConfig cfg2;
447
+ cfg1.name = QStringLiteral ( " pk" );
448
+ cfg2.name = QStringLiteral ( " col1" );
449
+ cfg.setColumns ( {{ cfg1, cfg2 }} );
450
+
451
+ dlg->mMainView ->setAttributeTableConfig ( cfg );
452
+
453
+ auto model { dlg->mMainView ->mFilterModel };
454
+
455
+ QCOMPARE ( model->data ( model->index ( 2 , 1 ), Qt::ItemDataRole::DisplayRole ).toString (), QString ( " 2,00100" ) );
456
+ QCOMPARE ( model->data ( model->index ( 1 , 1 ), Qt::ItemDataRole::DisplayRole ).toString (), QString ( " 10,00010" ) );
457
+ QCOMPARE ( model->data ( model->index ( 0 , 1 ), Qt::ItemDataRole::DisplayRole ).toString (), QString ( " 1.001,00000" ) );
458
+
459
+ QCOMPARE ( model->data ( model->index ( 2 , 2 ), QgsAttributeTableModel::Role::SortRole ).toDouble (), 2.001 );
460
+ QCOMPARE ( model->data ( model->index ( 1 , 2 ), QgsAttributeTableModel::Role::SortRole ).toDouble (), 10.0001 );
461
+ QCOMPARE ( model->data ( model->index ( 0 , 2 ), QgsAttributeTableModel::Role::SortRole ).toDouble (), 1001.0 );
462
+
463
+ QCOMPARE ( dlg->mMainView ->mTableView ->horizontalHeader ()->sortIndicatorSection (), 1 );
464
+ QCOMPARE ( dlg->mMainView ->mTableView ->horizontalHeader ()->sortIndicatorOrder (), Qt::SortOrder::DescendingOrder );
465
+ QVERIFY ( dlg->mMainView ->mTableView ->horizontalHeader ()->isSortIndicatorShown () );
466
+
467
+ }
468
+
414
469
void TestQgsAttributeTable::testRegression15974 ()
415
470
{
416
471
// Test duplicated rows in attribute table + two crashes.
0 commit comments