kernel/qguivariant.cpp

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

Generated by Squish Coco Non-Commercial