aircraftwidget.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. * \abstract 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. class AircraftWidget : public QWidget
  46. {
  47. Q_OBJECT
  48. public:
  49. explicit AircraftWidget(QWidget *parent = nullptr);
  50. ~AircraftWidget();
  51. private slots:
  52. void tableView_selectionChanged();
  53. void tableView_headerClicked(int column);
  54. void on_deleteAircraftButton_clicked();
  55. void on_newAircraftButton_clicked();
  56. void onNewTailDialog_editingFinished();
  57. void on_aircraftSearchLineEdit_textChanged(const QString &arg1);
  58. public slots:
  59. /*!
  60. * \brief invokes setupModelAndView() to account for changes the user has made in the SettingsWidget
  61. */
  62. void onAircraftWidget_settingChanged(SettingsWidget::SettingSignal signal);
  63. /*!
  64. * \brief Refreshes the view if the Database has been altered from outside the AircraftWidget
  65. */
  66. void onAircraftWidget_dataBaseUpdated();
  67. private:
  68. Ui::AircraftWidget *ui;
  69. QSqlTableModel *model;
  70. QTableView *view;
  71. QItemSelectionModel* selection;
  72. qint32 sortColumn;
  73. /*!
  74. * \brief selectedTails Holds a list of the entries the user has selected
  75. */
  76. QVector<qint32> selectedTails;
  77. void setupModelAndView();
  78. void onDeleteUnsuccessful();
  79. inline void refreshView(){model->select();}
  80. };
  81. #endif // AIRCRAFTWIDGET_H