Commit Graph

13249 Commits

Author SHA1 Message Date
Laszlo Agocs
bc4570ed24 rhi: Auto-rebuild rt by tracking attachment id and generation
Unlike the shader resource binding lists that automatically recognize
in setShaderResources() when a referenced QRhiResource has been rebuilt
in the meantime (create() was called i.e. there may be completely
different native objects underneath), QRhiTextureRenderTarget has no
such thing. This leads to an asymmetric API and requires also rebuilding
the rt whenever an attachment is rebuilt:

rt = rhi->newTextureRenderTarget({ { texture } })
rt->create()
cb->beginPass(rt, ...)
texture->setPixelSize(...)
texture->create()
rt->create() // this should not be needed
cb->beginPass(rt, ...)

Avoid having to do that second rt->create().

Change-Id: If14eaa7aac3530950498bbdf834324d0741a7c4d
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2021-12-10 15:08:51 +01:00
Marc Mutz
48b75def5d QList: fix typo in QList(It, It)
Remove scaffolding in the test again.

[ChangeLog][QtCore][QList] Fixed a regression that caused the range
constructor to fail for pure input_iterator's.

Pick-to: 6.2
Fixes: QTBUG-99036
Change-Id: I72d01a9c44c3862c335d96538f26a453b4c7c554
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2021-12-10 13:48:37 +00:00
Marc Mutz
2e07d045ff tst_containerapisymmetry: test ranged ctors with pure input_iterator types
Fails in Qt 6, succeeds in Qt 5.15, therefore needed to add the
version check.

Pick-to: 6.2 5.15
Task-number: QTBUG-99036
Change-Id: I9da1b2511d844b5fdcb63fdc58c8bc34d0f65736
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2021-12-09 22:49:45 +01:00
Edward Welbourne
6729a4b29c TAP test logger: avoid dangling space on TODO and SKIP lines
If an incident has an empty description we produced output with a
dangling space. Avoid triggering the inanity 'bot with those.
Reorganise the code to save some duplication.

Change-Id: I1dc29fa8ad4449a4584f11dddcf002e405cd9238
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2021-12-09 20:54:26 +01:00
Edward Welbourne
8d0b5270fa TAP test logger: skip XFail results as well as pass after an XFail
The rationale for skipping pass after XFail is "to emit a single test
point for" the test; emitting several XFails violates that aim.

Task-number: QTBUG-96844
Change-Id: Ia8626dfc2dded234b3aa530fc2dc2324f1e28400
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2021-12-09 20:54:26 +01:00
Edward Welbourne
77a93e6df3 Make Skip an incident in test logging
Skip ends the test (albeit inconclusively).  Rearrange the enums in
the abstract logger, move code to handle skip between relevant
function and tidy up various things that became simpler as a result.

Also reorder the message enum, and its switches, to separate testlib's
internals from the usual Qt messages, and put each group in ascending
order of severity.

Task-number: QTBUG-96844
Change-Id: I2c7a634b9f849830d64eafa750155e66e244b729
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2021-12-09 20:54:26 +01:00
Edward Welbourne
1c24b4b8d9 Match up testlib selftest's lists of generated files
The actual files present for expected data, the test function that
selected which tests to skip and the python function to select which
to not generate data for weren't in sync with one another.

The test-code's reason for omitting three tests was that we lacked
data files for them. So generate those and skip that exception. The
generator script's code to decide which to generate didn't exclude
anything like as many, so update it to match the test-code. In the
process, save repeating a startswith test that was used both
positively and negatively, unifying two conditions.

Extend the generator script's handling of its --skip-callgrind option
by auto-setting that option if valgrind isn't available, to match the
driver program's similar skipping.

The generated data included many files for tests we skip and, as
mentioned already, lacked files for some tests we only skipped because
we lacked them. Remove the unused files, add the lacking ones.

Change-Id: If91696cdd95b7b0d5f3d686bff839f1bf15e121b
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-12-09 20:54:25 +01:00
Edward Welbourne
37bc11e707 Refactor QTEST*_MAIN() implementations
The various variants duplicated some rather complex code around
varying setup in the middle. Rework in terms of a macro that defines
main() and takes the setup code as a parameter. That setup code also
had some common structure, so package that in a setup macro that takes
the class to be used.

Reworked various testlib selftests that were using QTEST_MAIN_IMPL();
change to use the new QTEST_MAIN_WRAPPER() and TEST_MAIN_SETUP().
These might be better dealt with by supporting a second form of the
initMain() test-setup function in the test classes, that takes
references for argc and argv, to let a test massage its command-line
options.

