Skip to content

Commit

Permalink
Add tileset messages to the tileset debugger
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lmoureaux authored and jwrober committed Jan 11, 2022
1 parent d295ed0 commit 33dd3ec
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 19 deletions.
1 change: 1 addition & 0 deletions client/gui-qt/mapview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions client/gui-qt/mapview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
107 changes: 88 additions & 19 deletions client/gui-qt/tileset_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
// utility
#include "fcintl.h"

#include <QHeaderView>
#include <QLabel>
#include <QListWidget>
#include <QPainter>
#include <QToolBar>
#include <QTreeWidget>
Expand All @@ -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);
}
}

/**
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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
7 changes: 7 additions & 0 deletions client/gui-qt/tileset_debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@

class QAction;
class QLabel;
class QListWidget;
class QTreeWidget;

struct tile;
struct tileset;

namespace freeciv {

Expand All @@ -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);

Expand All @@ -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;
};

Expand Down
1 change: 1 addition & 0 deletions data/themes/gui-qt/NightStalker/resource.qss
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ QRadioButton::indicator:checked:pressed {
QListView {
background-color: #414a57;
border: none;
color: white;
}

QListView:item::hover {
Expand Down

0 comments on commit 33dd3ec

Please sign in to comment.