Skip to content

Commit

Permalink
Merge pull request #35378 from 3nids/qgsexpressiontreeview
Browse files Browse the repository at this point in the history
move tree view from the expression builder to a dedicated class
  • Loading branch information
3nids committed Mar 27, 2020
2 parents 73314b5 + 7d17e0b commit 4fe477f
Show file tree
Hide file tree
Showing 17 changed files with 1,846 additions and 1,184 deletions.
3 changes: 3 additions & 0 deletions python/gui/auto_additions/qgsexpressionbuilderwidget.py
@@ -0,0 +1,3 @@
# The following has been generated automatically from src/gui/qgsexpressionbuilderwidget.h
QgsExpressionBuilderWidget.Flag.baseClass = QgsExpressionBuilderWidget
Flag = QgsExpressionBuilderWidget # dirty hack since SIP seems to introduce the flags in module
203 changes: 80 additions & 123 deletions python/gui/auto_generated/qgsexpressionbuilderwidget.sip.in
Expand Up @@ -10,104 +10,58 @@



class QgsExpressionItem : QStandardItem



class QgsExpressionBuilderWidget : QWidget
{
%Docstring
An expression item that can be used in the QgsExpressionBuilderWidget tree.
A reusable widget that can be used to build a expression string.
See QgsExpressionBuilderDialog for example of usage.
%End

%TypeHeaderCode
#include "qgsexpressionbuilderwidget.h"
%End
public:
enum ItemType

enum Flag
{
Header,
Field,
ExpressionNode
LoadNothing,
LoadRecent,
LoadUserExpressions,
LoadAll,
};
typedef QFlags<QgsExpressionBuilderWidget::Flag> Flags;

QgsExpressionItem( const QString &label,
const QString &expressionText,
const QString &helpText,
QgsExpressionItem::ItemType itemType = ExpressionNode );

QgsExpressionItem( const QString &label,
const QString &expressionText,
QgsExpressionItem::ItemType itemType = ExpressionNode );

QString getExpressionText() const;

QString getHelpText() const;
QgsExpressionBuilderWidget( QWidget *parent /TransferThis/ = 0 );
%Docstring
Gets the help text that is associated with this expression item.

:return: The help text.
Create a new expression builder widget with an optional parent.
%End
~QgsExpressionBuilderWidget();

void setHelpText( const QString &helpText );
void init( const QgsExpressionContext &context = QgsExpressionContext(), const QString &recentCollection = QStringLiteral( "generic" ), const Flags &flags = LoadAll );
%Docstring
Set the help text for the current item
Initialize without any layer

.. note::

The help text can be set as a html string.
.. versionadded:: 3.14
%End

QgsExpressionItem::ItemType getItemType() const;
void initWithLayer( QgsVectorLayer *layer, const QgsExpressionContext &context = QgsExpressionContext(), const QString &recentCollection = QStringLiteral( "generic" ), const Flags &flags = LoadAll );
%Docstring
Gets the type of expression item, e.g., header, field, ExpressionNode.

:return: The QgsExpressionItem.ItemType
%End

static const int CUSTOM_SORT_ROLE;
static const int ITEM_TYPE_ROLE;
static const int SEARCH_TAGS_ROLE;
Initialize with a layer

};

class QgsExpressionItemSearchProxy : QSortFilterProxyModel
{
%Docstring
Search proxy used to filter the QgsExpressionBuilderWidget tree.
The default search for a tree model only searches top level this will handle one
level down
%End

%TypeHeaderCode
#include "qgsexpressionbuilderwidget.h"
.. versionadded:: 3.14
%End
public:
QgsExpressionItemSearchProxy();

virtual bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const;


protected:

virtual bool lessThan( const QModelIndex &left, const QModelIndex &right ) const;

};


