qt5base-lts/examples
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
..
aggregate
corelib High-DPI: Remove usage of Qt::AA_EnableHighDpiScaling 2020-08-28 20:08:43 +02:00
dbus CMake: Workaround building DBus 'car' example with qmake 2020-08-23 11:04:04 +02:00
embedded Port the QXmlStream API from QStringRef to QStringView 2020-08-19 19:48:03 +02:00
gui CMake: Regenerate examples 2020-07-09 09:38:28 +02:00
network QAbstractSocket: Resolve remaining Qt6 TODOs 2020-08-24 17:43:56 +02:00
opengl CMake: Regenerate examples 2020-07-09 09:38:28 +02:00
qmake Add cmdline feature to qmake 2019-02-18 07:12:14 +00:00
qpa CMake: Regenerate examples 2020-07-09 09:38:28 +02:00
qtconcurrent CMake: Regenerate examples 2020-07-09 09:38:28 +02:00
qtestlib Don't depend on tools for the qtestlib examples 2020-08-12 19:37:15 +02:00
sql Deprecate the static int based API in QMetaType 2020-08-24 00:19:05 +02:00
vulkan Fix compiler warning about qsizetype/int mismatch 2020-08-04 13:28:33 +02:00
widgets Long live QKeyCombination! 2020-09-03 07:00:31 +02:00
xml Port the QXmlStream API from QStringRef to QStringView 2020-08-19 19:48:03 +02:00
CMakeLists.txt CMake: Regenerate examples 2020-07-09 09:38:28 +02:00
examples.pro Doc: Move touch examples around so they get included in docs 2018-09-14 03:56:22 +00:00
README

Qt is supplied with a number of example applications that have been
written to provide developers with examples of the Qt API in use,
highlight good programming practice, and showcase features found in each of
Qt's core technologies.


Documentation for examples can be found in the Examples section
of the Qt documentation.