-
Notifications
You must be signed in to change notification settings - Fork 3
/
Project.h
158 lines (120 loc) · 3.65 KB
/
Project.h
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
149
150
151
152
153
154
155
156
157
158
#ifndef PROJECT_H
#define PROJECT_H
#include <QObject>
#include <QString>
#include <QIcon>
#include <QDateTime>
#include <QHash>
#include "DbRec.h"
#include "Event.h"
#define PROJECT_REPORT_MARGIN_SECS 172800
class Project;
class Project_Table : public QObject, public DbTable
/*********************************************
* class for table that stores project records.
*/
{
Q_OBJECT
public:
Project_Table(QSqlDatabase &db);
~Project_Table();
/* Eliminate default copy constructor and assignment operator */
Project_Table(const Project_Table&)= delete;
Project_Table& operator=(const Project_Table&)= delete;
Project* operator[](int64_t id);
int fetchAll(QVector<int64_t> &idVec, const QString & sql_tail = QString());
int fetchAfter(QVector<int64_t> &idVec, const QDateTime &when);
int fetchClientAfter(QVector<int64_t> &idVec, int64_t client_id, const QDateTime &when);
/* Create new instance of Project, return it cast to DbRec */
virtual DbRec* factory() const;
signals:
void sig_insert(int64_t);
void sig_update(int64_t);
void sig_remove(int64_t);
private:
virtual void emit_cast_sig_insert(DbRec*);
virtual void emit_cast_sig_update(DbRec*);
virtual void emit_cast_sig_remove(DbRec*);
QHash<int64_t,Project*> _hash;
};
class Project : public DbRec {
public:
Project();
~Project();
/* Eliminate default copy constructor and assignment operator */
Project(const Project&)= delete;
Project& operator=(const Project&)= delete;
enum State {
ERROR,
STOPPED,
PAUSED,
RECORDING
};
/* Note: These Event related functions all use G.eventTable */
enum State currentState() const;
QIcon currentStateIcon() const;
void Start();
void Stop();
void Pause();
/* Set field values */
void set_id(int64_t id);
void set_client_id(int64_t id);
void set_project_id(int64_t id);
void set_title(const QString & title);
void set_rate(int64_t rate);
void set_charge_quantum(int32_t charge_quantum);
/* Returns true if field is null */
bool id(int64_t *rtn) const;
bool client_id(int64_t *rtn) const;
bool project_id(int64_t *rtn) const;
bool title(QString *rtn) const;
bool rate(int64_t *rtn) const;
bool charge_quantum(int32_t *rtn) const;
/* Asserted access functions */
int64_t id() const;
int64_t client_id() const;
QString title() const;
int64_t rate() const;
int32_t charge_quantum() const;
Project* parentProject() const;
/* Note: these function use assumed tables from G */
QString longTitle() const;
QString FQLongTitle() const;
int reportTime(int64_t begin_secs, int64_t end_secs);
int reportTime(const QDateTime &begin, const QDateTime &end)
{ return reportTime(begin.toSecsSinceEpoch(), end.toSecsSinceEpoch());}
/* Overloaded DbRec functions */
int insert();
int update();
int remove();
private:
friend class Project_Table;
#if 0
// Limit heap functions
void * operator new (size_t);
void * operator new[] (size_t);
void operator delete (void *);
void operator delete[] (void*);
#endif
/* Note: These Event related functions all use G.eventTable */
void insertEvent(int eventTypeEnum);
Event* lastEvent() const;
enum {
/* Make sure the field enums start at 0, and increase sequentially */
ID_FIELD = 0,
CLIENT_ID_FIELD,
PROJECT_ID_FIELD,
TITLE_FIELD,
RATE_FIELD,
CHARGE_QUANTUM_FIELD,
UNKNOWN_FIELD
};
int64_t _id,
_client_id,
_project_id;
QString _title;
int64_t _rate;
int32_t _charge_quantum;
const static DbField S_DbField_arr[];
};
#endif // PROJECT_H