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
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(),
......
......@@ -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();
......
......@@ -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);
......
......@@ -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);
}
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -63,6 +63,7 @@ protected:
}
void changeEvent(QEvent *e);
QString getSavePlotFilename();
IncrementalPlot* plot;
LogCompressor* compressor;
QFile* logFile;
......
......@@ -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()
......
......@@ -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);
......
......@@ -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 != "") {
......
......@@ -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);
......
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