Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. bool UserModel::insertUser( QString channelId, QSharedPointer<RocketChatUser> user )
  2. {
  3. auto values = userMap.values( channelId );
  4. int index = values.count();
  5. auto qIndex = QModelIndex();
  6. if ( channelId == current ) {
  7. beginInsertRows( qIndex, index, index );
  8. }
  9.  
  10. userMap.insert( channelId, user );
  11.  
  12. if ( channelId == current ) {
  13. endInsertRows();
  14. }
  15. }
  16.  
  17.  
  18. class UserModel: public QAbstractListModel
  19. {
  20. Q_OBJECT
  21. Q_PROPERTY(QString currentChannel READ getCurrent WRITE setCurrent NOTIFY currentChannelChanged)
  22. enum UserRoles {
  23. UserName = Qt::UserRole + 1,
  24. UserId
  25. };
  26. public:
  27. UserModel( QObject *parent = 0 );
  28. int rowCount( const QModelIndex &parent = QModelIndex() ) const;
  29. QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
  30. bool insertUser(QString,QSharedPointer<RocketChatUser>);
  31. QString getCurrent() const;
  32. void setCurrent(const QString &value);
  33. void onCurrentChannelChanged(const QString &newText);
  34.  
  35. protected:
  36. QHash<int, QByteArray> roleNames() const;
  37. QSet<QString> duplicateCheck;
  38. QMultiMap<QString, QSharedPointer<RocketChatUser>> userMap;
  39. QString current;
  40. signals:
  41. void currentChannelChanged(const QString &newText);
  42. };
  43.  
  44. UserModel userModel;
  45. context->setContextProperty("userModel",&userModel);
  46.  
  47. Drawer {
  48. z: 9
  49. width: Math.min(window.width, window.height) / 3 * 2
  50. height: window.height
  51. edge: Qt.LeftEdge
  52. ListView {
  53.  
  54. anchors.fill: parent
  55. spacing: 1
  56. header: ToolBar {
  57. Text {
  58. text: qsTr("Users in channel")
  59. anchors.centerIn: parent
  60. }
  61. width: parent.width - 1
  62. }
  63. id: userListView
  64. model: userModel
  65. delegate: RowLayout {
  66. width: parent.width
  67. Button {
  68. anchors.fill: parent
  69. text: model.username
  70. }
  71. /*BusyIndicator{
  72. id: loadingUserIndicator
  73. anchors.centerIn: parent
  74. }*/
  75. }
  76. Component.onCompleted: {
  77. userModel.currentChannel = channelView.currentChannel
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement