widgets/qcalendarwidget.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7enum { -
8 RowCount = 6, -
9 ColumnCount = 7, -
10 HeaderColumn = 0, -
11 HeaderRow = 0, -
12 MinimumDayOffset = 1 -
13}; -
14 -
15class QCalendarDateSectionValidator -
16{ -
17public: -
18 -
19 enum Section { -
20 NextSection, -
21 ThisSection, -
22 PrevSection -
23 }; -
24 -
25 QCalendarDateSectionValidator() {} -
26 virtual ~QCalendarDateSectionValidator() {} -
27 virtual Section handleKey(int key) = 0; -
28 virtual QDate applyToDate(const QDate &date) const = 0; -
29 virtual void setDate(const QDate &date) = 0; -
30 virtual QString text() const = 0; -
31 virtual QString text(const QDate &date, int repeat) const = 0; -
32 -
33 QLocale m_locale; -
34 -
35protected: -
36 QString highlightString(const QString &str, int pos) const; -
37private: -
38}; -
39 -
40QString QCalendarDateSectionValidator::highlightString(const QString &str, int pos) const -
41{ -
42 if (pos == 0)
never evaluated: pos == 0
0
43 return QLatin1String("<b>") + str + QLatin1String("</b>");
never executed: return QLatin1String("<b>") + str + QLatin1String("</b>");
0
44 int startPos = str.length() - pos; -
45 return str.mid(0, startPos) + QLatin1String("<b>") + str.mid(startPos, pos) + QLatin1String("</b>");
never executed: return str.mid(0, startPos) + QLatin1String("<b>") + str.mid(startPos, pos) + QLatin1String("</b>");
0
46 -
47} -
48 -
49class QCalendarDayValidator : public QCalendarDateSectionValidator -
50{ -
51 -
52public: -
53 QCalendarDayValidator(); -
54 virtual Section handleKey(int key); -
55 virtual QDate applyToDate(const QDate &date) const; -
56 virtual void setDate(const QDate &date); -
57 virtual QString text() const; -
58 virtual QString text(const QDate &date, int repeat) const; -
59private: -
60 int m_pos; -
61 int m_day; -
62 int m_oldDay; -
63}; -
64 -
65QCalendarDayValidator::QCalendarDayValidator() -
66 : QCalendarDateSectionValidator(), m_pos(0), m_day(1), m_oldDay(1) -
67{ -
68}
never executed: }
0
69 -
70QCalendarDateSectionValidator::Section QCalendarDayValidator::handleKey(int key) -
71{ -
72 if (key == Qt::Key_Right || key == Qt::Key_Left) {
never evaluated: key == Qt::Key_Right
never evaluated: key == Qt::Key_Left
0
73 m_pos = 0; -
74 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
75 } else if (key == Qt::Key_Up) {
never evaluated: key == Qt::Key_Up
0
76 m_pos = 0; -
77 ++m_day; -
78 if (m_day > 31)
never evaluated: m_day > 31
0
79 m_day = 1;
never executed: m_day = 1;
0
80 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
81 } else if (key == Qt::Key_Down) {
never evaluated: key == Qt::Key_Down
0
82 m_pos = 0; -
83 --m_day; -
84 if (m_day < 1)
never evaluated: m_day < 1
0
85 m_day = 31;
never executed: m_day = 31;
0
86 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
87 } else if (key == Qt::Key_Back || key == Qt::Key_Backspace) {
never evaluated: key == Qt::Key_Back
never evaluated: key == Qt::Key_Backspace
0
88 --m_pos; -
89 if (m_pos < 0)
never evaluated: m_pos < 0
0
90 m_pos = 1;
never executed: m_pos = 1;
0
91 -
92 if (m_pos == 0)
never evaluated: m_pos == 0
0
93 m_day = m_oldDay;
never executed: m_day = m_oldDay;
0
94 else -
95 m_day = m_day / 10;
never executed: m_day = m_day / 10;
0
96 -
97 -
98 if (m_pos == 0)
never evaluated: m_pos == 0
0
99 return QCalendarDateSectionValidator::PrevSection;
never executed: return QCalendarDateSectionValidator::PrevSection;
0
100 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
101 } -
102 if (key < Qt::Key_0 || key > Qt::Key_9)
never evaluated: key < Qt::Key_0
never evaluated: key > Qt::Key_9
0
103 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
104 int pressedKey = key - Qt::Key_0; -
105 if (m_pos == 0)
never evaluated: m_pos == 0
0
106 m_day = pressedKey;
never executed: m_day = pressedKey;
0
107 else -
108 m_day = m_day % 10 * 10 + pressedKey;
never executed: m_day = m_day % 10 * 10 + pressedKey;
0
109 if (m_day > 31)
never evaluated: m_day > 31
0
110 m_day = 31;
never executed: m_day = 31;
0
111 ++m_pos; -
112 if (m_pos > 1) {
never evaluated: m_pos > 1
0
113 m_pos = 0; -
114 return QCalendarDateSectionValidator::NextSection;
never executed: return QCalendarDateSectionValidator::NextSection;
0
115 } -
116 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
117} -
118 -
119QDate QCalendarDayValidator::applyToDate(const QDate &date) const -
120{ -
121 int day = m_day; -
122 if (day < 1)
never evaluated: day < 1
0
123 day = 1;
never executed: day = 1;
0
124 else if (day > 31)
never evaluated: day > 31
0
125 day = 31;
never executed: day = 31;
0
126 if (day > date.daysInMonth())
never evaluated: day > date.daysInMonth()
0
127 day = date.daysInMonth();
never executed: day = date.daysInMonth();
0
128 return QDate(date.year(), date.month(), day);
never executed: return QDate(date.year(), date.month(), day);
0
129} -
130 -
131void QCalendarDayValidator::setDate(const QDate &date) -
132{ -
133 m_day = m_oldDay = date.day(); -
134 m_pos = 0; -
135}
never executed: }
0
136 -
137QString QCalendarDayValidator::text() const -
138{ -
139 QString str; -
140 if (m_day / 10 == 0)
never evaluated: m_day / 10 == 0
0
141 str += QLatin1Char('0');
never executed: str += QLatin1Char('0');
0
142 str += QString::number(m_day); -
143 return highlightString(str, m_pos);
never executed: return highlightString(str, m_pos);
0
144} -
145 -
146QString QCalendarDayValidator::text(const QDate &date, int repeat) const -
147{ -
148 if (repeat <= 1) {
never evaluated: repeat <= 1
0
149 return QString::number(date.day());
never executed: return QString::number(date.day());
0
150 } else if (repeat == 2) {
never evaluated: repeat == 2
0
151 QString str; -
152 if (date.day() / 10 == 0)
never evaluated: date.day() / 10 == 0
0
153 str += QLatin1Char('0');
never executed: str += QLatin1Char('0');
0
154 return str + QString::number(date.day());
never executed: return str + QString::number(date.day());
0
155 } else if (repeat == 3) {
never evaluated: repeat == 3
0
156 return m_locale.dayName(date.dayOfWeek(), QLocale::ShortFormat);
never executed: return m_locale.dayName(date.dayOfWeek(), QLocale::ShortFormat);
0
157 } else if (repeat >= 4) {
never evaluated: repeat >= 4
0
158 return m_locale.dayName(date.dayOfWeek(), QLocale::LongFormat);
never executed: return m_locale.dayName(date.dayOfWeek(), QLocale::LongFormat);
0
159 } -
160 return QString();
never executed: return QString();
0
161} -
162 -
163 -
164 -
165class QCalendarMonthValidator : public QCalendarDateSectionValidator -
166{ -
167 -
168public: -
169 QCalendarMonthValidator(); -
170 virtual Section handleKey(int key); -
171 virtual QDate applyToDate(const QDate &date) const; -
172 virtual void setDate(const QDate &date); -
173 virtual QString text() const; -
174 virtual QString text(const QDate &date, int repeat) const; -
175private: -
176 int m_pos; -
177 int m_month; -
178 int m_oldMonth; -
179}; -
180 -
181QCalendarMonthValidator::QCalendarMonthValidator() -
182 : QCalendarDateSectionValidator(), m_pos(0), m_month(1), m_oldMonth(1) -
183{ -
184}
never executed: }
0
185 -
186QCalendarDateSectionValidator::Section QCalendarMonthValidator::handleKey(int key) -
187{ -
188 if (key == Qt::Key_Right || key == Qt::Key_Left) {
never evaluated: key == Qt::Key_Right
never evaluated: key == Qt::Key_Left
0
189 m_pos = 0; -
190 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
191 } else if (key == Qt::Key_Up) {
never evaluated: key == Qt::Key_Up
0
192 m_pos = 0; -
193 ++m_month; -
194 if (m_month > 12)
never evaluated: m_month > 12
0
195 m_month = 1;
never executed: m_month = 1;
0
196 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
197 } else if (key == Qt::Key_Down) {
never evaluated: key == Qt::Key_Down
0
198 m_pos = 0; -
199 --m_month; -
200 if (m_month < 1)
never evaluated: m_month < 1
0
201 m_month = 12;
never executed: m_month = 12;
0
202 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
203 } else if (key == Qt::Key_Back || key == Qt::Key_Backspace) {
never evaluated: key == Qt::Key_Back
never evaluated: key == Qt::Key_Backspace
0
204 --m_pos; -
205 if (m_pos < 0)
never evaluated: m_pos < 0
0
206 m_pos = 1;
never executed: m_pos = 1;
0
207 -
208 if (m_pos == 0)
never evaluated: m_pos == 0
0
209 m_month = m_oldMonth;
never executed: m_month = m_oldMonth;
0
210 else -
211 m_month = m_month / 10;
never executed: m_month = m_month / 10;
0
212 -
213 -
214 if (m_pos == 0)
never evaluated: m_pos == 0
0
215 return QCalendarDateSectionValidator::PrevSection;
never executed: return QCalendarDateSectionValidator::PrevSection;
0
216 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
217 } -
218 if (key < Qt::Key_0 || key > Qt::Key_9)
never evaluated: key < Qt::Key_0
never evaluated: key > Qt::Key_9
0
219 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
220 int pressedKey = key - Qt::Key_0; -
221 if (m_pos == 0)
never evaluated: m_pos == 0
0
222 m_month = pressedKey;
never executed: m_month = pressedKey;
0
223 else -
224 m_month = m_month % 10 * 10 + pressedKey;
never executed: m_month = m_month % 10 * 10 + pressedKey;
0
225 if (m_month > 12)
never evaluated: m_month > 12
0
226 m_month = 12;
never executed: m_month = 12;
0
227 ++m_pos; -
228 if (m_pos > 1) {
never evaluated: m_pos > 1
0
229 m_pos = 0; -
230 return QCalendarDateSectionValidator::NextSection;
never executed: return QCalendarDateSectionValidator::NextSection;
0
231 } -
232 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
233} -
234 -
235QDate QCalendarMonthValidator::applyToDate(const QDate &date) const -
236{ -
237 int month = m_month; -
238 if (month < 1)
never evaluated: month < 1
0
239 month = 1;
never executed: month = 1;
0
240 else if (month > 12)
never evaluated: month > 12
0
241 month = 12;
never executed: month = 12;
0
242 QDate newDate(date.year(), m_month, 1); -
243 int day = date.day(); -
244 if (day > newDate.daysInMonth())
never evaluated: day > newDate.daysInMonth()
0
245 day = newDate.daysInMonth();
never executed: day = newDate.daysInMonth();
0
246 return QDate(date.year(), month, day);
never executed: return QDate(date.year(), month, day);
0
247} -
248 -
249void QCalendarMonthValidator::setDate(const QDate &date) -
250{ -
251 m_month = m_oldMonth = date.month(); -
252 m_pos = 0; -
253}
never executed: }
0
254 -
255QString QCalendarMonthValidator::text() const -
256{ -
257 QString str; -
258 if (m_month / 10 == 0)
never evaluated: m_month / 10 == 0
0
259 str += QLatin1Char('0');
never executed: str += QLatin1Char('0');
0
260 str += QString::number(m_month); -
261 return highlightString(str, m_pos);
never executed: return highlightString(str, m_pos);
0
262} -
263 -
264QString QCalendarMonthValidator::text(const QDate &date, int repeat) const -
265{ -
266 if (repeat <= 1) {
never evaluated: repeat <= 1
0
267 return QString::number(date.month());
never executed: return QString::number(date.month());
0
268 } else if (repeat == 2) {
never evaluated: repeat == 2
0
269 QString str; -
270 if (date.month() / 10 == 0)
never evaluated: date.month() / 10 == 0
0
271 str += QLatin1Char('0');
never executed: str += QLatin1Char('0');
0
272 return str + QString::number(date.month());
never executed: return str + QString::number(date.month());
0
273 } else if (repeat == 3) {
never evaluated: repeat == 3
0
274 return m_locale.standaloneMonthName(date.month(), QLocale::ShortFormat);
never executed: return m_locale.standaloneMonthName(date.month(), QLocale::ShortFormat);
0
275 } else { -
276 return m_locale.standaloneMonthName(date.month(), QLocale::LongFormat);
never executed: return m_locale.standaloneMonthName(date.month(), QLocale::LongFormat);
0
277 } -
278} -
279 -
280 -
281 -
282class QCalendarYearValidator : public QCalendarDateSectionValidator -
283{ -
284 -
285public: -
286 QCalendarYearValidator(); -
287 virtual Section handleKey(int key); -
288 virtual QDate applyToDate(const QDate &date) const; -
289 virtual void setDate(const QDate &date); -
290 virtual QString text() const; -
291 virtual QString text(const QDate &date, int repeat) const; -
292private: -
293 int pow10(int n); -
294 int m_pos; -
295 int m_year; -
296 int m_oldYear; -
297}; -
298 -
299QCalendarYearValidator::QCalendarYearValidator() -
300 : QCalendarDateSectionValidator(), m_pos(0), m_year(2000), m_oldYear(2000) -
301{ -
302}
never executed: }
0
303 -
304int QCalendarYearValidator::pow10(int n) -
305{ -
306 int power = 1; -
307 for (int i = 0; i < n; i++)
never evaluated: i < n
0
308 power *= 10;
never executed: power *= 10;
0
309 return power;
never executed: return power;
0
310} -
311 -
312QCalendarDateSectionValidator::Section QCalendarYearValidator::handleKey(int key) -
313{ -
314 if (key == Qt::Key_Right || key == Qt::Key_Left) {
never evaluated: key == Qt::Key_Right
never evaluated: key == Qt::Key_Left
0
315 m_pos = 0; -
316 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
317 } else if (key == Qt::Key_Up) {
never evaluated: key == Qt::Key_Up
0
318 m_pos = 0; -
319 ++m_year; -
320 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
321 } else if (key == Qt::Key_Down) {
never evaluated: key == Qt::Key_Down
0
322 m_pos = 0; -
323 --m_year; -
324 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
325 } else if (key == Qt::Key_Back || key == Qt::Key_Backspace) {
never evaluated: key == Qt::Key_Back
never evaluated: key == Qt::Key_Backspace
0
326 --m_pos; -
327 if (m_pos < 0)
never evaluated: m_pos < 0
0
328 m_pos = 3;
never executed: m_pos = 3;
0
329 -
330 int pow = pow10(m_pos); -
331 m_year = m_oldYear / pow * pow + m_year % (pow * 10) / 10; -
332 -
333 if (m_pos == 0)
never evaluated: m_pos == 0
0
334 return QCalendarDateSectionValidator::PrevSection;
never executed: return QCalendarDateSectionValidator::PrevSection;
0
335 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
336 } -
337 if (key < Qt::Key_0 || key > Qt::Key_9)
never evaluated: key < Qt::Key_0
never evaluated: key > Qt::Key_9
0
338 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
339 int pressedKey = key - Qt::Key_0; -
340 int pow = pow10(m_pos); -
341 m_year = m_year / (pow * 10) * (pow * 10) + m_year % pow * 10 + pressedKey; -
342 ++m_pos; -
343 if (m_pos > 3) {
never evaluated: m_pos > 3
0
344 m_pos = 0; -
345 return QCalendarDateSectionValidator::NextSection;
never executed: return QCalendarDateSectionValidator::NextSection;
0
346 } -
347 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
348} -
349 -
350QDate QCalendarYearValidator::applyToDate(const QDate &date) const -
351{ -
352 int year = m_year; -
353 if (year < 1)
never evaluated: year < 1
0
354 year = 1;
never executed: year = 1;
0
355 QDate newDate(year, date.month(), 1); -
356 int day = date.day(); -
357 if (day > newDate.daysInMonth())
never evaluated: day > newDate.daysInMonth()
0
358 day = newDate.daysInMonth();
never executed: day = newDate.daysInMonth();
0
359 return QDate(year, date.month(), day);
never executed: return QDate(year, date.month(), day);
0
360} -
361 -
362void QCalendarYearValidator::setDate(const QDate &date) -
363{ -
364 m_year = m_oldYear = date.year(); -
365 m_pos = 0; -
366}
never executed: }
0
367 -
368QString QCalendarYearValidator::text() const -
369{ -
370 QString str; -
371 int pow = 10; -
372 for (int i = 0; i < 3; i++) {
never evaluated: i < 3
0
373 if (m_year / pow == 0)
never evaluated: m_year / pow == 0
0
374 str += QLatin1Char('0');
never executed: str += QLatin1Char('0');
0
375 pow *= 10; -
376 }
never executed: }
0
377 str += QString::number(m_year); -
378 return highlightString(str, m_pos);
never executed: return highlightString(str, m_pos);
0
379} -
380 -
381QString QCalendarYearValidator::text(const QDate &date, int repeat) const -
382{ -
383 if (repeat < 4) {
never evaluated: repeat < 4
0
384 QString str; -
385 int year = date.year() % 100; -
386 if (year / 10 == 0)
never evaluated: year / 10 == 0
0
387 str = QLatin1Char('0');
never executed: str = QLatin1Char('0');
0
388 return str + QString::number(year);
never executed: return str + QString::number(year);
0
389 } -
390 return QString::number(date.year());
never executed: return QString::number(date.year());
0
391} -
392 -
393 -
394 -
395class QCalendarDateValidator -
396{ -
397public: -
398 QCalendarDateValidator(); -
399 ~QCalendarDateValidator(); -
400 -
401 void handleKeyEvent(QKeyEvent *keyEvent); -
402 QString currentText() const; -
403 QDate currentDate() const { return m_currentDate; }
never executed: return m_currentDate;
0
404 void setFormat(const QString &format); -
405 void setInitialDate(const QDate &date); -
406 -
407 void setLocale(const QLocale &locale); -
408 -
409private: -
410 -
411 struct SectionToken { -
412 SectionToken(QCalendarDateSectionValidator *val, int rep) : validator(val), repeat(rep) {}
never executed: }
0
413 QCalendarDateSectionValidator *validator; -
414 int repeat; -
415 }; -
416 -
417 void toNextToken(); -
418 void toPreviousToken(); -
419 void applyToDate(); -
420 -
421 int countRepeat(const QString &str, int index) const; -
422 void clear(); -
423 -
424 QStringList m_separators; -
425 QList<SectionToken *> m_tokens; -
426 QCalendarDateSectionValidator *m_yearValidator; -
427 QCalendarDateSectionValidator *m_monthValidator; -
428 QCalendarDateSectionValidator *m_dayValidator; -
429 -
430 SectionToken *m_currentToken; -
431 -
432 QDate m_initialDate; -
433 QDate m_currentDate; -
434 -
435 QCalendarDateSectionValidator::Section m_lastSectionMove; -
436}; -
437 -
438QCalendarDateValidator::QCalendarDateValidator() -
439 : m_currentToken(0), m_lastSectionMove(QCalendarDateSectionValidator::ThisSection) -
440{ -
441 m_initialDate = m_currentDate = QDate::currentDate(); -
442 m_yearValidator = new QCalendarYearValidator(); -
443 m_monthValidator = new QCalendarMonthValidator(); -
444 m_dayValidator = new QCalendarDayValidator(); -
445}
never executed: }
0
446 -
447void QCalendarDateValidator::setLocale(const QLocale &locale) -
448{ -
449 m_yearValidator->m_locale = locale; -
450 m_monthValidator->m_locale = locale; -
451 m_dayValidator->m_locale = locale; -
452}
never executed: }
0
453 -
454QCalendarDateValidator::~QCalendarDateValidator() -
455{ -
456 delete m_yearValidator; -
457 delete m_monthValidator; -
458 delete m_dayValidator; -
459 clear(); -
460}
never executed: }
0
461 -
462 -
463int QCalendarDateValidator::countRepeat(const QString &str, int index) const -
464{ -
465 qt_noop(); -
466 int count = 1; -
467 const QChar ch = str.at(index); -
468 while (index + count < str.size() && str.at(index + count) == ch)
never evaluated: index + count < str.size()
never evaluated: str.at(index + count) == ch
0
469 ++count;
never executed: ++count;
0
470 return count;
never executed: return count;
0
471} -
472 -
473void QCalendarDateValidator::setInitialDate(const QDate &date) -
474{ -
475 m_yearValidator->setDate(date); -
476 m_monthValidator->setDate(date); -
477 m_dayValidator->setDate(date); -
478 m_initialDate = date; -
479 m_currentDate = date; -
480 m_lastSectionMove = QCalendarDateSectionValidator::ThisSection; -
481}
never executed: }
0
482 -
483QString QCalendarDateValidator::currentText() const -
484{ -
485 QString str; -
486 QStringListIterator itSep(m_separators); -
487 QListIterator<SectionToken *> itTok(m_tokens); -
488 while (itSep.hasNext()) {
never evaluated: itSep.hasNext()
0
489 str += itSep.next(); -
490 if (itTok.hasNext()) {
never evaluated: itTok.hasNext()
0
491 SectionToken *token = itTok.next(); -
492 QCalendarDateSectionValidator *validator = token->validator; -
493 if (m_currentToken == token)
never evaluated: m_currentToken == token
0
494 str += validator->text();
never executed: str += validator->text();
0
495 else -
496 str += validator->text(m_currentDate, token->repeat);
never executed: str += validator->text(m_currentDate, token->repeat);
0
497 } -
498 }
never executed: }
0
499 return str;
never executed: return str;
0
500} -
501 -
502void QCalendarDateValidator::clear() -
503{ -
504 QListIterator<SectionToken *> it(m_tokens); -
505 while (it.hasNext())
never evaluated: it.hasNext()
0
506 delete it.next();
never executed: delete it.next();
0
507 -
508 m_tokens.clear(); -
509 m_separators.clear(); -
510 -
511 m_currentToken = 0; -
512}
never executed: }
0
513 -
514void QCalendarDateValidator::setFormat(const QString &format) -
515{ -
516 clear(); -
517 -
518 int pos = 0; -
519 const QLatin1Char quote('\''); -
520 bool quoting = false; -
521 QString separator; -
522 while (pos < format.size()) {
never evaluated: pos < format.size()
0
523 QString mid = format.mid(pos); -
524 int offset = 1; -
525 -
526 if (mid.startsWith(quote)) {
never evaluated: mid.startsWith(quote)
0
527 quoting = !quoting; -
528 } else {
never executed: }
0
529 const QChar nextChar = format.at(pos); -
530 if (quoting) {
never evaluated: quoting
0
531 separator += nextChar; -
532 } else {
never executed: }
0
533 SectionToken *token = 0; -
534 if (nextChar == QLatin1Char('d')) {
never evaluated: nextChar == QLatin1Char('d')
0
535 offset = qMin(4, countRepeat(format, pos)); -
536 token = new SectionToken(m_dayValidator, offset); -
537 } else if (nextChar == QLatin1Char('M')) {
never evaluated: nextChar == QLatin1Char('M')
never executed: }
0
538 offset = qMin(4, countRepeat(format, pos)); -
539 token = new SectionToken(m_monthValidator, offset); -
540 } else if (nextChar == QLatin1Char('y')) {
never executed: }
never evaluated: nextChar == QLatin1Char('y')
0
541 offset = qMin(4, countRepeat(format, pos)); -
542 token = new SectionToken(m_yearValidator, offset); -
543 } else {
never executed: }
0
544 separator += nextChar; -
545 }
never executed: }
0
546 if (token) {
never evaluated: token
0
547 m_tokens.append(token); -
548 m_separators.append(separator); -
549 separator = QString(); -
550 if (!m_currentToken)
never evaluated: !m_currentToken
0
551 m_currentToken = token;
never executed: m_currentToken = token;
0
552 -
553 }
never executed: }
0
554 }
never executed: }
0
555 } -
556 pos += offset; -
557 }
never executed: }
0
558 m_separators += separator; -
559}
never executed: }
0
560 -
561void QCalendarDateValidator::applyToDate() -
562{ -
563 m_currentDate = m_yearValidator->applyToDate(m_currentDate); -
564 m_currentDate = m_monthValidator->applyToDate(m_currentDate); -
565 m_currentDate = m_dayValidator->applyToDate(m_currentDate); -
566}
never executed: }
0
567 -
568void QCalendarDateValidator::toNextToken() -
569{ -
570 const int idx = m_tokens.indexOf(m_currentToken); -
571 if (idx == -1)
never evaluated: idx == -1
0
572 return;
never executed: return;
0
573 if (idx + 1 >= m_tokens.count())
never evaluated: idx + 1 >= m_tokens.count()
0
574 m_currentToken = m_tokens.first();
never executed: m_currentToken = m_tokens.first();
0
575 else -
576 m_currentToken = m_tokens.at(idx + 1);
never executed: m_currentToken = m_tokens.at(idx + 1);
0
577} -
578 -
579void QCalendarDateValidator::toPreviousToken() -
580{ -
581 const int idx = m_tokens.indexOf(m_currentToken); -
582 if (idx == -1)
never evaluated: idx == -1
0
583 return;
never executed: return;
0
584 if (idx - 1 < 0)
never evaluated: idx - 1 < 0
0
585 m_currentToken = m_tokens.last();
never executed: m_currentToken = m_tokens.last();
0
586 else -
587 m_currentToken = m_tokens.at(idx - 1);
never executed: m_currentToken = m_tokens.at(idx - 1);
0
588} -
589 -
590void QCalendarDateValidator::handleKeyEvent(QKeyEvent *keyEvent) -
591{ -
592 if (!m_currentToken)
never evaluated: !m_currentToken
0
593 return;
never executed: return;
0
594 -
595 int key = keyEvent->key(); -
596 if (m_lastSectionMove == QCalendarDateSectionValidator::NextSection) {
never evaluated: m_lastSectionMove == QCalendarDateSectionValidator::NextSection
0
597 if (key == Qt::Key_Back || key == Qt::Key_Backspace)
never evaluated: key == Qt::Key_Back
never evaluated: key == Qt::Key_Backspace
0
598 toPreviousToken();
never executed: toPreviousToken();
0
599 }
never executed: }
0
600 if (key == Qt::Key_Right)
never evaluated: key == Qt::Key_Right
0
601 toNextToken();
never executed: toNextToken();
0
602 else if (key == Qt::Key_Left)
never evaluated: key == Qt::Key_Left
0
603 toPreviousToken();
never executed: toPreviousToken();
0
604 -
605 m_lastSectionMove = m_currentToken->validator->handleKey(key); -
606 -
607 applyToDate(); -
608 if (m_lastSectionMove == QCalendarDateSectionValidator::NextSection)
never evaluated: m_lastSectionMove == QCalendarDateSectionValidator::NextSection
0
609 toNextToken();
never executed: toNextToken();
0
610 else if (m_lastSectionMove == QCalendarDateSectionValidator::PrevSection)
never evaluated: m_lastSectionMove == QCalendarDateSectionValidator::PrevSection
0
611 toPreviousToken();
never executed: toPreviousToken();
0
612} -
613 -
614QWidget *QCalendarTextNavigator::widget() const -
615{ -
616 return m_widget;
executed: return m_widget;
Execution Count:29
29
617} -
618 -
619void QCalendarTextNavigator::setWidget(QWidget *widget) -
620{ -
621 m_widget = widget; -
622}
executed: }
Execution Count:29
29
623 -
624QDate QCalendarTextNavigator::date() const -
625{ -
626 return m_date;
never executed: return m_date;
0
627} -
628 -
629void QCalendarTextNavigator::setDate(const QDate &date) -
630{ -
631 m_date = date; -
632}
executed: }
Execution Count:8
8
633 -
634void QCalendarTextNavigator::updateDateLabel() -
635{ -
636 if (!m_widget)
never evaluated: !m_widget
0
637 return;
never executed: return;
0
638 -
639 m_acceptTimer.start(m_editDelay, this); -
640 -
641 m_dateText->setText(m_dateValidator->currentText()); -
642 -
643 QSize s = m_dateFrame->sizeHint(); -
644 QRect r = m_widget->geometry(); -
645 QRect newRect((r.width() - s.width()) / 2, (r.height() - s.height()) / 2, s.width(), s.height()); -
646 m_dateFrame->setGeometry(newRect); -
647 -
648 -
649 QPalette p = m_dateFrame->palette(); -
650 p.setBrush(QPalette::Window, m_dateFrame->window()->palette().brush(QPalette::Window)); -
651 m_dateFrame->setPalette(p); -
652 -
653 m_dateFrame->raise(); -
654 m_dateFrame->show(); -
655}
never executed: }
0
656 -
657void QCalendarTextNavigator::applyDate() -
658{ -
659 QDate date = m_dateValidator->currentDate(); -
660 if (m_date == date)
never evaluated: m_date == date
0
661 return;
never executed: return;
0
662 -
663 m_date = date; -
664 dateChanged(date); -
665}
never executed: }
0
666 -
667void QCalendarTextNavigator::createDateLabel() -
668{ -
669 if (m_dateFrame)
never evaluated: m_dateFrame
0
670 return;
never executed: return;
0
671 m_dateFrame = new QFrame(m_widget); -
672 QVBoxLayout *vl = new QVBoxLayout; -
673 m_dateText = new QLabel; -
674 vl->addWidget(m_dateText); -
675 m_dateFrame->setLayout(vl); -
676 m_dateFrame->setFrameShadow(QFrame::Plain); -
677 m_dateFrame->setFrameShape(QFrame::Box); -
678 m_dateValidator = new QCalendarDateValidator(); -
679 m_dateValidator->setLocale(m_widget->locale()); -
680 m_dateValidator->setFormat(m_widget->locale().dateFormat(QLocale::ShortFormat)); -
681 m_dateValidator->setInitialDate(m_date); -
682 -
683 m_dateFrame->setAutoFillBackground(true); -
684 m_dateFrame->setBackgroundRole(QPalette::Window); -
685}
never executed: }
0
686 -
687void QCalendarTextNavigator::removeDateLabel() -
688{ -
689 if (!m_dateFrame)
never evaluated: !m_dateFrame
0
690 return;
never executed: return;
0
691 m_acceptTimer.stop(); -
692 m_dateFrame->hide(); -
693 m_dateFrame->deleteLater(); -
694 delete m_dateValidator; -
695 m_dateFrame = 0; -
696 m_dateText = 0; -
697 m_dateValidator = 0; -
698}
never executed: }
0
699 -
700bool QCalendarTextNavigator::eventFilter(QObject *o, QEvent *e) -
701{ -
702 if (m_widget) {
partially evaluated: m_widget
TRUEFALSE
yes
Evaluation Count:563
no
Evaluation Count:0
0-563
703 if (e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease) {
evaluated: e->type() == QEvent::KeyPress
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:562
evaluated: e->type() == QEvent::KeyRelease
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:561
1-562
704 QKeyEvent* ke = (QKeyEvent*)e; -
705 if ((ke->text().length() > 0 && ke->text()[0].isPrint()) || m_dateFrame) {
partially evaluated: ke->text().length() > 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
never evaluated: ke->text()[0].isPrint()
partially evaluated: m_dateFrame
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
706 if (ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Select) {
never evaluated: ke->key() == Qt::Key_Return
never evaluated: ke->key() == Qt::Key_Enter
never evaluated: ke->key() == Qt::Key_Select
0
707 applyDate(); -
708 editingFinished(); -
709 removeDateLabel(); -
710 } else if (ke->key() == Qt::Key_Escape) {
never executed: }
never evaluated: ke->key() == Qt::Key_Escape
0
711 removeDateLabel(); -
712 } else if (e->type() == QEvent::KeyPress) {
never executed: }
never evaluated: e->type() == QEvent::KeyPress
0
713 createDateLabel(); -
714 m_dateValidator->handleKeyEvent(ke); -
715 updateDateLabel(); -
716 }
never executed: }
0
717 ke->accept(); -
718 return true;
never executed: return true;
0
719 } -
720 }
executed: }
Execution Count:2
2
721 }
executed: }
Execution Count:563
563
722 return QObject::eventFilter(o,e);
executed: return QObject::eventFilter(o,e);
Execution Count:563
563
723} -
724 -
725void QCalendarTextNavigator::timerEvent(QTimerEvent *e) -
726{ -
727 if (e->timerId() == m_acceptTimer.timerId()) {
never evaluated: e->timerId() == m_acceptTimer.timerId()
0
728 applyDate(); -
729 removeDateLabel(); -
730 }
never executed: }
0
731}
never executed: }
0
732 -
733int QCalendarTextNavigator::dateEditAcceptDelay() const -
734{ -
735 return m_editDelay;
never executed: return m_editDelay;
0
736} -
737 -
738void QCalendarTextNavigator::setDateEditAcceptDelay(int delay) -
739{ -
740 m_editDelay = delay; -
741}
never executed: }
0
742 -
743class QCalendarView; -
744 -
745class QCalendarModel : public QAbstractTableModel -
746{ -
747 public: template <typename T> inline void qt_check_for_QOBJECT_macro(const T &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); static inline QString tr(const char *s, const char *c = 0, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = 0, int n = -1) { return staticMetaObject.tr(s, c, n); } virtual int qt_metacall(QMetaObject::Call, int, void **); private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); struct QPrivateSignal {}; -
748public: -
749 QCalendarModel(QObject *parent = 0); -
750 -
751 int rowCount(const QModelIndex &) const -
752 { return RowCount + m_firstRow; }
executed: return RowCount + m_firstRow;
Execution Count:7687
7687
753 int columnCount(const QModelIndex &) const -
754 { return ColumnCount + m_firstColumn; }
executed: return ColumnCount + m_firstColumn;
Execution Count:8212
8212
755 QVariant data(const QModelIndex &index, int role) const; -
756 Qt::ItemFlags flags(const QModelIndex &index) const; -
757 -
758 bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) -
759 { -
760 beginInsertRows(parent, row, row + count - 1); -
761 endInsertRows(); -
762 return true;
executed: return true;
Execution Count:1
1
763 } -
764 bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) -
765 { -
766 beginInsertColumns(parent, column, column + count - 1); -
767 endInsertColumns(); -
768 return true;
never executed: return true;
0
769 } -
770 bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) -
771 { -
772 beginRemoveRows(parent, row, row + count - 1); -
773 endRemoveRows(); -
774 return true;
executed: return true;
Execution Count:1
1
775 } -
776 bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) -
777 { -
778 beginRemoveColumns(parent, column, column + count - 1); -
779 endRemoveColumns(); -
780 return true;
executed: return true;
Execution Count:5
5
781 } -
782 -
783 void showMonth(int year, int month); -
784 void setDate(const QDate &d); -
785 -
786 void setMinimumDate(const QDate &date); -
787 void setMaximumDate(const QDate &date); -
788 -
789 void setRange(const QDate &min, const QDate &max); -
790 -
791 void setHorizontalHeaderFormat(QCalendarWidget::HorizontalHeaderFormat format); -
792 -
793 void setFirstColumnDay(Qt::DayOfWeek dayOfWeek); -
794 Qt::DayOfWeek firstColumnDay() const; -
795 -
796 bool weekNumbersShown() const; -
797 void setWeekNumbersShown(bool show); -
798 -
799 QTextCharFormat formatForCell(int row, int col) const; -
800 Qt::DayOfWeek dayOfWeekForColumn(int section) const; -
801 int columnForDayOfWeek(Qt::DayOfWeek day) const; -
802 QDate dateForCell(int row, int column) const; -
803 void cellForDate(const QDate &date, int *row, int *column) const; -
804 QString dayName(Qt::DayOfWeek day) const; -
805 -
806 void setView(QCalendarView *view) -
807 { m_view = view; }
executed: }
Execution Count:27
27
808 -
809 void internalUpdate(); -
810 QDate referenceDate() const; -
811 int columnForFirstOfMonth(const QDate &date) const; -
812 -
813 int m_firstColumn; -
814 int m_firstRow; -
815 QDate m_date; -
816 QDate m_minimumDate; -
817 QDate m_maximumDate; -
818 int m_shownYear; -
819 int m_shownMonth; -
820 Qt::DayOfWeek m_firstDay; -
821 QCalendarWidget::HorizontalHeaderFormat m_horizontalHeaderFormat; -
822 bool m_weekNumbersShown; -
823 QMap<Qt::DayOfWeek, QTextCharFormat> m_dayFormats; -
824 QMap<QDate, QTextCharFormat> m_dateFormats; -
825 QTextCharFormat m_headerFormat; -
826 QCalendarView *m_view; -
827}; -
828 -
829class QCalendarView : public QTableView -
830{ -
831 public: template <typename T> inline void qt_check_for_QOBJECT_macro(const T &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); static inline QString tr(const char *s, const char *c = 0, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = 0, int n = -1) { return staticMetaObject.tr(s, c, n); } virtual int qt_metacall(QMetaObject::Call, int, void **); private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); struct QPrivateSignal {}; -
832public: -
833 QCalendarView(QWidget *parent = 0); -
834 -
835 void internalUpdate() { updateGeometries(); }
executed: }
Execution Count:586
586
836 void setReadOnly(bool enable); -
837 virtual void keyboardSearch(const QString & search) { (void)search; }
never executed: }
0
838 -
839public: -
840 void showDate(const QDate &date); -
841 void changeDate(const QDate &date, bool changeMonth); -
842 void clicked(const QDate &date); -
843 void editingFinished(); -
844protected: -
845 QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers); -
846 void mouseDoubleClickEvent(QMouseEvent *event); -
847 void mousePressEvent(QMouseEvent *event); -
848 void mouseMoveEvent(QMouseEvent *event); -
849 void mouseReleaseEvent(QMouseEvent *event); -
850 -
851 void wheelEvent(QWheelEvent *event); -
852 -
853 void keyPressEvent(QKeyEvent *event); -
854 bool event(QEvent *event); -
855 -
856 QDate handleMouseEvent(QMouseEvent *event); -
857public: -
858 bool readOnly; -
859private: -
860 bool validDateClicked; -
861 -
862 -
863 -
864}; -
865 -
866QCalendarModel::QCalendarModel(QObject *parent) -
867 : QAbstractTableModel(parent) -
868{ -
869 m_date = QDate::currentDate(); -
870 m_minimumDate = QDate::fromJulianDay(1); -
871 m_maximumDate = QDate(7999, 12, 31); -
872 m_shownYear = m_date.year(); -
873 m_shownMonth = m_date.month(); -
874 m_firstDay = QLocale().firstDayOfWeek(); -
875 m_horizontalHeaderFormat = QCalendarWidget::ShortDayNames; -
876 m_weekNumbersShown = true; -
877 m_firstColumn = 1; -
878 m_firstRow = 1; -
879 m_view = 0; -
880}
executed: }
Execution Count:27
27
881 -
882Qt::DayOfWeek QCalendarModel::dayOfWeekForColumn(int column) const -
883{ -
884 int col = column - m_firstColumn; -
885 if (col < 0 || col > 6)
partially evaluated: col < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12549
evaluated: col > 6
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:12548
0-12549
886 return Qt::Sunday;
executed: return Qt::Sunday;
Execution Count:1
1
887 int day = m_firstDay + col; -
888 if (day > 7)
evaluated: day > 7
TRUEFALSE
yes
Evaluation Count:10727
yes
Evaluation Count:1821
1821-10727
889 day -= 7;
executed: day -= 7;
Execution Count:10727
10727
890 return Qt::DayOfWeek(day);
executed: return Qt::DayOfWeek(day);
Execution Count:12548
12548
891} -
892 -
893int QCalendarModel::columnForDayOfWeek(Qt::DayOfWeek day) const -
894{ -
895 if (day < 1 || day > 7)
partially evaluated: day < 1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:22226
partially evaluated: day > 7
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:22226
0-22226
896 return -1;
never executed: return -1;
0
897 int column = (int)day - (int)m_firstDay; -
898 if (column < 0)
evaluated: column < 0
TRUEFALSE
yes
Evaluation Count:20098
yes
Evaluation Count:2128
2128-20098
899 column += 7;
executed: column += 7;
Execution Count:20098
20098
900 return column + m_firstColumn;
executed: return column + m_firstColumn;
Execution Count:22226
22226
901} -
902QDate QCalendarModel::referenceDate() const -
903{ -
904 int refDay = 1; -
905 while (refDay <= 31) {
partially evaluated: refDay <= 31
TRUEFALSE
yes
Evaluation Count:21932
no
Evaluation Count:0
0-21932
906 QDate refDate(m_shownYear, m_shownMonth, refDay); -
907 if (refDate.isValid())
partially evaluated: refDate.isValid()
TRUEFALSE
yes
Evaluation Count:21932
no
Evaluation Count:0
0-21932
908 return refDate;
executed: return refDate;
Execution Count:21932
21932
909 refDay += 1; -
910 }
never executed: }
0
911 return QDate();
never executed: return QDate();
0
912} -
913 -
914int QCalendarModel::columnForFirstOfMonth(const QDate &date) const -
915{ -
916 return (columnForDayOfWeek(static_cast<Qt::DayOfWeek>(date.dayOfWeek())) - (date.day() % 7) + 8) % 7;
executed: return (columnForDayOfWeek(static_cast<Qt::DayOfWeek>(date.dayOfWeek())) - (date.day() % 7) + 8) % 7;
Execution Count:21932
21932
917} -
918 -
919QDate QCalendarModel::dateForCell(int row, int column) const -
920{ -
921 if (row < m_firstRow || row > m_firstRow + RowCount - 1 ||
evaluated: row < m_firstRow
TRUEFALSE
yes
Evaluation Count:1137
yes
Evaluation Count:19467
partially evaluated: row > m_firstRow + RowCount - 1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:19467
0-19467
922 column < m_firstColumn || column > m_firstColumn + ColumnCount - 1)
evaluated: column < m_firstColumn
TRUEFALSE
yes
Evaluation Count:816
yes
Evaluation Count:18651
partially evaluated: column > m_firstColumn + ColumnCount - 1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:18651
0-18651
923 return QDate();
executed: return QDate();
Execution Count:1953
1953
924 const QDate refDate = referenceDate(); -
925 if (!refDate.isValid())
partially evaluated: !refDate.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:18651
0-18651
926 return QDate();
never executed: return QDate();
0
927 -
928 const int columnForFirstOfShownMonth = columnForFirstOfMonth(refDate); -
929 if (columnForFirstOfShownMonth - m_firstColumn < MinimumDayOffset)
evaluated: columnForFirstOfShownMonth - m_firstColumn < MinimumDayOffset
TRUEFALSE
yes
Evaluation Count:14207
yes
Evaluation Count:4444
4444-14207
930 row -= 1;
executed: row -= 1;
Execution Count:14207
14207
931 -
932 const int requestedDay = 7 * (row - m_firstRow) + column - columnForFirstOfShownMonth - refDate.day() + 1; -
933 return refDate.addDays(requestedDay);
executed: return refDate.addDays(requestedDay);
Execution Count:18651
18651
934} -
935 -
936void QCalendarModel::cellForDate(const QDate &date, int *row, int *column) const -
937{ -
938 if (!row && !column)
partially evaluated: !row
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3281
never evaluated: !column
0-3281
939 return;
never executed: return;
0
940 -
941 if (row)
partially evaluated: row
TRUEFALSE
yes
Evaluation Count:3281
no
Evaluation Count:0
0-3281
942 *row = -1;
executed: *row = -1;
Execution Count:3281
3281
943 if (column)
partially evaluated: column
TRUEFALSE
yes
Evaluation Count:3281
no
Evaluation Count:0
0-3281
944 *column = -1;
executed: *column = -1;
Execution Count:3281
3281
945 -
946 const QDate refDate = referenceDate(); -
947 if (!refDate.isValid())
partially evaluated: !refDate.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3281
0-3281
948 return;
never executed: return;
0
949 -
950 const int columnForFirstOfShownMonth = columnForFirstOfMonth(refDate); -
951 const int requestedPosition = refDate.daysTo(date) - m_firstColumn + columnForFirstOfShownMonth + refDate.day() - 1; -
952 -
953 int c = requestedPosition % 7; -
954 int r = requestedPosition / 7; -
955 if (c < 0) {
evaluated: c < 0
TRUEFALSE
yes
Evaluation Count:695
yes
Evaluation Count:2586
695-2586
956 c += 7; -
957 r -= 1; -
958 }
executed: }
Execution Count:695
695
959 -
960 if (columnForFirstOfShownMonth - m_firstColumn < MinimumDayOffset)
evaluated: columnForFirstOfShownMonth - m_firstColumn < MinimumDayOffset
TRUEFALSE
yes
Evaluation Count:1771
yes
Evaluation Count:1510
1510-1771
961 r += 1;
executed: r += 1;
Execution Count:1771
1771
962 -
963 if (r < 0 || r > RowCount - 1 || c < 0 || c > ColumnCount - 1)
evaluated: r < 0
TRUEFALSE
yes
Evaluation Count:543
yes
Evaluation Count:2738
evaluated: r > RowCount - 1
TRUEFALSE
yes
Evaluation Count:33
yes
Evaluation Count:2705
partially evaluated: c < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2705
partially evaluated: c > ColumnCount - 1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2705
0-2738
964 return;
executed: return;
Execution Count:576
576
965 -
966 if (row)
partially evaluated: row
TRUEFALSE
yes
Evaluation Count:2705
no
Evaluation Count:0
0-2705
967 *row = r + m_firstRow;
executed: *row = r + m_firstRow;
Execution Count:2705
2705
968 if (column)
partially evaluated: column
TRUEFALSE
yes
Evaluation Count:2705
no
Evaluation Count:0
0-2705
969 *column = c + m_firstColumn;
executed: *column = c + m_firstColumn;
Execution Count:2705
2705
970}
executed: }
Execution Count:2705
2705
971 -
972QString QCalendarModel::dayName(Qt::DayOfWeek day) const -
973{ -
974 switch (m_horizontalHeaderFormat) { -
975 case QCalendarWidget::SingleLetterDayNames: { -
976 QString standaloneDayName = m_view->locale().standaloneDayName(day, QLocale::NarrowFormat); -
977 if (standaloneDayName == m_view->locale().dayName(day, QLocale::NarrowFormat))
never evaluated: standaloneDayName == m_view->locale().dayName(day, QLocale::NarrowFormat)
0
978 return standaloneDayName.left(1);
never executed: return standaloneDayName.left(1);
0
979 return standaloneDayName;
never executed: return standaloneDayName;
0
980 } -
981 case QCalendarWidget::ShortDayNames: -
982 return m_view->locale().dayName(day, QLocale::ShortFormat);
executed: return m_view->locale().dayName(day, QLocale::ShortFormat);
Execution Count:455
455
983 case QCalendarWidget::LongDayNames: -
984 return m_view->locale().dayName(day, QLocale::LongFormat);
never executed: return m_view->locale().dayName(day, QLocale::LongFormat);
0
985 default: -
986 break;
never executed: break;
0
987 } -
988 return QString();
never executed: return QString();
0
989} -
990 -
991QTextCharFormat QCalendarModel::formatForCell(int row, int col) const -
992{ -
993 QPalette pal; -
994 QPalette::ColorGroup cg = QPalette::Active; -
995 if (m_view) {
partially evaluated: m_view
TRUEFALSE
yes
Evaluation Count:13900
no
Evaluation Count:0
0-13900
996 pal = m_view->palette(); -
997 if (!m_view->isEnabled())
partially evaluated: !m_view->isEnabled()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13900
0-13900
998 cg = QPalette::Disabled;
never executed: cg = QPalette::Disabled;
0
999 else if (!m_view->isActiveWindow())
evaluated: !m_view->isActiveWindow()
TRUEFALSE
yes
Evaluation Count:4682
yes
Evaluation Count:9218
4682-9218
1000 cg = QPalette::Inactive;
executed: cg = QPalette::Inactive;
Execution Count:4682
4682
1001 } -
1002 -
1003 QTextCharFormat format; -
1004 format.setFont(m_view->font()); -
1005 bool header = (m_weekNumbersShown && col == HeaderColumn)
evaluated: m_weekNumbersShown
TRUEFALSE
yes
Evaluation Count:13892
yes
Evaluation Count:8
evaluated: col == HeaderColumn
TRUEFALSE
yes
Evaluation Count:1805
yes
Evaluation Count:12087
8-13892
1006 || (m_horizontalHeaderFormat != QCalendarWidget::NoHorizontalHeader && row == HeaderRow);
partially evaluated: m_horizontalHeaderFormat != QCalendarWidget::NoHorizontalHeader
TRUEFALSE
yes
Evaluation Count:12095
no
Evaluation Count:0
evaluated: row == HeaderRow
TRUEFALSE
yes
Evaluation Count:1827
yes
Evaluation Count:10268
0-12095
1007 format.setBackground(pal.brush(cg, header ? QPalette::AlternateBase : QPalette::Base)); -
1008 format.setForeground(pal.brush(cg, QPalette::Text)); -
1009 if (header) {
evaluated: header
TRUEFALSE
yes
Evaluation Count:3632
yes
Evaluation Count:10268
3632-10268
1010 format.merge(m_headerFormat); -
1011 }
executed: }
Execution Count:3632
3632
1012 -
1013 if (col >= m_firstColumn && col < m_firstColumn + ColumnCount) {
evaluated: col >= m_firstColumn
TRUEFALSE
yes
Evaluation Count:12095
yes
Evaluation Count:1805
evaluated: col < m_firstColumn + ColumnCount
TRUEFALSE
yes
Evaluation Count:12094
yes
Evaluation Count:1
1-12095
1014 Qt::DayOfWeek dayOfWeek = dayOfWeekForColumn(col); -
1015 if (m_dayFormats.contains(dayOfWeek))
evaluated: m_dayFormats.contains(dayOfWeek)
TRUEFALSE
yes
Evaluation Count:3476
yes
Evaluation Count:8618
3476-8618
1016 format.merge(m_dayFormats.value(dayOfWeek));
executed: format.merge(m_dayFormats.value(dayOfWeek));
Execution Count:3476
3476
1017 }
executed: }
Execution Count:12094
12094
1018 -
1019 if (!header) {
evaluated: !header
TRUEFALSE
yes
Evaluation Count:10268
yes
Evaluation Count:3632
3632-10268
1020 QDate date = dateForCell(row, col); -
1021 format.merge(m_dateFormats.value(date)); -
1022 if(date < m_minimumDate || date > m_maximumDate)
evaluated: date < m_minimumDate
TRUEFALSE
yes
Evaluation Count:35
yes
Evaluation Count:10233
partially evaluated: date > m_maximumDate
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10233
0-10233
1023 format.setBackground(pal.brush(cg, QPalette::Window));
executed: format.setBackground(pal.brush(cg, QPalette::Window));
Execution Count:35
35
1024 if (m_shownMonth != date.month())
evaluated: m_shownMonth != date.month()
TRUEFALSE
yes
Evaluation Count:2919
yes
Evaluation Count:7349
2919-7349
1025 format.setForeground(pal.brush(QPalette::Disabled, QPalette::Text));
executed: format.setForeground(pal.brush(QPalette::Disabled, QPalette::Text));
Execution Count:2919
2919
1026 }
executed: }
Execution Count:10268
10268
1027 return format;
executed: return format;
Execution Count:13900
13900
1028} -
1029 -
1030QVariant QCalendarModel::data(const QModelIndex &index, int role) const -
1031{ -
1032 if (role == Qt::TextAlignmentRole)
evaluated: role == Qt::TextAlignmentRole
TRUEFALSE
yes
Evaluation Count:2744
yes
Evaluation Count:16426
2744-16426
1033 return (int) Qt::AlignCenter;
executed: return (int) Qt::AlignCenter;
Execution Count:2744
2744
1034 -
1035 int row = index.row(); -
1036 int column = index.column(); -
1037 -
1038 if(role == Qt::DisplayRole) {
evaluated: role == Qt::DisplayRole
TRUEFALSE
yes
Evaluation Count:2744
yes
Evaluation Count:13682
2744-13682
1039 if (m_weekNumbersShown && column == HeaderColumn
partially evaluated: m_weekNumbersShown
TRUEFALSE
yes
Evaluation Count:2744
no
Evaluation Count:0
evaluated: column == HeaderColumn
TRUEFALSE
yes
Evaluation Count:343
yes
Evaluation Count:2401
0-2744
1040 && row >= m_firstRow && row < m_firstRow + RowCount) {
evaluated: row >= m_firstRow
TRUEFALSE
yes
Evaluation Count:294
yes
Evaluation Count:49
partially evaluated: row < m_firstRow + RowCount
TRUEFALSE
yes
Evaluation Count:294
no
Evaluation Count:0
0-294
1041 QDate date = dateForCell(row, columnForDayOfWeek(Qt::Monday)); -
1042 if (date.isValid())
partially evaluated: date.isValid()
TRUEFALSE
yes
Evaluation Count:294
no
Evaluation Count:0
0-294
1043 return date.weekNumber();
executed: return date.weekNumber();
Execution Count:294
294
1044 }
never executed: }
0
1045 if (m_horizontalHeaderFormat != QCalendarWidget::NoHorizontalHeader && row == HeaderRow
partially evaluated: m_horizontalHeaderFormat != QCalendarWidget::NoHorizontalHeader
TRUEFALSE
yes
Evaluation Count:2450
no
Evaluation Count:0
evaluated: row == HeaderRow
TRUEFALSE
yes
Evaluation Count:392
yes
Evaluation Count:2058
0-2450
1046 && column >= m_firstColumn && column < m_firstColumn + ColumnCount)
evaluated: column >= m_firstColumn
TRUEFALSE
yes
Evaluation Count:343
yes
Evaluation Count:49
partially evaluated: column < m_firstColumn + ColumnCount
TRUEFALSE
yes
Evaluation Count:343
no
Evaluation Count:0
0-343
1047 return dayName(dayOfWeekForColumn(column));
executed: return dayName(dayOfWeekForColumn(column));
Execution Count:343
343
1048 QDate date = dateForCell(row, column); -
1049 if (date.isValid())
evaluated: date.isValid()
TRUEFALSE
yes
Evaluation Count:2058
yes
Evaluation Count:49
49-2058
1050 return date.day();
executed: return date.day();
Execution Count:2058
2058
1051 return QString();
executed: return QString();
Execution Count:49
49
1052 } -
1053 -
1054 QTextCharFormat fmt = formatForCell(row, column); -
1055 if (role == Qt::BackgroundColorRole)
evaluated: role == Qt::BackgroundColorRole
TRUEFALSE
yes
Evaluation Count:2706
yes
Evaluation Count:10976
2706-10976
1056 return fmt.background().color();
executed: return fmt.background().color();
Execution Count:2706
2706
1057 if (role == Qt::TextColorRole)
evaluated: role == Qt::TextColorRole
TRUEFALSE
yes
Evaluation Count:2744
yes
Evaluation Count:8232
2744-8232
1058 return fmt.foreground().color();
executed: return fmt.foreground().color();
Execution Count:2744
2744
1059 if (role == Qt::FontRole)
evaluated: role == Qt::FontRole
TRUEFALSE
yes
Evaluation Count:2744
yes
Evaluation Count:5488
2744-5488
1060 return fmt.font();
executed: return fmt.font();
Execution Count:2744
2744
1061 if (role == Qt::ToolTipRole)
partially evaluated: role == Qt::ToolTipRole
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5488
0-5488
1062 return fmt.toolTip();
never executed: return fmt.toolTip();
0
1063 return QVariant();
executed: return QVariant();
Execution Count:5488
5488
1064} -
1065 -
1066Qt::ItemFlags QCalendarModel::flags(const QModelIndex &index) const -
1067{ -
1068 QDate date = dateForCell(index.row(), index.column()); -
1069 if (!date.isValid())
evaluated: !date.isValid()
TRUEFALSE
yes
Evaluation Count:1218
yes
Evaluation Count:3755
1218-3755
1070 return QAbstractTableModel::flags(index);
executed: return QAbstractTableModel::flags(index);
Execution Count:1218
1218
1071 if (date < m_minimumDate)
evaluated: date < m_minimumDate
TRUEFALSE
yes
Evaluation Count:14
yes
Evaluation Count:3741
14-3741
1072 return 0;
executed: return 0;
Execution Count:14
14
1073 if (date > m_maximumDate)
partially evaluated: date > m_maximumDate
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3741
0-3741
1074 return 0;
never executed: return 0;
0
1075 return QAbstractTableModel::flags(index);
executed: return QAbstractTableModel::flags(index);
Execution Count:3741
3741
1076} -
1077 -
1078void QCalendarModel::setDate(const QDate &d) -
1079{ -
1080 m_date = d; -
1081 if (m_date < m_minimumDate)
evaluated: m_date < m_minimumDate
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:550
1-550
1082 m_date = m_minimumDate;
executed: m_date = m_minimumDate;
Execution Count:1
1
1083 else if (m_date > m_maximumDate)
evaluated: m_date > m_maximumDate
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:549
1-549
1084 m_date = m_maximumDate;
executed: m_date = m_maximumDate;
Execution Count:1
1
1085} -
1086 -
1087void QCalendarModel::showMonth(int year, int month) -
1088{ -
1089 if (m_shownYear == year && m_shownMonth == month)
evaluated: m_shownYear == year
TRUEFALSE
yes
Evaluation Count:26
yes
Evaluation Count:560
partially evaluated: m_shownMonth == month
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:26
0-560
1090 return;
never executed: return;
0
1091 -
1092 m_shownYear = year; -
1093 m_shownMonth = month; -
1094 -
1095 internalUpdate(); -
1096}
executed: }
Execution Count:586
586
1097 -
1098void QCalendarModel::setMinimumDate(const QDate &d) -
1099{ -
1100 if (!d.isValid() || d == m_minimumDate)
partially evaluated: !d.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:18
partially evaluated: d == m_minimumDate
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:18
0-18
1101 return;
never executed: return;
0
1102 -
1103 m_minimumDate = d; -
1104 if (m_maximumDate < m_minimumDate)
partially evaluated: m_maximumDate < m_minimumDate
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:18
0-18
1105 m_maximumDate = m_minimumDate;
never executed: m_maximumDate = m_minimumDate;
0
1106 if (m_date < m_minimumDate)
evaluated: m_date < m_minimumDate
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:16
2-16
1107 m_date = m_minimumDate;
executed: m_date = m_minimumDate;
Execution Count:2
2
1108 internalUpdate(); -
1109}
executed: }
Execution Count:18
18
1110 -
1111void QCalendarModel::setMaximumDate(const QDate &d) -
1112{ -
1113 if (!d.isValid() || d == m_maximumDate)
partially evaluated: !d.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
partially evaluated: d == m_maximumDate
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
0-13
1114 return;
never executed: return;
0
1115 -
1116 m_maximumDate = d; -
1117 if (m_minimumDate > m_maximumDate)
partially evaluated: m_minimumDate > m_maximumDate
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
0-13
1118 m_minimumDate = m_maximumDate;
never executed: m_minimumDate = m_maximumDate;
0
1119 if (m_date > m_maximumDate)
evaluated: m_date > m_maximumDate
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:10
3-10
1120 m_date = m_maximumDate;
executed: m_date = m_maximumDate;
Execution Count:3
3
1121 internalUpdate(); -
1122}
executed: }
Execution Count:13
13
1123 -
1124void QCalendarModel::setRange(const QDate &min, const QDate &max) -
1125{ -
1126 m_minimumDate = min; -
1127 m_maximumDate = max; -
1128 if (m_minimumDate > m_maximumDate)
partially evaluated: m_minimumDate > m_maximumDate
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
1129 qSwap(m_minimumDate, m_maximumDate);
never executed: qSwap(m_minimumDate, m_maximumDate);
0
1130 if (m_date < m_minimumDate)
partially evaluated: m_date < m_minimumDate
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
1131 m_date = m_minimumDate;
executed: m_date = m_minimumDate;
Execution Count:2
2
1132 if (m_date > m_maximumDate)
partially evaluated: m_date > m_maximumDate
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
1133 m_date = m_maximumDate;
never executed: m_date = m_maximumDate;
0
1134 internalUpdate(); -
1135}
executed: }
Execution Count:2
2
1136 -
1137void QCalendarModel::internalUpdate() -
1138{ -
1139 QModelIndex begin = index(0, 0); -
1140 QModelIndex end = index(m_firstRow + RowCount - 1, m_firstColumn + ColumnCount - 1); -
1141 dataChanged(begin, end); -
1142 headerDataChanged(Qt::Vertical, 0, m_firstRow + RowCount - 1); -
1143 headerDataChanged(Qt::Horizontal, 0, m_firstColumn + ColumnCount - 1); -
1144}
executed: }
Execution Count:630
630
1145 -
1146void QCalendarModel::setHorizontalHeaderFormat(QCalendarWidget::HorizontalHeaderFormat format) -
1147{ -
1148 if (m_horizontalHeaderFormat == format)
partially evaluated: m_horizontalHeaderFormat == format
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
1149 return;
never executed: return;
0
1150 -
1151 int oldFormat = m_horizontalHeaderFormat; -
1152 m_horizontalHeaderFormat = format; -
1153 if (oldFormat == QCalendarWidget::NoHorizontalHeader) {
evaluated: oldFormat == QCalendarWidget::NoHorizontalHeader
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:3
1-3
1154 m_firstRow = 1; -
1155 insertRow(0); -
1156 } else if (m_horizontalHeaderFormat == QCalendarWidget::NoHorizontalHeader) {
executed: }
Execution Count:1
evaluated: m_horizontalHeaderFormat == QCalendarWidget::NoHorizontalHeader
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2
1-2
1157 m_firstRow = 0; -
1158 removeRow(0); -
1159 }
executed: }
Execution Count:1
1
1160 internalUpdate(); -
1161}
executed: }
Execution Count:4
4
1162 -
1163void QCalendarModel::setFirstColumnDay(Qt::DayOfWeek dayOfWeek) -
1164{ -
1165 if (m_firstDay == dayOfWeek)
evaluated: m_firstDay == dayOfWeek
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:2
2-3
1166 return;
executed: return;
Execution Count:3
3
1167 -
1168 m_firstDay = dayOfWeek; -
1169 internalUpdate(); -
1170}
executed: }
Execution Count:2
2
1171 -
1172Qt::DayOfWeek QCalendarModel::firstColumnDay() const -
1173{ -
1174 return m_firstDay;
executed: return m_firstDay;
Execution Count:8
8
1175} -
1176 -
1177bool QCalendarModel::weekNumbersShown() const -
1178{ -
1179 return m_weekNumbersShown;
executed: return m_weekNumbersShown;
Execution Count:24
24
1180} -
1181 -
1182void QCalendarModel::setWeekNumbersShown(bool show) -
1183{ -
1184 if (m_weekNumbersShown == show)
partially evaluated: m_weekNumbersShown == show
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5
0-5
1185 return;
never executed: return;
0
1186 -
1187 m_weekNumbersShown = show; -
1188 if (show) {
partially evaluated: show
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5
0-5
1189 m_firstColumn = 1; -
1190 insertColumn(0); -
1191 } else {
never executed: }
0
1192 m_firstColumn = 0; -
1193 removeColumn(0); -
1194 }
executed: }
Execution Count:5
5
1195 internalUpdate(); -
1196}
executed: }
Execution Count:5
5
1197 -
1198QCalendarView::QCalendarView(QWidget *parent) -
1199 : QTableView(parent), -
1200 readOnly(false), -
1201 validDateClicked(false) -
1202{ -
1203 setTabKeyNavigation(false); -
1204 setShowGrid(false); -
1205 verticalHeader()->setVisible(false); -
1206 horizontalHeader()->setVisible(false); -
1207 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); -
1208 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); -
1209}
executed: }
Execution Count:27
27
1210 -
1211QModelIndex QCalendarView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) -
1212{ -
1213 QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model()); -
1214 if (!calendarModel)
partially evaluated: !calendarModel
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
1215 return QTableView::moveCursor(cursorAction, modifiers);
never executed: return QTableView::moveCursor(cursorAction, modifiers);
0
1216 -
1217 if (readOnly)
partially evaluated: readOnly
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
1218 return currentIndex();
never executed: return currentIndex();
0
1219 -
1220 QModelIndex index = currentIndex(); -
1221 QDate currentDate = static_cast<QCalendarModel*>(model())->dateForCell(index.row(), index.column()); -
1222 switch (cursorAction) { -
1223 case QAbstractItemView::MoveUp: -
1224 currentDate = currentDate.addDays(-7); -
1225 break;
never executed: break;
0
1226 case QAbstractItemView::MoveDown: -
1227 currentDate = currentDate.addDays(7); -
1228 break;
executed: break;
Execution Count:1
1
1229 case QAbstractItemView::MoveLeft: -
1230 currentDate = currentDate.addDays(isRightToLeft() ? 1 : -1); -
1231 break;
never executed: break;
0
1232 case QAbstractItemView::MoveRight: -
1233 currentDate = currentDate.addDays(isRightToLeft() ? -1 : 1); -
1234 break;
never executed: break;
0
1235 case QAbstractItemView::MoveHome: -
1236 currentDate = QDate(currentDate.year(), currentDate.month(), 1); -
1237 break;
never executed: break;
0
1238 case QAbstractItemView::MoveEnd: -
1239 currentDate = QDate(currentDate.year(), currentDate.month(), currentDate.daysInMonth()); -
1240 break;
never executed: break;
0
1241 case QAbstractItemView::MovePageUp: -
1242 currentDate = currentDate.addMonths(-1); -
1243 break;
never executed: break;
0
1244 case QAbstractItemView::MovePageDown: -
1245 currentDate = currentDate.addMonths(1); -
1246 break;
never executed: break;
0
1247 case QAbstractItemView::MoveNext: -
1248 case QAbstractItemView::MovePrevious: -
1249 return currentIndex();
never executed: return currentIndex();
0
1250 default: -
1251 break;
never executed: break;
0
1252 } -
1253 changeDate(currentDate, true); -
1254 return currentIndex();
executed: return currentIndex();
Execution Count:1
1
1255} -
1256 -
1257void QCalendarView::keyPressEvent(QKeyEvent *event) -
1258{ -
1259 if (!readOnly) {
partially evaluated: !readOnly
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
1260 switch (event->key()) { -
1261 case Qt::Key_Return: -
1262 case Qt::Key_Enter: -
1263 case Qt::Key_Select: -
1264 editingFinished(); -
1265 return;
never executed: return;
0
1266 default: -
1267 break;
executed: break;
Execution Count:1
1
1268 } -
1269 }
executed: }
Execution Count:1
1
1270 QTableView::keyPressEvent(event); -
1271}
executed: }
Execution Count:1
1
1272 -
1273 -
1274void QCalendarView::wheelEvent(QWheelEvent *event) -
1275{ -
1276 const int numDegrees = event->delta() / 8; -
1277 const int numSteps = numDegrees / 15; -
1278 const QModelIndex index = currentIndex(); -
1279 QDate currentDate = static_cast<QCalendarModel*>(model())->dateForCell(index.row(), index.column()); -
1280 currentDate = currentDate.addMonths(-numSteps); -
1281 showDate(currentDate); -
1282}
never executed: }
0
1283 -
1284 -
1285bool QCalendarView::event(QEvent *event) -
1286{ -
1287 return QTableView::event(event);
executed: return QTableView::event(event);
Execution Count:590
590
1288} -
1289 -
1290QDate QCalendarView::handleMouseEvent(QMouseEvent *event) -
1291{ -
1292 QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model()); -
1293 if (!calendarModel)
never evaluated: !calendarModel
0
1294 return QDate();
never executed: return QDate();
0
1295 -
1296 QPoint pos = event->pos(); -
1297 QModelIndex index = indexAt(pos); -
1298 QDate date = calendarModel->dateForCell(index.row(), index.column()); -
1299 if (date.isValid() && date >= calendarModel->m_minimumDate
never evaluated: date.isValid()
never evaluated: date >= calendarModel->m_minimumDate
0
1300 && date <= calendarModel->m_maximumDate) {
never evaluated: date <= calendarModel->m_maximumDate
0
1301 return date;
never executed: return date;
0
1302 } -
1303 return QDate();
never executed: return QDate();
0
1304} -
1305 -
1306void QCalendarView::mouseDoubleClickEvent(QMouseEvent *event) -
1307{ -
1308 QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model()); -
1309 if (!calendarModel) {
never evaluated: !calendarModel
0
1310 QTableView::mouseDoubleClickEvent(event); -
1311 return;
never executed: return;
0
1312 } -
1313 -
1314 if (readOnly)
never evaluated: readOnly
0
1315 return;
never executed: return;
0
1316 -
1317 QDate date = handleMouseEvent(event); -
1318 validDateClicked = false; -
1319 if (date == calendarModel->m_date && !style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick)) {
never evaluated: date == calendarModel->m_date
never evaluated: !style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick)
0
1320 editingFinished(); -
1321 }
never executed: }
0
1322}
never executed: }
0
1323 -
1324void QCalendarView::mousePressEvent(QMouseEvent *event) -
1325{ -
1326 QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model()); -
1327 if (!calendarModel) {
never evaluated: !calendarModel
0
1328 QTableView::mousePressEvent(event); -
1329 return;
never executed: return;
0
1330 } -
1331 -
1332 if (readOnly)
never evaluated: readOnly
0
1333 return;
never executed: return;
0
1334 -
1335 if (event->button() != Qt::LeftButton)
never evaluated: event->button() != Qt::LeftButton
0
1336 return;
never executed: return;
0
1337 -
1338 QDate date = handleMouseEvent(event); -
1339 if (date.isValid()) {
never evaluated: date.isValid()
0
1340 validDateClicked = true; -
1341 int row = -1, col = -1; -
1342 static_cast<QCalendarModel *>(model())->cellForDate(date, &row, &col); -
1343 if (row != -1 && col != -1) {
never evaluated: row != -1
never evaluated: col != -1
0
1344 selectionModel()->setCurrentIndex(model()->index(row, col), QItemSelectionModel::NoUpdate); -
1345 }
never executed: }
0
1346 } else {
never executed: }
0
1347 validDateClicked = false; -
1348 event->ignore(); -
1349 }
never executed: }
0
1350} -
1351 -
1352void QCalendarView::mouseMoveEvent(QMouseEvent *event) -
1353{ -
1354 QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model()); -
1355 if (!calendarModel) {
never evaluated: !calendarModel
0
1356 QTableView::mouseMoveEvent(event); -
1357 return;
never executed: return;
0
1358 } -
1359 -
1360 if (readOnly)
never evaluated: readOnly
0
1361 return;
never executed: return;
0
1362 -
1363 if (validDateClicked) {
never evaluated: validDateClicked
0
1364 QDate date = handleMouseEvent(event); -
1365 if (date.isValid()) {
never evaluated: date.isValid()
0
1366 int row = -1, col = -1; -
1367 static_cast<QCalendarModel *>(model())->cellForDate(date, &row, &col); -
1368 if (row != -1 && col != -1) {
never evaluated: row != -1
never evaluated: col != -1
0
1369 selectionModel()->setCurrentIndex(model()->index(row, col), QItemSelectionModel::NoUpdate); -
1370 }
never executed: }
0
1371 }
never executed: }
0
1372 } else {
never executed: }
0
1373 event->ignore(); -
1374 }
never executed: }
0
1375} -
1376 -
1377void QCalendarView::mouseReleaseEvent(QMouseEvent *event) -
1378{ -
1379 QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model()); -
1380 if (!calendarModel) {
never evaluated: !calendarModel
0
1381 QTableView::mouseReleaseEvent(event); -
1382 return;
never executed: return;
0
1383 } -
1384 -
1385 if (event->button() != Qt::LeftButton)
never evaluated: event->button() != Qt::LeftButton
0
1386 return;
never executed: return;
0
1387 -
1388 if (readOnly)
never evaluated: readOnly
0
1389 return;
never executed: return;
0
1390 -
1391 if (validDateClicked) {
never evaluated: validDateClicked
0
1392 QDate date = handleMouseEvent(event); -
1393 if (date.isValid()) {
never evaluated: date.isValid()
0
1394 changeDate(date, true); -
1395 clicked(date); -
1396 if (style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick))
never evaluated: style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick)
0
1397 editingFinished();
never executed: editingFinished();
0
1398 }
never executed: }
0
1399 validDateClicked = false; -
1400 } else {
never executed: }
0
1401 event->ignore(); -
1402 }
never executed: }
0
1403} -
1404 -
1405class QCalendarDelegate : public QItemDelegate -
1406{ -
1407 public: template <typename T> inline void qt_check_for_QOBJECT_macro(const T &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); static inline QString tr(const char *s, const char *c = 0, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = 0, int n = -1) { return staticMetaObject.tr(s, c, n); } virtual int qt_metacall(QMetaObject::Call, int, void **); private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); struct QPrivateSignal {}; -
1408public: -
1409 QCalendarDelegate(QCalendarWidgetPrivate *w, QObject *parent = 0) -
1410 : QItemDelegate(parent), calendarWidgetPrivate(w) -
1411 { }
executed: }
Execution Count:27
27
1412 virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, -
1413 const QModelIndex &index) const; -
1414 void paintCell(QPainter *painter, const QRect &rect, const QDate &date) const; -
1415 -
1416private: -
1417 QCalendarWidgetPrivate *calendarWidgetPrivate; -
1418 mutable QStyleOptionViewItem storedOption; -
1419}; -
1420 -
1421 -
1422class QCalToolButton: public QToolButton -
1423{ -
1424public: -
1425 QCalToolButton(QWidget * parent) -
1426 : QToolButton(parent) -
1427 { }
executed: }
Execution Count:54
54
1428protected: -
1429 void paintEvent(QPaintEvent *e) -
1430 { -
1431 (void)e; -
1432 -
1433 -
1434 QStyleOptionToolButton opt; -
1435 initStyleOption(&opt); -
1436 -
1437 if (opt.state & QStyle::State_MouseOver || isDown()) {
partially evaluated: opt.state & QStyle::State_MouseOver
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:93
evaluated: isDown()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:92
0-93
1438 -
1439 setPalette(QPalette()); -
1440 } else {
executed: }
Execution Count:1
1
1441 -
1442 QPalette toolPalette = palette(); -
1443 toolPalette.setColor(QPalette::ButtonText, toolPalette.color(QPalette::HighlightedText)); -
1444 setPalette(toolPalette); -
1445 }
executed: }
Execution Count:92
92
1446 -
1447 QToolButton::paintEvent(e); -
1448 }
executed: }
Execution Count:93
93
1449}; -
1450 -
1451class QPrevNextCalButton : public QToolButton -
1452{ -
1453 public: template <typename T> inline void qt_check_for_QOBJECT_macro(const T &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); static inline QString tr(const char *s, const char *c = 0, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = 0, int n = -1) { return staticMetaObject.tr(s, c, n); } virtual int qt_metacall(QMetaObject::Call, int, void **); private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); struct QPrivateSignal {}; -
1454public: -
1455 QPrevNextCalButton(QWidget *parent) : QToolButton(parent) {}
executed: }
Execution Count:54
54
1456protected: -
1457 void paintEvent(QPaintEvent *) { -
1458 QStylePainter painter(this); -
1459 QStyleOptionToolButton opt; -
1460 initStyleOption(&opt); -
1461 opt.state &= ~QStyle::State_HasFocus; -
1462 painter.drawComplexControl(QStyle::CC_ToolButton, opt); -
1463 }
executed: }
Execution Count:66
66
1464}; -
1465 -
1466class QCalendarWidgetPrivate : public QWidgetPrivate -
1467{ -
1468 inline QCalendarWidget* q_func() { return static_cast<QCalendarWidget *>(q_ptr); } inline const QCalendarWidget* q_func() const { return static_cast<const QCalendarWidget *>(q_ptr); } friend class QCalendarWidget; -
1469public: -
1470 QCalendarWidgetPrivate(); -
1471 -
1472 void showMonth(int year, int month); -
1473 void update(); -
1474 void paintCell(QPainter *painter, const QRect &rect, const QDate &date) const; -
1475 -
1476 void _q_slotShowDate(const QDate &date); -
1477 void _q_slotChangeDate(const QDate &date); -
1478 void _q_slotChangeDate(const QDate &date, bool changeMonth); -
1479 void _q_editingFinished(); -
1480 void _q_monthChanged(QAction*); -
1481 void _q_prevMonthClicked(); -
1482 void _q_nextMonthClicked(); -
1483 void _q_yearEditingFinished(); -
1484 void _q_yearClicked(); -
1485 -
1486 void createNavigationBar(QWidget *widget); -
1487 void updateButtonIcons(); -
1488 void updateMonthMenu(); -
1489 void updateMonthMenuNames(); -
1490 void updateNavigationBar(); -
1491 void updateCurrentPage(const QDate &newDate); -
1492 inline QDate getCurrentDate(); -
1493 void setNavigatorEnabled(bool enable); -
1494 -
1495 QCalendarModel *m_model; -
1496 QCalendarView *m_view; -
1497 QCalendarDelegate *m_delegate; -
1498 QItemSelectionModel *m_selection; -
1499 QCalendarTextNavigator *m_navigator; -
1500 bool m_dateEditEnabled; -
1501 -
1502 QToolButton *nextMonth; -
1503 QToolButton *prevMonth; -
1504 QCalToolButton *monthButton; -
1505 QMenu *monthMenu; -
1506 QMap<int, QAction *> monthToAction; -
1507 QCalToolButton *yearButton; -
1508 QSpinBox *yearEdit; -
1509 QWidget *navBarBackground; -
1510 QSpacerItem *spaceHolder; -
1511 -
1512 bool navBarVisible; -
1513 mutable QSize cachedSizeHint; -
1514 Qt::FocusPolicy oldFocusPolicy; -
1515}; -
1516 -
1517void QCalendarDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, -
1518 const QModelIndex &index) const -
1519{ -
1520 QDate date = calendarWidgetPrivate->m_model->dateForCell(index.row(), index.column()); -
1521 if (date.isValid()) {
evaluated: date.isValid()
TRUEFALSE
yes
Evaluation Count:2058
yes
Evaluation Count:686
686-2058
1522 storedOption = option; -
1523 QRect rect = option.rect; -
1524 calendarWidgetPrivate->paintCell(painter, rect, date); -
1525 } else {
executed: }
Execution Count:2058
2058
1526 QItemDelegate::paint(painter, option, index); -
1527 }
executed: }
Execution Count:686
686
1528} -
1529 -
1530void QCalendarDelegate::paintCell(QPainter *painter, const QRect &rect, const QDate &date) const -
1531{ -
1532 storedOption.rect = rect; -
1533 int row = -1; -
1534 int col = -1; -
1535 calendarWidgetPrivate->m_model->cellForDate(date, &row, &col); -
1536 QModelIndex idx = calendarWidgetPrivate->m_model->index(row, col); -
1537 QItemDelegate::paint(painter, storedOption, idx); -
1538}
executed: }
Execution Count:2058
2058
1539 -
1540QCalendarWidgetPrivate::QCalendarWidgetPrivate() -
1541 : QWidgetPrivate() -
1542{ -
1543 m_model = 0; -
1544 m_view = 0; -
1545 m_delegate = 0; -
1546 m_selection = 0; -
1547 m_navigator = 0; -
1548 m_dateEditEnabled = false; -
1549 navBarVisible = true; -
1550 oldFocusPolicy = Qt::StrongFocus; -
1551}
executed: }
Execution Count:27
27
1552 -
1553void QCalendarWidgetPrivate::setNavigatorEnabled(bool enable) -
1554{ -
1555 QCalendarWidget * const q = q_func(); -
1556 -
1557 bool navigatorEnabled = (m_navigator->widget() != 0); -
1558 if (enable == navigatorEnabled)
partially evaluated: enable == navigatorEnabled
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:29
0-29
1559 return;
never executed: return;
0
1560 -
1561 if (enable) {
evaluated: enable
TRUEFALSE
yes
Evaluation Count:28
yes
Evaluation Count:1
1-28
1562 m_navigator->setWidget(q); -
1563 q->connect(m_navigator, "2""dateChanged(QDate)", -
1564 q, "1""_q_slotChangeDate(QDate)"); -
1565 q->connect(m_navigator, "2""editingFinished()", -
1566 q, "1""_q_editingFinished()"); -
1567 m_view->installEventFilter(m_navigator); -
1568 } else {
executed: }
Execution Count:28
28
1569 m_navigator->setWidget(0); -
1570 q->disconnect(m_navigator, "2""dateChanged(QDate)", -
1571 q, "1""_q_slotChangeDate(QDate)"); -
1572 q->disconnect(m_navigator, "2""editingFinished()", -
1573 q, "1""_q_editingFinished()"); -
1574 m_view->removeEventFilter(m_navigator); -
1575 }
executed: }
Execution Count:1
1
1576} -
1577 -
1578void QCalendarWidgetPrivate::createNavigationBar(QWidget *widget) -
1579{ -
1580 QCalendarWidget * const q = q_func(); -
1581 navBarBackground = new QWidget(widget); -
1582 navBarBackground->setObjectName(QLatin1String("qt_calendar_navigationbar")); -
1583 navBarBackground->setAutoFillBackground(true); -
1584 navBarBackground->setBackgroundRole(QPalette::Highlight); -
1585 -
1586 prevMonth = new QPrevNextCalButton(navBarBackground); -
1587 nextMonth = new QPrevNextCalButton(navBarBackground); -
1588 prevMonth->setAutoRaise(true); -
1589 nextMonth->setAutoRaise(true); -
1590 prevMonth->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); -
1591 nextMonth->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); -
1592 nextMonth->setAutoRaise(true); -
1593 updateButtonIcons(); -
1594 prevMonth->setAutoRepeat(true); -
1595 nextMonth->setAutoRepeat(true); -
1596 -
1597 monthButton = new QCalToolButton(navBarBackground); -
1598 monthButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); -
1599 monthButton->setAutoRaise(true); -
1600 monthButton->setPopupMode(QToolButton::InstantPopup); -
1601 monthMenu = new QMenu(monthButton); -
1602 for (int i = 1; i <= 12; i++) {
evaluated: i <= 12
TRUEFALSE
yes
Evaluation Count:324
yes
Evaluation Count:27
27-324
1603 QString monthName(q->locale().standaloneMonthName(i, QLocale::LongFormat)); -
1604 QAction *act = monthMenu->addAction(monthName); -
1605 act->setData(i); -
1606 monthToAction[i] = act; -
1607 }
executed: }
Execution Count:324
324
1608 monthButton->setMenu(monthMenu); -
1609 yearButton = new QCalToolButton(navBarBackground); -
1610 yearButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); -
1611 yearButton->setAutoRaise(true); -
1612 yearEdit = new QSpinBox(navBarBackground); -
1613 -
1614 QFont font = q->font(); -
1615 font.setBold(true); -
1616 monthButton->setFont(font); -
1617 yearButton->setFont(font); -
1618 yearEdit->setFrame(false); -
1619 yearEdit->setMinimum(m_model->m_minimumDate.year()); -
1620 yearEdit->setMaximum(m_model->m_maximumDate.year()); -
1621 yearEdit->hide(); -
1622 spaceHolder = new QSpacerItem(0,0); -
1623 -
1624 QHBoxLayout *headerLayout = new QHBoxLayout; -
1625 headerLayout->setMargin(0); -
1626 headerLayout->setSpacing(0); -
1627 headerLayout->addWidget(prevMonth); -
1628 headerLayout->insertStretch(headerLayout->count()); -
1629 headerLayout->addWidget(monthButton); -
1630 headerLayout->addItem(spaceHolder); -
1631 headerLayout->addWidget(yearButton); -
1632 headerLayout->insertStretch(headerLayout->count()); -
1633 headerLayout->addWidget(nextMonth); -
1634 navBarBackground->setLayout(headerLayout); -
1635 -
1636 yearEdit->setFocusPolicy(Qt::StrongFocus); -
1637 prevMonth->setFocusPolicy(Qt::NoFocus); -
1638 nextMonth->setFocusPolicy(Qt::NoFocus); -
1639 yearButton->setFocusPolicy(Qt::NoFocus); -
1640 monthButton->setFocusPolicy(Qt::NoFocus); -
1641 -
1642 -
1643 prevMonth->setObjectName(QLatin1String("qt_calendar_prevmonth")); -
1644 nextMonth->setObjectName(QLatin1String("qt_calendar_nextmonth")); -
1645 monthButton->setObjectName(QLatin1String("qt_calendar_monthbutton")); -
1646 yearButton->setObjectName(QLatin1String("qt_calendar_yearbutton")); -
1647 yearEdit->setObjectName(QLatin1String("qt_calendar_yearedit")); -
1648 -
1649 updateMonthMenu(); -
1650 showMonth(m_model->m_date.year(), m_model->m_date.month()); -
1651}
executed: }
Execution Count:27
27
1652 -
1653void QCalendarWidgetPrivate::updateButtonIcons() -
1654{ -
1655 QCalendarWidget * const q = q_func(); -
1656 prevMonth->setIcon(q->style()->standardIcon(q->isRightToLeft() ? QStyle::SP_ArrowRight : QStyle::SP_ArrowLeft, 0, q)); -
1657 nextMonth->setIcon(q->style()->standardIcon(q->isRightToLeft() ? QStyle::SP_ArrowLeft : QStyle::SP_ArrowRight, 0, q)); -
1658}
executed: }
Execution Count:29
29
1659 -
1660void QCalendarWidgetPrivate::updateMonthMenu() -
1661{ -
1662 int beg = 1, end = 12; -
1663 bool prevEnabled = true; -
1664 bool nextEnabled = true; -
1665 if (m_model->m_shownYear == m_model->m_minimumDate.year()) {
evaluated: m_model->m_shownYear == m_model->m_minimumDate.year()
TRUEFALSE
yes
Evaluation Count:22
yes
Evaluation Count:624
22-624
1666 beg = m_model->m_minimumDate.month(); -
1667 if (m_model->m_shownMonth == m_model->m_minimumDate.month())
evaluated: m_model->m_shownMonth == m_model->m_minimumDate.month()
TRUEFALSE
yes
Evaluation Count:16
yes
Evaluation Count:6
6-16
1668 prevEnabled = false;
executed: prevEnabled = false;
Execution Count:16
16
1669 }
executed: }
Execution Count:22
22
1670 if (m_model->m_shownYear == m_model->m_maximumDate.year()) {
evaluated: m_model->m_shownYear == m_model->m_maximumDate.year()
TRUEFALSE
yes
Evaluation Count:16
yes
Evaluation Count:630
16-630
1671 end = m_model->m_maximumDate.month(); -
1672 if (m_model->m_shownMonth == m_model->m_maximumDate.month())
evaluated: m_model->m_shownMonth == m_model->m_maximumDate.month()
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:3
3-13
1673 nextEnabled = false;
executed: nextEnabled = false;
Execution Count:13
13
1674 }
executed: }
Execution Count:16
16
1675 prevMonth->setEnabled(prevEnabled); -
1676 nextMonth->setEnabled(nextEnabled); -
1677 for (int i = 1; i <= 12; i++) {
evaluated: i <= 12
TRUEFALSE
yes
Evaluation Count:7752
yes
Evaluation Count:646
646-7752
1678 bool monthEnabled = true; -
1679 if (i < beg || i > end)
evaluated: i < beg
TRUEFALSE
yes
Evaluation Count:51
yes
Evaluation Count:7701
evaluated: i > end
TRUEFALSE
yes
Evaluation Count:116
yes
Evaluation Count:7585
51-7701
1680 monthEnabled = false;
executed: monthEnabled = false;
Execution Count:167
167
1681 monthToAction[i]->setEnabled(monthEnabled); -
1682 }
executed: }
Execution Count:7752
7752
1683}
executed: }
Execution Count:646
646
1684 -
1685void QCalendarWidgetPrivate::updateMonthMenuNames() -
1686{ -
1687 QCalendarWidget * const q = q_func(); -
1688 -
1689 for (int i = 1; i <= 12; i++) {
evaluated: i <= 12
TRUEFALSE
yes
Evaluation Count:48
yes
Evaluation Count:4
4-48
1690 QString monthName(q->locale().standaloneMonthName(i, QLocale::LongFormat)); -
1691 monthToAction[i]->setText(monthName); -
1692 }
executed: }
Execution Count:48
48
1693}
executed: }
Execution Count:4
4
1694 -
1695void QCalendarWidgetPrivate::updateCurrentPage(const QDate &date) -
1696{ -
1697 QCalendarWidget * const q = q_func(); -
1698 -
1699 QDate newDate = date; -
1700 QDate minDate = q->minimumDate(); -
1701 QDate maxDate = q->maximumDate(); -
1702 if (minDate.isValid()&& minDate.daysTo(newDate) < 0)
partially evaluated: minDate.isValid()
TRUEFALSE
yes
Evaluation Count:18
no
Evaluation Count:0
partially evaluated: minDate.daysTo(newDate) < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:18
0-18
1703 newDate = minDate;
never executed: newDate = minDate;
0
1704 if (maxDate.isValid()&& maxDate.daysTo(newDate) > 0)
partially evaluated: maxDate.isValid()
TRUEFALSE
yes
Evaluation Count:18
no
Evaluation Count:0
partially evaluated: maxDate.daysTo(newDate) > 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:18
0-18
1705 newDate = maxDate;
never executed: newDate = maxDate;
0
1706 showMonth(newDate.year(), newDate.month()); -
1707 int row = -1, col = -1; -
1708 m_model->cellForDate(newDate, &row, &col); -
1709 if (row != -1 && col != -1)
partially evaluated: row != -1
TRUEFALSE
yes
Evaluation Count:18
no
Evaluation Count:0
partially evaluated: col != -1
TRUEFALSE
yes
Evaluation Count:18
no
Evaluation Count:0
0-18
1710 { -
1711 m_view->selectionModel()->setCurrentIndex(m_model->index(row, col), -
1712 QItemSelectionModel::NoUpdate); -
1713 }
executed: }
Execution Count:18
18
1714}
executed: }
Execution Count:18
18
1715 -
1716void QCalendarWidgetPrivate::_q_monthChanged(QAction *act) -
1717{ -
1718 monthButton->setText(act->text()); -
1719 QDate currentDate = getCurrentDate(); -
1720 QDate newDate = currentDate.addMonths(act->data().toInt()-currentDate.month()); -
1721 updateCurrentPage(newDate); -
1722}
never executed: }
0
1723 -
1724QDate QCalendarWidgetPrivate::getCurrentDate() -
1725{ -
1726 QModelIndex index = m_view->currentIndex(); -
1727 return m_model->dateForCell(index.row(), index.column());
executed: return m_model->dateForCell(index.row(), index.column());
Execution Count:217
217
1728} -
1729 -
1730void QCalendarWidgetPrivate::_q_prevMonthClicked() -
1731{ -
1732 QDate currentDate = getCurrentDate().addMonths(-1); -
1733 updateCurrentPage(currentDate); -
1734}
executed: }
Execution Count:14
14
1735 -
1736void QCalendarWidgetPrivate::_q_nextMonthClicked() -
1737{ -
1738 QDate currentDate = getCurrentDate().addMonths(1); -
1739 updateCurrentPage(currentDate); -
1740}
executed: }
Execution Count:2
2
1741 -
1742void QCalendarWidgetPrivate::_q_yearEditingFinished() -
1743{ -
1744 QCalendarWidget * const q = q_func(); -
1745 yearButton->setText(yearEdit->text()); -
1746 yearEdit->hide(); -
1747 q->setFocusPolicy(oldFocusPolicy); -
1748 (static_cast<QApplication *>(QCoreApplication::instance()))->removeEventFilter(q); -
1749 spaceHolder->changeSize(0, 0); -
1750 yearButton->show(); -
1751 QDate currentDate = getCurrentDate(); -
1752 currentDate = currentDate.addYears(yearEdit->text().toInt() - currentDate.year()); -
1753 updateCurrentPage(currentDate); -
1754}
executed: }
Execution Count:2
2
1755 -
1756void QCalendarWidgetPrivate::_q_yearClicked() -
1757{ -
1758 QCalendarWidget * const q = q_func(); -
1759 -
1760 yearEdit->setGeometry(yearButton->x(), yearButton->y(), -
1761 yearEdit->sizeHint().width(), yearButton->height()); -
1762 spaceHolder->changeSize(yearButton->width(), 0); -
1763 yearButton->hide(); -
1764 oldFocusPolicy = q->focusPolicy(); -
1765 q->setFocusPolicy(Qt::NoFocus); -
1766 yearEdit->show(); -
1767 (static_cast<QApplication *>(QCoreApplication::instance()))->installEventFilter(q); -
1768 yearEdit->raise(); -
1769 yearEdit->selectAll(); -
1770 yearEdit->setFocus(Qt::MouseFocusReason); -
1771}
executed: }
Execution Count:1
1
1772 -
1773void QCalendarWidgetPrivate::showMonth(int year, int month) -
1774{ -
1775 if (m_model->m_shownYear == year && m_model->m_shownMonth == month)
evaluated: m_model->m_shownYear == year
TRUEFALSE
yes
Evaluation Count:74
yes
Evaluation Count:560
evaluated: m_model->m_shownMonth == month
TRUEFALSE
yes
Evaluation Count:48
yes
Evaluation Count:26
26-560
1776 return;
executed: return;
Execution Count:48
48
1777 QCalendarWidget * const q = q_func(); -
1778 m_model->showMonth(year, month); -
1779 updateNavigationBar(); -
1780 q->currentPageChanged(year, month); -
1781 m_view->internalUpdate(); -
1782 cachedSizeHint = QSize(); -
1783 update(); -
1784 updateMonthMenu(); -
1785}
executed: }
Execution Count:586
586
1786 -
1787void QCalendarWidgetPrivate::updateNavigationBar() -
1788{ -
1789 QCalendarWidget * const q = q_func(); -
1790 -
1791 QString monthName = q->locale().standaloneMonthName(m_model->m_shownMonth, QLocale::LongFormat); -
1792 -
1793 monthButton->setText(monthName); -
1794 yearButton->setText(QString::number(m_model->m_shownYear)); -
1795 yearEdit->setValue(m_model->m_shownYear); -
1796}
executed: }
Execution Count:617
617
1797 -
1798void QCalendarWidgetPrivate::update() -
1799{ -
1800 QDate currentDate = m_model->m_date; -
1801 int row, column; -
1802 m_model->cellForDate(currentDate, &row, &column); -
1803 QModelIndex idx; -
1804 m_selection->clear(); -
1805 if (row != -1 && column != -1) {
evaluated: row != -1
TRUEFALSE
yes
Evaluation Count:598
yes
Evaluation Count:576
partially evaluated: column != -1
TRUEFALSE
yes
Evaluation Count:598
no
Evaluation Count:0
0-598
1806 idx = m_model->index(row, column); -
1807 m_selection->setCurrentIndex(idx, QItemSelectionModel::SelectCurrent); -
1808 }
executed: }
Execution Count:598
598
1809}
executed: }
Execution Count:1174
1174
1810 -
1811void QCalendarWidgetPrivate::paintCell(QPainter *painter, const QRect &rect, const QDate &date) const -
1812{ -
1813 const QCalendarWidget * const q = q_func(); -
1814 q->paintCell(painter, rect, date); -
1815}
executed: }
Execution Count:2058
2058
1816 -
1817void QCalendarWidgetPrivate::_q_slotShowDate(const QDate &date) -
1818{ -
1819 updateCurrentPage(date); -
1820}
never executed: }
0
1821 -
1822void QCalendarWidgetPrivate::_q_slotChangeDate(const QDate &date) -
1823{ -
1824 _q_slotChangeDate(date, true); -
1825}
never executed: }
0
1826 -
1827void QCalendarWidgetPrivate::_q_slotChangeDate(const QDate &date, bool changeMonth) -
1828{ -
1829 QDate oldDate = m_model->m_date; -
1830 m_model->setDate(date); -
1831 QDate newDate = m_model->m_date; -
1832 if (changeMonth)
partially evaluated: changeMonth
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
1833 showMonth(newDate.year(), newDate.month());
executed: showMonth(newDate.year(), newDate.month());
Execution Count:1
1
1834 if (oldDate != newDate) {
partially evaluated: oldDate != newDate
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
1835 update(); -
1836 QCalendarWidget * const q = q_func(); -
1837 m_navigator->setDate(newDate); -
1838 q->selectionChanged(); -
1839 }
executed: }
Execution Count:1
1
1840}
executed: }
Execution Count:1
1
1841 -
1842void QCalendarWidgetPrivate::_q_editingFinished() -
1843{ -
1844 QCalendarWidget * const q = q_func(); -
1845 q->activated(m_model->m_date); -
1846}
never executed: }
0
1847QCalendarWidget::QCalendarWidget(QWidget *parent) -
1848 : QWidget(*new QCalendarWidgetPrivate, parent, 0) -
1849{ -
1850 QCalendarWidgetPrivate * const d = d_func(); -
1851 -
1852 setAutoFillBackground(true); -
1853 setBackgroundRole(QPalette::Window); -
1854 -
1855 QVBoxLayout *layoutV = new QVBoxLayout(this); -
1856 layoutV->setMargin(0); -
1857 d->m_model = new QCalendarModel(this); -
1858 QTextCharFormat fmt; -
1859 fmt.setForeground(QBrush(Qt::red)); -
1860 d->m_model->m_dayFormats.insert(Qt::Saturday, fmt); -
1861 d->m_model->m_dayFormats.insert(Qt::Sunday, fmt); -
1862 d->m_view = new QCalendarView(this); -
1863 d->m_view->setObjectName(QLatin1String("qt_calendar_calendarview")); -
1864 d->m_view->setModel(d->m_model); -
1865 d->m_model->setView(d->m_view); -
1866 d->m_view->setSelectionBehavior(QAbstractItemView::SelectItems); -
1867 d->m_view->setSelectionMode(QAbstractItemView::SingleSelection); -
1868 d->m_view->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); -
1869 d->m_view->horizontalHeader()->setSectionsClickable(false); -
1870 d->m_view->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch); -
1871 d->m_view->verticalHeader()->setSectionsClickable(false); -
1872 d->m_selection = d->m_view->selectionModel(); -
1873 d->createNavigationBar(this); -
1874 d->m_view->setFrameStyle(QFrame::NoFrame); -
1875 d->m_delegate = new QCalendarDelegate(d, this); -
1876 d->m_view->setItemDelegate(d->m_delegate); -
1877 d->update(); -
1878 d->updateNavigationBar(); -
1879 setFocusPolicy(Qt::StrongFocus); -
1880 setFocusProxy(d->m_view); -
1881 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); -
1882 -
1883 connect(d->m_view, "2""showDate(QDate)", -
1884 this, "1""_q_slotShowDate(QDate)"); -
1885 connect(d->m_view, "2""changeDate(QDate,bool)", -
1886 this, "1""_q_slotChangeDate(QDate,bool)"); -
1887 connect(d->m_view, "2""clicked(QDate)", -
1888 this, "2""clicked(QDate)"); -
1889 connect(d->m_view, "2""editingFinished()", -
1890 this, "1""_q_editingFinished()"); -
1891 -
1892 connect(d->prevMonth, "2""clicked(bool)", -
1893 this, "1""_q_prevMonthClicked()"); -
1894 connect(d->nextMonth, "2""clicked(bool)", -
1895 this, "1""_q_nextMonthClicked()"); -
1896 connect(d->yearButton, "2""clicked(bool)", -
1897 this, "1""_q_yearClicked()"); -
1898 connect(d->monthMenu, "2""triggered(QAction*)", -
1899 this, "1""_q_monthChanged(QAction*)"); -
1900 connect(d->yearEdit, "2""editingFinished()", -
1901 this, "1""_q_yearEditingFinished()"); -
1902 -
1903 layoutV->setMargin(0); -
1904 layoutV->setSpacing(0); -
1905 layoutV->addWidget(d->navBarBackground); -
1906 layoutV->addWidget(d->m_view); -
1907 -
1908 d->m_navigator = new QCalendarTextNavigator(this); -
1909 setDateEditEnabled(true); -
1910}
executed: }
Execution Count:27
27
1911 -
1912 -
1913 -
1914 -
1915QCalendarWidget::~QCalendarWidget() -
1916{ -
1917} -
1918 -
1919 -
1920 -
1921 -
1922QSize QCalendarWidget::sizeHint() const -
1923{ -
1924 return minimumSizeHint();
executed: return minimumSizeHint();
Execution Count:18
18
1925} -
1926 -
1927 -
1928 -
1929 -
1930QSize QCalendarWidget::minimumSizeHint() const -
1931{ -
1932 const QCalendarWidgetPrivate * const d = d_func(); -
1933 if (d->cachedSizeHint.isValid())
evaluated: d->cachedSizeHint.isValid()
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:16
6-16
1934 return d->cachedSizeHint;
executed: return d->cachedSizeHint;
Execution Count:6
6
1935 -
1936 ensurePolished(); -
1937 -
1938 int w = 0; -
1939 int h = 0; -
1940 -
1941 int end = 53; -
1942 int rows = 7; -
1943 int cols = 8; -
1944 -
1945 const int marginH = (style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1) * 2; -
1946 -
1947 if (horizontalHeaderFormat() == QCalendarWidget::NoHorizontalHeader) {
partially evaluated: horizontalHeaderFormat() == QCalendarWidget::NoHorizontalHeader
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:16
0-16
1948 rows = 6; -
1949 } else {
never executed: }
0
1950 for (int i = 1; i <= 7; i++) {
evaluated: i <= 7
TRUEFALSE
yes
Evaluation Count:112
yes
Evaluation Count:16
16-112
1951 QFontMetrics fm(d->m_model->formatForCell(0, i).font()); -
1952 w = qMax(w, fm.width(d->m_model->dayName(d->m_model->dayOfWeekForColumn(i))) + marginH); -
1953 h = qMax(h, fm.height()); -
1954 }
executed: }
Execution Count:112
112
1955 }
executed: }
Execution Count:16
16
1956 -
1957 if (verticalHeaderFormat() == QCalendarWidget::NoVerticalHeader) {
evaluated: verticalHeaderFormat() == QCalendarWidget::NoVerticalHeader
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:15
1-15
1958 cols = 7; -
1959 } else {
executed: }
Execution Count:1
1
1960 for (int i = 1; i <= 6; i++) {
evaluated: i <= 6
TRUEFALSE
yes
Evaluation Count:90
yes
Evaluation Count:15
15-90
1961 QFontMetrics fm(d->m_model->formatForCell(i, 0).font()); -
1962 for (int j = 1; j < end; j++)
evaluated: j < end
TRUEFALSE
yes
Evaluation Count:4680
yes
Evaluation Count:90
90-4680
1963 w = qMax(w, fm.width(QString::number(j)) + marginH);
executed: w = qMax(w, fm.width(QString::number(j)) + marginH);
Execution Count:4680
4680
1964 h = qMax(h, fm.height()); -
1965 }
executed: }
Execution Count:90
90
1966 }
executed: }
Execution Count:15
15
1967 -
1968 QFontMetrics fm(d->m_model->formatForCell(1, 1).font()); -
1969 for (int i = 1; i <= end; i++) {
evaluated: i <= end
TRUEFALSE
yes
Evaluation Count:848
yes
Evaluation Count:16
16-848
1970 w = qMax(w, fm.width(QString::number(i)) + marginH); -
1971 h = qMax(h, fm.height()); -
1972 }
executed: }
Execution Count:848
848
1973 -
1974 if (d->m_view->showGrid()) {
partially evaluated: d->m_view->showGrid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:16
0-16
1975 -
1976 w += 1; -
1977 h += 1; -
1978 }
never executed: }
0
1979 -
1980 w += 1; -
1981 -
1982 h = qMax(h, d->m_view->verticalHeader()->minimumSectionSize()); -
1983 w = qMax(w, d->m_view->horizontalHeader()->minimumSectionSize()); -
1984 -
1985 -
1986 QSize headerSize(0, 0); -
1987 if (d->navBarVisible) {
partially evaluated: d->navBarVisible
TRUEFALSE
yes
Evaluation Count:16
no
Evaluation Count:0
0-16
1988 int headerH = d->navBarBackground->sizeHint().height(); -
1989 int headerW = 0; -
1990 -
1991 headerW += d->prevMonth->sizeHint().width(); -
1992 headerW += d->nextMonth->sizeHint().width(); -
1993 -
1994 QFontMetrics fm = d->monthButton->fontMetrics(); -
1995 int monthW = 0; -
1996 for (int i = 1; i < 12; i++) {
evaluated: i < 12
TRUEFALSE
yes
Evaluation Count:176
yes
Evaluation Count:16
16-176
1997 QString monthName = locale().standaloneMonthName(i, QLocale::LongFormat); -
1998 monthW = qMax(monthW, fm.boundingRect(monthName).width()); -
1999 }
executed: }
Execution Count:176
176
2000 const int buttonDecoMargin = d->monthButton->sizeHint().width() - fm.boundingRect(d->monthButton->text()).width(); -
2001 headerW += monthW + buttonDecoMargin; -
2002 -
2003 fm = d->yearButton->fontMetrics(); -
2004 headerW += fm.boundingRect(QLatin1String("5555")).width() + buttonDecoMargin; -
2005 -
2006 headerSize = QSize(headerW, headerH); -
2007 }
executed: }
Execution Count:16
16
2008 w *= cols; -
2009 w = qMax(headerSize.width(), w); -
2010 h = (h * rows) + headerSize.height(); -
2011 d->cachedSizeHint = QSize(w, h); -
2012 return d->cachedSizeHint;
executed: return d->cachedSizeHint;
Execution Count:16
16
2013} -
2014 -
2015 -
2016 -
2017 -
2018 -
2019void QCalendarWidget::paintCell(QPainter *painter, const QRect &rect, const QDate &date) const -
2020{ -
2021 const QCalendarWidgetPrivate * const d = d_func(); -
2022 d->m_delegate->paintCell(painter, rect, date); -
2023}
executed: }
Execution Count:2058
2058
2024QDate QCalendarWidget::selectedDate() const -
2025{ -
2026 const QCalendarWidgetPrivate * const d = d_func(); -
2027 return d->m_model->m_date;
executed: return d->m_model->m_date;
Execution Count:561
561
2028} -
2029 -
2030void QCalendarWidget::setSelectedDate(const QDate &date) -
2031{ -
2032 QCalendarWidgetPrivate * const d = d_func(); -
2033 if (d->m_model->m_date == date && date == d->getCurrentDate())
evaluated: d->m_model->m_date == date
TRUEFALSE
yes
Evaluation Count:168
yes
Evaluation Count:550
partially evaluated: date == d->getCurrentDate()
TRUEFALSE
yes
Evaluation Count:168
no
Evaluation Count:0
0-550
2034 return;
executed: return;
Execution Count:168
168
2035 -
2036 if (!date.isValid())
partially evaluated: !date.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:550
0-550
2037 return;
never executed: return;
0
2038 -
2039 d->m_model->setDate(date); -
2040 d->update(); -
2041 QDate newDate = d->m_model->m_date; -
2042 d->showMonth(newDate.year(), newDate.month()); -
2043 selectionChanged(); -
2044}
executed: }
Execution Count:550
550
2045int QCalendarWidget::yearShown() const -
2046{ -
2047 const QCalendarWidgetPrivate * const d = d_func(); -
2048 return d->m_model->m_shownYear;
executed: return d->m_model->m_shownYear;
Execution Count:60
60
2049} -
2050int QCalendarWidget::monthShown() const -
2051{ -
2052 const QCalendarWidgetPrivate * const d = d_func(); -
2053 return d->m_model->m_shownMonth;
executed: return d->m_model->m_shownMonth;
Execution Count:65
65
2054} -
2055void QCalendarWidget::setCurrentPage(int year, int month) -
2056{ -
2057 QCalendarWidgetPrivate * const d = d_func(); -
2058 QDate currentDate = d->getCurrentDate(); -
2059 int day = currentDate.day(); -
2060 int daysInMonths = QDate(year, month, 1).daysInMonth(); -
2061 if (day > daysInMonths)
evaluated: day > daysInMonths
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:28
3-28
2062 day = daysInMonths;
executed: day = daysInMonths;
Execution Count:3
3
2063 -
2064 d->showMonth(year, month); -
2065 -
2066 QDate newDate(year, month, day); -
2067 int row = -1, col = -1; -
2068 d->m_model->cellForDate(newDate, &row, &col); -
2069 if (row != -1 && col != -1) {
partially evaluated: row != -1
TRUEFALSE
yes
Evaluation Count:31
no
Evaluation Count:0
partially evaluated: col != -1
TRUEFALSE
yes
Evaluation Count:31
no
Evaluation Count:0
0-31
2070 d->m_view->selectionModel()->setCurrentIndex(d->m_model->index(row, col), -
2071 QItemSelectionModel::NoUpdate); -
2072 }
executed: }
Execution Count:31
31
2073}
executed: }
Execution Count:31
31
2074void QCalendarWidget::showNextMonth() -
2075{ -
2076 int year = yearShown(); -
2077 int month = monthShown(); -
2078 if (month == 12) {
evaluated: month == 12
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:4
1-4
2079 ++year; -
2080 month = 1; -
2081 } else {
executed: }
Execution Count:1
1
2082 ++month; -
2083 }
executed: }
Execution Count:4
4
2084 setCurrentPage(year, month); -
2085}
executed: }
Execution Count:5
5
2086void QCalendarWidget::showPreviousMonth() -
2087{ -
2088 int year = yearShown(); -
2089 int month = monthShown(); -
2090 if (month == 1) {
evaluated: month == 1
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:3
1-3
2091 --year; -
2092 month = 12; -
2093 } else {
executed: }
Execution Count:1
1
2094 --month; -
2095 }
executed: }
Execution Count:3
3
2096 setCurrentPage(year, month); -
2097}
executed: }
Execution Count:4
4
2098void QCalendarWidget::showNextYear() -
2099{ -
2100 int year = yearShown(); -
2101 int month = monthShown(); -
2102 ++year; -
2103 setCurrentPage(year, month); -
2104}
executed: }
Execution Count:3
3
2105void QCalendarWidget::showPreviousYear() -
2106{ -
2107 int year = yearShown(); -
2108 int month = monthShown(); -
2109 --year; -
2110 setCurrentPage(year, month); -
2111}
executed: }
Execution Count:3
3
2112 -
2113 -
2114 -
2115 -
2116 -
2117 -
2118void QCalendarWidget::showSelectedDate() -
2119{ -
2120 QDate currentDate = selectedDate(); -
2121 setCurrentPage(currentDate.year(), currentDate.month()); -
2122}
executed: }
Execution Count:4
4
2123 -
2124 -
2125 -
2126 -
2127 -
2128 -
2129void QCalendarWidget::showToday() -
2130{ -
2131 QDate currentDate = QDate::currentDate(); -
2132 setCurrentPage(currentDate.year(), currentDate.month()); -
2133}
executed: }
Execution Count:2
2
2134QDate QCalendarWidget::minimumDate() const -
2135{ -
2136 const QCalendarWidgetPrivate * const d = d_func(); -
2137 return d->m_model->m_minimumDate;
executed: return d->m_model->m_minimumDate;
Execution Count:21
21
2138} -
2139 -
2140void QCalendarWidget::setMinimumDate(const QDate &date) -
2141{ -
2142 QCalendarWidgetPrivate * const d = d_func(); -
2143 if (!date.isValid() || d->m_model->m_minimumDate == date)
partially evaluated: !date.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:703
evaluated: d->m_model->m_minimumDate == date
TRUEFALSE
yes
Evaluation Count:685
yes
Evaluation Count:18
0-703
2144 return;
executed: return;
Execution Count:685
685
2145 -
2146 QDate oldDate = d->m_model->m_date; -
2147 d->m_model->setMinimumDate(date); -
2148 d->yearEdit->setMinimum(d->m_model->m_minimumDate.year()); -
2149 d->updateMonthMenu(); -
2150 QDate newDate = d->m_model->m_date; -
2151 if (oldDate != newDate) {
evaluated: oldDate != newDate
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:16
2-16
2152 d->update(); -
2153 d->showMonth(newDate.year(), newDate.month()); -
2154 d->m_navigator->setDate(newDate); -
2155 selectionChanged(); -
2156 }
executed: }
Execution Count:2
2
2157}
executed: }
Execution Count:18
18
2158QDate QCalendarWidget::maximumDate() const -
2159{ -
2160 const QCalendarWidgetPrivate * const d = d_func(); -
2161 return d->m_model->m_maximumDate;
executed: return d->m_model->m_maximumDate;
Execution Count:21
21
2162} -
2163 -
2164void QCalendarWidget::setMaximumDate(const QDate &date) -
2165{ -
2166 QCalendarWidgetPrivate * const d = d_func(); -
2167 if (!date.isValid() || d->m_model->m_maximumDate == date)
partially evaluated: !date.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:703
evaluated: d->m_model->m_maximumDate == date
TRUEFALSE
yes
Evaluation Count:690
yes
Evaluation Count:13
0-703
2168 return;
executed: return;
Execution Count:690
690
2169 -
2170 QDate oldDate = d->m_model->m_date; -
2171 d->m_model->setMaximumDate(date); -
2172 d->yearEdit->setMaximum(d->m_model->m_maximumDate.year()); -
2173 d->updateMonthMenu(); -
2174 QDate newDate = d->m_model->m_date; -
2175 if (oldDate != newDate) {
evaluated: oldDate != newDate
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:10
3-10
2176 d->update(); -
2177 d->showMonth(newDate.year(), newDate.month()); -
2178 d->m_navigator->setDate(newDate); -
2179 selectionChanged(); -
2180 }
executed: }
Execution Count:3
3
2181}
executed: }
Execution Count:13
13
2182void QCalendarWidget::setDateRange(const QDate &min, const QDate &max) -
2183{ -
2184 QCalendarWidgetPrivate * const d = d_func(); -
2185 if (d->m_model->m_minimumDate == min && d->m_model->m_maximumDate == max)
partially evaluated: d->m_model->m_minimumDate == min
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
never evaluated: d->m_model->m_maximumDate == max
0-2
2186 return;
never executed: return;
0
2187 if (!min.isValid() || !max.isValid())
partially evaluated: !min.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
partially evaluated: !max.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
2188 return;
never executed: return;
0
2189 -
2190 QDate oldDate = d->m_model->m_date; -
2191 d->m_model->setRange(min, max); -
2192 d->yearEdit->setMinimum(d->m_model->m_minimumDate.year()); -
2193 d->yearEdit->setMaximum(d->m_model->m_maximumDate.year()); -
2194 d->updateMonthMenu(); -
2195 QDate newDate = d->m_model->m_date; -
2196 if (oldDate != newDate) {
partially evaluated: oldDate != newDate
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
2197 d->update(); -
2198 d->showMonth(newDate.year(), newDate.month()); -
2199 d->m_navigator->setDate(newDate); -
2200 selectionChanged(); -
2201 }
executed: }
Execution Count:2
2
2202}
executed: }
Execution Count:2
2
2203void QCalendarWidget::setHorizontalHeaderFormat(QCalendarWidget::HorizontalHeaderFormat format) -
2204{ -
2205 QCalendarWidgetPrivate * const d = d_func(); -
2206 if (d->m_model->m_horizontalHeaderFormat == format)
partially evaluated: d->m_model->m_horizontalHeaderFormat == format
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
2207 return;
never executed: return;
0
2208 -
2209 d->m_model->setHorizontalHeaderFormat(format); -
2210 d->cachedSizeHint = QSize(); -
2211 d->m_view->viewport()->update(); -
2212 d->m_view->updateGeometry(); -
2213}
executed: }
Execution Count:4
4
2214 -
2215QCalendarWidget::HorizontalHeaderFormat QCalendarWidget::horizontalHeaderFormat() const -
2216{ -
2217 const QCalendarWidgetPrivate * const d = d_func(); -
2218 return d->m_model->m_horizontalHeaderFormat;
executed: return d->m_model->m_horizontalHeaderFormat;
Execution Count:20
20
2219} -
2220QCalendarWidget::VerticalHeaderFormat QCalendarWidget::verticalHeaderFormat() const -
2221{ -
2222 const QCalendarWidgetPrivate * const d = d_func(); -
2223 bool shown = d->m_model->weekNumbersShown(); -
2224 if (shown)
evaluated: shown
TRUEFALSE
yes
Evaluation Count:16
yes
Evaluation Count:2
2-16
2225 return QCalendarWidget::ISOWeekNumbers;
executed: return QCalendarWidget::ISOWeekNumbers;
Execution Count:16
16
2226 return QCalendarWidget::NoVerticalHeader;
executed: return QCalendarWidget::NoVerticalHeader;
Execution Count:2
2
2227} -
2228 -
2229void QCalendarWidget::setVerticalHeaderFormat(QCalendarWidget::VerticalHeaderFormat format) -
2230{ -
2231 QCalendarWidgetPrivate * const d = d_func(); -
2232 bool show = false; -
2233 if (format == QCalendarWidget::ISOWeekNumbers)
evaluated: format == QCalendarWidget::ISOWeekNumbers
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:5
1-5
2234 show = true;
executed: show = true;
Execution Count:1
1
2235 if (d->m_model->weekNumbersShown() == show)
evaluated: d->m_model->weekNumbersShown() == show
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:5
1-5
2236 return;
executed: return;
Execution Count:1
1
2237 d->m_model->setWeekNumbersShown(show); -
2238 d->cachedSizeHint = QSize(); -
2239 d->m_view->viewport()->update(); -
2240 d->m_view->updateGeometry(); -
2241}
executed: }
Execution Count:5
5
2242bool QCalendarWidget::isGridVisible() const -
2243{ -
2244 const QCalendarWidgetPrivate * const d = d_func(); -
2245 return d->m_view->showGrid();
executed: return d->m_view->showGrid();
Execution Count:2
2
2246} -
2247 -
2248void QCalendarWidget::setGridVisible(bool show) -
2249{ -
2250 QCalendarWidgetPrivate * const d = d_func(); -
2251 d->m_view->setShowGrid(show); -
2252 d->cachedSizeHint = QSize(); -
2253 d->m_view->viewport()->update(); -
2254 d->m_view->updateGeometry(); -
2255}
executed: }
Execution Count:2
2
2256QCalendarWidget::SelectionMode QCalendarWidget::selectionMode() const -
2257{ -
2258 const QCalendarWidgetPrivate * const d = d_func(); -
2259 return d->m_view->readOnly ? QCalendarWidget::NoSelection : QCalendarWidget::SingleSelection;
executed: return d->m_view->readOnly ? QCalendarWidget::NoSelection : QCalendarWidget::SingleSelection;
Execution Count:32
32
2260} -
2261 -
2262void QCalendarWidget::setSelectionMode(SelectionMode mode) -
2263{ -
2264 QCalendarWidgetPrivate * const d = d_func(); -
2265 d->m_view->readOnly = (mode == QCalendarWidget::NoSelection); -
2266 d->setNavigatorEnabled(isDateEditEnabled() && (selectionMode() != QCalendarWidget::NoSelection)); -
2267 d->update(); -
2268}
executed: }
Execution Count:2
2
2269void QCalendarWidget::setFirstDayOfWeek(Qt::DayOfWeek dayOfWeek) -
2270{ -
2271 QCalendarWidgetPrivate * const d = d_func(); -
2272 if ((Qt::DayOfWeek)d->m_model->firstColumnDay() == dayOfWeek)
partially evaluated: (Qt::DayOfWeek)d->m_model->firstColumnDay() == dayOfWeek
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
2273 return;
never executed: return;
0
2274 -
2275 d->m_model->setFirstColumnDay(dayOfWeek); -
2276 d->update(); -
2277}
executed: }
Execution Count:1
1
2278 -
2279Qt::DayOfWeek QCalendarWidget::firstDayOfWeek() const -
2280{ -
2281 const QCalendarWidgetPrivate * const d = d_func(); -
2282 return (Qt::DayOfWeek)d->m_model->firstColumnDay();
executed: return (Qt::DayOfWeek)d->m_model->firstColumnDay();
Execution Count:7
7
2283} -
2284 -
2285 -
2286 -
2287 -
2288QTextCharFormat QCalendarWidget::headerTextFormat() const -
2289{ -
2290 const QCalendarWidgetPrivate * const d = d_func(); -
2291 return d->m_model->m_headerFormat;
never executed: return d->m_model->m_headerFormat;
0
2292} -
2293void QCalendarWidget::setHeaderTextFormat(const QTextCharFormat &format) -
2294{ -
2295 QCalendarWidgetPrivate * const d = d_func(); -
2296 d->m_model->m_headerFormat = format; -
2297 d->cachedSizeHint = QSize(); -
2298 d->m_view->viewport()->update(); -
2299 d->m_view->updateGeometry(); -
2300}
never executed: }
0
2301 -
2302 -
2303 -
2304 -
2305 -
2306 -
2307QTextCharFormat QCalendarWidget::weekdayTextFormat(Qt::DayOfWeek dayOfWeek) const -
2308{ -
2309 const QCalendarWidgetPrivate * const d = d_func(); -
2310 return d->m_model->m_dayFormats.value(dayOfWeek);
executed: return d->m_model->m_dayFormats.value(dayOfWeek);
Execution Count:31
31
2311} -
2312void QCalendarWidget::setWeekdayTextFormat(Qt::DayOfWeek dayOfWeek, const QTextCharFormat &format) -
2313{ -
2314 QCalendarWidgetPrivate * const d = d_func(); -
2315 d->m_model->m_dayFormats[dayOfWeek] = format; -
2316 d->cachedSizeHint = QSize(); -
2317 d->m_view->viewport()->update(); -
2318 d->m_view->updateGeometry(); -
2319}
executed: }
Execution Count:1
1
2320 -
2321 -
2322 -
2323 -
2324 -
2325QMap<QDate, QTextCharFormat> QCalendarWidget::dateTextFormat() const -
2326{ -
2327 const QCalendarWidgetPrivate * const d = d_func(); -
2328 return d->m_model->m_dateFormats;
never executed: return d->m_model->m_dateFormats;
0
2329} -
2330 -
2331 -
2332 -
2333 -
2334 -
2335QTextCharFormat QCalendarWidget::dateTextFormat(const QDate &date) const -
2336{ -
2337 const QCalendarWidgetPrivate * const d = d_func(); -
2338 return d->m_model->m_dateFormats.value(date);
executed: return d->m_model->m_dateFormats.value(date);
Execution Count:2
2
2339} -
2340 -
2341 -
2342 -
2343 -
2344 -
2345 -
2346void QCalendarWidget::setDateTextFormat(const QDate &date, const QTextCharFormat &format) -
2347{ -
2348 QCalendarWidgetPrivate * const d = d_func(); -
2349 if (date.isNull())
evaluated: date.isNull()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2
1-2
2350 d->m_model->m_dateFormats.clear();
executed: d->m_model->m_dateFormats.clear();
Execution Count:1
1
2351 else -
2352 d->m_model->m_dateFormats[date] = format;
executed: d->m_model->m_dateFormats[date] = format;
Execution Count:2
2
2353 d->m_view->viewport()->update(); -
2354 d->m_view->updateGeometry(); -
2355}
executed: }
Execution Count:3
3
2356bool QCalendarWidget::isDateEditEnabled() const -
2357{ -
2358 const QCalendarWidgetPrivate * const d = d_func(); -
2359 return d->m_dateEditEnabled;
executed: return d->m_dateEditEnabled;
Execution Count:29
29
2360} -
2361 -
2362void QCalendarWidget::setDateEditEnabled(bool enable) -
2363{ -
2364 QCalendarWidgetPrivate * const d = d_func(); -
2365 if (isDateEditEnabled() == enable)
partially evaluated: isDateEditEnabled() == enable
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:27
0-27
2366 return;
never executed: return;
0
2367 -
2368 d->m_dateEditEnabled = enable; -
2369 -
2370 d->setNavigatorEnabled(enable && (selectionMode() != QCalendarWidget::NoSelection)); -
2371}
executed: }
Execution Count:27
27
2372int QCalendarWidget::dateEditAcceptDelay() const -
2373{ -
2374 const QCalendarWidgetPrivate * const d = d_func(); -
2375 return d->m_navigator->dateEditAcceptDelay();
never executed: return d->m_navigator->dateEditAcceptDelay();
0
2376} -
2377 -
2378void QCalendarWidget::setDateEditAcceptDelay(int delay) -
2379{ -
2380 QCalendarWidgetPrivate * const d = d_func(); -
2381 d->m_navigator->setDateEditAcceptDelay(delay); -
2382}
never executed: }
0
2383void QCalendarWidget::updateCell(const QDate &date) -
2384{ -
2385 if (!date.isValid()) {
never evaluated: !date.isValid()
0
2386 QMessageLogger("widgets/qcalendarwidget.cpp", 2877, __PRETTY_FUNCTION__).warning("QCalendarWidget::updateCell: Invalid date"); -
2387 return;
never executed: return;
0
2388 } -
2389 -
2390 if (!isVisible())
never evaluated: !isVisible()
0
2391 return;
never executed: return;
0
2392 -
2393 QCalendarWidgetPrivate * const d = d_func(); -
2394 int row, column; -
2395 d->m_model->cellForDate(date, &row, &column); -
2396 if (row == -1 || column == -1)
never evaluated: row == -1
never evaluated: column == -1
0
2397 return;
never executed: return;
0
2398 -
2399 QModelIndex modelIndex = d->m_model->index(row, column); -
2400 if (!modelIndex.isValid())
never evaluated: !modelIndex.isValid()
0
2401 return;
never executed: return;
0
2402 -
2403 d->m_view->viewport()->update(d->m_view->visualRect(modelIndex)); -
2404}
never executed: }
0
2405void QCalendarWidget::updateCells() -
2406{ -
2407 QCalendarWidgetPrivate * const d = d_func(); -
2408 if (isVisible())
never evaluated: isVisible()
0
2409 d->m_view->viewport()->update();
never executed: d->m_view->viewport()->update();
0
2410}
never executed: }
0
2411bool QCalendarWidget::isNavigationBarVisible() const -
2412{ -
2413 const QCalendarWidgetPrivate * const d = d_func(); -
2414 return d->navBarVisible;
executed: return d->navBarVisible;
Execution Count:39
39
2415} -
2416 -
2417 -
2418void QCalendarWidget::setNavigationBarVisible(bool visible) -
2419{ -
2420 QCalendarWidgetPrivate * const d = d_func(); -
2421 d->navBarVisible = visible; -
2422 d->cachedSizeHint = QSize(); -
2423 d->navBarBackground->setVisible(visible); -
2424 updateGeometry(); -
2425}
executed: }
Execution Count:4
4
2426 -
2427 -
2428 -
2429 -
2430bool QCalendarWidget::event(QEvent *event) -
2431{ -
2432 QCalendarWidgetPrivate * const d = d_func(); -
2433 switch (event->type()) { -
2434 case QEvent::LayoutDirectionChange: -
2435 d->updateButtonIcons(); -
2436 case QEvent::LocaleChange:
code before this statement executed: case QEvent::LocaleChange:
Execution Count:2
2
2437 d->m_model->setFirstColumnDay(locale().firstDayOfWeek()); -
2438 d->cachedSizeHint = QSize(); -
2439 d->updateMonthMenuNames(); -
2440 d->updateNavigationBar(); -
2441 d->m_view->updateGeometry(); -
2442 break;
executed: break;
Execution Count:4
4
2443 case QEvent::FontChange: -
2444 case QEvent::ApplicationFontChange: -
2445 d->cachedSizeHint = QSize(); -
2446 d->m_view->updateGeometry(); -
2447 break;
never executed: break;
0
2448 case QEvent::StyleChange: -
2449 d->cachedSizeHint = QSize(); -
2450 d->m_view->updateGeometry(); -
2451 default: -
2452 break;
executed: break;
Execution Count:558
558
2453 } -
2454 return QWidget::event(event);
executed: return QWidget::event(event);
Execution Count:562
562
2455} -
2456 -
2457 -
2458 -
2459 -
2460bool QCalendarWidget::eventFilter(QObject *watched, QEvent *event) -
2461{ -
2462 QCalendarWidgetPrivate * const d = d_func(); -
2463 if (event->type() == QEvent::MouseButtonPress && d->yearEdit->hasFocus()) {
evaluated: event->type() == QEvent::MouseButtonPress
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:55
partially evaluated: d->yearEdit->hasFocus()
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-55
2464 QWidget *tlw = window(); -
2465 QWidget *widget = static_cast<QWidget*>(watched); -
2466 -
2467 -
2468 if (widget->window() == tlw) {
partially evaluated: widget->window() == tlw
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
2469 QPoint mousePos = widget->mapTo(tlw, static_cast<QMouseEvent *>(event)->pos()); -
2470 QRect geom = QRect(d->yearEdit->mapTo(tlw, QPoint(0, 0)), d->yearEdit->size()); -
2471 if (!geom.contains(mousePos)) {
partially evaluated: !geom.contains(mousePos)
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
2472 event->accept(); -
2473 d->_q_yearEditingFinished(); -
2474 setFocus(); -
2475 return true;
executed: return true;
Execution Count:1
1
2476 } -
2477 }
never executed: }
0
2478 }
never executed: }
0
2479 return QWidget::eventFilter(watched, event);
executed: return QWidget::eventFilter(watched, event);
Execution Count:55
55
2480} -
2481 -
2482 -
2483 -
2484 -
2485void QCalendarWidget::mousePressEvent(QMouseEvent *event) -
2486{ -
2487 setAttribute(Qt::WA_NoMouseReplay); -
2488 QWidget::mousePressEvent(event); -
2489 setFocus(); -
2490}
never executed: }
0
2491 -
2492 -
2493 -
2494 -
2495void QCalendarWidget::resizeEvent(QResizeEvent * event) -
2496{ -
2497 QCalendarWidgetPrivate * const d = d_func(); -
2498 -
2499 -
2500 -
2501 -
2502 if(d->yearEdit->isVisible() && event->size().width() != event->oldSize().width())
partially evaluated: d->yearEdit->isVisible()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:32
never evaluated: event->size().width() != event->oldSize().width()
0-32
2503 d->_q_yearEditingFinished();
never executed: d->_q_yearEditingFinished();
0
2504 -
2505 QWidget::resizeEvent(event); -
2506}
executed: }
Execution Count:32
32
2507 -
2508 -
2509 -
2510 -
2511void QCalendarWidget::keyPressEvent(QKeyEvent * event) -
2512{ -
2513 QCalendarWidgetPrivate * const d = d_func(); -
2514 if(d->yearEdit->isVisible()&& event->key() == Qt::Key_Escape)
partially evaluated: d->yearEdit->isVisible()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
never evaluated: event->key() == Qt::Key_Escape
0-1
2515 { -
2516 d->yearEdit->setValue(yearShown()); -
2517 d->_q_yearEditingFinished(); -
2518 return;
never executed: return;
0
2519 } -
2520 QWidget::keyPressEvent(event); -
2521}
executed: }
Execution Count:1
1
2522 -
2523 -
2524 -
2525 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial