newflightdialog.cpp 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667
  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 "newflightdialog.h"
  19. #include "ui_newflight.h"
  20. #include <QSqlRelationalTableModel>
  21. /// =======================================================
  22. /// Debug / WIP section
  23. /// =======================================================
  24. #define DEBUG(expr) \
  25. qDebug() << "~DEBUG" << __func__ << expr
  26. void NewFlightDialog::on_verifyButton_clicked()//debug button
  27. {
  28. //fillExtrasLineEdits();
  29. collectBasicData();
  30. collectAdditionalData();
  31. }
  32. static const auto IATA_RX = QLatin1String("[a-zA-Z0-9]{3}");
  33. static const auto ICAO_RX = QLatin1String("[a-zA-Z0-9]{4}");
  34. static const auto NAME_RX = QLatin1String("(\\p{L}+('|\\-)?)");//(\\p{L}+(\\s|'|\\-)?\\s?(\\p{L}+)?\\s?)
  35. static const auto ADD_NAME_RX = QLatin1String("(\\s?(\\p{L}+('|\\-)?))?");
  36. static const auto SELF_RX = QLatin1String("(self|SELF)");
  37. /// Raw Input validation
  38. static const auto TIME_VALID_RGX = QRegularExpression("([01]?[0-9]|2[0-3]):?[0-5][0-9]?");// We only want to allow inputs that make sense as a time, e.g. 99:99 is not a valid time
  39. static const auto LOC_VALID_RGX = QRegularExpression(IATA_RX + "|" + ICAO_RX);
  40. static const auto AIRCRAFT_VALID_RGX = QRegularExpression("[A-Z0-9]+\\-?[A-Z0-9]+");
  41. static const auto PILOT_NAME_VALID_RGX = QRegularExpression(SELF_RX + QLatin1Char('|')
  42. + NAME_RX + ADD_NAME_RX + ADD_NAME_RX + ADD_NAME_RX + ",?\\s?" // up to 4 first names
  43. + NAME_RX + ADD_NAME_RX + ADD_NAME_RX + ADD_NAME_RX );// up to 4 last names
  44. static const auto DATE_VALID_RGX = QRegularExpression("^([1-9][0-9]{3}).?(1[0-2]|0[1-9]).?(3[01]|0[1-9]|[12][0-9])?$");// . allows all seperators, still allows for 2020-02-31, additional verification via QDate::isValid()
  45. /// Invalid characters (validators keep text even if it returns Invalid, see `onInputRejected` below)
  46. static const auto TIME_INVALID_RGX = QRegularExpression("[^0-9:]");
  47. static const auto LOC_INVALID_RGX = QRegularExpression("[^A-Z0-9]");
  48. static const auto AIRCRAFT_INVALID_RGX = QRegularExpression("[^a-zA-Z0-9\\-]");
  49. static const auto PILOT_NAME_INVALID_RGX = QRegularExpression("[^\\p{L}|\\s|,]");
  50. static const auto DATE_INVALID_RGX = QRegularExpression("[^0-9|:|\\.|/|-]");
  51. static const auto INVALID_CHARS_RGX = QRegularExpression("[^\\p{L}|\\s|,|\\-|'|0-9|:|\\.]");
  52. /// Sql columns
  53. static const auto LOC_SQL_COL = SqlColumnNum(1); // TODO: locations are iata/icao so 1,2 merge columns in sql?
  54. static const auto AIRCRAFT_SQL_COL = SqlColumnNum(4);
  55. static const auto PILOT_NAME_SQL_COL = SqlColumnNum(6);
  56. /*
  57. * Window Construction
  58. */
  59. //For adding a new Flight to the logbook
  60. NewFlightDialog::NewFlightDialog(QWidget *parent, Db::editRole edRole) :
  61. QDialog(parent),
  62. ui(new Ui::NewFlight)
  63. {
  64. ui->setupUi(this);
  65. role = edRole;
  66. doUpdate = true;
  67. setup();
  68. //set date
  69. auto date = QDate::currentDate();
  70. ui->doftLineEdit->setText(date.toString(Qt::ISODate));
  71. emit ui->doftLineEdit->editingFinished();
  72. // Visually mark mandatory fields
  73. ui->deptLocLineEdit->setStyleSheet("border: 1px solid orange");
  74. ui->destLocLineEdit->setStyleSheet("border: 1px solid orange");
  75. ui->tofbTimeLineEdit->setStyleSheet("border: 1px solid orange");
  76. ui->tonbTimeLineEdit->setStyleSheet("border: 1px solid orange");
  77. ui->picNameLineEdit->setStyleSheet("border: 1px solid orange");
  78. ui->acftLineEdit->setStyleSheet("border: 1px solid orange");
  79. readSettings();
  80. }
  81. //For editing an existing flight
  82. NewFlightDialog::NewFlightDialog(QWidget *parent, Flight oldFlight, Db::editRole edRole) :
  83. QDialog(parent),
  84. ui(new Ui::NewFlight)
  85. {
  86. ui->setupUi(this);
  87. role=edRole;
  88. entry = oldFlight;
  89. doUpdate = true;
  90. setup();
  91. formFiller(oldFlight);
  92. }
  93. NewFlightDialog::~NewFlightDialog()
  94. {
  95. delete ui;
  96. }
  97. bool NewFlightDialog::eventFilter(QObject* object, QEvent* event)
  98. {
  99. if(object == ui->doftLineEdit && event->type() == QEvent::MouseButtonPress) {
  100. on_doftLineEditEntered();
  101. return false; // let the event continue to the edit
  102. } /*else if (object == this && event->type() == QEvent::Leave) {
  103. DEBUG("calendarWidget left.");
  104. //ui->doftLineEdit->blockSignals(false);
  105. //ui->calendarWidget->hide();
  106. //ui->placeLabel1->resize(ui->placeLabel2->size());
  107. //ui->doftLineEdit->setFocus();
  108. return false;
  109. }*/
  110. return false;
  111. }
  112. void NewFlightDialog::setup(){
  113. auto db = Db::Database();
  114. const auto location_settings = \
  115. LineEditSettings(LOC_VALID_RGX, LOC_INVALID_RGX, LOC_SQL_COL);
  116. const auto aircraft_settings = \
  117. LineEditSettings(AIRCRAFT_VALID_RGX, AIRCRAFT_INVALID_RGX, AIRCRAFT_SQL_COL);
  118. const auto pilot_name_settings = \
  119. LineEditSettings(PILOT_NAME_VALID_RGX, PILOT_NAME_INVALID_RGX, PILOT_NAME_SQL_COL);
  120. const auto time_settings = \
  121. LineEditSettings(TIME_VALID_RGX, TIME_INVALID_RGX, SqlColumnNum());
  122. const auto doft_settings = \
  123. LineEditSettings(DATE_VALID_RGX, DATE_INVALID_RGX, SqlColumnNum());
  124. // Set up Line Edits with QValidators, QCompleters
  125. auto line_edits = ui->flightDataTab->findChildren<QLineEdit*>();
  126. auto le_size = line_edits.size();
  127. for(auto i = 0; i < le_size; ++i){
  128. // auto bit_array = new QBitArray(le_size);
  129. // bit_array->setBit(i, true);
  130. this->lineEditBitMap[line_edits[i]] = i;
  131. }
  132. this->allOkBits.resize(line_edits.size());
  133. this->mandatoryLineEdits = {
  134. ui->doftLineEdit,
  135. ui->deptLocLineEdit,
  136. ui->destLocLineEdit,
  137. ui->tofbTimeLineEdit,
  138. ui->tonbTimeLineEdit,
  139. ui->picNameLineEdit,
  140. ui->acftLineEdit,
  141. };
  142. for(auto line_edit : line_edits)
  143. {
  144. auto le_name = line_edit->objectName();
  145. if(QRegularExpression("Loc").match(le_name).hasMatch()){
  146. setupLineEdit(line_edit, location_settings);
  147. }
  148. else if (QRegularExpression("Time").match(le_name).hasMatch()) {
  149. setupLineEdit(line_edit, time_settings);
  150. }
  151. else if (QRegularExpression("acft").match(le_name).hasMatch()) {
  152. setupLineEdit(line_edit, aircraft_settings);
  153. }
  154. else if (QRegularExpression("Name").match(le_name).hasMatch()) {
  155. setupLineEdit(line_edit, pilot_name_settings);
  156. }
  157. else if(QRegularExpression("doft").match(le_name).hasMatch()) {
  158. setupLineEdit(line_edit, doft_settings);
  159. }
  160. }
  161. //fill Lists
  162. pilots = CompletionList(CompleterTarget::pilots).list;
  163. tails = CompletionList(CompleterTarget::registrations).list;
  164. airports = CompletionList(CompleterTarget::airports).list;
  165. QString statement = "SELECT iata, icao FROM airports";
  166. auto result = Db::customQuery(statement,2);
  167. for(int i=0; i<result.length()-2; i += 2){
  168. airportMap.insert(result[i],result[i+1]);
  169. }
  170. // Groups for CheckBoxes
  171. QButtonGroup *FlightRulesGroup = new QButtonGroup(this);
  172. FlightRulesGroup->addButton(ui->IfrCheckBox);
  173. FlightRulesGroup->addButton(ui->VfrCheckBox);
  174. QButtonGroup *PilotTaskGroup = new QButtonGroup(this);
  175. PilotTaskGroup->addButton(ui->PilotFlyingCheckBox);
  176. PilotTaskGroup->addButton(ui->PilotMonitoringCheckBox);
  177. ui->flightDataTabWidget->setCurrentIndex(0);
  178. ui->flightDataTabWidget->removeTab(2); // hide calendar widget
  179. ui->calendarWidget->installEventFilter(this);
  180. ui->placeLabel1->installEventFilter(this);
  181. ui->doftLineEdit->installEventFilter(this);
  182. ui->deptLocLineEdit->setFocus();
  183. connect(ui->calendarWidget, SIGNAL(clicked(const QDate &)), this, SLOT(date_clicked(const QDate &)));
  184. connect(ui->calendarWidget, SIGNAL(activated(const QDate &)), this, SLOT(date_selected(const QDate &)));
  185. }
  186. void NewFlightDialog::formFiller(Flight oldFlight)
  187. {
  188. DEBUG("Filling Line Edits...");
  189. DEBUG("With Data: " << oldFlight.data);
  190. // Date
  191. //ui->doftLineEdit->setDate(QDate::fromString(oldFlight.data.value("doft"), Qt::ISODate));
  192. QStringList filled;
  193. // Line Edits
  194. auto line_edits = parent()->findChildren<QLineEdit *>();
  195. QStringList line_edits_names;
  196. for(const auto& le : line_edits){
  197. line_edits_names << le->objectName();
  198. }
  199. const QString& acft = Db::singleSelect("registration", "tails", "tail_id",
  200. oldFlight.data.value("acft"),
  201. Db::exactMatch);
  202. ui->acftLineEdit->setText(acft);
  203. line_edits_names.removeOne("acftLineEdit");
  204. for(const auto& key : oldFlight.data.keys()){
  205. auto rx = QRegularExpression(key + "LineEdit");//acftLineEdit
  206. for(const auto& leName : line_edits_names){
  207. if(rx.match(leName).hasMatch()) {
  208. //DEBUG("Loc Match found: " << key << " - " << leName);
  209. auto le = parent()->findChild<QLineEdit *>(leName);
  210. if(le != nullptr){
  211. le->setText(oldFlight.data.value(key));
  212. filled << leName;
  213. line_edits_names.removeOne(leName);
  214. }
  215. break;
  216. }
  217. }
  218. rx = QRegularExpression(key + "Loc\\w+?");
  219. for(const auto& leName : line_edits_names){
  220. if(rx.match(leName).hasMatch()) {
  221. //DEBUG("Loc Match found: " << key << " - " << leName);
  222. auto le = parent()->findChild<QLineEdit *>(leName);
  223. if(le != nullptr){
  224. le->setText(oldFlight.data.value(key));
  225. filled << leName;
  226. line_edits_names.removeOne(leName);
  227. }
  228. break;
  229. }
  230. }
  231. rx = QRegularExpression(key + "Time\\w+?");
  232. for(const auto& leName : line_edits_names){
  233. if(rx.match(leName).hasMatch()) {
  234. //DEBUG("Time Match found: " << key << " - " << leName);
  235. auto le = parent()->findChild<QLineEdit *>(leName);
  236. if(le != nullptr){
  237. DEBUG("Setting " << le->objectName() << " to " << Calc::minutesToString(oldFlight.data.value(key)));
  238. le->setText(Calc::minutesToString(
  239. oldFlight.data.value(key)));
  240. filled << leName;
  241. line_edits_names.removeOne(leName);
  242. }
  243. break;
  244. }
  245. }
  246. rx = QRegularExpression(key + "Name\\w+?");
  247. for(const auto& leName : line_edits_names){
  248. if(rx.match(leName).hasMatch()) {
  249. //DEBUG("Time Match found: " << key << " - " << leName);
  250. auto le = parent()->findChild<QLineEdit *>(leName);
  251. if(le != nullptr){
  252. const QString& column = "piclastname||', '||picfirstname";
  253. const QString& name = Db::singleSelect(column, "pilots", "pilot_id",
  254. oldFlight.data.value(key),
  255. Db::exactMatch);
  256. le->setText(name);
  257. filled << leName;
  258. line_edits_names.removeOne(leName);
  259. }
  260. break;
  261. }
  262. }
  263. }
  264. //FunctionComboBox
  265. QList<QLineEdit*> FCB = {ui->tPICTimeLineEdit, ui->tPICUSTimeLineEdit, ui->tSICTimeLineEdit,
  266. ui->tDualTimeLineEdit, ui->tFITimeLineEdit};
  267. for(const auto& le : FCB){
  268. if(le->text() != "00:00"){
  269. QString name = le->objectName();
  270. name.chop(12);
  271. name.remove(0,1);
  272. ui->FunctionComboBox->setCurrentText(name);
  273. }
  274. }
  275. // Approach Combo Box
  276. const QString& app = oldFlight.data.value("ApproachType");
  277. if(app != " "){
  278. ui->ApproachComboBox->setCurrentText(app);
  279. }
  280. // Task and Rules
  281. qint8 PF = oldFlight.data.value("pilotFlying").toInt();
  282. if (PF > 0) {
  283. ui->PilotFlyingCheckBox->setChecked(true);
  284. } else {
  285. ui->PilotMonitoringCheckBox->setChecked(true);
  286. }
  287. qint8 FR = oldFlight.data.value("tIFR").toInt();
  288. if (FR > 0) {
  289. ui->IfrCheckBox->setChecked(true);
  290. } else {
  291. ui->tIFRTimeLineEdit->setText("00:00");
  292. ui->VfrCheckBox->setChecked(true);
  293. }
  294. // Take Off and Landing
  295. qint8 TO = oldFlight.data.value("toDay").toInt() + oldFlight.data.value("toNight").toInt();
  296. qint8 LDG = oldFlight.data.value("ldgDay").toInt() + oldFlight.data.value("ldgNight").toInt();
  297. DEBUG("TO and LDG:" << TO << LDG);
  298. if(TO > 0) {
  299. ui->TakeoffCheckBox->setChecked(true);
  300. ui->TakeoffSpinBox->setValue(TO);
  301. } else {
  302. ui->TakeoffCheckBox->setChecked(false);
  303. ui->TakeoffSpinBox->setValue(0);
  304. }
  305. if(LDG > 0) {
  306. ui->LandingCheckBox->setChecked(true);
  307. ui->LandingSpinBox->setValue(LDG);
  308. } else {
  309. ui->LandingCheckBox->setChecked(false);
  310. ui->LandingSpinBox->setValue(0);
  311. }
  312. qint8 AL = oldFlight.data.value("autoland").toInt();
  313. if(AL > 0) {
  314. ui->AutolandCheckBox->setChecked(true);
  315. ui->AutolandSpinBox->setValue(AL);
  316. }
  317. for(const auto& le : mandatoryLineEdits){
  318. emit le->editingFinished();
  319. }
  320. }
  321. /*
  322. * ============================================================================
  323. * Functions
  324. * ============================================================================
  325. */
  326. /*!
  327. * \brief setLineEditValidator set Validators for QLineEdits that end with Time, Loc,
  328. * Aircraft or Name
  329. */
  330. inline void NewFlightDialog::setupLineEdit(QLineEdit* line_edit, LineEditSettings settings)
  331. {
  332. auto db = QSqlDatabase::database("qt_sql_default_connection");
  333. auto line_edit_objectName = line_edit->objectName();
  334. DEBUG("Setting validators for " << line_edit_objectName);
  335. auto [valid_rgx, invalid_rgx, sql_col] = settings.getAll();
  336. auto validator = new StrictRxValidator(valid_rgx, line_edit);
  337. auto comp_model = new QSqlRelationalTableModel(line_edit, db);
  338. comp_model->database().open();
  339. comp_model->setTable("QCompleterView");
  340. comp_model->select();
  341. auto completer = new QCompleter(comp_model, line_edit);
  342. completer->setCaseSensitivity(Qt::CaseInsensitive);
  343. completer->setCompletionMode(QCompleter::PopupCompletion);
  344. completer->setCompletionColumn(sql_col.column());
  345. completer->setFilterMode(Qt::MatchContains);
  346. //if(QRegularExpression("\\w+Loc").match(line_edit_objectName).hasMatch()) { completer->setFilterMode(Qt::MatchContains); }
  347. line_edit->setValidator(validator);
  348. line_edit->setCompleter(completer);
  349. }
  350. /*!
  351. * \brief NewFlight::writeSettings Writes current selection for auto-logging
  352. * to settings file.
  353. */
  354. void NewFlightDialog::writeSettings()
  355. {
  356. DEBUG("Writing Settings...");
  357. Settings::write("NewFlight/FunctionComboBox",ui->FunctionComboBox->currentText());
  358. Settings::write("NewFlight/ApproachComboBox",ui->ApproachComboBox->currentText());
  359. Settings::write("NewFlight/PilotFlyingCheckBox",ui->PilotFlyingCheckBox->isChecked());
  360. Settings::write("NewFlight/PilotMonitoringCheckBox",ui->PilotMonitoringCheckBox->isChecked());
  361. Settings::write("NewFlight/TakeoffSpinBox",ui->TakeoffSpinBox->value());
  362. Settings::write("NewFlight/TakeoffCheckBox",ui->TakeoffCheckBox->isChecked());
  363. Settings::write("NewFlight/LandingSpinBox",ui->LandingSpinBox->value());
  364. Settings::write("NewFlight/LandingCheckBox",ui->LandingCheckBox->isChecked());
  365. Settings::write("NewFlight/AutolandSpinBox",ui->AutolandSpinBox->value());
  366. Settings::write("NewFlight/AutolandCheckBox",ui->AutolandCheckBox->isChecked());
  367. Settings::write("NewFlight/IfrCheckBox",ui->IfrCheckBox->isChecked());
  368. Settings::write("NewFlight/VfrCheckBox",ui->VfrCheckBox->isChecked());
  369. }
  370. /*!
  371. * \brief NewFlight::readSettings Retreives auto-logging settings
  372. * and sets up ui accordingly
  373. */
  374. void NewFlightDialog::readSettings()
  375. {
  376. DEBUG("Reading Settings...");
  377. QSettings settings;
  378. ui->FunctionComboBox->setCurrentText(Settings::read("NewFlight/FunctionComboBox").toString());
  379. ui->ApproachComboBox->setCurrentText(Settings::read("NewFlight/ApproachComboBox").toString());
  380. ui->PilotFlyingCheckBox->setChecked(Settings::read("NewFlight/PilotFlyingCheckBox").toBool());
  381. ui->PilotMonitoringCheckBox->setChecked(Settings::read("NewFlight/PilotMonitoringCheckBox").toBool());
  382. ui->TakeoffSpinBox->setValue(Settings::read("NewFlight/TakeoffSpinBox").toInt());
  383. ui->TakeoffCheckBox->setChecked(Settings::read("NewFlight/TakeoffCheckBox").toBool());
  384. ui->LandingSpinBox->setValue(Settings::read("NewFlight/LandingSpinBox").toInt());
  385. ui->LandingCheckBox->setChecked(Settings::read("NewFlight/LandingCheckBox").toBool());
  386. ui->AutolandSpinBox->setValue(Settings::read("NewFlight/AutolandSpinBox").toInt());
  387. ui->AutolandCheckBox->setChecked(Settings::read("NewFlight/AutolandCheckBox").toBool());
  388. ui->IfrCheckBox->setChecked(Settings::read("NewFlight/IfrCheckBox").toBool());
  389. ui->VfrCheckBox->setChecked(Settings::read("NewFlight/VfrCheckBox").toBool());
  390. ui->FlightNumberLineEdit->setText(Settings::read("flightlogging/flightnumberPrefix").toString());
  391. if(Settings::read("NewFlight/FunctionComboBox").toString() == "PIC"){
  392. ui->picNameLineEdit->setText("self");
  393. ui->secondPilotNameLineEdit->setText("");
  394. }else if (Settings::read("NewFlight/FunctionComboBox").toString() == "Co-Pilot") {
  395. ui->picNameLineEdit->setText("");
  396. ui->secondPilotNameLineEdit->setText("self");
  397. }
  398. }
  399. /*!
  400. * \brief NewFlight::addNewPilotMessageBox If the user input is not in the pilotNameList, the user
  401. * is prompted if he wants to add a new entry to the database
  402. */
  403. void NewFlightDialog::addNewPilotMessageBox(QLineEdit *parent)
  404. {
  405. QMessageBox::StandardButton reply;
  406. reply = QMessageBox::question(this, "No Pilot found",
  407. "No pilot found.<br>Please enter the Name as"
  408. "<br><br><center><b>Lastname, Firstname</b></center><br><br>"
  409. "If this is the first time you log a flight with this pilot, you have to "
  410. "add the name to the database first.<br><br>Would you like to add a new pilot to the database?",
  411. QMessageBox::Yes|QMessageBox::No);
  412. if (reply == QMessageBox::Yes)
  413. {
  414. qDebug() << "Add new pilot selected";
  415. // create and open new pilot dialog
  416. auto np = NewPilotDialog(Db::createNew, this);
  417. np.exec();
  418. QString statement = "SELECT MAX(pilot_id) FROM pilots";
  419. QString id = Db::customQuery(statement,1).first();
  420. Pilot newPilot = Pilot(id.toInt());
  421. parent->setText(newPilot.data.value("displayname"));
  422. emit parent->editingFinished();
  423. }
  424. }
  425. /*!
  426. * \brief NewFlight::addNewAircraftMessageBox If the user input is not in the aircraftList, the user
  427. * is prompted if he wants to add a new entry to the database
  428. */
  429. void NewFlightDialog::addNewAircraftMessageBox(QLineEdit *parent)
  430. {
  431. QMessageBox::StandardButton reply;
  432. reply = QMessageBox::question(this, "No Aircraft found",
  433. "No aircraft with this registration found.<br>"
  434. "If this is the first time you log a flight with this aircraft, you have to "
  435. "add the registration to the database first.<br><br>Would you like to add a new aircraft to the database?",
  436. QMessageBox::Yes|QMessageBox::No);
  437. if (reply == QMessageBox::Yes)
  438. {
  439. DEBUG("Add new aircraft selected");
  440. // create and open new aircraft dialog
  441. auto na = NewTailDialog(ui->acftLineEdit->text(), Db::createNew, this);
  442. na.exec();
  443. QString statement = "SELECT MAX(tail_id) FROM tails";
  444. QString id = Db::customQuery(statement,1).first();
  445. auto newAcft = Aircraft(id.toInt());
  446. parent->setText(newAcft.data.value("registration"));
  447. emit parent->editingFinished();
  448. }
  449. }
  450. /// Input Verification and Collection
  451. /*!
  452. * \brief NewFlight::update check if needed inputs are available and update form
  453. */
  454. void NewFlightDialog::update()
  455. {
  456. if(doUpdate){
  457. QVector<QLineEdit*> notFilled;
  458. for(auto lineEdit : mandatoryLineEdits)
  459. {
  460. if(!allOkBits.testBit(lineEditBitMap[lineEdit]))
  461. {
  462. notFilled.push_back(lineEdit);
  463. }
  464. }
  465. if(notFilled.empty()){
  466. collectBasicData();
  467. fillExtras();
  468. } else {
  469. DEBUG("No update - not enough variables known.");
  470. }
  471. }
  472. }
  473. /*!
  474. * \brief NewFlight::collectBasicInput After mandatory inputs have passed
  475. * validation, collect values from line edits and combo boxes to create new Data
  476. * for flight object.
  477. */
  478. void NewFlightDialog::collectBasicData()
  479. {
  480. // purge old data to ensure database integrity
  481. newData.clear();
  482. DEBUG("Collecting Basic Input...");
  483. // Date of Flight
  484. if(QDate::fromString(ui->doftLineEdit->text(),Qt::ISODate).isValid()) {
  485. auto doft = ui->doftLineEdit->text();
  486. newData.insert("doft",doft);
  487. }
  488. // Departure Loc
  489. newData.insert("dept",ui->deptLocLineEdit->text());
  490. // Time Off Blocks
  491. auto timeOff = QTime::fromString(ui->tofbTimeLineEdit->text(),"hh:mm");
  492. if(timeOff.isValid()){
  493. int tofb = timeOff.hour() * 60 + timeOff.minute();
  494. newData.insert("tofb",QString::number(tofb));
  495. }
  496. // Destination Loc
  497. newData.insert("dest",ui->destLocLineEdit->text());
  498. // Time On Blocks
  499. auto timeOn = QTime::fromString(ui->tonbTimeLineEdit->text(),"hh:mm");
  500. if(timeOn.isValid()){
  501. int tonb = timeOn.hour() * 60 + timeOn.minute();
  502. newData.insert("tonb",QString::number(tonb));
  503. }
  504. //Block Time
  505. auto tofb = QTime::fromString(ui->tofbTimeLineEdit->text(),"hh:mm");
  506. auto tonb = QTime::fromString(ui->tonbTimeLineEdit->text(),"hh:mm");
  507. QString blockTime = Calc::blocktime(tofb, tonb).toString("hh:mm");
  508. QString blockMinutes = QString::number(Calc::stringToMinutes(blockTime));
  509. newData.insert("tblk",blockMinutes);
  510. // Aircraft
  511. QString reg = ui->acftLineEdit->text();
  512. QString acft = Db::singleSelect("tail_id","tails","registration",reg,Db::exactMatch);
  513. if(!acft.isEmpty()){
  514. newData.insert("acft",acft);
  515. } else {
  516. emit ui->acftLineEdit->inputRejected();
  517. }
  518. // Pilot
  519. if(ui->picNameLineEdit->text() == "self" || ui->picNameLineEdit->text() == "self"){
  520. newData.insert("pic","1");
  521. } else {
  522. QString name = ui->picNameLineEdit->text();
  523. QStringList names = name.split(',');
  524. if(names.length()==2){
  525. QString firstNames = names[1].simplified();
  526. QString lastNames = names[0].simplified();
  527. QString query = "SELECT pilot_id FROM pilots WHERE piclastname = \"" + lastNames
  528. + "\" AND picfirstname = \"" + firstNames + "\"";
  529. QVector<QString> pic = Db::customQuery(query,1);
  530. if(!pic.isEmpty()){
  531. newData.insert("pic",pic.first());
  532. }else {
  533. emit ui->picNameLineEdit->inputRejected();
  534. }
  535. }
  536. }
  537. }
  538. void NewFlightDialog::collectAdditionalData()
  539. {
  540. // Pilot 2
  541. if(!ui->secondPilotNameLineEdit->text().isEmpty()){
  542. if(ui->secondPilotNameLineEdit->text() == "self" || ui->secondPilotNameLineEdit->text() == "self"){
  543. newData.insert("secondPilot","1");
  544. } else {
  545. QString name = ui->secondPilotNameLineEdit->text();
  546. QStringList names = name.split(',');
  547. if(names.length()==2){
  548. QString firstNames = names[1].simplified();
  549. QString lastNames = names[0].simplified();
  550. QString query = "SELECT pilot_id FROM pilots WHERE piclastname = \"" + lastNames
  551. + "\" AND picfirstname = \"" + firstNames + "\"";
  552. QVector<QString> pic = Db::customQuery(query,1);
  553. if(!pic.isEmpty()){
  554. newData.insert("secondPilot",pic.first());
  555. }else {
  556. emit ui->secondPilotNameLineEdit->inputRejected();
  557. }
  558. }
  559. }
  560. }
  561. // Pilot 3
  562. if(!ui->thirdPilotNameLineEdit->text().isEmpty()){
  563. if(ui->thirdPilotNameLineEdit->text() == "self" || ui->thirdPilotNameLineEdit->text() == "self"){
  564. newData.insert("thirdPilot","1");
  565. } else {
  566. QString name = ui->thirdPilotNameLineEdit->text();
  567. QStringList names = name.split(',');
  568. if(names.length()==2){
  569. QString firstNames = names[1].simplified();
  570. QString lastNames = names[0].simplified();
  571. QString query = "SELECT pilot_id FROM pilots WHERE piclastname = \"" + lastNames
  572. + "\" AND picfirstname = \"" + firstNames + "\"";
  573. QVector<QString> pic = Db::customQuery(query,1);
  574. if(!pic.isEmpty()){
  575. newData.insert("thirdPilot",pic.first());
  576. }else {
  577. emit ui->thirdPilotNameLineEdit->inputRejected();
  578. }
  579. }
  580. }
  581. }
  582. // Extra Times
  583. auto tofb = QTime::fromString(ui->tofbTimeLineEdit->text(),"hh:mm");
  584. auto tonb = QTime::fromString(ui->tonbTimeLineEdit->text(),"hh:mm");
  585. QString blockTime = Calc::blocktime(tofb, tonb).toString("hh:mm");
  586. QString blockMinutes = QString::number(Calc::stringToMinutes(blockTime));
  587. auto acft = Aircraft(newData.value("acft").toInt());
  588. if(!acft.data.isEmpty()){// valid aircraft
  589. // SP SE
  590. if(acft.data.value("singlepilot") == "1" && acft.data.value("singleengine") == "1"){
  591. newData.insert("tSPSE", blockMinutes);
  592. newData.insert("tSPME", "");
  593. newData.insert("tMP", "");
  594. }
  595. // SP ME
  596. if(acft.data.value("singlepilot") == "1" && acft.data.value("multiengine") == "1"){
  597. newData.insert("tSPSE", "");
  598. newData.insert("tSPME", blockMinutes);
  599. newData.insert("tMP", "");
  600. }
  601. // MP
  602. if(acft.data.value("multipilot") == "1"){
  603. newData.insert("tSPSE", "");
  604. newData.insert("tSPME", "");
  605. newData.insert("tMP", blockMinutes);
  606. }
  607. }else{DEBUG("Aircraft Details Empty");}//invalid aircraft
  608. // IFR
  609. if(ui->IfrCheckBox->isChecked()){
  610. newData.insert("tIFR",blockMinutes);
  611. } else {
  612. newData.insert("tIFR","");
  613. }
  614. // Night
  615. QString deptDate = ui->doftLineEdit->text() + 'T' + tofb.toString("hh:mm");
  616. QDateTime deptDateTime = QDateTime::fromString(deptDate,"yyyy-MM-ddThh:mm");
  617. int tblk = blockMinutes.toInt();
  618. const int nightAngle = Settings::read("flightlogging/nightangle").toInt();
  619. QString nightTime = QString::number(
  620. Calc::calculateNightTime(
  621. newData.value("dept"), newData.value("dest"),
  622. deptDateTime, tblk, nightAngle));
  623. newData.insert("tNIGHT", nightTime);
  624. // Function times
  625. switch (ui->FunctionComboBox->currentIndex()) {
  626. case 0://PIC
  627. newData.insert("tPIC", blockMinutes);
  628. newData.insert("tPICUS", "");
  629. newData.insert("tSIC", "");
  630. newData.insert("tDual", "");
  631. newData.insert("tFI", "");
  632. break;
  633. case 1://PICUS
  634. newData.insert("tPIC", "");
  635. newData.insert("tPICUS", blockMinutes);
  636. newData.insert("tSIC", "");
  637. newData.insert("tDual", "");
  638. newData.insert("tFI", "");
  639. break;
  640. case 2://Co-Pilot
  641. newData.insert("tPIC", "");
  642. newData.insert("tPICUS", "");
  643. newData.insert("tSIC", blockMinutes);
  644. newData.insert("tDual", "");
  645. newData.insert("tFI", "");
  646. break;
  647. case 3://Dual
  648. newData.insert("tPIC", "");
  649. newData.insert("tPICUS", "");
  650. newData.insert("tSIC", "");
  651. newData.insert("tDual", blockMinutes);
  652. newData.insert("tFI", "");
  653. break;
  654. case 4://Instructor
  655. newData.insert("tPIC", "");
  656. newData.insert("tPICUS", "");
  657. newData.insert("tSIC", "");
  658. newData.insert("tDual", "");
  659. newData.insert("tFI", blockMinutes);
  660. }
  661. // Pilot Flying
  662. newData.insert("pilotFlying", QString::number(ui->PilotFlyingCheckBox->isChecked()));
  663. // TO and LDG
  664. if(ui->TakeoffCheckBox->isChecked()) {
  665. if(nightTime == "0"){ // all day
  666. newData.insert("toDay", QString::number(ui->TakeoffSpinBox->value()));
  667. newData.insert("toNight", "0");
  668. }else if (nightTime == blockTime) { // all night
  669. newData.insert("toDay", "0");
  670. newData.insert("toNight", QString::number(ui->TakeoffSpinBox->value()));
  671. } else { //check
  672. if(Calc::isNight(ui->deptLocLineEdit->text(), deptDateTime, nightAngle)){
  673. newData.insert("toDay", "0");
  674. newData.insert("toNight", QString::number(ui->TakeoffSpinBox->value()));
  675. }else{
  676. newData.insert("toDay", QString::number(ui->TakeoffSpinBox->value()));
  677. newData.insert("toNight", "0");
  678. }
  679. }
  680. } else {
  681. newData.insert("toDay", "0");
  682. newData.insert("toNight", "0");
  683. }
  684. if(ui->LandingCheckBox->isChecked()) {
  685. if(nightTime == "0"){ // all day
  686. newData.insert("ldgDay", QString::number(ui->LandingSpinBox->value()));
  687. newData.insert("ldgNight", "0");
  688. }else if (nightTime == blockTime) { // all night
  689. newData.insert("ldgDay", "0");
  690. newData.insert("ldgNight", QString::number(ui->LandingSpinBox->value()));
  691. } else { //check
  692. QString destDate = ui->doftLineEdit->text() + 'T' + tonb.toString("hh:mm");
  693. QDateTime destDateTime = QDateTime::fromString(destDate,"yyyy-MM-ddThh:mm");
  694. if(Calc::isNight(ui->destLocLineEdit->text(), destDateTime, nightAngle)){
  695. newData.insert("ldgDay", "0");
  696. newData.insert("ldgNight", QString::number(ui->LandingSpinBox->value()));
  697. }else{
  698. newData.insert("ldgDay", QString::number(ui->LandingSpinBox->value()));
  699. newData.insert("ldgNight", "0");
  700. }
  701. }
  702. } else {
  703. newData.insert("ldgDay", "0");
  704. newData.insert("ldgNight", "0");
  705. }
  706. newData.insert("autoland", QString::number(ui->AutolandSpinBox->value()));
  707. newData.insert("ApproachType", ui->ApproachComboBox->currentText());
  708. newData.insert("FlightNumber", ui->FlightNumberLineEdit->text());
  709. newData.insert("Remarks", ui->RemarksLineEdit->text());
  710. }
  711. /*!
  712. * \brief NewFlight::fillExtrasLineEdits Fills the deductable items in the newData map and
  713. * additional flight time line edits according to ui selections.
  714. * Neccessary prerequisites are valid Date, Departure Time and Place, Destination Time and Place,
  715. * PIC name (pilot_id) and Aircraft (tail_id)
  716. */
  717. void NewFlightDialog::fillExtras()
  718. {
  719. //zero labels and line edits
  720. QList<QLineEdit*> LE = {ui->tSPSETimeLineEdit, ui->tSPMETimeLineEdit, ui->tMPTimeLineEdit, ui->tIFRTimeLineEdit,
  721. ui->tNIGHTTimeLineEdit,ui->tPICTimeLineEdit, ui->tPICUSTimeLineEdit, ui->tSICTimeLineEdit,
  722. ui->tDualTimeLineEdit, ui->tFITimeLineEdit,};
  723. QList<QLabel*> LB = {ui->tSPSELabel, ui->tSPMELabel, ui->tMPLabel, ui->tIFRLabel, ui->tNIGHTLabel,
  724. ui->tPICLabel, ui->tPICUSLabel, ui->tSICLabel, ui->tDualLabel, ui->tFILabel};
  725. for(const auto& widget : LE) {widget->setText("");}
  726. for(const auto& widget : LB) {widget->setText("00:00");}
  727. //Times
  728. auto tofb = QTime::fromString(ui->tofbTimeLineEdit->text(),"hh:mm");
  729. auto tonb = QTime::fromString(ui->tonbTimeLineEdit->text(),"hh:mm");
  730. QString blockTime = Calc::blocktime(tofb, tonb).toString("hh:mm");
  731. QString blockMinutes = QString::number(Calc::stringToMinutes(blockTime));
  732. ui->tblkTimeLineEdit->setText(blockTime);
  733. auto acft = Aircraft(newData.value("acft").toInt());
  734. if(!acft.data.isEmpty()){// valid aircraft
  735. // SP SE
  736. if(acft.data.value("singlepilot") == "1" && acft.data.value("singleengine") == "1"){
  737. ui->tSPSETimeLineEdit->setText(blockTime);
  738. ui->tSPSELabel->setText(blockTime);
  739. }
  740. // SP ME
  741. if(acft.data.value("singlepilot") == "1" && acft.data.value("multiengine") == "1"){
  742. ui->tSPMETimeLineEdit->setText(blockTime);
  743. ui->tSPMELabel->setText(blockTime);
  744. }
  745. // MP
  746. if(acft.data.value("multipilot") == "1"){
  747. ui->tMPTimeLineEdit->setText(blockTime);
  748. ui->tMPLabel->setText(blockTime);
  749. }
  750. }else{DEBUG("Aircraft Details Empty");}//invalid aircraft
  751. // TOTAL
  752. ui->tblkLabel->setText("<b>" + blockTime + "</b>");
  753. ui->tblkLabel->setStyleSheet("color: green;");
  754. // IFR
  755. if(ui->IfrCheckBox->isChecked()){
  756. ui->tIFRTimeLineEdit->setText(blockTime);
  757. ui->tIFRLabel->setText(blockTime);
  758. }
  759. // Night
  760. QString deptDate = ui->doftLineEdit->text() + 'T' + tofb.toString("hh:mm");
  761. QDateTime deptDateTime = QDateTime::fromString(deptDate,"yyyy-MM-ddThh:mm");
  762. int tblk = blockMinutes.toInt();
  763. const int nightAngle = Settings::read("flightlogging/nightangle").toInt();
  764. QString nightTime = QString::number(
  765. Calc::calculateNightTime(
  766. newData.value("dept"), newData.value("dest"),
  767. deptDateTime, tblk, nightAngle));
  768. ui->tNIGHTTimeLineEdit->setText(Calc::minutesToString(nightTime));
  769. ui->tNIGHTLabel->setText(Calc::minutesToString(nightTime));
  770. // Function times
  771. switch (ui->FunctionComboBox->currentIndex()) {
  772. case 0://PIC
  773. ui->tPICTimeLineEdit->setText(blockTime);
  774. ui->tPICLabel->setText(blockTime);
  775. break;
  776. case 1://PICus
  777. ui->tPICUSTimeLineEdit->setText(blockTime);
  778. ui->tPICUSLabel->setText(blockTime);
  779. break;
  780. case 2://Co-Pilot
  781. ui->tSICTimeLineEdit->setText(blockTime);
  782. ui->tSICLabel->setText(blockTime);
  783. break;
  784. case 3://Dual
  785. ui->tDualTimeLineEdit->setText(blockTime);
  786. ui->tDualLabel->setText(blockTime);
  787. break;
  788. case 4://Instructor
  789. ui->tFITimeLineEdit->setText(blockTime);
  790. ui->tFILabel->setText(blockTime);
  791. }
  792. }
  793. bool NewFlightDialog::verifyInput()
  794. {
  795. QVector<QLineEdit*> notFilled;
  796. for(auto lineEdit : mandatoryLineEdits)
  797. {
  798. if(!allOkBits.testBit(lineEditBitMap[lineEdit]))
  799. {
  800. notFilled.push_back(lineEdit);
  801. }
  802. }
  803. if(!notFilled.empty()){
  804. QMessageBox notFilledMessageBox(this);
  805. auto errorMsg = QString("Not all required fields are filled out.\n\n"
  806. "Plase make sure the following are not empty:\n\n"
  807. "Departure\nDestination\nTime Off Blocks\nTime On Blocks\n"
  808. "Pilot in Command\nAircraft Registration\n\n");
  809. notFilledMessageBox.setText(errorMsg);
  810. notFilledMessageBox.exec();
  811. return false;
  812. } else {
  813. QStringList lineEditText;
  814. for(auto line_edit : mandatoryLineEdits)
  815. {
  816. lineEditText.push_back(line_edit->text());
  817. }
  818. emit mandatoryFieldsValid(this);
  819. return true;
  820. }
  821. }
  822. /*!
  823. * ============================================================================
  824. * ============================================================================
  825. * Slots
  826. * ============================================================================
  827. * ============================================================================
  828. */
  829. void NewFlightDialog::on_buttonBox_accepted()
  830. {
  831. DEBUG("OK pressed");
  832. if(verifyInput()){
  833. DEBUG("Input verified");
  834. collectBasicData();
  835. collectAdditionalData();
  836. switch (role) {
  837. case Db::editExisting:
  838. entry.setData(newData);
  839. DEBUG("Editing entry: " << entry.position.first << " - " << entry.position.second);
  840. DEBUG("with Data: " << newData);
  841. DEBUG("Function Times: " << newData.value("tPIC") << newData.value("tPICus") << newData.value("tSIC")
  842. << newData.value("tDual") << newData.value("tFI"));
  843. break;
  844. case Db::createNew:
  845. entry = Flight(newData);
  846. DEBUG("Creating New entry: " << entry.position.first << " - " << entry.position.second);
  847. DEBUG("with Data: " << newData);
  848. break;
  849. }
  850. if(entry.commit()){
  851. accept();
  852. }else{
  853. auto mb = new QMessageBox(this);
  854. auto errorMsg = QString("Unable to commit Flight to Logbook."
  855. "The following error has ocurred:\n\n");
  856. errorMsg.append(entry.error);
  857. mb->setText(errorMsg);
  858. mb->show();
  859. }
  860. }
  861. }
  862. void NewFlightDialog::on_buttonBox_rejected()
  863. {
  864. DEBUG("CANCEL pressed." << newData);
  865. reject();
  866. }
  867. /*!
  868. * \brief onInputRejected Set `line_edit`'s border to red and check if `rgx` matches
  869. * in order to keep text on line. Ensures corresponding LineEdit bit is 0. Only
  870. * valid characters are kept on the line edit.
  871. */
  872. void NewFlightDialog::onInputRejected(QLineEdit* line_edit, QRegularExpression rgx){
  873. DEBUG("Input rejected" << line_edit->text());
  874. line_edit->setStyleSheet("border: 1px solid red");
  875. this->allOkBits.setBit(this->lineEditBitMap[line_edit], false);
  876. auto text = line_edit->text();
  877. if(!rgx.match(text).hasMatch())
  878. {
  879. line_edit->setText(text);
  880. }
  881. if(INVALID_CHARS_RGX.match(text).hasMatch()){//remove globaly inacceptable chars
  882. DEBUG("Removing invalid char: " << text[text.length()-1]);
  883. text.chop(1);
  884. line_edit->setText(text);
  885. }
  886. }
  887. /*!
  888. * \brief onEditingFinishedCleanup resets styles and sets the corresponding bit to 1
  889. */
  890. void NewFlightDialog::onEditingFinishedCleanup(QLineEdit* line_edit)
  891. {
  892. //DEBUG("Input accepted" << line_edit << line_edit->text());
  893. line_edit->setStyleSheet("");
  894. this->allOkBits.setBit(this->lineEditBitMap[line_edit], true);
  895. }
  896. /// Date
  897. void NewFlightDialog::on_doftLineEditEntered()
  898. {
  899. const auto& cw = ui->calendarWidget;
  900. const auto& le = ui->doftLineEdit;
  901. const auto& anchor = ui->placeLabel1;
  902. if(cw->isVisible()){
  903. le->blockSignals(false);
  904. DEBUG("cw visible. Enabling line edit signals for: " << le->objectName());
  905. cw->hide();
  906. anchor->resize(ui->placeLabel2->size());
  907. le->setFocus();
  908. } else {
  909. le->blockSignals(true);
  910. DEBUG("Disabling line edit signals for: " << le->objectName());
  911. // Determine size based on layout coordinates
  912. int c1 = anchor->pos().rx();
  913. int c2 = le->pos().rx();
  914. int z = le->size().rwidth();
  915. int x = (c2 - c1)+ z;
  916. c1 = anchor->pos().ry();
  917. c2 = ui->acftLineEdit->pos().ry();
  918. z = ui->acftLineEdit->size().height();
  919. int y = (c2 - c1) + z;
  920. //Re-size calendar and parent label accordingly
  921. anchor->resize(x, y);
  922. cw->setParent(ui->placeLabel1);
  923. cw->setGeometry(QRect(0, 0, x, y));
  924. cw->show();
  925. cw->setFocus();
  926. }
  927. }
  928. void NewFlightDialog::date_clicked(const QDate &date)
  929. {
  930. DEBUG("Date clicked: " << date);
  931. const auto& le = ui->doftLineEdit;
  932. le->blockSignals(false);
  933. ui->calendarWidget->hide();
  934. ui->placeLabel1->resize(ui->placeLabel2->size());
  935. le->setText(date.toString(Qt::ISODate));
  936. le->setFocus();
  937. }
  938. void NewFlightDialog::date_selected(const QDate &date)
  939. {
  940. ui->calendarWidget->hide();
  941. ui->placeLabel1->resize(ui->placeLabel2->size());
  942. ui->doftDisplayLabel->setText(date.toString(Qt::TextDate));
  943. DEBUG("Date selected: " << date);
  944. const auto& le = ui->doftLineEdit;
  945. le->setText(date.toString(Qt::ISODate));
  946. le->setFocus();
  947. le->blockSignals(false);
  948. DEBUG("Enabling line edit signals for: " << le->objectName());
  949. }
  950. void NewFlightDialog::on_doftLineEdit_inputRejected()
  951. {
  952. onInputRejected(ui->doftLineEdit, DATE_INVALID_RGX);
  953. ui->placeLabel1->resize(ui->placeLabel2->size());
  954. ui->calendarWidget->hide();
  955. }
  956. void NewFlightDialog::on_doftLineEdit_editingFinished()
  957. {
  958. DEBUG(sender()->objectName() << "EDITING FINISHED.");
  959. auto line_edit = ui->doftLineEdit;
  960. auto text = ui->doftLineEdit->text();
  961. {//try to correct input if only numbers are entered, eg 20200101
  962. const QSignalBlocker blocker(line_edit);
  963. if(text.length() == 8) {
  964. text.insert(4,'-');
  965. text.insert(7,'-');
  966. DEBUG("editet text: " << text);
  967. auto date = QDate::fromString(text, Qt::ISODate);
  968. if(date.isValid()) {
  969. line_edit->setText(date.toString(Qt::ISODate));
  970. ui->doftDisplayLabel->setText(date.toString(Qt::TextDate));
  971. }
  972. }
  973. }
  974. auto date = QDate::fromString(text, Qt::ISODate);
  975. if(date.isValid()){
  976. onEditingFinishedCleanup(line_edit);
  977. const QSignalBlocker blocker(line_edit);
  978. ui->doftDisplayLabel->setText(date.toString(Qt::TextDate));
  979. } else {
  980. ui->doftDisplayLabel->setText("Invalid Date");
  981. emit line_edit->inputRejected();
  982. }
  983. }
  984. void NewFlightDialog::on_deptTZ_currentTextChanged(const QString &arg1)
  985. {
  986. DEBUG(arg1);
  987. // currently only UTC time logging is supported
  988. ui->deptTZ->setCurrentIndex(0);
  989. }
  990. void NewFlightDialog::on_destTZ_currentIndexChanged(const QString &arg1)
  991. {
  992. DEBUG(arg1);
  993. // currently only UTC time logging is supported
  994. ui->destTZ->setCurrentIndex(0);
  995. }
  996. /// Departure
  997. void NewFlightDialog::on_deptLocLineEdit_inputRejected()
  998. {
  999. //DEBUG("SENDER --->" << sender());
  1000. ui->deptLocLineEdit->setText(ui->deptLocLineEdit->text().toUpper());
  1001. onInputRejected(ui->deptLocLineEdit, QRegularExpression(LOC_INVALID_RGX));
  1002. }
  1003. void NewFlightDialog::on_deptLocLineEdit_textEdited(const QString &arg1)
  1004. {
  1005. ui->deptLocLineEdit->setText(arg1.toUpper());
  1006. }
  1007. void NewFlightDialog::on_deptLocLineEdit_editingFinished()
  1008. {
  1009. //DEBUG(sender()->objectName() << "EDITING FINISHED");
  1010. auto line_edit = ui->deptLocLineEdit;
  1011. auto text = ui->deptLocLineEdit->text();
  1012. // check if iata exists, replace with icao code if it does.
  1013. if(text.length() == 3){
  1014. text = airportMap.value(text);
  1015. }
  1016. // Check if 4-letter code is in locationList
  1017. if(text.length() == 4 && airports.indexOf(text) == -1){
  1018. //DEBUG("Airport not found.");
  1019. emit line_edit->inputRejected();
  1020. return;
  1021. }else{
  1022. //DEBUG("Departure accepted: " << text);
  1023. line_edit->setText(text);
  1024. onEditingFinishedCleanup(line_edit); //reset style sheet
  1025. ui->deptNameLabel->setText(Db::singleSelect("name","airports","icao",text,Db::exactMatch));
  1026. update();
  1027. }
  1028. }
  1029. void NewFlightDialog::on_tofbTimeLineEdit_inputRejected()
  1030. {
  1031. onInputRejected(ui->tofbTimeLineEdit, QRegularExpression(TIME_INVALID_RGX));
  1032. }
  1033. void NewFlightDialog::on_tofbTimeLineEdit_editingFinished()
  1034. {
  1035. ui->tofbTimeLineEdit->setText(Calc::formatTimeInput(ui->tofbTimeLineEdit->text()));
  1036. const auto time = QTime::fromString(ui->tofbTimeLineEdit->text(),"hh:mm");
  1037. auto line_edit = ui->tofbTimeLineEdit;
  1038. onEditingFinishedCleanup(line_edit);
  1039. if(time.isValid()){
  1040. int minutes = time.hour() * 60 + time.minute();
  1041. QString tofb = QString::number(minutes);
  1042. //DEBUG("Time Off Blocks accepted: " << tofb << " minutes - " << Calc::minutesToString(tofb));
  1043. }else{
  1044. emit line_edit->inputRejected();
  1045. }
  1046. onEditingFinishedCleanup(line_edit);
  1047. update();
  1048. }
  1049. /// Destination
  1050. void NewFlightDialog::on_destLocLineEdit_inputRejected()
  1051. {
  1052. ui->destLocLineEdit->setText(ui->destLocLineEdit->text().toUpper());
  1053. onInputRejected(ui->destLocLineEdit, QRegularExpression(LOC_INVALID_RGX));
  1054. }
  1055. void NewFlightDialog::on_destLocLineEdit_textEdited(const QString &arg1)
  1056. {
  1057. ui->destLocLineEdit->setText(arg1.toUpper());
  1058. }
  1059. void NewFlightDialog::on_destLocLineEdit_editingFinished()
  1060. {
  1061. //DEBUG(sender()->objectName() << "EDITING FINISHED");
  1062. auto line_edit = ui->destLocLineEdit;
  1063. auto text = ui->destLocLineEdit->text();
  1064. // check if iata exists, replace with icao code if it does.
  1065. if(text.length() == 3){
  1066. text = airportMap.value(text);
  1067. }
  1068. // Check if 4-letter code is in locationList
  1069. if(text.length() == 4 && airports.indexOf(text) == -1){
  1070. //DEBUG("Airport not found.");
  1071. emit line_edit->inputRejected();
  1072. return;
  1073. }else{
  1074. //DEBUG("Destination accepted: " << text);
  1075. line_edit->setText(text);
  1076. onEditingFinishedCleanup(line_edit); //reset style sheet
  1077. ui->destNameLabel->setText(Db::singleSelect("name","airports","icao",text,Db::exactMatch));
  1078. update();
  1079. }
  1080. }
  1081. void NewFlightDialog::on_tonbTimeLineEdit_inputRejected()
  1082. {
  1083. onInputRejected(ui->tonbTimeLineEdit, QRegularExpression(TIME_INVALID_RGX));
  1084. }
  1085. void NewFlightDialog::on_tonbTimeLineEdit_editingFinished()
  1086. {
  1087. ui->tonbTimeLineEdit->setText(Calc::formatTimeInput(ui->tonbTimeLineEdit->text()));
  1088. auto line_edit = ui->tonbTimeLineEdit;
  1089. const auto time = QTime::fromString(ui->tonbTimeLineEdit->text(),"hh:mm");
  1090. if(time.isValid()){
  1091. int minutes = time.hour() * 60 + time.minute();
  1092. QString tonb = QString::number(minutes);
  1093. newData.insert("tonb",tonb);
  1094. //DEBUG("Time On Blocks accepted: " << tonb << " minutes - " << Calc::minutesToString(tonb));
  1095. }else{
  1096. emit line_edit->inputRejected();
  1097. }
  1098. onEditingFinishedCleanup(line_edit);
  1099. update();
  1100. }
  1101. /// Date
  1102. void NewFlightDialog::on_doftTimeEdit_editingFinished()
  1103. {
  1104. update();
  1105. }
  1106. /// Aircraft
  1107. void NewFlightDialog::on_acftLineEdit_inputRejected()
  1108. {
  1109. ui->acftLineEdit->setText(ui->acftLineEdit->text().toUpper());
  1110. onInputRejected(ui->acftLineEdit, QRegularExpression(AIRCRAFT_INVALID_RGX));
  1111. }
  1112. void NewFlightDialog::on_acftLineEdit_editingFinished()
  1113. {
  1114. auto registrationList = CompletionList(CompleterTarget::registrations).list;
  1115. auto line_edit = ui->acftLineEdit;
  1116. auto text = ui->acftLineEdit->text();
  1117. QStringList match = registrationList.filter(line_edit->text(), Qt::CaseInsensitive);
  1118. //DEBUG("aircraft accepted: " << match);
  1119. if(match.length() != 0) {
  1120. text = match[0];
  1121. line_edit->setText(text.toUpper());
  1122. onEditingFinishedCleanup(line_edit);
  1123. QString column = "make||' '||model||'-'||variant";
  1124. ui->acftTypeLabel->setText(
  1125. Db::singleSelect(column,"tails","registration",text,Db::exactMatch));
  1126. update();
  1127. }else{
  1128. emit line_edit->inputRejected();
  1129. addNewAircraftMessageBox(line_edit);
  1130. }
  1131. }
  1132. /// Pilot(s)
  1133. void NewFlightDialog::on_picNameLineEdit_inputRejected()
  1134. {
  1135. onInputRejected(ui->picNameLineEdit, QRegularExpression(PILOT_NAME_INVALID_RGX));
  1136. }
  1137. void NewFlightDialog::on_picNameLineEdit_editingFinished()
  1138. {
  1139. auto line_edit = ui->picNameLineEdit;
  1140. auto text = line_edit->text();
  1141. if(text == "self" || text == "SELF") // Logbook owner is PIC
  1142. {
  1143. //DEBUG("Pilot selected: " << text);
  1144. onEditingFinishedCleanup(line_edit);
  1145. ui->FunctionComboBox->setCurrentIndex(0);
  1146. update();
  1147. return;
  1148. }else //check if entry is in pilotList
  1149. {
  1150. QStringList pilotList = CompletionList(CompleterTarget::pilots).list;
  1151. QStringList match = pilotList.filter(line_edit->text().remove(" "), Qt::CaseInsensitive);
  1152. if(match.length()!= 0)
  1153. {
  1154. QString pic = match[0];
  1155. line_edit->setText(pic.insert(pic.indexOf(',')+1," "));
  1156. //DEBUG("Pilot selected: " << pic);
  1157. onEditingFinishedCleanup(line_edit);
  1158. update();
  1159. }else
  1160. {
  1161. DEBUG("Pilot not found.");
  1162. emit line_edit->inputRejected();
  1163. addNewPilotMessageBox(line_edit);
  1164. }
  1165. }
  1166. }
  1167. /*
  1168. * ============================================================================
  1169. * The above entris are mandatory for logging a flight,
  1170. * the rest of the entries are either optional or can
  1171. * be determined from the entries already made.
  1172. * ============================================================================
  1173. */
  1174. void NewFlightDialog::on_secondPilotNameLineEdit_inputRejected()
  1175. {
  1176. onInputRejected(ui->secondPilotNameLineEdit, QRegularExpression(PILOT_NAME_INVALID_RGX));
  1177. }
  1178. void NewFlightDialog::on_secondPilotNameLineEdit_editingFinished()
  1179. {
  1180. auto line_edit = ui->secondPilotNameLineEdit;
  1181. auto text = line_edit->text();
  1182. if(text == "self" || text == "SELF") // Logbook owner is Pilot
  1183. {
  1184. //DEBUG("Pilot selected: " << text);
  1185. onEditingFinishedCleanup(line_edit);
  1186. ui->FunctionComboBox->setCurrentIndex(1);
  1187. return;
  1188. }else //check if entry is in pilotList
  1189. {
  1190. QStringList pilotList = CompletionList(CompleterTarget::pilots).list;
  1191. QStringList match = pilotList.filter(line_edit->text().remove(" "), Qt::CaseInsensitive);
  1192. if(match.length()!= 0)
  1193. {
  1194. QString pic = match[0];
  1195. line_edit->setText(pic.insert(pic.indexOf(',')+1," "));
  1196. //DEBUG("Pilot selected: " << pic);
  1197. onEditingFinishedCleanup(line_edit);
  1198. }else
  1199. {
  1200. DEBUG("Pilot not found.");
  1201. emit line_edit->inputRejected();
  1202. addNewPilotMessageBox(line_edit);
  1203. }
  1204. }
  1205. }
  1206. void NewFlightDialog::on_thirdPilotNameLineEdit_inputRejected()
  1207. {
  1208. onInputRejected(ui->thirdPilotNameLineEdit, QRegularExpression(PILOT_NAME_INVALID_RGX));
  1209. }
  1210. void NewFlightDialog::on_thirdPilotNameLineEdit_editingFinished()
  1211. {
  1212. auto line_edit = ui->thirdPilotNameLineEdit;
  1213. auto text = line_edit->text();
  1214. if(text == "self" || text == "SELF") // Logbook owner is Pilot
  1215. {
  1216. //DEBUG("Pilot selected: " << text);
  1217. onEditingFinishedCleanup(line_edit);
  1218. return;
  1219. }else //check if entry is in pilotList
  1220. {
  1221. QStringList pilotList = CompletionList(CompleterTarget::pilots).list;
  1222. QStringList match = pilotList.filter(line_edit->text().remove(" "), Qt::CaseInsensitive);
  1223. if(match.length()!= 0)
  1224. {
  1225. QString pic = match[0];
  1226. line_edit->setText(pic.insert(pic.indexOf(',')+1," "));
  1227. //DEBUG("Pilot selected: " << pic);
  1228. onEditingFinishedCleanup(line_edit);
  1229. }else
  1230. {
  1231. DEBUG("Pilot not found.");
  1232. emit line_edit->inputRejected();
  1233. addNewPilotMessageBox(line_edit);
  1234. }
  1235. }
  1236. }
  1237. void NewFlightDialog::on_FlightNumberLineEdit_textChanged(const QString &arg1)
  1238. {
  1239. ui->FlightNumberLineEdit->setText(arg1.toUpper());
  1240. }
  1241. /*
  1242. * ============================================================================
  1243. * Extras Tab - These are for user convenience. From many of
  1244. * these selections, determinations can be made on how to log
  1245. * details, so that the user does not have to enter each item
  1246. * manually. See also fillExtrasLineEdits()
  1247. * ============================================================================
  1248. */
  1249. void NewFlightDialog::on_setAsDefaultButton_clicked()
  1250. {
  1251. writeSettings();
  1252. }
  1253. void NewFlightDialog::on_restoreDefaultButton_clicked()
  1254. {
  1255. readSettings();
  1256. }
  1257. /*!
  1258. * \brief On a given flight, time can either be logged as Pilot Flying (PF) or
  1259. * Pilot Monitoring (PM). Cases where controls are changed during the flight
  1260. * are rare and can be logged by manually editing the extras.
  1261. */
  1262. void NewFlightDialog::on_PilotFlyingCheckBox_stateChanged(int)
  1263. {
  1264. DEBUG("PF checkbox state changed.");
  1265. if(ui->PilotFlyingCheckBox->isChecked()){
  1266. ui->TakeoffSpinBox->setValue(1);
  1267. ui->TakeoffCheckBox->setCheckState(Qt::Checked);
  1268. ui->LandingSpinBox->setValue(1);
  1269. ui->LandingCheckBox->setCheckState(Qt::Checked);
  1270. }else if(!ui->PilotFlyingCheckBox->isChecked()){
  1271. ui->TakeoffSpinBox->setValue(0);
  1272. ui->TakeoffCheckBox->setCheckState(Qt::Unchecked);
  1273. ui->LandingSpinBox->setValue(0);
  1274. ui->LandingCheckBox->setCheckState(Qt::Unchecked);
  1275. }
  1276. }
  1277. void NewFlightDialog::on_IfrCheckBox_stateChanged()
  1278. {
  1279. update();
  1280. }
  1281. void NewFlightDialog::on_ApproachComboBox_currentTextChanged(const QString &arg1)
  1282. {
  1283. if(arg1 == "ILS CAT III"){ //for a CAT III approach an Autoland is mandatory, so we can preselect it.
  1284. ui->AutolandCheckBox->setCheckState(Qt::Checked);
  1285. ui->AutolandSpinBox->setValue(1);
  1286. }else{
  1287. ui->AutolandCheckBox->setCheckState(Qt::Unchecked);
  1288. ui->AutolandSpinBox->setValue(0);
  1289. }
  1290. }
  1291. /*
  1292. * Extra Times - These line edits should be filled out automatically,
  1293. * based on the ui selections and the user provided input. However,
  1294. * manual adjustments are possible to cater for situations where for
  1295. * example one portion of the flight is logged under different rules
  1296. * than the rest of it.
  1297. *
  1298. * For example,
  1299. * if we know the aircraft details we can determine how to log these times.
  1300. * Some times are mutually exclusive, others can be combined.
  1301. *
  1302. * For example,
  1303. * for a commercial Passenger flight, the commander can log all time as
  1304. * Total Time and PIC time. If the aircraft is a multi-engine jet he can
  1305. * also log Multi-Pilot time, and if he is an instructor, instructor time.
  1306. *
  1307. * It is not possible, however to log flight time as VFR or IFR time
  1308. * simultaneously, as a flight at any given point in time can only follow
  1309. * one set of rules. It is possible, to change flight rules and log the first
  1310. * x minutes as VFR and the rest of it as IFR, for example. Hence the need
  1311. * for the possibility to edit these times manually.
  1312. *
  1313. * The most complex time to determine is night time, see documentation of
  1314. * the calc class for details.
  1315. *
  1316. * In General, the idea is to automatically fill as much as possible, but
  1317. * if the user decides to change these times, accept the inputs, as long as
  1318. * they are generally valid. We cannot cater for all possibilities, so as long
  1319. * as the time the user has put in is a valid time <= Total Time, it can be
  1320. * accepted to the database.
  1321. */
  1322. inline bool NewFlightDialog::isLessOrEqualToTotalTime(QString timeString)
  1323. {
  1324. if(newData.value("tblk").isEmpty()){
  1325. DEBUG("Total Time not set.");
  1326. auto mb = new QMessageBox(this);
  1327. mb->setText("Please fill out Departure and Arrival Time\n"
  1328. "before manually editing these times.");
  1329. mb->show();
  1330. return false;
  1331. } else {
  1332. int minutes = Calc::stringToMinutes(timeString);
  1333. if (minutes <= newData.value("tblk").toInt()) {
  1334. return true;
  1335. } else {
  1336. auto mb = new QMessageBox(this);
  1337. mb->setText("Cannot be more than Total Time of Flight:<br><br><center><b>"
  1338. + Calc::minutesToString(newData.value("tblk"))
  1339. + "</b></center><br>");
  1340. mb->show();
  1341. return false;
  1342. }
  1343. }
  1344. }
  1345. void NewFlightDialog::on_tblkTimeLineEdit_editingFinished()
  1346. {
  1347. const auto &le = ui->tblkTimeLineEdit;
  1348. le->setText(Calc::formatTimeInput(le->text()));
  1349. const auto &text = le->text();
  1350. newData.insert("tblk",QString::number(Calc::stringToMinutes(text)));
  1351. le->setText(QString());
  1352. }
  1353. void NewFlightDialog::on_tSPSETimeLineEdit_editingFinished()
  1354. {
  1355. const auto &le = ui->tSPSETimeLineEdit;
  1356. le->setText(Calc::formatTimeInput(le->text()));
  1357. const auto &text = le->text();
  1358. if(isLessOrEqualToTotalTime(text)){
  1359. newData.insert("tSPSE",QString::number(Calc::stringToMinutes(text)));
  1360. } else {
  1361. le->setText(QString());
  1362. }
  1363. }
  1364. void NewFlightDialog::on_tSPMETimeLineEdit_editingFinished()
  1365. {
  1366. const auto &le = ui->tSPMETimeLineEdit;
  1367. le->setText(Calc::formatTimeInput(le->text()));
  1368. const auto &text = le->text();
  1369. if(isLessOrEqualToTotalTime(text)){
  1370. newData.insert("tSPME",QString::number(Calc::stringToMinutes(text)));
  1371. } else {
  1372. le->setText(QString());
  1373. }
  1374. }
  1375. void NewFlightDialog::on_tMPTimeLineEdit_editingFinished()
  1376. {
  1377. const auto &le = ui->tMPTimeLineEdit;
  1378. le->setText(Calc::formatTimeInput(le->text()));
  1379. const auto &text = le->text();
  1380. if(isLessOrEqualToTotalTime(text)){
  1381. newData.insert("tMP",QString::number(Calc::stringToMinutes(text)));
  1382. } else {
  1383. le->setText(QString());
  1384. }
  1385. }
  1386. void NewFlightDialog::on_tIFRTimeLineEdit_editingFinished()
  1387. {
  1388. const auto &le = ui->tIFRTimeLineEdit;
  1389. le->setText(Calc::formatTimeInput(le->text()));
  1390. const auto &text = le->text();
  1391. if(isLessOrEqualToTotalTime(text)){
  1392. newData.insert("tIFR",QString::number(Calc::stringToMinutes(text)));
  1393. } else {
  1394. le->setText(QString());
  1395. }
  1396. }
  1397. void NewFlightDialog::on_tNIGHTTimeLineEdit_editingFinished()
  1398. {
  1399. const auto &le = ui->tNIGHTTimeLineEdit;
  1400. le->setText(Calc::formatTimeInput(le->text()));
  1401. const auto &text = le->text();
  1402. if(isLessOrEqualToTotalTime(text)){
  1403. newData.insert("tNIGHT",QString::number(Calc::stringToMinutes(text)));
  1404. } else {
  1405. le->setText(QString());
  1406. }
  1407. }
  1408. void NewFlightDialog::on_tPICTimeLineEdit_editingFinished()
  1409. {
  1410. const auto &le = ui->tPICTimeLineEdit;
  1411. le->setText(Calc::formatTimeInput(le->text()));
  1412. const auto &text = le->text();
  1413. if(isLessOrEqualToTotalTime(text)){
  1414. newData.insert("tPIC",QString::number(Calc::stringToMinutes(text)));
  1415. } else {
  1416. le->setText(QString());
  1417. }
  1418. }
  1419. void NewFlightDialog::on_tSICTimeLineEdit_editingFinished()
  1420. {
  1421. const auto &le = ui->tSICTimeLineEdit;
  1422. le->setText(Calc::formatTimeInput(le->text()));
  1423. const auto &text = le->text();
  1424. if(isLessOrEqualToTotalTime(text)){
  1425. newData.insert("tSIC",QString::number(Calc::stringToMinutes(text)));
  1426. } else {
  1427. le->setText(QString());
  1428. }
  1429. }
  1430. void NewFlightDialog::on_tDualTimeLineEdit_editingFinished()
  1431. {
  1432. const auto &le = ui->tDualTimeLineEdit;
  1433. le->setText(Calc::formatTimeInput(le->text()));
  1434. const auto &text = le->text();
  1435. if(isLessOrEqualToTotalTime(text)){
  1436. newData.insert("tDual",QString::number(Calc::stringToMinutes(text)));
  1437. } else {
  1438. le->setText(QString());
  1439. }
  1440. }
  1441. void NewFlightDialog::on_tFITimeLineEdit_editingFinished()
  1442. {
  1443. const auto &le = ui->tFITimeLineEdit;
  1444. le->setText(Calc::formatTimeInput(le->text()));
  1445. const auto &text = le->text();
  1446. if(isLessOrEqualToTotalTime(text)){
  1447. newData.insert("tFI",QString::number(Calc::stringToMinutes(text)));
  1448. } else {
  1449. le->setText(QString());
  1450. }
  1451. }
  1452. void NewFlightDialog::on_manualEditingCheckBox_stateChanged(int arg1)
  1453. {
  1454. QList<QLineEdit*> LE = {ui->tSPSETimeLineEdit, ui->tSPMETimeLineEdit, ui->tMPTimeLineEdit, ui->tIFRTimeLineEdit,
  1455. ui->tNIGHTTimeLineEdit,ui->tPICTimeLineEdit, ui->tPICUSTimeLineEdit, ui->tSICTimeLineEdit,
  1456. ui->tDualTimeLineEdit, ui->tFITimeLineEdit,};
  1457. switch (arg1) {
  1458. case 0:
  1459. for(const auto& le : LE){
  1460. le->setFocusPolicy(Qt::NoFocus);
  1461. doUpdate = true;
  1462. update();
  1463. }
  1464. break;
  1465. case 2:
  1466. for(const auto& le : LE){
  1467. le->setFocusPolicy(Qt::StrongFocus);
  1468. doUpdate = false;
  1469. }
  1470. break;
  1471. default:
  1472. break;
  1473. }
  1474. }
  1475. void NewFlightDialog::on_FunctionComboBox_currentTextChanged()
  1476. {
  1477. DEBUG("Current Index:" << ui->FunctionComboBox->currentIndex());
  1478. update();
  1479. }
  1480. void NewFlightDialog::on_TakeoffSpinBox_valueChanged(int arg1)
  1481. {
  1482. if(arg1 > 0) {
  1483. ui->TakeoffCheckBox->setChecked(true);
  1484. }
  1485. }
  1486. void NewFlightDialog::on_LandingSpinBox_valueChanged(int arg1)
  1487. {
  1488. if(arg1 > 0) {
  1489. ui->LandingCheckBox->setChecked(true);
  1490. }
  1491. }
  1492. void NewFlightDialog::on_AutolandSpinBox_valueChanged(int arg1)
  1493. {
  1494. if(arg1 > 0) {
  1495. ui->AutolandCheckBox->setChecked(true);
  1496. }
  1497. }
  1498. void NewFlightDialog::on_TakeoffCheckBox_stateChanged(int arg1)
  1499. {
  1500. if(arg1 == 0) {
  1501. ui->TakeoffSpinBox->setValue(0);
  1502. } else if ( arg1 == 2) {
  1503. ui->TakeoffSpinBox->setValue(1);
  1504. }
  1505. }
  1506. void NewFlightDialog::on_LandingCheckBox_stateChanged(int arg1)
  1507. {
  1508. if(arg1 == 0) {
  1509. ui->LandingSpinBox->setValue(0);
  1510. } else if ( arg1 == 2) {
  1511. ui->LandingSpinBox->setValue(1);
  1512. }
  1513. }
  1514. void NewFlightDialog::on_AutolandCheckBox_stateChanged(int arg1)
  1515. {
  1516. if(arg1 == 0) {
  1517. ui->AutolandSpinBox->setValue(0);
  1518. } else if ( arg1 == 2) {
  1519. ui->AutolandSpinBox->setValue(1);
  1520. }
  1521. }