logbookwidget.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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/classes/acompletiondata.h"
  29. namespace Ui {
  30. class LogbookWidget;
  31. }
  32. /*!
  33. * \brief The LogbookWidget displays data from the database in a QSqlTableView fed by a QSqlQuery Model
  34. *
  35. * \details The LogbookWidget is the primary display interface for flights logged in the database. It fetches and stores
  36. * flight data from the database via a QSqlQueryModel and displays it in a QTableView. With the way the flight data is
  37. * written in the database, it would not be human-readable, so some processing is done on the database side to present
  38. * a nicely formatted, human-readable display. This is achieved by means of a [SQL View](https://sqlite.org/lang_createview.html).
  39. *
  40. * The user can select a view from a list of available views in the SettingsWidget.
  41. *
  42. */
  43. class LogbookWidget : public QWidget
  44. {
  45. Q_OBJECT
  46. public:
  47. explicit LogbookWidget(ACompletionData &completion_data, QWidget *parent = nullptr);
  48. ~LogbookWidget();
  49. private slots:
  50. void on_newFlightButton_clicked();
  51. void on_editFlightButton_clicked();
  52. void on_deleteFlightPushButton_clicked();
  53. void on_showAllButton_clicked();
  54. void flightsTableView_selectionChanged();
  55. void on_tableView_customContextMenuRequested(const QPoint &pos);
  56. void on_actionDelete_Flight_triggered();
  57. void on_actionEdit_Flight_triggered();
  58. void on_tableView_doubleClicked();
  59. void on_flightSearchLlineEdit_textChanged(const QString &arg1);
  60. void on_flightSearchComboBox_currentIndexChanged(int);
  61. public slots:
  62. void refresh();
  63. void onLogbookWidget_viewSelectionChanged(SettingsWidget::SettingSignal signal);
  64. void repopulateModel();
  65. private:
  66. Ui::LogbookWidget *ui;
  67. QTableView* view;
  68. QSqlTableModel* displayModel;
  69. QItemSelectionModel* selectionModel;
  70. QMenu* menu;
  71. QVector<qint32> selectedFlights;
  72. void setupModelAndView(int view_id);
  73. void connectSignalsAndSlots();
  74. ACompletionData completionData;
  75. protected:
  76. /*!
  77. * \brief Handles change events, like updating the UI to new localisation
  78. */
  79. void changeEvent(QEvent* event) override;
  80. };
  81. #endif // LOGBOOKWIDGET_H