QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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
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
51 return cfg;
52}
53
54void QgsCheckBoxConfigDlg::setConfig( const QVariantMap &config )
55{
56 if ( layer()->fields().at( field() ).type() != QVariant::Bool )
57 {
58 leCheckedState->setText( config.value( QStringLiteral( "CheckedState" ) ).toString() );
59 leUncheckedState->setText( config.value( QStringLiteral( "UncheckedState" ) ).toString() );
60 }
61 mDisplayAsTextComboBox->setCurrentIndex( mDisplayAsTextComboBox->findData( config.value( QStringLiteral( "TextDisplayMethod" ), QString::number( static_cast< int >( QgsCheckBoxFieldFormatter::ShowTrueFalse ) ) ).toInt() ) );
62}
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).
Represents a vector layer which manages a vector based data sets.
QgsFields fields() const FINAL
Returns the list of fields of this layer.