cnjinhao / nana

a modern C++ GUI library
https://nana.acemind.cn
Boost Software License 1.0
2.33k stars 335 forks source link

list copy/paste and sort #125

Closed qPCR4vir closed 8 years ago

qPCR4vir commented 8 years ago

Hi, I'm using the list model. It was simple to set, and is working very fast (tested 50 000 items) but I have two problems: (sorry is long, but trivial)

So... it maybe crazy (we have to many different possibilities!) but maybe we can set four more members (std::funtions) on the header object : to_string(), to_cell, set_value() and comp() each taking a reference to the model object (CProgParam_SondeDesign::targets_comp& - in my case)? It will be very easy to setup, more consistent ....

        list.append_header(   "T Pos",        60);
        list.append_header(   "T Cand",       60);

        list.append_header(   "N Pos",        60);
        list.append_header(   "N Cand",       60);
        list.append_header(   "Targ #",       50);
        list.append_header(   "Targ name",        100);
        list.append_header(   "N Cand",       60);
        list.append_header(   "N Pos",        60);

        list.append_header(   "Num T Hits",       80);
        list.append_header(   "Num Hits OK",      80);

        list.append_header(   "N Pos",        60);
        list.append_header(   "N Cand",       60);
        list.append_header(   "Iterat#",           80);
        list.append_header(   "Targ name",         100);
        list.append_header(   "N Cand",       60);
        list.append_header(   "N Pos",        60);

        list.append_header(   "T Pos",        60);
        list.append_header(   "T Cand",       60);

        auto value_translator = [](const std::vector<nana::listbox::cell>& cells)
        {
            CProgParam_SondeDesign::targets_comp p;
            int i = 0;

            p.before.t_n_pos                 = std::stol(cells[i++].text);      //   "Num T Pos", 
            p.before.t_n_cand                = std::stol(cells[i++].text);      //   "Num T Cand", 

            p.before.target_1_n_cand_pos     = std::stol(cells[i++].text);      //   "Num Pos", 
            p.before.target_1_n_cand         = std::stol(cells[i++].text);      //   "Num Cand", 
            p.target_num                     = std::stol(cells[i++].text);      //   "Targ Num", 
            p.target_1_name                  = cells[i++].text ;                //   "Targ name", 
            p.after.target_1_n_cand          = std::stol(cells[i++].text);      //   "Num Cand", 
            p.after.target_1_n_cand_pos      = std::stol(cells[i++].text);      //   "Num Pos", 

            p.iteration_num                  = std::stol(cells[i++].text);                  //   "Num T Hits",      ????????????????????
            p.iteration_num                  = std::stol(cells[i++].text);                  //   "Num Hits OK",     ????????????????????

            p.before.target_2_n_cand_pos     = std::stol(cells[i++].text);      //   "Num Pos", 
            p.before.target_2_n_cand         = std::stol(cells[i++].text);      //   "Num Cand", 
            p.iteration_num                  = std::stol(cells[i++].text);      //   "Iterat#", 
            p.target_2_name                  = cells[i++].text;                 //   "Targ name", 
            p.after.target_2_n_cand          = std::stol(cells[i++].text);      //   "Num Cand", 
            p.after.target_2_n_cand_pos      = std::stol(cells[i++].text);      //   "Num Pos", 

            p.after.t_n_pos                  = std::stol(cells[i++].text);      //   "Num T Pos", 
            p.after.t_n_cand                 = std::stol(cells[i++].text);      //   "Num T Cand", 

            return p;
        };

        auto cell_translator = [](const CProgParam_SondeDesign::targets_comp& p)
        {
            std::vector<nana::listbox::cell> cells;

            cells.emplace_back(std::to_string(p.before.t_n_pos              ) );
            cells.emplace_back(std::to_string(p.before.t_n_cand             ) );

            cells.emplace_back(std::to_string(p.before.target_1_n_cand_pos  ) );
            cells.emplace_back(std::to_string(p.before.target_1_n_cand      ) );
            cells.emplace_back(std::to_string(p.target_num                  ) );
            cells.emplace_back(              (p.target_1_name               )   );
            cells.emplace_back(std::to_string(p.after.target_1_n_cand       )   );
            cells.emplace_back(std::to_string(p.after.target_1_n_cand_pos   )   );

            cells.emplace_back(std::to_string(p.iteration_num               )   );
            cells.emplace_back(std::to_string(p.iteration_num               )   );

            cells.emplace_back(std::to_string(p.before.target_2_n_cand_pos  )   );
            cells.emplace_back(std::to_string(p.before.target_2_n_cand      )   );
            cells.emplace_back(std::to_string(p.iteration_num               )   );
            cells.emplace_back(              (p.target_2_name               )   );
            cells.emplace_back(std::to_string(p.after.target_2_n_cand       )   );
            cells.emplace_back(std::to_string(p.after.target_2_n_cand_pos   )   );

            cells.emplace_back(std::to_string(p.after.t_n_pos               )   );
            cells.emplace_back(std::to_string(p.after.t_n_cand              )   );

            return cells;
        };

        list.at(0).model<std::recursive_mutex>(std::move(targets_comparitions), value_translator, cell_translator);
cnjinhao commented 8 years ago

The first issue is easy to fix. The second issue need some changes, for example

void set_sort_compare(size_type col,
      std::function<bool(const std::string&, nana::any*, const index_pair& pos1,
                   const std::string&, nana::any*, const index_pair& pos2, 
                                   model_interface * model,
                                   bool reverse)> strick_ordering);

Then by using pos1, pos2, and model pointer, it is possible to acceeing two target_comp objects.

qPCR4vir commented 8 years ago

your fix to 1 - tested, it works... thank you !!

... I see, the second is not trivial... I'm thinking more in the header direction, that keep all the functions we need to managed that "field data". Unfortunately right now I need to move fast ... so I'm implementing a simple workaround (formatting the numbers with left space pad)

qPCR4vir commented 8 years ago

Hi ! Have you plans to merge this (listbox-model branch) into develop? is not that easy...

cnjinhao commented 8 years ago

Hi, I will merge it into develop recently.