浏览代码

Database update, Entry class removed

ACurrencyEntry and AEntry removed as the last remaining pieces of the old DB Interface. 

Adjustments on how to handle currency entries. Those are now handled just like any other database entry on the DB Interface side.
Felix Turo 2 年之前
父节点
当前提交
3d46df9c4c

+ 0 - 2
CMakeLists.txt

@@ -82,8 +82,6 @@ set(PROJECT_SOURCES
     src/classes/row.cpp
     src/classes/acompletiondata.h
     src/classes/acompletiondata.cpp
-    src/classes/acurrencyentry.h
-    src/classes/acurrencyentry.cpp
     src/classes/astyle.h
     src/classes/astyle.cpp
     src/classes/astandardpaths.h

+ 0 - 1
assets/database/database_schema.md5

@@ -1 +0,0 @@
-c71c34d120dbc8fe7186c303d5cfb6bb  database_schema.sql

+ 2 - 2
assets/database/database_schema.sql

@@ -93,7 +93,7 @@ CREATE TABLE IF NOT EXISTS 'airports' (
 DROP TABLE IF EXISTS 'currencies';
 CREATE TABLE IF NOT EXISTS 'currencies' (
 	'currency_id'	INTEGER NOT NULL,
-	'description'	TEXT,
+	'currencyName'	TEXT,
 	'expiryDate'	NUMERIC,
 	PRIMARY KEY('currency_id' AUTOINCREMENT)
 );
@@ -285,4 +285,4 @@ CAST(SUM(toDay) AS INT) AS 'TO Day',
 CAST(SUM(toNight) AS INT) AS 'TO Night',  
 CAST(SUM(ldgDay) AS INT) AS 'LDG Day', 
 CAST(SUM(ldgNight) AS INT) AS 'LDG Night'  
-FROM flights
+FROM flights

+ 7 - 2
assets/database/templates/changelog.json

@@ -30,8 +30,8 @@
         "revision": 6
     },
     {
-        "comment": "\"Added autoincrement for flights",
-        "date": " pilots and tails tables\"",
+        "comment": "Added autoincrement for flights pilots and tails tables",
+        "date": "2020-11-21",
         "revision": 7
     },
     {
@@ -83,5 +83,10 @@
         "comment": "Added currencies table",
         "date": "2021-02-12",
         "revision": 17
+    },
+    {
+        "comment": "Revised currencies table column names",
+        "date": "2022-07-10",
+        "revision": 17
     }
 ]

+ 1 - 1
assets/database/templates/changelog.md5

@@ -1 +1 @@
-d7e78defe6401569eddf45592da9acc2  changelog.json
+0d31231993099ea01b5f50b528702c50  changelog.json

+ 6 - 6
assets/database/templates/currencies.json

@@ -1,32 +1,32 @@
 [
     {
         "currency_id": 1,
-        "description": "Licence",
+        "currencyName": "Licence",
         "expiryDate": null
     },
     {
         "currency_id": 2,
-        "description": "Type Rating",
+        "currencyName": "Type Rating",
         "expiryDate": null
     },
     {
         "currency_id": 3,
-        "description": "Line Check",
+        "currencyName": "Line Check",
         "expiryDate": null
     },
     {
         "currency_id": 4,
-        "description": "Medical",
+        "currencyName": "Medical",
         "expiryDate": null
     },
     {
         "currency_id": 5,
-        "description": "Custom1",
+        "currencyName": "Custom1",
         "expiryDate": null
     },
     {
         "currency_id": 6,
-        "description": "Custom2",
+        "currencyName": "Custom2",
         "expiryDate": null
     }
 ]

+ 1 - 1
assets/database/templates/currencies.md5

@@ -1 +1 @@
-65dcce8e3df9bcc8681edd746774f6d6  currencies.json
+f89063deb0b19c09b567abdbe74d3e46  currencies.json

+ 0 - 0
src/classes/acurrencyentry.cpp → deprecated/acurrencyentry.cpp


+ 0 - 0
src/classes/acurrencyentry.h → deprecated/acurrencyentry.h


+ 15 - 3
src/classes/row.cpp

@@ -21,12 +21,12 @@ Row::Row(OPL::DbTable table_name, int row_id, const RowData_T &row_data)
     hasData = true;
 };
 
-RowData_T Row::getRowData() const
+RowData_T Row::getData() const
 {
     return rowData;
 }
 
-void Row::setRowData(const RowData_T &value)
+void Row::setData(const RowData_T &value)
 {
     rowData = value;
     hasData = true;
@@ -42,7 +42,7 @@ void Row::setRowId(int value)
     rowId = value;
 }
 
-OPL::DbTable Row::getTable() const
+OPL::DbTable Row::getTableName() const
 {
     return table;
 }
@@ -155,4 +155,16 @@ FlightEntry::FlightEntry(int row_id, const RowData_T &row_data)
     : Row(DbTable::Flights, row_id, row_data)
 {}
 
+CurrencyEntry::CurrencyEntry()
+    : Row(DbTable::Currencies, 0)
+{}
+
+CurrencyEntry::CurrencyEntry(const RowData_T &row_data)
+    : Row(DbTable::Currencies, 0, row_data)
+{}
+
+CurrencyEntry::CurrencyEntry(int row_id, const RowData_T &row_data)
+    : Row(DbTable::Currencies, row_id, row_data)
+{}
+
 } // namespace OPL

+ 10 - 6
src/classes/row.h

@@ -19,11 +19,11 @@ public:
     Row(const Row&) = default;
     Row& operator=(const Row&) = default;
 
-    RowData_T getRowData() const;
-    void setRowData(const RowData_T &value);
+    RowData_T getData() const;
+    void setData(const RowData_T &value);
     int getRowId() const;
     void setRowId(int value);
-    OPL::DbTable getTable() const;
+    OPL::DbTable getTableName() const;
 
     bool isValid() const {return hasData && valid;}
 
@@ -40,7 +40,6 @@ protected:
     bool valid = true;
 };
 
-
 class AircraftEntry : public Row
 {
 public:
@@ -49,7 +48,6 @@ public:
     AircraftEntry(int row_id, const RowData_T &row_data);
 };
 
-
 class TailEntry : public Row
 {
 public:
@@ -61,7 +59,6 @@ public:
     const QString type() const;
 };
 
-
 class PilotEntry : public Row
 {
 public:
@@ -85,7 +82,14 @@ public:
     FlightEntry();
     FlightEntry(const RowData_T &row_data);
     FlightEntry(int row_id, const RowData_T &row_data);
+};
 
+class CurrencyEntry : public Row
+{
+public:
+    CurrencyEntry();
+    CurrencyEntry(const RowData_T &row_data);
+    CurrencyEntry(int row_id, const RowData_T &row_data);
 };
 
 } // namespace OPL

+ 50 - 215
src/database/adatabase.cpp

@@ -255,14 +255,14 @@ QSqlDatabase ADatabase::database()
     return QSqlDatabase::database(QStringLiteral("qt_sql_default_connection"));
 }
 
