Commit Graph

13224 Commits

Author SHA1 Message Date
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
Marc Mutz
ccaeffe565 QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH: use unqualified qHash() lookup
... instead of QT_PREPEND_NAMESPACE(qHash), which is qualified (prepends at least '::'), and therefore disables ADL.

This is not a problem as long as we wrote our qHash() overloads as free functions (incl. non-hidden friends), but it should™ fail for hidden friends, so use the old using-std::swap() trick to bring QT_PREPEND_NAMESPACE(qHash) into scope, proceeding with an unqualified lookup.

Pick-to: 6.2
Change-Id: I00860b2313699849f86bfe3dd9f41db4ce993cd3
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2021-11-29 18:55:10 +00:00
Volker Hilsheimer
56da533b45 Never handle scrollbars styled with box or border changes as transient
If scrollbars are styled with a style sheet that includes a box or
removes off the native border, then we never treat them as transient or
overlapping. Otherwise, the layout logic in QAbstractScrollArea will
show them on top of the viewport, overlapping the content.

Add case to the style sheet test baseline test. It's a test for
scrollbars in a scroll area, rather than a test for the styling of the
scrollbars themselves.

Fixes: QTBUG-98289
Pick-to: 6.2
Change-Id: Ic53ad248b3eedd54722ac7b2fe5256a27092dbc1
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
2021-11-29 16:02:28 +01:00
Eirik Aavitsland
8fbedf2196 QTextDocument: fix an off-by-one in the changed signal for lists
When blocks are added or removed in block groups, i.e. items added or
removed from text lists, the whole group is marked as changed, but the
calculation of the before/after group length would be one off. That
was reflected in the contentsChange signal.

Add unit test. Since the whole group changes when list items are
added, text is removed and the change-begin is not where the cursor
was when the change was made.

Fixes: QTBUG-82455
Pick-to: 6.2 5.15
Change-Id: I99ee2cfef4944fcac8aca492741fd0f3b0de4920
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2021-11-29 13:25:31 +01:00
Oliver Wolff
a892a7b2ca Shorten target name for qsortfilterproxymodel auto tests
These long target names can quickly lead to exceeding Windows' max path
length.

Pick-to: 6.2
Change-Id: Ibd77e53464a71221f9302d490afbe9c41c16646d
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-11-29 08:08:21 +01:00
Thiago Macieira
0e72a846d3 QObject: Q_ASSERT the object type before calling a PMF
The old-syle signal-slot syntax had the advantage of not delivering
signals to slots in derived classes after that derived class's
destructor had finished running (because we called via the virtual
qt_metacall). The new syntax made no checks, so a conversion from the
old to the new syntax may introduce crashes or other data corruptions at
runtime if the destructor had completed.

This commit introduces a Q_ASSERT to print the class name that the
object is not any more. Since this is in inline code, this should get
enabled for users' debug modes and does not therefore depend on Qt being
built in debug mode.

It required some Private classes to be adapted to the new form, by
exposing the public q_func() in the public: part.

Pick-to: 6.2
Fixes: QTBUG-33908
Change-Id: Iccb47e5527544b6fbd75fffd16b874cdc08c1f3e
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
2021-11-27 21:38:22 -08:00
Marc Mutz
a0f9aef11b Long live Q_GADGET_EXPORT!
Like Q_NAMESPACE_EXPORT for Q_NAMESPACE, this variant of Q_GADGET
allows passing an export macro. This is useful to avoid exporting the
whole class just to get the staticMetaObject hidden therein exported.

Before anyone asks: No, we don't need Q_OBJECT_EXPORT, because QObject
subclasses, being polymorphic, always need to have a class-level
export macro (to export their vtable), but while that technique also
works for value classes (the Q_GADGET audience), it is not desirable
for them, because it makes inline functions exported in Windows debug
builds, which is not what we want, because it needlessly restricts
what you can to with the inline functions (e.g. remove).

[ChangeLog][QtCore] Added the Q_GADGET_EXPORT macro, which is like
Q_GADGET, but allows passing an export macro (like Q_NAMESPACE_EXPORT
for Q_NAMESPACE).

Fixes: QTBUG-55458
Change-Id: I546297de1e8aa45d83381991bcd3fbca61e1eef0
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2021-11-27 01:25:10 +01:00
Laszlo Agocs
5a496a614b rhi: Add a more sophisticated resource update autotest case
This time exercising series of buffer updates and texture uploads
within proper, on-screen frames. (particularly interesting for dynamic
buffers in case the double (or more) buffering and having multiple
frames in flight involves special bookkeeping for these - using
'offscreen' frames like in other test cases does not necessarily
exercise all of this)

Change-Id: Id470919d27037359a1f0346a50a2a0e3966f5cd2
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2021-11-27 00:19:27 +01:00
Marc Mutz
6f6aa316f1 tst_qhashfunctions: check qHashRange{,Commutative}() find hidden friend qHash()
... extending the existing check for ADL-found qHash()
implementations.

Pick-to: 6.2 5.15
Change-Id: Iac6ed2721db9e95ee921bd1d5170fa8c8d43475d
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-11-26 22:42:40 +01:00
Volker Hilsheimer
969cd432f5 Share common code for baseline-testing widget UIs
Setting up the baseline tests, creating an appearance identifier,
and basic image-grabbing functionality doesn't need to be reinvented
for each test case that wants to use baseline testing of widget UIs.

As a drive-by, remove unneeded Qt 5 meta tags from .pri file.

Change-Id: I1562e1b377946305cac018e0f0f0175c2c07cd31
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2021-11-26 22:40:54 +01:00
Marc Mutz
ed343669f7 Long live QVERIFY_THROWS_NO_EXCEPTION!
Counter-part to QVERIFY_THROWS_EXCEPTION.

[ChangeLog][QTest] Added QVERIFY_THROWS_NO_EXCEPTION macro.

Change-Id: Ib6a80c8e810d5e2298ff00d608dae04e7a0c3e8f
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2021-11-26 18:28:50 +01:00
Marc Mutz
6a1a936537 QWaitCondition: also benchmark std::condition_variable{,_any}
Results on my machine (only forever results):

********* Start testing of tst_QWaitCondition *********
Config: Using QtTest library 6.3.0, Qt 6.3.0 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 11.2.1 20211115), ubuntu 20.04
PASS   : tst_QWaitCondition::oscillate_QWaitCondition_QMutex(forever)
RESULT : tst_QWaitCondition::oscillate_QWaitCondition_QMutex():"forever":
     637 msecs per iteration (total: 637, iterations: 1)
PASS   : tst_QWaitCondition::oscillate_QWaitCondition_QReadWriteLock(forever)
RESULT : tst_QWaitCondition::oscillate_QWaitCondition_QReadWriteLock():"forever":
     909 msecs per iteration (total: 909, iterations: 1)
PASS   : tst_QWaitCondition::oscillate_std_condition_variable_std_mutex(forever)
RESULT : tst_QWaitCondition::oscillate_std_condition_variable_std_mutex():"forever":
     331 msecs per iteration (total: 331, iterations: 1)
PASS   : tst_QWaitCondition::oscillate_std_condition_variable_any_QMutex(forever)
RESULT : tst_QWaitCondition::oscillate_std_condition_variable_any_QMutex():"forever":
     627 msecs per iteration (total: 627, iterations: 1)
PASS   : tst_QWaitCondition::oscillate_std_condition_variable_any_QReadWriteLock(forever)
RESULT : tst_QWaitCondition::oscillate_std_condition_variable_any_QReadWriteLock():"forever":
     913 msecs per iteration (total: 913, iterations: 1)

~331 vs. ~630ms. A pretty significant win (2x).

Mårten noticed that on Windows, condition_variable::wait_for(x, 0ms)
will not unlock the mutex, which, however, the program requires, so
use a 1ns timeout instead.

Drive-by fixes:
- add override to run() reimplementations
- fix type of timeout member variable (was int, should be unsigned long)
- fix naming of test functions to distinguish better between QMutex
  and std::mutex

Change-Id: Ib92310f15fbd58258b2043504642be5f0b860f39
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2021-11-26 18:28:50 +01:00
Luca Beldi
c27d2a57a4 Make QAbstractProxyModel itemData() behave like data()
QAbstractProxyModel::itemData/setItemData should behave
just like data()/setData() instead of calling the
QAbstractItemModel implementation.
Before this change the QAbstractProxyModel implementation
calls its the QAbstractItemModel implementation,
which ends up calling data()/setData() in a loop
bypassing the convenience of itemData/setItemData.

