Speed up inserting many items in sorted wxChoice in wxQt

Only sort the combobox once instead of doing it for every item.

See https://github.com/wxWidgets/wxWidgets/pull/1054
This commit is contained in:
Vadim Zeitlin 2018-12-13 15:17:18 +01:00
parent 89e4ee1ec0
commit 013c6a6b6a

View File

@ -141,7 +141,28 @@ int wxChoice::DoInsertItems(const wxArrayStringsAdapter & items,
wxClientDataType type)
{
InvalidateBestSize();
// Hack: to avoid resorting the model many times in DoInsertOneItem(),
// which will be called for each item from DoInsertItemsInLoop(), reset the
// wxCB_SORT style if we have it temporarily and only sort once at the end.
bool wasSorted = false;
if ( IsSorted() )
{
wasSorted = true;
ToggleWindowStyle(wxCB_SORT);
}
int n = DoInsertItemsInLoop(items, pos, clientData, type);
if ( wasSorted )
{
// Restore the flag turned off above.
ToggleWindowStyle(wxCB_SORT);
// And actually sort items now.
m_qtComboBox->model()->sort(0);
}
return n;
}