Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qstylefactory.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
6#include "qstyleplugin.h"
7#include "private/qfactoryloader_p.h"
8#include "qmutex.h"
9
10#include "qapplication.h"
12#if QT_CONFIG(style_fusion)
13#include "qfusionstyle_p.h"
14#endif
15
16QT_BEGIN_NAMESPACE
17
18using namespace Qt::StringLiterals;
19
20Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
21 (QStyleFactoryInterface_iid, "/styles"_L1, Qt::CaseInsensitive))
22
23/*!
24 \class QStyleFactory
25 \brief The QStyleFactory class creates QStyle objects.
26
27 \ingroup appearance
28 \inmodule QtWidgets
29
30 The QStyle class is an abstract base class that encapsulates the
31 look and feel of a GUI. QStyleFactory creates a QStyle object
32 using the create() function and a key identifying the style. The
33 styles are either built-in or dynamically loaded from a style
34 plugin (see QStylePlugin).
35
36 The valid keys can be retrieved using the keys()
37 function. Typically they include "windows" and "fusion".
38 Depending on the platform, "windowsvista"
39 and "macos" may be available.
40 Note that keys are case insensitive.
41
42 \sa QStyle
43*/
44
45/*!
46 Creates and returns a QStyle object that matches the given \a key, or
47 returns \nullptr if no matching style is found.
48
49 Both built-in styles and styles from style plugins are queried for a
50 matching style.
51
52 \note The keys used are case insensitive.
53
54 \sa keys()
55*/
56QStyle *QStyleFactory::create(const QString& key)
57{
58 QStyle *ret = nullptr;
59 QString style = key.toLower();
60#if QT_CONFIG(style_windows)
61 if (style == "windows"_L1)
62 ret = new QWindowsStyle;
63 else
64#endif
65#if QT_CONFIG(style_fusion)
66 if (style == "fusion"_L1)
67 ret = new QFusionStyle;
68 else
69#endif
70#if defined(Q_OS_MACOS) && QT_DEPRECATED_SINCE(6, 0)
71 if (style == "macintosh"_L1) {
72 qWarning() << "The style key 'macintosh' is deprecated. Please use 'macos' instead.";
73 style = QStringLiteral("macos");
74 } else
75#endif
76 { } // Keep these here - they make the #ifdefery above work
77 if (!ret)
78 ret = qLoadPlugin<QStyle, QStylePlugin>(loader(), style);
79 if (ret) {
80 ret->setObjectName(style);
81 ret->setName(style);
82 }
83 return ret;
84}
85
86/*!
87 Returns the list of valid keys, i.e. the keys this factory can
88 create styles for.
89
90 \sa create()
91*/
92QStringList QStyleFactory::keys()
93{
94 QStringList list;
95 typedef QMultiMap<int, QString> PluginKeyMap;
96
97 const PluginKeyMap keyMap = loader()->keyMap();
98 const PluginKeyMap::const_iterator cend = keyMap.constEnd();
99 for (PluginKeyMap::const_iterator it = keyMap.constBegin(); it != cend; ++it)
100 list.append(it.value());
101#if QT_CONFIG(style_windows)
102 if (!list.contains("Windows"_L1))
103 list << "Windows"_L1;
104#endif
105#if QT_CONFIG(style_fusion)
106 if (!list.contains("Fusion"_L1))
107 list << "Fusion"_L1;
108#endif
109 return list;
110}
111
112QT_END_NAMESPACE
Q_GLOBAL_STATIC_WITH_ARGS(PermissionStatusHash, g_permissionStatusHash,({ { qMetaTypeId< QCameraPermission >(), Qt::PermissionStatus::Undetermined }, { qMetaTypeId< QMicrophonePermission >(), Qt::PermissionStatus::Undetermined }, { qMetaTypeId< QBluetoothPermission >(), Qt::PermissionStatus::Undetermined }, { qMetaTypeId< QContactsPermission >(), Qt::PermissionStatus::Undetermined }, { qMetaTypeId< QCalendarPermission >(), Qt::PermissionStatus::Undetermined }, { qMetaTypeId< QLocationPermission >(), Qt::PermissionStatus::Undetermined } }))
#define QStyleFactoryInterface_iid