2
0
Эх сурвалжийг харах

Added check for duplicate sensors in models

Maldela 9 жил өмнө
parent
commit
30507ef450

+ 17 - 5
import/src/pwmfanmodel.cpp

@@ -51,18 +51,30 @@ void PwmFanModel::setPwmFans(const QList<PwmFan *> &fans)
     setStringList(list);
 }
 
-void PwmFanModel::addPwmFans(const QList<PwmFan *> &fans)
+void PwmFanModel::addPwmFans(QList<PwmFan *> newFans)
 {
-    if (!fans.isEmpty())
+    foreach (const auto &newFan, newFans)
     {
-        m_fans += fans;
+        foreach (const auto &fan, m_fans)
+        {
+            if (*fan == *newFan)
+            {
+                newFans.removeAll(newFan);
+                break;
+            }
+        }
+    }
+
+    if (!newFans.isEmpty())
+    {
+        m_fans += newFans;
         emit fansChanged();
 
         const auto oldSize = rowCount();
 
-        insertRows(oldSize, fans.size());
+        insertRows(oldSize, newFans.size());
 
-        foreach (const auto &fan, fans)
+        foreach (const auto &fan, newFans)
         {
             connect(fan, &PwmFan::nameChanged, this, static_cast<void(PwmFanModel::*)()>(&PwmFanModel::updateFan));
             updateFan(fan);

+ 1 - 1
import/src/pwmfanmodel.h

@@ -42,7 +42,7 @@ public:
 
     PwmFanModel(QObject *parent = Q_NULLPTR);
     void setPwmFans(const QList<PwmFan *> &fans);
-    void addPwmFans(const QList<PwmFan *> &fans);
+    void addPwmFans(QList<PwmFan *> newFans);
     QList<QObject *> fans() const;
 
 

+ 3 - 0
import/src/sensor.h

@@ -49,6 +49,9 @@ public:
     Hwmon * parent() const { return m_parent; }
     uint index() const { return m_index; }
 
+    bool operator==(const Sensor &other) { return m_path == other.path(); }
+    bool operator!=(const Sensor &other) { return m_path != other.path(); }
+
 
 public slots:
 

+ 19 - 6
import/src/tempmodel.cpp

@@ -46,7 +46,7 @@ void TempModel::setTemps(const QList<Temp *> &temps)
     m_temps = temps;
     emit tempsChanged();
 
-    auto list = QStringList();
+    QStringList list;
 
     foreach (const auto &temp, temps)
     {
@@ -58,18 +58,31 @@ void TempModel::setTemps(const QList<Temp *> &temps)
     setStringList(list);
 }
 
-void TempModel::addTemps(const QList<Temp *> &temps)
+void TempModel::addTemps(QList<Temp *> newTemps)
 {
-    if (!temps.isEmpty())
+
+    foreach (const auto &newTemp, newTemps)
+    {
+        foreach (const auto &temp, m_temps)
+        {
+            if (*temp == *newTemp)
+            {
+                newTemps.removeAll(newTemp);
+                break;
+            }
+        }
+    }
+
+    if (!newTemps.isEmpty())
     {
-        m_temps += temps;
+        m_temps += newTemps;
         emit tempsChanged();
 
         const auto oldSize = rowCount();
 
-        insertRows(oldSize, temps.size());
+        insertRows(oldSize, newTemps.size());
 
-        foreach (const auto &temp, temps)
+        foreach (const auto &temp, newTemps)
         {
             connect(temp, &Temp::nameChanged, this, static_cast<void(TempModel::*)()>(&TempModel::updateTemp));
             connect(temp, &Temp::valueChanged, this, static_cast<void(TempModel::*)()>(&TempModel::updateTemp));

+ 1 - 1
import/src/tempmodel.h

@@ -43,7 +43,7 @@ public:
 
     TempModel(QObject *parent = Q_NULLPTR);
     void setTemps(const QList<Temp *> &temps);
-    void addTemps(const QList<Temp *> &temps);
+    void addTemps(QList<Temp *> newTemps);
     QList<QObject *> temps() const;