QgsExpressionLineEdit class
The QgsExpressionLineEdit widget includes a line edit for entering expressions together with a button to open the expression creation dialog.
Contents
This widget is designed for use in contexts where no layer fields are available for use in an expression. In contexts where the expression is directly associated with a layer and fields can be used, then QgsFieldExpressionWidget is a more appropriate choice as it gives users direct access to select fields from a drop-down list.
QgsExpressionLineEdit also supports a multiline editor mode which is useful where more space is available for the widget, but where QgsExpressionBuilderWidget is too complex or large for use.
Constructors, destructors, conversion operators
- QgsExpressionLineEdit(QWidget* parent = nullptr) explicit
- Constructor for QgsExpressionLineEdit.
Public functions
- auto expectedOutputFormat() const -> QString
- Returns the expected format string, which is shown in the expression builder dialog for the widget.
- auto expression() const -> QString
- Returns the current expression shown in the widget.
- auto expressionDialogTitle() const -> QString
- Returns the title used for the expression dialog.
- auto isValidExpression(QString* expressionError = nullptr) const -> bool
- Determines if the current expression is valid.
- void registerExpressionContextGenerator(const QgsExpressionContextGenerator* generator)
- Register an expression context generator class that will be used to retrieve an expression context for the widget.
- void setExpectedOutputFormat(const QString& expected)
- Set the expected format string, which is shown in the expression builder dialog for the widget.
- void setExpressionDialogTitle(const QString& title)
- Sets the title used in the expression builder dialog.
- void setGeomCalculator(const QgsDistanceArea& distanceArea)
- Set the geometry calculator used in the expression dialog.
- void setLayer(QgsVectorLayer* layer)
- Sets a layer associated with the widget.
- void setMultiLine(bool multiLine)
- Sets whether the widget should show a multiline text editor.
Signals
- void expressionChanged(const QString& expression)
- Emitted when the expression is changed.
Public slots
- void setExpression(const QString& expression)
- Sets the current expression to show in the widget.
Function documentation
QgsExpressionLineEdit:: QgsExpressionLineEdit(QWidget* parent = nullptr) explicit
Constructor for QgsExpressionLineEdit.
| Parameters | |
|---|---|
| parent | parent widget |
QString QgsExpressionLineEdit:: expectedOutputFormat() const
Returns the expected format string, which is shown in the expression builder dialog for the widget.
This is purely a text format and no expression validation is done against it.
QString QgsExpressionLineEdit:: expression() const
Returns the current expression shown in the widget.
QString QgsExpressionLineEdit:: expressionDialogTitle() const
Returns the title used for the expression dialog.
bool QgsExpressionLineEdit:: isValidExpression(QString* expressionError = nullptr) const
Determines if the current expression is valid.
| Parameters | |
|---|---|
| expressionError | will be set to any generated error message if specified |
| Returns | true if the current expression is valid. |
void QgsExpressionLineEdit:: registerExpressionContextGenerator(const QgsExpressionContextGenerator* generator)
Register an expression context generator class that will be used to retrieve an expression context for the widget.
| Parameters | |
|---|---|
| generator | A QgsExpressionContextGenerator class that will be used to create an expression context when required. |
void QgsExpressionLineEdit:: setExpectedOutputFormat(const QString& expected)
Set the expected format string, which is shown in the expression builder dialog for the widget.
This is purely a text format and no expression validation is done against it.
void QgsExpressionLineEdit:: setExpressionDialogTitle(const QString& title)
Sets the title used in the expression builder dialog.
| Parameters | |
|---|---|
| title | dialog title |
void QgsExpressionLineEdit:: setGeomCalculator(const QgsDistanceArea& distanceArea)
Set the geometry calculator used in the expression dialog.
| Parameters | |
|---|---|
| distanceArea | calculator |
void QgsExpressionLineEdit:: setLayer(QgsVectorLayer* layer)
Sets a layer associated with the widget.
Required in order to get the fields and values from the layer. This will also automatically register the layer as expression context generator if no generator has been set before or the previous layer has been used as generator.
void QgsExpressionLineEdit:: setMultiLine(bool multiLine)
Sets whether the widget should show a multiline text editor.
| Parameters | |
|---|---|
| multiLine | set to true to show multiline editor, or false to show single line editor (the default). |
void QgsExpressionLineEdit:: expressionChanged(const QString& expression) signal
Emitted when the expression is changed.
| Parameters | |
|---|---|
| expression | new expression |
void QgsExpressionLineEdit:: setExpression(const QString& expression) public slot
Sets the current expression to show in the widget.
| Parameters | |
|---|---|
| expression | expression string |