QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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
19
21 : QgsEditorConfigWidget( vl, fieldIdx, parent )
22{
23 setupUi( this );
24
25 mDisplayAsTextComboBox->addItem( tr( "\"True\" or \"False\"" ), QgsCheckBoxFieldFormatter::ShowTrueFalse );
26 mDisplayAsTextComboBox->addItem( tr( "Stored Values" ), QgsCheckBoxFieldFormatter::ShowStoredValues );
27 mDisplayAsTextComboBox->setCurrentIndex( 0 );
28
29 connect( leCheckedState, &QLineEdit::textEdited, this, &QgsEditorConfigWidget::changed );
30 connect( leUncheckedState, &QLineEdit::textEdited, this, &QgsEditorConfigWidget::changed );
31 connect( mDisplayAsTextComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsEditorConfigWidget::changed );
32
33 if ( vl->fields().at( fieldIdx ).type() == QVariant::Bool )
34 {
35 leCheckedState->setEnabled( false );
36 leUncheckedState->setEnabled( false );
37
38 leCheckedState->setPlaceholderText( QStringLiteral( "TRUE" ) );
39 leUncheckedState->setPlaceholderText( QStringLiteral( "FALSE" ) );
40 }
41}
42
44{
45 QVariantMap cfg;
46
47 cfg.insert( QStringLiteral( "CheckedState" ), leCheckedState->text() );
48 cfg.insert( QStringLiteral( "UncheckedState" ), leUncheckedState->text() );
49 cfg.insert( QStringLiteral( "TextDisplayMethod" ), mDisplayAsTextComboBox->currentData().toInt() );
50 cfg.insert( QStringLiteral( "AllowNullState" ), mAllowNullState->isChecked() );
51
52 return cfg;
53}
54
55void QgsCheckBoxConfigDlg::setConfig( const QVariantMap &config )
56{
57 if ( layer()->fields().at( field() ).type() != QVariant::Bool )
58 {
59 leCheckedState->setText( config.value( QStringLiteral( "CheckedState" ) ).toString() );
60 leUncheckedState->setText( config.value( QStringLiteral( "UncheckedState" ) ).toString() );
61 }
62 mDisplayAsTextComboBox->setCurrentIndex( mDisplayAsTextComboBox->findData( config.value( QStringLiteral( "TextDisplayMethod" ), QString::number( static_cast< int >( QgsCheckBoxFieldFormatter::ShowTrueFalse ) ) ).toInt() ) );
63 mAllowNullState->setChecked( config.value( QStringLiteral( "AllowNullState" ) ).toBool() );
64}
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.
This class should be subclassed for every configurable editor widget type.
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.
QVariant::Type type
Definition: qgsfield.h:60
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
Definition: qgsfields.cpp:163
Represents a vector layer which manages a vector based data sets.
QgsFields fields() const FINAL
Returns the list of fields of this layer.