Skip to content

Commit

Permalink
[FEATURE] Search widget for relations using aggregates
Browse files Browse the repository at this point in the history
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 20, 2017
1 parent f5559b5 commit fdd0087
Show file tree
Hide file tree
Showing 35 changed files with 1,246 additions and 263 deletions.
12 changes: 12 additions & 0 deletions python/core/qgsaggregatecalculator.sip
Expand Up @@ -26,6 +26,13 @@ class QgsAggregateCalculator
%End
public:

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

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

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

};


Expand Down
19 changes: 19 additions & 0 deletions python/gui/editorwidgets/core/qgssearchwidgetwrapper.sip
Expand Up @@ -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();
Expand Down
@@ -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 *
************************************************************************/
5 changes: 5 additions & 0 deletions python/gui/editorwidgets/qgsrelationwidgetwrapper.sip
Expand Up @@ -71,6 +71,11 @@ class QgsRelationWidgetWrapper : QgsWidgetWrapper
.. versionadded:: 2.18
%End

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

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

Expand Down
3 changes: 3 additions & 0 deletions python/gui/gui_auto.sip
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
68 changes: 68 additions & 0 deletions python/gui/qgsaggregatetoolbutton.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 *
************************************************************************/
6 changes: 6 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,11 @@ class QgsAttributeForm : QWidget
.. versionadded:: 2.16
%End

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

signals:

void attributeChanged( const QString &attribute, const QVariant &value );
Expand Down
63 changes: 0 additions & 63 deletions python/gui/qgsattributeformeditorwidget.sip
Expand Up @@ -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.
Expand All @@ -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 );
Expand All @@ -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

};

/************************************************************************
Expand Down
48 changes: 48 additions & 0 deletions python/gui/qgsattributeformrelationeditorwidget.sip
@@ -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.