Skip to content
Permalink
Browse files

Fix row conditional formatting

Fixes #34122

The original implementation was storing the styles
in an hash keyed by the row number from the model
index, but that one changes when the table is reloaded.

By using feature id as a key instead, the style association
with the feature is maintained through sort/reload
operations.
  • Loading branch information
elpaso authored and nyalldawson committed Feb 5, 2020
1 parent 947fe8d commit 6bffe18af3d3931395ecc0d69718c9700febd69d
Showing with 4 additions and 4 deletions.
  1. +4 −4 src/gui/attributetable/qgsattributetablemodel.cpp
@@ -711,14 +711,14 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
{
mExpressionContext.setFeature( mFeat );
QList<QgsConditionalStyle> styles;
if ( mRowStylesMap.contains( index.row() ) )
if ( mRowStylesMap.contains( mFeat.id() ) )
{
styles = mRowStylesMap[index.row()];
styles = mRowStylesMap[mFeat.id()];
}
else
{
styles = QgsConditionalStyle::matchingConditionalStyles( layer()->conditionalStyles()->rowStyles(), QVariant(), mExpressionContext );
mRowStylesMap.insert( index.row(), styles );
mRowStylesMap.insert( mFeat.id(), styles );
}

QgsConditionalStyle rowstyle = QgsConditionalStyle::compressStyles( styles );
@@ -756,7 +756,7 @@ bool QgsAttributeTableModel::setData( const QModelIndex &index, const QVariant &
if ( !layer()->isModified() )
return false;

mRowStylesMap.remove( index.row() );
mRowStylesMap.remove( mFeat.id() );

return true;
}

0 comments on commit 6bffe18

Please sign in to comment.
You can’t perform that action at this time.