Browse Source

Fixed stringOfKey wrong return, attempted debug of createScemata FAILED

George 4 years ago
parent
commit
77166a02e7
4 changed files with 160 additions and 60 deletions
  1. 42 21
      src/classes/asettings.cpp
  2. 84 1
      src/classes/asettings.h
  3. 33 37
      src/gui/dialogues/firstrundialog.cpp
  4. 1 1
      src/testing/adebug.h

+ 42 - 21
src/classes/asettings.cpp

@@ -18,8 +18,6 @@
 #include "asettings.h"
 #include "src/astandardpaths.h"
 #include <QSettings>
-#include <algorithm>
-#include <iterator>
 
 
 QMap<ASettings::Main, QString> ASettings::mainMap = {
@@ -79,61 +77,84 @@ void ASettings::setup()
 //
 
 QVariant ASettings::read(const FlightLogging key)
-{ return QSettings().value(stringOfKey(key)); }
+{ return QSettings().value(pathOfKey(key)); }
 
 void ASettings::write(const FlightLogging key, const QVariant &val)
-{ QSettings().setValue(stringOfKey(key), val); }
+{ QSettings().setValue(pathOfKey(key), val); }
 
 QVariant ASettings::read(const LogBook key)
-{ return QSettings().value(stringOfKey(key)); }
+{ return QSettings().value(pathOfKey(key)); }
 
 void ASettings::write(const LogBook key, const QVariant &val)
-{ QSettings().setValue(stringOfKey(key), val); }
+{ QSettings().setValue(pathOfKey(key), val); }
 
 QVariant ASettings::read(const Main key)
-{ return QSettings().value(stringOfKey(key)); }
+{ return QSettings().value(pathOfKey(key)); }
 
 void ASettings::write(const Main key, const QVariant &val)
-{ QSettings().setValue(stringOfKey(key), val); }
+{ QSettings().setValue(pathOfKey(key), val); }
 
 QVariant ASettings::read(const Setup key)
-{ return QSettings().value(stringOfKey(key)); }
+{ return QSettings().value(pathOfKey(key)); }
 
 void ASettings::write(const Setup key, const QVariant &val)
-{ QSettings().setValue(stringOfKey(key), val); }
+{ QSettings().setValue(pathOfKey(key), val); }
 
 QVariant ASettings::read(const NewFlight key)
-{ return QSettings().value(stringOfKey(key)); }
+{ return QSettings().value(pathOfKey(key)); }
 
 void ASettings::write(const NewFlight key, const QVariant &val)
-{ QSettings().setValue(stringOfKey(key), val); }
+{ QSettings().setValue(pathOfKey(key), val); }
 
 QVariant ASettings::read(const UserData key)
-{ return QSettings().value(stringOfKey(key)); }
+{ return QSettings().value(pathOfKey(key)); }
 
 void ASettings::write(const UserData key, const QVariant &val)
-{ QSettings().setValue(stringOfKey(key), val); }
+{ QSettings().setValue(pathOfKey(key), val); }
 
 //
-// QString conversion
+// QString conversion PATH
 //
-QString ASettings::stringOfKey (const ASettings::FlightLogging key)
+QString ASettings::pathOfKey (const ASettings::FlightLogging key)
 { return QStringLiteral("flightlogging/") + flightLoggingMap[key]; }
 
-QString ASettings::stringOfKey (const ASettings::LogBook key)
+QString ASettings::pathOfKey (const ASettings::LogBook key)
 { return QStringLiteral("logbook/") + logBookMap[key]; }
 
-QString ASettings::stringOfKey (const ASettings::Main key)
+QString ASettings::pathOfKey (const ASettings::Main key)
 { return QStringLiteral("main/") + mainMap[key]; }
 
-QString ASettings::stringOfKey (const ASettings::NewFlight key)
+QString ASettings::pathOfKey (const ASettings::NewFlight key)
 { return QStringLiteral("NewFlight/") + newFlightMap[key]; }
 
-QString ASettings::stringOfKey (const ASettings::Setup key)
+QString ASettings::pathOfKey (const ASettings::Setup key)
 { return QStringLiteral("setup/") + setupMap[key]; }
 
-QString ASettings::stringOfKey (const ASettings::UserData key)
+QString ASettings::pathOfKey (const ASettings::UserData key)
 { return QStringLiteral("userdata/") + userDataMap[key]; }
 
+//
+// QString conversion ONLY KEY
+//
+QString ASettings::stringOfKey (const ASettings::FlightLogging key)
+{ return  flightLoggingMap[key]; }
+
+QString ASettings::stringOfKey (const ASettings::LogBook key)
+{ return  logBookMap[key]; }
+
+QString ASettings::stringOfKey (const ASettings::Main key)
+{ return  mainMap[key]; }
+
+QString ASettings::stringOfKey (const ASettings::NewFlight key)
+{ return  newFlightMap[key]; }
+
+QString ASettings::stringOfKey (const ASettings::Setup key)
+{ return  setupMap[key]; }
+
+QString ASettings::stringOfKey (const ASettings::UserData key)
+{ return  userDataMap[key]; }
+
+
+
 QSettings ASettings::settings()
 { return QSettings(); }

+ 84 - 1
src/classes/asettings.h

@@ -95,8 +95,22 @@ public:
     static QVariant read(const NewFlight key);
     static void write(const NewFlight key, const QVariant &val);
 
+    // [G]: enum class may be making it abit too strict perhaps?
+    // a workaround is to use plain enums and have one function takes an int
+    // All enums should be unique of course thats easy. See At the end of the file
+    // for details
     /*!
-     * \brief Return "ini_header/key"
+     * \brief Return string representation of path to key: "ini_header/key"
+     */
+    static QString pathOfKey(const Main key);
+    static QString pathOfKey(const LogBook key);
+    static QString pathOfKey(const NewFlight key);
+    static QString pathOfKey(const FlightLogging key);
+    static QString pathOfKey(const Setup key);
+    static QString pathOfKey(const UserData key);
+
+    /*!
+     * \brief Return string representation of key
      */
     static QString stringOfKey(const Main key);
     static QString stringOfKey(const LogBook key);
@@ -115,6 +129,75 @@ private:
     static QMap<Setup, QString> setupMap;
     static QMap<NewFlight, QString> newFlightMap;
 
+#define REFACTOR_PROPOSAL_REVIEWED true
+#if (REFACTOR_PROPOSAL_REVIEWED)
+    /* By default unless specified each enum is + 1.
+       If we are interested in doing multiple returns at once then
+       we should make them so that the can be OR-ed.
+
+        That means that in binary this means that
+        every new enum has only 1 bit on
+        that bit is always moving to the left
+    */
+    enum Setup2 {
+        SetupComplete       = 0x00'00'00'01,  // If this makes no sense look up hexadecimals
+    };                                        // the ' is legal in numbers it is ignored
+                                              // used only for reader convinience
+    enum Main2 {
+        Theme               = 0x00'00'00'02,
+        ThemeID             = 0x00'00'00'04,
+    };
+
+    enum LogBook2 {
+        View                = 0x00'00'00'08,
+    };
+
+    enum UserData2 {
+        LastName            = 0x00'00'00'10,
+        FirstName           = 0x00'00'00'20,
+        Company             = 0x00'00'00'40,
+        EmployeeID          = 0x00'00'00'80,
+        Phone               = 0x00'00'01'00,
+        Email               = 0x00'00'02'00,
+        DisplaySelfAs       = 0x00'00'04'00,
+        Alias               = 0x00'00'08'00,
+        AcSortColumn        = 0x00'00'10'00,
+        PilSortColumn       = 0x00'00'20'00,
+        AcAllowIncomplete   = 0x00'00'40'00,
+    };
+
+    enum FlightLogging2 {
+        Function            = 0x00'00'80'00,
+        Approach            = 0x00'01'00'00,
+        NightLogging        = 0x00'02'00'00,
+        LogIFR              = 0x00'04'00'00,
+        FlightNumberPrefix  = 0x00'08'00'00,
+        NumberTakeoffs      = 0x00'10'00'00,
+        NumberLandings      = 0x00'20'00'00,
+        PopupCalendar       = 0x00'40'00'00,
+        PilotFlying         = 0x00'80'00'00,
+        NightAngle          = 0x01'00'00'00,
+        Rules               = 0x02'00'00'00,
+    };
+
+    enum NewFlight2 {
+        FunctionComboBox    = 0x04'00'00'00,
+        CalendarCheckBox    = 0x08'00'00'00,
+    };
+
+    using Key = int;
+    using Keys = int;
+    /*
+     * Used like QMessageBox buttons;
+     *
+     * auto str = stringOfKey2(ASettings::Setup);
+     * auto strlist = stringOfKeys2(ASettings::Setup | ASettings::Function)
+     */
+    QString stringOfKey2(Key k);
+    QStringList stringOfKeys2(Keys ks);
+
+#endif
+
 };
 
 #endif // ASETTINGS_H

