mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-18 08:54:15 +01:00
OP-1222 Implemented scanning for and reading of optmpl files (json vehicle template files )
and implemented selection gui for the templates.
This commit is contained in:
parent
9c0c489e94
commit
7ab2839b6e
@ -27,15 +27,183 @@
|
||||
|
||||
#include "airframeinitialtuningpage.h"
|
||||
#include "ui_airframeinitialtuningpage.h"
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonArray>
|
||||
#include <QDir>
|
||||
#include "vehicletemplateexportdialog.h"
|
||||
|
||||
AirframeInitialTuningPage::AirframeInitialTuningPage(SetupWizard *wizard, QWidget *parent) :
|
||||
AbstractWizardPage(wizard, parent),
|
||||
ui(new Ui::AirframeInitialTuningPage)
|
||||
ui(new Ui::AirframeInitialTuningPage), m_dir(NULL), m_photoItem(NULL)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->templateImage->setScene(new QGraphicsScene());
|
||||
connect(ui->templateList, SIGNAL(itemSelectionChanged()), this, SLOT(templateSelectionChanged()));
|
||||
}
|
||||
|
||||
AirframeInitialTuningPage::~AirframeInitialTuningPage()
|
||||
{
|
||||
ui->templateList->clear();
|
||||
foreach(QJsonObject * templ, m_templates.values()) {
|
||||
delete templ;
|
||||
}
|
||||
m_templates.clear();
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void AirframeInitialTuningPage::initializePage()
|
||||
{
|
||||
switch (getWizard()->getVehicleType()) {
|
||||
case VehicleConfigurationSource::VEHICLE_FIXEDWING:
|
||||
m_dir = VehicleTemplateExportDialog::EXPORT_FIXEDWING_NAME;
|
||||
break;
|
||||
case VehicleConfigurationSource::VEHICLE_MULTI:
|
||||
m_dir = VehicleTemplateExportDialog::EXPORT_MULTI_NAME;
|
||||
break;
|
||||
case VehicleConfigurationSource::VEHICLE_HELI:
|
||||
m_dir = VehicleTemplateExportDialog::EXPORT_HELI_NAME;
|
||||
break;
|
||||
case VehicleConfigurationSource::VEHICLE_SURFACE:
|
||||
m_dir = VehicleTemplateExportDialog::EXPORT_SURFACE_NAME;
|
||||
break;
|
||||
default:
|
||||
m_dir = NULL;
|
||||
break;
|
||||
}
|
||||
loadValidFiles();
|
||||
setupTemplateList();
|
||||
}
|
||||
|
||||
bool AirframeInitialTuningPage::validatePage()
|
||||
{
|
||||
QJsonObject *templ = NULL;
|
||||
|
||||
if (ui->templateList->currentRow() >= 0) {
|
||||
templ = ui->templateList->item(ui->templateList->currentRow())->data(Qt::UserRole + 1).value<QJsonObject *>();
|
||||
}
|
||||
getWizard()->setVehicleTemplate(new QJsonObject(*templ));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AirframeInitialTuningPage::isComplete() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void AirframeInitialTuningPage::updatePhoto(QJsonObject *templ)
|
||||
{
|
||||
QPixmap photo;
|
||||
|
||||
if (m_photoItem != NULL) {
|
||||
ui->templateImage->scene()->removeItem(m_photoItem);
|
||||
}
|
||||
if (templ != NULL) {
|
||||
QByteArray imageData = QByteArray::fromBase64(templ->value("photo").toString().toLatin1());
|
||||
photo.loadFromData(imageData, "PNG");
|
||||
} else {
|
||||
photo.load(":/core/images/opie_90x120.gif");
|
||||
}
|
||||
m_photoItem = ui->templateImage->scene()->addPixmap(photo);
|
||||
ui->templateImage->setSceneRect(ui->templateImage->scene()->itemsBoundingRect());
|
||||
ui->templateImage->fitInView(ui->templateImage->scene()->itemsBoundingRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
|
||||
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("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>");
|
||||
description.append("<b>").append(tr("ESC(s): ")).append("</b>").append(templ->value("esc").toString()).append("<br>");
|
||||
description.append("<b>").append(tr("Servo(s): ")).append("</b>").append(templ->value("servo").toString()).append("<br>");
|
||||
description.append("<b>").append(tr("Battery: ")).append("</b>").append(templ->value("battery").toString()).append("<br>");
|
||||
description.append("<b>").append(tr("Propellers(s): ")).append("</b>").append(templ->value("propeller").toString()).append("<br>");
|
||||
description.append("<b>").append(tr("Controller: ")).append("</b>").append(templ->value("controller").toString()).append("<br>");
|
||||
description.append("<b>").append(tr("Comments: ")).append("</b>").append(templ->value("comment").toString());
|
||||
ui->templateDescription->setText(description);
|
||||
} else {
|
||||
ui->templateDescription->setText(tr("No vehicle selected!"));
|
||||
}
|
||||
}
|
||||
|
||||
void AirframeInitialTuningPage::templateSelectionChanged()
|
||||
{
|
||||
if (ui->templateList->currentRow() >= 0) {
|
||||
QJsonObject *templ = ui->templateList->item(ui->templateList->currentRow())->data(Qt::UserRole + 1).value<QJsonObject *>();
|
||||
updatePhoto(templ);
|
||||
updateDescription(templ);
|
||||
}
|
||||
}
|
||||
|
||||
void AirframeInitialTuningPage::loadValidFiles()
|
||||
{
|
||||
ui->templateList->clear();
|
||||
foreach(QJsonObject * templ, m_templates.values()) {
|
||||
delete templ;
|
||||
}
|
||||
m_templates.clear();
|
||||
|
||||
QDir templateDir(QString("%1/%2/").arg(VehicleTemplateExportDialog::EXPORT_BASE_NAME).arg(m_dir));
|
||||
QStringList names;
|
||||
names << "*.optmpl";
|
||||
templateDir.setNameFilters(names);
|
||||
templateDir.setSorting(QDir::Name);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AirframeInitialTuningPage::setupTemplateList()
|
||||
{
|
||||
QListWidgetItem *item = new QListWidgetItem(tr("None"), ui->templateList);
|
||||
|
||||
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]));
|
||||
}
|
||||
ui->templateList->setCurrentRow(0);
|
||||
}
|
||||
|
||||
QString AirframeInitialTuningPage::getTemplateKey(QJsonObject *templ)
|
||||
{
|
||||
return QString("%1 - %2").arg(templ->value("nick").toString()).arg(templ->value("name").toString());
|
||||
}
|
||||
|
||||
void AirframeInitialTuningPage::resizeEvent(QResizeEvent *)
|
||||
{
|
||||
ui->templateImage->setSceneRect(ui->templateImage->scene()->itemsBoundingRect());
|
||||
ui->templateImage->fitInView(ui->templateImage->scene()->itemsBoundingRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
|
||||
void AirframeInitialTuningPage::showEvent(QShowEvent *)
|
||||
{
|
||||
ui->templateImage->setSceneRect(ui->templateImage->scene()->itemsBoundingRect());
|
||||
ui->templateImage->fitInView(ui->templateImage->scene()->itemsBoundingRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
|
@ -29,6 +29,7 @@
|
||||
#define AIRFRAMEINITIALTUNINGPAGE_H
|
||||
|
||||
#include "abstractwizardpage.h"
|
||||
#include <QJsonObject>
|
||||
|
||||
namespace Ui {
|
||||
class AirframeInitialTuningPage;
|
||||
@ -40,9 +41,30 @@ class AirframeInitialTuningPage : public AbstractWizardPage {
|
||||
public:
|
||||
explicit AirframeInitialTuningPage(SetupWizard *wizard, QWidget *parent = 0);
|
||||
~AirframeInitialTuningPage();
|
||||
void initializePage();
|
||||
bool validatePage();
|
||||
bool isComplete() const;
|
||||
|
||||
public slots:
|
||||
void templateSelectionChanged();
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *);
|
||||
void showEvent(QShowEvent *);
|
||||
|
||||
private:
|
||||
Ui::AirframeInitialTuningPage *ui;
|
||||
const char *m_dir;
|
||||
QMap<QString, QJsonObject *> m_templates;
|
||||
QGraphicsPixmapItem *m_photoItem;
|
||||
|
||||
void loadValidFiles();
|
||||
void setupTemplateList();
|
||||
QString getTemplateKey(QJsonObject *templ);
|
||||
void updatePhoto(QJsonObject *templ);
|
||||
void updateDescription(QJsonObject *templ);
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(QJsonObject *)
|
||||
|
||||
#endif // AIRFRAMEINITIALTUNINGPAGE_H
|
||||
|
@ -7,80 +7,98 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>600</width>
|
||||
<height>400</height>
|
||||
<height>598</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>WizardPage</string>
|
||||
</property>
|
||||
<widget class="QLabel" name="label_main">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>9</x>
|
||||
<y>9</y>
|
||||
<width>582</width>
|
||||
<height>81</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_main">
|
||||
<property name="text">
|
||||
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8pt; font-weight:400; font-style:normal;">
|
||||
<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:12pt; font-weight:600;">Initial Tuning</span></p>
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:12pt; font-weight:600;"><br /></p>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2,sans-serif';">This section of the OpenPilot Wizard allows you to select a set of initial tunning parameters for your airframe. Presented below is a list of common airframe types, select the one that matches your airframe the closest, if unsure select the generic variant.</span> </p></body></html></string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QWidget" name="horizontalLayoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>100</y>
|
||||
<width>581</width>
|
||||
<height>291</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="2,3">
|
||||
<item>
|
||||
<widget class="QListWidget" name="listWidget">
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOn</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="10,4">
|
||||
<item>
|
||||
<widget class="QGraphicsView" name="graphicsView"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Description</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<zorder>label_main</zorder>
|
||||
<zorder>label_main</zorder>
|
||||
<zorder>horizontalLayoutWidget</zorder>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="2,0">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,4">
|
||||
<item>
|
||||
<widget class="QListWidget" name="templateList">
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOn</enum>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGraphicsView" name="templateImage">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>250</width>
|
||||
<height>250</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">background-color: rgba(254, 254, 254, 0);</string>
|
||||
</property>
|
||||
<property name="interactive">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="renderHints">
|
||||
<set>QPainter::Antialiasing|QPainter::HighQualityAntialiasing|QPainter::TextAntialiasing</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="templateDescription">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="undoRedoEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>Information about the Vehicle in short.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
@ -56,8 +56,8 @@
|
||||
SetupWizard::SetupWizard(QWidget *parent) : QWizard(parent), VehicleConfigurationSource(),
|
||||
m_controllerType(CONTROLLER_UNKNOWN),
|
||||
m_vehicleType(VEHICLE_UNKNOWN), m_inputType(INPUT_UNKNOWN), m_escType(ESC_UNKNOWN),
|
||||
m_servoType(SERVO_UNKNOWN), m_calibrationPerformed(false), m_restartNeeded(false),
|
||||
m_connectionManager(0)
|
||||
m_servoType(SERVO_UNKNOWN), m_vehicleTemplate(NULL),
|
||||
m_calibrationPerformed(false), m_restartNeeded(false), m_connectionManager(0)
|
||||
{
|
||||
setWindowTitle(tr("OpenPilot Setup Wizard"));
|
||||
setOption(QWizard::IndependentPages, false);
|
||||
@ -70,6 +70,14 @@ SetupWizard::SetupWizard(QWidget *parent) : QWizard(parent), VehicleConfiguratio
|
||||
createPages();
|
||||
}
|
||||
|
||||
SetupWizard::~SetupWizard()
|
||||
{
|
||||
if (m_vehicleTemplate != NULL) {
|
||||
delete m_vehicleTemplate;
|
||||
m_vehicleTemplate = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int SetupWizard::nextId() const
|
||||
{
|
||||
switch (currentId()) {
|
||||
@ -189,14 +197,11 @@ int SetupWizard::nextId() const
|
||||
case CONTROLLER_CC3D:
|
||||
case CONTROLLER_REVO:
|
||||
case CONTROLLER_NANO:
|
||||
case CONTROLLER_DISCOVERYF4:
|
||||
switch (getVehicleType()) {
|
||||
case VEHICLE_FIXEDWING:
|
||||
return PAGE_OUTPUT_CALIBRATION;
|
||||
|
||||
case CONTROLLER_DISCOVERYF4:
|
||||
// Skip calibration.
|
||||
return PAGE_OUTPUT_CALIBRATION;
|
||||
|
||||
default:
|
||||
return PAGE_BIAS_CALIBRATION;
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ class SetupWizard : public QWizard, public VehicleConfigurationSource {
|
||||
|
||||
public:
|
||||
SetupWizard(QWidget *parent = 0);
|
||||
~SetupWizard();
|
||||
int nextId() const;
|
||||
|
||||
void setControllerType(SetupWizard::CONTROLLER_TYPE type)
|
||||
@ -124,6 +125,15 @@ public:
|
||||
return m_radioSetting;
|
||||
}
|
||||
|
||||
void setVehicleTemplate(QJsonObject *templ)
|
||||
{
|
||||
m_vehicleTemplate = templ;
|
||||
}
|
||||
QJsonObject *getVehicleTemplate() const
|
||||
{
|
||||
return m_vehicleTemplate;
|
||||
}
|
||||
|
||||
void setLevellingBias(accelGyroBias bias)
|
||||
{
|
||||
m_calibrationBias = bias; m_calibrationPerformed = true;
|
||||
@ -193,6 +203,8 @@ private:
|
||||
GPS_TYPE m_gpsType;
|
||||
RADIO_SETTING m_radioSetting;
|
||||
|
||||
QJsonObject *m_vehicleTemplate;
|
||||
|
||||
bool m_calibrationPerformed;
|
||||
accelGyroBias m_calibrationBias;
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
#define VEHICLECONFIGURATIONSOURCE_H
|
||||
|
||||
#include <QString>
|
||||
#include <QJsonObject>
|
||||
#include "actuatorsettings.h"
|
||||
|
||||
struct accelGyroBias {
|
||||
@ -77,8 +78,9 @@ public:
|
||||
virtual VehicleConfigurationSource::AIRSPEED_TYPE getAirspeedType() const = 0;
|
||||
virtual VehicleConfigurationSource::GPS_TYPE getGpsType() const = 0;
|
||||
virtual VehicleConfigurationSource::RADIO_SETTING getRadioSetting() const = 0;
|
||||
virtual QJsonObject *getVehicleTemplate() const = 0;
|
||||
|
||||
virtual bool isCalibrationPerformed() const = 0;
|
||||
virtual bool isCalibrationPerformed() const = 0;
|
||||
virtual accelGyroBias getCalibrationBias() const = 0;
|
||||
|
||||
virtual bool isMotorCalibrationPerformed() const = 0;
|
||||
|
@ -43,12 +43,12 @@
|
||||
#include "stabilizationsettingsbank3.h"
|
||||
#include "ekfconfiguration.h"
|
||||
|
||||
const char* VehicleTemplateExportDialog::EXPORT_BASE_NAME = "../share/openpilotgcs/cloudconfig";
|
||||
const char* VehicleTemplateExportDialog::EXPORT_FIXEDWING_NAME = "fixedwing";
|
||||
const char* VehicleTemplateExportDialog::EXPORT_MULTI_NAME = "multirotor";
|
||||
const char* VehicleTemplateExportDialog::EXPORT_HELI_NAME = "helicopter";
|
||||
const char* VehicleTemplateExportDialog::EXPORT_SURFACE_NAME = "surface";
|
||||
const char* VehicleTemplateExportDialog::EXPORT_CUSTOM_NAME = "custom";
|
||||
const char *VehicleTemplateExportDialog::EXPORT_BASE_NAME = "../share/openpilotgcs/cloudconfig";
|
||||
const char *VehicleTemplateExportDialog::EXPORT_FIXEDWING_NAME = "fixedwing";
|
||||
const char *VehicleTemplateExportDialog::EXPORT_MULTI_NAME = "multirotor";
|
||||
const char *VehicleTemplateExportDialog::EXPORT_HELI_NAME = "helicopter";
|
||||
const char *VehicleTemplateExportDialog::EXPORT_SURFACE_NAME = "surface";
|
||||
const char *VehicleTemplateExportDialog::EXPORT_CUSTOM_NAME = "custom";
|
||||
|
||||
VehicleTemplateExportDialog::VehicleTemplateExportDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
@ -165,11 +165,11 @@ QString VehicleTemplateExportDialog::setupVehicleType()
|
||||
QString VehicleTemplateExportDialog::fixFilenameString(QString input, int truncate)
|
||||
{
|
||||
return input.replace(' ', "").replace('|', "").replace('/', "")
|
||||
.replace('\\', "").replace(':', "").replace('"', "")
|
||||
.replace('\'', "").replace('?', "").replace('*', "")
|
||||
.replace('>', "").replace('<', "")
|
||||
.replace('}', "").replace('{', "")
|
||||
.left(truncate);
|
||||
.replace('\\', "").replace(':', "").replace('"', "")
|
||||
.replace('\'', "").replace('?', "").replace('*', "")
|
||||
.replace('>', "").replace('<', "")
|
||||
.replace('}', "").replace('{', "")
|
||||
.left(truncate);
|
||||
}
|
||||
|
||||
|
||||
@ -203,28 +203,29 @@ void VehicleTemplateExportDialog::accept()
|
||||
QByteArray bytes;
|
||||
QBuffer buffer(&bytes);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
m_image.scaled(IMAGE_SCALE_WIDTH, IMAGE_SCALE_HEIGHT, Qt::KeepAspectRatio).save(&buffer, "PNG");
|
||||
exportObject["photo"] = bytes.toBase64().data();
|
||||
m_image.scaled(IMAGE_SCALE_WIDTH, IMAGE_SCALE_HEIGHT, Qt::KeepAspectRatio,
|
||||
Qt::SmoothTransformation).save(&buffer, "PNG");
|
||||
exportObject["photo"] = QString::fromLatin1(bytes.toBase64().data());
|
||||
|
||||
QJsonDocument saveDoc(exportObject);
|
||||
|
||||
QString fileName = QString("%1/%2/%3-%4-%5-%6.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(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)));
|
||||
QFile saveFile(fileName);
|
||||
QDir dir;
|
||||
dir.mkpath(QFileInfo(saveFile).absoluteDir().absolutePath());
|
||||
if (saveFile.open(QIODevice::WriteOnly)) {
|
||||
saveFile.write(saveDoc.toJson());
|
||||
saveFile.close();
|
||||
QMessageBox::information(this, "Export", tr("Settings were exported to \n%1").arg(QFileInfo(saveFile).absoluteFilePath()),QMessageBox::Ok);
|
||||
QMessageBox::information(this, "Export", tr("Settings were exported to \n%1").arg(QFileInfo(saveFile).absoluteFilePath()), QMessageBox::Ok);
|
||||
} else {
|
||||
QMessageBox::information(this, "Export", tr("Settings could not be exported to \n%1.\nPlease try again.")
|
||||
.arg(QFileInfo(saveFile).absoluteFilePath()),QMessageBox::Ok);
|
||||
.arg(QFileInfo(saveFile).absoluteFilePath()), QMessageBox::Ok);
|
||||
}
|
||||
QDialog::accept();
|
||||
}
|
||||
@ -243,15 +244,19 @@ void VehicleTemplateExportDialog::importImage()
|
||||
|
||||
QString VehicleTemplateExportDialog::getTypeDirectory()
|
||||
{
|
||||
switch(m_type) {
|
||||
switch (m_type) {
|
||||
case VehicleConfigurationSource::VEHICLE_FIXEDWING:
|
||||
return EXPORT_FIXEDWING_NAME;
|
||||
|
||||
case VehicleConfigurationSource::VEHICLE_MULTI:
|
||||
return EXPORT_MULTI_NAME;
|
||||
|
||||
case VehicleConfigurationSource::VEHICLE_HELI:
|
||||
return EXPORT_HELI_NAME;
|
||||
|
||||
case VehicleConfigurationSource::VEHICLE_SURFACE:
|
||||
return EXPORT_SURFACE_NAME;
|
||||
|
||||
default:
|
||||
return EXPORT_CUSTOM_NAME;
|
||||
}
|
||||
@ -260,7 +265,6 @@ QString VehicleTemplateExportDialog::getTypeDirectory()
|
||||
void VehicleTemplateExportDialog::updateStatus()
|
||||
{
|
||||
ui->acceptBtn->setEnabled(ui->Name->text().length() > 3 && ui->Owner->text().length() > 2 &&
|
||||
ui->ForumNick->text().length() > 2 && ui->Size->text().length() > 0 &&
|
||||
ui->Weight->text().length() > 0);
|
||||
|
||||
ui->ForumNick->text().length() > 2 && ui->Size->text().length() > 0 &&
|
||||
ui->Weight->text().length() > 0);
|
||||
}
|
||||
|
@ -40,12 +40,12 @@ class VehicleTemplateExportDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static const char* EXPORT_BASE_NAME;
|
||||
static const char* EXPORT_FIXEDWING_NAME;
|
||||
static const char* EXPORT_MULTI_NAME;
|
||||
static const char* EXPORT_HELI_NAME;
|
||||
static const char* EXPORT_SURFACE_NAME;
|
||||
static const char* EXPORT_CUSTOM_NAME;
|
||||
static const char *EXPORT_BASE_NAME;
|
||||
static const char *EXPORT_FIXEDWING_NAME;
|
||||
static const char *EXPORT_MULTI_NAME;
|
||||
static const char *EXPORT_HELI_NAME;
|
||||
static const char *EXPORT_SURFACE_NAME;
|
||||
static const char *EXPORT_CUSTOM_NAME;
|
||||
|
||||
explicit VehicleTemplateExportDialog(QWidget *parent = 0);
|
||||
~VehicleTemplateExportDialog();
|
||||
@ -58,7 +58,7 @@ private slots:
|
||||
void importImage();
|
||||
|
||||
private:
|
||||
static const int IMAGE_SCALE_WIDTH = 500;
|
||||
static const int IMAGE_SCALE_WIDTH = 500;
|
||||
static const int IMAGE_SCALE_HEIGHT = 500;
|
||||
Ui::VehicleTemplateExportDialog *ui;
|
||||
UAVObjectManager *m_uavoManager;
|
||||
|
@ -301,14 +301,14 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_3">
|
||||
<widget class="QFrame" name="frame_6">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
@ -322,95 +322,166 @@
|
||||
<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>
|
||||
<widget class="QFrame" name="frame_3">
|
||||
<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 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 alignment="Qt::AlignTop">
|
||||
<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="MinimumExpanding">
|
||||
<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 alignment="Qt::AlignRight">
|
||||
<widget class="QPushButton" name="ImportButton">
|
||||
<property name="text">
|
||||
<string>Select Image...</string>
|
||||
<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="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<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="frameShadow">
|
||||
<enum>QFrame::Sunken</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>
|
||||
<widget class="QFrame" name="frame_7">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_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_15">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>8</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Photo will be scaled to 500x500px</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="ImportButton">
|
||||
<property name="text">
|
||||
<string>Select Image...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<zorder>frame_4</zorder>
|
||||
<zorder>frame_3</zorder>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
Loading…
x
Reference in New Issue
Block a user