📄 qguivariant.cpp
字号:
/******************************************************************************** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file. Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://www.trolltech.com/products/qt/opensource.html**** If you are unsure which license is appropriate for your use, please** review the following information:** http://www.trolltech.com/products/qt/licensing.html or contact the** sales department at sales@trolltech.com.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qvariant.h"#include "qbitmap.h"#include "qbrush.h"#include "qcolor.h"#include "qcursor.h"#include "qdatastream.h"#include "qdebug.h"#include "qfont.h"#include "qicon.h"#include "qimage.h"#include "qkeysequence.h"#include "qpalette.h"#include "qpen.h"#include "qpixmap.h"#include "qpolygon.h"#include "qregion.h"#include "qsizepolicy.h"#include "qtextformat.h"#include "private/qvariant_p.h"#ifdef QT3_SUPPORTextern QDataStream &qt_stream_out_qcolorgroup(QDataStream &s, const QColorGroup &g);extern QDataStream &qt_stream_in_qcolorgroup(QDataStream &s, QColorGroup &g);#endifQ_CORE_EXPORT const QVariant::Handler *qcoreVariantHandler();static void construct(QVariant::Private *x, const void *copy){ switch (x->type) { case QVariant::Bitmap: v_construct<QBitmap>(x, copy); break; case QVariant::Region: v_construct<QRegion>(x, copy); break; case QVariant::Polygon: v_construct<QPolygon>(x, copy); break; case QVariant::Font: v_construct<QFont>(x, copy); break; case QVariant::Pixmap: v_construct<QPixmap>(x, copy); break; case QVariant::Image: v_construct<QImage>(x, copy); break; case QVariant::Brush: v_construct<QBrush>(x, copy); break; case QVariant::Color: v_construct<QColor>(x, copy); break; case QVariant::Palette: v_construct<QPalette>(x, copy); break;#ifdef QT3_SUPPORT case QVariant::ColorGroup: v_construct<QColorGroup>(x, copy); break;#endif#ifndef QT_NO_ICON case QVariant::Icon: v_construct<QIcon>(x, copy); break;#endif case QVariant::TextFormat: v_construct<QTextFormat>(x, copy); break; case QVariant::TextLength: v_construct<QTextLength>(x, copy); break;#ifndef QT_NO_SHORTCUT case QVariant::KeySequence: v_construct<QKeySequence>(x, copy); break;#endif case QVariant::Pen: v_construct<QPen>(x, copy); break; case QVariant::SizePolicy: v_construct<QSizePolicy>(x, copy); break;#ifndef QT_NO_CURSOR case QVariant::Cursor: v_construct<QCursor>(x, copy); break;#endif default: qcoreVariantHandler()->construct(x, copy); return; } x->is_null = !copy;}static void clear(QVariant::Private *d){ switch (d->type) { case QVariant::Bitmap: v_clear<QBitmap>(d); break; case QVariant::Cursor: v_clear<QCursor>(d); break; case QVariant::Region: v_clear<QRegion>(d); break; case QVariant::Polygon: v_clear<QPolygon>(d); break; case QVariant::Font: v_clear<QFont>(d); break; case QVariant::Pixmap: v_clear<QPixmap>(d); break; case QVariant::Image: v_clear<QImage>(d); break; case QVariant::Brush: v_clear<QBrush>(d); break; case QVariant::Color: v_clear<QColor>(d); break; case QVariant::Palette: v_clear<QPalette>(d); break;#ifdef QT3_SUPPORT case QVariant::ColorGroup: v_clear<QColorGroup>(d); break;#endif#ifndef QT_NO_ICON case QVariant::Icon: v_clear<QIcon>(d); break;#endif case QVariant::TextFormat: v_clear<QTextFormat>(d); break; case QVariant::TextLength: v_clear<QTextLength>(d); break; case QVariant::SizePolicy: v_clear<QSizePolicy>(d); break;#ifndef QT_NO_SHORTCUT case QVariant::KeySequence: v_clear<QKeySequence>(d); break;#endif case QVariant::Pen: v_clear<QPen>(d); break; default: qcoreVariantHandler()->clear(d); return; } d->type = QVariant::Invalid; d->is_null = true; d->is_shared = false;}static bool isNull(const QVariant::Private *d){ switch(d->type) { case QVariant::Bitmap: return v_cast<QBitmap>(d)->isNull(); case QVariant::Region: return v_cast<QRegion>(d)->isEmpty(); case QVariant::Polygon: return v_cast<QPolygon>(d)->isEmpty(); case QVariant::Pixmap: return v_cast<QPixmap>(d)->isNull(); case QVariant::Image: return v_cast<QImage>(d)->isNull();#ifndef QT_NO_ICON case QVariant::Icon: return v_cast<QIcon>(d)->isNull();#endif case QVariant::TextFormat: case QVariant::TextLength: case QVariant::Cursor: case QVariant::StringList: case QVariant::Font: case QVariant::Brush: case QVariant::Color: case QVariant::Palette:#ifdef QT3_SUPPORT case QVariant::ColorGroup:#endif case QVariant::SizePolicy:#ifndef QT_NO_SHORTCUT case QVariant::KeySequence:#endif case QVariant::Pen: break; default: return qcoreVariantHandler()->isNull(d); } return d->is_null;}#ifndef QT_NO_DATASTREAMstatic void load(QVariant::Private *d, QDataStream &s){ switch (d->type) {#ifndef QT_NO_CURSOR case QVariant::Cursor: s >> *v_cast<QCursor>(d); break;#endif case QVariant::Bitmap: s >> *v_cast<QBitmap>(d); break; case QVariant::Region: s >> *v_cast<QRegion>(d); break; case QVariant::Polygon: s >> *v_cast<QPolygon>(d); break; case QVariant::Font: s >> *v_cast<QFont>(d); break; case QVariant::Pixmap: s >> *v_cast<QPixmap>(d); break; case QVariant::Image: s >> *v_cast<QImage>(d); break; case QVariant::Brush: s >> *v_cast<QBrush>(d); break; case QVariant::Color: s >> *v_cast<QColor>(d); break; case QVariant::Palette: s >> *v_cast<QPalette>(d); break;#ifdef QT3_SUPPORT case QVariant::ColorGroup: qt_stream_in_qcolorgroup(s, *v_cast<QColorGroup>(d)); break;#endif#ifndef QT_NO_ICON case QVariant::Icon: { QPixmap x; s >> x; *v_cast<QIcon>(d) = QIcon(x); break; }#endif case QVariant::TextFormat: { QTextFormat x; s >> x; *v_cast<QTextFormat>(d) = x; break; } case QVariant::TextLength: { QTextLength x; s >> x; *v_cast<QTextLength>(d) = x; break; } case QVariant::SizePolicy: { int h, v; qint8 hfw; s >> h >> v >> hfw; QSizePolicy *sp = v_cast<QSizePolicy>(d); *sp = QSizePolicy(QSizePolicy::Policy(h), QSizePolicy::Policy(v)); sp->setHeightForWidth(bool(hfw)); break; }#ifndef QT_NO_SHORTCUT case QVariant::KeySequence: s >> *v_cast<QKeySequence>(d); break;#endif // QT_NO_SHORTCUT case QVariant::Pen: s >> *v_cast<QPen>(d); break; default: qcoreVariantHandler()->load(d, s); return; }}static void save(const QVariant::Private *d, QDataStream &s){ switch (d->type) {#ifndef QT_NO_CURSOR case QVariant::Cursor: s << *v_cast<QCursor>(d); break;#endif case QVariant::Bitmap: s << *v_cast<QBitmap>(d); break; case QVariant::Polygon: s << *v_cast<QPolygon>(d); break; case QVariant::Region: s << *v_cast<QRegion>(d); break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -