From aa2c28bc51b715433a6ad18fe08b748ba55d9a4c Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Fri, 15 Jan 2016 01:02:11 +0100 Subject: [PATCH] Forms: Let checkboxes be unchecked At least in PDF which is the only backend with form support Radio buttons are a bit of a mess since they're supposedly also uncheckable if NoToggleToOff is not set but in Adobe Reader they never are BUGS: 357743 --- ui/formwidgets.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ui/formwidgets.cpp b/ui/formwidgets.cpp index db95bf0ce..3d1b98d8e 100644 --- a/ui/formwidgets.cpp +++ b/ui/formwidgets.cpp @@ -83,8 +83,6 @@ QButtonGroup* FormWidgetsController::registerRadioButton( QAbstractButton *butto if ( !button ) return 0; - - QList< RadioData >::iterator it = m_radios.begin(), itEnd = m_radios.end(); const int id = formButton->id(); m_formButtons.insert( id, formButton ); @@ -147,6 +145,14 @@ void FormWidgetsController::slotButtonClicked( QAbstractButton *button ) int pageNumber = -1; if ( CheckBoxEdit *check = qobject_cast< CheckBoxEdit * >( button ) ) { + // Checkboxes need to be uncheckable so if clicking a checked one + // disable the exclusive status temporarily and uncheck it + if (m_formButtons[check->formField()->id()]->state()) { + const bool wasExclusive = button->group()->exclusive(); + button->group()->setExclusive(false); + check->setChecked(false); + button->group()->setExclusive(wasExclusive); + } pageNumber = check->pageItem()->pageNumber(); } else if ( RadioButtonEdit *radio = qobject_cast< RadioButtonEdit * >( button ) ) @@ -176,8 +182,14 @@ void FormWidgetsController::slotFormButtonsChangedByUndoRedo( int pageNumber, co { int id = formButton->id(); QAbstractButton* button = m_buttons[id]; + // temporarily disable exclusiveness of the button group + // since it breaks doing/redoing steps into which all the checkboxes + // are unchecked + const bool wasExclusive = button->group()->exclusive(); + button->group()->setExclusive(false); bool checked = formButton->state(); button->setChecked( checked ); + button->group()->setExclusive(wasExclusive); button->setFocus(); } emit changed( pageNumber );