newflightdialog.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. *openPilot Log - A FOSS Pilot Logbook Application
  3. *Copyright (C) 2020 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 NEWFLIGHT_H
  19. #define NEWFLIGHT_H
  20. #include <QDialog>
  21. #include <QRegularExpression>
  22. #include <QMessageBox>
  23. #include <QDebug>
  24. #include <QCompleter>
  25. #include <QStringList>
  26. #include <QButtonGroup>
  27. #include <QBitArray>
  28. #include <QLineEdit>
  29. #include <QCalendarWidget>
  30. #include <QTabWidget>
  31. #include <QKeyEvent>
  32. #include "src/functions/atime.h"
  33. #include "src/classes/aflightentry.h"
  34. #include "src/classes/apilotentry.h"
  35. #include "src/classes/atailentry.h"
  36. namespace Ui {
  37. class NewFlight;
  38. }
  39. class NewFlightDialog : public QDialog
  40. {
  41. Q_OBJECT
  42. public:
  43. /*!
  44. * \brief NewFlightDialog create a new flight and add it to the logbook.
  45. */
  46. explicit NewFlightDialog(QWidget *parent = nullptr);
  47. /*!
  48. * \brief NewFlightDialog Edit an existing logbook entry.
  49. */
  50. explicit NewFlightDialog(int row_id, QWidget *parent = nullptr);
  51. ~NewFlightDialog();
  52. private slots:
  53. void onToUpperTriggered_textChanged(const QString&);
  54. void onPilotNameLineEdit_editingFinished();
  55. void onLocationEditingFinished(QLineEdit*, QLabel*);
  56. void onTimeLineEdit_editingFinished();
  57. void onCompleter_highlighted(const QString&);
  58. void onCompleter_activated(const QString &);
  59. void onCalendarWidget_clicked(const QDate &date);
  60. void onCalendarWidget_selected(const QDate &date);
  61. void onDoftLineEdit_entered();
  62. void on_calendarCheckBox_stateChanged(int arg1);
  63. void on_doftLineEdit_editingFinished();
  64. void on_cancelButton_clicked();
  65. void on_submitButton_clicked();
  66. void on_setAsDefaultButton_clicked();
  67. void on_restoreDefaultButton_clicked();
  68. void on_PilotFlyingCheckBox_stateChanged(int arg1);
  69. void on_IfrCheckBox_stateChanged(int);
  70. void on_manualEditingCheckBox_stateChanged(int arg1);
  71. void on_ApproachComboBox_currentTextChanged(const QString &arg1);
  72. void on_FunctionComboBox_currentIndexChanged(int index);
  73. void on_deptLocLineEdit_editingFinished();
  74. void on_destLocLineEdit_editingFinished();
  75. void on_acftLineEdit_editingFinished();
  76. private:
  77. Ui::NewFlight *ui;
  78. /*!
  79. * \brief a AFlightEntry object that is used to store either position data
  80. * from an old entry, is used to fill the form for editing an entry, or is
  81. * filled with new data for adding a new entry to the logbook.
  82. */
  83. AFlightEntry flightEntry;
  84. QList<QLineEdit*> mandatoryLineEdits;
  85. QList<QLineEdit*> primaryTimeLineEdits;
  86. QList<QLineEdit*> pilotsLineEdits;
  87. /*!
  88. * \brief holds a bit for each mandatory line edit that is flipped
  89. * according to its validity state
  90. */
  91. QBitArray mandatoryLineEditsGood;
  92. /*!
  93. * To be used by the QCompleters
  94. */
  95. QStringList pilotList;
  96. QStringList tailsList;
  97. QStringList airportList;
  98. /*!
  99. * \brief Used to map user input to database keys
  100. */
  101. QMap<QString, int> pilotsIdMap;
  102. QMap<QString, int> tailsIdMap;
  103. QMap<QString, int> airportIcaoIdMap;
  104. QMap<QString, int> airportIataIdMap;
  105. QMap<QString, int> airportNameIdMap;
  106. opl::time::FlightTimeFormat flightTimeFormat;
  107. /*!
  108. * \brief If the user elects to manually edit function times, automatic updating
  109. * is disabled.
  110. */
  111. bool updateEnabled;
  112. void setup();
  113. void readSettings();
  114. void writeSettings();
  115. void setupButtonGroups();
  116. void setPopUpCalendarEnabled(bool state);
  117. void setupRawInputValidation();
  118. void setupSignalsAndSlots();
  119. void formFiller();
  120. void fillDeductibleData();
  121. void onMandatoryLineEditsFilled();
  122. void onGoodInputReceived(QLineEdit*);
  123. void onBadInputReceived(QLineEdit *);
  124. bool eventFilter(QObject *object, QEvent *event);
  125. bool isLessOrEqualThanBlockTime(const QString time_string);
  126. void addNewTail(QLineEdit*);
  127. void addNewPilot(QLineEdit *);
  128. RowData collectInput();
  129. /*!
  130. * \brief converts a time string as used in the UI to an integer of minutes for
  131. * use in the database based on the format in use in the Dialog
  132. */
  133. inline int stringToMinutes(const QString &time_string, opl::time::FlightTimeFormat format)
  134. {
  135. return ATime::toMinutes(ATime::fromString(time_string, format));
  136. }
  137. /*!
  138. * \brief minutesToString converts an integer of minutes as received from the database
  139. * to a String to be displayed in the UI, based on the format in use in the Dialog.
  140. */
  141. inline QString minutesToString(const int minutes, opl::time::FlightTimeFormat format)
  142. {
  143. return ATime::toString(ATime::fromMinutes(minutes), format);
  144. }
  145. };
  146. #endif // NEWFLIGHT_H