OpenCoverage

qquickshortcut.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/util/qquickshortcut.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2static bool qQuickShortcutContextMatcher(QObject *obj, Qt::ShortcutContext context)-
3{-
4 switch (context) {-
5 case
executed 16 times by 1 test: case Qt::ApplicationShortcut:
Executed by:
  • tst_qquickshortcut
Qt::ApplicationShortcut:
executed 16 times by 1 test: case Qt::ApplicationShortcut:
Executed by:
  • tst_qquickshortcut
16
6 return
executed 16 times by 1 test: return true;
Executed by:
  • tst_qquickshortcut
true;
executed 16 times by 1 test: return true;
Executed by:
  • tst_qquickshortcut
16
7 case
executed 140 times by 2 tests: case Qt::WindowShortcut:
Executed by:
  • tst_qquickitem
  • tst_qquickshortcut
Qt::WindowShortcut:
executed 140 times by 2 tests: case Qt::WindowShortcut:
Executed by:
  • tst_qquickitem
  • tst_qquickshortcut
140
8 while (obj
objDescription
TRUEevaluated 280 times by 2 tests
Evaluated by:
  • tst_qquickitem
  • tst_qquickshortcut
FALSEnever evaluated
&& !obj->isWindowType()
!obj->isWindowType()Description
TRUEevaluated 140 times by 2 tests
Evaluated by:
  • tst_qquickitem
  • tst_qquickshortcut
FALSEevaluated 140 times by 2 tests
Evaluated by:
  • tst_qquickitem
  • tst_qquickshortcut
) {
0-280
9 obj = obj->parent();-
10 if (QQuickItem *item = qobject_cast<QQuickItem *>(obj)
QQuickItem *it...ckItem *>(obj)Description
TRUEevaluated 140 times by 2 tests
Evaluated by:
  • tst_qquickitem
  • tst_qquickshortcut
FALSEnever evaluated
)
0-140
11 obj = item->window();
executed 140 times by 2 tests: obj = item->window();
Executed by:
  • tst_qquickitem
  • tst_qquickshortcut
140
12 }
executed 140 times by 2 tests: end of block
Executed by:
  • tst_qquickitem
  • tst_qquickshortcut
140
13 if (QWindow *renderWindow = QQuickRenderControl::renderWindowFor(qobject_cast<QQuickWindow *>(obj))
QWindow *rende...indow *>(obj))Description
TRUEnever evaluated
FALSEevaluated 140 times by 2 tests
Evaluated by:
  • tst_qquickitem
  • tst_qquickshortcut
)
0-140
14 obj = renderWindow;
never executed: obj = renderWindow;
0
15 return
executed 140 times by 2 tests: return obj && obj == QGuiApplication::focusWindow();
Executed by:
  • tst_qquickitem
  • tst_qquickshortcut
obj && obj == QGuiApplication::focusWindow();
executed 140 times by 2 tests: return obj && obj == QGuiApplication::focusWindow();
Executed by:
  • tst_qquickitem
  • tst_qquickshortcut
140
16 default
never executed: default:
:
never executed: default:
0
17 return
never executed: return false;
false;
never executed: return false;
0
18 }-
19}-
20-
21typedef bool (*ContextMatcher)(QObject *, Qt::ShortcutContext);-
22-
23namespace { namespace Q_QGS_ctxMatcher { typedef ContextMatcher Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized
guard.load() =...c::InitializedDescription
TRUEevaluated 4 times by 2 tests
Evaluated by:
  • tst_qquickitem
  • tst_qquickshortcut
FALSEnever evaluated
) guard.store(QtGlobalStatic::Destroyed);
executed 4 times by 2 tests: guard.store(QtGlobalStatic::Destroyed);
Executed by:
  • tst_qquickitem
  • tst_qquickshortcut
}
executed 4 times by 2 tests: end of block
Executed by:
  • tst_qquickitem
  • tst_qquickshortcut
}; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type (qQuickShortcutContextMatcher))) : value (qQuickShortcutContextMatcher) { guard.store(QtGlobalStatic::Initialized); } } holder; return
executed 1218 times by 2 tests: return &holder.value;
Executed by:
  • tst_qquickitem
  • tst_qquickshortcut
&holder.value;
executed 1218 times by 2 tests: return &holder.value;
Executed by:
  • tst_qquickitem
  • tst_qquickshortcut
} } } static QGlobalStatic<ContextMatcher, Q_QGS_ctxMatcher::innerFunction, Q_QGS_ctxMatcher::guard> ctxMatcher;
0-1218
24-
25__attribute__((visibility("default"))) ContextMatcher qt_quick_shortcut_context_matcher()-
26{-
27 return
executed 8 times by 1 test: return *ctxMatcher();
Executed by:
  • tst_qquickshortcut
*ctxMatcher();
executed 8 times by 1 test: return *ctxMatcher();
Executed by:
  • tst_qquickshortcut
8
28}-
29-
30__attribute__((visibility("default"))) void qt_quick_set_shortcut_context_matcher(ContextMatcher matcher)-
31{-
32 if (!ctxMatcher.isDestroyed()
!ctxMatcher.isDestroyed()Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • tst_qquickshortcut
FALSEnever evaluated
)
0-8
33 *
executed 8 times by 1 test: *ctxMatcher() = matcher;
Executed by:
  • tst_qquickshortcut
ctxMatcher() = matcher;
executed 8 times by 1 test: *ctxMatcher() = matcher;
Executed by:
  • tst_qquickshortcut
8
34}
executed 8 times by 1 test: end of block
Executed by:
  • tst_qquickshortcut
8
35-
36-
37-
38static QKeySequence valueToKeySequence(const QVariant &value)-
39{-
40 if (value.type() == QVariant::Int
value.type() == QVariant::IntDescription
TRUEnever evaluated
FALSEevaluated 1202 times by 2 tests
Evaluated by:
  • tst_qquickitem
  • tst_qquickshortcut
)
0-1202
41 return
never executed: return QKeySequence(static_cast<QKeySequence::StandardKey>(value.toInt()));
QKeySequence(static_cast<QKeySequence::StandardKey>(value.toInt()));
never executed: return QKeySequence(static_cast<QKeySequence::StandardKey>(value.toInt()));
0
42 return
executed 1202 times by 2 tests: return QKeySequence::fromString(value.toString());
Executed by:
  • tst_qquickitem
  • tst_qquickshortcut
QKeySequence::fromString(value.toString());
executed 1202 times by 2 tests: return QKeySequence::fromString(value.toString());
Executed by:
  • tst_qquickitem
  • tst_qquickshortcut
1202
43}-
44-
45QQuickShortcut::QQuickShortcut(QObject *parent) : QObject(parent),-
46 m_enabled(true), m_completed(false), m_autorepeat(true), m_context(Qt::WindowShortcut)-
47{-
48}
executed 1196 times by 2 tests: end of block
Executed by:
  • tst_qquickitem
  • tst_qquickshortcut
1196
49-
50QQuickShortcut::~QQuickShortcut()-
51{-
52 ungrabShortcut(m_shortcut);-
53 for (Shortcut &shortcut : m_shortcuts)-
54 ungrabShortcut(shortcut);
executed 12 times by 1 test: ungrabShortcut(shortcut);
Executed by:
  • tst_qquickshortcut
12
55}
executed 1196 times by 2 tests: end of block
Executed by:
  • tst_qquickitem
  • tst_qquickshortcut
1196
56QVariant QQuickShortcut::sequence() const-
57{-
58 return
executed 68 times by 1 test: return m_shortcut.userValue;
Executed by:
  • tst_qquickshortcut
m_shortcut.userValue;
executed 68 times by 1 test: return m_shortcut.userValue;
Executed by:
  • tst_qquickshortcut
68
59}-
60-
61void QQuickShortcut::setSequence(const QVariant &value)-
62{-
63 if (value == m_shortcut.userValue
value == m_shortcut.userValueDescription
TRUEnever evaluated
FALSEevaluated 1190 times by 2 tests
Evaluated by:
  • tst_qquickitem
  • tst_qquickshortcut
)
0-1190
64 return;
never executed: return;
0
65-
66 QKeySequence keySequence = valueToKeySequence(value);-
67-
68 ungrabShortcut(m_shortcut);-
69 m_shortcut.userValue = value;-
70 m_shortcut.keySequence = keySequence;-
71 grabShortcut(m_shortcut, m_context);-
72 sequenceChanged();-
73}
executed 1190 times by 2 tests: end of block
Executed by:
  • tst_qquickitem
  • tst_qquickshortcut
1190
74QVariantList QQuickShortcut::sequences() const-
75{-
76 QVariantList values;-
77 for (const Shortcut &shortcut : m_shortcuts)-
78 values += shortcut.userValue;
never executed: values += shortcut.userValue;
0
79 return
never executed: return values;
values;
never executed: return values;
0
80}-
81-
82void QQuickShortcut::setSequences(const QVariantList &values)-
83{-
84 QVector<Shortcut> remainder = m_shortcuts.mid(values.count());-
85 m_shortcuts.resize(values.count());-
86-
87 bool changed = !remainder.isEmpty();-
88 for (int i = 0; i < values.count()
i < values.count()Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • tst_qquickshortcut
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tst_qquickshortcut
; ++i) {
6-12
89 QVariant value = values.at(i);-
90 Shortcut& shortcut = m_shortcuts[i];-
91 if (value == shortcut.userValue
value == shortcut.userValueDescription
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • tst_qquickshortcut
)
0-12
92 continue;
never executed: continue;
0
93-
94 QKeySequence keySequence = valueToKeySequence(value);-
95-
96 ungrabShortcut(shortcut);-
97 shortcut.userValue = value;-
98 shortcut.keySequence = keySequence;-
99 grabShortcut(shortcut, m_context);-
100-
101 changed = true;-
102 }
executed 12 times by 1 test: end of block
Executed by:
  • tst_qquickshortcut
12
103-
104 if (changed
changedDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • tst_qquickshortcut
FALSEnever evaluated
)
0-6
105 sequencesChanged();
executed 6 times by 1 test: sequencesChanged();
Executed by:
  • tst_qquickshortcut
6
106}
executed 6 times by 1 test: end of block
Executed by:
  • tst_qquickshortcut
6
107QString QQuickShortcut::nativeText() const-
108{-
109 return
never executed: return m_shortcut.keySequence.toString(QKeySequence::NativeText);
m_shortcut.keySequence.toString(QKeySequence::NativeText);
never executed: return m_shortcut.keySequence.toString(QKeySequence::NativeText);
0
110}-
111QString QQuickShortcut::portableText() const-
112{-
113 return
never executed: return m_shortcut.keySequence.toString(QKeySequence::PortableText);
m_shortcut.keySequence.toString(QKeySequence::PortableText);
never executed: return m_shortcut.keySequence.toString(QKeySequence::PortableText);
0
114}-
115bool QQuickShortcut::isEnabled() const-
116{-
117 return
never executed: return m_enabled;
m_enabled;
never executed: return m_enabled;
0
118}-
119-
120void QQuickShortcut::setEnabled(bool enabled)-
121{-
122 if (enabled == m_enabled
enabled == m_enabledDescription
TRUEevaluated 744 times by 1 test
Evaluated by:
  • tst_qquickshortcut
FALSEevaluated 450 times by 1 test
Evaluated by:
  • tst_qquickshortcut
)
450-744
123 return;
executed 744 times by 1 test: return;
Executed by:
  • tst_qquickshortcut
744
124-
125 setEnabled(m_shortcut, enabled);-
126 for (Shortcut &shortcut : m_shortcuts)-
127 setEnabled(shortcut, enabled);
never executed: setEnabled(shortcut, enabled);
0
128-
129 m_enabled = enabled;-
130 enabledChanged();-
131}
executed 450 times by 1 test: end of block
Executed by:
  • tst_qquickshortcut
450
132bool QQuickShortcut::autoRepeat() const-
133{-
134 return
never executed: return m_autorepeat;
m_autorepeat;
never executed: return m_autorepeat;
0
135}-
136-
137void QQuickShortcut::setAutoRepeat(bool repeat)-
138{-
139 if (repeat == m_autorepeat
repeat == m_autorepeatDescription
TRUEevaluated 1188 times by 1 test
Evaluated by:
  • tst_qquickshortcut
FALSEnever evaluated
)
0-1188
140 return;
executed 1188 times by 1 test: return;
Executed by:
  • tst_qquickshortcut
1188
141-
142 setAutoRepeat(m_shortcut, repeat);-
143 for (Shortcut &shortcut : m_shortcuts)-
144 setAutoRepeat(shortcut, repeat);
never executed: setAutoRepeat(shortcut, repeat);
0
145-
146 m_autorepeat = repeat;-
147 autoRepeatChanged();-
148}
never executed: end of block
0
149Qt::ShortcutContext QQuickShortcut::context() const-
150{-
151 return
never executed: return m_context;
m_context;
never executed: return m_context;
0
152}-
153-
154void QQuickShortcut::setContext(Qt::ShortcutContext context)-
155{-
156 if (context == m_context
context == m_contextDescription
TRUEevaluated 992 times by 1 test
Evaluated by:
  • tst_qquickshortcut
FALSEevaluated 196 times by 1 test
Evaluated by:
  • tst_qquickshortcut
)
196-992
157 return;
executed 992 times by 1 test: return;
Executed by:
  • tst_qquickshortcut
992
158-
159 ungrabShortcut(m_shortcut);-
160 m_context = context;-
161 grabShortcut(m_shortcut, context);-
162 contextChanged();-
163}
executed 196 times by 1 test: end of block
Executed by:
  • tst_qquickshortcut
196
164-
165void QQuickShortcut::classBegin()-
166{-
167}-
168-
169void QQuickShortcut::componentComplete()-
170{-
171 m_completed = true;-
172 grabShortcut(m_shortcut, m_context);-
173 for (Shortcut &shortcut : m_shortcuts)-
174 grabShortcut(shortcut, m_context);
never executed: grabShortcut(shortcut, m_context);
0
175}
executed 1196 times by 2 tests: end of block
Executed by:
  • tst_qquickitem
  • tst_qquickshortcut
1196
176-
177bool QQuickShortcut::event(QEvent *event)-
178{-
179 if (m_enabled
m_enabledDescription
TRUEevaluated 70 times by 2 tests
Evaluated by:
  • tst_qquickitem
  • tst_qquickshortcut
FALSEnever evaluated
&& event->type() == QEvent::Shortcut
event->type() ...vent::ShortcutDescription
TRUEevaluated 70 times by 2 tests
Evaluated by:
  • tst_qquickitem
  • tst_qquickshortcut
FALSEnever evaluated
) {
0-70
180 QShortcutEvent *se = static_cast<QShortcutEvent *>(event);-
181 bool match = m_shortcut.matches(se);-
182 int i = 0;-
183 while (!match
!matchDescription
TRUEnever evaluated
FALSEevaluated 70 times by 2 tests
Evaluated by:
  • tst_qquickitem
  • tst_qquickshortcut
&& i < m_shortcuts.count()
i < m_shortcuts.count()Description
TRUEnever evaluated
FALSEnever evaluated
)
0-70
184 match |= m_shortcuts.at(i++).matches(se);
never executed: match |= m_shortcuts.at(i++).matches(se);
0
185 if (match
matchDescription
TRUEevaluated 70 times by 2 tests
Evaluated by:
  • tst_qquickitem
  • tst_qquickshortcut
FALSEnever evaluated
) {
0-70
186 if (se->isAmbiguous()
se->isAmbiguous()Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • tst_qquickshortcut
FALSEevaluated 52 times by 2 tests
Evaluated by:
  • tst_qquickitem
  • tst_qquickshortcut
)
18-52
187 activatedAmbiguously();
executed 18 times by 1 test: activatedAmbiguously();
Executed by:
  • tst_qquickshortcut
18
188 else-
189 activated();
executed 52 times by 2 tests: activated();
Executed by:
  • tst_qquickitem
  • tst_qquickshortcut
52
190 return
executed 70 times by 2 tests: return true;
Executed by:
  • tst_qquickitem
  • tst_qquickshortcut
true;
executed 70 times by 2 tests: return true;
Executed by:
  • tst_qquickitem
  • tst_qquickshortcut
70
191 }-
192 }
never executed: end of block
0
193 return
never executed: return false;
false;
never executed: return false;
0
194}-
195-
196bool QQuickShortcut::Shortcut::matches(QShortcutEvent *event) const-
197{-
198 return
executed 70 times by 2 tests: return event->shortcutId() == id && event->key() == keySequence;
Executed by:
  • tst_qquickitem
  • tst_qquickshortcut
event->shortcutId() == id && event->key() == keySequence;
executed 70 times by 2 tests: return event->shortcutId() == id && event->key() == keySequence;
Executed by:
  • tst_qquickitem
  • tst_qquickshortcut
70
199}-
200-
201void QQuickShortcut::setEnabled(QQuickShortcut::Shortcut &shortcut, bool enabled)-
202{-
203 if (shortcut.id
shortcut.idDescription
TRUEnever evaluated
FALSEevaluated 450 times by 1 test
Evaluated by:
  • tst_qquickshortcut
)
0-450
204 QGuiApplicationPrivate::instance()->shortcutMap.setShortcutEnabled(enabled, shortcut.id, this);
never executed: QGuiApplicationPrivate::instance()->shortcutMap.setShortcutEnabled(enabled, shortcut.id, this);
0
205}
executed 450 times by 1 test: end of block
Executed by:
  • tst_qquickshortcut
