Skip to content

Commit bc25781

Browse files
authored
Merge pull request #7013 from m-kuhn/sortList
Sort list on the attribute table/form view based on shown value
2 parents 3e9a37c + b76acbe commit bc25781

13 files changed

+381
-167
lines changed

python/gui/auto_generated/attributetable/qgsattributetablemodel.sip.in

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ Is mostly referred to as "master model" within this doc and the source.
2828
public:
2929
enum Role
3030
{
31-
SortRole,
3231
FeatureIdRole,
3332
FieldIndexRole,
34-
UserRole
33+
UserRole,
34+
// Insert
35+
SortRole,
3536
};
3637

3738
public:
@@ -190,17 +191,19 @@ Specify -1 as column to invalidate the cache
190191
:param column: The column index of the field to catch
191192
%End
192193

193-
void prefetchSortData( const QString &expression );
194+
void prefetchSortData( const QString &expression, unsigned long cacheIndex = 0 );
194195
%Docstring
195-
Prefetches the entire data for one expression. Based on this cached information
196-
the sorting can later be done in a performant way.
197-
198-
:param expression: The expression to cache
196+
Prefetches the entire data for an ``expression``. Based on this cached information
197+
the sorting can later be done in a performant way. A ``cacheIndex`` can be specified
198+
if multiple caches should be filled. In this case, the caches will be available
199+
as ``QgsAttributeTableModel.SortRole + cacheIndex``.
199200
%End
200201

201-
QString sortCacheExpression() const;
202+
QString sortCacheExpression( unsigned long cacheIndex = 0 ) const;
202203
%Docstring
203-
The expression which was used to fill the sorting cache
204+
The expression which was used to fill the sorting cache at index ``cacheIndex``.
205+
206+
.. seealso:: :py:func:`prefetchSortData`
204207
%End
205208

206209
void setRequest( const QgsFeatureRequest &request );

python/gui/auto_generated/attributetable/qgsfeaturelistmodel.sip.in

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212

13-
class QgsFeatureListModel : QAbstractProxyModel, QgsFeatureModel
13+
class QgsFeatureListModel : QSortFilterProxyModel, QgsFeatureModel
1414
{
1515

1616
%TypeHeaderCode
@@ -102,8 +102,6 @@ for a meaningful error message.
102102
virtual QItemSelection mapSelectionFromMaster( const QItemSelection &selection ) const;
103103
virtual QItemSelection mapSelectionToMaster( const QItemSelection &selection ) const;
104104

105-
virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const;
106-
107105
virtual QModelIndex parent( const QModelIndex &child ) const;
108106

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

116114
QModelIndexList fidToIndexList( QgsFeatureId fid );
117115

116+
bool sortByDisplayExpression() const;
117+
%Docstring
118+
Sort this model by its display expression.
119+
120+
.. versionadded:: 3.2
121+
%End
122+
123+
void setSortByDisplayExpression( bool sortByDisplayExpression );
124+
%Docstring
125+
Sort this model by its display expression.
126+
127+
.. note::
128+
129+
Not compatible with injectNull, if sorting by display expression is enabled,
130+
injectNull will automatically turned off.
131+
132+
.. versionadded:: 3.2
133+
%End
134+
118135
public slots:
119-
void onBeginRemoveRows( const QModelIndex &parent, int first, int last );
120-
void onEndRemoveRows( const QModelIndex &parent, int first, int last );
121-
void onBeginInsertRows( const QModelIndex &parent, int first, int last );
122-
void onEndInsertRows( const QModelIndex &parent, int first, int last );
136+
137+
void onBeginRemoveRows( const QModelIndex &parent, int first, int last );
138+
%Docstring
139+
Does nothing except for calling beginRemoveRows()
140+
141+
\deprecated
142+
%End
143+
144+
void onEndRemoveRows( const QModelIndex &parent, int first, int last );
145+
%Docstring
146+
Does nothing except for calling endRemoveRows()
147+
148+
\deprecated
149+
%End
150+
151+
void onBeginInsertRows( const QModelIndex &parent, int first, int last );
152+
%Docstring
153+
Does nothing except for calling beginInsertRows()
154+
155+
\deprecated
156+
%End
157+
158+
void onEndInsertRows( const QModelIndex &parent, int first, int last );
159+
%Docstring
160+
Does nothing except for calling endInsertRows()
161+
162+
\deprecated
163+
%End
123164

124165
};
125166

src/gui/attributetable/qgsattributetablefiltermodel.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
QgsAttributeTableFilterModel::QgsAttributeTableFilterModel( QgsMapCanvas *canvas, QgsAttributeTableModel *sourceModel, QObject *parent )
3333
: QSortFilterProxyModel( parent )
3434
, mCanvas( canvas )
35-
, mFilterMode( ShowAll )
36-
, mSelectedOnTop( false )
3735
{
3836
setSourceModel( sourceModel );
3937
setDynamicSortFilter( true );

src/gui/attributetable/qgsattributetablefiltermodel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ class GUI_EXPORT QgsAttributeTableFilterModel: public QSortFilterProxyModel, pub
268268
private:
269269
QgsFeatureIds mFilteredFeatures;
270270
QgsMapCanvas *mCanvas = nullptr;
271-
FilterMode mFilterMode;
272-
bool mSelectedOnTop;
271+
FilterMode mFilterMode = FilterMode::ShowAll;
272+
bool mSelectedOnTop = false;
273273
QgsAttributeTableModel *mTableModel = nullptr;
274274

275275
QgsAttributeTableConfig mConfig;

0 commit comments

Comments
 (0)