diff options
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qarraydata.h | 4 | ||||
-rw-r--r-- | src/corelib/tools/qarraydataops.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qbytearray.cpp | 11 | ||||
-rw-r--r-- | src/corelib/tools/qbytearraylist.h | 5 | ||||
-rw-r--r-- | src/corelib/tools/qhash.cpp | 25 | ||||
-rw-r--r-- | src/corelib/tools/qmargins.cpp | 412 | ||||
-rw-r--r-- | src/corelib/tools/qmargins.h | 265 | ||||
-rw-r--r-- | src/corelib/tools/qrect.cpp | 133 | ||||
-rw-r--r-- | src/corelib/tools/qrect.h | 96 | ||||
-rw-r--r-- | src/corelib/tools/qstring.cpp | 15 | ||||
-rw-r--r-- | src/corelib/tools/tools.pri | 2 |
11 files changed, 863 insertions, 107 deletions
diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h index 90b5649f09..534f310d36 100644 --- a/src/corelib/tools/qarraydata.h +++ b/src/corelib/tools/qarraydata.h @@ -135,7 +135,7 @@ struct QTypedArrayData public: T *i; typedef std::random_access_iterator_tag iterator_category; - typedef qptrdiff difference_type; + typedef int difference_type; typedef T value_type; typedef T *pointer; typedef T &reference; @@ -169,7 +169,7 @@ struct QTypedArrayData public: const T *i; typedef std::random_access_iterator_tag iterator_category; - typedef qptrdiff difference_type; + typedef int difference_type; typedef T value_type; typedef const T *pointer; typedef const T &reference; diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h index c8a0825480..b94c6b50ea 100644 --- a/src/corelib/tools/qarraydataops.h +++ b/src/corelib/tools/qarraydataops.h @@ -122,7 +122,7 @@ struct QPodArrayOps Q_ASSERT(b >= this->begin() && b < this->end()); Q_ASSERT(e > this->begin() && e < this->end()); - ::memmove(b, e, (this->end() - e) * sizeof(T)); + ::memmove(b, e, (static_cast<T *>(this->end()) - e) * sizeof(T)); this->size -= (e - b); } }; diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index 3030657a62..52207dcd4e 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -3665,12 +3665,6 @@ QByteArray QByteArray::toBase64(Base64Options options) const \sa toUShort() */ -/*! - \overload - - \sa toLongLong() -*/ - static char *qulltoa2(char *p, qulonglong n, int base) { #if defined(QT_CHECK_RANGE) @@ -3689,6 +3683,11 @@ static char *qulltoa2(char *p, qulonglong n, int base) return p; } +/*! + \overload + + \sa toLongLong() +*/ QByteArray &QByteArray::setNum(qlonglong n, int base) { const int buffsize = 66; // big enough for MAX_ULLONG in base 2 diff --git a/src/corelib/tools/qbytearraylist.h b/src/corelib/tools/qbytearraylist.h index 5ce6509c28..882bc68f09 100644 --- a/src/corelib/tools/qbytearraylist.h +++ b/src/corelib/tools/qbytearraylist.h @@ -97,9 +97,8 @@ inline QByteArray QByteArrayList::join(char sep) const inline QByteArrayList operator+(const QByteArrayList &lhs, const QByteArrayList &rhs) { - QByteArrayList res; - res.append( lhs ); - res.append( rhs ); + QByteArrayList res = lhs; + res += rhs; return res; } diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index 5320ea1fbf..a5d14a3535 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -337,20 +337,29 @@ uint qt_hash(const QStringRef &key) Q_DECL_NOTHROW } /* - The prime_deltas array is a table of selected prime values, even - though it doesn't look like one. The primes we are using are 1, - 2, 5, 11, 17, 37, 67, 131, 257, ..., i.e. primes in the immediate - surrounding of a power of two. + The prime_deltas array contains the difference between a power + of two and the next prime number: - The primeForNumBits() function returns the prime associated to a - power of two. For example, primeForNumBits(8) returns 257. + prime_deltas[i] = nextprime(2^i) - 2^i + + Basically, it's sequence A092131 from OEIS, assuming: + - nextprime(1) = 1 + - nextprime(2) = 2 + and + - left-extending it for the offset 0 (A092131 starts at i=1) + - stopping the sequence at i = 28 (the table is big enough...) */ static const uchar prime_deltas[] = { - 0, 0, 1, 3, 1, 5, 3, 3, 1, 9, 7, 5, 3, 9, 25, 3, - 1, 21, 3, 21, 7, 15, 9, 5, 3, 29, 15, 0, 0, 0, 0, 0 + 0, 0, 1, 3, 1, 5, 3, 3, 1, 9, 7, 5, 3, 17, 27, 3, + 1, 29, 3, 21, 7, 17, 15, 9, 43, 35, 15, 0, 0, 0, 0, 0 }; +/* + The primeForNumBits() function returns the prime associated to a + power of two. For example, primeForNumBits(8) returns 257. +*/ + static inline int primeForNumBits(int numBits) { return (1 << numBits) + prime_deltas[numBits]; diff --git a/src/corelib/tools/qmargins.cpp b/src/corelib/tools/qmargins.cpp index c5bd8468bc..088f0dc083 100644 --- a/src/corelib/tools/qmargins.cpp +++ b/src/corelib/tools/qmargins.cpp @@ -158,86 +158,63 @@ QT_BEGIN_NAMESPACE */ /*! - \fn QRect operator+(const QRect &rectangle, const QMargins &margins) - \relates QRect - - Returns the \a rectangle grown by the \a margins. - - \since 5.1 -*/ - -/*! - \fn QRect operator+(const QMargins &margins, const QRect &rectangle) - \relates QRect - \overload - - Returns the \a rectangle grown by the \a margins. - - \since 5.1 -*/ - -/*! - \fn QRect QRect::marginsAdded(const QMargins &margins) const - - Returns a rectangle grown by the \a margins. - - \sa operator+=(), marginsRemoved(), operator-=() - - \since 5.1 -*/ - -/*! - \fn QRect QRect::operator+=(const QMargins &margins) const + \fn const QMargins operator+(const QMargins &m1, const QMargins &m2) + \relates QMargins - Adds the \a margins to the rectangle, growing it. + Returns a QMargins object that is the sum of the given margins, \a m1 + and \a m2; each component is added separately. - \sa marginsAdded(), marginsRemoved(), operator-=() + \sa QMargins::operator+=(), QMargins::operator-=() \since 5.1 */ /*! - \fn QRect QRect::marginsRemoved(const QMargins &margins) const + \fn const QMargins operator-(const QMargins &m1, const QMargins &m2) + \relates QMargins - Removes the \a margins from the rectangle, shrinking it. + Returns a QMargins object that is formed by subtracting \a m2 from + \a m1; each component is subtracted separately. - \sa marginsAdded(), operator+=(), operator-=() + \sa QMargins::operator+=(), QMargins::operator-=() \since 5.1 */ /*! - \fn QRect QRect::operator -=(const QMargins &margins) const + \fn const QMargins operator+(const QMargins &lhs, int rhs) + \relates QMargins - Returns a rectangle shrunk by the \a margins. + Returns a QMargins object that is formed by adding \a rhs to + \a lhs. - \sa marginsRemoved(), operator+=(), marginsAdded() + \sa QMargins::operator+=(), QMargins::operator-=() - \since 5.1 + \since 5.3 */ /*! - \fn const QMargins operator+(const QMargins &m1, const QMargins &m2) + \fn const QMargins operator+(int lhs, const QMargins &rhs) \relates QMargins - Returns a QMargins object that is the sum of the given margins, \a m1 - and \a m2; each component is added separately. + Returns a QMargins object that is formed by adding \a lhs to + \a rhs. \sa QMargins::operator+=(), QMargins::operator-=() - \since 5.1 + \since 5.3 */ /*! - \fn const QMargins operator-(const QMargins &m1, const QMargins &m2) + \fn const QMargins operator-(const QMargins &lhs, int rhs) \relates QMargins - Returns a QMargins object that is formed by subtracting \a m2 from - \a m1; each component is subtracted separately. + Returns a QMargins object that is formed by subtracting \a rhs from + \a lhs. \sa QMargins::operator+=(), QMargins::operator-=() - \since 5.1 + \since 5.3 */ /*! @@ -317,6 +294,15 @@ QT_BEGIN_NAMESPACE */ /*! + \fn QMargins operator+(const QMargins &margins) + \relates QMargins + + Returns a QMargin object that is formed from all components of \a margins. + + \since 5.3 +*/ + +/*! \fn QMargins operator-(const QMargins &margins) \relates QMargins @@ -440,4 +426,336 @@ QDebug operator<<(QDebug dbg, const QMargins &m) { } #endif +/*! + \class QMarginsF + \inmodule QtCore + \ingroup painting + \since 5.3 + + \brief The QMarginsF class defines the four margins of a rectangle. + + QMarginsF defines a set of four margins; left, top, right and bottom, + that describe the size of the borders surrounding a rectangle. + + The isNull() function returns \c true only if all margins are set to zero. + + QMarginsF objects can be streamed as well as compared. +*/ + + +/***************************************************************************** + QMarginsF member functions + *****************************************************************************/ + +/*! + \fn QMarginsF::QMarginsF() + + Constructs a margins object with all margins set to 0. + + \sa isNull() +*/ + +/*! + \fn QMarginsF::QMarginsF(qreal left, qreal top, qreal right, qreal bottom) + + Constructs margins with the given \a left, \a top, \a right, \a bottom + + \sa setLeft(), setRight(), setTop(), setBottom() +*/ + +/*! + \fn QMarginsF::QMarginsF(const QMargins &margins) + + Constructs margins copied from the given \a margins +*/ + +/*! + \fn bool QMarginsF::isNull() const + + Returns \c true if all margins are is 0; otherwise returns + false. +*/ + + +/*! + \fn qreal QMarginsF::left() const + + Returns the left margin. + + \sa setLeft() +*/ + +/*! + \fn qreal QMarginsF::top() const + + Returns the top margin. + + \sa setTop() +*/ + +/*! + \fn qreal QMarginsF::right() const + + Returns the right margin. +*/ + +/*! + \fn qreal QMarginsF::bottom() const + + Returns the bottom margin. +*/ + + +/*! + \fn void QMarginsF::setLeft(qreal left) + + Sets the left margin to \a left. +*/ + +/*! + \fn void QMarginsF::setTop(qreal Top) + + Sets the Top margin to \a Top. +*/ + +/*! + \fn void QMarginsF::setRight(qreal right) + + Sets the right margin to \a right. +*/ + +/*! + \fn void QMarginsF::setBottom(qreal bottom) + + Sets the bottom margin to \a bottom. +*/ + +/*! + \fn bool operator==(const QMarginsF &lhs, const QMarginsF &rhs) + \relates QMarginsF + + Returns \c true if \a lhs and \a rhs are equal; otherwise returns \c false. +*/ + +/*! + \fn bool operator!=(const QMarginsF &lhs, const QMarginsF &rhs) + \relates QMarginsF + + Returns \c true if \a lhs and \a rhs are different; otherwise returns \c false. +*/ + +/*! + \fn const QMarginsF operator+(const QMarginsF &lhs, const QMarginsF &rhs) + \relates QMarginsF + + Returns a QMarginsF object that is the sum of the given margins, \a lhs + and \a rhs; each component is added separately. + + \sa QMarginsF::operator+=(), QMarginsF::operator-=() +*/ + +/*! + \fn const QMarginsF operator-(const QMarginsF &lhs, const QMarginsF &rhs) + \relates QMarginsF + + Returns a QMarginsF object that is formed by subtracting \a rhs from + \a lhs; each component is subtracted separately. + + \sa QMarginsF::operator+=(), QMarginsF::operator-=() +*/ + +/*! + \fn const QMarginsF operator+(const QMarginsF &lhs, qreal rhs) + \relates QMarginsF + + Returns a QMarginsF object that is formed by adding \a rhs to + \a lhs. + + \sa QMarginsF::operator+=(), QMarginsF::operator-=() +*/ + +/*! + \fn const QMarginsF operator+(qreal lhs, const QMarginsF &rhs) + \relates QMarginsF + + Returns a QMarginsF object that is formed by adding \a lhs to + \a rhs. + + \sa QMarginsF::operator+=(), QMarginsF::operator-=() +*/ + +/*! + \fn const QMarginsF operator-(const QMarginsF &lhs, qreal rhs) + \relates QMarginsF + + Returns a QMarginsF object that is formed by subtracting \a rhs from + \a lhs. + + \sa QMarginsF::operator+=(), QMarginsF::operator-=() +*/ + +/*! + \fn const QMarginsF operator*(const QMarginsF &lhs, qreal rhs) + \relates QMarginsF + \overload + + Returns a QMarginsF object that is formed by multiplying each component + of the given \a lhs margins by \a rhs factor. + + \sa QMarginsF::operator*=(), QMarginsF::operator/=() +*/ + +/*! + \fn const QMarginsF operator*(qreal lhs, const QMarginsF &rhs) + \relates QMarginsF + \overload + + Returns a QMarginsF object that is formed by multiplying each component + of the given \a lhs margins by \a rhs factor. + + \sa QMarginsF::operator*=(), QMarginsF::operator/=() +*/ + +/*! + \fn const QMarginsF operator/(const QMarginsF &lhs, qreal rhs) + \relates QMarginsF + \overload + + Returns a QMarginsF object that is formed by dividing the components of + the given \a lhs margins by the given \a rhs divisor. + + \sa QMarginsF::operator*=(), QMarginsF::operator/=() +*/ + +/*! + \fn QMarginsF operator+(const QMarginsF &margins) + \relates QMarginsF + + Returns a QMargin object that is formed from all components of \a margins. +*/ + +/*! + \fn QMarginsF operator-(const QMarginsF &margins) + \relates QMarginsF + + Returns a QMargin object that is formed by negating all components of \a margins. +*/ + +/*! + \fn QMarginsF &QMarginsF::operator+=(const QMarginsF &margins) + + Add each component of \a margins to the respective component of this object + and returns a reference to it. + + \sa operator-=() +*/ + +/*! + \fn QMarginsF &QMarginsF::operator-=(const QMarginsF &margins) + + Subtract each component of \a margins from the respective component of this object + and returns a reference to it. + + \sa operator+=() +*/ + +/*! + \fn QMarginsF &QMarginsF::operator+=(qreal addend) + \overload + + Adds the \a addend to each component of this object + and returns a reference to it. + + \sa operator-=() +*/ + +/*! + \fn QMarginsF &QMarginsF::operator-=(qreal subtrahend) + \overload + + Subtracts the \a subtrahend from each component of this object + and returns a reference to it. + + \sa operator+=() +*/ + +/*! + \fn QMarginsF &QMarginsF::operator*=(qreal factor) + + Multiplies each component of this object by \a factor + and returns a reference to it. + + \sa operator/=() +*/ + +/*! + \fn QMarginsF &QMarginsF::operator/=(qreal divisor) + + Divides each component of this object by \a divisor + and returns a reference to it. + + \sa operator*=() +*/ + +/*! + \fn QMargins QMarginsF::toMargins() const + + Returns an integer based copy of this margins object. + + Note that the components in the returned margins will be rounded to + the nearest integer. + + \sa QMarginsF() +*/ + +/***************************************************************************** + QMarginsF stream functions + *****************************************************************************/ +#ifndef QT_NO_DATASTREAM +/*! + \fn QDataStream &operator<<(QDataStream &stream, const QMarginsF &m) + \relates QMarginsF + + Writes margin \a m to the given \a stream and returns a + reference to the stream. + + \sa {Serializing Qt Data Types} +*/ + +QDataStream &operator<<(QDataStream &s, const QMarginsF &m) +{ + s << double(m.left()) << double(m.top()) << double(m.right()) << double(m.bottom()); + return s; +} + +/*! + \fn QDataStream &operator>>(QDataStream &stream, QMarginsF &m) + \relates QMarginsF + + Reads a margin from the given \a stream into margin \a m + and returns a reference to the stream. + + \sa {Serializing Qt Data Types} +*/ + +QDataStream &operator>>(QDataStream &s, QMarginsF &m) +{ + double left, top, right, bottom; + s >> left; + s >> top; + s >> right; + s >> bottom; + m = QMarginsF(qreal(left), qreal(top), qreal(right), qreal(bottom)); + return s; +} +#endif // QT_NO_DATASTREAM + +#ifndef QT_NO_DEBUG_STREAM +QDebug operator<<(QDebug dbg, const QMarginsF &m) { + dbg.nospace() << "QMarginsF(" << m.left() << ", " + << m.top() << ", " << m.right() << ", " << m.bottom() << ')'; + return dbg.space(); +} +#endif + QT_END_NAMESPACE diff --git a/src/corelib/tools/qmargins.h b/src/corelib/tools/qmargins.h index ad5e94cefe..d96ccaccae 100644 --- a/src/corelib/tools/qmargins.h +++ b/src/corelib/tools/qmargins.h @@ -42,10 +42,13 @@ #ifndef QMARGINS_H #define QMARGINS_H -#include <QtCore/qrect.h> +#include <QtCore/qnamespace.h> QT_BEGIN_NAMESPACE +/***************************************************************************** + QMargins class + *****************************************************************************/ class QMargins { @@ -149,51 +152,34 @@ Q_DECL_CONSTEXPR inline bool operator!=(const QMargins &m1, const QMargins &m2) m1.m_bottom != m2.m_bottom; } -Q_DECL_CONSTEXPR inline QRect operator+(const QRect &rectangle, const QMargins &margins) -{ - return QRect(QPoint(rectangle.left() - margins.left(), rectangle.top() - margins.top()), - QPoint(rectangle.right() + margins.right(), rectangle.bottom() + margins.bottom())); -} - -Q_DECL_CONSTEXPR inline QRect operator+(const QMargins &margins, const QRect &rectangle) -{ - return QRect(QPoint(rectangle.left() - margins.left(), rectangle.top() - margins.top()), - QPoint(rectangle.right() + margins.right(), rectangle.bottom() + margins.bottom())); -} - -inline QRect QRect::marginsAdded(const QMargins &margins) const -{ - return *this + margins; -} - -inline QRect QRect::marginsRemoved(const QMargins &margins) const +Q_DECL_CONSTEXPR inline QMargins operator+(const QMargins &m1, const QMargins &m2) { - return QRect(QPoint(x1 + margins.left(), y1 + margins.top()), - QPoint(x2 - margins.right(), y2 - margins.bottom())); + return QMargins(m1.left() + m2.left(), m1.top() + m2.top(), + m1.right() + m2.right(), m1.bottom() + m2.bottom()); } -inline QRect &QRect::operator+=(const QMargins &margins) +Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &m1, const QMargins &m2) { - *this = marginsAdded(margins); - return *this; + return QMargins(m1.left() - m2.left(), m1.top() - m2.top(), + m1.right() - m2.right(), m1.bottom() - m2.bottom()); } -inline QRect &QRect::operator-=(const QMargins &margins) +Q_DECL_CONSTEXPR inline QMargins operator+(const QMargins &lhs, int rhs) { - *this = marginsRemoved(margins); - return *this; + return QMargins(lhs.left() + rhs, lhs.top() + rhs, + lhs.right() + rhs, lhs.bottom() + rhs); } -Q_DECL_CONSTEXPR inline QMargins operator+(const QMargins &m1, const QMargins &m2) +Q_DECL_CONSTEXPR inline QMargins operator+(int lhs, const QMargins &rhs) { - return QMargins(m1.left() + m2.left(), m1.top() + m2.top(), - m1.right() + m2.right(), m1.bottom() + m2.bottom()); + return QMargins(rhs.left() + lhs, rhs.top() + lhs, + rhs.right() + lhs, rhs.bottom() + lhs); } -Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &m1, const QMargins &m2) +Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &lhs, int rhs) { - return QMargins(m1.left() - m2.left(), m1.top() - m2.top(), - m1.right() - m2.right(), m1.bottom() - m2.bottom()); + return QMargins(lhs.left() - rhs, lhs.top() - rhs, + lhs.right() - rhs, lhs.bottom() - rhs); } Q_DECL_CONSTEXPR inline QMargins operator*(const QMargins &margins, int factor) @@ -280,6 +266,11 @@ inline QMargins &QMargins::operator/=(qreal divisor) return *this = *this / divisor; } +Q_DECL_CONSTEXPR inline QMargins operator+(const QMargins &margins) +{ + return margins; +} + Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &margins) { return QMargins(-margins.left(), -margins.top(), -margins.right(), -margins.bottom()); @@ -289,6 +280,214 @@ Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &margins) Q_CORE_EXPORT QDebug operator<<(QDebug, const QMargins &); #endif +/***************************************************************************** + QMarginsF class + *****************************************************************************/ + +class QMarginsF +{ +public: + Q_DECL_CONSTEXPR QMarginsF(); + Q_DECL_CONSTEXPR QMarginsF(qreal left, qreal top, qreal right, qreal bottom); + Q_DECL_CONSTEXPR QMarginsF(const QMargins &margins); + + Q_DECL_CONSTEXPR bool isNull() const; + + Q_DECL_CONSTEXPR qreal left() const; + Q_DECL_CONSTEXPR qreal top() const; + Q_DECL_CONSTEXPR qreal right() const; + Q_DECL_CONSTEXPR qreal bottom() const; + + void setLeft(qreal left); + void setTop(qreal top); + void setRight(qreal right); + void setBottom(qreal bottom); + + QMarginsF &operator+=(const QMarginsF &margins); + QMarginsF &operator-=(const QMarginsF &margins); + QMarginsF &operator+=(qreal addend); + QMarginsF &operator-=(qreal subtrahend); + QMarginsF &operator*=(qreal factor); + QMarginsF &operator/=(qreal divisor); + + Q_DECL_CONSTEXPR inline QMargins toMargins() const; + +private: + qreal m_left; + qreal m_top; + qreal m_right; + qreal m_bottom; +}; + +Q_DECLARE_TYPEINFO(QMarginsF, Q_MOVABLE_TYPE); + +/***************************************************************************** + QMarginsF stream functions + *****************************************************************************/ + +#ifndef QT_NO_DATASTREAM +Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QMarginsF &); +Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QMarginsF &); +#endif + +/***************************************************************************** + QMarginsF inline functions + *****************************************************************************/ + +Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF() : m_left(0), m_top(0), m_right(0), m_bottom(0) {} + +Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF(qreal aleft, qreal atop, qreal aright, qreal abottom) + : m_left(aleft), m_top(atop), m_right(aright), m_bottom(abottom) {} + +Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF(const QMargins &margins) + : m_left(margins.left()), m_top(margins.top()), m_right(margins.right()), m_bottom(margins.bottom()) {} + +Q_DECL_CONSTEXPR inline bool QMarginsF::isNull() const +{ return qFuzzyIsNull(m_left) && qFuzzyIsNull(m_top) && qFuzzyIsNull(m_right) && qFuzzyIsNull(m_bottom); } + +Q_DECL_CONSTEXPR inline qreal QMarginsF::left() const +{ return m_left; } + +Q_DECL_CONSTEXPR inline qreal QMarginsF::top() const +{ return m_top; } + +Q_DECL_CONSTEXPR inline qreal QMarginsF::right() const +{ return m_right; } + +Q_DECL_CONSTEXPR inline qreal QMarginsF::bottom() const +{ return m_bottom; } + + +inline void QMarginsF::setLeft(qreal aleft) +{ m_left = aleft; } + +inline void QMarginsF::setTop(qreal atop) +{ m_top = atop; } + +inline void QMarginsF::setRight(qreal aright) +{ m_right = aright; } + +inline void QMarginsF::setBottom(qreal abottom) +{ m_bottom = abottom; } + +Q_DECL_CONSTEXPR inline bool operator==(const QMarginsF &lhs, const QMarginsF &rhs) +{ + return qFuzzyCompare(lhs.left(), rhs.left()) + && qFuzzyCompare(lhs.top(), rhs.top()) + && qFuzzyCompare(lhs.right(), rhs.right()) + && qFuzzyCompare(lhs.bottom(), rhs.bottom()); +} + +Q_DECL_CONSTEXPR inline bool operator!=(const QMarginsF &lhs, const QMarginsF &rhs) +{ + return !operator==(lhs, rhs); +} + +Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &lhs, const QMarginsF &rhs) +{ + return QMarginsF(lhs.left() + rhs.left(), lhs.top() + rhs.top(), + lhs.right() + rhs.right(), lhs.bottom() + rhs.bottom()); +} + +Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &lhs, const QMarginsF &rhs) +{ + return QMarginsF(lhs.left() - rhs.left(), lhs.top() - rhs.top(), + lhs.right() - rhs.right(), lhs.bottom() - rhs.bottom()); +} + +Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &lhs, qreal rhs) +{ + return QMarginsF(lhs.left() + rhs, lhs.top() + rhs, + lhs.right() + rhs, lhs.bottom() + rhs); +} + +Q_DECL_CONSTEXPR inline QMarginsF operator+(qreal lhs, const QMarginsF &rhs) +{ + return QMarginsF(rhs.left() + lhs, rhs.top() + lhs, + rhs.right() + lhs, rhs.bottom() + lhs); +} + +Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &lhs, qreal rhs) +{ + return QMarginsF(lhs.left() - rhs, lhs.top() - rhs, + lhs.right() - rhs, lhs.bottom() - rhs); +} + +Q_DECL_CONSTEXPR inline QMarginsF operator*(const QMarginsF &lhs, qreal rhs) +{ + return QMarginsF(lhs.left() * rhs, lhs.top() * rhs, + lhs.right() * rhs, lhs.bottom() * rhs); +} + +Q_DECL_CONSTEXPR inline QMarginsF operator*(qreal lhs, const QMarginsF &rhs) +{ + return QMarginsF(rhs.left() * lhs, rhs.top() * lhs, + rhs.right() * lhs, rhs.bottom() * lhs); +} + +Q_DECL_CONSTEXPR inline QMarginsF operator/(const QMarginsF &lhs, qreal divisor) +{ + return QMarginsF(lhs.left() / divisor, lhs.top() / divisor, + lhs.right() / divisor, lhs.bottom() / divisor); +} + +inline QMarginsF &QMarginsF::operator+=(const QMarginsF &margins) +{ + return *this = *this + margins; +} + +inline QMarginsF &QMarginsF::operator-=(const QMarginsF &margins) +{ + return *this = *this - margins; +} + +inline QMarginsF &QMarginsF::operator+=(qreal addend) +{ + m_left += addend; + m_top += addend; + m_right += addend; + m_bottom += addend; + return *this; +} + +inline QMarginsF &QMarginsF::operator-=(qreal subtrahend) +{ + m_left -= subtrahend; + m_top -= subtrahend; + m_right -= subtrahend; + m_bottom -= subtrahend; + return *this; +} + +inline QMarginsF &QMarginsF::operator*=(qreal factor) +{ + return *this = *this * factor; +} + +inline QMarginsF &QMarginsF::operator/=(qreal divisor) +{ + return *this = *this / divisor; +} + +Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &margins) +{ + return margins; +} + +Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &margins) +{ + return QMarginsF(-margins.left(), -margins.top(), -margins.right(), -margins.bottom()); +} + +Q_DECL_CONSTEXPR inline QMargins QMarginsF::toMargins() const +{ + return QMargins(qRound(m_left), qRound(m_top), qRound(m_right), qRound(m_bottom)); +} + +#ifndef QT_NO_DEBUG_STREAM +Q_CORE_EXPORT QDebug operator<<(QDebug, const QMarginsF &); +#endif + QT_END_NAMESPACE #endif // QMARGINS_H diff --git a/src/corelib/tools/qrect.cpp b/src/corelib/tools/qrect.cpp index fcff8931e8..33e8dd23fc 100644 --- a/src/corelib/tools/qrect.cpp +++ b/src/corelib/tools/qrect.cpp @@ -1162,6 +1162,74 @@ bool QRect::intersects(const QRect &r) const returns \c false. */ +/*! + \fn QRect operator+(const QRect &rectangle, const QMargins &margins) + \relates QRect + + Returns the \a rectangle grown by the \a margins. + + \since 5.1 +*/ + +/*! + \fn QRect operator+(const QMargins &margins, const QRect &rectangle) + \relates QRect + \overload + + Returns the \a rectangle grown by the \a margins. + + \since 5.1 +*/ + +/*! + \fn QRect operator-(const QRect &lhs, const QMargins &rhs) + \relates QRect + + Returns the \a lhs rectangle shrunken by the \a rhs margins. + + \since 5.3 +*/ + +/*! + \fn QRect QRect::marginsAdded(const QMargins &margins) const + + Returns a rectangle grown by the \a margins. + + \sa operator+=(), marginsRemoved(), operator-=() + + \since 5.1 +*/ + +/*! + \fn QRect QRect::operator+=(const QMargins &margins) const + + Adds the \a margins to the rectangle, growing it. + + \sa marginsAdded(), marginsRemoved(), operator-=() + + \since 5.1 +*/ + +/*! + \fn QRect QRect::marginsRemoved(const QMargins &margins) const + + Removes the \a margins from the rectangle, shrinking it. + + \sa marginsAdded(), operator+=(), operator-=() + + \since 5.1 +*/ + +/*! + \fn QRect QRect::operator -=(const QMargins &margins) const + + Returns a rectangle shrunk by the \a margins. + + \sa marginsRemoved(), operator+=(), marginsAdded() + + \since 5.1 +*/ + /***************************************************************************** QRect stream functions @@ -2311,6 +2379,71 @@ QRect QRectF::toAlignedRect() const returns \c false. */ +/*! + \fn QRectF operator+(const QRectF &lhs, const QMarginsF &rhs) + \relates QRectF + \since 5.3 + + Returns the \a lhs rectangle grown by the \a rhs margins. +*/ + +/*! + \fn QRectF operator-(const QRectF &lhs, const QMarginsF &rhs) + \relates QRectF + \since 5.3 + + Returns the \a lhs rectangle grown by the \a rhs margins. +*/ + +/*! + \fn QRectF operator+(const QMarginsF &lhs, const QRectF &rhs) + \relates QRectF + \overload + \since 5.3 + + Returns the \a lhs rectangle grown by the \a rhs margins. +*/ + +/*! + \fn QRectF QRectF::marginsAdded(const QMarginsF &margins) const + \relates QRectF + \since 5.3 + + Returns a rectangle grown by the \a margins. + + \sa operator+=(), marginsRemoved(), operator-=() +*/ + +/*! + \fn QRectF QRectF::marginsRemoved(const QMarginsF &margins) const + \relates QRectF + \since 5.3 + + Removes the \a margins from the rectangle, shrinking it. + + \sa marginsAdded(), operator+=(), operator-=() +*/ + +/*! + \fn QRectF QRectF::operator+=(const QMarginsF &margins) + \relates QRectF + \since 5.3 + + Adds the \a margins to the rectangle, growing it. + + \sa marginsAdded(), marginsRemoved(), operator-=() +*/ + +/*! + \fn QRectF QRectF::operator-=(const QMarginsF &margins) + \relates QRectF + \since 5.3 + + Returns a rectangle shrunk by the \a margins. + + \sa marginsRemoved(), operator+=(), marginsAdded() +*/ + /***************************************************************************** QRectF stream functions *****************************************************************************/ diff --git a/src/corelib/tools/qrect.h b/src/corelib/tools/qrect.h index 22696f9edf..2bb74e8221 100644 --- a/src/corelib/tools/qrect.h +++ b/src/corelib/tools/qrect.h @@ -42,6 +42,7 @@ #ifndef QRECT_H #define QRECT_H +#include <QtCore/qmargins.h> #include <QtCore/qsize.h> #include <QtCore/qpoint.h> @@ -51,8 +52,6 @@ QT_BEGIN_NAMESPACE -class QMargins; - class Q_CORE_EXPORT QRect { public: @@ -138,8 +137,8 @@ public: inline QRect intersected(const QRect &other) const; bool intersects(const QRect &r) const; - inline QRect marginsAdded(const QMargins &margins) const; - inline QRect marginsRemoved(const QMargins &margins) const; + Q_DECL_CONSTEXPR inline QRect marginsAdded(const QMargins &margins) const; + Q_DECL_CONSTEXPR inline QRect marginsRemoved(const QMargins &margins) const; inline QRect &operator+=(const QMargins &margins); inline QRect &operator-=(const QMargins &margins); @@ -452,6 +451,48 @@ 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; } +Q_DECL_CONSTEXPR inline QRect operator+(const QRect &rectangle, const QMargins &margins) +{ + return QRect(QPoint(rectangle.left() - margins.left(), rectangle.top() - margins.top()), + QPoint(rectangle.right() + margins.right(), rectangle.bottom() + margins.bottom())); +} + +Q_DECL_CONSTEXPR inline QRect operator+(const QMargins &margins, const QRect &rectangle) +{ + return QRect(QPoint(rectangle.left() - margins.left(), rectangle.top() - margins.top()), + QPoint(rectangle.right() + margins.right(), rectangle.bottom() + margins.bottom())); +} + +Q_DECL_CONSTEXPR inline QRect operator-(const QRect &lhs, const QMargins &rhs) +{ + return QRect(QPoint(lhs.left() + rhs.left(), lhs.top() + rhs.top()), + QPoint(lhs.right() - rhs.right(), lhs.bottom() - rhs.bottom())); +} + +Q_DECL_CONSTEXPR inline QRect QRect::marginsAdded(const QMargins &margins) const +{ + return QRect(QPoint(x1 - margins.left(), y1 - margins.top()), + QPoint(x2 + margins.right(), y2 + margins.bottom())); +} + +Q_DECL_CONSTEXPR inline QRect QRect::marginsRemoved(const QMargins &margins) const +{ + return QRect(QPoint(x1 + margins.left(), y1 + margins.top()), + QPoint(x2 - margins.right(), y2 - margins.bottom())); +} + +inline QRect &QRect::operator+=(const QMargins &margins) +{ + *this = marginsAdded(margins); + return *this; +} + +inline QRect &QRect::operator-=(const QMargins &margins) +{ + *this = marginsRemoved(margins); + return *this; +} + #ifndef QT_NO_DEBUG_STREAM Q_CORE_EXPORT QDebug operator<<(QDebug, const QRect &); #endif @@ -543,6 +584,11 @@ public: inline QRectF intersected(const QRectF &other) const; bool intersects(const QRectF &r) const; + Q_DECL_CONSTEXPR inline QRectF marginsAdded(const QMarginsF &margins) const; + Q_DECL_CONSTEXPR inline QRectF marginsRemoved(const QMarginsF &margins) const; + inline QRectF &operator+=(const QMarginsF &margins); + inline QRectF &operator-=(const QMarginsF &margins); + #if QT_DEPRECATED_SINCE(5, 0) QT_DEPRECATED QRectF unite(const QRectF &r) const { return united(r); } QT_DEPRECATED QRectF intersect(const QRectF &r) const { return intersected(r); } @@ -784,6 +830,48 @@ Q_DECL_CONSTEXPR inline QRect QRectF::toRect() const return QRect(qRound(xp), qRound(yp), qRound(w), qRound(h)); } +Q_DECL_CONSTEXPR inline QRectF operator+(const QRectF &lhs, const QMarginsF &rhs) +{ + return QRectF(QPointF(lhs.left() - rhs.left(), lhs.top() - rhs.top()), + QSizeF(lhs.width() + rhs.left() + rhs.right(), lhs.height() + rhs.top() + rhs.bottom())); +} + +Q_DECL_CONSTEXPR inline QRectF operator+(const QMarginsF &lhs, const QRectF &rhs) +{ + return QRectF(QPointF(rhs.left() - lhs.left(), rhs.top() - lhs.top()), + QSizeF(rhs.width() + lhs.left() + lhs.right(), rhs.height() + lhs.top() + lhs.bottom())); +} + +Q_DECL_CONSTEXPR inline QRectF operator-(const QRectF &lhs, const QMarginsF &rhs) +{ + return QRectF(QPointF(lhs.left() + rhs.left(), lhs.top() + rhs.top()), + QSizeF(lhs.width() - rhs.left() - rhs.right(), lhs.height() - rhs.top() - rhs.bottom())); +} + +Q_DECL_CONSTEXPR inline QRectF QRectF::marginsAdded(const QMarginsF &margins) const +{ + return QRectF(QPointF(xp - margins.left(), yp - margins.top()), + QSizeF(w + margins.left() + margins.right(), h + margins.top() + margins.bottom())); +} + +Q_DECL_CONSTEXPR inline QRectF QRectF::marginsRemoved(const QMarginsF &margins) const +{ + return QRectF(QPointF(xp + margins.left(), yp + margins.top()), + QSizeF(w - margins.left() - margins.right(), h - margins.top() - margins.bottom())); +} + +inline QRectF &QRectF::operator+=(const QMarginsF &margins) +{ + *this = marginsAdded(margins); + return *this; +} + +inline QRectF &QRectF::operator-=(const QMarginsF &margins) +{ + *this = marginsRemoved(margins); + return *this; +} + #ifndef QT_NO_DEBUG_STREAM Q_CORE_EXPORT QDebug operator<<(QDebug, const QRectF &); #endif diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 50f616a010..116da9e383 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -210,7 +210,7 @@ inline RetType UnrollTailLoop<0>::exec(int, RetType returnIfExited, Functor1, Fu #endif // conversion between Latin 1 and UTF-16 -static void qt_from_latin1(ushort *dst, const char *str, size_t size) +void qt_from_latin1(ushort *dst, const char *str, size_t size) { /* SIMD: * Unpacking with SSE has been shown to improve performance on recent CPUs @@ -1494,6 +1494,10 @@ QString::QString(QChar ch) \internal */ +/*! \fn QString::QString(QStringDataPtr) + \internal +*/ + /*! \fn QString &QString::operator=(const Null &) \internal */ @@ -6424,8 +6428,8 @@ QString &QString::setNum(qulonglong n, int base) to the given \a format and \a precision, and returns a reference to the string. - The \a format can be 'f', 'F', 'e', 'E', 'g' or 'G' (see the - arg() function documentation for an explanation of the formats). + The \a format can be 'e', 'E', 'f', 'g' or 'G' (see + \l{Argument Formats} for an explanation of the formats). The formatting always uses QLocale::C, i.e., English/UnitedStates. To get a localized string representation of a number, use @@ -8465,6 +8469,11 @@ bool operator<(const QStringRef &s1,const QStringRef &s2) */ /*! + \typedef QString::Data + \internal +*/ + +/*! \typedef QString::DataPtr \internal */ diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri index 7ef7e6f46a..1e4a503778 100644 --- a/src/corelib/tools/tools.pri +++ b/src/corelib/tools/tools.pri @@ -1,5 +1,7 @@ # Qt tools module +intel_icc: QMAKE_CXXFLAGS += -fp-model strict + HEADERS += \ tools/qalgorithms.h \ tools/qarraydata.h \ |