Add left, right, top and bottom properties to basic QML rect type.
authorMitch Curtis <mitch.curtis@theqtcompany.com>
Fri, 22 May 2015 11:03:25 +0000 (13:03 +0200)
committerJani Heikkinen <jani.heikkinen@theqtcompany.com>
Wed, 3 Jun 2015 04:29:06 +0000 (04:29 +0000)
Task-number: QTBUG-45528
Task-number: QTBUG-45530
Change-Id: I83c4056b4bde37ef2dc4424ffddd823c1654d92e
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
src/qml/doc/src/qmltypereference.qdoc
src/qml/qml/qqmlvaluetype.cpp
src/qml/qml/qqmlvaluetype_p.h
src/qml/qml/qqmlvaluetypewrapper.cpp
tests/auto/qml/qqmlvaluetypes/data/rect_compare.qml
tests/auto/qml/qqmlvaluetypes/data/rect_read.qml
tests/auto/qml/qqmlvaluetypes/data/rectf_compare.qml
tests/auto/qml/qqmlvaluetypes/data/rectf_read.qml
tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp

index 48f7ba1bae3f3cf624c94fa27b5f02afb1d5b255..31133c862f11f7ea2f81237e492bb29ad2d1888e 100644 (file)
@@ -208,6 +208,9 @@ Or use the \l{QtQml::Qt::rect()}{Qt.rect()} function:
 CustomObject { myRectProperty: Qt.rect(50, 50, 100, 100) }
 \endqml
 
+The \c rect type also exposes read-only \c left, \c right, \c top and \c bottom
+attributes. These are the same as their \l {QRectF}{C++ counterparts}.
+
 When integrating with C++, note that any QRect or QRectF value
 \l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
 converted into a \c rect value, and vice-versa. When a \c rect value is passed to C++, it
index 341ddf802d0607d05ad530c975e6362d8aed82be..b1472660807f29822ef3dde1364c0fda6f424e84 100644 (file)
@@ -388,6 +388,26 @@ void QQmlRectFValueType::setHeight(qreal h)
     v.setHeight(h);
 }
 
+qreal QQmlRectFValueType::left() const
+{
+    return v.left();
+}
+
+qreal QQmlRectFValueType::right() const
+{
+    return v.right();
+}
+
+qreal QQmlRectFValueType::top() const
+{
+    return v.top();
+}
+
+qreal QQmlRectFValueType::bottom() const
+{
+    return v.bottom();
+}
+
 int QQmlRectValueType::x() const
 {
     return v.x();
@@ -428,6 +448,25 @@ void QQmlRectValueType::setHeight(int h)
     v.setHeight(h);
 }
 
+int QQmlRectValueType::left() const
+{
+    return v.left();
+}
+
+int QQmlRectValueType::right() const
+{
+    return v.right();
+}
+
+int QQmlRectValueType::top() const
+{
+    return v.top();
+}
+
+int QQmlRectValueType::bottom() const
+{
+    return v.bottom();
+}
 
 QQmlEasingValueType::Type QQmlEasingValueType::type() const
 {
index be453ae35a6ee3c301baed9a1bce46556477be05..2c02cc0aa152ff05f3646181daf47bfc3bc12854 100644 (file)
@@ -153,6 +153,10 @@ struct QQmlRectFValueType
     Q_PROPERTY(qreal y READ y WRITE setY FINAL)
     Q_PROPERTY(qreal width READ width WRITE setWidth FINAL)
     Q_PROPERTY(qreal height READ height WRITE setHeight FINAL)
+    Q_PROPERTY(qreal left READ left DESIGNABLE false FINAL)
+    Q_PROPERTY(qreal right READ right DESIGNABLE false FINAL)
+    Q_PROPERTY(qreal top READ top DESIGNABLE false FINAL)
+    Q_PROPERTY(qreal bottom READ bottom DESIGNABLE false FINAL)
     Q_GADGET
 public:
     Q_INVOKABLE QString toString() const;
@@ -165,6 +169,11 @@ public:
     qreal height() const;
     void setWidth(qreal);
     void setHeight(qreal);
+
+    qreal left() const;
+    qreal right() const;
+    qreal top() const;
+    qreal bottom() const;
 };
 
 struct QQmlRectValueType
@@ -174,6 +183,10 @@ struct QQmlRectValueType
     Q_PROPERTY(int y READ y WRITE setY FINAL)
     Q_PROPERTY(int width READ width WRITE setWidth FINAL)
     Q_PROPERTY(int height READ height WRITE setHeight FINAL)
+    Q_PROPERTY(int left READ left DESIGNABLE false FINAL)
+    Q_PROPERTY(int right READ right DESIGNABLE false FINAL)
+    Q_PROPERTY(int top READ top DESIGNABLE false FINAL)
+    Q_PROPERTY(int bottom READ bottom DESIGNABLE false FINAL)
     Q_GADGET
 public:
     int x() const;
