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) ...@@ -268,72 +268,8 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
ParseCmdLineOptions(argc, argv, rgCmdLineOptions, sizeof(rgCmdLineOptions)/sizeof(rgCmdLineOptions[0]), false); ParseCmdLineOptions(argc, argv, rgCmdLineOptions, sizeof(rgCmdLineOptions)/sizeof(rgCmdLineOptions[0]), false);
#ifdef __mobile__ // Set up our logging filters
QLoggingCategory::setFilterRules(QStringLiteral("*Log.debug=false")); QGCLoggingCategoryRegister::instance()->setFilterRulesFromSettings(loggingOptions);
#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 timer for delayed missing fact display // Set up timer for delayed missing fact display
_missingParamsDelayedDisplayTimer.setSingleShot(true); _missingParamsDelayedDisplayTimer.setSingleShot(true);
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#include "QGCLoggingCategory.h" #include "QGCLoggingCategory.h"
#include <QSettings>
// Add Global logging categories (not class specific) here using QGC_LOGGING_CATEGORY // Add Global logging categories (not class specific) here using QGC_LOGGING_CATEGORY
QGC_LOGGING_CATEGORY(FirmwareUpgradeLog, "FirmwareUpgradeLog") QGC_LOGGING_CATEGORY(FirmwareUpgradeLog, "FirmwareUpgradeLog")
QGC_LOGGING_CATEGORY(FirmwareUpgradeVerboseLog, "FirmwareUpgradeVerboseLog") QGC_LOGGING_CATEGORY(FirmwareUpgradeVerboseLog, "FirmwareUpgradeVerboseLog")
...@@ -34,6 +36,7 @@ QGC_LOGGING_CATEGORY(MissionItemLog, "MissionItemLog") ...@@ -34,6 +36,7 @@ QGC_LOGGING_CATEGORY(MissionItemLog, "MissionItemLog")
QGC_LOGGING_CATEGORY(ParameterLoaderLog, "ParameterLoaderLog") QGC_LOGGING_CATEGORY(ParameterLoaderLog, "ParameterLoaderLog")
QGCLoggingCategoryRegister* _instance = NULL; QGCLoggingCategoryRegister* _instance = NULL;
const char* QGCLoggingCategoryRegister::_filterRulesSettingsGroup = "LoggingFilters";
QGCLoggingCategoryRegister* QGCLoggingCategoryRegister::instance(void) QGCLoggingCategoryRegister* QGCLoggingCategoryRegister::instance(void)
{ {
...@@ -44,3 +47,66 @@ QGCLoggingCategoryRegister* QGCLoggingCategoryRegister::instance(void) ...@@ -44,3 +47,66 @@ QGCLoggingCategoryRegister* QGCLoggingCategoryRegister::instance(void)
return _instance; 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) ...@@ -44,18 +44,36 @@ Q_DECLARE_LOGGING_CATEGORY(ParameterLoaderLog)
static QGCLoggingCategory qgcCategory ## name (__VA_ARGS__); \ static QGCLoggingCategory qgcCategory ## name (__VA_ARGS__); \
Q_LOGGING_CATEGORY(name, __VA_ARGS__) Q_LOGGING_CATEGORY(name, __VA_ARGS__)
class QGCLoggingCategoryRegister class QGCLoggingCategoryRegister : public QObject
{ {
Q_OBJECT
public: public:
static QGCLoggingCategoryRegister* instance(void); static QGCLoggingCategoryRegister* instance(void);
/// Registers the specified logging category to the system.
void registerCategory(const char* category) { _registeredCategories << category; } 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: private:
QGCLoggingCategoryRegister(void) { } QGCLoggingCategoryRegister(void) { }
QStringList _registeredCategories; QStringList _registeredCategories;
QString _commandLineLoggingOptions;
static const char* _filterRulesSettingsGroup;
}; };
class QGCLoggingCategory class QGCLoggingCategory
......
...@@ -26,115 +26,166 @@ import QtQuick.Controls 1.2 ...@@ -26,115 +26,166 @@ import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2 import QtQuick.Controls.Styles 1.2
import QtQuick.Dialogs 1.2 import QtQuick.Dialogs 1.2
import QGroundControl 1.0
import QGroundControl.Palette 1.0 import QGroundControl.Palette 1.0
import QGroundControl.Controls 1.0 import QGroundControl.Controls 1.0
import QGroundControl.Controllers 1.0 import QGroundControl.Controllers 1.0
import QGroundControl.ScreenTools 1.0 import QGroundControl.ScreenTools 1.0
Rectangle { QGCView {
id: logwindow id: qgcView
anchors.fill: parent viewPanel: panel
anchors.margins: ScreenTools.defaultFontPixelWidth
color: qgcPal.window
property bool loaded: false property bool loaded: false
QGCPalette { id: qgcPal } QGCPalette { id: qgcPal; colorGroupEnabled: panel.enabled }
Connections { Component {
target: debugMessageModel id: filtersDialogComponent
onDataChanged: { QGCViewDialog {
// Keep the view in sync if the button is checked QGCFlickable {
if (loaded) { anchors.fill: parent
if (followTail.checked) { contentHeight: categoryColumn.height
listview.positionViewAtEnd(); 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 { Rectangle {
color: index % 2 == 0 ? qgcPal.window : qgcPal.windowShade id: logwindow
height: Math.round(ScreenTools.defaultFontPixelHeight * 0.5 + field.height) anchors.fill: parent
width: listview.width anchors.margins: ScreenTools.defaultFontPixelWidth
color: qgcPal.window
Text {
id: field Connections {
text: display target: debugMessageModel
color: qgcPal.text
width: parent.width onDataChanged: {
wrapMode: Text.Wrap // Keep the view in sync if the button is checked
font.family: ScreenTools.normalFontFamily if (loaded) {
anchors.verticalCenter: parent.verticalCenter if (followTail.checked) {
listview.positionViewAtEnd();
}
}
}
} }
}
}
ListView { Component {
Component.onCompleted: { id: delegateItem
loaded = true Rectangle {
} color: index % 2 == 0 ? qgcPal.window : qgcPal.windowShade
anchors.top: parent.top height: Math.round(ScreenTools.defaultFontPixelHeight * 0.5 + field.height)
anchors.left: parent.left width: listview.width
anchors.right: parent.right
anchors.bottom: followTail.top Text {
anchors.bottomMargin: ScreenTools.defaultFontPixelWidth id: field
clip: true text: display
id: listview color: qgcPal.text
model: debugMessageModel width: parent.width
delegate: delegateItem wrapMode: Text.Wrap
} font.family: ScreenTools.normalFontFamily
anchors.verticalCenter: parent.verticalCenter
FileDialog { }
id: writeDialog }
folder: shortcuts.home }
nameFilters: ["Log files (*.txt)", "All Files (*)"]
selectExisting: false ListView {
title: "Select log save file" Component.onCompleted: {
onAccepted: { loaded = true
debugMessageModel.writeMessages(fileUrl); }
visible = false; anchors.top: parent.top
} anchors.left: parent.left
onRejected: visible = false anchors.right: parent.right
} anchors.bottom: followTail.top
anchors.bottomMargin: ScreenTools.defaultFontPixelWidth
Connections { clip: true
target: debugMessageModel id: listview
onWriteStarted: writeButton.enabled = false; model: debugMessageModel
onWriteFinished: writeButton.enabled = true; delegate: delegateItem
} }
QGCButton { FileDialog {
id: writeButton id: writeDialog
anchors.bottom: parent.bottom folder: shortcuts.home
anchors.left: parent.left nameFilters: [qsTr("Log files (*.txt)"), qsTr("All Files (*)")]
onClicked: writeDialog.visible = true selectExisting: false
text: "Save App Log" title: qsTr("Select log save file")
} onAccepted: {
debugMessageModel.writeMessages(fileUrl);
BusyIndicator { visible = false;
id: writeBusy }
anchors.bottom: writeButton.bottom onRejected: visible = false
anchors.left: writeButton.right }
height: writeButton.height
visible: !writeButton.enabled Connections {
} target: debugMessageModel
onWriteStarted: writeButton.enabled = false;
QGCButton { onWriteFinished: writeButton.enabled = true;
id: followTail }
anchors.bottom: parent.bottom
anchors.right: parent.right QGCButton {
text: "Show Latest" id: writeButton
checkable: true anchors.bottom: parent.bottom
checked: true anchors.left: parent.left
onClicked: writeDialog.visible = true
onCheckedChanged: { text: qsTr("Save App Log")
if (checked && loaded) { }
listview.positionViewAtEnd();
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 @@ ...@@ -36,6 +36,7 @@
#include "SettingsFact.h" #include "SettingsFact.h"
#include "FactMetaData.h" #include "FactMetaData.h"
#include "SimulatedPosition.h" #include "SimulatedPosition.h"
#include "QGCLoggingCategory.h"
#ifdef QT_DEBUG #ifdef QT_DEBUG
#include "MockLink.h" #include "MockLink.h"
...@@ -133,6 +134,18 @@ public: ...@@ -133,6 +134,18 @@ public:
QString appSettingsDistanceUnitsString(void) const { return FactMetaData::appSettingsDistanceUnitsString(); } 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 // Property accesors
FlightMapSettings* flightMapSettings () { return _flightMapSettings; } 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