Skip to content
Permalink
Browse files

Merge pull request #7013 from m-kuhn/sortList

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 bc2578120810ec556d433e44ae1375f67ee5d47f
@@ -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:
@@ -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 );
@@ -10,7 +10,7 @@



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

%TypeHeaderCode
@@ -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;
@@ -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

};

@@ -32,8 +32,6 @@
QgsAttributeTableFilterModel::QgsAttributeTableFilterModel( QgsMapCanvas *canvas, QgsAttributeTableModel *sourceModel, QObject *parent )
: QSortFilterProxyModel( parent )
, mCanvas( canvas )
, mFilterMode( ShowAll )
, mSelectedOnTop( false )
{
setSourceModel( sourceModel );
setDynamicSortFilter( true );
@@ -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;

0 comments on commit bc25781

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