2
0

pilotswidget.h 4.5 KB

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