Imported existing sources

This commit is contained in:
0xFEEDC0DE64
2018-09-17 19:37:34 +02:00
parent 57f2b87525
commit 04b8ade09e
13 changed files with 449 additions and 0 deletions

61
devtoolsplugin.cpp Normal file
View File

@@ -0,0 +1,61 @@
#include "devtoolsplugin.h"
#include <memory>
#include <QDebug>
#include <QDir>
#include <QCoreApplication>
#include <QLocale>
#include <QMenu>
#include <QAction>
#include "mainwindow.h"
#include "logmodel.h"
#include "logdialog.h"
std::shared_ptr<LogModel> model;
QtMessageHandler previousHandler;
void myMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message)
{
previousHandler(type, context, message);
model->log(type, context.file, context.line, context.function, context.category, message);
}
void registerMessageHandler()
{
model = std::make_shared<LogModel>();
previousHandler = qInstallMessageHandler(myMessageHandler);
}
Q_COREAPP_STARTUP_FUNCTION(registerMessageHandler)
DevToolsPlugin::DevToolsPlugin(QObject *parent) :
ZeiterfassungPlugin(parent)
{
qDebug() << "called";
static auto dir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(QStringLiteral("translations"));
if(m_translator.load(QLocale(), QStringLiteral("devtoolsplugin"), QStringLiteral("_"), dir))
{
if(!QCoreApplication::installTranslator(&m_translator))
{
qWarning() << "could not install translation devtoolsplugin";
}
}
else
{
qWarning() << "could not load translation devtoolsplugin";
}
}
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")),
tr("Show log"), dialog, &QWidget::show);
}