450
206-
207void QQuickShortcut::setAutoRepeat(QQuickShortcut::Shortcut &shortcut, bool repeat)-
208{-
209 if (shortcut.id
shortcut.idDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
210 QGuiApplicationPrivate::instance()->shortcutMap.setShortcutAutoRepeat(repeat, shortcut.id, this);
never executed: QGuiApplicationPrivate::instance()->shortcutMap.setShortcutAutoRepeat(repeat, shortcut.id, this);
0
211}
never executed: end of block
0
212-
213void QQuickShortcut::grabShortcut(Shortcut &shortcut, Qt::ShortcutContext context)-
214{-
215 if (m_completed
m_completedDescription
TRUEevaluated 1208 times by 2 tests
Evaluated by:
  • tst_qquickitem
  • tst_qquickshortcut
FALSEevaluated 1386 times by 2 tests
Evaluated by:
  • tst_qquickitem
  • tst_qquickshortcut
&& !shortcut.keySequence.isEmpty()
!shortcut.keyS...ence.isEmpty()Description
TRUEevaluated 1202 times by 2 tests
Evaluated by:
  • tst_qquickitem
  • tst_qquickshortcut
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tst_qquickshortcut
) {
6-1386
216 QGuiApplicationPrivate *pApp = QGuiApplicationPrivate::instance();-
217 shortcut.id = pApp->shortcutMap.addShortcut(this, shortcut.keySequence, context, *ctxMatcher());-
218 if (!m_enabled
!m_enabledDescription
TRUEevaluated 452 times by 1 test
Evaluated by:
  • tst_qquickshortcut
FALSEevaluated 750 times by 2 tests
Evaluated by:
  • tst_qquickitem
  • tst_qquickshortcut
)
452-750
219 pApp->shortcutMap.setShortcutEnabled(false, shortcut.id, this);
executed 452 times by 1 test: pApp->shortcutMap.setShortcutEnabled(false, shortcut.id, this);
Executed by:
  • tst_qquickshortcut
452
220 if (!m_autorepeat
!m_autorepeatDescription
TRUEnever evaluated
FALSEevaluated 1202 times by 2 tests
Evaluated by:
  • tst_qquickitem
  • tst_qquickshortcut
)
0-1202
221 pApp->shortcutMap.setShortcutAutoRepeat(false, shortcut.id, this);
never executed: pApp->shortcutMap.setShortcutAutoRepeat(false, shortcut.id, this);
0
222 }
executed 1202 times by 2 tests: end of block
Executed by:
  • tst_qquickitem
  • tst_qquickshortcut
1202
223}
executed 2594 times by 2 tests: end of block
Executed by:
  • tst_qquickitem
  • tst_qquickshortcut
2594
224-
225void QQuickShortcut::ungrabShortcut(Shortcut &shortcut)-
226{-
227 if (shortcut.id
shortcut.idDescription
TRUEevaluated 1202 times by 2 tests
Evaluated by:
  • tst_qquickitem
  • tst_qquickshortcut
FALSEevaluated 1404 times by 2 tests
Evaluated by:
  • tst_qquickitem
  • tst_qquickshortcut
) {
1202-1404
228 QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(shortcut.id, this);-
229 shortcut.id = 0;-
230 }
executed 1202 times by 2 tests: end of block
Executed by:
  • tst_qquickitem
  • tst_qquickshortcut
1202
231}
executed 2606 times by 2 tests: end of block
Executed by:
  • tst_qquickitem
  • tst_qquickshortcut
2606
232-
233-
234-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.0