diff options
author | Benjamin Poulain <benjamin.poulain@nokia.com> | 2009-05-18 12:39:14 (GMT) |
---|---|---|
committer | Benjamin Poulain <benjamin.poulain@nokia.com> | 2009-05-18 12:42:03 (GMT) |
commit | 6c16cb557205c8cf33bcf0493b3d9436c6f43236 (patch) | |
tree | a9e6aed7d44727c660a626e69176d3cb8ed792cf | |
parent | 0ff3bb25df3626a8112def75fc3ff048c70ebdb2 (diff) | |
download | Qt-6c16cb557205c8cf33bcf0493b3d9436c6f43236.zip Qt-6c16cb557205c8cf33bcf0493b3d9436c6f43236.tar.gz Qt-6c16cb557205c8cf33bcf0493b3d9436c6f43236.tar.bz2 |
QCalendarWidget::setDateTextFormat() reset the format is the date is invalid
According to the documentation, QCalendarWidget::setDateTextFormat() should
reset the format if the date is not valid.
New tests included for the formating of this widget.
Task-number: 252943
Reviewed-by: Olivier
-rw-r--r-- | src/gui/widgets/qcalendarwidget.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qcalendarwidget/tst_qcalendarwidget.cpp | 53 |
2 files changed, 54 insertions, 1 deletions
diff --git a/src/gui/widgets/qcalendarwidget.cpp b/src/gui/widgets/qcalendarwidget.cpp index 92c12a5..4436c04 100644 --- a/src/gui/widgets/qcalendarwidget.cpp +++ b/src/gui/widgets/qcalendarwidget.cpp @@ -2791,7 +2791,7 @@ QTextCharFormat QCalendarWidget::dateTextFormat(const QDate &date) const void QCalendarWidget::setDateTextFormat(const QDate &date, const QTextCharFormat &format) { Q_D(QCalendarWidget); - if ( date.isNull() && !format.isValid() ) + if (date.isNull()) d->m_model->m_dateFormats.clear(); else d->m_model->m_dateFormats[date] = format; diff --git a/tests/auto/qcalendarwidget/tst_qcalendarwidget.cpp b/tests/auto/qcalendarwidget/tst_qcalendarwidget.cpp index 67a822f..617832b 100644 --- a/tests/auto/qcalendarwidget/tst_qcalendarwidget.cpp +++ b/tests/auto/qcalendarwidget/tst_qcalendarwidget.cpp @@ -47,6 +47,8 @@ #include <qspinbox.h> #include <qmenu.h> #include <qdebug.h> +#include <qdatetime.h> +#include <qtextformat.h> //TESTED_CLASS= @@ -68,6 +70,11 @@ public slots: private slots: void getSetCheck(); void buttonClickCheck(); + + void setTextFormat(); + void resetTextFormat(); + + void setWeekdayFormat(); }; // Testing get/set functions @@ -215,6 +222,52 @@ void tst_QCalendarWidget::buttonClickCheck() } +void tst_QCalendarWidget::setTextFormat() +{ + QCalendarWidget calendar; + QTextCharFormat format; + format.setFontItalic(true); + format.setForeground(Qt::green); + + const QDate date(1984, 10, 20); + calendar.setDateTextFormat(date, format); + QCOMPARE(calendar.dateTextFormat(date), format); +} + +void tst_QCalendarWidget::resetTextFormat() +{ + QCalendarWidget calendar; + QTextCharFormat format; + format.setFontItalic(true); + format.setForeground(Qt::green); + + const QDate date(1984, 10, 20); + calendar.setDateTextFormat(date, format); + + calendar.setDateTextFormat(QDate(), QTextCharFormat()); + QCOMPARE(calendar.dateTextFormat(date), QTextCharFormat()); +} + +void tst_QCalendarWidget::setWeekdayFormat() +{ + QCalendarWidget calendar; + + QTextCharFormat format; + format.setFontItalic(true); + format.setForeground(Qt::green); + + calendar.setWeekdayTextFormat(Qt::Wednesday, format); + + // check the format of the a given month + for (int i = 1; i <= 31; ++i) { + const QDate date(1984, 10, i); + const Qt::DayOfWeek dayOfWeek = static_cast<Qt::DayOfWeek>(date.dayOfWeek()); + if (dayOfWeek == Qt::Wednesday) + QCOMPARE(calendar.weekdayTextFormat(dayOfWeek), format); + else + QVERIFY(calendar.weekdayTextFormat(dayOfWeek) != format); + } +} tst_QCalendarWidget::tst_QCalendarWidget() { |