Merge branch 'qt_listbox_failing_tests'
Fixes for item selection and cleanup. See https://github.com/wxWidgets/wxWidgets/pull/1159
This commit is contained in:
@@ -49,8 +49,8 @@ public:
|
||||
const wxValidator& validator = wxDefaultValidator,
|
||||
const wxString& name = wxListBoxNameStr);
|
||||
|
||||
virtual bool IsSelected(int n) const;
|
||||
virtual int GetSelections(wxArrayInt& aSelections) const;
|
||||
virtual bool IsSelected(int n) const wxOVERRIDE;
|
||||
virtual int GetSelections(wxArrayInt& aSelections) const wxOVERRIDE;
|
||||
|
||||
virtual unsigned int GetCount() const;
|
||||
virtual wxString GetString(unsigned int n) const;
|
||||
@@ -63,9 +63,9 @@ public:
|
||||
void QtSendEvent(wxEventType evtType, const QModelIndex &index, bool selected);
|
||||
|
||||
protected:
|
||||
virtual void DoSetFirstItem(int n);
|
||||
virtual void DoSetFirstItem(int n) wxOVERRIDE;
|
||||
|
||||
virtual void DoSetSelection(int n, bool select);
|
||||
virtual void DoSetSelection(int n, bool select) wxOVERRIDE;
|
||||
|
||||
virtual int DoInsertItems(const wxArrayStringsAdapter & items,
|
||||
unsigned int pos,
|
||||
@@ -90,6 +90,9 @@ protected:
|
||||
private:
|
||||
virtual void Init(); //common construction
|
||||
|
||||
// Common part of both Create() overloads.
|
||||
void DoCreate(wxWindow* parent, long style);
|
||||
|
||||
void UnSelectAll();
|
||||
|
||||
wxDECLARE_DYNAMIC_CLASS(wxListBox);
|
||||
|
@@ -86,14 +86,9 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id,
|
||||
const wxValidator& validator,
|
||||
const wxString& name)
|
||||
{
|
||||
Init();
|
||||
QListWidgetItem* item;
|
||||
m_qtWindow = m_qtListWidget = new wxQtListWidget( parent, this );
|
||||
DoCreate(parent, style);
|
||||
|
||||
if ( style == wxLB_SORT )
|
||||
{
|
||||
m_qtListWidget->setSortingEnabled(true);
|
||||
}
|
||||
QListWidgetItem* item;
|
||||
|
||||
while ( n-- > 0 )
|
||||
{
|
||||
@@ -117,8 +112,7 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id,
|
||||
const wxValidator& validator,
|
||||
const wxString& name)
|
||||
{
|
||||
Init();
|
||||
m_qtWindow = m_qtListWidget = new wxQtListWidget( parent, this );
|
||||
DoCreate(parent, style);
|
||||
|
||||
QStringList items;
|
||||
|
||||
@@ -130,6 +124,33 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id,
|
||||
return wxListBoxBase::Create( parent, id, pos, size, style, validator, name );
|
||||
}
|
||||
|
||||
void wxListBox::DoCreate(wxWindow* parent, long style)
|
||||
{
|
||||
Init();
|
||||
|
||||
m_qtWindow =
|
||||
m_qtListWidget = new wxQtListWidget( parent, this );
|
||||
|
||||
if ( style & wxLB_SORT )
|
||||
{
|
||||
m_qtListWidget->setSortingEnabled(true);
|
||||
}
|
||||
|
||||
// The following styles are mutually exclusive
|
||||
if ( style & wxLB_SINGLE )
|
||||
{
|
||||
m_qtListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
}
|
||||
else if ( style & wxLB_MULTIPLE )
|
||||
{
|
||||
m_qtListWidget->setSelectionMode(QAbstractItemView::MultiSelection);
|
||||
}
|
||||
else if ( style & wxLB_EXTENDED )
|
||||
{
|
||||
wxMISSING_IMPLEMENTATION( wxSTRINGIZE( wxLB_EXTENDED ));
|
||||
}
|
||||
}
|
||||
|
||||
void wxListBox::Init()
|
||||
{
|
||||
#if wxUSE_CHECKLISTBOX
|
||||
@@ -147,10 +168,9 @@ int wxListBox::GetSelections(wxArrayInt& aSelections) const
|
||||
{
|
||||
aSelections.clear();
|
||||
|
||||
for ( unsigned int i = 0; i < GetCount(); ++i)
|
||||
Q_FOREACH(QListWidgetItem* l, m_qtListWidget->selectedItems())
|
||||
{
|
||||
if ( IsSelected(i) )
|
||||
aSelections.push_back(i);
|
||||
aSelections.push_back( m_qtListWidget->row(l) );
|
||||
}
|
||||
|
||||
return aSelections.size();
|
||||
@@ -182,7 +202,15 @@ void wxListBox::SetString(unsigned int n, const wxString& s)
|
||||
|
||||
int wxListBox::GetSelection() const
|
||||
{
|
||||
return m_qtListWidget->currentIndex().row();
|
||||
if ( m_qtListWidget->selectedItems().empty() )
|
||||
{
|
||||
return wxNOT_FOUND;
|
||||
}
|
||||
|
||||
|
||||
QListWidgetItem* item = m_qtListWidget->selectedItems().first();
|
||||
|
||||
return m_qtListWidget->row(item);
|
||||
}
|
||||
|
||||
void wxListBox::DoSetFirstItem(int WXUNUSED(n))
|
||||
@@ -197,7 +225,7 @@ void wxListBox::DoSetSelection(int n, bool select)
|
||||
return;
|
||||
}
|
||||
|
||||
return m_qtListWidget->setCurrentRow(n, select ? QItemSelectionModel::Select : QItemSelectionModel::Deselect );
|
||||
m_qtListWidget->setItemSelected( m_qtListWidget->item(n), select);
|
||||
}
|
||||
|
||||
int wxListBox::DoInsertItems(const wxArrayStringsAdapter & items,
|
||||
@@ -266,9 +294,8 @@ QScrollArea *wxListBox::QtGetScrollBarsContainer() const
|
||||
|
||||
void wxListBox::UnSelectAll()
|
||||
{
|
||||
for ( unsigned int i = 0; i < GetCount(); ++i )
|
||||
Q_FOREACH(QListWidgetItem* l, m_qtListWidget->selectedItems())
|
||||
{
|
||||
if ( IsSelected(i) )
|
||||
DoSetSelection(i, false);
|
||||
m_qtListWidget->setItemSelected( l, false );
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user