1 /*
2     KSysGuard, the KDE System Guard
3 
4     Copyright (c) 2006 Tobias Koenig <tokoe@kde.org>
5 
6     This program is free software; you can redistribute it and/or
7     modify it under the terms of the GNU General Public
8     License as published by the Free Software Foundation; either
9     version 2 of the License, or (at your option) any later version.
10 
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 
20 */
21 
22 #ifndef SENSORMODEL_H
23 #define SENSORMODEL_H
24 
25 #include <QAbstractTableModel>
26 #include <QList>
27 #include <QColor>
28 
29 class SensorModelEntry
30 {
31   public:
32     typedef QList<SensorModelEntry> List;
33 
34     void setId( int id );
35     int id() const;
36 
37     void setHostName( const QString &hostName );
38     QString hostName() const;
39 
40     void setSensorName( const QString &sensorName );
41     QString sensorName() const;
42 
43     void setLabel( const QString &label );
44     QString label() const;
45 
46     void setUnit( const QString &unit );
47     QString unit() const;
48 
49     void setStatus( const QString &status );
50     QString status() const;
51 
52     void setColor( const QColor &color );
53     QColor color() const;
54 
55   private:
56     int mId;
57     QString mHostName;
58     QString mSensorName;
59     QString mLabel;
60     QString mUnit;
61     QString mStatus;
62     QColor mColor;
63 };
64 
65 class SensorModel : public QAbstractTableModel
66 {
67   Q_OBJECT
68   public:
69     enum Columns {
70         HostName=0,
71         SensorName=1,
72         Unit=2,
73         Status=3,
74         Label=4
75     };
76     explicit SensorModel( QObject *parent = nullptr );
77 
78     void setSensors( const SensorModelEntry::List &sensors );
79     SensorModelEntry::List sensors() const;
80 
81     void setSensor( const SensorModelEntry &sensor, const QModelIndex &index );
82     void removeSensor( const QModelIndex &index );
83     SensorModelEntry sensor( const QModelIndex &index ) const;
84 
85     void moveDownSensor(const QModelIndex &index);
86     void moveUpSensor(const QModelIndex &index);
87     void setHasLabel( bool hasLabel );
88 
89     int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
90     int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
91     QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
92     QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
93     QList<int> order() const;
94     QList<int> deleted() const;
95     void clearDeleted();
96     void resetOrder();
97 
98   private:
99     SensorModelEntry::List mSensors;
100 
101     bool mHasLabel;
102     /** The numbers of the sensors to be deleted.*/
103     QList<int> mDeleted;
104 };
105 
106 #endif
107