Skip to content

Commit f0799fd

Browse files
committed
Fix Clang Tidy warnings
readability-convert-member-functions-to-static modernize-use-auto readability-else-after-return readability-static-accessed-through-instance readability-inconsistent-declaration-parameter-name
1 parent 53745ba commit f0799fd

File tree

2 files changed

+51
-57
lines changed

2 files changed

+51
-57
lines changed

QHotkey/qhotkey.cpp

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -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) :
@@ -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)
@@ -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

QHotkey/qhotkey_x11.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class QHotkeyPrivateX11 : public QHotkeyPrivate
2222
// QHotkeyPrivate interface
2323
quint32 nativeKeycode(Qt::Key keycode, bool &ok) Q_DECL_OVERRIDE;
2424
quint32 nativeModifiers(Qt::KeyboardModifiers modifiers, bool &ok) Q_DECL_OVERRIDE;
25-
QString getX11String(Qt::Key keycode);
25+
static QString getX11String(Qt::Key keycode);
2626
bool registerShortcut(QHotkey::NativeShortcut shortcut) Q_DECL_OVERRIDE;
2727
bool unregisterShortcut(QHotkey::NativeShortcut shortcut) Q_DECL_OVERRIDE;
2828

@@ -64,7 +64,7 @@ bool QHotkeyPrivateX11::nativeEventFilter(const QByteArray &eventType, void *mes
6464
Q_UNUSED(eventType)
6565
Q_UNUSED(result)
6666

67-
xcb_generic_event_t *genericEvent = static_cast<xcb_generic_event_t *>(message);
67+
auto *genericEvent = static_cast<xcb_generic_event_t *>(message);
6868
if (genericEvent->response_type == XCB_KEY_PRESS) {
6969
xcb_key_press_event_t keyEvent = *static_cast<xcb_key_press_event_t *>(message);
7070
this->prevEvent = keyEvent;
@@ -75,7 +75,7 @@ bool QHotkeyPrivateX11::nativeEventFilter(const QByteArray &eventType, void *mes
7575
} else if (genericEvent->response_type == XCB_KEY_RELEASE) {
7676
xcb_key_release_event_t keyEvent = *static_cast<xcb_key_release_event_t *>(message);
7777
this->prevEvent = keyEvent;
78-
QTimer *timer = new QTimer(this);
78+
auto *timer = new QTimer(this);
7979
timer->setSingleShot(true);
8080
timer->setInterval(50);
8181
connect(timer, &QTimer::timeout, this, [this, keyEvent, timer] {
@@ -132,8 +132,8 @@ quint32 QHotkeyPrivateX11::nativeKeycode(Qt::Key keycode, bool &ok)
132132
if(res != 0)
133133
ok = true;
134134
return res;
135-
} else
136-
return 0;
135+
}
136+
return 0;
137137
}
138138

139139
quint32 QHotkeyPrivateX11::nativeModifiers(Qt::KeyboardModifiers modifiers, bool &ok)
@@ -173,8 +173,8 @@ bool QHotkeyPrivateX11::registerShortcut(QHotkey::NativeShortcut shortcut)
173173
error = errorHandler.errorString;
174174
this->unregisterShortcut(shortcut);
175175
return false;
176-
} else
177-
return true;
176+
}
177+
return true;
178178
}
179179

180180
bool QHotkeyPrivateX11::unregisterShortcut(QHotkey::NativeShortcut shortcut)
@@ -188,15 +188,15 @@ bool QHotkeyPrivateX11::unregisterShortcut(QHotkey::NativeShortcut shortcut)
188188
XUngrabKey(display,
189189
shortcut.key,
190190
shortcut.modifier | specialMod,
191-
DefaultRootWindow(display));
191+
XDefaultRootWindow(display));
192192
}
193193
XSync(display, False);
194194

195-
if(errorHandler.hasError) {
196-
error = errorHandler.errorString;
195+
if(HotkeyErrorHandler::hasError) {
196+
error = HotkeyErrorHandler::errorString;
197197
return false;
198-
} else
199-
return true;
198+
}
199+
return true;
200200
}
201201

202202
QString QHotkeyPrivateX11::formatX11Error(Display *display, int errorCode)

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