UI: save and restore ui settings in primary and secondary uis

This commit is contained in:
Carl Philipp Klemm 2026-04-26 17:28:57 +02:00
parent afb2d23173
commit 51193a5d0b
7 changed files with 132 additions and 4 deletions

View file

@ -4,6 +4,8 @@
#include <QHeaderView>
#include <QScroller>
#include <QMap>
#include <QJsonObject>
#include <QJsonArray>
#include "sensorsettingsdialog.h"
@ -13,8 +15,8 @@ SensorListWidget::SensorListWidget(const bool showHidden, QWidget *parent): QTre
setColumnCount(3);
setHeaderLabels({"Sensor", "Value", "Time"});
setSelectionBehavior(QAbstractItemView::SelectRows);
header()->setSectionResizeMode(0, QHeaderView::Interactive);
header()->setSectionResizeMode(1, QHeaderView::Interactive);
header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
QScroller::grabGesture(this, QScroller::LeftMouseButtonGesture);
setAutoScroll(true);
@ -120,7 +122,12 @@ void SensorListWidget::sensorsChanged(std::vector<Sensor> sensors)
{
groupItem = new QTreeWidgetItem(this);
groupItem->setText(0, sensor.groupName);
bool wasExpanded = expandedStates.value(sensor.groupName, false);
if(!wasExpanded && pendingGroupExpandedStates_.contains(sensor.groupName))
{
wasExpanded = pendingGroupExpandedStates_[sensor.groupName];
}
groupItem->setExpanded(wasExpanded);
groupItems[sensor.groupName] = groupItem;
}
@ -162,6 +169,36 @@ void SensorListWidget::setShowHidden(const bool showHidden)
sensorsChanged(*globalSensors.getSensors());
}
void SensorListWidget::store(QJsonObject& json) const
{
QJsonObject sensorListJson;
QJsonObject groupStates;
for(int i = 0; i < topLevelItemCount(); ++i)
{
QTreeWidgetItem* item = topLevelItem(i);
if(item->type() != 1001)
{
groupStates[item->text(0)] = item->isExpanded();
}
}
sensorListJson["GroupStates"] = groupStates;
json["SensorList"] = sensorListJson;
}
void SensorListWidget::load(const QJsonObject& json)
{
QJsonObject sensorListJson = json["SensorList"].toObject();
QJsonObject groupStates = sensorListJson["GroupStates"].toObject();
pendingGroupExpandedStates_.clear();
for(auto it = groupStates.begin(); it != groupStates.end(); ++it)
{
pendingGroupExpandedStates_[it.key()] = it.value().toBool();
}
}
const Sensor& SensorListItem::getSensor()
{
return sensor;