rosteritemmodel.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #include "rosteritemmodel.h"
  2. RosterItemModel::RosterItemModel(const QString &_contactGroup,
  3. const QString &_picStatus,
  4. const QString &_contactName,
  5. const QString &_contactJid,
  6. const QString &_contactResource,
  7. const QString &_contactTextStatus,
  8. const QString &_contactPicAvatar,
  9. const int _unreadMsg,
  10. const int _itemType,
  11. QObject *parent) :
  12. ListItem(parent),
  13. m_group(_contactGroup),
  14. m_pic_status(_picStatus),
  15. m_name(_contactName),
  16. m_jid(_contactJid),
  17. m_resource(_contactResource),
  18. m_text_status(_contactTextStatus),
  19. m_avatar(_contactPicAvatar),
  20. m_unreadmsg(_unreadMsg),
  21. m_item_type(_itemType)
  22. {
  23. }
  24. void RosterItemModel::setGroup( const QString &_contactGroup)
  25. {
  26. if(m_group != _contactGroup) {
  27. m_group = _contactGroup;
  28. emit dataChanged();
  29. }
  30. }
  31. void RosterItemModel::setPicStatus( const QString &_picStatus)
  32. {
  33. if(m_pic_status != _picStatus) {
  34. m_pic_status = _picStatus;
  35. emit dataChanged();
  36. }
  37. }
  38. void RosterItemModel::setContactName( const QString &_contactName)
  39. {
  40. if(m_name != _contactName) {
  41. m_name = _contactName;
  42. emit dataChanged();
  43. }
  44. }
  45. void RosterItemModel::setJid( const QString &_contactJid)
  46. {
  47. if(m_jid != _contactJid) {
  48. m_jid = _contactJid;
  49. emit dataChanged();
  50. }
  51. }
  52. void RosterItemModel::setResource( const QString &_contactResource)
  53. {
  54. if(m_resource != _contactResource) {
  55. m_resource = _contactResource;
  56. emit dataChanged();
  57. }
  58. }
  59. void RosterItemModel::setTextStatus( const QString &_contactTextStatus)
  60. {
  61. if(m_text_status != _contactTextStatus) {
  62. m_text_status = _contactTextStatus;
  63. emit dataChanged();
  64. }
  65. }
  66. void RosterItemModel::setAvatar( const QString &_contactPicAvatar)
  67. {
  68. if(m_avatar != _contactPicAvatar) {
  69. m_avatar = _contactPicAvatar;
  70. emit dataChanged();
  71. }
  72. }
  73. void RosterItemModel::setUnreadMsg( const int _unreadmsg)
  74. {
  75. if(m_unreadmsg != _unreadmsg) {
  76. m_unreadmsg = _unreadmsg;
  77. emit dataChanged();
  78. }
  79. }
  80. void RosterItemModel::setItemType(const int _itemType)
  81. {
  82. if(m_item_type != _itemType) {
  83. m_item_type = _itemType;
  84. emit dataChanged();
  85. }
  86. }
  87. QHash<int, QByteArray> RosterItemModel::roleNames() const
  88. {
  89. QHash<int, QByteArray> names;
  90. names[cntGroup] = "contactGroup";
  91. names[cntPicStatus] = "contactPicStatus";
  92. names[cntName] = "contactName";
  93. names[cntJid] = "contactJid";
  94. names[cntResource] = "contactResource";
  95. names[cntTextStatus] = "contactTextStatus";
  96. names[cntPicAvatar] = "contactPicAvatar";
  97. names[cntUnreadMsg] = "contactUnreadMsg";
  98. names[cntItemType] = "contactItemType";
  99. return names;
  100. }
  101. QVariant RosterItemModel::data(int role) const
  102. {
  103. switch(role) {
  104. case cntGroup:
  105. return group();
  106. case cntPicStatus:
  107. return picStatus();
  108. case cntName:
  109. return contactName();
  110. case cntJid:
  111. return contactJid();
  112. case cntResource:
  113. return contactResource();
  114. case cntTextStatus:
  115. return textStatus();
  116. case cntPicAvatar:
  117. return picAvatar();
  118. case cntUnreadMsg:
  119. return unreadMsg();
  120. case cntItemType:
  121. return itemType();
  122. default:
  123. return QVariant();
  124. }
  125. }
  126. void RosterItemModel::copy( const RosterItemModel *item )
  127. {
  128. m_group = item->group();
  129. m_pic_status = item->picStatus();
  130. m_name = item->contactName();
  131. m_jid = item->contactJid();
  132. m_resource = item->contactResource();
  133. m_text_status = item->textStatus();
  134. m_avatar = item->picAvatar();
  135. m_unreadmsg = item->unreadMsg();
  136. m_item_type = item->itemType();
  137. }