asettings.h 6.0 KB

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