Commit d652eeb9 authored by Don Gagne's avatar Don Gagne

Merge pull request #1187 from dogmaphobic/issue1185

Removing unused selectedFilter argument from QGXFileDialog methods.
parents 9bd7680f 9b6b8778
...@@ -476,13 +476,12 @@ void QGCApplication::criticalMessageBoxOnMainThread(const QString& title, const ...@@ -476,13 +476,12 @@ void QGCApplication::criticalMessageBoxOnMainThread(const QString& title, const
void QGCApplication::saveTempFlightDataLogOnMainThread(QString tempLogfile) void QGCApplication::saveTempFlightDataLogOnMainThread(QString tempLogfile)
{ {
QString defaultSuffix("mavlink"); QString saveFilename = QGCFileDialog::getSaveFileName(
QString saveFilename = QGCFileDialog::getSaveFileName(MainWindow::instance(), MainWindow::instance(),
tr("Select file to save Flight Data Log"), tr("Save Flight Data Log"),
qgcApp()->mavlinkLogFilesLocation(), qgcApp()->mavlinkLogFilesLocation(),
tr("Flight Data Log (*.mavlink)"), tr("Flight Data Log (*.mavlink)"),
0,0, "mavlink");
&defaultSuffix);
if (!saveFilename.isEmpty()) { if (!saveFilename.isEmpty()) {
QFile::copy(tempLogfile, saveFilename); QFile::copy(tempLogfile, saveFilename);
} }
......
...@@ -28,12 +28,13 @@ ...@@ -28,12 +28,13 @@
#include "UnitTest.h" #include "UnitTest.h"
#endif #endif
QString QGCFileDialog::getExistingDirectory(QWidget* parent, QString QGCFileDialog::getExistingDirectory(
const QString& caption, QWidget* parent,
const QString& dir, const QString& caption,
Options options) const QString& dir,
Options options)
{ {
_validate(NULL, options); _validate(options);
#ifdef QT_DEBUG #ifdef QT_DEBUG
if (qgcApp()->runningUnitTests()) { if (qgcApp()->runningUnitTests()) {
...@@ -45,57 +46,57 @@ QString QGCFileDialog::getExistingDirectory(QWidget* parent, ...@@ -45,57 +46,57 @@ QString QGCFileDialog::getExistingDirectory(QWidget* parent,
} }
} }
QString QGCFileDialog::getOpenFileName(QWidget* parent, QString QGCFileDialog::getOpenFileName(
const QString& caption, QWidget* parent,
const QString& dir, const QString& caption,
const QString& filter, const QString& dir,
QString* selectedFilter, const QString& filter,
Options options) Options options)
{ {
_validate(selectedFilter, options); _validate(options);
#ifdef QT_DEBUG #ifdef QT_DEBUG
if (qgcApp()->runningUnitTests()) { if (qgcApp()->runningUnitTests()) {
return UnitTest::_getOpenFileName(parent, caption, dir, filter, selectedFilter, options); return UnitTest::_getOpenFileName(parent, caption, dir, filter, options);
} else } else
#endif #endif
{ {
return QFileDialog::getOpenFileName(parent, caption, dir, filter, selectedFilter, options); return QFileDialog::getOpenFileName(parent, caption, dir, filter, NULL, options);
} }
} }
QStringList QGCFileDialog::getOpenFileNames(QWidget* parent, QStringList QGCFileDialog::getOpenFileNames(
const QString& caption, QWidget* parent,
const QString& dir, const QString& caption,
const QString& filter, const QString& dir,
QString* selectedFilter, const QString& filter,
Options options) Options options)
{ {
_validate(selectedFilter, options); _validate(options);
#ifdef QT_DEBUG #ifdef QT_DEBUG
if (qgcApp()->runningUnitTests()) { if (qgcApp()->runningUnitTests()) {
return UnitTest::_getOpenFileNames(parent, caption, dir, filter, selectedFilter, options); return UnitTest::_getOpenFileNames(parent, caption, dir, filter, options);
} else } else
#endif #endif
{ {
return QFileDialog::getOpenFileNames(parent, caption, dir, filter, selectedFilter, options); return QFileDialog::getOpenFileNames(parent, caption, dir, filter, NULL, options);
} }
} }
QString QGCFileDialog::getSaveFileName(QWidget* parent, QString QGCFileDialog::getSaveFileName(
const QString& caption, QWidget* parent,
const QString& dir, const QString& caption,
const QString& filter, const QString& dir,
QString* selectedFilter, const QString& filter,
Options options, const QString& defaultSuffix,
QString* defaultSuffix) Options options)
{ {
_validate(selectedFilter, options); _validate(options);
#ifdef QT_DEBUG #ifdef QT_DEBUG
if (qgcApp()->runningUnitTests()) { if (qgcApp()->runningUnitTests()) {
return UnitTest::_getSaveFileName(parent, caption, dir, filter, selectedFilter, options, defaultSuffix); return UnitTest::_getSaveFileName(parent, caption, dir, filter, defaultSuffix, options);
} else } else
#endif #endif
{ {
...@@ -104,12 +105,13 @@ QString QGCFileDialog::getSaveFileName(QWidget* parent, ...@@ -104,12 +105,13 @@ QString QGCFileDialog::getSaveFileName(QWidget* parent,
if (options) { if (options) {
dlg.setOptions(options); dlg.setOptions(options);
} }
if (defaultSuffix) { if (!defaultSuffix.isEmpty()) {
QString suffixCopy(defaultSuffix);
//-- Make sure dot is not present //-- Make sure dot is not present
if (defaultSuffix->startsWith(".")) { if (suffixCopy.startsWith(".")) {
defaultSuffix->remove(0,1); suffixCopy.remove(0,1);
} }
dlg.setDefaultSuffix(*defaultSuffix); dlg.setDefaultSuffix(suffixCopy);
} }
if (dlg.exec()) { if (dlg.exec()) {
if (dlg.selectedFiles().count()) { if (dlg.selectedFiles().count()) {
...@@ -121,17 +123,13 @@ QString QGCFileDialog::getSaveFileName(QWidget* parent, ...@@ -121,17 +123,13 @@ QString QGCFileDialog::getSaveFileName(QWidget* parent,
} }
/// @brief Validates and updates the parameters for the file dialog calls /// @brief Validates and updates the parameters for the file dialog calls
void QGCFileDialog::_validate(QString* selectedFilter, Options& options) void QGCFileDialog::_validate(Options& options)
{ {
// You can't use QGCFileDialog if QGCApplication is not created yet. // You can't use QGCFileDialog if QGCApplication is not created yet.
Q_ASSERT(qgcApp()); Q_ASSERT(qgcApp());
Q_ASSERT_X(QThread::currentThread() == qgcApp()->thread(), "Threading issue", "QGCFileDialog can only be called from main thread"); Q_ASSERT_X(QThread::currentThread() == qgcApp()->thread(), "Threading issue", "QGCFileDialog can only be called from main thread");
// Support for selectedFilter is not yet implemented through the unit test framework
Q_UNUSED(selectedFilter);
Q_ASSERT(selectedFilter == NULL);
// On OSX native dialog can hang so we always use Qt dialogs // On OSX native dialog can hang so we always use Qt dialogs
options |= DontUseNativeDialog; options |= DontUseNativeDialog;
......
...@@ -31,10 +31,21 @@ ...@@ -31,10 +31,21 @@
/// @author Don Gagne <don@thegagnes.com> /// @author Don Gagne <don@thegagnes.com>
/*! /*!
Subclass of <a href="http://qt-project.org/doc/qt-5/qfiledialog.html">QFileDialog</a> which re-implements the static public functions. The reason for this Subclass of <a href="http://qt-project.org/doc/qt-5/qfiledialog.html">QFileDialog</a> which re-implements the static public functions. The reason for this
is that the <a href="http://qt-project.org/doc/qt-5/qfiledialog.html">QFileDialog</a> implementations of these use the native os dialogs. On OSX these is that the <a href="http://qt-project.org/doc/qt-5/qfiledialog.html">QFileDialog</a> implementations of these use the native os dialogs. On OSX these
these can intermittently hang. So instead here we use the native dialogs. It also allows these can intermittently hang. So instead here we use the native dialogs. It also allows
use to catch these dialogs for unit testing. use to catch these dialogs for unit testing.
@remark If you need to know what type of file was returned by these functions, you can use something like:
@code{.cpp}
QString filename = QGCFileDialog::getSaveFileName(this, tr("Save File"), "~/", "Foo files (*.foo);;All Files (*.*)", "foo");
if (!filename.isEmpty()) {
QFileInfo fi(filename);
QString fileExtension(fi.suffix());
if (fileExtension == QString("foo")) {
// do something
}
}
@endcode
*/ */
class QGCFileDialog : public QFileDialog { class QGCFileDialog : public QFileDialog {
...@@ -50,10 +61,11 @@ public: ...@@ -50,10 +61,11 @@ public:
@return The chosen path or \c QString("") if none. @return The chosen path or \c QString("") if none.
@sa <a href="http://qt-project.org/doc/qt-5/qfiledialog.html#getExistingDirectory">QFileDialog::getExistingDirectory()</a> @sa <a href="http://qt-project.org/doc/qt-5/qfiledialog.html#getExistingDirectory">QFileDialog::getExistingDirectory()</a>
*/ */
static QString getExistingDirectory(QWidget* parent = 0, static QString getExistingDirectory(
const QString& caption = QString(), QWidget* parent = 0,
const QString& dir = QString(), const QString& caption = QString(),
Options options = ShowDirsOnly); const QString& dir = QString(),
Options options = ShowDirsOnly);
//! Static helper that invokes a File Open dialog where the user can select a file to be opened. //! Static helper that invokes a File Open dialog where the user can select a file to be opened.
/*! /*!
...@@ -61,17 +73,16 @@ public: ...@@ -61,17 +73,16 @@ public:
@param[in] caption The caption displayed at the top of the dialog. @param[in] caption The caption displayed at the top of the dialog.
@param[in] dir The initial directory shown to the user. @param[in] dir The initial directory shown to the user.
@param[in] filter The filter used for selecting the file type. @param[in] filter The filter used for selecting the file type.
@param[out] selectedFilter **NOT IMPLEMENTED - Set to NULL** Returns the filter that the user selected in the file dialog.
@param[in] options Set the various options that affect the look and feel of the dialog. @param[in] options Set the various options that affect the look and feel of the dialog.
@return The full path and filename to be opened or \c QString("") if none. @return The full path and filename to be opened or \c QString("") if none.
@sa <a href="http://qt-project.org/doc/qt-5/qfiledialog.html#getOpenFileName">QFileDialog::getOpenFileName()</a> @sa <a href="http://qt-project.org/doc/qt-5/qfiledialog.html#getOpenFileName">QFileDialog::getOpenFileName()</a>
*/ */
static QString getOpenFileName(QWidget* parent = 0, static QString getOpenFileName(
const QString& caption = QString(), QWidget* parent = 0,
const QString& dir = QString(), const QString& caption = QString(),
const QString& filter = QString(), const QString& dir = QString(),
QString* selectedFilter = 0, const QString& filter = QString(),
Options options = 0); Options options = 0);
//! Static helper that invokes a File Open dialog where the user can select one or more files to be opened. //! Static helper that invokes a File Open dialog where the user can select one or more files to be opened.
/*! /*!
...@@ -79,17 +90,16 @@ public: ...@@ -79,17 +90,16 @@ public:
@param[in] caption The caption displayed at the top of the dialog. @param[in] caption The caption displayed at the top of the dialog.
@param[in] dir The initial directory shown to the user. @param[in] dir The initial directory shown to the user.
@param[in] filter The filter used for selecting the file type. @param[in] filter The filter used for selecting the file type.
@param[out] selectedFilter **NOT IMPLEMENTED - Set to NULL** Returns the filter that the user selected in the file dialog.
@param[in] options Set the various options that affect the look and feel of the dialog. @param[in] options Set the various options that affect the look and feel of the dialog.
@return A <a href="http://qt-project.org/doc/qt-5/qstringlist.html">QStringList</a> object containing zero or more files to be opened. @return A <a href="http://qt-project.org/doc/qt-5/qstringlist.html">QStringList</a> object containing zero or more files to be opened.
@sa <a href="http://qt-project.org/doc/qt-5/qfiledialog.html#getOpenFileNames">QFileDialog::getOpenFileNames()</a> @sa <a href="http://qt-project.org/doc/qt-5/qfiledialog.html#getOpenFileNames">QFileDialog::getOpenFileNames()</a>
*/ */
static QStringList getOpenFileNames(QWidget* parent = 0, static QStringList getOpenFileNames(
const QString& caption = QString(), QWidget* parent = 0,
const QString& dir = QString(), const QString& caption = QString(),
const QString& filter = QString(), const QString& dir = QString(),
QString* selectedFilter = 0, const QString& filter = QString(),
Options options = 0); Options options = 0);
//! Static helper that invokes a File Save dialog where the user can select a directory and enter a filename to be saved. //! Static helper that invokes a File Save dialog where the user can select a directory and enter a filename to be saved.
/*! /*!
...@@ -97,29 +107,28 @@ public: ...@@ -97,29 +107,28 @@ public:
@param[in] caption The caption displayed at the top of the dialog. @param[in] caption The caption displayed at the top of the dialog.
@param[in] dir The initial directory shown to the user. @param[in] dir The initial directory shown to the user.
@param[in] filter The filter used for selecting the file type. @param[in] filter The filter used for selecting the file type.
@param[out] selectedFilter **NOT IMPLEMENTED - Set to NULL** Returns the filter that the user selected in the file dialog.
@param[in] options Set the various options that affect the look and feel of the dialog.
@param[in] defaultSuffix Specifies a string that will be added to the filename if it has no suffix already. The suffix is typically used to indicate the file type (e.g. "txt" indicates a text file). @param[in] defaultSuffix Specifies a string that will be added to the filename if it has no suffix already. The suffix is typically used to indicate the file type (e.g. "txt" indicates a text file).
@param[in] options Set the various options that affect the look and feel of the dialog.
@return The full path and filename to be used to save the file or \c QString("") if none. @return The full path and filename to be used to save the file or \c QString("") if none.
@sa <a href="http://qt-project.org/doc/qt-5/qfiledialog.html#getSaveFileName">QFileDialog::getSaveFileName()</a> @sa <a href="http://qt-project.org/doc/qt-5/qfiledialog.html#getSaveFileName">QFileDialog::getSaveFileName()</a>
@remark If a default suffix is given, it will be appended to the filename if the user does not enter one themselves. That is, if the user simply enters \e foo and the default suffix is set to \e bar, @remark If a default suffix is given, it will be appended to the filename if the user does not enter one themselves. That is, if the user simply enters \e foo and the default suffix is set to \e bar,
the returned filename will be \e foo.bar. However, if the user specifies a suffix, none will be added. That is, if the user enters \e foo.txt, that's what you will receive in return. the returned filename will be \e foo.bar. However, if the user specifies a suffix, none will be added. That is, if the user enters \e foo.txt, that's what you will receive in return.
*/ */
static QString getSaveFileName(QWidget* parent = 0, static QString getSaveFileName(
const QString& caption = QString(), QWidget* parent = 0,
const QString& dir = QString(), const QString& caption = QString(),
const QString& filter = QString(), const QString& dir = QString(),
QString* selectedFilter = 0, const QString& filter = QString(),
Options options = 0, const QString& defaultSuffix = QString(),
QString* defaultSuffix = 0); Options options = 0);
private slots: private slots:
/// @brief The exec slot is private becasue when only want QGCFileDialog users to use the static methods. Otherwise it will break /// @brief The exec slot is private because we only want QGCFileDialog users to use the static methods. Otherwise it will break
/// unit testing. /// unit testing.
int exec(void) { return QGCFileDialog::exec(); } int exec(void) { return QGCFileDialog::exec(); }
private: private:
static void _validate(QString* selectedFilter, Options& options); static void _validate(Options& options);
}; };
......
...@@ -273,10 +273,11 @@ QString UnitTest::_fileDialogResponseSingle(enum FileDialogType type) ...@@ -273,10 +273,11 @@ QString UnitTest::_fileDialogResponseSingle(enum FileDialogType type)
return retFile; return retFile;
} }
QString UnitTest::_getExistingDirectory(QWidget* parent, QString UnitTest::_getExistingDirectory(
const QString& caption, QWidget* parent,
const QString& dir, const QString& caption,
QFileDialog::Options options) const QString& dir,
QFileDialog::Options options)
{ {
Q_UNUSED(parent); Q_UNUSED(parent);
Q_UNUSED(caption); Q_UNUSED(caption);
...@@ -286,12 +287,12 @@ QString UnitTest::_getExistingDirectory(QWidget* parent, ...@@ -286,12 +287,12 @@ QString UnitTest::_getExistingDirectory(QWidget* parent,
return _fileDialogResponseSingle(getExistingDirectory); return _fileDialogResponseSingle(getExistingDirectory);
} }
QString UnitTest::_getOpenFileName(QWidget* parent, QString UnitTest::_getOpenFileName(
const QString& caption, QWidget* parent,
const QString& dir, const QString& caption,
const QString& filter, const QString& dir,
QString* selectedFilter, const QString& filter,
QFileDialog::Options options) QFileDialog::Options options)
{ {
Q_UNUSED(parent); Q_UNUSED(parent);
Q_UNUSED(caption); Q_UNUSED(caption);
...@@ -299,18 +300,15 @@ QString UnitTest::_getOpenFileName(QWidget* parent, ...@@ -299,18 +300,15 @@ QString UnitTest::_getOpenFileName(QWidget* parent,
Q_UNUSED(filter); Q_UNUSED(filter);
Q_UNUSED(options); Q_UNUSED(options);
// Support for selectedFilter is not yet implemented
Q_ASSERT(selectedFilter == NULL);
return _fileDialogResponseSingle(getOpenFileName); return _fileDialogResponseSingle(getOpenFileName);
} }
QStringList UnitTest::_getOpenFileNames(QWidget* parent, QStringList UnitTest::_getOpenFileNames(
const QString& caption, QWidget* parent,
const QString& dir, const QString& caption,
const QString& filter, const QString& dir,
QString* selectedFilter, const QString& filter,
QFileDialog::Options options) QFileDialog::Options options)
{ {
Q_UNUSED(parent); Q_UNUSED(parent);
Q_UNUSED(caption); Q_UNUSED(caption);
...@@ -318,9 +316,6 @@ QStringList UnitTest::_getOpenFileNames(QWidget* parent, ...@@ -318,9 +316,6 @@ QStringList UnitTest::_getOpenFileNames(QWidget* parent,
Q_UNUSED(filter); Q_UNUSED(filter);
Q_UNUSED(options); Q_UNUSED(options);
// Support for selectedFilter is not yet implemented
Q_ASSERT(selectedFilter == NULL);
QStringList retFiles; QStringList retFiles;
if (!_fileDialogResponseSet || _fileDialogExpectedType != getOpenFileNames) { if (!_fileDialogResponseSet || _fileDialogExpectedType != getOpenFileNames) {
...@@ -340,13 +335,13 @@ QStringList UnitTest::_getOpenFileNames(QWidget* parent, ...@@ -340,13 +335,13 @@ QStringList UnitTest::_getOpenFileNames(QWidget* parent,
return retFiles; return retFiles;
} }
QString UnitTest::_getSaveFileName(QWidget* parent, QString UnitTest::_getSaveFileName(
const QString& caption, QWidget* parent,
const QString& dir, const QString& caption,
const QString& filter, const QString& dir,
QString* selectedFilter, const QString& filter,
QFileDialog::Options options, const QString& defaultSuffix,
QString* defaultSuffix) QFileDialog::Options options)
{ {
Q_UNUSED(parent); Q_UNUSED(parent);
Q_UNUSED(caption); Q_UNUSED(caption);
...@@ -354,11 +349,9 @@ QString UnitTest::_getSaveFileName(QWidget* parent, ...@@ -354,11 +349,9 @@ QString UnitTest::_getSaveFileName(QWidget* parent,
Q_UNUSED(filter); Q_UNUSED(filter);
Q_UNUSED(options); Q_UNUSED(options);
if(defaultSuffix) if(!defaultSuffix.isEmpty()) {
Q_ASSERT(defaultSuffix->startsWith(".") == false); Q_ASSERT(defaultSuffix.startsWith(".") == false);
}
// Support for selectedFilter is not yet implemented
Q_ASSERT(selectedFilter == NULL);
return _fileDialogResponseSingle(getSaveFileName); return _fileDialogResponseSingle(getSaveFileName);
} }
...@@ -118,33 +118,34 @@ private: ...@@ -118,33 +118,34 @@ private:
// When the app is running in unit test mode the QGCFileDialog methods are re-routed here. // When the app is running in unit test mode the QGCFileDialog methods are re-routed here.
static QString _getExistingDirectory(QWidget* parent, static QString _getExistingDirectory(
const QString& caption, QWidget* parent,
const QString& dir, const QString& caption,
QFileDialog::Options options); const QString& dir,
QFileDialog::Options options);
static QString _getOpenFileName(QWidget* parent,
const QString& caption, static QString _getOpenFileName(
const QString& dir, QWidget* parent,
const QString& filter, const QString& caption,
QString* selectedFilter, const QString& dir,
QFileDialog::Options options); const QString& filter,
QFileDialog::Options options);
static QStringList _getOpenFileNames(QWidget* parent,
const QString& caption, static QStringList _getOpenFileNames(
const QString& dir, QWidget* parent,
const QString& filter, const QString& caption,
QString* selectedFilter, const QString& dir,
QFileDialog::Options options); const QString& filter,
QFileDialog::Options options);
static QString _getSaveFileName(QWidget* parent,
const QString& caption, static QString _getSaveFileName(
const QString& dir, QWidget* parent,
const QString& filter, const QString& caption,
QString* selectedFilter, const QString& dir,
QFileDialog::Options options, const QString& filter,
QString* defaultSuffix); const QString& defaultSuffix,
QFileDialog::Options options);
static QString _fileDialogResponseSingle(enum FileDialogType type); static QString _fileDialogResponseSingle(enum FileDialogType type);
// This allows the private calls to the file dialog methods // This allows the private calls to the file dialog methods
......
...@@ -836,16 +836,17 @@ void MainWindow::configureWindowName() ...@@ -836,16 +836,17 @@ void MainWindow::configureWindowName()
void MainWindow::startVideoCapture() void MainWindow::startVideoCapture()
{ {
// TODO: What is this? What kind of "Video" is saved to bmp?
QString format("bmp"); QString format("bmp");
QString initialPath = QDir::currentPath() + tr("/untitled.") + format; QString initialPath = QDir::currentPath() + tr("/untitled.") + format;
QString screenFileName = QGCFileDialog::getSaveFileName(this, tr("Save As"), QString screenFileName = QGCFileDialog::getSaveFileName(
initialPath, this, tr("Save Video Capture"),
tr("%1 Files (*.%2);;All Files (*)") initialPath,
.arg(format.toUpper()) tr("%1 Files (*.%2);;All Files (*)")
.arg(format), .arg(format.toUpper())
0,0, .arg(format),
&format); format);
delete videoTimer; delete videoTimer;
videoTimer = new QTimer(this); videoTimer = new QTimer(this);
} }
......
...@@ -105,8 +105,7 @@ void QGCBaseParamWidget::saveParametersToFile() ...@@ -105,8 +105,7 @@ void QGCBaseParamWidget::saveParametersToFile()
{ {
if (!mav) if (!mav)
return; return;
QString defaultSuffix("txt"); QString fileName = QGCFileDialog::getSaveFileName(this, tr("Save Parameters"), qgcApp()->savedParameterFilesLocation(), tr("Parameter File (*.txt)"), "txt");
QString fileName = QGCFileDialog::getSaveFileName(this, tr("Save File"), qgcApp()->savedParameterFilesLocation(), tr("Parameter File (*.txt)"), 0, 0, &defaultSuffix);
QFile file(fileName); QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
return; return;
...@@ -123,7 +122,7 @@ void QGCBaseParamWidget::loadParametersFromFile() ...@@ -123,7 +122,7 @@ void QGCBaseParamWidget::loadParametersFromFile()
if (!mav) if (!mav)
return; return;
QString fileName = QGCFileDialog::getOpenFileName(this, tr("Load File"), qgcApp()->savedParameterFilesLocation(), tr("Parameter file (*.txt)")); QString fileName = QGCFileDialog::getOpenFileName(this, tr("Load Parameters"), qgcApp()->savedParameterFilesLocation(), tr("Parameter file (*.txt)"));
QFile file(fileName); QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return; return;
......
...@@ -100,13 +100,17 @@ void QGCDataPlot2D::loadFile() ...@@ -100,13 +100,17 @@ void QGCDataPlot2D::loadFile()
void QGCDataPlot2D::loadFile(QString file) void QGCDataPlot2D::loadFile(QString file)
{ {
// TODO This "filename" is a private/protected member variable. It should be named in such way
// it indicates so. This same name is used in several places within this file in local scopes.
fileName = file; fileName = file;
if (QFileInfo(fileName).isReadable()) { QFileInfo fi(fileName);
if (fileName.contains(".raw") || fileName.contains(".imu")) { if (fi.isReadable()) {
if (fi.suffix() == QString("raw") || fi.suffix() == QString("imu")) {
loadRawLog(fileName); loadRawLog(fileName);
} else if (fileName.contains(".txt") || fileName.contains(".csv") || fileName.contains(".csv")) { } else if (fi.suffix() == QString("txt") || fi.suffix() == QString("csv")) {
loadCsvLog(fileName); loadCsvLog(fileName);
} }
// TODO Else, tell the user it doesn't know what to do with the file...
} }
} }
...@@ -115,12 +119,10 @@ void QGCDataPlot2D::loadFile(QString file) ...@@ -115,12 +119,10 @@ void QGCDataPlot2D::loadFile(QString file)
*/ */
QString QGCDataPlot2D::getSavePlotFilename() QString QGCDataPlot2D::getSavePlotFilename()
{ {
QString defaultSuffix("pdf");
QString fileName = QGCFileDialog::getSaveFileName( QString fileName = QGCFileDialog::getSaveFileName(
this, "Export File Name", QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), this, "Save Plot File", QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
"PDF Documents (*.pdf);;SVG Images (*.svg)", "PDF Documents (*.pdf);;SVG Images (*.svg)",
0,0, "pdf");
&defaultSuffix);
return fileName; return fileName;
} }
...@@ -133,11 +135,13 @@ void QGCDataPlot2D::savePlot() ...@@ -133,11 +135,13 @@ void QGCDataPlot2D::savePlot()
if (fileName.isEmpty()) if (fileName.isEmpty())
return; return;
// TODO This will change once we add "strict" file types in file selection dialogs
while(!(fileName.endsWith(".svg") || fileName.endsWith(".pdf"))) { while(!(fileName.endsWith(".svg") || fileName.endsWith(".pdf"))) {
QMessageBox::StandardButton button = QGCMessageBox::critical(tr("Unsuitable file extension for PDF or SVG"), QMessageBox::StandardButton button = QGCMessageBox::warning(
tr("Please choose .pdf or .svg as file extension. Click OK to change the file extension, cancel to not save the file."), tr("Unsuitable file extension for Plot document type."),
QMessageBox::Ok | QMessageBox::Cancel, tr("Please choose .pdf or .svg as file extension. Click OK to change the file extension, cancel to not save the file."),
QMessageBox::Ok); QMessageBox::Ok | QMessageBox::Cancel,
QMessageBox::Ok);
// Abort if cancelled // Abort if cancelled
if (button == QMessageBox::Cancel) { if (button == QMessageBox::Cancel) {
return; return;
...@@ -690,12 +694,10 @@ bool QGCDataPlot2D::linearRegression(double *x, double *y, int n, double *a, dou ...@@ -690,12 +694,10 @@ bool QGCDataPlot2D::linearRegression(double *x, double *y, int n, double *a, dou
void QGCDataPlot2D::saveCsvLog() void QGCDataPlot2D::saveCsvLog()
{ {
QString defaultSuffix("csv");
QString fileName = QGCFileDialog::getSaveFileName( QString fileName = QGCFileDialog::getSaveFileName(
this, "Export CSV File Name", QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), this, "Save CSV Log File", QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
"CSV file (*.csv);;Text file (*.txt)", "CSV file (*.csv);;Text file (*.txt)",
0,0, "csv");
&defaultSuffix);
if (fileName.isEmpty()) if (fileName.isEmpty())
return; //User cancelled return; //User cancelled
......
...@@ -217,14 +217,15 @@ void WaypointList::setUAS(UASInterface* uas) ...@@ -217,14 +217,15 @@ void WaypointList::setUAS(UASInterface* uas)
void WaypointList::saveWaypoints() void WaypointList::saveWaypoints()
{ {
QString defaultSuffix("txt"); // TODO Need better default directory
QString fileName = QGCFileDialog::getSaveFileName(this, tr("Save File"), "./waypoints.txt", tr("Waypoint File (*.txt)"), 0, 0, &defaultSuffix); // TODO Need better extension than .txt
QString fileName = QGCFileDialog::getSaveFileName(this, tr("Save Waypoint File"), "./waypoints.txt", tr("Waypoint File (*.txt)"), "txt");
WPM->saveWaypoints(fileName); WPM->saveWaypoints(fileName);
} }
void WaypointList::loadWaypoints() void WaypointList::loadWaypoints()
{ {
QString fileName = QGCFileDialog::getOpenFileName(this, tr("Load File"), ".", tr("Waypoint File (*.txt)")); QString fileName = QGCFileDialog::getOpenFileName(this, tr("Load Waypoint File"), ".", tr("Waypoint File (*.txt)"));
WPM->loadWaypoints(fileName); WPM->loadWaypoints(fileName);
} }
......
...@@ -571,14 +571,12 @@ void QGCToolWidget::widgetRemoved() ...@@ -571,14 +571,12 @@ void QGCToolWidget::widgetRemoved()
void QGCToolWidget::exportWidget() void QGCToolWidget::exportWidget()
{ {
QString defaultSuffix("qgw");
const QString widgetFileExtension(".qgw"); const QString widgetFileExtension(".qgw");
QString fileName = QGCFileDialog::getSaveFileName( QString fileName = QGCFileDialog::getSaveFileName(
this, tr("Specify File Name"), this, tr("Save Widget File"),
QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
tr("QGroundControl Widget (*%1)").arg(widgetFileExtension), tr("QGroundControl Widget (*%1)").arg(widgetFileExtension),
0,0, "qgw");
&defaultSuffix);
//-- Note that if the user enters foo.bar, this will end up foo.bar.qgw //-- Note that if the user enters foo.bar, this will end up foo.bar.qgw
if (!fileName.endsWith(widgetFileExtension)) if (!fileName.endsWith(widgetFileExtension))
{ {
...@@ -591,7 +589,7 @@ void QGCToolWidget::exportWidget() ...@@ -591,7 +589,7 @@ void QGCToolWidget::exportWidget()
void QGCToolWidget::importWidget() void QGCToolWidget::importWidget()
{ {
const QString widgetFileExtension(".qgw"); const QString widgetFileExtension(".qgw");
QString fileName = QGCFileDialog::getOpenFileName(this, tr("Specify File Name"), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), tr("QGroundControl Widget (*%1)").arg(widgetFileExtension)); QString fileName = QGCFileDialog::getOpenFileName(this, tr("Load Widget File"), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), tr("QGroundControl Widget (*%1)").arg(widgetFileExtension));
loadSettings(fileName); loadSettings(fileName);
} }
......
...@@ -433,13 +433,11 @@ void LinechartWidget::refresh() ...@@ -433,13 +433,11 @@ void LinechartWidget::refresh()
QString LinechartWidget::getLogSaveFilename() QString LinechartWidget::getLogSaveFilename()
{ {
QString defaultSuffix("log");
QString fileName = QGCFileDialog::getSaveFileName(this, QString fileName = QGCFileDialog::getSaveFileName(this,
tr("Specify log file name"), tr("Save Log File"),
QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
tr("Logfile (*.log)"), tr("Log file (*.log)"),
0,0, "log");
&defaultSuffix);
return fileName; return fileName;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment