From fd8248762ea87972f846351fc6131e1cfda75927 Mon Sep 17 00:00:00 2001 From: Liam Treacy Date: Thu, 6 Dec 2018 14:42:50 +0000 Subject: [PATCH 1/3] Add support for wxLB_SORT to wxListBox in wxQt --- src/qt/listbox.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/qt/listbox.cpp b/src/qt/listbox.cpp index 9723399523..d4b82855be 100644 --- a/src/qt/listbox.cpp +++ b/src/qt/listbox.cpp @@ -89,6 +89,11 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, QListWidgetItem* item; m_qtWindow = m_qtListWidget = new wxQtListWidget( parent, this ); + if ( style == wxLB_SORT ) + { + m_qtListWidget->setSortingEnabled(true); + } + while ( n-- > 0 ) { item = new QListWidgetItem(); From 1f0e456620fd5f0dff7d2ef2c6ab9c144ca4950e Mon Sep 17 00:00:00 2001 From: Liam Treacy Date: Thu, 6 Dec 2018 14:42:50 +0000 Subject: [PATCH 2/3] Implement wxListBox::GetSelections() in wxQt --- src/qt/listbox.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/qt/listbox.cpp b/src/qt/listbox.cpp index d4b82855be..2fa3647bfd 100644 --- a/src/qt/listbox.cpp +++ b/src/qt/listbox.cpp @@ -135,9 +135,17 @@ bool wxListBox::IsSelected(int n) const return item->isSelected(); } -int wxListBox::GetSelections(wxArrayInt& WXUNUSED(aSelections)) const +int wxListBox::GetSelections(wxArrayInt& aSelections) const { - return 0; + aSelections.clear(); + + for ( unsigned int i = 0; i < GetCount(); ++i) + { + if ( IsSelected(i) ) + aSelections.push_back(i); + } + + return aSelections.size(); } unsigned wxListBox::GetCount() const From 10381cb94e420175ca6874d570d28e6d9de96881 Mon Sep 17 00:00:00 2001 From: Liam Treacy Date: Thu, 6 Dec 2018 14:42:50 +0000 Subject: [PATCH 3/3] Deselect all items in wxQt wxListBox::SetSelection(wxNOT_FOUND) Follow wxWidgets API convention in wxQt too. --- include/wx/qt/listbox.h | 2 ++ src/qt/listbox.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/wx/qt/listbox.h b/include/wx/qt/listbox.h index dc0c761c65..e0086cda58 100644 --- a/include/wx/qt/listbox.h +++ b/include/wx/qt/listbox.h @@ -90,6 +90,8 @@ protected: private: virtual void Init(); //common construction + void UnSelectAll(); + wxDECLARE_DYNAMIC_CLASS(wxListBox); }; diff --git a/src/qt/listbox.cpp b/src/qt/listbox.cpp index 2fa3647bfd..0a6382cca3 100644 --- a/src/qt/listbox.cpp +++ b/src/qt/listbox.cpp @@ -182,6 +182,12 @@ void wxListBox::DoSetFirstItem(int WXUNUSED(n)) void wxListBox::DoSetSelection(int n, bool select) { + if ( n == wxNOT_FOUND ) + { + UnSelectAll(); + return; + } + return m_qtListWidget->setCurrentRow(n, select ? QItemSelectionModel::Select : QItemSelectionModel::Deselect ); } @@ -248,3 +254,12 @@ QScrollArea *wxListBox::QtGetScrollBarsContainer() const { return (QScrollArea *) m_qtListWidget; } + +void wxListBox::UnSelectAll() +{ + for ( unsigned int i = 0; i < GetCount(); ++i ) + { + if ( IsSelected(i) ) + DoSetSelection(i, false); + } +}