QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
|
A reusable widget that can be used to build a expression string. More...
#include <qgsexpressionbuilderwidget.h>
Public Types | |
enum | Flag { LoadNothing = 0 , LoadRecent = 1 << 1 , LoadUserExpressions = 1 << 2 , LoadAll = LoadRecent | LoadUserExpressions } |
Flag to determine what should be loaded. More... | |
Public Slots | |
void | autosave () |
Auto save the current Python function code. | |
void | editSelectedUserExpression () |
Edits the selected expression from the stored user expressions, the selected expression must be a user stored expression. | |
const QList< QgsExpressionItem * > | findExpressions (const QString &label) |
Returns the list of expression items matching a label. | |
void | loadAllUsedValues () |
Load all unique values from the set layer into the sample area. | |
void | loadAllValues () |
Load all unique values from the set layer into the sample area. | |
void | loadSampleUsedValues () |
Load used sample values into the sample value area. | |
void | loadSampleValues () |
Load sample values into the sample value area. | |
void | removeSelectedUserExpression () |
Removes the selected expression from the stored user expressions, the selected expression must be a user stored expression. | |
void | setAutoSave (bool enabled) |
Enabled or disable auto saving. | |
void | storeCurrentUserExpression () |
Adds the current expressions to the stored user expressions. | |
Signals | |
void | evalErrorChanged () |
Will be set to true if the current expression text reported an eval error with the context. | |
void | expressionParsed (bool isValid) |
Emitted when the user changes the expression in the widget. | |
void | parserErrorChanged () |
Will be set to true if the current expression text reported a parser error with the context. | |
Public Member Functions | |
QgsExpressionBuilderWidget (QWidget *parent=nullptr) | |
Create a new expression builder widget with an optional parent. | |
~QgsExpressionBuilderWidget () override | |
bool | evalError () const |
Will be set to true if the current expression text reported an eval error with the context. | |
QString | expectedOutputFormat () |
The set expected format string. | |
QgsExpressionContext | expressionContext () const |
Returns the expression context for the widget. | |
QString | expressionText () |
Gets the expression string that has been set in the expression area. | |
QgsExpressionTreeView * | expressionTree () const |
Returns the expression tree. | |
void | init (const QgsExpressionContext &context=QgsExpressionContext(), const QString &recentCollection=QStringLiteral("generic"), QgsExpressionBuilderWidget::Flags flags=LoadAll) |
Initialize without any layer. | |
void | initWithFields (const QgsFields &fields, const QgsExpressionContext &context=QgsExpressionContext(), const QString &recentCollection=QStringLiteral("generic"), QgsExpressionBuilderWidget::Flags flags=LoadAll) |
Initialize with given fields without any layer. | |
void | initWithLayer (QgsVectorLayer *layer, const QgsExpressionContext &context=QgsExpressionContext(), const QString &recentCollection=QStringLiteral("generic"), QgsExpressionBuilderWidget::Flags flags=LoadAll) |
Initialize with a layer. | |
bool | isExpressionValid () |
Returns if the expression is valid. | |
QgsVectorLayer * | layer () const |
Returns the current layer or a nullptr. | |
void | loadCodeFromFile (QString path) |
Loads code from the given file into the function editor. | |
Q_DECL_DEPRECATED void | loadFieldNames () |
Q_DECL_DEPRECATED void | loadFieldNames (const QgsFields &fields) |
Q_DECL_DEPRECATED void | loadFieldsAndValues (const QMap< QString, QStringList > &fieldValues) |
Loads field names and values from the specified map. | |
void | loadFunctionCode (const QString &code) |
Loads code into the function editor. | |
Q_DECL_DEPRECATED void | loadRecent (const QString &collection=QStringLiteral("generic")) |
Loads the recent expressions from the given collection. | |
Q_DECL_DEPRECATED void | loadUserExpressions () |
Loads the user expressions. | |
Q_DECL_DEPRECATED QStandardItemModel * | model () |
Returns a pointer to the dialog's function item model. | |
void | newFunctionFile (const QString &fileName="scratch") |
Creates a new file in the function editor. | |
bool | parserError () const |
Will be set to true if the current expression text reports a parser error with the context. | |
QgsProject * | project () |
Returns the project currently associated with the widget. | |
Q_DECL_DEPRECATED void | removeFromUserExpressions (const QString &label) |
Removes the expression label from the user stored expressions. | |
void | saveFunctionFile (QString fileName) |
Saves the current function editor text to the given file. | |
Q_DECL_DEPRECATED void | saveToRecent (const QString &collection="generic") |
Adds the current expression to the given collection. | |
Q_DECL_DEPRECATED void | saveToUserExpressions (const QString &label, const QString &expression, const QString &helpText) |
Stores the user expression with given label and helpText. | |
void | setExpectedOutputFormat (const QString &expected) |
The set expected format string. | |
void | setExpressionContext (const QgsExpressionContext &context) |
Sets the expression context for the widget. | |
void | setExpressionPreviewVisible (bool isVisible) |
Sets whether the expression preview is visible. | |
void | setExpressionText (const QString &expression) |
Sets the expression string for the widget. | |
void | setGeomCalculator (const QgsDistanceArea &da) |
Sets geometry calculator used in distance/area calculations. | |
void | setLayer (QgsVectorLayer *layer) |
Sets layer in order to get the fields and values. | |
void | setProject (QgsProject *project) |
Sets the project currently associated with the widget. | |
void | updateFunctionFileList (const QString &path) |
Updates the list of function files found at the given path. | |
Protected Member Functions | |
void | showEvent (QShowEvent *e) override |
A reusable widget that can be used to build a expression string.
See QgsExpressionBuilderDialog for example of usage.
Definition at line 42 of file qgsexpressionbuilderwidget.h.
Flag to determine what should be loaded.
Enumerator | |
---|---|
LoadNothing | Do not load anything. |
LoadRecent | Load recent expressions given the collection key. |
LoadUserExpressions | Load user expressions. |
LoadAll | Load everything. |
Definition at line 51 of file qgsexpressionbuilderwidget.h.
QgsExpressionBuilderWidget::QgsExpressionBuilderWidget | ( | QWidget * | parent = nullptr | ) |
Create a new expression builder widget with an optional parent.
Definition at line 73 of file qgsexpressionbuilderwidget.cpp.
|
override |
Definition at line 241 of file qgsexpressionbuilderwidget.cpp.
|
slot |
Auto save the current Python function code.
Definition at line 971 of file qgsexpressionbuilderwidget.cpp.
|
slot |
Edits the selected expression from the stored user expressions, the selected expression must be a user stored expression.
Definition at line 1004 of file qgsexpressionbuilderwidget.cpp.
bool QgsExpressionBuilderWidget::evalError | ( | ) | const |
Will be set to true
if the current expression text reported an eval error with the context.
Definition at line 704 of file qgsexpressionbuilderwidget.cpp.
|
signal |
Will be set to true
if the current expression text reported an eval error with the context.
QString QgsExpressionBuilderWidget::expectedOutputFormat | ( | ) |
The set expected format string.
This is pure text format and no expression validation is done against it.
Definition at line 667 of file qgsexpressionbuilderwidget.cpp.
|
inline |
Returns the expression context for the widget.
The context is used for the expression preview result and for populating the list of available functions and variables.
Definition at line 143 of file qgsexpressionbuilderwidget.h.
|
signal |
Emitted when the user changes the expression in the widget.
Users of this widget should connect to this signal to decide if to let the user continue.
isValid | Is true if the expression the user has typed is valid. |
QString QgsExpressionBuilderWidget::expressionText | ( | ) |
Gets the expression string that has been set in the expression area.
Definition at line 657 of file qgsexpressionbuilderwidget.cpp.
QgsExpressionTreeView * QgsExpressionBuilderWidget::expressionTree | ( | ) | const |
Returns the expression tree.
Definition at line 630 of file qgsexpressionbuilderwidget.cpp.
|
slot |
Returns the list of expression items matching a label.
Definition at line 1132 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::init | ( | const QgsExpressionContext & | context = QgsExpressionContext() , |
const QString & | recentCollection = QStringLiteral( "generic" ) , |
||
QgsExpressionBuilderWidget::Flags | flags = LoadAll |
||
) |
Initialize without any layer.
Definition at line 250 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::initWithFields | ( | const QgsFields & | fields, |
const QgsExpressionContext & | context = QgsExpressionContext() , |
||
const QString & | recentCollection = QStringLiteral( "generic" ) , |
||
QgsExpressionBuilderWidget::Flags | flags = LoadAll |
||
) |
Initialize with given fields without any layer.
Definition at line 267 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::initWithLayer | ( | QgsVectorLayer * | layer, |
const QgsExpressionContext & | context = QgsExpressionContext() , |
||
const QString & | recentCollection = QStringLiteral( "generic" ) , |
||
QgsExpressionBuilderWidget::Flags | flags = LoadAll |
||
) |
Initialize with a layer.
Definition at line 261 of file qgsexpressionbuilderwidget.cpp.
bool QgsExpressionBuilderWidget::isExpressionValid | ( | ) |
Returns if the expression is valid.
Definition at line 615 of file qgsexpressionbuilderwidget.cpp.
QgsVectorLayer * QgsExpressionBuilderWidget::layer | ( | ) | const |
Returns the current layer or a nullptr.
Definition at line 297 of file qgsexpressionbuilderwidget.cpp.
|
slot |
Load all unique values from the set layer into the sample area.
Only the used ones. Without available values, even if the formatter can provide them (eg. RelationReference).
Definition at line 942 of file qgsexpressionbuilderwidget.cpp.
|
slot |
Load all unique values from the set layer into the sample area.
Including all available values, in case the formatter can provide them (eg. RelationReference).
Definition at line 902 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::loadCodeFromFile | ( | QString | path | ) |
Loads code from the given file into the function editor.
Definition at line 495 of file qgsexpressionbuilderwidget.cpp.
|
inline |
Definition at line 98 of file qgsexpressionbuilderwidget.h.
|
inline |
Definition at line 101 of file qgsexpressionbuilderwidget.h.
void QgsExpressionBuilderWidget::loadFieldsAndValues | ( | const QMap< QString, QStringList > & | fieldValues | ) |
Loads field names and values from the specified map.
Definition at line 515 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::loadFunctionCode | ( | const QString & | code | ) |
Loads code into the function editor.
Definition at line 503 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::loadRecent | ( | const QString & | collection = QStringLiteral( "generic" ) | ) |
Loads the recent expressions from the given collection.
By default it is loaded from the collection "generic".
Definition at line 625 of file qgsexpressionbuilderwidget.cpp.
|
slot |
Load used sample values into the sample value area.
Only the used ones. Without available values, even if the formatter can provide them (eg. RelationReference).
Definition at line 922 of file qgsexpressionbuilderwidget.cpp.
|
slot |
Load sample values into the sample value area.
Including available values, in case the formatter can provide them (eg. RelationReference).
Definition at line 882 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::loadUserExpressions | ( | ) |
Loads the user expressions.
Definition at line 636 of file qgsexpressionbuilderwidget.cpp.
QStandardItemModel * QgsExpressionBuilderWidget::model | ( | ) |
Returns a pointer to the dialog's function item model.
This method is exposed for testing purposes only - it should not be used to modify the model.
Definition at line 709 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::newFunctionFile | ( | const QString & | fileName = "scratch" | ) |
Creates a new file in the function editor.
Definition at line 422 of file qgsexpressionbuilderwidget.cpp.
bool QgsExpressionBuilderWidget::parserError | ( | ) | const |
Will be set to true
if the current expression text reports a parser error with the context.
Definition at line 694 of file qgsexpressionbuilderwidget.cpp.
|
signal |
Will be set to true
if the current expression text reported a parser error with the context.
QgsProject * QgsExpressionBuilderWidget::project | ( | ) |
Returns the project currently associated with the widget.
Definition at line 716 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::removeFromUserExpressions | ( | const QString & | label | ) |
Removes the expression label from the user stored expressions.
Definition at line 646 of file qgsexpressionbuilderwidget.cpp.
|
slot |
Removes the selected expression from the stored user expressions, the selected expression must be a user stored expression.
Definition at line 1033 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::saveFunctionFile | ( | QString | fileName | ) |
Saves the current function editor text to the given file.
Definition at line 366 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::saveToRecent | ( | const QString & | collection = "generic" | ) |
Adds the current expression to the given collection.
By default it is saved to the collection "generic".
Definition at line 620 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::saveToUserExpressions | ( | const QString & | label, |
const QString & | expression, | ||
const QString & | helpText | ||
) |
Stores the user expression with given label and helpText.
Definition at line 641 of file qgsexpressionbuilderwidget.cpp.
|
inlineslot |
Enabled or disable auto saving.
When enabled Python scripts will be auto saved when text changes.
enabled | true to enable auto saving. |
Definition at line 313 of file qgsexpressionbuilderwidget.h.
void QgsExpressionBuilderWidget::setExpectedOutputFormat | ( | const QString & | expected | ) |
The set expected format string.
This is pure text format and no expression validation is done against it.
expected | The expected value format for the expression. |
Definition at line 672 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::setExpressionContext | ( | const QgsExpressionContext & | context | ) |
Sets the expression context for the widget.
The context is used for the expression preview result and to populate the list of available functions and variables.
context | expression context |
Definition at line 678 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::setExpressionPreviewVisible | ( | bool | isVisible | ) |
Sets whether the expression preview is visible.
Definition at line 699 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::setExpressionText | ( | const QString & | expression | ) |
Sets the expression string for the widget.
Definition at line 662 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::setGeomCalculator | ( | const QgsDistanceArea & | da | ) |
Sets geometry calculator used in distance/area calculations.
Definition at line 652 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::setLayer | ( | QgsVectorLayer * | layer | ) |
Sets layer in order to get the fields and values.
Definition at line 274 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::setProject | ( | QgsProject * | project | ) |
Sets the project currently associated with the widget.
This controls which layers and relations and other project-specific items are shown in the widget.
Definition at line 721 of file qgsexpressionbuilderwidget.cpp.
|
overrideprotected |
Definition at line 727 of file qgsexpressionbuilderwidget.cpp.
|
slot |
Adds the current expressions to the stored user expressions.
Definition at line 994 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::updateFunctionFileList | ( | const QString & | path | ) |
Updates the list of function files found at the given path.
Definition at line 392 of file qgsexpressionbuilderwidget.cpp.