Commit bc19757e authored by Nate Weibley's avatar Nate Weibley

Add file save support for logs

parent 9ceca7fe
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <QPainter> #include <QPainter>
#include <QStyleFactory> #include <QStyleFactory>
#include <QAction> #include <QAction>
#include <QStringListModel>
#ifdef QGC_ENABLE_BLUETOOTH #ifdef QGC_ENABLE_BLUETOOTH
#include <QBluetoothLocalDevice> #include <QBluetoothLocalDevice>
...@@ -485,7 +486,7 @@ bool QGCApplication::_initForNormalAppBoot(void) ...@@ -485,7 +486,7 @@ bool QGCApplication::_initForNormalAppBoot(void)
_qmlAppEngine = new QQmlApplicationEngine(this); _qmlAppEngine = new QQmlApplicationEngine(this);
_qmlAppEngine->addImportPath("qrc:/qml"); _qmlAppEngine->addImportPath("qrc:/qml");
_qmlAppEngine->rootContext()->setContextProperty("joystickManager", toolbox()->joystickManager()); _qmlAppEngine->rootContext()->setContextProperty("joystickManager", toolbox()->joystickManager());
_qmlAppEngine->rootContext()->setContextProperty("debugMessageModel", &AppMessages::getModel()); _qmlAppEngine->rootContext()->setContextProperty("debugMessageModel", AppMessages::getModel());
_qmlAppEngine->load(QUrl(QStringLiteral("qrc:/qml/MainWindowNative.qml"))); _qmlAppEngine->load(QUrl(QStringLiteral("qrc:/qml/MainWindowNative.qml")));
#else #else
// Start the user interface // Start the user interface
......
...@@ -22,11 +22,14 @@ This file is part of the QGROUNDCONTROL project ...@@ -22,11 +22,14 @@ This file is part of the QGROUNDCONTROL project
======================================================================*/ ======================================================================*/
#include "AppMessages.h" #include "AppMessages.h"
#include <QFile>
#include <QStringListModel> #include <QStringListModel>
#include <iostream> #include <QtConcurrent>
#include <QTextStream>
AppLogModel AppLogModel::instance;
static QtMessageHandler old_handler; static QtMessageHandler old_handler;
static QStringListModel debug_strings; static AppLogModel &debug_strings = AppLogModel::getModel();
static void msgHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) static void msgHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{ {
...@@ -51,7 +54,33 @@ void AppMessages::installHandler() ...@@ -51,7 +54,33 @@ void AppMessages::installHandler()
old_handler = qInstallMessageHandler(msgHandler); old_handler = qInstallMessageHandler(msgHandler);
} }
QStringListModel& AppMessages::getModel() AppLogModel *AppMessages::getModel()
{ {
return debug_strings; return &AppLogModel::getModel();
}
AppLogModel& AppLogModel::getModel()
{
return instance;
}
AppLogModel::AppLogModel() : QStringListModel()
{
}
void AppLogModel::writeMessages(const QUrl dest_file)
{
const QString writebuffer(stringList().join('\n').append('\n'));
QtConcurrent::run([dest_file, writebuffer] {
emit instance.writeStarted();
bool success = false;
QFile file(dest_file.toLocalFile());
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream out(&file);
out << writebuffer;
success = out.status() == QTextStream::Ok;
}
emit instance.writeFinished(success);
});
} }
...@@ -23,11 +23,31 @@ This file is part of the QGROUNDCONTROL project ...@@ -23,11 +23,31 @@ This file is part of the QGROUNDCONTROL project
#pragma once #pragma once
class QStringListModel; #include <QObject>
#include <QStringListModel>
#include <QUrl>
class AppLogModel : public QStringListModel
{
Q_OBJECT
public:
static AppLogModel& getModel();
Q_INVOKABLE void writeMessages(const QUrl dest_file);
signals:
void writeStarted();
void writeFinished(bool success);
private:
AppLogModel();
static AppLogModel instance;
};
class AppMessages class AppMessages
{ {
public: public:
static void installHandler(); static void installHandler();
static QStringListModel& getModel(); static AppLogModel* getModel();
}; };
...@@ -93,8 +93,44 @@ QGCView { ...@@ -93,8 +93,44 @@ QGCView {
delegate: delegateItem delegate: delegateItem
} }
FileDialog {
id: writeDialog
folder: shortcuts.home
nameFilters: ["Log files (*.txt)", "All Files (*)"]
selectExisting: false
title: "Select log save file"
onAccepted: {
debugMessageModel.writeMessages(fileUrl);
visible = false;
}
onRejected: visible = false
}
Connections {
target: debugMessageModel
onWriteStarted: writeButton.enabled = false;
onWriteFinished: writeButton.enabled = true;
}
QGCButton {
id: writeButton
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.margins: ScreenTools.defaultFontPixelWidth
onClicked: writeDialog.visible = true
text: "Save App Log"
}
BusyIndicator {
id: writeBusy
anchors.bottom: writeButton.bottom
anchors.left: writeButton.right
height: writeButton.height
visible: !writeButton.enabled
}
QGCButton { QGCButton {
id: followTail id: followTail
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.right: parent.right anchors.right: parent.right
anchors.margins: ScreenTools.defaultFontPixelWidth anchors.margins: ScreenTools.defaultFontPixelWidth
......
...@@ -165,7 +165,7 @@ MainWindow::MainWindow() ...@@ -165,7 +165,7 @@ MainWindow::MainWindow()
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
_mainQmlWidgetHolder->setContextPropertyObject("controller", this); _mainQmlWidgetHolder->setContextPropertyObject("controller", this);
_mainQmlWidgetHolder->setContextPropertyObject("debugMessageModel", &AppMessages::getModel()); _mainQmlWidgetHolder->setContextPropertyObject("debugMessageModel", AppMessages::getModel());
_mainQmlWidgetHolder->setSource(QUrl::fromUserInput("qrc:qml/MainWindowHybrid.qml")); _mainQmlWidgetHolder->setSource(QUrl::fromUserInput("qrc:qml/MainWindowHybrid.qml"));
// Image provider // Image provider
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment