37 connect( fieldRadio, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::typeChanged );
38 connect( rowRadio, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::typeChanged );
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 else if ( rowRadio->isChecked() )
122 mPanelHandled =
true;
129 mPanelHandled =
true;
139QList<QgsConditionalStyle> QgsFieldConditionalFormatWidget::getStyles()
141 QList<QgsConditionalStyle> styles;
142 if ( fieldRadio->isChecked() )
146 else if ( rowRadio->isChecked() )
154void QgsFieldConditionalFormatWidget::addNewRule()
170 QList<QgsConditionalStyle> styles;
173 styles.append( style );
176 styles.append( style );
179 styles.append( style );
182 styles.append( style );
185 styles.append( style );
188 styles.append( style );
192void QgsFieldConditionalFormatWidget::typeChanged()
197void QgsFieldConditionalFormatWidget::reloadStyles()
201 const auto constGetStyles = getStyles();
205 listView->setIconSize( size );
209 QStandardItem *item =
new QStandardItem( style.
displayText() );
211 mModel->appendRow( item );
215void QgsFieldConditionalFormatWidget::fieldChanged(
const QString &fieldName )
217 Q_UNUSED( fieldName )
221void QgsFieldConditionalFormatWidget::deleteCurrentRule()
226 QList<QgsConditionalStyle> styles = getStyles();
227 styles.removeAt( mEditIndex );
229 if ( fieldRadio->isChecked() )
231 fieldName = mFieldCombo->currentField();
234 else if ( rowRadio->isChecked() )
259 btnBackgroundColor->setColor( QColor() );
260 btnTextColor->setColor( QColor() );
261 checkIcon->setChecked(
false );
262 btnChangeIcon->setIcon( QIcon() );
263 btnBackgroundColor->setToNoColor();
264 btnTextColor->setToNoColor();
266 mFontBoldBtn->setChecked(
false );
267 mFontItalicBtn->setChecked(
false );
268 mFontStrikethroughBtn->setChecked(
false );
269 mFontUnderlineBtn->setChecked(
false );
272 mFontUnderlineBtn->setMinimumSize( buttonSize, buttonSize );
273 mFontUnderlineBtn->setMaximumSize( buttonSize, buttonSize );
274 mFontStrikethroughBtn->setMinimumSize( buttonSize, buttonSize );
275 mFontStrikethroughBtn->setMaximumSize( buttonSize, buttonSize );
276 mFontBoldBtn->setMinimumSize( buttonSize, buttonSize );
277 mFontBoldBtn->setMaximumSize( buttonSize, buttonSize );
278 mFontItalicBtn->setMinimumSize( buttonSize, buttonSize );
279 mFontItalicBtn->setMaximumSize( buttonSize, buttonSize );
285 connect( btnBuildExpression, &QAbstractButton::clicked,
this, &QgsEditConditionalFormatRuleWidget::setExpression );
286 connect( mPresetsList,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsEditConditionalFormatRuleWidget::presetSet );
288 btnBackgroundColor->setAllowOpacity(
true );
289 btnBackgroundColor->setShowNoColor(
true );
290 btnTextColor->setAllowOpacity(
true );
291 btnTextColor->setShowNoColor(
true );
292 mPresetsModel =
new QStandardItemModel( mPresetsList );
293 mPresetsList->setModel( mPresetsModel );
297 connect( checkIcon, &QCheckBox::toggled, btnChangeIcon, &QWidget::setEnabled );
307 mRuleEdit->setText( style.
rule() );
308 mNameEdit->setText( style.
name() );
309 setFormattingFromStyle( style );
316 style.
setRule( mRuleEdit->text() );
317 style.
setName( mNameEdit->text() );
319 const QColor backColor = btnBackgroundColor->color();
320 const QColor fontColor = btnTextColor->color();
322 QFont font = mFontFamilyCmbBx->currentFont();
323 font.setBold( mFontBoldBtn->isChecked() );
324 font.setItalic( mFontItalicBtn->isChecked() );
325 font.setStrikeOut( mFontStrikethroughBtn->isChecked() );
326 font.setUnderline( mFontUnderlineBtn->isChecked() );
330 if ( checkIcon->isChecked() )
341void QgsEditConditionalFormatRuleWidget::setExpression()
345 context.setHighlightedVariables( QStringList() << QStringLiteral(
"value" ) );
348 dlg.setWindowTitle( tr(
"Conditional Style Rule Expression" ) );
352 const QString expression = dlg.expressionBuilder()->expressionText();
353 mRuleEdit->setText( expression );
357void QgsEditConditionalFormatRuleWidget::presetSet(
int index )
359 if ( index == -1 || mPresets.isEmpty() )
362 const int styleIndex = mPresetsList->currentData( Qt::UserRole + 1 ).toInt();
364 setFormattingFromStyle( style );
367void QgsEditConditionalFormatRuleWidget::setFormattingFromStyle(
const QgsConditionalStyle &style )
370 btnTextColor->setColor( style.
textColor() );
371 if (
auto *lSymbol = style.
symbol() )
373 btnChangeIcon->setSymbol( lSymbol->clone() );
374 checkIcon->setChecked(
true );
378 checkIcon->setChecked(
false );
380 const QFont font = style.
font();
381 mFontBoldBtn->setChecked( font.bold() );
382 mFontItalicBtn->setChecked( font.italic() );
383 mFontStrikethroughBtn->setChecked( font.strikeOut() );
384 mFontUnderlineBtn->setChecked( font.underline() );
385 mFontFamilyCmbBx->setCurrentFont( font );
391 mPresetsModel->clear();
392 QStandardItem *item =
new QStandardItem( QString() );
393 mPresetsModel->appendRow( item );
399 QStandardItem *item =
new QStandardItem( QStringLiteral(
"abc - 123" ) );
403 item->setForeground( style.
textColor() );
405 item->setIcon( style.
icon() );
406 item->setFont( style.
font() );
407 item->setData( i, Qt::UserRole + 1 );
408 mPresetsModel->appendRow( item );
409 mPresets.append( style );
413 mPresetsList->setCurrentIndex( 0 );
418 mRuleEdit->setText( rule );
421bool QgsEditConditionalFormatRuleWidget::isCustomSet()
423 return ( btnBackgroundColor->color().isValid()
424 || btnTextColor->color().isValid()
425 || 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(Qgis::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.