diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2009-04-29 04:33:52 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2009-04-29 04:33:52 (GMT) |
commit | e79ce618a079c7f1664959da5d9d13b5f4e1d370 (patch) | |
tree | dabf9efe361c27cec4377de04e1a24ae3eca03fb /src/corelib | |
parent | f49f040660fd004ea6289cdc3a92a7ad42338237 (diff) | |
parent | 9ba03ca32ae12f8b135f3b4f80c445edc3e6b55e (diff) | |
download | Qt-e79ce618a079c7f1664959da5d9d13b5f4e1d370.zip Qt-e79ce618a079c7f1664959da5d9d13b5f4e1d370.tar.gz Qt-e79ce618a079c7f1664959da5d9d13b5f4e1d370.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/animation/qanimationgroup.cpp | 2 | ||||
-rw-r--r-- | src/corelib/codecs/qtsciicodec.cpp | 3 | ||||
-rw-r--r-- | src/corelib/codecs/qutfcodec.cpp | 4 | ||||
-rw-r--r-- | src/corelib/global/qfeatures.h | 22 | ||||
-rw-r--r-- | src/corelib/kernel/qcoreapplication.cpp | 15 | ||||
-rw-r--r-- | src/corelib/kernel/qcoreevent.cpp | 1 | ||||
-rw-r--r-- | src/corelib/kernel/qeventdispatcher_glib.cpp | 3 | ||||
-rw-r--r-- | src/corelib/kernel/qeventloop.cpp | 5 | ||||
-rw-r--r-- | src/corelib/kernel/qvariant.cpp | 158 | ||||
-rw-r--r-- | src/corelib/kernel/qvariant.h | 17 | ||||
-rw-r--r-- | src/corelib/kernel/qvariant_p.h | 43 | ||||
-rw-r--r-- | src/corelib/thread/qthread_unix.cpp | 3 | ||||
-rw-r--r-- | src/corelib/thread/qthread_win.cpp | 3 | ||||
-rw-r--r-- | src/corelib/tools/qbytearraymatcher.cpp | 3 | ||||
-rw-r--r-- | src/corelib/tools/qbytearraymatcher.h | 7 |
15 files changed, 155 insertions, 134 deletions
diff --git a/src/corelib/animation/qanimationgroup.cpp b/src/corelib/animation/qanimationgroup.cpp index 03573bb..c4066ce 100644 --- a/src/corelib/animation/qanimationgroup.cpp +++ b/src/corelib/animation/qanimationgroup.cpp @@ -41,7 +41,7 @@ /*! \class QAnimationGroup - \brief The QAnimationGroup is an abstract base class for group of animations. + \brief The QAnimationGroup class is an abstract base class for group of animations. \since 4.5 \ingroup animation \preliminary diff --git a/src/corelib/codecs/qtsciicodec.cpp b/src/corelib/codecs/qtsciicodec.cpp index 14d2c9c..0ec0567 100644 --- a/src/corelib/codecs/qtsciicodec.cpp +++ b/src/corelib/codecs/qtsciicodec.cpp @@ -180,8 +180,7 @@ QByteArray QTsciiCodec::name() const */ int QTsciiCodec::mibEnum() const { - /* There is no MIBEnum for TSCII now */ - return -3197; + return 2107; } static const int UnToTsLast = 124; // 125 items -- so the last will be 124 diff --git a/src/corelib/codecs/qutfcodec.cpp b/src/corelib/codecs/qutfcodec.cpp index 281bf75..1ac592e 100644 --- a/src/corelib/codecs/qutfcodec.cpp +++ b/src/corelib/codecs/qutfcodec.cpp @@ -413,9 +413,7 @@ QByteArray QUtf16Codec::name() const QList<QByteArray> QUtf16Codec::aliases() const { - QList<QByteArray> list; - list << "ISO-10646-UCS-2"; - return list; + return QList<QByteArray>(); } int QUtf16BECodec::mibEnum() const diff --git a/src/corelib/global/qfeatures.h b/src/corelib/global/qfeatures.h index c172f5f..f11c9df 100644 --- a/src/corelib/global/qfeatures.h +++ b/src/corelib/global/qfeatures.h @@ -386,11 +386,6 @@ #define QT_NO_PHONON_VOLUMESLIDER #endif -// QPrinter -#if !defined(QT_NO_PRINTER) && (defined(QT_NO_TEXTSTREAM)) -#define QT_NO_PRINTER -#endif - // QProcess #if !defined(QT_NO_PROCESS) && (defined(QT_NO_THREAD)) #define QT_NO_PROCESS @@ -516,6 +511,11 @@ #define QT_NO_LIBRARY #endif +// QPrinter +#if !defined(QT_NO_PRINTER) && (defined(QT_NO_TEXTSTREAM) || defined(QT_NO_PICTURE)) +#define QT_NO_PRINTER +#endif + // QScrollArea #if !defined(QT_NO_SCROLLAREA) && (defined(QT_NO_SCROLLBAR)) #define QT_NO_SCROLLAREA @@ -646,11 +646,6 @@ #define QT_NO_WHATSTHIS #endif -// Common UNIX Printing System -#if !defined(QT_NO_CUPS) && (defined(QT_NO_PRINTER) || defined(QT_NO_LIBRARY)) -#define QT_NO_CUPS -#endif - // QDirModel #if !defined(QT_NO_DIRMODEL) && (defined(QT_NO_ITEMVIEWS)) #define QT_NO_DIRMODEL @@ -731,6 +726,11 @@ #define QT_NO_COMPLETER #endif +// Common UNIX Printing System +#if !defined(QT_NO_CUPS) && (defined(QT_NO_PRINTER) || defined(QT_NO_LIBRARY)) +#define QT_NO_CUPS +#endif + // QDataWidgetMapper #if !defined(QT_NO_DATAWIDGETMAPPER) && (defined(QT_NO_ITEMVIEWS) || defined(QT_NO_PROPERTIES)) #define QT_NO_DATAWIDGETMAPPER @@ -762,7 +762,7 @@ #endif // QPrintPreviewWidget -#if !defined(QT_NO_PRINTPREVIEWWIDGET) && (defined(QT_NO_GRAPHICSVIEW) || defined(QT_NO_PRINTER) || defined(QT_NO_PICTURE)) +#if !defined(QT_NO_PRINTPREVIEWWIDGET) && (defined(QT_NO_GRAPHICSVIEW) || defined(QT_NO_PRINTER)) #define QT_NO_PRINTPREVIEWWIDGET #endif diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index a23b2dd..e4bd664 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -377,12 +377,12 @@ QString qAppName() QLibrary) can be retrieved with libraryPaths() and manipulated by setLibraryPaths(), addLibraryPath(), and removeLibraryPath(). - On Unix/Linux Qt is configured to use the system local settings by - default. This can cause a conflict when using POSIX functions, for - instance, when converting between data types such as floats and - strings, since the notation may differ between locales. To get - around this problem call the POSIX function setlocale(LC_NUMERIC,"C") - right after initializing QApplication or QCoreApplication to reset + On Unix/Linux Qt is configured to use the system local settings by + default. This can cause a conflict when using POSIX functions, for + instance, when converting between data types such as floats and + strings, since the notation may differ between locales. To get + around this problem call the POSIX function setlocale(LC_NUMERIC,"C") + right after initializing QApplication or QCoreApplication to reset the locale that is used for number formatting to "C"-locale. \sa QApplication, QAbstractEventDispatcher, QEventLoop, @@ -1908,8 +1908,7 @@ QStringList QCoreApplication::arguments() l1arg == "-qdebug" || l1arg == "-reverse" || l1arg == "-stylesheet" || - l1arg == "-widgetcount" || - l1arg == "-direct3d") + l1arg == "-widgetcount") ; else if (l1arg.startsWith("-style=")) ; diff --git a/src/corelib/kernel/qcoreevent.cpp b/src/corelib/kernel/qcoreevent.cpp index fc1cefb..4b4dfe5 100644 --- a/src/corelib/kernel/qcoreevent.cpp +++ b/src/corelib/kernel/qcoreevent.cpp @@ -260,6 +260,7 @@ QT_BEGIN_NAMESPACE \omitvalue ApplicationActivated \omitvalue ApplicationDeactivated \omitvalue MacGLWindowChange + \omitvalue MacGLClearDrawable \omitvalue NetworkReplyUpdated \omitvalue FutureCallOut \omitvalue CocoaRequestModal diff --git a/src/corelib/kernel/qeventdispatcher_glib.cpp b/src/corelib/kernel/qeventdispatcher_glib.cpp index 3fd768a..3c5b277 100644 --- a/src/corelib/kernel/qeventdispatcher_glib.cpp +++ b/src/corelib/kernel/qeventdispatcher_glib.cpp @@ -42,6 +42,7 @@ #include "qeventdispatcher_glib_p.h" #include "qeventdispatcher_unix_p.h" +#include <private/qmutexpool_p.h> #include <private/qthread_p.h> #include "qcoreapplication.h" @@ -224,6 +225,8 @@ QEventDispatcherGlibPrivate::QEventDispatcherGlibPrivate(GMainContext *context) : mainContext(context) { if (qgetenv("QT_NO_THREADED_GLIB").isEmpty()) { + static int dummyValue = 0; // only used for its address + QMutexLocker locker(QMutexPool::instance()->get(&dummyValue)); if (!g_thread_supported()) g_thread_init(NULL); } diff --git a/src/corelib/kernel/qeventloop.cpp b/src/corelib/kernel/qeventloop.cpp index 92bdf73..600f787 100644 --- a/src/corelib/kernel/qeventloop.cpp +++ b/src/corelib/kernel/qeventloop.cpp @@ -188,8 +188,9 @@ int QEventLoop::exec(ProcessEventsFlags flags) d->threadData->eventLoops.push(this); // remove posted quit events when entering a new event loop - if (qApp->thread() == thread()) - QCoreApplication::removePostedEvents(qApp, QEvent::Quit); + QCoreApplication *app = QCoreApplication::instance(); + if (app && app->thread() == thread()) + QCoreApplication::removePostedEvents(app, QEvent::Quit); #if defined(QT_NO_EXCEPTIONS) while (!d->exit) diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index b4427c0..b53e91f 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -71,27 +71,6 @@ QT_BEGIN_NAMESPACE # define FLT_DIG 6 #endif - -static const void *constDataHelper(const QVariant::Private &d) -{ - switch (d.type) { - case QVariant::Int: - return &d.data.i; - case QVariant::UInt: - return &d.data.u; - case QVariant::Bool: - return &d.data.b; - case QVariant::LongLong: - return &d.data.ll; - case QVariant::ULongLong: - return &d.data.ull; - case QVariant::Double: - return &d.data.d; - default: - return d.is_shared ? d.data.shared->ptr : reinterpret_cast<const void *>(&d.data.ptr); - } -} - static void construct(QVariant::Private *x, const void *copy) { x->is_shared = false; @@ -179,6 +158,9 @@ static void construct(QVariant::Private *x, const void *copy) case QVariant::Double: x->data.d = copy ? *static_cast<const double*>(copy) : 0.0; break; + case QMetaType::Float: + x->data.f = copy ? *static_cast<const float*>(copy) : 0.0f; + break; case QVariant::LongLong: x->data.ll = copy ? *static_cast<const qlonglong *>(copy) : Q_INT64_C(0); break; @@ -274,6 +256,7 @@ static void clear(QVariant::Private *d) case QVariant::LongLong: case QVariant::ULongLong: case QVariant::Double: + case QMetaType::Float: break; case QVariant::Invalid: case QVariant::UserType: @@ -342,6 +325,7 @@ static bool isNull(const QVariant::Private *d) case QVariant::ULongLong: case QVariant::Bool: case QVariant::Double: + case QMetaType::Float: break; } return d->is_null; @@ -433,6 +417,8 @@ static bool compare(const QVariant::Private *a, const QVariant::Private *b) return a->data.b == b->data.b; case QVariant::Double: return a->data.d == b->data.d; + case QMetaType::Float: + return a->data.f == b->data.f; case QVariant::Date: return *v_cast<QDate>(a) == *v_cast<QDate>(b); case QVariant::Time: @@ -491,7 +477,7 @@ static qlonglong qMetaTypeNumber(const QVariant::Private *d) case QMetaType::Long: return qlonglong(*static_cast<long *>(d->data.shared->ptr)); case QMetaType::Float: - return qRound64(*static_cast<float *>(d->data.shared->ptr)); + return qRound64(d->data.f); case QVariant::Double: return qRound64(d->data.d); } @@ -628,7 +614,7 @@ static bool convert(const QVariant::Private *d, QVariant::Type t, void *result, *str = QString::number(qMetaTypeUNumber(d)); break; case QMetaType::Float: - *str = QString::number(*static_cast<float *>(d->data.shared->ptr), 'g', FLT_DIG); + *str = QString::number(d->data.f, 'g', FLT_DIG); break; case QVariant::Double: *str = QString::number(d->data.d, 'g', DBL_DIG); @@ -799,7 +785,7 @@ static bool convert(const QVariant::Private *d, QVariant::Type t, void *result, *ba = QByteArray::number(d->data.d, 'g', DBL_DIG); break; case QMetaType::Float: - *ba = QByteArray::number(*static_cast<float *>(d->data.shared->ptr), 'g', FLT_DIG); + *ba = QByteArray::number(d->data.f, 'g', FLT_DIG); break; case QMetaType::Char: case QMetaType::UChar: @@ -901,7 +887,7 @@ static bool convert(const QVariant::Private *d, QVariant::Type t, void *result, *f = double(d->data.b); break; case QMetaType::Float: - *f = *static_cast<float *>(d->data.shared->ptr); + *f = double(d->data.f); break; case QVariant::LongLong: case QVariant::Int: @@ -1355,7 +1341,7 @@ void QVariant::create(int type, const void *copy) QVariant::~QVariant() { - if (d.type > Char && (!d.is_shared || !d.data.shared->ref.deref())) + if (d.type > Char && d.type != QMetaType::Float && (!d.is_shared || !d.data.shared->ref.deref())) handler->clear(&d); } @@ -1371,7 +1357,7 @@ QVariant::QVariant(const QVariant &p) { if (d.is_shared) { d.data.shared->ref.ref(); - } else if (p.d.type > Char) { + } else if (p.d.type > Char && p.d.type != QMetaType::Float) { handler->construct(&d, p.constData()); d.is_null = p.d.is_null; } @@ -1565,6 +1551,12 @@ QVariant::QVariant(const char *val) */ /*! + \fn QVariant::QVariant(float val) + + Constructs a new variant with a floating point value, \a val. +*/ + +/*! \fn QVariant::QVariant(const QList<QVariant> &val) Constructs a new variant with a list value, \a val. @@ -1619,44 +1611,44 @@ QVariant::QVariant(double val) { d.is_null = false; d.type = Double; d.data.d = val; } QVariant::QVariant(const QByteArray &val) -{ create(ByteArray, &val); } +{ d.is_null = false; d.type = ByteArray; v_construct<QByteArray>(&d, val); } QVariant::QVariant(const QBitArray &val) -{ create(BitArray, &val); } +{ d.is_null = false; d.type = BitArray; v_construct<QBitArray>(&d, val); } QVariant::QVariant(const QString &val) -{ create(String, &val); } +{ d.is_null = false; d.type = String; v_construct<QString>(&d, val); } QVariant::QVariant(const QChar &val) -{ create (Char, &val); } +{ d.is_null = false; d.type = Char; v_construct<QChar>(&d, val); } QVariant::QVariant(const QLatin1String &val) -{ QString str(val); create(String, &str); } +{ QString str(val); d.is_null = false; d.type = String; v_construct<QString>(&d, str); } QVariant::QVariant(const QStringList &val) -{ create(StringList, &val); } +{ d.is_null = false; d.type = StringList; v_construct<QStringList>(&d, val); } QVariant::QVariant(const QDate &val) -{ create(Date, &val); } +{ d.is_null = false; d.type = Date; v_construct<QDate>(&d, val); } QVariant::QVariant(const QTime &val) -{ create(Time, &val); } +{ d.is_null = false; d.type = Time; v_construct<QTime>(&d, val); } QVariant::QVariant(const QDateTime &val) -{ create(DateTime, &val); } +{ d.is_null = false; d.type = DateTime; v_construct<QDateTime>(&d, val); } QVariant::QVariant(const QList<QVariant> &list) -{ create(List, &list); } +{ d.is_null = false; d.type = List; v_construct<QVariantList>(&d, list); } QVariant::QVariant(const QMap<QString, QVariant> &map) -{ create(Map, &map); } +{ d.is_null = false; d.type = Map; v_construct<QVariantMap>(&d, map); } QVariant::QVariant(const QHash<QString, QVariant> &hash) -{ create(Hash, &hash); } +{ d.is_null = false; d.type = Hash; v_construct<QVariantHash>(&d, hash); } #ifndef QT_NO_GEOM_VARIANT -QVariant::QVariant(const QPoint &pt) { create(Point, &pt); } -QVariant::QVariant(const QPointF &pt) { create (PointF, &pt); } -QVariant::QVariant(const QRectF &r) { create (RectF, &r); } -QVariant::QVariant(const QLineF &l) { create (LineF, &l); } -QVariant::QVariant(const QLine &l) { create (Line, &l); } -QVariant::QVariant(const QRect &r) { create(Rect, &r); } -QVariant::QVariant(const QSize &s) { create(Size, &s); } -QVariant::QVariant(const QSizeF &s) { create(SizeF, &s); } +QVariant::QVariant(const QPoint &pt) { d.is_null = false; d.type = Point; v_construct<QPoint>(&d, pt); } +QVariant::QVariant(const QPointF &pt) { d.is_null = false; d.type = PointF; v_construct<QPointF>(&d, pt); } +QVariant::QVariant(const QRectF &r) { d.is_null = false; d.type = RectF; v_construct<QRectF>(&d, r); } +QVariant::QVariant(const QLineF &l) { d.is_null = false; d.type = LineF; v_construct<QLineF>(&d, l); } +QVariant::QVariant(const QLine &l) { d.is_null = false; d.type = Line; v_construct<QLine>(&d, l); } +QVariant::QVariant(const QRect &r) { d.is_null = false; d.type = Rect; v_construct<QRect>(&d, r); } +QVariant::QVariant(const QSize &s) { d.is_null = false; d.type = Size; v_construct<QSize>(&d, s); } +QVariant::QVariant(const QSizeF &s) { d.is_null = false; d.type = SizeF; v_construct<QSizeF>(&d, s); } #endif -QVariant::QVariant(const QUrl &u) { create(Url, &u); } -QVariant::QVariant(const QLocale &l) { create(Locale, &l); } +QVariant::QVariant(const QUrl &u) { d.is_null = false; d.type = Url; v_construct<QUrl>(&d, u); } +QVariant::QVariant(const QLocale &l) { d.is_null = false; d.type = Locale; v_construct<QLocale>(&d, l); } #ifndef QT_NO_REGEXP -QVariant::QVariant(const QRegExp ®Exp) { create(RegExp, ®Exp); } +QVariant::QVariant(const QRegExp ®Exp) { d.is_null = false; d.type = RegExp; v_construct<QRegExp>(&d, regExp); } #endif QVariant::QVariant(Qt::GlobalColor color) { create(62, &color); } @@ -1721,7 +1713,7 @@ QVariant& QVariant::operator=(const QVariant &variant) if (variant.d.is_shared) { variant.d.data.shared->ref.ref(); d = variant.d; - } else if (variant.d.type > Char) { + } else if (variant.d.type > Char && variant.d.type != QMetaType::Float) { d.type = variant.d.type; handler->construct(&d, variant.constData()); d.is_null = variant.d.is_null; @@ -1907,7 +1899,7 @@ void QVariant::load(QDataStream &s) } // const cast is safe since we operate on a newly constructed variant - if (!QMetaType::load(s, d.type, const_cast<void *>(constDataHelper(d)))) { + if (!QMetaType::load(s, d.type, const_cast<void *>(constData()))) { s.setStatus(QDataStream::ReadCorruptData); qWarning("QVariant::load: unable to load type %d.", d.type); } @@ -1947,7 +1939,7 @@ void QVariant::save(QDataStream &s) const return; } - if (!QMetaType::save(s, d.type, constDataHelper(d))) { + if (!QMetaType::save(s, d.type, constData())) { Q_ASSERT_X(false, "QVariant::save", "Invalid type to save"); qWarning("QVariant::save: unable to save type %d.", d.type); } @@ -2565,57 +2557,63 @@ static const quint32 qCanConvertMatrix[QVariant::LastCoreType + 1] = */ bool QVariant::canConvert(Type t) const { - if (d.type == uint(t)) + //we can treat floats as double + //the reason for not doing it the "proper" way is that QMetaType::Float's value is 135, + //which can't be handled by qCanConvertMatrix + //In addition QVariant::Type doesn't have a Float value, so we're using QMetaType::Float + const uint currentType = ((d.type == QMetaType::Float) ? QVariant::Double : d.type); + if (uint(t) == uint(QMetaType::Float)) t = QVariant::Double; + + if (currentType == uint(t)) return true; - if (d.type > QVariant::LastCoreType || t > QVariant::LastCoreType) { + if (currentType > QVariant::LastCoreType || t > QVariant::LastCoreType) { switch (uint(t)) { case QVariant::Int: - return d.type == QVariant::KeySequence - || d.type == QMetaType::ULong - || d.type == QMetaType::Long - || d.type == QMetaType::UShort - || d.type == QMetaType::UChar - || d.type == QMetaType::Char - || d.type == QMetaType::Short; + return currentType == QVariant::KeySequence + || currentType == QMetaType::ULong + || currentType == QMetaType::Long + || currentType == QMetaType::UShort + || currentType == QMetaType::UChar + || currentType == QMetaType::Char + || currentType == QMetaType::Short; case QVariant::Image: - return d.type == QVariant::Pixmap || d.type == QVariant::Bitmap; + return currentType == QVariant::Pixmap || currentType == QVariant::Bitmap; case QVariant::Pixmap: - return d.type == QVariant::Image || d.type == QVariant::Bitmap - || d.type == QVariant::Brush; + return currentType == QVariant::Image || currentType == QVariant::Bitmap + || currentType == QVariant::Brush; case QVariant::Bitmap: - return d.type == QVariant::Pixmap || d.type == QVariant::Image; + return currentType == QVariant::Pixmap || currentType == QVariant::Image; case QVariant::ByteArray: - return d.type == QVariant::Color; + return currentType == QVariant::Color; case QVariant::String: - return d.type == QVariant::KeySequence || d.type == QVariant::Font - || d.type == QVariant::Color; + return currentType == QVariant::KeySequence || currentType == QVariant::Font + || currentType == QVariant::Color; case QVariant::KeySequence: - return d.type == QVariant::String || d.type == QVariant::Int; + return currentType == QVariant::String || currentType == QVariant::Int; case QVariant::Font: - return d.type == QVariant::String; + return currentType == QVariant::String; case QVariant::Color: - return d.type == QVariant::String || d.type == QVariant::ByteArray - || d.type == QVariant::Brush; + return currentType == QVariant::String || currentType == QVariant::ByteArray + || currentType == QVariant::Brush; case QVariant::Brush: - return d.type == QVariant::Color || d.type == QVariant::Pixmap; + return currentType == QVariant::Color || currentType == QVariant::Pixmap; case QMetaType::Long: case QMetaType::Char: case QMetaType::UChar: case QMetaType::ULong: case QMetaType::Short: case QMetaType::UShort: - case QMetaType::Float: - return qCanConvertMatrix[QVariant::Int] & (1 << d.type) || d.type == QVariant::Int; + return qCanConvertMatrix[QVariant::Int] & (1 << currentType) || currentType == QVariant::Int; default: return false; } } - if(t == String && d.type == StringList) + if(t == String && currentType == StringList) return v_cast<QStringList>(&d)->count() == 1; else - return qCanConvertMatrix[t] & (1 << d.type); + return qCanConvertMatrix[t] & (1 << currentType); } /*! @@ -2726,7 +2724,7 @@ bool QVariant::cmp(const QVariant &v) const const void *QVariant::constData() const { - return constDataHelper(d); + return d.is_shared ? d.data.shared->ptr : reinterpret_cast<const void *>(&d.data.ptr); } /*! @@ -2739,7 +2737,7 @@ const void *QVariant::constData() const void* QVariant::data() { detach(); - return const_cast<void *>(constDataHelper(d)); + return const_cast<void *>(constData()); } diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 580b101..d73fcbc 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -128,7 +128,7 @@ class Q_CORE_EXPORT QVariant LineF = 24, Point = 25, PointF = 26, - RegExp = 27, + RegExp = 27, Hash = 28, LastCoreType = Hash, @@ -181,6 +181,7 @@ class Q_CORE_EXPORT QVariant QVariant(qulonglong ull); QVariant(bool b); QVariant(double d); + QVariant(float f) { d.is_null = false; d.type = QMetaType::Float; d.data.f = f; } #ifndef QT_NO_CAST_FROM_ASCII QT_ASCII_CAST_WARN_CONSTRUCTOR QVariant(const char *str); #endif @@ -349,6 +350,7 @@ class Q_CORE_EXPORT QVariant uint u; bool b; double d; + float f; qlonglong ll; qulonglong ull; void *ptr; @@ -443,7 +445,18 @@ inline QVariant qVariantFromValue(const QVariant &t) { return t; } template <typename T> inline void qVariantSetValue(QVariant &v, const T &t) { - v = QVariant(qMetaTypeId<T>(reinterpret_cast<T *>(0)), &t); + //if possible we reuse the current QVariant private + const int type = qMetaTypeId<T>(reinterpret_cast<T *>(0)); + QVariant::Private &d = v.data_ptr(); + if (type <= int(QVariant::Char) || (type == d.type && v.isDetached())) { + d.type = type; + T *old = reinterpret_cast<T*>(d.is_shared ? d.data.shared->ptr : &d.data.ptr); + if (QTypeInfo<T>::isComplex) + old->~T(); + new (old) T(t); //call the copy constructor + } else { + v = QVariant(type, &t); + } } inline QVariant::QVariant() {} diff --git a/src/corelib/kernel/qvariant_p.h b/src/corelib/kernel/qvariant_p.h index 0764fe3..074575b 100644 --- a/src/corelib/kernel/qvariant_p.h +++ b/src/corelib/kernel/qvariant_p.h @@ -60,8 +60,6 @@ QT_BEGIN_NAMESPACE -extern Q_CORE_EXPORT const QVariant::Handler *qExtendedVariantHandler; - #ifdef Q_CC_SUN // Sun CC picks the wrong overload, so introduce awful hack template <typename T> @@ -70,7 +68,7 @@ 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) - : reinterpret_cast<T*>(&d->data.c)); + : static_cast<T *>(static_cast<void *>(&d->data.c))); } #else // every other compiler in this world @@ -80,7 +78,7 @@ 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) - : reinterpret_cast<const T *>(&d->data.c)); + : static_cast<const T *>(static_cast<const void *>(&d->data.c))); } template <typename T> @@ -88,15 +86,17 @@ inline T *v_cast(QVariant::Private *d, T * = 0) { return ((sizeof(T) > sizeof(QVariant::Private::Data)) ? static_cast<T *>(d->data.shared->ptr) - : reinterpret_cast<T *>(&d->data.c)); + : static_cast<T *>(static_cast<void *>(&d->data.c))); } #endif -//a simple template that avoids to allocate 2 buffers when creating a QVariant + +//a simple template that avoids to allocate 2 memory chunks when creating a QVariant template <class T> class QVariantPrivateSharedEx : public QVariant::PrivateShared { public: + QVariantPrivateSharedEx() : QVariant::PrivateShared(&m_t) { } QVariantPrivateSharedEx(const T&t) : QVariant::PrivateShared(&m_t), m_t(t) { } private: @@ -105,14 +105,12 @@ private: // constructs a new variant if copy is 0, otherwise copy-constructs template <class T> -inline void v_construct(QVariant::Private *x, const T& t) +inline void v_construct(QVariant::Private *x, const T &t) { - x->type = qMetaTypeId<T>(reinterpret_cast<T *>(0)); if (sizeof(T) > sizeof(QVariant::Private::Data)) { x->data.shared = new QVariantPrivateSharedEx<T>(t); x->is_shared = true; } else { - x->is_shared = false; new (&x->data.ptr) T(t); } } @@ -120,24 +118,31 @@ inline void v_construct(QVariant::Private *x, const T& t) template <class T> inline void v_construct(QVariant::Private *x, const void *copy, T * = 0) { - if (copy) { - v_construct<T>(x, *reinterpret_cast<const T*>(copy)); + if (sizeof(T) > sizeof(QVariant::Private::Data)) { + x->data.shared = copy ? new QVariantPrivateSharedEx<T>(*static_cast<const T *>(copy)) + : new QVariantPrivateSharedEx<T>; + x->is_shared = true; } else { - T t; - v_construct<T>(x, t); + if (copy) + new (&x->data.ptr) T(*static_cast<const T *>(copy)); + else + new (&x->data.ptr) T; } } - // deletes the internal structures template <class T> inline void v_clear(QVariant::Private *d, T* = 0) { - //now we need to call the destructor in any case - //because QVariant::PrivateShared doesn't have a virtual destructor - v_cast<T>(d)->~T(); - if (sizeof(T) > sizeof(QVariant::Private::Data)) - delete d->data.shared; + + if (sizeof(T) > sizeof(QVariant::Private::Data)) { + //now we need to cast + //because QVariant::PrivateShared doesn't have a virtual destructor + delete static_cast<QVariantPrivateSharedEx<T>*>(d->data.shared); + } else { + v_cast<T>(d)->~T(); + } + } QT_END_NAMESPACE diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index f602821..8f1c698 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -180,8 +180,7 @@ void *QThreadPrivate::start(void *arg) data->quitNow = false; // ### TODO: allow the user to create a custom event dispatcher - if (QCoreApplication::instance()) - createEventDispatcher(data); + createEventDispatcher(data); emit thr->started(); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp index 27193c6..7094e3d 100644 --- a/src/corelib/thread/qthread_win.cpp +++ b/src/corelib/thread/qthread_win.cpp @@ -292,8 +292,7 @@ unsigned int __stdcall QThreadPrivate::start(void *arg) data->quitNow = false; // ### TODO: allow the user to create a custom event dispatcher - if (QCoreApplication::instance()) - createEventDispatcher(data); + createEventDispatcher(data); #if !defined(QT_NO_DEBUG) && defined(Q_CC_MSVC) && !defined(Q_OS_WINCE) // sets the name of the current thread. diff --git a/src/corelib/tools/qbytearraymatcher.cpp b/src/corelib/tools/qbytearraymatcher.cpp index cd4cf90..211d190 100644 --- a/src/corelib/tools/qbytearraymatcher.cpp +++ b/src/corelib/tools/qbytearraymatcher.cpp @@ -120,6 +120,7 @@ QByteArrayMatcher::QByteArrayMatcher() : d(0) { p.p = 0; + p.l = 0; qMemSet(p.q_skiptable, 0, sizeof(p.q_skiptable)); } @@ -170,7 +171,7 @@ QByteArrayMatcher::~QByteArrayMatcher() QByteArrayMatcher &QByteArrayMatcher::operator=(const QByteArrayMatcher &other) { q_pattern = other.q_pattern; - qMemCopy(p.q_skiptable, other.p.q_skiptable, sizeof(p.q_skiptable)); + qMemCopy(&p, &other.p, sizeof(p)); return *this; } diff --git a/src/corelib/tools/qbytearraymatcher.h b/src/corelib/tools/qbytearraymatcher.h index d7f2366..633e92c 100644 --- a/src/corelib/tools/qbytearraymatcher.h +++ b/src/corelib/tools/qbytearraymatcher.h @@ -67,7 +67,12 @@ public: int indexIn(const QByteArray &ba, int from = 0) const; int indexIn(const char *str, int len, int from = 0) const; - inline QByteArray pattern() const { return q_pattern; } + inline QByteArray pattern() const + { + if (q_pattern.isNull()) + return QByteArray((const char*)p.p, p.l); + return q_pattern; + } private: QByteArrayMatcherPrivate *d; |