Skip to content
Permalink
Browse files
CheckBox widget: support native Bool fields
  • Loading branch information
m-kuhn committed Apr 10, 2017
1 parent cfb8552 commit 88a8a2c94dde9af0f79d8326d65c0f2a133e42fd
Showing with 38 additions and 8 deletions.
  1. +14 −2 src/gui/editorwidgets/qgscheckboxconfigdlg.cpp
  2. +24 −6 src/gui/editorwidgets/qgscheckboxwidgetwrapper.cpp
@@ -22,6 +22,15 @@ QgsCheckBoxConfigDlg::QgsCheckBoxConfigDlg( QgsVectorLayer *vl, int fieldIdx, QW

connect( leCheckedState, &QLineEdit::textEdited, this, &QgsEditorConfigWidget::changed );
connect( leUncheckedState, &QLineEdit::textEdited, this, &QgsEditorConfigWidget::changed );

if ( vl->fields().at( fieldIdx ).type() == QVariant::Bool )
{
leCheckedState->setEnabled( false );
leUncheckedState->setEnabled( false );

leCheckedState->setPlaceholderText( QStringLiteral( "TRUE" ) );
leUncheckedState->setPlaceholderText( QStringLiteral( "FALSE" ) );
}
}

QVariantMap QgsCheckBoxConfigDlg::config()
@@ -36,6 +45,9 @@ QVariantMap QgsCheckBoxConfigDlg::config()

void QgsCheckBoxConfigDlg::setConfig( const QVariantMap &config )
{
leCheckedState->setText( config.value( QStringLiteral( "CheckedState" ) ).toString() );
leUncheckedState->setText( config.value( QStringLiteral( "UncheckedState" ) ).toString() );
if ( layer()->fields().at( field() ).type() != QVariant::Bool )
{
leCheckedState->setText( config.value( QStringLiteral( "CheckedState" ) ).toString() );
leUncheckedState->setText( config.value( QStringLiteral( "UncheckedState" ) ).toString() );
}
}
@@ -27,12 +27,21 @@ QVariant QgsCheckboxWidgetWrapper::value() const
{
QVariant v;

if ( mGroupBox )
v = mGroupBox->isChecked() ? config( QStringLiteral( "CheckedState" ) ) : config( QStringLiteral( "UncheckedState" ) );

if ( mCheckBox )
v = mCheckBox->isChecked() ? config( QStringLiteral( "CheckedState" ) ) : config( QStringLiteral( "UncheckedState" ) );
if ( field().type() == QVariant::Bool )
{
if ( mGroupBox )
v = mGroupBox->isChecked();
else if ( mCheckBox )
v = mCheckBox->isChecked();
}
else
{
if ( mGroupBox )
v = mGroupBox->isChecked() ? config( QStringLiteral( "CheckedState" ) ) : config( QStringLiteral( "UncheckedState" ) );

else if ( mCheckBox )
v = mCheckBox->isChecked() ? config( QStringLiteral( "CheckedState" ) ) : config( QStringLiteral( "UncheckedState" ) );
}

return v;
}
@@ -68,7 +77,16 @@ bool QgsCheckboxWidgetWrapper::valid() const

void QgsCheckboxWidgetWrapper::setValue( const QVariant &value )
{
bool state = ( value == config( QStringLiteral( "CheckedState" ) ) );
bool state = false;

if ( field().type() == QVariant::Bool )
{
state = value.toBool();
}
else
{
state = ( value == config( QStringLiteral( "CheckedState" ) ) );
}
if ( mGroupBox )
{
mGroupBox->setChecked( state );

0 comments on commit 88a8a2c

Please sign in to comment.