| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com)
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at qt-sales@nokia.com.
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include "qvariant.h"
|
|---|
| 43 |
|
|---|
| 44 | #include "qbitmap.h"
|
|---|
| 45 | #include "qbrush.h"
|
|---|
| 46 | #include "qcolor.h"
|
|---|
| 47 | #include "qcursor.h"
|
|---|
| 48 | #include "qdatastream.h"
|
|---|
| 49 | #include "qdebug.h"
|
|---|
| 50 | #include "qfont.h"
|
|---|
| 51 | #include "qicon.h"
|
|---|
| 52 | #include "qimage.h"
|
|---|
| 53 | #include "qkeysequence.h"
|
|---|
| 54 | #include "qtransform.h"
|
|---|
| 55 | #include "qmatrix.h"
|
|---|
| 56 | #include "qpalette.h"
|
|---|
| 57 | #include "qpen.h"
|
|---|
| 58 | #include "qpixmap.h"
|
|---|
| 59 | #include "qpolygon.h"
|
|---|
| 60 | #include "qregion.h"
|
|---|
| 61 | #include "qsizepolicy.h"
|
|---|
| 62 | #include "qtextformat.h"
|
|---|
| 63 |
|
|---|
| 64 | #include "private/qvariant_p.h"
|
|---|
| 65 |
|
|---|
| 66 | QT_BEGIN_NAMESPACE
|
|---|
| 67 |
|
|---|
| 68 | #ifdef QT3_SUPPORT
|
|---|
| 69 | extern QDataStream &qt_stream_out_qcolorgroup(QDataStream &s, const QColorGroup &g);
|
|---|
| 70 | extern QDataStream &qt_stream_in_qcolorgroup(QDataStream &s, QColorGroup &g);
|
|---|
| 71 | #endif
|
|---|
| 72 |
|
|---|
| 73 | Q_CORE_EXPORT const QVariant::Handler *qcoreVariantHandler();
|
|---|
| 74 |
|
|---|
| 75 | static void construct(QVariant::Private *x, const void *copy)
|
|---|
| 76 | {
|
|---|
| 77 | switch (x->type) {
|
|---|
| 78 | case QVariant::Bitmap:
|
|---|
| 79 | v_construct<QBitmap>(x, copy);
|
|---|
| 80 | break;
|
|---|
| 81 | case QVariant::Region:
|
|---|
| 82 | v_construct<QRegion>(x, copy);
|
|---|
| 83 | break;
|
|---|
| 84 | case QVariant::Polygon:
|
|---|
| 85 | v_construct<QPolygon>(x, copy);
|
|---|
| 86 | break;
|
|---|
| 87 | case QVariant::Font:
|
|---|
| 88 | v_construct<QFont>(x, copy);
|
|---|
| 89 | break;
|
|---|
| 90 | case QVariant::Pixmap:
|
|---|
| 91 | v_construct<QPixmap>(x, copy);
|
|---|
| 92 | break;
|
|---|
| 93 | case QVariant::Image:
|
|---|
| 94 | v_construct<QImage>(x, copy);
|
|---|
| 95 | break;
|
|---|
| 96 | case QVariant::Brush:
|
|---|
| 97 | v_construct<QBrush>(x, copy);
|
|---|
| 98 | break;
|
|---|
| 99 | case QVariant::Color:
|
|---|
| 100 | v_construct<QColor>(x, copy);
|
|---|
| 101 | break;
|
|---|
| 102 | case QVariant::Palette:
|
|---|
| 103 | v_construct<QPalette>(x, copy);
|
|---|
| 104 | break;
|
|---|
| 105 | #ifdef QT3_SUPPORT
|
|---|
| 106 | case QVariant::ColorGroup:
|
|---|
| 107 | v_construct<QColorGroup>(x, copy);
|
|---|
| 108 | break;
|
|---|
| 109 | #endif
|
|---|
| 110 | #ifndef QT_NO_ICON
|
|---|
| 111 | case QVariant::Icon:
|
|---|
| 112 | v_construct<QIcon>(x, copy);
|
|---|
| 113 | break;
|
|---|
| 114 | #endif
|
|---|
| 115 | case QVariant::Matrix:
|
|---|
| 116 | v_construct<QMatrix>(x, copy);
|
|---|
| 117 | break;
|
|---|
| 118 | case QVariant::Transform:
|
|---|
| 119 | v_construct<QTransform>(x, copy);
|
|---|
| 120 | break;
|
|---|
| 121 | case QVariant::TextFormat:
|
|---|
| 122 | v_construct<QTextFormat>(x, copy);
|
|---|
| 123 | break;
|
|---|
| 124 | case QVariant::TextLength:
|
|---|
| 125 | v_construct<QTextLength>(x, copy);
|
|---|
| 126 | break;
|
|---|
| 127 | #ifndef QT_NO_SHORTCUT
|
|---|
| 128 | case QVariant::KeySequence:
|
|---|
| 129 | v_construct<QKeySequence>(x, copy);
|
|---|
| 130 | break;
|
|---|
| 131 | #endif
|
|---|
| 132 | case QVariant::Pen:
|
|---|
| 133 | v_construct<QPen>(x, copy);
|
|---|
| 134 | break;
|
|---|
| 135 | case QVariant::SizePolicy:
|
|---|
| 136 | v_construct<QSizePolicy>(x, copy);
|
|---|
| 137 | break;
|
|---|
| 138 | #ifndef QT_NO_CURSOR
|
|---|
| 139 | case QVariant::Cursor:
|
|---|
| 140 | v_construct<QCursor>(x, copy);
|
|---|
| 141 | break;
|
|---|
| 142 | #endif
|
|---|
| 143 | case 62: {
|
|---|
| 144 | // small 'trick' to let a QVariant(Qt::blue) create a variant
|
|---|
| 145 | // of type QColor
|
|---|
| 146 | x->type = QVariant::Color;
|
|---|
| 147 | QColor color(*reinterpret_cast<const Qt::GlobalColor *>(copy));
|
|---|
| 148 | v_construct<QColor>(x, &color);
|
|---|
| 149 | break;
|
|---|
| 150 | }
|
|---|
| 151 | default:
|
|---|
| 152 | qcoreVariantHandler()->construct(x, copy);
|
|---|
| 153 | return;
|
|---|
| 154 | }
|
|---|
| 155 | x->is_null = !copy;
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | static void clear(QVariant::Private *d)
|
|---|
| 159 | {
|
|---|
| 160 | switch (d->type) {
|
|---|
| 161 | case QVariant::Bitmap:
|
|---|
| 162 | v_clear<QBitmap>(d);
|
|---|
| 163 | break;
|
|---|
| 164 | case QVariant::Cursor:
|
|---|
| 165 | v_clear<QCursor>(d);
|
|---|
| 166 | break;
|
|---|
| 167 | case QVariant::Region:
|
|---|
| 168 | v_clear<QRegion>(d);
|
|---|
| 169 | break;
|
|---|
| 170 | case QVariant::Polygon:
|
|---|
| 171 | v_clear<QPolygon>(d);
|
|---|
| 172 | break;
|
|---|
| 173 | case QVariant::Font:
|
|---|
| 174 | v_clear<QFont>(d);
|
|---|
| 175 | break;
|
|---|
| 176 | case QVariant::Pixmap:
|
|---|
| 177 | v_clear<QPixmap>(d);
|
|---|
| 178 | break;
|
|---|
| 179 | case QVariant::Image:
|
|---|
| 180 | v_clear<QImage>(d);
|
|---|
| 181 | break;
|
|---|
| 182 | case QVariant::Brush:
|
|---|
| 183 | v_clear<QBrush>(d);
|
|---|
| 184 | break;
|
|---|
| 185 | case QVariant::Color:
|
|---|
| 186 | v_clear<QColor>(d);
|
|---|
| 187 | break;
|
|---|
| 188 | case QVariant::Palette:
|
|---|
| 189 | v_clear<QPalette>(d);
|
|---|
| 190 | break;
|
|---|
| 191 | #ifdef QT3_SUPPORT
|
|---|
| 192 | case QVariant::ColorGroup:
|
|---|
| 193 | v_clear<QColorGroup>(d);
|
|---|
| 194 | break;
|
|---|
| 195 | #endif
|
|---|
| 196 | #ifndef QT_NO_ICON
|
|---|
| 197 | case QVariant::Icon:
|
|---|
| 198 | v_clear<QIcon>(d);
|
|---|
| 199 | break;
|
|---|
| 200 | #endif
|
|---|
| 201 | case QVariant::Matrix:
|
|---|
| 202 | v_clear<QMatrix>(d);
|
|---|
| 203 | break;
|
|---|
| 204 | case QVariant::Transform:
|
|---|
| 205 | v_clear<QTransform>(d);
|
|---|
| 206 | break;
|
|---|
| 207 | case QVariant::TextFormat:
|
|---|
| 208 | v_clear<QTextFormat>(d);
|
|---|
| 209 | break;
|
|---|
| 210 | case QVariant::TextLength:
|
|---|
| 211 | v_clear<QTextLength>(d);
|
|---|
| 212 | break;
|
|---|
| 213 | case QVariant::SizePolicy:
|
|---|
| 214 | v_clear<QSizePolicy>(d);
|
|---|
| 215 | break;
|
|---|
| 216 | #ifndef QT_NO_SHORTCUT
|
|---|
| 217 | case QVariant::KeySequence:
|
|---|
| 218 | v_clear<QKeySequence>(d);
|
|---|
| 219 | break;
|
|---|
| 220 | #endif
|
|---|
| 221 | case QVariant::Pen:
|
|---|
| 222 | v_clear<QPen>(d);
|
|---|
| 223 | break;
|
|---|
| 224 | default:
|
|---|
| 225 | qcoreVariantHandler()->clear(d);
|
|---|
| 226 | return;
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | d->type = QVariant::Invalid;
|
|---|
| 230 | d->is_null = true;
|
|---|
| 231 | d->is_shared = false;
|
|---|
| 232 | }
|
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 | static bool isNull(const QVariant::Private *d)
|
|---|
| 236 | {
|
|---|
| 237 | switch(d->type) {
|
|---|
| 238 | case QVariant::Bitmap:
|
|---|
| 239 | return v_cast<QBitmap>(d)->isNull();
|
|---|
| 240 | case QVariant::Region:
|
|---|
| 241 | return v_cast<QRegion>(d)->isEmpty();
|
|---|
| 242 | case QVariant::Polygon:
|
|---|
| 243 | return v_cast<QPolygon>(d)->isEmpty();
|
|---|
| 244 | case QVariant::Pixmap:
|
|---|
| 245 | return v_cast<QPixmap>(d)->isNull();
|
|---|
| 246 | case QVariant::Image:
|
|---|
| 247 | return v_cast<QImage>(d)->isNull();
|
|---|
| 248 | #ifndef QT_NO_ICON
|
|---|
| 249 | case QVariant::Icon:
|
|---|
| 250 | return v_cast<QIcon>(d)->isNull();
|
|---|
| 251 | #endif
|
|---|
| 252 | case QVariant::Matrix:
|
|---|
| 253 | case QVariant::TextFormat:
|
|---|
| 254 | case QVariant::TextLength:
|
|---|
| 255 | case QVariant::Cursor:
|
|---|
| 256 | case QVariant::StringList:
|
|---|
| 257 | case QVariant::Font:
|
|---|
| 258 | case QVariant::Brush:
|
|---|
| 259 | case QVariant::Color:
|
|---|
| 260 | case QVariant::Palette:
|
|---|
| 261 | #ifdef QT3_SUPPORT
|
|---|
| 262 | case QVariant::ColorGroup:
|
|---|
| 263 | #endif
|
|---|
| 264 | case QVariant::SizePolicy:
|
|---|
| 265 | #ifndef QT_NO_SHORTCUT
|
|---|
| 266 | case QVariant::KeySequence:
|
|---|
| 267 | #endif
|
|---|
| 268 | case QVariant::Pen:
|
|---|
| 269 | break;
|
|---|
| 270 | default:
|
|---|
| 271 | return qcoreVariantHandler()->isNull(d);
|
|---|
| 272 | }
|
|---|
| 273 | return d->is_null;
|
|---|
| 274 | }
|
|---|
| 275 |
|
|---|
| 276 | static bool compare(const QVariant::Private *a, const QVariant::Private *b)
|
|---|
| 277 | {
|
|---|
| 278 | Q_ASSERT(a->type == b->type);
|
|---|
| 279 | switch(a->type) {
|
|---|
| 280 | case QVariant::Cursor:
|
|---|
| 281 | #ifndef QT_NO_CURSOR
|
|---|
| 282 | return v_cast<QCursor>(a)->shape() == v_cast<QCursor>(b)->shape();
|
|---|
| 283 | #endif
|
|---|
| 284 | case QVariant::Bitmap:
|
|---|
| 285 | return v_cast<QBitmap>(a)->cacheKey()
|
|---|
| 286 | == v_cast<QBitmap>(b)->cacheKey();
|
|---|
| 287 | case QVariant::Polygon:
|
|---|
| 288 | return *v_cast<QPolygon>(a) == *v_cast<QPolygon>(b);
|
|---|
| 289 | case QVariant::Region:
|
|---|
| 290 | return *v_cast<QRegion>(a) == *v_cast<QRegion>(b);
|
|---|
| 291 | case QVariant::Font:
|
|---|
| 292 | return *v_cast<QFont>(a) == *v_cast<QFont>(b);
|
|---|
| 293 | case QVariant::Pixmap:
|
|---|
| 294 | return v_cast<QPixmap>(a)->cacheKey() == v_cast<QPixmap>(b)->cacheKey();
|
|---|
| 295 | case QVariant::Image:
|
|---|
| 296 | return *v_cast<QImage>(a) == *v_cast<QImage>(b);
|
|---|
| 297 | case QVariant::Brush:
|
|---|
| 298 | return *v_cast<QBrush>(a) == *v_cast<QBrush>(b);
|
|---|
| 299 | case QVariant::Color:
|
|---|
| 300 | return *v_cast<QColor>(a) == *v_cast<QColor>(b);
|
|---|
| 301 | case QVariant::Palette:
|
|---|
| 302 | return *v_cast<QPalette>(a) == *v_cast<QPalette>(b);
|
|---|
| 303 | #ifdef QT3_SUPPORT
|
|---|
| 304 | case QVariant::ColorGroup:
|
|---|
| 305 | return *v_cast<QColorGroup>(a) == *v_cast<QColorGroup>(b);
|
|---|
| 306 | #endif
|
|---|
| 307 | #ifndef QT_NO_ICON
|
|---|
| 308 | case QVariant::Icon:
|
|---|
| 309 | /* QIcon::operator==() cannot be reasonably implemented for QIcon,
|
|---|
| 310 | * so we always return false. */
|
|---|
| 311 | return false;
|
|---|
| 312 | #endif
|
|---|
| 313 | case QVariant::Matrix:
|
|---|
| 314 | return *v_cast<QMatrix>(a) == *v_cast<QMatrix>(b);
|
|---|
| 315 | case QVariant::Transform:
|
|---|
| 316 | return *v_cast<QTransform>(a) == *v_cast<QTransform>(b);
|
|---|
| 317 | case QVariant::TextFormat:
|
|---|
| 318 | return *v_cast<QTextFormat>(a) == *v_cast<QTextFormat>(b);
|
|---|
| 319 | case QVariant::TextLength:
|
|---|
| 320 | return *v_cast<QTextLength>(a) == *v_cast<QTextLength>(b);
|
|---|
| 321 | case QVariant::SizePolicy:
|
|---|
| 322 | return *v_cast<QSizePolicy>(a) == *v_cast<QSizePolicy>(b);
|
|---|
| 323 | #ifndef QT_NO_SHORTCUT
|
|---|
| 324 | case QVariant::KeySequence:
|
|---|
| 325 | return *v_cast<QKeySequence>(a) == *v_cast<QKeySequence>(b);
|
|---|
| 326 | #endif
|
|---|
| 327 | case QVariant::Pen:
|
|---|
| 328 | return *v_cast<QPen>(a) == *v_cast<QPen>(b);
|
|---|
| 329 | default:
|
|---|
| 330 | break;
|
|---|
| 331 | }
|
|---|
| 332 | return qcoreVariantHandler()->compare(a, b);
|
|---|
| 333 | }
|
|---|
| 334 |
|
|---|
| 335 |
|
|---|
| 336 |
|
|---|
| 337 | static bool convert(const QVariant::Private *d, QVariant::Type t,
|
|---|
| 338 | void *result, bool *ok)
|
|---|
| 339 | {
|
|---|
| 340 | switch (t) {
|
|---|
| 341 | case QVariant::ByteArray:
|
|---|
| 342 | if (d->type == QVariant::Color) {
|
|---|
| 343 | *static_cast<QByteArray *>(result) = v_cast<QColor>(d)->name().toLatin1();
|
|---|
| 344 | return true;
|
|---|
| 345 | }
|
|---|
| 346 | break;
|
|---|
| 347 | case QVariant::String: {
|
|---|
| 348 | QString *str = static_cast<QString *>(result);
|
|---|
| 349 | switch (d->type) {
|
|---|
| 350 | #ifndef QT_NO_SHORTCUT
|
|---|
| 351 | case QVariant::KeySequence:
|
|---|
| 352 | *str = QString(*v_cast<QKeySequence>(d));
|
|---|
| 353 | return true;
|
|---|
| 354 | #endif
|
|---|
| 355 | case QVariant::Font:
|
|---|
| 356 | *str = v_cast<QFont>(d)->toString();
|
|---|
| 357 | return true;
|
|---|
| 358 | case QVariant::Color:
|
|---|
| 359 | *str = v_cast<QColor>(d)->name();
|
|---|
| 360 | return true;
|
|---|
| 361 | default:
|
|---|
| 362 | break;
|
|---|
| 363 | }
|
|---|
| 364 | break;
|
|---|
| 365 | }
|
|---|
| 366 | case QVariant::Pixmap:
|
|---|
| 367 | if (d->type == QVariant::Image) {
|
|---|
| 368 | *static_cast<QPixmap *>(result) = QPixmap::fromImage(*v_cast<QImage>(d));
|
|---|
| 369 | return true;
|
|---|
| 370 | } else if (d->type == QVariant::Bitmap) {
|
|---|
| 371 | *static_cast<QPixmap *>(result) = *v_cast<QBitmap>(d);
|
|---|
| 372 | return true;
|
|---|
| 373 | } else if (d->type == QVariant::Brush) {
|
|---|
| 374 | if (v_cast<QBrush>(d)->style() == Qt::TexturePattern) {
|
|---|
| 375 | *static_cast<QPixmap *>(result) = v_cast<QBrush>(d)->texture();
|
|---|
| 376 | return true;
|
|---|
| 377 | }
|
|---|
| 378 | }
|
|---|
| 379 | break;
|
|---|
| 380 | case QVariant::Image:
|
|---|
| 381 | if (d->type == QVariant::Pixmap) {
|
|---|
| 382 | *static_cast<QImage *>(result) = v_cast<QPixmap>(d)->toImage();
|
|---|
| 383 | return true;
|
|---|
| 384 | } else if (d->type == QVariant::Bitmap) {
|
|---|
| 385 | *static_cast<QImage *>(result) = v_cast<QBitmap>(d)->toImage();
|
|---|
| 386 | return true;
|
|---|
| 387 | }
|
|---|
| 388 | break;
|
|---|
| 389 | case QVariant::Bitmap:
|
|---|
| 390 | if (d->type == QVariant::Pixmap) {
|
|---|
| 391 | *static_cast<QBitmap *>(result) = *v_cast<QPixmap>(d);
|
|---|
| 392 | return true;
|
|---|
| 393 | } else if (d->type == QVariant::Image) {
|
|---|
| 394 | *static_cast<QBitmap *>(result) = QBitmap::fromImage(*v_cast<QImage>(d));
|
|---|
| 395 | return true;
|
|---|
| 396 | }
|
|---|
| 397 | break;
|
|---|
| 398 | #ifndef QT_NO_SHORTCUT
|
|---|
| 399 | case QVariant::Int:
|
|---|
| 400 | if (d->type == QVariant::KeySequence) {
|
|---|
| 401 | *static_cast<int *>(result) = (int)(*(v_cast<QKeySequence>(d)));
|
|---|
| 402 | return true;
|
|---|
| 403 | }
|
|---|
| 404 | break;
|
|---|
| 405 | #endif
|
|---|
| 406 | case QVariant::Font:
|
|---|
| 407 | if (d->type == QVariant::String) {
|
|---|
| 408 | QFont *f = static_cast<QFont *>(result);
|
|---|
| 409 | f->fromString(*v_cast<QString>(d));
|
|---|
| 410 | return true;
|
|---|
| 411 | }
|
|---|
| 412 | break;
|
|---|
| 413 | case QVariant::Color:
|
|---|
| 414 | if (d->type == QVariant::String) {
|
|---|
| 415 | static_cast<QColor *>(result)->setNamedColor(*v_cast<QString>(d));
|
|---|
| 416 | return static_cast<QColor *>(result)->isValid();
|
|---|
| 417 | } else if (d->type == QVariant::ByteArray) {
|
|---|
| 418 | static_cast<QColor *>(result)->setNamedColor(QString::fromLatin1(
|
|---|
| 419 | *v_cast<QByteArray>(d)));
|
|---|
| 420 | return true;
|
|---|
| 421 | } else if (d->type == QVariant::Brush) {
|
|---|
| 422 | if (v_cast<QBrush>(d)->style() == Qt::SolidPattern) {
|
|---|
| 423 | *static_cast<QColor *>(result) = v_cast<QBrush>(d)->color();
|
|---|
| 424 | return true;
|
|---|
| 425 | }
|
|---|
| 426 | }
|
|---|
| 427 | break;
|
|---|
| 428 | case QVariant::Brush:
|
|---|
| 429 | if (d->type == QVariant::Color) {
|
|---|
| 430 | *static_cast<QBrush *>(result) = QBrush(*v_cast<QColor>(d));
|
|---|
| 431 | return true;
|
|---|
| 432 | } else if (d->type == QVariant::Pixmap) {
|
|---|
| 433 | *static_cast<QBrush *>(result) = QBrush(*v_cast<QPixmap>(d));
|
|---|
| 434 | return true;
|
|---|
| 435 | }
|
|---|
| 436 | break;
|
|---|
| 437 | #ifndef QT_NO_SHORTCUT
|
|---|
| 438 | case QVariant::KeySequence: {
|
|---|
| 439 | QKeySequence *seq = static_cast<QKeySequence *>(result);
|
|---|
| 440 | switch (d->type) {
|
|---|
| 441 | case QVariant::String:
|
|---|
| 442 | *seq = QKeySequence(*v_cast<QString>(d));
|
|---|
| 443 | return true;
|
|---|
| 444 | case QVariant::Int:
|
|---|
| 445 | *seq = QKeySequence(d->data.i);
|
|---|
| 446 | return true;
|
|---|
| 447 | default:
|
|---|
| 448 | break;
|
|---|
| 449 | }
|
|---|
| 450 | }
|
|---|
| 451 | #endif
|
|---|
| 452 | default:
|
|---|
| 453 | break;
|
|---|
| 454 | }
|
|---|
| 455 | return qcoreVariantHandler()->convert(d, t, result, ok);
|
|---|
| 456 | }
|
|---|
| 457 |
|
|---|
| 458 | #if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM)
|
|---|
| 459 | static void streamDebug(QDebug dbg, const QVariant &v)
|
|---|
| 460 | {
|
|---|
| 461 | switch(v.type()) {
|
|---|
| 462 | case QVariant::Cursor:
|
|---|
| 463 | #ifndef QT_NO_CURSOR
|
|---|
| 464 | // dbg.nospace() << qvariant_cast<QCursor>(v); //FIXME
|
|---|
| 465 | #endif
|
|---|
| 466 | break;
|
|---|
| 467 | case QVariant::Bitmap:
|
|---|
| 468 | // dbg.nospace() << qvariant_cast<QBitmap>(v); //FIXME
|
|---|
| 469 | break;
|
|---|
| 470 | case QVariant::Polygon:
|
|---|
| 471 | dbg.nospace() << qvariant_cast<QPolygon>(v);
|
|---|
| 472 | break;
|
|---|
| 473 | case QVariant::Region:
|
|---|
| 474 | dbg.nospace() << qvariant_cast<QRegion>(v);
|
|---|
| 475 | break;
|
|---|
| 476 | case QVariant::Font:
|
|---|
| 477 | // dbg.nospace() << qvariant_cast<QFont>(v); //FIXME
|
|---|
| 478 | break;
|
|---|
| 479 | case QVariant::Matrix:
|
|---|
| 480 | dbg.nospace() << qvariant_cast<QMatrix>(v);
|
|---|
| 481 | break;
|
|---|
| 482 | case QVariant::Transform:
|
|---|
| 483 | dbg.nospace() << qvariant_cast<QTransform>(v);
|
|---|
| 484 | break;
|
|---|
| 485 | case QVariant::Pixmap:
|
|---|
| 486 | // dbg.nospace() << qvariant_cast<QPixmap>(v); //FIXME
|
|---|
| 487 | break;
|
|---|
| 488 | case QVariant::Image:
|
|---|
| 489 | // dbg.nospace() << qvariant_cast<QImage>(v); //FIXME
|
|---|
| 490 | break;
|
|---|
| 491 | case QVariant::Brush:
|
|---|
| 492 | dbg.nospace() << qvariant_cast<QBrush>(v);
|
|---|
| 493 | break;
|
|---|
| 494 | case QVariant::Color:
|
|---|
| 495 | dbg.nospace() << qvariant_cast<QColor>(v);
|
|---|
| 496 | break;
|
|---|
| 497 | case QVariant::Palette:
|
|---|
| 498 | // dbg.nospace() << qvariant_cast<QPalette>(v); //FIXME
|
|---|
| 499 | break;
|
|---|
| 500 | #ifndef QT_NO_ICON
|
|---|
| 501 | case QVariant::Icon:
|
|---|
| 502 | // dbg.nospace() << qvariant_cast<QIcon>(v); // FIXME
|
|---|
| 503 | break;
|
|---|
| 504 | #endif
|
|---|
| 505 | case QVariant::SizePolicy:
|
|---|
| 506 | // dbg.nospace() << qvariant_cast<QSizePolicy>(v); //FIXME
|
|---|
| 507 | break;
|
|---|
| 508 | #ifndef QT_NO_SHORTCUT
|
|---|
| 509 | case QVariant::KeySequence:
|
|---|
| 510 | dbg.nospace() << qvariant_cast<QKeySequence>(v);
|
|---|
| 511 | break;
|
|---|
| 512 | #endif
|
|---|
| 513 | case QVariant::Pen:
|
|---|
| 514 | dbg.nospace() << qvariant_cast<QPen>(v);
|
|---|
| 515 | break;
|
|---|
| 516 | default:
|
|---|
| 517 | qcoreVariantHandler()->debugStream(dbg, v);
|
|---|
| 518 | break;
|
|---|
| 519 | }
|
|---|
| 520 | }
|
|---|
| 521 | #endif
|
|---|
| 522 |
|
|---|
| 523 | const QVariant::Handler qt_gui_variant_handler = {
|
|---|
| 524 | construct,
|
|---|
| 525 | clear,
|
|---|
| 526 | isNull,
|
|---|
| 527 | #ifndef QT_NO_DATASTREAM
|
|---|
| 528 | 0,
|
|---|
| 529 | 0,
|
|---|
| 530 | #endif
|
|---|
| 531 | compare,
|
|---|
| 532 | convert,
|
|---|
| 533 | 0,
|
|---|
| 534 | #if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM)
|
|---|
| 535 | streamDebug
|
|---|
| 536 | #else
|
|---|
| 537 | 0
|
|---|
| 538 | #endif
|
|---|
| 539 | };
|
|---|
| 540 |
|
|---|
| 541 | struct QMetaTypeGuiHelper
|
|---|
| 542 | {
|
|---|
| 543 | QMetaType::Constructor constr;
|
|---|
| 544 | QMetaType::Destructor destr;
|
|---|
| 545 | #ifndef QT_NO_DATASTREAM
|
|---|
| 546 | QMetaType::SaveOperator saveOp;
|
|---|
| 547 | QMetaType::LoadOperator loadOp;
|
|---|
| 548 | #endif
|
|---|
| 549 | };
|
|---|
| 550 |
|
|---|
| 551 | extern Q_CORE_EXPORT const QMetaTypeGuiHelper *qMetaTypeGuiHelper;
|
|---|
| 552 |
|
|---|
| 553 |
|
|---|
| 554 | #ifdef QT_NO_DATASTREAM
|
|---|
| 555 | # define Q_DECL_METATYPE_HELPER(TYPE) \
|
|---|
| 556 | typedef void *(*QConstruct##TYPE)(const TYPE *); \
|
|---|
| 557 | static const QConstruct##TYPE qConstruct##TYPE = qMetaTypeConstructHelper<TYPE>; \
|
|---|
| 558 | typedef void (*QDestruct##TYPE)(TYPE *); \
|
|---|
| 559 | static const QDestruct##TYPE qDestruct##TYPE = qMetaTypeDeleteHelper<TYPE>;
|
|---|
| 560 | #else
|
|---|
| 561 | # define Q_DECL_METATYPE_HELPER(TYPE) \
|
|---|
| 562 | typedef void *(*QConstruct##TYPE)(const TYPE *); \
|
|---|
| 563 | static const QConstruct##TYPE qConstruct##TYPE = qMetaTypeConstructHelper<TYPE>; \
|
|---|
| 564 | typedef void (*QDestruct##TYPE)(TYPE *); \
|
|---|
| 565 | static const QDestruct##TYPE qDestruct##TYPE = qMetaTypeDeleteHelper<TYPE>; \
|
|---|
| 566 | typedef void (*QSave##TYPE)(QDataStream &, const TYPE *); \
|
|---|
| 567 | static const QSave##TYPE qSave##TYPE = qMetaTypeSaveHelper<TYPE>; \
|
|---|
| 568 | typedef void (*QLoad##TYPE)(QDataStream &, TYPE *); \
|
|---|
| 569 | static const QLoad##TYPE qLoad##TYPE = qMetaTypeLoadHelper<TYPE>;
|
|---|
| 570 | #endif
|
|---|
| 571 |
|
|---|
| 572 | #ifdef QT3_SUPPORT
|
|---|
| 573 | Q_DECL_METATYPE_HELPER(QColorGroup)
|
|---|
| 574 | #endif
|
|---|
| 575 | Q_DECL_METATYPE_HELPER(QFont)
|
|---|
| 576 | Q_DECL_METATYPE_HELPER(QPixmap)
|
|---|
| 577 | Q_DECL_METATYPE_HELPER(QBrush)
|
|---|
| 578 | Q_DECL_METATYPE_HELPER(QColor)
|
|---|
| 579 | Q_DECL_METATYPE_HELPER(QPalette)
|
|---|
| 580 | #ifndef QT_NO_ICON
|
|---|
| 581 | Q_DECL_METATYPE_HELPER(QIcon)
|
|---|
| 582 | #endif
|
|---|
| 583 | Q_DECL_METATYPE_HELPER(QImage)
|
|---|
| 584 | Q_DECL_METATYPE_HELPER(QPolygon)
|
|---|
| 585 | Q_DECL_METATYPE_HELPER(QRegion)
|
|---|
| 586 | Q_DECL_METATYPE_HELPER(QBitmap)
|
|---|
| 587 | #ifndef QT_NO_CURSOR
|
|---|
| 588 | Q_DECL_METATYPE_HELPER(QCursor)
|
|---|
| 589 | #endif
|
|---|
| 590 | Q_DECL_METATYPE_HELPER(QSizePolicy)
|
|---|
| 591 | #ifndef QT_NO_SHORTCUT
|
|---|
| 592 | Q_DECL_METATYPE_HELPER(QKeySequence)
|
|---|
| 593 | #endif
|
|---|
| 594 | Q_DECL_METATYPE_HELPER(QPen)
|
|---|
| 595 | Q_DECL_METATYPE_HELPER(QTextLength)
|
|---|
| 596 | Q_DECL_METATYPE_HELPER(QTextFormat)
|
|---|
| 597 | Q_DECL_METATYPE_HELPER(QMatrix)
|
|---|
| 598 | Q_DECL_METATYPE_HELPER(QTransform)
|
|---|
| 599 |
|
|---|
| 600 | #ifdef QT_NO_DATASTREAM
|
|---|
| 601 | # define Q_IMPL_METATYPE_HELPER(TYPE) \
|
|---|
| 602 | { reinterpret_cast<QMetaType::Constructor>(qConstruct##TYPE), \
|
|---|
| 603 | reinterpret_cast<QMetaType::Destructor>(qDestruct##TYPE) }
|
|---|
| 604 | #else
|
|---|
| 605 | # define Q_IMPL_METATYPE_HELPER(TYPE) \
|
|---|
| 606 | { reinterpret_cast<QMetaType::Constructor>(qConstruct##TYPE), \
|
|---|
| 607 | reinterpret_cast<QMetaType::Destructor>(qDestruct##TYPE), \
|
|---|
| 608 | reinterpret_cast<QMetaType::SaveOperator>(qSave##TYPE), \
|
|---|
| 609 | reinterpret_cast<QMetaType::LoadOperator>(qLoad##TYPE) \
|
|---|
| 610 | }
|
|---|
| 611 | #endif
|
|---|
| 612 |
|
|---|
| 613 | static const QMetaTypeGuiHelper qVariantGuiHelper[] = {
|
|---|
| 614 | #ifdef QT3_SUPPORT
|
|---|
| 615 | Q_IMPL_METATYPE_HELPER(QColorGroup),
|
|---|
| 616 | #else
|
|---|
| 617 | {0, 0, 0, 0},
|
|---|
| 618 | #endif
|
|---|
| 619 | Q_IMPL_METATYPE_HELPER(QFont),
|
|---|
| 620 | Q_IMPL_METATYPE_HELPER(QPixmap),
|
|---|
| 621 | Q_IMPL_METATYPE_HELPER(QBrush),
|
|---|
| 622 | Q_IMPL_METATYPE_HELPER(QColor),
|
|---|
| 623 | Q_IMPL_METATYPE_HELPER(QPalette),
|
|---|
| 624 | #ifdef QT_NO_ICON
|
|---|
| 625 | {0, 0, 0, 0},
|
|---|
| 626 | #else
|
|---|
| 627 | Q_IMPL_METATYPE_HELPER(QIcon),
|
|---|
| 628 | #endif
|
|---|
| 629 | Q_IMPL_METATYPE_HELPER(QImage),
|
|---|
| 630 | Q_IMPL_METATYPE_HELPER(QPolygon),
|
|---|
| 631 | Q_IMPL_METATYPE_HELPER(QRegion),
|
|---|
| 632 | Q_IMPL_METATYPE_HELPER(QBitmap),
|
|---|
| 633 | #ifdef QT_NO_CURSOR
|
|---|
| 634 | {0, 0, 0, 0},
|
|---|
| 635 | #else
|
|---|
| 636 | Q_IMPL_METATYPE_HELPER(QCursor),
|
|---|
| 637 | #endif
|
|---|
| 638 | Q_IMPL_METATYPE_HELPER(QSizePolicy),
|
|---|
| 639 | #ifdef QT_NO_SHORTCUT
|
|---|
| 640 | {0, 0, 0, 0},
|
|---|
| 641 | #else
|
|---|
| 642 | Q_IMPL_METATYPE_HELPER(QKeySequence),
|
|---|
| 643 | #endif
|
|---|
| 644 | Q_IMPL_METATYPE_HELPER(QPen),
|
|---|
| 645 | Q_IMPL_METATYPE_HELPER(QTextLength),
|
|---|
| 646 | Q_IMPL_METATYPE_HELPER(QTextFormat),
|
|---|
| 647 | Q_IMPL_METATYPE_HELPER(QMatrix),
|
|---|
| 648 | Q_IMPL_METATYPE_HELPER(QTransform)
|
|---|
| 649 | };
|
|---|
| 650 |
|
|---|
| 651 | static const QVariant::Handler *qt_guivariant_last_handler = 0;
|
|---|
| 652 | int qRegisterGuiVariant()
|
|---|
| 653 | {
|
|---|
| 654 | qt_guivariant_last_handler = QVariant::handler;
|
|---|
| 655 | QVariant::handler = &qt_gui_variant_handler;
|
|---|
| 656 | qMetaTypeGuiHelper = qVariantGuiHelper;
|
|---|
| 657 | return 1;
|
|---|
| 658 | }
|
|---|
| 659 | Q_CONSTRUCTOR_FUNCTION(qRegisterGuiVariant)
|
|---|
| 660 |
|
|---|
| 661 | int qUnregisterGuiVariant()
|
|---|
| 662 | {
|
|---|
| 663 | QVariant::handler = qt_guivariant_last_handler;
|
|---|
| 664 | qMetaTypeGuiHelper = 0;
|
|---|
| 665 | return 1;
|
|---|
| 666 | }
|
|---|
| 667 | Q_DESTRUCTOR_FUNCTION(qUnregisterGuiVariant)
|
|---|
| 668 |
|
|---|
| 669 | QT_END_NAMESPACE
|
|---|