1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2006 Thomas Braxton <brax108@cox.net>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef KSERVICE_CONVERSION_CHECK_P_H
9#define KSERVICE_CONVERSION_CHECK_P_H
10
11#include <QDate>
12#include <QPoint>
13#include <QRect>
14#include <QSize>
15#include <QString>
16#include <QUuid>
17#include <QVariant>
18
19class QColor;
20class QFont;
21
22// Copied from kconfigconversioncheck_p.h in KConfig
23namespace KServiceConversionCheck
24{
25// used to distinguish between supported/unsupported types
26struct supported {
27};
28struct unsupported {
29};
30
31// traits type class to define support for constraints
32template<typename T>
33struct QVconvertible {
34 typedef unsupported toQString;
35 typedef unsupported toQVariant;
36};
37
38// constraint classes
39template<typename T>
40struct type_toQString {
41 void constraint()
42 {
43 supported x = y;
44 Q_UNUSED(x);
45 }
46 typename QVconvertible<T>::toQString y;
47};
48
49template<typename T>
50struct type_toQVariant {
51 void constraint()
52 {
53 supported x = y;
54 Q_UNUSED(x);
55 }
56 typename QVconvertible<T>::toQVariant y;
57};
58
59// check if T is convertible to QString thru QVariant
60// if not supported can't be used in QList<T> functions
61template<typename T>
62inline void to_QString()
63{
64 void (type_toQString<T>::*x)() = &type_toQString<T>::constraint;
65 Q_UNUSED(x);
66}
67
68// check if T is convertible to QVariant & supported in readEntry/writeEntry
69template<typename T>
70inline void to_QVariant()
71{
72 void (type_toQVariant<T>::*x)() = &type_toQVariant<T>::constraint;
73 Q_UNUSED(x);
74}
75
76// define for all types handled in readEntry/writeEntry
77// string_support - is supported by QVariant(type).toString(),
78// can be used in QList<T> functions
79// variant_support - has a QVariant constructor
80#define QVConversions(type, string_support, variant_support) \
81 template<> \
82 struct QVconvertible<type> { \
83 typedef string_support toQString; \
84 typedef variant_support toQVariant; \
85 }
86
87// The only types needed here are the types handled in readEntry/writeEntry
88// the default QVconvertible will take care of the rest.
89QVConversions(bool, supported, supported);
90QVConversions(int, supported, supported);
91QVConversions(unsigned int, supported, supported);
92QVConversions(long long, supported, supported);
93QVConversions(unsigned long long, supported, supported);
94QVConversions(float, supported, supported);
95QVConversions(double, supported, supported);
96QVConversions(QString, supported, supported);
97QVConversions(QColor, unsupported, supported);
98QVConversions(QFont, supported, supported);
99QVConversions(QDateTime, unsupported, supported);
100QVConversions(QDate, unsupported, supported);
101QVConversions(QSize, unsupported, supported);
102QVConversions(QRect, unsupported, supported);
103QVConversions(QPoint, unsupported, supported);
104QVConversions(QSizeF, unsupported, supported);
105QVConversions(QRectF, unsupported, supported);
106QVConversions(QPointF, unsupported, supported);
107QVConversions(QByteArray, supported, supported);
108QVConversions(QStringList, unsupported, supported);
109QVConversions(QVariantList, unsupported, supported);
110QVConversions(QUrl, supported, supported);
111QVConversions(QList<QUrl>, unsupported, supported);
112QVConversions(QUuid, supported, supported);
113}
114
115#endif
116

source code of kservice/src/services/kserviceconversioncheck_p.h