chatsitemmodel.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #include "chatsitemmodel.h"
  2. ChatsItemModel::ChatsItemModel( const QString &_picStatus,
  3. const QString &_contactName,
  4. const QString &_contactJid,
  5. const QString &_contactResource,
  6. const QString &_contactTextStatus,
  7. const QString &_contactPicAvatar,
  8. QObject *parent) :
  9. ListItem(parent),
  10. m_pic_status(_picStatus),
  11. m_name(_contactName),
  12. m_jid(_contactJid),
  13. m_resource(_contactResource),
  14. m_text_status(_contactTextStatus),
  15. m_avatar(_contactPicAvatar)
  16. {
  17. }
  18. void ChatsItemModel::setPicStatus(QString &_picStatus)
  19. {
  20. if(m_pic_status != _picStatus) {
  21. m_pic_status = _picStatus;
  22. emit dataChanged();
  23. }
  24. }
  25. void ChatsItemModel::setContactName(QString &_contactName)
  26. {
  27. if(m_name != _contactName) {
  28. m_name = _contactName;
  29. emit dataChanged();
  30. }
  31. }
  32. void ChatsItemModel::setJid(QString &_contactJid)
  33. {
  34. if(m_jid != _contactJid) {
  35. m_jid = _contactJid;
  36. emit dataChanged();
  37. }
  38. }
  39. void ChatsItemModel::setResource(QString &_contactResource)
  40. {
  41. if(m_resource != _contactResource) {
  42. m_resource = _contactResource;
  43. emit dataChanged();
  44. }
  45. }
  46. void ChatsItemModel::setTextStatus(QString &_contactTextStatus)
  47. {
  48. if(m_text_status != _contactTextStatus) {
  49. m_text_status = _contactTextStatus;
  50. emit dataChanged();
  51. }
  52. }
  53. void ChatsItemModel::setAvatar(QString &_contactPicAvatar)
  54. {
  55. if(m_avatar != _contactPicAvatar) {
  56. m_avatar = _contactPicAvatar;
  57. emit dataChanged();
  58. }
  59. }
  60. QHash<int, QByteArray> ChatsItemModel::roleNames() const
  61. {
  62. QHash<int, QByteArray> names;
  63. names[cntPicStatus] = "contactPicStatus";
  64. names[cntName] = "contactName";
  65. names[cntJid] = "contactJid";
  66. names[cntResource] = "contactResource";
  67. names[cntTextStatus] = "contactTextStatus";
  68. names[cntPicAvatar] = "contactPicAvatar";
  69. return names;
  70. }
  71. QVariant ChatsItemModel::data(int role) const
  72. {
  73. switch(role) {
  74. case cntPicStatus:
  75. return picStatus();
  76. case cntName:
  77. return contactName();
  78. case cntJid:
  79. return contactJid();
  80. case cntResource:
  81. return contactResource();
  82. case cntTextStatus:
  83. return textStatus();
  84. case cntPicAvatar:
  85. return picAvatar();
  86. default:
  87. return QVariant();
  88. }
  89. }