newflight.cpp 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  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 "newflight.h"
  19. #include "ui_newflight.h"
  20. #include "dbman.cpp"
  21. #include <QMessageBox>
  22. #include <QDebug>
  23. #include <QCompleter>
  24. #include <QStringList>
  25. #include <QStringListModel>
  26. #include <QSortFilterProxyModel>
  27. #include <QButtonGroup>
  28. /*
  29. * Debug / WIP
  30. */
  31. void NewFlight::on_verifyButton_clicked()//debug
  32. {
  33. /*on_newDoft_editingFinished();// - activate slots in case user has been active in last input before clicking submit
  34. on_newTonb_editingFinished();
  35. on_newTofb_editingFinished();
  36. on_newDept_editingFinished();
  37. on_newDest_editingFinished();
  38. on_newAcft_editingFinished();
  39. on_newPic_editingFinished();
  40. verifyInput();*/
  41. fillExtrasLineEdits();
  42. }
  43. void NewFlight::on_tabWidget_tabBarClicked(int index)
  44. {
  45. if(index == 1){
  46. nope();
  47. }
  48. }
  49. /*
  50. * Initialise variables
  51. */
  52. QDate date(QDate::currentDate());
  53. QString doft(QDate::currentDate().toString(Qt::ISODate));
  54. QString dept;
  55. QString dest;
  56. QTime tofb;
  57. QTime tonb;
  58. QTime tblk;
  59. QString pic;
  60. QString acft;
  61. QVector<QString> flight;
  62. // extras
  63. QString secondPilot;
  64. QString thirdPilot;
  65. QString PilotFunction;
  66. QString PilotTask;
  67. QString TakeOff;
  68. QString Landing;
  69. QString Autoland;
  70. QString ApproachType;
  71. /*
  72. * Window
  73. */
  74. NewFlight::NewFlight(QWidget *parent) :
  75. QDialog(parent),
  76. ui(new Ui::NewFlight)
  77. {
  78. ui->setupUi(this);
  79. ui->newDoft->setDate(QDate::currentDate());
  80. bool hasoldinput = dbFlight::checkScratchpad();
  81. qDebug() << "Hasoldinput? = " << hasoldinput;
  82. if(hasoldinput) // Re-populate the Form
  83. {
  84. flight = dbFlight::retreiveScratchpad();
  85. qDebug() << "Re-Filling Form from Scratchpad";
  86. returnInput(flight);
  87. }
  88. // Validators for Line Edits
  89. QRegExp icao_rx("[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]"); // allow only letters (upper and lower)
  90. QValidator *ICAOvalidator = new QRegExpValidator(icao_rx, this);
  91. ui->newDept->setValidator(ICAOvalidator);
  92. ui->newDest->setValidator(ICAOvalidator);
  93. QRegExp timehhmm("([01]?[0-9]?|2[0-3]):?[0-5][0-9]?"); //allows time in 24h format with optional leading 0 and with or without seperator
  94. QValidator *timeInputValidator = new QRegExpValidator(timehhmm, this);
  95. ui->newTofb->setValidator(timeInputValidator);
  96. ui->newTonb->setValidator(timeInputValidator);
  97. ui->spseTimeLineEdit->setValidator(timeInputValidator);
  98. ui->spmeTimeLineEdit->setValidator(timeInputValidator);
  99. ui->mpTimeLineEdit->setValidator(timeInputValidator);
  100. ui->totalTimeLineEdit->setValidator(timeInputValidator);
  101. ui->ifrTimeLineEdit->setValidator(timeInputValidator);
  102. ui->vfrTimeLineEdit->setValidator(timeInputValidator);
  103. ui->nightTimeLineEdit->setValidator(timeInputValidator);
  104. ui->xcTimeLineEdit->setValidator(timeInputValidator);
  105. ui->picTimeLineEdit->setValidator(timeInputValidator);
  106. ui->copTimeLineEdit->setValidator(timeInputValidator);
  107. ui->dualTimeLineEdit->setValidator(timeInputValidator);
  108. ui->fiTimeLineEdit->setValidator(timeInputValidator);
  109. ui->simTimeLineEdit->setValidator(timeInputValidator);
  110. QRegExp picname("^[a-zA-Z_]+,?( [a-zA-Z_]+)*$");// allow only lastname, firstname or lastname firstname with one whitespace
  111. QValidator *picNameValidator = new QRegExpValidator(picname, this);
  112. ui->newPic->setValidator(picNameValidator);
  113. ui->secondPilotLineEdit->setValidator(picNameValidator);
  114. ui->thirdPilotLineEdit->setValidator(picNameValidator);
  115. // Groups for CheckBoxes
  116. QButtonGroup *FlightRulesGroup = new QButtonGroup(this);
  117. FlightRulesGroup->addButton(ui->IfrCheckBox);
  118. FlightRulesGroup->addButton(ui->VfrCheckBox);
  119. QButtonGroup *PilotTaskGroup = new QButtonGroup(this);
  120. PilotTaskGroup->addButton(ui->PilotFlyingCheckBox);
  121. PilotTaskGroup->addButton(ui->PilotMonitoringCheckBox);
  122. restoreSettings();
  123. ui->deptTZ->setFocusPolicy(Qt::NoFocus);
  124. ui->destTZ->setFocusPolicy(Qt::NoFocus);
  125. ui->newDept->setFocus();
  126. }
  127. NewFlight::~NewFlight()
  128. {
  129. delete ui;
  130. }
  131. /*
  132. * Functions
  133. */
  134. void NewFlight::nope()
  135. {
  136. QMessageBox nope(this); //error box
  137. nope.setText("This feature is not yet available!");
  138. nope.exec();
  139. }
  140. /*!
  141. * \brief NewFlight::validateTimeInput verifies user input and formats to hh:mm
  142. * if the output is not a valid time, an empty string is returned.
  143. * \param userinput from a QLineEdit
  144. * \return formatted QString "hh:mm" or Empty String
  145. */
  146. QString NewFlight::validateTimeInput(QString userinput)
  147. {
  148. QString output; //
  149. QTime temptime; //empty time object is invalid by default
  150. bool containsSeperator = userinput.contains(":");
  151. if(userinput.length() == 4 && !containsSeperator)
  152. {
  153. temptime = QTime::fromString(userinput,"hhmm");
  154. }else if(userinput.length() == 3 && !containsSeperator)
  155. {
  156. if(userinput.toInt() < 240) //Qtime is invalid if time is between 000 and 240 for this case
  157. {
  158. QString tempstring = userinput.prepend("0");
  159. temptime = QTime::fromString(tempstring,"hhmm");
  160. }else
  161. {
  162. temptime = QTime::fromString(userinput,"Hmm");
  163. }
  164. }else if(userinput.length() == 4 && containsSeperator)
  165. {
  166. temptime = QTime::fromString(userinput,"h:mm");
  167. }else if(userinput.length() == 5 && containsSeperator)
  168. {
  169. temptime = QTime::fromString(userinput,"hh:mm");
  170. }
  171. output = temptime.toString("hh:mm");
  172. if(output.isEmpty())
  173. {
  174. QMessageBox timeformat(this);
  175. timeformat.setText("Please enter a valid time. Any of these formats is valid:\n845 0845 8:45 08:45");
  176. timeformat.exec();
  177. }
  178. return output;
  179. }
  180. /*!
  181. * \brief NewFlight::fillExtrasLineEdits Fills the flight time line edits according to ui selections
  182. */
  183. void NewFlight::fillExtrasLineEdits()
  184. {
  185. // SP SE
  186. // SP ME
  187. // MP
  188. // TOTAL
  189. if(tofb.isValid() && tonb.isValid()) {
  190. ui->totalTimeLineEdit->setText(calc::blocktime(tofb,tonb).toString("hh:mm"));
  191. }
  192. // IFR
  193. // VFR
  194. // Night
  195. if(tofb.isValid() && tonb.isValid() && dept.length() == 4 && dest.length() == 4) {
  196. QString deptDate = date.toString(Qt::ISODate) + 'T' + tofb.toString("hh:mm");
  197. qDebug() << "Departure Date: " << deptDate;
  198. QDateTime deptDateTime = QDateTime::fromString(deptDate,"yyyy-MM-ddThh:mm");
  199. qDebug() << "Departure DateTime " << deptDateTime;
  200. int blocktime = calc::time_to_minutes(calc::blocktime(tofb,tonb));
  201. qDebug() << "Blocktime: " << blocktime;
  202. //qDebug() << calc::calculateNightTime(dept, dest, deptDateTime, blocktime);
  203. //qDebug() << calc::minutes_to_string(QString::number(calc::calculateNightTime(dept, dest, deptDateTime, blocktime)));
  204. ui->nightTimeLineEdit->setText(calc::minutes_to_string(QString::number(calc::calculateNightTime(dept, dest, deptDateTime, blocktime))));
  205. }
  206. // XC
  207. // PIC
  208. // Co-Pilot
  209. // Dual
  210. // FI
  211. // SIM
  212. }
  213. QVector<QString> NewFlight::collectInput()
  214. {
  215. // Collect input from the user fields and return a vector containing the flight information
  216. QString doft = date.toString(Qt::ISODate); // Format Date
  217. QTime tblk = calc::blocktime(tofb,tonb); // Calculate Blocktime
  218. // Prepare Vector for commit to database
  219. flight = dbFlight::createFlightVectorFromInput(doft, dept, tofb, dest, tonb, tblk, pic, acft);
  220. qDebug() << "Created flight vector:" << flight;
  221. return flight;
  222. }
  223. bool NewFlight::verifyInput()
  224. //check if the input is correctly formatted and all required fields are filled
  225. {
  226. bool deptValid = false;
  227. bool tofbValid = false;
  228. bool destValid = false;
  229. bool tonbValid = false;
  230. bool tblkValid = false;
  231. bool picValid = false;
  232. bool acftValid = false;
  233. QTime tblk = calc::blocktime(tofb,tonb);
  234. int checktblk = calc::time_to_minutes(tblk);
  235. bool doftValid = true; //doft assumed to be always valid due to QDateTimeEdit constraints
  236. qDebug() << "NewFlight::verifyInput() says: Date:" << doft << " - Valid?\t" << doftValid;
  237. deptValid = db::CheckICAOValid(dept);
  238. qDebug() << "NewFlight::verifyInput() says: Departure is:\t" << dept << " - Valid?\t" << deptValid;
  239. destValid = db::CheckICAOValid(dest);
  240. qDebug() << "NewFlight::verifyInput() says: Destination is:\t" << dest << " - Valid?\t" << destValid;
  241. tofbValid = (unsigned)(calc::time_to_minutes(tofb)-0) <= (1440-0) && tofb.toString("hh:mm") != ""; // Make sure time is within range, DB 1 day = 1440 minutes. 0 is allowed (midnight) & that it is not empty.
  242. qDebug() << "NewFlight::verifyInput() says: tofb is:\t\t" << tofb.toString("hh:mm") << " - Valid?\t" << tofbValid;
  243. tonbValid = (unsigned)(calc::time_to_minutes(tonb)-0) <= (1440-0) && tonb.toString("hh:mm") != ""; // Make sure time is within range, DB 1 day = 1440 minutes
  244. qDebug() << "NewFlight::verifyInput() says: tonb is:\t\t" << tonb.toString("hh:mm")<< " - Valid?\t" << tonbValid;
  245. picValid = (pic.toInt() > 0); // pic should be a pilot_id retreived from the database
  246. qDebug() << "NewFlight::verifyInput() says: pic is pilotd_id:\t" << pic << " - Valid?\t" << picValid;
  247. if(!picValid)
  248. {
  249. QMessageBox msgBox(this);
  250. msgBox.setText("You cannot log a flight without a valid pilot");
  251. msgBox.exec();
  252. }
  253. acftValid = (acft.toInt() > 0);
  254. qDebug() << "NewFlight::verifyInput() says: acft is tail_id:\t" << acft << " - Valid?\t" << acftValid;
  255. if(!acftValid)
  256. {
  257. QMessageBox msgBox(this);
  258. msgBox.setText("You cannot log a flight without a valid aircraft");
  259. msgBox.exec();
  260. }
  261. tblkValid = checktblk != 0;
  262. qDebug() << "NewFlight::verifyInput() says: tblk is:\t\t" << tblk.toString("hh:mm") << " - Valid?\t" << tblkValid;
  263. if(deptValid && tofbValid && destValid && tonbValid
  264. && tblkValid && picValid && acftValid)
  265. {
  266. qDebug() << "====================================================";
  267. qDebug() << "NewFlight::verifyInput() says: All checks passed! Very impressive. ";
  268. return 1;
  269. }else
  270. {
  271. qDebug() << "====================================================";
  272. qDebug() << "NewFlight::verifyInput() says: Flight is invalid.";
  273. qDebug() << "NewFlight::verifyInput() says: I will call the cops.";
  274. return 0;
  275. }
  276. return 0;
  277. }
  278. void NewFlight::returnInput(QVector<QString> flight)
  279. {
  280. // Re-populates the input masks with the selected fields if input was erroneous to allow for corrections to be made
  281. qDebug() << "return Input: " << flight;
  282. ui->newDoft->setDate(QDate::fromString(flight[1],Qt::ISODate));
  283. ui->newDept->setText(flight[2]);
  284. ui->newTofb->setText(flight[3]);
  285. ui->newDest->setText(flight[4]);
  286. ui->newTonb->setText(flight[5]);
  287. // flight[6] is blocktime
  288. ui->newPic->setText(dbPilots::retreivePilotNameFromID(flight[7]));
  289. ui->newAcft->setText(db::RetreiveRegistration(flight[8]));
  290. }
  291. void NewFlight::storeSettings()
  292. {
  293. qDebug() << "Storing Settings...";
  294. dbSettings::storeSetting(100, ui->FunctionComboBox->currentText());
  295. dbSettings::storeSetting(101, ui->ApproachComboBox->currentText());
  296. dbSettings::storeSetting(102, QString::number(ui->PilotFlyingCheckBox->isChecked()));
  297. dbSettings::storeSetting(103, QString::number(ui->PilotMonitoringCheckBox->isChecked()));
  298. dbSettings::storeSetting(104, QString::number(ui->TakeoffSpinBox->value()));
  299. dbSettings::storeSetting(105, QString::number(ui->TakeoffCheckBox->isChecked()));
  300. dbSettings::storeSetting(106, QString::number(ui->LandingSpinBox->value()));
  301. dbSettings::storeSetting(107, QString::number(ui->LandingCheckBox->isChecked()));
  302. dbSettings::storeSetting(108, QString::number(ui->AutolandSpinBox->value()));
  303. dbSettings::storeSetting(109, QString::number(ui->AutolandCheckBox->isChecked()));
  304. dbSettings::storeSetting(110, QString::number(ui->IfrCheckBox->isChecked()));
  305. dbSettings::storeSetting(111, QString::number(ui->VfrCheckBox->isChecked()));
  306. //dbSettings::storesetting(112, QString::number(ui->autoNightCheckBox->isChecked()));
  307. }
  308. void NewFlight::restoreSettings()
  309. {
  310. qDebug() << "Restoring Settings...";//crashes if db is empty due to QVector index out of range.
  311. ui->FunctionComboBox->setCurrentText(dbSettings::retreiveSetting("100"));
  312. ui->ApproachComboBox->setCurrentText(dbSettings::retreiveSetting("101"));
  313. ui->PilotFlyingCheckBox->setChecked(dbSettings::retreiveSetting("102").toInt());
  314. ui->PilotMonitoringCheckBox->setChecked(dbSettings::retreiveSetting("103").toInt());
  315. ui->TakeoffSpinBox->setValue(dbSettings::retreiveSetting("104").toInt());
  316. ui->TakeoffCheckBox->setChecked(dbSettings::retreiveSetting("105").toInt());
  317. ui->LandingSpinBox->setValue(dbSettings::retreiveSetting("106").toInt());
  318. ui->LandingCheckBox->setChecked(dbSettings::retreiveSetting("107").toInt());
  319. ui->AutolandSpinBox->setValue(dbSettings::retreiveSetting("108").toInt());
  320. ui->AutolandCheckBox->setChecked(dbSettings::retreiveSetting("109").toInt());
  321. ui->IfrCheckBox->setChecked(dbSettings::retreiveSetting("110").toInt());
  322. ui->VfrCheckBox->setChecked(dbSettings::retreiveSetting("111").toInt());
  323. //ui->autoNightCheckBox->setChecked(dbSettings::retreiveSetting("112")[1].toInt());
  324. //qDebug() << "restore Settings ifr to int: " << dbSettings::retreiveSetting("110")[1].toInt();
  325. /*
  326. *
  327. * QString PilotFunction;
  328. QString PilotTask;
  329. QString TakeOff;
  330. QString Landing;
  331. QString Autoland;
  332. QString ApproachType;
  333. 100 PIC NewFlight::FunctionComboBox
  334. 101 ILS CAT I NewFlight::ApproachComboBox
  335. 102 Qt::Checked NewFlight::PilotFlyingCheckBox
  336. 103 Qt::Unchecked NewFlight::PilotMonitoringCheckBox
  337. 104 1 NewFlight::TakeoffSpinBox
  338. 105 Qt::Checked NewFlight::TakeoffCheckBox
  339. 106 1 NewFlight::LandingSpinBox
  340. 107 Qt::Checked NewFlight::LandingCheckBox
  341. 108 0 NewFlight::AutolandSpinBox
  342. 109 Qt::Unchecked NewFlight::AutolandCheckBox
  343. 110 Qt::Checked NewFlight::IfrCheckBox
  344. 111 Qt::Unchecked NewFlight::VfrCheckBox
  345. */
  346. }
  347. /*
  348. * Slots
  349. */
  350. void NewFlight::on_deptTZ_currentTextChanged(const QString &arg1)
  351. {
  352. if(arg1 == "Local"){nope();}
  353. ui->deptTZ->setCurrentIndex(0);
  354. }
  355. void NewFlight::on_destTZ_currentIndexChanged(const QString &arg1)
  356. {
  357. if(arg1 == "Local"){nope();}
  358. ui->destTZ->setCurrentIndex(0);
  359. }
  360. void NewFlight::on_newDept_textEdited(const QString &arg1)
  361. {
  362. ui->newDept->setText(arg1.toUpper());
  363. if(arg1.length()>2)
  364. {
  365. QStringList deptList = db::CompleteIcaoOrIata(arg1);
  366. qDebug() << "deptList = " << deptList;
  367. QCompleter *deptCompleter = new QCompleter(deptList, this);
  368. deptCompleter->setCaseSensitivity(Qt::CaseInsensitive);
  369. deptCompleter->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
  370. ui->newDept->setCompleter(deptCompleter);
  371. }
  372. }
  373. void NewFlight::on_newDept_editingFinished()
  374. {
  375. if(ui->newDept->text().length()<3)
  376. {
  377. QMessageBox msgBox(this);
  378. msgBox.setText("Please enter a 3- or 4-letter code.");
  379. msgBox.exec();
  380. ui->newDept->setText("");
  381. ui->newDept->setFocus();
  382. }
  383. QStringList deptList;
  384. if(ui->newDept->text().length()>1)
  385. {
  386. QStringList deptList = db::CompleteIcaoOrIata(ui->newDept->text());
  387. if(deptList.length() != 0)
  388. {
  389. dept = deptList.first();
  390. ui->newDept->setText(dept);
  391. }else
  392. {
  393. QMessageBox msgBox(this);
  394. msgBox.setText("No Airport with that name found.");
  395. msgBox.exec();
  396. ui->newDept->setText("");
  397. ui->newDept->setFocus();
  398. }
  399. }
  400. }
  401. void NewFlight::on_newDest_textEdited(const QString &arg1)
  402. {
  403. ui->newDest->setText(arg1.toUpper());
  404. if(arg1.length()>2)
  405. {
  406. QStringList destList = db::CompleteIcaoOrIata(arg1);
  407. QCompleter *destCompleter = new QCompleter(destList, this);
  408. destCompleter->setCaseSensitivity(Qt::CaseInsensitive);
  409. destCompleter->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
  410. ui->newDest->setCompleter(destCompleter);
  411. }
  412. }
  413. void NewFlight::on_newDest_editingFinished()
  414. {
  415. if(ui->newDest->text().length()<3)
  416. {
  417. QMessageBox msgBox(this);
  418. msgBox.setText("Please enter a 3- or 4-letter code.");
  419. msgBox.exec();
  420. ui->newDest->setText("");
  421. ui->newDest->setFocus();
  422. }
  423. QStringList destList;
  424. if(ui->newDest->text().length()>1)
  425. {
  426. QStringList destList = db::CompleteIcaoOrIata(ui->newDest->text());
  427. if(destList.length() != 0)
  428. {
  429. dest = destList.first();
  430. ui->newDest->setText(dest);
  431. }else
  432. {
  433. QMessageBox msgBox(this);
  434. msgBox.setText("No Airport with that name found.");
  435. msgBox.exec();
  436. ui->newDest->setText("");
  437. ui->newDest->setFocus();
  438. }
  439. }
  440. }
  441. void NewFlight::on_newDoft_editingFinished()
  442. {
  443. date = ui->newDoft->date();
  444. doft = date.toString(Qt::ISODate);
  445. }
  446. void NewFlight::on_newTofb_editingFinished()
  447. {
  448. ui->newTofb->setText(validateTimeInput(ui->newTofb->text()));
  449. tofb = QTime::fromString(ui->newTofb->text(),"hh:mm");
  450. if(!tofb.isValid()){
  451. ui->newTofb->setStyleSheet("border: 1px solid red");
  452. ui->newTofb->setFocus();
  453. }else{
  454. ui->newTofb->setStyleSheet("");
  455. }
  456. qDebug() << "New Time Off Blocks: " << tofb;
  457. }
  458. void NewFlight::on_newTonb_editingFinished()
  459. {
  460. ui->newTonb->setText(validateTimeInput(ui->newTonb->text()));
  461. tonb = QTime::fromString(ui->newTonb->text(),"hh:mm");
  462. if(!tonb.isValid()){
  463. ui->newTonb->setStyleSheet("border: 1px solid red");
  464. ui->newTonb->setFocus();
  465. }else{
  466. ui->newTonb->setStyleSheet("");
  467. }
  468. qDebug() << "New Time On Blocks: " << tonb;
  469. }
  470. void NewFlight::on_newAcft_textEdited(const QString &arg1)
  471. {
  472. if(arg1.length()>1)
  473. {
  474. QStringList acftList = db::newAcftGetString(arg1);
  475. QCompleter *acftCompleter = new QCompleter(acftList, this);
  476. acftCompleter->setCaseSensitivity(Qt::CaseInsensitive);
  477. acftCompleter->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
  478. ui->newAcft->setCompleter(acftCompleter);
  479. }
  480. }
  481. void NewFlight::on_newAcft_editingFinished()
  482. {
  483. acft = "-1";// set invalid
  484. if(ui->newAcft->text().contains(" "))// is input from QCompleter
  485. {
  486. QStringList input = ui->newAcft->text().split(" ");
  487. QString registration = input[0].trimmed();
  488. QStringList result = db::newAcftGetString(registration);
  489. if(result.length() > 0)
  490. {
  491. ui->newAcft->setText(result[0]);
  492. acft = db::newAcftGetId(registration);
  493. }else
  494. {
  495. acft = "-1";
  496. }
  497. }else // is input from user
  498. {
  499. QString input = ui->newAcft->text();
  500. QStringList result = db::newAcftGetString(input);
  501. if(result.length() > 0)
  502. {
  503. ui->newAcft->setText(result[0]);
  504. QStringList input = ui->newAcft->text().split(" ");
  505. QString registration = input[0].trimmed();
  506. acft = db::newAcftGetId(registration);
  507. }else
  508. {
  509. acft = "-1";
  510. }
  511. }
  512. if(acft == "-1")
  513. {
  514. QMessageBox::StandardButton reply;
  515. reply = QMessageBox::question(this, "No aircraft found", "No aircraft found.\n Would you like to add a new aircraft to the database?",
  516. QMessageBox::Yes|QMessageBox::No);
  517. if (reply == QMessageBox::Yes) {
  518. NewAcft na(this);
  519. na.exec();
  520. ui->newAcft->setText("");
  521. ui->newAcft->setFocus();
  522. }
  523. }
  524. qDebug() << "Editing finished. Acft: " << acft;
  525. }
  526. void NewFlight::on_newPic_textEdited(const QString &arg1)
  527. {
  528. if(arg1.length()>2)
  529. {
  530. QStringList picList = dbPilots::newPicGetString(arg1);
  531. QCompleter *picCompleter = new QCompleter(picList, this);
  532. picCompleter->setCaseSensitivity(Qt::CaseInsensitive);
  533. picCompleter->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
  534. ui->newPic->setCompleter(picCompleter);
  535. }
  536. }
  537. void NewFlight::on_newPic_editingFinished()
  538. {
  539. pic = "-1"; // set invalid
  540. if(ui->newPic->text() == "self")
  541. {
  542. pic = "1";
  543. }else
  544. {
  545. QString picname;
  546. QStringList picList = dbPilots::newPicGetString(ui->newPic->text());
  547. qDebug() << picList;
  548. if(picList.length()!= 0)
  549. {
  550. picname = picList[0];
  551. ui->newPic->setText(picname);
  552. pic = dbPilots::newPicGetId(picname);
  553. }else
  554. {
  555. QMessageBox::StandardButton reply;
  556. reply = QMessageBox::question(this, "No Pilot found", "No pilot found.\n Would you like to add a new pilot to the database?",
  557. QMessageBox::Yes|QMessageBox::No);
  558. if (reply == QMessageBox::Yes)
  559. {
  560. qDebug() << "Add new pilot selected";
  561. nope();
  562. }
  563. }
  564. }
  565. }
  566. void NewFlight::on_secondPilotLineEdit_textEdited(const QString &arg1)
  567. {
  568. if(arg1.length()>2)
  569. {
  570. QStringList picList = dbPilots::newPicGetString(arg1);
  571. QCompleter *picCompleter = new QCompleter(picList, this);
  572. picCompleter->setCaseSensitivity(Qt::CaseInsensitive);
  573. picCompleter->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
  574. ui->secondPilotLineEdit->setCompleter(picCompleter);
  575. }
  576. }
  577. void NewFlight::on_secondPilotLineEdit_editingFinished()
  578. {
  579. secondPilot = "-1"; // set invalid
  580. if(ui->secondPilotLineEdit->text() == "self")
  581. {
  582. secondPilot = "1";
  583. }else
  584. {
  585. QString picname;
  586. QStringList picList = dbPilots::newPicGetString(ui->secondPilotLineEdit->text());
  587. qDebug() << picList;
  588. if(picList.length()!= 0)
  589. {
  590. picname = picList[0];
  591. ui->secondPilotLineEdit->setText(picname);
  592. secondPilot = dbPilots::newPicGetId(picname);
  593. }else
  594. {
  595. QMessageBox::StandardButton reply;
  596. reply = QMessageBox::question(this, "No Pilot found", "No pilot found.\n Would you like to add a new pilot to the database?",
  597. QMessageBox::Yes|QMessageBox::No);
  598. if (reply == QMessageBox::Yes)
  599. {
  600. qDebug() << "Add new pilot selected";
  601. nope();
  602. }
  603. }
  604. }
  605. qDebug() << "Second Pilot: " << secondPilot;
  606. }
  607. void NewFlight::on_thirdPilotLineEdit_textEdited(const QString &arg1)
  608. {
  609. if(arg1.length()>2)
  610. {
  611. QStringList picList = dbPilots::newPicGetString(arg1);
  612. QCompleter *picCompleter = new QCompleter(picList, this);
  613. picCompleter->setCaseSensitivity(Qt::CaseInsensitive);
  614. picCompleter->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
  615. ui->thirdPilotLineEdit->setCompleter(picCompleter);
  616. }
  617. }
  618. void NewFlight::on_thirdPilotLineEdit_editingFinished()
  619. {
  620. thirdPilot = "-1"; // set invalid
  621. if(ui->thirdPilotLineEdit->text() == "self")
  622. {
  623. thirdPilot = "1";
  624. }else
  625. {
  626. QString picname;
  627. QStringList picList = dbPilots::newPicGetString(ui->thirdPilotLineEdit->text());
  628. qDebug() << picList;
  629. if(picList.length()!= 0)
  630. {
  631. picname = picList[0];
  632. ui->thirdPilotLineEdit->setText(picname);
  633. thirdPilot = dbPilots::newPicGetId(picname);
  634. }else
  635. {
  636. QMessageBox::StandardButton reply;
  637. reply = QMessageBox::question(this, "No Pilot found", "No pilot found.\n Would you like to add a new pilot to the database?",
  638. QMessageBox::Yes|QMessageBox::No);
  639. if (reply == QMessageBox::Yes)
  640. {
  641. qDebug() << "Add new pilot selected";
  642. nope();
  643. }
  644. }
  645. }
  646. qDebug() << "Third Pilot: " << thirdPilot;
  647. }
  648. /*
  649. * Extras
  650. */
  651. void NewFlight::on_PilotFlyingCheckBox_stateChanged(int)
  652. {
  653. if(ui->PilotFlyingCheckBox->isChecked()){
  654. ui->TakeoffSpinBox->setValue(1);
  655. ui->TakeoffCheckBox->setCheckState(Qt::Checked);
  656. ui->LandingSpinBox->setValue(1);
  657. ui->LandingCheckBox->setCheckState(Qt::Checked);
  658. }else if(!ui->PilotFlyingCheckBox->isChecked()){
  659. ui->TakeoffSpinBox->setValue(0);
  660. ui->TakeoffCheckBox->setCheckState(Qt::Unchecked);
  661. ui->LandingSpinBox->setValue(0);
  662. ui->LandingCheckBox->setCheckState(Qt::Unchecked);
  663. }
  664. }
  665. void NewFlight::on_setAsDefaultButton_clicked()
  666. {
  667. storeSettings();
  668. }
  669. void NewFlight::on_restoreDefaultButton_clicked()
  670. {
  671. restoreSettings();
  672. }
  673. void NewFlight::on_buttonBox_accepted()
  674. {
  675. on_newDoft_editingFinished();// - activate slots in case user has been active in last input before clicking submit
  676. on_newTonb_editingFinished();
  677. on_newTofb_editingFinished();
  678. on_newDept_editingFinished();
  679. on_newDest_editingFinished();
  680. on_newAcft_editingFinished();
  681. on_newPic_editingFinished();
  682. QVector<QString> flight;
  683. flight = collectInput();
  684. if(verifyInput())
  685. {
  686. dbFlight::commitFlight(flight);
  687. qDebug() << flight << "Has been commited.";
  688. QMessageBox msgBox(this);
  689. msgBox.setText("Flight has been commited.");
  690. msgBox.exec();
  691. }else
  692. {
  693. qDebug() << "Invalid Input. No entry has been made in the database.";
  694. dbFlight::commitToScratchpad(flight);
  695. QMessageBox msgBox(this);
  696. msgBox.setText("Invalid entries detected. Please check your input.");
  697. msgBox.exec();
  698. NewFlight nf(this);
  699. nf.exec();
  700. }
  701. }
  702. void NewFlight::on_buttonBox_rejected()
  703. {
  704. qDebug() << "NewFlight: Rejected\n";
  705. }
  706. void NewFlight::on_ApproachComboBox_currentTextChanged(const QString &arg1)
  707. {
  708. if(arg1 == "ILS CAT III"){
  709. ui->AutolandCheckBox->setCheckState(Qt::Checked);
  710. ui->AutolandSpinBox->setValue(1);
  711. }else{
  712. ui->AutolandCheckBox->setCheckState(Qt::Unchecked);
  713. ui->AutolandSpinBox->setValue(0);
  714. }
  715. ApproachType = arg1;
  716. qDebug() << "Approach Type: " << ApproachType;
  717. }
  718. /*
  719. * Times
  720. */
  721. void NewFlight::on_spseTimeLineEdit_editingFinished()
  722. {
  723. ui->spseTimeLineEdit->setText(validateTimeInput(ui->spseTimeLineEdit->text()));
  724. if(ui->spseTimeLineEdit->text() == ""){
  725. ui->spseTimeLineEdit->setStyleSheet("border: 1px solid red");
  726. ui->spseTimeLineEdit->setFocus();
  727. }else{
  728. ui->spseTimeLineEdit->setStyleSheet("");
  729. }
  730. }
  731. void NewFlight::on_spmeTimeLineEdit_editingFinished()
  732. {
  733. ui->spmeTimeLineEdit->setText(validateTimeInput(ui->spmeTimeLineEdit->text()));
  734. if(ui->spmeTimeLineEdit->text() == ""){
  735. ui->spmeTimeLineEdit->setStyleSheet("border: 1px solid red");
  736. ui->spmeTimeLineEdit->setFocus();
  737. }else{
  738. ui->spmeTimeLineEdit->setStyleSheet("");
  739. }
  740. }
  741. void NewFlight::on_mpTimeLineEdit_editingFinished()
  742. {
  743. ui->mpTimeLineEdit->setText(validateTimeInput(ui->mpTimeLineEdit->text()));
  744. if(ui->mpTimeLineEdit->text() == ""){
  745. ui->mpTimeLineEdit->setStyleSheet("border: 1px solid red");
  746. ui->mpTimeLineEdit->setFocus();
  747. }else{
  748. ui->mpTimeLineEdit->setStyleSheet("");
  749. }
  750. }
  751. void NewFlight::on_totalTimeLineEdit_editingFinished()
  752. {
  753. ui->totalTimeLineEdit->setText(validateTimeInput(ui->totalTimeLineEdit->text()));
  754. if(ui->totalTimeLineEdit->text() == ""){
  755. ui->totalTimeLineEdit->setStyleSheet("border: 1px solid red");
  756. ui->totalTimeLineEdit->setFocus();
  757. }else{
  758. ui->totalTimeLineEdit->setStyleSheet("");
  759. }
  760. }
  761. void NewFlight::on_ifrTimeLineEdit_editingFinished()
  762. {
  763. ui->ifrTimeLineEdit->setText(validateTimeInput(ui->ifrTimeLineEdit->text()));
  764. if(ui->ifrTimeLineEdit->text() == ""){
  765. ui->ifrTimeLineEdit->setStyleSheet("border: 1px solid red");
  766. ui->ifrTimeLineEdit->setFocus();
  767. }else{
  768. ui->ifrTimeLineEdit->setStyleSheet("");
  769. }
  770. }
  771. void NewFlight::on_vfrTimeLineEdit_editingFinished()
  772. {
  773. ui->vfrTimeLineEdit->setText(validateTimeInput(ui->vfrTimeLineEdit->text()));
  774. if(ui->vfrTimeLineEdit->text() == ""){
  775. ui->vfrTimeLineEdit->setStyleSheet("border: 1px solid red");
  776. ui->vfrTimeLineEdit->setFocus();
  777. }else{
  778. ui->vfrTimeLineEdit->setStyleSheet("");
  779. }
  780. }
  781. void NewFlight::on_nightTimeLineEdit_editingFinished()
  782. {
  783. ui->nightTimeLineEdit->setText(validateTimeInput(ui->nightTimeLineEdit->text()));
  784. if(ui->nightTimeLineEdit->text() == ""){
  785. ui->nightTimeLineEdit->setStyleSheet("border: 1px solid red");
  786. ui->nightTimeLineEdit->setFocus();
  787. }else{
  788. ui->nightTimeLineEdit->setStyleSheet("");
  789. }
  790. }
  791. void NewFlight::on_xcTimeLineEdit_editingFinished()
  792. {
  793. ui->xcTimeLineEdit->setText(validateTimeInput(ui->xcTimeLineEdit->text()));
  794. if(ui->xcTimeLineEdit->text() == ""){
  795. ui->xcTimeLineEdit->setStyleSheet("border: 1px solid red");
  796. ui->xcTimeLineEdit->setFocus();
  797. }else{
  798. ui->xcTimeLineEdit->setStyleSheet("");
  799. }
  800. }
  801. void NewFlight::on_picTimeLineEdit_editingFinished()
  802. {
  803. ui->picTimeLineEdit->setText(validateTimeInput(ui->picTimeLineEdit->text()));
  804. if(ui->picTimeLineEdit->text() == ""){
  805. ui->picTimeLineEdit->setStyleSheet("border: 1px solid red");
  806. ui->picTimeLineEdit->setFocus();
  807. }else{
  808. ui->picTimeLineEdit->setStyleSheet("");
  809. }
  810. }
  811. void NewFlight::on_copTimeLineEdit_editingFinished()
  812. {
  813. ui->copTimeLineEdit->setText(validateTimeInput(ui->copTimeLineEdit->text()));
  814. if(ui->copTimeLineEdit->text() == ""){
  815. ui->copTimeLineEdit->setStyleSheet("border: 1px solid red");
  816. ui->copTimeLineEdit->setFocus();
  817. }else{
  818. ui->copTimeLineEdit->setStyleSheet("");
  819. }
  820. }
  821. void NewFlight::on_dualTimeLineEdit_editingFinished()
  822. {
  823. ui->dualTimeLineEdit->setText(validateTimeInput(ui->dualTimeLineEdit->text()));
  824. if(ui->dualTimeLineEdit->text() == ""){
  825. ui->dualTimeLineEdit->setStyleSheet("border: 1px solid red");
  826. ui->dualTimeLineEdit->setFocus();
  827. }else{
  828. ui->dualTimeLineEdit->setStyleSheet("");
  829. }
  830. }
  831. void NewFlight::on_fiTimeLineEdit_editingFinished()
  832. {
  833. ui->fiTimeLineEdit->setText(validateTimeInput(ui->fiTimeLineEdit->text()));
  834. if(ui->fiTimeLineEdit->text() == ""){
  835. ui->fiTimeLineEdit->setStyleSheet("border: 1px solid red");
  836. ui->fiTimeLineEdit->setFocus();
  837. }else{
  838. ui->fiTimeLineEdit->setStyleSheet("");
  839. }
  840. }
  841. void NewFlight::on_simTimeLineEdit_editingFinished()
  842. {
  843. ui->simTimeLineEdit->setText(validateTimeInput(ui->simTimeLineEdit->text()));
  844. if(ui->simTimeLineEdit->text() == ""){
  845. ui->simTimeLineEdit->setStyleSheet("border: 1px solid red");
  846. ui->simTimeLineEdit->setFocus();
  847. }else{
  848. ui->simTimeLineEdit->setStyleSheet("");
  849. }
  850. }