mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
OP-1222 Added generated file name and export to a specific directory.
Added scaling of image to save file size. Added sanity check of input data to not be empty fields.
This commit is contained in:
parent
7bcdff9f2f
commit
0d6aabe37b
@ -65,8 +65,6 @@ private:
|
||||
|
||||
protected:
|
||||
void enableControls(bool enable);
|
||||
void resizeEvent(QResizeEvent *);
|
||||
void showEvent(QShowEvent *);
|
||||
|
||||
private slots:
|
||||
virtual void setupUI(QString airframeType);
|
||||
|
@ -34,6 +34,9 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QUuid>
|
||||
#include <QDebug>
|
||||
#include <QMessageBox>
|
||||
#include "stabilizationsettings.h"
|
||||
#include "stabilizationsettingsbank1.h"
|
||||
#include "stabilizationsettingsbank2.h"
|
||||
@ -50,6 +53,12 @@ VehicleTemplateExportDialog::VehicleTemplateExportDialog(QWidget *parent) :
|
||||
m_uavoManager = pm->getObject<UAVObjectManager>();
|
||||
ui->Photo->setScene(new QGraphicsScene(this));
|
||||
ui->Type->setText(setupVehicleType());
|
||||
|
||||
connect(ui->Name, SIGNAL(textChanged(QString)), this, SLOT(updateStatus()));
|
||||
connect(ui->Owner, SIGNAL(textChanged(QString)), this, SLOT(updateStatus()));
|
||||
connect(ui->ForumNick, SIGNAL(textChanged(QString)), this, SLOT(updateStatus()));
|
||||
connect(ui->Size, SIGNAL(textChanged(QString)), this, SLOT(updateStatus()));
|
||||
connect(ui->Weight, SIGNAL(textChanged(QString)), this, SLOT(updateStatus()));
|
||||
}
|
||||
|
||||
VehicleTemplateExportDialog::~VehicleTemplateExportDialog()
|
||||
@ -146,52 +155,65 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
void VehicleTemplateExportDialog::accept()
|
||||
{
|
||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Export template"), "", tr("Template (*.optmpl)"));
|
||||
QJsonObject exportObject;
|
||||
|
||||
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);
|
||||
|
||||
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();
|
||||
|
||||
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.scaled(500, 500, Qt::KeepAspectRatio).save(&buffer, "PNG");
|
||||
exportObject["photo"] = bytes.toBase64().data();
|
||||
|
||||
QByteArray bytes;
|
||||
QBuffer buffer(&bytes);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
m_image.save(&buffer, "PNG");
|
||||
exportObject["photo"] = bytes.toBase64().data();
|
||||
QJsonDocument saveDoc(exportObject);
|
||||
|
||||
QJsonDocument saveDoc(exportObject);
|
||||
saveFile.write(saveDoc.toJson());
|
||||
saveFile.close();
|
||||
}
|
||||
QString fileName = QString("../share/openpilotgcs/cloudconfig/%1/%2-%3-%4-%5.optmpl")
|
||||
.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);
|
||||
}
|
||||
QDialog::accept();
|
||||
}
|
||||
@ -207,3 +229,27 @@ void VehicleTemplateExportDialog::importImage()
|
||||
ui->Photo->fitInView(ui->Photo->scene()->itemsBoundingRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
}
|
||||
|
||||
QString VehicleTemplateExportDialog::getTypeDirectory()
|
||||
{
|
||||
switch(m_type) {
|
||||
case VehicleConfigurationSource::VEHICLE_FIXEDWING:
|
||||
return "fixedwing";
|
||||
case VehicleConfigurationSource::VEHICLE_MULTI:
|
||||
return "multirotor";
|
||||
case VehicleConfigurationSource::VEHICLE_HELI:
|
||||
return "helicopter";
|
||||
case VehicleConfigurationSource::VEHICLE_SURFACE:
|
||||
return "surface";
|
||||
default:
|
||||
return "custom";
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ public:
|
||||
|
||||
public slots:
|
||||
void accept();
|
||||
void updateStatus();
|
||||
|
||||
private slots:
|
||||
void importImage();
|
||||
@ -52,10 +53,13 @@ private slots:
|
||||
private:
|
||||
Ui::VehicleTemplateExportDialog *ui;
|
||||
UAVObjectManager *m_uavoManager;
|
||||
QString setupVehicleType();
|
||||
VehicleConfigurationSource::VEHICLE_TYPE m_type;
|
||||
VehicleConfigurationSource::VEHICLE_SUB_TYPE m_subType;
|
||||
QPixmap m_image;
|
||||
|
||||
QString getTypeDirectory();
|
||||
QString setupVehicleType();
|
||||
QString fixFilenameString(QString input, int truncate = 100);
|
||||
};
|
||||
|
||||
#endif // VEHICLETEMPLATEEXPORTDIALOG_H
|
||||
|
@ -413,14 +413,58 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item alignment="Qt::AlignBottom">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_5">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<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>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="cancelBtn">
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="acceptBtn">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Ok</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
@ -428,34 +472,34 @@
|
||||
<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>
|
||||
<sender>cancelBtn</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>VehicleTemplateExportDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
<x>458</x>
|
||||
<y>668</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
<x>304</x>
|
||||
<y>349</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>acceptBtn</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>VehicleTemplateExportDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>549</x>
|
||||
<y>668</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>304</x>
|
||||
<y>349</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
|
Loading…
x
Reference in New Issue
Block a user