Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make additional sort caches accessible
  • Loading branch information
m-kuhn committed May 17, 2018
1 parent 2325fe5 commit 9963892
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
Expand Up @@ -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 );
Expand Down
9 changes: 5 additions & 4 deletions src/gui/attributetable/qgsattributetablemodel.cpp
Expand Up @@ -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();
Expand Down
10 changes: 7 additions & 3 deletions src/gui/attributetable/qgsattributetablemodel.h
Expand Up @@ -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.
Expand Down

0 comments on commit 9963892

Please sign in to comment.