QGIS API Documentation  3.6.0-Noosa (5873452)
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 );
93  mAttributeForm->setMode( QgsAttributeEditorContext::AggregateSearchMode );
94  QGridLayout *glayout = new QGridLayout();
95  mContainerWidget->setLayout( glayout );
96  glayout->setMargin( 0 );
97  glayout->addWidget( mAttributeForm );
98  }
99  return rv;
100 }
QString expression() const override
Will be used to access the widget&#39;s value.
QString name
Definition: qgsrelation.h:48
Shows a search widget on a filter form.
QWidget * createWidget(QWidget *parent) override
This method should create a new widget with the provided parent.
Form is in aggregate search mode, show each widget in this mode.
A groupbox that collapses/expands when toggled and can save its collapsed and checked states...
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
This class contains context information for attribute editor widgets.
QgsRelationAggregateSearchWidgetWrapper(QgsVectorLayer *layer, QgsRelationWidgetWrapper *wrapper, QWidget *parent SIP_TRANSFERTHIS=nullptr)
Constructor.
QgsVectorLayer referencingLayer
Definition: qgsrelation.h:46
When showing a list of features (e.g. houses as an embedded form in a district form) ...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
void setContext(const QgsAttributeEditorContext &context)
Set the context in which this widget is shown.
bool applyDirectly() override
If this is true, then this search widget should take effect directly when its expression changes...
void setExpression(const QString &value) override
Set the expression which is currently used as filter for this widget.
QString aggregateFilter() const
The aggregate filter is only useful if the form is in AggregateFilter mode.
const QgsAttributeEditorContext & context() const
Returns information about the context in which this widget is shown.
bool valid() const override
Returns true if the widget has been properly initialized.
bool isValid
Definition: qgsrelation.h:49
bool eventFilter(QObject *watched, QEvent *event) override
QWidget * widget()
Access the widget managed by this wrapper.
QgsRelation relation() const
The relation for which this wrapper is created.
Represents a vector layer which manages a vector based data sets.
A form was embedded as a widget on another form.