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 KCONFIG_CONVERSION_CHECK_P_H
9#define KCONFIG_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
22namespace KConfigConversionCheck
23{
24// used to distinguish between supported/unsupported types
25struct supported {
26};
27struct unsupported {
28};
29
30// traits type class to define support for constraints
31template<typename T>
32struct QVconvertible {
33 typedef unsupported toQString;
34 typedef unsupported toQVariant;
35};
36
37// constraint classes
38template<typename T>
39struct type_toQString {
40 void constraint()
41 {
42 supported x = y;
43 Q_UNUSED(x);
44 }
45 typename QVconvertible<T>::toQString y;
46};
47
48template<typename T>
49struct type_toQVariant {
50 void constraint()
51 {
52 supported x = y;
53 Q_UNUSED(x);
54 }
55 typename QVconvertible<T>::toQVariant y;
56};
57
58// check if T is convertible to QString thru QVariant
59// if not supported can't be used in QList<T> functions
60template<typename T>
61inline void to_QString()
62{
63 void (type_toQString<T>::*x)() = &type_toQString<T>::constraint;
64 Q_UNUSED(x);
65}
66
67// check if T is convertible to QVariant & supported in readEntry/writeEntry
68template<typename T>
69inline void to_QVariant()
70{
71 void (type_toQVariant<T>::*x)() = &type_toQVariant<T>::constraint;
72 Q_UNUSED(x);
73}
74
75// define for all types handled in readEntry/writeEntry
76// string_support - is supported by QVariant(type).toString(),
77// can be used in QList<T> functions
78// variant_support - has a QVariant constructor
79#define QVConversions(type, string_support, variant_support) \
80 template<> \
81 struct QVconvertible<type> { \
82 typedef string_support toQString; \
83 typedef variant_support toQVariant; \
84 }
85
86// The only types needed here are the types handled in readEntry/writeEntry
87// the default QVconvertible will take care of the rest.
88QVConversions(bool, supported, supported);
89QVConversions(int, supported, supported);
90QVConversions(unsigned int, supported, supported);
91QVConversions(long long, supported, supported);
92QVConversions(unsigned long long, supported, supported);
93QVConversions(float, supported, supported);
94QVConversions(double, supported, supported);
95QVConversions(QString, supported, supported);
96QVConversions(QColor, unsupported, supported);
97QVConversions(QFont, supported, supported);
98QVConversions(QDateTime, unsupported, supported);
99QVConversions(QDate, unsupported, supported);
100QVConversions(QSize, unsupported, supported);
101QVConversions(QRect, unsupported, supported);
102QVConversions(QPoint, unsupported, supported);
103QVConversions(QSizeF, unsupported, supported);
104QVConversions(QRectF, unsupported, supported);
105QVConversions(QPointF, unsupported, supported);
106QVConversions(QByteArray, supported, supported);
107QVConversions(QStringList, unsupported, supported);
108QVConversions(QVariantList, unsupported, supported);
109QVConversions(QUrl, supported, supported);
110QVConversions(QList<QUrl>, unsupported, supported);
111QVConversions(QUuid, supported, supported);
112}
113
114#endif
115

source code of kconfig/src/core/kconfigconversioncheck_p.h