QEvdev: Extract Method updateDeviceCount()
The code is noisy and repeats, so wrap it in a function. Change-Id: I5e6e924e22b0bc631eb8176de96c49066b1c9029 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
parent
d6cd1a3c2b
commit
3f5d27bfda
|
|
@ -109,8 +109,7 @@ void QEvdevKeyboardManager::addKeyboard(const QString &deviceNode)
|
|||
keyboard = QEvdevKeyboardHandler::create(deviceNode, m_spec, m_defaultKeymapFile);
|
||||
if (keyboard) {
|
||||
m_keyboards.insert(deviceNode, keyboard);
|
||||
QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount(
|
||||
QInputDeviceManager::DeviceTypeKeyboard, m_keyboards.count());
|
||||
updateDeviceCount();
|
||||
} else {
|
||||
qWarning("Failed to open keyboard device %ls", qUtf16Printable(deviceNode));
|
||||
}
|
||||
|
|
@ -122,12 +121,17 @@ void QEvdevKeyboardManager::removeKeyboard(const QString &deviceNode)
|
|||
qCDebug(qLcEvdevKey, "Removing keyboard at %ls", qUtf16Printable(deviceNode));
|
||||
QEvdevKeyboardHandler *keyboard = m_keyboards.value(deviceNode);
|
||||
m_keyboards.remove(deviceNode);
|
||||
QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount(
|
||||
QInputDeviceManager::DeviceTypeKeyboard, m_keyboards.count());
|
||||
updateDeviceCount();
|
||||
delete keyboard;
|
||||
}
|
||||
}
|
||||
|
||||
void QEvdevKeyboardManager::updateDeviceCount()
|
||||
{
|
||||
QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount(
|
||||
QInputDeviceManager::DeviceTypeKeyboard, m_keyboards.count());
|
||||
}
|
||||
|
||||
void QEvdevKeyboardManager::loadKeymap(const QString &file)
|
||||
{
|
||||
m_defaultKeymapFile = file;
|
||||
|
|
|
|||
|
|
@ -74,6 +74,8 @@ public:
|
|||
void removeKeyboard(const QString &deviceNode);
|
||||
|
||||
private:
|
||||
void updateDeviceCount();
|
||||
|
||||
QString m_spec;
|
||||
QHash<QString,QEvdevKeyboardHandler*> m_keyboards;
|
||||
QDeviceDiscovery *m_deviceDiscovery;
|
||||
|
|
|
|||
|
|
@ -167,8 +167,7 @@ void QEvdevMouseManager::addMouse(const QString &deviceNode)
|
|||
connect(handler, &QEvdevMouseHandler::handleWheelEvent,
|
||||
this, &QEvdevMouseManager::handleWheelEvent);
|
||||
m_mice.insert(deviceNode, handler);
|
||||
QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount(
|
||||
QInputDeviceManager::DeviceTypePointer, m_mice.count());
|
||||
updateDeviceCount();
|
||||
} else {
|
||||
qWarning("evdevmouse: Failed to open mouse device %ls", qUtf16Printable(deviceNode));
|
||||
}
|
||||
|
|
@ -180,10 +179,15 @@ void QEvdevMouseManager::removeMouse(const QString &deviceNode)
|
|||
qCDebug(qLcEvdevMouse, "Removing mouse at %ls", qUtf16Printable(deviceNode));
|
||||
QEvdevMouseHandler *handler = m_mice.value(deviceNode);
|
||||
m_mice.remove(deviceNode);
|
||||
QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount(
|
||||
QInputDeviceManager::DeviceTypePointer, m_mice.count());
|
||||
updateDeviceCount();
|
||||
delete handler;
|
||||
}
|
||||
}
|
||||
|
||||
void QEvdevMouseManager::updateDeviceCount()
|
||||
{
|
||||
QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount(
|
||||
QInputDeviceManager::DeviceTypePointer, m_mice.count());
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ public:
|
|||
|
||||
private:
|
||||
void clampPosition();
|
||||
void updateDeviceCount();
|
||||
|
||||
QString m_spec;
|
||||
QHash<QString,QEvdevMouseHandler*> m_mice;
|
||||
|
|
|
|||
|
|
@ -109,8 +109,7 @@ void QEvdevTabletManager::addDevice(const QString &deviceNode)
|
|||
handler = new QEvdevTabletHandlerThread(deviceNode, m_spec);
|
||||
if (handler) {
|
||||
m_activeDevices.insert(deviceNode, handler);
|
||||
QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount(
|
||||
QInputDeviceManager::DeviceTypeTablet, m_activeDevices.count());
|
||||
updateDeviceCount();
|
||||
} else {
|
||||
qWarning("evdevtablet: Failed to open tablet device %ls", qUtf16Printable(deviceNode));
|
||||
}
|
||||
|
|
@ -122,10 +121,15 @@ void QEvdevTabletManager::removeDevice(const QString &deviceNode)
|
|||
qCDebug(qLcEvdevTablet, "Removing device at %ls", qUtf16Printable(deviceNode));
|
||||
QEvdevTabletHandlerThread *handler = m_activeDevices.value(deviceNode);
|
||||
m_activeDevices.remove(deviceNode);
|
||||
QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount(
|
||||
QInputDeviceManager::DeviceTypeTablet, m_activeDevices.count());
|
||||
updateDeviceCount();
|
||||
delete handler;
|
||||
}
|
||||
}
|
||||
|
||||
void QEvdevTabletManager::updateDeviceCount()
|
||||
{
|
||||
QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount(
|
||||
QInputDeviceManager::DeviceTypeTablet, m_activeDevices.count());
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -70,6 +70,8 @@ public:
|
|||
void removeDevice(const QString &deviceNode);
|
||||
|
||||
private:
|
||||
void updateDeviceCount();
|
||||
|
||||
QString m_spec;
|
||||
QDeviceDiscovery *m_deviceDiscovery;
|
||||
QHash<QString, QEvdevTabletHandlerThread *> m_activeDevices;
|
||||
|
|
|
|||
Loading…
Reference in New Issue