Change-Id: I7fb16b38d51c80ba2f5c9c82f3b7a37ffc636795
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-12-09 20:54:25 +01:00
Edward Welbourne
93830d9ed3 Fix x86 preprocessor check in testlib selftests
When deciding whether to run benchlibcallbrind, the code only tested
_i386; it now tests __x86_64 as well, to match a recent change in the
test itself. As there, reverse the test to reduce negations, flipping
the stanzas it selects between. Also tidy up the code that tests for
valgrind being present - and actually return true, to skip the test,
when it claims to be skipping the test.

Updated test results, now that the test can actually be run and
produce sensible output. Added an _2.txt that matches the results
presently seen in Coin on RHEL 8.4 (despite the fact that a local
build on such a VM produces output matching the _1.txt results).

Change-Id: Ibce09dca06a1eeb73e90fb1345834998683df9d8
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2021-12-09 20:54:25 +01:00
Edward Welbourne
e42fe5c775 Fix argv hacking in tst_benchlibcallgrind.cpp
It unconditionally added -callgrind to its own command-line options,
but the way testlib handles this argument is, in QTest::qRun(), to
re-run the program under the control of valgrind --tool=callgrind,
removing the -callgrind command-line option from the test and adding
-callgrindchild to its command-line options. So we shouldn't re-add
the -callgrind option in the resulting recursive call.

The test now runs quickly, producing sensible output, where previously
it took a very long time. Revised the drivers to reflect this
speed-up, but continue skipping the non-.txt formats to save the need
for variant-output files for many formats. To match that, removed the
unused non-.txt results files.

Change-Id: Iaa99c1b5964d50bccfc6076a21896791b6bbf289
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2021-12-09 20:54:25 +01:00
Edward Welbourne
4eb2dcd4b9 Replace a random define with a __has_include() check
The given reason for needing to define it was that there was no way to
test whether <valgrind/valgrind.h> is available to #include; but we
now require C++17 hence __has_include(). However, moc doesn't seem to
grok that, so move the test's #if-ery inside the test, since otherwise
it gets omitted because the test's metatype doesn't know it's there.

Change-Id: I75a100787b98a52fad4cfb0b047318a115c998e2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2021-12-09 20:54:25 +01:00
Marc Mutz
e297e80fd0 QVarLengthArray: make reallocation strongly exception safe
The old code had several bugs:

- it immediately clobbered *this with new state, before having copied
  over the elements from the old to the new buffer

- when buffer relocation threw, it would keep the new (partially-filled)
  buffer and throw away the old

- it unconditionally used std::move() for non-relocatable types, making
  it impossible to restore the original buffer when a move throws

Instead of clobbering *this with new state, do all the work on the
side and change *this only once the reallocation has happened
successfully.

Also use q_uninitialized_relocate_n() and unique_ptr in the
implementation to simplify the code. The former got the necessary
update to use std::move_if_noexcept() instead of an unconditional
std::move() for the non-relocatable case.

[ChangeLog][QtCore][QVarLengthArray] The append()-like functions are
now strongly exception safe. This means reallocation will now use
copies instead of moves, unless the value_type has a noexcept move
constructor.

Fixes: QTBUG-99039
Change-Id: I031251b8d14ac045592d01caed59d4638c3d9892
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2021-12-09 18:59:55 +00:00
Ievgenii Meshcheriakov
4f53c703e4 QLocale: Extend support for language codes
This commit extends functionality for QLocale::codeToLanguage()
and QLocale::languageToCode() by adding an additional argument
that allows selection of the ISO 639 code-set to consider for
those operations.

The following ISO 639 codes are supported:
    * Part 1
    * Part 2 bibliographic
    * Part 2 terminological
    * Part 3

As a result of this change the codeToLanguage() overload without
the additional argument now returns a Language value if it matches
any know code. Previously a valid language was returned only if
the function argument matched the first code defined for that
language from the above list.

[ChangeLog][QtCore][QLocale] Added overloads for codeToLanguage()
and languageToCode() that support specifying which ISO 639 codes
to consider.

Fixes: QTBUG-98129
Change-Id: I4da8a89e2e68a673cf63a621359cded609873fa2
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2021-12-09 03:45:08 +01:00
Sona Kurazyan
0fbeac0115 Fix the benchmark for QList::removeAll()
The benchmark was making assumptions about number of
constructor/assignment operator calls, which are not valid in Qt 6,
after the implementation of QList has changed. Considering that we
already check number of constructions, copy constructions, etc., in
tst_qlist.cpp, remove the checks from the benchmark.

As a driveby, fix the following warning:
"warning: parameter 'i' shadows member inherited from type 'MyBase'"

