Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow fall though of conditional rules
  • Loading branch information
NathanW2 committed Aug 21, 2015
1 parent 76f4f7c commit db56307
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/core/qgsconditionalstyle.cpp
Expand Up @@ -83,12 +83,12 @@ bool QgsConditionalStyle::matches( QVariant value, QgsFeature *feature )
QPixmap QgsConditionalStyle::renderPreview()
{
QPixmap pixmap( 64, 32 );
pixmap.fill( Qt::transparent );

QPainter painter( &pixmap );

if ( mBackColor.isValid() )
painter.setBrush( mBackColor );
else
painter.setBrush( QColor( Qt::white ) );

QRect rect = QRect( 0, 0, 64, 32 );
painter.setPen( Qt::NoPen );
Expand Down
11 changes: 11 additions & 0 deletions src/core/qgsfielduiproperties.cpp
Expand Up @@ -18,6 +18,17 @@ QList<QgsConditionalStyle> QgsFieldUIProperties::getConditionalStyles()
return mStyles;
}

QList<QgsConditionalStyle> QgsFieldUIProperties::matchingConditionalStyles( QVariant value, QgsFeature *feature )
{
QList<QgsConditionalStyle> styles;
foreach ( QgsConditionalStyle style, mStyles )
{
if ( style.matches( value, feature ) )
styles.append( style );
}
return styles;
}

QgsConditionalStyle QgsFieldUIProperties::matchingConditionalStyle( QVariant value, QgsFeature *feature )
{
foreach ( QgsConditionalStyle style, mStyles )
Expand Down
9 changes: 9 additions & 0 deletions src/core/qgsfielduiproperties.h
Expand Up @@ -32,6 +32,15 @@ class CORE_EXPORT QgsFieldUIProperties
*/
QList<QgsConditionalStyle> getConditionalStyles();

/**
* @brief Find and return the matching styles for the value and feature.
* If no match is found a invalid QgsCondtionalStyle is return.
*
* @return A condtional style that matches the value and feature.
* Check with QgsCondtionalStyle::isValid()
*/
QList<QgsConditionalStyle> matchingConditionalStyles( QVariant value, QgsFeature* feature );

/**
* @brief Find and return the matching style for the value and feature.
* If no match is found a invalid QgsCondtionalStyle is return.
Expand Down
14 changes: 13 additions & 1 deletion src/gui/attributetable/qgsattributetablemodel.cpp
Expand Up @@ -584,7 +584,19 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
}

QgsFieldUIProperties props = layer()->fieldUIProperties( field.name() );
QgsConditionalStyle style = props.matchingConditionalStyle( val, &mFeat );
QList<QgsConditionalStyle> styles = props.matchingConditionalStyles( val, &mFeat );
QgsConditionalStyle style;
foreach ( QgsConditionalStyle s, styles )
{
style.setFont( s.font() );
if ( s.backgroundColor().isValid() && s.backgroundColor().alpha() != 0 )
style.setBackgroundColor( s.backgroundColor() );
if ( s.textColor().isValid() && s.textColor().alpha() != 0 )
style.setTextColor( s.textColor() );
if ( s.symbol() )
style.setSymbol( s.symbol() );
}

if ( style.isValid() )
{
if ( role == Qt::BackgroundColorRole && style.backgroundColor().isValid() )
Expand Down
4 changes: 4 additions & 0 deletions src/gui/attributetable/qgsfieldconditionalformatwidget.cpp
Expand Up @@ -22,6 +22,10 @@ QgsFieldConditionalFormatWidget::QgsFieldConditionalFormatWidget( QWidget *paren
connect( mDefaultButtons , SIGNAL( buttonPressed( QAbstractButton* ) ), SLOT( defaultPressed( QAbstractButton* ) ) );
connect( btnChangeIcon , SIGNAL( clicked() ), SLOT( updateIcon() ) );
connect( btnBuildExpression , SIGNAL( clicked() ), SLOT( setExpression() ) );
btnBackgroundColor->setAllowAlpha( true );
btnBackgroundColor->setShowNoColor( true );
btnTextColor->setAllowAlpha( true );
btnTextColor->setShowNoColor( true );
mModel = new QStandardItemModel();
listView->setModel( mModel );
}
Expand Down

0 comments on commit db56307

Please sign in to comment.