Browse Source

RowData_T definition now in OPL namespace

Also added a macro in opl.h to increase performance with map type containers in Qt6 (using QHash iso QMap)
Felix Turo 2 years ago
parent
commit
a7ffdc0068

+ 3 - 3
docs/man/man3/ADatabase.3

@@ -96,7 +96,7 @@ Inherits QObject\&.
 .br
 .RI "deletes a list of entries from the database\&. Optimised for speed when deleting many entries\&. "
 .ti -1c
-.RI "RowData_T \fBgetEntryData\fP (\fBDataPosition\fP data_position)"
+.RI "OPL::RowData_T \fBgetEntryData\fP (\fBDataPosition\fP data_position)"
 .br
 .RI "retreive entry data from the database to create an entry object "
 .ti -1c
@@ -164,7 +164,7 @@ Inherits QObject\&.
 .br
 .RI "\fBDatabase::createBackup\fP copies the currently used database to an external backup location provided by the user\&. "
 .ti -1c
-.RI "QVector< RowData_T > \fBgetTable\fP (DatabaseTable table_name)"
+.RI "QVector< OPL::RowData_T > \fBgetTable\fP (DatabaseTable table_name)"
 .br
 .RI "getTable returns all contents of a given table from the database "
 .ti -1c
@@ -273,7 +273,7 @@ retreives a flight entry from the database\&. This function is a wrapper for Dat
 
 .PP
 retreives a PilotEntry from the database\&. This function is a wrapper for DataBase::getEntry(DataPosition), 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\&. 
-.SS "QVector< RowData_T > Database::getTable (DatabaseTable table_name)"
+.SS "QVector< OPL::RowData_T > Database::getTable (DatabaseTable table_name)"
 
 .PP
 getTable returns all contents of a given table from the database 

+ 5 - 5
docs/man/man3/AEntry.3

@@ -24,13 +24,13 @@ Inherited by \fBAAircraftEntry\fP, \fBACurrencyEntry\fP, \fBAFlightEntry\fP, \fB
 .RI "\fBAEntry\fP (\fBDataPosition\fP position_)"
 .br
 .ti -1c
-.RI "\fBAEntry\fP (RowData_T table_data)"
+.RI "\fBAEntry\fP (OPL::RowData_T table_data)"
 .br
 .ti -1c
-.RI "\fBAEntry\fP (\fBDataPosition\fP position_, RowData_T table_data)"
+.RI "\fBAEntry\fP (\fBDataPosition\fP position_, OPL::RowData_T table_data)"
 .br
 .ti -1c
-.RI "void \fBsetData\fP (RowData_T table_data)"
+.RI "void \fBsetData\fP (OPL::RowData_T table_data)"
 .br
 .ti -1c
 .RI "void \fBsetPosition\fP (\fBDataPosition\fP position_)"
@@ -39,7 +39,7 @@ Inherited by \fBAAircraftEntry\fP, \fBACurrencyEntry\fP, \fBAFlightEntry\fP, \fB
 .RI "const \fBDataPosition\fP & \fBgetPosition\fP () const"
 .br
 .ti -1c
-.RI "const RowData_T & \fBgetData\fP () const"
+.RI "const OPL::RowData_T & \fBgetData\fP () const"
 .br
 .ti -1c
 .RI "\fBoperator QString\fP () const"
@@ -50,7 +50,7 @@ Inherited by \fBAAircraftEntry\fP, \fBACurrencyEntry\fP, \fBAFlightEntry\fP, \fB
 
 .in +1c
 .ti -1c
-.RI "RowData_T \fBtableData\fP"
+.RI "OPL::RowData_T \fBtableData\fP"
 .br
 .in -1c
 .SS "Protected Attributes"

+ 3 - 3
docs/man/man3/OPL_Database.3

@@ -101,7 +101,7 @@ Inherits QObject\&.
 .br
 .RI "retreive a \fBRow\fP from the database "
 .ti -1c
-.RI "RowData_T \fBgetRowData\fP (const \fBOPL::DbTable\fP table, const int row_id)"
+.RI "OPL::RowData_T \fBgetRowData\fP (const \fBOPL::DbTable\fP table, const int row_id)"
 .br
 .RI "retreive a Map of <column name, column content> for a specific row in the database\&. "
 .ti -1c
@@ -137,7 +137,7 @@ Inherits QObject\&.
 .br
 .RI "returns a list of ROWID's in the flights table for which foreign key constraints exist\&. "
 .ti -1c
