Kaynağa Gözat

Small fixes for build

- Adding a WIN32 conditional in CMakeLists.txt to avoid the Application spawing a terminal window
- Added an additional exit() command for triggering program exit when it is called before the main application window has finished constructing (db validity check)
- Added a local path for the settings file within the application directory
- Added a check when parsing the sql source file to create the database (in some cases the end-of-file character is read as an addition sql statement)
- Added a fallback for random bool generation when arc4random is not available
Felix Turo 2 yıl önce
ebeveyn
işleme
9d8c6219f9

+ 29 - 12
CMakeLists.txt

@@ -182,19 +182,36 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
     add_definitions(-DQT_NO_DEBUG_OUTPUT)
 endif()
 
-
-if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
-    qt_add_executable(openPilotLog
-        ${PROJECT_SOURCES}
-        ${QM_FILES}
-        ${app_icon_macos}
-    )
+# set the win32 entry point to avoid terminal popping up
+if(WIN32)
+    MESSAGE("Building for WIN32")
+    if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
+        qt_add_executable(openPilotLog WIN32
+            ${PROJECT_SOURCES}
+            ${QM_FILES}
+            ${app_icon_macos}
+        )
+    else()
+        add_executable(openPilotLog
+            ${PROJECT_SOURCES}
+            ${QM_FILES}
+            ${app_icon_macos}
+        )
+    endif()
 else()
-    add_executable(openPilotLog
-        ${PROJECT_SOURCES}
-        ${QM_FILES}
-        ${app_icon_macos}
-    )
+    if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
+        qt_add_executable(openPilotLog
+            ${PROJECT_SOURCES}
+            ${QM_FILES}
+            ${app_icon_macos}
+     )
+    else()
+     add_executable(openPilotLog
+         ${PROJECT_SOURCES}
+         ${QM_FILES}
+         ${app_icon_macos}
+     )
+    endif()
 endif()
 
 

+ 1 - 0
mainwindow.cpp

@@ -278,6 +278,7 @@ void MainWindow::on_actionSettings_triggered()
 void MainWindow::on_actionQuit_triggered()
 {
     QApplication::quit();
+    exit(0);
 }
 
 void MainWindow::on_actionDebug_triggered()

+ 2 - 0
src/classes/paths.h

@@ -18,6 +18,7 @@ public:
         Backup,
         Log,
         Export,
+        Settings,
     };
 
     const static inline QHash<Directories, QLatin1String> directories = {
@@ -26,6 +27,7 @@ public:
         {Backup, QLatin1String("/backup")},
         {Log, QLatin1String("/log")},
         {Export, QLatin1String("/export")},
+        {Settings, QLatin1String("/settings")},
     };
 
     Paths();

+ 2 - 0
src/classes/settings.cpp

@@ -17,6 +17,7 @@
  */
 #include "settings.h"
 #include <QSettings>
+#include "src/classes/paths.h"
 
 
 QMap<Settings::Main, QString> Settings::mainMap = {
@@ -60,6 +61,7 @@ QMap<Settings::FlightLogging, QString> Settings::flightLoggingMap = {
 void Settings::setup()
 {
     QSettings::setDefaultFormat(QSettings::IniFormat);
+    QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, OPL::Paths::path(OPL::Paths::Settings));
     QSettings();
 }
 

+ 4 - 0
src/database/database.cpp

@@ -637,6 +637,10 @@ bool Database::createSchema()
     // create individual queries for each table/view
     auto list = filedata.split(';');
 
+    // make sure last empty line in sql file has not been parsed
+    if(list.last() == QByteArray("\n"))
+        list.removeLast();
+
     // Create Tables
     QSqlQuery q;
     QVector<QSqlError> errors;

+ 6 - 1
src/gui/dialogues/exporttocsvdialog.cpp

@@ -23,7 +23,12 @@ void ExportToCsvDialog::on_exportPushButton_clicked()
 {
     selectRows();
     // File Dialog where to save
-    QString filePath = QFileDialog::getSaveFileName(this, tr("Select Location"));
+    QString filePath = QFileDialog::getSaveFileName(this,
+                                                    tr("Select Location"),
+                                                    QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
+                                                    QStringLiteral("*.csv"));
+    if(filePath.isEmpty()) return; // user has cancelled file dialog
+
     if(!filePath.endsWith(QStringLiteral(".csv")))
         filePath += ".csv";
     DEB << filePath;

+ 5 - 1
src/gui/dialogues/exporttocsvdialog.h

@@ -7,6 +7,9 @@ namespace Ui {
 class ExportToCsvDialog;
 }
 
+/*!
+ * \brief The ExportToCsvDialog class enables the user to export the database to a CSV file
+ */
 class ExportToCsvDialog : public QDialog
 {
     Q_OBJECT
@@ -25,7 +28,8 @@ private:
 
     void init();
     /*!
-     * \brief fill the selectedRows vector with data based on the selected view
+     * \brief fill the selectedRows vector with data based on the selected view.
+     * The selected rows are a subset of the rows available in the database.
      */
     void selectRows();
 };

+ 4 - 4
src/gui/dialogues/firstrundialog.cpp

@@ -306,14 +306,14 @@ bool FirstRunDialog::setupDatabase()
     }
 
     if(!DB->createSchema()) {
-        WARN(tr("Database creation has been unsuccessful. The following error has ocurred:<br><br>%1")
-             .arg(DB->lastError.text()));
+        WARN(tr("Database creation has been unsuccessful. The following error has ocurred:<br><br>%1<br><br>%2")
+             .arg(FUNC_IDENT, DB->lastError.text()));
         return false;
     }
 
     if(!DB->importTemplateData(useRessourceData)) {
-        WARN(tr("Database creation has been unsuccessful. Unable to fill template data.<br><br>%1")
-             .arg(DB->lastError.text()));
+        WARN(tr("Database creation has been unsuccessful. Unable to fill template data.<br><br>%1<br><br>%2")
+             .arg(FUNC_IDENT, DB->lastError.text()));
         return false;
     }
     return true;

+ 5 - 0
src/testing/randomgenerator.cpp

@@ -131,7 +131,12 @@ const int RandomGenerator::randomTail()
 
 const bool RandomGenerator::randomBool()
 {
+#if HAVE_ARC4RANDOM
     return arc4random() > (RAND_MAX / 2);
+#else
+    auto gen = std::bind(std::uniform_int_distribution<>(0,1),std::default_random_engine());
+    return gen();
+#endif
 }
 
 } // namespace OPL