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 " ) );
91 QList<QgsConditionalStyle> styles = getStyles();
94 styles.replace( mEditIndex, ruleWidget->
currentStyle() );
102 if ( fieldRadio->isChecked() )
104 fieldName = mFieldCombo->currentField();
107 else if ( rowRadio->isChecked() )
123 mPanelHandled =
true;
130 mPanelHandled =
true;
140QList<QgsConditionalStyle> QgsFieldConditionalFormatWidget::getStyles()
142 QList<QgsConditionalStyle> styles;
143 if ( fieldRadio->isChecked() )
147 else if ( rowRadio->isChecked() )
155void QgsFieldConditionalFormatWidget::addNewRule()
171 QList<QgsConditionalStyle> styles;
174 styles.append( style );
177 styles.append( style );
180 styles.append( style );
183 styles.append( style );
186 styles.append( style );
189 styles.append( style );
193void QgsFieldConditionalFormatWidget::typeChanged()
198void QgsFieldConditionalFormatWidget::reloadStyles()
202 const auto constGetStyles = getStyles();
206 listView->setIconSize( size );
210 QStandardItem *item =
new QStandardItem( style.
displayText() );
212 mModel->appendRow( item );
216void QgsFieldConditionalFormatWidget::fieldChanged(
const QString &fieldName )
218 Q_UNUSED( fieldName )
222void QgsFieldConditionalFormatWidget::deleteCurrentRule()
227 QList<QgsConditionalStyle> styles = getStyles();
228 styles.removeAt( mEditIndex );
230 if ( fieldRadio->isChecked() )
232 fieldName = mFieldCombo->currentField();
235 else if ( rowRadio->isChecked() )
260 btnBackgroundColor->setColor( QColor() );
261 btnTextColor->setColor( QColor() );
262 checkIcon->setChecked(
false );
263 btnChangeIcon->setIcon( QIcon() );
264 btnBackgroundColor->setToNoColor();
265 btnTextColor->setToNoColor();
267 mFontBoldBtn->setChecked(
false );
268 mFontItalicBtn->setChecked(
false );
269 mFontStrikethroughBtn->setChecked(
false );
270 mFontUnderlineBtn->setChecked(
false );
273 mFontUnderlineBtn->setMinimumSize( buttonSize, buttonSize );
274 mFontUnderlineBtn->setMaximumSize( buttonSize, buttonSize );
275 mFontStrikethroughBtn->setMinimumSize( buttonSize, buttonSize );
276 mFontStrikethroughBtn->setMaximumSize( buttonSize, buttonSize );
277 mFontBoldBtn->setMinimumSize( buttonSize, buttonSize );
278 mFontBoldBtn->setMaximumSize( buttonSize, buttonSize );
279 mFontItalicBtn->setMinimumSize( buttonSize, buttonSize );
280 mFontItalicBtn->setMaximumSize( buttonSize, buttonSize );
286 connect( btnBuildExpression, &QAbstractButton::clicked,
this, &QgsEditConditionalFormatRuleWidget::setExpression );
287 connect( mPresetsList,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsEditConditionalFormatRuleWidget::presetSet );
289 btnBackgroundColor->setAllowOpacity(
true );
290 btnBackgroundColor->setShowNoColor(
true );
291 btnTextColor->setAllowOpacity(
true );
292 btnTextColor->setShowNoColor(
true );
293 mPresetsModel =
new QStandardItemModel( mPresetsList );
294 mPresetsList->setModel( mPresetsModel );
298 connect( checkIcon, &QCheckBox::toggled, btnChangeIcon, &QWidget::setEnabled );
308 mRuleEdit->setText( style.
rule() );
309 mNameEdit->setText( style.
name() );
310 setFormattingFromStyle( style );
317 style.
setRule( mRuleEdit->text() );
318 style.
setName( mNameEdit->text() );
320 const QColor backColor = btnBackgroundColor->color();
321 const QColor fontColor = btnTextColor->color();
323 QFont font = mFontFamilyCmbBx->currentFont();
324 font.setBold( mFontBoldBtn->isChecked() );
325 font.setItalic( mFontItalicBtn->isChecked() );
326 font.setStrikeOut( mFontStrikethroughBtn->isChecked() );
327 font.setUnderline( mFontUnderlineBtn->isChecked() );
331 if ( checkIcon->isChecked() )
342void QgsEditConditionalFormatRuleWidget::setExpression()
346 context.setHighlightedVariables( QStringList() << QStringLiteral(
"value" ) );
349 dlg.setWindowTitle( tr(
"Conditional Style Rule Expression" ) );
353 const QString expression = dlg.expressionBuilder()->expressionText();
354 mRuleEdit->setText( expression );
358void QgsEditConditionalFormatRuleWidget::presetSet(
int index )
360 if ( index == -1 || mPresets.isEmpty() )
363 const int styleIndex = mPresetsList->currentData( Qt::UserRole + 1 ).toInt();
365 setFormattingFromStyle( style );
368void QgsEditConditionalFormatRuleWidget::setFormattingFromStyle(
const QgsConditionalStyle &style )
371 btnTextColor->setColor( style.
textColor() );
372 if (
auto *lSymbol = style.
symbol() )
374 btnChangeIcon->setSymbol( lSymbol->clone() );
375 checkIcon->setChecked(
true );
379 checkIcon->setChecked(
false );
381 const QFont font = style.
font();
382 mFontBoldBtn->setChecked( font.bold() );
383 mFontItalicBtn->setChecked( font.italic() );
384 mFontStrikethroughBtn->setChecked( font.strikeOut() );
385 mFontUnderlineBtn->setChecked( font.underline() );
386 mFontFamilyCmbBx->setCurrentFont( font );
392 mPresetsModel->clear();
393 QStandardItem *item =
new QStandardItem( QString() );
394 mPresetsModel->appendRow( item );
400 QStandardItem *item =
new QStandardItem( QStringLiteral(
"abc - 123" ) );
404 item->setForeground( style.
textColor() );
406 item->setIcon( style.
icon() );
407 item->setFont( style.
font() );
408 item->setData( i, Qt::UserRole + 1 );
409 mPresetsModel->appendRow( item );
410 mPresets.append( style );
414 mPresetsList->setCurrentIndex( 0 );
419 mRuleEdit->setText( rule );
422bool QgsEditConditionalFormatRuleWidget::isCustomSet()
424 return ( btnBackgroundColor->color().isValid()
425 || btnTextColor->color().isValid()
426 || 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.