36 connect( fieldRadio, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::reloadStyles );
37 connect( rowRadio, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::reloadStyles );
38 connect( mNewButton, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::addNewRule );
39 connect( listView, &QAbstractItemView::clicked,
this, &QgsFieldConditionalFormatWidget::ruleClicked );
40 mModel =
new QStandardItemModel( listView );
41 listView->setModel( mModel );
43 connect( fieldRadio, &QRadioButton::toggled, mFieldCombo, &QWidget::setEnabled );
51 mFieldCombo->setLayer( layer );
52 mFieldCombo->setCurrentIndex( 0 );
55 void QgsFieldConditionalFormatWidget::ruleClicked(
const QModelIndex &index )
57 QList<QgsConditionalStyle> styles = getStyles();
64 mEditIndex = editIndex;
65 mEditing = editIndex >= 0;
66 mPanelHandled =
false;
74 if ( fieldRadio->isChecked() )
76 ruleWidget->
setRule( QStringLiteral(
"@value " ) );
88 QList<QgsConditionalStyle> styles = getStyles();
91 styles.replace( mEditIndex, ruleWidget->
currentStyle() );
99 if ( fieldRadio->isChecked() )
101 fieldName = mFieldCombo->currentField();
104 if ( rowRadio->isChecked() )
119 mPanelHandled =
true;
126 mPanelHandled =
true;
136 QList<QgsConditionalStyle> QgsFieldConditionalFormatWidget::getStyles()
138 QList<QgsConditionalStyle> styles;
139 if ( fieldRadio->isChecked() )
143 if ( rowRadio->isChecked() )
150 void QgsFieldConditionalFormatWidget::addNewRule()
166 QList<QgsConditionalStyle> styles;
169 styles.append( style );
172 styles.append( style );
175 styles.append( style );
178 styles.append( style );
181 styles.append( style );
184 styles.append( style );
188 void QgsFieldConditionalFormatWidget::reloadStyles()
192 const auto constGetStyles = getStyles();
195 listView->setIconSize( size );
199 QStandardItem *item =
new QStandardItem( style.displayText() );
200 item->setIcon( QIcon( style.renderPreview( size ) ) );
201 mModel->appendRow( item );
205 void QgsFieldConditionalFormatWidget::fieldChanged(
const QString &fieldName )
207 Q_UNUSED( fieldName )
211 void QgsFieldConditionalFormatWidget::deleteCurrentRule()
216 QList<QgsConditionalStyle> styles = getStyles();
217 styles.removeAt( mEditIndex );
219 if ( fieldRadio->isChecked() )
221 fieldName = mFieldCombo->currentField();
224 if ( rowRadio->isChecked() )
249 btnBackgroundColor->setColor( QColor() );
250 btnTextColor->setColor( QColor() );
251 checkIcon->setChecked(
false );
252 btnChangeIcon->setIcon( QIcon() );
253 btnBackgroundColor->setToNoColor();
254 btnTextColor->setToNoColor();
256 mFontBoldBtn->setChecked(
false );
257 mFontItalicBtn->setChecked(
false );
258 mFontStrikethroughBtn->setChecked(
false );
259 mFontUnderlineBtn->setChecked(
false );
262 mFontUnderlineBtn->setMinimumSize( buttonSize, buttonSize );
263 mFontUnderlineBtn->setMaximumSize( buttonSize, buttonSize );
264 mFontStrikethroughBtn->setMinimumSize( buttonSize, buttonSize );
265 mFontStrikethroughBtn->setMaximumSize( buttonSize, buttonSize );
266 mFontBoldBtn->setMinimumSize( buttonSize, buttonSize );
267 mFontBoldBtn->setMaximumSize( buttonSize, buttonSize );
268 mFontItalicBtn->setMinimumSize( buttonSize, buttonSize );
269 mFontItalicBtn->setMaximumSize( buttonSize, buttonSize );
275 connect( btnBuildExpression, &QAbstractButton::clicked,
this, &QgsEditConditionalFormatRuleWidget::setExpression );
276 connect( mPresetsList,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsEditConditionalFormatRuleWidget::presetSet );
278 btnBackgroundColor->setAllowOpacity(
true );
279 btnBackgroundColor->setShowNoColor(
true );
280 btnTextColor->setAllowOpacity(
true );
281 btnTextColor->setShowNoColor(
true );
282 mPresetsModel =
new QStandardItemModel( mPresetsList );
283 mPresetsList->setModel( mPresetsModel );
287 connect( checkIcon, &QCheckBox::toggled, btnChangeIcon, &QWidget::setEnabled );
297 mRuleEdit->setText( style.
rule() );
298 mNameEdit->setText( style.
name() );
299 setFormattingFromStyle( style );
306 style.
setRule( mRuleEdit->text() );
307 style.
setName( mNameEdit->text() );
309 QColor backColor = btnBackgroundColor->color();
310 QColor fontColor = btnTextColor->color();
312 QFont font = mFontFamilyCmbBx->currentFont();
313 font.setBold( mFontBoldBtn->isChecked() );
314 font.setItalic( mFontItalicBtn->isChecked() );
315 font.setStrikeOut( mFontStrikethroughBtn->isChecked() );
316 font.setUnderline( mFontUnderlineBtn->isChecked() );
320 if ( checkIcon->isChecked() )
331 void QgsEditConditionalFormatRuleWidget::setExpression()
338 dlg.setWindowTitle( tr(
"Conditional Style Rule Expression" ) );
343 mRuleEdit->setText( expression );
347 void QgsEditConditionalFormatRuleWidget::presetSet(
int index )
349 if ( index == -1 || mPresets.isEmpty() )
352 const int styleIndex = mPresetsList->currentData( Qt::UserRole + 1 ).toInt();
354 setFormattingFromStyle( style );
357 void QgsEditConditionalFormatRuleWidget::setFormattingFromStyle(
const QgsConditionalStyle &style )
360 btnTextColor->setColor( style.
textColor() );
363 btnChangeIcon->setSymbol( style.
symbol()->
clone() );
364 checkIcon->setChecked(
true );
368 checkIcon->setChecked(
false );
370 QFont font = style.
font();
371 mFontBoldBtn->setChecked( font.bold() );
372 mFontItalicBtn->setChecked( font.italic() );
373 mFontStrikethroughBtn->setChecked( font.strikeOut() );
374 mFontUnderlineBtn->setChecked( font.underline() );
375 mFontFamilyCmbBx->setCurrentFont( font );
381 mPresetsModel->clear();
382 QStandardItem *item =
new QStandardItem( QString() );
383 mPresetsModel->appendRow( item );
389 QStandardItem *item =
new QStandardItem( QStringLiteral(
"abc - 123" ) );
393 item->setForeground( style.
textColor() );
395 item->setIcon( style.
icon() );
396 item->setFont( style.
font() );
397 item->setData( i, Qt::UserRole + 1 );
398 mPresetsModel->appendRow( item );
399 mPresets.append( style );
403 mPresetsList->setCurrentIndex( 0 );
408 mRuleEdit->setText( rule );
411 bool QgsEditConditionalFormatRuleWidget::isCustomSet()
413 return ( btnBackgroundColor->color().isValid()
414 || btnTextColor->color().isValid()
415 || 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.
static const double UI_SCALE_FACTOR
UI scaling factor.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly...
void setRule(const QString &value)
Set the rule for the style.
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.
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.
QList< QgsConditionalStyle > fieldStyles(const QString &fieldName) const
Returns the conditional styles set for the field with matching fieldName.
void setFont(const QFont &value)
Set the font for the style.
QColor textColor() const
The text color set for style.
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.
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 setRowStyles(const QgsConditionalStyles &styles)
Sets the conditional styles that apply to full rows of data in the attribute table.
void setFieldStyles(const QString &fieldName, const QList< QgsConditionalStyle > &styles)
Set the conditional styles for a field, with the specified fieldName.
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.
QgsConditionalStyles rowStyles() const
Returns a list of row styles associated with the layer.
void setTextColor(const QColor &value)
Set the text color for the style.