Browse Source

working onfirstrun dialog and database

fiffty-50 4 years ago
parent
commit
9fdb2cd9f9

BIN
assets/database/logbook.db


+ 6 - 2
main.cpp

@@ -60,7 +60,7 @@ int main(int argc, char *argv[])
     int selectedtheme = settings.value("main/theme").toInt();
     QDir::setCurrent("/themes");
     switch (selectedtheme) {
-    case 1: {
+    case 1:{
         qDebug() << "main :: Loading light theme";
         QFile file(":light.qss");
         file.open(QFile::ReadOnly | QFile::Text);
@@ -68,7 +68,7 @@ int main(int argc, char *argv[])
         openPilotLog.setStyleSheet(stream.readAll());
         break;
     }
-    case 2:
+    case 2:{
         qDebug() << "Loading dark theme";
         QFile file(":dark.qss");
         file.open(QFile::ReadOnly | QFile::Text);
@@ -76,6 +76,10 @@ int main(int argc, char *argv[])
         openPilotLog.setStyleSheet(stream.readAll());
         break;
     }
+    default:
+        break;
+    }
+
 
     MainWindow w;
     //w.showMaximized();

+ 1 - 1
openPilotLog.pro.user

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 4.11.0, 2020-11-06T11:26:14. -->
+<!-- Written by QtCreator 4.11.0, 2020-11-06T21:35:31. -->
 <qtcreator>
  <data>
   <variable>EnvironmentId</variable>

+ 3 - 5
src/database/entry.h

@@ -35,11 +35,9 @@ public:
 
 
 
-    QPair   <QString, int>       position =
-        QPair<QString, int>();   // Position within the database, i.e. <table,row>
-    QVector <QString>           columns  = QVector<QString>();       // The columns within the table
-    QMap    <QString, QString>   data     =
-        QMap<QString, QString>(); // Tha data to fill that table, <column,value>
+    QPair   <QString, int>       position = QPair<QString, int>();   // Position within the database, i.e. <table,row>
+    QVector <QString>            columns  = QVector<QString>();       // The columns within the table
+    QMap    <QString, QString>   data     = QMap<QString, QString>(); // Tha data to fill that table, <column,value>
 
     void setData(const QMap<QString, QString> &value);
 

+ 75 - 5
src/gui/dialogues/firstrundialog.cpp

@@ -6,8 +6,15 @@ FirstRunDialog::FirstRunDialog(QWidget *parent) :
     ui(new Ui::FirstRunDialog)
 {
     ui->setupUi(this);
+    ui->tabWidget->setCurrentIndex(0);
+    ui->piclastnameLineEdit->setFocus();
+    ui->nightComboBox->setCurrentIndex(1);
 
-    disregard();
+    auto *themeGroup = new QButtonGroup;
+    themeGroup->addButton(ui->systemThemeCheckBox, 0);
+    themeGroup->addButton(ui->lightThemeCheckBox, 1);
+    themeGroup->addButton(ui->darkThemeCheckBox, 2);
+    connect(themeGroup, SIGNAL(buttonClicked(int)), this, SLOT(themeGroup_toggled(int)));
 }
 
 FirstRunDialog::~FirstRunDialog()
@@ -15,13 +22,76 @@ FirstRunDialog::~FirstRunDialog()
     delete ui;
 }
 
-void FirstRunDialog::on_pushButton_clicked()
+void FirstRunDialog::on_previousPushButton_clicked()
 {
-    accept();
+    if(ui->tabWidget->currentIndex()>0)
+        ui->tabWidget->setCurrentIndex(ui->tabWidget->currentIndex()-1);
 }
 
