فهرست منبع

improved temp labeling

Malte Veerman 5 سال پیش
والد
کامیت
c67d606760
4فایلهای تغییر یافته به همراه15 افزوده شده و 5 حذف شده
  1. 2 1
      import/src/sensor.cpp
  2. 9 3
      import/src/sensor.h
  3. 3 0
      import/src/temp.cpp
  4. 1 1
      import/src/tempmodel.cpp

+ 2 - 1
import/src/sensor.cpp

@@ -34,7 +34,8 @@ Sensor::Sensor(Hwmon *parent, uint index, const QString &type, bool device) : QO
     if (!parent)
         return;
 
-    m_id = QStringLiteral("hwmon") + parent->index() + "/" + type + QString::number(index);
+    m_id = parent->name() + "/" + type + QString::number(index);
+    m_path = device ? QStringLiteral("hwmon") + QString::number(parent->index()) + "/device/" + type + QString::number(index) : QStringLiteral("hwmon") + QString::number(parent->index()) + "/" + type + QString::number(index);
 
     connect(this, &Sensor::error, parent, &Hwmon::error);
 }

+ 9 - 3
import/src/sensor.h

@@ -47,12 +47,13 @@ public:
     virtual bool isValid() const = 0;
     virtual void update() = 0;
     QString id() const { return m_id; }
+    QString path() const { return m_path; }
     Hwmon * parent() const { return m_parent; }
     uint index() const { return m_index; }
     bool device() const { return m_device; }
 
-    bool operator==(const Sensor &other) { return m_id == other.id(); }
-    bool operator!=(const Sensor &other) { return m_id != other.id(); }
+    bool operator==(const Sensor &other) { return m_path == other.path(); }
+    bool operator!=(const Sensor &other) { return m_path != other.path(); }
 
 
 signals:
@@ -61,11 +62,16 @@ signals:
     void error(QString, bool = false);
 
 
+protected:
+
+    QString m_id;
+
+
 private:
 
     Hwmon *const m_parent;
     const uint m_index;
-    QString m_id;
+    QString m_path;
     bool m_device;
 };
 

+ 3 - 0
import/src/temp.cpp

@@ -68,7 +68,10 @@ Temp::Temp(uint index, Hwmon *parent, bool device) :
         if (labelFile->exists())
         {
             if (labelFile->open(QFile::ReadOnly))
+            {
                 m_label = QTextStream(labelFile).readLine();
+                m_id = parent->name() + "/" + m_label;
+            }
             else
                 emit error(i18n("Can't open label file: \'%1\'", path + "/temp" + QString::number(index) + "_label"));
         }

+ 1 - 1
import/src/tempmodel.cpp

@@ -61,7 +61,7 @@ QVariant TempModel::data(const QModelIndex& index, int role) const
     switch (role)
     {
         case DisplayRole:
-            return temp->name() + ": " + QString::number(temp->value()) + m_unit + "   (" + temp->id() + ")";
+            return temp->id() + ": " + QString::number(temp->value()) + m_unit + "   (" + temp->path() + ")";
 
         case ObjectRole:
             return QVariant::fromValue(temp);