From 91e27ef1628b352e1f905b5811cb036442e68242 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Wed, 29 Aug 2018 20:38:31 +0200 Subject: [PATCH] qtui: Add debug dialog for showing the resource file tree Add a dialog in the debug menu that shows the compiled-in resource files. This is useful for checking that resource generation and loading works properly. --- src/client/treemodel.cpp | 6 +++ src/client/treemodel.h | 2 + src/qtui/CMakeLists.txt | 2 + src/qtui/mainwin.cpp | 11 +++++- src/qtui/mainwin.h | 1 + src/qtui/resourcetreedlg.cpp | 57 +++++++++++++++++++++++++++++ src/qtui/resourcetreedlg.h | 36 ++++++++++++++++++ src/qtui/resourcetreedlg.ui | 71 ++++++++++++++++++++++++++++++++++++ 8 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 src/qtui/resourcetreedlg.cpp create mode 100644 src/qtui/resourcetreedlg.h create mode 100644 src/qtui/resourcetreedlg.ui diff --git a/src/client/treemodel.cpp b/src/client/treemodel.cpp index a8cd86b7..892ad5c8 100644 --- a/src/client/treemodel.cpp +++ b/src/client/treemodel.cpp @@ -347,6 +347,12 @@ TreeModel::~TreeModel() } +AbstractTreeItem *TreeModel::root() const +{ + return rootItem; +} + + QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent) const { if (row < 0 || row >= rowCount(parent) || column < 0 || column >= columnCount(parent)) diff --git a/src/client/treemodel.h b/src/client/treemodel.h index 12da2ed2..92bf7676 100644 --- a/src/client/treemodel.h +++ b/src/client/treemodel.h @@ -154,6 +154,8 @@ public: TreeModel(const QList &, QObject *parent = 0); virtual ~TreeModel(); + AbstractTreeItem *root() const; + virtual QVariant data(const QModelIndex &index, int role) const; virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); diff --git a/src/qtui/CMakeLists.txt b/src/qtui/CMakeLists.txt index d47a4ccf..10100d89 100644 --- a/src/qtui/CMakeLists.txt +++ b/src/qtui/CMakeLists.txt @@ -42,6 +42,7 @@ target_sources(${TARGET} PRIVATE qtuisettings.cpp qtuistyle.cpp receivefiledlg.cpp + resourcetreedlg.cpp settingsdlg.cpp settingspagedlg.cpp simplenetworkeditor.cpp @@ -77,6 +78,7 @@ target_sources(${TARGET} PRIVATE nicklistwidget.ui passwordchangedlg.ui receivefiledlg.ui + resourcetreedlg.ui settingsdlg.ui settingspagedlg.ui simplenetworkeditor.ui diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index f2c13886..2ce724b2 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -86,6 +86,7 @@ #include "qtuisettings.h" #include "qtuistyle.h" #include "receivefiledlg.h" +#include "resourcetreedlg.h" #include "settingsdlg.h" #include "settingspagedlg.h" #include "statusnotifieritem.h" @@ -454,6 +455,8 @@ void MainWin::setupActions() this, SLOT(on_actionDebugHotList_triggered()))); coll->addAction("DebugLog", new Action(icon::get("tools-report-bug"), tr("Debug &Log"), coll, this, SLOT(on_actionDebugLog_triggered()))); + coll->addAction("ShowResourceTree", new Action(icon::get("tools-report-bug"), tr("Show &Resource Tree"), coll, + this, SLOT(on_actionShowResourceTree_triggered()))); coll->addAction("ReloadStyle", new Action(icon::get("view-refresh"), tr("Reload Stylesheet"), coll, QtUi::style(), SLOT(reload()), QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_R))); @@ -629,6 +632,7 @@ void MainWin::setupMenus() _helpDebugMenu->addAction(coll->action("DebugMessageModel")); _helpDebugMenu->addAction(coll->action("DebugHotList")); _helpDebugMenu->addAction(coll->action("DebugLog")); + _helpDebugMenu->addAction(coll->action("ShowResourceTree")); _helpDebugMenu->addSeparator(); _helpDebugMenu->addAction(coll->action("ReloadStyle")); @@ -1975,10 +1979,15 @@ void MainWin::on_actionDebugMessageModel_triggered() void MainWin::on_actionDebugLog_triggered() { - auto dlg = new DebugLogDlg(this); + auto dlg = new DebugLogDlg(this); // will be deleted on close dlg->show(); } +void MainWin::on_actionShowResourceTree_triggered() +{ + auto dlg = new ResourceTreeDlg(this); // will be deleted on close + dlg->show(); +} void MainWin::showStatusBarMessage(const QString &message) { diff --git a/src/qtui/mainwin.h b/src/qtui/mainwin.h index 9b422504..f9e53e39 100644 --- a/src/qtui/mainwin.h +++ b/src/qtui/mainwin.h @@ -204,6 +204,7 @@ private slots: void on_actionDebugMessageModel_triggered(); void on_actionDebugHotList_triggered(); void on_actionDebugLog_triggered(); + void on_actionShowResourceTree_triggered(); void bindJumpKey(); void onJumpKey(); diff --git a/src/qtui/resourcetreedlg.cpp b/src/qtui/resourcetreedlg.cpp new file mode 100644 index 00000000..7616cf07 --- /dev/null +++ b/src/qtui/resourcetreedlg.cpp @@ -0,0 +1,57 @@ +/*************************************************************************** + * Copyright (C) 2005-2018 by the Quassel Project * + * devel@quassel-irc.org * + * * + * 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include "resourcetreedlg.h" + +#include +#include + +#include "treemodel.h" + +namespace { + +void addEntries(const QString &dir, AbstractTreeItem *parentItem) { + + auto entries = QDir{dir}.entryInfoList(QDir::AllEntries|QDir::NoDotAndDotDot, QDir::Name|QDir::DirsFirst); + QList itemList; + for (auto &&entry : entries) { + auto item = new SimpleTreeItem({entry.fileName(), entry.size()}, parentItem); + itemList << item; + if (entry.isDir()) { + addEntries(entry.absoluteFilePath(), item); + } + } + parentItem->newChilds(itemList); +} + +} + +ResourceTreeDlg::ResourceTreeDlg(QWidget *parent) + : QDialog(parent) +{ + ui.setupUi(this); + setAttribute(Qt::WA_DeleteOnClose, true); + + // We can't use QFileSystemModel, because it doesn't support the virtual resource file system :( + auto model = new TreeModel({tr("File"), tr("Size")}, this); + addEntries(":/", model->root()); + ui.treeView->setModel(model); + ui.treeView->resizeColumnToContents(0); +} diff --git a/src/qtui/resourcetreedlg.h b/src/qtui/resourcetreedlg.h new file mode 100644 index 00000000..d2dd77c1 --- /dev/null +++ b/src/qtui/resourcetreedlg.h @@ -0,0 +1,36 @@ +/*************************************************************************** + * Copyright (C) 2005-2018 by the Quassel Project * + * devel@quassel-irc.org * + * * + * 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#pragma once + +#include + +#include "ui_resourcetreedlg.h" + +class ResourceTreeDlg : public QDialog +{ + Q_OBJECT + +public: + ResourceTreeDlg(QWidget *parent = nullptr); + +private: + Ui::ResourceTreeDlg ui; +}; diff --git a/src/qtui/resourcetreedlg.ui b/src/qtui/resourcetreedlg.ui new file mode 100644 index 00000000..e916a526 --- /dev/null +++ b/src/qtui/resourcetreedlg.ui @@ -0,0 +1,71 @@ + + + ResourceTreeDlg + + + + 0 + 0 + 474 + 399 + + + + Resource Tree + + + + + + Shows the contents of the compiled-in resource tree. + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + + + buttonBox + accepted() + ResourceTreeDlg + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ResourceTreeDlg + reject() + + + 316 + 260 + + + 286 + 274 + + + + + -- 2.20.1