pilotswidget.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 PILOTSWIDGET_H
  19. #define PILOTSWIDGET_H
  20. #include <QWidget>
  21. #include <QItemSelection>
  22. #include <QSqlTableModel>
  23. #include <QTableView>
  24. #include "src/classes/asettings.h"
  25. #include "src/gui/dialogues/newpilotdialog.h"
  26. #include "src/gui/widgets/settingswidget.h"
  27. #include "src/functions/acalc.h"
  28. namespace Ui {
  29. class PilotsWidget;
  30. }
  31. /*!
  32. * \class PilotsWidget
  33. * \brief The PilotsWidget is used to view, edit, delete or add new pilots.
  34. * \details The widget consists of two main parts, a *QTableView* on the left side and a *QStackedWidget* on the right side.
  35. *
  36. * In the QTableView, a QSqlTableModel is used to access a view from the database, which holds a Pilots' Last Name,
  37. * First name and Company.
  38. *
  39. * The welcome page shown on the QStackedWidget on the right side has a QLineEdit that functions as a search box and a QCombobox
  40. * holding the possible columns that can be used to filter what is displayed. The text of the QLineEdit is used as a filter for the
  41. * QSqlTableModel, so the view is updated in real time.
  42. *
  43. * The *NewPilotDialog* is used for creating a new entry as well as for editing an existing entry. If the user selects a row
  44. * in the QTableView, the NewPilotDialog is displayed on the right side of the Widget, inside the QStackedWidget.
  45. * In order to avoid leaks from any previously made selections, existing Dialogs are deleted before a new one is created.
  46. * The NewPilotDialog's `accepted` and `rejected` signals are connected to refresh the view as required.
  47. *
  48. * The logbook owner is not shown in the QTableView as an editable Pilot since `self` is a special reserved alias for the
  49. * pilot with ROWID #1 as a way to identify and adequately display the logbook owner in the logbook. Editing personal details
  50. * is done via the *SettingsWidget*
  51. */
  52. class PilotsWidget : public QWidget
  53. {
  54. Q_OBJECT
  55. public:
  56. explicit PilotsWidget(QWidget *parent = nullptr);
  57. ~PilotsWidget();
  58. private slots:
  59. void tableView_selectionChanged();
  60. void tableView_headerClicked(int);
  61. void on_newPilotButton_clicked();
  62. void on_deletePilotButton_clicked();
  63. void onDeleteUnsuccessful();
  64. void onNewPilotDialog_editingFinished();
  65. void on_pilotSearchLineEdit_textChanged(const QString &arg1);
  66. public slots:
  67. /*!
  68. * \brief invokes setupModelAndView() to account for changes the user has made in the SettingsWidget
  69. */
  70. void onPilotsWidget_settingChanged(SettingsWidget::SettingSignal signal);
  71. /*!
  72. * \brief Refreshes the view if the Database has been altered from outside the AircraftWidget
  73. */
  74. void onPilotsWidget_databaseUpdated();
  75. /*!
  76. * \brief PilotsWidget::repopulateModel (public slot) - re-populates the model to cater for a change
  77. * to the database connection (for example, when a backup is created)
  78. */
  79. void repopulateModel();
  80. private:
  81. Ui::PilotsWidget *ui;
  82. QSqlTableModel *model;
  83. QTableView *view;
  84. QItemSelectionModel* selectionModel;
  85. qint32 sortColumn;
  86. QVector<qint32> selectedPilots;
  87. const QString getPilotName(const OPL::PilotEntry &pilot);
  88. const QString getFlightSummary(const OPL::FlightEntry &flight) const;
  89. void setupModelAndView();
  90. void connectSignalsAndSlots();
  91. inline void refreshView(){model->select();}
  92. protected:
  93. /*!
  94. * \brief Handles change events, like updating the UI to new localisation
  95. */
  96. void changeEvent(QEvent* event) override;
  97. };
  98. #endif // PILOTSWIDGET_H