class QgsExpressionBuilderWidget : QWidget
{
void initWithFields( const QgsFields &fields, const QgsExpressionContext &context = QgsExpressionContext(), const QString &recentCollection = QStringLiteral( "generic" ), const Flags &flags = LoadAll );
%Docstring
A reusable widget that can be used to build a expression string.
See QgsExpressionBuilderDialog for example of usage.
%End
Initialize with given fields without any layer

%TypeHeaderCode
#include "qgsexpressionbuilderwidget.h"
%End
public:

QgsExpressionBuilderWidget( QWidget *parent /TransferThis/ = 0 );
%Docstring
Create a new expression builder widget with an optional parent.
.. versionadded:: 3.14
%End
~QgsExpressionBuilderWidget();

void setLayer( QgsVectorLayer *layer );
%Docstring
Expand All @@ -118,23 +72,33 @@ Sets layer in order to get the fields and values
this needs to be called before calling loadFieldNames().
%End

void loadFieldNames();
QgsVectorLayer *layer() const;
%Docstring
Loads all the field names from the layer.
@remarks Should this really be public couldn't we just do this for the user?
Returns the current layer or a None.
%End

void loadFieldNames( const QgsFields &fields );
void loadFieldNames();
%Docstring

.. deprecated:: QGIS 3.14
this is now done automatically
%End

void loadFieldsAndValues( const QMap<QString, QStringList> &fieldValues );
void loadFieldNames( const QgsFields &fields );
%Docstring
Loads field names and values from the specified map.

.. note::
.. deprecated:: QGIS 3.14
use epxressionTree()->loadFieldNames() instead
%End

The field values must be quoted appropriately if they are strings.
void loadFieldsAndValues( const QMap<QString, QStringList> &fieldValues ) /Deprecated/;
%Docstring
Loads field names and values from the specified map.

.. versionadded:: 2.12

.. deprecated:: QGIS 3.14
this will not do anything, use setLayer() instead
%End

void setGeomCalculator( const QgsDistanceArea &da );
Expand Down Expand Up @@ -187,7 +151,7 @@ preview result and for populating the list of available functions and variables.
void setExpressionContext( const QgsExpressionContext &context );
%Docstring
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.
preview result and to populate the list of available functions and variables.

:param context: expression context

Expand All @@ -196,58 +160,63 @@ preview result and for populating the list of available functions and variables.
.. versionadded:: 2.12
%End

void registerItem( const QString &group, const QString &label, const QString &expressionText,
const QString &helpText = QString(),
QgsExpressionItem::ItemType type = QgsExpressionItem::ExpressionNode,
bool highlightedItem = false, int sortOrder = 1,
QIcon icon = QIcon(),
const QStringList &tags = QStringList() );
bool isExpressionValid();
%Docstring
Registers a node item for the expression builder.

:param group: The group the item will be show in the tree view. If the group doesn't exist it will be created.
:param label: The label that is show to the user for the item in the tree.
:param expressionText: The text that is inserted into the expression area when the user double clicks on the item.
:param helpText: The help text that the user will see when item is selected.
:param type: The type of the expression item.
:param highlightedItem: set to ``True`` to make the item highlighted, which inserts a bold copy of the item at the top level
:param sortOrder: sort ranking for item
:param icon: custom icon to show for item
:param tags: tags to find function
Returns if the expression is valid
%End

bool isExpressionValid();

void saveToRecent( const QString &collection = "generic" );
void saveToRecent( const QString &collection = "generic" ) /Deprecated/;
%Docstring
Adds the current expression to the given ``collection``.
By default it is saved to the collection "generic".

.. deprecated:: QGIS 3.14
use expressionTree()->saveRecent() instead
%End

void loadRecent( const QString &collection = QStringLiteral( "generic" ) );
void loadRecent( const QString &collection = QStringLiteral( "generic" ) )/Deprecated/;
%Docstring
Loads the recent expressions from the given ``collection``.
By default it is loaded from the collection "generic".

.. deprecated:: QGIS 3.14
use expressionTree()->loadRecent() instead
%End

void loadUserExpressions( );
QgsExpressionTreeView *expressionTree() const;
%Docstring
Returns the expression tree

.. versionadded:: 3.14
%End

void loadUserExpressions() /Deprecated/;
%Docstring
Loads the user expressions.

.. deprecated:: QGIS 3.14
use expressionTree()->loadUserExpressions() instead

.. versionadded:: 3.12
%End

void saveToUserExpressions( const QString &label, const QString expression, const QString &helpText );
void saveToUserExpressions( const QString &label, const QString expression, const QString &helpText ) /Deprecated/;
%Docstring
Stores the user ``expression`` with given ``label`` and ``helpText``.

.. deprecated:: QGIS 3.14
use expressionTree()->saveToUserExpressions() instead

.. versionadded:: 3.12
%End

void removeFromUserExpressions( const QString &label );
void removeFromUserExpressions( const QString &label ) /Deprecated/;
%Docstring
Removes the expression ``label`` from the user stored expressions.

.. deprecated:: QGIS 3.14
use expressionTree()->removeFromUserExpressions() instead

.. versionadded:: 3.12
%End

Expand Down Expand Up @@ -276,12 +245,14 @@ Loads code into the function editor
Updates the list of function files found at the given path
%End

QStandardItemModel *model();
QStandardItemModel *model() /Deprecated/;
%Docstring
Returns a pointer to the dialog's function item model.
This method is exposed for testing purposes only - it should not be used to modify the model.

.. versionadded:: 3.0

.. deprecated:: QGIS 3.14
%End

QgsProject *project();
Expand Down Expand Up @@ -386,24 +357,6 @@ the selected expression must be a user stored expression.
Edits the selected expression from the stored user expressions,
the selected expression must be a user stored expression.

.. versionadded:: 3.14
%End

QJsonDocument exportUserExpressions();
%Docstring
Create the expressions JSON document storing all the user expressions to be exported.

:return: the created expressions JSON file

.. versionadded:: 3.14
%End

void loadExpressionsFromJson( const QJsonDocument &expressionsDocument );
%Docstring
Load and permanently store the expressions from the expressions JSON document.

:param expressionsDocument: the parsed expressions JSON file

.. versionadded:: 3.14
%End

Expand All @@ -412,6 +365,9 @@ Load and permanently store the expressions from the expressions JSON document.
Returns the list of expression items matching a ``label``.

.. versionadded:: 3.12

.. deprecated:: QGIS 3.14
use expressionTree()->findExpressions instead
%End


Expand Down Expand Up @@ -446,6 +402,7 @@ with the context.
virtual void showEvent( QShowEvent *e );


public:
};


Expand Down

0 comments on commit 4fe477f

Please sign in to comment.