QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
editorwidgets
qgscheckboxconfigdlg.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgscheckboxconfigdlg.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 "
qgscheckboxconfigdlg.h
"
17
18
#include "
qgscheckboxfieldformatter.h
"
19
#include "
qgscheckboxwidgetwrapper.h
"
20
21
#include <QString>
22
23
#include "moc_qgscheckboxconfigdlg.cpp"
24
25
using namespace
Qt::StringLiterals;
26
27
QgsCheckBoxConfigDlg::QgsCheckBoxConfigDlg
(
QgsVectorLayer
*vl,
int
fieldIdx, QWidget *parent )
28
:
QgsEditorConfigWidget
( vl, fieldIdx, parent )
29
{
30
setupUi(
this
);
31
32
mDisplayAsTextComboBox->addItem( tr(
"\"True\" or \"False\""
),
QgsCheckBoxFieldFormatter::ShowTrueFalse
);
33
mDisplayAsTextComboBox->addItem( tr(
"Stored Values"
),
QgsCheckBoxFieldFormatter::ShowStoredValues
);
34
mDisplayAsTextComboBox->setCurrentIndex( 0 );
35
36
connect( leCheckedState, &QLineEdit::textEdited,
this
, &
QgsEditorConfigWidget::changed
);
37
connect( leUncheckedState, &QLineEdit::textEdited,
this
, &
QgsEditorConfigWidget::changed
);
38
connect( mDisplayAsTextComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this
, &
QgsEditorConfigWidget::changed
);
39
40
if
( vl->
fields
().
at
( fieldIdx ).
type
() == QMetaType::Type::Bool )
41
{
42
leCheckedState->setEnabled(
false
);
43
leUncheckedState->setEnabled(
false
);
44
45
leCheckedState->setPlaceholderText( u
"TRUE"
_s );
46
leUncheckedState->setPlaceholderText( u
"FALSE"
_s );
47
}
48
}
49
50
QVariantMap
QgsCheckBoxConfigDlg::config
()
51
{
52
QVariantMap cfg;
53
54
cfg.insert( u
"CheckedState"
_s, leCheckedState->text() );
55
cfg.insert( u
"UncheckedState"
_s, leUncheckedState->text() );
56
cfg.insert( u
"TextDisplayMethod"
_s, mDisplayAsTextComboBox->currentData().toInt() );
57
cfg.insert( u
"AllowNullState"
_s, mAllowNullState->isChecked() );
58
59
return
cfg;
60
}
61
62
void
QgsCheckBoxConfigDlg::setConfig
(
const
QVariantMap &
config
)
63
{
64
if
(
layer
()->fields().at(
field
() ).type() != QMetaType::Type::Bool )
65
{
66
leCheckedState->setText(
config
.value( u
"CheckedState"
_s ).toString() );
67
leUncheckedState->setText(
config
.value( u
"UncheckedState"
_s ).toString() );
68
}
69
mDisplayAsTextComboBox->setCurrentIndex(
70
mDisplayAsTextComboBox->findData(
config
.value( u
"TextDisplayMethod"
_s, QString::number(
static_cast<
int
>
(
QgsCheckBoxFieldFormatter::ShowTrueFalse
) ) ).toInt() )
71
);
72
mAllowNullState->setChecked(
config
.value( u
"AllowNullState"
_s ).toBool() );
73
}
QgsCheckBoxConfigDlg::setConfig
void setConfig(const QVariantMap &config) override
Update the configuration widget to represent the given configuration.
Definition
qgscheckboxconfigdlg.cpp:62
QgsCheckBoxConfigDlg::config
QVariantMap config() override
Create a configuration from the current GUI state.
Definition
qgscheckboxconfigdlg.cpp:50
QgsCheckBoxConfigDlg::QgsCheckBoxConfigDlg
QgsCheckBoxConfigDlg(QgsVectorLayer *vl, int fieldIdx, QWidget *parent=nullptr)
Definition
qgscheckboxconfigdlg.cpp:27
QgsCheckBoxFieldFormatter::ShowTrueFalse
@ ShowTrueFalse
Shows "True" or "False" strings.
Definition
qgscheckboxfieldformatter.h:38
QgsCheckBoxFieldFormatter::ShowStoredValues
@ ShowStoredValues
Shows actual stored field value.
Definition
qgscheckboxfieldformatter.h:39
QgsEditorConfigWidget::QgsEditorConfigWidget
QgsEditorConfigWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent)
Create a new configuration widget.
Definition
qgseditorconfigwidget.cpp:23
QgsEditorConfigWidget::field
int field()
Returns the field for which this configuration widget applies.
Definition
qgseditorconfigwidget.cpp:30
QgsEditorConfigWidget::layer
QgsVectorLayer * layer()
Returns the layer for which this configuration widget applies.
Definition
qgseditorconfigwidget.cpp:35
QgsEditorConfigWidget::changed
void changed()
Emitted when the configuration of the widget is changed.
QgsField::type
QMetaType::Type type
Definition
qgsfield.h:63
QgsFields::at
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
Definition
qgsfields.cpp:209
QgsVectorLayer
Represents a vector layer which manages a vector based dataset.
Definition
qgsvectorlayer.h:414
QgsVectorLayer::fields
QgsFields fields
Definition
qgsvectorlayer.h:422
qgscheckboxconfigdlg.h
qgscheckboxfieldformatter.h
qgscheckboxwidgetwrapper.h
Generated on
for QGIS API Documentation by
1.17.0