Skip to content
Permalink
Browse files

[FEATURE] Search widget for relations using aggregates

For each child relations, the subform is visible.

Each attribute of the children has a tool button option to define to which
aggregate the specified value should be compared. This allows for searching
things like

 * Each city where the highest building is more than 300 m
 * Each sensor where the median value is lower than 50 ppm
 * Each feature with a child with a missing value
 * ...
  • Loading branch information
m-kuhn committed Nov 1, 2017
1 parent f5559b5 commit fdd00870eee1d8f06a8cedf50c3e5d5ab3611319
Showing with 1,246 additions and 263 deletions.
  1. +12 −0 python/core/qgsaggregatecalculator.sip
  2. +19 −0 python/gui/editorwidgets/core/qgssearchwidgetwrapper.sip
  3. +53 −0 python/gui/editorwidgets/qgsrelationaggregatesearchwidgetwrapper.sip
  4. +5 −0 python/gui/editorwidgets/qgsrelationwidgetwrapper.sip
  5. +3 −0 python/gui/gui_auto.sip
  6. +68 −0 python/gui/qgsaggregatetoolbutton.sip
  7. +6 −0 python/gui/qgsattributeform.sip
  8. +0 −63 python/gui/qgsattributeformeditorwidget.sip
  9. +48 −0 python/gui/qgsattributeformrelationeditorwidget.sip
  10. +51 −1 python/gui/qgsattributeformwidget.sip
  11. +226 −0 src/core/qgsaggregatecalculator.cpp
  12. +9 −0 src/core/qgsaggregatecalculator.h
  13. +6 −0 src/gui/CMakeLists.txt
  14. +29 −0 src/gui/editorwidgets/core/qgssearchwidgetwrapper.cpp
  15. +13 −0 src/gui/editorwidgets/core/qgssearchwidgetwrapper.h
  16. +1 −1 src/gui/editorwidgets/qgscheckboxsearchwidgetwrapper.cpp
  17. +1 −1 src/gui/editorwidgets/qgsdatetimesearchwidgetwrapper.cpp
  18. +1 −1 src/gui/editorwidgets/qgsdefaultsearchwidgetwrapper.cpp
  19. +61 −0 src/gui/editorwidgets/qgsrelationaggregatesearchwidgetwrapper.cpp
  20. +47 −0 src/gui/editorwidgets/qgsrelationaggregatesearchwidgetwrapper.h
  21. +1 −1 src/gui/editorwidgets/qgsrelationreferencesearchwidgetwrapper.cpp
  22. +5 −0 src/gui/editorwidgets/qgsrelationwidgetwrapper.cpp
  23. +2 −0 src/gui/editorwidgets/qgsrelationwidgetwrapper.h
  24. +1 −1 src/gui/editorwidgets/qgsvaluemapsearchwidgetwrapper.cpp
  25. +1 −1 src/gui/editorwidgets/qgsvaluerelationsearchwidgetwrapper.cpp
  26. +115 −0 src/gui/qgsaggregatetoolbutton.cpp
  27. +58 −0 src/gui/qgsaggregatetoolbutton.h
  28. +54 −9 src/gui/qgsattributeform.cpp
  29. +4 −0 src/gui/qgsattributeform.h
  30. +32 −124 src/gui/qgsattributeformeditorwidget.cpp
  31. +3 −58 src/gui/qgsattributeformeditorwidget.h
  32. +38 −0 src/gui/qgsattributeformrelationeditorwidget.cpp
  33. +40 −0 src/gui/qgsattributeformrelationeditorwidget.h
  34. +166 −0 src/gui/qgsattributeformwidget.cpp
  35. +67 −2 src/gui/qgsattributeformwidget.h
@@ -26,6 +26,13 @@ class QgsAggregateCalculator
%End
public:

struct AggregateInfo
{
QString function;
QString name;
QSet<QVariant::Type> supportedTypes;
};

enum Aggregate
{
Count,
@@ -138,6 +145,11 @@ class QgsAggregateCalculator
:rtype: Aggregate
%End

static QList< QgsAggregateCalculator::AggregateInfo > aggregates();
%Docstring
:rtype: list of QgsAggregateCalculator.AggregateInfo
%End

};


@@ -169,6 +169,25 @@ class QgsSearchWidgetWrapper : QgsWidgetWrapper
:rtype: str
%End

QString createFieldIdentifier() const;
%Docstring
:rtype: str
%End



QString aggregate() const;
%Docstring
:rtype: str
%End
void setAggregate( const QString &aggregate );

QgsRelation aggregateRelation() const;
%Docstring
:rtype: QgsRelation
%End
void setAggregateRelation( const QgsRelation &aggregateRelation );

public slots:

