diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index c5a35921bde28c674c0fff65b3ef20f484c8bf34..e9f2f2559da4e999ee1c63683f1fd4e4fca52c5b 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -476,7 +476,7 @@ void QGCApplication::criticalMessageBoxOnMainThread(const QString& title, const void QGCApplication::saveTempFlightDataLogOnMainThread(QString tempLogfile) { - QString defaultSuffix = "mavlink"; + QString defaultSuffix("mavlink"); QString saveFilename = QGCFileDialog::getSaveFileName(MainWindow::instance(), tr("Select file to save Flight Data Log"), qgcApp()->mavlinkLogFilesLocation(), diff --git a/src/QGCFileDialog.cc b/src/QGCFileDialog.cc index 8f3edf316e4f9a40bc0cd8333b69bdee5dcd8d38..28222d089cab363ff9692ea6df274a2a9ea2d281 100644 --- a/src/QGCFileDialog.cc +++ b/src/QGCFileDialog.cc @@ -92,7 +92,7 @@ QString QGCFileDialog::getSaveFileName(QWidget* parent, QString* defaultSuffix) { _validate(selectedFilter, options); - + #ifdef QT_DEBUG if (qgcApp()->runningUnitTests()) { return UnitTest::_getSaveFileName(parent, caption, dir, filter, selectedFilter, options, defaultSuffix); @@ -105,8 +105,12 @@ QString QGCFileDialog::getSaveFileName(QWidget* parent, dlg.selectNameFilter(*selectedFilter); if (options) dlg.setOptions(options); - if (defaultSuffix) + if (defaultSuffix) { + //-- Make sure dot is not present + if (defaultSuffix->startsWith(".")) + defaultSuffix->remove(0,1); dlg.setDefaultSuffix(*defaultSuffix); + } if (dlg.exec()) if (dlg.selectedFiles().count()) return dlg.selectedFiles().first(); diff --git a/src/qgcunittest/UnitTest.cc b/src/qgcunittest/UnitTest.cc index d5e655b357dd82d5e4bda10892c443350ed63097..eaa164675935b082db1f2b7aeae04b9428dd4f79 100644 --- a/src/qgcunittest/UnitTest.cc +++ b/src/qgcunittest/UnitTest.cc @@ -353,10 +353,11 @@ QString UnitTest::_getSaveFileName(QWidget* parent, Q_UNUSED(dir); Q_UNUSED(filter); Q_UNUSED(options); - Q_UNUSED(defaultSuffix); - // Support for selectedFilter (elsewhere) is not yet implemented. Until it is added for all - // file dialogs, this stays here. + if(defaultSuffix) + Q_ASSERT(defaultSuffix->startsWith(".") == false); + + // Support for selectedFilter is not yet implemented Q_ASSERT(selectedFilter == NULL); return _fileDialogResponseSingle(getSaveFileName); diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index 4416ff2a6b8c447c7660ca790178af5a4fa8d7bc..0e5f5bc4bec00d317cd687234692a9caa7940fae 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -996,14 +996,16 @@ void MainWindow::configureWindowName() void MainWindow::startVideoCapture() { - QString format = "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)); + .arg(format), + 0,0, + &format); delete videoTimer; videoTimer = new QTimer(this); } diff --git a/src/ui/QGCBaseParamWidget.cc b/src/ui/QGCBaseParamWidget.cc index b6f86c90d2d7dbcfc6e61ba081585df9ddabf605..2d8c96997afcf70da528b24b84fae9aedd59d365 100644 --- a/src/ui/QGCBaseParamWidget.cc +++ b/src/ui/QGCBaseParamWidget.cc @@ -105,7 +105,8 @@ void QGCBaseParamWidget::saveParametersToFile() { if (!mav) return; - QString fileName = QGCFileDialog::getSaveFileName(this, tr("Save File"), qgcApp()->savedParameterFilesLocation(), tr("Parameter File (*.txt)")); + QString defaultSuffix("txt"); + QString fileName = QGCFileDialog::getSaveFileName(this, tr("Save File"), qgcApp()->savedParameterFilesLocation(), tr("Parameter File (*.txt)"), 0, 0, &defaultSuffix); QFile file(fileName); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { return; diff --git a/src/ui/QGCDataPlot2D.cc b/src/ui/QGCDataPlot2D.cc index 44f84a7b5d7240b09ada36378934c04e9009cb83..952fa0e0d7c99ec50e217ffd79ee992d2b7823d1 100644 --- a/src/ui/QGCDataPlot2D.cc +++ b/src/ui/QGCDataPlot2D.cc @@ -111,22 +111,28 @@ void QGCDataPlot2D::loadFile(QString file) } /** - * This function brings up a file name dialog and exports to either PDF or SVG, depending on the filename + * This function brings up a file name dialog and asks the user to enter a file to save to + */ +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,0, + &defaultSuffix); + return fileName; +} + +/** + * This function aks the user for a filename and exports to either PDF or SVG, depending on the filename */ void QGCDataPlot2D::savePlot() { - QString fileName = "plot.svg"; - fileName = QGCFileDialog::getSaveFileName( - this, "Export File Name", QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), - "PDF Documents (*.pdf);;SVG Images (*.svg)"); + QString fileName = getSavePlotFilename(); if (fileName.isEmpty()) return; - if (!fileName.contains(".")) { - // .pdf is default extension - fileName.append(".pdf"); - } - 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."), @@ -136,9 +142,8 @@ void QGCDataPlot2D::savePlot() if (button == QMessageBox::Cancel) { return; } - fileName = QGCFileDialog::getSaveFileName( - this, "Export File Name", QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), - "PDF Documents (*.pdf);;SVG Images (*.svg)"); + + fileName = getSavePlotFilename(); if (fileName.isEmpty()) return; //Abort if cancelled } @@ -685,21 +690,19 @@ bool QGCDataPlot2D::linearRegression(double *x, double *y, int n, double *a, dou void QGCDataPlot2D::saveCsvLog() { - QString fileName = "export.csv"; - fileName = QGCFileDialog::getSaveFileName( - this, "Export CSV File Name", QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), - "CSV file (*.csv);;Text file (*.txt)"); + QString defaultSuffix("csv"); + QString fileName = QGCFileDialog::getSaveFileName( + this, "Export CSV File Name", QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), + "CSV file (*.csv);;Text file (*.txt)", + 0,0, + &defaultSuffix); + if (fileName.isEmpty()) return; //User cancelled - if (!fileName.contains(".")) { - // .csv is default extension - fileName.append(".csv"); - } - bool success = logFile->copy(fileName); - qDebug() << "Saved CSV log. Success: " << success; + qDebug() << "Saved CSV log (" << fileName << "). Success: " << success; //qDebug() << "READE TO SAVE CSV LOG TO " << fileName; } diff --git a/src/ui/QGCDataPlot2D.h b/src/ui/QGCDataPlot2D.h index 917390121b5f04b1ae624f322c9857d250a6d02a..2ff6cacab03072209f2478ec60fe5f9b247d4d6a 100644 --- a/src/ui/QGCDataPlot2D.h +++ b/src/ui/QGCDataPlot2D.h @@ -63,6 +63,7 @@ protected: } void changeEvent(QEvent *e); + QString getSavePlotFilename(); IncrementalPlot* plot; LogCompressor* compressor; QFile* logFile; diff --git a/src/ui/WaypointList.cc b/src/ui/WaypointList.cc index 7d634e41449cf4c7f760c276dc183b806e12d31b..b019cd35942afdb4ad3727a7c3a5837ee201b214 100644 --- a/src/ui/WaypointList.cc +++ b/src/ui/WaypointList.cc @@ -217,10 +217,9 @@ void WaypointList::setUAS(UASInterface* uas) void WaypointList::saveWaypoints() { - - QString fileName = QGCFileDialog::getSaveFileName(this, tr("Save File"), "./waypoints.txt", tr("Waypoint File (*.txt)")); + QString defaultSuffix("txt"); + QString fileName = QGCFileDialog::getSaveFileName(this, tr("Save File"), "./waypoints.txt", tr("Waypoint File (*.txt)"), 0, 0, &defaultSuffix); WPM->saveWaypoints(fileName); - } void WaypointList::loadWaypoints() diff --git a/src/ui/designer/QGCToolWidget.cc b/src/ui/designer/QGCToolWidget.cc index 72db2d02bef438ee627083dede5f5a8ac4453af7..d56262c9a4a1d6437faeb22c9522254d378e90bc 100644 --- a/src/ui/designer/QGCToolWidget.cc +++ b/src/ui/designer/QGCToolWidget.cc @@ -571,8 +571,15 @@ void QGCToolWidget::widgetRemoved() void QGCToolWidget::exportWidget() { + QString defaultSuffix("qgw"); const QString widgetFileExtension(".qgw"); - QString fileName = QGCFileDialog::getSaveFileName(this, tr("Specify File Name"), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), tr("QGroundControl Widget (*%1);;").arg(widgetFileExtension)); + QString fileName = QGCFileDialog::getSaveFileName( + this, tr("Specify File Name"), + QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), + tr("QGroundControl Widget (*%1);;").arg(widgetFileExtension), + 0,0, + &defaultSuffix); + //-- Note that if the user enters foo.bar, this will end up foo.bar.qgw if (!fileName.endsWith(widgetFileExtension)) { fileName = fileName.append(widgetFileExtension); diff --git a/src/ui/linechart/LinechartWidget.cc b/src/ui/linechart/LinechartWidget.cc index 6cd99337ecfb3435c5fa7f7b5c3f257888448538..c6c5a2e2371d84457028bbf827e7b4336e55311b 100644 --- a/src/ui/linechart/LinechartWidget.cc +++ b/src/ui/linechart/LinechartWidget.cc @@ -431,11 +431,21 @@ void LinechartWidget::refresh() setUpdatesEnabled(true); } +QString LinechartWidget::getLogSaveFilename() +{ + QString defaultSuffix("log"); + QString fileName = QGCFileDialog::getSaveFileName(this, + tr("Specify log file name"), + QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), + tr("Logfile (*.log);;"), + 0,0, + &defaultSuffix); + return fileName; +} void LinechartWidget::startLogging() { // Store reference to file - // Append correct file ending if needed bool abort = false; // Check if any curve is enabled @@ -445,9 +455,9 @@ void LinechartWidget::startLogging() } // Let user select the log file name - //QDate date(QDate::currentDate()); + // QDate date(QDate::currentDate()); // QString("./pixhawk-log-" + date.toString("yyyy-MM-dd") + "-" + QString::number(logindex) + ".log") - QString fileName = QGCFileDialog::getSaveFileName(this, tr("Specify log file name"), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), tr("Logfile (*.log);;")); + QString fileName = getLogSaveFilename(); while (!(fileName.endsWith(".log")) && !abort && fileName != "") { QMessageBox::StandardButton button = QGCMessageBox::critical(tr("Unsuitable file extension for logfile"), @@ -458,10 +468,10 @@ void LinechartWidget::startLogging() abort = true; break; } - fileName = QGCFileDialog::getSaveFileName(this, tr("Specify log file name"), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), tr("Logfile (*.log);;")); + fileName = getLogSaveFilename(); } - qDebug() << "SAVE FILE" << fileName; + qDebug() << "SAVE FILE " << fileName; // Check if the user did not abort the file save dialog if (!abort && fileName != "") { diff --git a/src/ui/linechart/LinechartWidget.h b/src/ui/linechart/LinechartWidget.h index 4c9fb20b625418425ca2c58359a75d868fddf20c..081b31fe75478719d931de01580ecf91cd83ffba 100644 --- a/src/ui/linechart/LinechartWidget.h +++ b/src/ui/linechart/LinechartWidget.h @@ -123,6 +123,7 @@ protected: QToolButton* createButton(QWidget* parent); void createCurveItem(QString curve); void createLayout(); + QString getLogSaveFilename(); /** @brief Get the name for a curve key */ QString getCurveName(const QString& key, bool shortEnabled);