Coverage Report

Created: 2026-05-16 07:21

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