23 , mExistingLabels( existingLabels )
24 , mOriginalLabel( label )
29 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QgsExpressionStoreDialog::accept );
30 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QgsExpressionStoreDialog::reject );
31 mValidationError->hide();
32 mValidationError->setStyleSheet( QStringLiteral(
"QLabel { color : red; }" ) );
33 QPushButton *saveBtn { buttonBox->button( QDialogButtonBox::StandardButton::Save ) };
34 saveBtn->setEnabled(
false );
35 connect( mLabel, &QLineEdit::textChanged,
this, [ = ](
const QString & text )
38 if ( mOriginalLabel.simplified() != text.simplified() &&
39 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.