logbookwidget.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. *openPilotLog - A FOSS Pilot Logbook Application
  3. *Copyright (C) 2020-2021 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 LOGBOOKWIDGET_H
  19. #define LOGBOOKWIDGET_H
  20. #include <QWidget>
  21. #include <QItemSelection>
  22. #include <QSqlTableModel>
  23. #include <QMessageBox>
  24. #include <QDebug>
  25. #include <QMenu>
  26. #include <QTableView>
  27. #include "src/gui/widgets/settingswidget.h"
  28. #include "src/database/dbcompletiondata.h"
  29. #include "src/opl.h"
  30. namespace Ui {
  31. class LogbookWidget;
  32. }
  33. /*!
  34. * \brief The LogbookWidget displays data from the database in a QSqlTableView fed by a QSqlQuery Model
  35. *
  36. * \details The LogbookWidget is the primary display interface for flights logged in the database. It fetches and stores
  37. * flight data from the database via a QSqlQueryModel and displays it in a QTableView. With the way the flight data is
  38. * written in the database, it would not be human-readable, so some processing is done on the database side to present
  39. * a nicely formatted, human-readable display. This is achieved by means of a [SQL View](https://sqlite.org/lang_createview.html).
  40. *
  41. * The user can select a view from a list of available views in the SettingsWidget.
  42. *
  43. */
  44. class LogbookWidget : public QWidget
  45. {
  46. Q_OBJECT
  47. public:
  48. explicit LogbookWidget(OPL::DbCompletionData &completion_data, QWidget *parent = nullptr);
  49. ~LogbookWidget();
  50. private slots:
  51. void flightsTableView_selectionChanged();
  52. void on_tableView_customContextMenuRequested(const QPoint &pos);
  53. void on_actionDelete_Flight_triggered();
  54. void on_tableView_doubleClicked();
  55. void on_flightSearchLlineEdit_textChanged(const QString &arg1);
  56. void on_flightSearchComboBox_currentIndexChanged(int);
  57. void on_viewsComboBox_currentIndexChanged(int index);
  58. void on_actionEdit_Flight_triggered();
  59. void on_actionEdit_Sim_triggered();
  60. public slots:
  61. void refresh();
  62. void onLogbookWidget_viewSelectionChanged(SettingsWidget::SettingSignal signal);
  63. void repopulateModel();
  64. private:
  65. Ui::LogbookWidget *ui;
  66. QTableView* view;
  67. QSqlTableModel* displayModel;
  68. QItemSelectionModel* selectionModel;
  69. QMenu* menu;
  70. QList<int> selectedEntries;
  71. void setupModelAndView(int view_id);
  72. void connectSignalsAndSlots();
  73. const QString getFlightSummary(const OPL::FlightEntry &flight) const;
  74. OPL::DbCompletionData completionData;
  75. /*!
  76. * \brief isFlight Determines whether an entry shown in a view is a Flight or a Simulator.
  77. * \param model_row_id the row id in the QSqlTableModel used for displaying
  78. * \details In the composite views (SQL UNION) with Simulators included, the row_id of the
  79. * simulator entries is inverted to a negative value. A positive row id is thus a row id from
  80. * the flights table, whereas a negative rowid is a row id from the simulators table.
  81. */
  82. inline bool isFlight(int model_row_id) { return model_row_id > 0; }
  83. protected:
  84. /*!
  85. * \brief Handles change events, like updating the UI to new localisation
  86. */
  87. void changeEvent(QEvent* event) override;
  88. };
  89. #endif // LOGBOOKWIDGET_H