1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtWidgets module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include "qvariant.h" |
41 | |
42 | #include "qsizepolicy.h" |
43 | #include "qwidget.h" |
44 | |
45 | #include "private/qvariant_p.h" |
46 | #include <private/qmetatype_p.h> |
47 | |
48 | QT_BEGIN_NAMESPACE |
49 | |
50 | namespace { |
51 | static void construct(QVariant::Private *x, const void *copy) |
52 | { |
53 | switch (x->type) { |
54 | case QMetaType::QSizePolicy: |
55 | v_construct<QSizePolicy>(x, copy); |
56 | break; |
57 | default: |
58 | qWarning(msg: "Trying to construct an instance of an invalid type, type id: %i" , x->type); |
59 | x->type = QMetaType::UnknownType; |
60 | return; |
61 | } |
62 | x->is_null = !copy; |
63 | } |
64 | |
65 | static void clear(QVariant::Private *d) |
66 | { |
67 | switch (d->type) { |
68 | case QMetaType::QSizePolicy: |
69 | v_clear<QSizePolicy>(d); |
70 | break; |
71 | default: |
72 | Q_ASSERT(false); |
73 | return; |
74 | } |
75 | |
76 | d->type = QMetaType::UnknownType; |
77 | d->is_null = true; |
78 | d->is_shared = false; |
79 | } |
80 | |
81 | |
82 | static bool isNull(const QVariant::Private *) |
83 | { |
84 | return false; |
85 | } |
86 | |
87 | static bool compare(const QVariant::Private *a, const QVariant::Private *b) |
88 | { |
89 | Q_ASSERT(a->type == b->type); |
90 | switch(a->type) { |
91 | case QMetaType::QSizePolicy: |
92 | return *v_cast<QSizePolicy>(d: a) == *v_cast<QSizePolicy>(d: b); |
93 | default: |
94 | Q_ASSERT(false); |
95 | } |
96 | return false; |
97 | } |
98 | |
99 | static bool convert(const QVariant::Private *d, int type, void *result, bool *ok) |
100 | { |
101 | Q_UNUSED(d); |
102 | Q_UNUSED(type); |
103 | Q_UNUSED(result); |
104 | if (ok) |
105 | *ok = false; |
106 | return false; |
107 | } |
108 | |
109 | #if !defined(QT_NO_DEBUG_STREAM) |
110 | static void streamDebug(QDebug dbg, const QVariant &v) |
111 | { |
112 | QVariant::Private *d = const_cast<QVariant::Private *>(&v.data_ptr()); |
113 | switch (d->type) { |
114 | case QMetaType::QSizePolicy: |
115 | dbg.nospace() << *v_cast<QSizePolicy>(d); |
116 | break; |
117 | default: |
118 | dbg.nospace() << "QMetaType::Type(" << d->type << ')'; |
119 | } |
120 | } |
121 | #endif |
122 | |
123 | static const QVariant::Handler widgets_handler = { |
124 | .construct: construct, |
125 | .clear: clear, |
126 | .isNull: isNull, |
127 | #ifndef QT_NO_DATASTREAM |
128 | .load: nullptr, |
129 | .save: nullptr, |
130 | #endif |
131 | .compare: compare, |
132 | .convert: convert, |
133 | .canConvert: nullptr, |
134 | #if !defined(QT_NO_DEBUG_STREAM) |
135 | .debugStream: streamDebug |
136 | #else |
137 | 0 |
138 | #endif |
139 | }; |
140 | |
141 | #define QT_IMPL_METATYPEINTERFACE_WIDGETS_TYPES(MetaTypeName, MetaTypeId, RealName) \ |
142 | QT_METATYPE_INTERFACE_INIT(RealName), |
143 | |
144 | static const QMetaTypeInterface qVariantWidgetsHelper[] = { |
145 | QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_IMPL_METATYPEINTERFACE_WIDGETS_TYPES) |
146 | }; |
147 | |
148 | #undef QT_IMPL_METATYPEINTERFACE_WIDGETS_TYPES |
149 | |
150 | } // namespace |
151 | |
152 | extern Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeWidgetsHelper; |
153 | |
154 | void qRegisterWidgetsVariant() |
155 | { |
156 | qRegisterMetaType<QWidget*>(); |
157 | qMetaTypeWidgetsHelper = qVariantWidgetsHelper; |
158 | QVariantPrivate::registerHandler(name: QModulesPrivate::Widgets, handler: &widgets_handler); |
159 | } |
160 | Q_CONSTRUCTOR_FUNCTION(qRegisterWidgetsVariant) |
161 | |
162 | QT_END_NAMESPACE |
163 | |