~ubuntu-branches/ubuntu/natty/knemo/natty

« back to all changes in this revision

Viewing changes to src/knemod/statisticsmodel.h

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-02-22 16:36:22 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20110222163622-d8i62gy1stn7tydv
Tags: 0.7.0-0ubuntu1
* New upstream release.
* Switch to source format 3.0 (quilt).
* Make knemo depend on libqt4-sql-sqlite.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <QDate>
24
24
#include <QStandardItemModel>
25
25
#include <KCalendarSystem>
 
26
#include "data.h"
26
27
 
27
28
class StatisticsModel : public QStandardItemModel
28
29
{
29
30
    Q_OBJECT
30
31
public:
31
 
    enum GroupType
32
 
    {
33
 
        Hour  = 1,
34
 
        Day   = 2,
35
 
        Week  = 4,
36
 
        Month = 8,
37
 
        Year  = 16
38
 
    };
39
 
 
40
 
    StatisticsModel( enum GroupType t, QObject *parent = 0 );
 
32
    StatisticsModel( enum KNemoStats::PeriodUnits t, QObject *parent = 0 );
41
33
    virtual ~StatisticsModel();
42
34
 
43
35
    enum StatisticRoles
44
36
    {
45
 
        DataRole = Qt::UserRole + 1,
46
 
        SpanRole
 
37
        IdRole = Qt::UserRole + 1,
 
38
        SpanRole,
 
39
        TrafficTypeRole,
 
40
        DataRole
47
41
    };
48
42
 
49
43
    /**
50
 
     * Clear rows but leave column headers intact
 
44
     * Clear rows
51
45
     */
52
46
    void clearRows() { removeRows( 0, rowCount() ); }
53
47
 
54
 
    enum GroupType type() const { return mType; }
55
 
 
56
 
    void appendStats( const QDateTime& date, int tSpan, quint64 rx = 0, quint64 tx = 0 );
57
 
    void appendStats( const QDate& date, int days, quint64 rx = 0, quint64 tx = 0 );
58
 
    void setCalendar( const KCalendarSystem * c ) { mCalendar = c; }
59
 
 
 
48
    /**
 
49
     * Update the text in the date cell.  Handy after a rebuild or if a fancy
 
50
     * short date changes.
 
51
     */
 
52
    void updateDateText( int row );
 
53
 
 
54
    /**
 
55
     * Return the type of statistics that this model is tracking
 
56
     */
 
57
    enum KNemoStats::PeriodUnits periodType() const { return mPeriodType; }
 
58
 
 
59
    /**
 
60
     * Set the calendar that the model will use.  This must be done before any
 
61
     * entries are added.
 
62
     */
 
63
    void setCalendar( const KCalendarSystem * calendar ) { mCalendar = calendar; }
 
64
 
 
65
    /**
 
66
     * Creates a stats entry for the model.  If id < 0 it will create an id
 
67
     * that matches rowCount().  If days > 0 it will set a period of length
 
68
     * 'days'.  The latter is relevant only for custom billing periods.
 
69
     */
 
70
 
 
71
    int createEntry( const QDateTime &startDateTime, int id = -1, int days = -1 );
 
72
 
 
73
    /**
 
74
     * Return the id of a row.  If row < 0 it will return the id of the last
 
75
     * entry.  An invalid row will return -1.
 
76
     */
 
77
    int id( int row = -1 ) const;
 
78
 
 
79
    /**
 
80
     * Set the id of a row.  If row < 0 it will set the id of the last entry.
 
81
     */
 
82
    void setId( int id, int row = -1 );
 
83
 
 
84
    /**
 
85
     * Return the QDate of a row.  If row < 0 it will return the date of the
 
86
     * last entry.  An invalid row will return an invalid QDate.
 
87
     */
60
88
    QDate date( int row = -1 ) const;
 
89
 
 
90
    /**
 
91
     * Return the QDateTime of a row.  If row < 0 it will return QDateTime of
 
92
     * the last entry.  An invalid row will return an invalid QDateTime.
 
93
     */
61
94
    QDateTime dateTime( int row = -1 ) const;
 
95
 
 
96
    /**
 
97
     * Return the number of days that an entry spans.  If row < 0 it will
 
98
     * return the day span of the last entry.  An invalid row will return 0.
 
99
     */
62
100
    int days( int row = -1 ) const;
63
 
    quint64 rxBytes( int row = -1 ) const;
64
 
    quint64 txBytes( int row = -1 ) const;
65
 
    quint64 totalBytes( int row = -1 ) const;
 
101
 
 
102
    /**
 
103
     * Return a list of all traffic types tracked by this entry. If row < 0 it
 
104
     * will return the types of the last entry.
 
105
     */
 
106
    QList<KNemoStats::TrafficType> trafficTypes( int row = -1 ) const;
 
107
 
 
108
    /**
 
109
     * Clears the list of traffic types being tracked by the entry in the row.
 
110
     * If row < 0 it will clear the last entry.
 
111
     */
 
112
    void resetTrafficTypes( int row = -1 );
 
113
 
 
114
    /**
 
115
     * Set a traffic type as tracked by this entry.  If row < 0 it will add the
 
116
     * type to the list in the last entry.
 
117
     */
 
118
    void addTrafficType( int trafficType, int row = -1 );
 
119
 
 
120
    /**
 
121
     * Return the index of the given id.  An invalid id will return -1.
 
122
     */
 
123
    int indexOfId( int row ) const;
 
124
 
 
125
    /**
 
126
     * These return the rx, tx, total bytes for the entry in row 'row'.  If row
 
127
     * < 0 it will return the bytes of the last entry.
 
128
     */
 
129
    quint64 rxBytes( int row = -1, KNemoStats::TrafficType trafficType = KNemoStats::AllTraffic ) const;
 
130
    quint64 txBytes( int row = -1, KNemoStats::TrafficType traffictype = KNemoStats::AllTraffic ) const;
 
131
    quint64 totalBytes( int row = -1, KNemoStats::TrafficType trafficType = KNemoStats::AllTraffic ) const;
 
132
 
 
133
    /**
 
134
     * Set the traffic for given row and traffic type
 
135
     */
 
136
    void setTraffic( int row, quint64 rx, quint64 tx, KNemoStats::TrafficType trafficType = KNemoStats::AllTraffic );
 
137
 
 
138
    /**
 
139
     * Get the formatted text of the traffic levels.  If row < 0 it will return
 
140
     * the traffic of the last entry.
 
141
     */
66
142
    QString rxText( int row = -1 ) const;
67
143
    QString txText( int row = -1 ) const;
68
144
    QString totalText( int row = -1 ) const;
69
145
 
70
 
    // Always added to the current entry (last row)
71
 
    void addRxBytes( quint64 bytes );
72
 
    void addTxBytes( quint64 bytes );
 
146
    /**
 
147
     * These add traffic for the given type and row.  If row < 0 it will add
 
148
     * traffic to the last entry.
 
149
     */
 
150
    void addRxBytes( quint64 bytes, KNemoStats::TrafficType trafficType = KNemoStats::AllTraffic, int row = -1 );
 
151
    void addTxBytes( quint64 bytes, KNemoStats::TrafficType trafficType = KNemoStats::AllTraffic, int row = -1 );
73
152
 
74
153
private:
75
 
    // Always added to the current entry (last row)
76
 
    void addTotalBytes( quint64 bytes );
77
 
 
78
 
    enum StatisticColumns
 
154
    enum StatsColumn
79
155
    {
80
156
        Date = 0,
81
157
        TxBytes,
83
159
        TotalBytes
84
160
    };
85
161
 
86
 
    enum GroupType mType;
 
162
    void addBytes( enum StatsColumn column, KNemoStats::TrafficType trafficType, quint64 bytes, int row = -1 );
 
163
    quint64 bytes( enum StatsColumn column, int role, int row ) const;
 
164
    QString text( enum StatsColumn column, int row ) const;
 
165
    void updateText( QStandardItem * i );
 
166
 
 
167
    enum KNemoStats::PeriodUnits mPeriodType;
87
168
    const KCalendarSystem * mCalendar;
88
169
};
89
170