From 623bfe209371b6d35d030a66629b58f0f4f27b0d Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Fri, 6 Jul 2012 15:12:41 +0200 Subject: Add unary operator+ to QPoint and QPointF. As requested by Winfried Schenke: "QPoint should have an unary operator+ (the unary operator- exists). Classes with arithmetic operators should provide a complete set of operators, because some template code relies on it." Task-number: QTBUG-22913 Change-Id: Ib0c5105975f56c15f00bb48d83c8d911f5a204ac Reviewed-by: Thiago Macieira Reviewed-by: Marc Mutz --- src/corelib/tools/qpoint.cpp | 16 ++++++++++++++++ src/corelib/tools/qpoint.h | 10 ++++++++++ 2 files changed, 26 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/tools/qpoint.cpp b/src/corelib/tools/qpoint.cpp index 368ef7d697..785e255db5 100644 --- a/src/corelib/tools/qpoint.cpp +++ b/src/corelib/tools/qpoint.cpp @@ -325,6 +325,14 @@ QT_BEGIN_NAMESPACE \sa QPoint::operator*=() */ +/*! + \fn const QPoint operator+(const QPoint &point) + \relates QPoint + \since 5.0 + + Returns \a point unmodified. +*/ + /*! \fn const QPoint operator-(const QPoint &point) \overload @@ -663,6 +671,14 @@ QDebug operator<<(QDebug d, const QPointF &p) Returns a copy of the given \a point, multiplied by the given \a factor. */ +/*! + \fn const QPointF operator+(const QPointF &point) + \relates QPointF + \since 5.0 + + Returns \a point unmodified. +*/ + /*! \fn const QPointF operator-(const QPointF &point) \relates QPointF diff --git a/src/corelib/tools/qpoint.h b/src/corelib/tools/qpoint.h index be9567bc52..dc38ec622a 100644 --- a/src/corelib/tools/qpoint.h +++ b/src/corelib/tools/qpoint.h @@ -86,6 +86,7 @@ public: friend Q_DECL_CONSTEXPR inline const QPoint operator*(double, const QPoint &); friend Q_DECL_CONSTEXPR inline const QPoint operator*(const QPoint &, int); friend Q_DECL_CONSTEXPR inline const QPoint operator*(int, const QPoint &); + friend Q_DECL_CONSTEXPR inline const QPoint operator+(const QPoint &); friend Q_DECL_CONSTEXPR inline const QPoint operator-(const QPoint &); friend Q_DECL_CONSTEXPR inline const QPoint operator/(const QPoint &, qreal); @@ -182,6 +183,9 @@ Q_DECL_CONSTEXPR inline const QPoint operator*(double factor, const QPoint &p) Q_DECL_CONSTEXPR inline const QPoint operator*(int factor, const QPoint &p) { return QPoint(p.xp*factor, p.yp*factor); } +Q_DECL_CONSTEXPR inline const QPoint operator+(const QPoint &p) +{ return p; } + Q_DECL_CONSTEXPR inline const QPoint operator-(const QPoint &p) { return QPoint(-p.xp, -p.yp); } @@ -235,6 +239,7 @@ public: friend Q_DECL_CONSTEXPR inline const QPointF operator-(const QPointF &, const QPointF &); friend Q_DECL_CONSTEXPR inline const QPointF operator*(qreal, const QPointF &); friend Q_DECL_CONSTEXPR inline const QPointF operator*(const QPointF &, qreal); + friend Q_DECL_CONSTEXPR inline const QPointF operator+(const QPointF &); friend Q_DECL_CONSTEXPR inline const QPointF operator-(const QPointF &); friend Q_DECL_CONSTEXPR inline const QPointF operator/(const QPointF &, qreal); @@ -355,6 +360,11 @@ Q_DECL_CONSTEXPR inline const QPointF operator*(qreal c, const QPointF &p) return QPointF(p.xp*c, p.yp*c); } +Q_DECL_CONSTEXPR inline const QPointF operator+(const QPointF &p) +{ + return p; +} + Q_DECL_CONSTEXPR inline const QPointF operator-(const QPointF &p) { return QPointF(-p.xp, -p.yp); -- cgit v1.2.3