QGIS API Documentation 3.41.0-Master (af5edcb665c)
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 QString errorMessage;
37 if ( mOriginalLabel.simplified() != text.simplified() && mExistingLabels.contains( text.simplified() ) )
38 {
39 errorMessage = tr( "A stored expression with this name already exists" );
40 }
41 else if ( text.contains( '/' ) || text.contains( '\\' ) )
42 {
43 errorMessage = tr( "Labels cannot contain slashes (/ or \\)" );
44 }
45 if ( !errorMessage.isEmpty() )
46 {
47 mValidationError->show();
48 mValidationError->setText( errorMessage );
49 saveBtn->setEnabled( false );
50 }
51 else
52 {
53 mValidationError->hide();
54 saveBtn->setEnabled( true );
55 }
56 } );
57 // No slashes in labels!
58 QString labelFixed { label };
59 labelFixed.remove( '/' ).remove( '\\' );
60 mLabel->setText( labelFixed.simplified() );
61}
62
64{
65 // remove meta qrichtext instruction from html. It fails rendering
66 // when mixing with other html content
67 // see issue https://github.com/qgis/QGIS/issues/36191
68 return mHelpText->toHtml().replace( "<meta name=\"qrichtext\" content=\"1\" />", QString() );
69}
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.