27#include "moc_qgsfieldconditionalformatwidget.cpp"
39 connect( fieldRadio, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::typeChanged );
40 connect( rowRadio, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::typeChanged );
41 connect( mNewButton, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::addNewRule );
42 connect( listView, &QAbstractItemView::clicked,
this, &QgsFieldConditionalFormatWidget::ruleClicked );
43 mModel =
new QStandardItemModel( listView );
44 listView->setModel( mModel );
46 connect( fieldRadio, &QRadioButton::toggled, mFieldCombo, &QWidget::setEnabled );
54 mFieldCombo->setLayer( layer );
55 mFieldCombo->setCurrentIndex( 0 );
56 fieldChanged( mFieldCombo->currentField() );
59void QgsFieldConditionalFormatWidget::ruleClicked(
const QModelIndex &index )
61 const QList<QgsConditionalStyle> styles = getStyles();
68 mEditIndex = editIndex;
69 mEditing = editIndex >= 0;
70 mPanelHandled =
false;
78 if ( fieldRadio->isChecked() && style.
rule().isEmpty() )
80 ruleWidget->
setRule( QStringLiteral(
"@value " ) );
91 QList<QgsConditionalStyle> styles = getStyles();
94 styles.replace( mEditIndex, ruleWidget->
currentStyle() );
102 if ( fieldRadio->isChecked() )
104 fieldName = mFieldCombo->currentField();
105 mLayer->conditionalStyles()->setFieldStyles( fieldName, styles );
107 else if ( rowRadio->isChecked() )
109 mLayer->conditionalStyles()->setRowStyles( styles );
121 mPanelHandled =
true;
127 mPanelHandled =
true;
137QList<QgsConditionalStyle> QgsFieldConditionalFormatWidget::getStyles()
139 QList<QgsConditionalStyle> styles;
140 if ( fieldRadio->isChecked() )
144 else if ( rowRadio->isChecked() )
146 styles = mLayer->conditionalStyles()->rowStyles();
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::typeChanged()
195void QgsFieldConditionalFormatWidget::reloadStyles()
199 const auto constGetStyles = getStyles();
203 listView->setIconSize( size );
205 for (
const QgsConditionalStyle &style : constGetStyles )
207 QStandardItem *item =
new QStandardItem( style.
displayText() );
209 mModel->appendRow( item );
213void QgsFieldConditionalFormatWidget::fieldChanged(
const QString &fieldName )
215 Q_UNUSED( fieldName )
219void QgsFieldConditionalFormatWidget::deleteCurrentRule()
224 QList<QgsConditionalStyle> styles = getStyles();
225 styles.removeAt( mEditIndex );
227 if ( fieldRadio->isChecked() )
229 fieldName = mFieldCombo->currentField();
230 mLayer->conditionalStyles()->setFieldStyles( fieldName, styles );
232 else if ( rowRadio->isChecked() )
234 mLayer->conditionalStyles()->setRowStyles( styles );
257 btnBackgroundColor->setColor( QColor() );
258 btnTextColor->setColor( QColor() );
259 checkIcon->setChecked(
false );
260 btnChangeIcon->setIcon( QIcon() );
261 btnBackgroundColor->setToNoColor();
262 btnTextColor->setToNoColor();
264 mFontBoldBtn->setChecked(
false );
265 mFontItalicBtn->setChecked(
false );
266 mFontStrikethroughBtn->setChecked(
false );
267 mFontUnderlineBtn->setChecked(
false );
270 mFontUnderlineBtn->setMinimumSize( buttonSize, buttonSize );
271 mFontUnderlineBtn->setMaximumSize( buttonSize, buttonSize );
272 mFontStrikethroughBtn->setMinimumSize( buttonSize, buttonSize );
273 mFontStrikethroughBtn->setMaximumSize( buttonSize, buttonSize );
274 mFontBoldBtn->setMinimumSize( buttonSize, buttonSize );
275 mFontBoldBtn->setMaximumSize( buttonSize, buttonSize );
276 mFontItalicBtn->setMinimumSize( buttonSize, buttonSize );
277 mFontItalicBtn->setMaximumSize( buttonSize, buttonSize );
283 connect( btnBuildExpression, &QAbstractButton::clicked,
this, &QgsEditConditionalFormatRuleWidget::setExpression );
284 connect( mPresetsList,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsEditConditionalFormatRuleWidget::presetSet );
286 btnBackgroundColor->setAllowOpacity(
true );
287 btnBackgroundColor->setShowNoColor(
true );
288 btnTextColor->setAllowOpacity(
true );
289 btnTextColor->setShowNoColor(
true );
290 mPresetsModel =
new QStandardItemModel( mPresetsList );
291 mPresetsList->setModel( mPresetsModel );
295 connect( checkIcon, &QCheckBox::toggled, btnChangeIcon, &QWidget::setEnabled );
305 mRuleEdit->setText( style.
rule() );
306 mNameEdit->setText( style.
name() );
307 setFormattingFromStyle( style );
314 style.
setRule( mRuleEdit->text() );
315 style.
setName( mNameEdit->text() );
317 const QColor backColor = btnBackgroundColor->color();
318 const QColor fontColor = btnTextColor->color();
320 QFont font = mFontFamilyCmbBx->currentFont();
321 font.setBold( mFontBoldBtn->isChecked() );
322 font.setItalic( mFontItalicBtn->isChecked() );
323 font.setStrikeOut( mFontStrikethroughBtn->isChecked() );
324 font.setUnderline( mFontUnderlineBtn->isChecked() );
328 if ( checkIcon->isChecked() )
339void QgsEditConditionalFormatRuleWidget::setExpression()
343 context.setHighlightedVariables( QStringList() << QStringLiteral(
"value" ) );
346 dlg.setWindowTitle( tr(
"Conditional Style Rule Expression" ) );
350 const QString expression = dlg.expressionBuilder()->expressionText();
351 mRuleEdit->setText( expression );
355void QgsEditConditionalFormatRuleWidget::presetSet(
int index )
357 if ( index == -1 || mPresets.isEmpty() )
360 const int styleIndex = mPresetsList->currentData( Qt::UserRole + 1 ).toInt();
361 const QgsConditionalStyle style = mPresets.at( styleIndex );
362 setFormattingFromStyle( style );
365void QgsEditConditionalFormatRuleWidget::setFormattingFromStyle(
const QgsConditionalStyle &style )
368 btnTextColor->setColor( style.
textColor() );
369 if (
auto *lSymbol = style.
symbol() )
371 btnChangeIcon->setSymbol( lSymbol->clone() );
372 checkIcon->setChecked(
true );
376 checkIcon->setChecked(
false );
378 const QFont font = style.
font();
379 mFontBoldBtn->setChecked( font.bold() );
380 mFontItalicBtn->setChecked( font.italic() );
381 mFontStrikethroughBtn->setChecked( font.strikeOut() );
382 mFontUnderlineBtn->setChecked( font.underline() );
383 mFontFamilyCmbBx->setCurrentFont( font );
389 mPresetsModel->clear();
390 QStandardItem *item =
new QStandardItem( QString() );
391 mPresetsModel->appendRow( item );
397 QStandardItem *item =
new QStandardItem( QStringLiteral(
"abc - 123" ) );
401 item->setForeground( style.
textColor() );
403 item->setIcon( style.
icon() );
404 item->setFont( style.
font() );
405 item->setData( i, Qt::UserRole + 1 );
406 mPresetsModel->appendRow( item );
407 mPresets.append( style );
411 mPresetsList->setCurrentIndex( 0 );
416 mRuleEdit->setText( rule );
419bool QgsEditConditionalFormatRuleWidget::isCustomSet()
421 return ( btnBackgroundColor->color().isValid() || btnTextColor->color().isValid() || mFontButtons->checkedId() != -1 );
static const double UI_SCALE_FACTOR
UI scaling factor.
QList< QgsConditionalStyle > fieldStyles(const QString &fieldName) const
Returns the conditional styles set for the field with matching fieldName.
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 dataset.
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.