QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
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
16
#include "
qgsexpressionstoredialog.h
"
17
18
#include <QPushButton>
19
#include <QString>
20
#include <QStyle>
21
22
#include "moc_qgsexpressionstoredialog.cpp"
23
24
using namespace
Qt::StringLiterals;
25
26
QgsExpressionStoreDialog::QgsExpressionStoreDialog
(
const
QString &
label
,
const
QString &
expression
,
const
QString &
helpText
,
const
QStringList &existingLabels, QWidget *parent )
27
: QDialog( parent )
28
, mExistingLabels( existingLabels )
29
, mOriginalLabel(
label
)
30
{
31
setupUi(
this
);
32
mExpression->setText(
expression
);
33
mHelpText->setText(
helpText
);
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 ) {
41
QString errorMessage;
42
if
( mOriginalLabel.simplified() != text.simplified() && mExistingLabels.contains( text.simplified() ) )
43
{
44
errorMessage = tr(
"A stored expression with this name already exists"
);
45
}
46
else
if
( text.contains(
'/'
) || text.contains(
'\\'
) )
47
{
48
errorMessage = tr(
"Labels cannot contain slashes (/ or \\)"
);
49
}
50
if
( !errorMessage.isEmpty() )
51
{
52
mValidationError->show();
53
mValidationError->setText( errorMessage );
54
saveBtn->setEnabled(
false
);
55
}
56
else
57
{
58
mValidationError->hide();
59
saveBtn->setEnabled(
true
);
60
}
61
} );
62
// No slashes in labels!
63
QString labelFixed {
label
};
64
labelFixed.remove(
'/'
).remove(
'\\'
);
65
mLabel->setText( labelFixed.simplified() );
66
}
67
68
QString
QgsExpressionStoreDialog::helpText
()
const
69
{
70
// remove meta qrichtext instruction from html. It fails rendering
71
// when mixing with other html content
72
// see issue https://github.com/qgis/QGIS/issues/36191
73
return
mHelpText->toHtml().replace(
"<meta name=\"qrichtext\" content=\"1\" />"
, QString() );
74
}
QgsExpressionStoreDialog::label
QString label()
Returns the label text.
Definition
qgsexpressionstoredialog.h:49
QgsExpressionStoreDialog::expression
QString expression()
Returns the expression text.
Definition
qgsexpressionstoredialog.h:44
QgsExpressionStoreDialog::QgsExpressionStoreDialog
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.
Definition
qgsexpressionstoredialog.cpp:26
QgsExpressionStoreDialog::helpText
QString helpText() const
Returns the help text.
Definition
qgsexpressionstoredialog.cpp:68
qgsexpressionstoredialog.h
Generated on
for QGIS API Documentation by
1.17.0