-void FirstRunDialog::disregard()
+void FirstRunDialog::on_nextPushButton_clicked()
 {
-    //emit ui->pushButton->clicked();
+    if(ui->tabWidget->currentIndex()<2)
+        ui->tabWidget->setCurrentIndex(ui->tabWidget->currentIndex()+1);
+}
+
+void FirstRunDialog::themeGroup_toggled(int id)
+{
+    QSettings settings;
+    settings.setValue("main/theme", id);
+}
+
+void FirstRunDialog::on_finishButton_clicked()
+{
+    if(ui->piclastnameLineEdit->text().isEmpty() || ui->picfirstnameLineEdit->text().isEmpty()){
+        auto mb = new QMessageBox(this);
+        mb->setText("You have to enter a valid first and last name for the logbook.");
+        mb->show();
+    } else {
+        QSettings settings;
+        settings.setValue("userdata/piclastname",ui->piclastnameLineEdit->text());
+        settings.setValue("userdata/picfirstname",ui->picfirstnameLineEdit->text());
+        settings.setValue("userdata/employeeid",ui->employeeidLineEdit->text());
+        settings.setValue("userdata/phone",ui->phoneLineEdit->text());
+        settings.setValue("userdata/email",ui->emailLineEdit->text());
+
+        settings.setValue("flightlogging/function", ui->functionComboBox->currentText());
+        settings.setValue("flightlogging/rules", ui->rulesComboBox->currentText());
+        settings.setValue("flightlogging/approach", ui->approachComboBox->currentText());
+        settings.setValue("flightlogging/nightlogging", ui->functionComboBox->currentIndex());
+        settings.setValue("flightlogging/flightnumberPrefix", ui->prefixLineEdit->text());
+
+        QMap<QString,QString> data;
+        switch (ui->aliasComboBox->currentIndex()) {
+        case 0:
+            settings.setValue("userdata/displayselfas","self");
+            data.insert("displayname","self");
+            break;
+        case 1:
+            settings.setValue("userdata/displayselfas","SELF");
+            data.insert("displayname","SELF");
+            break;
+        case 2:{
+            settings.setValue("userdata/displayselfas","Last,F.");
+            QString name;
+            name.append(ui->piclastnameLineEdit->text());
+            name.append(QLatin1String(", "));
+            name.append(ui->picfirstnameLineEdit->text().left(1));
+            name.append(QLatin1Char('.'));
+            data.insert("displayname",name);
+        }
+            break;
+        default:
+            break;
+        }
+        data.insert("piclastname",ui->piclastnameLineEdit->text());
+        data.insert("picfirstname",ui->picfirstnameLineEdit->text());
+        data.insert("employeeid",ui->employeeidLineEdit->text());
+        data.insert("phone",ui->phoneLineEdit->text());
+        data.insert("email",ui->emailLineEdit->text());
 
+        Pilot pic("pilots",1);
+        pic.setData(data);
+        pic.commit();
+        accept();
+    }
 }

+ 14 - 2
src/gui/dialogues/firstrundialog.h

@@ -2,6 +2,11 @@
 #define FIRSTRUNDIALOG_H
 
 #include <QDialog>
+#include <QButtonGroup>
+#include <QSettings>
+#include <QMessageBox>
+#include <QRegularExpressionValidator>
+#include "src/classes/pilot.h"
 
 namespace Ui {
 class FirstRunDialog;
@@ -16,11 +21,18 @@ public:
     ~FirstRunDialog();
 
 private slots:
-    void on_pushButton_clicked();
+
+    void on_previousPushButton_clicked();
+
+    void on_nextPushButton_clicked();
+
+    void themeGroup_toggled(int id);
+
+    void on_finishButton_clicked();
 
 private:
     Ui::FirstRunDialog *ui;
-    void disregard();
+
 };
 
 #endif // FIRSTRUNDIALOG_H

+ 477 - 28
src/gui/dialogues/firstrundialog.ui

@@ -6,40 +6,489 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>640</width>
-    <height>480</height>
+    <width>1280</width>
+    <height>720</height>
    </rect>
   </property>
   <property name="windowTitle">
    <string>Dialog</string>
   </property>
