Skip to content

Commit dd9bf7e

Browse files
committed
Merge pull request #484 from matthias-kuhn/attribute-table-sort
Fix #7459: Sorting of attribute table takes type into account
2 parents aa6d22a + f28f13c commit dd9bf7e

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/gui/attributetable/qgsattributetablefiltermodel.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ QgsAttributeTableFilterModel::QgsAttributeTableFilterModel( QgsMapCanvas* canvas
3636
mMasterSelection = new QItemSelectionModel( this, this );
3737
setSourceModel( sourceModel );
3838
setDynamicSortFilter( true );
39+
setSortRole( QgsAttributeTableModel::SortRole );
3940
connect( layer(), SIGNAL( selectionChanged() ), SLOT( selectionChanged() ) );
4041
}
4142

src/gui/attributetable/qgsattributetablemodel.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ QVariant QgsAttributeTableModel::headerData( int section, Qt::Orientation orient
422422

423423
QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) const
424424
{
425-
if ( !index.isValid() || ( role != Qt::TextAlignmentRole && role != Qt::DisplayRole && role != Qt::EditRole ) )
425+
if ( !index.isValid() || ( role != Qt::TextAlignmentRole && role != Qt::DisplayRole && role != Qt::EditRole && role != SortRole ) )
426426
return QVariant();
427427

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

486+
if ( role == SortRole )
487+
{
488+
return val;
489+
}
490+
486491
return field.displayString( val );
487492
}
488493

src/gui/attributetable/qgsattributetablemodel.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
4242
{
4343
Q_OBJECT
4444

45+
public:
46+
enum Role
47+
{
48+
SortRole = Qt::UserRole + 1
49+
};
50+
4551
public:
4652
/**
4753
* Constructor

0 commit comments

Comments
 (0)