Commit Graph

165 Commits

Author SHA1 Message Date
Kai Köhne
d221ea609f Examples: Remove duplicated Qt6::PrintSupport link information
Some CMakeLists.txt files did link to Qt6::PrintSupport twice. Also
unify formatting and order of the linker step.

Change-Id: I4af935c5dc3de6c243aad8511b0803ceaa872589
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-11-30 14:48:50 +01:00
Kai Köhne
f562711c64 Examples: Use qt_standard_project_setup()
Change-Id: I0ceab08108b7e58e4e2ed25db9e3c289f5c0ddac
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-11-17 19:59:11 +01:00
Kai Köhne
bec264c15f Examples: Use Qt6:: to qualify Qt CMake packages
This is what we promote also in the documentation.

Change-Id: If91aebafe861b0c934acbb2c69afd182abc3345d
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-11-17 19:59:11 +01:00
Marc Mutz
aa37e67ef7 Port from qAsConst() to std::as_const()
We've been requiring C++17 since Qt 6.0, and our qAsConst use finally
starts to bother us (QTBUG-99313), so time to port away from it
now.

Since qAsConst has exactly the same semantics as std::as_const (down
to rvalue treatment, constexpr'ness and noexcept'ness), there's really
nothing more to it than a global search-and-replace, with manual
unstaging of the actual definition and documentation in dist/,
src/corelib/doc/ and src/corelib/global/.

Task-number: QTBUG-99313
Change-Id: I4c7114444a325ad4e62d0fcbfd347d2bbfb21541
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2022-10-11 23:17:18 +02:00
Lucie Gérard
32df595275 Change the license of all CMakeLists.txt and *.cmake files to BSD
Task-number: QTBUG-105718
Change-Id: I5d3ef70a31235868b9be6cb479b7621bf2a8ba39
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-08-23 23:58:42 +02:00
Lucie Gérard
fb1b20eab3 Add license headers to cmake files
CMakeLists.txt and .cmake files of significant size
(more than 2 lines according to our check in tst_license.pl)
now have the copyright and license header.

Existing copyright statements remain intact

Task-number: QTBUG-88621
Change-Id: I3b98cdc55ead806ec81ce09af9271f9b95af97fa
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-08-03 17:14:55 +02:00
Kai Köhne
65d9593413 Examples: Use signals, slots instead of Q_SIGNALS, Q_SLOTS
Pick-to: 6.4
Change-Id: I79a352d1bac11edf2d2b0443d2f1bb202fb4e254
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-07-21 11:24:36 +02:00
Ivan Solovev
7d2361b9da Addressbook example: port to QLatin1StringView
This allows to fix the warning:
 qtbase/examples/widgets/itemviews/addressbook/addresswidget.cpp:115:
  warning: loop variable ‘str’ of type ‘const QString&’ binds to a
  temporary constructed from type ‘const char* const’
  [-Wrange-loop-construct]

Pick-to: 6.4
Change-Id: Ibbfa7f9e85fe9ef79291f9da3d161667286b282e
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
2022-07-15 14:44:38 +02:00
Lucie Gérard
05fc3aef53 Use SPDX license identifiers
Replace the current license disclaimer in files by
a SPDX-License-Identifier.
Files that have to be modified by hand are modified.
License files are organized under LICENSES directory.

Task-number: QTBUG-67283
Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-05-16 16:37:38 +02:00
Kai Köhne
57402ffb9b Examples: Remove unneeded CMake options
CMAKE_INCLUDE_CURRENT_DIR is not necessary anymore for moc since
CMake 3.8: https://cmake.org/cmake/help/latest/release/3.8.html#other-changes

CMAKE_AUTORCC should not be used anymore. Instead, we now use
qt_add_resources() or similar

Enable CMAKE_AUTOUIC only if .ui files are present.

