Commit 77f442fd authored by dogmaphobic's avatar dogmaphobic

Changing the defaultSuffix argument from a pointer to a const.

Changing the order of the QGCFileDialog::getSaveFileName() function. The idea was to expand the existing QFileDialog version but as we removed the selectedFilter, we might as well make this more intuitive. The options argument is the one trully optional and should be last.
Adding an example to the documentation on how to go about figuring out what file type was returned by these functions.
parent 209d354c
......@@ -476,14 +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,
&defaultSuffix);
"mavlink");
if (!saveFilename.isEmpty()) {
QFile::copy(tempLogfile, saveFilename);
}
......
......@@ -89,14 +89,14 @@ QString QGCFileDialog::getSaveFileName(
const QString& caption,
const QString& dir,
const QString& filter,
Options options,
QString* defaultSuffix)
const QString& defaultSuffix,
Options options)
{
_validate(options);
#ifdef QT_DEBUG
if (qgcApp()->runningUnitTests()) {
return UnitTest::_getSaveFileName(parent, caption, dir, filter, options, defaultSuffix);
return UnitTest::_getSaveFileName(parent, caption, dir, filter, defaultSuffix, options);
} else
#endif
{
......@@ -105,12 +105,13 @@ QString QGCFileDialog::getSaveFileName(
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()) {
......
......@@ -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 {
......@@ -96,8 +107,8 @@ 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[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,
......@@ -108,9 +119,9 @@ public:
const QString& caption = QString(),
const QString& dir = QString(),
const QString& filter = QString(),
Options options = 0,
QString* defaultSuffix = 0);
const QString& defaultSuffix = QString(),
Options options = 0);
private slots:
/// @brief The exec slot is private becasue we only want QGCFileDialog users to use the static methods. Otherwise it will break
/// unit testing.
......
......@@ -340,8 +340,8 @@ QString UnitTest::_getSaveFileName(
const QString& caption,
const QString& dir,
const QString& filter,
QFileDialog::Options options,
QString* defaultSuffix)
const QString& defaultSuffix,
QFileDialog::Options options)
{
Q_UNUSED(parent);
Q_UNUSED(caption);
......@@ -349,8 +349,8 @@ QString UnitTest::_getSaveFileName(
Q_UNUSED(filter);
Q_UNUSED(options);
if(defaultSuffix)
Q_ASSERT(defaultSuffix->startsWith(".") == false);
if(!defaultSuffix.isEmpty())
Q_ASSERT(defaultSuffix.startsWith(".") == false);
return _fileDialogResponseSingle(getSaveFileName);
}
......@@ -143,9 +143,9 @@ private:
const QString& caption,
const QString& dir,
const QString& filter,
QFileDialog::Options options,
QString* defaultSuffix);
const QString& defaultSuffix,
QFileDialog::Options options);
static QString _fileDialogResponseSingle(enum FileDialogType type);
// This allows the private calls to the file dialog methods
......
......@@ -846,8 +846,7 @@ void MainWindow::startVideoCapture()
tr("%1 Files (*.%2);;All Files (*)")
.arg(format.toUpper())
.arg(format),
0,
&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 Parameters"), qgcApp()->savedParameterFilesLocation(), tr("Parameter File (*.txt)"), 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;
......
......@@ -115,12 +115,10 @@ void QGCDataPlot2D::loadFile(QString file)
*/
QString QGCDataPlot2D::getSavePlotFilename()
{
QString defaultSuffix("pdf");
QString fileName = QGCFileDialog::getSaveFileName(
this, "Export File Name", QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
"PDF Documents (*.pdf);;SVG Images (*.svg)",
0,
&defaultSuffix);
"pdf");
return fileName;
}
......@@ -690,12 +688,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),
"CSV file (*.csv);;Text file (*.txt)",
0,
&defaultSuffix);
"csv");
if (fileName.isEmpty())
return; //User cancelled
......
......@@ -217,8 +217,7 @@ 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, &defaultSuffix);
QString fileName = QGCFileDialog::getSaveFileName(this, tr("Save File"), "./waypoints.txt", tr("Waypoint File (*.txt)"), "txt");
WPM->saveWaypoints(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 Widget File Name"),
QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
tr("QGroundControl Widget (*%1)").arg(widgetFileExtension),
0,
&defaultSuffix);
"qgw");
//-- Note that if the user enters foo.bar, this will end up foo.bar.qgw
if (!fileName.endsWith(widgetFileExtension))
{
......
......@@ -433,13 +433,11 @@ void LinechartWidget::refresh()
QString LinechartWidget::getLogSaveFilename()
{
QString defaultSuffix("log");
QString fileName = QGCFileDialog::getSaveFileName(this,
tr("Specify Log File Name"),
QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
tr("Log file (*.log)"),
0,
&defaultSuffix);
"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