| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/kernel/qmetatype.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||||||||
| 6 | ** This file is part of the QtCore 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 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 | ** 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 3 as published by the Free Software | - | ||||||||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||||||||
| 39 | - | |||||||||||||||||||||||||
| 40 | #include "qmetatype.h" | - | ||||||||||||||||||||||||
| 41 | #include "qmetatype_p.h" | - | ||||||||||||||||||||||||
| 42 | #include "qobjectdefs.h" | - | ||||||||||||||||||||||||
| 43 | #include "qdatetime.h" | - | ||||||||||||||||||||||||
| 44 | #include "qbytearray.h" | - | ||||||||||||||||||||||||
| 45 | #include "qreadwritelock.h" | - | ||||||||||||||||||||||||
| 46 | #include "qstring.h" | - | ||||||||||||||||||||||||
| 47 | #include "qstringlist.h" | - | ||||||||||||||||||||||||
| 48 | #include "qvector.h" | - | ||||||||||||||||||||||||
| 49 | #include "qlocale.h" | - | ||||||||||||||||||||||||
| 50 | #include "qeasingcurve.h" | - | ||||||||||||||||||||||||
| 51 | #include "quuid.h" | - | ||||||||||||||||||||||||
| 52 | #include "qvariant.h" | - | ||||||||||||||||||||||||
| 53 | #include "qdatastream.h" | - | ||||||||||||||||||||||||
| 54 | #include "qmetatypeswitcher_p.h" | - | ||||||||||||||||||||||||
| 55 | - | |||||||||||||||||||||||||
| 56 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
| 57 | # include "qbitarray.h" | - | ||||||||||||||||||||||||
| 58 | # include "qurl.h" | - | ||||||||||||||||||||||||
| 59 | # include "qvariant.h" | - | ||||||||||||||||||||||||
| 60 | # include "qabstractitemmodel.h" | - | ||||||||||||||||||||||||
| 61 | # include "qregularexpression.h" | - | ||||||||||||||||||||||||
| 62 | # include "qjsonvalue.h" | - | ||||||||||||||||||||||||
| 63 | # include "qjsonobject.h" | - | ||||||||||||||||||||||||
| 64 | # include "qjsonarray.h" | - | ||||||||||||||||||||||||
| 65 | # include "qjsondocument.h" | - | ||||||||||||||||||||||||
| 66 | # include "qbytearraylist.h" | - | ||||||||||||||||||||||||
| 67 | #endif | - | ||||||||||||||||||||||||
| 68 | - | |||||||||||||||||||||||||
| 69 | #ifndef QT_NO_GEOM_VARIANT | - | ||||||||||||||||||||||||
| 70 | # include "qsize.h" | - | ||||||||||||||||||||||||
| 71 | # include "qpoint.h" | - | ||||||||||||||||||||||||
| 72 | # include "qrect.h" | - | ||||||||||||||||||||||||
| 73 | # include "qline.h" | - | ||||||||||||||||||||||||
| 74 | #endif | - | ||||||||||||||||||||||||
| 75 | - | |||||||||||||||||||||||||
| 76 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 77 | - | |||||||||||||||||||||||||
| 78 | #define NS(x) QT_PREPEND_NAMESPACE(x) | - | ||||||||||||||||||||||||
| 79 | - | |||||||||||||||||||||||||
| 80 | - | |||||||||||||||||||||||||
| 81 | namespace { | - | ||||||||||||||||||||||||
| 82 | struct DefinedTypesFilter { | - | ||||||||||||||||||||||||
| 83 | template<typename T> | - | ||||||||||||||||||||||||
| 84 | struct Acceptor { | - | ||||||||||||||||||||||||
| 85 | static const bool IsAccepted = QtMetaTypePrivate::TypeDefinition<T>::IsAvailable && QModulesPrivate::QTypeModuleInfo<T>::IsCore; | - | ||||||||||||||||||||||||
| 86 | }; | - | ||||||||||||||||||||||||
| 87 | }; | - | ||||||||||||||||||||||||
| 88 | } // namespace | - | ||||||||||||||||||||||||
| 89 | - | |||||||||||||||||||||||||
| 90 | /*! | - | ||||||||||||||||||||||||
| 91 | \macro Q_DECLARE_OPAQUE_POINTER(PointerType) | - | ||||||||||||||||||||||||
| 92 | \relates QMetaType | - | ||||||||||||||||||||||||
| 93 | \since 5.0 | - | ||||||||||||||||||||||||
| 94 | - | |||||||||||||||||||||||||
| 95 | This macro enables pointers to forward-declared types (\a PointerType) | - | ||||||||||||||||||||||||
| 96 | to be registered with QMetaType using either Q_DECLARE_METATYPE() | - | ||||||||||||||||||||||||
| 97 | or qRegisterMetaType(). | - | ||||||||||||||||||||||||
| 98 | - | |||||||||||||||||||||||||
| 99 | \sa Q_DECLARE_METATYPE(), qRegisterMetaType() | - | ||||||||||||||||||||||||
| 100 | */ | - | ||||||||||||||||||||||||
| 101 | - | |||||||||||||||||||||||||
| 102 | /*! | - | ||||||||||||||||||||||||
| 103 | \macro Q_DECLARE_METATYPE(Type) | - | ||||||||||||||||||||||||
| 104 | \relates QMetaType | - | ||||||||||||||||||||||||
| 105 | - | |||||||||||||||||||||||||
| 106 | This macro makes the type \a Type known to QMetaType as long as it | - | ||||||||||||||||||||||||
| 107 | provides a public default constructor, a public copy constructor and | - | ||||||||||||||||||||||||
| 108 | a public destructor. | - | ||||||||||||||||||||||||
| 109 | It is needed to use the type \a Type as a custom type in QVariant. | - | ||||||||||||||||||||||||
| 110 | - | |||||||||||||||||||||||||
| 111 | This macro requires that \a Type is a fully defined type at the point where | - | ||||||||||||||||||||||||
| 112 | it is used. For pointer types, it also requires that the pointed to type is | - | ||||||||||||||||||||||||
| 113 | fully defined. Use in conjunction with Q_DECLARE_OPAQUE_POINTER() to | - | ||||||||||||||||||||||||
| 114 | register pointers to forward declared types. | - | ||||||||||||||||||||||||
| 115 | - | |||||||||||||||||||||||||
| 116 | Ideally, this macro should be placed below the declaration of | - | ||||||||||||||||||||||||
| 117 | the class or struct. If that is not possible, it can be put in | - | ||||||||||||||||||||||||
| 118 | a private header file which has to be included every time that | - | ||||||||||||||||||||||||
| 119 | type is used in a QVariant. | - | ||||||||||||||||||||||||
| 120 | - | |||||||||||||||||||||||||
| 121 | Adding a Q_DECLARE_METATYPE() makes the type known to all template | - | ||||||||||||||||||||||||
| 122 | based functions, including QVariant. Note that if you intend to | - | ||||||||||||||||||||||||
| 123 | use the type in \e queued signal and slot connections or in | - | ||||||||||||||||||||||||
| 124 | QObject's property system, you also have to call | - | ||||||||||||||||||||||||
| 125 | qRegisterMetaType() since the names are resolved at runtime. | - | ||||||||||||||||||||||||
| 126 | - | |||||||||||||||||||||||||
| 127 | This example shows a typical use case of Q_DECLARE_METATYPE(): | - | ||||||||||||||||||||||||
| 128 | - | |||||||||||||||||||||||||
| 129 | \snippet code/src_corelib_kernel_qmetatype.cpp 0 | - | ||||||||||||||||||||||||
| 130 | - | |||||||||||||||||||||||||
| 131 | If \c MyStruct is in a namespace, the Q_DECLARE_METATYPE() macro | - | ||||||||||||||||||||||||
| 132 | has to be outside the namespace: | - | ||||||||||||||||||||||||
| 133 | - | |||||||||||||||||||||||||
| 134 | \snippet code/src_corelib_kernel_qmetatype.cpp 1 | - | ||||||||||||||||||||||||
| 135 | - | |||||||||||||||||||||||||
| 136 | Since \c{MyStruct} is now known to QMetaType, it can be used in QVariant: | - | ||||||||||||||||||||||||
| 137 | - | |||||||||||||||||||||||||
| 138 | \snippet code/src_corelib_kernel_qmetatype.cpp 2 | - | ||||||||||||||||||||||||
| 139 | - | |||||||||||||||||||||||||
| 140 | Some types are registered automatically and do not need this macro: | - | ||||||||||||||||||||||||
| 141 | - | |||||||||||||||||||||||||
| 142 | \list | - | ||||||||||||||||||||||||
| 143 | \li Pointers to classes derived from QObject | - | ||||||||||||||||||||||||
| 144 | \li QList<T>, QVector<T>, QQueue<T>, QStack<T>, QSet<T> or QLinkedList<T> | - | ||||||||||||||||||||||||
| 145 | where T is a registered meta type | - | ||||||||||||||||||||||||
| 146 | \li QHash<T1, T2>, QMap<T1, T2> or QPair<T1, T2> where T1 and T2 are | - | ||||||||||||||||||||||||
| 147 | registered meta types | - | ||||||||||||||||||||||||
| 148 | \li QPointer<T>, QSharedPointer<T>, QWeakPointer<T>, where T is a class that derives from QObject | - | ||||||||||||||||||||||||
| 149 | \li Enumerations registered with Q_ENUM or Q_FLAG | - | ||||||||||||||||||||||||
| 150 | \li Classes that have a Q_GADGET macro | - | ||||||||||||||||||||||||
| 151 | \endlist | - | ||||||||||||||||||||||||
| 152 | - | |||||||||||||||||||||||||
| 153 | \sa qRegisterMetaType() | - | ||||||||||||||||||||||||
| 154 | */ | - | ||||||||||||||||||||||||
| 155 | - | |||||||||||||||||||||||||
| 156 | /*! | - | ||||||||||||||||||||||||
| 157 | \macro Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE(Container) | - | ||||||||||||||||||||||||
| 158 | \relates QMetaType | - | ||||||||||||||||||||||||
| 159 | - | |||||||||||||||||||||||||
| 160 | This macro makes the container \a Container known to QMetaType as a sequential | - | ||||||||||||||||||||||||
| 161 | container. This makes it possible to put an instance of Container<T> into | - | ||||||||||||||||||||||||
| 162 | a QVariant, if T itself is known to QMetaType. | - | ||||||||||||||||||||||||
| 163 | - | |||||||||||||||||||||||||
| 164 | Note that all of the Qt sequential containers already have built-in | - | ||||||||||||||||||||||||
| 165 | support, and it is not necessary to use this macro with them. The | - | ||||||||||||||||||||||||
| 166 | std::vector and std::list containers also have built-in support. | - | ||||||||||||||||||||||||
| 167 | - | |||||||||||||||||||||||||
| 168 | This example shows a typical use of Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE(): | - | ||||||||||||||||||||||||
| 169 | - | |||||||||||||||||||||||||
| 170 | \snippet code/src_corelib_kernel_qmetatype.cpp 10 | - | ||||||||||||||||||||||||
| 171 | */ | - | ||||||||||||||||||||||||
| 172 | - | |||||||||||||||||||||||||
| 173 | /*! | - | ||||||||||||||||||||||||
| 174 | \macro Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE(Container) | - | ||||||||||||||||||||||||
| 175 | \relates QMetaType | - | ||||||||||||||||||||||||
| 176 | - | |||||||||||||||||||||||||
| 177 | This macro makes the container \a Container known to QMetaType as an associative | - | ||||||||||||||||||||||||
| 178 | container. This makes it possible to put an instance of Container<T, U> into | - | ||||||||||||||||||||||||
| 179 | a QVariant, if T and U are themselves known to QMetaType. | - | ||||||||||||||||||||||||
| 180 | - | |||||||||||||||||||||||||
| 181 | Note that all of the Qt associative containers already have built-in | - | ||||||||||||||||||||||||
| 182 | support, and it is not necessary to use this macro with them. The | - | ||||||||||||||||||||||||
| 183 | std::map container also has built-in support. | - | ||||||||||||||||||||||||
| 184 | - | |||||||||||||||||||||||||
| 185 | This example shows a typical use of Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE(): | - | ||||||||||||||||||||||||
| 186 | - | |||||||||||||||||||||||||
| 187 | \snippet code/src_corelib_kernel_qmetatype.cpp 11 | - | ||||||||||||||||||||||||
| 188 | */ | - | ||||||||||||||||||||||||
| 189 | - | |||||||||||||||||||||||||
| 190 | /*! | - | ||||||||||||||||||||||||
| 191 | \macro Q_DECLARE_SMART_POINTER_METATYPE(SmartPointer) | - | ||||||||||||||||||||||||
| 192 | \relates QMetaType | - | ||||||||||||||||||||||||
| 193 | - | |||||||||||||||||||||||||
| 194 | This macro makes the smart pointer \a SmartPointer known to QMetaType as a | - | ||||||||||||||||||||||||
| 195 | smart pointer. This makes it possible to put an instance of SmartPointer<T> into | - | ||||||||||||||||||||||||
| 196 | a QVariant, if T is a type which inherits QObject. | - | ||||||||||||||||||||||||
| 197 | - | |||||||||||||||||||||||||
| 198 | Note that the QWeakPointer, QSharedPointer and QPointer already have built-in | - | ||||||||||||||||||||||||
| 199 | support, and it is not necessary to use this macro with them. | - | ||||||||||||||||||||||||
| 200 | - | |||||||||||||||||||||||||
| 201 | This example shows a typical use of Q_DECLARE_SMART_POINTER_METATYPE(): | - | ||||||||||||||||||||||||
| 202 | - | |||||||||||||||||||||||||
| 203 | \snippet code/src_corelib_kernel_qmetatype.cpp 13 | - | ||||||||||||||||||||||||
| 204 | */ | - | ||||||||||||||||||||||||
| 205 | - | |||||||||||||||||||||||||
| 206 | /*! | - | ||||||||||||||||||||||||
| 207 | \enum QMetaType::Type | - | ||||||||||||||||||||||||
| 208 | - | |||||||||||||||||||||||||
| 209 | These are the built-in types supported by QMetaType: | - | ||||||||||||||||||||||||
| 210 | Read doc on QChar | - | ||||||||||||||||||||||||
| 211 | Read doc on \l QChar | - | ||||||||||||||||||||||||
| 212 | - | |||||||||||||||||||||||||
| 213 | \value Void \c void | - | ||||||||||||||||||||||||
| 214 | \value Bool \c bool | - | ||||||||||||||||||||||||
| 215 | \value Int \c int | - | ||||||||||||||||||||||||
| 216 | \value UInt \c{unsigned int} | - | ||||||||||||||||||||||||
| 217 | \value Double \c double | - | ||||||||||||||||||||||||
| 218 | \value QChar QChar | - | ||||||||||||||||||||||||
| 219 | \value QString QString | - | ||||||||||||||||||||||||
| 220 | \value QByteArray QByteArray | - | ||||||||||||||||||||||||
| 221 | - | |||||||||||||||||||||||||
| 222 | \value VoidStar \c{void *} | - | ||||||||||||||||||||||||
| 223 | \value Long \c{long} | - | ||||||||||||||||||||||||
| 224 | \value LongLong LongLong | - | ||||||||||||||||||||||||
| 225 | \value Short \c{short} | - | ||||||||||||||||||||||||
| 226 | \value Char \c{char} | - | ||||||||||||||||||||||||
| 227 | \value ULong \c{unsigned long} | - | ||||||||||||||||||||||||
| 228 | \value ULongLong ULongLong | - | ||||||||||||||||||||||||
| 229 | \value UShort \c{unsigned short} | - | ||||||||||||||||||||||||
| 230 | \value SChar \c{signed char} | - | ||||||||||||||||||||||||
| 231 | \value UChar \c{unsigned char} | - | ||||||||||||||||||||||||
| 232 | \value Float \c float | - | ||||||||||||||||||||||||
| 233 | \value QObjectStar QObject * | - | ||||||||||||||||||||||||
| 234 | \value QVariant QVariant | - | ||||||||||||||||||||||||
| 235 | - | |||||||||||||||||||||||||
| 236 | \value QCursor QCursor | - | ||||||||||||||||||||||||
| 237 | \value QDate QDate | - | ||||||||||||||||||||||||
| 238 | \value QSize QSize | - | ||||||||||||||||||||||||
| 239 | \value QTime QTime | - | ||||||||||||||||||||||||
| 240 | \value QVariantList QVariantList | - | ||||||||||||||||||||||||
| 241 | \value QPolygon QPolygon | - | ||||||||||||||||||||||||
| 242 | \value QPolygonF QPolygonF | - | ||||||||||||||||||||||||
| 243 | \value QColor QColor | - | ||||||||||||||||||||||||
| 244 | \value QSizeF QSizeF | - | ||||||||||||||||||||||||
| 245 | \value QRectF QRectF | - | ||||||||||||||||||||||||
| 246 | \value QLine QLine | - | ||||||||||||||||||||||||
| 247 | \value QTextLength QTextLength | - | ||||||||||||||||||||||||
| 248 | \value QStringList QStringList | - | ||||||||||||||||||||||||
| 249 | \value QVariantMap QVariantMap | - | ||||||||||||||||||||||||
| 250 | \value QVariantHash QVariantHash | - | ||||||||||||||||||||||||
| 251 | \value QIcon QIcon | - | ||||||||||||||||||||||||
| 252 | \value QPen QPen | - | ||||||||||||||||||||||||
| 253 | \value QLineF QLineF | - | ||||||||||||||||||||||||
| 254 | \value QTextFormat QTextFormat | - | ||||||||||||||||||||||||
| 255 | \value QRect QRect | - | ||||||||||||||||||||||||
| 256 | \value QPoint QPoint | - | ||||||||||||||||||||||||
| 257 | \value QUrl QUrl | - | ||||||||||||||||||||||||
| 258 | \value QRegExp QRegExp | - | ||||||||||||||||||||||||
| 259 | \value QRegularExpression QRegularExpression | - | ||||||||||||||||||||||||
| 260 | \value QDateTime QDateTime | - | ||||||||||||||||||||||||
| 261 | \value QPointF QPointF | - | ||||||||||||||||||||||||
| 262 | \value QPalette QPalette | - | ||||||||||||||||||||||||
| 263 | \value QFont QFont | - | ||||||||||||||||||||||||
| 264 | \value QBrush QBrush | - | ||||||||||||||||||||||||
| 265 | \value QRegion QRegion | - | ||||||||||||||||||||||||
| 266 | \value QBitArray QBitArray | - | ||||||||||||||||||||||||
| 267 | \value QImage QImage | - | ||||||||||||||||||||||||
| 268 | \value QKeySequence QKeySequence | - | ||||||||||||||||||||||||
| 269 | \value QSizePolicy QSizePolicy | - | ||||||||||||||||||||||||
| 270 | \value QPixmap QPixmap | - | ||||||||||||||||||||||||
| 271 | \value QLocale QLocale | - | ||||||||||||||||||||||||
| 272 | \value QBitmap QBitmap | - | ||||||||||||||||||||||||
| 273 | \value QMatrix QMatrix | - | ||||||||||||||||||||||||
| 274 | \value QTransform QTransform | - | ||||||||||||||||||||||||
| 275 | \value QMatrix4x4 QMatrix4x4 | - | ||||||||||||||||||||||||
| 276 | \value QVector2D QVector2D | - | ||||||||||||||||||||||||
| 277 | \value QVector3D QVector3D | - | ||||||||||||||||||||||||
| 278 | \value QVector4D QVector4D | - | ||||||||||||||||||||||||
| 279 | \value QQuaternion QQuaternion | - | ||||||||||||||||||||||||
| 280 | \value QEasingCurve QEasingCurve | - | ||||||||||||||||||||||||
| 281 | \value QJsonValue QJsonValue | - | ||||||||||||||||||||||||
| 282 | \value QJsonObject QJsonObject | - | ||||||||||||||||||||||||
| 283 | \value QJsonArray QJsonArray | - | ||||||||||||||||||||||||
| 284 | \value QJsonDocument QJsonDocument | - | ||||||||||||||||||||||||
| 285 | \value QModelIndex QModelIndex | - | ||||||||||||||||||||||||
| 286 | \value QPersistentModelIndex QPersistentModelIndex (since 5.5) | - | ||||||||||||||||||||||||
| 287 | \value QUuid QUuid | - | ||||||||||||||||||||||||
| 288 | \value QByteArrayList QByteArrayList | - | ||||||||||||||||||||||||
| 289 | - | |||||||||||||||||||||||||
| 290 | \value User Base value for user types | - | ||||||||||||||||||||||||
| 291 | \value UnknownType This is an invalid type id. It is returned from QMetaType for types that are not registered | - | ||||||||||||||||||||||||
| 292 | - | |||||||||||||||||||||||||
| 293 | Additional types can be registered using Q_DECLARE_METATYPE(). | - | ||||||||||||||||||||||||
| 294 | - | |||||||||||||||||||||||||
| 295 | \sa type(), typeName() | - | ||||||||||||||||||||||||
| 296 | */ | - | ||||||||||||||||||||||||
| 297 | - | |||||||||||||||||||||||||
| 298 | /*! | - | ||||||||||||||||||||||||
| 299 | \enum QMetaType::TypeFlag | - | ||||||||||||||||||||||||
| 300 | - | |||||||||||||||||||||||||
| 301 | The enum describes attributes of a type supported by QMetaType. | - | ||||||||||||||||||||||||
| 302 | - | |||||||||||||||||||||||||
| 303 | \value NeedsConstruction This type has non-trivial constructors. If the flag is not set instances can be safely initialized with memset to 0. | - | ||||||||||||||||||||||||
| 304 | \value NeedsDestruction This type has a non-trivial destructor. If the flag is not set calls to the destructor are not necessary before discarding objects. | - | ||||||||||||||||||||||||
| 305 | \value MovableType An instance of a type having this attribute can be safely moved by memcpy. | - | ||||||||||||||||||||||||
| 306 | \omitvalue SharedPointerToQObject | - | ||||||||||||||||||||||||
| 307 | \value IsEnumeration This type is an enumeration | - | ||||||||||||||||||||||||
| 308 | \value PointerToQObject This type is a pointer to a derived of QObject | - | ||||||||||||||||||||||||
| 309 | \omitvalue WeakPointerToQObject | - | ||||||||||||||||||||||||
| 310 | \omitvalue TrackingPointerToQObject | - | ||||||||||||||||||||||||
| 311 | \omitvalue WasDeclaredAsMetaType | - | ||||||||||||||||||||||||
| 312 | \omitvalue IsGadget This type is a Q_GADGET and it's corresponding QMetaObject can be accessed with QMetaType::metaObject Since 5.5. | - | ||||||||||||||||||||||||
| 313 | */ | - | ||||||||||||||||||||||||
| 314 | - | |||||||||||||||||||||||||
| 315 | /*! | - | ||||||||||||||||||||||||
| 316 | \class QMetaType | - | ||||||||||||||||||||||||
| 317 | \inmodule QtCore | - | ||||||||||||||||||||||||
| 318 | \brief The QMetaType class manages named types in the meta-object system. | - | ||||||||||||||||||||||||
| 319 | - | |||||||||||||||||||||||||
| 320 | \ingroup objectmodel | - | ||||||||||||||||||||||||
| 321 | \threadsafe | - | ||||||||||||||||||||||||
| 322 | - | |||||||||||||||||||||||||
| 323 | The class is used as a helper to marshall types in QVariant and | - | ||||||||||||||||||||||||
| 324 | in queued signals and slots connections. It associates a type | - | ||||||||||||||||||||||||
| 325 | name to a type so that it can be created and destructed | - | ||||||||||||||||||||||||
| 326 | dynamically at run-time. Declare new types with Q_DECLARE_METATYPE() | - | ||||||||||||||||||||||||
| 327 | to make them available to QVariant and other template-based functions. | - | ||||||||||||||||||||||||
| 328 | Call qRegisterMetaType() to make types available to non-template based | - | ||||||||||||||||||||||||
| 329 | functions, such as the queued signal and slot connections. | - | ||||||||||||||||||||||||
| 330 | - | |||||||||||||||||||||||||
| 331 | Any class or struct that has a public default | - | ||||||||||||||||||||||||
| 332 | constructor, a public copy constructor, and a public destructor | - | ||||||||||||||||||||||||
| 333 | can be registered. | - | ||||||||||||||||||||||||
| 334 | - | |||||||||||||||||||||||||
| 335 | The following code allocates and destructs an instance of | - | ||||||||||||||||||||||||
| 336 | \c{MyClass}: | - | ||||||||||||||||||||||||
| 337 | - | |||||||||||||||||||||||||
| 338 | \snippet code/src_corelib_kernel_qmetatype.cpp 3 | - | ||||||||||||||||||||||||
| 339 | - | |||||||||||||||||||||||||
| 340 | If we want the stream operators \c operator<<() and \c | - | ||||||||||||||||||||||||
| 341 | operator>>() to work on QVariant objects that store custom types, | - | ||||||||||||||||||||||||
| 342 | the custom type must provide \c operator<<() and \c operator>>() | - | ||||||||||||||||||||||||
| 343 | operators. | - | ||||||||||||||||||||||||
| 344 | - | |||||||||||||||||||||||||
| 345 | \sa Q_DECLARE_METATYPE(), QVariant::setValue(), QVariant::value(), QVariant::fromValue() | - | ||||||||||||||||||||||||
| 346 | */ | - | ||||||||||||||||||||||||
| 347 | - | |||||||||||||||||||||||||
| 348 | /*! | - | ||||||||||||||||||||||||
| 349 | \fn bool QMetaType::isValid() const | - | ||||||||||||||||||||||||
| 350 | \since 5.0 | - | ||||||||||||||||||||||||
| 351 | - | |||||||||||||||||||||||||
| 352 | Returns \c true if this QMetaType object contains valid | - | ||||||||||||||||||||||||
| 353 | information about a type, false otherwise. | - | ||||||||||||||||||||||||
| 354 | */ | - | ||||||||||||||||||||||||
| 355 | - | |||||||||||||||||||||||||
| 356 | /*! | - | ||||||||||||||||||||||||
| 357 | \fn bool QMetaType::isRegistered() const | - | ||||||||||||||||||||||||
| 358 | \since 5.0 | - | ||||||||||||||||||||||||
| 359 | - | |||||||||||||||||||||||||
| 360 | Returns \c true if this QMetaType object contains valid | - | ||||||||||||||||||||||||
| 361 | information about a type, false otherwise. | - | ||||||||||||||||||||||||
| 362 | */ | - | ||||||||||||||||||||||||
| 363 | - | |||||||||||||||||||||||||
| 364 | /*! | - | ||||||||||||||||||||||||
| 365 | \fn bool QMetaType::sizeOf() const | - | ||||||||||||||||||||||||
| 366 | \since 5.0 | - | ||||||||||||||||||||||||
| 367 | - | |||||||||||||||||||||||||
| 368 | Returns the size of the type in bytes (i.e. sizeof(T), | - | ||||||||||||||||||||||||
| 369 | where T is the actual type for which this QMetaType instance | - | ||||||||||||||||||||||||
| 370 | was constructed for). | - | ||||||||||||||||||||||||
| 371 | - | |||||||||||||||||||||||||
| 372 | This function is typically used together with construct() | - | ||||||||||||||||||||||||
| 373 | to perform low-level management of the memory used by a type. | - | ||||||||||||||||||||||||
| 374 | - | |||||||||||||||||||||||||
| 375 | \sa QMetaType::construct(), QMetaType::sizeOf() | - | ||||||||||||||||||||||||
| 376 | */ | - | ||||||||||||||||||||||||
| 377 | - | |||||||||||||||||||||||||
| 378 | /*! | - | ||||||||||||||||||||||||
| 379 | \fn TypeFlags QMetaType::flags() const | - | ||||||||||||||||||||||||
| 380 | \since 5.0 | - | ||||||||||||||||||||||||
| 381 | - | |||||||||||||||||||||||||
| 382 | Returns flags of the type for which this QMetaType instance was constructed. | - | ||||||||||||||||||||||||
| 383 | - | |||||||||||||||||||||||||
| 384 | \sa QMetaType::TypeFlags, QMetaType::typeFlags() | - | ||||||||||||||||||||||||
| 385 | */ | - | ||||||||||||||||||||||||
| 386 | - | |||||||||||||||||||||||||
| 387 | /*! | - | ||||||||||||||||||||||||
| 388 | \fn const QMetaObject *QMetaType::metaObject() const | - | ||||||||||||||||||||||||
| 389 | \since 5.5 | - | ||||||||||||||||||||||||
| 390 | - | |||||||||||||||||||||||||
| 391 | return a QMetaObject relative to this type. | - | ||||||||||||||||||||||||
| 392 | - | |||||||||||||||||||||||||
| 393 | If the type is a pointer type to a subclass of QObject, flags() contains | - | ||||||||||||||||||||||||
| 394 | QMetaType::PointerToQObject and this function returns the corresponding QMetaObject. This can | - | ||||||||||||||||||||||||
| 395 | be used to in combinaison with QMetaObject::construct to create QObject of this type. | - | ||||||||||||||||||||||||
| 396 | - | |||||||||||||||||||||||||
| 397 | If the type is a Q_GADGET, flags() contains QMetaType::IsGadget, and this function returns its | - | ||||||||||||||||||||||||
| 398 | QMetaObject. This can be used to retrieve QMetaMethod and QMetaProperty and use them on a | - | ||||||||||||||||||||||||
| 399 | pointer of this type. (given by QVariant::data for example) | - | ||||||||||||||||||||||||
| 400 | - | |||||||||||||||||||||||||
| 401 | If the type is an enumeration, flags() contains QMetaType::IsEnumeration, and this function | - | ||||||||||||||||||||||||
| 402 | returns the QMetaObject of the enclosing object if the enum was registered as a Q_ENUM or 0 | - | ||||||||||||||||||||||||
| 403 | otherwise | - | ||||||||||||||||||||||||
| 404 | - | |||||||||||||||||||||||||
| 405 | \sa QMetaType::metaObjectForType(), QMetaType::flags() | - | ||||||||||||||||||||||||
| 406 | */ | - | ||||||||||||||||||||||||
| 407 | - | |||||||||||||||||||||||||
| 408 | /*! | - | ||||||||||||||||||||||||
| 409 | \fn void *QMetaType::create(const void *copy = 0) const | - | ||||||||||||||||||||||||
| 410 | \since 5.0 | - | ||||||||||||||||||||||||
| 411 | - | |||||||||||||||||||||||||
| 412 | Returns a copy of \a copy, assuming it is of the type that this | - | ||||||||||||||||||||||||
| 413 | QMetaType instance was created for. If \a copy is null, creates | - | ||||||||||||||||||||||||
| 414 | a default constructed instance. | - | ||||||||||||||||||||||||
| 415 | - | |||||||||||||||||||||||||
| 416 | \sa QMetaType::destroy() | - | ||||||||||||||||||||||||
| 417 | */ | - | ||||||||||||||||||||||||
| 418 | - | |||||||||||||||||||||||||
| 419 | /*! | - | ||||||||||||||||||||||||
| 420 | \fn void QMetaType::destroy(void *data) const | - | ||||||||||||||||||||||||
| 421 | \since 5.0 | - | ||||||||||||||||||||||||
| 422 | - | |||||||||||||||||||||||||
| 423 | Destroys the \a data, assuming it is of the type that this | - | ||||||||||||||||||||||||
| 424 | QMetaType instance was created for. | - | ||||||||||||||||||||||||
| 425 | - | |||||||||||||||||||||||||
| 426 | \sa QMetaType::create() | - | ||||||||||||||||||||||||
| 427 | */ | - | ||||||||||||||||||||||||
| 428 | - | |||||||||||||||||||||||||
| 429 | /*! | - | ||||||||||||||||||||||||
| 430 | \fn void *QMetaType::construct(int type, const void *copy) | - | ||||||||||||||||||||||||
| 431 | \deprecated | - | ||||||||||||||||||||||||
| 432 | - | |||||||||||||||||||||||||
| 433 | Constructs a value of the given type which is a copy of \a copy. | - | ||||||||||||||||||||||||
| 434 | The default value for \a copy is 0. | - | ||||||||||||||||||||||||
| 435 | - | |||||||||||||||||||||||||
| 436 | Deprecated, use the static function QMetaType::create(int type, | - | ||||||||||||||||||||||||
| 437 | const void *copy) instead. | - | ||||||||||||||||||||||||
| 438 | */ | - | ||||||||||||||||||||||||
| 439 | /*! | - | ||||||||||||||||||||||||
| 440 | \fn void *QMetaType::construct(void *where, const void *copy = 0) const | - | ||||||||||||||||||||||||
| 441 | \since 5.0 | - | ||||||||||||||||||||||||
| 442 | - | |||||||||||||||||||||||||
| 443 | Constructs a value of the type that this QMetaType instance | - | ||||||||||||||||||||||||
| 444 | was constructed for in the existing memory addressed by \a where, | - | ||||||||||||||||||||||||
| 445 | that is a copy of \a copy, and returns \a where. If \a copy is | - | ||||||||||||||||||||||||
| 446 | zero, the value is default constructed. | - | ||||||||||||||||||||||||
| 447 | - | |||||||||||||||||||||||||
| 448 | This is a low-level function for explicitly managing the memory | - | ||||||||||||||||||||||||
| 449 | used to store the type. Consider calling create() if you don't | - | ||||||||||||||||||||||||
| 450 | need this level of control (that is, use "new" rather than | - | ||||||||||||||||||||||||
| 451 | "placement new"). | - | ||||||||||||||||||||||||
| 452 | - | |||||||||||||||||||||||||
| 453 | You must ensure that \a where points to a location where the new | - | ||||||||||||||||||||||||
| 454 | value can be stored and that \a where is suitably aligned. | - | ||||||||||||||||||||||||
| 455 | The type's size can be queried by calling sizeOf(). | - | ||||||||||||||||||||||||
| 456 | - | |||||||||||||||||||||||||
| 457 | The rule of thumb for alignment is that a type is aligned to its | - | ||||||||||||||||||||||||
| 458 | natural boundary, which is the smallest power of 2 that is bigger | - | ||||||||||||||||||||||||
| 459 | than the type, unless that alignment is larger than the maximum | - | ||||||||||||||||||||||||
| 460 | useful alignment for the platform. For practical purposes, | - | ||||||||||||||||||||||||
| 461 | alignment larger than 2 * sizeof(void*) is only necessary for | - | ||||||||||||||||||||||||
| 462 | special hardware instructions (e.g., aligned SSE loads and stores | - | ||||||||||||||||||||||||
| 463 | on x86). | - | ||||||||||||||||||||||||
| 464 | */ | - | ||||||||||||||||||||||||
| 465 | - | |||||||||||||||||||||||||
| 466 | /*! | - | ||||||||||||||||||||||||
| 467 | \fn void QMetaType::destruct(void *data) const | - | ||||||||||||||||||||||||
| 468 | \since 5.0 | - | ||||||||||||||||||||||||
| 469 | - | |||||||||||||||||||||||||
| 470 | Destructs the value, located at \a data, assuming that it is | - | ||||||||||||||||||||||||
| 471 | of the type for which this QMetaType instance was constructed for. | - | ||||||||||||||||||||||||
| 472 | - | |||||||||||||||||||||||||
| 473 | Unlike destroy(), this function only invokes the type's | - | ||||||||||||||||||||||||
| 474 | destructor, it doesn't invoke the delete operator. | - | ||||||||||||||||||||||||
| 475 | \sa QMetaType::construct() | - | ||||||||||||||||||||||||
| 476 | */ | - | ||||||||||||||||||||||||
| 477 | - | |||||||||||||||||||||||||
| 478 | /*! | - | ||||||||||||||||||||||||
| 479 | \fn QMetaType::~QMetaType() | - | ||||||||||||||||||||||||
| 480 | - | |||||||||||||||||||||||||
| 481 | Destructs this object. | - | ||||||||||||||||||||||||
| 482 | */ | - | ||||||||||||||||||||||||
| 483 | - | |||||||||||||||||||||||||
| 484 | #define QT_ADD_STATIC_METATYPE(MetaTypeName, MetaTypeId, RealName) \ | - | ||||||||||||||||||||||||
| 485 | { #RealName, sizeof(#RealName) - 1, MetaTypeId }, | - | ||||||||||||||||||||||||
| 486 | - | |||||||||||||||||||||||||
| 487 | #define QT_ADD_STATIC_METATYPE_ALIASES_ITER(MetaTypeName, MetaTypeId, AliasingName, RealNameStr) \ | - | ||||||||||||||||||||||||
| 488 | { RealNameStr, sizeof(RealNameStr) - 1, QMetaType::MetaTypeName }, | - | ||||||||||||||||||||||||
| 489 | - | |||||||||||||||||||||||||
| 490 | #define QT_ADD_STATIC_METATYPE_HACKS_ITER(MetaTypeName, TypeId, Name) \ | - | ||||||||||||||||||||||||
| 491 | QT_ADD_STATIC_METATYPE(MetaTypeName, MetaTypeName, Name) | - | ||||||||||||||||||||||||
| 492 | - | |||||||||||||||||||||||||
| 493 | static const struct { const char * typeName; int typeNameLength; int type; } types[] = { | - | ||||||||||||||||||||||||
| 494 | QT_FOR_EACH_STATIC_TYPE(QT_ADD_STATIC_METATYPE) | - | ||||||||||||||||||||||||
| 495 | QT_FOR_EACH_STATIC_ALIAS_TYPE(QT_ADD_STATIC_METATYPE_ALIASES_ITER) | - | ||||||||||||||||||||||||
| 496 | QT_FOR_EACH_STATIC_HACKS_TYPE(QT_ADD_STATIC_METATYPE_HACKS_ITER) | - | ||||||||||||||||||||||||
| 497 | {0, 0, QMetaType::UnknownType} | - | ||||||||||||||||||||||||
| 498 | }; | - | ||||||||||||||||||||||||
| 499 | - | |||||||||||||||||||||||||
| 500 | Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeGuiHelper = 0; | - | ||||||||||||||||||||||||
| 501 | Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeWidgetsHelper = 0; | - | ||||||||||||||||||||||||
| 502 | Q_CORE_EXPORT const QMetaObject *qMetaObjectWidgetsHelper = 0; | - | ||||||||||||||||||||||||
| 503 | - | |||||||||||||||||||||||||
| 504 | class QCustomTypeInfo : public QMetaTypeInterface | - | ||||||||||||||||||||||||
| 505 | { | - | ||||||||||||||||||||||||
| 506 | public: | - | ||||||||||||||||||||||||
| 507 | QCustomTypeInfo() | - | ||||||||||||||||||||||||
| 508 | : alias(-1) | - | ||||||||||||||||||||||||
| 509 | { | - | ||||||||||||||||||||||||
| 510 | QMetaTypeInterface empty = QT_METATYPE_INTERFACE_INIT(void); | - | ||||||||||||||||||||||||
| 511 | *static_cast<QMetaTypeInterface*>(this) = empty; | - | ||||||||||||||||||||||||
| 512 | } | - | ||||||||||||||||||||||||
| 513 | QByteArray typeName; | - | ||||||||||||||||||||||||
| 514 | int alias; | - | ||||||||||||||||||||||||
| 515 | }; | - | ||||||||||||||||||||||||
| 516 | - | |||||||||||||||||||||||||
| 517 | template<typename T, typename Key> | - | ||||||||||||||||||||||||
| 518 | class QMetaTypeFunctionRegistry | - | ||||||||||||||||||||||||
| 519 | { | - | ||||||||||||||||||||||||
| 520 | public: | - | ||||||||||||||||||||||||
| 521 | ~QMetaTypeFunctionRegistry() | - | ||||||||||||||||||||||||
| 522 | { | - | ||||||||||||||||||||||||
| 523 | const QWriteLocker locker(&lock); | - | ||||||||||||||||||||||||
| 524 | map.clear(); | - | ||||||||||||||||||||||||
| 525 | } | - | ||||||||||||||||||||||||
| 526 | - | |||||||||||||||||||||||||
| 527 | bool contains(Key k) const | - | ||||||||||||||||||||||||
| 528 | { | - | ||||||||||||||||||||||||
| 529 | const QReadLocker locker(&lock); | - | ||||||||||||||||||||||||
| 530 | return map.contains(k); | - | ||||||||||||||||||||||||
| 531 | } | - | ||||||||||||||||||||||||
| 532 | - | |||||||||||||||||||||||||
| 533 | bool insertIfNotContains(Key k, const T *f) | - | ||||||||||||||||||||||||
| 534 | { | - | ||||||||||||||||||||||||
| 535 | const QWriteLocker locker(&lock); | - | ||||||||||||||||||||||||
| 536 | const T* &fun = map[k]; | - | ||||||||||||||||||||||||
| 537 | if (fun != 0) | - | ||||||||||||||||||||||||
| 538 | return false; | - | ||||||||||||||||||||||||
| 539 | fun = f; | - | ||||||||||||||||||||||||
| 540 | return true; | - | ||||||||||||||||||||||||
| 541 | } | - | ||||||||||||||||||||||||
| 542 | - | |||||||||||||||||||||||||
| 543 | const T *function(Key k) const | - | ||||||||||||||||||||||||
| 544 | { | - | ||||||||||||||||||||||||
| 545 | const QReadLocker locker(&lock); | - | ||||||||||||||||||||||||
| 546 | return map.value(k, 0); | - | ||||||||||||||||||||||||
| 547 | } | - | ||||||||||||||||||||||||
| 548 | - | |||||||||||||||||||||||||
| 549 | void remove(int from, int to) | - | ||||||||||||||||||||||||
| 550 | { | - | ||||||||||||||||||||||||
| 551 | const Key k(from, to); | - | ||||||||||||||||||||||||
| 552 | const QWriteLocker locker(&lock); | - | ||||||||||||||||||||||||
| 553 | map.remove(k); | - | ||||||||||||||||||||||||
| 554 | } | - | ||||||||||||||||||||||||
| 555 | private: | - | ||||||||||||||||||||||||
| 556 | mutable QReadWriteLock lock; | - | ||||||||||||||||||||||||
| 557 | QHash<Key, const T *> map; | - | ||||||||||||||||||||||||
| 558 | }; | - | ||||||||||||||||||||||||
| 559 | - | |||||||||||||||||||||||||
| 560 | typedef QMetaTypeFunctionRegistry<QtPrivate::AbstractConverterFunction,QPair<int,int> > | - | ||||||||||||||||||||||||
| 561 | QMetaTypeConverterRegistry; | - | ||||||||||||||||||||||||
| 562 | typedef QMetaTypeFunctionRegistry<QtPrivate::AbstractComparatorFunction,int> | - | ||||||||||||||||||||||||
| 563 | QMetaTypeComparatorRegistry; | - | ||||||||||||||||||||||||
| 564 | typedef QMetaTypeFunctionRegistry<QtPrivate::AbstractDebugStreamFunction,int> | - | ||||||||||||||||||||||||
| 565 | QMetaTypeDebugStreamRegistry; | - | ||||||||||||||||||||||||
| 566 | - | |||||||||||||||||||||||||
| 567 | namespace | - | ||||||||||||||||||||||||
| 568 | { | - | ||||||||||||||||||||||||
| 569 | union CheckThatItIsPod | - | ||||||||||||||||||||||||
| 570 | { // This should break if QMetaTypeInterface is not a POD type | - | ||||||||||||||||||||||||
| 571 | QMetaTypeInterface iface; | - | ||||||||||||||||||||||||
| 572 | }; | - | ||||||||||||||||||||||||
| 573 | } | - | ||||||||||||||||||||||||
| 574 | - | |||||||||||||||||||||||||
| 575 | Q_DECLARE_TYPEINFO(QCustomTypeInfo, Q_MOVABLE_TYPE); | - | ||||||||||||||||||||||||
| 576 | Q_GLOBAL_STATIC(QVector<QCustomTypeInfo>, customTypes) | - | ||||||||||||||||||||||||
| 577 | Q_GLOBAL_STATIC(QReadWriteLock, customTypesLock) | - | ||||||||||||||||||||||||
| 578 | Q_GLOBAL_STATIC(QMetaTypeConverterRegistry, customTypesConversionRegistry) | - | ||||||||||||||||||||||||
| 579 | Q_GLOBAL_STATIC(QMetaTypeComparatorRegistry, customTypesComparatorRegistry) | - | ||||||||||||||||||||||||
| 580 | Q_GLOBAL_STATIC(QMetaTypeDebugStreamRegistry, customTypesDebugStreamRegistry) | - | ||||||||||||||||||||||||
| 581 | - | |||||||||||||||||||||||||
| 582 | /*! | - | ||||||||||||||||||||||||
| 583 | \fn bool QMetaType::registerConverter() | - | ||||||||||||||||||||||||
| 584 | \since 5.2 | - | ||||||||||||||||||||||||
| 585 | Registers the possibility of an implicit conversion from type From to type To in the meta | - | ||||||||||||||||||||||||
| 586 | type system. Returns \c true if the registration succeeded, otherwise false. | - | ||||||||||||||||||||||||
| 587 | */ | - | ||||||||||||||||||||||||
| 588 | - | |||||||||||||||||||||||||
| 589 | /*! | - | ||||||||||||||||||||||||
| 590 | \fn bool QMetaType::registerConverter(MemberFunction function) | - | ||||||||||||||||||||||||
| 591 | \since 5.2 | - | ||||||||||||||||||||||||
| 592 | \overload | - | ||||||||||||||||||||||||
| 593 | Registers a method \a function like To From::function() const as converter from type From | - | ||||||||||||||||||||||||
| 594 | to type To in the meta type system. Returns \c true if the registration succeeded, otherwise false. | - | ||||||||||||||||||||||||
| 595 | */ | - | ||||||||||||||||||||||||
| 596 | - | |||||||||||||||||||||||||
| 597 | /*! | - | ||||||||||||||||||||||||
| 598 | \fn bool QMetaType::registerConverter(MemberFunctionOk function) | - | ||||||||||||||||||||||||
| 599 | \since 5.2 | - | ||||||||||||||||||||||||
| 600 | \overload | - | ||||||||||||||||||||||||
| 601 | Registers a method \a function like To From::function(bool *ok) const as converter from type From | - | ||||||||||||||||||||||||
| 602 | to type To in the meta type system. Returns \c true if the registration succeeded, otherwise false. | - | ||||||||||||||||||||||||
| 603 | */ | - | ||||||||||||||||||||||||
| 604 | - | |||||||||||||||||||||||||
| 605 | /*! | - | ||||||||||||||||||||||||
| 606 | \fn bool QMetaType::registerConverter(UnaryFunction function) | - | ||||||||||||||||||||||||
| 607 | \since 5.2 | - | ||||||||||||||||||||||||
| 608 | \overload | - | ||||||||||||||||||||||||
| 609 | Registers a unary function object \a function as converter from type From | - | ||||||||||||||||||||||||
| 610 | to type To in the meta type system. Returns \c true if the registration succeeded, otherwise false. | - | ||||||||||||||||||||||||
| 611 | */ | - | ||||||||||||||||||||||||
| 612 | - | |||||||||||||||||||||||||
| 613 | /*! | - | ||||||||||||||||||||||||
| 614 | \fn bool QMetaType::registerComparators() | - | ||||||||||||||||||||||||
| 615 | \since 5.2 | - | ||||||||||||||||||||||||
| 616 | Registers comparison operators for the user-registered type T. This requires T to have | - | ||||||||||||||||||||||||
| 617 | both an operator== and an operator<. | - | ||||||||||||||||||||||||
| 618 | Returns \c true if the registration succeeded, otherwise false. | - | ||||||||||||||||||||||||
| 619 | */ | - | ||||||||||||||||||||||||
| 620 | - | |||||||||||||||||||||||||
| 621 | /*! | - | ||||||||||||||||||||||||
| 622 | \fn bool QMetaType::registerEqualsComparator() | - | ||||||||||||||||||||||||
| 623 | \since 5.5 | - | ||||||||||||||||||||||||
| 624 | Registers equals operator for the user-registered type T. This requires T to have | - | ||||||||||||||||||||||||
| 625 | an operator==. | - | ||||||||||||||||||||||||
| 626 | Returns \c true if the registration succeeded, otherwise false. | - | ||||||||||||||||||||||||
| 627 | */ | - | ||||||||||||||||||||||||
| 628 | - | |||||||||||||||||||||||||
| 629 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||||||||||||||||||||
| 630 | /*! | - | ||||||||||||||||||||||||
| 631 | \fn bool QMetaType::registerDebugStreamOperator() | - | ||||||||||||||||||||||||
| 632 | Registers the debug stream operator for the user-registered type T. This requires T to have | - | ||||||||||||||||||||||||
| 633 | an operator<<(QDebug dbg, T). | - | ||||||||||||||||||||||||
| 634 | Returns \c true if the registration succeeded, otherwise false. | - | ||||||||||||||||||||||||
| 635 | */ | - | ||||||||||||||||||||||||
| 636 | #endif | - | ||||||||||||||||||||||||
| 637 | - | |||||||||||||||||||||||||
| 638 | /*! | - | ||||||||||||||||||||||||
| 639 | Registers function \a f as converter function from type id \a from to \a to. | - | ||||||||||||||||||||||||
| 640 | If there's already a conversion registered, this does nothing but deleting \a f. | - | ||||||||||||||||||||||||
| 641 | Returns \c true if the registration succeeded, otherwise false. | - | ||||||||||||||||||||||||
| 642 | \since 5.2 | - | ||||||||||||||||||||||||
| 643 | \internal | - | ||||||||||||||||||||||||
| 644 | */ | - | ||||||||||||||||||||||||
| 645 | bool QMetaType::registerConverterFunction(const QtPrivate::AbstractConverterFunction *f, int from, int to) | - | ||||||||||||||||||||||||
| 646 | { | - | ||||||||||||||||||||||||
| 647 | if (!customTypesConversionRegistry()->insertIfNotContains(qMakePair(from, to), f)) { | - | ||||||||||||||||||||||||
| 648 | qWarning("Type conversion already registered from type %s to type %s", | - | ||||||||||||||||||||||||
| 649 | QMetaType::typeName(from), QMetaType::typeName(to)); | - | ||||||||||||||||||||||||
| 650 | return false; | - | ||||||||||||||||||||||||
| 651 | } | - | ||||||||||||||||||||||||
| 652 | return true; | - | ||||||||||||||||||||||||
| 653 | } | - | ||||||||||||||||||||||||
| 654 | - | |||||||||||||||||||||||||
| 655 | /*! | - | ||||||||||||||||||||||||
| 656 | \internal | - | ||||||||||||||||||||||||
| 657 | - | |||||||||||||||||||||||||
| 658 | Invoked automatically when a converter function object is destroyed. | - | ||||||||||||||||||||||||
| 659 | */ | - | ||||||||||||||||||||||||
| 660 | void QMetaType::unregisterConverterFunction(int from, int to) | - | ||||||||||||||||||||||||
| 661 | { | - | ||||||||||||||||||||||||
| 662 | if (customTypesConversionRegistry.isDestroyed()) | - | ||||||||||||||||||||||||
| 663 | return; | - | ||||||||||||||||||||||||
| 664 | customTypesConversionRegistry()->remove(from, to); | - | ||||||||||||||||||||||||
| 665 | } | - | ||||||||||||||||||||||||
| 666 | - | |||||||||||||||||||||||||
| 667 | bool QMetaType::registerComparatorFunction(const QtPrivate::AbstractComparatorFunction *f, int type) | - | ||||||||||||||||||||||||
| 668 | { | - | ||||||||||||||||||||||||
| 669 | if (!customTypesComparatorRegistry()->insertIfNotContains(type, f)) { | - | ||||||||||||||||||||||||
| 670 | qWarning("Comparators already registered for type %s", QMetaType::typeName(type)); | - | ||||||||||||||||||||||||
| 671 | return false; | - | ||||||||||||||||||||||||
| 672 | } | - | ||||||||||||||||||||||||
| 673 | return true; | - | ||||||||||||||||||||||||
| 674 | } | - | ||||||||||||||||||||||||
| 675 | - | |||||||||||||||||||||||||
| 676 | /*! | - | ||||||||||||||||||||||||
| 677 | \fn bool QMetaType::hasRegisteredComparators() | - | ||||||||||||||||||||||||
| 678 | Returns \c true, if the meta type system has registered comparators for type T. | - | ||||||||||||||||||||||||
| 679 | \since 5.2 | - | ||||||||||||||||||||||||
| 680 | */ | - | ||||||||||||||||||||||||
| 681 | - | |||||||||||||||||||||||||
| 682 | /*! | - | ||||||||||||||||||||||||
| 683 | Returns \c true, if the meta type system has registered comparators for type id \a typeId. | - | ||||||||||||||||||||||||
| 684 | \since 5.2 | - | ||||||||||||||||||||||||
| 685 | */ | - | ||||||||||||||||||||||||
| 686 | bool QMetaType::hasRegisteredComparators(int typeId) | - | ||||||||||||||||||||||||
| 687 | { | - | ||||||||||||||||||||||||
| 688 | return customTypesComparatorRegistry()->contains(typeId); | - | ||||||||||||||||||||||||
| 689 | } | - | ||||||||||||||||||||||||
| 690 | - | |||||||||||||||||||||||||
| 691 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||||||||||||||||||||
| 692 | bool QMetaType::registerDebugStreamOperatorFunction(const QtPrivate::AbstractDebugStreamFunction *f, | - | ||||||||||||||||||||||||
| 693 | int type) | - | ||||||||||||||||||||||||
| 694 | { | - | ||||||||||||||||||||||||
| 695 | if (!customTypesDebugStreamRegistry()->insertIfNotContains(type, f)) { | - | ||||||||||||||||||||||||
| 696 | qWarning("Debug stream operator already registered for type %s", QMetaType::typeName(type)); | - | ||||||||||||||||||||||||
| 697 | return false; | - | ||||||||||||||||||||||||
| 698 | } | - | ||||||||||||||||||||||||
| 699 | return true; | - | ||||||||||||||||||||||||
| 700 | } | - | ||||||||||||||||||||||||
| 701 | - | |||||||||||||||||||||||||
| 702 | /*! | - | ||||||||||||||||||||||||
| 703 | \fn bool QMetaType::hasRegisteredDebugStreamOperator() | - | ||||||||||||||||||||||||
| 704 | Returns \c true, if the meta type system has a registered debug stream operator for type T. | - | ||||||||||||||||||||||||
| 705 | \since 5.2 | - | ||||||||||||||||||||||||
| 706 | */ | - | ||||||||||||||||||||||||
| 707 | - | |||||||||||||||||||||||||
| 708 | /*! | - | ||||||||||||||||||||||||
| 709 | Returns \c true, if the meta type system has a registered debug stream operator for type | - | ||||||||||||||||||||||||
| 710 | id \a typeId. | - | ||||||||||||||||||||||||
| 711 | \since 5.2 | - | ||||||||||||||||||||||||
| 712 | */ | - | ||||||||||||||||||||||||
| 713 | bool QMetaType::hasRegisteredDebugStreamOperator(int typeId) | - | ||||||||||||||||||||||||
| 714 | { | - | ||||||||||||||||||||||||
| 715 | return customTypesDebugStreamRegistry()->contains(typeId); | - | ||||||||||||||||||||||||
| 716 | } | - | ||||||||||||||||||||||||
| 717 | #endif | - | ||||||||||||||||||||||||
| 718 | - | |||||||||||||||||||||||||
| 719 | /*! | - | ||||||||||||||||||||||||
| 720 | Converts the object at \a from from \a fromTypeId to the preallocated space at \a to | - | ||||||||||||||||||||||||
| 721 | typed \a toTypeId. Returns \c true, if the conversion succeeded, otherwise false. | - | ||||||||||||||||||||||||
| 722 | \since 5.2 | - | ||||||||||||||||||||||||
| 723 | */ | - | ||||||||||||||||||||||||
| 724 | bool QMetaType::convert(const void *from, int fromTypeId, void *to, int toTypeId) | - | ||||||||||||||||||||||||
| 725 | { | - | ||||||||||||||||||||||||
| 726 | const QtPrivate::AbstractConverterFunction * const f = | - | ||||||||||||||||||||||||
| 727 | customTypesConversionRegistry()->function(qMakePair(fromTypeId, toTypeId)); | - | ||||||||||||||||||||||||
| 728 | return f && f->convert(f, from, to); | - | ||||||||||||||||||||||||
| 729 | } | - | ||||||||||||||||||||||||
| 730 | - | |||||||||||||||||||||||||
| 731 | /*! | - | ||||||||||||||||||||||||
| 732 | Compares the objects at \a lhs and \a rhs. Both objects need to be of type \a typeId. | - | ||||||||||||||||||||||||
| 733 | \a result is set to less than, equal to or greater than zero, if \a lhs is less than, equal to | - | ||||||||||||||||||||||||
| 734 | or greater than \a rhs. Returns \c true, if the comparison succeeded, otherwise \c false. | - | ||||||||||||||||||||||||
| 735 | \since 5.2 | - | ||||||||||||||||||||||||
| 736 | */ | - | ||||||||||||||||||||||||
| 737 | bool QMetaType::compare(const void *lhs, const void *rhs, int typeId, int* result) | - | ||||||||||||||||||||||||
| 738 | { | - | ||||||||||||||||||||||||
| 739 | const QtPrivate::AbstractComparatorFunction * const f = | - | ||||||||||||||||||||||||
| 740 | customTypesComparatorRegistry()->function(typeId); | - | ||||||||||||||||||||||||
| 741 | if (!f) | - | ||||||||||||||||||||||||
| 742 | return false; | - | ||||||||||||||||||||||||
| 743 | if (f->equals(f, lhs, rhs)) | - | ||||||||||||||||||||||||
| 744 | *result = 0; | - | ||||||||||||||||||||||||
| 745 | else if (f->lessThan) | - | ||||||||||||||||||||||||
| 746 | *result = f->lessThan(f, lhs, rhs) ? -1 : 1; | - | ||||||||||||||||||||||||
| 747 | else | - | ||||||||||||||||||||||||
| 748 | return false; | - | ||||||||||||||||||||||||
| 749 | return true; | - | ||||||||||||||||||||||||
| 750 | } | - | ||||||||||||||||||||||||
| 751 | - | |||||||||||||||||||||||||
| 752 | /*! | - | ||||||||||||||||||||||||
| 753 | Compares the objects at \a lhs and \a rhs. Both objects need to be of type \a typeId. | - | ||||||||||||||||||||||||
| 754 | \a result is set to zero, if \a lhs equals to rhs. Returns \c true, if the comparison | - | ||||||||||||||||||||||||
| 755 | succeeded, otherwise \c false. | - | ||||||||||||||||||||||||
| 756 | \since 5.5 | - | ||||||||||||||||||||||||
| 757 | */ | - | ||||||||||||||||||||||||
| 758 | bool QMetaType::equals(const void *lhs, const void *rhs, int typeId, int *result) | - | ||||||||||||||||||||||||
| 759 | { | - | ||||||||||||||||||||||||
| 760 | const QtPrivate::AbstractComparatorFunction * const f | - | ||||||||||||||||||||||||
| 761 | = customTypesComparatorRegistry()->function(typeId); | - | ||||||||||||||||||||||||
| 762 | if (!f) | - | ||||||||||||||||||||||||
| 763 | return false; | - | ||||||||||||||||||||||||
| 764 | if (f->equals(f, lhs, rhs)) | - | ||||||||||||||||||||||||
| 765 | *result = 0; | - | ||||||||||||||||||||||||
| 766 | else | - | ||||||||||||||||||||||||
| 767 | *result = -1; | - | ||||||||||||||||||||||||
| 768 | return true; | - | ||||||||||||||||||||||||
| 769 | } | - | ||||||||||||||||||||||||
| 770 | - | |||||||||||||||||||||||||
| 771 | /*! | - | ||||||||||||||||||||||||
| 772 | Streams the object at \a rhs of type \a typeId to the debug stream \a dbg. Returns \c true | - | ||||||||||||||||||||||||
| 773 | on success, otherwise false. | - | ||||||||||||||||||||||||
| 774 | \since 5.2 | - | ||||||||||||||||||||||||
| 775 | */ | - | ||||||||||||||||||||||||
| 776 | bool QMetaType::debugStream(QDebug& dbg, const void *rhs, int typeId) | - | ||||||||||||||||||||||||
| 777 | { | - | ||||||||||||||||||||||||
| 778 | const QtPrivate::AbstractDebugStreamFunction * const f = customTypesDebugStreamRegistry()->function(typeId); | - | ||||||||||||||||||||||||
| 779 | if (!f) | - | ||||||||||||||||||||||||
| 780 | return false; | - | ||||||||||||||||||||||||
| 781 | f->stream(f, dbg, rhs); | - | ||||||||||||||||||||||||
| 782 | return true; | - | ||||||||||||||||||||||||
| 783 | } | - | ||||||||||||||||||||||||
| 784 | - | |||||||||||||||||||||||||
| 785 | /*! | - | ||||||||||||||||||||||||
| 786 | \fn bool QMetaType::hasRegisteredConverterFunction() | - | ||||||||||||||||||||||||
| 787 | Returns \c true, if the meta type system has a registered conversion from type From to type To. | - | ||||||||||||||||||||||||
| 788 | \since 5.2 | - | ||||||||||||||||||||||||
| 789 | \overload | - | ||||||||||||||||||||||||
| 790 | */ | - | ||||||||||||||||||||||||
| 791 | - | |||||||||||||||||||||||||
| 792 | /*! | - | ||||||||||||||||||||||||
| 793 | Returns \c true, if the meta type system has a registered conversion from meta type id \a fromTypeId | - | ||||||||||||||||||||||||
| 794 | to \a toTypeId | - | ||||||||||||||||||||||||
| 795 | \since 5.2 | - | ||||||||||||||||||||||||
| 796 | */ | - | ||||||||||||||||||||||||
| 797 | bool QMetaType::hasRegisteredConverterFunction(int fromTypeId, int toTypeId) | - | ||||||||||||||||||||||||
| 798 | { | - | ||||||||||||||||||||||||
| 799 | return customTypesConversionRegistry()->contains(qMakePair(fromTypeId, toTypeId)); | - | ||||||||||||||||||||||||
| 800 | } | - | ||||||||||||||||||||||||
| 801 | - | |||||||||||||||||||||||||
| 802 | #ifndef QT_NO_DATASTREAM | - | ||||||||||||||||||||||||
| 803 | /*! | - | ||||||||||||||||||||||||
| 804 | \internal | - | ||||||||||||||||||||||||
| 805 | */ | - | ||||||||||||||||||||||||
| 806 | void QMetaType::registerStreamOperators(const char *typeName, SaveOperator saveOp, | - | ||||||||||||||||||||||||
| 807 | LoadOperator loadOp) | - | ||||||||||||||||||||||||
| 808 | { | - | ||||||||||||||||||||||||
| 809 | registerStreamOperators(type(typeName), saveOp, loadOp); | - | ||||||||||||||||||||||||
| 810 | } | - | ||||||||||||||||||||||||
| 811 | - | |||||||||||||||||||||||||
| 812 | /*! | - | ||||||||||||||||||||||||
| 813 | \internal | - | ||||||||||||||||||||||||
| 814 | */ | - | ||||||||||||||||||||||||
| 815 | void QMetaType::registerStreamOperators(int idx, SaveOperator saveOp, | - | ||||||||||||||||||||||||
| 816 | LoadOperator loadOp) | - | ||||||||||||||||||||||||
| 817 | { | - | ||||||||||||||||||||||||
| 818 | if (idx < User) | - | ||||||||||||||||||||||||
| 819 | return; //builtin types should not be registered; | - | ||||||||||||||||||||||||
| 820 | QVector<QCustomTypeInfo> *ct = customTypes(); | - | ||||||||||||||||||||||||
| 821 | if (!ct) | - | ||||||||||||||||||||||||
| 822 | return; | - | ||||||||||||||||||||||||
| 823 | QWriteLocker locker(customTypesLock()); | - | ||||||||||||||||||||||||
| 824 | QCustomTypeInfo &inf = (*ct)[idx - User]; | - | ||||||||||||||||||||||||
| 825 | inf.saveOp = saveOp; | - | ||||||||||||||||||||||||
| 826 | inf.loadOp = loadOp; | - | ||||||||||||||||||||||||
| 827 | } | - | ||||||||||||||||||||||||
| 828 | #endif // QT_NO_DATASTREAM | - | ||||||||||||||||||||||||
| 829 | - | |||||||||||||||||||||||||
| 830 | /*! | - | ||||||||||||||||||||||||
| 831 | Returns the type name associated with the given \a typeId, or 0 if no | - | ||||||||||||||||||||||||
| 832 | matching type was found. The returned pointer must not be deleted. | - | ||||||||||||||||||||||||
| 833 | - | |||||||||||||||||||||||||
| 834 | \sa type(), isRegistered(), Type | - | ||||||||||||||||||||||||
| 835 | */ | - | ||||||||||||||||||||||||
| 836 | const char *QMetaType::typeName(int typeId) | - | ||||||||||||||||||||||||
| 837 | { | - | ||||||||||||||||||||||||
| 838 | const uint type = typeId; | - | ||||||||||||||||||||||||
| 839 | // In theory it can be filled during compilation time, but for some reason template code | - | ||||||||||||||||||||||||
| 840 | // that is able to do it causes GCC 4.6 to generate additional 3K of executable code. Probably | - | ||||||||||||||||||||||||
| 841 | // it is not worth of it. | - | ||||||||||||||||||||||||
| 842 | static const char *namesCache[QMetaType::HighestInternalId + 1]; | - | ||||||||||||||||||||||||
| 843 | - | |||||||||||||||||||||||||
| 844 | const char *result; | - | ||||||||||||||||||||||||
| 845 | if (type <= QMetaType::HighestInternalId && ((result = namesCache[type])))
| 4684-44294 | ||||||||||||||||||||||||
| 846 | return result executed 39610 times by 238 tests: ;return result;Executed by:
executed 39610 times by 238 tests: return result;Executed by:
| 39610 | ||||||||||||||||||||||||
| 847 | - | |||||||||||||||||||||||||
| 848 | #define QT_METATYPE_TYPEID_TYPENAME_CONVERTER(MetaTypeName, TypeId, RealName) \ | - | ||||||||||||||||||||||||
| 849 | case QMetaType::MetaTypeName: returnresult = #RealName; break; | - | ||||||||||||||||||||||||
| 850 | - | |||||||||||||||||||||||||
| 851 | switch (QMetaType::Type(type)) { | - | ||||||||||||||||||||||||
| 852 | QT_FOR_EACH_STATIC_TYPE(QT_METATYPE_TYPEID_TYPENAME_CONVERTER) executed 6 times by 6 tests: break;Executed by:
executed 369 times by 169 tests: break;Executed by:
executed 428 times by 204 tests: break;Executed by:
executed 369 times by 169 tests: break;Executed by:
executed 376 times by 176 tests: break;Executed by:
executed 369 times by 169 tests: break;Executed by:
executed 372 times by 172 tests: break;Executed by:
executed 4 times by 4 tests: break;Executed by:
executed 368 times by 168 tests: break;Executed by:
executed 3 times by 3 tests: break;Executed by:
executed 3 times by 3 tests: break;Executed by:
executed 369 times by 169 tests: break;Executed by:
executed 12 times by 7 tests: break;Executed by:
executed 3 times by 3 tests: break;Executed by:
executed 2 times by 2 tests: break;Executed by:
executed 168 times by 163 tests: break;Executed by:
executed 3 times by 3 tests: break;Executed by:
executed 219 times by 181 tests: break;Executed by:
executed 31 times by 26 tests: break;Executed by:
executed 24 times by 19 tests: break;Executed by:
executed 2 times by 2 tests: break;Executed by:
executed 57 times by 5 tests: break;Executed by:
executed 57 times by 5 tests: break;Executed by:
executed 60 times by 8 tests: break;Executed by:
executed 8 times by 8 tests: break;Executed by:
executed 3 times by 3 tests: break;Executed by:
executed 68 times by 16 tests: break;Executed by:
executed 60 times by 8 tests: break;Executed by:
executed 58 times by 6 tests: break;Executed by:
executed 57 times by 5 tests: break;Executed by:
executed 56 times by 4 tests: break;Executed by:
executed 56 times by 4 tests: break;Executed by:
executed 65 times by 13 tests: break;Executed by:
executed 59 times by 7 tests: break;Executed by:
executed 2 times by 2 tests: break;Executed by:
executed 3 times by 3 tests: break;Executed by:
executed 2 times by 2 tests: break;Executed by:
executed 119 times by 95 tests: break;Executed by:
executed 12 times by 12 tests: break;Executed by:
executed 2 times by 2 tests: break;Executed by:
executed 2 times by 2 tests: break;Executed by:
executed 2 times by 2 tests: break;Executed by:
executed 2 times by 2 tests: break;Executed by:
executed 2 times by 2 tests: break;Executed by:
executed 3 times by 3 tests: break;Executed by:
executed 20 times by 20 tests: break;Executed by:
executed 75 times by 22 tests: break;Executed by:
executed 18 times by 13 tests: break;Executed by:
executed 83 times by 7 tests: break;Executed by:
executed 2 times by 2 tests: break;Executed by:
executed 4 times by 4 tests: break;Executed by:
executed 4 times by 4 tests: break;Executed by:
executed 4 times by 4 tests: break;Executed by:
executed 4 times by 4 tests: break;Executed by:
executed 5 times by 5 tests: break;Executed by:
executed 11 times by 11 tests: break;Executed by:
executed 5 times by 5 tests: break;Executed by:
executed 4 times by 4 tests: break;Executed by:
executed 4 times by 4 tests: break;Executed by:
executed 4 times by 4 tests: break;Executed by:
executed 4 times by 4 tests: break;Executed by:
executed 5 times by 5 tests: break;Executed by:
executed 4 times by 4 tests: break;Executed by:
executed 4 times by 4 tests: break;Executed by:
executed 4 times by 4 tests: break;Executed by:
executed 5 times by 5 tests: break;Executed by:
executed 5 times by 5 tests: break;Executed by:
executed 5 times by 5 tests: break;Executed by:
executed 5 times by 5 tests: break;Executed by:
executed 5 times by 5 tests: break;Executed by:
executed 5 times by 5 tests: break;Executed by:
executed 5 times by 5 tests: break;Executed by:
executed 3 times by 3 tests: break;Executed by:
executed 3 times by 3 tests: break;Executed by:
executed 6 times by 6 tests: case QMetaType::Void:Executed by:
executed 369 times by 169 tests: case QMetaType::Bool:Executed by:
executed 428 times by 204 tests: case QMetaType::Int:Executed by:
executed 369 times by 169 tests: case QMetaType::UInt:Executed by:
executed 376 times by 176 tests: case QMetaType::LongLong:Executed by:
executed 369 times by 169 tests: case QMetaType::ULongLong:Executed by:
executed 372 times by 172 tests: case QMetaType::Double:Executed by:
executed 4 times by 4 tests: case QMetaType::Long:Executed by:
executed 368 times by 168 tests: case QMetaType::Short:Executed by:
executed 3 times by 3 tests: case QMetaType::Char:Executed by:
executed 3 times by 3 tests: case QMetaType::ULong:Executed by:
executed 369 times by 169 tests: case QMetaType::UShort:Executed by:
executed 12 times by 7 tests: case QMetaType::UChar:Executed by:
executed 3 times by 3 tests: case QMetaType::Float:Executed by:
executed 2 times by 2 tests: case QMetaType::SChar:Executed by:
executed 168 times by 163 tests: case QMetaType::VoidStar:Executed by:
executed 3 times by 3 tests: case QMetaType::QChar:Executed by:
executed 219 times by 181 tests: case QMetaType::QString:Executed by:
executed 31 times by 26 tests: case QMetaType::QStringList:Executed by:
executed 24 times by 19 tests: case QMetaType::QByteArray:Executed by:
executed 2 times by 2 tests: case QMetaType::QBitArray:Executed by:
executed 57 times by 5 tests: case QMetaType::QDate:Executed by:
executed 57 times by 5 tests: case QMetaType::QTime:Executed by:
executed 60 times by 8 tests: case QMetaType::QDateTime:Executed by:
executed 8 times by 8 tests: case QMetaType::QUrl:Executed by:
executed 3 times by 3 tests: case QMetaType::QLocale:Executed by:
executed 68 times by 16 tests: case QMetaType::QRect:Executed by:
executed 60 times by 8 tests: case QMetaType::QRectF:Executed by:
executed 58 times by 6 tests: case QMetaType::QSize:Executed by:
executed 57 times by 5 tests: case QMetaType::QSizeF:Executed by:
executed 56 times by 4 tests: case QMetaType::QLine:Executed by:
executed 56 times by 4 tests: case QMetaType::QLineF:Executed by:
executed 65 times by 13 tests: case QMetaType::QPoint:Executed by:
executed 59 times by 7 tests: case QMetaType::QPointF:Executed by:
executed 2 times by 2 tests: case QMetaType::QRegExp:Executed by:
executed 3 times by 3 tests: case QMetaType::QEasingCurve:Executed by:
executed 2 times by 2 tests: case QMetaType::QUuid:Executed by:
executed 119 times by 95 tests: case QMetaType::QVariant:Executed by:
executed 12 times by 12 tests: case QMetaType::QModelIndex:Executed by:
executed 2 times by 2 tests: case QMetaType::QRegularExpression:Executed by:
executed 2 times by 2 tests: case QMetaType::QJsonValue:Executed by:
executed 2 times by 2 tests: case QMetaType::QJsonObject:Executed by:
executed 2 times by 2 tests: case QMetaType::QJsonArray:Executed by:
executed 2 times by 2 tests: case QMetaType::QJsonDocument:Executed by:
executed 3 times by 3 tests: case QMetaType::QPersistentModelIndex:Executed by:
executed 20 times by 20 tests: case QMetaType::QObjectStar:Executed by:
executed 75 times by 22 tests: case QMetaType::QVariantMap:Executed by:
executed 18 times by 13 tests: case QMetaType::QVariantList:Executed by:
executed 83 times by 7 tests: case QMetaType::QVariantHash:Executed by:
executed 2 times by 2 tests: case QMetaType::QByteArrayList:Executed by:
executed 4 times by 4 tests: case QMetaType::QFont:Executed by:
executed 4 times by 4 tests: case QMetaType::QPixmap:Executed by:
executed 4 times by 4 tests: case QMetaType::QBrush:Executed by:
executed 4 times by 4 tests: case QMetaType::QColor:Executed by:
executed 5 times by 5 tests: case QMetaType::QPalette:Executed by:
executed 11 times by 11 tests: case QMetaType::QIcon:Executed by:
executed 5 times by 5 tests: case QMetaType::QImage:Executed by:
executed 4 times by 4 tests: case QMetaType::QPolygon:Executed by:
executed 4 times by 4 tests: case QMetaType::QRegion:Executed by:
executed 4 times by 4 tests: case QMetaType::QBitmap:Executed by:
executed 4 times by 4 tests: case QMetaType::QCursor:Executed by:
executed 5 times by 5 tests: case QMetaType::QKeySequence:Executed by:
executed 4 times by 4 tests: case QMetaType::QPen:Executed by:
executed 4 times by 4 tests: case QMetaType::QTextLength:Executed by:
executed 4 times by 4 tests: case QMetaType::QTextFormat:Executed by:
executed 5 times by 5 tests: case QMetaType::QMatrix:Executed by:
executed 5 times by 5 tests: case QMetaType::QTransform:Executed by:
executed 5 times by 5 tests: case QMetaType::QMatrix4x4:Executed by:
executed 5 times by 5 tests: case QMetaType::QVector2D:Executed by:
executed 5 times by 5 tests: case QMetaType::QVector3D:Executed by:
executed 5 times by 5 tests: case QMetaType::QVector4D:Executed by:
executed 5 times by 5 tests: case QMetaType::QQuaternion:Executed by:
executed 3 times by 3 tests: case QMetaType::QPolygonF:Executed by:
executed 3 times by 3 tests: case QMetaType::QSizePolicy:Executed by:
| 2-428 | ||||||||||||||||||||||||
| 853 | - | |||||||||||||||||||||||||
| 854 | case QMetaType::UnknownType: executed 7779 times by 197 tests: default:Executed by:
| 7779 | ||||||||||||||||||||||||
| case QMetaType::User executed 7779 times by 197 tests: default: break;default:Executed by:
executed 7779 times by 197 tests: default:Executed by:
| ||||||||||||||||||||||||||
| } executed 7779 times by 197 tests: {default:Executed by:
executed 7779 times by 197 tests: default:Executed by:
| ||||||||||||||||||||||||||
| 855 | if (Q_UNLIKELY(type < QMetaType::User)) {
| 962-6817 | ||||||||||||||||||||||||
| 856 | return Q_NULLPTR0; // It can happen when someone cast int to QVariant::Type, we should not crash... executed 962 times by 5 tests: return 0;Executed by:
| 962 | ||||||||||||||||||||||||
| 857 | } else { | - | ||||||||||||||||||||||||
| 858 | const QVector<QCustomTypeInfo> * const ct = customTypes(); | - | ||||||||||||||||||||||||
| 859 | QReadLocker locker(customTypesLock()); | - | ||||||||||||||||||||||||
| 860 | return ct && uint(ct->count()) > type - QMetaType::User && !ct->at(type - QMetaType::User).typeName.isEmpty() executed 6817 times by 195 tests: return ct && uint(ct->count()) > type - QMetaType::User && !ct->at(type - QMetaType::User).typeName.isEmpty() ? ct->at(type - QMetaType::User).typeName.constData() : 0;Executed by:
| 6817 | ||||||||||||||||||||||||
| 861 | ? ct->at(type - QMetaType::User).typeName.constData() executed 6817 times by 195 tests: return ct && uint(ct->count()) > type - QMetaType::User && !ct->at(type - QMetaType::User).typeName.isEmpty() ? ct->at(type - QMetaType::User).typeName.constData() : 0;Executed by:
| 6817 | ||||||||||||||||||||||||
| 862 | : Q_NULLPTR0; executed 6817 times by 195 tests: return ct && uint(ct->count()) > type - QMetaType::User && !ct->at(type - QMetaType::User).typeName.isEmpty() ? ct->at(type - QMetaType::User).typeName.constData() : 0;Executed by:
| 6817 | ||||||||||||||||||||||||
| 863 | } | - | ||||||||||||||||||||||||
| 864 | } | - | ||||||||||||||||||||||||
| 865 | } | - | ||||||||||||||||||||||||
| 866 | #undef QT_METATYPE_TYPEID_TYPENAME_CONVERTER | - | ||||||||||||||||||||||||
| 867 | - | |||||||||||||||||||||||||
| 868 | Q_ASSERT(type <= QMetaType::HighestInternalId); | - | ||||||||||||||||||||||||
| 869 | namesCache[type] = result; | - | ||||||||||||||||||||||||
| 870 | return result; executed 4624 times by 241 tests: return result;Executed by:
| 4624 | ||||||||||||||||||||||||
| 871 | } | - | ||||||||||||||||||||||||
| 872 | - | |||||||||||||||||||||||||
| 873 | /*! | - | ||||||||||||||||||||||||
| 874 | \internal | - | ||||||||||||||||||||||||
| 875 | Similar to QMetaType::type(), but only looks in the static set of types. | - | ||||||||||||||||||||||||
| 876 | */ | - | ||||||||||||||||||||||||
| 877 | static inline int qMetaTypeStaticType(const char *typeName, int length) | - | ||||||||||||||||||||||||
| 878 | { | - | ||||||||||||||||||||||||
| 879 | int i = 0; | - | ||||||||||||||||||||||||
| 880 | while (types[i].typeName && ((length != types[i].typeNameLength) | - | ||||||||||||||||||||||||
| 881 | || memcmp(typeName, types[i].typeName, length))) { | - | ||||||||||||||||||||||||
| 882 | ++i; | - | ||||||||||||||||||||||||
| 883 | } | - | ||||||||||||||||||||||||
| 884 | return types[i].type; | - | ||||||||||||||||||||||||
| 885 | } | - | ||||||||||||||||||||||||
| 886 | - | |||||||||||||||||||||||||
| 887 | /*! | - | ||||||||||||||||||||||||
| 888 | \internal | - | ||||||||||||||||||||||||
| 889 | Similar to QMetaType::type(), but only looks in the custom set of | - | ||||||||||||||||||||||||
| 890 | types, and doesn't lock the mutex. | - | ||||||||||||||||||||||||
| 891 | The extra \a firstInvalidIndex parameter is an easy way to avoid | - | ||||||||||||||||||||||||
| 892 | iterating over customTypes() a second time in registerNormalizedType(). | - | ||||||||||||||||||||||||
| 893 | */ | - | ||||||||||||||||||||||||
| 894 | static int qMetaTypeCustomType_unlocked(const char *typeName, int length, int *firstInvalidIndex = 0) | - | ||||||||||||||||||||||||
| 895 | { | - | ||||||||||||||||||||||||
| 896 | const QVector<QCustomTypeInfo> * const ct = customTypes(); | - | ||||||||||||||||||||||||
| 897 | if (!ct) | - | ||||||||||||||||||||||||
| 898 | return QMetaType::UnknownType; | - | ||||||||||||||||||||||||
| 899 | - | |||||||||||||||||||||||||
| 900 | if (firstInvalidIndex) | - | ||||||||||||||||||||||||
| 901 | *firstInvalidIndex = -1; | - | ||||||||||||||||||||||||
| 902 | for (int v = 0; v < ct->count(); ++v) { | - | ||||||||||||||||||||||||
| 903 | const QCustomTypeInfo &customInfo = ct->at(v); | - | ||||||||||||||||||||||||
| 904 | if ((length == customInfo.typeName.size()) | - | ||||||||||||||||||||||||
| 905 | && !memcmp(typeName, customInfo.typeName.constData(), length)) { | - | ||||||||||||||||||||||||
| 906 | if (customInfo.alias >= 0) | - | ||||||||||||||||||||||||
| 907 | return customInfo.alias; | - | ||||||||||||||||||||||||
| 908 | return v + QMetaType::User; | - | ||||||||||||||||||||||||
| 909 | } | - | ||||||||||||||||||||||||
| 910 | if (firstInvalidIndex && (*firstInvalidIndex < 0) && customInfo.typeName.isEmpty()) | - | ||||||||||||||||||||||||
| 911 | *firstInvalidIndex = v; | - | ||||||||||||||||||||||||
| 912 | } | - | ||||||||||||||||||||||||
| 913 | return QMetaType::UnknownType; | - | ||||||||||||||||||||||||
| 914 | } | - | ||||||||||||||||||||||||
| 915 | - | |||||||||||||||||||||||||
| 916 | /*! | - | ||||||||||||||||||||||||
| 917 | \internal | - | ||||||||||||||||||||||||
| 918 | - | |||||||||||||||||||||||||
| 919 | This function is needed until existing code outside of qtbase | - | ||||||||||||||||||||||||
| 920 | has been changed to call the new version of registerType(). | - | ||||||||||||||||||||||||
| 921 | */ | - | ||||||||||||||||||||||||
| 922 | int QMetaType::registerType(const char *typeName, Deleter deleter, | - | ||||||||||||||||||||||||
| 923 | Creator creator) | - | ||||||||||||||||||||||||
| 924 | { | - | ||||||||||||||||||||||||
| 925 | return registerType(typeName, deleter, creator, | - | ||||||||||||||||||||||||
| 926 | QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Destruct, | - | ||||||||||||||||||||||||
| 927 | QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Construct, 0, TypeFlags(), 0); | - | ||||||||||||||||||||||||
| 928 | } | - | ||||||||||||||||||||||||
| 929 | - | |||||||||||||||||||||||||
| 930 | /*! | - | ||||||||||||||||||||||||
| 931 | \internal | - | ||||||||||||||||||||||||
| 932 | \since 5.5 | - | ||||||||||||||||||||||||
| 933 | - | |||||||||||||||||||||||||
| 934 | Unregisters the user type with the given \a typeId and all its aliases. | - | ||||||||||||||||||||||||
| 935 | Returns \c true if the type was unregistered or \c false otherwise. | - | ||||||||||||||||||||||||
| 936 | - | |||||||||||||||||||||||||
| 937 | This function was added for QML to be able to deregister types after | - | ||||||||||||||||||||||||
| 938 | they are unloaded to prevent an infinite increase in custom types for | - | ||||||||||||||||||||||||
| 939 | applications that are unloading/reloading components often. | - | ||||||||||||||||||||||||
| 940 | */ | - | ||||||||||||||||||||||||
| 941 | bool QMetaType::unregisterType(int type) | - | ||||||||||||||||||||||||
| 942 | { | - | ||||||||||||||||||||||||
| 943 | QWriteLocker locker(customTypesLock()); | - | ||||||||||||||||||||||||
| 944 | QVector<QCustomTypeInfo> *ct = customTypes(); | - | ||||||||||||||||||||||||
| 945 | - | |||||||||||||||||||||||||
| 946 | // check if user type | - | ||||||||||||||||||||||||
| 947 | if ((type < User) || ((type - User) >= ct->size())) | - | ||||||||||||||||||||||||
| 948 | return false; | - | ||||||||||||||||||||||||
| 949 | - | |||||||||||||||||||||||||
| 950 | // only types without Q_DECLARE_METATYPE can be unregistered | - | ||||||||||||||||||||||||
| 951 | if (ct->data()[type - User].flags & WasDeclaredAsMetaType) | - | ||||||||||||||||||||||||
| 952 | return false; | - | ||||||||||||||||||||||||
| 953 | - | |||||||||||||||||||||||||
| 954 | // invalidate type and all its alias entries | - | ||||||||||||||||||||||||
| 955 | for (int v = 0; v < ct->count(); ++v) { | - | ||||||||||||||||||||||||
| 956 | if (((v + User) == type) || (ct->at(v).alias == type)) | - | ||||||||||||||||||||||||
| 957 | ct->data()[v].typeName.clear(); | - | ||||||||||||||||||||||||
| 958 | } | - | ||||||||||||||||||||||||
| 959 | return true; | - | ||||||||||||||||||||||||
| 960 | } | - | ||||||||||||||||||||||||
| 961 | - | |||||||||||||||||||||||||
| 962 | - | |||||||||||||||||||||||||
| 963 | /*! | - | ||||||||||||||||||||||||
| 964 | \internal | - | ||||||||||||||||||||||||
| 965 | \since 5.0 | - | ||||||||||||||||||||||||
| 966 | - | |||||||||||||||||||||||||
| 967 | Registers a user type for marshalling, with \a typeName, a \a | - | ||||||||||||||||||||||||
| 968 | deleter, a \a creator, a \a destructor, a \a constructor, and | - | ||||||||||||||||||||||||
| 969 | a \a size. Returns the type's handle, or -1 if the type could | - | ||||||||||||||||||||||||
| 970 | not be registered. | - | ||||||||||||||||||||||||
| 971 | */ | - | ||||||||||||||||||||||||
| 972 | int QMetaType::registerType(const char *typeName, Deleter deleter, | - | ||||||||||||||||||||||||
| 973 | Creator creator, | - | ||||||||||||||||||||||||
| 974 | Destructor destructor, | - | ||||||||||||||||||||||||
| 975 | Constructor constructor, | - | ||||||||||||||||||||||||
| 976 | int size, TypeFlags flags, const QMetaObject *metaObject) | - | ||||||||||||||||||||||||
| 977 | { | - | ||||||||||||||||||||||||
| 978 | #ifdef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 979 | NS(QByteArray) normalizedTypeName = typeName; | - | ||||||||||||||||||||||||
| 980 | #else | - | ||||||||||||||||||||||||
| 981 | NS(QByteArray) normalizedTypeName = QMetaObject::normalizedType(typeName); | - | ||||||||||||||||||||||||
| 982 | #endif | - | ||||||||||||||||||||||||
| 983 | - | |||||||||||||||||||||||||
| 984 | return registerNormalizedType(normalizedTypeName, deleter, creator, destructor, constructor, size, flags, metaObject); | - | ||||||||||||||||||||||||
| 985 | } | - | ||||||||||||||||||||||||
| 986 | - | |||||||||||||||||||||||||
| 987 | - | |||||||||||||||||||||||||
| 988 | /*! | - | ||||||||||||||||||||||||
| 989 | \internal | - | ||||||||||||||||||||||||
| 990 | \since 5.0 | - | ||||||||||||||||||||||||
| 991 | \overload | - | ||||||||||||||||||||||||
| 992 | Don't use, kept for binary compatibility | - | ||||||||||||||||||||||||
| 993 | - | |||||||||||||||||||||||||
| 994 | ### TODO Qt6: remove me | - | ||||||||||||||||||||||||
| 995 | */ | - | ||||||||||||||||||||||||
| 996 | int QMetaType::registerNormalizedType(const NS(QByteArray) &normalizedTypeName, Deleter deleter, | - | ||||||||||||||||||||||||
| 997 | Creator creator, | - | ||||||||||||||||||||||||
| 998 | Destructor destructor, | - | ||||||||||||||||||||||||
| 999 | Constructor constructor, | - | ||||||||||||||||||||||||
| 1000 | int size, TypeFlags flags, const QMetaObject *metaObject) | - | ||||||||||||||||||||||||
| 1001 | { | - | ||||||||||||||||||||||||
| 1002 | Q_UNUSED(deleter); | - | ||||||||||||||||||||||||
| 1003 | Q_UNUSED(creator); | - | ||||||||||||||||||||||||
| 1004 | return registerNormalizedType(normalizedTypeName, destructor, constructor, size, flags, metaObject); | - | ||||||||||||||||||||||||
| 1005 | } | - | ||||||||||||||||||||||||
| 1006 | - | |||||||||||||||||||||||||
| 1007 | - | |||||||||||||||||||||||||
| 1008 | /*! | - | ||||||||||||||||||||||||
| 1009 | \internal | - | ||||||||||||||||||||||||
| 1010 | \since 5.5 | - | ||||||||||||||||||||||||
| 1011 | - | |||||||||||||||||||||||||
| 1012 | Registers a user type for marshalling, with \a normalizedTypeName, | - | ||||||||||||||||||||||||
| 1013 | a \a destructor, a \a constructor, and a \a size. Returns the type's | - | ||||||||||||||||||||||||
| 1014 | handle, or -1 if the type could not be registered. | - | ||||||||||||||||||||||||
| 1015 | - | |||||||||||||||||||||||||
| 1016 | \note normalizedTypeName is not checked for conformance with | - | ||||||||||||||||||||||||
| 1017 | Qt's normalized format, so it must already conform. | - | ||||||||||||||||||||||||
| 1018 | */ | - | ||||||||||||||||||||||||
| 1019 | int QMetaType::registerNormalizedType(const NS(QByteArray) &normalizedTypeName, | - | ||||||||||||||||||||||||
| 1020 | Destructor destructor, | - | ||||||||||||||||||||||||
| 1021 | Constructor constructor, | - | ||||||||||||||||||||||||
| 1022 | int size, TypeFlags flags, const QMetaObject *metaObject) | - | ||||||||||||||||||||||||
| 1023 | { | - | ||||||||||||||||||||||||
| 1024 | QVector<QCustomTypeInfo> *ct = customTypes(); | - | ||||||||||||||||||||||||
| 1025 | if (!ct || normalizedTypeName.isEmpty() || !destructor || !constructor)
| 0-24484 | ||||||||||||||||||||||||
| 1026 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
| 1027 | - | |||||||||||||||||||||||||
| 1028 | int idx = qMetaTypeStaticType(normalizedTypeName.constData(), | - | ||||||||||||||||||||||||
| 1029 | normalizedTypeName.size()); | - | ||||||||||||||||||||||||
| 1030 | - | |||||||||||||||||||||||||
| 1031 | int previousSize = 0; | - | ||||||||||||||||||||||||
| 1032 | int previousFlags = 0; | - | ||||||||||||||||||||||||
| 1033 | if (idx == UnknownType) {
| 0-24484 | ||||||||||||||||||||||||
| 1034 | QWriteLocker locker(customTypesLock()); | - | ||||||||||||||||||||||||
| 1035 | int posInVector = -1; | - | ||||||||||||||||||||||||
| 1036 | idx = qMetaTypeCustomType_unlocked(normalizedTypeName.constData(), | - | ||||||||||||||||||||||||
| 1037 | normalizedTypeName.size(), | - | ||||||||||||||||||||||||
| 1038 | &posInVector); | - | ||||||||||||||||||||||||
| 1039 | if (idx == UnknownType) {
| 12024-12460 | ||||||||||||||||||||||||
| 1040 | QCustomTypeInfo inf; | - | ||||||||||||||||||||||||
| 1041 | inf.typeName = normalizedTypeName; | - | ||||||||||||||||||||||||
| 1042 | #ifndef QT_NO_DATASTREAM | - | ||||||||||||||||||||||||
| 1043 | inf.loadOp = 0; | - | ||||||||||||||||||||||||
| 1044 | inf.saveOp = 0; | - | ||||||||||||||||||||||||
| 1045 | #endif | - | ||||||||||||||||||||||||
| 1046 | inf.alias = -1; | - | ||||||||||||||||||||||||
| 1047 | inf.constructor = constructor; | - | ||||||||||||||||||||||||
| 1048 | inf.destructor = destructor; | - | ||||||||||||||||||||||||
| 1049 | inf.size = size; | - | ||||||||||||||||||||||||
| 1050 | inf.flags = flags; | - | ||||||||||||||||||||||||
| 1051 | inf.metaObject = metaObject; | - | ||||||||||||||||||||||||
| 1052 | if (posInVector == -1) {
| 3-12021 | ||||||||||||||||||||||||
| 1053 | idx = ct->size() + User; | - | ||||||||||||||||||||||||
| 1054 | ct->append(inf); | - | ||||||||||||||||||||||||
| 1055 | } else { executed 12021 times by 321 tests: end of blockExecuted by:
| 12021 | ||||||||||||||||||||||||
| 1056 | idx = posInVector + User; | - | ||||||||||||||||||||||||
| 1057 | ct->data()[posInVector] = inf; | - | ||||||||||||||||||||||||
| 1058 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||||||||
| 1059 | return idx; executed 12024 times by 321 tests: return idx;Executed by:
| 12024 | ||||||||||||||||||||||||
| 1060 | } | - | ||||||||||||||||||||||||
| 1061 | - | |||||||||||||||||||||||||
| 1062 | if (idx >= User) {
| 0-12460 | ||||||||||||||||||||||||
| 1063 | previousSize = ct->at(idx - User).size; | - | ||||||||||||||||||||||||
| 1064 | previousFlags = ct->at(idx - User).flags; | - | ||||||||||||||||||||||||
| 1065 | - | |||||||||||||||||||||||||
| 1066 | // Set new/additional flags in case of old library/app. | - | ||||||||||||||||||||||||
| 1067 | // Ensures that older code works in conjunction with new Qt releases | - | ||||||||||||||||||||||||
| 1068 | // requiring the new flags. | - | ||||||||||||||||||||||||
| 1069 | if (flags != previousFlags) {
| 0-12460 | ||||||||||||||||||||||||
| 1070 | QCustomTypeInfo &inf = ct->data()[idx - User]; | - | ||||||||||||||||||||||||
| 1071 | inf.flags |= flags; | - | ||||||||||||||||||||||||
| 1072 | if (metaObject)
| 0 | ||||||||||||||||||||||||
| 1073 | inf.metaObject = metaObject; never executed: inf.metaObject = metaObject; | 0 | ||||||||||||||||||||||||
| 1074 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1075 | } executed 12460 times by 83 tests: end of blockExecuted by:
| 12460 | ||||||||||||||||||||||||
| 1076 | } executed 12460 times by 83 tests: end of blockExecuted by:
| 12460 | ||||||||||||||||||||||||
| 1077 | - | |||||||||||||||||||||||||
| 1078 | if (idx < User) {
| 0-12460 | ||||||||||||||||||||||||
| 1079 | previousSize = QMetaType::sizeOf(idx); | - | ||||||||||||||||||||||||
| 1080 | previousFlags = QMetaType::typeFlags(idx); | - | ||||||||||||||||||||||||
| 1081 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1082 | - | |||||||||||||||||||||||||
| 1083 | if (Q_UNLIKELY(previousSize != size))) {
| 0-12460 | ||||||||||||||||||||||||
| 1084 | qFatal("QMetaType::registerType: Binary compatibility break " | - | ||||||||||||||||||||||||
| 1085 | "-- Size mismatch for type '%s' [%i]. Previously registered " | - | ||||||||||||||||||||||||
| 1086 | "size %i, now registering size %i.", | - | ||||||||||||||||||||||||
| 1087 | normalizedTypeName.constData(), idx, previousSize, size); | - | ||||||||||||||||||||||||
| 1088 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1089 | - | |||||||||||||||||||||||||
| 1090 | // these flags cannot change in a binary compatible way: | - | ||||||||||||||||||||||||
| 1091 | const int binaryCompatibilityFlag = PointerToQObject | IsEnumeration | SharedPointerToQObject | - | ||||||||||||||||||||||||
| 1092 | | WeakPointerToQObject | TrackingPointerToQObject; | - | ||||||||||||||||||||||||
| 1093 | if (Q_UNLIKELY((previousFlags ^ flags) & binaryCompatibilityFlag))) {
| 0-12460 | ||||||||||||||||||||||||
| 1094 | - | |||||||||||||||||||||||||
| 1095 | const char *msg = "QMetaType::registerType: Binary compatibility break. " | - | ||||||||||||||||||||||||
| 1096 | "\nType flags for type '%s' [%i] don't match. Previously " | - | ||||||||||||||||||||||||
| 1097 | "registered TypeFlags(0x%x), now registering TypeFlags(0x%x). "; | - | ||||||||||||||||||||||||
| 1098 | - | |||||||||||||||||||||||||
| 1099 | qFatal(msg, normalizedTypeName.constData(), idx, previousFlags, int(flags)); | - | ||||||||||||||||||||||||
| 1100 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1101 | - | |||||||||||||||||||||||||
| 1102 | return idx; executed 12460 times by 83 tests: return idx;Executed by:
| 12460 | ||||||||||||||||||||||||
| 1103 | } | - | ||||||||||||||||||||||||
| 1104 | - | |||||||||||||||||||||||||
| 1105 | /*! | - | ||||||||||||||||||||||||
| 1106 | \internal | - | ||||||||||||||||||||||||
| 1107 | \since 4.7 | - | ||||||||||||||||||||||||
| 1108 | - | |||||||||||||||||||||||||
| 1109 | Registers a user type for marshalling, as an alias of another type (typedef) | - | ||||||||||||||||||||||||
| 1110 | */ | - | ||||||||||||||||||||||||
| 1111 | int QMetaType::registerTypedef(const char* typeName, int aliasId) | - | ||||||||||||||||||||||||
| 1112 | { | - | ||||||||||||||||||||||||
| 1113 | #ifdef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 1114 | NS(QByteArray) normalizedTypeName = typeName; | - | ||||||||||||||||||||||||
| 1115 | #else | - | ||||||||||||||||||||||||
| 1116 | NS(QByteArray) normalizedTypeName = QMetaObject::normalizedType(typeName); | - | ||||||||||||||||||||||||
| 1117 | #endif | - | ||||||||||||||||||||||||
| 1118 | - | |||||||||||||||||||||||||
| 1119 | return registerNormalizedTypedef(normalizedTypeName, aliasId); | - | ||||||||||||||||||||||||
| 1120 | } | - | ||||||||||||||||||||||||
| 1121 | - | |||||||||||||||||||||||||
| 1122 | /*! | - | ||||||||||||||||||||||||
| 1123 | \internal | - | ||||||||||||||||||||||||
| 1124 | \since 5.0 | - | ||||||||||||||||||||||||
| 1125 | - | |||||||||||||||||||||||||
| 1126 | Registers a user type for marshalling, as an alias of another type (typedef). | - | ||||||||||||||||||||||||
| 1127 | Note that normalizedTypeName is not checked for conformance with Qt's normalized format, | - | ||||||||||||||||||||||||
| 1128 | so it must already conform. | - | ||||||||||||||||||||||||
| 1129 | */ | - | ||||||||||||||||||||||||
| 1130 | int QMetaType::registerNormalizedTypedef(const NS(QByteArray) &normalizedTypeName, int aliasId) | - | ||||||||||||||||||||||||
| 1131 | { | - | ||||||||||||||||||||||||
| 1132 | QVector<QCustomTypeInfo> *ct = customTypes(); | - | ||||||||||||||||||||||||
| 1133 | if (!ct || normalizedTypeName.isEmpty()) | - | ||||||||||||||||||||||||
| 1134 | return -1; | - | ||||||||||||||||||||||||
| 1135 | - | |||||||||||||||||||||||||
| 1136 | int idx = qMetaTypeStaticType(normalizedTypeName.constData(), | - | ||||||||||||||||||||||||
| 1137 | normalizedTypeName.size()); | - | ||||||||||||||||||||||||
| 1138 | - | |||||||||||||||||||||||||
| 1139 | if (idx == UnknownType) { | - | ||||||||||||||||||||||||
| 1140 | QWriteLocker locker(customTypesLock()); | - | ||||||||||||||||||||||||
| 1141 | int posInVector = -1; | - | ||||||||||||||||||||||||
| 1142 | idx = qMetaTypeCustomType_unlocked(normalizedTypeName.constData(), | - | ||||||||||||||||||||||||
| 1143 | normalizedTypeName.size(), | - | ||||||||||||||||||||||||
| 1144 | &posInVector); | - | ||||||||||||||||||||||||
| 1145 | - | |||||||||||||||||||||||||
| 1146 | if (idx == UnknownType) { | - | ||||||||||||||||||||||||
| 1147 | QCustomTypeInfo inf; | - | ||||||||||||||||||||||||
| 1148 | inf.typeName = normalizedTypeName; | - | ||||||||||||||||||||||||
| 1149 | inf.alias = aliasId; | - | ||||||||||||||||||||||||
| 1150 | if (posInVector == -1) | - | ||||||||||||||||||||||||
| 1151 | ct->append(inf); | - | ||||||||||||||||||||||||
| 1152 | else | - | ||||||||||||||||||||||||
| 1153 | ct->data()[posInVector] = inf; | - | ||||||||||||||||||||||||
| 1154 | return aliasId; | - | ||||||||||||||||||||||||
| 1155 | } | - | ||||||||||||||||||||||||
| 1156 | } | - | ||||||||||||||||||||||||
| 1157 | - | |||||||||||||||||||||||||
| 1158 | if (idx != aliasId) { | - | ||||||||||||||||||||||||
| 1159 | qWarning("QMetaType::registerTypedef: " | - | ||||||||||||||||||||||||
| 1160 | "-- Type name '%s' previously registered as typedef of '%s' [%i], " | - | ||||||||||||||||||||||||
| 1161 | "now registering as typedef of '%s' [%i].", | - | ||||||||||||||||||||||||
| 1162 | normalizedTypeName.constData(), QMetaType::typeName(idx), idx, | - | ||||||||||||||||||||||||
| 1163 | QMetaType::typeName(aliasId), aliasId); | - | ||||||||||||||||||||||||
| 1164 | } | - | ||||||||||||||||||||||||
| 1165 | return idx; | - | ||||||||||||||||||||||||
| 1166 | } | - | ||||||||||||||||||||||||
| 1167 | - | |||||||||||||||||||||||||
| 1168 | /*! | - | ||||||||||||||||||||||||
| 1169 | Returns \c true if the datatype with ID \a type is registered; | - | ||||||||||||||||||||||||
| 1170 | otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1171 | - | |||||||||||||||||||||||||
| 1172 | \sa type(), typeName(), Type | - | ||||||||||||||||||||||||
| 1173 | */ | - | ||||||||||||||||||||||||
| 1174 | bool QMetaType::isRegistered(int type) | - | ||||||||||||||||||||||||
| 1175 | { | - | ||||||||||||||||||||||||
| 1176 | // predefined type | - | ||||||||||||||||||||||||
| 1177 | if ((type >= FirstCoreType && type <= LastCoreType) | - | ||||||||||||||||||||||||
| 1178 | || (type >= FirstGuiType && type <= LastGuiType) | - | ||||||||||||||||||||||||
| 1179 | || (type >= FirstWidgetsType && type <= LastWidgetsType)) { | - | ||||||||||||||||||||||||
| 1180 | return true; | - | ||||||||||||||||||||||||
| 1181 | } | - | ||||||||||||||||||||||||
| 1182 | - | |||||||||||||||||||||||||
| 1183 | QReadLocker locker(customTypesLock()); | - | ||||||||||||||||||||||||
| 1184 | const QVector<QCustomTypeInfo> * const ct = customTypes(); | - | ||||||||||||||||||||||||
| 1185 | return ((type >= User) && (ct && ct->count() > type - User) && !ct->at(type - User).typeName.isEmpty()); | - | ||||||||||||||||||||||||
| 1186 | } | - | ||||||||||||||||||||||||
| 1187 | - | |||||||||||||||||||||||||
| 1188 | template <bool tryNormalizedType> | - | ||||||||||||||||||||||||
| 1189 | static inline int qMetaTypeTypeImpl(const char *typeName, int length) | - | ||||||||||||||||||||||||
| 1190 | { | - | ||||||||||||||||||||||||
| 1191 | if (!length) | - | ||||||||||||||||||||||||
| 1192 | return QMetaType::UnknownType; | - | ||||||||||||||||||||||||
| 1193 | int type = qMetaTypeStaticType(typeName, length); | - | ||||||||||||||||||||||||
| 1194 | if (type == QMetaType::UnknownType) { | - | ||||||||||||||||||||||||
| 1195 | QReadLocker locker(customTypesLock()); | - | ||||||||||||||||||||||||
| 1196 | type = qMetaTypeCustomType_unlocked(typeName, length); | - | ||||||||||||||||||||||||
| 1197 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 1198 | if ((type == QMetaType::UnknownType) && tryNormalizedType) { | - | ||||||||||||||||||||||||
| 1199 | const NS(QByteArray) normalizedTypeName = QMetaObject::normalizedType(typeName); | - | ||||||||||||||||||||||||
| 1200 | type = qMetaTypeStaticType(normalizedTypeName.constData(), | - | ||||||||||||||||||||||||
| 1201 | normalizedTypeName.size()); | - | ||||||||||||||||||||||||
| 1202 | if (type == QMetaType::UnknownType) { | - | ||||||||||||||||||||||||
| 1203 | type = qMetaTypeCustomType_unlocked(normalizedTypeName.constData(), | - | ||||||||||||||||||||||||
| 1204 | normalizedTypeName.size()); | - | ||||||||||||||||||||||||
| 1205 | } | - | ||||||||||||||||||||||||
| 1206 | } | - | ||||||||||||||||||||||||
| 1207 | #endif | - | ||||||||||||||||||||||||
| 1208 | } | - | ||||||||||||||||||||||||
| 1209 | return type; | - | ||||||||||||||||||||||||
| 1210 | } | - | ||||||||||||||||||||||||
| 1211 | - | |||||||||||||||||||||||||
| 1212 | /*! | - | ||||||||||||||||||||||||
| 1213 | Returns a handle to the type called \a typeName, or QMetaType::UnknownType if there is | - | ||||||||||||||||||||||||
| 1214 | no such type. | - | ||||||||||||||||||||||||
| 1215 | - | |||||||||||||||||||||||||
| 1216 | \sa isRegistered(), typeName(), Type | - | ||||||||||||||||||||||||
| 1217 | */ | - | ||||||||||||||||||||||||
| 1218 | int QMetaType::type(const char *typeName) | - | ||||||||||||||||||||||||
| 1219 | { | - | ||||||||||||||||||||||||
| 1220 | return qMetaTypeTypeImpl</*tryNormalizedType=*/true>(typeName, qstrlen(typeName)); | - | ||||||||||||||||||||||||
| 1221 | } | - | ||||||||||||||||||||||||
| 1222 | - | |||||||||||||||||||||||||
| 1223 | /*! | - | ||||||||||||||||||||||||
| 1224 | \a internal | - | ||||||||||||||||||||||||
| 1225 | - | |||||||||||||||||||||||||
| 1226 | Similar to QMetaType::type(); the only difference is that this function | - | ||||||||||||||||||||||||
| 1227 | doesn't attempt to normalize the type name (i.e., the lookup will fail | - | ||||||||||||||||||||||||
| 1228 | for type names in non-normalized form). | - | ||||||||||||||||||||||||
| 1229 | */ | - | ||||||||||||||||||||||||
| 1230 | int qMetaTypeTypeInternal(const char *typeName) | - | ||||||||||||||||||||||||
| 1231 | { | - | ||||||||||||||||||||||||
| 1232 | return qMetaTypeTypeImpl</*tryNormalizedType=*/false>(typeName, qstrlen(typeName)); | - | ||||||||||||||||||||||||
| 1233 | } | - | ||||||||||||||||||||||||
| 1234 | - | |||||||||||||||||||||||||
| 1235 | /*! | - | ||||||||||||||||||||||||
| 1236 | \since 5.5 | - | ||||||||||||||||||||||||
| 1237 | \overload | - | ||||||||||||||||||||||||
| 1238 | - | |||||||||||||||||||||||||
| 1239 | Returns a handle to the type called \a typeName, or 0 if there is | - | ||||||||||||||||||||||||
| 1240 | no such type. | - | ||||||||||||||||||||||||
| 1241 | - | |||||||||||||||||||||||||
| 1242 | \sa isRegistered(), typeName() | - | ||||||||||||||||||||||||
| 1243 | */ | - | ||||||||||||||||||||||||
| 1244 | int QMetaType::type(const QT_PREPEND_NAMESPACE(QByteArray) &typeName) | - | ||||||||||||||||||||||||
| 1245 | { | - | ||||||||||||||||||||||||
| 1246 | return qMetaTypeTypeImpl</*tryNormalizedType=*/true>(typeName.constData(), typeName.size()); | - | ||||||||||||||||||||||||
| 1247 | } | - | ||||||||||||||||||||||||
| 1248 | - | |||||||||||||||||||||||||
| 1249 | #ifndef QT_NO_DATASTREAM | - | ||||||||||||||||||||||||
| 1250 | /*! | - | ||||||||||||||||||||||||
| 1251 | Writes the object pointed to by \a data with the ID \a type to | - | ||||||||||||||||||||||||
| 1252 | the given \a stream. Returns \c true if the object is saved | - | ||||||||||||||||||||||||
| 1253 | successfully; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1254 | - | |||||||||||||||||||||||||
| 1255 | The type must have been registered with qRegisterMetaType() and | - | ||||||||||||||||||||||||
| 1256 | qRegisterMetaTypeStreamOperators() beforehand. | - | ||||||||||||||||||||||||
| 1257 | - | |||||||||||||||||||||||||
| 1258 | Normally, you should not need to call this function directly. | - | ||||||||||||||||||||||||
| 1259 | Instead, use QVariant's \c operator<<(), which relies on save() | - | ||||||||||||||||||||||||
| 1260 | to stream custom types. | - | ||||||||||||||||||||||||
| 1261 | - | |||||||||||||||||||||||||
| 1262 | \sa load(), qRegisterMetaTypeStreamOperators() | - | ||||||||||||||||||||||||
| 1263 | */ | - | ||||||||||||||||||||||||
| 1264 | bool QMetaType::save(QDataStream &stream, int type, const void *data) | - | ||||||||||||||||||||||||
| 1265 | { | - | ||||||||||||||||||||||||
| 1266 | if (!data || !isRegistered(type)) | - | ||||||||||||||||||||||||
| 1267 | return false; | - | ||||||||||||||||||||||||
| 1268 | - | |||||||||||||||||||||||||
| 1269 | switch(type) { | - | ||||||||||||||||||||||||
| 1270 | case QMetaType::UnknownType: | - | ||||||||||||||||||||||||
| 1271 | case QMetaType::Void: | - | ||||||||||||||||||||||||
| 1272 | case QMetaType::VoidStar: | - | ||||||||||||||||||||||||
| 1273 | case QMetaType::QObjectStar: | - | ||||||||||||||||||||||||
| 1274 | case QMetaType::QModelIndex: | - | ||||||||||||||||||||||||
| 1275 | case QMetaType::QPersistentModelIndex: | - | ||||||||||||||||||||||||
| 1276 | case QMetaType::QJsonValue: | - | ||||||||||||||||||||||||
| 1277 | case QMetaType::QJsonObject: | - | ||||||||||||||||||||||||
| 1278 | case QMetaType::QJsonArray: | - | ||||||||||||||||||||||||
| 1279 | case QMetaType::QJsonDocument: | - | ||||||||||||||||||||||||
| 1280 | return false; | - | ||||||||||||||||||||||||
| 1281 | case QMetaType::Long: | - | ||||||||||||||||||||||||
| 1282 | stream << qlonglong(*static_cast<const long *>(data)); | - | ||||||||||||||||||||||||
| 1283 | break; | - | ||||||||||||||||||||||||
| 1284 | case QMetaType::Int: | - | ||||||||||||||||||||||||
| 1285 | stream << *static_cast<const int *>(data); | - | ||||||||||||||||||||||||
| 1286 | break; | - | ||||||||||||||||||||||||
| 1287 | case QMetaType::Short: | - | ||||||||||||||||||||||||
| 1288 | stream << *static_cast<const short *>(data); | - | ||||||||||||||||||||||||
| 1289 | break; | - | ||||||||||||||||||||||||
| 1290 | case QMetaType::Char: | - | ||||||||||||||||||||||||
| 1291 | // force a char to be signed | - | ||||||||||||||||||||||||
| 1292 | stream << *static_cast<const signed char *>(data); | - | ||||||||||||||||||||||||
| 1293 | break; | - | ||||||||||||||||||||||||
| 1294 | case QMetaType::ULong: | - | ||||||||||||||||||||||||
| 1295 | stream << qulonglong(*static_cast<const ulong *>(data)); | - | ||||||||||||||||||||||||
| 1296 | break; | - | ||||||||||||||||||||||||
| 1297 | case QMetaType::UInt: | - | ||||||||||||||||||||||||
| 1298 | stream << *static_cast<const uint *>(data); | - | ||||||||||||||||||||||||
| 1299 | break; | - | ||||||||||||||||||||||||
| 1300 | case QMetaType::LongLong: | - | ||||||||||||||||||||||||
| 1301 | stream << *static_cast<const qlonglong *>(data); | - | ||||||||||||||||||||||||
| 1302 | break; | - | ||||||||||||||||||||||||
| 1303 | case QMetaType::ULongLong: | - | ||||||||||||||||||||||||
| 1304 | stream << *static_cast<const qulonglong *>(data); | - | ||||||||||||||||||||||||
| 1305 | break; | - | ||||||||||||||||||||||||
| 1306 | case QMetaType::UShort: | - | ||||||||||||||||||||||||
| 1307 | stream << *static_cast<const ushort *>(data); | - | ||||||||||||||||||||||||
| 1308 | break; | - | ||||||||||||||||||||||||
| 1309 | case QMetaType::SChar: | - | ||||||||||||||||||||||||
| 1310 | stream << *static_cast<const signed char *>(data); | - | ||||||||||||||||||||||||
| 1311 | break; | - | ||||||||||||||||||||||||
| 1312 | case QMetaType::UChar: | - | ||||||||||||||||||||||||
| 1313 | stream << *static_cast<const uchar *>(data); | - | ||||||||||||||||||||||||
| 1314 | break; | - | ||||||||||||||||||||||||
| 1315 | case QMetaType::Bool: | - | ||||||||||||||||||||||||
| 1316 | stream << qint8(*static_cast<const bool *>(data)); | - | ||||||||||||||||||||||||
| 1317 | break; | - | ||||||||||||||||||||||||
| 1318 | case QMetaType::Float: | - | ||||||||||||||||||||||||
| 1319 | stream << *static_cast<const float *>(data); | - | ||||||||||||||||||||||||
| 1320 | break; | - | ||||||||||||||||||||||||
| 1321 | case QMetaType::Double: | - | ||||||||||||||||||||||||
| 1322 | stream << *static_cast<const double *>(data); | - | ||||||||||||||||||||||||
| 1323 | break; | - | ||||||||||||||||||||||||
| 1324 | case QMetaType::QChar: | - | ||||||||||||||||||||||||
| 1325 | stream << *static_cast<const NS(QChar) *>(data); | - | ||||||||||||||||||||||||
| 1326 | break; | - | ||||||||||||||||||||||||
| 1327 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
| 1328 | case QMetaType::QVariantMap: | - | ||||||||||||||||||||||||
| 1329 | stream << *static_cast<const NS(QVariantMap)*>(data); | - | ||||||||||||||||||||||||
| 1330 | break; | - | ||||||||||||||||||||||||
| 1331 | case QMetaType::QVariantHash: | - | ||||||||||||||||||||||||
| 1332 | stream << *static_cast<const NS(QVariantHash)*>(data); | - | ||||||||||||||||||||||||
| 1333 | break; | - | ||||||||||||||||||||||||
| 1334 | case QMetaType::QVariantList: | - | ||||||||||||||||||||||||
| 1335 | stream << *static_cast<const NS(QVariantList)*>(data); | - | ||||||||||||||||||||||||
| 1336 | break; | - | ||||||||||||||||||||||||
| 1337 | case QMetaType::QVariant: | - | ||||||||||||||||||||||||
| 1338 | stream << *static_cast<const NS(QVariant)*>(data); | - | ||||||||||||||||||||||||
| 1339 | break; | - | ||||||||||||||||||||||||
| 1340 | case QMetaType::QByteArrayList: | - | ||||||||||||||||||||||||
| 1341 | stream << *static_cast<const NS(QByteArrayList)*>(data); | - | ||||||||||||||||||||||||
| 1342 | break; | - | ||||||||||||||||||||||||
| 1343 | #endif | - | ||||||||||||||||||||||||
| 1344 | case QMetaType::QByteArray: | - | ||||||||||||||||||||||||
| 1345 | stream << *static_cast<const NS(QByteArray)*>(data); | - | ||||||||||||||||||||||||
| 1346 | break; | - | ||||||||||||||||||||||||
| 1347 | case QMetaType::QString: | - | ||||||||||||||||||||||||
| 1348 | stream << *static_cast<const NS(QString)*>(data); | - | ||||||||||||||||||||||||
| 1349 | break; | - | ||||||||||||||||||||||||
| 1350 | case QMetaType::QStringList: | - | ||||||||||||||||||||||||
| 1351 | stream << *static_cast<const NS(QStringList)*>(data); | - | ||||||||||||||||||||||||
| 1352 | break; | - | ||||||||||||||||||||||||
| 1353 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
| 1354 | case QMetaType::QBitArray: | - | ||||||||||||||||||||||||
| 1355 | stream << *static_cast<const NS(QBitArray)*>(data); | - | ||||||||||||||||||||||||
| 1356 | break; | - | ||||||||||||||||||||||||
| 1357 | #endif | - | ||||||||||||||||||||||||
| 1358 | case QMetaType::QDate: | - | ||||||||||||||||||||||||
| 1359 | stream << *static_cast<const NS(QDate)*>(data); | - | ||||||||||||||||||||||||
| 1360 | break; | - | ||||||||||||||||||||||||
| 1361 | case QMetaType::QTime: | - | ||||||||||||||||||||||||
| 1362 | stream << *static_cast<const NS(QTime)*>(data); | - | ||||||||||||||||||||||||
| 1363 | break; | - | ||||||||||||||||||||||||
| 1364 | case QMetaType::QDateTime: | - | ||||||||||||||||||||||||
| 1365 | stream << *static_cast<const NS(QDateTime)*>(data); | - | ||||||||||||||||||||||||
| 1366 | break; | - | ||||||||||||||||||||||||
| 1367 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
| 1368 | case QMetaType::QUrl: | - | ||||||||||||||||||||||||
| 1369 | stream << *static_cast<const NS(QUrl)*>(data); | - | ||||||||||||||||||||||||
| 1370 | break; | - | ||||||||||||||||||||||||
| 1371 | #endif | - | ||||||||||||||||||||||||
| 1372 | case QMetaType::QLocale: | - | ||||||||||||||||||||||||
| 1373 | stream << *static_cast<const NS(QLocale)*>(data); | - | ||||||||||||||||||||||||
| 1374 | break; | - | ||||||||||||||||||||||||
| 1375 | #ifndef QT_NO_GEOM_VARIANT | - | ||||||||||||||||||||||||
| 1376 | case QMetaType::QRect: | - | ||||||||||||||||||||||||
| 1377 | stream << *static_cast<const NS(QRect)*>(data); | - | ||||||||||||||||||||||||
| 1378 | break; | - | ||||||||||||||||||||||||
| 1379 | case QMetaType::QRectF: | - | ||||||||||||||||||||||||
| 1380 | stream << *static_cast<const NS(QRectF)*>(data); | - | ||||||||||||||||||||||||
| 1381 | break; | - | ||||||||||||||||||||||||
| 1382 | case QMetaType::QSize: | - | ||||||||||||||||||||||||
| 1383 | stream << *static_cast<const NS(QSize)*>(data); | - | ||||||||||||||||||||||||
| 1384 | break; | - | ||||||||||||||||||||||||
| 1385 | case QMetaType::QSizeF: | - | ||||||||||||||||||||||||
| 1386 | stream << *static_cast<const NS(QSizeF)*>(data); | - | ||||||||||||||||||||||||
| 1387 | break; | - | ||||||||||||||||||||||||
| 1388 | case QMetaType::QLine: | - | ||||||||||||||||||||||||
| 1389 | stream << *static_cast<const NS(QLine)*>(data); | - | ||||||||||||||||||||||||
| 1390 | break; | - | ||||||||||||||||||||||||
| 1391 | case QMetaType::QLineF: | - | ||||||||||||||||||||||||
| 1392 | stream << *static_cast<const NS(QLineF)*>(data); | - | ||||||||||||||||||||||||
| 1393 | break; | - | ||||||||||||||||||||||||
| 1394 | case QMetaType::QPoint: | - | ||||||||||||||||||||||||
| 1395 | stream << *static_cast<const NS(QPoint)*>(data); | - | ||||||||||||||||||||||||
| 1396 | break; | - | ||||||||||||||||||||||||
| 1397 | case QMetaType::QPointF: | - | ||||||||||||||||||||||||
| 1398 | stream << *static_cast<const NS(QPointF)*>(data); | - | ||||||||||||||||||||||||
| 1399 | break; | - | ||||||||||||||||||||||||
| 1400 | #endif | - | ||||||||||||||||||||||||
| 1401 | #ifndef QT_NO_REGEXP | - | ||||||||||||||||||||||||
| 1402 | case QMetaType::QRegExp: | - | ||||||||||||||||||||||||
| 1403 | stream << *static_cast<const NS(QRegExp)*>(data); | - | ||||||||||||||||||||||||
| 1404 | break; | - | ||||||||||||||||||||||||
| 1405 | #endif | - | ||||||||||||||||||||||||
| 1406 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
| 1407 | #ifndef QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||||||||
| 1408 | case QMetaType::QRegularExpression: | - | ||||||||||||||||||||||||
| 1409 | stream << *static_cast<const NS(QRegularExpression)*>(data); | - | ||||||||||||||||||||||||
| 1410 | break; | - | ||||||||||||||||||||||||
| 1411 | #endif // QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||||||||
| 1412 | case QMetaType::QEasingCurve: | - | ||||||||||||||||||||||||
| 1413 | stream << *static_cast<const NS(QEasingCurve)*>(data); | - | ||||||||||||||||||||||||
| 1414 | break; | - | ||||||||||||||||||||||||
| 1415 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
| 1416 | case QMetaType::QFont: | - | ||||||||||||||||||||||||
| 1417 | case QMetaType::QPixmap: | - | ||||||||||||||||||||||||
| 1418 | case QMetaType::QBrush: | - | ||||||||||||||||||||||||
| 1419 | case QMetaType::QColor: | - | ||||||||||||||||||||||||
| 1420 | case QMetaType::QPalette: | - | ||||||||||||||||||||||||
| 1421 | case QMetaType::QImage: | - | ||||||||||||||||||||||||
| 1422 | case QMetaType::QPolygon: | - | ||||||||||||||||||||||||
| 1423 | case QMetaType::QPolygonF: | - | ||||||||||||||||||||||||
| 1424 | case QMetaType::QRegion: | - | ||||||||||||||||||||||||
| 1425 | case QMetaType::QBitmap: | - | ||||||||||||||||||||||||
| 1426 | case QMetaType::QCursor: | - | ||||||||||||||||||||||||
| 1427 | case QMetaType::QKeySequence: | - | ||||||||||||||||||||||||
| 1428 | case QMetaType::QPen: | - | ||||||||||||||||||||||||
| 1429 | case QMetaType::QTextLength: | - | ||||||||||||||||||||||||
| 1430 | case QMetaType::QTextFormat: | - | ||||||||||||||||||||||||
| 1431 | case QMetaType::QMatrix: | - | ||||||||||||||||||||||||
| 1432 | case QMetaType::QTransform: | - | ||||||||||||||||||||||||
| 1433 | case QMetaType::QMatrix4x4: | - | ||||||||||||||||||||||||
| 1434 | case QMetaType::QVector2D: | - | ||||||||||||||||||||||||
| 1435 | case QMetaType::QVector3D: | - | ||||||||||||||||||||||||
| 1436 | case QMetaType::QVector4D: | - | ||||||||||||||||||||||||
| 1437 | case QMetaType::QQuaternion: | - | ||||||||||||||||||||||||
| 1438 | case QMetaType::QIcon: | - | ||||||||||||||||||||||||
| 1439 | if (!qMetaTypeGuiHelper) | - | ||||||||||||||||||||||||
| 1440 | return false; | - | ||||||||||||||||||||||||
| 1441 | qMetaTypeGuiHelper[type - FirstGuiType].saveOp(stream, data); | - | ||||||||||||||||||||||||
| 1442 | break; | - | ||||||||||||||||||||||||
| 1443 | case QMetaType::QSizePolicy: | - | ||||||||||||||||||||||||
| 1444 | if (!qMetaTypeWidgetsHelper) | - | ||||||||||||||||||||||||
| 1445 | return false; | - | ||||||||||||||||||||||||
| 1446 | qMetaTypeWidgetsHelper[type - FirstWidgetsType].saveOp(stream, data); | - | ||||||||||||||||||||||||
| 1447 | break; | - | ||||||||||||||||||||||||
| 1448 | case QMetaType::QUuid: | - | ||||||||||||||||||||||||
| 1449 | stream << *static_cast<const NS(QUuid)*>(data); | - | ||||||||||||||||||||||||
| 1450 | break; | - | ||||||||||||||||||||||||
| 1451 | default: { | - | ||||||||||||||||||||||||
| 1452 | const QVector<QCustomTypeInfo> * const ct = customTypes(); | - | ||||||||||||||||||||||||
| 1453 | if (!ct) | - | ||||||||||||||||||||||||
| 1454 | return false; | - | ||||||||||||||||||||||||
| 1455 | - | |||||||||||||||||||||||||
| 1456 | SaveOperator saveOp = 0; | - | ||||||||||||||||||||||||
| 1457 | { | - | ||||||||||||||||||||||||
| 1458 | QReadLocker locker(customTypesLock()); | - | ||||||||||||||||||||||||
| 1459 | saveOp = ct->at(type - User).saveOp; | - | ||||||||||||||||||||||||
| 1460 | } | - | ||||||||||||||||||||||||
| 1461 | - | |||||||||||||||||||||||||
| 1462 | if (!saveOp) | - | ||||||||||||||||||||||||
| 1463 | return false; | - | ||||||||||||||||||||||||
| 1464 | saveOp(stream, data); | - | ||||||||||||||||||||||||
| 1465 | break; } | - | ||||||||||||||||||||||||
| 1466 | } | - | ||||||||||||||||||||||||
| 1467 | - | |||||||||||||||||||||||||
| 1468 | return true; | - | ||||||||||||||||||||||||
| 1469 | } | - | ||||||||||||||||||||||||
| 1470 | - | |||||||||||||||||||||||||
| 1471 | /*! | - | ||||||||||||||||||||||||
| 1472 | Reads the object of the specified \a type from the given \a | - | ||||||||||||||||||||||||
| 1473 | stream into \a data. Returns \c true if the object is loaded | - | ||||||||||||||||||||||||
| 1474 | successfully; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1475 | - | |||||||||||||||||||||||||
| 1476 | The type must have been registered with qRegisterMetaType() and | - | ||||||||||||||||||||||||
| 1477 | qRegisterMetaTypeStreamOperators() beforehand. | - | ||||||||||||||||||||||||
| 1478 | - | |||||||||||||||||||||||||
| 1479 | Normally, you should not need to call this function directly. | - | ||||||||||||||||||||||||
| 1480 | Instead, use QVariant's \c operator>>(), which relies on load() | - | ||||||||||||||||||||||||
| 1481 | to stream custom types. | - | ||||||||||||||||||||||||
| 1482 | - | |||||||||||||||||||||||||
| 1483 | \sa save(), qRegisterMetaTypeStreamOperators() | - | ||||||||||||||||||||||||
| 1484 | */ | - | ||||||||||||||||||||||||
| 1485 | bool QMetaType::load(QDataStream &stream, int type, void *data) | - | ||||||||||||||||||||||||
| 1486 | { | - | ||||||||||||||||||||||||
| 1487 | if (!data || !isRegistered(type)) | - | ||||||||||||||||||||||||
| 1488 | return false; | - | ||||||||||||||||||||||||
| 1489 | - | |||||||||||||||||||||||||
| 1490 | switch(type) { | - | ||||||||||||||||||||||||
| 1491 | case QMetaType::UnknownType: | - | ||||||||||||||||||||||||
| 1492 | case QMetaType::Void: | - | ||||||||||||||||||||||||
| 1493 | case QMetaType::VoidStar: | - | ||||||||||||||||||||||||
| 1494 | case QMetaType::QObjectStar: | - | ||||||||||||||||||||||||
| 1495 | case QMetaType::QModelIndex: | - | ||||||||||||||||||||||||
| 1496 | case QMetaType::QPersistentModelIndex: | - | ||||||||||||||||||||||||
| 1497 | case QMetaType::QJsonValue: | - | ||||||||||||||||||||||||
| 1498 | case QMetaType::QJsonObject: | - | ||||||||||||||||||||||||
| 1499 | case QMetaType::QJsonArray: | - | ||||||||||||||||||||||||
| 1500 | case QMetaType::QJsonDocument: | - | ||||||||||||||||||||||||
| 1501 | return false; | - | ||||||||||||||||||||||||
| 1502 | case QMetaType::Long: { | - | ||||||||||||||||||||||||
| 1503 | qlonglong l; | - | ||||||||||||||||||||||||
| 1504 | stream >> l; | - | ||||||||||||||||||||||||
| 1505 | *static_cast<long *>(data) = long(l); | - | ||||||||||||||||||||||||
| 1506 | break; } | - | ||||||||||||||||||||||||
| 1507 | case QMetaType::Int: | - | ||||||||||||||||||||||||
| 1508 | stream >> *static_cast<int *>(data); | - | ||||||||||||||||||||||||
| 1509 | break; | - | ||||||||||||||||||||||||
| 1510 | case QMetaType::Short: | - | ||||||||||||||||||||||||
| 1511 | stream >> *static_cast<short *>(data); | - | ||||||||||||||||||||||||
| 1512 | break; | - | ||||||||||||||||||||||||
| 1513 | case QMetaType::Char: | - | ||||||||||||||||||||||||
| 1514 | // force a char to be signed | - | ||||||||||||||||||||||||
| 1515 | stream >> *static_cast<signed char *>(data); | - | ||||||||||||||||||||||||
| 1516 | break; | - | ||||||||||||||||||||||||
| 1517 | case QMetaType::ULong: { | - | ||||||||||||||||||||||||
| 1518 | qulonglong ul; | - | ||||||||||||||||||||||||
| 1519 | stream >> ul; | - | ||||||||||||||||||||||||
| 1520 | *static_cast<ulong *>(data) = ulong(ul); | - | ||||||||||||||||||||||||
| 1521 | break; } | - | ||||||||||||||||||||||||
| 1522 | case QMetaType::UInt: | - | ||||||||||||||||||||||||
| 1523 | stream >> *static_cast<uint *>(data); | - | ||||||||||||||||||||||||
| 1524 | break; | - | ||||||||||||||||||||||||
| 1525 | case QMetaType::LongLong: | - | ||||||||||||||||||||||||
| 1526 | stream >> *static_cast<qlonglong *>(data); | - | ||||||||||||||||||||||||
| 1527 | break; | - | ||||||||||||||||||||||||
| 1528 | case QMetaType::ULongLong: | - | ||||||||||||||||||||||||
| 1529 | stream >> *static_cast<qulonglong *>(data); | - | ||||||||||||||||||||||||
| 1530 | break; | - | ||||||||||||||||||||||||
| 1531 | case QMetaType::UShort: | - | ||||||||||||||||||||||||
| 1532 | stream >> *static_cast<ushort *>(data); | - | ||||||||||||||||||||||||
| 1533 | break; | - | ||||||||||||||||||||||||
| 1534 | case QMetaType::SChar: | - | ||||||||||||||||||||||||
| 1535 | stream >> *static_cast<signed char *>(data); | - | ||||||||||||||||||||||||
| 1536 | break; | - | ||||||||||||||||||||||||
| 1537 | case QMetaType::UChar: | - | ||||||||||||||||||||||||
| 1538 | stream >> *static_cast<uchar *>(data); | - | ||||||||||||||||||||||||
| 1539 | break; | - | ||||||||||||||||||||||||
| 1540 | case QMetaType::Bool: { | - | ||||||||||||||||||||||||
| 1541 | qint8 b; | - | ||||||||||||||||||||||||
| 1542 | stream >> b; | - | ||||||||||||||||||||||||
| 1543 | *static_cast<bool *>(data) = b; | - | ||||||||||||||||||||||||
| 1544 | break; } | - | ||||||||||||||||||||||||
| 1545 | case QMetaType::Float: | - | ||||||||||||||||||||||||
| 1546 | stream >> *static_cast<float *>(data); | - | ||||||||||||||||||||||||
| 1547 | break; | - | ||||||||||||||||||||||||
| 1548 | case QMetaType::Double: | - | ||||||||||||||||||||||||
| 1549 | stream >> *static_cast<double *>(data); | - | ||||||||||||||||||||||||
| 1550 | break; | - | ||||||||||||||||||||||||
| 1551 | case QMetaType::QChar: | - | ||||||||||||||||||||||||
| 1552 | stream >> *static_cast< NS(QChar)*>(data); | - | ||||||||||||||||||||||||
| 1553 | break; | - | ||||||||||||||||||||||||
| 1554 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
| 1555 | case QMetaType::QVariantMap: | - | ||||||||||||||||||||||||
| 1556 | stream >> *static_cast< NS(QVariantMap)*>(data); | - | ||||||||||||||||||||||||
| 1557 | break; | - | ||||||||||||||||||||||||
| 1558 | case QMetaType::QVariantHash: | - | ||||||||||||||||||||||||
| 1559 | stream >> *static_cast< NS(QVariantHash)*>(data); | - | ||||||||||||||||||||||||
| 1560 | break; | - | ||||||||||||||||||||||||
| 1561 | case QMetaType::QVariantList: | - | ||||||||||||||||||||||||
| 1562 | stream >> *static_cast< NS(QVariantList)*>(data); | - | ||||||||||||||||||||||||
| 1563 | break; | - | ||||||||||||||||||||||||
| 1564 | case QMetaType::QVariant: | - | ||||||||||||||||||||||||
| 1565 | stream >> *static_cast< NS(QVariant)*>(data); | - | ||||||||||||||||||||||||
| 1566 | break; | - | ||||||||||||||||||||||||
| 1567 | case QMetaType::QByteArrayList: | - | ||||||||||||||||||||||||
| 1568 | stream >> *static_cast< NS(QByteArrayList)*>(data); | - | ||||||||||||||||||||||||
| 1569 | break; | - | ||||||||||||||||||||||||
| 1570 | #endif | - | ||||||||||||||||||||||||
| 1571 | case QMetaType::QByteArray: | - | ||||||||||||||||||||||||
| 1572 | stream >> *static_cast< NS(QByteArray)*>(data); | - | ||||||||||||||||||||||||
| 1573 | break; | - | ||||||||||||||||||||||||
| 1574 | case QMetaType::QString: | - | ||||||||||||||||||||||||
| 1575 | stream >> *static_cast< NS(QString)*>(data); | - | ||||||||||||||||||||||||
| 1576 | break; | - | ||||||||||||||||||||||||
| 1577 | case QMetaType::QStringList: | - | ||||||||||||||||||||||||
| 1578 | stream >> *static_cast< NS(QStringList)*>(data); | - | ||||||||||||||||||||||||
| 1579 | break; | - | ||||||||||||||||||||||||
| 1580 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
| 1581 | case QMetaType::QBitArray: | - | ||||||||||||||||||||||||
| 1582 | stream >> *static_cast< NS(QBitArray)*>(data); | - | ||||||||||||||||||||||||
| 1583 | break; | - | ||||||||||||||||||||||||
| 1584 | #endif | - | ||||||||||||||||||||||||
| 1585 | case QMetaType::QDate: | - | ||||||||||||||||||||||||
| 1586 | stream >> *static_cast< NS(QDate)*>(data); | - | ||||||||||||||||||||||||
| 1587 | break; | - | ||||||||||||||||||||||||
| 1588 | case QMetaType::QTime: | - | ||||||||||||||||||||||||
| 1589 | stream >> *static_cast< NS(QTime)*>(data); | - | ||||||||||||||||||||||||
| 1590 | break; | - | ||||||||||||||||||||||||
| 1591 | case QMetaType::QDateTime: | - | ||||||||||||||||||||||||
| 1592 | stream >> *static_cast< NS(QDateTime)*>(data); | - | ||||||||||||||||||||||||
| 1593 | break; | - | ||||||||||||||||||||||||
| 1594 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
| 1595 | case QMetaType::QUrl: | - | ||||||||||||||||||||||||
| 1596 | stream >> *static_cast< NS(QUrl)*>(data); | - | ||||||||||||||||||||||||
| 1597 | break; | - | ||||||||||||||||||||||||
| 1598 | #endif | - | ||||||||||||||||||||||||
| 1599 | case QMetaType::QLocale: | - | ||||||||||||||||||||||||
| 1600 | stream >> *static_cast< NS(QLocale)*>(data); | - | ||||||||||||||||||||||||
| 1601 | break; | - | ||||||||||||||||||||||||
| 1602 | #ifndef QT_NO_GEOM_VARIANT | - | ||||||||||||||||||||||||
| 1603 | case QMetaType::QRect: | - | ||||||||||||||||||||||||
| 1604 | stream >> *static_cast< NS(QRect)*>(data); | - | ||||||||||||||||||||||||
| 1605 | break; | - | ||||||||||||||||||||||||
| 1606 | case QMetaType::QRectF: | - | ||||||||||||||||||||||||
| 1607 | stream >> *static_cast< NS(QRectF)*>(data); | - | ||||||||||||||||||||||||
| 1608 | break; | - | ||||||||||||||||||||||||
| 1609 | case QMetaType::QSize: | - | ||||||||||||||||||||||||
| 1610 | stream >> *static_cast< NS(QSize)*>(data); | - | ||||||||||||||||||||||||
| 1611 | break; | - | ||||||||||||||||||||||||
| 1612 | case QMetaType::QSizeF: | - | ||||||||||||||||||||||||
| 1613 | stream >> *static_cast< NS(QSizeF)*>(data); | - | ||||||||||||||||||||||||
| 1614 | break; | - | ||||||||||||||||||||||||
| 1615 | case QMetaType::QLine: | - | ||||||||||||||||||||||||
| 1616 | stream >> *static_cast< NS(QLine)*>(data); | - | ||||||||||||||||||||||||
| 1617 | break; | - | ||||||||||||||||||||||||
| 1618 | case QMetaType::QLineF: | - | ||||||||||||||||||||||||
| 1619 | stream >> *static_cast< NS(QLineF)*>(data); | - | ||||||||||||||||||||||||
| 1620 | break; | - | ||||||||||||||||||||||||
| 1621 | case QMetaType::QPoint: | - | ||||||||||||||||||||||||
| 1622 | stream >> *static_cast< NS(QPoint)*>(data); | - | ||||||||||||||||||||||||
| 1623 | break; | - | ||||||||||||||||||||||||
| 1624 | case QMetaType::QPointF: | - | ||||||||||||||||||||||||
| 1625 | stream >> *static_cast< NS(QPointF)*>(data); | - | ||||||||||||||||||||||||
| 1626 | break; | - | ||||||||||||||||||||||||
| 1627 | #endif | - | ||||||||||||||||||||||||
| 1628 | #ifndef QT_NO_REGEXP | - | ||||||||||||||||||||||||
| 1629 | case QMetaType::QRegExp: | - | ||||||||||||||||||||||||
| 1630 | stream >> *static_cast< NS(QRegExp)*>(data); | - | ||||||||||||||||||||||||
| 1631 | break; | - | ||||||||||||||||||||||||
| 1632 | #endif | - | ||||||||||||||||||||||||
| 1633 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
| 1634 | #ifndef QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||||||||
| 1635 | case QMetaType::QRegularExpression: | - | ||||||||||||||||||||||||
| 1636 | stream >> *static_cast< NS(QRegularExpression)*>(data); | - | ||||||||||||||||||||||||
| 1637 | break; | - | ||||||||||||||||||||||||
| 1638 | #endif // QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||||||||
| 1639 | case QMetaType::QEasingCurve: | - | ||||||||||||||||||||||||
| 1640 | stream >> *static_cast< NS(QEasingCurve)*>(data); | - | ||||||||||||||||||||||||
| 1641 | break; | - | ||||||||||||||||||||||||
| 1642 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
| 1643 | case QMetaType::QFont: | - | ||||||||||||||||||||||||
| 1644 | case QMetaType::QPixmap: | - | ||||||||||||||||||||||||
| 1645 | case QMetaType::QBrush: | - | ||||||||||||||||||||||||
| 1646 | case QMetaType::QColor: | - | ||||||||||||||||||||||||
| 1647 | case QMetaType::QPalette: | - | ||||||||||||||||||||||||
| 1648 | case QMetaType::QImage: | - | ||||||||||||||||||||||||
| 1649 | case QMetaType::QPolygon: | - | ||||||||||||||||||||||||
| 1650 | case QMetaType::QPolygonF: | - | ||||||||||||||||||||||||
| 1651 | case QMetaType::QRegion: | - | ||||||||||||||||||||||||
| 1652 | case QMetaType::QBitmap: | - | ||||||||||||||||||||||||
| 1653 | case QMetaType::QCursor: | - | ||||||||||||||||||||||||
| 1654 | case QMetaType::QKeySequence: | - | ||||||||||||||||||||||||
| 1655 | case QMetaType::QPen: | - | ||||||||||||||||||||||||
| 1656 | case QMetaType::QTextLength: | - | ||||||||||||||||||||||||
| 1657 | case QMetaType::QTextFormat: | - | ||||||||||||||||||||||||
| 1658 | case QMetaType::QMatrix: | - | ||||||||||||||||||||||||
| 1659 | case QMetaType::QTransform: | - | ||||||||||||||||||||||||
| 1660 | case QMetaType::QMatrix4x4: | - | ||||||||||||||||||||||||
| 1661 | case QMetaType::QVector2D: | - | ||||||||||||||||||||||||
| 1662 | case QMetaType::QVector3D: | - | ||||||||||||||||||||||||
| 1663 | case QMetaType::QVector4D: | - | ||||||||||||||||||||||||
| 1664 | case QMetaType::QQuaternion: | - | ||||||||||||||||||||||||
| 1665 | case QMetaType::QIcon: | - | ||||||||||||||||||||||||
| 1666 | if (!qMetaTypeGuiHelper) | - | ||||||||||||||||||||||||
| 1667 | return false; | - | ||||||||||||||||||||||||
| 1668 | qMetaTypeGuiHelper[type - FirstGuiType].loadOp(stream, data); | - | ||||||||||||||||||||||||
| 1669 | break; | - | ||||||||||||||||||||||||
| 1670 | case QMetaType::QSizePolicy: | - | ||||||||||||||||||||||||
| 1671 | if (!qMetaTypeWidgetsHelper) | - | ||||||||||||||||||||||||
| 1672 | return false; | - | ||||||||||||||||||||||||
| 1673 | qMetaTypeWidgetsHelper[type - FirstWidgetsType].loadOp(stream, data); | - | ||||||||||||||||||||||||
| 1674 | break; | - | ||||||||||||||||||||||||
| 1675 | case QMetaType::QUuid: | - | ||||||||||||||||||||||||
| 1676 | stream >> *static_cast< NS(QUuid)*>(data); | - | ||||||||||||||||||||||||
| 1677 | break; | - | ||||||||||||||||||||||||
| 1678 | default: { | - | ||||||||||||||||||||||||
| 1679 | const QVector<QCustomTypeInfo> * const ct = customTypes(); | - | ||||||||||||||||||||||||
| 1680 | if (!ct) | - | ||||||||||||||||||||||||
| 1681 | return false; | - | ||||||||||||||||||||||||
| 1682 | - | |||||||||||||||||||||||||
| 1683 | LoadOperator loadOp = 0; | - | ||||||||||||||||||||||||
| 1684 | { | - | ||||||||||||||||||||||||
| 1685 | QReadLocker locker(customTypesLock()); | - | ||||||||||||||||||||||||
| 1686 | loadOp = ct->at(type - User).loadOp; | - | ||||||||||||||||||||||||
| 1687 | } | - | ||||||||||||||||||||||||
| 1688 | - | |||||||||||||||||||||||||
| 1689 | if (!loadOp) | - | ||||||||||||||||||||||||
| 1690 | return false; | - | ||||||||||||||||||||||||
| 1691 | loadOp(stream, data); | - | ||||||||||||||||||||||||
| 1692 | break; } | - | ||||||||||||||||||||||||
| 1693 | } | - | ||||||||||||||||||||||||
| 1694 | return true; | - | ||||||||||||||||||||||||
| 1695 | } | - | ||||||||||||||||||||||||
| 1696 | #endif // QT_NO_DATASTREAM | - | ||||||||||||||||||||||||
| 1697 | - | |||||||||||||||||||||||||
| 1698 | /*! | - | ||||||||||||||||||||||||
| 1699 | Returns a copy of \a copy, assuming it is of type \a type. If \a | - | ||||||||||||||||||||||||
| 1700 | copy is zero, creates a default constructed instance. | - | ||||||||||||||||||||||||
| 1701 | - | |||||||||||||||||||||||||
| 1702 | \sa destroy(), isRegistered(), Type | - | ||||||||||||||||||||||||
| 1703 | */ | - | ||||||||||||||||||||||||
| 1704 | void *QMetaType::create(int type, const void *copy) | - | ||||||||||||||||||||||||
| 1705 | { | - | ||||||||||||||||||||||||
| 1706 | QMetaType info(type); | - | ||||||||||||||||||||||||
| 1707 | if (int size = info.sizeOf()) | - | ||||||||||||||||||||||||
| 1708 | return info.construct(operator new(size), copy); | - | ||||||||||||||||||||||||
| 1709 | return 0; | - | ||||||||||||||||||||||||
| 1710 | } | - | ||||||||||||||||||||||||
| 1711 | - | |||||||||||||||||||||||||
| 1712 | /*! | - | ||||||||||||||||||||||||
| 1713 | Destroys the \a data, assuming it is of the \a type given. | - | ||||||||||||||||||||||||
| 1714 | - | |||||||||||||||||||||||||
| 1715 | \sa create(), isRegistered(), Type | - | ||||||||||||||||||||||||
| 1716 | */ | - | ||||||||||||||||||||||||
| 1717 | void QMetaType::destroy(int type, void *data) | - | ||||||||||||||||||||||||
| 1718 | { | - | ||||||||||||||||||||||||
| 1719 | QMetaType info(type); | - | ||||||||||||||||||||||||
| 1720 | info.destruct(data); | - | ||||||||||||||||||||||||
| 1721 | operator delete(data); | - | ||||||||||||||||||||||||
| 1722 | } | - | ||||||||||||||||||||||||
| 1723 | - | |||||||||||||||||||||||||
| 1724 | namespace { | - | ||||||||||||||||||||||||
| 1725 | class TypeConstructor { | - | ||||||||||||||||||||||||
| 1726 | template<typename T, bool IsAcceptedType = DefinedTypesFilter::Acceptor<T>::IsAccepted> | - | ||||||||||||||||||||||||
| 1727 | struct ConstructorImpl { | - | ||||||||||||||||||||||||
| 1728 | static void *Construct(const int /*type*/, void *where, const void *copy) { return QtMetaTypePrivate::QMetaTypeFunctionHelper<T>::Construct(where, copy); } | - | ||||||||||||||||||||||||
| 1729 | }; | - | ||||||||||||||||||||||||
| 1730 | template<typename T> | - | ||||||||||||||||||||||||
| 1731 | struct ConstructorImpl<T, /* IsAcceptedType = */ false> { | - | ||||||||||||||||||||||||
| 1732 | static void *Construct(const int type, void *where, const void *copy) | - | ||||||||||||||||||||||||
| 1733 | { | - | ||||||||||||||||||||||||
| 1734 | if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) | - | ||||||||||||||||||||||||
| 1735 | return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].constructor(where, copy) : 0; | - | ||||||||||||||||||||||||
| 1736 | - | |||||||||||||||||||||||||
| 1737 | if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) | - | ||||||||||||||||||||||||
| 1738 | return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].constructor(where, copy) : 0; | - | ||||||||||||||||||||||||
| 1739 | - | |||||||||||||||||||||||||
| 1740 | // This point can be reached only for known types that definition is not available, for example | - | ||||||||||||||||||||||||
| 1741 | // in bootstrap mode. We have no other choice then ignore it. | - | ||||||||||||||||||||||||
| 1742 | return 0; | - | ||||||||||||||||||||||||
| 1743 | } | - | ||||||||||||||||||||||||
| 1744 | }; | - | ||||||||||||||||||||||||
| 1745 | public: | - | ||||||||||||||||||||||||
| 1746 | TypeConstructor(const int type, void *where) | - | ||||||||||||||||||||||||
| 1747 | : m_type(type) | - | ||||||||||||||||||||||||
| 1748 | , m_where(where) | - | ||||||||||||||||||||||||
| 1749 | {} | - | ||||||||||||||||||||||||
| 1750 | - | |||||||||||||||||||||||||
| 1751 | template<typename T> | - | ||||||||||||||||||||||||
| 1752 | void *delegate(const T *copy) { return ConstructorImpl<T>::Construct(m_type, m_where, copy); } | - | ||||||||||||||||||||||||
| 1753 | void *delegate(const void *) { return m_where; } | - | ||||||||||||||||||||||||
| 1754 | void *delegate(const QMetaTypeSwitcher::UnknownType*) { return m_where; } | - | ||||||||||||||||||||||||
| 1755 | void *delegate(const QMetaTypeSwitcher::NotBuiltinType *copy) { return customTypeConstructor(m_type, m_where, copy); } | - | ||||||||||||||||||||||||
| 1756 | - | |||||||||||||||||||||||||
| 1757 | private: | - | ||||||||||||||||||||||||
| 1758 | static void *customTypeConstructor(const int type, void *where, const void *copy) | - | ||||||||||||||||||||||||
| 1759 | { | - | ||||||||||||||||||||||||
| 1760 | QMetaType::Constructor ctor; | - | ||||||||||||||||||||||||
| 1761 | const QVector<QCustomTypeInfo> * const ct = customTypes(); | - | ||||||||||||||||||||||||
| 1762 | { | - | ||||||||||||||||||||||||
| 1763 | QReadLocker locker(customTypesLock()); | - | ||||||||||||||||||||||||
| 1764 | if (Q_UNLIKELY(type < QMetaType::User || !ct || ct->count() <= type - QMetaType::User)) | - | ||||||||||||||||||||||||
| 1765 | return 0; | - | ||||||||||||||||||||||||
| 1766 | ctor = ct->at(type - QMetaType::User).constructor; | - | ||||||||||||||||||||||||
| 1767 | } | - | ||||||||||||||||||||||||
| 1768 | Q_ASSERT_X(ctor, "void *QMetaType::construct(int type, void *where, const void *copy)", "The type was not properly registered"); | - | ||||||||||||||||||||||||
| 1769 | return ctor(where, copy); | - | ||||||||||||||||||||||||
| 1770 | } | - | ||||||||||||||||||||||||
| 1771 | - | |||||||||||||||||||||||||
| 1772 | const int m_type; | - | ||||||||||||||||||||||||
| 1773 | void *m_where; | - | ||||||||||||||||||||||||
| 1774 | }; | - | ||||||||||||||||||||||||
| 1775 | } // namespace | - | ||||||||||||||||||||||||
| 1776 | - | |||||||||||||||||||||||||
| 1777 | /*! | - | ||||||||||||||||||||||||
| 1778 | \since 5.0 | - | ||||||||||||||||||||||||
| 1779 | - | |||||||||||||||||||||||||
| 1780 | Constructs a value of the given \a type in the existing memory | - | ||||||||||||||||||||||||
| 1781 | addressed by \a where, that is a copy of \a copy, and returns | - | ||||||||||||||||||||||||
| 1782 | \a where. If \a copy is zero, the value is default constructed. | - | ||||||||||||||||||||||||
| 1783 | - | |||||||||||||||||||||||||
| 1784 | This is a low-level function for explicitly managing the memory | - | ||||||||||||||||||||||||
| 1785 | used to store the type. Consider calling create() if you don't | - | ||||||||||||||||||||||||
| 1786 | need this level of control (that is, use "new" rather than | - | ||||||||||||||||||||||||
| 1787 | "placement new"). | - | ||||||||||||||||||||||||
| 1788 | - | |||||||||||||||||||||||||
| 1789 | You must ensure that \a where points to a location that can store | - | ||||||||||||||||||||||||
| 1790 | a value of type \a type, and that \a where is suitably aligned. | - | ||||||||||||||||||||||||
| 1791 | The type's size can be queried by calling sizeOf(). | - | ||||||||||||||||||||||||
| 1792 | - | |||||||||||||||||||||||||
| 1793 | The rule of thumb for alignment is that a type is aligned to its | - | ||||||||||||||||||||||||
| 1794 | natural boundary, which is the smallest power of 2 that is bigger | - | ||||||||||||||||||||||||
| 1795 | than the type, unless that alignment is larger than the maximum | - | ||||||||||||||||||||||||
| 1796 | useful alignment for the platform. For practical purposes, | - | ||||||||||||||||||||||||
| 1797 | alignment larger than 2 * sizeof(void*) is only necessary for | - | ||||||||||||||||||||||||
| 1798 | special hardware instructions (e.g., aligned SSE loads and stores | - | ||||||||||||||||||||||||
| 1799 | on x86). | - | ||||||||||||||||||||||||
| 1800 | - | |||||||||||||||||||||||||
| 1801 | \sa destruct(), sizeOf() | - | ||||||||||||||||||||||||
| 1802 | */ | - | ||||||||||||||||||||||||
| 1803 | void *QMetaType::construct(int type, void *where, const void *copy) | - | ||||||||||||||||||||||||
| 1804 | { | - | ||||||||||||||||||||||||
| 1805 | if (!where) | - | ||||||||||||||||||||||||
| 1806 | return 0; | - | ||||||||||||||||||||||||
| 1807 | TypeConstructor constructor(type, where); | - | ||||||||||||||||||||||||
| 1808 | return QMetaTypeSwitcher::switcher<void*>(constructor, type, copy); | - | ||||||||||||||||||||||||
| 1809 | } | - | ||||||||||||||||||||||||
| 1810 | - | |||||||||||||||||||||||||
| 1811 | - | |||||||||||||||||||||||||
| 1812 | namespace { | - | ||||||||||||||||||||||||
| 1813 | class TypeDestructor { | - | ||||||||||||||||||||||||
| 1814 | template<typename T, bool IsAcceptedType = DefinedTypesFilter::Acceptor<T>::IsAccepted> | - | ||||||||||||||||||||||||
| 1815 | struct DestructorImpl { | - | ||||||||||||||||||||||||
| 1816 | static void Destruct(const int /* type */, void *where) { QtMetaTypePrivate::QMetaTypeFunctionHelper<T>::Destruct(where); } | - | ||||||||||||||||||||||||
| 1817 | }; | - | ||||||||||||||||||||||||
| 1818 | template<typename T> | - | ||||||||||||||||||||||||
| 1819 | struct DestructorImpl<T, /* IsAcceptedType = */ false> { | - | ||||||||||||||||||||||||
| 1820 | static void Destruct(const int type, void *where) | - | ||||||||||||||||||||||||
| 1821 | { | - | ||||||||||||||||||||||||
| 1822 | if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) { | - | ||||||||||||||||||||||||
| 1823 | if (Q_LIKELY(qMetaTypeGuiHelper)) | - | ||||||||||||||||||||||||
| 1824 | qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].destructor(where); | - | ||||||||||||||||||||||||
| 1825 | return; | - | ||||||||||||||||||||||||
| 1826 | } | - | ||||||||||||||||||||||||
| 1827 | if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) { | - | ||||||||||||||||||||||||
| 1828 | if (Q_LIKELY(qMetaTypeWidgetsHelper)) | - | ||||||||||||||||||||||||
| 1829 | qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].destructor(where); | - | ||||||||||||||||||||||||
| 1830 | return; | - | ||||||||||||||||||||||||
| 1831 | } | - | ||||||||||||||||||||||||
| 1832 | // This point can be reached only for known types that definition is not available, for example | - | ||||||||||||||||||||||||
| 1833 | // in bootstrap mode. We have no other choice then ignore it. | - | ||||||||||||||||||||||||
| 1834 | } | - | ||||||||||||||||||||||||
| 1835 | }; | - | ||||||||||||||||||||||||
| 1836 | public: | - | ||||||||||||||||||||||||
| 1837 | TypeDestructor(const int type) | - | ||||||||||||||||||||||||
| 1838 | : m_type(type) | - | ||||||||||||||||||||||||
| 1839 | {} | - | ||||||||||||||||||||||||
| 1840 | - | |||||||||||||||||||||||||
| 1841 | template<typename T> | - | ||||||||||||||||||||||||
| 1842 | void delegate(const T *where) { DestructorImpl<T>::Destruct(m_type, const_cast<T*>(where)); } | - | ||||||||||||||||||||||||
| 1843 | void delegate(const void *) {} | - | ||||||||||||||||||||||||
| 1844 | void delegate(const QMetaTypeSwitcher::UnknownType*) {} | - | ||||||||||||||||||||||||
| 1845 | void delegate(const QMetaTypeSwitcher::NotBuiltinType *where) | - | ||||||||||||||||||||||||
| 1846 | { customTypeDestructor(m_type, const_cast<void *>(static_cast<const void *>(where))); } | - | ||||||||||||||||||||||||
| 1847 | - | |||||||||||||||||||||||||
| 1848 | private: | - | ||||||||||||||||||||||||
| 1849 | static void customTypeDestructor(const int type, void *where) | - | ||||||||||||||||||||||||
| 1850 | { | - | ||||||||||||||||||||||||
| 1851 | QMetaType::Destructor dtor; | - | ||||||||||||||||||||||||
| 1852 | const QVector<QCustomTypeInfo> * const ct = customTypes(); | - | ||||||||||||||||||||||||
| 1853 | { | - | ||||||||||||||||||||||||
| 1854 | QReadLocker locker(customTypesLock()); | - | ||||||||||||||||||||||||
| 1855 | if (Q_UNLIKELY(type < QMetaType::User || !ct || ct->count() <= type - QMetaType::User)) | - | ||||||||||||||||||||||||
| 1856 | return; | - | ||||||||||||||||||||||||
| 1857 | dtor = ct->at(type - QMetaType::User).destructor; | - | ||||||||||||||||||||||||
| 1858 | } | - | ||||||||||||||||||||||||
| 1859 | Q_ASSERT_X(dtor, "void QMetaType::destruct(int type, void *where)", "The type was not properly registered"); | - | ||||||||||||||||||||||||
| 1860 | dtor(where); | - | ||||||||||||||||||||||||
| 1861 | } | - | ||||||||||||||||||||||||
| 1862 | - | |||||||||||||||||||||||||
| 1863 | const int m_type; | - | ||||||||||||||||||||||||
| 1864 | }; | - | ||||||||||||||||||||||||
| 1865 | } // namespace | - | ||||||||||||||||||||||||
| 1866 | - | |||||||||||||||||||||||||
| 1867 | /*! | - | ||||||||||||||||||||||||
| 1868 | \since 5.0 | - | ||||||||||||||||||||||||
| 1869 | - | |||||||||||||||||||||||||
| 1870 | Destructs the value of the given \a type, located at \a where. | - | ||||||||||||||||||||||||
| 1871 | - | |||||||||||||||||||||||||
| 1872 | Unlike destroy(), this function only invokes the type's | - | ||||||||||||||||||||||||
| 1873 | destructor, it doesn't invoke the delete operator. | - | ||||||||||||||||||||||||
| 1874 | - | |||||||||||||||||||||||||
| 1875 | \sa construct() | - | ||||||||||||||||||||||||
| 1876 | */ | - | ||||||||||||||||||||||||
| 1877 | void QMetaType::destruct(int type, void *where) | - | ||||||||||||||||||||||||
| 1878 | { | - | ||||||||||||||||||||||||
| 1879 | if (!where) | - | ||||||||||||||||||||||||
| 1880 | return; | - | ||||||||||||||||||||||||
| 1881 | TypeDestructor destructor(type); | - | ||||||||||||||||||||||||
| 1882 | QMetaTypeSwitcher::switcher<void>(destructor, type, where); | - | ||||||||||||||||||||||||
| 1883 | } | - | ||||||||||||||||||||||||
| 1884 | - | |||||||||||||||||||||||||
| 1885 | - | |||||||||||||||||||||||||
| 1886 | namespace { | - | ||||||||||||||||||||||||
| 1887 | class SizeOf { | - | ||||||||||||||||||||||||
| 1888 | template<typename T, bool IsAcceptedType = DefinedTypesFilter::Acceptor<T>::IsAccepted> | - | ||||||||||||||||||||||||
| 1889 | struct SizeOfImpl { | - | ||||||||||||||||||||||||
| 1890 | static int Size(const int) { return QTypeInfo<T>::sizeOf; } | - | ||||||||||||||||||||||||
| 1891 | }; | - | ||||||||||||||||||||||||
| 1892 | template<typename T> | - | ||||||||||||||||||||||||
| 1893 | struct SizeOfImpl<T, /* IsAcceptedType = */ false> { | - | ||||||||||||||||||||||||
| 1894 | static int Size(const int type) | - | ||||||||||||||||||||||||
| 1895 | { | - | ||||||||||||||||||||||||
| 1896 | if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) | - | ||||||||||||||||||||||||
| 1897 | return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].size : 0; | - | ||||||||||||||||||||||||
| 1898 | - | |||||||||||||||||||||||||
| 1899 | if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) | - | ||||||||||||||||||||||||
| 1900 | return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].size : 0; | - | ||||||||||||||||||||||||
| 1901 | - | |||||||||||||||||||||||||
| 1902 | // This point can be reached only for known types that definition is not available, for example | - | ||||||||||||||||||||||||
| 1903 | // in bootstrap mode. We have no other choice then ignore it. | - | ||||||||||||||||||||||||
| 1904 | return 0; | - | ||||||||||||||||||||||||
| 1905 | } | - | ||||||||||||||||||||||||
| 1906 | }; | - | ||||||||||||||||||||||||
| 1907 | - | |||||||||||||||||||||||||
| 1908 | public: | - | ||||||||||||||||||||||||
| 1909 | SizeOf(int type) | - | ||||||||||||||||||||||||
| 1910 | : m_type(type) | - | ||||||||||||||||||||||||
| 1911 | {} | - | ||||||||||||||||||||||||
| 1912 | - | |||||||||||||||||||||||||
| 1913 | template<typename T> | - | ||||||||||||||||||||||||
| 1914 | int delegate(const T*) { return SizeOfImpl<T>::Size(m_type); } | - | ||||||||||||||||||||||||
| 1915 | int delegate(const QMetaTypeSwitcher::UnknownType*) { return 0; } | - | ||||||||||||||||||||||||
| 1916 | int delegate(const QMetaTypeSwitcher::NotBuiltinType*) { return customTypeSizeOf(m_type); } | - | ||||||||||||||||||||||||
| 1917 | private: | - | ||||||||||||||||||||||||
| 1918 | static int customTypeSizeOf(const int type) | - | ||||||||||||||||||||||||
| 1919 | { | - | ||||||||||||||||||||||||
| 1920 | const QVector<QCustomTypeInfo> * const ct = customTypes(); | - | ||||||||||||||||||||||||
| 1921 | QReadLocker locker(customTypesLock()); | - | ||||||||||||||||||||||||
| 1922 | if (Q_UNLIKELY(type < QMetaType::User || !ct || ct->count() <= type - QMetaType::User)) | - | ||||||||||||||||||||||||
| 1923 | return 0; | - | ||||||||||||||||||||||||
| 1924 | return ct->at(type - QMetaType::User).size; | - | ||||||||||||||||||||||||
| 1925 | } | - | ||||||||||||||||||||||||
| 1926 | - | |||||||||||||||||||||||||
| 1927 | const int m_type; | - | ||||||||||||||||||||||||
| 1928 | }; | - | ||||||||||||||||||||||||
| 1929 | } // namespace | - | ||||||||||||||||||||||||
| 1930 | - | |||||||||||||||||||||||||
| 1931 | /*! | - | ||||||||||||||||||||||||
| 1932 | \since 5.0 | - | ||||||||||||||||||||||||
| 1933 | - | |||||||||||||||||||||||||
| 1934 | Returns the size of the given \a type in bytes (i.e. sizeof(T), | - | ||||||||||||||||||||||||
| 1935 | where T is the actual type identified by the \a type argument). | - | ||||||||||||||||||||||||
| 1936 | - | |||||||||||||||||||||||||
| 1937 | This function is typically used together with construct() | - | ||||||||||||||||||||||||
| 1938 | to perform low-level management of the memory used by a type. | - | ||||||||||||||||||||||||
| 1939 | - | |||||||||||||||||||||||||
| 1940 | \sa construct() | - | ||||||||||||||||||||||||
| 1941 | */ | - | ||||||||||||||||||||||||
| 1942 | int QMetaType::sizeOf(int type) | - | ||||||||||||||||||||||||
| 1943 | { | - | ||||||||||||||||||||||||
| 1944 | SizeOf sizeOf(type); | - | ||||||||||||||||||||||||
| 1945 | return QMetaTypeSwitcher::switcher<int>(sizeOf, type, 0); | - | ||||||||||||||||||||||||
| 1946 | } | - | ||||||||||||||||||||||||
| 1947 | - | |||||||||||||||||||||||||
| 1948 | namespace { | - | ||||||||||||||||||||||||
| 1949 | class Flags | - | ||||||||||||||||||||||||
| 1950 | { | - | ||||||||||||||||||||||||
| 1951 | template<typename T, bool IsAcceptedType = DefinedTypesFilter::Acceptor<T>::IsAccepted> | - | ||||||||||||||||||||||||
| 1952 | struct FlagsImpl | - | ||||||||||||||||||||||||
| 1953 | { | - | ||||||||||||||||||||||||
| 1954 | static quint32 Flags(const int /* type */) | - | ||||||||||||||||||||||||
| 1955 | { | - | ||||||||||||||||||||||||
| 1956 | return QtPrivate::QMetaTypeTypeFlags<T>::Flags; | - | ||||||||||||||||||||||||
| 1957 | } | - | ||||||||||||||||||||||||
| 1958 | }; | - | ||||||||||||||||||||||||
| 1959 | template<typename T> | - | ||||||||||||||||||||||||
| 1960 | struct FlagsImpl<T, /* IsAcceptedType = */ false> | - | ||||||||||||||||||||||||
| 1961 | { | - | ||||||||||||||||||||||||
| 1962 | static quint32 Flags(const int type) | - | ||||||||||||||||||||||||
| 1963 | { | - | ||||||||||||||||||||||||
| 1964 | if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) | - | ||||||||||||||||||||||||
| 1965 | return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].flags : 0; | - | ||||||||||||||||||||||||
| 1966 | - | |||||||||||||||||||||||||
| 1967 | if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) | - | ||||||||||||||||||||||||
| 1968 | return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].flags : 0; | - | ||||||||||||||||||||||||
| 1969 | - | |||||||||||||||||||||||||
| 1970 | // This point can be reached only for known types that definition is not available, for example | - | ||||||||||||||||||||||||
| 1971 | // in bootstrap mode. We have no other choice then ignore it. | - | ||||||||||||||||||||||||
| 1972 | return 0; | - | ||||||||||||||||||||||||
| 1973 | } | - | ||||||||||||||||||||||||
| 1974 | }; | - | ||||||||||||||||||||||||
| 1975 | public: | - | ||||||||||||||||||||||||
| 1976 | Flags(const int type) | - | ||||||||||||||||||||||||
| 1977 | : m_type(type) | - | ||||||||||||||||||||||||
| 1978 | {} | - | ||||||||||||||||||||||||
| 1979 | template<typename T> | - | ||||||||||||||||||||||||
| 1980 | quint32 delegate(const T*) { return FlagsImpl<T>::Flags(m_type); } | - | ||||||||||||||||||||||||
| 1981 | quint32 delegate(const void*) { return 0; } | - | ||||||||||||||||||||||||
| 1982 | quint32 delegate(const QMetaTypeSwitcher::UnknownType*) { return 0; } | - | ||||||||||||||||||||||||
| 1983 | quint32 delegate(const QMetaTypeSwitcher::NotBuiltinType*) { return customTypeFlags(m_type); } | - | ||||||||||||||||||||||||
| 1984 | private: | - | ||||||||||||||||||||||||
| 1985 | const int m_type; | - | ||||||||||||||||||||||||
| 1986 | static quint32 customTypeFlags(const int type) | - | ||||||||||||||||||||||||
| 1987 | { | - | ||||||||||||||||||||||||
| 1988 | const QVector<QCustomTypeInfo> * const ct = customTypes(); | - | ||||||||||||||||||||||||
| 1989 | if (Q_UNLIKELY(!ct || type < QMetaType::User)) | - | ||||||||||||||||||||||||
| 1990 | return 0; | - | ||||||||||||||||||||||||
| 1991 | QReadLocker locker(customTypesLock()); | - | ||||||||||||||||||||||||
| 1992 | if (Q_UNLIKELY(ct->count() <= type - QMetaType::User)) | - | ||||||||||||||||||||||||
| 1993 | return 0; | - | ||||||||||||||||||||||||
| 1994 | return ct->at(type - QMetaType::User).flags; | - | ||||||||||||||||||||||||
| 1995 | } | - | ||||||||||||||||||||||||
| 1996 | }; | - | ||||||||||||||||||||||||
| 1997 | } // namespace | - | ||||||||||||||||||||||||
| 1998 | - | |||||||||||||||||||||||||
| 1999 | /*! | - | ||||||||||||||||||||||||
| 2000 | \since 5.0 | - | ||||||||||||||||||||||||
| 2001 | - | |||||||||||||||||||||||||
| 2002 | Returns flags of the given \a type. | - | ||||||||||||||||||||||||
| 2003 | - | |||||||||||||||||||||||||
| 2004 | \sa QMetaType::TypeFlags | - | ||||||||||||||||||||||||
| 2005 | */ | - | ||||||||||||||||||||||||
| 2006 | QMetaType::TypeFlags QMetaType::typeFlags(int type) | - | ||||||||||||||||||||||||
| 2007 | { | - | ||||||||||||||||||||||||
| 2008 | Flags flags(type); | - | ||||||||||||||||||||||||
| 2009 | return static_cast<QMetaType::TypeFlags>(QMetaTypeSwitcher::switcher<quint32>(flags, type, 0)); | - | ||||||||||||||||||||||||
| 2010 | } | - | ||||||||||||||||||||||||
| 2011 | - | |||||||||||||||||||||||||
| 2012 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
| 2013 | namespace { | - | ||||||||||||||||||||||||
| 2014 | class MetaObject | - | ||||||||||||||||||||||||
| 2015 | { | - | ||||||||||||||||||||||||
| 2016 | public: | - | ||||||||||||||||||||||||
| 2017 | MetaObject(const int type) | - | ||||||||||||||||||||||||
| 2018 | : m_type(type) | - | ||||||||||||||||||||||||
| 2019 | {} | - | ||||||||||||||||||||||||
| 2020 | - | |||||||||||||||||||||||||
| 2021 | template<typename T, bool IsAcceptedType = DefinedTypesFilter::Acceptor<T>::IsAccepted> | - | ||||||||||||||||||||||||
| 2022 | struct MetaObjectImpl | - | ||||||||||||||||||||||||
| 2023 | { | - | ||||||||||||||||||||||||
| 2024 | static const QMetaObject *MetaObject(int /*type*/) | - | ||||||||||||||||||||||||
| 2025 | { return QtPrivate::MetaObjectForType<T>::value(); } | - | ||||||||||||||||||||||||
| 2026 | }; | - | ||||||||||||||||||||||||
| 2027 | template<typename T> | - | ||||||||||||||||||||||||
| 2028 | struct MetaObjectImpl<T, /* IsAcceptedType = */ false> | - | ||||||||||||||||||||||||
| 2029 | { | - | ||||||||||||||||||||||||
| 2030 | static const QMetaObject *MetaObject(int type) { | - | ||||||||||||||||||||||||
| 2031 | if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) | - | ||||||||||||||||||||||||
| 2032 | return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].metaObject : 0; | - | ||||||||||||||||||||||||
| 2033 | if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) | - | ||||||||||||||||||||||||
| 2034 | return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].metaObject : 0; | - | ||||||||||||||||||||||||
| 2035 | return 0; | - | ||||||||||||||||||||||||
| 2036 | } | - | ||||||||||||||||||||||||
| 2037 | }; | - | ||||||||||||||||||||||||
| 2038 | - | |||||||||||||||||||||||||
| 2039 | template <typename T> | - | ||||||||||||||||||||||||
| 2040 | const QMetaObject *delegate(const T *) { return MetaObjectImpl<T>::MetaObject(m_type); } | - | ||||||||||||||||||||||||
| 2041 | const QMetaObject *delegate(const void*) { return 0; } | - | ||||||||||||||||||||||||
| 2042 | const QMetaObject *delegate(const QMetaTypeSwitcher::UnknownType*) { return 0; } | - | ||||||||||||||||||||||||
| 2043 | const QMetaObject *delegate(const QMetaTypeSwitcher::NotBuiltinType*) { return customMetaObject(m_type); } | - | ||||||||||||||||||||||||
| 2044 | private: | - | ||||||||||||||||||||||||
| 2045 | const int m_type; | - | ||||||||||||||||||||||||
| 2046 | static const QMetaObject *customMetaObject(const int type) | - | ||||||||||||||||||||||||
| 2047 | { | - | ||||||||||||||||||||||||
| 2048 | const QVector<QCustomTypeInfo> * const ct = customTypes(); | - | ||||||||||||||||||||||||
| 2049 | if (Q_UNLIKELY(!ct || type < QMetaType::User)) | - | ||||||||||||||||||||||||
| 2050 | return 0; | - | ||||||||||||||||||||||||
| 2051 | QReadLocker locker(customTypesLock()); | - | ||||||||||||||||||||||||
| 2052 | if (Q_UNLIKELY(ct->count() <= type - QMetaType::User)) | - | ||||||||||||||||||||||||
| 2053 | return 0; | - | ||||||||||||||||||||||||
| 2054 | return ct->at(type - QMetaType::User).metaObject; | - | ||||||||||||||||||||||||
| 2055 | } | - | ||||||||||||||||||||||||
| 2056 | }; | - | ||||||||||||||||||||||||
| 2057 | } // namespace | - | ||||||||||||||||||||||||
| 2058 | #endif | - | ||||||||||||||||||||||||
| 2059 | - | |||||||||||||||||||||||||
| 2060 | /*! | - | ||||||||||||||||||||||||
| 2061 | \since 5.0 | - | ||||||||||||||||||||||||
| 2062 | - | |||||||||||||||||||||||||
| 2063 | returns QMetaType::metaObject for \a type | - | ||||||||||||||||||||||||
| 2064 | - | |||||||||||||||||||||||||
| 2065 | \sa metaObject() | - | ||||||||||||||||||||||||
| 2066 | */ | - | ||||||||||||||||||||||||
| 2067 | const QMetaObject *QMetaType::metaObjectForType(int type) | - | ||||||||||||||||||||||||
| 2068 | { | - | ||||||||||||||||||||||||
| 2069 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
| 2070 | MetaObject mo(type); | - | ||||||||||||||||||||||||
| 2071 | return QMetaTypeSwitcher::switcher<const QMetaObject*>(mo, type, 0); | - | ||||||||||||||||||||||||
| 2072 | #else | - | ||||||||||||||||||||||||
| 2073 | Q_UNUSED(type); | - | ||||||||||||||||||||||||
| 2074 | return 0; | - | ||||||||||||||||||||||||
| 2075 | #endif | - | ||||||||||||||||||||||||
| 2076 | } | - | ||||||||||||||||||||||||
| 2077 | - | |||||||||||||||||||||||||
| 2078 | /*! | - | ||||||||||||||||||||||||
| 2079 | \fn int qRegisterMetaType(const char *typeName) | - | ||||||||||||||||||||||||
| 2080 | \relates QMetaType | - | ||||||||||||||||||||||||
| 2081 | \threadsafe | - | ||||||||||||||||||||||||
| 2082 | - | |||||||||||||||||||||||||
| 2083 | Registers the type name \a typeName for the type \c{T}. Returns | - | ||||||||||||||||||||||||
| 2084 | the internal ID used by QMetaType. Any class or struct that has a | - | ||||||||||||||||||||||||
| 2085 | public default constructor, a public copy constructor and a public | - | ||||||||||||||||||||||||
| 2086 | destructor can be registered. | - | ||||||||||||||||||||||||
| 2087 | - | |||||||||||||||||||||||||
| 2088 | This function requires that \c{T} is a fully defined type at the point | - | ||||||||||||||||||||||||
| 2089 | where the function is called. For pointer types, it also requires that the | - | ||||||||||||||||||||||||
| 2090 | pointed to type is fully defined. Use Q_DECLARE_OPAQUE_POINTER() to be able | - | ||||||||||||||||||||||||
| 2091 | to register pointers to forward declared types. | - | ||||||||||||||||||||||||
| 2092 | - | |||||||||||||||||||||||||
| 2093 | After a type has been registered, you can create and destroy | - | ||||||||||||||||||||||||
| 2094 | objects of that type dynamically at run-time. | - | ||||||||||||||||||||||||
| 2095 | - | |||||||||||||||||||||||||
| 2096 | This example registers the class \c{MyClass}: | - | ||||||||||||||||||||||||
| 2097 | - | |||||||||||||||||||||||||
| 2098 | \snippet code/src_corelib_kernel_qmetatype.cpp 4 | - | ||||||||||||||||||||||||
| 2099 | - | |||||||||||||||||||||||||
| 2100 | This function is useful to register typedefs so they can be used | - | ||||||||||||||||||||||||
| 2101 | by QMetaProperty, or in QueuedConnections | - | ||||||||||||||||||||||||
| 2102 | - | |||||||||||||||||||||||||
| 2103 | \snippet code/src_corelib_kernel_qmetatype.cpp 9 | - | ||||||||||||||||||||||||
| 2104 | - | |||||||||||||||||||||||||
| 2105 | \warning This function is useful only for registering an alias (typedef) | - | ||||||||||||||||||||||||
| 2106 | for every other use case Q_DECLARE_METATYPE and qMetaTypeId() should be used instead. | - | ||||||||||||||||||||||||
| 2107 | - | |||||||||||||||||||||||||
| 2108 | \sa {QMetaType::}{qRegisterMetaTypeStreamOperators()}, {QMetaType::}{isRegistered()}, | - | ||||||||||||||||||||||||
| 2109 | Q_DECLARE_METATYPE() | - | ||||||||||||||||||||||||
| 2110 | */ | - | ||||||||||||||||||||||||
| 2111 | - | |||||||||||||||||||||||||
| 2112 | /*! | - | ||||||||||||||||||||||||
| 2113 | \fn void qRegisterMetaTypeStreamOperators(const char *typeName) | - | ||||||||||||||||||||||||
| 2114 | \relates QMetaType | - | ||||||||||||||||||||||||
| 2115 | \threadsafe | - | ||||||||||||||||||||||||
| 2116 | - | |||||||||||||||||||||||||
| 2117 | Registers the stream operators for the type \c{T} called \a | - | ||||||||||||||||||||||||
| 2118 | typeName. | - | ||||||||||||||||||||||||
| 2119 | - | |||||||||||||||||||||||||
| 2120 | Afterward, the type can be streamed using QMetaType::load() and | - | ||||||||||||||||||||||||
| 2121 | QMetaType::save(). These functions are used when streaming a | - | ||||||||||||||||||||||||
| 2122 | QVariant. | - | ||||||||||||||||||||||||
| 2123 | - | |||||||||||||||||||||||||
| 2124 | \snippet code/src_corelib_kernel_qmetatype.cpp 5 | - | ||||||||||||||||||||||||
| 2125 | - | |||||||||||||||||||||||||
| 2126 | The stream operators should have the following signatures: | - | ||||||||||||||||||||||||
| 2127 | - | |||||||||||||||||||||||||
| 2128 | \snippet code/src_corelib_kernel_qmetatype.cpp 6 | - | ||||||||||||||||||||||||
| 2129 | - | |||||||||||||||||||||||||
| 2130 | \sa qRegisterMetaType(), QMetaType::isRegistered(), Q_DECLARE_METATYPE() | - | ||||||||||||||||||||||||
| 2131 | */ | - | ||||||||||||||||||||||||
| 2132 | - | |||||||||||||||||||||||||
| 2133 | /*! \typedef QMetaType::Deleter | - | ||||||||||||||||||||||||
| 2134 | \internal | - | ||||||||||||||||||||||||
| 2135 | */ | - | ||||||||||||||||||||||||
| 2136 | /*! \typedef QMetaType::Creator | - | ||||||||||||||||||||||||
| 2137 | \internal | - | ||||||||||||||||||||||||
| 2138 | */ | - | ||||||||||||||||||||||||
| 2139 | /*! \typedef QMetaType::SaveOperator | - | ||||||||||||||||||||||||
| 2140 | \internal | - | ||||||||||||||||||||||||
| 2141 | */ | - | ||||||||||||||||||||||||
| 2142 | /*! \typedef QMetaType::LoadOperator | - | ||||||||||||||||||||||||
| 2143 | \internal | - | ||||||||||||||||||||||||
| 2144 | */ | - | ||||||||||||||||||||||||
| 2145 | /*! \typedef QMetaType::Destructor | - | ||||||||||||||||||||||||
| 2146 | \internal | - | ||||||||||||||||||||||||
| 2147 | */ | - | ||||||||||||||||||||||||
| 2148 | /*! \typedef QMetaType::Constructor | - | ||||||||||||||||||||||||
| 2149 | \internal | - | ||||||||||||||||||||||||
| 2150 | */ | - | ||||||||||||||||||||||||
| 2151 | - | |||||||||||||||||||||||||
| 2152 | /*! | - | ||||||||||||||||||||||||
| 2153 | \fn int qRegisterMetaType() | - | ||||||||||||||||||||||||
| 2154 | \relates QMetaType | - | ||||||||||||||||||||||||
| 2155 | \threadsafe | - | ||||||||||||||||||||||||
| 2156 | \since 4.2 | - | ||||||||||||||||||||||||
| 2157 | - | |||||||||||||||||||||||||
| 2158 | Call this function to register the type \c T. \c T must be declared with | - | ||||||||||||||||||||||||
| 2159 | Q_DECLARE_METATYPE(). Returns the meta type Id. | - | ||||||||||||||||||||||||
| 2160 | - | |||||||||||||||||||||||||
| 2161 | Example: | - | ||||||||||||||||||||||||
| 2162 | - | |||||||||||||||||||||||||
| 2163 | \snippet code/src_corelib_kernel_qmetatype.cpp 7 | - | ||||||||||||||||||||||||
| 2164 | - | |||||||||||||||||||||||||
| 2165 | This function requires that \c{T} is a fully defined type at the point | - | ||||||||||||||||||||||||
| 2166 | where the function is called. For pointer types, it also requires that the | - | ||||||||||||||||||||||||
| 2167 | pointed to type is fully defined. Use Q_DECLARE_OPAQUE_POINTER() to be able | - | ||||||||||||||||||||||||
| 2168 | to register pointers to forward declared types. | - | ||||||||||||||||||||||||
| 2169 | - | |||||||||||||||||||||||||
| 2170 | After a type has been registered, you can create and destroy | - | ||||||||||||||||||||||||
| 2171 | objects of that type dynamically at run-time. | - | ||||||||||||||||||||||||
| 2172 | - | |||||||||||||||||||||||||
| 2173 | To use the type \c T in QVariant, using Q_DECLARE_METATYPE() is | - | ||||||||||||||||||||||||
| 2174 | sufficient. To use the type \c T in queued signal and slot connections, | - | ||||||||||||||||||||||||
| 2175 | \c{qRegisterMetaType<T>()} must be called before the first connection | - | ||||||||||||||||||||||||
| 2176 | is established. | - | ||||||||||||||||||||||||
| 2177 | - | |||||||||||||||||||||||||
| 2178 | Also, to use type \c T with the QObject::property() API, | - | ||||||||||||||||||||||||
| 2179 | \c{qRegisterMetaType<T>()} must be called before it is used, typically | - | ||||||||||||||||||||||||
| 2180 | in the constructor of the class that uses \c T, or in the \c{main()} | - | ||||||||||||||||||||||||
| 2181 | function. | - | ||||||||||||||||||||||||
| 2182 | - | |||||||||||||||||||||||||
| 2183 | \sa Q_DECLARE_METATYPE() | - | ||||||||||||||||||||||||
| 2184 | */ | - | ||||||||||||||||||||||||
| 2185 | - | |||||||||||||||||||||||||
| 2186 | /*! | - | ||||||||||||||||||||||||
| 2187 | \fn int qMetaTypeId() | - | ||||||||||||||||||||||||
| 2188 | \relates QMetaType | - | ||||||||||||||||||||||||
| 2189 | \threadsafe | - | ||||||||||||||||||||||||
| 2190 | \since 4.1 | - | ||||||||||||||||||||||||
| 2191 | - | |||||||||||||||||||||||||
| 2192 | Returns the meta type id of type \c T at compile time. If the | - | ||||||||||||||||||||||||
| 2193 | type was not declared with Q_DECLARE_METATYPE(), compilation will | - | ||||||||||||||||||||||||
| 2194 | fail. | - | ||||||||||||||||||||||||
| 2195 | - | |||||||||||||||||||||||||
| 2196 | Typical usage: | - | ||||||||||||||||||||||||
| 2197 | - | |||||||||||||||||||||||||
| 2198 | \snippet code/src_corelib_kernel_qmetatype.cpp 8 | - | ||||||||||||||||||||||||
| 2199 | - | |||||||||||||||||||||||||
| 2200 | QMetaType::type() returns the same ID as qMetaTypeId(), but does | - | ||||||||||||||||||||||||
| 2201 | a lookup at runtime based on the name of the type. | - | ||||||||||||||||||||||||
| 2202 | QMetaType::type() is a bit slower, but compilation succeeds if a | - | ||||||||||||||||||||||||
| 2203 | type is not registered. | - | ||||||||||||||||||||||||
| 2204 | - | |||||||||||||||||||||||||
| 2205 | \sa Q_DECLARE_METATYPE(), QMetaType::type() | - | ||||||||||||||||||||||||
| 2206 | */ | - | ||||||||||||||||||||||||
| 2207 | - | |||||||||||||||||||||||||
| 2208 | namespace { | - | ||||||||||||||||||||||||
| 2209 | class TypeInfo { | - | ||||||||||||||||||||||||
| 2210 | template<typename T, bool IsAcceptedType = DefinedTypesFilter::Acceptor<T>::IsAccepted> | - | ||||||||||||||||||||||||
| 2211 | struct TypeInfoImpl | - | ||||||||||||||||||||||||
| 2212 | { | - | ||||||||||||||||||||||||
| 2213 | TypeInfoImpl(const uint /* type */, QMetaTypeInterface &info) | - | ||||||||||||||||||||||||
| 2214 | { | - | ||||||||||||||||||||||||
| 2215 | QMetaTypeInterface tmp = QT_METATYPE_INTERFACE_INIT_NO_DATASTREAM(T); | - | ||||||||||||||||||||||||
| 2216 | info = tmp; | - | ||||||||||||||||||||||||
| 2217 | } | - | ||||||||||||||||||||||||
| 2218 | }; | - | ||||||||||||||||||||||||
| 2219 | - | |||||||||||||||||||||||||
| 2220 | template<typename T> | - | ||||||||||||||||||||||||
| 2221 | struct TypeInfoImpl<T, /* IsAcceptedType = */ false> | - | ||||||||||||||||||||||||
| 2222 | { | - | ||||||||||||||||||||||||
| 2223 | TypeInfoImpl(const uint type, QMetaTypeInterface &info) | - | ||||||||||||||||||||||||
| 2224 | { | - | ||||||||||||||||||||||||
| 2225 | if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) { | - | ||||||||||||||||||||||||
| 2226 | if (Q_LIKELY(qMetaTypeGuiHelper)) | - | ||||||||||||||||||||||||
| 2227 | info = qMetaTypeGuiHelper[type - QMetaType::FirstGuiType]; | - | ||||||||||||||||||||||||
| 2228 | return; | - | ||||||||||||||||||||||||
| 2229 | } | - | ||||||||||||||||||||||||
| 2230 | if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) { | - | ||||||||||||||||||||||||
| 2231 | if (Q_LIKELY(qMetaTypeWidgetsHelper)) | - | ||||||||||||||||||||||||
| 2232 | info = qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType]; | - | ||||||||||||||||||||||||
| 2233 | return; | - | ||||||||||||||||||||||||
| 2234 | } | - | ||||||||||||||||||||||||
| 2235 | } | - | ||||||||||||||||||||||||
| 2236 | }; | - | ||||||||||||||||||||||||
| 2237 | public: | - | ||||||||||||||||||||||||
| 2238 | QMetaTypeInterface info; | - | ||||||||||||||||||||||||
| 2239 | TypeInfo(const uint type) | - | ||||||||||||||||||||||||
| 2240 | : m_type(type) | - | ||||||||||||||||||||||||
| 2241 | { | - | ||||||||||||||||||||||||
| 2242 | QMetaTypeInterface tmp = QT_METATYPE_INTERFACE_INIT_EMPTY(); | - | ||||||||||||||||||||||||
| 2243 | info = tmp; | - | ||||||||||||||||||||||||
| 2244 | } | - | ||||||||||||||||||||||||
| 2245 | template<typename T> | - | ||||||||||||||||||||||||
| 2246 | void delegate(const T*) { TypeInfoImpl<T>(m_type, info); } | - | ||||||||||||||||||||||||
| 2247 | void delegate(const QMetaTypeSwitcher::UnknownType*) {} | - | ||||||||||||||||||||||||
| 2248 | void delegate(const QMetaTypeSwitcher::NotBuiltinType*) { customTypeInfo(m_type); } | - | ||||||||||||||||||||||||
| 2249 | private: | - | ||||||||||||||||||||||||
| 2250 | void customTypeInfo(const uint type) | - | ||||||||||||||||||||||||
| 2251 | { | - | ||||||||||||||||||||||||
| 2252 | const QVector<QCustomTypeInfo> * const ct = customTypes(); | - | ||||||||||||||||||||||||
| 2253 | if (Q_UNLIKELY(!ct)) | - | ||||||||||||||||||||||||
| 2254 | return; | - | ||||||||||||||||||||||||
| 2255 | QReadLocker locker(customTypesLock()); | - | ||||||||||||||||||||||||
| 2256 | if (Q_LIKELY(uint(ct->count()) > type - QMetaType::User)) | - | ||||||||||||||||||||||||
| 2257 | info = ct->at(type - QMetaType::User); | - | ||||||||||||||||||||||||
| 2258 | } | - | ||||||||||||||||||||||||
| 2259 | - | |||||||||||||||||||||||||
| 2260 | const uint m_type; | - | ||||||||||||||||||||||||
| 2261 | }; | - | ||||||||||||||||||||||||
| 2262 | } // namespace | - | ||||||||||||||||||||||||
| 2263 | - | |||||||||||||||||||||||||
| 2264 | /*! | - | ||||||||||||||||||||||||
| 2265 | \fn QMetaType QMetaType::typeInfo(const int type) | - | ||||||||||||||||||||||||
| 2266 | \internal | - | ||||||||||||||||||||||||
| 2267 | */ | - | ||||||||||||||||||||||||
| 2268 | QMetaType QMetaType::typeInfo(const int type) | - | ||||||||||||||||||||||||
| 2269 | { | - | ||||||||||||||||||||||||
| 2270 | TypeInfo typeInfo(type); | - | ||||||||||||||||||||||||
| 2271 | QMetaTypeSwitcher::switcher<void>(typeInfo, type, 0); | - | ||||||||||||||||||||||||
| 2272 | return typeInfo.info.constructor ? QMetaType(static_cast<ExtensionFlag>(QMetaType::CreateEx | QMetaType::DestroyEx) | - | ||||||||||||||||||||||||
| 2273 | , static_cast<const QMetaTypeInterface *>(0) // typeInfo::info is a temporary variable, we can't return address of it. | - | ||||||||||||||||||||||||
| 2274 | , 0 // unused | - | ||||||||||||||||||||||||
| 2275 | , 0 // unused | - | ||||||||||||||||||||||||
| 2276 | , typeInfo.info.saveOp | - | ||||||||||||||||||||||||
| 2277 | , typeInfo.info.loadOp | - | ||||||||||||||||||||||||
| 2278 | , typeInfo.info.constructor | - | ||||||||||||||||||||||||
| 2279 | , typeInfo.info.destructor | - | ||||||||||||||||||||||||
| 2280 | , typeInfo.info.size | - | ||||||||||||||||||||||||
| 2281 | , typeInfo.info.flags | - | ||||||||||||||||||||||||
| 2282 | , type | - | ||||||||||||||||||||||||
| 2283 | , typeInfo.info.metaObject) | - | ||||||||||||||||||||||||
| 2284 | : QMetaType(UnknownType); | - | ||||||||||||||||||||||||
| 2285 | } | - | ||||||||||||||||||||||||
| 2286 | - | |||||||||||||||||||||||||
| 2287 | /*! | - | ||||||||||||||||||||||||
| 2288 | \fn QMetaType::QMetaType(const int typeId) | - | ||||||||||||||||||||||||
| 2289 | \since 5.0 | - | ||||||||||||||||||||||||
| 2290 | - | |||||||||||||||||||||||||
| 2291 | Constructs a QMetaType object that contains all information about type \a typeId. | - | ||||||||||||||||||||||||
| 2292 | */ | - | ||||||||||||||||||||||||
| 2293 | QMetaType::QMetaType(const int typeId) | - | ||||||||||||||||||||||||
| 2294 | : m_typeId(typeId) | - | ||||||||||||||||||||||||
| 2295 | { | - | ||||||||||||||||||||||||
| 2296 | if (Q_UNLIKELY(typeId == UnknownType)) { | - | ||||||||||||||||||||||||
| 2297 | // Constructs invalid QMetaType instance. | - | ||||||||||||||||||||||||
| 2298 | m_extensionFlags = 0xffffffff; | - | ||||||||||||||||||||||||
| 2299 | Q_ASSERT(!isValid()); | - | ||||||||||||||||||||||||
| 2300 | } else { | - | ||||||||||||||||||||||||
| 2301 | // TODO it can be better. | - | ||||||||||||||||||||||||
| 2302 | *this = QMetaType::typeInfo(typeId); | - | ||||||||||||||||||||||||
| 2303 | if (m_typeId == UnknownType) | - | ||||||||||||||||||||||||
| 2304 | m_extensionFlags = 0xffffffff; | - | ||||||||||||||||||||||||
| 2305 | else if (m_typeId == QMetaType::Void) | - | ||||||||||||||||||||||||
| 2306 | m_extensionFlags = CreateEx | DestroyEx | ConstructEx | DestructEx; | - | ||||||||||||||||||||||||
| 2307 | } | - | ||||||||||||||||||||||||
| 2308 | } | - | ||||||||||||||||||||||||
| 2309 | - | |||||||||||||||||||||||||
| 2310 | /*! | - | ||||||||||||||||||||||||
| 2311 | \fn QMetaType::QMetaType(const QMetaType &other) | - | ||||||||||||||||||||||||
| 2312 | \since 5.0 | - | ||||||||||||||||||||||||
| 2313 | - | |||||||||||||||||||||||||
| 2314 | Copy constructs a QMetaType object. | - | ||||||||||||||||||||||||
| 2315 | */ | - | ||||||||||||||||||||||||
| 2316 | QMetaType::QMetaType(const QMetaType &other) | - | ||||||||||||||||||||||||
| 2317 | : m_creator_unused(other.m_creator_unused) | - | ||||||||||||||||||||||||
| 2318 | , m_deleter_unused(other.m_deleter_unused) | - | ||||||||||||||||||||||||
| 2319 | , m_saveOp(other.m_saveOp) | - | ||||||||||||||||||||||||
| 2320 | , m_loadOp(other.m_loadOp) | - | ||||||||||||||||||||||||
| 2321 | , m_constructor(other.m_constructor) | - | ||||||||||||||||||||||||
| 2322 | , m_destructor(other.m_destructor) | - | ||||||||||||||||||||||||
| 2323 | , m_extension(other.m_extension) // space reserved for future use | - | ||||||||||||||||||||||||
| 2324 | , m_size(other.m_size) | - | ||||||||||||||||||||||||
| 2325 | , m_typeFlags(other.m_typeFlags) | - | ||||||||||||||||||||||||
| 2326 | , m_extensionFlags(other.m_extensionFlags) | - | ||||||||||||||||||||||||
| 2327 | , m_typeId(other.m_typeId) | - | ||||||||||||||||||||||||
| 2328 | , m_metaObject(other.m_metaObject) | - | ||||||||||||||||||||||||
| 2329 | {} | - | ||||||||||||||||||||||||
| 2330 | - | |||||||||||||||||||||||||
| 2331 | QMetaType &QMetaType::operator =(const QMetaType &other) | - | ||||||||||||||||||||||||
| 2332 | { | - | ||||||||||||||||||||||||
| 2333 | m_creator_unused = other.m_creator_unused; | - | ||||||||||||||||||||||||
| 2334 | m_deleter_unused = other.m_deleter_unused; | - | ||||||||||||||||||||||||
| 2335 | m_saveOp = other.m_saveOp; | - | ||||||||||||||||||||||||
| 2336 | m_loadOp = other.m_loadOp; | - | ||||||||||||||||||||||||
| 2337 | m_constructor = other.m_constructor; | - | ||||||||||||||||||||||||
| 2338 | m_destructor = other.m_destructor; | - | ||||||||||||||||||||||||
| 2339 | m_size = other.m_size; | - | ||||||||||||||||||||||||
| 2340 | m_typeFlags = other.m_typeFlags; | - | ||||||||||||||||||||||||
| 2341 | m_extensionFlags = other.m_extensionFlags; | - | ||||||||||||||||||||||||
| 2342 | m_extension = other.m_extension; // space reserved for future use | - | ||||||||||||||||||||||||
| 2343 | m_typeId = other.m_typeId; | - | ||||||||||||||||||||||||
| 2344 | m_metaObject = other.m_metaObject; | - | ||||||||||||||||||||||||
| 2345 | return *this; | - | ||||||||||||||||||||||||
| 2346 | } | - | ||||||||||||||||||||||||
| 2347 | - | |||||||||||||||||||||||||
| 2348 | /*! | - | ||||||||||||||||||||||||
| 2349 | \fn void QMetaType::ctor(const QMetaTypeInterface *info) | - | ||||||||||||||||||||||||
| 2350 | \internal | - | ||||||||||||||||||||||||
| 2351 | - | |||||||||||||||||||||||||
| 2352 | Method used for future binary compatible extensions. The function may be | - | ||||||||||||||||||||||||
| 2353 | called from within QMetaType's constructor to force a library call from | - | ||||||||||||||||||||||||
| 2354 | inlined code. | - | ||||||||||||||||||||||||
| 2355 | */ | - | ||||||||||||||||||||||||
| 2356 | void QMetaType::ctor(const QMetaTypeInterface *info) | - | ||||||||||||||||||||||||
| 2357 | { | - | ||||||||||||||||||||||||
| 2358 | // Special case for Void type, the type is valid but not constructible. | - | ||||||||||||||||||||||||
| 2359 | // In future we may consider to remove this assert and extend this function to initialize | - | ||||||||||||||||||||||||
| 2360 | // differently m_extensionFlags for different types. Currently it is not needed. | - | ||||||||||||||||||||||||
| 2361 | Q_ASSERT(m_typeId == QMetaType::Void); | - | ||||||||||||||||||||||||
| 2362 | Q_UNUSED(info); | - | ||||||||||||||||||||||||
| 2363 | m_extensionFlags = CreateEx | DestroyEx | ConstructEx | DestructEx; | - | ||||||||||||||||||||||||
| 2364 | } | - | ||||||||||||||||||||||||
| 2365 | - | |||||||||||||||||||||||||
| 2366 | /*! | - | ||||||||||||||||||||||||
| 2367 | \fn void QMetaType::dtor() | - | ||||||||||||||||||||||||
| 2368 | \internal | - | ||||||||||||||||||||||||
| 2369 | - | |||||||||||||||||||||||||
| 2370 | Method used for future binary compatible extensions. The function may be | - | ||||||||||||||||||||||||
| 2371 | called from within QMetaType's destructor to force a library call from | - | ||||||||||||||||||||||||
| 2372 | inlined code. | - | ||||||||||||||||||||||||
| 2373 | */ | - | ||||||||||||||||||||||||
| 2374 | void QMetaType::dtor() | - | ||||||||||||||||||||||||
| 2375 | {} | - | ||||||||||||||||||||||||
| 2376 | - | |||||||||||||||||||||||||
| 2377 | /*! | - | ||||||||||||||||||||||||
| 2378 | \fn void *QMetaType::createExtended(const void *copy) const | - | ||||||||||||||||||||||||
| 2379 | \internal | - | ||||||||||||||||||||||||
| 2380 | - | |||||||||||||||||||||||||
| 2381 | Method used for future binary compatible extensions. The function may be called | - | ||||||||||||||||||||||||
| 2382 | during QMetaType::create to force library call from inlined code. | - | ||||||||||||||||||||||||
| 2383 | - | |||||||||||||||||||||||||
| 2384 | ### TODO Qt6 remove the extension | - | ||||||||||||||||||||||||
| 2385 | */ | - | ||||||||||||||||||||||||
| 2386 | void *QMetaType::createExtended(const void *copy) const | - | ||||||||||||||||||||||||
| 2387 | { | - | ||||||||||||||||||||||||
| 2388 | if (m_typeId == QMetaType::UnknownType) | - | ||||||||||||||||||||||||
| 2389 | return 0; | - | ||||||||||||||||||||||||
| 2390 | return m_constructor(operator new(m_size), copy); | - | ||||||||||||||||||||||||
| 2391 | } | - | ||||||||||||||||||||||||
| 2392 | - | |||||||||||||||||||||||||
| 2393 | /*! | - | ||||||||||||||||||||||||
| 2394 | \fn void QMetaType::destroyExtended(void *data) const | - | ||||||||||||||||||||||||
| 2395 | \internal | - | ||||||||||||||||||||||||
| 2396 | - | |||||||||||||||||||||||||
| 2397 | Method used for future binary compatible extensions. The function may be called | - | ||||||||||||||||||||||||
| 2398 | during QMetaType::destroy to force library call from inlined code. | - | ||||||||||||||||||||||||
| 2399 | - | |||||||||||||||||||||||||
| 2400 | ### TODO Qt6 remove the extension | - | ||||||||||||||||||||||||
| 2401 | */ | - | ||||||||||||||||||||||||
| 2402 | void QMetaType::destroyExtended(void *data) const | - | ||||||||||||||||||||||||
| 2403 | { | - | ||||||||||||||||||||||||
| 2404 | m_destructor(data); | - | ||||||||||||||||||||||||
| 2405 | operator delete(data); | - | ||||||||||||||||||||||||
| 2406 | } | - | ||||||||||||||||||||||||
| 2407 | - | |||||||||||||||||||||||||
| 2408 | /*! | - | ||||||||||||||||||||||||
| 2409 | \fn void *QMetaType::constructExtended(void *where, const void *copy) const | - | ||||||||||||||||||||||||
| 2410 | \internal | - | ||||||||||||||||||||||||
| 2411 | - | |||||||||||||||||||||||||
| 2412 | Method used for future binary compatible extensions. The function may be called | - | ||||||||||||||||||||||||
| 2413 | during QMetaType::construct to force library call from inlined code. | - | ||||||||||||||||||||||||
| 2414 | */ | - | ||||||||||||||||||||||||
| 2415 | void *QMetaType::constructExtended(void *where, const void *copy) const | - | ||||||||||||||||||||||||
| 2416 | { | - | ||||||||||||||||||||||||
| 2417 | Q_UNUSED(where); | - | ||||||||||||||||||||||||
| 2418 | Q_UNUSED(copy); | - | ||||||||||||||||||||||||
| 2419 | return 0; | - | ||||||||||||||||||||||||
| 2420 | } | - | ||||||||||||||||||||||||
| 2421 | - | |||||||||||||||||||||||||
| 2422 | /*! | - | ||||||||||||||||||||||||
| 2423 | \fn void QMetaType::destructExtended(void *data) const | - | ||||||||||||||||||||||||
| 2424 | \internal | - | ||||||||||||||||||||||||
| 2425 | - | |||||||||||||||||||||||||
| 2426 | Method used for future binary compatible extensions. The function may be called | - | ||||||||||||||||||||||||
| 2427 | during QMetaType::destruct to force library call from inlined code. | - | ||||||||||||||||||||||||
| 2428 | */ | - | ||||||||||||||||||||||||
| 2429 | void QMetaType::destructExtended(void *data) const | - | ||||||||||||||||||||||||
| 2430 | { | - | ||||||||||||||||||||||||
| 2431 | Q_UNUSED(data); | - | ||||||||||||||||||||||||
| 2432 | } | - | ||||||||||||||||||||||||
| 2433 | - | |||||||||||||||||||||||||
| 2434 | /*! | - | ||||||||||||||||||||||||
| 2435 | \fn uint QMetaType::sizeExtended() const | - | ||||||||||||||||||||||||
| 2436 | \internal | - | ||||||||||||||||||||||||
| 2437 | - | |||||||||||||||||||||||||
| 2438 | Method used for future binary compatible extensions. The function may be | - | ||||||||||||||||||||||||
| 2439 | called from within QMetaType::size to force a library call from | - | ||||||||||||||||||||||||
| 2440 | inlined code. | - | ||||||||||||||||||||||||
| 2441 | */ | - | ||||||||||||||||||||||||
| 2442 | uint QMetaType::sizeExtended() const | - | ||||||||||||||||||||||||
| 2443 | { | - | ||||||||||||||||||||||||
| 2444 | return 0; | - | ||||||||||||||||||||||||
| 2445 | } | - | ||||||||||||||||||||||||
| 2446 | - | |||||||||||||||||||||||||
| 2447 | /*! | - | ||||||||||||||||||||||||
| 2448 | \fn QMetaType::TypeFlags QMetaType::flagsExtended() const | - | ||||||||||||||||||||||||
| 2449 | \internal | - | ||||||||||||||||||||||||
| 2450 | - | |||||||||||||||||||||||||
| 2451 | Method used for future binary compatible extensions. The function may be | - | ||||||||||||||||||||||||
| 2452 | called from within QMetaType::flags to force a library call from | - | ||||||||||||||||||||||||
| 2453 | inlined code. | - | ||||||||||||||||||||||||
| 2454 | */ | - | ||||||||||||||||||||||||
| 2455 | QMetaType::TypeFlags QMetaType::flagsExtended() const | - | ||||||||||||||||||||||||
| 2456 | { | - | ||||||||||||||||||||||||
| 2457 | return 0; | - | ||||||||||||||||||||||||
| 2458 | } | - | ||||||||||||||||||||||||
| 2459 | - | |||||||||||||||||||||||||
| 2460 | /*! | - | ||||||||||||||||||||||||
| 2461 | \brief QMetaType::metaObjectExtended | - | ||||||||||||||||||||||||
| 2462 | \internal | - | ||||||||||||||||||||||||
| 2463 | - | |||||||||||||||||||||||||
| 2464 | Method used for future binary compatible extensions. The function may be | - | ||||||||||||||||||||||||
| 2465 | called from within QMetaType::metaObject to force a library call from | - | ||||||||||||||||||||||||
| 2466 | inlined code. | - | ||||||||||||||||||||||||
| 2467 | */ | - | ||||||||||||||||||||||||
| 2468 | const QMetaObject *QMetaType::metaObjectExtended() const | - | ||||||||||||||||||||||||
| 2469 | { | - | ||||||||||||||||||||||||
| 2470 | return 0; | - | ||||||||||||||||||||||||
| 2471 | } | - | ||||||||||||||||||||||||
| 2472 | - | |||||||||||||||||||||||||
| 2473 | - | |||||||||||||||||||||||||
| 2474 | namespace QtPrivate | - | ||||||||||||||||||||||||
| 2475 | { | - | ||||||||||||||||||||||||
| 2476 | const QMetaObject *metaObjectForQWidget() | - | ||||||||||||||||||||||||
| 2477 | { | - | ||||||||||||||||||||||||
| 2478 | if (!qMetaTypeWidgetsHelper) | - | ||||||||||||||||||||||||
| 2479 | return 0; | - | ||||||||||||||||||||||||
| 2480 | return qMetaObjectWidgetsHelper; | - | ||||||||||||||||||||||||
| 2481 | } | - | ||||||||||||||||||||||||
| 2482 | } | - | ||||||||||||||||||||||||
| 2483 | - | |||||||||||||||||||||||||
| 2484 | namespace QtMetaTypePrivate { | - | ||||||||||||||||||||||||
| 2485 | const bool VectorBoolElements::true_element = true; | - | ||||||||||||||||||||||||
| 2486 | const bool VectorBoolElements::false_element = false; | - | ||||||||||||||||||||||||
| 2487 | } | - | ||||||||||||||||||||||||
| 2488 | - | |||||||||||||||||||||||||
| 2489 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |