瀏覽代碼

Added stub database entry for previous exp, airport, acft and pilot

Felix Turowsky 1 年之前
父節點
當前提交
c8da304f36
共有 4 個文件被更改,包括 84 次插入39 次删除
  1. 1 0
      src/database/database.cpp
  2. 62 38
      src/gui/widgets/totalswidget.cpp
  3. 2 1
      src/gui/widgets/totalswidget.h
  4. 19 0
      src/opl.h

+ 1 - 0
src/database/database.cpp

@@ -386,6 +386,7 @@ bool Database::insert(const OPL::Row &new_row)
     } else {
         DEB << "Unable to commit.";
         DEB << "Query: " << statement;
+        DEB << "Bound Values: " << query.boundValues();
         DEB << "Query Error: " << query.lastError().text();
         lastError = query.lastError();
         return false;

+ 62 - 38
src/gui/widgets/totalswidget.cpp

@@ -20,6 +20,50 @@ TotalsWidget::~TotalsWidget()
     delete ui;
 }
 
+/*!
+ * \brief TotalsWidget::setup Sets the line edits as editable or read-only and connects signals if required
+ * \details This widget can be used to either display the totals (in the home widget) or
+ * to edit the total previous experience, from previous logbooks (in the settings widget).
+ */
+void TotalsWidget::setup(const WidgetType widgetType)
+{
+    const QList<QLineEdit *> lineEdits = this->findChildren<QLineEdit *>();
+
+    switch (widgetType) {
+    case TotalTimeWidget:
+        LOG << "Setting up totals widget";
+        // disable editing
+        for (const auto &lineEdit : lineEdits) {
+            lineEdit->setFocusPolicy(Qt::FocusPolicy::NoFocus);
+        }
+        // populate the UI
+        fillTotals(widgetType);
+        break;
+    case PreviousExperienceWidget:
+        LOG << "Setting up previous XP widget";
+        for (const auto &lineEdit : lineEdits) {
+            lineEdit->setFocusPolicy(Qt::FocusPolicy::StrongFocus);
+            // set a validator for the TO/LDG line edits, the other ones get validated seperately
+            if(lineEdit->objectName().contains(QLatin1String("to")) || lineEdit->objectName().contains(QLatin1String("ldg"))) {
+                lineEdit->setValidator( new QIntValidator(0,  std::numeric_limits<int>::max(), this) );
+            }
+        }
+        // initialise m_rowData
+        m_rowData = DB->getRowData(OPL::DbTable::Flights, TOTALS_DATA_ROW_ID);
+        // DB returns empty object if no entry exists. Crate a stub to prepare for user data
+        if(m_rowData == OPL::RowData_T()) {
+            fillStubData();
+        }
+
+        // populate the UI
+        fillTotals(widgetType);
+        connectSignalsAndSlots();
+        break;
+    default:
+        break;
+    }
+}
+
 /*!
  * \brief HomeWidget::fillTotals Retreives a Database Summary of Total Flight Time via the OPL::Statistics::totals
  * function and parses the return to fill out the QLineEdits.
@@ -35,7 +79,6 @@ void TotalsWidget::fillTotals(const WidgetType widgetType)
         break;
     case PreviousExperienceWidget:
         time_data = DB->getRowData(OPL::DbTable::Flights, TOTALS_DATA_ROW_ID);
-        DEB << time_data;
     }
 
     // fill the line edits with the data obtained
@@ -51,7 +94,7 @@ void TotalsWidget::fillTotals(const WidgetType widgetType)
                 // line edits for take offs and landings
                 line_edit->setText(field.toString());
             } else {
-                // line edits for total times
+                // line edits for total time
                 const QString time_string = OPL::Time::toString(field.toInt());
                 line_edit->setText(time_string);
             }
@@ -60,44 +103,25 @@ void TotalsWidget::fillTotals(const WidgetType widgetType)
     }
 }
 
-/*!
- * \brief TotalsWidget::setup Sets the line edits as editable or read-only and connects signals if required
- * \details This widget can be used to either display the totals (in the home widget) or
- * to edit the total previous experience, from previous logbooks (in the settings widget).
+/**
+ * @brief TotalsWidget::fillStubData Fills the row entry object with stub data if it is empty.
+ * \details The Widget retreives previous experience from the database. If the user has not entered
+ * any previous experience this database entry does not exist. The database returns an empty
+ * row object in this case. In order for the user to be able to fill in the previous experience,
+ * a stub entry has to be created to fulfill the databases NOT NULL constrains.
  */
