forked from CodingMorry7/Get2gether
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpaintCell.cpp
153 lines (137 loc) · 5.47 KB
/
paintCell.cpp
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
#include "paintCell.h"
#include "connection.h"
//#include <connection.h>
#include <QMessageBox>
#include <QSqlQuery>
#include <QDebug>
#include <QSqlError>
#include <QSqlQueryModel>
#include <QTableWidget>
#include <QtGui/QTextCharFormat>
#include <QString>
#include <QColor>
#include "dashboard.h"
#include "ui_dashboard.h"
#include <QIcon>
/*=================================================================================================================================*/
// class PaintCell-Specific Methods
/*=================================================================================================================================*/
/*.------------------------.*/
/*| Constructor |*/
/*'------------------------'*/
//default constructor
paintCell::paintCell()
{
connection myconn; //connect to database
myconn.openConn();
}
/*=================================================================================================================================*/
/*.------------------------.*/
/*| Paint Methods |*/
/*'------------------------'*/
/* Purpose: Paints specified date cell with specified color
* Preconditions: minimumDate < date < maximumDate
* color is defined in Qt
* Postconditions: Indicated date cell's background color is changed to specified color
*/
void paintCell::paint(Ui::dashboard *ui,QDate date, QColor color)
{
QBrush brush;
QTextCharFormat charFormat;
brush.setColor(color);
charFormat = ui->calendarWidget->dateTextFormat(date);
charFormat.setBackground(brush);
ui->calendarWidget->setDateTextFormat(date, charFormat);
}
/* Purpose: Paints all date cells of calendar widget
* Postconditions: All calendar cells with events are painted
* it's relevant color
*/
void paintCell::paintEvents(Ui::dashboard *ui,QDate date,bool isGroupMode,bool resetStatus,QString myuser,QString groupID,connection &newconn)
{
QSqlQuery *query = new QSqlQuery(newconn.db); // used to query DB
bool isGroupEvent, isThisGroupEvent;
/* If in personal mode,
* Prepare query using only logged in user
* Else in group mode,
* Select each group member's username in group
* Accumulate union select query based on current group
* member and selected calendar day
*/
if(!isGroupMode)
{
query->prepare("SELECT date, groupID "
"FROM innodb.EVENTS, innodb.USER_EVENTS "
"WHERE eventID = ID AND username ='" +myuser+
"' ORDER BY groupID"); // returns events
}
else
{
QSqlQuery selectMemberQ;
QString groupMember, qResult;
selectMemberQ.prepare("SELECT username "
"FROM innodb.GROUP_MEMBERS "
"WHERE groupID = '" +groupID+
"' AND username != '" +myuser+ "'");
qResult = "(SELECT date, groupID "
"FROM innodb.EVENTS, innodb.USER_EVENTS "
"WHERE username = '" +myuser+ "' AND eventID = ID) ";
/* If member select query executes,
* Grab each member's username
* Accumulate union select query for current member
* grabbing event date to paint
*/
if(selectMemberQ.exec() && selectMemberQ.first())
{
do
{
groupMember = selectMemberQ.value(0).toString();
qResult += "UNION (SELECT date, groupID "
"FROM innodb.EVENTS, innodb.USER_EVENTS "
"WHERE username = '" +groupMember+
"' AND eventID = ID) ";
}while(selectMemberQ.next());
qResult += "ORDER BY groupID"; // Order by groupID to have all group events at the end
// of the query so that group events are painted cyan
// even if personal events happen to be on the same day
query->prepare(qResult); // Prepare paint query using accumulated query
}
}
query->exec();
/* Paint every cell with an associated event
* until end of query
*/
while(query->next()) {
date = QDate::fromString(query->value(0).toString(), "ddd MMM d yyyy"); // parse query to identify date
isGroupEvent = (query->value(1).toInt() != 0);
isThisGroupEvent = isGroupEvent && (query->value(1).toString() == groupID);
/* If dashboard is in group mode,
* If event to color is selected group's event,
* Paint cyan
* Else, it's group member's personal event,
* Paint green
* Else, in personal mode
* If event is a group event,
* Paint cyan
* Else, personal event only
* Paint green
*/
if(isGroupMode)
{
if(resetStatus == true)
{
paint(ui,date, Qt::white);
}
else
{
if(isThisGroupEvent) paint(ui,date, Qt::cyan);
else paint(ui,date, Qt::green);
}
}
else
{
if(isGroupEvent) paint(ui,date, Qt::cyan);
else paint(ui,date, Qt::green); // paint parsed date cell green
}
}
}