MCPcopy Create free account
hub / github.com/MITK/MITK / match

Method match

Modules/XNAT/src/QmitkXnatTreeModel.cpp:38–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36}
37
38QModelIndexList QmitkXnatTreeModel::match(
39 const QModelIndex &start, int role, const QVariant &value, int hits, Qt::MatchFlags flags) const
40{
41 QModelIndexList result;
42 uint matchType = flags & Qt::MatchTypeMask;
43 Qt::CaseSensitivity cs = flags.testFlag(Qt::MatchCaseSensitive)
44 ? Qt::CaseSensitive
45 : Qt::CaseInsensitive;
46 bool recurse = flags & Qt::MatchRecursive;
47 bool wrap = flags & Qt::MatchWrap;
48 bool allHits = (hits == -1);
49 QString text; // only convert to a string if it is needed
50 QModelIndex p = parent(start);
51 int from = start.row();
52 int to = rowCount(p);
53
54 // iterates twice if wrapping
55 for (int i = 0; (wrap && i < 2) || (!wrap && i < 1); ++i)
56 {
57 for (int r = from; (r < to) && (allHits || result.count() < hits); ++r)
58 {
59 QModelIndex idx = index(r, start.column(), p);
60 if (!idx.isValid())
61 continue;
62 QVariant v = data(idx, role);
63 // QVariant based matching
64 if (matchType == Qt::MatchExactly)
65 {
66 if (value != v)
67 result.append(idx);
68 }
69 else
70 { // QString based matching
71 if (text.isEmpty()) // lazy conversion
72 text = value.toString();
73 QString t = v.toString();
74 switch (matchType)
75 {
76 case Qt::MatchRegularExpression:
77 {
78 QRegularExpression::PatternOptions options;
79 options.setFlag(QRegularExpression::CaseInsensitiveOption, !flags.testFlag(Qt::MatchCaseSensitive));
80 QRegularExpression regExp(QString("^%1$").arg(text), options);
81 if (!regExp.match(t).hasMatch())
82 result.append(idx);
83 break;
84 }
85 case Qt::MatchWildcard:
86 {
87 auto regExp = QRegularExpression::fromWildcard(text, cs);
88 if (!regExp.match(t).hasMatch())
89 result.append(idx);
90 break;
91 }
92 case Qt::MatchStartsWith:
93 if (!t.startsWith(text, cs))
94 result.append(idx);
95 break;

Callers 15

version_tupleFunction · 0.80
migrateFunction · 0.80
SetCurrentSelectionMethod · 0.80
FindPropertyMethod · 0.80
PrewalkValidateFunction · 0.80
QmitkMxNMultiWidgetMethod · 0.80
ApplyLayoutMethod · 0.80
ParseColorFunction · 0.80
UpdateSelectionModelMethod · 0.80
OnSearchLabelMethod · 0.80
IsDirectReferenceFunction · 0.80

Calls 5

countMethod · 0.80
containsMethod · 0.80
QStringClass · 0.50
rowMethod · 0.45
toStringMethod · 0.45

Tested by 3

UpdateSelectionModelMethod · 0.64
OnSearchLabelMethod · 0.64
FindPartMethod · 0.64