Add groups to the sensors
This commit is contained in:
parent
2fbfd1d458
commit
221cb519a2
6 changed files with 68 additions and 5 deletions
|
|
@ -33,6 +33,29 @@ void SensorStore::load(const QJsonObject& json)
|
|||
}
|
||||
}
|
||||
|
||||
std::vector<QString> SensorStore::allGroups() const
|
||||
{
|
||||
std::vector<QString> groups;
|
||||
for(const Sensor& sensor : sensors_)
|
||||
{
|
||||
if(!sensor.groupName.isEmpty())
|
||||
{
|
||||
bool found = false;
|
||||
for(const QString& group : groups)
|
||||
{
|
||||
if(group == sensor.groupName)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!found)
|
||||
groups.push_back(sensor.groupName);
|
||||
}
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
void SensorStore::sensorGotState(const Sensor& sensor, sensor_update_type_t type)
|
||||
{
|
||||
bool inSensors = false;
|
||||
|
|
@ -48,6 +71,7 @@ void SensorStore::sensorGotState(const Sensor& sensor, sensor_update_type_t type
|
|||
{
|
||||
sensors_[i].name = sensor.name;
|
||||
sensors_[i].hidden = sensor.hidden;
|
||||
sensors_[i].groupName = sensor.groupName;
|
||||
// Also update knownSensors_
|
||||
for(Sensor& known : knownSensors_)
|
||||
{
|
||||
|
|
@ -55,6 +79,7 @@ void SensorStore::sensorGotState(const Sensor& sensor, sensor_update_type_t type
|
|||
{
|
||||
known.name = sensor.name;
|
||||
known.hidden = sensor.hidden;
|
||||
known.groupName = sensor.groupName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -76,6 +101,7 @@ void SensorStore::sensorGotState(const Sensor& sensor, sensor_update_type_t type
|
|||
{
|
||||
newSensor.name = known.name;
|
||||
newSensor.hidden = known.hidden;
|
||||
newSensor.groupName = known.groupName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,17 +37,18 @@ public:
|
|||
uint64_t id;
|
||||
float field;
|
||||
QString name;
|
||||
QString groupName;
|
||||
QDateTime lastSeen;
|
||||
bool hidden;
|
||||
|
||||
Sensor(sensor_type_t typeIn, uint64_t idIn, float fieldIn = 0, QString nameIn = "", bool hiddenIn = false): type(typeIn),
|
||||
id(idIn), field(fieldIn), name(nameIn), hidden(hiddenIn)
|
||||
Sensor(sensor_type_t typeIn, uint64_t idIn, float fieldIn = 0, QString nameIn = "", bool hiddenIn = false, QString groupNameIn = ""): type(typeIn),
|
||||
id(idIn), field(fieldIn), name(nameIn), groupName(groupNameIn), hidden(hiddenIn)
|
||||
{
|
||||
lastSeen = QDateTime::currentDateTime();
|
||||
if(nameIn == "")
|
||||
generateName();
|
||||
}
|
||||
Sensor(QString nameIn = "dummy"): type(TYPE_DUMMY), id(0), field(0), name(nameIn), hidden(false)
|
||||
Sensor(QString nameIn = "dummy"): type(TYPE_DUMMY), id(0), field(0), name(nameIn), groupName(""), hidden(false)
|
||||
{
|
||||
lastSeen = QDateTime::currentDateTime();
|
||||
}
|
||||
|
|
@ -59,6 +60,7 @@ public:
|
|||
lastSeen = QDateTime::fromString(json["LastSeen"].toString(""));
|
||||
hidden = json["Hidden"].toBool(false);
|
||||
name = json["Name"].toString();
|
||||
groupName = json["GroupName"].toString();
|
||||
if(name == "")
|
||||
generateName();
|
||||
}
|
||||
|
|
@ -105,6 +107,7 @@ public:
|
|||
json["Id"] = static_cast<int>(id);
|
||||
json["Field"] = field;
|
||||
json["Name"] = name;
|
||||
json["GroupName"] = groupName;
|
||||
json["LastSeen"] = lastSeen.toString();
|
||||
json["Hidden"] = hidden;
|
||||
json["Unit"] = getUnit();
|
||||
|
|
@ -186,6 +189,7 @@ public:
|
|||
|
||||
void store(QJsonObject& json);
|
||||
void load(const QJsonObject& json);
|
||||
std::vector<QString> allGroups() const;
|
||||
|
||||
public slots:
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ void SensorListWidget::onDoubleClick(const QModelIndex &index)
|
|||
Sensor updatedSensor = sensor;
|
||||
updatedSensor.name = diag.getName();
|
||||
updatedSensor.hidden = diag.getHidden();
|
||||
updatedSensor.groupName = diag.getGroupName();
|
||||
globalSensors.sensorGotState(updatedSensor, SENSOR_UPDATE_USER);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,15 @@ SensorSettingsDialog::SensorSettingsDialog(const Sensor& sensor, QWidget* parent
|
|||
ui->label_idValue->setText(QString::number(sensor.id));
|
||||
ui->lineEdit_Name->setText(sensor.name);
|
||||
ui->checkBox_Hidden->setChecked(sensor.hidden);
|
||||
|
||||
// Populate group dropdown with existing groups
|
||||
std::vector<QString> groups = globalSensors.allGroups();
|
||||
for(const QString& group : groups)
|
||||
{
|
||||
ui->comboBox_Group->addItem(group);
|
||||
}
|
||||
// Set current group (will be empty string if no group)
|
||||
ui->comboBox_Group->setCurrentText(sensor.groupName);
|
||||
}
|
||||
|
||||
SensorSettingsDialog::~SensorSettingsDialog()
|
||||
|
|
@ -23,6 +32,11 @@ QString SensorSettingsDialog::getName() const
|
|||
return ui->lineEdit_Name->text();
|
||||
}
|
||||
|
||||
QString SensorSettingsDialog::getGroupName() const
|
||||
{
|
||||
return ui->comboBox_Group->currentText();
|
||||
}
|
||||
|
||||
bool SensorSettingsDialog::getHidden() const
|
||||
{
|
||||
return ui->checkBox_Hidden->isChecked();
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ public:
|
|||
~SensorSettingsDialog();
|
||||
|
||||
QString getName() const;
|
||||
QString getGroupName() const;
|
||||
bool getHidden() const;
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>150</height>
|
||||
<height>180</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
|
@ -71,6 +71,23 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_Group">
|
||||
<property name="text">
|
||||
<string>Group:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QComboBox" name="comboBox_Group">
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_Hidden">
|
||||
<property name="text">
|
||||
<string>Hidden:</string>
|
||||
|
|
@ -80,7 +97,7 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<item row="4" column="1">
|
||||
<widget class="QCheckBox" name="checkBox_Hidden">
|
||||
<property name="text">
|
||||
<string></string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue