Skip to content
Permalink
Browse files

[Fix #7597] Attribute Table: Reintroduce locale aware sorting

  • Loading branch information
m-kuhn committed Apr 15, 2013
1 parent cb6b951 commit 268c03745fb41438d560c2a08dde3a2fff7c5e96
@@ -57,7 +57,33 @@ bool QgsAttributeTableFilterModel::lessThan( const QModelIndex &left, const QMod
}
}

return QSortFilterProxyModel::lessThan( left, right );

QVariant leftData = left.data( QgsAttributeTableModel::SortRole );
QVariant rightData = right.data( QgsAttributeTableModel::SortRole );

if ( leftData.isNull() )
return true;

if ( rightData.isNull() )
return false;

switch ( leftData.type() )
{
case QVariant::Int:
case QVariant::UInt:
case QVariant::LongLong:
case QVariant::ULongLong:
return leftData.toLongLong() < rightData.toLongLong();

case QVariant::Double:
return leftData.toDouble() < rightData.toDouble();

default:
return leftData.toString().localeAwareCompare( rightData.toString() ) < 0;
}

// Avoid warning. Will never reach this
return false;
}

void QgsAttributeTableFilterModel::setSelectedOnTop( bool selectedOnTop )
@@ -495,6 +495,12 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons

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

// For sorting return unprocessed value
if ( SortRole == role )
{
return val;
}

if ( val.isNull() )
{
// 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
}
}

if ( role == SortRole )
{
return val;
}

return field.displayString( val );
}

0 comments on commit 268c037

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