@@ -1,173 +0,0 @@
1−/****************************************************************************
3−** Copyright (C) 2015 Jolla.
4−** Copyright (C) 2015 Canonical Ltd.
5−** Contact: http://www.qt-project.org/legal
7−** This file is part of the QtSystems module of the Qt Toolkit.
9−** $QT_BEGIN_LICENSE:LGPL$
10−** Commercial License Usage
11−** Licensees holding valid commercial Qt licenses may use this file in
12−** accordance with the commercial license agreement provided with the
13−** Software or, alternatively, in accordance with the terms contained in
14−** a written agreement between you and Digia. For licensing terms and
15−** conditions see http://qt.digia.com/licensing. For further information
16−** use the contact form at http://qt.digia.com/contact-us.
18−** GNU Lesser General Public License Usage
19−** Alternatively, this file may be used under the terms of the GNU Lesser
20−** General Public License version 2.1 as published by the Free Software
21−** Foundation and appearing in the file LICENSE.LGPL included in the
22−** packaging of this file. Please review the following information to
23−** ensure the GNU Lesser General Public License version 2.1 requirements
24−** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
26−** In addition, as a special exception, Digia gives you certain additional
27−** rights. These rights are described in the Digia Qt LGPL Exception
28−** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
30−** GNU General Public License Usage
31−** Alternatively, this file may be used under the terms of the GNU
32−** General Public License version 3.0 as published by the Free Software
33−** Foundation and appearing in the file LICENSE.GPL included in the
34−** packaging of this file. Please review the following information to
35−** ensure the GNU General Public License version 3.0 requirements will be
36−** met: http://www.gnu.org/copyleft/gpl.html.
41−****************************************************************************/
42−#include "mockqdeclarativeinputdeviceinfo_p.h"
44−QDeclarativeInputDeviceInfo::QDeclarativeInputDeviceInfo(QObject *parent) :
45− QAbstractListModel(parent),
46− deviceInfo(new QInputDeviceInfo)
48− connect(deviceInfo, &QInputDeviceInfo::deviceAdded,this,&QDeclarativeInputDeviceInfo::addedDevice);
49− connect(deviceInfo, &QInputDeviceInfo::deviceRemoved,this,&QDeclarativeInputDeviceInfo::removedDevice);
52−QDeclarativeInputDeviceInfo::~QDeclarativeInputDeviceInfo()
57−QVariant QDeclarativeInputDeviceInfo::data(const QModelIndex &index, int role) const
61− return QVariant::fromValue(static_cast<QObject *>(inputDevices.value(index.row())));
67−int QDeclarativeInputDeviceInfo::rowCount(const QModelIndex &parent) const
71− return inputDevices.count();
74−int QDeclarativeInputDeviceInfo::indexOf(const QString &devicePath) const
77− Q_FOREACH (QInputDevice *device, inputDevices) {
79− if (device->devicePath() == devicePath) return idx;
85−QInputDevice *QDeclarativeInputDeviceInfo::get(int index) const
87− if (index < 0 || index > inputDevices.count())
89− return inputDevices.value(index);
92−void QDeclarativeInputDeviceInfo::addMockMouse()
94− deviceInfo->addMockDevice(QInputDeviceInfo::Mouse);
97−void QDeclarativeInputDeviceInfo::addMockKeyboard()
99− deviceInfo->addMockDevice(QInputDeviceInfo::Keyboard);
102−void QDeclarativeInputDeviceInfo::removeMockMouse()
104− for (int i = 0; i < inputDevices.count(); i++) {
105− if (inputDevices.at(i)->types().testFlag(QInputDeviceInfo::Mouse)) {
106− deviceInfo->removeMockDevice(i);
112−void QDeclarativeInputDeviceInfo::removeMockKeyboard()
114− for (int i = 0; i < inputDevices.count(); i++) {
115− if (inputDevices.at(i)->types().testFlag(QInputDeviceInfo::Keyboard)) {
116− deviceInfo->removeMockDevice(i);
122−void QDeclarativeInputDeviceInfo::updateDeviceList()
124− QVector <QInputDevice *> newDevices = deviceInfo->deviceList();
126− int numNew = newDevices.count();
128− for (int i = 0; i < numNew; i++) {
129− int j = inputDevices.indexOf(newDevices.value(i));
131− // not found -> remove from list
132− beginInsertRows(QModelIndex(), i, i);
133− inputDevices.insert(i, newDevices.value(i));
135− } else if (i != j) {
136− // changed its position -> move it
137− QInputDevice* device = inputDevices.value(j);
138− beginMoveRows(QModelIndex(), j, j, QModelIndex(), i);
139− inputDevices.remove(j);
140− inputDevices.insert(i, device);
143− QModelIndex changedIndex(this->index(j, 0, QModelIndex()));
144− Q_EMIT dataChanged(changedIndex, changedIndex);
148− int numOld = inputDevices.count();
149− if (numOld > numNew) {
150− beginRemoveRows(QModelIndex(), numNew, numOld - 1);
151− inputDevices.remove(numNew, numOld - numNew);
156−void QDeclarativeInputDeviceInfo::addedDevice(const QString &devicePath)
159− Q_EMIT newDevice(devicePath);
162−void QDeclarativeInputDeviceInfo::removedDevice(const QString &devicePath)
165− Q_EMIT deviceRemoved(devicePath);
168−QHash<int, QByteArray> QDeclarativeInputDeviceInfo::roleNames() const
170− QHash<int, QByteArray> roles;
171− roles.insert(ServiceRole, "service");