diff options
Diffstat (limited to 'src/corelib')
30 files changed, 998 insertions, 182 deletions
diff --git a/src/corelib/arch/qatomic_armv5.h b/src/corelib/arch/qatomic_armv5.h index 6939650c54..253b9263de 100644 --- a/src/corelib/arch/qatomic_armv5.h +++ b/src/corelib/arch/qatomic_armv5.h @@ -54,6 +54,7 @@ QT_END_NAMESPACE #pragma qt_sync_stop_processing #endif +#define Q_ATOMIC_INT32_IS_SUPPORTED #define Q_ATOMIC_INT_REFERENCE_COUNTING_IS_NOT_NATIVE #define Q_ATOMIC_INT_TEST_AND_SET_IS_NOT_NATIVE #define Q_ATOMIC_INT_FETCH_AND_STORE_IS_ALWAYS_NATIVE @@ -98,6 +99,7 @@ template <int size> struct QBasicAtomicOps: QGenericAtomicOps<QBasicAtomicOps<si static Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW { return false; } static Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return false; } template <typename T> static bool testAndSetRelaxed(T &_q_value, T expectedValue, T newValue) Q_DECL_NOTHROW; + template <typename T> static bool testAndSetRelaxed(T &_q_value, T expectedValue, T newValue, T *currentValue) Q_DECL_NOTHROW; template <typename T> static T fetchAndStoreRelaxed(T &_q_value, T newValue) Q_DECL_NOTHROW; template <typename T> static T fetchAndAddRelaxed(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW; @@ -133,6 +135,18 @@ bool QBasicAtomicOps<4>::deref(T &_q_value) Q_DECL_NOTHROW } template<> template <typename T> inline +bool QBasicAtomicOps<4>::testAndSetRelaxed(T &_q_value, T expectedValue, T newValue) Q_DECL_NOTHROW +{ + T originalValue; + do { + originalValue = _q_value; + if (originalValue != expectedValue) + return false; + } while (_q_cmpxchg(expectedValue, newValue, &_q_value) != 0); + return true; +} + +template<> template <typename T> inline bool QBasicAtomicOps<4>::testAndSetRelaxed(T &_q_value, T expectedValue, T newValue, T *currentValue) Q_DECL_NOTHROW { T originalValue; diff --git a/src/corelib/arch/qatomic_armv6.h b/src/corelib/arch/qatomic_armv6.h index 4f1c758ded..31a06541ed 100644 --- a/src/corelib/arch/qatomic_armv6.h +++ b/src/corelib/arch/qatomic_armv6.h @@ -90,6 +90,10 @@ template <int size> struct QBasicAtomicOps: QGenericAtomicOps<QBasicAtomicOps<si static inline Q_DECL_CONSTEXPR bool isFetchAndAddNative() Q_DECL_NOTHROW { return true; } template <typename T> static T fetchAndAddRelaxed(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW; + +private: + template <typename T> static inline T shrinkFrom32Bit(T value); + template <typename T> static inline T extendTo32Bit(T value); }; template <typename T> struct QAtomicOps : QBasicAtomicOps<sizeof(T)> @@ -257,6 +261,36 @@ template<> struct QAtomicOpsSupport<8> { enum { IsSupported = 1 }; }; #define Q_ATOMIC_INT64_FETCH_AND_STORE_IS_ALWAYS_NATIVE #define Q_ATOMIC_INT64_FETCH_AND_ADD_IS_ALWAYS_NATIVE +// note: if T is signed, parameters are passed sign-extended in the +// registers. However, our 8- and 16-bit operations don't do sign +// extension. So we need to clear out the input on entry and sign-extend again +// on exit. +template<int Size> template <typename T> +T QBasicAtomicOps<Size>::shrinkFrom32Bit(T value) +{ + Q_STATIC_ASSERT(Size == 1 || Size == 2); + if (T(-1) > T(0)) + return value; // unsigned, ABI will zero extend + if (Size == 1) + asm volatile("and %0, %0, %1" : "+r" (value) : "I" (0xff)); + else + asm volatile("and %0, %0, %1" : "+r" (value) : "r" (0xffff)); + return value; +} + +template<int Size> template <typename T> +T QBasicAtomicOps<Size>::extendTo32Bit(T value) +{ + Q_STATIC_ASSERT(Size == 1 || Size == 2); + if (T(-1) > T(0)) + return value; // unsigned, ABI will zero extend + if (Size == 1) + asm volatile("sxtb %0, %0" : "+r" (value)); + else + asm volatile("sxth %0, %0" : "+r" (value)); + return value; +} + template<> template<typename T> inline bool QBasicAtomicOps<1>::ref(T &_q_value) Q_DECL_NOTHROW { @@ -308,7 +342,7 @@ bool QBasicAtomicOps<1>::testAndSetRelaxed(T &_q_value, T expectedValue, T newVa "beq 0b\n" : [result] "=&r" (result), "+m" (_q_value) - : [expectedValue] "r" (expectedValue), + : [expectedValue] "r" (shrinkFrom32Bit(expectedValue)), [newValue] "r" (newValue), [_q_value] "r" (&_q_value) : "cc"); @@ -330,11 +364,11 @@ bool QBasicAtomicOps<1>::testAndSetRelaxed(T &_q_value, T expectedValue, T newVa : [result] "=&r" (result), [tempValue] "=&r" (tempValue), "+m" (_q_value) - : [expectedValue] "r" (expectedValue), + : [expectedValue] "r" (shrinkFrom32Bit(expectedValue)), [newValue] "r" (newValue), [_q_value] "r" (&_q_value) : "cc"); - *currentValue = tempValue; + *currentValue = extendTo32Bit(tempValue); return result == 0; } @@ -354,7 +388,7 @@ T QBasicAtomicOps<1>::fetchAndStoreRelaxed(T &_q_value, T newValue) Q_DECL_NOTHR : [newValue] "r" (newValue), [_q_value] "r" (&_q_value) : "cc"); - return originalValue; + return extendTo32Bit(originalValue); } template<> template <typename T> inline @@ -376,7 +410,7 @@ T QBasicAtomicOps<1>::fetchAndAddRelaxed(T &_q_value, typename QAtomicAdditiveTy : [valueToAdd] "r" (valueToAdd * QAtomicAdditiveType<T>::AddScale), [_q_value] "r" (&_q_value) : "cc"); - return originalValue; + return extendTo32Bit(originalValue); } template<> template<typename T> inline @@ -430,7 +464,7 @@ bool QBasicAtomicOps<2>::testAndSetRelaxed(T &_q_value, T expectedValue, T newVa "beq 0b\n" : [result] "=&r" (result), "+m" (_q_value) - : [expectedValue] "r" (expectedValue), + : [expectedValue] "r" (shrinkFrom32Bit(expectedValue)), [newValue] "r" (newValue), [_q_value] "r" (&_q_value) : "cc"); @@ -452,11 +486,11 @@ bool QBasicAtomicOps<2>::testAndSetRelaxed(T &_q_value, T expectedValue, T newVa : [result] "=&r" (result), [tempValue] "=&r" (tempValue), "+m" (_q_value) - : [expectedValue] "r" (expectedValue), + : [expectedValue] "r" (shrinkFrom32Bit(expectedValue)), [newValue] "r" (newValue), [_q_value] "r" (&_q_value) : "cc"); - *currentValue = tempValue; + *currentValue = extendTo32Bit(tempValue); return result == 0; } @@ -476,7 +510,7 @@ T QBasicAtomicOps<2>::fetchAndStoreRelaxed(T &_q_value, T newValue) Q_DECL_NOTHR : [newValue] "r" (newValue), [_q_value] "r" (&_q_value) : "cc"); - return originalValue; + return extendTo32Bit(originalValue); } template<> template <typename T> inline @@ -498,7 +532,7 @@ T QBasicAtomicOps<2>::fetchAndAddRelaxed(T &_q_value, typename QAtomicAdditiveTy : [valueToAdd] "r" (valueToAdd * QAtomicAdditiveType<T>::AddScale), [_q_value] "r" (&_q_value) : "cc"); - return originalValue; + return extendTo32Bit(originalValue); } // Explanation from GCC's source code (config/arm/arm.c) on the modifiers below: diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp index 2552ddebe9..7e3e629c47 100644 --- a/src/corelib/codecs/qtextcodec.cpp +++ b/src/corelib/codecs/qtextcodec.cpp @@ -993,6 +993,8 @@ QString QTextDecoder::toUnicode(const char *chars, int len) return c->toUnicode(chars, len, &state); } +// in qstring.cpp: +void qt_from_latin1(ushort *dst, const char *str, size_t size); /*! \overload @@ -1005,12 +1007,10 @@ void QTextDecoder::toUnicode(QString *target, const char *chars, int len) case 106: // utf8 static_cast<const QUtf8Codec*>(c)->convertToUnicode(target, chars, len, &state); break; - case 4: { // latin1 + case 4: // latin1 target->resize(len); - ushort *data = (ushort*)target->data(); - for (int i = len; i >=0; --i) - data[i] = (uchar) chars[i]; - } break; + qt_from_latin1((ushort*)target->data(), chars, len); + break; default: *target = c->toUnicode(chars, len, &state); } diff --git a/src/corelib/codecs/qutfcodec.cpp b/src/corelib/codecs/qutfcodec.cpp index a5d16b0b54..54312601e4 100644 --- a/src/corelib/codecs/qutfcodec.cpp +++ b/src/corelib/codecs/qutfcodec.cpp @@ -85,7 +85,7 @@ static inline bool simdEncodeAscii(uchar *&dst, const ushort *&nextAscii, const // we don't want to load 32 bytes again in this loop if we know there are non-ASCII // characters still coming n = _bit_scan_reverse(n); - nextAscii = src + n; + nextAscii = src + n + 1; return false; } @@ -115,7 +115,7 @@ static inline bool simdDecodeAscii(ushort *&dst, const uchar *&nextAscii, const // we don't want to load 16 bytes again in this loop if we know there are non-ASCII // characters still coming n = _bit_scan_reverse(n); - nextAscii = src + n; + nextAscii = src + n + 1; return false; } diff --git a/src/corelib/corelib.pro b/src/corelib/corelib.pro index 373b3f148d..79c90e0664 100644 --- a/src/corelib/corelib.pro +++ b/src/corelib/corelib.pro @@ -24,6 +24,9 @@ ANDROID_LIB_DEPENDENCIES = \ ANDROID_BUNDLED_JAR_DEPENDENCIES = \ jar/QtAndroid-bundled.jar \ jar/QtAndroidAccessibility-bundled.jar +ANDROID_PERMISSIONS = \ + android.permission.INTERNET \ + android.permission.WRITE_EXTERNAL_STORAGE load(qt_module) diff --git a/src/corelib/doc/snippets/signalmapper/filereader.cpp b/src/corelib/doc/snippets/signalmapper/filereader.cpp index cb83ea9362..6770510f5e 100644 --- a/src/corelib/doc/snippets/signalmapper/filereader.cpp +++ b/src/corelib/doc/snippets/signalmapper/filereader.cpp @@ -74,8 +74,8 @@ FileReader::FileReader(QWidget *parent) //! [2] //slower due to signature normalization at runtime - connect(signalMapper, SIGNAL(mapped(const QString &)), - this, SLOT(readFile(const QString &))); + connect(signalMapper, SIGNAL(mapped(QString)), + this, SLOT(readFile(QString))); //! [2] */ QHBoxLayout *buttonLayout = new QHBoxLayout; diff --git a/src/corelib/global/global.pri b/src/corelib/global/global.pri index 789f500cab..efa585ff3e 100644 --- a/src/corelib/global/global.pri +++ b/src/corelib/global/global.pri @@ -29,15 +29,6 @@ SOURCES += \ # qlibraryinfo.cpp includes qconfig.cpp INCLUDEPATH += $$QT_BUILD_TREE/src/corelib/global -# configure creates these, not syncqt, so we need to manually inject them -qconfig_h_files = \ - $$OUT_PWD/global/qfeatures.h \ - $$OUT_PWD/global/qconfig.h \ - $$QT_BUILD_TREE/include/QtCore/QtConfig -targ_headers.files += $$qconfig_h_files -contains(QMAKE_BUNDLE_DATA, FRAMEWORK_HEADERS): \ - FRAMEWORK_HEADERS.files += $$qconfig_h_files - # Only used on platforms with CONFIG += precompile_header PRECOMPILED_HEADER = global/qt_pch.h diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index 70f45345c6..1eb442aa5f 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -489,6 +489,7 @@ #ifdef Q_CC_INTEL # define Q_COMPILER_RESTRICTED_VLA +# define Q_COMPILER_VARIADIC_MACROS // C++11 feature supported as an extension in other modes, too # if __INTEL_COMPILER < 1200 # define Q_NO_TEMPLATE_FRIENDS # endif @@ -498,7 +499,6 @@ # define Q_COMPILER_BINARY_LITERALS # endif # if __cplusplus >= 201103L -# define Q_COMPILER_VARIADIC_MACROS # if __INTEL_COMPILER >= 1200 # define Q_COMPILER_AUTO_TYPE # define Q_COMPILER_CLASS_ENUM @@ -560,6 +560,15 @@ # define Q_COMPILER_BINARY_LITERALS # endif +// Variadic macros are supported for gnu++98, c++11, c99 ... since 2.9 +# if ((__clang_major__ * 100) + __clang_minor__) >= 209 +# if !defined(__STRICT_ANSI__) || defined(__GXX_EXPERIMENTAL_CXX0X__) \ + || (defined(__cplusplus) && (__cplusplus >= 201103L)) \ + || (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) +# define Q_COMPILER_VARIADIC_MACROS +# endif +# endif + /* C++11 features, see http://clang.llvm.org/cxx_status.html */ # if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) /* Detect C++ features using __has_feature(), see http://clang.llvm.org/docs/LanguageExtensions.html#cxx11 */ @@ -656,7 +665,6 @@ /* Features that have no __has_feature() check */ # if ((__clang_major__ * 100) + __clang_minor__) >= 209 /* since clang 2.9 */ # define Q_COMPILER_EXTERN_TEMPLATES -# define Q_COMPILER_VARIADIC_MACROS # endif # endif @@ -693,13 +701,18 @@ // GCC supports binary literals in C, C++98 and C++11 modes # define Q_COMPILER_BINARY_LITERALS # endif +# if !defined(__STRICT_ANSI__) || defined(__GXX_EXPERIMENTAL_CXX0X__) \ + || (defined(__cplusplus) && (__cplusplus >= 201103L)) \ + || (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + // Variadic macros are supported for gnu++98, c++11, C99 ... since forever (gcc 2.97) +# define Q_COMPILER_VARIADIC_MACROS +# endif # if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L # if (__GNUC__ * 100 + __GNUC_MINOR__) >= 403 /* C++11 features supported in GCC 4.3: */ # define Q_COMPILER_DECLTYPE # define Q_COMPILER_RVALUE_REFS # define Q_COMPILER_STATIC_ASSERT -# define Q_COMPILER_VARIADIC_MACROS # endif # if (__GNUC__ * 100 + __GNUC_MINOR__) >= 404 /* C++11 features supported in GCC 4.4: */ diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index fe10c493a7..710f7e8ba1 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -743,7 +743,7 @@ Q_STATIC_ASSERT_X(UCHAR_MAX == 255, "Qt assumes that char is 8 bits"); \relates <QtGlobal> This enum describes the messages that can be sent to a message - handler (QtMsgHandler). You can use the enum to identify and + handler (QtMessageHandler). You can use the enum to identify and associate the various message types with the appropriate actions. @@ -2810,12 +2810,17 @@ int qrand() The char pointer will be invalid after the statement in which qPrintable() is used. This is because the array returned by - toLocal8Bit() will fall out of scope. + QString::toLocal8Bit() will fall out of scope. Example: \snippet code/src_corelib_global_qglobal.cpp 37 + \note qDebug(), qWarning(), qCritical(), qFatal() expect %s + arguments to be UTF-8 encoded, while qPrintable() converts to + local 8-bit encoding. Therefore using qPrintable for logging + strings is only safe if the argument contains only ASCII + characters. \sa qDebug(), qWarning(), qCritical(), qFatal() */ diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index ed1715ddb5..689de48e26 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -287,9 +287,9 @@ QLibraryInfo::buildDate() \since 5.3 */ -const char *QLibraryInfo::build() +const char *QLibraryInfo::build() Q_DECL_NOTHROW { - static const char data[] = "Qt " QT_VERSION_STR " (" __DATE__ "), " + static const char data[] = "Qt " QT_VERSION_STR " (" __DATE__ ", " COMPILER_STRING ", " #if QT_POINTER_SIZE == 4 "32" diff --git a/src/corelib/global/qlibraryinfo.h b/src/corelib/global/qlibraryinfo.h index 2a8a3b84b9..0b573c2e6a 100644 --- a/src/corelib/global/qlibraryinfo.h +++ b/src/corelib/global/qlibraryinfo.h @@ -59,7 +59,7 @@ public: static QDate buildDate(); #endif //QT_NO_DATESTRING - static const char * build(); + static const char * build() Q_DECL_NOTHROW; static bool isDebugBuild(); diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 2327c11c69..ea3a3ca13d 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -720,8 +720,8 @@ QString QFileSystemEngine::tempPath() temp = QFile::decodeName(qgetenv("TMPDIR")); if (temp.isEmpty()) { - qWarning("Neither the TEMP nor the TMPDIR environment variable is set, falling back to /tmp."); - temp = QLatin1String("/tmp"); + qWarning("Neither the TEMP nor the TMPDIR environment variable is set, falling back to /var/tmp."); + temp = QLatin1String("/var/tmp"); } return QDir::cleanPath(temp); #else diff --git a/src/corelib/io/qloggingcategory.cpp b/src/corelib/io/qloggingcategory.cpp index f37b9575aa..eb8aeaca50 100644 --- a/src/corelib/io/qloggingcategory.cpp +++ b/src/corelib/io/qloggingcategory.cpp @@ -109,7 +109,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(QLoggingCategory, qtDefaultCategory, apply to a category/type, the rule that comes later is applied. Rules can be set via \l setFilterRules(). Since Qt 5.3 logging rules - are also automatically loaded from the \c [rules] section of a logging + are also automatically loaded from the \c [Rules] section of a logging configuration file. Such configuration files are looked up in the QtProject configuration directory, or explicitly set in a \c QT_LOGGING_CONF environment variable. diff --git a/src/corelib/io/qloggingregistry.cpp b/src/corelib/io/qloggingregistry.cpp index b8fef16c0e..2619743ff4 100644 --- a/src/corelib/io/qloggingregistry.cpp +++ b/src/corelib/io/qloggingregistry.cpp @@ -203,7 +203,7 @@ void QLoggingSettingsParser::setContent(QTextStream &stream) continue; } - if (_section == QLatin1String("rules")) { + if (_section == QLatin1String("Rules")) { int equalPos = line.indexOf(QLatin1Char('=')); if ((equalPos != -1) && (line.lastIndexOf(QLatin1Char('=')) == equalPos)) { @@ -298,7 +298,7 @@ void QLoggingRegistry::unregisterCategory(QLoggingCategory *cat) void QLoggingRegistry::setApiRules(const QString &content) { QLoggingSettingsParser parser; - parser.setSection(QStringLiteral("rules")); + parser.setSection(QStringLiteral("Rules")); parser.setContent(content); QMutexLocker locker(®istryMutex); diff --git a/src/corelib/itemmodels/qsortfilterproxymodel.cpp b/src/corelib/itemmodels/qsortfilterproxymodel.cpp index ebc97ca2d9..1e377abf3e 100644 --- a/src/corelib/itemmodels/qsortfilterproxymodel.cpp +++ b/src/corelib/itemmodels/qsortfilterproxymodel.cpp @@ -2606,16 +2606,16 @@ void QSortFilterProxyModel::invalidateFilter() the following QVariant types: \list - \li QVariant::Int - \li QVariant::UInt - \li QVariant::LongLong - \li QVariant::ULongLong - \li QVariant::Double - \li QVariant::Char - \li QVariant::Date - \li QVariant::Time - \li QVariant::DateTime - \li QVariant::String + \li QMetaType::Int + \li QMetaType::UInt + \li QMetaType::LongLong + \li QMetaType::ULongLong + \li QMetaType::Double + \li QMetaType::QChar + \li QMetaType::QDate + \li QMetaType::QTime + \li QMetaType::QDateTime + \li QMetaType::QString \endlist Any other type will be converted to a QString using diff --git a/src/corelib/json/qjsondocument.cpp b/src/corelib/json/qjsondocument.cpp index 6e257df39d..90ce8c63a5 100644 --- a/src/corelib/json/qjsondocument.cpp +++ b/src/corelib/json/qjsondocument.cpp @@ -260,8 +260,8 @@ QJsonDocument QJsonDocument::fromBinaryData(const QByteArray &data, DataValidati /*! Creates a QJsonDocument from the QVariant \a variant. - If the \a variant contains any other type than a QVariant::Map, - QVariant::List or QVariant::StringList, the returned document + If the \a variant contains any other type than a QVariantMap, + QVariantList or QStringList, the returned document document is invalid. \sa toVariant() diff --git a/src/corelib/json/qjsonvalue.cpp b/src/corelib/json/qjsonvalue.cpp index c16824ebd2..487a431b8f 100644 --- a/src/corelib/json/qjsonvalue.cpp +++ b/src/corelib/json/qjsonvalue.cpp @@ -344,16 +344,16 @@ QJsonValue &QJsonValue::operator =(const QJsonValue &other) The conversion will convert QVariant types as follows: \list - \li QVariant::Bool to Bool - \li QVariant::Int - \li QVariant::Double - \li QVariant::LongLong - \li QVariant::ULongLong - \li QVariant::UInt to Double - \li QVariant::String to String - \li QVariant::StringList - \li QVariant::VariantList to Array - \li QVariant::VariantMap to Object + \li QMetaType::Bool to Bool + \li QMetaType::Int + \li QMetaType::Double + \li QMetaType::LongLong + \li QMetaType::ULongLong + \li QMetaType::UInt to Double + \li QMetaType::QString to String + \li QMetaType::QStringList + \li QMetaType::QVariantList to Array + \li QMetaType::QVariantMap to Object \endlist For all other QVariant types a conversion to a QString will be attempted. If the returned string @@ -395,9 +395,9 @@ QJsonValue QJsonValue::fromVariant(const QVariant &variant) The QJsonValue types will be converted as follows: \value Null QVariant() - \value Bool QVariant::Bool - \value Double QVariant::Double - \value String QVariant::String + \value Bool QMetaType::Bool + \value Double QMetaType::Double + \value String QString \value Array QVariantList \value Object QVariantMap \value Undefined QVariant() diff --git a/src/corelib/kernel/qjni_p.h b/src/corelib/kernel/qjni_p.h index b1f0011b94..83dd3a00af 100644 --- a/src/corelib/kernel/qjni_p.h +++ b/src/corelib/kernel/qjni_p.h @@ -177,7 +177,7 @@ public: { jobject jobj = static_cast<jobject>(o); if (!isSameObject(jobj)) { - d = QSharedPointer<QJNIObjectData>(new QJNIObjectData()); + d = QSharedPointer<QJNIObjectData>::create(); if (jobj) { QJNIEnvironmentPrivate env; d->m_jobject = env->NewGlobalRef(jobj); diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index dd9a7693ca..5e8f330a92 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -1165,7 +1165,7 @@ Q_CORE_EXPORT void QVariantPrivate::registerHandler(const int /* Modules::Names instead to construct variants from the pointer types represented by \c QMetaType::VoidStar, and \c QMetaType::QObjectStar. - \sa QVariant::fromValue(), Type + \sa QVariant::fromValue(), QMetaType::Type */ /*! @@ -1765,7 +1765,7 @@ const char *QVariant::typeName() const } /*! - Convert this variant to type Invalid and free up any resources + Convert this variant to type QMetaType::UnknownType and free up any resources used. */ void QVariant::clear() @@ -1781,7 +1781,7 @@ void QVariant::clear() Converts the int representation of the storage type, \a typeId, to its string representation. - Returns a null pointer if the type is QVariant::Invalid or doesn't exist. + Returns a null pointer if the type is QMetaType::UnknownType or doesn't exist. */ const char *QVariant::typeToName(int typeId) { @@ -2019,7 +2019,7 @@ QDataStream& operator<<(QDataStream &s, const QVariant::Type p) \fn bool QVariant::isValid() const Returns \c true if the storage type of this variant is not - QVariant::Invalid; otherwise returns \c false. + QMetaType::UnknownType; otherwise returns \c false. */ template <typename T> @@ -3488,7 +3488,7 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p) /*! \class QSequentialIterable - + \since 5.2 \inmodule QtCore \brief The QSequentialIterable class is an iterable interface for a container in a QVariant. @@ -3591,7 +3591,7 @@ bool QSequentialIterable::canReverseIterate() const /*! \class QSequentialIterable::const_iterator - + \since 5.2 \inmodule QtCore \brief The QSequentialIterable::const_iterator allows iteration over a container in a QVariant. @@ -3794,7 +3794,7 @@ QSequentialIterable::const_iterator QSequentialIterable::const_iterator::operato /*! \class QAssociativeIterable - + \since 5.2 \inmodule QtCore \brief The QAssociativeIterable class is an iterable interface for an associative container in a QVariant. @@ -3899,7 +3899,7 @@ int QAssociativeIterable::size() const /*! \class QAssociativeIterable::const_iterator - + \since 5.2 \inmodule QtCore \brief The QAssociativeIterable::const_iterator allows iteration over a container in a QVariant. 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 \ |