Skip to content
Permalink
Browse files

Fix invalid background/text colors showing in attribute table

  • Loading branch information
nyalldawson committed May 24, 2016
1 parent eba4d03 commit 38e05026fb7a517cfef7b2b69a5a6e3cd7f0c355
Showing with 43 additions and 33 deletions.
  1. +43 −33 src/gui/attributetable/qgsattributetablemodel.cpp
@@ -561,7 +561,7 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
if ( index.column() >= mFieldCount )
return QVariant();

int fieldId = mAttributes[index.column()];
int fieldId = mAttributes.at( index.column() );

if ( role == FieldIndexRole )
return fieldId;
@@ -596,46 +596,56 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons

QVariant val = mFeat.attribute( fieldId );

if ( role == Qt::DisplayRole )
switch ( role )
{
return mWidgetFactories[index.column()]->representValue( layer(), fieldId, mWidgetConfigs[index.column()], mAttributeWidgetCaches[index.column()], val );
}
case Qt::DisplayRole:
return mWidgetFactories.at( index.column() )->representValue( layer(), fieldId, mWidgetConfigs.at( index.column() ),
mAttributeWidgetCaches.at( index.column() ), val );

if ( role == Qt::BackgroundColorRole || role == Qt::TextColorRole || role == Qt::DecorationRole || role == Qt::FontRole )
{
mExpressionContext.setFeature( mFeat );
QList<QgsConditionalStyle> styles;
if ( mRowStylesMap.contains( index.row() ) )
{
styles = mRowStylesMap[index.row()];
}
else
case Qt::EditRole:
return val;

case Qt::BackgroundColorRole:
case Qt::TextColorRole:
case Qt::DecorationRole:
case Qt::FontRole:
{
styles = QgsConditionalStyle::matchingConditionalStyles( layer()->conditionalStyles()->rowStyles(), QVariant(), mExpressionContext );
mRowStylesMap.insert( index.row(), styles );
mExpressionContext.setFeature( mFeat );
QList<QgsConditionalStyle> styles;
if ( mRowStylesMap.contains( index.row() ) )
{
styles = mRowStylesMap[index.row()];
}
else
{
styles = QgsConditionalStyle::matchingConditionalStyles( layer()->conditionalStyles()->rowStyles(), QVariant(), mExpressionContext );
mRowStylesMap.insert( index.row(), styles );

}
}

QgsConditionalStyle rowstyle = QgsConditionalStyle::compressStyles( styles );
styles = layer()->conditionalStyles()->fieldStyles( field.name() );
styles = QgsConditionalStyle::matchingConditionalStyles( styles , val, mExpressionContext );
styles.insert( 0, rowstyle );
QgsConditionalStyle style = QgsConditionalStyle::compressStyles( styles );
QgsConditionalStyle rowstyle = QgsConditionalStyle::compressStyles( styles );
styles = layer()->conditionalStyles()->fieldStyles( field.name() );
styles = QgsConditionalStyle::matchingConditionalStyles( styles , val, mExpressionContext );
styles.insert( 0, rowstyle );
QgsConditionalStyle style = QgsConditionalStyle::compressStyles( styles );

if ( style.isValid() )
{
if ( role == Qt::BackgroundColorRole && style.validBackgroundColor() )
return style.backgroundColor();
if ( role == Qt::TextColorRole && style.validTextColor() )
return style.textColor();
if ( role == Qt::DecorationRole )
return style.icon();
if ( role == Qt::FontRole )
return style.font();
}
if ( style.isValid() )
{
if ( role == Qt::BackgroundColorRole && style.validBackgroundColor() )
return style.backgroundColor();
if ( role == Qt::TextColorRole && style.validTextColor() )
return style.textColor();
if ( role == Qt::DecorationRole )
return style.icon();
if ( role == Qt::FontRole )
return style.font();
}

return QVariant();
}
}
return val;

return QVariant();
}

bool QgsAttributeTableModel::setData( const QModelIndex &index, const QVariant &value, int role )

0 comments on commit 38e0502

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