virtual void clearWidget();
@@ -0,0 +1,53 @@
/************************************************************************
* 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
*************************************************************************
qgsrelationaggregatesearchwidget.h
-----------------------------
Date : Nov 2017
Copyright : (C) 2017 Matthias Kuhn
Email : matthias@opengis.ch
**************************************************************************
*
This program is free software; you can redistribute it and/or modify *
it under the terms of the GNU General Public License as published by *
the Free Software Foundation; either version 2 of the License, or *
(at your option) any later version. *
*
**************************************************************************
%End

%TypeHeaderCode
#include "qgsrelationaggregatesearchwidgetwrapper.h"
%End
public:
explicit QgsRelationAggregateSearchWidgetWrapper( QgsVectorLayer *vl, QgsRelationWidgetWrapper *wrapper, QWidget *parent /TransferThis/ = 0 );

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,11 @@ class QgsRelationWidgetWrapper : QgsWidgetWrapper
.. versionadded:: 2.18
%End

QgsRelation relation() const;
%Docstring
:rtype: QgsRelation
%End

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

@@ -52,9 +52,11 @@
%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
@@ -279,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,68 @@
/************************************************************************
* 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
*************************************************************************
qgsaggregatetoolbutton.h
--------------------------------------
Date : Nov 2017
Copyright : (C) 2017 Matthias Kuhn
Email : matthias@opengis.ch
**************************************************************************
*
This program is free software; you can redistribute it and/or modify *
it under the terms of the GNU General Public License as published by *
the Free Software Foundation; either version 2 of the License, or *
(at your option) any later version. *
*
**************************************************************************
%End

%TypeHeaderCode
#include "qgsaggregatetoolbutton.h"
%End
public:
QgsAggregateToolButton();

void setType( QVariant::Type type );

QVariant::Type type() const;
%Docstring
:rtype: QVariant.Type
%End

void setActive( bool active );
bool active() const;
%Docstring
:rtype: bool
%End

QString aggregate() const;
%Docstring
:rtype: str
%End
void setAggregate( const QString &aggregate );

signals:
void aggregateChanged();
void activeChanged();

};

/************************************************************************
* 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,11 @@ class QgsAttributeForm : QWidget
.. versionadded:: 2.16
%End

QString aggregateFilter() const;
%Docstring
:rtype: str
%End

signals:

void attributeChanged( const QString &attribute, const QVariant &value );
@@ -56,15 +56,6 @@ class QgsAttributeFormEditorWidget : QgsAttributeFormWidget
:rtype: QVariant
%End

virtual QString currentFilterExpression() const;

%Docstring
Creates an expression matching the current search filter value and
search properties represented in the widget.
.. versionadded:: 2.16
:rtype: str
%End

void setConstraintStatus( const QString &constraint, const QString &description, const QString &err, QgsEditorWidgetWrapper::ConstraintResult result );
%Docstring
Set the constraint status for this widget.
@@ -88,11 +79,6 @@ class QgsAttributeFormEditorWidget : QgsAttributeFormWidget
Called when field values have been committed;
%End

void resetSearch();
%Docstring
Resets the search/filter value of the widget.
%End

signals:

void valueChanged( const QVariant &value );
@@ -101,55 +87,6 @@ class QgsAttributeFormEditorWidget : QgsAttributeFormWidget
\param value new widget value
%End

protected:

QgsSearchWidgetToolButton *searchWidgetToolButton();
%Docstring
Returns a pointer to the search widget tool button in the widget.
.. note::

this method is in place for unit testing only, and is not considered
stable API
:rtype: QgsSearchWidgetToolButton
%End

void setSearchWidgetWrapper( QgsSearchWidgetWrapper *wrapper );
%Docstring
Sets the search widget wrapper for the widget used when the form is in
search mode.
\param wrapper search widget wrapper.
.. note::

the search widget wrapper should be created using searchWidgetFrame()
as its parent
.. note::

this method is in place for unit testing only, and is not considered
stable API
%End

QWidget *searchWidgetFrame();
%Docstring
Returns the widget which should be used as a parent during construction
of the search widget wrapper.
.. note::

this method is in place for unit testing only, and is not considered
stable AP
:rtype: QWidget
%End

QList< QgsSearchWidgetWrapper * > searchWidgetWrappers();
%Docstring
Returns the search widget wrapper used in this widget. The wrapper must
first be created using createSearchWidgetWrapper()
.. note::

this method is in place for unit testing only, and is not considered
stable API
:rtype: list of QgsSearchWidgetWrapper
%End

};

/************************************************************************
@@ -0,0 +1,48 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsattributeformrelationeditorwidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsAttributeFormRelationEditorWidget : QgsAttributeFormWidget
{
%Docstring
*************************************************************************
qgsattributeformrelationeditorwidget.h
--------------------------------------
Date : Nov 2017
Copyright : (C) 2017 Matthias Kuhn
Email : matthias@opengis.ch
**************************************************************************
*
This program is free software; you can redistribute it and/or modify *
it under the terms of the GNU General Public License as published by *
the Free Software Foundation; either version 2 of the License, or *
(at your option) any later version. *
*
**************************************************************************
%End

%TypeHeaderCode
#include "qgsattributeformrelationeditorwidget.h"
%End
public:
explicit QgsAttributeFormRelationEditorWidget( QgsRelationWidgetWrapper *wrapper, QgsAttributeForm *form );

virtual void createSearchWidgetWrappers();
virtual QString currentFilterExpression() const;

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsattributeformrelationeditorwidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

0 comments on commit fdd0087

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