-  <widget class="QPushButton" name="pushButton">
-   <property name="geometry">
-    <rect>
-     <x>280</x>
-     <y>250</y>
-     <width>80</width>
-     <height>27</height>
-    </rect>
-   </property>
-   <property name="text">
-    <string>OK</string>
-   </property>
-  </widget>
-  <widget class="QLabel" name="label">
-   <property name="geometry">
-    <rect>
-     <x>170</x>
-     <y>200</y>
-     <width>304</width>
-     <height>19</height>
-    </rect>
-   </property>
-   <property name="text">
-    <string>First Run / Setup Dialog to be shown here.</string>
-   </property>
-  </widget>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0" colspan="2">
+    <widget class="QTabWidget" name="tabWidget">
+     <property name="currentIndex">
+      <number>1</number>
+     </property>
+     <widget class="QWidget" name="tab_1">
+      <attribute name="title">
+       <string>General</string>
+      </attribute>
+      <layout class="QGridLayout" name="gridLayout_2">
+       <item row="0" column="1">
+        <widget class="QLabel" name="label">
+         <property name="text">
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:16pt;&quot;&gt;Welcome to openPilotLog!&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;Before getting started, we need to quickly run through this initial set-up process. Please note that none of the data you put in will be stored in any place other than your own personal computer and will only be used to fill out information in your logbook. OpenPilotLog will never collect, sell use your private data for any commercial purpose.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+         </property>
+         <property name="textFormat">
+          <enum>Qt::RichText</enum>
+         </property>
+         <property name="wordWrap">
+          <bool>true</bool>
+         </property>
+        </widget>
+       </item>
+       <item row="1" column="0">
+        <widget class="QLabel" name="lastNameLabel">
+         <property name="text">
+          <string>Last Name</string>
+         </property>
+        </widget>
+       </item>
+       <item row="1" column="1">
+        <widget class="QLineEdit" name="piclastnameLineEdit">
+         <property name="maxLength">
+          <number>40</number>
+         </property>
+         <property name="placeholderText">
+          <string>required</string>
+         </property>
+        </widget>
+       </item>
+       <item row="2" column="0">
+        <widget class="QLabel" name="firstNameLabel">
+         <property name="text">
+          <string>First Name</string>
+         </property>
+        </widget>
+       </item>
+       <item row="2" column="1">
+        <widget class="QLineEdit" name="picfirstnameLineEdit">
+         <property name="maxLength">
+          <number>40</number>
+         </property>
+         <property name="placeholderText">
+          <string>required</string>
+         </property>
+        </widget>
+       </item>
+       <item row="3" column="0">
+        <widget class="QLabel" name="employeeLabel">
+         <property name="text">
+          <string>Employee ID</string>
+         </property>
+        </widget>
+       </item>
+       <item row="3" column="1">
+        <widget class="QLineEdit" name="employeeidLineEdit">
+         <property name="focusPolicy">
+          <enum>Qt::StrongFocus</enum>
+         </property>
+         <property name="text">
+          <string/>
+         </property>
+         <property name="maxLength">
+          <number>40</number>
+         </property>
+         <property name="placeholderText">
+          <string>optional</string>
+         </property>
+        </widget>
+       </item>
+       <item row="4" column="0">
+        <widget class="QLabel" name="emailLabel">
+         <property name="text">
+          <string>eMail</string>
+         </property>
+        </widget>
+       </item>
+       <item row="4" column="1">
+        <widget class="QLineEdit" name="emailLineEdit">
+         <property name="maxLength">
+          <number>40</number>
+         </property>
+         <property name="placeholderText">
+          <string>optional</string>
+         </property>
+        </widget>
+       </item>
+       <item row="5" column="0">
+        <widget class="QLabel" name="phoneLabel">
+         <property name="text">
+          <string>Phone</string>
+         </property>
+        </widget>
+       </item>
+       <item row="5" column="1">
+        <widget class="QLineEdit" name="phoneLineEdit">
+         <property name="maxLength">
+          <number>40</number>
+         </property>
+         <property name="placeholderText">
+          <string>optional</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </widget>
+     <widget class="QWidget" name="tab_2">
+      <attribute name="title">
+       <string>Flight Logging</string>
+      </attribute>
+      <layout class="QGridLayout" name="gridLayout_3">
+       <item row="0" column="1">
+        <widget class="QLabel" name="label_2">
+         <property name="text">
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:16pt;&quot;&gt;Flight Logging&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;Here you can make selections about which parts of a new flight will be automatically completed by default. You can always change these settings for an individual flight or adjust them globally in the settings menu.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+         </property>
+         <property name="textFormat">
+          <enum>Qt::RichText</enum>
+         </property>
+         <property name="wordWrap">
+          <bool>true</bool>
+         </property>
+        </widget>
+       </item>
+       <item row="1" column="0">
+        <widget class="QLabel" name="aliasLabel">
+         <property name="text">
+          <string>Show own name as</string>
+         </property>
+        </widget>
+       </item>
+       <item row="1" column="1">
+        <widget class="QComboBox" name="aliasComboBox">
+         <item>
+          <property name="text">
+           <string>self</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>SELF</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>Lastname, Firstname</string>
+          </property>
+         </item>
+        </widget>
+       </item>
+       <item row="2" column="0">
+        <widget class="QLabel" name="functionLabel">
+         <property name="text">
+          <string>Function</string>
+         </property>
+        </widget>
+       </item>
+       <item row="2" column="1">
+        <widget class="QComboBox" name="functionComboBox">
+         <item>
+          <property name="text">
+           <string>PIC</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>SIC</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>DUAL</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>INSTRUCTOR</string>
+          </property>
+         </item>
+        </widget>
+       </item>
+       <item row="3" column="0">
+        <widget class="QLabel" name="rulesLabel">
+         <property name="text">
+          <string>Flight Rules</string>
+         </property>
+        </widget>
+       </item>
+       <item row="3" column="1">
+        <widget class="QComboBox" name="rulesComboBox">
+         <item>
+          <property name="text">
+           <string>VFR</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>IFR</string>
+          </property>
+         </item>
+        </widget>
+       </item>
+       <item row="4" column="0">
+        <widget class="QLabel" name="approachLabel">
+         <property name="text">
+          <string>Approach</string>
+         </property>
+        </widget>
+       </item>
+       <item row="4" column="1">
+        <widget class="QComboBox" name="approachComboBox">
+         <item>
+          <property name="text">
+           <string>VISUAL</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>ILS CAT I</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>ILS CAT II</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>ILS CAT III</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>GLS</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>MLS</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>LOC</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>LOC/DME</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>RNAV</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>RNAV (LNAV)</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>RNAV (LNAV/VNAV)</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>RNAV (LPV)</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>RNAV (RNP)</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>RNAV (RNP-AR)</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>VOR</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>VOR/DME</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>NDB</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>NDB/DME</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>TACAN</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>SRA</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>PAR</string>
+          </property>
+         </item>
+        </widget>
+       </item>
+       <item row="5" column="0">
+        <widget class="QLabel" name="nightLabel">
+         <property name="text">
+          <string>Night Time</string>
+         </property>
+        </widget>
+       </item>
+       <item row="5" column="1">
+        <widget class="QComboBox" name="nightComboBox">
+         <item>
+          <property name="text">
+           <string>NO</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>YES (EASA)</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>YES (SR/SS)</string>
+          </property>
+         </item>
+        </widget>
+       </item>
+       <item row="6" column="0">
+        <widget class="QLabel" name="prefixLabel">
+         <property name="text">
+          <string>Airline Prefix</string>
+         </property>
+        </widget>
+       </item>
+       <item row="6" column="1">
+        <widget class="QLineEdit" name="prefixLineEdit">
+         <property name="maxLength">
+          <number>10</number>
+         </property>
+         <property name="placeholderText">
+          <string>optional</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </widget>
+     <widget class="QWidget" name="tab_3">
+      <attribute name="title">
+       <string>Finish</string>
+      </attribute>
+      <layout class="QGridLayout" name="gridLayout_4">
+       <item row="0" column="0" colspan="2">
+        <widget class="QLabel" name="label_4">
+         <property name="text">
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:16pt;&quot;&gt;Finish&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;br/&gt;Almost done! Here you can select the theme to be used for the application.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+         </property>
+         <property name="textFormat">
+          <enum>Qt::RichText</enum>
+         </property>
+         <property name="wordWrap">
+          <bool>true</bool>
+         </property>
+        </widget>
+       </item>
+       <item row="1" column="0">
+        <widget class="QLabel" name="themeLabel">
+         <property name="text">
+          <string>Theme</string>
+         </property>
+        </widget>
+       </item>
+       <item row="1" column="1">
+        <widget class="QCheckBox" name="systemThemeCheckBox">
+         <property name="text">
+          <string>System Theme</string>
+         </property>
+        </widget>
+       </item>
+       <item row="2" column="1">
+        <widget class="QCheckBox" name="lightThemeCheckBox">
+         <property name="text">
+          <string>Light Theme</string>
+         </property>
+        </widget>
+       </item>
+       <item row="3" column="1">
+        <widget class="QCheckBox" name="darkThemeCheckBox">
+         <property name="text">
+          <string>Dark Theme</string>
+         </property>
+        </widget>
+       </item>
+       <item row="4" column="0" colspan="2">
+        <widget class="QPushButton" name="finishButton">
+         <property name="minimumSize">
+          <size>
+           <width>0</width>
+           <height>60</height>
+          </size>
+         </property>
+         <property name="styleSheet">
+          <string notr="true">background-color:rgb(78, 154, 6)</string>
+         </property>
+         <property name="text">
+          <string>Finish Setup</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </widget>
+    </widget>
+   </item>
+   <item row="1" column="0">
+    <widget class="QPushButton" name="previousPushButton">
+     <property name="text">
+      <string>Previous</string>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="1">
+    <widget class="QPushButton" name="nextPushButton">
+     <property name="text">
+      <string>Next</string>
+     </property>
+    </widget>
+   </item>
+  </layout>
  </widget>
