QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 "moc_qgscheckboxconfigdlg.cpp"
22
24 : QgsEditorConfigWidget( vl, fieldIdx, parent )
25{
26 setupUi( this );
27
28 mDisplayAsTextComboBox->addItem( tr( "\"True\" or \"False\"" ), QgsCheckBoxFieldFormatter::ShowTrueFalse );
29 mDisplayAsTextComboBox->addItem( tr( "Stored Values" ), QgsCheckBoxFieldFormatter::ShowStoredValues );
30 mDisplayAsTextComboBox->setCurrentIndex( 0 );
31
32 connect( leCheckedState, &QLineEdit::textEdited, this, &QgsEditorConfigWidget::changed );
33 connect( leUncheckedState, &QLineEdit::textEdited, this, &QgsEditorConfigWidget::changed );
34 connect( mDisplayAsTextComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsEditorConfigWidget::changed );
35
36 if ( vl->fields().at( fieldIdx ).type() == QMetaType::Type::Bool )
37 {
38 leCheckedState->setEnabled( false );
39 leUncheckedState->setEnabled( false );
40
41 leCheckedState->setPlaceholderText( QStringLiteral( "TRUE" ) );
42 leUncheckedState->setPlaceholderText( QStringLiteral( "FALSE" ) );
43 }
44}
45
47{
48 QVariantMap cfg;
49
50 cfg.insert( QStringLiteral( "CheckedState" ), leCheckedState->text() );
51 cfg.insert( QStringLiteral( "UncheckedState" ), leUncheckedState->text() );
52 cfg.insert( QStringLiteral( "TextDisplayMethod" ), mDisplayAsTextComboBox->currentData().toInt() );
53 cfg.insert( QStringLiteral( "AllowNullState" ), mAllowNullState->isChecked() );
54
55 return cfg;
56}
57
58void QgsCheckBoxConfigDlg::setConfig( const QVariantMap &config )
59{
60 if ( layer()->fields().at( field() ).type() != QMetaType::Type::Bool )
61 {
62 leCheckedState->setText( config.value( QStringLiteral( "CheckedState" ) ).toString() );
63 leUncheckedState->setText( config.value( QStringLiteral( "UncheckedState" ) ).toString() );
64 }
65 mDisplayAsTextComboBox->setCurrentIndex( mDisplayAsTextComboBox->findData( config.value( QStringLiteral( "TextDisplayMethod" ), QString::number( static_cast<int>( QgsCheckBoxFieldFormatter::ShowTrueFalse ) ) ).toInt() ) );
66 mAllowNullState->setChecked( config.value( QStringLiteral( "AllowNullState" ) ).toBool() );
67}
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:61
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.