Skip to content

Commit

Permalink
Add 'index' property to v::Model::Column
Browse files Browse the repository at this point in the history
  • Loading branch information
gvnnz committed May 24, 2024
1 parent ac97efe commit 3e19e0f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/glue/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ 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);
}

/* -------------------------------------------------------------------------- */

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)));
Expand Down
25 changes: 7 additions & 18 deletions src/gui/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::Column>& Model::Columns::getAll() const
{

Expand Down Expand Up @@ -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<int>(m_columns.size());
const int width = G_DEFAULT_COLUMN_WIDTH;

addColumn({index, width});
}

/* -------------------------------------------------------------------------- */
Expand All @@ -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
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/gui/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ struct Model
{
int getChannelIndex(ID) const;

int index;
int width;
std::vector<ID> channels = {};
};

struct Columns
{
int getColumnIndex(const Column&) const;
const std::vector<Column>& getAll() const;

Column& getColumnByIndex(int);
Expand Down

0 comments on commit 3e19e0f

Please sign in to comment.