From e20e63a0b7d835fce16d41599dd69d348d5648b2 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Sat, 5 Dec 2015 13:59:33 +0100 Subject: Remove Control::layoutDirection Calculate QQuickControl::isMirrored() from LayoutMirroring.enabled (QQuickItemPrivate::isMirrored()) and QLocale::textDirection(). Change-Id: I0e391d27df732734031f3e94d9828a1a2cfa7474 Reviewed-by: Mitch Curtis --- src/imports/controls/designer/ControlSection.qml | 14 ------ src/templates/qquickcontrol.cpp | 62 +++--------------------- src/templates/qquickcontrol_p.h | 8 --- src/templates/qquickcontrol_p_p.h | 1 - tests/auto/controls/data/tst_control.qml | 49 ++++--------------- tests/auto/controls/data/tst_progressbar.qml | 14 ++++-- tests/auto/controls/data/tst_rangeslider.qml | 19 ++++++-- tests/auto/controls/data/tst_slider.qml | 16 ++++-- 8 files changed, 54 insertions(+), 129 deletions(-) diff --git a/src/imports/controls/designer/ControlSection.qml b/src/imports/controls/designer/ControlSection.qml index e026d620..0d7a07d2 100644 --- a/src/imports/controls/designer/ControlSection.qml +++ b/src/imports/controls/designer/ControlSection.qml @@ -67,19 +67,5 @@ Section { Layout.fillWidth: true } } - - Label { - text: qsTr("Direction") - tooltip: qsTr("Layout direction of the control.") - } - SecondColumnLayout { - ComboBox { - backendValue: backendValues.layoutDirection - implicitWidth: 180 - model: [ "LeftToRight", "RightToLeft" ] - scope: "Qt" - Layout.fillWidth: true - } - } } } diff --git a/src/templates/qquickcontrol.cpp b/src/templates/qquickcontrol.cpp index 292bc8ec..993019b7 100644 --- a/src/templates/qquickcontrol.cpp +++ b/src/templates/qquickcontrol.cpp @@ -68,8 +68,7 @@ QT_BEGIN_NAMESPACE QQuickControlPrivate::QQuickControlPrivate() : hasTopPadding(false), hasLeftPadding(false), hasRightPadding(false), hasBottomPadding(false), padding(0), topPadding(0), leftPadding(0), rightPadding(0), bottomPadding(0), spacing(0), - layoutDirection(Qt::LeftToRight), background(Q_NULLPTR), contentItem(Q_NULLPTR), - accessibleAttached(Q_NULLPTR) + background(Q_NULLPTR), contentItem(Q_NULLPTR), accessibleAttached(Q_NULLPTR) { #ifndef QT_NO_ACCESSIBILITY QAccessible::installActivationObserver(this); @@ -86,7 +85,8 @@ QQuickControlPrivate::~QQuickControlPrivate() void QQuickControlPrivate::mirrorChange() { Q_Q(QQuickControl); - q->mirrorChange(); + if (locale.textDirection() == Qt::LeftToRight) + q->mirrorChange(); } void QQuickControlPrivate::setTopPadding(qreal value, bool reset) @@ -610,55 +610,6 @@ void QQuickControl::resetSpacing() setSpacing(0); } -/*! - \qmlproperty enumeration Qt.labs.controls::Control::layoutDirection - - This property holds the layout direction of the control. - - Possible values: - \value Qt.LeftToRight Items are laid out from left to right. If the width of the row is explicitly set, - the left anchor remains to the left of the row (default). - \value Qt.RightToLeft Items are laid out from right to left. If the width of the row is explicitly set, - the right anchor remains to the right of the row. - - \sa effectiveLayoutDirection -*/ -Qt::LayoutDirection QQuickControl::layoutDirection() const -{ - Q_D(const QQuickControl); - return d->layoutDirection; -} - -/*! - \qmlproperty enumeration Qt.labs.controls::Control::effectiveLayoutDirection - \readonly - - This property holds the effective layout direction of the control. - - When using the attached property \l {LayoutMirroring::enabled}{LayoutMirroring::enabled} - for locale layouts, the visual layout direction of the control will be mirrored. However, - the \l layoutDirection property will remain unchanged. - - \sa layoutDirection, {LayoutMirroring}{LayoutMirroring} -*/ -Qt::LayoutDirection QQuickControl::effectiveLayoutDirection() const -{ - Q_D(const QQuickControl); - if (d->isMirrored()) - return d->layoutDirection == Qt::RightToLeft ? Qt::LeftToRight : Qt::RightToLeft; - return d->layoutDirection; -} - -void QQuickControl::setLayoutDirection(Qt::LayoutDirection direction) -{ - Q_D(QQuickControl); - if (d->layoutDirection != direction) { - d->layoutDirection = direction; - emit layoutDirectionChanged(); - mirrorChange(); - } -} - /*! \qmlproperty Locale Qt.labs.calendar::Control::locale @@ -676,9 +627,12 @@ void QQuickControl::setLocale(const QLocale &locale) { Q_D(QQuickControl); if (d->locale != locale) { + bool wasMirrored = isMirrored(); localeChange(locale, d->locale); d->locale = locale; emit localeChanged(); + if (wasMirrored != isMirrored()) + mirrorChange(); } } @@ -695,7 +649,8 @@ void QQuickControl::setLocale(const QLocale &locale) */ bool QQuickControl::isMirrored() const { - return effectiveLayoutDirection() == Qt::RightToLeft; + Q_D(const QQuickControl); + return d->isMirrored() || d->locale.textDirection() == Qt::RightToLeft; } /*! @@ -802,7 +757,6 @@ void QQuickControl::geometryChanged(const QRectF &newGeometry, const QRectF &old void QQuickControl::mirrorChange() { - emit effectiveLayoutDirectionChanged(); emit mirroredChanged(); } diff --git a/src/templates/qquickcontrol_p.h b/src/templates/qquickcontrol_p.h index 8f6460f1..56e8a9fd 100644 --- a/src/templates/qquickcontrol_p.h +++ b/src/templates/qquickcontrol_p.h @@ -68,8 +68,6 @@ class Q_LABSTEMPLATES_EXPORT QQuickControl : public QQuickItem Q_PROPERTY(qreal rightPadding READ rightPadding WRITE setRightPadding RESET resetRightPadding NOTIFY rightPaddingChanged FINAL) Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding RESET resetBottomPadding NOTIFY bottomPaddingChanged FINAL) 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) @@ -109,10 +107,6 @@ public: void setSpacing(qreal spacing); void resetSpacing(); - Qt::LayoutDirection layoutDirection() const; - Qt::LayoutDirection effectiveLayoutDirection() const; - void setLayoutDirection(Qt::LayoutDirection direction); - QLocale locale() const; void setLocale(const QLocale &locale); @@ -134,8 +128,6 @@ Q_SIGNALS: void rightPaddingChanged(); void bottomPaddingChanged(); void spacingChanged(); - void layoutDirectionChanged(); - void effectiveLayoutDirectionChanged(); void localeChanged(); void mirroredChanged(); void backgroundChanged(); diff --git a/src/templates/qquickcontrol_p_p.h b/src/templates/qquickcontrol_p_p.h index f582014d..f0cc402a 100644 --- a/src/templates/qquickcontrol_p_p.h +++ b/src/templates/qquickcontrol_p_p.h @@ -114,7 +114,6 @@ public: qreal rightPadding; qreal bottomPadding; qreal spacing; - Qt::LayoutDirection layoutDirection; QLocale locale; QQuickItem *background; QQuickItem *contentItem; diff --git a/tests/auto/controls/data/tst_control.qml b/tests/auto/controls/data/tst_control.qml index 34173026..3bfc5e63 100644 --- a/tests/auto/controls/data/tst_control.qml +++ b/tests/auto/controls/data/tst_control.qml @@ -56,16 +56,6 @@ TestCase { T.Control { } } - SignalSpy { - id: layoutDirectionSpy - signalName: "layoutDirectionChanged" - } - - SignalSpy { - id: effectiveLayoutDirectionSpy - signalName: "effectiveLayoutDirectionChanged" - } - SignalSpy { id: mirroredSpy signalName: "mirroredChanged" @@ -213,54 +203,33 @@ TestCase { control.destroy() } - function test_layoutDirection() { + function test_mirrored() { var control = component.createObject(testCase) verify(control) - layoutDirectionSpy.target = control - effectiveLayoutDirectionSpy.target = control mirroredSpy.target = control - - verify(layoutDirectionSpy.valid) - verify(effectiveLayoutDirectionSpy.valid) verify(mirroredSpy.valid) + control.locale = Qt.locale("en_US") + compare(control.locale.name, "en_US") verify(!control.LayoutMirroring.enabled) - compare(control.layoutDirection, Qt.LeftToRight) - compare(control.effectiveLayoutDirection, Qt.LeftToRight) compare(control.mirrored, false) - control.layoutDirection = Qt.RightToLeft - compare(control.layoutDirection, Qt.RightToLeft) - compare(control.effectiveLayoutDirection, Qt.RightToLeft) + control.locale = Qt.locale("ar_EG") compare(control.mirrored, true) - compare(layoutDirectionSpy.count, 1) - compare(effectiveLayoutDirectionSpy.count, 1) compare(mirroredSpy.count, 1) control.LayoutMirroring.enabled = true - compare(control.layoutDirection, Qt.RightToLeft) - compare(control.effectiveLayoutDirection, Qt.LeftToRight) - compare(control.mirrored, false) - compare(layoutDirectionSpy.count, 1) - compare(effectiveLayoutDirectionSpy.count, 2) - compare(mirroredSpy.count, 2) + compare(control.mirrored, true) + compare(mirroredSpy.count, 1) - control.layoutDirection = Qt.LeftToRight - compare(control.layoutDirection, Qt.LeftToRight) - compare(control.effectiveLayoutDirection, Qt.RightToLeft) + control.locale = Qt.locale("en_US") compare(control.mirrored, true) - compare(layoutDirectionSpy.count, 2) - compare(effectiveLayoutDirectionSpy.count, 3) - compare(mirroredSpy.count, 3) + compare(mirroredSpy.count, 1) control.LayoutMirroring.enabled = false - compare(control.layoutDirection, Qt.LeftToRight) - compare(control.effectiveLayoutDirection, Qt.LeftToRight) compare(control.mirrored, false) - compare(layoutDirectionSpy.count, 2) - compare(effectiveLayoutDirectionSpy.count, 4) - compare(mirroredSpy.count, 4) + compare(mirroredSpy.count, 2) control.destroy() } diff --git a/tests/auto/controls/data/tst_progressbar.qml b/tests/auto/controls/data/tst_progressbar.qml index ed09f5e9..d5ee3e52 100644 --- a/tests/auto/controls/data/tst_progressbar.qml +++ b/tests/auto/controls/data/tst_progressbar.qml @@ -159,18 +159,26 @@ TestCase { compare(control.value, 0.25) compare(control.visualPosition, 0.25) - control.layoutDirection = Qt.RightToLeft + // RTL locale + control.locale = Qt.locale("ar_EG") compare(control.visualPosition, 0.75) + // RTL locale + LayoutMirroring control.LayoutMirroring.enabled = true - compare(control.visualPosition, 0.25) + compare(control.visualPosition, 0.75) - control.layoutDirection = Qt.LeftToRight + // LTR locale + LayoutMirroring + control.locale = Qt.locale("en_US") compare(control.visualPosition, 0.75) + // LTR locale control.LayoutMirroring.enabled = false compare(control.visualPosition, 0.25) + // LayoutMirroring + control.LayoutMirroring.enabled = true + compare(control.visualPosition, 0.75) + control.destroy() } } diff --git a/tests/auto/controls/data/tst_rangeslider.qml b/tests/auto/controls/data/tst_rangeslider.qml index 345013f2..2a77d205 100644 --- a/tests/auto/controls/data/tst_rangeslider.qml +++ b/tests/auto/controls/data/tst_rangeslider.qml @@ -251,22 +251,31 @@ TestCase { compare(control.second.position, 1.0) compare(control.second.visualPosition, 1.0) - control.layoutDirection = Qt.RightToLeft + // RTL locale + control.locale = Qt.locale("ar_EG") compare(control.first.visualPosition, 0.75) compare(control.second.visualPosition, 0.0) + // RTL locale + LayoutMirroring control.LayoutMirroring.enabled = true - compare(control.first.visualPosition, 0.25) - compare(control.second.visualPosition, 1.0) + compare(control.first.visualPosition, 0.75) + compare(control.second.visualPosition, 0.0) - control.layoutDirection = Qt.LeftToRight + // LTR locale + LayoutMirroring + control.locale = Qt.locale("en_US") compare(control.first.visualPosition, 0.75) compare(control.second.visualPosition, 0.0) + // LTR locale control.LayoutMirroring.enabled = false compare(control.first.visualPosition, 0.25) compare(control.second.visualPosition, 1.0) + // LayoutMirroring + control.LayoutMirroring.enabled = true + compare(control.first.visualPosition, 0.75) + compare(control.second.visualPosition, 0.0) + control.destroy() } @@ -545,7 +554,7 @@ TestCase { // RTL control.first.value = 0 - control.layoutDirection = Qt.RightToLeft + control.locale = Qt.locale("ar_EG") mousePress(control, control.first.handle.x, control.first.handle.y, Qt.LeftButton) compare(firstPressedSpy.count, 3) diff --git a/tests/auto/controls/data/tst_slider.qml b/tests/auto/controls/data/tst_slider.qml index e497636c..5957442f 100644 --- a/tests/auto/controls/data/tst_slider.qml +++ b/tests/auto/controls/data/tst_slider.qml @@ -185,18 +185,26 @@ TestCase { compare(control.value, 0.25) compare(control.visualPosition, 0.25) - control.layoutDirection = Qt.RightToLeft + // RTL locale + control.locale = Qt.locale("ar_EG") compare(control.visualPosition, 0.75) + // RTL locale + LayoutMirroring control.LayoutMirroring.enabled = true - compare(control.visualPosition, 0.25) + compare(control.visualPosition, 0.75) - control.layoutDirection = Qt.LeftToRight + // LTR locale + LayoutMirroring + control.locale = Qt.locale("en_US") compare(control.visualPosition, 0.75) + // LTR locale control.LayoutMirroring.enabled = false compare(control.visualPosition, 0.25) + // LayoutMirroring + control.LayoutMirroring.enabled = true + compare(control.visualPosition, 0.75) + control.destroy() } @@ -399,7 +407,7 @@ TestCase { // RTL control.value = 0 - control.layoutDirection = Qt.RightToLeft + control.locale = Qt.locale("ar_EG") mousePress(control, 0, 0, Qt.LeftButton) compare(pressedSpy.count, 3) -- cgit v1.2.3