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

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