Moved LogDialog from heap to stack

This commit is contained in:
Daniel Brunner
2018-11-18 15:22:09 +01:00
parent 53559c45a0
commit e77d9515a1

View File

@@ -1,7 +1,5 @@
#include "devtoolsplugin.h" #include "devtoolsplugin.h"
#include <memory>
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
#include <QCoreApplication> #include <QCoreApplication>
@@ -16,19 +14,18 @@
#include "logmodel.h" #include "logmodel.h"
#include "logdialog.h" #include "logdialog.h"
std::shared_ptr<LogModel> model; LogModel model;
QtMessageHandler previousHandler; QtMessageHandler previousHandler;
void myMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message) void myMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message)
{ {
previousHandler(type, context, message); previousHandler(type, context, message);
model->log(type, context.file, context.line, context.function, context.category, message); model.log(type, context.file, context.line, context.function, context.category, message);
} }
void registerMessageHandler() void registerMessageHandler()
{ {
model = std::make_shared<LogModel>();
previousHandler = qInstallMessageHandler(myMessageHandler); previousHandler = qInstallMessageHandler(myMessageHandler);
} }
@@ -54,8 +51,10 @@ DevToolsPlugin::DevToolsPlugin(QObject *parent) :
void DevToolsPlugin::attachTo(MainWindow &mainWindow) void DevToolsPlugin::attachTo(MainWindow &mainWindow)
{ {
auto dialog = new LogDialog(&mainWindow);
dialog->setModel(model.get());
mainWindow.menuTools()->addAction(QIcon(QStringLiteral(":/zeiterfassung/plugins/devtoolsplugin/images/dev-tools.png")), mainWindow.menuTools()->addAction(QIcon(QStringLiteral(":/zeiterfassung/plugins/devtoolsplugin/images/dev-tools.png")),
tr("Show log"), dialog, &QWidget::show); tr("Show log"), &mainWindow, [&mainWindow](){
LogDialog dialog(&mainWindow);
dialog.setModel(&model);
dialog.exec();
});
} }