diff options
author | Mitch Curtis <mitch.curtis@theqtcompany.com> | 2015-05-22 13:03:25 +0200 |
---|---|---|
committer | Jani Heikkinen <jani.heikkinen@theqtcompany.com> | 2015-06-03 04:29:06 +0000 |
commit | db9be0a9d6195bc52415ce28d605ace149d02782 (patch) | |
tree | a1b0dd262e53a08f7015efc8fb8a32ad0b82db9e /src | |
parent | db525935ccd64d2c5c674f8a66dbe7096d754e9f (diff) |
Add left, right, top and bottom properties to basic QML rect type.
Task-number: QTBUG-45528
Task-number: QTBUG-45530
Change-Id: I83c4056b4bde37ef2dc4424ffddd823c1654d92e
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/doc/src/qmltypereference.qdoc | 3 | ||||
-rw-r--r-- | src/qml/qml/qqmlvaluetype.cpp | 39 | ||||
-rw-r--r-- | src/qml/qml/qqmlvaluetype_p.h | 18 | ||||
-rw-r--r-- | src/qml/qml/qqmlvaluetypewrapper.cpp | 10 |
4 files changed, 66 insertions, 4 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(')'); } |