Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/util/qquickshortcut.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | static bool qQuickShortcutContextMatcher(QObject *obj, Qt::ShortcutContext context) | - | ||||||||||||
3 | { | - | ||||||||||||
4 | switch (context) { | - | ||||||||||||
5 | case executed 16 times by 1 test: Qt::ApplicationShortcut:case Qt::ApplicationShortcut: Executed by:
executed 16 times by 1 test: case Qt::ApplicationShortcut: Executed by:
| 16 | ||||||||||||
6 | return executed 16 times by 1 test: true;return true; Executed by:
executed 16 times by 1 test: return true; Executed by:
| 16 | ||||||||||||
7 | case executed 140 times by 2 tests: Qt::WindowShortcut:case Qt::WindowShortcut: Executed by:
executed 140 times by 2 tests: case Qt::WindowShortcut: Executed by:
| 140 | ||||||||||||
8 | while (obj
| 0-280 | ||||||||||||
9 | obj = obj->parent(); | - | ||||||||||||
10 | if (QQuickItem *item = qobject_cast<QQuickItem *>(obj)
| 0-140 | ||||||||||||
11 | obj = item->window(); executed 140 times by 2 tests: obj = item->window(); Executed by:
| 140 | ||||||||||||
12 | } executed 140 times by 2 tests: end of block Executed by:
| 140 | ||||||||||||
13 | if (QWindow *renderWindow = QQuickRenderControl::renderWindowFor(qobject_cast<QQuickWindow *>(obj))
| 0-140 | ||||||||||||
14 | obj = renderWindow; never executed: obj = renderWindow; | 0 | ||||||||||||
15 | return executed 140 times by 2 tests: obj && obj == QGuiApplication::focusWindow();return obj && obj == QGuiApplication::focusWindow(); Executed by:
executed 140 times by 2 tests: return obj && obj == QGuiApplication::focusWindow(); Executed by:
| 140 | ||||||||||||
16 | default never executed: :default: never executed: default: | 0 | ||||||||||||
17 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
18 | } | - | ||||||||||||
19 | } | - | ||||||||||||
20 | - | |||||||||||||
21 | typedef bool (*ContextMatcher)(QObject *, Qt::ShortcutContext); | - | ||||||||||||
22 | - | |||||||||||||
23 | namespace { 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
executed 4 times by 2 tests: }guard.store(QtGlobalStatic::Destroyed); Executed by:
executed 4 times by 2 tests: }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type (qQuickShortcutContextMatcher))) : value (qQuickShortcutContextMatcher) { guard.store(QtGlobalStatic::Initialized); } } holder; returnend of block Executed by:
executed 1218 times by 2 tests: &holder.value;return &holder.value; Executed by:
executed 1218 times by 2 tests: } } } static QGlobalStatic<ContextMatcher, Q_QGS_ctxMatcher::innerFunction, Q_QGS_ctxMatcher::guard> ctxMatcher;return &holder.value; Executed by:
| 0-1218 | ||||||||||||
24 | - | |||||||||||||
25 | __attribute__((visibility("default"))) ContextMatcher qt_quick_shortcut_context_matcher() | - | ||||||||||||
26 | { | - | ||||||||||||
27 | return executed 8 times by 1 test: *ctxMatcher();return *ctxMatcher(); Executed by:
executed 8 times by 1 test: return *ctxMatcher(); Executed by:
| 8 | ||||||||||||
28 | } | - | ||||||||||||
29 | - | |||||||||||||
30 | __attribute__((visibility("default"))) void qt_quick_set_shortcut_context_matcher(ContextMatcher matcher) | - | ||||||||||||
31 | { | - | ||||||||||||
32 | if (!ctxMatcher.isDestroyed()
| 0-8 | ||||||||||||
33 | * executed 8 times by 1 test: ctxMatcher() = matcher;*ctxMatcher() = matcher; Executed by:
executed 8 times by 1 test: *ctxMatcher() = matcher; Executed by:
| 8 | ||||||||||||
34 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||
35 | - | |||||||||||||
36 | - | |||||||||||||
37 | - | |||||||||||||
38 | static QKeySequence valueToKeySequence(const QVariant &value) | - | ||||||||||||
39 | { | - | ||||||||||||
40 | if (value.type() == QVariant::Int
| 0-1202 | ||||||||||||
41 | return never executed: QKeySequence(static_cast<QKeySequence::StandardKey>(value.toInt()));return 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: QKeySequence::fromString(value.toString());return QKeySequence::fromString(value.toString()); Executed by:
executed 1202 times by 2 tests: return QKeySequence::fromString(value.toString()); Executed by:
| 1202 | ||||||||||||
43 | } | - | ||||||||||||
44 | - | |||||||||||||
45 | QQuickShortcut::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:
| 1196 | ||||||||||||
49 | - | |||||||||||||
50 | QQuickShortcut::~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:
| 12 | ||||||||||||
55 | } executed 1196 times by 2 tests: end of block Executed by:
| 1196 | ||||||||||||
56 | QVariant QQuickShortcut::sequence() const | - | ||||||||||||
57 | { | - | ||||||||||||
58 | return executed 68 times by 1 test: m_shortcut.userValue;return m_shortcut.userValue; Executed by:
executed 68 times by 1 test: return m_shortcut.userValue; Executed by:
| 68 | ||||||||||||
59 | } | - | ||||||||||||
60 | - | |||||||||||||
61 | void QQuickShortcut::setSequence(const QVariant &value) | - | ||||||||||||
62 | { | - | ||||||||||||
63 | if (value == m_shortcut.userValue
| 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:
| 1190 | ||||||||||||
74 | QVariantList 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: values;return values; never executed: return values; | 0 | ||||||||||||
80 | } | - | ||||||||||||
81 | - | |||||||||||||
82 | void 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()
| 6-12 | ||||||||||||
89 | QVariant value = values.at(i); | - | ||||||||||||
90 | Shortcut& shortcut = m_shortcuts[i]; | - | ||||||||||||
91 | if (value == shortcut.userValue
| 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:
| 12 | ||||||||||||
103 | - | |||||||||||||
104 | if (changed
| 0-6 | ||||||||||||
105 | sequencesChanged(); executed 6 times by 1 test: sequencesChanged(); Executed by:
| 6 | ||||||||||||
106 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||
107 | QString QQuickShortcut::nativeText() const | - | ||||||||||||
108 | { | - | ||||||||||||
109 | return never executed: m_shortcut.keySequence.toString(QKeySequence::NativeText);return m_shortcut.keySequence.toString(QKeySequence::NativeText); never executed: return m_shortcut.keySequence.toString(QKeySequence::NativeText); | 0 | ||||||||||||
110 | } | - | ||||||||||||
111 | QString QQuickShortcut::portableText() const | - | ||||||||||||
112 | { | - | ||||||||||||
113 | return never executed: m_shortcut.keySequence.toString(QKeySequence::PortableText);return m_shortcut.keySequence.toString(QKeySequence::PortableText); never executed: return m_shortcut.keySequence.toString(QKeySequence::PortableText); | 0 | ||||||||||||
114 | } | - | ||||||||||||
115 | bool QQuickShortcut::isEnabled() const | - | ||||||||||||
116 | { | - | ||||||||||||
117 | return never executed: m_enabled;return m_enabled; never executed: return m_enabled; | 0 | ||||||||||||
118 | } | - | ||||||||||||
119 | - | |||||||||||||
120 | void QQuickShortcut::setEnabled(bool enabled) | - | ||||||||||||
121 | { | - | ||||||||||||
122 | if (enabled == m_enabled
| 450-744 | ||||||||||||
123 | return; executed 744 times by 1 test: return; Executed by:
| 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:
| 450 | ||||||||||||
132 | bool QQuickShortcut::autoRepeat() const | - | ||||||||||||
133 | { | - | ||||||||||||
134 | return never executed: m_autorepeat;return m_autorepeat; never executed: return m_autorepeat; | 0 | ||||||||||||
135 | } | - | ||||||||||||
136 | - | |||||||||||||
137 | void QQuickShortcut::setAutoRepeat(bool repeat) | - | ||||||||||||
138 | { | - | ||||||||||||
139 | if (repeat == m_autorepeat
| 0-1188 | ||||||||||||
140 | return; executed 1188 times by 1 test: return; Executed by:
| 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 | ||||||||||||
149 | Qt::ShortcutContext QQuickShortcut::context() const | - | ||||||||||||
150 | { | - | ||||||||||||
151 | return never executed: m_context;return m_context; never executed: return m_context; | 0 | ||||||||||||
152 | } | - | ||||||||||||
153 | - | |||||||||||||
154 | void QQuickShortcut::setContext(Qt::ShortcutContext context) | - | ||||||||||||
155 | { | - | ||||||||||||
156 | if (context == m_context
| 196-992 | ||||||||||||
157 | return; executed 992 times by 1 test: return; Executed by:
| 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:
| 196 | ||||||||||||
164 | - | |||||||||||||
165 | void QQuickShortcut::classBegin() | - | ||||||||||||
166 | { | - | ||||||||||||
167 | } | - | ||||||||||||
168 | - | |||||||||||||
169 | void 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:
| 1196 | ||||||||||||
176 | - | |||||||||||||
177 | bool QQuickShortcut::event(QEvent *event) | - | ||||||||||||
178 | { | - | ||||||||||||
179 | if (m_enabled
| 0-70 | ||||||||||||
180 | QShortcutEvent *se = static_cast<QShortcutEvent *>(event); | - | ||||||||||||
181 | bool match = m_shortcut.matches(se); | - | ||||||||||||
182 | int i = 0; | - | ||||||||||||
183 | while (!match
| 0-70 | ||||||||||||
184 | match |= m_shortcuts.at(i++).matches(se); never executed: match |= m_shortcuts.at(i++).matches(se); | 0 | ||||||||||||
185 | if (match
| 0-70 | ||||||||||||
186 | if (se->isAmbiguous()
| 18-52 | ||||||||||||
187 | activatedAmbiguously(); executed 18 times by 1 test: activatedAmbiguously(); Executed by:
| 18 | ||||||||||||
188 | else | - | ||||||||||||
189 | activated(); executed 52 times by 2 tests: activated(); Executed by:
| 52 | ||||||||||||
190 | return executed 70 times by 2 tests: true;return true; Executed by:
executed 70 times by 2 tests: return true; Executed by:
| 70 | ||||||||||||
191 | } | - | ||||||||||||
192 | } never executed: end of block | 0 | ||||||||||||
193 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
194 | } | - | ||||||||||||
195 | - | |||||||||||||
196 | bool QQuickShortcut::Shortcut::matches(QShortcutEvent *event) const | - | ||||||||||||
197 | { | - | ||||||||||||
198 | return executed 70 times by 2 tests: event->shortcutId() == id && event->key() == keySequence;return event->shortcutId() == id && event->key() == keySequence; Executed by:
executed 70 times by 2 tests: return event->shortcutId() == id && event->key() == keySequence; Executed by:
| 70 | ||||||||||||
199 | } | - | ||||||||||||
200 | - | |||||||||||||
201 | void QQuickShortcut::setEnabled(QQuickShortcut::Shortcut &shortcut, bool enabled) | - | ||||||||||||
202 | { | - | ||||||||||||
203 | if (shortcut.id
| 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:
| 450 | ||||||||||||
206 | - | |||||||||||||
207 | void QQuickShortcut::setAutoRepeat(QQuickShortcut::Shortcut &shortcut, bool repeat) | - | ||||||||||||
208 | { | - | ||||||||||||
209 | if (shortcut.id
| 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 | - | |||||||||||||
213 | void QQuickShortcut::grabShortcut(Shortcut &shortcut, Qt::ShortcutContext context) | - | ||||||||||||
214 | { | - | ||||||||||||
215 | if (m_completed
| 6-1386 | ||||||||||||
216 | QGuiApplicationPrivate *pApp = QGuiApplicationPrivate::instance(); | - | ||||||||||||
217 | shortcut.id = pApp->shortcutMap.addShortcut(this, shortcut.keySequence, context, *ctxMatcher()); | - | ||||||||||||
218 | if (!m_enabled
| 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:
| 452 | ||||||||||||
220 | if (!m_autorepeat
| 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:
| 1202 | ||||||||||||
223 | } executed 2594 times by 2 tests: end of block Executed by:
| 2594 | ||||||||||||
224 | - | |||||||||||||
225 | void QQuickShortcut::ungrabShortcut(Shortcut &shortcut) | - | ||||||||||||
226 | { | - | ||||||||||||
227 | if (shortcut.id
| 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:
| 1202 | ||||||||||||
231 | } executed 2606 times by 2 tests: end of block Executed by:
| 2606 | ||||||||||||
232 | - | |||||||||||||
233 | - | |||||||||||||
234 | - | |||||||||||||
Switch to Source code | Preprocessed file |