diff --git a/ground/openpilotgcs/src/plugins/flightlog/FlightLogDialog.qml b/ground/openpilotgcs/src/plugins/flightlog/FlightLogDialog.qml index 94dc4e884..4b36b2bc8 100644 --- a/ground/openpilotgcs/src/plugins/flightlog/FlightLogDialog.qml +++ b/ground/openpilotgcs/src/plugins/flightlog/FlightLogDialog.qml @@ -4,6 +4,8 @@ import QtQuick.Layouts 1.0 import org.openpilot 1.0 +import "functions.js" as Functions + Rectangle { width: 600 height: 400 @@ -32,7 +34,9 @@ Rectangle { model: logManager.logEntries itemDelegate: Text { - anchors.margins: 3 + anchors.fill: parent + anchors.margins: 2 + anchors.leftMargin: 5 font.pixelSize: 12 text: styleData.value } @@ -41,19 +45,32 @@ Rectangle { role: "Flight"; title: qsTr("Flight"); width: 50; delegate: Text { - anchors.margins: 3 + anchors.fill: parent + anchors.margins: 2 + anchors.leftMargin: 5 font.pixelSize: 12 text: styleData.value + 1 } } - TableViewColumn { role: "FlightTime"; title: qsTr("Time"); width: 50} - TableViewColumn { role: "Entry"; title: qsTr("#"); width: 50} TableViewColumn { - role: "Type"; title: "Type"; width: 100; + role: "FlightTime"; title: qsTr("Time"); width: 80; delegate: Text { - anchors.margins: 3 + anchors.fill: parent + anchors.margins: 2 + anchors.leftMargin: 5 + font.pixelSize: 12 + text: Functions.millisToTime(styleData.value) + } + } + TableViewColumn { + role: "Type"; title: "Type"; width: 50; + delegate: + Text { + anchors.fill: parent + anchors.margins: 2 + anchors.leftMargin: 5 font.pixelSize: 12 text: { switch(styleData.value) { diff --git a/ground/openpilotgcs/src/plugins/flightlog/flightLog.qrc b/ground/openpilotgcs/src/plugins/flightlog/flightLog.qrc index c58558e22..4283127f5 100644 --- a/ground/openpilotgcs/src/plugins/flightlog/flightLog.qrc +++ b/ground/openpilotgcs/src/plugins/flightlog/flightLog.qrc @@ -1,5 +1,6 @@ FlightLogDialog.qml + functions.js diff --git a/ground/openpilotgcs/src/plugins/flightlog/flightlog.pro b/ground/openpilotgcs/src/plugins/flightlog/flightlog.pro index 71adb9647..1aa79b004 100644 --- a/ground/openpilotgcs/src/plugins/flightlog/flightlog.pro +++ b/ground/openpilotgcs/src/plugins/flightlog/flightlog.pro @@ -15,7 +15,8 @@ SOURCES += flightlogplugin.cpp \ flightlogdialog.cpp OTHER_FILES += Flightlog.pluginspec \ - FlightLogDialog.qml + FlightLogDialog.qml \ + functions.js FORMS += diff --git a/ground/openpilotgcs/src/plugins/flightlog/flightlogmanager.cpp b/ground/openpilotgcs/src/plugins/flightlog/flightlogmanager.cpp index b7909414d..2060ad4cc 100644 --- a/ground/openpilotgcs/src/plugins/flightlog/flightlogmanager.cpp +++ b/ground/openpilotgcs/src/plugins/flightlog/flightlogmanager.cpp @@ -116,6 +116,7 @@ void FlightLogManager::retrieveLogs(int flightToRetrieve) { //Ok, we retrieved the entry, and it was the correct one. clone it and add it to the list ExtendedDebugLogEntry* logEntry = new ExtendedDebugLogEntry(); + logEntry->setObjectManager(m_objectManager); logEntry->setData(m_flightLogEntry->getData()); m_logEntries.append(logEntry); @@ -140,9 +141,37 @@ void FlightLogManager::retrieveLogs(int flightToRetrieve) { void FlightLogManager::exportLogs() { - } -ExtendedDebugLogEntry::ExtendedDebugLogEntry() : DebugLogEntry() +ExtendedDebugLogEntry::ExtendedDebugLogEntry() : DebugLogEntry(), + m_objectManager(0), m_object(0) { } + +ExtendedDebugLogEntry::~ExtendedDebugLogEntry() +{ + if(m_object) { + delete m_object; + m_object = 0; + } +} + +QString ExtendedDebugLogEntry::getLogString() +{ + if(getType() == DebugLogEntry::TYPE_TEXT) { + return QString((const char*)getData().Data); + } else if (getType() == DebugLogEntry::TYPE_UAVOBJECT) { + UAVDataObject *object = (UAVDataObject*)m_objectManager->getObject(getObjectID(), getInstanceID()); + object = object->clone(getInstanceID()); + object->unpack(getData().Data); + m_object = object; + return object->toString().replace("\n", " ").replace("\t", " "); + } else { + return ""; + } +} + +void ExtendedDebugLogEntry::setObjectManager(UAVObjectManager *objectManager) +{ + m_objectManager = objectManager; +} diff --git a/ground/openpilotgcs/src/plugins/flightlog/flightlogmanager.h b/ground/openpilotgcs/src/plugins/flightlog/flightlogmanager.h index 571d22935..d77e9ac1f 100644 --- a/ground/openpilotgcs/src/plugins/flightlog/flightlogmanager.h +++ b/ground/openpilotgcs/src/plugins/flightlog/flightlogmanager.h @@ -40,19 +40,25 @@ class ExtendedDebugLogEntry : public DebugLogEntry { Q_OBJECT - Q_PROPERTY(QString LogString READ LogString) + Q_PROPERTY(QString LogString READ getLogString WRITE setLogString NOTIFY LogStringUpdated) public: explicit ExtendedDebugLogEntry(); + ~ExtendedDebugLogEntry(); - QString LogString() - { - if(getType() == DebugLogEntry::TYPE_TEXT) { - return QString((const char*)getData().Data); - } else { - return "Object"; - } - } + QString getLogString(); + UAVDataObject* uavObject() { return m_object; } + void setObjectManager(UAVObjectManager *objectManager); + +public slots: + void setLogString(QString arg){ Q_UNUSED(arg); } + +signals: + void LogStringUpdated(QString arg); + +private: + UAVObjectManager *m_objectManager; + UAVDataObject *m_object; }; class FlightLogManager : public QObject { diff --git a/ground/openpilotgcs/src/plugins/flightlog/functions.js b/ground/openpilotgcs/src/plugins/flightlog/functions.js new file mode 100644 index 000000000..47884432b --- /dev/null +++ b/ground/openpilotgcs/src/plugins/flightlog/functions.js @@ -0,0 +1,20 @@ +.pragma library + +function millisToTime(ms) { + var secs = Math.floor(ms / 1000); + var msleft = ms % 1000; + var hours = Math.floor(secs / (60 * 60)); + var divisor_for_minutes = secs % (60 * 60); + var minutes = Math.floor(divisor_for_minutes / 60); + var divisor_for_seconds = divisor_for_minutes % 60; + var seconds = Math.ceil(divisor_for_seconds); + return pad(hours, 2) + ":" + pad(minutes, 2) + ":" + pad(seconds, 2) + ":" + pad(msleft, 3); +} + +function pad(number, length) { + var str = '' + number; + while (str.length < length) { + str = '0' + str; + } + return str; +}