[ChangeLog][QtCore][QAbstractProxyModel] The itemData()
and setItemData() functions will now call the respective
implementations in the source model (after mapping the
index to a source index), matching what data() and
setData() already did.
Before, the proxy model simply called the default
implementations of itemData()/setItemData() in its own
base class (QAbstractItemModel).

Change-Id: I9e680d355f44fa130660dd7e1c8ac37484c1566e
Reviewed-by: David Faure <david.faure@kdab.com>
2021-11-26 17:12:07 +00:00
Volker Hilsheimer
24022bc760 Stabilize tst_QAccessibilityMac
Introduce a TRY_EXPECT macro that uses qWaitFor, and use it whenever
EXPECT was used after a call to processEvents.

Fixes: QTBUG-94036
Pick-to: 6.2 5.15
Change-Id: Ia935444d529c2798637bf9b4a56e47a8dc9d75d2
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2021-11-26 14:22:05 +01:00
Marc Mutz
59600a514b QTest: de-inline QVERIFY_THROWS_EXCEPTION message formatting
Extract Method QTest::qCaught() to take the string handling out of the
header. This should help a bit in speeding up compilation of large
unit test files (provided they use QVERIFY_THROWS_EXCEPTION), although
I have no data to support that.

Since we changed the error message, update the selftest accordingly.

Change-Id: Id4a3c8c34d5df8d0c7a861106d269097f4a6de5c
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2021-11-26 09:57:59 +01:00
Volker Hilsheimer
77de4a9bb4 Fix and complete style sheet support for QToolButton
Amends 2b2e7b2ac5, which rewrote the
rendering to remove the conflation of menu arrows and arrow icons, but
introduced double rendering of the arrow icons if only the border was
styled.

Add a baseline test for style sheets, with a test function for
QToolButton configured in various ways and styled with different style
sheets.
The new test case includes a Qt 5 build system so that we can compare Qt
5.15 with Qt 6.

Fixes: QTBUG-98286
Pick-to: 6.2 6.2.2
Change-Id: I09cdc829c1a7e7913df4c3768dbe44b6dba4778b
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2021-11-26 09:36:07 +01:00
Mitch Curtis
efb283fb7f Add QTest::failOnWarning
This solves the long-standing problem of not being able to easily
fail a test when a certain warning is output.

[ChangeLog][QtTest] Added QTest::failOnWarning. When called in a test
function, any warning that matches the given pattern will cause a test
failure. The test will continue execution when a failure is added.
All patterns are cleared at the end of each test function.

Fixes: QTBUG-70029
Change-Id: I5763f8d4acf1cee8178be43a503619fbfb0f4f36
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2021-11-26 04:47:24 +01:00
Marc Mutz
1edf153a6b Long live QVERIFY_THROWS_EXCEPTION!
Use variable args macros to swallow any extra commas in the
expression. To use this, the type of the exception has to be first.
Use Eddy's suggestion for a new name to avoid breaking the old macro.

[ChangeLog][QtTest] Added QVERIFY_THROWS_EXCEPTION, replacing
QVERIFY_EXCEPTION_THROWN, which has therefore been deprecated.

Change-Id: I16825c35bae0631c5fad5a9a3ace4d6edc067f83
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2021-11-26 04:44:26 +01:00
Ievgenii Meshcheriakov
174af05400 QDir: Add support for setting directory permissions to mkdir()
This patch adds an overload of the QDir::mkdir() method that
accepts permissions. This allows setting of the directory
permissions at the time of its creation.

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

Task-number: QTBUG-79750
Change-Id: Ic9db723b94ff0d2da6e0b819ac2e5d1f9a4e2049
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2021-11-26 03:39:33 +01:00
Giuseppe D'Angelo
8c9875893b Q(Multi)Map: prevent dangling key/value after detach()
Q(Multi)Map mutating functions that take reference to a key and/or a
value (e.g. insert(), take(), etc.) must make sure that those references
are still valid -- that is, that the referred objects are still alive --
after the detach() call done inside those functions.

In fact, if the key/value are references into *this, one must take extra
steps in order to preserve them across the detach().

