Make additional sort caches accessible

This commit is contained in:
Matthias Kuhn 2018-05-17 08:57:06 +02:00
parent 2325fe5a39
commit 9963892790
No known key found for this signature in database
GPG Key ID: A0E766808764D73F
3 changed files with 19 additions and 10 deletions

View File

@ -194,14 +194,18 @@ Specify -1 as column to invalidate the cache
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.
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``.
:param expression: The expression to cache
%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 );

View File

@ -908,13 +908,14 @@ void QgsAttributeTableModel::prefetchSortData( const QString &expressionString,
}
}
QString QgsAttributeTableModel::sortCacheExpression() const
QString QgsAttributeTableModel::sortCacheExpression( unsigned long cacheIndex ) const
{
Q_ASSERT( !mSortCaches.empty() );
QString expressionString;
const QgsExpression &expression = mSortCaches.begin()->sortCacheExpression;
if ( cacheIndex >= mSortCaches.size() )
return expressionString;
const QgsExpression &expression = mSortCaches[cacheIndex].sortCacheExpression;
if ( expression.isValid() )
expressionString = expression.expression();

View File

@ -200,16 +200,20 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
/**
* Prefetches the entire data for one expression. Based on this cached information
* the sorting can later be done in a performant way.
* the sorting can later be done in a performant way. A \a cacheIndex can be specified
* if multiple caches should be filled. In this case, the caches will be available
* as ``QgsAttributeTableModel::SortRole + cacheIndex``.
*
* \param expression The expression to cache
*/
void prefetchSortData( const QString &expression, unsigned long cacheIndex = 0 );
/**
* The expression which was used to fill the sorting cache
* The expression which was used to fill the sorting cache at index \cacheIndex.
*
* \see prefetchSortData
*/
QString sortCacheExpression() const;
QString sortCacheExpression( unsigned long cacheIndex = 0 ) const;
/**
* Set a request that will be used to fill this attribute table model.