+ <tabstops>
+  <tabstop>piclastnameLineEdit</tabstop>
+  <tabstop>picfirstnameLineEdit</tabstop>
+  <tabstop>employeeidLineEdit</tabstop>
+  <tabstop>emailLineEdit</tabstop>
+  <tabstop>phoneLineEdit</tabstop>
+  <tabstop>previousPushButton</tabstop>
+  <tabstop>nextPushButton</tabstop>
+  <tabstop>aliasComboBox</tabstop>
+  <tabstop>functionComboBox</tabstop>
+  <tabstop>rulesComboBox</tabstop>
+  <tabstop>approachComboBox</tabstop>
+  <tabstop>nightComboBox</tabstop>
+  <tabstop>prefixLineEdit</tabstop>
+  <tabstop>systemThemeCheckBox</tabstop>
+  <tabstop>lightThemeCheckBox</tabstop>
+  <tabstop>darkThemeCheckBox</tabstop>
+  <tabstop>finishButton</tabstop>
+  <tabstop>tabWidget</tabstop>
+ </tabstops>
  <resources/>
  <connections/>
 </ui>

+ 2 - 3
src/gui/widgets/homewidget.cpp

@@ -38,9 +38,8 @@ HomeWidget::~HomeWidget()
 
 void HomeWidget::on_pushButton_clicked()
 {
-    auto pl = new Pilot("pilots", 498);
-    auto np = new NewPilot(*pl, Db::editExisting, this);
-    np->show();
+    FirstRunDialog dialog;
+    dialog.exec();
 }
 
 void HomeWidget::showTotals()

