Changeset View
Changeset View
Standalone View
Standalone View
src/CopyInputDialog.cpp
Show First 20 Lines • Show All 132 Lines • ▼ Show 20 Line(s) | 130 | } else { | |||
---|---|---|---|---|---|
133 | } | 133 | } | ||
134 | } | 134 | } | ||
135 | } | 135 | } | ||
136 | 136 | | |||
137 | void CopyInputDialog::setRowChecked(int row, bool checked) | 137 | void CopyInputDialog::setRowChecked(int row, bool checked) | ||
138 | { | 138 | { | ||
139 | QAbstractItemModel *model = _ui->sessionList->model(); | 139 | QAbstractItemModel *model = _ui->sessionList->model(); | ||
140 | QModelIndex index = model->index(row, _model->checkColumn()); | 140 | QModelIndex index = model->index(row, _model->checkColumn()); | ||
141 | if (checked) { | 141 | model->setData(index, static_cast<int>( checked ? Qt::Checked : Qt::Unchecked), Qt::CheckStateRole); | ||
142 | model->setData(index, static_cast<int>(Qt::Checked), Qt::CheckStateRole); | | |||
143 | } else { | | |||
144 | model->setData(index, static_cast<int>(Qt::Unchecked), Qt::CheckStateRole); | | |||
145 | } | | |||
146 | } | 142 | } | ||
147 | 143 | | |||
148 | CheckableSessionModel::CheckableSessionModel(QObject *parent) : | 144 | CheckableSessionModel::CheckableSessionModel(QObject *parent) : | ||
149 | SessionListModel(parent), | 145 | SessionListModel(parent), | ||
150 | _checkedSessions(QSet<Session *>()), | 146 | _checkedSessions(QSet<Session *>()), | ||
151 | _fixedSessions(QSet<Session *>()), | 147 | _fixedSessions(QSet<Session *>()), | ||
152 | _checkColumn(0) | 148 | _checkColumn(0) | ||
153 | { | 149 | { | ||
154 | } | 150 | } | ||
155 | 151 | | |||
156 | void CheckableSessionModel::setCheckColumn(int column) | 152 | void CheckableSessionModel::setCheckColumn(int column) | ||
157 | { | 153 | { | ||
158 | beginResetModel(); | 154 | beginResetModel(); | ||
159 | _checkColumn = column; | 155 | _checkColumn = column; | ||
160 | endResetModel(); | 156 | endResetModel(); | ||
161 | } | 157 | } | ||
162 | 158 | | |||
163 | Qt::ItemFlags CheckableSessionModel::flags(const QModelIndex &index) const | 159 | Qt::ItemFlags CheckableSessionModel::flags(const QModelIndex &index) const | ||
164 | { | 160 | { | ||
165 | auto *session = static_cast<Session *>(index.internalPointer()); | 161 | auto *session = static_cast<Session *>(index.internalPointer()); | ||
166 | 162 | | |||
167 | if (_fixedSessions.contains(session)) { | 163 | if (_fixedSessions.contains(session)) { | ||
168 | return SessionListModel::flags(index) & ~Qt::ItemIsEnabled; | 164 | return SessionListModel::flags(index) & ~Qt::ItemIsEnabled; | ||
169 | } else { | | |||
170 | return SessionListModel::flags(index) | Qt::ItemIsUserCheckable; | | |||
171 | } | 165 | } | ||
166 | return SessionListModel::flags(index) | Qt::ItemIsUserCheckable; | ||||
172 | } | 167 | } | ||
173 | 168 | | |||
174 | QVariant CheckableSessionModel::data(const QModelIndex &index, int role) const | 169 | QVariant CheckableSessionModel::data(const QModelIndex &index, int role) const | ||
175 | { | 170 | { | ||
176 | if (role == Qt::CheckStateRole && index.column() == _checkColumn) { | 171 | if (role == Qt::CheckStateRole && index.column() == _checkColumn) { | ||
177 | auto *session = static_cast<Session *>(index.internalPointer()); | 172 | auto *session = static_cast<Session *>(index.internalPointer()); | ||
178 | 173 | return QVariant::fromValue(static_cast<int>( | |||
179 | if (_checkedSessions.contains(session)) { | 174 | _checkedSessions.contains(session) ? Qt::Checked : Qt::Unchecked) | ||
180 | return QVariant::fromValue(static_cast<int>(Qt::Checked)); | 175 | ); | ||
181 | } else { | | |||
182 | return QVariant::fromValue(static_cast<int>(Qt::Unchecked)); | | |||
183 | } | 176 | } | ||
184 | } else { | | |||
185 | return SessionListModel::data(index, role); | 177 | return SessionListModel::data(index, role); | ||
186 | } | 178 | } | ||
187 | } | | |||
188 | 179 | | |||
189 | bool CheckableSessionModel::setData(const QModelIndex &index, const QVariant &value, int role) | 180 | bool CheckableSessionModel::setData(const QModelIndex &index, const QVariant &value, int role) | ||
190 | { | 181 | { | ||
191 | if (role == Qt::CheckStateRole && index.column() == _checkColumn) { | 182 | if (role == Qt::CheckStateRole && index.column() == _checkColumn) { | ||
192 | auto *session = static_cast<Session *>(index.internalPointer()); | 183 | auto *session = static_cast<Session *>(index.internalPointer()); | ||
193 | 184 | | |||
194 | if (_fixedSessions.contains(session)) { | 185 | if (_fixedSessions.contains(session)) { | ||
195 | return false; | 186 | return false; | ||
196 | } | 187 | } | ||
197 | 188 | | |||
198 | if (value.toInt() == Qt::Checked) { | 189 | if (value.toInt() == Qt::Checked) { | ||
199 | _checkedSessions.insert(session); | 190 | _checkedSessions.insert(session); | ||
200 | } else { | 191 | } else { | ||
201 | _checkedSessions.remove(session); | 192 | _checkedSessions.remove(session); | ||
202 | } | 193 | } | ||
203 | 194 | | |||
204 | emit dataChanged(index, index); | 195 | emit dataChanged(index, index); | ||
205 | return true; | 196 | return true; | ||
206 | } else { | | |||
207 | return SessionListModel::setData(index, value, role); | | |||
208 | } | 197 | } | ||
198 | return SessionListModel::setData(index, value, role); | ||||
209 | } | 199 | } | ||
210 | 200 | | |||
211 | void CheckableSessionModel::setCheckedSessions(const QSet<Session *> &sessions) | 201 | void CheckableSessionModel::setCheckedSessions(const QSet<Session *> &sessions) | ||
212 | { | 202 | { | ||
213 | beginResetModel(); | 203 | beginResetModel(); | ||
214 | _checkedSessions = sessions; | 204 | _checkedSessions = sessions; | ||
215 | endResetModel(); | 205 | endResetModel(); | ||
216 | } | 206 | } | ||
Show All 24 Lines |