24
24
#include <QStandardItemModel>
25
25
#include <KCalendarSystem>
27
28
class StatisticsModel : public QStandardItemModel
40
StatisticsModel( enum GroupType t, QObject *parent = 0 );
32
StatisticsModel( enum KNemoStats::PeriodUnits t, QObject *parent = 0 );
41
33
virtual ~StatisticsModel();
43
35
enum StatisticRoles
45
DataRole = Qt::UserRole + 1,
37
IdRole = Qt::UserRole + 1,
50
* Clear rows but leave column headers intact
52
46
void clearRows() { removeRows( 0, rowCount() ); }
54
enum GroupType type() const { return mType; }
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; }
49
* Update the text in the date cell. Handy after a rebuild or if a fancy
52
void updateDateText( int row );
55
* Return the type of statistics that this model is tracking
57
enum KNemoStats::PeriodUnits periodType() const { return mPeriodType; }
60
* Set the calendar that the model will use. This must be done before any
63
void setCalendar( const KCalendarSystem * calendar ) { mCalendar = calendar; }
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.
71
int createEntry( const QDateTime &startDateTime, int id = -1, int days = -1 );
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.
77
int id( int row = -1 ) const;
80
* Set the id of a row. If row < 0 it will set the id of the last entry.
82
void setId( int id, int row = -1 );
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.
60
88
QDate date( int row = -1 ) const;
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.
61
94
QDateTime dateTime( int row = -1 ) const;
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.
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;
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.
106
QList<KNemoStats::TrafficType> trafficTypes( int row = -1 ) const;
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.
112
void resetTrafficTypes( int row = -1 );
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.
118
void addTrafficType( int trafficType, int row = -1 );
121
* Return the index of the given id. An invalid id will return -1.
123
int indexOfId( int row ) const;
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.
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;
134
* Set the traffic for given row and traffic type
136
void setTraffic( int row, quint64 rx, quint64 tx, KNemoStats::TrafficType trafficType = KNemoStats::AllTraffic );
139
* Get the formatted text of the traffic levels. If row < 0 it will return
140
* the traffic of the last entry.
66
142
QString rxText( int row = -1 ) const;
67
143
QString txText( int row = -1 ) const;
68
144
QString totalText( int row = -1 ) const;
70
// Always added to the current entry (last row)
71
void addRxBytes( quint64 bytes );
72
void addTxBytes( quint64 bytes );
147
* These add traffic for the given type and row. If row < 0 it will add
148
* traffic to the last entry.
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 );
75
// Always added to the current entry (last row)
76
void addTotalBytes( quint64 bytes );