qtui: Add debug dialog for showing the resource file tree
authorManuel Nickschas <sputnick@quassel-irc.org>
Wed, 29 Aug 2018 18:38:31 +0000 (20:38 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 18 Nov 2018 10:06:43 +0000 (11:06 +0100)
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
src/client/treemodel.h
src/qtui/CMakeLists.txt
src/qtui/mainwin.cpp
src/qtui/mainwin.h
src/qtui/resourcetreedlg.cpp [new file with mode: 0644]
src/qtui/resourcetreedlg.h [new file with mode: 0644]
src/qtui/resourcetreedlg.ui [new file with mode: 0644]

index a8cd86b..892ad5c 100644 (file)
@@ -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))
index 12da2ed..92bf767 100644 (file)
@@ -154,6 +154,8 @@ public:
     TreeModel(const QList<QVariant> &, 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);
 
index d47a4cc..10100d8 100644 (file)
@@ -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
index f2c1388..2ce724b 100644 (file)
@@ -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)
 {
index 9b42250..f9e53e3 100644 (file)
@@ -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 (file)
index 0000000..7616cf0
--- /dev/null
@@ -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 <QDir>
+#include <QList>
+
+#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<AbstractTreeItem *> 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 (file)
index 0000000..d2dd77c
--- /dev/null
@@ -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 <QDialog>
+
+#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 (file)
index 0000000..e916a52
--- /dev/null
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ResourceTreeDlg</class>
+ <widget class="QDialog" name="ResourceTreeDlg">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>474</width>
+    <height>399</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Resource Tree</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QTreeView" name="treeView">
+     <property name="toolTip">
+      <string>Shows the contents of the compiled-in resource tree.</string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Close</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>ResourceTreeDlg</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>ResourceTreeDlg</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>