Pick-to: 6.2
Fixes: QTBUG-95096
Change-Id: Ida68fa5803641c8fa84f8309c0093986ed4c0a2b
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2021-12-09 03:45:08 +01:00
Volker Hilsheimer
b886a7ca65 Add unit test for moving of opaque widgets
Expose QWidgetRepaintManager's data structures so that we can write
unit tests, and verify that they are correct after moving opaque
widgets (which triggers the accelerated move code path).

Improve the compareWidget logic to not rely on screen grabbing
(which requires permissions), but instead use QPlatformBackingStore's
toImage function, which is faster and more reliable, and also doesn't
require us to show the UI we want to grab full screen in order to
avoid issues with overlapping windows etc.

Change-Id: Iff2ea419f03a390ab6baca26814fef6ff45f7470
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-12-08 23:06:42 +00:00
Liang Qi
c8609d1e7a tests: add a capability check for QWindow::requestActivate() call
This amends b65159a5ea.

Pick-to: 6.2
Change-Id: I6055004375b440997ea41b3e4538854780202e10
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-12-08 21:08:04 +01:00
Marc Mutz
d4a88e4ea4 QVarLengthArray: fix size update on failed append()
If the in-place constructor throws, the old code had already updated
the container's size(). Fix by delaying the update to after the
in-place construction.

[ChangeLog][QtCore][QVarLengthArray] Fixed a bug whereby a failed
append() would leave the container with an inconsistent size().

Pick-to: 6.2 5.15
Change-Id: Ief1e668d945149bd8ba96c8af1398baaa7876880
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2021-12-08 16:39:27 +00:00
Liang Qi
493a85a9e4 Widgets: setTransientParent() when a QMenu is a window
On some platforms, such as X11 and Wayland with some compositors,
QMenu could be a popup window, which should be set a transient parent
to get relative position, which is requested by Wayland.

Added transientParentWindow() for QMenuPrivate like QDialogPrivate.

Fixes: QTBUG-68636
Pick-to: 6.2
Change-Id: I6d8880cb008ecf61a4c005898b38e3953379a13d
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2021-12-08 13:45:36 +01:00
Lorn Potter
f0be152896 wasm: improve clipboard support
Add support for Clipboard API
Add clipboard manual test

Also includes these fixes:

- improve clipboard use for chrome browser
- make QClipboard::setText work
- html copy and paste
- image copy/paste

Chrome browser supports text, html and png

To use the Clipboard API, apps need to be served from
a secure context (https). There is a fallback in the
case of non secure context (http)

- Firefox requires dom.events.asyncClipboard.read,
dom.events.asyncClipboard.clipboardItem and
dom.events.asyncClipboard.dataTransfer to be
set from about:config, in order to support the
Clipboard API.

Change-Id: Ie4cb1bbb1dfc77e9655090a30967632780d15dd9
Fixes: QTBUG-74504
Fixes: QTBUG-93619
Fixes: QTBUG-79365
Fixes: QTBUG-86169
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2021-12-08 13:39:58 +10:00
Volker Hilsheimer
ec267a4c7c Add unit test for QWidgetPrivate::overlappedRegion
Added to QWidgetRepaintManager test case, which is the only place where
the function is used.

Includes a helper that creates a complex scene with opaque children,
which will be used in additional unit tests.

Change-Id: I0e0188dd560923a552a8967d8e992dc17cc849d6
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-12-08 00:40:21 +01:00
Marc Mutz
cb00db5a7e QVarLengthArray: add some basic checks for default-ctor
There seems to have been no-one that checked a simple empty()/isEmpty()...

Pick-to: 6.2 5.15
Change-Id: I7fa567f556532dfa21db759719f1303a768a9732
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2021-12-07 22:53:14 +01:00
Giuseppe D'Angelo
84fba93ebb QThread::create(): request interruption and join on destruction
If one destroys a running QThread, so far the behavior has been to crash
(à la std::thread) -- assuming the thread hasn't already signalled that
it has finished. This behavior is hostile to solutions such as using
QThread::create(), which always require a wait() before destroying the
thread object.

We can use the opportunity to change the behavior without breaking any
valid code. Instead of crashing, inside QThread's destructor we can ask
the new thread to quit, and then join it (à la std::jthread). This
simplifies the implementation of long-living runnables and the code that
manages them.

Deploying this solution for the whole QThread class may not be entirely
painless. While no correct code would work differently with the proposed
changes, incorrect code that deletes a running thread would no longer
crash "loudly" -- instead, it might deadlock "quietly", have memory
corruptions, etc.

