QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
editorwidgets
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 : matthias@opengis.ch
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
17
#include "
qgsrelationaggregatesearchwidgetwrapper.h
"
18
19
#include "
qgsattributeform.h
"
20
#include "
qgscollapsiblegroupbox.h
"
21
#include "
qgslogger.h
"
22
#include "
qgsrelationwidgetwrapper.h
"
23
24
#include <QGridLayout>
25
#include <QLabel>
26
#include <QString>
27
28
#include "moc_qgsrelationaggregatesearchwidgetwrapper.cpp"
29
30
using namespace
Qt::StringLiterals;
31
32
QgsRelationAggregateSearchWidgetWrapper::QgsRelationAggregateSearchWidgetWrapper
(
QgsVectorLayer
*vl,
QgsRelationWidgetWrapper
*wrapper, QWidget *parent )
33
:
QgsSearchWidgetWrapper
( vl, -1, parent )
34
, mWrapper( wrapper )
35
{
36
setContext
( mWrapper->context() );
37
}
38
39
QString
QgsRelationAggregateSearchWidgetWrapper::expression
()
const
40
{
41
QString aggregateFilter;
42
43
if
( mAttributeForm )
44
aggregateFilter = mAttributeForm->aggregateFilter();
45
46
if
( aggregateFilter.isEmpty() )
47
return
u
"TRUE"
_s;
48
else
49
return
aggregateFilter;
50
}
51
52
bool
QgsRelationAggregateSearchWidgetWrapper::valid
()
const
53
{
54
return
true
;
55
}
56
57
QWidget *
QgsRelationAggregateSearchWidgetWrapper::createWidget
( QWidget *parent )
58
{
59
QWidget *
widget
;
60
const
QgsRelation
relation = mWrapper->relation();
61
62
QgsCollapsibleGroupBox
*groupBox =
new
QgsCollapsibleGroupBox
( relation.
name
() );
63
64
if
( !relation.
isValid
() )
65
{
66
widget
=
new
QLabel( tr(
"Relation not valid"
) );
67
}
68
else
69
{
70
mContainerWidget =
new
QWidget( parent );
71
widget
= mContainerWidget;
72
widget
->installEventFilter(
this
);
73
}
74
75
groupBox->setLayout(
new
QGridLayout() );
76
groupBox->layout()->addWidget(
widget
);
77
78
return
groupBox;
79
}
80
81
bool
QgsRelationAggregateSearchWidgetWrapper::applyDirectly
()
82
{
83
return
true
;
84
}
85
86
void
QgsRelationAggregateSearchWidgetWrapper::setExpression
(
const
QString &value )
87
{
88
Q_UNUSED( value )
89
QgsDebugError
( u
"Not supported"
_s );
90
}
91
92
bool
QgsRelationAggregateSearchWidgetWrapper::eventFilter
( QObject *watched, QEvent *event )
93
{
94
const
bool
rv = QgsSearchWidgetWrapper::eventFilter( watched, event );
95
if
( event->type() == QEvent::Show && !mAttributeForm )
96
{
97
const
QgsAttributeEditorContext
subContext =
QgsAttributeEditorContext
(
context
(), mWrapper->
relation
(),
QgsAttributeEditorContext::Multiple
,
QgsAttributeEditorContext::Embed
);
98
mAttributeForm =
new
QgsAttributeForm
( mWrapper->relation().referencingLayer(),
QgsFeature
(), subContext, mContainerWidget );
99
mAttributeForm->setMode(
QgsAttributeEditorContext::AggregateSearchMode
);
100
QGridLayout *glayout =
new
QGridLayout();
101
mContainerWidget->setLayout( glayout );
102
glayout->setContentsMargins( 0, 0, 0, 0 );
103
glayout->addWidget( mAttributeForm );
104
}
105
return
rv;
106
}
QgsAttributeEditorContext
Contains context information for attribute editor widgets.
Definition
qgsattributeeditorcontext.h:42
QgsAttributeEditorContext::Multiple
@ Multiple
When showing a list of features (e.g. houses as an embedded form in a district form).
Definition
qgsattributeeditorcontext.h:67
QgsAttributeEditorContext::Embed
@ Embed
A form was embedded as a widget on another form.
Definition
qgsattributeeditorcontext.h:73
QgsAttributeEditorContext::AggregateSearchMode
@ AggregateSearchMode
Form is in aggregate search mode, show each widget in this mode.
Definition
qgsattributeeditorcontext.h:55
QgsAttributeEditorContext::relation
const QgsRelation & relation() const
Returns the attribute relation.
Definition
qgsattributeeditorcontext.h:188
QgsAttributeForm
The attribute form widget for vector layer features.
Definition
qgsattributeform.h:48
QgsCollapsibleGroupBox
A groupbox that collapses/expands when toggled and can save its collapsed and checked states.
Definition
qgscollapsiblegroupbox.h:196
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition
qgsfeature.h:60
QgsRelationAggregateSearchWidgetWrapper::setExpression
void setExpression(const QString &value) override
Set the expression which is currently used as filter for this widget.
Definition
qgsrelationaggregatesearchwidgetwrapper.cpp:86
QgsRelationAggregateSearchWidgetWrapper::QgsRelationAggregateSearchWidgetWrapper
QgsRelationAggregateSearchWidgetWrapper(QgsVectorLayer *layer, QgsRelationWidgetWrapper *wrapper, QWidget *parent SIP_TRANSFERTHIS=nullptr)
Constructor.
Definition
qgsrelationaggregatesearchwidgetwrapper.cpp:32
QgsRelationAggregateSearchWidgetWrapper::applyDirectly
bool applyDirectly() override
If this is true, then this search widget should take effect directly when its expression changes.
Definition
qgsrelationaggregatesearchwidgetwrapper.cpp:81
QgsRelationAggregateSearchWidgetWrapper::createWidget
QWidget * createWidget(QWidget *parent) override
This method should create a new widget with the provided parent.
Definition
qgsrelationaggregatesearchwidgetwrapper.cpp:57
QgsRelationAggregateSearchWidgetWrapper::valid
bool valid() const override
Returns true if the widget has been properly initialized.
Definition
qgsrelationaggregatesearchwidgetwrapper.cpp:52
QgsRelationAggregateSearchWidgetWrapper::expression
QString expression() const override
Will be used to access the widget's value.
Definition
qgsrelationaggregatesearchwidgetwrapper.cpp:39
QgsRelationAggregateSearchWidgetWrapper::eventFilter
bool eventFilter(QObject *watched, QEvent *event) override
Definition
qgsrelationaggregatesearchwidgetwrapper.cpp:92
QgsRelationWidgetWrapper
A widget wrapper for relation widgets.
Definition
qgsrelationwidgetwrapper.h:32
QgsRelation
Represents a relationship between two vector layers.
Definition
qgsrelation.h:42
QgsRelation::name
QString name
Definition
qgsrelation.h:52
QgsRelation::isValid
bool isValid
Definition
qgsrelation.h:53
QgsSearchWidgetWrapper::QgsSearchWidgetWrapper
QgsSearchWidgetWrapper(QgsVectorLayer *vl, int fieldIdx, QWidget *parent=nullptr)
Create a new widget wrapper.
Definition
qgssearchwidgetwrapper.cpp:92
QgsVectorLayer
Represents a vector layer which manages a vector based dataset.
Definition
qgsvectorlayer.h:414
QgsWidgetWrapper::widget
QWidget * widget()
Access the widget managed by this wrapper.
Definition
qgswidgetwrapper.cpp:49
QgsWidgetWrapper::context
const QgsAttributeEditorContext & context() const
Returns information about the context in which this widget is shown.
Definition
qgswidgetwrapper.cpp:89
QgsWidgetWrapper::setContext
void setContext(const QgsAttributeEditorContext &context)
Set the context in which this widget is shown.
Definition
qgswidgetwrapper.cpp:69
qgsattributeform.h
qgscollapsiblegroupbox.h
qgslogger.h
QgsDebugError
#define QgsDebugError(str)
Definition
qgslogger.h:71
qgsrelationaggregatesearchwidgetwrapper.h
qgsrelationwidgetwrapper.h
Generated on
for QGIS API Documentation by
1.17.0