mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-19 04:52:12 +01:00
OP-1222 Added vehicle template export function.
Exports vehicle information and image plus selected settings objects to JSon. Uncrustified.
This commit is contained in:
parent
46b95ee7d1
commit
f500f33326
@ -31,7 +31,7 @@
|
||||
#include "connectiondiagram.h"
|
||||
#include "ui_connectiondiagram.h"
|
||||
|
||||
const char* ConnectionDiagram::FILE_NAME = ":/setupwizard/resources/connection-diagrams.svg";
|
||||
const char *ConnectionDiagram::FILE_NAME = ":/setupwizard/resources/connection-diagrams.svg";
|
||||
const int ConnectionDiagram::IMAGE_PADDING = 10;
|
||||
|
||||
ConnectionDiagram::ConnectionDiagram(QWidget *parent, VehicleConfigurationSource *configSource) :
|
||||
@ -50,12 +50,14 @@ ConnectionDiagram::~ConnectionDiagram()
|
||||
void ConnectionDiagram::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QWidget::resizeEvent(event);
|
||||
|
||||
fitInView();
|
||||
}
|
||||
|
||||
void ConnectionDiagram::showEvent(QShowEvent *event)
|
||||
{
|
||||
QWidget::showEvent(event);
|
||||
|
||||
fitInView();
|
||||
}
|
||||
|
||||
@ -63,8 +65,8 @@ void ConnectionDiagram::fitInView()
|
||||
{
|
||||
ui->connectionDiagram->setSceneRect(m_scene->itemsBoundingRect());
|
||||
ui->connectionDiagram->fitInView(
|
||||
m_scene->itemsBoundingRect().adjusted(-IMAGE_PADDING,-IMAGE_PADDING, IMAGE_PADDING, IMAGE_PADDING),
|
||||
Qt::KeepAspectRatio);
|
||||
m_scene->itemsBoundingRect().adjusted(-IMAGE_PADDING, -IMAGE_PADDING, IMAGE_PADDING, IMAGE_PADDING),
|
||||
Qt::KeepAspectRatio);
|
||||
}
|
||||
|
||||
void ConnectionDiagram::setupGraphicsScene()
|
||||
@ -207,7 +209,7 @@ void ConnectionDiagram::setupGraphicsScene()
|
||||
}
|
||||
|
||||
if (m_configSource->getVehicleType() == VehicleConfigurationSource::VEHICLE_FIXEDWING &&
|
||||
m_configSource->getAirspeedType() != VehicleConfigurationSource::AIRSPEED_ESTIMATE) {
|
||||
m_configSource->getAirspeedType() != VehicleConfigurationSource::AIRSPEED_ESTIMATE) {
|
||||
switch (m_configSource->getAirspeedType()) {
|
||||
case VehicleConfigurationSource::AIRSPEED_EAGLETREE:
|
||||
if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_NANO) {
|
||||
|
@ -40,14 +40,14 @@ void AirSpeedPage::initializePage(VehicleConfigurationSource *settings)
|
||||
// Enable all
|
||||
setItemDisabled(-1, false);
|
||||
if (settings->getInputType() == VehicleConfigurationSource::INPUT_SBUS ||
|
||||
settings->getInputType() == VehicleConfigurationSource::INPUT_DSM2 ||
|
||||
settings->getInputType() == VehicleConfigurationSource::INPUT_DSMX10 ||
|
||||
settings->getInputType() == VehicleConfigurationSource::INPUT_DSMX11) {
|
||||
settings->getInputType() == VehicleConfigurationSource::INPUT_DSM2 ||
|
||||
settings->getInputType() == VehicleConfigurationSource::INPUT_DSMX10 ||
|
||||
settings->getInputType() == VehicleConfigurationSource::INPUT_DSMX11) {
|
||||
// Disable non estimated sensors if ports are taken by receivers
|
||||
setItemDisabled(VehicleConfigurationSource::AIRSPEED_EAGLETREE, true);
|
||||
setItemDisabled(VehicleConfigurationSource::AIRSPEED_MS4525, true);
|
||||
if (getSelectedItem()->id() == VehicleConfigurationSource::AIRSPEED_EAGLETREE ||
|
||||
getSelectedItem()->id() == VehicleConfigurationSource::AIRSPEED_MS4525) {
|
||||
getSelectedItem()->id() == VehicleConfigurationSource::AIRSPEED_MS4525) {
|
||||
// If previously selected invalid sensor, reset to estimated
|
||||
setSelectedItem(VehicleConfigurationSource::AIRSPEED_ESTIMATE);
|
||||
}
|
||||
@ -90,4 +90,3 @@ void AirSpeedPage::setupSelection(Selection *selection)
|
||||
"ms4525-speed-sensor",
|
||||
SetupWizard::AIRSPEED_MS4525);
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,6 @@ protected:
|
||||
void initializePage(VehicleConfigurationSource *settings);
|
||||
bool validatePage(SelectionItem *selectedItem);
|
||||
void setupSelection(Selection *selection);
|
||||
|
||||
};
|
||||
|
||||
#endif // AIRSPEEDPAGE_H
|
||||
|
@ -58,10 +58,12 @@ public:
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
void setDisabled(bool disabled) {
|
||||
void setDisabled(bool disabled)
|
||||
{
|
||||
m_disabled = disabled;
|
||||
}
|
||||
bool disabled() {
|
||||
bool disabled()
|
||||
{
|
||||
return m_disabled;
|
||||
}
|
||||
|
||||
|
@ -191,6 +191,7 @@ int SetupWizard::nextId() const
|
||||
switch (getVehicleType()) {
|
||||
case VEHICLE_FIXEDWING:
|
||||
return PAGE_OUTPUT_CALIBRATION;
|
||||
|
||||
default:
|
||||
return PAGE_BIAS_CALIBRATION;
|
||||
}
|
||||
|
@ -40,7 +40,8 @@ HEADERS += setupwizardplugin.h \
|
||||
pages/escpage.h \
|
||||
pages/servopage.h \
|
||||
pages/selectionpage.h \
|
||||
pages/airframeinitialtuningpage.h
|
||||
pages/airframeinitialtuningpage.h \
|
||||
vehicletemplateexportdialog.h
|
||||
|
||||
SOURCES += setupwizardplugin.cpp \
|
||||
setupwizard.cpp \
|
||||
@ -72,7 +73,8 @@ SOURCES += setupwizardplugin.cpp \
|
||||
pages/escpage.cpp \
|
||||
pages/servopage.cpp \
|
||||
pages/selectionpage.cpp \
|
||||
pages/airframeinitialtuningpage.cpp
|
||||
pages/airframeinitialtuningpage.cpp \
|
||||
vehicletemplateexportdialog.cpp
|
||||
|
||||
OTHER_FILES += SetupWizard.pluginspec
|
||||
|
||||
@ -96,7 +98,8 @@ FORMS += \
|
||||
pages/escpage.ui \
|
||||
pages/servopage.ui \
|
||||
pages/selectionpage.ui \
|
||||
pages/airframeinitialtuningpage.ui
|
||||
pages/airframeinitialtuningpage.ui \
|
||||
vehicletemplateexportdialog.ui
|
||||
|
||||
RESOURCES += \
|
||||
wizardResources.qrc
|
||||
|
@ -36,8 +36,7 @@
|
||||
#include <coreplugin/icore.h>
|
||||
#include <QKeySequence>
|
||||
#include <coreplugin/modemanager.h>
|
||||
#include <QJsonDocument>
|
||||
#include "stabilizationsettings.h"
|
||||
#include "vehicletemplateexportdialog.h"
|
||||
|
||||
SetupWizardPlugin::SetupWizardPlugin() : wizardRunning(false)
|
||||
{}
|
||||
@ -68,10 +67,10 @@ bool SetupWizardPlugin::initialize(const QStringList & args, QString *errMsg)
|
||||
ac->addAction(cmd, "Wizard");
|
||||
|
||||
cmd = am->registerAction(new QAction(this),
|
||||
"SetupWizardPlugin.ExportJSon",
|
||||
QList<int>() <<
|
||||
Core::Constants::C_GLOBAL_ID);
|
||||
cmd->action()->setText(tr("Export Stabilization Settings"));
|
||||
"SetupWizardPlugin.ExportJSon",
|
||||
QList<int>() <<
|
||||
Core::Constants::C_GLOBAL_ID);
|
||||
cmd->action()->setText(tr("Export Wizard Vehicle Template"));
|
||||
connect(cmd->action(), SIGNAL(triggered(bool)), this, SLOT(exportSettings()));
|
||||
|
||||
Core::ModeManager::instance()->addAction(cmd, 1);
|
||||
@ -79,7 +78,6 @@ bool SetupWizardPlugin::initialize(const QStringList & args, QString *errMsg)
|
||||
ac->appendGroup("Wizard");
|
||||
ac->addAction(cmd, "Wizard");
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -103,23 +101,9 @@ void SetupWizardPlugin::showSetupWizard()
|
||||
|
||||
void SetupWizardPlugin::exportSettings()
|
||||
{
|
||||
QFile saveFile(QStringLiteral("/home/fredrik/export.json"));
|
||||
|
||||
if (!saveFile.open(QIODevice::WriteOnly)) {
|
||||
qWarning("Couldn't open save file.");
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonObject exportObject;
|
||||
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *uavoManager = pm->getObject<UAVObjectManager>();
|
||||
StabilizationSettings* settings = StabilizationSettings::GetInstance(uavoManager);
|
||||
settings->toJson(exportObject);
|
||||
|
||||
QJsonDocument saveDoc(exportObject);
|
||||
saveFile.write(saveDoc.toJson());
|
||||
VehicleTemplateExportDialog dialog;
|
||||
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
void SetupWizardPlugin::wizardTerminated()
|
||||
|
@ -116,6 +116,7 @@ void VehicleConfigurationHelper::clearModifiedObjects()
|
||||
void VehicleConfigurationHelper::applyHardwareConfiguration()
|
||||
{
|
||||
HwSettings *hwSettings = HwSettings::GetInstance(m_uavoManager);
|
||||
|
||||
Q_ASSERT(hwSettings);
|
||||
HwSettings::DataFields data = hwSettings->getData();
|
||||
|
||||
@ -193,7 +194,6 @@ void VehicleConfigurationHelper::applyHardwareConfiguration()
|
||||
}
|
||||
|
||||
if (m_configSource->getGpsType() != VehicleConfigurationSource::GPS_DISABLED) {
|
||||
|
||||
GPSSettings *gpsSettings = GPSSettings::GetInstance(m_uavoManager);
|
||||
Q_ASSERT(gpsSettings);
|
||||
GPSSettings::DataFields gpsData = gpsSettings->getData();
|
||||
@ -201,28 +201,28 @@ void VehicleConfigurationHelper::applyHardwareConfiguration()
|
||||
switch (m_configSource->getGpsType()) {
|
||||
case VehicleConfigurationSource::GPS_NMEA:
|
||||
data.OptionalModules[HwSettings::OPTIONALMODULES_GPS] = 1;
|
||||
data.RM_MainPort = HwSettings::RM_MAINPORT_GPS;
|
||||
data.GPSSpeed = HwSettings::GPSSPEED_57600;
|
||||
data.RM_MainPort = HwSettings::RM_MAINPORT_GPS;
|
||||
data.GPSSpeed = HwSettings::GPSSPEED_57600;
|
||||
gpsData.DataProtocol = GPSSettings::DATAPROTOCOL_NMEA;
|
||||
break;
|
||||
case VehicleConfigurationSource::GPS_UBX:
|
||||
data.OptionalModules[HwSettings::OPTIONALMODULES_GPS] = 1;
|
||||
data.RM_MainPort = HwSettings::RM_MAINPORT_GPS;
|
||||
data.GPSSpeed = HwSettings::GPSSPEED_57600;
|
||||
data.RM_MainPort = HwSettings::RM_MAINPORT_GPS;
|
||||
data.GPSSpeed = HwSettings::GPSSPEED_57600;
|
||||
gpsData.DataProtocol = GPSSettings::DATAPROTOCOL_UBX;
|
||||
break;
|
||||
case VehicleConfigurationSource::GPS_PLATINUM:
|
||||
data.OptionalModules[HwSettings::OPTIONALMODULES_GPS] = 1;
|
||||
data.RM_MainPort = HwSettings::RM_MAINPORT_GPS;
|
||||
data.GPSSpeed = HwSettings::GPSSPEED_115200;
|
||||
data.GPSSpeed = HwSettings::GPSSPEED_115200;
|
||||
/*
|
||||
gpsData.DataProtocol = GPSSettings::DATAPROTOCOL_UBLOX;
|
||||
AuxMagSettings *magSettings = AuxMagSettings::GetInstance(m_uavoManager);
|
||||
AuxMagSettings::DataFields magsData = magSettings->getData();
|
||||
magsData.usage = AuxMagSettings::Both;
|
||||
magSettings->setData(magsData);
|
||||
addModifiedObject(magSettings, tr("Writing External Mag sensor settings"));
|
||||
*/
|
||||
gpsData.DataProtocol = GPSSettings::DATAPROTOCOL_UBLOX;
|
||||
AuxMagSettings *magSettings = AuxMagSettings::GetInstance(m_uavoManager);
|
||||
AuxMagSettings::DataFields magsData = magSettings->getData();
|
||||
magsData.usage = AuxMagSettings::Both;
|
||||
magSettings->setData(magsData);
|
||||
addModifiedObject(magSettings, tr("Writing External Mag sensor settings"));
|
||||
*/
|
||||
break;
|
||||
default:
|
||||
data.OptionalModules[HwSettings::OPTIONALMODULES_GPS] = 0;
|
||||
@ -234,8 +234,7 @@ void VehicleConfigurationHelper::applyHardwareConfiguration()
|
||||
}
|
||||
|
||||
if (m_configSource->getVehicleType() == VehicleConfigurationSource::VEHICLE_FIXEDWING &&
|
||||
m_configSource->getAirspeedType() != VehicleConfigurationSource::AIRSPEED_DISABLED) {
|
||||
|
||||
m_configSource->getAirspeedType() != VehicleConfigurationSource::AIRSPEED_DISABLED) {
|
||||
AirspeedSettings *airspeedSettings = AirspeedSettings::GetInstance(m_uavoManager);
|
||||
Q_ASSERT(airspeedSettings);
|
||||
AirspeedSettings::DataFields airspeedData = airspeedSettings->getData();
|
||||
|
@ -60,7 +60,7 @@ public:
|
||||
enum VEHICLE_SUB_TYPE { MULTI_ROTOR_UNKNOWN, MULTI_ROTOR_TRI_Y, MULTI_ROTOR_QUAD_X, MULTI_ROTOR_QUAD_PLUS,
|
||||
MULTI_ROTOR_HEXA, MULTI_ROTOR_HEXA_H, MULTI_ROTOR_HEXA_X, MULTI_ROTOR_HEXA_COAX_Y, MULTI_ROTOR_OCTO,
|
||||
MULTI_ROTOR_OCTO_X, MULTI_ROTOR_OCTO_V, MULTI_ROTOR_OCTO_COAX_X, MULTI_ROTOR_OCTO_COAX_PLUS,
|
||||
FIXED_WING_DUAL_AILERON, FIXED_WING_AILERON, FIXED_WING_ELEVON, HELI_CCPM };
|
||||
FIXED_WING_DUAL_AILERON, FIXED_WING_AILERON, FIXED_WING_ELEVON, FIXED_WING_VTAIL, HELI_CCPM };
|
||||
enum ESC_TYPE { ESC_RAPID, ESC_STANDARD, ESC_UNKNOWN };
|
||||
enum SERVO_TYPE { SERVO_ANALOG, SERVO_DIGITAL, SERVO_UNKNOWN };
|
||||
enum INPUT_TYPE { INPUT_PWM, INPUT_PPM, INPUT_SBUS, INPUT_DSMX10, INPUT_DSMX11, INPUT_DSM2, INPUT_UNKNOWN };
|
||||
|
@ -0,0 +1,209 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file vehicletemplateexportdialog.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
|
||||
* @addtogroup [Group]
|
||||
* @{
|
||||
* @addtogroup VehicleTemplateExportDialog
|
||||
* @{
|
||||
* @brief [Brief]
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "vehicletemplateexportdialog.h"
|
||||
#include "ui_vehicletemplateexportdialog.h"
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include "systemsettings.h"
|
||||
#include <QBuffer>
|
||||
#include <QFileDialog>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include "stabilizationsettings.h"
|
||||
#include "stabilizationsettingsbank1.h"
|
||||
#include "stabilizationsettingsbank2.h"
|
||||
#include "stabilizationsettingsbank3.h"
|
||||
#include "ekfconfiguration.h"
|
||||
|
||||
VehicleTemplateExportDialog::VehicleTemplateExportDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::VehicleTemplateExportDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connect(ui->ImportButton, SIGNAL(clicked()), this, SLOT(importImage()));
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
m_uavoManager = pm->getObject<UAVObjectManager>();
|
||||
ui->Photo->setScene(new QGraphicsScene(this));
|
||||
ui->Type->setText(setupVehicleType());
|
||||
}
|
||||
|
||||
VehicleTemplateExportDialog::~VehicleTemplateExportDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
QString VehicleTemplateExportDialog::setupVehicleType()
|
||||
{
|
||||
SystemSettings *systemSettings = SystemSettings::GetInstance(m_uavoManager);
|
||||
|
||||
Q_ASSERT(systemSettings);
|
||||
SystemSettings::DataFields systemSettingsData = systemSettings->getData();
|
||||
|
||||
switch (systemSettingsData.AirframeType) {
|
||||
case SystemSettings::AIRFRAMETYPE_FIXEDWING:
|
||||
m_type = VehicleConfigurationSource::VEHICLE_FIXEDWING;
|
||||
m_subType = VehicleConfigurationSource::FIXED_WING_AILERON;
|
||||
return tr("Fixed Wing - Aileron");
|
||||
|
||||
case SystemSettings::AIRFRAMETYPE_FIXEDWINGELEVON:
|
||||
m_type = VehicleConfigurationSource::VEHICLE_FIXEDWING;
|
||||
m_subType = VehicleConfigurationSource::FIXED_WING_ELEVON;
|
||||
return tr("Fixed Wing - Elevon");
|
||||
|
||||
case SystemSettings::AIRFRAMETYPE_FIXEDWINGVTAIL:
|
||||
m_type = VehicleConfigurationSource::VEHICLE_FIXEDWING;
|
||||
m_subType = VehicleConfigurationSource::FIXED_WING_VTAIL;
|
||||
return tr("Fixed Wing - V-Tail");
|
||||
|
||||
case SystemSettings::AIRFRAMETYPE_HELICP:
|
||||
m_type = VehicleConfigurationSource::VEHICLE_HELI;
|
||||
m_subType = VehicleConfigurationSource::HELI_CCPM;
|
||||
return tr("Helicopter");
|
||||
|
||||
case SystemSettings::AIRFRAMETYPE_TRI:
|
||||
m_type = VehicleConfigurationSource::VEHICLE_MULTI;
|
||||
m_subType = VehicleConfigurationSource::MULTI_ROTOR_TRI_Y;
|
||||
return tr("Multirotor - Tricopter");
|
||||
|
||||
case SystemSettings::AIRFRAMETYPE_QUADX:
|
||||
m_type = VehicleConfigurationSource::VEHICLE_MULTI;
|
||||
m_subType = VehicleConfigurationSource::MULTI_ROTOR_QUAD_X;
|
||||
return tr("Multirotor - Quadrocopter X");
|
||||
|
||||
case SystemSettings::AIRFRAMETYPE_QUADP:
|
||||
m_type = VehicleConfigurationSource::VEHICLE_MULTI;
|
||||
m_subType = VehicleConfigurationSource::MULTI_ROTOR_QUAD_PLUS;
|
||||
return tr("Multirotor - Quadrocopter +");
|
||||
|
||||
case SystemSettings::AIRFRAMETYPE_OCTOV:
|
||||
m_type = VehicleConfigurationSource::VEHICLE_MULTI;
|
||||
m_subType = VehicleConfigurationSource::MULTI_ROTOR_OCTO_V;
|
||||
return tr("Multirotor - Octocopter V");
|
||||
|
||||
case SystemSettings::AIRFRAMETYPE_OCTOCOAXX:
|
||||
m_type = VehicleConfigurationSource::VEHICLE_MULTI;
|
||||
m_subType = VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_X;
|
||||
return tr("Multirotor - Octocopter X8X");
|
||||
|
||||
case SystemSettings::AIRFRAMETYPE_OCTOCOAXP:
|
||||
m_type = VehicleConfigurationSource::VEHICLE_MULTI;
|
||||
m_subType = VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_PLUS;
|
||||
return tr("Multirotor - Octocopter X8+");
|
||||
|
||||
case SystemSettings::AIRFRAMETYPE_OCTO:
|
||||
m_type = VehicleConfigurationSource::VEHICLE_MULTI;
|
||||
m_subType = VehicleConfigurationSource::MULTI_ROTOR_OCTO;
|
||||
return tr("Multirotor - Octocopter +");
|
||||
|
||||
case SystemSettings::AIRFRAMETYPE_OCTOX:
|
||||
m_type = VehicleConfigurationSource::VEHICLE_MULTI;
|
||||
m_subType = VehicleConfigurationSource::MULTI_ROTOR_OCTO_X;
|
||||
return tr("Multirotor - Octocopter X");
|
||||
|
||||
case SystemSettings::AIRFRAMETYPE_HEXAX:
|
||||
m_type = VehicleConfigurationSource::VEHICLE_MULTI;
|
||||
m_subType = VehicleConfigurationSource::MULTI_ROTOR_HEXA_X;
|
||||
return tr("Multirotor - Hexacopter X");
|
||||
|
||||
case SystemSettings::AIRFRAMETYPE_HEXACOAX:
|
||||
m_type = VehicleConfigurationSource::VEHICLE_MULTI;
|
||||
m_subType = VehicleConfigurationSource::MULTI_ROTOR_HEXA_COAX_Y;
|
||||
return tr("Multirotor - Hexacopter Y6");
|
||||
|
||||
case SystemSettings::AIRFRAMETYPE_HEXA:
|
||||
m_type = VehicleConfigurationSource::VEHICLE_MULTI;
|
||||
m_subType = VehicleConfigurationSource::MULTI_ROTOR_HEXA;
|
||||
return tr("Multirotor - Hexacopter +");
|
||||
|
||||
default:
|
||||
m_type = VehicleConfigurationSource::VEHICLE_UNKNOWN;
|
||||
return tr("Unsupported");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void VehicleTemplateExportDialog::accept()
|
||||
{
|
||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Export template"), "", tr("Template (*.optmpl)"));
|
||||
|
||||
if (!fileName.isEmpty()) {
|
||||
if (!fileName.endsWith(".optmpl")) {
|
||||
fileName += ".optmpl";
|
||||
}
|
||||
QFile saveFile(fileName);
|
||||
if (saveFile.open(QIODevice::WriteOnly)) {
|
||||
QJsonObject exportObject;
|
||||
|
||||
QList<UAVObject *> objectsToExport;
|
||||
objectsToExport << StabilizationSettings::GetInstance(m_uavoManager);
|
||||
objectsToExport << StabilizationSettingsBank1::GetInstance(m_uavoManager);
|
||||
objectsToExport << StabilizationSettingsBank2::GetInstance(m_uavoManager);
|
||||
objectsToExport << StabilizationSettingsBank3::GetInstance(m_uavoManager);
|
||||
objectsToExport << EKFConfiguration::GetInstance(m_uavoManager);
|
||||
m_uavoManager->toJson(exportObject, objectsToExport);
|
||||
|
||||
exportObject["type"] = m_type;
|
||||
exportObject["subtype"] = m_subType;
|
||||
exportObject["name"] = ui->Name->text();
|
||||
exportObject["owner"] = ui->Owner->text();
|
||||
exportObject["nick"] = ui->ForumNick->text();
|
||||
exportObject["size"] = ui->Size->text();
|
||||
exportObject["weight"] = ui->Weight->text();
|
||||
exportObject["motor"] = ui->Motor->text();
|
||||
exportObject["esc"] = ui->Esc->text();
|
||||
exportObject["servo"] = ui->Servo->text();
|
||||
exportObject["battery"] = ui->Battery->text();
|
||||
exportObject["propeller"] = ui->Propeller->text();
|
||||
exportObject["controller"] = ui->Controllers->currentText();
|
||||
exportObject["comment"] = ui->Comment->document()->toPlainText();
|
||||
|
||||
QByteArray bytes;
|
||||
QBuffer buffer(&bytes);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
m_image.save(&buffer, "PNG");
|
||||
exportObject["photo"] = bytes.toBase64().data();
|
||||
|
||||
QJsonDocument saveDoc(exportObject);
|
||||
saveFile.write(saveDoc.toJson());
|
||||
saveFile.close();
|
||||
}
|
||||
}
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void VehicleTemplateExportDialog::importImage()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Import Image"), "", tr("Images (*.png *.jpg)"));
|
||||
|
||||
if (!fileName.isEmpty()) {
|
||||
m_image.load(fileName);
|
||||
ui->Photo->scene()->addPixmap(m_image);
|
||||
ui->Photo->setSceneRect(ui->Photo->scene()->itemsBoundingRect());
|
||||
ui->Photo->fitInView(ui->Photo->scene()->itemsBoundingRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file vehicletemplateexportdialog.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
|
||||
* @addtogroup [Group]
|
||||
* @{
|
||||
* @addtogroup VehicleTemplateExportDialog
|
||||
* @{
|
||||
* @brief [Brief]
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef VEHICLETEMPLATEEXPORTDIALOG_H
|
||||
#define VEHICLETEMPLATEEXPORTDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include "uavobjectmanager.h"
|
||||
#include "vehicleconfigurationsource.h"
|
||||
|
||||
namespace Ui {
|
||||
class VehicleTemplateExportDialog;
|
||||
}
|
||||
|
||||
class VehicleTemplateExportDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit VehicleTemplateExportDialog(QWidget *parent = 0);
|
||||
~VehicleTemplateExportDialog();
|
||||
|
||||
public slots:
|
||||
void accept();
|
||||
|
||||
private slots:
|
||||
void importImage();
|
||||
|
||||
private:
|
||||
Ui::VehicleTemplateExportDialog *ui;
|
||||
UAVObjectManager *m_uavoManager;
|
||||
QString setupVehicleType();
|
||||
VehicleConfigurationSource::VEHICLE_TYPE m_type;
|
||||
VehicleConfigurationSource::VEHICLE_SUB_TYPE m_subType;
|
||||
QPixmap m_image;
|
||||
};
|
||||
|
||||
#endif // VEHICLETEMPLATEEXPORTDIALOG_H
|
@ -0,0 +1,463 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>VehicleTemplateExportDialog</class>
|
||||
<widget class="QDialog" name="VehicleTemplateExportDialog">
|
||||
<property name="windowModality">
|
||||
<enum>Qt::ApplicationModal</enum>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>610</width>
|
||||
<height>700</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>610</width>
|
||||
<height>700</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>610</width>
|
||||
<height>700</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Vehicle Template Export</string>
|
||||
</property>
|
||||
<property name="sizeGripEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="modal">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_2">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="6" column="2">
|
||||
<widget class="QLabel" name="label_9">
|
||||
<property name="text">
|
||||
<string>Weight:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="11" column="1">
|
||||
<widget class="QLineEdit" name="Propeller">
|
||||
<property name="placeholderText">
|
||||
<string>Size and angle</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="10" column="2">
|
||||
<widget class="QLabel" name="label_11">
|
||||
<property name="text">
|
||||
<string>Battery:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QLineEdit" name="Size">
|
||||
<property name="placeholderText">
|
||||
<string>Size of the vehicle in mm</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Motor:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Name:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="10" column="0">
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="text">
|
||||
<string>Servo:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="10" column="1">
|
||||
<widget class="QLineEdit" name="Servo">
|
||||
<property name="placeholderText">
|
||||
<string>Brand and name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLineEdit" name="Owner">
|
||||
<property name="placeholderText">
|
||||
<string>Your name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="11" column="0">
|
||||
<widget class="QLabel" name="label_12">
|
||||
<property name="text">
|
||||
<string>Propeller:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<widget class="QLabel" name="label_10">
|
||||
<property name="text">
|
||||
<string>Forum name:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="5">
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="4">
|
||||
<widget class="QLineEdit" name="Name">
|
||||
<property name="placeholderText">
|
||||
<string>The name of the vehicle, brand etc</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Owner:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<widget class="QLineEdit" name="Motor">
|
||||
<property name="placeholderText">
|
||||
<string>Brand, size and Kv</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Size:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="10" column="3" colspan="2">
|
||||
<widget class="QLineEdit" name="Battery">
|
||||
<property name="placeholderText">
|
||||
<string>How many cells etc?</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="11" column="2">
|
||||
<widget class="QLabel" name="label_14">
|
||||
<property name="text">
|
||||
<string>Controller:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" colspan="4">
|
||||
<widget class="QLineEdit" name="Type">
|
||||
<property name="autoFillBackground">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">background-color: rgba(255, 255, 255, 0);</string>
|
||||
</property>
|
||||
<property name="frame">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="2">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>ESC:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="11" column="3" colspan="2">
|
||||
<widget class="QComboBox" name="Controllers">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>None</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>CC</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>CC3D</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Atom</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Revolution</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Nano</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Type:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="3" colspan="2">
|
||||
<widget class="QLineEdit" name="ForumNick">
|
||||
<property name="placeholderText">
|
||||
<string>Forum nickname</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="3" colspan="2">
|
||||
<widget class="QLineEdit" name="Esc">
|
||||
<property name="placeholderText">
|
||||
<string>Brand and name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="3" colspan="2">
|
||||
<widget class="QLineEdit" name="Weight">
|
||||
<property name="placeholderText">
|
||||
<string>Weight in grams</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_3">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_13">
|
||||
<property name="text">
|
||||
<string>Comment:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="Comment">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOn</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>Put comments here that doesn't fit in the categories above</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_4">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Photo:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGraphicsView" name="Photo">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">background-color: rgba(254, 254, 254, 0);</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="backgroundBrush">
|
||||
<brush brushstyle="NoBrush">
|
||||
<color alpha="255">
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</property>
|
||||
<property name="interactive">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item alignment="Qt::AlignRight">
|
||||
<widget class="QPushButton" name="ImportButton">
|
||||
<property name="text">
|
||||
<string>Import...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item alignment="Qt::AlignBottom">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>VehicleTemplateExportDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>VehicleTemplateExportDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
@ -538,16 +538,17 @@ void UAVObject::fromXML(QXmlStreamReader *xmlReader)
|
||||
{
|
||||
// Check that we are the correct object by name, and that we are the same instance id
|
||||
// but dont check id since we want to be able to be forward compatible.
|
||||
Q_ASSERT(xmlReader->name() == "object");
|
||||
Q_ASSERT(xmlReader->attributes().value("name") == getName());
|
||||
Q_ASSERT(xmlReader->attributes().value("instance") == QString("%1").arg(getInstID()));
|
||||
QXmlStreamReader::TokenType token = xmlReader->readNext();
|
||||
if(token == QXmlStreamReader::StartElement && xmlReader->name() == "fields") {
|
||||
while (xmlReader->readNextStartElement()) {
|
||||
if (xmlReader->name() == "field") {
|
||||
QStringRef fieldName = xmlReader->attributes().value("name");
|
||||
if (fieldName != "") {
|
||||
getField(*fieldName.string())->fromXML(xmlReader);
|
||||
if (xmlReader->name() == "object" &&
|
||||
xmlReader->attributes().value("name") == getName() &&
|
||||
xmlReader->attributes().value("instance") == QString("%1").arg(getInstID())) {
|
||||
QXmlStreamReader::TokenType token = xmlReader->readNext();
|
||||
if (token == QXmlStreamReader::StartElement && xmlReader->name() == "fields") {
|
||||
while (xmlReader->readNextStartElement()) {
|
||||
if (xmlReader->name() == "field") {
|
||||
QStringRef fieldName = xmlReader->attributes().value("name");
|
||||
if (fieldName != "") {
|
||||
getField(*fieldName.string())->fromXML(xmlReader);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -556,12 +557,14 @@ void UAVObject::fromXML(QXmlStreamReader *xmlReader)
|
||||
|
||||
void UAVObject::toJson(QJsonObject &jsonObject)
|
||||
{
|
||||
jsonObject["name"] = getName();
|
||||
jsonObject["name"] = getName();
|
||||
jsonObject["setting"] = isSettingsObject();
|
||||
jsonObject["id"] = QString("%1").arg(getObjID(), 1, 16).toUpper();
|
||||
jsonObject["instance"] = (int)getInstID();
|
||||
QJsonArray jSonFields;
|
||||
foreach(UAVObjectField * field, fields) {
|
||||
QJsonObject jSonField;
|
||||
|
||||
field->toJson(jSonField);
|
||||
jSonFields.append(jSonField);
|
||||
}
|
||||
@ -570,15 +573,17 @@ void UAVObject::toJson(QJsonObject &jsonObject)
|
||||
|
||||
void UAVObject::fromJson(const QJsonObject &jsonObject)
|
||||
{
|
||||
Q_ASSERT(jsonObject["name"].toString() == getName());
|
||||
Q_ASSERT(jsonObject["instance"].toInt() == (int)getInstID());
|
||||
QJsonArray jsonFields = jsonObject["fields"].toArray();
|
||||
for (int i = 0; i < jsonFields.size(); i++) {
|
||||
QJsonObject jsonField = jsonFields.at(i).toObject();
|
||||
UAVObjectField *field = getField(jsonField["name"].toString());
|
||||
if (field) {
|
||||
field->fromJson(jsonField);
|
||||
if (jsonObject["name"].toString() == getName() &&
|
||||
jsonObject["instance"].toInt() == (int)getInstID()) {
|
||||
QJsonArray jsonFields = jsonObject["fields"].toArray();
|
||||
for (int i = 0; i < jsonFields.size(); i++) {
|
||||
QJsonObject jsonField = jsonFields.at(i).toObject();
|
||||
UAVObjectField *field = getField(jsonField["name"].toString());
|
||||
if (field != NULL) {
|
||||
field->fromJson(jsonField);
|
||||
}
|
||||
}
|
||||
updated();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -698,7 +698,7 @@ void UAVObjectField::toJson(QJsonObject &jsonObject)
|
||||
QJsonArray values;
|
||||
for (unsigned int n = 0; n < numElements; ++n) {
|
||||
QJsonObject value;
|
||||
value["name"] = getElementNames().at(n);
|
||||
value["name"] = getElementNames().at(n);
|
||||
value["value"] = QJsonValue::fromVariant(getValue(n));
|
||||
values.append(value);
|
||||
}
|
||||
|
@ -27,6 +27,8 @@
|
||||
*/
|
||||
#include "uavobjectmanager.h"
|
||||
|
||||
#include <QtWidgetsDepends>
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
@ -296,6 +298,61 @@ qint32 UAVObjectManager::getNumInstances(quint32 objId)
|
||||
return getNumInstances(NULL, objId);
|
||||
}
|
||||
|
||||
void UAVObjectManager::toJson(QJsonObject &jsonObject, UAVObjectManager::JSON_EXPORT_OPTION what)
|
||||
{
|
||||
QList<UAVObject *> objects;
|
||||
QList< QList<UAVObject *> > allObjects = getObjects();
|
||||
foreach(QList<UAVObject *> instances, allObjects) {
|
||||
foreach(UAVObject * object, instances) {
|
||||
if (what == JSON_EXPORT_ALL ||
|
||||
(what == JSON_EXPORT_DATA && !object->isSettingsObject()) ||
|
||||
(what == JSON_EXPORT_SETTINGS && object->isSettingsObject()) ||
|
||||
(what == JSON_EXPORT_SETTINGS && object->isMetaDataObject())) {
|
||||
objects << object;
|
||||
}
|
||||
}
|
||||
}
|
||||
toJson(jsonObject, objects);
|
||||
}
|
||||
|
||||
void UAVObjectManager::toJson(QJsonObject &jsonObject, const QList<QString> &objectsToExport)
|
||||
{
|
||||
QList<UAVObject *> objects;
|
||||
foreach(QString objectName, objectsToExport) {
|
||||
QList<UAVObject *> instances = getObjectInstances(objectName);
|
||||
foreach(UAVObject * object, instances) {
|
||||
objects << object;
|
||||
}
|
||||
}
|
||||
toJson(jsonObject, objects);
|
||||
}
|
||||
|
||||
void UAVObjectManager::toJson(QJsonObject &jsonObject, const QList<UAVObject *> &objectsToExport)
|
||||
{
|
||||
QJsonArray jObjects;
|
||||
|
||||
foreach(UAVObject * object, objectsToExport) {
|
||||
QJsonObject jObject;
|
||||
|
||||
object->toJson(jObject);
|
||||
jObjects.append(jObject);
|
||||
}
|
||||
jsonObject["objects"] = jObjects;
|
||||
}
|
||||
|
||||
void UAVObjectManager::fromJson(const QJsonObject &jsonObject)
|
||||
{
|
||||
QJsonArray jObjects = jsonObject["objects"].toArray();
|
||||
|
||||
for (int i = 0; i < jObjects.size(); i++) {
|
||||
QJsonObject jObject = jObjects.at(i).toObject();
|
||||
UAVObject *object = getObject(jObject["name"].toString(), jObject["instance"].toInt());
|
||||
if (object != NULL) {
|
||||
object->fromJson(jObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for public getNumInstances
|
||||
*/
|
||||
|
@ -35,11 +35,13 @@
|
||||
#include <QList>
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
#include <QJsonObject>
|
||||
|
||||
class UAVOBJECTS_EXPORT UAVObjectManager : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum JSON_EXPORT_OPTION { JSON_EXPORT_ALL, JSON_EXPORT_METADATA, JSON_EXPORT_SETTINGS, JSON_EXPORT_DATA };
|
||||
UAVObjectManager();
|
||||
~UAVObjectManager();
|
||||
|
||||
@ -54,6 +56,11 @@ public:
|
||||
qint32 getNumInstances(const QString & name);
|
||||
qint32 getNumInstances(quint32 objId);
|
||||
|
||||
void toJson(QJsonObject &jsonObject, JSON_EXPORT_OPTION what = JSON_EXPORT_ALL);
|
||||
void toJson(QJsonObject &jsonObject, const QList<QString> &objectsToExport);
|
||||
void toJson(QJsonObject &jsonObject, const QList<UAVObject *> &objectsToExport);
|
||||
void fromJson(const QJsonObject &jsonObject);
|
||||
|
||||
signals:
|
||||
void newObject(UAVObject *obj);
|
||||
void newInstance(UAVObject *obj);
|
||||
|
Loading…
x
Reference in New Issue
Block a user