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 "qdeclarativeinputdevicemodel_p.h"
42#include "qinputinfo.h"
44QDeclarativeInputDeviceModel::QDeclarativeInputDeviceModel(QObject *parent) :
45 QAbstractListModel(parent),
46 deviceInfo(new QInputDeviceManager),
47 currentFilter(QInputDevice::Unknown)
49 connect(deviceInfo,SIGNAL(ready()),this,SLOT(updateDeviceList()));
50 connect(deviceInfo, &QInputDeviceManager::deviceAdded,this,&QDeclarativeInputDeviceModel::addedDevice);
51 connect(deviceInfo, &QInputDeviceManager::deviceRemoved,this,&QDeclarativeInputDeviceModel::removedDevice);
54QDeclarativeInputDeviceModel::~QDeclarativeInputDeviceModel()
59QVariant QDeclarativeInputDeviceModel::data(const QModelIndex &index, int role) const
63 return QVariant::fromValue(static_cast<QObject *>(inputDevices.value(index.row())));
66 return QVariant::fromValue(static_cast<QString>(inputDevices.value(index.row())->name()));
69 return QVariant::fromValue(static_cast<QString>(inputDevices.value(index.row())->devicePath()));
72 return QVariant::fromValue(static_cast<QList <int> >(inputDevices.value(index.row())->buttons()));
75 return QVariant::fromValue(static_cast<QList <int> >(inputDevices.value(index.row())->switches()));
77 case RelativeAxisRole:
78 return QVariant::fromValue(static_cast<QList <int> >(inputDevices.value(index.row())->relativeAxis()));
80 case AbsoluteAxisRole:
81 return QVariant::fromValue(static_cast<QList <int> >(inputDevices.value(index.row())->absoluteAxis()));
84 return QVariant::fromValue(static_cast<int>(inputDevices.value(index.row())->type()));
91int QDeclarativeInputDeviceModel::rowCount(const QModelIndex &parent) const
95 return inputDevices.count();
98int QDeclarativeInputDeviceModel::indexOf(const QString &devicePath) const
101 Q_FOREACH (QInputDevice *device, inputDevices) {
103 if (device->devicePath() == devicePath) return idx;
109QInputDevice *QDeclarativeInputDeviceModel::get(int index) const
111 if (index < 0 || index > inputDevices.count())
113 return inputDevices.value(index);
116void QDeclarativeInputDeviceModel::updateDeviceList()
118 QVector <QInputDevice *> newDevices = deviceInfo->deviceListOfType(currentFilter);
120 int numNew = newDevices.count();
122 for (int i = 0; i < numNew; i++) {
123 int j = inputDevices.indexOf(newDevices.value(i));
126 beginInsertRows(QModelIndex(), i, i);
127 inputDevices.insert(i, newDevices.value(i));
129 Q_EMIT countChanged();
131 // changed its position -> move it
132 QInputDevice* device = inputDevices.value(j);
133 beginMoveRows(QModelIndex(), j, j, QModelIndex(), i);
134 inputDevices.remove(j);
135 inputDevices.insert(i, device);
137 Q_EMIT countChanged();
139 QModelIndex changedIndex(this->index(j, 0, QModelIndex()));
140 Q_EMIT dataChanged(changedIndex, changedIndex);
143 int numOld = inputDevices.count();
144 if (numOld > numNew) {
145 beginRemoveRows(QModelIndex(), numNew, numOld - 1);
146 inputDevices.remove(numNew, numOld - numNew);
148 Q_EMIT countChanged();
152void QDeclarativeInputDeviceModel::addedDevice(const QString &devicePath)
155 Q_EMIT deviceAdded(devicePath);
158void QDeclarativeInputDeviceModel::removedDevice(const QString &devicePath)
161 Q_EMIT deviceRemoved(devicePath);
164QHash<int,QByteArray> QDeclarativeInputDeviceModel::roleNames() const
166 QHash<int, QByteArray> roles;
167 roles[NameRole] = "name";
168 roles[DevicePathRole] = "devicePath";
169 roles[ButtonsRole] = "buttons";
170 roles[SwitchesRole] = "switches";
171 roles[RelativeAxisRole] = "rAxis";
172 roles[AbsoluteAxisRole] = "aAxis";
173 roles[TypesRole] = "types";
178 * Returns the currently set device filter.
180QInputDevice::InputType QDeclarativeInputDeviceModel::deviceFilter()
182 return currentFilter;
186 * Sets the current input device filter to filter.
188void QDeclarativeInputDeviceModel::setDeviceFilter(QInputDevice::InputType filter)
190 if (filter != currentFilter) {
191 deviceInfo->setDeviceFilter(filter);
192 currentFilter = filter;
194 Q_EMIT deviceFilterChanged(filter);
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