Merge branch 'mac-dvc-setselections-performance' of https://github.com/vslavik/wxWidgets
Speed up wxDataViewCtrl::SetSelections() on macOS. See https://github.com/wxWidgets/wxWidgets/pull/2084
This commit is contained in:
@@ -514,6 +514,7 @@ public:
|
|||||||
virtual int GetSelections(wxDataViewItemArray& sel) const;
|
virtual int GetSelections(wxDataViewItemArray& sel) const;
|
||||||
virtual bool IsSelected(const wxDataViewItem& item) const;
|
virtual bool IsSelected(const wxDataViewItem& item) const;
|
||||||
virtual void Select(const wxDataViewItem& item);
|
virtual void Select(const wxDataViewItem& item);
|
||||||
|
virtual void Select(const wxDataViewItemArray& items);
|
||||||
virtual void SelectAll();
|
virtual void SelectAll();
|
||||||
virtual void Unselect(const wxDataViewItem& item);
|
virtual void Unselect(const wxDataViewItem& item);
|
||||||
virtual void UnselectAll();
|
virtual void UnselectAll();
|
||||||
|
@@ -90,6 +90,7 @@ public:
|
|||||||
virtual int GetSelections(wxDataViewItemArray& sel) const = 0; // returns all selected items in the native control
|
virtual int GetSelections(wxDataViewItemArray& sel) const = 0; // returns all selected items in the native control
|
||||||
virtual bool IsSelected (wxDataViewItem const& item) const = 0; // checks if the passed item is selected in the native control
|
virtual bool IsSelected (wxDataViewItem const& item) const = 0; // checks if the passed item is selected in the native control
|
||||||
virtual void Select (wxDataViewItem const& item) = 0; // selects the passed item in the native control
|
virtual void Select (wxDataViewItem const& item) = 0; // selects the passed item in the native control
|
||||||
|
virtual void Select (wxDataViewItemArray const& items) = 0; // selects the passed items in the native control
|
||||||
virtual void SelectAll() = 0; // selects all items in the native control
|
virtual void SelectAll() = 0; // selects all items in the native control
|
||||||
virtual void Unselect (wxDataViewItem const& item) = 0; // unselects the passed item in the native control
|
virtual void Unselect (wxDataViewItem const& item) = 0; // unselects the passed item in the native control
|
||||||
virtual void UnselectAll() = 0; // unselects all items in the native control
|
virtual void UnselectAll() = 0; // unselects all items in the native control
|
||||||
|
@@ -1675,6 +1675,9 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Sets the selection to the array of wxDataViewItems.
|
Sets the selection to the array of wxDataViewItems.
|
||||||
|
|
||||||
|
Note that if @a sel contains any invalid items, they are simply
|
||||||
|
ignored.
|
||||||
*/
|
*/
|
||||||
virtual void SetSelections(const wxDataViewItemArray& sel);
|
virtual void SetSelections(const wxDataViewItemArray& sel);
|
||||||
|
|
||||||
|
@@ -2508,6 +2508,20 @@ void wxCocoaDataViewControl::Select(const wxDataViewItem& item)
|
|||||||
byExtendingSelection:GetDataViewCtrl()->HasFlag(wxDV_MULTIPLE) ? YES : NO];
|
byExtendingSelection:GetDataViewCtrl()->HasFlag(wxDV_MULTIPLE) ? YES : NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxCocoaDataViewControl::Select(const wxDataViewItemArray& items)
|
||||||
|
{
|
||||||
|
NSMutableIndexSet *selection = [[NSMutableIndexSet alloc] init];
|
||||||
|
|
||||||
|
for ( const auto& i: items )
|
||||||
|
{
|
||||||
|
if ( i.IsOk() )
|
||||||
|
[selection addIndex:[m_OutlineView rowForItem:[m_DataSource getDataViewItemFromBuffer:i]]];
|
||||||
|
}
|
||||||
|
|
||||||
|
[m_OutlineView selectRowIndexes:selection byExtendingSelection:NO];
|
||||||
|
[selection release];
|
||||||
|
}
|
||||||
|
|
||||||
void wxCocoaDataViewControl::SelectAll()
|
void wxCocoaDataViewControl::SelectAll()
|
||||||
{
|
{
|
||||||
[m_OutlineView selectAll:m_OutlineView];
|
[m_OutlineView selectAll:m_OutlineView];
|
||||||
|
@@ -647,9 +647,8 @@ void wxDataViewCtrl::SetSelections(wxDataViewItemArray const& sel)
|
|||||||
last_parent = parent;
|
last_parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
// finally select the items:
|
// finally select the items:
|
||||||
for (i=0; i<noOfSelections; ++i)
|
dataViewWidgetPtr->Select(sel);
|
||||||
dataViewWidgetPtr->Select(sel[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDataViewCtrl::Unselect(wxDataViewItem const& item)
|
void wxDataViewCtrl::Unselect(wxDataViewItem const& item)
|
||||||
|
@@ -146,6 +146,30 @@ MultiColumnsDataViewCtrlTestCase::~MultiColumnsDataViewCtrlTestCase()
|
|||||||
// the tests themselves
|
// the tests themselves
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
TEST_CASE_METHOD(MultiSelectDataViewCtrlTestCase,
|
||||||
|
"wxDVC::Selection",
|
||||||
|
"[wxDataViewCtrl][select]")
|
||||||
|
{
|
||||||
|
// Check selection round-trip.
|
||||||
|
wxDataViewItemArray sel;
|
||||||
|
sel.push_back(m_child1);
|
||||||
|
sel.push_back(m_grandchild);
|
||||||
|
REQUIRE_NOTHROW( m_dvc->SetSelections(sel) );
|
||||||
|
|
||||||
|
wxDataViewItemArray sel2;
|
||||||
|
CHECK( m_dvc->GetSelections(sel2) == sel.size() );
|
||||||
|
|
||||||
|
CHECK( sel2 == sel );
|
||||||
|
|
||||||
|
// Invalid items in GetSelections() input are supposed to be just skipped.
|
||||||
|
sel.clear();
|
||||||
|
sel.push_back(wxDataViewItem());
|
||||||
|
REQUIRE_NOTHROW( m_dvc->SetSelections(sel) );
|
||||||
|
|
||||||
|
CHECK( m_dvc->GetSelections(sel2) == 0 );
|
||||||
|
CHECK( sel2.empty() );
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE_METHOD(MultiSelectDataViewCtrlTestCase,
|
TEST_CASE_METHOD(MultiSelectDataViewCtrlTestCase,
|
||||||
"wxDVC::DeleteSelected",
|
"wxDVC::DeleteSelected",
|
||||||
"[wxDataViewCtrl][delete]")
|
"[wxDataViewCtrl][delete]")
|
||||||
|
Reference in New Issue
Block a user