Skip to content

Commit

Permalink
Fix row conditional formatting
Browse files Browse the repository at this point in the history
Fixes qgis#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 committed Feb 5, 2020
1 parent 2e766b6 commit c5a9a65
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/gui/attributetable/qgsattributetablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit c5a9a65

Please sign in to comment.