mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-30 15:52:12 +01:00
OP-1571 Fixed template export.
User can now choose a place and a name if preferred. Location will be default location in GCS config dir if it exists, otherwise in the users home directory. Added code to handle exort and import/selection of template without image.
This commit is contained in:
parent
230367145c
commit
612c3802ec
@ -101,7 +101,7 @@ void AirframeInitialTuningPage::updatePhoto(QJsonObject *templ)
|
||||
if (m_photoItem != NULL) {
|
||||
ui->templateImage->scene()->removeItem(m_photoItem);
|
||||
}
|
||||
if (templ != NULL) {
|
||||
if (templ != NULL && !templ->value("photo").isUndefined()) {
|
||||
QByteArray imageData = QByteArray::fromBase64(templ->value("photo").toString().toLatin1());
|
||||
photo.loadFromData(imageData, "PNG");
|
||||
} else {
|
||||
|
@ -376,8 +376,8 @@ void OutputCalibrationPage::on_motorNeutralButton_toggled(bool checked)
|
||||
ui->motorNeutralButton->setText(checked ? tr("Stop") : tr("Start"));
|
||||
ui->motorNeutralSlider->setEnabled(checked);
|
||||
quint16 channel = getCurrentChannel();
|
||||
quint16 safeValue = m_actuatorSettings[channel].channelNeutral;
|
||||
onStartButtonToggle(ui->motorNeutralButton, channel, m_actuatorSettings[channel].channelNeutral, 0, ui->motorNeutralSlider);
|
||||
quint16 safeValue = 0;
|
||||
onStartButtonToggle(ui->motorNeutralButton, channel, m_actuatorSettings[channel].channelNeutral, safeValue, ui->motorNeutralSlider);
|
||||
}
|
||||
|
||||
void OutputCalibrationPage::onStartButtonToggle(QAbstractButton *button, quint16 channel, quint16 value, quint16 safeValue, QSlider *slider)
|
||||
|
@ -56,10 +56,11 @@
|
||||
|
||||
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_vehicleTemplate(NULL),
|
||||
m_gpsType(GPS_DISABLED), m_airspeedType(AIRSPEED_DISABLED),
|
||||
m_calibrationPerformed(false), m_restartNeeded(false), m_connectionManager(0)
|
||||
m_vehicleType(VEHICLE_UNKNOWN), m_inputType(INPUT_UNKNOWN),
|
||||
m_escType(ESC_UNKNOWN), m_servoType(SERVO_UNKNOWN),
|
||||
m_airspeedType(AIRSPEED_DISABLED), m_gpsType(GPS_DISABLED),
|
||||
m_vehicleTemplate(NULL), m_calibrationPerformed(false),
|
||||
m_restartNeeded(false), m_connectionManager(NULL)
|
||||
{
|
||||
setWindowTitle(tr("OpenPilot Setup Wizard"));
|
||||
setOption(QWizard::IndependentPages, false);
|
||||
|
@ -162,6 +162,16 @@ 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()
|
||||
{
|
||||
QJsonObject exportObject;
|
||||
@ -191,23 +201,44 @@ void VehicleTemplateExportDialog::accept()
|
||||
QUuid uuid = QUuid::createUuid();
|
||||
exportObject["uuid"] = uuid.toString();
|
||||
|
||||
QByteArray bytes;
|
||||
QBuffer buffer(&bytes);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
m_image.scaled(IMAGE_SCALE_WIDTH, IMAGE_SCALE_HEIGHT, Qt::KeepAspectRatio,
|
||||
Qt::SmoothTransformation).save(&buffer, "PNG");
|
||||
exportObject["photo"] = QString::fromLatin1(bytes.toBase64().data());
|
||||
if (!m_image.isNull()) {
|
||||
QByteArray bytes;
|
||||
QBuffer buffer(&bytes);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
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);
|
||||
|
||||
const char *fileType = ".optmpl";
|
||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Export settings"), "fileName""", QString("%1 (*%2)").arg(tr("OPTemplates", fileType)));
|
||||
|
||||
if (!fileName.isEmpty()) {
|
||||
if (!fileName.endsWith(fileType)) {
|
||||
fileName.append(fileType);
|
||||
QString fileName = QString("%1-%2-%3%4")
|
||||
.arg(fixFilenameString(ui->Name->text(), 20))
|
||||
.arg(fixFilenameString(ui->Type->text(), 30))
|
||||
.arg(fixFilenameString(uuid.toString().right(12)))
|
||||
.arg(fileType);
|
||||
|
||||
QString fullPath = QString("%1%2%3%4%5")
|
||||
.arg(EXPORT_BASE_NAME)
|
||||
.arg(QDir::separator())
|
||||
.arg(getTypeDirectory())
|
||||
.arg(QDir::separator())
|
||||
.arg(fileName);
|
||||
|
||||
QDir dir = QFileInfo(QFile(fullPath)).absoluteDir();
|
||||
if (!dir.exists()) {
|
||||
fullPath = QString("%1%2%3").arg(QDir::homePath(), QDir::separator(), fileName);
|
||||
}
|
||||
|
||||
fullPath = QFileDialog::getSaveFileName(this, tr("Export settings"), fullPath, QString("%1 (*%2)").arg(tr("OPTemplates", fileType)));
|
||||
|
||||
if (!fullPath.isEmpty()) {
|
||||
if (!fullPath.endsWith(fileType)) {
|
||||
fullPath.append(fileType);
|
||||
}
|
||||
QFile saveFile(fileName);
|
||||
QFile saveFile(fullPath);
|
||||
if (saveFile.open(QIODevice::WriteOnly)) {
|
||||
saveFile.write(saveDoc.toJson());
|
||||
saveFile.close();
|
||||
|
@ -66,6 +66,7 @@ private:
|
||||
VehicleConfigurationSource::VEHICLE_SUB_TYPE m_subType;
|
||||
QPixmap m_image;
|
||||
|
||||
QString fixFilenameString(QString input, int truncate = 100);
|
||||
QString getTypeDirectory();
|
||||
QString setupVehicleType();
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user