[libinput] Serialize QMatrix4x4 for KConfig

This commit is contained in:
Matt Scheirer 2020-07-24 13:33:35 -04:00 committed by Aleix Pol Gonzalez
parent a719ceab4a
commit e51cefe136

View file

@ -20,9 +20,11 @@
QDBusArgument &operator<<(QDBusArgument &argument, const QMatrix4x4 &matrix) QDBusArgument &operator<<(QDBusArgument &argument, const QMatrix4x4 &matrix)
{ {
argument.beginArray(qMetaTypeId<double>()); argument.beginArray(qMetaTypeId<double>());
for(quint8 row = 0; row < 4; ++row ) for (quint8 row = 0; row < 4; ++row) {
for(quint8 col = 0; col < 4; ++col ) for (quint8 col = 0; col < 4; ++col) {
argument << matrix(row, col); argument << matrix(row, col);
}
}
argument.endArray(); argument.endArray();
return argument; return argument;
} }
@ -30,8 +32,8 @@ QDBusArgument &operator<<(QDBusArgument &argument, const QMatrix4x4 &matrix)
const QDBusArgument &operator>>(const QDBusArgument &argument, QMatrix4x4 &matrix) const QDBusArgument &operator>>(const QDBusArgument &argument, QMatrix4x4 &matrix)
{ {
argument.beginArray(); argument.beginArray();
for(quint8 row = 0; row < 4; ++row ) { for (quint8 row = 0; row < 4; ++row) {
for(quint8 col = 0; col < 4; ++col ) { for (quint8 col = 0; col < 4; ++col) {
double val; double val;
argument >> val; argument >> val;
matrix(row, col) = val; matrix(row, col) = val;
@ -413,8 +415,14 @@ void Device::loadConfiguration()
if(it.value().qMatrix4x4Setter.setter != nullptr) { if(it.value().qMatrix4x4Setter.setter != nullptr) {
auto setter = it.value().qMatrix4x4Setter; auto setter = it.value().qMatrix4x4Setter;
QMatrix4x4 def = setter.defaultValue ? (this->*(setter.defaultValue))() : QMatrix4x4(); QList<float> list = m_config.readEntry(key.constData(), QList<float>());
(this->*(setter.setter))(m_config.readEntry(key.constData(), QVariant(def)).value<QMatrix4x4>()); QMatrix4x4 matrix;
if(list.size() == 16) {
matrix = QMatrix4x4(list.toVector().constData());
} else if(setter.defaultValue) {
matrix = (this->*(setter.defaultValue))();
}
(this->*(setter.setter))(matrix);
} }
}; };
@ -626,7 +634,13 @@ void Device::setCalibrationMatrix(QMatrix4x4 matrix) {
} }
if(setOrientedCalibrationMatrix(m_device, matrix, m_orientation)) { if(setOrientedCalibrationMatrix(m_device, matrix, m_orientation)) {
writeEntry(ConfigKey::Calibration, QVariant(matrix)); QList<float> list;
for (uchar row = 0; row < 4; ++row) {
for (uchar col = 0; col < 4; ++col) {
list << matrix(row,col);
}
}
writeEntry(ConfigKey::Calibration, list);
m_calibrationMatrix = matrix; m_calibrationMatrix = matrix;
Q_EMIT calibrationMatrixChanged(); Q_EMIT calibrationMatrixChanged();
} }