summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2019-09-04 14:33:40 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2019-09-04 14:33:40 +0200
commitf255b1e8e297e7e1363921580007145cff574e0d (patch)
tree9a799be282e6c0d6544d9f8c872073f83e6c0475 /src/corelib/tools
parent7e8705f6632428a8d9a937ab5fe087999347b3dd (diff)
parentbf8fcab8bb92ff534c5cec048d6dbebb3b73a348 (diff)
Merge remote-tracking branch 'origin/dev' into wip/qt6
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qbitarray.cpp20
-rw-r--r--src/corelib/tools/qcryptographichash.cpp8
-rw-r--r--src/corelib/tools/qeasingcurve.h3
-rw-r--r--src/corelib/tools/qlinkedlist.h7
-rw-r--r--src/corelib/tools/qlist.h11
-rw-r--r--src/corelib/tools/qpoint.cpp23
-rw-r--r--src/corelib/tools/qpoint.h4
-rw-r--r--src/corelib/tools/qset.h7
-rw-r--r--src/corelib/tools/qset.qdoc3
-rw-r--r--src/corelib/tools/qsize.cpp18
-rw-r--r--src/corelib/tools/qsize.h11
-rw-r--r--src/corelib/tools/qtimeline.h4
-rw-r--r--src/corelib/tools/qvarlengtharray.h7
-rw-r--r--src/corelib/tools/qvector.h7
-rw-r--r--src/corelib/tools/tools.pri14
15 files changed, 125 insertions, 22 deletions
diff --git a/src/corelib/tools/qbitarray.cpp b/src/corelib/tools/qbitarray.cpp
index 4e8e3c241e..f0b81cce66 100644
--- a/src/corelib/tools/qbitarray.cpp
+++ b/src/corelib/tools/qbitarray.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
+** Copyright (C) 2019 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -132,12 +132,12 @@ QT_BEGIN_NAMESPACE
* We overallocate the byte array by 1 byte. The first user bit is at
* d.data()[1]. On the extra first byte, we store the difference between the
* number of bits in the byte array (including this byte) and the number of
- * bits in the bit array. Therefore, it's always a number between 8 and 15.
+ * bits in the bit array. Therefore, for a non-empty QBitArray, it's always a
+ * number between 8 and 15. For the empty one, d is the an empty QByteArray and
+ * *d.constData() is the QByteArray's terminating NUL (0) byte.
*
* This allows for fast calculation of the bit array size:
* inline int size() const { return (d.size() << 3) - *d.constData(); }
- *
- * Note: for an array of zero size, *d.constData() is the QByteArray implicit NUL.
*/
/*!
@@ -154,8 +154,8 @@ QBitArray::QBitArray(int size, bool value)
uchar* c = reinterpret_cast<uchar*>(d.data());
memset(c + 1, value ? 0xff : 0, d.size() - 1);
*c = d.size()*8 - size;
- if (value && size && size % 8)
- *(c+1+size/8) &= (1 << (size%8)) - 1;
+ if (value && size && size & 7)
+ *(c+1+size/8) &= (1 << (size & 7)) - 1;
}
/*! \fn int QBitArray::size() const
@@ -227,8 +227,8 @@ void QBitArray::resize(int size)
uchar* c = reinterpret_cast<uchar*>(d.data());
if (size > (s << 3))
memset(c + s, 0, d.size() - s);
- else if ( size % 8)
- *(c+1+size/8) &= (1 << (size%8)) - 1;
+ else if (size & 7)
+ *(c+1+size/8) &= (1 << (size & 7)) - 1;
*c = d.size()*8 - size;
}
}
@@ -326,6 +326,8 @@ void QBitArray::fill(bool value, int begin, int end)
QBitArray QBitArray::fromBits(const char *data, qsizetype size)
{
QBitArray result;
+ if (size == 0)
+ return result;
qsizetype nbytes = (size + 7) / 8;
result.d = QByteArray(nbytes + 1, Qt::Uninitialized);
@@ -334,7 +336,7 @@ QBitArray QBitArray::fromBits(const char *data, qsizetype size)
// clear any unused bits from the last byte
if (size & 7)
- bits[nbytes] &= 0xffU >> (size & 7);
+ bits[nbytes] &= 0xffU >> (8 - (size & 7));
*bits = result.d.size() * 8 - size;
return result;
diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp
index ee7657789c..fa8d21e07a 100644
--- a/src/corelib/tools/qcryptographichash.cpp
+++ b/src/corelib/tools/qcryptographichash.cpp
@@ -391,19 +391,19 @@ void QCryptographicHash::addData(const char *data, int length)
break;
case RealSha3_224:
case Keccak_224:
- sha3Update(&d->sha3Context, reinterpret_cast<const BitSequence *>(data), length*8);
+ sha3Update(&d->sha3Context, reinterpret_cast<const BitSequence *>(data), quint64(length) * 8);
break;
case RealSha3_256:
case Keccak_256:
- sha3Update(&d->sha3Context, reinterpret_cast<const BitSequence *>(data), length*8);
+ sha3Update(&d->sha3Context, reinterpret_cast<const BitSequence *>(data), quint64(length) * 8);
break;
case RealSha3_384:
case Keccak_384:
- sha3Update(&d->sha3Context, reinterpret_cast<const BitSequence *>(data), length*8);
+ sha3Update(&d->sha3Context, reinterpret_cast<const BitSequence *>(data), quint64(length) * 8);
break;
case RealSha3_512:
case Keccak_512:
- sha3Update(&d->sha3Context, reinterpret_cast<const BitSequence *>(data), length*8);
+ sha3Update(&d->sha3Context, reinterpret_cast<const BitSequence *>(data), quint64(length) * 8);
break;
#endif
}
diff --git a/src/corelib/tools/qeasingcurve.h b/src/corelib/tools/qeasingcurve.h
index f7a1d6bdc0..81833a758f 100644
--- a/src/corelib/tools/qeasingcurve.h
+++ b/src/corelib/tools/qeasingcurve.h
@@ -41,6 +41,9 @@
#define QEASINGCURVE_H
#include <QtCore/qglobal.h>
+
+QT_REQUIRE_CONFIG(easingcurve);
+
#include <QtCore/qobjectdefs.h>
#include <QtCore/qvector.h>
diff --git a/src/corelib/tools/qlinkedlist.h b/src/corelib/tools/qlinkedlist.h
index 996a50fd1b..8970d39be0 100644
--- a/src/corelib/tools/qlinkedlist.h
+++ b/src/corelib/tools/qlinkedlist.h
@@ -275,6 +275,13 @@ private:
template <typename T>
Q_DECLARE_TYPEINFO_BODY(QLinkedList<T>, Q_MOVABLE_TYPE|Q_RELOCATABLE_TYPE);
+#if defined(__cpp_deduction_guides) && __cpp_deduction_guides >= 201606
+template <typename InputIterator,
+ typename ValueType = typename std::iterator_traits<InputIterator>::value_type,
+ QtPrivate::IfIsInputIterator<InputIterator> = true>
+QLinkedList(InputIterator, InputIterator) -> QLinkedList<ValueType>;
+#endif
+
template <typename T>
inline QLinkedList<T>::~QLinkedList()
{
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index 70bbc11ad2..be987c359b 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -112,7 +112,7 @@ struct Q_CORE_EXPORT QListData {
void remove(int i);
void remove(int i, int n);
void move(int from, int to);
- inline int size() const noexcept { return d->end - d->begin; }
+ inline int size() const noexcept { return int(d->end - d->begin); } // q6sizetype
inline bool isEmpty() const noexcept { return d->end == d->begin; }
inline void **at(int i) const noexcept { return d->array + d->begin + i; }
inline void **begin() const noexcept { return d->array + d->begin; }
@@ -446,6 +446,13 @@ private:
inline int count_impl(const T &, QListData::ArrayCompatibleLayout) const;
};
+#if defined(__cpp_deduction_guides) && __cpp_deduction_guides >= 201606
+template <typename InputIterator,
+ typename ValueType = typename std::iterator_traits<InputIterator>::value_type,
+ QtPrivate::IfIsInputIterator<InputIterator> = true>
+QList(InputIterator, InputIterator) -> QList<ValueType>;
+#endif
+
#if defined(Q_CC_BOR)
template <typename T>
Q_INLINE_TEMPLATE T &QList<T>::Node::t()
@@ -1044,7 +1051,7 @@ int lastIndexOf(const QList<T> &list, const U &u, int from)
Node *n = reinterpret_cast<Node *>(list.p.at(from + 1));
while (n-- != b) {
if (n->t() == u)
- return n - b;
+ return typename QList<T>::difference_type(n - b);
}
}
return -1;
diff --git a/src/corelib/tools/qpoint.cpp b/src/corelib/tools/qpoint.cpp
index e98eaac4fc..432fb33297 100644
--- a/src/corelib/tools/qpoint.cpp
+++ b/src/corelib/tools/qpoint.cpp
@@ -138,6 +138,17 @@ QT_BEGIN_NAMESPACE
\sa y(), setX()
*/
+/*!
+ \fn QPoint::transposed() const
+ \since 5.14
+
+ Returns a point with x and y coordinates exchanged:
+ \code
+ QPoint{1, 2}.transposed() // {2, 1}
+ \endcode
+
+ \sa x(), y(), setX(), setY()
+*/
/*!
\fn int &QPoint::rx()
@@ -583,6 +594,18 @@ QDebug operator<<(QDebug dbg, const QPointF &p)
*/
/*!
+ \fn QPointF::transposed() const
+ \since 5.14
+
+ Returns a point with x and y coordinates exchanged:
+ \code
+ QPointF{1.0, 2.0}.transposed() // {2.0, 1.0}
+ \endcode
+
+ \sa x(), y(), setX(), setY()
+*/
+
+/*!
\fn qreal& QPointF::rx()
Returns a reference to the x coordinate of this point.
diff --git a/src/corelib/tools/qpoint.h b/src/corelib/tools/qpoint.h
index 34df673b93..fe952f95da 100644
--- a/src/corelib/tools/qpoint.h
+++ b/src/corelib/tools/qpoint.h
@@ -64,6 +64,8 @@ public:
Q_DECL_CONSTEXPR inline int manhattanLength() const;
+ Q_DECL_CONSTEXPR QPoint transposed() const noexcept { return {yp, xp}; }
+
Q_DECL_RELAXED_CONSTEXPR inline int &rx();
Q_DECL_RELAXED_CONSTEXPR inline int &ry();
@@ -232,6 +234,8 @@ public:
Q_DECL_RELAXED_CONSTEXPR inline void setX(qreal x);
Q_DECL_RELAXED_CONSTEXPR inline void setY(qreal y);
+ Q_DECL_CONSTEXPR QPointF transposed() const noexcept { return {yp, xp}; }
+
Q_DECL_RELAXED_CONSTEXPR inline qreal &rx();
Q_DECL_RELAXED_CONSTEXPR inline qreal &ry();
diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h
index f6db47ed59..6683188ad4 100644
--- a/src/corelib/tools/qset.h
+++ b/src/corelib/tools/qset.h
@@ -263,6 +263,13 @@ private:
}
};
+#if defined(__cpp_deduction_guides) && __cpp_deduction_guides >= 201606
+template <typename InputIterator,
+ typename ValueType = typename std::iterator_traits<InputIterator>::value_type,
+ QtPrivate::IfIsInputIterator<InputIterator> = true>
+QSet(InputIterator, InputIterator) -> QSet<ValueType>;
+#endif
+
template <typename T>
uint qHash(const QSet<T> &key, uint seed = 0)
noexcept(noexcept(qHashRangeCommutative(key.begin(), key.end(), seed)))
diff --git a/src/corelib/tools/qset.qdoc b/src/corelib/tools/qset.qdoc
index 2e7a5a29ce..084523ed4b 100644
--- a/src/corelib/tools/qset.qdoc
+++ b/src/corelib/tools/qset.qdoc
@@ -108,9 +108,6 @@
Constructs a set with a copy of each of the elements in the
initializer list \a list.
-
- This function is only available if the program is being
- compiled in C++11 mode.
*/
/*! \fn template <class T> template<typename InputIterator> QSet<T>::QSet(InputIterator first, InputIterator last)
diff --git a/src/corelib/tools/qsize.cpp b/src/corelib/tools/qsize.cpp
index fe508ad459..2cbaae117d 100644
--- a/src/corelib/tools/qsize.cpp
+++ b/src/corelib/tools/qsize.cpp
@@ -390,7 +390,25 @@ QSize QSize::scaled(const QSize &s, Qt::AspectRatioMode mode) const noexcept
\sa expandedTo(), scale()
*/
+/*!
+ \fn QSize QSize::grownBy(QMargins margins) const
+ \fn QSizeF QSizeF::grownBy(QMarginsF margins) const
+ \since 5.14
+
+ Returns the size that results from growing this size by \a margins.
+
+ \sa shrunkBy()
+*/
+/*!
+ \fn QSize QSize::shrunkBy(QMargins margins) const
+ \fn QSizeF QSizeF::shrunkBy(QMarginsF margins) const
+ \since 5.14
+
+ Returns the size that results from shrinking this size by \a margins.
+
+ \sa grownBy()
+*/
/*****************************************************************************
QSize stream functions
diff --git a/src/corelib/tools/qsize.h b/src/corelib/tools/qsize.h
index 4114609856..06de1cd63f 100644
--- a/src/corelib/tools/qsize.h
+++ b/src/corelib/tools/qsize.h
@@ -41,6 +41,7 @@
#define QSIZE_H
#include <QtCore/qnamespace.h>
+#include <QtCore/qmargins.h>
#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
struct CGSize;
@@ -74,6 +75,11 @@ public:
Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QSize expandedTo(const QSize &) const noexcept;
Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QSize boundedTo(const QSize &) const noexcept;
+ Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QSize grownBy(QMargins m) const noexcept
+ { return {width() + m.left() + m.right(), height() + m.top() + m.bottom()}; }
+ Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QSize shrunkBy(QMargins m) const noexcept
+ { return {width() - m.left() - m.right(), height() - m.top() - m.bottom()}; }
+
Q_DECL_RELAXED_CONSTEXPR inline int &rwidth() noexcept;
Q_DECL_RELAXED_CONSTEXPR inline int &rheight() noexcept;
@@ -238,6 +244,11 @@ public:
Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QSizeF expandedTo(const QSizeF &) const noexcept;
Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QSizeF boundedTo(const QSizeF &) const noexcept;
+ Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QSizeF grownBy(QMarginsF m) const noexcept
+ { return {width() + m.left() + m.right(), height() + m.top() + m.bottom()}; }
+ Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QSizeF shrunkBy(QMarginsF m) const noexcept
+ { return {width() - m.left() - m.right(), height() - m.top() - m.bottom()}; }
+
Q_DECL_RELAXED_CONSTEXPR inline qreal &rwidth() noexcept;
Q_DECL_RELAXED_CONSTEXPR inline qreal &rheight() noexcept;
diff --git a/src/corelib/tools/qtimeline.h b/src/corelib/tools/qtimeline.h
index d9982bdb58..9a60cd679f 100644
--- a/src/corelib/tools/qtimeline.h
+++ b/src/corelib/tools/qtimeline.h
@@ -40,6 +40,10 @@
#ifndef QTIMELINE_H
#define QTIMELINE_H
+#include <QtCore/qglobal.h>
+
+QT_REQUIRE_CONFIG(easingcurve);
+
#include <QtCore/qeasingcurve.h>
#include <QtCore/qobject.h>
diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h
index 2f62526076..253d05ba2b 100644
--- a/src/corelib/tools/qvarlengtharray.h
+++ b/src/corelib/tools/qvarlengtharray.h
@@ -265,6 +265,13 @@ private:
}
};
+#if defined(__cpp_deduction_guides) && __cpp_deduction_guides >= 201606
+template <typename InputIterator,
+ typename ValueType = typename std::iterator_traits<InputIterator>::value_type,
+ QtPrivate::IfIsInputIterator<InputIterator> = true>
+QVarLengthArray(InputIterator, InputIterator) -> QVarLengthArray<ValueType>;
+#endif
+
template <class T, int Prealloc>
Q_INLINE_TEMPLATE QVarLengthArray<T, Prealloc>::QVarLengthArray(int asize)
: s(asize) {
diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h
index ebe6527d89..62fbdb4a2a 100644
--- a/src/corelib/tools/qvector.h
+++ b/src/corelib/tools/qvector.h
@@ -326,6 +326,13 @@ private:
class AlignmentDummy { Data header; T array[1]; };
};
+#if defined(__cpp_deduction_guides) && __cpp_deduction_guides >= 201606
+template <typename InputIterator,
+ typename ValueType = typename std::iterator_traits<InputIterator>::value_type,
+ QtPrivate::IfIsInputIterator<InputIterator> = true>
+QVector(InputIterator, InputIterator) -> QVector<ValueType>;
+#endif
+
#ifdef Q_CC_MSVC
// behavior change: an object of POD type constructed with an initializer of the form ()
// will be default-initialized
diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri
index a2236f90f2..40c84157cd 100644
--- a/src/corelib/tools/tools.pri
+++ b/src/corelib/tools/tools.pri
@@ -12,7 +12,6 @@ HEADERS += \
tools/qcontainerfwd.h \
tools/qcontainertools_impl.h \
tools/qcryptographichash.h \
- tools/qeasingcurve.h \
tools/qfreelist_p.h \
tools/qhash.h \
tools/qhashfunctions.h \
@@ -43,7 +42,6 @@ HEADERS += \
tools/qsimd_p.h \
tools/qsize.h \
tools/qstack.h \
- tools/qtimeline.h \
tools/qtools_p.h \
tools/qvarlengtharray.h \
tools/qvector.h \
@@ -54,7 +52,6 @@ SOURCES += \
tools/qarraydata.cpp \
tools/qbitarray.cpp \
tools/qcryptographichash.cpp \
- tools/qeasingcurve.cpp \
tools/qfreelist.cpp \
tools/qhash.cpp \
tools/qline.cpp \
@@ -72,7 +69,6 @@ SOURCES += \
tools/qsharedpointer.cpp \
tools/qsimd.cpp \
tools/qsize.cpp \
- tools/qtimeline.cpp \
tools/qversionnumber.cpp
msvc: NO_PCH_SOURCES += tools/qvector_msvc.cpp
@@ -104,6 +100,16 @@ qtConfig(system-doubleconversion) {
include($$PWD/../../3rdparty/double-conversion/double-conversion.pri)
}
+qtConfig(easingcurve) {
+ HEADERS += \
+ tools/qeasingcurve.h \
+ tools/qtimeline.h
+
+ SOURCES += \
+ tools/qeasingcurve.cpp \
+ tools/qtimeline.cpp
+}
+
# Note: libm should be present by default becaue this is C++
unix:!macx-icc:!vxworks:!haiku:!integrity:!wasm: LIBS_PRIVATE += -lm