22 #include <QHBoxLayout> 23 #include <QVBoxLayout> 24 #include <QToolButton> 29 , mLineEdit( nullptr )
30 , mCodeEditor( nullptr )
31 , mExpressionDialogTitle( tr(
"Expression dialog" ) )
36 mButton->
setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
38 connect( mButton, SIGNAL( clicked() ),
this, SLOT( editExpression() ) );
50 mExpressionDialogTitle = title;
57 if ( multiLine && !mCodeEditor )
60 mCodeEditor->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
76 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
79 connect( mCodeEditor, SIGNAL( textChanged() ),
this, SLOT( expressionEdited() ) );
83 else if ( !multiLine && !mLineEdit )
86 mCodeEditor =
nullptr;
88 mLineEdit->
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
98 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
120 return mLineEdit->
text();
121 else if ( mCodeEditor )
122 return mCodeEditor->text();
136 mLineEdit->
setText( newExpression );
137 else if ( mCodeEditor )
138 mCodeEditor->setText( newExpression );
141 void QgsExpressionLineEdit::editExpression()
161 void QgsExpressionLineEdit::expressionEdited()
168 updateLineEditStyle( expression );
174 if ( event->
type() == QEvent::EnabledChange )
180 void QgsExpressionLineEdit::updateLineEditStyle(
const QString& expression )
188 palette.
setColor( QPalette::Text, Qt::gray );
195 isValid = isExpressionValid( expression );
199 palette.
setColor( QPalette::Text, Qt::red );
203 palette.
setColor( QPalette::Text, Qt::black );
209 bool QgsExpressionLineEdit::isExpressionValid(
const QString& expressionStr )
212 expression.
prepare( &mExpressionContext );
Class for parsing and evaluation of expressions (formerly called "search strings").
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
void setContentsMargins(int left, int top, int right, int bottom)
void setColor(ColorGroup group, ColorRole role, const QColor &color)
Q_DECL_DEPRECATED bool prepare(const QgsFields &fields)
Get the expression ready for evaluation - find out column indexes.
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
void setMultiLine(bool multiLine)
Sets whether the widget should show a multiline text editor.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
void setExpression(const QString &expression)
Sets the current expression to show in the widget.
bool isValid() const
Checks if this expression is valid.
QString expression() const
Returns the current expression shown in the widget.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setGeomCalculator(const QgsDistanceArea &da)
Sets geometry calculator used in distance/area calculations.
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
void setGeomCalculator(const QgsDistanceArea &distanceArea)
Set the geometry calculator used in the expression dialog.
void expressionChanged(const QString &expression)
Emitted when the expression is changed.
void changeEvent(QEvent *event) override
General purpose distance and area calculator.
void setExpressionDialogTitle(const QString &title)
Sets the title used in the expression builder dialog.
void setLayer(QgsVectorLayer *layer)
Sets a layer associated with the widget.
A SQL editor based on QScintilla2.
void addStretch(int stretch)
bool isValidExpression(QString *expressionError=nullptr) const
Returns true if the current expression is valid.
static QgsExpressionContextScope * projectScope()
Creates a new scope which contains variables and functions relating to the current QGIS project...
QgsExpressionLineEdit(QWidget *parent=nullptr)
Constructor for QgsExpressionLineEdit.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Represents a vector layer which manages a vector based data sets.
A generic dialog for building expression strings.
void addLayout(QLayout *layout, int stretch)