Fix enabling radiobox buttons in wxQt

If a QGroupBox is disabled, then you cannot set any of its items to be
enabled without first enabling it. Enabling/disabling it will set that
value (true/false) on all of its items, although setting the QGroupBox
to an enabled state which it already has does not result in this
behaviour.

Fix wxQt to match the expected wxRadioBox behaviour and allow the unit
test to pass.

Closes https://github.com/wxWidgets/wxWidgets/pull/1064
This commit is contained in:
Liam Treacy
2018-12-10 11:23:50 +00:00
committed by Vadim Zeitlin
parent 91a87e765b
commit 2a64b65149
2 changed files with 40 additions and 7 deletions

View File

@@ -65,10 +65,11 @@ public:
using wxWindowBase::Enable;
using wxRadioBoxBase::GetDefaultBorder;
virtual bool Enable(unsigned int n, bool enable = true);
virtual bool Show(unsigned int n, bool show = true);
virtual bool IsItemEnabled(unsigned int n) const;
virtual bool IsItemShown(unsigned int n) const;
virtual bool Enable(unsigned int n, bool enable = true) wxOVERRIDE;
virtual bool Enable(bool enable = true) wxOVERRIDE;
virtual bool Show(unsigned int n, bool show = true) wxOVERRIDE;
virtual bool IsItemEnabled(unsigned int n) const wxOVERRIDE;
virtual bool IsItemShown(unsigned int n) const wxOVERRIDE;
virtual unsigned int GetCount() const;
virtual wxString GetString(unsigned int n) const;

View File

@@ -168,10 +168,42 @@ static QAbstractButton *GetButtonAt( const QButtonGroup *group, unsigned int n )
bool wxRadioBox::Enable(unsigned int n, bool enable)
{
QAbstractButton *qtButton = GetButtonAt( m_qtButtonGroup, n );
CHECK_BUTTON( qtButton, false );
if ( enable && !m_qtGroupBox->isEnabled() )
{
m_qtGroupBox->setEnabled( true );
for ( unsigned int i = 0; i < GetCount(); ++i )
{
QAbstractButton *qtButton = GetButtonAt( m_qtButtonGroup, i );
CHECK_BUTTON( qtButton, false );
qtButton->setEnabled( i == n );
}
}
else
{
QAbstractButton *qtButton = GetButtonAt( m_qtButtonGroup, n );
CHECK_BUTTON( qtButton, false );
qtButton->setEnabled(enable);
}
return true;
}
bool wxRadioBox::Enable( bool enable )
{
if ( m_qtGroupBox->isEnabled() == enable )
{
for ( unsigned int i = 0; i < GetCount(); ++i )
{
QAbstractButton *qtButton = GetButtonAt( m_qtButtonGroup, i );
CHECK_BUTTON( qtButton, false );
qtButton->setEnabled( enable );
}
}
m_qtGroupBox->setEnabled( enable );
qtButton->setEnabled( enable );
return true;
}