QGIS API Documentation  2.99.0-Master (e077efd)
Public Slots | Signals | Public Member Functions | Protected Member Functions | List of all members
QgsExpressionBuilderWidget Class Reference

A reusable widget that can be used to build a expression string. More...

#include <qgsexpressionbuilderwidget.h>

Inheritance diagram for QgsExpressionBuilderWidget:
Inheritance graph
[legend]

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 expressionParsed (bool isValid)
 Emitted when the user changes the expression in the widget. More...
 

Public Member Functions

 QgsExpressionBuilderWidget (QWidget *parent=nullptr)
 Create a new expression builder widget with an optional parent. More...
 
 ~QgsExpressionBuilderWidget ()
 
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...
 
void newFunctionFile (const QString &fileName="scratch")
 Create a new file in the function editor. More...
 
void registerItem (const QString &group, const QString &label, const QString &expressionText, const QString &helpText="", QgsExpressionItem::ItemType type=QgsExpressionItem::ExpressionNode, bool highlightedItem=false, int sortOrder=1)
 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 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 updateFunctionFileList (const QString &path)
 Update the list of function files found at the given path. More...
 

Protected Member Functions

void showEvent (QShowEvent *e)
 

Detailed Description

A reusable widget that can be used to build a expression string.

See QgsExpressionBuilderDialog for exmaple of usage.

Definition at line 124 of file qgsexpressionbuilderwidget.h.

Constructor & Destructor Documentation

§ QgsExpressionBuilderWidget()

QgsExpressionBuilderWidget::QgsExpressionBuilderWidget ( QWidget *  parent = nullptr)

Create a new expression builder widget with an optional parent.

Definition at line 39 of file qgsexpressionbuilderwidget.cpp.

§ ~QgsExpressionBuilderWidget()

QgsExpressionBuilderWidget::~QgsExpressionBuilderWidget ( )

Definition at line 110 of file qgsexpressionbuilderwidget.cpp.

Member Function Documentation

§ autosave

void QgsExpressionBuilderWidget::autosave ( )
slot

Auto save the current Python function code.

Definition at line 737 of file qgsexpressionbuilderwidget.cpp.

§ expressionContext()

QgsExpressionContext QgsExpressionBuilderWidget::expressionContext ( ) const
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.

See also
setExpressionContext
Note
added in QGIS 2.12

Definition at line 168 of file qgsexpressionbuilderwidget.h.

§ expressionParsed

void QgsExpressionBuilderWidget::expressionParsed ( bool  isValid)
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.

Parameters
isValidIs true if the expression the user has typed is valid.

§ expressionText()

QString QgsExpressionBuilderWidget::expressionText ( )

Gets the expression string that has been set in the expression area.

Returns
The expression as a string.

Definition at line 505 of file qgsexpressionbuilderwidget.cpp.

§ isExpressionValid()

bool QgsExpressionBuilderWidget::isExpressionValid ( )

Definition at line 399 of file qgsexpressionbuilderwidget.cpp.

§ loadAllValues

void QgsExpressionBuilderWidget::loadAllValues ( )
slot

Load all unique values from the set layer into the sample area.

Definition at line 715 of file qgsexpressionbuilderwidget.cpp.

§ loadCodeFromFile()

void QgsExpressionBuilderWidget::loadCodeFromFile ( QString  path)

Load code from the given file into the function editor.

Definition at line 257 of file qgsexpressionbuilderwidget.cpp.

§ loadFieldNames() [1/2]

void QgsExpressionBuilderWidget::loadFieldNames ( )

Loads all the field names from the layer.

Remarks
Should this really be public couldn't we just do this for the user?

Definition at line 286 of file qgsexpressionbuilderwidget.cpp.

§ loadFieldNames() [2/2]

void QgsExpressionBuilderWidget::loadFieldNames ( const QgsFields fields)

Definition at line 296 of file qgsexpressionbuilderwidget.cpp.

§ loadFieldsAndValues()

