QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
|
The QgsFieldExpressionWidget class reates a widget to choose fields and edit expressions It contains a combo box to display the fields and expression and a button to open the expression dialog. More...
#include <qgsfieldexpressionwidget.h>
Public Slots | |
void | setExpression (const QString &expression) |
Sets the current expression text and if applicable also the field. | |
void | setField (const QString &fieldName) |
sets the current field or expression in the widget | |
void | setFields (const QgsFields &fields) |
Sets the fields used in the widget to fields, this allows the widget to work without a layer. | |
void | setLayer (QgsMapLayer *layer) |
Sets the layer used to display the fields and expression. | |
void | setRow (int row) |
sets the current row in the widget | |
Signals | |
void | allowEvalErrorsChanged () |
Allow accepting expressions with evaluation errors. | |
void | fieldChanged (const QString &fieldName) |
Emitted when the currently selected field changes. | |
void | fieldChanged (const QString &fieldName, bool isValid) |
fieldChanged signal with indication of the validity of the expression | |
Public Member Functions | |
QgsFieldExpressionWidget (QWidget *parent=nullptr) | |
QgsFieldExpressionWidget creates a widget with a combo box to display the fields and expression and a button to open the expression dialog. | |
bool | allowEmptyFieldName () const |
Returns true if the combo box allows the empty field ("not set") choice. | |
bool | allowEvalErrors () const |
Allow accepting expressions with evaluation errors. | |
void | appendScope (QgsExpressionContextScope *scope) |
Appends a scope to the current expression context. | |
QString | asExpression () const |
Returns the currently selected field or expression. | |
QString | currentField (bool *isExpression=nullptr, bool *isValid=nullptr) const |
currentField returns the currently selected field or expression if allowed | |
QString | currentText () const |
Returns the current text that is set in the expression area. | |
QString | expression () const |
Returns the currently selected field or expression. | |
const QString | expressionDialogTitle () |
Returns the title used for the expression dialog. | |
QgsFieldProxyModel::Filters | filters () const |
currently used filter on list of fields | |
bool | isExpression () const |
If the content is not just a simple field this method will return true . | |
bool | isValidExpression (QString *expressionError=nullptr) const |
Returns true if the current expression is valid. | |
QgsVectorLayer * | layer () const |
Returns the layer currently associated with the widget. | |
void | registerExpressionContextGenerator (const QgsExpressionContextGenerator *generator) |
Register an expression context generator class that will be used to retrieve an expression context for the widget. | |
void | setAllowEmptyFieldName (bool allowEmpty) |
Sets whether an optional empty field ("not set") option is shown in the combo box. | |
void | setAllowEvalErrors (bool allowEvalErrors) |
Allow accepting expressions with evaluation errors. | |
void | setExpressionDialogTitle (const QString &title) |
define the title used in the expression dialog | |
void | setFilters (QgsFieldProxyModel::Filters filters) |
setFilters allows filtering according to the type of field | |
void | setGeomCalculator (const QgsDistanceArea &da) |
Sets the geometry calculator used in the expression dialog. | |
void | setLeftHandButtonStyle (bool isLeft) |
Protected Slots | |
void | currentFieldChanged () |
void | editExpression () |
open the expression dialog to edit the current or add a new expression | |
void | expressionEdited (const QString &expression) |
when expression is edited by the user in the line edit, it will be checked for validity | |
void | expressionEditingFinished () |
when expression has been edited (finished) it will be added to the model | |
bool | isExpressionValid (const QString &expressionStr) |
void | updateLineEditStyle (const QString &expression=QString()) |
updateLineEditStyle will re-style (color/font) the line edit depending on content and status | |
Protected Member Functions | |
void | changeEvent (QEvent *event) override |
bool | eventFilter (QObject *watched, QEvent *event) override |
Properties | |
bool | allowEmptyFieldName |
bool | allowEvalErrors |
QString | expressionDialogTitle |
QgsFieldProxyModel::Filters | filters |
Friends | |
class | TestQgsFieldExpressionWidget |
The QgsFieldExpressionWidget class reates a widget to choose fields and edit expressions It contains a combo box to display the fields and expression and a button to open the expression dialog.
The combo box is editable, allowing expressions to be edited inline. The validity of the expression is checked live on key press, invalid expressions are displayed in red. The expression will be added to the model (and the fieldChanged signals emitted) only when editing in the line edit is finished (focus lost, enter key pressed).
Definition at line 46 of file qgsfieldexpressionwidget.h.
|
explicit |
QgsFieldExpressionWidget creates a widget with a combo box to display the fields and expression and a button to open the expression dialog.
Definition at line 32 of file qgsfieldexpressionwidget.cpp.
bool QgsFieldExpressionWidget::allowEmptyFieldName | ( | ) | const |
Returns true
if the combo box allows the empty field ("not set") choice.
Definition at line 88 of file qgsfieldexpressionwidget.cpp.
bool QgsFieldExpressionWidget::allowEvalErrors | ( | ) | const |
Allow accepting expressions with evaluation errors.
This can be useful when we are not able to provide an expression context of which we are sure it's completely populated.
Definition at line 311 of file qgsfieldexpressionwidget.cpp.
|
signal |
Allow accepting expressions with evaluation errors.
This can be useful when we are not able to provide an expression context of which we are sure it's completely populated.
void QgsFieldExpressionWidget::appendScope | ( | QgsExpressionContextScope * | scope | ) |
Appends a scope to the current expression context.
scope | The scope to add. |
Definition at line 385 of file qgsfieldexpressionwidget.cpp.
QString QgsFieldExpressionWidget::asExpression | ( | ) | const |
Returns the currently selected field or expression.
If a field is currently selected, the returned value will be converted to a valid expression referencing this field (ie enclosing the field name with appropriate quotations).
Definition at line 118 of file qgsfieldexpressionwidget.cpp.
|
overrideprotected |
Definition at line 272 of file qgsfieldexpressionwidget.cpp.
QString QgsFieldExpressionWidget::currentField | ( | bool * | isExpression = nullptr , |
bool * | isValid = nullptr |
||
) | const |
currentField returns the currently selected field or expression if allowed
isExpression | determines if the string returned is the name of a field or an expression |
isValid | determines if the expression (or field) returned is valid |
Definition at line 139 of file qgsfieldexpressionwidget.cpp.
|
protectedslot |
Definition at line 325 of file qgsfieldexpressionwidget.cpp.
QString QgsFieldExpressionWidget::currentText | ( | ) | const |
Returns the current text that is set in the expression area.
Definition at line 113 of file qgsfieldexpressionwidget.cpp.
|
protectedslot |
open the expression dialog to edit the current or add a new expression
Definition at line 231 of file qgsfieldexpressionwidget.cpp.
|
overrideprotected |
Definition at line 297 of file qgsfieldexpressionwidget.cpp.
QString QgsFieldExpressionWidget::expression | ( | ) | const |
Returns the currently selected field or expression.
If a field is currently selected, the returned value will be converted to a valid expression referencing this field (ie enclosing the field name with appropriate quotations).
Alias for asExpression()
Definition at line 123 of file qgsfieldexpressionwidget.cpp.
|
inline |
Returns the title used for the expression dialog.
Definition at line 74 of file qgsfieldexpressionwidget.h.
|
protectedslot |
when expression is edited by the user in the line edit, it will be checked for validity
Definition at line 256 of file qgsfieldexpressionwidget.cpp.
|
protectedslot |
when expression has been edited (finished) it will be added to the model
Definition at line 262 of file qgsfieldexpressionwidget.cpp.
|
signal |
Emitted when the currently selected field changes.
|
signal |
fieldChanged signal with indication of the validity of the expression
|
inline |
currently used filter on list of fields
Definition at line 96 of file qgsfieldexpressionwidget.h.
bool QgsFieldExpressionWidget::isExpression | ( | ) | const |
If the content is not just a simple field this method will return true
.
Definition at line 134 of file qgsfieldexpressionwidget.cpp.
|
protectedslot |
Definition at line 378 of file qgsfieldexpressionwidget.cpp.
bool QgsFieldExpressionWidget::isValidExpression | ( | QString * | expressionError = nullptr | ) | const |
Returns true
if the current expression is valid.
Definition at line 128 of file qgsfieldexpressionwidget.cpp.
QgsVectorLayer * QgsFieldExpressionWidget::layer | ( | ) | const |
Returns the layer currently associated with the widget.
Definition at line 155 of file qgsfieldexpressionwidget.cpp.
void QgsFieldExpressionWidget::registerExpressionContextGenerator | ( | const QgsExpressionContextGenerator * | generator | ) |
Register an expression context generator class that will be used to retrieve an expression context for the widget.
generator | A QgsExpressionContextGenerator class that will be used to create an expression context when required. |
Definition at line 160 of file qgsfieldexpressionwidget.cpp.
void QgsFieldExpressionWidget::setAllowEmptyFieldName | ( | bool | allowEmpty | ) |
Sets whether an optional empty field ("not set") option is shown in the combo box.
Definition at line 82 of file qgsfieldexpressionwidget.cpp.
void QgsFieldExpressionWidget::setAllowEvalErrors | ( | bool | allowEvalErrors | ) |
Allow accepting expressions with evaluation errors.
This can be useful when we are not able to provide an expression context of which we are sure it's completely populated.
Definition at line 316 of file qgsfieldexpressionwidget.cpp.
|
slot |
Sets the current expression text and if applicable also the field.
Alias for setField.
Definition at line 226 of file qgsfieldexpressionwidget.cpp.
void QgsFieldExpressionWidget::setExpressionDialogTitle | ( | const QString & | title | ) |
define the title used in the expression dialog
Definition at line 72 of file qgsfieldexpressionwidget.cpp.
|
slot |
sets the current field or expression in the widget
Definition at line 183 of file qgsfieldexpressionwidget.cpp.
|
slot |
Sets the fields used in the widget to fields, this allows the widget to work without a layer.
Definition at line 221 of file qgsfieldexpressionwidget.cpp.
void QgsFieldExpressionWidget::setFilters | ( | QgsFieldProxyModel::Filters | filters | ) |
setFilters allows filtering according to the type of field
Definition at line 77 of file qgsfieldexpressionwidget.cpp.
void QgsFieldExpressionWidget::setGeomCalculator | ( | const QgsDistanceArea & | da | ) |
Sets the geometry calculator used in the expression dialog.
Definition at line 108 of file qgsfieldexpressionwidget.cpp.
|
slot |
Sets the layer used to display the fields and expression.
Definition at line 165 of file qgsfieldexpressionwidget.cpp.
void QgsFieldExpressionWidget::setLeftHandButtonStyle | ( | bool | isLeft | ) |
Definition at line 93 of file qgsfieldexpressionwidget.cpp.
|
inlineslot |
sets the current row in the widget
Definition at line 197 of file qgsfieldexpressionwidget.h.
|
protectedslot |
updateLineEditStyle will re-style (color/font) the line edit depending on content and status
expression | if expression is given it will be evaluated for the given string, otherwise it takes current expression from the model |
Definition at line 347 of file qgsfieldexpressionwidget.cpp.
|
friend |
Definition at line 259 of file qgsfieldexpressionwidget.h.
|
readwrite |
Definition at line 51 of file qgsfieldexpressionwidget.h.
|
readwrite |
Definition at line 52 of file qgsfieldexpressionwidget.h.
|
readwrite |
Definition at line 49 of file qgsfieldexpressionwidget.h.
|
readwrite |
Definition at line 50 of file qgsfieldexpressionwidget.h.