Skip to content

Commit db56307

Browse files
committed
Allow fall though of conditional rules
1 parent 76f4f7c commit db56307

5 files changed

+39
-3
lines changed

src/core/qgsconditionalstyle.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ bool QgsConditionalStyle::matches( QVariant value, QgsFeature *feature )
8383
QPixmap QgsConditionalStyle::renderPreview()
8484
{
8585
QPixmap pixmap( 64, 32 );
86+
pixmap.fill( Qt::transparent );
87+
8688
QPainter painter( &pixmap );
8789

8890
if ( mBackColor.isValid() )
8991
painter.setBrush( mBackColor );
90-
else
91-
painter.setBrush( QColor( Qt::white ) );
9292

9393
QRect rect = QRect( 0, 0, 64, 32 );
9494
painter.setPen( Qt::NoPen );

src/core/qgsfielduiproperties.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ QList<QgsConditionalStyle> QgsFieldUIProperties::getConditionalStyles()
1818
return mStyles;
1919
}
2020

21+
QList<QgsConditionalStyle> QgsFieldUIProperties::matchingConditionalStyles( QVariant value, QgsFeature *feature )
22+
{
23+
QList<QgsConditionalStyle> styles;
24+
foreach ( QgsConditionalStyle style, mStyles )
25+
{
26+
if ( style.matches( value, feature ) )
27+
styles.append( style );
28+
}
29+
return styles;
30+
}
31+
2132
QgsConditionalStyle QgsFieldUIProperties::matchingConditionalStyle( QVariant value, QgsFeature *feature )
2233
{
2334
foreach ( QgsConditionalStyle style, mStyles )

src/core/qgsfielduiproperties.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ class CORE_EXPORT QgsFieldUIProperties
3232
*/
3333
QList<QgsConditionalStyle> getConditionalStyles();
3434

35+
/**
36+
* @brief Find and return the matching styles for the value and feature.
37+
* If no match is found a invalid QgsCondtionalStyle is return.
38+
*
39+
* @return A condtional style that matches the value and feature.
40+
* Check with QgsCondtionalStyle::isValid()
41+
*/
42+
QList<QgsConditionalStyle> matchingConditionalStyles( QVariant value, QgsFeature* feature );
43+
3544
/**
3645
* @brief Find and return the matching style for the value and feature.
3746
* If no match is found a invalid QgsCondtionalStyle is return.

src/gui/attributetable/qgsattributetablemodel.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,19 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
584584
}
585585

586586
QgsFieldUIProperties props = layer()->fieldUIProperties( field.name() );
587-
QgsConditionalStyle style = props.matchingConditionalStyle( val, &mFeat );
587+
QList<QgsConditionalStyle> styles = props.matchingConditionalStyles( val, &mFeat );
588+
QgsConditionalStyle style;
589+
foreach ( QgsConditionalStyle s, styles )
590+
{
591+
style.setFont( s.font() );
592+
if ( s.backgroundColor().isValid() && s.backgroundColor().alpha() != 0 )
593+
style.setBackgroundColor( s.backgroundColor() );
594+
if ( s.textColor().isValid() && s.textColor().alpha() != 0 )
595+
style.setTextColor( s.textColor() );
596+
if ( s.symbol() )
597+
style.setSymbol( s.symbol() );
598+
}
599+
588600
if ( style.isValid() )
589601
{
590602
if ( role == Qt::BackgroundColorRole && style.backgroundColor().isValid() )

src/gui/attributetable/qgsfieldconditionalformatwidget.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ QgsFieldConditionalFormatWidget::QgsFieldConditionalFormatWidget( QWidget *paren
2222
connect( mDefaultButtons , SIGNAL( buttonPressed( QAbstractButton* ) ), SLOT( defaultPressed( QAbstractButton* ) ) );
2323
connect( btnChangeIcon , SIGNAL( clicked() ), SLOT( updateIcon() ) );
2424
connect( btnBuildExpression , SIGNAL( clicked() ), SLOT( setExpression() ) );
25+
btnBackgroundColor->setAllowAlpha( true );
26+
btnBackgroundColor->setShowNoColor( true );
27+
btnTextColor->setAllowAlpha( true );
28+
btnTextColor->setShowNoColor( true );
2529
mModel = new QStandardItemModel();
2630
listView->setModel( mModel );
2731
}

0 commit comments

Comments
 (0)