MCPcopy Create free account
hub / github.com/KDAB/GammaRay / match

Method match

common/modelutils.cpp:20–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18using namespace GammaRay;
19
20QModelIndexList ModelUtils::match(const QModelIndex &start, int role, MatchAcceptor accept,
21 int hits, Qt::MatchFlags flags)
22{
23 if (!start.isValid() || role < 0)
24 return QModelIndexList();
25
26 const QAbstractItemModel *model = start.model();
27 const QModelIndex parentIndex = model->parent(start);
28 bool recurse = flags & Qt::MatchRecursive;
29 bool wrap = flags & Qt::MatchWrap;
30 bool allHits = (hits == -1);
31 int from = start.row();
32 int to = model->rowCount(parentIndex);
33
34 QModelIndexList result;
35
36 // iterates twice if wrapping
37 for (int i = 0; (wrap && i < 2) || (!wrap && i < 1); ++i) {
38 for (int r = from; (r < to) && (allHits || result.size() < hits); ++r) {
39 QModelIndex idx = model->index(r, start.column(), parentIndex);
40 if (!idx.isValid())
41 continue;
42
43 const QVariant v = model->data(idx, role);
44 if (accept(v))
45 result << idx;
46
47 // search the hierarchy
48 if (recurse && model->hasChildren(idx)) {
49 result += match(model->index(0, idx.column(), idx), role,
50 accept, (allHits ? -1 : hits - result.size()), flags);
51 }
52 }
53
54 // prepare for the next iteration
55 from = 0;
56 to = start.row();
57 }
58
59 return result;
60}

Callers 15

fromStringMethod · 0.45
selfTestMethod · 0.45
validateHostAddressMethod · 0.45
handleIPAddressMethod · 0.45
handlePortStringMethod · 0.45
searchMatchesOneFunction · 0.45
searchMatchesAllFunction · 0.45
selectToolMethod · 0.45
setCurrentIndexMethod · 0.45
sendSelectionMethod · 0.45

Calls 10

rowMethod · 0.80
columnMethod · 0.80
isValidMethod · 0.45
modelMethod · 0.45
parentMethod · 0.45
rowCountMethod · 0.45
sizeMethod · 0.45
indexMethod · 0.45
dataMethod · 0.45
hasChildrenMethod · 0.45

Tested by 13

searchMatchesOneFunction · 0.36
searchMatchesAllFunction · 0.36
objectSelectedMethod · 0.36
selectItemMethod · 0.36
selectSGNodeMethod · 0.36
objectSelectedMethod · 0.36
objectSelectedMethod · 0.36
widgetSelectedMethod · 0.36
sceneItemSelectedMethod · 0.36
objectSelectedMethod · 0.36
objectSelectedMethod · 0.36
selectEntityMethod · 0.36