2
0

dbcompletiondata.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 DBCOMPLETIONDATA_H
  19. #define DBCOMPLETIONDATA_H
  20. #include "src/opl.h"
  21. namespace OPL {
  22. /*!
  23. * \brief The DatabaseTarget enum lists database items that are
  24. * used by completers, for content matching or need to be accessed programatically.
  25. */
  26. enum class CompleterTarget
  27. {
  28. AirportIdentifierICAO,
  29. AirportIdentifierIATA,
  30. AirportIdentifier,
  31. AirportNames,
  32. Registrations,
  33. Companies,
  34. PilotNames,
  35. AircraftTypes
  36. };
  37. /*!
  38. * \brief Provides data for QCompleters and QHashs
  39. *
  40. * \details QCompleters and QHashes are used for mapping user input to database keys.
  41. * The required data is retreived from the database and cached for fast access without the
  42. * need to query the database. The DbCompletionData class holds the last state of the database
  43. * (state of user-modifiable data) in order to intelligently refresh the completion data when needed.
  44. */
  45. class DbCompletionData
  46. {
  47. public:
  48. /*!
  49. * \brief init Retrieves Data and populates Lists and Maps
  50. */
  51. void init();
  52. /*!
  53. * \brief updates data from the user modifiable tables
  54. */
  55. void update();
  56. void updateTails();
  57. void updatePilots();
  58. void updateAirports();
  59. // Maps for input mapping DB key - user input
  60. QHash<int, QString> pilotsIdMap;
  61. QHash<int, QString> tailsIdMap;
  62. QHash<int, QString> airportIcaoIdMap;
  63. QHash<int, QString> airportIataIdMap;
  64. QHash<int, QString> airportNameIdMap;
  65. // Lists for QCompleter
  66. QStringList pilotList;
  67. QStringList tailsList;
  68. QStringList airportList;
  69. /*!
  70. * \brief getCompletionList returns a QStringList of values for a
  71. * QCompleter based on database values
  72. */
  73. static const QStringList getCompletionList(CompleterTarget target);
  74. /*!
  75. * \brief returns a QHash of a human-readable database value and
  76. * its row id. Used in the Dialogs to map user input to unique database entries.
  77. */
  78. static const QHash<int, QString> getIdMap(CompleterTarget target);
  79. const QHash<int, QString> &getAirportsMapICAO() const;
  80. const QHash<int, QString> &getAirportsMapIATA() const;
  81. private:
  82. QHash<int, QString> airportsMapICAO;
  83. QHash<int, QString> airportsMapIATA;
  84. };
  85. } // namespace OPL
  86. #endif // DBCOMPLETIONDATA_H