1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

Fixed GCS export file selection problem - in windows.

This commit is contained in:
Pip 2011-06-13 16:12:04 +01:00
parent a13c8470d3
commit 7b3241cca9
3 changed files with 123 additions and 171 deletions

View File

@ -37,6 +37,7 @@
#include <QSettings>
#include <QMessageBox>
#include <QFileInfo>
#include <QFileDialog>
#include <QDesktopServices>
#include <QUrl>
#include <QDir>
@ -47,10 +48,8 @@ ImportExportGadgetWidget::ImportExportGadgetWidget(QWidget *parent) :
{
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
ui->setupUi(this);
ui->configFile->setExpectedKind(Utils::PathChooser::File);
ui->configFile->setPromptDialogFilter(tr("XML file (*.xml)"));
ui->configFile->setPromptDialogTitle(tr("Choose configuration file"));
filename = "";
}
ImportExportGadgetWidget::~ImportExportGadgetWidget()
@ -72,35 +71,21 @@ void ImportExportGadgetWidget::changeEvent(QEvent *e)
void ImportExportGadgetWidget::on_exportButton_clicked()
{
QString file = ui->configFile->path();
QString file = filename;
QString filter = tr("GCS Settings file (*.xml)");
file = QFileDialog::getSaveFileName(this, tr("Save GCS Settings too file .."), QFileInfo(file).absoluteFilePath(), filter).trimmed();
if (file.isEmpty()) {
QMessageBox msgBox;
msgBox.setText(tr("Empty File name."));
msgBox.setInformativeText(tr("Please choose an export file name."));
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
return;
}
// Add a "XML" extension to the file in case it does not exist:
if (!file.endsWith(".xml"))
if (!file.toLower().endsWith(".xml"))
file.append(".xml");
filename = file;
qDebug() << "Export pressed! Write to file " << QFileInfo(file).absoluteFilePath();
if ( QFileInfo(file).exists() ){
QMessageBox msgBox;
msgBox.setText(tr("File already exists."));
msgBox.setInformativeText(tr("Do you want to overwrite the existing file?"));
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok);
if ( msgBox.exec() == QMessageBox::Ok ){
QFileInfo(file).absoluteDir().remove(QFileInfo(file).fileName());
}
else{
qDebug() << "Export canceled!";
return;
}
}
QMessageBox msgBox;
QDir dir = QFileInfo(file).absoluteDir();
if (! dir.exists()) {
@ -163,8 +148,17 @@ void ImportExportGadgetWidget::writeError(const QString& msg) const
void ImportExportGadgetWidget::on_importButton_clicked()
{
QString file = ui->configFile->path();
QString file = filename;
QString filter = tr("GCS Settings file (*.xml)");
file = QFileDialog::getOpenFileName(this, tr("Load GCS Settings from file .."), QFileInfo(file).absoluteFilePath(), filter).trimmed();
if (file.isEmpty()) {
return;
}
filename = file;
qDebug() << "Import pressed! Read from file " << QFileInfo(file).absoluteFilePath();
QMessageBox msgBox;
if (! QFileInfo(file).isReadable()) {
msgBox.setText(tr("Can't read file ") + QFileInfo(file).absoluteFilePath());

View File

@ -41,6 +41,8 @@ private:
void importConfiguration(const QString& fileName);
QList<Core::IConfigurablePlugin*> getConfigurables();
QString filename;
private slots:
void on_resetButton_clicked();
void on_helpButton_clicked();

View File

@ -7,41 +7,16 @@
<x>0</x>
<y>0</y>
<width>483</width>
<height>271</height>
<height>154</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Config File</string>
</property>
</widget>
</item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="Utils::PathChooser" name="configFile" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="groupBoxItems">
<property name="title">
<string>Items</string>
@ -80,21 +55,8 @@
</layout>
</widget>
</item>
<item row="2" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<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>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="helpButton">
<property name="maximumSize">
@ -154,15 +116,9 @@
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Utils::PathChooser</class>
<extends>QWidget</extends>
<header>utils/pathchooser.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../coreplugin/core.qrc"/>
</resources>