QGIS API Documentation 3.99.0-Master (09f76ad7019)
Loading...
Searching...
No Matches
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
17
20
21#include <QString>
22
23#include "moc_qgscheckboxconfigdlg.cpp"
24
25using namespace Qt::StringLiterals;
26
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
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
62void 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( mDisplayAsTextComboBox->findData( config.value( u"TextDisplayMethod"_s, QString::number( static_cast<int>( QgsCheckBoxFieldFormatter::ShowTrueFalse ) ) ).toInt() ) );
70 mAllowNullState->setChecked( config.value( u"AllowNullState"_s ).toBool() );
71}
void setConfig(const QVariantMap &config) override
Update the configuration widget to represent the given configuration.
QVariantMap config() override
Create a configuration from the current GUI state.
QgsCheckBoxConfigDlg(QgsVectorLayer *vl, int fieldIdx, QWidget *parent=nullptr)
@ ShowTrueFalse
Shows "True" or "False" strings.
@ ShowStoredValues
Shows actual stored field value.
QgsEditorConfigWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent)
Create a new configuration widget.
int field()
Returns the field for which this configuration widget applies.
QgsVectorLayer * layer()
Returns the layer for which this configuration widget applies.
void changed()
Emitted when the configuration of the widget is changed.
QMetaType::Type type
Definition qgsfield.h:63
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
Represents a vector layer which manages a vector based dataset.