28 mDeleteButton->hide();
30 connect( fieldRadio, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::reloadStyles );
31 connect( rowRadio, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::reloadStyles );
32 connect( mNewButton, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::addNewRule );
33 connect( mSaveRule, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::saveRule );
34 connect( mCancelButton, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::cancelRule );
35 connect( mDeleteButton, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::deleteRule );
36 connect( listView, &QAbstractItemView::clicked,
this, &QgsFieldConditionalFormatWidget::ruleClicked );
37 connect( btnBuildExpression, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::setExpression );
38 connect( mPresetsList,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsFieldConditionalFormatWidget::presetSet );
39 btnBackgroundColor->setAllowOpacity(
true );
40 btnBackgroundColor->setShowNoColor(
true );
41 btnTextColor->setAllowOpacity(
true );
42 btnTextColor->setShowNoColor(
true );
43 mPresetsModel =
new QStandardItemModel( listView );
44 mModel =
new QStandardItemModel( listView );
45 listView->setModel( mModel );
46 mPresetsList->setModel( mPresetsModel );
53 void QgsFieldConditionalFormatWidget::setExpression()
60 dlg.setWindowTitle( tr(
"Conditional Style Rule Expression" ) );
65 mRuleEdit->setText( expression );
69 void QgsFieldConditionalFormatWidget::presetSet(
int index )
71 if ( index == -1 || mPresets.isEmpty() )
75 setFormattingFromStyle( style );
81 mFieldCombo->setLayer( layer );
82 mFieldCombo->setCurrentIndex( 0 );
85 void QgsFieldConditionalFormatWidget::ruleClicked(
const QModelIndex &index )
87 QList<QgsConditionalStyle> styles = getStyles();
94 pages->setCurrentIndex( 1 );
95 mEditIndex = editIndex;
97 mDeleteButton->show();
103 mRuleEdit->setText( style.
rule() );
104 mNameEdit->setText( style.
name() );
105 setFormattingFromStyle( style );
107 void QgsFieldConditionalFormatWidget::setFormattingFromStyle(
const QgsConditionalStyle &style )
110 btnTextColor->setColor( style.
textColor() );
113 btnChangeIcon->setSymbol( style.
symbol()->
clone() );
114 checkIcon->setChecked(
true );
118 checkIcon->setChecked(
false );
120 QFont font = style.
font();
121 mFontBoldBtn->setChecked( font.bold() );
122 mFontItalicBtn->setChecked( font.italic() );
123 mFontStrikethroughBtn->setChecked( font.strikeOut() );
124 mFontUnderlineBtn->setChecked( font.underline() );
125 mFontFamilyCmbBx->setFont( font );
128 QList<QgsConditionalStyle> QgsFieldConditionalFormatWidget::getStyles()
130 QList<QgsConditionalStyle> styles;
131 if ( fieldRadio->isChecked() )
135 if ( rowRadio->isChecked() )
142 void QgsFieldConditionalFormatWidget::deleteRule()
144 QList<QgsConditionalStyle> styles = getStyles();
145 styles.removeAt( mEditIndex );
147 if ( fieldRadio->isChecked() )
149 fieldName = mFieldCombo->currentField();
152 if ( rowRadio->isChecked() )
157 pages->setCurrentIndex( 0 );
162 void QgsFieldConditionalFormatWidget::cancelRule()
164 pages->setCurrentIndex( 0 );
169 void QgsFieldConditionalFormatWidget::addNewRule()
171 pages->setCurrentIndex( 1 );
179 if ( fieldRadio->isChecked() )
181 mRuleEdit->setText( QStringLiteral(
"@value " ) );
183 btnBackgroundColor->setColor( QColor() );
184 btnTextColor->setColor( QColor() );
185 mPresetsList->setCurrentIndex( 0 );
186 mDeleteButton->hide();
188 checkIcon->setChecked(
false );
189 btnChangeIcon->setIcon( QIcon() );
190 btnBackgroundColor->setToNoColor();
191 btnTextColor->setToNoColor();
193 mFontBoldBtn->setChecked(
false );
194 mFontItalicBtn->setChecked(
false );
195 mFontStrikethroughBtn->setChecked(
false );
196 mFontUnderlineBtn->setChecked(
false );
203 mPresetsModel->clear();
208 QStandardItem *item =
new QStandardItem( QStringLiteral(
"abc - 123" ) );
212 item->setForeground( style.
textColor() );
214 item->setIcon( style.
icon() );
215 item->setFont( style.
font() );
216 mPresetsModel->appendRow( item );
217 mPresets.append( style );
220 mPresetsList->setCurrentIndex( 0 );
225 QList<QgsConditionalStyle> styles;
228 styles.append( style );
231 styles.append( style );
234 styles.append( style );
237 styles.append( style );
240 styles.append( style );
243 styles.append( style );
247 void QgsFieldConditionalFormatWidget::saveRule()
249 QList<QgsConditionalStyle> styles = getStyles();
253 style.
setRule( mRuleEdit->text() );
254 style.
setName( mNameEdit->text() );
256 QColor backColor = btnBackgroundColor->color();
257 QColor fontColor = btnTextColor->color();
259 QFont font = mFontFamilyCmbBx->currentFont();
260 font.setBold( mFontBoldBtn->isChecked() );
261 font.setItalic( mFontItalicBtn->isChecked() );
262 font.setStrikeOut( mFontStrikethroughBtn->isChecked() );
263 font.setUnderline( mFontUnderlineBtn->isChecked() );
267 if ( checkIcon->isChecked() )
277 styles.replace( mEditIndex, style );
281 styles.append( style );
285 if ( fieldRadio->isChecked() )
287 fieldName = mFieldCombo->currentField();
290 if ( rowRadio->isChecked() )
294 pages->setCurrentIndex( 0 );
300 void QgsFieldConditionalFormatWidget::reloadStyles()
306 QStandardItem *item =
new QStandardItem( style.
displayText() );
308 mModel->appendRow( item );
312 void QgsFieldConditionalFormatWidget::fieldChanged(
const QString &fieldName )
314 Q_UNUSED( fieldName );
320 pages->setCurrentIndex( 0 );
323 bool QgsFieldConditionalFormatWidget::isCustomSet()
325 return ( btnBackgroundColor->color().isValid()
326 || btnTextColor->color().isValid()
327 || mFontButtons->checkedId() != -1 );
void setName(const QString &value)
Set the name of the style.
Single variable definition for use within a QgsExpressionContextScope.
bool validTextColor() const
Check if the text color is valid for render.
QColor textColor() const
The text color set for style.
bool validBackgroundColor() const
Check if the background color is valid for render.
void setRule(const QString &value)
Set the rule for the style.
QFont font() const
The font for the style.
QList< QgsConditionalStyle > fieldStyles(const QString &fieldName)
Returns the conditional styles set for the field UI properties.
QgsExpressionBuilderWidget * expressionBuilder()
The builder widget that is used by the dialog.
QgsConditionalLayerStyles * conditionalStyles() const
Returns the conditional styles that are set for this layer.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
A marker symbol type, for rendering Point and MultiPoint geometries.
QList< QgsConditionalStyle > rowStyles()
QgsExpressionContextScope * lastScope()
Returns the last scope added to the context.
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
QPixmap icon() const
The icon set for style generated from the set symbol.
Conditional styling for a rule.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void fieldChanged(const QString &fieldName)
the signal is emitted when the currently selected field changes
QColor backgroundColor() const
The background color for style.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
QString name() const
The name of the style.
void setBackgroundColor(const QColor &value)
Set the background color for the style.
QPixmap renderPreview() const
Render a preview icon of the rule.
void setFont(const QFont &value)
Set the font for the style.
void setRowStyles(const QList< QgsConditionalStyle > &styles)
Set the conditional styles that apply to full rows of data in the attribute table.
void setSymbol(QgsSymbol *value)
Set the icon for the style.
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
QString rule() const
The condition rule set for the style.
void setHighlightedVariables(const QStringList &variableNames)
Sets the list of variable names within the context intended to be highlighted to the user...
bool isValid() const
isValid Check if this rule is valid.
QgsSymbol * symbol() const
The symbol used to generate the icon for the style.
void setFieldStyles(const QString &fieldName, const QList< QgsConditionalStyle > &styles)
Set the conditional styles for the field UI properties.
Represents a vector layer which manages a vector based data sets.
QString displayText() const
The name of the style.
A generic dialog for building expression strings.
void setTextColor(const QColor &value)
Set the text color for the style.