QMenuBar *TeamBuilder::createMenuBar(MainEngine *w) { QMenuBar *menuBar = new QMenuBar(); menuBar->setObjectName("TeamBuilder"); QMenu *fileMenu = menuBar->addMenu(tr("&File")); fileMenu->addAction(tr("&New"),this,SLOT(newTeam()),tr("Ctrl+N", "New")); fileMenu->addAction(tr("&Save all"),this,SLOT(saveAll()),tr("Ctrl+S", "Save all")); fileMenu->addAction(tr("&Load all"),this,SLOT(openLoadWindow()),tr("Ctrl+L", "Load all")); fileMenu->addSeparator(); fileMenu->addAction(tr("&Quit"),qApp,SLOT(quit()),tr("Ctrl+Q", "Quit")); QMenu *teamMenu = menuBar->addMenu(tr("&Team")); if (currentWidget() && currentWidget() == this->teamMenu) { teamMenu->addAction(tr("Choose pokemon"), this->teamMenu, SLOT(choosePokemon()), tr("Alt+E", "Choose Pokemon")); } teamMenu->addAction(tr("Trainer Menu"), this, SLOT(switchToTrainer()), tr("Ctrl+B", "Trainer Menu")); teamMenu->addSeparator(); teamMenu->addAction(tr("&Add team"), this, SLOT(addTeam()), tr("Ctrl+A", "Add team")); teamMenu->addAction(tr("&Load team"), this, SLOT(openTeam()), tr("Ctrl+Shift+L", "Load team")); teamMenu->addAction(tr("&Save team"), this, SLOT(saveTeam()), tr("Ctrl+Shift+S", "Save team")); teamMenu->addAction(tr("&Import team"), this, SLOT(importTeam()), tr("Ctrl+I", "Import team")); teamMenu->addAction(tr("&Export team"), this, SLOT(exportTeam()), tr("Ctrl+E", "Export team")); teamMenu->addSeparator(); teamMenu->addAction(tr("Import from Android"), this, SLOT(importAndroid()), tr("Ctrl+Shift+I", "Import from Android")); teamMenu->addAction(tr("Export to Android"), this, SLOT(exportAndroid()), tr("Ctrl+Shift+E", "Export to Android")); currentWidget()->addMenus(menuBar); /* Loading mod menu */ QMenu *menuMods = menuBar->addMenu(tr("&Mods")); QActionGroup *group = new QActionGroup(menuMods); QString currentMod = PokemonInfoConfig::currentMod(); // No mod option. QAction *noMod = menuMods->addAction(tr("&No mod"), this, SLOT(setNoMod())); noMod->setCheckable(true); noMod->setChecked(currentMod.length()==0); group->addAction(noMod); menuMods->addSeparator(); QStringList mods = PokemonInfoConfig::availableMods(); foreach(QString smod, mods) { QAction *mod = menuMods->addAction(smod, this, SLOT(changeMod())); mod->setProperty("name", smod); mod->setCheckable(true); mod->setChecked(currentMod == smod); group->addAction(mod); }
void table::Open() { if (m_model->smthChanged) { if (SaveRequest()) { Save(); } } QString fileName = QFileDialog::getOpenFileName(this,tr("Open"),QString(),tr("JSON Files (*.json)")); if (fileName == "") { return; } QFile f(fileName); QString data = ""; if(f.open(QIODevice::ReadOnly)) { data = f.readAll(); f.close(); } QJsonParseError parseError; QJsonDocument doc = QJsonDocument::fromJson(data.toUtf8(), &parseError); if(parseError.error) { QMessageBox::warning(this, tr("Error"), tr("Parse error")); return; } auto items = doc.object(); m_model->clear(); for (QJsonObject::Iterator iter = items.begin(); iter != items.end(); ++iter) { Team newTeam(iter.key(), iter.value().toInt()); m_model->append(newTeam); } m_fileName = fileName; m_model->smthChanged = false; ui->actionSave->setEnabled(false); }