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();
205 const auto constStyles = styles;
210 QStandardItem *item =
new QStandardItem( QStringLiteral(
"abc - 123" ) );
214 item->setForeground( style.
textColor() );
216 item->setIcon( style.
icon() );
217 item->setFont( style.
font() );
218 mPresetsModel->appendRow( item );
219 mPresets.append( style );
222 mPresetsList->setCurrentIndex( 0 );
227 QList<QgsConditionalStyle> styles;
230 styles.append( style );
233 styles.append( style );
236 styles.append( style );
239 styles.append( style );
242 styles.append( style );
245 styles.append( style );
249 void QgsFieldConditionalFormatWidget::saveRule()
251 QList<QgsConditionalStyle> styles = getStyles();
255 style.
setRule( mRuleEdit->text() );
256 style.
setName( mNameEdit->text() );
258 QColor backColor = btnBackgroundColor->color();
259 QColor fontColor = btnTextColor->color();
261 QFont font = mFontFamilyCmbBx->currentFont();
262 font.setBold( mFontBoldBtn->isChecked() );
263 font.setItalic( mFontItalicBtn->isChecked() );
264 font.setStrikeOut( mFontStrikethroughBtn->isChecked() );
265 font.setUnderline( mFontUnderlineBtn->isChecked() );
269 if ( checkIcon->isChecked() )
279 styles.replace( mEditIndex, style );
283 styles.append( style );
287 if ( fieldRadio->isChecked() )
289 fieldName = mFieldCombo->currentField();
292 if ( rowRadio->isChecked() )
296 pages->setCurrentIndex( 0 );
302 void QgsFieldConditionalFormatWidget::reloadStyles()
306 const auto constGetStyles = getStyles();
309 QStandardItem *item =
new QStandardItem( style.
displayText() );
311 mModel->appendRow( item );
315 void QgsFieldConditionalFormatWidget::fieldChanged(
const QString &fieldName )
317 Q_UNUSED( fieldName )
323 pages->setCurrentIndex( 0 );
326 bool QgsFieldConditionalFormatWidget::isCustomSet()
328 return ( btnBackgroundColor->color().isValid()
329 || btnTextColor->color().isValid()
330 || 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)
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.