Skip to content

Commit

Permalink
Merge pull request #5510 from m-kuhn/relationsearch
Browse files Browse the repository at this point in the history
[FEATURE] Search widget for relations using aggregates
  • Loading branch information
m-kuhn committed Nov 21, 2017
2 parents 153c83a + 81b475d commit 62713a5
Show file tree
Hide file tree
Showing 40 changed files with 1,734 additions and 396 deletions.
15 changes: 15 additions & 0 deletions python/core/qgsaggregatecalculator.sip
Expand Up @@ -26,6 +26,13 @@ class QgsAggregateCalculator
%End
public:

struct AggregateInfo
{
QString function; //!< The expression function
QString name; //!< A translated, human readable name
QSet<QVariant::Type> supportedTypes; //!< This aggregate function can only be used with these datatypes
};

enum Aggregate
{
Count,
Expand Down Expand Up @@ -138,6 +145,14 @@ class QgsAggregateCalculator
:rtype: Aggregate
%End

static QList< QgsAggregateCalculator::AggregateInfo > aggregates();
%Docstring
Structured information for available aggregates.

.. versionadded:: 3.2
:rtype: list of QgsAggregateCalculator.AggregateInfo
%End

};


Expand Down
35 changes: 28 additions & 7 deletions python/gui/editorwidgets/core/qgssearchwidgetwrapper.sip
Expand Up @@ -60,14 +60,8 @@
class QgsSearchWidgetWrapper : QgsWidgetWrapper
{
%Docstring
Manages an editor widget
Widget and wrapper share the same parent

A wrapper controls one attribute editor widget and is able to create a default
widget or use a pre-existent widget. It is able to set the widget to the value implied
by a field of a vector layer, or return the value it currently holds. Every time it is changed
it has to emit a valueChanged signal. If it fails to do so, there is no guarantee that the
changed status of the widget will be saved.
Shows a search widget on a filter form.
%End

%TypeHeaderCode
Expand Down Expand Up @@ -169,6 +163,33 @@ class QgsSearchWidgetWrapper : QgsWidgetWrapper
:rtype: str
%End

QString createFieldIdentifier() const;
%Docstring
Get a field name or expression to use as field comparison.
If in SearchMode returns a quoted field identifier.
If in AggregateSearchMode returns an appropriate aggregate expression.

.. versionadded:: 3.0
:rtype: str
%End

QString aggregate() const;
%Docstring
If in AggregateSearch mode, which aggregate should be used to construct
the filter expression. Is a Null String if none.

.. versionadded:: 3.0
:rtype: str
%End

void setAggregate( const QString &aggregate );
%Docstring
If in AggregateSearch mode, which aggregate should be used to construct
the filter expression. Is a Null String if none.

.. versionadded:: 3.0
%End

public slots:

virtual void clearWidget();
Expand Down
@@ -0,0 +1,49 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/editorwidgets/qgsrelationaggregatesearchwidgetwrapper.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsRelationAggregateSearchWidgetWrapper : QgsSearchWidgetWrapper
{
%Docstring

Search widget for the children of a relation.
For each attribute of the child, an additional QgsAggregateToolButton will be shown
to determine how the values should be aggregated for searching.

.. versionadded:: 3.0
%End

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

explicit QgsRelationAggregateSearchWidgetWrapper( QgsVectorLayer *layer, QgsRelationWidgetWrapper *wrapper, QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor
%End

virtual QString expression() const;

virtual bool valid() const;
virtual QWidget *createWidget( QWidget *parent );
virtual bool applyDirectly();
virtual void setExpression( const QString &value );

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/editorwidgets/qgsrelationaggregatesearchwidgetwrapper.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
8 changes: 8 additions & 0 deletions python/gui/editorwidgets/qgsrelationwidgetwrapper.sip
Expand Up @@ -71,6 +71,14 @@ class QgsRelationWidgetWrapper : QgsWidgetWrapper
.. versionadded:: 2.18
%End

QgsRelation relation() const;
%Docstring
The relation for which this wrapper is created.

.. versionadded:: 3.0
:rtype: QgsRelation
%End

protected:
virtual QWidget *createWidget( QWidget *parent );

Expand Down
10 changes: 10 additions & 0 deletions python/gui/editorwidgets/qgssearchwidgettoolbutton.sip
Expand Up @@ -8,6 +8,10 @@



%ModuleHeaderCode
#include "qgssearchwidgettoolbutton.h"
%End

class QgsSearchWidgetToolButton : QToolButton
{
%Docstring
Expand All @@ -19,6 +23,12 @@ class QgsSearchWidgetToolButton : QToolButton

%TypeHeaderCode
#include "qgssearchwidgettoolbutton.h"
%End
%ConvertToSubClassCode
if ( qobject_cast<QgsSearchWidgetToolButton *>( sipCpp ) )
sipType = sipType_QgsSearchWidgetToolButton;
else
sipType = nullptr;
%End
public:

Expand Down
4 changes: 4 additions & 0 deletions python/gui/gui_auto.sip
Expand Up @@ -52,9 +52,12 @@
%Include qgisinterface.sip
%Include qgsactionmenu.sip
%Include qgsadvanceddigitizingdockwidget.sip
%Include qgsaggregatetoolbutton.sip
%Include qgsattributedialog.sip
%Include qgsattributeform.sip
%Include qgsattributeformeditorwidget.sip
%Include qgsattributeformrelationeditorwidget.sip
%Include qgsattributeformwidget.sip
%Include qgsattributetypeloaddialog.sip
%Include qgsblendmodecombobox.sip
%Include qgsbrowsertreeview.sip
Expand Down Expand Up @@ -278,6 +281,7 @@
%Include editorwidgets/qgsrelationreferencewidget.sip
%Include editorwidgets/qgsrelationreferencewidgetwrapper.sip
%Include editorwidgets/qgsrelationwidgetwrapper.sip
%Include editorwidgets/qgsrelationaggregatesearchwidgetwrapper.sip
%Include editorwidgets/qgssearchwidgettoolbutton.sip
%Include editorwidgets/qgsspinbox.sip
%Include editorwidgets/qgsvaluemapsearchwidgetwrapper.sip
Expand Down
85 changes: 85 additions & 0 deletions python/gui/qgsaggregatetoolbutton.sip
@@ -0,0 +1,85 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsaggregatetoolbutton.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsAggregateToolButton : QToolButton
{
%Docstring

Offers a toolbutton to choose between different aggregate functions.
Functions are filtered based on the type.

.. versionadded:: 3.0
%End

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

QgsAggregateToolButton();
%Docstring
Constructor
%End

void setType( QVariant::Type type );
%Docstring
Based on the ``type`` of underlying data, some aggregates will be available or not.
%End

QVariant::Type type() const;
%Docstring
Based on the ``type`` of underlying data, some aggregates will be available or not.
:rtype: QVariant.Type
%End

void setActive( bool active );
%Docstring
When this flag is false, the aggregate will be deactivated. I.e. no aggregate is chosen.
%End

bool active() const;
%Docstring
When this flag is false, the aggregate will be deactivated. I.e. no aggregate is chosen.
:rtype: bool
%End

QString aggregate() const;
%Docstring
The function name of the selected aggregate or a Null String if none is chosen.
:rtype: str
%End

void setAggregate( const QString &aggregate );
%Docstring
The function name of the selected aggregate or a Null String if none is chosen.
%End

signals:

void aggregateChanged();
%Docstring
The function name of the selected aggregate has changed.
%End

void activeChanged();
%Docstring
A function has been selected or deselected.
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsaggregatetoolbutton.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
11 changes: 11 additions & 0 deletions python/gui/qgsattributeform.sip
Expand Up @@ -25,6 +25,7 @@ class QgsAttributeForm : QWidget
AddFeatureMode,
MultiEditMode,
SearchMode,
AggregateSearchMode,
};

enum FilterType
Expand Down Expand Up @@ -123,6 +124,16 @@ class QgsAttributeForm : QWidget
.. versionadded:: 2.16
%End

QString aggregateFilter() const;
%Docstring
The aggregate filter is only useful if the form is in AggregateFilter mode.
In this case it will return a combined expression according to the chosen filters
on all attribute widgets.

.. versionadded:: 3.0
:rtype: str
%End

signals:

void attributeChanged( const QString &attribute, const QVariant &value );
Expand Down

0 comments on commit 62713a5

Please sign in to comment.