Reuse code between wxListBox::Create() overloads

Add DoCreate() helper to actually create and initialize QListWidget.
This commit is contained in:
Vadim Zeitlin 2019-01-21 23:43:03 +01:00
parent a2356fbe4a
commit c8f427181e
2 changed files with 12 additions and 10 deletions

View File

@ -90,7 +90,9 @@ protected:
private: private:
virtual void Init(); //common construction virtual void Init(); //common construction
void setStyle(long style); // Common part of both Create() overloads.
void DoCreate(wxWindow* parent, long style);
void UnSelectAll(); void UnSelectAll();
wxDECLARE_DYNAMIC_CLASS(wxListBox); wxDECLARE_DYNAMIC_CLASS(wxListBox);

View File

@ -86,11 +86,9 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id,
const wxValidator& validator, const wxValidator& validator,
const wxString& name) const wxString& name)
{ {
Init(); DoCreate(parent, style);
QListWidgetItem* item;
m_qtWindow = m_qtListWidget = new wxQtListWidget( parent, this );
setStyle(style); QListWidgetItem* item;
while ( n-- > 0 ) while ( n-- > 0 )
{ {
@ -114,10 +112,7 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id,
const wxValidator& validator, const wxValidator& validator,
const wxString& name) const wxString& name)
{ {
Init(); DoCreate(parent, style);
m_qtWindow = m_qtListWidget = new wxQtListWidget( parent, this );
setStyle(style);
QStringList items; QStringList items;
@ -129,8 +124,13 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id,
return wxListBoxBase::Create( parent, id, pos, size, style, validator, name ); return wxListBoxBase::Create( parent, id, pos, size, style, validator, name );
} }
void wxListBox::setStyle(long style) void wxListBox::DoCreate(wxWindow* parent, long style)
{ {
Init();
m_qtWindow =
m_qtListWidget = new wxQtListWidget( parent, this );
if ( style & wxLB_SORT ) if ( style & wxLB_SORT )
{ {
m_qtListWidget->setSortingEnabled(true); m_qtListWidget->setSortingEnabled(true);