summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>2016-05-18 15:28:26 +0200
committerJake Petroules <jake.petroules@qt.io>2016-06-14 17:22:55 +0000
commit197471beacf5589802cb91f1ceba59ed99cbb511 (patch)
tree7e0e3d8f6e436de99c5024de5566f42a2504e606 /src/corelib
parentf862946c228f111e9572c6103faf526260fed04d (diff)
darwin: Add Foundation conversion functions for QPoint/QPointF
The fromCGPoint function was left out for QPoint, as the foundation type is using CGFloats internally. Clients should use an explicit QPointF::toPoint() when potentially throwing away precision. Change-Id: I12a37e8f81c86b7ada56066cc18ee29709cc21e3 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com> Reviewed-by: Jake Petroules <jake.petroules@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/kernel/qcore_foundation.mm38
-rw-r--r--src/corelib/tools/qpoint.h13
2 files changed, 51 insertions, 0 deletions
diff --git a/src/corelib/kernel/qcore_foundation.mm b/src/corelib/kernel/qcore_foundation.mm
index a488f4066d..4998b9e35a 100644
--- a/src/corelib/kernel/qcore_foundation.mm
+++ b/src/corelib/kernel/qcore_foundation.mm
@@ -458,5 +458,43 @@ QRectF QRectF::fromCGRect(CGRect rect) Q_DECL_NOTHROW
return QRectF(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
}
+// ----------------------------------------------------------------------------
+
+/*!
+ \since 5.8
+
+ Creates a CGPoint from a QPoint.
+
+ \sa fromCGPoint()
+*/
+CGPoint QPoint::toCGPoint() const Q_DECL_NOTHROW
+{
+ return CGPointMake(x(), y());
+}
+
+/*!
+ \since 5.8
+
+ Creates a CGPoint from a QPointF.
+
+ \sa fromCGPoint()
+*/
+CGPoint QPointF::toCGPoint() const Q_DECL_NOTHROW
+{
+ return CGPointMake(x(), y());
+}
+
+/*!
+ \since 5.8
+
+ Creates a QRectF from a CGPoint.
+
+ \sa toCGPoint()
+*/
+QPointF QPointF::fromCGPoint(CGPoint point) Q_DECL_NOTHROW
+{
+ return QPointF(point.x, point.y);
+}
+
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qpoint.h b/src/corelib/tools/qpoint.h
index 4e2e6b91a6..e2d7f4372a 100644
--- a/src/corelib/tools/qpoint.h
+++ b/src/corelib/tools/qpoint.h
@@ -42,6 +42,10 @@
#include <QtCore/qnamespace.h>
+#if defined(Q_OS_DARWIN)
+struct CGPoint;
+#endif
+
QT_BEGIN_NAMESPACE
@@ -89,6 +93,10 @@ public:
friend Q_DECL_CONSTEXPR inline const QPoint operator-(const QPoint &);
friend Q_DECL_CONSTEXPR inline const QPoint operator/(const QPoint &, qreal);
+#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
+ CGPoint toCGPoint() const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+#endif
+
private:
friend class QTransform;
int xp;
@@ -247,6 +255,11 @@ public:
Q_DECL_CONSTEXPR QPoint toPoint() const;
+#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
+ static QPointF fromCGPoint(CGPoint point) Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+ CGPoint toCGPoint() const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+#endif
+
private:
friend class QMatrix;
friend class QTransform;