asettings.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. *openPilot Log - A FOSS Pilot Logbook Application
  3. *Copyright (C) 2020 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 ASETTINGS_H
  19. #define ASETTINGS_H
  20. #include <QtCore>
  21. #include <QSettings>
  22. /*!
  23. * \brief Thin (namespace) wrapper for the QSettings class,
  24. * simplifying reading and writing of settings.
  25. */
  26. class ASettings {
  27. public:
  28. enum class Setup {
  29. SetupComplete,
  30. };
  31. enum class Main {
  32. Theme,
  33. ThemeID,
  34. };
  35. enum class LogBook {
  36. View,
  37. };
  38. enum class UserData {
  39. LastName,
  40. FirstName,
  41. Company,
  42. EmployeeID,
  43. Phone,
  44. Email,
  45. DisplaySelfAs,
  46. Alias,
  47. AcSortColumn, // not sure what ac is
  48. PilSortColumn,
  49. AcAllowIncomplete,
  50. };
  51. enum class FlightLogging {
  52. Function,
  53. Approach,
  54. NightLogging,
  55. LogIFR,
  56. FlightNumberPrefix,
  57. NumberTakeoffs,
  58. NumberLandings,
  59. PopupCalendar,
  60. PilotFlying,
  61. NightAngle,
  62. Rules,
  63. };
  64. enum class NewFlight {
  65. FunctionComboBox,
  66. CalendarCheckBox,
  67. };
  68. /*!
  69. * \brief Should be called after QCoreApplication::set...Name have been called.
  70. */
  71. static void setup();
  72. static QVariant read(const Setup key);
  73. static void write(const Setup key, const QVariant &val);
  74. static QVariant read(const LogBook key);
  75. static void write(const LogBook key, const QVariant &val);
  76. static QVariant read(const Main key);
  77. static void write(const Main key, const QVariant &val);
  78. static QVariant read(const FlightLogging key);
  79. static void write(const UserData key, const QVariant &val);
  80. static QVariant read(const UserData key);
  81. static void write(const FlightLogging key, const QVariant &val);
  82. static QVariant read(const NewFlight key);
  83. static void write(const NewFlight key, const QVariant &val);
  84. // [G]: enum class may be making it abit too strict perhaps?
  85. // a workaround is to use plain enums and have one function takes an int
  86. // All enums should be unique of course thats easy. See At the end of the file
  87. // for details
  88. /*!
  89. * \brief Return string representation of path to key: "ini_header/key"
  90. */
  91. static QString pathOfKey(const Main key);
  92. static QString pathOfKey(const LogBook key);
  93. static QString pathOfKey(const NewFlight key);
  94. static QString pathOfKey(const FlightLogging key);
  95. static QString pathOfKey(const Setup key);
  96. static QString pathOfKey(const UserData key);
  97. /*!
  98. * \brief Return string representation of key
  99. */
  100. static QString stringOfKey(const Main key);
  101. static QString stringOfKey(const LogBook key);
  102. static QString stringOfKey(const NewFlight key);
  103. static QString stringOfKey(const FlightLogging key);
  104. static QString stringOfKey(const Setup key);
  105. static QString stringOfKey(const UserData key);
  106. static QSettings settings();
  107. private:
  108. static QMap<Main, QString> mainMap;
  109. static QMap<LogBook, QString> logBookMap;
  110. static QMap<UserData, QString> userDataMap;
  111. static QMap<FlightLogging, QString> flightLoggingMap;
  112. static QMap<Setup, QString> setupMap;
  113. static QMap<NewFlight, QString> newFlightMap;
  114. #define REFACTOR_PROPOSAL_REVIEWED true
  115. #if (REFACTOR_PROPOSAL_REVIEWED)
  116. /* By default unless specified each enum is + 1.
  117. If we are interested in doing multiple returns at once then
  118. we should make them so that the can be OR-ed.
  119. That means that in binary this means that
  120. every new enum has only 1 bit on
  121. that bit is always moving to the left
  122. */
  123. enum Setup2 {
  124. SetupComplete = 0x00'00'00'01, // If this makes no sense look up hexadecimals
  125. }; // the ' is legal in numbers it is ignored
  126. // used only for reader convinience
  127. enum Main2 {
  128. Theme = 0x00'00'00'02,
  129. ThemeID = 0x00'00'00'04,
  130. };
  131. enum LogBook2 {
  132. View = 0x00'00'00'08,
  133. };
  134. enum UserData2 {
  135. LastName = 0x00'00'00'10,
  136. FirstName = 0x00'00'00'20,
  137. Company = 0x00'00'00'40,
  138. EmployeeID = 0x00'00'00'80,
  139. Phone = 0x00'00'01'00,
  140. Email = 0x00'00'02'00,
  141. DisplaySelfAs = 0x00'00'04'00,
  142. Alias = 0x00'00'08'00,
  143. AcSortColumn = 0x00'00'10'00,
  144. PilSortColumn = 0x00'00'20'00,
  145. AcAllowIncomplete = 0x00'00'40'00,
  146. };
  147. enum FlightLogging2 {
  148. Function = 0x00'00'80'00,
  149. Approach = 0x00'01'00'00,
  150. NightLogging = 0x00'02'00'00,
  151. LogIFR = 0x00'04'00'00,
  152. FlightNumberPrefix = 0x00'08'00'00,
  153. NumberTakeoffs = 0x00'10'00'00,
  154. NumberLandings = 0x00'20'00'00,
  155. PopupCalendar = 0x00'40'00'00,
  156. PilotFlying = 0x00'80'00'00,
  157. NightAngle = 0x01'00'00'00,
  158. Rules = 0x02'00'00'00,
  159. };
  160. enum NewFlight2 {
  161. FunctionComboBox = 0x04'00'00'00,
  162. CalendarCheckBox = 0x08'00'00'00,
  163. };
  164. using Key = int;
  165. using Keys = int;
  166. /*
  167. * Used like QMessageBox buttons;
  168. *
  169. * auto str = stringOfKey2(ASettings::Setup);
  170. * auto strlist = stringOfKeys2(ASettings::Setup | ASettings::Function)
  171. */
  172. QString stringOfKey2(Key k);
  173. QStringList stringOfKeys2(Keys ks);
  174. #endif
  175. };
  176. #endif // ASETTINGS_H