QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 }
QgsVectorLayer * layer()
Returns the layer for which this configuration widget applies.
int field()
Returns the field for which this configuration widget applies.
This class should be subclassed for every configurable editor widget type.
QgsCheckBoxConfigDlg(QgsVectorLayer *vl, int fieldIdx, QWidget *parent=nullptr)
QgsField at(int i) const
Gets field at particular index (must be in range 0..N-1)
Definition: qgsfields.cpp:163
QgsFields fields() const FINAL
Returns the list of fields of this layer.
QVariantMap config() override
Create a configuration from the current GUI state.
void changed()
Emitted when the configuration of the widget is changed.
void setConfig(const QVariantMap &config) override
Update the configuration widget to represent the given configuration.
Represents a vector layer which manages a vector based data sets.
QVariant::Type type
Definition: qgsfield.h:56