diff options
28 files changed, 606 insertions, 323 deletions
diff --git a/dist/changes-5.1.0 b/dist/changes-5.1.0 index 2b432fc811..4aa06cf342 100644 --- a/dist/changes-5.1.0 +++ b/dist/changes-5.1.0 @@ -46,6 +46,14 @@ Third party components QtCore ------ + - QRect: + * Added marginsAdded(), marginsRemoved() and operators +, -, +=, -= + taking a QMargins object allowing for conveniently adding or removing + margins. + - QMargins: + * Added operators for adding and subtracting QMargins objects, + multiplication and division for int/qreal and unary minus. + - QtGui diff --git a/src/corelib/global/qfeatures.h b/src/corelib/global/qfeatures.h index a63d3a3b3d..da5ef4687b 100644 --- a/src/corelib/global/qfeatures.h +++ b/src/corelib/global/qfeatures.h @@ -154,6 +154,9 @@ // Properties //#define QT_NO_PROPERTIES +// QRegularExpression +//#define QT_NO_REGULAREXPRESSION + // Resize Handler //#define QT_NO_RESIZEHANDLER diff --git a/src/corelib/global/qfeatures.txt b/src/corelib/global/qfeatures.txt index ad1ca5a6d5..25fd28c4cd 100644 --- a/src/corelib/global/qfeatures.txt +++ b/src/corelib/global/qfeatures.txt @@ -28,6 +28,13 @@ Requires: Name: CssParser SeeAlso: ??? +Feature: REGULAREXPRESSION +Description: Perl-compatible regular expression APIs +Section: Kernel +Requires: +Name: QRegularExpression +SeeAlso: ??? + Feature: CONCURRENT Description: Provides a high-level multi-threaded APIs Section: Kernel diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 0d737ac1a3..82b6ed54d1 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -944,11 +944,11 @@ bool QMetaType::save(QDataStream &stream, int type, const void *data) break; #endif #ifndef QT_BOOTSTRAPPED -#ifndef QT_NO_REGEXP +#ifndef QT_NO_REGULAREXPRESSION case QMetaType::QRegularExpression: stream << *static_cast<const NS(QRegularExpression)*>(data); break; -#endif // QT_NO_REGEXP +#endif // QT_NO_REGULAREXPRESSION case QMetaType::QEasingCurve: stream << *static_cast<const NS(QEasingCurve)*>(data); break; @@ -1167,11 +1167,11 @@ bool QMetaType::load(QDataStream &stream, int type, void *data) break; #endif #ifndef QT_BOOTSTRAPPED -#ifndef QT_NO_REGEXP +#ifndef QT_NO_REGULAREXPRESSION case QMetaType::QRegularExpression: stream >> *static_cast< NS(QRegularExpression)*>(data); break; -#endif // QT_NO_REGEXP +#endif // QT_NO_REGULAREXPRESSION case QMetaType::QEasingCurve: stream >> *static_cast< NS(QEasingCurve)*>(data); break; diff --git a/src/corelib/kernel/qmetatype_p.h b/src/corelib/kernel/qmetatype_p.h index 351baa9aaa..f31392e00d 100644 --- a/src/corelib/kernel/qmetatype_p.h +++ b/src/corelib/kernel/qmetatype_p.h @@ -221,7 +221,7 @@ template<> struct TypeDefinition<QPointF> { static const bool IsAvailable = fals #ifdef QT_NO_REGEXP template<> struct TypeDefinition<QRegExp> { static const bool IsAvailable = false; }; #endif -#if defined(QT_BOOTSTRAPPED) || defined(QT_NO_REGEXP) +#if defined(QT_BOOTSTRAPPED) || defined(QT_NO_REGULAREXPRESSION) template<> struct TypeDefinition<QRegularExpression> { static const bool IsAvailable = false; }; #endif #ifdef QT_NO_SHORTCUT diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 9091b5579e..28b0b66ba8 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -1690,7 +1690,7 @@ void qt_qFindChildren_helper(const QObject *parent, const QRegExp &re, } #endif // QT_NO_REGEXP -#ifndef QT_NO_REGEXP +#ifndef QT_NO_REGULAREXPRESSION /*! \internal */ @@ -1712,7 +1712,7 @@ void qt_qFindChildren_helper(const QObject *parent, const QRegularExpression &re qt_qFindChildren_helper(obj, re, mo, list, options); } } -#endif // QT_NO_REGEXP +#endif // QT_NO_REGULAREXPRESSION /*! \internal diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h index e9316c98f0..36aded2cdb 100644 --- a/src/corelib/kernel/qobject.h +++ b/src/corelib/kernel/qobject.h @@ -73,7 +73,7 @@ class QWidget; #ifndef QT_NO_REGEXP class QRegExp; #endif -#ifndef QT_NO_REGEXP +#ifndef QT_NO_REGULAREXPRESSION class QRegularExpression; #endif #ifndef QT_NO_USERDATA @@ -187,7 +187,7 @@ public: } #endif -#ifndef QT_NO_REGEXP +#ifndef QT_NO_REGULAREXPRESSION template<typename T> inline QList<T> findChildren(const QRegularExpression &re, Qt::FindChildOptions options = Qt::FindChildrenRecursively) const { diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 26deeba6a2..a88b7d2b1f 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -1529,10 +1529,13 @@ QVariant::QVariant(const QLocale &l) QVariant::QVariant(const QRegExp ®Exp) : d(RegExp) { v_construct<QRegExp>(&d, regExp); } +#endif // QT_NO_REGEXP #ifndef QT_BOOTSTRAPPED +#ifndef QT_NO_REGULAREXPRESSION QVariant::QVariant(const QRegularExpression &re) : d(RegularExpression) { v_construct<QRegularExpression>(&d, re); } +#endif QVariant::QVariant(const QUuid &uuid) : d(Uuid) { v_construct<QUuid>(&d, uuid); } @@ -1552,7 +1555,6 @@ QVariant::QVariant(const QJsonDocument &jsonDocument) : d(QMetaType::QJsonDocument) { v_construct<QJsonDocument>(&d, jsonDocument); } #endif // QT_BOOTSTRAPPED -#endif // QT_NO_REGEXP /*! Returns the storage type of the value stored in the variant. @@ -2214,6 +2216,7 @@ QRegExp QVariant::toRegExp() const } #endif +#ifndef QT_BOOTSTRAPPED /*! \fn QRegularExpression QVariant::toRegularExpression() const \since 5.0 @@ -2223,13 +2226,12 @@ QRegExp QVariant::toRegExp() const \sa canConvert(), convert() */ -#ifndef QT_BOOTSTRAPPED -#ifndef QT_NO_REGEXP +#ifndef QT_NO_REGULAREXPRESSION QRegularExpression QVariant::toRegularExpression() const { return qVariantToHelper<QRegularExpression>(d, handlerManager); } -#endif +#endif // QT_NO_REGULAREXPRESSION /*! \since 5.0 diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 86b43cf69a..692af9afc6 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -76,8 +76,10 @@ class QRect; class QRectF; #ifndef QT_NO_REGEXP class QRegExp; -class QRegularExpression; #endif // QT_NO_REGEXP +#ifndef QT_NO_REGULAREXPRESSION +class QRegularExpression; +#endif // QT_NO_REGULAREXPRESSION class QTextFormat; class QTextLength; class QUrl; @@ -240,11 +242,11 @@ class Q_CORE_EXPORT QVariant QVariant(const QLocale &locale); #ifndef QT_NO_REGEXP QVariant(const QRegExp ®Exp); -#ifndef QT_BOOTSRAPPED - QVariant(const QRegularExpression &re); -#endif // QT_BOOTSTRAPPED #endif // QT_NO_REGEXP #ifndef QT_BOOTSTRAPPED +#ifndef QT_NO_REGULAREXPRESSION + QVariant(const QRegularExpression &re); +#endif // QT_NO_REGULAREXPRESSION QVariant(const QUrl &url); QVariant(const QEasingCurve &easing); QVariant(const QUuid &uuid); @@ -253,7 +255,7 @@ class Q_CORE_EXPORT QVariant QVariant(const QJsonObject &jsonObject); QVariant(const QJsonArray &jsonArray); QVariant(const QJsonDocument &jsonDocument); -#endif +#endif // QT_BOOTSTRAPPED QVariant& operator=(const QVariant &other); #ifdef Q_COMPILER_RVALUE_REFS @@ -313,11 +315,11 @@ class Q_CORE_EXPORT QVariant QLocale toLocale() const; #ifndef QT_NO_REGEXP QRegExp toRegExp() const; -#ifndef QT_BOOTSTRAPPED - QRegularExpression toRegularExpression() const; -#endif // QT_BOOTSTRAPPED #endif // QT_NO_REGEXP #ifndef QT_BOOTSTRAPPED +#ifndef QT_NO_REGULAREXPRESSION + QRegularExpression toRegularExpression() const; +#endif // QT_NO_REGULAREXPRESSION QUrl toUrl() const; QEasingCurve toEasingCurve() const; QUuid toUuid() const; @@ -326,7 +328,7 @@ class Q_CORE_EXPORT QVariant QJsonObject toJsonObject() const; QJsonArray toJsonArray() const; QJsonDocument toJsonDocument() const; -#endif +#endif // QT_BOOTSTRAPPED #ifndef QT_NO_DATASTREAM void load(QDataStream &ds); diff --git a/src/corelib/tools/qmargins.cpp b/src/corelib/tools/qmargins.cpp index 6929433bb5..e30675dc63 100644 --- a/src/corelib/tools/qmargins.cpp +++ b/src/corelib/tools/qmargins.cpp @@ -157,6 +157,240 @@ QT_BEGIN_NAMESPACE Returns true if \a m1 and \a m2 are different; otherwise returns 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 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 +*/ + +/*! + \fn const QMargins operator+(const QMargins &m1, const QMargins &m2) + \relates QMargins + + Returns a QMargins object that is the sum of the given margins, \a m1 + and \a m2; each component is added separately. + + \sa QMargins::operator+=(), QMargins::operator-=() + + \since 5.1 +*/ + +/*! + \fn const QMargins operator-(const QMargins &m1, const QMargins &m2) + \relates QMargins + + Returns a QMargins object that is formed by subtracting \a m2 from + \a m1; each component is subtracted separately. + + \sa QMargins::operator+=(), QMargins::operator-=() + + \since 5.1 +*/ + +/*! + \fn const QMargins operator*(const QMargins &margins, int factor) + \relates QMargins + + Returns a QMargins object that is formed by multiplying each component + of the given \a margins by \a factor. + + \sa QMargins::operator*=(), QMargins::operator/=() + + \since 5.1 +*/ + +/*! + \fn const QMargins operator*(int factor, const QMargins &margins) + \relates QMargins + \overload + + Returns a QMargins object that is formed by multiplying each component + of the given \a margins by \a factor. + + \sa QMargins::operator*=(), QMargins::operator/=() + + \since 5.1 +*/ + +/*! + \fn const QMargins operator*(const QMargins &margins, qreal factor) + \relates QMargins + \overload + + Returns a QMargins object that is formed by multiplying each component + of the given \a margins by \a factor. + + \sa QMargins::operator*=(), QMargins::operator/=() + + \since 5.1 +*/ + +/*! + \fn const QMargins operator*(qreal factor, const QMargins &margins) + \relates QMargins + \overload + + Returns a QMargins object that is formed by multiplying each component + of the given \a margins by \a factor. + + \sa QMargins::operator*=(), QMargins::operator/=() + + \since 5.1 +*/ + +/*! + \fn const QMargins operator/(const QMargins &margins, int divisor) + \relates QMargins + + Returns a QMargins object that is formed by dividing the components of + the given \a margins by the given \a divisor. + + \sa QMargins::operator*=(), QMargins::operator/=() + + \since 5.1 +*/ + +/*! + \fn const QMargins operator/(const QMargins &, qreal) + \relates QMargins + \overload + + Returns a QMargins object that is formed by dividing the components of + the given \a margins by the given \a divisor. + + \sa QMargins::operator*=(), QMargins::operator/=() + + \since 5.1 +*/ + +/*! + \fn QMargins operator-(const QMargins &margins) + \relates QMargins + + Returns a QMargin object that is formed by negating all components of \a margins. + + \since 5.1 +*/ + +/*! + \fn QMargins &operator+=(const QMargins &margins) + + Add each component of \a margins to the respective component of this object + and returns a reference to it. + + \sa operator-=() + + \since 5.1 +*/ + +/*! + \fn QMargins &operator-=(const QMargins &margins) + + Subtract each component of \a margins from the respective component of this object + and returns a reference to it. + + \sa operator+=() + + \since 5.1 +*/ + +/*! + \fn QMargins &operator*=(int factor) + + Multiplies each component of this object by \a factor + and returns a reference to it. + + \sa operator/=() + + \since 5.1 +*/ + +/*! + \fn QMargins &operator*=(qreal factor) + \overload + + Multiplies each component of this object by \a factor + and returns a reference to it. + + \sa operator/=() + + \since 5.1 +*/ + +/*! + \fn QMargins &operator/=(int divisor) + + Divides each component of this object by \a divisor + and returns a reference to it. + + \sa operator*=() + + \since 5.1 +*/ + +/*! + \fn QMargins &operator/=(qreal divisor) + + \overload + + \sa operator*=() + + \since 5.1 +*/ + /***************************************************************************** QMargins stream functions *****************************************************************************/ diff --git a/src/corelib/tools/qmargins.h b/src/corelib/tools/qmargins.h index 8ceccd4419..dd6fb0261a 100644 --- a/src/corelib/tools/qmargins.h +++ b/src/corelib/tools/qmargins.h @@ -42,7 +42,7 @@ #ifndef QMARGINS_H #define QMARGINS_H -#include <QtCore/qnamespace.h> +#include <QtCore/qrect.h> QT_BEGIN_HEADER @@ -67,6 +67,15 @@ public: void setRight(int right); void setBottom(int bottom); + QMargins &operator+=(const QMargins &margins); + QMargins &operator-=(const QMargins &margins); + QMargins &operator+=(int); + QMargins &operator-=(int); + QMargins &operator*=(int); + QMargins &operator/=(int); + QMargins &operator*=(qreal); + QMargins &operator/=(qreal); + private: int m_left; int m_top; @@ -142,6 +151,124 @@ 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 +{ + 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; +} + +Q_DECL_CONSTEXPR inline QMargins operator+(const QMargins &m1, const QMargins &m2) +{ + return QMargins(m1.left() + m2.left(), m1.top() + m2.top(), + m1.right() + m2.right(), m1.bottom() + m2.bottom()); +} + +Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &m1, const QMargins &m2) +{ + return QMargins(m1.left() - m2.left(), m1.top() - m2.top(), + m1.right() - m2.right(), m1.bottom() - m2.bottom()); +} + +Q_DECL_CONSTEXPR inline QMargins operator*(const QMargins &margins, int factor) +{ + return QMargins(margins.left() * factor, margins.top() * factor, + margins.right() * factor, margins.bottom() * factor); +} + +Q_DECL_CONSTEXPR inline QMargins operator*(int factor, const QMargins &margins) +{ + return QMargins(margins.left() * factor, margins.top() * factor, + margins.right() * factor, margins.bottom() * factor); +} + +Q_DECL_CONSTEXPR inline QMargins operator*(const QMargins &margins, qreal factor) +{ + return QMargins(qRound(margins.left() * factor), qRound(margins.top() * factor), + qRound(margins.right() * factor), qRound(margins.bottom() * factor)); +} + +Q_DECL_CONSTEXPR inline QMargins operator*(qreal factor, const QMargins &margins) +{ + return QMargins(qRound(margins.left() * factor), qRound(margins.top() * factor), + qRound(margins.right() * factor), qRound(margins.bottom() * factor)); +} + +Q_DECL_CONSTEXPR inline QMargins operator/(const QMargins &margins, int divisor) +{ + return QMargins(margins.left() / divisor, margins.top() / divisor, + margins.right() / divisor, margins.bottom() / divisor); +} + +Q_DECL_CONSTEXPR inline QMargins operator/(const QMargins &margins, qreal divisor) +{ + return QMargins(qRound(margins.left() / divisor), qRound(margins.top() / divisor), + qRound(margins.right() / divisor), qRound(margins.bottom() / divisor)); +} + +inline QMargins &QMargins::operator+=(const QMargins &margins) +{ + return *this = *this + margins; +} + +inline QMargins &QMargins::operator-=(const QMargins &margins) +{ + return *this = *this - margins; +} + +inline QMargins &QMargins::operator*=(int factor) +{ + return *this = *this * factor; +} + +inline QMargins &QMargins::operator/=(int divisor) +{ + return *this = *this / divisor; +} + +inline QMargins &QMargins::operator*=(qreal factor) +{ + return *this = *this * factor; +} + +inline QMargins &QMargins::operator/=(qreal divisor) +{ + return *this = *this / divisor; +} + +Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &margins) +{ + return QMargins(-margins.left(), -margins.top(), -margins.right(), -margins.bottom()); +} + #ifndef QT_NO_DEBUG_STREAM Q_CORE_EXPORT QDebug operator<<(QDebug, const QMargins &); #endif diff --git a/src/corelib/tools/qrect.h b/src/corelib/tools/qrect.h index 6e1a819ef3..39b5602abf 100644 --- a/src/corelib/tools/qrect.h +++ b/src/corelib/tools/qrect.h @@ -53,6 +53,7 @@ QT_BEGIN_HEADER QT_BEGIN_NAMESPACE +class QMargins; class Q_CORE_EXPORT QRect { @@ -139,6 +140,11 @@ 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; + inline QRect &operator+=(const QMargins &margins); + inline QRect &operator-=(const QMargins &margins); + #if QT_DEPRECATED_SINCE(5, 0) QT_DEPRECATED QRect unite(const QRect &r) const { return united(r); } QT_DEPRECATED QRect intersect(const QRect &r) const { return intersected(r); } diff --git a/src/corelib/tools/qregularexpression.cpp b/src/corelib/tools/qregularexpression.cpp index 5c6b3ff044..1585389d22 100644 --- a/src/corelib/tools/qregularexpression.cpp +++ b/src/corelib/tools/qregularexpression.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2012 Giuseppe D'Angelo <dangelog@gmail.com>. +** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** @@ -725,6 +726,13 @@ QT_BEGIN_NAMESPACE that (in this text) there are other characters beyond the end of the subject string. This can lead to surprising results; see the discussion in the \l{partial matching} section for more details. + + \value NoMatch + No matching is done. This value is returned as the match type by a + default constructed QRegularExpressionMatch or + QRegularExpressionMatchIterator. Using this match type is not very + useful for the user, as no matching ever happens. This enum value + has been introduced in Qt 5.1. */ /*! @@ -1200,6 +1208,15 @@ QRegularExpressionMatchPrivate *QRegularExpressionPrivate::doMatch(const QString return new QRegularExpressionMatchPrivate(re, subject, matchType, matchOptions, 0); } + // skip optimizing and doing the actual matching if NoMatch type was requested + if (matchType == QRegularExpression::NoMatch) { + QRegularExpressionMatchPrivate *priv = new QRegularExpressionMatchPrivate(re, subject, + matchType, matchOptions, + 0); + priv->isValid = true; + return priv; + } + QRegularExpressionMatchPrivate *priv = new QRegularExpressionMatchPrivate(re, subject, matchType, matchOptions, capturingCount); diff --git a/src/corelib/tools/qregularexpression.h b/src/corelib/tools/qregularexpression.h index 4c95a5b3a0..57d03a34e5 100644 --- a/src/corelib/tools/qregularexpression.h +++ b/src/corelib/tools/qregularexpression.h @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2012 Giuseppe D'Angelo <dangelog@gmail.com>. +** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> ** Contact: http://www.qt-project.org/legal ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -42,7 +43,7 @@ #ifndef QREGULAREXPRESSION_H #define QREGULAREXPRESSION_H -#ifndef QT_NO_REGEXP +#ifndef QT_NO_REGULAREXPRESSION #include <QtCore/qstring.h> #include <QtCore/qshareddata.h> @@ -99,7 +100,8 @@ public: enum MatchType { NormalMatch = 0, PartialPreferCompleteMatch, - PartialPreferFirstMatch + PartialPreferFirstMatch, + NoMatch }; enum MatchOption { @@ -241,6 +243,6 @@ QT_END_NAMESPACE QT_END_HEADER -#endif // QT_NO_REGEXP +#endif // QT_NO_REGULAREXPRESSION #endif // QREGULAREXPRESSION_H diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 6db4fed0f8..10ef6b34dd 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -2762,13 +2762,17 @@ int QString::lastIndexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs str.size(), cs); } -#ifndef QT_NO_REGEXP + +#if !(defined(QT_NO_REGEXP) && defined(QT_NO_REGULAREXPRESSION)) struct QStringCapture { int pos; int len; int no; }; +#endif + +#ifndef QT_NO_REGEXP /*! \overload replace() @@ -2925,7 +2929,7 @@ QString& QString::replace(const QRegExp &rx, const QString &after) } #endif -#ifndef QT_NO_REGEXP +#ifndef QT_NO_REGULAREXPRESSION #ifndef QT_BOOTSTRAPPED /*! \overload replace() @@ -3055,7 +3059,7 @@ QString &QString::replace(const QRegularExpression &re, const QString &after) return *this; } #endif // QT_BOOTSTRAPPED -#endif // QT_NO_REGEXP +#endif // QT_NO_REGULAREXPRESSION /*! Returns the number of (potentially overlapping) occurrences of @@ -3256,7 +3260,7 @@ int QString::count(const QRegExp& rx) const } #endif // QT_NO_REGEXP -#ifndef QT_NO_REGEXP +#ifndef QT_NO_REGULAREXPRESSION #ifndef QT_BOOTSTRAPPED /*! \overload indexOf() @@ -3366,7 +3370,7 @@ int QString::count(const QRegularExpression &re) const return count; } #endif // QT_BOOTSTRAPPED -#endif // QT_NO_REGEXP +#endif // QT_NO_REGULAREXPRESSION /*! \fn int QString::count() const @@ -3487,7 +3491,7 @@ QString QString::section(const QString &sep, int start, int end, SectionFlags fl return ret; } -#ifndef QT_NO_REGEXP +#if !(defined(QT_NO_REGEXP) && defined(QT_NO_REGULAREXPRESSION)) class qt_section_chunk { public: qt_section_chunk(int l, QString s) { length = l; string = s; } @@ -3537,7 +3541,9 @@ static QString extractSections(const QList<qt_section_chunk> §ions, return ret; } +#endif +#ifndef QT_NO_REGEXP /*! \overload section() @@ -3575,7 +3581,7 @@ QString QString::section(const QRegExp ®, int start, int end, SectionFlags fl } #endif -#ifndef QT_NO_REGEXP +#ifndef QT_NO_REGULAREXPRESSION #ifndef QT_BOOTSTRAPPED /*! \overload section() @@ -3621,7 +3627,7 @@ QString QString::section(const QRegularExpression &re, int start, int end, Secti return extractSections(sections, start, end, flags); } #endif // QT_BOOTSTRAPPED -#endif // QT_NO_REGEXP +#endif // QT_NO_REGULAREXPRESSION /*! Returns a substring that contains the \a n leftmost characters @@ -6416,7 +6422,7 @@ QStringList QString::split(const QRegExp &rx, SplitBehavior behavior) const } #endif -#ifndef QT_NO_REGEXP +#ifndef QT_NO_REGULAREXPRESSION #ifndef QT_BOOTSTRAPPED /*! \overload @@ -6470,7 +6476,7 @@ QStringList QString::split(const QRegularExpression &re, SplitBehavior behavior) return list; } #endif // QT_BOOTSTRAPPED -#endif // QT_NO_REGEXP +#endif // QT_NO_REGULAREXPRESSION /*! \enum QString::NormalizationForm diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index b679f0f990..574285fa1e 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -335,7 +335,7 @@ public: inline bool contains(QRegExp &rx) const { return indexOf(rx) != -1; } #endif -#ifndef QT_NO_REGEXP +#ifndef QT_NO_REGULAREXPRESSION int indexOf(const QRegularExpression &re, int from = 0) const; int lastIndexOf(const QRegularExpression &re, int from = -1) const; bool contains(const QRegularExpression &re) const; @@ -356,7 +356,7 @@ public: #ifndef QT_NO_REGEXP QString section(const QRegExp ®, int start, int end = -1, SectionFlags flags = SectionDefault) const; #endif -#ifndef QT_NO_REGEXP +#ifndef QT_NO_REGULAREXPRESSION QString section(const QRegularExpression &re, int start, int end = -1, SectionFlags flags = SectionDefault) const; #endif QString left(int n) const Q_REQUIRED_RESULT; @@ -432,7 +432,7 @@ public: inline QString &remove(const QRegExp &rx) { return replace(rx, QString()); } #endif -#ifndef QT_NO_REGEXP +#ifndef QT_NO_REGULAREXPRESSION QString &replace(const QRegularExpression &re, const QString &after); inline QString &remove(const QRegularExpression &re) { return replace(re, QString()); } @@ -447,7 +447,7 @@ public: #ifndef QT_NO_REGEXP QStringList split(const QRegExp &sep, SplitBehavior behavior = KeepEmptyParts) const Q_REQUIRED_RESULT; #endif -#ifndef QT_NO_REGEXP +#ifndef QT_NO_REGULAREXPRESSION QStringList split(const QRegularExpression &sep, SplitBehavior behavior = KeepEmptyParts) const Q_REQUIRED_RESULT; #endif enum NormalizationForm { diff --git a/src/corelib/tools/qstringlist.cpp b/src/corelib/tools/qstringlist.cpp index d56f531e52..35ff2d3d84 100644 --- a/src/corelib/tools/qstringlist.cpp +++ b/src/corelib/tools/qstringlist.cpp @@ -320,7 +320,7 @@ QStringList QtPrivate::QStringList_filter(const QStringList *that, const QRegExp #endif #ifndef QT_BOOTSTRAPPED -#ifndef QT_NO_REGEXP +#ifndef QT_NO_REGULAREXPRESSION /*! \fn QStringList QStringList::filter(const QRegularExpression &re) const \overload @@ -338,7 +338,7 @@ QStringList QtPrivate::QStringList_filter(const QStringList *that, const QRegula } return res; } -#endif // QT_NO_REGEXP +#endif // QT_NO_REGULAREXPRESSION #endif // QT_BOOTSTRAPPED /*! @@ -395,7 +395,7 @@ void QtPrivate::QStringList_replaceInStrings(QStringList *that, const QRegExp &r #endif #ifndef QT_BOOTSTRAPPED -#ifndef QT_NO_REGEXP +#ifndef QT_NO_REGULAREXPRESSION /*! \fn QStringList &QStringList::replaceInStrings(const QRegularExpression &re, const QString &after) \overload @@ -424,7 +424,7 @@ void QtPrivate::QStringList_replaceInStrings(QStringList *that, const QRegularEx for (int i = 0; i < that->size(); ++i) (*that)[i].replace(re, after); } -#endif // QT_NO_REGEXP +#endif // QT_NO_REGULAREXPRESSION #endif // QT_BOOTSTRAPPED /*! @@ -619,7 +619,7 @@ int QtPrivate::QStringList_lastIndexOf(const QStringList *that, QRegExp &rx, int #endif #ifndef QT_BOOTSTRAPPED -#ifndef QT_NO_REGEXP +#ifndef QT_NO_REGULAREXPRESSION /*! \fn int QStringList::indexOf(const QRegularExpression &re, int from) const \overload @@ -676,7 +676,7 @@ int QtPrivate::QStringList_lastIndexOf(const QStringList *that, const QRegularEx } return -1; } -#endif // QT_NO_REGEXP +#endif // QT_NO_REGULAREXPRESSION #endif // QT_BOOTSTRAPPED /*! diff --git a/src/corelib/tools/qstringlist.h b/src/corelib/tools/qstringlist.h index 2448081004..9f7e41d800 100644 --- a/src/corelib/tools/qstringlist.h +++ b/src/corelib/tools/qstringlist.h @@ -99,12 +99,12 @@ public: #endif #ifndef QT_BOOTSTRAPPED -#ifndef QT_NO_REGEXP +#ifndef QT_NO_REGULAREXPRESSION inline QStringList filter(const QRegularExpression &re) const; inline QStringList &replaceInStrings(const QRegularExpression &re, const QString &after); inline int indexOf(const QRegularExpression &re, int from = 0) const; inline int lastIndexOf(const QRegularExpression &re, int from = -1) const; -#endif // QT_NO_REGEXP +#endif // QT_NO_REGULAREXPRESSION #endif // QT_BOOTSTRAPPED #if !defined(Q_NO_USING_KEYWORD) @@ -141,12 +141,12 @@ namespace QtPrivate { #endif #ifndef QT_BOOTSTRAPPED -#ifndef QT_NO_REGEXP +#ifndef QT_NO_REGULAREXPRESSION void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, const QRegularExpression &rx, const QString &after); QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, const QRegularExpression &re); int Q_CORE_EXPORT QStringList_indexOf(const QStringList *that, const QRegularExpression &re, int from); int Q_CORE_EXPORT QStringList_lastIndexOf(const QStringList *that, const QRegularExpression &re, int from); -#endif // QT_NO_REGEXP +#endif // QT_NO_REGULAREXPRESSION #endif // QT_BOOTSTRAPPED } @@ -220,7 +220,7 @@ inline int QStringList::lastIndexOf(QRegExp &rx, int from) const #endif #ifndef QT_BOOTSTRAPPED -#ifndef QT_NO_REGEXP +#ifndef QT_NO_REGULAREXPRESSION inline QStringList &QStringList::replaceInStrings(const QRegularExpression &rx, const QString &after) { QtPrivate::QStringList_replaceInStrings(this, rx, after); @@ -241,7 +241,7 @@ inline int QStringList::lastIndexOf(const QRegularExpression &rx, int from) cons { return QtPrivate::QStringList_lastIndexOf(this, rx, from); } -#endif // QT_NO_REGEXP +#endif // QT_NO_REGULAREXPRESSION #endif // QT_BOOTSTRAPPED #ifndef QT_NO_DATASTREAM diff --git a/src/gui/text/qabstractfontengine_p.h b/src/gui/text/qabstractfontengine_p.h deleted file mode 100644 index 847b6d64a5..0000000000 --- a/src/gui/text/qabstractfontengine_p.h +++ /dev/null @@ -1,108 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QABSTRACTFONTENGINE_P_H -#define QABSTRACTFONTENGINE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qfontengine_p.h" -#include "qabstractfontengine_qws.h" - -QT_BEGIN_NAMESPACE - -class QCustomFontEngine; - -class QProxyFontEngine : public QFontEngine -{ - Q_OBJECT -public: - QProxyFontEngine(QAbstractFontEngine *engine, const QFontDef &def); - virtual ~QProxyFontEngine(); - - virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, ShaperFlags flags) const; - virtual void recalcAdvances(QGlyphLayout *, ShaperFlags) const; - virtual QImage alphaMapForGlyph(glyph_t); - virtual void addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nglyphs, QPainterPath *path, QTextItem::RenderFlags flags); - virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs); - virtual glyph_metrics_t boundingBox(glyph_t glyph); - - virtual QFixed ascent() const; - virtual QFixed descent() const; - virtual QFixed leading() const; - virtual QFixed xHeight() const; - virtual QFixed averageCharWidth() const; - virtual QFixed lineThickness() const; - virtual QFixed underlinePosition() const; - virtual qreal maxCharWidth() const; - virtual qreal minLeftBearing() const; - virtual qreal minRightBearing() const; - virtual int glyphCount() const; - - virtual bool canRender(const QChar *string, int len); - - virtual Type type() const { return Proxy; } - virtual const char *name() const { return "proxy engine"; } - - virtual void draw(QPaintEngine *, qreal, qreal, const QTextItemInt &); - - inline QAbstractFontEngine::Capabilities capabilities() const - { return engineCapabilities; } - - bool drawAsOutline() const; - -private: - QAbstractFontEngine *engine; - QAbstractFontEngine::Capabilities engineCapabilities; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/gui/text/qfontengine_qpf.cpp b/src/gui/text/qfontengine_qpf.cpp index 93ff7b6bdb..10523b29f9 100644 --- a/src/gui/text/qfontengine_qpf.cpp +++ b/src/gui/text/qfontengine_qpf.cpp @@ -666,9 +666,7 @@ void QFontEngineQPF::draw(QPaintEngine *p, qreal _x, qreal _y, const QTextItemIn void QFontEngineQPF::addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags) { - if (renderingFontEngine && - (renderingFontEngine->type() != QFontEngine::Proxy - || static_cast<QProxyFontEngine *>(renderingFontEngine)->capabilities() & QAbstractFontEngine::CanOutlineGlyphs)) { + if (renderingFontEngine && renderingFontEngine->type() != QFontEngine::Proxy) { renderingFontEngine->addOutlineToPath(x, y, glyphs, path, flags); return; } diff --git a/src/gui/text/qrawfont_ft.cpp b/src/gui/text/qrawfont_ft.cpp deleted file mode 100644 index 34d6eb0e3d..0000000000 --- a/src/gui/text/qrawfont_ft.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/qglobal.h> - -#if !defined(QT_NO_RAWFONT) - -#include "qrawfont_p.h" -#include "qfontengine_ft_p.h" -#include "quuid.h" - - -QT_BEGIN_NAMESPACE - -class QFontEngineFTRawFont - - : public QFontEngineFT - -{ -public: - QFontEngineFTRawFont(const QFontDef &fontDef) - : QFontEngineFT(fontDef) - { - } - - void updateFamilyNameAndStyle() - { - fontDef.family = QString::fromUtf8(freetype->face->family_name); - - if (freetype->face->style_flags & FT_STYLE_FLAG_ITALIC) - fontDef.style = QFont::StyleItalic; - - if (freetype->face->style_flags & FT_STYLE_FLAG_BOLD) - fontDef.weight = QFont::Bold; - } - - bool initFromData(const QByteArray &fontData) - { - FaceId faceId; - faceId.filename = ""; - faceId.index = 0; - faceId.uuid = QUuid::createUuid().toByteArray(); - - return init(faceId, true, Format_None, fontData); - } -}; - - -void QRawFontPrivate::platformCleanUp() -{ - // Font engine handles all resources -} - -void QRawFontPrivate::platformLoadFromData(const QByteArray &fontData, qreal pixelSize, - QFont::HintingPreference hintingPreference) -{ - Q_ASSERT(fontEngine == 0); - - QFontDef fontDef; - fontDef.pixelSize = pixelSize; - - QFontEngineFTRawFont *fe = new QFontEngineFTRawFont(fontDef); - if (!fe->initFromData(fontData)) { - delete fe; - return; - } - - fe->updateFamilyNameAndStyle(); - - switch (hintingPreference) { - case QFont::PreferNoHinting: - fe->setDefaultHintStyle(QFontEngineFT::HintNone); - break; - case QFont::PreferFullHinting: - fe->setDefaultHintStyle(QFontEngineFT::HintFull); - break; - case QFont::PreferVerticalHinting: - fe->setDefaultHintStyle(QFontEngineFT::HintLight); - break; - default: - // Leave it as it is - break; - } - - fontEngine = fe; - fontEngine->ref.ref(); -} - -QT_END_NAMESPACE - -#endif // QT_NO_RAWFONT diff --git a/src/gui/util/qvalidator.cpp b/src/gui/util/qvalidator.cpp index 0d38ebaf14..645e7ceeda 100644 --- a/src/gui/util/qvalidator.cpp +++ b/src/gui/util/qvalidator.cpp @@ -502,9 +502,6 @@ void QIntValidator::setTop(int top) setRange(bottom(), top); } - -#ifndef QT_NO_REGEXP - /*! \internal */ @@ -521,6 +518,8 @@ QValidator::QValidator(QValidatorPrivate &d, QObject *parent) { } +#ifndef QT_NO_REGEXP + class QDoubleValidatorPrivate : public QValidatorPrivate { Q_DECLARE_PUBLIC(QDoubleValidator) @@ -907,7 +906,7 @@ void QRegExpValidator::setRegExp(const QRegExp& rx) #endif -#ifndef QT_NO_REGEXP +#ifndef QT_NO_REGULAREXPRESSION /*! \class QRegularExpressionValidator @@ -1058,7 +1057,7 @@ void QRegularExpressionValidatorPrivate::setRegularExpression(const QRegularExpr } } -#endif // QT_NO_REGEXP +#endif // QT_NO_REGULAREXPRESSION QT_END_NAMESPACE diff --git a/src/gui/util/qvalidator.h b/src/gui/util/qvalidator.h index 53acdfb31e..459af44ffc 100644 --- a/src/gui/util/qvalidator.h +++ b/src/gui/util/qvalidator.h @@ -197,7 +197,7 @@ private: #endif // QT_NO_REGEXP -#ifndef QT_NO_REGEXP +#ifndef QT_NO_REGULAREXPRESSION class QRegularExpressionValidatorPrivate; @@ -226,7 +226,7 @@ private: Q_DECLARE_PRIVATE(QRegularExpressionValidator) }; -#endif // QT_NO_REGEXP +#endif // QT_NO_REGULAREXPRESSION #endif // QT_NO_VALIDATOR diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 3831c6b10e..97aeadacd3 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -1118,7 +1118,7 @@ QRect QWindowsWindow::frameGeometry_sys() const QRect QWindowsWindow::geometry_sys() const { - return frameGeometry_sys() - frameMargins(); + return frameGeometry_sys().marginsRemoved(frameMargins()); } /*! diff --git a/src/plugins/platforms/windows/qwindowswindow.h b/src/plugins/platforms/windows/qwindowswindow.h index 978d1d5a53..7af1e2f718 100644 --- a/src/plugins/platforms/windows/qwindowswindow.h +++ b/src/plugins/platforms/windows/qwindowswindow.h @@ -283,17 +283,6 @@ private: HICON m_iconBig; }; -// Conveniences for window frames. -inline QRect operator+(const QRect &r, const QMargins &m) -{ - return r.adjusted(-m.left(), -m.top(), m.right(), m.bottom()); -} - -inline QRect operator-(const QRect &r, const QMargins &m) -{ - return r.adjusted(m.left(), m.top(), -m.right(), -m.bottom()); -} - // Debug QDebug operator<<(QDebug d, const RECT &r); #ifndef Q_OS_WINCE // maybe available on some SDKs revisit WM_GETMINMAXINFO/WM_NCCALCSIZE diff --git a/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp b/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp index 5e3b3d221e..b74fc53ed0 100644 --- a/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp +++ b/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp @@ -50,6 +50,7 @@ class tst_QMargins : public QObject private slots: void getSetCheck(); void dataStreamCheck(); + void operators(); }; // Testing get/set functions @@ -75,6 +76,49 @@ void tst_QMargins::getSetCheck() QCOMPARE(margins, QMargins(5, 0, 5, 0)); } +void tst_QMargins::operators() +{ + const QMargins m1(12, 14, 16, 18); + const QMargins m2(2, 3, 4, 5); + + const QMargins added = m1 + m2; + QCOMPARE(added, QMargins(14, 17, 20, 23)); + QMargins a = m1; + a += m2; + QCOMPARE(a, added); + + const QMargins subtracted = m1 - m2; + QCOMPARE(subtracted, QMargins(10, 11, 12, 13)); + a = m1; + a -= m2; + QCOMPARE(a, subtracted); + + const QMargins doubled = m1 * 2; + QCOMPARE(doubled, QMargins(24, 28, 32, 36)); + QCOMPARE(2 * m1, doubled); + QCOMPARE(qreal(2) * m1, doubled); + QCOMPARE(m1 * qreal(2), doubled); + + a = m1; + a *= 2; + QCOMPARE(a, doubled); + a = m1; + a *= qreal(2); + QCOMPARE(a, doubled); + + const QMargins halved = m1 / 2; + QCOMPARE(halved, QMargins(6, 7, 8, 9)); + + a = m1; + a /= 2; + QCOMPARE(a, halved); + a = m1; + a /= qreal(2); + QCOMPARE(a, halved); + + QCOMPARE(m1 + (-m1), QMargins()); +} + // Testing QDataStream operators void tst_QMargins::dataStreamCheck() { diff --git a/tests/auto/corelib/tools/qrect/tst_qrect.cpp b/tests/auto/corelib/tools/qrect/tst_qrect.cpp index 7772a8aa1e..a5f2fa73da 100644 --- a/tests/auto/corelib/tools/qrect/tst_qrect.cpp +++ b/tests/auto/corelib/tools/qrect/tst_qrect.cpp @@ -41,6 +41,7 @@ #include <QtTest/QtTest> #include <qrect.h> +#include <qmargins.h> #include <limits.h> #include <qdebug.h> @@ -133,6 +134,7 @@ private slots: void newMoveTopLeft(); void newMoveBottomRight_data(); void newMoveBottomRight(); + void margins(); void translate_data(); void translate(); @@ -3484,6 +3486,25 @@ void tst_QRect::newMoveBottomRight() QCOMPARE(r,nr); } +void tst_QRect::margins() +{ + const QRect rectangle = QRect(QPoint(10, 10), QSize(50 ,50)); + const QMargins margins = QMargins(2, 3, 4, 5); + + const QRect added = rectangle + margins; + QCOMPARE(added, QRect(QPoint(8, 7), QSize(56, 58))); + QCOMPARE(added, margins + rectangle); + QCOMPARE(added, rectangle.marginsAdded(margins)); + + QRect a = rectangle; + a += margins; + QCOMPARE(added, a); + + a = rectangle; + a -= margins; + QCOMPARE(a, QRect(QPoint(12, 13), QSize(44, 42))); + QCOMPARE(a, rectangle.marginsRemoved(margins)); +} void tst_QRect::translate_data() { diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp index 7073805db4..3662d32655 100644 --- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp +++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp @@ -126,8 +126,6 @@ bool operator!=(const Match &m, const QRegularExpressionMatch &rem) bool operator==(const QRegularExpressionMatchIterator &iterator, const QList<Match> &expectedMatchList) { QRegularExpressionMatchIterator i = iterator; - if (i.isValid() != (!expectedMatchList.isEmpty())) - return false; foreach (const Match &expectedMatch, expectedMatchList) { @@ -693,12 +691,31 @@ void tst_QRegularExpression::normalMatch() QFETCH(QRegularExpression::MatchOptions, matchOptions); QFETCH(Match, match); - QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NormalMatch, matchOptions); - consistencyCheck(m); - QVERIFY(m == match); + { + QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NormalMatch, matchOptions); + consistencyCheck(m); + QVERIFY(m == match); + QCOMPARE(m.regularExpression(), regexp); + QCOMPARE(m.matchType(), QRegularExpression::NormalMatch); + QCOMPARE(m.matchOptions(), matchOptions); + } + { + // ignore the expected results provided by the match object -- + // we'll never get any result when testing the NoMatch type. + // Just check the validity of the match here. + Match realMatch; + realMatch.clear(); + realMatch.isValid = match.isValid; + + QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NoMatch, matchOptions); + consistencyCheck(m); + QVERIFY(m == realMatch); + QCOMPARE(m.regularExpression(), regexp); + QCOMPARE(m.matchType(), QRegularExpression::NoMatch); + QCOMPARE(m.matchOptions(), matchOptions); + } } - void tst_QRegularExpression::partialMatch_data() { QTest::addColumn<QRegularExpression>("regexp"); @@ -952,9 +969,29 @@ void tst_QRegularExpression::partialMatch() QFETCH(QRegularExpression::MatchOptions, matchOptions); QFETCH(Match, match); - QRegularExpressionMatch m = regexp.match(subject, offset, matchType, matchOptions); - consistencyCheck(m); - QVERIFY(m == match); + { + QRegularExpressionMatch m = regexp.match(subject, offset, matchType, matchOptions); + consistencyCheck(m); + QVERIFY(m == match); + QCOMPARE(m.regularExpression(), regexp); + QCOMPARE(m.matchType(), matchType); + QCOMPARE(m.matchOptions(), matchOptions); + } + { + // ignore the expected results provided by the match object -- + // we'll never get any result when testing the NoMatch type. + // Just check the validity of the match here. + Match realMatch; + realMatch.clear(); + realMatch.isValid = match.isValid; + + QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NoMatch, matchOptions); + consistencyCheck(m); + QVERIFY(m == realMatch); + QCOMPARE(m.regularExpression(), regexp); + QCOMPARE(m.matchType(), QRegularExpression::NoMatch); + QCOMPARE(m.matchOptions(), matchOptions); + } } void tst_QRegularExpression::globalMatch_data() @@ -1223,10 +1260,28 @@ void tst_QRegularExpression::globalMatch() QFETCH(QRegularExpression::MatchType, matchType); QFETCH(QRegularExpression::MatchOptions, matchOptions); QFETCH(QList<Match>, matchList); + { + QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, matchType, matchOptions); + consistencyCheck(iterator); + QVERIFY(iterator == matchList); + QCOMPARE(iterator.regularExpression(), regexp); + QCOMPARE(iterator.matchType(), matchType); + QCOMPARE(iterator.matchOptions(), matchOptions); + } + { + // ignore the expected results provided by the match object -- + // we'll never get any result when testing the NoMatch type. + // Just check the validity of the match here. + QList<Match> realMatchList; + + QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, QRegularExpression::NoMatch, matchOptions); + consistencyCheck(iterator); + QVERIFY(iterator == realMatchList); + QCOMPARE(iterator.regularExpression(), regexp); + QCOMPARE(iterator.matchType(), QRegularExpression::NoMatch); + QCOMPARE(iterator.matchOptions(), matchOptions); + } - QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, matchType, matchOptions); - consistencyCheck(iterator); - QVERIFY(iterator == matchList); } void tst_QRegularExpression::serialize_data() |