aircraftwidget.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 AIRCRAFTWIDGET_H
  19. #define AIRCRAFTWIDGET_H
  20. #include <QWidget>
  21. #include <QItemSelection>
  22. #include <QSqlTableModel>
  23. #include <QTableView>
  24. #include "src/gui/widgets/settingswidget.h"
  25. namespace Ui {
  26. class AircraftWidget;
  27. }
  28. /*!
  29. * \class AircraftWidget
  30. * \brief The AircraftWidget is used to view, edit, delete or add new tails.
  31. * \details The widget consists of two main parts, a *QTableView* on the left side and a *QStackedWidget* on the right side.
  32. *
  33. * In the QTableView, a QSqlTableModel is used to access a view from the database, which holds a tails' Registration, Type and
  34. * Company.
  35. *
  36. * The welcome page shown on the QStackedWidget on the right side has a QLineEdit that functions as a search box and a QCombobox
  37. * 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
  38. * QSqlTableModel, so the view is updated in real time.
  39. *
  40. * The *NewTailDialog* is used for creating a new entry as well as for editing an existing entry. If the user selects a row
  41. * in the QTableView, the NewTailDilog is displayed on the right side of the Widget, inside the QStackedWidget.
  42. * In order to avoid leaks from any previously made selections, existing Dialogs are deleted before a new one is created.
  43. * The NewTailDialog's `accepted` and `rejected` signals are connected to refresh the view as required.
  44. *
  45. * Note: The ATailEntry class is used to operate on individual aircraft, whereas the AAircraftEntry class is used to retreive
  46. * templates of aircraft types. For example, 'D-ABCD' and 'N-XYZ' are different tails (Registrations), but they might be the same type of aircraft,
  47. * for example 'Boeing 737-800'.
  48. */
  49. class AircraftWidget : public QWidget
  50. {
  51. Q_OBJECT
  52. public:
  53. explicit AircraftWidget(QWidget *parent = nullptr);
  54. ~AircraftWidget();
  55. private slots:
  56. void tableView_selectionChanged();
  57. void tableView_headerClicked(int column);
  58. void on_deleteAircraftButton_clicked();
  59. void on_newAircraftButton_clicked();
  60. void onNewTailDialog_editingFinished();
  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. void setupModelAndView();
  87. void connectSignalsAndSlots();
  88. void onDeleteUnsuccessful();
  89. inline void refreshView(){model->select();}
  90. };
  91. #endif // AIRCRAFTWIDGET_H