1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-19 04:52:12 +01:00

OP-1763 Added function to save template in default location.

This commit is contained in:
m_thread 2015-03-18 11:51:06 +01:00
parent 48ef30850f
commit 1e1b97bd77
3 changed files with 75 additions and 64 deletions

View File

@ -46,6 +46,7 @@
#include "mixersettings.h"
#include "ekfconfiguration.h"
#include <uavtalk/telemetrymanager.h>
#include <utils/pathutils.h>
const char *VehicleTemplateExportDialog::EXPORT_BASE_NAME = "../share/openpilotgcs/cloudconfig";
const char *VehicleTemplateExportDialog::EXPORT_FIXEDWING_NAME = "fixedwing";
@ -56,7 +57,7 @@ const char *VehicleTemplateExportDialog::EXPORT_CUSTOM_NAME = "custom";
VehicleTemplateExportDialog::VehicleTemplateExportDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::VehicleTemplateExportDialog)
ui(new Ui::VehicleTemplateExportDialog), m_autopilotConnected(false)
{
ui->setupUi(this);
connect(ui->ImportButton, SIGNAL(clicked()), this, SLOT(importImage()));
@ -73,12 +74,17 @@ VehicleTemplateExportDialog::VehicleTemplateExportDialog(QWidget *parent) :
connect(ui->Weight, SIGNAL(textChanged(QString)), this, SLOT(updateStatus()));
connect(ui->exportBtn, SIGNAL(clicked()), this, SLOT(exportTemplate()));
connect(ui->saveAsBtn, SIGNAL(clicked()), this, SLOT(saveAsTemplate()));
connect(ui->importBtn, SIGNAL(clicked()), this, SLOT(importTemplate()));
connect(ui->cancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
connect(ui->cancelBtn_2, SIGNAL(clicked()), this, SLOT(reject()));
TelemetryManager *telemManager = pm->getObject<TelemetryManager>();
ui->importBtn->setEnabled(telemManager->isConnected());
if (telemManager->isConnected()) {
onAutoPilotConnect();
} else {
onAutoPilotDisconnect();
}
connect(telemManager, SIGNAL(connected()), this, SLOT(onAutoPilotConnect()));
connect(telemManager, SIGNAL(disconnected()), this, SLOT(onAutoPilotDisconnect()));
@ -183,17 +189,7 @@ 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::exportTemplate()
void VehicleTemplateExportDialog::saveTemplate(QString path)
{
QJsonObject exportObject;
@ -242,20 +238,14 @@ void VehicleTemplateExportDialog::exportTemplate()
.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(fullPath).absoluteDir();
if (!dir.exists()) {
fullPath = QString("%1%2%3").arg(QDir::homePath(), QDir::separator(), fileName);
QString fullPath;
if (path.isEmpty()) {
fullPath = QString("%1%2%3").arg(QDir::homePath()).arg(QDir::separator()).arg(fileName);
fullPath = QFileDialog::getSaveFileName(this, tr("Export settings"), fullPath, QString("%1 (*%2)").arg(tr("OPTemplates"), fileType));
} else {
fullPath = QString("%1%2%3").arg(path).arg(QDir::separator()).arg(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);
@ -268,10 +258,33 @@ void VehicleTemplateExportDialog::exportTemplate()
QMessageBox::information(this, "Export", tr("Settings could not be exported to \n%1(%2).\nPlease try again.")
.arg(QFileInfo(saveFile).absoluteFilePath(), saveFile.error()), QMessageBox::Ok);
}
QDialog::accept();
}
}
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::exportTemplate()
{
QString path = QString("%1%2%3%4").arg(Utils::PathUtils().InsertStoragePath("%%STOREPATH%%cloudconfig"))
.arg(QDir::separator()).arg(getTypeDirectory()).arg(QDir::separator());
QDir dir;
dir.mkpath(path);
saveTemplate(path);
}
void VehicleTemplateExportDialog::saveAsTemplate()
{
saveTemplate(QString(""));
}
void VehicleTemplateExportDialog::importTemplate()
{
QJsonObject *tmpl = ui->selectionWidget->selectedTemplate();
@ -315,11 +328,15 @@ void VehicleTemplateExportDialog::importImage()
void VehicleTemplateExportDialog::onAutoPilotConnect()
{
ui->importBtn->setEnabled(true);
m_autopilotConnected = true;
updateStatus();
}
void VehicleTemplateExportDialog::onAutoPilotDisconnect()
{
ui->importBtn->setEnabled(false);
m_autopilotConnected = false;
updateStatus();
}
QString VehicleTemplateExportDialog::getTypeDirectory()
@ -344,7 +361,9 @@ QString VehicleTemplateExportDialog::getTypeDirectory()
void VehicleTemplateExportDialog::updateStatus()
{
ui->exportBtn->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);
bool enabled = m_autopilotConnected && 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->exportBtn->setEnabled(enabled);
ui->saveAsBtn->setEnabled(enabled);
}

View File

@ -52,6 +52,7 @@ public:
public slots:
void exportTemplate();
void saveAsTemplate();
void importTemplate();
void updateStatus();
@ -68,10 +69,12 @@ private:
VehicleConfigurationSource::VEHICLE_TYPE m_type;
VehicleConfigurationSource::VEHICLE_SUB_TYPE m_subType;
QPixmap m_image;
bool m_autopilotConnected;
QString fixFilenameString(QString input, int truncate = 100);
QString getTypeDirectory();
QString setupVehicleType();
void saveTemplate(QString path);
};
#endif // VEHICLETEMPLATEEXPORTDIALOG_H

View File

@ -507,7 +507,20 @@
<item>
<widget class="QPushButton" name="cancelBtn">
<property name="text">
<string>Cancel</string>
<string>Close</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="saveAsBtn">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Save as</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
@ -519,6 +532,9 @@
<property name="text">
<string>Export</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
@ -590,6 +606,12 @@
<property name="text">
<string>Import</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
@ -653,38 +675,5 @@
<tabstop>Photo</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>cancelBtn</sender>
<signal>clicked()</signal>
<receiver>VehicleTemplateExportDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>458</x>
<y>668</y>
</hint>
<hint type="destinationlabel">
<x>304</x>
<y>349</y>
</hint>
</hints>
</connection>
<connection>
<sender>exportBtn</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>
</connections>
<connections/>
</ui>