| 26 | namespace Gerber { |
| 27 | |
| 28 | ComponentsModel::ComponentsModel(int fileId, QObject* parent) |
| 29 | : QAbstractItemModel(parent) |
| 30 | , rootItem(new ComponentsNode("")) |
| 31 | { |
| 32 | // auto file = App::project()->file<File>(fileId); |
| 33 | // for (auto item : *file->itemGroup(File::Components)) |
| 34 | // scene->addRect(item->boundingRect(), Qt::NoPen, file->color()); |
| 35 | |
| 36 | auto file = App::project()->file<Gerber::File>(fileId); |
| 37 | |
| 38 | using pair = std::pair<int, ComponentsNode*>; |
| 39 | std::map<QString, mvector<pair>> map; |
| 40 | |
| 41 | auto unsorted = new ComponentsNode(GbrObj::tr("unsorted")); |
| 42 | |
| 43 | for (const auto& component : file->components()) { |
| 44 | static constexpr ctll::fixed_string pattern(R"((\D+)(\d+).*)"); // fixed_string("(\\D+)(\\d+).*"); |
| 45 | |
| 46 | auto data { toU16StrView(component.refdes()) }; |
| 47 | |
| 48 | if (auto [whole, c1, c2] = ctre::match<pattern>(data); whole) { |
| 49 | if (map[CtreCapTo(c1)].empty()) |
| 50 | map[CtreCapTo(c1)].emplace_back(-1, new ComponentsNode(CtreCapTo(c1))); |
| 51 | map[CtreCapTo(c1)].emplace_back(CtreCapTo(c2).toInt(), new ComponentsNode(component)); |
| 52 | } else { |
| 53 | unsorted->append(new ComponentsNode(component)); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | for (auto& [key, value] : map) { |
| 58 | std::sort(value.begin(), value.end(), [](const pair& p1, const pair& p2) { return p1.first < p2.first; }); |
| 59 | for (size_t i = 1; i < value.size(); ++i) |
| 60 | value.front().second->append(value[i].second); |
| 61 | rootItem->append(value.front().second); |
| 62 | } |
| 63 | |
| 64 | // auto it = map.begin(); |
| 65 | // while (it != map.end()) { |
| 66 | // std::sort( |
| 67 | // it.value().begin(), |
| 68 | // it.value().end(), |
| 69 | // [](const QPair<int, ComponentsNode*>& p1, const QPair<int, ComponentsNode*>& p2) { |
| 70 | // return p1.first < p2.first; |
| 71 | // }); |
| 72 | // for (int i = 1; i < it.value().size(); ++i) { |
| 73 | // it.value().first().second->append(it.value()[i].second); |
| 74 | // } |
| 75 | // rootItem->append(it.value().first().second); |
| 76 | // ++it; |
| 77 | // } |
| 78 | |
| 79 | if (unsorted->childCount() > 0) |
| 80 | rootItem->append(unsorted); |
| 81 | else |
| 82 | delete unsorted; |
| 83 | } |
| 84 | |
| 85 | ComponentsModel::~ComponentsModel() |
nothing calls this directly
no test coverage detected