| 114 | } |
| 115 | |
| 116 | void SelectionModelModel::setModel(QAbstractItemModel *model) |
| 117 | { |
| 118 | if (model == m_model) |
| 119 | return; |
| 120 | |
| 121 | if (!m_currentSelectionModels.isEmpty()) { |
| 122 | beginRemoveRows(QModelIndex(), 0, m_currentSelectionModels.size() - 1); |
| 123 | m_currentSelectionModels.clear(); |
| 124 | endRemoveRows(); |
| 125 | } |
| 126 | |
| 127 | m_model = model; |
| 128 | QVector<QItemSelectionModel *> models; |
| 129 | std::copy_if(m_selectionModels.constBegin(), m_selectionModels.constEnd(), std::back_inserter(models), [this](QItemSelectionModel *model) { |
| 130 | return model->model() == m_model; |
| 131 | }); |
| 132 | |
| 133 | if (models.isEmpty()) |
| 134 | return; |
| 135 | |
| 136 | beginInsertRows(QModelIndex(), 0, models.size() - 1); |
| 137 | m_currentSelectionModels = std::move(models); |
| 138 | endInsertRows(); |
| 139 | } |
| 140 | |
| 141 | int SelectionModelModel::columnCount(const QModelIndex &parent) const |
| 142 | { |