-void TotalsWidget::setup(const WidgetType widgetType)
+void TotalsWidget::fillStubData()
 {
-    const QList<QLineEdit *> lineEdits = this->findChildren<QLineEdit *>();
-
-    switch (widgetType) {
-    case TotalTimeWidget:
-        LOG << "Setting up totals widget";
-        // disable editing
-        for (const auto &lineEdit : lineEdits) {
-            lineEdit->setFocusPolicy(Qt::FocusPolicy::NoFocus);
-        }
-        // populate the UI
-        fillTotals(widgetType);
-        break;
-    case PreviousExperienceWidget:
-        LOG << "Setting up previous XP widget";
-        for (const auto &lineEdit : lineEdits) {
-            lineEdit->setFocusPolicy(Qt::FocusPolicy::StrongFocus);
-            // set a validator for the TO/LDG line edits, the other ones get validated seperately
-            if(lineEdit->objectName().contains(QLatin1String("to")) || lineEdit->objectName().contains(QLatin1String("ldg"))) {
-                lineEdit->setValidator( new QIntValidator(0,  std::numeric_limits<int>::max(), this) );
-            }
-        }
-        // initialise m_rowData
-        m_rowData = DB->getRowData(OPL::DbTable::Flights, TOTALS_DATA_ROW_ID);
-
-        // populate the UI
-        fillTotals(widgetType);
-        connectSignalsAndSlots();
-        break;
-    default:
-        break;
-    }
+    m_rowData.insert(OPL::Db::FLIGHTS_ROWID, OPL::STUB_ROW_ID);
+    m_rowData.insert(OPL::Db::FLIGHTS_DOFT, OPL::STUB_ISO_DATE);
+    m_rowData.insert(OPL::Db::FLIGHTS_TOFB, 0);
+    m_rowData.insert(OPL::Db::FLIGHTS_TONB, 0);
+    m_rowData.insert(OPL::Db::FLIGHTS_TBLK, 0);
+    m_rowData.insert(OPL::Db::FLIGHTS_DEPT, OPL::STUB_AIRPORT_CODE);
+    m_rowData.insert(OPL::Db::FLIGHTS_DEST, OPL::STUB_AIRPORT_CODE);
+    m_rowData.insert(OPL::Db::FLIGHTS_PIC, OPL::STUB_ROW_ID);
+    m_rowData.insert(OPL::Db::FLIGHTS_ACFT, OPL::STUB_ROW_ID);
+    DEB << m_rowData;
 }
 
 /*!

+ 2 - 1
src/gui/widgets/totalswidget.h

@@ -28,9 +28,10 @@ private:
      * \brief m_rowData holds the data displayed in the line edits
      */
     OPL::RowData_T m_rowData;
-    const static int TOTALS_DATA_ROW_ID = 1;
+    const static int TOTALS_DATA_ROW_ID = OPL::STUB_ROW_ID;
 
     void fillTotals(const WidgetType widgetType);
+    void fillStubData();
     void setup(const WidgetType widgetType);
     void connectSignalsAndSlots();
     bool verifyUserTimeInput(QLineEdit *line_edit, const TimeInput &input);

+ 19 - 0
src/opl.h

@@ -67,6 +67,25 @@ namespace OPL {
 #define WARN(msg) OPL::ANotificationHandler::warn(msg, this)  // Use for warnings (will be displayed in GUI)
 #define CRIT(msg) OPL::ANotificationHandler::crit(msg, this)  // Use for critical warnings (will be displayed in GUI)
 
+/**
+ * @brief Defines the row ID for non-user entries in the database;
+ */
+const static int STUB_ROW_ID = -1;
+
+/**
+ * @brief Defines a four-letter code for a non-extistent (dummy) airport: "XXXX"
+ */
+const static char* STUB_AIRPORT_CODE = "XXXX";
+/**
+ * @brief Defines a registration for a non-existent (dummy) aircraft: "XX-XXX"
+ */
+const static char* STUB_AIRCRAFT_REG = "XX-XXX";
+
+/**
+ * @brief Defines a dummy date in the ISO date format: "1900-01-01"
+ */
+const static char* STUB_ISO_DATE = "1900-01-01";
+
 /*!
  * \brief The ANotificationHandler class handles displaying of user-directed messages. It displays
  * information to the user in a QMessageBox and forwards the displayed message to ALog so it is written