+ 33 - 37
src/gui/dialogues/firstrundialog.cpp

@@ -7,12 +7,7 @@
 #include "src/classes/adownload.h"
 #include "src/classes/asettings.h"
 #include "src/astandardpaths.h"
-
-static inline
-void prompt_error_box(QString title, QString text, QWidget* parent = nullptr)
-{
-    QMessageBox(QMessageBox::Warning, title, text, QMessageBox::Ok, parent).exec();
-}
+#include <QErrorMessage>
 
 FirstRunDialog::FirstRunDialog(QWidget *parent) :
     QDialog(parent),
@@ -29,7 +24,8 @@ FirstRunDialog::FirstRunDialog(QWidget *parent) :
     themeGroup->addButton(ui->lightThemeCheckBox, 1);
     themeGroup->addButton(ui->darkThemeCheckBox, 2);
 
-    QObject::connect(themeGroup, QOverload<int>::of(&QButtonGroup::buttonClicked),
+    // [G]: no sure what this connects and why button is overloaded but changed it to what QtCreator suggests
+    QObject::connect(themeGroup, &QButtonGroup::idClicked,
                      this, &FirstRunDialog::on_themeGroup_toggled);
 }
 
@@ -64,8 +60,9 @@ void FirstRunDialog::on_nextPushButton_clicked()
         if(ui->firstnameLineEdit->text().isEmpty()
            || ui->lastnameLineEdit->text().isEmpty())
         {
-            prompt_error_box(QStringLiteral("Error"),
-                             QStringLiteral("Please enter first and last name"));
+            QMessageBox(QMessageBox::Warning,QStringLiteral("Error"),
+                             QStringLiteral("Please enter first and last name")
+                             ).exec();
             return;
         }
         ui->previousPushButton->setEnabled(true);
