qguivariant.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/kernel/qguivariant.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
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 QtGui 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// Gui types-
41#include "qbitmap.h"-
42#include "qbrush.h"-
43#include "qcolor.h"-
44#include "qcursor.h"-
45#include "qfont.h"-
46#include "qimage.h"-
47#include "qkeysequence.h"-
48#include "qtransform.h"-
49#include "qmatrix.h"-
50#include "qpalette.h"-
51#include "qpen.h"-
52#include "qpixmap.h"-
53#include "qpolygon.h"-
54#include "qregion.h"-
55#include "qtextformat.h"-
56#include "qmatrix4x4.h"-
57#include "qvector2d.h"-
58#include "qvector3d.h"-
59#include "qvector4d.h"-
60#include "qquaternion.h"-
61#include "qicon.h"-
62-
63// Core types-
64#include "qvariant.h"-
65#include "qbitarray.h"-
66#include "qbytearray.h"-
67#include "qdatastream.h"-
68#include "qdebug.h"-
69#include "qmap.h"-
70#include "qdatetime.h"-
71#include "qeasingcurve.h"-
72#include "qlist.h"-
73#include "qstring.h"-
74#include "qstringlist.h"-
75#include "qurl.h"-
76#include "qlocale.h"-
77#include "quuid.h"-
78-
79#ifndef QT_NO_GEOM_VARIANT-
80#include "qsize.h"-
81#include "qpoint.h"-
82#include "qrect.h"-
83#include "qline.h"-
84#endif-
85-
86#include <float.h>-
87-
88#include "private/qvariant_p.h"-
89#include <private/qmetatype_p.h>-
90-
91QT_BEGIN_NAMESPACE-
92-
93Q_CORE_EXPORT const QVariant::Handler *qcoreVariantHandler();-
94-
95namespace {-
96struct GuiTypesFilter {-
97 template<typename T>-
98 struct Acceptor {-
99 static const bool IsAccepted = QModulesPrivate::QTypeModuleInfo<T>::IsGui && QtMetaTypePrivate::TypeDefinition<T>::IsAvailable;-
100 };-
101};-
102-
103static void construct(QVariant::Private *x, const void *copy)-
104{-
105 const int type = x->type;-
106 QVariantConstructor<GuiTypesFilter> constructor(x, copy);-
107 QMetaTypeSwitcher::switcher<void>(constructor, type, 0);-
108}
never executed: end of block
0
109-
110static void clear(QVariant::Private *d)-
111{-
112 QVariantDestructor<GuiTypesFilter> destructor(d);-
113 QMetaTypeSwitcher::switcher<void>(destructor, d->type, 0);-
114}
never executed: end of block
0
115-
116// This class is a hack that customizes access to QPolygon and QPolygonF-
117template<class Filter>-
118class QGuiVariantIsNull : public QVariantIsNull<Filter> {-
119 typedef QVariantIsNull<Filter> Base;-
120public:-
121 QGuiVariantIsNull(const QVariant::Private *d)-
122 : QVariantIsNull<Filter>(d)-
123 {}
never executed: end of block
0
124 template<typename T>-
125 bool delegate(const T *p) { return Base::delegate(p); }
never executed: return Base::delegate(p);
0
126 bool delegate(const QPolygon*) { return v_cast<QPolygon>(Base::m_d)->isEmpty(); }
never executed: return v_cast<QPolygon>(Base::m_d)->isEmpty();
0
127 bool delegate(const QPolygonF*) { return v_cast<QPolygonF>(Base::m_d)->isEmpty(); }
never executed: return v_cast<QPolygonF>(Base::m_d)->isEmpty();
0
128 bool delegate(const void *p) { return Base::delegate(p); }
never executed: return Base::delegate(p);
0
129};-
130static bool isNull(const QVariant::Private *d)-
131{-
132 QGuiVariantIsNull<GuiTypesFilter> isNull(d);-
133 return QMetaTypeSwitcher::switcher<bool>(isNull, d->type, 0);
never executed: return QMetaTypeSwitcher::switcher<bool>(isNull, d->type, 0);
0
134}-
135-
136// This class is a hack that customizes access to QPixmap, QBitmap, QCursor and QIcon-
137template<class Filter>-
138class QGuiVariantComparator : public QVariantComparator<Filter> {-
139 typedef QVariantComparator<Filter> Base;-
140public:-
141 QGuiVariantComparator(const QVariant::Private *a, const QVariant::Private *b)-
142 : QVariantComparator<Filter>(a, b)-
143 {}
never executed: end of block
0
144 template<typename T>-
145 bool delegate(const T *p)-
146 {-
147 return Base::delegate(p);
never executed: return Base::delegate(p);
0
148 }-
149 bool delegate(const QPixmap*)-
150 {-
151 return v_cast<QPixmap>(Base::m_a)->cacheKey() == v_cast<QPixmap>(Base::m_b)->cacheKey();
never executed: return v_cast<QPixmap>(Base::m_a)->cacheKey() == v_cast<QPixmap>(Base::m_b)->cacheKey();
0
152 }-
153 bool delegate(const QBitmap*)-
154 {-
155 return v_cast<QBitmap>(Base::m_a)->cacheKey() == v_cast<QBitmap>(Base::m_b)->cacheKey();
never executed: return v_cast<QBitmap>(Base::m_a)->cacheKey() == v_cast<QBitmap>(Base::m_b)->cacheKey();
0
156 }-
157#ifndef QT_NO_CURSOR-
158 bool delegate(const QCursor*)-
159 {-
160 return v_cast<QCursor>(Base::m_a)->shape() == v_cast<QCursor>(Base::m_b)->shape();
never executed: return v_cast<QCursor>(Base::m_a)->shape() == v_cast<QCursor>(Base::m_b)->shape();
0
161 }-
162#endif-
163#ifndef QT_NO_ICON-
164 bool delegate(const QIcon *)-
165 {-
166 return v_cast<QIcon>(Base::m_a)->cacheKey() == v_cast<QIcon>(Base::m_b)->cacheKey();
never executed: return v_cast<QIcon>(Base::m_a)->cacheKey() == v_cast<QIcon>(Base::m_b)->cacheKey();
0
167 }-
168#endif-
169 bool delegate(const void *p) { return Base::delegate(p); }
never executed: return Base::delegate(p);
0
170};-
171-
172static bool compare(const QVariant::Private *a, const QVariant::Private *b)-
173{-
174 QGuiVariantComparator<GuiTypesFilter> comparator(a, b);-
175 return QMetaTypeSwitcher::switcher<bool>(comparator, a->type, 0);
never executed: return QMetaTypeSwitcher::switcher<bool>(comparator, a->type, 0);
0
176}-
177-
178static bool convert(const QVariant::Private *d, int t,-
179 void *result, bool *ok)-
180{-
181 switch (t) {-
182 case QVariant::ByteArray:
never executed: case QVariant::ByteArray:
0
183 if (d->type == QVariant::Color) {
d->type == QVariant::ColorDescription
TRUEnever evaluated
FALSEnever evaluated
0
184 const QColor *c = v_cast<QColor>(d);-
185 *static_cast<QByteArray *>(result) = c->name(c->alpha() != 255 ? QColor::HexArgb : QColor::HexRgb).toLatin1();-
186 return true;
never executed: return true;
0
187 }-
188 break;
never executed: break;
0
189 case QVariant::String: {
never executed: case QVariant::String:
0
190 QString *str = static_cast<QString *>(result);-
191 switch (d->type) {-
192#ifndef QT_NO_SHORTCUT-
193 case QVariant::KeySequence:
never executed: case QVariant::KeySequence:
0
194 *str = (*v_cast<QKeySequence>(d)).toString(QKeySequence::NativeText);-
195 return true;
never executed: return true;
0
196#endif-
197 case QVariant::Font:
never executed: case QVariant::Font:
0
198 *str = v_cast<QFont>(d)->toString();-
199 return true;
never executed: return true;
0
200 case QVariant::Color: {
never executed: case QVariant::Color:
0
201 const QColor *c = v_cast<QColor>(d);-
202 *str = c->name(c->alpha() != 255 ? QColor::HexArgb : QColor::HexRgb);-
203 return true;
never executed: return true;
0
204 }-
205 default:
never executed: default:
0
206 break;
never executed: break;
0
207 }-
208 break;
never executed: break;
0
209 }-
210 case QVariant::Pixmap:
never executed: case QVariant::Pixmap:
0
211 if (d->type == QVariant::Image) {
d->type == QVariant::ImageDescription
TRUEnever evaluated
FALSEnever evaluated
0
212 *static_cast<QPixmap *>(result) = QPixmap::fromImage(*v_cast<QImage>(d));-
213 return true;
never executed: return true;
0
214 } else if (d->type == QVariant::Bitmap) {
d->type == QVariant::BitmapDescription
TRUEnever evaluated
FALSEnever evaluated
0
215 *static_cast<QPixmap *>(result) = *v_cast<QBitmap>(d);-
216 return true;
never executed: return true;
0
217 } else if (d->type == QVariant::Brush) {
d->type == QVariant::BrushDescription
TRUEnever evaluated
FALSEnever evaluated
0
218 if (v_cast<QBrush>(d)->style() == Qt::TexturePattern) {
v_cast<QBrush>...TexturePatternDescription
TRUEnever evaluated
FALSEnever evaluated
0
219 *static_cast<QPixmap *>(result) = v_cast<QBrush>(d)->texture();-
220 return true;
never executed: return true;
0
221 }-
222 }
never executed: end of block
0
223 break;
never executed: break;
0
224 case QVariant::Image:
never executed: case QVariant::Image:
0
225 if (d->type == QVariant::Pixmap) {
d->type == QVariant::PixmapDescription
TRUEnever evaluated
FALSEnever evaluated
0
226 *static_cast<QImage *>(result) = v_cast<QPixmap>(d)->toImage();-
227 return true;
never executed: return true;
0
228 } else if (d->type == QVariant::Bitmap) {
d->type == QVariant::BitmapDescription
TRUEnever evaluated
FALSEnever evaluated
0
229 *static_cast<QImage *>(result) = v_cast<QBitmap>(d)->toImage();-
230 return true;
never executed: return true;
0
231 }-
232 break;
never executed: break;
0
233 case QVariant::Bitmap:
never executed: case QVariant::Bitmap:
0
234 if (d->type == QVariant::Pixmap) {
d->type == QVariant::PixmapDescription
TRUEnever evaluated
FALSEnever evaluated
0
235 *static_cast<QBitmap *>(result) = *v_cast<QPixmap>(d);-
236 return true;
never executed: return true;
0
237 } else if (d->type == QVariant::Image) {
d->type == QVariant::ImageDescription
TRUEnever evaluated
FALSEnever evaluated
0
238 *static_cast<QBitmap *>(result) = QBitmap::fromImage(*v_cast<QImage>(d));-
239 return true;
never executed: return true;
0
240 }-
241 break;
never executed: break;
0
242#ifndef QT_NO_SHORTCUT-
243 case QVariant::Int:
never executed: case QVariant::Int:
0
244 if (d->type == QVariant::KeySequence) {
d->type == QVa...t::KeySequenceDescription
TRUEnever evaluated
FALSEnever evaluated
0
245 const QKeySequence &seq = *v_cast<QKeySequence>(d);-
246 *static_cast<int *>(result) = seq.isEmpty() ? 0 : seq[0];
seq.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
247 return true;
never executed: return true;
0
248 }-
249 break;
never executed: break;
0
250#endif-
251 case QVariant::Font:
never executed: case QVariant::Font:
0
252 if (d->type == QVariant::String) {
d->type == QVariant::StringDescription
TRUEnever evaluated
FALSEnever evaluated
0
253 QFont *f = static_cast<QFont *>(result);-
254 f->fromString(*v_cast<QString>(d));-
255 return true;
never executed: return true;
0
256 }-
257 break;
never executed: break;
0
258 case QVariant::Color:
never executed: case QVariant::Color:
0
259 if (d->type == QVariant::String) {
d->type == QVariant::StringDescription
TRUEnever evaluated
FALSEnever evaluated
0
260 static_cast<QColor *>(result)->setNamedColor(*v_cast<QString>(d));-
261 return static_cast<QColor *>(result)->isValid();
never executed: return static_cast<QColor *>(result)->isValid();
0
262 } else if (d->type == QVariant::ByteArray) {
d->type == QVariant::ByteArrayDescription
TRUEnever evaluated
FALSEnever evaluated
0
263 static_cast<QColor *>(result)->setNamedColor(QString::fromLatin1(-
264 *v_cast<QByteArray>(d)));-
265 return true;
never executed: return true;
0
266 } else if (d->type == QVariant::Brush) {
d->type == QVariant::BrushDescription
TRUEnever evaluated
FALSEnever evaluated
0
267 if (v_cast<QBrush>(d)->style() == Qt::SolidPattern) {
v_cast<QBrush>...::SolidPatternDescription
TRUEnever evaluated
FALSEnever evaluated
0
268 *static_cast<QColor *>(result) = v_cast<QBrush>(d)->color();-
269 return true;
never executed: return true;
0
270 }-
271 }
never executed: end of block
0
272 break;
never executed: break;
0
273 case QVariant::Brush:
never executed: case QVariant::Brush:
0
274 if (d->type == QVariant::Color) {
d->type == QVariant::ColorDescription
TRUEnever evaluated
FALSEnever evaluated
0
275 *static_cast<QBrush *>(result) = QBrush(*v_cast<QColor>(d));-
276 return true;
never executed: return true;
0
277 } else if (d->type == QVariant::Pixmap) {
d->type == QVariant::PixmapDescription
TRUEnever evaluated
FALSEnever evaluated
0
278 *static_cast<QBrush *>(result) = QBrush(*v_cast<QPixmap>(d));-
279 return true;
never executed: return true;
0
280 }-
281 break;
never executed: break;
0
282#ifndef QT_NO_SHORTCUT-
283 case QVariant::KeySequence: {
never executed: case QVariant::KeySequence:
0
284 QKeySequence *seq = static_cast<QKeySequence *>(result);-
285 switch (d->type) {-
286 case QVariant::String:
never executed: case QVariant::String:
0
287 *seq = QKeySequence(*v_cast<QString>(d));-
288 return true;
never executed: return true;
0
289 case QVariant::Int:
never executed: case QVariant::Int:
0
290 *seq = QKeySequence(d->data.i);-
291 return true;
never executed: return true;
0
292 default:
never executed: default:
0
293 break;
never executed: break;
0
294 }-
295 }-
296#endif-
297#ifndef QT_NO_ICON-
298 case QVariant::Icon: {
code before this statement never executed: case QVariant::Icon:
never executed: case QVariant::Icon:
0
299 if (ok)
okDescription
TRUEnever evaluated
FALSEnever evaluated
0
300 *ok = false;
never executed: *ok = false;
0
301 return false;
never executed: return false;
0
302 }-
303#endif-
304 default:
never executed: default:
0
305 break;
never executed: break;
0
306 }-
307 return qcoreVariantHandler()->convert(d, t, result, ok);
never executed: return qcoreVariantHandler()->convert(d, t, result, ok);
0
308}-
309-
310#if !defined(QT_NO_DEBUG_STREAM)-
311static void streamDebug(QDebug dbg, const QVariant &v)-
312{-
313 QVariant::Private *d = const_cast<QVariant::Private *>(&v.data_ptr());-
314 QVariantDebugStream<GuiTypesFilter> stream(dbg, d);-
315 QMetaTypeSwitcher::switcher<void>(stream, d->type, 0);-
316}
never executed: end of block
0
317#endif-
318-
319const QVariant::Handler qt_gui_variant_handler = {-
320 construct,-
321 clear,-
322 isNull,-
323#ifndef QT_NO_DATASTREAM-
324 0,-
325 0,-
326#endif-
327 compare,-
328 convert,-
329 0,-
330#if !defined(QT_NO_DEBUG_STREAM)-
331 streamDebug-
332#else-
333 0-
334#endif-
335};-
336-
337#define QT_IMPL_METATYPEINTERFACE_GUI_TYPES(MetaTypeName, MetaTypeId, RealName) \-
338 QT_METATYPE_INTERFACE_INIT(RealName),-
339-
340static const QMetaTypeInterface qVariantGuiHelper[] = {-
341 QT_FOR_EACH_STATIC_GUI_CLASS(QT_IMPL_METATYPEINTERFACE_GUI_TYPES)-
342};-
343-
344#undef QT_IMPL_METATYPEINTERFACE_GUI_TYPES-
345} // namespace used to hide QVariant handler-
346-
347extern Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeGuiHelper;-
348-
349void qRegisterGuiVariant()-
350{-
351 QVariantPrivate::registerHandler(QModulesPrivate::Gui, &qt_gui_variant_handler);-
352 qMetaTypeGuiHelper = qVariantGuiHelper;-
353}
never executed: end of block
0
354Q_CONSTRUCTOR_FUNCTION(qRegisterGuiVariant)
never executed: end of block
0
355-
356QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9