mirror of
https://github.com/wxWidgets/wxWidgets.git
synced 2026-09-23 06:33:59 +08:00
Fix losing text of generic wxListCtrl items when copying them
During the switch from copy to move ctor of wxListCtrl in a5777cdcbd
(Make wxListItemData movable and not copyable, 2023-01-19) copying the
item text was simply lost, resulting in items forgetting their text when
they were moved internally by the vector in which they are stored, which
could result in e.g. their text becoming empty when a new column was
appended.
Fix this by adding the missing text (and also image and user data) field
to the move ctor and move assignment operator.
Closes #25519.
This commit is contained in:
@@ -96,9 +96,11 @@ static const int MARGIN_AROUND_CHECKBOX = 5;
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxListItemData::wxListItemData(wxListItemData&& other)
|
||||
: m_image(other.m_image),
|
||||
m_data(other.m_data),
|
||||
m_owner(other.m_owner),
|
||||
m_text(std::move(other.m_text))
|
||||
{
|
||||
m_owner = other.m_owner;
|
||||
|
||||
// Take ownership of the pointers from the other object and reset them.
|
||||
std::swap(m_attr, other.m_attr);
|
||||
std::swap(m_rect, other.m_rect);
|
||||
@@ -109,6 +111,7 @@ wxListItemData& wxListItemData::operator=(wxListItemData&& other)
|
||||
m_image = other.m_image;
|
||||
m_data = other.m_data;
|
||||
m_owner = other.m_owner;
|
||||
m_text = std::move(other.m_text);
|
||||
|
||||
// Swap them to let our pointers be deleted by the other object if necessary.
|
||||
std::swap(m_attr, other.m_attr);
|
||||
|
||||
@@ -105,4 +105,19 @@ TEST_CASE_METHOD(ListViewTestCase, "ListView::Focus", "[listctrl][listview]")
|
||||
CHECK( m_list->GetFocusedItem() == 0 );
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(ListViewTestCase, "ListView::AppendColumn", "[listctrl][listview]")
|
||||
{
|
||||
m_list->AppendColumn("Column 0");
|
||||
m_list->AppendColumn("Column 1");
|
||||
|
||||
m_list->InsertItem(0, "First item");
|
||||
m_list->SetItem(0, 1, "First subitem");
|
||||
|
||||
// Appending a column shouldn't change the existing items.
|
||||
m_list->AppendColumn("Column 2");
|
||||
|
||||
CHECK( m_list->GetItemText(0) == "First item" );
|
||||
CHECK( m_list->GetItemText(0, 1) == "First subitem" );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user