Qt: Prune empty chip names from list
Vicki Pfau vi@endrift.com
Sat, 16 Feb 2019 16:25:29 -0800
2 files changed,
11 insertions(+),
2 deletions(-)
M
src/platform/qt/BattleChipView.cpp
→
src/platform/qt/BattleChipView.cpp
@@ -29,8 +29,9 @@
connect(m_ui.chipId, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), m_ui.inserted, [this]() { m_ui.inserted->setChecked(Qt::Unchecked); }); - connect(m_ui.chipId, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), m_ui.chipName, &QComboBox::setCurrentIndex); - connect(m_ui.chipName, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), m_ui.chipId, &QSpinBox::setValue); + connect(m_ui.chipName, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), m_ui.chipId, [this](int id) { + m_ui.chipId->setValue(m_chipIndexToId[id]); + }); connect(m_ui.inserted, &QAbstractButton::toggled, this, &BattleChipView::insertChip); connect(controller.get(), &CoreController::stopping, this, &QWidget::close);@@ -87,17 +88,24 @@ void BattleChipView::loadChipNames(int flavor) {
QStringList chipNames; chipNames.append(tr("(None)")); + m_chipIndexToId.clear(); if (flavor == GBA_FLAVOR_BEAST_LINK_GATE_US) { flavor = GBA_FLAVOR_BEAST_LINK_GATE; } QFile file(QString(":/res/chip-names-%1.txt").arg(flavor)); file.open(QIODevice::ReadOnly | QIODevice::Text); + int id = 0; while (true) { QByteArray line = file.readLine(); if (line.isEmpty()) { break; } + ++id; + if (line.trimmed().isEmpty()) { + continue; + } + m_chipIndexToId[chipNames.length()] = id; chipNames.append(QString::fromUtf8(line).trimmed()); }
M
src/platform/qt/BattleChipView.h
→
src/platform/qt/BattleChipView.h
@@ -33,6 +33,7 @@ void loadChipNames(int);
Ui::BattleChipView m_ui; + QMap<int, int> m_chipIndexToId; std::shared_ptr<CoreController> m_controller; };