Skip to content

Commit eb7ddab

Browse files
authored
Merge pull request #47 from Shatur95/fix-clang-tidy-warnings
Fix Clang Tidy warnings
2 parents 53745ba + 8584ff1 commit eb7ddab

File tree

4 files changed

+72
-85
lines changed

4 files changed

+72
-85
lines changed

QHotkey/qhotkey.cpp

Lines changed: 46 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Q_LOGGING_CATEGORY(logQHotkey, "QHotkey")
1010

11-
void QHotkey::addGlobalMapping(const QKeySequence &shortcut, const QHotkey::NativeShortcut &nativeShortcut)
11+
void QHotkey::addGlobalMapping(const QKeySequence &shortcut, QHotkey::NativeShortcut nativeShortcut)
1212
{
1313
QMetaObject::invokeMethod(QHotkeyPrivate::instance(), "addMappingInvoked", Qt::QueuedConnection,
1414
Q_ARG(Qt::Key, Qt::Key(shortcut[0] & ~Qt::KeyboardModifierMask)),
@@ -25,14 +25,13 @@ QHotkey::QHotkey(QObject *parent) :
2525
QObject(parent),
2626
_keyCode(Qt::Key_unknown),
2727
_modifiers(Qt::NoModifier),
28-
_nativeShortcut(),
2928
_registered(false)
3029
{}
3130

32-
QHotkey::QHotkey(const QKeySequence &sequence, bool autoRegister, QObject *parent) :
31+
QHotkey::QHotkey(const QKeySequence &shortcut, bool autoRegister, QObject *parent) :
3332
QHotkey(parent)
3433
{
35-
setShortcut(sequence, autoRegister);
34+
setShortcut(shortcut, autoRegister);
3635
}
3736

3837
QHotkey::QHotkey(Qt::Key keyCode, Qt::KeyboardModifiers modifiers, bool autoRegister, QObject *parent) :
@@ -41,7 +40,7 @@ QHotkey::QHotkey(Qt::Key keyCode, Qt::KeyboardModifiers modifiers, bool autoRegi
4140
setShortcut(keyCode, modifiers, autoRegister);
4241
}
4342

44-
QHotkey::QHotkey(const QHotkey::NativeShortcut &shortcut, bool autoRegister, QObject *parent) :
43+
QHotkey::QHotkey(QHotkey::NativeShortcut shortcut, bool autoRegister, QObject *parent) :
4544
QHotkey(parent)
4645
{
4746
setNativeShortcut(shortcut, autoRegister);
@@ -57,8 +56,7 @@ QKeySequence QHotkey::shortcut() const
5756
{
5857
if(_keyCode == Qt::Key_unknown)
5958
return QKeySequence();
60-
else
61-
return QKeySequence(_keyCode | _modifiers);
59+
return QKeySequence(static_cast<int>(_keyCode | _modifiers));
6260
}
6361

6462
Qt::Key QHotkey::keyCode() const
@@ -83,9 +81,9 @@ bool QHotkey::isRegistered() const
8381

8482
bool QHotkey::setShortcut(const QKeySequence &shortcut, bool autoRegister)
8583
{
86-
if(shortcut.isEmpty()) {
84+
if(shortcut.isEmpty())
8785
return resetShortcut();
88-
} else if(shortcut.count() > 1) {
86+
if(shortcut.count() > 1) {
8987
qCWarning(logQHotkey, "Keysequences with multiple shortcuts are not allowed! "
9088
"Only the first shortcut will be used!");
9189
}
@@ -118,15 +116,14 @@ bool QHotkey::setShortcut(Qt::Key keyCode, Qt::KeyboardModifiers modifiers, bool
118116
if(_nativeShortcut.isValid()) {
119117
if(autoRegister)
120118
return QHotkeyPrivate::instance()->addShortcut(this);
121-
else
122-
return true;
123-
} else {
124-
qCWarning(logQHotkey) << "Unable to map shortcut to native keys. Key:" << keyCode << "Modifiers:" << modifiers;
125-
_keyCode = Qt::Key_unknown;
126-
_modifiers = Qt::NoModifier;
127-
_nativeShortcut = NativeShortcut();
128-
return false;
119+
return true;
129120
}
121+
122+
qCWarning(logQHotkey) << "Unable to map shortcut to native keys. Key:" << keyCode << "Modifiers:" << modifiers;
123+
_keyCode = Qt::Key_unknown;
124+
_modifiers = Qt::NoModifier;
125+
_nativeShortcut = NativeShortcut();
126+
return false;
130127
}
131128

132129
bool QHotkey::resetShortcut()
@@ -158,35 +155,32 @@ bool QHotkey::setNativeShortcut(QHotkey::NativeShortcut nativeShortcut, bool aut
158155
_nativeShortcut = nativeShortcut;
159156
if(autoRegister)
160157
return QHotkeyPrivate::instance()->addShortcut(this);
161-
else
162-
return true;
163-
} else {
164-
_keyCode = Qt::Key_unknown;
165-
_modifiers = Qt::NoModifier;
166-
_nativeShortcut = NativeShortcut();
167158
return true;
168-
}
159+
}
160+
161+
_keyCode = Qt::Key_unknown;
162+
_modifiers = Qt::NoModifier;
163+
_nativeShortcut = NativeShortcut();
164+
return true;
169165
}
170166

171167
bool QHotkey::setRegistered(bool registered)
172168
{
173169
if(_registered && !registered)
174170
return QHotkeyPrivate::instance()->removeShortcut(this);
175-
else if(!_registered && registered) {
171+
if(!_registered && registered) {
176172
if(!_nativeShortcut.isValid())
177173
return false;
178-
else
179-
return QHotkeyPrivate::instance()->addShortcut(this);
180-
} else
181-
return true;
174+
return QHotkeyPrivate::instance()->addShortcut(this);
175+
}
176+
return true;
182177
}
183178

184179

185180

186181
// ---------- QHotkeyPrivate implementation ----------
187182

188-
QHotkeyPrivate::QHotkeyPrivate() :
189-
shortcuts()
183+
QHotkeyPrivate::QHotkeyPrivate()
190184
{
191185
Q_ASSERT_X(qApp, Q_FUNC_INFO, "QHotkey requires QCoreApplication to be instantiated");
192186
qApp->eventDispatcher()->installNativeEventFilter(this);
@@ -211,8 +205,8 @@ QHotkey::NativeShortcut QHotkeyPrivate::nativeShortcut(Qt::Key keycode, Qt::Keyb
211205
Q_ARG(Qt::Key, keycode),
212206
Q_ARG(Qt::KeyboardModifiers, modifiers))) {
213207
return QHotkey::NativeShortcut();
214-
} else
215-
return res;
208+
}
209+
return res;
216210
}
217211

218212
bool QHotkeyPrivate::addShortcut(QHotkey *hotkey)
@@ -228,11 +222,11 @@ bool QHotkeyPrivate::addShortcut(QHotkey *hotkey)
228222
Q_RETURN_ARG(bool, res),
229223
Q_ARG(QHotkey*, hotkey))) {
230224
return false;
231-
} else {
232-
if(res)
233-
emit hotkey->registeredChanged(true);
234-
return res;
235225
}
226+
227+
if(res)
228+
emit hotkey->registeredChanged(true);
229+
return res;
236230
}
237231

