From 11459d926862afed4d605af6f12defc4b35b7b0b Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Mon, 17 Mar 2025 21:58:31 +0100 Subject: [PATCH 1/2] editor for JSON config in launcher --- launcher/CMakeLists.txt | 3 + launcher/helper.cpp | 22 +++ launcher/helper.h | 3 + launcher/mainwindow_moc.cpp | 8 +- .../settingsView/configeditordialog_moc.cpp | 158 ++++++++++++++++++ .../settingsView/configeditordialog_moc.h | 46 +++++ .../settingsView/configeditordialog_moc.ui | 94 +++++++++++ launcher/settingsView/csettingsview_moc.cpp | 22 ++- launcher/settingsView/csettingsview_moc.h | 1 + launcher/settingsView/csettingsview_moc.ui | 14 ++ launcher/startGame/StartGameTab.cpp | 65 ++++--- launcher/startGame/StartGameTab.h | 2 - 12 files changed, 381 insertions(+), 57 deletions(-) create mode 100644 launcher/settingsView/configeditordialog_moc.cpp create mode 100644 launcher/settingsView/configeditordialog_moc.h create mode 100644 launcher/settingsView/configeditordialog_moc.ui diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 0154f87a7..2550bb5d6 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -14,6 +14,7 @@ set(launcher_SRCS modManager/imageviewer_moc.cpp modManager/chroniclesextractor.cpp settingsView/csettingsview_moc.cpp + settingsView/configeditordialog_moc.cpp startGame/StartGameTab.cpp firstLaunch/firstlaunch_moc.cpp main.cpp @@ -45,6 +46,7 @@ set(launcher_HEADERS modManager/modstate.h modManager/imageviewer_moc.h modManager/chroniclesextractor.h + settingsView/configeditordialog_moc.h settingsView/csettingsview_moc.h startGame/StartGameTab.h firstLaunch/firstlaunch_moc.h @@ -61,6 +63,7 @@ set(launcher_FORMS aboutProject/aboutproject_moc.ui modManager/cmodlistview_moc.ui modManager/imageviewer_moc.ui + settingsView/configeditordialog_moc.ui settingsView/csettingsview_moc.ui firstLaunch/firstlaunch_moc.ui mainwindow_moc.ui diff --git a/launcher/helper.cpp b/launcher/helper.cpp index 63abfb988..f00353776 100644 --- a/launcher/helper.cpp +++ b/launcher/helper.cpp @@ -10,6 +10,10 @@ #include "StdInc.h" #include "helper.h" +#include "mainwindow_moc.h" +#include "settingsView/csettingsview_moc.h" +#include "modManager/cmodlistview_moc.h" + #include "../lib/CConfigHandler.h" #include @@ -45,6 +49,16 @@ void loadSettings() persistentStorage.init("config/persistentStorage.json", ""); } +void reLoadSettings() +{ + loadSettings(); + for(const auto widget : qApp->allWidgets()) + if(auto settingsView = qobject_cast(widget)) + settingsView->loadSettings(); + getMainWindow()->updateTranslation(); + getMainWindow()->getModView()->reload(); +} + void enableScrollBySwiping(QObject * scrollTarget) { #ifdef VCMI_MOBILE @@ -89,4 +103,12 @@ void revealDirectoryInFileBrowser(QString path) QDesktopServices::openUrl(dirUrl); #endif } + +MainWindow * getMainWindow() +{ + foreach(QWidget *w, qApp->allWidgets()) + if(auto mainWin = qobject_cast(w)) + return mainWin; + return nullptr; +} } diff --git a/launcher/helper.h b/launcher/helper.h index c331c62fe..032fd59af 100644 --- a/launcher/helper.h +++ b/launcher/helper.h @@ -12,12 +12,15 @@ #include class QObject; +class MainWindow; namespace Helper { void loadSettings(); +void reLoadSettings(); void enableScrollBySwiping(QObject * scrollTarget); QString getRealPath(QString path); void performNativeCopy(QString src, QString dst); void revealDirectoryInFileBrowser(QString path); +MainWindow * getMainWindow(); } diff --git a/launcher/mainwindow_moc.cpp b/launcher/mainwindow_moc.cpp index f288bcaa1..71b2bb0a7 100644 --- a/launcher/mainwindow_moc.cpp +++ b/launcher/mainwindow_moc.cpp @@ -297,13 +297,7 @@ void MainWindow::manualInstallFile(QString filePath) QFile::remove(configFilePath); QFile::copy(filePath, configFilePath); - // reload settings - Helper::loadSettings(); - for(const auto widget : qApp->allWidgets()) - if(auto settingsView = qobject_cast(widget)) - settingsView->loadSettings(); - - getModView()->reload(); + Helper::reLoadSettings(); } } } diff --git a/launcher/settingsView/configeditordialog_moc.cpp b/launcher/settingsView/configeditordialog_moc.cpp new file mode 100644 index 000000000..074dab150 --- /dev/null +++ b/launcher/settingsView/configeditordialog_moc.cpp @@ -0,0 +1,158 @@ +/* + * configeditordialog_moc.cpp, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#include "StdInc.h" +#include "configeditordialog_moc.h" +#include "ui_configeditordialog_moc.h" + +#include "../helper.h" +#include "../mainwindow_moc.h" + +#include "../../lib/json/JsonNode.h" +#include "../../lib/VCMIDirs.h" +#include "../../lib/json/JsonFormatException.h" + +ConfigEditorDialog::ConfigEditorDialog(QWidget *parent): + QDialog(parent), + ui(new Ui::ConfigEditorDialog) +{ + ui->setupUi(this); + + setWindowTitle(tr("Config editor")); + + setWindowModality(Qt::ApplicationModal); +#ifdef VCMI_MOBILE + showMaximized(); +#else + show(); +#endif + + QStringList files = { + "settings.json", + "persistentStorage.json", + "modSettings.json", + }; + ui->comboBox->addItems(files); + + QFont font("Monospace"); + font.setStyleHint(QFont::TypeWriter); + ui->plainTextEdit->setFont(font); + ui->plainTextEdit->setLineWrapMode(QPlainTextEdit::LineWrapMode::NoWrap); + ui->plainTextEdit->setPlainText(loadFile(files.first())); + + connect(ui->comboBox, &QComboBox::currentTextChanged, this, &ConfigEditorDialog::onComboBoxTextChanged); + connect(ui->closeButton, &QPushButton::clicked, this, &ConfigEditorDialog::onCloseButtonClicked); + connect(ui->saveButton, &QPushButton::clicked, this, &ConfigEditorDialog::onSaveButtonClicked); +} + +ConfigEditorDialog::~ConfigEditorDialog() +{ + delete ui; +} + +void ConfigEditorDialog::showConfigEditorDialog() +{ + auto * dialog = new ConfigEditorDialog(); + + dialog->setAttribute(Qt::WA_DeleteOnClose); +} + +bool askUnsavedChanges(QWidget *parent) +{ + auto reply = QMessageBox::question(parent, QObject::tr("Unsaved changes"), QObject::tr("Do you want to discard changes?"), QMessageBox::Yes | QMessageBox::No); + return reply != QMessageBox::Yes; +} + +void ConfigEditorDialog::onComboBoxTextChanged(QString filename) +{ + auto inputText = ui->plainTextEdit->toPlainText(); + + if(filename == loadedFile) + return; + + if(inputText != loadedText) + { + if(askUnsavedChanges(this)) + { + ui->comboBox->setCurrentText(loadedFile); + return; + } + } + + ui->plainTextEdit->setPlainText(loadFile(filename)); +} + +void ConfigEditorDialog::onCloseButtonClicked() +{ + auto text = ui->plainTextEdit->toPlainText(); + if(text != loadedText) + { + if(askUnsavedChanges(this)) + return; + } + close(); +} + +void ConfigEditorDialog::onSaveButtonClicked() +{ + auto text = ui->plainTextEdit->toPlainText(); + auto filename = ui->comboBox->currentText(); + + if(text == loadedText) + { + close(); + return; + } + + auto stdText = text.toStdString(); + try + { + JsonParsingSettings jsonSettings; + jsonSettings.strict = true; + JsonNode node(reinterpret_cast(stdText.data()), stdText.size(), jsonSettings, filename.toStdString()); + } + catch(const JsonFormatException& e) + { + QMessageBox::critical(this, tr("JSON file is not valid!"), e.what()); + return; + } + + saveFile(filename, text); + + Helper::reLoadSettings(); + + close(); +} + +QString ConfigEditorDialog::loadFile(QString filename) +{ + auto file = pathToQString(VCMIDirs::get().userConfigPath() / filename.toStdString()); + QFile f(file); + if(!f.open(QFile::ReadOnly | QFile::Text)) + { + logGlobal->error("ConfigEditor can not open config for reading!"); + return ""; + } + loadedText = QString::fromUtf8(f.readAll()); + loadedFile = filename; + + return loadedText; +} + +void ConfigEditorDialog::saveFile(QString filename, QString content) +{ + auto file = pathToQString(VCMIDirs::get().userConfigPath() / filename.toStdString()); + QFile f(file); + if(!f.open(QFile::WriteOnly | QFile::Text)) + { + logGlobal->error("ConfigEditor can not open config for writing!"); + return; + } + f.write(content.toUtf8()); +} diff --git a/launcher/settingsView/configeditordialog_moc.h b/launcher/settingsView/configeditordialog_moc.h new file mode 100644 index 000000000..b8ef51c8f --- /dev/null +++ b/launcher/settingsView/configeditordialog_moc.h @@ -0,0 +1,46 @@ +/* + * configeditordialog_moc.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#pragma once +#include + +VCMI_LIB_NAMESPACE_BEGIN + +class JsonNode; + +VCMI_LIB_NAMESPACE_END + +namespace Ui { +class ConfigEditorDialog; +} + +class ConfigEditorDialog : public QDialog +{ + Q_OBJECT + +public: + explicit ConfigEditorDialog(QWidget *parent = nullptr); + ~ConfigEditorDialog(); + + static void showConfigEditorDialog(); + +private slots: + void onComboBoxTextChanged(QString filename); + void onCloseButtonClicked(); + void onSaveButtonClicked(); + +private: + Ui::ConfigEditorDialog *ui; + + QString loadedText; + QString loadedFile; + + QString loadFile(QString filename); + void saveFile(QString filename, QString content); +}; diff --git a/launcher/settingsView/configeditordialog_moc.ui b/launcher/settingsView/configeditordialog_moc.ui new file mode 100644 index 000000000..e8c6373df --- /dev/null +++ b/launcher/settingsView/configeditordialog_moc.ui @@ -0,0 +1,94 @@ + + + ConfigEditorDialog + + + + 0 + 0 + 640 + 480 + + + + + 0 + 0 + + + + + 371 + 247 + + + + + + + + 12 + + + 12 + + + 12 + + + 12 + + + + + + 0 + 0 + + + + Save + + + + + + + + + + QPlainTextEdit::NoWrap + + + false + + + + + + + + + + File: + + + + + + + + 0 + 0 + + + + Close + + + + + + + + diff --git a/launcher/settingsView/csettingsview_moc.cpp b/launcher/settingsView/csettingsview_moc.cpp index f921f73fb..6a1852ce7 100644 --- a/launcher/settingsView/csettingsview_moc.cpp +++ b/launcher/settingsView/csettingsview_moc.cpp @@ -12,6 +12,7 @@ #include "ui_csettingsview_moc.h" #include "mainwindow_moc.h" +#include "configeditordialog_moc.h" #include "../modManager/cmodlistview_moc.h" #include "../helper.h" @@ -54,14 +55,6 @@ static constexpr std::array downscalingFilterTypes = "best" }; -MainWindow * CSettingsView::getMainWindow() -{ - foreach(QWidget *w, qApp->allWidgets()) - if(QMainWindow* mainWin = qobject_cast(w)) - return dynamic_cast(mainWin); - return nullptr; -} - void CSettingsView::setDisplayList() { QStringList list; @@ -501,7 +494,7 @@ void CSettingsView::on_comboBoxLanguage_currentIndexChanged(int index) QString selectedLanguage = ui->comboBoxLanguage->itemData(index).toString(); node->String() = selectedLanguage.toStdString(); - getMainWindow()->updateTranslation(); + Helper::getMainWindow()->updateTranslation(); } void CSettingsView::changeEvent(QEvent *event) @@ -535,7 +528,7 @@ void CSettingsView::loadTranslation() { QString baseLanguage = Languages::getHeroesDataLanguage(); - auto * mainWindow = getMainWindow(); + auto * mainWindow = Helper::getMainWindow(); if (!mainWindow) return; @@ -568,7 +561,7 @@ void CSettingsView::loadTranslation() void CSettingsView::on_pushButtonTranslation_clicked() { - auto * mainWindow = getMainWindow(); + auto * mainWindow = Helper::getMainWindow(); assert(mainWindow); if (!mainWindow) @@ -632,7 +625,7 @@ void CSettingsView::on_spinBoxInterfaceScaling_valueChanged(int arg1) void CSettingsView::on_refreshRepositoriesButton_clicked() { - auto * mainWindow = getMainWindow(); + auto * mainWindow = Helper::getMainWindow(); assert(mainWindow); if (!mainWindow) @@ -641,6 +634,11 @@ void CSettingsView::on_refreshRepositoriesButton_clicked() mainWindow->getModView()->loadRepositories(); } +void CSettingsView::on_buttonConfigEditor_clicked() +{ + ConfigEditorDialog::showConfigEditorDialog(); +} + void CSettingsView::on_spinBoxFramerateLimit_valueChanged(int arg1) { Settings node = settings.write["video"]["targetfps"]; diff --git a/launcher/settingsView/csettingsview_moc.h b/launcher/settingsView/csettingsview_moc.h index 866a67886..f9fac9962 100644 --- a/launcher/settingsView/csettingsview_moc.h +++ b/launcher/settingsView/csettingsview_moc.h @@ -60,6 +60,7 @@ private slots: void on_lineEditRepositoryExtra_textEdited(const QString &arg1); void on_spinBoxInterfaceScaling_valueChanged(int arg1); void on_refreshRepositoriesButton_clicked(); + void on_buttonConfigEditor_clicked(); void on_spinBoxFramerateLimit_valueChanged(int arg1); void on_buttonVSync_toggled(bool value); void on_comboBoxEnemyPlayerAI_currentTextChanged(const QString &arg1); diff --git a/launcher/settingsView/csettingsview_moc.ui b/launcher/settingsView/csettingsview_moc.ui index a7a918973..f5deb1089 100644 --- a/launcher/settingsView/csettingsview_moc.ui +++ b/launcher/settingsView/csettingsview_moc.ui @@ -76,6 +76,20 @@ + + + + Config editor + + + + + + + Open editor + + + diff --git a/launcher/startGame/StartGameTab.cpp b/launcher/startGame/StartGameTab.cpp index f68c6d6d6..5242d362d 100644 --- a/launcher/startGame/StartGameTab.cpp +++ b/launcher/startGame/StartGameTab.cpp @@ -11,6 +11,7 @@ #include "StartGameTab.h" #include "ui_StartGameTab.h" +#include "../helper.h" #include "../mainwindow_moc.h" #include "../main.h" #include "../updatedialog_moc.h" @@ -87,19 +88,11 @@ StartGameTab::~StartGameTab() delete ui; } -MainWindow * StartGameTab::getMainWindow() -{ - foreach(QWidget *w, qApp->allWidgets()) - if(QMainWindow* mainWin = qobject_cast(w)) - return dynamic_cast(mainWin); - return nullptr; -} - void StartGameTab::refreshState() { refreshGameData(); refreshUpdateStatus(EGameUpdateStatus::NOT_CHECKED);//TODO - follow automatic check on startup setting - refreshTranslation(getMainWindow()->getTranslationStatus()); + refreshTranslation(Helper::getMainWindow()->getTranslationStatus()); refreshPresets(); refreshMods(); @@ -110,10 +103,10 @@ void StartGameTab::refreshPresets() { QSignalBlocker blocker(ui->comboBoxModPresets); - QStringList allPresets = getMainWindow()->getModView()->getAllPresets(); + QStringList allPresets = Helper::getMainWindow()->getModView()->getAllPresets(); ui->comboBoxModPresets->clear(); ui->comboBoxModPresets->addItems(allPresets); - ui->comboBoxModPresets->setCurrentText(getMainWindow()->getModView()->getActivePreset()); + ui->comboBoxModPresets->setCurrentText(Helper::getMainWindow()->getModView()->getActivePreset()); ui->buttonPresetDelete->setVisible(allPresets.size() > 1); } @@ -178,8 +171,8 @@ void StartGameTab::refreshTranslation(ETranslationStatus status) void StartGameTab::refreshMods() { constexpr int chroniclesCount = 8; - QStringList updateableMods = getMainWindow()->getModView()->getUpdateableMods(); - QStringList chroniclesMods = getMainWindow()->getModView()->getInstalledChronicles(); + QStringList updateableMods = Helper::getMainWindow()->getModView()->getUpdateableMods(); + QStringList chroniclesMods = Helper::getMainWindow()->getModView()->getInstalledChronicles(); ui->buttonUpdateMods->setText(tr("Update %n mods", "", updateableMods.size())); ui->buttonUpdateMods->setVisible(!updateableMods.empty()); @@ -207,7 +200,7 @@ void StartGameTab::refreshUpdateStatus(EGameUpdateStatus status) void StartGameTab::on_buttonGameStart_clicked() { - getMainWindow()->hide(); + Helper::getMainWindow()->hide(); startGame({}); } @@ -228,7 +221,7 @@ void StartGameTab::on_buttonUpdateCheck_clicked() void StartGameTab::on_buttonGameEditor_clicked() { - getMainWindow()->hide(); + Helper::getMainWindow()->hide(); startEditor({}); } @@ -253,7 +246,7 @@ void StartGameTab::on_buttonImportFiles_clicked() for(const auto & file : files) { logGlobal->info("Importing file %s", file.toStdString()); - getMainWindow()->manualInstallFile(file); + Helper::getMainWindow()->manualInstallFile(file); } }; @@ -264,29 +257,29 @@ void StartGameTab::on_buttonImportFiles_clicked() void StartGameTab::on_buttonInstallTranslation_clicked() { - if (getMainWindow()->getTranslationStatus() == ETranslationStatus::NOT_INSTALLLED) + if (Helper::getMainWindow()->getTranslationStatus() == ETranslationStatus::NOT_INSTALLLED) { QString preferredlanguage = QString::fromStdString(settings["general"]["language"].String()); - QString modName = getMainWindow()->getModView()->getTranslationModName(preferredlanguage); - getMainWindow()->getModView()->doInstallMod(modName); + QString modName = Helper::getMainWindow()->getModView()->getTranslationModName(preferredlanguage); + Helper::getMainWindow()->getModView()->doInstallMod(modName); } } void StartGameTab::on_buttonActivateTranslation_clicked() { QString preferredlanguage = QString::fromStdString(settings["general"]["language"].String()); - QString modName = getMainWindow()->getModView()->getTranslationModName(preferredlanguage); - getMainWindow()->getModView()->enableModByName(modName); + QString modName = Helper::getMainWindow()->getModView()->getTranslationModName(preferredlanguage); + Helper::getMainWindow()->getModView()->enableModByName(modName); } void StartGameTab::on_buttonUpdateMods_clicked() { - QStringList updateableMods = getMainWindow()->getModView()->getUpdateableMods(); + QStringList updateableMods = Helper::getMainWindow()->getModView()->getUpdateableMods(); - getMainWindow()->switchToModsTab(); + Helper::getMainWindow()->switchToModsTab(); for (const auto & modName : updateableMods) - getMainWindow()->getModView()->doUpdateMod(modName); + Helper::getMainWindow()->getModView()->doUpdateMod(modName); } void StartGameTab::on_buttonHelpImportFiles_clicked() @@ -395,7 +388,7 @@ void StartGameTab::on_buttonMissingCampaignsHelp_clicked() void StartGameTab::on_buttonPresetExport_clicked() { - JsonNode presetJson = getMainWindow()->getModView()->exportCurrentPreset(); + JsonNode presetJson = Helper::getMainWindow()->getModView()->exportCurrentPreset(); QString presetString = QString::fromStdString(presetJson.toCompactString()); QGuiApplication::clipboard()->setText(presetString); @@ -408,8 +401,8 @@ void StartGameTab::on_buttonPresetImport_clicked() QByteArray presetBytes(presetString.toUtf8()); JsonNode presetJson(reinterpret_cast(presetBytes.data()), presetBytes.size(), "imported preset"); - getMainWindow()->getModView()->importPreset(presetJson); - getMainWindow()->switchToModsTab(); + Helper::getMainWindow()->getModView()->importPreset(presetJson); + Helper::getMainWindow()->switchToModsTab(); refreshPresets(); } @@ -427,8 +420,8 @@ void StartGameTab::on_buttonPresetNew_clicked() if (ok && !presetName.isEmpty()) { - getMainWindow()->getModView()->createNewPreset(presetName); - getMainWindow()->getModView()->activatePreset(presetName); + Helper::getMainWindow()->getModView()->createNewPreset(presetName); + Helper::getMainWindow()->getModView()->activatePreset(presetName); refreshPresets(); } }; @@ -437,27 +430,27 @@ void StartGameTab::on_buttonPresetNew_clicked() void StartGameTab::on_buttonPresetDelete_clicked() { - QString activePresetBefore = getMainWindow()->getModView()->getActivePreset(); - QStringList allPresets = getMainWindow()->getModView()->getAllPresets(); + QString activePresetBefore = Helper::getMainWindow()->getModView()->getActivePreset(); + QStringList allPresets = Helper::getMainWindow()->getModView()->getAllPresets(); allPresets.removeAll(activePresetBefore); if (!allPresets.empty()) { - getMainWindow()->getModView()->activatePreset(allPresets.front()); - getMainWindow()->getModView()->deletePreset(activePresetBefore); + Helper::getMainWindow()->getModView()->activatePreset(allPresets.front()); + Helper::getMainWindow()->getModView()->deletePreset(activePresetBefore); refreshPresets(); } } void StartGameTab::on_comboBoxModPresets_currentTextChanged(const QString &presetName) { - getMainWindow()->getModView()->activatePreset(presetName); + Helper::getMainWindow()->getModView()->activatePreset(presetName); } void StartGameTab::on_buttonPresetRename_clicked() { const auto & functor = [this](){ - QString currentName = getMainWindow()->getModView()->getActivePreset(); + QString currentName = Helper::getMainWindow()->getModView()->getActivePreset(); bool ok; QString newName = QInputDialog::getText( @@ -470,7 +463,7 @@ void StartGameTab::on_buttonPresetRename_clicked() if (ok && !newName.isEmpty() && newName != currentName) { - getMainWindow()->getModView()->renamePreset(currentName, newName); + Helper::getMainWindow()->getModView()->renamePreset(currentName, newName); refreshPresets(); } }; diff --git a/launcher/startGame/StartGameTab.h b/launcher/startGame/StartGameTab.h index eb4cbb3e5..262ae69bf 100644 --- a/launcher/startGame/StartGameTab.h +++ b/launcher/startGame/StartGameTab.h @@ -31,8 +31,6 @@ class StartGameTab : public QWidget { Q_OBJECT - MainWindow * getMainWindow(); - void refreshUpdateStatus(EGameUpdateStatus status); void refreshTranslation(ETranslationStatus status); void refreshMods(); From a37150100504bd8091c7af2526f4051737634dc9 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sun, 23 Mar 2025 13:09:03 +0100 Subject: [PATCH 2/2] code review --- launcher/helper.cpp | 3 +++ launcher/settingsView/configeditordialog_moc.cpp | 6 +++--- launcher/settingsView/configeditordialog_moc.h | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/launcher/helper.cpp b/launcher/helper.cpp index f00353776..e741dfb43 100644 --- a/launcher/helper.cpp +++ b/launcher/helper.cpp @@ -54,7 +54,10 @@ void reLoadSettings() loadSettings(); for(const auto widget : qApp->allWidgets()) if(auto settingsView = qobject_cast(widget)) + { settingsView->loadSettings(); + break; + } getMainWindow()->updateTranslation(); getMainWindow()->getModView()->reload(); } diff --git a/launcher/settingsView/configeditordialog_moc.cpp b/launcher/settingsView/configeditordialog_moc.cpp index 074dab150..f45822657 100644 --- a/launcher/settingsView/configeditordialog_moc.cpp +++ b/launcher/settingsView/configeditordialog_moc.cpp @@ -63,9 +63,9 @@ void ConfigEditorDialog::showConfigEditorDialog() dialog->setAttribute(Qt::WA_DeleteOnClose); } -bool askUnsavedChanges(QWidget *parent) +bool ConfigEditorDialog::askUnsavedChanges(QWidget *parent) { - auto reply = QMessageBox::question(parent, QObject::tr("Unsaved changes"), QObject::tr("Do you want to discard changes?"), QMessageBox::Yes | QMessageBox::No); + auto reply = QMessageBox::question(parent, tr("Unsaved changes"), tr("Do you want to discard changes?"), QMessageBox::Yes | QMessageBox::No); return reply != QMessageBox::Yes; } @@ -137,7 +137,7 @@ QString ConfigEditorDialog::loadFile(QString filename) if(!f.open(QFile::ReadOnly | QFile::Text)) { logGlobal->error("ConfigEditor can not open config for reading!"); - return ""; + return {}; } loadedText = QString::fromUtf8(f.readAll()); loadedFile = filename; diff --git a/launcher/settingsView/configeditordialog_moc.h b/launcher/settingsView/configeditordialog_moc.h index b8ef51c8f..3d0002dad 100644 --- a/launcher/settingsView/configeditordialog_moc.h +++ b/launcher/settingsView/configeditordialog_moc.h @@ -41,6 +41,7 @@ private: QString loadedText; QString loadedFile; + bool askUnsavedChanges(QWidget *parent); QString loadFile(QString filename); void saveFile(QString filename, QString content); };