Skip to content

Commit

Permalink
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 26, 2020
1 parent c5841c3 commit bb8bced
Show file tree
Hide file tree
Showing 15 changed files with 1,681 additions and 1,122 deletions.
7 changes: 7 additions & 0 deletions python/core/auto_generated/qgsfieldformatterregistry.sip.in
Expand Up @@ -61,6 +61,13 @@ a default QgsFallbackFieldFormatter with a null id will be returned instead.
%Docstring
Returns a basic fallback field formatter which can be used
to represent any field in an unspectacular manner.
%End

static bool formatterCanProvideAvailableValues( QgsVectorLayer *layer, const QString &fieldName );
%Docstring
Returns if the formatter for a given layer and field name can provide available values

.. versionadded:: 3.14
%End

signals:
Expand Down
168 changes: 41 additions & 127 deletions python/gui/auto_generated/qgsexpressionbuilderwidget.sip.in
Expand Up @@ -10,86 +10,8 @@



class QgsExpressionItem : QStandardItem
{
%Docstring
An expression item that can be used in the QgsExpressionBuilderWidget tree.
%End

%TypeHeaderCode
#include "qgsexpressionbuilderwidget.h"
%End
public:
enum ItemType
{
Header,
Field,
ExpressionNode
};

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;
%Docstring
Gets the help text that is associated with this expression item.

:return: The help text.
%End

void setHelpText( const QString &helpText );
%Docstring
Set the help text for the current item

.. note::

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

QgsExpressionItem::ItemType getItemType() const;
%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;

};

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"
%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
{
Expand Down Expand Up @@ -118,13 +40,17 @@ 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( const QgsFields &fields = QgsFields() );
%Docstring

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

void loadFieldsAndValues( const QMap<QString, QStringList> &fieldValues );
%Docstring
Expand All @@ -135,6 +61,9 @@ Loads field names and values from the specified map.
The field values must be quoted appropriately if they are strings.

.. versionadded:: 2.12

.. deprecated::
use setLayer() and expressionTree()->
%End

void setGeomCalculator( const QgsDistanceArea &da );
Expand Down Expand Up @@ -187,67 +116,64 @@ 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

.. seealso:: :py:func:`expressionContext`

.. 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() );
%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
%End

bool isExpressionValid();

void saveToRecent( const QString &collection = "generic" );
void saveToRecent( const QString &collection = "generic" );
%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" ) );
%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;

void loadUserExpressions();
%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 );
%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 );
%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 +202,14 @@ Loads code into the function editor
Updates the list of function files found at the given path
%End

QStandardItemModel *model();
QStandardItemModel *model();
%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 +314,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 +322,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 +359,7 @@ with the context.
virtual void showEvent( QShowEvent *e );


public:
};


Expand Down

0 comments on commit bb8bced

Please sign in to comment.