/src/qtbase/src/gui/kernel/qguivariant.cpp
Line | Count | Source (jump to first uncovered line) |
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 "qbitarray.h" |
31 | | #include "qbytearray.h" |
32 | | #include "qdatastream.h" |
33 | | #include "qdatetime.h" |
34 | | #include "qdebug.h" |
35 | | #include "qline.h" |
36 | | #include "qlist.h" |
37 | | #include "qlocale.h" |
38 | | #include "qmap.h" |
39 | | #include "qpoint.h" |
40 | | #include "qrect.h" |
41 | | #include "qsize.h" |
42 | | #include "qstring.h" |
43 | | #include "qstringlist.h" |
44 | | #include "qurl.h" |
45 | | #include "quuid.h" |
46 | | #include "qvariant.h" |
47 | | |
48 | | #include <float.h> |
49 | | |
50 | | #include <private/qmetatype_p.h> |
51 | | |
52 | | QT_BEGIN_NAMESPACE |
53 | | |
54 | | namespace { |
55 | | struct QVariantGuiHelper : QMetaTypeModuleHelper |
56 | | { |
57 | | #define QT_IMPL_METATYPEINTERFACE_GUI_TYPES(MetaTypeName, MetaTypeId, RealName) \ |
58 | | QT_METATYPE_INTERFACE_INIT(RealName), |
59 | | |
60 | | static const QtPrivate::QMetaTypeInterface *interfaceForType(int type) |
61 | 0 | { |
62 | 0 | switch (type) { |
63 | 0 | QT_FOR_EACH_STATIC_GUI_CLASS(QT_METATYPE_CONVERT_ID_TO_TYPE) |
64 | 0 | default: return nullptr; |
65 | 0 | } |
66 | 0 | } |
67 | | #undef QT_IMPL_METATYPEINTERFACE_GUI_TYPES |
68 | | |
69 | | static bool convert(const void *from, int fromTypeId, void *to, int toTypeId) |
70 | 0 | { |
71 | 0 | Q_ASSERT(fromTypeId != toTypeId); |
72 | |
|
73 | 0 | bool onlyCheck = (from == nullptr && to == nullptr); |
74 | | // either two nullptrs from canConvert, or two valid pointers |
75 | 0 | Q_ASSERT(onlyCheck || (bool(from) && bool(to))); |
76 | |
|
77 | 0 | #if QT_CONFIG(shortcut) |
78 | 0 | using Int = int; |
79 | 0 | #endif |
80 | 0 | switch (makePair(toTypeId, fromTypeId)) { |
81 | 0 | QMETATYPE_CONVERTER(QByteArray, QColor, |
82 | 0 | result = source.name(source.alpha() != 255 ? |
83 | 0 | QColor::HexArgb : QColor::HexRgb).toLatin1(); |
84 | 0 | return true; |
85 | 0 | ); |
86 | 0 | QMETATYPE_CONVERTER(QColor, QByteArray, |
87 | 0 | result = QColor::fromString(QLatin1StringView(source)); |
88 | 0 | return result.isValid(); |
89 | 0 | ); |
90 | 0 | QMETATYPE_CONVERTER(QString, QColor, |
91 | 0 | result = source.name(source.alpha() != 255 ? |
92 | 0 | QColor::HexArgb : QColor::HexRgb); |
93 | 0 | return true; |
94 | 0 | ); |
95 | 0 | QMETATYPE_CONVERTER(QColor, QString, |
96 | 0 | result = QColor::fromString(source); |
97 | 0 | return result.isValid(); |
98 | 0 | ); |
99 | 0 | #if QT_CONFIG(shortcut) |
100 | 0 | QMETATYPE_CONVERTER(QString, QKeySequence, |
101 | 0 | result = source.toString(QKeySequence::NativeText); |
102 | 0 | return true; |
103 | 0 | ); |
104 | 0 | QMETATYPE_CONVERTER(QKeySequence, QString, result = source; return true;); |
105 | 0 | QMETATYPE_CONVERTER(Int, QKeySequence, |
106 | 0 | result = source.isEmpty() ? 0 : source[0].toCombined(); |
107 | 0 | return true; |
108 | 0 | ); |
109 | 0 | QMETATYPE_CONVERTER(QKeySequence, Int, result = source; return true;); |
110 | 0 | #endif |
111 | 0 | QMETATYPE_CONVERTER(QString, QFont, result = source.toString(); return true;); |
112 | 0 | QMETATYPE_CONVERTER(QFont, QString, return result.fromString(source);); |
113 | 0 | QMETATYPE_CONVERTER(QPixmap, QImage, result = QPixmap::fromImage(source); return true;); |
114 | 0 | QMETATYPE_CONVERTER(QImage, QPixmap, result = source.toImage(); return true;); |
115 | 0 | QMETATYPE_CONVERTER(QPixmap, QBitmap, result = source; return true;); |
116 | 0 | QMETATYPE_CONVERTER(QBitmap, QPixmap, result = QBitmap::fromPixmap(source); return true;); |
117 | 0 | QMETATYPE_CONVERTER(QImage, QBitmap, result = source.toImage(); return true;); |
118 | 0 | QMETATYPE_CONVERTER(QBitmap, QImage, result = QBitmap::fromImage(source); return true;); |
119 | 0 | QMETATYPE_CONVERTER(QPixmap, QBrush, result = source.texture(); return true;); |
120 | 0 | QMETATYPE_CONVERTER(QBrush, QPixmap, result = source; return true;); |
121 | 0 | QMETATYPE_CONVERTER(QColor, QBrush, |
122 | 0 | if (source.style() == Qt::SolidPattern) { |
123 | 0 | result = source.color(); |
124 | 0 | return true; |
125 | 0 | } |
126 | 0 | return false; |
127 | 0 | ); |
128 | 0 | QMETATYPE_CONVERTER(QBrush, QColor, result = source; return true;); |
129 | 0 | default: |
130 | 0 | break; |
131 | 0 | } |
132 | 0 | return false; |
133 | 0 | } |
134 | | }; |
135 | | } // namespace used to hide QVariant handler |
136 | | |
137 | | void qRegisterGuiVariant() |
138 | 48 | { |
139 | 48 | qMetaTypeGuiHelper = QMetaTypeModuleHelper{ |
140 | 48 | &QVariantGuiHelper::interfaceForType, |
141 | 48 | &QVariantGuiHelper::convert, |
142 | 48 | }; |
143 | 48 | } |
144 | | Q_CONSTRUCTOR_FUNCTION(qRegisterGuiVariant) |
145 | | |
146 | | QT_END_NAMESPACE |