MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / setFilterState

Method setFilterState

launcher/ui/dialogs/ExportInstanceDialog.cpp:177–283  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 {

Callers

nothing calls this directly

Calls 11

PathCombineFunction · 0.85
filePathMethod · 0.80
insertMethod · 0.80
coverMethod · 0.80
instanceRootMethod · 0.80
clearMethod · 0.45
removeMethod · 0.45
indexMethod · 0.45
isValidMethod · 0.45
sizeMethod · 0.45
parentMethod · 0.45

Tested by

no test coverage detected