OpenCoverage

qcalendarwidget.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qcalendarwidget.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qcalendarwidget.h"-
41-
42#ifndef QT_NO_CALENDARWIDGET-
43-
44#include <qabstractitemmodel.h>-
45#include <qitemdelegate.h>-
46#include <qdatetime.h>-
47#include <qtableview.h>-
48#include <qlayout.h>-
49#include <qevent.h>-
50#include <qtextformat.h>-
51#include <qheaderview.h>-
52#include <private/qwidget_p.h>-
53#include <qpushbutton.h>-
54#include <qtoolbutton.h>-
55#include <qlabel.h>-
56#include <qspinbox.h>-
57#include <qmenu.h>-
58#include <qapplication.h>-
59#include <qbasictimer.h>-
60#include <qstylepainter.h>-
61-
62#include <vector>-
63-
64QT_BEGIN_NAMESPACE-
65-
66enum {-
67 RowCount = 6,-
68 ColumnCount = 7,-
69 HeaderColumn = 0,-
70 HeaderRow = 0,-
71 MinimumDayOffset = 1-
72};-
73-
74namespace {-
75-
76static QString formatNumber(int number, int fieldWidth)-
77{-
78 return QString::number(number).rightJustified(fieldWidth, QLatin1Char('0'));
never executed: return QString::number(number).rightJustified(fieldWidth, QLatin1Char('0'));
0
79}-
80-
81class QCalendarDateSectionValidator-
82{-
83public:-
84-
85 enum Section {-
86 NextSection,-
87 ThisSection,-
88 PrevSection-
89 };-
90-
91 QCalendarDateSectionValidator() {}-
92 virtual ~QCalendarDateSectionValidator() {}-
93 virtual Section handleKey(int key) = 0;-
94 virtual QDate applyToDate(const QDate &date) const = 0;-
95 virtual void setDate(const QDate &date) = 0;-
96 virtual QString text() const = 0;-
97 virtual QString text(const QDate &date, int repeat) const = 0;-
98-
99 QLocale m_locale;-
100-
101protected:-
102 static QString highlightString(const QString &str, int pos);-
103private:-
104};-
105-
106QString QCalendarDateSectionValidator::highlightString(const QString &str, int pos)-
107{-
108 if (pos == 0)
pos == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
109 return QLatin1String("<b>") + str + QLatin1String("</b>");
never executed: return QLatin1String("<b>") + str + QLatin1String("</b>");
0
110 int startPos = str.length() - pos;-
111 return str.midRef(0, startPos) + QLatin1String("<b>") + str.midRef(startPos, pos) + QLatin1String("</b>");
never executed: return str.midRef(0, startPos) + QLatin1String("<b>") + str.midRef(startPos, pos) + QLatin1String("</b>");
0
112-
113}-
114-
115class QCalendarDayValidator : public QCalendarDateSectionValidator-
116{-
117-
118public:-
119 QCalendarDayValidator();-
120 virtual Section handleKey(int key) Q_DECL_OVERRIDE;-
121 virtual QDate applyToDate(const QDate &date) const Q_DECL_OVERRIDE;-
122 virtual void setDate(const QDate &date) Q_DECL_OVERRIDE;-
123 virtual QString text() const Q_DECL_OVERRIDE;-
124 virtual QString text(const QDate &date, int repeat) const Q_DECL_OVERRIDE;-
125private:-
126 int m_pos;-
127 int m_day;-
128 int m_oldDay;-
129};-
130-
131QCalendarDayValidator::QCalendarDayValidator()-
132 : QCalendarDateSectionValidator(), m_pos(0), m_day(1), m_oldDay(1)-
133{-
134}
never executed: end of block
0
135-
136QCalendarDateSectionValidator::Section QCalendarDayValidator::handleKey(int key)-
137{-
138 if (key == Qt::Key_Right || key == Qt::Key_Left) {
key == Qt::Key_RightDescription
TRUEnever evaluated
FALSEnever evaluated
key == Qt::Key_LeftDescription
TRUEnever evaluated
FALSEnever evaluated
0
139 m_pos = 0;-
140 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
141 } else if (key == Qt::Key_Up) {
key == Qt::Key_UpDescription
TRUEnever evaluated
FALSEnever evaluated
0
142 m_pos = 0;-
143 ++m_day;-
144 if (m_day > 31)
m_day > 31Description
TRUEnever evaluated
FALSEnever evaluated
0
145 m_day = 1;
never executed: m_day = 1;
0
146 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
147 } else if (key == Qt::Key_Down) {
key == Qt::Key_DownDescription
TRUEnever evaluated
FALSEnever evaluated
0
148 m_pos = 0;-
149 --m_day;-
150 if (m_day < 1)
m_day < 1Description
TRUEnever evaluated
FALSEnever evaluated
0
151 m_day = 31;
never executed: m_day = 31;
0
152 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
153 } else if (key == Qt::Key_Back || key == Qt::Key_Backspace) {
key == Qt::Key_BackDescription
TRUEnever evaluated
FALSEnever evaluated
key == Qt::Key_BackspaceDescription
TRUEnever evaluated
FALSEnever evaluated
0
154 --m_pos;-
155 if (m_pos < 0)
m_pos < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
156 m_pos = 1;
never executed: m_pos = 1;
0
157-
158 if (m_pos == 0)
m_pos == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
159 m_day = m_oldDay;
never executed: m_day = m_oldDay;
0
160 else-
161 m_day = m_day / 10;
never executed: m_day = m_day / 10;
0
162 //m_day = m_oldDay / 10 * 10 + m_day / 10;-
163-
164 if (m_pos == 0)
m_pos == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
165 return QCalendarDateSectionValidator::PrevSection;
never executed: return QCalendarDateSectionValidator::PrevSection;
0
166 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
167 }-
168 if (key < Qt::Key_0 || key > Qt::Key_9)
key < Qt::Key_0Description
TRUEnever evaluated
FALSEnever evaluated
key > Qt::Key_9Description
TRUEnever evaluated
FALSEnever evaluated
0
169 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
170 int pressedKey = key - Qt::Key_0;-
171 if (m_pos == 0)
m_pos == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
172 m_day = pressedKey;
never executed: m_day = pressedKey;
0
173 else-
174 m_day = m_day % 10 * 10 + pressedKey;
never executed: m_day = m_day % 10 * 10 + pressedKey;
0
175 if (m_day > 31)
m_day > 31Description
TRUEnever evaluated
FALSEnever evaluated
0
176 m_day = 31;
never executed: m_day = 31;
0
177 ++m_pos;-
178 if (m_pos > 1) {
m_pos > 1Description
TRUEnever evaluated
FALSEnever evaluated
0
179 m_pos = 0;-
180 return QCalendarDateSectionValidator::NextSection;
never executed: return QCalendarDateSectionValidator::NextSection;
0
181 }-
182 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
183}-
184-
185QDate QCalendarDayValidator::applyToDate(const QDate &date) const-
186{-
187 int day = m_day;-
188 if (day < 1)
day < 1Description
TRUEnever evaluated
FALSEnever evaluated
0
189 day = 1;
never executed: day = 1;
0
190 else if (day > 31)
day > 31Description
TRUEnever evaluated
FALSEnever evaluated
0
191 day = 31;
never executed: day = 31;
0
192 if (day > date.daysInMonth())
day > date.daysInMonth()Description
TRUEnever evaluated
FALSEnever evaluated
0
193 day = date.daysInMonth();
never executed: day = date.daysInMonth();
0
194 return QDate(date.year(), date.month(), day);
never executed: return QDate(date.year(), date.month(), day);
0
195}-
196-
197void QCalendarDayValidator::setDate(const QDate &date)-
198{-
199 m_day = m_oldDay = date.day();-
200 m_pos = 0;-
201}
never executed: end of block
0
202-
203QString QCalendarDayValidator::text() const-
204{-
205 return highlightString(formatNumber(m_day, 2), m_pos);
never executed: return highlightString(formatNumber(m_day, 2), m_pos);
0
206}-
207-
208QString QCalendarDayValidator::text(const QDate &date, int repeat) const-
209{-
210 if (repeat <= 1) {
repeat <= 1Description
TRUEnever evaluated
FALSEnever evaluated
0
211 return QString::number(date.day());
never executed: return QString::number(date.day());
0
212 } else if (repeat == 2) {
repeat == 2Description
TRUEnever evaluated
FALSEnever evaluated
0
213 return formatNumber(date.day(), 2);
never executed: return formatNumber(date.day(), 2);
0
214 } else if (repeat == 3) {
repeat == 3Description
TRUEnever evaluated
FALSEnever evaluated
0
215 return m_locale.dayName(date.dayOfWeek(), QLocale::ShortFormat);
never executed: return m_locale.dayName(date.dayOfWeek(), QLocale::ShortFormat);
0
216 } else /* repeat >= 4 */ {-
217 return m_locale.dayName(date.dayOfWeek(), QLocale::LongFormat);
never executed: return m_locale.dayName(date.dayOfWeek(), QLocale::LongFormat);
0
218 }-
219}-
220-
221//////////////////////////////////-
222-
223class QCalendarMonthValidator : public QCalendarDateSectionValidator-
224{-
225-
226public:-
227 QCalendarMonthValidator();-
228 virtual Section handleKey(int key) Q_DECL_OVERRIDE;-
229 virtual QDate applyToDate(const QDate &date) const Q_DECL_OVERRIDE;-
230 virtual void setDate(const QDate &date) Q_DECL_OVERRIDE;-
231 virtual QString text() const Q_DECL_OVERRIDE;-
232 virtual QString text(const QDate &date, int repeat) const Q_DECL_OVERRIDE;-
233private:-
234 int m_pos;-
235 int m_month;-
236 int m_oldMonth;-
237};-
238-
239QCalendarMonthValidator::QCalendarMonthValidator()-
240 : QCalendarDateSectionValidator(), m_pos(0), m_month(1), m_oldMonth(1)-
241{-
242}
never executed: end of block
0
243-
244QCalendarDateSectionValidator::Section QCalendarMonthValidator::handleKey(int key)-
245{-
246 if (key == Qt::Key_Right || key == Qt::Key_Left) {
key == Qt::Key_RightDescription
TRUEnever evaluated
FALSEnever evaluated
key == Qt::Key_LeftDescription
TRUEnever evaluated
FALSEnever evaluated
0
247 m_pos = 0;-
248 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
249 } else if (key == Qt::Key_Up) {
key == Qt::Key_UpDescription
TRUEnever evaluated
FALSEnever evaluated
0
250 m_pos = 0;-
251 ++m_month;-
252 if (m_month > 12)
m_month > 12Description
TRUEnever evaluated
FALSEnever evaluated
0
253 m_month = 1;
never executed: m_month = 1;
0
254 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
255 } else if (key == Qt::Key_Down) {
key == Qt::Key_DownDescription
TRUEnever evaluated
FALSEnever evaluated
0
256 m_pos = 0;-
257 --m_month;-
258 if (m_month < 1)
m_month < 1Description
TRUEnever evaluated
FALSEnever evaluated
0
259 m_month = 12;
never executed: m_month = 12;
0
260 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
261 } else if (key == Qt::Key_Back || key == Qt::Key_Backspace) {
key == Qt::Key_BackDescription
TRUEnever evaluated
FALSEnever evaluated
key == Qt::Key_BackspaceDescription
TRUEnever evaluated
FALSEnever evaluated
0
262 --m_pos;-
263 if (m_pos < 0)
m_pos < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
264 m_pos = 1;
never executed: m_pos = 1;
0
265-
266 if (m_pos == 0)
m_pos == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
267 m_month = m_oldMonth;
never executed: m_month = m_oldMonth;
0
268 else-
269 m_month = m_month / 10;
never executed: m_month = m_month / 10;
0
270 //m_month = m_oldMonth / 10 * 10 + m_month / 10;-
271-
272 if (m_pos == 0)
m_pos == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
273 return QCalendarDateSectionValidator::PrevSection;
never executed: return QCalendarDateSectionValidator::PrevSection;
0
274 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
275 }-
276 if (key < Qt::Key_0 || key > Qt::Key_9)
key < Qt::Key_0Description
TRUEnever evaluated
FALSEnever evaluated
key > Qt::Key_9Description
TRUEnever evaluated
FALSEnever evaluated
0
277 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
278 int pressedKey = key - Qt::Key_0;-
279 if (m_pos == 0)
m_pos == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
280 m_month = pressedKey;
never executed: m_month = pressedKey;
0
281 else-
282 m_month = m_month % 10 * 10 + pressedKey;
never executed: m_month = m_month % 10 * 10 + pressedKey;
0
283 if (m_month > 12)
m_month > 12Description
TRUEnever evaluated
FALSEnever evaluated
0
284 m_month = 12;
never executed: m_month = 12;
0
285 ++m_pos;-
286 if (m_pos > 1) {
m_pos > 1Description
TRUEnever evaluated
FALSEnever evaluated
0
287 m_pos = 0;-
288 return QCalendarDateSectionValidator::NextSection;
never executed: return QCalendarDateSectionValidator::NextSection;
0
289 }-
290 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
291}-
292-
293QDate QCalendarMonthValidator::applyToDate(const QDate &date) const-
294{-
295 int month = m_month;-
296 if (month < 1)
month < 1Description
TRUEnever evaluated
FALSEnever evaluated
0
297 month = 1;
never executed: month = 1;
0
298 else if (month > 12)
month > 12Description
TRUEnever evaluated
FALSEnever evaluated
0
299 month = 12;
never executed: month = 12;
0
300 QDate newDate(date.year(), m_month, 1);-
301 int day = date.day();-
302 if (day > newDate.daysInMonth())
day > newDate.daysInMonth()Description
TRUEnever evaluated
FALSEnever evaluated
0
303 day = newDate.daysInMonth();
never executed: day = newDate.daysInMonth();
0
304 return QDate(date.year(), month, day);
never executed: return QDate(date.year(), month, day);
0
305}-
306-
307void QCalendarMonthValidator::setDate(const QDate &date)-
308{-
309 m_month = m_oldMonth = date.month();-
310 m_pos = 0;-
311}
never executed: end of block
0
312-
313QString QCalendarMonthValidator::text() const-
314{-
315 return highlightString(formatNumber(m_month, 2), m_pos);
never executed: return highlightString(formatNumber(m_month, 2), m_pos);
0
316}-
317-
318QString QCalendarMonthValidator::text(const QDate &date, int repeat) const-
319{-
320 if (repeat <= 1) {
repeat <= 1Description
TRUEnever evaluated
FALSEnever evaluated
0
321 return QString::number(date.month());
never executed: return QString::number(date.month());
0
322 } else if (repeat == 2) {
repeat == 2Description
TRUEnever evaluated
FALSEnever evaluated
0
323 return formatNumber(date.month(), 2);
never executed: return formatNumber(date.month(), 2);
0
324 } else if (repeat == 3) {
repeat == 3Description
TRUEnever evaluated
FALSEnever evaluated
0
325 return m_locale.standaloneMonthName(date.month(), QLocale::ShortFormat);
never executed: return m_locale.standaloneMonthName(date.month(), QLocale::ShortFormat);
0
326 } else /*if (repeat >= 4)*/ {-
327 return m_locale.standaloneMonthName(date.month(), QLocale::LongFormat);
never executed: return m_locale.standaloneMonthName(date.month(), QLocale::LongFormat);
0
328 }-
329}-
330-
331//////////////////////////////////-
332-
333class QCalendarYearValidator : public QCalendarDateSectionValidator-
334{-
335-
336public:-
337 QCalendarYearValidator();-
338 virtual Section handleKey(int key) Q_DECL_OVERRIDE;-
339 virtual QDate applyToDate(const QDate &date) const Q_DECL_OVERRIDE;-
340 virtual void setDate(const QDate &date) Q_DECL_OVERRIDE;-
341 virtual QString text() const Q_DECL_OVERRIDE;-
342 virtual QString text(const QDate &date, int repeat) const Q_DECL_OVERRIDE;-
343private:-
344 int pow10(int n);-
345 int m_pos;-
346 int m_year;-
347 int m_oldYear;-
348};-
349-
350QCalendarYearValidator::QCalendarYearValidator()-
351 : QCalendarDateSectionValidator(), m_pos(0), m_year(2000), m_oldYear(2000)-
352{-
353}
never executed: end of block
0
354-
355int QCalendarYearValidator::pow10(int n)-
356{-
357 int power = 1;-
358 for (int i = 0; i < n; i++)
i < nDescription
TRUEnever evaluated
FALSEnever evaluated
0
359 power *= 10;
never executed: power *= 10;
0
360 return power;
never executed: return power;
0
361}-
362-
363QCalendarDateSectionValidator::Section QCalendarYearValidator::handleKey(int key)-
364{-
365 if (key == Qt::Key_Right || key == Qt::Key_Left) {
key == Qt::Key_RightDescription
TRUEnever evaluated
FALSEnever evaluated
key == Qt::Key_LeftDescription
TRUEnever evaluated
FALSEnever evaluated
0
366 m_pos = 0;-
367 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
368 } else if (key == Qt::Key_Up) {
key == Qt::Key_UpDescription
TRUEnever evaluated
FALSEnever evaluated
0
369 m_pos = 0;-
370 ++m_year;-
371 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
372 } else if (key == Qt::Key_Down) {
key == Qt::Key_DownDescription
TRUEnever evaluated
FALSEnever evaluated
0
373 m_pos = 0;-
374 --m_year;-
375 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
376 } else if (key == Qt::Key_Back || key == Qt::Key_Backspace) {
key == Qt::Key_BackDescription
TRUEnever evaluated
FALSEnever evaluated
key == Qt::Key_BackspaceDescription
TRUEnever evaluated
FALSEnever evaluated
0
377 --m_pos;-
378 if (m_pos < 0)
m_pos < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
379 m_pos = 3;
never executed: m_pos = 3;
0
380-
381 int pow = pow10(m_pos);-
382 m_year = m_oldYear / pow * pow + m_year % (pow * 10) / 10;-
383-
384 if (m_pos == 0)
m_pos == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
385 return QCalendarDateSectionValidator::PrevSection;
never executed: return QCalendarDateSectionValidator::PrevSection;
0
386 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
387 }-
388 if (key < Qt::Key_0 || key > Qt::Key_9)
key < Qt::Key_0Description
TRUEnever evaluated
FALSEnever evaluated
key > Qt::Key_9Description
TRUEnever evaluated
FALSEnever evaluated
0
389 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
390 int pressedKey = key - Qt::Key_0;-
391 int pow = pow10(m_pos);-
392 m_year = m_year / (pow * 10) * (pow * 10) + m_year % pow * 10 + pressedKey;-
393 ++m_pos;-
394 if (m_pos > 3) {
m_pos > 3Description
TRUEnever evaluated
FALSEnever evaluated
0
395 m_pos = 0;-
396 return QCalendarDateSectionValidator::NextSection;
never executed: return QCalendarDateSectionValidator::NextSection;
0
397 }-
398 return QCalendarDateSectionValidator::ThisSection;
never executed: return QCalendarDateSectionValidator::ThisSection;
0
399}-
400-
401QDate QCalendarYearValidator::applyToDate(const QDate &date) const-
402{-
403 int year = m_year;-
404 if (year < 1)
year < 1Description
TRUEnever evaluated
FALSEnever evaluated
0
405 year = 1;
never executed: year = 1;
0
406 QDate newDate(year, date.month(), 1);-
407 int day = date.day();-
408 if (day > newDate.daysInMonth())
day > newDate.daysInMonth()Description
TRUEnever evaluated
FALSEnever evaluated
0
409 day = newDate.daysInMonth();
never executed: day = newDate.daysInMonth();
0
410 return QDate(year, date.month(), day);
never executed: return QDate(year, date.month(), day);
0
411}-
412-
413void QCalendarYearValidator::setDate(const QDate &date)-
414{-
415 m_year = m_oldYear = date.year();-
416 m_pos = 0;-
417}
never executed: end of block
0
418-
419QString QCalendarYearValidator::text() const-
420{-
421 return highlightString(formatNumber(m_year, 4), m_pos);
never executed: return highlightString(formatNumber(m_year, 4), m_pos);
0
422}-
423-
424QString QCalendarYearValidator::text(const QDate &date, int repeat) const-
425{-
426 if (repeat < 4)
repeat < 4Description
TRUEnever evaluated
FALSEnever evaluated
0
427 return formatNumber(date.year() % 100, 2);
never executed: return formatNumber(date.year() % 100, 2);
0
428 return QString::number(date.year());
never executed: return QString::number(date.year());
0
429}-
430-
431///////////////////////////////////-
432-
433struct SectionToken {-
434 Q_DECL_CONSTEXPR SectionToken(QCalendarDateSectionValidator *v, int rep)-
435 : validator(v), repeat(rep) {}-
436-
437 QCalendarDateSectionValidator *validator;-
438 int repeat;-
439};-
440} // unnamed namespace-
441Q_DECLARE_TYPEINFO(SectionToken, Q_PRIMITIVE_TYPE);-
442namespace {-
443-
444class QCalendarDateValidator-
445{-
446public:-
447 QCalendarDateValidator();-
448 ~QCalendarDateValidator();-
449-
450 void handleKeyEvent(QKeyEvent *keyEvent);-
451 QString currentText() const;-
452 QDate currentDate() const { return m_currentDate; }
never executed: return m_currentDate;
0
453 void setFormat(const QString &format);-
454 void setInitialDate(const QDate &date);-
455-
456 void setLocale(const QLocale &locale);-
457-
458private:-
459 void toNextToken();-
460 void toPreviousToken();-
461 void applyToDate();-
462-
463 int countRepeat(const QString &str, int index) const;-
464 void clear();-
465-
466 QStringList m_separators;-
467 std::vector<SectionToken> m_tokens;-
468 QCalendarYearValidator m_yearValidator;-
469 QCalendarMonthValidator m_monthValidator;-
470 QCalendarDayValidator m_dayValidator;-
471-
472 int m_currentToken;-
473-
474 QDate m_initialDate;-
475 QDate m_currentDate;-
476-
477 QCalendarDateSectionValidator::Section m_lastSectionMove;-
478};-
479-
480QCalendarDateValidator::QCalendarDateValidator()-
481 : m_currentToken(-1),-
482 m_initialDate(QDate::currentDate()),-
483 m_currentDate(m_initialDate),-
484 m_lastSectionMove(QCalendarDateSectionValidator::ThisSection)-
485{-
486}
never executed: end of block
0
487-
488void QCalendarDateValidator::setLocale(const QLocale &locale)-
489{-
490 m_yearValidator.m_locale = locale;-
491 m_monthValidator.m_locale = locale;-
492 m_dayValidator.m_locale = locale;-
493}
never executed: end of block
0
494-
495QCalendarDateValidator::~QCalendarDateValidator()-
496{-
497 clear();-
498}
never executed: end of block
0
499-
500// from qdatetime.cpp-
501int QCalendarDateValidator::countRepeat(const QString &str, int index) const-
502{-
503 Q_ASSERT(index >= 0 && index < str.size());-
504 int count = 1;-
505 const QChar ch = str.at(index);-
506 while (index + count < str.size() && str.at(index + count) == ch)
index + count < str.size()Description
TRUEnever evaluated
FALSEnever evaluated
str.at(index + count) == chDescription
TRUEnever evaluated
FALSEnever evaluated
0
507 ++count;
never executed: ++count;
0
508 return count;
never executed: return count;
0
509}-
510-
511void QCalendarDateValidator::setInitialDate(const QDate &date)-
512{-
513 m_yearValidator.setDate(date);-
514 m_monthValidator.setDate(date);-
515 m_dayValidator.setDate(date);-
516 m_initialDate = date;-
517 m_currentDate = date;-
518 m_lastSectionMove = QCalendarDateSectionValidator::ThisSection;-
519}
never executed: end of block
0
520-
521QString QCalendarDateValidator::currentText() const-
522{-
523 QString str;-
524 const int numSeps = m_separators.size();-
525 const int numTokens = int(m_tokens.size());-
526 for (int i = 0; i < numSeps; ++i) {
i < numSepsDescription
TRUEnever evaluated
FALSEnever evaluated
0
527 str += m_separators.at(i);-
528 if (i < numTokens) {
i < numTokensDescription
TRUEnever evaluated
FALSEnever evaluated
0
529 const SectionToken &token = m_tokens[i];-
530 if (i == m_currentToken)
i == m_currentTokenDescription
TRUEnever evaluated
FALSEnever evaluated
0
531 str += token.validator->text();
never executed: str += token.validator->text();
0
532 else-
533 str += token.validator->text(m_currentDate, token.repeat);
never executed: str += token.validator->text(m_currentDate, token.repeat);
0
534 }-
535 }
never executed: end of block
0
536 return str;
never executed: return str;
0
537}-
538-
539void QCalendarDateValidator::clear()-
540{-
541 m_tokens.clear();-
542 m_separators.clear();-
543-
544 m_currentToken = -1;-
545}
never executed: end of block
0
546-
547void QCalendarDateValidator::setFormat(const QString &format)-
548{-
549 clear();-
550-
551 int pos = 0;-
552 const QLatin1Char quote('\'');-
553 bool quoting = false;-
554 QString separator;-
555 while (pos < format.size()) {
pos < format.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
556 const QStringRef mid = format.midRef(pos);-
557 int offset = 1;-
558-
559 if (mid.startsWith(quote)) {
mid.startsWith(quote)Description
TRUEnever evaluated
FALSEnever evaluated
0
560 quoting = !quoting;-
561 } else {
never executed: end of block
0
562 const QChar nextChar = format.at(pos);-
563 if (quoting) {
quotingDescription
TRUEnever evaluated
FALSEnever evaluated
0
564 separator += nextChar;-
565 quoting = false;-
566 } else {
never executed: end of block
0
567 QCalendarDateSectionValidator *validator = 0;-
568 if (nextChar == QLatin1Char('d')) {
nextChar == QLatin1Char('d')Description
TRUEnever evaluated
FALSEnever evaluated
0
569 offset = qMin(4, countRepeat(format, pos));-
570 validator = &m_dayValidator;-
571 } else if (nextChar == QLatin1Char('M')) {
never executed: end of block
nextChar == QLatin1Char('M')Description
TRUEnever evaluated
FALSEnever evaluated
0
572 offset = qMin(4, countRepeat(format, pos));-
573 validator = &m_monthValidator;-
574 } else if (nextChar == QLatin1Char('y')) {
never executed: end of block
nextChar == QLatin1Char('y')Description
TRUEnever evaluated
FALSEnever evaluated
0
575 offset = qMin(4, countRepeat(format, pos));-
576 validator = &m_yearValidator;-
577 } else {
never executed: end of block
0
578 separator += nextChar;-
579 }
never executed: end of block
0
580 if (validator) {
validatorDescription
TRUEnever evaluated
FALSEnever evaluated
0
581 m_tokens.push_back(SectionToken(validator, offset));-
582 m_separators.append(separator);-
583 separator = QString();-
584 if (m_currentToken < 0)
m_currentToken < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
585 m_currentToken = int(m_tokens.size()) - 1;
never executed: m_currentToken = int(m_tokens.size()) - 1;
0
586-
587 }
never executed: end of block
0
588 }
never executed: end of block
0
589 }-
590 pos += offset;-
591 }
never executed: end of block
0
592 m_separators += separator;-
593}
never executed: end of block
0
594-
595void QCalendarDateValidator::applyToDate()-
596{-
597 m_currentDate = m_yearValidator.applyToDate(m_currentDate);-
598 m_currentDate = m_monthValidator.applyToDate(m_currentDate);-
599 m_currentDate = m_dayValidator.applyToDate(m_currentDate);-
600}
never executed: end of block
0
601-
602void QCalendarDateValidator::toNextToken()-
603{-
604 if (m_currentToken < 0)
m_currentToken < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
605 return;
never executed: return;
0
606 ++m_currentToken;-
607 m_currentToken %= m_tokens.size();-
608}
never executed: end of block
0
609-
610void QCalendarDateValidator::toPreviousToken()-
611{-
612 if (m_currentToken < 0)
m_currentToken < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
613 return;
never executed: return;
0
614 --m_currentToken;-
615 m_currentToken %= m_tokens.size();-
616}
never executed: end of block
0
617-
618void QCalendarDateValidator::handleKeyEvent(QKeyEvent *keyEvent)-
619{-
620 if (m_currentToken < 0)
m_currentToken < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
621 return;
never executed: return;
0
622-
623 int key = keyEvent->key();-
624 if (m_lastSectionMove == QCalendarDateSectionValidator::NextSection) {
m_lastSectionM...r::NextSectionDescription
TRUEnever evaluated
FALSEnever evaluated
0
625 if (key == Qt::Key_Back || key == Qt::Key_Backspace)
key == Qt::Key_BackDescription
TRUEnever evaluated
FALSEnever evaluated
key == Qt::Key_BackspaceDescription
TRUEnever evaluated
FALSEnever evaluated
0
626 toPreviousToken();
never executed: toPreviousToken();
0
627 }
never executed: end of block
0
628 if (key == Qt::Key_Right)
key == Qt::Key_RightDescription
TRUEnever evaluated
FALSEnever evaluated
0
629 toNextToken();
never executed: toNextToken();
0
630 else if (key == Qt::Key_Left)
key == Qt::Key_LeftDescription
TRUEnever evaluated
FALSEnever evaluated
0
631 toPreviousToken();
never executed: toPreviousToken();
0
632-
633 m_lastSectionMove = m_tokens[m_currentToken].validator->handleKey(key);-
634-
635 applyToDate();-
636 if (m_lastSectionMove == QCalendarDateSectionValidator::NextSection)
m_lastSectionM...r::NextSectionDescription
TRUEnever evaluated
FALSEnever evaluated
0
637 toNextToken();
never executed: toNextToken();
0
638 else if (m_lastSectionMove == QCalendarDateSectionValidator::PrevSection)
m_lastSectionM...r::PrevSectionDescription
TRUEnever evaluated
FALSEnever evaluated
0
639 toPreviousToken();
never executed: toPreviousToken();
0
640}
never executed: end of block
0
641-
642//////////////////////////////////-
643-
644class QCalendarTextNavigator: public QObject-
645{-
646 Q_OBJECT-
647public:-
648 QCalendarTextNavigator(QObject *parent = 0)-
649 : QObject(parent), m_dateText(0), m_dateFrame(0), m_dateValidator(0), m_widget(0), m_editDelay(1500), m_date(QDate::currentDate()) { }
never executed: end of block
0
650-
651 QWidget *widget() const;-
652 void setWidget(QWidget *widget);-
653-
654 int dateEditAcceptDelay() const;-
655 void setDateEditAcceptDelay(int delay);-
656-
657 void setDate(const QDate &date);-
658-
659 bool eventFilter(QObject *o, QEvent *e) Q_DECL_OVERRIDE;-
660 void timerEvent(QTimerEvent *e) Q_DECL_OVERRIDE;-
661-
662signals:-
663 void dateChanged(const QDate &date);-
664 void editingFinished();-
665-
666private:-
667 void applyDate();-
668 void updateDateLabel();-
669 void createDateLabel();-
670 void removeDateLabel();-
671-
672 QLabel *m_dateText;-
673 QFrame *m_dateFrame;-
674 QBasicTimer m_acceptTimer;-
675 QCalendarDateValidator *m_dateValidator;-
676 QWidget *m_widget;-
677 int m_editDelay;-
678-
679 QDate m_date;-
680};-
681-
682QWidget *QCalendarTextNavigator::widget() const-
683{-
684 return m_widget;
never executed: return m_widget;
0
685}-
686-
687void QCalendarTextNavigator::setWidget(QWidget *widget)-
688{-
689 m_widget = widget;-
690}
never executed: end of block
0
691-
692void QCalendarTextNavigator::setDate(const QDate &date)-
693{-
694 m_date = date;-
695}
never executed: end of block
0
696-
697void QCalendarTextNavigator::updateDateLabel()-
698{-
699 if (!m_widget)
!m_widgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
700 return;
never executed: return;
0
701-
702 m_acceptTimer.start(m_editDelay, this);-
703-
704 m_dateText->setText(m_dateValidator->currentText());-
705-
706 QSize s = m_dateFrame->sizeHint();-
707 QRect r = m_widget->geometry(); // later, just the table section-
708 QRect newRect((r.width() - s.width()) / 2, (r.height() - s.height()) / 2, s.width(), s.height());-
709 m_dateFrame->setGeometry(newRect);-
710 // need to set palette after geometry update as phonestyle sets transparency-
711 // effect in move event.-
712 QPalette p = m_dateFrame->palette();-
713 p.setBrush(QPalette::Window, m_dateFrame->window()->palette().brush(QPalette::Window));-
714 m_dateFrame->setPalette(p);-
715-
716 m_dateFrame->raise();-
717 m_dateFrame->show();-
718}
never executed: end of block
0
719-
720void QCalendarTextNavigator::applyDate()-
721{-
722 QDate date = m_dateValidator->currentDate();-
723 if (m_date == date)
m_date == dateDescription
TRUEnever evaluated
FALSEnever evaluated
0
724 return;
never executed: return;
0
725-
726 m_date = date;-
727 emit dateChanged(date);-
728}
never executed: end of block
0
729-
730void QCalendarTextNavigator::createDateLabel()-
731{-
732 if (m_dateFrame)
m_dateFrameDescription
TRUEnever evaluated
FALSEnever evaluated
0
733 return;
never executed: return;
0
734 m_dateFrame = new QFrame(m_widget);-
735 QVBoxLayout *vl = new QVBoxLayout;-
736 m_dateText = new QLabel;-
737 vl->addWidget(m_dateText);-
738 m_dateFrame->setLayout(vl);-
739 m_dateFrame->setFrameShadow(QFrame::Plain);-
740 m_dateFrame->setFrameShape(QFrame::Box);-
741 m_dateValidator = new QCalendarDateValidator();-
742 m_dateValidator->setLocale(m_widget->locale());-
743 m_dateValidator->setFormat(m_widget->locale().dateFormat(QLocale::ShortFormat));-
744 m_dateValidator->setInitialDate(m_date);-
745-
746 m_dateFrame->setAutoFillBackground(true);-
747 m_dateFrame->setBackgroundRole(QPalette::Window);-
748}
never executed: end of block
0
749-
750void QCalendarTextNavigator::removeDateLabel()-
751{-
752 if (!m_dateFrame)
!m_dateFrameDescription
TRUEnever evaluated
FALSEnever evaluated
0
753 return;
never executed: return;
0
754 m_acceptTimer.stop();-
755 m_dateFrame->hide();-
756 m_dateFrame->deleteLater();-
757 delete m_dateValidator;-
758 m_dateFrame = 0;-
759 m_dateText = 0;-
760 m_dateValidator = 0;-
761}
never executed: end of block
0
762-
763bool QCalendarTextNavigator::eventFilter(QObject *o, QEvent *e)-
764{-
765 if (m_widget) {
m_widgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
766 if (e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease) {
e->type() == QEvent::KeyPressDescription
TRUEnever evaluated
FALSEnever evaluated
e->type() == Q...nt::KeyReleaseDescription
TRUEnever evaluated
FALSEnever evaluated
0
767 QKeyEvent* ke = (QKeyEvent*)e;-
768 if ((ke->text().length() > 0 && ke->text()[0].isPrint()) || m_dateFrame) {
ke->text().length() > 0Description
TRUEnever evaluated
FALSEnever evaluated
ke->text()[0].isPrint()Description
TRUEnever evaluated
FALSEnever evaluated
m_dateFrameDescription
TRUEnever evaluated
FALSEnever evaluated
0
769 if (ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Select) {
ke->key() == Qt::Key_ReturnDescription
TRUEnever evaluated
FALSEnever evaluated
ke->key() == Qt::Key_EnterDescription
TRUEnever evaluated
FALSEnever evaluated
ke->key() == Qt::Key_SelectDescription
TRUEnever evaluated
FALSEnever evaluated
0
770 applyDate();-
771 emit editingFinished();-
772 removeDateLabel();-
773 } else if (ke->matches(QKeySequence::Cancel)) {
never executed: end of block
ke->matches(QK...uence::Cancel)Description
TRUEnever evaluated
FALSEnever evaluated
0
774 removeDateLabel();-
775 } else if (e->type() == QEvent::KeyPress) {
never executed: end of block
e->type() == QEvent::KeyPressDescription
TRUEnever evaluated
FALSEnever evaluated
0
776 createDateLabel();-
777 m_dateValidator->handleKeyEvent(ke);-
778 updateDateLabel();-
779 }
never executed: end of block
0
780 ke->accept();-
781 return true;
never executed: return true;
0
782 }-
783 // If we are navigating let the user finish his date in old locate.-
784 // If we change our mind and want it to update immediately simply uncomment below-
785 /*-
786 } else if (e->type() == QEvent::LocaleChange) {-
787 if (m_dateValidator) {-
788 m_dateValidator->setLocale(m_widget->locale());-
789 m_dateValidator->setFormat(m_widget->locale().dateFormat(QLocale::ShortFormat));-
790 updateDateLabel();-
791 }-
792 */-
793 }
never executed: end of block
0
794 }
never executed: end of block
0
795 return QObject::eventFilter(o,e);
never executed: return QObject::eventFilter(o,e);
0
796}-
797-
798void QCalendarTextNavigator::timerEvent(QTimerEvent *e)-
799{-
800 if (e->timerId() == m_acceptTimer.timerId()) {
e->timerId() =...imer.timerId()Description
TRUEnever evaluated
FALSEnever evaluated
0
801 applyDate();-
802 removeDateLabel();-
803 }
never executed: end of block
0
804}
never executed: end of block
0
805-
806int QCalendarTextNavigator::dateEditAcceptDelay() const-
807{-
808 return m_editDelay;
never executed: return m_editDelay;
0
809}-
810-
811void QCalendarTextNavigator::setDateEditAcceptDelay(int delay)-
812{-
813 m_editDelay = delay;-
814}
never executed: end of block
0
815-
816class QCalendarView;-
817-
818// a small helper class that replaces a QMap<Qt::DayOfWeek, T>,-
819// but requires T to have a member-swap and a default constructor-
820// which should be cheap (no memory allocations)-
821-
822QT_WARNING_PUSH-
823QT_WARNING_DISABLE_MSVC(4351) // "new behavior: elements of array ... will be default initialized"-
824-
825template <typename T>-
826class StaticDayOfWeekAssociativeArray {-
827 bool contained[7];-
828 T data[7];-
829-
830 static Q_DECL_CONSTEXPR int day2idx(Qt::DayOfWeek day) Q_DECL_NOTHROW { return int(day) - 1; } // alt: day % 7-
831public:-
832 Q_DECL_CONSTEXPR StaticDayOfWeekAssociativeArray() Q_DECL_NOEXCEPT_EXPR(noexcept(T()))-
833 : contained(), data() {}-
834-
835 Q_DECL_CONSTEXPR bool contains(Qt::DayOfWeek day) const Q_DECL_NOTHROW { return contained[day2idx(day)]; }-
836 Q_DECL_CONSTEXPR const T &value(Qt::DayOfWeek day) const Q_DECL_NOTHROW { return data[day2idx(day)]; }-
837-
838 Q_DECL_RELAXED_CONSTEXPR T &operator[](Qt::DayOfWeek day) Q_DECL_NOTHROW-
839 {-
840 const int idx = day2idx(day);-
841 contained[idx] = true;-
842 return data[idx];
never executed: return data[idx];
0
843 }-
844-
845 Q_DECL_RELAXED_CONSTEXPR void insert(Qt::DayOfWeek day, T v) Q_DECL_NOTHROW-
846 {-
847 operator[](day).swap(v);-
848 }
never executed: end of block
0
849};-
850-
851QT_WARNING_POP-
852-
853class QCalendarModel : public QAbstractTableModel-
854{-
855 Q_OBJECT-
856public:-
857 QCalendarModel(QObject *parent = 0);-
858-
859 int rowCount(const QModelIndex &) const Q_DECL_OVERRIDE-
860 { return RowCount + m_firstRow; }
never executed: return RowCount + m_firstRow;
0
861 int columnCount(const QModelIndex &) const Q_DECL_OVERRIDE-
862 { return ColumnCount + m_firstColumn; }
never executed: return ColumnCount + m_firstColumn;
0
863 QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;-
864 Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;-
865-
866 bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE-
867 {-
868 beginInsertRows(parent, row, row + count - 1);-
869 endInsertRows();-
870 return true;
never executed: return true;
0
871 }-
872 bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE-
873 {-
874 beginInsertColumns(parent, column, column + count - 1);-
875 endInsertColumns();-
876 return true;
never executed: return true;
0
877 }-
878 bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE-
879 {-
880 beginRemoveRows(parent, row, row + count - 1);-
881 endRemoveRows();-
882 return true;
never executed: return true;
0
883 }-
884 bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE-
885 {-
886 beginRemoveColumns(parent, column, column + count - 1);-
887 endRemoveColumns();-
888 return true;
never executed: return true;
0
889 }-
890-
891 void showMonth(int year, int month);-
892 void setDate(const QDate &d);-
893-
894 void setMinimumDate(const QDate &date);-
895 void setMaximumDate(const QDate &date);-
896-
897 void setRange(const QDate &min, const QDate &max);-
898-
899 void setHorizontalHeaderFormat(QCalendarWidget::HorizontalHeaderFormat format);-
900-
901 void setFirstColumnDay(Qt::DayOfWeek dayOfWeek);-
902 Qt::DayOfWeek firstColumnDay() const;-
903-
904 bool weekNumbersShown() const;-
905 void setWeekNumbersShown(bool show);-
906-
907 QTextCharFormat formatForCell(int row, int col) const;-
908 Qt::DayOfWeek dayOfWeekForColumn(int section) const;-
909 int columnForDayOfWeek(Qt::DayOfWeek day) const;-
910 QDate dateForCell(int row, int column) const;-
911 void cellForDate(const QDate &date, int *row, int *column) const;-
912 QString dayName(Qt::DayOfWeek day) const;-
913-
914 void setView(QCalendarView *view)-
915 { m_view = view; }
never executed: end of block
0
916-
917 void internalUpdate();-
918 QDate referenceDate() const;-
919 int columnForFirstOfMonth(const QDate &date) const;-
920-
921 int m_firstColumn;-
922 int m_firstRow;-
923 QDate m_date;-
924 QDate m_minimumDate;-
925 QDate m_maximumDate;-
926 int m_shownYear;-
927 int m_shownMonth;-
928 Qt::DayOfWeek m_firstDay;-
929 QCalendarWidget::HorizontalHeaderFormat m_horizontalHeaderFormat;-
930 bool m_weekNumbersShown;-
931 StaticDayOfWeekAssociativeArray<QTextCharFormat> m_dayFormats;-
932 QMap<QDate, QTextCharFormat> m_dateFormats;-
933 QTextCharFormat m_headerFormat;-
934 QCalendarView *m_view;-
935};-
936-
937class QCalendarView : public QTableView-
938{-
939 Q_OBJECT-
940public:-
941 QCalendarView(QWidget *parent = 0);-
942-
943 void internalUpdate() { updateGeometries(); }
never executed: end of block
0
944 void setReadOnly(bool enable);-
945 virtual void keyboardSearch(const QString & search) Q_DECL_OVERRIDE { Q_UNUSED(search) }
never executed: end of block
0
946-
947signals:-
948 void showDate(const QDate &date);-
949 void changeDate(const QDate &date, bool changeMonth);-
950 void clicked(const QDate &date);-
951 void editingFinished();-
952protected:-
953 QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) Q_DECL_OVERRIDE;-
954 void mouseDoubleClickEvent(QMouseEvent *event) Q_DECL_OVERRIDE;-
955 void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;-
956 void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;-
957 void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;-
958#ifndef QT_NO_WHEELEVENT-
959 void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;-
960#endif-
961 void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;-
962 bool event(QEvent *event) Q_DECL_OVERRIDE;-
963-
964 QDate handleMouseEvent(QMouseEvent *event);-
965public:-
966 bool readOnly;-
967private:-
968 bool validDateClicked;-
969#ifdef QT_KEYPAD_NAVIGATION-
970 QDate origDate;-
971#endif-
972};-
973-
974QCalendarModel::QCalendarModel(QObject *parent)-
975 : QAbstractTableModel(parent),-
976 m_firstColumn(1),-
977 m_firstRow(1),-
978 m_date(QDate::currentDate()),-
979 m_minimumDate(QDate::fromJulianDay(1)),-
980 m_maximumDate(7999, 12, 31),-
981 m_shownYear(m_date.year()),-
982 m_shownMonth(m_date.month()),-
983 m_firstDay(QLocale().firstDayOfWeek()),-
984 m_horizontalHeaderFormat(QCalendarWidget::ShortDayNames),-
985 m_weekNumbersShown(true),-
986 m_view(Q_NULLPTR)-
987{-
988}
never executed: end of block
0
989-
990Qt::DayOfWeek QCalendarModel::dayOfWeekForColumn(int column) const-
991{-
992 int col = column - m_firstColumn;-
993 if (col < 0 || col > 6)
col < 0Description
TRUEnever evaluated
FALSEnever evaluated
col > 6Description
TRUEnever evaluated
FALSEnever evaluated
0
994 return Qt::Sunday;
never executed: return Qt::Sunday;
0
995 int day = m_firstDay + col;-
996 if (day > 7)
day > 7Description
TRUEnever evaluated
FALSEnever evaluated
0
997 day -= 7;
never executed: day -= 7;
0
998 return Qt::DayOfWeek(day);
never executed: return Qt::DayOfWeek(day);
0
999}-
1000-
1001int QCalendarModel::columnForDayOfWeek(Qt::DayOfWeek day) const-
1002{-
1003 if (day < 1 || day > 7)
day < 1Description
TRUEnever evaluated
FALSEnever evaluated
day > 7Description
TRUEnever evaluated
FALSEnever evaluated
0
1004 return -1;
never executed: return -1;
0
1005 int column = (int)day - (int)m_firstDay;-
1006 if (column < 0)
column < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1007 column += 7;
never executed: column += 7;
0
1008 return column + m_firstColumn;
never executed: return column + m_firstColumn;
0
1009}-
1010-
1011/*-
1012This simple algorithm tries to generate a valid date from the month shown.-
1013Some months don't contain a first day (e.g. Jan of -4713 year,-
1014so QDate (-4713, 1, 1) would be invalid). In that case we try to generate-
1015another valid date for that month. Later, returned date's day is the number of cells-
1016calendar widget will reserve for days before referenceDate. (E.g. if returned date's-
1017day is 16, that day will be placed in 3rd or 4th row, not in the 1st or 2nd row).-
1018Depending on referenceData we can change behaviour of Oct 1582. If referenceDate is 1st-
1019of Oct we render 1 Oct in 1st or 2nd row. If referenceDate is 17 of Oct we show always 16-
1020dates before 17 of Oct, and since this month contains the hole 5-14 Oct, the first of Oct-
1021will be rendered in 2nd or 3rd row, showing more dates from previous month.-
1022*/-
1023QDate QCalendarModel::referenceDate() const-
1024{-
1025 int refDay = 1;-
1026 while (refDay <= 31) {
refDay <= 31Description
TRUEnever evaluated
FALSEnever evaluated
0
1027 QDate refDate(m_shownYear, m_shownMonth, refDay);-
1028 if (refDate.isValid())
refDate.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1029 return refDate;
never executed: return refDate;
0
1030 refDay += 1;-
1031 }
never executed: end of block
0
1032 return QDate();
never executed: return QDate();
0
1033}-
1034-
1035int QCalendarModel::columnForFirstOfMonth(const QDate &date) const-
1036{-
1037 return (columnForDayOfWeek(static_cast<Qt::DayOfWeek>(date.dayOfWeek())) - (date.day() % 7) + 8) % 7;
never executed: return (columnForDayOfWeek(static_cast<Qt::DayOfWeek>(date.dayOfWeek())) - (date.day() % 7) + 8) % 7;
0
1038}-
1039-
1040QDate QCalendarModel::dateForCell(int row, int column) const-
1041{-
1042 if (row < m_firstRow || row > m_firstRow + RowCount - 1 ||
row < m_firstRowDescription
TRUEnever evaluated
FALSEnever evaluated
row > m_firstR...+ RowCount - 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1043 column < m_firstColumn || column > m_firstColumn + ColumnCount - 1)
column < m_firstColumnDescription
TRUEnever evaluated
FALSEnever evaluated
column > m_fir...olumnCount - 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1044 return QDate();
never executed: return QDate();
0
1045 const QDate refDate = referenceDate();-
1046 if (!refDate.isValid())
!refDate.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1047 return QDate();
never executed: return QDate();
0
1048-
1049 const int columnForFirstOfShownMonth = columnForFirstOfMonth(refDate);-
1050 if (columnForFirstOfShownMonth - m_firstColumn < MinimumDayOffset)
columnForFirst...nimumDayOffsetDescription
TRUEnever evaluated
FALSEnever evaluated
0
1051 row -= 1;
never executed: row -= 1;
0
1052-
1053 const int requestedDay = 7 * (row - m_firstRow) + column - columnForFirstOfShownMonth - refDate.day() + 1;-
1054 return refDate.addDays(requestedDay);
never executed: return refDate.addDays(requestedDay);
0
1055}-
1056-
1057void QCalendarModel::cellForDate(const QDate &date, int *row, int *column) const-
1058{-
1059 if (!row && !column)
!rowDescription
TRUEnever evaluated
FALSEnever evaluated
!columnDescription
TRUEnever evaluated
FALSEnever evaluated
0
1060 return;
never executed: return;
0
1061-
1062 if (row)
rowDescription
TRUEnever evaluated
FALSEnever evaluated
0
1063 *row = -1;
never executed: *row = -1;
0
1064 if (column)
columnDescription
TRUEnever evaluated
FALSEnever evaluated
0
1065 *column = -1;
never executed: *column = -1;
0
1066-
1067 const QDate refDate = referenceDate();-
1068 if (!refDate.isValid())
!refDate.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1069 return;
never executed: return;
0
1070-
1071 const int columnForFirstOfShownMonth = columnForFirstOfMonth(refDate);-
1072 const int requestedPosition = refDate.daysTo(date) - m_firstColumn + columnForFirstOfShownMonth + refDate.day() - 1;-
1073-
1074 int c = requestedPosition % 7;-
1075 int r = requestedPosition / 7;-
1076 if (c < 0) {
c < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1077 c += 7;-
1078 r -= 1;-
1079 }
never executed: end of block
0
1080-
1081 if (columnForFirstOfShownMonth - m_firstColumn < MinimumDayOffset)
columnForFirst...nimumDayOffsetDescription
TRUEnever evaluated
FALSEnever evaluated
0
1082 r += 1;
never executed: r += 1;
0
1083-
1084 if (r < 0 || r > RowCount - 1 || c < 0 || c > ColumnCount - 1)
r < 0Description
TRUEnever evaluated
FALSEnever evaluated
r > RowCount - 1Description
TRUEnever evaluated
FALSEnever evaluated
c < 0Description
TRUEnever evaluated
FALSEnever evaluated
c > ColumnCount - 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1085 return;
never executed: return;
0
1086-
1087 if (row)
rowDescription
TRUEnever evaluated
FALSEnever evaluated
0
1088 *row = r + m_firstRow;
never executed: *row = r + m_firstRow;
0
1089 if (column)
columnDescription
TRUEnever evaluated
FALSEnever evaluated
0
1090 *column = c + m_firstColumn;
never executed: *column = c + m_firstColumn;
0
1091}
never executed: end of block
0
1092-
1093QString QCalendarModel::dayName(Qt::DayOfWeek day) const-
1094{-
1095 switch (m_horizontalHeaderFormat) {-
1096 case QCalendarWidget::SingleLetterDayNames: {
never executed: case QCalendarWidget::SingleLetterDayNames:
0
1097 QString standaloneDayName = m_view->locale().standaloneDayName(day, QLocale::NarrowFormat);-
1098 if (standaloneDayName == m_view->locale().dayName(day, QLocale::NarrowFormat))
standaloneDayN...:NarrowFormat)Description
TRUEnever evaluated
FALSEnever evaluated
0
1099 return standaloneDayName.left(1);
never executed: return standaloneDayName.left(1);
0
1100 return standaloneDayName;
never executed: return standaloneDayName;
0
1101 }-
1102 case QCalendarWidget::ShortDayNames:
never executed: case QCalendarWidget::ShortDayNames:
0
1103 return m_view->locale().dayName(day, QLocale::ShortFormat);
never executed: return m_view->locale().dayName(day, QLocale::ShortFormat);
0
1104 case QCalendarWidget::LongDayNames:
never executed: case QCalendarWidget::LongDayNames:
0
1105 return m_view->locale().dayName(day, QLocale::LongFormat);
never executed: return m_view->locale().dayName(day, QLocale::LongFormat);
0
1106 default:
never executed: default:
0
1107 break;
never executed: break;
0
1108 }-
1109 return QString();
never executed: return QString();
0
1110}-
1111-
1112QTextCharFormat QCalendarModel::formatForCell(int row, int col) const-
1113{-
1114 QPalette pal;-
1115 QPalette::ColorGroup cg = QPalette::Active;-
1116 if (m_view) {
m_viewDescription
TRUEnever evaluated
FALSEnever evaluated
0
1117 pal = m_view->palette();-
1118 if (!m_view->isEnabled())
!m_view->isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
1119 cg = QPalette::Disabled;
never executed: cg = QPalette::Disabled;
0
1120 else if (!m_view->isActiveWindow())
!m_view->isActiveWindow()Description
TRUEnever evaluated
FALSEnever evaluated
0
1121 cg = QPalette::Inactive;
never executed: cg = QPalette::Inactive;
0
1122 }
never executed: end of block
0
1123-
1124 QTextCharFormat format;-
1125 format.setFont(m_view->font());-
1126 bool header = (m_weekNumbersShown && col == HeaderColumn)
m_weekNumbersShownDescription
TRUEnever evaluated
FALSEnever evaluated
col == HeaderColumnDescription
TRUEnever evaluated
FALSEnever evaluated
0
1127 || (m_horizontalHeaderFormat != QCalendarWidget::NoHorizontalHeader && row == HeaderRow);
m_horizontalHe...rizontalHeaderDescription
TRUEnever evaluated
FALSEnever evaluated
row == HeaderRowDescription
TRUEnever evaluated
FALSEnever evaluated
0
1128 format.setBackground(pal.brush(cg, header ? QPalette::AlternateBase : QPalette::Base));-
1129 format.setForeground(pal.brush(cg, QPalette::Text));-
1130 if (header) {
headerDescription
TRUEnever evaluated
FALSEnever evaluated
0
1131 format.merge(m_headerFormat);-
1132 }
never executed: end of block
0
1133-
1134 if (col >= m_firstColumn && col < m_firstColumn + ColumnCount) {
col >= m_firstColumnDescription
TRUEnever evaluated
FALSEnever evaluated
col < m_firstC... + ColumnCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
1135 Qt::DayOfWeek dayOfWeek = dayOfWeekForColumn(col);-
1136 if (m_dayFormats.contains(dayOfWeek))
m_dayFormats.c...ins(dayOfWeek)Description
TRUEnever evaluated
FALSEnever evaluated
0
1137 format.merge(m_dayFormats.value(dayOfWeek));
never executed: format.merge(m_dayFormats.value(dayOfWeek));
0
1138 }
never executed: end of block
0
1139-
1140 if (!header) {
!headerDescription
TRUEnever evaluated
FALSEnever evaluated
0
1141 QDate date = dateForCell(row, col);-
1142 format.merge(m_dateFormats.value(date));-
1143 if(date < m_minimumDate || date > m_maximumDate)
date < m_minimumDateDescription
TRUEnever evaluated
FALSEnever evaluated
date > m_maximumDateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1144 format.setBackground(pal.brush(cg, QPalette::Window));
never executed: format.setBackground(pal.brush(cg, QPalette::Window));
0
1145 if (m_shownMonth != date.month())
m_shownMonth != date.month()Description
TRUEnever evaluated
FALSEnever evaluated
0
1146 format.setForeground(pal.brush(QPalette::Disabled, QPalette::Text));
never executed: format.setForeground(pal.brush(QPalette::Disabled, QPalette::Text));
0
1147 }
never executed: end of block
0
1148 return format;
never executed: return format;
0
1149}-
1150-
1151QVariant QCalendarModel::data(const QModelIndex &index, int role) const-
1152{-
1153 if (role == Qt::TextAlignmentRole)
role == Qt::TextAlignmentRoleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1154 return (int) Qt::AlignCenter;
never executed: return (int) Qt::AlignCenter;
0
1155-
1156 int row = index.row();-
1157 int column = index.column();-
1158-
1159 if(role == Qt::DisplayRole) {
role == Qt::DisplayRoleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1160 if (m_weekNumbersShown && column == HeaderColumn
m_weekNumbersShownDescription
TRUEnever evaluated
FALSEnever evaluated
column == HeaderColumnDescription
TRUEnever evaluated
FALSEnever evaluated
0
1161 && row >= m_firstRow && row < m_firstRow + RowCount) {
row >= m_firstRowDescription
TRUEnever evaluated
FALSEnever evaluated
row < m_firstRow + RowCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
1162 QDate date = dateForCell(row, columnForDayOfWeek(Qt::Monday));-
1163 if (date.isValid())
date.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1164 return date.weekNumber();
never executed: return date.weekNumber();
0
1165 }
never executed: end of block
0
1166 if (m_horizontalHeaderFormat != QCalendarWidget::NoHorizontalHeader && row == HeaderRow
m_horizontalHe...rizontalHeaderDescription
TRUEnever evaluated
FALSEnever evaluated
row == HeaderRowDescription
TRUEnever evaluated
FALSEnever evaluated
0
1167 && column >= m_firstColumn && column < m_firstColumn + ColumnCount)
column >= m_firstColumnDescription
TRUEnever evaluated
FALSEnever evaluated
column < m_fir... + ColumnCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
1168 return dayName(dayOfWeekForColumn(column));
never executed: return dayName(dayOfWeekForColumn(column));
0
1169 QDate date = dateForCell(row, column);-
1170 if (date.isValid())
date.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1171 return date.day();
never executed: return date.day();
0
1172 return QString();
never executed: return QString();
0
1173 }-
1174-
1175 QTextCharFormat fmt = formatForCell(row, column);-
1176 if (role == Qt::BackgroundColorRole)
role == Qt::Ba...roundColorRoleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1177 return fmt.background().color();
never executed: return fmt.background().color();
0
1178 if (role == Qt::TextColorRole)
role == Qt::TextColorRoleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1179 return fmt.foreground().color();
never executed: return fmt.foreground().color();
0
1180 if (role == Qt::FontRole)
role == Qt::FontRoleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1181 return fmt.font();
never executed: return fmt.font();
0
1182 if (role == Qt::ToolTipRole)
role == Qt::ToolTipRoleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1183 return fmt.toolTip();
never executed: return fmt.toolTip();
0
1184 return QVariant();
never executed: return QVariant();
0
1185}-
1186-
1187Qt::ItemFlags QCalendarModel::flags(const QModelIndex &index) const-
1188{-
1189 QDate date = dateForCell(index.row(), index.column());-
1190 if (!date.isValid())
!date.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1191 return QAbstractTableModel::flags(index);
never executed: return QAbstractTableModel::flags(index);
0
1192 if (date < m_minimumDate)
date < m_minimumDateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1193 return 0;
never executed: return 0;
0
1194 if (date > m_maximumDate)
date > m_maximumDateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1195 return 0;
never executed: return 0;
0
1196 return QAbstractTableModel::flags(index);
never executed: return QAbstractTableModel::flags(index);
0
1197}-
1198-
1199void QCalendarModel::setDate(const QDate &d)-
1200{-
1201 m_date = d;-
1202 if (m_date < m_minimumDate)
m_date < m_minimumDateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1203 m_date = m_minimumDate;
never executed: m_date = m_minimumDate;
0
1204 else if (m_date > m_maximumDate)
m_date > m_maximumDateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1205 m_date = m_maximumDate;
never executed: m_date = m_maximumDate;
0
1206}
never executed: end of block
0
1207-
1208void QCalendarModel::showMonth(int year, int month)-
1209{-
1210 if (m_shownYear == year && m_shownMonth == month)
m_shownYear == yearDescription
TRUEnever evaluated
FALSEnever evaluated
m_shownMonth == monthDescription
TRUEnever evaluated
FALSEnever evaluated
0
1211 return;
never executed: return;
0
1212-
1213 m_shownYear = year;-
1214 m_shownMonth = month;-
1215-
1216 internalUpdate();-
1217}
never executed: end of block
0
1218-
1219void QCalendarModel::setMinimumDate(const QDate &d)-
1220{-
1221 if (!d.isValid() || d == m_minimumDate)
!d.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
d == m_minimumDateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1222 return;
never executed: return;
0
1223-
1224 m_minimumDate = d;-
1225 if (m_maximumDate < m_minimumDate)
m_maximumDate < m_minimumDateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1226 m_maximumDate = m_minimumDate;
never executed: m_maximumDate = m_minimumDate;
0
1227 if (m_date < m_minimumDate)
m_date < m_minimumDateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1228 m_date = m_minimumDate;
never executed: m_date = m_minimumDate;
0
1229 internalUpdate();-
1230}
never executed: end of block
0
1231-
1232void QCalendarModel::setMaximumDate(const QDate &d)-
1233{-
1234 if (!d.isValid() || d == m_maximumDate)
!d.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
d == m_maximumDateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1235 return;
never executed: return;
0
1236-
1237 m_maximumDate = d;-
1238 if (m_minimumDate > m_maximumDate)
m_minimumDate > m_maximumDateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1239 m_minimumDate = m_maximumDate;
never executed: m_minimumDate = m_maximumDate;
0
1240 if (m_date > m_maximumDate)
m_date > m_maximumDateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1241 m_date = m_maximumDate;
never executed: m_date = m_maximumDate;
0
1242 internalUpdate();-
1243}
never executed: end of block
0
1244-
1245void QCalendarModel::setRange(const QDate &min, const QDate &max)-
1246{-
1247 m_minimumDate = min;-
1248 m_maximumDate = max;-
1249 if (m_minimumDate > m_maximumDate)
m_minimumDate > m_maximumDateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1250 qSwap(m_minimumDate, m_maximumDate);
never executed: qSwap(m_minimumDate, m_maximumDate);
0
1251 if (m_date < m_minimumDate)
m_date < m_minimumDateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1252 m_date = m_minimumDate;
never executed: m_date = m_minimumDate;
0
1253 if (m_date > m_maximumDate)
m_date > m_maximumDateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1254 m_date = m_maximumDate;
never executed: m_date = m_maximumDate;
0
1255 internalUpdate();-
1256}
never executed: end of block
0
1257-
1258void QCalendarModel::internalUpdate()-
1259{-
1260 QModelIndex begin = index(0, 0);-
1261 QModelIndex end = index(m_firstRow + RowCount - 1, m_firstColumn + ColumnCount - 1);-
1262 emit dataChanged(begin, end);-
1263 emit headerDataChanged(Qt::Vertical, 0, m_firstRow + RowCount - 1);-
1264 emit headerDataChanged(Qt::Horizontal, 0, m_firstColumn + ColumnCount - 1);-
1265}
never executed: end of block
0
1266-
1267void QCalendarModel::setHorizontalHeaderFormat(QCalendarWidget::HorizontalHeaderFormat format)-
1268{-
1269 if (m_horizontalHeaderFormat == format)
m_horizontalHe...rmat == formatDescription
TRUEnever evaluated
FALSEnever evaluated
0
1270 return;
never executed: return;
0
1271-
1272 int oldFormat = m_horizontalHeaderFormat;-
1273 m_horizontalHeaderFormat = format;-
1274 if (oldFormat == QCalendarWidget::NoHorizontalHeader) {
oldFormat == Q...rizontalHeaderDescription
TRUEnever evaluated
FALSEnever evaluated
0
1275 m_firstRow = 1;-
1276 insertRow(0);-
1277 } else if (m_horizontalHeaderFormat == QCalendarWidget::NoHorizontalHeader) {
never executed: end of block
m_horizontalHe...rizontalHeaderDescription
TRUEnever evaluated
FALSEnever evaluated
0
1278 m_firstRow = 0;-
1279 removeRow(0);-
1280 }
never executed: end of block
0
1281 internalUpdate();-
1282}
never executed: end of block
0
1283-
1284void QCalendarModel::setFirstColumnDay(Qt::DayOfWeek dayOfWeek)-
1285{-
1286 if (m_firstDay == dayOfWeek)
m_firstDay == dayOfWeekDescription
TRUEnever evaluated
FALSEnever evaluated
0
1287 return;
never executed: return;
0
1288-
1289 m_firstDay = dayOfWeek;-
1290 internalUpdate();-
1291}
never executed: end of block
0
1292-
1293Qt::DayOfWeek QCalendarModel::firstColumnDay() const-
1294{-
1295 return m_firstDay;
never executed: return m_firstDay;
0
1296}-
1297-
1298bool QCalendarModel::weekNumbersShown() const-
1299{-
1300 return m_weekNumbersShown;
never executed: return m_weekNumbersShown;
0
1301}-
1302-
1303void QCalendarModel::setWeekNumbersShown(bool show)-
1304{-
1305 if (m_weekNumbersShown == show)
m_weekNumbersShown == showDescription
TRUEnever evaluated
FALSEnever evaluated
0
1306 return;
never executed: return;
0
1307-
1308 m_weekNumbersShown = show;-
1309 if (show) {
showDescription
TRUEnever evaluated
FALSEnever evaluated
0
1310 m_firstColumn = 1;-
1311 insertColumn(0);-
1312 } else {
never executed: end of block
0
1313 m_firstColumn = 0;-
1314 removeColumn(0);-
1315 }
never executed: end of block
0
1316 internalUpdate();-
1317}
never executed: end of block
0
1318-
1319QCalendarView::QCalendarView(QWidget *parent)-
1320 : QTableView(parent),-
1321 readOnly(false),-
1322 validDateClicked(false)-
1323{-
1324 setTabKeyNavigation(false);-
1325 setShowGrid(false);-
1326 verticalHeader()->setVisible(false);-
1327 horizontalHeader()->setVisible(false);-
1328 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);-
1329 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);-
1330}
never executed: end of block
0
1331-
1332QModelIndex QCalendarView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)-
1333{-
1334 QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model());-
1335 if (!calendarModel)
!calendarModelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1336 return QTableView::moveCursor(cursorAction, modifiers);
never executed: return QTableView::moveCursor(cursorAction, modifiers);
0
1337-
1338 if (readOnly)
readOnlyDescription
TRUEnever evaluated
FALSEnever evaluated
0
1339 return currentIndex();
never executed: return currentIndex();
0
1340-
1341 QModelIndex index = currentIndex();-
1342 QDate currentDate = static_cast<QCalendarModel*>(model())->dateForCell(index.row(), index.column());-
1343 switch (cursorAction) {-
1344 case QAbstractItemView::MoveUp:
never executed: case QAbstractItemView::MoveUp:
0
1345 currentDate = currentDate.addDays(-7);-
1346 break;
never executed: break;
0
1347 case QAbstractItemView::MoveDown:
never executed: case QAbstractItemView::MoveDown:
0
1348 currentDate = currentDate.addDays(7);-
1349 break;
never executed: break;
0
1350 case QAbstractItemView::MoveLeft:
never executed: case QAbstractItemView::MoveLeft:
0
1351 currentDate = currentDate.addDays(isRightToLeft() ? 1 : -1);-
1352 break;
never executed: break;
0
1353 case QAbstractItemView::MoveRight:
never executed: case QAbstractItemView::MoveRight:
0
1354 currentDate = currentDate.addDays(isRightToLeft() ? -1 : 1);-
1355 break;
never executed: break;
0
1356 case QAbstractItemView::MoveHome:
never executed: case QAbstractItemView::MoveHome:
0
1357 currentDate = QDate(currentDate.year(), currentDate.month(), 1);-
1358 break;
never executed: break;
0
1359 case QAbstractItemView::MoveEnd:
never executed: case QAbstractItemView::MoveEnd:
0
1360 currentDate = QDate(currentDate.year(), currentDate.month(), currentDate.daysInMonth());-
1361 break;
never executed: break;
0
1362 case QAbstractItemView::MovePageUp:
never executed: case QAbstractItemView::MovePageUp:
0
1363 currentDate = currentDate.addMonths(-1);-
1364 break;
never executed: break;
0
1365 case QAbstractItemView::MovePageDown:
never executed: case QAbstractItemView::MovePageDown:
0
1366 currentDate = currentDate.addMonths(1);-
1367 break;
never executed: break;
0
1368 case QAbstractItemView::MoveNext:
never executed: case QAbstractItemView::MoveNext:
0
1369 case QAbstractItemView::MovePrevious:
never executed: case QAbstractItemView::MovePrevious:
0
1370 return currentIndex();
never executed: return currentIndex();
0
1371 default:
never executed: default:
0
1372 break;
never executed: break;
0
1373 }-
1374 emit changeDate(currentDate, true);-
1375 return currentIndex();
never executed: return currentIndex();
0
1376}-
1377-
1378void QCalendarView::keyPressEvent(QKeyEvent *event)-
1379{-
1380#ifdef QT_KEYPAD_NAVIGATION-
1381 if (event->key() == Qt::Key_Select) {-
1382 if (QApplication::keypadNavigationEnabled()) {-
1383 if (!hasEditFocus()) {-
1384 setEditFocus(true);-
1385 return;-
1386 }-
1387 }-
1388 } else if (event->key() == Qt::Key_Back) {-
1389 if (QApplication::keypadNavigationEnabled() && hasEditFocus()) {-
1390 if (qobject_cast<QCalendarModel *>(model())) {-
1391 emit changeDate(origDate, true); //changes selection back to origDate, but doesn't activate-
1392 setEditFocus(false);-
1393 return;-
1394 }-
1395 }-
1396 }-
1397#endif-
1398-
1399 if (!readOnly) {
!readOnlyDescription
TRUEnever evaluated
FALSEnever evaluated
0
1400 switch (event->key()) {-
1401 case Qt::Key_Return:
never executed: case Qt::Key_Return:
0
1402 case Qt::Key_Enter:
never executed: case Qt::Key_Enter:
0
1403 case Qt::Key_Select:
never executed: case Qt::Key_Select:
0
1404 emit editingFinished();-
1405 return;
never executed: return;
0
1406 default:
never executed: default:
0
1407 break;
never executed: break;
0
1408 }-
1409 }-
1410 QTableView::keyPressEvent(event);-
1411}
never executed: end of block
0
1412-
1413#ifndef QT_NO_WHEELEVENT-
1414void QCalendarView::wheelEvent(QWheelEvent *event)-
1415{-
1416 const int numDegrees = event->delta() / 8;-
1417 const int numSteps = numDegrees / 15;-
1418 const QModelIndex index = currentIndex();-
1419 QDate currentDate = static_cast<QCalendarModel*>(model())->dateForCell(index.row(), index.column());-
1420 currentDate = currentDate.addMonths(-numSteps);-
1421 emit showDate(currentDate);-
1422}
never executed: end of block
0
1423#endif-
1424-
1425bool QCalendarView::event(QEvent *event)-
1426{-
1427#ifdef QT_KEYPAD_NAVIGATION-
1428 if (event->type() == QEvent::FocusIn) {-
1429 if (QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model())) {-
1430 origDate = calendarModel->m_date;-
1431 }-
1432 }-
1433#endif-
1434-
1435 return QTableView::event(event);
never executed: return QTableView::event(event);
0
1436}-
1437-
1438QDate QCalendarView::handleMouseEvent(QMouseEvent *event)-
1439{-
1440 QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model());-
1441 if (!calendarModel)
!calendarModelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1442 return QDate();
never executed: return QDate();
0
1443-
1444 QPoint pos = event->pos();-
1445 QModelIndex index = indexAt(pos);-
1446 QDate date = calendarModel->dateForCell(index.row(), index.column());-
1447 if (date.isValid() && date >= calendarModel->m_minimumDate
date.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
date >= calend...>m_minimumDateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1448 && date <= calendarModel->m_maximumDate) {
date <= calend...>m_maximumDateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1449 return date;
never executed: return date;
0
1450 }-
1451 return QDate();
never executed: return QDate();
0
1452}-
1453-
1454void QCalendarView::mouseDoubleClickEvent(QMouseEvent *event)-
1455{-
1456 QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model());-
1457 if (!calendarModel) {
!calendarModelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1458 QTableView::mouseDoubleClickEvent(event);-
1459 return;
never executed: return;
0
1460 }-
1461-
1462 if (readOnly)
readOnlyDescription
TRUEnever evaluated
FALSEnever evaluated
0
1463 return;
never executed: return;
0
1464-
1465 QDate date = handleMouseEvent(event);-
1466 validDateClicked = false;-
1467 if (date == calendarModel->m_date && !style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick)) {
date == calendarModel->m_dateDescription
TRUEnever evaluated
FALSEnever evaluated
!style()->styl...OnSingleClick)Description
TRUEnever evaluated
FALSEnever evaluated
0
1468 emit editingFinished();-
1469 }
never executed: end of block
0
1470}
never executed: end of block
0
1471-
1472void QCalendarView::mousePressEvent(QMouseEvent *event)-
1473{-
1474 QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model());-
1475 if (!calendarModel) {
!calendarModelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1476 QTableView::mousePressEvent(event);-
1477 return;
never executed: return;
0
1478 }-
1479-
1480 if (readOnly)
readOnlyDescription
TRUEnever evaluated
FALSEnever evaluated
0
1481 return;
never executed: return;
0
1482-
1483 if (event->button() != Qt::LeftButton)
event->button(...Qt::LeftButtonDescription
TRUEnever evaluated
FALSEnever evaluated
0
1484 return;
never executed: return;
0
1485-
1486 QDate date = handleMouseEvent(event);-
1487 if (date.isValid()) {
date.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1488 validDateClicked = true;-
1489 int row = -1, col = -1;-
1490 static_cast<QCalendarModel *>(model())->cellForDate(date, &row, &col);-
1491 if (row != -1 && col != -1) {
row != -1Description
TRUEnever evaluated
FALSEnever evaluated
col != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1492 selectionModel()->setCurrentIndex(model()->index(row, col), QItemSelectionModel::NoUpdate);-
1493 }
never executed: end of block
0
1494 } else {
never executed: end of block
0
1495 validDateClicked = false;-
1496 event->ignore();-
1497 }
never executed: end of block
0
1498}-
1499-
1500void QCalendarView::mouseMoveEvent(QMouseEvent *event)-
1501{-
1502 QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model());-
1503 if (!calendarModel) {
!calendarModelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1504 QTableView::mouseMoveEvent(event);-
1505 return;
never executed: return;
0
1506 }-
1507-
1508 if (readOnly)
readOnlyDescription
TRUEnever evaluated
FALSEnever evaluated
0
1509 return;
never executed: return;
0
1510-
1511 if (validDateClicked) {
validDateClickedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1512 QDate date = handleMouseEvent(event);-
1513 if (date.isValid()) {
date.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1514 int row = -1, col = -1;-
1515 static_cast<QCalendarModel *>(model())->cellForDate(date, &row, &col);-
1516 if (row != -1 && col != -1) {
row != -1Description
TRUEnever evaluated
FALSEnever evaluated
col != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1517 selectionModel()->setCurrentIndex(model()->index(row, col), QItemSelectionModel::NoUpdate);-
1518 }
never executed: end of block
0
1519 }
never executed: end of block
0
1520 } else {
never executed: end of block
0
1521 event->ignore();-
1522 }
never executed: end of block
0
1523}-
1524-
1525void QCalendarView::mouseReleaseEvent(QMouseEvent *event)-
1526{-
1527 QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model());-
1528 if (!calendarModel) {
!calendarModelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1529 QTableView::mouseReleaseEvent(event);-
1530 return;
never executed: return;
0
1531 }-
1532-
1533 if (event->button() != Qt::LeftButton)
event->button(...Qt::LeftButtonDescription
TRUEnever evaluated
FALSEnever evaluated
0
1534 return;
never executed: return;
0
1535-
1536 if (readOnly)
readOnlyDescription
TRUEnever evaluated
FALSEnever evaluated
0
1537 return;
never executed: return;
0
1538-
1539 if (validDateClicked) {
validDateClickedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1540 QDate date = handleMouseEvent(event);-
1541 if (date.isValid()) {
date.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1542 emit changeDate(date, true);-
1543 emit clicked(date);-
1544 if (style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick))
style()->style...OnSingleClick)Description
TRUEnever evaluated
FALSEnever evaluated
0
1545 emit editingFinished();
never executed: editingFinished();
0
1546 }
never executed: end of block
0
1547 validDateClicked = false;-
1548 } else {
never executed: end of block
0
1549 event->ignore();-
1550 }
never executed: end of block
0
1551}-
1552-
1553class QCalendarDelegate : public QItemDelegate-
1554{-
1555 Q_OBJECT-
1556public:-
1557 QCalendarDelegate(QCalendarWidgetPrivate *w, QObject *parent = 0)-
1558 : QItemDelegate(parent), calendarWidgetPrivate(w)-
1559 { }
never executed: end of block
0
1560 virtual void paint(QPainter *painter, const QStyleOptionViewItem &option,-
1561 const QModelIndex &index) const Q_DECL_OVERRIDE;-
1562 void paintCell(QPainter *painter, const QRect &rect, const QDate &date) const;-
1563-
1564private:-
1565 QCalendarWidgetPrivate *calendarWidgetPrivate;-
1566 mutable QStyleOptionViewItem storedOption;-
1567};-
1568-
1569//Private tool button class-
1570class QCalToolButton: public QToolButton-
1571{-
1572public:-
1573 QCalToolButton(QWidget * parent)-
1574 : QToolButton(parent)-
1575 { }
never executed: end of block
0
1576protected:-
1577 void paintEvent(QPaintEvent *e) Q_DECL_OVERRIDE-
1578 {-
1579 Q_UNUSED(e)-
1580-
1581#ifndef Q_DEAD_CODE_FROM_QT4_MAC-
1582 QStyleOptionToolButton opt;-
1583 initStyleOption(&opt);-
1584-
1585 if (opt.state & QStyle::State_MouseOver || isDown()) {
opt.state & QS...tate_MouseOverDescription
TRUEnever evaluated
FALSEnever evaluated
isDown()Description
TRUEnever evaluated
FALSEnever evaluated
0
1586 //act as normal button-
1587 setPalette(QPalette());-
1588 } else {
never executed: end of block
0
1589 //set the highlight color for button text-
1590 QPalette toolPalette = palette();-
1591 toolPalette.setColor(QPalette::ButtonText, toolPalette.color(QPalette::HighlightedText));-
1592 setPalette(toolPalette);-
1593 }
never executed: end of block
0
1594#endif-
1595 QToolButton::paintEvent(e);-
1596 }
never executed: end of block
0
1597};-
1598-
1599class QPrevNextCalButton : public QToolButton-
1600{-
1601 Q_OBJECT-
1602public:-
1603 QPrevNextCalButton(QWidget *parent) : QToolButton(parent) {}
never executed: end of block
0
1604protected:-
1605 void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE {-
1606 QStylePainter painter(this);-
1607 QStyleOptionToolButton opt;-
1608 initStyleOption(&opt);-
1609 opt.state &= ~QStyle::State_HasFocus;-
1610 painter.drawComplexControl(QStyle::CC_ToolButton, opt);-
1611 }
never executed: end of block
0
1612};-
1613-
1614} // unnamed namespace-
1615-
1616class QCalendarWidgetPrivate : public QWidgetPrivate-
1617{-
1618 Q_DECLARE_PUBLIC(QCalendarWidget)-
1619public:-
1620 QCalendarWidgetPrivate();-
1621-
1622 void showMonth(int year, int month);-
1623 void update();-
1624 void paintCell(QPainter *painter, const QRect &rect, const QDate &date) const;-
1625-
1626 void _q_slotShowDate(const QDate &date);-
1627 void _q_slotChangeDate(const QDate &date);-
1628 void _q_slotChangeDate(const QDate &date, bool changeMonth);-
1629 void _q_editingFinished();-
1630 void _q_monthChanged(QAction*);-
1631 void _q_prevMonthClicked();-
1632 void _q_nextMonthClicked();-
1633 void _q_yearEditingFinished();-
1634 void _q_yearClicked();-
1635-
1636 void createNavigationBar(QWidget *widget);-
1637 void updateButtonIcons();-
1638 void updateMonthMenu();-
1639 void updateMonthMenuNames();-
1640 void updateNavigationBar();-
1641 void updateCurrentPage(const QDate &newDate);-
1642 inline QDate getCurrentDate();-
1643 void setNavigatorEnabled(bool enable);-
1644-
1645 QCalendarModel *m_model;-
1646 QCalendarView *m_view;-
1647 QCalendarDelegate *m_delegate;-
1648 QItemSelectionModel *m_selection;-
1649 QCalendarTextNavigator *m_navigator;-
1650 bool m_dateEditEnabled;-
1651-
1652 QToolButton *nextMonth;-
1653 QToolButton *prevMonth;-
1654 QCalToolButton *monthButton;-
1655 QMenu *monthMenu;-
1656 QMap<int, QAction *> monthToAction;-
1657 QCalToolButton *yearButton;-
1658 QSpinBox *yearEdit;-
1659 QWidget *navBarBackground;-
1660 QSpacerItem *spaceHolder;-
1661-
1662 bool navBarVisible;-
1663 mutable QSize cachedSizeHint;-
1664 Qt::FocusPolicy oldFocusPolicy;-
1665};-
1666-
1667void QCalendarDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,-
1668 const QModelIndex &index) const-
1669{-
1670 QDate date = calendarWidgetPrivate->m_model->dateForCell(index.row(), index.column());-
1671 if (date.isValid()) {
date.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1672 storedOption = option;-
1673 QRect rect = option.rect;-
1674 calendarWidgetPrivate->paintCell(painter, rect, date);-
1675 } else {
never executed: end of block
0
1676 QItemDelegate::paint(painter, option, index);-
1677 }
never executed: end of block
0
1678}-
1679-
1680void QCalendarDelegate::paintCell(QPainter *painter, const QRect &rect, const QDate &date) const-
1681{-
1682 storedOption.rect = rect;-
1683 int row = -1;-
1684 int col = -1;-
1685 calendarWidgetPrivate->m_model->cellForDate(date, &row, &col);-
1686 QModelIndex idx = calendarWidgetPrivate->m_model->index(row, col);-
1687 QItemDelegate::paint(painter, storedOption, idx);-
1688}
never executed: end of block
0
1689-
1690QCalendarWidgetPrivate::QCalendarWidgetPrivate()-
1691 : QWidgetPrivate()-
1692{-
1693 m_model = 0;-
1694 m_view = 0;-
1695 m_delegate = 0;-
1696 m_selection = 0;-
1697 m_navigator = 0;-
1698 m_dateEditEnabled = false;-
1699 navBarVisible = true;-
1700 oldFocusPolicy = Qt::StrongFocus;-
1701}
never executed: end of block
0
1702-
1703void QCalendarWidgetPrivate::setNavigatorEnabled(bool enable)-
1704{-
1705 Q_Q(QCalendarWidget);-
1706-
1707 bool navigatorEnabled = (m_navigator->widget() != 0);-
1708 if (enable == navigatorEnabled)
enable == navigatorEnabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
1709 return;
never executed: return;
0
1710-
1711 if (enable) {
enableDescription
TRUEnever evaluated
FALSEnever evaluated
0
1712 m_navigator->setWidget(q);-
1713 q->connect(m_navigator, SIGNAL(dateChanged(QDate)),-
1714 q, SLOT(_q_slotChangeDate(QDate)));-
1715 q->connect(m_navigator, SIGNAL(editingFinished()),-
1716 q, SLOT(_q_editingFinished()));-
1717 m_view->installEventFilter(m_navigator);-
1718 } else {
never executed: end of block
0
1719 m_navigator->setWidget(0);-
1720 q->disconnect(m_navigator, SIGNAL(dateChanged(QDate)),-
1721 q, SLOT(_q_slotChangeDate(QDate)));-
1722 q->disconnect(m_navigator, SIGNAL(editingFinished()),-
1723 q, SLOT(_q_editingFinished()));-
1724 m_view->removeEventFilter(m_navigator);-
1725 }
never executed: end of block
0
1726}-
1727-
1728void QCalendarWidgetPrivate::createNavigationBar(QWidget *widget)-
1729{-
1730 Q_Q(QCalendarWidget);-
1731 navBarBackground = new QWidget(widget);-
1732 navBarBackground->setObjectName(QLatin1String("qt_calendar_navigationbar"));-
1733 navBarBackground->setAutoFillBackground(true);-
1734 navBarBackground->setBackgroundRole(QPalette::Highlight);-
1735-
1736 prevMonth = new QPrevNextCalButton(navBarBackground);-
1737 nextMonth = new QPrevNextCalButton(navBarBackground);-
1738 prevMonth->setAutoRaise(true);-
1739 nextMonth->setAutoRaise(true);-
1740 prevMonth->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);-
1741 nextMonth->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);-
1742 nextMonth->setAutoRaise(true);-
1743 updateButtonIcons();-
1744 prevMonth->setAutoRepeat(true);-
1745 nextMonth->setAutoRepeat(true);-
1746-
1747 monthButton = new QCalToolButton(navBarBackground);-
1748 monthButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);-
1749 monthButton->setAutoRaise(true);-
1750 monthButton->setPopupMode(QToolButton::InstantPopup);-
1751 monthMenu = new QMenu(monthButton);-
1752 for (int i = 1; i <= 12; i++) {
i <= 12Description
TRUEnever evaluated
FALSEnever evaluated
0
1753 QString monthName(q->locale().standaloneMonthName(i, QLocale::LongFormat));-
1754 QAction *act = monthMenu->addAction(monthName);-
1755 act->setData(i);-
1756 monthToAction[i] = act;-
1757 }
never executed: end of block
0
1758 monthButton->setMenu(monthMenu);-
1759 yearButton = new QCalToolButton(navBarBackground);-
1760 yearButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);-
1761 yearButton->setAutoRaise(true);-
1762 yearEdit = new QSpinBox(navBarBackground);-
1763-
1764 QFont font = q->font();-
1765 font.setBold(true);-
1766 monthButton->setFont(font);-
1767 yearButton->setFont(font);-
1768 yearEdit->setFrame(false);-
1769 yearEdit->setMinimum(m_model->m_minimumDate.year());-
1770 yearEdit->setMaximum(m_model->m_maximumDate.year());-
1771 yearEdit->hide();-
1772 spaceHolder = new QSpacerItem(0,0);-
1773-
1774 QHBoxLayout *headerLayout = new QHBoxLayout;-
1775 headerLayout->setMargin(0);-
1776 headerLayout->setSpacing(0);-
1777 headerLayout->addWidget(prevMonth);-
1778 headerLayout->insertStretch(headerLayout->count());-
1779 headerLayout->addWidget(monthButton);-
1780 headerLayout->addItem(spaceHolder);-
1781 headerLayout->addWidget(yearButton);-
1782 headerLayout->insertStretch(headerLayout->count());-
1783 headerLayout->addWidget(nextMonth);-
1784 navBarBackground->setLayout(headerLayout);-
1785-
1786 yearEdit->setFocusPolicy(Qt::StrongFocus);-
1787 prevMonth->setFocusPolicy(Qt::NoFocus);-
1788 nextMonth->setFocusPolicy(Qt::NoFocus);-
1789 yearButton->setFocusPolicy(Qt::NoFocus);-
1790 monthButton->setFocusPolicy(Qt::NoFocus);-
1791-
1792 //set names for the header controls.-
1793 prevMonth->setObjectName(QLatin1String("qt_calendar_prevmonth"));-
1794 nextMonth->setObjectName(QLatin1String("qt_calendar_nextmonth"));-
1795 monthButton->setObjectName(QLatin1String("qt_calendar_monthbutton"));-
1796 yearButton->setObjectName(QLatin1String("qt_calendar_yearbutton"));-
1797 yearEdit->setObjectName(QLatin1String("qt_calendar_yearedit"));-
1798-
1799 updateMonthMenu();-
1800 showMonth(m_model->m_date.year(), m_model->m_date.month());-
1801}
never executed: end of block
0
1802-
1803void QCalendarWidgetPrivate::updateButtonIcons()-
1804{-
1805 Q_Q(QCalendarWidget);-
1806 prevMonth->setIcon(q->style()->standardIcon(q->isRightToLeft() ? QStyle::SP_ArrowRight : QStyle::SP_ArrowLeft, 0, q));-
1807 nextMonth->setIcon(q->style()->standardIcon(q->isRightToLeft() ? QStyle::SP_ArrowLeft : QStyle::SP_ArrowRight, 0, q));-
1808}
never executed: end of block
0
1809-
1810void QCalendarWidgetPrivate::updateMonthMenu()-
1811{-
1812 int beg = 1, end = 12;-
1813 bool prevEnabled = true;-
1814 bool nextEnabled = true;-
1815 if (m_model->m_shownYear == m_model->m_minimumDate.year()) {
m_model->m_sho...mumDate.year()Description
TRUEnever evaluated
FALSEnever evaluated
0
1816 beg = m_model->m_minimumDate.month();-
1817 if (m_model->m_shownMonth == m_model->m_minimumDate.month())
m_model->m_sho...umDate.month()Description
TRUEnever evaluated
FALSEnever evaluated
0
1818 prevEnabled = false;
never executed: prevEnabled = false;
0
1819 }
never executed: end of block
0
1820 if (m_model->m_shownYear == m_model->m_maximumDate.year()) {
m_model->m_sho...mumDate.year()Description
TRUEnever evaluated
FALSEnever evaluated
0
1821 end = m_model->m_maximumDate.month();-
1822 if (m_model->m_shownMonth == m_model->m_maximumDate.month())
m_model->m_sho...umDate.month()Description
TRUEnever evaluated
FALSEnever evaluated
0
1823 nextEnabled = false;
never executed: nextEnabled = false;
0
1824 }
never executed: end of block
0
1825 prevMonth->setEnabled(prevEnabled);-
1826 nextMonth->setEnabled(nextEnabled);-
1827 for (int i = 1; i <= 12; i++) {
i <= 12Description
TRUEnever evaluated
FALSEnever evaluated
0
1828 bool monthEnabled = true;-
1829 if (i < beg || i > end)
i < begDescription
TRUEnever evaluated
FALSEnever evaluated
i > endDescription
TRUEnever evaluated
FALSEnever evaluated
0
1830 monthEnabled = false;
never executed: monthEnabled = false;
0
1831 monthToAction[i]->setEnabled(monthEnabled);-
1832 }
never executed: end of block
0
1833}
never executed: end of block
0
1834-
1835void QCalendarWidgetPrivate::updateMonthMenuNames()-
1836{-
1837 Q_Q(QCalendarWidget);-
1838-
1839 for (int i = 1; i <= 12; i++) {
i <= 12Description
TRUEnever evaluated
FALSEnever evaluated
0
1840 QString monthName(q->locale().standaloneMonthName(i, QLocale::LongFormat));-
1841 monthToAction[i]->setText(monthName);-
1842 }
never executed: end of block
0
1843}
never executed: end of block
0
1844-
1845void QCalendarWidgetPrivate::updateCurrentPage(const QDate &date)-
1846{-
1847 Q_Q(QCalendarWidget);-
1848-
1849 QDate newDate = date;-
1850 QDate minDate = q->minimumDate();-
1851 QDate maxDate = q->maximumDate();-
1852 if (minDate.isValid()&& minDate.daysTo(newDate) < 0)
minDate.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
minDate.daysTo(newDate) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1853 newDate = minDate;
never executed: newDate = minDate;
0
1854 if (maxDate.isValid()&& maxDate.daysTo(newDate) > 0)
maxDate.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
maxDate.daysTo(newDate) > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1855 newDate = maxDate;
never executed: newDate = maxDate;
0
1856 showMonth(newDate.year(), newDate.month());-
1857 int row = -1, col = -1;-
1858 m_model->cellForDate(newDate, &row, &col);-
1859 if (row != -1 && col != -1)
row != -1Description
TRUEnever evaluated
FALSEnever evaluated
col != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1860 {-
1861 m_view->selectionModel()->setCurrentIndex(m_model->index(row, col),-
1862 QItemSelectionModel::NoUpdate);-
1863 }
never executed: end of block
0
1864}
never executed: end of block
0
1865-
1866void QCalendarWidgetPrivate::_q_monthChanged(QAction *act)-
1867{-
1868 monthButton->setText(act->text());-
1869 QDate currentDate = getCurrentDate();-
1870 QDate newDate = currentDate.addMonths(act->data().toInt()-currentDate.month());-
1871 updateCurrentPage(newDate);-
1872}
never executed: end of block
0
1873-
1874QDate QCalendarWidgetPrivate::getCurrentDate()-
1875{-
1876 QModelIndex index = m_view->currentIndex();-
1877 return m_model->dateForCell(index.row(), index.column());
never executed: return m_model->dateForCell(index.row(), index.column());
0
1878}-
1879-
1880void QCalendarWidgetPrivate::_q_prevMonthClicked()-
1881{-
1882 QDate currentDate = getCurrentDate().addMonths(-1);-
1883 updateCurrentPage(currentDate);-
1884}
never executed: end of block
0
1885-
1886void QCalendarWidgetPrivate::_q_nextMonthClicked()-
1887{-
1888 QDate currentDate = getCurrentDate().addMonths(1);-
1889 updateCurrentPage(currentDate);-
1890}
never executed: end of block
0
1891-
1892void QCalendarWidgetPrivate::_q_yearEditingFinished()-
1893{-
1894 Q_Q(QCalendarWidget);-
1895 yearButton->setText(yearEdit->text());-
1896 yearEdit->hide();-
1897 q->setFocusPolicy(oldFocusPolicy);-
1898 qApp->removeEventFilter(q);-
1899 spaceHolder->changeSize(0, 0);-
1900 yearButton->show();-
1901 QDate currentDate = getCurrentDate();-
1902 currentDate = currentDate.addYears(yearEdit->text().toInt() - currentDate.year());-
1903 updateCurrentPage(currentDate);-
1904}
never executed: end of block
0
1905-
1906void QCalendarWidgetPrivate::_q_yearClicked()-
1907{-
1908 Q_Q(QCalendarWidget);-
1909 //show the spinbox on top of the button-
1910 yearEdit->setGeometry(yearButton->x(), yearButton->y(),-
1911 yearEdit->sizeHint().width(), yearButton->height());-
1912 spaceHolder->changeSize(yearButton->width(), 0);-
1913 yearButton->hide();-
1914 oldFocusPolicy = q->focusPolicy();-
1915 q->setFocusPolicy(Qt::NoFocus);-
1916 yearEdit->show();-
1917 qApp->installEventFilter(q);-
1918 yearEdit->raise();-
1919 yearEdit->selectAll();-
1920 yearEdit->setFocus(Qt::MouseFocusReason);-
1921}
never executed: end of block
0
1922-
1923void QCalendarWidgetPrivate::showMonth(int year, int month)-
1924{-
1925 if (m_model->m_shownYear == year && m_model->m_shownMonth == month)
m_model->m_shownYear == yearDescription
TRUEnever evaluated
FALSEnever evaluated
m_model->m_shownMonth == monthDescription
TRUEnever evaluated
FALSEnever evaluated
0
1926 return;
never executed: return;
0
1927 Q_Q(QCalendarWidget);-
1928 m_model->showMonth(year, month);-
1929 updateNavigationBar();-
1930 emit q->currentPageChanged(year, month);-
1931 m_view->internalUpdate();-
1932 cachedSizeHint = QSize();-
1933 update();-
1934 updateMonthMenu();-
1935}
never executed: end of block
0
1936-
1937void QCalendarWidgetPrivate::updateNavigationBar()-
1938{-
1939 Q_Q(QCalendarWidget);-
1940-
1941 QString monthName = q->locale().standaloneMonthName(m_model->m_shownMonth, QLocale::LongFormat);-
1942-
1943 monthButton->setText(monthName);-
1944 yearButton->setText(QString::number(m_model->m_shownYear));-
1945 yearEdit->setValue(m_model->m_shownYear);-
1946}
never executed: end of block
0
1947-
1948void QCalendarWidgetPrivate::update()-
1949{-
1950 QDate currentDate = m_model->m_date;-
1951 int row, column;-
1952 m_model->cellForDate(currentDate, &row, &column);-
1953 QModelIndex idx;-
1954 m_selection->clear();-
1955 if (row != -1 && column != -1) {
row != -1Description
TRUEnever evaluated
FALSEnever evaluated
column != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1956 idx = m_model->index(row, column);-
1957 m_selection->setCurrentIndex(idx, QItemSelectionModel::SelectCurrent);-
1958 }
never executed: end of block
0
1959}
never executed: end of block
0
1960-
1961void QCalendarWidgetPrivate::paintCell(QPainter *painter, const QRect &rect, const QDate &date) const-
1962{-
1963 Q_Q(const QCalendarWidget);-
1964 q->paintCell(painter, rect, date);-
1965}
never executed: end of block
0
1966-
1967void QCalendarWidgetPrivate::_q_slotShowDate(const QDate &date)-
1968{-
1969 updateCurrentPage(date);-
1970}
never executed: end of block
0
1971-
1972void QCalendarWidgetPrivate::_q_slotChangeDate(const QDate &date)-
1973{-
1974 _q_slotChangeDate(date, true);-
1975}
never executed: end of block
0
1976-
1977void QCalendarWidgetPrivate::_q_slotChangeDate(const QDate &date, bool changeMonth)-
1978{-
1979 QDate oldDate = m_model->m_date;-
1980 m_model->setDate(date);-
1981 QDate newDate = m_model->m_date;-
1982 if (changeMonth)
changeMonthDescription
TRUEnever evaluated
FALSEnever evaluated
0
1983 showMonth(newDate.year(), newDate.month());
never executed: showMonth(newDate.year(), newDate.month());
0
1984 if (oldDate != newDate) {
oldDate != newDateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1985 update();-
1986 Q_Q(QCalendarWidget);-
1987 m_navigator->setDate(newDate);-
1988 emit q->selectionChanged();-
1989 }
never executed: end of block
0
1990}
never executed: end of block
0
1991-
1992void QCalendarWidgetPrivate::_q_editingFinished()-
1993{-
1994 Q_Q(QCalendarWidget);-
1995 emit q->activated(m_model->m_date);-
1996}
never executed: end of block
0
1997-
1998/*!-
1999 \class QCalendarWidget-
2000 \brief The QCalendarWidget class provides a monthly based-
2001 calendar widget allowing the user to select a date.-
2002 \since 4.2-
2003-
2004 \ingroup advanced-
2005 \inmodule QtWidgets-
2006-
2007 \image fusion-calendarwidget.png-
2008-
2009 The widget is initialized with the current month and year, but-
2010 QCalendarWidget provides several public slots to change the year-
2011 and month that is shown.-
2012-
2013 By default, today's date is selected, and the user can select a-
2014 date using both mouse and keyboard. The currently selected date-
2015 can be retrieved using the selectedDate() function. It is-
2016 possible to constrain the user selection to a given date range by-
2017 setting the minimumDate and maximumDate properties.-
2018 Alternatively, both properties can be set in one go using the-
2019 setDateRange() convenience slot. Set the \l selectionMode-
2020 property to NoSelection to prohibit the user from selecting at-
2021 all. Note that a date also can be selected programmatically using-
2022 the setSelectedDate() slot.-
2023-
2024 The currently displayed month and year can be retrieved using the-
2025 monthShown() and yearShown() functions, respectively.-
2026-
2027 A newly created calendar widget uses abbreviated day names, and-
2028 both Saturdays and Sundays are marked in red. The calendar grid is-
2029 not visible. The week numbers are displayed, and the first column-
2030 day is the first day of the week for the calendar's locale.-
2031-
2032 The notation of the days can be altered to a single letter-
2033 abbreviations ("M" for "Monday") by setting the-
2034 horizontalHeaderFormat property to-
2035 QCalendarWidget::SingleLetterDayNames. Setting the same property-
2036 to QCalendarWidget::LongDayNames makes the header display the-
2037 complete day names. The week numbers can be removed by setting-
2038 the verticalHeaderFormat property to-
2039 QCalendarWidget::NoVerticalHeader. The calendar grid can be-
2040 turned on by setting the gridVisible property to true using the-
2041 setGridVisible() function:-
2042-
2043 \table-
2044 \row \li-
2045 \image qcalendarwidget-grid.png-
2046 \row \li-
2047 \snippet code/src_gui_widgets_qcalendarwidget.cpp 0-
2048 \endtable-
2049-
2050 Finally, the day in the first column can be altered using the-
2051 setFirstDayOfWeek() function.-
2052-
2053 The QCalendarWidget class also provides three signals,-
2054 selectionChanged(), activated() and currentPageChanged() making it-
2055 possible to respond to user interaction.-
2056-
2057 The rendering of the headers, weekdays or single days can be-
2058 largely customized by setting QTextCharFormat's for some special-
2059 weekday, a special date or for the rendering of the headers.-
2060-
2061 Only a subset of the properties in QTextCharFormat are used by the-
2062 calendar widget. Currently, the foreground, background and font-
2063 properties are used to determine the rendering of individual cells-
2064 in the widget.-
2065-
2066 \sa QDate, QDateEdit, QTextCharFormat-
2067*/-
2068-
2069/*!-
2070 \enum QCalendarWidget::SelectionMode-
2071-
2072 This enum describes the types of selection offered to the user for-
2073 selecting dates in the calendar.-
2074-
2075 \value NoSelection Dates cannot be selected.-
2076 \value SingleSelection Single dates can be selected.-
2077-
2078 \sa selectionMode-
2079*/-
2080-
2081/*!-
2082 Constructs a calendar widget with the given \a parent.-
2083-
2084 The widget is initialized with the current month and year, and the-
2085 currently selected date is today.-
2086-
2087 \sa setCurrentPage()-
2088*/-
2089QCalendarWidget::QCalendarWidget(QWidget *parent)-
2090 : QWidget(*new QCalendarWidgetPrivate, parent, 0)-
2091{-
2092 Q_D(QCalendarWidget);-
2093-
2094 setAutoFillBackground(true);-
2095 setBackgroundRole(QPalette::Window);-
2096-
2097 QVBoxLayout *layoutV = new QVBoxLayout(this);-
2098 layoutV->setMargin(0);-
2099 d->m_model = new QCalendarModel(this);-
2100 QTextCharFormat fmt;-
2101 fmt.setForeground(QBrush(Qt::red));-
2102 d->m_model->m_dayFormats.insert(Qt::Saturday, fmt);-
2103 d->m_model->m_dayFormats.insert(Qt::Sunday, fmt);-
2104 d->m_view = new QCalendarView(this);-
2105 d->m_view->setObjectName(QLatin1String("qt_calendar_calendarview"));-
2106 d->m_view->setModel(d->m_model);-
2107 d->m_model->setView(d->m_view);-
2108 d->m_view->setSelectionBehavior(QAbstractItemView::SelectItems);-
2109 d->m_view->setSelectionMode(QAbstractItemView::SingleSelection);-
2110 d->m_view->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);-
2111 d->m_view->horizontalHeader()->setSectionsClickable(false);-
2112 d->m_view->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);-
2113 d->m_view->verticalHeader()->setSectionsClickable(false);-
2114 d->m_selection = d->m_view->selectionModel();-
2115 d->createNavigationBar(this);-
2116 d->m_view->setFrameStyle(QFrame::NoFrame);-
2117 d->m_delegate = new QCalendarDelegate(d, this);-
2118 d->m_view->setItemDelegate(d->m_delegate);-
2119 d->update();-
2120 d->updateNavigationBar();-
2121 setFocusPolicy(Qt::StrongFocus);-
2122 setFocusProxy(d->m_view);-
2123 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);-
2124-
2125 connect(d->m_view, SIGNAL(showDate(QDate)),-
2126 this, SLOT(_q_slotShowDate(QDate)));-
2127 connect(d->m_view, SIGNAL(changeDate(QDate,bool)),-
2128 this, SLOT(_q_slotChangeDate(QDate,bool)));-
2129 connect(d->m_view, SIGNAL(clicked(QDate)),-
2130 this, SIGNAL(clicked(QDate)));-
2131 connect(d->m_view, SIGNAL(editingFinished()),-
2132 this, SLOT(_q_editingFinished()));-
2133-
2134 connect(d->prevMonth, SIGNAL(clicked(bool)),-
2135 this, SLOT(_q_prevMonthClicked()));-
2136 connect(d->nextMonth, SIGNAL(clicked(bool)),-
2137 this, SLOT(_q_nextMonthClicked()));-
2138 connect(d->yearButton, SIGNAL(clicked(bool)),-
2139 this, SLOT(_q_yearClicked()));-
2140 connect(d->monthMenu, SIGNAL(triggered(QAction*)),-
2141 this, SLOT(_q_monthChanged(QAction*)));-
2142 connect(d->yearEdit, SIGNAL(editingFinished()),-
2143 this, SLOT(_q_yearEditingFinished()));-
2144-
2145 layoutV->setMargin(0);-
2146 layoutV->setSpacing(0);-
2147 layoutV->addWidget(d->navBarBackground);-
2148 layoutV->addWidget(d->m_view);-
2149-
2150 d->m_navigator = new QCalendarTextNavigator(this);-
2151 setDateEditEnabled(true);-
2152}
never executed: end of block
0
2153-
2154/*!-
2155 Destroys the calendar widget.-
2156*/-
2157QCalendarWidget::~QCalendarWidget()-
2158{-
2159}-
2160-
2161/*!-
2162 \reimp-
2163*/-
2164QSize QCalendarWidget::sizeHint() const-
2165{-
2166 return minimumSizeHint();
never executed: return minimumSizeHint();
0
2167}-
2168-
2169/*!-
2170 \reimp-
2171*/-
2172QSize QCalendarWidget::minimumSizeHint() const-
2173{-
2174 Q_D(const QCalendarWidget);-
2175 if (d->cachedSizeHint.isValid())
d->cachedSizeHint.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
2176 return d->cachedSizeHint;
never executed: return d->cachedSizeHint;
0
2177-
2178 ensurePolished();-
2179-
2180 int w = 0;-
2181 int h = 0;-
2182-
2183 int end = 53;-
2184 int rows = 7;-
2185 int cols = 8;-
2186-
2187 const int marginH = (style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1) * 2;-
2188-
2189 if (horizontalHeaderFormat() == QCalendarWidget::NoHorizontalHeader) {
horizontalHead...rizontalHeaderDescription
TRUEnever evaluated
FALSEnever evaluated
0
2190 rows = 6;-
2191 } else {
never executed: end of block
0
2192 for (int i = 1; i <= 7; i++) {
i <= 7Description
TRUEnever evaluated
FALSEnever evaluated
0
2193 QFontMetrics fm(d->m_model->formatForCell(0, i).font());-
2194 w = qMax(w, fm.width(d->m_model->dayName(d->m_model->dayOfWeekForColumn(i))) + marginH);-
2195 h = qMax(h, fm.height());-
2196 }
never executed: end of block
0
2197 }
never executed: end of block
0
2198-
2199 if (verticalHeaderFormat() == QCalendarWidget::NoVerticalHeader) {
verticalHeader...VerticalHeaderDescription
TRUEnever evaluated
FALSEnever evaluated
0
2200 cols = 7;-
2201 } else {
never executed: end of block
0
2202 for (int i = 1; i <= 6; i++) {
i <= 6Description
TRUEnever evaluated
FALSEnever evaluated
0
2203 QFontMetrics fm(d->m_model->formatForCell(i, 0).font());-
2204 for (int j = 1; j < end; j++)
j < endDescription
TRUEnever evaluated
FALSEnever evaluated
0
2205 w = qMax(w, fm.width(QString::number(j)) + marginH);
never executed: w = qMax(w, fm.width(QString::number(j)) + marginH);
0
2206 h = qMax(h, fm.height());-
2207 }
never executed: end of block
0
2208 }
never executed: end of block
0
2209-
2210 QFontMetrics fm(d->m_model->formatForCell(1, 1).font());-
2211 for (int i = 1; i <= end; i++) {
i <= endDescription
TRUEnever evaluated
FALSEnever evaluated
0
2212 w = qMax(w, fm.width(QString::number(i)) + marginH);-
2213 h = qMax(h, fm.height());-
2214 }
never executed: end of block
0
2215-
2216 if (d->m_view->showGrid()) {
d->m_view->showGrid()Description
TRUEnever evaluated
FALSEnever evaluated
0
2217 // hardcoded in tableview-
2218 w += 1;-
2219 h += 1;-
2220 }
never executed: end of block
0
2221-
2222 w += 1; // default column span-
2223-
2224 h = qMax(h, d->m_view->verticalHeader()->minimumSectionSize());-
2225 w = qMax(w, d->m_view->horizontalHeader()->minimumSectionSize());-
2226-
2227 //add the size of the header.-
2228 QSize headerSize(0, 0);-
2229 if (d->navBarVisible) {
d->navBarVisibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
2230 int headerH = d->navBarBackground->sizeHint().height();-
2231 int headerW = 0;-
2232-
2233 headerW += d->prevMonth->sizeHint().width();-
2234 headerW += d->nextMonth->sizeHint().width();-
2235-
2236 QFontMetrics fm = d->monthButton->fontMetrics();-
2237 int monthW = 0;-
2238 for (int i = 1; i < 12; i++) {
i < 12Description
TRUEnever evaluated
FALSEnever evaluated
0
2239 QString monthName = locale().standaloneMonthName(i, QLocale::LongFormat);-
2240 monthW = qMax(monthW, fm.boundingRect(monthName).width());-
2241 }
never executed: end of block
0
2242 const int buttonDecoMargin = d->monthButton->sizeHint().width() - fm.boundingRect(d->monthButton->text()).width();-
2243 headerW += monthW + buttonDecoMargin;-
2244-
2245 fm = d->yearButton->fontMetrics();-
2246 headerW += fm.boundingRect(QLatin1String("5555")).width() + buttonDecoMargin;-
2247-
2248 headerSize = QSize(headerW, headerH);-
2249 }
never executed: end of block
0
2250 w *= cols;-
2251 w = qMax(headerSize.width(), w);-
2252 h = (h * rows) + headerSize.height();-
2253 QMargins cm = contentsMargins();-
2254 w += cm.left() + cm.right();-
2255 h += cm.top() + cm.bottom();-
2256 d->cachedSizeHint = QSize(w, h);-
2257 return d->cachedSizeHint;
never executed: return d->cachedSizeHint;
0
2258}-
2259-
2260/*!-
2261 Paints the cell specified by the given \a date, using the given \a painter and \a rect.-
2262*/-
2263-
2264void QCalendarWidget::paintCell(QPainter *painter, const QRect &rect, const QDate &date) const-
2265{-
2266 Q_D(const QCalendarWidget);-
2267 d->m_delegate->paintCell(painter, rect, date);-
2268}
never executed: end of block
0
2269-
2270/*!-
2271 \property QCalendarWidget::selectedDate-
2272 \brief the currently selected date.-
2273-
2274 The selected date must be within the date range specified by the-
2275 minimumDate and maximumDate properties. By default, the selected-
2276 date is the current date.-
2277-
2278 \sa setDateRange()-
2279*/-
2280-
2281QDate QCalendarWidget::selectedDate() const-
2282{-
2283 Q_D(const QCalendarWidget);-
2284 return d->m_model->m_date;
never executed: return d->m_model->m_date;
0
2285}-
2286-
2287void QCalendarWidget::setSelectedDate(const QDate &date)-
2288{-
2289 Q_D(QCalendarWidget);-
2290 if (d->m_model->m_date == date && date == d->getCurrentDate())
d->m_model->m_date == dateDescription
TRUEnever evaluated
FALSEnever evaluated
date == d->getCurrentDate()Description
TRUEnever evaluated
FALSEnever evaluated
0
2291 return;
never executed: return;
0
2292-
2293 if (!date.isValid())
!date.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
2294 return;
never executed: return;
0
2295-
2296 d->m_model->setDate(date);-
2297 d->update();-
2298 QDate newDate = d->m_model->m_date;-
2299 d->showMonth(newDate.year(), newDate.month());-
2300 emit selectionChanged();-
2301}
never executed: end of block
0
2302-
2303/*!-
2304 Returns the year of the currently displayed month. Months are-
2305 numbered from 1 to 12.-
2306-
2307 \sa monthShown(), setCurrentPage()-
2308*/-
2309-
2310int QCalendarWidget::yearShown() const-
2311{-
2312 Q_D(const QCalendarWidget);-
2313 return d->m_model->m_shownYear;
never executed: return d->m_model->m_shownYear;
0
2314}-
2315-
2316/*!-
2317 Returns the currently displayed month. Months are numbered from 1 to-
2318 12.-
2319-
2320 \sa yearShown(), setCurrentPage()-
2321*/-
2322-
2323int QCalendarWidget::monthShown() const-
2324{-
2325 Q_D(const QCalendarWidget);-
2326 return d->m_model->m_shownMonth;
never executed: return d->m_model->m_shownMonth;
0
2327}-
2328-
2329/*!-
2330 Displays the given \a month of the given \a year without changing-
2331 the selected date. Use the setSelectedDate() function to alter the-
2332 selected date.-
2333-
2334 The currently displayed month and year can be retrieved using the-
2335 monthShown() and yearShown() functions respectively.-
2336-
2337 \sa yearShown(), monthShown(), showPreviousMonth(), showNextMonth(),-
2338 showPreviousYear(), showNextYear()-
2339*/-
2340-
2341void QCalendarWidget::setCurrentPage(int year, int month)-
2342{-
2343 Q_D(QCalendarWidget);-
2344 QDate currentDate = d->getCurrentDate();-
2345 int day = currentDate.day();-
2346 int daysInMonths = QDate(year, month, 1).daysInMonth();-
2347 if (day > daysInMonths)
day > daysInMonthsDescription
TRUEnever evaluated
FALSEnever evaluated
0
2348 day = daysInMonths;
never executed: day = daysInMonths;
0
2349-
2350 d->showMonth(year, month);-
2351-
2352 QDate newDate(year, month, day);-
2353 int row = -1, col = -1;-
2354 d->m_model->cellForDate(newDate, &row, &col);-
2355 if (row != -1 && col != -1) {
row != -1Description
TRUEnever evaluated
FALSEnever evaluated
col != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
2356 d->m_view->selectionModel()->setCurrentIndex(d->m_model->index(row, col),-
2357 QItemSelectionModel::NoUpdate);-
2358 }
never executed: end of block
0
2359}
never executed: end of block
0
2360-
2361/*!-
2362 Shows the next month relative to the currently displayed-
2363 month. Note that the selected date is not changed.-
2364-
2365 \sa showPreviousMonth(), setCurrentPage(), setSelectedDate()-
2366*/-
2367-
2368void QCalendarWidget::showNextMonth()-
2369{-
2370 int year = yearShown();-
2371 int month = monthShown();-
2372 if (month == 12) {
month == 12Description
TRUEnever evaluated
FALSEnever evaluated
0
2373 ++year;-
2374 month = 1;-
2375 } else {
never executed: end of block
0
2376 ++month;-
2377 }
never executed: end of block
0
2378 setCurrentPage(year, month);-
2379}
never executed: end of block
0
2380-
2381/*!-
2382 Shows the previous month relative to the currently displayed-
2383 month. Note that the selected date is not changed.-
2384-
2385 \sa showNextMonth(), setCurrentPage(), setSelectedDate()-
2386*/-
2387-
2388void QCalendarWidget::showPreviousMonth()-
2389{-
2390 int year = yearShown();-
2391 int month = monthShown();-
2392 if (month == 1) {
month == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
2393 --year;-
2394 month = 12;-
2395 } else {
never executed: end of block
0
2396 --month;-
2397 }
never executed: end of block
0
2398 setCurrentPage(year, month);-
2399}
never executed: end of block
0
2400-
2401/*!-
2402 Shows the currently displayed month in the \e next year relative-
2403 to the currently displayed year. Note that the selected date is-
2404 not changed.-
2405-
2406 \sa showPreviousYear(), setCurrentPage(), setSelectedDate()-
2407*/-
2408-
2409void QCalendarWidget::showNextYear()-
2410{-
2411 int year = yearShown();-
2412 int month = monthShown();-
2413 ++year;-
2414 setCurrentPage(year, month);-
2415}
never executed: end of block
0
2416-
2417/*!-
2418 Shows the currently displayed month in the \e previous year-
2419 relative to the currently displayed year. Note that the selected-
2420 date is not changed.-
2421-
2422 \sa showNextYear(), setCurrentPage(), setSelectedDate()-
2423*/-
2424-
2425void QCalendarWidget::showPreviousYear()-
2426{-
2427 int year = yearShown();-
2428 int month = monthShown();-
2429 --year;-
2430 setCurrentPage(year, month);-
2431}
never executed: end of block
0
2432-
2433/*!-
2434 Shows the month of the selected date.-
2435-
2436 \sa selectedDate(), setCurrentPage()-
2437*/-
2438void QCalendarWidget::showSelectedDate()-
2439{-
2440 QDate currentDate = selectedDate();-
2441 setCurrentPage(currentDate.year(), currentDate.month());-
2442}
never executed: end of block
0
2443-
2444/*!-
2445 Shows the month of the today's date.-
2446-
2447 \sa selectedDate(), setCurrentPage()-
2448*/-
2449void QCalendarWidget::showToday()-
2450{-
2451 QDate currentDate = QDate::currentDate();-
2452 setCurrentPage(currentDate.year(), currentDate.month());-
2453}
never executed: end of block
0
2454-
2455/*!-
2456 \property QCalendarWidget::minimumDate-
2457 \brief the minimum date of the currently specified date range.-
2458-
2459 The user will not be able to select a date that is before the-
2460 currently set minimum date.-
2461-
2462 \table-
2463 \row-
2464 \li \image qcalendarwidget-minimum.png-
2465 \row-
2466 \li-
2467 \snippet code/src_gui_widgets_qcalendarwidget.cpp 1-
2468 \endtable-
2469-
2470 By default, the minimum date is the earliest date that the QDate-
2471 class can handle.-
2472-
2473 When setting a minimum date, the maximumDate and selectedDate-
2474 properties are adjusted if the selection range becomes invalid. If-
2475 the provided date is not a valid QDate object, the-
2476 setMinimumDate() function does nothing.-
2477-
2478 \sa setDateRange()-
2479*/-
2480-
2481QDate QCalendarWidget::minimumDate() const-
2482{-
2483 Q_D(const QCalendarWidget);-
2484 return d->m_model->m_minimumDate;
never executed: return d->m_model->m_minimumDate;
0
2485}-
2486-
2487void QCalendarWidget::setMinimumDate(const QDate &date)-
2488{-
2489 Q_D(QCalendarWidget);-
2490 if (!date.isValid() || d->m_model->m_minimumDate == date)
!date.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
d->m_model->m_...umDate == dateDescription
TRUEnever evaluated
FALSEnever evaluated
0
2491 return;
never executed: return;
0
2492-
2493 QDate oldDate = d->m_model->m_date;-
2494 d->m_model->setMinimumDate(date);-
2495 d->yearEdit->setMinimum(d->m_model->m_minimumDate.year());-
2496 d->updateMonthMenu();-
2497 QDate newDate = d->m_model->m_date;-
2498 if (oldDate != newDate) {
oldDate != newDateDescription
TRUEnever evaluated
FALSEnever evaluated
0
2499 d->update();-
2500 d->showMonth(newDate.year(), newDate.month());-
2501 d->m_navigator->setDate(newDate);-
2502 emit selectionChanged();-
2503 }
never executed: end of block
0
2504}
never executed: end of block
0
2505-
2506/*!-
2507 \property QCalendarWidget::maximumDate-
2508 \brief the maximum date of the currently specified date range.-
2509-
2510 The user will not be able to select a date which is after the-
2511 currently set maximum date.-
2512-
2513 \table-
2514 \row-
2515 \li \image qcalendarwidget-maximum.png-
2516 \row-
2517 \li-
2518 \snippet code/src_gui_widgets_qcalendarwidget.cpp 2-
2519 \endtable-
2520-
2521 By default, the maximum date is the last day the QDate class can-
2522 handle.-
2523-
2524 When setting a maximum date, the minimumDate and selectedDate-
2525 properties are adjusted if the selection range becomes invalid. If-
2526 the provided date is not a valid QDate object, the-
2527 setMaximumDate() function does nothing.-
2528-
2529 \sa setDateRange()-
2530*/-
2531-
2532QDate QCalendarWidget::maximumDate() const-
2533{-
2534 Q_D(const QCalendarWidget);-
2535 return d->m_model->m_maximumDate;
never executed: return d->m_model->m_maximumDate;
0
2536}-
2537-
2538void QCalendarWidget::setMaximumDate(const QDate &date)-
2539{-
2540 Q_D(QCalendarWidget);-
2541 if (!date.isValid() || d->m_model->m_maximumDate == date)
!date.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
d->m_model->m_...umDate == dateDescription
TRUEnever evaluated
FALSEnever evaluated
0
2542 return;
never executed: return;
0
2543-
2544 QDate oldDate = d->m_model->m_date;-
2545 d->m_model->setMaximumDate(date);-
2546 d->yearEdit->setMaximum(d->m_model->m_maximumDate.year());-
2547 d->updateMonthMenu();-
2548 QDate newDate = d->m_model->m_date;-
2549 if (oldDate != newDate) {
oldDate != newDateDescription
TRUEnever evaluated
FALSEnever evaluated
0
2550 d->update();-
2551 d->showMonth(newDate.year(), newDate.month());-
2552 d->m_navigator->setDate(newDate);-
2553 emit selectionChanged();-
2554 }
never executed: end of block
0
2555}
never executed: end of block
0
2556-
2557/*!-
2558 Defines a date range by setting the minimumDate and maximumDate-
2559 properties.-
2560-
2561 The date range restricts the user selection, i.e. the user can-
2562 only select dates within the specified date range. Note that-
2563-
2564 \snippet code/src_gui_widgets_qcalendarwidget.cpp 3-
2565-
2566 is analogous to-
2567-
2568 \snippet code/src_gui_widgets_qcalendarwidget.cpp 4-
2569-
2570 If either the \a min or \a max parameters are not valid QDate-
2571 objects, this function does nothing.-
2572-
2573 \sa setMinimumDate(), setMaximumDate()-
2574*/-
2575-
2576void QCalendarWidget::setDateRange(const QDate &min, const QDate &max)-
2577{-
2578 Q_D(QCalendarWidget);-
2579 if (d->m_model->m_minimumDate == min && d->m_model->m_maximumDate == max)
d->m_model->m_...mumDate == minDescription
TRUEnever evaluated
FALSEnever evaluated
d->m_model->m_...mumDate == maxDescription
TRUEnever evaluated
FALSEnever evaluated
0
2580 return;
never executed: return;
0
2581 if (!min.isValid() || !max.isValid())
!min.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
!max.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
2582 return;
never executed: return;
0
2583-
2584 QDate oldDate = d->m_model->m_date;-
2585 d->m_model->setRange(min, max);-
2586 d->yearEdit->setMinimum(d->m_model->m_minimumDate.year());-
2587 d->yearEdit->setMaximum(d->m_model->m_maximumDate.year());-
2588 d->updateMonthMenu();-
2589 QDate newDate = d->m_model->m_date;-
2590 if (oldDate != newDate) {
oldDate != newDateDescription
TRUEnever evaluated
FALSEnever evaluated
0
2591 d->update();-
2592 d->showMonth(newDate.year(), newDate.month());-
2593 d->m_navigator->setDate(newDate);-
2594 emit selectionChanged();-
2595 }
never executed: end of block
0
2596}
never executed: end of block
0
2597-
2598-
2599/*! \enum QCalendarWidget::HorizontalHeaderFormat-
2600-
2601 This enum type defines the various formats the horizontal header can display.-
2602-
2603 \value SingleLetterDayNames The header displays a single letter abbreviation for day names (e.g. M for Monday).-
2604 \value ShortDayNames The header displays a short abbreviation for day names (e.g. Mon for Monday).-
2605 \value LongDayNames The header displays complete day names (e.g. Monday).-
2606 \value NoHorizontalHeader The header is hidden.-
2607-
2608 \sa horizontalHeaderFormat(), VerticalHeaderFormat-
2609*/-
2610-
2611/*!-
2612 \property QCalendarWidget::horizontalHeaderFormat-
2613 \brief the format of the horizontal header.-
2614-
2615 The default value is QCalendarWidget::ShortDayNames.-
2616*/-
2617-
2618void QCalendarWidget::setHorizontalHeaderFormat(QCalendarWidget::HorizontalHeaderFormat format)-
2619{-
2620 Q_D(QCalendarWidget);-
2621 if (d->m_model->m_horizontalHeaderFormat == format)
d->m_model->m_...rmat == formatDescription
TRUEnever evaluated
FALSEnever evaluated
0
2622 return;
never executed: return;
0
2623-
2624 d->m_model->setHorizontalHeaderFormat(format);-
2625 d->cachedSizeHint = QSize();-
2626 d->m_view->viewport()->update();-
2627 d->m_view->updateGeometry();-
2628}
never executed: end of block
0
2629-
2630QCalendarWidget::HorizontalHeaderFormat QCalendarWidget::horizontalHeaderFormat() const-
2631{-
2632 Q_D(const QCalendarWidget);-
2633 return d->m_model->m_horizontalHeaderFormat;
never executed: return d->m_model->m_horizontalHeaderFormat;
0
2634}-
2635-
2636-
2637/*!-
2638 \enum QCalendarWidget::VerticalHeaderFormat-
2639-
2640 This enum type defines the various formats the vertical header can display.-
2641-
2642 \value ISOWeekNumbers The header displays ISO week numbers as described by \l QDate::weekNumber().-
2643 \value NoVerticalHeader The header is hidden.-
2644-
2645 \sa verticalHeaderFormat(), HorizontalHeaderFormat-
2646*/-
2647-
2648/*!-
2649 \property QCalendarWidget::verticalHeaderFormat-
2650 \brief the format of the vertical header.-
2651-
2652 The default value is QCalendarWidget::ISOWeekNumber.-
2653*/-
2654-
2655QCalendarWidget::VerticalHeaderFormat QCalendarWidget::verticalHeaderFormat() const-
2656{-
2657 Q_D(const QCalendarWidget);-
2658 bool shown = d->m_model->weekNumbersShown();-
2659 if (shown)
shownDescription
TRUEnever evaluated
FALSEnever evaluated
0
2660 return QCalendarWidget::ISOWeekNumbers;
never executed: return QCalendarWidget::ISOWeekNumbers;
0
2661 return QCalendarWidget::NoVerticalHeader;
never executed: return QCalendarWidget::NoVerticalHeader;
0
2662}-
2663-
2664void QCalendarWidget::setVerticalHeaderFormat(QCalendarWidget::VerticalHeaderFormat format)-
2665{-
2666 Q_D(QCalendarWidget);-
2667 bool show = false;-
2668 if (format == QCalendarWidget::ISOWeekNumbers)
format == QCal...ISOWeekNumbersDescription
TRUEnever evaluated
FALSEnever evaluated
0
2669 show = true;
never executed: show = true;
0
2670 if (d->m_model->weekNumbersShown() == show)
d->m_model->we...hown() == showDescription
TRUEnever evaluated
FALSEnever evaluated
0
2671 return;
never executed: return;
0
2672 d->m_model->setWeekNumbersShown(show);-
2673 d->cachedSizeHint = QSize();-
2674 d->m_view->viewport()->update();-
2675 d->m_view->updateGeometry();-
2676}
never executed: end of block
0
2677-
2678/*!-
2679 \property QCalendarWidget::gridVisible-
2680 \brief whether the table grid is displayed.-
2681-
2682 \table-
2683 \row-
2684 \li \inlineimage qcalendarwidget-grid.png-
2685 \row-
2686 \li-
2687 \snippet code/src_gui_widgets_qcalendarwidget.cpp 5-
2688 \endtable-
2689-
2690 The default value is false.-
2691*/-
2692-
2693bool QCalendarWidget::isGridVisible() const-
2694{-
2695 Q_D(const QCalendarWidget);-
2696 return d->m_view->showGrid();
never executed: return d->m_view->showGrid();
0
2697}-
2698-
2699void QCalendarWidget::setGridVisible(bool show)-
2700{-
2701 Q_D(QCalendarWidget);-
2702 d->m_view->setShowGrid(show);-
2703 d->cachedSizeHint = QSize();-
2704 d->m_view->viewport()->update();-
2705 d->m_view->updateGeometry();-
2706}
never executed: end of block
0
2707-
2708/*!-
2709 \property QCalendarWidget::selectionMode-
2710 \brief the type of selection the user can make in the calendar-
2711-
2712 When this property is set to SingleSelection, the user can select a date-
2713 within the minimum and maximum allowed dates, using either the mouse or-
2714 the keyboard.-
2715-
2716 When the property is set to NoSelection, the user will be unable to select-
2717 dates, but they can still be selected programmatically. Note that the date-
2718 that is selected when the property is set to NoSelection will still be-
2719 the selected date of the calendar.-
2720-
2721 The default value is SingleSelection.-
2722*/-
2723-
2724QCalendarWidget::SelectionMode QCalendarWidget::selectionMode() const-
2725{-
2726 Q_D(const QCalendarWidget);-
2727 return d->m_view->readOnly ? QCalendarWidget::NoSelection : QCalendarWidget::SingleSelection;
never executed: return d->m_view->readOnly ? QCalendarWidget::NoSelection : QCalendarWidget::SingleSelection;
0
2728}-
2729-
2730void QCalendarWidget::setSelectionMode(SelectionMode mode)-
2731{-
2732 Q_D(QCalendarWidget);-
2733 d->m_view->readOnly = (mode == QCalendarWidget::NoSelection);-
2734 d->setNavigatorEnabled(isDateEditEnabled() && (selectionMode() != QCalendarWidget::NoSelection));-
2735 d->update();-
2736}
never executed: end of block
0
2737-
2738/*!-
2739 \property QCalendarWidget::firstDayOfWeek-
2740 \brief a value identifying the day displayed in the first column.-
2741-
2742 By default, the day displayed in the first column-
2743 is the first day of the week for the calendar's locale.-
2744*/-
2745-
2746void QCalendarWidget::setFirstDayOfWeek(Qt::DayOfWeek dayOfWeek)-
2747{-
2748 Q_D(QCalendarWidget);-
2749 if ((Qt::DayOfWeek)d->m_model->firstColumnDay() == dayOfWeek)
(Qt::DayOfWeek...) == dayOfWeekDescription
TRUEnever evaluated
FALSEnever evaluated
0
2750 return;
never executed: return;
0
2751-
2752 d->m_model->setFirstColumnDay(dayOfWeek);-
2753 d->update();-
2754}
never executed: end of block
0
2755-
2756Qt::DayOfWeek QCalendarWidget::firstDayOfWeek() const-
2757{-
2758 Q_D(const QCalendarWidget);-
2759 return (Qt::DayOfWeek)d->m_model->firstColumnDay();
never executed: return (Qt::DayOfWeek)d->m_model->firstColumnDay();
0
2760}-
2761-
2762/*!-
2763 Returns the text char format for rendering the header.-
2764*/-
2765QTextCharFormat QCalendarWidget::headerTextFormat() const-
2766{-
2767 Q_D(const QCalendarWidget);-
2768 return d->m_model->m_headerFormat;
never executed: return d->m_model->m_headerFormat;
0
2769}-
2770-
2771/*!-
2772 Sets the text char format for rendering the header to \a format.-
2773 If you also set a weekday text format, this format's foreground and-
2774 background color will take precedence over the header's format.-
2775 The other formatting information will still be decided by-
2776 the header's format.-
2777*/-
2778void QCalendarWidget::setHeaderTextFormat(const QTextCharFormat &format)-
2779{-
2780 Q_D(QCalendarWidget);-
2781 d->m_model->m_headerFormat = format;-
2782 d->cachedSizeHint = QSize();-
2783 d->m_view->viewport()->update();-
2784 d->m_view->updateGeometry();-
2785}
never executed: end of block
0
2786-
2787/*!-
2788 Returns the text char format for rendering of day in the week \a dayOfWeek.-
2789-
2790 \sa headerTextFormat()-
2791*/-
2792QTextCharFormat QCalendarWidget::weekdayTextFormat(Qt::DayOfWeek dayOfWeek) const-
2793{-
2794 Q_D(const QCalendarWidget);-
2795 return d->m_model->m_dayFormats.value(dayOfWeek);
never executed: return d->m_model->m_dayFormats.value(dayOfWeek);
0
2796}-
2797-
2798/*!-
2799 Sets the text char format for rendering of day in the week \a dayOfWeek to \a format.-
2800 The format will take precedence over the header format in case of foreground-
2801 and background color. Other text formatting information is taken from the headers format.-
2802-
2803 \sa setHeaderTextFormat()-
2804*/-
2805void QCalendarWidget::setWeekdayTextFormat(Qt::DayOfWeek dayOfWeek, const QTextCharFormat &format)-
2806{-
2807 Q_D(QCalendarWidget);-
2808 d->m_model->m_dayFormats[dayOfWeek] = format;-
2809 d->cachedSizeHint = QSize();-
2810 d->m_view->viewport()->update();-
2811 d->m_view->updateGeometry();-
2812}
never executed: end of block
0
2813-
2814/*!-
2815 Returns a QMap from QDate to QTextCharFormat showing all dates-
2816 that use a special format that alters their rendering.-
2817*/-
2818QMap<QDate, QTextCharFormat> QCalendarWidget::dateTextFormat() const-
2819{-
2820 Q_D(const QCalendarWidget);-
2821 return d->m_model->m_dateFormats;
never executed: return d->m_model->m_dateFormats;
0
2822}-
2823-
2824/*!-
2825 Returns a QTextCharFormat for \a date. The char format can be be-
2826 empty if the date is not renderd specially.-
2827*/-
2828QTextCharFormat QCalendarWidget::dateTextFormat(const QDate &date) const-
2829{-
2830 Q_D(const QCalendarWidget);-
2831 return d->m_model->m_dateFormats.value(date);
never executed: return d->m_model->m_dateFormats.value(date);
0
2832}-
2833-
2834/*!-
2835 Sets the format used to render the given \a date to that specified by \a format.-
2836-
2837 If \a date is null, all date formats are cleared.-
2838*/-
2839void QCalendarWidget::setDateTextFormat(const QDate &date, const QTextCharFormat &format)-
2840{-
2841 Q_D(QCalendarWidget);-
2842 if (date.isNull())
date.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
2843 d->m_model->m_dateFormats.clear();
never executed: d->m_model->m_dateFormats.clear();
0
2844 else-
2845 d->m_model->m_dateFormats[date] = format;
never executed: d->m_model->m_dateFormats[date] = format;
0
2846 d->m_view->viewport()->update();-
2847 d->m_view->updateGeometry();-
2848}
never executed: end of block
0
2849-
2850/*!-
2851 \property QCalendarWidget::dateEditEnabled-
2852 \brief whether the date edit popup is enabled-
2853 \since 4.3-
2854-
2855 If this property is enabled, pressing a non-modifier key will cause a-
2856 date edit to popup if the calendar widget has focus, allowing the user-
2857 to specify a date in the form specified by the current locale.-
2858-
2859 By default, this property is enabled.-
2860-
2861 The date edit is simpler in appearance than QDateEdit, but allows the-
2862 user to navigate between fields using the left and right cursor keys,-
2863 increment and decrement individual fields using the up and down cursor-
2864 keys, and enter values directly using the number keys.-
2865-
2866 \sa QCalendarWidget::dateEditAcceptDelay-
2867*/-
2868bool QCalendarWidget::isDateEditEnabled() const-
2869{-
2870 Q_D(const QCalendarWidget);-
2871 return d->m_dateEditEnabled;
never executed: return d->m_dateEditEnabled;
0
2872}-
2873-
2874void QCalendarWidget::setDateEditEnabled(bool enable)-
2875{-
2876 Q_D(QCalendarWidget);-
2877 if (isDateEditEnabled() == enable)
isDateEditEnabled() == enableDescription
TRUEnever evaluated
FALSEnever evaluated
0
2878 return;
never executed: return;
0
2879-
2880 d->m_dateEditEnabled = enable;-
2881-
2882 d->setNavigatorEnabled(enable && (selectionMode() != QCalendarWidget::NoSelection));-
2883}
never executed: end of block
0
2884-
2885/*!-
2886 \property QCalendarWidget::dateEditAcceptDelay-
2887 \brief the time an inactive date edit is shown before its contents are accepted-
2888 \since 4.3-
2889-
2890 If the calendar widget's \l{dateEditEnabled}{date edit is enabled}, this-
2891 property specifies the amount of time (in millseconds) that the date edit-
2892 remains open after the most recent user input. Once this time has elapsed,-
2893 the date specified in the date edit is accepted and the popup is closed.-
2894-
2895 By default, the delay is defined to be 1500 milliseconds (1.5 seconds).-
2896*/-
2897int QCalendarWidget::dateEditAcceptDelay() const-
2898{-
2899 Q_D(const QCalendarWidget);-
2900 return d->m_navigator->dateEditAcceptDelay();
never executed: return d->m_navigator->dateEditAcceptDelay();
0
2901}-
2902-
2903void QCalendarWidget::setDateEditAcceptDelay(int delay)-
2904{-
2905 Q_D(QCalendarWidget);-
2906 d->m_navigator->setDateEditAcceptDelay(delay);-
2907}
never executed: end of block
0
2908-
2909/*!-
2910 \since 4.4-
2911-
2912 Updates the cell specified by the given \a date unless updates-
2913 are disabled or the cell is hidden.-
2914-
2915 \sa updateCells(), yearShown(), monthShown()-
2916*/-
2917void QCalendarWidget::updateCell(const QDate &date)-
2918{-
2919 if (Q_UNLIKELY(!date.isValid())) {
__builtin_expe...lid()), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
2920 qWarning("QCalendarWidget::updateCell: Invalid date");-
2921 return;
never executed: return;
0
2922 }-
2923-
2924 if (!isVisible())
!isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
2925 return;
never executed: return;
0
2926-
2927 Q_D(QCalendarWidget);-
2928 int row, column;-
2929 d->m_model->cellForDate(date, &row, &column);-
2930 if (row == -1 || column == -1)
row == -1Description
TRUEnever evaluated
FALSEnever evaluated
column == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
2931 return;
never executed: return;
0
2932-
2933 QModelIndex modelIndex = d->m_model->index(row, column);-
2934 if (!modelIndex.isValid())
!modelIndex.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
2935 return;
never executed: return;
0
2936-
2937 d->m_view->viewport()->update(d->m_view->visualRect(modelIndex));-
2938}
never executed: end of block
0
2939-
2940/*!-
2941 \since 4.4-
2942-
2943 Updates all visible cells unless updates are disabled.-
2944-
2945 \sa updateCell()-
2946*/-
2947void QCalendarWidget::updateCells()-
2948{-
2949 Q_D(QCalendarWidget);-
2950 if (isVisible())
isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
2951 d->m_view->viewport()->update();
never executed: d->m_view->viewport()->update();
0
2952}
never executed: end of block
0
2953-
2954/*!-
2955 \fn void QCalendarWidget::selectionChanged()-
2956-
2957 This signal is emitted when the currently selected date is-
2958 changed.-
2959-
2960 The currently selected date can be changed by the user using the-
2961 mouse or keyboard, or by the programmer using setSelectedDate().-
2962-
2963 \sa selectedDate()-
2964*/-
2965-
2966/*!-
2967 \fn void QCalendarWidget::currentPageChanged(int year, int month)-
2968-
2969 This signal is emitted when the currently shown month is changed.-
2970 The new \a year and \a month are passed as parameters.-
2971-
2972 \sa setCurrentPage()-
2973*/-
2974-
2975/*!-
2976 \fn void QCalendarWidget::activated(const QDate &date)-
2977-
2978 This signal is emitted whenever the user presses the Return or-
2979 Enter key or double-clicks a \a date in the calendar-
2980 widget.-
2981*/-
2982-
2983/*!-
2984 \fn void QCalendarWidget::clicked(const QDate &date)-
2985-
2986 This signal is emitted when a mouse button is clicked. The date-
2987 the mouse was clicked on is specified by \a date. The signal is-
2988 only emitted when clicked on a valid date, e.g., dates are not-
2989 outside the minimumDate() and maximumDate(). If the selection mode-
2990 is NoSelection, this signal will not be emitted.-
2991-
2992*/-
2993-
2994/*!-
2995 \property QCalendarWidget::navigationBarVisible-
2996 \brief whether the navigation bar is shown or not-
2997-
2998 \since 4.3-
2999-
3000 When this property is \c true (the default), the next month,-
3001 previous month, month selection, year selection controls are-
3002 shown on top.-
3003-
3004 When the property is set to false, these controls are hidden.-
3005*/-
3006-
3007bool QCalendarWidget::isNavigationBarVisible() const-
3008{-
3009 Q_D(const QCalendarWidget);-
3010 return d->navBarVisible;
never executed: return d->navBarVisible;
0
3011}-
3012-
3013-
3014void QCalendarWidget::setNavigationBarVisible(bool visible)-
3015{-
3016 Q_D(QCalendarWidget);-
3017 d->navBarVisible = visible;-
3018 d->cachedSizeHint = QSize();-
3019 d->navBarBackground->setVisible(visible);-
3020 updateGeometry();-
3021}
never executed: end of block
0
3022-
3023/*!-
3024 \reimp-
3025*/-
3026bool QCalendarWidget::event(QEvent *event)-
3027{-
3028 Q_D(QCalendarWidget);-
3029 switch (event->type()) {-
3030 case QEvent::LayoutDirectionChange:
never executed: case QEvent::LayoutDirectionChange:
0
3031 d->updateButtonIcons();-
3032 break;
never executed: break;
0
3033 case QEvent::LocaleChange:
never executed: case QEvent::LocaleChange:
0
3034 d->m_model->setFirstColumnDay(locale().firstDayOfWeek());-
3035 d->cachedSizeHint = QSize();-
3036 d->updateMonthMenuNames();-
3037 d->updateNavigationBar();-
3038 d->m_view->updateGeometry();-
3039 break;
never executed: break;
0
3040 case QEvent::FontChange:
never executed: case QEvent::FontChange:
0
3041 case QEvent::ApplicationFontChange:
never executed: case QEvent::ApplicationFontChange:
0
3042 d->cachedSizeHint = QSize();-
3043 d->m_view->updateGeometry();-
3044 break;
never executed: break;
0
3045 case QEvent::StyleChange:
never executed: case QEvent::StyleChange:
0
3046 d->cachedSizeHint = QSize();-
3047 d->m_view->updateGeometry();-
3048 default:
code before this statement never executed: default:
never executed: default:
0
3049 break;
never executed: break;
0
3050 }-
3051 return QWidget::event(event);
never executed: return QWidget::event(event);
0
3052}-
3053-
3054/*!-
3055 \reimp-
3056*/-
3057bool QCalendarWidget::eventFilter(QObject *watched, QEvent *event)-
3058{-
3059 Q_D(QCalendarWidget);-
3060 if (event->type() == QEvent::MouseButtonPress && d->yearEdit->hasFocus()) {
event->type() ...useButtonPressDescription
TRUEnever evaluated
FALSEnever evaluated
d->yearEdit->hasFocus()Description
TRUEnever evaluated
FALSEnever evaluated
0
3061 QWidget *tlw = window();-
3062 QWidget *widget = static_cast<QWidget*>(watched);-
3063 //as we have a event filter on the whole application we first make sure that the top level widget-
3064 //of both this and the watched widget are the same to decide if we should finish the year edition.-
3065 if (widget->window() == tlw) {
widget->window() == tlwDescription
TRUEnever evaluated
FALSEnever evaluated
0
3066 QPoint mousePos = widget->mapTo(tlw, static_cast<QMouseEvent *>(event)->pos());-
3067 QRect geom = QRect(d->yearEdit->mapTo(tlw, QPoint(0, 0)), d->yearEdit->size());-
3068 if (!geom.contains(mousePos)) {
!geom.contains(mousePos)Description
TRUEnever evaluated
FALSEnever evaluated
0
3069 event->accept();-
3070 d->_q_yearEditingFinished();-
3071 setFocus();-
3072 return true;
never executed: return true;
0
3073 }-
3074 }
never executed: end of block
0
3075 }
never executed: end of block
0
3076 return QWidget::eventFilter(watched, event);
never executed: return QWidget::eventFilter(watched, event);
0
3077}-
3078-
3079/*!-
3080 \reimp-
3081*/-
3082void QCalendarWidget::mousePressEvent(QMouseEvent *event)-
3083{-
3084 setAttribute(Qt::WA_NoMouseReplay);-
3085 QWidget::mousePressEvent(event);-
3086 setFocus();-
3087}
never executed: end of block
0
3088-
3089/*!-
3090 \reimp-
3091*/-
3092void QCalendarWidget::resizeEvent(QResizeEvent * event)-
3093{-
3094 Q_D(QCalendarWidget);-
3095-
3096 // XXX Should really use a QWidgetStack for yearEdit and yearButton,-
3097 // XXX here we hide the year edit when the layout is likely to break-
3098 // XXX the manual positioning of the yearEdit over the yearButton.-
3099 if(d->yearEdit->isVisible() && event->size().width() != event->oldSize().width())
d->yearEdit->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
event->size()....Size().width()Description
TRUEnever evaluated
FALSEnever evaluated
0
3100 d->_q_yearEditingFinished();
never executed: d->_q_yearEditingFinished();
0
3101-
3102 QWidget::resizeEvent(event);-
3103}
never executed: end of block
0
3104-
3105/*!-
3106 \reimp-
3107*/-
3108void QCalendarWidget::keyPressEvent(QKeyEvent * event)-
3109{-
3110 Q_D(QCalendarWidget);-
3111 if (d->yearEdit->isVisible()&& event->matches(QKeySequence::Cancel)) {
d->yearEdit->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
event->matches...uence::Cancel)Description
TRUEnever evaluated
FALSEnever evaluated
0
3112 d->yearEdit->setValue(yearShown());-
3113 d->_q_yearEditingFinished();-
3114 return;
never executed: return;
0
3115 }-
3116 QWidget::keyPressEvent(event);-
3117}
never executed: end of block
0
3118-
3119QT_END_NAMESPACE-
3120-
3121#include "qcalendarwidget.moc"-
3122#include "moc_qcalendarwidget.cpp"-
3123-
3124#endif //QT_NO_CALENDARWIDGET-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9