QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Public Slots | Signals | Public Member Functions | Protected Slots | Protected Member Functions | Properties | Private Attributes | List of all members
QgsFieldExpressionWidget Class Reference

The QgsFieldExpressionWidget class reates a widget to choose fields and edit expressions It contains a combo boxto display the fields and expression and a button to open the expression dialog. More...

#include <qgsfieldexpressionwidget.h>

Inheritance diagram for QgsFieldExpressionWidget:
Inheritance graph
[legend]
Collaboration diagram for QgsFieldExpressionWidget:
Collaboration graph
[legend]

Public Slots

void setLayer (QgsVectorLayer *layer)
 set the layer used to display the fields and expression More...
 
void setLayer (QgsMapLayer *layer)
 convenience slot to connect QgsMapLayerComboBox layer signal More...
 
void setField (const QString &fieldName)
 sets the current field or expression in the widget More...
 

Signals

void fieldChanged (QString fieldName)
 the signal is emitted when the currently selected field changes More...
 
void fieldChanged (QString fieldName, bool isValid)
 fieldChanged signal with indication of the validity of the expression More...
 

Public Member Functions

 QgsFieldExpressionWidget (QWidget *parent=0)
 QgsFieldExpressionWidget creates a widget with a combo box to display the fields and expression and a button to open the expression dialog. More...
 
void setExpressionDialogTitle (QString title)
 define the title used in the expression dialog More...
 
const QString expressionDialogTitle ()
 return the title used for the expression dialog More...
 
void setFilters (QgsFieldProxyModel::Filters filters)
 setFilters allows fitering according to the type of field More...
 
void setLeftHandButtonStyle (bool isLeft)
 
QgsFieldProxyModel::Filters filters () const
 currently used filter on list of fields More...
 
void setGeomCalculator (const QgsDistanceArea &da)
 set the geometry calculator used in the expression dialog More...
 
QString currentField (bool *isExpression=0, bool *isValid=0) const
 currentField returns the currently selected field or expression if allowed More...
 
bool isValidExpression (QString *expressionError=0) const
 Return true if the current expression is valid. More...
 
bool isExpression () const
 
QString currentText () const
 Return the current text that is set in the expression area. More...
 
QgsVectorLayerlayer () const
 Returns the currently used layer. More...
 

Protected Slots

void editExpression ()
 open the expression dialog to edit the current or add a new expression More...
 
void expressionEdited (const QString expression)
 when expression is edited by the user in the line edit, it will be checked for validity More...
 
void expressionEditingFinished ()
 when expression has been edited (finished) it will be added to the model More...
 
void currentFieldChanged ()
 
void updateLineEditStyle (const QString expression=QString())
 updateLineEditStyle will re-style (color/font) the line edit depending on content and status More...
 
bool isExpressionValid (const QString expressionStr)
 

Protected Member Functions

void changeEvent (QEvent *event)
 

Properties

QString expressionDialogTitle
 
QgsFieldProxyModel::Filters filters
 

Private Attributes

QComboBox * mCombo
 
QToolButton * mButton
 
QgsFieldProxyModelmFieldProxyModel
 
QString mExpressionDialogTitle
 
QSharedPointer< const
QgsDistanceArea
mDa
 

Detailed Description

The QgsFieldExpressionWidget class reates a widget to choose fields and edit expressions It contains a combo boxto 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 40 of file qgsfieldexpressionwidget.h.

Constructor & Destructor Documentation

QgsFieldExpressionWidget::QgsFieldExpressionWidget ( QWidget *  parent = 0)
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 25 of file qgsfieldexpressionwidget.cpp.

References currentFieldChanged(), editExpression(), expressionEdited(), expressionEditingFinished(), QgsApplication::getThemeIcon(), mButton, mCombo, mFieldProxyModel, QgsFieldModel::setAllowExpression(), and QgsFieldProxyModel::sourceFieldModel().

Member Function Documentation

void QgsFieldExpressionWidget::changeEvent ( QEvent *  event)
protected

Definition at line 200 of file qgsfieldexpressionwidget.cpp.

References updateLineEditStyle().

QString QgsFieldExpressionWidget::currentField ( bool *  isExpression = 0,
bool *  isValid = 0 
) const

currentField returns the currently selected field or expression if allowed

Parameters
isExpressiondetermines if the string returned is the name of a field or an expression
isValiddetermines if the expression (or field) returned is valid

Definition at line 103 of file qgsfieldexpressionwidget.cpp.

References currentText(), isExpression(), and isValidExpression().

Referenced by currentFieldChanged(), QgsDataDefinedSymbolDialog::dataDefinedProperties(), and updateLineEditStyle().

void QgsFieldExpressionWidget::currentFieldChanged ( )
protectedslot
QString QgsFieldExpressionWidget::currentText ( ) const

Return the current text that is set in the expression area.

Definition at line 86 of file qgsfieldexpressionwidget.cpp.

References mCombo.

Referenced by currentField(), editExpression(), isExpression(), and isValidExpression().

void QgsFieldExpressionWidget::editExpression ( )
protectedslot

open the expression dialog to edit the current or add a new expression

Definition at line 164 of file qgsfieldexpressionwidget.cpp.

References currentText(), QgsExpressionBuilderDialog::expressionText(), layer(), mDa, mExpressionDialogTitle, setField(), and QgsExpressionBuilderDialog::setGeomCalculator().

Referenced by QgsFieldExpressionWidget().