-.RI "QVector< RowData_T > \fBgetTable\fP (\fBOPL::DbTable\fP table)"
+.RI "QVector< OPL::RowData_T > \fBgetTable\fP (\fBOPL::DbTable\fP table)"
 .br
 .RI "getTable returns all contents of a given table from the database "
 .ti -1c
@@ -240,7 +240,7 @@ The QSqlDatabase object pertaining to the connection\&.
 .RE
 .PP
 
-.SS "QVector< RowData_T > OPL::Database::getTable (\fBOPL::DbTable\fP table)"
+.SS "QVector< OPL::RowData_T > OPL::Database::getTable (\fBOPL::DbTable\fP table)"
 
 .PP
 getTable returns all contents of a given table from the database 

+ 3 - 3
docs/man/man3/OPL_Row.3

@@ -15,7 +15,7 @@ Inherited by \fBOPL::AircraftEntry\fP, \fBOPL::CurrencyEntry\fP, \fBOPL::FlightE
 
 .in +1c
 .ti -1c
-.RI "\fBRow\fP (\fBOPL::DbTable\fP table_name, int row_id, const RowData_T &row_data)"
+.RI "\fBRow\fP (\fBOPL::DbTable\fP table_name, int row_id, const OPL::RowData_T &row_data)"
 .br
 .ti -1c
 .RI "\fBRow\fP (\fBOPL::DbTable\fP table_name, int row_id)"
@@ -30,10 +30,10 @@ Inherited by \fBOPL::AircraftEntry\fP, \fBOPL::CurrencyEntry\fP, \fBOPL::FlightE
 .RI "\fBRow\fP & \fBoperator=\fP (const \fBRow\fP &)=default"
 .br
 .ti -1c
-.RI "RowData_T \fBgetData\fP () const"
+.RI "OPL::RowData_T \fBgetData\fP () const"
 .br
 .ti -1c
-.RI "void \fBsetData\fP (const RowData_T &value)"
+.RI "void \fBsetData\fP (const OPL::RowData_T &value)"
 .br
 .ti -1c
 .RI "int \fBgetRowId\fP () const"

+ 31 - 1
mainwindow.cpp

@@ -29,7 +29,37 @@
 // Quick and dirty Debug area
 void MainWindow::doDebugStuff()
 {
-    completionData.update();
+    const auto entry = DB->getPilotEntry(1);
+    DEB << entry;
+
+    const auto hash = entry.getData();
+    QMap<QString, QVariant> map;
+    for (const auto &var : hash) {
+        map.insert(hash.key(var), var);
+    }
+    {
+    ATimer timer;
+    for (int i = 0; i < 1000 ; i++ ) {
+
+
+        QString string;
+        string.append(hash.value(OPL::Db::PILOTS_ALIAS).toString());
+        string.append(hash.value(OPL::Db::PILOTS_FIRSTNAME).toString());
+        string.append(hash.value(OPL::Db::PILOTS_LASTNAME).toString());
+    }
+    LOG << "Hash lookup time:";}
+    {
+    ATimer timer;
+    for (int i = 0; i < 10000 ; i++ ) {
+        QString string;
+        string.append(map.value(OPL::Db::PILOTS_ALIAS).toString());
+        string.append(map.value(OPL::Db::PILOTS_FIRSTNAME).toString());
+        string.append(map.value(OPL::Db::PILOTS_LASTNAME).toString());
+
+    }
+    LOG << "map lookup time:";}
+
+
 }
 
 MainWindow::MainWindow(QWidget *parent)

+ 1 - 1
src/classes/aaircraftentry.h

