~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
    KSysGuard, the KDE System Guard

    Copyright (c) 2001 Tobias Koenig <tokoe@kde.org>

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

*/

#ifndef SENSORLOGGER_H
#define SENSORLOGGER_H

#include <QtGui/QTreeView>

#include <SensorDisplay.h>

class LogSensorModel;
class QDomElement;

class LogSensor : public QObject, public KSGRD::SensorClient
{
  Q_OBJECT

  public:
    explicit LogSensor( QObject *parent );
    ~LogSensor();

    virtual void answerReceived( int id, const QList<QByteArray>&answer );

    void setHostName( const QString& name );
    QString hostName() const;

    void setSensorName( const QString& name );
    QString sensorName() const;

    void setFileName( const QString& name );
    QString fileName() const;

    void setUpperLimitActive( bool value );
    bool upperLimitActive() const;

    void setLowerLimitActive( bool value );
    bool lowerLimitActive() const;

    void setUpperLimit( double value );
    double upperLimit() const;

    void setLowerLimit( double value );
    double lowerLimit() const;

    void setTimerInterval( int interval );
    int timerInterval() const;

    bool isLogging() const;

    bool limitReached() const;

  public Q_SLOTS:
    void timerOff();
    void timerOn();

    void startLogging();
    void stopLogging();

  Q_SIGNALS:
    void changed();

  protected:
    virtual void timerTick();

  private:
    QString mSensorName;
    QString mHostName;
    QString mFileName;

    int mTimerInterval;
    int mTimerID;

    bool mLowerLimitActive;
    bool mUpperLimitActive;

    double mLowerLimit;
    double mUpperLimit;

    bool mLimitReached;
};

class LogSensorView : public QTreeView
{
  Q_OBJECT

  public:
    LogSensorView( QWidget *parent = 0 );

  Q_SIGNALS:
    void contextMenuRequest( const QModelIndex &index, const QPoint &pos );

  protected:
    virtual void contextMenuEvent( QContextMenuEvent *event );
};

class SensorLogger : public KSGRD::SensorDisplay
{
  Q_OBJECT

  public:
    SensorLogger( QWidget *parent, const QString& title, SharedSettings *workSheetSettings );
    ~SensorLogger();

    bool addSensor( const QString& hostName, const QString& sensorName,
                    const QString& sensorType, const QString& sensorDescr);

    bool editSensor( LogSensor* );

    virtual void answerReceived( int, const QList<QByteArray>& );

    bool restoreSettings( QDomElement& );
    bool saveSettings( QDomDocument&, QDomElement& );

    void configureSettings();

    virtual bool hasSettingsDialog() const
    {
      return true;
    }

  public Q_SLOTS:
    void applyStyle();
    void contextMenuRequest( const QModelIndex &index, const QPoint &pos );

  private:
    LogSensorModel *mModel;
    LogSensorView *mView;
};

#endif