Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qguivariant.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 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
4// Gui types
5#include "qbitmap.h"
6#include "qbrush.h"
7#include "qcolor.h"
8#include "qcolorspace.h"
9#include "qcursor.h"
10#include "qfont.h"
11#include "qimage.h"
12#if QT_CONFIG(shortcut)
13# include "qkeysequence.h"
14#endif
15#include "qtransform.h"
16#include "qpalette.h"
17#include "qpen.h"
18#include "qpixmap.h"
19#include "qpolygon.h"
20#include "qregion.h"
21#include "qtextformat.h"
22#include "qmatrix4x4.h"
23#include "qvector2d.h"
24#include "qvector3d.h"
25#include "qvector4d.h"
26#include "qquaternion.h"
27#include "qicon.h"
28
29// Core types
30#include "qvariant.h"
31#include "qbitarray.h"
32#include "qbytearray.h"
33#include "qdatastream.h"
34#include "qdebug.h"
35#include "qmap.h"
36#include "qdatetime.h"
37#include "qlist.h"
38#include "qstring.h"
39#include "qstringlist.h"
40#include "qurl.h"
41#include "qlocale.h"
42#include "quuid.h"
43
44#ifndef QT_NO_GEOM_VARIANT
45#include "qsize.h"
46#include "qpoint.h"
47#include "qrect.h"
48#include "qline.h"
49#endif
50
51#include <float.h>
52
53#include <private/qmetatype_p.h>
54
56
57namespace {
58
59// NOLINTNEXTLINE(cppcoreguidelines-virtual-class-destructor): this is not a base class
60static constexpr struct : QMetaTypeModuleHelper
61{
62#define QT_IMPL_METATYPEINTERFACE_GUI_TYPES(MetaTypeName, MetaTypeId, RealName) \
63 QT_METATYPE_INTERFACE_INIT(RealName),
64
65 const QtPrivate::QMetaTypeInterface *interfaceForType(int type) const override {
66 switch (type) {
68 default: return nullptr;
69 }
70 }
71#undef QT_IMPL_METATYPEINTERFACE_GUI_TYPES
72
73 bool convert(const void *from, int fromTypeId, void *to, int toTypeId) const override
74 {
75 Q_ASSERT(fromTypeId != toTypeId);
76
77 bool onlyCheck = (from == nullptr && to == nullptr);
78 // either two nullptrs from canConvert, or two valid pointers
79 Q_ASSERT(onlyCheck || (bool(from) && bool(to)));
80
81#if QT_CONFIG(shortcut)
82 using Int = int;
83#endif
84 switch (makePair(toTypeId, fromTypeId)) {
86 result = source.name(source.alpha() != 255 ?
87 QColor::HexArgb : QColor::HexRgb).toLatin1();
88 return true;
89 );
92 return result.isValid();
93 );
95 result = source.name(source.alpha() != 255 ?
96 QColor::HexArgb : QColor::HexRgb);
97 return true;
98 );
101 return result.isValid();
102 );
103#if QT_CONFIG(shortcut)
106 return true;
107 );
110 result = source.isEmpty() ? 0 : source[0].toCombined();
111 return true;
112 );
113 QMETATYPE_CONVERTER(QKeySequence, Int, result = source; return true;);
114#endif
116 QMETATYPE_CONVERTER(QFont, QString, return result.fromString(source););
126 if (source.style() == Qt::SolidPattern) {
127 result = source.color();
128 return true;
129 }
130 return false;
131 );
132 QMETATYPE_CONVERTER(QBrush, QColor, result = source; return true;);
133 default:
134 break;
135 }
136 return false;
137 }
138} qVariantGuiHelper;
139
140} // namespace used to hide QVariant handler
141
143{
144 qMetaTypeGuiHelper = &qVariantGuiHelper;
145}
147
\inmodule QtGui
Definition qbitmap.h:16
static QBitmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Returns a copy of the given image converted to a bitmap using the specified image conversion flags.
Definition qbitmap.cpp:170
static QBitmap fromPixmap(const QPixmap &pixmap)
Returns a copy of the given pixmap converted to a bitmap.
Definition qbitmap.cpp:234
\inmodule QtGui
Definition qbrush.h:30
QPixmap texture() const
Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set.
Definition qbrush.cpp:711
\inmodule QtCore
Definition qbytearray.h:57
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
static QColor fromString(QAnyStringView name) noexcept
Definition qcolor.cpp:980
QString name(NameFormat format=HexRgb) const
Definition qcolor.cpp:834
@ HexArgb
Definition qcolor.h:36
\reentrant
Definition qfont.h:22
QString toString() const
Returns a description of the font.
Definition qfont.cpp:2143
\inmodule QtGui
Definition qimage.h:37
The QKeySequence class encapsulates a key sequence as used by shortcuts.
bool isEmpty() const
Returns true if the key sequence is empty; otherwise returns false.
QString toString(SequenceFormat format=PortableText) const
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
QImage toImage() const
Converts the pixmap to a QImage.
Definition qpixmap.cpp:408
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition qpixmap.cpp:1437
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
@ SolidPattern
Q_CONSTRUCTOR_FUNCTION(qt_apple_check_os_version)
void qRegisterGuiVariant()
Q_CONSTINIT Q_CORE_EXPORT const QMetaTypeModuleHelper * qMetaTypeGuiHelper
static const QtPrivate::QMetaTypeInterface * interfaceForType(int typeId)
#define QT_FOR_EACH_STATIC_GUI_CLASS(F)
Definition qmetatype.h:159
#define QT_METATYPE_CONVERT_ID_TO_TYPE(MetaTypeName, MetaTypeId, RealName)
#define QMETATYPE_CONVERTER(To, From, assign_and_return)
Definition qmetatype_p.h:23
GLenum type
GLsizei GLsizei GLchar * source
GLuint64EXT * result
[6]
static constexpr To convert(const std::array< Mapping, N > &mapping, From Mapping::*from, To Mapping::*to, From value, To defaultValue)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47