From 53751dfe892afa3e2685b40970dc8090566f6684 Mon Sep 17 00:00:00 2001
From: dogmaphobic <dogmaphobic@users.noreply.github.com>
Date: Tue, 3 Feb 2015 17:00:35 -0500
Subject: [PATCH] Adding some TODO items Fixing braces Changing data plot save
 files to csv only Fixing LinechartWidget::startLogging() as it no longer
 needs to worry about a proper file name being set.

---
 src/ui/QGCDataPlot2D.cc             | 11 ++++---
 src/ui/linechart/LinechartWidget.cc | 49 +++++++++--------------------
 src/ui/linechart/LinechartWidget.h  |  1 -
 3 files changed, 22 insertions(+), 39 deletions(-)

diff --git a/src/ui/QGCDataPlot2D.cc b/src/ui/QGCDataPlot2D.cc
index f443eef7dc..a676f11919 100644
--- a/src/ui/QGCDataPlot2D.cc
+++ b/src/ui/QGCDataPlot2D.cc
@@ -157,6 +157,7 @@ void QGCDataPlot2D::savePlot()
     } else if (fileName.endsWith(".svg")) {
         exportSVG(fileName);
     }
+    // TODO Tell the user the name (type) was invalid (neither pdf nor svg) and nothing is being done.
 }
 
 
@@ -272,7 +273,7 @@ void QGCDataPlot2D::selectFile()
     }
     else
     {
-        fileName = QGCFileDialog::getOpenFileName(this, tr("Load Log File"), QString(), "Log files (*.csv *.txt *.log)");
+        fileName = QGCFileDialog::getOpenFileName(this, tr("Load Log File"), QString(), "Log files (*.csv);;All Files (*)");
     }
 
     // Check if the user hit cancel, which results in an empty string.
@@ -698,11 +699,13 @@ void QGCDataPlot2D::saveCsvLog()
 {
     QString fileName = QGCFileDialog::getSaveFileName(
         this, "Save CSV Log File", QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
-        "CSV file (*.csv);;Text file (*.txt)",
-        "csv");
+        "CSV file (*.csv)",
+        "csv",
+        true);
 
-    if (fileName.isEmpty())
+    if (fileName.isEmpty()) {
         return; //User cancelled
+    }
 
     bool success = logFile->copy(fileName);
 
diff --git a/src/ui/linechart/LinechartWidget.cc b/src/ui/linechart/LinechartWidget.cc
index 372e284b53..d87d049a95 100644
--- a/src/ui/linechart/LinechartWidget.cc
+++ b/src/ui/linechart/LinechartWidget.cc
@@ -431,49 +431,29 @@ void LinechartWidget::refresh()
     setUpdatesEnabled(true);
 }
 
-QString LinechartWidget::getLogSaveFilename()
-{
-    QString fileName = QGCFileDialog::getSaveFileName(this,
-        tr("Save Log File"),
-        QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
-        tr("Log file (*.log)"),
-        "log",
-        true);
-    return fileName;
-}
-
 void LinechartWidget::startLogging()
 {
-    // Store reference to file
-    bool abort = false;
-
     // Check if any curve is enabled
     if (!activePlot->anyCurveVisible()) {
-        QGCMessageBox::critical(tr("No curves selected for logging."), tr("Please check all curves you want to log. Currently no data would be logged, aborting the logging."));
+        QGCMessageBox::critical(
+            tr("No curves selected for logging."),
+            tr("Please check all curves you want to log. Currently no data would be logged. Aborting the logging."));
         return;
     }
 
     // Let user select the log file name
     // QDate date(QDate::currentDate());
     // QString("./pixhawk-log-" + date.toString("yyyy-MM-dd") + "-" + QString::number(logindex) + ".log")
-    QString fileName = getLogSaveFilename();
-
-    while (!(fileName.endsWith(".log")) && !abort && fileName != "") {
-        QMessageBox::StandardButton button = QGCMessageBox::critical(tr("Unsuitable file extension for logfile"),
-                                                                     tr("Please choose .log as file extension. Click OK to change the file extension, cancel to not start logging."),
-                                                                     QMessageBox::Ok | QMessageBox::Cancel,
-                                                                     QMessageBox::Ok);
-        if (button != QMessageBox::Ok) {
-            abort = true;
-            break;
-        }
-        fileName = getLogSaveFilename();
-    }
+    QString fileName = QGCFileDialog::getSaveFileName(this,
+        tr("Save Log File"),
+        QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
+        tr("Log file (*.log)"),
+        "log", // Default type
+        true); // Enforce default type
 
     qDebug() << "SAVE FILE " << fileName;
 
-    // Check if the user did not abort the file save dialog
-    if (!abort && fileName != "") {
+    if (!fileName.isEmpty()) {
         logFile = new QFile(fileName);
         if (logFile->open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text)) {
             logging = true;
@@ -498,10 +478,11 @@ void LinechartWidget::stopLogging()
         compressor = new LogCompressor(logFile->fileName(), logFile->fileName());
         connect(compressor, SIGNAL(finishedFile(QString)), this, SIGNAL(logfileWritten(QString)));
 
-        QMessageBox::StandardButton button = QGCMessageBox::question(tr("Starting Log Compression"),
-                                                                     tr("Should empty fields (e.g. due to packet drops) be filled with the previous value of the same variable (zero order hold)?"),
-                                                                     QMessageBox::Yes | QMessageBox::No,
-                                                                     QMessageBox::No);
+        QMessageBox::StandardButton button = QGCMessageBox::question(
+            tr("Starting Log Compression"),
+            tr("Should empty fields (e.g. due to packet drops) be filled with the previous value of the same variable (zero order hold)?"),
+            QMessageBox::Yes | QMessageBox::No,
+            QMessageBox::No);
         bool fill;
         if (button == QMessageBox::Yes)
         {
diff --git a/src/ui/linechart/LinechartWidget.h b/src/ui/linechart/LinechartWidget.h
index 081b31fe75..4c9fb20b62 100644
--- a/src/ui/linechart/LinechartWidget.h
+++ b/src/ui/linechart/LinechartWidget.h
@@ -123,7 +123,6 @@ 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);
 
-- 
GitLab