diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-10-06 01:01:08 +0200 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-10-06 01:01:08 +0200 |
commit | 2c4b44d7500be72b6eb74c4989e7311b3f924119 (patch) | |
tree | 8cf8cb8aa36f18ee9474486178f51c7fe0770ee8 /src | |
parent | 7e2016de5ee6d9cc2c5d6b94fab4bc56a8a33303 (diff) | |
parent | 327b305e95187fda869c5af407e78a17e0e381cd (diff) |
Merge remote-tracking branch 'origin/5.15' into dev
Change-Id: Ife31dad3c8dc43c5ff4d266e6d646230c5d20a50
Diffstat (limited to 'src')
39 files changed, 600 insertions, 118 deletions
diff --git a/src/corelib/Qt5CoreConfigExtras.cmake.in b/src/corelib/Qt5CoreConfigExtras.cmake.in index e0652fdcf9..659faac6a5 100644 --- a/src/corelib/Qt5CoreConfigExtras.cmake.in +++ b/src/corelib/Qt5CoreConfigExtras.cmake.in @@ -46,6 +46,8 @@ if (NOT TARGET Qt5::rcc) ) endif() +set(CMAKE_AUTOMOC_MACRO_NAMES "Q_OBJECT" "Q_GADGET" "Q_NAMESPACE" "Q_NAMESPACE_EXPORT") + set(Qt5Core_QMAKE_EXECUTABLE Qt5::qmake) set(Qt5Core_MOC_EXECUTABLE Qt5::moc) set(Qt5Core_RCC_EXECUTABLE Qt5::rcc) diff --git a/src/corelib/global/qfloat16.cpp b/src/corelib/global/qfloat16.cpp index 2ba4c79374..6c21b7de5a 100644 --- a/src/corelib/global/qfloat16.cpp +++ b/src/corelib/global/qfloat16.cpp @@ -155,7 +155,7 @@ QT_BEGIN_NAMESPACE int qfloat16::fpClassify() const noexcept { return isInf() ? FP_INFINITE : isNaN() ? FP_NAN - : !b16 ? FP_ZERO : isNormal() ? FP_NORMAL : FP_SUBNORMAL; + : !(b16 & 0x7fff) ? FP_ZERO : isNormal() ? FP_NORMAL : FP_SUBNORMAL; } /*! \fn int qRound(qfloat16 value) diff --git a/src/corelib/global/qfloat16.h b/src/corelib/global/qfloat16.h index 4d1aa91349..9a4f1800a4 100644 --- a/src/corelib/global/qfloat16.h +++ b/src/corelib/global/qfloat16.h @@ -94,7 +94,7 @@ public: static constexpr qfloat16 _limit_quiet_NaN() noexcept { return qfloat16(Wrap(0x7e00)); } // Signalling NaN is 0x7f00 inline constexpr bool isNormal() const noexcept - { return b16 == 0 || ((b16 & 0x7c00) && (b16 & 0x7c00) != 0x7c00); } + { return (b16 & 0x7fff) == 0 || ((b16 & 0x7c00) && (b16 & 0x7c00) != 0x7c00); } private: quint16 b16; constexpr inline explicit qfloat16(Wrap nibble) noexcept : b16(nibble.b16) {} @@ -296,7 +296,7 @@ class numeric_limits<QT_PREPEND_NAMESPACE(qfloat16)> : public numeric_limits<flo public: /* Treat quint16 b16 as if it were: - uint S: 1; // b16 >> 15 (sign) + uint S: 1; // b16 >> 15 (sign); can be set for zero uint E: 5; // (b16 >> 10) & 0x1f (offset exponent) uint M: 10; // b16 & 0x3ff (adjusted mantissa) diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 63ad44f79a..114a4d71e2 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -2956,11 +2956,10 @@ QString QSysInfo::prettyProductName() if (!name) return result + versionString; result += QLatin1String(name); -# if !defined(Q_OS_WIN) - return result + QLatin1String(" (") + versionString + QLatin1Char(')'); -# else +# if !defined(Q_OS_WIN) || defined(Q_OS_WINRT) + return result + QLatin1String(" (") + versionString + QLatin1Char(')'); +# else // (resembling winver.exe): Windows 10 "Windows 10 Version 1809" - result += QLatin1String(" Version "); if (majorVersion >= 10) { const auto releaseId = windows10ReleaseId(); if (!releaseId.isEmpty()) @@ -2968,7 +2967,7 @@ QString QSysInfo::prettyProductName() return result; } // Windows 7: "Windows 7 Version 6.1 (Build 7601: Service Pack 1)" - result += versionString + QLatin1String(" ("); + result += QLatin1String(" Version ") + versionString + QLatin1String(" ("); const auto build = windows7Build(); if (!build.isEmpty()) result += QLatin1String("Build ") + build; @@ -2976,7 +2975,7 @@ QString QSysInfo::prettyProductName() if (!servicePack.isEmpty()) result += QLatin1String(": ") + servicePack; return result + QLatin1Char(')'); -# endif // Windows +# endif // Windows #elif defined(Q_OS_HAIKU) return QLatin1String("Haiku ") + productVersion(); #elif defined(Q_OS_UNIX) diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index c7357f9d13..6476b7404a 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -495,6 +495,8 @@ static QString prefixFromAppDirHelper() #endif #if !defined(QT_BUILD_QMAKE) && QT_CONFIG(relocatable) +#if !defined(QT_STATIC) && !(defined(Q_OS_DARWIN) && QT_CONFIG(framework)) \ + && (QT_CONFIG(dlopen) || defined(Q_OS_WIN)) static QString prefixFromQtCoreLibraryHelper(const QString &qtCoreLibraryPath) { const QString qtCoreLibrary = QDir::fromNativeSeparators(qtCoreLibraryPath); @@ -503,6 +505,7 @@ static QString prefixFromQtCoreLibraryHelper(const QString &qtCoreLibraryPath) + QLatin1String(QT_CONFIGURE_LIBLOCATION_TO_PREFIX_PATH); return QDir::cleanPath(prefixDir); } +#endif #if defined(Q_OS_WIN) #if defined(Q_OS_WINRT) @@ -851,10 +854,14 @@ QT_END_NAMESPACE #include "private/qcoreapplication_p.h" +QT_WARNING_DISABLE_GCC("-Wattributes") +QT_WARNING_DISABLE_CLANG("-Wattributes") +QT_WARNING_DISABLE_INTEL(2621) + extern const char qt_core_interpreter[] __attribute__((section(".interp"))) = ELF_INTERPRETER; -extern "C" void qt_core_boilerplate(); +extern "C" void qt_core_boilerplate() __attribute__((force_align_arg_pointer)); void qt_core_boilerplate() { printf("This is the QtCore library version " QT_BUILD_STR "\n" diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index 4a119a1e2f..fc7122d904 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -746,7 +746,6 @@ bool QSettingsPrivate::iniUnescapedStringList(const QByteArray &str, int from, i { '\'', '\'' }, { '\\', '\\' } }; - static const int numEscapeCodes = sizeof(escapeCodes) / sizeof(escapeCodes[0]); bool isStringList = false; bool inQuotedString = false; @@ -770,9 +769,9 @@ StNormal: goto end; ch = str.at(i++); - for (int j = 0; j < numEscapeCodes; ++j) { - if (ch == escapeCodes[j][0]) { - stringResult += QLatin1Char(escapeCodes[j][1]); + for (const auto &escapeCode : escapeCodes) { + if (ch == escapeCode[0]) { + stringResult += QLatin1Char(escapeCode[1]); goto StNormal; } } diff --git a/src/corelib/kernel/qcore_mac_objc.mm b/src/corelib/kernel/qcore_mac_objc.mm index 9e9e71c397..b1f3b74cd4 100644 --- a/src/corelib/kernel/qcore_mac_objc.mm +++ b/src/corelib/kernel/qcore_mac_objc.mm @@ -211,6 +211,12 @@ QDebug operator<<(QDebug debug, const QMacAutoReleasePool *pool) debug << "QMacAutoReleasePool(" << (const void *)pool << ')'; return debug; } + +QDebug operator<<(QDebug debug, const QCFString &string) +{ + debug << static_cast<QString>(string); + return debug; +} #endif // !QT_NO_DEBUG_STREAM #ifdef Q_OS_MACOS diff --git a/src/corelib/kernel/qcore_mac_p.h b/src/corelib/kernel/qcore_mac_p.h index 3266dc10a8..535d3579b2 100644 --- a/src/corelib/kernel/qcore_mac_p.h +++ b/src/corelib/kernel/qcore_mac_p.h @@ -137,8 +137,10 @@ private: template <typename T> class QCFType : public QAppleRefCounted<T, CFTypeRef, CFRetain, CFRelease> { + using Base = QAppleRefCounted<T, CFTypeRef, CFRetain, CFRelease>; public: - using QAppleRefCounted<T, CFTypeRef, CFRetain, CFRelease>::QAppleRefCounted; + using Base::Base; + explicit QCFType(CFTypeRef r) : Base(static_cast<T>(r)) {} template <typename X> X as() const { return reinterpret_cast<X>(this->value); } static QCFType constructFromGet(const T &t) { @@ -151,6 +153,7 @@ public: class Q_CORE_EXPORT QCFString : public QCFType<CFStringRef> { public: + using QCFType<CFStringRef>::QCFType; inline QCFString(const QString &str) : QCFType<CFStringRef>(0), string(str) {} inline QCFString(const CFStringRef cfstr = 0) : QCFType<CFStringRef>(cfstr) {} inline QCFString(const QCFType<CFStringRef> &other) : QCFType<CFStringRef>(other) {} @@ -168,7 +171,8 @@ Q_CORE_EXPORT bool qt_mac_applicationIsInDarkMode(); #endif #ifndef QT_NO_DEBUG_STREAM -QDebug operator<<(QDebug debug, const QMacAutoReleasePool *pool); +Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QMacAutoReleasePool *pool); +Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QCFString &string); #endif Q_CORE_EXPORT bool qt_apple_isApplicationExtension(); diff --git a/src/corelib/text/qchar.cpp b/src/corelib/text/qchar.cpp index d959c55bb7..9b03a93278 100644 --- a/src/corelib/text/qchar.cpp +++ b/src/corelib/text/qchar.cpp @@ -61,6 +61,7 @@ QT_BEGIN_NAMESPACE /*! \class QLatin1Char \inmodule QtCore + \reentrant \brief The QLatin1Char class provides an 8-bit ASCII/Latin-1 character. \ingroup string-processing diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 48d57e5e6e..75a5bc802e 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -345,6 +345,23 @@ QByteArray QLocalePrivate::bcp47Name(char separator) const return localeId.withLikelySubtagsRemoved().name(separator); } +/*! + \internal + */ +QByteArray QLocalePrivate::rawName(char separator) const +{ + QByteArrayList parts; + if (m_data->m_language_id != QLocale::AnyLanguage) + parts.append(languageCode().latin1()); + if (m_data->m_script_id != QLocale::AnyScript) + parts.append(scriptCode().latin1()); + if (m_data->m_country_id != QLocale::AnyCountry) + parts.append(countryCode().latin1()); + + return parts.join(separator); +} + + static const QLocaleData *findLocaleDataById(const QLocaleId &lid) { QLocaleId localeId = lid.withLikelySubtagsAdded(); @@ -4367,30 +4384,63 @@ QString QLocale::formattedDataSize(qint64 bytes, int precision, DataSizeFormats */ QStringList QLocale::uiLanguages() const { + QStringList uiLanguages; + QVector<QLocale> locales; #ifndef QT_NO_SYSTEMLOCALE if (d->m_data == systemData()) { QVariant res = systemLocale()->query(QSystemLocale::UILanguages, QVariant()); if (!res.isNull()) { - QStringList result = res.toStringList(); - if (!result.isEmpty()) - return result; + uiLanguages = res.toStringList(); + // ... but we need to include likely-adjusted forms of each of those, too: + for (const auto entry : qAsConst(uiLanguages)) + locales.append(QLocale(entry)); } - } + } else #endif - QLocaleId id = QLocaleId::fromIds(d->m_data->m_language_id, d->m_data->m_script_id, - d->m_data->m_country_id); - const QLocaleId max = id.withLikelySubtagsAdded(); - const QLocaleId min = max.withLikelySubtagsRemoved(); + { + locales.append(*this); + } + for (int i = locales.size(); i-- > 0; ) { + const QLocale &locale = locales.at(i); + int j; + QByteArray prior; + if (i < uiLanguages.size()) { + // Adding likely-adjusted forms to system locale's list. + // Name the locale is derived from: + const QString &name = uiLanguages.at(i); + prior = name.toLatin1(); + // Don't try to likely-adjust if construction's likely-adjustments + // were so drastic the result doesn't match the prior name: + if (locale.name() != name && locale.d->rawName() != prior) + continue; + // Insert just after prior: + j = i + 1; + } else { + // Plain locale, not system locale; just append. + j = uiLanguages.size(); + } + const auto data = locale.d->m_data; + + QLocaleId id + = QLocaleId::fromIds(data->m_language_id, data->m_script_id, data->m_country_id); + const QLocaleId max = id.withLikelySubtagsAdded(); + const QLocaleId min = max.withLikelySubtagsRemoved(); + id.script_id = 0; // For re-use as script-less variant. + + // Include version with all likely sub-tags (last) if distinct from the rest: + if (max != min && max != id && max.name() != prior) + uiLanguages.insert(j, QString::fromLatin1(max.name())); + + // Include scriptless version if likely-equivalent and distinct: + if (data->m_script_id && id != min && id.name() != prior + && id.withLikelySubtagsAdded() == max) { + uiLanguages.insert(j, QString::fromLatin1(id.name())); + } - QStringList uiLanguages; - uiLanguages.append(QString::fromLatin1(min.name())); - if (id.script_id) { - id.script_id = 0; - if (id != min && id.withLikelySubtagsAdded() == max) - uiLanguages.append(QString::fromLatin1(id.name())); + // Include minimal version (first) unless it's what our locale is derived from: + if (min.name() != prior) + uiLanguages.insert(j, QString::fromLatin1(min.name())); } - if (max != min && max != id) - uiLanguages.append(QString::fromLatin1(max.name())); return uiLanguages; } diff --git a/src/corelib/text/qlocale_p.h b/src/corelib/text/qlocale_p.h index 5ebed9b385..edee3a89c7 100644 --- a/src/corelib/text/qlocale_p.h +++ b/src/corelib/text/qlocale_p.h @@ -359,6 +359,7 @@ public: quint16 countryId() const { return m_data->m_country_id; } QByteArray bcp47Name(char separator = '-') const; + QByteArray rawName(char separator = '-') const; inline QLatin1String languageCode() const { return languageToCode(QLocale::Language(m_data->m_language_id)); } inline QLatin1String scriptCode() const { return scriptToCode(QLocale::Script(m_data->m_script_id)); } diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index be987c359b..425ffa42a5 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -1051,7 +1051,7 @@ int lastIndexOf(const QList<T> &list, const U &u, int from) Node *n = reinterpret_cast<Node *>(list.p.at(from + 1)); while (n-- != b) { if (n->t() == u) - return typename QList<T>::difference_type(n - b); + return int(n - b); } } return -1; diff --git a/src/corelib/tools/qpair.qdoc b/src/corelib/tools/qpair.qdoc index 59e6931995..65576ef2e6 100644 --- a/src/corelib/tools/qpair.qdoc +++ b/src/corelib/tools/qpair.qdoc @@ -28,6 +28,7 @@ /*! \class QPair \inmodule QtCore + \reentrant \brief The QPair class is a template class that stores a pair of items. \ingroup tools diff --git a/src/dbus/qdbus_symbols.cpp b/src/dbus/qdbus_symbols.cpp index 284ba999c2..1e2cbf6da6 100644 --- a/src/dbus/qdbus_symbols.cpp +++ b/src/dbus/qdbus_symbols.cpp @@ -100,15 +100,15 @@ bool qdbus_loadLibDBus() }; lib->unload(); - for (uint i = 0; i < sizeof(majorversions) / sizeof(majorversions[0]); ++i) { - for (uint j = 0; j < sizeof(baseNames) / sizeof(baseNames[0]); ++j) { + for (const int majorversion : majorversions) { + for (const QString &baseName : baseNames) { #ifdef Q_OS_WIN QString suffix; - if (majorversions[i] != -1) - suffix = QString::number(- majorversions[i]); // negative so it prepends the dash - lib->setFileName(baseNames[j] + suffix); + if (majorversion != -1) + suffix = QString::number(- majorversion); // negative so it prepends the dash + lib->setFileName(baseName + suffix); #else - lib->setFileNameAndVersion(baseNames[j], majorversions[i]); + lib->setFileNameAndVersion(baseName, majorversion); #endif if (lib->load() && lib->resolve("dbus_connection_open_private")) return true; diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index a9c194afce..fa4c419ef0 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -2533,9 +2533,8 @@ void QGuiApplicationPrivate::processCloseEvent(QWindowSystemInterfacePrivate::Cl QCloseEvent event; QGuiApplication::sendSpontaneousEvent(e->window.data(), &event); - if (e->accepted) { - *(e->accepted) = event.isAccepted(); - } + + e->eventAccepted = event.isAccepted(); } void QGuiApplicationPrivate::processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e) diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp index 4e95751397..2a0cb1094c 100644 --- a/src/gui/kernel/qplatformwindow.cpp +++ b/src/gui/kernel/qplatformwindow.cpp @@ -348,9 +348,7 @@ void QPlatformWindow::setWindowIcon(const QIcon &icon) { Q_UNUSED(icon); } */ bool QPlatformWindow::close() { - bool accepted = false; - QWindowSystemInterface::handleCloseEvent<QWindowSystemInterface::SynchronousDelivery>(window(), &accepted); - return accepted; + return QWindowSystemInterface::handleCloseEvent<QWindowSystemInterface::SynchronousDelivery>(window()); } /*! diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp index 40a298226a..03be72ca30 100644 --- a/src/gui/kernel/qwindowsysteminterface.cpp +++ b/src/gui/kernel/qwindowsysteminterface.cpp @@ -340,13 +340,11 @@ QT_DEFINE_QPA_EVENT_HANDLER(void, handleExposeEvent, QWindow *window, const QReg QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e); } -QT_DEFINE_QPA_EVENT_HANDLER(void, handleCloseEvent, QWindow *window, bool *accepted) +QT_DEFINE_QPA_EVENT_HANDLER(bool, handleCloseEvent, QWindow *window) { - if (window) { - QWindowSystemInterfacePrivate::CloseEvent *e = - new QWindowSystemInterfacePrivate::CloseEvent(window, accepted); - QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e); - } + Q_ASSERT(window); + auto *event = new QWindowSystemInterfacePrivate::CloseEvent(window); + return QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(event); } /*! diff --git a/src/gui/kernel/qwindowsysteminterface.h b/src/gui/kernel/qwindowsysteminterface.h index fd70eda9ff..4a0bc858a9 100644 --- a/src/gui/kernel/qwindowsysteminterface.h +++ b/src/gui/kernel/qwindowsysteminterface.h @@ -194,7 +194,7 @@ public: static void handleExposeEvent(QWindow *window, const QRegion ®ion); template<typename Delivery = QWindowSystemInterface::DefaultDelivery> - static void handleCloseEvent(QWindow *window, bool *accepted = nullptr); + static bool handleCloseEvent(QWindow *window); template<typename Delivery = QWindowSystemInterface::DefaultDelivery> static void handleEnterEvent(QWindow *window, const QPointF &local = QPointF(), const QPointF& global = QPointF()); diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h index d6513f1836..540170f733 100644 --- a/src/gui/kernel/qwindowsysteminterface_p.h +++ b/src/gui/kernel/qwindowsysteminterface_p.h @@ -123,11 +123,10 @@ public: class CloseEvent : public WindowSystemEvent { public: - explicit CloseEvent(QWindow *w, bool *a = nullptr) - : WindowSystemEvent(Close), window(w), accepted(a) + explicit CloseEvent(QWindow *w) + : WindowSystemEvent(Close), window(w) { } QPointer<QWindow> window; - bool *accepted; }; class GeometryChangeEvent : public WindowSystemEvent { diff --git a/src/gui/painting/qpagesize.cpp b/src/gui/painting/qpagesize.cpp index a1c9f6e417..c98ca8a1fb 100644 --- a/src/gui/painting/qpagesize.cpp +++ b/src/gui/painting/qpagesize.cpp @@ -222,8 +222,6 @@ static const int qt_windowsConversion[][2] = { {DMPAPER_PENV_10_ROTATED, DMPAPER_PENV_10} // Is = DMPAPER_LAST, use as loop terminator }; -static const int windowsConversionCount = int(sizeof(qt_windowsConversion) / sizeof(qt_windowsConversion[0])); - // Standard sizes data struct StandardPageSize { QPageSize::PageSizeId id; @@ -423,9 +421,9 @@ static QPageSize::PageSizeId qt_idForWindowsID(int windowsId, QSize *match = 0) if (windowsId <= DMPAPER_NONE || windowsId > DMPAPER_LAST) return QPageSize::Custom; // Check if one of the unsupported values, convert to valid value if is - for (int i = 0; i < windowsConversionCount; ++i) { - if (qt_windowsConversion[i][0] == windowsId) { - windowsId = qt_windowsConversion[i][1]; + for (const auto &it : qt_windowsConversion) { + if (it[0] == windowsId) { + windowsId = it[1]; break; } } diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index cb32aa08f3..36a6557e04 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -3241,12 +3241,12 @@ QVector<int> QRhiVulkan::supportedSampleCounts() const VkSampleCountFlags stencil = limits->framebufferStencilSampleCounts; QVector<int> result; - for (size_t i = 0; i < sizeof(qvk_sampleCounts) / sizeof(qvk_sampleCounts[0]); ++i) { - if ((color & qvk_sampleCounts[i].mask) - && (depth & qvk_sampleCounts[i].mask) - && (stencil & qvk_sampleCounts[i].mask)) + for (const auto &qvk_sampleCount : qvk_sampleCounts) { + if ((color & qvk_sampleCount.mask) + && (depth & qvk_sampleCount.mask) + && (stencil & qvk_sampleCount.mask)) { - result.append(qvk_sampleCounts[i].count); + result.append(qvk_sampleCount.count); } } @@ -3263,9 +3263,9 @@ VkSampleCountFlagBits QRhiVulkan::effectiveSampleCount(int sampleCount) return VK_SAMPLE_COUNT_1_BIT; } - for (size_t i = 0; i < sizeof(qvk_sampleCounts) / sizeof(qvk_sampleCounts[0]); ++i) { - if (qvk_sampleCounts[i].count == sampleCount) - return qvk_sampleCounts[i].mask; + for (const auto &qvk_sampleCount : qvk_sampleCounts) { + if (qvk_sampleCount.count == sampleCount) + return qvk_sampleCount.mask; } Q_UNREACHABLE(); diff --git a/src/gui/text/qtextdocumentfragment.cpp b/src/gui/text/qtextdocumentfragment.cpp index 723e5c907c..742c56382d 100644 --- a/src/gui/text/qtextdocumentfragment.cpp +++ b/src/gui/text/qtextdocumentfragment.cpp @@ -1062,6 +1062,7 @@ QTextHtmlImporter::ProcessNodeResult QTextHtmlImporter::processBlockNode() fmt.setLeftPadding(leftPadding(currentNodeIdx)); if (rightPadding(currentNodeIdx) >= 0) fmt.setRightPadding(rightPadding(currentNodeIdx)); +#ifndef QT_NO_CSSPARSER if (tableCellBorder(currentNodeIdx, QCss::TopEdge) > 0) fmt.setTopBorder(tableCellBorder(currentNodeIdx, QCss::TopEdge)); if (tableCellBorder(currentNodeIdx, QCss::RightEdge) > 0) @@ -1086,6 +1087,7 @@ QTextHtmlImporter::ProcessNodeResult QTextHtmlImporter::processBlockNode() fmt.setBottomBorderBrush(tableCellBorderBrush(currentNodeIdx, QCss::BottomEdge)); if (tableCellBorderBrush(currentNodeIdx, QCss::LeftEdge) != Qt::NoBrush) fmt.setLeftBorderBrush(tableCellBorderBrush(currentNodeIdx, QCss::LeftEdge)); +#endif cell.setFormat(fmt); diff --git a/src/gui/text/qtextdocumentlayout.cpp b/src/gui/text/qtextdocumentlayout.cpp index a9a177da8b..1d5afee16b 100644 --- a/src/gui/text/qtextdocumentlayout.cpp +++ b/src/gui/text/qtextdocumentlayout.cpp @@ -265,6 +265,9 @@ public: inline QFixed topPadding(QTextTable *table, const QTextTableCell &cell) const { +#ifdef QT_NO_CSSPARSER + Q_UNUSED(table); +#endif return paddingProperty(cell.format(), QTextFormat::TableCellTopPadding) #ifndef QT_NO_CSSPARSER + cellBorderWidth(table, cell, QCss::TopEdge) @@ -274,6 +277,9 @@ public: inline QFixed bottomPadding(QTextTable *table, const QTextTableCell &cell) const { +#ifdef QT_NO_CSSPARSER + Q_UNUSED(table); +#endif return paddingProperty(cell.format(), QTextFormat::TableCellBottomPadding) #ifndef QT_NO_CSSPARSER + cellBorderWidth(table, cell, QCss::BottomEdge) @@ -283,6 +289,9 @@ public: inline QFixed leftPadding(QTextTable *table, const QTextTableCell &cell) const { +#ifdef QT_NO_CSSPARSER + Q_UNUSED(table); +#endif return paddingProperty(cell.format(), QTextFormat::TableCellLeftPadding) #ifndef QT_NO_CSSPARSER + cellBorderWidth(table, cell, QCss::LeftEdge) @@ -292,6 +301,9 @@ public: inline QFixed rightPadding(QTextTable *table, const QTextTableCell &cell) const { +#ifdef QT_NO_CSSPARSER + Q_UNUSED(table); +#endif return paddingProperty(cell.format(), QTextFormat::TableCellRightPadding) #ifndef QT_NO_CSSPARSER + cellBorderWidth(table, cell, QCss::RightEdge) @@ -1034,15 +1046,22 @@ static bool cellClipTest(QTextTable *table, QTextTableData *td, const QTextTableCell &cell, QRectF cellRect) { +#ifdef QT_NO_CSSPARSER + Q_UNUSED(table); + Q_UNUSED(cell); +#endif + if (!cell_context.clip.isValid()) return false; if (td->borderCollapse) { // we need to account for the cell borders in the clipping test +#ifndef QT_NO_CSSPARSER cellRect.adjust(-axisEdgeData(table, td, cell, QCss::LeftEdge).width / 2, -axisEdgeData(table, td, cell, QCss::TopEdge).width / 2, axisEdgeData(table, td, cell, QCss::RightEdge).width / 2, axisEdgeData(table, td, cell, QCss::BottomEdge).width / 2); +#endif } else { qreal border = td->border.toReal(); cellRect.adjust(-border, -border, border, border); @@ -1798,6 +1817,13 @@ void QTextDocumentLayoutPrivate::drawTableCellBorder(const QRectF &cellRect, QPa if (turn_off_antialiasing) painter->setRenderHint(QPainter::Antialiasing, false); +#else + Q_UNUSED(cell); + Q_UNUSED(cellRect); + Q_UNUSED(painter); + Q_UNUSED(table); + Q_UNUSED(td); + Q_UNUSED(cell); #endif } @@ -2285,12 +2311,14 @@ QTextLayoutStruct QTextDocumentLayoutPrivate::layoutCell(QTextTable *t, const QT + td->border + td->paddingProperty(cell.format(), QTextFormat::TableCellTopPadding); // top cell-border is not repeated +#ifndef QT_NO_CSSPARSER const int headerRowCount = t->format().headerRowCount(); if (td->borderCollapse && headerRowCount > 0) { // consider the header row's bottom edge width qreal headerRowBottomBorderWidth = axisEdgeData(t, td, t->cellAt(headerRowCount - 1, cell.column()), QCss::BottomEdge).width; layoutStruct.pageTopMargin += QFixed::fromReal(scaleToDevice(headerRowBottomBorderWidth) / 2); } +#endif layoutStruct.pageBottomMargin = td->effectiveBottomMargin + td->cellSpacing + td->effectiveBottomBorder + td->bottomPadding(t, cell); layoutStruct.pageBottom = (currentPage + 1) * layoutStruct.pageHeight - layoutStruct.pageBottomMargin; diff --git a/src/gui/vulkan/qvulkanwindow.cpp b/src/gui/vulkan/qvulkanwindow.cpp index 1114516fa8..caf53eb586 100644 --- a/src/gui/vulkan/qvulkanwindow.cpp +++ b/src/gui/vulkan/qvulkanwindow.cpp @@ -498,12 +498,12 @@ QVector<int> QVulkanWindow::supportedSampleCounts() VkSampleCountFlags depth = limits->framebufferDepthSampleCounts; VkSampleCountFlags stencil = limits->framebufferStencilSampleCounts; - for (size_t i = 0; i < sizeof(qvk_sampleCounts) / sizeof(qvk_sampleCounts[0]); ++i) { - if ((color & qvk_sampleCounts[i].mask) - && (depth & qvk_sampleCounts[i].mask) - && (stencil & qvk_sampleCounts[i].mask)) + for (const auto &qvk_sampleCount : qvk_sampleCounts) { + if ((color & qvk_sampleCount.mask) + && (depth & qvk_sampleCount.mask) + && (stencil & qvk_sampleCount.mask)) { - result.append(qvk_sampleCounts[i].count); + result.append(qvk_sampleCount.count); } } @@ -547,9 +547,9 @@ void QVulkanWindow::setSampleCount(int sampleCount) return; } - for (size_t i = 0; i < sizeof(qvk_sampleCounts) / sizeof(qvk_sampleCounts[0]); ++i) { - if (qvk_sampleCounts[i].count == sampleCount) { - d->sampleCount = qvk_sampleCounts[i].mask; + for (const auto &qvk_sampleCount : qvk_sampleCounts) { + if (qvk_sampleCount.count == sampleCount) { + d->sampleCount = qvk_sampleCount.mask; return; } } diff --git a/src/network/access/qhttp2protocolhandler.cpp b/src/network/access/qhttp2protocolhandler.cpp index ee6d493e85..efbeb17d39 100644 --- a/src/network/access/qhttp2protocolhandler.cpp +++ b/src/network/access/qhttp2protocolhandler.cpp @@ -1339,14 +1339,13 @@ void QHttp2ProtocolHandler::markAsReset(quint32 streamID) quint32 QHttp2ProtocolHandler::popStreamToResume() { quint32 streamID = connectionStreamID; - const int nQ = sizeof suspendedStreams / sizeof suspendedStreams[0]; using QNR = QHttpNetworkRequest; - const QNR::Priority ranks[nQ] = {QNR::HighPriority, - QNR::NormalPriority, - QNR::LowPriority}; + const QNR::Priority ranks[] = {QNR::HighPriority, + QNR::NormalPriority, + QNR::LowPriority}; - for (int i = 0; i < nQ; ++i) { - auto &queue = suspendedStreams[ranks[i]]; + for (const QNR::Priority rank : ranks) { + auto &queue = suspendedStreams[rank]; auto it = queue.begin(); for (; it != queue.end(); ++it) { if (!activeStreams.contains(*it)) @@ -1367,9 +1366,7 @@ quint32 QHttp2ProtocolHandler::popStreamToResume() void QHttp2ProtocolHandler::removeFromSuspended(quint32 streamID) { - const int nQ = sizeof suspendedStreams / sizeof suspendedStreams[0]; - for (int i = 0; i < nQ; ++i) { - auto &q = suspendedStreams[i]; + for (auto &q : suspendedStreams) { q.erase(std::remove(q.begin(), q.end(), streamID), q.end()); } } diff --git a/src/platformsupport/edid/qedidparser.cpp b/src/platformsupport/edid/qedidparser.cpp index 06c8852825..6bf1f1db96 100644 --- a/src/platformsupport/edid/qedidparser.cpp +++ b/src/platformsupport/edid/qedidparser.cpp @@ -42,8 +42,6 @@ #include "qedidparser_p.h" #include "qedidvendortable_p.h" -#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) - #define EDID_DESCRIPTOR_ALPHANUMERIC_STRING 0xfe #define EDID_DESCRIPTOR_PRODUCT_NAME 0xfc #define EDID_DESCRIPTOR_SERIAL_NUMBER 0xff @@ -139,9 +137,9 @@ bool QEdidParser::parse(const QByteArray &blob) manufacturer = m_vendorCache.value(pnpIdString); if (manufacturer.isEmpty()) { // Find the manufacturer from the vendor lookup table - for (size_t i = 0; i < ARRAY_LENGTH(q_edidVendorTable); i++) { - if (strncmp(q_edidVendorTable[i].id, pnpId, 3) == 0) { - manufacturer = QString::fromUtf8(q_edidVendorTable[i].name); + for (const auto &vendor : q_edidVendorTable) { + if (strncmp(vendor.id, pnpId, 3) == 0) { + manufacturer = QString::fromUtf8(vendor.name); break; } } diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm index ac4a8f35f8..201a82864f 100644 --- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm +++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm @@ -159,7 +159,7 @@ void QCoreTextFontDatabase::populateFamily(const QString &familyName) // A single family might match several different fonts with different styles eg. QCFType<CFArrayRef> matchingFonts = (CFArrayRef) CTFontDescriptorCreateMatchingFontDescriptors(nameOnlyDescriptor, 0); if (!matchingFonts) { - qWarning() << "QCoreTextFontDatabase: Found no matching fonts for family" << familyName; + qCWarning(lcQpaFonts) << "QCoreTextFontDatabase: Found no matching fonts for family" << familyName; return; } @@ -400,20 +400,20 @@ QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family) auto attributes = @{ id(kCTFontFamilyNameAttribute): family.toNSString() }; QCFType<CTFontDescriptorRef> fontDescriptor = CTFontDescriptorCreateWithAttributes(CFDictionaryRef(attributes)); if (!fontDescriptor) { - qWarning() << "Failed to create fallback font descriptor for" << family; + qCWarning(lcQpaFonts) << "Failed to create fallback font descriptor for" << family; return QStringList(); } QCFType<CTFontRef> font = CTFontCreateWithFontDescriptor(fontDescriptor, 12.0, 0); if (!font) { - qWarning() << "Failed to create fallback font for" << family; + qCWarning(lcQpaFonts) << "Failed to create fallback font for" << family; return QStringList(); } QCFType<CFArrayRef> cascadeList = CFArrayRef(CTFontCopyDefaultCascadeListForLanguages(font, (CFArrayRef)[NSUserDefaults.standardUserDefaults stringArrayForKey:@"AppleLanguages"])); if (!cascadeList) { - qWarning() << "Failed to create fallback cascade list for" << family; + qCWarning(lcQpaFonts) << "Failed to create fallback cascade list for" << family; return QStringList(); } diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 8ff2890ed2..f212b3e3f0 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -1272,14 +1272,11 @@ void QCocoaWindow::windowWillClose() bool QCocoaWindow::windowShouldClose() { qCDebug(lcQpaWindow) << "QCocoaWindow::windowShouldClose" << window(); - // This callback should technically only determine if the window - // should (be allowed to) close, but since our QPA API to determine - // that also involves actually closing the window we do both at the - // same time, instead of doing the latter in windowWillClose. - bool accepted = false; - QWindowSystemInterface::handleCloseEvent(window(), &accepted); - QWindowSystemInterface::flushWindowSystemEvents(); - return accepted; + // This callback should technically only determine if the window + // should (be allowed to) close, but since our QPA API to determine + // that also involves actually closing the window we do both at the + // same time, instead of doing the latter in windowWillClose. + return QWindowSystemInterface::handleCloseEvent<QWindowSystemInterface::SynchronousDelivery>(window()); } // ----------------------------- QPA forwarding ----------------------------- diff --git a/src/plugins/sqldrivers/ibase/qsql_ibase.cpp b/src/plugins/sqldrivers/ibase/qsql_ibase.cpp index b0b5375222..d0928fe6ab 100644 --- a/src/plugins/sqldrivers/ibase/qsql_ibase.cpp +++ b/src/plugins/sqldrivers/ibase/qsql_ibase.cpp @@ -40,6 +40,7 @@ #include "qsql_ibase_p.h" #include <qcoreapplication.h> #include <qdatetime.h> +#include <qdeadlinetimer.h> #include <qvariant.h> #include <qsqlerror.h> #include <qsqlfield.h> @@ -1570,10 +1571,9 @@ void QIBaseDriver::close() d->eventBuffers.clear(); #if defined(FB_API_VER) - // Workaround for Firebird crash - QTime timer; - timer.start(); - while (timer.elapsed() < 500) + // TODO check whether this workaround for Firebird crash is still needed + QDeadlineTimer timer(500); + while (!timer.hasExpired()) QCoreApplication::processEvents(); #endif } diff --git a/src/tools/bootstrap/bootstrap.pro b/src/tools/bootstrap/bootstrap.pro index f9ffd1bbea..09a1c68001 100644 --- a/src/tools/bootstrap/bootstrap.pro +++ b/src/tools/bootstrap/bootstrap.pro @@ -75,6 +75,7 @@ SOURCES += \ ../../corelib/serialization/qxmlutils.cpp \ ../../corelib/serialization/qxmlstream.cpp \ ../../corelib/text/qbytearray.cpp \ + ../../corelib/text/qbytearraylist.cpp \ ../../corelib/text/qbytearraymatcher.cpp \ ../../corelib/text/qlocale.cpp \ ../../corelib/text/qlocale_tools.cpp \ diff --git a/src/tools/moc/collectjson.cpp b/src/tools/moc/collectjson.cpp new file mode 100644 index 0000000000..4029bca5e9 --- /dev/null +++ b/src/tools/moc/collectjson.cpp @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** 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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qfile.h> +#include <qjsonarray.h> +#include <qjsondocument.h> +#include <qjsonobject.h> +#include <qhashfunctions.h> +#include <qstringlist.h> +#include <cstdlib> + +static bool readFromDevice(QIODevice *device, QJsonArray *allMetaObjects) +{ + const QByteArray contents = device->readAll(); + if (contents.isEmpty()) + return true; + + QJsonParseError error {}; + QJsonDocument metaObjects = QJsonDocument::fromJson(contents, &error); + if (error.error != QJsonParseError::NoError) { + fprintf(stderr, "%s at %d\n", error.errorString().toUtf8().constData(), error.offset); + return false; + } + + allMetaObjects->append(metaObjects.object()); + return true; +} + +int collectJson(const QStringList &jsonFiles, const QString &outputFile) +{ + qSetGlobalQHashSeed(0); + + QFile output; + if (outputFile.isEmpty()) { + if (!output.open(stdout, QIODevice::WriteOnly)) { + fprintf(stderr, "Error opening stdout for writing\n"); + return EXIT_FAILURE; + } + } else { + output.setFileName(outputFile); + if (!output.open(QIODevice::WriteOnly)) { + fprintf(stderr, "Error opening %s for writing\n", qPrintable(outputFile)); + return EXIT_FAILURE; + } + } + + QJsonArray allMetaObjects; + if (jsonFiles.isEmpty()) { + QFile f; + if (!f.open(stdin, QIODevice::ReadOnly)) { + fprintf(stderr, "Error opening stdin for reading\n"); + return EXIT_FAILURE; + } + + if (!readFromDevice(&f, &allMetaObjects)) { + fprintf(stderr, "Error parsing data from stdin\n"); + return EXIT_FAILURE; + } + } + + for (const QString &jsonFile: jsonFiles) { + QFile f(jsonFile); + if (!f.open(QIODevice::ReadOnly)) { + fprintf(stderr, "Error opening %s for reading\n", qPrintable(jsonFile)); + return EXIT_FAILURE; + } + + if (!readFromDevice(&f, &allMetaObjects)) { + fprintf(stderr, "Error parsing %s\n", qPrintable(jsonFile)); + return EXIT_FAILURE; + } + } + + QJsonDocument doc(allMetaObjects); + output.write(doc.toJson()); + + return EXIT_SUCCESS; +} diff --git a/src/tools/moc/collectjson.h b/src/tools/moc/collectjson.h new file mode 100644 index 0000000000..9d329c96ca --- /dev/null +++ b/src/tools/moc/collectjson.h @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the tools applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** 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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef COLLECTJSON_H +#define COLLECTJSON_H + +#include <qglobal.h> +#include <qstring.h> +#include <qstringlist.h> + +QT_BEGIN_NAMESPACE + +int collectJson(const QStringList &jsonFiles, const QString &outputFile); + +QT_END_NAMESPACE + +#endif // COLLECTOJSON_H diff --git a/src/tools/moc/main.cpp b/src/tools/moc/main.cpp index ba559b572f..4aa040a9bb 100644 --- a/src/tools/moc/main.cpp +++ b/src/tools/moc/main.cpp @@ -30,6 +30,7 @@ #include "preprocessor.h" #include "moc.h" #include "outputrevision.h" +#include "collectjson.h" #include <qfile.h> #include <qfileinfo.h> @@ -37,10 +38,12 @@ #include <stdio.h> #include <stdlib.h> #include <ctype.h> +#include <errno.h> #include <qcoreapplication.h> #include <qcommandlineoption.h> #include <qcommandlineparser.h> +#include <qscopedpointer.h> QT_BEGIN_NAMESPACE @@ -77,6 +80,10 @@ void error(const char *msg = "Invalid argument") fprintf(stderr, "moc: %s\n", msg); } +struct ScopedPointerFileCloser +{ + static inline void cleanup(FILE *handle) { if (handle) fclose(handle); } +}; static inline bool hasNext(const Symbols &symbols, int i) { return (i < symbols.size()); } @@ -293,10 +300,20 @@ int runMoc(int argc, char **argv) ignoreConflictsOption.setDescription(QStringLiteral("Ignore all options that conflict with compilers, like -pthread conflicting with moc's -p option.")); parser.addOption(ignoreConflictsOption); + QCommandLineOption jsonOption(QStringLiteral("output-json")); + jsonOption.setDescription(QStringLiteral("In addition to generating C++ code, create a machine-readable JSON file in a file that matches the output file and an extra .json extension.")); + parser.addOption(jsonOption); + + QCommandLineOption collectOption(QStringLiteral("collect-json")); + collectOption.setDescription(QStringLiteral("Instead of processing C++ code, collect previously generated JSON output into a single file.")); + parser.addOption(collectOption); + parser.addPositionalArgument(QStringLiteral("[header-file]"), QStringLiteral("Header file to read from, otherwise stdin.")); parser.addPositionalArgument(QStringLiteral("[@option-file]"), QStringLiteral("Read additional options from option-file.")); + parser.addPositionalArgument(QStringLiteral("[MOC generated json file]"), + QStringLiteral("MOC generated json output")); const QStringList arguments = argumentsFromCommandLineAndFile(app.arguments()); if (arguments.isEmpty()) @@ -305,6 +322,10 @@ int runMoc(int argc, char **argv) parser.process(arguments); const QStringList files = parser.positionalArguments(); + output = parser.value(outputOption); + if (parser.isSet(collectOption)) + return collectJson(files, output); + if (files.count() > 1) { error(qPrintable(QLatin1String("Too many input files specified: '") + files.join(QLatin1String("' '")) + QLatin1Char('\''))); parser.showHelp(1); @@ -313,7 +334,6 @@ int runMoc(int argc, char **argv) } const bool ignoreConflictingOptions = parser.isSet(ignoreConflictsOption); - output = parser.value(outputOption); pp.preprocessOnly = parser.isSet(preprocessOption); if (parser.isSet(noIncludeOption)) { moc.noInclude = true; @@ -485,6 +505,8 @@ int runMoc(int argc, char **argv) // 3. and output meta object code + QScopedPointer<FILE, ScopedPointerFileCloser> jsonOutput; + if (output.size()) { // output file specified #if defined(_MSC_VER) if (_wfopen_s(&out, reinterpret_cast<const wchar_t *>(output.utf16()), L"w") != 0) @@ -496,6 +518,21 @@ int runMoc(int argc, char **argv) fprintf(stderr, "moc: Cannot create %s\n", QFile::encodeName(output).constData()); return 1; } + + if (parser.isSet(jsonOption)) { + const QString jsonOutputFileName = output + QLatin1String(".json"); + FILE *f; +#if defined(_MSC_VER) + if (_wfopen_s(&f, reinterpret_cast<const wchar_t *>(jsonOutputFileName.utf16()), L"w") != 0) +#else + f = fopen(QFile::encodeName(jsonOutputFileName).constData(), "w"); + if (!f) +#endif + fprintf(stderr, "moc: Cannot create JSON output file %s. %s\n", + QFile::encodeName(jsonOutputFileName).constData(), + strerror(errno)); + jsonOutput.reset(f); + } } else { // use stdout out = stdout; } @@ -506,7 +543,7 @@ int runMoc(int argc, char **argv) if (moc.classList.isEmpty()) moc.note("No relevant classes found. No output generated."); else - moc.generate(out); + moc.generate(out, jsonOutput.data()); } if (output.size()) diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index 50946443be..8cc605fd8a 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -35,6 +35,7 @@ #include <QtCore/qfile.h> #include <QtCore/qfileinfo.h> #include <QtCore/qdir.h> +#include <QtCore/qjsondocument.h> // for normalizeTypeInternal #include <private/qmetaobject_moc_p.h> @@ -999,7 +1000,7 @@ static QByteArrayList requiredQtContainers(const QVector<ClassDef> &classes) return required; } -void Moc::generate(FILE *out) +void Moc::generate(FILE *out, FILE *jsonOutput) { QByteArray fn = filename; int i = filename.length()-1; @@ -1062,6 +1063,23 @@ void Moc::generate(FILE *out) fprintf(out, "QT_WARNING_POP\n"); fprintf(out, "QT_END_MOC_NAMESPACE\n"); + + if (jsonOutput) { + QJsonObject mocData; + mocData[QLatin1String("outputRevision")] = mocOutputRevision; + mocData[QLatin1String("inputFile")] = QLatin1String(fn.constData()); + + QJsonArray classesJsonFormatted; + + for (const ClassDef &cdef: qAsConst(classList)) + classesJsonFormatted.append(cdef.toJson()); + + if (!classesJsonFormatted.isEmpty()) + mocData[QLatin1String("classes")] = classesJsonFormatted; + + QJsonDocument jsonDoc(mocData); + fputs(jsonDoc.toJson().constData(), jsonOutput); + } } void Moc::parseSlots(ClassDef *def, FunctionDef::Access access) @@ -1784,6 +1802,186 @@ void Moc::checkProperties(ClassDef *cdef) } } +QJsonObject ClassDef::toJson() const +{ + QJsonObject cls; + cls[QLatin1String("className")] = QString::fromUtf8(classname.constData()); + cls[QLatin1String("qualifiedClassName")] = QString::fromUtf8(qualified.constData()); + + QJsonArray classInfos; + for (const auto &info: qAsConst(classInfoList)) { + QJsonObject infoJson; + infoJson[QLatin1String("name")] = QString::fromUtf8(info.name); + infoJson[QLatin1String("value")] = QString::fromUtf8(info.value); + classInfos.append(infoJson); + } + + if (classInfos.size()) + cls[QLatin1String("classInfos")] = classInfos; + + const auto appendFunctions = [&cls](const QString &type, const QVector<FunctionDef> &funcs) { + QJsonArray jsonFuncs; + + for (const FunctionDef &fdef: funcs) + jsonFuncs.append(fdef.toJson()); + + if (!jsonFuncs.isEmpty()) + cls[type] = jsonFuncs; + }; + + appendFunctions(QLatin1String("signals"), signalList); + appendFunctions(QLatin1String("slots"), slotList); + appendFunctions(QLatin1String("constructors"), constructorList); + appendFunctions(QLatin1String("methods"), methodList); + + QJsonArray props; + + for (const PropertyDef &propDef: qAsConst(propertyList)) + props.append(propDef.toJson()); + + if (!props.isEmpty()) + cls[QLatin1String("properties")] = props; + + if (hasQGadget) + cls[QLatin1String("gadget")] = true; + + QJsonArray superClasses; + + for (const auto &super: qAsConst(superclassList)) { + const auto name = super.first; + const auto access = super.second; + QJsonObject superCls; + superCls[QLatin1String("name")] = QString::fromUtf8(name); + FunctionDef::accessToJson(&superCls, access); + superClasses.append(superCls); + } + + if (!superClasses.isEmpty()) + cls[QLatin1String("superClasses")] = superClasses; + + QJsonArray enums; + for (const EnumDef &enumDef: qAsConst(enumList)) + enums.append(enumDef.toJson(*this)); + if (!enums.isEmpty()) + cls[QLatin1String("enums")] = enums; + + QJsonArray ifaces; + for (const QVector<Interface> &ifaceList: interfaceList) { + QJsonArray jsonList; + for (const Interface &iface: ifaceList) { + QJsonObject ifaceJson; + ifaceJson[QLatin1String("id")] = QString::fromUtf8(iface.interfaceId); + ifaceJson[QLatin1String("className")] = QString::fromUtf8(iface.className); + jsonList.append(ifaceJson); + } + ifaces.append(jsonList); + } + if (!ifaces.isEmpty()) + cls[QLatin1String("interfaces")] = ifaces; + + return cls; +} + +QJsonObject FunctionDef::toJson() const +{ + QJsonObject fdef; + fdef[QLatin1String("name")] = QString::fromUtf8(name); + if (!tag.isEmpty()) + fdef[QLatin1String("tag")] = QString::fromUtf8(tag); + fdef[QLatin1String("returnType")] = QString::fromUtf8(normalizedType); + QJsonArray args; + for (const ArgumentDef &arg: arguments) + args.append(arg.toJson()); + + if (!args.isEmpty()) + fdef[QLatin1String("arguments")] = args; + + accessToJson(&fdef, access); + + if (revision > 0) + fdef[QLatin1String("revision")] = revision; + + return fdef; +} + +void FunctionDef::accessToJson(QJsonObject *obj, FunctionDef::Access acs) +{ + switch (acs) { + case Private: (*obj)[QLatin1String("access")] = QLatin1String("private"); break; + case Public: (*obj)[QLatin1String("access")] = QLatin1String("public"); break; + case Protected: (*obj)[QLatin1String("access")] = QLatin1String("protected"); break; + } +} + +QJsonObject ArgumentDef::toJson() const +{ + QJsonObject arg; + arg[QLatin1String("type")] = QString::fromUtf8(normalizedType); + if (!name.isEmpty()) + arg[QLatin1String("name")] = QString::fromUtf8(name); + return arg; +} + +QJsonObject PropertyDef::toJson() const +{ + QJsonObject prop; + prop[QLatin1String("name")] = QString::fromUtf8(name); + prop[QLatin1String("type")] = QString::fromUtf8(type); + + const auto jsonify = [&prop](const char *str, const QByteArray &member) { + if (!member.isEmpty()) + prop[QLatin1String(str)] = QString::fromUtf8(member); + }; + + jsonify("member", member); + jsonify("read", read); + jsonify("write", write); + jsonify("reset", reset); + jsonify("notify", notify); + jsonify("privateClass", inPrivateClass); + + const auto jsonifyBoolOrString = [&prop](const char *str, const QByteArray &boolOrString) { + QJsonValue value; + if (boolOrString == "true") + value = true; + else if (boolOrString == "false") + value = false; + else + value = QString::fromUtf8(boolOrString); // function name to query at run-time + prop[QLatin1String(str)] = value; + }; + + jsonifyBoolOrString("designable", designable); + jsonifyBoolOrString("scriptable", scriptable); + jsonifyBoolOrString("stored", stored); + jsonifyBoolOrString("user", user); + + prop[QLatin1String("constant")] = constant; + prop[QLatin1String("final")] = final; + + if (revision > 0) + prop[QLatin1String("revision")] = revision; + + return prop; +} + +QJsonObject EnumDef::toJson(const ClassDef &cdef) const +{ + QJsonObject def; + def[QLatin1String("name")] = QString::fromUtf8(name); + if (!enumName.isEmpty()) + def[QLatin1String("alias")] = QString::fromUtf8(enumName); + def[QLatin1String("isFlag")] = cdef.enumDeclarations.value(name); + def[QLatin1String("isClass")] = isEnumClass; + + QJsonArray valueArr; + for (const QByteArray &value: values) + valueArr.append(QString::fromUtf8(value)); + if (!valueArr.isEmpty()) + def[QLatin1String("values")] = valueArr; + + return def; +} QT_END_NAMESPACE diff --git a/src/tools/moc/moc.h b/src/tools/moc/moc.h index bb1c9501fe..687ea2552f 100644 --- a/src/tools/moc/moc.h +++ b/src/tools/moc/moc.h @@ -61,6 +61,7 @@ struct Type }; Q_DECLARE_TYPEINFO(Type, Q_MOVABLE_TYPE); +struct ClassDef; struct EnumDef { QByteArray name; @@ -68,6 +69,7 @@ struct EnumDef QVector<QByteArray> values; bool isEnumClass; // c++11 enum class EnumDef() : isEnumClass(false) {} + QJsonObject toJson(const ClassDef &cdef) const; }; Q_DECLARE_TYPEINFO(EnumDef, Q_MOVABLE_TYPE); @@ -78,6 +80,8 @@ struct ArgumentDef QByteArray rightType, normalizedType, name; QByteArray typeNameForCast; // type name to be used in cast from void * in metacall bool isDefault; + + QJsonObject toJson() const; }; Q_DECLARE_TYPEINFO(ArgumentDef, Q_MOVABLE_TYPE); @@ -111,6 +115,9 @@ struct FunctionDef bool isConstructor = false; bool isDestructor = false; bool isAbstract = false; + + QJsonObject toJson() const; + static void accessToJson(QJsonObject *obj, Access acs); }; Q_DECLARE_TYPEINFO(FunctionDef, Q_MOVABLE_TYPE); @@ -130,6 +137,8 @@ struct PropertyDef int revision = 0; bool constant = false; bool final = false; + + QJsonObject toJson() const; }; Q_DECLARE_TYPEINFO(PropertyDef, Q_MOVABLE_TYPE); @@ -183,6 +192,7 @@ struct ClassDef : BaseDef { bool hasQObject = false; bool hasQGadget = false; + QJsonObject toJson() const; }; Q_DECLARE_TYPEINFO(ClassDef, Q_MOVABLE_TYPE); Q_DECLARE_TYPEINFO(ClassDef::Interface, Q_MOVABLE_TYPE); @@ -215,7 +225,7 @@ public: QMap<QString, QJsonArray> metaArgs; void parse(); - void generate(FILE *out); + void generate(FILE *out, FILE *jsonOutput); bool parseClassHead(ClassDef *def); inline bool inClass(const ClassDef *def) const { diff --git a/src/tools/moc/moc.pri b/src/tools/moc/moc.pri index 90839a445b..278d5607cd 100644 --- a/src/tools/moc/moc.pri +++ b/src/tools/moc/moc.pri @@ -10,9 +10,12 @@ HEADERS = $$PWD/moc.h \ $$PWD/utils.h \ $$PWD/generator.h \ $$PWD/outputrevision.h \ - $$PWD/cbordevice.h + $$PWD/cbordevice.h \ + $$PWD/collectjson.h + SOURCES = $$PWD/moc.cpp \ $$PWD/preprocessor.cpp \ $$PWD/generator.cpp \ $$PWD/parser.cpp \ - $$PWD/token.cpp + $$PWD/token.cpp \ + $$PWD/collectjson.cpp diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index 089f398e71..c2afed775c 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -1776,8 +1776,8 @@ void QAbstractItemView::mousePressEvent(QMouseEvent *event) QItemSelectionModel::SelectionFlags command = selectionCommand(index, event); d->noSelectionOnMousePress = command == QItemSelectionModel::NoUpdate || !index.isValid(); QPoint offset = d->offset(); + d->pressedPosition = pos + offset; if ((command & QItemSelectionModel::Current) == 0) { - d->pressedPosition = pos + offset; d->currentSelectionStartIndex = index; } else if (!d->currentSelectionStartIndex.isValid()) diff --git a/src/widgets/itemviews/qtreewidget.cpp b/src/widgets/itemviews/qtreewidget.cpp index d285ad6d28..a2d6e7798d 100644 --- a/src/widgets/itemviews/qtreewidget.cpp +++ b/src/widgets/itemviews/qtreewidget.cpp @@ -748,11 +748,14 @@ QMimeData *QTreeModel::internalMimeData() const QMimeData *QTreeModel::mimeData(const QModelIndexList &indexes) const { - QList<QTreeWidgetItem*> items; - for (const auto &index : indexes) { - if (index.column() == 0) // only one item per row - items << item(index); - } + QList<QTreeWidgetItem *> items; + std::transform(indexes.begin(), indexes.end(), std::back_inserter(items), + [this](const QModelIndex &idx) -> QTreeWidgetItem * { return item(idx); }); + + // Ensure we only have one item as an item may have more than + // one index selected if there is more than one column + std::sort(items.begin(), items.end()); + items.erase(std::unique(items.begin(), items.end()), items.end()); // cachedIndexes is a little hack to avoid copying from QModelIndexList to // QList<QTreeWidgetItem*> and back again in the view diff --git a/src/widgets/kernel/qgesturemanager.cpp b/src/widgets/kernel/qgesturemanager.cpp index d9d071a31a..d0c6b882b5 100644 --- a/src/widgets/kernel/qgesturemanager.cpp +++ b/src/widgets/kernel/qgesturemanager.cpp @@ -133,6 +133,7 @@ Qt::GestureType QGestureManager::registerGestureRecognizer(QGestureRecognizer *r void QGestureManager::unregisterGestureRecognizer(Qt::GestureType type) { QList<QGestureRecognizer *> list = m_recognizers.values(type); + m_recognizers.remove(type); foreach (QGesture *g, m_gestureToRecognizer.keys()) { QGestureRecognizer *recognizer = m_gestureToRecognizer.value(g); if (list.contains(recognizer)) { |