summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/QtNative.java3
-rw-r--r--src/corelib/codecs/qlatincodec.cpp18
-rw-r--r--src/corelib/codecs/qtextcodec.cpp11
-rw-r--r--src/corelib/codecs/qutfcodec.cpp6
-rw-r--r--src/corelib/configure.json2
-rw-r--r--src/corelib/corelib.pro1
-rw-r--r--src/corelib/global/qglobal.h30
-rw-r--r--src/corelib/global/qsystemdetection.h9
-rw-r--r--src/corelib/global/qt_pch.h4
-rw-r--r--src/corelib/io/qdir.cpp37
-rw-r--r--src/corelib/io/qdir_p.h6
-rw-r--r--src/corelib/io/qdiriterator.cpp6
-rw-r--r--src/corelib/io/qfile.cpp25
-rw-r--r--src/corelib/io/qfiledevice.cpp14
-rw-r--r--src/corelib/io/qfiledevice_p.h4
-rw-r--r--src/corelib/io/qfileinfo.cpp6
-rw-r--r--src/corelib/io/qfileinfo_p.h8
-rw-r--r--src/corelib/io/qfilesystemengine_unix.cpp4
-rw-r--r--src/corelib/io/qfilesystemiterator_unix.cpp47
-rw-r--r--src/corelib/io/qfilesystemwatcher_inotify.cpp27
-rw-r--r--src/corelib/io/qfsfileengine.cpp45
-rw-r--r--src/corelib/io/qfsfileengine_p.h10
-rw-r--r--src/corelib/io/qipaddress.cpp2
-rw-r--r--src/corelib/io/qprocess.cpp7
-rw-r--r--src/corelib/io/qprocess_p.h50
-rw-r--r--src/corelib/io/qprocess_unix.cpp2
-rw-r--r--src/corelib/io/qresource.cpp70
-rw-r--r--src/corelib/io/qresource.h5
-rw-r--r--src/corelib/io/qsavefile.cpp37
-rw-r--r--src/corelib/io/qstandardpaths.cpp2
-rw-r--r--src/corelib/io/qstandardpaths_unix.cpp75
-rw-r--r--src/corelib/io/qstorageinfo_unix.cpp14
-rw-r--r--src/corelib/io/qtemporaryfile.cpp16
-rw-r--r--src/corelib/io/qtldurl.cpp6
-rw-r--r--src/corelib/io/qurl.cpp2
-rw-r--r--src/corelib/io/qurlidna.cpp5
-rw-r--r--src/corelib/io/qurlquery.cpp10
-rw-r--r--src/corelib/itemmodels/qabstractitemmodel.cpp23
-rw-r--r--src/corelib/itemmodels/qsortfilterproxymodel.cpp64
-rw-r--r--src/corelib/kernel/qcore_mac_objc.mm5
-rw-r--r--src/corelib/kernel/qcore_mac_p.h10
-rw-r--r--src/corelib/kernel/qeventdispatcher_winrt_p.h2
-rw-r--r--src/corelib/kernel/qmetaobject.cpp2
-rw-r--r--src/corelib/kernel/qmetaobjectbuilder.cpp12
-rw-r--r--src/corelib/kernel/qmetatype.h2
-rw-r--r--src/corelib/kernel/qobject.cpp28
-rw-r--r--src/corelib/kernel/qobject_p.h9
-rw-r--r--src/corelib/kernel/qobjectdefs.h37
-rw-r--r--src/corelib/kernel/qsignalmapper.cpp8
-rw-r--r--src/corelib/kernel/qsignalmapper.h6
-rw-r--r--src/corelib/kernel/qtranslator.cpp3
-rw-r--r--src/corelib/kernel/qvariant.h2
-rw-r--r--src/corelib/plugin/qpluginloader.cpp2
-rw-r--r--src/corelib/serialization/qcborarray.cpp6
-rw-r--r--src/corelib/serialization/qcborstream.cpp10
-rw-r--r--src/corelib/serialization/qjson.cpp6
-rw-r--r--src/corelib/serialization/qjson_p.h97
-rw-r--r--src/corelib/serialization/qjsonarray.cpp2
-rw-r--r--src/corelib/serialization/qjsoncbor.cpp2
-rw-r--r--src/corelib/serialization/qjsondocument.cpp11
-rw-r--r--src/corelib/serialization/qjsondocument.h3
-rw-r--r--src/corelib/serialization/qjsonobject.cpp307
-rw-r--r--src/corelib/serialization/qjsonobject.h41
-rw-r--r--src/corelib/serialization/qjsonvalue.cpp11
-rw-r--r--src/corelib/serialization/qjsonvalue.h3
-rw-r--r--src/corelib/serialization/qtextstream.cpp2
-rw-r--r--src/corelib/serialization/qxmlstream.cpp6
-rw-r--r--src/corelib/text/UNICODE_LICENSE.txt (renamed from src/corelib/tools/UNICODE_LICENSE.txt)0
-rw-r--r--src/corelib/text/qbytearray.cpp (renamed from src/corelib/tools/qbytearray.cpp)9
-rw-r--r--src/corelib/text/qbytearray.h (renamed from src/corelib/tools/qbytearray.h)0
-rw-r--r--src/corelib/text/qbytearray_p.h (renamed from src/corelib/tools/qbytearray_p.h)2
-rw-r--r--src/corelib/text/qbytearraylist.cpp (renamed from src/corelib/tools/qbytearraylist.cpp)0
-rw-r--r--src/corelib/text/qbytearraylist.h (renamed from src/corelib/tools/qbytearraylist.h)0
-rw-r--r--src/corelib/text/qbytearraymatcher.cpp (renamed from src/corelib/tools/qbytearraymatcher.cpp)0
-rw-r--r--src/corelib/text/qbytearraymatcher.h (renamed from src/corelib/tools/qbytearraymatcher.h)0
-rw-r--r--src/corelib/text/qbytedata_p.h (renamed from src/corelib/tools/qbytedata_p.h)0
-rw-r--r--src/corelib/text/qchar.cpp (renamed from src/corelib/tools/qchar.cpp)18
-rw-r--r--src/corelib/text/qchar.h (renamed from src/corelib/tools/qchar.h)10
-rw-r--r--src/corelib/text/qcollator.cpp (renamed from src/corelib/tools/qcollator.cpp)0
-rw-r--r--src/corelib/text/qcollator.h (renamed from src/corelib/tools/qcollator.h)0
-rw-r--r--src/corelib/text/qcollator_icu.cpp (renamed from src/corelib/tools/qcollator_icu.cpp)0
-rw-r--r--src/corelib/text/qcollator_macx.cpp (renamed from src/corelib/tools/qcollator_macx.cpp)0
-rw-r--r--src/corelib/text/qcollator_p.h (renamed from src/corelib/tools/qcollator_p.h)0
-rw-r--r--src/corelib/text/qcollator_posix.cpp (renamed from src/corelib/tools/qcollator_posix.cpp)0
-rw-r--r--src/corelib/text/qcollator_win.cpp (renamed from src/corelib/tools/qcollator_win.cpp)0
-rw-r--r--src/corelib/text/qdoublescanprint_p.h (renamed from src/corelib/tools/qdoublescanprint_p.h)0
-rw-r--r--src/corelib/text/qharfbuzz.cpp (renamed from src/corelib/tools/qharfbuzz.cpp)0
-rw-r--r--src/corelib/text/qharfbuzz_p.h (renamed from src/corelib/tools/qharfbuzz_p.h)0
-rw-r--r--src/corelib/text/qlocale.cpp (renamed from src/corelib/tools/qlocale.cpp)198
-rw-r--r--src/corelib/text/qlocale.h (renamed from src/corelib/tools/qlocale.h)0
-rw-r--r--src/corelib/text/qlocale.qdoc (renamed from src/corelib/tools/qlocale.qdoc)0
-rw-r--r--src/corelib/text/qlocale_data_p.h (renamed from src/corelib/tools/qlocale_data_p.h)0
-rw-r--r--src/corelib/text/qlocale_icu.cpp (renamed from src/corelib/tools/qlocale_icu.cpp)0
-rw-r--r--src/corelib/text/qlocale_mac.mm (renamed from src/corelib/tools/qlocale_mac.mm)0
-rw-r--r--src/corelib/text/qlocale_p.h (renamed from src/corelib/tools/qlocale_p.h)8
-rw-r--r--src/corelib/text/qlocale_tools.cpp (renamed from src/corelib/tools/qlocale_tools.cpp)0
-rw-r--r--src/corelib/text/qlocale_tools_p.h (renamed from src/corelib/tools/qlocale_tools_p.h)0
-rw-r--r--src/corelib/text/qlocale_unix.cpp (renamed from src/corelib/tools/qlocale_unix.cpp)0
-rw-r--r--src/corelib/text/qlocale_win.cpp (renamed from src/corelib/tools/qlocale_win.cpp)0
-rw-r--r--src/corelib/text/qregexp.cpp (renamed from src/corelib/tools/qregexp.cpp)2
-rw-r--r--src/corelib/text/qregexp.h (renamed from src/corelib/tools/qregexp.h)0
-rw-r--r--src/corelib/text/qregularexpression.cpp (renamed from src/corelib/tools/qregularexpression.cpp)0
-rw-r--r--src/corelib/text/qregularexpression.h (renamed from src/corelib/tools/qregularexpression.h)0
-rw-r--r--src/corelib/text/qstring.cpp (renamed from src/corelib/tools/qstring.cpp)15
-rw-r--r--src/corelib/text/qstring.h (renamed from src/corelib/tools/qstring.h)61
-rw-r--r--src/corelib/text/qstring_compat.cpp (renamed from src/corelib/tools/qstring_compat.cpp)0
-rw-r--r--src/corelib/text/qstring_mips_dsp_asm.S (renamed from src/corelib/tools/qstring_mips_dsp_asm.S)0
-rw-r--r--src/corelib/text/qstringalgorithms.h (renamed from src/corelib/tools/qstringalgorithms.h)11
-rw-r--r--src/corelib/text/qstringalgorithms_p.h (renamed from src/corelib/tools/qstringalgorithms_p.h)0
-rw-r--r--src/corelib/text/qstringbuilder.cpp (renamed from src/corelib/tools/qstringbuilder.cpp)0
-rw-r--r--src/corelib/text/qstringbuilder.h (renamed from src/corelib/tools/qstringbuilder.h)0
-rw-r--r--src/corelib/text/qstringiterator.qdoc (renamed from src/corelib/tools/qstringiterator.qdoc)0
-rw-r--r--src/corelib/text/qstringiterator_p.h (renamed from src/corelib/tools/qstringiterator_p.h)0
-rw-r--r--src/corelib/text/qstringlist.cpp (renamed from src/corelib/tools/qstringlist.cpp)0
-rw-r--r--src/corelib/text/qstringlist.h (renamed from src/corelib/tools/qstringlist.h)0
-rw-r--r--src/corelib/text/qstringliteral.h (renamed from src/corelib/tools/qstringliteral.h)0
-rw-r--r--src/corelib/text/qstringmatcher.cpp (renamed from src/corelib/tools/qstringmatcher.cpp)0
-rw-r--r--src/corelib/text/qstringmatcher.h (renamed from src/corelib/tools/qstringmatcher.h)0
-rw-r--r--src/corelib/text/qstringview.cpp (renamed from src/corelib/tools/qstringview.cpp)27
-rw-r--r--src/corelib/text/qstringview.h (renamed from src/corelib/tools/qstringview.h)8
-rw-r--r--src/corelib/text/qt_attribution.json (renamed from src/corelib/tools/qt_attribution.json)0
-rw-r--r--src/corelib/text/qtextboundaryfinder.cpp (renamed from src/corelib/tools/qtextboundaryfinder.cpp)0
-rw-r--r--src/corelib/text/qtextboundaryfinder.h (renamed from src/corelib/tools/qtextboundaryfinder.h)0
-rw-r--r--src/corelib/text/qunicodetables.cpp (renamed from src/corelib/tools/qunicodetables.cpp)0
-rw-r--r--src/corelib/text/qunicodetables_p.h (renamed from src/corelib/tools/qunicodetables_p.h)0
-rw-r--r--src/corelib/text/qunicodetools.cpp (renamed from src/corelib/tools/qunicodetools.cpp)0
-rw-r--r--src/corelib/text/qunicodetools_p.h (renamed from src/corelib/tools/qunicodetools_p.h)0
-rw-r--r--src/corelib/text/qvsnprintf.cpp (renamed from src/corelib/tools/qvsnprintf.cpp)0
-rw-r--r--src/corelib/text/text.pri100
-rw-r--r--src/corelib/thread/qmutexpool.cpp151
-rw-r--r--src/corelib/thread/qorderedmutexlocker_p.h2
-rw-r--r--src/corelib/thread/qthread.cpp8
-rw-r--r--src/corelib/thread/thread.pri2
-rw-r--r--src/corelib/time/qdatetime.cpp49
-rw-r--r--src/corelib/tools/qalgorithms.qdoc4
-rw-r--r--src/corelib/tools/qarraydatapointer.h13
-rw-r--r--src/corelib/tools/qcontainerfwd.h2
-rw-r--r--src/corelib/tools/qeasingcurve.cpp4
-rw-r--r--src/corelib/tools/qhash.h38
-rw-r--r--src/corelib/tools/qlinkedlist.cpp4
-rw-r--r--src/corelib/tools/qlinkedlist.h8
-rw-r--r--src/corelib/tools/qshareddata.h16
-rw-r--r--src/corelib/tools/qtimeline.cpp35
-rw-r--r--src/corelib/tools/qvarlengtharray.h4
-rw-r--r--src/corelib/tools/qvector.h2
-rw-r--r--src/corelib/tools/tools.pri88
-rw-r--r--src/dbus/qdbuserror.h3
-rw-r--r--src/gui/configure.json1
-rw-r--r--src/gui/image/qimage.cpp4
-rw-r--r--src/gui/image/qimagereader.cpp29
-rw-r--r--src/gui/image/qmovie.cpp13
-rw-r--r--src/gui/image/qpixmapcache.cpp33
-rw-r--r--src/gui/image/qpnghandler.cpp56
-rw-r--r--src/gui/kernel/qevent.cpp218
-rw-r--r--src/gui/kernel/qevent.h30
-rw-r--r--src/gui/kernel/qguiapplication.cpp5
-rw-r--r--src/gui/kernel/qopenglcontext.cpp2
-rw-r--r--src/gui/kernel/qstylehints.cpp44
-rw-r--r--src/gui/kernel/qstylehints.h4
-rw-r--r--src/gui/opengl/qopenglprogrambinarycache.cpp37
-rw-r--r--src/gui/opengl/qopenglprogrambinarycache_p.h6
-rw-r--r--src/gui/opengl/qopenglshaderprogram.cpp8
-rw-r--r--src/gui/opengl/qopengltextureglyphcache.cpp4
-rw-r--r--src/gui/opengl/qopengltextureglyphcache_p.h2
-rw-r--r--src/gui/painting/qbackingstore.cpp2
-rw-r--r--src/gui/painting/qcolorspace.cpp279
-rw-r--r--src/gui/painting/qcolorspace.h30
-rw-r--r--src/gui/painting/qcolorspace_p.h17
-rw-r--r--src/gui/painting/qcolortransform.cpp27
-rw-r--r--src/gui/painting/qcolortransform.h29
-rw-r--r--src/gui/painting/qcolortransform_p.h4
-rw-r--r--src/gui/painting/qdrawhelper.cpp27
-rw-r--r--src/gui/painting/qicc.cpp245
-rw-r--r--src/gui/painting/qpagedpaintdevice.cpp3
-rw-r--r--src/gui/painting/qpagedpaintdevice.h1
-rw-r--r--src/gui/painting/qpaintengine_raster.cpp6
-rw-r--r--src/gui/painting/qpainterpath.cpp9
-rw-r--r--src/gui/painting/qpainterpath_p.h2
-rw-r--r--src/gui/painting/qpdf.cpp12
-rw-r--r--src/gui/painting/qpdf_p.h1
-rw-r--r--src/gui/painting/qpdfwriter.cpp8
-rw-r--r--src/gui/painting/qtextureglyphcache.cpp2
-rw-r--r--src/gui/painting/qtextureglyphcache_p.h8
-rw-r--r--src/gui/rhi/qrhi.cpp71
-rw-r--r--src/gui/rhi/qrhi_p_p.h6
-rw-r--r--src/gui/rhi/qrhid3d11.cpp4
-rw-r--r--src/gui/rhi/qrhigles2.cpp919
-rw-r--r--src/gui/rhi/qrhigles2_p_p.h148
-rw-r--r--src/gui/rhi/qrhimetal.mm15
-rw-r--r--src/gui/rhi/qrhivulkan.cpp65
-rw-r--r--src/gui/text/qdistancefield.cpp3
-rw-r--r--src/gui/text/qdistancefield_p.h1
-rw-r--r--src/gui/text/qfontengine.cpp12
-rw-r--r--src/gui/text/qfontengine_p.h4
-rw-r--r--src/gui/text/qfontengineglyphcache_p.h7
-rw-r--r--src/gui/text/qtextobject.cpp2
-rw-r--r--src/gui/util/qdesktopservices.cpp2
-rw-r--r--src/network/access/qhttp2protocolhandler.cpp25
-rw-r--r--src/network/access/qhttpthreaddelegate.cpp36
-rw-r--r--src/network/access/qnetworkaccessmanager.cpp17
-rw-r--r--src/network/access/qnetworkreplywasmimpl.cpp6
-rw-r--r--src/network/access/qnetworkrequest.cpp15
-rw-r--r--src/network/access/qnetworkrequest.h3
-rw-r--r--src/network/access/qspdyprotocolhandler.cpp15
-rw-r--r--src/network/access/qspdyprotocolhandler_p.h2
-rw-r--r--src/network/bearer/qsharednetworksession.cpp14
-rw-r--r--src/network/configure.json23
-rw-r--r--src/network/kernel/kernel.pri2
-rw-r--r--src/network/kernel/qhostinfo.cpp163
-rw-r--r--src/network/kernel/qhostinfo.h6
-rw-r--r--src/network/kernel/qhostinfo_p.h50
-rw-r--r--src/network/kernel/qnetconmonitor_darwin.mm2
-rw-r--r--src/network/kernel/qnetconmonitor_p.h6
-rw-r--r--src/network/kernel/qnetconmonitor_stub.cpp2
-rw-r--r--src/network/kernel/qnetconmonitor_win.cpp710
-rw-r--r--src/network/socket/qhttpsocketengine.cpp2
-rw-r--r--src/network/socket/qnativesocketengine_unix.cpp3
-rw-r--r--src/network/socket/qnativesocketengine_win.cpp115
-rw-r--r--src/network/ssl/qsslcertificate_openssl.cpp13
-rw-r--r--src/network/ssl/qsslsocket_mac.cpp2
-rw-r--r--src/network/ssl/qsslsocket_openssl11.cpp2
-rw-r--r--src/network/ssl/qsslsocket_openssl_symbols.cpp128
-rw-r--r--src/network/ssl/qsslsocket_schannel.cpp2
-rw-r--r--src/platformsupport/eglconvenience/qeglstreamconvenience_p.h11
-rw-r--r--src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp72
-rw-r--r--src/platformsupport/fontdatabases/freetype/qfontengine_ft.cpp4
-rw-r--r--src/platformsupport/fontdatabases/freetype/qfontengine_ft_p.h2
-rw-r--r--src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm10
-rw-r--r--src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h4
-rw-r--r--src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp42
-rw-r--r--src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite_p.h4
-rw-r--r--src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp2
-rw-r--r--src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp2
-rw-r--r--src/platformsupport/input/libinput/qlibinputhandler.cpp2
-rw-r--r--src/platformsupport/kmsconvenience/qkmsdevice.cpp19
-rw-r--r--src/plugins/imageformats/gif/qgifhandler.cpp2
-rw-r--r--src/plugins/imageformats/gif/qgifhandler_p.h2
-rw-r--r--src/plugins/imageformats/ico/qicohandler.cpp3
-rw-r--r--src/plugins/imageformats/ico/qicohandler.h2
-rw-r--r--src/plugins/imageformats/jpeg/qjpeghandler.cpp2
-rw-r--r--src/plugins/imageformats/jpeg/qjpeghandler_p.h2
-rw-r--r--src/plugins/platforms/cocoa/cocoa.pro2
-rw-r--r--src/plugins/platforms/cocoa/qcocoabackingstore.h11
-rw-r--r--src/plugins/platforms/cocoa/qcocoabackingstore.mm30
-rw-r--r--src/plugins/platforms/cocoa/qcocoaglcontext.h2
-rw-r--r--src/plugins/platforms/cocoa/qcocoaglcontext.mm83
-rw-r--r--src/plugins/platforms/cocoa/qcocoaintegration.mm23
-rw-r--r--src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm18
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.mm39
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindowmanager.h (renamed from src/corelib/thread/qmutexpool_p.h)51
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindowmanager.mm108
-rw-r--r--src/plugins/platforms/cocoa/qprintengine_mac.mm8
-rw-r--r--src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.cpp50
-rw-r--r--src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.h2
-rw-r--r--src/plugins/platforms/wasm/qwasmcompositor.cpp4
-rw-r--r--src/plugins/platforms/wasm/qwasmeventtranslator.cpp90
-rw-r--r--src/plugins/platforms/wasm/qwasmeventtranslator.h36
-rw-r--r--src/plugins/platforms/wasm/qwasmfontdatabase.cpp11
-rw-r--r--src/plugins/platforms/wasm/wasm.pro2
-rw-r--r--src/plugins/platforms/windows/qwindowsinputcontext.cpp9
-rw-r--r--src/plugins/platforms/windows/qwindowskeymapper.cpp18
-rw-r--r--src/plugins/platforms/windows/qwindowspointerhandler.cpp13
-rw-r--r--src/plugins/platforms/windows/qwindowspointerhandler.h1
-rw-r--r--src/plugins/platforms/windows/qwindowsscreen.cpp31
-rw-r--r--src/plugins/platforms/winrt/qwinrtfileengine.cpp38
-rw-r--r--src/plugins/platforms/winrt/qwinrtfileengine.h1
-rw-r--r--src/plugins/platforms/winrt/qwinrtscreen.cpp6
-rw-r--r--src/plugins/platforms/winrt/qwinrtscreen.h1
-rw-r--r--src/plugins/platforms/xcb/qxcbconnection.cpp2
-rw-r--r--src/plugins/platforms/xcb/qxcbeventqueue.cpp9
-rw-r--r--src/plugins/platforms/xcb/qxcbwindow.cpp2
-rw-r--r--src/plugins/sqldrivers/psql/qsql_psql.cpp4
-rw-r--r--src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp2
-rw-r--r--src/plugins/sqldrivers/tds/qsql_tds.cpp2
-rw-r--r--src/plugins/styles/mac/qmacstyle_mac.mm71
-rw-r--r--src/printsupport/kernel/qcups.cpp2
-rw-r--r--src/src.pro10
-rw-r--r--src/testlib/qabstracttestlogger.cpp2
-rw-r--r--src/testlib/qabstracttestlogger_p.h5
-rw-r--r--src/testlib/qbenchmark.cpp27
-rw-r--r--src/testlib/qbenchmark_p.h46
-rw-r--r--src/testlib/qbenchmarkevent.cpp9
-rw-r--r--src/testlib/qbenchmarkevent_p.h2
-rw-r--r--src/testlib/qbenchmarkmeasurement_p.h4
-rw-r--r--src/testlib/qbenchmarkperfevents.cpp7
-rw-r--r--src/testlib/qbenchmarkperfevents_p.h22
-rw-r--r--src/testlib/qbenchmarkvalgrind.cpp4
-rw-r--r--src/testlib/qcsvbenchmarklogger.cpp4
-rw-r--r--src/testlib/qplaintestlogger.cpp4
-rw-r--r--src/testlib/qsignaldumper.cpp4
-rw-r--r--src/testlib/qtaptestlogger.cpp4
-rw-r--r--src/testlib/qteamcitylogger.cpp8
-rw-r--r--src/testlib/qtest.h17
-rw-r--r--src/testlib/qtest_gui.h16
-rw-r--r--src/testlib/qtestblacklist.cpp9
-rw-r--r--src/testlib/qtestcase.cpp138
-rw-r--r--src/testlib/qtestcase.h34
-rw-r--r--src/testlib/qtestcoreelement_p.h4
-rw-r--r--src/testlib/qtestdata.cpp10
-rw-r--r--src/testlib/qtestelement.cpp2
-rw-r--r--src/testlib/qtestelement_p.h4
-rw-r--r--src/testlib/qtestelementattribute.cpp10
-rw-r--r--src/testlib/qtestelementattribute_p.h4
-rw-r--r--src/testlib/qtesteventloop.h9
-rw-r--r--src/testlib/qtestlog.cpp14
-rw-r--r--src/testlib/qtestlog_p.h7
-rw-r--r--src/testlib/qtestresult.cpp178
-rw-r--r--src/testlib/qtestresult_p.h32
-rw-r--r--src/testlib/qtesttable.cpp14
-rw-r--r--src/testlib/qtestxunitstreamer.cpp5
-rw-r--r--src/testlib/qxmltestlogger.cpp29
-rw-r--r--src/testlib/qxunittestlogger.cpp11
-rw-r--r--src/testlib/qxunittestlogger_p.h14
-rw-r--r--src/tools/bootstrap/bootstrap.pro29
-rw-r--r--src/tools/moc/generator.cpp11
-rw-r--r--src/tools/uic/cpp/cppwriteinitialization.cpp5
-rw-r--r--src/widgets/accessible/simplewidgets.cpp3
-rw-r--r--src/widgets/dialogs/qcolordialog.cpp2
-rw-r--r--src/widgets/dialogs/qfiledialog.cpp3
-rw-r--r--src/widgets/dialogs/qfileinfogatherer.cpp10
-rw-r--r--src/widgets/dialogs/qfileinfogatherer_p.h8
-rw-r--r--src/widgets/dialogs/qfilesystemmodel.cpp13
-rw-r--r--src/widgets/dialogs/qfilesystemmodel_p.h55
-rw-r--r--src/widgets/dialogs/qfontdialog.cpp2
-rw-r--r--src/widgets/doc/macOS/AppKit/AppKit.h1
-rw-r--r--src/widgets/doc/qtwidgets.qdocconf3
-rw-r--r--src/widgets/doc/src/widgets-and-layouts/layout.qdoc2
-rw-r--r--src/widgets/graphicsview/qgraphicsitem.cpp4
-rw-r--r--src/widgets/graphicsview/qgraphicsproxywidget.cpp15
-rw-r--r--src/widgets/graphicsview/qgraphicsscene.cpp2
-rw-r--r--src/widgets/graphicsview/qgraphicsview.cpp13
-rw-r--r--src/widgets/graphicsview/qgraphicswidget_p.cpp4
-rw-r--r--src/widgets/graphicsview/qgraphicswidget_p.h3
-rw-r--r--src/widgets/itemviews/qabstractitemview.cpp16
-rw-r--r--src/widgets/itemviews/qheaderview.cpp80
-rw-r--r--src/widgets/itemviews/qitemeditorfactory.cpp8
-rw-r--r--src/widgets/itemviews/qlistview.cpp17
-rw-r--r--src/widgets/itemviews/qlistwidget.cpp6
-rw-r--r--src/widgets/itemviews/qtableview.cpp5
-rw-r--r--src/widgets/itemviews/qtablewidget.cpp4
-rw-r--r--src/widgets/itemviews/qtreeview.cpp5
-rw-r--r--src/widgets/itemviews/qtreewidget.cpp4
-rw-r--r--src/widgets/kernel/qapplication.cpp63
-rw-r--r--src/widgets/kernel/qapplication_p.h7
-rw-r--r--src/widgets/kernel/qwidget.cpp98
-rw-r--r--src/widgets/kernel/qwidget.h3
-rw-r--r--src/widgets/kernel/qwidget_p.h2
-rw-r--r--src/widgets/kernel/qwidgetwindow.cpp9
-rw-r--r--src/widgets/styles/qfusionstyle.cpp9
-rw-r--r--src/widgets/util/qcompleter.cpp9
-rw-r--r--src/widgets/widgets/qabstractbutton.cpp7
-rw-r--r--src/widgets/widgets/qabstractscrollarea.cpp8
-rw-r--r--src/widgets/widgets/qabstractslider.cpp23
-rw-r--r--src/widgets/widgets/qabstractspinbox.cpp13
-rw-r--r--src/widgets/widgets/qcalendarwidget.cpp7
-rw-r--r--src/widgets/widgets/qcombobox.cpp49
-rw-r--r--src/widgets/widgets/qcombobox.h5
-rw-r--r--src/widgets/widgets/qcommandlinkbutton.cpp2
-rw-r--r--src/widgets/widgets/qdatetimeedit.cpp29
-rw-r--r--src/widgets/widgets/qlineedit.cpp101
-rw-r--r--src/widgets/widgets/qlineedit.h3
-rw-r--r--src/widgets/widgets/qlineedit_p.cpp17
-rw-r--r--src/widgets/widgets/qlineedit_p.h11
-rw-r--r--src/widgets/widgets/qmenu.cpp12
-rw-r--r--src/widgets/widgets/qplaintextedit.cpp23
-rw-r--r--src/widgets/widgets/qscrollarea.cpp5
-rw-r--r--src/widgets/widgets/qscrollbar.cpp10
-rw-r--r--src/widgets/widgets/qslider.cpp3
-rw-r--r--src/widgets/widgets/qsplitter.cpp7
-rw-r--r--src/widgets/widgets/qtabbar.cpp7
-rw-r--r--src/widgets/widgets/qtabwidget.cpp7
-rw-r--r--src/widgets/widgets/qtextbrowser.cpp7
-rw-r--r--src/widgets/widgets/qtextedit.cpp21
-rw-r--r--src/widgets/widgets/qtoolbar.cpp1
-rw-r--r--src/widgets/widgets/qwidgetlinecontrol.cpp5
-rw-r--r--src/widgets/widgets/qwidgettextcontrol.cpp11
-rw-r--r--src/xml/sax/qxml.cpp20
377 files changed, 5630 insertions, 3090 deletions
diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java
index 9679fd40f4..c33d5016ce 100644
--- a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java
+++ b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java
@@ -178,6 +178,9 @@ public class QtNative
return fdDesc.detachFd();
} catch (FileNotFoundException e) {
return -1;
+ } catch (SecurityException e) {
+ Log.e(QtTAG, "Exception when opening file", e);
+ return -1;
}
}
diff --git a/src/corelib/codecs/qlatincodec.cpp b/src/corelib/codecs/qlatincodec.cpp
index 463c5a56ae..55e6f0ba4d 100644
--- a/src/corelib/codecs/qlatincodec.cpp
+++ b/src/corelib/codecs/qlatincodec.cpp
@@ -62,7 +62,7 @@ QByteArray QLatin1Codec::convertFromUnicode(const QChar *ch, int len, ConverterS
char *d = r.data();
int invalid = 0;
for (int i = 0; i < len; ++i) {
- if (ch[i] > 0xff) {
+ if (ch[i] > QChar(0xff)) {
d[i] = replacement;
++invalid;
} else {
@@ -112,28 +112,28 @@ QString QLatin15Codec::convertToUnicode(const char* chars, int len, ConverterSta
while(len--) {
switch(uc->unicode()) {
case 0xa4:
- *uc = 0x20ac;
+ *uc = QChar(0x20ac);
break;
case 0xa6:
- *uc = 0x0160;
+ *uc = QChar(0x0160);
break;
case 0xa8:
- *uc = 0x0161;
+ *uc = QChar(0x0161);
break;
case 0xb4:
- *uc = 0x017d;
+ *uc = QChar(0x017d);
break;
case 0xb8:
- *uc = 0x017e;
+ *uc = QChar(0x017e);
break;
case 0xbc:
- *uc = 0x0152;
+ *uc = QChar(0x0152);
break;
case 0xbd:
- *uc = 0x0153;
+ *uc = QChar(0x0153);
break;
case 0xbe:
- *uc = 0x0178;
+ *uc = QChar(0x0178);
break;
default:
break;
diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp
index 85cfcdbf48..8639e4f2f0 100644
--- a/src/corelib/codecs/qtextcodec.cpp
+++ b/src/corelib/codecs/qtextcodec.cpp
@@ -544,11 +544,9 @@ QTextCodec *QTextCodec::codecForName(const QByteArray &name)
#if !QT_CONFIG(icu)
QTextCodecCache *cache = &globalData->codecCache;
QTextCodec *codec;
- if (cache) {
- codec = cache->value(name);
- if (codec)
- return codec;
- }
+ codec = cache->value(name);
+ if (codec)
+ return codec;
for (TextCodecListConstIt it = globalData->allCodecs.constBegin(), cend = globalData->allCodecs.constEnd(); it != cend; ++it) {
QTextCodec *cursor = *it;
@@ -560,8 +558,7 @@ QTextCodec *QTextCodec::codecForName(const QByteArray &name)
QList<QByteArray> aliases = cursor->aliases();
for (ByteArrayListConstIt ait = aliases.constBegin(), acend = aliases.constEnd(); ait != acend; ++ait) {
if (qTextCodecNameMatch(*ait, name)) {
- if (cache)
- cache->insert(name, cursor);
+ cache->insert(name, cursor);
return cursor;
}
}
diff --git a/src/corelib/codecs/qutfcodec.cpp b/src/corelib/codecs/qutfcodec.cpp
index 85736fdf02..af36bd7e2f 100644
--- a/src/corelib/codecs/qutfcodec.cpp
+++ b/src/corelib/codecs/qutfcodec.cpp
@@ -951,10 +951,10 @@ QString QUtf32::convertToUnicode(const char *chars, int len, QTextCodec::Convert
}
uint code = (endian == BigEndianness) ? qFromBigEndian<quint32>(tuple) : qFromLittleEndian<quint32>(tuple);
if (QChar::requiresSurrogates(code)) {
- *qch++ = QChar::highSurrogate(code);
- *qch++ = QChar::lowSurrogate(code);
+ *qch++ = QChar(QChar::highSurrogate(code));
+ *qch++ = QChar(QChar::lowSurrogate(code));
} else {
- *qch++ = code;
+ *qch++ = QChar(code);
}
num = 0;
}
diff --git a/src/corelib/configure.json b/src/corelib/configure.json
index 88c7bbfbed..83c30fb47b 100644
--- a/src/corelib/configure.json
+++ b/src/corelib/configure.json
@@ -596,7 +596,7 @@
"qDoubleSnprintf(argv[0], 1, invalidLocale, \"invalid format\", a);",
"qDoubleSscanf(argv[0], invalidLocale, \"invalid format\", &a, &argc);"
],
- "qmake": "DEFINES += QDSP_P_H=$$shell_quote(\\\"@PWD@/tools/qdoublescanprint_p.h\\\")"
+ "qmake": "DEFINES += QDSP_P_H=$$shell_quote(\\\"@PWD@/text/qdoublescanprint_p.h\\\")"
}
}
},
diff --git a/src/corelib/corelib.pro b/src/corelib/corelib.pro
index 521f840292..b9bcc70e17 100644
--- a/src/corelib/corelib.pro
+++ b/src/corelib/corelib.pro
@@ -36,6 +36,7 @@ qtConfig(animation): include(animation/animation.pri)
include(global/global.pri)
include(thread/thread.pri)
include(tools/tools.pri)
+include(text/text.pri)
include(time/time.pri)
include(io/io.pri)
include(itemmodels/itemmodels.pri)
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index f85824c7b3..736378508f 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -1,7 +1,7 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
+** Copyright (C) 2019 The Qt Company Ltd.
+** Copyright (C) 2019 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -613,7 +613,8 @@ using qsizetype = QIntegerForSizeof<std::size_t>::Signed;
# define Q_ALWAYS_INLINE inline
#endif
-#if defined(Q_CC_GNU) && defined(Q_OS_WIN)
+#if defined(Q_CC_GNU) && defined(Q_OS_WIN) && !defined(QT_NO_DATA_RELOCATION)
+// ### Qt6: you can remove me
# define QT_INIT_METAOBJECT __attribute__((init_priority(101)))
#else
# define QT_INIT_METAOBJECT
@@ -1002,6 +1003,29 @@ QT_WARNING_DISABLE_MSVC(4530) /* C++ exception handler used, but unwind semantic
# endif
#endif
+// Work around MSVC warning about use of 3-arg algorithms
+// until we can depend on the C++14 4-arg ones.
+//
+// These algortithms do NOT check for equal length.
+// They need to be treated as if they called the 3-arg version (which they do)!
+#ifdef Q_CC_MSVC
+# define QT_3ARG_ALG(alg, f1, l1, f2, l2) \
+ std::alg(f1, l1, f2, l2)
+#else
+# define QT_3ARG_ALG(alg, f1, l1, f2, l2) \
+ [&f1, &l1, &f2, &l2]() { \
+ Q_UNUSED(l2); \
+ return std::alg(f1, l1, f2); \
+ }()
+#endif
+template <typename ForwardIterator1, typename ForwardIterator2>
+inline bool qt_is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
+ ForwardIterator2 first2, ForwardIterator2 last2)
+{
+ return QT_3ARG_ALG(is_permutation, first1, last1, first2, last2);
+}
+#undef QT_3ARG_ALG
+
// this adds const to non-const objects (like std::as_const)
template <typename T>
Q_DECL_CONSTEXPR typename std::add_const<T>::type &qAsConst(T &t) noexcept { return t; }
diff --git a/src/corelib/global/qsystemdetection.h b/src/corelib/global/qsystemdetection.h
index 02e2f77c6b..4ebbe16ead 100644
--- a/src/corelib/global/qsystemdetection.h
+++ b/src/corelib/global/qsystemdetection.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
+** Copyright (C) 2019 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -180,6 +181,12 @@
#if defined(Q_OS_WIN32) || defined(Q_OS_WIN64) || defined(Q_OS_WINRT)
# define Q_OS_WINDOWS
# define Q_OS_WIN
+# if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+// On Windows, pointers to dllimport'ed variables are not constant expressions,
+// so to keep to certain initializations (like QMetaObject) constexpr, we need
+// to use functions instead.
+# define QT_NO_DATA_RELOCATION
+# endif
#endif
#if defined(Q_OS_WIN)
diff --git a/src/corelib/global/qt_pch.h b/src/corelib/global/qt_pch.h
index 3972991618..0dfd6c745f 100644
--- a/src/corelib/global/qt_pch.h
+++ b/src/corelib/global/qt_pch.h
@@ -55,6 +55,10 @@
#include <stdlib.h>
#include <qglobal.h>
#ifdef Q_OS_WIN
+# ifdef Q_CC_MINGW
+// <unistd.h> must be included before any other header pulls in <time.h>.
+# include <unistd.h> // Define _POSIX_THREAD_SAFE_FUNCTIONS to obtain localtime_r()
+# endif
# define _POSIX_
# include <limits.h>
# undef _POSIX_
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp
index 62dae3577c..fae935fc24 100644
--- a/src/corelib/io/qdir.cpp
+++ b/src/corelib/io/qdir.cpp
@@ -153,7 +153,7 @@ QDirPrivate::QDirPrivate(const QDirPrivate &copy)
bool QDirPrivate::exists() const
{
- if (fileEngine.isNull()) {
+ if (!fileEngine) {
QFileSystemEngine::fillMetaData(dirEntry, metaData,
QFileSystemMetaData::ExistsAttribute | QFileSystemMetaData::DirectoryType); // always stat
return metaData.exists() && metaData.isDirectory();
@@ -226,7 +226,7 @@ inline void QDirPrivate::resolveAbsoluteEntry() const
return;
QString absoluteName;
- if (fileEngine.isNull()) {
+ if (!fileEngine) {
if (!dirEntry.isRelative() && dirEntry.isClean()) {
absoluteDirEntry = dirEntry;
return;
@@ -693,7 +693,7 @@ QString QDir::absolutePath() const
QString QDir::canonicalPath() const
{
const QDirPrivate* d = d_ptr.constData();
- if (d->fileEngine.isNull()) {
+ if (!d->fileEngine) {
QFileSystemEntry answer = QFileSystemEngine::canonicalName(d->dirEntry, d->metaData);
return answer.filePath();
}
@@ -947,6 +947,12 @@ QString QDir::fromNativeSeparators(const QString &pathName)
int i = pathName.indexOf(QLatin1Char('\\'));
if (i != -1) {
QString n(pathName);
+ if (n.startsWith(QLatin1String("\\\\?\\"))) {
+ n.remove(0, 4);
+ i = n.indexOf(QLatin1Char('\\'));
+ if (i == -1)
+ return n;
+ }
QChar * const data = n.data();
data[i++] = QLatin1Char('/');
@@ -1496,7 +1502,7 @@ bool QDir::mkdir(const QString &dirName) const
}
QString fn = filePath(dirName);
- if (d->fileEngine.isNull())
+ if (!d->fileEngine)
return QFileSystemEngine::createDirectory(QFileSystemEntry(fn), false);
return d->fileEngine->mkdir(fn, false);
}
@@ -1520,7 +1526,7 @@ bool QDir::rmdir(const QString &dirName) const
}
QString fn = filePath(dirName);
- if (d->fileEngine.isNull())
+ if (!d->fileEngine)
return QFileSystemEngine::removeDirectory(QFileSystemEntry(fn), false);
return d->fileEngine->rmdir(fn, false);
@@ -1548,7 +1554,7 @@ bool QDir::mkpath(const QString &dirPath) const
}
QString fn = filePath(dirPath);
- if (d->fileEngine.isNull())
+ if (!d->fileEngine)
return QFileSystemEngine::createDirectory(QFileSystemEntry(fn), true);
return d->fileEngine->mkdir(fn, true);
}
@@ -1574,7 +1580,7 @@ bool QDir::rmpath(const QString &dirPath) const
}
QString fn = filePath(dirPath);
- if (d->fileEngine.isNull())
+ if (!d->fileEngine)
return QFileSystemEngine::removeDirectory(QFileSystemEntry(fn), true);
return d->fileEngine->rmdir(fn, true);
}
@@ -1647,7 +1653,7 @@ bool QDir::isReadable() const
{
const QDirPrivate* d = d_ptr.constData();
- if (d->fileEngine.isNull()) {
+ if (!d->fileEngine) {
if (!d->metaData.hasFlags(QFileSystemMetaData::UserReadPermission))
QFileSystemEngine::fillMetaData(d->dirEntry, d->metaData, QFileSystemMetaData::UserReadPermission);
@@ -1692,7 +1698,7 @@ bool QDir::exists() const
*/
bool QDir::isRoot() const
{
- if (d_ptr->fileEngine.isNull())
+ if (!d_ptr->fileEngine)
return d_ptr->dirEntry.isRoot();
return d_ptr->fileEngine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::RootFlag;
}
@@ -1724,7 +1730,7 @@ bool QDir::isRoot() const
*/
bool QDir::isRelative() const
{
- if (d_ptr->fileEngine.isNull())
+ if (!d_ptr->fileEngine)
return d_ptr->dirEntry.isRelative();
return d_ptr->fileEngine->isRelativePath();
}
@@ -1741,7 +1747,7 @@ bool QDir::makeAbsolute()
{
const QDirPrivate *d = d_ptr.constData();
QScopedPointer<QDirPrivate> dir;
- if (!d->fileEngine.isNull()) {
+ if (!!d->fileEngine) {
QString absolutePath = d->fileEngine->fileName(QAbstractFileEngine::AbsoluteName);
if (QDir::isRelativePath(absolutePath))
return false;
@@ -1774,8 +1780,8 @@ bool QDir::operator==(const QDir &dir) const
if (d == other)
return true;
Qt::CaseSensitivity sensitive;
- if (d->fileEngine.isNull() || other->fileEngine.isNull()) {
- if (d->fileEngine.data() != other->fileEngine.data()) // one is native, the other is a custom file-engine
+ if (!d->fileEngine || !other->fileEngine) {
+ if (d->fileEngine.get() != other->fileEngine.get()) // one is native, the other is a custom file-engine
return false;
sensitive = QFileSystemEngine::isCaseSensitive() ? Qt::CaseSensitive : Qt::CaseInsensitive;
@@ -2339,6 +2345,11 @@ static QString qt_cleanPath(const QString &path, bool *ok)
if (path.isEmpty())
return path;
QString name = path;
+#if defined (Q_OS_WIN)
+ if (name.startsWith(QLatin1String("\\\\?\\")))
+ name.remove(0, 4);
+#endif
+
QChar dir_separator = QDir::separator();
if (dir_separator != QLatin1Char('/'))
name.replace(dir_separator, QLatin1Char('/'));
diff --git a/src/corelib/io/qdir_p.h b/src/corelib/io/qdir_p.h
index 0f3ab7f899..af105de8db 100644
--- a/src/corelib/io/qdir_p.h
+++ b/src/corelib/io/qdir_p.h
@@ -54,6 +54,8 @@
#include "qfilesystementry_p.h"
#include "qfilesystemmetadata_p.h"
+#include <memory>
+
QT_BEGIN_NAMESPACE
class QDirPrivate : public QSharedData
@@ -82,7 +84,7 @@ public:
static inline QChar getFilterSepChar(const QString &nameFilter);
- static inline QStringList splitFilters(const QString &nameFilter, QChar sep = 0);
+ static inline QStringList splitFilters(const QString &nameFilter, QChar sep = {});
void setPath(const QString &path);
@@ -98,7 +100,7 @@ public:
QDir::SortFlags sort;
QDir::Filters filters;
- QScopedPointer<QAbstractFileEngine> fileEngine;
+ std::unique_ptr<QAbstractFileEngine> fileEngine;
QFileSystemEntry dirEntry;
mutable QFileSystemEntry absoluteDirEntry;
diff --git a/src/corelib/io/qdiriterator.cpp b/src/corelib/io/qdiriterator.cpp
index 303caf29a4..ce436b06e3 100644
--- a/src/corelib/io/qdiriterator.cpp
+++ b/src/corelib/io/qdiriterator.cpp
@@ -107,6 +107,8 @@
#include <QtCore/private/qfilesystemengine_p.h>
#include <QtCore/private/qfileinfo_p.h>
+#include <memory>
+
QT_BEGIN_NAMESPACE
template <class Iterator>
@@ -132,7 +134,7 @@ public:
void checkAndPushDirectory(const QFileInfo &);
bool matchesFilters(const QString &fileName, const QFileInfo &fi) const;
- QScopedPointer<QAbstractFileEngine> engine;
+ std::unique_ptr<QAbstractFileEngine> engine;
QFileSystemEntry dirEntry;
const QStringList nameFilters;
@@ -435,7 +437,7 @@ bool QDirIteratorPrivate::matchesFilters(const QString &fileName, const QFileInf
QDirIterator::QDirIterator(const QDir &dir, IteratorFlags flags)
{
const QDirPrivate *other = dir.d_ptr.constData();
- d.reset(new QDirIteratorPrivate(other->dirEntry, other->nameFilters, other->filters, flags, !other->fileEngine.isNull()));
+ d.reset(new QDirIteratorPrivate(other->dirEntry, other->nameFilters, other->filters, flags, bool(other->fileEngine)));
}
/*!
diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp
index 9f9a9e3040..95f03ef816 100644
--- a/src/corelib/io/qfile.cpp
+++ b/src/corelib/io/qfile.cpp
@@ -55,6 +55,8 @@
# include "qcoreapplication.h"
#endif
+#include <private/qmemory_p.h>
+
#ifdef QT_NO_QOBJECT
#define tr(X) QString::fromLatin1(X)
#endif
@@ -85,10 +87,9 @@ QFilePrivate::openExternalFile(int flags, int fd, QFile::FileHandleFlags handleF
Q_UNUSED(fd);
return false;
#else
- delete fileEngine;
- fileEngine = nullptr;
- QFSFileEngine *fe = new QFSFileEngine;
- fileEngine = fe;
+ auto fs = qt_make_unique<QFSFileEngine>();
+ auto fe = fs.get();
+ fileEngine = std::move(fs);
return fe->open(QIODevice::OpenMode(flags), fd, handleFlags);
#endif
}
@@ -101,10 +102,9 @@ QFilePrivate::openExternalFile(int flags, FILE *fh, QFile::FileHandleFlags handl
Q_UNUSED(fh);
return false;
#else
- delete fileEngine;
- fileEngine = nullptr;
- QFSFileEngine *fe = new QFSFileEngine;
- fileEngine = fe;
+ auto fs = qt_make_unique<QFSFileEngine>();
+ auto fe = fs.get();
+ fileEngine = std::move(fs);
return fe->open(QIODevice::OpenMode(flags), fh, handleFlags);
#endif
}
@@ -112,8 +112,8 @@ QFilePrivate::openExternalFile(int flags, FILE *fh, QFile::FileHandleFlags handl
QAbstractFileEngine *QFilePrivate::engine() const
{
if (!fileEngine)
- fileEngine = QAbstractFileEngine::create(fileName);
- return fileEngine;
+ fileEngine.reset(QAbstractFileEngine::create(fileName));
+ return fileEngine.get();
}
//************* QFile
@@ -334,10 +334,7 @@ QFile::setFileName(const QString &name)
file_already_open(*this, "setFileName");
close();
}
- if(d->fileEngine) { //get a new file engine later
- delete d->fileEngine;
- d->fileEngine = nullptr;
- }
+ d->fileEngine.reset(); //get a new file engine later
d->fileName = name;
}
diff --git a/src/corelib/io/qfiledevice.cpp b/src/corelib/io/qfiledevice.cpp
index 2f74547054..ee619d99cc 100644
--- a/src/corelib/io/qfiledevice.cpp
+++ b/src/corelib/io/qfiledevice.cpp
@@ -42,6 +42,8 @@
#include "qfiledevice_p.h"
#include "qfsfileengine_p.h"
+#include <private/qmemory_p.h>
+
#ifdef QT_NO_QOBJECT
#define tr(X) QString::fromLatin1(X)
#endif
@@ -53,24 +55,20 @@ QT_BEGIN_NAMESPACE
#endif
QFileDevicePrivate::QFileDevicePrivate()
- : fileEngine(nullptr),
- cachedSize(0),
+ : cachedSize(0),
error(QFile::NoError), lastWasWrite(false)
{
writeBufferChunkSize = QFILE_WRITEBUFFER_SIZE;
}
QFileDevicePrivate::~QFileDevicePrivate()
-{
- delete fileEngine;
- fileEngine = nullptr;
-}
+ = default;
QAbstractFileEngine * QFileDevicePrivate::engine() const
{
if (!fileEngine)
- fileEngine = new QFSFileEngine;
- return fileEngine;
+ fileEngine = qt_make_unique<QFSFileEngine>();
+ return fileEngine.get();
}
void QFileDevicePrivate::setError(QFileDevice::FileError err)
diff --git a/src/corelib/io/qfiledevice_p.h b/src/corelib/io/qfiledevice_p.h
index 47053d01b7..aef3fca811 100644
--- a/src/corelib/io/qfiledevice_p.h
+++ b/src/corelib/io/qfiledevice_p.h
@@ -53,6 +53,8 @@
#include "private/qiodevice_p.h"
+#include <memory>
+
QT_BEGIN_NAMESPACE
class QAbstractFileEngine;
@@ -75,7 +77,7 @@ protected:
void setError(QFileDevice::FileError err, const QString &errorString);
void setError(QFileDevice::FileError err, int errNum);
- mutable QAbstractFileEngine *fileEngine;
+ mutable std::unique_ptr<QAbstractFileEngine> fileEngine;
mutable qint64 cachedSize;
QFileDevice::FileHandleFlags handleFlags;
diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp
index f5b398feae..a5a3bc8b3e 100644
--- a/src/corelib/io/qfileinfo.cpp
+++ b/src/corelib/io/qfileinfo.cpp
@@ -707,11 +707,11 @@ bool QFileInfo::exists(const QString &file)
return false;
QFileSystemEntry entry(file);
QFileSystemMetaData data;
- QAbstractFileEngine *engine =
- QFileSystemEngine::resolveEntryAndCreateLegacyEngine(entry, data);
+ std::unique_ptr<QAbstractFileEngine> engine
+ {QFileSystemEngine::resolveEntryAndCreateLegacyEngine(entry, data)};
// Expensive fallback to non-QFileSystemEngine implementation
if (engine)
- return QFileInfo(new QFileInfoPrivate(entry, data, engine)).exists();
+ return QFileInfo(new QFileInfoPrivate(entry, data, std::move(engine))).exists();
QFileSystemEngine::fillMetaData(entry, data, QFileSystemMetaData::ExistsAttribute);
return data.exists();
diff --git a/src/corelib/io/qfileinfo_p.h b/src/corelib/io/qfileinfo_p.h
index 36f440812f..333ea70adc 100644
--- a/src/corelib/io/qfileinfo_p.h
+++ b/src/corelib/io/qfileinfo_p.h
@@ -61,6 +61,8 @@
#include <QtCore/private/qfilesystementry_p.h>
#include <QtCore/private/qfilesystemmetadata_p.h>
+#include <memory>
+
QT_BEGIN_NAMESPACE
class QFileInfoPrivate : public QSharedData
@@ -126,10 +128,10 @@ public:
metaData = QFileSystemMetaData();
}
- inline QFileInfoPrivate(const QFileSystemEntry &file, const QFileSystemMetaData &data, QAbstractFileEngine *engine)
+ inline QFileInfoPrivate(const QFileSystemEntry &file, const QFileSystemMetaData &data, std::unique_ptr<QAbstractFileEngine> engine)
: fileEntry(file),
metaData(data),
- fileEngine(engine),
+ fileEngine{std::move(engine)},
cachedFlags(0),
#ifndef QT_NO_FSFILEENGINE
isDefaultConstructed(false),
@@ -163,7 +165,7 @@ public:
QFileSystemEntry fileEntry;
mutable QFileSystemMetaData metaData;
- QScopedPointer<QAbstractFileEngine> const fileEngine;
+ std::unique_ptr<QAbstractFileEngine> const fileEngine;
mutable QString fileNames[QAbstractFileEngine::NFileNames];
mutable QString fileOwners[2]; // QAbstractFileEngine::FileOwner: OwnerUser and OwnerGroup
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp
index 066a7c3f01..74865fe31f 100644
--- a/src/corelib/io/qfilesystemengine_unix.cpp
+++ b/src/corelib/io/qfilesystemengine_unix.cpp
@@ -822,6 +822,8 @@ QString QFileSystemEngine::resolveUserName(uint userId)
#endif
if (pw)
return QFile::decodeName(QByteArray(pw->pw_name));
+#else // Integrity || WASM
+ Q_UNUSED(userId);
#endif
return QString();
}
@@ -859,6 +861,8 @@ QString QFileSystemEngine::resolveGroupName(uint groupId)
#endif
if (gr)
return QFile::decodeName(QByteArray(gr->gr_name));
+#else // Integrity || WASM
+ Q_UNUSED(groupId);
#endif
return QString();
}
diff --git a/src/corelib/io/qfilesystemiterator_unix.cpp b/src/corelib/io/qfilesystemiterator_unix.cpp
index 5ac7e13a2e..2d09c277eb 100644
--- a/src/corelib/io/qfilesystemiterator_unix.cpp
+++ b/src/corelib/io/qfilesystemiterator_unix.cpp
@@ -40,13 +40,54 @@
#include "qplatformdefs.h"
#include "qfilesystemiterator_p.h"
+#if QT_CONFIG(textcodec)
+# include <qtextcodec.h>
+# include <private/qutfcodec_p.h>
+#endif
+
#ifndef QT_NO_FILESYSTEMITERATOR
+#include <memory>
+
#include <stdlib.h>
#include <errno.h>
QT_BEGIN_NAMESPACE
+static bool checkNameDecodable(const char *d_name, qsizetype len)
+{
+ // This function is called in a loop from advance() below, but the loop is
+ // usually run only once.
+
+#if QT_CONFIG(textcodec)
+ // We identify the codecs by their RFC 2978 MIBenum values. In this
+ // function:
+ // 3 US-ASCII (ANSI X3.4-1986)
+ // 4 Latin1 (ISO-8859-1)
+ // 106 UTF-8
+ QTextCodec *codec = QTextCodec::codecForLocale();
+# ifdef QT_LOCALE_IS_UTF8
+ int mibEnum = 106;
+# else
+ int mibEnum = codec->mibEnum();
+# endif
+ if (Q_LIKELY(mibEnum == 106)) // UTF-8
+ return QUtf8::isValidUtf8(d_name, len).isValidUtf8;
+ if (mibEnum == 3) // US-ASCII
+ return QtPrivate::isAscii(QLatin1String(d_name, len));
+ if (mibEnum == 4) // Latin 1
+ return true;
+
+ // fall back to generic QTextCodec
+ QTextCodec::ConverterState cs(QTextCodec::IgnoreHeader);
+ codec->toUnicode(d_name, len, &cs);
+ return cs.invalidChars == 0 && cs.remainingChars == 0;
+#else
+ // if we have no text codecs, then QString::fromLocal8Bit is fromLatin1
+ return true;
+#endif
+}
+
QFileSystemIterator::QFileSystemIterator(const QFileSystemEntry &entry, QDir::Filters filters,
const QStringList &nameFilters, QDirIterator::IteratorFlags flags)
: nativePath(entry.nativeFilePath())
@@ -81,9 +122,9 @@ bool QFileSystemIterator::advance(QFileSystemEntry &fileEntry, QFileSystemMetaDa
dirEntry = QT_READDIR(dir);
if (dirEntry) {
- // process entries with correct UTF-8 names only
- if (QFile::encodeName(QFile::decodeName(dirEntry->d_name)) == dirEntry->d_name) {
- fileEntry = QFileSystemEntry(nativePath + QByteArray(dirEntry->d_name), QFileSystemEntry::FromNativePath());
+ qsizetype len = strlen(dirEntry->d_name);
+ if (checkNameDecodable(dirEntry->d_name, len)) {
+ fileEntry = QFileSystemEntry(nativePath + QByteArray(dirEntry->d_name, len), QFileSystemEntry::FromNativePath());
metaData.fillFromDirEnt(*dirEntry);
return true;
}
diff --git a/src/corelib/io/qfilesystemwatcher_inotify.cpp b/src/corelib/io/qfilesystemwatcher_inotify.cpp
index 5fb5685f42..ca1f6cc359 100644
--- a/src/corelib/io/qfilesystemwatcher_inotify.cpp
+++ b/src/corelib/io/qfilesystemwatcher_inotify.cpp
@@ -422,16 +422,27 @@ void QInotifyFileSystemWatcherEngine::readFromInotify()
}
}
-QString QInotifyFileSystemWatcherEngine::getPathFromID(int id) const
+template <typename Hash, typename Key>
+typename Hash::const_iterator
+find_last_in_equal_range(const Hash &c, const Key &key)
{
- QHash<int, QString>::const_iterator i = idToPath.find(id);
- while (i != idToPath.constEnd() && i.key() == id) {
- if ((i + 1) == idToPath.constEnd() || (i + 1).key() != id) {
- return i.value();
- }
+ // find c.equal_range(key).second - 1 without backwards iteration:
+ auto i = c.find(key);
+ const auto end = c.cend();
+ if (i == end)
+ return end;
+ decltype(i) prev;
+ do {
+ prev = i;
++i;
- }
- return QString();
+ } while (i != end && i.key() == key);
+ return prev;
+}
+
+QString QInotifyFileSystemWatcherEngine::getPathFromID(int id) const
+{
+ auto i = find_last_in_equal_range(idToPath, id);
+ return i == idToPath.cend() ? QString() : i.value() ;
}
QT_END_NAMESPACE
diff --git a/src/corelib/io/qfsfileengine.cpp b/src/corelib/io/qfsfileengine.cpp
index 0db27f3e25..0d73839f8d 100644
--- a/src/corelib/io/qfsfileengine.cpp
+++ b/src/corelib/io/qfsfileengine.cpp
@@ -167,19 +167,21 @@ QFSFileEngine::QFSFileEngine(QFSFileEnginePrivate &dd)
/*!
\internal
*/
-bool QFSFileEngine::processOpenModeFlags(QIODevice::OpenMode *mode)
+ProcessOpenModeResult processOpenModeFlags(QIODevice::OpenMode openMode)
{
- QIODevice::OpenMode &openMode = *mode;
+ ProcessOpenModeResult result;
+ result.ok = false;
if ((openMode & QFile::NewOnly) && (openMode & QFile::ExistingOnly)) {
qWarning("NewOnly and ExistingOnly are mutually exclusive");
- setError(QFile::OpenError, QLatin1String("NewOnly and ExistingOnly are mutually exclusive"));
- return false;
+ result.error = QLatin1String("NewOnly and ExistingOnly are mutually exclusive");
+ return result;
}
if ((openMode & QFile::ExistingOnly) && !(openMode & (QFile::ReadOnly | QFile::WriteOnly))) {
qWarning("ExistingOnly must be specified alongside ReadOnly, WriteOnly, or ReadWrite");
- setError(QFile::OpenError, QLatin1String("ExistingOnly must be specified alongside ReadOnly, WriteOnly, or ReadWrite"));
- return false;
+ result.error = QLatin1String(
+ "ExistingOnly must be specified alongside ReadOnly, WriteOnly, or ReadWrite");
+ return result;
}
// Either Append or NewOnly implies WriteOnly
@@ -190,7 +192,9 @@ bool QFSFileEngine::processOpenModeFlags(QIODevice::OpenMode *mode)
if ((openMode & QFile::WriteOnly) && !(openMode & (QFile::ReadOnly | QFile::Append | QFile::NewOnly)))
openMode |= QFile::Truncate;
- return true;
+ result.ok = true;
+ result.openMode = openMode;
+ return result;
}
/*!
@@ -234,16 +238,19 @@ bool QFSFileEngine::open(QIODevice::OpenMode openMode)
return false;
}
- if (!processOpenModeFlags(&openMode))
+ const ProcessOpenModeResult res = processOpenModeFlags(openMode);
+ if (!res.ok) {
+ setError(QFileDevice::OpenError, res.error);
return false;
+ }
- d->openMode = openMode;
+ d->openMode = res.openMode;
d->lastFlushFailed = false;
d->tried_stat = 0;
d->fh = nullptr;
d->fd = -1;
- return d->nativeOpen(openMode);
+ return d->nativeOpen(d->openMode);
}
/*!
@@ -262,17 +269,20 @@ bool QFSFileEngine::open(QIODevice::OpenMode openMode, FILE *fh, QFile::FileHand
Q_D(QFSFileEngine);
- if (!processOpenModeFlags(&openMode))
+ const ProcessOpenModeResult res = processOpenModeFlags(openMode);
+ if (!res.ok) {
+ setError(QFileDevice::OpenError, res.error);
return false;
+ }
- d->openMode = openMode;
+ d->openMode = res.openMode;
d->lastFlushFailed = false;
d->closeFileHandle = (handleFlags & QFile::AutoCloseHandle);
d->fileEntry.clear();
d->tried_stat = 0;
d->fd = -1;
- return d->openFh(openMode, fh);
+ return d->openFh(d->openMode, fh);
}
/*!
@@ -321,10 +331,13 @@ bool QFSFileEngine::open(QIODevice::OpenMode openMode, int fd, QFile::FileHandle
{
Q_D(QFSFileEngine);
- if (!processOpenModeFlags(&openMode))
+ const ProcessOpenModeResult res = processOpenModeFlags(openMode);
+ if (!res.ok) {
+ setError(QFileDevice::OpenError, res.error);
return false;
+ }
- d->openMode = openMode;
+ d->openMode = res.openMode;
d->lastFlushFailed = false;
d->closeFileHandle = (handleFlags & QFile::AutoCloseHandle);
d->fileEntry.clear();
@@ -332,7 +345,7 @@ bool QFSFileEngine::open(QIODevice::OpenMode openMode, int fd, QFile::FileHandle
d->fd = -1;
d->tried_stat = 0;
- return d->openFd(openMode, fd);
+ return d->openFd(d->openMode, fd);
}
diff --git a/src/corelib/io/qfsfileengine_p.h b/src/corelib/io/qfsfileengine_p.h
index 0f416f4886..639c01571a 100644
--- a/src/corelib/io/qfsfileengine_p.h
+++ b/src/corelib/io/qfsfileengine_p.h
@@ -61,6 +61,13 @@
QT_BEGIN_NAMESPACE
+struct ProcessOpenModeResult {
+ bool ok;
+ QIODevice::OpenMode openMode;
+ QString error;
+};
+Q_CORE_EXPORT ProcessOpenModeResult processOpenModeFlags(QIODevice::OpenMode mode);
+
class QFSFileEnginePrivate;
class Q_CORE_EXPORT QFSFileEngine : public QAbstractFileEngine
@@ -131,9 +138,6 @@ public:
protected:
QFSFileEngine(QFSFileEnginePrivate &dd);
-
-private:
- inline bool processOpenModeFlags(QIODevice::OpenMode *mode);
};
class Q_AUTOTEST_EXPORT QFSFileEnginePrivate : public QAbstractFileEnginePrivate
diff --git a/src/corelib/io/qipaddress.cpp b/src/corelib/io/qipaddress.cpp
index b3421fca8f..ddc5b6607f 100644
--- a/src/corelib/io/qipaddress.cpp
+++ b/src/corelib/io/qipaddress.cpp
@@ -312,7 +312,7 @@ void toString(QString &appendTo, const IPv6Address address)
}
}
- const QChar colon = ushort(':');
+ const QChar colon = u':';
if (zeroRunLength < 4)
zeroRunOffset = -1;
else if (zeroRunOffset == 0)
diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp
index 0b964e6a21..35ca2542f7 100644
--- a/src/corelib/io/qprocess.cpp
+++ b/src/corelib/io/qprocess.cpp
@@ -202,6 +202,7 @@ void QProcessEnvironmentPrivate::insert(const QProcessEnvironmentPrivate &other)
vars.insert(it.key(), it.value());
#ifdef Q_OS_UNIX
+ const OrderedNameMapMutexLocker locker(this, &other);
auto nit = other.nameMap.constBegin();
const auto nend = other.nameMap.constEnd();
for ( ; nit != nend; ++nit)
@@ -275,7 +276,6 @@ bool QProcessEnvironment::operator==(const QProcessEnvironment &other) const
return true;
if (d) {
if (other.d) {
- QProcessEnvironmentPrivate::OrderedMutexLocker locker(d, other.d);
return d->vars == other.d->vars;
} else {
return isEmpty();
@@ -322,7 +322,6 @@ bool QProcessEnvironment::contains(const QString &name) const
{
if (!d)
return false;
- QProcessEnvironmentPrivate::MutexLocker locker(d);
return d->vars.contains(d->prepareName(name));
}
@@ -373,7 +372,6 @@ QString QProcessEnvironment::value(const QString &name, const QString &defaultVa
if (!d)
return defaultValue;
- QProcessEnvironmentPrivate::MutexLocker locker(d);
const auto it = d->vars.constFind(d->prepareName(name));
if (it == d->vars.constEnd())
return defaultValue;
@@ -398,7 +396,6 @@ QStringList QProcessEnvironment::toStringList() const
{
if (!d)
return QStringList();
- QProcessEnvironmentPrivate::MutexLocker locker(d);
return d->toList();
}
@@ -412,7 +409,6 @@ QStringList QProcessEnvironment::keys() const
{
if (!d)
return QStringList();
- QProcessEnvironmentPrivate::MutexLocker locker(d);
return d->keys();
}
@@ -429,7 +425,6 @@ void QProcessEnvironment::insert(const QProcessEnvironment &e)
return;
// our re-impl of detach() detaches from null
- QProcessEnvironmentPrivate::MutexLocker locker(e.d);
d->insert(*e.d);
}
diff --git a/src/corelib/io/qprocess_p.h b/src/corelib/io/qprocess_p.h
index d02e87837c..2587530c09 100644
--- a/src/corelib/io/qprocess_p.h
+++ b/src/corelib/io/qprocess_p.h
@@ -146,16 +146,22 @@ public:
inline QString nameToString(const Key &name) const { return name; }
inline Value prepareValue(const QString &value) const { return value; }
inline QString valueToString(const Value &value) const { return value; }
- struct MutexLocker {
- MutexLocker(const QProcessEnvironmentPrivate *) {}
+#else
+ struct NameMapMutexLocker : public QMutexLocker
+ {
+ NameMapMutexLocker(const QProcessEnvironmentPrivate *d) : QMutexLocker(&d->nameMapMutex) {}
};
- struct OrderedMutexLocker {
- OrderedMutexLocker(const QProcessEnvironmentPrivate *,
- const QProcessEnvironmentPrivate *) {}
+ struct OrderedNameMapMutexLocker : public QOrderedMutexLocker
+ {
+ OrderedNameMapMutexLocker(const QProcessEnvironmentPrivate *d1,
+ const QProcessEnvironmentPrivate *d2)
+ : QOrderedMutexLocker(&d1->nameMapMutex, &d2->nameMapMutex)
+ {}
};
-#else
+
inline Key prepareName(const QString &name) const
{
+ const NameMapMutexLocker locker(this);
Key &ent = nameMap[name];
if (ent.isEmpty())
ent = name.toLocal8Bit();
@@ -164,40 +170,27 @@ public:
inline QString nameToString(const Key &name) const
{
const QString sname = QString::fromLocal8Bit(name);
- nameMap[sname] = name;
+ {
+ const NameMapMutexLocker locker(this);
+ nameMap[sname] = name;
+ }
return sname;
}
inline Value prepareValue(const QString &value) const { return Value(value); }
inline QString valueToString(const Value &value) const { return value.string(); }
- struct MutexLocker : public QMutexLocker
- {
- MutexLocker(const QProcessEnvironmentPrivate *d) : QMutexLocker(&d->mutex) {}
- };
- struct OrderedMutexLocker : public QOrderedMutexLocker
- {
- OrderedMutexLocker(const QProcessEnvironmentPrivate *d1,
- const QProcessEnvironmentPrivate *d2) :
- QOrderedMutexLocker(&d1->mutex, &d2->mutex)
- {}
- };
-
QProcessEnvironmentPrivate() : QSharedData() {}
QProcessEnvironmentPrivate(const QProcessEnvironmentPrivate &other) :
- QSharedData()
+ QSharedData(), vars(other.vars)
{
- // This being locked ensures that the functions that only assign
- // d pointers don't need explicit locking.
// We don't need to lock our own mutex, as this object is new and
// consequently not shared. For the same reason, non-const methods
// do not need a lock, as they detach objects (however, we need to
// ensure that they really detach before using prepareName()).
- MutexLocker locker(&other);
- vars = other.vars;
+ NameMapMutexLocker locker(&other);
nameMap = other.nameMap;
- // We need to detach our members, so that our mutex can protect them.
- // As we are being detached, they likely would be detached a moment later anyway.
- vars.detach();
+ // We need to detach our nameMap, so that our mutex can protect it.
+ // As we are being detached, it likely would be detached a moment later anyway.
nameMap.detach();
}
#endif
@@ -208,8 +201,7 @@ public:
#ifdef Q_OS_UNIX
typedef QHash<QString, Key> NameHash;
mutable NameHash nameMap;
-
- mutable QMutex mutex;
+ mutable QMutex nameMapMutex;
#endif
static QProcessEnvironment fromList(const QStringList &list);
diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp
index 1d5b76a8a4..951fc4ccaa 100644
--- a/src/corelib/io/qprocess_unix.cpp
+++ b/src/corelib/io/qprocess_unix.cpp
@@ -438,7 +438,6 @@ void QProcessPrivate::startProcess()
int envc = 0;
char **envp = 0;
if (environment.d.constData()) {
- QProcessEnvironmentPrivate::MutexLocker locker(environment.d);
envp = _q_dupEnvironment(environment.d.constData()->vars, &envc);
}
@@ -970,7 +969,6 @@ bool QProcessPrivate::startDetached(qint64 *pid)
int envc = 0;
char **envp = nullptr;
if (environment.d.constData()) {
- QProcessEnvironmentPrivate::MutexLocker locker(environment.d);
envp = _q_dupEnvironment(environment.d.constData()->vars, &envc);
}
diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp
index fcc5b69179..52b746d04a 100644
--- a/src/corelib/io/qresource.cpp
+++ b/src/corelib/io/qresource.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
-** Copyright (C) 2018 Intel Corporation.
+** Copyright (C) 2019 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -279,14 +279,14 @@ static inline QStringList *resourceSearchPaths()
This enum is used by compressionAlgorithm() to indicate which algorithm the
RCC tool used to compress the payload.
- \value NoCompression Contents are not compressed (isCompressed() is false).
+ \value NoCompression Contents are not compressed
\value ZlibCompression Contents are compressed using \l{zlib}{https://zlib.net} and can
be decompressed using the qUncompress() function.
\value ZstdCompression Contents are compressed using \l{zstd}{https://zstd.net}. To
decompress, use the \c{ZSTD_decompress} function from the zstd
library.
- \sa compressionAlgorithm(), isCompressed()
+ \sa compressionAlgorithm()
*/
class QResourcePrivate {
@@ -551,13 +551,20 @@ bool QResource::isValid() const
\sa isDir()
*/
-
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
+ \obsolete
+
Returns \c true if the resource represents a file and the data backing it
is in a compressed format, false otherwise. If the data is compressed,
check compressionAlgorithm() to verify what algorithm to use to decompress
the data.
+ \note This function is deprecated and can be replaced with
+ \code
+ compressionAlgorithm() != NoCompression
+ \endcode
+
\sa data(), compressionAlgorithm(), isFile()
*/
@@ -565,6 +572,7 @@ bool QResource::isCompressed() const
{
return compressionAlgorithm() != NoCompression;
}
+#endif
/*!
\since 5.13
@@ -582,7 +590,7 @@ bool QResource::isCompressed() const
See \l{http://facebook.github.io/zstd/zstd_manual.html}{Zstandard manual}.
- \sa isCompressed(), data(), isFile()
+ \sa data(), isFile()
*/
QResource::Compression QResource::compressionAlgorithm() const
{
@@ -606,11 +614,11 @@ qint64 QResource::size() const
/*!
Returns direct access to a read only segment of data that this resource
- represents. If the resource is compressed the data returns is
- compressed and qUncompress() must be used to access the data. If the
- resource is a directory \nullptr is returned.
+ represents. If the resource is compressed the data returned is compressed
+ and the appropriate library functions must be used to access the data. If
+ the resource is a directory \nullptr is returned.
- \sa size(), isCompressed(), isFile()
+ \sa size(), compressionAlgorithm(), isFile()
*/
const uchar *QResource::data() const
@@ -940,12 +948,15 @@ bool QResourceRoot::mappingRootSubdir(const QString &path, QString *match) const
Q_CORE_EXPORT bool qRegisterResourceData(int version, const unsigned char *tree,
const unsigned char *name, const unsigned char *data)
{
+ if (resourceGlobalData.isDestroyed())
+ return false;
QMutexLocker lock(resourceMutex());
- if (version >= 0x01 && version <= 0x3 && resourceList()) {
+ ResourceList *list = resourceList();
+ if (version >= 0x01 && version <= 0x3) {
bool found = false;
QResourceRoot res(version, tree, name, data);
- for(int i = 0; i < resourceList()->size(); ++i) {
- if(*resourceList()->at(i) == res) {
+ for (int i = 0; i < list->size(); ++i) {
+ if (*list->at(i) == res) {
found = true;
break;
}
@@ -953,7 +964,7 @@ Q_CORE_EXPORT bool qRegisterResourceData(int version, const unsigned char *tree,
if(!found) {
QResourceRoot *root = new QResourceRoot(version, tree, name, data);
root->ref.ref();
- resourceList()->append(root);
+ list->append(root);
}
return true;
}
@@ -967,11 +978,12 @@ Q_CORE_EXPORT bool qUnregisterResourceData(int version, const unsigned char *tre
return false;
QMutexLocker lock(resourceMutex());
- if (version >= 0x01 && version <= 0x3 && resourceList()) {
+ if (version >= 0x01 && version <= 0x3) {
QResourceRoot res(version, tree, name, data);
- for(int i = 0; i < resourceList()->size(); ) {
- if(*resourceList()->at(i) == res) {
- QResourceRoot *root = resourceList()->takeAt(i);
+ ResourceList *list = resourceList();
+ for (int i = 0; i < list->size(); ) {
+ if (*list->at(i) == res) {
+ QResourceRoot *root = list->takeAt(i);
if(!root->ref.deref())
delete root;
} else {
@@ -1217,7 +1229,7 @@ QResource::unregisterResource(const QString &rccFilename, const QString &resourc
if(res->type() == QResourceRoot::Resource_File) {
QDynamicFileResourceRoot *root = reinterpret_cast<QDynamicFileResourceRoot*>(res);
if (root->mappingFile() == rccFilename && root->mappingRoot() == r) {
- resourceList()->removeAt(i);
+ list->removeAt(i);
if(!root->ref.deref()) {
delete root;
return true;
@@ -1288,7 +1300,7 @@ QResource::unregisterResource(const uchar *rccData, const QString &resourceRoot)
if(res->type() == QResourceRoot::Resource_Buffer) {
QDynamicBufferResourceRoot *root = reinterpret_cast<QDynamicBufferResourceRoot*>(res);
if (root->mappingBuffer() == rccData && root->mappingRoot() == r) {
- resourceList()->removeAt(i);
+ list->removeAt(i);
if(!root->ref.deref()) {
delete root;
return true;
@@ -1366,9 +1378,15 @@ bool QResourceFileEngine::open(QIODevice::OpenMode flags)
qWarning("QResourceFileEngine::open: Missing file name");
return false;
}
- if(flags & QIODevice::WriteOnly)
+ if (flags & QIODevice::WriteOnly)
return false;
- d->uncompress();
+ if (d->resource.compressionAlgorithm() != QResource::NoCompression) {
+ d->uncompress();
+ if (d->uncompressed.isNull()) {
+ d->errorString = QSystemError::stdString(EIO);
+ return false;
+ }
+ }
if (!d->resource.isValid()) {
d->errorString = QSystemError::stdString(ENOENT);
return false;
@@ -1395,7 +1413,7 @@ qint64 QResourceFileEngine::read(char *data, qint64 len)
len = size()-d->offset;
if(len <= 0)
return 0;
- if(d->resource.isCompressed())
+ if (!d->uncompressed.isNull())
memcpy(data, d->uncompressed.constData()+d->offset, len);
else
memcpy(data, d->resource.data()+d->offset, len);
@@ -1431,9 +1449,9 @@ bool QResourceFileEngine::link(const QString &)
qint64 QResourceFileEngine::size() const
{
Q_D(const QResourceFileEngine);
- if(!d->resource.isValid())
+ if (!d->resource.isValid())
return 0;
- if (d->resource.isCompressed()) {
+ if (d->resource.compressionAlgorithm() != QResource::NoCompression) {
d->uncompress();
return d->uncompressed.size();
}
@@ -1596,7 +1614,7 @@ uchar *QResourceFileEnginePrivate::map(qint64 offset, qint64 size, QFile::Memory
Q_UNUSED(flags);
qint64 max = resource.size();
- if (resource.isCompressed()) {
+ if (resource.compressionAlgorithm() != QResource::NoCompression) {
uncompress();
max = uncompressed.size();
}
@@ -1609,7 +1627,7 @@ uchar *QResourceFileEnginePrivate::map(qint64 offset, qint64 size, QFile::Memory
}
const uchar *address = resource.data();
- if (resource.isCompressed())
+ if (resource.compressionAlgorithm() != QResource::NoCompression)
address = reinterpret_cast<const uchar *>(uncompressed.constData());
return const_cast<uchar *>(address) + offset;
diff --git a/src/corelib/io/qresource.h b/src/corelib/io/qresource.h
index 5e798de436..5ee8d5d266 100644
--- a/src/corelib/io/qresource.h
+++ b/src/corelib/io/qresource.h
@@ -72,7 +72,6 @@ public:
bool isValid() const;
- bool isCompressed() const;
Compression compressionAlgorithm() const;
qint64 size() const;
const uchar *data() const;
@@ -84,6 +83,10 @@ public:
QT_DEPRECATED_X("Use QDir::searchPaths() instead")
static QStringList searchPaths();
#endif
+#if QT_DEPRECATED_SINCE(5, 15)
+ QT_DEPRECATED_VERSION_X_5_15("Use QResource::compressionAlgorithm() instead")
+ bool isCompressed() const;
+#endif
static bool registerResource(const QString &rccFilename, const QString &resourceRoot=QString());
static bool unregisterResource(const QString &rccFilename, const QString &resourceRoot=QString());
diff --git a/src/corelib/io/qsavefile.cpp b/src/corelib/io/qsavefile.cpp
index 915d0a0a00..f41e6302a2 100644
--- a/src/corelib/io/qsavefile.cpp
+++ b/src/corelib/io/qsavefile.cpp
@@ -150,8 +150,7 @@ QSaveFile::~QSaveFile()
QFileDevice::close();
if (d->fileEngine) {
d->fileEngine->remove();
- delete d->fileEngine;
- d->fileEngine = nullptr;
+ d->fileEngine.reset();
}
}
@@ -197,6 +196,7 @@ bool QSaveFile::open(OpenMode mode)
return false;
}
unsetError();
+ d->writeError = QFileDevice::NoError;
if ((mode & (ReadOnly | WriteOnly)) == 0) {
qWarning("QSaveFile::open: Open mode not specified");
return false;
@@ -234,7 +234,7 @@ bool QSaveFile::open(OpenMode mode)
}
auto openDirectly = [&]() {
- d->fileEngine = QAbstractFileEngine::create(d->finalFileName);
+ d->fileEngine.reset(QAbstractFileEngine::create(d->finalFileName));
if (d->fileEngine->open(mode | QIODevice::Unbuffered)) {
d->useTemporaryFile = false;
QFileDevice::open(mode);
@@ -251,8 +251,7 @@ bool QSaveFile::open(OpenMode mode)
if (openDirectly())
return true;
d->setError(d->fileEngine->error(), d->fileEngine->errorString());
- delete d->fileEngine;
- d->fileEngine = nullptr;
+ d->fileEngine.reset();
} else {
QString msg =
QSaveFile::tr("QSaveFile cannot open '%1' without direct write fallback "
@@ -264,18 +263,17 @@ bool QSaveFile::open(OpenMode mode)
}
#endif
- d->fileEngine = new QTemporaryFileEngine(&d->finalFileName, QTemporaryFileEngine::Win32NonShared);
+ d->fileEngine.reset(new QTemporaryFileEngine(&d->finalFileName, QTemporaryFileEngine::Win32NonShared));
// if the target file exists, we'll copy its permissions below,
// but until then, let's ensure the temporary file is not accessible
// to a third party
int perm = (existingFile.exists() ? 0600 : 0666);
- static_cast<QTemporaryFileEngine *>(d->fileEngine)->initialize(d->finalFileName, perm);
+ static_cast<QTemporaryFileEngine *>(d->fileEngine.get())->initialize(d->finalFileName, perm);
// Same as in QFile: QIODevice provides the buffering, so there's no need to request it from the file engine.
if (!d->fileEngine->open(mode | QIODevice::Unbuffered)) {
QFileDevice::FileError err = d->fileEngine->error();
#ifdef Q_OS_UNIX
if (d->directWriteFallback && err == QFileDevice::OpenError && errno == EACCES) {
- delete d->fileEngine;
if (openDirectly())
return true;
err = d->fileEngine->error();
@@ -284,8 +282,7 @@ bool QSaveFile::open(OpenMode mode)
if (err == QFileDevice::UnspecifiedError)
err = QFileDevice::OpenError;
d->setError(err, d->fileEngine->errorString());
- delete d->fileEngine;
- d->fileEngine = nullptr;
+ d->fileEngine.reset();
return false;
}
@@ -331,30 +328,26 @@ bool QSaveFile::commit()
}
QFileDevice::close(); // calls flush()
+ const auto fe = std::move(d->fileEngine);
+
// Sync to disk if possible. Ignore errors (e.g. not supported).
- d->fileEngine->syncToDisk();
+ fe->syncToDisk();
if (d->useTemporaryFile) {
if (d->writeError != QFileDevice::NoError) {
- d->fileEngine->remove();
+ fe->remove();
d->writeError = QFileDevice::NoError;
- delete d->fileEngine;
- d->fileEngine = nullptr;
return false;
}
// atomically replace old file with new file
// Can't use QFile::rename for that, must use the file engine directly
- Q_ASSERT(d->fileEngine);
- if (!d->fileEngine->renameOverwrite(d->finalFileName)) {
- d->setError(d->fileEngine->error(), d->fileEngine->errorString());
- d->fileEngine->remove();
- delete d->fileEngine;
- d->fileEngine = nullptr;
+ Q_ASSERT(fe);
+ if (!fe->renameOverwrite(d->finalFileName)) {
+ d->setError(fe->error(), fe->errorString());
+ fe->remove();
return false;
}
}
- delete d->fileEngine;
- d->fileEngine = nullptr;
return true;
}
diff --git a/src/corelib/io/qstandardpaths.cpp b/src/corelib/io/qstandardpaths.cpp
index dbf650d5f6..f56fef7f8e 100644
--- a/src/corelib/io/qstandardpaths.cpp
+++ b/src/corelib/io/qstandardpaths.cpp
@@ -297,7 +297,7 @@ QT_BEGIN_NAMESPACE
\li "<APPROOT>/tmp"
\row \li HomeLocation
\li "<APPROOT>/files"
- \li "<APPROOT>" (not writable)
+ \li system defined
\row \li DataLocation
\li "<APPROOT>/files", "<USER>/<APPNAME>/files"
\li "<APPROOT>/Library/Application Support"
diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp
index f4f8787968..6425890e3f 100644
--- a/src/corelib/io/qstandardpaths_unix.cpp
+++ b/src/corelib/io/qstandardpaths_unix.cpp
@@ -71,6 +71,28 @@ static void appendOrganizationAndApp(QString &path)
#endif
}
+#if QT_CONFIG(regularexpression)
+static QLatin1String xdg_key_name(QStandardPaths::StandardLocation type)
+{
+ switch (type) {
+ case QStandardPaths::DesktopLocation:
+ return QLatin1String("DESKTOP");
+ case QStandardPaths::DocumentsLocation:
+ return QLatin1String("DOCUMENTS");
+ case QStandardPaths::PicturesLocation:
+ return QLatin1String("PICTURES");
+ case QStandardPaths::MusicLocation:
+ return QLatin1String("MUSIC");
+ case QStandardPaths::MoviesLocation:
+ return QLatin1String("VIDEOS");
+ case QStandardPaths::DownloadLocation:
+ return QLatin1String("DOWNLOAD");
+ default:
+ return QLatin1String();
+ }
+}
+#endif
+
QString QStandardPaths::writableLocation(StandardLocation type)
{
switch (type) {
@@ -182,61 +204,32 @@ QString QStandardPaths::writableLocation(StandardLocation type)
if (xdgConfigHome.isEmpty())
xdgConfigHome = QDir::homePath() + QLatin1String("/.config");
QFile file(xdgConfigHome + QLatin1String("/user-dirs.dirs"));
- if (!isTestModeEnabled() && file.open(QIODevice::ReadOnly)) {
- QHash<QString, QString> lines;
+ const QLatin1String key = xdg_key_name(type);
+ if (!key.isEmpty() && !isTestModeEnabled() && file.open(QIODevice::ReadOnly)) {
QTextStream stream(&file);
// Only look for lines like: XDG_DESKTOP_DIR="$HOME/Desktop"
QRegularExpression exp(QLatin1String("^XDG_(.*)_DIR=(.*)$"));
+ QString result;
while (!stream.atEnd()) {
const QString &line = stream.readLine();
QRegularExpressionMatch match = exp.match(line);
- if (match.hasMatch()) {
- const QStringList lst = match.capturedTexts();
- const QString key = lst.at(1);
- QString value = lst.at(2);
+ if (match.hasMatch() && match.capturedView(1) == key) {
+ QStringView value = match.capturedView(2);
if (value.length() > 2
&& value.startsWith(QLatin1Char('\"'))
&& value.endsWith(QLatin1Char('\"')))
value = value.mid(1, value.length() - 2);
- // Store the key and value: "DESKTOP", "$HOME/Desktop"
- lines[key] = value;
- }
- }
-
- QString key;
- switch (type) {
- case DesktopLocation:
- key = QLatin1String("DESKTOP");
- break;
- case DocumentsLocation:
- key = QLatin1String("DOCUMENTS");
- break;
- case PicturesLocation:
- key = QLatin1String("PICTURES");
- break;
- case MusicLocation:
- key = QLatin1String("MUSIC");
- break;
- case MoviesLocation:
- key = QLatin1String("VIDEOS");
- break;
- case DownloadLocation:
- key = QLatin1String("DOWNLOAD");
- break;
- default:
- break;
- }
- if (!key.isEmpty()) {
- QString value = lines.value(key);
- if (!value.isEmpty()) {
// value can start with $HOME
if (value.startsWith(QLatin1String("$HOME")))
- value = QDir::homePath() + value.midRef(5);
- if (value.length() > 1 && value.endsWith(QLatin1Char('/')))
- value.chop(1);
- return value;
+ result = QDir::homePath() + value.mid(5);
+ else
+ result = value.toString();
+ if (result.length() > 1 && result.endsWith(QLatin1Char('/')))
+ result.chop(1);
}
}
+ if (!result.isNull())
+ return result;
}
#endif // QT_CONFIG(regularexpression)
diff --git a/src/corelib/io/qstorageinfo_unix.cpp b/src/corelib/io/qstorageinfo_unix.cpp
index 4669c20711..1e72241e68 100644
--- a/src/corelib/io/qstorageinfo_unix.cpp
+++ b/src/corelib/io/qstorageinfo_unix.cpp
@@ -468,8 +468,18 @@ inline bool QStorageIterator::next()
size_t len = strlen(buffer.data());
if (len == 0)
return false;
- if (ptr[len - 1] == '\n')
- ptr[len - 1] = '\0';
+ while (Q_UNLIKELY(ptr[len - 1] != '\n' && !feof(fp))) {
+ // buffer wasn't large enough. Enlarge and try again.
+ // (we're readidng from the kernel, so OOM is unlikely)
+ buffer.resize((buffer.size() + 4096) & ~4095);
+ ptr = buffer.data();
+ if (fgets(ptr + len, buffer.size() - len, fp) == nullptr)
+ return false;
+
+ len += strlen(ptr + len);
+ Q_ASSERT(len < size_t(buffer.size()));
+ }
+ ptr[len - 1] = '\0';
// parse the line
bool ok;
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index c89ad06a1f..acd31f4d84 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -544,10 +544,10 @@ QTemporaryFilePrivate::~QTemporaryFilePrivate()
QAbstractFileEngine *QTemporaryFilePrivate::engine() const
{
if (!fileEngine) {
- fileEngine = new QTemporaryFileEngine(&templateName);
+ fileEngine.reset(new QTemporaryFileEngine(&templateName));
resetFileEngine();
}
- return fileEngine;
+ return fileEngine.get();
}
void QTemporaryFilePrivate::resetFileEngine() const
@@ -555,7 +555,7 @@ void QTemporaryFilePrivate::resetFileEngine() const
if (!fileEngine)
return;
- QTemporaryFileEngine *tef = static_cast<QTemporaryFileEngine *>(fileEngine);
+ QTemporaryFileEngine *tef = static_cast<QTemporaryFileEngine *>(fileEngine.get());
if (fileName.isEmpty())
tef->initialize(templateName, 0600);
else
@@ -568,7 +568,7 @@ void QTemporaryFilePrivate::materializeUnnamedFile()
if (!fileName.isEmpty() || !fileEngine)
return;
- auto *tef = static_cast<QTemporaryFileEngine *>(fileEngine);
+ auto *tef = static_cast<QTemporaryFileEngine *>(fileEngine.get());
fileName = tef->fileName(QAbstractFileEngine::DefaultName);
#endif
}
@@ -792,7 +792,7 @@ void QTemporaryFile::setAutoRemove(bool b)
QString QTemporaryFile::fileName() const
{
Q_D(const QTemporaryFile);
- auto tef = static_cast<QTemporaryFileEngine *>(d->fileEngine);
+ auto tef = static_cast<QTemporaryFileEngine *>(d->fileEngine.get());
if (tef && tef->isReallyOpen())
const_cast<QTemporaryFilePrivate *>(d)->materializeUnnamedFile();
@@ -841,7 +841,7 @@ void QTemporaryFile::setFileTemplate(const QString &name)
bool QTemporaryFile::rename(const QString &newName)
{
Q_D(QTemporaryFile);
- auto tef = static_cast<QTemporaryFileEngine *>(d->fileEngine);
+ auto tef = static_cast<QTemporaryFileEngine *>(d->fileEngine.get());
if (!tef || !tef->isReallyOpen() || !tef->filePathWasTemplate)
return QFile::rename(newName);
@@ -947,7 +947,7 @@ QTemporaryFile *QTemporaryFile::createNativeFile(QFile &file)
bool QTemporaryFile::open(OpenMode flags)
{
Q_D(QTemporaryFile);
- auto tef = static_cast<QTemporaryFileEngine *>(d->fileEngine);
+ auto tef = static_cast<QTemporaryFileEngine *>(d->fileEngine.get());
if (tef && tef->isReallyOpen()) {
setOpenMode(flags);
return true;
@@ -961,7 +961,7 @@ bool QTemporaryFile::open(OpenMode flags)
d->resetFileEngine();
if (QFile::open(flags)) {
- tef = static_cast<QTemporaryFileEngine *>(d->fileEngine);
+ tef = static_cast<QTemporaryFileEngine *>(d->fileEngine.get());
if (tef->isUnnamedFile())
d->fileName.clear();
else
diff --git a/src/corelib/io/qtldurl.cpp b/src/corelib/io/qtldurl.cpp
index a934d19fa2..912609ec91 100644
--- a/src/corelib/io/qtldurl.cpp
+++ b/src/corelib/io/qtldurl.cpp
@@ -59,9 +59,9 @@ enum TLDMatchType {
static bool containsTLDEntry(QStringView entry, TLDMatchType match)
{
const QStringView matchSymbols[] = {
- QStringViewLiteral(""),
- QStringViewLiteral("*"),
- QStringViewLiteral("!"),
+ u"",
+ u"*",
+ u"!",
};
const auto symbol = matchSymbols[match];
int index = qt_hash(entry, qt_hash(symbol)) % tldCount;
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index d9ebc6c750..878e007fb0 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -1010,7 +1010,7 @@ inline bool QUrlPrivate::setScheme(const QString &value, int len, bool doSetErro
for (int i = needsLowercasing; i >= 0; --i) {
ushort c = schemeData[i].unicode();
if (c >= 'A' && c <= 'Z')
- schemeData[i] = c + 0x20;
+ schemeData[i] = QChar(c + 0x20);
}
}
diff --git a/src/corelib/io/qurlidna.cpp b/src/corelib/io/qurlidna.cpp
index 2f89d22660..a2f0caa606 100644
--- a/src/corelib/io/qurlidna.cpp
+++ b/src/corelib/io/qurlidna.cpp
@@ -2220,9 +2220,8 @@ Q_AUTOTEST_EXPORT void qt_punycodeEncoder(const QChar *s, int ucLength, QString
bool skipped = false;
// copy all basic code points verbatim to output.
for (uint j = 0; j < (uint) ucLength; ++j) {
- ushort js = s[j].unicode();
- if (js < 0x80)
- *d++ = js;
+ if (s[j].unicode() < 0x80)
+ *d++ = s[j];
else
skipped = true;
}
diff --git a/src/corelib/io/qurlquery.cpp b/src/corelib/io/qurlquery.cpp
index 36a2880bf1..8d80a2d8bd 100644
--- a/src/corelib/io/qurlquery.cpp
+++ b/src/corelib/io/qurlquery.cpp
@@ -146,7 +146,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn QUrlQuery(std::initializer_list<QPair<QString, QString>> list)
+ \fn QUrlQuery::QUrlQuery(std::initializer_list<QPair<QString, QString>> list)
\since 5.13
@@ -293,9 +293,9 @@ void QUrlQueryPrivate::setQuery(const QString &query)
const QChar *delimiter = nullptr;
while (pos != end) {
// scan for the component parts of this pair
- if (!delimiter && pos->unicode() == valueDelimiter)
+ if (!delimiter && *pos == valueDelimiter)
delimiter = pos;
- if (pos->unicode() == pairDelimiter)
+ if (*pos == pairDelimiter)
break;
++pos;
}
@@ -584,8 +584,8 @@ QString QUrlQuery::query(QUrl::ComponentFormattingOptions encoding) const
*/
void QUrlQuery::setQueryDelimiters(QChar valueDelimiter, QChar pairDelimiter)
{
- d->valueDelimiter = valueDelimiter.unicode();
- d->pairDelimiter = pairDelimiter.unicode();
+ d->valueDelimiter = valueDelimiter;
+ d->pairDelimiter = pairDelimiter;
}
/*!
diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp
index 2eacb3cc94..e19d9479f8 100644
--- a/src/corelib/itemmodels/qabstractitemmodel.cpp
+++ b/src/corelib/itemmodels/qabstractitemmodel.cpp
@@ -532,21 +532,16 @@ void QAbstractItemModelPrivate::invalidatePersistentIndex(const QModelIndex &ind
}
}
-namespace {
- struct DefaultRoleNames : public QHash<int, QByteArray>
+using DefaultRoleNames = QHash<int, QByteArray>;
+Q_GLOBAL_STATIC_WITH_ARGS(DefaultRoleNames, qDefaultRoleNames, (
{
- DefaultRoleNames() {
- (*this)[Qt::DisplayRole] = "display";
- (*this)[Qt::DecorationRole] = "decoration";
- (*this)[Qt::EditRole] = "edit";
- (*this)[Qt::ToolTipRole] = "toolTip";
- (*this)[Qt::StatusTipRole] = "statusTip";
- (*this)[Qt::WhatsThisRole] = "whatsThis";
- }
- };
-}
-
-Q_GLOBAL_STATIC(DefaultRoleNames, qDefaultRoleNames)
+ { Qt::DisplayRole, "display" },
+ { Qt::DecorationRole, "decoration" },
+ { Qt::EditRole, "edit" },
+ { Qt::ToolTipRole, "toolTip" },
+ { Qt::StatusTipRole, "statusTip" },
+ { Qt::WhatsThisRole, "whatsThis" },
+ }))
const QHash<int,QByteArray> &QAbstractItemModelPrivate::defaultRoleNames()
{
diff --git a/src/corelib/itemmodels/qsortfilterproxymodel.cpp b/src/corelib/itemmodels/qsortfilterproxymodel.cpp
index d13e6199db..675bf4b8c3 100644
--- a/src/corelib/itemmodels/qsortfilterproxymodel.cpp
+++ b/src/corelib/itemmodels/qsortfilterproxymodel.cpp
@@ -64,11 +64,7 @@ struct QSortFilterProxyModelDataChanged
static inline QSet<int> qVectorToSet(const QVector<int> &vector)
{
- QSet<int> set;
- set.reserve(vector.size());
- for(int i=0; i < vector.size(); ++i)
- set << vector.at(i);
- return set;
+ return {vector.begin(), vector.end()};
}
class QSortFilterProxyModelLessThan
@@ -130,7 +126,7 @@ struct QRowsRemoval
{
}
- bool contains(QModelIndex parent, int row)
+ bool contains(QModelIndex parent, int row) const
{
do {
if (parent == parent_source)
@@ -470,8 +466,8 @@ bool QSortFilterProxyModelPrivate::filterRecursiveAcceptsRow(int source_row, con
void QSortFilterProxyModelPrivate::remove_from_mapping(const QModelIndex &source_parent)
{
if (Mapping *m = source_index_mapping.take(source_parent)) {
- for (int i = 0; i < m->mapped_children.size(); ++i)
- remove_from_mapping(m->mapped_children.at(i));
+ for (const QModelIndex &mappedIdx : qAsConst(m->mapped_children))
+ remove_from_mapping(mappedIdx);
delete m;
}
}
@@ -607,9 +603,9 @@ void QSortFilterProxyModelPrivate::sort()
Q_Q(QSortFilterProxyModel);
emit q->layoutAboutToBeChanged(QList<QPersistentModelIndex>(), QAbstractItemModel::VerticalSortHint);
QModelIndexPairList source_indexes = store_persistent_indexes();
- IndexMap::const_iterator it = source_index_mapping.constBegin();
- for (; it != source_index_mapping.constEnd(); ++it) {
- QModelIndex source_parent = it.key();
+ const auto end = source_index_mapping.constEnd();
+ for (auto it = source_index_mapping.constBegin(); it != end; ++it) {
+ const QModelIndex &source_parent = it.key();
Mapping *m = it.value();
sort_source_rows(m->source_rows, source_parent);
build_source_to_proxy_mapping(m->source_rows, m->proxy_rows);
@@ -735,13 +731,14 @@ void QSortFilterProxyModelPrivate::remove_source_items(
if (!proxy_parent.isValid() && source_parent.isValid())
return; // nothing to do (already removed)
- QVector<QPair<int, int> > proxy_intervals;
- proxy_intervals = proxy_intervals_for_source_items(source_to_proxy, source_items);
+ const auto proxy_intervals = proxy_intervals_for_source_items(
+ source_to_proxy, source_items);
- for (int i = proxy_intervals.size()-1; i >= 0; --i) {
- QPair<int, int> interval = proxy_intervals.at(i);
- int proxy_start = interval.first;
- int proxy_end = interval.second;
+ const auto end = proxy_intervals.rend();
+ for (auto it = proxy_intervals.rbegin(); it != end; ++it) {
+ const QPair<int, int> &interval = *it;
+ const int proxy_start = interval.first;
+ const int proxy_end = interval.second;
remove_proxy_interval(source_to_proxy, proxy_to_source, proxy_start, proxy_end,
proxy_parent, orient, emit_signal);
}
@@ -875,15 +872,15 @@ void QSortFilterProxyModelPrivate::insert_source_items(
if (!proxy_parent.isValid() && source_parent.isValid())
return; // nothing to do (source_parent is not mapped)
- QVector<QPair<int, QVector<int> > > proxy_intervals;
- proxy_intervals = proxy_intervals_for_source_items_to_add(
+ const auto proxy_intervals = proxy_intervals_for_source_items_to_add(
proxy_to_source, source_items, source_parent, orient);
- for (int i = proxy_intervals.size()-1; i >= 0; --i) {
- QPair<int, QVector<int> > interval = proxy_intervals.at(i);
- int proxy_start = interval.first;
- QVector<int> source_items = interval.second;
- int proxy_end = proxy_start + source_items.size() - 1;
+ const auto end = proxy_intervals.rend();
+ for (auto it = proxy_intervals.rbegin(); it != end; ++it) {
+ const QPair<int, QVector<int> > &interval = *it;
+ const int proxy_start = interval.first;
+ const QVector<int> &source_items = interval.second;
+ const int proxy_end = proxy_start + source_items.size() - 1;
if (emit_signal) {
if (orient == Qt::Vertical)
@@ -1195,8 +1192,8 @@ QModelIndexPairList QSortFilterProxyModelPrivate::store_persistent_indexes() con
Q_Q(const QSortFilterProxyModel);
QModelIndexPairList source_indexes;
source_indexes.reserve(persistent.indexes.count());
- for (QPersistentModelIndexData *data : qAsConst(persistent.indexes)) {
- QModelIndex proxy_index = data->index;
+ for (const QPersistentModelIndexData *data : qAsConst(persistent.indexes)) {
+ const QModelIndex &proxy_index = data->index;
QModelIndex source_index = q->mapToSource(proxy_index);
source_indexes.append(qMakePair(proxy_index, QPersistentModelIndex(source_index)));
}
@@ -1217,9 +1214,9 @@ void QSortFilterProxyModelPrivate::update_persistent_indexes(
const int numSourceIndexes = source_indexes.count();
from.reserve(numSourceIndexes);
to.reserve(numSourceIndexes);
- for (int i = 0; i < numSourceIndexes; ++i) {
- QModelIndex source_index = source_indexes.at(i).second;
- QModelIndex old_proxy_index = source_indexes.at(i).first;
+ for (const auto &indexPair : source_indexes) {
+ const QPersistentModelIndex &source_index = indexPair.second;
+ const QModelIndex &old_proxy_index = indexPair.first;
create_mapping(source_index.parent());
QModelIndex proxy_index = q->mapFromSource(source_index);
from << old_proxy_index;
@@ -1264,7 +1261,7 @@ void QSortFilterProxyModelPrivate::filter_changed(const QModelIndex &source_pare
const QVector<QModelIndex> mappedChildren = m->mapped_children;
QVector<int> indexesToRemove;
for (int i = 0; i < mappedChildren.size(); ++i) {
- const QModelIndex source_child_index = mappedChildren.at(i);
+ const QModelIndex &source_child_index = mappedChildren.at(i);
if (rows_removed.contains(source_child_index.row()) || columns_removed.contains(source_child_index.column())) {
indexesToRemove.push_back(i);
remove_from_mapping(source_child_index);
@@ -2296,10 +2293,9 @@ QMimeData *QSortFilterProxyModel::mimeData(const QModelIndexList &indexes) const
{
Q_D(const QSortFilterProxyModel);
QModelIndexList source_indexes;
- const int numIndexes = indexes.count();
- source_indexes.reserve(numIndexes);
- for (int i = 0; i < numIndexes; ++i)
- source_indexes << mapToSource(indexes.at(i));
+ source_indexes.reserve(indexes.count());
+ for (const QModelIndex &idx : indexes)
+ source_indexes << mapToSource(idx);
return d->model->mimeData(source_indexes);
}
diff --git a/src/corelib/kernel/qcore_mac_objc.mm b/src/corelib/kernel/qcore_mac_objc.mm
index 15b69acbd4..9e9e71c397 100644
--- a/src/corelib/kernel/qcore_mac_objc.mm
+++ b/src/corelib/kernel/qcore_mac_objc.mm
@@ -514,10 +514,9 @@ Q_CONSTRUCTOR_FUNCTION(qt_apple_check_os_version);
// -------------------------------------------------------------------------
-void QMacKeyValueObserver::addObserver()
+void QMacKeyValueObserver::addObserver(NSKeyValueObservingOptions options)
{
- [object addObserver:observer forKeyPath:keyPath
- options:NSKeyValueObservingOptionNew context:callback.get()];
+ [object addObserver:observer forKeyPath:keyPath options:options context:callback.get()];
}
void QMacKeyValueObserver::removeObserver() {
diff --git a/src/corelib/kernel/qcore_mac_p.h b/src/corelib/kernel/qcore_mac_p.h
index 0e1a5fe345..447dcd9cbe 100644
--- a/src/corelib/kernel/qcore_mac_p.h
+++ b/src/corelib/kernel/qcore_mac_p.h
@@ -350,8 +350,12 @@ public:
QMacKeyValueObserver() {}
// Note: QMacKeyValueObserver must not outlive the object observed!
- QMacKeyValueObserver(id object, NSString *keyPath, Callback callback)
- : object(object), keyPath(keyPath), callback(new Callback(callback)) { addObserver(); }
+ QMacKeyValueObserver(id object, NSString *keyPath, Callback callback,
+ NSKeyValueObservingOptions options = NSKeyValueObservingOptionNew)
+ : object(object), keyPath(keyPath), callback(new Callback(callback))
+ {
+ addObserver(options);
+ }
QMacKeyValueObserver(const QMacKeyValueObserver &other)
: QMacKeyValueObserver(other.object, other.keyPath, *other.callback.get()) {}
@@ -381,7 +385,7 @@ private:
std::swap(first.callback, second.callback);
}
- void addObserver();
+ void addObserver(NSKeyValueObservingOptions options);
id object = nil;
NSString *keyPath = nullptr;
diff --git a/src/corelib/kernel/qeventdispatcher_winrt_p.h b/src/corelib/kernel/qeventdispatcher_winrt_p.h
index 8b998a7958..2672f11123 100644
--- a/src/corelib/kernel/qeventdispatcher_winrt_p.h
+++ b/src/corelib/kernel/qeventdispatcher_winrt_p.h
@@ -57,7 +57,7 @@
#include <qt_windows.h>
-namespace std { template <typename T> class function; }
+#include <functional>
QT_BEGIN_NAMESPACE
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp
index 56217262f2..acb1f54bdf 100644
--- a/src/corelib/kernel/qmetaobject.cpp
+++ b/src/corelib/kernel/qmetaobject.cpp
@@ -953,7 +953,7 @@ static const QMetaObject *QMetaObject_findMetaObject(const QMetaObject *self, co
return self;
if (self->d.relatedMetaObjects) {
Q_ASSERT(priv(self->d.data)->revision >= 2);
- const QMetaObject * const *e = self->d.relatedMetaObjects;
+ const auto *e = self->d.relatedMetaObjects;
if (e) {
while (*e) {
if (const QMetaObject *m =QMetaObject_findMetaObject((*e), name))
diff --git a/src/corelib/kernel/qmetaobjectbuilder.cpp b/src/corelib/kernel/qmetaobjectbuilder.cpp
index d2030f0275..f77c4ce32f 100644
--- a/src/corelib/kernel/qmetaobjectbuilder.cpp
+++ b/src/corelib/kernel/qmetaobjectbuilder.cpp
@@ -747,7 +747,7 @@ void QMetaObjectBuilder::addMetaObject
if ((members & RelatedMetaObjects) != 0) {
Q_ASSERT(priv(prototype->d.data)->revision >= 2);
- const QMetaObject * const *objects = prototype->d.relatedMetaObjects;
+ const auto *objects = prototype->d.relatedMetaObjects;
if (objects) {
while (*objects != 0) {
addRelatedMetaObject(*objects);
@@ -1464,16 +1464,16 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
// Create the relatedMetaObjects block if we need one.
if (d->relatedMetaObjects.size() > 0) {
- ALIGN(size, QMetaObject *);
- const QMetaObject **objects =
- reinterpret_cast<const QMetaObject **>(buf + size);
+ using SuperData = QMetaObject::SuperData;
+ ALIGN(size, SuperData);
+ auto objects = reinterpret_cast<SuperData *>(buf + size);
if (buf) {
meta->d.relatedMetaObjects = objects;
for (index = 0; index < d->relatedMetaObjects.size(); ++index)
objects[index] = d->relatedMetaObjects[index];
- objects[index] = 0;
+ objects[index] = nullptr;
}
- size += sizeof(QMetaObject *) * (d->relatedMetaObjects.size() + 1);
+ size += sizeof(SuperData) * (d->relatedMetaObjects.size() + 1);
}
// Align the final size and return it.
diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h
index a97764ede4..44cce73359 100644
--- a/src/corelib/kernel/qmetatype.h
+++ b/src/corelib/kernel/qmetatype.h
@@ -216,7 +216,7 @@ inline Q_DECL_CONSTEXPR int qMetaTypeId();
F(QQueue) \
F(QStack) \
F(QSet) \
- F(QLinkedList)
+ /*end*/
#define QT_FOR_EACH_AUTOMATIC_TEMPLATE_2ARG(F) \
F(QHash, class) \
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 5c1ae8aa43..d364ae1087 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -93,12 +93,6 @@ QAbstractDynamicMetaObject::~QAbstractDynamicMetaObject()
{
}
-
-struct QSlotObjectBaseDeleter { // for use with QScopedPointer<QSlotObjectBase,...>
- static void cleanup(QtPrivate::QSlotObjectBase *slot) {
- if (slot) slot->destroyIfLastRef();
- }
-};
static int *queuedConnectionTypes(const QList<QByteArray> &typeNames)
{
int *types = new int [typeNames.count() + 1];
@@ -3380,7 +3374,7 @@ QObjectPrivate::Connection *QMetaObjectPrivate::connect(const QObject *sender,
type &= Qt::UniqueConnection - 1;
}
- QScopedPointer<QObjectPrivate::Connection> c(new QObjectPrivate::Connection);
+ std::unique_ptr<QObjectPrivate::Connection> c{new QObjectPrivate::Connection};
c->sender = s;
c->signal_index = signal_index;
c->receiver.storeRelaxed(r);
@@ -3394,14 +3388,14 @@ QObjectPrivate::Connection *QMetaObjectPrivate::connect(const QObject *sender,
c->argumentTypes.storeRelaxed(types);
c->callFunction = callFunction;
- QObjectPrivate::get(s)->addConnection(signal_index, c.data());
+ QObjectPrivate::get(s)->addConnection(signal_index, c.get());
locker.unlock();
QMetaMethod smethod = QMetaObjectPrivate::signal(smeta, signal_index);
if (smethod.isValid())
s->connectNotify(smethod);
- return c.take();
+ return c.release();
}
/*!
@@ -3791,10 +3785,16 @@ void doActivate(QObject *sender, int signal_index, void **argv)
if (c->isSlotObject) {
c->slotObj->ref();
- QScopedPointer<QtPrivate::QSlotObjectBase, QSlotObjectBaseDeleter> obj(c->slotObj);
+
+ struct Deleter {
+ void operator()(QtPrivate::QSlotObjectBase *slot) const {
+ if (slot) slot->destroyIfLastRef();
+ }
+ };
+ const std::unique_ptr<QtPrivate::QSlotObjectBase, Deleter> obj{c->slotObj};
{
- Q_TRACE_SCOPE(QMetaObject_activate_slot_functor, obj.data());
+ Q_TRACE_SCOPE(QMetaObject_activate_slot_functor, obj.get());
obj->call(receiver, argv);
}
} else if (c->callFunction && c->method_offset <= receiver->metaObject()->methodOffset()) {
@@ -4947,7 +4947,7 @@ QMetaObject::Connection QObjectPrivate::connectImpl(const QObject *sender, int s
type = static_cast<Qt::ConnectionType>(type ^ Qt::UniqueConnection);
}
- QScopedPointer<QObjectPrivate::Connection> c(new QObjectPrivate::Connection);
+ std::unique_ptr<QObjectPrivate::Connection> c{new QObjectPrivate::Connection};
c->sender = s;
c->signal_index = signal_index;
QThreadData *td = r->d_func()->threadData;
@@ -4962,8 +4962,8 @@ QMetaObject::Connection QObjectPrivate::connectImpl(const QObject *sender, int s
c->ownArgumentTypes = false;
}
- QObjectPrivate::get(s)->addConnection(signal_index, c.data());
- QMetaObject::Connection ret(c.take());
+ QObjectPrivate::get(s)->addConnection(signal_index, c.get());
+ QMetaObject::Connection ret(c.release());
locker.unlock();
QMetaMethod method = QMetaObjectPrivate::signal(senderMetaObject, signal_index);
diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h
index 9cf1bfed08..95ffc1b2e8 100644
--- a/src/corelib/kernel/qobject_p.h
+++ b/src/corelib/kernel/qobject_p.h
@@ -486,8 +486,11 @@ class Q_CORE_EXPORT QAbstractMetaCallEvent : public QEvent
{
public:
QAbstractMetaCallEvent(const QObject *sender, int signalId, QSemaphore *semaphore = nullptr)
- : QEvent(MetaCall), signalId_(signalId), sender_(sender), semaphore_(semaphore)
- {}
+ : QEvent(MetaCall), signalId_(signalId), sender_(sender)
+#if QT_CONFIG(thread)
+ , semaphore_(semaphore)
+#endif
+ { Q_UNUSED(semaphore); }
~QAbstractMetaCallEvent();
virtual void placeMetaCall(QObject *object) = 0;
@@ -498,7 +501,9 @@ public:
private:
int signalId_;
const QObject *sender_;
+#if QT_CONFIG(thread)
QSemaphore *semaphore_;
+#endif
};
class Q_CORE_EXPORT QMetaCallEvent : public QAbstractMetaCallEvent
diff --git a/src/corelib/kernel/qobjectdefs.h b/src/corelib/kernel/qobjectdefs.h
index ef22b6e67f..dc2d832fe5 100644
--- a/src/corelib/kernel/qobjectdefs.h
+++ b/src/corelib/kernel/qobjectdefs.h
@@ -1,7 +1,7 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
+** Copyright (C) 2019 The Qt Company Ltd.
+** Copyright (C) 2019 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -572,13 +572,42 @@ struct Q_CORE_EXPORT QMetaObject
int static_metacall(Call, int, void **) const;
static int metacall(QObject *, Call, int, void **);
+ template <const QMetaObject &MO> static constexpr const QMetaObject *staticMetaObject()
+ {
+ return &MO;
+ }
+
+ struct SuperData {
+ const QMetaObject *direct;
+ SuperData() = default;
+ constexpr SuperData(std::nullptr_t) : direct(nullptr) {}
+ constexpr SuperData(const QMetaObject *mo) : direct(mo) {}
+
+ constexpr const QMetaObject *operator->() const { return operator const QMetaObject *(); }
+
+#ifdef QT_NO_DATA_RELOCATION
+ using Getter = const QMetaObject *(*)();
+ Getter indirect = nullptr;
+ constexpr SuperData(Getter g) : direct(nullptr), indirect(g) {}
+ constexpr operator const QMetaObject *() const
+ { return indirect ? indirect() : direct; }
+ template <const QMetaObject &MO> static constexpr SuperData link()
+ { return SuperData(QMetaObject::staticMetaObject<MO>); }
+#else
+ constexpr operator const QMetaObject *() const
+ { return direct; }
+ template <const QMetaObject &MO> static constexpr SuperData link()
+ { return SuperData(QMetaObject::staticMetaObject<MO>()); }
+#endif
+ };
+
struct { // private data
- const QMetaObject *superdata;
+ SuperData superdata;
const QByteArrayData *stringdata;
const uint *data;
typedef void (*StaticMetacallFunction)(QObject *, QMetaObject::Call, int, void **);
StaticMetacallFunction static_metacall;
- const QMetaObject * const *relatedMetaObjects;
+ const SuperData *relatedMetaObjects;
void *extradata; //reserved for future use
} d;
diff --git a/src/corelib/kernel/qsignalmapper.cpp b/src/corelib/kernel/qsignalmapper.cpp
index 34fea861cd..24b174972f 100644
--- a/src/corelib/kernel/qsignalmapper.cpp
+++ b/src/corelib/kernel/qsignalmapper.cpp
@@ -38,7 +38,6 @@
****************************************************************************/
#include "qglobal.h"
-#if QT_DEPRECATED_SINCE(5, 10)
#include "qsignalmapper.h"
#include "qhash.h"
@@ -64,7 +63,6 @@ public:
/*!
\class QSignalMapper
\inmodule QtCore
- \obsolete The recommended solution is connecting the signal to a lambda.
\brief The QSignalMapper class bundles signals from identifiable senders.
\ingroup objectmodel
@@ -72,7 +70,9 @@ public:
This class collects a set of parameterless signals, and re-emits
them with integer, string or widget parameters corresponding to
- the object that sent the signal.
+ the object that sent the signal. Note that in most cases you can
+ use lambdas for passing custom parameters to slots. This is less
+ costly and will simplify the code.
The class supports the mapping of particular strings or integers
with particular objects using setMapping(). The objects' signals
@@ -314,5 +314,3 @@ void QSignalMapper::map(QObject *sender)
QT_END_NAMESPACE
#include "moc_qsignalmapper.cpp"
-
-#endif
diff --git a/src/corelib/kernel/qsignalmapper.h b/src/corelib/kernel/qsignalmapper.h
index 6c4cfa9627..0da1e8f87d 100644
--- a/src/corelib/kernel/qsignalmapper.h
+++ b/src/corelib/kernel/qsignalmapper.h
@@ -42,8 +42,6 @@
#include <QtCore/qobject.h>
-#if QT_DEPRECATED_SINCE(5, 10)
-
QT_BEGIN_NAMESPACE
class QSignalMapperPrivate;
@@ -53,7 +51,7 @@ class Q_CORE_EXPORT QSignalMapper : public QObject
Q_OBJECT
Q_DECLARE_PRIVATE(QSignalMapper)
public:
- QT_DEPRECATED explicit QSignalMapper(QObject *parent = nullptr);
+ explicit QSignalMapper(QObject *parent = nullptr);
~QSignalMapper();
void setMapping(QObject *sender, int id);
@@ -84,6 +82,4 @@ private:
QT_END_NAMESPACE
-#endif
-
#endif // QSIGNALMAPPER_H
diff --git a/src/corelib/kernel/qtranslator.cpp b/src/corelib/kernel/qtranslator.cpp
index 637ef84d21..ddb96ecad6 100644
--- a/src/corelib/kernel/qtranslator.cpp
+++ b/src/corelib/kernel/qtranslator.cpp
@@ -528,7 +528,8 @@ bool QTranslatorPrivate::do_load(const QString &realname, const QString &directo
// memory, so no need to use QFile to copy it again.
Q_ASSERT(!d->resource);
d->resource = new QResource(realname);
- if (resource->isValid() && !resource->isCompressed() && resource->size() >= MagicLength
+ if (resource->isValid() && resource->compressionAlgorithm() == QResource::NoCompression
+ && resource->size() >= MagicLength
&& !memcmp(resource->data(), magic, MagicLength)) {
d->unmapLength = resource->size();
d->unmapPointer = reinterpret_cast<char *>(const_cast<uchar *>(resource->data()));
diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h
index c8cb551863..39b7e4c0ce 100644
--- a/src/corelib/kernel/qvariant.h
+++ b/src/corelib/kernel/qvariant.h
@@ -362,7 +362,7 @@ class Q_CORE_EXPORT QVariant
static inline QVariant fromValue(const T &value)
{ return QVariant(qMetaTypeId<T>(), &value, QTypeInfo<T>::isPointer); }
-#if QT_HAS_INCLUDE(<variant>) && __cplusplus >= 201703L
+#if (QT_HAS_INCLUDE(<variant>) && __cplusplus >= 201703L) || defined(Q_CLANG_QDOC)
template<typename... Types>
static inline QVariant fromStdVariant(const std::variant<Types...> &value)
{
diff --git a/src/corelib/plugin/qpluginloader.cpp b/src/corelib/plugin/qpluginloader.cpp
index 00480198bd..4e0c3a511b 100644
--- a/src/corelib/plugin/qpluginloader.cpp
+++ b/src/corelib/plugin/qpluginloader.cpp
@@ -92,7 +92,7 @@ QT_BEGIN_NAMESPACE
but if other instances of QPluginLoader are using the same
library, the call will fail, and unloading will only happen when
every instance has called unload(). Right before the unloading
- happen, the root component will also be deleted.
+ happens, the root component will also be deleted.
See \l{How to Create Qt Plugins} for more information about
how to make your application extensible through plugins.
diff --git a/src/corelib/serialization/qcborarray.cpp b/src/corelib/serialization/qcborarray.cpp
index 28ae40f3df..ca0156e07d 100644
--- a/src/corelib/serialization/qcborarray.cpp
+++ b/src/corelib/serialization/qcborarray.cpp
@@ -273,7 +273,7 @@ QCborValue QCborArray::at(qsizetype i) const
not be empty.
QCborValueRef has the exact same API as \l QCborValue, with one important
- difference: if you assign new values to it, this map will be updated with
+ difference: if you assign new values to it, this array will be updated with
that new value.
\sa operator[](), at(), last(), insert(), prepend(), append(),
@@ -287,7 +287,7 @@ QCborValue QCborArray::at(qsizetype i) const
not be empty.
QCborValueRef has the exact same API as \l QCborValue, with one important
- difference: if you assign new values to it, this map will be updated with
+ difference: if you assign new values to it, this array will be updated with
that new value.
\sa operator[](), at(), first(), insert(), prepend(), append(),
@@ -302,7 +302,7 @@ QCborValue QCborArray::at(qsizetype i) const
with undefined entries, until it has an entry at the specified index.
QCborValueRef has the exact same API as \l QCborValue, with one important
- difference: if you assign new values to it, this map will be updated with
+ difference: if you assign new values to it, this array will be updated with
that new value.
\sa at(), first(), last(), insert(), prepend(), append(),
diff --git a/src/corelib/serialization/qcborstream.cpp b/src/corelib/serialization/qcborstream.cpp
index 078c14a32d..c598eee213 100644
--- a/src/corelib/serialization/qcborstream.cpp
+++ b/src/corelib/serialization/qcborstream.cpp
@@ -1972,7 +1972,15 @@ inline void QCborStreamReader::preparse()
if (lastError() == QCborError::NoError) {
type_ = cbor_value_get_type(&d->currentElement);
- if (type_ != CborInvalidType) {
+ if (type_ == CborInvalidType) {
+ // We may have reached the end.
+ if (d->device && d->containerStack.isEmpty()) {
+ d->buffer.clear();
+ if (d->bufferStart)
+ d->device->skip(d->bufferStart);
+ d->bufferStart = 0;
+ }
+ } else {
d->lastError = {};
// Undo the type mapping that TinyCBOR does (we have an explicit type
// for negative integer and we don't have separate types for Boolean,
diff --git a/src/corelib/serialization/qjson.cpp b/src/corelib/serialization/qjson.cpp
index d74ffb2a20..76f1eae1ce 100644
--- a/src/corelib/serialization/qjson.cpp
+++ b/src/corelib/serialization/qjson.cpp
@@ -175,7 +175,7 @@ void Base::removeItems(int pos, int numItems)
length -= numItems;
}
-int Object::indexOf(const QString &key, bool *exists) const
+int Object::indexOf(QStringView key, bool *exists) const
{
int min = 0;
int n = length;
@@ -257,7 +257,7 @@ bool Array::isValid(int maxSize) const
}
-bool Entry::operator ==(const QString &key) const
+bool Entry::operator ==(QStringView key) const
{
if (value.latinKey)
return (shallowLatin1Key() == key);
@@ -270,7 +270,7 @@ bool Entry::operator==(QLatin1String key) const
if (value.latinKey)
return shallowLatin1Key() == key;
else
- return shallowKey() == key;
+ return shallowKey() == QString(key); // ### conversion to QString
}
bool Entry::operator ==(const Entry &other) const
diff --git a/src/corelib/serialization/qjson_p.h b/src/corelib/serialization/qjson_p.h
index 9de53d5b74..7978bed7da 100644
--- a/src/corelib/serialization/qjson_p.h
+++ b/src/corelib/serialization/qjson_p.h
@@ -66,11 +66,13 @@
#include <limits.h>
#include <limits>
+#include <type_traits>
QT_BEGIN_NAMESPACE
// in qstring.cpp
void qt_to_latin1_unchecked(uchar *dst, const ushort *uc, qsizetype len);
+void qt_from_latin1(ushort *dst, const char *str, size_t size) noexcept;
/*
This defines a binary data structure for Json data. The data structure is optimised for fast reading
@@ -153,16 +155,24 @@ typedef qle_uint offset;
// round the size up to the next 4 byte boundary
inline int alignedSize(int size) { return (size + 3) & ~3; }
-static inline bool useCompressed(const QString &s)
+const int MaxLatin1Length = 0x7fff;
+
+static inline bool useCompressed(QStringView s)
{
- if (s.length() >= 0x8000)
+ if (s.length() > MaxLatin1Length)
return false;
return QtPrivate::isLatin1(s);
}
-static inline int qStringSize(const QString &string, bool compress)
+static inline bool useCompressed(QLatin1String s)
+{
+ return s.size() <= MaxLatin1Length;
+}
+
+template <typename T>
+static inline int qStringSize(T string, bool compress)
{
- int l = 2 + string.length();
+ int l = 2 + string.size();
if (!compress)
l *= 2;
return alignedSize(l);
@@ -214,37 +224,49 @@ public:
return maxSize >= 0 && uint(d->length) <= maxSize / sizeof(ushort);
}
- inline String &operator=(const QString &str)
+ inline String &operator=(QStringView str)
{
d->length = str.length();
+ qToLittleEndian<quint16>(str.utf16(), str.length(), d->utf16);
+ fillTrailingZeros();
+ return *this;
+ }
+
+ inline String &operator=(QLatin1String str)
+ {
+ d->length = str.size();
#if Q_BYTE_ORDER == Q_BIG_ENDIAN
- const ushort *uc = (const ushort *)str.unicode();
- for (int i = 0; i < str.length(); ++i)
- d->utf16[i] = uc[i];
+ for (int i = 0; i < str.size(); ++i)
+ d->utf16[i] = str[i].unicode();
#else
- memcpy(d->utf16, str.unicode(), str.length()*sizeof(ushort));
+ qt_from_latin1((ushort *)d->utf16, str.data(), str.size());
#endif
- if (str.length() & 1)
- d->utf16[str.length()] = 0;
+ fillTrailingZeros();
return *this;
}
- inline bool operator ==(const QString &str) const {
+ void fillTrailingZeros()
+ {
+ if (d->length & 1)
+ d->utf16[d->length] = 0;
+ }
+
+ inline bool operator ==(QStringView str) const {
int slen = str.length();
int l = d->length;
if (slen != l)
return false;
- const ushort *s = (const ushort *)str.constData();
+ const ushort *s = (const ushort *)str.utf16();
const qle_ushort *a = d->utf16;
const ushort *b = s;
while (l-- && *a == *b)
a++,b++;
return (l == -1);
}
- inline bool operator !=(const QString &str) const {
+ inline bool operator !=(QStringView str) const {
return !operator ==(str);
}
- inline bool operator >=(const QString &str) const {
+ inline bool operator >=(QStringView str) const {
// ###
return toString() >= str;
}
@@ -292,18 +314,34 @@ public:
return byteSize() <= maxSize;
}
- inline Latin1String &operator=(const QString &str)
+ inline Latin1String &operator=(QStringView str)
{
int len = d->length = str.length();
uchar *l = (uchar *)d->latin1;
- const ushort *uc = (const ushort *)str.unicode();
+ const ushort *uc = (const ushort *)str.utf16();
qt_to_latin1_unchecked(l, uc, len);
- for ( ; (quintptr)(l+len) & 0x3; ++len)
- l[len] = 0;
+ fillTrailingZeros();
return *this;
}
+ inline Latin1String &operator=(QLatin1String str)
+ {
+ int len = d->length = str.size();
+ uchar *l = (uchar *)d->latin1;
+ memcpy(l, str.data(), len);
+
+ fillTrailingZeros();
+ return *this;
+ }
+
+ void fillTrailingZeros()
+ {
+ uchar *l = (uchar *)d->latin1;
+ for (int len = d->length; (quintptr)(l + len) & 0x3; ++len)
+ l[len] = 0;
+ }
+
QLatin1String toQLatin1String() const noexcept {
return QLatin1String(d->latin1, d->length);
}
@@ -351,11 +389,11 @@ public:
{ \
return lhs.toQLatin1String() op rhs; \
} \
- inline bool operator op(const QString &lhs, Latin1String rhs) noexcept \
+ inline bool operator op(QStringView lhs, Latin1String rhs) noexcept \
{ \
return lhs op rhs.toQLatin1String(); \
} \
- inline bool operator op(Latin1String lhs, const QString &rhs) noexcept \
+ inline bool operator op(Latin1String lhs, QStringView rhs) noexcept \
{ \
return lhs.toQLatin1String() op rhs; \
} \
@@ -419,7 +457,8 @@ inline bool String::operator<(const Latin1String &str) const
}
-static inline void copyString(char *dest, const QString &str, bool compress)
+template <typename T>
+static inline void copyString(char *dest, T str, bool compress)
{
if (compress) {
Latin1String string(dest);
@@ -469,7 +508,7 @@ public:
Entry *entryAt(int i) const {
return reinterpret_cast<Entry *>(((char *)this) + table()[i]);
}
- int indexOf(const QString &key, bool *exists) const;
+ int indexOf(QStringView key, bool *exists) const;
int indexOf(QLatin1String key, bool *exists) const;
bool isValid(int maxSize) const;
@@ -577,9 +616,9 @@ public:
return shallowKey().isValid(maxSize);
}
- bool operator ==(const QString &key) const;
- inline bool operator !=(const QString &key) const { return !operator ==(key); }
- inline bool operator >=(const QString &key) const;
+ bool operator ==(QStringView key) const;
+ inline bool operator !=(QStringView key) const { return !operator ==(key); }
+ inline bool operator >=(QStringView key) const;
bool operator==(QLatin1String key) const;
inline bool operator!=(QLatin1String key) const { return !operator ==(key); }
@@ -589,7 +628,7 @@ public:
bool operator >=(const Entry &other) const;
};
-inline bool Entry::operator >=(const QString &key) const
+inline bool Entry::operator >=(QStringView key) const
{
if (value.latinKey)
return (shallowLatin1Key() >= key);
@@ -602,10 +641,10 @@ inline bool Entry::operator >=(QLatin1String key) const
if (value.latinKey)
return shallowLatin1Key() >= key;
else
- return shallowKey() >= key;
+ return shallowKey() >= QString(key); // ### conversion to QString
}
-inline bool operator <(const QString &key, const Entry &e)
+inline bool operator <(QStringView key, const Entry &e)
{ return e >= key; }
inline bool operator<(QLatin1String key, const Entry &e)
diff --git a/src/corelib/serialization/qjsonarray.cpp b/src/corelib/serialization/qjsonarray.cpp
index 6b327619ad..9636ac5856 100644
--- a/src/corelib/serialization/qjsonarray.cpp
+++ b/src/corelib/serialization/qjsonarray.cpp
@@ -845,7 +845,7 @@ bool QJsonArray::operator!=(const QJsonArray &other) const
The return value is of type QJsonValueRef, a helper class for QJsonArray
and QJsonObject. When you get an object of type QJsonValueRef, you can
use it as if it were a reference to a QJsonValue. If you assign to it,
- the assignment will apply to the character in the QJsonArray of QJsonObject
+ the assignment will apply to the element in the QJsonArray or QJsonObject
from which you got the reference.
\sa operator+()
diff --git a/src/corelib/serialization/qjsoncbor.cpp b/src/corelib/serialization/qjsoncbor.cpp
index e0c390f610..d6a0c8c48a 100644
--- a/src/corelib/serialization/qjsoncbor.cpp
+++ b/src/corelib/serialization/qjsoncbor.cpp
@@ -421,7 +421,7 @@ QJsonArray QCborArray::toJsonArray() const
}
/*!
- Recursively converts every \l QCborValue value in this array to JSON using
+ Recursively converts every \l QCborValue value in this map to JSON using
QCborValue::toJsonValue() and creates a string key for all keys that aren't
strings, then returns the corresponding QJsonObject composed of those
associations.
diff --git a/src/corelib/serialization/qjsondocument.cpp b/src/corelib/serialization/qjsondocument.cpp
index f8027efb58..193b80ee22 100644
--- a/src/corelib/serialization/qjsondocument.cpp
+++ b/src/corelib/serialization/qjsondocument.cpp
@@ -544,6 +544,7 @@ void QJsonDocument::setArray(const QJsonArray &array)
d->ref.ref();
}
+#if QT_STRINGVIEW_LEVEL < 2
/*!
Returns a QJsonValue representing the value for the key \a key.
@@ -558,6 +559,16 @@ void QJsonDocument::setArray(const QJsonArray &array)
*/
const QJsonValue QJsonDocument::operator[](const QString &key) const
{
+ return (*this)[QStringView(key)];
+}
+#endif
+
+/*!
+ \overload
+ \since 5.14
+*/
+const QJsonValue QJsonDocument::operator[](QStringView key) const
+{
if (!isObject())
return QJsonValue(QJsonValue::Undefined);
diff --git a/src/corelib/serialization/qjsondocument.h b/src/corelib/serialization/qjsondocument.h
index a8006a6cc5..a8e7485f5d 100644
--- a/src/corelib/serialization/qjsondocument.h
+++ b/src/corelib/serialization/qjsondocument.h
@@ -146,7 +146,10 @@ public:
void setObject(const QJsonObject &object);
void setArray(const QJsonArray &array);
+#if QT_STRINGVIEW_LEVEL < 2
const QJsonValue operator[](const QString &key) const;
+#endif
+ const QJsonValue operator[](QStringView key) const;
const QJsonValue operator[](QLatin1String key) const;
const QJsonValue operator[](int i) const;
diff --git a/src/corelib/serialization/qjsonobject.cpp b/src/corelib/serialization/qjsonobject.cpp
index c1a6328b2f..329bc4d2c9 100644
--- a/src/corelib/serialization/qjsonobject.cpp
+++ b/src/corelib/serialization/qjsonobject.cpp
@@ -377,6 +377,7 @@ bool QJsonObject::isEmpty() const
return !o->length;
}
+#if QT_STRINGVIEW_LEVEL < 2
/*!
Returns a QJsonValue representing the value for the key \a key.
@@ -386,14 +387,17 @@ bool QJsonObject::isEmpty() const
*/
QJsonValue QJsonObject::value(const QString &key) const
{
- if (!d)
- return QJsonValue(QJsonValue::Undefined);
+ return value(QStringView(key));
+}
+#endif
- bool keyExists;
- int i = o->indexOf(key, &keyExists);
- if (!keyExists)
- return QJsonValue(QJsonValue::Undefined);
- return QJsonValue(d, o, o->entryAt(i)->value);
+/*!
+ \overload
+ \since 5.14
+*/
+QJsonValue QJsonObject::value(QStringView key) const
+{
+ return valueImpl(key);
}
/*!
@@ -402,6 +406,15 @@ QJsonValue QJsonObject::value(const QString &key) const
*/
QJsonValue QJsonObject::value(QLatin1String key) const
{
+ return valueImpl(key);
+}
+
+/*!
+ \internal
+*/
+template <typename T>
+QJsonValue QJsonObject::valueImpl(T key) const
+{
if (!d)
return QJsonValue(QJsonValue::Undefined);
@@ -412,6 +425,7 @@ QJsonValue QJsonObject::value(QLatin1String key) const
return QJsonValue(d, o, o->entryAt(i)->value);
}
+#if QT_STRINGVIEW_LEVEL < 2
/*!
Returns a QJsonValue representing the value for the key \a key.
@@ -423,8 +437,16 @@ QJsonValue QJsonObject::value(QLatin1String key) const
*/
QJsonValue QJsonObject::operator [](const QString &key) const
{
- return value(key);
+ return (*this)[QStringView(key)];
}
+#endif
+
+/*!
+ \fn QJsonValue QJsonObject::operator [](QStringView key) const
+
+ \overload
+ \since 5.14
+*/
/*!
\fn QJsonValue QJsonObject::operator [](QLatin1String key) const
@@ -433,6 +455,7 @@ QJsonValue QJsonObject::operator [](const QString &key) const
\since 5.7
*/
+#if QT_STRINGVIEW_LEVEL < 2
/*!
Returns a reference to the value for \a key.
@@ -446,14 +469,17 @@ QJsonValue QJsonObject::operator [](const QString &key) const
*/
QJsonValueRef QJsonObject::operator [](const QString &key)
{
- // ### somewhat inefficient, as we lookup the key twice if it doesn't yet exist
- bool keyExists = false;
- int index = o ? o->indexOf(key, &keyExists) : -1;
- if (!keyExists) {
- iterator i = insert(key, QJsonValue());
- index = i.i;
- }
- return QJsonValueRef(this, index);
+ return (*this)[QStringView(key)];
+}
+#endif
+
+/*!
+ \overload
+ \since 5.14
+*/
+QJsonValueRef QJsonObject::operator [](QStringView key)
+{
+ return atImpl(key);
}
/*!
@@ -462,10 +488,25 @@ QJsonValueRef QJsonObject::operator [](const QString &key)
*/
QJsonValueRef QJsonObject::operator [](QLatin1String key)
{
- // ### optimize me
- return operator[](QString(key));
+ return atImpl(key);
+}
+
+/*!
+ \internal
+*/
+template <typename T>
+QJsonValueRef QJsonObject::atImpl(T key)
+{
+ bool keyExists = false;
+ int index = o ? o->indexOf(key, &keyExists) : 0;
+ if (!keyExists) {
+ iterator i = insertAt(index, key, QJsonValue(), false);
+ index = i.i;
+ }
+ return QJsonValueRef(this, index);
}
+#if QT_STRINGVIEW_LEVEL < 2
/*!
Inserts a new item with the key \a key and a value of \a value.
@@ -481,10 +522,49 @@ QJsonValueRef QJsonObject::operator [](QLatin1String key)
*/
QJsonObject::iterator QJsonObject::insert(const QString &key, const QJsonValue &value)
{
+ return insert(QStringView(key), value);
+}
+#endif
+
+/*!
+ \overload
+ \since 5.14
+*/
+QJsonObject::iterator QJsonObject::insert(QStringView key, const QJsonValue &value)
+{
+ return insertImpl(key, value);
+}
+
+/*!
+ \overload
+ \since 5.14
+*/
+QJsonObject::iterator QJsonObject::insert(QLatin1String key, const QJsonValue &value)
+{
+ return insertImpl(key, value);
+}
+
+/*!
+ \internal
+*/
+template <typename T>
+QJsonObject::iterator QJsonObject::insertImpl(T key, const QJsonValue &value)
+{
if (value.t == QJsonValue::Undefined) {
remove(key);
return end();
}
+ bool keyExists = false;
+ int pos = o ? o->indexOf(key, &keyExists) : 0;
+ return insertAt(pos, key, value, keyExists);
+}
+
+/*!
+ \internal
+ */
+template <typename T>
+QJsonObject::iterator QJsonObject::insertAt(int pos, T key, const QJsonValue &value, bool keyExists)
+{
QJsonValue val = value;
bool latinOrIntValue;
@@ -500,8 +580,6 @@ QJsonObject::iterator QJsonObject::insert(const QString &key, const QJsonValue &
if (!o->length)
o->tableOffset = sizeof(QJsonPrivate::Object);
- bool keyExists = false;
- int pos = o->indexOf(key, &keyExists);
if (keyExists)
++d->compactionCounter;
@@ -518,12 +596,12 @@ QJsonObject::iterator QJsonObject::insert(const QString &key, const QJsonValue &
if (valueSize)
QJsonPrivate::Value::copyData(val, (char *)e + valueOffset, latinOrIntValue);
- if (d->compactionCounter > 32u && d->compactionCounter >= unsigned(o->length) / 2u)
- compact();
+ compactIfNeeded();
return iterator(this, pos);
}
+#if QT_STRINGVIEW_LEVEL < 2
/*!
Removes \a key from the object.
@@ -531,6 +609,34 @@ QJsonObject::iterator QJsonObject::insert(const QString &key, const QJsonValue &
*/
void QJsonObject::remove(const QString &key)
{
+ remove(QStringView(key));
+}
+#endif
+
+/*!
+ \overload
+ \since 5.14
+*/
+void QJsonObject::remove(QStringView key)
+{
+ removeImpl(key);
+}
+
+/*!
+ \overload
+ \since 5.14
+*/
+void QJsonObject::remove(QLatin1String key)
+{
+ removeImpl(key);
+}
+
+/*!
+ \internal
+*/
+template <typename T>
+void QJsonObject::removeImpl(T key)
+{
if (!d)
return;
@@ -539,13 +645,10 @@ void QJsonObject::remove(const QString &key)
if (!keyExists)
return;
- detach2();
- o->removeItems(index, 1);
- ++d->compactionCounter;
- if (d->compactionCounter > 32u && d->compactionCounter >= unsigned(o->length) / 2u)
- compact();
+ removeAt(index);
}
+#if QT_STRINGVIEW_LEVEL < 2
/*!
Removes \a key from the object.
@@ -557,6 +660,34 @@ void QJsonObject::remove(const QString &key)
*/
QJsonValue QJsonObject::take(const QString &key)
{
+ return take(QStringView(key));
+}
+#endif
+
+/*!
+ \overload
+ \since 5.14
+*/
+QJsonValue QJsonObject::take(QStringView key)
+{
+ return takeImpl(key);
+}
+
+/*!
+ \overload
+ \since 5.14
+*/
+QJsonValue QJsonObject::take(QLatin1String key)
+{
+ return takeImpl(key);
+}
+
+/*!
+ \internal
+*/
+template <typename T>
+QJsonValue QJsonObject::takeImpl(T key)
+{
if (!o)
return QJsonValue(QJsonValue::Undefined);
@@ -566,15 +697,12 @@ QJsonValue QJsonObject::take(const QString &key)
return QJsonValue(QJsonValue::Undefined);
QJsonValue v(d, o, o->entryAt(index)->value);
- detach2();
- o->removeItems(index, 1);
- ++d->compactionCounter;
- if (d->compactionCounter > 32u && d->compactionCounter >= unsigned(o->length) / 2u)
- compact();
+ removeAt(index);
return v;
}
+#if QT_STRINGVIEW_LEVEL < 2
/*!
Returns \c true if the object contains key \a key.
@@ -582,12 +710,17 @@ QJsonValue QJsonObject::take(const QString &key)
*/
bool QJsonObject::contains(const QString &key) const
{
- if (!o)
- return false;
+ return contains(QStringView(key));
+}
+#endif
- bool keyExists;
- o->indexOf(key, &keyExists);
- return keyExists;
+/*!
+ \overload
+ \since 5.14
+*/
+bool QJsonObject::contains(QStringView key) const
+{
+ return containsImpl(key);
}
/*!
@@ -596,6 +729,15 @@ bool QJsonObject::contains(const QString &key) const
*/
bool QJsonObject::contains(QLatin1String key) const
{
+ return containsImpl(key);
+}
+
+/*!
+ \internal
+*/
+template <typename T>
+bool QJsonObject::containsImpl(T key) const
+{
if (!o)
return false;
@@ -652,15 +794,13 @@ QJsonObject::iterator QJsonObject::erase(QJsonObject::iterator it)
int index = it.i;
- o->removeItems(index, 1);
- ++d->compactionCounter;
- if (d->compactionCounter > 32u && d->compactionCounter >= unsigned(o->length) / 2u)
- compact();
+ removeAt(index);
// iterator hasn't changed
return it;
}
+#if QT_STRINGVIEW_LEVEL < 2
/*!
Returns an iterator pointing to the item with key \a key in the
map.
@@ -670,12 +810,17 @@ QJsonObject::iterator QJsonObject::erase(QJsonObject::iterator it)
*/
QJsonObject::iterator QJsonObject::find(const QString &key)
{
- bool keyExists = false;
- int index = o ? o->indexOf(key, &keyExists) : 0;
- if (!keyExists)
- return end();
- detach2();
- return iterator(this, index);
+ return find(QStringView(key));
+}
+#endif
+
+/*!
+ \overload
+ \since 5.14
+*/
+QJsonObject::iterator QJsonObject::find(QStringView key)
+{
+ return findImpl(key);
}
/*!
@@ -684,6 +829,15 @@ QJsonObject::iterator QJsonObject::find(const QString &key)
*/
QJsonObject::iterator QJsonObject::find(QLatin1String key)
{
+ return findImpl(key);
+}
+
+/*!
+ \internal
+*/
+template <typename T>
+QJsonObject::iterator QJsonObject::findImpl(T key)
+{
bool keyExists = false;
int index = o ? o->indexOf(key, &keyExists) : 0;
if (!keyExists)
@@ -692,10 +846,18 @@ QJsonObject::iterator QJsonObject::find(QLatin1String key)
return iterator(this, index);
}
+#if QT_STRINGVIEW_LEVEL < 2
/*! \fn QJsonObject::const_iterator QJsonObject::find(const QString &key) const
\overload
*/
+#endif
+
+/*! \fn QJsonObject::const_iterator QJsonObject::find(QStringView key) const
+
+ \overload
+ \since 5.14
+*/
/*! \fn QJsonObject::const_iterator QJsonObject::find(QLatin1String key) const
@@ -703,6 +865,7 @@ QJsonObject::iterator QJsonObject::find(QLatin1String key)
\since 5.7
*/
+#if QT_STRINGVIEW_LEVEL < 2
/*!
Returns a const iterator pointing to the item with key \a key in the
map.
@@ -712,11 +875,17 @@ QJsonObject::iterator QJsonObject::find(QLatin1String key)
*/
QJsonObject::const_iterator QJsonObject::constFind(const QString &key) const
{
- bool keyExists = false;
- int index = o ? o->indexOf(key, &keyExists) : 0;
- if (!keyExists)
- return end();
- return const_iterator(this, index);
+ return constFind(QStringView(key));
+}
+#endif
+
+/*!
+ \overload
+ \since 5.14
+*/
+QJsonObject::const_iterator QJsonObject::constFind(QStringView key) const
+{
+ return constFindImpl(key);
}
/*!
@@ -725,6 +894,15 @@ QJsonObject::const_iterator QJsonObject::constFind(const QString &key) const
*/
QJsonObject::const_iterator QJsonObject::constFind(QLatin1String key) const
{
+ return constFindImpl(key);
+}
+
+/*!
+ \internal
+*/
+template <typename T>
+QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const
+{
bool keyExists = false;
int index = o ? o->indexOf(key, &keyExists) : 0;
if (!keyExists)
@@ -1261,6 +1439,15 @@ void QJsonObject::compact()
/*!
\internal
*/
+void QJsonObject::compactIfNeeded()
+{
+ if (d->compactionCounter > 32u && d->compactionCounter >= unsigned(o->length) / 2u)
+ compact();
+}
+
+/*!
+ \internal
+ */
QString QJsonObject::keyAt(int i) const
{
Q_ASSERT(o && i >= 0 && i < (int)o->length);
@@ -1289,7 +1476,21 @@ void QJsonObject::setValueAt(int i, const QJsonValue &val)
Q_ASSERT(o && i >= 0 && i < (int)o->length);
QJsonPrivate::Entry *e = o->entryAt(i);
- insert(e->key(), val);
+ if (val.t == QJsonValue::Undefined)
+ removeAt(i);
+ else
+ insertAt(i, e->key(), val, true);
+}
+
+/*!
+ \internal
+ */
+void QJsonObject::removeAt(int index)
+{
+ detach2();
+ o->removeItems(index, 1);
+ ++d->compactionCounter;
+ compactIfNeeded();
}
uint qHash(const QJsonObject &object, uint seed)
diff --git a/src/corelib/serialization/qjsonobject.h b/src/corelib/serialization/qjsonobject.h
index d8e2ab9ca7..05463f6f36 100644
--- a/src/corelib/serialization/qjsonobject.h
+++ b/src/corelib/serialization/qjsonobject.h
@@ -100,16 +100,28 @@ public:
inline int length() const { return size(); }
bool isEmpty() const;
+#if QT_STRINGVIEW_LEVEL < 2
QJsonValue value(const QString &key) const;
- QJsonValue value(QLatin1String key) const;
QJsonValue operator[] (const QString &key) const;
- QJsonValue operator[] (QLatin1String key) const { return value(key); }
QJsonValueRef operator[] (const QString &key);
+#endif
+ QJsonValue value(QStringView key) const;
+ QJsonValue value(QLatin1String key) const;
+ QJsonValue operator[] (QStringView key) const { return value(key); }
+ QJsonValue operator[] (QLatin1String key) const { return value(key); }
+ QJsonValueRef operator[] (QStringView key);
QJsonValueRef operator[] (QLatin1String key);
+#if QT_STRINGVIEW_LEVEL < 2
void remove(const QString &key);
QJsonValue take(const QString &key);
bool contains(const QString &key) const;
+#endif
+ void remove(QStringView key);
+ void remove(QLatin1String key);
+ QJsonValue take(QStringView key);
+ QJsonValue take(QLatin1String key);
+ bool contains(QStringView key) const;
bool contains(QLatin1String key) const;
bool operator==(const QJsonObject &other) const;
@@ -218,13 +230,20 @@ public:
// more Qt
typedef iterator Iterator;
typedef const_iterator ConstIterator;
+#if QT_STRINGVIEW_LEVEL < 2
iterator find(const QString &key);
- iterator find(QLatin1String key);
const_iterator find(const QString &key) const { return constFind(key); }
- const_iterator find(QLatin1String key) const { return constFind(key); }
const_iterator constFind(const QString &key) const;
- const_iterator constFind(QLatin1String key) const;
iterator insert(const QString &key, const QJsonValue &value);
+#endif
+ iterator find(QStringView key);
+ iterator find(QLatin1String key);
+ const_iterator find(QStringView key) const { return constFind(key); }
+ const_iterator find(QLatin1String key) const { return constFind(key); }
+ const_iterator constFind(QStringView key) const;
+ const_iterator constFind(QLatin1String key) const;
+ iterator insert(QStringView key, const QJsonValue &value);
+ iterator insert(QLatin1String key, const QJsonValue &value);
// STL compatibility
typedef QJsonValue mapped_type;
@@ -247,10 +266,22 @@ private:
void detach(uint reserve = 0);
bool detach2(uint reserve = 0);
void compact();
+ void compactIfNeeded();
+
+ template <typename T> QJsonValue valueImpl(T key) const;
+ template <typename T> QJsonValueRef atImpl(T key);
+ template <typename T> void removeImpl(T key);
+ template <typename T> QJsonValue takeImpl(T key);
+ template <typename T> bool containsImpl(T key) const;
+ template <typename T> iterator findImpl(T key);
+ template <typename T> const_iterator constFindImpl(T key) const;
+ template <typename T> iterator insertImpl(T key, const QJsonValue &value);
QString keyAt(int i) const;
QJsonValue valueAt(int i) const;
void setValueAt(int i, const QJsonValue &val);
+ void removeAt(int i);
+ template <typename T> iterator insertAt(int i, T key, const QJsonValue &val, bool exists);
QJsonPrivate::Data *d;
QJsonPrivate::Object *o;
diff --git a/src/corelib/serialization/qjsonvalue.cpp b/src/corelib/serialization/qjsonvalue.cpp
index 0bd28581f3..5f07a6a03e 100644
--- a/src/corelib/serialization/qjsonvalue.cpp
+++ b/src/corelib/serialization/qjsonvalue.cpp
@@ -694,6 +694,7 @@ QJsonObject QJsonValue::toObject() const
return toObject(QJsonObject());
}
+#if QT_STRINGVIEW_LEVEL < 2
/*!
Returns a QJsonValue representing the value for the key \a key.
@@ -708,6 +709,16 @@ QJsonObject QJsonValue::toObject() const
*/
const QJsonValue QJsonValue::operator[](const QString &key) const
{
+ return (*this)[QStringView(key)];
+}
+#endif
+
+/*!
+ \overload
+ \since 5.14
+*/
+const QJsonValue QJsonValue::operator[](QStringView key) const
+{
if (!isObject())
return QJsonValue(QJsonValue::Undefined);
diff --git a/src/corelib/serialization/qjsonvalue.h b/src/corelib/serialization/qjsonvalue.h
index 37d84f9e60..430fa06c0f 100644
--- a/src/corelib/serialization/qjsonvalue.h
+++ b/src/corelib/serialization/qjsonvalue.h
@@ -137,7 +137,10 @@ public:
QJsonObject toObject() const;
QJsonObject toObject(const QJsonObject &defaultValue) const;
+#if QT_STRINGVIEW_LEVEL < 2
const QJsonValue operator[](const QString &key) const;
+#endif
+ const QJsonValue operator[](QStringView key) const;
const QJsonValue operator[](QLatin1String key) const;
const QJsonValue operator[](int i) const;
diff --git a/src/corelib/serialization/qtextstream.cpp b/src/corelib/serialization/qtextstream.cpp
index 9d4bc223ab..a675c3cede 100644
--- a/src/corelib/serialization/qtextstream.cpp
+++ b/src/corelib/serialization/qtextstream.cpp
@@ -888,7 +888,7 @@ inline bool QTextStreamPrivate::getChar(QChar *ch)
if ((string && stringOffset == string->size())
|| (device && readBuffer.isEmpty() && !fillReadBuffer())) {
if (ch)
- *ch = 0;
+ *ch = QChar();
return false;
}
if (ch)
diff --git a/src/corelib/serialization/qxmlstream.cpp b/src/corelib/serialization/qxmlstream.cpp
index be3a476cb2..500e0aa6be 100644
--- a/src/corelib/serialization/qxmlstream.cpp
+++ b/src/corelib/serialization/qxmlstream.cpp
@@ -782,8 +782,8 @@ QXmlStreamPrivateTagStack::QXmlStreamPrivateTagStack()
tagStackStringStorage.reserve(32);
tagStackStringStorageSize = 0;
NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.push();
- namespaceDeclaration.prefix = addToStringStorage(QStringViewLiteral("xml"));
- namespaceDeclaration.namespaceUri = addToStringStorage(QStringViewLiteral("http://www.w3.org/XML/1998/namespace"));
+ namespaceDeclaration.prefix = addToStringStorage(u"xml");
+ namespaceDeclaration.namespaceUri = addToStringStorage(u"http://www.w3.org/XML/1998/namespace");
initialTagStackStringStorageSize = tagStackStringStorageSize;
}
@@ -1423,7 +1423,7 @@ inline int QXmlStreamReaderPrivate::fastScanNMTOKEN()
int n = 0;
uint c;
while ((c = getChar()) != StreamEOF) {
- if (fastDetermineNameChar(c) == NotName) {
+ if (fastDetermineNameChar(QChar(c)) == NotName) {
putChar(c);
return n;
} else {
diff --git a/src/corelib/tools/UNICODE_LICENSE.txt b/src/corelib/text/UNICODE_LICENSE.txt
index 1c73202b74..1c73202b74 100644
--- a/src/corelib/tools/UNICODE_LICENSE.txt
+++ b/src/corelib/text/UNICODE_LICENSE.txt
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/text/qbytearray.cpp
index ecbb4743af..c50e087c10 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/text/qbytearray.cpp
@@ -40,7 +40,7 @@
#include "qbytearray.h"
#include "qbytearraymatcher.h"
-#include "qtools_p.h"
+#include "private/qtools_p.h"
#include "qstring.h"
#include "qlist.h"
#include "qlocale.h"
@@ -972,12 +972,11 @@ QByteArray qUncompress(const uchar* data, int nbytes)
\section2 8-bit Character Comparisons
In QByteArray, the notion of uppercase and lowercase and of which
- character is greater than or less than another character is
- locale dependent. This affects functions that support a case
+ character is greater than or less than another character is done
+ in the Latin-1 locale. This affects functions that support a case
insensitive option or that compare or lowercase or uppercase
their arguments. Case insensitive operations and comparisons will
- be accurate if both strings contain only ASCII characters. (If \c
- $LC_CTYPE is set, most Unix systems do "the right thing".)
+ be accurate if both strings contain only Latin-1 characters.
Functions that this affects include contains(), indexOf(),
lastIndexOf(), operator<(), operator<=(), operator>(),
operator>=(), isLower(), isUpper(), toLower() and toUpper().
diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/text/qbytearray.h
index 7c571706d8..7c571706d8 100644
--- a/src/corelib/tools/qbytearray.h
+++ b/src/corelib/text/qbytearray.h
diff --git a/src/corelib/tools/qbytearray_p.h b/src/corelib/text/qbytearray_p.h
index 6ebff739cd..3c6257f786 100644
--- a/src/corelib/tools/qbytearray_p.h
+++ b/src/corelib/text/qbytearray_p.h
@@ -52,7 +52,7 @@
//
#include <QtCore/qbytearray.h>
-#include "qtools_p.h"
+#include "private/qtools_p.h"
QT_BEGIN_NAMESPACE
diff --git a/src/corelib/tools/qbytearraylist.cpp b/src/corelib/text/qbytearraylist.cpp
index d04555ed4d..d04555ed4d 100644
--- a/src/corelib/tools/qbytearraylist.cpp
+++ b/src/corelib/text/qbytearraylist.cpp
diff --git a/src/corelib/tools/qbytearraylist.h b/src/corelib/text/qbytearraylist.h
index 0250b649b8..0250b649b8 100644
--- a/src/corelib/tools/qbytearraylist.h
+++ b/src/corelib/text/qbytearraylist.h
diff --git a/src/corelib/tools/qbytearraymatcher.cpp b/src/corelib/text/qbytearraymatcher.cpp
index 72e09226af..72e09226af 100644
--- a/src/corelib/tools/qbytearraymatcher.cpp
+++ b/src/corelib/text/qbytearraymatcher.cpp
diff --git a/src/corelib/tools/qbytearraymatcher.h b/src/corelib/text/qbytearraymatcher.h
index 0eedfc1d20..0eedfc1d20 100644
--- a/src/corelib/tools/qbytearraymatcher.h
+++ b/src/corelib/text/qbytearraymatcher.h
diff --git a/src/corelib/tools/qbytedata_p.h b/src/corelib/text/qbytedata_p.h
index b319d75811..b319d75811 100644
--- a/src/corelib/tools/qbytedata_p.h
+++ b/src/corelib/text/qbytedata_p.h
diff --git a/src/corelib/tools/qchar.cpp b/src/corelib/text/qchar.cpp
index e097e4a5fe..0c190c6a3d 100644
--- a/src/corelib/tools/qchar.cpp
+++ b/src/corelib/text/qchar.cpp
@@ -1885,11 +1885,11 @@ static void composeHelper(QString *str, QChar::UnicodeVersion version, int from)
QChar *d = s.data();
// ligatureHelper() never changes planes
if (QChar::requiresSurrogates(ligature)) {
- d[starter] = QChar::highSurrogate(ligature);
- d[starter + 1] = QChar::lowSurrogate(ligature);
+ d[starter] = QChar(QChar::highSurrogate(ligature));
+ d[starter + 1] = QChar(QChar::lowSurrogate(ligature));
s.remove(i, 2);
} else {
- d[starter] = ligature;
+ d[starter] = QChar(ligature);
s.remove(i, 1);
}
continue;
@@ -1962,16 +1962,16 @@ static void canonicalOrderHelper(QString *str, QChar::UnicodeVersion version, in
int p = pos;
// exchange characters
if (!QChar::requiresSurrogates(u2)) {
- uc[p++] = u2;
+ uc[p++] = QChar(u2);
} else {
- uc[p++] = QChar::highSurrogate(u2);
- uc[p++] = QChar::lowSurrogate(u2);
+ uc[p++] = QChar(QChar::highSurrogate(u2));
+ uc[p++] = QChar(QChar::lowSurrogate(u2));
}
if (!QChar::requiresSurrogates(u1)) {
- uc[p++] = u1;
+ uc[p++] = QChar(u1);
} else {
- uc[p++] = QChar::highSurrogate(u1);
- uc[p++] = QChar::lowSurrogate(u1);
+ uc[p++] = QChar(QChar::highSurrogate(u1));
+ uc[p++] = QChar(QChar::lowSurrogate(u1));
}
if (pos > 0)
--pos;
diff --git a/src/corelib/tools/qchar.h b/src/corelib/text/qchar.h
index 73344ecf52..e028a24c24 100644
--- a/src/corelib/tools/qchar.h
+++ b/src/corelib/text/qchar.h
@@ -443,17 +443,17 @@ public:
#endif
inline unsigned char combiningClass() const noexcept { return QChar::combiningClass(ucs); }
- inline QChar mirroredChar() const noexcept { return QChar::mirroredChar(ucs); }
+ inline QChar mirroredChar() const noexcept { return QChar(QChar::mirroredChar(ucs)); }
inline bool hasMirrored() const noexcept { return QChar::hasMirrored(ucs); }
QString decomposition() const;
inline Decomposition decompositionTag() const noexcept { return QChar::decompositionTag(ucs); }
inline int digitValue() const noexcept { return QChar::digitValue(ucs); }
- inline QChar toLower() const noexcept { return QChar::toLower(ucs); }
- inline QChar toUpper() const noexcept { return QChar::toUpper(ucs); }
- inline QChar toTitleCase() const noexcept { return QChar::toTitleCase(ucs); }
- inline QChar toCaseFolded() const noexcept { return QChar::toCaseFolded(ucs); }
+ inline QChar toLower() const noexcept { return QChar(QChar::toLower(ucs)); }
+ inline QChar toUpper() const noexcept { return QChar(QChar::toUpper(ucs)); }
+ inline QChar toTitleCase() const noexcept { return QChar(QChar::toTitleCase(ucs)); }
+ inline QChar toCaseFolded() const noexcept { return QChar(QChar::toCaseFolded(ucs)); }
inline Script script() const noexcept { return QChar::script(ucs); }
diff --git a/src/corelib/tools/qcollator.cpp b/src/corelib/text/qcollator.cpp
index 958216bde8..958216bde8 100644
--- a/src/corelib/tools/qcollator.cpp
+++ b/src/corelib/text/qcollator.cpp
diff --git a/src/corelib/tools/qcollator.h b/src/corelib/text/qcollator.h
index 6bb5038371..6bb5038371 100644
--- a/src/corelib/tools/qcollator.h
+++ b/src/corelib/text/qcollator.h
diff --git a/src/corelib/tools/qcollator_icu.cpp b/src/corelib/text/qcollator_icu.cpp
index 8acda45070..8acda45070 100644
--- a/src/corelib/tools/qcollator_icu.cpp
+++ b/src/corelib/text/qcollator_icu.cpp
diff --git a/src/corelib/tools/qcollator_macx.cpp b/src/corelib/text/qcollator_macx.cpp
index 071d7c048f..071d7c048f 100644
--- a/src/corelib/tools/qcollator_macx.cpp
+++ b/src/corelib/text/qcollator_macx.cpp
diff --git a/src/corelib/tools/qcollator_p.h b/src/corelib/text/qcollator_p.h
index fc2d434a8d..fc2d434a8d 100644
--- a/src/corelib/tools/qcollator_p.h
+++ b/src/corelib/text/qcollator_p.h
diff --git a/src/corelib/tools/qcollator_posix.cpp b/src/corelib/text/qcollator_posix.cpp
index 9cbc539ebe..9cbc539ebe 100644
--- a/src/corelib/tools/qcollator_posix.cpp
+++ b/src/corelib/text/qcollator_posix.cpp
diff --git a/src/corelib/tools/qcollator_win.cpp b/src/corelib/text/qcollator_win.cpp
index 9d81de882f..9d81de882f 100644
--- a/src/corelib/tools/qcollator_win.cpp
+++ b/src/corelib/text/qcollator_win.cpp
diff --git a/src/corelib/tools/qdoublescanprint_p.h b/src/corelib/text/qdoublescanprint_p.h
index 3865c69a99..3865c69a99 100644
--- a/src/corelib/tools/qdoublescanprint_p.h
+++ b/src/corelib/text/qdoublescanprint_p.h
diff --git a/src/corelib/tools/qharfbuzz.cpp b/src/corelib/text/qharfbuzz.cpp
index a3e266ccd2..a3e266ccd2 100644
--- a/src/corelib/tools/qharfbuzz.cpp
+++ b/src/corelib/text/qharfbuzz.cpp
diff --git a/src/corelib/tools/qharfbuzz_p.h b/src/corelib/text/qharfbuzz_p.h
index 2a0307d35f..2a0307d35f 100644
--- a/src/corelib/tools/qharfbuzz_p.h
+++ b/src/corelib/text/qharfbuzz_p.h
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/text/qlocale.cpp
index 939f8eb34d..5685d87c85 100644
--- a/src/corelib/tools/qlocale.cpp
+++ b/src/corelib/text/qlocale.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Copyright (C) 2019 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
@@ -304,7 +304,8 @@ QByteArray QLocaleId::name(char separator) const
(script_id != QLocale::AnyScript ? script_code_list + 4 * script_id : nullptr);
const unsigned char *country =
(country_id != QLocale::AnyCountry ? country_code_list + 3 * country_id : nullptr);
- char len = (lang[2] != 0 ? 3 : 2) + (script ? 4+1 : 0) + (country ? (country[2] != 0 ? 3 : 2)+1 : 0);
+ char len = (lang[2] != 0 ? 3 : 2) + (script ? 4 + 1 : 0)
+ + (country ? (country[2] != 0 ? 3 : 2) + 1 : 0);
QByteArray name(len, Qt::Uninitialized);
char *uc = name.data();
*uc++ = lang[0];
@@ -335,7 +336,8 @@ QByteArray QLocalePrivate::bcp47Name(char separator) const
if (m_data->m_language_id == QLocale::C)
return QByteArrayLiteral("en");
- QLocaleId localeId = QLocaleId::fromIds(m_data->m_language_id, m_data->m_script_id, m_data->m_country_id);
+ QLocaleId localeId = QLocaleId::fromIds(m_data->m_language_id, m_data->m_script_id,
+ m_data->m_country_id);
return localeId.withLikelySubtagsRemoved().name(separator);
}
@@ -367,8 +369,10 @@ static const QLocaleData *findLocaleDataById(const QLocaleId &localeId)
} while (data->m_language_id && data->m_language_id == localeId.language_id);
} else {
do {
- if (data->m_script_id == localeId.script_id && data->m_country_id == localeId.country_id)
+ if (data->m_script_id == localeId.script_id
+ && data->m_country_id == localeId.country_id) {
return data;
+ }
++data;
} while (data->m_language_id && data->m_language_id == localeId.language_id);
}
@@ -376,7 +380,8 @@ static const QLocaleData *findLocaleDataById(const QLocaleId &localeId)
return nullptr;
}
-const QLocaleData *QLocaleData::findLocaleData(QLocale::Language language, QLocale::Script script, QLocale::Country country)
+const QLocaleData *QLocaleData::findLocaleData(QLocale::Language language, QLocale::Script script,
+ QLocale::Country country)
{
QLocaleId localeId = QLocaleId::fromIds(language, script, country);
QLocaleId likelyId = localeId.withLikelySubtagsAdded();
@@ -438,7 +443,8 @@ const QLocaleData *QLocaleData::findLocaleData(QLocale::Language language, QLoca
return locale_data + idx;
}
-static bool parse_locale_tag(const QString &input, int &i, QString *result, const QString &separators)
+static bool parse_locale_tag(const QString &input, int &i, QString *result,
+ const QString &separators)
{
*result = QString(8, Qt::Uninitialized); // worst case according to BCP47
QChar *pch = result->data();
@@ -487,7 +493,8 @@ bool qt_splitLocaleName(const QString &name, QString &lang, QString &script, QSt
state = ScriptState;
break;
case ScriptState: {
- QString scripts = QString::fromLatin1((const char *)script_code_list, sizeof(script_code_list) - 1);
+ QString scripts = QString::fromLatin1((const char *)script_code_list,
+ sizeof(script_code_list) - 1);
if (value.length() == 4 && scripts.indexOf(value) % 4 == 0) {
// script name is always 4 characters
script = value;
@@ -560,8 +567,8 @@ QString qt_readEscapedFormatString(QStringView format, int *idx)
while (i < format.size()) {
if (format.at(i).unicode() == '\'') {
- if (i + 1 < format.size() && format.at(i + 1).unicode() == '\'') {
- // "''" inside of a quoted string
+ if (format.mid(i + 1).startsWith(QLatin1Char('\''))) {
+ // "''" inside a quoted string
result.append(QLatin1Char('\''));
i += 2;
} else {
@@ -610,7 +617,8 @@ static QLocale::NumberOptions default_number_options = QLocale::DefaultNumberOpt
static const QLocaleData *const c_data = locale_data;
static QLocalePrivate *c_private()
{
- static QLocalePrivate c_locale = { c_data, Q_BASIC_ATOMIC_INITIALIZER(1), QLocale::OmitGroupSeparator };
+ static QLocalePrivate c_locale =
+ { c_data, Q_BASIC_ATOMIC_INITIALIZER(1), QLocale::OmitGroupSeparator };
return &c_locale;
}
@@ -833,9 +841,11 @@ QLocale::QLocale(QLocalePrivate &dd)
"language[_script][_country][.codeset][@modifier]" or "C", where:
\list
- \li language is a lowercase, two-letter, ISO 639 language code (also some three-letter codes),
+ \li language is a lowercase, two-letter, ISO 639 language code (also some
+ three-letter codes),
\li script is a titlecase, four-letter, ISO 15924 script code,
- \li country is an uppercase, two-letter, ISO 3166 country code (also "419" as defined by United Nations),
+ \li country is an uppercase, two-letter, ISO 3166 country code
+ (also "419" as defined by United Nations),
\li and codeset and modifier are ignored.
\endlist
@@ -1036,9 +1046,11 @@ QString QLocale::quoteString(const QStringRef &str, QuotationStyle style) const
if (d->m_data == systemData()) {
QVariant res;
if (style == QLocale::AlternateQuotation)
- res = systemLocale()->query(QSystemLocale::StringToAlternateQuotation, QVariant::fromValue(str));
+ res = systemLocale()->query(QSystemLocale::StringToAlternateQuotation,
+ QVariant::fromValue(str));
if (res.isNull() || style == QLocale::StandardQuotation)
- res = systemLocale()->query(QSystemLocale::StringToStandardQuotation, QVariant::fromValue(str));
+ res = systemLocale()->query(QSystemLocale::StringToStandardQuotation,
+ QVariant::fromValue(str));
if (!res.isNull())
return res.toString();
}
@@ -1046,8 +1058,9 @@ QString QLocale::quoteString(const QStringRef &str, QuotationStyle style) const
if (style == QLocale::StandardQuotation)
return QChar(d->m_data->m_quotation_start) % str % QChar(d->m_data->m_quotation_end);
- else
- return QChar(d->m_data->m_alternate_quotation_start) % str % QChar(d->m_data->m_alternate_quotation_end);
+
+ return QChar(d->m_data->m_alternate_quotation_start)
+ % str % QChar(d->m_data->m_alternate_quotation_end);
}
/*!
@@ -1060,8 +1073,8 @@ QString QLocale::createSeparatedList(const QStringList &list) const
{
#ifndef QT_NO_SYSTEMLOCALE
if (d->m_data == systemData()) {
- QVariant res;
- res = systemLocale()->query(QSystemLocale::ListToSeparatedString, QVariant::fromValue(list));
+ QVariant res =
+ systemLocale()->query(QSystemLocale::ListToSeparatedString, QVariant::fromValue(list));
if (!res.isNull())
return res.toString();
@@ -1072,12 +1085,20 @@ QString QLocale::createSeparatedList(const QStringList &list) const
if (size == 1) {
return list.at(0);
} else if (size == 2) {
- QString format = getLocaleData(list_pattern_part_data + d->m_data->m_list_pattern_part_two_idx, d->m_data->m_list_pattern_part_two_size);
+ QString format = getLocaleData(
+ list_pattern_part_data + d->m_data->m_list_pattern_part_two_idx,
+ d->m_data->m_list_pattern_part_two_size);
return format.arg(list.at(0), list.at(1));
} else if (size > 2) {
- QString formatStart = getLocaleData(list_pattern_part_data + d->m_data->m_list_pattern_part_start_idx, d->m_data->m_list_pattern_part_start_size);
- QString formatMid = getLocaleData(list_pattern_part_data + d->m_data->m_list_pattern_part_mid_idx, d->m_data->m_list_pattern_part_mid_size);
- QString formatEnd = getLocaleData(list_pattern_part_data + d->m_data->m_list_pattern_part_end_idx, d->m_data->m_list_pattern_part_end_size);
+ QString formatStart = getLocaleData(
+ list_pattern_part_data + d->m_data->m_list_pattern_part_start_idx,
+ d->m_data->m_list_pattern_part_start_size);
+ QString formatMid = getLocaleData(
+ list_pattern_part_data + d->m_data->m_list_pattern_part_mid_idx,
+ d->m_data->m_list_pattern_part_mid_size);
+ QString formatEnd = getLocaleData(
+ list_pattern_part_data + d->m_data->m_list_pattern_part_end_idx,
+ d->m_data->m_list_pattern_part_end_size);
QString result = formatStart.arg(list.at(0), list.at(1));
for (int i = 2; i < size - 1; ++i)
result = formatMid.arg(result, list.at(i));
@@ -1187,7 +1208,8 @@ static qulonglong toIntegral_helper(const QLocaleData *d, QStringView str, bool
template <typename T> static inline
T toIntegral_helper(const QLocalePrivate *d, QStringView str, bool *ok)
{
- using Int64 = typename std::conditional<std::is_unsigned<T>::value, qulonglong, qlonglong>::type;
+ using Int64 =
+ typename std::conditional<std::is_unsigned<T>::value, qulonglong, qlonglong>::type;
// we select the right overload by the last, unused parameter
Int64 val = toIntegral_helper(d->m_data, str, ok, d->m_numberOptions, Int64());
@@ -1203,8 +1225,8 @@ T toIntegral_helper(const QLocalePrivate *d, QStringView str, bool *ok)
/*!
\since 4.8
- Returns the dash-separated language, script and country (and possibly other BCP47 fields)
- of this locale as a string.
+ Returns the dash-separated language, script and country (and possibly other
+ BCP47 fields) of this locale as a string.
Unlike the uiLanguages() the returned value of the bcp47Name() represents
the locale name of the QLocale data but not the language the user-interface
@@ -1966,7 +1988,8 @@ QString QLocale::toString(const QDate &date, FormatType format) const
#ifndef QT_NO_SYSTEMLOCALE
if (d->m_data == systemData()) {
QVariant res = systemLocale()->query(format == LongFormat
- ? QSystemLocale::DateToStringLong : QSystemLocale::DateToStringShort,
+ ? QSystemLocale::DateToStringLong
+ : QSystemLocale::DateToStringShort,
date);
if (!res.isNull())
return res.toString();
@@ -2094,7 +2117,8 @@ QString QLocale::toString(const QTime &time, FormatType format) const
#ifndef QT_NO_SYSTEMLOCALE
if (d->m_data == systemData()) {
QVariant res = systemLocale()->query(format == LongFormat
- ? QSystemLocale::TimeToStringLong : QSystemLocale::TimeToStringShort,
+ ? QSystemLocale::TimeToStringLong
+ : QSystemLocale::TimeToStringShort,
time);
if (!res.isNull())
return res.toString();
@@ -2121,7 +2145,8 @@ QString QLocale::dateFormat(FormatType format) const
#ifndef QT_NO_SYSTEMLOCALE
if (d->m_data == systemData()) {
QVariant res = systemLocale()->query(format == LongFormat
- ? QSystemLocale::DateFormatLong : QSystemLocale::DateFormatShort,
+ ? QSystemLocale::DateFormatLong
+ : QSystemLocale::DateFormatShort,
QVariant());
if (!res.isNull())
return res.toString();
@@ -2158,7 +2183,8 @@ QString QLocale::timeFormat(FormatType format) const
#ifndef QT_NO_SYSTEMLOCALE
if (d->m_data == systemData()) {
QVariant res = systemLocale()->query(format == LongFormat
- ? QSystemLocale::TimeFormatLong : QSystemLocale::TimeFormatShort,
+ ? QSystemLocale::TimeFormatLong
+ : QSystemLocale::TimeFormatShort,
QVariant());
if (!res.isNull())
return res.toString();
@@ -2499,8 +2525,8 @@ QString QLocale::toString(double i, char f, int prec) const
/*!
Returns a QLocale object initialized to the system locale.
- On Windows and Mac, this locale will use the decimal/grouping characters and date/time
- formats specified in the system configuration panel.
+ On Windows and Mac, this locale will use the decimal/grouping characters and
+ date/time formats specified in the system configuration panel.
\sa c()
*/
@@ -2521,10 +2547,12 @@ QLocale QLocale::system()
script and \a country.
Getting a list of all locales:
- QList<QLocale> allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
+ QList<QLocale> allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript,
+ QLocale::AnyCountry);
Getting a list of locales suitable for Russia:
- QList<QLocale> locales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::Russia);
+ QList<QLocale> locales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript,
+ QLocale::Russia);
*/
QList<QLocale> QLocale::matchingLocales(QLocale::Language language,
QLocale::Script script,
@@ -2538,8 +2566,10 @@ QList<QLocale> QLocale::matchingLocales(QLocale::Language language,
return QList<QLocale>() << QLocale(QLocale::C);
QList<QLocale> result;
- if (language == QLocale::AnyLanguage && script == QLocale::AnyScript && country == QLocale::AnyCountry)
+ if (language == QLocale::AnyLanguage && script == QLocale::AnyScript
+ && country == QLocale::AnyCountry) {
result.reserve(locale_data_size);
+ }
const QLocaleData *data = locale_data + locale_index[language];
while ( (data != locale_data + locale_data_size)
&& (language == QLocale::AnyLanguage || data->m_language_id == uint(language))) {
@@ -2599,7 +2629,8 @@ QString QLocale::monthName(int month, FormatType type) const
#ifndef QT_NO_SYSTEMLOCALE
if (d->m_data == systemData()) {
QVariant res = systemLocale()->query(type == LongFormat
- ? QSystemLocale::MonthNameLong : QSystemLocale::MonthNameShort,
+ ? QSystemLocale::MonthNameLong
+ : QSystemLocale::MonthNameShort,
month);
if (!res.isNull())
return res.toString();
@@ -2645,7 +2676,8 @@ QString QLocale::standaloneMonthName(int month, FormatType type) const
#ifndef QT_NO_SYSTEMLOCALE
if (d->m_data == systemData()) {
QVariant res = systemLocale()->query(type == LongFormat
- ? QSystemLocale::StandaloneMonthNameLong : QSystemLocale::StandaloneMonthNameShort,
+ ? QSystemLocale::StandaloneMonthNameLong
+ : QSystemLocale::StandaloneMonthNameShort,
month);
if (!res.isNull())
return res.toString();
@@ -2692,7 +2724,8 @@ QString QLocale::dayName(int day, FormatType type) const
#ifndef QT_NO_SYSTEMLOCALE
if (d->m_data == systemData()) {
QVariant res = systemLocale()->query(type == LongFormat
- ? QSystemLocale::DayNameLong : QSystemLocale::DayNameShort,
+ ? QSystemLocale::DayNameLong
+ : QSystemLocale::DayNameShort,
day);
if (!res.isNull())
return res.toString();
@@ -2741,7 +2774,8 @@ QString QLocale::standaloneDayName(int day, FormatType type) const
#ifndef QT_NO_SYSTEMLOCALE
if (d->m_data == systemData()) {
QVariant res = systemLocale()->query(type == LongFormat
- ? QSystemLocale::DayNameLong : QSystemLocale::DayNameShort,
+ ? QSystemLocale::DayNameLong
+ : QSystemLocale::DayNameShort,
day);
if (!res.isNull())
return res.toString();
@@ -3025,7 +3059,8 @@ QString QLocalePrivate::dateTimeToString(QStringView format, const QDateTime &da
case 4: {
const int yr = date.year();
const int len = (yr < 0) ? 5 : 4;
- result.append(m_data->longLongToString(yr, -1, 10, len, QLocaleData::ZeroPadded));
+ result.append(m_data->longLongToString(yr, -1, 10, len,
+ QLocaleData::ZeroPadded));
break;
}
case 2:
@@ -3047,7 +3082,8 @@ QString QLocalePrivate::dateTimeToString(QStringView format, const QDateTime &da
result.append(m_data->longLongToString(date.month()));
break;
case 2:
- result.append(m_data->longLongToString(date.month(), -1, 10, 2, QLocaleData::ZeroPadded));
+ result.append(m_data->longLongToString(date.month(), -1, 10, 2,
+ QLocaleData::ZeroPadded));
break;
case 3:
result.append(q->monthName(date.month(), QLocale::ShortFormat));
@@ -3066,7 +3102,8 @@ QString QLocalePrivate::dateTimeToString(QStringView format, const QDateTime &da
result.append(m_data->longLongToString(date.day()));
break;
case 2:
- result.append(m_data->longLongToString(date.day(), -1, 10, 2, QLocaleData::ZeroPadded));
+ result.append(m_data->longLongToString(date.day(), -1, 10, 2,
+ QLocaleData::ZeroPadded));
break;
case 3:
result.append(q->dayName(date.dayOfWeek(), QLocale::ShortFormat));
@@ -3099,7 +3136,8 @@ QString QLocalePrivate::dateTimeToString(QStringView format, const QDateTime &da
result.append(m_data->longLongToString(hour));
break;
case 2:
- result.append(m_data->longLongToString(hour, -1, 10, 2, QLocaleData::ZeroPadded));
+ result.append(m_data->longLongToString(hour, -1, 10, 2,
+ QLocaleData::ZeroPadded));
break;
}
break;
@@ -3112,7 +3150,8 @@ QString QLocalePrivate::dateTimeToString(QStringView format, const QDateTime &da
result.append(m_data->longLongToString(time.hour()));
break;
case 2:
- result.append(m_data->longLongToString(time.hour(), -1, 10, 2, QLocaleData::ZeroPadded));
+ result.append(m_data->longLongToString(time.hour(), -1, 10, 2,
+ QLocaleData::ZeroPadded));
break;
}
break;
@@ -3125,7 +3164,8 @@ QString QLocalePrivate::dateTimeToString(QStringView format, const QDateTime &da
result.append(m_data->longLongToString(time.minute()));
break;
case 2:
- result.append(m_data->longLongToString(time.minute(), -1, 10, 2, QLocaleData::ZeroPadded));
+ result.append(m_data->longLongToString(time.minute(), -1, 10, 2,
+ QLocaleData::ZeroPadded));
break;
}
break;
@@ -3138,42 +3178,32 @@ QString QLocalePrivate::dateTimeToString(QStringView format, const QDateTime &da
result.append(m_data->longLongToString(time.second()));
break;
case 2:
- result.append(m_data->longLongToString(time.second(), -1, 10, 2, QLocaleData::ZeroPadded));
+ result.append(m_data->longLongToString(time.second(), -1, 10, 2,
+ QLocaleData::ZeroPadded));
break;
}
break;
case 'a':
used = true;
- if (i + 1 < format.size() && format.at(i + 1).unicode() == 'p') {
- repeat = 2;
- } else {
- repeat = 1;
- }
+ repeat = format.mid(i + 1).startsWith(QLatin1Char('p')) ? 2 : 1;
result.append(time.hour() < 12 ? q->amText().toLower() : q->pmText().toLower());
break;
case 'A':
used = true;
- if (i + 1 < format.size() && format.at(i + 1).unicode() == 'P') {
- repeat = 2;
- } else {
- repeat = 1;
- }
+ repeat = format.mid(i + 1).startsWith(QLatin1Char('P')) ? 2 : 1;
result.append(time.hour() < 12 ? q->amText().toUpper() : q->pmText().toUpper());
break;
case 'z':
used = true;
- if (repeat >= 3) {
- repeat = 3;
- } else {
- repeat = 1;
- }
+ repeat = (repeat >= 3) ? 3 : 1;
// note: the millisecond component is treated like the decimal part of the seconds
// so ms == 2 is always printed as "002", but ms == 200 can be either "2" or "200"
- result.append(m_data->longLongToString(time.msec(), -1, 10, 3, QLocaleData::ZeroPadded));
+ result.append(m_data->longLongToString(time.msec(), -1, 10, 3,
+ QLocaleData::ZeroPadded));
if (repeat == 1) {
if (result.endsWith(zero()))
result.chop(1);
@@ -3187,20 +3217,16 @@ QString QLocalePrivate::dateTimeToString(QStringView format, const QDateTime &da
used = true;
repeat = 1;
// If we have a QDateTime use the time spec otherwise use the current system tzname
- if (formatDate) {
- result.append(datetime.timeZoneAbbreviation());
- } else {
- result.append(QDateTime::currentDateTime().timeZoneAbbreviation());
- }
+ result.append(formatDate ? datetime.timeZoneAbbreviation()
+ : QDateTime::currentDateTime().timeZoneAbbreviation());
break;
default:
break;
}
}
- if (!used) {
+ if (!used)
result.append(QString(repeat, c));
- }
i += repeat;
}
@@ -3216,7 +3242,8 @@ QString QLocaleData::doubleToString(double d, int precision, DoubleForm form,
QString QLocaleData::doubleToString(const QChar _zero, const QChar plus, const QChar minus,
const QChar exponential, const QChar group, const QChar decimal,
- double d, int precision, DoubleForm form, int width, unsigned flags)
+ double d, int precision, DoubleForm form, int width,
+ unsigned flags)
{
if (precision != QLocale::FloatingPointShortest && precision < 0)
precision = 6;
@@ -3589,11 +3616,14 @@ bool QLocaleData::numberToCLocale(QStringView s, QLocale::NumberOptions number_o
return false;
// check distance from the last separator or from the beginning of the digits
- // ### FIXME: Some locales allow other groupings! See https://en.wikipedia.org/wiki/Thousands_separator
+ // ### FIXME: Some locales allow other groupings!
+ // See https://en.wikipedia.org/wiki/Thousands_separator
if (last_separator_idx != -1 && idx - last_separator_idx != 4)
return false;
- if (last_separator_idx == -1 && (start_of_digits_idx == -1 || idx - start_of_digits_idx > 3))
+ if (last_separator_idx == -1
+ && (start_of_digits_idx == -1 || idx - start_of_digits_idx > 3)) {
return false;
+ }
last_separator_idx = idx;
++group_cnt;
@@ -3603,7 +3633,8 @@ bool QLocaleData::numberToCLocale(QStringView s, QLocale::NumberOptions number_o
continue;
} else if (out == '.' || out == 'e' || out == 'E') {
// check distance from the last separator
- // ### FIXME: Some locales allow other groupings! See https://en.wikipedia.org/wiki/Thousands_separator
+ // ### FIXME: Some locales allow other groupings!
+ // See https://en.wikipedia.org/wiki/Thousands_separator
if (last_separator_idx != -1 && idx - last_separator_idx != 4)
return false;
@@ -3663,9 +3694,10 @@ bool QLocaleData::validateChars(QStringView str, NumberMode numMode, QByteArray
// The only non-digit character after the 'e' can be '+' or '-'.
// If a zero is directly after that, then the exponent is zero-padded.
- if ((number_options & QLocale::RejectLeadingZeroInExponent) && c == '0' && eCnt > 0 &&
- !lastWasDigit)
+ if ((number_options & QLocale::RejectLeadingZeroInExponent)
+ && c == '0' && eCnt > 0 && !lastWasDigit) {
return false;
+ }
lastWasDigit = true;
} else {
@@ -3917,7 +3949,8 @@ QString QLocale::toCurrencyString(qlonglong value, const QString &symbol) const
#ifndef QT_NO_SYSTEMLOCALE
if (d->m_data == systemData()) {
QSystemLocale::CurrencyToStringArgument arg(value, symbol);
- QVariant res = systemLocale()->query(QSystemLocale::CurrencyToString, QVariant::fromValue(arg));
+ QVariant res =
+ systemLocale()->query(QSystemLocale::CurrencyToString, QVariant::fromValue(arg));
if (!res.isNull())
return res.toString();
}
@@ -3947,7 +3980,8 @@ QString QLocale::toCurrencyString(qulonglong value, const QString &symbol) const
#ifndef QT_NO_SYSTEMLOCALE
if (d->m_data == systemData()) {
QSystemLocale::CurrencyToStringArgument arg(value, symbol);
- QVariant res = systemLocale()->query(QSystemLocale::CurrencyToString, QVariant::fromValue(arg));
+ QVariant res =
+ systemLocale()->query(QSystemLocale::CurrencyToString, QVariant::fromValue(arg));
if (!res.isNull())
return res.toString();
}
@@ -3989,7 +4023,8 @@ QString QLocale::toCurrencyString(double value, const QString &symbol, int preci
#ifndef QT_NO_SYSTEMLOCALE
if (d->m_data == systemData()) {
QSystemLocale::CurrencyToStringArgument arg(value, symbol);
- QVariant res = systemLocale()->query(QSystemLocale::CurrencyToString, QVariant::fromValue(arg));
+ QVariant res =
+ systemLocale()->query(QSystemLocale::CurrencyToString, QVariant::fromValue(arg));
if (!res.isNull())
return res.toString();
}
@@ -4126,7 +4161,8 @@ QStringList QLocale::uiLanguages() const
}
}
#endif
- QLocaleId id = QLocaleId::fromIds(d->m_data->m_language_id, d->m_data->m_script_id, d->m_data->m_country_id);
+ 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();
@@ -4182,7 +4218,8 @@ QString QLocale::nativeLanguageName() const
return res.toString();
}
#endif
- return getLocaleData(endonyms_data + d->m_data->m_language_endonym_idx, d->m_data->m_language_endonym_size);
+ return getLocaleData(endonyms_data + d->m_data->m_language_endonym_idx,
+ d->m_data->m_language_endonym_size);
}
/*!
@@ -4202,7 +4239,8 @@ QString QLocale::nativeCountryName() const
return res.toString();
}
#endif
- return getLocaleData(endonyms_data + d->m_data->m_country_endonym_idx, d->m_data->m_country_endonym_size);
+ return getLocaleData(endonyms_data + d->m_data->m_country_endonym_idx,
+ d->m_data->m_country_endonym_size);
}
#ifndef QT_NO_DEBUG_STREAM
diff --git a/src/corelib/tools/qlocale.h b/src/corelib/text/qlocale.h
index 09de830ca3..09de830ca3 100644
--- a/src/corelib/tools/qlocale.h
+++ b/src/corelib/text/qlocale.h
diff --git a/src/corelib/tools/qlocale.qdoc b/src/corelib/text/qlocale.qdoc
index 426cb9dbeb..426cb9dbeb 100644
--- a/src/corelib/tools/qlocale.qdoc
+++ b/src/corelib/text/qlocale.qdoc
diff --git a/src/corelib/tools/qlocale_data_p.h b/src/corelib/text/qlocale_data_p.h
index 2c351a3fb1..2c351a3fb1 100644
--- a/src/corelib/tools/qlocale_data_p.h
+++ b/src/corelib/text/qlocale_data_p.h
diff --git a/src/corelib/tools/qlocale_icu.cpp b/src/corelib/text/qlocale_icu.cpp
index afe0aae583..afe0aae583 100644
--- a/src/corelib/tools/qlocale_icu.cpp
+++ b/src/corelib/text/qlocale_icu.cpp
diff --git a/src/corelib/tools/qlocale_mac.mm b/src/corelib/text/qlocale_mac.mm
index 9719278426..9719278426 100644
--- a/src/corelib/tools/qlocale_mac.mm
+++ b/src/corelib/text/qlocale_mac.mm
diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/text/qlocale_p.h
index 1e3da35a02..37afb8542b 100644
--- a/src/corelib/tools/qlocale_p.h
+++ b/src/corelib/text/qlocale_p.h
@@ -285,9 +285,9 @@ public:
quint16 m_language_id, m_script_id, m_country_id;
// FIXME QTBUG-69324: not all unicode code-points map to single-token UTF-16 :-(
- quint16 m_decimal, m_group, m_list, m_percent, m_zero, m_minus, m_plus, m_exponential;
- quint16 m_quotation_start, m_quotation_end;
- quint16 m_alternate_quotation_start, m_alternate_quotation_end;
+ char16_t m_decimal, m_group, m_list, m_percent, m_zero, m_minus, m_plus, m_exponential;
+ char16_t m_quotation_start, m_quotation_end;
+ char16_t m_alternate_quotation_start, m_alternate_quotation_end;
quint16 m_list_pattern_part_start_idx, m_list_pattern_part_start_size;
quint16 m_list_pattern_part_mid_idx, m_list_pattern_part_mid_size;
@@ -417,7 +417,7 @@ inline char QLocaleData::digitToCLocale(QChar in) const
if (in == m_group)
return ',';
- if (in == m_exponential || in == QChar::toUpper(m_exponential))
+ if (in == m_exponential || in == QChar(QChar::toUpper(m_exponential)))
return 'e';
// In several languages group() is a non-breaking space (U+00A0) or its thin
diff --git a/src/corelib/tools/qlocale_tools.cpp b/src/corelib/text/qlocale_tools.cpp
index db8c8cd12f..db8c8cd12f 100644
--- a/src/corelib/tools/qlocale_tools.cpp
+++ b/src/corelib/text/qlocale_tools.cpp
diff --git a/src/corelib/tools/qlocale_tools_p.h b/src/corelib/text/qlocale_tools_p.h
index 594331ae37..594331ae37 100644
--- a/src/corelib/tools/qlocale_tools_p.h
+++ b/src/corelib/text/qlocale_tools_p.h
diff --git a/src/corelib/tools/qlocale_unix.cpp b/src/corelib/text/qlocale_unix.cpp
index ff4274d932..ff4274d932 100644
--- a/src/corelib/tools/qlocale_unix.cpp
+++ b/src/corelib/text/qlocale_unix.cpp
diff --git a/src/corelib/tools/qlocale_win.cpp b/src/corelib/text/qlocale_win.cpp
index dc904ad02d..dc904ad02d 100644
--- a/src/corelib/tools/qlocale_win.cpp
+++ b/src/corelib/text/qlocale_win.cpp
diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/text/qregexp.cpp
index dd38ba0360..d81826b47b 100644
--- a/src/corelib/tools/qregexp.cpp
+++ b/src/corelib/text/qregexp.cpp
@@ -2035,7 +2035,7 @@ bool QRegExpMatchState::matchHere()
#ifndef QT_NO_REGEXP_CCLASS
const QRegExpCharClass &cc = eng->cl.at(m ^ QRegExpEngine::CharClassBit);
if (eng->cs)
- inside = cc.in(ch);
+ inside = cc.in(QChar(ch));
else if (cc.negative())
inside = cc.in(QChar(ch).toLower()) &&
cc.in(QChar(ch).toUpper());
diff --git a/src/corelib/tools/qregexp.h b/src/corelib/text/qregexp.h
index 8f6de24c74..8f6de24c74 100644
--- a/src/corelib/tools/qregexp.h
+++ b/src/corelib/text/qregexp.h
diff --git a/src/corelib/tools/qregularexpression.cpp b/src/corelib/text/qregularexpression.cpp
index 17acd476b2..17acd476b2 100644
--- a/src/corelib/tools/qregularexpression.cpp
+++ b/src/corelib/text/qregularexpression.cpp
diff --git a/src/corelib/tools/qregularexpression.h b/src/corelib/text/qregularexpression.h
index f799a38ae4..f799a38ae4 100644
--- a/src/corelib/tools/qregularexpression.h
+++ b/src/corelib/text/qregularexpression.h
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/text/qstring.cpp
index 47db97cdfc..375843e36e 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -49,8 +49,8 @@
#include <qtextcodec.h>
#endif
#include <private/qutfcodec_p.h>
-#include <private/qlocale_tools_p.h>
-#include "qsimd_p.h"
+#include "qlocale_tools_p.h"
+#include "private/qsimd_p.h"
#include <qnumeric.h>
#include <qdatastream.h>
#include <qlist.h>
@@ -59,7 +59,6 @@
#include "qstringbuilder.h"
#include "qstringmatcher.h"
#include "qvarlengtharray.h"
-#include "qtools_p.h"
#include "qdebug.h"
#include "qendian.h"
#include "qcollator.h"
@@ -2092,7 +2091,7 @@ int QString::toUcs4_helper(const ushort *uc, int length, uint *out)
If \a size is negative, \a unicode is assumed to point to a \\0'-terminated
array and its length is determined dynamically. The terminating
- nul-character is not considered part of the string.
+ null character is not considered part of the string.
QString makes a deep copy of the string data. The unicode data is copied as
is and the Byte Order Mark is preserved if present.
@@ -3208,7 +3207,7 @@ QString& QString::replace(QChar ch, const QString &after, Qt::CaseSensitivity cs
return remove(ch, cs);
if (after.d->size == 1)
- return replace(ch, after.d->data()[0], cs);
+ return replace(ch, after.front(), cs);
if (d->size == 0)
return *this;
@@ -5770,7 +5769,7 @@ QString QString::trimmed_helper(QString &str)
The return value is of type QCharRef, a helper class for QString.
When you get an object of type QCharRef, you can use it as if it
- were a QChar &. If you assign to it, the assignment will apply to
+ were a reference to a QChar. If you assign to it, the assignment will apply to
the character in the QString from which you got the reference.
\note Before Qt 5.14 it was possible to use this operator to access
@@ -6666,7 +6665,7 @@ static QString detachAndConvertCase(T &str, QStringIterator it)
} else if (Q_UNLIKELY(QChar::requiresSurrogates(uc))) {
// so far, case convertion never changes planes (guaranteed by the qunicodetables generator)
pp++;
- *pp++ = QChar::lowSurrogate(uc + caseDiff);
+ *pp++ = QChar(QChar::lowSurrogate(uc + caseDiff));
} else {
*pp++ = QChar(uc + caseDiff);
}
@@ -11439,7 +11438,7 @@ bool QStringRef::isRightToLeft() const
\sa QString::isRightToLeft()
*/
-bool QtPrivate::isRightToLeft(QStringView string)
+bool QtPrivate::isRightToLeft(QStringView string) noexcept
{
const ushort *p = reinterpret_cast<const ushort*>(string.data());
const ushort * const end = p + string.size();
diff --git a/src/corelib/tools/qstring.h b/src/corelib/text/qstring.h
index 6788e53057..88286b902a 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/text/qstring.h
@@ -89,6 +89,10 @@ class QTextCodec;
class QStringRef;
template <typename T> class QVector;
+namespace QtPrivate {
+template <bool...B> class BoolList;
+}
+
class QLatin1String
{
public:
@@ -231,7 +235,7 @@ QT_DEPRECATED_X("Use QLatin1String") typedef QLatin1String QLatin1Literal;
//
// QLatin1String inline implementations
//
-inline bool QtPrivate::isLatin1(QLatin1String) noexcept
+Q_DECL_CONSTEXPR bool QtPrivate::isLatin1(QLatin1String) noexcept
{ return true; }
//
@@ -333,6 +337,7 @@ public:
QChar fillChar = QLatin1Char(' ')) const;
Q_REQUIRED_RESULT QString arg(QLatin1String a, int fieldWidth = 0,
QChar fillChar = QLatin1Char(' ')) const;
+#if QT_STRINGVIEW_LEVEL < 2
Q_REQUIRED_RESULT QString arg(const QString &a1, const QString &a2) const;
Q_REQUIRED_RESULT QString arg(const QString &a1, const QString &a2, const QString &a3) const;
Q_REQUIRED_RESULT QString arg(const QString &a1, const QString &a2, const QString &a3,
@@ -350,6 +355,33 @@ public:
Q_REQUIRED_RESULT QString arg(const QString &a1, const QString &a2, const QString &a3,
const QString &a4, const QString &a5, const QString &a6,
const QString &a7, const QString &a8, const QString &a9) const;
+#endif
+private:
+ template <typename T>
+ struct is_convertible_to_view_or_qstring_helper
+ : std::integral_constant<bool,
+ std::is_convertible<T, QString>::value ||
+ std::is_convertible<T, QStringView>::value ||
+ std::is_convertible<T, QLatin1String>::value> {};
+ template <typename T>
+ struct is_convertible_to_view_or_qstring
+ : is_convertible_to_view_or_qstring_helper<typename std::decay<T>::type> {};
+public:
+ template <typename...Args>
+ Q_REQUIRED_RESULT
+#ifdef Q_CLANG_QDOC
+ QString
+#else
+ typename std::enable_if<
+ sizeof...(Args) >= 2 && std::is_same<
+ QtPrivate::BoolList<is_convertible_to_view_or_qstring<Args>::value..., true>,
+ QtPrivate::BoolList<true, is_convertible_to_view_or_qstring<Args>::value...>
+ >::value,
+ QString
+ >::type
+#endif
+ arg(Args &&...args) const
+ { return qToStringViewIgnoringNull(*this).arg(std::forward<Args>(args)...); }
#if QT_DEPRECATED_SINCE(5, 14)
QT_DEPRECATED_X("Use vasprintf(), arg() or QTextStream instead")
@@ -1002,11 +1034,11 @@ inline QString::QString(QLatin1String aLatin1) : d(fromLatin1_helper(aLatin1.lat
inline int QString::length() const
{ return d->size; }
inline const QChar QString::at(int i) const
-{ Q_ASSERT(uint(i) < uint(size())); return d->data()[i]; }
+{ Q_ASSERT(uint(i) < uint(size())); return QChar(d->data()[i]); }
inline const QChar QString::operator[](int i) const
-{ Q_ASSERT(uint(i) < uint(size())); return d->data()[i]; }
+{ Q_ASSERT(uint(i) < uint(size())); return QChar(d->data()[i]); }
inline const QChar QString::operator[](uint i) const
-{ Q_ASSERT(i < uint(size())); return d->data()[i]; }
+{ Q_ASSERT(i < uint(size())); return QChar(d->data()[i]); }
inline bool QString::isEmpty() const
{ return d->size == 0; }
inline const QChar *QString::unicode() const
@@ -1053,6 +1085,7 @@ inline QString QString::arg(short a, int fieldWidth, int base, QChar fillChar) c
{ return arg(qlonglong(a), fieldWidth, base, fillChar); }
inline QString QString::arg(ushort a, int fieldWidth, int base, QChar fillChar) const
{ return arg(qulonglong(a), fieldWidth, base, fillChar); }
+#if QT_STRINGVIEW_LEVEL < 2
inline QString QString::arg(const QString &a1, const QString &a2) const
{ return qToStringViewIgnoringNull(*this).arg(a1, a2); }
inline QString QString::arg(const QString &a1, const QString &a2, const QString &a3) const
@@ -1078,6 +1111,7 @@ inline QString QString::arg(const QString &a1, const QString &a2, const QString
const QString &a4, const QString &a5, const QString &a6,
const QString &a7, const QString &a8, const QString &a9) const
{ return qToStringViewIgnoringNull(*this).arg(a1, a2, a3, a4, a5, a6, a7, a8, a9); }
+#endif
inline QString QString::section(QChar asep, int astart, int aend, SectionFlags aflags) const
{ return section(QString(asep), astart, aend, aflags); }
@@ -1088,7 +1122,19 @@ QT_WARNING_DISABLE_INTEL(111) // "statement is unreachable"
inline int QString::toWCharArray(wchar_t *array) const
{
- return QStringView(*this).toWCharArray(array);
+ return qToStringViewIgnoringNull(*this).toWCharArray(array);
+}
+
+int QStringView::toWCharArray(wchar_t *array) const
+{
+ if (sizeof(wchar_t) == sizeof(QChar)) {
+ if (auto src = data())
+ memcpy(array, src, sizeof(QChar) * size());
+ return size();
+ } else {
+ return QString::toUcs4_helper(reinterpret_cast<const ushort *>(data()), int(size()),
+ reinterpret_cast<uint *>(array));
+ }
}
QT_WARNING_POP
@@ -1118,11 +1164,11 @@ public:
{
using namespace QtPrivate::DeprecatedRefClassBehavior;
if (Q_LIKELY(i < s.d->size))
- return s.d->data()[i];
+ return QChar(s.d->data()[i]);
#ifdef QT_DEBUG
warn(WarningType::OutOfRange, EmittingClass::QCharRef);
#endif
- return 0;
+ return QChar();
}
inline QCharRef &operator=(QChar c)
{
@@ -2014,6 +2060,7 @@ Q_REQUIRED_RESULT Q_ALWAYS_INLINE QString argToQStringDispatch(StringView patter
return QtPrivate::argToQString(pattern, sizeof...(Args), argBases);
}
+ inline QStringViewArg qStringLikeToArg(const QString &s) noexcept { return QStringViewArg{qToStringViewIgnoringNull(s)}; }
Q_DECL_CONSTEXPR inline QStringViewArg qStringLikeToArg(QStringView s) noexcept { return QStringViewArg{s}; }
inline QStringViewArg qStringLikeToArg(const QChar &c) noexcept { return QStringViewArg{QStringView{&c, 1}}; }
Q_DECL_CONSTEXPR inline QLatin1StringArg qStringLikeToArg(QLatin1String s) noexcept { return QLatin1StringArg{s}; }
diff --git a/src/corelib/tools/qstring_compat.cpp b/src/corelib/text/qstring_compat.cpp
index 45bb816e4b..45bb816e4b 100644
--- a/src/corelib/tools/qstring_compat.cpp
+++ b/src/corelib/text/qstring_compat.cpp
diff --git a/src/corelib/tools/qstring_mips_dsp_asm.S b/src/corelib/text/qstring_mips_dsp_asm.S
index 202f322310..202f322310 100644
--- a/src/corelib/tools/qstring_mips_dsp_asm.S
+++ b/src/corelib/text/qstring_mips_dsp_asm.S
diff --git a/src/corelib/tools/qstringalgorithms.h b/src/corelib/text/qstringalgorithms.h
index 2b480b1e4c..d54e376aa9 100644
--- a/src/corelib/tools/qstringalgorithms.h
+++ b/src/corelib/text/qstringalgorithms.h
@@ -92,12 +92,13 @@ Q_REQUIRED_RESULT Q_CORE_EXPORT QByteArray convertToLatin1(QStringView str);
Q_REQUIRED_RESULT Q_CORE_EXPORT QByteArray convertToUtf8(QStringView str);
Q_REQUIRED_RESULT Q_CORE_EXPORT QByteArray convertToLocal8Bit(QStringView str);
Q_REQUIRED_RESULT Q_CORE_EXPORT QVector<uint> convertToUcs4(QStringView str);
-Q_REQUIRED_RESULT Q_CORE_EXPORT bool isRightToLeft(QStringView string);
-Q_REQUIRED_RESULT Q_CORE_EXPORT bool isAscii(QLatin1String s) noexcept;
-Q_REQUIRED_RESULT Q_CORE_EXPORT bool isAscii(QStringView s) noexcept;
-Q_REQUIRED_RESULT bool isLatin1(QLatin1String s) noexcept; // in qstring.h
-Q_REQUIRED_RESULT Q_CORE_EXPORT bool isLatin1(QStringView s) noexcept;
+Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isRightToLeft(QStringView string) noexcept;
+
+Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isAscii(QLatin1String s) noexcept;
+Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isAscii(QStringView s) noexcept;
+Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline bool isLatin1(QLatin1String s) noexcept;
+Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isLatin1(QStringView s) noexcept;
} // namespace QtPRivate
diff --git a/src/corelib/tools/qstringalgorithms_p.h b/src/corelib/text/qstringalgorithms_p.h
index 64d9f2e676..64d9f2e676 100644
--- a/src/corelib/tools/qstringalgorithms_p.h
+++ b/src/corelib/text/qstringalgorithms_p.h
diff --git a/src/corelib/tools/qstringbuilder.cpp b/src/corelib/text/qstringbuilder.cpp
index cf443ec369..cf443ec369 100644
--- a/src/corelib/tools/qstringbuilder.cpp
+++ b/src/corelib/text/qstringbuilder.cpp
diff --git a/src/corelib/tools/qstringbuilder.h b/src/corelib/text/qstringbuilder.h
index b3cf2f695e..b3cf2f695e 100644
--- a/src/corelib/tools/qstringbuilder.h
+++ b/src/corelib/text/qstringbuilder.h
diff --git a/src/corelib/tools/qstringiterator.qdoc b/src/corelib/text/qstringiterator.qdoc
index 9d7c54ce9f..9d7c54ce9f 100644
--- a/src/corelib/tools/qstringiterator.qdoc
+++ b/src/corelib/text/qstringiterator.qdoc
diff --git a/src/corelib/tools/qstringiterator_p.h b/src/corelib/text/qstringiterator_p.h
index 219589b6e4..219589b6e4 100644
--- a/src/corelib/tools/qstringiterator_p.h
+++ b/src/corelib/text/qstringiterator_p.h
diff --git a/src/corelib/tools/qstringlist.cpp b/src/corelib/text/qstringlist.cpp
index 4bbe424ed2..4bbe424ed2 100644
--- a/src/corelib/tools/qstringlist.cpp
+++ b/src/corelib/text/qstringlist.cpp
diff --git a/src/corelib/tools/qstringlist.h b/src/corelib/text/qstringlist.h
index a464d443dc..a464d443dc 100644
--- a/src/corelib/tools/qstringlist.h
+++ b/src/corelib/text/qstringlist.h
diff --git a/src/corelib/tools/qstringliteral.h b/src/corelib/text/qstringliteral.h
index 603f19c0b4..603f19c0b4 100644
--- a/src/corelib/tools/qstringliteral.h
+++ b/src/corelib/text/qstringliteral.h
diff --git a/src/corelib/tools/qstringmatcher.cpp b/src/corelib/text/qstringmatcher.cpp
index 167a467480..167a467480 100644
--- a/src/corelib/tools/qstringmatcher.cpp
+++ b/src/corelib/text/qstringmatcher.cpp
diff --git a/src/corelib/tools/qstringmatcher.h b/src/corelib/text/qstringmatcher.h
index 6de4353930..6de4353930 100644
--- a/src/corelib/tools/qstringmatcher.h
+++ b/src/corelib/text/qstringmatcher.h
diff --git a/src/corelib/tools/qstringview.cpp b/src/corelib/text/qstringview.cpp
index cc852dd042..75de827583 100644
--- a/src/corelib/tools/qstringview.cpp
+++ b/src/corelib/text/qstringview.cpp
@@ -57,9 +57,8 @@ QT_BEGIN_NAMESPACE
The UTF-16 string may be represented as an array (or an array-compatible
data-structure such as QString,
- std::basic_string, etc.) of QChar, \c ushort, \c char16_t (on compilers that
- support C++11 Unicode strings) or (on platforms, such as Windows,
- where it is a 16-bit type) \c wchar_t.
+ std::basic_string, etc.) of QChar, \c ushort, \c char16_t or
+ (on platforms, such as Windows, where it is a 16-bit type) \c wchar_t.
QStringView is designed as an interface type; its main use-case is
as a function parameter type. When QStringViews are used as automatic
@@ -115,8 +114,7 @@ QT_BEGIN_NAMESPACE
/*!
\typedef QStringView::storage_type
- Alias for \c{char16_t} for non-Windows or if Q_COMPILER_UNICODE_STRINGS
- is defined. Otherwise, alias for \c{wchar_t}.
+ Alias for \c{char16_t}.
*/
/*!
@@ -532,6 +530,7 @@ QT_BEGIN_NAMESPACE
/*!
\fn QString QStringView::arg(Args &&...args) const
\fn QString QLatin1String::arg(Args &&...args) const
+ \fn QString QString::arg(Args &&...args) const
\since 5.14
Replaces occurrences of \c{%N} in this string with the corresponding
@@ -539,8 +538,8 @@ QT_BEGIN_NAMESPACE
the \a args replaces the \c{%N} with the lowest \c{N} (all of them), the
second of the \a args the \c{%N} with the next-lowest \c{N} etc.
- \c Args can consist of anything that implicitly converts to QStringView
- or QLatin1String.
+ \c Args can consist of anything that implicitly converts to QString,
+ QStringView or QLatin1String.
In addition, the following types are also supported: QChar, QLatin1Char.
@@ -866,11 +865,12 @@ QT_BEGIN_NAMESPACE
*/
/*!
+ \fn QStringView::toWCharArray(wchar_t *array) const
\since 5.14
Transcribes this string into the given \a array.
- Caller is responsible for ensuring \a array is large enough to hold the
+ The caller is responsible for ensuring \a array is large enough to hold the
\c wchar_t encoding of this string (allocating the array with the same length
as the string is always sufficient). The array is encoded in UTF-16 on
platforms where \c wchar_t is 2 bytes wide (e.g. Windows); otherwise (Unix
@@ -884,15 +884,4 @@ QT_BEGIN_NAMESPACE
\sa QString::toWCharArray()
*/
-int QStringView::toWCharArray(wchar_t *array) const
-{
- if (sizeof(wchar_t) == sizeof(QChar)) {
- memcpy(array, data(), sizeof(QChar) * size());
- return size();
- } else {
- return QString::toUcs4_helper(reinterpret_cast<const ushort *>(data()), int(size()),
- reinterpret_cast<uint *>(array));
- }
-}
-
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qstringview.h b/src/corelib/text/qstringview.h
index b84b2995b9..0a82ac4201 100644
--- a/src/corelib/tools/qstringview.h
+++ b/src/corelib/text/qstringview.h
@@ -62,9 +62,7 @@ struct IsCompatibleCharTypeHelper
: std::integral_constant<bool,
std::is_same<Char, QChar>::value ||
std::is_same<Char, ushort>::value ||
-#if defined(Q_COMPILER_UNICODE_STRINGS)
std::is_same<Char, char16_t>::value ||
-#endif
(std::is_same<Char, wchar_t>::value && sizeof(wchar_t) == sizeof(QChar))> {};
template <typename Char>
struct IsCompatibleCharType
@@ -105,11 +103,7 @@ struct IsCompatibleStdBasicString
class QStringView
{
public:
-#if defined(Q_OS_WIN) && !defined(Q_COMPILER_UNICODE_STRINGS)
- typedef wchar_t storage_type;
-#else
typedef char16_t storage_type;
-#endif
typedef const QChar value_type;
typedef std::ptrdiff_t difference_type;
typedef qsizetype size_type;
@@ -294,7 +288,7 @@ public:
Q_REQUIRED_RESULT bool isRightToLeft() const noexcept
{ return QtPrivate::isRightToLeft(*this); }
- Q_REQUIRED_RESULT Q_CORE_EXPORT int toWCharArray(wchar_t *array) const;
+ Q_REQUIRED_RESULT inline int toWCharArray(wchar_t *array) const; // defined in qstring.h
//
// STL compatibility API:
diff --git a/src/corelib/tools/qt_attribution.json b/src/corelib/text/qt_attribution.json
index f91742d421..f91742d421 100644
--- a/src/corelib/tools/qt_attribution.json
+++ b/src/corelib/text/qt_attribution.json
diff --git a/src/corelib/tools/qtextboundaryfinder.cpp b/src/corelib/text/qtextboundaryfinder.cpp
index 67dd15377b..67dd15377b 100644
--- a/src/corelib/tools/qtextboundaryfinder.cpp
+++ b/src/corelib/text/qtextboundaryfinder.cpp
diff --git a/src/corelib/tools/qtextboundaryfinder.h b/src/corelib/text/qtextboundaryfinder.h
index b1e5008f54..b1e5008f54 100644
--- a/src/corelib/tools/qtextboundaryfinder.h
+++ b/src/corelib/text/qtextboundaryfinder.h
diff --git a/src/corelib/tools/qunicodetables.cpp b/src/corelib/text/qunicodetables.cpp
index d57b39ff1f..d57b39ff1f 100644
--- a/src/corelib/tools/qunicodetables.cpp
+++ b/src/corelib/text/qunicodetables.cpp
diff --git a/src/corelib/tools/qunicodetables_p.h b/src/corelib/text/qunicodetables_p.h
index cb7a211cb6..cb7a211cb6 100644
--- a/src/corelib/tools/qunicodetables_p.h
+++ b/src/corelib/text/qunicodetables_p.h
diff --git a/src/corelib/tools/qunicodetools.cpp b/src/corelib/text/qunicodetools.cpp
index 08e1146c59..08e1146c59 100644
--- a/src/corelib/tools/qunicodetools.cpp
+++ b/src/corelib/text/qunicodetools.cpp
diff --git a/src/corelib/tools/qunicodetools_p.h b/src/corelib/text/qunicodetools_p.h
index ed6fcb5d65..ed6fcb5d65 100644
--- a/src/corelib/tools/qunicodetools_p.h
+++ b/src/corelib/text/qunicodetools_p.h
diff --git a/src/corelib/tools/qvsnprintf.cpp b/src/corelib/text/qvsnprintf.cpp
index 43a21771a1..43a21771a1 100644
--- a/src/corelib/tools/qvsnprintf.cpp
+++ b/src/corelib/text/qvsnprintf.cpp
diff --git a/src/corelib/text/text.pri b/src/corelib/text/text.pri
new file mode 100644
index 0000000000..25e281f37a
--- /dev/null
+++ b/src/corelib/text/text.pri
@@ -0,0 +1,100 @@
+# Qt text / string / character / unicode / byte array module
+
+HEADERS += \
+ text/qbytearray.h \
+ text/qbytearray_p.h \
+ text/qbytearraylist.h \
+ text/qbytearraymatcher.h \
+ text/qbytedata_p.h \
+ text/qchar.h \
+ text/qcollator.h \
+ text/qcollator_p.h \
+ text/qdoublescanprint_p.h \
+ text/qlocale.h \
+ text/qlocale_p.h \
+ text/qlocale_tools_p.h \
+ text/qlocale_data_p.h \
+ text/qregexp.h \
+ text/qstring.h \
+ text/qstringalgorithms.h \
+ text/qstringalgorithms_p.h \
+ text/qstringbuilder.h \
+ text/qstringiterator_p.h \
+ text/qstringlist.h \
+ text/qstringliteral.h \
+ text/qstringmatcher.h \
+ text/qstringview.h \
+ text/qtextboundaryfinder.h \
+ text/qunicodetables_p.h \
+ text/qunicodetools_p.h
+
+
+SOURCES += \
+ text/qbytearray.cpp \
+ text/qbytearraylist.cpp \
+ text/qbytearraymatcher.cpp \
+ text/qcollator.cpp \
+ text/qlocale.cpp \
+ text/qlocale_tools.cpp \
+ text/qregexp.cpp \
+ text/qstring.cpp \
+ text/qstringbuilder.cpp \
+ text/qstringlist.cpp \
+ text/qstringview.cpp \
+ text/qtextboundaryfinder.cpp \
+ text/qunicodetools.cpp \
+ text/qvsnprintf.cpp
+
+NO_PCH_SOURCES += text/qstring_compat.cpp
+false: SOURCES += $$NO_PCH_SOURCES # Hack for QtCreator
+
+!nacl:macos: {
+ SOURCES += text/qlocale_mac.mm
+}
+else:unix {
+ SOURCES += text/qlocale_unix.cpp
+}
+else:win32 {
+ SOURCES += text/qlocale_win.cpp
+} else:integrity {
+ SOURCES += text/qlocale_unix.cpp
+}
+
+qtConfig(icu) {
+ QMAKE_USE_PRIVATE += icu
+
+ SOURCES += text/qlocale_icu.cpp \
+ text/qcollator_icu.cpp
+} else: win32 {
+ SOURCES += text/qcollator_win.cpp
+} else: macos {
+ SOURCES += text/qcollator_macx.cpp
+} else {
+ SOURCES += text/qcollator_posix.cpp
+}
+
+qtConfig(regularexpression) {
+ QMAKE_USE_PRIVATE += pcre2
+
+ HEADERS += \
+ text/qregularexpression.h
+ SOURCES += text/qregularexpression.cpp
+}
+
+INCLUDEPATH += ../3rdparty/harfbuzz/src
+HEADERS += ../3rdparty/harfbuzz/src/harfbuzz.h
+SOURCES += ../3rdparty/harfbuzz/src/harfbuzz-buffer.c \
+ ../3rdparty/harfbuzz/src/harfbuzz-gdef.c \
+ ../3rdparty/harfbuzz/src/harfbuzz-gsub.c \
+ ../3rdparty/harfbuzz/src/harfbuzz-gpos.c \
+ ../3rdparty/harfbuzz/src/harfbuzz-impl.c \
+ ../3rdparty/harfbuzz/src/harfbuzz-open.c \
+ ../3rdparty/harfbuzz/src/harfbuzz-stream.c \
+ ../3rdparty/harfbuzz/src/harfbuzz-shaper-all.cpp \
+ text/qharfbuzz.cpp
+HEADERS += text/qharfbuzz_p.h
+
+TR_EXCLUDE += ../3rdparty/*
+
+# MIPS DSP
+MIPS_DSP_ASM += text/qstring_mips_dsp_asm.S
diff --git a/src/corelib/thread/qmutexpool.cpp b/src/corelib/thread/qmutexpool.cpp
deleted file mode 100644
index 3ece30c01c..0000000000
--- a/src/corelib/thread/qmutexpool.cpp
+++ /dev/null
@@ -1,151 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and 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 Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qatomic.h"
-#include "qmutexpool_p.h"
-
-QT_BEGIN_NAMESPACE
-
-Q_GLOBAL_STATIC_WITH_ARGS(QMutexPool, globalMutexPool, (QMutex::Recursive))
-
-/*!
- \class QMutexPool
- \inmodule QtCore
- \brief The QMutexPool class provides a pool of QMutex objects.
-
- \internal
-
- \ingroup thread
-
- QMutexPool is a convenience class that provides access to a fixed
- number of QMutex objects.
-
- Typical use of a QMutexPool is in situations where it is not
- possible or feasible to use one QMutex for every protected object.
- The mutex pool will return a mutex based on the address of the
- object that needs protection.
-
- For example, consider this simple class:
-
- \snippet code/src_corelib_thread_qmutexpool.cpp 0
-
- Adding a QMutex member to the Number class does not make sense,
- because it is so small. However, in order to ensure that access to
- each Number is protected, you need to use a mutex. In this case, a
- QMutexPool would be ideal.
-
- Code to calculate the square of a number would then look something
- like this:
-
- \snippet code/src_corelib_thread_qmutexpool.cpp 1
-
- This function will safely calculate the square of a number, since
- it uses a mutex from a QMutexPool. The mutex is locked and
- unlocked automatically by the QMutexLocker class. See the
- QMutexLocker documentation for more details.
-*/
-
-/*!
- Constructs a QMutexPool, reserving space for \a size QMutexes. All
- mutexes in the pool are created with \a recursionMode. By default,
- all mutexes are non-recursive.
-
- The QMutexes are created when needed, and deleted when the
- QMutexPool is destructed.
-*/
-QMutexPool::QMutexPool(QMutex::RecursionMode recursionMode, int size)
- : mutexes(size), recursionMode(recursionMode)
-{
- for (int index = 0; index < mutexes.count(); ++index) {
- mutexes[index].storeRelaxed(0);
- }
-}
-
-/*!
- Destructs a QMutexPool. All QMutexes that were created by the pool
- are deleted.
-*/
-QMutexPool::~QMutexPool()
-{
- for (int index = 0; index < mutexes.count(); ++index)
- delete mutexes[index].loadAcquire();
-}
-
-/*!
- Returns the global QMutexPool instance.
-*/
-QMutexPool *QMutexPool::instance()
-{
- return globalMutexPool();
-}
-
-/*!
- \fn QMutexPool::get(const void *address)
- Returns a QMutex from the pool. QMutexPool uses the value \a address
- to determine which mutex is returned from the pool.
-*/
-
-/*!
- \internal
- create the mutex for the given index
- */
-QMutex *QMutexPool::createMutex(int index)
-{
- // mutex not created, create one
- QMutex *newMutex = new QMutex(recursionMode);
- if (!mutexes[index].testAndSetRelease(nullptr, newMutex)) {
- delete newMutex;
- return mutexes[index].loadAcquire();
- } else {
- return newMutex;
- }
-}
-
-/*!
- Returns a QMutex from the global mutex pool.
-*/
-QMutex *QMutexPool::globalInstanceGet(const void *address)
-{
- QMutexPool * const globalInstance = globalMutexPool();
- if (globalInstance == 0)
- return 0;
- return globalInstance->get(address);
-}
-
-QT_END_NAMESPACE
diff --git a/src/corelib/thread/qorderedmutexlocker_p.h b/src/corelib/thread/qorderedmutexlocker_p.h
index e0a67388d4..570c526225 100644
--- a/src/corelib/thread/qorderedmutexlocker_p.h
+++ b/src/corelib/thread/qorderedmutexlocker_p.h
@@ -159,7 +159,7 @@ public:
void relock() {}
void unlock() {}
- static bool relock(QBasicMutex *, QBasicMutex *) {}
+ static bool relock(QBasicMutex *, QBasicMutex *) { return false; }
};
using QBasicMutexLocker = QMutexLocker;
diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp
index 280c785049..9fd1dd059d 100644
--- a/src/corelib/thread/qthread.cpp
+++ b/src/corelib/thread/qthread.cpp
@@ -851,7 +851,7 @@ Qt::HANDLE QThread::currentThreadId() noexcept
QThread *QThread::currentThread()
{
- return QThreadData::current()->thread;
+ return QThreadData::current()->thread.loadAcquire();
}
int QThread::idealThreadCount() noexcept
@@ -883,11 +883,11 @@ QThreadData *QThreadData::current(bool createIfNecessary)
if (!data && createIfNecessary) {
data = new QThreadData;
data->thread = new QAdoptedThread(data);
- data->threadId.storeRelaxed(Qt::HANDLE(data->thread));
+ data->threadId.storeRelaxed(Qt::HANDLE(data->thread.loadAcquire()));
data->deref();
data->isAdopted = true;
- if (!QCoreApplicationPrivate::theMainThread)
- QCoreApplicationPrivate::theMainThread = data->thread.loadRelaxed();
+ if (!QCoreApplicationPrivate::theMainThread.loadAcquire())
+ QCoreApplicationPrivate::theMainThread.storeRelease(data->thread.loadRelaxed());
}
return data;
}
diff --git a/src/corelib/thread/thread.pri b/src/corelib/thread/thread.pri
index 22f0de0523..d11e6500ff 100644
--- a/src/corelib/thread/thread.pri
+++ b/src/corelib/thread/thread.pri
@@ -28,7 +28,6 @@ qtConfig(thread) {
thread/qbasicatomic.h \
thread/qfutex_p.h \
thread/qgenericatomic.h \
- thread/qmutexpool_p.h \
thread/qmutex_p.h \
thread/qorderedmutexlocker_p.h \
thread/qreadwritelock_p.h \
@@ -40,7 +39,6 @@ qtConfig(thread) {
SOURCES += \
thread/qatomic.cpp \
thread/qmutex.cpp \
- thread/qmutexpool.cpp \
thread/qreadwritelock.cpp \
thread/qsemaphore.cpp \
thread/qthreadpool.cpp \
diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp
index 31206f779d..64943bdaaf 100644
--- a/src/corelib/time/qdatetime.cpp
+++ b/src/corelib/time/qdatetime.cpp
@@ -346,11 +346,10 @@ static constexpr int daysInUsualMonth(int month) // (February isn't usual.)
setDate(). The fromString() function returns a QDate given a string and a
date format which is used to interpret the date within the string.
- The year(), month(), and day() functions provide access to the
- year, month, and day numbers. Also, dayOfWeek() and dayOfYear()
- functions are provided. The same information is provided in
- textual format by the toString(), shortDayName(), longDayName(),
- shortMonthName(), and longMonthName() functions.
+ The year(), month(), and day() functions provide access to the year, month,
+ and day numbers. Also, dayOfWeek() and dayOfYear() functions are
+ provided. The same information is provided in textual format by
+ toString(). The day and month numbers can be mapped to names using QLocale.
QDate provides a full set of operators to compare two QDate
objects where smaller means earlier, and larger means later.
@@ -1076,11 +1075,10 @@ static QString toStringIsoDate(qint64 jd)
Returns the date as a string. The \a format parameter determines
the format of the string.
- If the \a format is Qt::TextDate, the string is formatted in
- the default way. QDate::shortDayName() and QDate::shortMonthName()
- are used to generate the string, so the day and month names will
- be localized names using the system locale, i.e. QLocale::system(). An
- example of this formatting is "Sat May 20 1995".
+ If the \a format is Qt::TextDate, the string is formatted in the default
+ way. The day and month names will be localized names using the system
+ locale, i.e. QLocale::system(). An example of this formatting
+ is "Sat May 20 1995".
If the \a format is Qt::ISODate, the string format corresponds
to the ISO 8601 extended specification for representations of
@@ -1112,7 +1110,7 @@ static QString toStringIsoDate(qint64 jd)
range 0 to 9999. This restriction may apply to locale-aware
formats as well, depending on the locale settings.
- \sa fromString(), shortDayName(), shortMonthName(), QLocale::toString()
+ \sa fromString(), QLocale::toString()
*/
QString QDate::toString(Qt::DateFormat format) const
{
@@ -1131,7 +1129,7 @@ QString QDate::toString(Qt::DateFormat format) const
case Qt::DefaultLocaleLongDate:
return QLocale().toString(*this, QLocale::LongFormat);
case Qt::RFC2822Date:
- return QLocale::c().toString(*this, QStringViewLiteral("dd MMM yyyy"));
+ return QLocale::c().toString(*this, u"dd MMM yyyy");
default:
#if QT_CONFIG(textdate)
case Qt::TextDate:
@@ -3272,10 +3270,9 @@ inline qint64 QDateTimePrivate::zoneMSecsToEpochMSecs(qint64 zoneMSecs, const QT
provides functions for comparing datetimes and for manipulating a
datetime by adding a number of seconds, days, months, or years.
- QDateTime can describe datetimes with respect to
- \l{Qt::LocalTime}{local time}, to \l{Qt::UTC}{UTC}, to a specified
- \l{Qt::OffsetFromUTC}{offset from UTC} or to a specified
- \l{Qt::TimeZone}{time zone}, in conjunction
+ QDateTime can describe datetimes with respect to \l{Qt::LocalTime}{local
+ time}, to \l{Qt::UTC}{UTC}, to a specified \l{Qt::OffsetFromUTC}{offset
+ from UTC} or to a specified \l{Qt::TimeZone}{time zone}, in conjunction
with the QTimeZone class. For example, a time zone of "Europe/Berlin" will
apply the daylight-saving rules as used in Germany since 1970. In contrast,
an offset from UTC of +3600 seconds is one hour ahead of UTC (usually
@@ -4065,12 +4062,10 @@ void QDateTime::setTime_t(uint secsSince1Jan1970UTC)
Returns the datetime as a string in the \a format given.
- If the \a format is Qt::TextDate, the string is formatted in
- the default way. QDate::shortDayName(), QDate::shortMonthName(),
- and QTime::toString() are used to generate the string, so the
- day and month names will be localized names using the system locale,
- i.e. QLocale::system(). An example of this formatting is
- "Wed May 20 03:40:13 1998".
+ If the \a format is Qt::TextDate, the string is formatted in the default
+ way. The day and month names will be localized names using the system
+ locale, i.e. QLocale::system(). An example of this formatting is "Wed May 20
+ 03:40:13 1998".
If the \a format is Qt::ISODate, the string format corresponds
to the ISO 8601 extended specification for representations of
@@ -4127,7 +4122,7 @@ QString QDateTime::toString(Qt::DateFormat format) const
case Qt::DefaultLocaleLongDate:
return QLocale().toString(*this, QLocale::LongFormat);
case Qt::RFC2822Date: {
- buf = QLocale::c().toString(*this, QStringViewLiteral("dd MMM yyyy hh:mm:ss "));
+ buf = QLocale::c().toString(*this, u"dd MMM yyyy hh:mm:ss ");
buf += toOffsetString(Qt::TextDate, offsetFromUtc());
return buf;
}
@@ -5239,18 +5234,14 @@ QDateTime QDateTime::fromString(const QString &string, Qt::DateFormat format)
\row \li dd \li the day as number with a leading zero (01 to 31)
\row \li ddd
\li the abbreviated localized day name (e.g. 'Mon' to 'Sun').
- Uses QDate::shortDayName().
\row \li dddd
\li the long localized day name (e.g. 'Monday' to 'Sunday').
- Uses QDate::longDayName().
\row \li M \li the month as number without a leading zero (1-12)
\row \li MM \li the month as number with a leading zero (01-12)
\row \li MMM
\li the abbreviated localized month name (e.g. 'Jan' to 'Dec').
- Uses QDate::shortMonthName().
\row \li MMMM
\li the long localized month name (e.g. 'January' to 'December').
- Uses QDate::longMonthName().
\row \li yy \li the year as two digit number (00-99)
\row \li yyyy \li the year as four digit number
\endtable
@@ -5631,7 +5622,7 @@ QDebug operator<<(QDebug dbg, const QTime &time)
QDebugStateSaver saver(dbg);
dbg.nospace() << "QTime(";
if (time.isValid())
- dbg.nospace() << time.toString(QStringViewLiteral("HH:mm:ss.zzz"));
+ dbg.nospace() << time.toString(u"HH:mm:ss.zzz");
else
dbg.nospace() << "Invalid";
dbg.nospace() << ')';
@@ -5644,7 +5635,7 @@ QDebug operator<<(QDebug dbg, const QDateTime &date)
dbg.nospace() << "QDateTime(";
if (date.isValid()) {
const Qt::TimeSpec ts = date.timeSpec();
- dbg.noquote() << date.toString(QStringViewLiteral("yyyy-MM-dd HH:mm:ss.zzz t"))
+ dbg.noquote() << date.toString(u"yyyy-MM-dd HH:mm:ss.zzz t")
<< ' ' << ts;
switch (ts) {
case Qt::UTC:
diff --git a/src/corelib/tools/qalgorithms.qdoc b/src/corelib/tools/qalgorithms.qdoc
index a73ec1e22a..c86e69f9c3 100644
--- a/src/corelib/tools/qalgorithms.qdoc
+++ b/src/corelib/tools/qalgorithms.qdoc
@@ -155,8 +155,8 @@
\section2 Porting guidelines
- Most of the times, an application using the deprecated Qt algorithmic functions
- can be easily ported to use the equivalent STL functions. You need to
+ Most of the time, an application using the deprecated Qt algorithmic functions
+ can be easily ported to use the equivalent STL functions. You need to:
\list 1
\li add the \c{#include <algorithm>} preprocessor directive;
diff --git a/src/corelib/tools/qarraydatapointer.h b/src/corelib/tools/qarraydatapointer.h
index 0322615f91..af5173c9ad 100644
--- a/src/corelib/tools/qarraydatapointer.h
+++ b/src/corelib/tools/qarraydatapointer.h
@@ -202,22 +202,11 @@ inline bool operator!=(const QArrayDataPointer<T> &lhs, const QArrayDataPointer<
}
template <class T>
-inline void qSwap(QArrayDataPointer<T> &p1, QArrayDataPointer<T> &p2)
+inline void swap(QArrayDataPointer<T> &p1, QArrayDataPointer<T> &p2)
{
p1.swap(p2);
}
QT_END_NAMESPACE
-namespace std
-{
- template <class T>
- inline void swap(
- QT_PREPEND_NAMESPACE(QArrayDataPointer)<T> &p1,
- QT_PREPEND_NAMESPACE(QArrayDataPointer)<T> &p2)
- {
- p1.swap(p2);
- }
-}
-
#endif // include guard
diff --git a/src/corelib/tools/qcontainerfwd.h b/src/corelib/tools/qcontainerfwd.h
index 646d8908c3..532b4c95ce 100644
--- a/src/corelib/tools/qcontainerfwd.h
+++ b/src/corelib/tools/qcontainerfwd.h
@@ -47,7 +47,9 @@ QT_BEGIN_NAMESPACE
template <class Key, class T> class QCache;
template <class Key, class T> class QHash;
+#ifndef QT_NO_LINKED_LIST
template <class T> class QLinkedList;
+#endif
template <class T> class QList;
template <class Key, class T> class QMap;
template <class Key, class T> class QMultiHash;
diff --git a/src/corelib/tools/qeasingcurve.cpp b/src/corelib/tools/qeasingcurve.cpp
index c807bbd2e1..8e00c46b41 100644
--- a/src/corelib/tools/qeasingcurve.cpp
+++ b/src/corelib/tools/qeasingcurve.cpp
@@ -907,6 +907,10 @@ struct TCBEase : public BezierEase
return BezierEase::value(x);
}
+ QEasingCurveFunction *copy() const override
+ {
+ return new TCBEase{*this};
+ }
};
struct ElasticEase : public QEasingCurveFunction
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index 4b4cb2d5f0..236e433101 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -136,7 +136,7 @@ struct QHashDummyValue
{
};
-inline bool operator==(const QHashDummyValue & /* v1 */, const QHashDummyValue & /* v2 */)
+constexpr bool operator==(const QHashDummyValue &, const QHashDummyValue &) noexcept
{
return true;
}
@@ -957,44 +957,32 @@ Q_OUTOFLINE_TEMPLATE typename QHash<Key, T>::Node **QHash<Key, T>::findNode(cons
template <class Key, class T>
Q_OUTOFLINE_TEMPLATE bool QHash<Key, T>::operator==(const QHash &other) const
{
- if (size() != other.size())
- return false;
if (d == other.d)
return true;
+ if (size() != other.size())
+ return false;
const_iterator it = begin();
while (it != end()) {
// Build two equal ranges for i.key(); one for *this and one for other.
// For *this we can avoid a lookup via equal_range, as we know the beginning of the range.
- auto thisEqualRangeEnd = it;
- while (thisEqualRangeEnd != end() && it.key() == thisEqualRangeEnd.key())
- ++thisEqualRangeEnd;
+ auto thisEqualRangeStart = it;
+ const Key &thisEqualRangeKey = it.key();
+ size_type n = 0;
+ do {
+ ++it;
+ ++n;
+ } while (it != end() && it.key() == thisEqualRangeKey);
- const auto otherEqualRange = other.equal_range(it.key());
+ const auto otherEqualRange = other.equal_range(thisEqualRangeKey);
- if (std::distance(it, thisEqualRangeEnd) != std::distance(otherEqualRange.first, otherEqualRange.second))
+ if (n != std::distance(otherEqualRange.first, otherEqualRange.second))
return false;
// Keys in the ranges are equal by construction; this checks only the values.
- //
- // When using the 3-arg std::is_permutation, MSVC will emit warning C4996,
- // passing an unchecked iterator to a Standard Library algorithm. We don't
- // want to suppress the warning, and we can't use stdext::make_checked_array_iterator
- // because QHash::(const_)iterator does not work with size_t and thus will
- // emit more warnings. Use the 4-arg std::is_permutation instead (which
- // is supported since MSVC 2015).
- //
- // ### Qt 6: if C++14 library support is a mandated minimum, remove the ifdef for MSVC.
- if (!std::is_permutation(it, thisEqualRangeEnd, otherEqualRange.first
-#ifdef Q_CC_MSVC
- , otherEqualRange.second
-#endif
- )) {
+ if (!qt_is_permutation(thisEqualRangeStart, it, otherEqualRange.first, otherEqualRange.second))
return false;
- }
-
- it = thisEqualRangeEnd;
}
return true;
diff --git a/src/corelib/tools/qlinkedlist.cpp b/src/corelib/tools/qlinkedlist.cpp
index d239fe0ef4..3b1bc8aab1 100644
--- a/src/corelib/tools/qlinkedlist.cpp
+++ b/src/corelib/tools/qlinkedlist.cpp
@@ -37,6 +37,10 @@
**
****************************************************************************/
+#ifdef QT_NO_LINKED_LIST
+# undef QT_NO_LINKED_LIST
+#endif
+
#include "qlinkedlist.h"
QT_BEGIN_NAMESPACE
diff --git a/src/corelib/tools/qlinkedlist.h b/src/corelib/tools/qlinkedlist.h
index d4e5bca0ed..996a50fd1b 100644
--- a/src/corelib/tools/qlinkedlist.h
+++ b/src/corelib/tools/qlinkedlist.h
@@ -40,6 +40,10 @@
#ifndef QLINKEDLIST_H
#define QLINKEDLIST_H
+#include <QtCore/qglobal.h>
+
+#ifndef QT_NO_LINKED_LIST
+
#include <QtCore/qiterator.h>
#include <QtCore/qrefcount.h>
#include <QtCore/qcontainertools_impl.h>
@@ -581,4 +585,8 @@ inline QDataStream &operator<<(QDataStream &s, const QLinkedList<T> &l)
QT_END_NAMESPACE
+Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE(QLinkedList)
+
+#endif // QT_NO_LINKED_LIST
+
#endif // QLINKEDLIST_H
diff --git a/src/corelib/tools/qshareddata.h b/src/corelib/tools/qshareddata.h
index ab54c76720..f123f8e7b9 100644
--- a/src/corelib/tools/qshareddata.h
+++ b/src/corelib/tools/qshareddata.h
@@ -297,25 +297,13 @@ template <class T> inline bool operator==(const QExplicitlySharedDataPointer<T>
}
template <class T>
-Q_INLINE_TEMPLATE void qSwap(QSharedDataPointer<T> &p1, QSharedDataPointer<T> &p2)
+Q_INLINE_TEMPLATE void swap(QSharedDataPointer<T> &p1, QSharedDataPointer<T> &p2)
{ p1.swap(p2); }
template <class T>
-Q_INLINE_TEMPLATE void qSwap(QExplicitlySharedDataPointer<T> &p1, QExplicitlySharedDataPointer<T> &p2)
+Q_INLINE_TEMPLATE void swap(QExplicitlySharedDataPointer<T> &p1, QExplicitlySharedDataPointer<T> &p2)
{ p1.swap(p2); }
-QT_END_NAMESPACE
-namespace std {
- template <class T>
- Q_INLINE_TEMPLATE void swap(QT_PREPEND_NAMESPACE(QSharedDataPointer)<T> &p1, QT_PREPEND_NAMESPACE(QSharedDataPointer)<T> &p2)
- { p1.swap(p2); }
-
- template <class T>
- Q_INLINE_TEMPLATE void swap(QT_PREPEND_NAMESPACE(QExplicitlySharedDataPointer)<T> &p1, QT_PREPEND_NAMESPACE(QExplicitlySharedDataPointer)<T> &p2)
- { p1.swap(p2); }
-}
-QT_BEGIN_NAMESPACE
-
template <class T>
Q_INLINE_TEMPLATE uint qHash(const QSharedDataPointer<T> &ptr, uint seed = 0) noexcept
{
diff --git a/src/corelib/tools/qtimeline.cpp b/src/corelib/tools/qtimeline.cpp
index fa6c45aa11..0b11e7c77b 100644
--- a/src/corelib/tools/qtimeline.cpp
+++ b/src/corelib/tools/qtimeline.cpp
@@ -526,29 +526,24 @@ QTimeLine::CurveShape QTimeLine::curveShape() const
return EaseInOutCurve;
}
-void QTimeLine::setCurveShape(CurveShape shape)
+static QEasingCurve::Type convert(QTimeLine::CurveShape shape)
{
switch (shape) {
- default:
- case EaseInOutCurve:
- setEasingCurve(QEasingCurve(QEasingCurve::InOutSine));
- break;
- case EaseInCurve:
- setEasingCurve(QEasingCurve(QEasingCurve::InCurve));
- break;
- case EaseOutCurve:
- setEasingCurve(QEasingCurve(QEasingCurve::OutCurve));
- break;
- case LinearCurve:
- setEasingCurve(QEasingCurve(QEasingCurve::Linear));
- break;
- case SineCurve:
- setEasingCurve(QEasingCurve(QEasingCurve::SineCurve));
- break;
- case CosineCurve:
- setEasingCurve(QEasingCurve(QEasingCurve::CosineCurve));
- break;
+#define CASE(x, y) case QTimeLine::x: return QEasingCurve::y
+ CASE(EaseInOutCurve, InOutSine);
+ CASE(EaseInCurve, InCurve);
+ CASE(EaseOutCurve, OutCurve);
+ CASE(LinearCurve, Linear);
+ CASE(SineCurve, SineCurve);
+ CASE(CosineCurve, CosineCurve);
+#undef CASE
}
+ Q_UNREACHABLE();
+}
+
+void QTimeLine::setCurveShape(CurveShape shape)
+{
+ setEasingCurve(convert(shape));
}
/*!
diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h
index ba65ae7ef2..2f62526076 100644
--- a/src/corelib/tools/qvarlengtharray.h
+++ b/src/corelib/tools/qvarlengtharray.h
@@ -112,7 +112,9 @@ public:
inline void removeLast() {
Q_ASSERT(s > 0);
- realloc(s - 1, a);
+ if (QTypeInfo<T>::isComplex)
+ ptr[s - 1].~T();
+ --s;
}
inline int size() const { return s; }
inline int count() const { return s; }
diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h
index 65a5174abf..ebe6527d89 100644
--- a/src/corelib/tools/qvector.h
+++ b/src/corelib/tools/qvector.h
@@ -424,7 +424,7 @@ template <typename T>
void QVector<T>::resize(int asize)
{
if (asize == d->size)
- return;
+ return detach();
if (asize > int(d->alloc) || !isDetached()) { // there is not enough space
QArrayData::AllocationOptions opt = asize > int(d->alloc) ? QArrayData::Grow : QArrayData::Default;
realloc(qMax(int(d->alloc), asize), opt);
diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri
index 52eddd5d6b..a2236f90f2 100644
--- a/src/corelib/tools/tools.pri
+++ b/src/corelib/tools/tools.pri
@@ -8,19 +8,10 @@ HEADERS += \
tools/qarraydataops.h \
tools/qarraydatapointer.h \
tools/qbitarray.h \
- tools/qbytearray.h \
- tools/qbytearray_p.h \
- tools/qbytearraylist.h \
- tools/qbytearraymatcher.h \
- tools/qbytedata_p.h \
tools/qcache.h \
- tools/qchar.h \
- tools/qcollator.h \
- tools/qcollator_p.h \
tools/qcontainerfwd.h \
tools/qcontainertools_impl.h \
tools/qcryptographichash.h \
- tools/qdoublescanprint_p.h \
tools/qeasingcurve.h \
tools/qfreelist_p.h \
tools/qhash.h \
@@ -29,10 +20,6 @@ HEADERS += \
tools/qline.h \
tools/qlinkedlist.h \
tools/qlist.h \
- tools/qlocale.h \
- tools/qlocale_p.h \
- tools/qlocale_tools_p.h \
- tools/qlocale_data_p.h \
tools/qmakearray_p.h \
tools/qmap.h \
tools/qmargins.h \
@@ -43,7 +30,6 @@ HEADERS += \
tools/qpoint.h \
tools/qqueue.h \
tools/qrect.h \
- tools/qregexp.h \
tools/qringbuffer_p.h \
tools/qrefcount.h \
tools/qscopeguard.h \
@@ -57,20 +43,8 @@ HEADERS += \
tools/qsimd_p.h \
tools/qsize.h \
tools/qstack.h \
- tools/qstring.h \
- tools/qstringalgorithms.h \
- tools/qstringalgorithms_p.h \
- tools/qstringbuilder.h \
- tools/qstringiterator_p.h \
- tools/qstringlist.h \
- tools/qstringliteral.h \
- tools/qstringmatcher.h \
- tools/qstringview.h \
- tools/qtextboundaryfinder.h \
tools/qtimeline.h \
tools/qtools_p.h \
- tools/qunicodetables_p.h \
- tools/qunicodetools_p.h \
tools/qvarlengtharray.h \
tools/qvector.h \
tools/qversionnumber.h
@@ -79,10 +53,6 @@ HEADERS += \
SOURCES += \
tools/qarraydata.cpp \
tools/qbitarray.cpp \
- tools/qbytearray.cpp \
- tools/qbytearraylist.cpp \
- tools/qbytearraymatcher.cpp \
- tools/qcollator.cpp \
tools/qcryptographichash.cpp \
tools/qeasingcurve.cpp \
tools/qfreelist.cpp \
@@ -90,47 +60,24 @@ SOURCES += \
tools/qline.cpp \
tools/qlinkedlist.cpp \
tools/qlist.cpp \
- tools/qlocale.cpp \
- tools/qlocale_tools.cpp \
tools/qpoint.cpp \
tools/qmap.cpp \
tools/qmargins.cpp \
tools/qmessageauthenticationcode.cpp \
tools/qcontiguouscache.cpp \
tools/qrect.cpp \
- tools/qregexp.cpp \
tools/qrefcount.cpp \
tools/qringbuffer.cpp \
tools/qshareddata.cpp \
tools/qsharedpointer.cpp \
tools/qsimd.cpp \
tools/qsize.cpp \
- tools/qstring.cpp \
- tools/qstringbuilder.cpp \
- tools/qstringlist.cpp \
- tools/qstringview.cpp \
- tools/qtextboundaryfinder.cpp \
tools/qtimeline.cpp \
- tools/qunicodetools.cpp \
- tools/qvsnprintf.cpp \
tools/qversionnumber.cpp
-NO_PCH_SOURCES = tools/qstring_compat.cpp
msvc: NO_PCH_SOURCES += tools/qvector_msvc.cpp
false: SOURCES += $$NO_PCH_SOURCES # Hack for QtCreator
-!nacl:mac: {
- SOURCES += tools/qlocale_mac.mm
-}
-else:unix {
- SOURCES += tools/qlocale_unix.cpp
-}
-else:win32 {
- SOURCES += tools/qlocale_win.cpp
-} else:integrity {
- SOURCES += tools/qlocale_unix.cpp
-}
-
qtConfig(system-zlib) {
include($$PWD/../../3rdparty/zlib_dependency.pri)
} else {
@@ -138,27 +85,6 @@ qtConfig(system-zlib) {
include($$PWD/../../3rdparty/zlib.pri)
}
-qtConfig(icu) {
- QMAKE_USE_PRIVATE += icu
-
- SOURCES += tools/qlocale_icu.cpp \
- tools/qcollator_icu.cpp
-} else: win32 {
- SOURCES += tools/qcollator_win.cpp
-} else: macx {
- SOURCES += tools/qcollator_macx.cpp
-} else {
- SOURCES += tools/qcollator_posix.cpp
-}
-
-qtConfig(regularexpression) {
- QMAKE_USE_PRIVATE += pcre2
-
- HEADERS += \
- tools/qregularexpression.h
- SOURCES += tools/qregularexpression.cpp
-}
-
qtConfig(commandlineparser) {
HEADERS += \
tools/qcommandlineoption.h \
@@ -168,19 +94,6 @@ qtConfig(commandlineparser) {
tools/qcommandlineparser.cpp
}
-INCLUDEPATH += ../3rdparty/harfbuzz/src
-HEADERS += ../3rdparty/harfbuzz/src/harfbuzz.h
-SOURCES += ../3rdparty/harfbuzz/src/harfbuzz-buffer.c \
- ../3rdparty/harfbuzz/src/harfbuzz-gdef.c \
- ../3rdparty/harfbuzz/src/harfbuzz-gsub.c \
- ../3rdparty/harfbuzz/src/harfbuzz-gpos.c \
- ../3rdparty/harfbuzz/src/harfbuzz-impl.c \
- ../3rdparty/harfbuzz/src/harfbuzz-open.c \
- ../3rdparty/harfbuzz/src/harfbuzz-stream.c \
- ../3rdparty/harfbuzz/src/harfbuzz-shaper-all.cpp \
- tools/qharfbuzz.cpp
-HEADERS += tools/qharfbuzz_p.h
-
INCLUDEPATH += ../3rdparty/md5 \
../3rdparty/md4 \
../3rdparty/sha3
@@ -197,5 +110,4 @@ unix:!macx-icc:!vxworks:!haiku:!integrity:!wasm: LIBS_PRIVATE += -lm
TR_EXCLUDE += ../3rdparty/*
# MIPS DSP
-MIPS_DSP_ASM += tools/qstring_mips_dsp_asm.S
MIPS_DSP_HEADERS += ../gui/painting/qt_mips_asm_dsp_p.h
diff --git a/src/dbus/qdbuserror.h b/src/dbus/qdbuserror.h
index bcf68dbcdc..312bac71de 100644
--- a/src/dbus/qdbuserror.h
+++ b/src/dbus/qdbuserror.h
@@ -41,6 +41,7 @@
#define QDBUSERROR_H
#include <QtDBus/qtdbusglobal.h>
+#include <QtCore/qobjectdefs.h>
#include <QtCore/qstring.h>
#ifndef QT_NO_DBUS
@@ -54,6 +55,7 @@ class QDBusMessage;
class Q_DBUS_EXPORT QDBusError
{
+ Q_GADGET
public:
enum ErrorType {
NoError = 0,
@@ -90,6 +92,7 @@ public:
LastErrorType = InvalidMember
#endif
};
+ Q_ENUM(ErrorType)
QDBusError();
#ifndef QT_BOOTSTRAPPED
diff --git a/src/gui/configure.json b/src/gui/configure.json
index 764e92a729..5aac1f221a 100644
--- a/src/gui/configure.json
+++ b/src/gui/configure.json
@@ -1550,6 +1550,7 @@
},
"xcb-native-painting": {
"label": "Native painting (experimental)",
+ "autoDetect": false,
"emitIf": "features.xcb",
"condition": "features.xcb-xlib && features.fontconfig && libs.xrender",
"output": [ "privateFeature" ]
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp
index 61d32b0dec..cd2fe5bc10 100644
--- a/src/gui/image/qimage.cpp
+++ b/src/gui/image/qimage.cpp
@@ -5067,12 +5067,12 @@ void QImage::applyColorTransform(const QColorTransform &transform)
if (depth() > 32) {
for (int i = 0; i < height(); ++i) {
QRgba64 *scanline = reinterpret_cast<QRgba64 *>(scanLine(i));
- transform.d_func()->apply(scanline, scanline, width(), flags);
+ transform.d->apply(scanline, scanline, width(), flags);
}
} else {
for (int i = 0; i < height(); ++i) {
QRgb *scanline = reinterpret_cast<QRgb *>(scanLine(i));
- transform.d_func()->apply(scanline, scanline, width(), flags);
+ transform.d->apply(scanline, scanline, width(), flags);
}
}
diff --git a/src/gui/image/qimagereader.cpp b/src/gui/image/qimagereader.cpp
index 2762b702b2..6a0763e696 100644
--- a/src/gui/image/qimagereader.cpp
+++ b/src/gui/image/qimagereader.cpp
@@ -197,7 +197,7 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device,
#ifdef QIMAGEREADER_DEBUG
qDebug() << "QImageReader::createReadHandler( device =" << (void *)device << ", format =" << format << "),"
- << keyMap.size() << "plugins available: " << keyMap.values();
+ << keyMap.uniqueKeys().size() << "plugins available: " << keyMap;
#endif
int suffixPluginIndex = -1;
@@ -325,6 +325,29 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device,
#endif
}
+ if (handler && device && !suffix.isEmpty()) {
+ Q_ASSERT(qobject_cast<QFile *>(device));
+ // We have a file claiming to be of a recognized format. Now confirm that
+ // the handler also recognizes the file contents.
+ const qint64 pos = device->pos();
+ handler->setDevice(device);
+ if (!form.isEmpty())
+ handler->setFormat(form);
+ bool canRead = handler->canRead();
+ device->seek(pos);
+ if (canRead) {
+ // ok, we're done.
+ return handler;
+ }
+#ifdef QIMAGEREADER_DEBUG
+ qDebug() << "QImageReader::createReadHandler: the" << suffix << "handler can not read this file";
+#endif
+ // File may still be valid, just with wrong suffix, so fall back to
+ // finding a handler based on contents, below.
+ delete handler;
+ handler = nullptr;
+ }
+
#ifndef QT_NO_IMAGEFORMATPLUGIN
if (!handler && (autoDetectImageFormat || ignoresFormatAndExtension)) {
// check if any of our plugins recognize the file from its contents.
@@ -336,7 +359,7 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device,
if (plugin && plugin->capabilities(device, QByteArray()) & QImageIOPlugin::CanRead) {
handler = plugin->create(device, testFormat);
#ifdef QIMAGEREADER_DEBUG
- qDebug() << "QImageReader::createReadHandler: the" << keyMap.keys().at(i) << "plugin can read this data";
+ qDebug() << "QImageReader::createReadHandler: the" << keyMap.value(i) << "plugin can read this data";
#endif
break;
}
@@ -1074,7 +1097,7 @@ QList<QByteArray> QImageReader::supportedSubTypes() const
\since 5.5
Returns the transformation metadata of the image, including image orientation. If the format
- does not support transformation metadata \c QImageIOHandler::Transformation_None is returned.
+ does not support transformation metadata, QImageIOHandler::TransformationNone is returned.
\sa setAutoTransform(), autoTransform()
*/
diff --git a/src/gui/image/qmovie.cpp b/src/gui/image/qmovie.cpp
index 4b588527ae..3e975115ab 100644
--- a/src/gui/image/qmovie.cpp
+++ b/src/gui/image/qmovie.cpp
@@ -207,8 +207,8 @@ public:
: pixmap(QPixmap()), delay(QMOVIE_INVALID_DELAY), endMark(false)
{ }
- inline QFrameInfo(const QPixmap &pixmap, int delay)
- : pixmap(pixmap), delay(delay), endMark(false)
+ inline QFrameInfo(QPixmap &&pixmap, int delay)
+ : pixmap(std::move(pixmap)), delay(delay), endMark(false)
{ }
inline bool isValid()
@@ -222,6 +222,7 @@ public:
static inline QFrameInfo endMarker()
{ return QFrameInfo(true); }
};
+Q_DECLARE_TYPEINFO(QFrameInfo, Q_MOVABLE_TYPE);
class QMoviePrivate : public QObjectPrivate
{
@@ -380,9 +381,7 @@ QFrameInfo QMoviePrivate::infoForFrame(int frameNumber)
}
if (frameNumber > greatestFrameNumber)
greatestFrameNumber = frameNumber;
- QPixmap aPixmap = QPixmap::fromImage(std::move(anImage));
- int aDelay = reader->nextImageDelay();
- return QFrameInfo(aPixmap, aDelay);
+ return QFrameInfo(QPixmap::fromImage(std::move(anImage)), reader->nextImageDelay());
} else if (frameNumber != 0) {
// We've read all frames now. Return an end marker
haveReadAll = true;
@@ -406,9 +405,7 @@ QFrameInfo QMoviePrivate::infoForFrame(int frameNumber)
return QFrameInfo(); // Invalid
}
greatestFrameNumber = i;
- QPixmap aPixmap = QPixmap::fromImage(std::move(anImage));
- int aDelay = reader->nextImageDelay();
- QFrameInfo info(aPixmap, aDelay);
+ QFrameInfo info(QPixmap::fromImage(std::move(anImage)), reader->nextImageDelay());
// Cache it!
frameMap.insert(i, info);
if (i == frameNumber) {
diff --git a/src/gui/image/qpixmapcache.cpp b/src/gui/image/qpixmapcache.cpp
index a41ec8f35c..483d6d79a2 100644
--- a/src/gui/image/qpixmapcache.cpp
+++ b/src/gui/image/qpixmapcache.cpp
@@ -42,6 +42,8 @@
#include "qobject.h"
#include "qdebug.h"
#include "qpixmapcache_p.h"
+#include "qthread.h"
+#include "qcoreapplication.h"
QT_BEGIN_NAMESPACE
@@ -83,6 +85,9 @@ QT_BEGIN_NAMESPACE
with QPixmapCache} explains how to use QPixmapCache to speed up
applications by caching the results of painting.
+ \note QPixmapCache is only usable from the application's main thread.
+ Access from other threads will be ignored and return failure.
+
\sa QCache, QPixmap
*/
@@ -98,6 +103,14 @@ static inline int cost(const QPixmap &pixmap)
return static_cast<int>(qBound(1LL, costKb, costMax));
}
+static inline bool qt_pixmapcache_thread_test()
+{
+ if (Q_LIKELY(QCoreApplication::instance() && QThread::currentThread() == QCoreApplication::instance()->thread()))
+ return true;
+
+ return false;
+}
+
/*!
\class QPixmapCache::Key
\brief The QPixmapCache::Key class can be used for efficient access
@@ -490,6 +503,8 @@ QPixmapCacheEntry::~QPixmapCacheEntry()
QPixmap *QPixmapCache::find(const QString &key)
{
+ if (!qt_pixmapcache_thread_test())
+ return nullptr;
return pm_cache()->object(key);
}
@@ -519,6 +534,8 @@ bool QPixmapCache::find(const QString &key, QPixmap &pixmap)
bool QPixmapCache::find(const QString &key, QPixmap *pixmap)
{
+ if (!qt_pixmapcache_thread_test())
+ return false;
QPixmap *ptr = pm_cache()->object(key);
if (ptr && pixmap)
*pixmap = *ptr;
@@ -536,6 +553,8 @@ bool QPixmapCache::find(const QString &key, QPixmap *pixmap)
*/
bool QPixmapCache::find(const Key &key, QPixmap *pixmap)
{
+ if (!qt_pixmapcache_thread_test())
+ return false;
//The key is not valid anymore, a flush happened before probably
if (!key.d || !key.d->isValid)
return false;
@@ -567,6 +586,8 @@ bool QPixmapCache::find(const Key &key, QPixmap *pixmap)
bool QPixmapCache::insert(const QString &key, const QPixmap &pixmap)
{
+ if (!qt_pixmapcache_thread_test())
+ return false;
return pm_cache()->insert(key, pixmap, cost(pixmap));
}
@@ -587,6 +608,8 @@ bool QPixmapCache::insert(const QString &key, const QPixmap &pixmap)
*/
QPixmapCache::Key QPixmapCache::insert(const QPixmap &pixmap)
{
+ if (!qt_pixmapcache_thread_test())
+ return QPixmapCache::Key();
return pm_cache()->insert(pixmap, cost(pixmap));
}
@@ -601,6 +624,8 @@ QPixmapCache::Key QPixmapCache::insert(const QPixmap &pixmap)
*/
bool QPixmapCache::replace(const Key &key, const QPixmap &pixmap)
{
+ if (!qt_pixmapcache_thread_test())
+ return false;
//The key is not valid anymore, a flush happened before probably
if (!key.d || !key.d->isValid)
return false;
@@ -630,6 +655,8 @@ int QPixmapCache::cacheLimit()
void QPixmapCache::setCacheLimit(int n)
{
+ if (!qt_pixmapcache_thread_test())
+ return;
pm_cache()->setMaxCost(n);
}
@@ -638,6 +665,8 @@ void QPixmapCache::setCacheLimit(int n)
*/
void QPixmapCache::remove(const QString &key)
{
+ if (!qt_pixmapcache_thread_test())
+ return;
pm_cache()->remove(key);
}
@@ -649,6 +678,8 @@ void QPixmapCache::remove(const QString &key)
*/
void QPixmapCache::remove(const Key &key)
{
+ if (!qt_pixmapcache_thread_test())
+ return;
//The key is not valid anymore, a flush happened before probably
if (!key.d || !key.d->isValid)
return;
@@ -661,6 +692,8 @@ void QPixmapCache::remove(const Key &key)
void QPixmapCache::clear()
{
+ if (!QCoreApplication::closingDown() && !qt_pixmapcache_thread_test())
+ return;
QT_TRY {
if (pm_cache.exists())
pm_cache->clear();
diff --git a/src/gui/image/qpnghandler.cpp b/src/gui/image/qpnghandler.cpp
index 864a944fcb..16d6c25b8b 100644
--- a/src/gui/image/qpnghandler.cpp
+++ b/src/gui/image/qpnghandler.cpp
@@ -53,7 +53,6 @@
#include <qcolorspace.h>
#include <private/qcolorspace_p.h>
-#include <private/qicc_p.h>
#include <png.h>
#include <pngconf.h>
@@ -607,9 +606,13 @@ bool QPngHandlerPrivate::readPngHeader()
#endif
png_uint_32 profLen;
png_get_iCCP(png_ptr, info_ptr, &name, &compressionType, &profileData, &profLen);
- if (!QIcc::fromIccProfile(QByteArray::fromRawData((const char *)profileData, profLen), &colorSpace)) {
+ colorSpace = QColorSpace::fromIccProfile(QByteArray::fromRawData((const char *)profileData, profLen));
+ if (!colorSpace.isValid()) {
qWarning() << "QPngHandler: Failed to parse ICC profile";
} else {
+ QColorSpacePrivate *csD = QColorSpacePrivate::getWritable(colorSpace);
+ if (csD->description.isEmpty())
+ csD->description = QString::fromLatin1((const char *)name);
colorSpaceState = Icc;
}
}
@@ -628,11 +631,25 @@ bool QPngHandlerPrivate::readPngHeader()
png_get_gAMA(png_ptr, info_ptr, &file_gamma);
fileGamma = file_gamma;
if (fileGamma > 0.0f && colorSpaceState <= GammaChrm) {
- QColorSpacePrivate *csPrivate = colorSpace.d_func();
- csPrivate->gamut = QColorSpace::Gamut::SRgb;
- csPrivate->transferFunction = QColorSpace::TransferFunction::Gamma;
- csPrivate->gamma = fileGamma;
- csPrivate->initialize();
+ QColorSpacePrimaries primaries;
+ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_cHRM)) {
+ double white_x, white_y, red_x, red_y;
+ double green_x, green_y, blue_x, blue_y;
+ png_get_cHRM(png_ptr, info_ptr,
+ &white_x, &white_y, &red_x, &red_y,
+ &green_x, &green_y, &blue_x, &blue_y);
+ primaries.whitePoint = QPointF(white_x, white_y);
+ primaries.redPoint = QPointF(red_x, red_y);
+ primaries.greenPoint = QPointF(green_x, green_y);
+ primaries.bluePoint = QPointF(blue_x, blue_y);
+ }
+ if (primaries.areValid()) {
+ colorSpace = QColorSpace(primaries.whitePoint, primaries.redPoint, primaries.greenPoint, primaries.bluePoint,
+ QColorSpace::TransferFunction::Gamma, fileGamma);
+ } else {
+ colorSpace = QColorSpace(QColorSpace::Primaries::SRgb,
+ QColorSpace::TransferFunction::Gamma, fileGamma);
+ }
colorSpaceState = GammaChrm;
}
}
@@ -663,10 +680,7 @@ bool QPngHandlerPrivate::readPngImage(QImage *outImage)
// This configuration forces gamma correction and
// thus changes the output colorspace
png_set_gamma(png_ptr, 1.0f / gamma, fileGamma);
- QColorSpacePrivate *csPrivate = colorSpace.d_func();
- csPrivate->transferFunction = QColorSpace::TransferFunction::Gamma;
- csPrivate->gamma = gamma;
- csPrivate->initialize();
+ colorSpace = colorSpace.withTransferFunction(QColorSpace::TransferFunction::Gamma, 1.0f / gamma);
colorSpaceState = GammaChrm;
}
@@ -962,6 +976,26 @@ bool QPNGImageWriter::writeImage(const QImage& image, volatile int compression_i
bpc, // per channel
color_type, 0, 0, 0); // sets #channels
+#ifdef PNG_iCCP_SUPPORTED
+ if (image.colorSpace().isValid()) {
+ QColorSpace cs = image.colorSpace();
+ // Support the old gamma making it override transferfunction.
+ if (gamma != 0.0 && !qFuzzyCompare(cs.gamma(), 1.0f / gamma))
+ cs = cs.withTransferFunction(QColorSpace::TransferFunction::Gamma, 1.0f / gamma);
+ QByteArray iccProfileName = QColorSpacePrivate::get(cs)->description.toLatin1();
+ if (iccProfileName.isEmpty())
+ iccProfileName = QByteArrayLiteral("Custom");
+ QByteArray iccProfile = cs.iccProfile();
+ png_set_iCCP(png_ptr, info_ptr,
+ #if PNG_LIBPNG_VER < 10500
+ iccProfileName.data(), PNG_COMPRESSION_TYPE_BASE, iccProfile.data(),
+ #else
+ iccProfileName.constData(), PNG_COMPRESSION_TYPE_BASE,
+ (png_const_bytep)iccProfile.constData(),
+ #endif
+ iccProfile.length());
+ } else
+#endif
if (gamma != 0.0) {
png_set_gAMA(png_ptr, info_ptr, 1.0/gamma);
}
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index e1d685b1b0..ec52791010 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -754,31 +754,15 @@ QHoverEvent::~QHoverEvent()
\fn Qt::Orientation QWheelEvent::orientation() const
\obsolete
- Returns the wheel's orientation.
-
Use angleDelta() instead.
*/
+#if QT_CONFIG(wheelevent)
+#if QT_DEPRECATED_SINCE(5, 15)
/*!
\obsolete
- Constructs a wheel event object.
-
- Use the constructor taking \e angleDelta and \e pixelDelta QPoints instead.
-
- The position, \a pos, is the location of the mouse cursor within
- the widget. The globalPos() is initialized to QCursor::pos()
- which is usually, but not always, correct.
- Use the other constructor if you need to specify the global
- position explicitly.
-
- The \a buttons describe the state of the mouse buttons at the time
- of the event, \a delta contains the rotation distance,
- \a modifiers holds the keyboard modifier flags at the time of the
- event, and \a orient holds the wheel's orientation.
-
- \sa pos(), pixelDelta(), angleDelta()
+ This constructor has been deprecated.
*/
-#if QT_CONFIG(wheelevent)
QWheelEvent::QWheelEvent(const QPointF &pos, int delta,
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
Qt::Orientation orient)
@@ -793,26 +777,8 @@ QWheelEvent::QWheelEvent(const QPointF &pos, int delta,
}
/*!
- \internal
-*/
-QWheelEvent::~QWheelEvent()
-{
-}
-
-/*!
\obsolete
- Constructs a wheel event object.
-
- Use the constructor taking \e angleDelta and \e pixelDelta QPoints instead.
-
- The \a pos provides the location of the mouse cursor
- within the widget. The position in global coordinates is specified
- by \a globalPos. \a delta contains the rotation distance, \a modifiers
- holds the keyboard modifier flags at the time of the event, and
- \a orient holds the wheel's orientation.
-
-
- \sa pos(), pixelDelta(), angleDelta()
+ This constructor has been deprecated.
*/
QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos, int delta,
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
@@ -827,27 +793,8 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos, int delta
}
/*!
- Constructs a wheel event object.
-
- The \a pos provides the location of the mouse cursor
- within the window. The position in global coordinates is specified
- by \a globalPos.
-
- \a pixelDelta contains the scrolling distance in pixels on screen, while
- \a angleDelta contains the wheel rotation distance. \a pixelDelta is
- optional and can be null.
-
- The mouse and keyboard states at the time of the event are specified by
- \a buttons and \a modifiers.
-
- For backwards compatibility, the event can also hold monodirectional wheel
- event data: \a qt4Delta specifies the rotation, and \a qt4Orientation the
- direction.
-
- The phase() is initialized to Qt::ScrollUpdate. Use the other constructor
- to specify the phase explicitly.
-
- \sa posF(), globalPosF(), angleDelta(), pixelDelta()
+ \obsolete
+ This constructor has been deprecated.
*/
QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
@@ -858,26 +805,8 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
{}
/*!
- Constructs a wheel event object.
-
- The \a pos provides the location of the mouse cursor
- within the window. The position in global coordinates is specified
- by \a globalPos.
-
- \a pixelDelta contains the scrolling distance in pixels on screen, while
- \a angleDelta contains the wheel rotation distance. \a pixelDelta is
- optional and can be null.
-
- The mouse and keyboard states at the time of the event are specified by
- \a buttons and \a modifiers.
-
- For backwards compatibility, the event can also hold monodirectional wheel
- event data: \a qt4Delta specifies the rotation, and \a qt4Orientation the
- direction.
-
- The scrolling phase of the event is specified by \a phase.
-
- \sa posF(), globalPosF(), angleDelta(), pixelDelta(), phase()
+ \obsolete
+ This constructor has been deprecated.
*/
QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
@@ -888,31 +817,8 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
{}
/*!
- Constructs a wheel event object.
-
- The \a pos provides the location of the mouse cursor within the window. The
- position in global coordinates is specified by \a globalPos.
-
- \a pixelDelta contains the scrolling distance in pixels on screen, while
- \a angleDelta contains the wheel rotation distance. \a pixelDelta is
- optional and can be null.
-
- The mouse and keyboard states at the time of the event are specified by
- \a buttons and \a modifiers.
-
- For backwards compatibility, the event can also hold monodirectional wheel
- event data: \a qt4Delta specifies the rotation, and \a qt4Orientation the
- direction.
-
- The scrolling phase of the event is specified by \a phase.
-
- If the wheel event comes from a physical mouse wheel, \a source is set to
- Qt::MouseEventNotSynthesized. If it comes from a gesture detected by the
- operating system, or from a non-mouse hardware device, such that \a pixelDelta is
- directly related to finger movement, \a source is set to Qt::MouseEventSynthesizedBySystem.
- If it comes from Qt, source would be set to Qt::MouseEventSynthesizedByQt.
-
- \sa posF(), globalPosF(), angleDelta(), pixelDelta(), phase()
+ \obsolete
+ This constructor has been deprecated.
*/
QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
@@ -923,37 +829,8 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
{}
/*!
- Constructs a wheel event object.
-
- The \a pos provides the location of the mouse cursor
- within the window. The position in global coordinates is specified
- by \a globalPos.
-
- \a pixelDelta contains the scrolling distance in pixels on screen, while
- \a angleDelta contains the wheel rotation distance. \a pixelDelta is
- optional and can be null.
-
- The mouse and keyboard states at the time of the event are specified by
- \a buttons and \a modifiers.
-
- For backwards compatibility, the event can also hold monodirectional wheel
- event data: \a qt4Delta specifies the rotation, and \a qt4Orientation the
- direction.
-
- The scrolling phase of the event is specified by \a phase.
-
- If the wheel event comes from a physical mouse wheel, \a source is set to
- Qt::MouseEventNotSynthesized. If it comes from a gesture detected by the
- operating system, or from a non-mouse hardware device, such that \a
- pixelDelta is directly related to finger movement, \a source is set to
- Qt::MouseEventSynthesizedBySystem. If it comes from Qt, source would be set
- to Qt::MouseEventSynthesizedByQt.
-
- If the system is configured to invert the delta values delivered with the
- event (such as natural scrolling of the touchpad on OS X), \a inverted
- should be \c true. Otherwise, \a inverted is \c false
-
- \sa posF(), globalPosF(), angleDelta(), pixelDelta(), phase()
+ \obsolete
+ This constructor has been deprecated.
*/
QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
QPoint pixelDelta, QPoint angleDelta, int qt4Delta, Qt::Orientation qt4Orientation,
@@ -962,6 +839,7 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
angleD(angleDelta), qt4D(qt4Delta), qt4O(qt4Orientation), mouseState(buttons), src(source),
invertedScrolling(inverted), ph(phase)
{}
+#endif // QT_DEPRECATED_SINCE(5, 15)
/*!
Constructs a wheel event object.
@@ -990,7 +868,7 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
event (such as natural scrolling of the touchpad on macOS), \a inverted
should be \c true. Otherwise, \a inverted is \c false
- \sa posF(), globalPosF(), angleDelta(), pixelDelta(), phase()
+ \sa position(), globalPosition(), angleDelta(), pixelDelta(), phase(), inverted(), source()
*/
QWheelEvent::QWheelEvent(QPointF pos, QPointF globalPos, QPoint pixelDelta, QPoint angleDelta,
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase,
@@ -1002,6 +880,12 @@ QWheelEvent::QWheelEvent(QPointF pos, QPointF globalPos, QPoint pixelDelta, QPoi
qt4D = (qt4O == Qt::Horizontal ? angleDelta.x() : angleDelta.y());
}
+/*!
+ \internal
+*/
+QWheelEvent::~QWheelEvent()
+{
+}
#endif // QT_CONFIG(wheelevent)
/*!
@@ -1061,87 +945,59 @@ QWheelEvent::QWheelEvent(QPointF pos, QPointF globalPos, QPoint pixelDelta, QPoi
/*!
\fn QPoint QWheelEvent::pos() const
+ \obsolete
- Returns the position of the mouse cursor relative to the widget
- that received the event.
-
- If you move your widgets around in response to mouse events,
- use globalPos() instead of this function.
-
- \sa x(), y(), globalPos()
+ This function has been deprecated, use position() instead.
*/
/*!
\fn int QWheelEvent::x() const
+ \obsolete
- Returns the x position of the mouse cursor, relative to the
- widget that received the event.
-
- \sa y(), pos()
+ This function has been deprecated, use position() instead.
*/
/*!
\fn int QWheelEvent::y() const
+ \obsolete
- Returns the y position of the mouse cursor, relative to the
- widget that received the event.
-
- \sa x(), pos()
+ This function has been deprecated, use position() instead.
*/
/*!
\fn QPoint QWheelEvent::globalPos() const
+ \obsolete
- Returns the global position of the mouse pointer \e{at the time
- of the event}. This is important on asynchronous window systems
- such as X11; whenever you move your widgets around in response to
- mouse events, globalPos() can differ a lot from the current
- cursor position returned by QCursor::pos().
-
- \sa globalX(), globalY()
+ This function has been deprecated, use globalPosition() instead.
*/
/*!
\fn int QWheelEvent::globalX() const
+ \obsolete
- Returns the global x position of the mouse cursor at the time of
- the event.
-
- \sa globalY(), globalPos()
+ This function has been deprecated, use globalPosition() instead.
*/
/*!
\fn int QWheelEvent::globalY() const
+ \obsolete
- Returns the global y position of the mouse cursor at the time of
- the event.
-
- \sa globalX(), globalPos()
+ This function has been deprecated, use globalPosition() instead.
*/
/*!
\fn const QPointF &QWheelEvent::posF() const
+ \obsolete
- Returns the position of the mouse cursor relative to the widget
- that received the event.
-
- If you move your widgets around in response to mouse events,
- use globalPosF() instead of this function.
-
- \sa globalPosF()
+ This function has been deprecated, use position() instead.
*/
/*!
\fn const QPointF &QWheelEvent::globalPosF() const
+ \obsolete
- Returns the global position of the mouse pointer \e{at the time
- of the event}. This is important on asynchronous window systems
- such as X11; whenever you move your widgets around in response to
- mouse events, globalPosF() can differ a lot from the current
- cursor position returned by QCursor::pos().
-
- \sa posF()
+ This function has been deprecated, use globalPosition() instead.
*/
/*!
@@ -4074,8 +3930,10 @@ QDebug operator<<(QDebug dbg, const QEvent *e)
dbg << "QWheelEvent(" << we->phase();
if (!we->pixelDelta().isNull() || !we->angleDelta().isNull())
dbg << ", pixelDelta=" << we->pixelDelta() << ", angleDelta=" << we->angleDelta();
+#if QT_DEPRECATED_SINCE(5, 14)
else if (int qt4Delta = we->delta())
dbg << ", delta=" << qt4Delta << ", orientation=" << we->orientation();
+#endif
dbg << ')';
}
break;
diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h
index eb0a6208a9..b73d90529a 100644
--- a/src/gui/kernel/qevent.h
+++ b/src/gui/kernel/qevent.h
@@ -175,24 +175,34 @@ class Q_GUI_EXPORT QWheelEvent : public QInputEvent
public:
enum { DefaultDeltasPerStep = 120 };
+#if QT_DEPRECATED_SINCE(5, 15)
+ // Actually deprecated since 5.0, in docs
+ QT_DEPRECATED_VERSION_X_5_15("Use the last QWheelEvent constructor taking pixelDelta, angleDelta, phase, and inverted")
QWheelEvent(const QPointF &pos, int delta,
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
Qt::Orientation orient = Qt::Vertical);
+ // Actually deprecated since 5.0, in docs
+ QT_DEPRECATED_VERSION_X_5_15("Use the last QWheelEvent constructor taking pixelDelta, angleDelta, phase, and inverted")
QWheelEvent(const QPointF &pos, const QPointF& globalPos, int delta,
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
Qt::Orientation orient = Qt::Vertical);
+ QT_DEPRECATED_VERSION_X_5_15("Use the last QWheelEvent constructor taking pixelDelta, angleDelta, phase, and inverted")
QWheelEvent(const QPointF &pos, const QPointF& globalPos,
QPoint pixelDelta, QPoint angleDelta, int qt4Delta, Qt::Orientation qt4Orientation,
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
+ QT_DEPRECATED_VERSION_X_5_15("Use the last QWheelEvent constructor taking pixelDelta, angleDelta, phase, and inverted")
QWheelEvent(const QPointF &pos, const QPointF& globalPos,
QPoint pixelDelta, QPoint angleDelta, int qt4Delta, Qt::Orientation qt4Orientation,
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase);
+ QT_DEPRECATED_VERSION_X_5_15("Use the last QWheelEvent constructor taking pixelDelta, angleDelta, phase, and inverted")
QWheelEvent(const QPointF &pos, const QPointF &globalPos, QPoint pixelDelta, QPoint angleDelta,
int qt4Delta, Qt::Orientation qt4Orientation, Qt::MouseButtons buttons,
Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, Qt::MouseEventSource source);
+ QT_DEPRECATED_VERSION_X_5_15("Use the last QWheelEvent constructor taking pixelDelta, angleDelta, phase, and inverted")
QWheelEvent(const QPointF &pos, const QPointF &globalPos, QPoint pixelDelta, QPoint angleDelta,
int qt4Delta, Qt::Orientation qt4Orientation, Qt::MouseButtons buttons,
Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, Qt::MouseEventSource source, bool inverted);
+#endif
QWheelEvent(QPointF pos, QPointF globalPos, QPoint pixelDelta, QPoint angleDelta,
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase,
@@ -203,19 +213,35 @@ public:
inline QPoint pixelDelta() const { return pixelD; }
inline QPoint angleDelta() const { return angleD; }
+#if QT_DEPRECATED_SINCE(5, 15)
+ // Actually deprecated since 5.0, in docs
+ QT_DEPRECATED_VERSION_X_5_15("Use angleDelta()")
inline int delta() const { return qt4D; }
+ // Actually deprecated since 5.0, in docs
+ QT_DEPRECATED_VERSION_X_5_15("Use angleDelta()")
inline Qt::Orientation orientation() const { return qt4O; }
-
#ifndef QT_NO_INTEGER_EVENT_COORDINATES
+ QT_DEPRECATED_VERSION_X_5_15("Use position()")
inline QPoint pos() const { return p.toPoint(); }
+ QT_DEPRECATED_VERSION_X_5_15("Use globalPosition()")
inline QPoint globalPos() const { return g.toPoint(); }
+ QT_DEPRECATED_VERSION_X_5_15("Use position()")
inline int x() const { return int(p.x()); }
+ QT_DEPRECATED_VERSION_X_5_15("Use position()")
inline int y() const { return int(p.y()); }
+ QT_DEPRECATED_VERSION_X_5_15("Use globalPosition()")
inline int globalX() const { return int(g.x()); }
+ QT_DEPRECATED_VERSION_X_5_15("Use globalPosition()")
inline int globalY() const { return int(g.y()); }
#endif
+ QT_DEPRECATED_VERSION_X_5_15("Use position()")
inline const QPointF &posF() const { return p; }
+ QT_DEPRECATED_VERSION_X_5_15("Use globalPosition()")
inline const QPointF &globalPosF() const { return g; }
+#endif // QT_DEPRECATED_SINCE(5, 15)
+
+ inline QPointF position() const { return p; }
+ inline QPointF globalPosition() const { return g; }
inline Qt::MouseButtons buttons() const { return mouseState; }
@@ -231,7 +257,7 @@ protected:
QPoint angleD;
int qt4D = 0;
Qt::Orientation qt4O = Qt::Vertical;
- Qt::MouseButtons mouseState;
+ Qt::MouseButtons mouseState = Qt::NoButton;
uint _unused_ : 2; // Kept for binary compatibility
uint src: 2;
bool invertedScrolling : 1;
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index ceb5055a9d..426f2aeece 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -2239,8 +2239,13 @@ void QGuiApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::Wh
return;
}
+#if QT_DEPRECATED_SINCE(5, 14)
QWheelEvent ev(localPoint, globalPoint, e->pixelDelta, e->angleDelta, e->qt4Delta, e->qt4Orientation,
mouse_buttons, e->modifiers, e->phase, e->source, e->inverted);
+#else
+ QWheelEvent ev(localPoint, globalPoint, e->pixelDelta, e->angleDelta,
+ mouse_buttons, e->modifiers, e->phase, e->inverted, e->source);
+#endif
ev.setTimestamp(e->timestamp);
QGuiApplication::sendSpontaneousEvent(window, &ev);
#else
diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp
index 326d2823eb..10adee438b 100644
--- a/src/gui/kernel/qopenglcontext.cpp
+++ b/src/gui/kernel/qopenglcontext.cpp
@@ -611,8 +611,8 @@ bool QOpenGLContext::create()
d->platformGLContext = QGuiApplicationPrivate::platformIntegration()->createPlatformOpenGLContext(this);
if (!d->platformGLContext)
return false;
- d->platformGLContext->initialize();
d->platformGLContext->setContext(this);
+ d->platformGLContext->initialize();
if (!d->platformGLContext->isSharing())
d->shareContext = 0;
d->shareGroup = d->shareContext ? d->shareContext->shareGroup() : new QOpenGLContextGroup;
diff --git a/src/gui/kernel/qstylehints.cpp b/src/gui/kernel/qstylehints.cpp
index 9b5b7a6f1e..732ede90d0 100644
--- a/src/gui/kernel/qstylehints.cpp
+++ b/src/gui/kernel/qstylehints.cpp
@@ -65,6 +65,20 @@ static inline QVariant themeableHint(QPlatformTheme::ThemeHint th,
return QGuiApplicationPrivate::platformIntegration()->styleHint(ih);
}
+static inline QVariant themeableHint(QPlatformTheme::ThemeHint th)
+{
+ if (!QCoreApplication::instance()) {
+ qWarning("Must construct a QGuiApplication before accessing a platform theme hint.");
+ return QVariant();
+ }
+ if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
+ const QVariant themeHint = theme->themeHint(th);
+ if (themeHint.isValid())
+ return themeHint;
+ }
+ return QPlatformTheme::defaultThemeHint(th);
+}
+
class QStyleHintsPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QStyleHints)
@@ -80,6 +94,8 @@ public:
int m_showShortcutsInContextMenus = -1;
int m_wheelScrollLines = -1;
int m_mouseQuickSelectionThreshold = -1;
+ int m_mouseDoubleClickDistance = -1;
+ int m_touchDoubleTapDistance = -1;
};
/*!
@@ -133,6 +149,34 @@ int QStyleHints::mouseDoubleClickInterval() const
}
/*!
+ \property QStyleHints::mouseDoubleClickDistance
+ \brief the maximum distance, in pixels, that the mouse can be moved between
+ two consecutive mouse clicks and still have it detected as a double-click
+ \since 5.14
+*/
+int QStyleHints::mouseDoubleClickDistance() const
+{
+ Q_D(const QStyleHints);
+ return d->m_mouseDoubleClickDistance >= 0 ?
+ d->m_mouseDoubleClickDistance :
+ themeableHint(QPlatformTheme::MouseDoubleClickDistance).toInt();
+}
+
+/*!
+ \property QStyleHints::touchDoubleTapDistance
+ \brief the maximum distance, in pixels, that a finger can be moved between
+ two consecutive taps and still have it detected as a double-tap
+ \since 5.14
+*/
+int QStyleHints::touchDoubleTapDistance() const
+{
+ Q_D(const QStyleHints);
+ return d->m_touchDoubleTapDistance >= 0 ?
+ d->m_touchDoubleTapDistance :
+ themeableHint(QPlatformTheme::TouchDoubleTapDistance).toInt();
+}
+
+/*!
Sets the \a mousePressAndHoldInterval.
\internal
\sa mousePressAndHoldInterval()
diff --git a/src/gui/kernel/qstylehints.h b/src/gui/kernel/qstylehints.h
index 9091db9624..30d8fdc64d 100644
--- a/src/gui/kernel/qstylehints.h
+++ b/src/gui/kernel/qstylehints.h
@@ -74,10 +74,14 @@ class Q_GUI_EXPORT QStyleHints : public QObject
Q_PROPERTY(bool useHoverEffects READ useHoverEffects WRITE setUseHoverEffects NOTIFY useHoverEffectsChanged FINAL)
Q_PROPERTY(int wheelScrollLines READ wheelScrollLines NOTIFY wheelScrollLinesChanged FINAL)
Q_PROPERTY(int mouseQuickSelectionThreshold READ mouseQuickSelectionThreshold WRITE setMouseQuickSelectionThreshold NOTIFY mouseQuickSelectionThresholdChanged FINAL)
+ Q_PROPERTY(int mouseDoubleClickDistance READ mouseDoubleClickDistance STORED false CONSTANT FINAL)
+ Q_PROPERTY(int touchDoubleTapDistance READ touchDoubleTapDistance STORED false CONSTANT FINAL)
public:
void setMouseDoubleClickInterval(int mouseDoubleClickInterval);
int mouseDoubleClickInterval() const;
+ int mouseDoubleClickDistance() const;
+ int touchDoubleTapDistance() const;
void setMousePressAndHoldInterval(int mousePressAndHoldInterval);
int mousePressAndHoldInterval() const;
void setStartDragDistance(int startDragDistance);
diff --git a/src/gui/opengl/qopenglprogrambinarycache.cpp b/src/gui/opengl/qopenglprogrambinarycache.cpp
index c96021a969..1f1ac1fd80 100644
--- a/src/gui/opengl/qopenglprogrambinarycache.cpp
+++ b/src/gui/opengl/qopenglprogrambinarycache.cpp
@@ -168,12 +168,19 @@ bool QOpenGLProgramBinaryCache::verifyHeader(const QByteArray &buf) const
bool QOpenGLProgramBinaryCache::setProgramBinary(uint programId, uint blobFormat, const void *p, uint blobSize)
{
- QOpenGLExtraFunctions *funcs = QOpenGLContext::currentContext()->extraFunctions();
+ QOpenGLContext *context = QOpenGLContext::currentContext();
+ QOpenGLExtraFunctions *funcs = context->extraFunctions();
while (true) {
GLenum error = funcs->glGetError();
if (error == GL_NO_ERROR || error == GL_CONTEXT_LOST)
break;
}
+#if defined(QT_OPENGL_ES_2)
+ if (context->isOpenGLES() && context->format().majorVersion() < 3) {
+ initializeProgramBinaryOES(context);
+ programBinaryOES(programId, blobFormat, p, blobSize);
+ } else
+#endif
funcs->glProgramBinary(programId, blobFormat, p, blobSize);
GLenum err = funcs->glGetError();
@@ -347,7 +354,8 @@ void QOpenGLProgramBinaryCache::save(const QByteArray &cacheKey, uint programId)
GLEnvInfo info;
- QOpenGLExtraFunctions *funcs = QOpenGLContext::currentContext()->extraFunctions();
+ QOpenGLContext *context = QOpenGLContext::currentContext();
+ QOpenGLExtraFunctions *funcs = context->extraFunctions();
GLint blobSize = 0;
while (true) {
GLenum error = funcs->glGetError();
@@ -390,6 +398,12 @@ void QOpenGLProgramBinaryCache::save(const QByteArray &cacheKey, uint programId)
*p++ = 0;
GLint outSize = 0;
+#if defined(QT_OPENGL_ES_2)
+ if (context->isOpenGLES() && context->format().majorVersion() < 3) {
+ initializeProgramBinaryOES(context);
+ getProgramBinaryOES(programId, blobSize, &outSize, &blobFormat, p);
+ } else
+#endif
funcs->glGetProgramBinary(programId, blobSize, &outSize, &blobFormat, p);
if (blobSize != outSize) {
qCDebug(DBG_SHADER_CACHE, "glGetProgramBinary returned size %d instead of %d", outSize, blobSize);
@@ -398,14 +412,33 @@ void QOpenGLProgramBinaryCache::save(const QByteArray &cacheKey, uint programId)
writeUInt(&blobFormatPtr, blobFormat);
+#if QT_CONFIG(temporaryfile)
QSaveFile f(cacheFileName(cacheKey));
if (f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
f.write(blob);
if (!f.commit())
+#else
+ QFile f(cacheFileName(cacheKey));
+ if (f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
+ if (f.write(blob) < blob.length())
+#endif
qCDebug(DBG_SHADER_CACHE, "Failed to write %s to shader cache", qPrintable(f.fileName()));
} else {
qCDebug(DBG_SHADER_CACHE, "Failed to create %s in shader cache", qPrintable(f.fileName()));
}
}
+#if defined(QT_OPENGL_ES_2)
+void QOpenGLProgramBinaryCache::initializeProgramBinaryOES(QOpenGLContext *context)
+{
+ if (m_programBinaryOESInitialized)
+ return;
+ m_programBinaryOESInitialized = true;
+
+ Q_ASSERT(context);
+ getProgramBinaryOES = (void (QOPENGLF_APIENTRYP)(GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary))context->getProcAddress("glGetProgramBinaryOES");
+ programBinaryOES = (void (QOPENGLF_APIENTRYP)(GLuint program, GLenum binaryFormat, const GLvoid *binary, GLint length))context->getProcAddress("glProgramBinaryOES");
+}
+#endif
+
QT_END_NAMESPACE
diff --git a/src/gui/opengl/qopenglprogrambinarycache_p.h b/src/gui/opengl/qopenglprogrambinarycache_p.h
index a0e1f91e25..9fade08e66 100644
--- a/src/gui/opengl/qopenglprogrambinarycache_p.h
+++ b/src/gui/opengl/qopenglprogrambinarycache_p.h
@@ -93,6 +93,12 @@ private:
uint format;
};
QCache<QByteArray, MemCacheEntry> m_memCache;
+#if defined(QT_OPENGL_ES_2)
+ void (QOPENGLF_APIENTRYP programBinaryOES)(GLuint program, GLenum binaryFormat, const GLvoid *binary, GLsizei length);
+ void (QOPENGLF_APIENTRYP getProgramBinaryOES)(GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary);
+ void initializeProgramBinaryOES(QOpenGLContext *context);
+ bool m_programBinaryOESInitialized = false;
+#endif
};
QT_END_NAMESPACE
diff --git a/src/gui/opengl/qopenglshaderprogram.cpp b/src/gui/opengl/qopenglshaderprogram.cpp
index f225d5dc75..3c7bd4f90d 100644
--- a/src/gui/opengl/qopenglshaderprogram.cpp
+++ b/src/gui/opengl/qopenglshaderprogram.cpp
@@ -3755,8 +3755,14 @@ QOpenGLProgramBinarySupportCheck::QOpenGLProgramBinarySupportCheck(QOpenGLContex
if (ctx) {
if (ctx->isOpenGLES()) {
qCDebug(DBG_SHADER_CACHE, "OpenGL ES v%d context", ctx->format().majorVersion());
- if (ctx->format().majorVersion() >= 3)
+ if (ctx->format().majorVersion() >= 3) {
m_supported = true;
+ } else {
+ const bool hasExt = ctx->hasExtension("GL_OES_get_program_binary");
+ qCDebug(DBG_SHADER_CACHE, "GL_OES_get_program_binary support = %d", hasExt);
+ if (hasExt)
+ m_supported = true;
+ }
} else {
const bool hasExt = ctx->hasExtension("GL_ARB_get_program_binary");
qCDebug(DBG_SHADER_CACHE, "GL_ARB_get_program_binary support = %d", hasExt);
diff --git a/src/gui/opengl/qopengltextureglyphcache.cpp b/src/gui/opengl/qopengltextureglyphcache.cpp
index e3cbba955d..490dc99749 100644
--- a/src/gui/opengl/qopengltextureglyphcache.cpp
+++ b/src/gui/opengl/qopengltextureglyphcache.cpp
@@ -53,8 +53,8 @@ static int next_qopengltextureglyphcache_serial_number()
return 1 + serial.fetchAndAddRelaxed(1);
}
-QOpenGLTextureGlyphCache::QOpenGLTextureGlyphCache(QFontEngine::GlyphFormat format, const QTransform &matrix)
- : QImageTextureGlyphCache(format, matrix)
+QOpenGLTextureGlyphCache::QOpenGLTextureGlyphCache(QFontEngine::GlyphFormat format, const QTransform &matrix, const QColor &color)
+ : QImageTextureGlyphCache(format, matrix, color)
, m_textureResource(0)
, pex(0)
, m_blitProgram(0)
diff --git a/src/gui/opengl/qopengltextureglyphcache_p.h b/src/gui/opengl/qopengltextureglyphcache_p.h
index aed128cf9e..4bea4a463a 100644
--- a/src/gui/opengl/qopengltextureglyphcache_p.h
+++ b/src/gui/opengl/qopengltextureglyphcache_p.h
@@ -110,7 +110,7 @@ public:
class Q_GUI_EXPORT QOpenGLTextureGlyphCache : public QImageTextureGlyphCache
{
public:
- QOpenGLTextureGlyphCache(QFontEngine::GlyphFormat glyphFormat, const QTransform &matrix);
+ QOpenGLTextureGlyphCache(QFontEngine::GlyphFormat glyphFormat, const QTransform &matrix, const QColor &color = QColor());
~QOpenGLTextureGlyphCache();
virtual void createTextureData(int width, int height) override;
diff --git a/src/gui/painting/qbackingstore.cpp b/src/gui/painting/qbackingstore.cpp
index 3fab903c4d..3240b83451 100644
--- a/src/gui/painting/qbackingstore.cpp
+++ b/src/gui/painting/qbackingstore.cpp
@@ -186,7 +186,7 @@ QPaintDevice *QBackingStore::paintDevice()
void QBackingStore::endPaint()
{
if (paintDevice()->paintingActive())
- qWarning() << "QBackingStore::endPaint() called with active painter on backingstore paint device";
+ qWarning("QBackingStore::endPaint() called with active painter; did you forget to destroy it or call QPainter::end() on it?");
handle()->endPaint();
}
diff --git a/src/gui/painting/qcolorspace.cpp b/src/gui/painting/qcolorspace.cpp
index 8d3bbbe412..043a951521 100644
--- a/src/gui/painting/qcolorspace.cpp
+++ b/src/gui/painting/qcolorspace.cpp
@@ -55,34 +55,34 @@ QT_BEGIN_NAMESPACE
QBasicMutex QColorSpacePrivate::s_lutWriteLock;
-QColorSpacePrimaries::QColorSpacePrimaries(QColorSpace::Gamut gamut)
+QColorSpacePrimaries::QColorSpacePrimaries(QColorSpace::Primaries primaries)
{
- switch (gamut) {
- case QColorSpace::Gamut::SRgb:
+ switch (primaries) {
+ case QColorSpace::Primaries::SRgb:
redPoint = QPointF(0.640, 0.330);
greenPoint = QPointF(0.300, 0.600);
bluePoint = QPointF(0.150, 0.060);
whitePoint = QColorVector::D65Chromaticity();
break;
- case QColorSpace::Gamut::DciP3D65:
+ case QColorSpace::Primaries::DciP3D65:
redPoint = QPointF(0.680, 0.320);
greenPoint = QPointF(0.265, 0.690);
bluePoint = QPointF(0.150, 0.060);
whitePoint = QColorVector::D65Chromaticity();
break;
- case QColorSpace::Gamut::Bt2020:
+ case QColorSpace::Primaries::Bt2020:
redPoint = QPointF(0.708, 0.292);
greenPoint = QPointF(0.190, 0.797);
bluePoint = QPointF(0.131, 0.046);
whitePoint = QColorVector::D65Chromaticity();
break;
- case QColorSpace::Gamut::AdobeRgb:
+ case QColorSpace::Primaries::AdobeRgb:
redPoint = QPointF(0.640, 0.330);
greenPoint = QPointF(0.210, 0.710);
bluePoint = QPointF(0.150, 0.060);
whitePoint = QColorVector::D65Chromaticity();
break;
- case QColorSpace::Gamut::ProPhotoRgb:
+ case QColorSpace::Primaries::ProPhotoRgb:
redPoint = QPointF(0.7347, 0.2653);
greenPoint = QPointF(0.1596, 0.8404);
bluePoint = QPointF(0.0366, 0.0001);
@@ -153,7 +153,7 @@ QColorMatrix QColorSpacePrimaries::toXyzMatrix() const
QColorSpacePrivate::QColorSpacePrivate()
: id(QColorSpace::Unknown)
- , gamut(QColorSpace::Gamut::Custom)
+ , primaries(QColorSpace::Primaries::Custom)
, transferFunction(QColorSpace::TransferFunction::Custom)
, gamma(0.0f)
, whitePoint(QColorVector::null())
@@ -163,48 +163,43 @@ QColorSpacePrivate::QColorSpacePrivate()
QColorSpacePrivate::QColorSpacePrivate(QColorSpace::ColorSpaceId colorSpaceId)
: id(colorSpaceId)
+ , gamma(0.0f)
{
switch (colorSpaceId) {
case QColorSpace::Undefined:
- gamut = QColorSpace::Gamut::Custom;
+ primaries = QColorSpace::Primaries::Custom;
transferFunction = QColorSpace::TransferFunction::Custom;
- gamma = 0.0f;
description = QStringLiteral("Undefined");
break;
case QColorSpace::SRgb:
- gamut = QColorSpace::Gamut::SRgb;
+ primaries = QColorSpace::Primaries::SRgb;
transferFunction = QColorSpace::TransferFunction::SRgb;
- gamma = 2.31f; // ?
description = QStringLiteral("sRGB");
break;
case QColorSpace::SRgbLinear:
- gamut = QColorSpace::Gamut::SRgb;
+ primaries = QColorSpace::Primaries::SRgb;
transferFunction = QColorSpace::TransferFunction::Linear;
- gamma = 1.0f;
description = QStringLiteral("Linear sRGB");
break;
case QColorSpace::AdobeRgb:
- gamut = QColorSpace::Gamut::AdobeRgb;
+ primaries = QColorSpace::Primaries::AdobeRgb;
transferFunction = QColorSpace::TransferFunction::Gamma;
gamma = 2.19921875f; // Not quite 2.2, see https://www.adobe.com/digitalimag/pdfs/AdobeRGB1998.pdf
description = QStringLiteral("Adobe RGB");
break;
case QColorSpace::DisplayP3:
- gamut = QColorSpace::Gamut::DciP3D65;
+ primaries = QColorSpace::Primaries::DciP3D65;
transferFunction = QColorSpace::TransferFunction::SRgb;
- gamma = 2.31f; // ?
description = QStringLiteral("Display P3");
break;
case QColorSpace::ProPhotoRgb:
- gamut = QColorSpace::Gamut::ProPhotoRgb;
+ primaries = QColorSpace::Primaries::ProPhotoRgb;
transferFunction = QColorSpace::TransferFunction::ProPhotoRgb;
- gamma = 1.8f;
description = QStringLiteral("ProPhoto RGB");
break;
case QColorSpace::Bt2020:
- gamut = QColorSpace::Gamut::Bt2020;
+ primaries = QColorSpace::Primaries::Bt2020;
transferFunction = QColorSpace::TransferFunction::Bt2020;
- gamma = 2.1f; // ?
description = QStringLiteral("BT.2020");
break;
case QColorSpace::Unknown:
@@ -216,8 +211,8 @@ QColorSpacePrivate::QColorSpacePrivate(QColorSpace::ColorSpaceId colorSpaceId)
initialize();
}
-QColorSpacePrivate::QColorSpacePrivate(QColorSpace::Gamut gamut, QColorSpace::TransferFunction fun, float gamma)
- : gamut(gamut)
+QColorSpacePrivate::QColorSpacePrivate(QColorSpace::Primaries primaries, QColorSpace::TransferFunction fun, float gamma)
+ : primaries(primaries)
, transferFunction(fun)
, gamma(gamma)
{
@@ -229,74 +224,81 @@ QColorSpacePrivate::QColorSpacePrivate(QColorSpace::Gamut gamut, QColorSpace::Tr
QColorSpacePrivate::QColorSpacePrivate(const QColorSpacePrimaries &primaries,
QColorSpace::TransferFunction fun,
float gamma)
- : gamut(QColorSpace::Gamut::Custom)
+ : primaries(QColorSpace::Primaries::Custom)
, transferFunction(fun)
, gamma(gamma)
{
Q_ASSERT(primaries.areValid());
toXyz = primaries.toXyzMatrix();
whitePoint = QColorVector(primaries.whitePoint);
- if (!identifyColorSpace())
- id = QColorSpace::Unknown;
+ identifyColorSpace();
setTransferFunction();
}
bool QColorSpacePrivate::identifyColorSpace()
{
- switch (gamut) {
- case QColorSpace::Gamut::SRgb:
+ switch (primaries) {
+ case QColorSpace::Primaries::SRgb:
if (transferFunction == QColorSpace::TransferFunction::SRgb) {
id = QColorSpace::SRgb;
- description = QStringLiteral("sRGB");
+ if (description.isEmpty())
+ description = QStringLiteral("sRGB");
return true;
}
if (transferFunction == QColorSpace::TransferFunction::Linear) {
id = QColorSpace::SRgbLinear;
- description = QStringLiteral("Linear sRGB");
+ if (description.isEmpty())
+ description = QStringLiteral("Linear sRGB");
return true;
}
break;
- case QColorSpace::Gamut::AdobeRgb:
+ case QColorSpace::Primaries::AdobeRgb:
if (transferFunction == QColorSpace::TransferFunction::Gamma) {
if (qAbs(gamma - 2.19921875f) < (1/1024.0f)) {
id = QColorSpace::AdobeRgb;
- description = QStringLiteral("Adobe RGB");
+ if (description.isEmpty())
+ description = QStringLiteral("Adobe RGB");
return true;
}
}
break;
- case QColorSpace::Gamut::DciP3D65:
+ case QColorSpace::Primaries::DciP3D65:
if (transferFunction == QColorSpace::TransferFunction::SRgb) {
id = QColorSpace::DisplayP3;
- description = QStringLiteral("Display P3");
+ if (description.isEmpty())
+ description = QStringLiteral("Display P3");
return true;
}
break;
- case QColorSpace::Gamut::ProPhotoRgb:
+ case QColorSpace::Primaries::ProPhotoRgb:
if (transferFunction == QColorSpace::TransferFunction::ProPhotoRgb) {
id = QColorSpace::ProPhotoRgb;
- description = QStringLiteral("ProPhoto RGB");
+ if (description.isEmpty())
+ description = QStringLiteral("ProPhoto RGB");
return true;
}
if (transferFunction == QColorSpace::TransferFunction::Gamma) {
// ProPhoto RGB's curve is effectively gamma 1.8 for 8bit precision.
if (qAbs(gamma - 1.8f) < (1/1024.0f)) {
id = QColorSpace::ProPhotoRgb;
- description = QStringLiteral("ProPhoto RGB");
+ if (description.isEmpty())
+ description = QStringLiteral("ProPhoto RGB");
return true;
}
}
break;
- case QColorSpace::Gamut::Bt2020:
+ case QColorSpace::Primaries::Bt2020:
if (transferFunction == QColorSpace::TransferFunction::Bt2020) {
id = QColorSpace::Bt2020;
- description = QStringLiteral("BT.2020");
+ if (description.isEmpty())
+ description = QStringLiteral("BT.2020");
return true;
}
break;
default:
break;
}
+ id = QColorSpace::Unknown;
return false;
}
@@ -308,14 +310,14 @@ void QColorSpacePrivate::initialize()
void QColorSpacePrivate::setToXyzMatrix()
{
- if (gamut == QColorSpace::Gamut::Custom) {
+ if (primaries == QColorSpace::Primaries::Custom) {
toXyz = QColorMatrix::null();
whitePoint = QColorVector::D50();
return;
}
- QColorSpacePrimaries primaries(gamut);
- toXyz = primaries.toXyzMatrix();
- whitePoint = QColorVector(primaries.whitePoint);
+ QColorSpacePrimaries colorSpacePrimaries(primaries);
+ toXyz = colorSpacePrimaries.toXyzMatrix();
+ whitePoint = QColorVector(colorSpacePrimaries.whitePoint);
}
void QColorSpacePrivate::setTransferFunction()
@@ -324,6 +326,8 @@ void QColorSpacePrivate::setTransferFunction()
case QColorSpace::TransferFunction::Linear:
trc[0].m_type = QColorTrc::Type::Function;
trc[0].m_fun = QColorTransferFunction();
+ if (qFuzzyIsNull(gamma))
+ gamma = 1.0f;
break;
case QColorSpace::TransferFunction::Gamma:
trc[0].m_type = QColorTrc::Type::Function;
@@ -332,14 +336,20 @@ void QColorSpacePrivate::setTransferFunction()
case QColorSpace::TransferFunction::SRgb:
trc[0].m_type = QColorTrc::Type::Function;
trc[0].m_fun = QColorTransferFunction::fromSRgb();
+ if (qFuzzyIsNull(gamma))
+ gamma = 2.31f;
break;
case QColorSpace::TransferFunction::ProPhotoRgb:
trc[0].m_type = QColorTrc::Type::Function;
trc[0].m_fun = QColorTransferFunction::fromProPhotoRgb();
+ if (qFuzzyIsNull(gamma))
+ gamma = 1.8f;
break;
case QColorSpace::TransferFunction::Bt2020:
trc[0].m_type = QColorTrc::Type::Function;
trc[0].m_fun = QColorTransferFunction::fromBt2020();
+ if (qFuzzyIsNull(gamma))
+ gamma = 1.961f;
break;
case QColorSpace::TransferFunction::Custom:
break;
@@ -355,10 +365,12 @@ QColorTransform QColorSpacePrivate::transformationToColorSpace(const QColorSpace
{
Q_ASSERT(out);
QColorTransform combined;
- combined.d_ptr.reset(new QColorTransformPrivate);
- combined.d_ptr->colorSpaceIn = this;
- combined.d_ptr->colorSpaceOut = out;
- combined.d_ptr->colorMatrix = out->toXyz.inverted() * toXyz;
+ auto ptr = new QColorTransformPrivate;
+ combined.d = ptr;
+ combined.d->ref.ref();
+ ptr->colorSpaceIn = this;
+ ptr->colorSpaceOut = out;
+ ptr->colorMatrix = out->toXyz.inverted() * toXyz;
return combined;
}
@@ -381,12 +393,14 @@ QColorTransform QColorSpacePrivate::transformationToColorSpace(const QColorSpace
QColorSpace can also represent color spaces defined by ICC profiles or embedded
in images, that do not otherwise fit the predefined color spaces.
- A color space can generally speaking be conceived as a combination of a transfer
- function and a gamut. The gamut defines which colors the color space can represent.
- A color space that can represent a wider range of colors is also known as a
- wide-gamut color space. The gamut is defined by three primary colors that represent
- exactly how red, green, and blue look in this particular color space, and a white
- color that represents where and how bright pure white is.
+ A color space can generally speaking be conceived as a combination of set of primary
+ colors and a transfer function. The primaries defines the axes of the color space, and
+ the transfer function how values are mapped on the axes.
+ The primaries are defined by three primary colors that represent exactly how red, green,
+ and blue look in this particular color space, and a white color that represents where
+ and how bright pure white is. The range of colors expressable by the primary colors is
+ called the gamut, and a color space that can represent a wider range of colors is also
+ known as a wide-gamut color space.
The transfer function or gamma curve determines how each component in the
color space is encoded. These are used because human perception does not operate
@@ -418,16 +432,16 @@ QColorTransform QColorSpacePrivate::transformationToColorSpace(const QColorSpace
*/
/*!
- \enum QColorSpace::Gamut
+ \enum QColorSpace::Primaries
- Predefined gamuts, or sets of primary colors.
+ Predefined sets of primary colors.
- \value Custom The gamut is undefined or does not match any predefined sets.
- \value SRgb The sRGB gamut
- \value AdobeRgb The Adobe RGB gamut
- \value DciP3D65 The DCI-P3 gamut with the D65 whitepoint
- \value ProPhotoRgb The ProPhoto RGB gamut with the D50 whitepoint
- \value Bt2020 The BT.2020 gamut
+ \value Custom The primaries are undefined or does not match any predefined sets.
+ \value SRgb The sRGB primaries
+ \value AdobeRgb The Adobe RGB primaries
+ \value DciP3D65 The DCI-P3 primaries with the D65 whitepoint
+ \value ProPhotoRgb The ProPhoto RGB primaries with the D50 whitepoint
+ \value Bt2020 The BT.2020 primaries
*/
/*!
@@ -463,25 +477,25 @@ QColorSpace::QColorSpace(QColorSpace::ColorSpaceId colorSpaceId)
}
/*!
- Creates a custom color space with the gamut \a gamut, using the transfer function \a fun and
+ Creates a custom color space with the primaries \a primaries, using the transfer function \a fun and
optionally \a gamma.
*/
-QColorSpace::QColorSpace(QColorSpace::Gamut gamut, QColorSpace::TransferFunction fun, float gamma)
- : d_ptr(new QColorSpacePrivate(gamut, fun, gamma))
+QColorSpace::QColorSpace(QColorSpace::Primaries primaries, QColorSpace::TransferFunction fun, float gamma)
+ : d_ptr(new QColorSpacePrivate(primaries, fun, gamma))
{
}
/*!
- Creates a custom color space with the gamut \a gamut, using a gamma transfer function of
+ Creates a custom color space with the primaries \a primaries, using a gamma transfer function of
\a gamma.
*/
-QColorSpace::QColorSpace(QColorSpace::Gamut gamut, float gamma)
- : d_ptr(new QColorSpacePrivate(gamut, TransferFunction::Gamma, gamma))
+QColorSpace::QColorSpace(QColorSpace::Primaries primaries, float gamma)
+ : d_ptr(new QColorSpacePrivate(primaries, TransferFunction::Gamma, gamma))
{
}
/*!
- Creates a custom colorspace with a gamut based on the chromaticities of the primary colors \a whitePoint,
+ Creates a custom colorspace with a primaries based on the chromaticities of the primary colors \a whitePoint,
\a redPoint, \a greenPoint and \a bluePoint, and using the transfer function \a fun and optionally \a gamma.
*/
QColorSpace::QColorSpace(const QPointF &whitePoint, const QPointF &redPoint,
@@ -501,7 +515,7 @@ QColorSpace::~QColorSpace()
{
}
-QColorSpace::QColorSpace(QColorSpace &&colorSpace)
+QColorSpace::QColorSpace(QColorSpace &&colorSpace) noexcept
: d_ptr(std::move(colorSpace.d_ptr))
{
}
@@ -511,7 +525,7 @@ QColorSpace::QColorSpace(const QColorSpace &colorSpace)
{
}
-QColorSpace &QColorSpace::operator=(QColorSpace &&colorSpace)
+QColorSpace &QColorSpace::operator=(QColorSpace &&colorSpace) noexcept
{
d_ptr = std::move(colorSpace.d_ptr);
return *this;
@@ -523,6 +537,12 @@ QColorSpace &QColorSpace::operator=(const QColorSpace &colorSpace)
return *this;
}
+/*! \fn void QColorSpace::swap(QColorSpace &other)
+
+ Swaps color space \a other with this color space. This operation is very fast and
+ never fails.
+*/
+
/*!
Returns the id of the predefined color space this object
represents or \c Unknown if it doesn't match any of them.
@@ -533,19 +553,21 @@ QColorSpace::ColorSpaceId QColorSpace::colorSpaceId() const noexcept
}
/*!
- Returns the predefined gamut of the color space
- or \c Gamut::Custom if it doesn't match any of them.
+ Returns the predefined primaries of the color space
+ or \c primaries::Custom if it doesn't match any of them.
*/
-QColorSpace::Gamut QColorSpace::gamut() const noexcept
+QColorSpace::Primaries QColorSpace::primaries() const noexcept
{
- return d_ptr->gamut;
+ if (Q_UNLIKELY(!d_ptr))
+ return QColorSpace::Primaries::Custom;
+ return d_ptr->primaries;
}
/*!
Returns the predefined transfer function of the color space
or \c TransferFunction::Custom if it doesn't match any of them.
- \sa gamma()
+ \sa gamma(), setTransferFunction(), withTransferFunction()
*/
QColorSpace::TransferFunction QColorSpace::transferFunction() const noexcept
{
@@ -565,6 +587,91 @@ float QColorSpace::gamma() const noexcept
}
/*!
+ Sets the transfer function to \a transferFunction and \a gamma.
+
+ \note This also changes colorSpaceId().
+
+ \sa transferFunction(), gamma(), withTransferFunction()
+*/
+void QColorSpace::setTransferFunction(QColorSpace::TransferFunction transferFunction, float gamma)
+{
+ if (!isValid() || transferFunction == QColorSpace::TransferFunction::Custom)
+ return;
+ if (d_ptr->transferFunction == transferFunction && d_ptr->gamma == gamma)
+ return;
+ d_ptr.detach();
+ d_ptr->description.clear();
+ d_ptr->transferFunction = transferFunction;
+ d_ptr->gamma = gamma;
+ d_ptr->identifyColorSpace();
+ d_ptr->setTransferFunction();
+}
+
+/*!
+ Returns a copy of this color space, except using the transfer function
+ \a transferFunction and \a gamma.
+
+ \sa transferFunction(), gamma(), setTransferFunction()
+*/
+QColorSpace QColorSpace::withTransferFunction(QColorSpace::TransferFunction transferFunction, float gamma) const
+{
+ if (!isValid() || transferFunction == QColorSpace::TransferFunction::Custom)
+ return *this;
+ if (d_ptr->transferFunction == transferFunction && d_ptr->gamma == gamma)
+ return *this;
+ QColorSpace out(*this);
+ out.setTransferFunction(transferFunction, gamma);
+ return out;
+}
+
+/*!
+ Sets the primaries to those of the \a primariesId set.
+
+ \note This also changes colorSpaceId().
+
+ \sa primaries()
+*/
+void QColorSpace::setPrimaries(QColorSpace::Primaries primariesId)
+{
+ if (!isValid() || primariesId == QColorSpace::Primaries::Custom)
+ return;
+ if (d_ptr->primaries == primariesId)
+ return;
+ d_ptr.detach();
+ d_ptr->description.clear();
+ d_ptr->primaries = primariesId;
+ d_ptr->identifyColorSpace();
+ d_ptr->setToXyzMatrix();
+}
+
+/*!
+ Set primaries to the chromaticities of \a whitePoint, \a redPoint, \a greenPoint
+ and \a bluePoint.
+
+ \note This also changes colorSpaceId().
+
+ \sa primaries()
+*/
+void QColorSpace::setPrimaries(const QPointF &whitePoint, const QPointF &redPoint,
+ const QPointF &greenPoint, const QPointF &bluePoint)
+{
+ if (!isValid())
+ return;
+ QColorSpacePrimaries primaries(whitePoint, redPoint, greenPoint, bluePoint);
+ if (!primaries.areValid())
+ return;
+ QColorMatrix toXyz = primaries.toXyzMatrix();
+ if (QColorVector(primaries.whitePoint) == d_ptr->whitePoint && toXyz == d_ptr->toXyz)
+ return;
+ d_ptr.detach();
+ d_ptr->description.clear();
+ d_ptr->primaries = QColorSpace::Primaries::Custom;
+ d_ptr->toXyz = toXyz;
+ d_ptr->whitePoint = QColorVector(primaries.whitePoint);
+ d_ptr->identifyColorSpace();
+}
+
+/*!
Returns an ICC profile representing the color space.
If the color space was generated from an ICC profile, that profile
@@ -631,8 +738,8 @@ bool operator==(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2)
if (colorSpace1.colorSpaceId() != QColorSpace::Unknown && colorSpace2.colorSpaceId() != QColorSpace::Unknown)
return colorSpace1.colorSpaceId() == colorSpace2.colorSpaceId();
- if (colorSpace1.gamut() != QColorSpace::Gamut::Custom && colorSpace2.gamut() != QColorSpace::Gamut::Custom) {
- if (colorSpace1.gamut() != colorSpace2.gamut())
+ if (colorSpace1.primaries() != QColorSpace::Primaries::Custom && colorSpace2.primaries() != QColorSpace::Primaries::Custom) {
+ if (colorSpace1.primaries() != colorSpace2.primaries())
return false;
} else {
if (colorSpace1.d_ptr->toXyz != colorSpace2.d_ptr->toXyz)
@@ -644,7 +751,7 @@ bool operator==(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2)
if (colorSpace1.transferFunction() != colorSpace2.transferFunction())
return false;
if (colorSpace1.transferFunction() == QColorSpace::TransferFunction::Gamma)
- return colorSpace1.gamma() == colorSpace2.gamma();
+ return (qAbs(colorSpace1.gamma() - colorSpace2.gamma()) <= (1.0f / 512.0f));
return true;
}
@@ -676,20 +783,6 @@ QColorTransform QColorSpace::transformationToColorSpace(const QColorSpace &color
return d_ptr->transformationToColorSpace(colorspace.d_ptr.constData());
}
-/*!
- \internal
-*/
-QColorSpacePrivate *QColorSpace::d_func()
-{
- d_ptr.detach();
- return d_ptr.data();
-}
-
-/*!
- \fn const QColorSpacePrivate* QColorSpacePrivate::d_func() const
- \internal
-*/
-
/*****************************************************************************
QColorSpace stream functions
*****************************************************************************/
@@ -734,7 +827,7 @@ QDebug operator<<(QDebug dbg, const QColorSpace &colorSpace)
QDebugStateSaver saver(dbg);
dbg.nospace();
dbg << "QColorSpace(";
- dbg << colorSpace.colorSpaceId() << ", " << colorSpace.gamut() << ", " << colorSpace.transferFunction();
+ dbg << colorSpace.colorSpaceId() << ", " << colorSpace.primaries() << ", " << colorSpace.transferFunction();
dbg << ", gamma=" << colorSpace.gamma();
dbg << ')';
return dbg;
diff --git a/src/gui/painting/qcolorspace.h b/src/gui/painting/qcolorspace.h
index 56676826a9..a7c1091911 100644
--- a/src/gui/painting/qcolorspace.h
+++ b/src/gui/painting/qcolorspace.h
@@ -63,7 +63,7 @@ public:
Bt2020,
};
Q_ENUM(ColorSpaceId)
- enum class Gamut {
+ enum class Primaries {
Custom = 0,
SRgb,
AdobeRgb,
@@ -71,7 +71,7 @@ public:
ProPhotoRgb,
Bt2020,
};
- Q_ENUM(Gamut)
+ Q_ENUM(Primaries)
enum class TransferFunction {
Custom = 0,
Linear,
@@ -83,23 +83,33 @@ public:
Q_ENUM(TransferFunction)
QColorSpace(ColorSpaceId colorSpaceId = Undefined);
- QColorSpace(Gamut gamut, TransferFunction fun, float gamma = 0.0f);
- QColorSpace(Gamut gamut, float gamma);
+ QColorSpace(Primaries primaries, TransferFunction fun, float gamma = 0.0f);
+ QColorSpace(Primaries primaries, float gamma);
QColorSpace(const QPointF &whitePoint, const QPointF &redPoint,
const QPointF &greenPoint, const QPointF &bluePoint,
TransferFunction fun, float gamma = 0.0f);
~QColorSpace();
- QColorSpace(QColorSpace &&colorSpace);
+ QColorSpace(QColorSpace &&colorSpace) noexcept;
QColorSpace(const QColorSpace &colorSpace);
- QColorSpace &operator=(QColorSpace &&colorSpace);
+ QColorSpace &operator=(QColorSpace &&colorSpace) noexcept;
QColorSpace &operator=(const QColorSpace &colorSpace);
+ void swap(QColorSpace &colorSpace) noexcept
+ { qSwap(d_ptr, colorSpace.d_ptr); }
+
ColorSpaceId colorSpaceId() const noexcept;
- Gamut gamut() const noexcept;
+ Primaries primaries() const noexcept;
TransferFunction transferFunction() const noexcept;
float gamma() const noexcept;
+ void setTransferFunction(TransferFunction transferFunction, float gamma = 0.0f);
+ QColorSpace withTransferFunction(TransferFunction transferFunction, float gamma = 0.0f) const;
+
+ void setPrimaries(Primaries primariesId);
+ void setPrimaries(const QPointF &whitePoint, const QPointF &redPoint,
+ const QPointF &greenPoint, const QPointF &bluePoint);
+
bool isValid() const noexcept;
friend Q_GUI_EXPORT bool operator==(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2);
@@ -110,11 +120,9 @@ public:
QColorTransform transformationToColorSpace(const QColorSpace &colorspace) const;
- QColorSpacePrivate *d_func();
- inline const QColorSpacePrivate *d_func() const { return d_ptr.constData(); }
private:
- friend class QColorSpacePrivate;
+ Q_DECLARE_PRIVATE(QColorSpace)
QExplicitlySharedDataPointer<QColorSpacePrivate> d_ptr;
};
@@ -124,6 +132,8 @@ inline bool operator!=(const QColorSpace &colorSpace1, const QColorSpace &colorS
return !(colorSpace1 == colorSpace2);
}
+Q_DECLARE_SHARED(QColorSpace)
+
// QColorSpace stream functions
#if !defined(QT_NO_DATASTREAM)
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QColorSpace &);
diff --git a/src/gui/painting/qcolorspace_p.h b/src/gui/painting/qcolorspace_p.h
index 95e0655d0c..2a40a0cfd8 100644
--- a/src/gui/painting/qcolorspace_p.h
+++ b/src/gui/painting/qcolorspace_p.h
@@ -66,7 +66,7 @@ class Q_GUI_EXPORT QColorSpacePrimaries
{
public:
QColorSpacePrimaries() = default;
- QColorSpacePrimaries(QColorSpace::Gamut gamut);
+ QColorSpacePrimaries(QColorSpace::Primaries primaries);
QColorSpacePrimaries(QPointF whitePoint,
QPointF redPoint,
QPointF greenPoint,
@@ -91,10 +91,21 @@ class QColorSpacePrivate : public QSharedData
public:
QColorSpacePrivate();
QColorSpacePrivate(QColorSpace::ColorSpaceId colorSpaceId);
- QColorSpacePrivate(QColorSpace::Gamut gamut, QColorSpace::TransferFunction fun, float gamma);
+ QColorSpacePrivate(QColorSpace::Primaries primaries, QColorSpace::TransferFunction fun, float gamma);
QColorSpacePrivate(const QColorSpacePrimaries &primaries, QColorSpace::TransferFunction fun, float gamma);
QColorSpacePrivate(const QColorSpacePrivate &other) = default;
+ static QColorSpacePrivate *getWritable(QColorSpace &colorSpace)
+ {
+ colorSpace.d_ptr.detach();
+ return colorSpace.d_ptr.data();
+ }
+
+ static const QColorSpacePrivate *get(const QColorSpace &colorSpace)
+ {
+ return colorSpace.d_ptr.data();
+ }
+
void initialize();
void setToXyzMatrix();
void setTransferFunction();
@@ -102,7 +113,7 @@ public:
QColorTransform transformationToColorSpace(const QColorSpacePrivate *out) const;
QColorSpace::ColorSpaceId id;
- QColorSpace::Gamut gamut;
+ QColorSpace::Primaries primaries;
QColorSpace::TransferFunction transferFunction;
float gamma;
QColorVector whitePoint;
diff --git a/src/gui/painting/qcolortransform.cpp b/src/gui/painting/qcolortransform.cpp
index de08bf4221..53fd1dfbaa 100644
--- a/src/gui/painting/qcolortransform.cpp
+++ b/src/gui/painting/qcolortransform.cpp
@@ -134,8 +134,18 @@ void QColorTransformPrivate::updateLutsOut() const
*/
-QColorTransform::~QColorTransform() noexcept
+QColorTransform::QColorTransform(const QColorTransform &colorTransform) noexcept
+ : d(colorTransform.d)
{
+ if (d)
+ d->ref.ref();
+}
+
+
+QColorTransform::~QColorTransform()
+{
+ if (d && !d->ref.deref())
+ delete d;
}
/*!
@@ -143,11 +153,10 @@ QColorTransform::~QColorTransform() noexcept
The input should be opaque or unpremultiplied.
*/
-QRgb QColorTransform::map(const QRgb &argb) const
+QRgb QColorTransform::map(QRgb argb) const
{
- if (!d_ptr)
+ if (!d)
return argb;
- Q_D(const QColorTransform);
constexpr float f = 1.0f / 255.0f;
QColorVector c = { qRed(argb) * f, qGreen(argb) * f, qBlue(argb) * f };
c.x = d->colorSpaceIn->trc[0].apply(c.x);
@@ -175,11 +184,10 @@ QRgb QColorTransform::map(const QRgb &argb) const
The input should be opaque or unpremultiplied.
*/
-QRgba64 QColorTransform::map(const QRgba64 &rgba64) const
+QRgba64 QColorTransform::map(QRgba64 rgba64) const
{
- if (!d_ptr)
+ if (!d)
return rgba64;
- Q_D(const QColorTransform);
constexpr float f = 1.0f / 65535.0f;
QColorVector c = { rgba64.red() * f, rgba64.green() * f, rgba64.blue() * f };
c.x = d->colorSpaceIn->trc[0].apply(c.x);
@@ -208,9 +216,8 @@ QRgba64 QColorTransform::map(const QRgba64 &rgba64) const
*/
QColor QColorTransform::map(const QColor &color) const
{
- if (!d_ptr)
+ if (!d)
return color;
- Q_D(const QColorTransform);
QColor clr = color;
if (color.spec() != QColor::ExtendedRgb || color.spec() != QColor::Rgb)
clr = clr.toRgb();
@@ -228,7 +235,7 @@ QColor QColorTransform::map(const QColor &color) const
c = d->colorMatrix.map(c);
bool inGamut = c.x >= 0.0f && c.x <= 1.0f && c.y >= 0.0f && c.y <= 1.0f && c.z >= 0.0f && c.z <= 1.0f;
if (inGamut) {
- if (d_ptr->colorSpaceOut->lut.generated.loadAcquire()) {
+ if (d->colorSpaceOut->lut.generated.loadAcquire()) {
c.x = d->colorSpaceOut->lut[0]->fromLinear(c.x);
c.y = d->colorSpaceOut->lut[1]->fromLinear(c.y);
c.z = d->colorSpaceOut->lut[2]->fromLinear(c.z);
diff --git a/src/gui/painting/qcolortransform.h b/src/gui/painting/qcolortransform.h
index 9274387b97..5fb51739a7 100644
--- a/src/gui/painting/qcolortransform.h
+++ b/src/gui/painting/qcolortransform.h
@@ -51,43 +51,42 @@ class QRgba64;
class QColorSpacePrivate;
class QColorTransformPrivate;
-class Q_GUI_EXPORT QColorTransform
+class QColorTransform
{
public:
- QColorTransform() noexcept : d_ptr(nullptr) { }
- ~QColorTransform() noexcept;
- QColorTransform(const QColorTransform &colorTransform) noexcept
- : d_ptr(colorTransform.d_ptr)
- { }
+ QColorTransform() noexcept : d(nullptr) { }
+ Q_GUI_EXPORT ~QColorTransform();
+ Q_GUI_EXPORT QColorTransform(const QColorTransform &colorTransform) noexcept;
QColorTransform(QColorTransform &&colorTransform) noexcept
- : d_ptr(std::move(colorTransform.d_ptr))
+ : d{qExchange(colorTransform.d, nullptr)}
{ }
QColorTransform &operator=(const QColorTransform &other) noexcept
{
- d_ptr = other.d_ptr;
+ QColorTransform{other}.swap(*this);
return *this;
}
QColorTransform &operator=(QColorTransform &&other) noexcept
{
- d_ptr = std::move(other.d_ptr);
+ QColorTransform{std::move(other)}.swap(*this);
return *this;
}
- bool isNull() const { return d_ptr.isNull(); }
+ void swap(QColorTransform &other) noexcept { qSwap(d, other.d); }
- QRgb map(const QRgb &argb) const;
- QRgba64 map(const QRgba64 &rgba64) const;
- QColor map(const QColor &color) const;
+ Q_GUI_EXPORT QRgb map(QRgb argb) const;
+ Q_GUI_EXPORT QRgba64 map(QRgba64 rgba64) const;
+ Q_GUI_EXPORT QColor map(const QColor &color) const;
private:
friend class QColorSpace;
friend class QColorSpacePrivate;
friend class QImage;
- Q_DECLARE_PRIVATE(QColorTransform)
- QSharedPointer<QColorTransformPrivate> d_ptr;
+ const QColorTransformPrivate *d;
};
+Q_DECLARE_SHARED(QColorTransform)
+
QT_END_NAMESPACE
#endif // QCOLORTRANSFORM_H
diff --git a/src/gui/painting/qcolortransform_p.h b/src/gui/painting/qcolortransform_p.h
index 74a1e7fe0a..5d7116248d 100644
--- a/src/gui/painting/qcolortransform_p.h
+++ b/src/gui/painting/qcolortransform_p.h
@@ -54,9 +54,11 @@
#include "qcolormatrix_p.h"
#include "qcolorspace_p.h"
+#include <QtCore/qshareddata.h>
+
QT_BEGIN_NAMESPACE
-class QColorTransformPrivate
+class QColorTransformPrivate : public QSharedData
{
public:
QColorMatrix colorMatrix;
diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp
index 006befea22..674f52678d 100644
--- a/src/gui/painting/qdrawhelper.cpp
+++ b/src/gui/painting/qdrawhelper.cpp
@@ -2053,6 +2053,23 @@ inline void fetchTransformed_pixelBounds(int max, int l1, int l2, int &v)
}
}
+static inline bool canUseFastMatrixPath(const qreal cx, const qreal cy, const qsizetype length, const QSpanData *data)
+{
+ if (Q_UNLIKELY(!data->fast_matrix))
+ return false;
+
+ qreal fx = (data->m21 * cy + data->m11 * cx + data->dx) * fixed_scale;
+ qreal fy = (data->m22 * cy + data->m12 * cx + data->dy) * fixed_scale;
+ qreal minc = std::min(fx, fy);
+ qreal maxc = std::max(fx, fy);
+ fx += std::trunc(data->m11 * fixed_scale) * length;
+ fy += std::trunc(data->m12 * fixed_scale) * length;
+ minc = std::min(minc, std::min(fx, fy));
+ maxc = std::max(maxc, std::max(fx, fy));
+
+ return minc >= std::numeric_limits<int>::min() && maxc <= std::numeric_limits<int>::max();
+}
+
template<TextureBlendType blendType, QPixelLayout::BPP bpp, typename T>
static void QT_FASTCALL fetchTransformed_fetcher(T *buffer, const QSpanData *data,
int y, int x, int length)
@@ -2070,7 +2087,7 @@ static void QT_FASTCALL fetchTransformed_fetcher(T *buffer, const QSpanData *dat
// When templated 'fetch' should be inlined at compile time:
const FetchPixelFunc fetch = (bpp == QPixelLayout::BPPNone) ? qFetchPixel[layout->bpp] : FetchPixelFunc(fetchPixel<bpp>);
- if (data->fast_matrix) {
+ if (canUseFastMatrixPath(cx, cy, length, data)) {
// The increment pr x in the scanline
int fdx = (int)(data->m11 * fixed_scale);
int fdy = (int)(data->m12 * fixed_scale);
@@ -3026,7 +3043,7 @@ static const uint * QT_FASTCALL fetchTransformedBilinearARGB32PM(uint *buffer, c
uint *end = buffer + length;
uint *b = buffer;
- if (data->fast_matrix) {
+ if (canUseFastMatrixPath(cx, cy, length, data)) {
// The increment pr x in the scanline
int fdx = (int)(data->m11 * fixed_scale);
int fdy = (int)(data->m12 * fixed_scale);
@@ -3383,7 +3400,7 @@ static const uint *QT_FASTCALL fetchTransformedBilinear(uint *buffer, const Oper
const qreal cx = x + qreal(0.5);
const qreal cy = y + qreal(0.5);
- if (data->fast_matrix) {
+ if (canUseFastMatrixPath(cx, cy, length, data)) {
// The increment pr x in the scanline
int fdx = (int)(data->m11 * fixed_scale);
int fdy = (int)(data->m12 * fixed_scale);
@@ -3570,7 +3587,7 @@ static const QRgba64 *QT_FASTCALL fetchTransformedBilinear64_uint32(QRgba64 *buf
QRgba64 *end = buffer + length;
QRgba64 *b = buffer;
- if (data->fast_matrix) {
+ if (canUseFastMatrixPath(cx, cy, length, data)) {
// The increment pr x in the scanline
const int fdx = (int)(data->m11 * fixed_scale);
const int fdy = (int)(data->m12 * fixed_scale);
@@ -3728,7 +3745,7 @@ static const QRgba64 *QT_FASTCALL fetchTransformedBilinear64_uint64(QRgba64 *buf
QRgba64 *end = buffer + length;
QRgba64 *b = buffer;
- if (data->fast_matrix) {
+ if (canUseFastMatrixPath(cx, cy, length, data)) {
// The increment pr x in the scanline
const int fdx = (int)(data->m11 * fixed_scale);
const int fdy = (int)(data->m12 * fixed_scale);
diff --git a/src/gui/painting/qicc.cpp b/src/gui/painting/qicc.cpp
index d88b005782..6cb7b57493 100644
--- a/src/gui/painting/qicc.cpp
+++ b/src/gui/painting/qicc.cpp
@@ -42,8 +42,9 @@
#include <qbuffer.h>
#include <qbytearray.h>
#include <qdatastream.h>
-#include <qloggingcategory.h>
#include <qendian.h>
+#include <qloggingcategory.h>
+#include <qstring.h>
#include "qcolorspace_p.h"
#include "qcolortrc_p.h"
@@ -117,6 +118,7 @@ enum class Tag : quint32 {
bkpt = IccTag('b', 'k', 'p', 't'),
mft1 = IccTag('m', 'f', 't', '1'),
mft2 = IccTag('m', 'f', 't', '2'),
+ mluc = IccTag('m', 'l', 'u', 'c'),
mAB_ = IccTag('m', 'A', 'B', ' '),
mBA_ = IccTag('m', 'B', 'A', ' '),
chad = IccTag('c', 'h', 'a', 'd'),
@@ -164,6 +166,25 @@ struct ParaTagData : GenericTagData {
quint32_be parameter[1];
};
+struct DescTagData : GenericTagData {
+ quint32_be asciiDescriptionLength;
+ char asciiDescription[1];
+ // .. we ignore the rest
+};
+
+struct MlucTagRecord {
+ quint16_be languageCode;
+ quint16_be countryCode;
+ quint32_be size;
+ quint32_be offset;
+};
+
+struct MlucTagData : GenericTagData {
+ quint32_be recordCount;
+ quint32_be recordSize; // = sizeof(MlucTagRecord)
+ MlucTagRecord records[1];
+};
+
// For both mAB and mBA
struct mABTagData : GenericTagData {
quint8 inputChannels;
@@ -190,23 +211,17 @@ static float fromFixedS1516(int x)
return x * (1.0f / 65536.0f);
}
-QColorVector fromXyzData(const XYZTagData *xyz)
-{
- const float x = fromFixedS1516(xyz->fixedX);
- const float y = fromFixedS1516(xyz->fixedY);
- const float z = fromFixedS1516(xyz->fixedZ);
- qCDebug(lcIcc) << "XYZ_ " << x << y << z;
-
- return QColorVector(x, y, z);
-}
-
static bool isValidIccProfile(const ICCProfileHeader &header)
{
if (header.signature != uint(Tag::acsp)) {
qCWarning(lcIcc, "Failed ICC signature test");
return false;
}
- if (header.profileSize < (sizeof(ICCProfileHeader) + header.tagCount * sizeof(TagTableEntry))) {
+
+ // Don't overflow 32bit integers:
+ if (header.tagCount >= INT32_MAX / sizeof(TagTableEntry))
+ return false;
+ if (header.profileSize - sizeof(ICCProfileHeader) < header.tagCount * sizeof(TagTableEntry)) {
qCWarning(lcIcc, "Failed basic size sanity");
return false;
}
@@ -288,7 +303,7 @@ QByteArray toIccProfile(const QColorSpace &space)
if (!space.isValid())
return QByteArray();
- const QColorSpacePrivate *spaceDPtr = space.d_func();
+ const QColorSpacePrivate *spaceDPtr = QColorSpacePrivate::get(space);
constexpr int tagCount = 9;
constexpr uint profileDataOffset = 128 + 4 + 12 * tagCount;
@@ -413,17 +428,44 @@ QByteArray toIccProfile(const QColorSpace &space)
return iccProfile;
}
-bool parseTRC(const GenericTagData *trcData, QColorTrc &gamma)
+struct TagEntry {
+ quint32 offset;
+ quint32 size;
+};
+
+bool parseXyzData(const QByteArray &data, const TagEntry &tagEntry, QColorVector &colorVector)
+{
+ if (tagEntry.size < sizeof(XYZTagData)) {
+ qCWarning(lcIcc) << "Undersized XYZ tag";
+ return false;
+ }
+ const XYZTagData *xyz = reinterpret_cast<const XYZTagData *>(data.constData() + tagEntry.offset);
+ if (xyz->type != quint32(Tag::XYZ_)) {
+ qCWarning(lcIcc) << "Bad XYZ content type";
+ return false;
+ }
+ const float x = fromFixedS1516(xyz->fixedX);
+ const float y = fromFixedS1516(xyz->fixedY);
+ const float z = fromFixedS1516(xyz->fixedZ);
+
+ colorVector = QColorVector(x, y, z);
+ return true;
+}
+
+bool parseTRC(const QByteArray &data, const TagEntry &tagEntry, QColorTrc &gamma)
{
+ const GenericTagData *trcData = reinterpret_cast<const GenericTagData *>(data.constData() + tagEntry.offset);
if (trcData->type == quint32(Tag::curv)) {
- const CurvTagData *curv = reinterpret_cast<const CurvTagData *>(trcData);
- qCDebug(lcIcc) << "curv" << uint(curv->valueCount);
+ const CurvTagData *curv = static_cast<const CurvTagData *>(trcData);
+ if (curv->valueCount > (1 << 16))
+ return false;
+ if (tagEntry.size - 12 < 2 * curv->valueCount)
+ return false;
if (curv->valueCount == 0) {
gamma.m_type = QColorTrc::Type::Function;
gamma.m_fun = QColorTransferFunction(); // Linear
} else if (curv->valueCount == 1) {
float g = curv->value[0] * (1.0f / 256.0f);
- qCDebug(lcIcc) << g;
gamma.m_type = QColorTrc::Type::Function;
gamma.m_fun = QColorTransferFunction::fromGamma(g);
} else {
@@ -445,49 +487,54 @@ bool parseTRC(const GenericTagData *trcData, QColorTrc &gamma)
return true;
}
if (trcData->type == quint32(Tag::para)) {
- const ParaTagData *para = reinterpret_cast<const ParaTagData *>(trcData);
- qCDebug(lcIcc) << "para" << uint(para->curveType);
+ if (tagEntry.size < sizeof(ParaTagData))
+ return false;
+ const ParaTagData *para = static_cast<const ParaTagData *>(trcData);
switch (para->curveType) {
case 0: {
float g = fromFixedS1516(para->parameter[0]);
- qCDebug(lcIcc) << g;
gamma.m_type = QColorTrc::Type::Function;
gamma.m_fun = QColorTransferFunction::fromGamma(g);
break;
}
case 1: {
+ if (tagEntry.size < sizeof(ParaTagData) + 2 * 4)
+ return false;
float g = fromFixedS1516(para->parameter[0]);
float a = fromFixedS1516(para->parameter[1]);
float b = fromFixedS1516(para->parameter[2]);
float d = -b / a;
- qCDebug(lcIcc) << g << a << b;
gamma.m_type = QColorTrc::Type::Function;
gamma.m_fun = QColorTransferFunction(a, b, 0.0f, d, 0.0f, 0.0f, g);
break;
}
case 2: {
+ if (tagEntry.size < sizeof(ParaTagData) + 3 * 4)
+ return false;
float g = fromFixedS1516(para->parameter[0]);
float a = fromFixedS1516(para->parameter[1]);
float b = fromFixedS1516(para->parameter[2]);
float c = fromFixedS1516(para->parameter[3]);
float d = -b / a;
- qCDebug(lcIcc) << g << a << b << c;
gamma.m_type = QColorTrc::Type::Function;
gamma.m_fun = QColorTransferFunction(a, b, 0.0f, d, c, c, g);
break;
}
case 3: {
+ if (tagEntry.size < sizeof(ParaTagData) + 4 * 4)
+ return false;
float g = fromFixedS1516(para->parameter[0]);
float a = fromFixedS1516(para->parameter[1]);
float b = fromFixedS1516(para->parameter[2]);
float c = fromFixedS1516(para->parameter[3]);
float d = fromFixedS1516(para->parameter[4]);
- qCDebug(lcIcc) << g << a << b << c << d;
gamma.m_type = QColorTrc::Type::Function;
gamma.m_fun = QColorTransferFunction(a, b, c, d, 0.0f, 0.0f, g);
break;
}
case 4: {
+ if (tagEntry.size < sizeof(ParaTagData) + 6 * 4)
+ return false;
float g = fromFixedS1516(para->parameter[0]);
float a = fromFixedS1516(para->parameter[1]);
float b = fromFixedS1516(para->parameter[2]);
@@ -495,7 +542,6 @@ bool parseTRC(const GenericTagData *trcData, QColorTrc &gamma)
float d = fromFixedS1516(para->parameter[4]);
float e = fromFixedS1516(para->parameter[5]);
float f = fromFixedS1516(para->parameter[6]);
- qCDebug(lcIcc) << g << a << b << c << d << e << f;
gamma.m_type = QColorTrc::Type::Function;
gamma.m_fun = QColorTransferFunction(a, b, c, d, e, f, g);
break;
@@ -510,6 +556,53 @@ bool parseTRC(const GenericTagData *trcData, QColorTrc &gamma)
return false;
}
+bool parseDesc(const QByteArray &data, const TagEntry &tagEntry, QString &descName)
+{
+ const GenericTagData *tag = (const GenericTagData *)(data.constData() + tagEntry.offset);
+
+ // Either 'desc' (ICCv2) or 'mluc' (ICCv4)
+ if (tag->type == quint32(Tag::desc)) {
+ if (tagEntry.size < sizeof(DescTagData))
+ return false;
+ const DescTagData *desc = (const DescTagData *)(data.constData() + tagEntry.offset);
+ const quint32 len = desc->asciiDescriptionLength;
+ if (len < 1)
+ return false;
+ if (tagEntry.size - 12 < len)
+ return false;
+ if (desc->asciiDescription[len - 1] != '\0')
+ return false;
+ descName = QString::fromLatin1(desc->asciiDescription, len - 1);
+ return true;
+ }
+ if (tag->type != quint32(Tag::mluc))
+ return false;
+
+ if (tagEntry.size < sizeof(MlucTagData))
+ return false;
+ const MlucTagData *mluc = (const MlucTagData *)(data.constData() + tagEntry.offset);
+ if (mluc->recordCount < 1)
+ return false;
+ if (mluc->recordSize < 12)
+ return false;
+ // We just use the primary record regardless of language or country.
+ const quint32 stringOffset = mluc->records[0].offset;
+ const quint32 stringSize = mluc->records[0].size;
+ if (tagEntry.size < stringOffset || tagEntry.size - stringOffset < stringSize )
+ return false;
+ if ((stringSize | stringOffset) & 1)
+ return false;
+ quint32 stringLen = stringSize / 2;
+ const ushort *unicodeString = (const ushort *)(data.constData() + tagEntry.offset + stringOffset);
+ // The given length shouldn't include 0-termination, but might.
+ if (stringLen > 1 && unicodeString[stringLen - 1] == 0)
+ --stringLen;
+ QVarLengthArray<quint16> utf16hostendian(stringLen);
+ qFromBigEndian<ushort>(unicodeString, stringLen, utf16hostendian.data());
+ descName = QString::fromUtf16(utf16hostendian.data(), stringLen);
+ return true;
+}
+
bool fromIccProfile(const QByteArray &data, QColorSpace *colorSpace)
{
if (data.size() < qsizetype(sizeof(ICCProfileHeader))) {
@@ -529,8 +622,12 @@ bool fromIccProfile(const QByteArray &data, QColorSpace *colorSpace)
// Read tag index
const TagTableEntry *tagTable = (const TagTableEntry *)(data.constData() + sizeof(ICCProfileHeader));
const qsizetype offsetToData = sizeof(ICCProfileHeader) + header->tagCount * sizeof(TagTableEntry);
+ if (offsetToData > data.size()) {
+ qCWarning(lcIcc) << "fromIccProfile: failed index size sanity";
+ return false;
+ }
- QHash<Tag, quint32> tagIndex;
+ QHash<Tag, TagEntry> tagIndex;
for (uint i = 0; i < header->tagCount; ++i) {
// Sanity check tag sizes and offsets:
if (qsizetype(tagTable[i].offset) < offsetToData) {
@@ -542,15 +639,24 @@ bool fromIccProfile(const QByteArray &data, QColorSpace *colorSpace)
qCWarning(lcIcc) << "fromIccProfile: failed tag offset sanity 2";
return false;
}
- if ((tagTable[i].offset + tagTable[i].size) > header->profileSize) {
+ if (tagTable[i].size < 12) {
+ qCWarning(lcIcc) << "fromIccProfile: failed minimal tag size sanity";
+ return false;
+ }
+ if (tagTable[i].size > header->profileSize - tagTable[i].offset) {
qCWarning(lcIcc) << "fromIccProfile: failed tag offset + size sanity";
return false;
}
+ if (tagTable[i].offset & 0x03) {
+ qCWarning(lcIcc) << "fromIccProfile: invalid tag offset alignment";
+ return false;
+ }
// printf("'%4s' %d %d\n", (const char *)&tagTable[i].signature,
// quint32(tagTable[i].offset),
// quint32(tagTable[i].size));
- tagIndex.insert(Tag(quint32(tagTable[i].signature)), tagTable[i].offset);
+ tagIndex.insert(Tag(quint32(tagTable[i].signature)), { tagTable[i].offset, tagTable[i].size });
}
+
// Check the profile is three-component matrix based (what we currently support):
if (!tagIndex.contains(Tag::rXYZ) || !tagIndex.contains(Tag::gXYZ) || !tagIndex.contains(Tag::bXYZ) ||
!tagIndex.contains(Tag::rTRC) || !tagIndex.contains(Tag::gTRC) || !tagIndex.contains(Tag::bTRC) ||
@@ -559,70 +665,70 @@ bool fromIccProfile(const QByteArray &data, QColorSpace *colorSpace)
return false;
}
+ QColorSpacePrivate *colorspaceDPtr = QColorSpacePrivate::getWritable(*colorSpace);
+
// Parse XYZ tags
- const XYZTagData *rXyz = (const XYZTagData *)(data.constData() + tagIndex[Tag::rXYZ]);
- const XYZTagData *gXyz = (const XYZTagData *)(data.constData() + tagIndex[Tag::gXYZ]);
- const XYZTagData *bXyz = (const XYZTagData *)(data.constData() + tagIndex[Tag::bXYZ]);
- const XYZTagData *wXyz = (const XYZTagData *)(data.constData() + tagIndex[Tag::wtpt]);
- if (rXyz->type != quint32(Tag::XYZ_) || gXyz->type != quint32(Tag::XYZ_) ||
- wXyz->type != quint32(Tag::XYZ_) || wXyz->type != quint32(Tag::XYZ_)) {
- qCWarning(lcIcc) << "fromIccProfile: Bad XYZ data type";
+ if (!parseXyzData(data, tagIndex[Tag::rXYZ], colorspaceDPtr->toXyz.r))
+ return false;
+ if (!parseXyzData(data, tagIndex[Tag::gXYZ], colorspaceDPtr->toXyz.g))
+ return false;
+ if (!parseXyzData(data, tagIndex[Tag::bXYZ], colorspaceDPtr->toXyz.b))
+ return false;
+ if (!parseXyzData(data, tagIndex[Tag::wtpt], colorspaceDPtr->whitePoint))
return false;
- }
- QColorSpacePrivate *colorspaceDPtr = colorSpace->d_func();
-
- colorspaceDPtr->toXyz.r = fromXyzData(rXyz);
- colorspaceDPtr->toXyz.g = fromXyzData(gXyz);
- colorspaceDPtr->toXyz.b = fromXyzData(bXyz);
- QColorVector whitePoint = fromXyzData(wXyz);
- colorspaceDPtr->whitePoint = whitePoint;
- colorspaceDPtr->gamut = QColorSpace::Gamut::Custom;
+ colorspaceDPtr->primaries = QColorSpace::Primaries::Custom;
if (colorspaceDPtr->toXyz == QColorMatrix::toXyzFromSRgb()) {
- qCDebug(lcIcc) << "fromIccProfile: sRGB gamut detected";
- colorspaceDPtr->gamut = QColorSpace::Gamut::SRgb;
+ qCDebug(lcIcc) << "fromIccProfile: sRGB primaries detected";
+ colorspaceDPtr->primaries = QColorSpace::Primaries::SRgb;
} else if (colorspaceDPtr->toXyz == QColorMatrix::toXyzFromAdobeRgb()) {
- qCDebug(lcIcc) << "fromIccProfile: Adobe RGB gamut detected";
- colorspaceDPtr->gamut = QColorSpace::Gamut::AdobeRgb;
+ qCDebug(lcIcc) << "fromIccProfile: Adobe RGB primaries detected";
+ colorspaceDPtr->primaries = QColorSpace::Primaries::AdobeRgb;
} else if (colorspaceDPtr->toXyz == QColorMatrix::toXyzFromDciP3D65()) {
- qCDebug(lcIcc) << "fromIccProfile: DCI-P3 D65 gamut detected";
- colorspaceDPtr->gamut = QColorSpace::Gamut::DciP3D65;
+ qCDebug(lcIcc) << "fromIccProfile: DCI-P3 D65 primaries detected";
+ colorspaceDPtr->primaries = QColorSpace::Primaries::DciP3D65;
} else if (colorspaceDPtr->toXyz == QColorMatrix::toXyzFromBt2020()) {
- qCDebug(lcIcc) << "fromIccProfile: BT.2020 gamut detected";
- colorspaceDPtr->gamut = QColorSpace::Gamut::Bt2020;
+ qCDebug(lcIcc) << "fromIccProfile: BT.2020 primaries detected";
+ colorspaceDPtr->primaries = QColorSpace::Primaries::Bt2020;
}
if (colorspaceDPtr->toXyz == QColorMatrix::toXyzFromProPhotoRgb()) {
- qCDebug(lcIcc) << "fromIccProfile: ProPhoto RGB gamut detected";
- colorspaceDPtr->gamut = QColorSpace::Gamut::ProPhotoRgb;
+ qCDebug(lcIcc) << "fromIccProfile: ProPhoto RGB primaries detected";
+ colorspaceDPtr->primaries = QColorSpace::Primaries::ProPhotoRgb;
}
// Reset the matrix to our canonical values:
- if (colorspaceDPtr->gamut != QColorSpace::Gamut::Custom)
+ if (colorspaceDPtr->primaries != QColorSpace::Primaries::Custom)
colorspaceDPtr->setToXyzMatrix();
// Parse TRC tags
- const GenericTagData *rTrc;
- const GenericTagData *gTrc;
- const GenericTagData *bTrc;
+ TagEntry rTrc;
+ TagEntry gTrc;
+ TagEntry bTrc;
if (tagIndex.contains(Tag::aarg) && tagIndex.contains(Tag::aagg) && tagIndex.contains(Tag::aabg)) {
// Apple extension for parametric version of TRCs in ICCv2:
- rTrc = (const GenericTagData *)(data.constData() + tagIndex[Tag::aarg]);
- gTrc = (const GenericTagData *)(data.constData() + tagIndex[Tag::aagg]);
- bTrc = (const GenericTagData *)(data.constData() + tagIndex[Tag::aabg]);
+ rTrc = tagIndex[Tag::aarg];
+ gTrc = tagIndex[Tag::aagg];
+ bTrc = tagIndex[Tag::aabg];
} else {
- rTrc = (const GenericTagData *)(data.constData() + tagIndex[Tag::rTRC]);
- gTrc = (const GenericTagData *)(data.constData() + tagIndex[Tag::gTRC]);
- bTrc = (const GenericTagData *)(data.constData() + tagIndex[Tag::bTRC]);
+ rTrc = tagIndex[Tag::rTRC];
+ gTrc = tagIndex[Tag::gTRC];
+ bTrc = tagIndex[Tag::bTRC];
}
QColorTrc rCurve;
QColorTrc gCurve;
QColorTrc bCurve;
- if (!parseTRC(rTrc, rCurve))
+ if (!parseTRC(data, rTrc, rCurve)) {
+ qCWarning(lcIcc) << "fromIccProfile: Invalid rTRC";
return false;
- if (!parseTRC(gTrc, gCurve))
+ }
+ if (!parseTRC(data, gTrc, gCurve)) {
+ qCWarning(lcIcc) << "fromIccProfile: Invalid gTRC";
return false;
- if (!parseTRC(bTrc, bCurve))
+ }
+ if (!parseTRC(data, bTrc, bCurve)) {
+ qCWarning(lcIcc) << "fromIccProfile: Invalid bTRC";
return false;
+ }
if (rCurve == gCurve && gCurve == bCurve && rCurve.m_type == QColorTrc::Type::Function) {
if (rCurve.m_fun.isLinear()) {
qCDebug(lcIcc) << "fromIccProfile: Linear gamma detected";
@@ -652,7 +758,12 @@ bool fromIccProfile(const QByteArray &data, QColorSpace *colorSpace)
colorspaceDPtr->transferFunction = QColorSpace::TransferFunction::Custom;
}
- // FIXME: try to parse the description..
+ if (tagIndex.contains(Tag::desc)) {
+ if (!parseDesc(data, tagIndex[Tag::desc], colorspaceDPtr->description))
+ qCWarning(lcIcc) << "fromIccProfile: Failed to parse description";
+ else
+ qCDebug(lcIcc) << "fromIccProfile: Description" << colorspaceDPtr->description;
+ }
if (!colorspaceDPtr->identifyColorSpace())
colorspaceDPtr->id = QColorSpace::Unknown;
diff --git a/src/gui/painting/qpagedpaintdevice.cpp b/src/gui/painting/qpagedpaintdevice.cpp
index 72b2834470..3fdd0206b7 100644
--- a/src/gui/painting/qpagedpaintdevice.cpp
+++ b/src/gui/painting/qpagedpaintdevice.cpp
@@ -42,6 +42,7 @@
QT_BEGIN_NAMESPACE
+// ### Qt 6: remove when the deprecated constructor is removed
class QDummyPagedPaintDevicePrivate : public QPagedPaintDevicePrivate
{
bool setPageLayout(const QPageLayout &newPageLayout) override
@@ -85,7 +86,7 @@ QPagedPaintDevicePrivate::~QPagedPaintDevicePrivate()
\class QPagedPaintDevice
\inmodule QtGui
- \brief The QPagedPaintDevice class is a represents a paintdevice that supports
+ \brief The QPagedPaintDevice class represents a paint device that supports
multiple pages.
\ingroup painting
diff --git a/src/gui/painting/qpagedpaintdevice.h b/src/gui/painting/qpagedpaintdevice.h
index 1c37c17fa3..21e23e0eb4 100644
--- a/src/gui/painting/qpagedpaintdevice.h
+++ b/src/gui/painting/qpagedpaintdevice.h
@@ -213,6 +213,7 @@ public:
Envelope10 = Comm10E
};
+ // keep in sync with QPdfEngine::PdfVersion!
enum PdfVersion { PdfVersion_1_4, PdfVersion_A1b, PdfVersion_1_6 };
// ### Qt6 Make these virtual
diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp
index 461ad51200..0a440e5b75 100644
--- a/src/gui/painting/qpaintengine_raster.cpp
+++ b/src/gui/painting/qpaintengine_raster.cpp
@@ -2902,9 +2902,9 @@ bool QRasterPaintEngine::drawCachedGlyphs(int numGlyphs, const glyph_t *glyphs,
QFontEngine::GlyphFormat glyphFormat = fontEngine->glyphFormat != QFontEngine::Format_None ? fontEngine->glyphFormat : d->glyphCacheFormat;
QImageTextureGlyphCache *cache =
- static_cast<QImageTextureGlyphCache *>(fontEngine->glyphCache(0, glyphFormat, s->matrix));
+ static_cast<QImageTextureGlyphCache *>(fontEngine->glyphCache(0, glyphFormat, s->matrix, QColor(s->penData.solidColor)));
if (!cache) {
- cache = new QImageTextureGlyphCache(glyphFormat, s->matrix);
+ cache = new QImageTextureGlyphCache(glyphFormat, s->matrix, QColor(s->penData.solidColor));
fontEngine->setGlyphCache(0, cache);
}
@@ -4295,7 +4295,7 @@ protected:
QSharedPointer<const CacheInfo> addCacheElement(quint64 hash_val, const QGradient &gradient, int opacity) {
if (cache.size() == maxCacheSize()) {
// may remove more than 1, but OK
- cache.erase(cache.begin() + QRandomGenerator::global()->bounded(maxCacheSize()));
+ cache.erase(std::next(cache.begin(), QRandomGenerator::global()->bounded(maxCacheSize())));
}
auto cache_entry = QSharedPointer<CacheInfo>::create(gradient.stops(), opacity, gradient.interpolationMode());
generateGradientColorTable(gradient, cache_entry->buffer64, paletteSize(), opacity);
diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp
index 8801e66b0f..b1d1f30800 100644
--- a/src/gui/painting/qpainterpath.cpp
+++ b/src/gui/painting/qpainterpath.cpp
@@ -661,6 +661,7 @@ void QPainterPath::clear()
detach();
d_func()->clear();
+ d_func()->elements.append( {0, 0, MoveToElement} );
}
/*!
@@ -2337,12 +2338,12 @@ bool QPainterPath::operator==(const QPainterPath &path) const
{
QPainterPathData *d = reinterpret_cast<QPainterPathData *>(d_func());
QPainterPathData *other_d = path.d_func();
- if (other_d == d)
+ if (other_d == d) {
return true;
- else if (!d || !other_d) {
- if (!d && other_d->elements.empty() && other_d->fillRule == Qt::OddEvenFill)
+ } else if (!d || !other_d) {
+ if (!other_d && isEmpty() && elementAt(0) == QPointF() && d->fillRule == Qt::OddEvenFill)
return true;
- if (!other_d && d && d->elements.empty() && d->fillRule == Qt::OddEvenFill)
+ if (!d && path.isEmpty() && path.elementAt(0) == QPointF() && other_d->fillRule == Qt::OddEvenFill)
return true;
return false;
}
diff --git a/src/gui/painting/qpainterpath_p.h b/src/gui/painting/qpainterpath_p.h
index 22bdbde2a9..a420e0b3d9 100644
--- a/src/gui/painting/qpainterpath_p.h
+++ b/src/gui/painting/qpainterpath_p.h
@@ -313,7 +313,7 @@ inline void QPainterPathData::clear()
elements.clear();
cStart = 0;
-
+ fillRule = Qt::OddEvenFill;
bounds = {};
controlBounds = {};
diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp
index 25d488961c..f560e1f0f0 100644
--- a/src/gui/painting/qpdf.cpp
+++ b/src/gui/painting/qpdf.cpp
@@ -1570,12 +1570,14 @@ void QPdfEnginePrivate::writeHeader()
{
addXrefEntry(0,false);
- static const QHash<QPdfEngine::PdfVersion, const char *> mapping {
- {QPdfEngine::Version_1_4, "1.4"},
- {QPdfEngine::Version_A1b, "1.4"},
- {QPdfEngine::Version_1_6, "1.6"}
+ // Keep in sync with QPdfEngine::PdfVersion!
+ static const char mapping[][4] = {
+ "1.4", // Version_1_4
+ "1.4", // Version_A1b
+ "1.6", // Version_1_6
};
- const char *verStr = mapping.value(pdfVersion, "1.4");
+ static const size_t numMappings = sizeof mapping / sizeof *mapping;
+ const char *verStr = mapping[size_t(pdfVersion) < numMappings ? pdfVersion : 0];
xprintf("%%PDF-%s\n", verStr);
xprintf("%%\303\242\303\243\n");
diff --git a/src/gui/painting/qpdf_p.h b/src/gui/painting/qpdf_p.h
index e337c61f64..89e549614a 100644
--- a/src/gui/painting/qpdf_p.h
+++ b/src/gui/painting/qpdf_p.h
@@ -168,6 +168,7 @@ class Q_GUI_EXPORT QPdfEngine : public QPaintEngine
Q_DECLARE_PRIVATE(QPdfEngine)
friend class QPdfWriter;
public:
+ // keep in sync with QPagedPaintDevice::PdfVersion and QPdfEnginePrivate::writeHeader()::mapping!
enum PdfVersion
{
Version_1_4,
diff --git a/src/gui/painting/qpdfwriter.cpp b/src/gui/painting/qpdfwriter.cpp
index 7f18ce42be..bf7e2d3dca 100644
--- a/src/gui/painting/qpdfwriter.cpp
+++ b/src/gui/painting/qpdfwriter.cpp
@@ -170,17 +170,11 @@ void QPdfWriter::setPdfVersion(PdfVersion version)
{
Q_D(QPdfWriter);
- static const QHash<QPdfWriter::PdfVersion, QPdfEngine::PdfVersion> engineMapping {
- {QPdfWriter::PdfVersion_1_4, QPdfEngine::Version_1_4},
- {QPdfWriter::PdfVersion_A1b, QPdfEngine::Version_A1b},
- {QPdfWriter::PdfVersion_1_6, QPdfEngine::Version_1_6}
- };
-
if (d->pdfVersion == version)
return;
d->pdfVersion = version;
- d->engine->setPdfVersion(engineMapping.value(version, QPdfEngine::Version_1_4));
+ d->engine->setPdfVersion(static_cast<QPdfEngine::PdfVersion>(static_cast<int>(version)));
}
/*!
diff --git a/src/gui/painting/qtextureglyphcache.cpp b/src/gui/painting/qtextureglyphcache.cpp
index e8c47df21c..7a3dd04965 100644
--- a/src/gui/painting/qtextureglyphcache.cpp
+++ b/src/gui/painting/qtextureglyphcache.cpp
@@ -267,7 +267,7 @@ QImage QTextureGlyphCache::textureMapForGlyph(glyph_t g, QFixed subPixelPosition
case QFontEngine::Format_A32:
return m_current_fontengine->alphaRGBMapForGlyph(g, subPixelPosition, m_transform);
case QFontEngine::Format_ARGB:
- return m_current_fontengine->bitmapForGlyph(g, subPixelPosition, m_transform);
+ return m_current_fontengine->bitmapForGlyph(g, subPixelPosition, m_transform, color());
default:
return m_current_fontengine->alphaMapForGlyph(g, subPixelPosition, m_transform);
}
diff --git a/src/gui/painting/qtextureglyphcache_p.h b/src/gui/painting/qtextureglyphcache_p.h
index 1e83ab46d1..b6fc7230a8 100644
--- a/src/gui/painting/qtextureglyphcache_p.h
+++ b/src/gui/painting/qtextureglyphcache_p.h
@@ -74,8 +74,8 @@ class QTextItemInt;
class Q_GUI_EXPORT QTextureGlyphCache : public QFontEngineGlyphCache
{
public:
- QTextureGlyphCache(QFontEngine::GlyphFormat format, const QTransform &matrix)
- : QFontEngineGlyphCache(format, matrix), m_current_fontengine(nullptr),
+ QTextureGlyphCache(QFontEngine::GlyphFormat format, const QTransform &matrix, const QColor &color = QColor())
+ : QFontEngineGlyphCache(format, matrix, color), m_current_fontengine(nullptr),
m_w(0), m_h(0), m_cx(0), m_cy(0), m_currentRowHeight(0)
{ }
@@ -165,8 +165,8 @@ inline uint qHash(const QTextureGlyphCache::GlyphAndSubPixelPosition &g)
class Q_GUI_EXPORT QImageTextureGlyphCache : public QTextureGlyphCache
{
public:
- QImageTextureGlyphCache(QFontEngine::GlyphFormat format, const QTransform &matrix)
- : QTextureGlyphCache(format, matrix) { }
+ QImageTextureGlyphCache(QFontEngine::GlyphFormat format, const QTransform &matrix, const QColor &color = QColor())
+ : QTextureGlyphCache(format, matrix, color) { }
~QImageTextureGlyphCache();
virtual void createTextureData(int width, int height) override;
diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp
index d7c1607e57..7443c0a04f 100644
--- a/src/gui/rhi/qrhi.cpp
+++ b/src/gui/rhi/qrhi.cpp
@@ -36,6 +36,7 @@
#include "qrhi_p_p.h"
#include <qmath.h>
+#include <QLoggingCategory>
#include "qrhinull_p_p.h"
#ifndef QT_NO_OPENGL
@@ -54,6 +55,8 @@
QT_BEGIN_NAMESPACE
+Q_LOGGING_CATEGORY(QRHI_LOG_INFO, "qt.rhi.general")
+
/*!
\class QRhi
\inmodule QtRhi
@@ -260,6 +263,12 @@ QT_BEGIN_NAMESPACE
tied to those concepts, however, and is thus a topic that is currently out
of scope, but may be introduced in the future.
+ \note The Metal backend requires that an autorelease pool is available on
+ the rendering thread, ideally wrapping each iteration of the render loop.
+ This needs no action from the users of QRhi when rendering on the main
+ (gui) thread, but becomes important when a separate, dedicated render
+ thread is used.
+
\section3 Resource synchronization
QRhi does not expose APIs for resource barriers or image layout
@@ -383,6 +392,22 @@ QT_BEGIN_NAMESPACE
texture object is "exported" via QRhi::nativeHandles() or
QRhiTexture::nativeHandles(). Most importantly, passing pointers in structs
and via setters does not transfer ownership.
+
+ \section2 Troubleshooting
+
+ Errors are printed to the output via qWarning(). Additional debug messages
+ can be enabled via the following logging categories. Messages from these
+ categories are not printed by default unless explicitly enabled via
+ QRhi::EnableProfiling or the facilities of QLoggingCategory (such as, the
+ \c QT_LOGGING_RULES environment variable).
+
+ \list
+ \li \c{qt.rhi.general}
+ \endlist
+
+ It is strongly advised to inspect the output with the logging categories
+ (\c{qt.rhi.*}) enabled whenever a QRhi-based application is not behaving as
+ expected.
*/
/*!
@@ -403,7 +428,8 @@ QT_BEGIN_NAMESPACE
\value EnableProfiling Enables gathering timing (CPU, GPU) and resource
(QRhiBuffer, QRhiTexture, etc.) information and additional metadata. See
QRhiProfiler. Avoid enabling in production builds as it may involve a
- performance penalty.
+ performance penalty. Also enables debug messages from the \c{qt.rhi.*}
+ logging categories.
\value EnableDebugMarkers Enables debug marker groups. Without this frame
debugging features like making debug groups and custom resource name
@@ -3867,11 +3893,21 @@ QRhi *QRhi::create(Implementation impl, QRhiInitParams *params, Flags flags, QRh
if (r->d) {
r->d->q = r.data();
+
if (flags.testFlag(EnableProfiling)) {
QRhiProfilerPrivate *profD = QRhiProfilerPrivate::get(&r->d->profiler);
profD->rhiDWhenEnabled = r->d;
+ const_cast<QLoggingCategory &>(QRHI_LOG_INFO()).setEnabled(QtDebugMsg, true);
}
+
+ // Play nice with QSG_INFO since that is still the most commonly used
+ // way to get graphics info printed from Qt Quick apps, and the Quick
+ // scenegraph is our primary user.
+ if (qEnvironmentVariableIsSet("QSG_INFO"))
+ const_cast<QLoggingCategory &>(QRHI_LOG_INFO()).setEnabled(QtDebugMsg, true);
+
r->d->debugMarkers = flags.testFlag(EnableDebugMarkers);
+
if (r->d->create(flags)) {
r->d->implType = impl;
r->d->implThread = QThread::currentThread();
@@ -4911,6 +4947,11 @@ QRhiShaderResourceBindings *QRhi::newShaderResourceBindings()
backends. See \l{QRhiBuffer::UsageFlag}{UsageFlags} and
\l{QRhi::NonDynamicUniformBuffers}{the feature flags}.
+ \note Backends may choose to allocate buffers bigger than \a size. This is
+ done transparently to applications, so there are no special restrictions on
+ the value of \a size. QRhiBuffer::size() will always report back the value
+ that was requested in \a size.
+
\sa QRhiResource::release()
*/
QRhiBuffer *QRhi::newBuffer(QRhiBuffer::Type type,
@@ -5331,4 +5372,32 @@ void QRhiPassResourceTracker::registerTexture(QRhiTexture *tex, TextureAccess *a
m_textures.append(t);
}
+QRhiPassResourceTracker::BufferStage QRhiPassResourceTracker::toPassTrackerBufferStage(QRhiShaderResourceBinding::StageFlags stages)
+{
+ // pick the earlier stage (as this is going to be dstAccessMask)
+ if (stages.testFlag(QRhiShaderResourceBinding::VertexStage))
+ return QRhiPassResourceTracker::BufVertexStage;
+ if (stages.testFlag(QRhiShaderResourceBinding::FragmentStage))
+ return QRhiPassResourceTracker::BufFragmentStage;
+ if (stages.testFlag(QRhiShaderResourceBinding::ComputeStage))
+ return QRhiPassResourceTracker::BufComputeStage;
+
+ Q_UNREACHABLE();
+ return QRhiPassResourceTracker::BufVertexStage;
+}
+
+QRhiPassResourceTracker::TextureStage QRhiPassResourceTracker::toPassTrackerTextureStage(QRhiShaderResourceBinding::StageFlags stages)
+{
+ // pick the earlier stage (as this is going to be dstAccessMask)
+ if (stages.testFlag(QRhiShaderResourceBinding::VertexStage))
+ return QRhiPassResourceTracker::TexVertexStage;
+ if (stages.testFlag(QRhiShaderResourceBinding::FragmentStage))
+ return QRhiPassResourceTracker::TexFragmentStage;
+ if (stages.testFlag(QRhiShaderResourceBinding::ComputeStage))
+ return QRhiPassResourceTracker::TexComputeStage;
+
+ Q_UNREACHABLE();
+ return QRhiPassResourceTracker::TexVertexStage;
+}
+
QT_END_NAMESPACE
diff --git a/src/gui/rhi/qrhi_p_p.h b/src/gui/rhi/qrhi_p_p.h
index 83d521f441..b592fe82f2 100644
--- a/src/gui/rhi/qrhi_p_p.h
+++ b/src/gui/rhi/qrhi_p_p.h
@@ -52,6 +52,7 @@
#include "qrhiprofiler_p_p.h"
#include <QBitArray>
#include <QAtomicInt>
+#include <QLoggingCategory>
QT_BEGIN_NAMESPACE
@@ -60,6 +61,8 @@ QT_BEGIN_NAMESPACE
#define QRHI_PROF QRhiProfilerPrivate *rhiP = m_rhi->profilerPrivateOrNull()
#define QRHI_PROF_F(f) for (bool qrhip_enabled = rhiP != nullptr; qrhip_enabled; qrhip_enabled = false) rhiP->f
+Q_DECLARE_LOGGING_CATEGORY(QRHI_LOG_INFO)
+
class QRhiImplementation
{
public:
@@ -553,6 +556,9 @@ public:
};
const QVector<Texture> *textures() const { return &m_textures; }
+ static BufferStage toPassTrackerBufferStage(QRhiShaderResourceBinding::StageFlags stages);
+ static TextureStage toPassTrackerTextureStage(QRhiShaderResourceBinding::StageFlags stages);
+
private:
QVector<Buffer> m_buffers;
QVector<Texture> m_textures;
diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp
index a8a490eb5c..0c5df600a0 100644
--- a/src/gui/rhi/qrhid3d11.cpp
+++ b/src/gui/rhi/qrhid3d11.cpp
@@ -189,10 +189,10 @@ bool QRhiD3D11::create(QRhi::Flags flags)
DXGI_ADAPTER_DESC1 desc;
adapter->GetDesc1(&desc);
const QString name = QString::fromUtf16((char16_t *) desc.Description);
- qDebug("Adapter %d: '%s' (flags 0x%x)", adapterIndex, qPrintable(name), desc.Flags);
+ qCDebug(QRHI_LOG_INFO, "Adapter %d: '%s' (flags 0x%x)", adapterIndex, qPrintable(name), desc.Flags);
if (!adapterToUse && (requestedAdapterIndex < 0 || requestedAdapterIndex == adapterIndex)) {
adapterToUse = adapter;
- qDebug(" using this adapter");
+ qCDebug(QRHI_LOG_INFO, " using this adapter");
} else {
adapter->Release();
}
diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp
index 22cb030c27..379801efbd 100644
--- a/src/gui/rhi/qrhigles2.cpp
+++ b/src/gui/rhi/qrhigles2.cpp
@@ -47,12 +47,13 @@ QT_BEGIN_NAMESPACE
OpenGL backend. Binding vertex attribute locations and decomposing uniform
buffers into uniforms are handled transparently to the application via the
reflection data (QShaderDescription). Real uniform buffers are never used,
- regardless of the GLSL version. Textures and buffers feature no special logic,
- it's all just glTexSubImage2D and glBufferSubData (with "dynamic" buffers set
- to GL_DYNAMIC_DRAW). The swapchain and the associated renderbuffer for
- depth-stencil will be dummies since we have no control over the underlying
- buffers here. While we try to keep this backend clean GLES 2.0, some GL(ES)
- 3.0 features like multisample renderbuffers and blits are used when available.
+ regardless of the GLSL version. Textures and buffers feature no special
+ logic, it's all just glTexSubImage2D and glBufferSubData (with "dynamic"
+ buffers set to GL_DYNAMIC_DRAW). The swapchain and the associated
+ renderbuffer for depth-stencil will be dummies since we have no control over
+ the underlying buffers here. While the baseline here is plain GLES 2.0, some
+ modern GL(ES) features like multisample renderbuffers, blits, and compute are
+ used when available. Also functional with core profile contexts.
*/
/*!
@@ -239,6 +240,34 @@ QT_BEGIN_NAMESPACE
#define GL_MAX_SAMPLES 0x8D57
#endif
+#ifndef GL_SHADER_STORAGE_BUFFER
+#define GL_SHADER_STORAGE_BUFFER 0x90D2
+#endif
+
+#ifndef GL_READ_ONLY
+#define GL_READ_ONLY 0x88B8
+#endif
+
+#ifndef GL_WRITE_ONLY
+#define GL_WRITE_ONLY 0x88B9
+#endif
+
+#ifndef GL_READ_WRITE
+#define GL_READ_WRITE 0x88BA
+#endif
+
+#ifndef GL_COMPUTE_SHADER
+#define GL_COMPUTE_SHADER 0x91B9
+#endif
+
+#ifndef GL_ALL_BARRIER_BITS
+#define GL_ALL_BARRIER_BITS 0xFFFFFFFF
+#endif
+
+#ifndef GL_VERTEX_PROGRAM_POINT_SIZE
+#define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642
+#endif
+
/*!
Constructs a new QRhiGles2InitParams.
@@ -356,7 +385,7 @@ bool QRhiGles2::create(QRhi::Flags flags)
ctx = nullptr;
return false;
}
- qDebug() << "Created OpenGL context" << ctx->format();
+ qCDebug(QRHI_LOG_INFO) << "Created OpenGL context" << ctx->format();
}
if (!ensureContext(maybeWindow ? maybeWindow : fallbackSurface)) // see 'window' discussion in QRhiGles2InitParams comments
@@ -368,7 +397,7 @@ bool QRhiGles2::create(QRhi::Flags flags)
const char *renderer = reinterpret_cast<const char *>(f->glGetString(GL_RENDERER));
const char *version = reinterpret_cast<const char *>(f->glGetString(GL_VERSION));
if (vendor && renderer && version)
- qDebug("OpenGL VENDOR: %s RENDERER: %s VERSION: %s", vendor, renderer, version);
+ qCDebug(QRHI_LOG_INFO, "OpenGL VENDOR: %s RENDERER: %s VERSION: %s", vendor, renderer, version);
const QSurfaceFormat actualFormat = ctx->format();
@@ -400,9 +429,9 @@ bool QRhiGles2::create(QRhi::Flags flags)
caps.gles = actualFormat.renderableType() == QSurfaceFormat::OpenGLES;
if (caps.gles)
- caps.fixedIndexPrimitiveRestart = caps.ctxMajor >= 3;
+ caps.fixedIndexPrimitiveRestart = caps.ctxMajor >= 3; // ES 3.0
else
- caps.fixedIndexPrimitiveRestart = caps.ctxMajor > 4 || (caps.ctxMajor == 4 && caps.ctxMinor >= 3);
+ caps.fixedIndexPrimitiveRestart = caps.ctxMajor > 4 || (caps.ctxMajor == 4 && caps.ctxMinor >= 3); // 4.3
if (caps.fixedIndexPrimitiveRestart)
f->glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX);
@@ -411,8 +440,8 @@ bool QRhiGles2::create(QRhi::Flags flags)
caps.bgraInternalFormat = caps.bgraExternalFormat && caps.gles;
caps.r8Format = f->hasOpenGLFeature(QOpenGLFunctions::TextureRGFormats);
caps.r16Format = f->hasOpenGLExtension(QOpenGLExtensions::Sized16Formats);
- caps.floatFormats = caps.ctxMajor >= 3;
- caps.depthTexture = caps.ctxMajor >= 3;
+ caps.floatFormats = caps.ctxMajor >= 3; // 3.0 or ES 3.0
+ caps.depthTexture = caps.ctxMajor >= 3; // 3.0 or ES 3.0
caps.packedDepthStencil = f->hasOpenGLExtension(QOpenGLExtensions::PackedDepthStencil);
#ifdef Q_OS_WASM
caps.needsDepthStencilCombinedAttach = true;
@@ -421,12 +450,31 @@ bool QRhiGles2::create(QRhi::Flags flags)
#endif
caps.srgbCapableDefaultFramebuffer = f->hasOpenGLExtension(QOpenGLExtensions::SRGBFrameBuffer);
caps.coreProfile = actualFormat.profile() == QSurfaceFormat::CoreProfile;
- caps.uniformBuffers = caps.ctxMajor >= 3 && (caps.gles || caps.ctxMinor >= 1);
+
+ if (caps.gles)
+ caps.uniformBuffers = caps.ctxMajor >= 3; // ES 3.0
+ else
+ caps.uniformBuffers = caps.ctxMajor > 3 || (caps.ctxMajor == 3 && caps.ctxMinor >= 1); // 3.1
+
caps.elementIndexUint = f->hasOpenGLExtension(QOpenGLExtensions::ElementIndexUint);
caps.depth24 = f->hasOpenGLExtension(QOpenGLExtensions::Depth24);
caps.rgba8Format = f->hasOpenGLExtension(QOpenGLExtensions::Sized8Formats);
- caps.instancing = caps.ctxMajor >= 3 && (caps.gles || caps.ctxMinor >= 3);
- caps.baseVertex = caps.ctxMajor >= 3 && caps.ctxMinor >= 2;
+
+ if (caps.gles)
+ caps.instancing = caps.ctxMajor >= 3; // ES 3.0
+ else
+ caps.instancing = caps.ctxMajor > 3 || (caps.ctxMajor == 3 && caps.ctxMinor >= 3); // 3.3
+
+ caps.baseVertex = caps.ctxMajor > 3 || (caps.ctxMajor == 3 && caps.ctxMinor >= 2); // 3.2 or ES 3.2
+
+ if (caps.gles)
+ caps.compute = caps.ctxMajor > 3 || (caps.ctxMajor == 3 && caps.ctxMinor >= 1); // ES 3.1
+ else
+ caps.compute = caps.ctxMajor > 4 || (caps.ctxMajor == 4 && caps.ctxMinor >= 3); // 4.3
+
+ if (!caps.gles)
+ f->glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
+ // else (with gles) this is always on
nativeHandlesStruct.context = ctx;
@@ -683,7 +731,7 @@ bool QRhiGles2::isFeatureSupported(QRhi::Feature feature) const
case QRhi::ElementIndexUint:
return caps.elementIndexUint;
case QRhi::Compute:
- return false;
+ return caps.compute;
case QRhi::WideLines:
return true;
case QRhi::VertexShaderPointSize:
@@ -778,10 +826,11 @@ void QRhiGles2::setGraphicsPipeline(QRhiCommandBuffer *cb, QRhiGraphicsPipeline
QGles2CommandBuffer *cbD = QRHI_RES(QGles2CommandBuffer, cb);
Q_ASSERT(cbD->recordingPass == QGles2CommandBuffer::RenderPass);
QGles2GraphicsPipeline *psD = QRHI_RES(QGles2GraphicsPipeline, ps);
- const bool pipelineChanged = cbD->currentPipeline != ps || cbD->currentPipelineGeneration != psD->generation;
+ const bool pipelineChanged = cbD->currentGraphicsPipeline != ps || cbD->currentPipelineGeneration != psD->generation;
if (pipelineChanged) {
- cbD->currentPipeline = ps;
+ cbD->currentGraphicsPipeline = ps;
+ cbD->currentComputePipeline = nullptr;
cbD->currentPipelineGeneration = psD->generation;
QGles2CommandBuffer::Command cmd;
@@ -796,35 +845,92 @@ void QRhiGles2::setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBind
const QRhiCommandBuffer::DynamicOffset *dynamicOffsets)
{
QGles2CommandBuffer *cbD = QRHI_RES(QGles2CommandBuffer, cb);
- Q_ASSERT(cbD->recordingPass == QGles2CommandBuffer::RenderPass);
- Q_ASSERT(cbD->currentPipeline);
+ Q_ASSERT(cbD->recordingPass != QGles2CommandBuffer::NoPass);
+ QGles2GraphicsPipeline *gfxPsD = QRHI_RES(QGles2GraphicsPipeline, cbD->currentGraphicsPipeline);
+ QGles2ComputePipeline *compPsD = QRHI_RES(QGles2ComputePipeline, cbD->currentComputePipeline);
- if (!srb)
- srb = QRHI_RES(QGles2GraphicsPipeline, cbD->currentPipeline)->m_shaderResourceBindings;
+ if (!srb) {
+ if (gfxPsD)
+ srb = gfxPsD->m_shaderResourceBindings;
+ else
+ srb = compPsD->m_shaderResourceBindings;
+ }
+ QRhiPassResourceTracker &passResTracker(cbD->passResTrackers[cbD->currentPassResTrackerIndex]);
QGles2ShaderResourceBindings *srbD = QRHI_RES(QGles2ShaderResourceBindings, srb);
bool hasDynamicOffsetInSrb = false;
for (int i = 0, ie = srbD->m_bindings.count(); i != ie; ++i) {
const QRhiShaderResourceBindingPrivate *b = QRhiShaderResourceBindingPrivate::get(&srbD->m_bindings[i]);
switch (b->type) {
case QRhiShaderResourceBinding::UniformBuffer:
+ // no BufUniformRead / AccessUniform because no real uniform buffers are used
if (b->u.ubuf.hasDynamicOffset)
hasDynamicOffsetInSrb = true;
break;
+ case QRhiShaderResourceBinding::SampledTexture:
+ trackedRegisterTexture(&passResTracker,
+ QRHI_RES(QGles2Texture, b->u.stex.tex),
+ QRhiPassResourceTracker::TexSample,
+ QRhiPassResourceTracker::toPassTrackerTextureStage(b->stage));
+ break;
+ case QRhiShaderResourceBinding::ImageLoad:
+ Q_FALLTHROUGH();
+ case QRhiShaderResourceBinding::ImageStore:
+ Q_FALLTHROUGH();
+ case QRhiShaderResourceBinding::ImageLoadStore:
+ {
+ QGles2Texture *texD = QRHI_RES(QGles2Texture, b->u.simage.tex);
+ QRhiPassResourceTracker::TextureAccess access;
+ if (b->type == QRhiShaderResourceBinding::ImageLoad)
+ access = QRhiPassResourceTracker::TexStorageLoad;
+ else if (b->type == QRhiShaderResourceBinding::ImageStore)
+ access = QRhiPassResourceTracker::TexStorageStore;
+ else
+ access = QRhiPassResourceTracker::TexStorageLoadStore;
+ trackedRegisterTexture(&passResTracker, texD, access,
+ QRhiPassResourceTracker::toPassTrackerTextureStage(b->stage));
+ }
+ break;
+ case QRhiShaderResourceBinding::BufferLoad:
+ Q_FALLTHROUGH();
+ case QRhiShaderResourceBinding::BufferStore:
+ Q_FALLTHROUGH();
+ case QRhiShaderResourceBinding::BufferLoadStore:
+ {
+ QGles2Buffer *bufD = QRHI_RES(QGles2Buffer, b->u.sbuf.buf);
+ QRhiPassResourceTracker::BufferAccess access;
+ if (b->type == QRhiShaderResourceBinding::BufferLoad)
+ access = QRhiPassResourceTracker::BufStorageLoad;
+ else if (b->type == QRhiShaderResourceBinding::BufferStore)
+ access = QRhiPassResourceTracker::BufStorageStore;
+ else
+ access = QRhiPassResourceTracker::BufStorageLoadStore;
+ trackedRegisterBuffer(&passResTracker, bufD, access,
+ QRhiPassResourceTracker::toPassTrackerBufferStage(b->stage));
+ }
+ break;
default:
break;
}
}
- const bool srbChanged = cbD->currentSrb != srb || cbD->currentSrbGeneration != srbD->generation;
+ const bool srbChanged = gfxPsD ? (cbD->currentGraphicsSrb != srb) : (cbD->currentComputeSrb != srb);
+ const bool srbRebuilt = cbD->currentSrbGeneration != srbD->generation;
- if (srbChanged || hasDynamicOffsetInSrb) {
- cbD->currentSrb = srb;
+ if (srbChanged || srbRebuilt || hasDynamicOffsetInSrb) {
+ if (gfxPsD) {
+ cbD->currentGraphicsSrb = srb;
+ cbD->currentComputeSrb = nullptr;
+ } else {
+ cbD->currentGraphicsSrb = nullptr;
+ cbD->currentComputeSrb = srb;
+ }
cbD->currentSrbGeneration = srbD->generation;
QGles2CommandBuffer::Command cmd;
cmd.cmd = QGles2CommandBuffer::Command::BindShaderResources;
- cmd.args.bindShaderResources.ps = cbD->currentPipeline;
+ cmd.args.bindShaderResources.maybeGraphicsPs = gfxPsD;
+ cmd.args.bindShaderResources.maybeComputePs = compPsD;
cmd.args.bindShaderResources.srb = srb;
cmd.args.bindShaderResources.dynamicOffsetCount = 0;
if (hasDynamicOffsetInSrb) {
@@ -851,30 +957,39 @@ void QRhiGles2::setVertexInput(QRhiCommandBuffer *cb,
{
QGles2CommandBuffer *cbD = QRHI_RES(QGles2CommandBuffer, cb);
Q_ASSERT(cbD->recordingPass == QGles2CommandBuffer::RenderPass);
+ QRhiPassResourceTracker &passResTracker(cbD->passResTrackers[cbD->currentPassResTrackerIndex]);
for (int i = 0; i < bindingCount; ++i) {
QRhiBuffer *buf = bindings[i].first;
quint32 ofs = bindings[i].second;
QGles2Buffer *bufD = QRHI_RES(QGles2Buffer, buf);
Q_ASSERT(bufD->m_usage.testFlag(QRhiBuffer::VertexBuffer));
+
QGles2CommandBuffer::Command cmd;
cmd.cmd = QGles2CommandBuffer::Command::BindVertexBuffer;
- cmd.args.bindVertexBuffer.ps = cbD->currentPipeline;
+ cmd.args.bindVertexBuffer.ps = cbD->currentGraphicsPipeline;
cmd.args.bindVertexBuffer.buffer = bufD->buffer;
cmd.args.bindVertexBuffer.offset = ofs;
cmd.args.bindVertexBuffer.binding = startBinding + i;
cbD->commands.append(cmd);
+
+ trackedRegisterBuffer(&passResTracker, bufD, QRhiPassResourceTracker::BufVertexInput,
+ QRhiPassResourceTracker::BufVertexInputStage);
}
if (indexBuf) {
QGles2Buffer *ibufD = QRHI_RES(QGles2Buffer, indexBuf);
Q_ASSERT(ibufD->m_usage.testFlag(QRhiBuffer::IndexBuffer));
+
QGles2CommandBuffer::Command cmd;
cmd.cmd = QGles2CommandBuffer::Command::BindIndexBuffer;
cmd.args.bindIndexBuffer.buffer = ibufD->buffer;
cmd.args.bindIndexBuffer.offset = indexOffset;
cmd.args.bindIndexBuffer.type = indexFormat == QRhiCommandBuffer::IndexUInt16 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
cbD->commands.append(cmd);
+
+ trackedRegisterBuffer(&passResTracker, ibufD, QRhiPassResourceTracker::BufIndexRead,
+ QRhiPassResourceTracker::BufVertexInputStage);
}
}
@@ -932,7 +1047,7 @@ void QRhiGles2::setStencilRef(QRhiCommandBuffer *cb, quint32 refValue)
QGles2CommandBuffer::Command cmd;
cmd.cmd = QGles2CommandBuffer::Command::StencilRef;
cmd.args.stencilRef.ref = refValue;
- cmd.args.stencilRef.ps = cbD->currentPipeline;
+ cmd.args.stencilRef.ps = cbD->currentGraphicsPipeline;
cbD->commands.append(cmd);
}
@@ -944,7 +1059,7 @@ void QRhiGles2::draw(QRhiCommandBuffer *cb, quint32 vertexCount,
QGles2CommandBuffer::Command cmd;
cmd.cmd = QGles2CommandBuffer::Command::Draw;
- cmd.args.draw.ps = cbD->currentPipeline;
+ cmd.args.draw.ps = cbD->currentGraphicsPipeline;
cmd.args.draw.vertexCount = vertexCount;
cmd.args.draw.firstVertex = firstVertex;
cmd.args.draw.instanceCount = instanceCount;
@@ -960,7 +1075,7 @@ void QRhiGles2::drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount,
QGles2CommandBuffer::Command cmd;
cmd.cmd = QGles2CommandBuffer::Command::DrawIndexed;
- cmd.args.drawIndexed.ps = cbD->currentPipeline;
+ cmd.args.drawIndexed.ps = cbD->currentGraphicsPipeline;
cmd.args.drawIndexed.indexCount = indexCount;
cmd.args.drawIndexed.firstIndex = firstIndex;
cmd.args.drawIndexed.instanceCount = instanceCount;
@@ -1126,9 +1241,48 @@ QRhi::FrameOpResult QRhiGles2::flushCommandBuffer()
return QRhi::FrameOpSuccess;
}
+void QRhiGles2::trackedBufferBarrier(QGles2CommandBuffer *cbD, QGles2Buffer *bufD, QGles2Buffer::Access access)
+{
+ Q_ASSERT(cbD->recordingPass == QGles2CommandBuffer::NoPass); // this is for resource updates only
+ const QGles2Buffer::Access prevAccess = bufD->usageState.access;
+ if (access == prevAccess)
+ return;
+
+ if (prevAccess == QGles2Buffer::AccessStorageWrite || prevAccess == QGles2Buffer::AccessStorageReadWrite) {
+ // Generating the minimal barrier set is way too complicated to do
+ // correctly (prevAccess is overwritten so we won't have proper
+ // tracking across multiple passes) so setting all barrier bits will do
+ // for now.
+ QGles2CommandBuffer::Command cmd;
+ cmd.cmd = QGles2CommandBuffer::Command::Barrier;
+ cmd.args.barrier.barriers = GL_ALL_BARRIER_BITS;
+ cbD->commands.append(cmd);
+ }
+
+ bufD->usageState.access = access;
+}
+
+void QRhiGles2::trackedImageBarrier(QGles2CommandBuffer *cbD, QGles2Texture *texD, QGles2Texture::Access access)
+{
+ Q_ASSERT(cbD->recordingPass == QGles2CommandBuffer::NoPass); // this is for resource updates only
+ const QGles2Texture::Access prevAccess = texD->usageState.access;
+ if (access == prevAccess)
+ return;
+
+ if (prevAccess == QGles2Texture::AccessStorageWrite || prevAccess == QGles2Texture::AccessStorageReadWrite) {
+ QGles2CommandBuffer::Command cmd;
+ cmd.cmd = QGles2CommandBuffer::Command::Barrier;
+ cmd.args.barrier.barriers = GL_ALL_BARRIER_BITS;
+ cbD->commands.append(cmd);
+ }
+
+ texD->usageState.access = access;
+}
+
void QRhiGles2::enqueueSubresUpload(QGles2Texture *texD, QGles2CommandBuffer *cbD,
int layer, int level, const QRhiTextureSubresourceUploadDescription &subresDesc)
{
+ trackedImageBarrier(cbD, texD, QGles2Texture::AccessUpdate);
const bool isCompressed = isCompressedFormat(texD->m_format);
const bool isCubeMap = texD->m_flags.testFlag(QRhiTexture::CubeMap);
const GLenum faceTargetBase = isCubeMap ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : texD->target;
@@ -1229,9 +1383,10 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
if (bufD->m_usage.testFlag(QRhiBuffer::UniformBuffer)) {
memcpy(bufD->ubuf.data() + u.offset, u.data.constData(), u.data.size());
} else {
+ trackedBufferBarrier(cbD, bufD, QGles2Buffer::AccessUpdate);
QGles2CommandBuffer::Command cmd;
cmd.cmd = QGles2CommandBuffer::Command::BufferSubData;
- cmd.args.bufferSubData.target = bufD->target;
+ cmd.args.bufferSubData.target = bufD->targetForDataOps;
cmd.args.bufferSubData.buffer = bufD->buffer;
cmd.args.bufferSubData.offset = u.offset;
cmd.args.bufferSubData.size = u.data.size();
@@ -1247,9 +1402,10 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
if (bufD->m_usage.testFlag(QRhiBuffer::UniformBuffer)) {
memcpy(bufD->ubuf.data() + u.offset, u.data.constData(), u.data.size());
} else {
+ trackedBufferBarrier(cbD, bufD, QGles2Buffer::AccessUpdate);
QGles2CommandBuffer::Command cmd;
cmd.cmd = QGles2CommandBuffer::Command::BufferSubData;
- cmd.args.bufferSubData.target = bufD->target;
+ cmd.args.bufferSubData.target = bufD->targetForDataOps;
cmd.args.bufferSubData.buffer = bufD->buffer;
cmd.args.bufferSubData.offset = u.offset;
cmd.args.bufferSubData.size = u.data.size();
@@ -1273,6 +1429,9 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
QGles2Texture *srcD = QRHI_RES(QGles2Texture, u.copy.src);
QGles2Texture *dstD = QRHI_RES(QGles2Texture, u.copy.dst);
+ trackedImageBarrier(cbD, srcD, QGles2Texture::AccessRead);
+ trackedImageBarrier(cbD, dstD, QGles2Texture::AccessUpdate);
+
const QSize size = u.copy.desc.pixelSize().isEmpty() ? srcD->m_pixelSize : u.copy.desc.pixelSize();
// do not translate coordinates, even if sp is bottom-left from gl's pov
const QPoint sp = u.copy.desc.sourceTopLeft();
@@ -1308,6 +1467,7 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
cmd.cmd = QGles2CommandBuffer::Command::ReadPixels;
cmd.args.readPixels.result = u.read.result;
QGles2Texture *texD = QRHI_RES(QGles2Texture, u.read.rb.texture());
+ trackedImageBarrier(cbD, texD, QGles2Texture::AccessRead);
cmd.args.readPixels.texture = texD ? texD->texture : 0;
if (texD) {
cmd.args.readPixels.w = texD->m_pixelSize.width();
@@ -1320,9 +1480,10 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
}
cbD->commands.append(cmd);
} else if (u.type == QRhiResourceUpdateBatchPrivate::TextureOp::MipGen) {
+ QGles2Texture *texD = QRHI_RES(QGles2Texture, u.mipgen.tex);
+ trackedImageBarrier(cbD, texD, QGles2Texture::AccessFramebuffer);
QGles2CommandBuffer::Command cmd;
cmd.cmd = QGles2CommandBuffer::Command::GenMip;
- QGles2Texture *texD = QRHI_RES(QGles2Texture, u.mipgen.tex);
cmd.args.genMip.target = texD->target;
cmd.args.genMip.texture = texD->texture;
cbD->commands.append(cmd);
@@ -1571,6 +1732,88 @@ static inline GLenum toGlTextureCompareFunc(QRhiSampler::CompareOp op)
}
}
+static inline QGles2Buffer::Access toGlAccess(QRhiPassResourceTracker::BufferAccess access)
+{
+ switch (access) {
+ case QRhiPassResourceTracker::BufVertexInput:
+ return QGles2Buffer::AccessVertex;
+ case QRhiPassResourceTracker::BufIndexRead:
+ return QGles2Buffer::AccessIndex;
+ case QRhiPassResourceTracker::BufUniformRead:
+ return QGles2Buffer::AccessUniform;
+ case QRhiPassResourceTracker::BufStorageLoad:
+ return QGles2Buffer::AccessStorageRead;
+ case QRhiPassResourceTracker::BufStorageStore:
+ return QGles2Buffer::AccessStorageWrite;
+ case QRhiPassResourceTracker::BufStorageLoadStore:
+ return QGles2Buffer::AccessStorageReadWrite;
+ default:
+ Q_UNREACHABLE();
+ break;
+ }
+ return QGles2Buffer::AccessNone;
+}
+
+static inline QRhiPassResourceTracker::UsageState toPassTrackerUsageState(const QGles2Buffer::UsageState &bufUsage)
+{
+ QRhiPassResourceTracker::UsageState u;
+ u.layout = 0; // N/A
+ u.access = bufUsage.access;
+ u.stage = 0; // N/A
+ return u;
+}
+
+static inline QGles2Texture::Access toGlAccess(QRhiPassResourceTracker::TextureAccess access)
+{
+ switch (access) {
+ case QRhiPassResourceTracker::TexSample:
+ return QGles2Texture::AccessSample;
+ case QRhiPassResourceTracker::TexColorOutput:
+ return QGles2Texture::AccessFramebuffer;
+ case QRhiPassResourceTracker::TexDepthOutput:
+ return QGles2Texture::AccessFramebuffer;
+ case QRhiPassResourceTracker::TexStorageLoad:
+ return QGles2Texture::AccessStorageRead;
+ case QRhiPassResourceTracker::TexStorageStore:
+ return QGles2Texture::AccessStorageWrite;
+ case QRhiPassResourceTracker::TexStorageLoadStore:
+ return QGles2Texture::AccessStorageReadWrite;
+ default:
+ Q_UNREACHABLE();
+ break;
+ }
+ return QGles2Texture::AccessNone;
+}
+
+static inline QRhiPassResourceTracker::UsageState toPassTrackerUsageState(const QGles2Texture::UsageState &texUsage)
+{
+ QRhiPassResourceTracker::UsageState u;
+ u.layout = 0; // N/A
+ u.access = texUsage.access;
+ u.stage = 0; // N/A
+ return u;
+}
+
+void QRhiGles2::trackedRegisterBuffer(QRhiPassResourceTracker *passResTracker,
+ QGles2Buffer *bufD,
+ QRhiPassResourceTracker::BufferAccess access,
+ QRhiPassResourceTracker::BufferStage stage)
+{
+ QGles2Buffer::UsageState &u(bufD->usageState);
+ passResTracker->registerBuffer(bufD, 0, &access, &stage, toPassTrackerUsageState(u));
+ u.access = toGlAccess(access);
+}
+
+void QRhiGles2::trackedRegisterTexture(QRhiPassResourceTracker *passResTracker,
+ QGles2Texture *texD,
+ QRhiPassResourceTracker::TextureAccess access,
+ QRhiPassResourceTracker::TextureStage stage)
+{
+ QGles2Texture::UsageState &u(texD->usageState);
+ passResTracker->registerTexture(texD, &access, &stage, toPassTrackerUsageState(u));
+ u.access = toGlAccess(access);
+}
+
void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
{
QGles2CommandBuffer *cbD = QRHI_RES(QGles2CommandBuffer, cb);
@@ -1747,7 +1990,8 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
executeBindGraphicsPipeline(cmd.args.bindGraphicsPipeline.ps);
break;
case QGles2CommandBuffer::Command::BindShaderResources:
- bindShaderResources(cmd.args.bindShaderResources.ps,
+ bindShaderResources(cmd.args.bindShaderResources.maybeGraphicsPs,
+ cmd.args.bindShaderResources.maybeComputePs,
cmd.args.bindShaderResources.srb,
cmd.args.bindShaderResources.dynamicOffsetPairs,
cmd.args.bindShaderResources.dynamicOffsetCount);
@@ -1890,6 +2134,51 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
f->glBindTexture(cmd.args.genMip.target, cmd.args.genMip.texture);
f->glGenerateMipmap(cmd.args.genMip.target);
break;
+ case QGles2CommandBuffer::Command::BindComputePipeline:
+ {
+ QGles2ComputePipeline *psD = QRHI_RES(QGles2ComputePipeline, cmd.args.bindComputePipeline.ps);
+ f->glUseProgram(psD->program);
+ }
+ break;
+ case QGles2CommandBuffer::Command::Dispatch:
+ f->glDispatchCompute(cmd.args.dispatch.x, cmd.args.dispatch.y, cmd.args.dispatch.z);
+ break;
+ case QGles2CommandBuffer::Command::BarriersForPass:
+ {
+ GLbitfield barriers = 0;
+ QRhiPassResourceTracker &tracker(cbD->passResTrackers[cmd.args.barriersForPass.trackerIndex]);
+ const QVector<QRhiPassResourceTracker::Buffer> *buffers = tracker.buffers();
+ // we only care about after-write, not any other accesses, and
+ // cannot tell if something was written in a shader several passes
+ // ago: now the previously written resource may be used with an
+ // access that was not in the previous passes, result in a missing
+ // barrier in theory. Hence setting all barrier bits whenever
+ // something previously written is used for the first time in a
+ // subsequent pass.
+ for (const QRhiPassResourceTracker::Buffer &b : *buffers) {
+ QGles2Buffer::Access accessBeforePass = QGles2Buffer::Access(b.stateAtPassBegin.access);
+ if (accessBeforePass == QGles2Buffer::AccessStorageWrite
+ || accessBeforePass == QGles2Buffer::AccessStorageReadWrite)
+ {
+ barriers |= GL_ALL_BARRIER_BITS;
+ }
+ }
+ const QVector<QRhiPassResourceTracker::Texture> *textures = tracker.textures();
+ for (const QRhiPassResourceTracker::Texture &t : *textures) {
+ QGles2Texture::Access accessBeforePass = QGles2Texture::Access(t.stateAtPassBegin.access);
+ if (accessBeforePass == QGles2Texture::AccessStorageWrite
+ || accessBeforePass == QGles2Texture::AccessStorageReadWrite)
+ {
+ barriers |= GL_ALL_BARRIER_BITS;
+ }
+ }
+ if (barriers)
+ f->glMemoryBarrier(barriers);
+ }
+ break;
+ case QGles2CommandBuffer::Command::Barrier:
+ f->glMemoryBarrier(cmd.args.barrier.barriers);
+ break;
default:
break;
}
@@ -1969,10 +2258,10 @@ void QRhiGles2::executeBindGraphicsPipeline(QRhiGraphicsPipeline *ps)
f->glUseProgram(psD->program);
}
-void QRhiGles2::bindShaderResources(QRhiGraphicsPipeline *ps, QRhiShaderResourceBindings *srb,
+void QRhiGles2::bindShaderResources(QRhiGraphicsPipeline *maybeGraphicsPs, QRhiComputePipeline *maybeComputePs,
+ QRhiShaderResourceBindings *srb,
const uint *dynOfsPairs, int dynOfsCount)
{
- QGles2GraphicsPipeline *psD = QRHI_RES(QGles2GraphicsPipeline, ps);
QGles2ShaderResourceBindings *srbD = QRHI_RES(QGles2ShaderResourceBindings, srb);
int texUnit = 0;
@@ -1994,7 +2283,9 @@ void QRhiGles2::bindShaderResources(QRhiGraphicsPipeline *ps, QRhiShaderResource
QGles2Buffer *bufD = QRHI_RES(QGles2Buffer, b->u.ubuf.buf);
const QByteArray bufView = QByteArray::fromRawData(bufD->ubuf.constData() + viewOffset,
b->u.ubuf.maybeSize ? b->u.ubuf.maybeSize : bufD->m_size);
- for (QGles2GraphicsPipeline::Uniform &uniform : psD->uniforms) {
+ QVector<QGles2UniformDescription> &uniforms(maybeGraphicsPs ? QRHI_RES(QGles2GraphicsPipeline, maybeGraphicsPs)->uniforms
+ : QRHI_RES(QGles2ComputePipeline, maybeComputePs)->uniforms);
+ for (QGles2UniformDescription &uniform : uniforms) {
if (uniform.binding == b->binding) {
// in a uniform buffer everything is at least 4 byte aligned
// so this should not cause unaligned reads
@@ -2034,6 +2325,30 @@ void QRhiGles2::bindShaderResources(QRhiGraphicsPipeline *ps, QRhiShaderResource
case QShaderDescription::Int4:
f->glUniform4iv(uniform.glslLocation, 1, reinterpret_cast<const qint32 *>(src));
break;
+ case QShaderDescription::Uint:
+ f->glUniform1ui(uniform.glslLocation, *reinterpret_cast<const quint32 *>(src));
+ break;
+ case QShaderDescription::Uint2:
+ f->glUniform2uiv(uniform.glslLocation, 1, reinterpret_cast<const quint32 *>(src));
+ break;
+ case QShaderDescription::Uint3:
+ f->glUniform3uiv(uniform.glslLocation, 1, reinterpret_cast<const quint32 *>(src));
+ break;
+ case QShaderDescription::Uint4:
+ f->glUniform4uiv(uniform.glslLocation, 1, reinterpret_cast<const quint32 *>(src));
+ break;
+ case QShaderDescription::Bool: // a glsl bool is 4 bytes, like (u)int
+ f->glUniform1i(uniform.glslLocation, *reinterpret_cast<const qint32 *>(src));
+ break;
+ case QShaderDescription::Bool2:
+ f->glUniform2iv(uniform.glslLocation, 1, reinterpret_cast<const qint32 *>(src));
+ break;
+ case QShaderDescription::Bool3:
+ f->glUniform3iv(uniform.glslLocation, 1, reinterpret_cast<const qint32 *>(src));
+ break;
+ case QShaderDescription::Bool4:
+ f->glUniform4iv(uniform.glslLocation, 1, reinterpret_cast<const qint32 *>(src));
+ break;
// ### more types
default:
break;
@@ -2046,8 +2361,10 @@ void QRhiGles2::bindShaderResources(QRhiGraphicsPipeline *ps, QRhiShaderResource
{
QGles2Texture *texD = QRHI_RES(QGles2Texture, b->u.stex.tex);
QGles2Sampler *samplerD = QRHI_RES(QGles2Sampler, b->u.stex.sampler);
+ QVector<QGles2SamplerDescription> &samplers(maybeGraphicsPs ? QRHI_RES(QGles2GraphicsPipeline, maybeGraphicsPs)->samplers
+ : QRHI_RES(QGles2ComputePipeline, maybeComputePs)->samplers);
- for (QGles2GraphicsPipeline::Sampler &sampler : psD->samplers) {
+ for (QGles2SamplerDescription &sampler : samplers) {
if (sampler.binding == b->binding) {
f->glActiveTexture(GL_TEXTURE0 + texUnit);
f->glBindTexture(texD->target, texD->texture);
@@ -2074,6 +2391,38 @@ void QRhiGles2::bindShaderResources(QRhiGraphicsPipeline *ps, QRhiShaderResource
}
}
break;
+ case QRhiShaderResourceBinding::ImageLoad:
+ Q_FALLTHROUGH();
+ case QRhiShaderResourceBinding::ImageStore:
+ Q_FALLTHROUGH();
+ case QRhiShaderResourceBinding::ImageLoadStore:
+ {
+ QGles2Texture *texD = QRHI_RES(QGles2Texture, b->u.simage.tex);
+ const bool layered = texD->m_flags.testFlag(QRhiTexture::CubeMap);
+ GLenum access = GL_READ_WRITE;
+ if (b->type == QRhiShaderResourceBinding::ImageLoad)
+ access = GL_READ_ONLY;
+ else if (b->type == QRhiShaderResourceBinding::ImageStore)
+ access = GL_WRITE_ONLY;
+ f->glBindImageTexture(b->binding, texD->texture,
+ b->u.simage.level, layered, 0,
+ access, texD->glsizedintformat);
+ }
+ break;
+ case QRhiShaderResourceBinding::BufferLoad:
+ Q_FALLTHROUGH();
+ case QRhiShaderResourceBinding::BufferStore:
+ Q_FALLTHROUGH();
+ case QRhiShaderResourceBinding::BufferLoadStore:
+ {
+ QGles2Buffer *bufD = QRHI_RES(QGles2Buffer, b->u.sbuf.buf);
+ if (b->u.sbuf.offset == 0 && b->u.sbuf.maybeSize == 0)
+ f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, b->binding, bufD->buffer);
+ else
+ f->glBindBufferRange(GL_SHADER_STORAGE_BUFFER, b->binding, bufD->buffer,
+ b->u.sbuf.offset, b->u.sbuf.maybeSize ? b->u.sbuf.maybeSize : bufD->m_size);
+ }
+ break;
default:
Q_UNREACHABLE();
break;
@@ -2095,8 +2444,11 @@ QGles2RenderTargetData *QRhiGles2::enqueueBindFramebuffer(QRhiRenderTarget *rt,
bool *wantsColorClear, bool *wantsDsClear)
{
QGles2RenderTargetData *rtD = nullptr;
+ QRhiPassResourceTracker &passResTracker(cbD->passResTrackers[cbD->currentPassResTrackerIndex]);
+
QGles2CommandBuffer::Command fbCmd;
fbCmd.cmd = QGles2CommandBuffer::Command::BindFramebuffer;
+
switch (rt->resourceType()) {
case QRhiResource::RenderTarget:
rtD = &QRHI_RES(QGles2ReferenceRenderTarget, rt)->d;
@@ -2117,14 +2469,39 @@ QGles2RenderTargetData *QRhiGles2::enqueueBindFramebuffer(QRhiRenderTarget *rt,
*wantsDsClear = !rtTex->m_flags.testFlag(QRhiTextureRenderTarget::PreserveDepthStencilContents);
fbCmd.args.bindFramebuffer.fbo = rtTex->framebuffer;
fbCmd.args.bindFramebuffer.colorAttCount = rtD->colorAttCount;
+
+ const QVector<QRhiColorAttachment> colorAttachments = rtTex->m_desc.colorAttachments();
+ for (const QRhiColorAttachment &colorAttachment : colorAttachments) {
+ QGles2Texture *texD = QRHI_RES(QGles2Texture, colorAttachment.texture());
+ QGles2Texture *resolveTexD = QRHI_RES(QGles2Texture, colorAttachment.resolveTexture());
+ if (texD) {
+ trackedRegisterTexture(&passResTracker, texD,
+ QRhiPassResourceTracker::TexColorOutput,
+ QRhiPassResourceTracker::TexColorOutputStage);
+ }
+ if (resolveTexD) {
+ trackedRegisterTexture(&passResTracker, resolveTexD,
+ QRhiPassResourceTracker::TexColorOutput,
+ QRhiPassResourceTracker::TexColorOutputStage);
+ }
+ // renderbuffers cannot be written in shaders (no image store) so
+ // they do not matter here
+ }
+ if (rtTex->m_desc.depthTexture()) {
+ trackedRegisterTexture(&passResTracker, QRHI_RES(QGles2Texture, rtTex->m_desc.depthTexture()),
+ QRhiPassResourceTracker::TexDepthOutput,
+ QRhiPassResourceTracker::TexDepthOutputStage);
+ }
}
break;
default:
Q_UNREACHABLE();
break;
}
+
fbCmd.args.bindFramebuffer.srgb = rtD->srgbUpdateAndBlend;
cbD->commands.append(fbCmd);
+
return rtD;
}
@@ -2140,6 +2517,15 @@ void QRhiGles2::beginPass(QRhiCommandBuffer *cb,
if (resourceUpdates)
enqueueResourceUpdates(cb, resourceUpdates);
+ // Get a new resource tracker. Then add a command that will generate
+ // glMemoryBarrier() calls based on that tracker when submitted.
+ cbD->passResTrackers.append(QRhiPassResourceTracker());
+ cbD->currentPassResTrackerIndex = cbD->passResTrackers.count() - 1;
+ QGles2CommandBuffer::Command cmd;
+ cmd.cmd = QGles2CommandBuffer::Command::BarriersForPass;
+ cmd.args.barriersForPass.trackerIndex = cbD->currentPassResTrackerIndex;
+ cbD->commands.append(cmd);
+
bool wantsColorClear, wantsDsClear;
QGles2RenderTargetData *rtD = enqueueBindFramebuffer(rt, cbD, &wantsColorClear, &wantsDsClear);
@@ -2160,6 +2546,8 @@ void QRhiGles2::beginPass(QRhiCommandBuffer *cb,
cbD->recordingPass = QGles2CommandBuffer::RenderPass;
cbD->currentTarget = rt;
+
+ cbD->resetCachedState();
}
void QRhiGles2::endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates)
@@ -2212,7 +2600,16 @@ void QRhiGles2::beginComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch
if (resourceUpdates)
enqueueResourceUpdates(cb, resourceUpdates);
+ cbD->passResTrackers.append(QRhiPassResourceTracker());
+ cbD->currentPassResTrackerIndex = cbD->passResTrackers.count() - 1;
+ QGles2CommandBuffer::Command cmd;
+ cmd.cmd = QGles2CommandBuffer::Command::BarriersForPass;
+ cmd.args.barriersForPass.trackerIndex = cbD->currentPassResTrackerIndex;
+ cbD->commands.append(cmd);
+
cbD->recordingPass = QGles2CommandBuffer::ComputePass;
+
+ cbD->resetCachedState();
}
void QRhiGles2::endComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates)
@@ -2228,16 +2625,189 @@ void QRhiGles2::endComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *r
void QRhiGles2::setComputePipeline(QRhiCommandBuffer *cb, QRhiComputePipeline *ps)
{
- Q_UNUSED(cb);
- Q_UNUSED(ps);
+ QGles2CommandBuffer *cbD = QRHI_RES(QGles2CommandBuffer, cb);
+ Q_ASSERT(cbD->recordingPass == QGles2CommandBuffer::ComputePass);
+ QGles2ComputePipeline *psD = QRHI_RES(QGles2ComputePipeline, ps);
+ const bool pipelineChanged = cbD->currentComputePipeline != ps || cbD->currentPipelineGeneration != psD->generation;
+
+ if (pipelineChanged) {
+ cbD->currentGraphicsPipeline = nullptr;
+ cbD->currentComputePipeline = ps;
+ cbD->currentPipelineGeneration = psD->generation;
+
+ QGles2CommandBuffer::Command cmd;
+ cmd.cmd = QGles2CommandBuffer::Command::BindComputePipeline;
+ cmd.args.bindComputePipeline.ps = ps;
+ cbD->commands.append(cmd);
+ }
}
void QRhiGles2::dispatch(QRhiCommandBuffer *cb, int x, int y, int z)
{
- Q_UNUSED(cb);
- Q_UNUSED(x);
- Q_UNUSED(y);
- Q_UNUSED(z);
+ QGles2CommandBuffer *cbD = QRHI_RES(QGles2CommandBuffer, cb);
+ Q_ASSERT(cbD->recordingPass == QGles2CommandBuffer::ComputePass);
+
+ QGles2CommandBuffer::Command cmd;
+ cmd.cmd = QGles2CommandBuffer::Command::Dispatch;
+ cmd.args.dispatch.x = x;
+ cmd.args.dispatch.y = y;
+ cmd.args.dispatch.z = z;
+ cbD->commands.append(cmd);
+}
+
+static inline GLenum toGlShaderType(QRhiShaderStage::Type type)
+{
+ switch (type) {
+ case QRhiShaderStage::Vertex:
+ return GL_VERTEX_SHADER;
+ case QRhiShaderStage::Fragment:
+ return GL_FRAGMENT_SHADER;
+ case QRhiShaderStage::Compute:
+ return GL_COMPUTE_SHADER;
+ default:
+ Q_UNREACHABLE();
+ return GL_VERTEX_SHADER;
+ }
+}
+
+bool QRhiGles2::compileShader(GLuint program, const QRhiShaderStage &shaderStage,
+ QShaderDescription *desc, int *glslVersionUsed)
+{
+ GLuint shader = f->glCreateShader(toGlShaderType(shaderStage.type()));
+ const QShader bakedShader = shaderStage.shader();
+ QVector<int> versionsToTry;
+ QByteArray source;
+ if (caps.gles) {
+ if (caps.ctxMajor > 3 || (caps.ctxMajor == 3 && caps.ctxMinor >= 2)) {
+ versionsToTry << 320 << 310 << 300 << 100;
+ } else if (caps.ctxMajor == 3 && caps.ctxMinor == 1) {
+ versionsToTry << 310 << 300 << 100;
+ } else if (caps.ctxMajor == 3 && caps.ctxMinor == 0) {
+ versionsToTry << 300 << 100;
+ } else {
+ versionsToTry << 100;
+ }
+ for (int v : versionsToTry) {
+ QShaderVersion ver(v, QShaderVersion::GlslEs);
+ source = bakedShader.shader({ QShader::GlslShader, ver, shaderStage.shaderVariant() }).shader();
+ if (!source.isEmpty()) {
+ if (glslVersionUsed)
+ *glslVersionUsed = v;
+ break;
+ }
+ }
+ } else {
+ if (caps.ctxMajor > 4 || (caps.ctxMajor == 4 && caps.ctxMinor >= 6)) {
+ versionsToTry << 460 << 450 << 440 << 430 << 420 << 410 << 400 << 330 << 150;
+ } else if (caps.ctxMajor == 4 && caps.ctxMinor == 5) {
+ versionsToTry << 450 << 440 << 430 << 420 << 410 << 400 << 330 << 150;
+ } else if (caps.ctxMajor == 4 && caps.ctxMinor == 4) {
+ versionsToTry << 440 << 430 << 420 << 410 << 400 << 330 << 150;
+ } else if (caps.ctxMajor == 4 && caps.ctxMinor == 3) {
+ versionsToTry << 430 << 420 << 410 << 400 << 330 << 150;
+ } else if (caps.ctxMajor == 4 && caps.ctxMinor == 2) {
+ versionsToTry << 420 << 410 << 400 << 330 << 150;
+ } else if (caps.ctxMajor == 4 && caps.ctxMinor == 1) {
+ versionsToTry << 410 << 400 << 330 << 150;
+ } else if (caps.ctxMajor == 4 && caps.ctxMinor == 0) {
+ versionsToTry << 400 << 330 << 150;
+ } else if (caps.ctxMajor == 3 && caps.ctxMinor == 3) {
+ versionsToTry << 330 << 150;
+ } else if (caps.ctxMajor == 3 && caps.ctxMinor == 2) {
+ versionsToTry << 150;
+ }
+ if (!caps.coreProfile)
+ versionsToTry << 120;
+ for (int v : versionsToTry) {
+ source = bakedShader.shader({ QShader::GlslShader, v, shaderStage.shaderVariant() }).shader();
+ if (!source.isEmpty()) {
+ if (glslVersionUsed)
+ *glslVersionUsed = v;
+ break;
+ }
+ }
+ }
+ if (source.isEmpty()) {
+ qWarning() << "No GLSL shader code found (versions tried: " << versionsToTry
+ << ") in baked shader" << bakedShader;
+ return false;
+ }
+
+ const char *srcStr = source.constData();
+ const GLint srcLength = source.count();
+ f->glShaderSource(shader, 1, &srcStr, &srcLength);
+ f->glCompileShader(shader);
+ GLint compiled = 0;
+ f->glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
+ if (!compiled) {
+ GLint infoLogLength = 0;
+ f->glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
+ QByteArray log;
+ if (infoLogLength > 1) {
+ GLsizei length = 0;
+ log.resize(infoLogLength);
+ f->glGetShaderInfoLog(shader, infoLogLength, &length, log.data());
+ }
+ qWarning("Failed to compile shader: %s\nSource was:\n%s", log.constData(), source.constData());
+ return false;
+ }
+
+ f->glAttachShader(program, shader);
+ f->glDeleteShader(shader);
+
+ *desc = bakedShader.description();
+ return true;
+}
+
+bool QRhiGles2::linkProgram(GLuint program)
+{
+ f->glLinkProgram(program);
+ GLint linked = 0;
+ f->glGetProgramiv(program, GL_LINK_STATUS, &linked);
+ if (!linked) {
+ GLint infoLogLength = 0;
+ f->glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);
+ QByteArray log;
+ if (infoLogLength > 1) {
+ GLsizei length = 0;
+ log.resize(infoLogLength);
+ f->glGetProgramInfoLog(program, infoLogLength, &length, log.data());
+ }
+ qWarning("Failed to link shader program: %s", log.constData());
+ return false;
+ }
+ return true;
+}
+
+void QRhiGles2::gatherUniforms(GLuint program, const QShaderDescription::UniformBlock &ub,
+ QVector<QGles2UniformDescription> *dst)
+{
+ const QByteArray prefix = ub.structName.toUtf8() + '.';
+ for (const QShaderDescription::BlockVariable &blockMember : ub.members) {
+ // ### no array support for now
+ QGles2UniformDescription uniform;
+ uniform.type = blockMember.type;
+ const QByteArray name = prefix + blockMember.name.toUtf8();
+ uniform.glslLocation = f->glGetUniformLocation(program, name.constData());
+ if (uniform.glslLocation >= 0) {
+ uniform.binding = ub.binding;
+ uniform.offset = blockMember.offset;
+ uniform.size = blockMember.size;
+ dst->append(uniform);
+ }
+ }
+}
+
+void QRhiGles2::gatherSamplers(GLuint program, const QShaderDescription::InOutVariable &v,
+ QVector<QGles2SamplerDescription> *dst)
+{
+ QGles2SamplerDescription sampler;
+ const QByteArray name = v.name.toUtf8();
+ sampler.glslLocation = f->glGetUniformLocation(program, name.constData());
+ if (sampler.glslLocation >= 0) {
+ sampler.binding = v.binding;
+ dst->append(sampler);
+ }
}
QGles2Buffer::QGles2Buffer(QRhiImplementation *rhi, Type type, UsageFlags usage, int size)
@@ -2277,34 +2847,34 @@ bool QGles2Buffer::build()
QRHI_RES_RHI(QRhiGles2);
QRHI_PROF;
+ const int nonZeroSize = m_size <= 0 ? 256 : m_size;
+
if (m_usage.testFlag(QRhiBuffer::UniformBuffer)) {
- if (m_usage.testFlag(QRhiBuffer::VertexBuffer) || m_usage.testFlag(QRhiBuffer::IndexBuffer)) {
+ if (int(m_usage) != QRhiBuffer::UniformBuffer) {
qWarning("Uniform buffer: multiple usages specified, this is not supported by the OpenGL backend");
return false;
}
- ubuf.resize(m_size);
- QRHI_PROF_F(newBuffer(this, m_size, 0, 1));
+ ubuf.resize(nonZeroSize);
+ QRHI_PROF_F(newBuffer(this, nonZeroSize, 0, 1));
return true;
}
if (!rhiD->ensureContext())
return false;
- if (m_usage.testFlag(QRhiBuffer::VertexBuffer)) {
- if (m_usage.testFlag(QRhiBuffer::IndexBuffer)) {
- qWarning("Vertex buffer: multiple usages specified, this is not supported by the OpenGL backend");
- return false;
- }
- target = GL_ARRAY_BUFFER;
- }
+ targetForDataOps = GL_ARRAY_BUFFER;
if (m_usage.testFlag(QRhiBuffer::IndexBuffer))
- target = GL_ELEMENT_ARRAY_BUFFER;
+ targetForDataOps = GL_ELEMENT_ARRAY_BUFFER;
+ else if (m_usage.testFlag(QRhiBuffer::StorageBuffer))
+ targetForDataOps = GL_SHADER_STORAGE_BUFFER;
rhiD->f->glGenBuffers(1, &buffer);
- rhiD->f->glBindBuffer(target, buffer);
- rhiD->f->glBufferData(target, m_size, nullptr, m_type == Dynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
+ rhiD->f->glBindBuffer(targetForDataOps, buffer);
+ rhiD->f->glBufferData(targetForDataOps, nonZeroSize, nullptr, m_type == Dynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
+
+ usageState.access = AccessNone;
- QRHI_PROF_F(newBuffer(this, m_size, 1, 0));
+ QRHI_PROF_F(newBuffer(this, nonZeroSize, 1, 0));
rhiD->registerResource(this);
return true;
}
@@ -2473,58 +3043,73 @@ bool QGles2Texture::prepareBuild(QSize *adjustedSize)
gltype = GL_UNSIGNED_BYTE;
if (isCompressed) {
+ if (m_flags.testFlag(UsedWithLoadStore)) {
+ qWarning("Compressed texture cannot be used with image load/store");
+ return false;
+ }
glintformat = toGlCompressedTextureFormat(m_format, m_flags);
if (!glintformat) {
qWarning("Compressed format %d not mappable to GL compressed format", m_format);
return false;
}
+ glsizedintformat = glintformat;
glformat = GL_RGBA;
} else {
switch (m_format) {
case QRhiTexture::RGBA8:
glintformat = GL_RGBA;
+ glsizedintformat = rhiD->caps.rgba8Format ? GL_RGBA8 : GL_RGBA;
glformat = GL_RGBA;
break;
case QRhiTexture::BGRA8:
glintformat = rhiD->caps.bgraInternalFormat ? GL_BGRA : GL_RGBA;
+ glsizedintformat = rhiD->caps.rgba8Format ? GL_RGBA8 : GL_RGBA;
glformat = GL_BGRA;
break;
case QRhiTexture::R16:
glintformat = GL_R16;
+ glsizedintformat = glintformat;
glformat = GL_RED;
gltype = GL_UNSIGNED_SHORT;
break;
case QRhiTexture::R8:
glintformat = GL_R8;
+ glsizedintformat = glintformat;
glformat = GL_RED;
break;
case QRhiTexture::RED_OR_ALPHA8:
glintformat = rhiD->caps.coreProfile ? GL_R8 : GL_ALPHA;
+ glsizedintformat = glintformat;
glformat = rhiD->caps.coreProfile ? GL_RED : GL_ALPHA;
break;
case QRhiTexture::RGBA16F:
glintformat = GL_RGBA16F;
+ glsizedintformat = glintformat;
glformat = GL_RGBA;
gltype = GL_HALF_FLOAT;
break;
case QRhiTexture::RGBA32F:
glintformat = GL_RGBA32F;
+ glsizedintformat = glintformat;
glformat = GL_RGBA;
gltype = GL_FLOAT;
break;
case QRhiTexture::D16:
glintformat = GL_DEPTH_COMPONENT16;
+ glsizedintformat = glintformat;
glformat = GL_DEPTH_COMPONENT;
gltype = GL_UNSIGNED_SHORT;
break;
case QRhiTexture::D32F:
glintformat = GL_DEPTH_COMPONENT32F;
+ glsizedintformat = glintformat;
glformat = GL_DEPTH_COMPONENT;
gltype = GL_FLOAT;
break;
default:
Q_UNREACHABLE();
glintformat = GL_RGBA;
+ glsizedintformat = rhiD->caps.rgba8Format ? GL_RGBA8 : GL_RGBA;
glformat = GL_RGBA;
break;
}
@@ -2532,6 +3117,8 @@ bool QGles2Texture::prepareBuild(QSize *adjustedSize)
samplerState = QGles2SamplerData();
+ usageState.access = AccessNone;
+
if (adjustedSize)
*adjustedSize = size;
@@ -2552,18 +3139,25 @@ bool QGles2Texture::build()
const bool isCompressed = rhiD->isCompressedFormat(m_format);
if (!isCompressed) {
rhiD->f->glBindTexture(target, texture);
- if (hasMipMaps || isCube) {
- const GLenum faceTargetBase = isCube ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : target;
- for (int layer = 0, layerCount = isCube ? 6 : 1; layer != layerCount; ++layer) {
- for (int level = 0; level != mipLevelCount; ++level) {
- const QSize mipSize = rhiD->q->sizeForMipLevel(level, size);
- rhiD->f->glTexImage2D(faceTargetBase + layer, level, glintformat,
- mipSize.width(), mipSize.height(), 0,
- glformat, gltype, nullptr);
+ if (!m_flags.testFlag(UsedWithLoadStore)) {
+ if (hasMipMaps || isCube) {
+ const GLenum faceTargetBase = isCube ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : target;
+ for (int layer = 0, layerCount = isCube ? 6 : 1; layer != layerCount; ++layer) {
+ for (int level = 0; level != mipLevelCount; ++level) {
+ const QSize mipSize = rhiD->q->sizeForMipLevel(level, size);
+ rhiD->f->glTexImage2D(faceTargetBase + layer, level, glsizedintformat,
+ mipSize.width(), mipSize.height(), 0,
+ glformat, gltype, nullptr);
+ }
}
+ } else {
+ rhiD->f->glTexImage2D(target, 0, glsizedintformat, size.width(), size.height(),
+ 0, glformat, gltype, nullptr);
}
} else {
- rhiD->f->glTexImage2D(target, 0, glintformat, size.width(), size.height(), 0, glformat, gltype, nullptr);
+ // Must be specified with immutable storage functions otherwise
+ // bindImageTexture may fail.
+ rhiD->f->glTexStorage2D(target, mipLevelCount, glsizedintformat, size.width(), size.height());
}
specified = true;
} else {
@@ -2900,161 +3494,39 @@ bool QGles2GraphicsPipeline::build()
program = rhiD->f->glCreateProgram();
- int sourceVer = 0;
+ QShaderDescription vsDesc;
+ QShaderDescription fsDesc;
for (const QRhiShaderStage &shaderStage : qAsConst(m_shaderStages)) {
const bool isVertex = shaderStage.type() == QRhiShaderStage::Vertex;
const bool isFragment = shaderStage.type() == QRhiShaderStage::Fragment;
- if (!isVertex && !isFragment)
- continue;
-
- GLuint shader = rhiD->f->glCreateShader(isVertex ? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER);
- const QShader bakedShader = shaderStage.shader();
- QVector<int> versionsToTry;
- QByteArray source;
- if (rhiD->caps.gles) {
- if (rhiD->caps.ctxMajor > 3 || (rhiD->caps.ctxMajor == 3 && rhiD->caps.ctxMinor >= 2)) {
- versionsToTry << 320 << 310 << 300 << 100;
- } else if (rhiD->caps.ctxMajor == 3 && rhiD->caps.ctxMinor == 1) {
- versionsToTry << 310 << 300 << 100;
- } else if (rhiD->caps.ctxMajor == 3 && rhiD->caps.ctxMinor == 0) {
- versionsToTry << 300 << 100;
- } else {
- versionsToTry << 100;
- }
- for (int v : versionsToTry) {
- QShaderVersion ver(v, QShaderVersion::GlslEs);
- source = bakedShader.shader({ QShader::GlslShader, ver, shaderStage.shaderVariant() }).shader();
- if (!source.isEmpty()) {
- sourceVer = v;
- break;
- }
- }
- } else {
- if (rhiD->caps.ctxMajor > 4 || (rhiD->caps.ctxMajor == 4 && rhiD->caps.ctxMinor >= 6)) {
- versionsToTry << 460 << 450 << 440 << 430 << 420 << 410 << 400 << 330 << 150;
- } else if (rhiD->caps.ctxMajor == 4 && rhiD->caps.ctxMinor == 5) {
- versionsToTry << 450 << 440 << 430 << 420 << 410 << 400 << 330 << 150;
- } else if (rhiD->caps.ctxMajor == 4 && rhiD->caps.ctxMinor == 4) {
- versionsToTry << 440 << 430 << 420 << 410 << 400 << 330 << 150;
- } else if (rhiD->caps.ctxMajor == 4 && rhiD->caps.ctxMinor == 3) {
- versionsToTry << 430 << 420 << 410 << 400 << 330 << 150;
- } else if (rhiD->caps.ctxMajor == 4 && rhiD->caps.ctxMinor == 2) {
- versionsToTry << 420 << 410 << 400 << 330 << 150;
- } else if (rhiD->caps.ctxMajor == 4 && rhiD->caps.ctxMinor == 1) {
- versionsToTry << 410 << 400 << 330 << 150;
- } else if (rhiD->caps.ctxMajor == 4 && rhiD->caps.ctxMinor == 0) {
- versionsToTry << 400 << 330 << 150;
- } else if (rhiD->caps.ctxMajor == 3 && rhiD->caps.ctxMinor == 3) {
- versionsToTry << 330 << 150;
- } else if (rhiD->caps.ctxMajor == 3 && rhiD->caps.ctxMinor == 2) {
- versionsToTry << 150;
- }
- if (!rhiD->caps.coreProfile)
- versionsToTry << 120;
- for (int v : versionsToTry) {
- source = bakedShader.shader({ QShader::GlslShader, v, shaderStage.shaderVariant() }).shader();
- if (!source.isEmpty()) {
- sourceVer = v;
- break;
- }
- }
- }
- if (source.isEmpty()) {
- qWarning() << "No GLSL shader code found (versions tried: " << versionsToTry
- << ") in baked shader" << bakedShader;
- return false;
- }
-
- const char *srcStr = source.constData();
- const GLint srcLength = source.count();
- rhiD->f->glShaderSource(shader, 1, &srcStr, &srcLength);
- rhiD->f->glCompileShader(shader);
- GLint compiled = 0;
- rhiD->f->glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
- if (!compiled) {
- GLint infoLogLength = 0;
- rhiD->f->glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
- QByteArray log;
- if (infoLogLength > 1) {
- GLsizei length = 0;
- log.resize(infoLogLength);
- rhiD->f->glGetShaderInfoLog(shader, infoLogLength, &length, log.data());
- }
- qWarning("Failed to compile shader: %s\nSource was:\n%s", log.constData(), source.constData());
- return false;
+ if (isVertex) {
+ if (!rhiD->compileShader(program, shaderStage, &vsDesc, nullptr))
+ return false;
+ } else if (isFragment) {
+ if (!rhiD->compileShader(program, shaderStage, &fsDesc, nullptr))
+ return false;
}
-
- rhiD->f->glAttachShader(program, shader);
- rhiD->f->glDeleteShader(shader);
-
- if (isVertex)
- vsDesc = bakedShader.description();
- else
- fsDesc = bakedShader.description();
}
- // not very useful atm since we assume the qsb-generated GLSL shaders never use uniform blocks
- canUseUniformBuffers = rhiD->caps.uniformBuffers && sourceVer >= 140;
-
for (auto inVar : vsDesc.inputVariables()) {
const QByteArray name = inVar.name.toUtf8();
rhiD->f->glBindAttribLocation(program, inVar.location, name.constData());
}
- rhiD->f->glLinkProgram(program);
- GLint linked = 0;
- rhiD->f->glGetProgramiv(program, GL_LINK_STATUS, &linked);
- if (!linked) {
- GLint infoLogLength = 0;
- rhiD->f->glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);
- QByteArray log;
- if (infoLogLength > 1) {
- GLsizei length = 0;
- log.resize(infoLogLength);
- rhiD->f->glGetProgramInfoLog(program, infoLogLength, &length, log.data());
- }
- qWarning("Failed to link shader program: %s", log.constData());
+ if (!rhiD->linkProgram(program))
return false;
- }
-
- auto lookupUniforms = [this, rhiD](const QShaderDescription::UniformBlock &ub) {
- const QByteArray prefix = ub.structName.toUtf8() + '.';
- for (const QShaderDescription::BlockVariable &blockMember : ub.members) {
- // ### no array support for now
- Uniform uniform;
- uniform.type = blockMember.type;
- const QByteArray name = prefix + blockMember.name.toUtf8();
- uniform.glslLocation = rhiD->f->glGetUniformLocation(program, name.constData());
- if (uniform.glslLocation >= 0) {
- uniform.binding = ub.binding;
- uniform.offset = blockMember.offset;
- uniform.size = blockMember.size;
- uniforms.append(uniform);
- }
- }
- };
for (const QShaderDescription::UniformBlock &ub : vsDesc.uniformBlocks())
- lookupUniforms(ub);
+ rhiD->gatherUniforms(program, ub, &uniforms);
for (const QShaderDescription::UniformBlock &ub : fsDesc.uniformBlocks())
- lookupUniforms(ub);
-
- auto lookupSamplers = [this, rhiD](const QShaderDescription::InOutVariable &v) {
- Sampler sampler;
- const QByteArray name = v.name.toUtf8();
- sampler.glslLocation = rhiD->f->glGetUniformLocation(program, name.constData());
- if (sampler.glslLocation >= 0) {
- sampler.binding = v.binding;
- samplers.append(sampler);
- }
- };
+ rhiD->gatherUniforms(program, ub, &uniforms);
for (const QShaderDescription::InOutVariable &v : vsDesc.combinedImageSamplers())
- lookupSamplers(v);
+ rhiD->gatherSamplers(program, v, &samplers);
for (const QShaderDescription::InOutVariable &v : fsDesc.combinedImageSamplers())
- lookupSamplers(v);
+ rhiD->gatherSamplers(program, v, &samplers);
generation += 1;
rhiD->registerResource(this);
@@ -3073,11 +3545,52 @@ QGles2ComputePipeline::~QGles2ComputePipeline()
void QGles2ComputePipeline::release()
{
+ if (!program)
+ return;
+
+ QRhiGles2::DeferredReleaseEntry e;
+ e.type = QRhiGles2::DeferredReleaseEntry::Pipeline;
+
+ e.pipeline.program = program;
+
+ program = 0;
+ uniforms.clear();
+ samplers.clear();
+
+ QRHI_RES_RHI(QRhiGles2);
+ rhiD->releaseQueue.append(e);
+
+ rhiD->unregisterResource(this);
}
bool QGles2ComputePipeline::build()
{
- return false;
+ QRHI_RES_RHI(QRhiGles2);
+
+ if (program)
+ release();
+
+ if (!rhiD->ensureContext())
+ return false;
+
+ program = rhiD->f->glCreateProgram();
+ QShaderDescription csDesc;
+
+ if (!rhiD->compileShader(program, m_shaderStage, &csDesc, nullptr))
+ return false;
+ if (!rhiD->linkProgram(program))
+ return false;
+
+ for (const QShaderDescription::UniformBlock &ub : csDesc.uniformBlocks())
+ rhiD->gatherUniforms(program, ub, &uniforms);
+ for (const QShaderDescription::InOutVariable &v : csDesc.combinedImageSamplers())
+ rhiD->gatherSamplers(program, v, &samplers);
+
+ // storage images and buffers need no special steps here
+
+ generation += 1;
+ rhiD->registerResource(this);
+ return true;
}
QGles2CommandBuffer::QGles2CommandBuffer(QRhiImplementation *rhi)
diff --git a/src/gui/rhi/qrhigles2_p_p.h b/src/gui/rhi/qrhigles2_p_p.h
index d6682977ff..88a6144b42 100644
--- a/src/gui/rhi/qrhigles2_p_p.h
+++ b/src/gui/rhi/qrhigles2_p_p.h
@@ -66,8 +66,22 @@ struct QGles2Buffer : public QRhiBuffer
bool build() override;
GLuint buffer = 0;
- GLenum target;
+ GLenum targetForDataOps;
QByteArray ubuf;
+ enum Access {
+ AccessNone,
+ AccessVertex,
+ AccessIndex,
+ AccessUniform,
+ AccessStorageRead,
+ AccessStorageWrite,
+ AccessStorageReadWrite,
+ AccessUpdate
+ };
+ struct UsageState {
+ Access access;
+ };
+ UsageState usageState;
friend class QRhiGles2;
};
@@ -127,12 +141,27 @@ struct QGles2Texture : public QRhiTexture
bool owns = true;
GLenum target;
GLenum glintformat;
+ GLenum glsizedintformat;
GLenum glformat;
GLenum gltype;
QGles2SamplerData samplerState;
bool specified = false;
int mipLevelCount = 0;
QRhiGles2TextureNativeHandles nativeHandlesStruct;
+ enum Access {
+ AccessNone,
+ AccessSample,
+ AccessFramebuffer,
+ AccessStorageRead,
+ AccessStorageWrite,
+ AccessStorageReadWrite,
+ AccessUpdate,
+ AccessRead
+ };
+ struct UsageState {
+ Access access;
+ };
+ UsageState usageState;
uint generation = 0;
friend class QRhiGles2;
@@ -213,6 +242,25 @@ struct QGles2ShaderResourceBindings : public QRhiShaderResourceBindings
friend class QRhiGles2;
};
+struct QGles2UniformDescription
+{
+ QShaderDescription::VariableType type;
+ int glslLocation;
+ int binding;
+ uint offset;
+ int size;
+};
+
+Q_DECLARE_TYPEINFO(QGles2UniformDescription, Q_MOVABLE_TYPE);
+
+struct QGles2SamplerDescription
+{
+ int glslLocation;
+ int binding;
+};
+
+Q_DECLARE_TYPEINFO(QGles2SamplerDescription, Q_MOVABLE_TYPE);
+
struct QGles2GraphicsPipeline : public QRhiGraphicsPipeline
{
QGles2GraphicsPipeline(QRhiImplementation *rhi);
@@ -222,38 +270,24 @@ struct QGles2GraphicsPipeline : public QRhiGraphicsPipeline
GLuint program = 0;
GLenum drawMode = GL_TRIANGLES;
- QShaderDescription vsDesc;
- QShaderDescription fsDesc;
- bool canUseUniformBuffers = false;
-
- struct Uniform {
- QShaderDescription::VariableType type;
- int glslLocation;
- int binding;
- uint offset;
- int size;
- };
- QVector<Uniform> uniforms;
-
- struct Sampler {
- int glslLocation;
- int binding;
- };
- QVector<Sampler> samplers;
-
+ QVector<QGles2UniformDescription> uniforms;
+ QVector<QGles2SamplerDescription> samplers;
uint generation = 0;
friend class QRhiGles2;
};
-Q_DECLARE_TYPEINFO(QGles2GraphicsPipeline::Uniform, Q_MOVABLE_TYPE);
-Q_DECLARE_TYPEINFO(QGles2GraphicsPipeline::Sampler, Q_MOVABLE_TYPE);
-
struct QGles2ComputePipeline : public QRhiComputePipeline
{
QGles2ComputePipeline(QRhiImplementation *rhi);
~QGles2ComputePipeline();
void release() override;
bool build() override;
+
+ GLuint program = 0;
+ QVector<QGles2UniformDescription> uniforms;
+ QVector<QGles2SamplerDescription> samplers;
+ uint generation = 0;
+ friend class QRhiGles2;
};
struct QGles2CommandBuffer : public QRhiCommandBuffer
@@ -286,7 +320,11 @@ struct QGles2CommandBuffer : public QRhiCommandBuffer
CompressedImage,
CompressedSubImage,
BlitFromRenderbuffer,
- GenMip
+ GenMip,
+ BindComputePipeline,
+ Dispatch,
+ BarriersForPass,
+ Barrier
};
Cmd cmd;
@@ -339,7 +377,8 @@ struct QGles2CommandBuffer : public QRhiCommandBuffer
QRhiGraphicsPipeline *ps;
} bindGraphicsPipeline;
struct {
- QRhiGraphicsPipeline *ps;
+ QRhiGraphicsPipeline *maybeGraphicsPs;
+ QRhiComputePipeline *maybeComputePs;
QRhiShaderResourceBindings *srb;
int dynamicOffsetCount;
uint dynamicOffsetPairs[MAX_UBUF_BINDINGS * 2]; // binding, offsetInConstants
@@ -436,6 +475,20 @@ struct QGles2CommandBuffer : public QRhiCommandBuffer
GLenum target;
GLuint texture;
} genMip;
+ struct {
+ QRhiComputePipeline *ps;
+ } bindComputePipeline;
+ struct {
+ GLuint x;
+ GLuint y;
+ GLuint z;
+ } dispatch;
+ struct {
+ int trackerIndex;
+ } barriersForPass;
+ struct {
+ GLbitfield barriers;
+ } barrier;
} args;
};
@@ -446,11 +499,16 @@ struct QGles2CommandBuffer : public QRhiCommandBuffer
};
QVector<Command> commands;
+ QVarLengthArray<QRhiPassResourceTracker, 8> passResTrackers;
+ int currentPassResTrackerIndex;
+
PassType recordingPass;
QRhiRenderTarget *currentTarget;
- QRhiGraphicsPipeline *currentPipeline;
+ QRhiGraphicsPipeline *currentGraphicsPipeline;
+ QRhiComputePipeline *currentComputePipeline;
uint currentPipelineGeneration;
- QRhiShaderResourceBindings *currentSrb;
+ QRhiShaderResourceBindings *currentGraphicsSrb;
+ QRhiShaderResourceBindings *currentComputeSrb;
uint currentSrbGeneration;
QVector<QByteArray> dataRetainPool;
@@ -467,6 +525,12 @@ struct QGles2CommandBuffer : public QRhiCommandBuffer
}
void resetCommands() {
commands.clear();
+ // beginExternal() can lead to calling resetCommands() inside a pass,
+ // hence the condition
+ if (recordingPass == NoPass) {
+ passResTrackers.clear();
+ currentPassResTrackerIndex = -1;
+ }
dataRetainPool.clear();
imageRetainPool.clear();
}
@@ -477,9 +541,11 @@ struct QGles2CommandBuffer : public QRhiCommandBuffer
resetCachedState();
}
void resetCachedState() {
- currentPipeline = nullptr;
+ currentGraphicsPipeline = nullptr;
+ currentComputePipeline = nullptr;
currentPipelineGeneration = 0;
- currentSrb = nullptr;
+ currentGraphicsSrb = nullptr;
+ currentComputeSrb = nullptr;
currentSrbGeneration = 0;
}
};
@@ -606,17 +672,35 @@ public:
bool ensureContext(QSurface *surface = nullptr) const;
void executeDeferredReleases();
QRhi::FrameOpResult flushCommandBuffer();
+ void trackedBufferBarrier(QGles2CommandBuffer *cbD, QGles2Buffer *bufD, QGles2Buffer::Access access);
+ void trackedImageBarrier(QGles2CommandBuffer *cbD, QGles2Texture *texD, QGles2Texture::Access access);
void enqueueSubresUpload(QGles2Texture *texD, QGles2CommandBuffer *cbD,
int layer, int level, const QRhiTextureSubresourceUploadDescription &subresDesc);
void enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates);
+ void trackedRegisterBuffer(QRhiPassResourceTracker *passResTracker,
+ QGles2Buffer *bufD,
+ QRhiPassResourceTracker::BufferAccess access,
+ QRhiPassResourceTracker::BufferStage stage);
+ void trackedRegisterTexture(QRhiPassResourceTracker *passResTracker,
+ QGles2Texture *texD,
+ QRhiPassResourceTracker::TextureAccess access,
+ QRhiPassResourceTracker::TextureStage stage);
void executeCommandBuffer(QRhiCommandBuffer *cb);
void executeBindGraphicsPipeline(QRhiGraphicsPipeline *ps);
- void bindShaderResources(QRhiGraphicsPipeline *ps, QRhiShaderResourceBindings *srb,
+ void bindShaderResources(QRhiGraphicsPipeline *maybeGraphicsPs, QRhiComputePipeline *maybeComputePs,
+ QRhiShaderResourceBindings *srb,
const uint *dynOfsPairs, int dynOfsCount);
QGles2RenderTargetData *enqueueBindFramebuffer(QRhiRenderTarget *rt, QGles2CommandBuffer *cbD,
bool *wantsColorClear = nullptr, bool *wantsDsClear = nullptr);
int effectiveSampleCount(int sampleCount) const;
QSize safeTextureSize(const QSize &size) const;
+ bool compileShader(GLuint program, const QRhiShaderStage &shaderStage,
+ QShaderDescription *desc, int *glslVersionUsed);
+ bool linkProgram(GLuint program);
+ void gatherUniforms(GLuint program, const QShaderDescription::UniformBlock &ub,
+ QVector<QGles2UniformDescription> *dst);
+ void gatherSamplers(GLuint program, const QShaderDescription::InOutVariable &v,
+ QVector<QGles2SamplerDescription> *dst);
QOpenGLContext *ctx = nullptr;
bool importedContext = false;
@@ -652,7 +736,8 @@ public:
depth24(false),
rgba8Format(false),
instancing(false),
- baseVertex(false)
+ baseVertex(false),
+ compute(false)
{ }
int ctxMajor;
int ctxMinor;
@@ -682,6 +767,7 @@ public:
uint rgba8Format : 1;
uint instancing : 1;
uint baseVertex : 1;
+ uint compute : 1;
} caps;
QGles2SwapChain *currentSwapChain = nullptr;
QVector<GLint> supportedCompressedFormats;
diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm
index fa537a504b..ffb2283ae7 100644
--- a/src/gui/rhi/qrhimetal.mm
+++ b/src/gui/rhi/qrhimetal.mm
@@ -57,7 +57,8 @@ QT_BEGIN_NAMESPACE
Textures are Private (device local) and a host visible staging buffer is
used to upload data to them. Does not rely on strong objects refs from
command buffers but does rely on the automatic resource tracking of the
- command encoders.
+ command encoders. Assumes that an autorelease pool (ideally per frame) is
+ available on the thread on which QRhi is used.
*/
#if __has_feature(objc_arc)
@@ -352,7 +353,7 @@ bool QRhiMetal::create(QRhi::Flags flags)
else
d->dev = MTLCreateSystemDefaultDevice();
- qDebug("Metal device: %s", qPrintable(QString::fromNSString([d->dev name])));
+ qCDebug(QRHI_LOG_INFO, "Metal device: %s", qPrintable(QString::fromNSString([d->dev name])));
if (importedCmdQueue)
[d->cmdQueue retain];
@@ -1214,10 +1215,12 @@ QRhi::FrameOpResult QRhiMetal::endFrame(QRhiSwapChain *swapChain, QRhi::EndFrame
Q_ASSERT(currentSwapChain == swapChainD);
const bool needsPresent = !flags.testFlag(QRhi::SkipPresent);
- if (needsPresent) {
+ if (needsPresent)
[swapChainD->cbWrapper.d->cb presentDrawable: swapChainD->d->curDrawable];
- swapChainD->d->curDrawable = nil;
- }
+
+ // Must not hold on to the drawable, regardless of needsPresent.
+ // (internally it is autoreleased or something, it seems)
+ swapChainD->d->curDrawable = nil;
__block int thisFrameSlot = currentFrameSlot;
[swapChainD->cbWrapper.d->cb addCompletedHandler: ^(id<MTLCommandBuffer>) {
@@ -3535,7 +3538,7 @@ bool QMetalSwapChain::buildOrResize()
rtWrapper.d->colorAttCount = 1;
rtWrapper.d->dsAttCount = ds ? 1 : 0;
- qDebug("got CAMetalLayer, size %dx%d", pixelSize.width(), pixelSize.height());
+ qCDebug(QRHI_LOG_INFO, "got CAMetalLayer, size %dx%d", pixelSize.width(), pixelSize.height());
if (samples > 1) {
MTLTextureDescriptor *desc = [[MTLTextureDescriptor alloc] init];
diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp
index 7c4eeaf226..61a1595a50 100644
--- a/src/gui/rhi/qrhivulkan.cpp
+++ b/src/gui/rhi/qrhivulkan.cpp
@@ -360,14 +360,14 @@ bool QRhiVulkan::create(QRhi::Flags flags)
requestedPhysDevIndex = qEnvironmentVariableIntValue("QT_VK_PHYSICAL_DEVICE_INDEX");
for (uint32_t i = 0; i < physDevCount; ++i) {
f->vkGetPhysicalDeviceProperties(physDevs[i], &physDevProperties);
- qDebug("Physical device %d: '%s' %d.%d.%d", i,
- physDevProperties.deviceName,
- VK_VERSION_MAJOR(physDevProperties.driverVersion),
- VK_VERSION_MINOR(physDevProperties.driverVersion),
- VK_VERSION_PATCH(physDevProperties.driverVersion));
+ qCDebug(QRHI_LOG_INFO, "Physical device %d: '%s' %d.%d.%d", i,
+ physDevProperties.deviceName,
+ VK_VERSION_MAJOR(physDevProperties.driverVersion),
+ VK_VERSION_MINOR(physDevProperties.driverVersion),
+ VK_VERSION_PATCH(physDevProperties.driverVersion));
if (physDevIndex < 0 && (requestedPhysDevIndex < 0 || requestedPhysDevIndex == int(i))) {
physDevIndex = i;
- qDebug(" using this physical device");
+ qCDebug(QRHI_LOG_INFO, " using this physical device");
}
}
if (physDevIndex < 0) {
@@ -386,7 +386,8 @@ bool QRhiVulkan::create(QRhi::Flags flags)
gfxQueueFamilyIdx = -1;
int computelessGfxQueueCandidateIdx = -1;
for (int i = 0; i < queueFamilyProps.count(); ++i) {
- qDebug("queue family %d: flags=0x%x count=%d", i, queueFamilyProps[i].queueFlags, queueFamilyProps[i].queueCount);
+ qCDebug(QRHI_LOG_INFO, "queue family %d: flags=0x%x count=%d",
+ i, queueFamilyProps[i].queueFlags, queueFamilyProps[i].queueCount);
if (gfxQueueFamilyIdx == -1
&& (queueFamilyProps[i].queueFlags & VK_QUEUE_GRAPHICS_BIT)
&& (!maybeWindow || inst->supportsPresent(physDev, i, maybeWindow)))
@@ -422,7 +423,7 @@ bool QRhiVulkan::create(QRhi::Flags flags)
f->vkEnumerateDeviceExtensionProperties(physDev, nullptr, &devExtCount, nullptr);
QVector<VkExtensionProperties> devExts(devExtCount);
f->vkEnumerateDeviceExtensionProperties(physDev, nullptr, &devExtCount, devExts.data());
- qDebug("%d device extensions available", devExts.count());
+ qCDebug(QRHI_LOG_INFO, "%d device extensions available", devExts.count());
QVector<const char *> requestedDevExts;
requestedDevExts.append("VK_KHR_swapchain");
@@ -1244,9 +1245,9 @@ bool QRhiVulkan::recreateSwapChain(QRhiSwapChain *swapChain)
// with VK_ERROR_NATIVE_WINDOW_IN_USE_KHR if the old swapchain is provided)
const bool reuseExisting = swapChainD->sc && swapChainD->lastConnectedSurface == swapChainD->surface;
- qDebug("Creating %s swapchain of %u buffers, size %dx%d, presentation mode %d",
- reuseExisting ? "recycled" : "new",
- reqBufferCount, swapChainD->pixelSize.width(), swapChainD->pixelSize.height(), presentMode);
+ qCDebug(QRHI_LOG_INFO, "Creating %s swapchain of %u buffers, size %dx%d, presentation mode %d",
+ reuseExisting ? "recycled" : "new",
+ reqBufferCount, swapChainD->pixelSize.width(), swapChainD->pixelSize.height(), presentMode);
VkSwapchainCreateInfoKHR swapChainInfo;
memset(&swapChainInfo, 0, sizeof(swapChainInfo));
@@ -1290,7 +1291,7 @@ bool QRhiVulkan::recreateSwapChain(QRhiSwapChain *swapChain)
return false;
}
if (actualSwapChainBufferCount != reqBufferCount)
- qDebug("Actual swapchain buffer count is %u", actualSwapChainBufferCount);
+ qCDebug(QRHI_LOG_INFO, "Actual swapchain buffer count is %u", actualSwapChainBufferCount);
swapChainD->bufferCount = actualSwapChainBufferCount;
VkImage swapChainImages[QVkSwapChain::MAX_BUFFER_COUNT];
@@ -1661,6 +1662,10 @@ QRhi::FrameOpResult QRhiVulkan::endFrame(QRhiSwapChain *swapChain, QRhi::EndFram
}
}
+ // Do platform-specific WM notification. F.ex. essential on X11 in
+ // order to prevent glitches on resizing the window.
+ inst->presentQueued(swapChainD->window);
+
// mark the current swapchain buffer as unused from our side
frame.imageAcquired = false;
// and move on to the next buffer
@@ -3660,34 +3665,6 @@ void QRhiVulkan::setGraphicsPipeline(QRhiCommandBuffer *cb, QRhiGraphicsPipeline
psD->lastActiveFrameSlot = currentFrameSlot;
}
-QRhiPassResourceTracker::BufferStage toPassTrackerBufferStage(QRhiShaderResourceBinding::StageFlags stages)
-{
- // pick the earlier stage (as this is going to be dstAccessMask)
- if (stages.testFlag(QRhiShaderResourceBinding::VertexStage))
- return QRhiPassResourceTracker::BufVertexStage;
- if (stages.testFlag(QRhiShaderResourceBinding::FragmentStage))
- return QRhiPassResourceTracker::BufFragmentStage;
- if (stages.testFlag(QRhiShaderResourceBinding::ComputeStage))
- return QRhiPassResourceTracker::BufComputeStage;
-
- Q_UNREACHABLE();
- return QRhiPassResourceTracker::BufVertexStage;
-}
-
-QRhiPassResourceTracker::TextureStage toPassTrackerTextureStage(QRhiShaderResourceBinding::StageFlags stages)
-{
- // pick the earlier stage (as this is going to be dstAccessMask)
- if (stages.testFlag(QRhiShaderResourceBinding::VertexStage))
- return QRhiPassResourceTracker::TexVertexStage;
- if (stages.testFlag(QRhiShaderResourceBinding::FragmentStage))
- return QRhiPassResourceTracker::TexFragmentStage;
- if (stages.testFlag(QRhiShaderResourceBinding::ComputeStage))
- return QRhiPassResourceTracker::TexComputeStage;
-
- Q_UNREACHABLE();
- return QRhiPassResourceTracker::TexVertexStage;
-}
-
void QRhiVulkan::setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBindings *srb,
int dynamicOffsetCount,
const QRhiCommandBuffer::DynamicOffset *dynamicOffsets)
@@ -3743,7 +3720,7 @@ void QRhiVulkan::setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBin
bufD->lastActiveFrameSlot = currentFrameSlot;
trackedRegisterBuffer(&passResTracker, bufD, bufD->m_type == QRhiBuffer::Dynamic ? currentFrameSlot : 0,
QRhiPassResourceTracker::BufUniformRead,
- toPassTrackerBufferStage(b->stage));
+ QRhiPassResourceTracker::toPassTrackerBufferStage(b->stage));
// Check both the "local" id (the generation counter) and the
// global id. The latter is relevant when a newly allocated
@@ -3764,7 +3741,7 @@ void QRhiVulkan::setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBin
samplerD->lastActiveFrameSlot = currentFrameSlot;
trackedRegisterTexture(&passResTracker, texD,
QRhiPassResourceTracker::TexSample,
- toPassTrackerTextureStage(b->stage));
+ QRhiPassResourceTracker::toPassTrackerTextureStage(b->stage));
if (texD->generation != bd.stex.texGeneration
|| texD->m_id != bd.stex.texId
@@ -3797,7 +3774,7 @@ void QRhiVulkan::setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBin
access = QRhiPassResourceTracker::TexStorageLoadStore;
trackedRegisterTexture(&passResTracker, texD,
access,
- toPassTrackerTextureStage(b->stage));
+ QRhiPassResourceTracker::toPassTrackerTextureStage(b->stage));
if (texD->generation != bd.simage.generation || texD->m_id != bd.simage.id) {
rewriteDescSet = true;
@@ -3828,7 +3805,7 @@ void QRhiVulkan::setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBin
access = QRhiPassResourceTracker::BufStorageLoadStore;
trackedRegisterBuffer(&passResTracker, bufD, bufD->m_type == QRhiBuffer::Dynamic ? currentFrameSlot : 0,
access,
- toPassTrackerBufferStage(b->stage));
+ QRhiPassResourceTracker::toPassTrackerBufferStage(b->stage));
if (bufD->generation != bd.sbuf.generation || bufD->m_id != bd.sbuf.id) {
rewriteDescSet = true;
diff --git a/src/gui/text/qdistancefield.cpp b/src/gui/text/qdistancefield.cpp
index 17824a5ba1..d8a971c7b7 100644
--- a/src/gui/text/qdistancefield.cpp
+++ b/src/gui/text/qdistancefield.cpp
@@ -899,9 +899,6 @@ QDistanceField::QDistanceField(int width, int height)
{
}
-QDistanceField &QDistanceField::operator=(const QDistanceField &)
- = default;
-
QDistanceField::QDistanceField(const QRawFont &font, glyph_t glyph, bool doubleResolution)
{
setGlyph(font, glyph, doubleResolution);
diff --git a/src/gui/text/qdistancefield_p.h b/src/gui/text/qdistancefield_p.h
index d6d8edd85d..823bfaf1c6 100644
--- a/src/gui/text/qdistancefield_p.h
+++ b/src/gui/text/qdistancefield_p.h
@@ -94,7 +94,6 @@ public:
QDistanceField(const QRawFont &font, glyph_t glyph, bool doubleResolution = false);
QDistanceField(QFontEngine *fontEngine, glyph_t glyph, bool doubleResolution = false);
QDistanceField(const QPainterPath &path, glyph_t glyph, bool doubleResolution = false);
- QDistanceField &operator=(const QDistanceField &other);
bool isNull() const;
diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp
index 537d4bcefd..4198df6e43 100644
--- a/src/gui/text/qfontengine.cpp
+++ b/src/gui/text/qfontengine.cpp
@@ -899,7 +899,7 @@ QImage QFontEngine::alphaRGBMapForGlyph(glyph_t glyph, QFixed /*subPixelPosition
return rgbMask;
}
-QImage QFontEngine::bitmapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform&)
+QImage QFontEngine::bitmapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform&, const QColor &)
{
Q_UNUSED(subPixelPosition);
@@ -1075,7 +1075,10 @@ void QFontEngine::setGlyphCache(const void *context, QFontEngineGlyphCache *cach
}
-QFontEngineGlyphCache *QFontEngine::glyphCache(const void *context, GlyphFormat format, const QTransform &transform) const
+QFontEngineGlyphCache *QFontEngine::glyphCache(const void *context,
+ GlyphFormat format,
+ const QTransform &transform,
+ const QColor &color) const
{
const QHash<const void*, GlyphCaches>::const_iterator caches = m_glyphCaches.constFind(context);
if (caches == m_glyphCaches.cend())
@@ -1083,8 +1086,11 @@ QFontEngineGlyphCache *QFontEngine::glyphCache(const void *context, GlyphFormat
for (auto &e : *caches) {
QFontEngineGlyphCache *cache = e.cache.data();
- if (format == cache->glyphFormat() && qtransform_equals_no_translate(cache->m_transform, transform))
+ if (format == cache->glyphFormat()
+ && (format != Format_ARGB || color == cache->color())
+ && qtransform_equals_no_translate(cache->m_transform, transform)) {
return cache;
+ }
}
return nullptr;
diff --git a/src/gui/text/qfontengine_p.h b/src/gui/text/qfontengine_p.h
index 8dcfd7d66c..e20b52cb65 100644
--- a/src/gui/text/qfontengine_p.h
+++ b/src/gui/text/qfontengine_p.h
@@ -189,7 +189,7 @@ public:
virtual QImage alphaMapForGlyph(glyph_t, const QTransform &t);
virtual QImage alphaMapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t);
virtual QImage alphaRGBMapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t);
- virtual QImage bitmapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t);
+ virtual QImage bitmapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t, const QColor &color = QColor());
virtual QImage *lockedAlphaMapForGlyph(glyph_t glyph, QFixed subPixelPosition,
GlyphFormat neededFormat,
const QTransform &t = QTransform(),
@@ -251,7 +251,7 @@ public:
void clearGlyphCache(const void *key);
void setGlyphCache(const void *key, QFontEngineGlyphCache *data);
- QFontEngineGlyphCache *glyphCache(const void *key, GlyphFormat format, const QTransform &transform) const;
+ QFontEngineGlyphCache *glyphCache(const void *key, GlyphFormat format, const QTransform &transform, const QColor &color = QColor()) const;
static const uchar *getCMap(const uchar *table, uint tableSize, bool *isSymbolFont, int *cmapSize);
static quint32 getTrueTypeGlyphIndex(const uchar *cmap, int cmapSize, uint unicode);
diff --git a/src/gui/text/qfontengineglyphcache_p.h b/src/gui/text/qfontengineglyphcache_p.h
index fd5db1ecf5..532be10a83 100644
--- a/src/gui/text/qfontengineglyphcache_p.h
+++ b/src/gui/text/qfontengineglyphcache_p.h
@@ -65,7 +65,10 @@ QT_BEGIN_NAMESPACE
class Q_GUI_EXPORT QFontEngineGlyphCache: public QSharedData
{
public:
- QFontEngineGlyphCache(QFontEngine::GlyphFormat format, const QTransform &matrix) : m_format(format), m_transform(matrix)
+ QFontEngineGlyphCache(QFontEngine::GlyphFormat format, const QTransform &matrix, const QColor &color = QColor())
+ : m_format(format)
+ , m_transform(matrix)
+ , m_color(color)
{
Q_ASSERT(m_format != QFontEngine::Format_None);
}
@@ -74,9 +77,11 @@ public:
QFontEngine::GlyphFormat glyphFormat() const { return m_format; }
const QTransform &transform() const { return m_transform; }
+ const QColor &color() const { return m_color; }
QFontEngine::GlyphFormat m_format;
QTransform m_transform;
+ QColor m_color;
};
typedef QHash<void *, QList<QFontEngineGlyphCache *> > GlyphPointerHash;
typedef QHash<int, QList<QFontEngineGlyphCache *> > GlyphIntHash;
diff --git a/src/gui/text/qtextobject.cpp b/src/gui/text/qtextobject.cpp
index 1302bd66bb..b845889c3d 100644
--- a/src/gui/text/qtextobject.cpp
+++ b/src/gui/text/qtextobject.cpp
@@ -1322,7 +1322,7 @@ QTextList *QTextBlock::textList() const
QTextBlockUserData *QTextBlock::userData() const
{
if (!p || !n)
- return 0;
+ return nullptr;
const QTextBlockData *b = p->blockMap().fragment(n);
return b->userData;
diff --git a/src/gui/util/qdesktopservices.cpp b/src/gui/util/qdesktopservices.cpp
index ee0ff4c6ef..99214c4960 100644
--- a/src/gui/util/qdesktopservices.cpp
+++ b/src/gui/util/qdesktopservices.cpp
@@ -290,6 +290,7 @@ void QDesktopServices::unsetUrlHandler(const QString &scheme)
setUrlHandler(scheme, 0, 0);
}
+#if QT_DEPRECATED_SINCE(5, 0)
/*!
\enum QDesktopServices::StandardLocation
\since 4.4
@@ -344,6 +345,7 @@ void QDesktopServices::unsetUrlHandler(const QString &scheme)
\obsolete
Use QStandardPaths::displayName()
*/
+#endif
extern Q_CORE_EXPORT QString qt_applicationName_noFallback();
diff --git a/src/network/access/qhttp2protocolhandler.cpp b/src/network/access/qhttp2protocolhandler.cpp
index 93afcf0ee1..0ece5b7179 100644
--- a/src/network/access/qhttp2protocolhandler.cpp
+++ b/src/network/access/qhttp2protocolhandler.cpp
@@ -170,7 +170,6 @@ QHttp2ProtocolHandler::QHttp2ProtocolHandler(QHttpNetworkConnectionChannel *chan
encoder(HPack::FieldLookupTable::DefaultSize, true)
{
Q_ASSERT(channel && m_connection);
-
continuedFrames.reserve(20);
const ProtocolParameters params(m_connection->http2Parameters());
@@ -328,10 +327,32 @@ bool QHttp2ProtocolHandler::sendRequest()
return false;
}
+ // Process 'fake' (created by QNetworkAccessManager::connectToHostEncrypted())
+ // requests first:
+ auto &requests = m_channel->spdyRequestsToSend;
+ for (auto it = requests.begin(), endIt = requests.end(); it != endIt;) {
+ const auto &pair = *it;
+ const QString scheme(pair.first.url().scheme());
+ if (scheme == QLatin1String("preconnect-http")
+ || scheme == QLatin1String("preconnect-https")) {
+ m_connection->preConnectFinished();
+ emit pair.second->finished();
+ it = requests.erase(it);
+ if (!requests.size()) {
+ // Normally, after a connection was established and H2
+ // was negotiated, we send a client preface. connectToHostEncrypted
+ // though is not meant to send any data, it's just a 'preconnect'.
+ // Thus we return early:
+ return true;
+ }
+ } else {
+ ++it;
+ }
+ }
+
if (!prefaceSent && !sendClientPreface())
return false;
- auto &requests = m_channel->spdyRequestsToSend;
if (!requests.size())
return true;
diff --git a/src/network/access/qhttpthreaddelegate.cpp b/src/network/access/qhttpthreaddelegate.cpp
index 6fb4710d77..acc551a7c9 100644
--- a/src/network/access/qhttpthreaddelegate.cpp
+++ b/src/network/access/qhttpthreaddelegate.cpp
@@ -128,7 +128,8 @@ static QByteArray makeCacheKey(QUrl &url, QNetworkProxy *proxy, const QString &p
QString result;
QUrl copy = url;
QString scheme = copy.scheme();
- bool isEncrypted = scheme == QLatin1String("https");
+ bool isEncrypted = scheme == QLatin1String("https")
+ || scheme == QLatin1String("preconnect-https");
copy.setPort(copy.port(isEncrypted ? 443 : 80));
if (scheme == QLatin1String("preconnect-http")) {
copy.setScheme(QLatin1String("http"));
@@ -296,17 +297,29 @@ void QHttpThreadDelegate::startRequest()
connectionType = QHttpNetworkConnection::ConnectionTypeHTTP2Direct;
}
+ const bool isH2 = httpRequest.isHTTP2Allowed() || httpRequest.isHTTP2Direct();
+ if (isH2) {
+#if QT_CONFIG(ssl)
+ if (ssl) {
+ if (!httpRequest.isHTTP2Direct()) {
+ QList<QByteArray> protocols;
+ protocols << QSslConfiguration::ALPNProtocolHTTP2
+ << QSslConfiguration::NextProtocolHttp1_1;
+ incomingSslConfiguration->setAllowedNextProtocols(protocols);
+ }
+ urlCopy.setScheme(QStringLiteral("h2s"));
+ } else
+#endif // QT_CONFIG(ssl)
+ {
+ urlCopy.setScheme(QStringLiteral("h2"));
+ }
+ }
+
#ifndef QT_NO_SSL
if (ssl && !incomingSslConfiguration.data())
incomingSslConfiguration.reset(new QSslConfiguration);
- if (httpRequest.isHTTP2Allowed() && ssl) {
- // With HTTP2Direct we do not try any protocol negotiation.
- QList<QByteArray> protocols;
- protocols << QSslConfiguration::ALPNProtocolHTTP2
- << QSslConfiguration::NextProtocolHttp1_1;
- incomingSslConfiguration->setAllowedNextProtocols(protocols);
- } else if (httpRequest.isSPDYAllowed() && ssl) {
+ if (!isH2 && httpRequest.isSPDYAllowed() && ssl) {
connectionType = QHttpNetworkConnection::ConnectionTypeSPDY;
urlCopy.setScheme(QStringLiteral("spdy")); // to differentiate SPDY requests from HTTPS requests
QList<QByteArray> nextProtocols;
@@ -323,12 +336,11 @@ void QHttpThreadDelegate::startRequest()
cacheKey = makeCacheKey(urlCopy, &cacheProxy, httpRequest.peerVerifyName());
else
#endif
- cacheKey = makeCacheKey(urlCopy, 0, httpRequest.peerVerifyName());
-
+ cacheKey = makeCacheKey(urlCopy, nullptr, httpRequest.peerVerifyName());
// the http object is actually a QHttpNetworkConnection
httpConnection = static_cast<QNetworkAccessCachedHttpConnection *>(connections.localData()->requestEntryNow(cacheKey));
- if (httpConnection == 0) {
+ if (!httpConnection) {
// no entry in cache; create an object
// the http object is actually a QHttpNetworkConnection
#ifdef QT_NO_BEARERMANAGEMENT
@@ -358,7 +370,7 @@ void QHttpThreadDelegate::startRequest()
connections.localData()->addEntry(cacheKey, httpConnection);
} else {
if (httpRequest.withCredentials()) {
- QNetworkAuthenticationCredential credential = authenticationManager->fetchCachedCredentials(httpRequest.url(), 0);
+ QNetworkAuthenticationCredential credential = authenticationManager->fetchCachedCredentials(httpRequest.url(), nullptr);
if (!credential.user.isEmpty() && !credential.password.isEmpty()) {
QAuthenticator auth;
auth.setUser(credential.user);
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp
index a2996e3533..29192ae7b0 100644
--- a/src/network/access/qnetworkaccessmanager.cpp
+++ b/src/network/access/qnetworkaccessmanager.cpp
@@ -493,9 +493,9 @@ QNetworkAccessManager::QNetworkAccessManager(QObject *parent)
connect(&d->statusMonitor, SIGNAL(onlineStateChanged(bool)),
SLOT(_q_onlineStateChanged(bool)));
#ifdef QT_NO_BEARERMANAGEMENT
- d->networkAccessible = d->statusMonitor.isNetworkAccesible();
+ d->networkAccessible = d->statusMonitor.isNetworkAccessible();
#else
- d->networkAccessible = d->statusMonitor.isNetworkAccesible() ? Accessible : NotAccessible;
+ d->networkAccessible = d->statusMonitor.isNetworkAccessible() ? Accessible : NotAccessible;
} else {
// if a session is required, we track online state through
// the QNetworkSession's signals if a request is already made.
@@ -1236,10 +1236,11 @@ void QNetworkAccessManager::connectToHostEncrypted(const QString &hostName, quin
if (sslConfiguration != QSslConfiguration::defaultConfiguration())
request.setSslConfiguration(sslConfiguration);
- // There is no way to enable SPDY via a request, so we need to check
- // the ssl configuration whether SPDY is allowed here.
- if (sslConfiguration.allowedNextProtocols().contains(
- QSslConfiguration::NextProtocolSpdy3_0))
+ // There is no way to enable SPDY/HTTP2 via a request, so we need to check
+ // the ssl configuration whether SPDY/HTTP2 is allowed here.
+ if (sslConfiguration.allowedNextProtocols().contains(QSslConfiguration::ALPNProtocolHTTP2))
+ request.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, true);
+ else if (sslConfiguration.allowedNextProtocols().contains(QSslConfiguration::NextProtocolSpdy3_0))
request.setAttribute(QNetworkRequest::SpdyAllowedAttribute, true);
request.setPeerVerifyName(peerName);
@@ -1565,8 +1566,8 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera
QNetworkReplyImpl *reply = new QNetworkReplyImpl(this);
#ifndef QT_NO_BEARERMANAGEMENT
// NETMONTODO: network reply impl must be augmented to use the same monitoring
- // capabilities as http network reply impl does.
- if (!isLocalFile && !d->statusMonitor.isEnabled()) {
+ // capabilities as http network reply impl does. Once it does: uncomment the condition below
+ if (!isLocalFile /*&& !d->statusMonitor.isEnabled()*/) {
connect(this, SIGNAL(networkSessionConnected()),
reply, SLOT(_q_networkSessionConnected()));
}
diff --git a/src/network/access/qnetworkreplywasmimpl.cpp b/src/network/access/qnetworkreplywasmimpl.cpp
index ee91dc20b3..53784407d8 100644
--- a/src/network/access/qnetworkreplywasmimpl.cpp
+++ b/src/network/access/qnetworkreplywasmimpl.cpp
@@ -135,8 +135,10 @@ static void q_loadCallback(val event)
if (readyState == 4) { // done
reply->setReplyAttributes(xhr["data-handler"].as<quintptr>(), status, statusText);
- if (!responseString.isEmpty())
- reply->dataReceived(responseString.toUtf8(), responseString.size());
+ if (!responseString.isEmpty()) {
+ QByteArray responseStringArray = responseString.toUtf8();
+ reply->dataReceived(responseStringArray, responseStringArray.size());
+ }
}
}
if (status >= 400 && !statusText.isEmpty())
diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp
index ba36c75419..37f64c3f52 100644
--- a/src/network/access/qnetworkrequest.cpp
+++ b/src/network/access/qnetworkrequest.cpp
@@ -468,13 +468,24 @@ public:
};
/*!
+ Constructs a QNetworkRequest object with no URL to be requested.
+ Use setUrl() to set one.
+
+ \sa url(), setUrl()
+*/
+QNetworkRequest::QNetworkRequest()
+ : d(new QNetworkRequestPrivate)
+{
+}
+
+/*!
Constructs a QNetworkRequest object with \a url as the URL to be
requested.
\sa url(), setUrl()
*/
QNetworkRequest::QNetworkRequest(const QUrl &url)
- : d(new QNetworkRequestPrivate)
+ : QNetworkRequest()
{
d->url = url;
}
@@ -1344,7 +1355,7 @@ QDateTime QNetworkHeadersPrivate::fromHttpDate(const QByteArray &value)
QByteArray QNetworkHeadersPrivate::toHttpDate(const QDateTime &dt)
{
- return QLocale::c().toString(dt, QStringViewLiteral("ddd, dd MMM yyyy hh:mm:ss 'GMT'"))
+ return QLocale::c().toString(dt, u"ddd, dd MMM yyyy hh:mm:ss 'GMT'")
.toLatin1();
}
diff --git a/src/network/access/qnetworkrequest.h b/src/network/access/qnetworkrequest.h
index 846ead1592..8ad4ab41c0 100644
--- a/src/network/access/qnetworkrequest.h
+++ b/src/network/access/qnetworkrequest.h
@@ -128,7 +128,8 @@ public:
};
- explicit QNetworkRequest(const QUrl &url = QUrl());
+ QNetworkRequest();
+ explicit QNetworkRequest(const QUrl &url);
QNetworkRequest(const QNetworkRequest &other);
~QNetworkRequest();
QNetworkRequest &operator=(QNetworkRequest &&other) noexcept { swap(other); return *this; }
diff --git a/src/network/access/qspdyprotocolhandler.cpp b/src/network/access/qspdyprotocolhandler.cpp
index 403c01e974..f845235bf7 100644
--- a/src/network/access/qspdyprotocolhandler.cpp
+++ b/src/network/access/qspdyprotocolhandler.cpp
@@ -305,7 +305,7 @@ bool QSpdyProtocolHandler::sendRequest()
currentReply->setSpdyWasUsed(true);
qint32 streamID = generateNextStreamID();
- currentReply->setProperty("SPDYStreamID", streamID);
+ m_streamIDs.insert(currentReply, streamID);
currentReply->setRequest(currentRequest);
currentReply->d_func()->connection = m_connection;
@@ -322,7 +322,7 @@ bool QSpdyProtocolHandler::sendRequest()
void QSpdyProtocolHandler::_q_replyDestroyed(QObject* reply)
{
- qint32 streamID = reply->property("SPDYStreamID").toInt();
+ qint32 streamID = m_streamIDs.take(reply);
if (m_inFlightStreams.remove(streamID))
sendRST_STREAM(streamID, RST_STREAM_CANCEL);
}
@@ -624,10 +624,12 @@ void QSpdyProtocolHandler::sendSYN_STREAM(const HttpMessagePair &messagePair,
// hack: set the stream ID on the device directly, so when we get
// the signal for uploading we know which stream we are sending on
- request.uploadByteDevice()->setProperty("SPDYStreamID", streamID);
+ m_streamIDs.insert(request.uploadByteDevice(), streamID);
QObject::connect(request.uploadByteDevice(), SIGNAL(readyRead()), this,
SLOT(_q_uploadDataReadyRead()), Qt::QueuedConnection);
+ QObject::connect(request.uploadByteDevice(), SIGNAL(destroyed(QObject*)), this,
+ SLOT(_q_uploadDataDestroyed(QObject *)));
}
QByteArray namesAndValues = composeHeader(request);
@@ -663,6 +665,11 @@ void QSpdyProtocolHandler::sendSYN_STREAM(const HttpMessagePair &messagePair,
uploadData(streamID);
}
+void QSpdyProtocolHandler::_q_uploadDataDestroyed(QObject *uploadData)
+{
+ m_streamIDs.remove(uploadData);
+}
+
void QSpdyProtocolHandler::sendRST_STREAM(qint32 streamID, RST_STREAM_STATUS_CODE statusCode)
{
char wireData[8];
@@ -756,7 +763,7 @@ void QSpdyProtocolHandler::_q_uploadDataReadyRead()
{
QNonContiguousByteDevice *device = qobject_cast<QNonContiguousByteDevice *>(sender());
Q_ASSERT(device);
- qint32 streamID = device->property("SPDYStreamID").toInt();
+ qint32 streamID = m_streamIDs.value(device);
Q_ASSERT(streamID > 0);
uploadData(streamID);
}
diff --git a/src/network/access/qspdyprotocolhandler_p.h b/src/network/access/qspdyprotocolhandler_p.h
index dd93a9aba2..14e2ff388a 100644
--- a/src/network/access/qspdyprotocolhandler_p.h
+++ b/src/network/access/qspdyprotocolhandler_p.h
@@ -110,6 +110,7 @@ public:
private slots:
void _q_uploadDataReadyRead();
void _q_replyDestroyed(QObject*);
+ void _q_uploadDataDestroyed(QObject *);
private:
@@ -216,6 +217,7 @@ private:
bool m_waitingForCompleteStream;
z_stream m_deflateStream;
z_stream m_inflateStream;
+ QHash<QObject *, qint32> m_streamIDs;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QSpdyProtocolHandler::DataFrameFlags)
diff --git a/src/network/bearer/qsharednetworksession.cpp b/src/network/bearer/qsharednetworksession.cpp
index af543f77e3..b3e9892f4b 100644
--- a/src/network/bearer/qsharednetworksession.cpp
+++ b/src/network/bearer/qsharednetworksession.cpp
@@ -64,9 +64,23 @@ struct DeleteLater {
}
};
+template <typename Container>
+static void maybe_prune_expired(Container &c)
+{
+ if (c.size() > 16) {
+ for (auto it = c.cbegin(), end = c.cend(); it != end; /*erasing*/) {
+ if (!it->second.lock())
+ it = c.erase(it);
+ else
+ ++it;
+ }
+ }
+}
+
QSharedPointer<QNetworkSession> QSharedNetworkSessionManager::getSession(const QNetworkConfiguration &config)
{
QSharedNetworkSessionManager *m = sharedNetworkSessionManager();
+ maybe_prune_expired(m->sessions);
auto &entry = m->sessions[config];
//if already have a session, return it
if (auto p = entry.toStrongRef())
diff --git a/src/network/configure.json b/src/network/configure.json
index 56805da7b2..9652dfd1f7 100644
--- a/src/network/configure.json
+++ b/src/network/configure.json
@@ -208,6 +208,22 @@
"main": ["gss_ctx_id_t ctx;"],
"qmake": "LIBS += -lgssapi_krb5"
}
+ },
+ "netlistmgr": {
+ "label": "Network List Manager",
+ "type": "compile",
+ "test": {
+ "include": [ "netlistmgr.h", "wrl/client.h" ],
+ "main": [
+ "using namespace Microsoft::WRL;",
+ "ComPtr<INetworkListManager> networkListManager;",
+ "ComPtr<IConnectionPoint> connectionPoint;",
+ "ComPtr<IConnectionPointContainer> connectionPointContainer;",
+ "networkListManager.As(&connectionPointContainer);",
+ "connectionPointContainer->FindConnectionPoint(IID_INetworkConnectionEvents, &connectionPoint);"
+ ],
+ "qmake": "LIBS += -lOle32"
+ }
}
},
@@ -397,6 +413,13 @@
"section": "Networking",
"condition": "config.win32 && !config.winrt",
"output": [ "publicFeature", "feature" ]
+ },
+ "netlistmgr": {
+ "label": "Network List Manager",
+ "purpose": "Use Network List Manager to keep track of network connectivity",
+ "section": "Networking",
+ "condition": "config.win32 && tests.netlistmgr",
+ "output": [ "privateFeature" ]
}
},
diff --git a/src/network/kernel/kernel.pri b/src/network/kernel/kernel.pri
index 0e4cef5e74..a55648dbc7 100644
--- a/src/network/kernel/kernel.pri
+++ b/src/network/kernel/kernel.pri
@@ -77,6 +77,8 @@ macos | ios {
kernel/qnetconmonitor_darwin.mm
LIBS_PRIVATE += -framework SystemConfiguration
+} else:qtConfig(netlistmgr) {
+ SOURCES += kernel/qnetconmonitor_win.cpp
} else {
SOURCES += kernel/qnetconmonitor_stub.cpp
}
diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp
index 25ff873307..487cac6d90 100644
--- a/src/network/kernel/qhostinfo.cpp
+++ b/src/network/kernel/qhostinfo.cpp
@@ -47,6 +47,7 @@
#include <qabstracteventdispatcher.h>
#include <qcoreapplication.h>
#include <qmetaobject.h>
+#include <qscopeguard.h>
#include <qstringlist.h>
#include <qthread.h>
#include <qurl.h>
@@ -85,13 +86,6 @@ private:
QString m_toBeLookedUp;
};
-// ### C++11: remove once we can use std::any_of()
-template<class InputIt, class UnaryPredicate>
-bool any_of(InputIt first, InputIt last, UnaryPredicate p)
-{
- return std::find_if(first, last, p) != last;
-}
-
template <typename InputIt, typename OutputIt1, typename OutputIt2, typename UnaryPredicate>
std::pair<OutputIt1, OutputIt2> separate_if(InputIt first, InputIt last, OutputIt1 dest1, OutputIt2 dest2, UnaryPredicate p)
{
@@ -118,11 +112,39 @@ int get_signal_index()
return signal_index + QMetaObjectPrivate::signalOffset(senderMetaObject);
}
-void emit_results_ready(const QHostInfo &hostInfo, const QObject *receiver,
- QtPrivate::QSlotObjectBase *slotObj)
+}
+
+/*
+ The calling thread is likely the one that executes the lookup via
+ QHostInfoRunnable. Unless we operate with a queued connection already,
+ posts the QHostInfo to a dedicated QHostInfoResult object that lives in
+ the same thread as the user-provided receiver, or (if there is none) in
+ the thread that made the call to lookupHost. That QHostInfoResult object
+ then calls the user code in the correct thread.
+
+ The 'result' object deletes itself (via deleteLater) when the metacall
+ event is received.
+*/
+void QHostInfoResult::postResultsReady(const QHostInfo &info)
{
+ // queued connection will take care of dispatching to right thread
+ if (!slotObj) {
+ emitResultsReady(info);
+ return;
+ }
static const int signal_index = get_signal_index();
+
+ // we used to have a context object, but it's already destroyed
+ if (withContextObject && !receiver)
+ return;
+
+ /* QHostInfoResult c'tor moves the result object to the thread of receiver.
+ If we don't have a receiver, then the result object will not live in a
+ thread that runs an event loop - so move it to this' thread, which is the thread
+ that initiated the lookup, and required to have a running event loop. */
auto result = new QHostInfoResult(receiver, slotObj);
+ if (!receiver)
+ result->moveToThread(thread());
Q_CHECK_PTR(result);
const int nargs = 2;
auto types = reinterpret_cast<int *>(malloc(nargs * sizeof(int)));
@@ -132,15 +154,13 @@ void emit_results_ready(const QHostInfo &hostInfo, const QObject *receiver,
auto args = reinterpret_cast<void **>(malloc(nargs * sizeof(void *)));
Q_CHECK_PTR(args);
args[0] = 0;
- args[1] = QMetaType::create(types[1], &hostInfo);
+ args[1] = QMetaType::create(types[1], &info);
Q_CHECK_PTR(args[1]);
auto metaCallEvent = new QMetaCallEvent(slotObj, nullptr, signal_index, nargs, types, args);
Q_CHECK_PTR(metaCallEvent);
qApp->postEvent(result, metaCallEvent);
}
-}
-
/*!
\class QHostInfo
\brief The QHostInfo class provides static functions for host name lookups.
@@ -328,6 +348,10 @@ int QHostInfo::lookupHost(const QString &name, QObject *receiver,
ready, the \a functor is called with a QHostInfo argument. The
QHostInfo object can then be inspected to get the results of the
lookup.
+
+ The \a functor will be run in the thread that makes the call to lookupHost;
+ that thread must have a running Qt event loop.
+
\note There is no guarantee on the order the signals will be emitted
if you start multiple requests with lookupHost().
@@ -398,7 +422,7 @@ QHostInfo QHostInfo::fromName(const QString &name)
#endif
QHostInfo hostInfo = QHostInfoAgent::fromName(name);
- QAbstractHostInfoLookupManager* manager = theHostInfoLookupManager();
+ QHostInfoLookupManager* manager = theHostInfoLookupManager();
manager->cache.put(name, hostInfo);
return hostInfo;
}
@@ -411,7 +435,7 @@ QHostInfo QHostInfoPrivate::fromName(const QString &name, QSharedPointer<QNetwor
#endif
QHostInfo hostInfo = QHostInfoAgent::fromName(name, session);
- QAbstractHostInfoLookupManager* manager = theHostInfoLookupManager();
+ QHostInfoLookupManager* manager = theHostInfoLookupManager();
manager->cache.put(name, hostInfo);
return hostInfo;
}
@@ -600,8 +624,9 @@ QHostInfo QHostInfoAgent::lookup(const QString &hostName)
\sa lookupId()
*/
QHostInfo::QHostInfo(int id)
- : d(new QHostInfoPrivate)
+ : d_ptr(new QHostInfoPrivate)
{
+ Q_D(QHostInfo);
d->lookupId = id;
}
@@ -609,17 +634,30 @@ QHostInfo::QHostInfo(int id)
Constructs a copy of \a other.
*/
QHostInfo::QHostInfo(const QHostInfo &other)
- : d(new QHostInfoPrivate(*other.d.data()))
+ : d_ptr(new QHostInfoPrivate(*other.d_ptr))
{
}
/*!
+ Move-constucts a new QHostInfo from \a other.
+
+ \note The moved-from object \a other is placed in a
+ partially-formed state, in which the only valid operations are
+ destruction and assignment of a new value.
+
+ \since 5.14
+*/
+
+/*!
Assigns the data of the \a other object to this host info object,
and returns a reference to it.
*/
QHostInfo &QHostInfo::operator=(const QHostInfo &other)
{
- *d.data() = *other.d.data();
+ if (d_ptr)
+ *d_ptr = *other.d_ptr;
+ else
+ d_ptr = new QHostInfoPrivate(*other.d_ptr);
return *this;
}
@@ -628,6 +666,7 @@ QHostInfo &QHostInfo::operator=(const QHostInfo &other)
*/
QHostInfo::~QHostInfo()
{
+ delete d_ptr;
}
/*!
@@ -642,6 +681,7 @@ QHostInfo::~QHostInfo()
*/
QList<QHostAddress> QHostInfo::addresses() const
{
+ Q_D(const QHostInfo);
return d->addrs;
}
@@ -652,6 +692,7 @@ QList<QHostAddress> QHostInfo::addresses() const
*/
void QHostInfo::setAddresses(const QList<QHostAddress> &addresses)
{
+ Q_D(QHostInfo);
d->addrs = addresses;
}
@@ -662,6 +703,7 @@ void QHostInfo::setAddresses(const QList<QHostAddress> &addresses)
*/
QString QHostInfo::hostName() const
{
+ Q_D(const QHostInfo);
return d->hostName;
}
@@ -672,6 +714,7 @@ QString QHostInfo::hostName() const
*/
void QHostInfo::setHostName(const QString &hostName)
{
+ Q_D(QHostInfo);
d->hostName = hostName;
}
@@ -683,6 +726,7 @@ void QHostInfo::setHostName(const QString &hostName)
*/
QHostInfo::HostInfoError QHostInfo::error() const
{
+ Q_D(const QHostInfo);
return d->err;
}
@@ -693,6 +737,7 @@ QHostInfo::HostInfoError QHostInfo::error() const
*/
void QHostInfo::setError(HostInfoError error)
{
+ Q_D(QHostInfo);
d->err = error;
}
@@ -703,6 +748,7 @@ void QHostInfo::setError(HostInfoError error)
*/
int QHostInfo::lookupId() const
{
+ Q_D(const QHostInfo);
return d->lookupId;
}
@@ -713,6 +759,7 @@ int QHostInfo::lookupId() const
*/
void QHostInfo::setLookupId(int id)
{
+ Q_D(QHostInfo);
d->lookupId = id;
}
@@ -724,6 +771,7 @@ void QHostInfo::setLookupId(int id)
*/
QString QHostInfo::errorString() const
{
+ Q_D(const QHostInfo);
return d->errorStr;
}
@@ -735,6 +783,7 @@ QString QHostInfo::errorString() const
*/
void QHostInfo::setErrorString(const QString &str)
{
+ Q_D(QHostInfo);
d->errorStr = str;
}
@@ -791,7 +840,8 @@ int QHostInfo::lookupHostImpl(const QString &name,
QHostInfo hostInfo(id);
hostInfo.setError(QHostInfo::HostNotFound);
hostInfo.setErrorString(QCoreApplication::translate("QHostInfo", "No host name given"));
- emit_results_ready(hostInfo, receiver, slotObj);
+ QHostInfoResult result(receiver, slotObj);
+ result.postResultsReady(hostInfo);
return id;
}
@@ -805,7 +855,8 @@ int QHostInfo::lookupHostImpl(const QString &name,
QHostInfo info = manager->cache.get(name, &valid);
if (valid) {
info.setLookupId(id);
- emit_results_ready(info, receiver, slotObj);
+ QHostInfoResult result(receiver, slotObj);
+ result.postResultsReady(info);
return id;
}
}
@@ -833,11 +884,10 @@ QHostInfoRunnable::QHostInfoRunnable(const QString &hn, int i, const QObject *re
void QHostInfoRunnable::run()
{
QHostInfoLookupManager *manager = theHostInfoLookupManager();
+ const auto sg = qScopeGuard([&] { manager->lookupFinished(this); });
// check aborted
- if (manager->wasAborted(id)) {
- manager->lookupFinished(this);
+ if (manager->wasAborted(id))
return;
- }
QHostInfo hostInfo;
@@ -859,14 +909,12 @@ void QHostInfoRunnable::run()
}
// check aborted again
- if (manager->wasAborted(id)) {
- manager->lookupFinished(this);
+ if (manager->wasAborted(id))
return;
- }
// signal emission
hostInfo.setLookupId(id);
- resultEmitter.emitResultsReady(hostInfo);
+ resultEmitter.postResultsReady(hostInfo);
#if QT_CONFIG(thread)
// now also iterate through the postponed ones
@@ -879,30 +927,31 @@ void QHostInfoRunnable::run()
QHostInfoRunnable* postponed = *it;
// we can now emit
hostInfo.setLookupId(postponed->id);
- postponed->resultEmitter.emitResultsReady(hostInfo);
+ postponed->resultEmitter.postResultsReady(hostInfo);
delete postponed;
}
manager->postponedLookups.erase(partitionBegin, partitionEnd);
}
#endif
- manager->lookupFinished(this);
-
// thread goes back to QThreadPool
}
QHostInfoLookupManager::QHostInfoLookupManager() : wasDeleted(false)
{
- moveToThread(QCoreApplicationPrivate::mainThread());
#if QT_CONFIG(thread)
- connect(QCoreApplication::instance(), SIGNAL(destroyed()), SLOT(waitForThreadPoolDone()), Qt::DirectConnection);
+ QObject::connect(QCoreApplication::instance(), &QObject::destroyed,
+ &threadPool, [&](QObject *) { threadPool.waitForDone(); },
+ Qt::DirectConnection);
threadPool.setMaxThreadCount(20); // do up to 20 DNS lookups in parallel
#endif
}
QHostInfoLookupManager::~QHostInfoLookupManager()
{
+ QMutexLocker locker(&mutex);
wasDeleted = true;
+ locker.unlock();
// don't qDeleteAll currentLookups, the QThreadPool has ownership
clear();
@@ -928,7 +977,8 @@ void QHostInfoLookupManager::clear()
cache.clear();
}
-void QHostInfoLookupManager::work()
+// assumes mutex is locked by caller
+void QHostInfoLookupManager::rescheduleWithMutexHeld()
{
if (wasDeleted)
return;
@@ -937,8 +987,6 @@ void QHostInfoLookupManager::work()
// - launch new lookups via the thread pool
// - make sure only one lookup per host/IP is in progress
- QMutexLocker locker(&mutex);
-
if (!finishedLookups.isEmpty()) {
// remove ID from aborted if it is in there
for (int i = 0; i < finishedLookups.length(); i++) {
@@ -950,7 +998,7 @@ void QHostInfoLookupManager::work()
#if QT_CONFIG(thread)
auto isAlreadyRunning = [this](QHostInfoRunnable *lookup) {
- return any_of(currentLookups.cbegin(), currentLookups.cend(), ToBeLookedUpEquals(lookup->toBeLookedUp));
+ return std::any_of(currentLookups.cbegin(), currentLookups.cend(), ToBeLookedUpEquals(lookup->toBeLookedUp));
};
// Transfer any postponed lookups that aren't currently running to the scheduled list, keeping already-running lookups:
@@ -990,22 +1038,23 @@ void QHostInfoLookupManager::work()
// called by QHostInfo
void QHostInfoLookupManager::scheduleLookup(QHostInfoRunnable *r)
{
+ QMutexLocker locker(&this->mutex);
+
if (wasDeleted)
return;
- QMutexLocker locker(&this->mutex);
scheduledLookups.enqueue(r);
- work();
+ rescheduleWithMutexHeld();
}
// called by QHostInfo
void QHostInfoLookupManager::abortLookup(int id)
{
+ QMutexLocker locker(&this->mutex);
+
if (wasDeleted)
return;
- QMutexLocker locker(&this->mutex);
-
#if QT_CONFIG(thread)
// is postponed? delete and return
for (int i = 0; i < postponedLookups.length(); i++) {
@@ -1031,25 +1080,27 @@ void QHostInfoLookupManager::abortLookup(int id)
// called from QHostInfoRunnable
bool QHostInfoLookupManager::wasAborted(int id)
{
+ QMutexLocker locker(&this->mutex);
+
if (wasDeleted)
return true;
- QMutexLocker locker(&this->mutex);
return abortedLookups.contains(id);
}
// called from QHostInfoRunnable
void QHostInfoLookupManager::lookupFinished(QHostInfoRunnable *r)
{
+ QMutexLocker locker(&this->mutex);
+
if (wasDeleted)
return;
- QMutexLocker locker(&this->mutex);
#if QT_CONFIG(thread)
currentLookups.removeOne(r);
#endif
finishedLookups.append(r);
- work();
+ rescheduleWithMutexHeld();
}
// This function returns immediately when we had a result in the cache, else it will later emit a signal
@@ -1059,7 +1110,7 @@ QHostInfo qt_qhostinfo_lookup(const QString &name, QObject *receiver, const char
*id = -1;
// check cache
- QAbstractHostInfoLookupManager* manager = theHostInfoLookupManager();
+ QHostInfoLookupManager* manager = theHostInfoLookupManager();
if (manager && manager->cache.isEnabled()) {
QHostInfo info = manager->cache.get(name, valid);
if (*valid) {
@@ -1076,7 +1127,7 @@ QHostInfo qt_qhostinfo_lookup(const QString &name, QObject *receiver, const char
void qt_qhostinfo_clear_cache()
{
- QAbstractHostInfoLookupManager* manager = theHostInfoLookupManager();
+ QHostInfoLookupManager* manager = theHostInfoLookupManager();
if (manager) {
manager->clear();
}
@@ -1085,7 +1136,7 @@ void qt_qhostinfo_clear_cache()
#ifdef QT_BUILD_INTERNAL
void Q_AUTOTEST_EXPORT qt_qhostinfo_enable_cache(bool e)
{
- QAbstractHostInfoLookupManager* manager = theHostInfoLookupManager();
+ QHostInfoLookupManager* manager = theHostInfoLookupManager();
if (manager) {
manager->cache.setEnabled(e);
}
@@ -1093,7 +1144,7 @@ void Q_AUTOTEST_EXPORT qt_qhostinfo_enable_cache(bool e)
void qt_qhostinfo_cache_inject(const QString &hostname, const QHostInfo &resolution)
{
- QAbstractHostInfoLookupManager* manager = theHostInfoLookupManager();
+ QHostInfoLookupManager* manager = theHostInfoLookupManager();
if (!manager || !manager->cache.isEnabled())
return;
@@ -1106,23 +1157,10 @@ void qt_qhostinfo_cache_inject(const QString &hostname, const QHostInfo &resolut
QHostInfoCache::QHostInfoCache() : max_age(60), enabled(true), cache(128)
{
#ifdef QT_QHOSTINFO_CACHE_DISABLED_BY_DEFAULT
- enabled = false;
+ enabled.store(false, std::memory_order_relaxed);
#endif
}
-bool QHostInfoCache::isEnabled()
-{
- return enabled;
-}
-
-// this function is currently only used for the auto tests
-// and not usable by public API
-void QHostInfoCache::setEnabled(bool e)
-{
- enabled = e;
-}
-
-
QHostInfo QHostInfoCache::get(const QString &name, bool *valid)
{
QMutexLocker locker(&this->mutex);
@@ -1162,9 +1200,4 @@ void QHostInfoCache::clear()
cache.clear();
}
-QAbstractHostInfoLookupManager* QAbstractHostInfoLookupManager::globalInstance()
-{
- return theHostInfoLookupManager();
-}
-
QT_END_NAMESPACE
diff --git a/src/network/kernel/qhostinfo.h b/src/network/kernel/qhostinfo.h
index dc31cc08e4..cda286b423 100644
--- a/src/network/kernel/qhostinfo.h
+++ b/src/network/kernel/qhostinfo.h
@@ -62,11 +62,12 @@ public:
explicit QHostInfo(int lookupId = -1);
QHostInfo(const QHostInfo &d);
+ QHostInfo(QHostInfo &&other) noexcept : d_ptr(qExchange(other.d_ptr, nullptr)) {}
QHostInfo &operator=(const QHostInfo &d);
QHostInfo &operator=(QHostInfo &&other) noexcept { swap(other); return *this; }
~QHostInfo();
- void swap(QHostInfo &other) noexcept { qSwap(d, other.d); }
+ void swap(QHostInfo &other) noexcept { qSwap(d_ptr, other.d_ptr); }
QString hostName() const;
void setHostName(const QString &name);
@@ -147,7 +148,8 @@ public:
#endif // Q_QDOC
private:
- QScopedPointer<QHostInfoPrivate> d;
+ QHostInfoPrivate *d_ptr;
+ Q_DECLARE_PRIVATE(QHostInfo)
static int lookupHostImpl(const QString &name,
const QObject *receiver,
diff --git a/src/network/kernel/qhostinfo_p.h b/src/network/kernel/qhostinfo_p.h
index 7df3f5414c..9a4657234e 100644
--- a/src/network/kernel/qhostinfo_p.h
+++ b/src/network/kernel/qhostinfo_p.h
@@ -73,6 +73,7 @@
#include <QNetworkSession>
#include <QSharedPointer>
+#include <atomic>
QT_BEGIN_NAMESPACE
@@ -83,12 +84,14 @@ class QHostInfoResult : public QObject
QPointer<const QObject> receiver = nullptr;
QtPrivate::QSlotObjectBase *slotObj = nullptr;
+ const bool withContextObject = false;
public:
QHostInfoResult() = default;
QHostInfoResult(const QObject *receiver, QtPrivate::QSlotObjectBase *slotObj) :
receiver(receiver),
- slotObj(slotObj)
+ slotObj(slotObj),
+ withContextObject(slotObj && receiver)
{
connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, this,
&QObject::deleteLater);
@@ -96,10 +99,15 @@ public:
moveToThread(receiver->thread());
}
+ void postResultsReady(const QHostInfo &info);
+
public Q_SLOTS:
inline void emitResultsReady(const QHostInfo &info)
{
if (slotObj) {
+ // we used to have a context object, but it's already destroyed
+ if (withContextObject && !receiver)
+ return;
QHostInfo copy = info;
void *args[2] = { nullptr, reinterpret_cast<void *>(&copy) };
slotObj->call(const_cast<QObject*>(receiver.data()), args);
@@ -177,10 +185,12 @@ public:
void put(const QString &name, const QHostInfo &info);
void clear();
- bool isEnabled();
- void setEnabled(bool e);
+ bool isEnabled() { return enabled.load(std::memory_order_relaxed); }
+ // this function is currently only used for the auto tests
+ // and not usable by public API
+ void setEnabled(bool e) { enabled.store(e, std::memory_order_relaxed); }
private:
- bool enabled;
+ std::atomic<bool> enabled;
struct QHostInfoCacheElement {
QHostInfo info;
QElapsedTimer age;
@@ -205,31 +215,13 @@ public:
};
-class QAbstractHostInfoLookupManager : public QObject
-{
- Q_OBJECT
-
-public:
- ~QAbstractHostInfoLookupManager() {}
- virtual void clear() = 0;
-
- QHostInfoCache cache;
-
-protected:
- QAbstractHostInfoLookupManager() {}
- static QAbstractHostInfoLookupManager* globalInstance();
-
-};
-
-class QHostInfoLookupManager : public QAbstractHostInfoLookupManager
+class QHostInfoLookupManager
{
- Q_OBJECT
public:
QHostInfoLookupManager();
~QHostInfoLookupManager();
- void clear() override;
- void work();
+ void clear();
// called from QHostInfo
void scheduleLookup(QHostInfoRunnable *r);
@@ -239,6 +231,8 @@ public:
void lookupFinished(QHostInfoRunnable *r);
bool wasAborted(int id);
+ QHostInfoCache cache;
+
friend class QHostInfoRunnable;
protected:
#if QT_CONFIG(thread)
@@ -252,14 +246,12 @@ protected:
#if QT_CONFIG(thread)
QThreadPool threadPool;
#endif
- QRecursiveMutex mutex;
+ QMutex mutex;
bool wasDeleted;
-private slots:
-#if QT_CONFIG(thread)
- void waitForThreadPoolDone() { threadPool.waitForDone(); }
-#endif
+private:
+ void rescheduleWithMutexHeld();
};
QT_END_NAMESPACE
diff --git a/src/network/kernel/qnetconmonitor_darwin.mm b/src/network/kernel/qnetconmonitor_darwin.mm
index a64cd6e530..f6daf9ed50 100644
--- a/src/network/kernel/qnetconmonitor_darwin.mm
+++ b/src/network/kernel/qnetconmonitor_darwin.mm
@@ -376,7 +376,7 @@ bool QNetworkStatusMonitor::isMonitoring() const
return d->ipv4Probe.isMonitoring() || d->ipv6Probe.isMonitoring();
}
-bool QNetworkStatusMonitor::isNetworkAccesible()
+bool QNetworkStatusMonitor::isNetworkAccessible()
{
// This function is to be executed on the thread that created
// and uses 'this'.
diff --git a/src/network/kernel/qnetconmonitor_p.h b/src/network/kernel/qnetconmonitor_p.h
index 74ee56d422..282bac5081 100644
--- a/src/network/kernel/qnetconmonitor_p.h
+++ b/src/network/kernel/qnetconmonitor_p.h
@@ -61,7 +61,7 @@
QT_BEGIN_NAMESPACE
class QNetworkConnectionMonitorPrivate;
-class QNetworkConnectionMonitor : public QObject
+class Q_AUTOTEST_EXPORT QNetworkConnectionMonitor : public QObject
{
Q_OBJECT
@@ -91,7 +91,7 @@ private:
};
class QNetworkStatusMonitorPrivate;
-class QNetworkStatusMonitor : public QObject
+class Q_AUTOTEST_EXPORT QNetworkStatusMonitor : public QObject
{
Q_OBJECT
@@ -99,7 +99,7 @@ public:
QNetworkStatusMonitor();
~QNetworkStatusMonitor();
- bool isNetworkAccesible();
+ bool isNetworkAccessible();
bool start();
void stop();
diff --git a/src/network/kernel/qnetconmonitor_stub.cpp b/src/network/kernel/qnetconmonitor_stub.cpp
index 7f3a0c44c6..1ad4e9ba5a 100644
--- a/src/network/kernel/qnetconmonitor_stub.cpp
+++ b/src/network/kernel/qnetconmonitor_stub.cpp
@@ -123,7 +123,7 @@ bool QNetworkStatusMonitor::isMonitoring() const
return false;
}
-bool QNetworkStatusMonitor::isNetworkAccesible()
+bool QNetworkStatusMonitor::isNetworkAccessible()
{
return false;
}
diff --git a/src/network/kernel/qnetconmonitor_win.cpp b/src/network/kernel/qnetconmonitor_win.cpp
new file mode 100644
index 0000000000..b543508169
--- /dev/null
+++ b/src/network/kernel/qnetconmonitor_win.cpp
@@ -0,0 +1,710 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtNetwork module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qnetconmonitor_p.h"
+
+#include "private/qobject_p.h"
+
+#include <QtCore/quuid.h>
+#include <QtCore/qmetaobject.h>
+
+#include <QtNetwork/qnetworkinterface.h>
+
+#include <objbase.h>
+#include <netlistmgr.h>
+#include <wrl/client.h>
+#include <wrl/wrappers/corewrappers.h>
+#include <comdef.h>
+#include <iphlpapi.h>
+
+#include <algorithm>
+
+using namespace Microsoft::WRL;
+
+QT_BEGIN_NAMESPACE
+
+Q_LOGGING_CATEGORY(lcNetMon, "qt.network.monitor");
+
+namespace {
+QString errorStringFromHResult(HRESULT hr)
+{
+ _com_error error(hr);
+ return QString::fromWCharArray(error.ErrorMessage());
+}
+
+template<typename T>
+bool QueryInterfaceImpl(IUnknown *from, REFIID riid, void **ppvObject)
+{
+ if (riid == __uuidof(T)) {
+ *ppvObject = static_cast<T *>(from);
+ from->AddRef();
+ return true;
+ }
+ return false;
+}
+
+QNetworkInterface getInterfaceFromHostAddress(const QHostAddress &local)
+{
+ QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
+ auto it = std::find_if(
+ interfaces.cbegin(), interfaces.cend(), [&local](const QNetworkInterface &iface) {
+ const auto &entries = iface.addressEntries();
+ return std::any_of(entries.cbegin(), entries.cend(),
+ [&local](const QNetworkAddressEntry &entry) {
+ return entry.ip().isEqual(local,
+ QHostAddress::TolerantConversion);
+ });
+ });
+ if (it == interfaces.cend()) {
+ qCWarning(lcNetMon, "Could not find the interface for the local address.");
+ return {};
+ }
+ return *it;
+}
+} // anonymous namespace
+
+class QNetworkConnectionEvents final : public INetworkConnectionEvents
+{
+public:
+ QNetworkConnectionEvents(QNetworkConnectionMonitorPrivate *monitor);
+ ~QNetworkConnectionEvents();
+
+ HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) override;
+
+ ULONG STDMETHODCALLTYPE AddRef() override { return ++ref; }
+ ULONG STDMETHODCALLTYPE Release() override
+ {
+ if (--ref == 0) {
+ delete this;
+ return 0;
+ }
+ return ref;
+ }
+
+ HRESULT STDMETHODCALLTYPE
+ NetworkConnectionConnectivityChanged(GUID connectionId, NLM_CONNECTIVITY connectivity) override;
+ HRESULT STDMETHODCALLTYPE NetworkConnectionPropertyChanged(
+ GUID connectionId, NLM_CONNECTION_PROPERTY_CHANGE flags) override;
+
+ Q_REQUIRED_RESULT
+ bool setTarget(const QNetworkInterface &iface);
+ Q_REQUIRED_RESULT
+ bool startMonitoring();
+ Q_REQUIRED_RESULT
+ bool stopMonitoring();
+
+private:
+ ComPtr<INetworkConnection> getNetworkConnectionFromAdapterGuid(QUuid guid);
+
+ QUuid currentConnectionId{};
+
+ ComPtr<INetworkListManager> networkListManager;
+ ComPtr<IConnectionPoint> connectionPoint;
+
+ QNetworkConnectionMonitorPrivate *monitor = nullptr;
+
+ QAtomicInteger<ULONG> ref = 1; // start at 1 for our own initial reference
+ DWORD cookie = 0;
+};
+
+class QNetworkConnectionMonitorPrivate : public QObjectPrivate
+{
+ Q_DECLARE_PUBLIC(QNetworkConnectionMonitor);
+
+public:
+ QNetworkConnectionMonitorPrivate();
+ ~QNetworkConnectionMonitorPrivate();
+
+ Q_REQUIRED_RESULT
+ bool setTargets(const QHostAddress &local, const QHostAddress &remote);
+ Q_REQUIRED_RESULT
+ bool startMonitoring();
+ void stopMonitoring();
+
+ void setConnectivity(NLM_CONNECTIVITY newConnectivity);
+
+private:
+ ComPtr<QNetworkConnectionEvents> connectionEvents;
+ // We can assume we have access to internet/subnet when this class is created because
+ // connection has already been established to the peer:
+ NLM_CONNECTIVITY connectivity =
+ NLM_CONNECTIVITY(NLM_CONNECTIVITY_IPV4_INTERNET | NLM_CONNECTIVITY_IPV6_INTERNET
+ | NLM_CONNECTIVITY_IPV4_SUBNET | NLM_CONNECTIVITY_IPV6_SUBNET);
+
+ bool sameSubnet = false;
+ bool monitoring = false;
+ bool comInitFailed = false;
+ bool remoteIsIPv6 = false;
+};
+
+QNetworkConnectionEvents::QNetworkConnectionEvents(QNetworkConnectionMonitorPrivate *monitor)
+ : monitor(monitor)
+{
+ auto hr = CoCreateInstance(CLSID_NetworkListManager, nullptr, CLSCTX_INPROC_SERVER,
+ IID_INetworkListManager, &networkListManager);
+ if (FAILED(hr)) {
+ qCWarning(lcNetMon) << "Could not get a NetworkListManager instance:"
+ << errorStringFromHResult(hr);
+ return;
+ }
+
+ ComPtr<IConnectionPointContainer> connectionPointContainer;
+ hr = networkListManager.As(&connectionPointContainer);
+ if (SUCCEEDED(hr)) {
+ hr = connectionPointContainer->FindConnectionPoint(IID_INetworkConnectionEvents,
+ &connectionPoint);
+ }
+ if (FAILED(hr)) {
+ qCWarning(lcNetMon) << "Failed to get connection point for network events:"
+ << errorStringFromHResult(hr);
+ }
+}
+
+QNetworkConnectionEvents::~QNetworkConnectionEvents()
+{
+ Q_ASSERT(ref == 0);
+}
+
+ComPtr<INetworkConnection> QNetworkConnectionEvents::getNetworkConnectionFromAdapterGuid(QUuid guid)
+{
+ ComPtr<IEnumNetworkConnections> connections;
+ auto hr = networkListManager->GetNetworkConnections(connections.GetAddressOf());
+ if (FAILED(hr)) {
+ qCWarning(lcNetMon) << "Failed to enumerate network connections:"
+ << errorStringFromHResult(hr);
+ return nullptr;
+ }
+ ComPtr<INetworkConnection> connection = nullptr;
+ do {
+ hr = connections->Next(1, connection.GetAddressOf(), nullptr);
+ if (FAILED(hr)) {
+ qCWarning(lcNetMon) << "Failed to get next network connection in enumeration:"
+ << errorStringFromHResult(hr);
+ break;
+ }
+ if (connection) {
+ GUID adapterId;
+ hr = connection->GetAdapterId(&adapterId);
+ if (FAILED(hr)) {
+ qCWarning(lcNetMon) << "Failed to get adapter ID from network connection:"
+ << errorStringFromHResult(hr);
+ continue;
+ }
+ if (guid == adapterId)
+ return connection;
+ }
+ } while (connection);
+ return nullptr;
+}
+
+HRESULT STDMETHODCALLTYPE QNetworkConnectionEvents::QueryInterface(REFIID riid, void **ppvObject)
+{
+ if (!ppvObject)
+ return E_INVALIDARG;
+
+ return QueryInterfaceImpl<IUnknown>(this, riid, ppvObject)
+ || QueryInterfaceImpl<INetworkConnectionEvents>(this, riid, ppvObject)
+ ? S_OK
+ : E_NOINTERFACE;
+}
+
+HRESULT STDMETHODCALLTYPE QNetworkConnectionEvents::NetworkConnectionConnectivityChanged(
+ GUID connectionId, NLM_CONNECTIVITY newConnectivity)
+{
+ // This function is run on a different thread than 'monitor' is created on, so we need to run
+ // it on that thread
+ QMetaObject::invokeMethod(monitor->q_ptr,
+ [this, connectionId, newConnectivity, monitor = this->monitor]() {
+ if (connectionId == currentConnectionId)
+ monitor->setConnectivity(newConnectivity);
+ },
+ Qt::QueuedConnection);
+ return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE QNetworkConnectionEvents::NetworkConnectionPropertyChanged(
+ GUID connectionId, NLM_CONNECTION_PROPERTY_CHANGE flags)
+{
+ Q_UNUSED(connectionId);
+ Q_UNUSED(flags);
+ return E_NOTIMPL;
+}
+
+bool QNetworkConnectionEvents::setTarget(const QNetworkInterface &iface)
+{
+ // Unset this in case it's already set to something
+ currentConnectionId = QUuid{};
+
+ NET_LUID luid;
+ if (ConvertInterfaceIndexToLuid(iface.index(), &luid) != NO_ERROR) {
+ qCWarning(lcNetMon, "Could not get the LUID for the interface.");
+ return false;
+ }
+ GUID guid;
+ if (ConvertInterfaceLuidToGuid(&luid, &guid) != NO_ERROR) {
+ qCWarning(lcNetMon, "Could not get the GUID for the interface.");
+ return false;
+ }
+ ComPtr<INetworkConnection> connection = getNetworkConnectionFromAdapterGuid(guid);
+ if (!connection) {
+ qCWarning(lcNetMon, "Could not get the INetworkConnection instance for the adapter GUID.");
+ return false;
+ }
+ auto hr = connection->GetConnectionId(&guid);
+ if (FAILED(hr)) {
+ qCWarning(lcNetMon) << "Failed to get the connection's GUID:" << errorStringFromHResult(hr);
+ return false;
+ }
+ currentConnectionId = guid;
+
+ return true;
+}
+
+bool QNetworkConnectionEvents::startMonitoring()
+{
+ if (currentConnectionId.isNull()) {
+ qCWarning(lcNetMon, "Can not start monitoring, set targets first");
+ return false;
+ }
+ if (!connectionPoint) {
+ qCWarning(lcNetMon,
+ "We don't have the connection point, cannot start listening to events!");
+ return false;
+ }
+
+ auto hr = connectionPoint->Advise(this, &cookie);
+ if (FAILED(hr)) {
+ qCWarning(lcNetMon) << "Failed to subscribe to network connectivity events:"
+ << errorStringFromHResult(hr);
+ return false;
+ }
+ return true;
+}
+
+bool QNetworkConnectionEvents::stopMonitoring()
+{
+ auto hr = connectionPoint->Unadvise(cookie);
+ if (FAILED(hr)) {
+ qCWarning(lcNetMon) << "Failed to unsubscribe from network connection events:"
+ << errorStringFromHResult(hr);
+ return false;
+ }
+ cookie = 0;
+ currentConnectionId = QUuid{};
+ return true;
+}
+
+QNetworkConnectionMonitorPrivate::QNetworkConnectionMonitorPrivate()
+{
+ auto hr = CoInitialize(nullptr);
+ if (FAILED(hr)) {
+ qCWarning(lcNetMon) << "Failed to initialize COM:" << errorStringFromHResult(hr);
+ comInitFailed = true;
+ return;
+ }
+
+ connectionEvents = new QNetworkConnectionEvents(this);
+}
+
+QNetworkConnectionMonitorPrivate::~QNetworkConnectionMonitorPrivate()
+{
+ if (comInitFailed)
+ return;
+ connectionEvents.Reset();
+ CoUninitialize();
+}
+
+bool QNetworkConnectionMonitorPrivate::setTargets(const QHostAddress &local,
+ const QHostAddress &remote)
+{
+ if (comInitFailed)
+ return false;
+
+ QNetworkInterface iface = getInterfaceFromHostAddress(local);
+ if (!iface.isValid())
+ return false;
+ const auto &addressEntries = iface.addressEntries();
+ auto it = std::find_if(
+ addressEntries.cbegin(), addressEntries.cend(),
+ [&local](const QNetworkAddressEntry &entry) { return entry.ip() == local; });
+ if (Q_UNLIKELY(it == addressEntries.cend())) {
+ qCWarning(lcNetMon, "The address entry we were working with disappeared");
+ return false;
+ }
+ sameSubnet = remote.isInSubnet(local, it->prefixLength());
+ remoteIsIPv6 = remote.protocol() == QAbstractSocket::IPv6Protocol;
+
+ return connectionEvents->setTarget(iface);
+}
+
+void QNetworkConnectionMonitorPrivate::setConnectivity(NLM_CONNECTIVITY newConnectivity)
+{
+ Q_Q(QNetworkConnectionMonitor);
+ const bool reachable = q->isReachable();
+ connectivity = newConnectivity;
+ const bool newReachable = q->isReachable();
+ if (reachable != newReachable)
+ emit q->reachabilityChanged(newReachable);
+}
+
+bool QNetworkConnectionMonitorPrivate::startMonitoring()
+{
+ Q_ASSERT(connectionEvents);
+ Q_ASSERT(!monitoring);
+ if (connectionEvents->startMonitoring())
+ monitoring = true;
+ return monitoring;
+}
+
+void QNetworkConnectionMonitorPrivate::stopMonitoring()
+{
+ Q_ASSERT(connectionEvents);
+ Q_ASSERT(monitoring);
+ if (connectionEvents->stopMonitoring())
+ monitoring = false;
+}
+
+QNetworkConnectionMonitor::QNetworkConnectionMonitor()
+ : QObject(*new QNetworkConnectionMonitorPrivate)
+{
+}
+
+QNetworkConnectionMonitor::QNetworkConnectionMonitor(const QHostAddress &local,
+ const QHostAddress &remote)
+ : QObject(*new QNetworkConnectionMonitorPrivate)
+{
+ setTargets(local, remote);
+}
+
+QNetworkConnectionMonitor::~QNetworkConnectionMonitor() = default;
+
+bool QNetworkConnectionMonitor::setTargets(const QHostAddress &local, const QHostAddress &remote)
+{
+ if (isMonitoring()) {
+ qCWarning(lcNetMon, "Monitor is already active, call stopMonitoring() first");
+ return false;
+ }
+ if (local.isNull()) {
+ qCWarning(lcNetMon, "Invalid (null) local address, cannot create a reachability target");
+ return false;
+ }
+ // Silently return false for loopback addresses instead of printing warnings later
+ if (remote.isLoopback())
+ return false;
+
+ return d_func()->setTargets(local, remote);
+}
+
+bool QNetworkConnectionMonitor::startMonitoring()
+{
+ Q_D(QNetworkConnectionMonitor);
+ if (isMonitoring()) {
+ qCWarning(lcNetMon, "Monitor is already active, call stopMonitoring() first");
+ return false;
+ }
+ return d->startMonitoring();
+}
+
+bool QNetworkConnectionMonitor::isMonitoring() const
+{
+ return d_func()->monitoring;
+}
+
+void QNetworkConnectionMonitor::stopMonitoring()
+{
+ Q_D(QNetworkConnectionMonitor);
+ if (!isMonitoring()) {
+ qCWarning(lcNetMon, "stopMonitoring was called when not monitoring!");
+ return;
+ }
+ d->stopMonitoring();
+}
+
+bool QNetworkConnectionMonitor::isReachable()
+{
+ Q_D(QNetworkConnectionMonitor);
+ NLM_CONNECTIVITY required = d->sameSubnet
+ ? (d->remoteIsIPv6 ? NLM_CONNECTIVITY_IPV6_SUBNET : NLM_CONNECTIVITY_IPV4_SUBNET)
+ : (d->remoteIsIPv6 ? NLM_CONNECTIVITY_IPV6_INTERNET : NLM_CONNECTIVITY_IPV4_INTERNET);
+ return d_func()->connectivity & required;
+}
+
+class QNetworkListManagerEvents final : public INetworkListManagerEvents
+{
+public:
+ QNetworkListManagerEvents(QNetworkStatusMonitorPrivate *monitor);
+ ~QNetworkListManagerEvents();
+
+ HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) override;
+
+ ULONG STDMETHODCALLTYPE AddRef() override { return ++ref; }
+ ULONG STDMETHODCALLTYPE Release() override
+ {
+ if (--ref == 0) {
+ delete this;
+ return 0;
+ }
+ return ref;
+ }
+
+ HRESULT STDMETHODCALLTYPE ConnectivityChanged(NLM_CONNECTIVITY newConnectivity) override;
+
+ Q_REQUIRED_RESULT
+ bool start();
+ Q_REQUIRED_RESULT
+ bool stop();
+
+private:
+ ComPtr<INetworkListManager> networkListManager = nullptr;
+ ComPtr<IConnectionPoint> connectionPoint = nullptr;
+
+ QNetworkStatusMonitorPrivate *monitor = nullptr;
+
+ QAtomicInteger<ULONG> ref = 1; // start at 1 for our own initial reference
+ DWORD cookie = 0;
+};
+
+class QNetworkStatusMonitorPrivate : public QObjectPrivate
+{
+ Q_DECLARE_PUBLIC(QNetworkStatusMonitor);
+
+public:
+ QNetworkStatusMonitorPrivate();
+ ~QNetworkStatusMonitorPrivate();
+
+ Q_REQUIRED_RESULT
+ bool start();
+ void stop();
+
+ void setConnectivity(NLM_CONNECTIVITY newConnectivity);
+
+private:
+ friend class QNetworkListManagerEvents;
+
+ ComPtr<QNetworkListManagerEvents> managerEvents;
+ NLM_CONNECTIVITY connectivity = NLM_CONNECTIVITY_DISCONNECTED;
+
+ bool monitoring = false;
+ bool comInitFailed = false;
+};
+
+QNetworkListManagerEvents::QNetworkListManagerEvents(QNetworkStatusMonitorPrivate *monitor)
+ : monitor(monitor)
+{
+ auto hr = CoCreateInstance(CLSID_NetworkListManager, nullptr, CLSCTX_INPROC_SERVER,
+ IID_INetworkListManager, &networkListManager);
+ if (FAILED(hr)) {
+ qCWarning(lcNetMon) << "Could not get a NetworkListManager instance:"
+ << errorStringFromHResult(hr);
+ return;
+ }
+
+ // Set initial connectivity
+ hr = networkListManager->GetConnectivity(&monitor->connectivity);
+ if (FAILED(hr))
+ qCWarning(lcNetMon) << "Could not get connectivity:" << errorStringFromHResult(hr);
+
+ ComPtr<IConnectionPointContainer> connectionPointContainer;
+ hr = networkListManager.As(&connectionPointContainer);
+ if (SUCCEEDED(hr)) {
+ hr = connectionPointContainer->FindConnectionPoint(IID_INetworkListManagerEvents,
+ &connectionPoint);
+ }
+ if (FAILED(hr)) {
+ qCWarning(lcNetMon) << "Failed to get connection point for network list manager events:"
+ << errorStringFromHResult(hr);
+ }
+}
+
+QNetworkListManagerEvents::~QNetworkListManagerEvents()
+{
+ Q_ASSERT(ref == 0);
+}
+
+HRESULT STDMETHODCALLTYPE QNetworkListManagerEvents::QueryInterface(REFIID riid, void **ppvObject)
+{
+ if (!ppvObject)
+ return E_INVALIDARG;
+
+ return QueryInterfaceImpl<IUnknown>(this, riid, ppvObject)
+ || QueryInterfaceImpl<INetworkListManagerEvents>(this, riid, ppvObject)
+ ? S_OK
+ : E_NOINTERFACE;
+}
+
+HRESULT STDMETHODCALLTYPE
+QNetworkListManagerEvents::ConnectivityChanged(NLM_CONNECTIVITY newConnectivity)
+{
+ // This function is run on a different thread than 'monitor' is created on, so we need to run
+ // it on that thread
+ QMetaObject::invokeMethod(monitor->q_ptr,
+ [newConnectivity, monitor = this->monitor]() {
+ monitor->setConnectivity(newConnectivity);
+ },
+ Qt::QueuedConnection);
+ return S_OK;
+}
+
+bool QNetworkListManagerEvents::start()
+{
+ if (!connectionPoint) {
+ qCWarning(lcNetMon, "Initialization failed, can't start!");
+ return false;
+ }
+ auto hr = connectionPoint->Advise(this, &cookie);
+ if (FAILED(hr)) {
+ qCWarning(lcNetMon) << "Failed to subscribe to network connectivity events:"
+ << errorStringFromHResult(hr);
+ return false;
+ }
+ return true;
+}
+
+bool QNetworkListManagerEvents::stop()
+{
+ Q_ASSERT(connectionPoint);
+ auto hr = connectionPoint->Unadvise(cookie);
+ if (FAILED(hr)) {
+ qCWarning(lcNetMon) << "Failed to unsubscribe from network connectivity events:"
+ << errorStringFromHResult(hr);
+ return false;
+ }
+ cookie = 0;
+ return true;
+}
+
+QNetworkStatusMonitorPrivate::QNetworkStatusMonitorPrivate()
+{
+ auto hr = CoInitialize(nullptr);
+ if (FAILED(hr)) {
+ qCWarning(lcNetMon) << "Failed to initialize COM:" << errorStringFromHResult(hr);
+ comInitFailed = true;
+ return;
+ }
+ managerEvents = new QNetworkListManagerEvents(this);
+}
+
+QNetworkStatusMonitorPrivate::~QNetworkStatusMonitorPrivate()
+{
+ if (comInitFailed)
+ return;
+ if (monitoring)
+ stop();
+ managerEvents.Reset();
+ CoUninitialize();
+}
+
+void QNetworkStatusMonitorPrivate::setConnectivity(NLM_CONNECTIVITY newConnectivity)
+{
+ Q_Q(QNetworkStatusMonitor);
+
+ const bool oldAccessibility = q->isNetworkAccessible();
+ connectivity = newConnectivity;
+ const bool accessibility = q->isNetworkAccessible();
+ if (oldAccessibility != accessibility)
+ emit q->onlineStateChanged(accessibility);
+}
+
+bool QNetworkStatusMonitorPrivate::start()
+{
+ if (comInitFailed)
+ return false;
+ Q_ASSERT(managerEvents);
+ Q_ASSERT(!monitoring);
+ if (managerEvents->start())
+ monitoring = true;
+ return monitoring;
+}
+
+void QNetworkStatusMonitorPrivate::stop()
+{
+ Q_ASSERT(managerEvents);
+ Q_ASSERT(monitoring);
+ if (managerEvents->stop())
+ monitoring = false;
+}
+
+QNetworkStatusMonitor::QNetworkStatusMonitor() : QObject(*new QNetworkStatusMonitorPrivate) {}
+
+QNetworkStatusMonitor::~QNetworkStatusMonitor() {}
+
+bool QNetworkStatusMonitor::start()
+{
+ if (isMonitoring()) {
+ qCWarning(lcNetMon, "Monitor is already active, call stopMonitoring() first");
+ return false;
+ }
+
+ return d_func()->start();
+}
+
+void QNetworkStatusMonitor::stop()
+{
+ if (!isMonitoring()) {
+ qCWarning(lcNetMon, "stopMonitoring was called when not monitoring!");
+ return;
+ }
+
+ d_func()->stop();
+}
+
+bool QNetworkStatusMonitor::isMonitoring() const
+{
+ return d_func()->monitoring;
+}
+
+bool QNetworkStatusMonitor::isNetworkAccessible()
+{
+ return d_func()->connectivity
+ & (NLM_CONNECTIVITY_IPV4_INTERNET | NLM_CONNECTIVITY_IPV6_INTERNET
+ | NLM_CONNECTIVITY_IPV4_SUBNET | NLM_CONNECTIVITY_IPV6_SUBNET);
+}
+
+bool QNetworkStatusMonitor::isEnabled()
+{
+ return true;
+}
+
+void QNetworkStatusMonitor::reachabilityChanged(bool online)
+{
+ Q_UNUSED(online);
+ Q_UNREACHABLE();
+}
+
+QT_END_NAMESPACE
diff --git a/src/network/socket/qhttpsocketengine.cpp b/src/network/socket/qhttpsocketengine.cpp
index 6cae29193d..c67b273937 100644
--- a/src/network/socket/qhttpsocketengine.cpp
+++ b/src/network/socket/qhttpsocketengine.cpp
@@ -627,7 +627,7 @@ void QHttpSocketEngine::slotSocketReadNotification()
// from http spec is also allowed.
if (proxyConnectionHeader.isEmpty())
proxyConnectionHeader = d->reply->headerField("Connection");
- if (proxyConnectionHeader.compare("close", Qt::CaseSensitive) == 0) {
+ if (proxyConnectionHeader.compare("close", Qt::CaseInsensitive) == 0) {
willClose = true;
} else if (proxyConnectionHeader.compare("keep-alive", Qt::CaseInsensitive) == 0) {
willClose = false;
diff --git a/src/network/socket/qnativesocketengine_unix.cpp b/src/network/socket/qnativesocketengine_unix.cpp
index 24c17124dc..3ca586e247 100644
--- a/src/network/socket/qnativesocketengine_unix.cpp
+++ b/src/network/socket/qnativesocketengine_unix.cpp
@@ -1000,8 +1000,11 @@ qint64 QNativeSocketEnginePrivate::nativeReceiveDatagram(char *data, qint64 maxS
// parse the ancillary data
struct cmsghdr *cmsgptr;
+ QT_WARNING_PUSH
+ QT_WARNING_DISABLE_CLANG("-Wsign-compare")
for (cmsgptr = CMSG_FIRSTHDR(&msg); cmsgptr != NULL;
cmsgptr = CMSG_NXTHDR(&msg, cmsgptr)) {
+ QT_WARNING_POP
if (cmsgptr->cmsg_level == IPPROTO_IPV6 && cmsgptr->cmsg_type == IPV6_PKTINFO
&& cmsgptr->cmsg_len >= CMSG_LEN(sizeof(in6_pktinfo))) {
in6_pktinfo *info = reinterpret_cast<in6_pktinfo *>(CMSG_DATA(cmsgptr));
diff --git a/src/network/socket/qnativesocketengine_win.cpp b/src/network/socket/qnativesocketengine_win.cpp
index b429b3c365..9edabd7822 100644
--- a/src/network/socket/qnativesocketengine_win.cpp
+++ b/src/network/socket/qnativesocketengine_win.cpp
@@ -623,6 +623,53 @@ bool QNativeSocketEnginePrivate::fetchConnectionParameters()
}
+static void setErrorFromWSAError(int error, QNativeSocketEnginePrivate *d)
+{
+ Q_ASSERT(d);
+ switch (error) {
+ case WSAEISCONN:
+ d->socketState = QAbstractSocket::ConnectedState;
+ break;
+ case WSAEHOSTUNREACH:
+ d->setError(QAbstractSocket::NetworkError, QNativeSocketEnginePrivate::HostUnreachableErrorString);
+ d->socketState = QAbstractSocket::UnconnectedState;
+ break;
+ case WSAEADDRNOTAVAIL:
+ d->setError(QAbstractSocket::NetworkError, QNativeSocketEnginePrivate::AddressNotAvailableErrorString);
+ d->socketState = QAbstractSocket::UnconnectedState;
+ break;
+ case WSAEINPROGRESS:
+ d->setError(QAbstractSocket::UnfinishedSocketOperationError, QNativeSocketEnginePrivate::InvalidSocketErrorString);
+ d->socketState = QAbstractSocket::ConnectingState;
+ break;
+ case WSAEADDRINUSE:
+ d->setError(QAbstractSocket::NetworkError, QNativeSocketEnginePrivate::AddressInuseErrorString);
+ break;
+ case WSAECONNREFUSED:
+ d->setError(QAbstractSocket::ConnectionRefusedError, QNativeSocketEnginePrivate::ConnectionRefusedErrorString);
+ d->socketState = QAbstractSocket::UnconnectedState;
+ break;
+ case WSAETIMEDOUT:
+ d->setError(QAbstractSocket::NetworkError, QNativeSocketEnginePrivate::ConnectionTimeOutErrorString);
+ d->socketState = QAbstractSocket::UnconnectedState;
+ break;
+ case WSAEACCES:
+ d->setError(QAbstractSocket::SocketAccessError, QNativeSocketEnginePrivate::AccessErrorString);
+ d->socketState = QAbstractSocket::UnconnectedState;
+ break;
+ case WSAENETUNREACH:
+ d->setError(QAbstractSocket::NetworkError, QNativeSocketEnginePrivate::NetworkUnreachableErrorString);
+ d->socketState = QAbstractSocket::UnconnectedState;
+ break;
+ case WSAEINVAL:
+ case WSAEALREADY:
+ d->setError(QAbstractSocket::UnfinishedSocketOperationError, QNativeSocketEnginePrivate::InvalidSocketErrorString);
+ break;
+ default:
+ break;
+ }
+}
+
bool QNativeSocketEnginePrivate::nativeConnect(const QHostAddress &address, quint16 port)
{
@@ -651,9 +698,6 @@ bool QNativeSocketEnginePrivate::nativeConnect(const QHostAddress &address, quin
case WSANOTINITIALISED:
//###
break;
- case WSAEISCONN:
- socketState = QAbstractSocket::ConnectedState;
- break;
case WSAEWOULDBLOCK: {
// If WSAConnect returns WSAEWOULDBLOCK on the second
// connection attempt, we have to check SO_ERROR's
@@ -668,82 +712,33 @@ bool QNativeSocketEnginePrivate::nativeConnect(const QHostAddress &address, quin
do {
if (::getsockopt(socketDescriptor, SOL_SOCKET, SO_ERROR, (char *) &value, &valueSize) == 0) {
if (value != NOERROR) {
+ WS_ERROR_DEBUG(value);
+ errorDetected = true;
// MSDN says getsockopt with SO_ERROR clears the error, but it's not actually cleared
// and this can affect all subsequent WSAConnect attempts, so clear it now.
const int val = NO_ERROR;
::setsockopt(socketDescriptor, SOL_SOCKET, SO_ERROR, reinterpret_cast<const char*>(&val), sizeof val);
- }
-
- if (value == WSAECONNREFUSED) {
- setError(QAbstractSocket::ConnectionRefusedError, ConnectionRefusedErrorString);
- socketState = QAbstractSocket::UnconnectedState;
- errorDetected = true;
- break;
- }
- if (value == WSAETIMEDOUT) {
- setError(QAbstractSocket::NetworkError, ConnectionTimeOutErrorString);
- socketState = QAbstractSocket::UnconnectedState;
- errorDetected = true;
- break;
- }
- if (value == WSAEHOSTUNREACH) {
- setError(QAbstractSocket::NetworkError, HostUnreachableErrorString);
- socketState = QAbstractSocket::UnconnectedState;
- errorDetected = true;
- break;
- }
- if (value == WSAEADDRNOTAVAIL) {
- setError(QAbstractSocket::NetworkError, AddressNotAvailableErrorString);
- socketState = QAbstractSocket::UnconnectedState;
- errorDetected = true;
- break;
- }
- if (value == NOERROR) {
+ } else {
// When we get WSAEWOULDBLOCK the outcome was not known, so a
// NOERROR might indicate that the result of the operation
// is still unknown. We try again to increase the chance that we did
// get the correct result.
tryAgain = !tryAgain;
}
+ setErrorFromWSAError(value, this);
}
tries++;
} while (tryAgain && (tries < 2));
if (errorDetected)
break;
+ // fall through to unfinished operation error handling
+ err = WSAEINPROGRESS;
Q_FALLTHROUGH();
}
- case WSAEINPROGRESS:
- setError(QAbstractSocket::UnfinishedSocketOperationError, InvalidSocketErrorString);
- socketState = QAbstractSocket::ConnectingState;
- break;
- case WSAEADDRINUSE:
- setError(QAbstractSocket::NetworkError, AddressInuseErrorString);
- break;
- case WSAECONNREFUSED:
- setError(QAbstractSocket::ConnectionRefusedError, ConnectionRefusedErrorString);
- socketState = QAbstractSocket::UnconnectedState;
- break;
- case WSAETIMEDOUT:
- setError(QAbstractSocket::NetworkError, ConnectionTimeOutErrorString);
- break;
- case WSAEACCES:
- setError(QAbstractSocket::SocketAccessError, AccessErrorString);
- socketState = QAbstractSocket::UnconnectedState;
- break;
- case WSAEHOSTUNREACH:
- setError(QAbstractSocket::NetworkError, HostUnreachableErrorString);
- socketState = QAbstractSocket::UnconnectedState;
- break;
- case WSAENETUNREACH:
- setError(QAbstractSocket::NetworkError, NetworkUnreachableErrorString);
- socketState = QAbstractSocket::UnconnectedState;
- break;
- case WSAEINVAL:
- case WSAEALREADY:
- setError(QAbstractSocket::UnfinishedSocketOperationError, InvalidSocketErrorString);
- break;
+
default:
+ setErrorFromWSAError(err, this);
break;
}
if (socketState != QAbstractSocket::ConnectedState) {
diff --git a/src/network/ssl/qsslcertificate_openssl.cpp b/src/network/ssl/qsslcertificate_openssl.cpp
index 806c6426e4..6f1fb26add 100644
--- a/src/network/ssl/qsslcertificate_openssl.cpp
+++ b/src/network/ssl/qsslcertificate_openssl.cpp
@@ -45,12 +45,19 @@
#include "qsslcertificateextension_p.h"
#include <QtCore/qendian.h>
+#include <QtCore/qmutex.h>
-#if QT_CONFIG(thread)
-#include <QtCore/private/qmutexpool_p.h>
-#endif
QT_BEGIN_NAMESPACE
+Q_CONSTEXPR int MutexPoolSize = 17;
+static QBasicMutex mutexPool[MutexPoolSize];
+namespace QMutexPool {
+ static QBasicMutex *globalInstanceGet(const void *addr)
+ {
+ return mutexPool + (quintptr(addr) % MutexPoolSize);
+ }
+}
+
// forward declaration
static QMultiMap<QByteArray, QString> _q_mapFromX509Name(X509_NAME *name);
diff --git a/src/network/ssl/qsslsocket_mac.cpp b/src/network/ssl/qsslsocket_mac.cpp
index 487e975db6..1725937bc2 100644
--- a/src/network/ssl/qsslsocket_mac.cpp
+++ b/src/network/ssl/qsslsocket_mac.cpp
@@ -215,7 +215,7 @@ void QSecureTransportContext::reset(SSLContextRef newContext)
context = newContext;
}
-Q_GLOBAL_STATIC_WITH_ARGS(QMutex, qt_securetransport_mutex, (QMutex::Recursive))
+Q_GLOBAL_STATIC(QRecursiveMutex, qt_securetransport_mutex)
//#define QSSLSOCKET_DEBUG
diff --git a/src/network/ssl/qsslsocket_openssl11.cpp b/src/network/ssl/qsslsocket_openssl11.cpp
index cc2d6ea2d9..28be4f2e79 100644
--- a/src/network/ssl/qsslsocket_openssl11.cpp
+++ b/src/network/ssl/qsslsocket_openssl11.cpp
@@ -72,7 +72,7 @@
QT_BEGIN_NAMESPACE
-Q_GLOBAL_STATIC_WITH_ARGS(QMutex, qt_opensslInitMutex, (QMutex::Recursive))
+Q_GLOBAL_STATIC(QRecursiveMutex, qt_opensslInitMutex)
void QSslSocketPrivate::deinitialize()
{
diff --git a/src/network/ssl/qsslsocket_openssl_symbols.cpp b/src/network/ssl/qsslsocket_openssl_symbols.cpp
index 2eb9763e90..1fcfdf9f16 100644
--- a/src/network/ssl/qsslsocket_openssl_symbols.cpp
+++ b/src/network/ssl/qsslsocket_openssl_symbols.cpp
@@ -63,13 +63,11 @@
# include <QtCore/qlibrary.h>
#endif
#include <QtCore/qmutex.h>
-#if QT_CONFIG(thread)
-#include <private/qmutexpool_p.h>
-#endif
#include <QtCore/qdatetime.h>
#if defined(Q_OS_UNIX)
#include <QtCore/qdir.h>
#endif
+#include <QtCore/private/qmemory_p.h>
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
#include <link.h>
#endif
@@ -599,8 +597,8 @@ DEFINEFUNC2(PKCS12 *, d2i_PKCS12_bio, BIO *bio, bio, PKCS12 **pkcs12, pkcs12, re
DEFINEFUNC(void, PKCS12_free, PKCS12 *pkcs12, pkcs12, return, DUMMYARG)
#define RESOLVEFUNC(func) \
- if (!(_q_##func = _q_PTR_##func(libs.first->resolve(#func))) \
- && !(_q_##func = _q_PTR_##func(libs.second->resolve(#func)))) \
+ if (!(_q_##func = _q_PTR_##func(libs.ssl->resolve(#func))) \
+ && !(_q_##func = _q_PTR_##func(libs.crypto->resolve(#func)))) \
qsslSocketCannotResolveSymbolWarning(#func);
#if !defined QT_LINKED_OPENSSL
@@ -736,34 +734,31 @@ static QStringList findAllLibCrypto()
# endif
#ifdef Q_OS_WIN
-static bool tryToLoadOpenSslWin32Library(QLatin1String ssleay32LibName, QLatin1String libeay32LibName, QPair<QSystemLibrary*, QSystemLibrary*> &pair)
-{
- pair.first = 0;
- pair.second = 0;
- QSystemLibrary *ssleay32 = new QSystemLibrary(ssleay32LibName);
+struct LoadedOpenSsl {
+ std::unique_ptr<QSystemLibrary> ssl, crypto;
+};
+
+static bool tryToLoadOpenSslWin32Library(QLatin1String ssleay32LibName, QLatin1String libeay32LibName, LoadedOpenSsl &result)
+{
+ auto ssleay32 = qt_make_unique<QSystemLibrary>(ssleay32LibName);
if (!ssleay32->load(false)) {
- delete ssleay32;
return FALSE;
}
- QSystemLibrary *libeay32 = new QSystemLibrary(libeay32LibName);
+ auto libeay32 = qt_make_unique<QSystemLibrary>(libeay32LibName);
if (!libeay32->load(false)) {
- delete ssleay32;
- delete libeay32;
return FALSE;
}
- pair.first = ssleay32;
- pair.second = libeay32;
+ result.ssl = std::move(ssleay32);
+ result.crypto = std::move(libeay32);
return TRUE;
}
-static QPair<QSystemLibrary*, QSystemLibrary*> loadOpenSslWin32()
+static LoadedOpenSsl loadOpenSsl()
{
- QPair<QSystemLibrary*,QSystemLibrary*> pair;
- pair.first = 0;
- pair.second = 0;
+ LoadedOpenSsl result;
#if QT_CONFIG(opensslv11)
// With OpenSSL 1.1 the names have changed to libssl-1_1(-x64) and libcrypto-1_1(-x64), for builds using
@@ -776,7 +771,7 @@ static QPair<QSystemLibrary*, QSystemLibrary*> loadOpenSslWin32()
#endif // !Q_PROCESSOR_x86_64
tryToLoadOpenSslWin32Library(QLatin1String("libssl-1_1" QT_SSL_SUFFIX),
- QLatin1String("libcrypto-1_1" QT_SSL_SUFFIX), pair);
+ QLatin1String("libcrypto-1_1" QT_SSL_SUFFIX), result);
#undef QT_SSL_SUFFIX
@@ -785,28 +780,30 @@ static QPair<QSystemLibrary*, QSystemLibrary*> loadOpenSslWin32()
// When OpenSSL is built using MSVC then the libraries are named 'ssleay32.dll' and 'libeay32'dll'.
// When OpenSSL is built using GCC then different library names are used (depending on the OpenSSL version)
// The oldest version of a GCC-based OpenSSL which can be detected by the code below is 0.9.8g (released in 2007)
- if (!tryToLoadOpenSslWin32Library(QLatin1String("ssleay32"), QLatin1String("libeay32"), pair)) {
- if (!tryToLoadOpenSslWin32Library(QLatin1String("libssl-10"), QLatin1String("libcrypto-10"), pair)) {
- if (!tryToLoadOpenSslWin32Library(QLatin1String("libssl-8"), QLatin1String("libcrypto-8"), pair)) {
- tryToLoadOpenSslWin32Library(QLatin1String("libssl-7"), QLatin1String("libcrypto-7"), pair);
+ if (!tryToLoadOpenSslWin32Library(QLatin1String("ssleay32"), QLatin1String("libeay32"), result)) {
+ if (!tryToLoadOpenSslWin32Library(QLatin1String("libssl-10"), QLatin1String("libcrypto-10"), result)) {
+ if (!tryToLoadOpenSslWin32Library(QLatin1String("libssl-8"), QLatin1String("libcrypto-8"), result)) {
+ tryToLoadOpenSslWin32Library(QLatin1String("libssl-7"), QLatin1String("libcrypto-7"), result);
}
}
}
#endif // !QT_CONFIG(opensslv11)
- return pair;
+ return result;
}
#else
-static QPair<QLibrary*, QLibrary*> loadOpenSsl()
+struct LoadedOpenSsl {
+ std::unique_ptr<QLibrary> ssl, crypto;
+};
+
+static LoadedOpenSsl loadOpenSsl()
{
- QPair<QLibrary*,QLibrary*> pair;
+ LoadedOpenSsl result = {qt_make_unique<QLibrary>(), qt_make_unique<QLibrary>()};
# if defined(Q_OS_UNIX)
- QLibrary *&libssl = pair.first;
- QLibrary *&libcrypto = pair.second;
- libssl = new QLibrary;
- libcrypto = new QLibrary;
+ QLibrary * const libssl = result.ssl.get();
+ QLibrary * const libcrypto = result.crypto.get();
// Try to find the libssl library on the system.
//
@@ -850,7 +847,7 @@ static QPair<QLibrary*, QLibrary*> loadOpenSsl()
libcrypto->setFileNameAndVersion(QLatin1String("crypto"), QLatin1String(SHLIB_VERSION_NUMBER));
if (libcrypto->load() && libssl->load()) {
// libssl.so.<SHLIB_VERSION_NUMBER> and libcrypto.so.<SHLIB_VERSION_NUMBER> found
- return pair;
+ return result;
} else {
libssl->unload();
libcrypto->unload();
@@ -869,7 +866,7 @@ static QPair<QLibrary*, QLibrary*> loadOpenSsl()
libssl->setFileNameAndVersion(QLatin1String("ssl"), fallbackSoname);
libcrypto->setFileNameAndVersion(QLatin1String("crypto"), fallbackSoname);
if (libcrypto->load() && libssl->load()) {
- return pair;
+ return result;
} else {
libssl->unload();
libcrypto->unload();
@@ -885,11 +882,28 @@ static QPair<QLibrary*, QLibrary*> loadOpenSsl()
// macOS's /usr/lib/libssl.dylib, /usr/lib/libcrypto.dylib will be picked up in the third
// attempt, _after_ <bundle>/Contents/Frameworks has been searched.
// iOS does not ship a system libssl.dylib, libcrypto.dylib in the first place.
+# if defined(Q_OS_ANDROID)
+ // OpenSSL 1.1.x must be suffixed otherwise it will use the system libcrypto.so libssl.so which on API-21 are OpenSSL 1.0 not 1.1
+ auto openSSLSuffix = [](const QByteArray &defaultSuffix = {}) {
+ auto suffix = qgetenv("ANDROID_OPENSSL_SUFFIX");
+ if (suffix.isEmpty())
+ return defaultSuffix;
+ return suffix;
+ };
+# if QT_CONFIG(opensslv11)
+ static QString suffix = QString::fromLatin1(openSSLSuffix("_1_1"));
+# else
+ static QString suffix = QString::fromLatin1(openSSLSuffix());
+# endif
+ libssl->setFileNameAndVersion(QLatin1String("ssl") + suffix, -1);
+ libcrypto->setFileNameAndVersion(QLatin1String("crypto") + suffix, -1);
+# else
libssl->setFileNameAndVersion(QLatin1String("ssl"), -1);
libcrypto->setFileNameAndVersion(QLatin1String("crypto"), -1);
+# endif
if (libcrypto->load() && libssl->load()) {
// libssl.so.0 and libcrypto.so.0 found
- return pair;
+ return result;
} else {
libssl->unload();
libcrypto->unload();
@@ -914,7 +928,7 @@ static QPair<QLibrary*, QLibrary*> loadOpenSsl()
if (libssl->load()) {
// libssl.so.x and libcrypto.so.x found
- return pair;
+ return result;
} else {
libssl->unload();
}
@@ -924,41 +938,33 @@ static QPair<QLibrary*, QLibrary*> loadOpenSsl()
}
// failed to load anything
- delete libssl;
- delete libcrypto;
- libssl = libcrypto = 0;
- return pair;
+ result = {};
+ return result;
# else
// not implemented for this platform yet
- return pair;
+ return result;
# endif
}
#endif
+static QBasicMutex symbolResolveMutex;
+static QBasicAtomicInt symbolsResolved = Q_BASIC_ATOMIC_INITIALIZER(false);
+static bool triedToResolveSymbols = false;
+
bool q_resolveOpenSslSymbols()
{
- static bool symbolsResolved = false;
- static bool triedToResolveSymbols = false;
-#if QT_CONFIG(thread)
-#if QT_CONFIG(opensslv11)
- QMutexLocker locker(QMutexPool::globalInstanceGet((void *)&q_OPENSSL_init_ssl));
-#else
- QMutexLocker locker(QMutexPool::globalInstanceGet((void *)&q_SSL_library_init));
-#endif
-#endif
- if (symbolsResolved)
+ if (symbolsResolved.loadAcquire())
+ return true;
+ QMutexLocker locker(&symbolResolveMutex);
+ if (symbolsResolved.loadRelaxed())
return true;
if (triedToResolveSymbols)
return false;
triedToResolveSymbols = true;
-#ifdef Q_OS_WIN
- QPair<QSystemLibrary *, QSystemLibrary *> libs = loadOpenSslWin32();
-#else
- QPair<QLibrary *, QLibrary *> libs = loadOpenSsl();
-#endif
- if (!libs.first || !libs.second)
+ LoadedOpenSsl libs = loadOpenSsl();
+ if (!libs.ssl || !libs.crypto)
// failed to load them
return false;
@@ -1007,8 +1013,6 @@ bool q_resolveOpenSslSymbols()
if (!_q_OpenSSL_version) {
// Apparently, we were built with OpenSSL 1.1 enabled but are now using
// a wrong library.
- delete libs.first;
- delete libs.second;
qCWarning(lcSsl, "Incompatible version of OpenSSL");
return false;
}
@@ -1130,8 +1134,6 @@ bool q_resolveOpenSslSymbols()
// OpenSSL 1.1 has deprecated and removed SSLeay. We consider a failure to
// resolve this symbol as a failure to resolve symbols.
// The right operand of '||' above is ... a bit of paranoia.
- delete libs.first;
- delete libs.second;
qCWarning(lcSsl, "Incompatible version of OpenSSL");
return false;
}
@@ -1402,9 +1404,7 @@ bool q_resolveOpenSslSymbols()
RESOLVEFUNC(d2i_PKCS12_bio)
RESOLVEFUNC(PKCS12_free)
- symbolsResolved = true;
- delete libs.first;
- delete libs.second;
+ symbolsResolved.storeRelease(true);
return true;
}
#endif // QT_CONFIG(library)
diff --git a/src/network/ssl/qsslsocket_schannel.cpp b/src/network/ssl/qsslsocket_schannel.cpp
index 1314b432a4..c254659a33 100644
--- a/src/network/ssl/qsslsocket_schannel.cpp
+++ b/src/network/ssl/qsslsocket_schannel.cpp
@@ -431,7 +431,7 @@ QByteArray createAlpnString(const QByteArrayList &nextAllowedProtocols)
bool QSslSocketPrivate::s_loadRootCertsOnDemand = true;
bool QSslSocketPrivate::s_loadedCiphersAndCerts = false;
-Q_GLOBAL_STATIC_WITH_ARGS(QMutex, qt_schannel_mutex, (QMutex::Recursive))
+Q_GLOBAL_STATIC(QRecursiveMutex, qt_schannel_mutex)
void QSslSocketPrivate::ensureInitialized()
{
diff --git a/src/platformsupport/eglconvenience/qeglstreamconvenience_p.h b/src/platformsupport/eglconvenience/qeglstreamconvenience_p.h
index 31a79dbc6c..c3d3070210 100644
--- a/src/platformsupport/eglconvenience/qeglstreamconvenience_p.h
+++ b/src/platformsupport/eglconvenience/qeglstreamconvenience_p.h
@@ -131,12 +131,6 @@ typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERRELEASEKHRPROC) (EGLDisplay
typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMEROUTPUTEXTPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLOutputLayerEXT layer);
#endif
-#ifndef EGL_EXT_stream_acquire_mode
-#define EGL_EXT_stream_acquire_mode 1
-#define EGL_CONSUMER_AUTO_ACQUIRE_EXT 0x332B
-#define EGL_RESOURCE_BUSY_EXT 0x3353
-#endif
-
#ifndef EGL_EXT_platform_device
#define EGL_PLATFORM_DEVICE_EXT 0x313F
#endif
@@ -162,11 +156,6 @@ typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERACQUIREATTRIBNVPROC) (EGLDi
typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERRELEASEATTRIBNVPROC) (EGLDisplay dpy, EGLStreamKHR stream, const EGLAttrib *attrib_list);
#endif
-#ifndef EGL_NV_output_drm_flip_event
-#define EGL_NV_output_drm_flip_event 1
-#define EGL_DRM_FLIP_EVENT_DATA_NV 0x333E
-#endif
-
QT_BEGIN_NAMESPACE
class QEGLStreamConvenience
diff --git a/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp b/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp
index e28b40c240..7abf295782 100644
--- a/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp
+++ b/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp
@@ -927,66 +927,38 @@ void QFontconfigDatabase::setupFontEngine(QFontEngineFT *engine, const QFontDef
antialias = antialiasingEnabled - 1;
}
- // try to find a match for fid
- const QFontEngine::FaceId fid = engine->faceId();
+ QFontEngine::GlyphFormat format;
+ // try and get the pattern
FcPattern *pattern = FcPatternCreate();
- FcPattern *match = nullptr;
-
- // try a trivial match by filename - FC_FILE is highest priority, so if it matches, FcFontMatch
- // will just find the file (fine) and spend a millisecond or so doing unnecessary work (bad).
- if (!fid.filename.isEmpty() && QFile::exists(QString::fromUtf8(fid.filename))) {
- FcBlanks *blanks = FcConfigGetBlanks(nullptr);
- int count = 0;
- FcPattern *fileMatch = FcFreeTypeQuery((const FcChar8 *)fid.filename.data(), fid.index,
- blanks, &count);
- if (fileMatch) {
- // Apply Fontconfig configuration - FcFreeTypeQuery only returns information stored in
- // the font file, we also want to respect system and user settings.
- FcConfigSubstitute(0, pattern, FcMatchPattern);
- FcDefaultSubstitute(pattern);
- match = FcFontRenderPrepare(0, pattern, fileMatch);
- FcPatternDestroy(fileMatch);
- }
- }
- if (!match) {
- FcValue value;
+ FcValue value;
+ value.type = FcTypeString;
+ QByteArray cs = fontDef.family.toUtf8();
+ value.u.s = (const FcChar8 *)cs.data();
+ FcPatternAdd(pattern,FC_FAMILY,value,true);
- // Fontconfig rules might process this information for arbitrary purposes, so add it,
- // even though we already know that it doesn't match an existing file.
- if (!fid.filename.isEmpty()) {
- value.type = FcTypeString;
- value.u.s = (const FcChar8 *)fid.filename.data();
- FcPatternAdd(pattern, FC_FILE, value, true);
+ QFontEngine::FaceId fid = engine->faceId();
- value.type = FcTypeInteger;
- value.u.i = fid.index;
- FcPatternAdd(pattern, FC_INDEX, value, true);
- }
+ if (!fid.filename.isEmpty()) {
+ value.u.s = (const FcChar8 *)fid.filename.data();
+ FcPatternAdd(pattern,FC_FILE,value,true);
- const QByteArray cs = fontDef.family.toUtf8();
- value.type = FcTypeString;
- value.u.s = (const FcChar8 *)cs.data();
- FcPatternAdd(pattern, FC_FAMILY, value, true);
-
- if (fontDef.pixelSize > 0.1) {
- value.type = FcTypeDouble;
- value.u.d = fontDef.pixelSize;
- FcPatternAdd(pattern, FC_PIXEL_SIZE, value, true);
- }
+ value.type = FcTypeInteger;
+ value.u.i = fid.index;
+ FcPatternAdd(pattern,FC_INDEX,value,true);
+ }
- FcResult result;
+ if (fontDef.pixelSize > 0.1)
+ FcPatternAddDouble(pattern, FC_PIXEL_SIZE, fontDef.pixelSize);
- FcConfigSubstitute(0, pattern, FcMatchPattern);
- FcDefaultSubstitute(pattern);
+ FcResult result;
- match = FcFontMatch(0, pattern, &result);
- }
+ FcConfigSubstitute(0, pattern, FcMatchPattern);
+ FcDefaultSubstitute(pattern);
- QFontEngine::GlyphFormat format;
+ FcPattern *match = FcFontMatch(0, pattern, &result);
if (match) {
- engine->setDefaultHintStyle(defaultHintStyleFromMatch(
- (QFont::HintingPreference)fontDef.hintingPreference, match, useXftConf));
+ engine->setDefaultHintStyle(defaultHintStyleFromMatch((QFont::HintingPreference)fontDef.hintingPreference, match, useXftConf));
FcBool fc_autohint;
if (FcPatternGetBool(match, FC_AUTOHINT,0, &fc_autohint) == FcResultMatch)
diff --git a/src/platformsupport/fontdatabases/freetype/qfontengine_ft.cpp b/src/platformsupport/fontdatabases/freetype/qfontengine_ft.cpp
index 8d0a20f7b9..b608e7f483 100644
--- a/src/platformsupport/fontdatabases/freetype/qfontengine_ft.cpp
+++ b/src/platformsupport/fontdatabases/freetype/qfontengine_ft.cpp
@@ -1929,8 +1929,10 @@ QImage QFontEngineFT::alphaRGBMapForGlyph(glyph_t g, QFixed subPixelPosition, co
return QFontEngine::alphaRGBMapForGlyph(g, subPixelPosition, t);
}
-QImage QFontEngineFT::bitmapForGlyph(glyph_t g, QFixed subPixelPosition, const QTransform &t)
+QImage QFontEngineFT::bitmapForGlyph(glyph_t g, QFixed subPixelPosition, const QTransform &t, const QColor &color)
{
+ Q_UNUSED(color);
+
Glyph *glyph = loadGlyphFor(g, subPixelPosition, defaultFormat, t);
if (glyph == nullptr)
return QImage();
diff --git a/src/platformsupport/fontdatabases/freetype/qfontengine_ft_p.h b/src/platformsupport/fontdatabases/freetype/qfontengine_ft_p.h
index 2765db2946..b636c42e63 100644
--- a/src/platformsupport/fontdatabases/freetype/qfontengine_ft_p.h
+++ b/src/platformsupport/fontdatabases/freetype/qfontengine_ft_p.h
@@ -236,7 +236,7 @@ private:
QImage alphaMapForGlyph(glyph_t, QFixed) override;
QImage alphaMapForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &t) override;
QImage alphaRGBMapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t) override;
- QImage bitmapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t) override;
+ QImage bitmapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t, const QColor &color) override;
glyph_metrics_t alphaMapBoundingBox(glyph_t glyph,
QFixed subPixelPosition,
const QTransform &matrix,
diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm
index 25e7c6df72..072dd1a28a 100644
--- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm
+++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm
@@ -747,7 +747,7 @@ qreal QCoreTextFontEngine::fontSmoothingGamma()
return 2.0;
}
-QImage QCoreTextFontEngine::imageForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &matrix)
+QImage QCoreTextFontEngine::imageForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &matrix, const QColor &color)
{
glyph_metrics_t br = alphaMapBoundingBox(glyph, subPixelPosition, matrix, glyphFormat);
@@ -827,6 +827,8 @@ QImage QCoreTextFontEngine::imageForGlyph(glyph_t glyph, QFixed subPixelPosition
CTFontDrawGlyphs(ctfont, &cgGlyph, &CGPointZero, 1, ctx);
}
} else {
+ CGContextSetRGBFillColor(ctx, color.redF(), color.greenF(), color.blueF(), color.alphaF());
+
// CGContextSetTextMatrix does not work with color glyphs, so we use
// the CTM instead. This means we must translate the CTM as well, to
// set the glyph position, instead of using CGContextSetTextPosition.
@@ -884,12 +886,12 @@ QImage QCoreTextFontEngine::alphaRGBMapForGlyph(glyph_t glyph, QFixed subPixelPo
return imageForGlyph(glyph, subPixelPosition, x);
}
-QImage QCoreTextFontEngine::bitmapForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &t)
+QImage QCoreTextFontEngine::bitmapForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &t, const QColor &color)
{
if (t.type() > QTransform::TxScale)
- return QFontEngine::bitmapForGlyph(glyph, subPixelPosition, t);
+ return QFontEngine::bitmapForGlyph(glyph, subPixelPosition, t, color);
- return imageForGlyph(glyph, subPixelPosition, t);
+ return imageForGlyph(glyph, subPixelPosition, t, color);
}
void QCoreTextFontEngine::recalcAdvances(QGlyphLayout *glyphs, QFontEngine::ShaperFlags flags) const
diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h
index 4064507058..51d839688d 100644
--- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h
+++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h
@@ -110,7 +110,7 @@ public:
QImage alphaMapForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &t) override;
QImage alphaRGBMapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t) override;
glyph_metrics_t alphaMapBoundingBox(glyph_t glyph, QFixed, const QTransform &matrix, GlyphFormat) override;
- QImage bitmapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t) override;
+ QImage bitmapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t, const QColor &color) override;
QFixed emSquareSize() const override;
void doKerning(QGlyphLayout *g, ShaperFlags flags) const override;
@@ -137,7 +137,7 @@ public:
protected:
QCoreTextFontEngine(const QFontDef &def);
void init();
- QImage imageForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &m);
+ QImage imageForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &m, const QColor &color = QColor());
void loadAdvancesForGlyphs(QVarLengthArray<CGGlyph> &cgGlyphs, QGlyphLayout *glyphs) const;
bool hasColorGlyphs() const;
bool shouldAntialias() const;
diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp b/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp
index 60a5896e7b..a4490a6664 100644
--- a/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp
+++ b/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp
@@ -650,7 +650,8 @@ bool QWindowsFontEngineDirectWrite::supportsSubPixelPositions() const
QImage QWindowsFontEngineDirectWrite::imageForGlyph(glyph_t t,
QFixed subPixelPosition,
int margin,
- const QTransform &originalTransform)
+ const QTransform &originalTransform,
+ const QColor &color)
{
UINT16 glyphIndex = t;
FLOAT glyphAdvance = 0;
@@ -735,6 +736,7 @@ QImage QWindowsFontEngineDirectWrite::imageForGlyph(glyph_t t,
#if defined(QT_USE_DIRECTWRITE2)
BOOL ok = true;
+
if (SUCCEEDED(hr)) {
while (SUCCEEDED(hr) && ok) {
const DWRITE_COLOR_GLYPH_RUN *colorGlyphRun = 0;
@@ -759,10 +761,18 @@ QImage QWindowsFontEngineDirectWrite::imageForGlyph(glyph_t t,
break;
}
- float r = qBound(0.0f, colorGlyphRun->runColor.r, 1.0f);
- float g = qBound(0.0f, colorGlyphRun->runColor.g, 1.0f);
- float b = qBound(0.0f, colorGlyphRun->runColor.b, 1.0f);
- float a = qBound(0.0f, colorGlyphRun->runColor.a, 1.0f);
+ float r, g, b, a;
+ if (colorGlyphRun->paletteIndex == 0xFFFF) {
+ r = float(color.redF());
+ g = float(color.greenF());
+ b = float(color.blueF());
+ a = float(color.alphaF());
+ } else {
+ r = qBound(0.0f, colorGlyphRun->runColor.r, 1.0f);
+ g = qBound(0.0f, colorGlyphRun->runColor.g, 1.0f);
+ b = qBound(0.0f, colorGlyphRun->runColor.b, 1.0f);
+ a = qBound(0.0f, colorGlyphRun->runColor.a, 1.0f);
+ }
if (!qFuzzyIsNull(a)) {
renderGlyphRun(&image,
@@ -784,11 +794,21 @@ QImage QWindowsFontEngineDirectWrite::imageForGlyph(glyph_t t,
} else
#endif
{
+ float r, g, b, a;
+ if (glyphFormat == QFontEngine::Format_ARGB) {
+ r = float(color.redF());
+ g = float(color.greenF());
+ b = float(color.blueF());
+ a = float(color.alphaF());
+ } else {
+ r = g = b = a = 0.0;
+ }
+
renderGlyphRun(&image,
- 0.0,
- 0.0,
- 0.0,
- 1.0,
+ r,
+ g,
+ b,
+ a,
glyphAnalysis,
boundingRect);
}
@@ -1001,9 +1021,9 @@ glyph_metrics_t QWindowsFontEngineDirectWrite::alphaMapBoundingBox(glyph_t glyph
}
}
-QImage QWindowsFontEngineDirectWrite::bitmapForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &t)
+QImage QWindowsFontEngineDirectWrite::bitmapForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &t, const QColor &color)
{
- return imageForGlyph(glyph, subPixelPosition, glyphMargin(QFontEngine::Format_A32), t);
+ return imageForGlyph(glyph, subPixelPosition, glyphMargin(QFontEngine::Format_A32), t, color);
}
QT_END_NAMESPACE
diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite_p.h b/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite_p.h
index 3eaf8cf3d8..c8c6b83bf9 100644
--- a/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite_p.h
+++ b/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite_p.h
@@ -112,7 +112,7 @@ public:
QImage alphaMapForGlyph(glyph_t glyph, QFixed subPixelPosition) override;
QImage alphaMapForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &t) override;
QImage alphaRGBMapForGlyph(glyph_t t, QFixed subPixelPosition, const QTransform &xform) override;
- QImage bitmapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t) override;
+ QImage bitmapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t, const QColor &color) override;
QFontEngine *cloneWithSize(qreal pixelSize) const override;
Qt::HANDLE handle() const override;
@@ -126,7 +126,7 @@ public:
void setUniqueFamilyName(const QString &newName) { m_uniqueFamilyName = newName; }
private:
- QImage imageForGlyph(glyph_t t, QFixed subPixelPosition, int margin, const QTransform &xform);
+ QImage imageForGlyph(glyph_t t, QFixed subPixelPosition, int margin, const QTransform &xform, const QColor &color = QColor());
void collectMetrics();
void renderGlyphRun(QImage *destination, float r, float g, float b, float a, IDWriteGlyphRunAnalysis *glyphAnalysis, const QRect &boundingRect);
static QString filenameFromFontFile(IDWriteFontFile *fontFile);
diff --git a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp
index bff4a2522c..3555763b89 100644
--- a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp
+++ b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp
@@ -231,7 +231,7 @@ void QEvdevKeyboardHandler::processKeyEvent(int nativecode, int unicode, int qtc
QWindowSystemInterface::handleExtendedKeyEvent(0, (isPress ? QEvent::KeyPress : QEvent::KeyRelease),
qtcode, modifiers, nativecode + 8, 0, int(modifiers),
- (unicode != 0xffff ) ? QString(unicode) : QString(), autoRepeat);
+ (unicode != 0xffff ) ? QString(QChar(unicode)) : QString(), autoRepeat);
}
QEvdevKeyboardHandler::KeycodeAction QEvdevKeyboardHandler::processKeycode(quint16 keycode, bool pressed, bool autorepeat)
diff --git a/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp b/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp
index 0c19294905..daa52d690e 100644
--- a/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp
+++ b/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp
@@ -96,7 +96,7 @@ QEvdevMouseManager::QEvdevMouseManager(const QString &key, const QString &specif
}
QInputDeviceManager *manager = QGuiApplicationPrivate::inputDeviceManager();
- connect(manager, &QInputDeviceManager::cursorPositionChangeRequested, [=](const QPoint &pos) {
+ connect(manager, &QInputDeviceManager::cursorPositionChangeRequested, [this](const QPoint &pos) {
m_x = pos.x();
m_y = pos.y();
clampPosition();
diff --git a/src/platformsupport/input/libinput/qlibinputhandler.cpp b/src/platformsupport/input/libinput/qlibinputhandler.cpp
index bb81890a67..95dfb46d16 100644
--- a/src/platformsupport/input/libinput/qlibinputhandler.cpp
+++ b/src/platformsupport/input/libinput/qlibinputhandler.cpp
@@ -115,7 +115,7 @@ QLibInputHandler::QLibInputHandler(const QString &key, const QString &spec)
m_touch.reset(new QLibInputTouch);
QInputDeviceManager *manager = QGuiApplicationPrivate::inputDeviceManager();
- connect(manager, &QInputDeviceManager::cursorPositionChangeRequested, [=](const QPoint &pos) {
+ connect(manager, &QInputDeviceManager::cursorPositionChangeRequested, [this](const QPoint &pos) {
m_pointer->setPos(pos);
});
diff --git a/src/platformsupport/kmsconvenience/qkmsdevice.cpp b/src/platformsupport/kmsconvenience/qkmsdevice.cpp
index 8cc7a539b5..1ba32895f8 100644
--- a/src/platformsupport/kmsconvenience/qkmsdevice.cpp
+++ b/src/platformsupport/kmsconvenience/qkmsdevice.cpp
@@ -66,6 +66,8 @@ enum OutputConfiguration {
int QKmsDevice::crtcForConnector(drmModeResPtr resources, drmModeConnectorPtr connector)
{
+ int candidate = -1;
+
for (int i = 0; i < connector->count_encoders; i++) {
drmModeEncoderPtr encoder = drmModeGetEncoder(m_dri_fd, connector->encoders[i]);
if (!encoder) {
@@ -73,19 +75,30 @@ int QKmsDevice::crtcForConnector(drmModeResPtr resources, drmModeConnectorPtr co
continue;
}
+ quint32 encoderId = encoder->encoder_id;
+ quint32 crtcId = encoder->crtc_id;
quint32 possibleCrtcs = encoder->possible_crtcs;
drmModeFreeEncoder(encoder);
for (int j = 0; j < resources->count_crtcs; j++) {
bool isPossible = possibleCrtcs & (1 << j);
bool isAvailable = !(m_crtc_allocator & (1 << j));
-
- if (isPossible && isAvailable)
+ // Preserve the existing CRTC -> encoder -> connector routing if
+ // any. It makes the initialization faster, and may be better
+ // since we have a very dumb picking algorithm.
+ bool isBestChoice = (!connector->encoder_id ||
+ (connector->encoder_id == encoderId &&
+ resources->crtcs[j] == crtcId));
+
+ if (isPossible && isAvailable && isBestChoice) {
return j;
+ } else if (isPossible && isAvailable) {
+ candidate = j;
+ }
}
}
- return -1;
+ return candidate;
}
static const char * const connector_type_names[] = { // must match DRM_MODE_CONNECTOR_*
diff --git a/src/plugins/imageformats/gif/qgifhandler.cpp b/src/plugins/imageformats/gif/qgifhandler.cpp
index 1aef1a24d2..a6029b691c 100644
--- a/src/plugins/imageformats/gif/qgifhandler.cpp
+++ b/src/plugins/imageformats/gif/qgifhandler.cpp
@@ -1215,9 +1215,11 @@ int QGifHandler::currentImageNumber() const
return frameNumber;
}
+#if QT_DEPRECATED_SINCE(5, 13)
QByteArray QGifHandler::name() const
{
return "gif";
}
+#endif
QT_END_NAMESPACE
diff --git a/src/plugins/imageformats/gif/qgifhandler_p.h b/src/plugins/imageformats/gif/qgifhandler_p.h
index b004ee610d..c6592043ce 100644
--- a/src/plugins/imageformats/gif/qgifhandler_p.h
+++ b/src/plugins/imageformats/gif/qgifhandler_p.h
@@ -73,7 +73,9 @@ public:
bool read(QImage *image) override;
bool write(const QImage &image) override;
+#if QT_DEPRECATED_SINCE(5, 13)
QByteArray name() const override;
+#endif
static bool canRead(QIODevice *device);
diff --git a/src/plugins/imageformats/ico/qicohandler.cpp b/src/plugins/imageformats/ico/qicohandler.cpp
index 4908850cc5..c8e31dceac 100644
--- a/src/plugins/imageformats/ico/qicohandler.cpp
+++ b/src/plugins/imageformats/ico/qicohandler.cpp
@@ -818,6 +818,7 @@ bool QtIcoHandler::write(const QImage &image)
return ICOReader::write(device, imgs);
}
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
* Return the common identifier of the format.
* For ICO format this will return "ico".
@@ -826,7 +827,7 @@ QByteArray QtIcoHandler::name() const
{
return "ico";
}
-
+#endif
/*! \reimp
diff --git a/src/plugins/imageformats/ico/qicohandler.h b/src/plugins/imageformats/ico/qicohandler.h
index 435f036113..328dfce47e 100644
--- a/src/plugins/imageformats/ico/qicohandler.h
+++ b/src/plugins/imageformats/ico/qicohandler.h
@@ -54,7 +54,9 @@ public:
bool read(QImage *image) override;
bool write(const QImage &image) override;
+#if QT_DEPRECATED_SINCE(5, 13)
QByteArray name() const override;
+#endif
int imageCount() const override;
bool jumpToImage(int imageNumber) override;
diff --git a/src/plugins/imageformats/jpeg/qjpeghandler.cpp b/src/plugins/imageformats/jpeg/qjpeghandler.cpp
index 9d5ccc8a3d..0fb21df1d3 100644
--- a/src/plugins/imageformats/jpeg/qjpeghandler.cpp
+++ b/src/plugins/imageformats/jpeg/qjpeghandler.cpp
@@ -1136,9 +1136,11 @@ void QJpegHandler::setOption(ImageOption option, const QVariant &value)
}
}
+#if QT_DEPRECATED_SINCE(5, 13)
QByteArray QJpegHandler::name() const
{
return "jpeg";
}
+#endif
QT_END_NAMESPACE
diff --git a/src/plugins/imageformats/jpeg/qjpeghandler_p.h b/src/plugins/imageformats/jpeg/qjpeghandler_p.h
index d832bf82f3..fafa930c11 100644
--- a/src/plugins/imageformats/jpeg/qjpeghandler_p.h
+++ b/src/plugins/imageformats/jpeg/qjpeghandler_p.h
@@ -68,7 +68,9 @@ public:
bool read(QImage *image) override;
bool write(const QImage &image) override;
+#if QT_DEPRECATED_SINCE(5, 13)
QByteArray name() const override;
+#endif
static bool canRead(QIODevice *device);
diff --git a/src/plugins/platforms/cocoa/cocoa.pro b/src/plugins/platforms/cocoa/cocoa.pro
index 083b7c1655..02e00039ae 100644
--- a/src/plugins/platforms/cocoa/cocoa.pro
+++ b/src/plugins/platforms/cocoa/cocoa.pro
@@ -6,6 +6,7 @@ SOURCES += main.mm \
qcocoatheme.mm \
qcocoabackingstore.mm \
qcocoawindow.mm \
+ qcocoawindowmanager.mm \
qnsview.mm \
qnswindow.mm \
qnswindowdelegate.mm \
@@ -41,6 +42,7 @@ HEADERS += qcocoaintegration.h \
qcocoatheme.h \
qcocoabackingstore.h \
qcocoawindow.h \
+ qcocoawindowmanager.h \
qnsview.h \
qnswindow.h \
qnswindowdelegate.h \
diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.h b/src/plugins/platforms/cocoa/qcocoabackingstore.h
index 2398e6351e..9be6814ae7 100644
--- a/src/plugins/platforms/cocoa/qcocoabackingstore.h
+++ b/src/plugins/platforms/cocoa/qcocoabackingstore.h
@@ -49,7 +49,14 @@
QT_BEGIN_NAMESPACE
-class QNSWindowBackingStore : public QRasterBackingStore
+class QCocoaBackingStore : public QRasterBackingStore
+{
+protected:
+ QCocoaBackingStore(QWindow *window);
+ QCFType<CGColorSpaceRef> colorSpace() const;
+};
+
+class QNSWindowBackingStore : public QCocoaBackingStore
{
public:
QNSWindowBackingStore(QWindow *window);
@@ -64,7 +71,7 @@ private:
void redrawRoundedBottomCorners(CGRect) const;
};
-class QCALayerBackingStore : public QPlatformBackingStore
+class QCALayerBackingStore : public QCocoaBackingStore
{
public:
QCALayerBackingStore(QWindow *window);
diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.mm b/src/plugins/platforms/cocoa/qcocoabackingstore.mm
index 01b4894324..6015257f4e 100644
--- a/src/plugins/platforms/cocoa/qcocoabackingstore.mm
+++ b/src/plugins/platforms/cocoa/qcocoabackingstore.mm
@@ -48,11 +48,24 @@
QT_BEGIN_NAMESPACE
-QNSWindowBackingStore::QNSWindowBackingStore(QWindow *window)
+QCocoaBackingStore::QCocoaBackingStore(QWindow *window)
: QRasterBackingStore(window)
{
}
+QCFType<CGColorSpaceRef> QCocoaBackingStore::colorSpace() const
+{
+ NSView *view = static_cast<QCocoaWindow *>(window()->handle())->view();
+ return QCFType<CGColorSpaceRef>::constructFromGet(view.window.colorSpace.CGColorSpace);
+}
+
+// ----------------------------------------------------------------------------
+
+QNSWindowBackingStore::QNSWindowBackingStore(QWindow *window)
+ : QCocoaBackingStore(window)
+{
+}
+
QNSWindowBackingStore::~QNSWindowBackingStore()
{
}
@@ -175,11 +188,10 @@ void QNSWindowBackingStore::flush(QWindow *window, const QRegion &region, const
Q_ASSERT_X(graphicsContext, "QCocoaBackingStore",
"Focusing the view should give us a current graphics context");
- // Prevent potentially costly color conversion by assigning the display color space
- // to the backingstore image. This does not copy the underlying image data.
- CGColorSpaceRef displayColorSpace = view.window.screen.colorSpace.CGColorSpace;
+ // Tag backingstore image with color space based on the window.
+ // Note: This does not copy the underlying image data.
QCFType<CGImageRef> cgImage = CGImageCreateCopyWithColorSpace(
- QCFType<CGImageRef>(m_image.toCGImage()), displayColorSpace);
+ QCFType<CGImageRef>(m_image.toCGImage()), colorSpace());
// Create temporary image to use for blitting, without copying image data
NSImage *backingStoreImage = [[[NSImage alloc] initWithCGImage:cgImage size:NSZeroSize] autorelease];
@@ -293,7 +305,7 @@ void QNSWindowBackingStore::redrawRoundedBottomCorners(CGRect windowRect) const
// ----------------------------------------------------------------------------
QCALayerBackingStore::QCALayerBackingStore(QWindow *window)
- : QPlatformBackingStore(window)
+ : QCocoaBackingStore(window)
{
qCDebug(lcQpaBackingStore) << "Creating QCALayerBackingStore for" << window;
m_buffers.resize(1);
@@ -432,11 +444,7 @@ bool QCALayerBackingStore::recreateBackBufferIfNeeded()
<< "based on requested" << m_requestedSize << "and dpr =" << devicePixelRatio;
static auto pixelFormat = QImage::toPixelFormat(QImage::Format_ARGB32_Premultiplied);
-
- NSView *view = static_cast<QCocoaWindow *>(window()->handle())->view();
- auto colorSpace = QCFType<CGColorSpaceRef>::constructFromGet(view.window.screen.colorSpace.CGColorSpace);
-
- m_buffers.back().reset(new GraphicsBuffer(requestedBufferSize, devicePixelRatio, pixelFormat, colorSpace));
+ m_buffers.back().reset(new GraphicsBuffer(requestedBufferSize, devicePixelRatio, pixelFormat, colorSpace()));
return true;
}
diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.h b/src/plugins/platforms/cocoa/qcocoaglcontext.h
index c1041ac2da..bb309c0713 100644
--- a/src/plugins/platforms/cocoa/qcocoaglcontext.h
+++ b/src/plugins/platforms/cocoa/qcocoaglcontext.h
@@ -56,6 +56,8 @@ public:
QCocoaGLContext(QOpenGLContext *context);
~QCocoaGLContext();
+ void initialize() override;
+
bool makeCurrent(QPlatformSurface *surface) override;
void swapBuffers(QPlatformSurface *surface) override;
void doneCurrent() override;
diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.mm b/src/plugins/platforms/cocoa/qcocoaglcontext.mm
index 0f8fec0548..7b124ea517 100644
--- a/src/plugins/platforms/cocoa/qcocoaglcontext.mm
+++ b/src/plugins/platforms/cocoa/qcocoaglcontext.mm
@@ -40,6 +40,8 @@
#include "qcocoaglcontext.h"
#include "qcocoawindow.h"
#include "qcocoahelpers.h"
+#include "qcocoascreen.h"
+
#include <qdebug.h>
#include <QtPlatformHeaders/qcocoanativecontext.h>
#include <dlfcn.h>
@@ -53,32 +55,19 @@ static inline QByteArray getGlString(GLenum param)
return QByteArray();
}
-@implementation NSOpenGLPixelFormat (QtHelpers)
-- (GLint)qt_getAttribute:(NSOpenGLPixelFormatAttribute)attribute
-{
- int value = 0;
- [self getValues:&value forAttribute:attribute forVirtualScreen:0];
- return value;
-}
-@end
-
-@implementation NSOpenGLContext (QtHelpers)
-- (GLint)qt_getParameter:(NSOpenGLContextParameter)parameter
-{
- int value = 0;
- [self getValues:&value forParameter:parameter];
- return value;
-}
-@end
-
QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(lcQpaOpenGLContext, "qt.qpa.openglcontext", QtWarningMsg);
QCocoaGLContext::QCocoaGLContext(QOpenGLContext *context)
- : QPlatformOpenGLContext(), m_format(context->format())
+ : QPlatformOpenGLContext()
+ , m_format(context->format())
+{
+}
+
+void QCocoaGLContext::initialize()
{
- QVariant nativeHandle = context->nativeHandle();
+ QVariant nativeHandle = context()->nativeHandle();
if (!nativeHandle.isNull()) {
if (!nativeHandle.canConvert<QCocoaNativeContext>()) {
qCWarning(lcQpaOpenGLContext, "QOpenGLContext native handle must be a QCocoaNativeContext");
@@ -95,7 +84,7 @@ QCocoaGLContext::QCocoaGLContext(QOpenGLContext *context)
// Note: We have no way of knowing whether the NSOpenGLContext was created with the
// share context as reported by the QOpenGLContext, but we just have to trust that
// it was. It's okey, as the only thing we're using it for is to report isShared().
- if (QPlatformOpenGLContext *shareContext = context->shareHandle())
+ if (QPlatformOpenGLContext *shareContext = context()->shareHandle())
m_shareContext = static_cast<QCocoaGLContext *>(shareContext)->nativeContext();
updateSurfaceFormat();
@@ -110,7 +99,7 @@ QCocoaGLContext::QCocoaGLContext(QOpenGLContext *context)
if (m_format.renderableType() != QSurfaceFormat::OpenGL)
return;
- if (QPlatformOpenGLContext *shareContext = context->shareHandle()) {
+ if (QPlatformOpenGLContext *shareContext = context()->shareHandle()) {
m_shareContext = static_cast<QCocoaGLContext *>(shareContext)->nativeContext();
// Allow sharing between 3.2 Core and 4.1 Core profile versions in
@@ -150,6 +139,9 @@ QCocoaGLContext::QCocoaGLContext(QOpenGLContext *context)
return;
}
+ // The native handle should reflect the underlying context, even if we created it
+ context()->setNativeHandle(QVariant::fromValue<QCocoaNativeContext>(m_context));
+
// --------------------- Set NSOpenGLContext properties ---------------------
const GLint interval = m_format.swapInterval() >= 0 ? m_format.swapInterval() : 1;
@@ -285,7 +277,32 @@ void QCocoaGLContext::updateSurfaceFormat()
NSOpenGLPixelFormat *pixelFormat = m_context.pixelFormat;
- int colorSize = [pixelFormat qt_getAttribute:NSOpenGLPFAColorSize];
+ GLint virtualScreen = [&, this]() {
+ auto *platformScreen = static_cast<QCocoaScreen*>(context()->screen()->handle());
+ auto displayId = platformScreen->nativeScreen().qt_displayId;
+ auto requestedDisplay = CGDisplayIDToOpenGLDisplayMask(displayId);
+ for (int i = 0; i < pixelFormat.numberOfVirtualScreens; ++i) {
+ GLint supportedDisplays;
+ [pixelFormat getValues:&supportedDisplays forAttribute:NSOpenGLPFAScreenMask forVirtualScreen:i];
+ // Note: The mask returned for NSOpenGLPFAScreenMask is a bit mask of
+ // physical displays that the renderer can drive, while the one returned
+ // from CGDisplayIDToOpenGLDisplayMask has a single bit set, representing
+ // that particular display.
+ if (requestedDisplay & supportedDisplays)
+ return i;
+ }
+ qCWarning(lcQpaOpenGLContext) << "Could not find virtual screen for"
+ << platformScreen << "with displayId" << displayId;
+ return 0;
+ }();
+
+ auto pixelFormatAttribute = [&](NSOpenGLPixelFormatAttribute attribute) {
+ int value = 0;
+ [pixelFormat getValues:&value forAttribute:attribute forVirtualScreen:virtualScreen];
+ return value;
+ };
+
+ int colorSize = pixelFormatAttribute(NSOpenGLPFAColorSize);
colorSize /= 4; // The attribute includes the alpha component
m_format.setRedBufferSize(colorSize);
m_format.setGreenBufferSize(colorSize);
@@ -297,22 +314,28 @@ void QCocoaGLContext::updateSurfaceFormat()
// size, as that will make the user believe the alpha channel can be used for
// something useful, when in reality it can't, due to the surface being opaque.
if (m_format.alphaBufferSize() > 0)
- m_format.setAlphaBufferSize([pixelFormat qt_getAttribute:NSOpenGLPFAAlphaSize]);
+ m_format.setAlphaBufferSize(pixelFormatAttribute(NSOpenGLPFAAlphaSize));
- m_format.setDepthBufferSize([pixelFormat qt_getAttribute:NSOpenGLPFADepthSize]);
- m_format.setStencilBufferSize([pixelFormat qt_getAttribute:NSOpenGLPFAStencilSize]);
- m_format.setSamples([pixelFormat qt_getAttribute:NSOpenGLPFASamples]);
+ m_format.setDepthBufferSize(pixelFormatAttribute(NSOpenGLPFADepthSize));
+ m_format.setStencilBufferSize(pixelFormatAttribute(NSOpenGLPFAStencilSize));
+ m_format.setSamples(pixelFormatAttribute(NSOpenGLPFASamples));
- if ([pixelFormat qt_getAttribute:NSOpenGLPFATripleBuffer])
+ if (pixelFormatAttribute(NSOpenGLPFATripleBuffer))
m_format.setSwapBehavior(QSurfaceFormat::TripleBuffer);
- else if ([pixelFormat qt_getAttribute:NSOpenGLPFADoubleBuffer])
+ else if (pixelFormatAttribute(NSOpenGLPFADoubleBuffer))
m_format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
else
m_format.setSwapBehavior(QSurfaceFormat::SingleBuffer);
// ------------------- Query the context -------------------
- m_format.setSwapInterval([m_context qt_getParameter:NSOpenGLCPSwapInterval]);
+ auto glContextParameter = [&](NSOpenGLContextParameter parameter) {
+ int value = 0;
+ [m_context getValues:&value forParameter:parameter];
+ return value;
+ };
+
+ m_format.setSwapInterval(glContextParameter(NSOpenGLCPSwapInterval));
if (oldContext)
[oldContext makeCurrentContext];
diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm
index 08e7447a75..9a2f19c2f2 100644
--- a/src/plugins/platforms/cocoa/qcocoaintegration.mm
+++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm
@@ -215,25 +215,6 @@ QCocoaIntegration::QCocoaIntegration(const QStringList &paramList)
connect(qGuiApp, &QGuiApplication::focusWindowChanged,
this, &QCocoaIntegration::focusWindowChanged);
-
- static auto splashScreenHider = QMacKeyValueObserver(NSApp, @"modalWindow", []{
- const QWindowList allWindows = QGuiApplication::topLevelWindows();
- for (QWindow *window : allWindows) {
- if ((window->flags() & Qt::SplashScreen) == Qt::SplashScreen) {
- QCocoaWindow *platformWindow = static_cast<QCocoaWindow*>(window->handle());
- NSWindow *splashWindow = platformWindow->view().window;
- if (!splashWindow)
- continue;
- if (NSApp.modalWindow) {
- NSInteger originalLevel = splashWindow.level;
- splashWindow.level = NSNormalWindowLevel;
- window->setProperty("_q_levelBeforeModalSession", (qlonglong)originalLevel);
- } else if (NSInteger originalLevel = window->property("_q_levelBeforeModalSession").toLongLong()) {
- splashWindow.level = originalLevel;
- }
- }
- }
- });
}
QCocoaIntegration::~QCocoaIntegration()
@@ -331,9 +312,7 @@ QPlatformOffscreenSurface *QCocoaIntegration::createPlatformOffscreenSurface(QOf
#ifndef QT_NO_OPENGL
QPlatformOpenGLContext *QCocoaIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
{
- QCocoaGLContext *glContext = new QCocoaGLContext(context);
- context->setNativeHandle(QVariant::fromValue<QCocoaNativeContext>(glContext->nativeContext()));
- return glContext;
+ return new QCocoaGLContext(context);
}
#endif
diff --git a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm
index de5cf85854..db64702b8d 100644
--- a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm
+++ b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm
@@ -118,11 +118,13 @@ class QSystemTrayIconSys
public:
QSystemTrayIconSys(QCocoaSystemTrayIcon *sys) {
item = [[QNSStatusItem alloc] initWithSysTray:sys];
- [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:item];
+ NSUserNotificationCenter.defaultUserNotificationCenter.delegate = item;
}
~QSystemTrayIconSys() {
[[[item item] view] setHidden: YES];
- [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:nil];
+ NSUserNotificationCenter *center = NSUserNotificationCenter.defaultUserNotificationCenter;
+ if (center.delegate == item)
+ center.delegate = nil;
[item release];
}
QNSStatusItem *item;
@@ -264,7 +266,6 @@ bool QCocoaSystemTrayIcon::supportsMessages() const
void QCocoaSystemTrayIcon::showMessage(const QString &title, const QString &message,
const QIcon& icon, MessageIcon, int)
{
- Q_UNUSED(icon);
if (!m_sys)
return;
@@ -272,7 +273,16 @@ void QCocoaSystemTrayIcon::showMessage(const QString &title, const QString &mess
notification.title = [NSString stringWithUTF8String:title.toUtf8().data()];
notification.informativeText = [NSString stringWithUTF8String:message.toUtf8().data()];
- [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
+ if (!icon.isNull()) {
+ auto *nsimage = qt_mac_create_nsimage(icon);
+ [nsimage setTemplate:icon.isMask()];
+ notification.contentImage = [nsimage autorelease];
+ }
+
+ NSUserNotificationCenter *center = NSUserNotificationCenter.defaultUserNotificationCenter;
+ center.delegate = m_sys->item;
+ [center deliverNotification:notification];
+ [notification release];
}
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index 363a026e71..8f3c192745 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -454,13 +454,35 @@ NSInteger QCocoaWindow::windowLevel(Qt::WindowFlags flags)
if (type == Qt::ToolTip)
windowLevel = NSScreenSaverWindowLevel;
- // Any "special" window should be in at least the same level as its parent.
- if (type != Qt::Window) {
- const QWindow * const transientParent = window()->transientParent();
- const QCocoaWindow * const transientParentWindow = transientParent ?
- static_cast<QCocoaWindow *>(transientParent->handle()) : nullptr;
- if (transientParentWindow)
- windowLevel = qMax([transientParentWindow->nativeWindow() level], windowLevel);
+ auto *transientParent = window()->transientParent();
+ if (transientParent && transientParent->handle()) {
+ // We try to keep windows in at least the same window level as
+ // their transient parent. Unfortunately this only works when the
+ // window is created. If the window level changes after that, as
+ // a result of a call to setWindowFlags, or by changing the level
+ // of the native window, we will not pick this up, and the window
+ // will be left behind (or in a different window level than) its
+ // parent. We could KVO-observe the window level of our transient
+ // parent, but that requires us to know when the parent goes away
+ // so that we can unregister the observation before the parent is
+ // dealloced, something we can't do for generic NSWindows. Another
+ // way would be to override [NSWindow setLevel:] and notify child
+ // windows about the change, but that doesn't work for foreign
+ // windows, which can still be transient parents via fromWinId().
+ // One area where this problem is apparent is when AppKit tweaks
+ // the window level of modal windows during application activation
+ // and deactivation. Since we don't pick up on these window level
+ // changes in a generic way, we need to add logic explicitly to
+ // re-evaluate the window level after AppKit has done its tweaks.
+
+ auto *transientCocoaWindow = static_cast<QCocoaWindow *>(transientParent->handle());
+ auto *nsWindow = transientCocoaWindow->nativeWindow();
+
+ // We only upgrade the window level for "special" windows, to work
+ // around Qt Designer parenting the designer windows to the widget
+ // palette window (QTBUG-31779). This should be fixed in designer.
+ if (type != Qt::Window)
+ windowLevel = qMax(windowLevel, nsWindow.level);
}
return windowLevel;
@@ -1626,6 +1648,9 @@ QCocoaNSWindow *QCocoaWindow::createNSWindow(bool shouldBePanel)
[nsWindow setDepthLimit:NSWindowDepthTwentyfourBitRGB];
}
+ if (format().colorSpace() == QSurfaceFormat::sRGBColorSpace)
+ nsWindow.colorSpace = NSColorSpace.sRGBColorSpace;
+
return nsWindow;
}
diff --git a/src/corelib/thread/qmutexpool_p.h b/src/plugins/platforms/cocoa/qcocoawindowmanager.h
index 00710199b8..54f17eeccd 100644
--- a/src/corelib/thread/qmutexpool_p.h
+++ b/src/plugins/platforms/cocoa/qcocoawindowmanager.h
@@ -1,9 +1,9 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
-** This file is part of the QtCore module of the Qt Toolkit.
+** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
@@ -37,52 +37,27 @@
**
****************************************************************************/
-#ifndef QMUTEXPOOL_P_H
-#define QMUTEXPOOL_P_H
+#ifndef QCOCOAWINDOWMANAGER_H
+#define QCOCOAWINDOWMANAGER_H
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
+#include <QtCore/qglobal.h>
-#include <QtCore/private/qglobal_p.h>
-#include "QtCore/qatomic.h"
-#include "QtCore/qmutex.h"
-#include "QtCore/qvarlengtharray.h"
-
-QT_REQUIRE_CONFIG(thread);
+#include <AppKit/AppKit.h>
QT_BEGIN_NAMESPACE
-class Q_CORE_EXPORT QMutexPool
+class QCocoaWindowManager
{
public:
- explicit QMutexPool(QMutex::RecursionMode recursionMode = QMutex::NonRecursive, int size = 131);
- ~QMutexPool();
-
- inline QMutex *get(const void *address) {
- int index = uint(quintptr(address)) % mutexes.count();
- QMutex *m = mutexes[index].loadAcquire();
- if (m)
- return m;
- else
- return createMutex(index);
- }
- static QMutexPool *instance();
- static QMutex *globalInstanceGet(const void *address);
+ static QCocoaWindowManager *instance();
private:
- QMutex *createMutex(int index);
- QVarLengthArray<QAtomicPointer<QMutex>, 131> mutexes;
- QMutex::RecursionMode recursionMode;
+ QCocoaWindowManager();
+ void initialize();
+
+ void modalSessionChanged();
};
QT_END_NAMESPACE
-#endif // QMUTEXPOOL_P_H
+#endif // QCOCOAWINDOWMANAGER_H
diff --git a/src/plugins/platforms/cocoa/qcocoawindowmanager.mm b/src/plugins/platforms/cocoa/qcocoawindowmanager.mm
new file mode 100644
index 0000000000..879bfaa546
--- /dev/null
+++ b/src/plugins/platforms/cocoa/qcocoawindowmanager.mm
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qcocoawindowmanager.h"
+#include "qcocoawindow.h"
+
+#include <QtCore/private/qcore_mac_p.h>
+
+#include <QtGui/qguiapplication.h>
+#include <QtGui/qwindow.h>
+
+QT_BEGIN_NAMESPACE
+
+QCocoaWindowManager *QCocoaWindowManager::instance()
+{
+ static auto *instance = new QCocoaWindowManager;
+ return instance;
+}
+
+QCocoaWindowManager::QCocoaWindowManager()
+{
+ if (NSApp) {
+ initialize();
+ } else {
+ static auto applicationDidFinishLaunching(QMacNotificationObserver(nil,
+ NSApplicationDidFinishLaunchingNotification, [this] { initialize(); }));
+ }
+}
+
+void QCocoaWindowManager::initialize()
+{
+ Q_ASSERT(NSApp);
+
+ // Whenever the modalWindow property of NSApplication changes we have a new
+ // modal session running. Observing the app modal window instead of our own
+ // event dispatcher sessions allows us to track session started by native
+ // APIs as well. We need to check the initial state as well, in case there
+ // is already a modal session running.
+ static auto modalSessionObserver(QMacKeyValueObserver(
+ NSApp, @"modalWindow", [this] { modalSessionChanged(); },
+ NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew));
+}
+
+void QCocoaWindowManager::modalSessionChanged()
+{
+ // Make sure that no window is overlapping the modal window. This can
+ // happen for e.g. splash screens, which have the NSPopUpMenuWindowLevel.
+ for (auto *window : QGuiApplication::topLevelWindows()) {
+ auto *platformWindow = static_cast<QCocoaWindow*>(window->handle());
+ if (!platformWindow)
+ continue;
+
+ auto naturalWindowLevel = platformWindow->windowLevel(window->flags());
+ if (naturalWindowLevel > NSModalPanelWindowLevel) {
+ NSWindow *nativeWindow = platformWindow->nativeWindow();
+ if (NSApp.modalWindow) {
+ // Lower window to that of the modal windows, but no less
+ nativeWindow.level = NSModalPanelWindowLevel;
+ [nativeWindow orderBack:nil];
+ } else {
+ // Restore window's natural window level, whatever that was
+ nativeWindow.level = naturalWindowLevel;
+ }
+ }
+ }
+}
+
+static void initializeWindowManager() { Q_UNUSED(QCocoaWindowManager::instance()); }
+Q_CONSTRUCTOR_FUNCTION(initializeWindowManager)
+
+QT_END_NAMESPACE
+
diff --git a/src/plugins/platforms/cocoa/qprintengine_mac.mm b/src/plugins/platforms/cocoa/qprintengine_mac.mm
index f2f29b26ee..58ad53a6e1 100644
--- a/src/plugins/platforms/cocoa/qprintengine_mac.mm
+++ b/src/plugins/platforms/cocoa/qprintengine_mac.mm
@@ -522,16 +522,16 @@ void QMacPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va
if (mode == property(PPK_Duplex).toInt() || !d->m_printDevice->supportedDuplexModes().contains(mode))
break;
switch (mode) {
- case QPrinter::DuplexNone:
+ case QPrint::DuplexNone:
PMSetDuplex(d->settings(), kPMDuplexNone);
break;
- case QPrinter::DuplexAuto:
+ case QPrint::DuplexAuto:
PMSetDuplex(d->settings(), d->m_pageLayout.orientation() == QPageLayout::Landscape ? kPMDuplexTumble : kPMDuplexNoTumble);
break;
- case QPrinter::DuplexLongSide:
+ case QPrint::DuplexLongSide:
PMSetDuplex(d->settings(), kPMDuplexNoTumble);
break;
- case QPrinter::DuplexShortSide:
+ case QPrint::DuplexShortSide:
PMSetDuplex(d->settings(), kPMDuplexTumble);
break;
default:
diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.cpp
index 2c6b4245b7..3e78196227 100644
--- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.cpp
+++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.cpp
@@ -114,20 +114,16 @@ public:
: QEglFSWindow(w)
, m_integration(integration)
, m_egl_stream(EGL_NO_STREAM_KHR)
- , m_framePending(false)
{ }
~QEglFSKmsEglDeviceWindow() { destroy(); }
void invalidateSurface() override;
void resetSurface() override;
- void flip();
- static void pageFlipHandler(int fd, unsigned int sequence, unsigned int tv_sec, unsigned int tv_usec, void *user_data);
const QEglFSKmsEglDeviceIntegration *m_integration;
EGLStreamKHR m_egl_stream;
EGLint m_latency;
- bool m_framePending;
};
void QEglFSKmsEglDeviceWindow::invalidateSurface()
@@ -148,9 +144,6 @@ void QEglFSKmsEglDeviceWindow::resetSurface()
streamAttribs[streamAttribCount++] = EGL_STREAM_FIFO_LENGTH_KHR;
streamAttribs[streamAttribCount++] = fifoLength;
}
-
- streamAttribs[streamAttribCount++] = EGL_CONSUMER_AUTO_ACQUIRE_EXT;
- streamAttribs[streamAttribCount++] = EGL_FALSE;
streamAttribs[streamAttribCount++] = EGL_NONE;
m_egl_stream = m_integration->m_funcs->create_stream(display, streamAttribs);
@@ -248,49 +241,6 @@ void QEglFSKmsEglDeviceWindow::resetSurface()
qCDebug(qLcEglfsKmsDebug, "Created stream producer surface %p", m_surface);
}
-void QEglFSKmsEglDeviceWindow::flip()
-{
- EGLDisplay display = screen()->display();
-
- EGLAttrib acquire_attribs[3] = { EGL_NONE };
-
- acquire_attribs[0] = EGL_DRM_FLIP_EVENT_DATA_NV;
- acquire_attribs[1] = (EGLAttrib)this;
- acquire_attribs[2] = EGL_NONE;
-
- if (m_egl_stream != EGL_NO_STREAM_KHR)
- if (!m_integration->m_funcs->acquire_stream_attrib_nv(display, m_egl_stream, acquire_attribs))
- qWarning("eglStreamConsumerAcquireAttribNV failed: eglError: %x", eglGetError());
-
- m_framePending = true;
-
- while (m_framePending) {
- drmEventContext drmEvent;
- memset(&drmEvent, 0, sizeof(drmEvent));
- drmEvent.version = 3;
- drmEvent.vblank_handler = nullptr;
- drmEvent.page_flip_handler = pageFlipHandler;
- drmHandleEvent(m_integration->m_device->fd(), &drmEvent);
- }
-}
-
-void QEglFSKmsEglDeviceWindow::pageFlipHandler(int fd, unsigned int sequence, unsigned int tv_sec, unsigned int tv_usec, void *user_data)
-{
- Q_UNUSED(fd);
- Q_UNUSED(sequence);
- Q_UNUSED(tv_sec);
- Q_UNUSED(tv_usec);
-
- QEglFSKmsEglDeviceWindow *window = static_cast<QEglFSKmsEglDeviceWindow*>(user_data);
- window->m_framePending = false;
-}
-
-void QEglFSKmsEglDeviceIntegration::presentBuffer(QPlatformSurface *surface)
-{
- QEglFSKmsEglDeviceWindow *eglWindow = static_cast<QEglFSKmsEglDeviceWindow*>(surface);
- eglWindow->flip();
-}
-
QEglFSWindow *QEglFSKmsEglDeviceIntegration::createWindow(QWindow *window) const
{
QEglFSKmsEglDeviceWindow *eglWindow = new QEglFSKmsEglDeviceWindow(window, this);
diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.h b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.h
index a5697ec831..5819d82ebf 100644
--- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.h
+++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.h
@@ -62,8 +62,6 @@ public:
bool supportsPBuffers() const override;
QEglFSWindow *createWindow(QWindow *window) const override;
- void presentBuffer(QPlatformSurface *surface) override;
-
EGLDeviceEXT eglDevice() const { return m_egl_device; }
protected:
diff --git a/src/plugins/platforms/wasm/qwasmcompositor.cpp b/src/plugins/platforms/wasm/qwasmcompositor.cpp
index 6d211667be..a810880c43 100644
--- a/src/plugins/platforms/wasm/qwasmcompositor.cpp
+++ b/src/plugins/platforms/wasm/qwasmcompositor.cpp
@@ -681,7 +681,7 @@ void QWasmCompositor::frame()
QWasmWindow *someWindow = nullptr;
- foreach (QWasmWindow *window, m_windowStack) {
+ for (QWasmWindow *window : qAsConst(m_windowStack)) {
if (window->window()->surfaceClass() == QSurface::Window
&& qt_window_private(static_cast<QWindow *>(window->window()))->receivedExpose) {
someWindow = window;
@@ -715,7 +715,7 @@ void QWasmCompositor::frame()
m_blitter->bind();
m_blitter->setRedBlueSwizzle(true);
- foreach (QWasmWindow *window, m_windowStack) {
+ for (QWasmWindow *window : qAsConst(m_windowStack)) {
QWasmCompositedWindow &compositedWindow = m_compositedWindows[window];
if (!compositedWindow.visible)
diff --git a/src/plugins/platforms/wasm/qwasmeventtranslator.cpp b/src/plugins/platforms/wasm/qwasmeventtranslator.cpp
index 3895646b89..ad94ba9c77 100644
--- a/src/plugins/platforms/wasm/qwasmeventtranslator.cpp
+++ b/src/plugins/platforms/wasm/qwasmeventtranslator.cpp
@@ -138,16 +138,16 @@ static constexpr const auto KeyTbl = qMakeArray(
Emkb2Qt< Qt::Key_Minus, '-' >,
Emkb2Qt< Qt::Key_Period, '.' >,
Emkb2Qt< Qt::Key_Slash, '/' >,
- Emkb2Qt< Qt::Key_0, '0' >,
- Emkb2Qt< Qt::Key_1, '1' >,
- Emkb2Qt< Qt::Key_2, '2' >,
- Emkb2Qt< Qt::Key_3, '3' >,
- Emkb2Qt< Qt::Key_4, '4' >,
- Emkb2Qt< Qt::Key_5, '5' >,
- Emkb2Qt< Qt::Key_6, '6' >,
- Emkb2Qt< Qt::Key_7, '7' >,
- Emkb2Qt< Qt::Key_8, '8' >,
- Emkb2Qt< Qt::Key_9, '9' >,
+ Emkb2Qt< Qt::Key_0, 'D','i','g','i','t','0' >,
+ Emkb2Qt< Qt::Key_1, 'D','i','g','i','t','1' >,
+ Emkb2Qt< Qt::Key_2, 'D','i','g','i','t','2' >,
+ Emkb2Qt< Qt::Key_3, 'D','i','g','i','t','3' >,
+ Emkb2Qt< Qt::Key_4, 'D','i','g','i','t','4' >,
+ Emkb2Qt< Qt::Key_5, 'D','i','g','i','t','5' >,
+ Emkb2Qt< Qt::Key_6, 'D','i','g','i','t','6' >,
+ Emkb2Qt< Qt::Key_7, 'D','i','g','i','t','7' >,
+ Emkb2Qt< Qt::Key_8, 'D','i','g','i','t','8' >,
+ Emkb2Qt< Qt::Key_9, 'D','i','g','i','t','9' >,
Emkb2Qt< Qt::Key_Semicolon, ';' >,
Emkb2Qt< Qt::Key_Equal, '=' >,
Emkb2Qt< Qt::Key_A, 'K','e','y','A' >,
@@ -432,7 +432,8 @@ Qt::Key QWasmEventTranslator::translateEmscriptKey(const EmscriptenKeyboardEvent
{
Qt::Key qtKey = Qt::Key_unknown;
- if (qstrncmp(emscriptKey->code, "Key", 3) == 0 || qstrncmp(emscriptKey->code, "Numpad", 6) == 0) {
+ if (qstrncmp(emscriptKey->code, "Key", 3) == 0 || qstrncmp(emscriptKey->code, "Numpad", 6) == 0 ||
+ qstrncmp(emscriptKey->code, "Digit", 5) == 0) {
emkb2qt_t searchKey{emscriptKey->code, 0}; // search emcsripten code
auto it1 = std::lower_bound(KeyTbl.cbegin(), KeyTbl.cend(), searchKey);
@@ -779,6 +780,60 @@ quint64 QWasmEventTranslator::getTimestamp()
return QDeadlineTimer::current().deadlineNSecs() / 1000;
}
+struct KeyMapping { Qt::Key from, to; };
+
+constexpr KeyMapping tildeKeyTable[] = { // ~
+ { Qt::Key_A, Qt::Key_Atilde },
+ { Qt::Key_N, Qt::Key_Ntilde },
+ { Qt::Key_O, Qt::Key_Otilde },
+};
+constexpr KeyMapping graveKeyTable[] = { // `
+ { Qt::Key_A, Qt::Key_Agrave },
+ { Qt::Key_E, Qt::Key_Egrave },
+ { Qt::Key_I, Qt::Key_Igrave },
+ { Qt::Key_O, Qt::Key_Ograve },
+ { Qt::Key_U, Qt::Key_Ugrave },
+};
+constexpr KeyMapping acuteKeyTable[] = { // '
+ { Qt::Key_A, Qt::Key_Aacute },
+ { Qt::Key_E, Qt::Key_Eacute },
+ { Qt::Key_I, Qt::Key_Iacute },
+ { Qt::Key_O, Qt::Key_Oacute },
+ { Qt::Key_U, Qt::Key_Uacute },
+ { Qt::Key_Y, Qt::Key_Yacute },
+};
+constexpr KeyMapping diaeresisKeyTable[] = { // umlaut ¨
+ { Qt::Key_A, Qt::Key_Adiaeresis },
+ { Qt::Key_E, Qt::Key_Ediaeresis },
+ { Qt::Key_I, Qt::Key_Idiaeresis },
+ { Qt::Key_O, Qt::Key_Odiaeresis },
+ { Qt::Key_U, Qt::Key_Udiaeresis },
+ { Qt::Key_Y, Qt::Key_ydiaeresis },
+};
+constexpr KeyMapping circumflexKeyTable[] = { // ^
+ { Qt::Key_A, Qt::Key_Acircumflex },
+ { Qt::Key_E, Qt::Key_Ecircumflex },
+ { Qt::Key_I, Qt::Key_Icircumflex },
+ { Qt::Key_O, Qt::Key_Ocircumflex },
+ { Qt::Key_U, Qt::Key_Ucircumflex },
+};
+
+static Qt::Key find_impl(const KeyMapping *first, const KeyMapping *last, Qt::Key key) noexcept
+{
+ while (first != last) {
+ if (first->from == key)
+ return first->to;
+ ++first;
+ }
+ return Qt::Key_unknown;
+}
+
+template <size_t N>
+static Qt::Key find(const KeyMapping (&map)[N], Qt::Key key) noexcept
+{
+ return find_impl(map, map + N, key);
+}
+
Qt::Key QWasmEventTranslator::translateDeadKey(Qt::Key deadKey, Qt::Key accentBaseKey)
{
Qt::Key wasmKey = Qt::Key_unknown;
@@ -788,31 +843,30 @@ Qt::Key QWasmEventTranslator::translateDeadKey(Qt::Key deadKey, Qt::Key accentBa
#else
case Qt::Key_O: // ´ Key_Dead_Grave
#endif
- wasmKey = graveKeyTable.value(accentBaseKey);
+ wasmKey = find(graveKeyTable, accentBaseKey);
break;
case Qt::Key_E: // ´ Key_Dead_Acute
- wasmKey = acuteKeyTable.value(accentBaseKey);
+ wasmKey = find(acuteKeyTable, accentBaseKey);
break;
case Qt::Key_AsciiTilde:
case Qt::Key_N:// Key_Dead_Tilde
- wasmKey = tildeKeyTable.value(accentBaseKey);
+ wasmKey = find(tildeKeyTable, accentBaseKey);
break;
#ifndef Q_OS_MACOS
case Qt::Key_QuoteLeft:
#endif
case Qt::Key_U:// ¨ Key_Dead_Diaeresis
- wasmKey = diaeresisKeyTable.value(accentBaseKey);
+ wasmKey = find(diaeresisKeyTable, accentBaseKey);
break;
case Qt::Key_I:// macOS Key_Dead_Circumflex
case Qt::Key_6:// linux
case Qt::Key_Apostrophe:// linux
- wasmKey = circumflexKeyTable.value(accentBaseKey);
- break;
+ wasmKey = find(circumflexKeyTable, accentBaseKey);
break;
default:
break;
- };
+ };
return wasmKey;
}
diff --git a/src/plugins/platforms/wasm/qwasmeventtranslator.h b/src/plugins/platforms/wasm/qwasmeventtranslator.h
index 1655b7226a..568ae00732 100644
--- a/src/plugins/platforms/wasm/qwasmeventtranslator.h
+++ b/src/plugins/platforms/wasm/qwasmeventtranslator.h
@@ -77,42 +77,6 @@ private:
Qt::Key translateDeadKey(Qt::Key deadKey, Qt::Key accentBaseKey);
- QHash<Qt::Key , Qt::Key> tildeKeyTable { // ~
- { Qt::Key_A, Qt::Key_Atilde},
- { Qt::Key_N, Qt::Key_Ntilde},
- { Qt::Key_O, Qt::Key_Otilde}
- };
- QHash<Qt::Key , Qt::Key> graveKeyTable { // `
- { Qt::Key_A, Qt::Key_Agrave},
- { Qt::Key_E, Qt::Key_Egrave},
- { Qt::Key_I, Qt::Key_Igrave},
- { Qt::Key_O, Qt::Key_Ograve},
- { Qt::Key_U, Qt::Key_Ugrave}
- };
- QHash<Qt::Key , Qt::Key> acuteKeyTable { // '
- { Qt::Key_A, Qt::Key_Aacute},
- { Qt::Key_E, Qt::Key_Eacute},
- { Qt::Key_I, Qt::Key_Iacute},
- { Qt::Key_O, Qt::Key_Oacute},
- { Qt::Key_U, Qt::Key_Uacute},
- { Qt::Key_Y, Qt::Key_Yacute}
- };
- QHash<Qt::Key , Qt::Key> diaeresisKeyTable { // umlaut ¨
- { Qt::Key_A, Qt::Key_Adiaeresis},
- { Qt::Key_E, Qt::Key_Ediaeresis},
- { Qt::Key_I, Qt::Key_Idiaeresis},
- { Qt::Key_O, Qt::Key_Odiaeresis},
- { Qt::Key_U, Qt::Key_Udiaeresis},
- { Qt::Key_Y, Qt::Key_ydiaeresis}
- };
- QHash<Qt::Key , Qt::Key> circumflexKeyTable { // ^
- { Qt::Key_A, Qt::Key_Acircumflex},
- { Qt::Key_E, Qt::Key_Ecircumflex},
- { Qt::Key_I, Qt::Key_Icircumflex},
- { Qt::Key_O, Qt::Key_Ocircumflex},
- { Qt::Key_U, Qt::Key_Ucircumflex}
- };
-
QMap <int, QPointF> pressedTouchIds;
private:
diff --git a/src/plugins/platforms/wasm/qwasmfontdatabase.cpp b/src/plugins/platforms/wasm/qwasmfontdatabase.cpp
index dc6bb5847e..53e875ead6 100644
--- a/src/plugins/platforms/wasm/qwasmfontdatabase.cpp
+++ b/src/plugins/platforms/wasm/qwasmfontdatabase.cpp
@@ -38,10 +38,13 @@ void QWasmFontDatabase::populateFontDatabase()
// Load font file from resources. Currently
// all fonts needs to be bundled with the nexe
// as Qt resources.
- QStringList fontFileNames = QStringList() << QStringLiteral(":/fonts/DejaVuSansMono.ttf")
- << QStringLiteral(":/fonts/Vera.ttf")
- << QStringLiteral(":/fonts/DejaVuSans.ttf");
- foreach (const QString &fontFileName, fontFileNames) {
+
+ const QString fontFileNames[] = {
+ QStringLiteral(":/fonts/DejaVuSansMono.ttf"),
+ QStringLiteral(":/fonts/Vera.ttf"),
+ QStringLiteral(":/fonts/DejaVuSans.ttf"),
+ };
+ for (const QString &fontFileName : fontFileNames) {
QFile theFont(fontFileName);
if (!theFont.open(QIODevice::ReadOnly))
break;
diff --git a/src/plugins/platforms/wasm/wasm.pro b/src/plugins/platforms/wasm/wasm.pro
index c28df8f893..f8c8175525 100644
--- a/src/plugins/platforms/wasm/wasm.pro
+++ b/src/plugins/platforms/wasm/wasm.pro
@@ -7,6 +7,8 @@ QT += \
# Avoid X11 header collision, use generic EGL native types
DEFINES += QT_EGL_NO_X11
+DEFINES += QT_NO_FOREACH
+
SOURCES = \
main.cpp \
qwasmintegration.cpp \
diff --git a/src/plugins/platforms/windows/qwindowsinputcontext.cpp b/src/plugins/platforms/windows/qwindowsinputcontext.cpp
index e681dbb0cb..d5258ca6a3 100644
--- a/src/plugins/platforms/windows/qwindowsinputcontext.cpp
+++ b/src/plugins/platforms/windows/qwindowsinputcontext.cpp
@@ -47,6 +47,7 @@
#include <QtCore/qobject.h>
#include <QtCore/qrect.h>
#include <QtCore/qtextboundaryfinder.h>
+#include <QtCore/qoperatingsystemversion.h>
#include <QtGui/qevent.h>
#include <QtGui/qtextformat.h>
@@ -279,7 +280,13 @@ void QWindowsInputContext::showInputPanel()
// with Windows 10 if the Windows IME is (re)enabled _after_ the caret is shown.
if (m_caretCreated) {
cursorRectChanged();
- ShowCaret(platformWindow->handle());
+ // We only call ShowCaret() on Windows 10 as in earlier versions the caret
+ // would actually be visible (QTBUG-74492) and the workaround for the
+ // Surface seems unnecessary there anyway. But leave it hidden for IME.
+ if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows10)
+ ShowCaret(platformWindow->handle());
+ else
+ HideCaret(platformWindow->handle());
setWindowsImeEnabled(platformWindow, false);
setWindowsImeEnabled(platformWindow, true);
}
diff --git a/src/plugins/platforms/windows/qwindowskeymapper.cpp b/src/plugins/platforms/windows/qwindowskeymapper.cpp
index 4b54051e0c..4f0f846749 100644
--- a/src/plugins/platforms/windows/qwindowskeymapper.cpp
+++ b/src/plugins/platforms/windows/qwindowskeymapper.cpp
@@ -1301,7 +1301,23 @@ bool QWindowsKeyMapper::translateKeyEventInternal(QWindow *window, MSG msg,
|| code == Qt::Key_Control
|| code == Qt::Key_Meta
|| code == Qt::Key_Alt)) {
- // Someone ate the key down event
+
+ // Workaround for QTBUG-77153:
+ // The Surface Pen eraser button generates Meta+F18/19/20 keystrokes,
+ // but when it is not touching the screen the Fn Down is eaten and only
+ // a Fn Up with the previous state as "not pressed" is generated, which
+ // would be ignored. We detect this case and synthesize the expected events.
+ if ((msg.lParam & 0x40000000) == 0 &&
+ Qt::KeyboardModifier(state) == Qt::NoModifier &&
+ ((code == Qt::Key_F18) || (code == Qt::Key_F19) || (code == Qt::Key_F20))) {
+ QWindowSystemInterface::handleExtendedKeyEvent(receiver, QEvent::KeyPress, code,
+ Qt::MetaModifier, scancode,
+ quint32(msg.wParam), MetaLeft);
+ QWindowSystemInterface::handleExtendedKeyEvent(receiver, QEvent::KeyRelease, code,
+ Qt::NoModifier, scancode,
+ quint32(msg.wParam), 0);
+ result = true;
+ }
} else {
if (!code)
code = asciiToKeycode(rec->ascii ? char(rec->ascii) : char(msg.wParam), state);
diff --git a/src/plugins/platforms/windows/qwindowspointerhandler.cpp b/src/plugins/platforms/windows/qwindowspointerhandler.cpp
index b3d961db72..cffd8427a2 100644
--- a/src/plugins/platforms/windows/qwindowspointerhandler.cpp
+++ b/src/plugins/platforms/windows/qwindowspointerhandler.cpp
@@ -80,13 +80,12 @@ bool QWindowsPointerHandler::translatePointerEvent(QWindow *window, HWND hwnd, Q
*result = 0;
const quint32 pointerId = GET_POINTERID_WPARAM(msg.wParam);
- POINTER_INPUT_TYPE pointerType;
- if (!QWindowsContext::user32dll.getPointerType(pointerId, &pointerType)) {
+ if (!QWindowsContext::user32dll.getPointerType(pointerId, &m_pointerType)) {
qWarning() << "GetPointerType() failed:" << qt_error_string();
return false;
}
- switch (pointerType) {
+ switch (m_pointerType) {
case QT_PT_POINTER:
case QT_PT_MOUSE:
case QT_PT_TOUCHPAD: {
@@ -684,7 +683,7 @@ bool QWindowsPointerHandler::translateMouseWheelEvent(QWindow *window,
QPoint localPos = QWindowsGeometryHint::mapFromGlobal(receiver, globalPos);
- QWindowSystemInterface::handleWheelEvent(window, localPos, globalPos, QPoint(), angleDelta, keyModifiers);
+ QWindowSystemInterface::handleWheelEvent(receiver, localPos, globalPos, QPoint(), angleDelta, keyModifiers);
return true;
}
@@ -734,7 +733,11 @@ bool QWindowsPointerHandler::translateMouseEvent(QWindow *window,
}
Qt::MouseEventSource source = Qt::MouseEventNotSynthesized;
- if (isMouseEventSynthesizedFromPenOrTouch()) {
+ // Following the logic of the old mouse handler, only events synthesized
+ // for touch screen are marked as such. On some systems, using the bit 7 of
+ // the extra msg info for checking if synthesized for touch does not work,
+ // so we use the pointer type of the last pointer message.
+ if (isMouseEventSynthesizedFromPenOrTouch() && m_pointerType == QT_PT_TOUCH) {
if (QWindowsIntegration::instance()->options() & QWindowsIntegration::DontPassOsMouseEventsSynthesizedFromTouch)
return false;
source = Qt::MouseEventSynthesizedBySystem;
diff --git a/src/plugins/platforms/windows/qwindowspointerhandler.h b/src/plugins/platforms/windows/qwindowspointerhandler.h
index 068e804007..8874db27e3 100644
--- a/src/plugins/platforms/windows/qwindowspointerhandler.h
+++ b/src/plugins/platforms/windows/qwindowspointerhandler.h
@@ -82,6 +82,7 @@ private:
bool m_needsEnterOnPointerUpdate = false;
QEvent::Type m_lastEventType = QEvent::None;
Qt::MouseButton m_lastEventButton = Qt::NoButton;
+ DWORD m_pointerType = 0;
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp
index d919d97211..282c0b107e 100644
--- a/src/plugins/platforms/windows/qwindowsscreen.cpp
+++ b/src/plugins/platforms/windows/qwindowsscreen.cpp
@@ -303,23 +303,28 @@ void QWindowsScreen::handleChanges(const QWindowsScreenData &newData)
m_data.hMonitor = newData.hMonitor;
}
- if (m_data.geometry != newData.geometry || m_data.availableGeometry != newData.availableGeometry) {
- m_data.geometry = newData.geometry;
- m_data.availableGeometry = newData.availableGeometry;
- QWindowSystemInterface::handleScreenGeometryChange(screen(),
- newData.geometry, newData.availableGeometry);
- }
- if (!qFuzzyCompare(m_data.dpi.first, newData.dpi.first)
- || !qFuzzyCompare(m_data.dpi.second, newData.dpi.second)) {
- m_data.dpi = newData.dpi;
+ // QGuiApplicationPrivate::processScreenGeometryChange() checks and emits
+ // DPI and orientation as well, so, assign new values and emit DPI first.
+ const bool geometryChanged = m_data.geometry != newData.geometry
+ || m_data.availableGeometry != newData.availableGeometry;
+ const bool dpiChanged = !qFuzzyCompare(m_data.dpi.first, newData.dpi.first)
+ || !qFuzzyCompare(m_data.dpi.second, newData.dpi.second);
+ const bool orientationChanged = m_data.orientation != newData.orientation;
+ m_data.dpi = newData.dpi;
+ m_data.orientation = newData.orientation;
+ m_data.geometry = newData.geometry;
+ m_data.availableGeometry = newData.availableGeometry;
+
+ if (dpiChanged) {
QWindowSystemInterface::handleScreenLogicalDotsPerInchChange(screen(),
newData.dpi.first,
newData.dpi.second);
}
- if (m_data.orientation != newData.orientation) {
- m_data.orientation = newData.orientation;
- QWindowSystemInterface::handleScreenOrientationChange(screen(),
- newData.orientation);
+ if (orientationChanged)
+ QWindowSystemInterface::handleScreenOrientationChange(screen(), newData.orientation);
+ if (geometryChanged) {
+ QWindowSystemInterface::handleScreenGeometryChange(screen(),
+ newData.geometry, newData.availableGeometry);
}
}
diff --git a/src/plugins/platforms/winrt/qwinrtfileengine.cpp b/src/plugins/platforms/winrt/qwinrtfileengine.cpp
index 3014b30c38..962e4ab938 100644
--- a/src/plugins/platforms/winrt/qwinrtfileengine.cpp
+++ b/src/plugins/platforms/winrt/qwinrtfileengine.cpp
@@ -43,6 +43,7 @@
#include <QtCore/QCoreApplication>
#include <QtCore/QHash>
#include <QtCore/qfunctions_winrt.h>
+#include <QtCore/private/qfsfileengine_p.h>
#include <wrl.h>
#include <windows.storage.h>
@@ -196,7 +197,19 @@ bool QWinRTFileEngine::open(QIODevice::OpenMode openMode)
hr = QWinRTFunctions::await(op, d->stream.GetAddressOf());
RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::OpenError, false);
- d->openMode = openMode;
+ const ProcessOpenModeResult res = processOpenModeFlags(openMode);
+ if (!res.ok) {
+ setError(QFileDevice::OpenError, res.error);
+ return false;
+ }
+ d->openMode = res.openMode;
+ if (d->openMode & QIODevice::Truncate) {
+ if (!setSize(0)) {
+ close();
+ setError(QFileDevice::OpenError, QLatin1String("Could not truncate file"));
+ return false;
+ }
+ }
return SUCCEEDED(hr);
}
@@ -257,6 +270,29 @@ qint64 QWinRTFileEngine::size() const
return qint64(size);
}
+bool QWinRTFileEngine::setSize(qint64 size)
+{
+ Q_D(QWinRTFileEngine);
+ if (!d->stream) {
+ setError(QFileDevice::ResizeError, QLatin1String("File must be open to be resized"));
+ return false;
+ }
+
+ if (size < 0) {
+ setError(QFileDevice::ResizeError, QLatin1String("File size cannot be negative"));
+ return false;
+ }
+
+ HRESULT hr = d->stream->put_Size(static_cast<quint64>(size));
+ RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::ResizeError, false);
+ if (!flush()) {
+ setError(QFileDevice::ResizeError, QLatin1String("Could not flush file"));
+ return false;
+ }
+
+ return true;
+}
+
qint64 QWinRTFileEngine::pos() const
{
Q_D(const QWinRTFileEngine);
diff --git a/src/plugins/platforms/winrt/qwinrtfileengine.h b/src/plugins/platforms/winrt/qwinrtfileengine.h
index 4485917c9e..453565a95a 100644
--- a/src/plugins/platforms/winrt/qwinrtfileengine.h
+++ b/src/plugins/platforms/winrt/qwinrtfileengine.h
@@ -79,6 +79,7 @@ public:
bool close() override;
bool flush() override;
qint64 size() const override;
+ bool setSize(qint64 size) override;
qint64 pos() const override;
bool seek(qint64 pos) override;
bool remove() override;
diff --git a/src/plugins/platforms/winrt/qwinrtscreen.cpp b/src/plugins/platforms/winrt/qwinrtscreen.cpp
index 0d77889a36..86ab7651c6 100644
--- a/src/plugins/platforms/winrt/qwinrtscreen.cpp
+++ b/src/plugins/platforms/winrt/qwinrtscreen.cpp
@@ -669,12 +669,6 @@ QDpi QWinRTScreen::logicalDpi() const
return QDpi(d->logicalDpi, d->logicalDpi);
}
-qreal QWinRTScreen::pixelDensity() const
-{
- Q_D(const QWinRTScreen);
- return qMax(1, qRound(d->logicalDpi / 96));
-}
-
qreal QWinRTScreen::scaleFactor() const
{
Q_D(const QWinRTScreen);
diff --git a/src/plugins/platforms/winrt/qwinrtscreen.h b/src/plugins/platforms/winrt/qwinrtscreen.h
index 63c254940d..6b57780fa1 100644
--- a/src/plugins/platforms/winrt/qwinrtscreen.h
+++ b/src/plugins/platforms/winrt/qwinrtscreen.h
@@ -96,7 +96,6 @@ public:
QImage::Format format() const override;
QSizeF physicalSize() const override;
QDpi logicalDpi() const override;
- qreal pixelDensity() const override;
qreal scaleFactor() const;
QPlatformCursor *cursor() const override;
Qt::KeyboardModifiers keyboardModifiers() const;
diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp
index d27a288feb..cac6345b66 100644
--- a/src/plugins/platforms/xcb/qxcbconnection.cpp
+++ b/src/plugins/platforms/xcb/qxcbconnection.cpp
@@ -132,7 +132,9 @@ QXcbConnection::QXcbConnection(QXcbNativeInterface *nativeInterface, bool canGra
if (!m_startupId.isNull())
qunsetenv("DESKTOP_STARTUP_ID");
+ const int focusInDelay = 100;
m_focusInTimer.setSingleShot(true);
+ m_focusInTimer.setInterval(focusInDelay);
m_focusInTimer.callOnTimeout([]() {
// No FocusIn events for us, proceed with FocusOut normally.
QWindowSystemInterface::handleWindowActivated(nullptr, Qt::ActiveWindowFocusReason);
diff --git a/src/plugins/platforms/xcb/qxcbeventqueue.cpp b/src/plugins/platforms/xcb/qxcbeventqueue.cpp
index 82a36c0727..759ee3cc95 100644
--- a/src/plugins/platforms/xcb/qxcbeventqueue.cpp
+++ b/src/plugins/platforms/xcb/qxcbeventqueue.cpp
@@ -226,11 +226,13 @@ void QXcbEventQueue::run()
};
while (!m_closeConnectionDetected && (event = xcb_wait_for_event(connection))) {
+ m_newEventsMutex.lock();
enqueueEvent(event);
while (!m_closeConnectionDetected && (event = xcb_poll_for_queued_event(connection)))
enqueueEvent(event);
m_newEventsCondition.wakeOne();
+ m_newEventsMutex.unlock();
wakeUpDispatcher();
}
@@ -350,9 +352,12 @@ bool QXcbEventQueue::peekEventQueue(PeekerCallback peeker, void *peekerData,
void QXcbEventQueue::waitForNewEvents(unsigned long time)
{
- m_newEventsMutex.lock();
+ QMutexLocker locker(&m_newEventsMutex);
+ QXcbEventNode *tailBeforeFlush = m_flushedTail;
+ flushBufferedEvents();
+ if (tailBeforeFlush != m_flushedTail)
+ return;
m_newEventsCondition.wait(&m_newEventsMutex, time);
- m_newEventsMutex.unlock();
}
void QXcbEventQueue::sendCloseConnectionEvent() const
diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp
index 396b47001d..1d1a4eea1c 100644
--- a/src/plugins/platforms/xcb/qxcbwindow.cpp
+++ b/src/plugins/platforms/xcb/qxcbwindow.cpp
@@ -848,7 +848,7 @@ void QXcbWindow::doFocusOut()
connection()->setFocusWindow(nullptr);
relayFocusToModalWindow();
// Do not set the active window to nullptr if there is a FocusIn coming.
- connection()->focusInTimer().start(400);
+ connection()->focusInTimer().start();
}
struct QtMotifWmHints {
diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp
index bf9424897d..0bae45382d 100644
--- a/src/plugins/sqldrivers/psql/qsql_psql.cpp
+++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp
@@ -1506,7 +1506,7 @@ QString QPSQLDriver::formatValue(const QSqlField &field, bool trimStrings) const
// this is safe since postgresql stores only the UTC value and not the timezone offset (only used
// while parsing), so we have correct behavior in both case of with timezone and without tz
r = QStringLiteral("TIMESTAMP WITH TIME ZONE ") + QLatin1Char('\'') +
- QLocale::c().toString(field.value().toDateTime().toUTC(), QStringViewLiteral("yyyy-MM-ddThh:mm:ss.zzz")) +
+ QLocale::c().toString(field.value().toDateTime().toUTC(), u"yyyy-MM-ddThh:mm:ss.zzz") +
QLatin1Char('Z') + QLatin1Char('\'');
} else {
r = nullStr();
@@ -1518,7 +1518,7 @@ QString QPSQLDriver::formatValue(const QSqlField &field, bool trimStrings) const
case QVariant::Time:
#if QT_CONFIG(datestring)
if (field.value().toTime().isValid()) {
- r = QLatin1Char('\'') + field.value().toTime().toString(QStringViewLiteral("hh:mm:ss.zzz")) + QLatin1Char('\'');
+ r = QLatin1Char('\'') + field.value().toTime().toString(u"hh:mm:ss.zzz") + QLatin1Char('\'');
} else
#endif
{
diff --git a/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp b/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp
index f1a003ddcd..001bd673fc 100644
--- a/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp
+++ b/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp
@@ -531,7 +531,7 @@ bool QSQLiteResult::exec()
}
case QVariant::Time: {
const QTime time = value.toTime();
- const QString str = time.toString(QStringViewLiteral("hh:mm:ss.zzz"));
+ const QString str = time.toString(u"hh:mm:ss.zzz");
res = sqlite3_bind_text16(d->stmt, i + 1, str.utf16(),
str.size() * sizeof(ushort), SQLITE_TRANSIENT);
break;
diff --git a/src/plugins/sqldrivers/tds/qsql_tds.cpp b/src/plugins/sqldrivers/tds/qsql_tds.cpp
index 603372230d..9c8d242028 100644
--- a/src/plugins/sqldrivers/tds/qsql_tds.cpp
+++ b/src/plugins/sqldrivers/tds/qsql_tds.cpp
@@ -813,7 +813,7 @@ QString QTDSDriver::formatValue(const QSqlField &field,
r = QLatin1String("NULL");
else if (field.type() == QVariant::DateTime) {
if (field.value().toDateTime().isValid()){
- r = field.value().toDateTime().toString(QStringViewLiteral("yyyyMMdd hh:mm:ss"));
+ r = field.value().toDateTime().toString(u"yyyyMMdd hh:mm:ss");
r.prepend(QLatin1String("'"));
r.append(QLatin1String("'"));
} else
diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm
index 85bf71be3f..968ca68619 100644
--- a/src/plugins/styles/mac/qmacstyle_mac.mm
+++ b/src/plugins/styles/mac/qmacstyle_mac.mm
@@ -75,6 +75,8 @@
#include <QtWidgets/qwizard.h>
#endif
+#include <cmath>
+
QT_USE_NAMESPACE
static QWindow *qt_getWindow(const QWidget *widget)
@@ -456,6 +458,37 @@ static bool setupSlider(NSSlider *slider, const QStyleOptionSlider *sl)
return true;
}
+static void fixStaleGeometry(NSSlider *slider)
+{
+ // If it's later fixed in AppKit, this function is not needed.
+ // On macOS Mojave we suddenly have NSSliderCell with a cached
+ // (and stale) geometry, thus its -drawKnob, -drawBarInside:flipped:,
+ // -drawTickMarks fail to render the slider properly. Setting the number
+ // of tickmarks triggers an update in geometry.
+
+ Q_ASSERT(slider);
+
+ if (QOperatingSystemVersion::current() < QOperatingSystemVersion::MacOSMojave)
+ return;
+
+ NSSliderCell *cell = slider.cell;
+ const NSRect barRect = [cell barRectFlipped:NO];
+ const NSSize sliderSize = slider.frame.size;
+ CGFloat difference = 0.;
+ if (slider.vertical)
+ difference = std::abs(sliderSize.height - barRect.size.height);
+ else
+ difference = std::abs(sliderSize.width - barRect.size.width);
+
+ if (difference > 6.) {
+ // Stale ...
+ const auto nOfTicks = slider.numberOfTickMarks;
+ // Non-zero, different from nOfTicks to force update
+ slider.numberOfTickMarks = nOfTicks + 10;
+ slider.numberOfTickMarks = nOfTicks;
+ }
+}
+
static bool isInMacUnifiedToolbarArea(QWindow *window, int windowY)
{
QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
@@ -2083,10 +2116,9 @@ void QMacStyle::unpolish(QWidget* w)
#if QT_CONFIG(menu)
qobject_cast<QMenu*>(w) &&
#endif
- !w->testAttribute(Qt::WA_SetPalette)) {
- QPalette pal = qApp->palette(w);
- w->setPalette(pal);
- w->setAttribute(Qt::WA_SetPalette, false);
+ !w->testAttribute(Qt::WA_SetPalette))
+ {
+ w->setPalette(QPalette());
w->setWindowOpacity(1.0);
}
@@ -2102,9 +2134,9 @@ void QMacStyle::unpolish(QWidget* w)
#if QT_CONFIG(tabbar)
if (qobject_cast<QTabBar*>(w)) {
if (!w->testAttribute(Qt::WA_SetFont))
- w->setFont(qApp->font(w));
+ w->setFont(QFont());
if (!w->testAttribute(Qt::WA_SetPalette))
- w->setPalette(qApp->palette(w));
+ w->setPalette(QPalette());
}
#endif
@@ -5241,9 +5273,20 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
}
d->drawNSViewInRect(slider, opt->rect, p, ^(CGContextRef ctx, const CGRect &rect) {
- if (isHorizontal && sl->upsideDown) {
- CGContextTranslateCTM(ctx, rect.size.width, 0);
- CGContextScaleCTM(ctx, -1, 1);
+
+ // Since the GC is flipped, upsideDown means *not* inverted when vertical.
+ const bool verticalFlip = !isHorizontal && !sl->upsideDown; // FIXME: && !isSierraOrLater
+
+ if (isHorizontal) {
+ if (sl->upsideDown) {
+ CGContextTranslateCTM(ctx, rect.size.width, rect.origin.y);
+ CGContextScaleCTM(ctx, -1, 1);
+ } else {
+ CGContextTranslateCTM(ctx, 0, rect.origin.y);
+ }
+ } else if (verticalFlip) {
+ CGContextTranslateCTM(ctx, rect.origin.x, rect.size.height);
+ CGContextScaleCTM(ctx, 1, -1);
}
if (hasDoubleTicks) {
@@ -5254,9 +5297,6 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
CGContextTranslateCTM(ctx, 1, 0);
}
- // Since the GC is flipped, upsideDown means *not* inverted when vertical.
- const bool verticalFlip = !isHorizontal && !sl->upsideDown; // FIXME: && !isSierraOrLater
-
#if 0
// FIXME: Sadly, this part doesn't work. It seems to somehow polute the
// NSSlider's internal state and, when we need to use the "else" part,
@@ -5276,6 +5316,8 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
#endif
{
[slider calcSize];
+ if (!hasDoubleTicks)
+ fixStaleGeometry(slider);
NSSliderCell *cell = slider.cell;
const int numberOfTickMarks = slider.numberOfTickMarks;
@@ -5285,10 +5327,10 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
const CGRect barRect = [cell barRectFlipped:hasTicks];
if (drawBar) {
+ [cell drawBarInside:barRect flipped:!verticalFlip];
// This ain't HIG kosher: force unfilled bar look.
if (hasDoubleTicks)
slider.numberOfTickMarks = numberOfTickMarks;
- [cell drawBarInside:barRect flipped:!verticalFlip];
}
if (hasTicks && drawTicks) {
@@ -5318,9 +5360,6 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
// This ain't HIG kosher: force round knob look.
if (hasDoubleTicks)
slider.numberOfTickMarks = 0;
- // Draw the knob in the symmetrical position instead of flipping.
- if (verticalFlip)
- slider.intValue = slider.maxValue - slider.intValue + slider.minValue;
[cell drawKnob];
}
}
diff --git a/src/printsupport/kernel/qcups.cpp b/src/printsupport/kernel/qcups.cpp
index 5236b8c8fa..2fc4621960 100644
--- a/src/printsupport/kernel/qcups.cpp
+++ b/src/printsupport/kernel/qcups.cpp
@@ -106,7 +106,7 @@ static inline QString jobHoldToString(const QCUPSSupport::JobHoldUntil jobHold,
if (holdUntilTime < localDateTime.time())
localDateTime = localDateTime.addDays(1);
localDateTime.setTime(holdUntilTime);
- return localDateTime.toUTC().time().toString(QStringViewLiteral("HH:mm"));
+ return localDateTime.toUTC().time().toString(u"HH:mm");
}
// else fall through:
Q_FALLTHROUGH();
diff --git a/src/src.pro b/src/src.pro
index 9ccc1e8f65..832a3b6d82 100644
--- a/src/src.pro
+++ b/src/src.pro
@@ -1,8 +1,10 @@
TEMPLATE = subdirs
-QT_FOR_CONFIG += core-private gui-private
+QT_FOR_CONFIG += core-private gui-private printsupport
+
include($$OUT_PWD/corelib/qtcore-config.pri)
include($$OUT_PWD/gui/qtgui-config.pri)
+include($$OUT_PWD/printsupport/qtprintsupport-config.pri)
force_bootstrap|!qtConfig(commandlineparser): \
CONFIG += force_dbus_bootstrap
@@ -225,11 +227,13 @@ qtConfig(gui) {
src_testlib.depends += src_gui # if QtGui is enabled, QtTest requires QtGui's headers
qtConfig(widgets) {
SUBDIRS += src_tools_uic src_widgets
- !android-embedded: SUBDIRS += src_printsupport
TOOLS += src_tools_uic
src_plugins.depends += src_widgets
- !android-embedded: src_plugins.depends += src_printsupport
src_testlib.depends += src_widgets # if QtWidgets is enabled, QtTest requires QtWidgets's headers
+ qtConfig(printer) {
+ SUBDIRS += src_printsupport
+ src_plugins.depends += src_printsupport
+ }
qtConfig(opengl) {
SUBDIRS += src_opengl
src_plugins.depends += src_opengl
diff --git a/src/testlib/qabstracttestlogger.cpp b/src/testlib/qabstracttestlogger.cpp
index 2b54cd410b..ff05dd88c7 100644
--- a/src/testlib/qabstracttestlogger.cpp
+++ b/src/testlib/qabstracttestlogger.cpp
@@ -87,7 +87,7 @@ QAbstractTestLogger::~QAbstractTestLogger()
if (stream != stdout) {
fclose(stream);
}
- stream = 0;
+ stream = nullptr;
}
void QAbstractTestLogger::filterUnprintable(char *str) const
diff --git a/src/testlib/qabstracttestlogger_p.h b/src/testlib/qabstracttestlogger_p.h
index 9bb1d1e80c..e5a1404c16 100644
--- a/src/testlib/qabstracttestlogger_p.h
+++ b/src/testlib/qabstracttestlogger_p.h
@@ -117,8 +117,7 @@ struct QTestCharBuffer
{
enum { InitialSize = 512 };
- inline QTestCharBuffer()
- : _size(InitialSize), buf(staticBuf)
+ inline QTestCharBuffer() : buf(staticBuf)
{
staticBuf[0] = '\0';
}
@@ -170,7 +169,7 @@ struct QTestCharBuffer
}
private:
- int _size;
+ int _size = InitialSize;
char* buf;
char staticBuf[InitialSize];
};
diff --git a/src/testlib/qbenchmark.cpp b/src/testlib/qbenchmark.cpp
index cbc009c993..aafdc64831 100644
--- a/src/testlib/qbenchmark.cpp
+++ b/src/testlib/qbenchmark.cpp
@@ -51,14 +51,6 @@ QT_BEGIN_NAMESPACE
QBenchmarkGlobalData *QBenchmarkGlobalData::current;
QBenchmarkGlobalData::QBenchmarkGlobalData()
- : measurer(0)
- , walltimeMinimum(-1)
- , iterationCount(-1)
- , medianIterationCount(-1)
- , createChart(false)
- , verboseOutput(false)
- , minimumTotal(-1)
- , mode_(WallTime)
{
setMode(mode_);
}
@@ -74,14 +66,13 @@ void QBenchmarkGlobalData::setMode(Mode mode)
{
mode_ = mode;
- if (measurer)
- delete measurer;
+ delete measurer;
measurer = createMeasurer();
}
QBenchmarkMeasurerBase * QBenchmarkGlobalData::createMeasurer()
{
- QBenchmarkMeasurerBase *measurer = 0;
+ QBenchmarkMeasurerBase *measurer = nullptr;
if (0) {
#if QT_CONFIG(valgrind)
} else if (mode_ == CallgrindChildProcess || mode_ == CallgrindParentProcess) {
@@ -106,24 +97,18 @@ QBenchmarkMeasurerBase * QBenchmarkGlobalData::createMeasurer()
int QBenchmarkGlobalData::adjustMedianIterationCount()
{
- if (medianIterationCount != -1) {
- return medianIterationCount;
- } else {
- return measurer->adjustMedianCount(1);
- }
+ return medianIterationCount != -1
+ ? medianIterationCount : measurer->adjustMedianCount(1);
}
QBenchmarkTestMethodData *QBenchmarkTestMethodData::current;
-QBenchmarkTestMethodData::QBenchmarkTestMethodData()
-:resultAccepted(false), runOnce(false), iterationCount(-1)
-{
-}
+QBenchmarkTestMethodData::QBenchmarkTestMethodData() = default;
QBenchmarkTestMethodData::~QBenchmarkTestMethodData()
{
- QBenchmarkTestMethodData::current = 0;
+ QBenchmarkTestMethodData::current = nullptr;
}
void QBenchmarkTestMethodData::beginDataRun()
diff --git a/src/testlib/qbenchmark_p.h b/src/testlib/qbenchmark_p.h
index 49868ac23a..93b5becb2b 100644
--- a/src/testlib/qbenchmark_p.h
+++ b/src/testlib/qbenchmark_p.h
@@ -81,7 +81,7 @@ struct QBenchmarkContext
QString slotName;
QString tag; // from _data() function
- int checkpointIndex;
+ int checkpointIndex = -1;
QString toString() const
{
@@ -89,7 +89,7 @@ struct QBenchmarkContext
.arg(slotName, tag, QString::number(checkpointIndex));
}
- QBenchmarkContext() : checkpointIndex(-1) {}
+ QBenchmarkContext() = default;
};
Q_DECLARE_TYPEINFO(QBenchmarkContext, Q_MOVABLE_TYPE);
@@ -97,19 +97,13 @@ class QBenchmarkResult
{
public:
QBenchmarkContext context;
- qreal value;
- int iterations;
- QTest::QBenchmarkMetric metric;
- bool setByMacro;
- bool valid;
-
- QBenchmarkResult()
- : value(-1)
- , iterations(-1)
- , metric(QTest::FramesPerSecond)
- , setByMacro(true)
- , valid(false)
- { }
+ qreal value = -1;
+ int iterations = -1;
+ QTest::QBenchmarkMetric metric = QTest::FramesPerSecond;
+ bool setByMacro = true;
+ bool valid = false;
+
+ QBenchmarkResult() = default;
QBenchmarkResult(
const QBenchmarkContext &context, const qreal value, const int iterations,
@@ -147,17 +141,17 @@ public:
QBenchmarkMeasurerBase *createMeasurer();
int adjustMedianIterationCount();
- QBenchmarkMeasurerBase *measurer;
+ QBenchmarkMeasurerBase *measurer = nullptr;
QBenchmarkContext context;
- int walltimeMinimum;
- int iterationCount;
- int medianIterationCount;
- bool createChart;
- bool verboseOutput;
+ int walltimeMinimum = -1;
+ int iterationCount = -1;
+ int medianIterationCount = -1;
+ bool createChart = false;
+ bool verboseOutput = false;
QString callgrindOutFileBase;
- int minimumTotal;
+ int minimumTotal = -1;
private:
- Mode mode_;
+ Mode mode_ = WallTime;
};
/*
@@ -184,9 +178,9 @@ public:
void setResult(qreal value, QTest::QBenchmarkMetric metric, bool setByMacro = true);
QBenchmarkResult result;
- bool resultAccepted;
- bool runOnce;
- int iterationCount;
+ bool resultAccepted = false;
+ bool runOnce = false;
+ int iterationCount = -1;
};
// low-level API:
diff --git a/src/testlib/qbenchmarkevent.cpp b/src/testlib/qbenchmarkevent.cpp
index a8270219e4..bcae9325cd 100644
--- a/src/testlib/qbenchmarkevent.cpp
+++ b/src/testlib/qbenchmarkevent.cpp
@@ -44,14 +44,9 @@
QT_BEGIN_NAMESPACE
-QBenchmarkEvent::QBenchmarkEvent()
- : eventCounter(0)
-{
-}
+QBenchmarkEvent::QBenchmarkEvent() = default;
-QBenchmarkEvent::~QBenchmarkEvent()
-{
-}
+QBenchmarkEvent::~QBenchmarkEvent() = default;
void QBenchmarkEvent::start()
{
diff --git a/src/testlib/qbenchmarkevent_p.h b/src/testlib/qbenchmarkevent_p.h
index 0f47aa475c..9fe3daa33b 100644
--- a/src/testlib/qbenchmarkevent_p.h
+++ b/src/testlib/qbenchmarkevent_p.h
@@ -76,7 +76,7 @@ public:
#else
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override;
#endif
- qint64 eventCounter;
+ qint64 eventCounter = 0;
};
QT_END_NAMESPACE
diff --git a/src/testlib/qbenchmarkmeasurement_p.h b/src/testlib/qbenchmarkmeasurement_p.h
index 8dbfd4b618..1e2b82c25d 100644
--- a/src/testlib/qbenchmarkmeasurement_p.h
+++ b/src/testlib/qbenchmarkmeasurement_p.h
@@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE
class QBenchmarkMeasurerBase
{
public:
- virtual ~QBenchmarkMeasurerBase() {}
+ virtual ~QBenchmarkMeasurerBase() = default;
virtual void init() {}
virtual void start() = 0;
virtual qint64 checkpoint() = 0;
@@ -66,7 +66,7 @@ public:
virtual bool isMeasurementAccepted(qint64 measurement) = 0;
virtual int adjustIterationCount(int suggestion) = 0;
virtual int adjustMedianCount(int suggestion) = 0;
- virtual bool repeatCount() { return 1; }
+ virtual bool repeatCount() { return true; }
virtual bool needsWarmupIteration() { return false; }
virtual QTest::QBenchmarkMetric metricType() = 0;
};
diff --git a/src/testlib/qbenchmarkperfevents.cpp b/src/testlib/qbenchmarkperfevents.cpp
index 91f0792338..e8c6969d4a 100644
--- a/src/testlib/qbenchmarkperfevents.cpp
+++ b/src/testlib/qbenchmarkperfevents.cpp
@@ -147,7 +147,7 @@ bool QBenchmarkPerfEventsMeasurer::isAvailable()
{
// this generates an EFAULT because attr == NULL if perf_event_open is available
// if the kernel is too old, it generates ENOSYS
- return perf_event_open(0, 0, 0, 0, 0) == -1 && errno != ENOSYS;
+ return perf_event_open(nullptr, 0, 0, 0, 0) == -1 && errno != ENOSYS;
}
/* Event list structure
@@ -500,10 +500,7 @@ void QBenchmarkPerfEventsMeasurer::listCounters()
"Attributes can be combined, for example: -perfcounter branch-mispredicts:kh\n");
}
-QBenchmarkPerfEventsMeasurer::QBenchmarkPerfEventsMeasurer()
- : fd(-1)
-{
-}
+QBenchmarkPerfEventsMeasurer::QBenchmarkPerfEventsMeasurer() = default;
QBenchmarkPerfEventsMeasurer::~QBenchmarkPerfEventsMeasurer()
{
diff --git a/src/testlib/qbenchmarkperfevents_p.h b/src/testlib/qbenchmarkperfevents_p.h
index 86ba556549..3f27161ef5 100644
--- a/src/testlib/qbenchmarkperfevents_p.h
+++ b/src/testlib/qbenchmarkperfevents_p.h
@@ -60,23 +60,23 @@ class QBenchmarkPerfEventsMeasurer : public QBenchmarkMeasurerBase
public:
QBenchmarkPerfEventsMeasurer();
~QBenchmarkPerfEventsMeasurer();
- virtual void init() override;
- virtual void start() override;
- virtual qint64 checkpoint() override;
- virtual qint64 stop() override;
- virtual bool isMeasurementAccepted(qint64 measurement) override;
- virtual int adjustIterationCount(int suggestion) override;
- virtual int adjustMedianCount(int suggestion) override;
- virtual bool repeatCount() override { return 1; }
- virtual bool needsWarmupIteration() override { return true; }
- virtual QTest::QBenchmarkMetric metricType() override;
+ void init() override;
+ void start() override;
+ qint64 checkpoint() override;
+ qint64 stop() override;
+ bool isMeasurementAccepted(qint64 measurement) override;
+ int adjustIterationCount(int suggestion) override;
+ int adjustMedianCount(int suggestion) override;
+ bool repeatCount() override { return true; }
+ bool needsWarmupIteration() override { return true; }
+ QTest::QBenchmarkMetric metricType() override;
static bool isAvailable();
static QTest::QBenchmarkMetric metricForEvent(quint32 type, quint64 event_id);
static void setCounter(const char *name);
static void listCounters();
private:
- int fd;
+ int fd = -1;
qint64 readValue();
};
diff --git a/src/testlib/qbenchmarkvalgrind.cpp b/src/testlib/qbenchmarkvalgrind.cpp
index 0dac804338..44888c4d30 100644
--- a/src/testlib/qbenchmarkvalgrind.cpp
+++ b/src/testlib/qbenchmarkvalgrind.cpp
@@ -168,7 +168,7 @@ QString QBenchmarkValgrindUtils::outFileBase(qint64 pid)
// Returns \c true upon success, otherwise false.
bool QBenchmarkValgrindUtils::runCallgrindSubProcess(const QStringList &origAppArgs, int &exitCode)
{
- const QString execFile(origAppArgs.at(0));
+ const QString &execFile = origAppArgs.at(0);
QStringList args;
args << QLatin1String("--tool=callgrind") << QLatin1String("--instr-atstart=yes")
<< QLatin1String("--quiet")
@@ -177,7 +177,7 @@ bool QBenchmarkValgrindUtils::runCallgrindSubProcess(const QStringList &origAppA
// pass on original arguments that make sense (e.g. avoid wasting time producing output
// that will be ignored anyway) ...
for (int i = 1; i < origAppArgs.size(); ++i) {
- const QString arg(origAppArgs.at(i));
+ const QString &arg = origAppArgs.at(i);
if (arg == QLatin1String("-callgrind"))
continue;
args << arg; // ok to pass on
diff --git a/src/testlib/qcsvbenchmarklogger.cpp b/src/testlib/qcsvbenchmarklogger.cpp
index ee7270b634..f410ec6e3d 100644
--- a/src/testlib/qcsvbenchmarklogger.cpp
+++ b/src/testlib/qcsvbenchmarklogger.cpp
@@ -46,9 +46,7 @@ QCsvBenchmarkLogger::QCsvBenchmarkLogger(const char *filename)
{
}
-QCsvBenchmarkLogger::~QCsvBenchmarkLogger()
-{
-}
+QCsvBenchmarkLogger::~QCsvBenchmarkLogger() = default;
void QCsvBenchmarkLogger::startLogging()
{
diff --git a/src/testlib/qplaintestlogger.cpp b/src/testlib/qplaintestlogger.cpp
index ed53dcdde8..c2e0bebaa0 100644
--- a/src/testlib/qplaintestlogger.cpp
+++ b/src/testlib/qplaintestlogger.cpp
@@ -316,9 +316,7 @@ QPlainTestLogger::QPlainTestLogger(const char *filename)
{
}
-QPlainTestLogger::~QPlainTestLogger()
-{
-}
+QPlainTestLogger::~QPlainTestLogger() = default;
void QPlainTestLogger::startLogging()
{
diff --git a/src/testlib/qsignaldumper.cpp b/src/testlib/qsignaldumper.cpp
index d0b6d0dd3f..70f4d5e63d 100644
--- a/src/testlib/qsignaldumper.cpp
+++ b/src/testlib/qsignaldumper.cpp
@@ -56,7 +56,7 @@ namespace QTest
inline static void qPrintMessage(const QByteArray &ba)
{
- QTestLog::info(ba.constData(), 0, 0);
+ QTestLog::info(ba.constData(), nullptr, 0);
}
Q_GLOBAL_STATIC(QList<QByteArray>, ignoreClasses)
@@ -169,7 +169,7 @@ static void qSignalDumperCallbackEndSignal(QObject *caller, int /*signal_index*/
void QSignalDumper::startDump()
{
static QSignalSpyCallbackSet set = { QTest::qSignalDumperCallback,
- QTest::qSignalDumperCallbackSlot, QTest::qSignalDumperCallbackEndSignal, 0 };
+ QTest::qSignalDumperCallbackSlot, QTest::qSignalDumperCallbackEndSignal, nullptr };
qt_register_signal_spy_callbacks(&set);
}
diff --git a/src/testlib/qtaptestlogger.cpp b/src/testlib/qtaptestlogger.cpp
index 476761e602..5b5a3c4875 100644
--- a/src/testlib/qtaptestlogger.cpp
+++ b/src/testlib/qtaptestlogger.cpp
@@ -55,9 +55,7 @@ QTapTestLogger::QTapTestLogger(const char *filename)
{
}
-QTapTestLogger::~QTapTestLogger()
-{
-}
+QTapTestLogger::~QTapTestLogger() = default;
void QTapTestLogger::startLogging()
{
diff --git a/src/testlib/qteamcitylogger.cpp b/src/testlib/qteamcitylogger.cpp
index 88c83d1269..8a77143454 100644
--- a/src/testlib/qteamcitylogger.cpp
+++ b/src/testlib/qteamcitylogger.cpp
@@ -103,9 +103,7 @@ QTeamCityLogger::QTeamCityLogger(const char *filename)
{
}
-QTeamCityLogger::~QTeamCityLogger()
-{
-}
+QTeamCityLogger::~QTeamCityLogger() = default;
void QTeamCityLogger::startLogging()
{
@@ -224,9 +222,7 @@ QString QTeamCityLogger::tcEscapedString(const QString &str) const
{
QString formattedString;
- for (int i = 0; i < str.length(); i++) {
- QChar ch = str.at(i);
-
+ for (QChar ch : str) {
switch (ch.toLatin1()) {
case '\n':
formattedString.append(QLatin1String("|n"));
diff --git a/src/testlib/qtest.h b/src/testlib/qtest.h
index 7affdcb8b4..cdf0800371 100644
--- a/src/testlib/qtest.h
+++ b/src/testlib/qtest.h
@@ -46,6 +46,7 @@
#include <QtTest/qtestdata.h>
#include <QtTest/qbenchmark.h>
+#include <QtCore/qbitarray.h>
#include <QtCore/qbytearray.h>
#include <QtCore/qstring.h>
#include <QtCore/qstringlist.h>
@@ -91,25 +92,35 @@ template<> inline char *toString(const QByteArray &ba)
return QTest::toPrettyCString(ba.constData(), ba.length());
}
+template<> inline char *toString(const QBitArray &ba)
+{
+ qsizetype size = ba.size();
+ char *str = static_cast<char *>(malloc(size + 1));
+ for (qsizetype i = 0; i < size; ++i)
+ str[i] = "01"[ba.testBit(i)];
+ str[size] = '\0';
+ return str;
+}
+
#if QT_CONFIG(datestring)
template<> inline char *toString(const QTime &time)
{
return time.isValid()
- ? qstrdup(qPrintable(time.toString(QStringViewLiteral("hh:mm:ss.zzz"))))
+ ? qstrdup(qPrintable(time.toString(u"hh:mm:ss.zzz")))
: qstrdup("Invalid QTime");
}
template<> inline char *toString(const QDate &date)
{
return date.isValid()
- ? qstrdup(qPrintable(date.toString(QStringViewLiteral("yyyy/MM/dd"))))
+ ? qstrdup(qPrintable(date.toString(u"yyyy/MM/dd")))
: qstrdup("Invalid QDate");
}
template<> inline char *toString(const QDateTime &dateTime)
{
return dateTime.isValid()
- ? qstrdup(qPrintable(dateTime.toString(QStringViewLiteral("yyyy/MM/dd hh:mm:ss.zzz[t]"))))
+ ? qstrdup(qPrintable(dateTime.toString(u"yyyy/MM/dd hh:mm:ss.zzz[t]")))
: qstrdup("Invalid QDateTime");
}
#endif // datestring
diff --git a/src/testlib/qtest_gui.h b/src/testlib/qtest_gui.h
index e5101e6955..d1efde54b1 100644
--- a/src/testlib/qtest_gui.h
+++ b/src/testlib/qtest_gui.h
@@ -162,6 +162,14 @@ inline bool qCompare(QImage const &t1, QImage const &t2,
}
if (t1Null && t2Null)
return compare_helper(true, nullptr, nullptr, nullptr, actual, expected, file, line);
+ if (!qFuzzyCompare(t1.devicePixelRatioF(), t2.devicePixelRatioF())) {
+ qsnprintf(msg, 1024, "Compared QImages differ in device pixel ratio.\n"
+ " Actual (%s): %g\n"
+ " Expected (%s): %g",
+ actual, t1.devicePixelRatioF(),
+ expected, t2.devicePixelRatioF());
+ return compare_helper(false, msg, nullptr, nullptr, actual, expected, file, line);
+ }
if (t1.width() != t2.width() || t1.height() != t2.height()) {
qsnprintf(msg, 1024, "Compared QImages differ in size.\n"
" Actual (%s): %dx%d\n"
@@ -196,6 +204,14 @@ inline bool qCompare(QPixmap const &t1, QPixmap const &t2, const char *actual, c
}
if (t1Null && t2Null)
return compare_helper(true, nullptr, nullptr, nullptr, actual, expected, file, line);
+ if (!qFuzzyCompare(t1.devicePixelRatioF(), t2.devicePixelRatioF())) {
+ qsnprintf(msg, 1024, "Compared QPixmaps differ in device pixel ratio.\n"
+ " Actual (%s): %g\n"
+ " Expected (%s): %g",
+ actual, t1.devicePixelRatioF(),
+ expected, t2.devicePixelRatioF());
+ return compare_helper(false, msg, nullptr, nullptr, actual, expected, file, line);
+ }
if (t1.width() != t2.width() || t1.height() != t2.height()) {
qsnprintf(msg, 1024, "Compared QPixmaps differ in size.\n"
" Actual (%s): %dx%d\n"
diff --git a/src/testlib/qtestblacklist.cpp b/src/testlib/qtestblacklist.cpp
index 15f01c4af0..91258e9ec4 100644
--- a/src/testlib/qtestblacklist.cpp
+++ b/src/testlib/qtestblacklist.cpp
@@ -169,12 +169,14 @@ static QSet<QByteArray> keywords()
#endif
;
+#if QT_CONFIG(properties)
QCoreApplication *app = QCoreApplication::instance();
if (app) {
const QVariant platformName = app->property("platformName");
if (platformName.isValid())
set << platformName.toByteArray();
}
+#endif
return set;
}
@@ -218,11 +220,10 @@ static bool checkCondition(const QByteArray &condition)
static const QSet<QByteArray> matchedConditions = activeConditions();
QList<QByteArray> conds = condition.split(' ');
- for (int i = 0; i < conds.size(); ++i) {
- QByteArray c = conds.at(i);
+ for (QByteArray c : conds) {
bool result = c.startsWith('!');
if (result)
- c = c.mid(1);
+ c.remove(0, 1);
result ^= matchedConditions.contains(c);
if (!result)
@@ -232,7 +233,7 @@ static bool checkCondition(const QByteArray &condition)
}
static bool ignoreAll = false;
-static std::set<QByteArray> *ignoredTests = 0;
+static std::set<QByteArray> *ignoredTests = nullptr;
namespace QTestPrivate {
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 619376fd33..990fc5679d 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -289,7 +289,7 @@ namespace QTest
{
class WatchDog;
-static QObject *currentTestObject = 0;
+static QObject *currentTestObject = nullptr;
static QString mainSourcePath;
#if defined(Q_OS_MACOS)
@@ -423,7 +423,7 @@ Q_TESTLIB_EXPORT bool printAvailableFunctions = false;
Q_TESTLIB_EXPORT QStringList testFunctions;
Q_TESTLIB_EXPORT QStringList testTags;
-static void qPrintTestSlots(FILE *stream, const char *filter = 0)
+static void qPrintTestSlots(FILE *stream, const char *filter = nullptr)
{
for (int i = 0; i < QTest::currentTestObject->metaObject()->methodCount(); ++i) {
QMetaMethod sl = QTest::currentTestObject->metaObject()->method(i);
@@ -516,7 +516,7 @@ static int qToInt(const char *str)
Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, const char *const argv[], bool qml)
{
int logFormat = -1; // Not set
- const char *logFilename = 0;
+ const char *logFilename = nullptr;
QTest::testFunctions.clear();
QTest::testTags.clear();
@@ -897,7 +897,7 @@ struct QTestDataSetter
}
~QTestDataSetter()
{
- QTestResult::setCurrentTestData(0);
+ QTestResult::setCurrentTestData(nullptr);
}
};
@@ -974,11 +974,11 @@ void TestMethods::invokeTestOnData(int index) const
if (i == -1) {
QTestLog::info(qPrintable(
QString::fromLatin1("warmup stage result : %1")
- .arg(QBenchmarkTestMethodData::current->result.value)), 0, 0);
+ .arg(QBenchmarkTestMethodData::current->result.value)), nullptr, 0);
} else {
QTestLog::info(qPrintable(
QString::fromLatin1("accumulation stage result: %1")
- .arg(QBenchmarkTestMethodData::current->result.value)), 0, 0);
+ .arg(QBenchmarkTestMethodData::current->result.value)), nullptr, 0);
}
}
}
@@ -1040,7 +1040,7 @@ public:
void run() override {
QMutexLocker locker(&mutex);
waitCondition.wakeAll();
- while (1) {
+ while (true) {
int t = timeout.loadRelaxed();
if (!t)
break;
@@ -1115,7 +1115,7 @@ bool TestMethods::invokeTest(int index, const char *data, WatchDog *watchDog) co
if (data && !dataCount) {
// Let empty data tag through.
if (!*data)
- data = 0;
+ data = nullptr;
else {
fprintf(stderr, "Unknown testdata for function %s(): '%s'\n", name.constData(), data);
fprintf(stderr, "Function has no testdata.\n");
@@ -1130,10 +1130,9 @@ bool TestMethods::invokeTest(int index, const char *data, WatchDog *watchDog) co
if (!data || !qstrcmp(data, table.testData(curDataIndex)->dataTag())) {
foundFunction = true;
- QTestPrivate::checkBlackLists(name.constData(), dataCount ? table.testData(curDataIndex)->dataTag() : 0);
+ QTestPrivate::checkBlackLists(name.constData(), dataCount ? table.testData(curDataIndex)->dataTag() : nullptr);
- QTestDataSetter s(curDataIndex >= dataCount ? static_cast<QTestData *>(0)
- : table.testData(curDataIndex));
+ QTestDataSetter s(curDataIndex >= dataCount ? nullptr : table.testData(curDataIndex));
QTestPrivate::qtestMouseButtons = Qt::NoButton;
if (watchDog)
@@ -1156,14 +1155,14 @@ bool TestMethods::invokeTest(int index, const char *data, WatchDog *watchDog) co
return false;
}
- QTestResult::setCurrentGlobalTestData(0);
+ QTestResult::setCurrentGlobalTestData(nullptr);
++curGlobalDataIndex;
} while (curGlobalDataIndex < globalDataCount);
QTestResult::finishedCurrentTestFunction();
QTestResult::setSkipCurrentTest(false);
QTestResult::setBlacklistCurrentTest(false);
- QTestResult::setCurrentTestData(0);
+ QTestResult::setCurrentTestData(nullptr);
return true;
}
@@ -1241,7 +1240,7 @@ char *toHexRepresentation(const char *ba, int length)
* */
const int maxLen = 50;
const int len = qMin(maxLen, length);
- char *result = 0;
+ char *result = nullptr;
if (length > maxLen) {
const int size = len * 3 + 4;
@@ -1274,10 +1273,8 @@ char *toHexRepresentation(const char *ba, int length)
++o;
if (i == len)
break;
- else {
- result[o] = ' ';
- ++o;
- }
+ result[o] = ' ';
+ ++o;
}
return result;
@@ -1497,7 +1494,7 @@ void TestMethods::invokeTests(QObject *testObject) const
QTestResult::finishedCurrentTestDataCleanup();
}
QTestResult::finishedCurrentTestFunction();
- QTestResult::setCurrentTestFunction(0);
+ QTestResult::setCurrentTestFunction(nullptr);
}
#if defined(Q_OS_UNIX)
@@ -1567,7 +1564,7 @@ FatalSignalHandler::FatalSignalHandler()
stack.ss_flags = 0;
stack.ss_size = sizeof alternate_stack;
stack.ss_sp = alternate_stack;
- sigaltstack(&stack, 0);
+ sigaltstack(&stack, nullptr);
act.sa_flags |= SA_ONSTACK;
#endif
@@ -1586,7 +1583,7 @@ FatalSignalHandler::FatalSignalHandler()
oldact.sa_flags & SA_SIGINFO ||
#endif
oldact.sa_handler != SIG_DFL) {
- sigaction(fatalSignals[i], &oldact, 0);
+ sigaction(fatalSignals[i], &oldact, nullptr);
} else
{
sigaddset(&handledSignals, fatalSignals[i]);
@@ -1611,7 +1608,7 @@ FatalSignalHandler::~FatalSignalHandler()
// If someone overwrote it in the mean time, put it back
if (oldact.sa_handler != FatalSignalHandler::signal)
- sigaction(i, &oldact, 0);
+ sigaction(i, &oldact, nullptr);
}
}
@@ -1927,7 +1924,7 @@ int QTest::qRun()
QTestResult::addFailure("Caught unhandled exception", __FILE__, __LINE__);
if (QTestResult::currentTestFunction()) {
QTestResult::finishedCurrentTestFunction();
- QTestResult::setCurrentTestFunction(0);
+ QTestResult::setCurrentTestFunction(nullptr);
}
QTestLog::stopLogging();
@@ -1936,7 +1933,7 @@ int QTest::qRun()
IOPMAssertionRelease(powerID);
}
#endif
- currentTestObject = 0;
+ currentTestObject = nullptr;
// Rethrow exception to make debugging easier.
throw;
@@ -1957,13 +1954,13 @@ int QTest::qRun()
*/
void QTest::qCleanup()
{
- currentTestObject = 0;
+ currentTestObject = nullptr;
QTestTable::clearGlobalTestTable();
QTestLog::stopLogging();
delete QBenchmarkGlobalData::current;
- QBenchmarkGlobalData::current = 0;
+ QBenchmarkGlobalData::current = nullptr;
QSignalDumper::endDump();
@@ -2550,9 +2547,9 @@ bool QTest::qCompare(qfloat16 const &t1, qfloat16 const &t2, const char *actual,
bool QTest::qCompare(float const &t1, float const &t2, const char *actual, const char *expected,
const char *file, int line)
{
- return compare_helper(floatingCompare(t1, t2),
- "Compared floats are not the same (fuzzy compare)",
- toString(t1), toString(t2), actual, expected, file, line);
+ return QTestResult::compare(floatingCompare(t1, t2),
+ "Compared floats are not the same (fuzzy compare)",
+ t1, t2, actual, expected, file, line);
}
/*! \fn bool QTest::qCompare(const double &t1, const double &t2, const char *actual, const char *expected, const char *file, int line)
@@ -2561,11 +2558,86 @@ bool QTest::qCompare(float const &t1, float const &t2, const char *actual, const
bool QTest::qCompare(double const &t1, double const &t2, const char *actual, const char *expected,
const char *file, int line)
{
- return compare_helper(floatingCompare(t1, t2),
- "Compared doubles are not the same (fuzzy compare)",
- toString(t1), toString(t2), actual, expected, file, line);
+ return QTestResult::compare(floatingCompare(t1, t2),
+ "Compared doubles are not the same (fuzzy compare)",
+ t1, t2, actual, expected, file, line);
+}
+
+/*! \fn bool QTest::qCompare(int t1, int t2, const char *actual, const char *expected, const char *file, int line)
+ \internal
+ \since 5.14
+ */
+bool QTest::qCompare(int t1, int t2, const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return QTestResult::compare(t1 == t2,
+ "Compared values are not the same",
+ t1, t2, actual, expected, file, line);
+}
+
+/*! \fn bool QTest::qCompare(unsigned t1, unsigned t2, const char *actual, const char *expected, const char *file, int line)
+ \internal
+ \since 5.14
+ */
+bool QTest::qCompare(unsigned t1, unsigned t2, const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return QTestResult::compare(t1 == t2,
+ "Compared values are not the same",
+ t1, t2, actual, expected, file, line);
+}
+
+/*! \fn bool QTest::qCompare(QStringView t1, QStringView t2, const char *actual, const char *expected, const char *file, int line)
+ \internal
+ \since 5.14
+ */
+bool QTest::qCompare(QStringView t1, QStringView t2, const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return QTestResult::compare(t1 == t2,
+ "Compared values are not the same",
+ t1, t2, actual, expected, file, line);
}
+/*! \fn bool QTest::qCompare(QStringView t1, const QLatin1String &t2, const char *actual, const char *expected, const char *file, int line)
+ \internal
+ \since 5.14
+ */
+bool QTest::qCompare(QStringView t1, const QLatin1String &t2, const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return QTestResult::compare(t1 == t2,
+ "Compared values are not the same",
+ t1, t2, actual, expected, file, line);
+}
+
+/*! \fn bool QTest::qCompare(const QLatin1String &t1, QStringView t2, const char *actual, const char *expected, const char *file, int line)
+ \internal
+ \since 5.14
+ */
+bool QTest::qCompare(const QLatin1String &t1, QStringView t2, const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return QTestResult::compare(t1 == t2,
+ "Compared values are not the same",
+ t1, t2, actual, expected, file, line);
+}
+
+/*! \fn bool QTest::qCompare(const QString &t1, const QString &t2, const char *actual, const char *expected, const char *file, int line)
+ \internal
+ \since 5.14
+ */
+
+/*! \fn bool QTest::qCompare(const QString &t1, const QLatin1String &t2, const char *actual, const char *expected, const char *file, int line)
+ \internal
+ \since 5.14
+ */
+
+/*! \fn bool QTest::qCompare(const QLatin1String &t1, const QString &t2, const char *actual, const char *expected, const char *file, int line)
+ \internal
+ \since 5.14
+ */
+
/*! \fn bool QTest::qCompare(const double &t1, const float &t2, const char *actual, const char *expected, const char *file, int line)
\internal
*/
@@ -2703,7 +2775,7 @@ template <> Q_TESTLIB_EXPORT char *QTest::toString<char>(const char &t)
char *QTest::toString(const char *str)
{
if (!str)
- return 0;
+ return nullptr;
char *msg = new char[strlen(str) + 1];
return qstrcpy(msg, str);
}
diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h
index af7c0f43b9..e61e450e98 100644
--- a/src/testlib/qtestcase.h
+++ b/src/testlib/qtestcase.h
@@ -363,6 +363,40 @@ namespace QTest
Q_TESTLIB_EXPORT bool qCompare(double const &t1, double const &t2,
const char *actual, const char *expected, const char *file, int line);
+ Q_TESTLIB_EXPORT bool qCompare(int t1, int t2, const char *actual, const char *expected,
+ const char *file, int line);
+
+ Q_TESTLIB_EXPORT bool qCompare(unsigned t1, unsigned t2, const char *actual, const char *expected,
+ const char *file, int line);
+
+ Q_TESTLIB_EXPORT bool qCompare(QStringView t1, QStringView t2,
+ const char *actual, const char *expected,
+ const char *file, int line);
+ Q_TESTLIB_EXPORT bool qCompare(QStringView t1, const QLatin1String &t2,
+ const char *actual, const char *expected,
+ const char *file, int line);
+ Q_TESTLIB_EXPORT bool qCompare(const QLatin1String &t1, QStringView t2,
+ const char *actual, const char *expected,
+ const char *file, int line);
+ inline bool qCompare(const QString &t1, const QString &t2,
+ const char *actual, const char *expected,
+ const char *file, int line)
+ {
+ return qCompare(QStringView(t1), QStringView(t2), actual, expected, file, line);
+ }
+ inline bool qCompare(const QString &t1, const QLatin1String &t2,
+ const char *actual, const char *expected,
+ const char *file, int line)
+ {
+ return qCompare(QStringView(t1), t2, actual, expected, file, line);
+ }
+ inline bool qCompare(const QLatin1String &t1, const QString &t2,
+ const char *actual, const char *expected,
+ const char *file, int line)
+ {
+ return qCompare(t1, QStringView(t2), actual, expected, file, line);
+ }
+
inline bool compare_ptr_helper(const volatile void *t1, const volatile void *t2, const char *actual,
const char *expected, const char *file, int line)
{
diff --git a/src/testlib/qtestcoreelement_p.h b/src/testlib/qtestcoreelement_p.h
index 84406fed85..a101ab5ea3 100644
--- a/src/testlib/qtestcoreelement_p.h
+++ b/src/testlib/qtestcoreelement_p.h
@@ -74,13 +74,13 @@ class QTestCoreElement: public QTestCoreList<ElementType>
QTest::LogElementType elementType() const;
private:
- QTestElementAttribute *listOfAttributes;
+ QTestElementAttribute *listOfAttributes = nullptr;
QTest::LogElementType type;
};
template<class ElementType>
QTestCoreElement<ElementType>::QTestCoreElement(int t)
- :listOfAttributes(nullptr), type(QTest::LogElementType(t))
+ : type(QTest::LogElementType(t))
{
}
diff --git a/src/testlib/qtestdata.cpp b/src/testlib/qtestdata.cpp
index a8ee130a7d..3a1c6d7e7b 100644
--- a/src/testlib/qtestdata.cpp
+++ b/src/testlib/qtestdata.cpp
@@ -51,12 +51,10 @@ QT_BEGIN_NAMESPACE
class QTestDataPrivate
{
public:
- QTestDataPrivate() : tag(0), parent(0), data(0), dataCount(0) {}
-
- char *tag;
- QTestTable *parent;
- void **data;
- int dataCount;
+ char *tag = nullptr;
+ QTestTable *parent = nullptr;
+ void **data = nullptr;
+ int dataCount = 0;
};
QTestData::QTestData(const char *tag, QTestTable *parent)
diff --git a/src/testlib/qtestelement.cpp b/src/testlib/qtestelement.cpp
index 622e5344f3..b468295917 100644
--- a/src/testlib/qtestelement.cpp
+++ b/src/testlib/qtestelement.cpp
@@ -43,8 +43,6 @@ QT_BEGIN_NAMESPACE
QTestElement::QTestElement(int type)
: QTestCoreElement<QTestElement>(type)
- , listOfChildren(0)
- , parent(0)
{
}
diff --git a/src/testlib/qtestelement_p.h b/src/testlib/qtestelement_p.h
index dacbe6c106..a6b2791a42 100644
--- a/src/testlib/qtestelement_p.h
+++ b/src/testlib/qtestelement_p.h
@@ -69,8 +69,8 @@ class QTestElement: public QTestCoreElement<QTestElement>
void setParent(const QTestElement *p);
private:
- QTestElement *listOfChildren;
- const QTestElement * parent;
+ QTestElement *listOfChildren = nullptr;
+ const QTestElement * parent = nullptr;
};
diff --git a/src/testlib/qtestelementattribute.cpp b/src/testlib/qtestelementattribute.cpp
index 9d752bf26a..e194ee50f7 100644
--- a/src/testlib/qtestelementattribute.cpp
+++ b/src/testlib/qtestelementattribute.cpp
@@ -104,11 +104,7 @@ QT_BEGIN_NAMESPACE
\value LET_SystemError
*/
-QTestElementAttribute::QTestElementAttribute()
- :attributeValue(0),
- attributeIndex(QTest::AI_Undefined)
-{
-}
+QTestElementAttribute::QTestElementAttribute() = default;
QTestElementAttribute::~QTestElementAttribute()
{
@@ -145,7 +141,7 @@ const char *QTestElementAttribute::name() const
if (attributeIndex != QTest::AI_Undefined)
return AttributeNames[attributeIndex];
- return 0;
+ return nullptr;
}
QTest::AttributeIndex QTestElementAttribute::index() const
@@ -168,7 +164,7 @@ bool QTestElementAttribute::setPair(QTest::AttributeIndex index, const char *val
attributeIndex = index;
attributeValue = qstrdup(value);
- return attributeValue != 0;
+ return attributeValue != nullptr;
}
QT_END_NAMESPACE
diff --git a/src/testlib/qtestelementattribute_p.h b/src/testlib/qtestelementattribute_p.h
index cb4dbb5f16..f3815b72d1 100644
--- a/src/testlib/qtestelementattribute_p.h
+++ b/src/testlib/qtestelementattribute_p.h
@@ -106,8 +106,8 @@ class QTestElementAttribute: public QTestCoreList<QTestElementAttribute>
bool setPair(QTest::AttributeIndex attributeIndex, const char *value);
private:
- char *attributeValue;
- QTest::AttributeIndex attributeIndex;
+ char *attributeValue = nullptr;
+ QTest::AttributeIndex attributeIndex = QTest::AI_Undefined;
};
QT_END_NAMESPACE
diff --git a/src/testlib/qtesteventloop.h b/src/testlib/qtesteventloop.h
index a77b47cd7f..b194e24c3a 100644
--- a/src/testlib/qtesteventloop.h
+++ b/src/testlib/qtesteventloop.h
@@ -56,8 +56,7 @@ class Q_TESTLIB_EXPORT QTestEventLoop : public QObject
Q_OBJECT
public:
- inline QTestEventLoop(QObject *aParent = nullptr)
- : QObject(aParent), inLoop(false), _timeout(false), timerId(-1), loop(nullptr) {}
+ using QObject::QObject;
inline void enterLoopMSecs(int ms);
inline void enterLoop(int secs) { enterLoopMSecs(secs * 1000); }
@@ -84,10 +83,10 @@ protected:
private:
Q_DECL_UNUSED_MEMBER bool inLoop; // ### Qt 6: remove
- bool _timeout;
- int timerId;
+ bool _timeout = false;
+ int timerId = -1;
- QEventLoop *loop;
+ QEventLoop *loop = nullptr;
};
inline void QTestEventLoop::enterLoopMSecs(int ms)
diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp
index 14543c3cde..f3ebf343c5 100644
--- a/src/testlib/qtestlog.cpp
+++ b/src/testlib/qtestlog.cpp
@@ -111,7 +111,7 @@ namespace QTest {
struct IgnoreResultList
{
inline IgnoreResultList(QtMsgType tp, const QVariant &patternIn)
- : type(tp), pattern(patternIn), next(0) {}
+ : type(tp), pattern(patternIn) {}
static inline void clearList(IgnoreResultList *&list)
{
@@ -163,10 +163,10 @@ namespace QTest {
QtMsgType type;
QVariant pattern;
- IgnoreResultList *next;
+ IgnoreResultList *next = nullptr;
};
- static IgnoreResultList *ignoreResultList = 0;
+ static IgnoreResultList *ignoreResultList = nullptr;
static QVector<QAbstractTestLogger*> loggers;
static bool loggerUsingStdout = false;
@@ -181,7 +181,7 @@ namespace QTest {
{
if (!ignoreResultList)
return false;
- IgnoreResultList *last = 0;
+ IgnoreResultList *last = nullptr;
IgnoreResultList *list = ignoreResultList;
while (list) {
if (list->matches(type, message)) {
@@ -191,7 +191,7 @@ namespace QTest {
else if (list->next)
ignoreResultList = list->next;
else
- ignoreResultList = 0;
+ ignoreResultList = nullptr;
delete list;
return true;
@@ -438,11 +438,11 @@ void QTestLog::stopLogging()
void QTestLog::addLogger(LogMode mode, const char *filename)
{
if (filename && strcmp(filename, "-") == 0)
- filename = 0;
+ filename = nullptr;
if (!filename)
QTest::loggerUsingStdout = true;
- QAbstractTestLogger *logger = 0;
+ QAbstractTestLogger *logger = nullptr;
switch (mode) {
case QTestLog::Plain:
logger = new QPlainTestLogger(filename);
diff --git a/src/testlib/qtestlog_p.h b/src/testlib/qtestlog_p.h
index e63e89a78e..fff36f290d 100644
--- a/src/testlib/qtestlog_p.h
+++ b/src/testlib/qtestlog_p.h
@@ -66,6 +66,10 @@ class QTestData;
class Q_TESTLIB_EXPORT QTestLog
{
public:
+ QTestLog() = delete;
+ ~QTestLog() = delete;
+ Q_DISABLE_COPY_MOVE(QTestLog)
+
enum LogMode {
Plain = 0, XML, LightXML, XunitXML, CSV, TeamCity, TAP
#if defined(QT_USE_APPLE_UNIFIED_LOGGING)
@@ -135,9 +139,6 @@ public:
static qreal msecsFunctionTime() { return QTestLog::nsecsFunctionTime() / 1000000.; }
private:
- QTestLog();
- ~QTestLog();
-
static bool printAvailableTags;
};
diff --git a/src/testlib/qtestresult.cpp b/src/testlib/qtestresult.cpp
index a7a4807e06..88028aac6e 100644
--- a/src/testlib/qtestresult.cpp
+++ b/src/testlib/qtestresult.cpp
@@ -39,42 +39,45 @@
#include <QtTest/private/qtestresult_p.h>
#include <QtCore/qglobal.h>
+#include <QtCore/qstringview.h>
#include <QtTest/private/qtestlog_p.h>
+#include <QtTest/qtest.h> // toString() specializations for QStringView
#include <QtTest/qtestdata.h>
+#include <QtTest/qtestcase.h>
#include <QtTest/qtestassert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-static const char *currentAppName = 0;
+static const char *currentAppName = nullptr;
QT_BEGIN_NAMESPACE
namespace QTest
{
- static QTestData *currentTestData = 0;
- static QTestData *currentGlobalTestData = 0;
- static const char *currentTestFunc = 0;
- static const char *currentTestObjectName = 0;
+ static QTestData *currentTestData = nullptr;
+ static QTestData *currentGlobalTestData = nullptr;
+ static const char *currentTestFunc = nullptr;
+ static const char *currentTestObjectName = nullptr;
static bool failed = false;
static bool skipCurrentTest = false;
static bool blacklistCurrentTest = false;
- static const char *expectFailComment = 0;
+ static const char *expectFailComment = nullptr;
static int expectFailMode = 0;
}
void QTestResult::reset()
{
- QTest::currentTestData = 0;
- QTest::currentGlobalTestData = 0;
- QTest::currentTestFunc = 0;
- QTest::currentTestObjectName = 0;
+ QTest::currentTestData = nullptr;
+ QTest::currentGlobalTestData = nullptr;
+ QTest::currentTestFunc = nullptr;
+ QTest::currentTestObjectName = nullptr;
QTest::failed = false;
- QTest::expectFailComment = 0;
+ QTest::expectFailComment = nullptr;
QTest::expectFailMode = 0;
QTest::blacklistCurrentTest = false;
@@ -126,18 +129,18 @@ static void clearExpectFail()
{
QTest::expectFailMode = 0;
delete [] const_cast<char *>(QTest::expectFailComment);
- QTest::expectFailComment = 0;
+ QTest::expectFailComment = nullptr;
}
void QTestResult::finishedCurrentTestData()
{
if (QTest::expectFailMode)
- addFailure("QEXPECT_FAIL was called without any subsequent verification statements", 0, 0);
+ addFailure("QEXPECT_FAIL was called without any subsequent verification statements", nullptr, 0);
clearExpectFail();
if (!QTest::failed && QTestLog::unhandledIgnoreMessages()) {
QTestLog::printUnhandledIgnoreMessages();
- addFailure("Not all expected messages were received", 0, 0);
+ addFailure("Not all expected messages were received", nullptr, 0);
}
QTestLog::clearIgnoreMessages();
}
@@ -157,7 +160,7 @@ void QTestResult::finishedCurrentTestDataCleanup()
void QTestResult::finishedCurrentTestFunction()
{
- QTest::currentTestFunc = 0;
+ QTest::currentTestFunc = nullptr;
QTest::failed = false;
QTestLog::leaveTestFunction();
@@ -170,14 +173,12 @@ const char *QTestResult::currentTestFunction()
const char *QTestResult::currentDataTag()
{
- return QTest::currentTestData ? QTest::currentTestData->dataTag()
- : static_cast<const char *>(0);
+ return QTest::currentTestData ? QTest::currentTestData->dataTag() : nullptr;
}
const char *QTestResult::currentGlobalDataTag()
{
- return QTest::currentGlobalTestData ? QTest::currentGlobalTestData->dataTag()
- : static_cast<const char *>(0);
+ return QTest::currentGlobalTestData ? QTest::currentGlobalTestData->dataTag() : nullptr;
}
static bool isExpectFailData(const char *dataIndex)
@@ -265,17 +266,54 @@ bool QTestResult::verify(bool statement, const char *statementStr,
return checkStatement(statement, msg, file, line);
}
-bool QTestResult::compare(bool success, const char *failureMsg,
- char *val1, char *val2,
- const char *actual, const char *expected,
- const char *file, int line)
+// Format failures using the toString() template
+template <class Actual, class Expected>
+void formatFailMessage(char *msg, size_t maxMsgLen,
+ const char *failureMsg,
+ const Actual &val1, const Expected &val2,
+ const char *actual, const char *expected)
{
- QTEST_ASSERT(expected);
- QTEST_ASSERT(actual);
+ auto val1S = QTest::toString(val1);
+ auto val2S = QTest::toString(val2);
+
+ size_t len1 = mbstowcs(nullptr, actual, maxMsgLen); // Last parameter is not ignored on QNX
+ size_t len2 = mbstowcs(nullptr, expected, maxMsgLen); // (result is never larger than this).
+ qsnprintf(msg, maxMsgLen, "%s\n Actual (%s)%*s %s\n Expected (%s)%*s %s",
+ failureMsg,
+ actual, qMax(len1, len2) - len1 + 1, ":", val1S ? val1S : "<null>",
+ expected, qMax(len1, len2) - len2 + 1, ":", val2S ? val2S : "<null>");
+
+ delete [] val1S;
+ delete [] val2S;
+}
+
+// Overload to format failures for "const char *" - no need to strdup().
+void formatFailMessage(char *msg, size_t maxMsgLen,
+ const char *failureMsg,
+ const char *val1, const char *val2,
+ const char *actual, const char *expected)
+{
+ size_t len1 = mbstowcs(nullptr, actual, maxMsgLen); // Last parameter is not ignored on QNX
+ size_t len2 = mbstowcs(nullptr, expected, maxMsgLen); // (result is never larger than this).
+ qsnprintf(msg, maxMsgLen, "%s\n Actual (%s)%*s %s\n Expected (%s)%*s %s",
+ failureMsg,
+ actual, qMax(len1, len2) - len1 + 1, ":", val1 ? val1 : "<null>",
+ expected, qMax(len1, len2) - len2 + 1, ":", val2 ? val2 : "<null>");
+}
+template <class Actual, class Expected>
+static bool compareHelper(bool success, const char *failureMsg,
+ const Actual &val1, const Expected &val2,
+ const char *actual, const char *expected,
+ const char *file, int line,
+ bool hasValues = true)
+{
const size_t maxMsgLen = 1024;
char msg[maxMsgLen] = {'\0'};
+ QTEST_ASSERT(expected);
+ QTEST_ASSERT(actual);
+
if (QTestLog::verboseLevel() >= 2) {
qsnprintf(msg, maxMsgLen, "QCOMPARE(%s, %s)", actual, expected);
QTestLog::info(msg, file, line);
@@ -289,20 +327,92 @@ bool QTestResult::compare(bool success, const char *failureMsg,
qsnprintf(msg, maxMsgLen,
"QCOMPARE(%s, %s) returned TRUE unexpectedly.", actual, expected);
}
- } else if (val1 || val2) {
- size_t len1 = mbstowcs(NULL, actual, maxMsgLen); // Last parameter is not ignored on QNX
- size_t len2 = mbstowcs(NULL, expected, maxMsgLen); // (result is never larger than this).
- qsnprintf(msg, maxMsgLen, "%s\n Actual (%s)%*s %s\n Expected (%s)%*s %s",
- failureMsg,
- actual, qMax(len1, len2) - len1 + 1, ":", val1 ? val1 : "<null>",
- expected, qMax(len1, len2) - len2 + 1, ":", val2 ? val2 : "<null>");
- } else
+ return checkStatement(success, msg, file, line);
+ }
+
+
+ if (!hasValues) {
qsnprintf(msg, maxMsgLen, "%s", failureMsg);
+ return checkStatement(success, msg, file, line);
+ }
+
+ formatFailMessage(msg, maxMsgLen, failureMsg, val1, val2, actual, expected);
+
+ return checkStatement(success, msg, file, line);
+}
+
+bool QTestResult::compare(bool success, const char *failureMsg,
+ char *val1, char *val2,
+ const char *actual, const char *expected,
+ const char *file, int line)
+{
+ const bool result = compareHelper(success, failureMsg,
+ val1 != nullptr ? val1 : "<null>",
+ val2 != nullptr ? val2 : "<null>",
+ actual, expected, file, line,
+ val1 != nullptr && val2 != nullptr);
+ // Our caller got these from QTest::toString()
delete [] val1;
delete [] val2;
- return checkStatement(success, msg, file, line);
+ return result;
+}
+
+bool QTestResult::compare(bool success, const char *failureMsg,
+ double val1, double val2,
+ const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return compareHelper(success, failureMsg, val1, val2, actual, expected, file, line);
+}
+
+bool QTestResult::compare(bool success, const char *failureMsg,
+ float val1, float val2,
+ const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return compareHelper(success, failureMsg, val1, val2, actual, expected, file, line);
+}
+
+bool QTestResult::compare(bool success, const char *failureMsg,
+ int val1, int val2,
+ const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return compareHelper(success, failureMsg, val1, val2, actual, expected, file, line);
+}
+
+bool QTestResult::compare(bool success, const char *failureMsg,
+ unsigned val1, unsigned val2,
+ const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return compareHelper(success, failureMsg, val1, val2, actual, expected, file, line);
+}
+
+bool QTestResult::compare(bool success, const char *failureMsg,
+ QStringView val1, QStringView val2,
+ const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return compareHelper(success, failureMsg, val1, val2, actual, expected, file, line);
+}
+
+bool QTestResult::compare(bool success, const char *failureMsg,
+ QStringView val1, const QLatin1String &val2,
+ const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return compareHelper(success, failureMsg, val1, val2, actual, expected, file, line);
+}
+
+bool QTestResult::compare(bool success, const char *failureMsg,
+ const QLatin1String & val1, QStringView val2,
+ const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return compareHelper(success, failureMsg, val1, val2, actual, expected, file, line);
}
void QTestResult::addFailure(const char *message, const char *file, int line)
diff --git a/src/testlib/qtestresult_p.h b/src/testlib/qtestresult_p.h
index 4df75b2805..38a3024a0f 100644
--- a/src/testlib/qtestresult_p.h
+++ b/src/testlib/qtestresult_p.h
@@ -55,6 +55,9 @@
QT_BEGIN_NAMESPACE
+class QLatin1String;
+class QStringView;
+
class QTestResultPrivate;
class QTestData;
@@ -79,7 +82,34 @@ public:
char *val1, char *val2,
const char *actual, const char *expected,
const char *file, int line);
-
+ static bool compare(bool success, const char *failureMsg,
+ double val1, double val2,
+ const char *actual, const char *expected,
+ const char *file, int line);
+ static bool compare(bool success, const char *failureMsg,
+ float val1, float val2,
+ const char *actual, const char *expected,
+ const char *file, int line);
+ static bool compare(bool success, const char *failureMsg,
+ int val1, int val2,
+ const char *actual, const char *expected,
+ const char *file, int line);
+ static bool compare(bool success, const char *failureMsg,
+ unsigned val1, unsigned val2,
+ const char *actual, const char *expected,
+ const char *file, int line);
+ static bool compare(bool success, const char *failureMsg,
+ QStringView val1, QStringView val2,
+ const char *actual, const char *expected,
+ const char *file, int line);
+ static bool compare(bool success, const char *failureMsg,
+ const QLatin1String &val1, QStringView val2,
+ const char *actual, const char *expected,
+ const char *file, int line);
+ static bool compare(bool success, const char *failureMsg,
+ QStringView val1, const QLatin1String &val2,
+ const char *actual, const char *expected,
+ const char *file, int line);
static void setCurrentGlobalTestData(QTestData *data);
static void setCurrentTestData(QTestData *data);
static void setCurrentTestFunction(const char *func);
diff --git a/src/testlib/qtesttable.cpp b/src/testlib/qtesttable.cpp
index 20e0702d44..85dff17017 100644
--- a/src/testlib/qtesttable.cpp
+++ b/src/testlib/qtesttable.cpp
@@ -58,11 +58,11 @@ public:
}
struct Element {
- Element() : name(nullptr), type(0) {}
+ Element() = default;
Element(const char *n, int t) : name(n), type(t) {}
- const char *name;
- int type;
+ const char *name = nullptr;
+ int type = 0;
};
using ElementList = std::vector<Element>;
@@ -78,8 +78,8 @@ public:
static QTestTable *gTable;
};
-QTestTable *QTestTablePrivate::currentTestTable = 0;
-QTestTable *QTestTablePrivate::gTable = 0;
+QTestTable *QTestTablePrivate::currentTestTable = nullptr;
+QTestTable *QTestTablePrivate::gTable = nullptr;
void QTestTable::addColumn(int type, const char *name)
{
@@ -119,7 +119,7 @@ QTestTable::QTestTable()
QTestTable::~QTestTable()
{
- QTestTablePrivate::currentTestTable = 0;
+ QTestTablePrivate::currentTestTable = nullptr;
delete d;
}
@@ -172,7 +172,7 @@ QTestTable *QTestTable::globalTestTable()
void QTestTable::clearGlobalTestTable()
{
delete QTestTablePrivate::gTable;
- QTestTablePrivate::gTable = 0;
+ QTestTablePrivate::gTable = nullptr;
}
QTestTable *QTestTable::currentTestTable()
diff --git a/src/testlib/qtestxunitstreamer.cpp b/src/testlib/qtestxunitstreamer.cpp
index fe9a6e21cc..bdbdfa9610 100644
--- a/src/testlib/qtestxunitstreamer.cpp
+++ b/src/testlib/qtestxunitstreamer.cpp
@@ -54,8 +54,7 @@ QTestXunitStreamer::QTestXunitStreamer(QXunitTestLogger *logger)
QTEST_ASSERT(testLogger);
}
-QTestXunitStreamer::~QTestXunitStreamer()
-{}
+QTestXunitStreamer::~QTestXunitStreamer() = default;
void QTestXunitStreamer::indentForElement(const QTestElement* element, char* buf, int size)
{
@@ -129,7 +128,7 @@ void QTestXunitStreamer::formatAttributes(const QTestElement* element, const QTe
return;
}
- char const* key = 0;
+ char const* key = nullptr;
if (attrindex == QTest::AI_Description)
key = "message";
else if (attrindex != QTest::AI_File && attrindex != QTest::AI_Line)
diff --git a/src/testlib/qxmltestlogger.cpp b/src/testlib/qxmltestlogger.cpp
index c47042c3a0..763cea327b 100644
--- a/src/testlib/qxmltestlogger.cpp
+++ b/src/testlib/qxmltestlogger.cpp
@@ -107,9 +107,7 @@ QXmlTestLogger::QXmlTestLogger(XmlMode mode, const char *filename)
{
}
-QXmlTestLogger::~QXmlTestLogger()
-{
-}
+QXmlTestLogger::~QXmlTestLogger() = default;
void QXmlTestLogger::startLogging()
{
@@ -182,23 +180,20 @@ inline static bool isEmpty(const char *str)
static const char *incidentFormatString(bool noDescription, bool noTag)
{
if (noDescription) {
- if (noTag)
- return "<Incident type=\"%s\" file=\"%s\" line=\"%d\" />\n";
- else
- return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n"
+ return noTag
+ ? "<Incident type=\"%s\" file=\"%s\" line=\"%d\" />\n"
+ : "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n"
" <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n"
"</Incident>\n";
- } else {
- if (noTag)
- return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n"
- " <Description><![CDATA[%s%s%s%s]]></Description>\n"
- "</Incident>\n";
- else
- return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n"
- " <DataTag><![CDATA[%s%s%s]]></DataTag>\n"
- " <Description><![CDATA[%s]]></Description>\n"
- "</Incident>\n";
}
+ return noTag
+ ? "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n"
+ " <Description><![CDATA[%s%s%s%s]]></Description>\n"
+ "</Incident>\n"
+ : "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n"
+ " <DataTag><![CDATA[%s%s%s]]></DataTag>\n"
+ " <Description><![CDATA[%s]]></Description>\n"
+ "</Incident>\n";
}
static const char *benchmarkResultFormatString()
diff --git a/src/testlib/qxunittestlogger.cpp b/src/testlib/qxunittestlogger.cpp
index 336edb5994..b3cac9cb82 100644
--- a/src/testlib/qxunittestlogger.cpp
+++ b/src/testlib/qxunittestlogger.cpp
@@ -59,13 +59,6 @@ QT_BEGIN_NAMESPACE
QXunitTestLogger::QXunitTestLogger(const char *filename)
: QAbstractTestLogger(filename)
- , listOfTestcases(0)
- , currentLogElement(0)
- , errorLogElement(0)
- , logFormatter(0)
- , testCounter(0)
- , failureCounter(0)
- , errorCounter(0)
{
}
@@ -155,7 +148,7 @@ void QXunitTestLogger::leaveTestFunction()
void QXunitTestLogger::addIncident(IncidentTypes type, const char *description,
const char *file, int line)
{
- const char *typeBuf = 0;
+ const char *typeBuf = nullptr;
char buf[100];
switch (type) {
@@ -299,7 +292,7 @@ void QXunitTestLogger::addTag(QTestElement* element)
void QXunitTestLogger::addMessage(MessageTypes type, const QString &message, const char *file, int line)
{
QTestElement *errorElement = new QTestElement(QTest::LET_Error);
- const char *typeBuf = 0;
+ const char *typeBuf = nullptr;
switch (type) {
case QAbstractTestLogger::Warn:
diff --git a/src/testlib/qxunittestlogger_p.h b/src/testlib/qxunittestlogger_p.h
index 48f07ddcf2..518ba098f4 100644
--- a/src/testlib/qxunittestlogger_p.h
+++ b/src/testlib/qxunittestlogger_p.h
@@ -79,14 +79,14 @@ class QXunitTestLogger : public QAbstractTestLogger
const char *file = nullptr, int line = 0) override;
private:
- QTestElement *listOfTestcases;
- QTestElement *currentLogElement;
- QTestElement *errorLogElement;
- QTestXunitStreamer *logFormatter;
+ QTestElement *listOfTestcases = nullptr;
+ QTestElement *currentLogElement = nullptr;
+ QTestElement *errorLogElement = nullptr;
+ QTestXunitStreamer *logFormatter = nullptr;
- int testCounter;
- int failureCounter;
- int errorCounter;
+ int testCounter = 0;
+ int failureCounter = 0;
+ int errorCounter = 0;
};
QT_END_NAMESPACE
diff --git a/src/tools/bootstrap/bootstrap.pro b/src/tools/bootstrap/bootstrap.pro
index 757460393e..32e36cefa0 100644
--- a/src/tools/bootstrap/bootstrap.pro
+++ b/src/tools/bootstrap/bootstrap.pro
@@ -74,32 +74,32 @@ SOURCES += \
../../corelib/serialization/qtextstream.cpp \
../../corelib/serialization/qxmlutils.cpp \
../../corelib/serialization/qxmlstream.cpp \
+ ../../corelib/text/qbytearray.cpp \
+ ../../corelib/text/qbytearraymatcher.cpp \
+ ../../corelib/text/qlocale.cpp \
+ ../../corelib/text/qlocale_tools.cpp \
+ ../../corelib/text/qregexp.cpp \
+ ../../corelib/text/qstring.cpp \
+ ../../corelib/text/qstringbuilder.cpp \
+ ../../corelib/text/qstring_compat.cpp \
+ ../../corelib/text/qstringlist.cpp \
+ ../../corelib/text/qstringview.cpp \
+ ../../corelib/text/qvsnprintf.cpp \
../../corelib/time/qdatetime.cpp \
- ../../corelib/tools/qbitarray.cpp \
- ../../corelib/tools/qbytearray.cpp \
../../corelib/tools/qarraydata.cpp \
- ../../corelib/tools/qbytearraymatcher.cpp \
+ ../../corelib/tools/qbitarray.cpp \
../../corelib/tools/qcommandlineparser.cpp \
../../corelib/tools/qcommandlineoption.cpp \
../../corelib/tools/qcryptographichash.cpp \
../../corelib/tools/qhash.cpp \
../../corelib/tools/qlist.cpp \
- ../../corelib/tools/qlocale.cpp \
- ../../corelib/tools/qlocale_tools.cpp \
../../corelib/tools/qmap.cpp \
- ../../corelib/tools/qregexp.cpp \
../../corelib/tools/qringbuffer.cpp \
../../corelib/tools/qpoint.cpp \
../../corelib/tools/qrect.cpp \
../../corelib/tools/qsize.cpp \
../../corelib/tools/qline.cpp \
- ../../corelib/tools/qstring.cpp \
- ../../corelib/tools/qstringbuilder.cpp \
- ../../corelib/tools/qstring_compat.cpp \
- ../../corelib/tools/qstringlist.cpp \
- ../../corelib/tools/qstringview.cpp \
../../corelib/tools/qversionnumber.cpp \
- ../../corelib/tools/qvsnprintf.cpp \
../../xml/dom/qdom.cpp \
../../xml/sax/qxml.cpp
@@ -126,10 +126,7 @@ win32:SOURCES += ../../corelib/global/qoperatingsystemversion_win.cpp \
mac {
SOURCES += \
../../corelib/kernel/qcoreapplication_mac.cpp \
- ../../corelib/kernel/qcore_mac.cpp \
- ../../corelib/io/qfilesystemengine_unix.cpp \
- ../../corelib/io/qfilesystemiterator_unix.cpp \
- ../../corelib/io/qfsfileengine_unix.cpp
+ ../../corelib/kernel/qcore_mac.cpp
OBJECTIVE_SOURCES += \
../../corelib/global/qoperatingsystemversion_darwin.mm \
diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp
index 41d0bbf2a1..6a74e739e6 100644
--- a/src/tools/moc/generator.cpp
+++ b/src/tools/moc/generator.cpp
@@ -518,10 +518,15 @@ void Generator::generateCode()
}
}
+//
+// Generate meta object link to parent meta objects
+//
+
if (!extraList.isEmpty()) {
- fprintf(out, "static const QMetaObject * const qt_meta_extradata_%s[] = {\n ", qualifiedClassNameIdentifier.constData());
+ fprintf(out, "static const QMetaObject::SuperData qt_meta_extradata_%s[] = {\n",
+ qualifiedClassNameIdentifier.constData());
for (int i = 0; i < extraList.count(); ++i) {
- fprintf(out, " &%s::staticMetaObject,\n", extraList.at(i).constData());
+ fprintf(out, " QMetaObject::SuperData::link<%s::staticMetaObject>(),\n", extraList.at(i).constData());
}
fprintf(out, " nullptr\n};\n\n");
}
@@ -537,7 +542,7 @@ void Generator::generateCode()
if (isQObject)
fprintf(out, " nullptr,\n");
else if (cdef->superclassList.size() && (!cdef->hasQGadget || knownGadgets.contains(purestSuperClass)))
- fprintf(out, " &%s::staticMetaObject,\n", purestSuperClass.constData());
+ fprintf(out, " QMetaObject::SuperData::link<%s::staticMetaObject>(),\n", purestSuperClass.constData());
else
fprintf(out, " nullptr,\n");
fprintf(out, " qt_meta_stringdata_%s.data,\n"
diff --git a/src/tools/uic/cpp/cppwriteinitialization.cpp b/src/tools/uic/cpp/cppwriteinitialization.cpp
index d16c859eed..fd5f8c9017 100644
--- a/src/tools/uic/cpp/cppwriteinitialization.cpp
+++ b/src/tools/uic/cpp/cppwriteinitialization.cpp
@@ -547,10 +547,11 @@ void WriteInitialization::acceptUI(DomUI *node)
m_output << m_option.indent << language::endFunctionDefinition("setupUi");
if (!m_mainFormUsedInRetranslateUi && language::language() == Language::Cpp) {
+ // Mark varName as unused to avoid compiler warnings.
m_refreshInitialization += m_indent;
- m_refreshInitialization += QLatin1String("Q_UNUSED(");
+ m_refreshInitialization += QLatin1String("(void)");
m_refreshInitialization += varName ;
- m_refreshInitialization += QLatin1String(");\n");
+ m_refreshInitialization += QLatin1String(";\n");
}
m_output << m_option.indent
diff --git a/src/widgets/accessible/simplewidgets.cpp b/src/widgets/accessible/simplewidgets.cpp
index 716c833fc9..ca74ee4b12 100644
--- a/src/widgets/accessible/simplewidgets.cpp
+++ b/src/widgets/accessible/simplewidgets.cpp
@@ -779,8 +779,7 @@ int QAccessibleLineEdit::cursorPosition() const
QRect QAccessibleLineEdit::characterRect(int offset) const
{
int x = lineEdit()->d_func()->control->cursorToX(offset);
- int y;
- lineEdit()->getTextMargins(0, &y, 0, 0);
+ int y = lineEdit()->textMargins().top();
QFontMetrics fm(lineEdit()->font());
const QString ch = text(offset, offset + 1);
if (ch.isEmpty())
diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp
index 82c341b47c..fc00290536 100644
--- a/src/widgets/dialogs/qcolordialog.cpp
+++ b/src/widgets/dialogs/qcolordialog.cpp
@@ -1745,7 +1745,7 @@ void QColorDialogPrivate::initWidgets()
q->connect(custom, SIGNAL(selected(int,int)), SLOT(_q_newCustom(int,int)));
q->connect(custom, SIGNAL(currentChanged(int,int)), SLOT(_q_nextCustom(int,int)));
- q->connect(custom, &QWellArray::colorChanged, [=] (int index, QRgb color) {
+ q->connect(custom, &QWellArray::colorChanged, [this] (int index, QRgb color) {
QColorDialogOptions::setCustomColor(index, color);
if (custom)
custom->update();
diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp
index 2f45635298..c85b56d4f5 100644
--- a/src/widgets/dialogs/qfiledialog.cpp
+++ b/src/widgets/dialogs/qfiledialog.cpp
@@ -44,6 +44,7 @@
#include "qfiledialog.h"
#include "qfiledialog_p.h"
+#include <private/qapplication_p.h>
#include <private/qguiapplication_p.h>
#include <qfontmetrics.h>
#include <qaction.h>
@@ -4035,7 +4036,7 @@ bool QFileDialogPrivate::itemViewKeyboardEvent(QKeyEvent *event) {
return true;
case Qt::Key_Back:
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled())
+ if (QApplicationPrivate::keypadNavigationEnabled())
return false;
#endif
case Qt::Key_Left:
diff --git a/src/widgets/dialogs/qfileinfogatherer.cpp b/src/widgets/dialogs/qfileinfogatherer.cpp
index f39ae2b53e..9ab75e0b0a 100644
--- a/src/widgets/dialogs/qfileinfogatherer.cpp
+++ b/src/widgets/dialogs/qfileinfogatherer.cpp
@@ -79,14 +79,8 @@ static QString translateDriveName(const QFileInfo &drive)
Creates thread
*/
QFileInfoGatherer::QFileInfoGatherer(QObject *parent)
- : QThread(parent), abort(false),
-#if QT_CONFIG(filesystemwatcher)
- watcher(0),
-#endif
-#ifdef Q_OS_WIN
- m_resolveSymlinks(true),
-#endif
- m_iconProvider(&defaultProvider)
+ : QThread(parent)
+ , m_iconProvider(&defaultProvider)
{
#if QT_CONFIG(filesystemwatcher)
watcher = new QFileSystemWatcher(this);
diff --git a/src/widgets/dialogs/qfileinfogatherer_p.h b/src/widgets/dialogs/qfileinfogatherer_p.h
index 795f60249f..829c620c1e 100644
--- a/src/widgets/dialogs/qfileinfogatherer_p.h
+++ b/src/widgets/dialogs/qfileinfogatherer_p.h
@@ -210,13 +210,13 @@ private:
QAtomicInt abort;
#if QT_CONFIG(filesystemwatcher)
- QFileSystemWatcher *watcher;
-#endif
-#ifdef Q_OS_WIN
- bool m_resolveSymlinks; // not accessed by run()
+ QFileSystemWatcher *watcher = nullptr;
#endif
QFileIconProvider *m_iconProvider; // not accessed by run()
QFileIconProvider defaultProvider;
+#ifdef Q_OS_WIN
+ bool m_resolveSymlinks = true; // not accessed by run()
+#endif
};
QT_END_NAMESPACE
diff --git a/src/widgets/dialogs/qfilesystemmodel.cpp b/src/widgets/dialogs/qfilesystemmodel.cpp
index b521f50f40..820fc6e220 100644
--- a/src/widgets/dialogs/qfilesystemmodel.cpp
+++ b/src/widgets/dialogs/qfilesystemmodel.cpp
@@ -227,11 +227,9 @@ bool QFileSystemModel::remove(const QModelIndex &aindex)
/*!
Constructs a file system model with the given \a parent.
*/
-QFileSystemModel::QFileSystemModel(QObject *parent)
- : QAbstractItemModel(*new QFileSystemModelPrivate, parent)
+QFileSystemModel::QFileSystemModel(QObject *parent) :
+ QFileSystemModel(*new QFileSystemModelPrivate, parent)
{
- Q_D(QFileSystemModel);
- d->init();
}
/*!
@@ -247,9 +245,7 @@ QFileSystemModel::QFileSystemModel(QFileSystemModelPrivate &dd, QObject *parent)
/*!
Destroys this file system model.
*/
-QFileSystemModel::~QFileSystemModel()
-{
-}
+QFileSystemModel::~QFileSystemModel() = default;
/*!
\reimp
@@ -1945,6 +1941,9 @@ QStringList QFileSystemModelPrivate::unwatchPathsAt(const QModelIndex &index)
void QFileSystemModelPrivate::init()
{
Q_Q(QFileSystemModel);
+
+ delayedSortTimer.setSingleShot(true);
+
qRegisterMetaType<QVector<QPair<QString,QFileInfo> > >();
#if QT_CONFIG(filesystemwatcher)
q->connect(&fileInfoGatherer, SIGNAL(newListOfFiles(QString,QStringList)),
diff --git a/src/widgets/dialogs/qfilesystemmodel_p.h b/src/widgets/dialogs/qfilesystemmodel_p.h
index d8f9f2b076..844e417e2d 100644
--- a/src/widgets/dialogs/qfilesystemmodel_p.h
+++ b/src/widgets/dialogs/qfilesystemmodel_p.h
@@ -99,13 +99,13 @@ public:
class QFileSystemNode
{
public:
+ Q_DISABLE_COPY_MOVE(QFileSystemNode)
+
explicit QFileSystemNode(const QString &filename = QString(), QFileSystemNode *p = nullptr)
- : fileName(filename), populatedChildren(false), isVisible(false), dirtyChildrenIndex(-1), parent(p), info(nullptr) {}
+ : fileName(filename), parent(p) {}
~QFileSystemNode() {
qDeleteAll(children);
delete info;
- info = nullptr;
- parent = nullptr;
}
QString fileName;
@@ -204,31 +204,16 @@ public:
}
}
- bool populatedChildren;
- bool isVisible;
QHash<QFileSystemModelNodePathKey, QFileSystemNode *> children;
QList<QString> visibleChildren;
- int dirtyChildrenIndex;
+ QExtendedInformation *info = nullptr;
QFileSystemNode *parent;
-
-
- QExtendedInformation *info;
-
+ int dirtyChildrenIndex = -1;
+ bool populatedChildren = false;
+ bool isVisible = false;
};
- QFileSystemModelPrivate() :
- forceSort(true),
- sortColumn(0),
- sortOrder(Qt::AscendingOrder),
- readOnly(true),
- setRootPath(false),
- filters(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::AllDirs),
- nameFilterDisables(true), // false on windows, true on mac and unix
- disableRecursiveSort(false)
- {
- delayedSortTimer.setSingleShot(true);
- }
-
+ QFileSystemModelPrivate() = default;
void init();
/*
\internal
@@ -303,18 +288,7 @@ public:
QFileInfoGatherer fileInfoGatherer;
#endif // filesystemwatcher
QTimer delayedSortTimer;
- bool forceSort;
- int sortColumn;
- Qt::SortOrder sortOrder;
- bool readOnly;
- bool setRootPath;
- QDir::Filters filters;
QHash<const QFileSystemNode*, bool> bypassFilters;
- bool nameFilterDisables;
- //This flag is an optimization for the QFileDialog
- //It enable a sort which is not recursive, it means
- //we sort only what we see.
- bool disableRecursiveSort;
#if QT_CONFIG(regularexpression)
QStringList nameFilters;
#endif
@@ -322,7 +296,6 @@ public:
QFileSystemNode root;
- QBasicTimer fetchingTimer;
struct Fetching {
QString dir;
QString file;
@@ -330,6 +303,18 @@ public:
};
QVector<Fetching> toFetch;
+ QBasicTimer fetchingTimer;
+
+ QDir::Filters filters = QDir::AllEntries | QDir::NoDotAndDotDot | QDir::AllDirs;
+ int sortColumn = 0;
+ Qt::SortOrder sortOrder = Qt::AscendingOrder;
+ bool forceSort = true;
+ bool readOnly = true;
+ bool setRootPath = false;
+ bool nameFilterDisables = true; // false on windows, true on mac and unix
+ // This flag is an optimization for QFileDialog. It enables a sort which is
+ // not recursive, meaning we sort only what we see.
+ bool disableRecursiveSort = false;
};
Q_DECLARE_TYPEINFO(QFileSystemModelPrivate::Fetching, Q_MOVABLE_TYPE);
diff --git a/src/widgets/dialogs/qfontdialog.cpp b/src/widgets/dialogs/qfontdialog.cpp
index cd296ca020..7e3592e034 100644
--- a/src/widgets/dialogs/qfontdialog.cpp
+++ b/src/widgets/dialogs/qfontdialog.cpp
@@ -163,7 +163,7 @@ QFontDialog::QFontDialog(QWidget *parent)
\since 4.5
Constructs a standard font dialog with the given \a parent and specified
- \a initial color.
+ \a initial font.
*/
QFontDialog::QFontDialog(const QFont &initial, QWidget *parent)
: QFontDialog(parent)
diff --git a/src/widgets/doc/macOS/AppKit/AppKit.h b/src/widgets/doc/macOS/AppKit/AppKit.h
new file mode 100644
index 0000000000..29e2004423
--- /dev/null
+++ b/src/widgets/doc/macOS/AppKit/AppKit.h
@@ -0,0 +1 @@
+// Dummy header used in documentation build
diff --git a/src/widgets/doc/qtwidgets.qdocconf b/src/widgets/doc/qtwidgets.qdocconf
index 6e04372a8b..548224bf61 100644
--- a/src/widgets/doc/qtwidgets.qdocconf
+++ b/src/widgets/doc/qtwidgets.qdocconf
@@ -5,6 +5,9 @@ project = QtWidgets
description = Qt Widgets Reference Documentation
version = $QT_VERSION
+# dummy macOS headers for generating docs under non-mac platforms
+includepaths += -I./macOS
+
examplesinstallpath = widgets
qhp.projects = QtWidgets
diff --git a/src/widgets/doc/src/widgets-and-layouts/layout.qdoc b/src/widgets/doc/src/widgets-and-layouts/layout.qdoc
index e507d66451..65569a9cd2 100644
--- a/src/widgets/doc/src/widgets-and-layouts/layout.qdoc
+++ b/src/widgets/doc/src/widgets-and-layouts/layout.qdoc
@@ -220,7 +220,7 @@
When you make your own widget class, you should also communicate its layout
properties. If the widget uses one of Qt's layouts, this is already taken
- care of. If the widget does not have any child widgets, or uses manual
+ care of. If the widget does not have any child widgets, or uses a manual
layout, you can change the behavior of the widget using any or all of the
following mechanisms:
diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp
index 65708fa1ca..ca30c72db5 100644
--- a/src/widgets/graphicsview/qgraphicsitem.cpp
+++ b/src/widgets/graphicsview/qgraphicsitem.cpp
@@ -449,8 +449,8 @@
\value ItemSendsGeometryChanges The item enables itemChange()
notifications for ItemPositionChange, ItemPositionHasChanged,
- ItemMatrixChange, ItemTransformChange, ItemTransformHasChanged,
- ItemRotationChange, ItemRotationHasChanged, ItemScaleChange, ItemScaleHasChanged,
+ ItemTransformChange, ItemTransformHasChanged, ItemRotationChange,
+ ItemRotationHasChanged, ItemScaleChange, ItemScaleHasChanged,
ItemTransformOriginPointChange, and ItemTransformOriginPointHasChanged. For
performance reasons, these notifications are disabled by default. You must
enable this flag to receive notifications for position and transform
diff --git a/src/widgets/graphicsview/qgraphicsproxywidget.cpp b/src/widgets/graphicsview/qgraphicsproxywidget.cpp
index f1b01fbb4d..2b6712075f 100644
--- a/src/widgets/graphicsview/qgraphicsproxywidget.cpp
+++ b/src/widgets/graphicsview/qgraphicsproxywidget.cpp
@@ -697,9 +697,7 @@ void QGraphicsProxyWidgetPrivate::setWidget_helper(QWidget *newWidget, bool auto
if (!newWidget->testAttribute(Qt::WA_Resized))
newWidget->adjustSize();
- int left, top, right, bottom;
- newWidget->getContentsMargins(&left, &top, &right, &bottom);
- q->setContentsMargins(left, top, right, bottom);
+ q->setContentsMargins(newWidget->contentsMargins());
q->setWindowTitle(newWidget->windowTitle());
// size policies and constraints..
@@ -1293,8 +1291,15 @@ void QGraphicsProxyWidget::wheelEvent(QGraphicsSceneWheelEvent *event)
pos = d->mapToReceiver(pos, receiver);
// Send mouse event.
- QWheelEvent wheelEvent(pos.toPoint(), event->screenPos(), event->delta(),
- event->buttons(), event->modifiers(), event->orientation());
+ QPoint angleDelta;
+ if (event->orientation() == Qt::Horizontal)
+ angleDelta.setX(event->delta());
+ else
+ angleDelta.setY(event->delta());
+ // pixelDelta, inverted, scrollPhase and source from the original QWheelEvent
+ // were not preserved in the QGraphicsSceneWheelEvent unfortunately
+ QWheelEvent wheelEvent(pos, event->screenPos(), QPoint(), angleDelta,
+ event->buttons(), event->modifiers(), Qt::NoScrollPhase, false);
QPointer<QWidget> focusWidget = d->widget->focusWidget();
extern bool qt_sendSpontaneousEvent(QObject *, QEvent *);
qt_sendSpontaneousEvent(receiver, &wheelEvent);
diff --git a/src/widgets/graphicsview/qgraphicsscene.cpp b/src/widgets/graphicsview/qgraphicsscene.cpp
index 2cdbdc2072..313939e638 100644
--- a/src/widgets/graphicsview/qgraphicsscene.cpp
+++ b/src/widgets/graphicsview/qgraphicsscene.cpp
@@ -2805,7 +2805,7 @@ QGraphicsPolygonItem *QGraphicsScene::addPolygon(const QPolygonF &polygon,
Note that the item's geometry is provided in item coordinates, and its
position is initialized to (0, 0). For example, if a QRect(50, 50, 100,
100) is added, its top-left corner will be at (50, 50) relative to the
- origin in the items coordinate system.
+ origin in the item's coordinate system.
If the item is visible (i.e., QGraphicsItem::isVisible() returns \c true),
QGraphicsScene will emit changed() once control goes back to the event
diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp
index 3ec9668cde..7f14218720 100644
--- a/src/widgets/graphicsview/qgraphicsview.cpp
+++ b/src/widgets/graphicsview/qgraphicsview.cpp
@@ -691,7 +691,7 @@ void QGraphicsViewPrivate::mouseMoveEventHandler(QMouseEvent *event)
}
// Find the topmost item under the mouse with a cursor.
foreach (QGraphicsItem *item, scene->d_func()->cachedItemsUnderMouse) {
- if (item->hasCursor()) {
+ if (item->isEnabled() && item->hasCursor()) {
_q_setViewportCursor(item->cursor());
return;
}
@@ -808,7 +808,7 @@ void QGraphicsViewPrivate::_q_unsetViewportCursor()
Q_Q(QGraphicsView);
const auto items = q->items(lastMouseEvent.pos());
for (QGraphicsItem *item : items) {
- if (item->hasCursor()) {
+ if (item->isEnabled() && item->hasCursor()) {
_q_setViewportCursor(item->cursor());
return;
}
@@ -3426,12 +3426,13 @@ void QGraphicsView::wheelEvent(QWheelEvent *event)
QGraphicsSceneWheelEvent wheelEvent(QEvent::GraphicsSceneWheel);
wheelEvent.setWidget(viewport());
- wheelEvent.setScenePos(mapToScene(event->pos()));
- wheelEvent.setScreenPos(event->globalPos());
+ wheelEvent.setScenePos(mapToScene(event->position().toPoint()));
+ wheelEvent.setScreenPos(event->globalPosition().toPoint());
wheelEvent.setButtons(event->buttons());
wheelEvent.setModifiers(event->modifiers());
- wheelEvent.setDelta(event->delta());
- wheelEvent.setOrientation(event->orientation());
+ const bool horizontal = qAbs(event->angleDelta().x()) > qAbs(event->angleDelta().y());
+ wheelEvent.setDelta(horizontal ? event->angleDelta().x() : event->angleDelta().y());
+ wheelEvent.setOrientation(horizontal ? Qt::Horizontal : Qt::Vertical);
wheelEvent.setAccepted(false);
QCoreApplication::sendEvent(d->scene, &wheelEvent);
event->setAccepted(wheelEvent.isAccepted());
diff --git a/src/widgets/graphicsview/qgraphicswidget_p.cpp b/src/widgets/graphicsview/qgraphicswidget_p.cpp
index cc08b1c566..fd47f444ea 100644
--- a/src/widgets/graphicsview/qgraphicswidget_p.cpp
+++ b/src/widgets/graphicsview/qgraphicswidget_p.cpp
@@ -110,8 +110,6 @@ QGraphicsWidgetPrivate::QGraphicsWidgetPrivate()
QGraphicsWidgetPrivate::~QGraphicsWidgetPrivate()
{
- // Remove any lazily allocated data
- delete windowData;
}
/*!
@@ -147,7 +145,7 @@ void QGraphicsWidgetPrivate::ensureWindowFrameMargins() const
void QGraphicsWidgetPrivate::ensureWindowData()
{
if (!windowData)
- windowData = new WindowData;
+ windowData = qt_make_unique<WindowData>();
}
void QGraphicsWidgetPrivate::setPalette_helper(const QPalette &palette)
diff --git a/src/widgets/graphicsview/qgraphicswidget_p.h b/src/widgets/graphicsview/qgraphicswidget_p.h
index 5e0fdb693b..e4cc2c3016 100644
--- a/src/widgets/graphicsview/qgraphicswidget_p.h
+++ b/src/widgets/graphicsview/qgraphicswidget_p.h
@@ -190,7 +190,8 @@ public:
, buttonMouseOver(false)
, buttonSunken(false)
{}
- } *windowData;
+ };
+ std::unique_ptr<WindowData> windowData;
void ensureWindowData();
bool setWindowFrameMargins;
diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp
index 6ff0fe8132..d4c83cb82c 100644
--- a/src/widgets/itemviews/qabstractitemview.cpp
+++ b/src/widgets/itemviews/qabstractitemview.cpp
@@ -61,6 +61,7 @@
#include <qstyleditemdelegate.h>
#include <private/qabstractitemview_p.h>
#include <private/qabstractitemmodel_p.h>
+#include <private/qapplication_p.h>
#include <private/qguiapplication_p.h>
#include <private/qscrollbar_p.h>
#ifndef QT_NO_ACCESSIBILITY
@@ -343,7 +344,7 @@ void QAbstractItemViewPrivate::_q_scrollerStateChanged()
\value SingleSelection When the user selects an item, any already-selected
item becomes unselected. It is possible for the user to deselect the selected
- item.
+ item by pressing the Ctrl key when clicking the selected item.
\value ContiguousSelection When the user selects an item in the usual way,
the selection is cleared and the new item selected. However, if the user
@@ -2290,7 +2291,7 @@ void QAbstractItemView::keyPressEvent(QKeyEvent *event)
#ifdef QT_KEYPAD_NAVIGATION
switch (event->key()) {
case Qt::Key_Select:
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
if (!hasEditFocus()) {
setEditFocus(true);
return;
@@ -2298,7 +2299,7 @@ void QAbstractItemView::keyPressEvent(QKeyEvent *event)
}
break;
case Qt::Key_Back:
- if (QApplication::keypadNavigationEnabled() && hasEditFocus()) {
+ if (QApplicationPrivate::keypadNavigationEnabled() && hasEditFocus()) {
setEditFocus(false);
} else {
event->ignore();
@@ -2309,7 +2310,7 @@ void QAbstractItemView::keyPressEvent(QKeyEvent *event)
// Let's ignore vertical navigation events, only if there is no other widget
// what can take the focus in vertical direction. This means widget can handle navigation events
// even the widget don't have edit focus, and there is no other widget in requested direction.
- if(QApplication::keypadNavigationEnabled() && !hasEditFocus()
+ if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()
&& QWidgetPrivate::canKeypadNavigate(Qt::Vertical)) {
event->ignore();
return;
@@ -2318,14 +2319,14 @@ void QAbstractItemView::keyPressEvent(QKeyEvent *event)
case Qt::Key_Left:
case Qt::Key_Right:
// Similar logic as in up and down events
- if(QApplication::keypadNavigationEnabled() && !hasEditFocus()
+ if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()
&& (QWidgetPrivate::canKeypadNavigate(Qt::Horizontal) || QWidgetPrivate::inTabWidget(this))) {
event->ignore();
return;
}
break;
default:
- if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) {
+ if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) {
event->ignore();
return;
}
@@ -2413,7 +2414,8 @@ void QAbstractItemView::keyPressEvent(QKeyEvent *event)
case Qt::Key_Down:
case Qt::Key_Up:
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled() && QWidgetPrivate::canKeypadNavigate(Qt::Vertical)) {
+ if (QApplicationPrivate::keypadNavigationEnabled()
+ && QWidgetPrivate::canKeypadNavigate(Qt::Vertical)) {
event->accept(); // don't change focus
break;
}
diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp
index be80843b07..c4766a74bd 100644
--- a/src/widgets/itemviews/qheaderview.cpp
+++ b/src/widgets/itemviews/qheaderview.cpp
@@ -189,7 +189,7 @@ static const int maxSizeSection = 1048575; // since section size is in a bitfiel
The following values are obsolete:
\value Custom Use Fixed instead.
- \sa setResizeMode(), setSectionResizeMode(), stretchLastSection, minimumSectionSize
+ \sa setSectionResizeMode(), stretchLastSection, minimumSectionSize
*/
/*!
@@ -880,7 +880,7 @@ void QHeaderView::swapSections(int first, int second)
size equal to zero is however not recommended. In that situation hideSection
should be used instead.
- \sa sectionResized(), resizeMode(), sectionSize(), hideSection()
+ \sa sectionResized(), sectionSize(), hideSection()
*/
void QHeaderView::resizeSection(int logical, int size)
@@ -960,7 +960,7 @@ void QHeaderView::resizeSection(int logical, int size)
Resizes the sections according to the given \a mode, ignoring the current
resize mode.
- \sa resizeMode(), sectionResized()
+ \sa sectionResized()
*/
void QHeaderView::resizeSections(QHeaderView::ResizeMode mode)
@@ -1139,16 +1139,6 @@ void QHeaderView::setSectionsMovable(bool movable)
d->movableSections = movable;
}
-// ### Qt 6 - remove this obsolete function
-/*!
- \obsolete
- \fn void QHeaderView::setMovable(bool movable)
-
- Use setSectionsMovable instead.
-
- \sa setSectionsMovable()
-*/
-
/*!
\since 5.0
@@ -1167,16 +1157,6 @@ bool QHeaderView::sectionsMovable() const
return d->movableSections;
}
-// ### Qt 6 - remove this obsolete function
-/*!
- \obsolete
- \fn bool QHeaderView::isMovable() const
-
- Use sectionsMovable instead.
-
- \sa sectionsMovable()
-*/
-
/*!
\property QHeaderView::firstSectionMovable
\brief Whether the first column can be moved by the user
@@ -1223,16 +1203,6 @@ void QHeaderView::setSectionsClickable(bool clickable)
d->clickableSections = clickable;
}
-// ### Qt 6 - remove this obsolete function
-/*!
- \obsolete
- \fn void QHeaderView::setClickable(bool clickable)
-
- Use setSectionsClickable instead.
-
- \sa setSectionsClickable()
-*/
-
/*!
\since 5.0
@@ -1249,16 +1219,6 @@ bool QHeaderView::sectionsClickable() const
return d->clickableSections;
}
-// ### Qt 6 - remove this obsolete function
-/*!
- \obsolete
- \fn bool QHeaderView::isClickable() const
-
- Use sectionsClickable instead.
-
- \sa sectionsClickable()
-*/
-
void QHeaderView::setHighlightSections(bool highlight)
{
Q_D(QHeaderView);
@@ -1277,7 +1237,7 @@ bool QHeaderView::highlightSections() const
Sets the constraints on how the header can be resized to those described
by the given \a mode.
- \sa resizeMode(), length(), sectionResized()
+ \sa length(), sectionResized()
*/
void QHeaderView::setSectionResizeMode(ResizeMode mode)
@@ -1327,26 +1287,6 @@ void QHeaderView::setSectionResizeMode(int logicalIndex, ResizeMode mode)
d->doDelayedResizeSections(); // section sizes may change as a result of the new mode
}
-// ### Qt 6 - remove this obsolete function
-/*!
- \overload
- \obsolete
- \fn void QHeaderView::setResizeMode(int logicalIndex, ResizeMode mode)
-
- Use setSectionResizeMode instead.
-
- \sa setSectionResizeMode()
-*/
-
-/*!
- \obsolete
- \fn void QHeaderView::setResizeMode(ResizeMode mode)
-
- Use setSectionResizeMode instead.
-
- \sa setSectionResizeMode()
-*/
-
/*!
\since 5.0
@@ -1407,16 +1347,6 @@ int QHeaderView::resizeContentsPrecision() const
return d->resizeContentsPrecision;
}
-// ### Qt 6 - remove this obsolete function
-/*!
- \obsolete
- \fn QHeaderView::ResizeMode QHeaderView::resizeMode(int logicalIndex) const
-
- Use sectionResizeMode instead.
-
- \sa sectionResizeMode()
-*/
-
/*!
\since 4.1
@@ -1424,7 +1354,7 @@ int QHeaderView::resizeContentsPrecision() const
views, this can be used to see if the headerview needs to resize the
sections when the view's geometry changes.
- \sa stretchLastSection, resizeMode()
+ \sa stretchLastSection
*/
int QHeaderView::stretchSectionCount() const
diff --git a/src/widgets/itemviews/qitemeditorfactory.cpp b/src/widgets/itemviews/qitemeditorfactory.cpp
index 2d49dd4421..8ed2ee5f28 100644
--- a/src/widgets/itemviews/qitemeditorfactory.cpp
+++ b/src/widgets/itemviews/qitemeditorfactory.cpp
@@ -570,11 +570,9 @@ void QExpandingLineEdit::changeEvent(QEvent *e)
void QExpandingLineEdit::updateMinimumWidth()
{
- int left, right;
- getTextMargins(&left, 0, &right, 0);
- int width = left + right + 4 /*horizontalMargin in qlineedit.cpp*/;
- getContentsMargins(&left, 0, &right, 0);
- width += left + right;
+ const QMargins tm = textMargins();
+ const QMargins cm = contentsMargins();
+ const int width = tm.left() + tm.right() + cm.left() + cm.right() + 4 /*horizontalMargin in qlineedit.cpp*/;
QStyleOptionFrame opt;
initStyleOption(&opt);
diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp
index 25facd1484..04cddf2926 100644
--- a/src/widgets/itemviews/qlistview.cpp
+++ b/src/widgets/itemviews/qlistview.cpp
@@ -54,6 +54,7 @@
#if QT_CONFIG(rubberband)
#include <qrubberband.h>
#endif
+#include <private/qapplication_p.h>
#include <private/qlistview_p.h>
#include <private/qscrollbar_p.h>
#include <qdebug.h>
@@ -810,14 +811,14 @@ void QListView::mouseReleaseEvent(QMouseEvent *e)
void QListView::wheelEvent(QWheelEvent *e)
{
Q_D(QListView);
- if (e->orientation() == Qt::Vertical) {
+ if (qAbs(e->angleDelta().y()) > qAbs(e->angleDelta().x())) {
if (e->angleDelta().x() == 0
- && ((d->flow == TopToBottom && d->wrap) || (d->flow == LeftToRight && !d->wrap))
- && d->vbar->minimum() == 0 && d->vbar->maximum() == 0) {
+ && ((d->flow == TopToBottom && d->wrap) || (d->flow == LeftToRight && !d->wrap))
+ && d->vbar->minimum() == 0 && d->vbar->maximum() == 0) {
QPoint pixelDelta(e->pixelDelta().y(), e->pixelDelta().x());
QPoint angleDelta(e->angleDelta().y(), e->angleDelta().x());
- QWheelEvent hwe(e->pos(), e->globalPos(), pixelDelta, angleDelta, e->delta(),
- Qt::Horizontal, e->buttons(), e->modifiers(), e->phase(), e->source(), e->inverted());
+ QWheelEvent hwe(e->position(), e->globalPosition(), pixelDelta, angleDelta,
+ e->buttons(), e->modifiers(), e->phase(), e->inverted(), e->source());
if (e->spontaneous())
qt_sendSpontaneousEvent(d->hbar, &hwe);
else
@@ -1185,7 +1186,7 @@ QModelIndex QListView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifie
rect.translate(0, -rect.height());
if (rect.bottom() <= 0) {
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
int row = d->batchStartRow() - 1;
while (row >= 0 && d->isHiddenOrDisabled(row))
--row;
@@ -1214,7 +1215,7 @@ QModelIndex QListView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifie
rect.translate(0, rect.height());
if (rect.top() >= contents.height()) {
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
int rowCount = d->model->rowCount(d->root);
int row = 0;
while (row < rowCount && d->isHiddenOrDisabled(row))
@@ -1895,7 +1896,7 @@ bool QListViewPrivate::dropOn(QDropEvent *event, int *dropRow, int *dropCol, QMo
void QListViewPrivate::removeCurrentAndDisabled(QVector<QModelIndex> *indexes, const QModelIndex &current) const
{
- auto isCurrentOrDisabled = [=](const QModelIndex &index) {
+ auto isCurrentOrDisabled = [this, current](const QModelIndex &index) {
return !isIndexEnabled(index) || index == current;
};
indexes->erase(std::remove_if(indexes->begin(), indexes->end(),
diff --git a/src/widgets/itemviews/qlistwidget.cpp b/src/widgets/itemviews/qlistwidget.cpp
index 37bb370e73..e7dcfac403 100644
--- a/src/widgets/itemviews/qlistwidget.cpp
+++ b/src/widgets/itemviews/qlistwidget.cpp
@@ -930,12 +930,14 @@ QDataStream &operator>>(QDataStream &in, QListWidgetItem &item)
\sa Qt::AlignmentFlag
*/
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
\fn QColor QListWidgetItem::backgroundColor() const
\obsolete
This function is deprecated. Use background() instead.
*/
+#endif
/*!
\fn QBrush QListWidgetItem::background() const
@@ -946,6 +948,7 @@ QDataStream &operator>>(QDataStream &in, QListWidgetItem &item)
\sa setBackground(), foreground()
*/
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
\fn QColor QListWidgetItem::textColor() const
\obsolete
@@ -954,6 +957,7 @@ QDataStream &operator>>(QDataStream &in, QListWidgetItem &item)
This function is deprecated. Use foreground() instead.
*/
+#endif
/*!
\fn QBrush QListWidgetItem::foreground() const
@@ -1119,12 +1123,14 @@ void QListWidgetItem::setFlags(Qt::ItemFlags aflags)
\sa background(), setForeground()
*/
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
\fn void QListWidgetItem::setTextColor(const QColor &color)
\obsolete
This function is deprecated. Use setForeground() instead.
*/
+#endif
/*!
\fn void QListWidgetItem::setForeground(const QBrush &brush)
diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp
index 8860ef208d..e706af1a42 100644
--- a/src/widgets/itemviews/qtableview.cpp
+++ b/src/widgets/itemviews/qtableview.cpp
@@ -51,6 +51,7 @@
#if QT_CONFIG(abstractbutton)
#include <qabstractbutton.h>
#endif
+#include <private/qapplication_p.h>
#include <private/qtableview_p.h>
#include <private/qheaderview_p.h>
#include <private/qscrollbar_p.h>
@@ -1710,7 +1711,7 @@ QModelIndex QTableView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifi
case MoveUp: {
int originalRow = visualRow;
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled() && visualRow == 0)
+ if (QApplicationPrivate::keypadNavigationEnabled() && visualRow == 0)
visualRow = d->visualRow(model()->rowCount() - 1) + 1;
// FIXME? visualRow = bottom + 1;
#endif
@@ -1739,7 +1740,7 @@ QModelIndex QTableView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifi
visualRow = d->visualRow(d->rowSpanEndLogical(span.top(), span.height()));
}
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled() && visualRow >= bottom)
+ if (QApplicationPrivate::keypadNavigationEnabled() && visualRow >= bottom)
visualRow = -1;
#endif
int r = d->logicalRow(visualRow);
diff --git a/src/widgets/itemviews/qtablewidget.cpp b/src/widgets/itemviews/qtablewidget.cpp
index 0fb9e28385..a25a582881 100644
--- a/src/widgets/itemviews/qtablewidget.cpp
+++ b/src/widgets/itemviews/qtablewidget.cpp
@@ -1251,6 +1251,7 @@ void QTableWidgetItem::setFlags(Qt::ItemFlags aflags)
\sa font(), setText(), setForeground()
*/
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
\fn QColor QTableWidgetItem::backgroundColor() const
\obsolete
@@ -1264,6 +1265,7 @@ void QTableWidgetItem::setFlags(Qt::ItemFlags aflags)
This function is deprecated. Use setBackground() instead.
*/
+#endif
/*!
\fn QBrush QTableWidgetItem::background() const
@@ -1283,6 +1285,7 @@ void QTableWidgetItem::setFlags(Qt::ItemFlags aflags)
\sa setForeground()
*/
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
\fn QColor QTableWidgetItem::textColor() const
\obsolete
@@ -1296,6 +1299,7 @@ void QTableWidgetItem::setFlags(Qt::ItemFlags aflags)
This function is deprecated. Use setForeground() instead.
*/
+#endif
/*!
\fn QBrush QTableWidgetItem::foreground() const
diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp
index 55b10d13c1..23a530821f 100644
--- a/src/widgets/itemviews/qtreeview.cpp
+++ b/src/widgets/itemviews/qtreeview.cpp
@@ -55,6 +55,7 @@
#include <qaccessible.h>
#endif
+#include <private/qapplication_p.h>
#include <private/qtreeview_p.h>
#include <private/qheaderview_p.h>
@@ -2214,14 +2215,14 @@ QModelIndex QTreeView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifie
case MoveNext:
case MoveDown:
#ifdef QT_KEYPAD_NAVIGATION
- if (vi == d->viewItems.count()-1 && QApplication::keypadNavigationEnabled())
+ if (vi == d->viewItems.count()-1 && QApplicationPrivate::keypadNavigationEnabled())
return d->model->index(0, current.column(), d->root);
#endif
return d->modelIndex(d->below(vi), current.column());
case MovePrevious:
case MoveUp:
#ifdef QT_KEYPAD_NAVIGATION
- if (vi == 0 && QApplication::keypadNavigationEnabled())
+ if (vi == 0 && QApplicationPrivate::keypadNavigationEnabled())
return d->modelIndex(d->viewItems.count() - 1, current.column());
#endif
return d->modelIndex(d->above(vi), current.column());
diff --git a/src/widgets/itemviews/qtreewidget.cpp b/src/widgets/itemviews/qtreewidget.cpp
index d2dc91b18c..d285ad6d28 100644
--- a/src/widgets/itemviews/qtreewidget.cpp
+++ b/src/widgets/itemviews/qtreewidget.cpp
@@ -1251,6 +1251,7 @@ bool QTreeWidgetItem::isFirstColumnSpanned() const
\sa font(), setText(), setForeground()
*/
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
\fn QColor QTreeWidgetItem::backgroundColor(int column) const
\obsolete
@@ -1264,6 +1265,7 @@ bool QTreeWidgetItem::isFirstColumnSpanned() const
This function is deprecated. Use setBackground() instead.
*/
+#endif
/*!
\fn QBrush QTreeWidgetItem::background(int column) const
@@ -1284,6 +1286,7 @@ bool QTreeWidgetItem::isFirstColumnSpanned() const
\sa setForeground()
*/
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
\fn QColor QTreeWidgetItem::textColor(int column) const
\obsolete
@@ -1297,6 +1300,7 @@ bool QTreeWidgetItem::isFirstColumnSpanned() const
This function is deprecated. Use setForeground() instead.
*/
+#endif
/*!
\fn QBrush QTreeWidgetItem::foreground(int column) const
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index c922aecceb..94b14ecb4f 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -236,9 +236,6 @@ void QApplicationPrivate::createEventDispatcher()
encapsulated in a QStyle object. This can be changed at runtime
with setStyle().
- \li It specifies how the application is to allocate colors. See
- setColorSpec() for details.
-
\li It provides localization of strings that are visible to the
user via translate().
@@ -299,11 +296,6 @@ void QApplicationPrivate::createEventDispatcher()
setStyle().
\row
- \li Color usage
- \li colorSpec(),
- setColorSpec().
-
- \row
\li Text handling
\li installTranslator(),
removeTranslator()
@@ -337,6 +329,7 @@ void QApplicationPrivate::createEventDispatcher()
\sa QCoreApplication, QAbstractEventDispatcher, QEventLoop, QSettings
*/
+#if QT_DEPRECATED_SINCE(5, 8)
// ### fixme: Qt 6: Remove ColorSpec and accessors.
/*!
\enum QApplication::ColorSpec
@@ -350,15 +343,7 @@ void QApplicationPrivate::createEventDispatcher()
See setColorSpec() for full details.
*/
-
-/*!
- \fn QApplication::setGraphicsSystem(const QString &)
- \obsolete
-
- This call has no effect.
-
- Use the QPA framework instead.
-*/
+#endif
/*!
\fn QWidget *QApplication::topLevelAt(const QPoint &point)
@@ -1956,15 +1941,8 @@ bool QApplication::event(QEvent *e)
return QGuiApplication::event(e);
}
-/*!
- \fn void QApplication::syncX()
- Was used to synchronize with the X server in 4.x, here for source compatibility.
- \internal
- \obsolete
-*/
-
// ### FIXME: topLevelWindows does not contain QWidgets without a parent
-// until create_sys is called. So we have to override the
+// until QWidgetPrivate::create is called. So we have to override the
// QGuiApplication::notifyLayoutDirectionChange
// to do the right thing.
void QApplicationPrivate::notifyLayoutDirectionChange()
@@ -3240,13 +3218,18 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
if (spontaneous && phase == Qt::ScrollBegin)
QApplicationPrivate::wheel_widget = nullptr;
- const QPoint &relpos = wheel->pos();
+ QPoint relpos = wheel->position().toPoint();
if (spontaneous && (phase == Qt::NoScrollPhase || phase == Qt::ScrollUpdate))
QApplicationPrivate::giveFocusAccordingToFocusPolicy(w, e, relpos);
+#if QT_DEPRECATED_SINCE(5, 14)
QWheelEvent we(relpos, wheel->globalPos(), wheel->pixelDelta(), wheel->angleDelta(), wheel->delta(), wheel->orientation(), wheel->buttons(),
wheel->modifiers(), phase, wheel->source(), wheel->inverted());
+#else
+ QWheelEvent we(relpos, wheel->globalPosition(), wheel->pixelDelta(), wheel->angleDelta(), wheel->buttons(),
+ wheel->modifiers(), phase, wheel->inverted(), wheel->source());
+#endif
we.setTimestamp(wheel->timestamp());
bool eventAccepted;
do {
@@ -3281,9 +3264,14 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
// is set. Since it accepted the wheel event previously, we continue
// sending those events until we get a ScrollEnd, which signifies
// the end of the natural scrolling sequence.
- const QPoint &relpos = QApplicationPrivate::wheel_widget->mapFromGlobal(wheel->globalPos());
+ const QPoint &relpos = QApplicationPrivate::wheel_widget->mapFromGlobal(wheel->globalPosition().toPoint());
+#if QT_DEPRECATED_SINCE(5, 0)
QWheelEvent we(relpos, wheel->globalPos(), wheel->pixelDelta(), wheel->angleDelta(), wheel->delta(), wheel->orientation(), wheel->buttons(),
wheel->modifiers(), wheel->phase(), wheel->source());
+#else
+ QWheelEvent we(relpos, wheel->globalPosition(), wheel->pixelDelta(), wheel->angleDelta(), wheel->buttons(),
+ wheel->modifiers(), wheel->phase(), wheel->inverted(), wheel->source());
+#endif
we.setTimestamp(wheel->timestamp());
we.spont = true;
we.ignore();
@@ -3833,8 +3821,6 @@ void QApplicationPrivate::openPopup(QWidget *popup)
This feature is available in Qt for Embedded Linux only.
\since 4.6
-
- \sa keypadNavigationEnabled()
*/
void QApplication::setNavigationMode(Qt::NavigationMode mode)
{
@@ -3847,8 +3833,6 @@ void QApplication::setNavigationMode(Qt::NavigationMode mode)
This feature is available in Qt for Embedded Linux only.
\since 4.6
-
- \sa keypadNavigationEnabled()
*/
Qt::NavigationMode QApplication::navigationMode()
{
@@ -3984,15 +3968,6 @@ int QApplication::doubleClickInterval()
}
/*!
- \fn QApplication::keyboardInputDirection()
- \since 4.2
- \deprecated
-
- Returns the current keyboard input direction. Replaced with QInputMethod::inputDirection()
- \sa QInputMethod::inputDirection()
-*/
-
-/*!
\property QApplication::keyboardInputInterval
\brief the time limit in milliseconds that distinguishes a key press
from two consecutive key presses
@@ -4129,14 +4104,6 @@ void QApplication::beep()
\sa QCoreApplication::instance(), qGuiApp
*/
-/*!
- \fn QLocale QApplication::keyboardInputLocale()
- \since 4.2
- \obsolete
-
- Returns the current keyboard input locale. Replaced with QInputMethod::locale()
-*/
-
bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event)
{
return QGuiApplication::sendSpontaneousEvent(receiver, event);
diff --git a/src/widgets/kernel/qapplication_p.h b/src/widgets/kernel/qapplication_p.h
index 98eb9b73c6..36c0ba8739 100644
--- a/src/widgets/kernel/qapplication_p.h
+++ b/src/widgets/kernel/qapplication_p.h
@@ -136,6 +136,13 @@ public:
static QWidget *tryModalHelper_sys(QWidget *top);
bool canQuit();
#endif
+#ifdef QT_KEYPAD_NAVIGATION
+ static bool keypadNavigationEnabled()
+ {
+ return navigationMode == Qt::NavigationModeKeypadTabOrder ||
+ navigationMode == Qt::NavigationModeKeypadDirectional;
+ }
+#endif
bool notify_helper(QObject *receiver, QEvent * e);
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index 89b0e56297..cdea0a570c 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -393,7 +393,7 @@ QPointer<QWidget> QWidgetPrivate::editingWidget;
This feature is only available in Qt for Embedded Linux.
- \sa setEditFocus(), QApplication::keypadNavigationEnabled()
+ \sa setEditFocus(), QApplication::navigationMode()
*/
bool QWidget::hasEditFocus() const
{
@@ -413,7 +413,7 @@ bool QWidget::hasEditFocus() const
This feature is only available in Qt for Embedded Linux.
- \sa hasEditFocus(), QApplication::keypadNavigationEnabled()
+ \sa hasEditFocus(), QApplication::navigationMode()
*/
void QWidget::setEditFocus(bool on)
{
@@ -1193,7 +1193,7 @@ void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f)
q->setAttribute(Qt::WA_ContentsMarginsRespectsSafeArea);
q->setAttribute(Qt::WA_WState_Hidden);
- //give potential windows a bigger "pre-initial" size; create_sys() will give them a new size later
+ //give potential windows a bigger "pre-initial" size; create() will give them a new size later
data.crect = parentWidget ? QRect(0,0,100,30) : QRect(0,0,640,480);
focus_next = focus_prev = q;
@@ -1287,27 +1287,19 @@ QScreen *QWidgetPrivate::associatedScreen() const
/*!
Creates a new widget window.
- The parameter \a window is ignored in Qt 5. Please use
- QWindow::fromWinId() to create a QWindow wrapping a foreign
- window and pass it to QWidget::createWindowContainer() instead.
-
- Initializes the window (sets the geometry etc.) if \a
- initializeWindow is true. If \a initializeWindow is false, no
- initialization is performed. This parameter only makes sense if \a
- window is a valid window.
-
- Destroys the old window if \a destroyOldWindow is true. If \a
- destroyOldWindow is false, you are responsible for destroying the
- window yourself (using platform native code).
-
- The QWidget constructor calls create(0,true,true) to create a
- window for this widget.
+ The parameters \a window, \a initializeWindow, and \a destroyOldWindow
+ are ignored in Qt 5. Please use QWindow::fromWinId() to create a
+ QWindow wrapping a foreign window and pass it to
+ QWidget::createWindowContainer() instead.
\sa createWindowContainer(), QWindow::fromWinId()
*/
void QWidget::create(WId window, bool initializeWindow, bool destroyOldWindow)
{
+ Q_UNUSED(initializeWindow);
+ Q_UNUSED(destroyOldWindow);
+
Q_D(QWidget);
if (Q_UNLIKELY(window))
qWarning("QWidget::create(): Parameter 'window' does not have any effect.");
@@ -1367,7 +1359,7 @@ void QWidget::create(WId window, bool initializeWindow, bool destroyOldWindow)
d->updateIsOpaque();
setAttribute(Qt::WA_WState_Created); // set created flag
- d->create_sys(window, initializeWindow, destroyOldWindow);
+ d->create();
// a real toplevel window needs a backing store
if (isWindow() && windowType() != Qt::Desktop) {
@@ -1431,14 +1423,10 @@ void q_createNativeChildrenAndSetParent(const QWidget *parentWidget)
}
-void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyOldWindow)
+void QWidgetPrivate::create()
{
Q_Q(QWidget);
- Q_UNUSED(window);
- Q_UNUSED(initializeWindow);
- Q_UNUSED(destroyOldWindow);
-
if (!q->testAttribute(Qt::WA_NativeWindow) && !q->isWindow())
return; // we only care about real toplevels
@@ -6469,8 +6457,18 @@ void QWidget::setFocusProxy(QWidget * w)
}
}
+ QWidget *oldDeepestFocusProxy = d_func()->deepestFocusProxy();
+ if (!oldDeepestFocusProxy)
+ oldDeepestFocusProxy = this;
+ const bool changingAppFocusWidget = (QApplicationPrivate::focus_widget == oldDeepestFocusProxy);
+
d->createExtra();
d->extra->focus_proxy = w;
+
+ if (changingAppFocusWidget) {
+ QWidget *newDeepestFocusProxy = d_func()->deepestFocusProxy();
+ QApplicationPrivate::focus_widget = newDeepestFocusProxy ? newDeepestFocusProxy : this;
+ }
}
@@ -7474,6 +7472,17 @@ QByteArray QWidget::saveGeometry() const
return array;
}
+static void checkRestoredGeometry(const QRect &availableGeometry, QRect *restoredGeometry,
+ int frameHeight)
+{
+ if (!restoredGeometry->intersects(availableGeometry)) {
+ restoredGeometry->moveBottom(qMin(restoredGeometry->bottom(), availableGeometry.bottom()));
+ restoredGeometry->moveLeft(qMax(restoredGeometry->left(), availableGeometry.left()));
+ restoredGeometry->moveRight(qMin(restoredGeometry->right(), availableGeometry.right()));
+ }
+ restoredGeometry->moveTop(qMax(restoredGeometry->top(), availableGeometry.top() + frameHeight));
+}
+
/*!
\since 4.2
@@ -7528,7 +7537,7 @@ bool QWidget::restoreGeometry(const QByteArray &geometry)
quint8 fullScreen;
qint32 restoredScreenWidth = 0;
- stream >> restoredFrameGeometry
+ stream >> restoredFrameGeometry // Only used for sanity checks in version 0
>> restoredNormalGeometry
>> restoredScreenNumber
>> maximized
@@ -7558,8 +7567,6 @@ bool QWidget::restoreGeometry(const QByteArray &geometry)
}
const int frameHeight = 20;
- if (!restoredFrameGeometry.isValid())
- restoredFrameGeometry = QRect(QPoint(0,0), sizeHint());
if (!restoredNormalGeometry.isValid())
restoredNormalGeometry = QRect(QPoint(0, frameHeight), sizeHint());
@@ -7579,23 +7586,11 @@ bool QWidget::restoreGeometry(const QByteArray &geometry)
// - (Mac only) The window is higher than the available geometry. It must
// be possible to bring the size grip on screen by moving the window.
#if 0 // Used to be included in Qt4 for Q_WS_MAC
- restoredFrameGeometry.setHeight(qMin(restoredFrameGeometry.height(), availableGeometry.height()));
restoredNormalGeometry.setHeight(qMin(restoredNormalGeometry.height(), availableGeometry.height() - frameHeight));
#endif
- if (!restoredFrameGeometry.intersects(availableGeometry)) {
- restoredFrameGeometry.moveBottom(qMin(restoredFrameGeometry.bottom(), availableGeometry.bottom()));
- restoredFrameGeometry.moveLeft(qMax(restoredFrameGeometry.left(), availableGeometry.left()));
- restoredFrameGeometry.moveRight(qMin(restoredFrameGeometry.right(), availableGeometry.right()));
- }
- restoredFrameGeometry.moveTop(qMax(restoredFrameGeometry.top(), availableGeometry.top()));
-
- if (!restoredNormalGeometry.intersects(availableGeometry)) {
- restoredNormalGeometry.moveBottom(qMin(restoredNormalGeometry.bottom(), availableGeometry.bottom()));
- restoredNormalGeometry.moveLeft(qMax(restoredNormalGeometry.left(), availableGeometry.left()));
- restoredNormalGeometry.moveRight(qMin(restoredNormalGeometry.right(), availableGeometry.right()));
- }
- restoredNormalGeometry.moveTop(qMax(restoredNormalGeometry.top(), availableGeometry.top() + frameHeight));
+ checkRestoredGeometry(availableGeometry, &restoredGeometry, frameHeight);
+ checkRestoredGeometry(availableGeometry, &restoredNormalGeometry, frameHeight);
if (maximized || fullScreen) {
// set geometry before setting the window state to make
@@ -7649,7 +7644,7 @@ bool QWidget::restoreGeometry(const QByteArray &geometry)
Changing the margins will trigger a resizeEvent().
- \sa contentsRect(), getContentsMargins()
+ \sa contentsRect(), contentsMargins()
*/
void QWidget::setContentsMargins(int left, int top, int right, int bottom)
{
@@ -7679,7 +7674,7 @@ void QWidget::setContentsMargins(int left, int top, int right, int bottom)
Changing the margins will trigger a resizeEvent().
- \sa contentsRect(), getContentsMargins()
+ \sa contentsRect(), contentsMargins()
*/
void QWidget::setContentsMargins(const QMargins &margins)
{
@@ -7708,7 +7703,11 @@ void QWidgetPrivate::updateContentsRect()
QCoreApplication::sendEvent(q, &e);
}
+#if QT_DEPRECATED_SINCE(5, 14)
/*!
+ \obsolete
+ Use contentsMargins().
+
Returns the widget's contents margins for \a left, \a top, \a
right, and \a bottom.
@@ -7726,6 +7725,7 @@ void QWidget::getContentsMargins(int *left, int *top, int *right, int *bottom) c
if (bottom)
*bottom = m.bottom();
}
+#endif
// FIXME: Move to qmargins.h for next minor Qt release
QMargins operator|(const QMargins &m1, const QMargins &m2)
@@ -7739,7 +7739,7 @@ QMargins operator|(const QMargins &m1, const QMargins &m2)
\brief The contentsMargins function returns the widget's contents margins.
- \sa getContentsMargins(), setContentsMargins(), contentsRect()
+ \sa setContentsMargins(), contentsRect()
*/
QMargins QWidget::contentsMargins() const
{
@@ -7752,7 +7752,7 @@ QMargins QWidget::contentsMargins() const
/*!
Returns the area inside the widget's margins.
- \sa setContentsMargins(), getContentsMargins()
+ \sa setContentsMargins(), contentsMargins()
*/
QRect QWidget::contentsRect() const
{
@@ -9408,12 +9408,6 @@ bool QWidget::event(QEvent *event)
d->renderToTextureReallyDirty = 1;
#endif
break;
- case QEvent::PlatformSurface: {
- auto surfaceEvent = static_cast<QPlatformSurfaceEvent*>(event);
- if (surfaceEvent->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed)
- d->setWinId(0);
- break;
- }
#ifndef QT_NO_PROPERTIES
case QEvent::DynamicPropertyChange: {
const QByteArray &propName = static_cast<QDynamicPropertyChangeEvent *>(event)->propertyName();
@@ -11392,7 +11386,7 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on)
// windowModality property and then reshown.
}
if (testAttribute(Qt::WA_WState_Created)) {
- // don't call setModal_sys() before create_sys()
+ // don't call setModal_sys() before create()
d->setModal_sys();
}
break;
diff --git a/src/widgets/kernel/qwidget.h b/src/widgets/kernel/qwidget.h
index e47deb5d0d..0777bed65c 100644
--- a/src/widgets/kernel/qwidget.h
+++ b/src/widgets/kernel/qwidget.h
@@ -524,7 +524,10 @@ public:
void setContentsMargins(int left, int top, int right, int bottom);
void setContentsMargins(const QMargins &margins);
+#if QT_DEPRECATED_SINCE(5, 14)
+ QT_DEPRECATED_X("use contentsMargins()")
void getContentsMargins(int *left, int *top, int *right, int *bottom) const;
+#endif
QMargins contentsMargins() const;
QRect contentsRect() const;
diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h
index 99ec38e050..7cb9a3895a 100644
--- a/src/widgets/kernel/qwidget_p.h
+++ b/src/widgets/kernel/qwidget_p.h
@@ -360,7 +360,7 @@ public:
void update(T t);
void init(QWidget *desktopWidget, Qt::WindowFlags f);
- void create_sys(WId window, bool initializeWindow, bool destroyOldWindow);
+ void create();
void createRecursively();
void createWinId();
diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp
index ba10083829..5537ff497a 100644
--- a/src/widgets/kernel/qwidgetwindow.cpp
+++ b/src/widgets/kernel/qwidgetwindow.cpp
@@ -828,14 +828,14 @@ void QWidgetWindow::handleWheelEvent(QWheelEvent *event)
return;
QWidget *rootWidget = m_widget;
- QPoint pos = event->pos();
+ QPoint pos = event->position().toPoint();
// Use proper popup window for wheel event. Some QPA sends the wheel
// event to the root menu, so redirect it to the proper popup window.
QWidget *activePopupWidget = QApplication::activePopupWidget();
if (activePopupWidget && activePopupWidget != m_widget) {
rootWidget = activePopupWidget;
- pos = rootWidget->mapFromGlobal(event->globalPos());
+ pos = rootWidget->mapFromGlobal(event->globalPosition().toPoint());
}
// which child should have it?
@@ -846,7 +846,12 @@ void QWidgetWindow::handleWheelEvent(QWheelEvent *event)
QPoint mapped = widget->mapFrom(rootWidget, pos);
+#if QT_DEPRECATED_SINCE(5, 0)
QWheelEvent translated(mapped, event->globalPos(), event->pixelDelta(), event->angleDelta(), event->delta(), event->orientation(), event->buttons(), event->modifiers(), event->phase(), event->source(), event->inverted());
+#else
+ QWheelEvent translated(QPointF(mapped), event->globalPosition(), event->pixelDelta(), event->angleDelta(),
+ event->buttons(), event->modifiers(), event->phase(), event->inverted(), event->source());
+#endif
translated.setTimestamp(event->timestamp());
QGuiApplication::forwardEvent(widget, &translated, event);
}
diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp
index 34cc3c93db..e21ff4bec8 100644
--- a/src/widgets/styles/qfusionstyle.cpp
+++ b/src/widgets/styles/qfusionstyle.cpp
@@ -469,7 +469,14 @@ void QFusionStyle::drawPrimitive(PrimitiveElement elem,
case PE_FrameGroupBox:
{
QPixmap pixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/fusion_groupbox.png"));
- int topMargin = qMax(pixelMetric(PM_ExclusiveIndicatorHeight), option->fontMetrics.height()) + groupBoxTopMargin;
+ int topMargin = 0;
+ auto control = dynamic_cast<const QGroupBox *>(widget);
+ if (control && !control->isCheckable() && control->title().isEmpty()) {
+ // Shrinking the topMargin if Not checkable AND title is empty
+ topMargin = groupBoxTopMargin;
+ } else {
+ topMargin = qMax(pixelMetric(PM_ExclusiveIndicatorHeight), option->fontMetrics.height()) + groupBoxTopMargin;
+ }
QRect frame = option->rect.adjusted(0, topMargin, 0, 0);
qDrawBorderPixmap(painter, frame, QMargins(6, 6, 6, 6), pixmap);
break;
diff --git a/src/widgets/util/qcompleter.cpp b/src/widgets/util/qcompleter.cpp
index ee0418b5b8..7b69eff30c 100644
--- a/src/widgets/util/qcompleter.cpp
+++ b/src/widgets/util/qcompleter.cpp
@@ -161,6 +161,7 @@
#include "QtWidgets/qapplication.h"
#include "QtGui/qevent.h"
#include "QtWidgets/qdesktopwidget.h"
+#include <private/qapplication_p.h>
#include <private/qdesktopwidget_p.h>
#if QT_CONFIG(lineedit)
#include "QtWidgets/qlineedit.h"
@@ -1416,7 +1417,7 @@ bool QCompleter::eventFilter(QObject *o, QEvent *e)
// widget lost focus, hide the popup
if (d->widget && (!d->widget->hasFocus()
#ifdef QT_KEYPAD_NAVIGATION
- || (QApplication::keypadNavigationEnabled() && !d->widget->hasEditFocus())
+ || (QApplicationPrivate::keypadNavigationEnabled() && !d->widget->hasEditFocus())
#endif
))
d->popup->hide();
@@ -1434,7 +1435,7 @@ bool QCompleter::eventFilter(QObject *o, QEvent *e)
switch (key) {
#ifdef QT_KEYPAD_NAVIGATION
case Qt::Key_Select:
- if (!QApplication::keypadNavigationEnabled())
+ if (!QApplicationPrivate::keypadNavigationEnabled())
break;
#endif
case Qt::Key_Return:
@@ -1464,7 +1465,7 @@ bool QCompleter::eventFilter(QObject *o, QEvent *e)
#ifdef QT_KEYPAD_NAVIGATION
case QEvent::KeyRelease: {
QKeyEvent *ke = static_cast<QKeyEvent *>(e);
- if (QApplication::keypadNavigationEnabled() && ke->key() == Qt::Key_Back) {
+ if (QApplicationPrivate::keypadNavigationEnabled() && ke->key() == Qt::Key_Back) {
// Send the event to the 'widget'. This is what we did for KeyPress, so we need
// to do the same for KeyRelease, in case the widget's KeyPress event set
// up something (such as a timer) that is relying on also receiving the
@@ -1481,7 +1482,7 @@ bool QCompleter::eventFilter(QObject *o, QEvent *e)
case QEvent::MouseButtonPress: {
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
// if we've clicked in the widget (or its descendant), let it handle the click
QWidget *source = qobject_cast<QWidget *>(o);
if (source) {
diff --git a/src/widgets/widgets/qabstractbutton.cpp b/src/widgets/widgets/qabstractbutton.cpp
index f30a3bc7b8..d956d2ba23 100644
--- a/src/widgets/widgets/qabstractbutton.cpp
+++ b/src/widgets/widgets/qabstractbutton.cpp
@@ -44,6 +44,7 @@
#endif
#if QT_CONFIG(buttongroup)
#include "qbuttongroup.h"
+#include "private/qapplication_p.h"
#include "private/qbuttongroup_p.h"
#endif
#include "qabstractbutton_p.h"
@@ -319,7 +320,7 @@ void QAbstractButtonPrivate::moveFocus(int key)
if (exclusive
#ifdef QT_KEYPAD_NAVIGATION
- && !QApplication::keypadNavigationEnabled()
+ && !QApplicationPrivate::keypadNavigationEnabled()
#endif
&& candidate
&& fb->d_func()->checked
@@ -1063,7 +1064,7 @@ void QAbstractButton::keyPressEvent(QKeyEvent *e)
case Qt::Key_Right:
case Qt::Key_Down: {
#ifdef QT_KEYPAD_NAVIGATION
- if ((QApplication::keypadNavigationEnabled()
+ if ((QApplicationPrivate::keypadNavigationEnabled()
&& (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right))
|| (!QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional
|| (e->key() == Qt::Key_Up || e->key() == Qt::Key_Down))) {
@@ -1159,7 +1160,7 @@ void QAbstractButton::focusInEvent(QFocusEvent *e)
{
Q_D(QAbstractButton);
#ifdef QT_KEYPAD_NAVIGATION
- if (!QApplication::keypadNavigationEnabled())
+ if (!QApplicationPrivate::keypadNavigationEnabled())
#endif
d->fixFocusPolicy();
QWidget::focusInEvent(e);
diff --git a/src/widgets/widgets/qabstractscrollarea.cpp b/src/widgets/widgets/qabstractscrollarea.cpp
index b9e0d3280f..55b2dcd662 100644
--- a/src/widgets/widgets/qabstractscrollarea.cpp
+++ b/src/widgets/widgets/qabstractscrollarea.cpp
@@ -1324,7 +1324,7 @@ void QAbstractScrollArea::mouseMoveEvent(QMouseEvent *e)
void QAbstractScrollArea::wheelEvent(QWheelEvent *e)
{
Q_D(QAbstractScrollArea);
- if (e->orientation() == Qt::Horizontal)
+ if (qAbs(e->angleDelta().x()) > qAbs(e->angleDelta().y()))
QCoreApplication::sendEvent(d->hbar, e);
else
QCoreApplication::sendEvent(d->vbar, e);
@@ -1362,7 +1362,7 @@ void QAbstractScrollArea::keyPressEvent(QKeyEvent * e)
#endif
} else {
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) {
+ if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) {
e->ignore();
return;
}
@@ -1376,7 +1376,7 @@ void QAbstractScrollArea::keyPressEvent(QKeyEvent * e)
break;
case Qt::Key_Left:
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled() && hasEditFocus()
+ if (QApplicationPrivate::keypadNavigationEnabled() && hasEditFocus()
&& (!d->hbar->isVisible() || d->hbar->value() == d->hbar->minimum())) {
//if we aren't using the hbar or we are already at the leftmost point ignore
e->ignore();
@@ -1389,7 +1389,7 @@ void QAbstractScrollArea::keyPressEvent(QKeyEvent * e)
break;
case Qt::Key_Right:
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled() && hasEditFocus()
+ if (QApplicationPrivate::keypadNavigationEnabled() && hasEditFocus()
&& (!d->hbar->isVisible() || d->hbar->value() == d->hbar->maximum())) {
//if we aren't using the hbar or we are already at the rightmost point ignore
e->ignore();
diff --git a/src/widgets/widgets/qabstractslider.cpp b/src/widgets/widgets/qabstractslider.cpp
index 2172ebc99c..129d540f50 100644
--- a/src/widgets/widgets/qabstractslider.cpp
+++ b/src/widgets/widgets/qabstractslider.cpp
@@ -47,6 +47,8 @@
#endif
#include <limits.h>
+#include <private/qapplication_p.h>
+
QT_BEGIN_NAMESPACE
/*!
@@ -764,10 +766,11 @@ void QAbstractSlider::wheelEvent(QWheelEvent * e)
{
Q_D(QAbstractSlider);
e->ignore();
- int delta = e->delta();
+ bool vertical = bool(e->angleDelta().y());
+ int delta = vertical ? e->angleDelta().y() : e->angleDelta().x();
if (e->inverted())
delta = -delta;
- if (d->scrollByDelta(e->orientation(), e->modifiers(), delta))
+ if (d->scrollByDelta(vertical ? Qt::Vertical : Qt::Horizontal, e->modifiers(), delta))
e->accept();
}
@@ -815,13 +818,13 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev)
switch (ev->key()) {
#ifdef QT_KEYPAD_NAVIGATION
case Qt::Key_Select:
- if (QApplication::keypadNavigationEnabled())
+ if (QApplicationPrivate::keypadNavigationEnabled())
setEditFocus(!hasEditFocus());
else
ev->ignore();
break;
case Qt::Key_Back:
- if (QApplication::keypadNavigationEnabled() && hasEditFocus()) {
+ if (QApplicationPrivate::keypadNavigationEnabled() && hasEditFocus()) {
setValue(d->origValue);
setEditFocus(false);
} else
@@ -834,7 +837,7 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev)
// In QApplication::KeypadNavigationDirectional, we want to change the slider
// value if there is no left/right navigation possible and if this slider is not
// inside a tab widget.
- if (QApplication::keypadNavigationEnabled()
+ if (QApplicationPrivate::keypadNavigationEnabled()
&& (!hasEditFocus() && QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder
|| d->orientation == Qt::Vertical
|| !hasEditFocus()
@@ -842,7 +845,7 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev)
ev->ignore();
return;
}
- if (QApplication::keypadNavigationEnabled() && d->orientation == Qt::Vertical)
+ if (QApplicationPrivate::keypadNavigationEnabled() && d->orientation == Qt::Vertical)
action = d->invertedControls ? SliderSingleStepSub : SliderSingleStepAdd;
else
#endif
@@ -854,7 +857,7 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev)
case Qt::Key_Right:
#ifdef QT_KEYPAD_NAVIGATION
// Same logic as in Qt::Key_Left
- if (QApplication::keypadNavigationEnabled()
+ if (QApplicationPrivate::keypadNavigationEnabled()
&& (!hasEditFocus() && QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder
|| d->orientation == Qt::Vertical
|| !hasEditFocus()
@@ -862,7 +865,7 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev)
ev->ignore();
return;
}
- if (QApplication::keypadNavigationEnabled() && d->orientation == Qt::Vertical)
+ if (QApplicationPrivate::keypadNavigationEnabled() && d->orientation == Qt::Vertical)
action = d->invertedControls ? SliderSingleStepAdd : SliderSingleStepSub;
else
#endif
@@ -875,7 +878,7 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev)
#ifdef QT_KEYPAD_NAVIGATION
// In QApplication::KeypadNavigationDirectional, we want to change the slider
// value if there is no up/down navigation possible.
- if (QApplication::keypadNavigationEnabled()
+ if (QApplicationPrivate::keypadNavigationEnabled()
&& (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder
|| d->orientation == Qt::Horizontal
|| !hasEditFocus() && QWidgetPrivate::canKeypadNavigate(Qt::Vertical))) {
@@ -888,7 +891,7 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev)
case Qt::Key_Down:
#ifdef QT_KEYPAD_NAVIGATION
// Same logic as in Qt::Key_Up
- if (QApplication::keypadNavigationEnabled()
+ if (QApplicationPrivate::keypadNavigationEnabled()
&& (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder
|| d->orientation == Qt::Horizontal
|| !hasEditFocus() && QWidgetPrivate::canKeypadNavigate(Qt::Vertical))) {
diff --git a/src/widgets/widgets/qabstractspinbox.cpp b/src/widgets/widgets/qabstractspinbox.cpp
index e6e9939a10..f5708788b8 100644
--- a/src/widgets/widgets/qabstractspinbox.cpp
+++ b/src/widgets/widgets/qabstractspinbox.cpp
@@ -39,6 +39,7 @@
#include <qplatformdefs.h>
#include <private/qabstractspinbox_p.h>
+#include <private/qapplication_p.h>
#if QT_CONFIG(datetimeparser)
#include <private/qdatetimeparser_p.h>
#endif
@@ -803,7 +804,7 @@ bool QAbstractSpinBox::event(QEvent *event)
#ifdef QT_KEYPAD_NAVIGATION
case QEvent::EnterEditFocus:
case QEvent::LeaveEditFocus:
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
const bool b = d->edit->event(event);
d->edit->setSelection(d->edit->displayText().size() - d->suffix.size(),0);
if (event->type() == QEvent::LeaveEditFocus)
@@ -1025,7 +1026,7 @@ void QAbstractSpinBox::keyPressEvent(QKeyEvent *event)
case Qt::Key_Up:
case Qt::Key_Down: {
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
// Reserve up/down for nav - use left/right for edit.
if (!hasEditFocus() && (event->key() == Qt::Key_Up
|| event->key() == Qt::Key_Down)) {
@@ -1061,13 +1062,13 @@ void QAbstractSpinBox::keyPressEvent(QKeyEvent *event)
#ifdef QT_KEYPAD_NAVIGATION
case Qt::Key_Left:
case Qt::Key_Right:
- if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) {
+ if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) {
event->ignore();
return;
}
break;
case Qt::Key_Back:
- if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) {
+ if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) {
event->ignore();
return;
}
@@ -1085,7 +1086,7 @@ void QAbstractSpinBox::keyPressEvent(QKeyEvent *event)
#ifdef QT_KEYPAD_NAVIGATION
case Qt::Key_Select:
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
// Toggles between left/right moving cursor and inc/dec.
setEditFocus(!hasEditFocus());
}
@@ -1221,7 +1222,7 @@ void QAbstractSpinBox::focusOutEvent(QFocusEvent *event)
#ifdef QT_KEYPAD_NAVIGATION
// editingFinished() is already emitted on LeaveEditFocus
- if (!QApplication::keypadNavigationEnabled())
+ if (!QApplicationPrivate::keypadNavigationEnabled())
#endif
emit editingFinished();
}
diff --git a/src/widgets/widgets/qcalendarwidget.cpp b/src/widgets/widgets/qcalendarwidget.cpp
index 510b34cb18..78706b1854 100644
--- a/src/widgets/widgets/qcalendarwidget.cpp
+++ b/src/widgets/widgets/qcalendarwidget.cpp
@@ -54,6 +54,7 @@
#include <qspinbox.h>
#include <qmenu.h>
#include <qapplication.h>
+#include <private/qapplication_p.h>
#include <qbasictimer.h>
#include <qstylepainter.h>
@@ -1384,14 +1385,14 @@ void QCalendarView::keyPressEvent(QKeyEvent *event)
{
#ifdef QT_KEYPAD_NAVIGATION
if (event->key() == Qt::Key_Select) {
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
if (!hasEditFocus()) {
setEditFocus(true);
return;
}
}
} else if (event->key() == Qt::Key_Back) {
- if (QApplication::keypadNavigationEnabled() && hasEditFocus()) {
+ if (QApplicationPrivate::keypadNavigationEnabled() && hasEditFocus()) {
if (qobject_cast<QCalendarModel *>(model())) {
emit changeDate(origDate, true); //changes selection back to origDate, but doesn't activate
setEditFocus(false);
@@ -1418,7 +1419,7 @@ void QCalendarView::keyPressEvent(QKeyEvent *event)
#if QT_CONFIG(wheelevent)
void QCalendarView::wheelEvent(QWheelEvent *event)
{
- const int numDegrees = event->delta() / 8;
+ const int numDegrees = event->angleDelta().y() / 8;
const int numSteps = numDegrees / 15;
const QModelIndex index = currentIndex();
QDate currentDate = static_cast<QCalendarModel*>(model())->dateForCell(index.row(), index.column());
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp
index 0b52747b6a..8b54d61e8e 100644
--- a/src/widgets/widgets/qcombobox.cpp
+++ b/src/widgets/widgets/qcombobox.cpp
@@ -223,7 +223,7 @@ void QComboBoxPrivate::_q_completerActivated(const QModelIndex &index)
}
# ifdef QT_KEYPAD_NAVIGATION
- if ( QApplication::keypadNavigationEnabled()
+ if ( QApplicationPrivate::keypadNavigationEnabled()
&& q->isEditable()
&& q->completer()
&& q->completer()->completionMode() == QCompleter::UnfilteredPopupCompletion ) {
@@ -896,11 +896,6 @@ QStyleOptionComboBox QComboBoxPrivateContainer::comboStyleOption() const
\fn void QComboBox::currentIndexChanged(const QString &text)
\since 4.1
- \obsolete
-
- Use currentTextChanged(const QString &) or currentIndexChanged(int)
- instead.
-
This signal is sent whenever the currentIndex in the combobox
changes either through user interaction or programmatically. The
item's \a text is passed.
@@ -1539,7 +1534,7 @@ void QComboBox::setAutoCompletion(bool enable)
Q_D(QComboBox);
#ifdef QT_KEYPAD_NAVIGATION
- if (Q_UNLIKELY(QApplication::keypadNavigationEnabled() && !enable && isEditable()))
+ if (Q_UNLIKELY(QApplicationPrivate::keypadNavigationEnabled() && !enable && isEditable()))
qWarning("QComboBox::setAutoCompletion: auto completion is mandatory when combo box editable");
#endif
@@ -1886,7 +1881,7 @@ void QComboBox::setLineEdit(QLineEdit *edit)
setAutoCompletion(d->autoCompletion);
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
// Editable combo boxes will have a completer that is set to UnfilteredPopupCompletion.
// This means that when the user enters edit mode they are immediately presented with a
// list of possible completions.
@@ -2628,7 +2623,7 @@ bool QComboBoxPrivate::showNativePopup()
/*!
Displays the list of items in the combobox. If the list is empty
- then the no items will be shown.
+ then no items will be shown.
If you reimplement this function to show a custom pop-up, make
sure you call hidePopup() to reset the internal state.
@@ -2658,7 +2653,7 @@ void QComboBox::showPopup()
#ifdef QT_KEYPAD_NAVIGATION
#if QT_CONFIG(completer)
- if (QApplication::keypadNavigationEnabled() && d->completer) {
+ if (QApplicationPrivate::keypadNavigationEnabled() && d->completer) {
// editable combo box is line edit plus completer
setEditFocus(true);
d->completer->complete(); // show popup
@@ -2719,15 +2714,14 @@ void QComboBox::showPopup()
int heightMargin = container->topMargin() + container->bottomMargin();
// add the frame of the container
- int marginTop, marginBottom;
- container->getContentsMargins(0, &marginTop, 0, &marginBottom);
- heightMargin += marginTop + marginBottom;
+ const QMargins cm = container->contentsMargins();
+ heightMargin += cm.top() + cm.bottom();
//add the frame of the view
- view()->getContentsMargins(0, &marginTop, 0, &marginBottom);
- marginTop += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->top;
- marginBottom += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->bottom;
- heightMargin += marginTop + marginBottom;
+ const QMargins vm = view()->contentsMargins();
+ heightMargin += vm.top() + vm.bottom();
+ heightMargin += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->top;
+ heightMargin += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->bottom;
listRect.setHeight(listRect.height() + heightMargin);
}
@@ -2864,7 +2858,7 @@ void QComboBox::showPopup()
container->update();
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled())
+ if (QApplicationPrivate::keypadNavigationEnabled())
view()->setEditFocus(true);
#endif
if (startTimer) {
@@ -2936,7 +2930,7 @@ void QComboBox::hidePopup()
d->container->hide();
}
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled() && isEditable() && hasFocus())
+ if (QApplicationPrivate::keypadNavigationEnabled() && isEditable() && hasFocus())
setEditFocus(true);
#endif
d->_q_resetButton();
@@ -3195,7 +3189,7 @@ void QComboBoxPrivate::showPopupFromMouseEvent(QMouseEvent *e)
}
} else {
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled() && sc == QStyle::SC_ComboBoxEditField && lineEdit) {
+ if (QApplicationPrivate::keypadNavigationEnabled() && sc == QStyle::SC_ComboBoxEditField && lineEdit) {
lineEdit->event(e); //so lineedit can move cursor, etc
return;
}
@@ -3244,7 +3238,7 @@ void QComboBox::keyPressEvent(QKeyEvent *e)
Q_FALLTHROUGH();
case Qt::Key_PageUp:
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled())
+ if (QApplicationPrivate::keypadNavigationEnabled())
e->ignore();
else
#endif
@@ -3259,7 +3253,7 @@ void QComboBox::keyPressEvent(QKeyEvent *e)
Q_FALLTHROUGH();
case Qt::Key_PageDown:
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled())
+ if (QApplicationPrivate::keypadNavigationEnabled())
e->ignore();
else
#endif
@@ -3293,7 +3287,7 @@ void QComboBox::keyPressEvent(QKeyEvent *e)
break;
#ifdef QT_KEYPAD_NAVIGATION
case Qt::Key_Select:
- if (QApplication::keypadNavigationEnabled()
+ if (QApplicationPrivate::keypadNavigationEnabled()
&& (!hasEditFocus() || !d->lineEdit)) {
showPopup();
return;
@@ -3301,11 +3295,11 @@ void QComboBox::keyPressEvent(QKeyEvent *e)
break;
case Qt::Key_Left:
case Qt::Key_Right:
- if (QApplication::keypadNavigationEnabled() && !hasEditFocus())
+ if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus())
e->ignore();
break;
case Qt::Key_Back:
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
if (!hasEditFocus() || !d->lineEdit)
e->ignore();
} else {
@@ -3383,12 +3377,13 @@ void QComboBox::wheelEvent(QWheelEvent *e)
!d->viewContainer()->isVisible()) {
const int rowCount = count();
int newIndex = currentIndex();
+ int delta = e->angleDelta().y();
- if (e->delta() > 0) {
+ if (delta > 0) {
newIndex--;
while ((newIndex >= 0) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled))
newIndex--;
- } else if (e->delta() < 0) {
+ } else if (delta < 0) {
newIndex++;
while (newIndex < rowCount && !(d->model->index(newIndex, d->modelColumn, d->root).flags() & Qt::ItemIsEnabled))
newIndex++;
diff --git a/src/widgets/widgets/qcombobox.h b/src/widgets/widgets/qcombobox.h
index 3b48b151a1..286772c091 100644
--- a/src/widgets/widgets/qcombobox.h
+++ b/src/widgets/widgets/qcombobox.h
@@ -227,11 +227,8 @@ Q_SIGNALS:
void highlighted(int index);
void textHighlighted(const QString &);
void currentIndexChanged(int index);
- void currentTextChanged(const QString &);
-#if QT_DEPRECATED_SINCE(5, 13)
- QT_DEPRECATED_VERSION_X(5, 13, "Use currentTextChanged() instead")
void currentIndexChanged(const QString &);
-#endif
+ void currentTextChanged(const QString &);
#if QT_DEPRECATED_SINCE(5, 15)
QT_DEPRECATED_VERSION_X(5, 15, "Use textActivated() instead")
void activated(const QString &);
diff --git a/src/widgets/widgets/qcommandlinkbutton.cpp b/src/widgets/widgets/qcommandlinkbutton.cpp
index 68dfefb3b7..2b9258fd91 100644
--- a/src/widgets/widgets/qcommandlinkbutton.cpp
+++ b/src/widgets/widgets/qcommandlinkbutton.cpp
@@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE
\ingroup basicwidgets
\inmodule QtWidgets
- The command link is a new control that was introduced by Windows Vista. It's
+ The command link is a new control that was introduced by Windows Vista. Its
intended use is similar to that of a radio button in that it is used to choose
between a set of mutually exclusive options. Command link buttons should not
be used by themselves but rather as an alternative to radio buttons in
diff --git a/src/widgets/widgets/qdatetimeedit.cpp b/src/widgets/widgets/qdatetimeedit.cpp
index 45c72e24d4..3c92d4be0e 100644
--- a/src/widgets/widgets/qdatetimeedit.cpp
+++ b/src/widgets/widgets/qdatetimeedit.cpp
@@ -37,6 +37,7 @@
**
****************************************************************************/
+#include <private/qapplication_p.h>
#include <private/qdatetimeedit_p.h>
#include <qabstractspinbox.h>
#include <qapplication.h>
@@ -642,7 +643,7 @@ QDateTimeEdit::Section QDateTimeEdit::currentSection() const
{
Q_D(const QDateTimeEdit);
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled() && d->focusOnButton)
+ if (QApplicationPrivate::keypadNavigationEnabled() && d->focusOnButton)
return NoSection;
#endif
return QDateTimeEditPrivate::convertToPublic(d->sectionType(d->currentSectionIndex));
@@ -1055,7 +1056,7 @@ void QDateTimeEdit::keyPressEvent(QKeyEvent *event)
switch (event->key()) {
#ifdef QT_KEYPAD_NAVIGATION
case Qt::Key_NumberSign: //shortcut to popup calendar
- if (QApplication::keypadNavigationEnabled() && d->calendarPopupEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled() && d->calendarPopupEnabled()) {
d->initCalendarPopup();
d->positionCalendarPopup();
d->monthCalendar->show();
@@ -1063,7 +1064,7 @@ void QDateTimeEdit::keyPressEvent(QKeyEvent *event)
}
break;
case Qt::Key_Select:
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
if (hasEditFocus()) {
if (d->focusOnButton) {
d->initCalendarPopup();
@@ -1095,7 +1096,7 @@ void QDateTimeEdit::keyPressEvent(QKeyEvent *event)
return;
default:
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled() && !hasEditFocus()
+ if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()
&& !event->text().isEmpty() && event->text().at(0).isLetterOrNumber()) {
setEditFocus(true);
@@ -1117,8 +1118,8 @@ void QDateTimeEdit::keyPressEvent(QKeyEvent *event)
if (event->key() == Qt::Key_Left || event->key() == Qt::Key_Right) {
if (
#ifdef QT_KEYPAD_NAVIGATION
- QApplication::keypadNavigationEnabled() && !hasEditFocus()
- || !QApplication::keypadNavigationEnabled() &&
+ QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()
+ || !QApplicationPrivate::keypadNavigationEnabled() &&
#endif
!(event->modifiers() & Qt::ControlModifier)) {
select = false;
@@ -1127,7 +1128,7 @@ void QDateTimeEdit::keyPressEvent(QKeyEvent *event)
#if 0 // Used to be included in Qt4 for Q_WS_MAC
else
#ifdef QT_KEYPAD_NAVIGATION
- if (!QApplication::keypadNavigationEnabled())
+ if (!QApplicationPrivate::keypadNavigationEnabled())
#endif
{
select = (event->modifiers() & Qt::ShiftModifier);
@@ -1147,7 +1148,7 @@ void QDateTimeEdit::keyPressEvent(QKeyEvent *event)
&& (event->key() != Qt::Key_Tab || !(event->modifiers() & Qt::ShiftModifier));
#ifdef QT_KEYPAD_NAVIGATION
int newSection = d->nextPrevSection(d->currentSectionIndex, forward);
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
if (d->focusOnButton) {
newSection = forward ? 0 : d->sectionNodes.size() - 1;
d->focusOnButton = false;
@@ -1290,7 +1291,7 @@ void QDateTimeEdit::stepBy(int steps)
Q_D(QDateTimeEdit);
#ifdef QT_KEYPAD_NAVIGATION
// with keypad navigation and not editFocus, left right change the date/time by a fixed amount.
- if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) {
+ if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) {
// if date based, shift by day. else shift by 15min
if (d->sections & DateSections_Mask) {
setDateTime(dateTime().addDays(steps));
@@ -1417,7 +1418,7 @@ QDateTimeEdit::StepEnabled QDateTimeEdit::stepEnabled() const
QAbstractSpinBox::StepEnabled ret = 0;
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) {
+ if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) {
if (d->wrapping)
return StepEnabled(StepUpEnabled | StepDownEnabled);
// 3 cases. date, time, datetime. each case look
@@ -1702,7 +1703,7 @@ void QDateTimeEditPrivate::updateEdit()
if (!specialValue()
#ifdef QT_KEYPAD_NAVIGATION
- && !(QApplication::keypadNavigationEnabled() && !edit->hasEditFocus())
+ && !(QApplicationPrivate::keypadNavigationEnabled() && !edit->hasEditFocus())
#endif
) {
int cursor = sectionPos(currentSectionIndex);
@@ -1731,7 +1732,7 @@ void QDateTimeEditPrivate::setSelected(int sectionIndex, bool forward)
{
if (specialValue()
#ifdef QT_KEYPAD_NAVIGATION
- || (QApplication::keypadNavigationEnabled() && !edit->hasEditFocus())
+ || (QApplicationPrivate::keypadNavigationEnabled() && !edit->hasEditFocus())
#endif
) {
edit->selectAll();
@@ -2426,7 +2427,7 @@ void QDateTimeEditPrivate::init(const QVariant &var)
break;
}
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled())
+ if (QApplicationPrivate::keypadNavigationEnabled())
q->setCalendarPopup(true);
#endif
q->setInputMethodHints(Qt::ImhPreferNumbers);
@@ -2602,7 +2603,7 @@ QCalendarWidget *QCalendarPopup::verifyCalendarInstance()
QCalendarWidget *cw = new QCalendarWidget(this);
cw->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled())
+ if (QApplicationPrivate::keypadNavigationEnabled())
cw->setHorizontalHeaderFormat(QCalendarWidget::SingleLetterDayNames);
#endif
setCalendarWidget(cw);
diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp
index 68e3de05bc..7f482a6a4e 100644
--- a/src/widgets/widgets/qlineedit.cpp
+++ b/src/widgets/widgets/qlineedit.cpp
@@ -293,7 +293,7 @@ QLineEdit::~QLineEdit()
/*!
\property QLineEdit::text
- \brief the line edit's text
+ \brief the line edit's text.
Setting this property clears the selection, clears the undo/redo
history, moves the cursor to the end of the line and resets the
@@ -322,7 +322,7 @@ void QLineEdit::setText(const QString& text)
\since 4.7
\property QLineEdit::placeholderText
- \brief the line edit's placeholder text
+ \brief the line edit's placeholder text.
Setting this property makes the line edit display a grayed-out
placeholder text as long as the line edit is empty.
@@ -354,7 +354,7 @@ void QLineEdit::setPlaceholderText(const QString& placeholderText)
/*!
\property QLineEdit::displayText
- \brief the displayed text
+ \brief the displayed text.
If \l echoMode is \l Normal this returns the same as text(); if
\l EchoMode is \l Password or \l PasswordEchoOnEdit it returns a string of
@@ -375,7 +375,7 @@ QString QLineEdit::displayText() const
/*!
\property QLineEdit::maxLength
- \brief the maximum permitted length of the text
+ \brief the maximum permitted length of the text.
If the text is too long, it is truncated at the limit.
@@ -405,7 +405,7 @@ void QLineEdit::setMaxLength(int maxLength)
/*!
\property QLineEdit::frame
- \brief whether the line edit draws itself with a frame
+ \brief whether the line edit draws itself with a frame.
If enabled (the default) the line edit draws itself inside a
frame, otherwise the line edit draws itself without any frame.
@@ -544,7 +544,7 @@ void QLineEdit::setFrame(bool enable)
/*!
\property QLineEdit::echoMode
- \brief the line edit's echo mode
+ \brief the line edit's echo mode.
The echo mode determines how the text entered in the line edit is
displayed (or echoed) to the user.
@@ -684,11 +684,12 @@ QSize QLineEdit::sizeHint() const
ensurePolished();
QFontMetrics fm(font());
const int iconSize = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this);
- int h = qMax(fm.height(), iconSize - 2) + 2 * QLineEditPrivate::verticalMargin
- + d->topTextMargin + d->bottomTextMargin
+ const QMargins tm = d->effectiveTextMargins();
+ int h = qMax(fm.height(), qMax(14, iconSize - 2)) + 2 * QLineEditPrivate::verticalMargin
+ + tm.top() + tm.bottom()
+ d->topmargin + d->bottommargin;
int w = fm.horizontalAdvance(QLatin1Char('x')) * 17 + 2 * QLineEditPrivate::horizontalMargin
- + d->effectiveLeftTextMargin() + d->effectiveRightTextMargin()
+ + tm.left() + tm.right()
+ d->leftmargin + d->rightmargin; // "some"
QStyleOptionFrame opt;
initStyleOption(&opt);
@@ -708,11 +709,12 @@ QSize QLineEdit::minimumSizeHint() const
Q_D(const QLineEdit);
ensurePolished();
QFontMetrics fm = fontMetrics();
+ const QMargins tm = d->effectiveTextMargins();
int h = fm.height() + qMax(2 * QLineEditPrivate::verticalMargin, fm.leading())
- + d->topTextMargin + d->bottomTextMargin
+ + tm.top() + tm.bottom()
+ d->topmargin + d->bottommargin;
int w = fm.maxWidth()
- + d->effectiveLeftTextMargin() + d->effectiveRightTextMargin()
+ + tm.left() + tm.right()
+ d->leftmargin + d->rightmargin;
QStyleOptionFrame opt;
initStyleOption(&opt);
@@ -723,7 +725,7 @@ QSize QLineEdit::minimumSizeHint() const
/*!
\property QLineEdit::cursorPosition
- \brief the current cursor position for this line edit
+ \brief the current cursor position for this line edit.
Setting the cursor position causes a repaint when appropriate.
@@ -756,7 +758,7 @@ int QLineEdit::cursorPositionAt(const QPoint &pos)
/*!
\property QLineEdit::alignment
- \brief the alignment of the line edit
+ \brief the alignment of the line edit.
Both horizontal and vertical alignment is allowed here, Qt::AlignJustify
will map to Qt::AlignLeft.
@@ -894,7 +896,7 @@ void QLineEdit::end(bool mark)
/*!
\property QLineEdit::modified
- \brief whether the line edit's contents has been modified by the user
+ \brief whether the line edit's contents has been modified by the user.
The modified flag is never read by QLineEdit; it has a default value
of false and is changed to true whenever the user changes the line
@@ -924,7 +926,7 @@ void QLineEdit::setModified(bool modified)
/*!
\property QLineEdit::hasSelectedText
- \brief whether there is any text selected
+ \brief whether there is any text selected.
hasSelectedText() returns \c true if some or all of the text has been
selected by the user; otherwise returns \c false.
@@ -943,7 +945,7 @@ bool QLineEdit::hasSelectedText() const
/*!
\property QLineEdit::selectedText
- \brief the selected text
+ \brief the selected text.
If there is no selected text this property's value is
an empty string.
@@ -1030,7 +1032,7 @@ void QLineEdit::setSelection(int start, int length)
/*!
\property QLineEdit::undoAvailable
- \brief whether undo is available
+ \brief whether undo is available.
Undo becomes available once the user has modified the text in the line edit.
@@ -1045,7 +1047,7 @@ bool QLineEdit::isUndoAvailable() const
/*!
\property QLineEdit::redoAvailable
- \brief whether redo is available
+ \brief whether redo is available.
Redo becomes available once the user has performed one or more undo operations
on text in the line edit.
@@ -1062,7 +1064,7 @@ bool QLineEdit::isRedoAvailable() const
/*!
\property QLineEdit::dragEnabled
\brief whether the lineedit starts a drag if the user presses and
- moves the mouse on some selected text
+ moves the mouse on some selected text.
Dragging is disabled by default.
*/
@@ -1081,7 +1083,7 @@ void QLineEdit::setDragEnabled(bool b)
/*!
\property QLineEdit::cursorMoveStyle
- \brief the movement style of cursor in this line edit
+ \brief the movement style of cursor in this line edit.
\since 4.8
When this property is set to Qt::VisualMoveStyle, the line edit will use visual
@@ -1127,17 +1129,11 @@ bool QLineEdit::hasAcceptableInput() const
sizes \a left, \a top, \a right, and \a bottom.
\since 4.5
- See also getTextMargins().
+ See also textMargins().
*/
void QLineEdit::setTextMargins(int left, int top, int right, int bottom)
{
- Q_D(QLineEdit);
- d->leftTextMargin = left;
- d->topTextMargin = top;
- d->rightTextMargin = right;
- d->bottomTextMargin = bottom;
- updateGeometry();
- update();
+ setTextMargins({left, top, right, bottom});
}
/*!
@@ -1148,10 +1144,17 @@ void QLineEdit::setTextMargins(int left, int top, int right, int bottom)
*/
void QLineEdit::setTextMargins(const QMargins &margins)
{
- setTextMargins(margins.left(), margins.top(), margins.right(), margins.bottom());
+ Q_D(QLineEdit);
+ d->textMargins = margins;
+ updateGeometry();
+ update();
}
+#if QT_DEPRECATED_SINCE(5, 14)
/*!
+ \obsolete
+ Use textMargins()
+
Returns the widget's text margins for \a left, \a top, \a right, and \a bottom.
\since 4.5
@@ -1159,16 +1162,17 @@ void QLineEdit::setTextMargins(const QMargins &margins)
*/
void QLineEdit::getTextMargins(int *left, int *top, int *right, int *bottom) const
{
- Q_D(const QLineEdit);
+ QMargins m = textMargins();
if (left)
- *left = d->leftTextMargin;
+ *left = m.left();
if (top)
- *top = d->topTextMargin;
+ *top = m.top();
if (right)
- *right = d->rightTextMargin;
+ *right = m.right();
if (bottom)
- *bottom = d->bottomTextMargin;
+ *bottom = m.bottom();
}
+#endif
/*!
\since 4.6
@@ -1179,12 +1183,12 @@ void QLineEdit::getTextMargins(int *left, int *top, int *right, int *bottom) con
QMargins QLineEdit::textMargins() const
{
Q_D(const QLineEdit);
- return QMargins(d->leftTextMargin, d->topTextMargin, d->rightTextMargin, d->bottomTextMargin);
+ return d->textMargins;
}
/*!
\property QLineEdit::inputMask
- \brief The validation input mask
+ \brief The validation input mask.
If no mask is set, inputMask() returns an empty string.
@@ -1481,7 +1485,7 @@ bool QLineEdit::event(QEvent * e)
d->initMouseYThreshold();
}
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
if (e->type() == QEvent::EnterEditFocus) {
end(false);
d->setCursorVisible(true);
@@ -1513,7 +1517,7 @@ void QLineEdit::mousePressEvent(QMouseEvent* e)
if (e->button() == Qt::RightButton)
return;
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) {
+ if (QApplication::QApplicationPrivate() && !hasEditFocus()) {
setEditFocus(true);
// Get the completion list to pop up.
if (d->control->completer())
@@ -1722,7 +1726,7 @@ void QLineEdit::keyPressEvent(QKeyEvent *event)
bool select = false;
switch (event->key()) {
case Qt::Key_Select:
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
if (hasEditFocus()) {
setEditFocus(false);
if (d->control->completer() && d->control->completer()->popup()->isVisible())
@@ -1733,13 +1737,13 @@ void QLineEdit::keyPressEvent(QKeyEvent *event)
break;
case Qt::Key_Back:
case Qt::Key_No:
- if (!QApplication::keypadNavigationEnabled() || !hasEditFocus()) {
+ if (!QApplicationPrivate::keypadNavigationEnabled() || !hasEditFocus()) {
event->ignore();
return;
}
break;
default:
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
if (!hasEditFocus() && !(event->modifiers() & Qt::ControlModifier)) {
if (!event->text().isEmpty() && event->text().at(0).isPrint()
&& !isReadOnly())
@@ -1754,7 +1758,7 @@ void QLineEdit::keyPressEvent(QKeyEvent *event)
- if (QApplication::keypadNavigationEnabled() && !select && !hasEditFocus()) {
+ if (QApplicationPrivate::keypadNavigationEnabled() && !select && !hasEditFocus()) {
setEditFocus(true);
if (event->key() == Qt::Key_Select)
return; // Just start. No action.
@@ -1801,7 +1805,7 @@ void QLineEdit::inputMethodEvent(QInputMethodEvent *e)
// Focus in if currently in navigation focus on the widget
// Only focus in on preedits, to allow input methods to
// commit text as they focus out without interfering with focus
- if (QApplication::keypadNavigationEnabled()
+ if (QApplicationPrivate::keypadNavigationEnabled()
&& hasFocus() && !hasEditFocus()
&& !e->preeditString().isEmpty())
setEditFocus(true);
@@ -1874,7 +1878,7 @@ void QLineEdit::focusInEvent(QFocusEvent *e)
d->clickCausedFocus = 1;
}
#ifdef QT_KEYPAD_NAVIGATION
- if (!QApplication::keypadNavigationEnabled() || (hasEditFocus() && ( e->reason() == Qt::PopupFocusReason))) {
+ if (!QApplicationPrivate::keypadNavigationEnabled() || (hasEditFocus() && ( e->reason() == Qt::PopupFocusReason))) {
#endif
d->control->setBlinkingCursorEnabled(true);
QStyleOptionFrame opt;
@@ -1918,7 +1922,7 @@ void QLineEdit::focusOutEvent(QFocusEvent *e)
d->control->setBlinkingCursorEnabled(false);
#ifdef QT_KEYPAD_NAVIGATION
// editingFinished() is already emitted on LeaveEditFocus
- if (!QApplication::keypadNavigationEnabled())
+ if (!QApplicationPrivate::keypadNavigationEnabled())
#endif
if (reason != Qt::PopupFocusReason
|| !(QApplication::activePopupWidget() && QApplication::activePopupWidget()->parentWidget() == this)) {
@@ -1950,10 +1954,7 @@ void QLineEdit::paintEvent(QPaintEvent *)
initStyleOption(&panel);
style()->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, &p, this);
QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this);
- r.setX(r.x() + d->effectiveLeftTextMargin());
- r.setY(r.y() + d->topTextMargin);
- r.setRight(r.right() - d->effectiveRightTextMargin());
- r.setBottom(r.bottom() - d->bottomTextMargin);
+ r = r.marginsRemoved(d->effectiveTextMargins());
p.setClipRect(r);
QFontMetrics fm = fontMetrics();
@@ -2041,7 +2042,7 @@ void QLineEdit::paintEvent(QPaintEvent *)
int flags = QWidgetLineControl::DrawText;
#ifdef QT_KEYPAD_NAVIGATION
- if (!QApplication::keypadNavigationEnabled() || hasEditFocus())
+ if (!QApplicationPrivate::keypadNavigationEnabled() || hasEditFocus())
#endif
if (d->control->hasSelectedText() || (d->cursorVisible && !d->control->inputMask().isEmpty() && !d->control->isReadOnly())){
flags |= QWidgetLineControl::DrawSelections;
diff --git a/src/widgets/widgets/qlineedit.h b/src/widgets/widgets/qlineedit.h
index de82927f74..1cf1f24449 100644
--- a/src/widgets/widgets/qlineedit.h
+++ b/src/widgets/widgets/qlineedit.h
@@ -172,7 +172,10 @@ public:
void setTextMargins(int left, int top, int right, int bottom);
void setTextMargins(const QMargins &margins);
+#if QT_DEPRECATED_SINCE(5, 14)
+ QT_DEPRECATED_X("use textMargins()")
void getTextMargins(int *left, int *top, int *right, int *bottom) const;
+#endif
QMargins textMargins() const;
#if QT_CONFIG(action)
diff --git a/src/widgets/widgets/qlineedit_p.cpp b/src/widgets/widgets/qlineedit_p.cpp
index 7d580e50a5..d2b5f87906 100644
--- a/src/widgets/widgets/qlineedit_p.cpp
+++ b/src/widgets/widgets/qlineedit_p.cpp
@@ -254,10 +254,7 @@ QRect QLineEditPrivate::adjustedContentsRect() const
QStyleOptionFrame opt;
q->initStyleOption(&opt);
QRect r = q->style()->subElementRect(QStyle::SE_LineEditContents, &opt, q);
- r.setX(r.x() + effectiveLeftTextMargin());
- r.setY(r.y() + topTextMargin);
- r.setRight(r.right() - effectiveRightTextMargin());
- r.setBottom(r.bottom() - bottomTextMargin);
+ r = r.marginsRemoved(effectiveTextMargins());
return r;
}
@@ -672,14 +669,12 @@ static int effectiveTextMargin(int defaultMargin, const QLineEditPrivate::SideWi
return e.widget->isVisibleTo(e.widget->parentWidget()); }));
}
-int QLineEditPrivate::effectiveLeftTextMargin() const
+QMargins QLineEditPrivate::effectiveTextMargins() const
{
- return effectiveTextMargin(leftTextMargin, leftSideWidgetList(), sideWidgetParameters());
-}
-
-int QLineEditPrivate::effectiveRightTextMargin() const
-{
- return effectiveTextMargin(rightTextMargin, rightSideWidgetList(), sideWidgetParameters());
+ return {effectiveTextMargin(textMargins.left(), leftSideWidgetList(), sideWidgetParameters()),
+ textMargins.top(),
+ effectiveTextMargin(textMargins.right(), rightSideWidgetList(), sideWidgetParameters()),
+ textMargins.bottom()};
}
diff --git a/src/widgets/widgets/qlineedit_p.h b/src/widgets/widgets/qlineedit_p.h
index 3f98aab901..a11fea6bbe 100644
--- a/src/widgets/widgets/qlineedit_p.h
+++ b/src/widgets/widgets/qlineedit_p.h
@@ -67,6 +67,7 @@
#endif
#include "QtCore/qpointer.h"
#include "QtCore/qmimedata.h"
+#include <QtCore/qmargins.h>
#include "private/qwidgetlinecontrol_p.h"
@@ -153,7 +154,7 @@ public:
: control(0), frame(1), contextMenuEnabled(1), cursorVisible(0),
dragEnabled(0), clickCausedFocus(0), edited(0), hscroll(0), vscroll(0),
alignment(Qt::AlignLeading | Qt::AlignVCenter),
- leftTextMargin(0), topTextMargin(0), rightTextMargin(0), bottomTextMargin(0),
+ textMargins{0, 0, 0, 0},
lastTextSize(0), mouseYThreshold(0)
{
}
@@ -233,10 +234,7 @@ public:
void _q_textChanged(const QString &);
void _q_clearButtonClicked();
- int leftTextMargin; // use effectiveLeftTextMargin() in case of icon.
- int topTextMargin;
- int rightTextMargin; // use effectiveRightTextMargin() in case of icon.
- int bottomTextMargin;
+ QMargins textMargins; // use effectiveTextMargins() in case of icon.
QString placeholderText;
@@ -252,8 +250,7 @@ public:
inline const SideWidgetEntryList &rightSideWidgetList() const
{ return q_func()->layoutDirection() == Qt::LeftToRight ? trailingSideWidgets : leadingSideWidgets; }
- int effectiveLeftTextMargin() const;
- int effectiveRightTextMargin() const;
+ QMargins effectiveTextMargins() const;
private:
struct SideWidgetLocation {
diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp
index 72653b377d..e38490dabd 100644
--- a/src/widgets/widgets/qmenu.cpp
+++ b/src/widgets/widgets/qmenu.cpp
@@ -142,9 +142,7 @@ public:
#endif
if (style() != p->style())
setStyle(p->style());
- int leftMargin, topMargin, rightMargin, bottomMargin;
- p->getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin);
- setContentsMargins(leftMargin, topMargin, rightMargin, bottomMargin);
+ setContentsMargins(p->contentsMargins());
setLayoutDirection(p->layoutDirection());
//QObject::connect(this, SIGNAL(triggered(QAction*)), this, SLOT(onTrigger(QAction*)));
//QObject::connect(this, SIGNAL(hovered(QAction*)), this, SLOT(onHovered(QAction*)));
@@ -200,7 +198,7 @@ void QMenuPrivate::init()
q->setAttribute(Qt::WA_X11NetWmWindowTypePopupMenu);
defaultMenuAction = menuAction = new QAction(q);
menuAction->d_func()->menu = q;
- QObject::connect(menuAction, &QAction::changed, [=] {
+ QObject::connect(menuAction, &QAction::changed, [this] {
if (!tornPopup.isNull())
tornPopup->updateWindowTitle();
});
@@ -2392,7 +2390,7 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
}
#ifdef QT_KEYPAD_NAVIGATION
- if (!atAction && QApplication::keypadNavigationEnabled()) {
+ if (!atAction && QApplicationPrivate::keypadNavigationEnabled()) {
// Try to have one item activated
if (d->defaultAction && d->defaultAction->isEnabled()) {
atAction = d->defaultAction;
@@ -2847,8 +2845,8 @@ void QMenu::paintEvent(QPaintEvent *e)
void QMenu::wheelEvent(QWheelEvent *e)
{
Q_D(QMenu);
- if (d->scroll && rect().contains(e->pos()))
- d->scrollMenu(e->delta() > 0 ?
+ if (d->scroll && rect().contains(e->position().toPoint()))
+ d->scrollMenu(e->angleDelta().y() > 0 ?
QMenuPrivate::QMenuScroller::ScrollUp : QMenuPrivate::QMenuScroller::ScrollDown);
}
#endif
diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp
index 397304ec44..8843797430 100644
--- a/src/widgets/widgets/qplaintextedit.cpp
+++ b/src/widgets/widgets/qplaintextedit.cpp
@@ -54,6 +54,7 @@
#endif
#include <qstyle.h>
#include <qtimer.h>
+#include "private/qapplication_p.h"
#include "private/qtextdocumentlayout_p.h"
#include "private/qabstracttextdocumentlayout_p.h"
#include "qtextdocument.h"
@@ -1573,7 +1574,7 @@ bool QPlainTextEdit::event(QEvent *e)
}
#ifdef QT_KEYPAD_NAVIGATION
else if (e->type() == QEvent::EnterEditFocus || e->type() == QEvent::LeaveEditFocus) {
- if (QApplication::keypadNavigationEnabled())
+ if (QApplicationPrivate::keypadNavigationEnabled())
d->sendControlEvent(e);
}
#endif
@@ -1691,7 +1692,7 @@ void QPlainTextEdit::keyPressEvent(QKeyEvent *e)
#ifdef QT_KEYPAD_NAVIGATION
switch (e->key()) {
case Qt::Key_Select:
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
if (!(d->control->textInteractionFlags() & Qt::LinksAccessibleByKeyboard))
setEditFocus(!hasEditFocus());
else {
@@ -1709,14 +1710,14 @@ void QPlainTextEdit::keyPressEvent(QKeyEvent *e)
break;
case Qt::Key_Back:
case Qt::Key_No:
- if (!QApplication::keypadNavigationEnabled()
- || (QApplication::keypadNavigationEnabled() && !hasEditFocus())) {
+ if (!QApplicationPrivate::keypadNavigationEnabled()
+ || (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus())) {
e->ignore();
return;
}
break;
default:
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
if (!hasEditFocus() && !(e->modifiers() & Qt::ControlModifier)) {
if (e->text()[0].isPrint()) {
setEditFocus(true);
@@ -1792,7 +1793,7 @@ void QPlainTextEdit::keyPressEvent(QKeyEvent *e)
switch (e->key()) {
case Qt::Key_Up:
case Qt::Key_Down:
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
// Cursor position didn't change, so we want to leave
// these keys to change focus.
e->ignore();
@@ -1801,7 +1802,7 @@ void QPlainTextEdit::keyPressEvent(QKeyEvent *e)
break;
case Qt::Key_Left:
case Qt::Key_Right:
- if (QApplication::keypadNavigationEnabled()
+ if (QApplicationPrivate::keypadNavigationEnabled()
&& QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) {
// Same as for Key_Up and Key_Down.
e->ignore();
@@ -1810,7 +1811,7 @@ void QPlainTextEdit::keyPressEvent(QKeyEvent *e)
break;
case Qt::Key_Back:
if (!e->isAutoRepeat()) {
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
if (document()->isEmpty()) {
setEditFocus(false);
e->accept();
@@ -1836,7 +1837,7 @@ void QPlainTextEdit::keyReleaseEvent(QKeyEvent *e)
{
#ifdef QT_KEYPAD_NAVIGATION
Q_D(QPlainTextEdit);
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
if (!e->isAutoRepeat() && e->key() == Qt::Key_Back
&& d->deleteAllTimer.isActive()) {
d->deleteAllTimer.stop();
@@ -2080,7 +2081,7 @@ void QPlainTextEdit::mousePressEvent(QMouseEvent *e)
{
Q_D(QPlainTextEdit);
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled() && !hasEditFocus())
+ if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus())
setEditFocus(true);
#endif
d->sendControlEvent(e);
@@ -2212,7 +2213,7 @@ void QPlainTextEdit::inputMethodEvent(QInputMethodEvent *e)
Q_D(QPlainTextEdit);
#ifdef QT_KEYPAD_NAVIGATION
if (d->control->textInteractionFlags() & Qt::TextEditable
- && QApplication::keypadNavigationEnabled()
+ && QApplicationPrivate::keypadNavigationEnabled()
&& !hasEditFocus()) {
setEditFocus(true);
selectAll(); // so text is replaced rather than appended to
diff --git a/src/widgets/widgets/qscrollarea.cpp b/src/widgets/widgets/qscrollarea.cpp
index 9994344d79..68aa545082 100644
--- a/src/widgets/widgets/qscrollarea.cpp
+++ b/src/widgets/widgets/qscrollarea.cpp
@@ -46,6 +46,7 @@
#include "qapplication.h"
#include "qvariant.h"
#include "qdebug.h"
+#include "private/qapplication_p.h"
#include "private/qlayoutengine_p.h"
QT_BEGIN_NAMESPACE
@@ -300,7 +301,7 @@ bool QScrollArea::event(QEvent *e)
d->updateScrollBars();
}
#ifdef QT_KEYPAD_NAVIGATION
- else if (QApplication::keypadNavigationEnabled()) {
+ else if (QApplicationPrivate::keypadNavigationEnabled()) {
if (e->type() == QEvent::Show)
QApplication::instance()->installEventFilter(this);
else if (e->type() == QEvent::Hide)
@@ -319,7 +320,7 @@ bool QScrollArea::eventFilter(QObject *o, QEvent *e)
Q_D(QScrollArea);
#ifdef QT_KEYPAD_NAVIGATION
if (d->widget && o != d->widget && e->type() == QEvent::FocusIn
- && QApplication::keypadNavigationEnabled()) {
+ && QApplicationPrivate::keypadNavigationEnabled()) {
if (o->isWidgetType())
ensureWidgetVisible(static_cast<QWidget *>(o));
}
diff --git a/src/widgets/widgets/qscrollbar.cpp b/src/widgets/widgets/qscrollbar.cpp
index b4168268a0..08d771a27a 100644
--- a/src/widgets/widgets/qscrollbar.cpp
+++ b/src/widgets/widgets/qscrollbar.cpp
@@ -497,16 +497,14 @@ bool QScrollBar::event(QEvent *event)
void QScrollBar::wheelEvent(QWheelEvent *event)
{
event->ignore();
- int delta = event->delta();
// scrollbar is a special case - in vertical mode it reaches minimum
// value in the upper position, however QSlider's minimum value is on
- // the bottom. So we need to invert a value, but since the scrollbar is
- // inverted by default, we need to inverse the delta value for the
+ // the bottom. So we need to invert the value, but since the scrollbar is
+ // inverted by default, we need to invert the delta value only for the
// horizontal orientation.
- if (event->orientation() == Qt::Horizontal)
- delta = -delta;
+ int delta = (orientation() == Qt::Horizontal ? -event->angleDelta().x() : event->angleDelta().y());
Q_D(QScrollBar);
- if (d->scrollByDelta(event->orientation(), event->modifiers(), delta))
+ if (d->scrollByDelta(orientation(), event->modifiers(), delta))
event->accept();
if (event->phase() == Qt::ScrollBegin)
diff --git a/src/widgets/widgets/qslider.cpp b/src/widgets/widgets/qslider.cpp
index 47d3b2fb81..161e4ba27a 100644
--- a/src/widgets/widgets/qslider.cpp
+++ b/src/widgets/widgets/qslider.cpp
@@ -46,6 +46,7 @@
#include "qpainter.h"
#include "qstyle.h"
#include "qstyleoption.h"
+#include "private/qapplication_p.h"
#include "private/qabstractslider_p.h"
#include "qdebug.h"
@@ -360,7 +361,7 @@ void QSlider::mousePressEvent(QMouseEvent *ev)
return;
}
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled())
+ if (QApplicationPrivate::keypadNavigationEnabled())
setEditFocus(true);
#endif
ev->accept();
diff --git a/src/widgets/widgets/qsplitter.cpp b/src/widgets/widgets/qsplitter.cpp
index 08533040a7..e7a4889996 100644
--- a/src/widgets/widgets/qsplitter.cpp
+++ b/src/widgets/widgets/qsplitter.cpp
@@ -771,14 +771,13 @@ void QSplitterPrivate::setGeo(QSplitterLayoutStruct *sls, int p, int s, bool all
if (!sls->handle->isHidden()) {
QSplitterHandle *h = sls->handle;
QSize hs = h->sizeHint();
- int left, top, right, bottom;
- h->getContentsMargins(&left, &top, &right, &bottom);
+ const QMargins m = h->contentsMargins();
if (orient==Qt::Horizontal) {
if (q->isRightToLeft())
p = contents.width() - p + hs.width();
- h->setGeometry(p-hs.width() - left, contents.y(), hs.width() + left + right, contents.height());
+ h->setGeometry(p-hs.width() - m.left(), contents.y(), hs.width() + m.left() + m.right(), contents.height());
} else {
- h->setGeometry(contents.x(), p-hs.height() - top, contents.width(), hs.height() + top + bottom);
+ h->setGeometry(contents.x(), p-hs.height() - m.top(), contents.width(), hs.height() + m.top() + m.bottom());
}
}
}
diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp
index f6f56c12d1..18fda11ddf 100644
--- a/src/widgets/widgets/qtabbar.cpp
+++ b/src/widgets/widgets/qtabbar.cpp
@@ -65,6 +65,7 @@
#endif
#include "qdebug.h"
+#include "private/qapplication_p.h"
#include "private/qtabbar_p.h"
#if 0 // Used to be included in Qt4 for Q_WS_MAC
@@ -415,7 +416,7 @@ void QTabBarPrivate::init()
QObject::connect(rightB, SIGNAL(clicked()), q, SLOT(_q_scrollTabs()));
rightB->hide();
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
leftB->setFocusPolicy(Qt::NoFocus);
rightB->setFocusPolicy(Qt::NoFocus);
q->setFocusPolicy(Qt::NoFocus);
@@ -2210,7 +2211,9 @@ void QTabBar::wheelEvent(QWheelEvent *event)
{
#ifndef Q_OS_MAC
Q_D(QTabBar);
- int offset = event->delta() > 0 ? -1 : 1;
+ int delta = (qAbs(event->angleDelta().x()) > qAbs(event->angleDelta().y()) ?
+ event->angleDelta().x() : event->angleDelta().y());
+ int offset = delta > 0 ? -1 : 1;
d->setCurrentNextEnabledIndex(offset);
QWidget::wheelEvent(event);
#else
diff --git a/src/widgets/widgets/qtabwidget.cpp b/src/widgets/widgets/qtabwidget.cpp
index 547b8a82f9..4d7b39ae01 100644
--- a/src/widgets/widgets/qtabwidget.cpp
+++ b/src/widgets/widgets/qtabwidget.cpp
@@ -39,6 +39,7 @@
#include "qtabwidget.h"
+#include "private/qapplication_p.h"
#include "private/qwidget_p.h"
#include "private/qtabbar_p.h"
#include "qapplication.h"
@@ -241,7 +242,7 @@ void QTabWidgetPrivate::init()
q->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding,
QSizePolicy::TabWidget));
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled())
+ if (QApplicationPrivate::keypadNavigationEnabled())
q->setFocusPolicy(Qt::NoFocus);
else
#endif
@@ -1108,14 +1109,14 @@ void QTabWidget::keyPressEvent(QKeyEvent *e)
if (((e->key() == Qt::Key_Tab || e->key() == Qt::Key_Backtab) &&
count() > 1 && e->modifiers() & Qt::ControlModifier)
#ifdef QT_KEYPAD_NAVIGATION
- || QApplication::keypadNavigationEnabled() && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right) && count() > 1
+ || QApplicationPrivate::keypadNavigationEnabled() && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right) && count() > 1
#endif
) {
int pageCount = d->tabs->count();
int page = currentIndex();
int dx = (e->key() == Qt::Key_Backtab || e->modifiers() & Qt::ShiftModifier) ? -1 : 1;
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled() && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right))
+ if (QApplicationPrivate::keypadNavigationEnabled() && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right))
dx = e->key() == (isRightToLeft() ? Qt::Key_Right : Qt::Key_Left) ? -1 : 1;
#endif
for (int pass = 0; pass < pageCount; ++pass) {
diff --git a/src/widgets/widgets/qtextbrowser.cpp b/src/widgets/widgets/qtextbrowser.cpp
index 7a77f86de2..3e49390315 100644
--- a/src/widgets/widgets/qtextbrowser.cpp
+++ b/src/widgets/widgets/qtextbrowser.cpp
@@ -42,6 +42,7 @@
#include <qstack.h>
#include <qapplication.h>
+#include <private/qapplication_p.h>
#include <qevent.h>
#include <qdesktopwidget.h>
#include <qdebug.h>
@@ -1016,7 +1017,7 @@ void QTextBrowser::keyPressEvent(QKeyEvent *ev)
Q_D(QTextBrowser);
switch (ev->key()) {
case Qt::Key_Select:
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
if (!hasEditFocus()) {
setEditFocus(true);
return;
@@ -1031,7 +1032,7 @@ void QTextBrowser::keyPressEvent(QKeyEvent *ev)
}
break;
case Qt::Key_Back:
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
if (hasEditFocus()) {
setEditFocus(false);
ev->accept();
@@ -1041,7 +1042,7 @@ void QTextBrowser::keyPressEvent(QKeyEvent *ev)
QTextEdit::keyPressEvent(ev);
return;
default:
- if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) {
+ if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) {
ev->ignore();
return;
}
diff --git a/src/widgets/widgets/qtextedit.cpp b/src/widgets/widgets/qtextedit.cpp
index 8599573e5a..bd9e5f8159 100644
--- a/src/widgets/widgets/qtextedit.cpp
+++ b/src/widgets/widgets/qtextedit.cpp
@@ -70,6 +70,7 @@
#include <qtextformat.h>
#include <qdatetime.h>
#include <qapplication.h>
+#include <private/qapplication_p.h>
#include <limits.h>
#include <qtexttable.h>
#include <qvariant.h>
@@ -1116,7 +1117,7 @@ bool QTextEdit::event(QEvent *e)
#endif // QT_NO_CONTEXTMENU
#ifdef QT_KEYPAD_NAVIGATION
if (e->type() == QEvent::EnterEditFocus || e->type() == QEvent::LeaveEditFocus) {
- if (QApplication::keypadNavigationEnabled())
+ if (QApplicationPrivate::keypadNavigationEnabled())
d->sendControlEvent(e);
}
#endif
@@ -1301,7 +1302,7 @@ void QTextEdit::keyPressEvent(QKeyEvent *e)
#ifdef QT_KEYPAD_NAVIGATION
switch (e->key()) {
case Qt::Key_Select:
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
// code assumes linksaccessible + editable isn't meaningful
if (d->control->textInteractionFlags() & Qt::TextEditable) {
setEditFocus(!hasEditFocus());
@@ -1322,14 +1323,14 @@ void QTextEdit::keyPressEvent(QKeyEvent *e)
break;
case Qt::Key_Back:
case Qt::Key_No:
- if (!QApplication::keypadNavigationEnabled()
- || (QApplication::keypadNavigationEnabled() && !hasEditFocus())) {
+ if (!QApplicationPrivate::keypadNavigationEnabled()
+ || (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus())) {
e->ignore();
return;
}
break;
default:
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
if (!hasEditFocus() && !(e->modifiers() & Qt::ControlModifier)) {
if (e->text()[0].isPrint())
setEditFocus(true);
@@ -1418,7 +1419,7 @@ void QTextEdit::keyPressEvent(QKeyEvent *e)
switch (e->key()) {
case Qt::Key_Up:
case Qt::Key_Down:
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
// Cursor position didn't change, so we want to leave
// these keys to change focus.
e->ignore();
@@ -1427,7 +1428,7 @@ void QTextEdit::keyPressEvent(QKeyEvent *e)
break;
case Qt::Key_Back:
if (!e->isAutoRepeat()) {
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
if (document()->isEmpty() || !(d->control->textInteractionFlags() & Qt::TextEditable)) {
setEditFocus(false);
e->accept();
@@ -1453,7 +1454,7 @@ void QTextEdit::keyReleaseEvent(QKeyEvent *e)
{
#ifdef QT_KEYPAD_NAVIGATION
Q_D(QTextEdit);
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
if (!e->isAutoRepeat() && e->key() == Qt::Key_Back
&& d->deleteAllTimer.isActive()) {
d->deleteAllTimer.stop();
@@ -1665,7 +1666,7 @@ void QTextEdit::mousePressEvent(QMouseEvent *e)
{
Q_D(QTextEdit);
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled() && !hasEditFocus())
+ if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus())
setEditFocus(true);
#endif
d->sendControlEvent(e);
@@ -1796,7 +1797,7 @@ void QTextEdit::inputMethodEvent(QInputMethodEvent *e)
Q_D(QTextEdit);
#ifdef QT_KEYPAD_NAVIGATION
if (d->control->textInteractionFlags() & Qt::TextEditable
- && QApplication::keypadNavigationEnabled()
+ && QApplicationPrivate::keypadNavigationEnabled()
&& !hasEditFocus())
setEditFocus(true);
#endif
diff --git a/src/widgets/widgets/qtoolbar.cpp b/src/widgets/widgets/qtoolbar.cpp
index fcaafbc581..d1a0f5ea78 100644
--- a/src/widgets/widgets/qtoolbar.cpp
+++ b/src/widgets/widgets/qtoolbar.cpp
@@ -53,7 +53,6 @@
#if QT_CONFIG(rubberband)
#include <qrubberband.h>
#endif
-#include <qsignalmapper.h>
#include <qstylepainter.h>
#include <qstyleoption.h>
#include <qtoolbutton.h>
diff --git a/src/widgets/widgets/qwidgetlinecontrol.cpp b/src/widgets/widgets/qwidgetlinecontrol.cpp
index 56dba1dd32..46bc29eed7 100644
--- a/src/widgets/widgets/qwidgetlinecontrol.cpp
+++ b/src/widgets/widgets/qwidgetlinecontrol.cpp
@@ -54,6 +54,7 @@
#endif
#include "qapplication.h"
+#include "private/qapplication_p.h"
#if QT_CONFIG(graphicsview)
#include "qgraphicssceneevent.h"
#endif
@@ -1662,7 +1663,7 @@ void QWidgetLineControl::processKeyEvent(QKeyEvent* event)
case Qt::Key_F4:
#ifdef QT_KEYPAD_NAVIGATION
case Qt::Key_Select:
- if (!QApplication::keypadNavigationEnabled())
+ if (!QApplicationPrivate::keypadNavigationEnabled())
break;
#endif
if (!m_completer->currentCompletion().isEmpty() && hasSelectedText()
@@ -1912,7 +1913,7 @@ void QWidgetLineControl::processKeyEvent(QKeyEvent* event)
break;
#ifdef QT_KEYPAD_NAVIGATION
case Qt::Key_Back:
- if (QApplication::keypadNavigationEnabled() && !event->isAutoRepeat()
+ if (QApplicationPrivate::keypadNavigationEnabled() && !event->isAutoRepeat()
&& !isReadOnly()) {
if (text().length() == 0) {
setText(m_cancelText);
diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp
index 70e1c148a1..fdbaf29dd8 100644
--- a/src/widgets/widgets/qwidgettextcontrol.cpp
+++ b/src/widgets/widgets/qwidgettextcontrol.cpp
@@ -55,6 +55,7 @@
#endif
#include <qstyle.h>
#include <qtimer.h>
+#include "private/qapplication_p.h"
#include "private/qtextdocumentlayout_p.h"
#include "private/qabstracttextdocumentlayout_p.h"
#include "qtextdocument.h"
@@ -294,7 +295,7 @@ bool QWidgetTextControlPrivate::cursorMoveKeyEvent(QKeyEvent *e)
bool isNavigationEvent = e->key() == Qt::Key_Up || e->key() == Qt::Key_Down;
#ifdef QT_KEYPAD_NAVIGATION
- ignoreNavigationEvents = ignoreNavigationEvents || QApplication::keypadNavigationEnabled();
+ ignoreNavigationEvents = ignoreNavigationEvents || QApplicationPrivate::keypadNavigationEnabled();
isNavigationEvent = isNavigationEvent ||
(QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional
&& (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right));
@@ -1159,7 +1160,7 @@ void QWidgetTextControl::processEvent(QEvent *e, const QMatrix &matrix, QWidget
#ifdef QT_KEYPAD_NAVIGATION
case QEvent::EnterEditFocus:
case QEvent::LeaveEditFocus:
- if (QApplication::keypadNavigationEnabled())
+ if (QApplicationPrivate::keypadNavigationEnabled())
d->editFocusEvent(e);
break;
#endif
@@ -2218,7 +2219,7 @@ void QWidgetTextControlPrivate::focusEvent(QFocusEvent *e)
emit q->updateRequest(q->selectionRect());
if (e->gotFocus()) {
#ifdef QT_KEYPAD_NAVIGATION
- if (!QApplication::keypadNavigationEnabled() || (hasEditFocus && (e->reason() == Qt::PopupFocusReason))) {
+ if (!QApplicationPrivate::keypadNavigationEnabled() || (hasEditFocus && (e->reason() == Qt::PopupFocusReason))) {
#endif
cursorOn = (interactionFlags & (Qt::TextSelectableByKeyboard | Qt::TextEditable));
if (interactionFlags & Qt::TextEditable) {
@@ -2259,7 +2260,7 @@ void QWidgetTextControlPrivate::editFocusEvent(QEvent *e)
{
Q_Q(QWidgetTextControl);
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
if (e->type() == QEvent::EnterEditFocus && interactionFlags & Qt::TextEditable) {
const QTextCursor oldSelection = cursor;
const int oldCursorPos = cursor.position();
@@ -3280,7 +3281,7 @@ QAbstractTextDocumentLayout::PaintContext QWidgetTextControl::getPaintContext(QW
if (!d->dndFeedbackCursor.isNull())
ctx.cursorPosition = d->dndFeedbackCursor.position();
#ifdef QT_KEYPAD_NAVIGATION
- if (!QApplication::keypadNavigationEnabled() || d->hasEditFocus)
+ if (!QApplicationPrivate::keypadNavigationEnabled() || d->hasEditFocus)
#endif
if (d->cursor.hasSelection()) {
QAbstractTextDocumentLayout::Selection selection;
diff --git a/src/xml/sax/qxml.cpp b/src/xml/sax/qxml.cpp
index 1c45118fb1..1993073cce 100644
--- a/src/xml/sax/qxml.cpp
+++ b/src/xml/sax/qxml.cpp
@@ -1161,12 +1161,12 @@ QChar QXmlInputSource::next()
d->nextReturnedEndOfData = false;
fetchData();
if (d->pos >= d->length) {
- return EndOfDocument;
+ return QChar(EndOfDocument);
}
return next();
}
d->nextReturnedEndOfData = true;
- return EndOfData;
+ return QChar(EndOfData);
}
// QXmlInputSource has no way to signal encoding errors. The best we can do
@@ -1174,7 +1174,7 @@ QChar QXmlInputSource::next()
// will then just call this function again to get the next char.
QChar c = d->unicode[d->pos++];
if (c.unicode() == EndOfData)
- c = EndOfDocument;
+ c = QChar(EndOfDocument);
return c;
}
@@ -1313,8 +1313,8 @@ static QString extractEncodingDecl(const QString &text, bool *needMoreText)
return QString();
while (pos < endPos) {
- ushort uc = text.at(pos).unicode();
- if (uc == '\'' || uc == '"')
+ QChar uc = text.at(pos);
+ if (uc == u'\'' || uc == u'"')
break;
++pos;
}
@@ -1325,8 +1325,8 @@ static QString extractEncodingDecl(const QString &text, bool *needMoreText)
QString encoding;
++pos;
while (pos < endPos) {
- ushort uc = text.at(pos).unicode();
- if (uc == '\'' || uc == '"')
+ QChar uc = text.at(pos);
+ if (uc == u'\'' || uc == u'"')
break;
encoding.append(uc);
++pos;
@@ -7800,7 +7800,7 @@ void QXmlSimpleReaderPrivate::next()
c = inputSource->next();
// If we are not incremental parsing, we just skip over EndOfData chars to give the
// parser an uninterrupted stream of document chars.
- if (c == QXmlInputSource::EndOfData && parseStack == nullptr)
+ if (c == QChar(QXmlInputSource::EndOfData) && parseStack == nullptr)
c = inputSource->next();
if (uc == '\n') {
lineNr++;
@@ -7877,7 +7877,7 @@ void QXmlSimpleReaderPrivate::init(const QXmlInputSource *i)
*/
void QXmlSimpleReaderPrivate::initData()
{
- c = QXmlInputSource::EndOfData;
+ c = QChar(QXmlInputSource::EndOfData);
xmlRefStack.clear();
next();
}
@@ -7925,7 +7925,7 @@ void QXmlSimpleReaderPrivate::unexpectedEof(ParseFunction where, int state)
if (parseStack == nullptr) {
reportParseError(QLatin1String(XMLERR_UNEXPECTEDEOF));
} else {
- if (c == QXmlInputSource::EndOfDocument) {
+ if (c == QChar(QXmlInputSource::EndOfDocument)) {
reportParseError(QLatin1String(XMLERR_UNEXPECTEDEOF));
} else {
pushParseState(where, state);