1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-29 14:52:12 +01:00

OP-1119 Added Functions.js to host functions needed in qml.

Added de-serialization of UAVDataObjects in table.
Started to clean up memory management tasks in code.
This commit is contained in:
m_thread 2013-11-25 17:58:29 +01:00
parent 00d710a324
commit daf589d9ce
6 changed files with 92 additions and 18 deletions

View File

@ -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) {

View File

@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/flightlog">
<file>FlightLogDialog.qml</file>
<file>functions.js</file>
</qresource>
</RCC>

View File

@ -15,7 +15,8 @@ SOURCES += flightlogplugin.cpp \
flightlogdialog.cpp
OTHER_FILES += Flightlog.pluginspec \
FlightLogDialog.qml
FlightLogDialog.qml \
functions.js
FORMS +=

View File

@ -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;
}

View File

@ -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 {

View File

@ -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;
}