1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-03-22 14:19:42 +01:00

OP-1244 Added csv export implementation.

This commit is contained in:
m_thread 2014-02-26 12:36:53 +01:00
parent b7ab2701a4
commit c5549a287b
2 changed files with 25 additions and 1 deletions

View File

@ -241,6 +241,17 @@ void FlightLogManager::exportToOPL(QString fileName)
void FlightLogManager::exportToCSV(QString fileName)
{
QFile csvFile(fileName);
if (csvFile.open(QFile::ReadWrite)) {
QTextStream csvStream(&csvFile);
csvStream << "Flight" << '\t' << "Flight Time" << '\t' << "Entry" << '\t' << "Data" << '\n';
foreach (ExtendedDebugLogEntry *entry , m_logEntries) {
entry->toCSV(&csvStream);
}
csvFile.flush();
csvFile.close();
}
}
void FlightLogManager::exportToXML(QString fileName)
@ -254,7 +265,7 @@ void FlightLogManager::exportToXML(QString fileName)
xmlWriter.writeStartDocument("1.0", true);
xmlWriter.writeStartElement("logs");
xmlWriter.writeComment("This file was created by the export function in OpenPilot GCS.");
xmlWriter.writeComment("This file was created by the flight log export in OpenPilot GCS.");
foreach (ExtendedDebugLogEntry *entry , m_logEntries) {
entry->toXML(&xmlWriter);
}
@ -367,6 +378,17 @@ void ExtendedDebugLogEntry::toXML(QXmlStreamWriter *xmlWriter)
xmlWriter->writeEndElement(); //entry
}
void ExtendedDebugLogEntry::toCSV(QTextStream *csvStream)
{
QString data;
if (getType() == DebugLogEntry::TYPE_TEXT) {
data = QString((const char *)getData().Data);
} else if (getType() == DebugLogEntry::TYPE_UAVOBJECT) {
data = m_object->toString().replace("\n", "").replace("\t", "");
}
*csvStream << QString::number(getFlight()) << '\t' << QString::number(getFlightTime()) << '\t' << QString::number(getEntry()) << '\t' << data << '\n';
}
void ExtendedDebugLogEntry::setData(const DebugLogEntry::DataFields &data, UAVObjectManager *objectManager)
{
DebugLogEntry::setData(data);

View File

@ -33,6 +33,7 @@
#include <QQmlListProperty>
#include <QSemaphore>
#include <QXmlStreamWriter>
#include <QTextStream>
#include "uavobjectmanager.h"
#include "debuglogentry.h"
@ -48,6 +49,7 @@ public:
QString getLogString();
void toXML(QXmlStreamWriter *xmlWriter);
void toCSV(QTextStream *csvStream);
UAVDataObject *uavObject()
{
return m_object;