QGIS API Documentation
3.4.15-Madeira (e83d02e274)
|
A reusable widget that can be used to build a expression string. More...
#include <qgsexpressionbuilderwidget.h>
Public Slots | |
void | autosave () |
Auto save the current Python function code. More... | |
void | loadAllValues () |
Load all unique values from the set layer into the sample area. More... | |
void | loadSampleValues () |
Load sample values into the sample value area. More... | |
void | setAutoSave (bool enabled) |
Enabled or disable auto saving. More... | |
Signals | |
void | evalErrorChanged () |
Will be set to true if the current expression text reported an eval error with the context. More... | |
void | expressionParsed (bool isValid) |
Emitted when the user changes the expression in the widget. More... | |
void | parserErrorChanged () |
Will be set to true if the current expression text reported a parser error with the context. More... | |
Public Member Functions | |
QgsExpressionBuilderWidget (QWidget *parent=nullptr) | |
Create a new expression builder widget with an optional parent. More... | |
~QgsExpressionBuilderWidget () override | |
bool | evalError () const |
Will be set to true if the current expression text reported an eval error with the context. More... | |
QString | expectedOutputFormat () |
The set expected format string. More... | |
QgsExpressionContext | expressionContext () const |
Returns the expression context for the widget. More... | |
QString | expressionText () |
Gets the expression string that has been set in the expression area. More... | |
bool | isExpressionValid () |
void | loadCodeFromFile (QString path) |
Load code from the given file into the function editor. More... | |
void | loadFieldNames () |
Loads all the field names from the layer. More... | |
void | loadFieldNames (const QgsFields &fields) |
void | loadFieldsAndValues (const QMap< QString, QStringList > &fieldValues) |
Loads field names and values from the specified map. More... | |
void | loadFunctionCode (const QString &code) |
Load code into the function editor. More... | |
void | loadRecent (const QString &collection="generic") |
Loads the recent expressions from the given collection. More... | |
QStandardItemModel * | model () |
Returns a pointer to the dialog's function item model. More... | |
void | newFunctionFile (const QString &fileName="scratch") |
Create a new file in the function editor. More... | |
bool | parserError () const |
Will be set to true if the current expression text reports a parser error with the context. More... | |
QgsProject * | project () |
Returns the project currently associated with the widget. More... | |
void | registerItem (const QString &group, const QString &label, const QString &expressionText, const QString &helpText=QString(), QgsExpressionItem::ItemType type=QgsExpressionItem::ExpressionNode, bool highlightedItem=false, int sortOrder=1, QIcon icon=QIcon()) |
Registers a node item for the expression builder. More... | |
void | saveFunctionFile (QString fileName) |
Save the current function editor text to the given file. More... | |
void | saveToRecent (const QString &collection="generic") |
Adds the current expression to the given collection. More... | |
void | setExpectedOutputFormat (const QString &expected) |
The set expected format string. More... | |
void | setExpressionContext (const QgsExpressionContext &context) |
Sets the expression context for the widget. More... | |
void | setExpressionText (const QString &expression) |
Sets the expression string for the widget. More... | |
void | setGeomCalculator (const QgsDistanceArea &da) |
Sets geometry calculator used in distance/area calculations. More... | |
void | setLayer (QgsVectorLayer *layer) |
Sets layer in order to get the fields and values. More... | |
void | setProject (QgsProject *project) |
Sets the project currently associated with the widget. More... | |
void | updateFunctionFileList (const QString &path) |
Update the list of function files found at the given path. More... | |
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 132 of file qgsexpressionbuilderwidget.h.
QgsExpressionBuilderWidget::QgsExpressionBuilderWidget | ( | QWidget * | parent = nullptr | ) |
Create a new expression builder widget with an optional parent.
Definition at line 43 of file qgsexpressionbuilderwidget.cpp.
|
override |
Definition at line 207 of file qgsexpressionbuilderwidget.cpp.
|
slot |
Auto save the current Python function code.
Definition at line 1092 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 839 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 682 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 196 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 672 of file qgsexpressionbuilderwidget.cpp.
bool QgsExpressionBuilderWidget::isExpressionValid | ( | ) |
Definition at line 532 of file qgsexpressionbuilderwidget.cpp.
|
slot |
Load all unique values from the set layer into the sample area.
Definition at line 1070 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::loadCodeFromFile | ( | QString | path | ) |
Load code from the given file into the function editor.
Definition at line 374 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::loadFieldNames | ( | ) |
Loads all the field names from the layer.
Definition at line 403 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::loadFieldNames | ( | const QgsFields & | fields | ) |
Definition at line 414 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::loadFieldsAndValues | ( | const QMap< QString, QStringList > & | fieldValues | ) |
Loads field names and values from the specified map.
Definition at line 434 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::loadFunctionCode | ( | const QString & | code | ) |
Load code into the function editor.
Definition at line 382 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::loadRecent | ( | const QString & | collection = "generic" | ) |
Loads the recent expressions from the given collection.
By default it is loaded from the collection "generic".
Definition at line 555 of file qgsexpressionbuilderwidget.cpp.
|
slot |
Load sample values into the sample value area.
Definition at line 1057 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 853 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::newFunctionFile | ( | const QString & | fileName = "scratch" | ) |
Create a new file in the function editor.
Definition at line 335 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 825 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 858 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::registerItem | ( | const QString & | group, |
const QString & | label, | ||
const QString & | expressionText, | ||
const QString & | helpText = QString() , |
||
QgsExpressionItem::ItemType | type = QgsExpressionItem::ExpressionNode , |
||
bool | highlightedItem = false , |
||
int | sortOrder = 1 , |
||
QIcon | icon = QIcon() |
||
) |
Registers a node item for the expression builder.
group | The group the item will be show in the tree view. If the group doesn't exsit it will be created. |
label | The label that is show to the user for the item in the tree. |
expressionText | The text that is inserted into the expression area when the user double clicks on the item. |
helpText | The help text that the user will see when item is selected. |
type | The type of the expression item. |
highlightedItem | set to true to make the item highlighted, which inserts a bold copy of the item at the top level |
sortOrder | sort ranking for item |
icon | custom icon to show for item |
Definition at line 488 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::saveFunctionFile | ( | QString | fileName | ) |
Save the current function editor text to the given file.
Definition at line 283 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 537 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 323 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 687 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 for populating the list of available functions and variables.
context | expression context |
Definition at line 693 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::setExpressionText | ( | const QString & | expression | ) |
Sets the expression string for the widget.
Definition at line 677 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::setGeomCalculator | ( | const QgsDistanceArea & | da | ) |
Sets geometry calculator used in distance/area calculations.
Definition at line 667 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::setLayer | ( | QgsVectorLayer * | layer | ) |
Sets layer in order to get the fields and values.
Definition at line 220 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 863 of file qgsexpressionbuilderwidget.cpp.
|
overrideprotected |
Definition at line 869 of file qgsexpressionbuilderwidget.cpp.
void QgsExpressionBuilderWidget::updateFunctionFileList | ( | const QString & | path | ) |
Update the list of function files found at the given path.
Definition at line 306 of file qgsexpressionbuilderwidget.cpp.