row.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. *openPilotLog - A FOSS Pilot Logbook Application
  3. *Copyright (C) 2020-2022 Felix Turowsky
  4. *
  5. *This program is free software: you can redistribute it and/or modify
  6. *it under the terms of the GNU General Public License as published by
  7. *the Free Software Foundation, either version 3 of the License, or
  8. *(at your option) any later version.
  9. *
  10. *This program is distributed in the hope that it will be useful,
  11. *but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. *GNU General Public License for more details.
  14. *
  15. *You should have received a copy of the GNU General Public License
  16. *along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. #ifndef ROW_H
  19. #define ROW_H
  20. #include "src/opl.h"
  21. namespace OPL {
  22. /*!
  23. * \brief The Row class provides an interface for retreiving and submitting entries from the database.
  24. *
  25. * \details The Row class is a base class and when instantiated, the appropriate subclass should be used.
  26. *
  27. * The database holds all the data related to the logbook in different tables. Each of these tables is composed of
  28. * rows. Each row has different columns and each column contains the data. As such, an entry can be thought of
  29. * as a row in the database. The row class encapsulates the data contained in each row.
  30. *
  31. * A row is uniquely identified by its position in the database, consisting of the table name (QString) and the row id (int).
  32. * A new entry, which is not yet in the database has the row id 0. If a new row object is created, the hasData
  33. * bool is set to false. Before submitting the entry to the database, setData() has to be called to fill the row
  34. * with data and toggle the verification bit.
  35. *
  36. * The Row Object holds all the necessary information the Database class needs to commit (create or update) it.
  37. * The Identifying information can be accessed with getRowId and getTable() / getTableName().
  38. *
  39. * For convenience and readabilty, subclasses exist that have the table property pre-set. These rows are then
  40. * referred to as entries. See AircraftEntry, FlightEntry etc.
  41. */
  42. class Row
  43. {
  44. public:
  45. Row() { valid = false;} // Require specifying position
  46. Row(OPL::DbTable table_name, int row_id, const RowData_T &row_data);
  47. Row(OPL::DbTable table_name, int row_id);
  48. Row(OPL::DbTable table_name);
  49. Row(const Row&) = default;
  50. Row& operator=(const Row&) = default;
  51. const RowData_T& getData() const;
  52. void setData(const RowData_T &value);
  53. int getRowId() const;
  54. void setRowId(int value);
  55. OPL::DbTable getTable() const;
  56. const QString getTableName() const;
  57. const QString getPosition() const;
  58. bool isValid() const {return hasData && valid;}
  59. /*!
  60. * \brief operator QString can be used for printing debug information to stdout
  61. */
  62. operator QString() const;
  63. private:
  64. OPL::DbTable table;
  65. int rowId;
  66. RowData_T rowData;
  67. protected:
  68. bool hasData;
  69. bool valid = true;
  70. };
  71. /*!
  72. * \brief A Row representing an Aircraft entry. See Row class for details.
  73. */
  74. class AircraftEntry : public Row
  75. {
  76. public:
  77. AircraftEntry();
  78. AircraftEntry(const RowData_T &row_data);
  79. AircraftEntry(int row_id, const RowData_T &row_data);
  80. };
  81. /*!
  82. * \brief A Row representing a Tail (Registration) entry. See Row class for details.
  83. */
  84. class TailEntry : public Row
  85. {
  86. public:
  87. TailEntry();
  88. TailEntry(const RowData_T &row_data);
  89. TailEntry(int row_id, const RowData_T &row_data);
  90. const QString registration() const { return getData().value(OPL::Db::TAILS_REGISTRATION).toString(); }
  91. const QString type() const { return getData().value(OPL::Db::TAILS_MAKE).toString(); } //TODO - Create String for make-model-variant
  92. };
  93. /*!
  94. * \brief A Row representing a Pilot entry. See Row class for details.
  95. */
  96. class PilotEntry : public Row
  97. {
  98. public:
  99. PilotEntry();
  100. PilotEntry(const RowData_T &row_data);
  101. PilotEntry(int row_id, const RowData_T &row_data);
  102. const QString lastName() const { return getData().value(OPL::Db::PILOTS_LASTNAME).toString(); }
  103. const QString firstName() const { return getData().value(OPL::Db::PILOTS_FIRSTNAME).toString(); }
  104. };
  105. /*!
  106. * \brief A Row representing a Simulator entry. See Row class for details.
  107. */
  108. class SimulatorEntry : public Row
  109. {
  110. public:
  111. SimulatorEntry();
  112. SimulatorEntry(const RowData_T &row_data);
  113. SimulatorEntry(int row_id, const RowData_T &row_data);
  114. };
  115. /*!
  116. * \brief A Row representing a Flight entry. See Row class for details.
  117. */
  118. class FlightEntry : public Row
  119. {
  120. public:
  121. FlightEntry();
  122. FlightEntry(const RowData_T &row_data);
  123. FlightEntry(int row_id, const RowData_T &row_data);
  124. };
  125. /*!
  126. * \brief A Row representing a Currency entry. See Row class for details.
  127. */
  128. class CurrencyEntry : public Row
  129. {
  130. public:
  131. CurrencyEntry();
  132. CurrencyEntry(const RowData_T &row_data);
  133. CurrencyEntry(int row_id, const RowData_T &row_data);
  134. };
  135. /*!
  136. * \brief A Row representing an Airport entry. See Row class for details.
  137. */
  138. class AirportEntry : public Row
  139. {
  140. public:
  141. AirportEntry();
  142. AirportEntry(const RowData_T &row_data);
  143. AirportEntry(int row_id, const RowData_T &row_data);
  144. const QString iata() const { return getData().value(OPL::Db::AIRPORTS_IATA).toString(); }
  145. const QString icao() const { return getData().value(OPL::Db::AIRPORTS_ICAO).toString(); }
  146. };
  147. /*!
  148. * \brief A Row representing an Airport entry. See Row class for details.
  149. */
  150. class PreviousExperienceEntry : public Row
  151. {
  152. public:
  153. PreviousExperienceEntry();
  154. PreviousExperienceEntry(const RowData_T &row_data);
  155. PreviousExperienceEntry(int row_id, const RowData_T &row_data);
  156. };
  157. } // namespace OPL
  158. #endif // ROW_H