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