tempmodel.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 2015 Malte Veerman <malte.veerman@gmail.com>
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of
  7. * the License or (at your option) version 3 or any later version
  8. * accepted by the membership of KDE e.V. (or its successor approved
  9. * by the membership of KDE e.V.), which shall act as a proxy
  10. * defined in Section 14 of version 3 of the license.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. #ifndef TEMPMODEL_H
  22. #define TEMPMODEL_H
  23. #include <QtCore/QAbstractListModel>
  24. namespace Fancontrol {
  25. class Temp;
  26. class TempModel : public QAbstractListModel
  27. {
  28. Q_OBJECT
  29. Q_PROPERTY(int length READ rowCount NOTIFY tempsChanged)
  30. public:
  31. enum Roles
  32. {
  33. DisplayRole,
  34. ObjectRole
  35. };
  36. Q_ENUM(Roles)
  37. TempModel(QObject *parent = Q_NULLPTR);
  38. void setTemps(QList<Temp *> temps);
  39. void addTemp(Temp *newTemp);
  40. void addTemps(const QList<Temp *> &newTemps);
  41. virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override { Q_UNUSED(parent) return m_temps.size(); }
  42. virtual QVariant data(const QModelIndex &index, int role = DisplayRole) const override;
  43. virtual QHash<int, QByteArray> roleNames() const override;
  44. void updateTemp(Temp *temp);
  45. void setUnit(const QString &unit) { if (unit != m_unit) { m_unit = unit; updateAll(); } }
  46. Q_INVOKABLE QObject *temp(int index) const;
  47. Q_INVOKABLE int indexOf(QObject *temp) const;
  48. protected:
  49. void updateAll();
  50. signals:
  51. void tempsChanged();
  52. private:
  53. void updateTemp();
  54. QList<Temp *> m_temps;
  55. QString m_unit;
  56. };
  57. }
  58. #endif //TEMPMODEL_H