File indexing completed on 2024-05-12 05:35:40
0001 /* 0002 SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com> 0003 SPDX-FileCopyrightText: 2023 Jeremy Whiting <jpwhiting@kde.org> 0004 SPDX-FileCopyrightText: 2023 Niccolò Venerandi <niccolo@venerandi.com> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #pragma once 0010 0011 #include <QList> 0012 #include <QStandardItemModel> 0013 0014 class Gamepad; 0015 0016 class DeviceModel : public QAbstractListModel 0017 { 0018 Q_OBJECT 0019 Q_PROPERTY(int count READ count NOTIFY devicesChanged) 0020 0021 public: 0022 DeviceModel(); 0023 0024 Q_INVOKABLE Gamepad *device(int index) const; 0025 0026 int rowCount(const QModelIndex &parent) const override; 0027 QVariant data(const QModelIndex &index, int role) const override; 0028 0029 int count() const; 0030 0031 Q_SIGNALS: 0032 void devicesChanged(); 0033 0034 private Q_SLOTS: 0035 void poll(); 0036 0037 private: 0038 void addDevice(const int deviceIndex); 0039 void removeDevice(const int deviceIndex); 0040 0041 // Map of sdl indexes to Gamepad devices 0042 QMap<int, Gamepad *> m_devices; 0043 };