28 , mExistingLabels( existingLabels )
29 , mOriginalLabel(
label )
34 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QgsExpressionStoreDialog::accept );
35 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QgsExpressionStoreDialog::reject );
36 mValidationError->hide();
37 mValidationError->setStyleSheet( u
"QLabel { color : red; }"_s );
38 QPushButton *saveBtn { buttonBox->button( QDialogButtonBox::StandardButton::Save ) };
39 saveBtn->setEnabled(
false );
40 connect( mLabel, &QLineEdit::textChanged,
this, [
this, saveBtn](
const QString &text ) {
42 if ( mOriginalLabel.simplified() != text.simplified() && mExistingLabels.contains( text.simplified() ) )
44 errorMessage = tr(
"A stored expression with this name already exists" );
46 else if ( text.contains(
'/' ) || text.contains(
'\\' ) )
48 errorMessage = tr(
"Labels cannot contain slashes (/ or \\)" );
50 if ( !errorMessage.isEmpty() )
52 mValidationError->show();
53 mValidationError->setText( errorMessage );
54 saveBtn->setEnabled(
false );
58 mValidationError->hide();
59 saveBtn->setEnabled(
true );
63 QString labelFixed {
label };
64 labelFixed.remove(
'/' ).remove(
'\\' );
65 mLabel->setText( labelFixed.simplified() );
QgsExpressionStoreDialog(const QString &label, const QString &expression, const QString &helpText, const QStringList &existingLabels=QStringList(), QWidget *parent=nullptr)
Creates a QgsExpressionStoreDialog with given label, expression and helpText.