msgitemmodel.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #include "msgitemmodel.h"
  2. MsgItemModel::MsgItemModel( const QString _msgId,
  3. const QString &_msgResource,
  4. const QString &_msgDateTime,
  5. const QString &_msgText,
  6. const bool &_msgDlr,
  7. const bool &_msgMy,
  8. const int &_msgType,
  9. QObject *parent ) :
  10. ListItem(parent),
  11. m_id(_msgId),
  12. m_resource(_msgResource),
  13. m_datetime(_msgDateTime),
  14. m_text(_msgText),
  15. m_dlr(_msgDlr),
  16. m_myMsg(_msgMy),
  17. m_type(_msgType)
  18. {
  19. }
  20. void MsgItemModel::setMsgId(QString &_id)
  21. {
  22. if(m_id != _id) {
  23. m_id = _id;
  24. emit dataChanged();
  25. }
  26. }
  27. void MsgItemModel::setResource(QString &_resource)
  28. {
  29. if(m_resource != _resource) {
  30. m_resource = _resource;
  31. emit dataChanged();
  32. }
  33. }
  34. void MsgItemModel::setMsgDateTime(QString &_msgDateTime)
  35. {
  36. if(m_datetime != _msgDateTime) {
  37. m_datetime = _msgDateTime;
  38. emit dataChanged();
  39. }
  40. }
  41. void MsgItemModel::setMsgText(QString &_msgText)
  42. {
  43. if(m_text != _msgText) {
  44. m_text = _msgText;
  45. emit dataChanged();
  46. }
  47. }
  48. void MsgItemModel::setMsgDlr(bool _msgDlr)
  49. {
  50. if(m_dlr != _msgDlr) {
  51. m_dlr = _msgDlr;
  52. emit dataChanged();
  53. }
  54. }
  55. void MsgItemModel::setMsgMy(bool _msgMy)
  56. {
  57. if(m_myMsg != _msgMy) {
  58. m_myMsg = _msgMy;
  59. emit dataChanged();
  60. }
  61. }
  62. void MsgItemModel::setMsgType(int _msgType)
  63. {
  64. if(m_type != _msgType) {
  65. m_type = _msgType;
  66. emit dataChanged();
  67. }
  68. }
  69. QHash<int, QByteArray> MsgItemModel::roleNames() const
  70. {
  71. QHash<int, QByteArray> names;
  72. names[ r_msgId ] = "msgId";
  73. names[ r_msgResource ] = "msgResource";
  74. names[ r_msgDateTime ] = "msgDateTime";
  75. names[ r_msgText ] = "msgText";
  76. names[ r_msgDlr ] = "msgDlr";
  77. names[ r_msgMy ] = "msgMy";
  78. names[ r_msgType ] = "msgType";
  79. return names;
  80. }
  81. QVariant MsgItemModel::data(int role) const
  82. {
  83. switch(role) {
  84. case r_msgId:
  85. return msgId();
  86. case r_msgResource:
  87. return msgResource();
  88. case r_msgDateTime:
  89. return msgDateTime();
  90. case r_msgText:
  91. return msgText();
  92. case r_msgDlr:
  93. return msgDlr();
  94. case r_msgMy:
  95. return msgMy();
  96. case r_msgType:
  97. return msgType();
  98. default:
  99. return QVariant();
  100. }
  101. }