mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-30 15:52:12 +01:00
OP-1222 Added UUID to template file for identification.
Implemented the code to apply the template settings. Fixed tab order in template export dialog. Extended support for parsing and applying json data in uavobjectmanager.
This commit is contained in:
parent
ee6317af8b
commit
b0e337c540
@ -82,6 +82,9 @@ bool AirframeInitialTuningPage::validatePage()
|
||||
if (ui->templateList->currentRow() >= 0) {
|
||||
templ = ui->templateList->item(ui->templateList->currentRow())->data(Qt::UserRole + 1).value<QJsonObject *>();
|
||||
}
|
||||
if (getWizard()->getVehicleTemplate() != NULL) {
|
||||
delete getWizard()->getVehicleTemplate();
|
||||
}
|
||||
getWizard()->setVehicleTemplate(new QJsonObject(*templ));
|
||||
return true;
|
||||
}
|
||||
@ -114,8 +117,11 @@ void AirframeInitialTuningPage::updateDescription(QJsonObject *templ)
|
||||
if (templ != NULL) {
|
||||
QString description;
|
||||
description.append("<b>").append(tr("Name of Vehicle: ")).append("</b>").append(templ->value("name").toString()).append("<br>");
|
||||
description.append("<b>").append(tr("Name of Owner: ")).append("</b>").append(templ->value("owner").toString())
|
||||
.append(" (").append(templ->value("nick").toString()).append(")").append("<br>");
|
||||
description.append("<b>").append(tr("Name of Owner: ")).append("</b>").append(templ->value("owner").toString());
|
||||
if (templ->value("nick") != "") {
|
||||
description.append(" (").append(templ->value("nick").toString()).append(")");
|
||||
}
|
||||
description.append("<br>");
|
||||
description.append("<b>").append(tr("Size: ")).append("</b>").append(templ->value("size").toString()).append("<br>");
|
||||
description.append("<b>").append(tr("Weight: ")).append("</b>").append(templ->value("weight").toString()).append("<br>");
|
||||
description.append("<b>").append(tr("Motor(s): ")).append("</b>").append(templ->value("motor").toString()).append("<br>");
|
||||
@ -156,26 +162,19 @@ void AirframeInitialTuningPage::loadValidFiles()
|
||||
QStringList files = templateDir.entryList();
|
||||
foreach(QString fileName, files) {
|
||||
QFile file(QString("%1/%2").arg(templateDir.absolutePath()).arg(fileName));
|
||||
|
||||
if (file.open(QFile::ReadOnly)) {
|
||||
QByteArray jsonData = file.readAll();
|
||||
QJsonDocument templateDoc = QJsonDocument::fromJson(jsonData);
|
||||
QJsonObject json = templateDoc.object();
|
||||
if (json["type"].toInt() == getWizard()->getVehicleType() &&
|
||||
json["subtype"].toInt() == getWizard()->getVehicleSubType()) {
|
||||
QString nameKey = getTemplateKey(&json);
|
||||
int index = 0;
|
||||
while (true) {
|
||||
if (!m_templates.contains(nameKey)) {
|
||||
m_templates[nameKey] = new QJsonObject(json);
|
||||
break;
|
||||
} else {
|
||||
nameKey = QString("%1 - %2").arg(nameKey).arg(++index);
|
||||
}
|
||||
QString uuid = json["uuid"].toString();
|
||||
if (!m_templates.contains(uuid)) {
|
||||
m_templates[json["uuid"].toString()] = new QJsonObject(json);
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
@ -185,15 +184,16 @@ void AirframeInitialTuningPage::setupTemplateList()
|
||||
|
||||
item->setData(Qt::UserRole + 1, QVariant::fromValue((QJsonObject *)NULL));
|
||||
foreach(QString templ, m_templates.keys()) {
|
||||
item = new QListWidgetItem(templ, ui->templateList);
|
||||
item->setData(Qt::UserRole + 1, QVariant::fromValue(m_templates[templ]));
|
||||
QJsonObject *json = m_templates[templ];
|
||||
item = new QListWidgetItem(json->value("name").toString(), ui->templateList);
|
||||
item->setData(Qt::UserRole + 1, QVariant::fromValue(json));
|
||||
}
|
||||
ui->templateList->setCurrentRow(0);
|
||||
}
|
||||
|
||||
QString AirframeInitialTuningPage::getTemplateKey(QJsonObject *templ)
|
||||
{
|
||||
return QString("%1 - %2").arg(templ->value("nick").toString()).arg(templ->value("name").toString());
|
||||
return QString(templ->value("name").toString());
|
||||
}
|
||||
|
||||
void AirframeInitialTuningPage::resizeEvent(QResizeEvent *)
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "gpssettings.h"
|
||||
#include "airspeedsettings.h"
|
||||
#include <QtCore/qmath.h>
|
||||
#include <QJsonObject>
|
||||
|
||||
const qint16 VehicleConfigurationHelper::LEGACY_ESC_FREQUENCE = 50;
|
||||
const qint16 VehicleConfigurationHelper::RAPID_ESC_FREQUENCE = 400;
|
||||
@ -82,6 +83,8 @@ bool VehicleConfigurationHelper::setupVehicle(bool save)
|
||||
applyStabilizationConfiguration();
|
||||
applyManualControlDefaults();
|
||||
|
||||
applyTemplateSettings();
|
||||
|
||||
bool result = saveChangesToController(save);
|
||||
emit saveProgress(m_modifiedObjects.count() + 1, ++m_progress, result ? tr("Done!") : tr("Failed!"));
|
||||
return result;
|
||||
@ -747,6 +750,21 @@ void VehicleConfigurationHelper::applyManualControlDefaults()
|
||||
addModifiedObject(mcSettings, tr("Writing manual control defaults"));
|
||||
}
|
||||
|
||||
void VehicleConfigurationHelper::applyTemplateSettings()
|
||||
{
|
||||
if (m_configSource->getVehicleTemplate() != NULL) {
|
||||
QJsonObject* json = m_configSource->getVehicleTemplate();
|
||||
QList<UAVObject*> updatedObjects;
|
||||
m_uavoManager->fromJson(*json, &updatedObjects);
|
||||
foreach (UAVObject* object, updatedObjects) {
|
||||
UAVDataObject *dataObj = dynamic_cast<UAVDataObject*>(object);
|
||||
if (dataObj != NULL) {
|
||||
addModifiedObject(dataObj, QString(tr("Writing template settings for %1")).arg(object->getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool VehicleConfigurationHelper::saveChangesToController(bool save)
|
||||
{
|
||||
qDebug() << "Saving modified objects to controller. " << m_modifiedObjects.count() << " objects in found.";
|
||||
|
@ -87,6 +87,7 @@ private:
|
||||
void applySensorBiasConfiguration();
|
||||
void applyStabilizationConfiguration();
|
||||
void applyManualControlDefaults();
|
||||
void applyTemplateSettings();
|
||||
|
||||
void applyMixerConfiguration(mixerChannelSettings channels[]);
|
||||
|
||||
|
@ -199,6 +199,8 @@ void VehicleTemplateExportDialog::accept()
|
||||
exportObject["propeller"] = ui->Propeller->text();
|
||||
exportObject["controller"] = ui->Controllers->currentText();
|
||||
exportObject["comment"] = ui->Comment->document()->toPlainText();
|
||||
QUuid uuid = QUuid::createUuid();
|
||||
exportObject["uuid"] = uuid.toString();
|
||||
|
||||
QByteArray bytes;
|
||||
QBuffer buffer(&bytes);
|
||||
@ -209,13 +211,12 @@ void VehicleTemplateExportDialog::accept()
|
||||
|
||||
QJsonDocument saveDoc(exportObject);
|
||||
|
||||
QString fileName = QString("%1/%2/%3-%4-%5-%6.optmpl")
|
||||
QString fileName = QString("%1/%2/%3-%4-%5.optmpl")
|
||||
.arg(EXPORT_BASE_NAME)
|
||||
.arg(getTypeDirectory())
|
||||
.arg(fixFilenameString(ui->ForumNick->text(), 15))
|
||||
.arg(fixFilenameString(ui->Name->text(), 20))
|
||||
.arg(fixFilenameString(ui->Type->text(), 30))
|
||||
.arg(fixFilenameString(QUuid::createUuid().toString().right(12)));
|
||||
.arg(fixFilenameString(uuid.toString().right(12)));
|
||||
QFile saveFile(fileName);
|
||||
QDir dir;
|
||||
dir.mkpath(QFileInfo(saveFile).absoluteDir().absolutePath());
|
||||
|
@ -540,6 +540,25 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>Type</tabstop>
|
||||
<tabstop>Name</tabstop>
|
||||
<tabstop>Owner</tabstop>
|
||||
<tabstop>ForumNick</tabstop>
|
||||
<tabstop>Size</tabstop>
|
||||
<tabstop>Weight</tabstop>
|
||||
<tabstop>Motor</tabstop>
|
||||
<tabstop>Esc</tabstop>
|
||||
<tabstop>Servo</tabstop>
|
||||
<tabstop>Battery</tabstop>
|
||||
<tabstop>Propeller</tabstop>
|
||||
<tabstop>Controllers</tabstop>
|
||||
<tabstop>Comment</tabstop>
|
||||
<tabstop>ImportButton</tabstop>
|
||||
<tabstop>acceptBtn</tabstop>
|
||||
<tabstop>cancelBtn</tabstop>
|
||||
<tabstop>Photo</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
|
@ -340,7 +340,7 @@ void UAVObjectManager::toJson(QJsonObject &jsonObject, const QList<UAVObject *>
|
||||
jsonObject["objects"] = jObjects;
|
||||
}
|
||||
|
||||
void UAVObjectManager::fromJson(const QJsonObject &jsonObject)
|
||||
void UAVObjectManager::fromJson(const QJsonObject &jsonObject, QList<UAVObject *> *updatedObjects)
|
||||
{
|
||||
QJsonArray jObjects = jsonObject["objects"].toArray();
|
||||
|
||||
@ -349,6 +349,9 @@ void UAVObjectManager::fromJson(const QJsonObject &jsonObject)
|
||||
UAVObject *object = getObject(jObject["name"].toString(), jObject["instance"].toInt());
|
||||
if (object != NULL) {
|
||||
object->fromJson(jObject);
|
||||
if (updatedObjects != NULL) {
|
||||
updatedObjects->append(object);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ public:
|
||||
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);
|
||||
void fromJson(const QJsonObject &jsonObject, QList<UAVObject *> *updatedObjects = NULL);
|
||||
|
||||
signals:
|
||||
void newObject(UAVObject *obj);
|
||||
|
Loading…
x
Reference in New Issue
Block a user