mirror of
				https://github.com/qgis/QGIS.git
				synced 2025-11-04 00:04:25 -05:00 
			
		
		
		
	
		
			
				
	
	
		
			136 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			136 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
 | 
						|
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
 | 
						|
    void setExpressionDialogTitle( const QString& title );
 | 
						|
 | 
						|
    //! return the title used for the expression dialog
 | 
						|
    const QString expressionDialogTitle();
 | 
						|
 | 
						|
    //! setFilters allows fitering according to the type of field
 | 
						|
    void setFilters( QgsFieldProxyModel::Filters filters );
 | 
						|
 | 
						|
    void setLeftHandButtonStyle( bool isLeft );
 | 
						|
 | 
						|
    //! currently used filter on list of fields
 | 
						|
    QgsFieldProxyModel::Filters filters() const;
 | 
						|
 | 
						|
    //! set the geometry calculator used in the expression dialog
 | 
						|
    void setGeomCalculator( const QgsDistanceArea &da );
 | 
						|
 | 
						|
    /**
 | 
						|
     * @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
 | 
						|
     * @param isValid determines if the expression (or field) returned is valid
 | 
						|
     */
 | 
						|
    QString currentField( bool *isExpression = 0, bool *isValid = 0 ) const;
 | 
						|
 | 
						|
    /**
 | 
						|
      * Return true if the current expression is valid
 | 
						|
      */
 | 
						|
    bool isValidExpression( QString *expressionError = 0 ) const;
 | 
						|
 | 
						|
    bool isExpression() const;
 | 
						|
    /**
 | 
						|
      * Return the current text that is set in the expression area
 | 
						|
      */
 | 
						|
    QString currentText() const;
 | 
						|
 | 
						|
    /** 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;
 | 
						|
 | 
						|
    /**
 | 
						|
     * 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;
 | 
						|
 | 
						|
    /**
 | 
						|
     * Returns the layer currently associated with the widget.
 | 
						|
     * @see setLayer()
 | 
						|
     */
 | 
						|
    QgsVectorLayer* layer() const;
 | 
						|
 | 
						|
    /**
 | 
						|
     * 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
 | 
						|
     */
 | 
						|
    void registerExpressionContextGenerator( QgsExpressionContextGenerator* generator );
 | 
						|
 | 
						|
  signals:
 | 
						|
    //! the signal is emitted when the currently selected field changes
 | 
						|
    void fieldChanged( const QString& fieldName );
 | 
						|
 | 
						|
    //! fieldChanged signal with indication of the validity of the expression
 | 
						|
    void fieldChanged( const QString& fieldName, bool isValid );
 | 
						|
 | 
						|
//    void returnPressed();
 | 
						|
 | 
						|
  public slots:
 | 
						|
    /**
 | 
						|
     * Sets the layer used to display the fields and expression.
 | 
						|
     * @see layer()
 | 
						|
     */
 | 
						|
    void setLayer( QgsMapLayer* layer );
 | 
						|
 | 
						|
    //! sets the current row in the widget
 | 
						|
    void setRow( int row );
 | 
						|
 | 
						|
    //! sets the current field or expression in the widget
 | 
						|
    void setField( const QString &fieldName );
 | 
						|
 | 
						|
    /**
 | 
						|
     * 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 );
 | 
						|
 | 
						|
  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
 | 
						|
    void expressionEdited( const QString& expression );
 | 
						|
 | 
						|
    //! when expression has been edited (finished) it will be added to the model
 | 
						|
    void expressionEditingFinished();
 | 
						|
 | 
						|
    void currentFieldChanged();
 | 
						|
 | 
						|
    /**
 | 
						|
     * @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
 | 
						|
     */
 | 
						|
    void updateLineEditStyle( const QString& expression = QString() );
 | 
						|
 | 
						|
    bool isExpressionValid( const QString& expressionStr );
 | 
						|
 | 
						|
  protected:
 | 
						|
    void changeEvent( QEvent* event );
 | 
						|
};
 |