Skip to content

Commit

Permalink
sipify QgsFieldExpressionWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Apr 19, 2017
1 parent daa3c2a commit 55860e8
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 91 deletions.
1 change: 0 additions & 1 deletion python/auto_sip.blacklist
Expand Up @@ -364,7 +364,6 @@ gui/qgsextentgroupbox.sip
gui/qgsexternalresourcewidget.sip
gui/qgsfeatureselectiondlg.sip
gui/qgsfieldcombobox.sip
gui/qgsfieldexpressionwidget.sip
gui/qgsfieldmodel.sip
gui/qgsfieldproxymodel.sip
gui/qgsfieldvalidator.sip
Expand Down
233 changes: 152 additions & 81 deletions python/gui/qgsfieldexpressionwidget.sip
@@ -1,135 +1,206 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsfieldexpressionwidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/







class QgsFieldExpressionWidget : QWidget
{
%Docstring
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).
%End

%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 );
%Docstring
QgsFieldExpressionWidget creates a widget with a combo box to display the fields and expression and a button to open the expression dialog
%End

//! define the title used in the expression dialog
void setExpressionDialogTitle( const QString& title );
void setExpressionDialogTitle( const QString &title );
%Docstring
define the title used in the expression dialog
%End

//! return the title used for the expression dialog
const QString expressionDialogTitle();
%Docstring
return the title used for the expression dialog
:rtype: str
%End

//! setFilters allows fitering according to the type of field
void setFilters( QgsFieldProxyModel::Filters filters );
%Docstring
setFilters allows fitering according to the type of field
%End

void setLeftHandButtonStyle( bool isLeft );

//! currently used filter on list of fields
QgsFieldProxyModel::Filters filters() const;
%Docstring
currently used filter on list of fields
:rtype: QgsFieldProxyModel.Filters
%End

//! set the geometry calculator used in the expression dialog
void setGeomCalculator( const QgsDistanceArea &da );
%Docstring
set the geometry calculator used in the expression dialog
%End

/**
* @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;
%Docstring
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
:rtype: str
%End

/**
* Return true if the current expression is valid
*/
bool isValidExpression( QString *expressionError = 0 ) const;
%Docstring
Return true if the current expression is valid
:rtype: bool
%End

bool isExpression() const;
/**
* Return the current text that is set in the expression area
*/
%Docstring
If the content is not just a simple field this method will return true.
:rtype: bool
%End

QString currentText() const;
%Docstring
Return the current text that is set in the expression area
:rtype: str
%End

/** 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;
%Docstring
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).
.. versionadded:: 2.14
:rtype: str
%End

/**
* 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;
%Docstring
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).

/**
* 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 );
Alias for asExpression()

signals:
//! the signal is emitted when the currently selected field changes
void fieldChanged( const QString& fieldName );
.. versionadded:: 3.0
:rtype: str
%End

//! fieldChanged signal with indication of the validity of the expression
void fieldChanged( const QString& fieldName, bool isValid );
QgsVectorLayer *layer() const;
%Docstring
Returns the layer currently associated with the widget.
\see setLayer()
:rtype: QgsVectorLayer
%End

// void returnPressed();
void registerExpressionContextGenerator( const QgsExpressionContextGenerator *generator );
%Docstring
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.
.. versionadded:: 3.0
%End

signals:
void fieldChanged( const QString &fieldName );
%Docstring
the signal is emitted when the currently selected field changes
%End

void fieldChanged( const QString &fieldName, bool isValid );
%Docstring
fieldChanged signal with indication of the validity of the expression
%End

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 setLayer( QgsMapLayer *layer );
%Docstring
Sets the layer used to display the fields and expression.
\see layer()
%End

void setRow( int row );
%Docstring
sets the current row in the widget
%End

//! sets the current field or expression in the widget
void setField( const QString &fieldName );
%Docstring
sets the current field or expression in the widget
%End

void setExpression( const QString &expression );
%Docstring
Sets the current expression text and if applicable also the field.
Alias for setField.

/**
* 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 );
.. versionadded:: 3.0
%End

protected slots:
//! open the expression dialog to edit the current or add a new expression
void editExpression();
%Docstring
open the expression dialog to edit the current or add a new expression
%End

//! when expression is edited by the user in the line edit, it will be checked for validity
void expressionEdited( const QString& expression );
void expressionEdited( const QString &expression );
%Docstring
when expression is edited by the user in the line edit, it will be checked for validity
%End

//! when expression has been edited (finished) it will be added to the model
void expressionEditingFinished();
%Docstring
when expression has been edited (finished) it will be added to the model
%End

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() );
void updateLineEditStyle( const QString &expression = QString() );
%Docstring
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
%End

bool isExpressionValid( const QString& expressionStr );
bool isExpressionValid( const QString &expressionStr );
%Docstring
:rtype: bool
%End

protected:
void changeEvent( QEvent* event );
virtual void changeEvent( QEvent *event );

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsfieldexpressionwidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
18 changes: 9 additions & 9 deletions src/gui/qgsfieldexpressionwidget.h
Expand Up @@ -16,17 +16,19 @@
#ifndef QGSFIELDEXPRESSIONWIDGET_H
#define QGSFIELDEXPRESSIONWIDGET_H

#include <QWidget>
#include <QToolButton>
#include <QComboBox>
#include <QColor>
#include <QComboBox>
#include <QToolButton>
#include <QWidget>
#include <memory>

#include "qgis_gui.h"
#include "qgis.h"
#include "qgsdistancearea.h"
#include "qgsfieldproxymodel.h"
#include "qgsexpressioncontext.h"
#include "qgsexpressioncontextgenerator.h"
#include "qgis_gui.h"
#include "qgsexpressioncontext.h"
#include "qgsfieldproxymodel.h"


class QgsMapLayer;
class QgsVectorLayer;
Expand All @@ -52,7 +54,7 @@ class GUI_EXPORT QgsFieldExpressionWidget : public QWidget
/**
* \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 = nullptr );
explicit QgsFieldExpressionWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );

//! define the title used in the expression dialog
void setExpressionDialogTitle( const QString &title );
Expand Down Expand Up @@ -134,8 +136,6 @@ class GUI_EXPORT QgsFieldExpressionWidget : public QWidget
//! fieldChanged signal with indication of the validity of the expression
void fieldChanged( const QString &fieldName, bool isValid );

// void returnPressed();

public slots:

/**
Expand Down

0 comments on commit 55860e8

Please sign in to comment.