mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-15 00:07:25 -05:00
CheckBox widget: support native Bool fields
This commit is contained in:
parent
cfb8552b14
commit
88a8a2c94d
@ -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 );
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user