| 33 | } |
| 34 | |
| 35 | void ModelCellModel::setModelIndex(const QModelIndex &idx) |
| 36 | { |
| 37 | const auto newRoles = rolesForModel(idx.model()); |
| 38 | if (newRoles != m_roles) { |
| 39 | if (!m_roles.isEmpty()) { |
| 40 | beginRemoveRows(QModelIndex(), 0, m_roles.size() - 1); |
| 41 | m_roles.clear(); |
| 42 | endRemoveRows(); |
| 43 | } |
| 44 | m_index = idx; |
| 45 | if (!newRoles.isEmpty()) { |
| 46 | beginInsertRows(QModelIndex(), 0, newRoles.size() - 1); |
| 47 | m_roles = newRoles; |
| 48 | endInsertRows(); |
| 49 | } |
| 50 | } else { |
| 51 | m_index = idx; |
| 52 | if (!m_roles.isEmpty()) { |
| 53 | emit dataChanged(index(0, 1), index(rowCount() - 1, 1)); |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | QVector<ModelCellModel::RoleInfo> ModelCellModel::rolesForModel(const QAbstractItemModel *model) |
| 59 | { |