From 7b3241cca99baa3a3907b02d42dd4415cacc5621 Mon Sep 17 00:00:00 2001 From: Pip Date: Mon, 13 Jun 2011 16:12:04 +0100 Subject: [PATCH] Fixed GCS export file selection problem - in windows. --- .../importexport/importexportgadgetwidget.cpp | 52 ++-- .../importexport/importexportgadgetwidget.h | 4 +- .../importexport/importexportgadgetwidget.ui | 238 +++++++----------- 3 files changed, 123 insertions(+), 171 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.cpp b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.cpp index 350e1a3ff..6e1d4d2c3 100644 --- a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -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(); - 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")) + 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()) { + return; + } + + // Add a "XML" extension to the file in case it does not exist: + 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()); diff --git a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.h b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.h index ced46a059..bb6d46aa3 100644 --- a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.h +++ b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.h @@ -41,8 +41,10 @@ private: void importConfiguration(const QString& fileName); QList getConfigurables(); + QString filename; + private slots: - void on_resetButton_clicked(); + void on_resetButton_clicked(); void on_helpButton_clicked(); void on_importButton_clicked(); void on_exportButton_clicked(); diff --git a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.ui b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.ui index c29461d5c..d466d1dd2 100644 --- a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.ui +++ b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.ui @@ -7,162 +7,118 @@ 0 0 483 - 271 + 154 Form - - - + + + - - - - 0 - 0 - - - - Config File + + + Items + + + + + General (Workspace, Key-Bindings) + + + true + + + + + + + All Gadgets + + + true + + + + + + + Plugins + + + true + + + + - - - - 0 - 0 - - - - - - - - - - Items - - - - - - General (Workspace, Key-Bindings) - - - true - - - - - - - All Gadgets - - - true - - - - - - - Plugins - - - true - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 32 - 32 - - - - - - - - :/core/images/helpicon.svg:/core/images/helpicon.svg - - - - 32 - 32 - - - - true - - - - - - - Export the GCS settings selected in the checkboxes above. - - - Export - - - - - - - Import settings from the config file, only for the items checked above. - - - Import - - - - - - - Resets your GCS configuration to its default configuration. - - - Reset Config - - + + + + + + 32 + 32 + + + + + + + + :/core/images/helpicon.svg:/core/images/helpicon.svg + + + + 32 + 32 + + + + true + + + + + + + Export the GCS settings selected in the checkboxes above. + + + Export + + + + + + + Import settings from the config file, only for the items checked above. + + + Import + + + + + + + Resets your GCS configuration to its default configuration. + + + Reset Config + + + + - - - Utils::PathChooser - QWidget -
utils/pathchooser.h
- 1 -
-