aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/imports/calendar/qquickcalendarview.cpp19
-rw-r--r--src/imports/calendar/qquickmonthmodel.cpp2
-rw-r--r--src/imports/calendar/qquickweeknumbercolumn.cpp19
-rw-r--r--src/imports/calendar/qquickweeknumbermodel.cpp32
-rw-r--r--tests/auto/calendar/data/tst_calendarview.qml122
-rw-r--r--tests/auto/calendar/data/tst_weeknumbercolumn.qml56
-rw-r--r--tests/auto/snippets/data/calendarview/qtlabscalendar-calendarview-layout.qml2
-rw-r--r--tests/auto/snippets/data/calendarview/qtlabscalendar-calendarview.qml2
-rw-r--r--tests/auto/snippets/data/dayofweekrow/qtlabscalendar-dayofweekrow-layout.qml2
-rw-r--r--tests/auto/snippets/data/weeknumbercolumn/qtlabscalendar-weeknumbercolumn-layout.qml6
-rw-r--r--tests/auto/snippets/data/weeknumbercolumn/qtlabscalendar-weeknumbercolumn.qml2
11 files changed, 235 insertions, 29 deletions
diff --git a/src/imports/calendar/qquickcalendarview.cpp b/src/imports/calendar/qquickcalendarview.cpp
index 705ec8f7..7c7c54e9 100644
--- a/src/imports/calendar/qquickcalendarview.cpp
+++ b/src/imports/calendar/qquickcalendarview.cpp
@@ -40,6 +40,7 @@
#include <QtGui/qstylehints.h>
#include <QtGui/qguiapplication.h>
#include <QtLabsTemplates/private/qquickcontrol_p_p.h>
+#include <QtQml/qqmlinfo.h>
QT_BEGIN_NAMESPACE
@@ -180,23 +181,33 @@ QQuickCalendarView::QQuickCalendarView(QQuickItem *parent) :
\qmlproperty int Qt.labs.calendar::CalendarView::month
This property holds the number of the month.
+
+ The value must be in the range from \c 0 (January) to \c 11 (December). The default
+ value is the current month.
*/
int QQuickCalendarView::month() const
{
Q_D(const QQuickCalendarView);
- return d->model->month();
+ return d->model->month() - 1;
}
void QQuickCalendarView::setMonth(int month)
{
Q_D(QQuickCalendarView);
- d->model->setMonth(month);
+ if (month < 0 || month > 11) {
+ qmlInfo(this) << "month " << month << " is out of range [0...11]";
+ return;
+ }
+ d->model->setMonth(month + 1);
}
/*!
\qmlproperty int Qt.labs.calendar::CalendarView::year
This property holds the number of the year.
+
+ The value must be in the range from \c -271820 to \c 275759. The default
+ value is the current year.
*/
int QQuickCalendarView::year() const
{
@@ -207,6 +218,10 @@ int QQuickCalendarView::year() const
void QQuickCalendarView::setYear(int year)
{
Q_D(QQuickCalendarView);
+ if (year < -271820 || year > 275759) {
+ qmlInfo(this) << "year " << year << " is out of range [-271820...275759]";
+ return;
+ }
d->model->setYear(year);
}
diff --git a/src/imports/calendar/qquickmonthmodel.cpp b/src/imports/calendar/qquickmonthmodel.cpp
index 7188bc00..cdf5656d 100644
--- a/src/imports/calendar/qquickmonthmodel.cpp
+++ b/src/imports/calendar/qquickmonthmodel.cpp
@@ -194,7 +194,7 @@ QVariant QQuickMonthModel::data(const QModelIndex &index, int role) const
case WeekNumberRole:
return date.weekNumber();
case MonthRole:
- return date.month();
+ return date.month() - 1;
case YearRole:
return date.year();
default:
diff --git a/src/imports/calendar/qquickweeknumbercolumn.cpp b/src/imports/calendar/qquickweeknumbercolumn.cpp
index 21540607..34e4bd52 100644
--- a/src/imports/calendar/qquickweeknumbercolumn.cpp
+++ b/src/imports/calendar/qquickweeknumbercolumn.cpp
@@ -38,6 +38,7 @@
#include "qquickweeknumbermodel_p.h"
#include <QtLabsTemplates/private/qquickcontrol_p_p.h>
+#include <QtQml/qqmlinfo.h>
QT_BEGIN_NAMESPACE
@@ -108,23 +109,33 @@ QQuickWeekNumberColumn::QQuickWeekNumberColumn(QQuickItem *parent) :
\qmlproperty int Qt.labs.calendar::WeekNumberColumn::month
This property holds the number of the month that the week numbers are calculated for.
+
+ The value must be in the range from \c 0 (January) to \c 11 (December). The default
+ value is the current month.
*/
int QQuickWeekNumberColumn::month() const
{
Q_D(const QQuickWeekNumberColumn);
- return d->model->month();
+ return d->model->month() - 1;
}
void QQuickWeekNumberColumn::setMonth(int month)
{
Q_D(QQuickWeekNumberColumn);
- d->model->setMonth(month);
+ if (month < 0 || month > 11) {
+ qmlInfo(this) << "month " << month << " is out of range [0...11]";
+ return;
+ }
+ d->model->setMonth(month + 1);
}
/*!
\qmlproperty int Qt.labs.calendar::WeekNumberColumn::year
This property holds the number of the year that the week numbers are calculated for.
+
+ The value must be in the range from \c -271820 to \c 275759. The default
+ value is the current year.
*/
int QQuickWeekNumberColumn::year() const
{
@@ -135,6 +146,10 @@ int QQuickWeekNumberColumn::year() const
void QQuickWeekNumberColumn::setYear(int year)
{
Q_D(QQuickWeekNumberColumn);
+ if (year < -271820 || year > 275759) {
+ qmlInfo(this) << "year " << year << " is out of range [-271820...275759]";
+ return;
+ }
d->model->setYear(year);
}
diff --git a/src/imports/calendar/qquickweeknumbermodel.cpp b/src/imports/calendar/qquickweeknumbermodel.cpp
index f6a0b014..4ff6674d 100644
--- a/src/imports/calendar/qquickweeknumbermodel.cpp
+++ b/src/imports/calendar/qquickweeknumbermodel.cpp
@@ -46,21 +46,21 @@ class QQuickWeekNumberModelPrivate : public QAbstractItemModelPrivate
Q_DECLARE_PUBLIC(QQuickWeekNumberModel)
public:
- QQuickWeekNumberModelPrivate()
+ QQuickWeekNumberModelPrivate() : month(-1), year(-1)
{
QDate date = QDate::currentDate();
+ init(date.month(), date.year(), locale);
month = date.month();
year = date.year();
- first = calculateFirst(month, year, locale);
}
void init(int month, int year, const QLocale &locale = QLocale());
- static int calculateFirst(int month, int year, const QLocale &locale);
+ static QDate calculateFirst(int month, int year, const QLocale &locale);
int month;
int year;
- int first;
QLocale locale;
+ int weekNumbers[6];
};
void QQuickWeekNumberModelPrivate::init(int m, int y, const QLocale &l)
@@ -69,21 +69,19 @@ void QQuickWeekNumberModelPrivate::init(int m, int y, const QLocale &l)
if (m == month && y == year && l.firstDayOfWeek() == locale.firstDayOfWeek())
return;
- first = calculateFirst(m, y, l);
-
- emit q->dataChanged(q->index(0, 0), q->index(5, 0));
-}
-
-int QQuickWeekNumberModelPrivate::calculateFirst(int month, int year, const QLocale &locale)
-{
// The actual first (1st) day of the month.
- QDate firstDayOfMonthDate(year, month, 1);
- int difference = ((firstDayOfMonthDate.dayOfWeek() - locale.firstDayOfWeek()) + 7) % 7;
+ QDate firstDayOfMonthDate(y, m, 1);
+ int difference = ((firstDayOfMonthDate.dayOfWeek() - l.firstDayOfWeek()) + 7) % 7;
// The first day to display should never be the 1st of the month, as we want some days from
// the previous month to be visible.
if (difference == 0)
difference += 7;
- return firstDayOfMonthDate.addDays(-difference).weekNumber();
+
+ for (int i = 0; i < 6; ++i)
+ weekNumbers[i] = firstDayOfMonthDate.addDays(i * 7 - difference).weekNumber();
+
+ if (q) // null at construction
+ emit q->dataChanged(q->index(0, 0), q->index(5, 0));
}
QQuickWeekNumberModel::QQuickWeekNumberModel(QObject *parent) :
@@ -144,15 +142,15 @@ int QQuickWeekNumberModel::weekNumberAt(int index) const
Q_D(const QQuickWeekNumberModel);
if (index < 0 || index > 5)
return -1;
- return d->first + index;
+ return d->weekNumbers[index];
}
int QQuickWeekNumberModel::indexOf(int weekNumber) const
{
Q_D(const QQuickWeekNumberModel);
- if (weekNumber < d->first || weekNumber > d->first + 6)
+ if (weekNumber < d->weekNumbers[0] || weekNumber > d->weekNumbers[5])
return -1;
- return weekNumber - d->first;
+ return weekNumber - d->weekNumbers[0];
}
QVariant QQuickWeekNumberModel::data(const QModelIndex &index, int role) const
diff --git a/tests/auto/calendar/data/tst_calendarview.qml b/tests/auto/calendar/data/tst_calendarview.qml
index ef1e4380..8bb702c5 100644
--- a/tests/auto/calendar/data/tst_calendarview.qml
+++ b/tests/auto/calendar/data/tst_calendarview.qml
@@ -55,6 +55,128 @@ TestCase {
CalendarView { }
}
+ function test_locale() {
+ var control = component.createObject(testCase, {month: 0, year: 2013})
+
+ compare(control.contentItem.children.length, 6 * 7 + 1)
+
+ // January 2013
+ compare(control.month, 0)
+ compare(control.year, 2013)
+
+ // en_GB
+ control.locale = Qt.locale("en_GB")
+ compare(control.locale.name, "en_GB")
+
+ // M T W T F S S
+ var en_GB = [31, 1, 2, 3, 4, 5, 6,
+ 7, 8, 9, 10, 11, 12, 13,
+ 14, 15, 16, 17, 18, 19, 20,
+ 21, 22, 23, 24, 25, 26, 27,
+ 28, 29, 30, 31, 1, 2, 3,
+ 4, 5, 6, 7, 8, 9, 10]
+
+ for (var i = 0; i < 42; ++i)
+ compare(control.contentItem.children[i].text, en_GB[i].toString())
+
+ // en_US
+ control.locale = Qt.locale("en_US")
+ compare(control.locale.name, "en_US")
+
+ // S M T W T F S
+ var en_US = [30, 31, 1, 2, 3, 4, 5,
+ 6, 7, 8, 9, 10, 11, 12,
+ 13, 14, 15, 16, 17, 18, 19,
+ 20, 21, 22, 23, 24, 25, 26,
+ 27, 28, 29, 30, 31, 1, 2,
+ 3, 4, 5, 6, 7, 8, 9]
+
+ for (var j = 0; j < 42; ++j)
+ compare(control.contentItem.children[j].text, en_US[j].toString())
+
+ control.destroy()
+ }
+
+ function test_range() {
+ var control = component.createObject(testCase)
+
+ control.month = 0
+ compare(control.month, 0)
+
+ ignoreWarning(Qt.resolvedUrl("tst_calendarview.qml") + ":55:9: QML AbstractCalendarView: month -1 is out of range [0...11]")
+ control.month = -1
+ compare(control.month, 0)
+
+ control.month = 11
+ compare(control.month, 11)
+
+ ignoreWarning(Qt.resolvedUrl("tst_calendarview.qml") + ":55:9: QML AbstractCalendarView: month 12 is out of range [0...11]")
+ control.month = 12
+ compare(control.month, 11)
+
+ control.year = -271820
+ compare(control.year, -271820)
+
+ ignoreWarning(Qt.resolvedUrl("tst_calendarview.qml") + ":55:9: QML AbstractCalendarView: year -271821 is out of range [-271820...275759]")
+ control.year = -271821
+ compare(control.year, -271820)
+
+ control.year = 275759
+ compare(control.year, 275759)
+
+ ignoreWarning(Qt.resolvedUrl("tst_calendarview.qml") + ":55:9: QML AbstractCalendarView: year 275760 is out of range [-271820...275759]")
+ control.year = 275760
+ compare(control.year, 275759)
+
+ control.destroy()
+ }
+
+ function test_bce() {
+ var control = component.createObject(testCase)
+
+ compare(control.contentItem.children.length, 6 * 7 + 1)
+
+ // fi_FI
+ control.locale = Qt.locale("fi_FI")
+ compare(control.locale.name, "fi_FI")
+
+ // January 1 BCE
+ control.month = 0
+ compare(control.month, 0)
+ control.year = -1
+ compare(control.year, -1)
+
+ // M T W T F S S
+ var jan1bce = [27, 28, 29, 30, 31, 1, 2,
+ 3, 4, 5, 6, 7, 8, 9,
+ 10, 11, 12, 13, 14, 15, 16,
+ 17, 18, 19, 20, 21, 22, 23,
+ 24, 25, 26, 27, 28, 29, 30,
+ 31, 1, 2, 3, 4, 5, 6]
+
+ for (var i = 0; i < 42; ++i)
+ compare(control.contentItem.children[i].text, jan1bce[i].toString())
+
+ // February 1 BCE
+ control.month = 1
+ compare(control.month, 1)
+ control.year = -1
+ compare(control.year, -1)
+
+ // M T W T F S S
+ var feb1bce = [31, 1, 2, 3, 4, 5, 6,
+ 7, 8, 9, 10, 11, 12, 13,
+ 14, 15, 16, 17, 18, 19, 20,
+ 21, 22, 23, 24, 25, 26, 27,
+ 28, 29, 1, 2, 3, 4, 5,
+ 6, 7, 8, 9, 10, 11, 12]
+
+ for (var j = 0; j < 42; ++j)
+ compare(control.contentItem.children[j].text, feb1bce[j].toString())
+
+ control.destroy()
+ }
+
function test_font() {
var control = component.createObject(testCase)
diff --git a/tests/auto/calendar/data/tst_weeknumbercolumn.qml b/tests/auto/calendar/data/tst_weeknumbercolumn.qml
index f0c84bc0..a163123d 100644
--- a/tests/auto/calendar/data/tst_weeknumbercolumn.qml
+++ b/tests/auto/calendar/data/tst_weeknumbercolumn.qml
@@ -55,6 +55,62 @@ TestCase {
WeekNumberColumn { }
}
+ function test_locale() {
+ var control = component.createObject(testCase)
+
+ compare(control.contentItem.children.length, 6 + 1)
+
+ control.month = 11
+ control.year = 2015
+
+ // en_US: [48...53]
+ control.locale = Qt.locale("en_US")
+ for (var i = 0; i < 6; ++i)
+ compare(control.contentItem.children[i].text, (i + 48).toString())
+
+ // no_NO: [49...1]
+ control.locale = Qt.locale("no_NO")
+ for (var j = 0; j < 5; ++j)
+ compare(control.contentItem.children[j].text, (j + 49).toString())
+ compare(control.contentItem.children[5].text, "1")
+
+ control.destroy()
+ }
+
+ function test_range() {
+ var control = component.createObject(testCase)
+
+ control.month = 0
+ compare(control.month, 0)
+
+ ignoreWarning(Qt.resolvedUrl("tst_weeknumbercolumn.qml") + ":55:9: QML AbstractWeekNumberColumn: month -1 is out of range [0...11]")
+ control.month = -1
+ compare(control.month, 0)
+
+ control.month = 11
+ compare(control.month, 11)
+
+ ignoreWarning(Qt.resolvedUrl("tst_weeknumbercolumn.qml") + ":55:9: QML AbstractWeekNumberColumn: month 12 is out of range [0...11]")
+ control.month = 12
+ compare(control.month, 11)
+
+ control.year = -271820
+ compare(control.year, -271820)
+
+ ignoreWarning(Qt.resolvedUrl("tst_weeknumbercolumn.qml") + ":55:9: QML AbstractWeekNumberColumn: year -271821 is out of range [-271820...275759]")
+ control.year = -271821
+ compare(control.year, -271820)
+
+ control.year = 275759
+ compare(control.year, 275759)
+
+ ignoreWarning(Qt.resolvedUrl("tst_weeknumbercolumn.qml") + ":55:9: QML AbstractWeekNumberColumn: year 275760 is out of range [-271820...275759]")
+ control.year = 275760
+ compare(control.year, 275759)
+
+ control.destroy()
+ }
+
function test_font() {
var control = component.createObject(testCase)
diff --git a/tests/auto/snippets/data/calendarview/qtlabscalendar-calendarview-layout.qml b/tests/auto/snippets/data/calendarview/qtlabscalendar-calendarview-layout.qml
index 8aaddba6..ec32368b 100644
--- a/tests/auto/snippets/data/calendarview/qtlabscalendar-calendarview-layout.qml
+++ b/tests/auto/snippets/data/calendarview/qtlabscalendar-calendarview-layout.qml
@@ -23,7 +23,7 @@ GridLayout {
CalendarView {
id: view
- month: 12
+ month: 11
year: 2015
locale: Qt.locale("en_US")
diff --git a/tests/auto/snippets/data/calendarview/qtlabscalendar-calendarview.qml b/tests/auto/snippets/data/calendarview/qtlabscalendar-calendarview.qml
index b853d635..e1cad178 100644
--- a/tests/auto/snippets/data/calendarview/qtlabscalendar-calendarview.qml
+++ b/tests/auto/snippets/data/calendarview/qtlabscalendar-calendarview.qml
@@ -3,7 +3,7 @@ import Qt.labs.calendar 1.0
//! [1]
CalendarView {
- month: 12
+ month: 11
year: 2015
locale: Qt.locale("en_US")
}
diff --git a/tests/auto/snippets/data/dayofweekrow/qtlabscalendar-dayofweekrow-layout.qml b/tests/auto/snippets/data/dayofweekrow/qtlabscalendar-dayofweekrow-layout.qml
index d013b167..88267b2c 100644
--- a/tests/auto/snippets/data/dayofweekrow/qtlabscalendar-dayofweekrow-layout.qml
+++ b/tests/auto/snippets/data/dayofweekrow/qtlabscalendar-dayofweekrow-layout.qml
@@ -11,7 +11,7 @@ ColumnLayout {
CalendarView {
id: view
- month: 12
+ month: 11
year: 2015
locale: Qt.locale("en_US")
Layout.fillWidth: true
diff --git a/tests/auto/snippets/data/weeknumbercolumn/qtlabscalendar-weeknumbercolumn-layout.qml b/tests/auto/snippets/data/weeknumbercolumn/qtlabscalendar-weeknumbercolumn-layout.qml
index 479b069c..47a260fa 100644
--- a/tests/auto/snippets/data/weeknumbercolumn/qtlabscalendar-weeknumbercolumn-layout.qml
+++ b/tests/auto/snippets/data/weeknumbercolumn/qtlabscalendar-weeknumbercolumn-layout.qml
@@ -5,15 +5,15 @@ import Qt.labs.calendar 1.0
//! [1]
RowLayout {
WeekNumberColumn {
- month: 12
- year: 2015
+ month: view.month
+ year: view.year
locale: view.locale
Layout.fillHeight: true
}
CalendarView {
id: view
- month: 12
+ month: 11
year: 2015
locale: Qt.locale("en_US")
Layout.fillHeight: true
diff --git a/tests/auto/snippets/data/weeknumbercolumn/qtlabscalendar-weeknumbercolumn.qml b/tests/auto/snippets/data/weeknumbercolumn/qtlabscalendar-weeknumbercolumn.qml
index eaa50bff..6e450b57 100644
--- a/tests/auto/snippets/data/weeknumbercolumn/qtlabscalendar-weeknumbercolumn.qml
+++ b/tests/auto/snippets/data/weeknumbercolumn/qtlabscalendar-weeknumbercolumn.qml
@@ -3,7 +3,7 @@ import Qt.labs.calendar 1.0
//! [1]
WeekNumberColumn {
- month: 12
+ month: 11
year: 2015
locale: Qt.locale("en_US")
}