diff options
Diffstat (limited to 'src/corelib/global')
-rw-r--r-- | src/corelib/global/qglobal.cpp | 15 | ||||
-rw-r--r-- | src/corelib/global/qglobal.h | 7 | ||||
-rw-r--r-- | src/corelib/global/qnamespace.h | 6 | ||||
-rw-r--r-- | src/corelib/global/qnamespace.qdoc | 22 | ||||
-rw-r--r-- | src/corelib/global/qnumeric.cpp | 136 | ||||
-rw-r--r-- | src/corelib/global/qnumeric.h | 3 |
6 files changed, 185 insertions, 4 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index ff2c4bbe5e..2637a6a0d8 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -2136,7 +2136,9 @@ QString qt_error_string(int errorCode) s = QT_TRANSLATE_NOOP("QIODevice", "No space left on device"); break; default: { -#ifdef Q_OS_WIN +#if defined(Q_OS_WIN) + // Retrieve the system error message for the last-error code. +# ifndef Q_OS_WINRT wchar_t *string = 0; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, NULL, @@ -2147,6 +2149,17 @@ QString qt_error_string(int errorCode) NULL); ret = QString::fromWCharArray(string); LocalFree((HLOCAL)string); +# else // !Q_OS_WINRT + __declspec(thread) static wchar_t errorString[4096]; + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + errorCode, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + errorString, + ARRAYSIZE(errorString), + NULL); + ret = QString::fromWCharArray(errorString); +# endif // Q_OS_WINRT if (ret.isEmpty() && errorCode == ERROR_MOD_NOT_FOUND) ret = QString::fromLatin1("The specified module could not be found."); diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index b1a22ddf03..fd5ab865f3 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -45,11 +45,11 @@ #include <stddef.h> -#define QT_VERSION_STR "5.2.0" +#define QT_VERSION_STR "5.3.0" /* QT_VERSION is (major << 16) + (minor << 8) + patch. */ -#define QT_VERSION 0x050200 +#define QT_VERSION 0x050300 /* can be used like #if (QT_VERSION >= QT_VERSION_CHECK(4, 4, 0)) */ @@ -192,7 +192,7 @@ typedef qint64 qlonglong; typedef quint64 qulonglong; #ifndef QT_POINTER_SIZE -# if defined(Q_OS_WIN64) +# if defined(Q_OS_WIN64) || (defined(Q_OS_WINRT) && defined(_M_X64)) # define QT_POINTER_SIZE 8 # elif defined(Q_OS_WIN32) || defined(Q_OS_WINCE) || defined(Q_OS_WINRT) # define QT_POINTER_SIZE 4 @@ -542,6 +542,7 @@ class QDataStream; #if defined(Q_OS_WINRT) # define QT_NO_PROCESS +# define QT_NO_FILESYSTEMWATCHER #endif inline void qt_noop(void) {} diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index 420721cb54..1409e5d977 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -1584,6 +1584,12 @@ public: ScrollUpdate, ScrollEnd }; + + enum MouseEventSource { + MouseEventNotSynthesized, + MouseEventSynthesizedBySystem, + MouseEventSynthesizedByQt + }; } #ifdef Q_MOC_RUN ; diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index f46640ea0e..78f6a60287 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -2895,3 +2895,25 @@ \value ScrollEnd Scrolling has ended, but the scrolling distance did not change anymore. */ + +/*! + \enum Qt::MouseEventSource + \since 5.3 + + This enum describes the source of a mouse event and can be useful + to determine if the event is an artificial mouse event originating + from another device such as a touchscreen. + + \value MouseEventNotSynthesized The most common value. On + platforms where such information is available this value indicates + that the event was generated in response to a genuine mouse event + in the system. + + \value MouseEventSynthesizedBySystem Indicates that the mouse + event was synthesized from a touch event by the platform. + + \value MouseEventSynthesizedByQt Indicates that the mouse event was + synthesized from an unhandled touch event by Qt. + + \sa Qt::AA_SynthesizeMouseForUnhandledTouchEvents +*/ diff --git a/src/corelib/global/qnumeric.cpp b/src/corelib/global/qnumeric.cpp index d09357c26c..7d8bd8c3c6 100644 --- a/src/corelib/global/qnumeric.cpp +++ b/src/corelib/global/qnumeric.cpp @@ -41,6 +41,7 @@ #include "qnumeric.h" #include "qnumeric_p.h" +#include <string.h> QT_BEGIN_NAMESPACE @@ -99,4 +100,139 @@ Q_CORE_EXPORT double qQNaN() { return qt_qnan(); } Q_CORE_EXPORT double qInf() { return qt_inf(); } + +/*! + \internal + */ +static inline quint32 f2i(float f) +{ + quint32 i; + memcpy(&i, &f, sizeof(f)); + return i; +} + +/*! + Returns the number of representable floating-point numbers between \a a and \a b. + + This function provides an alternative way of doing approximated comparisons of floating-point + numbers similar to qFuzzyCompare(). However, it returns the distance between two numbers, which + gives the caller a possibility to choose the accepted error. Errors are relative, so for + instance the distance between 1.0E-5 and 1.00001E-5 will give 110, while the distance between + 1.0E36 and 1.00001E36 will give 127. + + This function is useful if a floating point comparison requires a certain precision. + Therefore, if \a a and \a b are equal it will return 0. The maximum value it will return for 32-bit + floating point numbers is 4,278,190,078. This is the distance between \c{-FLT_MAX} and + \c{+FLT_MAX}. + + The function does not give meaningful results if any of the arguments are \c Infinite or \c NaN. + You can check for this by calling qIsFinite(). + + The return value can be considered as the "error", so if you for instance want to compare + two 32-bit floating point numbers and all you need is an approximated 24-bit precision, you can + use this function like this: + + \code + if (qFloatDistance(a, b) < (1 << 7)) { // The last 7 bits are not + // significant + // precise enough + } + \endcode + + \sa qFuzzyCompare() + \relates <QtGlobal> +*/ +Q_CORE_EXPORT quint32 qFloatDistance(float a, float b) +{ + static const quint32 smallestPositiveFloatAsBits = 0x00000001; // denormalized, (SMALLEST), (1.4E-45) + /* Assumes: + * IEE754 format. + * Integers and floats have the same endian + */ + Q_STATIC_ASSERT(sizeof(quint32) == sizeof(float)); + Q_ASSERT(qIsFinite(a) && qIsFinite(b)); + if (a == b) + return 0; + if ((a < 0) != (b < 0)) { + // if they have different signs + if (a < 0) + a = -a; + else /*if (b < 0)*/ + b = -b; + return qFloatDistance(0.0F, a) + qFloatDistance(0.0F, b); + } + if (a < 0) { + a = -a; + b = -b; + } + // at this point a and b should not be negative + + // 0 is special + if (!a) + return f2i(b) - smallestPositiveFloatAsBits + 1; + if (!b) + return f2i(a) - smallestPositiveFloatAsBits + 1; + + // finally do the common integer subtraction + return a > b ? f2i(a) - f2i(b) : f2i(b) - f2i(a); +} + + +/*! + \internal + */ +static inline quint64 d2i(double d) +{ + quint64 i; + memcpy(&i, &d, sizeof(d)); + return i; +} + +/*! + Returns the number of representable floating-point numbers between \a a and \a b. + + This function serves the same purpose as \c{qFloatDistance(float, float)}, but + returns the distance between two \c double numbers. Since the range is larger + than for two \c float numbers (\c{[-DBL_MAX,DBL_MAX]}), the return type is quint64. + + + \sa qFuzzyCompare() + \relates <QtGlobal> +*/ +Q_CORE_EXPORT quint64 qFloatDistance(double a, double b) +{ + static const quint64 smallestPositiveFloatAsBits = 0x1; // denormalized, (SMALLEST) + /* Assumes: + * IEE754 format double precision + * Integers and floats have the same endian + */ + Q_STATIC_ASSERT(sizeof(quint64) == sizeof(double)); + Q_ASSERT(qIsFinite(a) && qIsFinite(b)); + if (a == b) + return 0; + if ((a < 0) != (b < 0)) { + // if they have different signs + if (a < 0) + a = -a; + else /*if (b < 0)*/ + b = -b; + return qFloatDistance(0.0, a) + qFloatDistance(0.0, b); + } + if (a < 0) { + a = -a; + b = -b; + } + // at this point a and b should not be negative + + // 0 is special + if (!a) + return d2i(b) - smallestPositiveFloatAsBits + 1; + if (!b) + return d2i(a) - smallestPositiveFloatAsBits + 1; + + // finally do the common integer subtraction + return a > b ? d2i(a) - d2i(b) : d2i(b) - d2i(a); +} + + QT_END_NAMESPACE diff --git a/src/corelib/global/qnumeric.h b/src/corelib/global/qnumeric.h index 25db5443eb..633486dff1 100644 --- a/src/corelib/global/qnumeric.h +++ b/src/corelib/global/qnumeric.h @@ -57,6 +57,9 @@ Q_CORE_EXPORT double qSNaN(); Q_CORE_EXPORT double qQNaN(); Q_CORE_EXPORT double qInf(); +Q_CORE_EXPORT quint32 qFloatDistance(float a, float b); +Q_CORE_EXPORT quint64 qFloatDistance(double a, double b); + #define Q_INFINITY (QT_PREPEND_NAMESPACE(qInf)()) #define Q_SNAN (QT_PREPEND_NAMESPACE(qSNaN)()) #define Q_QNAN (QT_PREPEND_NAMESPACE(qQNaN)()) |