summaryrefslogtreecommitdiff
path: root/src/positioning/qgeorectangle.h
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@theqtcompany.com>2015-01-05 15:40:59 +0100
committerAlex Blasche <alexander.blasche@theqtcompany.com>2015-01-08 14:07:26 +0100
commit8bf0a15bfc124fbb664592d4c3f29973fc23262e (patch)
tree62d0dc2f89f6631dea511ba591c3b694d2e0e3ce /src/positioning/qgeorectangle.h
parent7765577cca78f1789f8685bea245e93f697fd125 (diff)
downloadqtlocation-8bf0a15bfc124fbb664592d4c3f29973fc23262e.tar.gz
Make QtLocation work after internal valuetype changes in QtQML
The value type wrapper code was completely removed. Instead QGeoShape & derived classes and QGeoCoordinate use Q_GADGET to advertise their meta data which in turn allows QtQML to dynamically discover the types when needed. This implies that the above C++ classes become larger as the meta data is permanently added. On the positive side all QML value type wrapper were removed which reduces the QML plugin size. At the same time it becomes significantly easier to use those types in other QML plugins such as the QtLocation one. Unfortunately this change comes with an unavoidable behavior change as well. Previously is was possible to set a width and height on an invalid QML rectangle. In the case of an invalid rect it was made valid (setting center to 0,0) before setting the height or width. The QGeoRectangle class explicitly aborts calls to setHeight() and setWidth() in case of an invalid rect. From now on the C++ class behavior is used in QML too. This was the reason for the change to tst_map_routing.qml in this patch. Incidentally the documentation always referred to the QGeoRectangle documentation and thus always stated the now new behavior. Documentation for the value types and the relevant behavior changes will be re-added in a later commit. Each Gadget must be registered using QMetaType::registerComparators<T>() to enable == and != operators in QML. Unfortunately QMetaType requires the operator< which does not make any sense for the value types touched by this patch. Right now, a warning is printed. Attempts will be made to remove the operator< requirement in QMetaType. Otherwise the warning has to be removed before the release as they are printed very often. [ChangeLog][QtPositioning][Important Behavior Changes] The QML rectangle type ignores setting of the height and width if the rectangle is invalid. Previously the property setter changed the rectangle center to QGeoCoordinate(0,0) before setting the height and width of a previously invalid rectangle. Change-Id: Iab98ede58066ce03b2b4e0ce03ed85ba7ecb1020 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/positioning/qgeorectangle.h')
-rw-r--r--src/positioning/qgeorectangle.h21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/positioning/qgeorectangle.h b/src/positioning/qgeorectangle.h
index 662c7630..d25456ab 100644
--- a/src/positioning/qgeorectangle.h
+++ b/src/positioning/qgeorectangle.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtPositioning module of the Qt Toolkit.
@@ -43,6 +43,15 @@ class QGeoRectanglePrivate;
class Q_POSITIONING_EXPORT QGeoRectangle : public QGeoShape
{
+ Q_GADGET
+ Q_PROPERTY(QGeoCoordinate bottomLeft READ bottomLeft WRITE setBottomLeft)
+ Q_PROPERTY(QGeoCoordinate bottomRight READ bottomRight WRITE setBottomRight)
+ Q_PROPERTY(QGeoCoordinate topLeft READ topLeft WRITE setTopLeft)
+ Q_PROPERTY(QGeoCoordinate topRight READ topRight WRITE setTopRight)
+ Q_PROPERTY(QGeoCoordinate center READ center WRITE setCenter)
+ Q_PROPERTY(double height READ height WRITE setHeight)
+ Q_PROPERTY(double width READ width WRITE setWidth)
+
public:
QGeoRectangle();
QGeoRectangle(const QGeoCoordinate &center, double degreesWidth, double degreesHeight);
@@ -114,6 +123,8 @@ public:
QGeoRectangle operator|(const QGeoRectangle &rectangle) const;
QGeoRectangle &operator|=(const QGeoRectangle &rectangle);
+ Q_INVOKABLE QString toString() const;
+
private:
inline QGeoRectanglePrivate *d_func();
inline const QGeoRectanglePrivate *d_func() const;
@@ -126,6 +137,14 @@ inline QGeoRectangle QGeoRectangle::operator|(const QGeoRectangle &rectangle) co
return united(rectangle);
}
+// FIXME: Exists to satisfy QMetaType::registerComparators() which is required for
+// QML value type. Remove once QMetaType has been fixed.
+inline bool operator<(const QGeoRectangle &/*lhs*/, const QGeoRectangle &/*rhs*/)
+{
+ qWarning("'<' operator not valid for QGeoRectangle\n");
+ return false;
+}
+
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QGeoRectangle)