void QgsExpressionBuilderWidget::loadFieldsAndValues ( const QMap< QString, QStringList > &  fieldValues)

Loads field names and values from the specified map.

Note
The field values must be quoted appropriately if they are strings.
added in QGIS 2.12

Definition at line 313 of file qgsexpressionbuilderwidget.cpp.

§ loadFunctionCode()

void QgsExpressionBuilderWidget::loadFunctionCode ( const QString &  code)

Load code into the function editor.

Definition at line 265 of file qgsexpressionbuilderwidget.cpp.

§ loadRecent()

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 422 of file qgsexpressionbuilderwidget.cpp.

§ loadSampleValues

void QgsExpressionBuilderWidget::loadSampleValues ( )
slot

Load sample values into the sample value area.

Definition at line 702 of file qgsexpressionbuilderwidget.cpp.

§ newFunctionFile()

void QgsExpressionBuilderWidget::newFunctionFile ( const QString &  fileName = "scratch")

Create a new file in the function editor.

Definition at line 220 of file qgsexpressionbuilderwidget.cpp.

§ registerItem()

void QgsExpressionBuilderWidget::registerItem ( const QString &  group,
const QString &  label,
const QString &  expressionText,
const QString &  helpText = "",
QgsExpressionItem::ItemType  type = QgsExpressionItem::ExpressionNode,
bool  highlightedItem = false,
int  sortOrder = 1 
)

Registers a node item for the expression builder.

Parameters
groupThe group the item will be show in the tree view. If the group doesn't exsit it will be created.
labelThe label that is show to the user for the item in the tree.
expressionTextThe text that is inserted into the expression area when the user double clicks on the item.
helpTextThe help text that the user will see when item is selected.
typeThe type of the expression item.
highlightedItemset to true to make the item highlighted, which inserts a bold copy of the item at the top level
sortOrdersort ranking for item

Definition at line 356 of file qgsexpressionbuilderwidget.cpp.

§ saveFunctionFile()

void QgsExpressionBuilderWidget::saveFunctionFile ( QString  fileName)

Save the current function editor text to the given file.

Definition at line 179 of file qgsexpressionbuilderwidget.cpp.

§ saveToRecent()

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 404 of file qgsexpressionbuilderwidget.cpp.

§ setAutoSave

void QgsExpressionBuilderWidget::setAutoSave ( bool  enabled)
inlineslot

Enabled or disable auto saving.

When enabled Python scripts will be auto saved when text changes.

Parameters
enabledTrue to enable auto saving.

Definition at line 248 of file qgsexpressionbuilderwidget.h.

§ setExpressionContext()

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.

Parameters
contextexpression context
See also
expressionContext
Note
added in QGIS 2.12

Definition at line 515 of file qgsexpressionbuilderwidget.cpp.

§ setExpressionText()

void QgsExpressionBuilderWidget::setExpressionText ( const QString &  expression)

Sets the expression string for the widget.

Definition at line 510 of file qgsexpressionbuilderwidget.cpp.

§ setGeomCalculator()

void QgsExpressionBuilderWidget::setGeomCalculator ( const QgsDistanceArea da)

Sets geometry calculator used in distance/area calculations.

Definition at line 500 of file qgsexpressionbuilderwidget.cpp.

§ setLayer()

void QgsExpressionBuilderWidget::setLayer ( QgsVectorLayer layer)

Sets layer in order to get the fields and values.

Note
this needs to be called before calling loadFieldNames().

Definition at line 123 of file qgsexpressionbuilderwidget.cpp.

§ showEvent()

void QgsExpressionBuilderWidget::showEvent ( QShowEvent *  e)
protected

Definition at line 629 of file qgsexpressionbuilderwidget.cpp.

§ updateFunctionFileList()

void QgsExpressionBuilderWidget::updateFunctionFileList ( const QString &  path)

Update the list of function files found at the given path.

Definition at line 202 of file qgsexpressionbuilderwidget.cpp.


The documentation for this class was generated from the following files: