QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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 "qgsattributeform.h"
20#include "qgslogger.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 const 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
79
81{
82 Q_UNUSED( value )
83 QgsDebugError( QStringLiteral( "Not supported" ) );
84}
85
86bool QgsRelationAggregateSearchWidgetWrapper::eventFilter( QObject *watched, QEvent *event )
87{
88 const 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}
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:56
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.
QString name
Definition qgsrelation.h:48
QgsVectorLayer * referencingLayer
Definition qgsrelation.h:46
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