| 1 | // Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include "qgenericinputdevice_p.h" |
| 5 | |
| 6 | #include <Qt3DInput/private/qabstractphysicaldevice_p.h> |
| 7 | |
| 8 | QT_BEGIN_NAMESPACE |
| 9 | |
| 10 | namespace Qt3DInput { |
| 11 | |
| 12 | |
| 13 | QGenericInputDevice::QGenericInputDevice(Qt3DCore::QNode *parent) |
| 14 | : QAbstractPhysicalDevice(parent) |
| 15 | {} |
| 16 | |
| 17 | static void setHashFromVariantMap(QHash<QString, int> &hash, const QVariantMap &map) |
| 18 | { |
| 19 | hash.clear(); |
| 20 | for (QVariantMap::const_iterator it = map.cbegin(); it != map.cend(); ++it) { |
| 21 | bool ok; |
| 22 | int value = it.value().toInt(ok: &ok); |
| 23 | if (ok) |
| 24 | hash[it.key()] = value; |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | static QVariantMap hash2VariantMap(const QHash<QString, int> &hash) |
| 29 | { |
| 30 | QVariantMap ret; |
| 31 | for (QHash<QString, int>::const_iterator it = hash.cbegin(); it != hash.cend(); ++it) |
| 32 | ret[it.key()] = it.value(); |
| 33 | return ret; |
| 34 | } |
| 35 | |
| 36 | QVariantMap QGenericInputDevice::axesMap() const |
| 37 | { |
| 38 | Q_D(const QAbstractPhysicalDevice); |
| 39 | return hash2VariantMap(hash: d->m_axesHash); |
| 40 | } |
| 41 | |
| 42 | void QGenericInputDevice::setAxesMap(const QVariantMap &axesMap) |
| 43 | { |
| 44 | Q_D(QAbstractPhysicalDevice); |
| 45 | setHashFromVariantMap(hash&: d->m_axesHash, map: axesMap); |
| 46 | emit axesMapChanged(); |
| 47 | } |
| 48 | |
| 49 | QVariantMap QGenericInputDevice::buttonsMap() const |
| 50 | { |
| 51 | Q_D(const QAbstractPhysicalDevice); |
| 52 | return hash2VariantMap(hash: d->m_buttonsHash); |
| 53 | } |
| 54 | |
| 55 | void QGenericInputDevice::setButtonsMap(const QVariantMap &buttonsMap) |
| 56 | { |
| 57 | Q_D(QAbstractPhysicalDevice); |
| 58 | setHashFromVariantMap(hash&: d->m_buttonsHash, map: buttonsMap); |
| 59 | emit axesMapChanged(); |
| 60 | } |
| 61 | |
| 62 | } // Qt3DInput |
| 63 | |
| 64 | QT_END_NAMESPACE |
| 65 | |
| 66 | #include "moc_qgenericinputdevice_p.cpp" |
| 67 |
