2012-09-26 18:36:47 +02:00
|
|
|
#include "console.h"
|
|
|
|
|
|
|
|
#include <QFont>
|
2012-09-26 18:42:22 +02:00
|
|
|
#include <QScrollBar>
|
2012-09-26 18:36:47 +02:00
|
|
|
#include <QSqlDatabase>
|
|
|
|
#include <QSqlQuery>
|
|
|
|
#include <QSqlRecord>
|
|
|
|
|
|
|
|
#include "core/application.h"
|
|
|
|
#include "core/database.h"
|
2020-05-25 22:02:19 -07:00
|
|
|
#include "core/logging.h"
|
2012-09-26 18:36:47 +02:00
|
|
|
|
|
|
|
Console::Console(Application* app, QWidget* parent)
|
2014-02-07 16:34:20 +01:00
|
|
|
: QDialog(parent), app_(app) {
|
2012-09-26 18:36:47 +02:00
|
|
|
ui_.setupUi(this);
|
2020-05-25 16:40:55 -07:00
|
|
|
connect(ui_.database_run, SIGNAL(clicked()), SLOT(RunQuery()));
|
2020-05-25 22:02:19 -07:00
|
|
|
connect(ui_.qt_dump_button, SIGNAL(clicked()), SLOT(Dump()));
|
2012-09-26 18:36:47 +02:00
|
|
|
|
|
|
|
QFont font("Monospace");
|
|
|
|
font.setStyleHint(QFont::TypeWriter);
|
|
|
|
|
2020-05-25 16:40:55 -07:00
|
|
|
ui_.database_output->setFont(font);
|
|
|
|
ui_.database_query->setFont(font);
|
2020-05-25 22:02:19 -07:00
|
|
|
|
|
|
|
QList<QObject*> objs = GetTopLevelObjects();
|
|
|
|
for (QObject* obj : objs)
|
|
|
|
ui_.qt_dump_box->addItem(obj->objectName() + " object tree",
|
|
|
|
obj->objectName());
|
2012-09-26 18:36:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Console::RunQuery() {
|
|
|
|
QSqlDatabase db = app_->database()->Connect();
|
2020-05-25 16:40:55 -07:00
|
|
|
QSqlQuery query = db.exec(ui_.database_query->text());
|
|
|
|
ui_.database_query->clear();
|
2012-09-26 18:36:47 +02:00
|
|
|
|
2020-05-25 16:40:55 -07:00
|
|
|
ui_.database_output->append("<b>> " + query.executedQuery() + "</b>");
|
2012-09-26 18:36:47 +02:00
|
|
|
|
|
|
|
query.next();
|
|
|
|
|
|
|
|
while (query.isValid()) {
|
|
|
|
QSqlRecord record = query.record();
|
|
|
|
QStringList values;
|
|
|
|
for (int i = 0; i < record.count(); ++i) {
|
|
|
|
values.append(record.value(i).toString());
|
|
|
|
}
|
|
|
|
|
2020-05-25 16:40:55 -07:00
|
|
|
ui_.database_output->append(values.join("|"));
|
2012-09-26 18:36:47 +02:00
|
|
|
|
|
|
|
query.next();
|
|
|
|
}
|
2012-09-26 18:42:22 +02:00
|
|
|
|
2020-05-25 16:40:55 -07:00
|
|
|
ui_.database_output->verticalScrollBar()->setValue(
|
|
|
|
ui_.database_output->verticalScrollBar()->maximum());
|
2012-09-26 18:36:47 +02:00
|
|
|
}
|
2020-05-25 22:02:19 -07:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2020-12-31 13:30:59 -08:00
|
|
|
|
|
|
|
void Console::AddPage(QWidget* page, const QString& label) {
|
|
|
|
ui_.tabWidget->addTab(page, label);
|
|
|
|
}
|