QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgsexpressionstoredialog.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsexpressionstoredialog.cpp
3 ---------------------
4 begin : December 2019
5 copyright : (C) 2019 by Alessandro Pasotti
6 email : elpaso at itopen dot it
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17#include "moc_qgsexpressionstoredialog.cpp"
18#include <QPushButton>
19#include <QStyle>
20
21QgsExpressionStoreDialog::QgsExpressionStoreDialog( const QString &label, const QString &expression, const QString &helpText, const QStringList &existingLabels, QWidget *parent )
22 : QDialog( parent )
23 , mExistingLabels( existingLabels )
24 , mOriginalLabel( label )
25{
26 setupUi( this );
27 mExpression->setText( expression );
28 mHelpText->setText( helpText );
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 )
36 {
37 QString errorMessage;
38 if ( mOriginalLabel.simplified() != text.simplified() &&
39 mExistingLabels.contains( text.simplified() ) )
40 {
41 errorMessage = tr( "A stored expression with this name already exists" );
42 }
43 else if ( text.contains( '/' ) || text.contains( '\\' ) )
44 {
45 errorMessage = tr( "Labels cannot contain slashes (/ or \\)" );
46 }
47 if ( ! errorMessage.isEmpty() )
48 {
49 mValidationError->show();
50 mValidationError->setText( errorMessage );
51 saveBtn->setEnabled( false );
52 }
53 else
54 {
55 mValidationError->hide();
56 saveBtn->setEnabled( true );
57 }
58 } );
59 // No slashes in labels!
60 QString labelFixed { label };
61 labelFixed.remove( '/' ).remove( '\\' );
62 mLabel->setText( labelFixed.simplified() );
63}
64
66{
67 // remove meta qrichtext instruction from html. It fails rendering
68 // when mixing with other html content
69 // see issue https://github.com/qgis/QGIS/issues/36191
70 return mHelpText->toHtml().replace( "<meta name=\"qrichtext\" content=\"1\" />", QString() );
71}
QString label()
Returns the label text.
QString expression()
Returns the expression text.
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.
QString helpText() const
Returns the help text.