Skip to content

Commit ea0f4da

Browse files
committedAug 1, 2016
Sort attribute table by value for numerical columns
Fix #15318 Fix #15295
1 parent 1d2b0b4 commit ea0f4da

File tree

3 files changed

+48
-12
lines changed

3 files changed

+48
-12
lines changed
 

‎src/gui/attributetable/qgsattributetablemodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ void QgsAttributeTableModel::prefetchSortData( const QString& expressionString )
829829
}
830830
else
831831
{
832-
QVariant sortValue = widgetFactory->representValue( layer(), mSortFieldIndex, widgetConfig, widgetCache, f.attribute( mSortFieldIndex ) );
832+
QVariant sortValue = widgetFactory->sortValue( layer(), mSortFieldIndex, widgetConfig, widgetCache, f.attribute( mSortFieldIndex ) );
833833
mSortCache.insert( f.id(), sortValue );
834834
}
835835
}

‎tests/src/gui/testqgsdualview.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,33 @@ void TestQgsDualView::testSort()
172172
QModelIndex index = mDualView->tableView()->model()->index( i, 0 );
173173
QCOMPARE( mDualView->tableView()->model()->data( index ).toString(), classes.at( i ) );
174174
}
175+
176+
QStringList headings;
177+
headings << "0"
178+
<< "0"
179+
<< "12"
180+
<< "34"
181+
<< "80"
182+
<< "85"
183+
<< "90"
184+
<< "90"
185+
<< "95"
186+
<< "100"
187+
<< "140"
188+
<< "160"
189+
<< "180"
190+
<< "240"
191+
<< "270"
192+
<< "300"
193+
<< "340";
194+
195+
mDualView->setSortExpression( "Heading" );
196+
197+
for ( int i = 0; i < headings.length(); ++i )
198+
{
199+
QModelIndex index = mDualView->tableView()->model()->index( i, 1 );
200+
QCOMPARE( mDualView->tableView()->model()->data( index ).toString(), headings.at( i ) );
201+
}
175202
}
176203

177204
void TestQgsDualView::testAttributeFormSharedValueScanning()

‎tests/src/python/test_qgsattributetablemodel.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,17 @@
1212
# This will get replaced with a git SHA1 when you do a git archive
1313
__revision__ = '$Format:%H$'
1414

15-
from qgis.gui import QgsAttributeTableModel, QgsEditorWidgetRegistry
16-
from qgis.core import QgsFeature, QgsGeometry, QgsPoint, QgsVectorLayer, QgsVectorLayerCache
15+
from qgis.gui import (
16+
QgsAttributeTableModel,
17+
QgsEditorWidgetRegistry
18+
)
19+
from qgis.core import (
20+
QgsFeature,
21+
QgsGeometry,
22+
QgsPoint,
23+
QgsVectorLayer,
24+
QgsVectorLayerCache
25+
)
1726

1827
from qgis.testing import (start_app,
1928
unittest
@@ -51,20 +60,20 @@ def createLayer(self):
5160
f.setGeometry(QgsGeometry.fromPoint(QgsPoint(100 * i, 2 ^ i)))
5261
features.append(f)
5362

54-
assert pr.addFeatures(features)
63+
self.assertTrue(pr.addFeatures(features))
5564
return layer
5665

5766
def testLoad(self):
58-
assert self.am.rowCount() == 10, self.am.rowCount()
59-
assert self.am.columnCount() == 2, self.am.columnCount()
67+
self.assertEquals(self.am.rowCount(), 10)
68+
self.assertEquals(self.am.columnCount(), 2)
6069

6170
def testRemove(self):
6271
self.layer.startEditing()
6372
self.layer.deleteFeature(5)
64-
assert self.am.rowCount() == 9, self.am.rowCount()
73+
self.assertEquals(self.am.rowCount(), 9)
6574
self.layer.setSelectedFeatures([1, 3, 6, 7])
6675
self.layer.deleteSelectedFeatures()
67-
assert self.am.rowCount() == 5, self.am.rowCount()
76+
self.assertEquals(self.am.rowCount(), 5)
6877

6978
def testAdd(self):
7079
self.layer.startEditing()
@@ -74,14 +83,14 @@ def testAdd(self):
7483
f.setGeometry(QgsGeometry.fromPoint(QgsPoint(100, 200)))
7584
self.layer.addFeature(f)
7685

77-
assert self.am.rowCount() == 11, self.am.rowCount()
86+
self.assertEquals(self.am.rowCount(), 11)
7887

7988
def testRemoveColumns(self):
80-
assert self.layer.startEditing()
89+
self.assertTrue(self.layer.startEditing())
8190

82-
assert self.layer.deleteAttribute(1)
91+
self.assertTrue(self.layer.deleteAttribute(1))
8392

84-
assert self.am.columnCount() == 1, self.am.columnCount()
93+
self.assertEquals(self.am.columnCount(), 1)
8594

8695
if __name__ == '__main__':
8796
unittest.main()

0 commit comments

Comments
 (0)
Please sign in to comment.