Hence I'm limiting this approach to only the threads created by
QThread::create(), at least for the time being. This also side-steps
perhaps the biggest problem of generalizing the approach, which is that
placing such interrupt+join logic into~QThread's destructor would cause
it to be run _after_ a QThread subclass' own destructor has run,
destroying the subclass' data members too early. This might create
an antipattern if one chooses to subclass QThread. With create(), a
subclass in question exists, and it indeed has NSDMs, but it's entirely
under our control (in fact, I'm placing the logic just in its dtor).

[ChangeLog][QtCore][QThread] Destroying a QThread object created by
QThread::create() while the thread that it manages is still running will
now automatically ask that thread to quit, and will wait until the
thread has finished. Before, this resulted in a program crash. See the
documentation of QThread::~QThread() for more details.

Change-Id: Ib268b13da422e277ee3ed6f6c7b2ecc8cea5750c
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2021-12-07 16:56:49 +01:00
Marc Mutz
f898128ee2 tst_qmetatype: factor the most expensive test into its own TU
The PRINT_2ARD_TEMPLATE macro expansion alone is responsible for about
50% of the compile time and RAM requirements of tst_qmetatype.cpp. By
factoring it into its own TU, we reduce the maximum memory load on my
machine from 4.0GiB to 2.5GiB, provided we don't parallelize the
build, then we take 0.5GiB more.

This is a quick-fix for the QNX build problems currently plaguing the
CI. Going forward, we should probably have a better solution, whatever
that may be.

Task-number: QTQAINFRA-4669
Change-Id: I2732b4c25b369b15cce1c7afe222d041ecb6795a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-12-07 15:57:33 +01:00
Marc Mutz
31f155d985 tst_qmetatype: move an #ifdef to the header
... so it can be used by multiple .cpp files.

Task-number: QTQAINFRA-4669
Change-Id: I7212b9b08cd3bfa44ee741ee4789d1d0024e4708
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2021-12-07 09:06:18 +01:00
Mårten Nordheim
78df625510 QMultiHash: fix erase returning the wrong iterator
When deleting the last item in a chain, without it being the last item
in the chain, then we re-use the iterator which was passed in as an
argument. This is wrong if we detached earlier in the function, and
means we return an iterator to the previously shared data.

Pick-to: 6.2
Change-Id: I7da6309e23a32073da59e7da0cbfd1d16734f1ca
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2021-12-07 03:07:49 +01:00
Igor Kushnir
d797e3c88e Optimize QMimeDatabase::mimeTypeForFile(f, MatchDefault)
Open the file only if matching on content is needed.

Use QFileInfo::filePath() instead of QFileInfo::absoluteFilePath() in
QMimeDatabase::mimeTypeForFile(). filePath() does much less work, and so
is faster. Thiago Macieira helpfully explained in a review comment why
the absolute path is not useful for correctness here: "Nothing needs
absolute paths within the same application that would resolve the
relative path to absolute. You only need an absolute path if you're
communicating with another application that may be in a different
directory."

QMimeDatabase::mimeTypeForFile() checks fileInfo.isDir(), so the
fileName.endsWith(QLatin1Char('/')) check in
QMimeDatabasePrivate::mimeTypeForFileNameAndData() was redundant when
called from this function. The other two callers of that function now
check this condition before opening IO devices. This improves
performance of the two QMimeDatabase::mimeTypeForFileNameAndData()
overloads in the corner case.

Refactor and optimize QMimeDatabasePrivate::findByFileName() and its
usages. Previously each caller constructed a QFileInfo object and passed
QFileInfo::fileName() into this function. Now the callers simply pass an
absolute or relative path to a file into this function, which then uses
QFileSystemEntry::fileName() to exclude the path. Constructing QFileInfo
is relatively expensive, so this change slightly improves performance.

Optimize QMimeDatabasePrivate::loadProviders() by calling static
QFileInfo::exists() instead of constructing a QFileInfo object and
calling the non-static QFileInfo::exists() overload. Note that the
QFileInfo object was always created, even if QFileInfo::exists() under
an `if` and an `#if` was never called.

The following table contains the average results of the added benchmark
tst_QMimeDatabase::benchMimeTypeForFile() on my GNU/Linux system before
and at this commit. The numbers denote milliseconds per iteration.

        data row tag                        before  at
MatchDefault:
        archive                             0.029   0.016
        OpenDocument Text                   0.029   0.015
        existent archive with extension     0.039   0.025
        existent C with extension           0.033   0.020
        existent text file with extension   0.033   0.020
        existent C w/o extension            0.076   0.074
        existent patch w/o extension        0.11    0.105
        existent archive w/o extension      0.069   0.066
MatchExtension:
        archive                             0.012   0.0115
        OpenDocument Text                   0.0115  0.011
        existent archive with extension     0.017   0.016
        existent C with extension           0.011   0.011
        existent text file with extension   0.011   0.011
        existent C w/o extension            0.016   0.0155
        existent patch w/o extension        0.013   0.012
        existent archive w/o extension      0.013   0.012
MatchContent:
        archive                             0.019   0.012
        OpenDocument Text                   0.019   0.012
        existent archive with extension     0.053   0.051
        existent C with extension           0.056   0.0545
        existent text file with extension   0.058   0.056
        existent C w/o extension            0.0605  0.059
        existent patch w/o extension        0.10    0.099
        existent archive w/o extension      0.057   0.054

Change-Id: Idb541656e073a2c4822ace3f4da412f29f2351f8
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: David Faure <david.faure@kdab.com>
2021-12-06 22:55:06 +02:00
Mårten Nordheim
6f542f19bf QFontDatabase (Windows): Sanitize font requests early
After the windows font engine was no longer marking everything as
scalable we started limiting the font size of requests to the maximum
of Courier when it was requested. This was a regression from 5.8 and not
in agreement with our documentation.

The problem is that we would only make the switch from Courier to
Courier New after having already gone through the foundry-lookup and
found a closest-available font size for Courier.

With this sanitization step in the backend we can make these changes
early enough that we haven't yet adjusted e.g. the font size.

Pick-to: 6.2 5.15
Fixes: QTBUG-58995
Change-Id: I319e93e6b78c7c3c5539964ac5ab4e05f8902ab6
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
2021-12-06 20:06:06 +01:00
Tatiana Borisova
eba9196304 Fix tst_qfloat16 runtime failure for INTEGRITY
- GHS compiler is not fully compliant with iec559. Therefore we need
to update is_iec559 checking for GHS case.

Pick-to: 6.2
Change-Id: Ia094509d26bf5f0109f2937547a056267019cffb
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Janne Koskinen <janne.p.koskinen@qt.io>
2021-12-06 18:53:50 +00:00
Edward Welbourne
9e835fe5a4 tst_BenchlibCallgrind: fix x86 preprocessor check
Its twoHundredMillionInstructions() test has #if-ery to limit it to
gcc and x86; however, it was testing only __i386 for the x86 part,
where gcc defines __x86_64 instead on modern 64-bit systems. In the
process, invert the condition and the branches it controls - positive
tests are easier to comprehend.

Change-Id: I8e906c606c48aa5034e02e3ed5d042fbb1f2ecbc
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2021-12-06 19:06:30 +01:00
Dmitry Shachnev
f25761c617 Remove chip.debug compiled binary leftover from debugging
Pick-to: 6.2
Change-Id: I9d1ca06ffb5f9b8fc6e6042c399311dcec059521
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2021-12-06 07:15:59 +00:00
Mårten Nordheim
cdc3de6c84 QStringBuilder: Add support for QByteArrayView
[ChangeLog][QtCore][QStringBuilder] Added support for QByteArrayView.

Change-Id: If2c23549d533dd31c320f3ee455fcd01ea5b460a
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2021-12-04 08:21:22 +00:00
Mårten Nordheim
9909ec0bc6 QNAM: Reintroduce h2c with an attribute
[ChangeLog][QtNetwork][QNetworkRequest] Added
QNetworkRequest::Http2CleartextAllowedAttribute which controls whether
HTTP/2 cleartext (h2c) is allowed or not. The default is false. This
replaces the QT_NETWORK_H2C_ALLOWED environment variable.

Task-number: QTBUG-98642
Change-Id: I43ae1cc671788f6d2559cd316f6667b412c8e75e
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2021-12-04 08:20:52 +00:00
Ievgenii Meshcheriakov
83f2f27bb6 QFile: Add open() overload that accepts permissions argument
The new overload allows creation of files with non-default permissions.
This is useful when files need to be created with more restrictive
permissions than the default ones, and removes the time window when
such files are available with less restrictive permissions.

[ChangeLog][QtCore][QFile] Added QDir::open() overload that
accepts permissions argument.

Fixes: QTBUG-79750
Change-Id: Iddfced3c324e03f2c53f421c9b31c76dee82df58
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2021-12-04 01:27:11 +01:00
Ievgenii Meshcheriakov
56e13acf4e QAbstractFileEngine: Add permission argument to open()
The new argument allows atomic creation of files with non-default
permissions.

Task-number: QTBUG-79750
Change-Id: I4c49455b41f924ba87148302c8d0f77f5de0832b
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2021-12-04 01:27:08 +01:00
Volker Hilsheimer
56bd1b76d2 Don't change resolve mask when setting brush doesn't change palette
After 556511f9f3, which moved the resolve
mask storage into the palette's d-pointer, modifying the resolve mask
requires a detach. As of now, we only detached when setting a different
brush, but always modified the resolve mask, which broke palettes that
shared the d-pointer (likely the global default palette).

However, detaching has negative side effects when styles set brushes on
temporary palette objects and then use that palette object's cache key
to build a cache of pixmaps. As each drawing would detach the palette
(even if the palette doesn't change, which is likely), the cache key
changes with each detach, and the cache would quickly increase in size.
This was addressed in changes d7bcdc3a44
and 1e75dcf251.

We can either detach and find other ways to address the issues from
QTBUG-65475, or we can not change the resolve mask when the brush doesn't
change and completely ignore the call.

Since QFont ignores the setting of any attribute to a value that is
identical to the current value, and since it's possible to force that
the resolve-bit is set by calling setBrush twice with different brushes,
ignoring the call seems like the better solution.

[ChangeLog][QtGui][QPalette] Setting a brush on a palette that is
identical to the current brush no longer sets the resolve mask bit for
that particular role, so items using the palette will continue to
inherit changes from parent items.

Fixes: QTBUG-98762
Task-number: QTBUG-65475
Pick-to: 6.2
Change-Id: Ife0f934b6a066858408ef75b7bb7ab61193ceb47
Reviewed-by: Simon Hausmann <hausmann@gmail.com>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2021-12-03 21:07:09 +01:00
Volker Hilsheimer
c034ad03ac QPA: Set focus reason when window activation changes focus
QApplication hides the fact that the reason is never set by several
QPA plugins, but Quick items don't receive the correct reason on
Windows, Android, the offscreen plugin, and other platforms.

Add relevant scenario to the QFocusEvent test case, and fix the
plugins to always set the focus reason when handling window activation
changes. Exclude the minimal plugin from the test, it seems largely
unmaintained anyway.

Task-number: QTBUG-75862
Change-Id: I5404a225b387fc9a3851b6968d0777c687127ed1
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-12-03 08:15:29 +01:00
Shawn Rutledge
dbb9579566 Text editing: smart block and char format after newline
When you are editing in a QTextEdit and press enter to start a new line,
calling insertBlock() with no arguments tries to preserve the current
charFormat and blockFormat. That is often OK:
- if you hit enter at the end of a list item, you probably want another
  item in the same list
- if you are writing code inside a code block, you're probably just
  writing the next statement on the next line: stay in the same block
- margins, indents, tab positions should stay the same (but hopefully
  your editor has UI to manually reset the block format to default
  in case you are not continuing in the same style)
But there are some exceptions we can apply to be helpful:
- nobody ever wants to follow an <hr/> with another one (but
  hopefully the application has an action to insert one manually)
- a heading is more likely to be followed by a paragraph, or perhaps
  a smaller heading; another heading at the same level is unlikely.
  We need to reset the char format, not only the block format, because
  the large font and heavy font weight are stored there.
- when adding to a todo list, hitting enter at the end of the last task,
  let's assume the next task is not yet done, so it will be unchecked
  by default (else, why are you writing a todo list at all)
To achieve that, we need to customize the formats and call the
insertBlock() overload that takes them. The no-argument insertBlock()
will continue to preserve the formats, because it's an old API that is
used for much more than interactive editing.

Additionally, word processors tend to let you end a list (for example)
by hitting enter twice. In that case, you stay in the same paragraph
that you created the first time you hit enter, but now the formats are
reset to default, so that you can go on typing an ordinary paragraph,
rather than having to mouse up to the toolbar to select the paragraph
style in a combobox, or something like that. So we now do that: reset
both block and char formats after you hit enter on a blank line; but if
you then hit enter again, after the block format has been reset, then
you will get the actual blank line (empty block) inserted.

[ChangeLog][QtWidgets][QTextEdit] Hitting enter at the end of a line
with a special block format (horizontal rule, heading, checklist item)
now makes some "smart" adjustments to avoid retaining properties that
are unlikely to be continued on the next line. Hitting enter twice now
resets block and char formats to default.

Fixes: QTBUG-48815
Task-number: QTBUG-80473
Fixes: QTBUG-97459
Change-Id: I3dfdd5b4c0d9ffb4673acc861cb7b5c22291df25
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
2021-12-02 22:22:59 +01:00
Marc Mutz
ecc307ff41 QString et al: fix lastIndexOf() API asymmetry
Commit 6cee204d56 introduced overloads
of lastIndexOf() which drop the 'from' argument, inadvertently fixing
QTBUG-80694, but failed to provide the new overloads for all existing
lastIndexOf() overloads, making the fix for QTBUG-80694 incomplete.

This patch completes the fix, by adding the missing overloads (for
char-likes) and also adds the missing (non-regex) tests to
tst_qstringapisymmetry.

Also amends 1c164ec7f2.

Fixes: QTBUG-80694
Change-Id: Ib4b3d597d658ce2edf01a2bce0d711ecea593d6e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-12-02 16:05:33 +00:00
Alexey Edelev
63b8840380 Fix dependency chain that collects the metatype json files
cmake_automoc_parser has the logic preventing the run of moc with the
--collect-json parameter if metatype json files are not changed.
This logic only verify if the file list is changed but not their
content. This change adds a timestamp file that contains the last
metatype json file timestamp that was modified during the last
cmake_automoc_parser run. The logic still prevents of running
'moc --collect-json' when the list of metatype json files is not
changed, but also checks if their content is no changed.

Another approach it to generate the depfile that can be utilized by
CMake in add_custom_command as DEPFILE argument. But this concept only
works from the second build attempt because of an issue related to
dyndep.

Pick-to: 6.2
Fixes: QTBUG-98532
Change-Id: I713f8bfa9ae769cefe0beac0b7fa19750b00a765
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-12-02 16:34:23 +01:00
Volker Hilsheimer
d22bafe355 QTableView: correctly toggle column selection when scrolled
We need to check whether the horizontal header's selection includes the
index for the row at the top, rather than for row 0, as the index we
check is based on the scrolled position of the header, so would never be
included in the top row when the view is scrolled. This is correctly
done in selectRow already.

Add a test case that simulates selection of rows and columns by clicking
on the header.

Fixes: QTBUG-98444
Pick-to: 6.2
Change-Id: I2fa1b32bf75dc96225b40145b713bf7e2ffc29dd
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-12-02 14:16:49 +00:00
Volker Hilsheimer
97cfd49401 Don't let text table cells shrink below their minimum width
We calculate the minimum width, but then use it only to make sure that
the maximum width is at least as large as it. Without setting the layout
struct's minimumWidth as well, table cells can be smaller.

Add a test case.

Fixes: QTBUG-86671
Fixes: QTBUG-97463
Pick-to: 6.2 5.15
Change-Id: Idf4ad015938abb8d3e599e9a58e002f29c0067be
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
2021-12-02 15:16:49 +01:00
Eskil Abrahamsen Blomfeldt
6b02473e1e Fix overlapping text for Osaka font on macOS
The Osaka font on macOS has all zeroes in the OS/2 table, probably
because it is not intended to be cross-platform. In Qt 6 (since
f761ad3cd9) we are trying using the
same vertical metrics on all platforms, but this only works if
they are valid.

To work around this issue, we detect the case when ascent/descent
values are both 0, since this is very unlikely to be intentional,
so we fall back to the system-provided ascent and descent in these
cases.

Adding the test also revealed that we had missed the check for
a macOS-specific bitmap font format when skipping the check for
bitmap fonts in 7a18b7e2c2.

[ChangeLog][macOS][Text] Fixed a problem where using the Osaka
font would lead to overlapping text.

Pick-to: 6.2
Fixes: QTBUG-96880
Change-Id: Ifea7918641a68829e8f5ef20a4fb61c0a7e5b757
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-12-02 07:54:39 +01:00
Zhang Yu
c6c039167c Fix fail to activate first sub window with QMdiArea::TabbedView
The first sub window added will activate itself automatically, and
isActive is set to true. Therefore the call to setActiveSubWindow to
activate the first sub window will be ignored.

When showing the mdiarea, all sub windows will be activated in the order
in which they were added, so the active window will always be the last
sub window added.

Fix this by setting isActive to false so that setActiveSubWindow
activates the first sub window when the mdiarea becomes active.

Fixes: QTBUG-92037
Pick-to: 6.2
Change-Id: Id4a793e2059803c1a4ada916fdae2d3cc02cdf06
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2021-12-02 09:08:40 +08:00
Volker Hilsheimer
9538c7ca73 Don't shrink a column when it spans multiple columns
If a cell spans multiple columns, then the merged cells' starting
column's maximum width should never become smaller than what was
calculated from previous rows.

Otherwise, we'd distribute the space of the column that has a span
across all merged columns, resulting in unnecessary line breaks esp if
WrapAnywhere is enabled.

Add a test case.

Fixes: QTBUG-91691
Fixes: QTBUG-95240
Pick-to: 6.2 5.15
Change-Id: Ic27dbdb128071e50fba049de85c9f23ba2f059b3
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2021-12-01 21:23:05 +01:00
Alexandru Croitor
4ad57bb212 Re-enable tst_qopenglwindow on Linux
Amends 5d6705c567

Change-Id: I359b638465e24f3da0941083f9ad6f022b5222ed
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
2021-12-01 03:28:56 +01:00
Sona Kurazyan
3be72253a6 Fix QFuture continuations/handlers to work with move-only callables
std::function, which is used to store the type-erased continuation
lambdas, requires the passed callable to be copy-constructible. This
makes impossible to use move-only callables with continuations/handlers.
In particular, it makes impossible passing lambdas that are capturing
move-only objects. The workaround is to store the continuation lambda
inside a wrapper for the callable, which stores the move-only lambda in
a QSharedPtr and can be stored in std::function, since it's copyable.

Pick-to: 6.2
Fixes: QTBUG-98493
Change-Id: I8b7a22fcf68dc132b3c533216a7a1665e9f9fb0a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2021-12-01 01:58:18 +01:00
Giuseppe D'Angelo
54536bb5ae QString::arg: deprecate use of arbitrary Unicode digits as replacements
The only documented replacements for Q*String*::arg() are sequences like
%1, %2, %3 -- where the n-th number is expressed using a sequence of
ASCII digits [1].

The code parsing the replacements however used the QChar::digitValue()
function. That function simply checks if a QChar has a *Unicode digit
value* (no matter what its block/category is), and if so, returns the
corresponding digit value as an int (otherwise returns -1).

The result of this is that a sequence like "%¹" or "%१" actually
triggered substitutions (both count as "1"). Similarly, QChars with
a digit value would be parsed as part of longer sequences like "%1²"
(counting as "12" (!)).

This behavior is weird, undocumented, and extremely likely the usual
backstabbing by Unicode by using "convenience" QChar methods -- that is,
never *intended* by the implementation.

This commit deprecates (via warnings) such usages, which for the time
being are left working as before (in the name of backwards
compatibility). At the same time: given it's extremely unlikely that
someone would be deliberately relying on this behavior, it implements
the desired change of behavior (only accept sequences of ASCII digits)
starting from Qt 6.6, that is, after the next LTS.

Throughout Qt 6's lifetime users will still be able to control arg()'s
behavior by setting an env variable, but that variable (and the support
for Unicode digits) will disappear in Qt 7.

To summarize:

* Qt 6.3->6.5: default is Unicode digits, env var to control
* Qt 6.6->6.x: default is ASCII digits, env var to control
* Qt 7: only ASCII digits, no env var

[1] That's the name Unicode gives to them, cf. https://www.unicode.org/charts/PDF/U0000.pdf

[ChangeLog][QtCore][Deprecation Notices] The arg() functions
featured in Qt string classes have always been documented to require
replacements tokens to be sequences of ASCII digits (like %1, %2, %34,
and so on). A coding oversight made it accept sequences of arbitrary
characters with a Unicode digit value instead. For instance, "%2੩" is
interpreted as the 23rd substitution; and "%1²" is interpreted as the
12th substitution. This behavior is deprecated, and will result in
runtime warnings. Starting from Qt 6.6, arg()'s behavior will be changed
to accept only ASCII digits by default. That means that "%1²" is going
to be interpreted as substitution number 1 followed by the "²" character
(which does not get substituted, so it gets left as-is in the result).
Users can restore the previous semantics (accept Unicode digits) by
setting the QT_USE_UNICODE_DIGIT_VALUES_IN_STRING_ARG environment
variable to a non-zero value. In Qt 7, arg() will only support sequences
of ASCII digits. Note that from Qt 6.3 users can also set
QT_USE_UNICODE_DIGIT_VALUES_IN_STRING_ARG to zero; this will make arg()
use ASCII digits only, in preparation for the future change of defaults.

Change-Id: I8a044b629bcca6996e76018c9faf7c6748ae04e8
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2021-11-30 19:33:34 +02:00
Janne Juntunen
2bfa4b9960 QNX: check and use elf.h from alternative location
In QNX, instead of #include <elf.h>, we have to use #include <sys/elf.h>
since that file is placed in a subdirectory.

Also removed the previous workaround.

Fixes: QTBUG-97833
Change-Id: Id932a5eeb618a42c8778459cdfd8bb5bf903523c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2021-11-30 14:37:52 +02:00
Mårten Nordheim
4c930e9d13 QNAM: Disable h2c by default
And since it's relatively unlikely to be used, just leave it
behind a environment variable for now.

[ChangeLog][QtNetwork][Potentially Source-Incompatible] Support for
clear-text http/2 was disabled due to incompatibility with certain
servers. If you were relying on this feature you must re-enable it by
setting the QT_NETWORK_ALLOW_H2C environment variable. For a later
version of Qt it will get a dedicated attribute.

Pick-to: 6.2
Task-number: QTBUG-98642
Change-Id: Id3e360726e285b3128e3e3f4bce9440404c9ad6e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2021-11-30 00:04:38 +01:00
Marc Mutz
8568a6386c Check that QStringView::split() w/rvalue QRegularExpression returns valid data
This test currently passes in Qt 6, but fails in Qt 5.15, thus the
QT_VERSION check.

Pick-to: 6.2 5.15
Task-number: QTBUG-98653
Change-Id: I3c7b9bc7ef74f605ff63768b38c473296274d0de
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2021-11-29 20:04:38 +00:00