29 mDeleteButton->hide();
31 connect( fieldRadio, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::reloadStyles );
32 connect( rowRadio, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::reloadStyles );
33 connect( mNewButton, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::addNewRule );
34 connect( mSaveRule, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::saveRule );
35 connect( mCancelButton, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::cancelRule );
36 connect( mDeleteButton, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::deleteRule );
37 connect( listView, &QAbstractItemView::clicked,
this, &QgsFieldConditionalFormatWidget::ruleClicked );
38 connect( btnBuildExpression, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::setExpression );
39 connect( mPresetsList,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsFieldConditionalFormatWidget::presetSet );
40 btnBackgroundColor->setAllowOpacity(
true );
41 btnBackgroundColor->setShowNoColor(
true );
42 btnTextColor->setAllowOpacity(
true );
43 btnTextColor->setShowNoColor(
true );
44 mPresetsModel =
new QStandardItemModel( listView );
45 mModel =
new QStandardItemModel( listView );
46 listView->setModel( mModel );
47 mPresetsList->setModel( mPresetsModel );
54 void QgsFieldConditionalFormatWidget::setExpression()
61 dlg.setWindowTitle( tr(
"Conditional Style Rule Expression" ) );
66 mRuleEdit->setText( expression );
70 void QgsFieldConditionalFormatWidget::presetSet(
int index )
72 if ( index == -1 || mPresets.isEmpty() )
76 setFormattingFromStyle( style );
82 mFieldCombo->setLayer( layer );
83 mFieldCombo->setCurrentIndex( 0 );
86 void QgsFieldConditionalFormatWidget::ruleClicked(
const QModelIndex &index )
88 QList<QgsConditionalStyle> styles = getStyles();
95 pages->setCurrentIndex( 1 );
96 mEditIndex = editIndex;
98 mDeleteButton->show();
104 mRuleEdit->setText( style.
rule() );
105 mNameEdit->setText( style.
name() );
106 setFormattingFromStyle( style );
108 void QgsFieldConditionalFormatWidget::setFormattingFromStyle(
const QgsConditionalStyle &style )
111 btnTextColor->setColor( style.
textColor() );
114 btnChangeIcon->setSymbol( style.
symbol()->
clone() );
115 checkIcon->setChecked(
true );
119 checkIcon->setChecked(
false );
121 QFont font = style.
font();
122 mFontBoldBtn->setChecked( font.bold() );
123 mFontItalicBtn->setChecked( font.italic() );
124 mFontStrikethroughBtn->setChecked( font.strikeOut() );
125 mFontUnderlineBtn->setChecked( font.underline() );
126 mFontFamilyCmbBx->setFont( font );
129 QList<QgsConditionalStyle> QgsFieldConditionalFormatWidget::getStyles()
131 QList<QgsConditionalStyle> styles;
132 if ( fieldRadio->isChecked() )
136 if ( rowRadio->isChecked() )
143 void QgsFieldConditionalFormatWidget::deleteRule()
145 QList<QgsConditionalStyle> styles = getStyles();
146 styles.removeAt( mEditIndex );
148 if ( fieldRadio->isChecked() )
150 fieldName = mFieldCombo->currentField();
153 if ( rowRadio->isChecked() )
158 pages->setCurrentIndex( 0 );
163 void QgsFieldConditionalFormatWidget::cancelRule()
165 pages->setCurrentIndex( 0 );
170 void QgsFieldConditionalFormatWidget::addNewRule()
172 pages->setCurrentIndex( 1 );
180 if ( fieldRadio->isChecked() )
182 mRuleEdit->setText( QStringLiteral(
"@value " ) );
184 btnBackgroundColor->setColor( QColor() );
185 btnTextColor->setColor( QColor() );
186 mPresetsList->setCurrentIndex( 0 );
187 mDeleteButton->hide();
189 checkIcon->setChecked(
false );
190 btnChangeIcon->setIcon( QIcon() );
191 btnBackgroundColor->setToNoColor();
192 btnTextColor->setToNoColor();
194 mFontBoldBtn->setChecked(
false );
195 mFontItalicBtn->setChecked(
false );
196 mFontStrikethroughBtn->setChecked(
false );
197 mFontUnderlineBtn->setChecked(
false );
204 mPresetsModel->clear();
209 QStandardItem *item =
new QStandardItem( QStringLiteral(
"abc - 123" ) );
213 item->setForeground( style.
textColor() );
215 item->setIcon( style.
icon() );
216 item->setFont( style.
font() );
217 mPresetsModel->appendRow( item );
218 mPresets.append( style );
221 mPresetsList->setCurrentIndex( 0 );
226 QList<QgsConditionalStyle> styles;
229 styles.append( style );
232 styles.append( style );
235 styles.append( style );
238 styles.append( style );
241 styles.append( style );
244 styles.append( style );
248 void QgsFieldConditionalFormatWidget::saveRule()
250 QList<QgsConditionalStyle> styles = getStyles();
254 style.
setRule( mRuleEdit->text() );
255 style.
setName( mNameEdit->text() );
257 QColor backColor = btnBackgroundColor->color();
258 QColor fontColor = btnTextColor->color();
260 QFont font = mFontFamilyCmbBx->currentFont();
261 font.setBold( mFontBoldBtn->isChecked() );
262 font.setItalic( mFontItalicBtn->isChecked() );
263 font.setStrikeOut( mFontStrikethroughBtn->isChecked() );
264 font.setUnderline( mFontUnderlineBtn->isChecked() );
268 if ( checkIcon->isChecked() )
278 styles.replace( mEditIndex, style );
282 styles.append( style );
286 if ( fieldRadio->isChecked() )
288 fieldName = mFieldCombo->currentField();
291 if ( rowRadio->isChecked() )
295 pages->setCurrentIndex( 0 );
301 void QgsFieldConditionalFormatWidget::reloadStyles()
307 QStandardItem *item =
new QStandardItem( style.
displayText() );
309 mModel->appendRow( item );
313 void QgsFieldConditionalFormatWidget::fieldChanged(
const QString &fieldName )
315 Q_UNUSED( fieldName );
321 pages->setCurrentIndex( 0 );
324 bool QgsFieldConditionalFormatWidget::isCustomSet()
326 return ( btnBackgroundColor->color().isValid()
327 || btnTextColor->color().isValid()
328 || mFontButtons->checkedId() != -1 );
QString name() const
The name of the style.
void setName(const QString &value)
Set the name of the style.
Single variable definition for use within a QgsExpressionContextScope.
void setRule(const QString &value)
Set the rule for the style.
QList< QgsConditionalStyle > fieldStyles(const QString &fieldName)
Returns the conditional styles set for the field UI properties.
QgsExpressionBuilderWidget * expressionBuilder()
The builder widget that is used by the dialog.
bool validBackgroundColor() const
Check if the background color is valid for render.
QPixmap icon() const
The icon set for style generated from the set symbol.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
A marker symbol type, for rendering Point and MultiPoint geometries.
QgsConditionalLayerStyles * conditionalStyles() const
Returns the conditional styles that are set for this layer.
QList< QgsConditionalStyle > rowStyles()
QgsExpressionContextScope * lastScope()
Returns the last scope added to the context.
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
Conditional styling for a rule.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
bool isValid() const
isValid Check if this rule is valid.
void fieldChanged(const QString &fieldName)
the signal is emitted when the currently selected field changes
QColor backgroundColor() const
The background color for style.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
void setBackgroundColor(const QColor &value)
Set the background color for the style.
void setFont(const QFont &value)
Set the font for the style.
void setRowStyles(const QList< QgsConditionalStyle > &styles)
Set the conditional styles that apply to full rows of data in the attribute table.
QColor textColor() const
The text color set for style.
QPixmap renderPreview() const
Render a preview icon of the rule.
void setSymbol(QgsSymbol *value)
Set the icon for the style.
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
bool validTextColor() const
Check if the text color is valid for render.
QgsSymbol * symbol() const
The symbol used to generate the icon for the style.
QString displayText() const
The name of the style.
void setHighlightedVariables(const QStringList &variableNames)
Sets the list of variable names within the context intended to be highlighted to the user...
QFont font() const
The font for the style.
void setFieldStyles(const QString &fieldName, const QList< QgsConditionalStyle > &styles)
Set the conditional styles for the field UI properties.
Represents a vector layer which manages a vector based data sets.
QString rule() const
The condition rule set for the style.
A generic dialog for building expression strings.
void setTextColor(const QColor &value)
Set the text color for the style.