37 connect( fieldRadio, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::reloadStyles );
38 connect( rowRadio, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::reloadStyles );
39 connect( mNewButton, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::addNewRule );
40 connect( listView, &QAbstractItemView::clicked,
this, &QgsFieldConditionalFormatWidget::ruleClicked );
41 mModel =
new QStandardItemModel( listView );
42 listView->setModel( mModel );
44 connect( fieldRadio, &QRadioButton::toggled, mFieldCombo, &QWidget::setEnabled );
52 mFieldCombo->setLayer( layer );
53 mFieldCombo->setCurrentIndex( 0 );
54 fieldChanged( mFieldCombo->currentField() );
57void QgsFieldConditionalFormatWidget::ruleClicked(
const QModelIndex &index )
59 const QList<QgsConditionalStyle> styles = getStyles();
66 mEditIndex = editIndex;
67 mEditing = editIndex >= 0;
68 mPanelHandled =
false;
76 if ( fieldRadio->isChecked() && style.
rule().isEmpty() )
78 ruleWidget->
setRule( QStringLiteral(
"@value " ) );
90 QList<QgsConditionalStyle> styles = getStyles();
93 styles.replace( mEditIndex, ruleWidget->
currentStyle() );
101 if ( fieldRadio->isChecked() )
103 fieldName = mFieldCombo->currentField();
106 if ( rowRadio->isChecked() )
121 mPanelHandled =
true;
128 mPanelHandled =
true;
138QList<QgsConditionalStyle> QgsFieldConditionalFormatWidget::getStyles()
140 QList<QgsConditionalStyle> styles;
141 if ( fieldRadio->isChecked() )
145 if ( rowRadio->isChecked() )
152void QgsFieldConditionalFormatWidget::addNewRule()
168 QList<QgsConditionalStyle> styles;
171 styles.append( style );
174 styles.append( style );
177 styles.append( style );
180 styles.append( style );
183 styles.append( style );
186 styles.append( style );
190void QgsFieldConditionalFormatWidget::reloadStyles()
194 const auto constGetStyles = getStyles();
198 listView->setIconSize( size );
202 QStandardItem *item =
new QStandardItem( style.
displayText() );
204 mModel->appendRow( item );
208void QgsFieldConditionalFormatWidget::fieldChanged(
const QString &fieldName )
210 Q_UNUSED( fieldName )
214void QgsFieldConditionalFormatWidget::deleteCurrentRule()
219 QList<QgsConditionalStyle> styles = getStyles();
220 styles.removeAt( mEditIndex );
222 if ( fieldRadio->isChecked() )
224 fieldName = mFieldCombo->currentField();
227 if ( rowRadio->isChecked() )
252 btnBackgroundColor->setColor( QColor() );
253 btnTextColor->setColor( QColor() );
254 checkIcon->setChecked(
false );
255 btnChangeIcon->setIcon( QIcon() );
256 btnBackgroundColor->setToNoColor();
257 btnTextColor->setToNoColor();
259 mFontBoldBtn->setChecked(
false );
260 mFontItalicBtn->setChecked(
false );
261 mFontStrikethroughBtn->setChecked(
false );
262 mFontUnderlineBtn->setChecked(
false );
265 mFontUnderlineBtn->setMinimumSize( buttonSize, buttonSize );
266 mFontUnderlineBtn->setMaximumSize( buttonSize, buttonSize );
267 mFontStrikethroughBtn->setMinimumSize( buttonSize, buttonSize );
268 mFontStrikethroughBtn->setMaximumSize( buttonSize, buttonSize );
269 mFontBoldBtn->setMinimumSize( buttonSize, buttonSize );
270 mFontBoldBtn->setMaximumSize( buttonSize, buttonSize );
271 mFontItalicBtn->setMinimumSize( buttonSize, buttonSize );
272 mFontItalicBtn->setMaximumSize( buttonSize, buttonSize );
278 connect( btnBuildExpression, &QAbstractButton::clicked,
this, &QgsEditConditionalFormatRuleWidget::setExpression );
279 connect( mPresetsList,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsEditConditionalFormatRuleWidget::presetSet );
281 btnBackgroundColor->setAllowOpacity(
true );
282 btnBackgroundColor->setShowNoColor(
true );
283 btnTextColor->setAllowOpacity(
true );
284 btnTextColor->setShowNoColor(
true );
285 mPresetsModel =
new QStandardItemModel( mPresetsList );
286 mPresetsList->setModel( mPresetsModel );
290 connect( checkIcon, &QCheckBox::toggled, btnChangeIcon, &QWidget::setEnabled );
300 mRuleEdit->setText( style.
rule() );
301 mNameEdit->setText( style.
name() );
302 setFormattingFromStyle( style );
309 style.
setRule( mRuleEdit->text() );
310 style.
setName( mNameEdit->text() );
312 const QColor backColor = btnBackgroundColor->color();
313 const QColor fontColor = btnTextColor->color();
315 QFont font = mFontFamilyCmbBx->currentFont();
316 font.setBold( mFontBoldBtn->isChecked() );
317 font.setItalic( mFontItalicBtn->isChecked() );
318 font.setStrikeOut( mFontStrikethroughBtn->isChecked() );
319 font.setUnderline( mFontUnderlineBtn->isChecked() );
323 if ( checkIcon->isChecked() )
334void QgsEditConditionalFormatRuleWidget::setExpression()
338 context.setHighlightedVariables( QStringList() << QStringLiteral(
"value" ) );
341 dlg.setWindowTitle( tr(
"Conditional Style Rule Expression" ) );
345 const QString expression = dlg.expressionBuilder()->expressionText();
346 mRuleEdit->setText( expression );
350void QgsEditConditionalFormatRuleWidget::presetSet(
int index )
352 if ( index == -1 || mPresets.isEmpty() )
355 const int styleIndex = mPresetsList->currentData( Qt::UserRole + 1 ).toInt();
357 setFormattingFromStyle( style );
360void QgsEditConditionalFormatRuleWidget::setFormattingFromStyle(
const QgsConditionalStyle &style )
363 btnTextColor->setColor( style.
textColor() );
364 if (
auto *lSymbol = style.
symbol() )
366 btnChangeIcon->setSymbol( lSymbol->clone() );
367 checkIcon->setChecked(
true );
371 checkIcon->setChecked(
false );
373 const QFont font = style.
font();
374 mFontBoldBtn->setChecked( font.bold() );
375 mFontItalicBtn->setChecked( font.italic() );
376 mFontStrikethroughBtn->setChecked( font.strikeOut() );
377 mFontUnderlineBtn->setChecked( font.underline() );
378 mFontFamilyCmbBx->setCurrentFont( font );
384 mPresetsModel->clear();
385 QStandardItem *item =
new QStandardItem( QString() );
386 mPresetsModel->appendRow( item );
392 QStandardItem *item =
new QStandardItem( QStringLiteral(
"abc - 123" ) );
396 item->setForeground( style.
textColor() );
398 item->setIcon( style.
icon() );
399 item->setFont( style.
font() );
400 item->setData( i, Qt::UserRole + 1 );
401 mPresetsModel->appendRow( item );
402 mPresets.append( style );
406 mPresetsList->setCurrentIndex( 0 );
411 mRuleEdit->setText( rule );
414bool QgsEditConditionalFormatRuleWidget::isCustomSet()
416 return ( btnBackgroundColor->color().isValid()
417 || btnTextColor->color().isValid()
418 || mFontButtons->checkedId() != -1 );
static const double UI_SCALE_FACTOR
UI scaling factor.
QgsConditionalStyles rowStyles() const
Returns a list of row styles associated with the layer.
QList< QgsConditionalStyle > fieldStyles(const QString &fieldName) const
Returns the conditional styles set for the field with matching fieldName.
void setFieldStyles(const QString &fieldName, const QList< QgsConditionalStyle > &styles)
Set the conditional styles for a field, with the specified fieldName.
void setRowStyles(const QgsConditionalStyles &styles)
Sets the conditional styles that apply to full rows of data in the attribute table.
Conditional styling for a rule.
QString displayText() const
The name of the style.
QString name() const
The name of the style.
void setSymbol(QgsSymbol *value)
Set the icon for the style.
void setName(const QString &value)
Set the name of the style.
QPixmap renderPreview(const QSize &size=QSize()) const
Render a preview icon of the rule, at the specified size.
void setTextColor(const QColor &value)
Set the text color for the style.
void setRule(const QString &value)
Set the rule for the style.
void setBackgroundColor(const QColor &value)
Set the background color for the style.
void setFont(const QFont &value)
Set the font for the style.
QColor backgroundColor() const
The background color for style.
QColor textColor() const
The text color set for style.
QString rule() const
The condition rule set for the style.
QFont font() const
The font for the style.
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.
bool isValid() const
isValid Check if this rule is valid.
QPixmap icon() const
The icon set for style generated from the set symbol.
bool validBackgroundColor() const
Check if the background color is valid for render.
A generic dialog for building expression strings.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void fieldChanged(const QString &fieldName)
Emitted when the currently selected field changes.
A marker symbol type, for rendering Point and MultiPoint geometries.
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
Represents a vector layer which manages a vector based data sets.
QgsConditionalLayerStyles * conditionalStyles() const
Returns the conditional styles that are set for this layer.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly,...
Single variable definition for use within a QgsExpressionContextScope.