Consider the scenario where one has two shallow copies of QMap, each
accessed by a different thread, and each thread calls a mutating
function on its copy, using a reference into the map (e.g.
map.take(map.firstKey())). Let's call the shared payload of this QMap
SP, with its refcount of 2; it's important to note that the argument
(call it A) passed to the mutating function belongs to SP.

Each thread may then find the reference count to be different than 1 and
therefore do a detach() from inside the mutating function. Then this
could happen:

Thread 1:                         Thread 2:

detach()                          detach()
  SP refcount != 1 => true          SP refcount != 1 => true
    deep copy from SP                 deep copy from SP
    ref() the new copy                ref() the new copy
  SP.deref() => 1 => don't dealloc SP
  set the new copy as payload
                                    SP.deref() => 0 => dealloc SP
                                    set the new copy as payload

  use A to access the new copy      use A to access the new copy

The order of ref()/deref() SP and the new copy in each thread doesn't
really matter here. What really matters is that SP has been destroyed
and that means A is a danging reference.

Fix this by keeping SP alive in the mutating functions before doing a
detach(). This can simply be realized by taking a local copy of the map
from within such functions.

remove() doesn't suffer from this because its implementation doesn't do
a bare detach() but something slightly smarter.

Change-Id: Iad974a1ad1bd5ee5d1e9378ae90947bef737b6bb
Pick-to: 6.2
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2021-11-26 02:14:52 +01:00
Edward Welbourne
7039fb1e42 Skip QTimeZone::checkOffset() if there are no valid zones to test
Change-Id: I62df34fe40b8e89b99912e8ad0d1d2f2f11fd71e
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2021-11-26 02:14:52 +01:00
Edward Welbourne
bcc15f36cc Check for relevant zones existing when adding data rows
tst_QDate::startOfDay_endOfDay_data() naively assumed some zones would
exist. They don't on QNX, apparently.

Change-Id: I3a364964d03f59f5869b4b7639f089dd303180b1
Reviewed-by: Andreas Buhr <andreas.buhr@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2021-11-26 02:14:52 +01:00
Edward Welbourne
0cad974d0d Add a note to save the next reader some confusion
I was briefly confused about why an Etc/GMT+3 test was using GMT as
localtime. Fortunately I worked it out before mis-"correcting" it.

Change-Id: I7b0473c7d3974ef186e1170cf4999aca52aaaf45
Reviewed-by: Andreas Buhr <andreas.buhr@qt.io>
2021-11-26 02:14:52 +01:00
Edward Welbourne
6437bd240f Skip test if it has no data-rows
On QNX, tst_QDateTime::fromStringStringFormat_localTimeZone_data()
failed to set up any rows for the data-driven tests to fetch, leading
to an assertion failure on trying to fetch a row.

Change-Id: I7c405b1142a8cb6d445b501ea44fe3d440570cf3
Reviewed-by: Andreas Buhr <andreas.buhr@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2021-11-26 02:14:52 +01:00
Marc Mutz
f4e89d58da QVERIFY_EXCEPTION_THROWN: re-throw unknown exceptions
Swallowing unknown exceptions is dangerous business, as the exception
might be a pthread cancellation token, the swallowing of which would
terminate the program.

Instead of returning from the catch-all-clause, therefore, re-throw
the unknown exception.

Fix tst_verifyexceptionthrown failure cases that use
non-std::exception-derived true negative exceptions to not let the
exception escape from the test function.

As a drive-by, pretty up the macro's docs.

[ChangeLog][QtTest][QVERIFY_EXCEPTION_THROWN] Now re-throws unknown
exceptions (= not derived from std::exception) (was: swallowed them
and returned from the test function), in order to play nice with
pthread cancellation.

Pick-to: 6.2 5.15
Change-Id: Ic036d4a9ed4b7683fa67e27af8bcbae0eefdd0da
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2021-11-25 13:00:55 +01:00
Fabian Kosmale
925ad78024 tst_qmetatype: Temporarily disable expensive tests on QNX
The compiler runs out of memory and fails to compile tst_qmetatype.cpp.
Set TST_QMETATYPE_BROKEN_COMPILER from a previous compiler workaround
for QNX to disable the most expensive part of the test.

Task-number: QTQAINFRA-4669
Change-Id: I3a99b6b790dc074e9d1db262e758555fb45e4331
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2021-11-25 09:53:34 +01:00