From 27917305452f2a55ae3be74e83b8a724248ec43f Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Thu, 26 Jan 2012 20:43:47 -0600 Subject: Split out qt3 and tqt3 files --- qtinterface/interface_tqt3/tqvariant.cpp | 129 +++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 qtinterface/interface_tqt3/tqvariant.cpp (limited to 'qtinterface/interface_tqt3/tqvariant.cpp') diff --git a/qtinterface/interface_tqt3/tqvariant.cpp b/qtinterface/interface_tqt3/tqvariant.cpp new file mode 100644 index 0000000..5a59993 --- /dev/null +++ b/qtinterface/interface_tqt3/tqvariant.cpp @@ -0,0 +1,129 @@ +/* + +Copyright (C) 2010 Timothy Pearson + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public License +along with this library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +Boston, MA 02110-1301, USA. + +*/ + +#include +#include + +#ifdef USE_QT4 + +#include + +// This is taken straight from +#ifdef Q_CC_SUN // Sun CC picks the wrong overload, so introduce awful hack + +template +inline T *v_cast(const QVariant::Private *nd, T * = 0) +{ + QVariant::Private *d = const_cast(nd); + return ((sizeof(T) > sizeof(QVariant::Private::Data)) + ? static_cast(d->data.shared->ptr) + : static_cast(static_cast(&d->data.c))); +} + +#else // every other compiler in this world + +template +inline const T *v_cast(const QVariant::Private *d, T * = 0) +{ + return ((sizeof(T) > sizeof(QVariant::Private::Data)) + ? static_cast(d->data.shared->ptr) + : static_cast(static_cast(&d->data.c))); +} + +template +inline T *v_cast(QVariant::Private *d, T * = 0) +{ + return ((sizeof(T) > sizeof(QVariant::Private::Data)) + ? static_cast(d->data.shared->ptr) + : static_cast(static_cast(&d->data.c))); +} + +#endif + +template +inline T qVariantToHelper(const QVariant::Private &d, QVariant::Type t, + const QVariant::Handler *handler, T * = 0) +{ + if (d.type == t) + return *v_cast(&d); + + T ret; + handler->convert(&d, t, &ret, 0); + return ret; +} + +QFont QVariant::toFont() const { + return qVariantToHelper(d, Font, handler); +} + +QColor QVariant::toColor() const { + return qVariantToHelper(d, Color, handler); +} + +QCursor QVariant::toCursor() const { + return qVariantToHelper(d, Cursor, handler); +} + +QBitmap QVariant::toBitmap() const { + return qVariantToHelper(d, Bitmap, handler); +} + +Q3PointArray QVariant::toPointArray() const { + return qVariantToHelper(d, PointArray, handler); +} + +QRegion QVariant::toRegion() const { + return qVariantToHelper(d, Region, handler); +} + +QPixmap QVariant::toPixmap() const { + return qVariantToHelper(d, Pixmap, handler); +} + +QImage QVariant::toImage() const { + return qVariantToHelper(d, Image, handler); +} + +QBrush QVariant::toBrush() const { + return qVariantToHelper(d, Brush, handler); +} + +QPalette QVariant::toPalette() const { + return qVariantToHelper(d, Palette, handler); +} + +QColorGroup QVariant::toColorGroup() const { + return qVariantToHelper(d, ColorGroup, handler); +} + +QIconSet QVariant::toIconSet() const { + return qVariantToHelper(d, IconSet, handler); +} + +QFont QVariant::asFont() { + return toFont(); +} + +QColor QVariant::asColor() { + return toColor(); +} + +#endif // USE_QT4 -- cgit v1.2.3