Pick-to: 6.3
Task-number: QTBUG-87643
Change-Id: I835e2994cd5dba9918136999499b9077961b616c
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-01-24 14:00:00 +01:00
Kai Köhne
80a76df178 Examples: Fix whitespace issues in CMakeLists.txt
Pick-to: 6.3
Change-Id: I8e6dd1f250f8be6016ee4164cb2ab7034cbb1203
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-12-13 14:16:26 +00:00
Kai Köhne
51f22a3a04 Examples: Remove remaining conversion markers in CMakeLists.txt
Pick-to: 6.3
Change-Id: Ia5d474a3efd6aadbd0ef1537318f2f24e6c24fee
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-12-13 14:16:26 +00:00
Kai Köhne
28a9d116bb CMake: Prefer unversioned commands
Pick-to: 6.3
Change-Id: Ib32700ab82cf6b271c49e25d12fbad8c9c6bc1d1
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-12-13 14:16:25 +00:00
Kai Köhne
7024e7a627 Examples: Use find_package(Qt6 REQUIRED COMPONENTS ...) idiom
Also consolidate several find_package(Qt6 ...) calls in one call.

Task-number: QTBUG-98867
Change-Id: Idfd5e71f46d4489fac7411cbfadb84437a0658f3
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2021-12-10 10:48:26 +01:00
Kai Köhne
251e848007 Remove .prev_CMakeLists.txt
These are left-overs from the initial qmake2cmake conversion.

Pick-to: 6.2
Change-Id: Ie15c9ff022ea4566d10c1ba74599de9af83d29a7
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-12-06 11:23:26 +00:00
Tang Haixiang
f5eda09a63 Modify the target Square in the puzzle
targetSquare judges which square the position falls in. The point
scaling calculation method should not be used. The return value of
QPoint operator/ will be rounded up. Modified to separate the x and
y of position to calculate.

Fixes: QTBUG-81842
Change-Id: I70375185a78ba47efe01be3fd490e0fb0f456e17
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2021-11-03 01:10:32 +00:00
Joerg Bornemann
ff00ef6410 Raise cmake_minimum_required to VERSION 3.16 in examples
Pick-to: 6.2
Task-number: QTBUG-95636
Change-Id: I1270b4846d8a23bc3563b6942c0910e095d2be4a
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-08-17 19:18:54 +02:00
Marc Mutz
0e02f6536a Port all in-tree addAction() users from postfix to infix QKeySequence
The former is QT_DEPRECATED_SINCE(6, 4).

Change-Id: I9e60639651b0832f1e3d3282d15dd0ab0b22d819
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
2021-07-14 00:46:49 +02:00
Craig Scott
d97fd7af2b Build examples in isolated sub-builds using ExternalProject
Examples are intended to show how to build against an installed Qt.
Building them as part of the main build means the way the Qt targets
are defined and created are not representative of an end user's build.
By building them as separate projects using ExternalProject, we can
more closely replicate the intended audience's environment. This
should allow us to catch more problems earlier.

Having examples built as part of the main build also creates problems
with some static builds where a tool built by the main build is needed
during configure time. This happens with other repos like qtdeclarative
but not (currently) with qtbase. Converting the examples in qtbase to
be built using ExternalProject is intended as a demonstrator for how
other repos can do similar. Until other repos are converted, they will
continue to work as they did before, with examples as part of the main
build for non-static builds only.

The new build-externally behavior is only supported for non-prefix
builds with this change. Prefix builds will continue to use the old
non-external method. Support for building examples externally in
prefix builds will be a separate change.

Task-number: QTBUG-90820
Fixes: QTBUG-91068
Change-Id: I2304329940568dbdb7da18d54d5595ea7d8668bc
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-05-26 13:33:29 +02:00
Friedemann Kleint
2393a40ccd Rewrite the fetchmore example
- Start in root folder so that large directories (/bin/, Windows)
  are easily reachable
- Remove the line edit and navigate by double clicking instead
  since this is more in line with expectations
- Use a QPlainTextEdit for logging
- Make the log message more informative
- Add icons

Change-Id: Ia3cd7fc143efef80772923291f0b711913aa47be
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
2021-04-23 12:43:28 +00:00
Samuel Gaist
e65558c230 Fix Editable Tree Model example model rowCount and model instance leak
The rowCount method has been fixed to correctly pass the "Common error
test #3: the second column should NOT have the same children".

It also fixes the model being leaked.

