summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2012-02-17 12:02:14 +0100
committerQt by Nokia <qt-info@nokia.com>2012-02-22 00:07:31 +0100
commitf3141c58badbd2da9eb42021e9704742c3e52a9b (patch)
treeb8b45bc1639ddeceac9d2fb326944a895794bd6b /src/corelib/tools
parent4c577aead97abb4e22fedcf57cb9aea6c5bfa623 (diff)
QtCore: add constexpr to geometric classes
This turns code like QPoint(12, 12) into a compile-time expression, under a C++11 compiler, and allows to define arrays of these types that end up in read-only memory, just like PODs would. Some constructors and QLine::pointAt() needed to be adjusted to fit into the empty-body/only-return-expression requirement for constexpr constructors/functions. Change-Id: Id11ee2752c948930c3e40a91d1f6d7c97db7a373 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qline.h142
-rw-r--r--src/corelib/tools/qmargins.h37
-rw-r--r--src/corelib/tools/qpoint.h134
-rw-r--r--src/corelib/tools/qrect.h242
-rw-r--r--src/corelib/tools/qsize.h139
5 files changed, 331 insertions, 363 deletions
diff --git a/src/corelib/tools/qline.h b/src/corelib/tools/qline.h
index 58ef0316ad..92ea4ea426 100644
--- a/src/corelib/tools/qline.h
+++ b/src/corelib/tools/qline.h
@@ -56,37 +56,37 @@ QT_BEGIN_NAMESPACE
class Q_CORE_EXPORT QLine
{
public:
- inline QLine();
- inline QLine(const QPoint &pt1, const QPoint &pt2);
- inline QLine(int x1, int y1, int x2, int y2);
+ Q_DECL_CONSTEXPR inline QLine();
+ Q_DECL_CONSTEXPR inline QLine(const QPoint &pt1, const QPoint &pt2);
+ Q_DECL_CONSTEXPR inline QLine(int x1, int y1, int x2, int y2);
- inline bool isNull() const;
+ Q_DECL_CONSTEXPR inline bool isNull() const;
- inline QPoint p1() const;
- inline QPoint p2() const;
+ Q_DECL_CONSTEXPR inline QPoint p1() const;
+ Q_DECL_CONSTEXPR inline QPoint p2() const;
- inline int x1() const;
- inline int y1() const;
+ Q_DECL_CONSTEXPR inline int x1() const;
+ Q_DECL_CONSTEXPR inline int y1() const;
- inline int x2() const;
- inline int y2() const;
+ Q_DECL_CONSTEXPR inline int x2() const;
+ Q_DECL_CONSTEXPR inline int y2() const;
- inline int dx() const;
- inline int dy() const;
+ Q_DECL_CONSTEXPR inline int dx() const;
+ Q_DECL_CONSTEXPR inline int dy() const;
inline void translate(const QPoint &p);
inline void translate(int dx, int dy);
- inline QLine translated(const QPoint &p) const;
- inline QLine translated(int dx, int dy) const;
+ Q_DECL_CONSTEXPR inline QLine translated(const QPoint &p) const;
+ Q_DECL_CONSTEXPR inline QLine translated(int dx, int dy) const;
inline void setP1(const QPoint &p1);
inline void setP2(const QPoint &p2);
inline void setPoints(const QPoint &p1, const QPoint &p2);
inline void setLine(int x1, int y1, int x2, int y2);
- inline bool operator==(const QLine &d) const;
- inline bool operator!=(const QLine &d) const { return !(*this == d); }
+ Q_DECL_CONSTEXPR inline bool operator==(const QLine &d) const;
+ Q_DECL_CONSTEXPR inline bool operator!=(const QLine &d) const { return !(*this == d); }
private:
QPoint pt1, pt2;
@@ -97,53 +97,53 @@ Q_DECLARE_TYPEINFO(QLine, Q_MOVABLE_TYPE);
* class QLine inline members
*******************************************************************************/
-inline QLine::QLine() { }
+Q_DECL_CONSTEXPR inline QLine::QLine() { }
-inline QLine::QLine(const QPoint &pt1_, const QPoint &pt2_) : pt1(pt1_), pt2(pt2_) { }
+Q_DECL_CONSTEXPR inline QLine::QLine(const QPoint &pt1_, const QPoint &pt2_) : pt1(pt1_), pt2(pt2_) { }
-inline QLine::QLine(int x1pos, int y1pos, int x2pos, int y2pos) : pt1(QPoint(x1pos, y1pos)), pt2(QPoint(x2pos, y2pos)) { }
+Q_DECL_CONSTEXPR inline QLine::QLine(int x1pos, int y1pos, int x2pos, int y2pos) : pt1(QPoint(x1pos, y1pos)), pt2(QPoint(x2pos, y2pos)) { }
-inline bool QLine::isNull() const
+Q_DECL_CONSTEXPR inline bool QLine::isNull() const
{
return pt1 == pt2;
}
-inline int QLine::x1() const
+Q_DECL_CONSTEXPR inline int QLine::x1() const
{
return pt1.x();
}
-inline int QLine::y1() const
+Q_DECL_CONSTEXPR inline int QLine::y1() const
{
return pt1.y();
}
-inline int QLine::x2() const
+Q_DECL_CONSTEXPR inline int QLine::x2() const
{
return pt2.x();
}
-inline int QLine::y2() const
+Q_DECL_CONSTEXPR inline int QLine::y2() const
{
return pt2.y();
}
-inline QPoint QLine::p1() const
+Q_DECL_CONSTEXPR inline QPoint QLine::p1() const
{
return pt1;
}
-inline QPoint QLine::p2() const
+Q_DECL_CONSTEXPR inline QPoint QLine::p2() const
{
return pt2;
}
-inline int QLine::dx() const
+Q_DECL_CONSTEXPR inline int QLine::dx() const
{
return pt2.x() - pt1.x();
}
-inline int QLine::dy() const
+Q_DECL_CONSTEXPR inline int QLine::dy() const
{
return pt2.y() - pt1.y();
}
@@ -159,12 +159,12 @@ inline void QLine::translate(int adx, int ady)
this->translate(QPoint(adx, ady));
}
-inline QLine QLine::translated(const QPoint &p) const
+Q_DECL_CONSTEXPR inline QLine QLine::translated(const QPoint &p) const
{
return QLine(pt1 + p, pt2 + p);
}
-inline QLine QLine::translated(int adx, int ady) const
+Q_DECL_CONSTEXPR inline QLine QLine::translated(int adx, int ady) const
{
return translated(QPoint(adx, ady));
}
@@ -191,7 +191,7 @@ inline void QLine::setLine(int aX1, int aY1, int aX2, int aY2)
pt2 = QPoint(aX2, aY2);
}
-inline bool QLine::operator==(const QLine &d) const
+Q_DECL_CONSTEXPR inline bool QLine::operator==(const QLine &d) const
{
return pt1 == d.pt1 && pt2 == d.pt2;
}
@@ -213,26 +213,26 @@ public:
enum IntersectType { NoIntersection, BoundedIntersection, UnboundedIntersection };
- inline QLineF();
- inline QLineF(const QPointF &pt1, const QPointF &pt2);
- inline QLineF(qreal x1, qreal y1, qreal x2, qreal y2);
- inline QLineF(const QLine &line) : pt1(line.p1()), pt2(line.p2()) { }
+ Q_DECL_CONSTEXPR inline QLineF();
+ Q_DECL_CONSTEXPR inline QLineF(const QPointF &pt1, const QPointF &pt2);
+ Q_DECL_CONSTEXPR inline QLineF(qreal x1, qreal y1, qreal x2, qreal y2);
+ Q_DECL_CONSTEXPR inline QLineF(const QLine &line) : pt1(line.p1()), pt2(line.p2()) { }
static QLineF fromPolar(qreal length, qreal angle);
- bool isNull() const;
+ Q_DECL_CONSTEXPR bool isNull() const;
- inline QPointF p1() const;
- inline QPointF p2() const;
+ Q_DECL_CONSTEXPR inline QPointF p1() const;
+ Q_DECL_CONSTEXPR inline QPointF p2() const;
- inline qreal x1() const;
- inline qreal y1() const;
+ Q_DECL_CONSTEXPR inline qreal x1() const;
+ Q_DECL_CONSTEXPR inline qreal y1() const;
- inline qreal x2() const;
- inline qreal y2() const;
+ Q_DECL_CONSTEXPR inline qreal x2() const;
+ Q_DECL_CONSTEXPR inline qreal y2() const;
- inline qreal dx() const;
- inline qreal dy() const;
+ Q_DECL_CONSTEXPR inline qreal dx() const;
+ Q_DECL_CONSTEXPR inline qreal dy() const;
qreal length() const;
void setLength(qreal len);
@@ -243,29 +243,29 @@ public:
qreal angleTo(const QLineF &l) const;
QLineF unitVector() const;
- QLineF normalVector() const;
+ Q_DECL_CONSTEXPR inline QLineF normalVector() const;
// ### Qt 5: rename intersects() or intersection() and rename IntersectType IntersectionType
IntersectType intersect(const QLineF &l, QPointF *intersectionPoint) const;
qreal angle(const QLineF &l) const;
- QPointF pointAt(qreal t) const;
+ Q_DECL_CONSTEXPR inline QPointF pointAt(qreal t) const;
inline void translate(const QPointF &p);
inline void translate(qreal dx, qreal dy);
- inline QLineF translated(const QPointF &p) const;
- inline QLineF translated(qreal dx, qreal dy) const;
+ Q_DECL_CONSTEXPR inline QLineF translated(const QPointF &p) const;
+ Q_DECL_CONSTEXPR inline QLineF translated(qreal dx, qreal dy) const;
inline void setP1(const QPointF &p1);
inline void setP2(const QPointF &p2);
inline void setPoints(const QPointF &p1, const QPointF &p2);
inline void setLine(qreal x1, qreal y1, qreal x2, qreal y2);
- inline bool operator==(const QLineF &d) const;
- inline bool operator!=(const QLineF &d) const { return !(*this == d); }
+ Q_DECL_CONSTEXPR inline bool operator==(const QLineF &d) const;
+ Q_DECL_CONSTEXPR inline bool operator!=(const QLineF &d) const { return !(*this == d); }
- QLine toLine() const;
+ Q_DECL_CONSTEXPR QLine toLine() const;
private:
QPointF pt1, pt2;
@@ -276,66 +276,66 @@ Q_DECLARE_TYPEINFO(QLineF, Q_MOVABLE_TYPE);
* class QLineF inline members
*******************************************************************************/
-inline QLineF::QLineF()
+Q_DECL_CONSTEXPR inline QLineF::QLineF()
{
}
-inline QLineF::QLineF(const QPointF &apt1, const QPointF &apt2)
+Q_DECL_CONSTEXPR inline QLineF::QLineF(const QPointF &apt1, const QPointF &apt2)
: pt1(apt1), pt2(apt2)
{
}
-inline QLineF::QLineF(qreal x1pos, qreal y1pos, qreal x2pos, qreal y2pos)
+Q_DECL_CONSTEXPR inline QLineF::QLineF(qreal x1pos, qreal y1pos, qreal x2pos, qreal y2pos)
: pt1(x1pos, y1pos), pt2(x2pos, y2pos)
{
}
-inline qreal QLineF::x1() const
+Q_DECL_CONSTEXPR inline qreal QLineF::x1() const
{
return pt1.x();
}
-inline qreal QLineF::y1() const
+Q_DECL_CONSTEXPR inline qreal QLineF::y1() const
{
return pt1.y();
}
-inline qreal QLineF::x2() const
+Q_DECL_CONSTEXPR inline qreal QLineF::x2() const
{
return pt2.x();
}
-inline qreal QLineF::y2() const
+Q_DECL_CONSTEXPR inline qreal QLineF::y2() const
{
return pt2.y();
}
-inline bool QLineF::isNull() const
+Q_DECL_CONSTEXPR inline bool QLineF::isNull() const
{
return qFuzzyCompare(pt1.x(), pt2.x()) && qFuzzyCompare(pt1.y(), pt2.y());
}
-inline QPointF QLineF::p1() const
+Q_DECL_CONSTEXPR inline QPointF QLineF::p1() const
{
return pt1;
}
-inline QPointF QLineF::p2() const
+Q_DECL_CONSTEXPR inline QPointF QLineF::p2() const
{
return pt2;
}
-inline qreal QLineF::dx() const
+Q_DECL_CONSTEXPR inline qreal QLineF::dx() const
{
return pt2.x() - pt1.x();
}
-inline qreal QLineF::dy() const
+Q_DECL_CONSTEXPR inline qreal QLineF::dy() const
{
return pt2.y() - pt1.y();
}
-inline QLineF QLineF::normalVector() const
+Q_DECL_CONSTEXPR inline QLineF QLineF::normalVector() const
{
return QLineF(p1(), p1() + QPointF(dy(), -dx()));
}
@@ -351,12 +351,12 @@ inline void QLineF::translate(qreal adx, qreal ady)
this->translate(QPointF(adx, ady));
}
-inline QLineF QLineF::translated(const QPointF &p) const
+Q_DECL_CONSTEXPR inline QLineF QLineF::translated(const QPointF &p) const
{
return QLineF(pt1 + p, pt2 + p);
}
-inline QLineF QLineF::translated(qreal adx, qreal ady) const
+Q_DECL_CONSTEXPR inline QLineF QLineF::translated(qreal adx, qreal ady) const
{
return translated(QPointF(adx, ady));
}
@@ -369,14 +369,12 @@ inline void QLineF::setLength(qreal len)
pt2 = QPointF(pt1.x() + v.dx() * len, pt1.y() + v.dy() * len);
}
-inline QPointF QLineF::pointAt(qreal t) const
+Q_DECL_CONSTEXPR inline QPointF QLineF::pointAt(qreal t) const
{
- qreal vx = pt2.x() - pt1.x();
- qreal vy = pt2.y() - pt1.y();
- return QPointF(pt1.x() + vx * t, pt1.y() + vy * t);
+ return QPointF(pt1.x() + (pt2.x() - pt1.x()) * t, pt1.y() + (pt2.y() - pt1.y()) * t);
}
-inline QLine QLineF::toLine() const
+Q_DECL_CONSTEXPR inline QLine QLineF::toLine() const
{
return QLine(pt1.toPoint(), pt2.toPoint());
}
@@ -405,7 +403,7 @@ inline void QLineF::setLine(qreal aX1, qreal aY1, qreal aX2, qreal aY2)
}
-inline bool QLineF::operator==(const QLineF &d) const
+Q_DECL_CONSTEXPR inline bool QLineF::operator==(const QLineF &d) const
{
return pt1 == d.pt1 && pt2 == d.pt2;
}
diff --git a/src/corelib/tools/qmargins.h b/src/corelib/tools/qmargins.h
index 7d9d07ed46..d3551fa195 100644
--- a/src/corelib/tools/qmargins.h
+++ b/src/corelib/tools/qmargins.h
@@ -52,15 +52,15 @@ QT_BEGIN_NAMESPACE
class QMargins
{
public:
- QMargins();
- QMargins(int left, int top, int right, int bottom);
+ Q_DECL_CONSTEXPR QMargins();
+ Q_DECL_CONSTEXPR QMargins(int left, int top, int right, int bottom);
- bool isNull() const;
+ Q_DECL_CONSTEXPR bool isNull() const;
- int left() const;
- int top() const;
- int right() const;
- int bottom() const;
+ Q_DECL_CONSTEXPR int left() const;
+ Q_DECL_CONSTEXPR int top() const;
+ Q_DECL_CONSTEXPR int right() const;
+ Q_DECL_CONSTEXPR int bottom() const;
void setLeft(int left);
void setTop(int top);
@@ -73,8 +73,8 @@ private:
int m_right;
int m_bottom;
- friend inline bool operator==(const QMargins &, const QMargins &);
- friend inline bool operator!=(const QMargins &, const QMargins &);
+ friend Q_DECL_CONSTEXPR inline bool operator==(const QMargins &, const QMargins &);
+ friend Q_DECL_CONSTEXPR inline bool operator!=(const QMargins &, const QMargins &);
};
Q_DECLARE_TYPEINFO(QMargins, Q_MOVABLE_TYPE);
@@ -91,25 +91,24 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QMargins &);
QMargins inline functions
*****************************************************************************/
-inline QMargins::QMargins()
-{ m_top = m_bottom = m_left = m_right = 0; }
+Q_DECL_CONSTEXPR inline QMargins::QMargins() : m_left(0), m_top(0), m_right(0), m_bottom(0) {}
-inline QMargins::QMargins(int aleft, int atop, int aright, int abottom)
+Q_DECL_CONSTEXPR inline QMargins::QMargins(int aleft, int atop, int aright, int abottom)
: m_left(aleft), m_top(atop), m_right(aright), m_bottom(abottom) {}
-inline bool QMargins::isNull() const
+Q_DECL_CONSTEXPR inline bool QMargins::isNull() const
{ return m_left==0 && m_top==0 && m_right==0 && m_bottom==0; }
-inline int QMargins::left() const
+Q_DECL_CONSTEXPR inline int QMargins::left() const
{ return m_left; }
-inline int QMargins::top() const
+Q_DECL_CONSTEXPR inline int QMargins::top() const
{ return m_top; }
-inline int QMargins::right() const
+Q_DECL_CONSTEXPR inline int QMargins::right() const
{ return m_right; }
-inline int QMargins::bottom() const
+Q_DECL_CONSTEXPR inline int QMargins::bottom() const
{ return m_bottom; }
@@ -125,7 +124,7 @@ inline void QMargins::setRight(int aright)
inline void QMargins::setBottom(int abottom)
{ m_bottom = abottom; }
-inline bool operator==(const QMargins &m1, const QMargins &m2)
+Q_DECL_CONSTEXPR inline bool operator==(const QMargins &m1, const QMargins &m2)
{
return
m1.m_left == m2.m_left &&
@@ -134,7 +133,7 @@ inline bool operator==(const QMargins &m1, const QMargins &m2)
m1.m_bottom == m2.m_bottom;
}
-inline bool operator!=(const QMargins &m1, const QMargins &m2)
+Q_DECL_CONSTEXPR inline bool operator!=(const QMargins &m1, const QMargins &m2)
{
return
m1.m_left != m2.m_left ||
diff --git a/src/corelib/tools/qpoint.h b/src/corelib/tools/qpoint.h
index 2e987fcf41..0eb22807e8 100644
--- a/src/corelib/tools/qpoint.h
+++ b/src/corelib/tools/qpoint.h
@@ -52,17 +52,17 @@ QT_BEGIN_NAMESPACE
class Q_CORE_EXPORT QPoint
{
public:
- QPoint();
- QPoint(int xpos, int ypos);
+ Q_DECL_CONSTEXPR QPoint();
+ Q_DECL_CONSTEXPR QPoint(int xpos, int ypos);
- bool isNull() const;
+ Q_DECL_CONSTEXPR bool isNull() const;
- int x() const;
- int y() const;
+ Q_DECL_CONSTEXPR int x() const;
+ Q_DECL_CONSTEXPR int y() const;
void setX(int x);
void setY(int y);
- int manhattanLength() const;
+ Q_DECL_CONSTEXPR int manhattanLength() const;
int &rx();
int &ry();
@@ -76,18 +76,18 @@ public:
QPoint &operator/=(qreal c);
- friend inline bool operator==(const QPoint &, const QPoint &);
- friend inline bool operator!=(const QPoint &, const QPoint &);
- friend inline const QPoint operator+(const QPoint &, const QPoint &);
- friend inline const QPoint operator-(const QPoint &, const QPoint &);
- friend inline const QPoint operator*(const QPoint &, float);
- friend inline const QPoint operator*(float, const QPoint &);
- friend inline const QPoint operator*(const QPoint &, double);
- friend inline const QPoint operator*(double, const QPoint &);
- friend inline const QPoint operator*(const QPoint &, int);
- friend inline const QPoint operator*(int, const QPoint &);
- friend inline const QPoint operator-(const QPoint &);
- friend inline const QPoint operator/(const QPoint &, qreal);
+ friend Q_DECL_CONSTEXPR inline bool operator==(const QPoint &, const QPoint &);
+ friend Q_DECL_CONSTEXPR inline bool operator!=(const QPoint &, const QPoint &);
+ friend Q_DECL_CONSTEXPR inline const QPoint operator+(const QPoint &, const QPoint &);
+ friend Q_DECL_CONSTEXPR inline const QPoint operator-(const QPoint &, const QPoint &);
+ friend Q_DECL_CONSTEXPR inline const QPoint operator*(const QPoint &, float);
+ friend Q_DECL_CONSTEXPR inline const QPoint operator*(float, const QPoint &);
+ friend Q_DECL_CONSTEXPR inline const QPoint operator*(const QPoint &, double);
+ 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 &, qreal);
private:
friend class QTransform;
@@ -109,19 +109,17 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QPoint &);
QPoint inline functions
*****************************************************************************/
-inline QPoint::QPoint()
-{ xp=0; yp=0; }
+Q_DECL_CONSTEXPR inline QPoint::QPoint() : xp(0), yp(0) {}
-inline QPoint::QPoint(int xpos, int ypos)
-{ xp = xpos; yp = ypos; }
+Q_DECL_CONSTEXPR inline QPoint::QPoint(int xpos, int ypos) : xp(xpos), yp(ypos) {}
-inline bool QPoint::isNull() const
+Q_DECL_CONSTEXPR inline bool QPoint::isNull() const
{ return xp == 0 && yp == 0; }
-inline int QPoint::x() const
+Q_DECL_CONSTEXPR inline int QPoint::x() const
{ return xp; }
-inline int QPoint::y() const
+Q_DECL_CONSTEXPR inline int QPoint::y() const
{ return yp; }
inline void QPoint::setX(int xpos)
@@ -130,7 +128,7 @@ inline void QPoint::setX(int xpos)
inline void QPoint::setY(int ypos)
{ yp = ypos; }
-inline int QPoint::manhattanLength() const
+inline int Q_DECL_CONSTEXPR QPoint::manhattanLength() const
{ return qAbs(x())+qAbs(y()); }
inline int &QPoint::rx()
@@ -154,37 +152,37 @@ inline QPoint &QPoint::operator*=(double c)
inline QPoint &QPoint::operator*=(int c)
{ xp = xp*c; yp = yp*c; return *this; }
-inline bool operator==(const QPoint &p1, const QPoint &p2)
+Q_DECL_CONSTEXPR inline bool operator==(const QPoint &p1, const QPoint &p2)
{ return p1.xp == p2.xp && p1.yp == p2.yp; }
-inline bool operator!=(const QPoint &p1, const QPoint &p2)
+Q_DECL_CONSTEXPR inline bool operator!=(const QPoint &p1, const QPoint &p2)
{ return p1.xp != p2.xp || p1.yp != p2.yp; }
-inline const QPoint operator+(const QPoint &p1, const QPoint &p2)
+Q_DECL_CONSTEXPR inline const QPoint operator+(const QPoint &p1, const QPoint &p2)
{ return QPoint(p1.xp+p2.xp, p1.yp+p2.yp); }
-inline const QPoint operator-(const QPoint &p1, const QPoint &p2)
+Q_DECL_CONSTEXPR inline const QPoint operator-(const QPoint &p1, const QPoint &p2)
{ return QPoint(p1.xp-p2.xp, p1.yp-p2.yp); }
-inline const QPoint operator*(const QPoint &p, float c)
+Q_DECL_CONSTEXPR inline const QPoint operator*(const QPoint &p, float c)
{ return QPoint(qRound(p.xp*c), qRound(p.yp*c)); }
-inline const QPoint operator*(const QPoint &p, double c)
+Q_DECL_CONSTEXPR inline const QPoint operator*(const QPoint &p, double c)
{ return QPoint(qRound(p.xp*c), qRound(p.yp*c)); }
-inline const QPoint operator*(const QPoint &p, int c)
+Q_DECL_CONSTEXPR inline const QPoint operator*(const QPoint &p, int c)
{ return QPoint(p.xp*c, p.yp*c); }
-inline const QPoint operator*(float c, const QPoint &p)
+Q_DECL_CONSTEXPR inline const QPoint operator*(float c, const QPoint &p)
{ return QPoint(qRound(p.xp*c), qRound(p.yp*c)); }
-inline const QPoint operator*(double c, const QPoint &p)
+Q_DECL_CONSTEXPR inline const QPoint operator*(double c, const QPoint &p)
{ return QPoint(qRound(p.xp*c), qRound(p.yp*c)); }
-inline const QPoint operator*(int c, const QPoint &p)
+Q_DECL_CONSTEXPR inline const QPoint operator*(int c, const QPoint &p)
{ return QPoint(p.xp*c, p.yp*c); }
-inline const QPoint operator-(const QPoint &p)
+Q_DECL_CONSTEXPR inline const QPoint operator-(const QPoint &p)
{ return QPoint(-p.xp, -p.yp); }
inline QPoint &QPoint::operator/=(qreal c)
@@ -194,7 +192,7 @@ inline QPoint &QPoint::operator/=(qreal c)
return *this;
}
-inline const QPoint operator/(const QPoint &p, qreal c)
+Q_DECL_CONSTEXPR inline const QPoint operator/(const QPoint &p, qreal c)
{
return QPoint(qRound(p.xp/c), qRound(p.yp/c));
}
@@ -210,16 +208,16 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QPoint &);
class Q_CORE_EXPORT QPointF
{
public:
- QPointF();
- QPointF(const QPoint &p);
- QPointF(qreal xpos, qreal ypos);
+ Q_DECL_CONSTEXPR QPointF();
+ Q_DECL_CONSTEXPR QPointF(const QPoint &p);
+ Q_DECL_CONSTEXPR QPointF(qreal xpos, qreal ypos);
- qreal manhattanLength() const;
+ Q_DECL_CONSTEXPR qreal manhattanLength() const;
bool isNull() const;
- qreal x() const;
- qreal y() const;
+ Q_DECL_CONSTEXPR qreal x() const;
+ Q_DECL_CONSTEXPR qreal y() const;
void setX(qreal x);
void setY(qreal y);
@@ -231,16 +229,16 @@ public:
QPointF &operator*=(qreal c);
QPointF &operator/=(qreal c);
- friend inline bool operator==(const QPointF &, const QPointF &);
- friend inline bool operator!=(const QPointF &, const QPointF &);
- friend inline const QPointF operator+(const QPointF &, const QPointF &);
- friend inline const QPointF operator-(const QPointF &, const QPointF &);
- friend inline const QPointF operator*(qreal, const QPointF &);
- friend inline const QPointF operator*(const QPointF &, qreal);
- friend inline const QPointF operator-(const QPointF &);
- friend inline const QPointF operator/(const QPointF &, qreal);
+ friend Q_DECL_CONSTEXPR inline bool operator==(const QPointF &, const QPointF &);
+ friend Q_DECL_CONSTEXPR inline bool operator!=(const QPointF &, const QPointF &);
+ friend Q_DECL_CONSTEXPR inline const QPointF operator+(const QPointF &, const QPointF &);
+ 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 &, qreal);
- QPoint toPoint() const;
+ Q_DECL_CONSTEXPR QPoint toPoint() const;
private:
friend class QMatrix;
@@ -264,13 +262,13 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QPointF &);
QPointF inline functions
*****************************************************************************/
-inline QPointF::QPointF() : xp(0), yp(0) { }
+Q_DECL_CONSTEXPR inline QPointF::QPointF() : xp(0), yp(0) { }
-inline QPointF::QPointF(qreal xpos, qreal ypos) : xp(xpos), yp(ypos) { }
+Q_DECL_CONSTEXPR inline QPointF::QPointF(qreal xpos, qreal ypos) : xp(xpos), yp(ypos) { }
-inline QPointF::QPointF(const QPoint &p) : xp(p.x()), yp(p.y()) { }
+Q_DECL_CONSTEXPR inline QPointF::QPointF(const QPoint &p) : xp(p.x()), yp(p.y()) { }
-inline qreal QPointF::manhattanLength() const
+Q_DECL_CONSTEXPR inline qreal QPointF::manhattanLength() const
{
return qAbs(x())+qAbs(y());
}
@@ -280,12 +278,12 @@ inline bool QPointF::isNull() const
return qIsNull(xp) && qIsNull(yp);
}
-inline qreal QPointF::x() const
+Q_DECL_CONSTEXPR inline qreal QPointF::x() const
{
return xp;
}
-inline qreal QPointF::y() const
+Q_DECL_CONSTEXPR inline qreal QPointF::y() const
{
return yp;
}
@@ -327,37 +325,37 @@ inline QPointF &QPointF::operator*=(qreal c)
xp*=c; yp*=c; return *this;
}
-inline bool operator==(const QPointF &p1, const QPointF &p2)
+Q_DECL_CONSTEXPR inline bool operator==(const QPointF &p1, const QPointF &p2)
{
return qFuzzyIsNull(p1.xp - p2.xp) && qFuzzyIsNull(p1.yp - p2.yp);
}
-inline bool operator!=(const QPointF &p1, const QPointF &p2)
+Q_DECL_CONSTEXPR inline bool operator!=(const QPointF &p1, const QPointF &p2)
{
return !qFuzzyIsNull(p1.xp - p2.xp) || !qFuzzyIsNull(p1.yp - p2.yp);
}
-inline const QPointF operator+(const QPointF &p1, const QPointF &p2)
+Q_DECL_CONSTEXPR inline const QPointF operator+(const QPointF &p1, const QPointF &p2)
{
return QPointF(p1.xp+p2.xp, p1.yp+p2.yp);
}
-inline const QPointF operator-(const QPointF &p1, const QPointF &p2)
+Q_DECL_CONSTEXPR inline const QPointF operator-(const QPointF &p1, const QPointF &p2)
{
return QPointF(p1.xp-p2.xp, p1.yp-p2.yp);
}
-inline const QPointF operator*(const QPointF &p, qreal c)
+Q_DECL_CONSTEXPR inline const QPointF operator*(const QPointF &p, qreal c)
{
return QPointF(p.xp*c, p.yp*c);
}
-inline const QPointF operator*(qreal c, const QPointF &p)
+Q_DECL_CONSTEXPR inline const QPointF operator*(qreal c, const QPointF &p)
{
return QPointF(p.xp*c, p.yp*c);
}
-inline const QPointF operator-(const QPointF &p)
+Q_DECL_CONSTEXPR inline const QPointF operator-(const QPointF &p)
{
return QPointF(-p.xp, -p.yp);
}
@@ -369,12 +367,12 @@ inline QPointF &QPointF::operator/=(qreal c)
return *this;
}
-inline const QPointF operator/(const QPointF &p, qreal c)
+Q_DECL_CONSTEXPR inline const QPointF operator/(const QPointF &p, qreal c)
{
return QPointF(p.xp/c, p.yp/c);
}
-inline QPoint QPointF::toPoint() const
+Q_DECL_CONSTEXPR inline QPoint QPointF::toPoint() const
{
return QPoint(qRound(xp), qRound(yp));
}
diff --git a/src/corelib/tools/qrect.h b/src/corelib/tools/qrect.h
index bc9a4d68be..4bf10061ab 100644
--- a/src/corelib/tools/qrect.h
+++ b/src/corelib/tools/qrect.h
@@ -57,23 +57,23 @@ QT_BEGIN_NAMESPACE
class Q_CORE_EXPORT QRect
{
public:
- QRect() { x1 = y1 = 0; x2 = y2 = -1; }
- QRect(const QPoint &topleft, const QPoint &bottomright);
- QRect(const QPoint &topleft, const QSize &size);
- QRect(int left, int top, int width, int height);
-
- bool isNull() const;
- bool isEmpty() const;
- bool isValid() const;
-
- int left() const;
- int top() const;
- int right() const;
- int bottom() const;
+ Q_DECL_CONSTEXPR QRect() : x1(0), y1(0), x2(-1), y2(-1) {}
+ Q_DECL_CONSTEXPR QRect(const QPoint &topleft, const QPoint &bottomright);
+ Q_DECL_CONSTEXPR QRect(const QPoint &topleft, const QSize &size);
+ Q_DECL_CONSTEXPR QRect(int left, int top, int width, int height);
+
+ Q_DECL_CONSTEXPR bool isNull() const;
+ Q_DECL_CONSTEXPR bool isEmpty() const;
+ Q_DECL_CONSTEXPR bool isValid() const;
+
+ Q_DECL_CONSTEXPR int left() const;
+ Q_DECL_CONSTEXPR int top() const;
+ Q_DECL_CONSTEXPR int right() const;
+ Q_DECL_CONSTEXPR int bottom() const;
QRect normalized() const;
- int x() const;
- int y() const;
+ Q_DECL_CONSTEXPR int x() const;
+ Q_DECL_CONSTEXPR int y() const;
void setLeft(int pos);
void setTop(int pos);
void setRight(int pos);
@@ -86,11 +86,11 @@ public:
void setTopRight(const QPoint &p);
void setBottomLeft(const QPoint &p);
- QPoint topLeft() const;
- QPoint bottomRight() const;
- QPoint topRight() const;
- QPoint bottomLeft() const;
- QPoint center() const;
+ Q_DECL_CONSTEXPR QPoint topLeft() const;
+ Q_DECL_CONSTEXPR QPoint bottomRight() const;
+ Q_DECL_CONSTEXPR QPoint topRight() const;
+ Q_DECL_CONSTEXPR QPoint bottomLeft() const;
+ Q_DECL_CONSTEXPR QPoint center() const;
void moveLeft(int pos);
void moveTop(int pos);
@@ -104,8 +104,8 @@ public:
inline void translate(int dx, int dy);
inline void translate(const QPoint &p);
- inline QRect translated(int dx, int dy) const;
- inline QRect translated(const QPoint &p) const;
+ Q_DECL_CONSTEXPR inline QRect translated(int dx, int dy) const;
+ Q_DECL_CONSTEXPR inline QRect translated(const QPoint &p) const;
void moveTo(int x, int t);
void moveTo(const QPoint &p);
@@ -117,11 +117,11 @@ public:
inline void getCoords(int *x1, int *y1, int *x2, int *y2) const;
inline void adjust(int x1, int y1, int x2, int y2);
- inline QRect adjusted(int x1, int y1, int x2, int y2) const;
+ Q_DECL_CONSTEXPR inline QRect adjusted(int x1, int y1, int x2, int y2) const;
- QSize size() const;
- int width() const;
- int height() const;
+ Q_DECL_CONSTEXPR QSize size() const;
+ Q_DECL_CONSTEXPR int width() const;
+ Q_DECL_CONSTEXPR int height() const;
void setWidth(int w);
void setHeight(int h);
void setSize(const QSize &s);
@@ -144,8 +144,8 @@ public:
QT_DEPRECATED QRect intersect(const QRect &r) const { return intersected(r); }
#endif
- friend Q_CORE_EXPORT_INLINE bool operator==(const QRect &, const QRect &);
- friend Q_CORE_EXPORT_INLINE bool operator!=(const QRect &, const QRect &);
+ friend Q_CORE_EXPORT_INLINE Q_DECL_CONSTEXPR bool operator==(const QRect &, const QRect &);
+ friend Q_CORE_EXPORT_INLINE Q_DECL_CONSTEXPR bool operator!=(const QRect &, const QRect &);
private:
int x1;
@@ -155,8 +155,8 @@ private:
};
Q_DECLARE_TYPEINFO(QRect, Q_MOVABLE_TYPE);
-Q_CORE_EXPORT_INLINE bool operator==(const QRect &, const QRect &);
-Q_CORE_EXPORT_INLINE bool operator!=(const QRect &, const QRect &);
+Q_CORE_EXPORT_INLINE Q_DECL_CONSTEXPR bool operator==(const QRect &, const QRect &);
+Q_CORE_EXPORT_INLINE Q_DECL_CONSTEXPR bool operator!=(const QRect &, const QRect &);
/*****************************************************************************
@@ -171,55 +171,40 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QRect &);
QRect inline member functions
*****************************************************************************/
-inline QRect::QRect(int aleft, int atop, int awidth, int aheight)
-{
- x1 = aleft;
- y1 = atop;
- x2 = (aleft + awidth - 1);
- y2 = (atop + aheight - 1);
-}
+Q_DECL_CONSTEXPR inline QRect::QRect(int aleft, int atop, int awidth, int aheight)
+ : x1(aleft), y1(atop), x2(aleft + awidth - 1), y2(atop + aheight - 1) {}
-inline QRect::QRect(const QPoint &atopLeft, const QPoint &abottomRight)
-{
- x1 = atopLeft.x();
- y1 = atopLeft.y();
- x2 = abottomRight.x();
- y2 = abottomRight.y();
-}
+Q_DECL_CONSTEXPR inline QRect::QRect(const QPoint &atopLeft, const QPoint &abottomRight)
+ : x1(atopLeft.x()), y1(atopLeft.y()), x2(abottomRight.x()), y2(abottomRight.y()) {}
-inline QRect::QRect(const QPoint &atopLeft, const QSize &asize)
-{
- x1 = atopLeft.x();
- y1 = atopLeft.y();
- x2 = (x1+asize.width() - 1);
- y2 = (y1+asize.height() - 1);
-}
+Q_DECL_CONSTEXPR inline QRect::QRect(const QPoint &atopLeft, const QSize &asize)
+ : x1(atopLeft.x()), y1(atopLeft.y()), x2(atopLeft.x()+asize.width() - 1), y2(atopLeft.y()+asize.height() - 1) {}
-inline bool QRect::isNull() const
+Q_DECL_CONSTEXPR inline bool QRect::isNull() const
{ return x2 == x1 - 1 && y2 == y1 - 1; }
-inline bool QRect::isEmpty() const
+Q_DECL_CONSTEXPR inline bool QRect::isEmpty() const
{ return x1 > x2 || y1 > y2; }
-inline bool QRect::isValid() const
+Q_DECL_CONSTEXPR inline bool QRect::isValid() const
{ return x1 <= x2 && y1 <= y2; }
-inline int QRect::left() const
+Q_DECL_CONSTEXPR inline int QRect::left() const
{ return x1; }
-inline int QRect::top() const
+Q_DECL_CONSTEXPR inline int QRect::top() const
{ return y1; }
-inline int QRect::right() const
+Q_DECL_CONSTEXPR inline int QRect::right() const
{ return x2; }
-inline int QRect::bottom() const
+Q_DECL_CONSTEXPR inline int QRect::bottom() const
{ return y2; }
-inline int QRect::x() const
+Q_DECL_CONSTEXPR inline int QRect::x() const
{ return x1; }
-inline int QRect::y() const
+Q_DECL_CONSTEXPR inline int QRect::y() const
{ return y1; }
inline void QRect::setLeft(int pos)
@@ -252,28 +237,28 @@ inline void QRect::setX(int ax)
inline void QRect::setY(int ay)
{ y1 = ay; }
-inline QPoint QRect::topLeft() const
+Q_DECL_CONSTEXPR inline QPoint QRect::topLeft() const
{ return QPoint(x1, y1); }
-inline QPoint QRect::bottomRight() const
+Q_DECL_CONSTEXPR inline QPoint QRect::bottomRight() const
{ return QPoint(x2, y2); }
-inline QPoint QRect::topRight() const
+Q_DECL_CONSTEXPR inline QPoint QRect::topRight() const
{ return QPoint(x2, y1); }
-inline QPoint QRect::bottomLeft() const
+Q_DECL_CONSTEXPR inline QPoint QRect::bottomLeft() const
{ return QPoint(x1, y2); }
-inline QPoint QRect::center() const
+Q_DECL_CONSTEXPR inline QPoint QRect::center() const
{ return QPoint((x1+x2)/2, (y1+y2)/2); }
-inline int QRect::width() const
+Q_DECL_CONSTEXPR inline int QRect::width() const
{ return x2 - x1 + 1; }
-inline int QRect::height() const
+Q_DECL_CONSTEXPR inline int QRect::height() const
{ return y2 - y1 + 1; }
-inline QSize QRect::size() const
+Q_DECL_CONSTEXPR inline QSize QRect::size() const
{ return QSize(width(), height()); }
inline void QRect::translate(int dx, int dy)
@@ -292,10 +277,10 @@ inline void QRect::translate(const QPoint &p)
y2 += p.y();
}
-inline QRect QRect::translated(int dx, int dy) const
+Q_DECL_CONSTEXPR inline QRect QRect::translated(int dx, int dy) const
{ return QRect(QPoint(x1 + dx, y1 + dy), QPoint(x2 + dx, y2 + dy)); }
-inline QRect QRect::translated(const QPoint &p) const
+Q_DECL_CONSTEXPR inline QRect QRect::translated(const QPoint &p) const
{ return QRect(QPoint(x1 + p.x(), y1 + p.y()), QPoint(x2 + p.x(), y2 + p.y())); }
inline void QRect::moveTo(int ax, int ay)
@@ -388,7 +373,7 @@ inline void QRect::setCoords(int xp1, int yp1, int xp2, int yp2)
y2 = yp2;
}
-inline QRect QRect::adjusted(int xp1, int yp1, int xp2, int yp2) const
+Q_DECL_CONSTEXPR inline QRect QRect::adjusted(int xp1, int yp1, int xp2, int yp2) const
{ return QRect(QPoint(x1 + xp1, y1 + yp1), QPoint(x2 + xp2, y2 + yp2)); }
inline void QRect::adjust(int dx1, int dy1, int dx2, int dy2)
@@ -443,12 +428,12 @@ inline QRect QRect::united(const QRect &r) const
return *this | r;
}
-inline bool operator==(const QRect &r1, const QRect &r2)
+Q_DECL_CONSTEXPR inline bool operator==(const QRect &r1, const QRect &r2)
{
return r1.x1==r2.x1 && r1.x2==r2.x2 && r1.y1==r2.y1 && r1.y2==r2.y2;
}
-inline bool operator!=(const QRect &r1, const QRect &r2)
+Q_DECL_CONSTEXPR inline bool operator!=(const QRect &r1, const QRect &r2)
{
return r1.x1!=r2.x1 || r1.x2!=r2.x2 || r1.y1!=r2.y1 || r1.y2!=r2.y2;
}
@@ -461,24 +446,24 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QRect &);
class Q_CORE_EXPORT QRectF
{
public:
- QRectF() { xp = yp = 0.; w = h = 0.; }
- QRectF(const QPointF &topleft, const QSizeF &size);
- QRectF(const QPointF &topleft, const QPointF &bottomRight);
- QRectF(qreal left, qreal top, qreal width, qreal height);
- QRectF(const QRect &rect);
-
- bool isNull() const;
- bool isEmpty() const;
- bool isValid() const;
+ Q_DECL_CONSTEXPR QRectF() : xp(0.), yp(0.), w(0.), h(0.) {}
+ Q_DECL_CONSTEXPR QRectF(const QPointF &topleft, const QSizeF &size);
+ Q_DECL_CONSTEXPR QRectF(const QPointF &topleft, const QPointF &bottomRight);
+ Q_DECL_CONSTEXPR QRectF(qreal left, qreal top, qreal width, qreal height);
+ Q_DECL_CONSTEXPR QRectF(const QRect &rect);
+
+ Q_DECL_CONSTEXPR bool isNull() const;
+ Q_DECL_CONSTEXPR bool isEmpty() const;
+ Q_DECL_CONSTEXPR bool isValid() const;
QRectF normalized() const;
- inline qreal left() const { return xp; }
- inline qreal top() const { return yp; }
- inline qreal right() const { return xp + w; }
- inline qreal bottom() const { return yp + h; }
+ Q_DECL_CONSTEXPR inline qreal left() const { return xp; }
+ Q_DECL_CONSTEXPR inline qreal top() const { return yp; }
+ Q_DECL_CONSTEXPR inline qreal right() const { return xp + w; }
+ Q_DECL_CONSTEXPR inline qreal bottom() const { return yp + h; }
- inline qreal x() const;
- inline qreal y() const;
+ Q_DECL_CONSTEXPR inline qreal x() const;
+ Q_DECL_CONSTEXPR inline qreal y() const;
inline void setLeft(qreal pos);
inline void setTop(qreal pos);
inline void setRight(qreal pos);
@@ -486,11 +471,11 @@ public:
inline void setX(qreal pos) { setLeft(pos); }
inline void setY(qreal pos) { setTop(pos); }
- inline QPointF topLeft() const { return QPointF(xp, yp); }
- inline QPointF bottomRight() const { return QPointF(xp+w, yp+h); }
- inline QPointF topRight() const { return QPointF(xp+w, yp); }
- inline QPointF bottomLeft() const { return QPointF(xp, yp+h); }
- inline QPointF center() const;
+ Q_DECL_CONSTEXPR inline QPointF topLeft() const { return QPointF(xp, yp); }
+ Q_DECL_CONSTEXPR inline QPointF bottomRight() const { return QPointF(xp+w, yp+h); }
+ Q_DECL_CONSTEXPR inline QPointF topRight() const { return QPointF(xp+w, yp); }
+ Q_DECL_CONSTEXPR inline QPointF bottomLeft() const { return QPointF(xp, yp+h); }
+ Q_DECL_CONSTEXPR inline QPointF center() const;
void setTopLeft(const QPointF &p);
void setBottomRight(const QPointF &p);
@@ -510,8 +495,8 @@ public:
void translate(qreal dx, qreal dy);
void translate(const QPointF &p);
- QRectF translated(qreal dx, qreal dy) const;
- QRectF translated(const QPointF &p) const;
+ Q_DECL_CONSTEXPR QRectF translated(qreal dx, qreal dy) const;
+ Q_DECL_CONSTEXPR QRectF translated(const QPointF &p) const;
void moveTo(qreal x, qreal t);
void moveTo(const QPointF &p);
@@ -523,11 +508,11 @@ public:
void getCoords(qreal *x1, qreal *y1, qreal *x2, qreal *y2) const;
inline void adjust(qreal x1, qreal y1, qreal x2, qreal y2);
- inline QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const;
+ Q_DECL_CONSTEXPR inline QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const;
- QSizeF size() const;
- qreal width() const;
- qreal height() const;
+ Q_DECL_CONSTEXPR QSizeF size() const;
+ Q_DECL_CONSTEXPR qreal width() const;
+ Q_DECL_CONSTEXPR qreal height() const;
void setWidth(qreal w);
void setHeight(qreal h);
void setSize(const QSizeF &s);
@@ -549,10 +534,10 @@ public:
QT_DEPRECATED QRectF intersect(const QRectF &r) const { return intersected(r); }
#endif
- friend Q_CORE_EXPORT_INLINE bool operator==(const QRectF &, const QRectF &);
- friend Q_CORE_EXPORT_INLINE bool operator!=(const QRectF &, const QRectF &);
+ friend Q_CORE_EXPORT_INLINE Q_DECL_CONSTEXPR bool operator==(const QRectF &, const QRectF &);
+ friend Q_CORE_EXPORT_INLINE Q_DECL_CONSTEXPR bool operator!=(const QRectF &, const QRectF &);
- QRect toRect() const;
+ Q_DECL_CONSTEXPR QRect toRect() const;
QRect toAlignedRect() const;
private:
@@ -563,8 +548,8 @@ private:
};
Q_DECLARE_TYPEINFO(QRectF, Q_MOVABLE_TYPE);
-Q_CORE_EXPORT_INLINE bool operator==(const QRectF &, const QRectF &);
-Q_CORE_EXPORT_INLINE bool operator!=(const QRectF &, const QRectF &);
+Q_CORE_EXPORT_INLINE Q_DECL_CONSTEXPR bool operator==(const QRectF &, const QRectF &);
+Q_CORE_EXPORT_INLINE Q_DECL_CONSTEXPR bool operator!=(const QRectF &, const QRectF &);
/*****************************************************************************
@@ -579,45 +564,40 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QRectF &);
QRectF inline member functions
*****************************************************************************/
-inline QRectF::QRectF(qreal aleft, qreal atop, qreal awidth, qreal aheight)
+Q_DECL_CONSTEXPR inline QRectF::QRectF(qreal aleft, qreal atop, qreal awidth, qreal aheight)
: xp(aleft), yp(atop), w(awidth), h(aheight)
{
}
-inline QRectF::QRectF(const QPointF &atopLeft, const QSizeF &asize)
+Q_DECL_CONSTEXPR inline QRectF::QRectF(const QPointF &atopLeft, const QSizeF &asize)
+ : xp(atopLeft.x()), yp(atopLeft.y()), w(asize.width()), h(asize.height())
{
- xp = atopLeft.x();
- yp = atopLeft.y();
- w = asize.width();
- h = asize.height();
}
-inline QRectF::QRectF(const QPointF &atopLeft, const QPointF &abottomRight)
+
+Q_DECL_CONSTEXPR inline QRectF::QRectF(const QPointF &atopLeft, const QPointF &abottomRight)
+ : xp(atopLeft.x()), yp(atopLeft.y()), w(abottomRight.x() - atopLeft.x()), h(abottomRight.y() - atopLeft.y())
{
- xp = atopLeft.x();
- yp = atopLeft.y();
- w = abottomRight.x() - xp;
- h = abottomRight.y() - yp;
}
-inline QRectF::QRectF(const QRect &r)
+Q_DECL_CONSTEXPR inline QRectF::QRectF(const QRect &r)
: xp(r.x()), yp(r.y()), w(r.width()), h(r.height())
{
}
-inline bool QRectF::isNull() const
+Q_DECL_CONSTEXPR inline bool QRectF::isNull() const
{ return w == 0. && h == 0.; }
-inline bool QRectF::isEmpty() const
+Q_DECL_CONSTEXPR inline bool QRectF::isEmpty() const
{ return w <= 0. || h <= 0.; }
-inline bool QRectF::isValid() const
+Q_DECL_CONSTEXPR inline bool QRectF::isValid() const
{ return w > 0. && h > 0.; }
-inline qreal QRectF::x() const
+Q_DECL_CONSTEXPR inline qreal QRectF::x() const
{ return xp; }
-inline qreal QRectF::y() const
+Q_DECL_CONSTEXPR inline qreal QRectF::y() const
{ return yp; }
inline void QRectF::setLeft(qreal pos) { qreal diff = pos - xp; xp += diff; w -= diff; }
@@ -636,7 +616,7 @@ inline void QRectF::setBottomLeft(const QPointF &p) { setLeft(p.x()); setBottom(
inline void QRectF::setBottomRight(const QPointF &p) { setRight(p.x()); setBottom(p.y()); }
-inline QPointF QRectF::center() const
+Q_DECL_CONSTEXPR inline QPointF QRectF::center() const
{ return QPointF(xp + w/2, yp + h/2); }
inline void QRectF::moveLeft(qreal pos) { xp = pos; }
@@ -657,13 +637,13 @@ inline void QRectF::moveBottomRight(const QPointF &p) { moveRight(p.x()); moveBo
inline void QRectF::moveCenter(const QPointF &p) { xp = p.x() - w/2; yp = p.y() - h/2; }
-inline qreal QRectF::width() const
+Q_DECL_CONSTEXPR inline qreal QRectF::width() const
{ return w; }
-inline qreal QRectF::height() const
+Q_DECL_CONSTEXPR inline qreal QRectF::height() const
{ return h; }
-inline QSizeF QRectF::size() const
+Q_DECL_CONSTEXPR inline QSizeF QRectF::size() const
{ return QSizeF(w, h); }
inline void QRectF::translate(qreal dx, qreal dy)
@@ -690,10 +670,10 @@ inline void QRectF::moveTo(const QPointF &p)
yp = p.y();
}
-inline QRectF QRectF::translated(qreal dx, qreal dy) const
+Q_DECL_CONSTEXPR inline QRectF QRectF::translated(qreal dx, qreal dy) const
{ return QRectF(xp + dx, yp + dy, w, h); }
-inline QRectF QRectF::translated(const QPointF &p) const
+Q_DECL_CONSTEXPR inline QRectF QRectF::translated(const QPointF &p) const
{ return QRectF(xp + p.x(), yp + p.y(), w, h); }
inline void QRectF::getRect(qreal *ax, qreal *ay, qreal *aaw, qreal *aah) const
@@ -731,7 +711,7 @@ inline void QRectF::setCoords(qreal xp1, qreal yp1, qreal xp2, qreal yp2)
inline void QRectF::adjust(qreal xp1, qreal yp1, qreal xp2, qreal yp2)
{ xp += xp1; yp += yp1; w += xp2 - xp1; h += yp2 - yp1; }
-inline QRectF QRectF::adjusted(qreal xp1, qreal yp1, qreal xp2, qreal yp2) const
+Q_DECL_CONSTEXPR inline QRectF QRectF::adjusted(qreal xp1, qreal yp1, qreal xp2, qreal yp2) const
{ return QRectF(xp + xp1, yp + yp1, w + xp2 - xp1, h + yp2 - yp1); }
inline void QRectF::setWidth(qreal aw)
@@ -773,19 +753,19 @@ inline QRectF QRectF::united(const QRectF &r) const
return *this | r;
}
-inline bool operator==(const QRectF &r1, const QRectF &r2)
+Q_DECL_CONSTEXPR inline bool operator==(const QRectF &r1, const QRectF &r2)
{
return qFuzzyCompare(r1.xp, r2.xp) && qFuzzyCompare(r1.yp, r2.yp)
&& qFuzzyCompare(r1.w, r2.w) && qFuzzyCompare(r1.h, r2.h);
}
-inline bool operator!=(const QRectF &r1, const QRectF &r2)
+Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &r1, const QRectF &r2)
{
return !qFuzzyCompare(r1.xp, r2.xp) || !qFuzzyCompare(r1.yp, r2.yp)
|| !qFuzzyCompare(r1.w, r2.w) || !qFuzzyCompare(r1.h, r2.h);
}
-inline QRect QRectF::toRect() const
+Q_DECL_CONSTEXPR inline QRect QRectF::toRect() const
{
return QRect(qRound(xp), qRound(yp), qRound(w), qRound(h));
}
diff --git a/src/corelib/tools/qsize.h b/src/corelib/tools/qsize.h
index fece0ac943..88af9e876b 100644
--- a/src/corelib/tools/qsize.h
+++ b/src/corelib/tools/qsize.h
@@ -52,27 +52,27 @@ QT_BEGIN_NAMESPACE
class Q_CORE_EXPORT QSize
{
public:
- QSize();
- QSize(int w, int h);
+ Q_DECL_CONSTEXPR QSize();
+ Q_DECL_CONSTEXPR QSize(int w, int h);
- bool isNull() const;
- bool isEmpty() const;
- bool isValid() const;
+ Q_DECL_CONSTEXPR bool isNull() const;
+ Q_DECL_CONSTEXPR bool isEmpty() const;
+ Q_DECL_CONSTEXPR bool isValid() const;
- int width() const;
- int height() const;
+ Q_DECL_CONSTEXPR int width() const;
+ Q_DECL_CONSTEXPR int height() const;
void setWidth(int w);
void setHeight(int h);
void transpose();
- QSize transposed() const;
+ Q_DECL_CONSTEXPR QSize transposed() const;
void scale(int w, int h, Qt::AspectRatioMode mode);
void scale(const QSize &s, Qt::AspectRatioMode mode);
QSize scaled(int w, int h, Qt::AspectRatioMode mode) const;
QSize scaled(const QSize &s, Qt::AspectRatioMode mode) const;
- QSize expandedTo(const QSize &) const;
- QSize boundedTo(const QSize &) const;
+ Q_DECL_CONSTEXPR QSize expandedTo(const QSize &) const;
+ Q_DECL_CONSTEXPR QSize boundedTo(const QSize &) const;
int &rwidth();
int &rheight();
@@ -82,12 +82,12 @@ public:
QSize &operator*=(qreal c);
QSize &operator/=(qreal c);
- friend inline bool operator==(const QSize &, const QSize &);
- friend inline bool operator!=(const QSize &, const QSize &);
- friend inline const QSize operator+(const QSize &, const QSize &);
- friend inline const QSize operator-(const QSize &, const QSize &);
- friend inline const QSize operator*(const QSize &, qreal);
- friend inline const QSize operator*(qreal, const QSize &);
+ friend inline Q_DECL_CONSTEXPR bool operator==(const QSize &, const QSize &);
+ friend inline Q_DECL_CONSTEXPR bool operator!=(const QSize &, const QSize &);
+ friend inline Q_DECL_CONSTEXPR const QSize operator+(const QSize &, const QSize &);
+ friend inline Q_DECL_CONSTEXPR const QSize operator-(const QSize &, const QSize &);
+ friend inline Q_DECL_CONSTEXPR const QSize operator*(const QSize &, qreal);
+ friend inline Q_DECL_CONSTEXPR const QSize operator*(qreal, const QSize &);
friend inline const QSize operator/(const QSize &, qreal);
private:
@@ -110,25 +110,23 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QSize &);
QSize inline functions
*****************************************************************************/
-inline QSize::QSize()
-{ wd = ht = -1; }
+Q_DECL_CONSTEXPR inline QSize::QSize() : wd(-1), ht(-1) {}
-inline QSize::QSize(int w, int h)
-{ wd = w; ht = h; }
+Q_DECL_CONSTEXPR inline QSize::QSize(int w, int h) : wd(w), ht(h) {}
-inline bool QSize::isNull() const
+Q_DECL_CONSTEXPR inline bool QSize::isNull() const
{ return wd==0 && ht==0; }
-inline bool QSize::isEmpty() const
+Q_DECL_CONSTEXPR inline bool QSize::isEmpty() const
{ return wd<1 || ht<1; }
-inline bool QSize::isValid() const
+Q_DECL_CONSTEXPR inline bool QSize::isValid() const
{ return wd>=0 && ht>=0; }
-inline int QSize::width() const
+Q_DECL_CONSTEXPR inline int QSize::width() const
{ return wd; }
-inline int QSize::height() const
+Q_DECL_CONSTEXPR inline int QSize::height() const
{ return ht; }
inline void QSize::setWidth(int w)
@@ -137,7 +135,7 @@ inline void QSize::setWidth(int w)
inline void QSize::setHeight(int h)
{ ht = h; }
-inline QSize QSize::transposed() const
+Q_DECL_CONSTEXPR inline QSize QSize::transposed() const
{ return QSize(ht, wd); }
inline void QSize::scale(int w, int h, Qt::AspectRatioMode mode)
@@ -164,22 +162,22 @@ inline QSize &QSize::operator-=(const QSize &s)
inline QSize &QSize::operator*=(qreal c)
{ wd = qRound(wd*c); ht = qRound(ht*c); return *this; }
-inline bool operator==(const QSize &s1, const QSize &s2)
+Q_DECL_CONSTEXPR inline bool operator==(const QSize &s1, const QSize &s2)
{ return s1.wd == s2.wd && s1.ht == s2.ht; }
-inline bool operator!=(const QSize &s1, const QSize &s2)
+Q_DECL_CONSTEXPR inline bool operator!=(const QSize &s1, const QSize &s2)
{ return s1.wd != s2.wd || s1.ht != s2.ht; }
-inline const QSize operator+(const QSize & s1, const QSize & s2)
+Q_DECL_CONSTEXPR inline const QSize operator+(const QSize & s1, const QSize & s2)
{ return QSize(s1.wd+s2.wd, s1.ht+s2.ht); }
-inline const QSize operator-(const QSize &s1, const QSize &s2)
+Q_DECL_CONSTEXPR inline const QSize operator-(const QSize &s1, const QSize &s2)
{ return QSize(s1.wd-s2.wd, s1.ht-s2.ht); }
-inline const QSize operator*(const QSize &s, qreal c)
+Q_DECL_CONSTEXPR inline const QSize operator*(const QSize &s, qreal c)
{ return QSize(qRound(s.wd*c), qRound(s.ht*c)); }
-inline const QSize operator*(qreal c, const QSize &s)
+Q_DECL_CONSTEXPR inline const QSize operator*(qreal c, const QSize &s)
{ return QSize(qRound(s.wd*c), qRound(s.ht*c)); }
inline QSize &QSize::operator/=(qreal c)
@@ -195,12 +193,12 @@ inline const QSize operator/(const QSize &s, qreal c)
return QSize(qRound(s.wd/c), qRound(s.ht/c));
}
-inline QSize QSize::expandedTo(const QSize & otherSize) const
+Q_DECL_CONSTEXPR inline QSize QSize::expandedTo(const QSize & otherSize) const
{
return QSize(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht));
}
-inline QSize QSize::boundedTo(const QSize & otherSize) const
+Q_DECL_CONSTEXPR inline QSize QSize::boundedTo(const QSize & otherSize) const
{
return QSize(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht));
}
@@ -213,28 +211,28 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QSize &);
class Q_CORE_EXPORT QSizeF
{
public:
- QSizeF();
- QSizeF(const QSize &sz);
- QSizeF(qreal w, qreal h);
+ Q_DECL_CONSTEXPR QSizeF();
+ Q_DECL_CONSTEXPR QSizeF(const QSize &sz);
+ Q_DECL_CONSTEXPR QSizeF(qreal w, qreal h);
bool isNull() const;
- bool isEmpty() const;
- bool isValid() const;
+ Q_DECL_CONSTEXPR bool isEmpty() const;
+ Q_DECL_CONSTEXPR bool isValid() const;
- qreal width() const;
- qreal height() const;
+ Q_DECL_CONSTEXPR qreal width() const;
+ Q_DECL_CONSTEXPR qreal height() const;
void setWidth(qreal w);
void setHeight(qreal h);
void transpose();
- QSizeF transposed() const;
+ Q_DECL_CONSTEXPR QSizeF transposed() const;
void scale(qreal w, qreal h, Qt::AspectRatioMode mode);
void scale(const QSizeF &s, Qt::AspectRatioMode mode);
QSizeF scaled(qreal w, qreal h, Qt::AspectRatioMode mode) const;
QSizeF scaled(const QSizeF &s, Qt::AspectRatioMode mode) const;
- QSizeF expandedTo(const QSizeF &) const;
- QSizeF boundedTo(const QSizeF &) const;
+ Q_DECL_CONSTEXPR QSizeF expandedTo(const QSizeF &) const;
+ Q_DECL_CONSTEXPR QSizeF boundedTo(const QSizeF &) const;
qreal &rwidth();
qreal &rheight();
@@ -244,15 +242,15 @@ public:
QSizeF &operator*=(qreal c);
QSizeF &operator/=(qreal c);
- friend inline bool operator==(const QSizeF &, const QSizeF &);
- friend inline bool operator!=(const QSizeF &, const QSizeF &);
- friend inline const QSizeF operator+(const QSizeF &, const QSizeF &);
- friend inline const QSizeF operator-(const QSizeF &, const QSizeF &);
- friend inline const QSizeF operator*(const QSizeF &, qreal);
- friend inline const QSizeF operator*(qreal, const QSizeF &);
+ friend Q_DECL_CONSTEXPR inline bool operator==(const QSizeF &, const QSizeF &);
+ friend Q_DECL_CONSTEXPR inline bool operator!=(const QSizeF &, const QSizeF &);
+ friend Q_DECL_CONSTEXPR inline const QSizeF operator+(const QSizeF &, const QSizeF &);
+ friend Q_DECL_CONSTEXPR inline const QSizeF operator-(const QSizeF &, const QSizeF &);
+ friend Q_DECL_CONSTEXPR inline const QSizeF operator*(const QSizeF &, qreal);
+ friend Q_DECL_CONSTEXPR inline const QSizeF operator*(qreal, const QSizeF &);
friend inline const QSizeF operator/(const QSizeF &, qreal);
- inline QSize toSize() const;
+ Q_DECL_CONSTEXPR inline QSize toSize() const;
private:
qreal wd;
@@ -275,30 +273,25 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QSizeF &);
QSizeF inline functions
*****************************************************************************/
-inline QSizeF::QSizeF()
-{ wd = ht = -1.; }
+Q_DECL_CONSTEXPR inline QSizeF::QSizeF() : wd(-1.), ht(-1.) {}
-inline QSizeF::QSizeF(const QSize &sz)
- : wd(sz.width()), ht(sz.height())
-{
-}
+Q_DECL_CONSTEXPR inline QSizeF::QSizeF(const QSize &sz) : wd(sz.width()), ht(sz.height()) {}
-inline QSizeF::QSizeF(qreal w, qreal h)
-{ wd = w; ht = h; }
+Q_DECL_CONSTEXPR inline QSizeF::QSizeF(qreal w, qreal h) : wd(w), ht(h) {}
inline bool QSizeF::isNull() const
{ return qIsNull(wd) && qIsNull(ht); }
-inline bool QSizeF::isEmpty() const
+Q_DECL_CONSTEXPR inline bool QSizeF::isEmpty() const
{ return wd <= 0. || ht <= 0.; }
-inline bool QSizeF::isValid() const
+Q_DECL_CONSTEXPR inline bool QSizeF::isValid() const
{ return wd >= 0. && ht >= 0.; }
-inline qreal QSizeF::width() const
+Q_DECL_CONSTEXPR inline qreal QSizeF::width() const
{ return wd; }
-inline qreal QSizeF::height() const
+Q_DECL_CONSTEXPR inline qreal QSizeF::height() const
{ return ht; }
inline void QSizeF::setWidth(qreal w)
@@ -307,7 +300,7 @@ inline void QSizeF::setWidth(qreal w)
inline void QSizeF::setHeight(qreal h)
{ ht = h; }
-inline QSizeF QSizeF::transposed() const
+Q_DECL_CONSTEXPR inline QSizeF QSizeF::transposed() const
{ return QSizeF(ht, wd); }
inline void QSizeF::scale(qreal w, qreal h, Qt::AspectRatioMode mode)
@@ -334,22 +327,22 @@ inline QSizeF &QSizeF::operator-=(const QSizeF &s)
inline QSizeF &QSizeF::operator*=(qreal c)
{ wd *= c; ht *= c; return *this; }
-inline bool operator==(const QSizeF &s1, const QSizeF &s2)
+Q_DECL_CONSTEXPR inline bool operator==(const QSizeF &s1, const QSizeF &s2)
{ return qFuzzyCompare(s1.wd, s2.wd) && qFuzzyCompare(s1.ht, s2.ht); }
-inline bool operator!=(const QSizeF &s1, const QSizeF &s2)
+Q_DECL_CONSTEXPR inline bool operator!=(const QSizeF &s1, const QSizeF &s2)
{ return !qFuzzyCompare(s1.wd, s2.wd) || !qFuzzyCompare(s1.ht, s2.ht); }
-inline const QSizeF operator+(const QSizeF & s1, const QSizeF & s2)
+Q_DECL_CONSTEXPR inline const QSizeF operator+(const QSizeF & s1, const QSizeF & s2)
{ return QSizeF(s1.wd+s2.wd, s1.ht+s2.ht); }
-inline const QSizeF operator-(const QSizeF &s1, const QSizeF &s2)
+Q_DECL_CONSTEXPR inline const QSizeF operator-(const QSizeF &s1, const QSizeF &s2)
{ return QSizeF(s1.wd-s2.wd, s1.ht-s2.ht); }
-inline const QSizeF operator*(const QSizeF &s, qreal c)
+Q_DECL_CONSTEXPR inline const QSizeF operator*(const QSizeF &s, qreal c)
{ return QSizeF(s.wd*c, s.ht*c); }
-inline const QSizeF operator*(qreal c, const QSizeF &s)
+Q_DECL_CONSTEXPR inline const QSizeF operator*(qreal c, const QSizeF &s)
{ return QSizeF(s.wd*c, s.ht*c); }
inline QSizeF &QSizeF::operator/=(qreal c)
@@ -365,17 +358,17 @@ inline const QSizeF operator/(const QSizeF &s, qreal c)
return QSizeF(s.wd/c, s.ht/c);
}
-inline QSizeF QSizeF::expandedTo(const QSizeF & otherSize) const
+Q_DECL_CONSTEXPR inline QSizeF QSizeF::expandedTo(const QSizeF & otherSize) const
{
return QSizeF(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht));
}
-inline QSizeF QSizeF::boundedTo(const QSizeF & otherSize) const
+Q_DECL_CONSTEXPR inline QSizeF QSizeF::boundedTo(const QSizeF & otherSize) const
{
return QSizeF(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht));
}
-inline QSize QSizeF::toSize() const
+Q_DECL_CONSTEXPR inline QSize QSizeF::toSize() const
{
return QSize(qRound(wd), qRound(ht));
}