Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
2 | ** | - |
3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
4 | ** Contact: http://www.qt-project.org/legal | - |
5 | ** | - |
6 | ** This file is part of the QtGui module of the Qt Toolkit. | - |
7 | ** | - |
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
9 | ** Commercial License Usage | - |
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - |
11 | ** accordance with the commercial license agreement provided with the | - |
12 | ** Software or, alternatively, in accordance with the terms contained in | - |
13 | ** a written agreement between you and Digia. For licensing terms and | - |
14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
15 | ** use the contact form at http://qt.digia.com/contact-us. | - |
16 | ** | - |
17 | ** GNU Lesser General Public License Usage | - |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - |
19 | ** General Public License version 2.1 as published by the Free Software | - |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
21 | ** packaging of this file. Please review the following information to | - |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
24 | ** | - |
25 | ** In addition, as a special exception, Digia gives you certain additional | - |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
28 | ** | - |
29 | ** GNU General Public License Usage | - |
30 | ** Alternatively, this file may be used under the terms of the GNU | - |
31 | ** General Public License version 3.0 as published by the Free Software | - |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
33 | ** packaging of this file. Please review the following information to | - |
34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
36 | ** | - |
37 | ** | - |
38 | ** $QT_END_LICENSE$ | - |
39 | ** | - |
40 | ****************************************************************************/ | - |
41 | | - |
42 | #include "qshortcutmap_p.h" | - |
43 | #include "private/qobject_p.h" | - |
44 | #include "qkeysequence.h" | - |
45 | #include "qdebug.h" | - |
46 | #include "qevent.h" | - |
47 | #include "qvector.h" | - |
48 | #include "qcoreapplication.h" | - |
49 | #include <private/qkeymapper_p.h> | - |
50 | | - |
51 | #include <algorithm> | - |
52 | | - |
53 | #ifndef QT_NO_SHORTCUT | - |
54 | | - |
55 | QT_BEGIN_NAMESPACE | - |
56 | | - |
57 | // To enable verbose output uncomment below | - |
58 | //#define DEBUG_QSHORTCUTMAP | - |
59 | | - |
60 | /* \internal | - |
61 | Entry data for QShortcutMap | - |
62 | Contains: | - |
63 | Keysequence for entry | - |
64 | Pointer to parent owning the sequence | - |
65 | */ | - |
66 | | - |
67 | struct QShortcutEntry | - |
68 | { | - |
69 | QShortcutEntry() | - |
70 | : keyseq(0), context(Qt::WindowShortcut), enabled(false), autorepeat(1), id(0), owner(0), contextMatcher(0) | - |
71 | {} | 0 |
72 | | - |
73 | QShortcutEntry(const QKeySequence &k) | - |
74 | : keyseq(k), context(Qt::WindowShortcut), enabled(false), autorepeat(1), id(0), owner(0), contextMatcher(0) | - |
75 | {} executed: } Execution Count:250 | 250 |
76 | | - |
77 | QShortcutEntry(QObject *o, const QKeySequence &k, Qt::ShortcutContext c, int i, bool a, QShortcutMap::ContextMatcher m) | - |
78 | : keyseq(k), context(c), enabled(true), autorepeat(a), id(i), owner(o), contextMatcher(m) | - |
79 | {} executed: } Execution Count:2624 | 2624 |
80 | | - |
81 | bool correctContext() const { return contextMatcher(owner, context); } executed: return contextMatcher(owner, context); Execution Count:219 | 219 |
82 | | - |
83 | bool operator<(const QShortcutEntry &f) const | - |
84 | { return keyseq < f.keyseq; } executed: return keyseq < f.keyseq; Execution Count:5530 | 5530 |
85 | | - |
86 | QKeySequence keyseq; | - |
87 | Qt::ShortcutContext context; | - |
88 | bool enabled : 1; | - |
89 | bool autorepeat : 1; | - |
90 | signed int id; | - |
91 | QObject *owner; | - |
92 | QShortcutMap::ContextMatcher contextMatcher; | - |
93 | }; | - |
94 | | - |
95 | #if 0 //ndef QT_NO_DEBUG_STREAM | - |
96 | /*! \internal | - |
97 | QDebug operator<< for easy debug output of the shortcut entries. | - |
98 | */ | - |
99 | static QDebug &operator<<(QDebug &dbg, const QShortcutEntry *se) { | - |
100 | if (!se) | - |
101 | return dbg << "QShortcutEntry(0x0)"; | - |
102 | dbg.nospace() | - |
103 | << "QShortcutEntry(" << se->keyseq | - |
104 | << "), id(" << se->id << "), enabled(" << se->enabled << "), autorepeat(" << se->autorepeat | - |
105 | << "), owner(" << se->owner << ')'; | - |
106 | return dbg.space(); | - |
107 | } | - |
108 | #endif // QT_NO_DEBUGSTREAM | - |
109 | | - |
110 | /* \internal | - |
111 | Private data for QShortcutMap | - |
112 | */ | - |
113 | class QShortcutMapPrivate | - |
114 | { | - |
115 | Q_DECLARE_PUBLIC(QShortcutMap) | - |
116 | | - |
117 | public: | - |
118 | QShortcutMapPrivate(QShortcutMap* parent) | - |
119 | : q_ptr(parent), currentId(0), ambigCount(0), currentState(QKeySequence::NoMatch) | - |
120 | { | - |
121 | identicals.reserve(10); executed (the execution status of this line is deduced): identicals.reserve(10); | - |
122 | currentSequences.reserve(10); executed (the execution status of this line is deduced): currentSequences.reserve(10); | - |
123 | } executed: } Execution Count:289 | 289 |
124 | QShortcutMap *q_ptr; // Private's parent | - |
125 | | - |
126 | QList<QShortcutEntry> sequences; // All sequences! | - |
127 | | - |
128 | int currentId; // Global shortcut ID number | - |
129 | int ambigCount; // Index of last enabled ambiguous dispatch | - |
130 | QKeySequence::SequenceMatch currentState; | - |
131 | QVector<QKeySequence> currentSequences; // Sequence for the current state | - |
132 | QVector<QKeySequence> newEntries; | - |
133 | QKeySequence prevSequence; // Sequence for the previous identical match | - |
134 | QVector<const QShortcutEntry*> identicals; // Last identical matches | - |
135 | }; | - |
136 | | - |
137 | | - |
138 | /*! \internal | - |
139 | QShortcutMap constructor. | - |
140 | */ | - |
141 | QShortcutMap::QShortcutMap() | - |
142 | : d_ptr(new QShortcutMapPrivate(this)) | - |
143 | { | - |
144 | resetState(); executed (the execution status of this line is deduced): resetState(); | - |
145 | } executed: } Execution Count:289 | 289 |
146 | | - |
147 | /*! \internal | - |
148 | QShortcutMap destructor. | - |
149 | */ | - |
150 | QShortcutMap::~QShortcutMap() | - |
151 | { | - |
152 | } | - |
153 | | - |
154 | /*! \internal | - |
155 | Adds a shortcut to the global map. | - |
156 | Returns the id of the newly added shortcut. | - |
157 | */ | - |
158 | int QShortcutMap::addShortcut(QObject *owner, const QKeySequence &key, Qt::ShortcutContext context, ContextMatcher matcher) | - |
159 | { | - |
160 | Q_ASSERT_X(owner, "QShortcutMap::addShortcut", "All shortcuts need an owner"); executed (the execution status of this line is deduced): qt_noop(); | - |
161 | Q_ASSERT_X(!key.isEmpty(), "QShortcutMap::addShortcut", "Cannot add keyless shortcuts to map"); executed (the execution status of this line is deduced): qt_noop(); | - |
162 | Q_D(QShortcutMap); executed (the execution status of this line is deduced): QShortcutMapPrivate * const d = d_func(); | - |
163 | | - |
164 | QShortcutEntry newEntry(owner, key, context, --(d->currentId), true, matcher); executed (the execution status of this line is deduced): QShortcutEntry newEntry(owner, key, context, --(d->currentId), true, matcher); | - |
165 | QList<QShortcutEntry>::iterator it = std::upper_bound(d->sequences.begin(), d->sequences.end(), newEntry); executed (the execution status of this line is deduced): QList<QShortcutEntry>::iterator it = std::upper_bound(d->sequences.begin(), d->sequences.end(), newEntry); | - |
166 | d->sequences.insert(it, newEntry); // Insert sorted executed (the execution status of this line is deduced): d->sequences.insert(it, newEntry); | - |
167 | #if defined(DEBUG_QSHORTCUTMAP) | - |
168 | qDebug().nospace() | - |
169 | << "QShortcutMap::addShortcut(" << owner << ", " | - |
170 | << key << ", " << context << ") = " << d->currentId; | - |
171 | #endif | - |
172 | return d->currentId; executed: return d->currentId; Execution Count:2624 | 2624 |
173 | } | - |
174 | | - |
175 | /*! \internal | - |
176 | Removes a shortcut from the global map. | - |
177 | If \a owner is 0, all entries in the map with the key sequence specified | - |
178 | is removed. If \a key is null, all sequences for \a owner is removed from | - |
179 | the map. If \a id is 0, any identical \a key sequences owned by \a owner | - |
180 | are removed. | - |
181 | Returns the number of sequences removed from the map. | - |
182 | */ | - |
183 | | - |
184 | int QShortcutMap::removeShortcut(int id, QObject *owner, const QKeySequence &key) | - |
185 | { | - |
186 | Q_D(QShortcutMap); executed (the execution status of this line is deduced): QShortcutMapPrivate * const d = d_func(); | - |
187 | int itemsRemoved = 0; executed (the execution status of this line is deduced): int itemsRemoved = 0; | - |
188 | bool allOwners = (owner == 0); executed (the execution status of this line is deduced): bool allOwners = (owner == 0); | - |
189 | bool allKeys = key.isEmpty(); executed (the execution status of this line is deduced): bool allKeys = key.isEmpty(); | - |
190 | bool allIds = id == 0; executed (the execution status of this line is deduced): bool allIds = id == 0; | - |
191 | | - |
192 | // Special case, remove everything | - |
193 | if (allOwners && allKeys && id == 0) { partially evaluated: allOwners no Evaluation Count:0 | yes Evaluation Count:2876 |
never evaluated: allKeys never evaluated: id == 0 | 0-2876 |
194 | itemsRemoved = d->sequences.size(); never executed (the execution status of this line is deduced): itemsRemoved = d->sequences.size(); | - |
195 | d->sequences.clear(); never executed (the execution status of this line is deduced): d->sequences.clear(); | - |
196 | return itemsRemoved; never executed: return itemsRemoved; | 0 |
197 | } | - |
198 | | - |
199 | int i = d->sequences.size()-1; executed (the execution status of this line is deduced): int i = d->sequences.size()-1; | - |
200 | while (i>=0) evaluated: i>=0 yes Evaluation Count:14059 | yes Evaluation Count:1480 |
| 1480-14059 |
201 | { | - |
202 | const QShortcutEntry &entry = d->sequences.at(i); executed (the execution status of this line is deduced): const QShortcutEntry &entry = d->sequences.at(i); | - |
203 | int entryId = entry.id; executed (the execution status of this line is deduced): int entryId = entry.id; | - |
204 | if ((allOwners || entry.owner == owner) partially evaluated: allOwners no Evaluation Count:0 | yes Evaluation Count:14059 |
evaluated: entry.owner == owner yes Evaluation Count:2665 | yes Evaluation Count:11394 |
| 0-14059 |
205 | && (allIds || entry.id == id) evaluated: allIds yes Evaluation Count:1223 | yes Evaluation Count:1442 |
evaluated: entry.id == id yes Evaluation Count:1396 | yes Evaluation Count:46 |
| 46-1442 |
206 | && (allKeys || entry.keyseq == key)) { partially evaluated: allKeys yes Evaluation Count:2619 | no Evaluation Count:0 |
never evaluated: entry.keyseq == key | 0-2619 |
207 | d->sequences.removeAt(i); executed (the execution status of this line is deduced): d->sequences.removeAt(i); | - |
208 | ++itemsRemoved; executed (the execution status of this line is deduced): ++itemsRemoved; | - |
209 | } executed: } Execution Count:2619 | 2619 |
210 | if (id == entryId) evaluated: id == entryId yes Evaluation Count:1396 | yes Evaluation Count:12663 |
| 1396-12663 |
211 | return itemsRemoved; executed: return itemsRemoved; Execution Count:1396 | 1396 |
212 | --i; executed (the execution status of this line is deduced): --i; | - |
213 | } executed: } Execution Count:12663 | 12663 |
214 | #if defined(DEBUG_QSHORTCUTMAP) | - |
215 | qDebug().nospace() | - |
216 | << "QShortcutMap::removeShortcut(" << id << ", " << owner << ", " | - |
217 | << key << ") = " << itemsRemoved; | - |
218 | #endif | - |
219 | return itemsRemoved; executed: return itemsRemoved; Execution Count:1480 | 1480 |
220 | } | - |
221 | | - |
222 | /*! \internal | - |
223 | Changes the enable state of a shortcut to \a enable. | - |
224 | If \a owner is 0, all entries in the map with the key sequence specified | - |
225 | is removed. If \a key is null, all sequences for \a owner is removed from | - |
226 | the map. If \a id is 0, any identical \a key sequences owned by \a owner | - |
227 | are changed. | - |
228 | Returns the number of sequences which are matched in the map. | - |
229 | */ | - |
230 | int QShortcutMap::setShortcutEnabled(bool enable, int id, QObject *owner, const QKeySequence &key) | - |
231 | { | - |
232 | Q_D(QShortcutMap); executed (the execution status of this line is deduced): QShortcutMapPrivate * const d = d_func(); | - |
233 | int itemsChanged = 0; executed (the execution status of this line is deduced): int itemsChanged = 0; | - |
234 | bool allOwners = (owner == 0); executed (the execution status of this line is deduced): bool allOwners = (owner == 0); | - |
235 | bool allKeys = key.isEmpty(); executed (the execution status of this line is deduced): bool allKeys = key.isEmpty(); | - |
236 | bool allIds = id == 0; executed (the execution status of this line is deduced): bool allIds = id == 0; | - |
237 | | - |
238 | int i = d->sequences.size()-1; executed (the execution status of this line is deduced): int i = d->sequences.size()-1; | - |
239 | while (i>=0) partially evaluated: i>=0 yes Evaluation Count:724 | no Evaluation Count:0 |
| 0-724 |
240 | { | - |
241 | QShortcutEntry entry = d->sequences.at(i); executed (the execution status of this line is deduced): QShortcutEntry entry = d->sequences.at(i); | - |
242 | if ((allOwners || entry.owner == owner) partially evaluated: allOwners no Evaluation Count:0 | yes Evaluation Count:724 |
evaluated: entry.owner == owner yes Evaluation Count:598 | yes Evaluation Count:126 |
| 0-724 |
243 | && (allIds || entry.id == id) partially evaluated: allIds no Evaluation Count:0 | yes Evaluation Count:598 |
partially evaluated: entry.id == id yes Evaluation Count:598 | no Evaluation Count:0 |
| 0-598 |
244 | && (allKeys || entry.keyseq == key)) { partially evaluated: allKeys yes Evaluation Count:598 | no Evaluation Count:0 |
never evaluated: entry.keyseq == key | 0-598 |
245 | d->sequences[i].enabled = enable; executed (the execution status of this line is deduced): d->sequences[i].enabled = enable; | - |
246 | ++itemsChanged; executed (the execution status of this line is deduced): ++itemsChanged; | - |
247 | } executed: } Execution Count:598 | 598 |
248 | if (id == entry.id) evaluated: id == entry.id yes Evaluation Count:598 | yes Evaluation Count:126 |
| 126-598 |
249 | return itemsChanged; executed: return itemsChanged; Execution Count:598 | 598 |
250 | --i; executed (the execution status of this line is deduced): --i; | - |
251 | } executed: } Execution Count:126 | 126 |
252 | #if defined(DEBUG_QSHORTCUTMAP) | - |
253 | qDebug().nospace() | - |
254 | << "QShortcutMap::setShortcutEnabled(" << enable << ", " << id << ", " | - |
255 | << owner << ", " << key << ") = " << itemsChanged; | - |
256 | #endif | - |
257 | return itemsChanged; never executed: return itemsChanged; | 0 |
258 | } | - |
259 | | - |
260 | /*! \internal | - |
261 | Changes the auto repeat state of a shortcut to \a enable. | - |
262 | If \a owner is 0, all entries in the map with the key sequence specified | - |
263 | is removed. If \a key is null, all sequences for \a owner is removed from | - |
264 | the map. If \a id is 0, any identical \a key sequences owned by \a owner | - |
265 | are changed. | - |
266 | Returns the number of sequences which are matched in the map. | - |
267 | */ | - |
268 | int QShortcutMap::setShortcutAutoRepeat(bool on, int id, QObject *owner, const QKeySequence &key) | - |
269 | { | - |
270 | Q_D(QShortcutMap); executed (the execution status of this line is deduced): QShortcutMapPrivate * const d = d_func(); | - |
271 | int itemsChanged = 0; executed (the execution status of this line is deduced): int itemsChanged = 0; | - |
272 | bool allOwners = (owner == 0); executed (the execution status of this line is deduced): bool allOwners = (owner == 0); | - |
273 | bool allKeys = key.isEmpty(); executed (the execution status of this line is deduced): bool allKeys = key.isEmpty(); | - |
274 | bool allIds = id == 0; executed (the execution status of this line is deduced): bool allIds = id == 0; | - |
275 | | - |
276 | int i = d->sequences.size()-1; executed (the execution status of this line is deduced): int i = d->sequences.size()-1; | - |
277 | while (i>=0) partially evaluated: i>=0 yes Evaluation Count:3 | no Evaluation Count:0 |
| 0-3 |
278 | { | - |
279 | QShortcutEntry entry = d->sequences.at(i); executed (the execution status of this line is deduced): QShortcutEntry entry = d->sequences.at(i); | - |
280 | if ((allOwners || entry.owner == owner) partially evaluated: allOwners no Evaluation Count:0 | yes Evaluation Count:3 |
partially evaluated: entry.owner == owner yes Evaluation Count:3 | no Evaluation Count:0 |
| 0-3 |
281 | && (allIds || entry.id == id) partially evaluated: allIds no Evaluation Count:0 | yes Evaluation Count:3 |
evaluated: entry.id == id yes Evaluation Count:2 | yes Evaluation Count:1 |
| 0-3 |
282 | && (allKeys || entry.keyseq == key)) { partially evaluated: allKeys yes Evaluation Count:2 | no Evaluation Count:0 |
never evaluated: entry.keyseq == key | 0-2 |
283 | d->sequences[i].autorepeat = on; executed (the execution status of this line is deduced): d->sequences[i].autorepeat = on; | - |
284 | ++itemsChanged; executed (the execution status of this line is deduced): ++itemsChanged; | - |
285 | } executed: } Execution Count:2 | 2 |
286 | if (id == entry.id) evaluated: id == entry.id yes Evaluation Count:2 | yes Evaluation Count:1 |
| 1-2 |
287 | return itemsChanged; executed: return itemsChanged; Execution Count:2 | 2 |
288 | --i; executed (the execution status of this line is deduced): --i; | - |
289 | } executed: } Execution Count:1 | 1 |
290 | #if defined(DEBUG_QSHORTCUTMAP) | - |
291 | qDebug().nospace() | - |
292 | << "QShortcutMap::setShortcutAutoRepeat(" << on << ", " << id << ", " | - |
293 | << owner << ", " << key << ") = " << itemsChanged; | - |
294 | #endif | - |
295 | return itemsChanged; never executed: return itemsChanged; | 0 |
296 | } | - |
297 | | - |
298 | /*! \internal | - |
299 | Resets the state of the statemachine to NoMatch | - |
300 | */ | - |
301 | void QShortcutMap::resetState() | - |
302 | { | - |
303 | Q_D(QShortcutMap); executed (the execution status of this line is deduced): QShortcutMapPrivate * const d = d_func(); | - |
304 | d->currentState = QKeySequence::NoMatch; executed (the execution status of this line is deduced): d->currentState = QKeySequence::NoMatch; | - |
305 | clearSequence(d->currentSequences); executed (the execution status of this line is deduced): clearSequence(d->currentSequences); | - |
306 | } executed: } Execution Count:404 | 404 |
307 | | - |
308 | /*! \internal | - |
309 | Returns the current state of the statemachine | - |
310 | */ | - |
311 | QKeySequence::SequenceMatch QShortcutMap::state() | - |
312 | { | - |
313 | Q_D(QShortcutMap); never executed (the execution status of this line is deduced): QShortcutMapPrivate * const d = d_func(); | - |
314 | return d->currentState; never executed: return d->currentState; | 0 |
315 | } | - |
316 | | - |
317 | /*! \internal | - |
318 | Uses ShortcutOverride event to see if any widgets want to override | - |
319 | the event. If not, uses nextState(QKeyEvent) to check for a grabbed | - |
320 | Shortcut, and dispatchEvent() is found an identical. | - |
321 | \sa nextState, dispatchEvent | - |
322 | */ | - |
323 | bool QShortcutMap::tryShortcutEvent(QObject *o, QKeyEvent *e) | - |
324 | { | - |
325 | Q_D(QShortcutMap); executed (the execution status of this line is deduced): QShortcutMapPrivate * const d = d_func(); | - |
326 | | - |
327 | bool wasAccepted = e->isAccepted(); executed (the execution status of this line is deduced): bool wasAccepted = e->isAccepted(); | - |
328 | bool wasSpontaneous = e->spont; executed (the execution status of this line is deduced): bool wasSpontaneous = e->spont; | - |
329 | if (d->currentState == QKeySequence::NoMatch) { evaluated: d->currentState == QKeySequence::NoMatch yes Evaluation Count:5525 | yes Evaluation Count:5 |
| 5-5525 |
330 | ushort orgType = e->t; executed (the execution status of this line is deduced): ushort orgType = e->t; | - |
331 | e->t = QEvent::ShortcutOverride; executed (the execution status of this line is deduced): e->t = QEvent::ShortcutOverride; | - |
332 | e->ignore(); executed (the execution status of this line is deduced): e->ignore(); | - |
333 | QCoreApplication::sendEvent(o, e); executed (the execution status of this line is deduced): QCoreApplication::sendEvent(o, e); | - |
334 | e->t = orgType; executed (the execution status of this line is deduced): e->t = orgType; | - |
335 | e->spont = wasSpontaneous; executed (the execution status of this line is deduced): e->spont = wasSpontaneous; | - |
336 | if (e->isAccepted()) { evaluated: e->isAccepted() yes Evaluation Count:2373 | yes Evaluation Count:3152 |
| 2373-3152 |
337 | if (!wasAccepted) partially evaluated: !wasAccepted no Evaluation Count:0 | yes Evaluation Count:2373 |
| 0-2373 |
338 | e->ignore(); never executed: e->ignore(); | 0 |
339 | return false; executed: return false; Execution Count:2373 | 2373 |
340 | } | - |
341 | } executed: } Execution Count:3152 | 3152 |
342 | | - |
343 | QKeySequence::SequenceMatch result = nextState(e); executed (the execution status of this line is deduced): QKeySequence::SequenceMatch result = nextState(e); | - |
344 | bool stateWasAccepted = e->isAccepted(); executed (the execution status of this line is deduced): bool stateWasAccepted = e->isAccepted(); | - |
345 | if (wasAccepted) partially evaluated: wasAccepted yes Evaluation Count:3157 | no Evaluation Count:0 |
| 0-3157 |
346 | e->accept(); executed: e->accept(); Execution Count:3157 | 3157 |
347 | else | - |
348 | e->ignore(); never executed: e->ignore(); | 0 |
349 | | - |
350 | int identicalMatches = d->identicals.count(); executed (the execution status of this line is deduced): int identicalMatches = d->identicals.count(); | - |
351 | | - |
352 | switch(result) { | - |
353 | case QKeySequence::NoMatch: | - |
354 | return stateWasAccepted; executed: return stateWasAccepted; Execution Count:3037 | 3037 |
355 | case QKeySequence::ExactMatch: | - |
356 | resetState(); executed (the execution status of this line is deduced): resetState(); | - |
357 | dispatchEvent(e); executed (the execution status of this line is deduced): dispatchEvent(e); | - |
358 | default: | - |
359 | break; executed: break; Execution Count:120 | 120 |
360 | } | - |
361 | // If nextState is QKeySequence::ExactMatch && identicals.count == 0 | - |
362 | // we've only found disabled shortcuts | - |
363 | return identicalMatches > 0 || result == QKeySequence::PartialMatch; executed: return identicalMatches > 0 || result == QKeySequence::PartialMatch; Execution Count:120 | 120 |
364 | } | - |
365 | | - |
366 | /*! \internal | - |
367 | Returns the next state of the statemachine | - |
368 | If return value is SequenceMatch::ExactMatch, then a call to matches() | - |
369 | will return a QObjects* list of all matching objects for the last matching | - |
370 | sequence. | - |
371 | */ | - |
372 | QKeySequence::SequenceMatch QShortcutMap::nextState(QKeyEvent *e) | - |
373 | { | - |
374 | Q_D(QShortcutMap); executed (the execution status of this line is deduced): QShortcutMapPrivate * const d = d_func(); | - |
375 | // Modifiers can NOT be shortcuts... | - |
376 | if (e->key() >= Qt::Key_Shift && evaluated: e->key() >= Qt::Key_Shift yes Evaluation Count:248 | yes Evaluation Count:2909 |
| 248-2909 |
377 | e->key() <= Qt::Key_Alt) evaluated: e->key() <= Qt::Key_Alt yes Evaluation Count:229 | yes Evaluation Count:19 |
| 19-229 |
378 | return d->currentState; executed: return d->currentState; Execution Count:229 | 229 |
379 | | - |
380 | QKeySequence::SequenceMatch result = QKeySequence::NoMatch; executed (the execution status of this line is deduced): QKeySequence::SequenceMatch result = QKeySequence::NoMatch; | - |
381 | | - |
382 | // We start fresh each time.. | - |
383 | d->identicals.resize(0); executed (the execution status of this line is deduced): d->identicals.resize(0); | - |
384 | | - |
385 | result = find(e); executed (the execution status of this line is deduced): result = find(e); | - |
386 | if (result == QKeySequence::NoMatch && (e->modifiers() & Qt::KeypadModifier)) { evaluated: result == QKeySequence::NoMatch yes Evaluation Count:2810 | yes Evaluation Count:118 |
evaluated: (e->modifiers() & Qt::KeypadModifier) yes Evaluation Count:3 | yes Evaluation Count:2807 |
| 3-2810 |
387 | // Try to find a match without keypad modifier | - |
388 | QKeyEvent event = *e; executed (the execution status of this line is deduced): QKeyEvent event = *e; | - |
389 | event.setModifiers(e->modifiers() & ~Qt::KeypadModifier); executed (the execution status of this line is deduced): event.setModifiers(e->modifiers() & ~Qt::KeypadModifier); | - |
390 | result = find(&event); executed (the execution status of this line is deduced): result = find(&event); | - |
391 | } executed: } Execution Count:3 | 3 |
392 | if (result == QKeySequence::NoMatch && e->modifiers() & Qt::ShiftModifier) { evaluated: result == QKeySequence::NoMatch yes Evaluation Count:2809 | yes Evaluation Count:119 |
evaluated: e->modifiers() & Qt::ShiftModifier yes Evaluation Count:25 | yes Evaluation Count:2784 |
| 25-2809 |
393 | // If Shift + Key_Backtab, also try Shift + Qt::Key_Tab | - |
394 | if (e->key() == Qt::Key_Backtab) { evaluated: e->key() == Qt::Key_Backtab yes Evaluation Count:3 | yes Evaluation Count:22 |
| 3-22 |
395 | QKeyEvent pe = QKeyEvent(e->type(), Qt::Key_Tab, e->modifiers(), e->text()); executed (the execution status of this line is deduced): QKeyEvent pe = QKeyEvent(e->type(), Qt::Key_Tab, e->modifiers(), e->text()); | - |
396 | result = find(&pe); executed (the execution status of this line is deduced): result = find(&pe); | - |
397 | } executed: } Execution Count:3 | 3 |
398 | } executed: } Execution Count:25 | 25 |
399 | | - |
400 | // Should we eat this key press? | - |
401 | if (d->currentState == QKeySequence::PartialMatch evaluated: d->currentState == QKeySequence::PartialMatch yes Evaluation Count:5 | yes Evaluation Count:2923 |
| 5-2923 |
402 | || (d->currentState == QKeySequence::ExactMatch && d->identicals.count())) partially evaluated: d->currentState == QKeySequence::ExactMatch no Evaluation Count:0 | yes Evaluation Count:2923 |
never evaluated: d->identicals.count() | 0-2923 |
403 | e->accept(); executed: e->accept(); Execution Count:5 | 5 |
404 | // Does the new state require us to clean up? | - |
405 | if (result == QKeySequence::NoMatch) evaluated: result == QKeySequence::NoMatch yes Evaluation Count:2808 | yes Evaluation Count:120 |
| 120-2808 |
406 | clearSequence(d->currentSequences); executed: clearSequence(d->currentSequences); Execution Count:2808 | 2808 |
407 | d->currentState = result; executed (the execution status of this line is deduced): d->currentState = result; | - |
408 | | - |
409 | #if defined(DEBUG_QSHORTCUTMAP) | - |
410 | qDebug().nospace() << "QShortcutMap::nextState(" << e << ") = " << result; | - |
411 | #endif | - |
412 | return result; executed: return result; Execution Count:2928 | 2928 |
413 | } | - |
414 | | - |
415 | | - |
416 | /*! \internal | - |
417 | Determines if an enabled shortcut has a matcing key sequence. | - |
418 | */ | - |
419 | bool QShortcutMap::hasShortcutForKeySequence(const QKeySequence &seq) const | - |
420 | { | - |
421 | Q_D(const QShortcutMap); executed (the execution status of this line is deduced): const QShortcutMapPrivate * const d = d_func(); | - |
422 | QShortcutEntry entry(seq); // needed for searching executed (the execution status of this line is deduced): QShortcutEntry entry(seq); | - |
423 | QList<QShortcutEntry>::ConstIterator itEnd = d->sequences.constEnd(); executed (the execution status of this line is deduced): QList<QShortcutEntry>::ConstIterator itEnd = d->sequences.constEnd(); | - |
424 | QList<QShortcutEntry>::ConstIterator it = std::lower_bound(d->sequences.constBegin(), itEnd, entry); executed (the execution status of this line is deduced): QList<QShortcutEntry>::ConstIterator it = std::lower_bound(d->sequences.constBegin(), itEnd, entry); | - |
425 | | - |
426 | for (;it != itEnd; ++it) { partially evaluated: it != itEnd no Evaluation Count:0 | yes Evaluation Count:14 |
| 0-14 |
427 | if (matches(entry.keyseq, (*it).keyseq) == QKeySequence::ExactMatch && (*it).correctContext() && (*it).enabled) { never evaluated: matches(entry.keyseq, (*it).keyseq) == QKeySequence::ExactMatch never evaluated: (*it).correctContext() never evaluated: (*it).enabled | 0 |
428 | return true; never executed: return true; | 0 |
429 | } | - |
430 | } | 0 |
431 | | - |
432 | //end of the loop: we didn't find anything | - |
433 | return false; executed: return false; Execution Count:14 | 14 |
434 | } | - |
435 | | - |
436 | /*! \internal | - |
437 | Returns the next state of the statemachine, based | - |
438 | on the new key event \a e. | - |
439 | Matches are appended to the vector of identicals, | - |
440 | which can be access through matches(). | - |
441 | \sa matches | - |
442 | */ | - |
443 | QKeySequence::SequenceMatch QShortcutMap::find(QKeyEvent *e) | - |
444 | { | - |
445 | Q_D(QShortcutMap); executed (the execution status of this line is deduced): QShortcutMapPrivate * const d = d_func(); | - |
446 | if (!d->sequences.count()) evaluated: !d->sequences.count() yes Evaluation Count:2698 | yes Evaluation Count:236 |
| 236-2698 |
447 | return QKeySequence::NoMatch; executed: return QKeySequence::NoMatch; Execution Count:2698 | 2698 |
448 | | - |
449 | createNewSequences(e, d->newEntries); executed (the execution status of this line is deduced): createNewSequences(e, d->newEntries); | - |
450 | #if defined(DEBUG_QSHORTCUTMAP) | - |
451 | qDebug() << "Possible shortcut key sequences:" << d->newEntries; | - |
452 | #endif | - |
453 | | - |
454 | // Should never happen | - |
455 | if (d->newEntries == d->currentSequences) { partially evaluated: d->newEntries == d->currentSequences no Evaluation Count:0 | yes Evaluation Count:236 |
| 0-236 |
456 | Q_ASSERT_X(e->key() != Qt::Key_unknown || e->text().length(), never executed (the execution status of this line is deduced): qt_noop(); | - |
457 | "QShortcutMap::find", "New sequence to find identical to previous"); | - |
458 | return QKeySequence::NoMatch; never executed: return QKeySequence::NoMatch; | 0 |
459 | } | - |
460 | | - |
461 | // Looking for new identicals, scrap old | - |
462 | d->identicals.resize(0); executed (the execution status of this line is deduced): d->identicals.resize(0); | - |
463 | | - |
464 | bool partialFound = false; executed (the execution status of this line is deduced): bool partialFound = false; | - |
465 | bool identicalDisabledFound = false; executed (the execution status of this line is deduced): bool identicalDisabledFound = false; | - |
466 | QVector<QKeySequence> okEntries; executed (the execution status of this line is deduced): QVector<QKeySequence> okEntries; | - |
467 | int result = QKeySequence::NoMatch; executed (the execution status of this line is deduced): int result = QKeySequence::NoMatch; | - |
468 | for (int i = d->newEntries.count()-1; i >= 0 ; --i) { evaluated: i >= 0 yes Evaluation Count:236 | yes Evaluation Count:236 |
| 236 |
469 | QShortcutEntry entry(d->newEntries.at(i)); // needed for searching executed (the execution status of this line is deduced): QShortcutEntry entry(d->newEntries.at(i)); | - |
470 | QList<QShortcutEntry>::ConstIterator itEnd = d->sequences.constEnd(); executed (the execution status of this line is deduced): QList<QShortcutEntry>::ConstIterator itEnd = d->sequences.constEnd(); | - |
471 | QList<QShortcutEntry>::ConstIterator it = executed (the execution status of this line is deduced): QList<QShortcutEntry>::ConstIterator it = | - |
472 | std::lower_bound(d->sequences.constBegin(), itEnd, entry); executed (the execution status of this line is deduced): std::lower_bound(d->sequences.constBegin(), itEnd, entry); | - |
473 | | - |
474 | int oneKSResult = QKeySequence::NoMatch; executed (the execution status of this line is deduced): int oneKSResult = QKeySequence::NoMatch; | - |
475 | int tempRes = QKeySequence::NoMatch; executed (the execution status of this line is deduced): int tempRes = QKeySequence::NoMatch; | - |
476 | do { | - |
477 | if (it == itEnd) evaluated: it == itEnd yes Evaluation Count:78 | yes Evaluation Count:377 |
| 78-377 |
478 | break; executed: break; Execution Count:78 | 78 |
479 | tempRes = matches(entry.keyseq, (*it).keyseq); executed (the execution status of this line is deduced): tempRes = matches(entry.keyseq, (*it).keyseq); | - |
480 | oneKSResult = qMax(oneKSResult, tempRes); executed (the execution status of this line is deduced): oneKSResult = qMax(oneKSResult, tempRes); | - |
481 | if (tempRes != QKeySequence::NoMatch && (*it).correctContext()) { evaluated: tempRes != QKeySequence::NoMatch yes Evaluation Count:219 | yes Evaluation Count:158 |
evaluated: (*it).correctContext() yes Evaluation Count:217 | yes Evaluation Count:2 |
| 2-219 |
482 | if (tempRes == QKeySequence::ExactMatch) { evaluated: tempRes == QKeySequence::ExactMatch yes Evaluation Count:209 | yes Evaluation Count:8 |
| 8-209 |
483 | if ((*it).enabled) evaluated: (*it).enabled yes Evaluation Count:154 | yes Evaluation Count:55 |
| 55-154 |
484 | d->identicals.append(&*it); executed: d->identicals.append(&*it); Execution Count:154 | 154 |
485 | else | - |
486 | identicalDisabledFound = true; executed: identicalDisabledFound = true; Execution Count:55 | 55 |
487 | } else if (tempRes == QKeySequence::PartialMatch) { partially evaluated: tempRes == QKeySequence::PartialMatch yes Evaluation Count:8 | no Evaluation Count:0 |
| 0-8 |
488 | // We don't need partials, if we have identicals | - |
489 | if (d->identicals.size()) partially evaluated: d->identicals.size() no Evaluation Count:0 | yes Evaluation Count:8 |
| 0-8 |
490 | break; | 0 |
491 | // We only care about enabled partials, so we don't consume | - |
492 | // key events when all partials are disabled! | - |
493 | partialFound |= (*it).enabled; executed (the execution status of this line is deduced): partialFound |= (*it).enabled; | - |
494 | } executed: } Execution Count:8 | 8 |
495 | } | - |
496 | ++it; executed (the execution status of this line is deduced): ++it; | - |
497 | // If we got a valid match on this run, there might still be more keys to check against, | - |
498 | // so we'll loop once more. If we get NoMatch, there's guaranteed no more possible | - |
499 | // matches in the shortcutmap. | - |
500 | } while (tempRes != QKeySequence::NoMatch); executed: } Execution Count:377 evaluated: tempRes != QKeySequence::NoMatch yes Evaluation Count:219 | yes Evaluation Count:158 |
| 158-377 |
501 | | - |
502 | // If the type of match improves (ergo, NoMatch->Partial, or Partial->Exact), clear the | - |
503 | // previous list. If this match is equal or better than the last match, append to the list | - |
504 | if (oneKSResult > result) { evaluated: oneKSResult > result yes Evaluation Count:122 | yes Evaluation Count:114 |
| 114-122 |
505 | okEntries.clear(); executed (the execution status of this line is deduced): okEntries.clear(); | - |
506 | #if defined(DEBUG_QSHORTCUTMAP) | - |
507 | qDebug() << "Found better match (" << d->newEntries << "), clearing key sequence list"; | - |
508 | #endif | - |
509 | } executed: } Execution Count:122 | 122 |
510 | if (oneKSResult && oneKSResult >= result) { evaluated: oneKSResult yes Evaluation Count:122 | yes Evaluation Count:114 |
partially evaluated: oneKSResult >= result yes Evaluation Count:122 | no Evaluation Count:0 |
| 0-122 |
511 | okEntries << d->newEntries.at(i); executed (the execution status of this line is deduced): okEntries << d->newEntries.at(i); | - |
512 | #if defined(DEBUG_QSHORTCUTMAP) | - |
513 | qDebug() << "Added ok key sequence" << d->newEntries; | - |
514 | #endif | - |
515 | } executed: } Execution Count:122 | 122 |
516 | } executed: } Execution Count:236 | 236 |
517 | | - |
518 | if (d->identicals.size()) { evaluated: d->identicals.size() yes Evaluation Count:112 | yes Evaluation Count:124 |
| 112-124 |
519 | result = QKeySequence::ExactMatch; executed (the execution status of this line is deduced): result = QKeySequence::ExactMatch; | - |
520 | } else if (partialFound) { executed: } Execution Count:112 evaluated: partialFound yes Evaluation Count:5 | yes Evaluation Count:119 |
| 5-119 |
521 | result = QKeySequence::PartialMatch; executed (the execution status of this line is deduced): result = QKeySequence::PartialMatch; | - |
522 | } else if (identicalDisabledFound) { executed: } Execution Count:5 evaluated: identicalDisabledFound yes Evaluation Count:3 | yes Evaluation Count:116 |
| 3-116 |
523 | result = QKeySequence::ExactMatch; executed (the execution status of this line is deduced): result = QKeySequence::ExactMatch; | - |
524 | } else { executed: } Execution Count:3 | 3 |
525 | clearSequence(d->currentSequences); executed (the execution status of this line is deduced): clearSequence(d->currentSequences); | - |
526 | result = QKeySequence::NoMatch; executed (the execution status of this line is deduced): result = QKeySequence::NoMatch; | - |
527 | } executed: } Execution Count:116 | 116 |
528 | if (result != QKeySequence::NoMatch) evaluated: result != QKeySequence::NoMatch yes Evaluation Count:120 | yes Evaluation Count:116 |
| 116-120 |
529 | d->currentSequences = okEntries; executed: d->currentSequences = okEntries; Execution Count:120 | 120 |
530 | #if defined(DEBUG_QSHORTCUTMAP) | - |
531 | qDebug() << "Returning shortcut match == " << result; | - |
532 | #endif | - |
533 | return QKeySequence::SequenceMatch(result); executed: return QKeySequence::SequenceMatch(result); Execution Count:236 | 236 |
534 | } | - |
535 | | - |
536 | /*! \internal | - |
537 | Clears \a seq to an empty QKeySequence. | - |
538 | Same as doing (the slower) | - |
539 | \snippet code/src_gui_kernel_qshortcutmap.cpp 0 | - |
540 | */ | - |
541 | void QShortcutMap::clearSequence(QVector<QKeySequence> &ksl) | - |
542 | { | - |
543 | ksl.clear(); executed (the execution status of this line is deduced): ksl.clear(); | - |
544 | d_func()->newEntries.clear(); executed (the execution status of this line is deduced): d_func()->newEntries.clear(); | - |
545 | } executed: } Execution Count:3328 | 3328 |
546 | | - |
547 | /*! \internal | - |
548 | Alters \a seq to the new sequence state, based on the | - |
549 | current sequence state, and the new key event \a e. | - |
550 | */ | - |
551 | void QShortcutMap::createNewSequences(QKeyEvent *e, QVector<QKeySequence> &ksl) | - |
552 | { | - |
553 | Q_D(QShortcutMap); executed (the execution status of this line is deduced): QShortcutMapPrivate * const d = d_func(); | - |
554 | QList<int> possibleKeys = QKeyMapper::possibleKeys(e); executed (the execution status of this line is deduced): QList<int> possibleKeys = QKeyMapper::possibleKeys(e); | - |
555 | int pkTotal = possibleKeys.count(); executed (the execution status of this line is deduced): int pkTotal = possibleKeys.count(); | - |
556 | if (!pkTotal) partially evaluated: !pkTotal no Evaluation Count:0 | yes Evaluation Count:236 |
| 0-236 |
557 | return; | 0 |
558 | | - |
559 | int ssActual = d->currentSequences.count(); executed (the execution status of this line is deduced): int ssActual = d->currentSequences.count(); | - |
560 | int ssTotal = qMax(1, ssActual); executed (the execution status of this line is deduced): int ssTotal = qMax(1, ssActual); | - |
561 | // Resize to possible permutations of the current sequence(s). | - |
562 | ksl.resize(pkTotal * ssTotal); executed (the execution status of this line is deduced): ksl.resize(pkTotal * ssTotal); | - |
563 | | - |
564 | int index = ssActual ? d->currentSequences.at(0).count() : 0; evaluated: ssActual yes Evaluation Count:5 | yes Evaluation Count:231 |
| 5-231 |
565 | for (int pkNum = 0; pkNum < pkTotal; ++pkNum) { evaluated: pkNum < pkTotal yes Evaluation Count:236 | yes Evaluation Count:236 |
| 236 |
566 | for (int ssNum = 0; ssNum < ssTotal; ++ssNum) { evaluated: ssNum < ssTotal yes Evaluation Count:236 | yes Evaluation Count:236 |
| 236 |
567 | int i = (pkNum * ssTotal) + ssNum; executed (the execution status of this line is deduced): int i = (pkNum * ssTotal) + ssNum; | - |
568 | QKeySequence &curKsl = ksl[i]; executed (the execution status of this line is deduced): QKeySequence &curKsl = ksl[i]; | - |
569 | if (ssActual) { evaluated: ssActual yes Evaluation Count:5 | yes Evaluation Count:231 |
| 5-231 |
570 | const QKeySequence &curSeq = d->currentSequences.at(ssNum); executed (the execution status of this line is deduced): const QKeySequence &curSeq = d->currentSequences.at(ssNum); | - |
571 | curKsl.setKey(curSeq[0], 0); executed (the execution status of this line is deduced): curKsl.setKey(curSeq[0], 0); | - |
572 | curKsl.setKey(curSeq[1], 1); executed (the execution status of this line is deduced): curKsl.setKey(curSeq[1], 1); | - |
573 | curKsl.setKey(curSeq[2], 2); executed (the execution status of this line is deduced): curKsl.setKey(curSeq[2], 2); | - |
574 | curKsl.setKey(curSeq[3], 3); executed (the execution status of this line is deduced): curKsl.setKey(curSeq[3], 3); | - |
575 | } else { executed: } Execution Count:5 | 5 |
576 | curKsl.setKey(0, 0); executed (the execution status of this line is deduced): curKsl.setKey(0, 0); | - |
577 | curKsl.setKey(0, 1); executed (the execution status of this line is deduced): curKsl.setKey(0, 1); | - |
578 | curKsl.setKey(0, 2); executed (the execution status of this line is deduced): curKsl.setKey(0, 2); | - |
579 | curKsl.setKey(0, 3); executed (the execution status of this line is deduced): curKsl.setKey(0, 3); | - |
580 | } executed: } Execution Count:231 | 231 |
581 | curKsl.setKey(possibleKeys.at(pkNum), index); executed (the execution status of this line is deduced): curKsl.setKey(possibleKeys.at(pkNum), index); | - |
582 | } executed: } Execution Count:236 | 236 |
583 | } executed: } Execution Count:236 | 236 |
584 | } executed: } Execution Count:236 | 236 |
585 | | - |
586 | /*! \internal | - |
587 | Basically the same function as QKeySequence::matches(const QKeySequence &seq) const | - |
588 | only that is specially handles Key_hyphen as Key_Minus, as people mix these up all the time and | - |
589 | they conceptually the same. | - |
590 | */ | - |
591 | QKeySequence::SequenceMatch QShortcutMap::matches(const QKeySequence &seq1, | - |
592 | const QKeySequence &seq2) const | - |
593 | { | - |
594 | uint userN = seq1.count(), executed (the execution status of this line is deduced): uint userN = seq1.count(), | - |
595 | seqN = seq2.count(); executed (the execution status of this line is deduced): seqN = seq2.count(); | - |
596 | | - |
597 | if (userN > seqN) evaluated: userN > seqN yes Evaluation Count:2 | yes Evaluation Count:375 |
| 2-375 |
598 | return QKeySequence::NoMatch; executed: return QKeySequence::NoMatch; Execution Count:2 | 2 |
599 | | - |
600 | // If equal in length, we have a potential ExactMatch sequence, | - |
601 | // else we already know it can only be partial. | - |
602 | QKeySequence::SequenceMatch match = (userN == seqN evaluated: userN == seqN yes Evaluation Count:365 | yes Evaluation Count:10 |
| 10-365 |
603 | ? QKeySequence::ExactMatch executed (the execution status of this line is deduced): ? QKeySequence::ExactMatch | - |
604 | : QKeySequence::PartialMatch); executed (the execution status of this line is deduced): : QKeySequence::PartialMatch); | - |
605 | | - |
606 | for (uint i = 0; i < userN; ++i) { evaluated: i < userN yes Evaluation Count:379 | yes Evaluation Count:219 |
| 219-379 |
607 | int userKey = seq1[i], executed (the execution status of this line is deduced): int userKey = seq1[i], | - |
608 | sequenceKey = seq2[i]; executed (the execution status of this line is deduced): sequenceKey = seq2[i]; | - |
609 | if ((userKey & Qt::Key_unknown) == Qt::Key_hyphen) partially evaluated: (userKey & Qt::Key_unknown) == Qt::Key_hyphen no Evaluation Count:0 | yes Evaluation Count:379 |
| 0-379 |
610 | userKey = (userKey & Qt::KeyboardModifierMask) | Qt::Key_Minus; never executed: userKey = (userKey & Qt::KeyboardModifierMask) | Qt::Key_Minus; | 0 |
611 | if ((sequenceKey & Qt::Key_unknown) == Qt::Key_hyphen) partially evaluated: (sequenceKey & Qt::Key_unknown) == Qt::Key_hyphen no Evaluation Count:0 | yes Evaluation Count:379 |
| 0-379 |
612 | sequenceKey = (sequenceKey & Qt::KeyboardModifierMask) | Qt::Key_Minus; never executed: sequenceKey = (sequenceKey & Qt::KeyboardModifierMask) | Qt::Key_Minus; | 0 |
613 | if (userKey != sequenceKey) evaluated: userKey != sequenceKey yes Evaluation Count:156 | yes Evaluation Count:223 |
| 156-223 |
614 | return QKeySequence::NoMatch; executed: return QKeySequence::NoMatch; Execution Count:156 | 156 |
615 | } executed: } Execution Count:223 | 223 |
616 | return match; executed: return match; Execution Count:219 | 219 |
617 | } | - |
618 | | - |
619 | | - |
620 | /*! \internal | - |
621 | Converts keyboard button states into modifier states | - |
622 | */ | - |
623 | int QShortcutMap::translateModifiers(Qt::KeyboardModifiers modifiers) | - |
624 | { | - |
625 | int result = 0; never executed (the execution status of this line is deduced): int result = 0; | - |
626 | if (modifiers & Qt::ShiftModifier) never evaluated: modifiers & Qt::ShiftModifier | 0 |
627 | result |= Qt::SHIFT; never executed: result |= Qt::SHIFT; | 0 |
628 | if (modifiers & Qt::ControlModifier) never evaluated: modifiers & Qt::ControlModifier | 0 |
629 | result |= Qt::CTRL; never executed: result |= Qt::CTRL; | 0 |
630 | if (modifiers & Qt::MetaModifier) never evaluated: modifiers & Qt::MetaModifier | 0 |
631 | result |= Qt::META; never executed: result |= Qt::META; | 0 |
632 | if (modifiers & Qt::AltModifier) never evaluated: modifiers & Qt::AltModifier | 0 |
633 | result |= Qt::ALT; never executed: result |= Qt::ALT; | 0 |
634 | return result; never executed: return result; | 0 |
635 | } | - |
636 | | - |
637 | /*! \internal | - |
638 | Returns the vector of QShortcutEntry's matching the last Identical state. | - |
639 | */ | - |
640 | QVector<const QShortcutEntry*> QShortcutMap::matches() const | - |
641 | { | - |
642 | Q_D(const QShortcutMap); never executed (the execution status of this line is deduced): const QShortcutMapPrivate * const d = d_func(); | - |
643 | return d->identicals; never executed: return d->identicals; | 0 |
644 | } | - |
645 | | - |
646 | /*! \internal | - |
647 | Dispatches QShortcutEvents to widgets who grabbed the matched key sequence. | - |
648 | */ | - |
649 | void QShortcutMap::dispatchEvent(QKeyEvent *e) | - |
650 | { | - |
651 | Q_D(QShortcutMap); executed (the execution status of this line is deduced): QShortcutMapPrivate * const d = d_func(); | - |
652 | if (!d->identicals.size()) evaluated: !d->identicals.size() yes Evaluation Count:3 | yes Evaluation Count:112 |
| 3-112 |
653 | return; executed: return; Execution Count:3 | 3 |
654 | | - |
655 | const QKeySequence &curKey = d->identicals.at(0)->keyseq; executed (the execution status of this line is deduced): const QKeySequence &curKey = d->identicals.at(0)->keyseq; | - |
656 | if (d->prevSequence != curKey) { evaluated: d->prevSequence != curKey yes Evaluation Count:86 | yes Evaluation Count:26 |
| 26-86 |
657 | d->ambigCount = 0; executed (the execution status of this line is deduced): d->ambigCount = 0; | - |
658 | d->prevSequence = curKey; executed (the execution status of this line is deduced): d->prevSequence = curKey; | - |
659 | } executed: } Execution Count:86 | 86 |
660 | // Find next | - |
661 | const QShortcutEntry *current = 0, *next = 0; executed (the execution status of this line is deduced): const QShortcutEntry *current = 0, *next = 0; | - |
662 | int i = 0, enabledShortcuts = 0; executed (the execution status of this line is deduced): int i = 0, enabledShortcuts = 0; | - |
663 | while(i < d->identicals.size()) { evaluated: i < d->identicals.size() yes Evaluation Count:146 | yes Evaluation Count:97 |
| 97-146 |
664 | current = d->identicals.at(i); executed (the execution status of this line is deduced): current = d->identicals.at(i); | - |
665 | if (current->enabled || !next){ partially evaluated: current->enabled yes Evaluation Count:146 | no Evaluation Count:0 |
never evaluated: !next | 0-146 |
666 | ++enabledShortcuts; executed (the execution status of this line is deduced): ++enabledShortcuts; | - |
667 | if (enabledShortcuts > d->ambigCount + 1) evaluated: enabledShortcuts > d->ambigCount + 1 yes Evaluation Count:15 | yes Evaluation Count:131 |
| 15-131 |
668 | break; executed: break; Execution Count:15 | 15 |
669 | next = current; executed (the execution status of this line is deduced): next = current; | - |
670 | } executed: } Execution Count:131 | 131 |
671 | ++i; executed (the execution status of this line is deduced): ++i; | - |
672 | } executed: } Execution Count:131 | 131 |
673 | d->ambigCount = (d->identicals.size() == i ? 0 : d->ambigCount + 1); evaluated: d->identicals.size() == i yes Evaluation Count:97 | yes Evaluation Count:15 |
| 15-97 |
674 | // Don't trigger shortcut if we're autorepeating and the shortcut is | - |
675 | // grabbed with not accepting autorepeats. | - |
676 | if (!next || (e->isAutoRepeat() && !next->autorepeat)) partially evaluated: !next no Evaluation Count:0 | yes Evaluation Count:112 |
partially evaluated: e->isAutoRepeat() no Evaluation Count:0 | yes Evaluation Count:112 |
never evaluated: !next->autorepeat | 0-112 |
677 | return; | 0 |
678 | // Dispatch next enabled | - |
679 | #if defined(DEBUG_QSHORTCUTMAP) | - |
680 | qDebug().nospace() | - |
681 | << "QShortcutMap::dispatchEvent(): Sending QShortcutEvent(\"" | - |
682 | << next->keyseq.toString() << "\", " << next->id << ", " | - |
683 | << (bool)(enabledShortcuts>1) << ") to object(" << next->owner << ')'; | - |
684 | #endif | - |
685 | QShortcutEvent se(next->keyseq, next->id, enabledShortcuts>1); executed (the execution status of this line is deduced): QShortcutEvent se(next->keyseq, next->id, enabledShortcuts>1); | - |
686 | QCoreApplication::sendEvent(const_cast<QObject *>(next->owner), &se); executed (the execution status of this line is deduced): QCoreApplication::sendEvent(const_cast<QObject *>(next->owner), &se); | - |
687 | } executed: } Execution Count:112 | 112 |
688 | | - |
689 | /* \internal | - |
690 | QShortcutMap dump function, only available when DEBUG_QSHORTCUTMAP is | - |
691 | defined. | - |
692 | */ | - |
693 | #if defined(Dump_QShortcutMap) | - |
694 | void QShortcutMap::dumpMap() const | - |
695 | { | - |
696 | Q_D(const QShortcutMap); | - |
697 | for (int i = 0; i < d->sequences.size(); ++i) | - |
698 | qDebug().nospace() << &(d->sequences.at(i)); | - |
699 | } | - |
700 | #endif | - |
701 | | - |
702 | QT_END_NAMESPACE | - |
703 | | - |
704 | #endif // QT_NO_SHORTCUT | - |
705 | | - |
| | |