Skip to content
Permalink
Browse files

Merge pull request #5510 from m-kuhn/relationsearch

[FEATURE] Search widget for relations using aggregates
  • Loading branch information
m-kuhn committed Nov 21, 2017
2 parents 153c83a + 81b475d commit 62713a5029a71207191929f2e9eafefabeddcc96
Showing with 1,734 additions and 396 deletions.
  1. +15 −0 python/core/qgsaggregatecalculator.sip
  2. +28 −7 python/gui/editorwidgets/core/qgssearchwidgetwrapper.sip
  3. +49 −0 python/gui/editorwidgets/qgsrelationaggregatesearchwidgetwrapper.sip
  4. +8 −0 python/gui/editorwidgets/qgsrelationwidgetwrapper.sip
  5. +10 −0 python/gui/editorwidgets/qgssearchwidgettoolbutton.sip
  6. +4 −0 python/gui/gui_auto.sip
  7. +85 −0 python/gui/qgsaggregatetoolbutton.sip
  8. +11 −0 python/gui/qgsattributeform.sip
  9. +6 −98 python/gui/qgsattributeformeditorwidget.sip
  10. +43 −0 python/gui/qgsattributeformrelationeditorwidget.sip
  11. +149 −0 python/gui/qgsattributeformwidget.sip
  12. +228 −0 src/core/qgsaggregatecalculator.cpp
  13. +19 −0 src/core/qgsaggregatecalculator.h
  14. +8 −0 src/gui/CMakeLists.txt
  15. +3 −2 src/gui/editorwidgets/core/qgseditorwidgetwrapper.cpp
  16. +19 −0 src/gui/editorwidgets/core/qgssearchwidgetwrapper.cpp
  17. +29 −7 src/gui/editorwidgets/core/qgssearchwidgetwrapper.h
  18. +1 −1 src/gui/editorwidgets/qgscheckboxsearchwidgetwrapper.cpp
  19. +1 −1 src/gui/editorwidgets/qgsdatetimesearchwidgetwrapper.cpp
  20. +1 −1 src/gui/editorwidgets/qgsdefaultsearchwidgetwrapper.cpp
  21. +85 −0 src/gui/editorwidgets/qgsrelationaggregatesearchwidgetwrapper.cpp
  22. +58 −0 src/gui/editorwidgets/qgsrelationaggregatesearchwidgetwrapper.h
  23. +1 −1 src/gui/editorwidgets/qgsrelationreferencesearchwidgetwrapper.cpp
  24. +5 −0 src/gui/editorwidgets/qgsrelationwidgetwrapper.cpp
  25. +7 −0 src/gui/editorwidgets/qgsrelationwidgetwrapper.h
  26. +16 −0 src/gui/editorwidgets/qgssearchwidgettoolbutton.h
  27. +1 −1 src/gui/editorwidgets/qgsvaluemapsearchwidgetwrapper.cpp
  28. +1 −1 src/gui/editorwidgets/qgsvaluerelationsearchwidgetwrapper.cpp
  29. +123 −0 src/gui/qgsaggregatetoolbutton.cpp
  30. +98 −0 src/gui/qgsaggregatetoolbutton.h
  31. +60 −15 src/gui/qgsattributeform.cpp
  32. +12 −0 src/gui/qgsattributeform.h
  33. +47 −147 src/gui/qgsattributeformeditorwidget.cpp
  34. +12 −103 src/gui/qgsattributeformeditorwidget.h
  35. +40 −0 src/gui/qgsattributeformrelationeditorwidget.cpp
  36. +52 −0 src/gui/qgsattributeformrelationeditorwidget.h
  37. +199 −0 src/gui/qgsattributeformwidget.cpp
  38. +179 −0 src/gui/qgsattributeformwidget.h
  39. +17 −9 tests/src/python/test_qgsattributeformeditorwidget.py
  40. +4 −2 tests/src/python/test_qgsrelationeditwidget.py
@@ -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,
@@ -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

};


@@ -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
@@ -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();
@@ -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 *
************************************************************************/
@@ -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 );

@@ -8,6 +8,10 @@



%ModuleHeaderCode
#include "qgssearchwidgettoolbutton.h"
%End

class QgsSearchWidgetToolButton : QToolButton
{
%Docstring
@@ -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:

@@ -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
@@ -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
@@ -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 *
************************************************************************/
@@ -25,6 +25,7 @@ class QgsAttributeForm : QWidget
AddFeatureMode,
MultiEditMode,
SearchMode,
AggregateSearchMode,
};

enum FilterType
@@ -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 );

0 comments on commit 62713a5

Please sign in to comment.
You can’t perform that action at this time.