-bool ADatabase::commit(const AEntry &entry)
-{
-    if (exists(entry)) {
-        return update(entry);
-    } else {
-        return insert(entry);
-    }
-}
+//bool ADatabase::commit(const AEntry &entry)
+//{
+//    if (exists(entry)) {
+//        return update(entry);
+//    } else {
+//        return insert(entry);
+//    }
+//}
 
 bool ADatabase::commit(const OPL::Row &row)
 {
@@ -312,33 +312,33 @@ bool ADatabase::commit(const QJsonArray &json_arr, const QString &table_name)
         return false;
 }
 
-bool ADatabase::remove(const AEntry &entry)
-{
-    if (!exists(entry)) {
-        LOG << "Error: Database entry not found.";
-        return false;
-    }
-
-    QString statement = QLatin1String("DELETE FROM ") + entry.getPosition().tableName
-            + QLatin1String(" WHERE ROWID=?");
-
-    QSqlQuery query;
-    query.prepare(statement);
-    query.addBindValue(entry.getPosition().rowId);
-
-    if (query.exec())
-    {
-        LOG << "Entry " << entry.getPosition() << " removed.";
-        emit dataBaseUpdated();
-        return true;
-    } else {
-        DEB << "Unable to delete.";
-        DEB << "Query: " << statement;
-        DEB << "Query Error: " << query.lastError().text();
-        lastError = query.lastError();
-        return false;
-    }
-}
+//bool ADatabase::remove(const AEntry &entry)
+//{
+//    if (!exists(entry)) {
+//        LOG << "Error: Database entry not found.";
+//        return false;
+//    }
+//
+//    QString statement = QLatin1String("DELETE FROM ") + entry.getPosition().tableName
+//            + QLatin1String(" WHERE ROWID=?");
+//
+//    QSqlQuery query;
+//    query.prepare(statement);
+//    query.addBindValue(entry.getPosition().rowId);
+//
+//    if (query.exec())
+//    {
+//        LOG << "Entry " << entry.getPosition() << " removed.";
+//        emit dataBaseUpdated();
+//        return true;
+//    } else {
+//        DEB << "Unable to delete.";
+//        DEB << "Query: " << statement;
+//        DEB << "Query Error: " << query.lastError().text();
+//        lastError = query.lastError();
+//        return false;
+//    }
+//}
 
 bool ADatabase::remove(const OPL::Row &row)
 {
@@ -347,7 +347,7 @@ bool ADatabase::remove(const OPL::Row &row)
         return false;
     }
 
-    QString statement = QLatin1String("DELETE FROM ") + OPL::GLOBALS->getDbTableName(row.getTable())
+    QString statement = QLatin1String("DELETE FROM ") + OPL::GLOBALS->getDbTableName(row.getTableName())
             + QLatin1String(" WHERE ROWID=?");
 
     QSqlQuery query;
@@ -369,14 +369,14 @@ bool ADatabase::remove(const OPL::Row &row)
     }
 }
 
