Implemented creating of new light types or lights
This commit is contained in:
@ -20,11 +20,13 @@ ColumnLayout {
|
|||||||
|
|
||||||
model: deviceTypesModel
|
model: deviceTypesModel
|
||||||
|
|
||||||
onAddClicked: (index) => console.log('added', index);
|
onAddClicked: (index) => deviceTypesModel.insertRow(index < 0 ? 0 : index + 1);
|
||||||
onRemoveClicked: (index) => deviceTypesModel.removeRow(index)
|
onRemoveClicked: (index) => deviceTypesModel.removeRow(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
|
enabled: listView.currentIndex !== -1
|
||||||
|
|
||||||
GridLayout {
|
GridLayout {
|
||||||
Layout.preferredWidth: 300
|
Layout.preferredWidth: 300
|
||||||
Layout.maximumWidth: 300
|
Layout.maximumWidth: 300
|
||||||
|
@ -20,11 +20,13 @@ ColumnLayout {
|
|||||||
|
|
||||||
model: devicesModel
|
model: devicesModel
|
||||||
|
|
||||||
onAddClicked: (index) => console.log('added', index)
|
onAddClicked: (index) => devicesModel.insertRow(index < 0 ? 0 : index + 1);
|
||||||
onRemoveClicked: (index) => devicesModel.removeRow(index)
|
onRemoveClicked: (index) => devicesModel.removeRow(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
|
enabled: listView.currentIndex !== -1
|
||||||
|
|
||||||
GridLayout {
|
GridLayout {
|
||||||
Layout.preferredWidth: 300
|
Layout.preferredWidth: 300
|
||||||
Layout.maximumWidth: 300
|
Layout.maximumWidth: 300
|
||||||
|
@ -234,6 +234,41 @@ bool DevicesModel::setData(const QModelIndex &index, const QVariant &value, int
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DevicesModel::insertRows(int row, int count, const QModelIndex &parent)
|
||||||
|
{
|
||||||
|
if (parent.isValid())
|
||||||
|
{
|
||||||
|
qWarning() << "hilfe" << __LINE__;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_controller)
|
||||||
|
{
|
||||||
|
qWarning() << "hilfe" << __LINE__;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto &lights = m_controller->lightProject().lights;
|
||||||
|
|
||||||
|
if (row < 0)
|
||||||
|
{
|
||||||
|
qWarning() << "hilfe" << __LINE__;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (row > lights.size())
|
||||||
|
{
|
||||||
|
qWarning() << "hilfe" << __LINE__;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
beginInsertRows({}, row, row+count-1);
|
||||||
|
lights.insert(std::begin(lights) + row, count, LightConfig{ .id=99, .name="<neu>", .lightTypeId=0, .address=0, .position={} });
|
||||||
|
endInsertRows();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool DevicesModel::removeRows(int row, int count, const QModelIndex &parent)
|
bool DevicesModel::removeRows(int row, int count, const QModelIndex &parent)
|
||||||
{
|
{
|
||||||
if (parent.isValid())
|
if (parent.isValid())
|
||||||
@ -250,6 +285,12 @@ bool DevicesModel::removeRows(int row, int count, const QModelIndex &parent)
|
|||||||
|
|
||||||
auto &lights = m_controller->lightProject().lights;
|
auto &lights = m_controller->lightProject().lights;
|
||||||
|
|
||||||
|
if (row < 0)
|
||||||
|
{
|
||||||
|
qWarning() << "hilfe" << __LINE__;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (row >= lights.size())
|
if (row >= lights.size())
|
||||||
{
|
{
|
||||||
qWarning() << "hilfe" << __LINE__;
|
qWarning() << "hilfe" << __LINE__;
|
||||||
|
@ -25,6 +25,7 @@ public:
|
|||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
||||||
|
bool insertRows(int row, int count, const QModelIndex &parent) override;
|
||||||
bool removeRows(int row, int count, const QModelIndex &parent) override;
|
bool removeRows(int row, int count, const QModelIndex &parent) override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -195,6 +195,41 @@ bool DeviceTypesModel::setData(const QModelIndex &index, const QVariant &value,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DeviceTypesModel::insertRows(int row, int count, const QModelIndex &parent)
|
||||||
|
{
|
||||||
|
if (parent.isValid())
|
||||||
|
{
|
||||||
|
qWarning() << "hilfe" << __LINE__;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_controller)
|
||||||
|
{
|
||||||
|
qWarning() << "hilfe" << __LINE__;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto &lightTypes = m_controller->lightProject().lightTypes;
|
||||||
|
|
||||||
|
if (row < 0)
|
||||||
|
{
|
||||||
|
qWarning() << "hilfe" << __LINE__;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (row > lightTypes.size())
|
||||||
|
{
|
||||||
|
qWarning() << "hilfe" << __LINE__;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
beginInsertRows({}, row, row+count-1);
|
||||||
|
lightTypes.insert(std::begin(lightTypes) + row, count, LightTypeConfig{ .id=99, .name="<neu>" });
|
||||||
|
endInsertRows();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool DeviceTypesModel::removeRows(int row, int count, const QModelIndex &parent)
|
bool DeviceTypesModel::removeRows(int row, int count, const QModelIndex &parent)
|
||||||
{
|
{
|
||||||
if (parent.isValid())
|
if (parent.isValid())
|
||||||
@ -211,6 +246,12 @@ bool DeviceTypesModel::removeRows(int row, int count, const QModelIndex &parent)
|
|||||||
|
|
||||||
auto &lightTypes = m_controller->lightProject().lightTypes;
|
auto &lightTypes = m_controller->lightProject().lightTypes;
|
||||||
|
|
||||||
|
if (row < 0)
|
||||||
|
{
|
||||||
|
qWarning() << "hilfe" << __LINE__;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (row >= lightTypes.size())
|
if (row >= lightTypes.size())
|
||||||
{
|
{
|
||||||
qWarning() << "hilfe" << __LINE__;
|
qWarning() << "hilfe" << __LINE__;
|
||||||
|
@ -25,6 +25,7 @@ public:
|
|||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
||||||
|
bool insertRows(int row, int count, const QModelIndex &parent) override;
|
||||||
bool removeRows(int row, int count, const QModelIndex &parent) override;
|
bool removeRows(int row, int count, const QModelIndex &parent) override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
Reference in New Issue
Block a user