@@ -112,10 +109,13 @@ void FirstRunDialog::finish()
     data.insert(ASettings::stringOfKey(ASettings::UserData::Phone), ui->phoneLineEdit->text());
     data.insert(ASettings::stringOfKey(ASettings::UserData::Email), ui->emailLineEdit->text());
 
+    auto db_fail_msg_box = QMessageBox(QMessageBox::Critical, QStringLiteral("Database setup failed"),
+                                       QStringLiteral("Errors have ocurred creating the database."
+                                                      "Without a working database The application will not be usable."));
+    // [G]: Im abit confused on the logic here
+    // why do you write setup complete twice?
     if (!setupDatabase()) {
-        QMessageBox message_box(this);
-        message_box.setText(QStringLiteral("Errors have ocurred creating the database. Without a working database The application will not be usable."));
-        message_box.exec();
+        db_fail_msg_box.exec();
     }
     ASettings::write(ASettings::Setup::SetupComplete, true);
 
@@ -125,39 +125,33 @@ void FirstRunDialog::finish()
     auto pilot = APilotEntry(1);
     pilot.setData(data);
     if (aDB()->commit(pilot)) {
-        ASettings::write(QStringLiteral("setup/setup_complete"), true);
+        ASettings::write(ASettings::Setup::SetupComplete, true);
         QDialog::accept();
     } else {
-        QMessageBox message_box(this);
-        message_box.setText(QStringLiteral("Errors have ocurred creating the database. "
-                                           "Without a working database The application will "
-                                           "not be usable."));
+        db_fail_msg_box.exec();
         QDialog::reject();
     }
 }
 
 bool FirstRunDialog::setupDatabase()
 {
-
-    QMessageBox confirm;
-    DEB << "TESTETESTS";
-    confirm.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+    auto confirm = QMessageBox(QMessageBox::Question, QStringLiteral("Create Database"),
+                               QStringLiteral("We are now going to create the database.<br>"  // [G]: Why both <br> and \n ?
+                                              "Would you like to download the latest database information?"
+                                              "<br>(Recommended, Internet connection required)\n"),
+                               QMessageBox::Yes | QMessageBox::No, this);
     confirm.setDefaultButton(QMessageBox::No);
-    confirm.setIcon(QMessageBox::Question);
-    confirm.setWindowTitle(QStringLiteral("Create Database"));
-    confirm.setText(QStringLiteral("We are now going to create the database.<br>"
-                                   "Would you like to download the latest database information?"
-                                   "<br>(Recommended, Internet connection required)\n"));
-
-    int reply = confirm.exec();
-    if (reply == QMessageBox::Yes)
+
+    if (confirm.exec() == QMessageBox::Yes)
         ADataBaseSetup::downloadTemplates();
 
     aDB()->disconnect();
     ADataBaseSetup::backupOldData();
     aDB()->connect();
 
-    ///[F]: to do: handle unsuccessful steps
+    // [F]: todo: handle unsuccessful steps
+    // [G]: only two / for comments
+    // three are shorthand for documentation
     if(!ADataBaseSetup::createDatabase())
         return false;
     if(!ADataBaseSetup::importDefaultData())
@@ -168,14 +162,16 @@ bool FirstRunDialog::setupDatabase()
 
 void FirstRunDialog::reject()
 {
-    auto confirm = QMessageBox(this);
-    confirm.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+    auto confirm = QMessageBox(QMessageBox::Critical,
+                                     QStringLiteral("Setup incomplete"),
+                                     QStringLiteral("Without completing the initial setup"
+                                                    " you cannot use the application.<br><br>"
+                                                    "Quit anyway?"),
+                                     QMessageBox::Yes | QMessageBox::No,
+                                     this
+                                     );
     confirm.setDefaultButton(QMessageBox::No);
-    confirm.setIcon(QMessageBox::Critical);
-    confirm.setWindowTitle(QStringLiteral("Setup incomplete"));
-    confirm.setText(QStringLiteral("Without completing the initial setup"
-                                   " you cannot use the application.<br><br>"
-                                   "Quit anyway?"));
+
     if (confirm.exec() == QMessageBox::Yes) {
         DEB << "rejected.";
         QDialog::reject();

+ 1 - 1
src/testing/adebug.h

@@ -3,7 +3,7 @@
 
 #include <QDebug>
 
-#define DEB qDebug() << __PRETTY_FUNCTION__ << "\t"
+#define DEB qDebug() << __PRETTY_FUNCTION__ << "\t\n"
 
 /*!
  * Representation macro for custom classes.