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
void QGCApplication::saveTempFlightDataLogOnMainThread(QString tempLogfile)
{
QString defaultSuffix("mavlink");
QString saveFilename = QGCFileDialog::getSaveFileName(MainWindow::instance(),
tr("Select file to save Flight Data Log"),
qgcApp()->mavlinkLogFilesLocation(),
tr("Flight Data Log (*.mavlink)"),
0,0,
&defaultSuffix);
QString saveFilename = QGCFileDialog::getSaveFileName(
MainWindow::instance(),
tr("Save Flight Data Log"),
qgcApp()->mavlinkLogFilesLocation(),
tr("Flight Data Log (*.mavlink)"),
"mavlink");
if (!saveFilename.isEmpty()) {
QFile::copy(tempLogfile, saveFilename);
}
......
......@@ -28,12 +28,13 @@
#include "UnitTest.h"
#endif
QString QGCFileDialog::getExistingDirectory(QWidget* parent,
const QString& caption,
const QString& dir,
Options options)
QString QGCFileDialog::getExistingDirectory(
QWidget* parent,
const QString& caption,
const QString& dir,
Options options)
{
_validate(NULL, options);
_validate(options);
#ifdef QT_DEBUG
if (qgcApp()->runningUnitTests()) {
......@@ -45,57 +46,57 @@ QString QGCFileDialog::getExistingDirectory(QWidget* parent,
}
}
QString QGCFileDialog::getOpenFileName(QWidget* parent,
const QString& caption,
const QString& dir,
const QString& filter,
QString* selectedFilter,
Options options)
QString QGCFileDialog::getOpenFileName(
QWidget* parent,
const QString& caption,
const QString& dir,
const QString& filter,
Options options)
{
_validate(selectedFilter, options);
_validate(options);
#ifdef QT_DEBUG
if (qgcApp()->runningUnitTests()) {
return UnitTest::_getOpenFileName(parent, caption, dir, filter, selectedFilter, options);
return UnitTest::_getOpenFileName(parent, caption, dir, filter, options);
} else
#endif
{
return QFileDialog::getOpenFileName(parent, caption, dir, filter, selectedFilter, options);
return QFileDialog::getOpenFileName(parent, caption, dir, filter, NULL, options);
}
}
QStringList QGCFileDialog::getOpenFileNames(QWidget* parent,
const QString& caption,
const QString& dir,
const QString& filter,
QString* selectedFilter,
Options options)
QStringList QGCFileDialog::getOpenFileNames(
QWidget* parent,
const QString& caption,
const QString& dir,
const QString& filter,
Options options)
{
_validate(selectedFilter, options);
_validate(options);
#ifdef QT_DEBUG
if (qgcApp()->runningUnitTests()) {
return UnitTest::_getOpenFileNames(parent, caption, dir, filter, selectedFilter, options);
return UnitTest::_getOpenFileNames(parent, caption, dir, filter, options);
} else
#endif
{
return QFileDialog::getOpenFileNames(parent, caption, dir, filter, selectedFilter, options);
return QFileDialog::getOpenFileNames(parent, caption, dir, filter, NULL, options);
}
}
QString QGCFileDialog::getSaveFileName(QWidget* parent,
const QString& caption,
const QString& dir,
const QString& filter,
QString* selectedFilter,
Options options,
QString* defaultSuffix)
QString QGCFileDialog::getSaveFileName(
QWidget* parent,
const QString& caption,
const QString& dir,
const QString& filter,
const QString& defaultSuffix,
Options options)
{
_validate(selectedFilter, options);
_validate(options);
#ifdef QT_DEBUG
if (qgcApp()->runningUnitTests()) {
return UnitTest::_getSaveFileName(parent, caption, dir, filter, selectedFilter, options, defaultSuffix);
return UnitTest::_getSaveFileName(parent, caption, dir, filter, defaultSuffix, options);
} else
#endif
{
......@@ -104,12 +105,13 @@ QString QGCFileDialog::getSaveFileName(QWidget* parent,
if (options) {
dlg.setOptions(options);
}
if (defaultSuffix) {
if (!defaultSuffix.isEmpty()) {
QString suffixCopy(defaultSuffix);
//-- Make sure dot is not present
if (defaultSuffix->startsWith(".")) {
defaultSuffix->remove(0,1);
if (suffixCopy.startsWith(".")) {
suffixCopy.remove(0,1);
}
dlg.setDefaultSuffix(*defaultSuffix);
dlg.setDefaultSuffix(suffixCopy);
}
if (dlg.exec()) {
if (dlg.selectedFiles().count()) {
......@@ -121,17 +123,13 @@ QString QGCFileDialog::getSaveFileName(QWidget* parent,
}
/// @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.
Q_ASSERT(qgcApp());
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
options |= DontUseNativeDialog;
......
......@@ -31,10 +31,21 @@
/// @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
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
use to catch these dialogs for unit testing.
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
these can intermittently hang. So instead here we use the native dialogs. It also allows
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 {
......@@ -50,10 +61,11 @@ public:
@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>
*/
static QString getExistingDirectory(QWidget* parent = 0,
const QString& caption = QString(),
const QString& dir = QString(),
Options options = ShowDirsOnly);
static QString getExistingDirectory(
QWidget* parent = 0,
const QString& caption = QString(),
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.
/*!
......@@ -61,17 +73,16 @@ public:
@param[in] caption The caption displayed at the top of the dialog.
@param[in] dir The initial directory shown to the user.
@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.
@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>
*/
static QString getOpenFileName(QWidget* parent = 0,
const QString& caption = QString(),
const QString& dir = QString(),
const QString& filter = QString(),
QString* selectedFilter = 0,
Options options = 0);
static QString getOpenFileName(
QWidget* parent = 0,
const QString& caption = QString(),
const QString& dir = QString(),
const QString& filter = QString(),
Options options = 0);
//! 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:
@param[in] caption The caption displayed at the top of the dialog.
@param[in] dir The initial directory shown to the user.
@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.
@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>
*/
static QStringList getOpenFileNames(QWidget* parent = 0,
const QString& caption = QString(),
const QString& dir = QString(),
const QString& filter = QString(),
QString* selectedFilter = 0,
Options options = 0);
static QStringList getOpenFileNames(
QWidget* parent = 0,
const QString& caption = QString(),
const QString& dir = QString(),
const QString& filter = QString(),
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.
/*!
......@@ -97,29 +107,28 @@ public:
@param[in] caption The caption displayed at the top of the dialog.
@param[in] dir The initial directory shown to the user.
@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] 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.
@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,
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,
const QString& caption = QString(),
const QString& dir = QString(),
const QString& filter = QString(),
QString* selectedFilter = 0,
Options options = 0,
QString* defaultSuffix = 0);
static QString getSaveFileName(
QWidget* parent = 0,
const QString& caption = QString(),
const QString& dir = QString(),
const QString& filter = QString(),
const QString& defaultSuffix = QString(),
Options options = 0);
private slots:
/// @brief The exec slot is private becasue when only want QGCFileDialog users to use the static methods. Otherwise it will break
/// unit testing.
/// @brief The exec slot is private because we only want QGCFileDialog users to use the static methods. Otherwise it will break
/// unit testing.
int exec(void) { return QGCFileDialog::exec(); }
private:
static void _validate(QString* selectedFilter, Options& options);
static void _validate(Options& options);
};
......
......@@ -273,10 +273,11 @@ QString UnitTest::_fileDialogResponseSingle(enum FileDialogType type)
return retFile;
}
QString UnitTest::_getExistingDirectory(QWidget* parent,
const QString& caption,
const QString& dir,
QFileDialog::Options options)
QString UnitTest::_getExistingDirectory(
QWidget* parent,
const QString& caption,
const QString& dir,
QFileDialog::Options options)
{
Q_UNUSED(parent);
Q_UNUSED(caption);
......@@ -286,12 +287,12 @@ QString UnitTest::_getExistingDirectory(QWidget* parent,
return _fileDialogResponseSingle(getExistingDirectory);
}
QString UnitTest::_getOpenFileName(QWidget* parent,
const QString& caption,
const QString& dir,
const QString& filter,
QString* selectedFilter,
QFileDialog::Options options)
QString UnitTest::_getOpenFileName(
QWidget* parent,
const QString& caption,
const QString& dir,
const QString& filter,
QFileDialog::Options options)
{
Q_UNUSED(parent);
Q_UNUSED(caption);
......@@ -299,18 +300,15 @@ QString UnitTest::_getOpenFileName(QWidget* parent,
Q_UNUSED(filter);
Q_UNUSED(options);
// Support for selectedFilter is not yet implemented
Q_ASSERT(selectedFilter == NULL);
return _fileDialogResponseSingle(getOpenFileName);
}
QStringList UnitTest::_getOpenFileNames(QWidget* parent,
const QString& caption,
const QString& dir,
const QString& filter,
QString* selectedFilter,
QFileDialog::Options options)
QStringList UnitTest::_getOpenFileNames(
QWidget* parent,
const QString& caption,
const QString& dir,
const QString& filter,
QFileDialog::Options options)
{
Q_UNUSED(parent);
Q_UNUSED(caption);
......@@ -318,9 +316,6 @@ QStringList UnitTest::_getOpenFileNames(QWidget* parent,
Q_UNUSED(filter);
Q_UNUSED(options);
// Support for selectedFilter is not yet implemented
Q_ASSERT(selectedFilter == NULL);
QStringList retFiles;
if (!_fileDialogResponseSet || _fileDialogExpectedType != getOpenFileNames) {
......@@ -340,13 +335,13 @@ QStringList UnitTest::_getOpenFileNames(QWidget* parent,
return retFiles;
}
QString UnitTest::_getSaveFileName(QWidget* parent,
const QString& caption,
const QString& dir,
const QString& filter,
QString* selectedFilter,
QFileDialog::Options options,
QString* defaultSuffix)
QString UnitTest::_getSaveFileName(
QWidget* parent,
const QString& caption,
const QString& dir,
const QString& filter,
const QString& defaultSuffix,
QFileDialog::Options options)
{
Q_UNUSED(parent);
Q_UNUSED(caption);
......@@ -354,11 +349,9 @@ QString UnitTest::_getSaveFileName(QWidget* parent,
Q_UNUSED(filter);
Q_UNUSED(options);
if(defaultSuffix)
Q_ASSERT(defaultSuffix->startsWith(".") == false);
// Support for selectedFilter is not yet implemented
Q_ASSERT(selectedFilter == NULL);
if(!defaultSuffix.isEmpty()) {
Q_ASSERT(defaultSuffix.startsWith(".") == false);
}
return _fileDialogResponseSingle(getSaveFileName);
}
......@@ -118,33 +118,34 @@ private:
// When the app is running in unit test mode the QGCFileDialog methods are re-routed here.
static QString _getExistingDirectory(QWidget* parent,
const QString& caption,
const QString& dir,
QFileDialog::Options options);
static QString _getOpenFileName(QWidget* parent,
const QString& caption,
const QString& dir,
const QString& filter,
QString* selectedFilter,
QFileDialog::Options options);
static QStringList _getOpenFileNames(QWidget* parent,
const QString& caption,
const QString& dir,
const QString& filter,
QString* selectedFilter,
QFileDialog::Options options);
static QString _getSaveFileName(QWidget* parent,
const QString& caption,
const QString& dir,
const QString& filter,
QString* selectedFilter,
QFileDialog::Options options,
QString* defaultSuffix);
static QString _getExistingDirectory(
QWidget* parent,
const QString& caption,
const QString& dir,
QFileDialog::Options options);
static QString _getOpenFileName(
QWidget* parent,
const QString& caption,
const QString& dir,
const QString& filter,
QFileDialog::Options options);
static QStringList _getOpenFileNames(
QWidget* parent,
const QString& caption,
const QString& dir,
const QString& filter,
QFileDialog::Options options);
static QString _getSaveFileName(
QWidget* parent,
const QString& caption,
const QString& dir,
const QString& filter,
const QString& defaultSuffix,
QFileDialog::Options options);
static QString _fileDialogResponseSingle(enum FileDialogType type);
// This allows the private calls to the file dialog methods
......
......@@ -836,16 +836,17 @@ void MainWindow::configureWindowName()
void MainWindow::startVideoCapture()
{
// TODO: What is this? What kind of "Video" is saved to bmp?
QString format("bmp");
QString initialPath = QDir::currentPath() + tr("/untitled.") + format;
QString screenFileName = QGCFileDialog::getSaveFileName(this, tr("Save As"),
initialPath,
tr("%1 Files (*.%2);;All Files (*)")
.arg(format.toUpper())
.arg(format),
0,0,
&format);
QString screenFileName = QGCFileDialog::getSaveFileName(
this, tr("Save Video Capture"),
initialPath,
tr("%1 Files (*.%2);;All Files (*)")
.arg(format.toUpper())
.arg(format),
format);
delete videoTimer;
videoTimer = new QTimer(this);
}
......
......@@ -105,8 +105,7 @@ void QGCBaseParamWidget::saveParametersToFile()
{
if (!mav)
return;
QString defaultSuffix("txt");
QString fileName = QGCFileDialog::getSaveFileName(this, tr("Save File"), qgcApp()->savedParameterFilesLocation(), tr("Parameter File (*.txt)"), 0, 0, &defaultSuffix);
QString fileName = QGCFileDialog::getSaveFileName(this, tr("Save Parameters"), qgcApp()->savedParameterFilesLocation(), tr("Parameter File (*.txt)"), "txt");
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
return;
......@@ -123,7 +122,7 @@ void QGCBaseParamWidget::loadParametersFromFile()
if (!mav)
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);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
......
......@@ -100,13 +100,17 @@ void QGCDataPlot2D::loadFile()
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;
if (QFileInfo(fileName).isReadable()) {
if (fileName.contains(".raw") || fileName.contains(".imu")) {
QFileInfo fi(fileName);
if (fi.isReadable()) {
if (fi.suffix() == QString("raw") || fi.suffix() == QString("imu")) {
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);
}
// TODO Else, tell the user it doesn't know what to do with the file...
}
}
......@@ -115,12 +119,10 @@ void QGCDataPlot2D::loadFile(QString file)
*/
QString QGCDataPlot2D::getSavePlotFilename()
{
QString defaultSuffix("pdf");
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)",
0,0,
&defaultSuffix);
"pdf");
return fileName;
}
......@@ -133,11 +135,13 @@ void QGCDataPlot2D::savePlot()
if (fileName.isEmpty())
return;
// TODO This will change once we add "strict" file types in file selection dialogs
while(!(fileName.endsWith(".svg") || fileName.endsWith(".pdf"))) {
QMessageBox::StandardButton button = QGCMessageBox::critical(tr("Unsuitable file extension for PDF or SVG"),
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::Cancel,
QMessageBox::Ok);
QMessageBox::StandardButton button = QGCMessageBox::warning(
tr("Unsuitable file extension for Plot document type."),
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::Cancel,
QMessageBox::Ok);
// Abort if cancelled
if (button == QMessageBox::Cancel) {
return;
......@@ -690,12 +694,10 @@ bool QGCDataPlot2D::linearRegression(double *x, double *y, int n, double *a, dou
void QGCDataPlot2D::saveCsvLog()
{
QString defaultSuffix("csv");
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)",
0,0,
&defaultSuffix);
"csv");
if (fileName.isEmpty())
return; //User cancelled
......
......@@ -217,14 +217,15 @@ void WaypointList::setUAS(UASInterface* uas)
void WaypointList::saveWaypoints()
{
QString defaultSuffix("txt");
QString fileName = QGCFileDialog::getSaveFileName(this, tr("Save File"), "./waypoints.txt", tr("Waypoint File (*.txt)"), 0, 0, &defaultSuffix);
// TODO Need better default directory
// 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);
}
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);
}
......
......@@ -571,14 +571,12 @@ void QGCToolWidget::widgetRemoved()
void QGCToolWidget::exportWidget()
{
QString defaultSuffix("qgw");
const QString widgetFileExtension(".qgw");
QString fileName = QGCFileDialog::getSaveFileName(
this, tr("Specify File Name"),
this, tr("Save Widget File"),
QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
tr("QGroundControl Widget (*%1)").arg(widgetFileExtension),
0,0,
&defaultSuffix);
"qgw");
//-- Note that if the user enters foo.bar, this will end up foo.bar.qgw
if (!fileName.endsWith(widgetFileExtension))
{
......@@ -591,7 +589,7 @@ void QGCToolWidget::exportWidget()
void QGCToolWidget::importWidget()
{
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);
}
......
......@@ -433,13 +433,11 @@ void LinechartWidget::refresh()
QString LinechartWidget::getLogSaveFilename()
{
QString defaultSuffix("log");
QString fileName = QGCFileDialog::getSaveFileName(this,
tr("Specify log file name"),
tr("Save Log File"),
QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
tr("Logfile (*.log)"),
0,0,
&defaultSuffix);
tr("Log file (*.log)"),
"log");
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