diff options
-rw-r--r-- | src/imports/calendar/qquickdayofweekrow.cpp | 29 | ||||
-rw-r--r-- | src/imports/calendar/qquickdayofweekrow_p.h | 7 | ||||
-rw-r--r-- | src/imports/calendar/qquickmonthgrid.cpp | 29 | ||||
-rw-r--r-- | src/imports/calendar/qquickmonthgrid_p.h | 7 | ||||
-rw-r--r-- | src/imports/calendar/qquickweeknumbercolumn.cpp | 27 | ||||
-rw-r--r-- | src/imports/calendar/qquickweeknumbercolumn_p.h | 7 | ||||
-rw-r--r-- | src/templates/qquickcontrol.cpp | 31 | ||||
-rw-r--r-- | src/templates/qquickcontrol_p.h | 7 | ||||
-rw-r--r-- | src/templates/qquickcontrol_p_p.h | 1 | ||||
-rw-r--r-- | src/templates/qquickspinbox.cpp | 27 | ||||
-rw-r--r-- | src/templates/qquickspinbox_p.h | 5 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_control.qml | 13 |
12 files changed, 83 insertions, 107 deletions
diff --git a/src/imports/calendar/qquickdayofweekrow.cpp b/src/imports/calendar/qquickdayofweekrow.cpp index 3c146c1f..8788ac95 100644 --- a/src/imports/calendar/qquickdayofweekrow.cpp +++ b/src/imports/calendar/qquickdayofweekrow.cpp @@ -48,8 +48,8 @@ QT_BEGIN_NAMESPACE \inqmlmodule Qt.labs.calendar \brief A row of names for the days in a week. - DayOfWeekRow presents day of week names in a row. The names of - the days are ordered and formatted using the specified \l locale. + DayOfWeekRow presents day of week names in a row. The names of the days + are ordered and formatted using the specified \l {Control::locale}{locale}. \image qtlabscalendar-dayofweekrow.png \snippet qtlabscalendar-dayofweekrow.qml 1 @@ -98,24 +98,6 @@ QQuickDayOfWeekRow::QQuickDayOfWeekRow(QQuickItem *parent) : Q_D(QQuickDayOfWeekRow); d->model = new QQuickDayOfWeekModel(this); d->source = QVariant::fromValue(d->model); - connect(d->model, &QQuickDayOfWeekModel::localeChanged, this, &QQuickDayOfWeekRow::localeChanged); -} - -/*! - \qmlproperty Locale Qt.labs.calendar::DayOfWeekRow::locale - - This property holds the locale that is used to format names of the days in a week. -*/ -QLocale QQuickDayOfWeekRow::locale() const -{ - Q_D(const QQuickDayOfWeekRow); - return d->model->locale(); -} - -void QQuickDayOfWeekRow::setLocale(const QLocale &locale) -{ - Q_D(QQuickDayOfWeekRow); - d->model->setLocale(locale); } /*! @@ -190,6 +172,13 @@ void QQuickDayOfWeekRow::geometryChanged(const QRectF &newGeometry, const QRectF d->resizeItems(); } +void QQuickDayOfWeekRow::localeChange(const QLocale &newLocale, const QLocale &oldLocale) +{ + Q_D(QQuickDayOfWeekRow); + QQuickControl::localeChange(newLocale, oldLocale); + d->model->setLocale(newLocale); +} + void QQuickDayOfWeekRow::paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding) { Q_D(QQuickDayOfWeekRow); diff --git a/src/imports/calendar/qquickdayofweekrow_p.h b/src/imports/calendar/qquickdayofweekrow_p.h index 5161ed89..93916765 100644 --- a/src/imports/calendar/qquickdayofweekrow_p.h +++ b/src/imports/calendar/qquickdayofweekrow_p.h @@ -49,7 +49,6 @@ // #include <QtLabsTemplates/private/qquickcontrol_p.h> -#include <QtCore/qlocale.h> QT_BEGIN_NAMESPACE @@ -59,16 +58,12 @@ class QQuickDayOfWeekRowPrivate; class QQuickDayOfWeekRow : public QQuickControl { Q_OBJECT - Q_PROPERTY(QLocale locale READ locale WRITE setLocale NOTIFY localeChanged FINAL) Q_PROPERTY(QVariant source READ source WRITE setSource NOTIFY sourceChanged FINAL) Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL) public: explicit QQuickDayOfWeekRow(QQuickItem *parent = Q_NULLPTR); - QLocale locale() const; - void setLocale(const QLocale &locale); - QVariant source() const; void setSource(const QVariant &source); @@ -76,13 +71,13 @@ public: void setDelegate(QQmlComponent *delegate); Q_SIGNALS: - void localeChanged(); void sourceChanged(); void delegateChanged(); protected: void componentComplete() Q_DECL_OVERRIDE; void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; + void localeChange(const QLocale &newLocale, const QLocale &oldLocale) Q_DECL_OVERRIDE; void paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding) Q_DECL_OVERRIDE; private: diff --git a/src/imports/calendar/qquickmonthgrid.cpp b/src/imports/calendar/qquickmonthgrid.cpp index 432e15e5..ac49b62c 100644 --- a/src/imports/calendar/qquickmonthgrid.cpp +++ b/src/imports/calendar/qquickmonthgrid.cpp @@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE MonthGrid presents a calendar month in a grid. The contents are calculated for a given \l month and \l year, using the specified - \l locale. + \l {Control::locale}{locale}. \image qtlabscalendar-monthgrid.png \snippet qtlabscalendar-monthgrid.qml 1 @@ -173,7 +173,6 @@ QQuickMonthGrid::QQuickMonthGrid(QQuickItem *parent) : d->source = QVariant::fromValue(d->model); connect(d->model, &QQuickMonthModel::monthChanged, this, &QQuickMonthGrid::monthChanged); connect(d->model, &QQuickMonthModel::yearChanged, this, &QQuickMonthGrid::yearChanged); - connect(d->model, &QQuickMonthModel::localeChanged, this, &QQuickMonthGrid::localeChanged); connect(d->model, &QQuickMonthModel::titleChanged, this, &QQuickMonthGrid::titleChanged); } @@ -245,23 +244,6 @@ void QQuickMonthGrid::setYear(int year) } /*! - \qmlproperty Locale Qt.labs.calendar::MonthGrid::locale - - This property holds the locale that is used to calculate the contents. -*/ -QLocale QQuickMonthGrid::locale() const -{ - Q_D(const QQuickMonthGrid); - return d->model->locale(); -} - -void QQuickMonthGrid::setLocale(const QLocale &locale) -{ - Q_D(QQuickMonthGrid); - d->model->setLocale(locale); -} - -/*! \internal \qmlproperty model Qt.labs.calendar::MonthGrid::source @@ -290,7 +272,7 @@ void QQuickMonthGrid::setSource(const QVariant &source) This property is provided for convenience. MonthGrid itself does not visualize the title. The default value consists of the month name, - formatted using \l locale, and the year number. + formatted using \l {Control::locale}{locale}, and the year number. */ QString QQuickMonthGrid::title() const { @@ -367,6 +349,13 @@ void QQuickMonthGrid::geometryChanged(const QRectF &newGeometry, const QRectF &o d->resizeItems(); } +void QQuickMonthGrid::localeChange(const QLocale &newLocale, const QLocale &oldLocale) +{ + Q_D(QQuickMonthGrid); + QQuickControl::localeChange(newLocale, oldLocale); + d->model->setLocale(newLocale); +} + void QQuickMonthGrid::paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding) { Q_D(QQuickMonthGrid); diff --git a/src/imports/calendar/qquickmonthgrid_p.h b/src/imports/calendar/qquickmonthgrid_p.h index c7caa7f5..47be2f7c 100644 --- a/src/imports/calendar/qquickmonthgrid_p.h +++ b/src/imports/calendar/qquickmonthgrid_p.h @@ -49,7 +49,6 @@ // #include <QtLabsTemplates/private/qquickcontrol_p.h> -#include <QtCore/qlocale.h> QT_BEGIN_NAMESPACE @@ -61,7 +60,6 @@ class QQuickMonthGrid : public QQuickControl Q_OBJECT Q_PROPERTY(int month READ month WRITE setMonth NOTIFY monthChanged FINAL) Q_PROPERTY(int year READ year WRITE setYear NOTIFY yearChanged FINAL) - Q_PROPERTY(QLocale locale READ locale WRITE setLocale NOTIFY localeChanged FINAL) Q_PROPERTY(QVariant source READ source WRITE setSource NOTIFY sourceChanged FINAL) Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged FINAL) Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL) @@ -75,9 +73,6 @@ public: int year() const; void setYear(int year); - QLocale locale() const; - void setLocale(const QLocale &locale); - QVariant source() const; void setSource(const QVariant &source); @@ -90,7 +85,6 @@ public: Q_SIGNALS: void monthChanged(); void yearChanged(); - void localeChanged(); void sourceChanged(); void titleChanged(); void delegateChanged(); @@ -103,6 +97,7 @@ Q_SIGNALS: protected: void componentComplete() Q_DECL_OVERRIDE; void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; + void localeChange(const QLocale &newLocale, const QLocale &oldLocale) Q_DECL_OVERRIDE; void paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding) Q_DECL_OVERRIDE; void updatePolish() Q_DECL_OVERRIDE; diff --git a/src/imports/calendar/qquickweeknumbercolumn.cpp b/src/imports/calendar/qquickweeknumbercolumn.cpp index d39b1e0a..04890411 100644 --- a/src/imports/calendar/qquickweeknumbercolumn.cpp +++ b/src/imports/calendar/qquickweeknumbercolumn.cpp @@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE WeekNumberColumn presents week numbers in a column. The week numbers are calculated for a given \l month and \l year, using the specified - \l locale. + \l {Control::locale}{locale}. \image qtlabscalendar-weeknumbercolumn.png \snippet qtlabscalendar-weeknumbercolumn.qml 1 @@ -102,7 +102,6 @@ QQuickWeekNumberColumn::QQuickWeekNumberColumn(QQuickItem *parent) : d->source = QVariant::fromValue(d->model); connect(d->model, &QQuickWeekNumberModel::monthChanged, this, &QQuickWeekNumberColumn::monthChanged); connect(d->model, &QQuickWeekNumberModel::yearChanged, this, &QQuickWeekNumberColumn::yearChanged); - connect(d->model, &QQuickWeekNumberModel::localeChanged, this, &QQuickWeekNumberColumn::localeChanged); } /*! @@ -173,23 +172,6 @@ void QQuickWeekNumberColumn::setYear(int year) } /*! - \qmlproperty Locale Qt.labs.calendar::WeekNumberColumn::locale - - This property holds the locale that is used to calculate the week numbers. -*/ -QLocale QQuickWeekNumberColumn::locale() const -{ - Q_D(const QQuickWeekNumberColumn); - return d->model->locale(); -} - -void QQuickWeekNumberColumn::setLocale(const QLocale &locale) -{ - Q_D(QQuickWeekNumberColumn); - d->model->setLocale(locale); -} - -/*! \internal \qmlproperty model Qt.labs.calendar::WeekNumberColumn::source @@ -258,6 +240,13 @@ void QQuickWeekNumberColumn::geometryChanged(const QRectF &newGeometry, const QR d->resizeItems(); } +void QQuickWeekNumberColumn::localeChange(const QLocale &newLocale, const QLocale &oldLocale) +{ + Q_D(QQuickWeekNumberColumn); + QQuickControl::localeChange(newLocale, oldLocale); + d->model->setLocale(newLocale); +} + void QQuickWeekNumberColumn::paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding) { Q_D(QQuickWeekNumberColumn); diff --git a/src/imports/calendar/qquickweeknumbercolumn_p.h b/src/imports/calendar/qquickweeknumbercolumn_p.h index f23d2948..c1ebfbd7 100644 --- a/src/imports/calendar/qquickweeknumbercolumn_p.h +++ b/src/imports/calendar/qquickweeknumbercolumn_p.h @@ -49,7 +49,6 @@ // #include <QtLabsTemplates/private/qquickcontrol_p.h> -#include <QtCore/qlocale.h> QT_BEGIN_NAMESPACE @@ -61,7 +60,6 @@ class QQuickWeekNumberColumn : public QQuickControl Q_OBJECT Q_PROPERTY(int month READ month WRITE setMonth NOTIFY monthChanged FINAL) Q_PROPERTY(int year READ year WRITE setYear NOTIFY yearChanged FINAL) - Q_PROPERTY(QLocale locale READ locale WRITE setLocale NOTIFY localeChanged FINAL) Q_PROPERTY(QVariant source READ source WRITE setSource NOTIFY sourceChanged FINAL) Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL) @@ -74,9 +72,6 @@ public: int year() const; void setYear(int year); - QLocale locale() const; - void setLocale(const QLocale &locale); - QVariant source() const; void setSource(const QVariant &source); @@ -86,13 +81,13 @@ public: Q_SIGNALS: void monthChanged(); void yearChanged(); - void localeChanged(); void sourceChanged(); void delegateChanged(); protected: void componentComplete() Q_DECL_OVERRIDE; void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; + void localeChange(const QLocale &newLocale, const QLocale &oldLocale) Q_DECL_OVERRIDE; void paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding) Q_DECL_OVERRIDE; private: diff --git a/src/templates/qquickcontrol.cpp b/src/templates/qquickcontrol.cpp index 0b8c3067..292bc8ec 100644 --- a/src/templates/qquickcontrol.cpp +++ b/src/templates/qquickcontrol.cpp @@ -660,6 +660,29 @@ void QQuickControl::setLayoutDirection(Qt::LayoutDirection direction) } /*! + \qmlproperty Locale Qt.labs.calendar::Control::locale + + This property holds the locale of the control. + + \sa mirrored, {LayoutMirroring}{LayoutMirroring} +*/ +QLocale QQuickControl::locale() const +{ + Q_D(const QQuickControl); + return d->locale; +} + +void QQuickControl::setLocale(const QLocale &locale) +{ + Q_D(QQuickControl); + if (d->locale != locale) { + localeChange(locale, d->locale); + d->locale = locale; + emit localeChanged(); + } +} + +/*! \qmlproperty bool Qt.labs.controls::Control::mirrored \readonly @@ -668,7 +691,7 @@ void QQuickControl::setLayoutDirection(Qt::LayoutDirection direction) This property is provided for convenience. A control is considered mirrored when its visual layout direction is right-to-left. - \sa effectiveLayoutDirection, {LayoutMirroring}{LayoutMirroring} + \sa locale, {LayoutMirroring}{LayoutMirroring} */ bool QQuickControl::isMirrored() const { @@ -797,4 +820,10 @@ void QQuickControl::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) Q_UNUSED(oldItem); } +void QQuickControl::localeChange(const QLocale &newLocale, const QLocale &oldLocale) +{ + Q_UNUSED(newLocale); + Q_UNUSED(oldLocale); +} + QT_END_NAMESPACE diff --git a/src/templates/qquickcontrol_p.h b/src/templates/qquickcontrol_p.h index 346b45b3..8f6460f1 100644 --- a/src/templates/qquickcontrol_p.h +++ b/src/templates/qquickcontrol_p.h @@ -48,6 +48,7 @@ // We mean it. // +#include <QtCore/qlocale.h> #include <QtQuick/qquickitem.h> #include <QtLabsTemplates/private/qtlabstemplatesglobal_p.h> @@ -69,6 +70,7 @@ class Q_LABSTEMPLATES_EXPORT QQuickControl : public QQuickItem Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing RESET resetSpacing NOTIFY spacingChanged FINAL) Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged FINAL) Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged FINAL) + Q_PROPERTY(QLocale locale READ locale WRITE setLocale NOTIFY localeChanged FINAL) Q_PROPERTY(bool mirrored READ isMirrored NOTIFY mirroredChanged FINAL) Q_PROPERTY(QQuickItem *background READ background WRITE setBackground NOTIFY backgroundChanged FINAL) Q_PROPERTY(QQuickItem *contentItem READ contentItem WRITE setContentItem NOTIFY contentItemChanged FINAL) @@ -111,6 +113,9 @@ public: Qt::LayoutDirection effectiveLayoutDirection() const; void setLayoutDirection(Qt::LayoutDirection direction); + QLocale locale() const; + void setLocale(const QLocale &locale); + bool isMirrored() const; QQuickItem *background() const; @@ -131,6 +136,7 @@ Q_SIGNALS: void spacingChanged(); void layoutDirectionChanged(); void effectiveLayoutDirectionChanged(); + void localeChanged(); void mirroredChanged(); void backgroundChanged(); void contentItemChanged(); @@ -153,6 +159,7 @@ protected: virtual void mirrorChange(); virtual void paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding); virtual void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem); + virtual void localeChange(const QLocale &newLocale, const QLocale &oldLocale); #ifndef QT_NO_ACCESSIBILITY virtual void accessibilityActiveChanged(bool active); diff --git a/src/templates/qquickcontrol_p_p.h b/src/templates/qquickcontrol_p_p.h index ab185952..f582014d 100644 --- a/src/templates/qquickcontrol_p_p.h +++ b/src/templates/qquickcontrol_p_p.h @@ -115,6 +115,7 @@ public: qreal bottomPadding; qreal spacing; Qt::LayoutDirection layoutDirection; + QLocale locale; QQuickItem *background; QQuickItem *contentItem; QQuickAccessibleAttached *accessibleAttached; diff --git a/src/templates/qquickspinbox.cpp b/src/templates/qquickspinbox.cpp index 9e0bd723..1b06bfd4 100644 --- a/src/templates/qquickspinbox.cpp +++ b/src/templates/qquickspinbox.cpp @@ -113,7 +113,6 @@ public: int repeatTimer; QQuickSpinButton *up; QQuickSpinButton *down; - QLocale locale; QValidator *validator; QJSValue textFromValue; QJSValue valueFromText; @@ -337,26 +336,6 @@ void QQuickSpinBox::setStepSize(int step) } /*! - \qmlproperty Locale Qt.labs.controls::SpinBox::locale - - This property holds the locale that is used to format the value. -*/ -QLocale QQuickSpinBox::locale() const -{ - Q_D(const QQuickSpinBox); - return d->locale; -} - -void QQuickSpinBox::setLocale(const QLocale &locale) -{ - Q_D(QQuickSpinBox); - if (d->locale != locale) { - d->locale = locale; - emit localeChanged(); - } -} - -/*! \qmlproperty Validator Qt.labs.controls::SpinBox::validator This property holds the input text validator. By default, SpinBox uses @@ -364,7 +343,7 @@ void QQuickSpinBox::setLocale(const QLocale &locale) \snippet SpinBox.qml validator - \sa textFromValue, valueFromText, locale + \sa textFromValue, valueFromText, {Control::locale}{locale} */ QValidator *QQuickSpinBox::validator() const { @@ -398,7 +377,7 @@ void QQuickSpinBox::setValidator(QValidator *validator) textFromValue: function(value, locale) { return Number(value).toLocaleString(locale, 'f', 0); } \endcode - \sa valueFromText, validator, locale + \sa valueFromText, validator, {Control::locale}{locale} */ QJSValue QQuickSpinBox::textFromValue() const { @@ -434,7 +413,7 @@ void QQuickSpinBox::setTextFromValue(const QJSValue &callback) valueFromText: function(text, locale) { return Number.fromLocaleString(locale, text); } \endcode - \sa textFromValue, validator, locale + \sa textFromValue, validator, {Control::locale}{locale} */ QJSValue QQuickSpinBox::valueFromText() const { diff --git a/src/templates/qquickspinbox_p.h b/src/templates/qquickspinbox_p.h index 1ea7130d..3db12a10 100644 --- a/src/templates/qquickspinbox_p.h +++ b/src/templates/qquickspinbox_p.h @@ -65,7 +65,6 @@ class Q_LABSTEMPLATES_EXPORT QQuickSpinBox : public QQuickControl Q_PROPERTY(int to READ to WRITE setTo NOTIFY toChanged FINAL) Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged FINAL) Q_PROPERTY(int stepSize READ stepSize WRITE setStepSize NOTIFY stepSizeChanged FINAL) - Q_PROPERTY(QLocale locale READ locale WRITE setLocale NOTIFY localeChanged FINAL) Q_PROPERTY(QValidator *validator READ validator WRITE setValidator NOTIFY validatorChanged FINAL) Q_PROPERTY(QJSValue textFromValue READ textFromValue WRITE setTextFromValue NOTIFY textFromValueChanged FINAL) Q_PROPERTY(QJSValue valueFromText READ valueFromText WRITE setValueFromText NOTIFY valueFromTextChanged FINAL) @@ -87,9 +86,6 @@ public: int stepSize() const; void setStepSize(int step); - QLocale locale() const; - void setLocale(const QLocale &locale); - QValidator *validator() const; void setValidator(QValidator *validator); @@ -111,7 +107,6 @@ Q_SIGNALS: void toChanged(); void valueChanged(); void stepSizeChanged(); - void localeChanged(); void validatorChanged(); void textFromValueChanged(); void valueFromTextChanged(); diff --git a/tests/auto/controls/data/tst_control.qml b/tests/auto/controls/data/tst_control.qml index 15b25112..34173026 100644 --- a/tests/auto/controls/data/tst_control.qml +++ b/tests/auto/controls/data/tst_control.qml @@ -656,4 +656,17 @@ TestCase { control4.destroy() } + + function test_locale() { + var control = component.createObject(testCase) + verify(control) + + control.locale = Qt.locale("en_US") + compare(control.locale.name, "en_US") + + control.locale = Qt.locale("nb_NO") + compare(control.locale.name, "nb_NO") + + control.destroy() + } } |