Qt: Create a new cheat set if no cheat set is specified

This commit is contained in:
Jeffrey Pfau 2015-08-07 21:04:47 -07:00
parent 3dc22d9cc5
commit a9620df0b8
1 changed files with 15 additions and 5 deletions

View File

@ -99,19 +99,29 @@ void CheatsView::removeSet() {
}
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();
}