Browse Source

Changed retreiving of settings

fiffty-50 4 years ago
parent
commit
402c4044a7
4 changed files with 45 additions and 17 deletions
  1. 31 3
      dbman.cpp
  2. 1 1
      main.cpp
  3. 12 12
      newflight.cpp
  4. 1 1
      settingswidget.cpp

+ 31 - 3
dbman.cpp

@@ -898,10 +898,34 @@ public:
     }
 
     /*
-     * Aircraft Database Related Functions
+     * Settings Database Related Functions
      */
 
-    static QVector<QString> retreiveSetting(QString setting_id)
+    /*!
+     * \brief retreiveSetting Looks up a setting in the database and returns its value
+     * \param setting_id
+     * \return setting value
+     */
+    static QString retreiveSetting(QString setting_id)
+    {
+        QSqlQuery query;
+        query.prepare("SELECT setting FROM settings WHERE setting_id = ?");
+        query.addBindValue(setting_id);
+        query.exec();
+
+        QString setting = "-1";
+
+        while(query.next()){
+            setting = query.value(0).toString();
+        }
+        return setting;
+    }
+    /*!
+     * \brief retreiveSettingInfo Looks up a setting in the database and returns its value and description
+     * \param setting_id
+     * \return {setting_id, setting, description}
+     */
+    static QVector<QString> retreiveSettingInfo(QString setting_id)
     {
         QSqlQuery query;
         query.prepare("SELECT * FROM settings WHERE setting_id = ?");
@@ -917,7 +941,11 @@ public:
         }
         return setting;
     }
-
+    /*!
+     * \brief storesetting Updates a stored setting in the database
+     * \param setting_id
+     * \param setting_value
+     */
     static void storesetting(int setting_id, QString setting_value)
     {
         QSqlQuery query;

+ 1 - 1
main.cpp

@@ -38,7 +38,7 @@ int main(int argc, char *argv[])
 
     //Theming with CSS inlcues QFile,QTextStream, QDir, themes folder and TARGET = flog, RESOURCES = themes/breeze.qrc in pro
     // credit: https://github.com/Alexhuszagh/BreezeStyleSheets
-    selectedtheme = db::retreiveSetting("10")[1].toInt();
+    selectedtheme = db::retreiveSetting("10").toInt();
     QDir::setCurrent("/themes");
     if (selectedtheme == 1){
         qDebug() << "Loading light theme";

+ 12 - 12
newflight.cpp

@@ -350,18 +350,18 @@ void NewFlight::storeSettings()
 void NewFlight::restoreSettings()
 {
     qDebug() << "Restoring Settings...";//crashes if db is empty due to QVector index out of range.
-    ui->FunctionComboBox->setCurrentText(db::retreiveSetting("100")[1]);
-    ui->ApproachComboBox->setCurrentText(db::retreiveSetting("101")[1]);
-    ui->PilotFlyingCheckBox->setChecked(db::retreiveSetting("102")[1].toInt());
-    ui->PilotMonitoringCheckBox->setChecked(db::retreiveSetting("103")[1].toInt());
-    ui->TakeoffSpinBox->setValue(db::retreiveSetting("104")[1].toInt());
-    ui->TakeoffCheckBox->setChecked(db::retreiveSetting("105")[1].toInt());
-    ui->LandingSpinBox->setValue(db::retreiveSetting("106")[1].toInt());
-    ui->LandingCheckBox->setChecked(db::retreiveSetting("107")[1].toInt());
-    ui->AutolandSpinBox->setValue(db::retreiveSetting("108")[1].toInt());
-    ui->AutolandCheckBox->setChecked(db::retreiveSetting("109")[1].toInt());
-    ui->IfrCheckBox->setChecked(db::retreiveSetting("110")[1].toInt());
-    ui->VfrCheckBox->setChecked(db::retreiveSetting("111")[1].toInt());
+    ui->FunctionComboBox->setCurrentText(db::retreiveSetting("100"));
+    ui->ApproachComboBox->setCurrentText(db::retreiveSetting("101"));
+    ui->PilotFlyingCheckBox->setChecked(db::retreiveSetting("102").toInt());
+    ui->PilotMonitoringCheckBox->setChecked(db::retreiveSetting("103").toInt());
+    ui->TakeoffSpinBox->setValue(db::retreiveSetting("104").toInt());
+    ui->TakeoffCheckBox->setChecked(db::retreiveSetting("105").toInt());
+    ui->LandingSpinBox->setValue(db::retreiveSetting("106").toInt());
+    ui->LandingCheckBox->setChecked(db::retreiveSetting("107").toInt());
+    ui->AutolandSpinBox->setValue(db::retreiveSetting("108").toInt());
+    ui->AutolandCheckBox->setChecked(db::retreiveSetting("109").toInt());
+    ui->IfrCheckBox->setChecked(db::retreiveSetting("110").toInt());
+    ui->VfrCheckBox->setChecked(db::retreiveSetting("111").toInt());
     //ui->autoNightCheckBox->setChecked(db::retreiveSetting("112")[1].toInt());
     //qDebug() << "restore Settings ifr to int: " << db::retreiveSetting("110")[1].toInt();
 

+ 1 - 1
settingswidget.cpp

@@ -17,7 +17,7 @@ settingsWidget::settingsWidget(QWidget *parent) :
     themeGroup->addButton(ui->lightThemeCheckBox);
     themeGroup->addButton(ui->darkThemeCheckBox);
 
-    int themeSetting = db::retreiveSetting("10")[1].toInt();
+    int themeSetting = db::retreiveSetting("10").toInt();
     qDebug() << themeSetting;
     switch (themeSetting) {
       case 0: