Automatic id incrementation
This commit is contained in:
@ -1,5 +1,7 @@
|
|||||||
#include "devicesmodel.h"
|
#include "devicesmodel.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QQmlEngine>
|
#include <QQmlEngine>
|
||||||
|
|
||||||
@ -262,8 +264,13 @@ bool DevicesModel::insertRows(int row, int count, const QModelIndex &parent)
|
|||||||
return false;
|
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);
|
beginInsertRows({}, row, row+count-1);
|
||||||
lights.insert(std::begin(lights) + row, count, LightConfig{ .id=99, .name="<neu>", .lightTypeId=0, .address=0, .position={} });
|
auto iter = std::begin(lights) + row;
|
||||||
|
for (; count > 0; count--)
|
||||||
|
iter = lights.insert(iter, LightConfig{ .id=id++, .name="<neu>", .lightTypeId=0, .address=0, .position={} }) + 1;
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -223,8 +223,13 @@ bool DeviceTypesModel::insertRows(int row, int count, const QModelIndex &parent)
|
|||||||
return false;
|
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);
|
beginInsertRows({}, row, row+count-1);
|
||||||
lightTypes.insert(std::begin(lightTypes) + row, count, LightTypeConfig{ .id=99, .name="<neu>" });
|
auto iter = std::begin(lightTypes) + row;
|
||||||
|
for (; count > 0; count--)
|
||||||
|
iter = lightTypes.insert(iter, LightTypeConfig{ .id=id++, .name="<neu>" }) + 1;
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user