@@ -25,7 +25,7 @@ struct AAircraftEntry : public AEntry {
 public:
     AAircraftEntry();
     AAircraftEntry(RowId_T row_id);
-    AAircraftEntry(RowData_T table_data);
+    AAircraftEntry(OPL::RowData_T table_data);
 
     AAircraftEntry(const AAircraftEntry& te) = default;
     AAircraftEntry& operator=(const AAircraftEntry& te) = default;

+ 3 - 1
src/database/database.h

@@ -35,10 +35,12 @@
 #include "src/database/row.h"
 #include "src/classes/astandardpaths.h"
 
-using RowData_T = QHash<QString, QVariant>;
+
 
 namespace OPL {
 
+//using RowData_T = QHash<QString, QVariant>;
+
 /*!
  * \brief Convenience macro that returns instance of DataBase.
  * Instead of this:

+ 0 - 1
src/database/row.h

@@ -20,7 +20,6 @@
 #define ROW_H
 #include "src/opl.h"
 
-
 namespace OPL {
 
 /*!

+ 3 - 3
src/gui/dialogues/firstrundialog.cpp

@@ -340,7 +340,7 @@ bool FirstRunDialog::createUserEntry()
 
 bool FirstRunDialog::writeCurrencies()
 {
-    const QHash<OPL::CurrencyName, QDateEdit*> currencies_list = {
+    const QMap<OPL::CurrencyName, QDateEdit*> currencies_list = {
         {OPL::CurrencyName::Licence,    ui->currLicDateEdit},
         {OPL::CurrencyName::TypeRating, ui->currTrDateEdit},
         {OPL::CurrencyName::LineCheck,  ui->currLckDateEdit},
@@ -348,7 +348,7 @@ bool FirstRunDialog::writeCurrencies()
         {OPL::CurrencyName::Custom1,    ui->currCustom1DateEdit},
         {OPL::CurrencyName::Custom2,    ui->currCustom2DateEdit},
     };
-    const QHash<OPL::CurrencyName, ASettings::UserData> settings_list = {
+    const QMap<OPL::CurrencyName, ASettings::UserData> settings_list = {
         {OPL::CurrencyName::Licence,    ASettings::UserData::ShowLicCurrency },
         {OPL::CurrencyName::TypeRating, ASettings::UserData::ShowTrCurrency },
         {OPL::CurrencyName::LineCheck,  ASettings::UserData::ShowLckCurrency },
@@ -362,7 +362,7 @@ bool FirstRunDialog::writeCurrencies()
         const auto enum_value = currencies_list.key(date_edit);
         // only write dates that have been edited
         if (date_edit->date() != today) {
-            RowData_T row_data = {{OPL::Db::CURRENCIES_EXPIRYDATE, date_edit->date().toString(Qt::ISODate)}};
+            OPL::RowData_T row_data = {{OPL::Db::CURRENCIES_EXPIRYDATE, date_edit->date().toString(Qt::ISODate)}};
             if (enum_value == OPL::CurrencyName::Custom1)
                 row_data.insert(OPL::Db::CURRENCIES_CURRENCYNAME, ui->currCustom1LineEdit->text());
             else if(enum_value == OPL::CurrencyName::Custom2)

+ 1 - 1
src/gui/dialogues/newairportdialog.cpp

@@ -39,7 +39,7 @@ void NewAirportDialog::on_buttonBox_accepted()
         return;
     }
     // create Entry object
-    RowData_T airport_data = {
+    OPL::RowData_T airport_data = {
         {OPL::Db::AIRPORTS_ICAO, ui->icaoLineEdit->text()},
         {OPL::Db::AIRPORTS_IATA, ui->iataLineEdit->text()},
         {OPL::Db::AIRPORTS_LAT,  ui->latitudeLineEdit->text()},

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

@@ -361,14 +361,14 @@ bool NewFlightDialog::addNewPilot(QLineEdit& parent_line_edit)
 /*!
  * \brief NewFlightDialog::prepareFlightEntryData reads the user input from the UI and converts it into
  * the database format.
- * \return RowData_T a map containing a row ready for database submission
+ * \return OPL::RowData_T a map containing a row ready for database submission
  */
-RowData_T NewFlightDialog::prepareFlightEntryData()
+OPL::RowData_T NewFlightDialog::prepareFlightEntryData()
 {
     if(!validationState.allValid())
         return {};
 
-    RowData_T new_data;
+    OPL::RowData_T new_data;
     // Calculate Block and Night Time
     const int block_minutes = ATime::blockMinutes(ui->tofbTimeLineEdit->text(), ui->tonbTimeLineEdit->text());
     QDateTime departure_date_time = ADateTime::fromString(ui->doftLineEdit->text() + ui->tofbTimeLineEdit->text());

+ 1 - 1
src/gui/dialogues/newflightdialog.h

@@ -182,7 +182,7 @@ private:
 
 
     bool checkPilotFunctionsValid();
-    RowData_T prepareFlightEntryData();
+    OPL::RowData_T prepareFlightEntryData();
 
 
 private slots:

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

@@ -91,7 +91,7 @@ void NewPilotDialog::formFiller()
 
 void NewPilotDialog::submitForm()
 {
-    RowData_T new_data;
+    OPL::RowData_T new_data;
     const auto line_edits = this->findChildren<QLineEdit *>();
     for(auto& le : line_edits) {
         auto key = le->objectName().remove(QStringLiteral("LineEdit"));

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

@@ -147,9 +147,9 @@ bool NewSimDialog::verifyInput(QString& error_msg)
     return true;
 }
 
-RowData_T NewSimDialog::collectInput()
+OPL::RowData_T NewSimDialog::collectInput()
 {
-    RowData_T new_entry;
+    OPL::RowData_T new_entry;
     // Date
     new_entry.insert(OPL::Db::SIMULATORS_DATE, ui->dateLineEdit->text());
     // Time

+ 1 - 1
src/gui/dialogues/newsimdialog.h

@@ -44,7 +44,7 @@ private:
     void init();
     void fillEntryData();
     bool verifyInput(QString &error_msg);
-    RowData_T collectInput();
+    OPL::RowData_T collectInput();
 
     OPL::SimulatorEntry entry;
 };

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

@@ -178,7 +178,7 @@ bool NewTailDialog::verify()
  */
 void NewTailDialog::submitForm()
 {
-    RowData_T new_data;
+    OPL::RowData_T new_data;
     //retreive Line Edits
     auto line_edits = this->findChildren<QLineEdit *>();
     line_edits.removeOne(this->findChild<QLineEdit *>(QStringLiteral("searchLineEdit")));

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

@@ -189,7 +189,7 @@ void SettingsWidget::setupValidators()
  */
 void SettingsWidget::updatePersonalDetails()
 {
-    RowData_T user_data;
+    OPL::RowData_T user_data;
     switch (ui->aliasComboBox->currentIndex()) {
     case 0:
         user_data.insert(OPL::Db::PILOTS_ALIAS, QStringLiteral("self"));
@@ -482,7 +482,7 @@ void SettingsWidget::on_resetStylePushButton_clicked()
 
 void SettingsWidget::on_currLicDateEdit_userDateChanged(const QDate &date)
 {
-    const RowData_T row_data = {{OPL::Db::CURRENCIES_EXPIRYDATE, date.toString(Qt::ISODate)}};
+    const OPL::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 (!DB->commit(entry))
         WARN(tr("Unable to update currency. The following error has ocurred:<br>%1").arg(DB->lastError.text()));
@@ -492,7 +492,7 @@ void SettingsWidget::on_currLicDateEdit_userDateChanged(const QDate &date)
 
 void SettingsWidget::on_currTrDateEdit_userDateChanged(const QDate &date)
 {
-    const RowData_T row_data = {{OPL::Db::CURRENCIES_EXPIRYDATE, date.toString(Qt::ISODate)}};
+    const OPL::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 (!DB->commit(entry))
         WARN(tr("Unable to update currency. The following error has ocurred:<br>%1").arg(DB->lastError.text()));
@@ -502,7 +502,7 @@ void SettingsWidget::on_currTrDateEdit_userDateChanged(const QDate &date)
 
 void SettingsWidget::on_currLckDateEdit_userDateChanged(const QDate &date)
 {
-    const RowData_T row_data = {{OPL::Db::CURRENCIES_EXPIRYDATE, date.toString(Qt::ISODate)}};
+    const OPL::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 (!DB->commit(entry))
         WARN(tr("Unable to update currency. The following error has ocurred:<br>%1").arg(DB->lastError.text()));
@@ -512,7 +512,7 @@ void SettingsWidget::on_currLckDateEdit_userDateChanged(const QDate &date)
 
 void SettingsWidget::on_currMedDateEdit_userDateChanged(const QDate &date)
 {
-    const RowData_T row_data = {{OPL::Db::CURRENCIES_EXPIRYDATE, date.toString(Qt::ISODate)}};
+    const OPL::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 (!DB->commit(entry))
         WARN(tr("Unable to update currency. The following error has ocurred:<br>%1").arg(DB->lastError.text()));
@@ -522,7 +522,7 @@ void SettingsWidget::on_currMedDateEdit_userDateChanged(const QDate &date)
 
 void SettingsWidget::on_currCustom1DateEdit_userDateChanged(const QDate &date)
 {
-    const RowData_T row_data = {{OPL::Db::CURRENCIES_EXPIRYDATE, date.toString(Qt::ISODate)},
+    const OPL::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;
@@ -534,7 +534,7 @@ void SettingsWidget::on_currCustom1DateEdit_userDateChanged(const QDate &date)
 
 void SettingsWidget::on_currCustom2DateEdit_userDateChanged(const QDate &date)
 {
-    const RowData_T row_data = {{OPL::Db::CURRENCIES_EXPIRYDATE, date.toString(Qt::ISODate)},
+    const OPL::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 (!DB->commit(entry))

+ 51 - 1
src/opl.h

@@ -149,6 +149,55 @@ public:
 private:
     Q_OBJECT
 
+#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
+    const static inline QHash<Translation, QString> L10N_FilePaths {
+        {Translation::English, QStringLiteral("l10n/openpilotlog_en")},
+        {Translation::German,  QStringLiteral("l10n/openpilotlog_de")},
+        {Translation::Spanish, QStringLiteral("l10n/openpilotlog_es")},
+    };
+    const static inline QHash<Translation, QString> L10N_DisplayNames {
+        {Translation::English, QStringLiteral("English")},
+        {Translation::German,  QStringLiteral("Deutsch")},
+        {Translation::Spanish, QStringLiteral("Español")},
+    };
+    const static inline QHash<DbViewName, QString> DATABASE_VIEWS = {
+        {DbViewName::Default,        QStringLiteral("viewDefault")},
+        {DbViewName::DefaultWithSim, QStringLiteral("viewDefaultSim")},
+        {DbViewName::Easa,           QStringLiteral("viewEasa")},
+        {DbViewName::EasaWithSim,    QStringLiteral("viewEasaSim")},
+        {DbViewName::SimulatorOnly,  QStringLiteral("viewSimulators")},
+    };
+    const QHash<DbViewName, QString> DATABASE_VIEW_DISPLAY_NAMES = {
+        {DbViewName::Default,        tr("Default")},
+        {DbViewName::DefaultWithSim, tr("Default with Simulator")},
+        {DbViewName::Easa,           tr("EASA-FCL")},
+        {DbViewName::EasaWithSim,    tr("EASA-FCL with Simulator")},
+        {DbViewName::SimulatorOnly,  tr("Simulator Sessions Only")},
+    };
+    const static inline QHash<PilotFunction, QString> PILOT_FUNCTIONS = {
+        {PilotFunction::PIC,   QStringLiteral("PIC")},
+        {PilotFunction::PICUS, QStringLiteral("PICUS")},
+        {PilotFunction::SIC,   QStringLiteral("SIC")},
+        {PilotFunction::DUAL,  QStringLiteral("DUAL")},
+        {PilotFunction::FI,    QStringLiteral("FI")},
+    };
+    const static inline QHash<SimulatorType, QString> SIMULATOR_TYPES = {
+        {SimulatorType::FNPTI,  QStringLiteral("FNPT I")},
+        {SimulatorType::FNPTII, QStringLiteral("FNPT II")},
+        {SimulatorType::FSTD,   QStringLiteral("FSTD")},
+    };
+    const static inline QHash<DbTable, QString> DB_TABLES = {
+        //Flights, Simulators, Pilots, Tails, Aircraft, Airports
+        {DbTable::Flights,      QStringLiteral("flights")},
+        {DbTable::Simulators,   QStringLiteral("simulators")},
+        {DbTable::Pilots,       QStringLiteral("pilots")},
+        {DbTable::Tails,        QStringLiteral("tails")},
+        {DbTable::Aircraft,     QStringLiteral("aircraft")},
+        {DbTable::Airports,     QStringLiteral("airports")},
+        {DbTable::Currencies,   QStringLiteral("currencies")},
+        {DbTable::Changelog,    QStringLiteral("changelog")},
+    };
+#else
     const static inline QMap<Translation, QString> L10N_FilePaths {
         {Translation::English, QStringLiteral("l10n/openpilotlog_en")},
         {Translation::German,  QStringLiteral("l10n/openpilotlog_de")},
@@ -186,7 +235,6 @@ private:
         {SimulatorType::FSTD,   QStringLiteral("FSTD")},
     };
     const static inline QMap<DbTable, QString> DB_TABLES = {
-        //Flights, Simulators, Pilots, Tails, Aircraft, Airports
         {DbTable::Flights,      QStringLiteral("flights")},
         {DbTable::Simulators,   QStringLiteral("simulators")},
         {DbTable::Pilots,       QStringLiteral("pilots")},
@@ -196,6 +244,8 @@ private:
         {DbTable::Currencies,   QStringLiteral("currencies")},
         {DbTable::Changelog,    QStringLiteral("changelog")},
     };
+#endif
+
     const static inline QStringList APPROACH_TYPES = {
             QStringLiteral("VISUAL"),
             QStringLiteral("ILS CAT I"),