diff --git a/devicesmodel.cpp b/devicesmodel.cpp index 5b89204..94229a6 100644 --- a/devicesmodel.cpp +++ b/devicesmodel.cpp @@ -1,5 +1,7 @@ #include "devicesmodel.h" +#include + #include #include @@ -262,8 +264,13 @@ bool DevicesModel::insertRows(int row, int count, const QModelIndex &parent) return false; } + auto max_iter = std::max_element(std::cbegin(lights), std::cend(lights), [](const auto &l, const auto &r){ return l.id < r.id; }); + auto id = max_iter != std::cend(lights) ? max_iter->id + 1 : 0; + beginInsertRows({}, row, row+count-1); - lights.insert(std::begin(lights) + row, count, LightConfig{ .id=99, .name="", .lightTypeId=0, .address=0, .position={} }); + auto iter = std::begin(lights) + row; + for (; count > 0; count--) + iter = lights.insert(iter, LightConfig{ .id=id++, .name="", .lightTypeId=0, .address=0, .position={} }) + 1; endInsertRows(); return true; diff --git a/devicetypesmodel.cpp b/devicetypesmodel.cpp index 551192c..380ae06 100644 --- a/devicetypesmodel.cpp +++ b/devicetypesmodel.cpp @@ -223,8 +223,13 @@ bool DeviceTypesModel::insertRows(int row, int count, const QModelIndex &parent) return false; } + auto max_iter = std::max_element(std::cbegin(lightTypes), std::cend(lightTypes), [](const auto &l, const auto &r){ return l.id < r.id; }); + auto id = max_iter != std::cend(lightTypes) ? max_iter->id + 1 : 0; + beginInsertRows({}, row, row+count-1); - lightTypes.insert(std::begin(lightTypes) + row, count, LightTypeConfig{ .id=99, .name="" }); + auto iter = std::begin(lightTypes) + row; + for (; count > 0; count--) + iter = lightTypes.insert(iter, LightTypeConfig{ .id=id++, .name="" }) + 1; endInsertRows(); return true;