Commit bb39af73 authored by dogmaphobic's avatar dogmaphobic

Merge remote-tracking branch 'Mavlink/master' into preferencesPanel

* Mavlink/master:
  Log selection support fron Settings/Console
  Remove X to close since it conflicts with QGCViewDialogs
parents e2d9e4bc 4c3c6da4
......@@ -268,72 +268,8 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
ParseCmdLineOptions(argc, argv, rgCmdLineOptions, sizeof(rgCmdLineOptions)/sizeof(rgCmdLineOptions[0]), false);
#ifdef __mobile__
QLoggingCategory::setFilterRules(QStringLiteral("*Log.debug=false"));
#else
QString filterRules;
// Turn off bogus ssl warning
filterRules += "qt.network.ssl.warning=false\n";
if (logging) {
QStringList logList = loggingOptions.split(",");
if (logList[0] == "full") {
filterRules += "*Log.debug=true\n";
for(int i=1; i<logList.count(); i++) {
filterRules += logList[i];
filterRules += ".debug=false\n";
}
} else {
foreach(const QString &rule, logList) {
filterRules += rule;
filterRules += ".debug=true\n";
}
}
} else {
// First thing we want to do is set up the qtlogging.ini file. If it doesn't already exist we copy
// it to the correct location. This way default debug builds will have logging turned off.
static const char* qtProjectDir = "QtProject";
static const char* qtLoggingFile = "qtlogging.ini";
bool loggingDirectoryOk = false;
QDir iniFileLocation(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation));
if (!iniFileLocation.cd(qtProjectDir)) {
if (!iniFileLocation.mkdir(qtProjectDir)) {
qDebug() << "Unable to create qtlogging.ini directory" << iniFileLocation.filePath(qtProjectDir);
} else {
if (!iniFileLocation.cd(qtProjectDir)) {
qDebug() << "Unable to access qtlogging.ini directory" << iniFileLocation.filePath(qtProjectDir);;
}
loggingDirectoryOk = true;
}
} else {
loggingDirectoryOk = true;
}
if (loggingDirectoryOk) {
qDebug () << "Logging ini file directory" << iniFileLocation.absolutePath();
if (!iniFileLocation.exists(qtLoggingFile)) {
QFile loggingFile(iniFileLocation.filePath(qtLoggingFile));
if (loggingFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream out(&loggingFile);
out << "[Rules]\n";
out << "*Log.debug=false\n";
foreach(const QString &category, QGCLoggingCategoryRegister::instance()->registeredCategories()) {
out << category << ".debug=false\n";
}
} else {
qDebug() << "Unable to create logging file" << QString(qtLoggingFile) << "in" << iniFileLocation;
}
}
}
}
qDebug() << "Filter rules" << filterRules;
QLoggingCategory::setFilterRules(filterRules);
#endif
// Set up our logging filters
QGCLoggingCategoryRegister::instance()->setFilterRulesFromSettings(loggingOptions);
// Set up timer for delayed missing fact display
_missingParamsDelayedDisplayTimer.setSingleShot(true);
......
......@@ -26,6 +26,8 @@
#include "QGCLoggingCategory.h"
#include <QSettings>
// Add Global logging categories (not class specific) here using QGC_LOGGING_CATEGORY
QGC_LOGGING_CATEGORY(FirmwareUpgradeLog, "FirmwareUpgradeLog")
QGC_LOGGING_CATEGORY(FirmwareUpgradeVerboseLog, "FirmwareUpgradeVerboseLog")
......@@ -34,6 +36,7 @@ QGC_LOGGING_CATEGORY(MissionItemLog, "MissionItemLog")
QGC_LOGGING_CATEGORY(ParameterLoaderLog, "ParameterLoaderLog")
QGCLoggingCategoryRegister* _instance = NULL;
const char* QGCLoggingCategoryRegister::_filterRulesSettingsGroup = "LoggingFilters";
QGCLoggingCategoryRegister* QGCLoggingCategoryRegister::instance(void)
{
......@@ -44,3 +47,66 @@ QGCLoggingCategoryRegister* QGCLoggingCategoryRegister::instance(void)
return _instance;
}
QStringList QGCLoggingCategoryRegister::registeredCategories(void)
{
_registeredCategories.sort();
return _registeredCategories;
}
void QGCLoggingCategoryRegister::setCategoryLoggingOn(const QString& category, bool enable)
{
QSettings settings;
settings.beginGroup(_filterRulesSettingsGroup);
settings.setValue(category, enable);
}
bool QGCLoggingCategoryRegister::categoryLoggingOn(const QString& category)
{
QSettings settings;
settings.beginGroup(_filterRulesSettingsGroup);
return settings.value(category, false).toBool();
}
void QGCLoggingCategoryRegister::setFilterRulesFromSettings(const QString& commandLineLoggingOptions)
{
if (!commandLineLoggingOptions.isEmpty()) {
_commandLineLoggingOptions = commandLineLoggingOptions;
}
QString filterRules;
// Turn off bogus ssl warning
filterRules += "qt.network.ssl.warning=false\n";
filterRules += "*Log.debug=false\n";
// Set up filters defined in settings
foreach (QString category, _registeredCategories) {
if (categoryLoggingOn(category)) {
filterRules += category;
filterRules += ".debug=true\n";
}
}
// Command line rules take precedence, so they go last in the list
if (!_commandLineLoggingOptions.isEmpty()) {
QStringList logList = _commandLineLoggingOptions.split(",");
if (logList[0] == "full") {
filterRules += "*Log.debug=true\n";
for(int i=1; i<logList.count(); i++) {
filterRules += logList[i];
filterRules += ".debug=false\n";
}
} else {
foreach(const QString &rule, logList) {
filterRules += rule;
filterRules += ".debug=true\n";
}
}
}
qDebug() << "Filter rules" << filterRules;
QLoggingCategory::setFilterRules(filterRules);
}
......@@ -44,18 +44,36 @@ Q_DECLARE_LOGGING_CATEGORY(ParameterLoaderLog)
static QGCLoggingCategory qgcCategory ## name (__VA_ARGS__); \
Q_LOGGING_CATEGORY(name, __VA_ARGS__)
class QGCLoggingCategoryRegister
class QGCLoggingCategoryRegister : public QObject
{
Q_OBJECT
public:
static QGCLoggingCategoryRegister* instance(void);
/// Registers the specified logging category to the system.
void registerCategory(const char* category) { _registeredCategories << category; }
const QStringList& registeredCategories(void) { return _registeredCategories; }
/// Returns the list of available logging category names.
Q_INVOKABLE QStringList registeredCategories(void);
/// Turns on/off logging for the specified category. State is saved in app settings.
Q_INVOKABLE void setCategoryLoggingOn(const QString& category, bool enable);
/// Returns true if logging is turned on for the specified category.
Q_INVOKABLE bool categoryLoggingOn(const QString& category);
/// Sets the logging filters rules from saved settings.
/// @param commandLineLogggingOptions Logging options which were specified on the command line
void setFilterRulesFromSettings(const QString& commandLineLoggingOptions);
private:
QGCLoggingCategoryRegister(void) { }
QStringList _registeredCategories;
QString _commandLineLoggingOptions;
static const char* _filterRulesSettingsGroup;
};
class QGCLoggingCategory
......
......@@ -26,115 +26,166 @@ import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
import QtQuick.Dialogs 1.2
import QGroundControl 1.0
import QGroundControl.Palette 1.0
import QGroundControl.Controls 1.0
import QGroundControl.Controllers 1.0
import QGroundControl.ScreenTools 1.0
Rectangle {
id: logwindow
anchors.fill: parent
anchors.margins: ScreenTools.defaultFontPixelWidth
color: qgcPal.window
QGCView {
id: qgcView
viewPanel: panel
property bool loaded: false
QGCPalette { id: qgcPal }
QGCPalette { id: qgcPal; colorGroupEnabled: panel.enabled }
Connections {
target: debugMessageModel
onDataChanged: {
// Keep the view in sync if the button is checked
if (loaded) {
if (followTail.checked) {
listview.positionViewAtEnd();
Component {
id: filtersDialogComponent
QGCViewDialog {
QGCFlickable {
anchors.fill: parent
contentHeight: categoryColumn.height
clip: true
Column {
id: categoryColumn
spacing: ScreenTools.defaultFontPixelHeight / 2
Repeater {
model: QGroundControl.loggingCategories()
QGCCheckBox {
text: modelData
checked: QGroundControl.categoryLoggingOn(modelData)
onClicked: {
QGroundControl.setCategoryLoggingOn(modelData, checked)
QGroundControl.updateLoggingFilterRules()
}
}
}
}
}
}
}
} // QGCViewDialog
} // Component - filtersDialogComponent
QGCViewPanel {
id: panel
anchors.fill: parent
Component {
id: delegateItem
Rectangle {
color: index % 2 == 0 ? qgcPal.window : qgcPal.windowShade
height: Math.round(ScreenTools.defaultFontPixelHeight * 0.5 + field.height)
width: listview.width
Text {
id: field
text: display
color: qgcPal.text
width: parent.width
wrapMode: Text.Wrap
font.family: ScreenTools.normalFontFamily
anchors.verticalCenter: parent.verticalCenter
id: logwindow
anchors.fill: parent
anchors.margins: ScreenTools.defaultFontPixelWidth
color: qgcPal.window
Connections {
target: debugMessageModel
onDataChanged: {
// Keep the view in sync if the button is checked
if (loaded) {
if (followTail.checked) {
listview.positionViewAtEnd();
}
}
}
}
}
}
ListView {
Component.onCompleted: {
loaded = true
}
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: followTail.top
anchors.bottomMargin: ScreenTools.defaultFontPixelWidth
clip: true
id: listview
model: debugMessageModel
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
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 {
id: followTail
anchors.bottom: parent.bottom
anchors.right: parent.right
text: "Show Latest"
checkable: true
checked: true
onCheckedChanged: {
if (checked && loaded) {
listview.positionViewAtEnd();
Component {
id: delegateItem
Rectangle {
color: index % 2 == 0 ? qgcPal.window : qgcPal.windowShade
height: Math.round(ScreenTools.defaultFontPixelHeight * 0.5 + field.height)
width: listview.width
Text {
id: field
text: display
color: qgcPal.text
width: parent.width
wrapMode: Text.Wrap
font.family: ScreenTools.normalFontFamily
anchors.verticalCenter: parent.verticalCenter
}
}
}
ListView {
Component.onCompleted: {
loaded = true
}
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: followTail.top
anchors.bottomMargin: ScreenTools.defaultFontPixelWidth
clip: true
id: listview
model: debugMessageModel
delegate: delegateItem
}
FileDialog {
id: writeDialog
folder: shortcuts.home
nameFilters: [qsTr("Log files (*.txt)"), qsTr("All Files (*)")]
selectExisting: false
title: qsTr("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
onClicked: writeDialog.visible = true
text: qsTr("Save App Log")
}
BusyIndicator {
id: writeBusy
anchors.bottom: writeButton.bottom
anchors.left: writeButton.right
height: writeButton.height
visible: !writeButton.enabled
}
QGCButton {
id: followTail
anchors.right: filterButton.left
anchors.rightMargin: ScreenTools.defaultFontPixelWidth
anchors.bottom: parent.bottom
text: qsTr("Show Latest")
checkable: true
checked: true
onCheckedChanged: {
if (checked && loaded) {
listview.positionViewAtEnd();
}
}
}
QGCButton {
id: filterButton
anchors.bottom: parent.bottom
anchors.right: parent.right
text: qsTr("Set logging")
onClicked: showDialog(filtersDialogComponent, qsTr("Turn on logging categories"), qgcView.showDialogDefaultWidth, StandardButton.Close)
}
}
}
}
} // QGCViewPanel
} // QGCView
......@@ -36,6 +36,7 @@
#include "SettingsFact.h"
#include "FactMetaData.h"
#include "SimulatedPosition.h"
#include "QGCLoggingCategory.h"
#ifdef QT_DEBUG
#include "MockLink.h"
......@@ -133,6 +134,18 @@ public:
QString appSettingsDistanceUnitsString(void) const { return FactMetaData::appSettingsDistanceUnitsString(); }
/// Returns the list of available logging category names.
Q_INVOKABLE QStringList loggingCategories(void) const { return QGCLoggingCategoryRegister::instance()->registeredCategories(); }
/// Turns on/off logging for the specified category. State is saved in app settings.
Q_INVOKABLE void setCategoryLoggingOn(const QString& category, bool enable) { QGCLoggingCategoryRegister::instance()->setCategoryLoggingOn(category, enable); };
/// Returns true if logging is turned on for the specified category.
Q_INVOKABLE bool categoryLoggingOn(const QString& category) { return QGCLoggingCategoryRegister::instance()->categoryLoggingOn(category); };
/// Updates the logging filter rules after settings have changed
Q_INVOKABLE void updateLoggingFilterRules(void) { QGCLoggingCategoryRegister::instance()->setFilterRulesFromSettings(QString()); }
// Property accesors
FlightMapSettings* flightMapSettings () { return _flightMapSettings; }
......
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