Skip to content
Permalink
Browse files

Sort attribute table by value for numerical columns

Fix #15318
Fix #15295
  • Loading branch information
m-kuhn committed Aug 1, 2016
1 parent 1d2b0b4 commit ea0f4da58c87bc590f8b23049da0963ee9d9cd23
@@ -829,7 +829,7 @@ void QgsAttributeTableModel::prefetchSortData( const QString& expressionString )
}
else
{
QVariant sortValue = widgetFactory->representValue( layer(), mSortFieldIndex, widgetConfig, widgetCache, f.attribute( mSortFieldIndex ) );
QVariant sortValue = widgetFactory->sortValue( layer(), mSortFieldIndex, widgetConfig, widgetCache, f.attribute( mSortFieldIndex ) );
mSortCache.insert( f.id(), sortValue );
}
}
@@ -172,6 +172,33 @@ void TestQgsDualView::testSort()
QModelIndex index = mDualView->tableView()->model()->index( i, 0 );
QCOMPARE( mDualView->tableView()->model()->data( index ).toString(), classes.at( i ) );
}

QStringList headings;
headings << "0"
<< "0"
<< "12"
<< "34"
<< "80"
<< "85"
<< "90"
<< "90"
<< "95"
<< "100"
<< "140"
<< "160"
<< "180"
<< "240"
<< "270"
<< "300"
<< "340";

mDualView->setSortExpression( "Heading" );

for ( int i = 0; i < headings.length(); ++i )
{
QModelIndex index = mDualView->tableView()->model()->index( i, 1 );
QCOMPARE( mDualView->tableView()->model()->data( index ).toString(), headings.at( i ) );
}
}

void TestQgsDualView::testAttributeFormSharedValueScanning()
@@ -12,8 +12,17 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from qgis.gui import QgsAttributeTableModel, QgsEditorWidgetRegistry
from qgis.core import QgsFeature, QgsGeometry, QgsPoint, QgsVectorLayer, QgsVectorLayerCache
from qgis.gui import (
QgsAttributeTableModel,
QgsEditorWidgetRegistry
)
from qgis.core import (
QgsFeature,
QgsGeometry,
QgsPoint,
QgsVectorLayer,
QgsVectorLayerCache
)

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

assert pr.addFeatures(features)
self.assertTrue(pr.addFeatures(features))
return layer

def testLoad(self):
assert self.am.rowCount() == 10, self.am.rowCount()
assert self.am.columnCount() == 2, self.am.columnCount()
self.assertEquals(self.am.rowCount(), 10)
self.assertEquals(self.am.columnCount(), 2)

def testRemove(self):
self.layer.startEditing()
self.layer.deleteFeature(5)
assert self.am.rowCount() == 9, self.am.rowCount()
self.assertEquals(self.am.rowCount(), 9)
self.layer.setSelectedFeatures([1, 3, 6, 7])
self.layer.deleteSelectedFeatures()
assert self.am.rowCount() == 5, self.am.rowCount()
self.assertEquals(self.am.rowCount(), 5)

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

assert self.am.rowCount() == 11, self.am.rowCount()
self.assertEquals(self.am.rowCount(), 11)

def testRemoveColumns(self):
assert self.layer.startEditing()
self.assertTrue(self.layer.startEditing())

assert self.layer.deleteAttribute(1)
self.assertTrue(self.layer.deleteAttribute(1))

assert self.am.columnCount() == 1, self.am.columnCount()
self.assertEquals(self.am.columnCount(), 1)

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

0 comments on commit ea0f4da

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