16#include "moc_qgsfieldconditionalformatwidget.cpp"
38 connect( fieldRadio, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::typeChanged );
39 connect( rowRadio, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::typeChanged );
40 connect( mNewButton, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::addNewRule );
41 connect( listView, &QAbstractItemView::clicked,
this, &QgsFieldConditionalFormatWidget::ruleClicked );
42 mModel =
new QStandardItemModel( listView );
43 listView->setModel( mModel );
45 connect( fieldRadio, &QRadioButton::toggled, mFieldCombo, &QWidget::setEnabled );
53 mFieldCombo->setLayer( layer );
54 mFieldCombo->setCurrentIndex( 0 );
55 fieldChanged( mFieldCombo->currentField() );
58void QgsFieldConditionalFormatWidget::ruleClicked(
const QModelIndex &index )
60 const QList<QgsConditionalStyle> styles = getStyles();
67 mEditIndex = editIndex;
68 mEditing = editIndex >= 0;
69 mPanelHandled =
false;
77 if ( fieldRadio->isChecked() && style.
rule().isEmpty() )
79 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() )
120 mPanelHandled =
true;
126 mPanelHandled =
true;
136QList<QgsConditionalStyle> QgsFieldConditionalFormatWidget::getStyles()
138 QList<QgsConditionalStyle> styles;
139 if ( fieldRadio->isChecked() )
143 else if ( rowRadio->isChecked() )
151void QgsFieldConditionalFormatWidget::addNewRule()
167 QList<QgsConditionalStyle> styles;
170 styles.append( style );
173 styles.append( style );
176 styles.append( style );
179 styles.append( style );
182 styles.append( style );
185 styles.append( style );
189void QgsFieldConditionalFormatWidget::typeChanged()
194void QgsFieldConditionalFormatWidget::reloadStyles()
198 const auto constGetStyles = getStyles();
202 listView->setIconSize( size );
206 QStandardItem *item =
new QStandardItem( style.
displayText() );
208 mModel->appendRow( item );
212void QgsFieldConditionalFormatWidget::fieldChanged(
const QString &fieldName )
214 Q_UNUSED( fieldName )
218void QgsFieldConditionalFormatWidget::deleteCurrentRule()
223 QList<QgsConditionalStyle> styles = getStyles();
224 styles.removeAt( mEditIndex );
226 if ( fieldRadio->isChecked() )
228 fieldName = mFieldCombo->currentField();
231 else if ( rowRadio->isChecked() )
256 btnBackgroundColor->setColor( QColor() );
257 btnTextColor->setColor( QColor() );
258 checkIcon->setChecked(
false );
259 btnChangeIcon->setIcon( QIcon() );
260 btnBackgroundColor->setToNoColor();
261 btnTextColor->setToNoColor();
263 mFontBoldBtn->setChecked(
false );
264 mFontItalicBtn->setChecked(
false );
265 mFontStrikethroughBtn->setChecked(
false );
266 mFontUnderlineBtn->setChecked(
false );
269 mFontUnderlineBtn->setMinimumSize( buttonSize, buttonSize );
270 mFontUnderlineBtn->setMaximumSize( buttonSize, buttonSize );
271 mFontStrikethroughBtn->setMinimumSize( buttonSize, buttonSize );
272 mFontStrikethroughBtn->setMaximumSize( buttonSize, buttonSize );
273 mFontBoldBtn->setMinimumSize( buttonSize, buttonSize );
274 mFontBoldBtn->setMaximumSize( buttonSize, buttonSize );
275 mFontItalicBtn->setMinimumSize( buttonSize, buttonSize );
276 mFontItalicBtn->setMaximumSize( buttonSize, buttonSize );
282 connect( btnBuildExpression, &QAbstractButton::clicked,
this, &QgsEditConditionalFormatRuleWidget::setExpression );
283 connect( mPresetsList,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsEditConditionalFormatRuleWidget::presetSet );
285 btnBackgroundColor->setAllowOpacity(
true );
286 btnBackgroundColor->setShowNoColor(
true );
287 btnTextColor->setAllowOpacity(
true );
288 btnTextColor->setShowNoColor(
true );
289 mPresetsModel =
new QStandardItemModel( mPresetsList );
290 mPresetsList->setModel( mPresetsModel );
294 connect( checkIcon, &QCheckBox::toggled, btnChangeIcon, &QWidget::setEnabled );
304 mRuleEdit->setText( style.
rule() );
305 mNameEdit->setText( style.
name() );
306 setFormattingFromStyle( style );
313 style.
setRule( mRuleEdit->text() );
314 style.
setName( mNameEdit->text() );
316 const QColor backColor = btnBackgroundColor->color();
317 const QColor fontColor = btnTextColor->color();
319 QFont font = mFontFamilyCmbBx->currentFont();
320 font.setBold( mFontBoldBtn->isChecked() );
321 font.setItalic( mFontItalicBtn->isChecked() );
322 font.setStrikeOut( mFontStrikethroughBtn->isChecked() );
323 font.setUnderline( mFontUnderlineBtn->isChecked() );
327 if ( checkIcon->isChecked() )
338void QgsEditConditionalFormatRuleWidget::setExpression()
342 context.setHighlightedVariables( QStringList() << QStringLiteral(
"value" ) );
345 dlg.setWindowTitle( tr(
"Conditional Style Rule Expression" ) );
349 const QString expression = dlg.expressionBuilder()->expressionText();
350 mRuleEdit->setText( expression );
354void QgsEditConditionalFormatRuleWidget::presetSet(
int index )
356 if ( index == -1 || mPresets.isEmpty() )
359 const int styleIndex = mPresetsList->currentData( Qt::UserRole + 1 ).toInt();
361 setFormattingFromStyle( style );
364void QgsEditConditionalFormatRuleWidget::setFormattingFromStyle(
const QgsConditionalStyle &style )
367 btnTextColor->setColor( style.
textColor() );
368 if (
auto *lSymbol = style.
symbol() )
370 btnChangeIcon->setSymbol( lSymbol->clone() );
371 checkIcon->setChecked(
true );
375 checkIcon->setChecked(
false );
377 const QFont font = style.
font();
378 mFontBoldBtn->setChecked( font.bold() );
379 mFontItalicBtn->setChecked( font.italic() );
380 mFontStrikethroughBtn->setChecked( font.strikeOut() );
381 mFontUnderlineBtn->setChecked( font.underline() );
382 mFontFamilyCmbBx->setCurrentFont( font );
388 mPresetsModel->clear();
389 QStandardItem *item =
new QStandardItem( QString() );
390 mPresetsModel->appendRow( item );
396 QStandardItem *item =
new QStandardItem( QStringLiteral(
"abc - 123" ) );
400 item->setForeground( style.
textColor() );
402 item->setIcon( style.
icon() );
403 item->setFont( style.
font() );
404 item->setData( i, Qt::UserRole + 1 );
405 mPresetsModel->appendRow( item );
406 mPresets.append( style );
410 mPresetsList->setCurrentIndex( 0 );
415 mRuleEdit->setText( rule );
418bool QgsEditConditionalFormatRuleWidget::isCustomSet()
420 return ( btnBackgroundColor->color().isValid() || btnTextColor->color().isValid() || 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.