25 , mExistingLabels( existingLabels )
26 , mOriginalLabel(
label )
31 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QgsExpressionStoreDialog::accept );
32 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QgsExpressionStoreDialog::reject );
33 mValidationError->hide();
34 mValidationError->setStyleSheet( QStringLiteral(
"QLabel { color : red; }" ) );
35 QPushButton *saveBtn { buttonBox->button( QDialogButtonBox::StandardButton::Save ) };
36 saveBtn->setEnabled(
false );
37 connect( mLabel, &QLineEdit::textChanged,
this, [
this, saveBtn](
const QString &text ) {
39 if ( mOriginalLabel.simplified() != text.simplified() && mExistingLabels.contains( text.simplified() ) )
41 errorMessage = tr(
"A stored expression with this name already exists" );
43 else if ( text.contains(
'/' ) || text.contains(
'\\' ) )
45 errorMessage = tr(
"Labels cannot contain slashes (/ or \\)" );
47 if ( !errorMessage.isEmpty() )
49 mValidationError->show();
50 mValidationError->setText( errorMessage );
51 saveBtn->setEnabled(
false );
55 mValidationError->hide();
56 saveBtn->setEnabled(
true );
60 QString labelFixed {
label };
61 labelFixed.remove(
'/' ).remove(
'\\' );
62 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.