Skip to content

Commit

Permalink
[Fix #7597] Attribute Table: Reintroduce locale aware sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Apr 15, 2013
1 parent cb6b951 commit 268c037
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
28 changes: 27 additions & 1 deletion src/gui/attributetable/qgsattributetablefiltermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
10 changes: 6 additions & 4 deletions src/gui/attributetable/qgsattributetablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -522,10 +528,6 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
}
}

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

return field.displayString( val );
}
Expand Down

0 comments on commit 268c037

Please sign in to comment.