qt5base-lts/tests/manual/inputdevices/inputdevicemodel.h
Shawn Rutledge dc7f4f7b4e Add a manual test to show a QTreeView with QInputDevice::devices()
At least on X11 this is a real hierarchy: slave devices come and go
as children of the master devices. The goal is to verify that this tree
and the output of `xinput list` are in sync. The model calls
[begin|end]InsertRows() and [begin|end]RemoveRows() as necessary to
attempt to keep the view updated.

Task-number: QTBUG-46412
Task-number: QTBUG-98720
Task-number: QTBUG-104878
Task-number: QTBUG-112141
Change-Id: I8a2252f041cd1de777eef225d0e7f0db5c90a706
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
2023-03-21 22:00:50 +01:00

56 lines
1.5 KiB
C++

// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef INPUTDEVICEMODEL_H
#define INPUTDEVICEMODEL_H
#include <QAbstractItemModel>
class QInputDevice;
class InputDeviceModel : public QAbstractItemModel
{
Q_OBJECT
public:
enum Role {
Name = Qt::UserRole + 1,
DeviceType,
PointerType,
Capabilities,
SystemId,
SeatName,
AvailableVirtualGeometry,
MaximumPoints,
ButtonCount,
UniqueId,
NRoles
};
Q_ENUM(Role);
explicit InputDeviceModel(QObject *parent = nullptr);
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex &index) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
signals:
void deviceAdded(const QObject *o);
private slots:
void onDeviceAdded(const QObject *o);
private:
void watchDevice(const QInputDevice *dev) const;
void deviceDestroyed(QObject *o);
mutable QList<const QInputDevice *> m_known;
};
#endif // INPUTDEVICEMODEL_H