From d411c3159cc3052ba521748a0c926d3c6dc38309 Mon Sep 17 00:00:00 2001 From: Graham Dawes Date: Fri, 11 Jan 2019 11:37:24 +0000 Subject: [PATCH 1/5] Replace template that is only ever instantiated with one type --- src/qt/radiobox.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/qt/radiobox.cpp b/src/qt/radiobox.cpp index b2093e3596..55ceb2403d 100644 --- a/src/qt/radiobox.cpp +++ b/src/qt/radiobox.cpp @@ -110,17 +110,14 @@ bool wxRadioBox::Create(wxWindow *parent, } -template < typename Button > static void AddChoices( QButtonGroup *qtButtonGroup, QBoxLayout *qtBoxLayout, int count, const wxString choices[] ) { - Button *btn; bool isFirst = true; - int id = 0; while ( count-- > 0 ) { - btn = new Button( wxQtConvertString( *choices++ )); + QRadioButton *btn = new QRadioButton( wxQtConvertString( *choices++ )); qtButtonGroup->addButton( btn, id++ ); qtBoxLayout->addWidget( btn ); @@ -160,7 +157,7 @@ bool wxRadioBox::Create(wxWindow *parent, else if ( style & wxRA_SPECIFY_ROWS ) m_qtBoxLayout = new QVBoxLayout; - AddChoices< QRadioButton >( m_qtButtonGroup, m_qtBoxLayout, n, choices ); + AddChoices( m_qtButtonGroup, m_qtBoxLayout, n, choices ); m_qtBoxLayout->addStretch(1); m_qtGroupBox->setLayout(m_qtBoxLayout); From 12d4ed3e8c16bc5337c6a487f313f9014dabbd47 Mon Sep 17 00:00:00 2001 From: Graham Dawes Date: Fri, 11 Jan 2019 11:55:42 +0000 Subject: [PATCH 2/5] Collapse 2 loop dependent variables into a single variable --- src/qt/radiobox.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/qt/radiobox.cpp b/src/qt/radiobox.cpp index 55ceb2403d..7958639d67 100644 --- a/src/qt/radiobox.cpp +++ b/src/qt/radiobox.cpp @@ -113,12 +113,11 @@ bool wxRadioBox::Create(wxWindow *parent, static void AddChoices( QButtonGroup *qtButtonGroup, QBoxLayout *qtBoxLayout, int count, const wxString choices[] ) { bool isFirst = true; - int id = 0; - while ( count-- > 0 ) + for (int i = 0; i < count; ++i ) { - QRadioButton *btn = new QRadioButton( wxQtConvertString( *choices++ )); - qtButtonGroup->addButton( btn, id++ ); + QRadioButton *btn = new QRadioButton( wxQtConvertString( choices[i] )); + qtButtonGroup->addButton( btn, i ); qtBoxLayout->addWidget( btn ); if ( isFirst ) From 4f32cfc5fbae5b218f0ab461c953e5680dbdd7ed Mon Sep 17 00:00:00 2001 From: Graham Dawes Date: Fri, 11 Jan 2019 14:39:54 +0000 Subject: [PATCH 3/5] Add support for grid layout in wxRadioBox under wxQT --- include/wx/qt/radiobox.h | 4 +-- src/qt/radiobox.cpp | 57 ++++++++++++++++++++++++++-------------- 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/include/wx/qt/radiobox.h b/include/wx/qt/radiobox.h index 679298b83b..a3149e25e6 100644 --- a/include/wx/qt/radiobox.h +++ b/include/wx/qt/radiobox.h @@ -10,7 +10,7 @@ class QGroupBox; class QButtonGroup; -class QBoxLayout; +class QGridLayout; class WXDLLIMPEXP_CORE wxRadioBox : public wxControl, public wxRadioBoxBase { @@ -89,7 +89,7 @@ private: QButtonGroup *m_qtButtonGroup; // Autofit layout for buttons (either vert. or horiz.): - QBoxLayout *m_qtBoxLayout; + QGridLayout *m_qtGridLayout; wxDECLARE_DYNAMIC_CLASS(wxRadioBox); }; diff --git a/src/qt/radiobox.cpp b/src/qt/radiobox.cpp index 7958639d67..2282f199b3 100644 --- a/src/qt/radiobox.cpp +++ b/src/qt/radiobox.cpp @@ -59,7 +59,7 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl); wxRadioBox::wxRadioBox() : m_qtGroupBox(NULL), m_qtButtonGroup(NULL), - m_qtBoxLayout(NULL) + m_qtGridLayout(NULL) { } @@ -110,19 +110,46 @@ bool wxRadioBox::Create(wxWindow *parent, } -static void AddChoices( QButtonGroup *qtButtonGroup, QBoxLayout *qtBoxLayout, int count, const wxString choices[] ) +static void AddChoices( QButtonGroup *qtButtonGroup, QGridLayout *qtGridLayout, int count, const wxString choices[], int style, int majorDim ) { + if ( count <= 0 ) + return; + + // wxRA_SPECIFY_COLS means that we arrange buttons in + // left to right order and GetMajorDim() is the number of columns while + // wxRA_SPECIFY_ROWS means that the buttons are arranged top to bottom and + // GetMajorDim() is the number of rows. + + const bool columnMajor = style & wxRA_SPECIFY_COLS; + const int numMajor = majorDim > 0 ? majorDim : count; + bool isFirst = true; - for (int i = 0; i < count; ++i ) + for ( int i = 0; i < count; ++i ) { - QRadioButton *btn = new QRadioButton( wxQtConvertString( choices[i] )); + QRadioButton *btn = new QRadioButton(wxQtConvertString (choices[i]) ); qtButtonGroup->addButton( btn, i ); - qtBoxLayout->addWidget( btn ); - if ( isFirst ) + int row; + int col; + + if (columnMajor) { - btn->setChecked(true); + col = i % numMajor; + row = i / numMajor; + + } + else + { + col = i / numMajor; + row = i % numMajor; + } + + qtGridLayout->addWidget( btn, row, col ); + + if (isFirst) + { + btn->setChecked( true ); isFirst = false; } } @@ -135,7 +162,7 @@ bool wxRadioBox::Create(wxWindow *parent, const wxPoint& pos, const wxSize& size, int n, const wxString choices[], - int WXUNUSED(majorDim), + int majorDim, long style, const wxValidator& val, const wxString& name) @@ -147,18 +174,10 @@ bool wxRadioBox::Create(wxWindow *parent, if ( !(style & (wxRA_SPECIFY_ROWS | wxRA_SPECIFY_COLS)) ) style |= wxRA_SPECIFY_COLS; - // wxRA_SPECIFY_COLS means that we arrange buttons in - // left to right order and GetMajorDim() is the number of columns while - // wxRA_SPECIFY_ROWS means that the buttons are arranged top to bottom and - // GetMajorDim() is the number of rows. - if ( style & wxRA_SPECIFY_COLS ) - m_qtBoxLayout = new QHBoxLayout; - else if ( style & wxRA_SPECIFY_ROWS ) - m_qtBoxLayout = new QVBoxLayout; + m_qtGridLayout = new QGridLayout; - AddChoices( m_qtButtonGroup, m_qtBoxLayout, n, choices ); - m_qtBoxLayout->addStretch(1); - m_qtGroupBox->setLayout(m_qtBoxLayout); + AddChoices( m_qtButtonGroup, m_qtGridLayout, n, choices, style, majorDim ); + m_qtGroupBox->setLayout(m_qtGridLayout); return QtCreateControl( parent, id, pos, size, style, val, name ); } From a823236ac16fefc88d4770b4769b42d0b9d60fa7 Mon Sep 17 00:00:00 2001 From: Graham Dawes Date: Fri, 11 Jan 2019 15:02:41 +0000 Subject: [PATCH 4/5] Improve layout of wxRadioBox under wxQT --- src/qt/radiobox.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/qt/radiobox.cpp b/src/qt/radiobox.cpp index 2282f199b3..17cc6a0b0a 100644 --- a/src/qt/radiobox.cpp +++ b/src/qt/radiobox.cpp @@ -177,7 +177,12 @@ bool wxRadioBox::Create(wxWindow *parent, m_qtGridLayout = new QGridLayout; AddChoices( m_qtButtonGroup, m_qtGridLayout, n, choices, style, majorDim ); - m_qtGroupBox->setLayout(m_qtGridLayout); + + QVBoxLayout *qtBoxLayout = new QVBoxLayout; + qtBoxLayout->addLayout(m_qtGridLayout); + qtBoxLayout->addStretch(); + + m_qtGroupBox->setLayout(qtBoxLayout); return QtCreateControl( parent, id, pos, size, style, val, name ); } From 4a18bc897d29cfa000ab642c8ed8f036f3461d8d Mon Sep 17 00:00:00 2001 From: Graham Dawes Date: Mon, 14 Jan 2019 08:06:34 +0000 Subject: [PATCH 5/5] Improve layout of radioboxes in horizontal sizers with expand flag under wxQT --- src/qt/radiobox.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/qt/radiobox.cpp b/src/qt/radiobox.cpp index 17cc6a0b0a..b73a881a78 100644 --- a/src/qt/radiobox.cpp +++ b/src/qt/radiobox.cpp @@ -178,11 +178,15 @@ bool wxRadioBox::Create(wxWindow *parent, AddChoices( m_qtButtonGroup, m_qtGridLayout, n, choices, style, majorDim ); - QVBoxLayout *qtBoxLayout = new QVBoxLayout; - qtBoxLayout->addLayout(m_qtGridLayout); - qtBoxLayout->addStretch(); + QVBoxLayout *vertLayout = new QVBoxLayout; + vertLayout->addLayout(m_qtGridLayout); + vertLayout->addStretch(); - m_qtGroupBox->setLayout(qtBoxLayout); + QHBoxLayout *horzLayout = new QHBoxLayout; + horzLayout->addLayout(vertLayout); + horzLayout->addStretch(); + + m_qtGroupBox->setLayout(horzLayout); return QtCreateControl( parent, id, pos, size, style, val, name ); }