From 9963892790bc0933b668eccb71bc19ba7593bd1c Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Thu, 17 May 2018 08:57:06 +0200 Subject: [PATCH] Make additional sort caches accessible --- .../attributetable/qgsattributetablemodel.sip.in | 10 +++++++--- src/gui/attributetable/qgsattributetablemodel.cpp | 9 +++++---- src/gui/attributetable/qgsattributetablemodel.h | 10 +++++++--- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/python/gui/auto_generated/attributetable/qgsattributetablemodel.sip.in b/python/gui/auto_generated/attributetable/qgsattributetablemodel.sip.in index a55f8ebbd4e..e323f3adeca 100644 --- a/python/gui/auto_generated/attributetable/qgsattributetablemodel.sip.in +++ b/python/gui/auto_generated/attributetable/qgsattributetablemodel.sip.in @@ -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 ); diff --git a/src/gui/attributetable/qgsattributetablemodel.cpp b/src/gui/attributetable/qgsattributetablemodel.cpp index 749ad154ac7..bab4a33afe6 100644 --- a/src/gui/attributetable/qgsattributetablemodel.cpp +++ b/src/gui/attributetable/qgsattributetablemodel.cpp @@ -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(); diff --git a/src/gui/attributetable/qgsattributetablemodel.h b/src/gui/attributetable/qgsattributetablemodel.h index 48570b800ee..e7d76a1ae28 100644 --- a/src/gui/attributetable/qgsattributetablemodel.h +++ b/src/gui/attributetable/qgsattributetablemodel.h @@ -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.