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)
|
void SensorStore::sensorGotState(const Sensor& sensor, sensor_update_type_t type)
|
||||||
{
|
{
|
||||||
bool inSensors = false;
|
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].name = sensor.name;
|
||||||
sensors_[i].hidden = sensor.hidden;
|
sensors_[i].hidden = sensor.hidden;
|
||||||
|
sensors_[i].groupName = sensor.groupName;
|
||||||
// Also update knownSensors_
|
// Also update knownSensors_
|
||||||
for(Sensor& known : 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.name = sensor.name;
|
||||||
known.hidden = sensor.hidden;
|
known.hidden = sensor.hidden;
|
||||||
|
known.groupName = sensor.groupName;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -76,6 +101,7 @@ void SensorStore::sensorGotState(const Sensor& sensor, sensor_update_type_t type
|
||||||
{
|
{
|
||||||
newSensor.name = known.name;
|
newSensor.name = known.name;
|
||||||
newSensor.hidden = known.hidden;
|
newSensor.hidden = known.hidden;
|
||||||
|
newSensor.groupName = known.groupName;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,17 +37,18 @@ public:
|
||||||
uint64_t id;
|
uint64_t id;
|
||||||
float field;
|
float field;
|
||||||
QString name;
|
QString name;
|
||||||
|
QString groupName;
|
||||||
QDateTime lastSeen;
|
QDateTime lastSeen;
|
||||||
bool hidden;
|
bool hidden;
|
||||||
|
|
||||||
Sensor(sensor_type_t typeIn, uint64_t idIn, float fieldIn = 0, QString nameIn = "", bool hiddenIn = false): type(typeIn),
|
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), hidden(hiddenIn)
|
id(idIn), field(fieldIn), name(nameIn), groupName(groupNameIn), hidden(hiddenIn)
|
||||||
{
|
{
|
||||||
lastSeen = QDateTime::currentDateTime();
|
lastSeen = QDateTime::currentDateTime();
|
||||||
if(nameIn == "")
|
if(nameIn == "")
|
||||||
generateName();
|
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();
|
lastSeen = QDateTime::currentDateTime();
|
||||||
}
|
}
|
||||||
|
|
@ -59,6 +60,7 @@ public:
|
||||||
lastSeen = QDateTime::fromString(json["LastSeen"].toString(""));
|
lastSeen = QDateTime::fromString(json["LastSeen"].toString(""));
|
||||||
hidden = json["Hidden"].toBool(false);
|
hidden = json["Hidden"].toBool(false);
|
||||||
name = json["Name"].toString();
|
name = json["Name"].toString();
|
||||||
|
groupName = json["GroupName"].toString();
|
||||||
if(name == "")
|
if(name == "")
|
||||||
generateName();
|
generateName();
|
||||||
}
|
}
|
||||||
|
|
@ -105,6 +107,7 @@ public:
|
||||||
json["Id"] = static_cast<int>(id);
|
json["Id"] = static_cast<int>(id);
|
||||||
json["Field"] = field;
|
json["Field"] = field;
|
||||||
json["Name"] = name;
|
json["Name"] = name;
|
||||||
|
json["GroupName"] = groupName;
|
||||||
json["LastSeen"] = lastSeen.toString();
|
json["LastSeen"] = lastSeen.toString();
|
||||||
json["Hidden"] = hidden;
|
json["Hidden"] = hidden;
|
||||||
json["Unit"] = getUnit();
|
json["Unit"] = getUnit();
|
||||||
|
|
@ -186,6 +189,7 @@ public:
|
||||||
|
|
||||||
void store(QJsonObject& json);
|
void store(QJsonObject& json);
|
||||||
void load(const QJsonObject& json);
|
void load(const QJsonObject& json);
|
||||||
|
std::vector<QString> allGroups() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ void SensorListWidget::onDoubleClick(const QModelIndex &index)
|
||||||
Sensor updatedSensor = sensor;
|
Sensor updatedSensor = sensor;
|
||||||
updatedSensor.name = diag.getName();
|
updatedSensor.name = diag.getName();
|
||||||
updatedSensor.hidden = diag.getHidden();
|
updatedSensor.hidden = diag.getHidden();
|
||||||
|
updatedSensor.groupName = diag.getGroupName();
|
||||||
globalSensors.sensorGotState(updatedSensor, SENSOR_UPDATE_USER);
|
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->label_idValue->setText(QString::number(sensor.id));
|
||||||
ui->lineEdit_Name->setText(sensor.name);
|
ui->lineEdit_Name->setText(sensor.name);
|
||||||
ui->checkBox_Hidden->setChecked(sensor.hidden);
|
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()
|
SensorSettingsDialog::~SensorSettingsDialog()
|
||||||
|
|
@ -23,6 +32,11 @@ QString SensorSettingsDialog::getName() const
|
||||||
return ui->lineEdit_Name->text();
|
return ui->lineEdit_Name->text();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString SensorSettingsDialog::getGroupName() const
|
||||||
|
{
|
||||||
|
return ui->comboBox_Group->currentText();
|
||||||
|
}
|
||||||
|
|
||||||
bool SensorSettingsDialog::getHidden() const
|
bool SensorSettingsDialog::getHidden() const
|
||||||
{
|
{
|
||||||
return ui->checkBox_Hidden->isChecked();
|
return ui->checkBox_Hidden->isChecked();
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ public:
|
||||||
~SensorSettingsDialog();
|
~SensorSettingsDialog();
|
||||||
|
|
||||||
QString getName() const;
|
QString getName() const;
|
||||||
|
QString getGroupName() const;
|
||||||
bool getHidden() const;
|
bool getHidden() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>400</width>
|
<width>400</width>
|
||||||
<height>150</height>
|
<height>180</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
|
@ -71,6 +71,23 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0">
|
<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">
|
<widget class="QLabel" name="label_Hidden">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Hidden:</string>
|
<string>Hidden:</string>
|
||||||
|
|
@ -80,7 +97,7 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="1">
|
<item row="4" column="1">
|
||||||
<widget class="QCheckBox" name="checkBox_Hidden">
|
<widget class="QCheckBox" name="checkBox_Hidden">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string></string>
|
<string></string>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue