diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-02-25 20:00:56 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-02-25 20:00:56 +0100 |
commit | ee6c83db18e65e4eec7b7280213b780576b24c03 (patch) | |
tree | caf049a79f3187962059c7f73181b22b71dc1632 /src/imports/calendar | |
parent | 718f6def0b2c4d84bdc8ebdc9633697885747feb (diff) | |
parent | db5780507733ef803e963dcef0b5260c4b94acfa (diff) |
Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts:
src/templates/qquickrangeslider_p.h
Change-Id: Ibe8ec18a7e22080f69f316d0394af1d03517ce93
Diffstat (limited to 'src/imports/calendar')
-rw-r--r-- | src/imports/calendar/qquickcalendar.cpp | 2 | ||||
-rw-r--r-- | src/imports/calendar/qquickcalendarmodel.cpp | 38 | ||||
-rw-r--r-- | src/imports/calendar/qquickmonthgrid.cpp | 2 | ||||
-rw-r--r-- | src/imports/calendar/qquickweeknumbercolumn.cpp | 2 |
4 files changed, 35 insertions, 9 deletions
diff --git a/src/imports/calendar/qquickcalendar.cpp b/src/imports/calendar/qquickcalendar.cpp index 5a14bb27..b64759f2 100644 --- a/src/imports/calendar/qquickcalendar.cpp +++ b/src/imports/calendar/qquickcalendar.cpp @@ -52,7 +52,7 @@ QT_BEGIN_NAMESPACE with the JavaScript Date type, that is used by the QML language. This means that \c Date::getMonth() can be assigned to MonthGrid::month and WeekNumberColumn::month as is. When dealing with dealing with month numbers - diretly, it is highly recommended to use the following enumeration values + directly, it is highly recommended to use the following enumeration values to avoid confusion. \value Calendar.January January (0) diff --git a/src/imports/calendar/qquickcalendarmodel.cpp b/src/imports/calendar/qquickcalendarmodel.cpp index 6b59d45a..9d214450 100644 --- a/src/imports/calendar/qquickcalendarmodel.cpp +++ b/src/imports/calendar/qquickcalendarmodel.cpp @@ -60,9 +60,28 @@ QT_BEGIN_NAMESPACE \row \li \b model.year : int \li The number of the year \endtable + The Qt Labs Calendar module uses 0-based month numbers to be consistent + with the JavaScript Date type, that is used by the QML language. This + means that \c Date::getMonth() can be passed to the methods as is. When + dealing with dealing with month numbers directly, it is highly recommended + to use the following enumeration values to avoid confusion. + + \value Calendar.January January (0) + \value Calendar.February February (1) + \value Calendar.March March (2) + \value Calendar.April April (3) + \value Calendar.May May (4) + \value Calendar.June June (5) + \value Calendar.July July (6) + \value Calendar.August August (7) + \value Calendar.September September (8) + \value Calendar.October October (9) + \value Calendar.November November (10) + \value Calendar.December December (11) + \labs - \sa MonthGrid + \sa MonthGrid, Calendar */ class QQuickCalendarModelPrivate : public QAbstractItemModelPrivate @@ -87,9 +106,16 @@ public: int QQuickCalendarModelPrivate::getCount(const QDate& from, const QDate &to) { + if (!from.isValid() || !to.isValid()) + return 0; + QDate f(from.year(), from.month(), 1); QDate t(to.year(), to.month(), to.daysInMonth()); - QDate r = QDate(1, 1, 1).addDays(f.daysTo(t)); + int days = f.daysTo(t); + if (days < 0) + return 0; + + QDate r = QDate(1, 1, 1).addDays(days); int years = r.year() - 1; int months = r.month() - 1; return 12 * years + months + (r.day() / t.day()); @@ -169,7 +195,7 @@ void QQuickCalendarModel::setTo(const QDate &to) int QQuickCalendarModel::monthAt(int index) const { Q_D(const QQuickCalendarModel); - return d->from.addMonths(index).month(); + return d->from.addMonths(index).month() - 1; } /*! @@ -190,7 +216,8 @@ int QQuickCalendarModel::yearAt(int index) const */ int QQuickCalendarModel::indexOf(const QDate &date) const { - return indexOf(date.year(), date.month()); + Q_D(const QQuickCalendarModel); + return d->getCount(d->from, date) - 1; } /*! @@ -200,8 +227,7 @@ int QQuickCalendarModel::indexOf(const QDate &date) const */ int QQuickCalendarModel::indexOf(int year, int month) const { - Q_D(const QQuickCalendarModel); - return d->getCount(d->from, QDate(year, month, 1)) - 1; + return indexOf(QDate(year, month + 1, 1)); } QVariant QQuickCalendarModel::data(const QModelIndex &index, int role) const diff --git a/src/imports/calendar/qquickmonthgrid.cpp b/src/imports/calendar/qquickmonthgrid.cpp index 8fe9ad63..c6ad3d53 100644 --- a/src/imports/calendar/qquickmonthgrid.cpp +++ b/src/imports/calendar/qquickmonthgrid.cpp @@ -188,7 +188,7 @@ QQuickMonthGrid::QQuickMonthGrid(QQuickItem *parent) : The Qt Labs Calendar module uses 0-based month numbers to be consistent with the JavaScript Date type, that is used by the QML language. This means that \c Date::getMonth() can be assigned to this property as is. - When dealing with dealing with month numbers diretly, it is highly + When dealing with dealing with month numbers directly, it is highly recommended to use the following enumeration values to avoid confusion. \value Calendar.January January (0) diff --git a/src/imports/calendar/qquickweeknumbercolumn.cpp b/src/imports/calendar/qquickweeknumbercolumn.cpp index 031b0555..a128b500 100644 --- a/src/imports/calendar/qquickweeknumbercolumn.cpp +++ b/src/imports/calendar/qquickweeknumbercolumn.cpp @@ -116,7 +116,7 @@ QQuickWeekNumberColumn::QQuickWeekNumberColumn(QQuickItem *parent) : The Qt Labs Calendar module uses 0-based month numbers to be consistent with the JavaScript Date type, that is used by the QML language. This means that \c Date::getMonth() can be assigned to this property as is. - When dealing with dealing with month numbers diretly, it is highly + When dealing with dealing with month numbers directly, it is highly recommended to use the following enumeration values to avoid confusion. \value Calendar.January January (0) |