From 38c522307525fede674a2ff463cafdf02b1201d8 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Wed, 22 Feb 2023 21:48:35 +0100 Subject: [PATCH] Fixed register groups sliders being offset when a new register group was inserted --- dmxcontroller.h | 2 ++ registergroupsmodel.cpp | 32 ++++++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/dmxcontroller.h b/dmxcontroller.h index 1160874..21a7b39 100644 --- a/dmxcontroller.h +++ b/dmxcontroller.h @@ -26,6 +26,8 @@ public: Q_INVOKABLE bool saveProject(const QUrl &url); Q_INVOKABLE void setRegisterGroupSlider(int registerGroupId, quint8 value); + std::vector ®isterGroupStates() { return m_registerGroupStates; } + const std::vector ®isterGroupStates() const { return m_registerGroupStates; } LightProject &lightProject() { return m_lightProject; } const LightProject &lightProject() const { return m_lightProject; } diff --git a/registergroupsmodel.cpp b/registergroupsmodel.cpp index b3be657..750ea65 100644 --- a/registergroupsmodel.cpp +++ b/registergroupsmodel.cpp @@ -241,9 +241,18 @@ bool RegisterGroupsModel::insertRows(int row, int count, const QModelIndex &pare beginInsertRows({}, row, row+count-1); { QMutexLocker locker{&m_controller->mutex()}; - auto iter = std::begin(registerGroups) + row; - for (auto i = 0; i < count; i++) - iter = registerGroups.insert(iter, RegisterGroupConfig{ .id=id++, .name="" }) + 1; + + { + auto iter = std::begin(registerGroups) + row; + for (auto i = 0; i < count; i++) + iter = registerGroups.insert(iter, RegisterGroupConfig{ .id=id++, .name="" }) + 1; + } + + if (auto ®isterGroupStates = m_controller->registerGroupStates(); registerGroupStates.size() > row) + { + registerGroupStates.insert(std::begin(registerGroupStates) + row, count, {}); +// emit m_controller->registerGroupStatesChanged(registerGroupStates); + } } endInsertRows(); @@ -293,9 +302,20 @@ bool RegisterGroupsModel::removeRows(int row, int count, const QModelIndex &pare beginRemoveRows({}, row, row+count-1); { QMutexLocker locker{&m_controller->mutex()}; - auto begin = std::begin(registerGroups) + row; - auto end = begin + count; - registerGroups.erase(begin, end); + + { + auto begin = std::begin(registerGroups) + row; + auto end = begin + count; + registerGroups.erase(begin, end); + } + + if (auto ®isterGroupStates = m_controller->registerGroupStates(); registerGroupStates.size() > row) + { + auto begin = std::begin(registerGroupStates) + row; + auto end = begin + std::min(count, registerGroupStates.size() - row + count); + registerGroupStates.erase(begin, end); + //emit m_controller->registerGroupStatesChanged(registerGroupStates); + } } endRemoveRows();