acurrencyentry.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include "acurrencyentry.h"
  2. #include "src/opl.h"
  3. AEntry::AEntry(DataPosition position_)
  4. : position(position_)
  5. {}
  6. AEntry::AEntry(RowData_T table_data)
  7. : tableData(table_data)
  8. {}
  9. AEntry::AEntry(DataPosition position_, RowData_T table_data)
  10. : position(position_), tableData(table_data)
  11. {}
  12. void AEntry::setData(RowData_T table_data)
  13. {
  14. tableData = table_data;
  15. }
  16. void AEntry::setPosition(DataPosition position_)
  17. {
  18. position = position_;
  19. }
  20. const DataPosition& AEntry::getPosition() const
  21. {
  22. return position;
  23. }
  24. const RowData_T& AEntry::getData() const
  25. {
  26. return tableData;
  27. }
  28. AEntry::operator QString() const
  29. {
  30. QString out("\033[32m[Entry Data]:\t\033[m\n");
  31. int item_count = 0;
  32. QHash<ColName_T, ColData_T>::const_iterator i;
  33. for (i = tableData.constBegin(); i!= tableData.constEnd(); ++i) {
  34. QString spacer(":");
  35. int spaces = (14 - i.key().length());
  36. if (spaces > 0)
  37. for (int i = 0; i < spaces ; i++)
  38. spacer += QLatin1Char(' ');
  39. if (i.value().toString().isEmpty()) {
  40. out.append(QLatin1String("\t\033[m") + i.key()
  41. + spacer
  42. + QLatin1String("\033[35m----"));
  43. spaces = (14 - i.value().toString().length());
  44. spacer = QString();
  45. if (spaces > 0)
  46. for (int i = 0; i < spaces ; i++)
  47. spacer += QLatin1Char(' ');
  48. out.append(spacer);
  49. } else {
  50. out.append(QLatin1String("\t\033[m") + i.key()
  51. + spacer
  52. + QLatin1String("\033[35m")
  53. + i.value().toString());
  54. spaces = (14 - i.value().toString().length());
  55. spacer = QString();
  56. if (spaces > 0)
  57. for (int i = 0; i < spaces ; i++)
  58. spacer += QLatin1Char(' ');
  59. out.append(spacer);
  60. }
  61. item_count ++;
  62. if (item_count % 4 == 0)
  63. out.append(QLatin1String("\n"));
  64. }
  65. out.append(QLatin1String("\n"));
  66. QTextStream(stdout) << out;
  67. return QString();
  68. }
  69. /*!
  70. * \brief ACurrencyEntry::ACurrencyEntry Creates an ACurrenyEntry object.
  71. *
  72. * The Data Position is initalized by using the strongly typed enum
  73. * CurrencyName, which maps to the static row id for the currency.
  74. */
  75. ACurrencyEntry::ACurrencyEntry(ACurrencyEntry::CurrencyName currency_name)
  76. : AEntry::AEntry(DataPosition(OPL::Db::TABLE_CURRENCIES, static_cast<int>(currency_name)))
  77. {}
  78. ACurrencyEntry::ACurrencyEntry(ACurrencyEntry::CurrencyName currency_name, QDate expiration_date)
  79. : AEntry::AEntry(DataPosition(OPL::Db::TABLE_CURRENCIES, static_cast<int>(currency_name)))
  80. {
  81. if (expiration_date.isValid()) {
  82. tableData.insert(OPL::Db::CURRENCIES_EXPIRYDATE, expiration_date.toString(Qt::ISODate));
  83. } else {
  84. DEB << "Invalid Date.";
  85. }
  86. }
  87. /*!
  88. * \brief ACurrencyEntry::isValid returns true if the object holds a valid expiration date.
  89. *
  90. * Unless a user has previously entered an expiration date, this will return false.
  91. * \return
  92. */
  93. bool ACurrencyEntry::isValid() const
  94. {
  95. return QDate::fromString(
  96. tableData.value(OPL::Db::CURRENCIES_EXPIRYDATE).toString(), Qt::ISODate
  97. ).isValid();
  98. }