console: Add a Qt debug tab

Add a tab for Qt debug features. Initially provides access to dumpObjectTree() on
Application and MainWindow objects. This dumps the object's child objects to the
log.
This commit is contained in:
Jim Broadus 2020-05-25 22:02:19 -07:00 committed by John Maguire
parent 32367d2d45
commit 0271f43cc9
3 changed files with 82 additions and 0 deletions

View File

@ -8,17 +8,24 @@
#include "core/application.h"
#include "core/database.h"
#include "core/logging.h"
Console::Console(Application* app, QWidget* parent)
: QDialog(parent), app_(app) {
ui_.setupUi(this);
connect(ui_.database_run, SIGNAL(clicked()), SLOT(RunQuery()));
connect(ui_.qt_dump_button, SIGNAL(clicked()), SLOT(Dump()));
QFont font("Monospace");
font.setStyleHint(QFont::TypeWriter);
ui_.database_output->setFont(font);
ui_.database_query->setFont(font);
QList<QObject*> objs = GetTopLevelObjects();
for (QObject* obj : objs)
ui_.qt_dump_box->addItem(obj->objectName() + " object tree",
obj->objectName());
}
void Console::RunQuery() {
@ -45,3 +52,28 @@ void Console::RunQuery() {
ui_.database_output->verticalScrollBar()->setValue(
ui_.database_output->verticalScrollBar()->maximum());
}
void Console::Dump() {
QString item = ui_.qt_dump_box->currentData().toString();
QObject* obj = FindTopLevelObject(item);
if (obj == nullptr) {
qLog(Error) << "Object not found" << item;
return;
}
obj->dumpObjectTree();
}
QList<QObject*> Console::GetTopLevelObjects() {
QList<QObject*> objs;
objs << app_;
// The parent should be the main window.
if (parent() != nullptr) objs << parent();
return objs;
}
QObject* Console::FindTopLevelObject(QString& name) {
for (QObject* obj : GetTopLevelObjects())
if (obj->objectName() == name) return obj;
return nullptr;
}

View File

@ -13,9 +13,14 @@ class Console : public QDialog {
Console(Application* app, QWidget* parent = nullptr);
private slots:
// Database
void RunQuery();
// Qt
void Dump();
private:
QList<QObject*> GetTopLevelObjects();
QObject* FindTopLevelObject(QString& name);
Ui::Console ui_;
Application* app_;
};

View File

@ -48,6 +48,51 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="qt_tab">
<attribute name="title">
<string>Qt</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="qt_dump_group">
<property name="title">
<string>Dump To Logs</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QComboBox" name="qt_dump_box"/>
</item>
<item>
<widget class="QPushButton" name="qt_dump_button">
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>dump</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>