@@ -185,6 +198,11 @@ public:
     int height() const;
     void setWidth(int);
     void setHeight(int);
+
+    int left() const;
+    int right() const;
+    int top() const;
+    int bottom() const;
 };
 
 struct QQmlEasingValueType
index 67092438a7282f49b4959d246a90b0b99a0a445a..e87d9ede77c9e247c820aeda4f6a1c2889b6458f 100644 (file)
@@ -315,10 +315,12 @@ ReturnedValue QQmlValueTypeWrapper::method_toString(CallContext *ctx)
         const QMetaObject *mo = w->d()->propertyCache->metaObject();
         const int propCount = mo->propertyCount();
         for (int i = 0; i < propCount; ++i) {
-            QVariant value = mo->property(i).readOnGadget(w->d()->gadgetPtr);
-            result += value.toString();
-            if (i < propCount - 1)
-                result += QStringLiteral(", ");
+            if (mo->property(i).isDesignable()) {
+                QVariant value = mo->property(i).readOnGadget(w->d()->gadgetPtr);
+                if (i > 0)
+                    result += QLatin1String(", ");
+                result += value.toString();
+            }
         }
         result += QLatin1Char(')');
     }
index c511c2dfc446ea2e269fa7cabce37df663b56351..104e7ba1e9729f3b861b2bf060df530c0cb444bd 100644 (file)
@@ -1,10 +1,6 @@
 import Test 1.0
 
 MyTypeObject {
-    property int r_x: rect.x
-    property int r_y: rect.y
-    property int r_width: rect.width
-    property int r_height: rect.height
     property variant copy: rect
     property string tostring: rect.toString()
 
index c3b37a7099d8d3892cc18dcbb97654f8760ccc8e..da6deddd75bad13c7e937ff3c02c31969b505fe0 100644 (file)
@@ -5,6 +5,10 @@ MyTypeObject {
     property int r_y: rect.y
     property int r_width: rect.width
     property int r_height: rect.height
+    property int r_left: rect.left
+    property int r_right: rect.right
+    property int r_top: rect.top
+    property int r_bottom: rect.bottom
     property variant copy: rect
 }
 
index 6ac4049558a34dae4cf2bcbb764ff7f707850dea..eb61755bcffcc6201438ae6cfc3c2ddb80ab6d8a 100644 (file)
@@ -1,10 +1,6 @@
 import Test 1.0
 
 MyTypeObject {
-    property real r_x: rectf.x
-    property real r_y: rectf.y
-    property real r_width: rectf.width
-    property real r_height: rectf.height
     property variant copy: rectf
     property string tostring: rectf.toString()
 
index 6ff3ce30bf2bb02bc93d7a3b60a7278e3e2c2bf3..878868254d7c1172a4f8ed29865f547df499c87e 100644 (file)
@@ -5,6 +5,10 @@ MyTypeObject {
     property real r_y: rectf.y
     property real r_width: rectf.width
     property real r_height: rectf.height
+    property real r_left: rectf.left
+    property real r_right: rectf.right
+    property real r_top: rectf.top
+    property real r_bottom: rectf.bottom
     property variant copy: rectf
 }
 
index 2892e746da5763a82f615c77e03c43aabc0e97bf..578004b0a15e3330951adbe82007db634da559b9 100644 (file)
@@ -371,6 +371,10 @@ void tst_qqmlvaluetypes::rect()
         QCOMPARE(object->property("r_y").toInt(), 3);
         QCOMPARE(object->property("r_width").toInt(), 109);
         QCOMPARE(object->property("r_height").toInt(), 102);
+        QCOMPARE(object->property("r_left").toInt(), 2);
+        QCOMPARE(object->property("r_right").toInt(), 110);
+        QCOMPARE(object->property("r_top").toInt(), 3);
+        QCOMPARE(object->property("r_bottom").toInt(), 104);
         QCOMPARE(object->property("copy"), QVariant(QRect(2, 3, 109, 102)));
 
         delete object;
@@ -418,6 +422,10 @@ void tst_qqmlvaluetypes::rectf()
         QCOMPARE(float(object->property("r_y").toDouble()), float(99.2));
         QCOMPARE(float(object->property("r_width").toDouble()), float(88.1));
         QCOMPARE(float(object->property("r_height").toDouble()), float(77.6));
+        QCOMPARE(float(object->property("r_left").toDouble()), float(103.8));
+        QCOMPARE(float(object->property("r_right").toDouble()), float(191.9));
+        QCOMPARE(float(object->property("r_top").toDouble()), float(99.2));
+        QCOMPARE(float(object->property("r_bottom").toDouble()), float(176.8));
         QCOMPARE(object->property("copy"), QVariant(QRectF(103.8, 99.2, 88.1, 77.6)));
 
         delete object;