Search code examples
wxwidgets

wxDataViewListCtrl is slow with 100k items from another thread


The requirements:

  1. 100k lines
  2. One of the columns is not text - its custom painted with wxDC*.
  3. The items addition is coming from another thread using wxThreadEvent.
  • Up until now I used wxDataViewListCtrl, but it takes too long to AppendItem 100 thousand time.
  • wxListCtrl (in virtual mode) does not have the ability to use wxDC* - please correct me if I am wrong.

The only thing I can think of is using wxDataViewCtrl + wxDataViewModel. But I can't understand how to add items.

I looked at the samples (https://github.com/wxWidgets/wxWidgets/tree/WX_3_0_BRANCH/samples/dataview), too complex for me. I cant understand them.

I looked at the wiki (https://wiki.wxwidgets.org/WxDataViewCtrl), also too complex for me.

Can somebody please provide a very simple example of a wxDataViewCtrl + wxDataViewModel with one string column and one wxDC* column.

Thanks in advance.

P.S.

Per @HajoKirchhoff's request in the comments, I am posting some code:

// This is called from Rust 100k times.
extern "C" void Add_line_to_data_view_list_control(unsigned int index,
                                                   const char* date,
                                                   const char* sha1) {
    wxThreadEvent evt(wxEVT_THREAD, 44);
    evt.SetPayload(ViewListLine{index, std::string(date), std::string(sha1)});
    wxQueueEvent(g_this, evt.Clone());
}

void TreeWidget::Add_line_to_data_view_list_control(wxThreadEvent& event) {
    ViewListLine view_list_line = event.GetPayload<ViewListLine>();

    wxVector<wxVariant> item;

    item.push_back(wxVariant(static_cast<int>(view_list_line.index)));
    item.push_back(wxVariant(view_list_line.date));
    item.push_back(wxVariant(view_list_line.sha1));

    AppendItem(item);
}


Solution

  • Thank you every one who replied!

    @Vz.'s words "If you have any concrete questions, you should ask them" got me thinking and I took another look at the samples of wxWidgets. The full code can be found here. Look at the following classes:

    1. TreeDataViewModel
    2. TreeWidget
    3. TreeCustomRenderer