47 ) |
47 ) |
48 return QVariant(); |
48 return QVariant(); |
49 |
49 |
50 return m_data.at(index.row()).at(index.column()); |
50 return m_data.at(index.row()).at(index.column()); |
51 } |
51 } |
|
52 |
|
53 void RoomsListModel::setRoomsList(const QStringList & rooms) |
|
54 { |
|
55 if(m_data.size()) |
|
56 { |
|
57 beginRemoveRows(QModelIndex(), 0, m_data.size() - 1); |
|
58 m_data.clear(); |
|
59 endRemoveRows(); |
|
60 } |
|
61 |
|
62 for(int i = 0; i < rooms.size(); i += 8) |
|
63 { |
|
64 QStringList l; |
|
65 l.reserve(8); |
|
66 for(int t = 0; t < 8; ++t) |
|
67 l.append(rooms[i + t]); |
|
68 |
|
69 m_data.append(roomInfo2RoomRecord(l)); |
|
70 } |
|
71 |
|
72 beginInsertRows(QModelIndex(), 0, m_data.size() - 1); |
|
73 endInsertRows(); |
|
74 } |
|
75 |
|
76 void RoomsListModel::addRoom(const QStringList & info) |
|
77 { |
|
78 beginInsertRows(QModelIndex(), 0, 0); |
|
79 |
|
80 m_data.prepend(roomInfo2RoomRecord(info)); |
|
81 |
|
82 endInsertRows(); |
|
83 } |
|
84 |
|
85 void RoomsListModel::removeRoom(const QString & name) |
|
86 { |
|
87 int i = 0; |
|
88 while(i < m_data.size() && m_data[i].at(0) != name) |
|
89 ++i; |
|
90 if(i >= m_data.size()) |
|
91 return; |
|
92 |
|
93 beginRemoveRows(QModelIndex(), i, i); |
|
94 |
|
95 m_data.removeAt(i); |
|
96 |
|
97 endRemoveRows(); |
|
98 } |
|
99 |
|
100 void RoomsListModel::updateRoom(const QString & name, const QStringList & info) |
|
101 { |
|
102 int i = 0; |
|
103 while(i < m_data.size() && m_data[i].at(0) != name) |
|
104 ++i; |
|
105 if(i >= m_data.size()) |
|
106 return; |
|
107 |
|
108 |
|
109 m_data[i] = roomInfo2RoomRecord(info); |
|
110 |
|
111 emit dataChanged(index(i, 0), index(i, columnCount(QModelIndex()) - 1)); |
|
112 } |
|
113 |
|
114 QStringList RoomsListModel::roomInfo2RoomRecord(const QStringList & info) |
|
115 { |
|
116 QStringList result; |
|
117 |
|
118 result = info; |
|
119 result.removeFirst(); |
|
120 |
|
121 return result; |
|
122 } |