newacft.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 "newacft.h"
  19. #include "ui_newacft.h"
  20. #include "showaircraftlist.h"
  21. #include <QStringListModel>
  22. #include <QSortFilterProxyModel>
  23. #include <QCompleter>
  24. #include <QDebug>
  25. #include <QMessageBox>
  26. #include <QSqlQueryModel> // test
  27. QString registration = "invalid";
  28. QString make = "invalid";
  29. QString model = "invalid";
  30. QString variant = "invalid";
  31. QString aircraft_id = "0";
  32. NewAcft::NewAcft(QWidget *parent) :
  33. QDialog(parent),
  34. ui(new Ui::NewAcft)
  35. {
  36. ui->setupUi(this);
  37. }
  38. NewAcft::~NewAcft()
  39. {
  40. delete ui;
  41. }
  42. void NewAcft::on_MakeLineEdit_textEdited(const QString &arg1)
  43. {
  44. QStringList makeList = dbAircraft::retreiveAircraftMake(arg1);
  45. makeList.removeDuplicates();
  46. QCompleter *makeCompleter = new QCompleter(makeList, this);
  47. makeCompleter->setCaseSensitivity(Qt::CaseInsensitive);
  48. makeCompleter->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
  49. ui->MakeLineEdit->setCompleter(makeCompleter);
  50. }
  51. void NewAcft::on_MakeLineEdit_editingFinished()
  52. {
  53. QStringList makeList = dbAircraft::retreiveAircraftMake(ui->MakeLineEdit->text());
  54. if(makeList.length() != 0)
  55. {
  56. make = makeList.first();
  57. ui->MakeLineEdit->setText(make);
  58. }else
  59. {
  60. QMessageBox msgBox;
  61. msgBox.setText("No Airplane Maker with that name found.");
  62. msgBox.exec();
  63. ui->MakeLineEdit->setText("");
  64. }
  65. }
  66. void NewAcft::on_ModelLineEdit_textEdited(const QString &arg1)
  67. {
  68. QStringList modelList = dbAircraft::retreiveAircraftModel(make, arg1);
  69. modelList.removeDuplicates();
  70. QCompleter *modelCompleter = new QCompleter(modelList, this);
  71. modelCompleter->setCaseSensitivity(Qt::CaseInsensitive);
  72. modelCompleter->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
  73. ui->ModelLineEdit->setCompleter(modelCompleter);
  74. }
  75. void NewAcft::on_ModelLineEdit_editingFinished()
  76. {
  77. QStringList modelList = dbAircraft::retreiveAircraftModel(make, ui->ModelLineEdit->text());
  78. if(modelList.length() != 0)
  79. {
  80. model = modelList.first();
  81. ui->ModelLineEdit->setText(model);
  82. }else
  83. {
  84. QMessageBox msgBox;
  85. msgBox.setText("No Model (Type) with that name found.");
  86. msgBox.exec();
  87. ui->ModelLineEdit->setText("");
  88. }
  89. }
  90. void NewAcft::on_VariantLineEdit_textEdited(const QString &arg1)
  91. {
  92. QStringList variantList = dbAircraft::retreiveAircraftVariant(make, model, arg1);
  93. variantList.removeDuplicates();
  94. QCompleter *variantCompleter = new QCompleter(variantList, this);
  95. variantCompleter->setCaseSensitivity(Qt::CaseInsensitive);
  96. variantCompleter->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
  97. ui->VariantLineEdit->setCompleter(variantCompleter);
  98. }
  99. void NewAcft::on_VariantLineEdit_editingFinished()
  100. {
  101. QStringList VariantList = dbAircraft::retreiveAircraftVariant(make, model, ui->VariantLineEdit->text());
  102. if(VariantList.length() != 0)
  103. {
  104. variant = VariantList.first();
  105. ui->VariantLineEdit->setText(variant);
  106. }else
  107. {
  108. QMessageBox msgBox;
  109. msgBox.setText("No Variant found. Are you sure you want to proceed?");
  110. msgBox.exec();
  111. ui->VariantLineEdit->setText("");
  112. }
  113. }
  114. void NewAcft::on_buttonBox_accepted()
  115. {
  116. qDebug() << "Accepted Button pressed";
  117. aircraft_id = dbAircraft::retreiveAircraftIdFromMakeModelVariant(make, model, variant);
  118. if(aircraft_id.contains("0") && aircraft_id.length() < 2)
  119. {
  120. QMessageBox nope;
  121. nope.setText("EASA FCL.050 requires Pilots to record details of:\n\n"
  122. "Make\t e.g. Boeing\nModel\t e.g. 737\nVariant\t e.g. 800\n\nRegistration\n\n"
  123. "Please check or edit the aircraft database.");
  124. nope.exec();
  125. }else
  126. {
  127. dbAircraft::commitTailToDb(registration, aircraft_id, "");
  128. NewAcft::reject();
  129. }
  130. }
  131. void NewAcft::on_buttonBox_rejected()
  132. {
  133. make = "xxx";
  134. model = "xxx";
  135. variant = "xxx";
  136. aircraft_id = "0";
  137. NewAcft::reject();
  138. }
  139. void NewAcft::on_VerifyButton_clicked()
  140. {
  141. if(ui->EasaEnabledCheckBox->isChecked())
  142. {
  143. QString checkstring = "[ " + registration + " ] " + make + " " + model + "-" + variant;
  144. ui->VerifyLineEdit->setText(checkstring);
  145. }else
  146. {
  147. ui->VerifyLineEdit->setText("EASA FCL.050 compliance checks disabled.");
  148. }
  149. }
  150. void NewAcft::on_RegistrationLineEdit_editingFinished()
  151. {
  152. registration = ui->RegistrationLineEdit->text();
  153. }
  154. void NewAcft::on_EasaEnabledCheckBox_stateChanged()
  155. {
  156. QMessageBox nope;
  157. nope.setText("Data Input without Format checking may corrupt the database.");
  158. nope.exec();
  159. }
  160. void NewAcft::on_showAllPushButton_clicked()
  161. {
  162. ShowAircraftList sa(this);
  163. sa.exec();
  164. }