2014-04-04 10:13:26 +02:00
|
|
|
|
|
|
|
class QgsFieldExpressionWidget : QWidget
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include "qgsfieldexpressionwidget.h"
|
|
|
|
%End
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @brief QgsFieldExpressionWidget creates a widget with a combo box to display the fields and expression and a button to open the expression dialog
|
|
|
|
*/
|
|
|
|
explicit QgsFieldExpressionWidget( QWidget *parent /TransferThis/ = 0 );
|
|
|
|
|
|
|
|
//! define the title used in the expression dialog
|
2015-10-07 11:55:34 +11:00
|
|
|
void setExpressionDialogTitle( const QString& title );
|
2014-05-18 15:22:26 +02:00
|
|
|
|
|
|
|
//! return the title used for the expression dialog
|
|
|
|
const QString expressionDialogTitle();
|
|
|
|
|
2014-05-12 09:04:39 +02:00
|
|
|
//! setFilters allows fitering according to the type of field
|
2015-10-07 11:55:34 +11:00
|
|
|
void setFilters( const QgsFieldProxyModel::Filters& filters );
|
2014-04-04 10:13:26 +02:00
|
|
|
|
2014-06-14 11:47:05 +02:00
|
|
|
void setLeftHandButtonStyle( bool isLeft );
|
|
|
|
|
2014-05-12 09:04:39 +02:00
|
|
|
//! currently used filter on list of fields
|
2014-09-01 16:45:54 +02:00
|
|
|
QgsFieldProxyModel::Filters filters() const;
|
2014-04-04 10:13:26 +02:00
|
|
|
|
2014-05-12 09:04:39 +02:00
|
|
|
//! set the geometry calculator used in the expression dialog
|
|
|
|
void setGeomCalculator( const QgsDistanceArea &da );
|
2014-05-18 15:22:26 +02:00
|
|
|
|
2014-04-04 10:13:26 +02:00
|
|
|
/**
|
|
|
|
* @brief currentField returns the currently selected field or expression if allowed
|
|
|
|
* @param isExpression determines if the string returned is the name of a field or an expression
|
2014-05-05 10:04:34 +02:00
|
|
|
* @param isValid determines if the expression (or field) returned is valid
|
2014-04-04 10:13:26 +02:00
|
|
|
*/
|
2014-09-01 16:45:54 +02:00
|
|
|
QString currentField( bool *isExpression = 0, bool *isValid = 0 ) const;
|
2014-04-04 10:13:26 +02:00
|
|
|
|
2014-06-14 11:47:05 +02:00
|
|
|
/**
|
|
|
|
* Return true if the current expression is valid
|
|
|
|
*/
|
2014-09-01 16:45:54 +02:00
|
|
|
bool isValidExpression( QString *expressionError = 0 ) const;
|
2014-06-14 11:47:05 +02:00
|
|
|
|
2014-09-01 16:45:54 +02:00
|
|
|
bool isExpression() const;
|
2014-06-14 11:47:05 +02:00
|
|
|
/**
|
|
|
|
* Return the current text that is set in the expression area
|
|
|
|
*/
|
2014-09-01 16:45:54 +02:00
|
|
|
QString currentText() const;
|
2014-06-14 11:47:05 +02:00
|
|
|
|
2016-02-24 11:32:54 +11:00
|
|
|
/** 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).
|
|
|
|
* @note added in QGIS 2.14
|
|
|
|
*/
|
|
|
|
QString asExpression() const;
|
|
|
|
|
2016-09-09 09:49:25 +02:00
|
|
|
/**
|
|
|
|
* 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()
|
|
|
|
*
|
|
|
|
* @note added in QGIS 3.0
|
|
|
|
*/
|
|
|
|
QString expression() const;
|
|
|
|
|
2014-04-04 10:13:26 +02:00
|
|
|
//! Returns the currently used layer
|
2014-09-01 16:45:54 +02:00
|
|
|
QgsVectorLayer* layer() const;
|
2014-05-18 15:22:26 +02:00
|
|
|
|
2016-08-10 19:44:30 +02:00
|
|
|
/**
|
|
|
|
* Register an expression context generator class that will be used to retrieve
|
|
|
|
* an expression context for the widget.
|
|
|
|
* @param generator A QgsExpressionContextGenerator class that will be used to
|
|
|
|
* create an expression context when required.
|
|
|
|
* @note added in QGIS 3.0
|
2015-08-20 10:50:38 +10:00
|
|
|
*/
|
2016-08-10 19:44:30 +02:00
|
|
|
void registerExpressionContextGenerator( QgsExpressionContextGenerator* generator );
|
2015-08-20 10:50:38 +10:00
|
|
|
|
2014-04-23 08:58:09 +02:00
|
|
|
signals:
|
2014-05-02 10:32:37 +02:00
|
|
|
//! the signal is emitted when the currently selected field changes
|
2015-10-26 22:46:25 +11:00
|
|
|
void fieldChanged( const QString& fieldName );
|
2014-05-02 10:32:37 +02:00
|
|
|
|
2014-05-02 07:42:00 +02:00
|
|
|
//! fieldChanged signal with indication of the validity of the expression
|
2015-10-26 22:46:25 +11:00
|
|
|
void fieldChanged( const QString& fieldName, bool isValid );
|
2014-04-23 08:58:09 +02:00
|
|
|
|
2014-06-19 21:46:00 +10:00
|
|
|
// void returnPressed();
|
2014-06-14 11:47:05 +02:00
|
|
|
|
2014-04-04 10:13:26 +02:00
|
|
|
public slots:
|
|
|
|
//! set the layer used to display the fields and expression
|
2014-05-02 07:42:00 +02:00
|
|
|
void setLayer( QgsVectorLayer* layer );
|
2014-05-02 10:32:37 +02:00
|
|
|
|
2014-05-02 07:42:00 +02:00
|
|
|
//! convenience slot to connect QgsMapLayerComboBox layer signal
|
2014-04-04 10:13:26 +02:00
|
|
|
void setLayer( QgsMapLayer* layer );
|
|
|
|
|
2016-04-19 09:44:12 +10:00
|
|
|
//! sets the current row in the widget
|
|
|
|
void setRow( int row );
|
|
|
|
|
2014-04-04 10:13:26 +02:00
|
|
|
//! sets the current field or expression in the widget
|
2014-05-18 15:22:26 +02:00
|
|
|
void setField( const QString &fieldName );
|
2014-05-27 23:22:50 +02:00
|
|
|
|
2016-09-09 09:49:25 +02:00
|
|
|
/**
|
|
|
|
* Sets the current expression text and if applicable also the field.
|
|
|
|
* Alias for setField.
|
|
|
|
*
|
|
|
|
* @note Added in QGIS 3.0
|
|
|
|
*/
|
|
|
|
void setExpression( const QString& expression );
|
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
protected slots:
|
|
|
|
//! open the expression dialog to edit the current or add a new expression
|
|
|
|
void editExpression();
|
|
|
|
|
|
|
|
//! when expression is edited by the user in the line edit, it will be checked for validity
|
2015-10-07 11:55:34 +11:00
|
|
|
void expressionEdited( const QString& expression );
|
2014-05-27 23:22:50 +02:00
|
|
|
|
|
|
|
//! when expression has been edited (finished) it will be added to the model
|
|
|
|
void expressionEditingFinished();
|
|
|
|
|
2014-06-06 08:45:03 +02:00
|
|
|
void currentFieldChanged();
|
2014-05-27 23:22:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief updateLineEditStyle will re-style (color/font) the line edit depending on content and status
|
|
|
|
* @param expression if expression is given it will be evaluated for the given string, otherwise it takes
|
|
|
|
* current expression from the model
|
|
|
|
*/
|
2015-10-07 11:55:34 +11:00
|
|
|
void updateLineEditStyle( const QString& expression = QString() );
|
2014-05-27 23:22:50 +02:00
|
|
|
|
2015-10-07 11:55:34 +11:00
|
|
|
bool isExpressionValid( const QString& expressionStr );
|
2014-05-27 23:22:50 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void changeEvent( QEvent* event );
|
2014-04-04 10:13:26 +02:00
|
|
|
};
|