Skip to content

Commit

Permalink
Fix #7459: Sorting of attribute table takes type into account
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Mar 27, 2013
1 parent 0005467 commit f28f13c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/gui/attributetable/qgsattributetablefiltermodel.cpp
Expand Up @@ -36,6 +36,7 @@ QgsAttributeTableFilterModel::QgsAttributeTableFilterModel( QgsMapCanvas* canvas
mMasterSelection = new QItemSelectionModel( this, this );
setSourceModel( sourceModel );
setDynamicSortFilter( true );
setSortRole( QgsAttributeTableModel::SortRole );
connect( layer(), SIGNAL( selectionChanged() ), SLOT( selectionChanged() ) );
}

Expand Down
7 changes: 6 additions & 1 deletion src/gui/attributetable/qgsattributetablemodel.cpp
Expand Up @@ -422,7 +422,7 @@ QVariant QgsAttributeTableModel::headerData( int section, Qt::Orientation orient

QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) const
{
if ( !index.isValid() || ( role != Qt::TextAlignmentRole && role != Qt::DisplayRole && role != Qt::EditRole ) )
if ( !index.isValid() || ( role != Qt::TextAlignmentRole && role != Qt::DisplayRole && role != Qt::EditRole && role != SortRole ) )
return QVariant();

QgsFeatureId rowId = rowToId( index.row() );
Expand Down Expand Up @@ -483,6 +483,11 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
}
}

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

return field.displayString( val );
}

Expand Down
6 changes: 6 additions & 0 deletions src/gui/attributetable/qgsattributetablemodel.h
Expand Up @@ -42,6 +42,12 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
{
Q_OBJECT

public:
enum Role
{
SortRole = Qt::UserRole + 1
};

public:
/**
* Constructor
Expand Down

0 comments on commit f28f13c

Please sign in to comment.