QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
editorwidgets
qgskeyvaluewidgetwrapper.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgskeyvaluewidgetwrapper.cpp
3
--------------------------------------
4
Date : 08.2016
5
Copyright : (C) 2016 Patrick Valsecchi
6
Email : patrick.valsecchi@camptocamp.com
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 "
qgskeyvaluewidgetwrapper.h
"
17
18
#include "
qgsattributeform.h
"
19
#include "
qgskeyvaluewidget.h
"
20
21
#include "moc_qgskeyvaluewidgetwrapper.cpp"
22
23
QgsKeyValueWidgetWrapper::QgsKeyValueWidgetWrapper
(
QgsVectorLayer
*
layer
,
int
fieldIdx
, QWidget *editor, QWidget *parent )
24
:
QgsEditorWidgetWrapper
(
layer
,
fieldIdx
, editor, parent )
25
{}
26
27
QVariant
QgsKeyValueWidgetWrapper::value
()
const
28
{
29
if
( !mWidget )
30
return
QgsVariantUtils::createNullVariant
( QMetaType::Type::QVariantMap );
31
return
mWidget->map();
32
}
33
34
void
QgsKeyValueWidgetWrapper::showIndeterminateState
()
35
{
36
mWidget->setMap( QVariantMap() );
37
}
38
39
void
QgsKeyValueWidgetWrapper::setEnabled
(
bool
enabled )
40
{
41
if
( mWidget )
42
{
43
mWidget->setReadOnly( !enabled );
44
}
45
}
46
47
QWidget *
QgsKeyValueWidgetWrapper::createWidget
( QWidget *parent )
48
{
49
if
(
isInTable
( parent ) )
50
{
51
// if to be put in a table, draw a border and set a decent size
52
QFrame *ret =
new
QFrame( parent );
53
ret->setFrameShape( QFrame::StyledPanel );
54
QHBoxLayout *layout =
new
QHBoxLayout( ret );
55
layout->addWidget(
new
QgsKeyValueWidget
( ret ) );
56
ret->setMinimumSize( QSize( 320, 110 ) );
57
return
ret;
58
}
59
else
60
{
61
return
new
QgsKeyValueWidget
( parent );
62
}
63
}
64
65
void
QgsKeyValueWidgetWrapper::initWidget
( QWidget *editor )
66
{
67
mWidget = qobject_cast<QgsKeyValueWidget *>( editor );
68
if
( !mWidget )
69
{
70
mWidget = editor->findChild<
QgsKeyValueWidget
*>();
71
}
72
73
connect( mWidget, &
QgsKeyValueWidget::valueChanged
,
this
, &QgsKeyValueWidgetWrapper::onValueChanged );
74
}
75
76
bool
QgsKeyValueWidgetWrapper::valid
()
const
77
{
78
return
true
;
79
}
80
81
void
QgsKeyValueWidgetWrapper::updateValues(
const
QVariant &value,
const
QVariantList & )
82
{
83
mWidget->
setMap
(
value
.toMap() );
84
}
85
86
void
QgsKeyValueWidgetWrapper::updateConstraintWidgetStatus
()
87
{
88
// Nothing
89
}
90
91
void
QgsKeyValueWidgetWrapper::onValueChanged()
92
{
93
emitValueChanged
();
94
}
QgsEditorWidgetWrapper::updateConstraintWidgetStatus
virtual void updateConstraintWidgetStatus()
This should update the widget with a visual cue if a constraint status changed.
Definition
qgseditorwidgetwrapper.cpp:112
QgsEditorWidgetWrapper::fieldIdx
int fieldIdx() const
Access the field index.
Definition
qgseditorwidgetwrapper.cpp:37
QgsEditorWidgetWrapper::QgsEditorWidgetWrapper
QgsEditorWidgetWrapper(QgsVectorLayer *vl, int fieldIdx, QWidget *editor=nullptr, QWidget *parent=nullptr)
Create a new widget wrapper.
Definition
qgseditorwidgetwrapper.cpp:32
QgsEditorWidgetWrapper::isInTable
static bool isInTable(const QWidget *parent)
Check if the given widget or one of its parent is a QTableView.
Definition
qgseditorwidgetwrapper.cpp:305
QgsEditorWidgetWrapper::emitValueChanged
void emitValueChanged()
Will call the value() method to determine the emitted value.
Definition
qgseditorwidgetwrapper.cpp:98
QgsKeyValueWidgetWrapper::value
QVariant value() const override
Will be used to access the widget's value.
Definition
qgskeyvaluewidgetwrapper.cpp:27
QgsKeyValueWidgetWrapper::createWidget
QWidget * createWidget(QWidget *parent) override
This method should create a new widget with the provided parent.
Definition
qgskeyvaluewidgetwrapper.cpp:47
QgsKeyValueWidgetWrapper::showIndeterminateState
void showIndeterminateState() override
Sets the widget to display in an indeterminate "mixed value" state.
Definition
qgskeyvaluewidgetwrapper.cpp:34
QgsKeyValueWidgetWrapper::QgsKeyValueWidgetWrapper
QgsKeyValueWidgetWrapper(QgsVectorLayer *layer, int fieldIdx, QWidget *editor=nullptr, QWidget *parent=nullptr)
Constructor for QgsKeyValueWidgetWrapper.
Definition
qgskeyvaluewidgetwrapper.cpp:23
QgsKeyValueWidgetWrapper::initWidget
void initWidget(QWidget *editor) override
This method should initialize the editor widget with runtime data.
Definition
qgskeyvaluewidgetwrapper.cpp:65
QgsKeyValueWidgetWrapper::setEnabled
void setEnabled(bool enabled) override
Definition
qgskeyvaluewidgetwrapper.cpp:39
QgsKeyValueWidgetWrapper::valid
bool valid() const override
Returns true if the widget has been properly initialized.
Definition
qgskeyvaluewidgetwrapper.cpp:76
QgsKeyValueWidget
Widget allowing editing a QVariantMap, using a table.
Definition
qgskeyvaluewidget.h:65
QgsKeyValueWidget::setMap
void setMap(const QVariantMap &map)
Set the initial value of the widget.
Definition
qgskeyvaluewidget.cpp:27
QgsTableWidgetBase::valueChanged
void valueChanged()
Emitted each time a key or a value is changed.
QgsVariantUtils::createNullVariant
static QVariant createNullVariant(QMetaType::Type metaType)
Helper method to properly create a null QVariant from a metaType Returns the created QVariant.
Definition
qgsvariantutils.cpp:628
QgsVectorLayer
Represents a vector layer which manages a vector based dataset.
Definition
qgsvectorlayer.h:414
QgsWidgetWrapper::layer
QgsVectorLayer * layer() const
Returns the vector layer associated with the widget.
Definition
qgswidgetwrapper.cpp:94
qgsattributeform.h
qgskeyvaluewidget.h
qgskeyvaluewidgetwrapper.h
Generated on
for QGIS API Documentation by
1.17.0