openPilotLog
logbookwidget.h
1 /*
2  *openPilotLog - A FOSS Pilot Logbook Application
3  *Copyright (C) 2020-2022 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 LOGBOOKWIDGET_H
19 #define LOGBOOKWIDGET_H
20 
21 #include <QWidget>
22 #include <QItemSelection>
23 #include <QSqlTableModel>
24 #include <QMessageBox>
25 #include <QDebug>
26 #include <QMenu>
27 #include <QTableView>
28 #include "src/gui/widgets/settingswidget.h"
29 #include "src/database/dbcompletiondata.h"
30 #include "src/opl.h"
31 
32 namespace Ui {
33 class LogbookWidget;
34 }
35 
47 class LogbookWidget : public QWidget
48 {
49  Q_OBJECT
50 
51 public:
52  explicit LogbookWidget(OPL::DbCompletionData &completion_data, QWidget *parent = nullptr);
53  ~LogbookWidget();
54 
55 private slots:
56  void flightsTableView_selectionChanged();
57  void on_tableView_customContextMenuRequested(const QPoint &pos);
58  void on_actionDelete_Flight_triggered();
59 
60  void on_tableView_doubleClicked();
61  void on_flightSearchLlineEdit_textChanged(const QString &arg1);
62  void on_flightSearchComboBox_currentIndexChanged(int);
63 
64  void on_viewsComboBox_currentIndexChanged(int index);
65 
66  void on_actionEdit_Flight_triggered();
67  void on_actionEdit_Sim_triggered();
68 
69 public slots:
70  void refresh();
71  void onLogbookWidget_viewSelectionChanged(SettingsWidget::SettingSignal signal);
72  void repopulateModel();
73 
74 private:
75  Ui::LogbookWidget *ui;
76 
77  QTableView* view;
78 
79  QSqlTableModel* displayModel;
80 
81  QItemSelectionModel* selectionModel;
82 
83  QMenu* menu;
84 
85  QList<int> selectedEntries;
86 
87  void setupModelAndView(int view_id);
88  void connectSignalsAndSlots();
89 
90  const QString getFlightSummary(const OPL::FlightEntry &flight) const;
91 
92  OPL::DbCompletionData completionData;
93 
101  inline bool isFlight(int model_row_id) { return model_row_id > 0; }
102 
103 protected:
107  void changeEvent(QEvent* event) override;
108 };
109 
110 #endif // LOGBOOKWIDGET_H
The LogbookWidget displays data from the database in a QSqlTableView fed by a QSqlQuery Model.
Definition: logbookwidget.h:48
void changeEvent(QEvent *event) override
Handles change events, like updating the UI to new localisation.
Definition: logbookwidget.cpp:117
void refresh()
LogbookWidget::refresh Refreshes the view to reflect changes in the database.
Definition: logbookwidget.cpp:231
void repopulateModel()
LogbookWidget::repopulateModel (public slot) - cleanly re-populates the model to cater for a change t...
Definition: logbookwidget.cpp:282
Provides data for QCompleters and QHashs.
Definition: dbcompletiondata.h:48
A Row representing a Flight entry. See Row class for details.
Definition: row.h:133
SettingSignal
enumerates Widgets that need to receive a signal when a setting is updated.
Definition: settingswidget.h:51