-bool ADatabase::removeMany(const QList<DataPosition> &data_position_list)
+bool ADatabase::removeMany(const QList<DataPosition> &position_list)
 {
     int errorCount = 0;
     QSqlQuery query;
     query.prepare(QStringLiteral("BEGIN EXCLUSIVE TRANSACTION"));
     query.exec();
 
-    for (const auto& data_position : data_position_list) {
+    for (const auto& data_position : position_list) {
         if (!exists(data_position)) {
             errorCount++;
         }
@@ -412,36 +412,7 @@ bool ADatabase::removeMany(const QList<DataPosition> &data_position_list)
     }
 }
 
-bool ADatabase::exists(const AEntry &entry)
-{
-    if(entry.getPosition().rowId == 0)
-        return false;
-
-    //Check database for row id
-    QString statement = QLatin1String("SELECT COUNT(*) FROM ") + entry.getPosition().tableName
-            + QLatin1String(" WHERE ROWID=?");
-    QSqlQuery query;
-    query.prepare(statement);
-    query.addBindValue(entry.getPosition().rowId);
-    query.setForwardOnly(true);
-    query.exec();
-    //this returns either 1 or 0 since row ids are unique
-    if (!query.isActive()) {
-        lastError = query.lastError();
-        DEB << "Query Error: " << query.lastError().text() << statement;
-        return false;
-    }
-    query.next();
-    int rowId = query.value(0).toInt();
-    if (rowId) {
-        return true;
-    } else {
-        LOG << "Database entry not found.";
-        return false;
-    }
-}
-
-bool ADatabase::exists(DataPosition data_position)
+bool ADatabase::exists(const DataPosition &data_position)
 {
     if(data_position.rowId == 0)
         return false;
@@ -475,7 +446,7 @@ bool ADatabase::exists(const OPL::Row &row)
         return false;
 
     //Check database for row id
-    QString statement = QLatin1String("SELECT COUNT(*) FROM ") + OPL::GLOBALS->getDbTableName(row.getTable())
+    QString statement = QLatin1String("SELECT COUNT(*) FROM ") + OPL::GLOBALS->getDbTableName(row.getTableName())
             + QLatin1String(" WHERE ROWID=?");
     QSqlQuery query;
     query.prepare(statement);
@@ -513,53 +484,18 @@ bool ADatabase::clear()
     return true;
 }
 
-
-bool ADatabase::update(const AEntry &updated_entry)
-{
-    auto data = updated_entry.getData();
-    QString statement = QLatin1String("UPDATE ") + updated_entry.getPosition().tableName + QLatin1String(" SET ");
-    RowData_T::const_iterator i;
-    for (i = data.constBegin(); i != data.constEnd(); ++i) {
-        statement.append(i.key() + "=?,");
-    }
-    statement.chop(1);
-    statement.append(QLatin1String(" WHERE ROWID=?"));
-    QSqlQuery query;
-    query.prepare(statement);
-    for (i = data.constBegin(); i != data.constEnd(); ++i) {
-        if (i.value() == QVariant(QString()) || i.value() == 0) {
-            query.addBindValue(QVariant(QVariant::String));
-        } else {
-            query.addBindValue(i.value());
-        }
-    }
-    query.addBindValue(updated_entry.getPosition().rowId);
-
-    if (query.exec())
-    {
-        DEB << "Entry successfully committed.";
-        emit dataBaseUpdated();
-        return true;
-    } else {
-        DEB << "Unable to commit.";
-        DEB << "Query: " << statement;
-        DEB << "Query Error: " << query.lastError().text();
-        lastError = query.lastError();
-        return false;
-    }
-}
-
 bool ADatabase::update(const OPL::Row &updated_row)
 {
-    QString statement = QLatin1String("UPDATE ") + OPL::GLOBALS->getDbTableName(updated_row.getTable()) + QLatin1String(" SET ");
-    for (auto i = updated_row.getRowData().constBegin(); i != updated_row.getRowData().constEnd(); ++i) {
+    QString statement = QLatin1String("UPDATE ") + OPL::GLOBALS->getDbTableName(updated_row.getTableName()) + QLatin1String(" SET ");
+    for (auto i = updated_row.getData().constBegin(); i != updated_row.getData().constEnd(); ++i) {
         statement.append(i.key() + "=?,");
     }
     statement.chop(1);
     statement.append(QLatin1String(" WHERE ROWID=?"));
     QSqlQuery query;
     query.prepare(statement);
-    for (auto i = updated_row.getRowData().constBegin(); i != updated_row.getRowData().constEnd(); ++i) {
+    DEB << "Statement: " << statement;
+    for (auto i = updated_row.getData().constBegin(); i != updated_row.getData().constEnd(); ++i) {
         if (i.value() == QVariant(QString()) || i.value() == 0) {
             query.addBindValue(QVariant(QVariant::String));
         } else {
@@ -567,6 +503,7 @@ bool ADatabase::update(const OPL::Row &updated_row)
         }
     }
     query.addBindValue(updated_row.getRowId());
+    DEB << "Bound values: " << query.boundValues();
 
     if (query.exec())
     {
@@ -582,59 +519,17 @@ bool ADatabase::update(const OPL::Row &updated_row)
     }
 }
 
-bool ADatabase::insert(const AEntry &new_entry)
-{
-    QString statement = QLatin1String("INSERT INTO ") + new_entry.getTableName() + QLatin1String(" (");
-    RowData_T::const_iterator i;
-    for (auto i = new_entry.getData().constBegin(); i != new_entry.getData().constEnd(); ++i) {
-        statement.append(i.key() + QLatin1Char(','));
-    }
-    statement.chop(1);
-    statement += QLatin1String(") VALUES (");
-
-    for (int i=0; i < new_entry.getData().size(); ++i) {
-        statement += QLatin1String("?,");
-    }
-    statement.chop(1);
-    statement += QLatin1Char(')');
-
-    QSqlQuery query;
-    query.prepare(statement);
-
-    for (i = new_entry.getData().constBegin(); i != new_entry.getData().constEnd(); ++i) {
-        if (i.value() == QVariant(QString()) || i.value() == 0) {
-            query.addBindValue(QVariant(QVariant::String));
-        } else {
-            query.addBindValue(i.value());
-        }
-    }
-
-    //check result.
-    if (query.exec())
-    {
-        DEB << "Entry successfully committed.";
-        emit dataBaseUpdated();
-        return true;
-    } else {
-        DEB << "Unable to commit.";
-        DEB << "Query: " << statement;
-        DEB << "Query Error: " << query.lastError().text();
-        lastError = query.lastError();
-        return false;
-    }
-}
-
 bool ADatabase::insert(const OPL::Row &new_row)
 {
-    QString statement = QLatin1String("INSERT INTO ") + OPL::GLOBALS->getDbTableName(new_row.getTable()) + QLatin1String(" (");
+    QString statement = QLatin1String("INSERT INTO ") + OPL::GLOBALS->getDbTableName(new_row.getTableName()) + QLatin1String(" (");
     QHash<QString, QVariant>::const_iterator i;
-    for (i = new_row.getRowData().constBegin(); i != new_row.getRowData().constEnd(); ++i) {
+    for (i = new_row.getData().constBegin(); i != new_row.getData().constEnd(); ++i) {
         statement.append(i.key() + QLatin1Char(','));
     }
     statement.chop(1);
     statement += QLatin1String(") VALUES (");
 
-    for (int i=0; i < new_row.getRowData().size(); ++i) {
+    for (int i=0; i < new_row.getData().size(); ++i) {
         statement += QLatin1String("?,");
     }
     statement.chop(1);
@@ -643,7 +538,7 @@ bool ADatabase::insert(const OPL::Row &new_row)
     QSqlQuery query;
     query.prepare(statement);
 
-    for (i = new_row.getRowData().constBegin(); i != new_row.getRowData().constEnd(); ++i) {
+    for (i = new_row.getData().constBegin(); i != new_row.getData().constEnd(); ++i) {
         if (i.value() == QVariant(QString()) || i.value() == 0) {
             query.addBindValue(QVariant(QVariant::String));
         } else {
@@ -723,13 +618,6 @@ RowData_T ADatabase::getEntryData(const DataPosition &data_position)
     return entry_data;
 }
 
-AEntry ADatabase::getEntry(const DataPosition &data_position)
-{
-    AEntry entry(data_position);
-    entry.setData(getEntryData(data_position));
-    return entry;
-}
-
 OPL::Row ADatabase::getRow(const OPL::DbTable table, const int row_id)
 {
     QString statement = QLatin1String("SELECT * FROM ") + OPL::GLOBALS->getDbTableName(table)
@@ -794,48 +682,6 @@ RowData_T ADatabase::getRowData(const OPL::DbTable table, const int row_id)
     return entry_data;
 }
 
-//OPL::PilotEntry ADatabase::getPilotEntry(RowId_T row_id)
-//{
-//    APilotEntry pilot_entry(row_id);
-//    pilot_entry.setData(getEntryData(pilot_entry.getPosition()));
-//    return pilot_entry;
-//}
-
-//OPL::TailEntry ADatabase::getTailEntry(RowId_T row_id)
-//{
-//    ATailEntry tail_entry(row_id);
-//    tail_entry.setData(getEntryData(tail_entry.getPosition()));
-//    return tail_entry;
-//}
-
-//OPL::AircraftEntry ADatabase::getAircraftEntry(RowId_T row_id)
-//{
-//    AAircraftEntry aircraft_entry(row_id);
-//    aircraft_entry.setData(getEntryData(aircraft_entry.getPosition()));
-//    return aircraft_entry;
-//}
-
-//AFlightEntry ADatabase::getFlightEntry(RowId_T row_id)
-//{
-//    AFlightEntry flight_entry(row_id);
-//    flight_entry.setData(getEntryData(flight_entry.getPosition()));
-//    return flight_entry;
-//}
-
-//ASimulatorEntry ADatabase::getSimEntry(RowId_T row_id)
-//{
-//    ASimulatorEntry sim_entry(row_id);
-//    sim_entry.setData(getEntryData(sim_entry.getPosition()));
-//    return sim_entry;
-//}
-
-ACurrencyEntry ADatabase::getCurrencyEntry(const ACurrencyEntry::CurrencyName &currency_name)
-{
-    ACurrencyEntry currency_entry(currency_name);
-    currency_entry.setData(getEntryData(currency_entry.getPosition()));
-    return currency_entry;
-}
-
 const QStringList ADatabase::getCompletionList(ADatabaseTarget target)
 {
     QString statement;
@@ -884,8 +730,7 @@ const QStringList ADatabase::getCompletionList(ADatabaseTarget target)
     return completer_list;
 }
 
-const
-QHash<RowId_T, QString> ADatabase::getIdMap(ADatabaseTarget target)
+const QHash<RowId_T, QString> ADatabase::getIdMap(ADatabaseTarget target)
 {
     QString statement;
 
@@ -997,16 +842,6 @@ QList<RowId_T> ADatabase::getForeignKeyConstraints(RowId_T foreign_row_id, AData
     return row_ids;
 }
 
-//APilotEntry ADatabase::resolveForeignPilot(RowId_T foreign_key)
-//{
-//    return aDB->getPilotEntry(foreign_key);
-//}
-
-//ATailEntry ADatabase::resolveForeignTail(RowId_T foreign_key)
-//{
-//    return aDB->getTailEntry(foreign_key);
-//}
-
 QVector<QVariant> ADatabase::customQuery(QString statement, int return_values)
 {
     QSqlQuery query(statement);

+ 18 - 33
src/database/adatabase.h

@@ -35,7 +35,6 @@
 #include "src/classes/row.h"
 
 #include "src/classes/astandardpaths.h"
-#include "src/classes/acurrencyentry.h"
 
 #define SQLITE_DRIVER QStringLiteral("QSQLITE")
 
@@ -245,10 +244,8 @@ public:
     /*!
      * \brief Checks if an entry exists in the database, based on position data
      */
-    bool exists(const AEntry &entry);
-    bool exists(DataPosition data_position);
-
     bool exists(const OPL::Row &row);
+    bool exists(const DataPosition &position);
 
     /*!
      * \brief clear resets the database, i.e. deletes all content in the tables containing
@@ -260,8 +257,6 @@ public:
      * \brief commits an entry to the database, calls either insert or update,
      * based on position data
      */
-    bool commit(const AEntry &entry);
-
     bool commit(const OPL::Row &row);
 
     /*!
@@ -274,21 +269,21 @@ public:
     /*!
      * \brief Create new entry in the databse based on UserInput
      */
-    bool insert(const AEntry &new_entry);
+    //bool insert(const AEntry &new_entry);
 
     bool insert(const OPL::Row &new_row);
 
     /*!
      * \brief Updates entry in database from existing entry tweaked by the user.
      */
-    bool update(const AEntry &updated_entry);
+    //bool update(const AEntry &updated_entry);
 
     bool update(const OPL::Row &updated_row);
 
     /*!
      * \brief deletes an entry from the database.
      */
-    bool remove(const AEntry &entry);
+    //bool remove(const AEntry &entry);
 
     bool remove(const OPL::Row &row);
 
@@ -296,29 +291,27 @@ public:
      * \brief deletes a list of entries from the database. Optimised for speed when
      * deleting many entries.
      */
-    bool removeMany(const QList<DataPosition> &);
+    bool removeMany(const QList<DataPosition> &position_list);
 
     /*!
      * \brief retreive entry data from the database to create an entry object
      */
     RowData_T getEntryData(const DataPosition &data_position);
 
-    /*!
-     * \brief retreive an Entry from the database.
-     */
-    AEntry getEntry(const DataPosition &data_position);
-
     /*!
      * \brief retreive a Row from the database
      */
     OPL::Row getRow(const OPL::DbTable table, const int row_id);
 
+    /*!
+     * \brief retreive a Map of <column name, column content> for a specific row in the database.
+     */
     RowData_T getRowData(const OPL::DbTable table, const int row_id);
 
     /*!
      * \brief retreives a PilotEntry from the database.
      *
-     * This function is a wrapper for DataBase::getEntry(DataPosition),
+     * This function is a wrapper for DataBase::getRowData,
      * where the table is already set and which returns a PilotEntry
      * instead of an Entry. It allows for easy access to a pilot entry
      * with only the RowId required as input.
@@ -332,7 +325,7 @@ public:
     /*!
      * \brief retreives a TailEntry from the database.
      *
-     * This function is a wrapper for DataBase::getEntry(DataPosition),
+     * This function is a wrapper for DataBase::getRowData,
      * where the table is already set and which returns a TailEntry
      * instead of an Entry. It allows for easy access to a tail entry
      * with only the RowId required as input.
@@ -346,7 +339,7 @@ public:
     /*!
      * \brief retreives a TailEntry from the database.
      *
-     * This function is a wrapper for DataBase::getEntry(DataPosition),
+     * This function is a wrapper for DataBase::getRowData,
      * where the table is already set and which returns an AAircraftEntry
      * instead of an AEntry. It allows for easy access to an aircraft entry
      * with only the RowId required as input.
@@ -360,7 +353,7 @@ public:
     /*!
      * \brief retreives a flight entry from the database.
      *
-     * This function is a wrapper for DataBase::getEntry(DataPosition),
+     * This function is a wrapper for DataBase::getRowData,
      * where the table is already set and which returns an AFlightEntry
      * instead of an AEntry. It allows for easy access to a flight entry
      * with only the RowId required as input.
@@ -374,7 +367,7 @@ public:
     /*!
      * \brief retreives a Simulator entry from the database.
      *
-     * This function is a wrapper for DataBase::getEntry(DataPosition),
+     * This function is a wrapper for DataBase::getRowData,
      * where the table is already set and which returns an ASimEntry
      * instead of an AEntry. It allows for easy access to a Simulator entry
      * with only the RowId required as input.
@@ -388,7 +381,11 @@ public:
     /*!
      * \brief Retreives a currency entry from the database.
      */
-    ACurrencyEntry getCurrencyEntry(const ACurrencyEntry::CurrencyName &currency_name);
+    inline OPL::CurrencyEntry getCurrencyEntry(RowId_T row_id)
+    {
+        const auto data = getRowData(OPL::DbTable::Currencies, row_id);
+        return OPL::CurrencyEntry(row_id, data);
+    }
 
     /*!
      * \brief getCompletionList returns a QStringList of values for a
@@ -413,18 +410,6 @@ public:
      */
     QList<RowId_T> getForeignKeyConstraints(RowId_T foreign_row_id, ADatabaseTable target);
 
-    /*!
-     * \brief Resolves the foreign key in a flight entry
-     * \return The Pilot Entry referencted by the foreign key.
-     */
-    //APilotEntry resolveForeignPilot(RowId_T foreign_key);
-
-    /*!
-     * \brief Resolves the foreign key in a flight entry
-     * \return The Tail Entry referencted by the foreign key.
-     */
-    //ATailEntry resolveForeignTail(RowId_T foreign_key);
-
     /*!
      * \brief Return a summary of a database
      * \details Creates a summary of the database giving a quick overview of the relevant contents. The

+ 6 - 6
src/functions/acalc.cpp

@@ -314,10 +314,10 @@ void ACalc::updateAutoTimes(int acft_id)
     DEB << "Updating " << flight_list.length() << " flights with this aircraft.";
 
     auto acft = aDB->getTailEntry(acft_id);
-    auto acft_data = acft.getRowData();
+    auto acft_data = acft.getData();
     for (const auto& item : flight_list) {
         auto flight = aDB->getFlightEntry(item.toInt());
-        auto flight_data = flight.getRowData();
+        auto flight_data = flight.getData();
 
         if(acft_data.value(OPL::Db::TAILS_MULTIPILOT).toInt() == 0
                 && acft_data.value(OPL::Db::TAILS_MULTIENGINE) == 0) {
@@ -326,7 +326,7 @@ void ACalc::updateAutoTimes(int acft_id)
             flight_data.insert(OPL::Db::FLIGHTS_TSPME, QString());
             flight_data.insert(OPL::Db::FLIGHTS_TMP, QString());
         } else if ((acft_data.value(OPL::Db::TAILS_MULTIPILOT) == 0
-                    && acft.getRowData().value(OPL::Db::TAILS_MULTIENGINE) == 1)) {
+                    && acft.getData().value(OPL::Db::TAILS_MULTIENGINE) == 1)) {
             DEB << "SPME";
             flight_data.insert(OPL::Db::FLIGHTS_TSPME, flight_data.value(OPL::Db::FLIGHTS_TBLK));
             flight_data.insert(OPL::Db::FLIGHTS_TSPSE, QString());
@@ -337,7 +337,7 @@ void ACalc::updateAutoTimes(int acft_id)
             flight_data.insert(OPL::Db::FLIGHTS_TSPSE, QString());
             flight_data.insert(OPL::Db::FLIGHTS_TSPME, QString());
         }
-        flight.setRowData(flight_data);
+        flight.setData(flight_data);
         aDB->commit(flight);
     }
 }
@@ -362,7 +362,7 @@ void ACalc::updateNightTimes()
     for (const auto& item : flight_list) {
 
         auto flt = aDB->getFlightEntry(item.toInt());
-        auto data = flt.getRowData();
+        auto data = flt.getData();
         auto dateTime = QDateTime(QDate::fromString(data.value(OPL::Db::FLIGHTS_DOFT).toString(), Qt::ISODate),
                                   QTime().addSecs(data.value(OPL::Db::FLIGHTS_TOFB).toInt() * 60),
                                   Qt::UTC);
@@ -372,7 +372,7 @@ void ACalc::updateNightTimes()
                                        dateTime,
                                        data.value(OPL::Db::FLIGHTS_TBLK).toInt(),
                                        night_angle));
-        flt.setRowData(data);
+        flt.setData(data);
         aDB->commit(flt);
     }
 }

+ 14 - 8
src/gui/dialogues/firstrundialog.cpp

@@ -331,20 +331,26 @@ bool FirstRunDialog::createUserEntry()
 
 bool FirstRunDialog::writeCurrencies()
 {
-    const QList<QPair<ACurrencyEntry::CurrencyName, QDateEdit*>> currencies_list = {
-        {ACurrencyEntry::CurrencyName::Licence,     ui->currLicDateEdit},
-        {ACurrencyEntry::CurrencyName::TypeRating,  ui->currTrDateEdit},
-        {ACurrencyEntry::CurrencyName::LineCheck,   ui->currLckDateEdit},
-        {ACurrencyEntry::CurrencyName::Medical,     ui->currMedDateEdit},
-        {ACurrencyEntry::CurrencyName::Custom1,     ui->currCustom1DateEdit},
-        {ACurrencyEntry::CurrencyName::Custom2,     ui->currCustom1DateEdit},
+    const QList<QPair<OPL::CurrencyName, QDateEdit*>> currencies_list = {
+        {OPL::CurrencyName::Licence,    ui->currLicDateEdit},
+        {OPL::CurrencyName::TypeRating, ui->currTrDateEdit},
+        {OPL::CurrencyName::LineCheck,  ui->currLckDateEdit},
+        {OPL::CurrencyName::Medical,    ui->currMedDateEdit},
+        {OPL::CurrencyName::Custom1,    ui->currCustom1DateEdit},
+        {OPL::CurrencyName::Custom2,    ui->currCustom2DateEdit},
     };
 
     QDate today = QDate::currentDate();
     for (const auto &pair : currencies_list) {
         // only write dates that have been edited
         if (pair.second->date() != today) {
-            ACurrencyEntry entry(pair.first, pair.second->date());
+            RowData_T row_data = {{OPL::Db::CURRENCIES_EXPIRYDATE, pair.second->date().toString(Qt::ISODate)}};
+            if (pair.first == OPL::CurrencyName::Custom1)
+                row_data.insert(OPL::Db::CURRENCIES_CURRENCYNAME, ui->currCustom1LineEdit->text());
+            else if(pair.first == OPL::CurrencyName::Custom2)
+                row_data.insert(OPL::Db::CURRENCIES_CURRENCYNAME, ui->currCustom2LineEdit->text());
+
+            OPL::CurrencyEntry entry(static_cast<int>(pair.first), row_data);
             if (!aDB->commit(entry))
                 return false;
         }

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

@@ -197,7 +197,7 @@ void NewFlightDialog::fillWithEntryData()
     DEB << "Restoring Flight: ";
     DEB << flightEntry;
 
-    const auto &flight_data = flightEntry.getRowData();
+    const auto &flight_data = flightEntry.getData();
 
     // Date of Flight
     ui->doftLineEdit->setText(flight_data.value(OPL::Db::FLIGHTS_DOFT).toString());
@@ -388,8 +388,8 @@ RowData_T NewFlightDialog::prepareFlightEntryData()
     int acft_id = completionData.tailsIdMap.key(ui->acftLineEdit->text());
     new_data.insert(OPL::Db::FLIGHTS_ACFT, acft_id);
     const OPL::TailEntry acft_data = aDB->getTailEntry(acft_id);
-    bool multi_pilot = acft_data.getRowData().value(OPL::Db::TAILS_MULTIPILOT).toBool();
-    bool multi_engine = acft_data.getRowData().value(OPL::Db::TAILS_MULTIENGINE).toBool();
+    bool multi_pilot = acft_data.getData().value(OPL::Db::TAILS_MULTIPILOT).toBool();
+    bool multi_engine = acft_data.getData().value(OPL::Db::TAILS_MULTIENGINE).toBool();
 
     if (multi_pilot) {
         new_data.insert(OPL::Db::FLIGHTS_TMP, block_minutes);
@@ -776,7 +776,7 @@ void NewFlightDialog::on_buttonBox_accepted()
     DEB << flightEntry;
 
     //DEB << "Setting Data for flightEntry...";
-    flightEntry.setRowData(newData);
+    flightEntry.setData(newData);
     DEB << "Committing: ";
     DEB << flightEntry;
     if (!aDB->commit(flightEntry)) {

+ 2 - 2
src/gui/dialogues/newpilotdialog.cpp

@@ -84,7 +84,7 @@ void NewPilotDialog::formFiller()
 
     for (const auto &le : line_edits) {
         auto key = le->objectName().remove(QStringLiteral("LineEdit"));
-        le->setText(pilotEntry.getRowData().value(key).toString());
+        le->setText(pilotEntry.getData().value(key).toString());
     }
 }
 
@@ -98,7 +98,7 @@ void NewPilotDialog::submitForm()
         new_data.insert(key, value);
     }
 
-    pilotEntry.setRowData(new_data);
+    pilotEntry.setData(new_data);
     DEB << "Submitting Pilot:";
     DEB << pilotEntry;
     if (!aDB->commit(pilotEntry)) {

+ 2 - 2
src/gui/dialogues/newsimdialog.cpp

@@ -51,7 +51,7 @@ void NewSimDialog::init()
  */
 void NewSimDialog::fillEntryData()
 {
-    const auto& data = entry.getRowData();
+    const auto& data = entry.getData();
     ui->dateLineEdit->setText(data.value(OPL::Db::SIMULATORS_DATE).toString());
     ui->totalTimeLineEdit->setText(ATime::toString(data.value(OPL::Db::SIMULATORS_TIME).toInt()));
     ui->deviceTypeComboBox->setCurrentIndex(data.value(OPL::Db::SIMULATORS_TYPE).toInt());
@@ -176,7 +176,7 @@ void NewSimDialog::on_buttonBox_accepted()
         return;
     }
 
-    entry.setRowData(collectInput());
+    entry.setData(collectInput());
 
     DEB << entry;
 

+ 2 - 2
src/gui/dialogues/newtaildialog.cpp

@@ -116,7 +116,7 @@ void NewTailDialog::fillForm(OPL::Row entry, bool is_template)
     if (is_template)
         line_edits.removeOne(ui->registrationLineEdit);
 
-    auto data = entry.getRowData();
+    auto data = entry.getData();
 
     for (const auto &le : qAsConst(line_edits)) {
         auto key = le->objectName().remove(QStringLiteral("LineEdit"));
@@ -202,7 +202,7 @@ void NewTailDialog::submitForm()
 
     //create db object
 
-    entry.setRowData(new_data);
+    entry.setData(new_data);
     LOG << "Commiting: " << entry;
     if (!aDB->commit(entry)) {
         QMessageBox message_box(this);

+ 8 - 8
src/gui/widgets/aircraftwidget.cpp

@@ -188,7 +188,7 @@ void AircraftWidget::on_deleteAircraftButton_clicked()
         message_box.setWindowTitle(tr("Delete Aircraft"));
         message_box.setText(tr("You are deleting the following aircraft:<br><br><b><tt>"
                                "%1 - (%2)</b></tt><br><br>Are you sure?"
-                               ).arg(entry.getRowData().value(OPL::Db::TAILS_REGISTRATION).toString(),
+                               ).arg(entry.getData().value(OPL::Db::TAILS_REGISTRATION).toString(),
                                      getAircraftTypeString(entry)));
 
         if (message_box.exec() == QMessageBox::Yes) {
@@ -261,12 +261,12 @@ void AircraftWidget::repopulateModel()
 const QString AircraftWidget::getAircraftTypeString(const OPL::Row &row) const
 {
     QString type_string;
-    if (!row.getRowData().value(OPL::Db::TAILS_MAKE).toString().isEmpty())
-        type_string.append(row.getRowData().value(OPL::Db::TAILS_MAKE).toString() + QLatin1Char(' '));
-    if (!row.getRowData().value(OPL::Db::TAILS_MODEL).toString().isEmpty())
-        type_string.append(row.getRowData().value(OPL::Db::TAILS_MODEL).toString());
-    if (!row.getRowData().value(OPL::Db::TAILS_VARIANT).toString().isEmpty())
-        type_string.append(QLatin1Char('-') + row.getRowData().value(OPL::Db::TAILS_VARIANT).toString());
+    if (!row.getData().value(OPL::Db::TAILS_MAKE).toString().isEmpty())
+        type_string.append(row.getData().value(OPL::Db::TAILS_MAKE).toString() + QLatin1Char(' '));
+    if (!row.getData().value(OPL::Db::TAILS_MODEL).toString().isEmpty())
+        type_string.append(row.getData().value(OPL::Db::TAILS_MODEL).toString());
+    if (!row.getData().value(OPL::Db::TAILS_VARIANT).toString().isEmpty())
+        type_string.append(QLatin1Char('-') + row.getData().value(OPL::Db::TAILS_VARIANT).toString());
 
     return type_string;
 }
@@ -276,7 +276,7 @@ const QString AircraftWidget::getFlightSummary(const OPL::FlightEntry &flight) c
     if(!flight.isValid())
         return QString();
 
-    auto tableData = flight.getRowData();
+    auto tableData = flight.getData();
     QString flight_summary;
     auto space = QLatin1Char(' ');
     flight_summary.append(tableData.value(OPL::Db::FLIGHTS_DOFT).toString() + space);

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

@@ -26,7 +26,6 @@
 #include <QtGlobal>
 #include "src/functions/atime.h"
 #include "src/functions/astat.h"
-#include "src/classes/acurrencyentry.h"
 #include "src/classes/atranslator.h"
 #include "src/classes/ahash.h"
 #include "src/classes/ajson.h"

+ 21 - 17
src/gui/widgets/homewidget.cpp

@@ -21,6 +21,7 @@
 #include "src/database/adatabase.h"
 #include "src/functions/atime.h"
 #include "src/classes/asettings.h"
+#include "src/classes/row.h"
 
 // EASA FTL Limitations in minutes
 // 100 hours per 28 days
@@ -95,12 +96,19 @@ void HomeWidget::fillTotals()
     }
 }
 
-void HomeWidget::fillCurrency(ACurrencyEntry::CurrencyName currency_name, QLabel* display_label)
+void HomeWidget::fillCurrency(OPL::CurrencyName currency_name, QLabel* display_label)
 {
-    auto currency_entry = aDB->getCurrencyEntry(currency_name);
+    const auto currency_entry = aDB->getCurrencyEntry(static_cast<int>(currency_name));
+
+    if (currency_name == OPL::CurrencyName::Custom1) {
+        ui->currCustom1Label->setText(currency_entry.getData().value(OPL::Db::CURRENCIES_CURRENCYNAME).toString());
+    } else if (currency_name == OPL::CurrencyName::Custom2) {
+        ui->currCustom2Label->setText(currency_entry.getData().value(OPL::Db::CURRENCIES_CURRENCYNAME).toString());
+    }
+
     if (currency_entry.isValid()) {
-        auto currency_date = QDate::fromString(currency_entry.tableData.value(
-                                                   OPL::Db::CURRENCIES_EXPIRYDATE).toString(),
+        const auto currency_date = QDate::fromString(currency_entry.getData().value(
+                                               OPL::Db::CURRENCIES_EXPIRYDATE).toString(),
                                                Qt::ISODate);
         display_label->setText(currency_date.toString(Qt::TextDate));
         setLabelColour(display_label, Colour::None);
@@ -126,30 +134,26 @@ void HomeWidget::fillSelectedCurrencies()
     fillCurrencyTakeOffLanding();
 
     ASettings::read(ASettings::UserData::ShowLicCurrency).toBool() ?
-                fillCurrency(ACurrencyEntry::CurrencyName::Licence, ui->currLicDisplayLabel)
+                fillCurrency(OPL::CurrencyName::Licence, ui->currLicDisplayLabel)
               : hideLabels(ui->currLicLabel, ui->currLicDisplayLabel);
     ASettings::read(ASettings::UserData::ShowTrCurrency).toBool() ?
-                fillCurrency(ACurrencyEntry::CurrencyName::TypeRating, ui->currTrDisplayLabel)
+                fillCurrency(OPL::CurrencyName::TypeRating, ui->currTrDisplayLabel)
               : hideLabels(ui->currTrLabel, ui->currTrDisplayLabel);
     ASettings::read(ASettings::UserData::ShowLckCurrency).toBool() ?
-                fillCurrency(ACurrencyEntry::CurrencyName::LineCheck, ui->currLckDisplayLabel)
+                fillCurrency(OPL::CurrencyName::LineCheck, ui->currLckDisplayLabel)
               : hideLabels(ui->currLckLabel, ui->currLckDisplayLabel);
     ASettings::read(ASettings::UserData::ShowMedCurrency).toBool() ?
-                fillCurrency(ACurrencyEntry::CurrencyName::Medical, ui->currMedDisplayLabel)
+                fillCurrency(OPL::CurrencyName::Medical, ui->currMedDisplayLabel)
               : hideLabels(ui->currMedLabel, ui->currMedDisplayLabel);
-
     ASettings::read(ASettings::UserData::ShowCustom1Currency).toBool() ?
-                fillCurrency(ACurrencyEntry::CurrencyName::Custom1, ui->currCustom1DisplayLabel)
+                fillCurrency(OPL::CurrencyName::Custom1, ui->currCustom1DisplayLabel)
+              : hideLabels(ui->currCustom1Label, ui->currCustom1DisplayLabel);
+    ASettings::read(ASettings::UserData::ShowCustom1Currency).toBool() ?
+                fillCurrency(OPL::CurrencyName::Custom1, ui->currCustom1DisplayLabel)
               : hideLabels(ui->currCustom1Label, ui->currCustom1DisplayLabel);
-    const QString custom1_text = ASettings::read(ASettings::UserData::Custom1CurrencyName).toString();
-    if (!custom1_text.isEmpty())
-        ui->currCustom1Label->setText(custom1_text);
     ASettings::read(ASettings::UserData::ShowCustom2Currency).toBool() ?
-                fillCurrency(ACurrencyEntry::CurrencyName::Custom2, ui->currCustom2DisplayLabel)
+                fillCurrency(OPL::CurrencyName::Custom2, ui->currCustom2DisplayLabel)
               : hideLabels(ui->currCustom2Label, ui->currCustom2DisplayLabel);
-    const QString custom2_text = ASettings::read(ASettings::UserData::Custom2CurrencyName).toString();
-    if (!custom2_text.isEmpty())
-        ui->currCustom2Label->setText(custom2_text);
 }
 
 /*!

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

@@ -26,7 +26,6 @@
 #include "src/functions/astat.h"
 #include "src/database/adatabase.h"
 #include "src/classes/asettings.h"
-#include "src/classes/acurrencyentry.h"
 
 namespace Ui {
 class HomeWidget;
@@ -67,7 +66,7 @@ private:
     void fillTotals();
     void fillSelectedCurrencies();
     void fillCurrencyTakeOffLanding();
-    void fillCurrency(ACurrencyEntry::CurrencyName currency_name, QLabel *display_label);
+    void fillCurrency(OPL::CurrencyName currency_name, QLabel *display_label);
     void fillLimitations();
 
     enum class Colour {Red, Orange, None};

+ 1 - 1
src/gui/widgets/logbookwidget.cpp

@@ -102,7 +102,7 @@ const QString LogbookWidget::getFlightSummary(const OPL::FlightEntry &flight) co
     if(!flight.isValid())
         return QString();
 
-    auto tableData = flight.getRowData();
+    auto tableData = flight.getData();
     QString flight_summary;
     auto space = QLatin1Char(' ');
     flight_summary.append(tableData.value(OPL::Db::FLIGHTS_DOFT).toString() + space);

+ 3 - 3
src/gui/widgets/pilotswidget.cpp

@@ -243,8 +243,8 @@ const QString PilotsWidget::getPilotName(const OPL::PilotEntry &pilot)
     if (!pilot.isValid())
         return QString();
 
-    return pilot.getRowData().value(OPL::Db::PILOTS_LASTNAME).toString() + QLatin1String(", ")
-            + pilot.getRowData().value(OPL::Db::PILOTS_FIRSTNAME).toString();
+    return pilot.getData().value(OPL::Db::PILOTS_LASTNAME).toString() + QLatin1String(", ")
+            + pilot.getData().value(OPL::Db::PILOTS_FIRSTNAME).toString();
 }
 
 const QString PilotsWidget::getFlightSummary(const OPL::FlightEntry &flight) const
@@ -253,7 +253,7 @@ const QString PilotsWidget::getFlightSummary(const OPL::FlightEntry &flight) con
     if(!flight.isValid())
         return QString();
 
-    auto tableData = flight.getRowData();
+    auto tableData = flight.getData();
     QString flight_summary;
     auto space = QLatin1Char(' ');
     flight_summary.append(tableData.value(OPL::Db::FLIGHTS_DOFT).toString() + space);

+ 47 - 25
src/gui/widgets/settingswidget.cpp

@@ -74,22 +74,23 @@ void SettingsWidget::setupDateEdits()
         date_edit->setDisplayFormat(date_format_string);
     }
     // Fill currencies
-    const QList<QPair<ACurrencyEntry::CurrencyName, QDateEdit* >> currencies = {
-        {ACurrencyEntry::CurrencyName::Licence,     ui->currLicDateEdit},
-        {ACurrencyEntry::CurrencyName::TypeRating,  ui->currTrDateEdit},
-        {ACurrencyEntry::CurrencyName::LineCheck,   ui->currLckDateEdit},
-        {ACurrencyEntry::CurrencyName::Medical,     ui->currMedDateEdit},
-        {ACurrencyEntry::CurrencyName::Custom1,     ui->currCustom1DateEdit},
-        {ACurrencyEntry::CurrencyName::Custom2,     ui->currCustom2DateEdit}
+    const QList<QPair<OPL::CurrencyName, QDateEdit*>> currencies_list = {
+        {OPL::CurrencyName::Licence,    ui->currLicDateEdit},
+        {OPL::CurrencyName::TypeRating, ui->currTrDateEdit},
+        {OPL::CurrencyName::LineCheck,  ui->currLckDateEdit},
+        {OPL::CurrencyName::Medical,    ui->currMedDateEdit},
+        {OPL::CurrencyName::Custom1,    ui->currCustom1DateEdit},
+        {OPL::CurrencyName::Custom2,    ui->currCustom2DateEdit},
     };
-    for (const auto &pair : currencies) {
+    for (const auto &pair : currencies_list) {
         const QSignalBlocker signal_blocker(pair.second);
-        const auto entry = aDB->getCurrencyEntry(pair.first);
+        const auto entry = aDB->getCurrencyEntry(static_cast<int>(pair.first));
         if (entry.isValid()) { // set date
             const auto date = QDate::fromString(
-                        entry.tableData.value(OPL::Db::CURRENCIES_EXPIRYDATE).toString(),
+                        entry.getData().value(OPL::Db::CURRENCIES_EXPIRYDATE).toString(),
                         Qt::ISODate);
-            pair.second->setDate(date);
+            if(date.isValid())
+                pair.second->setDate(date);
         } else { // set current date
             pair.second->setDate(QDate::currentDate());
         }
@@ -104,7 +105,7 @@ void SettingsWidget::readSettings()
     //const QSignalBlocker blocker(this); // don't emit editing finished for setting these values
 
     // Personal Data Tab
-    auto user_data = aDB->getPilotEntry(1).getRowData();
+    auto user_data = aDB->getPilotEntry(1).getData();
     ui->lastnameLineEdit->setText(user_data.value(OPL::Db::PILOTS_LASTNAME).toString());
     ui->firstnameLineEdit->setText(user_data.value(OPL::Db::PILOTS_FIRSTNAME).toString());
     ui->companyLineEdit->setText(user_data.value(OPL::Db::PILOTS_COMPANY).toString());
@@ -160,7 +161,7 @@ void SettingsWidget::setupValidators()
         {ui->firstnameLineEdit, QRegularExpression(QLatin1String("\\w+"))},
         {ui->lastnameLineEdit, QRegularExpression(QLatin1String("\\w+"))},
         {ui->phoneLineEdit, QRegularExpression(QLatin1String("^[+]{0,1}[0-9\\-\\s]+"))},
-        {ui->emailLineEdit, QRegularExpression(QLatin1String("\\A[a-z0-9!#$%&'*+/=?^_‘{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_‘{|}~-]+)*@"
+        {ui->emailLineEdit, QRegularExpression(QString("\\A[a-z0-9!#$%&'*+/=?^_‘{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_‘{|}~-]+)*@"
          "(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\z"))},
         {ui->companyLineEdit, QRegularExpression(QLatin1String("\\w+"))},
         {ui->employeeidLineEdit, QRegularExpression(QLatin1String("\\w+"))},
@@ -472,43 +473,64 @@ void SettingsWidget::on_resetStylePushButton_clicked()
 
 void SettingsWidget::on_currLicDateEdit_userDateChanged(const QDate &date)
 {
-    ACurrencyEntry entry(ACurrencyEntry::CurrencyName::Licence, date);
-    aDB->commit(entry);
+    const RowData_T row_data = {{OPL::Db::CURRENCIES_EXPIRYDATE, date.toString(Qt::ISODate)}};
+    const OPL::CurrencyEntry entry(static_cast<int>(OPL::CurrencyName::Licence), row_data);
+    if (!aDB->commit(entry))
+        WARN(tr("Unable to update currency. The following error has ocurred:<br>%1").arg(aDB->lastError.text()));
+
     emit settingChanged(HomeWidget);
 }
 
 void SettingsWidget::on_currTrDateEdit_userDateChanged(const QDate &date)
 {
-    ACurrencyEntry entry(ACurrencyEntry::CurrencyName::TypeRating, date);
-    aDB->commit(entry);
+    const RowData_T row_data = {{OPL::Db::CURRENCIES_EXPIRYDATE, date.toString(Qt::ISODate)}};
+    const OPL::CurrencyEntry entry(static_cast<int>(OPL::CurrencyName::TypeRating), row_data);
+    if (!aDB->commit(entry))
+        WARN(tr("Unable to update currency. The following error has ocurred:<br>%1").arg(aDB->lastError.text()));
+
     emit settingChanged(HomeWidget);
 }
 
 void SettingsWidget::on_currLckDateEdit_userDateChanged(const QDate &date)
 {
-    ACurrencyEntry entry(ACurrencyEntry::CurrencyName::LineCheck, date);
-    aDB->commit(entry);
+    const RowData_T row_data = {{OPL::Db::CURRENCIES_EXPIRYDATE, date.toString(Qt::ISODate)}};
+    const OPL::CurrencyEntry entry(static_cast<int>(OPL::CurrencyName::LineCheck), row_data);
+    if (!aDB->commit(entry))
+        WARN(tr("Unable to update currency. The following error has ocurred:<br>%1").arg(aDB->lastError.text()));
+
     emit settingChanged(HomeWidget);
 }
 
 void SettingsWidget::on_currMedDateEdit_userDateChanged(const QDate &date)
 {
-    ACurrencyEntry entry(ACurrencyEntry::CurrencyName::Medical, date);
-    aDB->commit(entry);
+    const RowData_T row_data = {{OPL::Db::CURRENCIES_EXPIRYDATE, date.toString(Qt::ISODate)}};
+    const OPL::CurrencyEntry entry(static_cast<int>(OPL::CurrencyName::Medical), row_data);
+    if (!aDB->commit(entry))
+        WARN(tr("Unable to update currency. The following error has ocurred:<br>%1").arg(aDB->lastError.text()));
+
     emit settingChanged(HomeWidget);
 }
 
 void SettingsWidget::on_currCustom1DateEdit_userDateChanged(const QDate &date)
 {
-    ACurrencyEntry entry(ACurrencyEntry::CurrencyName::Custom1, date);
-    aDB->commit(entry);
+    const RowData_T row_data = {{OPL::Db::CURRENCIES_EXPIRYDATE, date.toString(Qt::ISODate)},
+                                {OPL::Db::CURRENCIES_CURRENCYNAME, ui->currCustom1LineEdit->text()}};
+    const OPL::CurrencyEntry entry(static_cast<int>(OPL::CurrencyName::Custom1), row_data);
+    DEB << entry;
+    if (!aDB->commit(entry))
+        WARN(tr("Unable to update currency. The following error has ocurred:<br><br>%1").arg(aDB->lastError.text()));
+
     emit settingChanged(HomeWidget);
 }
 
 void SettingsWidget::on_currCustom2DateEdit_userDateChanged(const QDate &date)
 {
-    ACurrencyEntry entry(ACurrencyEntry::CurrencyName::Custom2, date);
-    aDB->commit(entry);
+    const RowData_T row_data = {{OPL::Db::CURRENCIES_EXPIRYDATE, date.toString(Qt::ISODate)},
+                                {OPL::Db::CURRENCIES_CURRENCYNAME, ui->currCustom2LineEdit->text()}};
+    const OPL::CurrencyEntry entry(static_cast<int>(OPL::CurrencyName::Custom2), row_data);
+    if (!aDB->commit(entry))
+        WARN(tr("Unable to update currency. The following error has ocurred:<br><br>%1").arg(aDB->lastError.text()));
+
     emit settingChanged(HomeWidget);
 }
 

+ 9 - 1
src/opl.h

@@ -115,8 +115,16 @@ enum class DbViewName {Default, DefaultWithSim, Easa, EasaWithSim, SimulatorOnly
  */
 enum class SimulatorType {FNPTI = 0, FNPTII = 1, FSTD = 2};
 
+/*!
+ * \brief Enumerates the tables in the database
+ */
 enum class DbTable {Flights, Simulators, Pilots, Tails, Aircraft, Airports, Currencies};
 
+/*!
+ * \brief Enumerates the currency names
+ */
+enum class CurrencyName {Licence = 1, TypeRating = 2, LineCheck = 3, Medical = 4, Custom1 = 5, Custom2 = 6};
+
 /*!
  * \brief The OplGlobals class encapsulates non-POD globals to avoid making them static. It is available
  * as a global static object via the OPL::GLOBAL makro and may be used as if it were a pointer, guaranteed to be initialized exactly once.
@@ -299,7 +307,7 @@ const inline auto  PILOTS_EMAIL           = QStringLiteral("email");
 
 // Currencies table
 const inline auto  CURRENCIES_EXPIRYDATE  = QStringLiteral("expiryDate");
-const inline auto  CURRENCIES_DESCRIPTION = QStringLiteral("description");
+const inline auto  CURRENCIES_CURRENCYNAME = QStringLiteral("currencyName");
 
 // Simulators table
 const inline auto  SIMULATORS_ROWID       = QStringLiteral("session_id");