dbsummary.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. *openPilotLog - A FOSS Pilot Logbook Application
  3. *Copyright (C) 2020-2023 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 DBSUMMARY_H
  19. #define DBSUMMARY_H
  20. #include "src/database/database.h"
  21. namespace OPL {
  22. /*!
  23. * \brief Enumerates the QHash keys used when summarising a database
  24. */
  25. enum class DbSummaryKey {
  26. total_flights,
  27. total_tails,
  28. total_pilots,
  29. last_flight,
  30. total_time,
  31. };
  32. /*!
  33. * \brief The DbSummary class collects summaries of entries and relevant data from the database.
  34. *
  35. * \details Summaries are used mainly in the BackupWidget to give the user a quick overview about the
  36. * contents of a database so they can decide which backup to delete/restore. This class is a helper class
  37. * to avoid interfacing with the database directly. It uses a separate database connection in order to not
  38. * interfere with the currently active database.
  39. */
  40. class DbSummary : public QObject
  41. {
  42. public:
  43. DbSummary() = default;
  44. /*!
  45. * \brief Return a summary of a database
  46. * \details Creates a summary of the database giving a quick overview of the relevant contents. The
  47. * function runs several specialised SQL queries to create a QHash<DatabaseSummaryKey, QString> containing
  48. * Total Flight Time, Number of unique aircraft and pilots, as well as the date of last flight. Uses a temporary
  49. * database connection separate from the default connection in order to not tamper with the currently active
  50. * database connection. The full path to the database to be summarized has to be provided.
  51. */
  52. static const QMap<DbSummaryKey, QString> databaseSummary(const QString& db_path);
  53. /*!
  54. * \brief returns a short summary string of the database, containing total time and date of last flight.
  55. */
  56. static const QString summaryString(const QString& db_path);
  57. private:
  58. Q_OBJECT
  59. inline const static QString SQLITE_DRIVER = QStringLiteral("QSQLITE");
  60. };
  61. } // namespace OPL
  62. #endif // DBSUMMARY_H