17 #include <QPushButton> 22 , mExistingLabels( existingLabels )
25 mExpression->setText( expression );
26 mHelpText->setText( helpText );
27 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QgsExpressionStoreDialog::accept );
28 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QgsExpressionStoreDialog::reject );
29 mValidationError->hide();
30 mValidationError->setStyleSheet( QStringLiteral(
"QLabel { color : red; }" ) );
31 QPushButton *saveBtn { buttonBox->button( QDialogButtonBox::StandardButton::Save ) };
32 saveBtn->setEnabled(
false );
33 connect( mLabel, &QLineEdit::textChanged,
this, [ = ](
const QString & text )
36 if ( mExistingLabels.contains( text ) )
38 errorMessage = tr(
"A stored expression with this name already exists" );
40 else if ( text.contains(
'/' ) || text.contains(
'\\' ) )
42 errorMessage = tr(
"Labels cannot contain slashes (/ or \\)" );
44 if ( ! errorMessage.isEmpty() )
46 mValidationError->show();
47 mValidationError->setText( errorMessage );
48 saveBtn->setEnabled(
false );
52 mValidationError->hide();
53 saveBtn->setEnabled(
true );
57 QString labelFixed { label };
58 labelFixed.remove(
'/' ).remove(
'\\' );
59 mLabel->setText( labelFixed );
QgsExpressionStoreDialog(const QString &label, const QString &expression, const QString &helpText, const QStringList &existingLabels, QWidget *parent=nullptr)
Creates a QgsExpressionStoreDialog with given label, expression and helpText.