Skip to content

Commit 0b95c77

Browse files
committedMay 22, 2017
Don't prefetch attribute table sort values when no sorting set
Shaves some seconds off opening the attribute table in certain circumstances (no sorting applied) Refs #16577, #16239
1 parent ebd3e0d commit 0b95c77

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed
 

‎src/gui/attributetable/qgsattributetablemodel.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ QgsAttributeTableModel::QgsAttributeTableModel( QgsVectorLayerCache *layerCache,
4444
: QAbstractTableModel( parent )
4545
, mLayerCache( layerCache )
4646
, mFieldCount( 0 )
47-
, mSortCacheExpression( QLatin1String( "" ) )
4847
, mSortFieldIndex( -1 )
4948
, mExtraColumns( 0 )
5049
{
@@ -212,19 +211,19 @@ void QgsAttributeTableModel::featureAdded( QgsFeatureId fid, bool resettingModel
212211

213212
if ( featOk && mFeatureRequest.acceptFeature( mFeat ) )
214213
{
215-
if ( mSortFieldIndex == -1 )
216-
{
217-
mExpressionContext.setFeature( mFeat );
218-
mSortCache[mFeat.id()] = mSortCacheExpression.evaluate( &mExpressionContext );
219-
}
220-
else
214+
if ( mSortFieldIndex >= 0 )
221215
{
222216
QgsFieldFormatter *fieldFormatter = mFieldFormatters.at( mSortFieldIndex );
223217
const QVariant &widgetCache = mAttributeWidgetCaches.at( mSortFieldIndex );
224218
const QVariantMap &widgetConfig = mWidgetConfigs.at( mSortFieldIndex );
225219
QVariant sortValue = fieldFormatter->representValue( layer(), mSortFieldIndex, widgetConfig, widgetCache, mFeat.attribute( mSortFieldIndex ) );
226220
mSortCache.insert( mFeat.id(), sortValue );
227221
}
222+
else if ( mSortCacheExpression.isValid() )
223+
{
224+
mExpressionContext.setFeature( mFeat );
225+
mSortCache[mFeat.id()] = mSortCacheExpression.evaluate( &mExpressionContext );
226+
}
228227

229228
// Skip if the fid is already in the map (do not add twice)!
230229
if ( ! mIdRowMap.contains( fid ) )
@@ -799,7 +798,14 @@ void QgsAttributeTableModel::prefetchSortData( const QString &expressionString )
799798
mSortCache.clear();
800799
mSortCacheAttributes.clear();
801800
mSortFieldIndex = -1;
802-
mSortCacheExpression = QgsExpression( expressionString );
801+
if ( !expressionString.isEmpty() )
802+
mSortCacheExpression = QgsExpression( expressionString );
803+
else
804+
{
805+
// no sorting
806+
mSortCacheExpression = QgsExpression();
807+
return;
808+
}
803809

804810
QgsFieldFormatter *fieldFormatter = nullptr;
805811
QVariant widgetCache;
@@ -852,7 +858,7 @@ void QgsAttributeTableModel::prefetchSortData( const QString &expressionString )
852858

853859
QString QgsAttributeTableModel::sortCacheExpression() const
854860
{
855-
if ( mSortCacheExpression.rootNode() )
861+
if ( mSortCacheExpression.isValid() )
856862
return mSortCacheExpression.expression();
857863
else
858864
return QString();

0 commit comments

Comments
 (0)
Please sign in to comment.