Skip to content

Commit

Permalink
Fix possible crash on models with < 100 presets (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
offa committed Sep 13, 2024
1 parent d42e1f2 commit 3047fc8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 42 deletions.
14 changes: 6 additions & 8 deletions src/ui/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QDir>
#include <QFileDialog>
#include <QSettings>
#include <algorithm>

namespace plug
{
Expand All @@ -51,14 +52,11 @@ namespace plug
ui->spinBox->setValue(font.pointSize());
ui->fontComboBox->setCurrentFont(font);

for (std::size_t i = 0; i < 100; ++i)
{
if (names[i][0] == 0x00)
{
break;
}
ui->listWidget->addItem(QString("[%1] %2").arg(i + 1).arg(QString::fromStdString(names[i])));
}
std::size_t index{1};
std::for_each(names.cbegin(), names.cend(), [&index, this](const auto& name)
{
ui->listWidget->addItem(QString("[%1] %2").arg(index).arg(QString::fromStdString(name)));
++index; });

connect(ui->listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(load_slot(std::size_t)));
connect(ui->listWidget_2, SIGNAL(currentRowChanged(int)), this, SLOT(load_file(std::size_t)));
Expand Down
14 changes: 6 additions & 8 deletions src/ui/loadfromamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "ui/mainwindow.h"
#include "ui_loadfromamp.h"
#include <QSettings>
#include <algorithm>

namespace plug
{
Expand Down Expand Up @@ -61,14 +62,11 @@ namespace plug

void LoadFromAmp::load_names(const std::vector<std::string>& names)
{
for (std::size_t i = 0; i < 100; ++i)
{
if (names[i][0] == 0x00)
{
break;
}
ui->comboBox->addItem(QString("[%1] %2").arg(i + 1).arg(QString::fromStdString(names[i])));
}
std::size_t index{1};
std::for_each(names.cbegin(), names.cend(), [&index, this](const auto& name)
{
ui->comboBox->addItem(QString("[%1] %2").arg(index).arg(QString::fromStdString(name)));
++index; });
}

void LoadFromAmp::delete_items()
Expand Down
34 changes: 16 additions & 18 deletions src/ui/quickpresets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "ui/quickpresets.h"
#include "ui_quickpresets.h"
#include <algorithm>

namespace plug
{
Expand Down Expand Up @@ -50,24 +51,21 @@ namespace plug
QSettings settings;
std::size_t i = 0;

for (i = 0; i < 100; i++)
{
if (names[i][0] == 0x00)
{
break;
}
const QString name = QString::fromStdString(names[i]);
ui->comboBox->addItem(QString("[%1] %2").arg(i + 1).arg(name));
ui->comboBox_2->addItem(QString("[%1] %2").arg(i + 1).arg(name));
ui->comboBox_3->addItem(QString("[%1] %2").arg(i + 1).arg(name));
ui->comboBox_4->addItem(QString("[%1] %2").arg(i + 1).arg(name));
ui->comboBox_5->addItem(QString("[%1] %2").arg(i + 1).arg(name));
ui->comboBox_6->addItem(QString("[%1] %2").arg(i + 1).arg(name));
ui->comboBox_7->addItem(QString("[%1] %2").arg(i + 1).arg(name));
ui->comboBox_8->addItem(QString("[%1] %2").arg(i + 1).arg(name));
ui->comboBox_9->addItem(QString("[%1] %2").arg(i + 1).arg(name));
ui->comboBox_10->addItem(QString("[%1] %2").arg(i + 1).arg(name));
}
std::for_each(names.cbegin(), names.cend(), [&i, this](const auto& nameStr)
{
const QString name = QString::fromStdString(nameStr);
const auto index = i + 1;
ui->comboBox->addItem(QString("[%1] %2").arg(index).arg(name));
ui->comboBox_2->addItem(QString("[%1] %2").arg(index).arg(name));
ui->comboBox_3->addItem(QString("[%1] %2").arg(index).arg(name));
ui->comboBox_4->addItem(QString("[%1] %2").arg(index).arg(name));
ui->comboBox_5->addItem(QString("[%1] %2").arg(index).arg(name));
ui->comboBox_6->addItem(QString("[%1] %2").arg(index).arg(name));
ui->comboBox_7->addItem(QString("[%1] %2").arg(index).arg(name));
ui->comboBox_8->addItem(QString("[%1] %2").arg(index).arg(name));
ui->comboBox_9->addItem(QString("[%1] %2").arg(index).arg(name));
ui->comboBox_10->addItem(QString("[%1] %2").arg(index).arg(name));
++i; });

ui->comboBox->addItem(tr("[Empty]"));
ui->comboBox_2->addItem(tr("[Empty]"));
Expand Down
14 changes: 6 additions & 8 deletions src/ui/saveonamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "ui/mainwindow.h"
#include "ui_saveonamp.h"
#include <QSettings>
#include <algorithm>

namespace plug
{
Expand Down Expand Up @@ -62,14 +63,11 @@ namespace plug

void SaveOnAmp::load_names(const std::vector<std::string>& names)
{
for (std::size_t i = 0; i < 100; ++i)
{
if (names[i][0] == 0x00)
{
break;
}
ui->comboBox->addItem(QString("[%1] %2").arg(i + 1).arg(QString::fromStdString(names[i])));
}
std::size_t index{1};
std::for_each(names.cbegin(), names.cend(), [&index, this](const auto& name)
{
ui->comboBox->addItem(QString("[%1] %2").arg(index).arg(QString::fromStdString(name)));
++index; });
}

void SaveOnAmp::delete_items()
Expand Down

0 comments on commit 3047fc8

Please sign in to comment.