37 connect( fieldRadio, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::reloadStyles );
38 connect( rowRadio, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::reloadStyles );
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() );
57 void 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 if ( rowRadio->isChecked() )
121 mPanelHandled =
true;
128 mPanelHandled =
true;
138 QList<QgsConditionalStyle> QgsFieldConditionalFormatWidget::getStyles()
140 QList<QgsConditionalStyle> styles;
141 if ( fieldRadio->isChecked() )
145 if ( rowRadio->isChecked() )
152 void 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 );
190 void QgsFieldConditionalFormatWidget::reloadStyles()
194 const auto constGetStyles = getStyles();
198 listView->setIconSize( size );
202 QStandardItem *item =
new QStandardItem( style.
displayText() );
204 mModel->appendRow( item );
208 void QgsFieldConditionalFormatWidget::fieldChanged(
const QString &fieldName )
210 Q_UNUSED( fieldName )
214 void QgsFieldConditionalFormatWidget::deleteCurrentRule()
219 QList<QgsConditionalStyle> styles = getStyles();
220 styles.removeAt( mEditIndex );
222 if ( fieldRadio->isChecked() )
224 fieldName = mFieldCombo->currentField();
227 if ( rowRadio->isChecked() )
252 btnBackgroundColor->setColor( QColor() );
253 btnTextColor->setColor( QColor() );
254 checkIcon->setChecked(
false );
255 btnChangeIcon->setIcon( QIcon() );
256 btnBackgroundColor->setToNoColor();
257 btnTextColor->setToNoColor();
259 mFontBoldBtn->setChecked(
false );
260 mFontItalicBtn->setChecked(
false );
261 mFontStrikethroughBtn->setChecked(
false );
262 mFontUnderlineBtn->setChecked(
false );
265 mFontUnderlineBtn->setMinimumSize( buttonSize, buttonSize );
266 mFontUnderlineBtn->setMaximumSize( buttonSize, buttonSize );
267 mFontStrikethroughBtn->setMinimumSize( buttonSize, buttonSize );
268 mFontStrikethroughBtn->setMaximumSize( buttonSize, buttonSize );
269 mFontBoldBtn->setMinimumSize( buttonSize, buttonSize );
270 mFontBoldBtn->setMaximumSize( buttonSize, buttonSize );
271 mFontItalicBtn->setMinimumSize( buttonSize, buttonSize );
272 mFontItalicBtn->setMaximumSize( buttonSize, buttonSize );
278 connect( btnBuildExpression, &QAbstractButton::clicked,
this, &QgsEditConditionalFormatRuleWidget::setExpression );
279 connect( mPresetsList,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsEditConditionalFormatRuleWidget::presetSet );
281 btnBackgroundColor->setAllowOpacity(
true );
282 btnBackgroundColor->setShowNoColor(
true );
283 btnTextColor->setAllowOpacity(
true );
284 btnTextColor->setShowNoColor(
true );
285 mPresetsModel =
new QStandardItemModel( mPresetsList );
286 mPresetsList->setModel( mPresetsModel );
290 connect( checkIcon, &QCheckBox::toggled, btnChangeIcon, &QWidget::setEnabled );
300 mRuleEdit->setText( style.
rule() );
301 mNameEdit->setText( style.
name() );
302 setFormattingFromStyle( style );
309 style.
setRule( mRuleEdit->text() );
310 style.
setName( mNameEdit->text() );
312 const QColor backColor = btnBackgroundColor->color();
313 const QColor fontColor = btnTextColor->color();
315 QFont font = mFontFamilyCmbBx->currentFont();
316 font.setBold( mFontBoldBtn->isChecked() );
317 font.setItalic( mFontItalicBtn->isChecked() );
318 font.setStrikeOut( mFontStrikethroughBtn->isChecked() );
319 font.setUnderline( mFontUnderlineBtn->isChecked() );
323 if ( checkIcon->isChecked() )
334 void QgsEditConditionalFormatRuleWidget::setExpression()
338 context.setHighlightedVariables( QStringList() << QStringLiteral(
"value" ) );
341 dlg.setWindowTitle( tr(
"Conditional Style Rule Expression" ) );
345 const QString expression = dlg.expressionBuilder()->expressionText();
346 mRuleEdit->setText( expression );
350 void QgsEditConditionalFormatRuleWidget::presetSet(
int index )
352 if ( index == -1 || mPresets.isEmpty() )
355 const int styleIndex = mPresetsList->currentData( Qt::UserRole + 1 ).toInt();
357 setFormattingFromStyle( style );
360 void QgsEditConditionalFormatRuleWidget::setFormattingFromStyle(
const QgsConditionalStyle &style )
363 btnTextColor->setColor( style.
textColor() );
364 if (
auto *lSymbol = style.
symbol() )
366 btnChangeIcon->setSymbol( lSymbol->clone() );
367 checkIcon->setChecked(
true );
371 checkIcon->setChecked(
false );
373 const QFont font = style.
font();
374 mFontBoldBtn->setChecked( font.bold() );
375 mFontItalicBtn->setChecked( font.italic() );
376 mFontStrikethroughBtn->setChecked( font.strikeOut() );
377 mFontUnderlineBtn->setChecked( font.underline() );
378 mFontFamilyCmbBx->setCurrentFont( font );
384 mPresetsModel->clear();
385 QStandardItem *item =
new QStandardItem( QString() );
386 mPresetsModel->appendRow( item );
392 QStandardItem *item =
new QStandardItem( QStringLiteral(
"abc - 123" ) );
396 item->setForeground( style.
textColor() );
398 item->setIcon( style.
icon() );
399 item->setFont( style.
font() );
400 item->setData( i, Qt::UserRole + 1 );
401 mPresetsModel->appendRow( item );
402 mPresets.append( style );
406 mPresetsList->setCurrentIndex( 0 );
411 mRuleEdit->setText( rule );
414 bool QgsEditConditionalFormatRuleWidget::isCustomSet()
416 return ( btnBackgroundColor->color().isValid()
417 || btnTextColor->color().isValid()
418 || mFontButtons->checkedId() != -1 );