Skip to content

Commit 9963892

Browse files
committed
Make additional sort caches accessible
1 parent 2325fe5 commit 9963892

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,18 @@ Specify -1 as column to invalidate the cache
194194
void prefetchSortData( const QString &expression, unsigned long cacheIndex = 0 );
195195
%Docstring
196196
Prefetches the entire data for one expression. Based on this cached information
197-
the sorting can later be done in a performant way.
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``.
198200

199201
:param expression: The expression to cache
200202
%End
201203

202-
QString sortCacheExpression() const;
204+
QString sortCacheExpression( unsigned long cacheIndex = 0 ) const;
203205
%Docstring
204-
The expression which was used to fill the sorting cache
206+
The expression which was used to fill the sorting cache at index \cacheIndex.
207+
208+
.. seealso:: :py:func:`prefetchSortData`
205209
%End
206210

207211
void setRequest( const QgsFeatureRequest &request );

src/gui/attributetable/qgsattributetablemodel.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -908,13 +908,14 @@ void QgsAttributeTableModel::prefetchSortData( const QString &expressionString,
908908
}
909909
}
910910

911-
QString QgsAttributeTableModel::sortCacheExpression() const
911+
QString QgsAttributeTableModel::sortCacheExpression( unsigned long cacheIndex ) const
912912
{
913-
Q_ASSERT( !mSortCaches.empty() );
914-
915913
QString expressionString;
916914

917-
const QgsExpression &expression = mSortCaches.begin()->sortCacheExpression;
915+
if ( cacheIndex >= mSortCaches.size() )
916+
return expressionString;
917+
918+
const QgsExpression &expression = mSortCaches[cacheIndex].sortCacheExpression;
918919

919920
if ( expression.isValid() )
920921
expressionString = expression.expression();

src/gui/attributetable/qgsattributetablemodel.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,20 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
200200

201201
/**
202202
* Prefetches the entire data for one expression. Based on this cached information
203-
* the sorting can later be done in a performant way.
203+
* the sorting can later be done in a performant way. A \a cacheIndex can be specified
204+
* if multiple caches should be filled. In this case, the caches will be available
205+
* as ``QgsAttributeTableModel::SortRole + cacheIndex``.
204206
*
205207
* \param expression The expression to cache
206208
*/
207209
void prefetchSortData( const QString &expression, unsigned long cacheIndex = 0 );
208210

209211
/**
210-
* The expression which was used to fill the sorting cache
212+
* The expression which was used to fill the sorting cache at index \cacheIndex.
213+
*
214+
* \see prefetchSortData
211215
*/
212-
QString sortCacheExpression() const;
216+
QString sortCacheExpression( unsigned long cacheIndex = 0 ) const;
213217

214218
/**
215219
* Set a request that will be used to fill this attribute table model.

0 commit comments

Comments
 (0)