From 9df3604c6e9a7b3bc2e46045fc70d7470469d842 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 7 Aug 2022 01:49:16 +0300 Subject: [PATCH 54/54] Ruledit: Add Sanity Check button See osdn #43103 Signed-off-by: Marko Lindqvist --- tools/ruledit/conversion_log.cpp | 4 +- tools/ruledit/conversion_log.h | 4 +- tools/ruledit/ruledit_qt.cpp | 2 +- tools/ruledit/tab_misc.cpp | 66 ++++++++++++++++++++++++-------- tools/ruledit/tab_misc.h | 1 + 5 files changed, 55 insertions(+), 22 deletions(-) diff --git a/tools/ruledit/conversion_log.cpp b/tools/ruledit/conversion_log.cpp index cd51259ad2..d36f67fb1c 100644 --- a/tools/ruledit/conversion_log.cpp +++ b/tools/ruledit/conversion_log.cpp @@ -27,7 +27,7 @@ /**********************************************************************//** Setup conversion_log object **************************************************************************/ -conversion_log::conversion_log() : QDialog() +conversion_log::conversion_log(QString title) : QDialog() { QGridLayout *main_layout = new QGridLayout(this); QPushButton *close_button; @@ -43,7 +43,7 @@ conversion_log::conversion_log() : QDialog() main_layout->addWidget(close_button, row++, 0); setLayout(main_layout); - setWindowTitle(QString::fromUtf8(R__("Old ruleset to a new format"))); + setWindowTitle(title); setVisible(false); } diff --git a/tools/ruledit/conversion_log.h b/tools/ruledit/conversion_log.h index ac20d9ef6f..c0eb31a6fe 100644 --- a/tools/ruledit/conversion_log.h +++ b/tools/ruledit/conversion_log.h @@ -1,4 +1,4 @@ -/********************************************************************** +/*********************************************************************** Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -27,7 +27,7 @@ class conversion_log : public QDialog Q_OBJECT public: - explicit conversion_log(); + explicit conversion_log(QString title); void add(const char *msg); private: diff --git a/tools/ruledit/ruledit_qt.cpp b/tools/ruledit/ruledit_qt.cpp index 94019b38a4..967966dfb7 100644 --- a/tools/ruledit/ruledit_qt.cpp +++ b/tools/ruledit/ruledit_qt.cpp @@ -224,7 +224,7 @@ void ruledit_gui::launch_now() { QByteArray rn_bytes; - convlog = new conversion_log(); + convlog = new conversion_log(QString::fromUtf8(R__("Old ruleset to a new format"))); rn_bytes = ruleset_select->text().toUtf8(); sz_strlcpy(game.server.rulesetdir, rn_bytes.data()); diff --git a/tools/ruledit/tab_misc.cpp b/tools/ruledit/tab_misc.cpp index 57090667eb..1ec9724d2b 100644 --- a/tools/ruledit/tab_misc.cpp +++ b/tools/ruledit/tab_misc.cpp @@ -43,6 +43,7 @@ #include "rssanity.h" // ruledit +#include "conversion_log.h" #include "ruledit.h" #include "ruledit_qt.h" #include "rulesave.h" @@ -60,10 +61,7 @@ tab_misc::tab_misc(ruledit_gui *ui_in) : QWidget() QLabel *label; QLabel *name_label; QLabel *version_label; - QPushButton *save_button; - QPushButton *always_active_effects; - QPushButton *all_effects; - QPushButton *refresh_button; + QPushButton *button; int row = 0; QTableWidgetItem *item; char ttbuf[2048]; @@ -118,9 +116,9 @@ tab_misc::tab_misc(ruledit_gui *ui_in) : QWidget() main_layout->addWidget(save_ver_label, row, 0); savedir_version = new QCheckBox(this); main_layout->addWidget(savedir_version, row++, 1); - save_button = new QPushButton(QString::fromUtf8(R__("Save now")), this); - connect(save_button, SIGNAL(pressed()), this, SLOT(save_now())); - main_layout->addWidget(save_button, row++, 1); + button = new QPushButton(QString::fromUtf8(R__("Save now")), this); + connect(button, SIGNAL(pressed()), this, SLOT(save_now())); + main_layout->addWidget(button, row++, 1); label = new QLabel(QString::fromUtf8(R__("Description from file"))); label->setParent(this); @@ -135,12 +133,16 @@ tab_misc::tab_misc(ruledit_gui *ui_in) : QWidget() desc_file = new QLineEdit(this); main_layout->addWidget(desc_file, row++, 1); - always_active_effects = new QPushButton(QString::fromUtf8(R__("Always active Effects")), this); - connect(always_active_effects, SIGNAL(pressed()), this, SLOT(edit_aae_effects())); - main_layout->addWidget(always_active_effects, row++, 1); - all_effects = new QPushButton(QString::fromUtf8(R__("All Effects")), this); - connect(all_effects, SIGNAL(pressed()), this, SLOT(edit_all_effects())); - main_layout->addWidget(all_effects, row++, 1); + button = new QPushButton(QString::fromUtf8(R__("Sanity check rules")), this); + connect(button, SIGNAL(pressed()), this, SLOT(sanity_check())); + main_layout->addWidget(button, row++, 1); + + button = new QPushButton(QString::fromUtf8(R__("Always active Effects")), this); + connect(button, SIGNAL(pressed()), this, SLOT(edit_aae_effects())); + main_layout->addWidget(button, row++, 1); + button = new QPushButton(QString::fromUtf8(R__("All Effects")), this); + connect(button, SIGNAL(pressed()), this, SLOT(edit_all_effects())); + main_layout->addWidget(button, row++, 1); stats = new QTableWidget(this); stats->setColumnCount(8); @@ -225,13 +227,13 @@ tab_misc::tab_misc(ruledit_gui *ui_in) : QWidget() stats->horizontalHeader()->setVisible(false); stats->setEditTriggers(QAbstractItemView::NoEditTriggers); main_layout->addWidget(stats, row++, 0, 1, 2); - refresh_button = new QPushButton(QString::fromUtf8(R__("Refresh Stats")), this); - connect(refresh_button, SIGNAL(pressed()), this, SLOT(refresh_stats())); - main_layout->addWidget(refresh_button, row++, 0, 1, 2); + button = new QPushButton(QString::fromUtf8(R__("Refresh Stats")), this); + connect(button, SIGNAL(pressed()), this, SLOT(refresh_stats())); + main_layout->addWidget(button, row++, 0, 1, 2); // Stats never change except with experimental features. Hide useless // button. - show_experimental(refresh_button); + show_experimental(button); refresh(); @@ -439,6 +441,36 @@ void tab_misc::edit_aae_effects() nullptr, EFMC_NONE); } +static conversion_log *sanitylog; + +/**********************************************************************//** + Ruleset conversion log callback +**************************************************************************/ +static void sanity_log_cb(const char *msg) +{ + sanitylog->add(msg); +} + +/**********************************************************************//** + Run sanity check for current rules +**************************************************************************/ +void tab_misc::sanity_check() +{ + struct rscompat_info compat_info; + + sanitylog = new conversion_log(QString::fromUtf8(R__("Sanity Check"))); + + rscompat_init_info(&compat_info); + compat_info.compat_mode = FALSE; + compat_info.log_cb = sanity_log_cb; + + if (!sanity_check_ruleset_data(&compat_info)) { + ui->display_msg(R__("Sanity check failed!")); + } else { + ui->display_msg(R__("Sanity check success")); + } +} + /**********************************************************************//** User wants to edit effects from full list **************************************************************************/ diff --git a/tools/ruledit/tab_misc.h b/tools/ruledit/tab_misc.h index f6dcb3d5c2..7a93956610 100644 --- a/tools/ruledit/tab_misc.h +++ b/tools/ruledit/tab_misc.h @@ -39,6 +39,7 @@ class tab_misc : public QWidget void edit_aae_effects(); void edit_all_effects(); void desc_file_toggle(bool checked); + void sanity_check(); private: ruledit_gui *ui; -- 2.35.1