Skip to content

Commit 268c037

Browse files
committed
[Fix #7597] Attribute Table: Reintroduce locale aware sorting
1 parent cb6b951 commit 268c037

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

src/gui/attributetable/qgsattributetablefiltermodel.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,33 @@ bool QgsAttributeTableFilterModel::lessThan( const QModelIndex &left, const QMod
5757
}
5858
}
5959

60-
return QSortFilterProxyModel::lessThan( left, right );
60+
61+
QVariant leftData = left.data( QgsAttributeTableModel::SortRole );
62+
QVariant rightData = right.data( QgsAttributeTableModel::SortRole );
63+
64+
if ( leftData.isNull() )
65+
return true;
66+
67+
if ( rightData.isNull() )
68+
return false;
69+
70+
switch ( leftData.type() )
71+
{
72+
case QVariant::Int:
73+
case QVariant::UInt:
74+
case QVariant::LongLong:
75+
case QVariant::ULongLong:
76+
return leftData.toLongLong() < rightData.toLongLong();
77+
78+
case QVariant::Double:
79+
return leftData.toDouble() < rightData.toDouble();
80+
81+
default:
82+
return leftData.toString().localeAwareCompare( rightData.toString() ) < 0;
83+
}
84+
85+
// Avoid warning. Will never reach this
86+
return false;
6187
}
6288

6389
void QgsAttributeTableFilterModel::setSelectedOnTop( bool selectedOnTop )

src/gui/attributetable/qgsattributetablemodel.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,12 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
495495

496496
const QVariant &val = mFeat.attribute( fieldId );
497497

498+
// For sorting return unprocessed value
499+
if ( SortRole == role )
500+
{
501+
return val;
502+
}
503+
498504
if ( val.isNull() )
499505
{
500506
// if the value is NULL, show that in table, but don't show "NULL" text in editor
@@ -522,10 +528,6 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
522528
}
523529
}
524530

525-
if ( role == SortRole )
526-
{
527-
return val;
528-
}
529531

530532
return field.displayString( val );
531533
}

0 commit comments

Comments
 (0)