diff options
Diffstat (limited to 'src/corelib')
38 files changed, 736 insertions, 587 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 02220d0db2..62308aec9d 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -1185,30 +1185,35 @@ bool qSharedBuild() Q_DECL_NOTHROW \macro Q_OS_DARWIN \relates <QtGlobal> - Defined on Darwin-based operating systems such as OS X and iOS, - including any open source version(s) of Darwin. + Defined on Darwin-based operating systems such as OS X, iOS, watchOS, and tvOS. */ /*! - \macro Q_OS_MAC + \macro Q_OS_OSX \relates <QtGlobal> - Defined on Darwin-based operating systems distributed by Apple, which - currently includes OS X and iOS, but not the open source versions of Darwin. + Defined on OS X. */ /*! - \macro Q_OS_OSX + \macro Q_OS_IOS \relates <QtGlobal> - Defined on OS X. + Defined on iOS. */ /*! - \macro Q_OS_IOS + \macro Q_OS_WATCHOS \relates <QtGlobal> - Defined on iOS. + Defined on watchOS. + */ + +/*! + \macro Q_OS_TVOS + \relates <QtGlobal> + + Defined on tvOS. */ /*! diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 4813c2b100..d4bbbe833c 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -41,11 +41,11 @@ #include <stddef.h> -#define QT_VERSION_STR "5.6.0" +#define QT_VERSION_STR "5.7.0" /* QT_VERSION is (major << 16) + (minor << 8) + patch. */ -#define QT_VERSION 0x050600 +#define QT_VERSION 0x050700 /* can be used like #if (QT_VERSION >= QT_VERSION_CHECK(4, 4, 0)) */ diff --git a/src/corelib/global/qhooks.cpp b/src/corelib/global/qhooks.cpp index 382f45f592..40a7c88f13 100644 --- a/src/corelib/global/qhooks.cpp +++ b/src/corelib/global/qhooks.cpp @@ -37,7 +37,7 @@ QT_BEGIN_NAMESPACE // Only add to the end, and bump version if you do. quintptr Q_CORE_EXPORT qtHookData[] = { - 2, // hook data version + 3, // hook data version QHooks::LastHookIndex, // size of qtHookData QT_VERSION, @@ -52,6 +52,15 @@ quintptr Q_CORE_EXPORT qtHookData[] = { 0, // Startup, void(*)(), called once QCoreApplication is operational + 0, + + // TypeInformationVersion, an integral value, bumped whenever private + // object sizes or member offsets that are used in Qt Creator's + // data structure "pretty printing" change. + // + // The required sizes and offsets are tested in tests/auto/other/toolsupport. + // When this fails and the change was intentional, adjust the test and + // adjust this value here. 0 }; diff --git a/src/corelib/global/qhooks_p.h b/src/corelib/global/qhooks_p.h index 3ff4980abe..2beb58f8a7 100644 --- a/src/corelib/global/qhooks_p.h +++ b/src/corelib/global/qhooks_p.h @@ -61,6 +61,7 @@ enum HookIndex { AddQObject = 3, RemoveQObject = 4, Startup = 5, + TypeInformationVersion = 6, LastHookIndex }; diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index de8a17fa51..056e519e56 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -482,7 +482,8 @@ public: AA_DontShowIconsInMenus = 2, AA_NativeWindows = 3, AA_DontCreateNativeWidgetSiblings = 4, - AA_MacPluginApplication = 5, + AA_PluginApplication = 5, + AA_MacPluginApplication = AA_PluginApplication, // ### Qt 6: remove me AA_DontUseNativeMenuBar = 6, AA_MacDontSwapCtrlAndMeta = 7, AA_Use96Dpi = 8, @@ -497,6 +498,7 @@ public: AA_ShareOpenGLContexts = 18, AA_SetPalette = 19, AA_NoHighDpiScaling = 20, + AA_UseStyleSheetPropagationInWidgetStyles = 21, // ### Qt 6: remove me // Add new attributes before this line AA_AttributeCount diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index 443eae5a11..8568dfd97c 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -120,13 +120,21 @@ widgets stay non-native unless specifically set by the Qt::WA_NativeWindow attribute. - \value AA_MacPluginApplication Stops the Qt mac application from doing - specific initializations that do not necessarily make sense when using Qt - to author a plugin. This includes avoiding loading our nib for the main - menu and not taking possession of the native menu bar. When setting this + \value AA_PluginApplication Indicates that Qt is used to author a plugin. Depending + on the operating system, it suppresses specific initializations that do not + necessarily make sense in the plugin case. + + For example on OS X, this includes avoiding loading our nib for the main + menu and not taking possession of the native menu bar. Setting this attribute to true will also set the AA_DontUseNativeMenuBar attribute to true. It also disables native event filters. + This attribute has been added in Qt 5.7. It must be set before + \l {QGuiApplication}{Q(Gui)Application} is constructed. + + \value AA_MacPluginApplication This attribute has been deprecated. + Use AA_PluginApplication instead. + \value AA_DontUseNativeMenuBar All menubars created while this attribute is set to true won't be used as a native menubar (e.g, the menubar at the top of the main screen on OS X or at the bottom in Windows CE). @@ -205,6 +213,13 @@ so this does not guarantee that QPaintDevice::devicePixelRatio() will be equal to 1. This value has been added in Qt 5.6. + \value AA_UseStyleSheetPropagationInWidgetStyles By default, Qt Style Sheets + disable regular QWidget palette and font propagation. When this flag + is enabled, font and palette changes propagate as though the user had + manually called the corresponding QWidget methods. See + \l{The Style Sheet Syntax#Inheritance}{The Style Sheet Syntax - Inheritance} + for more details. This value has been added in Qt 5.7. + The following values are obsolete: \value AA_ImmediateWidgetCreation This attribute is no longer fully diff --git a/src/corelib/global/qsystemdetection.h b/src/corelib/global/qsystemdetection.h index d19784163a..f043f6c5c9 100644 --- a/src/corelib/global/qsystemdetection.h +++ b/src/corelib/global/qsystemdetection.h @@ -41,10 +41,11 @@ /* The operating system, must be one of: (Q_OS_x) - DARWIN - Any Darwin system - MAC - OS X and iOS + DARWIN - Any Darwin system (OS X, iOS, watchOS, tvOS) OSX - OS X IOS - iOS + WATCHOS - watchOS + TVOS - tvOS MSDOS - MS-DOS and Windows OS2 - OS/2 OS2EMX - XFree86 on OS/2 (not PM) @@ -87,12 +88,32 @@ */ #if defined(__APPLE__) && (defined(__GNUC__) || defined(__xlC__) || defined(__xlc__)) -# define Q_OS_DARWIN -# define Q_OS_BSD4 -# ifdef __LP64__ -# define Q_OS_DARWIN64 +# include <TargetConditionals.h> +# if defined(TARGET_OS_MAC) && TARGET_OS_MAC +# define Q_OS_DARWIN +# define Q_OS_BSD4 +# ifdef __LP64__ +# define Q_OS_DARWIN64 +# else +# define Q_OS_DARWIN32 +# endif +# if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE +# if defined(TARGET_OS_TV) && TARGET_OS_TV +# define Q_OS_TVOS +# elif defined(TARGET_OS_WATCH) && TARGET_OS_WATCH +# define Q_OS_WATCHOS +# else +# // TARGET_OS_IOS is only available in newer SDKs, +# // so assume any other iOS-based platform is iOS for now +# define Q_OS_IOS +# endif +# else +# // there is no "real" OS X define (rdar://22640089), +# // assume any non iOS-based platform is OS X for now +# define Q_OS_OSX +# endif # else -# define Q_OS_DARWIN32 +# error "Qt has not been ported to this Apple platform - see http://www.qt.io/developers" # endif #elif defined(__ANDROID__) || defined(ANDROID) # define Q_OS_ANDROID @@ -181,28 +202,26 @@ # define Q_OS_WIN #endif -#if defined(Q_OS_DARWIN) -# define Q_OS_MAC -# if defined(Q_OS_DARWIN64) -# define Q_OS_MAC64 -# elif defined(Q_OS_DARWIN32) -# define Q_OS_MAC32 -# endif -# include <TargetConditionals.h> -# if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE -# define Q_OS_IOS -# elif defined(TARGET_OS_MAC) && TARGET_OS_MAC -# define Q_OS_OSX -# define Q_OS_MACX // compatibility synonym -# endif -#endif - #if defined(Q_OS_WIN) # undef Q_OS_UNIX #elif !defined(Q_OS_UNIX) # define Q_OS_UNIX #endif +// Compatibility synonyms +#ifdef Q_OS_DARWIN +#define Q_OS_MAC +#endif +#ifdef Q_OS_DARWIN32 +#define Q_OS_MAC32 +#endif +#ifdef Q_OS_DARWIN64 +#define Q_OS_MAC64 +#endif +#ifdef Q_OS_OSX +#define Q_OS_MACX +#endif + #ifdef Q_OS_DARWIN # include <Availability.h> # include <AvailabilityMacros.h> diff --git a/src/corelib/io/io.pri b/src/corelib/io/io.pri index b2bcbdf727..7be1e5883e 100644 --- a/src/corelib/io/io.pri +++ b/src/corelib/io/io.pri @@ -149,20 +149,14 @@ win32 { } freebsd: LIBS_PRIVATE += -lutil # qlockfile_unix.cpp requires this mac { + SOURCES += io/qstorageinfo_mac.cpp + OBJECTIVE_SOURCES += io/qstandardpaths_mac.mm osx { OBJECTIVE_SOURCES += io/qfilesystemwatcher_fsevents.mm HEADERS += io/qfilesystemwatcher_fsevents_p.h - } - macx { - SOURCES += io/qstorageinfo_mac.cpp - OBJECTIVE_SOURCES += io/qstandardpaths_mac.mm LIBS += -framework DiskArbitration -framework IOKit } else:ios { - OBJECTIVE_SOURCES += io/qstandardpaths_ios.mm - SOURCES += io/qstorageinfo_mac.cpp LIBS += -framework MobileCoreServices - } else { - SOURCES += io/qstandardpaths_unix.cpp } } else:blackberry { SOURCES += \ diff --git a/src/corelib/io/qdatastream.cpp b/src/corelib/io/qdatastream.cpp index 675178ea80..c32df4c8a6 100644 --- a/src/corelib/io/qdatastream.cpp +++ b/src/corelib/io/qdatastream.cpp @@ -527,6 +527,7 @@ void QDataStream::setByteOrder(ByteOrder bo) \value Qt_5_4 Version 16 (Qt 5.4) \value Qt_5_5 Same as Qt_5_4 \value Qt_5_6 Version 17 (Qt 5.6) + \value Qt_5_7 Same as Qt_5_6 \omitvalue Qt_DefaultCompiledVersion \sa setVersion(), version() diff --git a/src/corelib/io/qdatastream.h b/src/corelib/io/qdatastream.h index 5730c12907..744829c659 100644 --- a/src/corelib/io/qdatastream.h +++ b/src/corelib/io/qdatastream.h @@ -84,10 +84,11 @@ public: Qt_5_4 = 16, Qt_5_5 = Qt_5_4, Qt_5_6 = 17, -#if QT_VERSION >= 0x050700 + Qt_5_7 = Qt_5_6, +#if QT_VERSION >= 0x050800 #error Add the datastream version for this Qt version and update Qt_DefaultCompiledVersion #endif - Qt_DefaultCompiledVersion = Qt_5_6 + Qt_DefaultCompiledVersion = Qt_5_7 }; enum ByteOrder { diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 8fbe96adb9..3539c75548 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -1186,7 +1186,7 @@ bool QProcessPrivate::_q_startupNotification() } q->setProcessState(QProcess::NotRunning); - setErrorAndEmit(QProcess::FailedToStart); + setErrorAndEmit(QProcess::FailedToStart, errorString); // the error string was already set #ifdef Q_OS_UNIX // make sure the process manager removes this entry waitForDeadChild(); diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 63480dfc6b..a958aa4322 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -672,6 +672,7 @@ void QProcessPrivate::execChild(const char *workingDir, char **path, char **argv qt_safe_close(childStartedPipe[0]); // enter the working directory + const char *callthatfailed = "chdir: "; if (workingDir && QT_CHDIR(workingDir) == -1) { // failed, stop the process goto report_errno; @@ -683,6 +684,7 @@ void QProcessPrivate::execChild(const char *workingDir, char **path, char **argv // execute the process if (!envp) { qt_safe_execvp(argv[0], argv); + callthatfailed = "execvp: "; } else { if (path) { char **arg = path; @@ -700,15 +702,19 @@ void QProcessPrivate::execChild(const char *workingDir, char **path, char **argv #endif qt_safe_execve(argv[0], argv, envp); } + callthatfailed = "execve: "; } // notify failure + // we're running in the child process, so we don't need to be thread-safe; + // we can use strerror report_errno: - QString error = qt_error_string(errno); + const char *msg = strerror(errno); #if defined (QPROCESS_DEBUG) - fprintf(stderr, "QProcessPrivate::execChild() failed (%s), notifying parent process\n", qPrintable(error)); + fprintf(stderr, "QProcessPrivate::execChild() failed (%s), notifying parent process\n", msg); #endif - qt_safe_write(childStartedPipe[1], error.data(), error.length() * sizeof(QChar)); + qt_safe_write(childStartedPipe[1], callthatfailed, strlen(callthatfailed)); + qt_safe_write(childStartedPipe[1], msg, strlen(msg)); qt_safe_close(childStartedPipe[1]); childStartedPipe[1] = -1; } @@ -716,8 +722,15 @@ report_errno: bool QProcessPrivate::processStarted() { - ushort buf[errorBufferMax]; - int i = qt_safe_read(childStartedPipe[0], &buf, sizeof buf); + char buf[errorBufferMax]; + int i = 0; + int ret; + do { + ret = qt_safe_read(childStartedPipe[0], buf + i, sizeof buf - i); + if (ret > 0) + i += ret; + } while (ret > 0 && i < int(sizeof buf)); + if (startupSocketNotifier) { startupSocketNotifier->setEnabled(false); startupSocketNotifier->deleteLater(); @@ -732,7 +745,7 @@ bool QProcessPrivate::processStarted() // did we read an error message? if (i > 0) - q_func()->setErrorString(QString((const QChar *)buf, i / sizeof(QChar))); + q_func()->setErrorString(QString::fromLocal8Bit(buf, i)); return i <= 0; } diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index 0c44582af8..3460753fbe 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -2413,14 +2413,24 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, This enum type specifies the storage format used by QSettings. - \value NativeFormat Store the settings using the most - appropriate storage format for the platform. - On Windows, this means the system registry; - on OS X and iOS, this means the CFPreferences - API; on Unix, this means textual - configuration files in INI format. - \value IniFormat Store the settings in INI files. - \value InvalidFormat Special value returned by registerFormat(). + \value NativeFormat Store the settings using the most + appropriate storage format for the platform. + On Windows, this means the system registry; + on OS X and iOS, this means the CFPreferences + API; on Unix, this means textual + configuration files in INI format. + \value Registry32Format Windows only: Explicitly access the 32-bit system registry + from a 64-bit application running on 64-bit Windows. + On 32-bit Windows or from a 32-bit application on 64-bit Windows, + this works the same as specifying NativeFormat. + This enum value was added in Qt 5.7. + \value Registry64Format Windows only: Explicitly access the 64-bit system registry + from a 32-bit application running on 64-bit Windows. + On 32-bit Windows or from a 64-bit application on 64-bit Windows, + this works the same as specifying NativeFormat. + This enum value was added in Qt 5.7. + \value IniFormat Store the settings in INI files. + \value InvalidFormat Special value returned by registerFormat(). \omitvalue CustomFormat1 \omitvalue CustomFormat2 \omitvalue CustomFormat3 diff --git a/src/corelib/io/qsettings.h b/src/corelib/io/qsettings.h index 8f41273ffa..dd0c4a9bfb 100644 --- a/src/corelib/io/qsettings.h +++ b/src/corelib/io/qsettings.h @@ -79,6 +79,11 @@ public: NativeFormat, IniFormat, +#ifdef Q_OS_WIN + Registry32Format, + Registry64Format, +#endif + InvalidFormat = 16, CustomFormat1, CustomFormat2, diff --git a/src/corelib/io/qsettings_win.cpp b/src/corelib/io/qsettings_win.cpp index 1546219c3b..88f58422a8 100644 --- a/src/corelib/io/qsettings_win.cpp +++ b/src/corelib/io/qsettings_win.cpp @@ -41,6 +41,18 @@ #include "qdebug.h" #include <qt_windows.h> +// See "Accessing an Alternate Registry View" at: +// http://msdn.microsoft.com/en-us/library/aa384129%28VS.85%29.aspx +#ifndef KEY_WOW64_64KEY + // Access a 32-bit key from either a 32-bit or 64-bit application. +# define KEY_WOW64_64KEY 0x0100 +#endif + +#ifndef KEY_WOW64_32KEY + // Access a 64-bit key from either a 32-bit or 64-bit application. +# define KEY_WOW64_32KEY 0x0200 +#endif + QT_BEGIN_NAMESPACE /* Keys are stored in QStrings. If the variable name starts with 'u', this is a "user" @@ -135,12 +147,13 @@ static QString errorCodeToString(DWORD errorCode) return result; } -// Open a key with the specified perms -static HKEY openKey(HKEY parentHandle, REGSAM perms, const QString &rSubKey) +// Open a key with the specified "perms". +// "access" is to explicitly use the 32- or 64-bit branch. +static HKEY openKey(HKEY parentHandle, REGSAM perms, const QString &rSubKey, REGSAM access = 0) { HKEY resultHandle = 0; LONG res = RegOpenKeyEx(parentHandle, reinterpret_cast<const wchar_t *>(rSubKey.utf16()), - 0, perms, &resultHandle); + 0, perms | access, &resultHandle); if (res == ERROR_SUCCESS) return resultHandle; @@ -148,17 +161,18 @@ static HKEY openKey(HKEY parentHandle, REGSAM perms, const QString &rSubKey) return 0; } -// Open a key with the specified perms, create it if it does not exist -static HKEY createOrOpenKey(HKEY parentHandle, REGSAM perms, const QString &rSubKey) +// Open a key with the specified "perms", create it if it does not exist. +// "access" is to explicitly use the 32- or 64-bit branch. +static HKEY createOrOpenKey(HKEY parentHandle, REGSAM perms, const QString &rSubKey, REGSAM access = 0) { // try to open it - HKEY resultHandle = openKey(parentHandle, perms, rSubKey); + HKEY resultHandle = openKey(parentHandle, perms, rSubKey, access); if (resultHandle != 0) return resultHandle; // try to create it LONG res = RegCreateKeyEx(parentHandle, reinterpret_cast<const wchar_t *>(rSubKey.utf16()), 0, 0, - REG_OPTION_NON_VOLATILE, perms, 0, &resultHandle, 0); + REG_OPTION_NON_VOLATILE, perms | access, 0, &resultHandle, 0); if (res == ERROR_SUCCESS) return resultHandle; @@ -169,11 +183,12 @@ static HKEY createOrOpenKey(HKEY parentHandle, REGSAM perms, const QString &rSub return 0; } -// Open or create a key in read-write mode if possible, otherwise read-only -static HKEY createOrOpenKey(HKEY parentHandle, const QString &rSubKey, bool *readOnly) +// Open or create a key in read-write mode if possible, otherwise read-only. +// "access" is to explicitly use the 32- or 64-bit branch. +static HKEY createOrOpenKey(HKEY parentHandle, const QString &rSubKey, bool *readOnly, REGSAM access = 0) { // try to open or create it read/write - HKEY resultHandle = createOrOpenKey(parentHandle, registryPermissions, rSubKey); + HKEY resultHandle = createOrOpenKey(parentHandle, registryPermissions, rSubKey, access); if (resultHandle != 0) { if (readOnly != 0) *readOnly = false; @@ -181,7 +196,7 @@ static HKEY createOrOpenKey(HKEY parentHandle, const QString &rSubKey, bool *rea } // try to open or create it read/only - resultHandle = createOrOpenKey(parentHandle, KEY_READ, rSubKey); + resultHandle = createOrOpenKey(parentHandle, KEY_READ, rSubKey, access); if (resultHandle != 0) { if (readOnly != 0) *readOnly = true; @@ -247,9 +262,9 @@ static QStringList childKeysOrGroups(HKEY parentHandle, QSettingsPrivate::ChildS return result; } -static void allKeys(HKEY parentHandle, const QString &rSubKey, NameSet *result) +static void allKeys(HKEY parentHandle, const QString &rSubKey, NameSet *result, REGSAM access = 0) { - HKEY handle = openKey(parentHandle, KEY_READ, rSubKey); + HKEY handle = openKey(parentHandle, KEY_READ, rSubKey, access); if (handle == 0) return; @@ -270,11 +285,11 @@ static void allKeys(HKEY parentHandle, const QString &rSubKey, NameSet *result) if (!s.isEmpty()) s += QLatin1Char('\\'); s += childGroups.at(i); - allKeys(parentHandle, s, result); + allKeys(parentHandle, s, result, access); } } -static void deleteChildGroups(HKEY parentHandle) +static void deleteChildGroups(HKEY parentHandle, REGSAM access = 0) { QStringList childGroups = childKeysOrGroups(parentHandle, QSettingsPrivate::ChildGroups); @@ -282,10 +297,10 @@ static void deleteChildGroups(HKEY parentHandle) QString group = childGroups.at(i); // delete subgroups in group - HKEY childGroupHandle = openKey(parentHandle, registryPermissions, group); + HKEY childGroupHandle = openKey(parentHandle, registryPermissions, group, access); if (childGroupHandle == 0) continue; - deleteChildGroups(childGroupHandle); + deleteChildGroups(childGroupHandle, access); RegCloseKey(childGroupHandle); // delete group itself @@ -305,7 +320,7 @@ static void deleteChildGroups(HKEY parentHandle) class RegistryKey { public: - RegistryKey(HKEY parent_handle = 0, const QString &key = QString(), bool read_only = true); + RegistryKey(HKEY parent_handle = 0, const QString &key = QString(), bool read_only = true, REGSAM access = 0); QString key() const; HKEY handle() const; HKEY parentHandle() const; @@ -316,13 +331,15 @@ private: mutable HKEY m_handle; QString m_key; mutable bool m_read_only; + REGSAM m_access; }; -RegistryKey::RegistryKey(HKEY parent_handle, const QString &key, bool read_only) +RegistryKey::RegistryKey(HKEY parent_handle, const QString &key, bool read_only, REGSAM access) : m_parent_handle(parent_handle), m_handle(0), m_key(key), - m_read_only(read_only) + m_read_only(read_only), + m_access(access) { } @@ -337,9 +354,9 @@ HKEY RegistryKey::handle() const return m_handle; if (m_read_only) - m_handle = openKey(m_parent_handle, KEY_READ, m_key); + m_handle = openKey(m_parent_handle, KEY_READ, m_key, m_access); else - m_handle = createOrOpenKey(m_parent_handle, m_key, &m_read_only); + m_handle = createOrOpenKey(m_parent_handle, m_key, &m_read_only, m_access); return m_handle; } @@ -371,8 +388,8 @@ class QWinSettingsPrivate : public QSettingsPrivate { public: QWinSettingsPrivate(QSettings::Scope scope, const QString &organization, - const QString &application); - QWinSettingsPrivate(QString rKey); + const QString &application, REGSAM access = 0); + QWinSettingsPrivate(QString rKey, REGSAM access = 0); ~QWinSettingsPrivate(); void remove(const QString &uKey); @@ -390,11 +407,13 @@ public: private: RegistryKeyList regList; // list of registry locations to search for keys bool deleteWriteHandleOnExit; + REGSAM access; }; QWinSettingsPrivate::QWinSettingsPrivate(QSettings::Scope scope, const QString &organization, - const QString &application) - : QSettingsPrivate(QSettings::NativeFormat, scope, organization, application) + const QString &application, REGSAM access) + : QSettingsPrivate(QSettings::NativeFormat, scope, organization, application), + access(access) { deleteWriteHandleOnExit = false; @@ -405,23 +424,24 @@ QWinSettingsPrivate::QWinSettingsPrivate(QSettings::Scope scope, const QString & if (scope == QSettings::UserScope) { if (!application.isEmpty()) - regList.append(RegistryKey(HKEY_CURRENT_USER, appPrefix, !regList.isEmpty())); + regList.append(RegistryKey(HKEY_CURRENT_USER, appPrefix, !regList.isEmpty(), access)); - regList.append(RegistryKey(HKEY_CURRENT_USER, orgPrefix, !regList.isEmpty())); + regList.append(RegistryKey(HKEY_CURRENT_USER, orgPrefix, !regList.isEmpty(), access)); } if (!application.isEmpty()) - regList.append(RegistryKey(HKEY_LOCAL_MACHINE, appPrefix, !regList.isEmpty())); + regList.append(RegistryKey(HKEY_LOCAL_MACHINE, appPrefix, !regList.isEmpty(), access)); - regList.append(RegistryKey(HKEY_LOCAL_MACHINE, orgPrefix, !regList.isEmpty())); + regList.append(RegistryKey(HKEY_LOCAL_MACHINE, orgPrefix, !regList.isEmpty(), access)); } if (regList.isEmpty()) setStatus(QSettings::AccessError); } -QWinSettingsPrivate::QWinSettingsPrivate(QString rPath) - : QSettingsPrivate(QSettings::NativeFormat) +QWinSettingsPrivate::QWinSettingsPrivate(QString rPath, REGSAM access) + : QSettingsPrivate(QSettings::NativeFormat), + access(access) { deleteWriteHandleOnExit = false; @@ -460,9 +480,9 @@ QWinSettingsPrivate::QWinSettingsPrivate(QString rPath) } if (rPath.length() == keyLength) - regList.append(RegistryKey(keyName, QString(), false)); + regList.append(RegistryKey(keyName, QString(), false, access)); else if (rPath[keyLength] == QLatin1Char('\\')) - regList.append(RegistryKey(keyName, rPath.mid(keyLength+1), false)); + regList.append(RegistryKey(keyName, rPath.mid(keyLength+1), false, access)); } bool QWinSettingsPrivate::readKey(HKEY parentHandle, const QString &rSubKey, QVariant *value) const @@ -471,7 +491,7 @@ bool QWinSettingsPrivate::readKey(HKEY parentHandle, const QString &rSubKey, QVa QString rSubkeyPath = keyPath(rSubKey); // open a handle on the subkey - HKEY handle = openKey(parentHandle, KEY_READ, rSubkeyPath); + HKEY handle = openKey(parentHandle, KEY_READ, rSubkeyPath, access); if (handle == 0) return false; @@ -604,16 +624,16 @@ void QWinSettingsPrivate::remove(const QString &uKey) // try to delete value bar in key foo LONG res; - HKEY handle = openKey(writeHandle(), registryPermissions, keyPath(rKey)); + HKEY handle = openKey(writeHandle(), registryPermissions, keyPath(rKey), access); if (handle != 0) { res = RegDeleteValue(handle, reinterpret_cast<const wchar_t *>(keyName(rKey).utf16())); RegCloseKey(handle); } // try to delete key foo/bar and all subkeys - handle = openKey(writeHandle(), registryPermissions, rKey); + handle = openKey(writeHandle(), registryPermissions, rKey, access); if (handle != 0) { - deleteChildGroups(handle); + deleteChildGroups(handle, access); if (rKey.isEmpty()) { QStringList childKeys = childKeysOrGroups(handle, QSettingsPrivate::ChildKeys); @@ -661,7 +681,7 @@ void QWinSettingsPrivate::set(const QString &uKey, const QVariant &value) QString rKey = escapedKey(uKey); - HKEY handle = createOrOpenKey(writeHandle(), registryPermissions, keyPath(rKey)); + HKEY handle = createOrOpenKey(writeHandle(), registryPermissions, keyPath(rKey), access); if (handle == 0) { setStatus(QSettings::AccessError); return; @@ -775,13 +795,13 @@ QStringList QWinSettingsPrivate::children(const QString &uKey, ChildSpec spec) c HKEY parent_handle = regList.at(i).handle(); if (parent_handle == 0) continue; - HKEY handle = openKey(parent_handle, KEY_READ, rKey); + HKEY handle = openKey(parent_handle, KEY_READ, rKey, access); if (handle == 0) continue; if (spec == AllKeys) { NameSet keys; - allKeys(handle, QLatin1String(""), &keys); + allKeys(handle, QLatin1String(""), &keys, access); mergeKeySets(&result, keys); } else { // ChildGroups or ChildKeys QStringList names = childKeysOrGroups(handle, spec); @@ -836,20 +856,26 @@ bool QWinSettingsPrivate::isWritable() const QSettingsPrivate *QSettingsPrivate::create(QSettings::Format format, QSettings::Scope scope, const QString &organization, const QString &application) { - if (format == QSettings::NativeFormat) { + if (format == QSettings::NativeFormat) return new QWinSettingsPrivate(scope, organization, application); - } else { + else if (format == QSettings::Registry32Format) + return new QWinSettingsPrivate(scope, organization, application, KEY_WOW64_32KEY); + else if (format == QSettings::Registry64Format) + return new QWinSettingsPrivate(scope, organization, application, KEY_WOW64_64KEY); + else return new QConfFileSettingsPrivate(format, scope, organization, application); - } } QSettingsPrivate *QSettingsPrivate::create(const QString &fileName, QSettings::Format format) { - if (format == QSettings::NativeFormat) { + if (format == QSettings::NativeFormat) return new QWinSettingsPrivate(fileName); - } else { + else if (format == QSettings::Registry32Format) + return new QWinSettingsPrivate(fileName, KEY_WOW64_32KEY); + else if (format == QSettings::Registry64Format) + return new QWinSettingsPrivate(fileName, KEY_WOW64_64KEY); + else return new QConfFileSettingsPrivate(fileName, format); - } } QT_END_NAMESPACE diff --git a/src/corelib/io/qstandardpaths.cpp b/src/corelib/io/qstandardpaths.cpp index 8828e09e8f..0137e859e7 100644 --- a/src/corelib/io/qstandardpaths.cpp +++ b/src/corelib/io/qstandardpaths.cpp @@ -277,13 +277,13 @@ QT_BEGIN_NAMESPACE \header \li Path type \li Android \li iOS \row \li DesktopLocation \li "<APPROOT>/files" - \li "<APPROOT>/<APPDIR>" (not writable) + \li "<APPROOT>/Documents/Desktop" \row \li DocumentsLocation \li "<USER>/Documents", "<USER>/<APPNAME>/Documents" \li "<APPROOT>/Documents" \row \li FontsLocation \li "/system/fonts" (not writable) - \li "<APPROOT>/Documents/.fonts" + \li "<APPROOT>/Library/Fonts" \row \li ApplicationsLocation \li not supported (directory not readable) \li not supported @@ -301,7 +301,7 @@ QT_BEGIN_NAMESPACE \li "<APPROOT>/tmp" \row \li HomeLocation \li "<APPROOT>/files" - \li "<APPROOT>/<APPDIR>" (not writable) + \li "<APPROOT>" (not writable) \row \li DataLocation \li "<APPROOT>/files", "<USER>/<APPNAME>/files" \li "<APPROOT>/Library/Application Support" @@ -316,13 +316,13 @@ QT_BEGIN_NAMESPACE \li not supported \row \li ConfigLocation \li "<APPROOT>/files/settings" - \li "<APPROOT>/Documents" + \li "<APPROOT>/Library/Preferences" \row \li GenericConfigLocation \li "<APPROOT>/files/settings" (there is no shared settings) - \li "<APPROOT>/Documents" + \li "<APPROOT>/Library/Preferences" \row \li DownloadLocation \li "<USER>/Downloads", "<USER>/<APPNAME>/Downloads" - \li "<APPROOT>/Documents/Download" + \li "<APPROOT>/Documents/Downloads" \row \li GenericCacheLocation \li "<APPROOT>/cache" (there is no shared cache) \li "<APPROOT>/Library/Caches" @@ -331,7 +331,7 @@ QT_BEGIN_NAMESPACE \li "<APPROOT>/Library/Application Support" \row \li AppConfigLocation \li "<APPROOT>/files/settings" - \li "<APPROOT>/Documents" + \li "<APPROOT>/Library/Preferences/<APPNAME>" \row \li AppLocalDataLocation \li "<APPROOT>/files", "<USER>/<APPNAME>/files" \li "<APPROOT>/Library/Application Support" @@ -555,7 +555,7 @@ QString QStandardPaths::findExecutable(const QString &executableName, const QStr an empty QString if no relevant location can be found. */ -#if !defined(Q_OS_OSX) && !defined(QT_BOOTSTRAPPED) +#if !defined(Q_OS_MAC) && !defined(QT_BOOTSTRAPPED) QString QStandardPaths::displayName(StandardLocation type) { switch (type) { diff --git a/src/corelib/io/qstandardpaths_ios.mm b/src/corelib/io/qstandardpaths_ios.mm deleted file mode 100644 index eb85e2fd23..0000000000 --- a/src/corelib/io/qstandardpaths_ios.mm +++ /dev/null @@ -1,133 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL21$ -** 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 The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#import <UIKit/UIKit.h> - -#include "qstandardpaths.h" - -#ifndef QT_NO_STANDARDPATHS - -QT_BEGIN_NAMESPACE - -static QString pathForDirectory(NSSearchPathDirectory directory) -{ - return QString::fromNSString( - [NSSearchPathForDirectoriesInDomains(directory, NSUserDomainMask, YES) lastObject]); -} - -static QString bundlePath() -{ - return QString::fromNSString([[NSBundle mainBundle] bundlePath]); -} - -QString QStandardPaths::writableLocation(StandardLocation type) -{ - QString location; - - switch (type) { - case DocumentsLocation: - location = pathForDirectory(NSDocumentDirectory); - break; - case FontsLocation: - location = pathForDirectory(NSDocumentDirectory) + QLatin1String("/.fonts"); - break; - case ApplicationsLocation: - // NSApplicationDirectory points to a non-existing write-protected path. - break; - case MusicLocation: - // NSMusicDirectory points to a non-existing write-protected path. Use sensible fallback. - location = pathForDirectory(NSDocumentDirectory) + QLatin1String("/Music"); - break; - case MoviesLocation: - // NSMoviesDirectory points to a non-existing write-protected path. Use sensible fallback. - location = pathForDirectory(NSDocumentDirectory) + QLatin1String("/Movies"); - break; - case PicturesLocation: - // NSPicturesDirectory points to a non-existing write-protected path. Use sensible fallback. - location = pathForDirectory(NSDocumentDirectory) + QLatin1String("/Pictures"); - break; - case TempLocation: - location = QString::fromNSString(NSTemporaryDirectory()); - break; - case DesktopLocation: - case HomeLocation: - location = bundlePath(); - break; - case AppDataLocation: - case AppLocalDataLocation: - location = pathForDirectory(NSApplicationSupportDirectory); - break; - case GenericDataLocation: - location = pathForDirectory(NSDocumentDirectory); - break; - case CacheLocation: - case GenericCacheLocation: - location = pathForDirectory(NSCachesDirectory); - break; - case ConfigLocation: - case GenericConfigLocation: - case AppConfigLocation: - location = pathForDirectory(NSDocumentDirectory); - break; - case DownloadLocation: - // NSDownloadsDirectory points to a non-existing write-protected path. - location = pathForDirectory(NSDocumentDirectory) + QLatin1String("/Download"); - break; - case RuntimeLocation: - break; - default: - break; - } - - return location; -} - -QStringList QStandardPaths::standardLocations(StandardLocation type) -{ - QStringList dirs; - - switch (type) { - case PicturesLocation: - dirs << writableLocation(PicturesLocation) << QLatin1String("assets-library://"); - break; - default: - dirs << writableLocation(type); - break; - } - - return dirs; -} - -QT_END_NAMESPACE - -#endif // QT_NO_STANDARDPATHS diff --git a/src/corelib/io/qstandardpaths_mac.mm b/src/corelib/io/qstandardpaths_mac.mm index d6126ce1c3..57d365e916 100644 --- a/src/corelib/io/qstandardpaths_mac.mm +++ b/src/corelib/io/qstandardpaths_mac.mm @@ -32,6 +32,9 @@ ****************************************************************************/ #include "qstandardpaths.h" + +#ifndef QT_NO_STANDARDPATHS + #include <qdir.h> #include <qurl.h> #include <private/qcore_mac_p.h> @@ -40,63 +43,47 @@ #include <qcoreapplication.h> #endif -#include <CoreFoundation/CoreFoundation.h> -#include <ApplicationServices/ApplicationServices.h> +#import <Foundation/Foundation.h> QT_BEGIN_NAMESPACE -/* - Translates a QStandardPaths::StandardLocation into the mac equivalent. -*/ -OSType translateLocation(QStandardPaths::StandardLocation type) +static QString pathForDirectory(NSSearchPathDirectory directory, + NSSearchPathDomainMask mask) +{ + return QString::fromNSString( + [NSSearchPathForDirectoriesInDomains(directory, mask, YES) lastObject]); +} + +static NSSearchPathDirectory searchPathDirectory(QStandardPaths::StandardLocation type) { switch (type) { - case QStandardPaths::ConfigLocation: - case QStandardPaths::GenericConfigLocation: - case QStandardPaths::AppConfigLocation: - return kPreferencesFolderType; case QStandardPaths::DesktopLocation: - return kDesktopFolderType; + return NSDesktopDirectory; case QStandardPaths::DocumentsLocation: - return kDocumentsFolderType; - case QStandardPaths::FontsLocation: - // There are at least two different font directories on the mac: /Library/Fonts and ~/Library/Fonts. - // To select a specific one we have to specify a different first parameter when calling FSFindFolder. - return kFontsFolderType; + return NSDocumentDirectory; case QStandardPaths::ApplicationsLocation: - return kApplicationsFolderType; + return NSApplicationDirectory; case QStandardPaths::MusicLocation: - return kMusicDocumentsFolderType; + return NSMusicDirectory; case QStandardPaths::MoviesLocation: - return kMovieDocumentsFolderType; + return NSMoviesDirectory; case QStandardPaths::PicturesLocation: - return kPictureDocumentsFolderType; - case QStandardPaths::TempLocation: - return kTemporaryFolderType; + return NSPicturesDirectory; case QStandardPaths::GenericDataLocation: case QStandardPaths::RuntimeLocation: case QStandardPaths::AppDataLocation: case QStandardPaths::AppLocalDataLocation: - return kApplicationSupportFolderType; + return NSApplicationSupportDirectory; case QStandardPaths::GenericCacheLocation: case QStandardPaths::CacheLocation: - return kCachedDataFolderType; + return NSCachesDirectory; + case QStandardPaths::DownloadLocation: + return NSDownloadsDirectory; default: - return kDesktopFolderType; + return (NSSearchPathDirectory)0; } } -/* - Constructs a full unicode path from a FSRef. -*/ -static QString getFullPath(const FSRef &ref) -{ - QByteArray ba(2048, 0); - if (FSRefMakePath(&ref, reinterpret_cast<UInt8 *>(ba.data()), ba.size()) == noErr) - return QString::fromUtf8(ba.constData()).normalized(QString::NormalizationForm_C); - return QString(); -} - static void appendOrganizationAndApp(QString &path) { #ifndef QT_BOOTSTRAPPED @@ -111,28 +98,65 @@ static void appendOrganizationAndApp(QString &path) #endif } -static QString macLocation(QStandardPaths::StandardLocation type, short domain) +static QString baseWritableLocation(QStandardPaths::StandardLocation type, + NSSearchPathDomainMask mask = NSUserDomainMask, + bool appendOrgAndApp = false) { - // https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/index.html - if (type == QStandardPaths::DownloadLocation) { - NSFileManager *fileManager = [NSFileManager defaultManager]; - NSURL *url = [fileManager URLForDirectory:NSDownloadsDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil]; - if (!url) - return QString(); - return QString::fromNSString([url path]); + QString path; + const NSSearchPathDirectory dir = searchPathDirectory(type); + switch (type) { + case QStandardPaths::HomeLocation: + path = QDir::homePath(); + break; + case QStandardPaths::TempLocation: + path = QDir::tempPath(); + break; +#ifdef Q_OS_IOS + // These locations point to non-existing write-protected paths. Use sensible fallbacks. + case QStandardPaths::MusicLocation: + path = pathForDirectory(NSDocumentDirectory, mask) + QLatin1String("/Music"); + break; + case QStandardPaths::MoviesLocation: + path = pathForDirectory(NSDocumentDirectory, mask) + QLatin1String("/Movies"); + break; + case QStandardPaths::PicturesLocation: + path = pathForDirectory(NSDocumentDirectory, mask) + QLatin1String("/Pictures"); + break; + case QStandardPaths::DownloadLocation: + path = pathForDirectory(NSDocumentDirectory, mask) + QLatin1String("/Downloads"); + break; + case QStandardPaths::DesktopLocation: + path = pathForDirectory(NSDocumentDirectory, mask) + QLatin1String("/Desktop"); + break; + case QStandardPaths::ApplicationsLocation: + break; +#endif + case QStandardPaths::FontsLocation: + path = pathForDirectory(NSLibraryDirectory, mask) + QLatin1String("/Fonts"); + break; + case QStandardPaths::ConfigLocation: + case QStandardPaths::GenericConfigLocation: + case QStandardPaths::AppConfigLocation: + path = pathForDirectory(NSLibraryDirectory, mask) + QLatin1String("/Preferences"); + break; + default: + path = pathForDirectory(dir, mask); + break; } - // http://developer.apple.com/documentation/Carbon/Reference/Folder_Manager/Reference/reference.html - FSRef ref; - OSErr err = FSFindFolder(domain, translateLocation(type), false, &ref); - if (err) - return QString(); - - QString path = getFullPath(ref); + if (appendOrgAndApp) { + switch (type) { + case QStandardPaths::AppDataLocation: + case QStandardPaths::AppLocalDataLocation: + case QStandardPaths::AppConfigLocation: + case QStandardPaths::CacheLocation: + appendOrganizationAndApp(path); + break; + default: + break; + } + } - if (type == QStandardPaths::AppDataLocation || type == QStandardPaths::AppLocalDataLocation || - type == QStandardPaths::CacheLocation || type == QStandardPaths::AppConfigLocation) - appendOrganizationAndApp(path); return path; } @@ -167,31 +191,32 @@ QString QStandardPaths::writableLocation(StandardLocation type) } } - switch (type) { - case HomeLocation: - return QDir::homePath(); - case TempLocation: - return QDir::tempPath(); - case GenericDataLocation: - case AppDataLocation: - case AppLocalDataLocation: - case GenericCacheLocation: - case CacheLocation: - case RuntimeLocation: - return macLocation(type, kUserDomain); - default: - return macLocation(type, kOnAppropriateDisk); - } + return baseWritableLocation(type, NSUserDomainMask, true); } QStringList QStandardPaths::standardLocations(StandardLocation type) { QStringList dirs; - if (type == GenericDataLocation || type == AppDataLocation || type == AppLocalDataLocation || type == GenericCacheLocation || type == CacheLocation) { - const QString path = macLocation(type, kOnAppropriateDisk); - if (!path.isEmpty()) - dirs.append(path); +#ifdef Q_OS_IOS + if (type == PicturesLocation) + dirs << writableLocation(PicturesLocation) << QLatin1String("assets-library://"); +#endif + + if (type == GenericDataLocation || type == FontsLocation || type == ApplicationsLocation + || type == AppDataLocation || type == AppLocalDataLocation + || type == GenericCacheLocation || type == CacheLocation) { + QList<NSSearchPathDomainMask> masks; + masks << NSLocalDomainMask; + if (type == FontsLocation || type == GenericCacheLocation) + masks << NSSystemDomainMask; + + for (QList<NSSearchPathDomainMask>::const_iterator it = masks.begin(); + it != masks.end(); ++it) { + const QString path = baseWritableLocation(type, *it, true); + if (!path.isEmpty() && !dirs.contains(path)) + dirs.append(path); + } } if (type == AppDataLocation || type == AppLocalDataLocation) { @@ -219,28 +244,41 @@ QStringList QStandardPaths::standardLocations(StandardLocation type) } } const QString localDir = writableLocation(type); - dirs.prepend(localDir); + if (!localDir.isEmpty()) + dirs.prepend(localDir); return dirs; } #ifndef QT_BOOTSTRAPPED QString QStandardPaths::displayName(StandardLocation type) { + // Use "Home" instead of the user's Unix username if (QStandardPaths::HomeLocation == type) return QCoreApplication::translate("QStandardPaths", "Home"); - FSRef ref; - OSErr err = FSFindFolder(kOnAppropriateDisk, translateLocation(type), false, &ref); - if (err) - return QString(); + // The temporary directory returned by the old Carbon APIs is ~/Library/Caches/TemporaryItems, + // the display name of which ("TemporaryItems") isn't translated by the system. The standard + // temporary directory has no reasonable display name either, so use something more sensible. + if (QStandardPaths::TempLocation == type) + return QCoreApplication::translate("QStandardPaths", "Temporary Items"); - QCFString displayName; - err = LSCopyDisplayNameForRef(&ref, &displayName); - if (err) - return QString(); + // standardLocations() may return an empty list on some platforms + if (QStandardPaths::ApplicationsLocation == type) + return QCoreApplication::translate("QStandardPaths", "Applications"); - return static_cast<QString>(displayName); + if (QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, + standardLocations(type).first().toCFString(), + kCFURLPOSIXPathStyle, true)) { + QCFString name; + CFURLCopyResourcePropertyForKey(url, kCFURLLocalizedNameKey, &name, NULL); + if (name && CFStringGetLength(name)) + return QString::fromCFString(name); + } + + return QFileInfo(baseWritableLocation(type)).fileName(); } #endif QT_END_NAMESPACE + +#endif // QT_NO_STANDARDPATHS diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 2719019d30..53725c7f90 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -2686,7 +2686,7 @@ void QCoreApplication::removeLibraryPath(const QString &path) i.e. MSG or XCB event structs. \note Native event filters will be disabled when the application the - Qt::AA_MacPluginApplication attribute is set. + Qt::AA_PluginApplication attribute is set. For maximum portability, you should always try to use QEvent and QObject::installEventFilter() whenever possible. @@ -2697,8 +2697,8 @@ void QCoreApplication::removeLibraryPath(const QString &path) */ void QCoreApplication::installNativeEventFilter(QAbstractNativeEventFilter *filterObj) { - if (QCoreApplication::testAttribute(Qt::AA_MacPluginApplication)) { - qWarning("Native event filters are not applied when the Qt::AA_MacPluginApplication attribute is set"); + if (QCoreApplication::testAttribute(Qt::AA_PluginApplication)) { + qWarning("Native event filters are not applied when the Qt::AA_PluginApplication attribute is set"); return; } diff --git a/src/corelib/kernel/qcoreevent.h b/src/corelib/kernel/qcoreevent.h index 53da4a849b..d9de828fa1 100644 --- a/src/corelib/kernel/qcoreevent.h +++ b/src/corelib/kernel/qcoreevent.h @@ -276,6 +276,8 @@ public: PlatformSurface = 217, // Platform surface created or about to be destroyed + Pointer = 218, // QQuickPointerEvent; ### Qt 6: QPointerEvent + // 512 reserved for Qt Jambi's MetaCall event // 513 reserved for Qt Jambi's DeleteOnMainThread event diff --git a/src/corelib/kernel/qmetaobjectbuilder.cpp b/src/corelib/kernel/qmetaobjectbuilder.cpp index 021e137273..e346d7b44e 100644 --- a/src/corelib/kernel/qmetaobjectbuilder.cpp +++ b/src/corelib/kernel/qmetaobjectbuilder.cpp @@ -36,6 +36,7 @@ #include "qobject_p.h" #include "qmetaobject_p.h" +#include <vector> #include <stdlib.h> QT_BEGIN_NAMESPACE @@ -88,7 +89,6 @@ static inline Q_DECL_UNUSED const QMetaObjectPrivate *priv(const uint* data) class QMetaMethodBuilderPrivate { public: - QMetaMethodBuilderPrivate() {} // for QVector, don't use QMetaMethodBuilderPrivate (QMetaMethod::MethodType _methodType, const QByteArray& _signature, @@ -145,7 +145,6 @@ Q_DECLARE_TYPEINFO(QMetaMethodBuilderPrivate, Q_MOVABLE_TYPE); class QMetaPropertyBuilderPrivate { public: - QMetaPropertyBuilderPrivate() {} // for QVector, don't use QMetaPropertyBuilderPrivate (const QByteArray& _name, const QByteArray& _type, int notifierIdx=-1, int _revision = 0) @@ -184,7 +183,6 @@ Q_DECLARE_TYPEINFO(QMetaPropertyBuilderPrivate, Q_MOVABLE_TYPE); class QMetaEnumBuilderPrivate { public: - QMetaEnumBuilderPrivate() {} // for QVector, don't use QMetaEnumBuilderPrivate(const QByteArray& _name) : name(_name), isFlag(false) { @@ -213,19 +211,19 @@ public: QByteArray className; const QMetaObject *superClass; QMetaObjectBuilder::StaticMetacallFunction staticMetacallFunction; - QVector<QMetaMethodBuilderPrivate> methods; - QVector<QMetaMethodBuilderPrivate> constructors; - QVector<QMetaPropertyBuilderPrivate> properties; + std::vector<QMetaMethodBuilderPrivate> methods; + std::vector<QMetaMethodBuilderPrivate> constructors; + std::vector<QMetaPropertyBuilderPrivate> properties; QList<QByteArray> classInfoNames; QList<QByteArray> classInfoValues; - QVector<QMetaEnumBuilderPrivate> enumerators; + std::vector<QMetaEnumBuilderPrivate> enumerators; QList<const QMetaObject *> relatedMetaObjects; int flags; }; bool QMetaObjectBuilderPrivate::hasRevisionedProperties() const { - for (int i = 0; i < properties.size(); ++i) { + for (size_t i = 0; i < properties.size(); ++i) { if (properties.at(i).revision) return true; } @@ -234,7 +232,7 @@ bool QMetaObjectBuilderPrivate::hasRevisionedProperties() const bool QMetaObjectBuilderPrivate::hasRevisionedMethods() const { - for (int i = 0; i < methods.size(); ++i) { + for (size_t i = 0; i < methods.size(); ++i) { if (methods.at(i).revision) return true; } @@ -353,7 +351,7 @@ void QMetaObjectBuilder::setFlags(MetaObjectFlags flags) */ int QMetaObjectBuilder::methodCount() const { - return d->methods.size(); + return int(d->methods.size()); } /*! @@ -363,7 +361,7 @@ int QMetaObjectBuilder::methodCount() const */ int QMetaObjectBuilder::constructorCount() const { - return d->constructors.size(); + return int(d->constructors.size()); } /*! @@ -374,7 +372,7 @@ int QMetaObjectBuilder::constructorCount() const */ int QMetaObjectBuilder::propertyCount() const { - return d->properties.size(); + return int(d->properties.size()); } /*! @@ -386,7 +384,7 @@ int QMetaObjectBuilder::propertyCount() const */ int QMetaObjectBuilder::enumeratorCount() const { - return d->enumerators.size(); + return int(d->enumerators.size()); } /*! @@ -427,8 +425,8 @@ int QMetaObjectBuilder::relatedMetaObjectCount() const */ QMetaMethodBuilder QMetaObjectBuilder::addMethod(const QByteArray& signature) { - int index = d->methods.size(); - d->methods.append(QMetaMethodBuilderPrivate(QMetaMethod::Method, signature)); + int index = int(d->methods.size()); + d->methods.push_back(QMetaMethodBuilderPrivate(QMetaMethod::Method, signature)); return QMetaMethodBuilder(this, index); } @@ -444,8 +442,8 @@ QMetaMethodBuilder QMetaObjectBuilder::addMethod(const QByteArray& signature) QMetaMethodBuilder QMetaObjectBuilder::addMethod (const QByteArray& signature, const QByteArray& returnType) { - int index = d->methods.size(); - d->methods.append(QMetaMethodBuilderPrivate + int index = int(d->methods.size()); + d->methods.push_back(QMetaMethodBuilderPrivate (QMetaMethod::Method, signature, returnType)); return QMetaMethodBuilder(this, index); } @@ -491,8 +489,8 @@ QMetaMethodBuilder QMetaObjectBuilder::addMethod(const QMetaMethod& prototype) */ QMetaMethodBuilder QMetaObjectBuilder::addSlot(const QByteArray& signature) { - int index = d->methods.size(); - d->methods.append(QMetaMethodBuilderPrivate(QMetaMethod::Slot, signature)); + int index = int(d->methods.size()); + d->methods.push_back(QMetaMethodBuilderPrivate(QMetaMethod::Slot, signature)); return QMetaMethodBuilder(this, index); } @@ -506,8 +504,8 @@ QMetaMethodBuilder QMetaObjectBuilder::addSlot(const QByteArray& signature) */ QMetaMethodBuilder QMetaObjectBuilder::addSignal(const QByteArray& signature) { - int index = d->methods.size(); - d->methods.append(QMetaMethodBuilderPrivate + int index = int(d->methods.size()); + d->methods.push_back(QMetaMethodBuilderPrivate (QMetaMethod::Signal, signature, QByteArray("void"), QMetaMethod::Public)); return QMetaMethodBuilder(this, index); } @@ -523,9 +521,9 @@ QMetaMethodBuilder QMetaObjectBuilder::addSignal(const QByteArray& signature) */ QMetaMethodBuilder QMetaObjectBuilder::addConstructor(const QByteArray& signature) { - int index = d->constructors.size(); - d->constructors.append(QMetaMethodBuilderPrivate(QMetaMethod::Constructor, signature, - /*returnType=*/QByteArray())); + int index = int(d->constructors.size()); + d->constructors.push_back(QMetaMethodBuilderPrivate(QMetaMethod::Constructor, signature, + /*returnType=*/QByteArray())); return QMetaMethodBuilder(this, -(index + 1)); } @@ -564,8 +562,8 @@ QMetaMethodBuilder QMetaObjectBuilder::addConstructor(const QMetaMethod& prototy QMetaPropertyBuilder QMetaObjectBuilder::addProperty (const QByteArray& name, const QByteArray& type, int notifierId) { - int index = d->properties.size(); - d->properties.append(QMetaPropertyBuilderPrivate(name, type, notifierId)); + int index = int(d->properties.size()); + d->properties.push_back(QMetaPropertyBuilderPrivate(name, type, notifierId)); return QMetaPropertyBuilder(this, index); } @@ -615,8 +613,8 @@ QMetaPropertyBuilder QMetaObjectBuilder::addProperty(const QMetaProperty& protot */ QMetaEnumBuilder QMetaObjectBuilder::addEnumerator(const QByteArray& name) { - int index = d->enumerators.size(); - d->enumerators.append(QMetaEnumBuilderPrivate(name)); + int index = int(d->enumerators.size()); + d->enumerators.push_back(QMetaEnumBuilderPrivate(name)); return QMetaEnumBuilder(this, index); } @@ -762,7 +760,7 @@ void QMetaObjectBuilder::addMetaObject */ QMetaMethodBuilder QMetaObjectBuilder::method(int index) const { - if (index >= 0 && index < d->methods.size()) + if (uint(index) < d->methods.size()) return QMetaMethodBuilder(this, index); else return QMetaMethodBuilder(); @@ -775,7 +773,7 @@ QMetaMethodBuilder QMetaObjectBuilder::method(int index) const */ QMetaMethodBuilder QMetaObjectBuilder::constructor(int index) const { - if (index >= 0 && index < d->constructors.size()) + if (uint(index) < d->constructors.size()) return QMetaMethodBuilder(this, -(index + 1)); else return QMetaMethodBuilder(); @@ -788,7 +786,7 @@ QMetaMethodBuilder QMetaObjectBuilder::constructor(int index) const */ QMetaPropertyBuilder QMetaObjectBuilder::property(int index) const { - if (index >= 0 && index < d->properties.size()) + if (uint(index) < d->properties.size()) return QMetaPropertyBuilder(this, index); else return QMetaPropertyBuilder(); @@ -802,7 +800,7 @@ QMetaPropertyBuilder QMetaObjectBuilder::property(int index) const */ QMetaEnumBuilder QMetaObjectBuilder::enumerator(int index) const { - if (index >= 0 && index < d->enumerators.size()) + if (uint(index) < d->enumerators.size()) return QMetaEnumBuilder(this, index); else return QMetaEnumBuilder(); @@ -866,9 +864,9 @@ QByteArray QMetaObjectBuilder::classInfoValue(int index) const */ void QMetaObjectBuilder::removeMethod(int index) { - if (index >= 0 && index < d->methods.size()) { - d->methods.removeAt(index); - for (int prop = 0; prop < d->properties.size(); ++prop) { + if (uint(index) < d->methods.size()) { + d->methods.erase(d->methods.begin() + index); + for (size_t prop = 0; prop < d->properties.size(); ++prop) { // Adjust the indices of property notify signal references. if (d->properties[prop].notifySignal == index) { d->properties[prop].notifySignal = -1; @@ -888,8 +886,8 @@ void QMetaObjectBuilder::removeMethod(int index) */ void QMetaObjectBuilder::removeConstructor(int index) { - if (index >= 0 && index < d->constructors.size()) - d->constructors.removeAt(index); + if (uint(index) < d->constructors.size()) + d->constructors.erase(d->constructors.begin() + index); } /*! @@ -900,8 +898,8 @@ void QMetaObjectBuilder::removeConstructor(int index) */ void QMetaObjectBuilder::removeProperty(int index) { - if (index >= 0 && index < d->properties.size()) - d->properties.removeAt(index); + if (uint(index) < d->properties.size()) + d->properties.erase(d->properties.begin() + index); } /*! @@ -913,8 +911,8 @@ void QMetaObjectBuilder::removeProperty(int index) */ void QMetaObjectBuilder::removeEnumerator(int index) { - if (index >= 0 && index < d->enumerators.size()) - d->enumerators.removeAt(index); + if (uint(index) < d->enumerators.size()) + d->enumerators.erase(d->enumerators.begin() + index); } /*! @@ -959,9 +957,9 @@ void QMetaObjectBuilder::removeRelatedMetaObject(int index) int QMetaObjectBuilder::indexOfMethod(const QByteArray& signature) { QByteArray sig = QMetaObject::normalizedSignature(signature); - for (int index = 0; index < d->methods.size(); ++index) { + for (size_t index = 0; index < d->methods.size(); ++index) { if (sig == d->methods[index].signature) - return index; + return int(index); } return -1; } @@ -975,10 +973,10 @@ int QMetaObjectBuilder::indexOfMethod(const QByteArray& signature) int QMetaObjectBuilder::indexOfSignal(const QByteArray& signature) { QByteArray sig = QMetaObject::normalizedSignature(signature); - for (int index = 0; index < d->methods.size(); ++index) { + for (size_t index = 0; index < d->methods.size(); ++index) { if (sig == d->methods[index].signature && d->methods[index].methodType() == QMetaMethod::Signal) - return index; + return int(index); } return -1; } @@ -992,10 +990,10 @@ int QMetaObjectBuilder::indexOfSignal(const QByteArray& signature) int QMetaObjectBuilder::indexOfSlot(const QByteArray& signature) { QByteArray sig = QMetaObject::normalizedSignature(signature); - for (int index = 0; index < d->methods.size(); ++index) { + for (size_t index = 0; index < d->methods.size(); ++index) { if (sig == d->methods[index].signature && d->methods[index].methodType() == QMetaMethod::Slot) - return index; + return int(index); } return -1; } @@ -1009,9 +1007,9 @@ int QMetaObjectBuilder::indexOfSlot(const QByteArray& signature) int QMetaObjectBuilder::indexOfConstructor(const QByteArray& signature) { QByteArray sig = QMetaObject::normalizedSignature(signature); - for (int index = 0; index < d->constructors.size(); ++index) { + for (size_t index = 0; index < d->constructors.size(); ++index) { if (sig == d->constructors[index].signature) - return index; + return int(index); } return -1; } @@ -1024,9 +1022,9 @@ int QMetaObjectBuilder::indexOfConstructor(const QByteArray& signature) */ int QMetaObjectBuilder::indexOfProperty(const QByteArray& name) { - for (int index = 0; index < d->properties.size(); ++index) { + for (size_t index = 0; index < d->properties.size(); ++index) { if (name == d->properties[index].name) - return index; + return int(index); } return -1; } @@ -1039,9 +1037,9 @@ int QMetaObjectBuilder::indexOfProperty(const QByteArray& name) */ int QMetaObjectBuilder::indexOfEnumerator(const QByteArray& name) { - for (int index = 0; index < d->enumerators.size(); ++index) { + for (size_t index = 0; index < d->enumerators.size(); ++index) { if (name == d->enumerators[index].name) - return index; + return int(index); } return -1; } @@ -1155,10 +1153,10 @@ void QMetaStringTable::writeBlob(char *out) const // Returns the sum of all parameters (including return type) for the given // \a methods. This is needed for calculating the size of the methods' // parameter type/name meta-data. -static int aggregateParameterCount(const QVector<QMetaMethodBuilderPrivate> &methods) +static int aggregateParameterCount(const std::vector<QMetaMethodBuilderPrivate> &methods) { int sum = 0; - for (int i = 0; i < methods.size(); ++i) + for (size_t i = 0; i < methods.size(); ++i) sum += methods.at(i).parameterCount() + 1; // +1 for return type return sum; } @@ -1200,7 +1198,7 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, = reinterpret_cast<QMetaObjectPrivate *>(buf + size); int pmetaSize = size; dataIndex = MetaObjectPrivateFieldCount; - for (index = 0; index < d->properties.size(); ++index) { + for (size_t index = 0; index < d->properties.size(); ++index) { if (d->properties[index].notifySignal != -1) { hasNotifySignals = true; break; @@ -1209,8 +1207,8 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, int methodParametersDataSize = ((aggregateParameterCount(d->methods) + aggregateParameterCount(d->constructors)) * 2) // types and parameter names - - d->methods.size() // return "parameters" don't have names - - d->constructors.size(); // "this" parameters don't have names + - int(d->methods.size()) // return "parameters" don't have names + - int(d->constructors.size()); // "this" parameters don't have names if (buf) { Q_STATIC_ASSERT_X(QMetaObjectPrivate::OutputRevision == 7, "QMetaObjectBuilder should generate the same version as moc"); pmeta->revision = QMetaObjectPrivate::OutputRevision; @@ -1222,48 +1220,48 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, pmeta->classInfoData = dataIndex; dataIndex += 2 * d->classInfoNames.size(); - pmeta->methodCount = d->methods.size(); + pmeta->methodCount = int(d->methods.size()); pmeta->methodData = dataIndex; - dataIndex += 5 * d->methods.size(); + dataIndex += 5 * int(d->methods.size()); if (hasRevisionedMethods) - dataIndex += d->methods.size(); + dataIndex += int(d->methods.size()); paramsIndex = dataIndex; dataIndex += methodParametersDataSize; - pmeta->propertyCount = d->properties.size(); + pmeta->propertyCount = int(d->properties.size()); pmeta->propertyData = dataIndex; - dataIndex += 3 * d->properties.size(); + dataIndex += 3 * int(d->properties.size()); if (hasNotifySignals) - dataIndex += d->properties.size(); + dataIndex += int(d->properties.size()); if (hasRevisionedProperties) - dataIndex += d->properties.size(); + dataIndex += int(d->properties.size()); - pmeta->enumeratorCount = d->enumerators.size(); + pmeta->enumeratorCount = int(d->enumerators.size()); pmeta->enumeratorData = dataIndex; - dataIndex += 4 * d->enumerators.size(); + dataIndex += 4 * int(d->enumerators.size()); - pmeta->constructorCount = d->constructors.size(); + pmeta->constructorCount = int(d->constructors.size()); pmeta->constructorData = dataIndex; - dataIndex += 5 * d->constructors.size(); + dataIndex += 5 * int(d->constructors.size()); } else { - dataIndex += 2 * d->classInfoNames.size(); - dataIndex += 5 * d->methods.size(); + dataIndex += 2 * int(d->classInfoNames.size()); + dataIndex += 5 * int(d->methods.size()); if (hasRevisionedMethods) - dataIndex += d->methods.size(); + dataIndex += int(d->methods.size()); paramsIndex = dataIndex; dataIndex += methodParametersDataSize; - dataIndex += 3 * d->properties.size(); + dataIndex += 3 * int(d->properties.size()); if (hasNotifySignals) - dataIndex += d->properties.size(); + dataIndex += int(d->properties.size()); if (hasRevisionedProperties) - dataIndex += d->properties.size(); - dataIndex += 4 * d->enumerators.size(); - dataIndex += 5 * d->constructors.size(); + dataIndex += int(d->properties.size()); + dataIndex += 4 * int(d->enumerators.size()); + dataIndex += 5 * int(d->constructors.size()); } // Allocate space for the enumerator key names and values. enumIndex = dataIndex; - for (index = 0; index < d->enumerators.size(); ++index) { + for (size_t index = 0; index < d->enumerators.size(); ++index) { QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]); dataIndex += 2 * enumerator->keys.size(); } @@ -1305,7 +1303,7 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, // Output the methods in the class. Q_ASSERT(!buf || dataIndex == pmeta->methodData); - for (index = 0; index < d->methods.size(); ++index) { + for (size_t index = 0; index < d->methods.size(); ++index) { QMetaMethodBuilderPrivate *method = &(d->methods[index]); int name = strings.enter(method->name()); int argc = method->parameterCount(); @@ -1324,7 +1322,7 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, paramsIndex += 1 + argc * 2; } if (hasRevisionedMethods) { - for (index = 0; index < d->methods.size(); ++index) { + for (size_t index = 0; index < d->methods.size(); ++index) { QMetaMethodBuilderPrivate *method = &(d->methods[index]); if (buf) data[dataIndex] = method->revision; @@ -1333,12 +1331,12 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, } // Output the method parameters in the class. - Q_ASSERT(!buf || dataIndex == pmeta->methodData + d->methods.size() * 5 - + (hasRevisionedMethods ? d->methods.size() : 0)); + Q_ASSERT(!buf || dataIndex == pmeta->methodData + int(d->methods.size()) * 5 + + (hasRevisionedMethods ? int(d->methods.size()) : 0)); for (int x = 0; x < 2; ++x) { - QVector<QMetaMethodBuilderPrivate> &methods = (x == 0) ? d->methods : d->constructors; - for (index = 0; index < methods.size(); ++index) { - QMetaMethodBuilderPrivate *method = &(methods[index]); + const std::vector<QMetaMethodBuilderPrivate> &methods = (x == 0) ? d->methods : d->constructors; + for (size_t index = 0; index < methods.size(); ++index) { + const QMetaMethodBuilderPrivate *method = &(methods[index]); QList<QByteArray> paramTypeNames = method->parameterTypes(); int paramCount = paramTypeNames.size(); for (int i = -1; i < paramCount; ++i) { @@ -1367,7 +1365,7 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, // Output the properties in the class. Q_ASSERT(!buf || dataIndex == pmeta->propertyData); - for (index = 0; index < d->properties.size(); ++index) { + for (size_t index = 0; index < d->properties.size(); ++index) { QMetaPropertyBuilderPrivate *prop = &(d->properties[index]); int name = strings.enter(prop->name); @@ -1390,7 +1388,7 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, dataIndex += 3; } if (hasNotifySignals) { - for (index = 0; index < d->properties.size(); ++index) { + for (size_t index = 0; index < d->properties.size(); ++index) { QMetaPropertyBuilderPrivate *prop = &(d->properties[index]); if (buf) { if (prop->notifySignal != -1) @@ -1402,7 +1400,7 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, } } if (hasRevisionedProperties) { - for (index = 0; index < d->properties.size(); ++index) { + for (size_t index = 0; index < d->properties.size(); ++index) { QMetaPropertyBuilderPrivate *prop = &(d->properties[index]); if (buf) data[dataIndex] = prop->revision; @@ -1412,7 +1410,7 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, // Output the enumerators in the class. Q_ASSERT(!buf || dataIndex == pmeta->enumeratorData); - for (index = 0; index < d->enumerators.size(); ++index) { + for (size_t index = 0; index < d->enumerators.size(); ++index) { QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]); int name = strings.enter(enumerator->name); int isFlag = (int)(enumerator->isFlag); @@ -1437,7 +1435,7 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, // Output the constructors in the class. Q_ASSERT(!buf || dataIndex == pmeta->constructorData); - for (index = 0; index < d->constructors.size(); ++index) { + for (size_t index = 0; index < d->constructors.size(); ++index) { QMetaMethodBuilderPrivate *method = &(d->constructors[index]); int name = strings.enter(method->name()); int argc = method->parameterCount(); @@ -1612,10 +1610,10 @@ void QMetaObjectBuilder::serialize(QDataStream& stream) const // Write the counts for each type of class member. stream << d->classInfoNames.size(); - stream << d->methods.size(); - stream << d->properties.size(); - stream << d->enumerators.size(); - stream << d->constructors.size(); + stream << int(d->methods.size()); + stream << int(d->properties.size()); + stream << int(d->enumerators.size()); + stream << int(d->constructors.size()); stream << d->relatedMetaObjects.size(); // Write the items of class information. @@ -1625,7 +1623,7 @@ void QMetaObjectBuilder::serialize(QDataStream& stream) const } // Write the methods. - for (index = 0; index < d->methods.size(); ++index) { + for (size_t index = 0; index < d->methods.size(); ++index) { const QMetaMethodBuilderPrivate *method = &(d->methods[index]); stream << method->signature; stream << method->returnType; @@ -1637,7 +1635,7 @@ void QMetaObjectBuilder::serialize(QDataStream& stream) const } // Write the properties. - for (index = 0; index < d->properties.size(); ++index) { + for (size_t index = 0; index < d->properties.size(); ++index) { const QMetaPropertyBuilderPrivate *property = &(d->properties[index]); stream << property->name; stream << property->type; @@ -1648,7 +1646,7 @@ void QMetaObjectBuilder::serialize(QDataStream& stream) const } // Write the enumerators. - for (index = 0; index < d->enumerators.size(); ++index) { + for (size_t index = 0; index < d->enumerators.size(); ++index) { const QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]); stream << enumerator->name; stream << enumerator->isFlag; @@ -1657,7 +1655,7 @@ void QMetaObjectBuilder::serialize(QDataStream& stream) const } // Write the constructors. - for (index = 0; index < d->constructors.size(); ++index) { + for (size_t index = 0; index < d->constructors.size(); ++index) { const QMetaMethodBuilderPrivate *method = &(d->constructors[index]); stream << method->signature; stream << method->returnType; @@ -1796,7 +1794,7 @@ void QMetaObjectBuilder::deserialize stream >> property->flags; stream >> property->notifySignal; if (property->notifySignal < -1 || - property->notifySignal >= d->methods.size()) { + property->notifySignal >= int(d->methods.size())) { // Notify signal method index is out of range. stream.setStatus(QDataStream::ReadCorruptData); return; @@ -1875,9 +1873,9 @@ void QMetaObjectBuilder::deserialize QMetaMethodBuilderPrivate *QMetaMethodBuilder::d_func() const { // Positive indices indicate methods, negative indices indicate constructors. - if (_mobj && _index >= 0 && _index < _mobj->d->methods.size()) + if (_mobj && _index >= 0 && _index < int(_mobj->d->methods.size())) return &(_mobj->d->methods[_index]); - else if (_mobj && -_index >= 1 && -_index <= _mobj->d->constructors.size()) + else if (_mobj && -_index >= 1 && -_index <= int(_mobj->d->constructors.size())) return &(_mobj->d->constructors[(-_index) - 1]); else return 0; @@ -2116,7 +2114,7 @@ void QMetaMethodBuilder::setRevision(int revision) QMetaPropertyBuilderPrivate *QMetaPropertyBuilder::d_func() const { - if (_mobj && _index >= 0 && _index < _mobj->d->properties.size()) + if (_mobj && _index >= 0 && _index < int(_mobj->d->properties.size())) return &(_mobj->d->properties[_index]); else return 0; @@ -2588,7 +2586,7 @@ void QMetaPropertyBuilder::setRevision(int revision) QMetaEnumBuilderPrivate *QMetaEnumBuilder::d_func() const { - if (_mobj && _index >= 0 && _index < _mobj->d->enumerators.size()) + if (_mobj && _index >= 0 && _index < int(_mobj->d->enumerators.size())) return &(_mobj->d->enumerators[_index]); else return 0; diff --git a/src/corelib/plugin/qfactoryloader.cpp b/src/corelib/plugin/qfactoryloader.cpp index cc5aa1394a..f7545b5bcb 100644 --- a/src/corelib/plugin/qfactoryloader.cpp +++ b/src/corelib/plugin/qfactoryloader.cpp @@ -33,7 +33,7 @@ #include "qfactoryloader_p.h" -#ifndef QT_NO_LIBRARY +#ifndef QT_NO_QOBJECT #include "qfactoryinterface.h" #include "qmap.h" #include <qdir.h> @@ -50,10 +50,6 @@ QT_BEGIN_NAMESPACE -Q_GLOBAL_STATIC(QList<QFactoryLoader *>, qt_factory_loaders) - -Q_GLOBAL_STATIC_WITH_ARGS(QMutex, qt_factoryloader_mutex, (QMutex::Recursive)) - namespace { // avoid duplicate QStringLiteral data: @@ -69,18 +65,24 @@ class QFactoryLoaderPrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QFactoryLoader) public: QFactoryLoaderPrivate(){} + QByteArray iid; +#ifndef QT_NO_LIBRARY ~QFactoryLoaderPrivate(); mutable QMutex mutex; - QByteArray iid; QList<QLibraryPrivate*> libraryList; QMap<QString,QLibraryPrivate*> keyMap; QString suffix; Qt::CaseSensitivity cs; QStringList loadedPaths; - - void unloadPath(const QString &path); +#endif }; +#ifndef QT_NO_LIBRARY + +Q_GLOBAL_STATIC(QList<QFactoryLoader *>, qt_factory_loaders) + +Q_GLOBAL_STATIC_WITH_ARGS(QMutex, qt_factoryloader_mutex, (QMutex::Recursive)) + QFactoryLoaderPrivate::~QFactoryLoaderPrivate() { for (int i = 0; i < libraryList.count(); ++i) { @@ -90,25 +92,6 @@ QFactoryLoaderPrivate::~QFactoryLoaderPrivate() } } -QFactoryLoader::QFactoryLoader(const char *iid, - const QString &suffix, - Qt::CaseSensitivity cs) - : QObject(*new QFactoryLoaderPrivate) -{ - moveToThread(QCoreApplicationPrivate::mainThread()); - Q_D(QFactoryLoader); - d->iid = iid; - d->cs = cs; - d->suffix = suffix; - - - QMutexLocker locker(qt_factoryloader_mutex()); - update(); - qt_factory_loaders()->append(this); -} - - - void QFactoryLoader::update() { #ifdef QT_SHARED @@ -229,13 +212,56 @@ QFactoryLoader::~QFactoryLoader() qt_factory_loaders()->removeAll(this); } +#if defined(Q_OS_UNIX) && !defined (Q_OS_MAC) +QLibraryPrivate *QFactoryLoader::library(const QString &key) const +{ + Q_D(const QFactoryLoader); + return d->keyMap.value(d->cs ? key : key.toLower()); +} +#endif + +void QFactoryLoader::refreshAll() +{ + QMutexLocker locker(qt_factoryloader_mutex()); + QList<QFactoryLoader *> *loaders = qt_factory_loaders(); + for (QList<QFactoryLoader *>::const_iterator it = loaders->constBegin(); + it != loaders->constEnd(); ++it) { + (*it)->update(); + } +} + +#endif // QT_NO_LIBRARY + +QFactoryLoader::QFactoryLoader(const char *iid, + const QString &suffix, + Qt::CaseSensitivity cs) + : QObject(*new QFactoryLoaderPrivate) +{ + moveToThread(QCoreApplicationPrivate::mainThread()); + Q_D(QFactoryLoader); + d->iid = iid; +#ifndef QT_NO_LIBRARY + d->cs = cs; + d->suffix = suffix; + + QMutexLocker locker(qt_factoryloader_mutex()); + update(); + qt_factory_loaders()->append(this); +#else + Q_UNUSED(suffix); + Q_UNUSED(cs); +#endif +} + QList<QJsonObject> QFactoryLoader::metaData() const { Q_D(const QFactoryLoader); - QMutexLocker locker(&d->mutex); QList<QJsonObject> metaData; +#ifndef QT_NO_LIBRARY + QMutexLocker locker(&d->mutex); for (int i = 0; i < d->libraryList.size(); ++i) metaData.append(d->libraryList.at(i)->metaData); +#endif foreach (const QStaticPlugin &plugin, QPluginLoader::staticPlugins()) { const QJsonObject object = plugin.metaData(); @@ -252,6 +278,7 @@ QObject *QFactoryLoader::instance(int index) const if (index < 0) return 0; +#ifndef QT_NO_LIBRARY if (index < d->libraryList.size()) { QLibraryPrivate *library = d->libraryList.at(index); if (library->instance || library->loadPlugin()) { @@ -266,8 +293,9 @@ QObject *QFactoryLoader::instance(int index) const } return 0; } - index -= d->libraryList.size(); +#endif + QVector<QStaticPlugin> staticPlugins = QPluginLoader::staticPlugins(); for (int i = 0; i < staticPlugins.count(); ++i) { const QJsonObject object = staticPlugins.at(i).metaData(); @@ -282,24 +310,6 @@ QObject *QFactoryLoader::instance(int index) const return 0; } -#if defined(Q_OS_UNIX) && !defined (Q_OS_MAC) -QLibraryPrivate *QFactoryLoader::library(const QString &key) const -{ - Q_D(const QFactoryLoader); - return d->keyMap.value(d->cs ? key : key.toLower()); -} -#endif - -void QFactoryLoader::refreshAll() -{ - QMutexLocker locker(qt_factoryloader_mutex()); - QList<QFactoryLoader *> *loaders = qt_factory_loaders(); - for (QList<QFactoryLoader *>::const_iterator it = loaders->constBegin(); - it != loaders->constEnd(); ++it) { - (*it)->update(); - } -} - QMultiMap<int, QString> QFactoryLoader::keyMap() const { QMultiMap<int, QString> result; @@ -335,4 +345,4 @@ int QFactoryLoader::indexOf(const QString &needle) const QT_END_NAMESPACE -#endif // QT_NO_LIBRARY +#endif // QT_NO_QOBJECT diff --git a/src/corelib/plugin/qfactoryloader_p.h b/src/corelib/plugin/qfactoryloader_p.h index 1c48491b0d..ee07084180 100644 --- a/src/corelib/plugin/qfactoryloader_p.h +++ b/src/corelib/plugin/qfactoryloader_p.h @@ -45,17 +45,18 @@ // We mean it. // +#include "QtCore/qglobal.h" +#ifndef QT_NO_QOBJECT + #include "QtCore/qobject.h" #include "QtCore/qstringlist.h" #include "QtCore/qjsonobject.h" #include "QtCore/qmap.h" #include "private/qlibrary_p.h" -#ifndef QT_NO_LIBRARY QT_BEGIN_NAMESPACE class QFactoryLoaderPrivate; - class Q_CORE_EXPORT QFactoryLoader : public QObject { Q_OBJECT @@ -65,21 +66,23 @@ public: explicit QFactoryLoader(const char *iid, const QString &suffix = QString(), Qt::CaseSensitivity = Qt::CaseSensitive); + +#ifndef QT_NO_LIBRARY ~QFactoryLoader(); - QList<QJsonObject> metaData() const; - QObject *instance(int index) const; + void update(); + static void refreshAll(); #if defined(Q_OS_UNIX) && !defined (Q_OS_MAC) QLibraryPrivate *library(const QString &key) const; -#endif +#endif // Q_OS_UNIX && !Q_OS_MAC +#endif // !QT_NO_LIBRARY QMultiMap<int, QString> keyMap() const; int indexOf(const QString &needle) const; - void update(); - - static void refreshAll(); + QList<QJsonObject> metaData() const; + QObject *instance(int index) const; }; template <class PluginInterface, class FactoryInterface> @@ -112,6 +115,6 @@ PluginInterface *qLoadPlugin1(const QFactoryLoader *loader, QT_END_NAMESPACE -#endif // QT_NO_LIBRARY +#endif // QT_NO_QOBJECT #endif // QFACTORYLOADER_P_H diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp index 920e02ae5a..763f0fb1e9 100644 --- a/src/corelib/plugin/qlibrary.cpp +++ b/src/corelib/plugin/qlibrary.cpp @@ -302,7 +302,7 @@ static bool findPatternUnloaded(const QString &library, QLibraryPrivate *lib) if (pos >= 0) { if (hasMetaData) { const char *data = filedata + pos; - QJsonDocument doc = QLibraryPrivate::fromRawMetaData(data); + QJsonDocument doc = qJsonFromRawLibraryMetaData(data); lib->metaData = doc.object(); if (qt_debug_component()) qWarning("Found metadata in lib %s, metadata=\n%s\n", @@ -677,7 +677,7 @@ static bool qt_get_metadata(QtPluginQueryVerificationDataFunction pfn, QLibraryP if (!szData) return false; - QJsonDocument doc = QLibraryPrivate::fromRawMetaData(szData); + QJsonDocument doc = qJsonFromRawLibraryMetaData(szData); if (doc.isNull()) return false; priv->metaData = doc.object(); diff --git a/src/corelib/plugin/qlibrary_p.h b/src/corelib/plugin/qlibrary_p.h index ada90d7bfd..11b0cb1eb9 100644 --- a/src/corelib/plugin/qlibrary_p.h +++ b/src/corelib/plugin/qlibrary_p.h @@ -57,9 +57,20 @@ # include "QtCore/qt_windows.h" #endif +QT_BEGIN_NAMESPACE + +// Needed also in case of QT_NO_LIBRARY, for static plugin loading. +inline QJsonDocument qJsonFromRawLibraryMetaData(const char *raw) +{ + raw += strlen("QTMETADATA "); + // the size of the embedded JSON object can be found 8 bytes into the data (see qjson_p.h), + // but doesn't include the size of the header (8 bytes) + QByteArray json(raw, qFromLittleEndian<uint>(*(const uint *)(raw + 8)) + 8); + return QJsonDocument::fromBinaryData(json); +} + #ifndef QT_NO_LIBRARY -QT_BEGIN_NAMESPACE bool qt_debug_component(); @@ -104,14 +115,6 @@ public: void updatePluginState(); bool isPlugin(); - static inline QJsonDocument fromRawMetaData(const char *raw) { - raw += strlen("QTMETADATA "); - // the size of the embedded JSON object can be found 8 bytes into the data (see qjson_p.h), - // but doesn't include the size of the header (8 bytes) - QByteArray json(raw, qFromLittleEndian<uint>(*(const uint *)(raw + 8)) + 8); - return QJsonDocument::fromBinaryData(json); - } - private: explicit QLibraryPrivate(const QString &canonicalFileName, const QString &version, QLibrary::LoadHints loadHints); ~QLibraryPrivate(); @@ -132,8 +135,8 @@ private: friend class QLibraryStore; }; -QT_END_NAMESPACE - #endif // QT_NO_LIBRARY +QT_END_NAMESPACE + #endif // QLIBRARY_P_H diff --git a/src/corelib/plugin/qpluginloader.cpp b/src/corelib/plugin/qpluginloader.cpp index 24101be87b..8264a27842 100644 --- a/src/corelib/plugin/qpluginloader.cpp +++ b/src/corelib/plugin/qpluginloader.cpp @@ -41,10 +41,10 @@ #include "qdebug.h" #include "qdir.h" -#ifndef QT_NO_LIBRARY - QT_BEGIN_NAMESPACE +#ifndef QT_NO_LIBRARY + /*! \class QPluginLoader \inmodule QtCore @@ -382,9 +382,6 @@ QString QPluginLoader::errorString() const return (!d || d->errorString.isEmpty()) ? tr("Unknown error") : d->errorString; } -typedef QVector<QStaticPlugin> StaticPluginList; -Q_GLOBAL_STATIC(StaticPluginList, staticPluginList) - /*! \since 4.4 \property QPluginLoader::loadHints @@ -413,6 +410,11 @@ QLibrary::LoadHints QPluginLoader::loadHints() const return d ? d->loadHints() : QLibrary::LoadHints(); } +#endif // QT_NO_LIBRARY + +typedef QVector<QStaticPlugin> StaticPluginList; +Q_GLOBAL_STATIC(StaticPluginList, staticPluginList) + /*! \relates QPluginLoader \since 5.0 @@ -465,9 +467,8 @@ QVector<QStaticPlugin> QPluginLoader::staticPlugins() */ QJsonObject QStaticPlugin::metaData() const { - return QLibraryPrivate::fromRawMetaData(rawMetaData()).object(); + return qJsonFromRawLibraryMetaData(rawMetaData()).object(); } QT_END_NAMESPACE -#endif // QT_NO_LIBRARY diff --git a/src/corelib/plugin/qpluginloader.h b/src/corelib/plugin/qpluginloader.h index 0ab25bbb07..5dc7d1b66c 100644 --- a/src/corelib/plugin/qpluginloader.h +++ b/src/corelib/plugin/qpluginloader.h @@ -37,10 +37,10 @@ #include <QtCore/qlibrary.h> #include <QtCore/qplugin.h> -#ifndef QT_NO_LIBRARY - QT_BEGIN_NAMESPACE +#ifndef QT_NO_LIBRARY + class QLibraryPrivate; class QJsonObject; @@ -78,8 +78,17 @@ private: Q_DISABLE_COPY(QPluginLoader) }; -QT_END_NAMESPACE +#else + +class Q_CORE_EXPORT QPluginLoader +{ +public: + static QObjectList staticInstances(); + static QVector<QStaticPlugin> staticPlugins(); +}; #endif // QT_NO_LIBRARY +QT_END_NAMESPACE + #endif //QPLUGINLOADER_H diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index a9f361c205..c223c9de6c 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -1713,6 +1713,14 @@ QByteArray &QByteArray::prepend(const char *str, int len) return *this; } +/*! \fn QByteArray &QByteArray::prepend(int count, char ch) + + \overload + \since 5.7 + + Prepends \a count copies of character \a ch to this byte array. +*/ + /*! \overload @@ -1825,6 +1833,17 @@ QByteArray &QByteArray::append(const char *str, int len) return *this; } +/*! \fn QByteArray &QByteArray::append(int count, char ch) + + \overload + \since 5.7 + + Appends \a count copies of character \a ch to this byte + array and returns a reference to this byte array. + + If \a count is negative or zero nothing is appended to the byte array. +*/ + /*! \overload @@ -1941,6 +1960,33 @@ QByteArray &QByteArray::insert(int i, char ch) return qbytearray_insert(this, i, &ch, 1); } +/*! \fn QByteArray &QByteArray::insert(int i, int count, char ch) + + \overload + \since 5.7 + + Inserts \a count copies of character \a ch at index position \a i in the + byte array. + + If \a i is greater than size(), the array is first extended using resize(). +*/ + +QByteArray &QByteArray::insert(int i, int count, char ch) +{ + if (i < 0 || count <= 0) + return *this; + + int oldsize = size(); + resize(qMax(i, oldsize) + count); + char *dst = d->data(); + if (i > oldsize) + ::memset(dst + oldsize, 0x20, i - oldsize); + else if (i < oldsize) + ::memmove(dst + i + count, dst + i, oldsize - i); + ::memset(dst + i, ch, count); + return *this; +} + /*! Removes \a len bytes from the array, starting at index position \a pos, and returns a reference to the array. diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index f0032227e8..6c79a603d3 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -255,21 +255,21 @@ public: # define Q_REQUIRED_RESULT # define Q_REQUIRED_RESULT_pushed # endif - QByteArray toLower() const & Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QByteArray toLower() const & Q_REQUIRED_RESULT { return toLower_helper(*this); } - QByteArray toLower() && Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QByteArray toLower() && Q_REQUIRED_RESULT { return toLower_helper(*this); } - QByteArray toUpper() const & Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QByteArray toUpper() const & Q_REQUIRED_RESULT { return toUpper_helper(*this); } - QByteArray toUpper() && Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QByteArray toUpper() && Q_REQUIRED_RESULT { return toUpper_helper(*this); } - QByteArray trimmed() const & Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QByteArray trimmed() const & Q_REQUIRED_RESULT { return trimmed_helper(*this); } - QByteArray trimmed() && Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QByteArray trimmed() && Q_REQUIRED_RESULT { return trimmed_helper(*this); } - QByteArray simplified() const & Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QByteArray simplified() const & Q_REQUIRED_RESULT { return simplified_helper(*this); } - QByteArray simplified() && Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QByteArray simplified() && Q_REQUIRED_RESULT { return simplified_helper(*this); } # ifdef Q_REQUIRED_RESULT_pushed # pragma pop_macro("Q_REQUIRED_RESULT") @@ -285,14 +285,17 @@ public: QByteArray rightJustified(int width, char fill = ' ', bool truncate = false) const Q_REQUIRED_RESULT; QByteArray &prepend(char c); + QByteArray &prepend(int count, char c); QByteArray &prepend(const char *s); QByteArray &prepend(const char *s, int len); QByteArray &prepend(const QByteArray &a); QByteArray &append(char c); + QByteArray &append(int count, char c); QByteArray &append(const char *s); QByteArray &append(const char *s, int len); QByteArray &append(const QByteArray &a); QByteArray &insert(int i, char c); + QByteArray &insert(int i, int count, char c); QByteArray &insert(int i, const char *s); QByteArray &insert(int i, const char *s, int len); QByteArray &insert(int i, const QByteArray &a); @@ -568,6 +571,10 @@ inline QByteArray::const_iterator QByteArray::cend() const { return d->data() + d->size; } inline QByteArray::const_iterator QByteArray::constEnd() const { return d->data() + d->size; } +inline QByteArray &QByteArray::append(int n, char ch) +{ return insert(d->size, n, ch); } +inline QByteArray &QByteArray::prepend(int n, char ch) +{ return insert(0, n, ch); } inline QByteArray &QByteArray::operator+=(char c) { return append(c); } inline QByteArray &QByteArray::operator+=(const char *s) diff --git a/src/corelib/tools/qregexp.h b/src/corelib/tools/qregexp.h index f384e6c51f..9c68c194e0 100644 --- a/src/corelib/tools/qregexp.h +++ b/src/corelib/tools/qregexp.h @@ -68,10 +68,9 @@ public: ~QRegExp(); QRegExp &operator=(const QRegExp &rx); #ifdef Q_COMPILER_RVALUE_REFS - inline QRegExp &operator=(QRegExp &&other) - { qSwap(priv,other.priv); return *this; } + QRegExp &operator=(QRegExp &&other) Q_DECL_NOTHROW { swap(other); return *this; } #endif - inline void swap(QRegExp &other) { qSwap(priv, other.priv); } + void swap(QRegExp &other) Q_DECL_NOTHROW { qSwap(priv, other.priv); } bool operator==(const QRegExp &rx) const; inline bool operator!=(const QRegExp &rx) const { return !operator==(rx); } diff --git a/src/corelib/tools/qringbuffer.cpp b/src/corelib/tools/qringbuffer.cpp index 85cfdaf129..e9b655c01e 100644 --- a/src/corelib/tools/qringbuffer.cpp +++ b/src/corelib/tools/qringbuffer.cpp @@ -65,6 +65,8 @@ const char *QRingBuffer::readPointerAtPosition(qint64 pos, qint64 &length) const void QRingBuffer::free(qint64 bytes) { + Q_ASSERT(bytes <= bufferSize); + while (bytes > 0) { const qint64 blockSize = buffers.first().size() - head; @@ -100,20 +102,25 @@ char *QRingBuffer::reserve(qint64 bytes) if (bytes <= 0 || bytes >= MaxByteArraySize) return 0; - const qint64 newSize = bytes + tail; - // if need buffer reallocation - if (newSize > buffers.last().size()) { - if (newSize > buffers.last().capacity() && (tail >= basicBlockSize - || newSize >= MaxByteArraySize)) { - // shrink this buffer to its current size - buffers.last().resize(tail); - - // create a new QByteArray - buffers.append(QByteArray()); - ++tailBuffer; - tail = 0; + if (buffers.isEmpty()) { + buffers.append(QByteArray()); + buffers.first().resize(qMax(basicBlockSize, int(bytes))); + } else { + const qint64 newSize = bytes + tail; + // if need buffer reallocation + if (newSize > buffers.last().size()) { + if (newSize > buffers.last().capacity() && (tail >= basicBlockSize + || newSize >= MaxByteArraySize)) { + // shrink this buffer to its current size + buffers.last().resize(tail); + + // create a new QByteArray + buffers.append(QByteArray()); + ++tailBuffer; + tail = 0; + } + buffers.last().resize(qMax(basicBlockSize, tail + int(bytes))); } - buffers.last().resize(qMax(basicBlockSize, tail + int(bytes))); } char *writePtr = buffers.last().data() + tail; @@ -134,9 +141,13 @@ char *QRingBuffer::reserveFront(qint64 bytes) return 0; if (head < bytes) { - buffers.first().remove(0, head); - if (tailBuffer == 0) - tail -= head; + if (buffers.isEmpty()) { + buffers.append(QByteArray()); + } else { + buffers.first().remove(0, head); + if (tailBuffer == 0) + tail -= head; + } head = qMax(basicBlockSize, int(bytes)); if (bufferSize == 0) { @@ -155,6 +166,8 @@ char *QRingBuffer::reserveFront(qint64 bytes) void QRingBuffer::chop(qint64 bytes) { + Q_ASSERT(bytes <= bufferSize); + while (bytes > 0) { if (tailBuffer == 0 || tail > bytes) { // keep a single block around if it does not exceed @@ -185,6 +198,9 @@ void QRingBuffer::chop(qint64 bytes) void QRingBuffer::clear() { + if (buffers.isEmpty()) + return; + buffers.erase(buffers.begin() + 1, buffers.end()); buffers.first().clear(); @@ -193,20 +209,32 @@ void QRingBuffer::clear() bufferSize = 0; } -qint64 QRingBuffer::indexOf(char c, qint64 maxLength) const +qint64 QRingBuffer::indexOf(char c, qint64 maxLength, qint64 pos) const { - qint64 index = 0; - qint64 j = head; - for (int i = 0; index < maxLength && i < buffers.size(); ++i) { - const char *ptr = buffers[i].constData() + j; - j = qMin(index + (i == tailBuffer ? tail : buffers[i].size()) - j, maxLength); - - while (index < j) { - if (*ptr++ == c) - return index; - ++index; + if (maxLength <= 0 || pos < 0) + return -1; + + qint64 index = -(pos + head); + for (int i = 0; i < buffers.size(); ++i) { + const qint64 nextBlockIndex = qMin(index + (i == tailBuffer ? tail : buffers[i].size()), + maxLength); + + if (nextBlockIndex > 0) { + const char *ptr = buffers[i].constData(); + if (index < 0) { + ptr -= index; + index = 0; + } + + const char *findPtr = reinterpret_cast<const char *>(memchr(ptr, c, + nextBlockIndex - index)); + if (findPtr) + return qint64(findPtr - ptr) + index + pos; + + if (nextBlockIndex == maxLength) + return -1; } - j = 0; + index = nextBlockIndex; } return -1; } @@ -288,7 +316,10 @@ qint64 QRingBuffer::peek(char *data, qint64 maxLength, qint64 pos) const void QRingBuffer::append(const QByteArray &qba) { if (tail == 0) { - buffers.last() = qba; + if (buffers.isEmpty()) + buffers.append(qba); + else + buffers.last() = qba; } else { buffers.last().resize(tail); buffers.append(qba); diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h index 68509a6a80..3a5ae1c4cc 100644 --- a/src/corelib/tools/qringbuffer_p.h +++ b/src/corelib/tools/qringbuffer_p.h @@ -54,9 +54,7 @@ class QRingBuffer { public: explicit inline QRingBuffer(int growth = 4096) : - head(0), tail(0), tailBuffer(0), basicBlockSize(growth), bufferSize(0) { - buffers.append(QByteArray()); - } + head(0), tail(0), tailBuffer(0), basicBlockSize(growth), bufferSize(0) { } inline qint64 nextDataBlockSize() const { return (tailBuffer == 0 ? tail : buffers.first().size()) - head; @@ -114,7 +112,7 @@ public: Q_CORE_EXPORT void clear(); inline qint64 indexOf(char c) const { return indexOf(c, size()); } - Q_CORE_EXPORT qint64 indexOf(char c, qint64 maxLength) const; + Q_CORE_EXPORT qint64 indexOf(char c, qint64 maxLength, qint64 pos = 0) const; Q_CORE_EXPORT qint64 read(char *data, qint64 maxLength); Q_CORE_EXPORT QByteArray read(); Q_CORE_EXPORT qint64 peek(char *data, qint64 maxLength, qint64 pos = 0) const; diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp index 86f4c6a268..4d30396cb6 100644 --- a/src/corelib/tools/qsharedpointer.cpp +++ b/src/corelib/tools/qsharedpointer.cpp @@ -1292,6 +1292,17 @@ compile. Use qSharedPointerConstCast to cast away the constness. */ +/*! + \fn QDebug operator<<(QDebug debug, const QSharedPointer<T> &ptr) + \relates QSharedPointer + \since 5.7 + + Writes the pointer tracked by \a ptr into the debug object \a debug for + debugging purposes. + + \sa {Debugging Techniques} +*/ + #include <qset.h> #include <qmutex.h> diff --git a/src/corelib/tools/qsharedpointer.h b/src/corelib/tools/qsharedpointer.h index 279ec36a28..56e13d500f 100644 --- a/src/corelib/tools/qsharedpointer.h +++ b/src/corelib/tools/qsharedpointer.h @@ -153,6 +153,8 @@ template <class X, class T> QSharedPointer<X> qSharedPointerObjectCast(const QWe template <class X, class T> QWeakPointer<X> qWeakPointerCast(const QWeakPointer<T> &src); +template <class T> QDebug operator<<(QDebug debug, const QSharedPointer<T> &ptr); + QT_END_NAMESPACE #endif // Q_QDOC diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 1323dd6b1c..ace6c5d093 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -55,6 +55,7 @@ QT_END_NAMESPACE #include <new> #include <QtCore/qatomic.h> #include <QtCore/qobject.h> // for qobject_cast +#include <QtCore/qdebug.h> #if QT_DEPRECATED_SINCE(5, 5) #include <QtCore/qhash.h> #endif @@ -305,7 +306,7 @@ public: inline T &operator*() const { return *data(); } inline T *operator->() const { return data(); } - QSharedPointer() : value(Q_NULLPTR), d(Q_NULLPTR) { } + QSharedPointer() Q_DECL_NOTHROW : value(Q_NULLPTR), d(Q_NULLPTR) {} ~QSharedPointer() { deref(); } inline explicit QSharedPointer(T *ptr) : value(ptr) // noexcept @@ -315,22 +316,22 @@ public: inline QSharedPointer(T *ptr, Deleter deleter) : value(ptr) // throws { internalConstruct(ptr, deleter); } - inline QSharedPointer(const QSharedPointer &other) : value(other.value), d(other.d) + QSharedPointer(const QSharedPointer &other) Q_DECL_NOTHROW : value(other.value), d(other.d) { if (d) ref(); } - inline QSharedPointer &operator=(const QSharedPointer &other) + QSharedPointer &operator=(const QSharedPointer &other) Q_DECL_NOTHROW { QSharedPointer copy(other); swap(copy); return *this; } #ifdef Q_COMPILER_RVALUE_REFS - inline QSharedPointer(QSharedPointer &&other) + QSharedPointer(QSharedPointer &&other) Q_DECL_NOTHROW : value(other.value), d(other.d) { other.d = Q_NULLPTR; other.value = Q_NULLPTR; } - inline QSharedPointer &operator=(QSharedPointer &&other) + QSharedPointer &operator=(QSharedPointer &&other) Q_DECL_NOTHROW { QSharedPointer moved(std::move(other)); swap(moved); @@ -596,7 +597,7 @@ public: inline bool operator !() const { return isNull(); } inline T *data() const { return d == Q_NULLPTR || d->strongref.load() == 0 ? Q_NULLPTR : value; } - inline QWeakPointer() : d(Q_NULLPTR), value(Q_NULLPTR) { } + inline QWeakPointer() Q_DECL_NOTHROW : d(Q_NULLPTR), value(Q_NULLPTR) { } inline ~QWeakPointer() { if (d && !d->weakref.deref()) delete d; } #ifndef QT_NO_QOBJECT @@ -614,15 +615,26 @@ public: { return *this = QWeakPointer(ptr); } #endif - inline QWeakPointer(const QWeakPointer &o) : d(o.d), value(o.value) + QWeakPointer(const QWeakPointer &other) Q_DECL_NOTHROW : d(other.d), value(other.value) { if (d) d->weakref.ref(); } - inline QWeakPointer &operator=(const QWeakPointer &o) +#ifdef Q_COMPILER_RVALUE_REFS + QWeakPointer(QWeakPointer &&other) Q_DECL_NOTHROW + : d(other.d), value(other.value) { - internalSet(o.d, o.value); + other.d = Q_NULLPTR; + other.value = Q_NULLPTR; + } + QWeakPointer &operator=(QWeakPointer &&other) Q_DECL_NOTHROW + { QWeakPointer moved(std::move(other)); swap(moved); return *this; } +#endif + QWeakPointer &operator=(const QWeakPointer &other) Q_DECL_NOTHROW + { + QWeakPointer copy(other); + swap(copy); return *this; } - inline void swap(QWeakPointer &other) + void swap(QWeakPointer &other) Q_DECL_NOTHROW { qSwap(this->d, other.d); qSwap(this->value, other.value); @@ -858,6 +870,16 @@ inline void qSwap(QSharedPointer<T> &p1, QSharedPointer<T> &p2) p1.swap(p2); } +#ifndef QT_NO_DEBUG_STREAM +template <class T> +Q_INLINE_TEMPLATE QDebug operator<<(QDebug debug, const QSharedPointer<T> &ptr) +{ + QDebugStateSaver saver(debug); + debug.nospace() << "QSharedPointer(" << ptr.data() << ")"; + return debug; +} +#endif + QT_END_NAMESPACE namespace std { template <class T> diff --git a/src/corelib/tools/qsimd_p.h b/src/corelib/tools/qsimd_p.h index 1e8b3420cf..96f5419af6 100644 --- a/src/corelib/tools/qsimd_p.h +++ b/src/corelib/tools/qsimd_p.h @@ -73,6 +73,7 @@ * SSE4_2 | x86 | I & C | I & C | I only | * AVX | x86 | I & C | I & C | I & C | * AVX2 | x86 | I & C | I & C | I only | + * AVX512xx | x86 | I & C | I & C | I only | * I = intrinsics; C = code generation * * Code can use the following constructs to determine compiler support & status: diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index 7829317d1f..47c4272389 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -386,25 +386,25 @@ public: # define Q_REQUIRED_RESULT # define Q_REQUIRED_RESULT_pushed # endif - QString toLower() const & Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QString toLower() const & Q_REQUIRED_RESULT { return toLower_helper(*this); } - QString toLower() && Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QString toLower() && Q_REQUIRED_RESULT { return toLower_helper(*this); } - QString toUpper() const & Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QString toUpper() const & Q_REQUIRED_RESULT { return toUpper_helper(*this); } - QString toUpper() && Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QString toUpper() && Q_REQUIRED_RESULT { return toUpper_helper(*this); } - QString toCaseFolded() const & Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QString toCaseFolded() const & Q_REQUIRED_RESULT { return toCaseFolded_helper(*this); } - QString toCaseFolded() && Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QString toCaseFolded() && Q_REQUIRED_RESULT { return toCaseFolded_helper(*this); } - QString trimmed() const & Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QString trimmed() const & Q_REQUIRED_RESULT { return trimmed_helper(*this); } - QString trimmed() && Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QString trimmed() && Q_REQUIRED_RESULT { return trimmed_helper(*this); } - QString simplified() const & Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QString simplified() const & Q_REQUIRED_RESULT { return simplified_helper(*this); } - QString simplified() && Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QString simplified() && Q_REQUIRED_RESULT { return simplified_helper(*this); } # ifdef Q_REQUIRED_RESULT_pushed # pragma pop_macro("Q_REQUIRED_RESULT") diff --git a/src/corelib/tools/qversionnumber.h b/src/corelib/tools/qversionnumber.h index ebf1844f38..6a2718ca28 100644 --- a/src/corelib/tools/qversionnumber.h +++ b/src/corelib/tools/qversionnumber.h @@ -273,7 +273,7 @@ public: Q_CORE_EXPORT static Q_DECL_PURE_FUNCTION QVersionNumber commonPrefix(const QVersionNumber &v1, const QVersionNumber &v2) Q_REQUIRED_RESULT; Q_CORE_EXPORT QString toString() const Q_REQUIRED_RESULT; - Q_CORE_EXPORT static Q_DECL_PURE_FUNCTION QVersionNumber fromString(const QString &string, int *suffixIndex = 0) Q_REQUIRED_RESULT; + Q_CORE_EXPORT static Q_DECL_PURE_FUNCTION QVersionNumber fromString(const QString &string, int *suffixIndex = Q_NULLPTR) Q_REQUIRED_RESULT; private: #ifndef QT_NO_DATASTREAM |