From 3e19e0f5d1e52444a670cf7c921044437f98b54d Mon Sep 17 00:00:00 2001 From: gvnnz Date: Fri, 24 May 2024 21:26:09 +0200 Subject: [PATCH] Add 'index' property to v::Model::Column --- src/glue/channel.cpp | 4 ++-- src/gui/model.cpp | 25 +++++++------------------ src/gui/model.h | 2 +- 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/glue/channel.cpp b/src/glue/channel.cpp index 0d6f65612..15737e74e 100644 --- a/src/glue/channel.cpp +++ b/src/glue/channel.cpp @@ -70,7 +70,7 @@ void printLoadError_(int res) Data makeData_(ID channelId, const v::Model::Column& column) { const int position = column.getChannelIndex(channelId); - const int columnIndex = g_ui->model.columns.getColumnIndex(column); + const int columnIndex = column.index; return Data(g_engine->getChannelsApi().get(channelId), columnIndex, position); } @@ -78,7 +78,7 @@ Data makeData_(ID channelId, const v::Model::Column& column) Column makeColumn_(const v::Model::Column& modelColumn) { - Column column{g_ui->model.columns.getColumnIndex(modelColumn), modelColumn.width, {}}; + Column column{modelColumn.index, modelColumn.width, {}}; for (const ID channelId : modelColumn.channels) column.channels.push_back(makeData_(channelId, g_ui->model.columns.getColumnByChannelId(channelId))); diff --git a/src/gui/model.cpp b/src/gui/model.cpp index fb7f0714f..e5b598a11 100644 --- a/src/gui/model.cpp +++ b/src/gui/model.cpp @@ -40,20 +40,6 @@ int Model::Column::getChannelIndex(ID channelId) const /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int Model::Columns::getColumnIndex(const Column& target) const -{ - for (int i = 0; const Column& column : m_columns) - { - if (&target == &column) - return i; - i++; - } - assert(false); - return -1; -} - -/* -------------------------------------------------------------------------- */ - const std::vector& Model::Columns::getAll() const { @@ -85,7 +71,10 @@ Model::Column& Model::Columns::getColumnByChannelId(ID channelId) void Model::Columns::addDefaultColumn() { - addColumn({G_DEFAULT_COLUMN_WIDTH}); + const int index = static_cast(m_columns.size()); + const int width = G_DEFAULT_COLUMN_WIDTH; + + addColumn({index, width}); } /* -------------------------------------------------------------------------- */ @@ -108,7 +97,7 @@ void Model::Columns::moveChannel(ID channelId, int columnIndex, int newPosition) { const Column& column = getColumnByChannelId(channelId); - if (getColumnIndex(column) == columnIndex) // If in same column + if (column.index == columnIndex) // If in same column { const int oldPosition = column.getChannelIndex(channelId); if (newPosition >= oldPosition) // If moved below, readjust index @@ -263,9 +252,9 @@ void Model::load(const m::Conf& conf) void Model::load(const m::Patch& patch) { columns.clear(); - for (const m::Patch::Column& pcolumn : patch.columns) + for (int i = 0; const m::Patch::Column& pcolumn : patch.columns) { - Column column{.width = pcolumn.width}; + Column column{.index = i++, .width = pcolumn.width}; for (ID channelId : pcolumn.channels) column.channels.push_back(channelId); columns.addColumn(std::move(column)); diff --git a/src/gui/model.h b/src/gui/model.h index ea2bb7507..3161570c1 100644 --- a/src/gui/model.h +++ b/src/gui/model.h @@ -43,13 +43,13 @@ struct Model { int getChannelIndex(ID) const; + int index; int width; std::vector channels = {}; }; struct Columns { - int getColumnIndex(const Column&) const; const std::vector& getAll() const; Column& getColumnByIndex(int);