1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the Qt Designer of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
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 https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** BSD License Usage
18 ** Alternatively, you may use this file under the terms of the BSD license
19 ** as follows:
20 **
21 ** "Redistribution and use in source and binary forms, with or without
22 ** modification, are permitted provided that the following conditions are
23 ** met:
24 ** * Redistributions of source code must retain the above copyright
25 ** notice, this list of conditions and the following disclaimer.
26 ** * Redistributions in binary form must reproduce the above copyright
27 ** notice, this list of conditions and the following disclaimer in
28 ** the documentation and/or other materials provided with the
29 ** distribution.
30 ** * Neither the name of The Qt Company Ltd nor the names of its
31 ** contributors may be used to endorse or promote products derived
32 ** from this software without specific prior written permission.
33 **
34 **
35 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46 **
47 ** $QT_END_LICENSE$
48 **
49 ****************************************************************************/
50
51 //
52 // W A R N I N G
53 // -------------
54 //
55 // This file is not part of the Qt API. It exists for the convenience
56 // of Qt Designer. This header
57 // file may change from version to version without notice, or even be removed.
58 //
59 // We mean it.
60 //
61
62 #ifndef UILIBPROPERTIES_H
63 #define UILIBPROPERTIES_H
64
65 #include "uilib_global.h"
66
67 #include <QtCore/qobject.h>
68 #include <QtCore/qmetaobject.h>
69 #include <QtCore/qlocale.h>
70 #include <QtCore/qcoreapplication.h>
71
72 #include <QtWidgets/qwidget.h>
73
74 #include "formbuilderextra_p.h"
75
76 QT_BEGIN_NAMESPACE
77
78 #ifdef QFORMINTERNAL_NAMESPACE
79 namespace QFormInternal
80 {
81 #endif
82
83 class QAbstractFormBuilder;
84 class DomProperty;
85
86 QDESIGNER_UILIB_EXPORT DomProperty *variantToDomProperty(QAbstractFormBuilder *abstractFormBuilder, const QMetaObject *meta, const QString &propertyName, const QVariant &value);
87
88
89 QDESIGNER_UILIB_EXPORT QVariant domPropertyToVariant(const DomProperty *property);
90 QDESIGNER_UILIB_EXPORT QVariant domPropertyToVariant(QAbstractFormBuilder *abstractFormBuilder, const QMetaObject *meta, const DomProperty *property);
91
92 // This class exists to provide meta information
93 // for enumerations only.
94 class QAbstractFormBuilderGadget: public QWidget
95 {
96 Q_OBJECT
Q_PROPERTY(Qt::ItemFlags itemFlags READ fakeItemFlags)97 Q_PROPERTY(Qt::ItemFlags itemFlags READ fakeItemFlags)
98 Q_PROPERTY(Qt::CheckState checkState READ fakeCheckState)
99 Q_PROPERTY(Qt::Alignment textAlignment READ fakeAlignment)
100 Q_PROPERTY(Qt::Orientation orientation READ fakeOrientation)
101 Q_PROPERTY(QSizePolicy::Policy sizeType READ fakeSizeType)
102 Q_PROPERTY(QPalette::ColorRole colorRole READ fakeColorRole)
103 Q_PROPERTY(QPalette::ColorGroup colorGroup READ fakeColorGroup)
104 Q_PROPERTY(QFont::StyleStrategy styleStrategy READ fakeStyleStrategy)
105 Q_PROPERTY(Qt::CursorShape cursorShape READ fakeCursorShape)
106 Q_PROPERTY(Qt::BrushStyle brushStyle READ fakeBrushStyle)
107 Q_PROPERTY(Qt::ToolBarArea toolBarArea READ fakeToolBarArea)
108 Q_PROPERTY(QGradient::Type gradientType READ fakeGradientType)
109 Q_PROPERTY(QGradient::Spread gradientSpread READ fakeGradientSpread)
110 Q_PROPERTY(QGradient::CoordinateMode gradientCoordinate READ fakeGradientCoordinate)
111 Q_PROPERTY(QLocale::Language language READ fakeLanguage)
112 Q_PROPERTY(QLocale::Country country READ fakeCountry)
113 public:
114 QAbstractFormBuilderGadget() { Q_ASSERT(0); }
115
fakeOrientation()116 Qt::Orientation fakeOrientation() const { Q_ASSERT(0); return Qt::Horizontal; }
fakeSizeType()117 QSizePolicy::Policy fakeSizeType() const { Q_ASSERT(0); return QSizePolicy::Expanding; }
fakeColorGroup()118 QPalette::ColorGroup fakeColorGroup() const { Q_ASSERT(0); return static_cast<QPalette::ColorGroup>(0); }
fakeColorRole()119 QPalette::ColorRole fakeColorRole() const { Q_ASSERT(0); return static_cast<QPalette::ColorRole>(0); }
fakeStyleStrategy()120 QFont::StyleStrategy fakeStyleStrategy() const { Q_ASSERT(0); return QFont::PreferDefault; }
fakeCursorShape()121 Qt::CursorShape fakeCursorShape() const { Q_ASSERT(0); return Qt::ArrowCursor; }
fakeBrushStyle()122 Qt::BrushStyle fakeBrushStyle() const { Q_ASSERT(0); return Qt::NoBrush; }
fakeToolBarArea()123 Qt::ToolBarArea fakeToolBarArea() const { Q_ASSERT(0); return Qt::NoToolBarArea; }
fakeGradientType()124 QGradient::Type fakeGradientType() const { Q_ASSERT(0); return QGradient::NoGradient; }
fakeGradientSpread()125 QGradient::Spread fakeGradientSpread() const { Q_ASSERT(0); return QGradient::PadSpread; }
fakeGradientCoordinate()126 QGradient::CoordinateMode fakeGradientCoordinate() const { Q_ASSERT(0); return QGradient::LogicalMode; }
fakeLanguage()127 QLocale::Language fakeLanguage() const { Q_ASSERT(0); return QLocale::C; }
fakeCountry()128 QLocale::Country fakeCountry() const { Q_ASSERT(0); return QLocale::AnyCountry; }
fakeItemFlags()129 Qt::ItemFlags fakeItemFlags() const { Q_ASSERT(0); return Qt::NoItemFlags; }
fakeCheckState()130 Qt::CheckState fakeCheckState() const { Q_ASSERT(0); return Qt::Unchecked; }
fakeAlignment()131 Qt::Alignment fakeAlignment() const { Q_ASSERT(0); return Qt::AlignLeft; }
132 };
133
134 // Convert key to value for a given QMetaEnum
135 template <class EnumType>
136 inline EnumType enumKeyToValue(const QMetaEnum &metaEnum,const char *key, const EnumType* = nullptr)
137 {
138 int val = metaEnum.keyToValue(key);
139 if (val == -1) {
140
141 uiLibWarning(QCoreApplication::translate("QFormBuilder", "The enumeration-value '%1' is invalid. The default value '%2' will be used instead.")
142 .arg(QString::fromUtf8(key)).arg(QString::fromUtf8(metaEnum.key(0))));
143 val = metaEnum.value(0);
144 }
145 return static_cast<EnumType>(val);
146 }
147
148 // Convert keys to value for a given QMetaEnum
149 template <class EnumType>
150 inline EnumType enumKeysToValue(const QMetaEnum &metaEnum,const char *keys, const EnumType* = nullptr)
151 {
152 int val = metaEnum.keysToValue(keys);
153 if (val == -1) {
154
155 uiLibWarning(QCoreApplication::translate("QFormBuilder", "The flag-value '%1' is invalid. Zero will be used instead.")
156 .arg(QString::fromUtf8(keys)));
157 val = 0;
158 }
159 return static_cast<EnumType>(QFlag(val));
160 }
161
162 // Access meta enumeration object of a qobject
163 template <class QObjectType>
metaEnum(const char * name)164 inline QMetaEnum metaEnum(const char *name)
165 {
166 const int e_index = QObjectType::staticMetaObject.indexOfProperty(name);
167 Q_ASSERT(e_index != -1);
168 return QObjectType::staticMetaObject.property(e_index).enumerator();
169 }
170
171 // Convert key to value for enumeration by name
172 template <class QObjectType, class EnumType>
enumKeyOfObjectToValue(const char * enumName,const char * key)173 inline EnumType enumKeyOfObjectToValue(const char *enumName, const char *key)
174 {
175 const QMetaEnum me = metaEnum<QObjectType>(enumName);
176 return enumKeyToValue<EnumType>(me, key);
177 }
178
179 #ifdef QFORMINTERNAL_NAMESPACE
180 }
181 #endif
182
183 QT_END_NAMESPACE
184
185 #endif // UILIBPROPERTIES_H
186