dbvalidate.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 "dbvalidate.h"
  19. #include "dbapi.h"
  20. // named functions
  21. bool dbValidate::verify_id(QString id)
  22. {
  23. if (id.toInt()>=0){return true;}else{return false;}
  24. }
  25. bool dbValidate::verify_doft(QString doft)
  26. {
  27. return QDate::fromString(doft,Qt::ISODate).isValid();
  28. }
  29. bool dbValidate::verify_dept(QString dept)
  30. {
  31. return dbAirport::checkICAOValid(dept);
  32. }
  33. bool dbValidate::verify_dest(QString dest)
  34. {
  35. return dbAirport::checkICAOValid(dest);
  36. }
  37. bool dbValidate::verify_tofb(QString tofb)
  38. {
  39. return QTime::fromString(tofb,"hh:mm").isValid();
  40. }
  41. bool dbValidate::verify_tonb(QString tonb)
  42. {
  43. return QTime::fromString(tonb,"hh:mm").isValid();
  44. }
  45. bool dbValidate::verify_pic(QString picname)
  46. {
  47. return dbPilots::verifyPilotExists(picname.split(QLatin1Char(',')));
  48. }
  49. bool dbValidate::verify_acft(QString registration)
  50. {
  51. return !dbAircraft::retreiveTailId(registration).isEmpty();
  52. }
  53. bool dbValidate::verify_tblk(QString tblk)
  54. {
  55. return QTime::fromString(tblk,"hh:mm").isValid();
  56. }
  57. bool dbValidate::verify_tSPSE(QString tSPSE)
  58. {
  59. return QTime::fromString(tSPSE,"hh:mm").isValid();
  60. }
  61. bool dbValidate::verify_tSPME(QString tSPME)
  62. {
  63. return QTime::fromString(tSPME,"hh:mm").isValid();
  64. }
  65. bool dbValidate::verify_tMP(QString tMP)
  66. {
  67. return QTime::fromString(tMP,"hh:mm").isValid();
  68. }
  69. bool dbValidate::verify_tNIGHT(QString tNIGHT)
  70. {
  71. return QTime::fromString(tNIGHT,"hh:mm").isValid();
  72. }
  73. bool dbValidate::verify_tIFR(QString tIFR)
  74. {
  75. return QTime::fromString(tIFR,"hh:mm").isValid();
  76. }
  77. bool dbValidate::verify_tPIC(QString tPIC)
  78. {
  79. return QTime::fromString(tPIC,"hh:mm").isValid();
  80. }
  81. bool dbValidate::verify_tPICUS(QString tPICUS)
  82. {
  83. return QTime::fromString(tPICUS,"hh:mm").isValid();
  84. }
  85. bool dbValidate::verify_tSIC(QString tSIC)
  86. {
  87. return QTime::fromString(tSIC,"hh:mm").isValid();
  88. }
  89. bool dbValidate::verify_tDual(QString tDual)
  90. {
  91. return QTime::fromString(tDual,"hh:mm").isValid();
  92. }
  93. bool dbValidate::verify_tFI(QString tFI)
  94. {
  95. return QTime::fromString(tFI,"hh:mm").isValid();
  96. }
  97. bool dbValidate::verify_tSIM(QString tSIM)
  98. {
  99. return QTime::fromString(tSIM,"hh:mm").isValid();
  100. }
  101. bool dbValidate::verify_pilotFlying(QString pf)
  102. {
  103. if(pf.toInt() == 1 || pf.toInt() == 0){
  104. return true;
  105. }else{return false;}
  106. }
  107. bool dbValidate::verify_toDay(QString toDay)
  108. {
  109. if(toDay.toInt() <= 0){
  110. return true;
  111. }else{return false;}
  112. }
  113. bool dbValidate::verify_toNight(QString toNight)
  114. {
  115. if(toNight.toInt() <= 0){
  116. return true;
  117. }else{return false;}
  118. }
  119. bool dbValidate::verify_ldgDay(QString ldgDay)
  120. {
  121. if(ldgDay.toInt() <= 0){
  122. return true;
  123. }else{return false;}
  124. }
  125. bool dbValidate::verify_ldgNight(QString ldgNight)
  126. {
  127. if(ldgNight.toInt() <= 0){
  128. return true;
  129. }else{return false;}
  130. }
  131. bool dbValidate::verify_autoland(QString autoland)
  132. {
  133. if(autoland.toInt() <= 0){
  134. return true;
  135. }else{
  136. return false;}
  137. }
  138. bool dbValidate::verify_secondPilot(QString pilotName)
  139. {
  140. return dbPilots::verifyPilotExists(pilotName.split(QLatin1Char(',')));
  141. }
  142. bool dbValidate::verify_thirdPilot(QString pilotName)
  143. {
  144. return dbPilots::verifyPilotExists(pilotName.split(QLatin1Char(',')));
  145. }
  146. bool dbValidate::verify_FlightNumber(QString flightNumer)
  147. {
  148. QRegularExpression notAllowed("[^a-zA-Z0-9-]+");
  149. if(!flightNumer.contains(notAllowed)){
  150. return true;
  151. }else{
  152. return false;}
  153. }
  154. bool dbValidate::verify_Remarks(QString remarks)
  155. {
  156. QRegularExpression notAllowed("[^a-zA-Z0-9\(\)\\s]+");
  157. if(remarks.length() < 20 && !remarks.contains(notAllowed)){
  158. return true;
  159. }else{
  160. return false;}
  161. }