36 connect( fieldRadio, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::reloadStyles );
37 connect( rowRadio, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::reloadStyles );
38 connect( mNewButton, &QAbstractButton::clicked,
this, &QgsFieldConditionalFormatWidget::addNewRule );
39 connect( listView, &QAbstractItemView::clicked,
this, &QgsFieldConditionalFormatWidget::ruleClicked );
40 mModel =
new QStandardItemModel( listView );
41 listView->setModel( mModel );
43 connect( fieldRadio, &QRadioButton::toggled, mFieldCombo, &QWidget::setEnabled );
51 mFieldCombo->setLayer( layer );
52 mFieldCombo->setCurrentIndex( 0 );
53 fieldChanged( mFieldCombo->currentField() );
56 void QgsFieldConditionalFormatWidget::ruleClicked(
const QModelIndex &index )
58 QList<QgsConditionalStyle> styles = getStyles();
65 mEditIndex = editIndex;
66 mEditing = editIndex >= 0;
67 mPanelHandled =
false;
75 if ( fieldRadio->isChecked() && style.
rule().isEmpty() )
77 ruleWidget->
setRule( QStringLiteral(
"@value " ) );
89 QList<QgsConditionalStyle> styles = getStyles();
92 styles.replace( mEditIndex, ruleWidget->
currentStyle() );
100 if ( fieldRadio->isChecked() )
102 fieldName = mFieldCombo->currentField();
105 if ( rowRadio->isChecked() )
120 mPanelHandled =
true;
127 mPanelHandled =
true;
137 QList<QgsConditionalStyle> QgsFieldConditionalFormatWidget::getStyles()
139 QList<QgsConditionalStyle> styles;
140 if ( fieldRadio->isChecked() )
144 if ( rowRadio->isChecked() )
151 void 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 );
189 void QgsFieldConditionalFormatWidget::reloadStyles()
193 const auto constGetStyles = getStyles();
195 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
201 listView->setIconSize( size );
205 QStandardItem *item =
new QStandardItem( style.
displayText() );
207 mModel->appendRow( item );
211 void QgsFieldConditionalFormatWidget::fieldChanged(
const QString &fieldName )
213 Q_UNUSED( fieldName )
217 void QgsFieldConditionalFormatWidget::deleteCurrentRule()
222 QList<QgsConditionalStyle> styles = getStyles();
223 styles.removeAt( mEditIndex );
225 if ( fieldRadio->isChecked() )
227 fieldName = mFieldCombo->currentField();
230 if ( rowRadio->isChecked() )
255 btnBackgroundColor->setColor( QColor() );
256 btnTextColor->setColor( QColor() );
257 checkIcon->setChecked(
false );
258 btnChangeIcon->setIcon( QIcon() );
259 btnBackgroundColor->setToNoColor();
260 btnTextColor->setToNoColor();
262 mFontBoldBtn->setChecked(
false );
263 mFontItalicBtn->setChecked(
false );
264 mFontStrikethroughBtn->setChecked(
false );
265 mFontUnderlineBtn->setChecked(
false );
268 mFontUnderlineBtn->setMinimumSize( buttonSize, buttonSize );
269 mFontUnderlineBtn->setMaximumSize( buttonSize, buttonSize );
270 mFontStrikethroughBtn->setMinimumSize( buttonSize, buttonSize );
271 mFontStrikethroughBtn->setMaximumSize( buttonSize, buttonSize );
272 mFontBoldBtn->setMinimumSize( buttonSize, buttonSize );
273 mFontBoldBtn->setMaximumSize( buttonSize, buttonSize );
274 mFontItalicBtn->setMinimumSize( buttonSize, buttonSize );
275 mFontItalicBtn->setMaximumSize( buttonSize, buttonSize );
281 connect( btnBuildExpression, &QAbstractButton::clicked,
this, &QgsEditConditionalFormatRuleWidget::setExpression );
282 connect( mPresetsList,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsEditConditionalFormatRuleWidget::presetSet );
284 btnBackgroundColor->setAllowOpacity(
true );
285 btnBackgroundColor->setShowNoColor(
true );
286 btnTextColor->setAllowOpacity(
true );
287 btnTextColor->setShowNoColor(
true );
288 mPresetsModel =
new QStandardItemModel( mPresetsList );
289 mPresetsList->setModel( mPresetsModel );
293 connect( checkIcon, &QCheckBox::toggled, btnChangeIcon, &QWidget::setEnabled );
303 mRuleEdit->setText( style.
rule() );
304 mNameEdit->setText( style.
name() );
305 setFormattingFromStyle( style );
312 style.
setRule( mRuleEdit->text() );
313 style.
setName( mNameEdit->text() );
315 QColor backColor = btnBackgroundColor->color();
316 QColor fontColor = btnTextColor->color();
318 QFont font = mFontFamilyCmbBx->currentFont();
319 font.setBold( mFontBoldBtn->isChecked() );
320 font.setItalic( mFontItalicBtn->isChecked() );
321 font.setStrikeOut( mFontStrikethroughBtn->isChecked() );
322 font.setUnderline( mFontUnderlineBtn->isChecked() );
326 if ( checkIcon->isChecked() )
337 void QgsEditConditionalFormatRuleWidget::setExpression()
341 context.setHighlightedVariables( QStringList() << QStringLiteral(
"value" ) );
344 dlg.setWindowTitle( tr(
"Conditional Style Rule Expression" ) );
348 QString expression = dlg.expressionBuilder()->expressionText();
349 mRuleEdit->setText( expression );
353 void QgsEditConditionalFormatRuleWidget::presetSet(
int index )
355 if ( index == -1 || mPresets.isEmpty() )
358 const int styleIndex = mPresetsList->currentData( Qt::UserRole + 1 ).toInt();
360 setFormattingFromStyle( style );
363 void QgsEditConditionalFormatRuleWidget::setFormattingFromStyle(
const QgsConditionalStyle &style )
366 btnTextColor->setColor( style.
textColor() );
369 btnChangeIcon->setSymbol( style.
symbol()->
clone() );
370 checkIcon->setChecked(
true );
374 checkIcon->setChecked(
false );
376 QFont font = style.
font();
377 mFontBoldBtn->setChecked( font.bold() );
378 mFontItalicBtn->setChecked( font.italic() );
379 mFontStrikethroughBtn->setChecked( font.strikeOut() );
380 mFontUnderlineBtn->setChecked( font.underline() );
381 mFontFamilyCmbBx->setCurrentFont( font );
387 mPresetsModel->clear();
388 QStandardItem *item =
new QStandardItem( QString() );
389 mPresetsModel->appendRow( item );
395 QStandardItem *item =
new QStandardItem( QStringLiteral(
"abc - 123" ) );
399 item->setForeground( style.
textColor() );
401 item->setIcon( style.
icon() );
402 item->setFont( style.
font() );
403 item->setData( i, Qt::UserRole + 1 );
404 mPresetsModel->appendRow( item );
405 mPresets.append( style );
409 mPresetsList->setCurrentIndex( 0 );
414 mRuleEdit->setText( rule );
417 bool QgsEditConditionalFormatRuleWidget::isCustomSet()
419 return ( btnBackgroundColor->color().isValid()
420 || btnTextColor->color().isValid()
421 || mFontButtons->checkedId() != -1 );