all repos — mgba @ a9620df0b8fbe74d48a6f459592049291a93948e

mGBA Game Boy Advance Emulator

Qt: Create a new cheat set if no cheat set is specified
Jeffrey Pfau jeffrey@endrift.com
Fri, 07 Aug 2015 21:04:47 -0700
commit

a9620df0b8fbe74d48a6f459592049291a93948e

parent

3dc22d9cc5c93429dabd8428bfc359132543f318

1 files changed, 15 insertions(+), 5 deletions(-)

jump to
M src/platform/qt/CheatsView.cppsrc/platform/qt/CheatsView.cpp

@@ -99,19 +99,29 @@ m_controller->threadContinue();

} void CheatsView::enterCheat(std::function<bool(GBACheatSet*, const char*)> callback) { - GBACheatSet* set; + GBACheatSet* set = nullptr; QModelIndexList selection = m_ui.cheatList->selectionModel()->selectedIndexes(); - if (selection.count() != 1) { - return; + QModelIndex index; + if (selection.count() == 0) { + set = new GBACheatSet; + GBACheatSetInit(set, nullptr); + } else if (selection.count() == 1) { + index = selection[0]; + set = m_model.itemAt(index); } - set = m_model.itemAt(selection[0]); + if (!set) { return; } m_controller->threadInterrupt(); + if (selection.count() == 0) { + m_model.addSet(set); + index = m_model.index(m_model.rowCount() - 1, 0, QModelIndex()); + m_ui.cheatList->selectionModel()->select(index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); + } QStringList cheats = m_ui.codeEntry->toPlainText().split('\n', QString::SkipEmptyParts); for (const QString& string : cheats) { - m_model.beginAppendRow(selection[0]); + m_model.beginAppendRow(index); callback(set, string.toUtf8().constData()); m_model.endAppendRow(); }