@@ -11,12 +11,28 @@ using namespace udata;
1111 * @brief Commitment::Commitment
1212 */
1313Commitment::Commitment () {}
14-
14+ /* *
15+ * @brief Commitment::Commitment Creates a new commitment. This constructor
16+ * tries its best to solve any date conflicts such as dateStart being greater
17+ * than dateEnd, which should not happen. It also updates all the TimeWindow
18+ * objects in commitment so that the data is up to date with the current date of
19+ * the machine.
20+ * @param newName The name of this new commitment.
21+ * @param newStart The date this commitment started. If, for whatever reason,
22+ * this date happens to be earlier than the current date of the machine, then
23+ * the current date is fetched from the system and this parameter is
24+ * overwritten.
25+ * @param newEnd The date this commitment will end, if it has an end date.
26+ * @param newFrequency The object that describes the frequency of this
27+ * commitment(how many times a week the user will commit to this).
28+ * @param newType The type of commitment this is; WEEKLY, MONTHLY, etc.
29+ * @param newNoEndDate Decides whether or not this commitment has an enddate.
30+ */
1531Commitment::Commitment (QString newName, QDate newStart, QDate newEnd,
16- udata::CommitmentFrequency newInterval ,
32+ udata::CommitmentFrequency newFrequency ,
1733 CommitmentType newType, bool newNoEndDate)
1834 : name{newName}, dateStart{newStart}, dateEnd{newEnd},
19- frequency{newInterval },
35+ frequency{newFrequency },
2036 commitmentWindows{}, Type{newType}, noEndDate{newNoEndDate} {
2137 if (dateStart < QDate::currentDate ()) {
2238 dateStart = QDate::currentDate ();
@@ -35,15 +51,17 @@ void Commitment::setFrequency(long long newTime, int newFrequency,
3551}
3652void Commitment::setFrequency (CommitmentFrequency newFrequency) {
3753 frequency = newFrequency;
38- }
54+ } /* *
55+ * @brief Commitment::setCommitmentWindows
56+ * @param newCommitmentWindows
57+ * @note updates commitment windows if the date between this commitment and
58+ * the system are out of sync.
59+ */
3960void Commitment::setCommitmentWindows (
4061 QVector<TimeWindow> &newCommitmentWindows) {
4162 for (auto windows : newCommitmentWindows) {
4263 commitmentWindows.append (windows);
4364 }
44- qDebug () << " setting windows on this commitment-->"
45- << commitmentWindows.length ();
46- // commitmentWindows = newCommitmentWindows;
4765}
4866void Commitment::setType (CommitmentType newType) { Type = newType; }
4967CommitmentType &Commitment::getType () { return Type; }
@@ -88,12 +106,16 @@ void Commitment::updateCommitmentWindows(Session newSession) {
88106 */
89107void Commitment::updateCommitmentWindows () {
90108 QDate currentDate = QDate::currentDate ();
109+ // If the user is done with this commitment, our work is done. There is no
110+ // update needed.
91111 if (isDone ()) {
92- if (name == " Test#100" ) {
93- qDebug () << " Test#100 is done!" ;
94- }
95112 return ;
96- } else if (commitmentWindows.isEmpty ()) {
113+
114+ }
115+ // If there are no TimeWindow objects that are part of the commitment then we
116+ // are constructing this Commitment for the first time and only need a single
117+ // TimeWindow.
118+ else if (commitmentWindows.isEmpty ()) {
97119 commitmentWindows.push_back (TimeWindow{});
98120 TimeWindow &newWindow = commitmentWindows.last ();
99121 newWindow.startDate .setDate (currentDate.year (), currentDate.month (),
@@ -103,6 +125,8 @@ void Commitment::updateCommitmentWindows() {
103125 currentDate.day ());
104126 newWindow.frequency = frequency.frequency ;
105127 } else {
128+ // If our TimeWindow objects are up to date, then we don't need to update
129+ // them :)
106130 TimeWindow &lastWindow = commitmentWindows.last ();
107131 int daysSinceLastCommitmentWindow =
108132 lastWindow.startDate .daysTo (QDate::currentDate ());
@@ -112,7 +136,11 @@ void Commitment::updateCommitmentWindows() {
112136
113137 else if (daysSinceLastCommitmentWindow < frequency.timeWindowSize ) {
114138 return ;
115- } else if (daysSinceLastCommitmentWindow >= frequency.timeWindowSize ) {
139+ }
140+ // Imagine we had a weekly commitment
141+ // If it has been more than week since the last time we added a TimeWindow,
142+ // then we might need to add 1 or more TimeWindow objects to this commitment
143+ else if (daysSinceLastCommitmentWindow >= frequency.timeWindowSize ) {
116144 int NumberOfTimeWindows =
117145 daysSinceLastCommitmentWindow / frequency.timeWindowSize ;
118146 currentDate = lastWindow.endDate .addDays (1 );
@@ -134,15 +162,10 @@ void Commitment::updateCommitmentWindows() {
134162 * updated by this function.
135163 */
136164void Commitment::update () {
137- // updateCommitmentWindows();
138- qDebug () << " upating-->" << name;
139165 if (noEndDate) {
140- qDebug () << " update on Commitment#1" ;
141166 done = false ;
142167 return ;
143168 }
144- qDebug () << " update on Commitment#2" ;
145- // << commitmentWindows.last().endDate << "," << dateEnd;
146169 if (QDate::currentDate () > dateEnd) {
147170 done = true ;
148171 }
@@ -165,12 +188,11 @@ void Commitment::setDone(bool newDone) { done = newDone; }
165188 * Meaning this function, in that case, will return true.
166189 *
167190 * @note Commitments that have noEndDate set to "true" are never considered
168- * "done". In such case, this function will always return " false" .
191+ * "done". In such case, this function will always return false.
169192 * @return true if this commitment is "done". Otherwise, it returns false.
170193 */
171194bool Commitment::isDone () {
172195 update ();
173- qDebug () << " isDone#1" ;
174196 return done;
175197}
176198QVector<TimeWindow> &Commitment::getCommitmentWindows () {
@@ -214,8 +236,6 @@ QDataStream &udata::operator>>(QDataStream &in,
214236 */
215237QDataStream &udata::operator <<(QDataStream &out,
216238 const udata::Commitment &newCommitment) {
217- qDebug () << " QDataStream &udata::operator<<(QDataStream &out, const "
218- " udata::Commitment &newCommitment)" ;
219239 out << newCommitment.name << newCommitment.dateStart << newCommitment.dateEnd
220240 << newCommitment.frequency << newCommitment.Type
221241 << newCommitment.noEndDate ;
@@ -262,9 +282,6 @@ QDataStream &udata::operator>>(QDataStream &in,
262282 in >> newDone;
263283
264284 newCommitment.name = commitmentName;
265- if (commitmentName == " Poetry" ) {
266- qDebug () << " number of time windows:" << newTimeWindows.length ();
267- }
268285 newCommitment.dateStart = commitmentDateStart;
269286 newCommitment.dateEnd = commitmentDateEnd;
270287 newCommitment.noEndDate = newNoEndDate;
@@ -285,7 +302,6 @@ QDataStream &udata::operator<<(QDataStream &out,
285302 out << s;
286303 };
287304 out << newTimeWindow.frequency ;
288- qDebug () << " newTimeWindow startDate=*****************#2" ;
289305 return out;
290306}
291307QDataStream &udata::operator >>(QDataStream &in, TimeWindow &newTimeWindow) {
@@ -294,8 +310,6 @@ QDataStream &udata::operator>>(QDataStream &in, TimeWindow &newTimeWindow) {
294310 int TimeWindowFrequency = 0 ;
295311 in >> newStartDate >> newEndDate;
296312 newTimeWindow.startDate = newStartDate;
297- qDebug ()
298- << " newTimeWindow startDate=*****************#1" ; // <<newTimeWindow.startDate;
299313 newTimeWindow.endDate = newEndDate;
300314 int sessionCount = 0 ;
301315 in >> sessionCount;
@@ -387,8 +401,3 @@ QString Commitment::summary() const {
387401 return summary;
388402}
389403CommitmentFrequency &Commitment::getFrequency () { return frequency; }
390- /* *
391- * @brief Commitment::setSessions
392- * @param value
393- */
394- void Commitment::setSessions (QVector<Session> value) {}
0 commit comments