Commit f54298a2 authored by David Redondo's avatar David Redondo 🏎

Do not insert non existing columns

d->sensors is what we derive columnCount() from, when the sensors are changed
or the model is reset we called beginInsertColumns for each sensor making the
outwards state of the model inconsistent. For example
when setting the sensors to a list of 4 sensors, beginInsertColumns would be
called 4 times, making some outside observers of the model think it would have
8 columns. So we need to initialize sensorInfos to avoid this.
Found when using the model with a QTransposeProxyModel.

(cherry picked from commit 74db33b1)
parent 984148d3
......@@ -361,11 +361,11 @@ void SensorDataModel::onMetaDataChanged(const QString &sensorId, const SensorInf
void SensorDataModel::onValueChanged(const QString &sensorId, const QVariant &value)
if (!d->sensorData.contains(sensorId) || !d->enabled) {
const auto column = d->sensors.indexOf(sensorId);
if (column == -1 || !d->enabled) {
auto column = d->sensors.indexOf(sensorId);
d->sensorData[sensorId] = value;
Q_EMIT dataChanged(index(0, column), index(0, column), {Qt::DisplayRole, Value, FormattedValue});
......@@ -382,6 +382,10 @@ void SensorDataModel::Private::sensorsChanged()
sensors = requestedSensors;
for (const auto& sensor : sensors) {
sensorInfos[sensor] = KSysGuard::SensorInfo();
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment