QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
editorwidgets
qgsenumerationwidgetwrapper.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsenumerationwidgetwrapper.cpp
3
--------------------------------------
4
Date : 5.1.2014
5
Copyright : (C) 2014 Matthias Kuhn
6
Email : matthias at opengis 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 "
qgsenumerationwidgetwrapper.h
"
17
18
#include "
qgsapplication.h
"
19
#include "
qgsvectordataprovider.h
"
20
#include "
qgsvectorlayer.h
"
21
22
#include "moc_qgsenumerationwidgetwrapper.cpp"
23
24
QgsEnumerationWidgetWrapper::QgsEnumerationWidgetWrapper
(
QgsVectorLayer
*
layer
,
int
fieldIdx
, QWidget *editor, QWidget *parent )
25
:
QgsEditorWidgetWrapper
(
layer
,
fieldIdx
, editor, parent )
26
27
{}
28
29
30
QVariant
QgsEnumerationWidgetWrapper::value
()
const
31
{
32
QVariant
value
;
33
34
if
( mComboBox )
35
value
= mComboBox->currentData();
36
37
return
value
;
38
}
39
40
void
QgsEnumerationWidgetWrapper::showIndeterminateState
()
41
{
42
if
( mComboBox )
43
{
44
whileBlocking
( mComboBox )->setCurrentIndex( -1 );
45
}
46
}
47
48
QWidget *
QgsEnumerationWidgetWrapper::createWidget
( QWidget *parent )
49
{
50
QComboBox *combo =
new
QComboBox( parent );
51
combo->setMinimumContentsLength( 1 );
52
combo->setSizeAdjustPolicy( QComboBox::SizeAdjustPolicy::AdjustToMinimumContentsLengthWithIcon );
53
return
combo;
54
}
55
56
void
QgsEnumerationWidgetWrapper::initWidget
( QWidget *editor )
57
{
58
mComboBox = qobject_cast<QComboBox *>( editor );
59
60
if
( mComboBox )
61
{
62
const
QgsField
field
(
layer
()->fields().at(
fieldIdx
() ) );
63
// also add NULL entry if not restricted by constraints
64
if
( !(
field
.constraints().constraints() &
QgsFieldConstraints::ConstraintNotNull
) )
65
{
66
mComboBox->addItem(
QgsApplication::nullRepresentation
(),
QgsVariantUtils::createNullVariant
(
field
.type() ) );
67
}
68
69
const
QList<QPair<QString, QString>> values(
layer
()->dataProvider()->codedValues(
fieldIdx
() ) );
70
for
(
const
QPair<QString, QString> &pair : values )
71
{
72
mComboBox->addItem( pair.second, pair.first );
73
}
74
connect( mComboBox,
static_cast<
void
( QComboBox::* )(
int
)
>
( &QComboBox::currentIndexChanged ),
this
,
static_cast<
void
(
QgsEditorWidgetWrapper
::* )()
>
( &
QgsEditorWidgetWrapper::emitValueChanged
) );
75
}
76
}
77
78
bool
QgsEnumerationWidgetWrapper::valid
()
const
79
{
80
return
mComboBox;
81
}
82
83
void
QgsEnumerationWidgetWrapper::updateValues(
const
QVariant &value,
const
QVariantList & )
84
{
85
if
( mComboBox )
86
{
87
mComboBox->setCurrentIndex( mComboBox->findData(
value
) );
88
}
89
}
QgsApplication::nullRepresentation
static QString nullRepresentation()
Returns the string used to represent the value NULL throughout QGIS.
Definition
qgsapplication.cpp:2227
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::emitValueChanged
void emitValueChanged()
Will call the value() method to determine the emitted value.
Definition
qgseditorwidgetwrapper.cpp:98
QgsEditorWidgetWrapper::field
QgsField field() const
Access the field.
Definition
qgseditorwidgetwrapper.cpp:42
QgsEnumerationWidgetWrapper::value
QVariant value() const override
Will be used to access the widget's value.
Definition
qgsenumerationwidgetwrapper.cpp:30
QgsEnumerationWidgetWrapper::createWidget
QWidget * createWidget(QWidget *parent) override
This method should create a new widget with the provided parent.
Definition
qgsenumerationwidgetwrapper.cpp:48
QgsEnumerationWidgetWrapper::initWidget
void initWidget(QWidget *editor) override
This method should initialize the editor widget with runtime data.
Definition
qgsenumerationwidgetwrapper.cpp:56
QgsEnumerationWidgetWrapper::valid
bool valid() const override
Returns true if the widget has been properly initialized.
Definition
qgsenumerationwidgetwrapper.cpp:78
QgsEnumerationWidgetWrapper::QgsEnumerationWidgetWrapper
QgsEnumerationWidgetWrapper(QgsVectorLayer *layer, int fieldIdx, QWidget *editor=nullptr, QWidget *parent=nullptr)
Constructor for QgsEnumerationWidgetWrapper.
Definition
qgsenumerationwidgetwrapper.cpp:24
QgsEnumerationWidgetWrapper::showIndeterminateState
void showIndeterminateState() override
Sets the widget to display in an indeterminate "mixed value" state.
Definition
qgsenumerationwidgetwrapper.cpp:40
QgsFieldConstraints::ConstraintNotNull
@ ConstraintNotNull
Field may not be null.
Definition
qgsfieldconstraints.h:44
QgsField
Encapsulate a field in an attribute table or data source.
Definition
qgsfield.h:56
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
whileBlocking
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition
qgis.h:7637
qgsapplication.h
qgsenumerationwidgetwrapper.h
qgsvectordataprovider.h
qgsvectorlayer.h
Generated on
for QGIS API Documentation by
1.17.0