on bionic help sign in
unity8/tests/mocks/Unity/InputInfo/qinputdeviceinfo_mock.cpp
56 lines 1.7 kB history raw
1/*
2 * Copyright 2015 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#include "qinputdeviceinfo_mock_p.h"
19#include <QTimer>
20#include <QDebug>
22QInputDeviceManagerPrivate::QInputDeviceManagerPrivate(QObject *parent) :
23 QObject(parent),
24 currentFilter(QInputDevice::Unknown)
26 QTimer::singleShot(1, this, SIGNAL(ready()));
29QInputDeviceManagerPrivate::~QInputDeviceManagerPrivate()
33QInputDevice *QInputDeviceManagerPrivate::addMockDevice(const QString &devicePath, QInputDevice::InputType type)
35 QInputDevice *inputDevice = new QInputDevice(this);
36 inputDevice->setDevicePath(devicePath);
37 inputDevice->setName("Mock Device " + devicePath);
38 inputDevice->setType(type);
39 deviceMap.insert(devicePath, inputDevice);
40 Q_EMIT deviceAdded(devicePath);
41 return inputDevice;
44void QInputDeviceManagerPrivate::removeDevice(const QString &path)
46 auto it = deviceMap.begin();
47 while (it != deviceMap.end()) {
48 const QString devicePath = it.key();
49 if (devicePath.contains(path)) {
50 it = deviceMap.erase(it);
51 Q_EMIT deviceRemoved(devicePath);
52 } else {
53 ++it;
54 }
55 }