newflight.cpp 31 KB

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