238232
bool QHotkeyPrivate::removeShortcut(QHotkey *hotkey)
@@ -248,11 +242,11 @@ bool QHotkeyPrivate::removeShortcut(QHotkey *hotkey)
248242
Q_RETURN_ARG(bool, res),
249243
Q_ARG(QHotkey*, hotkey))) {
250244
return false;
251-
} else {
252-
if(res)
253-
emit hotkey->registeredChanged(false);
254-
return res;
255245
}
246+
247+
if(res)
248+
emit hotkey->registeredChanged(false);
249+
return res;
256250
}
257251

258252
void QHotkeyPrivate::activateShortcut(QHotkey::NativeShortcut shortcut)
@@ -269,7 +263,7 @@ void QHotkeyPrivate::releaseShortcut(QHotkey::NativeShortcut shortcut)
269263
signal.invoke(hkey, Qt::QueuedConnection);
270264
}
271265

272-
void QHotkeyPrivate::addMappingInvoked(Qt::Key keycode, Qt::KeyboardModifiers modifiers, const QHotkey::NativeShortcut &nativeShortcut)
266+
void QHotkeyPrivate::addMappingInvoked(Qt::Key keycode, Qt::KeyboardModifiers modifiers, QHotkey::NativeShortcut nativeShortcut)
273267
{
274268
mapping.insert({keycode, modifiers}, nativeShortcut);
275269
}
@@ -302,24 +296,24 @@ bool QHotkeyPrivate::removeShortcutInvoked(QHotkey *hotkey)
302296
if (!unregisterShortcut(shortcut)) {
303297
qCWarning(logQHotkey) << QHotkey::tr("Failed to unregister %1. Error: %2").arg(hotkey->shortcut().toString(), error);
304298
return false;
305-
} else
306-
return true;
307-
} else
299+
}
308300
return true;
301+
}
302+
return true;
309303
}
310304

311305
QHotkey::NativeShortcut QHotkeyPrivate::nativeShortcutInvoked(Qt::Key keycode, Qt::KeyboardModifiers modifiers)
312306
{
313307
if(mapping.contains({keycode, modifiers}))
314308
return mapping.value({keycode, modifiers});
315309

316-
bool ok1, ok2 = false;
310+
bool ok1 = false;
317311
auto k = nativeKeycode(keycode, ok1);
312+
bool ok2 = false;
318313
auto m = nativeModifiers(modifiers, ok2);
319314
if(ok1 && ok2)
320315
return {k, m};
321-
else
322-
return {};
316+
return {};
323317
}
324318

325319

@@ -341,26 +335,26 @@ bool QHotkey::NativeShortcut::isValid() const
341335
return valid;
342336
}
343337

344-
bool QHotkey::NativeShortcut::operator ==(const QHotkey::NativeShortcut &other) const
338+
bool QHotkey::NativeShortcut::operator ==(QHotkey::NativeShortcut other) const
345339
{
346340
return (key == other.key) &&
347341
(modifier == other.modifier) &&
348342
valid == other.valid;
349343
}
350344

351-
bool QHotkey::NativeShortcut::operator !=(const QHotkey::NativeShortcut &other) const
345+
bool QHotkey::NativeShortcut::operator !=(QHotkey::NativeShortcut other) const
352346
{
353347
return (key != other.key) ||
354348
(modifier != other.modifier) ||
355349
valid != other.valid;
356350
}
357351

358-
uint qHash(const QHotkey::NativeShortcut &key)
352+
uint qHash(QHotkey::NativeShortcut key)
359353
{
360354
return qHash(key.key) ^ qHash(key.modifier);
361355
}
362356

363-
uint qHash(const QHotkey::NativeShortcut &key, uint seed)
357+
uint qHash(QHotkey::NativeShortcut key, uint seed)
364358
{
365359
return qHash(key.key, seed) ^ qHash(key.modifier, seed);
366360
}

QHotkey/qhotkey.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ class QHOTKEY_SHARED_EXPORT QHotkey : public QObject
4646
bool isValid() const;
4747

4848
//! Equality operator
49-
bool operator ==(const NativeShortcut &other) const;
49+
bool operator ==(NativeShortcut other) const;
5050
//! Inequality operator
51-
bool operator !=(const NativeShortcut &other) const;
51+
bool operator !=(NativeShortcut other) const;
5252

5353
private:
5454
bool valid;
5555
};
5656

5757
//! Adds a global mapping of a key sequence to a replacement native shortcut
58-
static void addGlobalMapping(const QKeySequence &shortcut, const NativeShortcut &nativeShortcut);
58+
static void addGlobalMapping(const QKeySequence &shortcut, NativeShortcut nativeShortcut);
5959

6060
//! Checks if global shortcuts are supported by the current platform
6161
static bool isPlatformSupported();
@@ -67,8 +67,8 @@ class QHOTKEY_SHARED_EXPORT QHotkey : public QObject
6767
//! Constructs a hotkey with a key and modifiers and optionally registers it
6868
explicit QHotkey(Qt::Key keyCode, Qt::KeyboardModifiers modifiers, bool autoRegister = false, QObject *parent = nullptr);
6969
//! Constructs a hotkey from a native shortcut and optionally registers it
70-
explicit QHotkey(const NativeShortcut &shortcut, bool autoRegister = false, QObject *parent = nullptr);
71-
~QHotkey();
70+
explicit QHotkey(NativeShortcut shortcut, bool autoRegister = false, QObject *parent = nullptr);
71+
~QHotkey() override;
7272

7373
//! @readAcFn{QHotkey::registered}
7474
bool isRegistered() const;
@@ -94,7 +94,7 @@ public slots:
9494
bool resetShortcut();
9595

9696
//! Set this hotkey to a native shortcut
97-
bool setNativeShortcut(NativeShortcut nativeShortcut, bool autoRegister = false);
97+
bool setNativeShortcut(QHotkey::NativeShortcut nativeShortcut, bool autoRegister = false);
9898

9999
signals:
100100
//! Will be emitted if the shortcut is pressed
@@ -114,8 +114,8 @@ public slots:
114114
bool _registered;
115115
};
116116

117-
uint QHOTKEY_SHARED_EXPORT qHash(const QHotkey::NativeShortcut &key);
118-
uint QHOTKEY_SHARED_EXPORT qHash(const QHotkey::NativeShortcut &key, uint seed);
117+
uint QHOTKEY_SHARED_EXPORT qHash(QHotkey::NativeShortcut key);
118+
uint QHOTKEY_SHARED_EXPORT qHash(QHotkey::NativeShortcut key, uint seed);
119119

120120
QHOTKEY_SHARED_EXPORT Q_DECLARE_LOGGING_CATEGORY(logQHotkey)
121121

QHotkey/qhotkey_p.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class QHOTKEY_SHARED_EXPORT QHotkeyPrivate : public QObject, public QAbstractNat
3939
QHash<QPair<Qt::Key, Qt::KeyboardModifiers>, QHotkey::NativeShortcut> mapping;
4040
QMultiHash<QHotkey::NativeShortcut, QHotkey*> shortcuts;
4141

42-
Q_INVOKABLE void addMappingInvoked(Qt::Key keycode, Qt::KeyboardModifiers modifiers, const QHotkey::NativeShortcut &nativeShortcut);
42+
Q_INVOKABLE void addMappingInvoked(Qt::Key keycode, Qt::KeyboardModifiers modifiers, QHotkey::NativeShortcut nativeShortcut);
4343
Q_INVOKABLE bool addShortcutInvoked(QHotkey *hotkey);
4444
Q_INVOKABLE bool removeShortcutInvoked(QHotkey *hotkey);
4545
Q_INVOKABLE QHotkey::NativeShortcut nativeShortcutInvoked(Qt::Key keycode, Qt::KeyboardModifiers modifiers);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy