diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-08-17 02:58:26 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-08-17 02:58:26 (GMT) |
commit | 65d6e2c443ea31886de14736b21953fb8695eaf7 (patch) | |
tree | 45be09de909749ff10350fdc2377c4dbf3e815d8 /src/corelib/kernel | |
parent | 6eab5d70003fe18ada199009d4b636765c609786 (diff) | |
parent | 72c1cb2ffdfb2742985e12025d4578aa2fe80ce7 (diff) | |
download | Qt-65d6e2c443ea31886de14736b21953fb8695eaf7.zip Qt-65d6e2c443ea31886de14736b21953fb8695eaf7.tar.gz Qt-65d6e2c443ea31886de14736b21953fb8695eaf7.tar.bz2 |
Merge branch 'master' of git@scm.dev.nokia.troll.no:qt/qt into kinetic-declarativeui
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r-- | src/corelib/kernel/qfunctions_wince.cpp | 7 | ||||
-rw-r--r-- | src/corelib/kernel/qvariant.cpp | 58 | ||||
-rw-r--r-- | src/corelib/kernel/qvariant.h | 2 |
3 files changed, 53 insertions, 14 deletions
diff --git a/src/corelib/kernel/qfunctions_wince.cpp b/src/corelib/kernel/qfunctions_wince.cpp index 2b5d4fe..77f680a 100644 --- a/src/corelib/kernel/qfunctions_wince.cpp +++ b/src/corelib/kernel/qfunctions_wince.cpp @@ -292,13 +292,14 @@ bool qt_wince__chmod(const char *file, int mode) bool qt_wince__wchmod(const wchar_t *file, int mode) { + BOOL success = FALSE; // ### Does not work properly, what about just adding one property? if(mode&_S_IWRITE) { - return SetFileAttributes(file, FILE_ATTRIBUTE_NORMAL); + success = SetFileAttributes(file, FILE_ATTRIBUTE_NORMAL); } else if((mode&_S_IREAD) && !(mode&_S_IWRITE)) { - return SetFileAttributes(file, FILE_ATTRIBUTE_READONLY); + success = SetFileAttributes(file, FILE_ATTRIBUTE_READONLY); } - return false; + return success ? 0 : -1; } HANDLE qt_wince_CreateFileA(LPCSTR filename, DWORD access, DWORD share, LPSECURITY_ATTRIBUTES attr, DWORD dispo, DWORD flags, HANDLE tempFile) diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index dfed4db..3c430eb 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -658,6 +658,7 @@ static bool convert(const QVariant::Private *d, QVariant::Type t, void *result, break; case QVariant::Url: *str = v_cast<QUrl>(d)->toString(); + break; default: return false; } @@ -935,10 +936,10 @@ static bool convert(const QVariant::Private *d, QVariant::Type t, void *result, float *f = static_cast<float *>(result); switch (d->type) { case QVariant::String: - *f = float(v_cast<QString>(d)->toDouble(ok)); + *f = v_cast<QString>(d)->toFloat(ok); break; case QVariant::ByteArray: - *f = float(v_cast<QByteArray>(d)->toDouble(ok)); + *f = v_cast<QByteArray>(d)->toFloat(ok); break; case QVariant::Bool: *f = float(d->data.b); @@ -1053,7 +1054,7 @@ static void streamDebug(QDebug dbg, const QVariant &v) dbg.nospace() << v.toULongLong(); break; case QMetaType::Float: - dbg.nospace() << qVariantValue<float>(v); + dbg.nospace() << v.toFloat(); break; case QMetaType::QObjectStar: dbg.nospace() << qVariantValue<QObject *>(v); @@ -2330,16 +2331,17 @@ QBitArray QVariant::toBitArray() const } template <typename T> -inline T qNumVariantToHelper(const QVariant::Private &d, QVariant::Type t, +inline T qNumVariantToHelper(const QVariant::Private &d, const QVariant::Handler *handler, bool *ok, const T& val) { + uint t = qMetaTypeId<T>(); if (ok) *ok = true; if (d.type == t) return val; T ret; - if (!handler->convert(&d, t, &ret, ok) && ok) + if (!handler->convert(&d, QVariant::Type(t), &ret, ok) && ok) *ok = false; return ret; } @@ -2361,7 +2363,7 @@ inline T qNumVariantToHelper(const QVariant::Private &d, QVariant::Type t, */ int QVariant::toInt(bool *ok) const { - return qNumVariantToHelper<int>(d, Int, handler, ok, d.data.i); + return qNumVariantToHelper<int>(d, handler, ok, d.data.i); } /*! @@ -2381,7 +2383,7 @@ int QVariant::toInt(bool *ok) const */ uint QVariant::toUInt(bool *ok) const { - return qNumVariantToHelper<uint>(d, UInt, handler, ok, d.data.u); + return qNumVariantToHelper<uint>(d, handler, ok, d.data.u); } /*! @@ -2396,7 +2398,7 @@ uint QVariant::toUInt(bool *ok) const */ qlonglong QVariant::toLongLong(bool *ok) const { - return qNumVariantToHelper<qlonglong>(d, LongLong, handler, ok, d.data.ll); + return qNumVariantToHelper<qlonglong>(d, handler, ok, d.data.ll); } /*! @@ -2412,7 +2414,7 @@ qlonglong QVariant::toLongLong(bool *ok) const */ qulonglong QVariant::toULongLong(bool *ok) const { - return qNumVariantToHelper<qulonglong>(d, ULongLong, handler, ok, d.data.ull); + return qNumVariantToHelper<qulonglong>(d, handler, ok, d.data.ull); } /*! @@ -2439,7 +2441,7 @@ bool QVariant::toBool() const /*! Returns the variant as a double if the variant has type() \l - Double, \l Bool, \l ByteArray, \l Int, \l LongLong, \l String, \l + Double, \l QMetaType::Float, \l Bool, \l ByteArray, \l Int, \l LongLong, \l String, \l UInt, or \l ULongLong; otherwise returns 0.0. If \a ok is non-null: \c{*}\a{ok} is set to true if the value could be @@ -2449,7 +2451,41 @@ bool QVariant::toBool() const */ double QVariant::toDouble(bool *ok) const { - return qNumVariantToHelper<double>(d, Double, handler, ok, d.data.d); + return qNumVariantToHelper<double>(d, handler, ok, d.data.d); +} + +/*! + Returns the variant as a float if the variant has type() \l + Double, \l QMetaType::Float, \l Bool, \l ByteArray, \l Int, \l LongLong, \l String, \l + UInt, or \l ULongLong; otherwise returns 0.0. + + \since 4.6 + + If \a ok is non-null: \c{*}\a{ok} is set to true if the value could be + converted to a double; otherwise \c{*}\a{ok} is set to false. + + \sa canConvert(), convert() +*/ +float QVariant::toFloat(bool *ok) const +{ + return qNumVariantToHelper<float>(d, handler, ok, d.data.d); +} + +/*! + Returns the variant as a qreal if the variant has type() \l + Double, \l QMetaType::Float, \l Bool, \l ByteArray, \l Int, \l LongLong, \l String, \l + UInt, or \l ULongLong; otherwise returns 0.0. + + \since 4.6 + + If \a ok is non-null: \c{*}\a{ok} is set to true if the value could be + converted to a double; otherwise \c{*}\a{ok} is set to false. + + \sa canConvert(), convert() +*/ +qreal QVariant::toReal(bool *ok) const +{ + return qNumVariantToHelper<qreal>(d, handler, ok, d.data.d); } /*! diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 569355a..79bd5b8 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -250,6 +250,8 @@ class Q_CORE_EXPORT QVariant qulonglong toULongLong(bool *ok = 0) const; bool toBool() const; double toDouble(bool *ok = 0) const; + float toFloat(bool *ok = 0) const; + qreal toReal(bool *ok = 0) const; QByteArray toByteArray() const; QBitArray toBitArray() const; QString toString() const; |