aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/doc/src/qmltypereference.qdoc3
-rw-r--r--src/qml/qml/qqmlvaluetype.cpp39
-rw-r--r--src/qml/qml/qqmlvaluetype_p.h18
-rw-r--r--src/qml/qml/qqmlvaluetypewrapper.cpp10
-rw-r--r--tests/auto/qml/qqmlvaluetypes/data/rect_compare.qml4
-rw-r--r--tests/auto/qml/qqmlvaluetypes/data/rect_read.qml4
-rw-r--r--tests/auto/qml/qqmlvaluetypes/data/rectf_compare.qml4
-rw-r--r--tests/auto/qml/qqmlvaluetypes/data/rectf_read.qml4
-rw-r--r--tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp8
9 files changed, 82 insertions, 12 deletions
diff --git a/src/qml/doc/src/qmltypereference.qdoc b/src/qml/doc/src/qmltypereference.qdoc
index 48f7ba1bae..31133c862f 100644
--- a/src/qml/doc/src/qmltypereference.qdoc
+++ b/src/qml/doc/src/qmltypereference.qdoc
@@ -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
diff --git a/src/qml/qml/qqmlvaluetype.cpp b/src/qml/qml/qqmlvaluetype.cpp
index 341ddf802d..b147266080 100644
--- a/src/qml/qml/qqmlvaluetype.cpp
+++ b/src/qml/qml/qqmlvaluetype.cpp
@@ -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
{
diff --git a/src/qml/qml/qqmlvaluetype_p.h b/src/qml/qml/qqmlvaluetype_p.h
index be453ae35a..2c02cc0aa1 100644
--- a/src/qml/qml/qqmlvaluetype_p.h
+++ b/src/qml/qml/qqmlvaluetype_p.h
@@ -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
diff --git a/src/qml/qml/qqmlvaluetypewrapper.cpp b/src/qml/qml/qqmlvaluetypewrapper.cpp
index 67092438a7..e87d9ede77 100644
--- a/src/qml/qml/qqmlvaluetypewrapper.cpp
+++ b/src/qml/qml/qqmlvaluetypewrapper.cpp
@@ -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(')');
}
diff --git a/tests/auto/qml/qqmlvaluetypes/data/rect_compare.qml b/tests/auto/qml/qqmlvaluetypes/data/rect_compare.qml
index c511c2dfc4..104e7ba1e9 100644
--- a/tests/auto/qml/qqmlvaluetypes/data/rect_compare.qml
+++ b/tests/auto/qml/qqmlvaluetypes/data/rect_compare.qml
@@ -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()
diff --git a/tests/auto/qml/qqmlvaluetypes/data/rect_read.qml b/tests/auto/qml/qqmlvaluetypes/data/rect_read.qml
index c3b37a7099..da6deddd75 100644
--- a/tests/auto/qml/qqmlvaluetypes/data/rect_read.qml
+++ b/tests/auto/qml/qqmlvaluetypes/data/rect_read.qml
@@ -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
}
diff --git a/tests/auto/qml/qqmlvaluetypes/data/rectf_compare.qml b/tests/auto/qml/qqmlvaluetypes/data/rectf_compare.qml
index 6ac4049558..eb61755bcf 100644
--- a/tests/auto/qml/qqmlvaluetypes/data/rectf_compare.qml
+++ b/tests/auto/qml/qqmlvaluetypes/data/rectf_compare.qml
@@ -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()
diff --git a/tests/auto/qml/qqmlvaluetypes/data/rectf_read.qml b/tests/auto/qml/qqmlvaluetypes/data/rectf_read.qml
index 6ff3ce30bf..878868254d 100644
--- a/tests/auto/qml/qqmlvaluetypes/data/rectf_read.qml
+++ b/tests/auto/qml/qqmlvaluetypes/data/rectf_read.qml
@@ -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
}
diff --git a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
index 2892e746da..578004b0a1 100644
--- a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
+++ b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
@@ -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;