Fix incorrect sensor selection due to reorder sensors in SensorListWidget

This commit is contained in:
Carl Philipp Klemm 2025-10-05 23:29:23 +02:00
parent 271330d5fd
commit 0c5603ca44
7 changed files with 47 additions and 15 deletions

View file

@ -56,7 +56,7 @@ void SensorListWidget::sensorsChanged(std::vector<Sensor> sensors)
else itemString.append("\"Silent\"");
}
setItem(static_cast<int>(row), 0, new QTableWidgetItem(sensors[i].name + (sensors[i].hidden ? " (H)" : "")));
setItem(static_cast<int>(row), 0, new SensorListItem(sensors[i].name + (sensors[i].hidden ? " (H)" : ""), sensors[i]));
setItem(static_cast<int>(row), 1, new QTableWidgetItem(itemString));
if(sensors[i].type <= 128)
setItem(static_cast<int>(row), 2, new QTableWidgetItem(sensors[i].lastSeen.time().toString("hh:mm")));
@ -67,8 +67,23 @@ void SensorListWidget::sensorsChanged(std::vector<Sensor> sensors)
resizeColumnsToContents();
}
const Sensor& SensorListWidget::getSensorForIndex(const QModelIndex &index)
{
return static_cast<SensorListItem*>(item(index.row(), 0))->getSensor();
}
void SensorListWidget::setShowHidden(const bool showHidden)
{
showHidden_=showHidden;
}
const Sensor& SensorListItem::getSensor()
{
return sensor;
}
SensorListItem::SensorListItem(const QString& text, const Sensor& sensor):
QTableWidgetItem(text, 1001), sensor(sensor)
{
}