+ 1 - 0
src/gui/widgets/homewidget.h

@@ -31,6 +31,7 @@
 #include "src/gui/dialogues/newpilot.h"
 #include "src/database/entry.h"
 #include "src/gui/widgets/totalswidget.h"
+#include "src/gui/dialogues/firstrundialog.h"
 
 
 namespace Ui {

+ 1 - 0
src/gui/widgets/pilotswidget.cpp

@@ -42,6 +42,7 @@ PilotsWidget::PilotsWidget(QWidget *parent) :
 
     QSqlTableModel *model = new QSqlTableModel;
     model->setTable("viewPilots");
+    model->setFilter("ID > 1");//to not allow editing of self, shall be done via settings
     model->select();
 
     QTableView *view = ui->tableView;

+ 2 - 2
src/gui/widgets/settingswidget.cpp

@@ -53,7 +53,7 @@ SettingsWidget::SettingsWidget(QWidget *parent) :
      * Flight Logging Tab
      */
     //QString storedPrefix = db::singleSelect("setting","settings","setting_id","50",sql::exactMatch);
-    QString storedPrefix = settings.value("userdata/flightnumberPrefix").toString();
+    QString storedPrefix = settings.value("flightlogging/flightnumberPrefix").toString();
     if (storedPrefix.length() != 0) {
         ui->flightNumberPrefixLineEdit->setText(storedPrefix);
     }
@@ -80,7 +80,7 @@ SettingsWidget::~SettingsWidget()
 void SettingsWidget::on_flightNumberPrefixLineEdit_textEdited(const QString &arg1)
 {
     QSettings settings;
-    settings.setValue("userdata/flightnumberPrefix", arg1);
+    settings.setValue("flightlogging/flightnumberPrefix", arg1);
 }
 
 void SettingsWidget::themeGroup_toggled(int id)