| 175 | } |
| 176 | |
| 177 | bool setFilterState(QModelIndex index, Qt::CheckState state) |
| 178 | { |
| 179 | QFileSystemModel *fsm = qobject_cast<QFileSystemModel *>(sourceModel()); |
| 180 | |
| 181 | if (!fsm) |
| 182 | { |
| 183 | return false; |
| 184 | } |
| 185 | |
| 186 | QModelIndex sourceIndex = mapToSource(index); |
| 187 | auto blockedPath = relPath(fsm->filePath(sourceIndex)); |
| 188 | bool changed = false; |
| 189 | if (state == Qt::Unchecked) |
| 190 | { |
| 191 | // blocking a path |
| 192 | auto &node = blocked.insert(blockedPath); |
| 193 | // get rid of all blocked nodes below |
| 194 | node.clear(); |
| 195 | changed = true; |
| 196 | } |
| 197 | else if (state == Qt::Checked || state == Qt::PartiallyChecked) |
| 198 | { |
| 199 | if (!blocked.remove(blockedPath)) |
| 200 | { |
| 201 | auto cover = blocked.cover(blockedPath); |
| 202 | qDebug() << "Blocked by cover" << cover; |
| 203 | // uncover |
| 204 | blocked.remove(cover); |
| 205 | // block all contents, except for any cover |
| 206 | QModelIndex rootIndex = |
| 207 | fsm->index(FS::PathCombine(m_instance->instanceRoot(), cover)); |
| 208 | QModelIndex doing = rootIndex; |
| 209 | int row = 0; |
| 210 | QStack<QModelIndex> todo; |
| 211 | while (1) |
| 212 | { |
| 213 | auto node = fsm->index(row, 0, doing); |
| 214 | if (!node.isValid()) |
| 215 | { |
| 216 | if (!todo.size()) |
| 217 | { |
| 218 | break; |
| 219 | } |
| 220 | else |
| 221 | { |
| 222 | doing = todo.pop(); |
| 223 | row = 0; |
| 224 | continue; |
| 225 | } |
| 226 | } |
| 227 | auto relpath = relPath(fsm->filePath(node)); |
| 228 | if (blockedPath.startsWith(relpath)) // cover found? |
| 229 | { |
| 230 | // continue processing cover later |
| 231 | todo.push(node); |
| 232 | } |
| 233 | else |
| 234 | { |