QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgsrelationaggregatesearchwidgetwrapper.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsrelationaggregatesearchwidget.cpp
3 -----------------------------
4 Date : Nov 2017
5 Copyright : (C) 2017 Matthias Kuhn
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 "moc_qgsrelationaggregatesearchwidgetwrapper.cpp"
19#include "qgsattributeform.h"
21#include "qgslogger.h"
23
24#include <QLabel>
25#include <QGridLayout>
26
28 : QgsSearchWidgetWrapper( vl, -1, parent )
29 , mWrapper( wrapper )
30{
31 setContext( mWrapper->context() );
32}
33
35{
36 QString aggregateFilter;
37
38 if ( mAttributeForm )
39 aggregateFilter = mAttributeForm->aggregateFilter();
40
41 if ( aggregateFilter.isEmpty() )
42 return QStringLiteral( "TRUE" );
43 else
44 return aggregateFilter;
45}
46
48{
49 return true;
50}
51
53{
54 QWidget *widget;
55 const QgsRelation relation = mWrapper->relation();
56
57 QgsCollapsibleGroupBox *groupBox = new QgsCollapsibleGroupBox( relation.name() );
58
59 if ( !relation.isValid() )
60 {
61 widget = new QLabel( tr( "Relation not valid" ) );
62 }
63 else
64 {
65 mContainerWidget = new QWidget( parent );
66 widget = mContainerWidget;
67 widget->installEventFilter( this );
68 }
69
70 groupBox->setLayout( new QGridLayout() );
71 groupBox->layout()->addWidget( widget );
72
73 return groupBox;
74}
75
80
82{
83 Q_UNUSED( value )
84 QgsDebugError( QStringLiteral( "Not supported" ) );
85}
86
87bool QgsRelationAggregateSearchWidgetWrapper::eventFilter( QObject *watched, QEvent *event )
88{
89 const bool rv = QgsSearchWidgetWrapper::eventFilter( watched, event );
90 if ( event->type() == QEvent::Show && !mAttributeForm )
91 {
93 mAttributeForm = new QgsAttributeForm( mWrapper->relation().referencingLayer(), QgsFeature(), subContext, mContainerWidget );
95 QGridLayout *glayout = new QGridLayout();
96 mContainerWidget->setLayout( glayout );
97 glayout->setContentsMargins( 0, 0, 0, 0 );
98 glayout->addWidget( mAttributeForm );
99 }
100 return rv;
101}
This class contains context information for attribute editor widgets.
@ Multiple
When showing a list of features (e.g. houses as an embedded form in a district form)
@ Embed
A form was embedded as a widget on another form.
@ AggregateSearchMode
Form is in aggregate search mode, show each widget in this mode.
QString aggregateFilter() const
The aggregate filter is only useful if the form is in AggregateFilter mode.
void setMode(QgsAttributeEditorContext::Mode mode)
Sets the current mode of the form.
A groupbox that collapses/expands when toggled and can save its collapsed and checked states.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
void setExpression(const QString &value) override
Set the expression which is currently used as filter for this widget.
QgsRelationAggregateSearchWidgetWrapper(QgsVectorLayer *layer, QgsRelationWidgetWrapper *wrapper, QWidget *parent SIP_TRANSFERTHIS=nullptr)
Constructor.
bool applyDirectly() override
If this is true, then this search widget should take effect directly when its expression changes.
QWidget * createWidget(QWidget *parent) override
This method should create a new widget with the provided parent.
bool valid() const override
Returns true if the widget has been properly initialized.
QString expression() const override
Will be used to access the widget's value.
bool eventFilter(QObject *watched, QEvent *event) override
QgsRelation relation() const
The relation for which this wrapper is created.
Represents a relationship between two vector layers.
Definition qgsrelation.h:44
QString name
Definition qgsrelation.h:50
QgsVectorLayer * referencingLayer
Definition qgsrelation.h:48
Shows a search widget on a filter form.
Represents a vector layer which manages a vector based data sets.
QWidget * widget()
Access the widget managed by this wrapper.
const QgsAttributeEditorContext & context() const
Returns information about the context in which this widget is shown.
void setContext(const QgsAttributeEditorContext &context)
Set the context in which this widget is shown.
#define QgsDebugError(str)
Definition qgslogger.h:38