aflightentry.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #include "aflightentry.h"
  19. #include "src/database/adatabase.h"
  20. AFlightEntry::AFlightEntry()
  21. : AEntry::AEntry(DEFAULT_FLIGHT_POSITION)
  22. {}
  23. AFlightEntry::AFlightEntry(RowId row_id)
  24. : AEntry::AEntry(DataPosition(DB_TABLE_FLIGHTS, row_id))
  25. {}
  26. AFlightEntry::AFlightEntry(RowData table_data)
  27. : AEntry::AEntry(DEFAULT_FLIGHT_POSITION, table_data)
  28. {}
  29. const QString AFlightEntry::summary()
  30. {
  31. if(tableData.isEmpty())
  32. return QString();
  33. QString flight_summary;
  34. flight_summary.append(tableData.value(DB_FLIGHTS_DOFT).toString() + " ");
  35. flight_summary.append(tableData.value(DB_FLIGHTS_DEPT).toString() + " ");
  36. flight_summary.append(ACalc::minutesToString(tableData.value(DB_FLIGHTS_TOFB).toString()) + " ");
  37. flight_summary.append(ACalc::minutesToString(tableData.value(DB_FLIGHTS_TONB).toString()) + " ");
  38. flight_summary.append(tableData.value(DB_FLIGHTS_DEST).toString() + " ");
  39. return flight_summary;
  40. }
  41. const QString AFlightEntry::getRegistration()
  42. {
  43. ATailEntry acft = aDB->resolveForeignTail(tableData.value(DB_FLIGHTS_ACFT).toInt());
  44. return acft.registration();
  45. }
  46. const QString AFlightEntry::getPilotName(pilotPosition pilot_)
  47. {
  48. switch (pilot_) {
  49. case pilotPosition::pic: {
  50. auto foreign_pilot = aDB->resolveForeignPilot(tableData.value(DB_FLIGHTS_PIC).toInt());
  51. return foreign_pilot.name();
  52. break;
  53. }
  54. case pilotPosition::secondPilot: {
  55. auto foreign_pilot = aDB->resolveForeignPilot(tableData.value(DB_FLIGHTS_SECONDPILOT).toInt());
  56. return foreign_pilot.name();
  57. }
  58. case pilotPosition::thirdPilot: {
  59. auto foreign_pilot = aDB->resolveForeignPilot(tableData.value(DB_FLIGHTS_THIRDPILOT).toInt());
  60. return foreign_pilot.name();
  61. break;
  62. } // case scope
  63. } // switch (pilot_)
  64. return QString();
  65. }