QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
16 #include "qgscheckboxconfigdlg.h"
17 
18 QgsCheckBoxConfigDlg::QgsCheckBoxConfigDlg( QgsVectorLayer *vl, int fieldIdx, QWidget *parent )
19  : QgsEditorConfigWidget( vl, fieldIdx, parent )
20 {
21  setupUi( this );
22 
23  connect( leCheckedState, &QLineEdit::textEdited, this, &QgsEditorConfigWidget::changed );
24  connect( leUncheckedState, &QLineEdit::textEdited, this, &QgsEditorConfigWidget::changed );
25 
26  if ( vl->fields().at( fieldIdx ).type() == QVariant::Bool )
27  {
28  leCheckedState->setEnabled( false );
29  leUncheckedState->setEnabled( false );
30 
31  leCheckedState->setPlaceholderText( QStringLiteral( "TRUE" ) );
32  leUncheckedState->setPlaceholderText( QStringLiteral( "FALSE" ) );
33  }
34 }
35 
37 {
38  QVariantMap cfg;
39 
40  cfg.insert( QStringLiteral( "CheckedState" ), leCheckedState->text() );
41  cfg.insert( QStringLiteral( "UncheckedState" ), leUncheckedState->text() );
42 
43  return cfg;
44 }
45 
46 void QgsCheckBoxConfigDlg::setConfig( const QVariantMap &config )
47 {
48  if ( layer()->fields().at( field() ).type() != QVariant::Bool )
49  {
50  leCheckedState->setText( config.value( QStringLiteral( "CheckedState" ) ).toString() );
51  leUncheckedState->setText( config.value( QStringLiteral( "UncheckedState" ) ).toString() );
52  }
53 }
QgsEditorConfigWidget
This class should be subclassed for every configurable editor widget type.
Definition: qgseditorconfigwidget.h:39
QgsVectorLayer::fields
QgsFields fields() const FINAL
Returns the list of fields of this layer.
Definition: qgsvectorlayer.cpp:3283
QgsEditorConfigWidget::field
int field()
Returns the field for which this configuration widget applies.
Definition: qgseditorconfigwidget.cpp:28
QgsEditorConfigWidget::layer
QgsVectorLayer * layer()
Returns the layer for which this configuration widget applies.
Definition: qgseditorconfigwidget.cpp:33
QgsCheckBoxConfigDlg::setConfig
void setConfig(const QVariantMap &config) override
Update the configuration widget to represent the given configuration.
Definition: qgscheckboxconfigdlg.cpp:46
QgsCheckBoxConfigDlg::QgsCheckBoxConfigDlg
QgsCheckBoxConfigDlg(QgsVectorLayer *vl, int fieldIdx, QWidget *parent=nullptr)
Definition: qgscheckboxconfigdlg.cpp:18
qgscheckboxconfigdlg.h
QgsCheckBoxConfigDlg::config
QVariantMap config() override
Create a configuration from the current GUI state.
Definition: qgscheckboxconfigdlg.cpp:36
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsEditorConfigWidget::changed
void changed()
Emitted when the configuration of the widget is changed.
QgsFields::at
QgsField at(int i) const
Gets field at particular index (must be in range 0..N-1)
Definition: qgsfields.cpp:163
QgsField::type
QVariant::Type type
Definition: qgsfield.h:57