Skip to content

Commit

Permalink
Merge pull request #7013 from m-kuhn/sortList
Browse files Browse the repository at this point in the history
Sort list on the attribute table/form view based on shown value
  • Loading branch information
m-kuhn committed May 18, 2018
2 parents 3e9a37c + b76acbe commit bc25781
Show file tree
Hide file tree
Showing 13 changed files with 381 additions and 167 deletions.
Expand Up @@ -28,10 +28,11 @@ Is mostly referred to as "master model" within this doc and the source.
public:
enum Role
{
SortRole,
FeatureIdRole,
FieldIndexRole,
UserRole
UserRole,
// Insert
SortRole,
};

public:
Expand Down Expand Up @@ -190,17 +191,19 @@ Specify -1 as column to invalidate the cache
:param column: The column index of the field to catch
%End

void prefetchSortData( const QString &expression );
void prefetchSortData( const QString &expression, unsigned long cacheIndex = 0 );
%Docstring
Prefetches the entire data for one expression. Based on this cached information
the sorting can later be done in a performant way.

:param expression: The expression to cache
Prefetches the entire data for an ``expression``. Based on this cached information
the sorting can later be done in a performant way. A ``cacheIndex`` can be specified
if multiple caches should be filled. In this case, the caches will be available
as ``QgsAttributeTableModel.SortRole + cacheIndex``.
%End

QString sortCacheExpression() const;
QString sortCacheExpression( unsigned long cacheIndex = 0 ) const;
%Docstring
The expression which was used to fill the sorting cache
The expression which was used to fill the sorting cache at index ``cacheIndex``.

.. seealso:: :py:func:`prefetchSortData`
%End

void setRequest( const QgsFeatureRequest &request );
Expand Down
Expand Up @@ -10,7 +10,7 @@



class QgsFeatureListModel : QAbstractProxyModel, QgsFeatureModel
class QgsFeatureListModel : QSortFilterProxyModel, QgsFeatureModel
{

%TypeHeaderCode
Expand Down Expand Up @@ -102,8 +102,6 @@ for a meaningful error message.
virtual QItemSelection mapSelectionFromMaster( const QItemSelection &selection ) const;
virtual QItemSelection mapSelectionToMaster( const QItemSelection &selection ) const;

virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const;

virtual QModelIndex parent( const QModelIndex &child ) const;

virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const;
Expand All @@ -115,11 +113,54 @@ for a meaningful error message.

QModelIndexList fidToIndexList( QgsFeatureId fid );

bool sortByDisplayExpression() const;
%Docstring
Sort this model by its display expression.

.. versionadded:: 3.2
%End

void setSortByDisplayExpression( bool sortByDisplayExpression );
%Docstring
Sort this model by its display expression.

.. note::

Not compatible with injectNull, if sorting by display expression is enabled,
injectNull will automatically turned off.

.. versionadded:: 3.2
%End

public slots:
void onBeginRemoveRows( const QModelIndex &parent, int first, int last );
void onEndRemoveRows( const QModelIndex &parent, int first, int last );
void onBeginInsertRows( const QModelIndex &parent, int first, int last );
void onEndInsertRows( const QModelIndex &parent, int first, int last );

void onBeginRemoveRows( const QModelIndex &parent, int first, int last );
%Docstring
Does nothing except for calling beginRemoveRows()

\deprecated
%End

void onEndRemoveRows( const QModelIndex &parent, int first, int last );
%Docstring
Does nothing except for calling endRemoveRows()

\deprecated
%End

void onBeginInsertRows( const QModelIndex &parent, int first, int last );
%Docstring
Does nothing except for calling beginInsertRows()

\deprecated
%End

void onEndInsertRows( const QModelIndex &parent, int first, int last );
%Docstring
Does nothing except for calling endInsertRows()

\deprecated
%End

};

Expand Down
2 changes: 0 additions & 2 deletions src/gui/attributetable/qgsattributetablefiltermodel.cpp
Expand Up @@ -32,8 +32,6 @@
QgsAttributeTableFilterModel::QgsAttributeTableFilterModel( QgsMapCanvas *canvas, QgsAttributeTableModel *sourceModel, QObject *parent )
: QSortFilterProxyModel( parent )
, mCanvas( canvas )
, mFilterMode( ShowAll )
, mSelectedOnTop( false )
{
setSourceModel( sourceModel );
setDynamicSortFilter( true );
Expand Down
4 changes: 2 additions & 2 deletions src/gui/attributetable/qgsattributetablefiltermodel.h
Expand Up @@ -268,8 +268,8 @@ class GUI_EXPORT QgsAttributeTableFilterModel: public QSortFilterProxyModel, pub
private:
QgsFeatureIds mFilteredFeatures;
QgsMapCanvas *mCanvas = nullptr;
FilterMode mFilterMode;
bool mSelectedOnTop;
FilterMode mFilterMode = FilterMode::ShowAll;
bool mSelectedOnTop = false;
QgsAttributeTableModel *mTableModel = nullptr;

QgsAttributeTableConfig mConfig;
Expand Down

0 comments on commit bc25781

Please sign in to comment.