QGIS API Documentation
2.8.2-Wien
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
src
gui
editorwidgets
qgsrelationwidgetwrapper.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsrelationwidgetwrapper.cpp
3
--------------------------------------
4
Date : 14.5.2014
5
Copyright : (C) 2014 Matthias Kuhn
6
Email : matthias dot kuhn at gmx dot 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
#include "
qgsrelationwidgetwrapper.h
"
17
18
#include "
qgsrelationeditorwidget.h
"
19
#include "
qgsattributeeditorcontext.h
"
20
21
#include <QWidget>
22
23
QgsRelationWidgetWrapper::QgsRelationWidgetWrapper
(
QgsVectorLayer
* vl,
const
QgsRelation
& relation, QWidget* editor, QWidget* parent )
24
:
QgsWidgetWrapper
( vl, editor, parent )
25
, mRelation( relation )
26
, mWidget( NULL )
27
{
28
}
29
30
QWidget*
QgsRelationWidgetWrapper::createWidget
( QWidget* parent )
31
{
32
return
new
QgsRelationEditorWidget
( parent );
33
}
34
35
void
QgsRelationWidgetWrapper::setFeature
(
const
QgsFeature
& feature )
36
{
37
if
( mWidget && mRelation.
isValid
() )
38
mWidget->
setRelationFeature
( mRelation, feature );
39
}
40
41
void
QgsRelationWidgetWrapper::initWidget
( QWidget* editor )
42
{
43
QgsRelationEditorWidget
* w =
dynamic_cast<
QgsRelationEditorWidget
*
>
( editor );
44
45
// if the editor cannot be cast to relation editor, insert a new one
46
if
( !w )
47
{
48
w =
new
QgsRelationEditorWidget
( editor );
49
w->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
50
if
( ! editor->layout() )
51
{
52
editor->setLayout(
new
QGridLayout() );
53
}
54
editor->layout()->addWidget( w );
55
}
56
57
QgsAttributeEditorContext
myContext(
QgsAttributeEditorContext
(
context
(), mRelation,
QgsAttributeEditorContext::Multiple
,
QgsAttributeEditorContext::Embed
) );
58
59
w->
setEditorContext
( myContext );
60
61
// If this widget is already embedded by the same relation, reduce functionality
62
const
QgsAttributeEditorContext
* ctx = &
context
();
63
do
64
{
65
if
( ctx->
relation
().
name
() == mRelation.
name
() && ctx->
formMode
() ==
QgsAttributeEditorContext::Embed
)
66
{
67
w->setVisible(
false
);
68
break
;
69
}
70
ctx = ctx->
parentContext
();
71
}
72
while
( ctx );
73
74
mWidget = w;
75
}
Generated on Sun May 10 2015 16:33:25 for QGIS API Documentation by
1.8.1.2