QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsrelationaggregatesearchwidgetwrapper.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrelationaggregatesearchwidget.cpp
3  -----------------------------
4  Date : Nov 2017
5  Copyright : (C) 2017 Matthias Kuhn
6  Email : [email protected]
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 
18 #include "qgsattributeform.h"
20 #include "qgslogger.h"
21 #include "qgscollapsiblegroupbox.h"
22 
23 #include <QLabel>
24 #include <QGridLayout>
25 
27  : QgsSearchWidgetWrapper( vl, -1, parent )
28  , mWrapper( wrapper )
29 {
30  setContext( mWrapper->context() );
31 }
32 
34 {
35  QString aggregateFilter;
36 
37  if ( mAttributeForm )
38  aggregateFilter = mAttributeForm->aggregateFilter();
39 
40  if ( aggregateFilter.isEmpty() )
41  return QStringLiteral( "TRUE" );
42  else
43  return aggregateFilter;
44 }
45 
47 {
48  return true;
49 }
50 
52 {
53  QWidget *widget;
54  QgsRelation relation = mWrapper->relation();
55 
56  QgsCollapsibleGroupBox *groupBox = new QgsCollapsibleGroupBox( relation.name() );
57 
58  if ( !relation.isValid() )
59  {
60  widget = new QLabel( tr( "Relation not valid" ) );
61  }
62  else
63  {
64  mContainerWidget = new QWidget( parent );
65  widget = mContainerWidget;
66  widget->installEventFilter( this );
67  }
68 
69  groupBox->setLayout( new QGridLayout() );
70  groupBox->layout()->addWidget( widget );
71 
72  return groupBox;
73 }
74 
76 {
77  return true;
78 }
79 
81 {
82  Q_UNUSED( value )
83  QgsDebugMsg( QStringLiteral( "Not supported" ) );
84 }
85 
86 bool QgsRelationAggregateSearchWidgetWrapper::eventFilter( QObject *watched, QEvent *event )
87 {
88  bool rv = QgsSearchWidgetWrapper::eventFilter( watched, event );
89  if ( event->type() == QEvent::Show && !mAttributeForm )
90  {
92  mAttributeForm = new QgsAttributeForm( mWrapper->relation().referencingLayer(), QgsFeature(), subContext, mContainerWidget );
94  QGridLayout *glayout = new QGridLayout();
95  mContainerWidget->setLayout( glayout );
96  glayout->setContentsMargins( 0, 0, 0, 0 );
97  glayout->addWidget( mAttributeForm );
98  }
99  return rv;
100 }
qgsattributeform.h
qgscollapsiblegroupbox.h
QgsRelation::name
QString name
Definition: qgsrelation.h:48
QgsRelationWidgetWrapper
Definition: qgsrelationwidgetwrapper.h:31
QgsSearchWidgetWrapper
Shows a search widget on a filter form.
Definition: qgssearchwidgetwrapper.h:86
QgsRelationAggregateSearchWidgetWrapper::eventFilter
bool eventFilter(QObject *watched, QEvent *event) override
Definition: qgsrelationaggregatesearchwidgetwrapper.cpp:86
QgsAttributeEditorContext::Embed
@ Embed
A form was embedded as a widget on another form.
Definition: qgsattributeeditorcontext.h:72
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsAttributeForm::aggregateFilter
QString aggregateFilter() const
The aggregate filter is only useful if the form is in AggregateFilter mode.
Definition: qgsattributeform.cpp:2408
QgsWidgetWrapper::context
const QgsAttributeEditorContext & context() const
Returns information about the context in which this widget is shown.
Definition: qgswidgetwrapper.cpp:86
QgsCollapsibleGroupBox
A groupbox that collapses/expands when toggled and can save its collapsed and checked states.
Definition: qgscollapsiblegroupbox.h:179
QgsWidgetWrapper::widget
QWidget * widget()
Access the widget managed by this wrapper.
Definition: qgswidgetwrapper.cpp:46
QgsRelation::referencingLayer
QgsVectorLayer * referencingLayer
Definition: qgsrelation.h:46
QgsRelationWidgetWrapper::relation
QgsRelation relation() const
The relation for which this wrapper is created.
Definition: qgsrelationwidgetwrapper.cpp:80
QgsRelationAggregateSearchWidgetWrapper::valid
bool valid() const override
Returns true if the widget has been properly initialized.
Definition: qgsrelationaggregatesearchwidgetwrapper.cpp:46
QgsRelationAggregateSearchWidgetWrapper::applyDirectly
bool applyDirectly() override
If this is true, then this search widget should take effect directly when its expression changes.
Definition: qgsrelationaggregatesearchwidgetwrapper.cpp:75
QgsRelationAggregateSearchWidgetWrapper::createWidget
QWidget * createWidget(QWidget *parent) override
This method should create a new widget with the provided parent.
Definition: qgsrelationaggregatesearchwidgetwrapper.cpp:51
QgsRelationAggregateSearchWidgetWrapper::expression
QString expression() const override
Will be used to access the widget's value.
Definition: qgsrelationaggregatesearchwidgetwrapper.cpp:33
QgsRelationAggregateSearchWidgetWrapper::QgsRelationAggregateSearchWidgetWrapper
QgsRelationAggregateSearchWidgetWrapper(QgsVectorLayer *layer, QgsRelationWidgetWrapper *wrapper, QWidget *parent SIP_TRANSFERTHIS=nullptr)
Constructor.
Definition: qgsrelationaggregatesearchwidgetwrapper.cpp:26
QgsAttributeForm::setMode
void setMode(QgsAttributeEditorContext::Mode mode)
Sets the current mode of the form.
Definition: qgsattributeform.cpp:131
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsRelation::isValid
bool isValid
Definition: qgsrelation.h:49
qgsrelationaggregatesearchwidgetwrapper.h
QgsRelation
Definition: qgsrelation.h:42
QgsFeature
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
QgsAttributeForm
Definition: qgsattributeform.h:45
QgsAttributeEditorContext::AggregateSearchMode
@ AggregateSearchMode
Form is in aggregate search mode, show each widget in this mode.
Definition: qgsattributeeditorcontext.h:55
qgslogger.h
QgsAttributeEditorContext
This class contains context information for attribute editor widgets.
Definition: qgsattributeeditorcontext.h:41
qgsrelationwidgetwrapper.h
QgsWidgetWrapper::setContext
void setContext(const QgsAttributeEditorContext &context)
Set the context in which this widget is shown.
Definition: qgswidgetwrapper.cpp:66
QgsAttributeEditorContext::Multiple
@ Multiple
When showing a list of features (e.g. houses as an embedded form in a district form)
Definition: qgsattributeeditorcontext.h:66
QgsRelationAggregateSearchWidgetWrapper::setExpression
void setExpression(const QString &value) override
Set the expression which is currently used as filter for this widget.
Definition: qgsrelationaggregatesearchwidgetwrapper.cpp:80