1/****************************************************************************
3** Copyright (C) 2015 Jolla.
4** Contact: http://www.qt-project.org/legal
6** This file is part of the QtSystems module of the Qt Toolkit.
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Digia. For licensing terms and
14** conditions see http://qt.digia.com/licensing. For further information
15** use the contact form at http://qt.digia.com/contact-us.
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25** In addition, as a special exception, Digia gives you certain additional
26** rights. These rights are described in the Digia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
40****************************************************************************/
41#include "qdeclarativeinputdeviceinfo_p.h"
43QDeclarativeInputDeviceInfo::QDeclarativeInputDeviceInfo(QObject *parent) :
44 QAbstractListModel(parent),
45 deviceInfo(new QInputDeviceInfo)
47 connect(deviceInfo, &QInputDeviceInfo::ready, this, &QDeclarativeInputDeviceInfo::updateDeviceList);
48 connect(deviceInfo, &QInputDeviceInfo::deviceAdded,this,&QDeclarativeInputDeviceInfo::addedDevice);
49 connect(deviceInfo, &QInputDeviceInfo::deviceRemoved,this,&QDeclarativeInputDeviceInfo::removedDevice);
52QDeclarativeInputDeviceInfo::~QDeclarativeInputDeviceInfo()
57QVariant QDeclarativeInputDeviceInfo::data(const QModelIndex &index, int role) const
61 return QVariant::fromValue(static_cast<QObject *>(inputDevices.value(index.row())));
67int QDeclarativeInputDeviceInfo::rowCount(const QModelIndex &parent) const
71 return inputDevices.count();
74int QDeclarativeInputDeviceInfo::indexOf(const QString &devicePath) const
77 Q_FOREACH (QInputDevice *device, inputDevices) {
79 if (device->devicePath() == devicePath) return idx;
85QInputDevice *QDeclarativeInputDeviceInfo::get(int index) const
87 if (index < 0 || index > inputDevices.count())
89 return inputDevices.value(index);
92void QDeclarativeInputDeviceInfo::updateDeviceList()
94 QVector <QInputDevice *> newDevices = deviceInfo->deviceList();
96 int numNew = newDevices.count();
98 for (int i = 0; i < numNew; i++) {
99 int j = inputDevices.indexOf(newDevices.value(i));
101 // not found -> remove from list
102 beginInsertRows(QModelIndex(), i, i);
103 inputDevices.insert(i, newDevices.value(i));
106 // changed its position -> move it
107 QInputDevice* device = inputDevices.value(j);
108 beginMoveRows(QModelIndex(), j, j, QModelIndex(), i);
109 inputDevices.remove(j);
110 inputDevices.insert(i, device);
113 QModelIndex changedIndex(this->index(j, 0, QModelIndex()));
114 Q_EMIT dataChanged(changedIndex, changedIndex);
118 int numOld = inputDevices.count();
119 if (numOld > numNew) {
120 beginRemoveRows(QModelIndex(), numNew, numOld - 1);
121 inputDevices.remove(numNew, numOld - numNew);
126void QDeclarativeInputDeviceInfo::addedDevice(const QString &devicePath)
129 Q_EMIT newDevice(devicePath);
132void QDeclarativeInputDeviceInfo::removedDevice(const QString &devicePath)
135 Q_EMIT deviceRemoved(devicePath);
138QHash<int, QByteArray> QDeclarativeInputDeviceInfo::roleNames() const
140 QHash<int, QByteArray> roles;
141 roles.insert(ServiceRole, "service");
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list