From 33dd3eca04f6bbc5d2bdcf190abd2dd3497f369d Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Mon, 10 Jan 2022 04:15:37 +0100 Subject: [PATCH] Add tileset messages to the tileset debugger Any message with a level < LOG_FATAL is now saved so the user can have a look later on. This is in particular useful for terrain sprites, since they generate LOG_ERROR messages when missing. There are still many conditions under which a crash is the only solution. Related to #632. Related to #806. --- client/gui-qt/mapview.cpp | 1 + client/gui-qt/mapview.h | 2 + client/gui-qt/tileset_debugger.cpp | 107 +++++++++++++++---- client/gui-qt/tileset_debugger.h | 7 ++ data/themes/gui-qt/NightStalker/resource.qss | 1 + 5 files changed, 99 insertions(+), 19 deletions(-) diff --git a/client/gui-qt/mapview.cpp b/client/gui-qt/mapview.cpp index d71505d140..66bfa008ad 100644 --- a/client/gui-qt/mapview.cpp +++ b/client/gui-qt/mapview.cpp @@ -580,6 +580,7 @@ void tileset_changed(void) science_report *sci_rep; QWidget *w; + queen()->mapview_wdg->debugger()->refresh(tileset); update_unit_info_label(get_units_in_focus()); destroy_city_dialog(); // Update science report if open diff --git a/client/gui-qt/mapview.h b/client/gui-qt/mapview.h index b5ea22d0f2..7af931b07a 100644 --- a/client/gui-qt/mapview.h +++ b/client/gui-qt/mapview.h @@ -63,6 +63,8 @@ class map_view : public QWidget { bool menu_click; + freeciv::tileset_debugger *debugger() const { return m_debugger; } + public slots: void show_debugger(); void hide_debugger(); diff --git a/client/gui-qt/tileset_debugger.cpp b/client/gui-qt/tileset_debugger.cpp index 30b8150df8..86ba234622 100644 --- a/client/gui-qt/tileset_debugger.cpp +++ b/client/gui-qt/tileset_debugger.cpp @@ -25,7 +25,9 @@ // utility #include "fcintl.h" +#include #include +#include #include #include #include @@ -44,30 +46,55 @@ namespace freeciv { tileset_debugger::tileset_debugger(QWidget *parent) : QDialog(parent) { setWindowTitle(_("Tileset debugger")); + auto tabs = new QTabWidget; auto layout = new QVBoxLayout; + layout->addWidget(tabs); + layout->setContentsMargins(0, 0, 0, 0); setLayout(layout); - auto toolbar = new QToolBar; - toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - layout->addWidget(toolbar); - - m_pick_action = - toolbar->addAction(QIcon::fromTheme("pointer"), _("Pick tile")); - m_pick_action->setToolTip(_("Pick a tile to inspect on the map")); - m_pick_action->setCheckable(true); - connect(m_pick_action, &QAction::toggled, this, - &tileset_debugger::pick_tile); - - m_label = new QLabel; - layout->addWidget(m_label); - - m_content = new QTreeWidget; - m_content->setHeaderHidden(true); - m_content->setSelectionMode(QAbstractItemView::NoSelection); - layout->addWidget(m_content, 100); + // Log tab + { + m_messages = new QListWidget; + tabs->addTab(m_messages, _("Messages")); + + m_messages->setEditTriggers(QAbstractItemView::NoEditTriggers); + m_messages->setSelectionMode(QAbstractItemView::ContiguousSelection); + m_messages->setTextElideMode(Qt::ElideNone); + m_messages->setWordWrap(true); + m_messages->setSizeAdjustPolicy( + QAbstractItemView::AdjustToContentsOnFirstShow); + refresh_messages(tileset); + } - set_tile(nullptr); + // Tile inspector tab + { + auto tab = new QWidget; + tabs->addTab(tab, _("Inspector")); + auto layout = new QVBoxLayout; + tab->setLayout(layout); + + auto toolbar = new QToolBar; + toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + layout->addWidget(toolbar); + + m_pick_action = + toolbar->addAction(QIcon::fromTheme("pointer"), _("Pick tile")); + m_pick_action->setToolTip(_("Pick a tile to inspect on the map")); + m_pick_action->setCheckable(true); + connect(m_pick_action, &QAction::toggled, this, + &tileset_debugger::pick_tile); + + m_label = new QLabel; + layout->addWidget(m_label); + + m_content = new QTreeWidget; + m_content->setHeaderHidden(true); + m_content->setSelectionMode(QAbstractItemView::NoSelection); + layout->addWidget(m_content, 100); + + set_tile(nullptr); + } } /** @@ -166,6 +193,18 @@ void tileset_debugger::set_tile(const ::tile *t) m_content->expandAll(); } +/** + * Enters or exits tile picking mode. + */ +void tileset_debugger::refresh(const struct tileset *t) +{ + // Refresh the tile info, if any + set_tile(m_tile); + + // Reload messages + refresh_messages(t); +} + /** * Enters or exits tile picking mode. */ @@ -174,4 +213,34 @@ void tileset_debugger::pick_tile(bool active) emit tile_picking_requested(active); } +/** + * Refresh the messages list + */ +void tileset_debugger::refresh_messages(const struct tileset *t) +{ + fc_assert_ret(t != nullptr); + + m_messages->clear(); + + const auto log = tileset_log(t); + for (std::size_t i = 0; i < log.size(); ++i) { + auto item = new QListWidgetItem; + switch (log[i].level) { + case QtFatalMsg: + case QtCriticalMsg: + item->setIcon(QIcon::fromTheme(QStringLiteral("data-error"))); + break; + case QtWarningMsg: + item->setIcon(QIcon::fromTheme(QStringLiteral("data-warning"))); + break; + case QtInfoMsg: + case QtDebugMsg: + item->setIcon(QIcon::fromTheme(QStringLiteral("data-information"))); + break; + } + item->setText(log[i].message); + m_messages->addItem(item); + } +} + } // namespace freeciv diff --git a/client/gui-qt/tileset_debugger.h b/client/gui-qt/tileset_debugger.h index 54b40ba8e8..ebfcf6c39e 100644 --- a/client/gui-qt/tileset_debugger.h +++ b/client/gui-qt/tileset_debugger.h @@ -13,9 +13,11 @@ class QAction; class QLabel; +class QListWidget; class QTreeWidget; struct tile; +struct tileset; namespace freeciv { @@ -26,6 +28,8 @@ class tileset_debugger : public QDialog { explicit tileset_debugger(QWidget *parent = nullptr); virtual ~tileset_debugger(); + void refresh(const struct tileset *t); + const ::tile *tile() const { return m_tile; } void set_tile(const ::tile *t); @@ -36,9 +40,12 @@ private slots: void pick_tile(bool active); private: + void refresh_messages(const struct tileset *t); + const ::tile *m_tile; QLabel *m_label; QAction *m_pick_action; + QListWidget *m_messages; QTreeWidget *m_content; }; diff --git a/data/themes/gui-qt/NightStalker/resource.qss b/data/themes/gui-qt/NightStalker/resource.qss index ddd62e2edc..ec0a391f70 100644 --- a/data/themes/gui-qt/NightStalker/resource.qss +++ b/data/themes/gui-qt/NightStalker/resource.qss @@ -463,6 +463,7 @@ QRadioButton::indicator:checked:pressed { QListView { background-color: #414a57; border: none; + color: white; } QListView:item::hover {