Fixes: QTBUG-92178
Pick-to: 5.15
Change-Id: If92973e6f83ea9a2715bd335269f6e50d80f52c6
Reviewed-by: Luca Beldi <v.ronin@yahoo.it>
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
2021-03-29 12:09:41 +01:00
Friedemann Kleint
060fceb2ab dirview example: Show file icons on Windows
Use QFileIconProvider from QtWidgets.

Pick-to: 6.0
Task-number: QTBUG-66177
Change-Id: I22db2f8671c64d90c45ff7160af9a6925d1cecea
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2021-02-13 10:37:54 +01:00
Allan Sandfeld Jensen
b26fa9722f Add multi key bindings to QShortcut
This makes it feature comparable with QAction, and makes it possible
to use as a backend for QAction, and fixes a few missing alternative
keybindings in qtwidgets.

Change-Id: Iaefc630b96c4743fc5ef429dc841870ddd99fc64
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2020-11-04 10:32:38 +02:00
Alexandru Croitor
397b372517 CMake: Regenerate examples to set the WIN32_EXECUTABLE property
As well as the MACOSX_BUNDLE properties as necessary.

Task-number: QTBUG-87664
Task-number: QTBUG-86827
Change-Id: I7677449a26d51fa853bd67bab6b3b61afbd2b12f
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2020-10-27 12:49:39 +01:00
Alexandru Croitor
2ffbac7cb2 CMake: Regenerate examples to use qt_add_executable
Task-number: QTBUG-87661
Change-Id: I0dacfdc97a3fb7d88da85b67800f2c1b084d869b
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2020-10-19 11:51:47 +02:00
Friedemann Kleint
d55940d7f6 Brush up the basicsortfiltermodel example
- Add a clear button to the line edit
- Indicate invalid regular expressions

Change-Id: I1dbeaa0f9168224ccb9134c0c1fe281da14dcbce
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2020-10-14 20:35:16 +02:00
Shawn Rutledge
b0cd3bcec4 Use QScroller in the Dir View example
We have never had enough examples that show how easy it is to install
a QScroller.  In this case, one line makes a QTreeView flickable.

Pick-to: 5.15
Task-number: QTBUG-86090
Change-Id: Idb8b4709617befb261f3b78d63ddbdaf5ad18d6b
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
2020-10-14 18:29:00 +00:00
Allan Sandfeld Jensen
564b59d903 Another round of replacing 0 with nullptr
This time based on grepping to also include documentation, tests and
examples previously missed by the automatic tool.

Change-Id: Ied1703f4bcc470fbc275f759ed5b7c588a5c4e9f
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
2020-10-07 23:02:47 +02:00
Lars Knoll
557623cc4f Rename QLibraryInfo::location() to path()
As per ### Qt6 comment. Also rename the LibraryLocation enum
to LibraryPath.

Change-Id: I556025a19c5bcdf2ff52598eaba32269522d4128
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2020-09-12 23:35:56 +02:00
Volker Hilsheimer
00a5629d8d Remove deprecated QPrinter and QPagedPaintDevice APIs
Adjusting the QPrinter test case - some use cases no longer exist, or are
already tested in QPageSize and QPageLayout tests.

Adjust examples and manual tests.

Change-Id: I01cbc65f3d8031aea2dac86dd942126ba708b111
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2020-09-04 08:37:59 +02:00
Giuseppe D'Angelo
25351dcc54 Long live QKeyCombination!
C++20 via P1120 is deprecating arithmetic operations between
unrelated enumeration types, and GCC 10 is already complaining.
Hence, these operations might become illegal in C++23 or C++26 at
the latest.

A case of this that affects Qt is in key combinations: a
QKeySequence can be constructed by summing / ORing modifiers and a
key, for instance:

  Qt::CTRL + Qt::Key_A
  Qt::SHIFT | Qt::CTRL | Qt::Key_G (recommended, see below)

The problem is that the modifiers and the key belong to different
enumerations (and there's 2 enumerations for the modifier, and one
for the key).

To solve this: add a dedicated class to represent a combination of
keys, and operators between those enumerations to build instances
of this class.

I would've simply defined operator|, but again docs and pre-existing
code use operator+ as well, so added both to at least tackle simple
cases (modifier + key).