const QString QgsFieldExpressionWidget::expressionDialogTitle ( )
inline

return the title used for the expression dialog

Definition at line 57 of file qgsfieldexpressionwidget.h.

void QgsFieldExpressionWidget::expressionEdited ( const QString  expression)
protectedslot

when expression is edited by the user in the line edit, it will be checked for validity

Definition at line 183 of file qgsfieldexpressionwidget.cpp.

References fieldChanged(), isValidExpression(), and updateLineEditStyle().

Referenced by QgsFieldExpressionWidget().

void QgsFieldExpressionWidget::expressionEditingFinished ( )
protectedslot

when expression has been edited (finished) it will be added to the model

Definition at line 189 of file qgsfieldexpressionwidget.cpp.

References currentFieldChanged(), QgsFieldModel::indexFromName(), mCombo, mFieldProxyModel, QgsDebugMsg, QgsFieldModel::setExpression(), and QgsFieldProxyModel::sourceFieldModel().

Referenced by QgsFieldExpressionWidget().

void QgsFieldExpressionWidget::fieldChanged ( QString  fieldName)
signal

the signal is emitted when the currently selected field changes

Referenced by currentFieldChanged(), and expressionEdited().

void QgsFieldExpressionWidget::fieldChanged ( QString  fieldName,
bool  isValid 
)
signal

fieldChanged signal with indication of the validity of the expression

QgsFieldProxyModel::Filters QgsFieldExpressionWidget::filters ( ) const
inline

currently used filter on list of fields

Definition at line 65 of file qgsfieldexpressionwidget.h.

bool QgsFieldExpressionWidget::isExpression ( ) const
bool QgsFieldExpressionWidget::isExpressionValid ( const QString  expressionStr)
protectedslot
bool QgsFieldExpressionWidget::isValidExpression ( QString *  expressionError = 0) const

Return true if the current expression is valid.

Definition at line 91 of file qgsfieldexpressionwidget.cpp.

References currentText(), QgsExpression::isValid(), layer(), and QgsVectorLayer::pendingFields().

Referenced by currentField(), and expressionEdited().

QgsVectorLayer * QgsFieldExpressionWidget::layer ( ) const
void QgsFieldExpressionWidget::setExpressionDialogTitle ( QString  title)

define the title used in the expression dialog

Definition at line 59 of file qgsfieldexpressionwidget.cpp.

References mExpressionDialogTitle.

void QgsFieldExpressionWidget::setField ( const QString &  fieldName)
slot
void QgsFieldExpressionWidget::setFilters ( QgsFieldProxyModel::Filters  filters)

setFilters allows fitering according to the type of field

Definition at line 64 of file qgsfieldexpressionwidget.cpp.

References mFieldProxyModel, and QgsFieldProxyModel::setFilters().

void QgsFieldExpressionWidget::setGeomCalculator ( const QgsDistanceArea da)

set the geometry calculator used in the expression dialog

Definition at line 81 of file qgsfieldexpressionwidget.cpp.

References mDa.

void QgsFieldExpressionWidget::setLayer ( QgsVectorLayer layer)
slot

set the layer used to display the fields and expression

Definition at line 131 of file qgsfieldexpressionwidget.cpp.

References mFieldProxyModel, QgsFieldModel::setLayer(), and QgsFieldProxyModel::sourceFieldModel().

Referenced by QgsDataDefinedSymbolDialog::QgsDataDefinedSymbolDialog(), and setLayer().

void QgsFieldExpressionWidget::setLayer ( QgsMapLayer layer)
slot

convenience slot to connect QgsMapLayerComboBox layer signal

Definition at line 122 of file qgsfieldexpressionwidget.cpp.

References layer(), and setLayer().

void QgsFieldExpressionWidget::setLeftHandButtonStyle ( bool  isLeft)

Definition at line 69 of file qgsfieldexpressionwidget.cpp.

References mCombo.

void QgsFieldExpressionWidget::updateLineEditStyle ( const QString  expression = QString())
protectedslot

updateLineEditStyle will re-style (color/font) the line edit depending on content and status

Parameters
expressionif expression is given it will be evaluated for the given string, otherwise it takes current expression from the model

Definition at line 230 of file qgsfieldexpressionwidget.cpp.

References currentField(), isExpression(), isExpressionValid(), and mCombo.

Referenced by changeEvent(), currentFieldChanged(), and expressionEdited().

Member Data Documentation

QToolButton* QgsFieldExpressionWidget::mButton
private

Definition at line 136 of file qgsfieldexpressionwidget.h.

Referenced by QgsFieldExpressionWidget().

QComboBox* QgsFieldExpressionWidget::mCombo
private
QSharedPointer<const QgsDistanceArea> QgsFieldExpressionWidget::mDa
private

Definition at line 139 of file qgsfieldexpressionwidget.h.

Referenced by editExpression(), and setGeomCalculator().

QString QgsFieldExpressionWidget::mExpressionDialogTitle
private

Definition at line 138 of file qgsfieldexpressionwidget.h.

Referenced by editExpression(), and setExpressionDialogTitle().

QgsFieldProxyModel* QgsFieldExpressionWidget::mFieldProxyModel
private

Property Documentation

QString QgsFieldExpressionWidget::expressionDialogTitle
readwriteprivate

Definition at line 43 of file qgsfieldexpressionwidget.h.

QgsFieldProxyModel::Filters QgsFieldExpressionWidget::filters
readwriteprivate

Definition at line 45 of file qgsfieldexpressionwidget.h.


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