Use a generic mechanism to watch input device properties
This reduces code duplication and provides a generic way to monitor all relevant input device properties.
This commit is contained in:
parent
f15e6806f3
commit
9adb5eed02
2 changed files with 23 additions and 20 deletions
|
@ -1591,29 +1591,29 @@ QModelIndex InputDeviceModel::parent(const QModelIndex &child) const
|
|||
return QModelIndex();
|
||||
}
|
||||
|
||||
void InputDeviceModel::slotPropertyChanged()
|
||||
{
|
||||
const auto device = static_cast<LibInput::Device *>(sender());
|
||||
|
||||
for (int i = 0; i < device->metaObject()->propertyCount(); ++i) {
|
||||
const QMetaProperty metaProperty = device->metaObject()->property(i);
|
||||
if (metaProperty.notifySignalIndex() == senderSignalIndex()) {
|
||||
const QModelIndex parent = index(m_devices.indexOf(device), 0, QModelIndex());
|
||||
const QModelIndex child = index(i, 1, parent);
|
||||
Q_EMIT dataChanged(child, child, QVector<int>{Qt::DisplayRole});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InputDeviceModel::setupDeviceConnections(LibInput::Device *device)
|
||||
{
|
||||
connect(device, &LibInput::Device::enabledChanged, this,
|
||||
[this, device] {
|
||||
const QModelIndex parent = index(m_devices.indexOf(device), 0, QModelIndex());
|
||||
const QModelIndex child = index(device->metaObject()->indexOfProperty("enabled"), 1, parent);
|
||||
Q_EMIT dataChanged(child, child, QVector<int>{Qt::DisplayRole});
|
||||
QMetaMethod handler = metaObject()->method(metaObject()->indexOfMethod("slotPropertyChanged()"));
|
||||
for (int i = 0; i < device->metaObject()->propertyCount(); ++i) {
|
||||
const QMetaProperty metaProperty = device->metaObject()->property(i);
|
||||
if (metaProperty.hasNotifySignal()) {
|
||||
connect(device, metaProperty.notifySignal(), this, handler);
|
||||
}
|
||||
);
|
||||
connect(device, &LibInput::Device::leftHandedChanged, this,
|
||||
[this, device] {
|
||||
const QModelIndex parent = index(m_devices.indexOf(device), 0, QModelIndex());
|
||||
const QModelIndex child = index(device->metaObject()->indexOfProperty("leftHanded"), 1, parent);
|
||||
Q_EMIT dataChanged(child, child, QVector<int>{Qt::DisplayRole});
|
||||
}
|
||||
);
|
||||
connect(device, &LibInput::Device::pointerAccelerationChanged, this,
|
||||
[this, device] {
|
||||
const QModelIndex parent = index(m_devices.indexOf(device), 0, QModelIndex());
|
||||
const QModelIndex child = index(device->metaObject()->indexOfProperty("pointerAcceleration"), 1, parent);
|
||||
Q_EMIT dataChanged(child, child, QVector<int>{Qt::DisplayRole});
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex DataSourceModel::index(int row, int column, const QModelIndex &parent) const
|
||||
|
|
|
@ -181,6 +181,9 @@ public:
|
|||
int rowCount(const QModelIndex &parent) const override;
|
||||
QModelIndex parent(const QModelIndex &child) const override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void slotPropertyChanged();
|
||||
|
||||
private:
|
||||
void setupDeviceConnections(LibInput::Device *device);
|
||||
QVector<LibInput::Device*> m_devices;
|
||||
|
|
Loading…
Reference in a new issue