2
0

tailswidget.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 TAILSWIDGET_H
  19. #define TAILSWIDGET_H
  20. #include <QWidget>
  21. #include <QItemSelection>
  22. #include <QSqlTableModel>
  23. #include <QTableView>
  24. #include "src/database/flightentry.h"
  25. #include "src/gui/widgets/settingswidget.h"
  26. namespace Ui {
  27. class AircraftWidget;
  28. }
  29. /*!
  30. * \class AircraftWidget
  31. * \brief The AircraftWidget is used to view, edit, delete or add new tails.
  32. * \details The widget consists of two main parts, a *QTableView* on the left side and a *QStackedWidget* on the right side.
  33. *
  34. * In the QTableView, a QSqlTableModel is used to access a view from the database, which holds a tails' Registration, Type and
  35. * Company.
  36. *
  37. * The welcome page shown on the QStackedWidget on the right side has a QLineEdit that functions as a search box and a QCombobox
  38. * 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
  39. * QSqlTableModel, so the view is updated in real time.
  40. *
  41. * The *NewTailDialog* is used for creating a new entry as well as for editing an existing entry. If the user selects a row
  42. * in the QTableView, the NewTailDilog is displayed on the right side of the Widget, inside the QStackedWidget.
  43. * In order to avoid leaks from any previously made selections, existing Dialogs are deleted before a new one is created.
  44. * The NewTailDialog's `accepted` and `rejected` signals are connected to refresh the view as required.
  45. *
  46. * Note: The ATailEntry class is used to operate on individual aircraft, whereas the AAircraftEntry class is used to retreive
  47. * templates of aircraft types. For example, 'D-ABCD' and 'N-XYZ' are different tails (Registrations), but they might be the same type of aircraft,
  48. * for example 'Boeing 737-800'.
  49. */
  50. class TailsWidget : public QWidget
  51. {
  52. Q_OBJECT
  53. public:
  54. explicit TailsWidget(QWidget *parent = nullptr);
  55. ~TailsWidget();
  56. private slots:
  57. void tableView_selectionChanged();
  58. void tableView_headerClicked(int column);
  59. void on_deleteAircraftButton_clicked();
  60. void on_newAircraftButton_clicked();
  61. void on_aircraftSearchLineEdit_textChanged(const QString &arg1);
  62. public slots:
  63. /*!
  64. * \brief invokes setupModelAndView() to account for changes the user has made in the SettingsWidget
  65. */
  66. void onAircraftWidget_settingChanged(SettingsWidget::SettingSignal signal);
  67. /*!
  68. * \brief Refreshes the view if the Database has been altered from outside the AircraftWidget
  69. */
  70. void onAircraftWidget_dataBaseUpdated();
  71. /*!
  72. * \brief AircraftWidget::repopulateModel (public slot) - re-populates the model to cater for a change
  73. * to the database connection (for example, when a backup is created)
  74. */
  75. void repopulateModel();
  76. private:
  77. Ui::AircraftWidget *ui;
  78. QSqlTableModel *model;
  79. QTableView *view;
  80. QItemSelectionModel* selection;
  81. qint32 sortColumn;
  82. /*!
  83. * \brief selectedTails Holds a list of the entries the user has selected
  84. */
  85. QVector<qint32> selectedTails;
  86. const QString getAircraftTypeString(const OPL::Row &row) const;
  87. const QString getFlightSummary(const OPL::FlightEntry &flight) const;
  88. void setupModelAndView();
  89. void connectSignalsAndSlots();
  90. void onDeleteUnsuccessful();
  91. void setUiEnabled(bool enabled);
  92. inline void refreshView(){model->select();}
  93. protected:
  94. /*!
  95. * \brief Handles change events, like updating the UI to new localisation
  96. */
  97. void changeEvent(QEvent* event) override;
  98. };
  99. #endif // TAILSWIDGET_H