newacft.cpp 5.3 KB

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