Commit fcf4fda2 authored by dogmaphobic's avatar dogmaphobic

WIP issue #1173. Adding default suffix (extension). While at it, added...

WIP issue #1173. Adding default suffix (extension). While at it, added selected filter support and removed unit test assert about its use.
parent 28d17cbe
......@@ -476,10 +476,13 @@ 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)"));
tr("Flight Data Log (*.mavlink)"),
0,0,
&defaultSuffix);
if (!saveFilename.isEmpty()) {
QFile::copy(tempLogfile, saveFilename);
}
......
......@@ -88,7 +88,8 @@ QString QGCFileDialog::getSaveFileName(QWidget* parent,
const QString& dir,
const QString& filter,
QString* selectedFilter,
Options options)
Options options,
QString* defaultSuffix)
{
_validate(selectedFilter, options);
......@@ -98,7 +99,17 @@ QString QGCFileDialog::getSaveFileName(QWidget* parent,
} else
#endif
{
return QFileDialog::getSaveFileName(parent, caption, dir, filter, selectedFilter, options);
QFileDialog dlg(parent, caption, dir, filter);
if (selectedFilter)
dlg.selectNameFilter(*selectedFilter);
if (options)
dlg.setOptions(options);
if (defaultSuffix)
dlg.setDefaultSuffix(*defaultSuffix);
if (dlg.exec())
if (dlg.selectedFiles().count())
return dlg.selectedFiles().first();
return QString("");
}
}
......
......@@ -55,12 +55,16 @@ public:
QString* selectedFilter = 0,
Options options = 0);
/// @brief getSaveFileName with an extra (optional) argument to define the extension (suffix) to
/// be added if none is given by the user. If set, don't add the preceding period (i.e.
/// use "mavlink" instead of ".mavlink")
static QString getSaveFileName(QWidget* parent = 0,
const QString& caption = QString(),
const QString& dir = QString(),
const QString& filter = QString(),
QString* selectedFilter = 0,
Options options = 0);
Options options = 0,
QString* defaultSuffix = 0);
private slots:
/// @brief The exec slot is private becasue when only want QGCFileDialog users to use the static methods. Otherwise it will break
......
......@@ -345,16 +345,15 @@ QString UnitTest::_getSaveFileName(QWidget* parent,
const QString& dir,
const QString& filter,
QString* selectedFilter,
QFileDialog::Options options)
QFileDialog::Options options,
QString* defaultSuffix)
{
Q_UNUSED(parent);
Q_UNUSED(caption);
Q_UNUSED(dir);
Q_UNUSED(filter);
Q_UNUSED(options);
// Support for selectedFilter is not yet implemented
Q_ASSERT(selectedFilter == NULL);
Q_UNUSED(defaultSuffix);
return _fileDialogResponseSingle(getSaveFileName);
}
......@@ -142,7 +142,8 @@ private:
const QString& dir,
const QString& filter,
QString* selectedFilter,
QFileDialog::Options options);
QFileDialog::Options options,
QString* defaultSuffix);
static QString _fileDialogResponseSingle(enum FileDialogType type);
......
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