Commit 32495fc4 authored by dogmaphobic's avatar dogmaphobic

Added default suffixes to these functions:

QGCApplication::saveTempFlightDataLogOnMainThread()
MainWindow::startVideoCapture()
QGCBaseParamWidget::saveParametersToFile()
QGCDataPlot2D::savePlot()
QGCDataPlot2D::saveCsvLog()
WaypointList::saveWaypoints()
QGCToolWidget::exportWidget()
LinechartWidget::startLogging()

Making sure defaultSuffix doesn’t start with a dot (i.e. “.bar”)

QGCFileDialog::getSaveFileName()

Assert if defaultSuffix contains a dot (i.e. “.bar”)

UnitTest::_getSaveFileName()
parent 20e6c748
...@@ -476,7 +476,7 @@ void QGCApplication::criticalMessageBoxOnMainThread(const QString& title, const ...@@ -476,7 +476,7 @@ void QGCApplication::criticalMessageBoxOnMainThread(const QString& title, const
void QGCApplication::saveTempFlightDataLogOnMainThread(QString tempLogfile) void QGCApplication::saveTempFlightDataLogOnMainThread(QString tempLogfile)
{ {
QString defaultSuffix = "mavlink"; QString defaultSuffix("mavlink");
QString saveFilename = QGCFileDialog::getSaveFileName(MainWindow::instance(), QString saveFilename = QGCFileDialog::getSaveFileName(MainWindow::instance(),
tr("Select file to save Flight Data Log"), tr("Select file to save Flight Data Log"),
qgcApp()->mavlinkLogFilesLocation(), qgcApp()->mavlinkLogFilesLocation(),
......
...@@ -105,8 +105,12 @@ QString QGCFileDialog::getSaveFileName(QWidget* parent, ...@@ -105,8 +105,12 @@ QString QGCFileDialog::getSaveFileName(QWidget* parent,
dlg.selectNameFilter(*selectedFilter); dlg.selectNameFilter(*selectedFilter);
if (options) if (options)
dlg.setOptions(options); dlg.setOptions(options);
if (defaultSuffix) if (defaultSuffix) {
//-- Make sure dot is not present
if (defaultSuffix->startsWith("."))
defaultSuffix->remove(0,1);
dlg.setDefaultSuffix(*defaultSuffix); dlg.setDefaultSuffix(*defaultSuffix);
}
if (dlg.exec()) if (dlg.exec())
if (dlg.selectedFiles().count()) if (dlg.selectedFiles().count())
return dlg.selectedFiles().first(); return dlg.selectedFiles().first();
......
...@@ -353,10 +353,11 @@ QString UnitTest::_getSaveFileName(QWidget* parent, ...@@ -353,10 +353,11 @@ QString UnitTest::_getSaveFileName(QWidget* parent,
Q_UNUSED(dir); Q_UNUSED(dir);
Q_UNUSED(filter); Q_UNUSED(filter);
Q_UNUSED(options); Q_UNUSED(options);
Q_UNUSED(defaultSuffix);
// Support for selectedFilter (elsewhere) is not yet implemented. Until it is added for all if(defaultSuffix)
// file dialogs, this stays here. Q_ASSERT(defaultSuffix->startsWith(".") == false);
// Support for selectedFilter is not yet implemented
Q_ASSERT(selectedFilter == NULL); Q_ASSERT(selectedFilter == NULL);
return _fileDialogResponseSingle(getSaveFileName); return _fileDialogResponseSingle(getSaveFileName);
......
...@@ -996,14 +996,16 @@ void MainWindow::configureWindowName() ...@@ -996,14 +996,16 @@ void MainWindow::configureWindowName()
void MainWindow::startVideoCapture() void MainWindow::startVideoCapture()
{ {
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(this, tr("Save As"),
initialPath, initialPath,
tr("%1 Files (*.%2);;All Files (*)") tr("%1 Files (*.%2);;All Files (*)")
.arg(format.toUpper()) .arg(format.toUpper())
.arg(format)); .arg(format),
0,0,
&format);
delete videoTimer; delete videoTimer;
videoTimer = new QTimer(this); videoTimer = new QTimer(this);
} }
......
...@@ -105,7 +105,8 @@ void QGCBaseParamWidget::saveParametersToFile() ...@@ -105,7 +105,8 @@ void QGCBaseParamWidget::saveParametersToFile()
{ {
if (!mav) if (!mav)
return; 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); QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
return; return;
......
...@@ -111,22 +111,28 @@ void QGCDataPlot2D::loadFile(QString file) ...@@ -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
*/ */
void QGCDataPlot2D::savePlot() QString QGCDataPlot2D::getSavePlotFilename()
{ {
QString fileName = "plot.svg"; QString defaultSuffix("pdf");
fileName = QGCFileDialog::getSaveFileName( QString fileName = QGCFileDialog::getSaveFileName(
this, "Export File Name", QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), this, "Export File Name", QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
"PDF Documents (*.pdf);;SVG Images (*.svg)"); "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 = getSavePlotFilename();
if (fileName.isEmpty()) if (fileName.isEmpty())
return; return;
if (!fileName.contains(".")) {
// .pdf is default extension
fileName.append(".pdf");
}
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::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."), 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() ...@@ -136,9 +142,8 @@ void QGCDataPlot2D::savePlot()
if (button == QMessageBox::Cancel) { if (button == QMessageBox::Cancel) {
return; return;
} }
fileName = QGCFileDialog::getSaveFileName(
this, "Export File Name", QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), fileName = getSavePlotFilename();
"PDF Documents (*.pdf);;SVG Images (*.svg)");
if (fileName.isEmpty()) if (fileName.isEmpty())
return; //Abort if cancelled return; //Abort if cancelled
} }
...@@ -685,21 +690,19 @@ bool QGCDataPlot2D::linearRegression(double *x, double *y, int n, double *a, dou ...@@ -685,21 +690,19 @@ bool QGCDataPlot2D::linearRegression(double *x, double *y, int n, double *a, dou
void QGCDataPlot2D::saveCsvLog() void QGCDataPlot2D::saveCsvLog()
{ {
QString fileName = "export.csv"; QString defaultSuffix("csv");
fileName = QGCFileDialog::getSaveFileName( QString fileName = QGCFileDialog::getSaveFileName(
this, "Export CSV File Name", QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), this, "Export CSV File Name", QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
"CSV file (*.csv);;Text file (*.txt)"); "CSV file (*.csv);;Text file (*.txt)",
0,0,
&defaultSuffix);
if (fileName.isEmpty()) if (fileName.isEmpty())
return; //User cancelled return; //User cancelled
if (!fileName.contains(".")) {
// .csv is default extension
fileName.append(".csv");
}
bool success = logFile->copy(fileName); 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; //qDebug() << "READE TO SAVE CSV LOG TO " << fileName;
} }
......
...@@ -63,6 +63,7 @@ protected: ...@@ -63,6 +63,7 @@ protected:
} }
void changeEvent(QEvent *e); void changeEvent(QEvent *e);
QString getSavePlotFilename();
IncrementalPlot* plot; IncrementalPlot* plot;
LogCompressor* compressor; LogCompressor* compressor;
QFile* logFile; QFile* logFile;
......
...@@ -217,10 +217,9 @@ void WaypointList::setUAS(UASInterface* uas) ...@@ -217,10 +217,9 @@ void WaypointList::setUAS(UASInterface* uas)
void WaypointList::saveWaypoints() void WaypointList::saveWaypoints()
{ {
QString defaultSuffix("txt");
QString fileName = QGCFileDialog::getSaveFileName(this, tr("Save File"), "./waypoints.txt", tr("Waypoint File (*.txt)")); QString fileName = QGCFileDialog::getSaveFileName(this, tr("Save File"), "./waypoints.txt", tr("Waypoint File (*.txt)"), 0, 0, &defaultSuffix);
WPM->saveWaypoints(fileName); WPM->saveWaypoints(fileName);
} }
void WaypointList::loadWaypoints() void WaypointList::loadWaypoints()
......
...@@ -571,8 +571,15 @@ void QGCToolWidget::widgetRemoved() ...@@ -571,8 +571,15 @@ void QGCToolWidget::widgetRemoved()
void QGCToolWidget::exportWidget() void QGCToolWidget::exportWidget()
{ {
QString defaultSuffix("qgw");
const QString widgetFileExtension(".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)) if (!fileName.endsWith(widgetFileExtension))
{ {
fileName = fileName.append(widgetFileExtension); fileName = fileName.append(widgetFileExtension);
......
...@@ -431,11 +431,21 @@ void LinechartWidget::refresh() ...@@ -431,11 +431,21 @@ void LinechartWidget::refresh()
setUpdatesEnabled(true); 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() void LinechartWidget::startLogging()
{ {
// Store reference to file // Store reference to file
// Append correct file ending if needed
bool abort = false; bool abort = false;
// Check if any curve is enabled // Check if any curve is enabled
...@@ -445,9 +455,9 @@ void LinechartWidget::startLogging() ...@@ -445,9 +455,9 @@ void LinechartWidget::startLogging()
} }
// Let user select the log file name // 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("./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 != "") { while (!(fileName.endsWith(".log")) && !abort && fileName != "") {
QMessageBox::StandardButton button = QGCMessageBox::critical(tr("Unsuitable file extension for logfile"), QMessageBox::StandardButton button = QGCMessageBox::critical(tr("Unsuitable file extension for logfile"),
...@@ -458,10 +468,10 @@ void LinechartWidget::startLogging() ...@@ -458,10 +468,10 @@ void LinechartWidget::startLogging()
abort = true; abort = true;
break; 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 // Check if the user did not abort the file save dialog
if (!abort && fileName != "") { if (!abort && fileName != "") {
......
...@@ -123,6 +123,7 @@ protected: ...@@ -123,6 +123,7 @@ protected:
QToolButton* createButton(QWidget* parent); QToolButton* createButton(QWidget* parent);
void createCurveItem(QString curve); void createCurveItem(QString curve);
void createLayout(); void createLayout();
QString getLogSaveFilename();
/** @brief Get the name for a curve key */ /** @brief Get the name for a curve key */
QString getCurveName(const QString& key, bool shortEnabled); QString getCurveName(const QString& key, bool shortEnabled);
......
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