aentry.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. *openPilotLog - A FOSS Pilot Logbook Application
  3. *Copyright (C) 2020-2021 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 "aentry.h"
  19. AEntry::AEntry(DataPosition position_)
  20. : position(position_)
  21. {}
  22. AEntry::AEntry(RowData_T table_data)
  23. : tableData(table_data)
  24. {}
  25. AEntry::AEntry(DataPosition position_, RowData_T table_data)
  26. : position(position_), tableData(table_data)
  27. {}
  28. void AEntry::setData(RowData_T table_data)
  29. {
  30. tableData = table_data;
  31. }
  32. void AEntry::setPosition(DataPosition position_)
  33. {
  34. position = position_;
  35. }
  36. const DataPosition& AEntry::getPosition() const
  37. {
  38. return position;
  39. }
  40. const RowData_T& AEntry::getData() const
  41. {
  42. return tableData;
  43. }
  44. AEntry::operator QString() const
  45. {
  46. QString out("\033[32m[Entry Data]:\t\033[m\n");
  47. int item_count = 0;
  48. QHash<ColName_T, ColData_T>::const_iterator i;
  49. for (i = tableData.constBegin(); i!= tableData.constEnd(); ++i) {
  50. QString spacer(":");
  51. int spaces = (14 - i.key().length());
  52. if (spaces > 0)
  53. for (int i = 0; i < spaces ; i++)
  54. spacer += QLatin1Char(' ');
  55. if (i.value().toString().isEmpty()) {
  56. out.append(QLatin1String("\t\033[m") + i.key()
  57. + spacer
  58. + QLatin1String("\033[35m----"));
  59. spaces = (14 - i.value().toString().length());
  60. spacer = QString();
  61. if (spaces > 0)
  62. for (int i = 0; i < spaces ; i++)
  63. spacer += QLatin1Char(' ');
  64. out.append(spacer);
  65. } else {
  66. out.append(QLatin1String("\t\033[m") + i.key()
  67. + spacer
  68. + QLatin1String("\033[35m")
  69. + i.value().toString());
  70. spaces = (14 - i.value().toString().length());
  71. spacer = QString();
  72. if (spaces > 0)
  73. for (int i = 0; i < spaces ; i++)
  74. spacer += QLatin1Char(' ');
  75. out.append(spacer);
  76. }
  77. item_count ++;
  78. if (item_count % 4 == 0)
  79. out.append(QLatin1String("\n"));
  80. }
  81. out.append(QLatin1String("\n"));
  82. QTextStream(stdout) << out;
  83. return QString();
  84. }