Multiple modifiers create a problem: operator+ between them yields
int, not the corresponding flags type (because operator+ is not
overloaded for this use case):

  Qt::CTRL + Qt::SHIFT + Qt::Key_A
  \__________________/      /
          int              /
           \______________/
                  int

Not only this loses track of the datatypes involved, but it would
also then "add" the key (with NO warnings, now its int + enum, so
it's not mixing enums!) and yielding int again.

I don't want to special-case this; the point of the class is
that int is the wrong datatype. Everything works just fine when
using operator| instead:

  Qt::CTRL | Qt::SHIFT | Qt::Key_A
  \__________________/      /
      Qt::Modifiers        /
           \______________/
            QKeyCombination

So I'm defining operator+ so that the simple cases still work,
but also deprecating it.

Port some code around Qt to the new class. In certain cases,
it's a huge win for clarity. In some others, I've just added
the necessary casts to make it still compile without warnings,
without attempting refactorings.

[ChangeLog][QtCore][QKeyCombination] New class to represent
a combination of a key and zero or more modifiers, to be used
when defining shortcuts or similar.

[ChangeLog][Potentially Source-Incompatible Changes] A keyboard
modifier (such as Qt::CTRL, Qt::AltModifier, etc.) should be
combined with a key (such as Qt::Key_A, Qt::Key_F1, etc.) by using
operator|, not operator+.  The result is now an object of type
QKeyCombination, that stores the key and the modifiers.

Change-Id: I657a3a328232f059023fff69c5031ee31cc91dd6
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2020-09-03 07:00:31 +02:00
Tor Arne Vestbø
dce106c77c High-DPI: Remove usage of Qt::AA_EnableHighDpiScaling
This attribute is now on by default.

Change-Id: I7c9d2e3445d204d3450758673048d514bc9c850c
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2020-08-28 20:08:43 +02:00
Volker Hilsheimer
c501e09efa Replace QAbstractItemView::viewOptions with initViewItemOption
viewOptions returned a QStyleOptionViewItem object. Such a method
can never support newer versions of the option structure.

Most styleable QWidget classes provide a virtual method
initStyleOption that initializes the option object passed in as a
pointer, e.g QFrame, QAbstractSpinBox, or QComboBox.

Follow that API convention, but name it initViewItemOption, as the
QStyleOptionViewItem struct contains information about the item as
well as the widget itelf.

This is a source incompatible change that will go unnoticed unless
existing subclasses mark their overrides as 'override', or call
the removed QAbstractItemView::viewOption virtual function.

[ChangeLog][QtWidgets][QAbstractItemView] The virtual viewOptions
method that previously returned a QStyleOptionViewItem object has
been renamed to initViewItemOption, and initializes a
QStyleOptionViewItem object that's passed in through a pointer.

Change-Id: Ie058702aed42d77274fa3c4abb43ba302e57e348
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
2020-08-26 18:02:58 +02:00
Lars Knoll
f741a12de1 Disentangle QIODevice dependencies
Move the QIODevice::OpenMode enum into a base class, so that
we can remove the full QIODevice (and thus QObject) dependency
from qdatastream.h and qtextstream.h.

This is required so that we can include QDataStream in qmetatype.h
without getting circular dependencies.

As a nice side effect, QDataStream and QTextStream can now inherit
QIODeviceBase and provide the OpenMode enum directly in their
class scope.

Change-Id: Ifa68b7b1d8d95687ed032f6c9206f92e63bfacdf
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
2020-08-15 20:55:31 +02:00
Alexandru Croitor
74cb331af3 CMake: Regenerate examples
Change-Id: I1c51b10af4e2b26f54740f257164c56a0e2a03ce
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2020-07-09 09:38:28 +02:00
Lars Schmertmann
6ce2f3f26b Add ; to Q_UNUSED
This is required to remove the ; from the macro with Qt 6.

Task-number: QTBUG-82978
Change-Id: I3f0b6717956ca8fa486bed9817b89dfa19f5e0e1
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
2020-07-07 11:51:48 +02:00
Jarek Kobus
29c99bddbf Use QList instead of QVector in examples
Task-number: QTBUG-84469
Change-Id: Id14119168bb1bf11f99bda7ef6ee9cf51bcfab2e
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
2020-06-23 14:01:11 +02:00
Shawn Rutledge
a061a64642 Replace calls to deprecated QEvent accessor functions
Many of these were generated by clazy using the new qevent-accessors check.

Change-Id: Ie17af17f50fdc9f47d7859d267c14568cc350fd0
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2020-06-08 19:11:51 +02:00
Sona Kurazyan
9b51d5f571 CMake: Regenerate examples/widgets/ projects
Also add the missing examples/widgets/gallery project.

Change-Id: Iec3d61881065cf93d90f9fd3da928ffcd4f0c0aa
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2020-04-29 22:48:38 +02:00
Marc Mutz
693c28b9fb examples: avoid int -> QChar conversions
They're being made explicit/deprecated/removed.

Change-Id: I61d8c40dc86035813b85724beb21a65b6f8dffef
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
2020-04-29 10:10:36 +02:00
Lars Knoll
48794f5057 Port example over to QRegularExpression
Change-Id: I1e15bfa0a2973aabcad78f3eba4bb4903f8f3f6f
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2020-04-15 14:38:23 +02:00
Lars Knoll
52d91508fd Convert the example to use QRegularExpression
Change-Id: I7a4259ac43e59a8f50ee1c5072a3da5b977d8bfe
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
2020-04-15 14:38:17 +02:00
Simon Hausmann
ff922e7b87 Merge remote-tracking branch 'origin/5.15' into dev
Conflicts:
	src/corelib/kernel/qmetatype.cpp

Change-Id: I88eb0d3e9c9a38abf7241a51e370c655ae74e38a
2020-03-16 18:41:27 +01:00
Qt Forward Merge Bot
116d68f105 Merge remote-tracking branch 'origin/5.14' into 5.15
Conflicts:
	src/corelib/plugin/qlibrary.cpp
	src/corelib/plugin/qlibrary_unix.cpp
	src/corelib/plugin/qpluginloader.cpp

Change-Id: I866feaaa2a4936ee5389679724c8471a5b4b583d
2020-03-11 11:27:49 +01:00
Oliver Wolff
7c7bd44669 examples: Fix build for configurations that do not have printsupport
printsupport features are only available if the module is available for
the configuration. Every printer feature check has to be coupled with a
check for the module itself.

Change-Id: Id2ca84e71d5d74463d0ff35e8b18b252a779a883
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
2020-03-05 15:11:36 +01:00
Lars Knoll
2a4b957789 Merge remote-tracking branch 'origin/5.15' into dev
Change-Id: I99ee6f8b4bdc372437ee60d1feab931487fe55c4
2020-03-04 14:39:18 +00:00
Assam Boudjelthia
e5f4e14059 Examples: enable HighDPI scaling for examples on Android
These examples show very tiny UI elements on Android devices,
thus enabling HighDPI.

Task-number: QTBUG-80717
Change-Id: I813801d5249dc1fcfc6f61a8d146f60dd19901f6
Reviewed-by: BogDan Vatra <bogdan@kdab.com>
2020-03-03 19:35:11 +02:00
Qt Forward Merge Bot
63312fe2ec Merge remote-tracking branch 'origin/5.15' into dev
Change-Id: If36d96c0fef3de5ab6503977501c55c62a2ecc97
2020-03-03 14:13:02 +01:00
Edward Welbourne
c158f881b3 Docs: Use Qt::SplitBehavior in preference to QString::SplitBehavior
The Qt version was added in 5.14 "for use as eventual replacement for
QString::SplitBehavior." Move another step closer to that goal.

Applied suitable wrapping round various char and string literals,
since docs are meant to show best practice.

Change-Id: Ie061905fad26f9b4dda3eedba4612704f0a19126
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2020-02-28 15:37:11 +01:00
Vitaly Fanaskov
3703a28511 QComboBox: remove currentIndexChanged(const QString&)
Fixes: QTBUG-81913
Task-number: QTBUG-81845
Change-Id: I8f24b858ce4e35b495440001d7734cc8f169cd5f
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2020-02-19 11:32:40 +00:00