diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-08-12 18:31:45 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-08-12 18:31:45 +0000 |
commit | 52f8a1d18175ad99fbc01d2d9b7b9e822573cac3 (patch) | |
tree | b5ca23487a951381de58cfc28fb3cde9d6052d8d /qtinterface/tqvariant.cpp | |
parent | 8385c1bc03d09c43de703fcf50d8f607f3250cfa (diff) | |
download | tqtinterface-52f8a1d18175ad99fbc01d2d9b7b9e822573cac3.tar.gz tqtinterface-52f8a1d18175ad99fbc01d2d9b7b9e822573cac3.zip |
Qt3 compilation fix
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/dependencies/tqtinterface@1162810 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'qtinterface/tqvariant.cpp')
-rw-r--r-- | qtinterface/tqvariant.cpp | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/qtinterface/tqvariant.cpp b/qtinterface/tqvariant.cpp index 3672da7..981922e 100644 --- a/qtinterface/tqvariant.cpp +++ b/qtinterface/tqvariant.cpp @@ -21,3 +21,109 @@ Boston, MA 02110-1301, USA. #include <tqt.h> #include <tqvariant.h> + +#include <Qt/qbitmap.h> + +#ifdef USE_QT4 + +// This is taken straight from <private/qvariant_p.h> +#ifdef Q_CC_SUN // Sun CC picks the wrong overload, so introduce awful hack + +template <typename T> +inline T *v_cast(const QVariant::Private *nd, T * = 0) +{ + QVariant::Private *d = const_cast<QVariant::Private *>(nd); + return ((sizeof(T) > sizeof(QVariant::Private::Data)) + ? static_cast<T *>(d->data.shared->ptr) + : static_cast<T *>(static_cast<void *>(&d->data.c))); +} + +#else // every other compiler in this world + +template <typename T> +inline const T *v_cast(const QVariant::Private *d, T * = 0) +{ + return ((sizeof(T) > sizeof(QVariant::Private::Data)) + ? static_cast<const T *>(d->data.shared->ptr) + : static_cast<const T *>(static_cast<const void *>(&d->data.c))); +} + +template <typename T> +inline T *v_cast(QVariant::Private *d, T * = 0) +{ + return ((sizeof(T) > sizeof(QVariant::Private::Data)) + ? static_cast<T *>(d->data.shared->ptr) + : static_cast<T *>(static_cast<void *>(&d->data.c))); +} + +#endif + +template <typename T> +inline T qVariantToHelper(const QVariant::Private &d, QVariant::Type t, + const QVariant::Handler *handler, T * = 0) +{ + if (d.type == t) + return *v_cast<T>(&d); + + T ret; + handler->convert(&d, t, &ret, 0); + return ret; +} + +QFont QVariant::toFont() const { + return qVariantToHelper<QFont>(d, Font, handler); +} + +QColor QVariant::toColor() const { + return qVariantToHelper<QColor>(d, Color, handler); +} + +QCursor QVariant::toCursor() const { + return qVariantToHelper<QCursor>(d, Cursor, handler); +} + +QBitmap QVariant::toBitmap() const { + return qVariantToHelper<QBitmap>(d, Bitmap, handler); +} + +Q3PointArray QVariant::toPointArray() const { + return qVariantToHelper<Q3PointArray>(d, PointArray, handler); +} + +QRegion QVariant::toRegion() const { + return qVariantToHelper<QRegion>(d, Region, handler); +} + +QPixmap QVariant::toPixmap() const { + return qVariantToHelper<QPixmap>(d, Pixmap, handler); +} + +QImage QVariant::toImage() const { + return qVariantToHelper<QImage>(d, Image, handler); +} + +QBrush QVariant::toBrush() const { + return qVariantToHelper<QBrush>(d, Brush, handler); +} + +QPalette QVariant::toPalette() const { + return qVariantToHelper<QPalette>(d, Palette, handler); +} + +QColorGroup QVariant::toColorGroup() const { + return qVariantToHelper<QColorGroup>(d, ColorGroup, handler); +} + +QIconSet QVariant::toIconSet() const { + return qVariantToHelper<QIconSet>(d, IconSet, handler); +} + +QFont QVariant::asFont() { + return toFont(); +} + +QColor QVariant::asColor() { + return toColor(); +} + +#endif // USE_QT4
\ No newline at end of file |