Dont install event filter unless its registered
This commit is contained in:
parent
844c4a28f4
commit
cf92852bb3
@ -62,6 +62,7 @@ GlobalShortcut::GlobalShortcut(QKeySequence shortcut, GlobalShortcutBackend *bac
|
||||
}
|
||||
|
||||
GlobalShortcut::~GlobalShortcut() {
|
||||
|
||||
if (this == initialized_) {
|
||||
QAbstractEventDispatcher::instance()->removeNativeEventFilter(this);
|
||||
initialized_ = nullptr;
|
||||
@ -69,6 +70,7 @@ GlobalShortcut::~GlobalShortcut() {
|
||||
else {
|
||||
unsetShortcut();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool GlobalShortcut::setShortcut(const QKeySequence &shortcut) {
|
||||
|
@ -32,15 +32,16 @@
|
||||
#include "globalshortcutbackend.h"
|
||||
#include "globalshortcut.h"
|
||||
|
||||
GlobalShortcutBackendSystem::GlobalShortcutBackendSystem(GlobalShortcuts *parent) : GlobalShortcutBackend(parent),
|
||||
gshortcut_init_(new GlobalShortcut(this)) {}
|
||||
GlobalShortcutBackendSystem::GlobalShortcutBackendSystem(GlobalShortcuts *parent) : GlobalShortcutBackend(parent), gshortcut_init_(nullptr) {}
|
||||
|
||||
GlobalShortcutBackendSystem::~GlobalShortcutBackendSystem(){}
|
||||
GlobalShortcutBackendSystem::~GlobalShortcutBackendSystem() { DoUnregister(); }
|
||||
|
||||
bool GlobalShortcutBackendSystem::DoRegister() {
|
||||
|
||||
qLog(Debug) << "Registering";
|
||||
|
||||
if (!gshortcut_init_) gshortcut_init_ = new GlobalShortcut(this);
|
||||
|
||||
for (const GlobalShortcuts::Shortcut &shortcut : manager_->shortcuts().values()) {
|
||||
AddShortcut(shortcut.action);
|
||||
}
|
||||
@ -63,8 +64,14 @@ bool GlobalShortcutBackendSystem::AddShortcut(QAction *action) {
|
||||
void GlobalShortcutBackendSystem::DoUnregister() {
|
||||
|
||||
qLog(Debug) << "Unregistering";
|
||||
|
||||
qDeleteAll(shortcuts_);
|
||||
shortcuts_.clear();
|
||||
|
||||
if (gshortcut_init_) {
|
||||
delete gshortcut_init_;
|
||||
gshortcut_init_ = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user