diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2012-05-03 10:18:36 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@nokia.com> | 2012-05-03 12:26:09 +0200 |
commit | 1e49914fee099c4c0d634743326b50ad02e6c8f1 (patch) | |
tree | 422eedb9ddcb16fa9f5a653737b4c78d8930eeae /src | |
parent | 1eac22a1b9dad7f843916afa9b7c820aa1c23777 (diff) | |
parent | c0d249019b098890fb8e5e9e144c2dd8029a670c (diff) |
Merge remote-tracking branch 'origin/api_changes'
Conflicts:
src/corelib/global/qglobal.cpp
src/corelib/global/qlogging.cpp
src/gui/kernel/qguiapplication.h
src/gui/kernel/qwindow.cpp
src/gui/kernel/qwindow.h
tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
Change-Id: I62a8805577a7940d4d36bed985eb3e7019d22f2e
Diffstat (limited to 'src')
29 files changed, 383 insertions, 507 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp index 16f6783a52..dc6c3aa616 100644 --- a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp @@ -246,20 +246,21 @@ const TInputType &myMin(const TInputType &value1, const TInputType &value2) #include <stdio.h> #include <stdlib.h> -void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const char *msg) +void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) { + QByteArray localMsg = msg.toLocal8Bit(); switch (type) { case QtDebugMsg: - fprintf(stderr, "Debug: %s (%s:%u, %s)\n", msg, context.file, context.line, context.function); + fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); break; case QtWarningMsg: - fprintf(stderr, "Warning: %s (%s:%u, %s)\n", msg, context.file, context.line, context.function); + fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); break; case QtCriticalMsg: - fprintf(stderr, "Critical: %s (%s:%u, %s)\n", msg, context.file, context.line, context.function); + fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); break; case QtFatalMsg: - fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", msg, context.file, context.line, context.function); + fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); abort(); } } diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 99078b17f4..966d66a038 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -440,7 +440,7 @@ QT_BEGIN_NAMESPACE Finally, the QtMsgType definition identifies the various messages that can be generated and sent to a Qt message handler; - QMessageHandler is a type definition for a pointer to a function with + QtMessageHandler is a type definition for a pointer to a function with the signature \c {void myMessageHandler(QtMsgType, const QMessageLogContext &, const char *)}. QMessageLogContext class contains the line, file, and function the @@ -476,7 +476,7 @@ QT_BEGIN_NAMESPACE accept a \l qreal value as their argument returning the value rounded up to the nearest integer and 64-bit integer respectively, the qInstallMessageHandler() function which installs the given - QMessageHandler, and the qVersion() function which returns the + QtMessageHandler, and the qVersion() function which returns the version number of Qt at run-time as a string. \section1 Macros @@ -678,7 +678,7 @@ QT_BEGIN_NAMESPACE \value QtSystemMsg - \sa QMessageHandler, qInstallMessageHandler() + \sa QtMessageHandler, qInstallMessageHandler() */ /*! \typedef QFunctionPointer diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 81fe82a973..52ffae5f98 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -45,11 +45,12 @@ #include "qstring.h" #include "qvarlengtharray.h" #include "qdebug.h" +#include "qmutex.h" #ifndef QT_BOOTSTRAPPED #include "qcoreapplication.h" #include "qthread.h" #endif -#ifdef Q_OS_WINCE +#ifdef Q_OS_WIN #include <qt_windows.h> #endif @@ -66,7 +67,7 @@ QT_BEGIN_NAMESPACE The class provides information about the source code location a qDebug(), qWarning(), qCritical() or qFatal() message was generated. - \sa QMessageLogger, QMessageHandler, qInstallMessageHandler() + \sa QMessageLogger, QtMessageHandler, qInstallMessageHandler() */ /*! @@ -92,6 +93,7 @@ QT_BEGIN_NAMESPACE \internal Uses a local buffer to output the message. Not locale safe + cuts off everything after character 255, but will work in out of memory situations. + Stop the execution afterwards. */ static void qEmergencyOut(QtMsgType msgType, const char *msg, va_list ap) { @@ -99,8 +101,33 @@ static void qEmergencyOut(QtMsgType msgType, const char *msg, va_list ap) emergency_buf[255] = '\0'; if (msg) qvsnprintf(emergency_buf, 255, msg, ap); - QMessageLogContext context; - qt_message_output(msgType, context, emergency_buf); + +#if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB) + OutputDebugStringA(emergency_buf); +#else + fprintf(stderr, "%s", emergency_buf); + fflush(stderr); +#endif + + if (msgType == QtFatalMsg + || (msgType == QtWarningMsg + && (!qgetenv("QT_FATAL_WARNINGS").isNull())) ) { +#if defined(Q_CC_MSVC) && defined(QT_DEBUG) && defined(_DEBUG) && defined(_CRT_ERROR) + // get the current report mode + int reportMode = _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_WNDW); + _CrtSetReportMode(_CRT_ERROR, reportMode); + int ret = _CrtDbgReport(_CRT_ERROR, __FILE__, __LINE__, QT_VERSION_STR, + msg); + if (ret == 1) + _CrtDbgBreak(); +#endif + +#if (defined(Q_OS_UNIX) || defined(Q_CC_MINGW)) + abort(); // trap; generates core dump +#else + exit(1); // goodbye cruel world +#endif + } } #endif @@ -116,10 +143,10 @@ static void qt_message(QtMsgType msgType, const QMessageLogContext &context, con return; } #endif - QByteArray buf; + QString buf; if (msg) { QT_TRY { - buf = QString().vsprintf(msg, ap).toLocal8Bit(); + buf = QString().vsprintf(msg, ap); } QT_CATCH(const std::bad_alloc &) { #if !defined(QT_NO_EXCEPTIONS) qEmergencyOut(msgType, msg, ap); @@ -128,7 +155,7 @@ static void qt_message(QtMsgType msgType, const QMessageLogContext &context, con #endif } } - qt_message_output(msgType, context, buf.constData()); + qt_message_output(msgType, context, buf); } #undef qDebug @@ -374,21 +401,53 @@ static const char appnameTokenC[] = "%{appname}"; static const char threadidTokenC[] = "%{threadid}"; static const char emptyTokenC[] = ""; +static const char defaultPattern[] = "%{message}"; + + struct QMessagePattern { QMessagePattern(); ~QMessagePattern(); + void setPattern(const QString &pattern); + // 0 terminated arrays of literal tokens / literal or placeholder tokens const char **literals; const char **tokens; + + bool fromEnvironment; + static QBasicMutex mutex; }; +QBasicMutex QMessagePattern::mutex; + QMessagePattern::QMessagePattern() + : literals(0) + , tokens(0) + , fromEnvironment(false) { - QString pattern = QString::fromLocal8Bit(qgetenv("QT_MESSAGE_PATTERN")); - if (pattern.isEmpty()) { - pattern = QLatin1String("%{message}"); + const QString envPattern = QString::fromLocal8Bit(qgetenv("QT_MESSAGE_PATTERN")); + if (envPattern.isEmpty()) { + setPattern(QLatin1String(defaultPattern)); + } else { + setPattern(envPattern); + fromEnvironment = true; } +} + +QMessagePattern::~QMessagePattern() +{ + for (int i = 0; literals[i] != 0; ++i) + delete [] literals[i]; + delete [] literals; + literals = 0; + delete [] tokens; + tokens = 0; +} + +void QMessagePattern::setPattern(const QString &pattern) +{ + delete [] tokens; + delete [] literals; // scanner QList<QString> lexemes; @@ -452,13 +511,13 @@ QMessagePattern::QMessagePattern() else { fprintf(stderr, "%s\n", QString::fromLatin1("QT_MESSAGE_PATTERN: Unknown placeholder %1\n" - ).arg(lexeme).toLocal8Bit().constData()); + ).arg(lexeme).toLatin1().constData()); fflush(stderr); tokens[i] = emptyTokenC; } } else { char *literal = new char[lexeme.size() + 1]; - strncpy(literal, lexeme.toLocal8Bit().constData(), lexeme.size()); + strncpy(literal, lexeme.toLatin1().constData(), lexeme.size()); literal[lexeme.size()] = '\0'; literalsVar.append(literal); tokens[i] = literal; @@ -469,91 +528,88 @@ QMessagePattern::QMessagePattern() memcpy(literals, literalsVar.constData(), literalsVar.size() * sizeof(const char*)); } -QMessagePattern::~QMessagePattern() -{ - for (int i = 0; literals[i] != 0; ++i) - delete [] literals[i]; - delete [] literals; - literals = 0; - delete [] tokens; - tokens = 0; -} - Q_GLOBAL_STATIC(QMessagePattern, qMessagePattern) /*! \internal */ -Q_CORE_EXPORT QByteArray qMessageFormatString(QtMsgType type, const QMessageLogContext &context, - const char *str) +Q_CORE_EXPORT QString qMessageFormatString(QtMsgType type, const QMessageLogContext &context, + const QString &str) { - QByteArray message; + QString message; + + QMutexLocker lock(&QMessagePattern::mutex); QMessagePattern *pattern = qMessagePattern(); if (!pattern) { // after destruction of static QMessagePattern instance message.append(str); - message.append('\n'); + message.append(QLatin1Char('\n')); return message; } + // don't print anything if pattern was empty + if (pattern->tokens[0] == 0) + return message; + // we do not convert file, function, line literals to local encoding due to overhead for (int i = 0; pattern->tokens[i] != 0; ++i) { const char *token = pattern->tokens[i]; if (token == messageTokenC) { message.append(str); } else if (token == categoryTokenC) { - message.append(context.category); + message.append(QLatin1String(context.category)); } else if (token == typeTokenC) { switch (type) { - case QtDebugMsg: message.append("debug"); break; - case QtWarningMsg: message.append("warning"); break; - case QtCriticalMsg:message.append("critical"); break; - case QtFatalMsg: message.append("fatal"); break; + case QtDebugMsg: message.append(QLatin1String("debug")); break; + case QtWarningMsg: message.append(QLatin1String("warning")); break; + case QtCriticalMsg:message.append(QLatin1String("critical")); break; + case QtFatalMsg: message.append(QLatin1String("fatal")); break; } } else if (token == fileTokenC) { if (context.file) - message.append(context.file); + message.append(QLatin1String(context.file)); else - message.append("unknown"); + message.append(QLatin1String("unknown")); } else if (token == lineTokenC) { - message.append(QByteArray::number(context.line)); + message.append(QString::number(context.line)); } else if (token == functionTokenC) { if (context.function) - message.append(qCleanupFuncinfo(context.function)); + message.append(QString::fromLatin1(qCleanupFuncinfo(context.function))); else - message.append("unknown"); + message.append(QLatin1String("unknown")); #ifndef QT_BOOTSTRAPPED } else if (token == pidTokenC) { - message.append(QByteArray::number(QCoreApplication::applicationPid())); + message.append(QString::number(QCoreApplication::applicationPid())); } else if (token == appnameTokenC) { - message.append(QCoreApplication::applicationName().toUtf8().constData()); + message.append(QCoreApplication::applicationName()); } else if (token == threadidTokenC) { - message.append("0x" + QByteArray::number(qlonglong(QThread::currentThread()->currentThread()), 16)); + message.append(QLatin1String("0x")); + message.append(QString::number(qlonglong(QThread::currentThread()->currentThread()), 16)); #endif } else { - message.append(token); + message.append(QLatin1String(token)); } } - message.append('\n'); + message.append(QLatin1Char('\n')); return message; } static QtMsgHandler msgHandler = 0; // pointer to debug handler (without context) -static QMessageHandler messageHandler = 0; // pointer to debug handler (with context) +static QtMessageHandler messageHandler = 0; // pointer to debug handler (with context) +static QMessageHandler messageHandler2 = 0; // TODO: Remove before Qt5.0 beta /*! \internal */ static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &context, - const char *buf) + const QString &buf) { - QByteArray logMessage = qMessageFormatString(type, context, buf); + QString logMessage = qMessageFormatString(type, context, buf); #if defined(Q_OS_WINCE) - QString fstr = QString::fromLocal8Bit(logMessage); - OutputDebugString(reinterpret_cast<const wchar_t *> (fstr.utf16())); + OutputDebugString(reinterpret_cast<const wchar_t *> (logMessage.utf16())); #else - fprintf(stderr, "%s", logMessage.constData()); + fprintf(stderr, "%s", logMessage.toLocal8Bit().constData()); fflush(stderr); #endif } @@ -561,28 +617,43 @@ static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &con /*! \internal */ +static void qDefaultMessageHandler2(QtMsgType type, const QMessageLogContext &context, + const char *buf) +{ + qDefaultMessageHandler(type, context, QString::fromLocal8Bit(buf)); +} + +/*! + \internal +*/ static void qDefaultMsgHandler(QtMsgType type, const char *buf) { QMessageLogContext emptyContext; - qDefaultMessageHandler(type, emptyContext, buf); + qDefaultMessageHandler(type, emptyContext, QLatin1String(buf)); } /*! \internal */ -void qt_message_output(QtMsgType msgType, const QMessageLogContext &context, const char *buf) +void qt_message_output(QtMsgType msgType, const QMessageLogContext &context, const QString &message) { if (!msgHandler) msgHandler = qDefaultMsgHandler; if (!messageHandler) messageHandler = qDefaultMessageHandler; + if (!messageHandler2) + messageHandler2 = qDefaultMessageHandler2; + + if (messageHandler == qDefaultMessageHandler + && messageHandler2 != qDefaultMessageHandler2) + (*messageHandler2)(msgType, context, message.toLocal8Bit().constData()); // prefer new message handler over the old one if (msgHandler == qDefaultMsgHandler || messageHandler != qDefaultMessageHandler) { - (*messageHandler)(msgType, context, buf); + (*messageHandler)(msgType, context, message); } else { - (*msgHandler)(msgType, buf); + (*msgHandler)(msgType, message.toLocal8Bit().constData()); } if (msgType == QtFatalMsg @@ -593,14 +664,12 @@ void qt_message_output(QtMsgType msgType, const QMessageLogContext &context, con // get the current report mode int reportMode = _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_WNDW); _CrtSetReportMode(_CRT_ERROR, reportMode); -#if !defined(Q_OS_WINCE) - int ret = _CrtDbgReport(_CRT_ERROR, context.file, context.line, QT_VERSION_STR, buf); -#else - int ret = _CrtDbgReportW(_CRT_ERROR, _CRT_WIDE(context.file), + + int ret = _CrtDbgReportW(_CRT_ERROR, reinterpret_cast<const wchar_t *> ( + QString::fromLatin1(context.file).utf16()), context.line, _CRT_WIDE(QT_VERSION_STR), reinterpret_cast<const wchar_t *> ( - QString::fromLatin1(buf).utf16())); -#endif + message.utf16())); if (ret == 0 && reportMode & _CRTDBG_MODE_WNDW) return; // ignore else if (ret == 1) @@ -626,8 +695,9 @@ void qErrnoWarning(const char *msg, ...) buf.vsprintf(msg, ap); va_end(ap); - QMessageLogger().critical("%s (%s)", buf.toLocal8Bit().constData(), - qt_error_string(-1).toLocal8Bit().constData()); + buf += QLatin1String(" (") + qt_error_string(-1) + QLatin1Char(')'); + QMessageLogContext context; + qt_message_output(QtCriticalMsg, context, buf); } void qErrnoWarning(int code, const char *msg, ...) @@ -641,15 +711,22 @@ void qErrnoWarning(int code, const char *msg, ...) buf.vsprintf(msg, ap); va_end(ap); - QMessageLogger().critical("%s (%s)", buf.toLocal8Bit().constData(), - qt_error_string(code).toLocal8Bit().constData()); + buf += QLatin1String(" (") + qt_error_string(code) + QLatin1Char(')'); + QMessageLogContext context; + qt_message_output(QtCriticalMsg, context, buf); } #if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB) extern bool usingWinMain; extern Q_CORE_EXPORT void qWinMsgHandler(QtMsgType t, const char *str); extern Q_CORE_EXPORT void qWinMessageHandler(QtMsgType t, const QMessageLogContext &context, - const char *str); + const QString &str); + +void qWinMessageHandler2(QtMsgType t, const QMessageLogContext &context, + const char *str) +{ + qWinMessageHandler(t, context, QString::fromLocal8Bit(str)); +} #endif /*! @@ -660,38 +737,27 @@ extern Q_CORE_EXPORT void qWinMessageHandler(QtMsgType t, const QMessageLogConte This is a typedef for a pointer to a function with the following signature: - \snippet code/src_corelib_global_qglobal.cpp 7 - - This typedef is deprecated, you should use QMessageHandler instead. - \sa QtMsgType, QMessageHandler, qInstallMsgHandler(), qInstallMessageHandler() -*/ - -/*! - \fn QtMsgHandler qInstallMsgHandler(QtMsgHandler handler) - \relates <QtGlobal> - \deprecated + \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 7 - Installs a Qt message \a handler which has been defined - previously. This method is deprecated, use qInstallMessageHandler - instead. - \sa QtMsgHandler, qInstallMessageHandler + This typedef is deprecated, you should use QtMessageHandler instead. + \sa QtMsgType, QtMessageHandler, qInstallMsgHandler(), qInstallMessageHandler() */ /*! - \typedef QMessageHandler + \typedef QtMessageHandler \relates <QtGlobal> \since 5.0 This is a typedef for a pointer to a function with the following signature: - \snippet code/src_corelib_global_qglobal.cpp 49 + \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 49 \sa QtMsgType, qInstallMessageHandler() */ /*! - \fn QMessageHandler qInstallMessageHandler(QMessageHandler handler) + \fn QtMessageHandler qInstallMessageHandler(QtMessageHandler handler) \relates <QtGlobal> \since 5.0 @@ -719,17 +785,61 @@ extern Q_CORE_EXPORT void qWinMessageHandler(QtMsgType t, const QMessageLogConte Example: - \snippet code/src_corelib_global_qglobal.cpp 23 + \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 23 - \sa qDebug(), qWarning(), qCritical(), qFatal(), QtMsgType, + \sa QtMessageHandler, QtMsgType, qDebug(), qWarning(), qCritical(), qFatal(), {Debugging Techniques} */ -QMessageHandler qInstallMessageHandler(QMessageHandler h) +/*! + \fn QtMsgHandler qInstallMsgHandler(QtMsgHandler handler) + \relates <QtGlobal> + \deprecated + + Installs a Qt message \a handler which has been defined + previously. This method is deprecated, use qInstallMessageHandler + instead. + \sa QtMsgHandler, qInstallMessageHandler +*/ +/*! + \fn void qSetMessagePattern(const QString &pattern) + \relates <QtGlobal> + \since 5.0 + + \brief Changes the output of the default message handler. + + Allows to tweak the output of qDebug(), qWarning(), qCritical() and qFatal(). + + Following placeholders are supported: + + \table + \header \li Placeholder \li Description + \row \li \c %{appname} \li QCoreApplication::applicationName() + \row \li \c %{file} \li Path to source file + \row \li \c %{function} \li Function + \row \li \c %{line} \li Line in source file + \row \li \c %{message} \li The actual message + \row \li \c %{pid} \li QCoreApplication::applicationPid() + \row \li \c %{threadid} \li ID of current thread + \row \li \c %{type} \li "debug", "warning", "critical" or "fatal" + \endtable + + The default pattern is "%{message}". + + The pattern can also be changed at runtime by setting the QT_MESSAGE_PATTERN + environment variable; if both qSetMessagePattern() is called and QT_MESSAGE_PATTERN is + set, the environment variable takes precedence. + + qSetMessagePattern() has no effect if a custom message handler is installed. + + \sa qInstallMessageHandler, Debugging Techniques + */ + +QtMessageHandler qInstallMessageHandler(QtMessageHandler h) { if (!messageHandler) messageHandler = qDefaultMessageHandler; - QMessageHandler old = messageHandler; + QtMessageHandler old = messageHandler; messageHandler = h; #if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB) if (!messageHandler && usingWinMain) @@ -738,6 +848,19 @@ QMessageHandler qInstallMessageHandler(QMessageHandler h) return old; } +QMessageHandler qInstallMessageHandler(QMessageHandler h) +{ + if (!messageHandler2) + messageHandler2 = qDefaultMessageHandler2; + QMessageHandler old = messageHandler2; + messageHandler2 = h; +#if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB) + if (!messageHandler2 && usingWinMain) + messageHandler2 = qWinMessageHandler2; +#endif + return old; +} + QtMsgHandler qInstallMsgHandler(QtMsgHandler h) { //if handler is 0, set it to the @@ -753,6 +876,14 @@ QtMsgHandler qInstallMsgHandler(QtMsgHandler h) return old; } +void qSetMessagePattern(const QString &pattern) +{ + QMutexLocker lock(&QMessagePattern::mutex); + + if (!qMessagePattern()->fromEnvironment) + qMessagePattern()->setPattern(pattern); +} + void QMessageLogContext::copy(const QMessageLogContext &logContext) { this->category = logContext.category; @@ -760,4 +891,5 @@ void QMessageLogContext::copy(const QMessageLogContext &logContext) this->line = logContext.line; this->function = logContext.function; } + QT_END_NAMESPACE diff --git a/src/corelib/global/qlogging.h b/src/corelib/global/qlogging.h index 0860ef71b8..8366a852ab 100644 --- a/src/corelib/global/qlogging.h +++ b/src/corelib/global/qlogging.h @@ -155,7 +155,8 @@ private: # define qWarning QT_NO_QWARNING_MACRO #endif -Q_CORE_EXPORT void qt_message_output(QtMsgType, const QMessageLogContext &context, const char *buf); +Q_CORE_EXPORT void qt_message_output(QtMsgType, const QMessageLogContext &context, + const QString &message); Q_CORE_EXPORT void qErrnoWarning(int code, const char *msg, ...); Q_CORE_EXPORT void qErrnoWarning(const char *msg, ...); @@ -164,9 +165,15 @@ Q_CORE_EXPORT void qErrnoWarning(const char *msg, ...); typedef void (*QtMsgHandler)(QtMsgType, const char *); Q_CORE_EXPORT QtMsgHandler qInstallMsgHandler(QtMsgHandler); +typedef void (*QtMessageHandler)(QtMsgType, const QMessageLogContext &, const QString &); +Q_CORE_EXPORT QtMessageHandler qInstallMessageHandler(QtMessageHandler); + +// TODO: Remove before Qt5.0 Beta typedef void (*QMessageHandler)(QtMsgType, const QMessageLogContext &, const char *); Q_CORE_EXPORT QMessageHandler qInstallMessageHandler(QMessageHandler); +Q_CORE_EXPORT void qSetMessagePattern(const QString &messagePattern); + QT_END_HEADER QT_END_NAMESPACE diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index 48a382eea6..34abb5b75b 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -85,7 +85,7 @@ public: QT_TRY { qt_message_output(stream->type, stream->context, - stream->buffer.toLocal8Bit().data()); + stream->buffer); } QT_CATCH(std::bad_alloc&) { /* We're out of memory - give up. */ } } delete stream; diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 95c80cad20..5d70c4c5d8 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -1082,6 +1082,12 @@ void QCoreApplication::postEvent(QObject *receiver, QEvent *event, int priority) if (event->type() == QEvent::DeferredDelete && data == QThreadData::current()) { // remember the current running eventloop for DeferredDelete // events posted in the receiver's thread + + // check that QEvent's d pointer is unused before we store the loop level + // if further updates to QEvent have made the use of the d pointer necessary, + // then update this code to store the loop level somewhere else + Q_ASSERT_X(event->d == 0, "QCoreApplication::postEvent", + "Internal error: this code relies on QEvent::d being null"); event->d = reinterpret_cast<QEventPrivate *>(quintptr(data->loopLevel)); } diff --git a/src/corelib/kernel/qcoreapplication_win.cpp b/src/corelib/kernel/qcoreapplication_win.cpp index 7cc1f0e286..5649a8dd76 100644 --- a/src/corelib/kernel/qcoreapplication_win.cpp +++ b/src/corelib/kernel/qcoreapplication_win.cpp @@ -141,29 +141,28 @@ public: }; // defined in qlogging.cpp -extern Q_CORE_EXPORT QByteArray qMessageFormatString(QtMsgType type, - const QMessageLogContext &context, - const char *str); +extern Q_CORE_EXPORT QString qMessageFormatString(QtMsgType type, + const QMessageLogContext &context, + const QString &str); -Q_CORE_EXPORT void qWinMessageHandler(QtMsgType t, const QMessageLogContext &context, const char *str) +Q_CORE_EXPORT void qWinMessageHandler(QtMsgType t, const QMessageLogContext &context, const QString &str) { // cannot use QMutex here, because qWarning()s in the QMutex // implementation may cause this function to recurse static QWinMsgHandlerCriticalSection staticCriticalSection; - QByteArray message = qMessageFormatString(t, context, str); - QString s(QString::fromLocal8Bit(message)); + QString message = qMessageFormatString(t, context, str); // OutputDebugString is not threadsafe. staticCriticalSection.lock(); - OutputDebugString((wchar_t*)s.utf16()); + OutputDebugString((wchar_t*)message.utf16()); staticCriticalSection.unlock(); } Q_CORE_EXPORT void qWinMsgHandler(QtMsgType t, const char *str) { QMessageLogContext emptyContext; - qWinMessageHandler(t, emptyContext, str); + qWinMessageHandler(t, emptyContext, QString::fromLocal8Bit(str)); } /***************************************************************************** @@ -189,7 +188,7 @@ void qWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdParam, usingWinMain = true; // Install default debug handler - qInstallMsgHandler(qWinMsgHandler); + qInstallMessageHandler(qWinMessageHandler); // Create command line argv = qWinCmdLine<char>(cmdParam, int(strlen(cmdParam)), argc); diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 809d3bf589..2756dd5241 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -82,7 +82,7 @@ namespace { struct DefinedTypesFilter { template<typename T> struct Acceptor { - static const bool IsAccepted = QtMetaTypePrivate::TypeDefinition<T>::IsAvailable && QTypeModuleInfo<T>::IsCore; + static const bool IsAccepted = QtMetaTypePrivate::TypeDefinition<T>::IsAvailable && QModulesPrivate::QTypeModuleInfo<T>::IsCore; }; }; } // namespace @@ -1109,11 +1109,11 @@ class TypeCreator { struct CreatorImpl<T, /* IsAcceptedType = */ false> { static void *Create(const int type, const void *copy) { - if (QTypeModuleInfo<T>::IsGui) { + if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) { if (Q_LIKELY(qMetaTypeGuiHelper)) return qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].creator(copy); } - if (QTypeModuleInfo<T>::IsWidget) { + if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) { if (Q_LIKELY(qMetaTypeWidgetsHelper)) return qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].creator(copy); } @@ -1171,12 +1171,12 @@ class TypeDestroyer { struct DestroyerImpl<T, /* IsAcceptedType = */ false> { static void Destroy(const int type, void *where) { - if (QTypeModuleInfo<T>::IsGui) { + if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) { if (Q_LIKELY(qMetaTypeGuiHelper)) qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].deleter(where); return; } - if (QTypeModuleInfo<T>::IsWidget) { + if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) { if (Q_LIKELY(qMetaTypeWidgetsHelper)) qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].deleter(where); return; @@ -1237,10 +1237,10 @@ class TypeConstructor { struct ConstructorImpl<T, /* IsAcceptedType = */ false> { static void *Construct(const int type, void *where, const void *copy) { - if (QTypeModuleInfo<T>::IsGui) + if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].constructor(where, copy) : 0; - if (QTypeModuleInfo<T>::IsWidget) + if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].constructor(where, copy) : 0; // This point can be reached only for known types that definition is not available, for example @@ -1325,12 +1325,12 @@ class TypeDestructor { struct DestructorImpl<T, /* IsAcceptedType = */ false> { static void Destruct(const int type, void *where) { - if (QTypeModuleInfo<T>::IsGui) { + if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) { if (Q_LIKELY(qMetaTypeGuiHelper)) qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].destructor(where); return; } - if (QTypeModuleInfo<T>::IsWidget) { + if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) { if (Q_LIKELY(qMetaTypeWidgetsHelper)) qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].destructor(where); return; @@ -1398,10 +1398,10 @@ class SizeOf { struct SizeOfImpl<T, /* IsAcceptedType = */ false> { static int Size(const int type) { - if (QTypeModuleInfo<T>::IsGui) + if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].size : 0; - if (QTypeModuleInfo<T>::IsWidget) + if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].size : 0; // This point can be reached only for known types that definition is not available, for example @@ -1466,10 +1466,10 @@ class Flags { static quint32 Flags(const int type) { - if (QTypeModuleInfo<T>::IsGui) + if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].flags : 0; - if (QTypeModuleInfo<T>::IsWidget) + if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].flags : 0; // This point can be reached only for known types that definition is not available, for example @@ -1649,12 +1649,12 @@ class TypeInfo { { TypeInfoImpl(const uint type, QMetaTypeInterface &info) { - if (QTypeModuleInfo<T>::IsGui) { + if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) { if (Q_LIKELY(qMetaTypeGuiHelper)) info = qMetaTypeGuiHelper[type - QMetaType::FirstGuiType]; return; } - if (QTypeModuleInfo<T>::IsWidget) { + if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) { if (Q_LIKELY(qMetaTypeWidgetsHelper)) info = qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType]; return; @@ -1671,7 +1671,6 @@ public: } template<typename T> void delegate(const T*) { TypeInfoImpl<T>(m_type, info); } - void delegate(const void*) {} void delegate(const QMetaTypeSwitcher::UnknownType*) {} void delegate(const QMetaTypeSwitcher::NotBuiltinType*) { customTypeInfo(m_type); } private: @@ -1693,7 +1692,7 @@ QMetaType QMetaType::typeInfo(const int type) { TypeInfo typeInfo(type); QMetaTypeSwitcher::switcher<void>(typeInfo, type, 0); - return typeInfo.info.creator || type == Void ? QMetaType(QMetaType::NoExtensionFlags + return typeInfo.info.creator ? QMetaType(QMetaType::NoExtensionFlags , static_cast<const QMetaTypeInterface *>(0) // typeInfo::info is a temporary variable, we can't return address of it. , typeInfo.info.creator , typeInfo.info.deleter diff --git a/src/corelib/kernel/qmetatype_p.h b/src/corelib/kernel/qmetatype_p.h index 985cf71974..b593489963 100644 --- a/src/corelib/kernel/qmetatype_p.h +++ b/src/corelib/kernel/qmetatype_p.h @@ -70,7 +70,6 @@ static inline int moduleForType(const uint typeId) return Widgets; return Unknown; } -} template <typename T> class QTypeModuleInfo @@ -114,6 +113,7 @@ QT_FOR_EACH_STATIC_CORE_CLASS(QT_DECLARE_CORE_MODULE_TYPES_ITER) QT_FOR_EACH_STATIC_CORE_TEMPLATE(QT_DECLARE_CORE_MODULE_TYPES_ITER) QT_FOR_EACH_STATIC_GUI_CLASS(QT_DECLARE_GUI_MODULE_TYPES_ITER) QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_DECLARE_WIDGETS_MODULE_TYPES_ITER) +} // namespace QModulesPrivate #undef QT_DECLARE_CORE_MODULE_TYPES_ITER #undef QT_DECLARE_GUI_MODULE_TYPES_ITER diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 5e24ffebd1..7ccc5e500e 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -103,7 +103,7 @@ namespace { struct CoreTypesFilter { template<typename T> struct Acceptor { - static const bool IsAccepted = QTypeModuleInfo<T>::IsCore && QtMetaTypePrivate::TypeDefinition<T>::IsAvailable; + static const bool IsAccepted = QModulesPrivate::QTypeModuleInfo<T>::IsCore && QtMetaTypePrivate::TypeDefinition<T>::IsAvailable; }; }; } // annonymous @@ -1353,19 +1353,6 @@ QVariant::QVariant(const char *val) Constructs a new variant with the regular expression value \a re. */ -/*! \since 4.2 - \fn QVariant::QVariant(Qt::GlobalColor color) - - Constructs a new variant of type QVariant::Color and initializes - it with \a color. - - This is a convenience constructor that allows \c{QVariant(Qt::blue);} - to create a valid QVariant storing a QColor. - - Note: This constructor will assert if the application does not link - to the Qt GUI library. - */ - QVariant::QVariant(Type type) { create(type, 0); } QVariant::QVariant(int typeId, const void *copy) @@ -1447,7 +1434,6 @@ QVariant::QVariant(const QRegExp ®Exp) { d.is_null = false; d.type = RegExp; QVariant::QVariant(const QRegularExpression &re) { d.is_null = false; d.type = QMetaType::QRegularExpression; v_construct<QRegularExpression>(&d, re); } #endif // QT_BOOTSTRAPPED #endif // QT_NO_REGEXP -QVariant::QVariant(Qt::GlobalColor color) { create(62, &color); } /*! Returns the storage type of the value stored in the variant. @@ -1586,9 +1572,6 @@ void QVariant::clear() */ const char *QVariant::typeToName(int typeId) { - if (typeId == Invalid) - return 0; - return QMetaType::typeName(typeId); } @@ -1602,9 +1585,6 @@ const char *QVariant::typeToName(int typeId) */ QVariant::Type QVariant::nameToType(const char *name) { - if (!name || !*name) - return Invalid; - int metaType = QMetaType::type(name); return metaType <= int(UserType) ? QVariant::Type(metaType) : UserType; } diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index fb0e059f45..cd8ac9823d 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -248,7 +248,6 @@ class Q_CORE_EXPORT QVariant QVariant(const QUrl &url); QVariant(const QEasingCurve &easing); #endif - QVariant(Qt::GlobalColor color); QVariant& operator=(const QVariant &other); #ifdef Q_COMPILER_RVALUE_REFS diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index 45be63aa9b..0f5ebcfb18 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -169,13 +169,14 @@ struct QByteArrayDataPtr #if defined(Q_COMPILER_LAMBDA) # define QByteArrayLiteral(str) \ - ([]() -> QByteArrayDataPtr { \ + ([]() -> QByteArray { \ enum { Size = sizeof(str) - 1 }; \ static const QStaticByteArrayData<Size> qbytearray_literal = { \ Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER(Size), \ str }; \ QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; \ - return holder; \ + const QByteArray ba(holder); \ + return ba; \ }()) \ /**/ @@ -185,22 +186,22 @@ struct QByteArrayDataPtr // To do that, we need the __extension__ {( )} trick which only GCC supports # define QByteArrayLiteral(str) \ - __extension__ ({ \ + QByteArray(__extension__ ({ \ enum { Size = sizeof(str) - 1 }; \ static const QStaticByteArrayData<Size> qbytearray_literal = { \ Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER(Size), \ str }; \ QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; \ holder; \ - }) \ + })) \ /**/ #endif #ifndef QByteArrayLiteral -// no lambdas, not GCC, use const char * instead +// no lambdas, not GCC, just return a temporary QByteArray -# define QByteArrayLiteral(str) (str) +# define QByteArrayLiteral(str) QByteArray(str, sizeof(str) - 1) #endif class Q_CORE_EXPORT QByteArray diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 39747aa3e9..04626742bd 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -796,9 +796,6 @@ const QString::Null QString::null = { }; \sa split() */ -const QStaticStringData<1> QString::shared_null = { Q_STATIC_STRING_DATA_HEADER_INITIALIZER(0), { 0 } }; -const QStaticStringData<1> QString::shared_empty = { Q_STATIC_STRING_DATA_HEADER_INITIALIZER(0), { 0 } }; - /*! \typedef QString::ConstIterator Qt-style synonym for QString::const_iterator. @@ -1039,7 +1036,7 @@ int QString::toUcs4_helper(const ushort *uc, int length, uint *out) QString::QString(const QChar *unicode, int size) { if (!unicode) { - d = shared_null.data_ptr(); + d = Data::sharedNull(); } else { if (size < 0) { size = 0; @@ -1047,15 +1044,11 @@ QString::QString(const QChar *unicode, int size) ++size; } if (!size) { - d = shared_empty.data_ptr(); + d = Data::allocate(0); } else { - d = (Data*) ::malloc(sizeof(Data) + (uint(size) + 1u) * sizeof(QChar)); + d = Data::allocate(size + 1); Q_CHECK_PTR(d); - d->ref.initializeOwned(); d->size = size; - d->alloc = uint(size) + 1u; - d->capacityReserved = false; - d->offset = sizeof(QStringData); memcpy(d->data(), unicode, size * sizeof(QChar)); d->data()[size] = '\0'; } @@ -1071,15 +1064,11 @@ QString::QString(const QChar *unicode, int size) QString::QString(int size, QChar ch) { if (size <= 0) { - d = shared_empty.data_ptr(); + d = Data::allocate(0); } else { - d = (Data*) ::malloc(sizeof(Data) + (uint(size) + 1u) * sizeof(QChar)); + d = Data::allocate(size + 1); Q_CHECK_PTR(d); - d->ref.initializeOwned(); d->size = size; - d->alloc = uint(size) + 1u; - d->capacityReserved = false; - d->offset = sizeof(QStringData); d->data()[size] = '\0'; ushort *i = d->data() + size; ushort *b = d->data(); @@ -1097,13 +1086,9 @@ QString::QString(int size, QChar ch) */ QString::QString(int size, Qt::Initialization) { - d = (Data*) ::malloc(sizeof(Data) + (uint(size) + 1u) * sizeof(QChar)); + d = Data::allocate(size + 1); Q_CHECK_PTR(d); - d->ref.initializeOwned(); d->size = size; - d->alloc = uint(size) + 1u; - d->capacityReserved = false; - d->offset = sizeof(QStringData); d->data()[size] = '\0'; } @@ -1119,13 +1104,9 @@ QString::QString(int size, Qt::Initialization) */ QString::QString(QChar ch) { - d = (Data *) ::malloc(sizeof(Data) + 2*sizeof(QChar)); + d = Data::allocate(2); Q_CHECK_PTR(d); - d->ref.initializeOwned(); d->size = 1; - d->alloc = 2u; - d->capacityReserved = false; - d->offset = sizeof(QStringData); d->data()[0] = ch.unicode(); d->data()[1] = '\0'; } @@ -1182,12 +1163,6 @@ QString::QString(QChar ch) \internal */ -// ### Qt 5: rename freeData() to avoid confusion. See task 197625. -void QString::free(Data *d) -{ - ::free(d); -} - /*! Sets the size of the string to \a size characters. @@ -1229,9 +1204,9 @@ void QString::resize(int size) } if (size == 0 && !d->capacityReserved) { - Data *x = shared_empty.data_ptr(); + Data *x = Data::allocate(0); if (!d->ref.deref()) - QString::free(d); + Data::deallocate(d); d = x; } else { if (d->ref.isShared() || uint(size) + 1u > d->alloc @@ -1301,17 +1276,14 @@ void QString::reallocData(uint alloc, bool grow) alloc = qAllocMore(alloc * sizeof(QChar), sizeof(Data)) / sizeof(QChar); if (d->ref.isShared() || IS_RAW_DATA(d)) { - Data *x = static_cast<Data *>(::malloc(sizeof(Data) + alloc * sizeof(QChar))); + Data::AllocationOptions allocOptions(d->capacityReserved ? Data::CapacityReserved : 0); + Data *x = Data::allocate(alloc, allocOptions); Q_CHECK_PTR(x); - x->ref.initializeOwned(); x->size = qMin(int(alloc) - 1, d->size); - x->alloc = alloc; - x->capacityReserved = d->capacityReserved; - x->offset = sizeof(QStringData); ::memcpy(x->data(), d->data(), x->size * sizeof(QChar)); x->data()[x->size] = 0; if (!d->ref.deref()) - QString::free(d); + Data::deallocate(d); d = x; } else { Data *p = static_cast<Data *>(::realloc(d, sizeof(Data) + alloc * sizeof(QChar))); @@ -1351,7 +1323,7 @@ QString &QString::operator=(const QString &other) { other.d->ref.ref(); if (!d->ref.deref()) - QString::free(d); + Data::deallocate(d); d = other.d; return *this; } @@ -1521,8 +1493,8 @@ QString& QString::insert(int i, QChar ch) */ QString &QString::append(const QString &str) { - if (str.d != &shared_null.str) { - if (d == &shared_null.str) { + if (str.d != Data::sharedNull()) { + if (d == Data::sharedNull()) { operator=(str); } else { if (d->ref.isShared() || uint(d->size + str.d->size) + 1u > d->alloc) @@ -4049,19 +4021,15 @@ QString::Data *QString::fromLatin1_helper(const char *str, int size) { Data *d; if (!str) { - d = shared_null.data_ptr(); + d = Data::sharedNull(); } else if (size == 0 || (!*str && size < 0)) { - d = shared_empty.data_ptr(); + d = Data::allocate(0); } else { if (size < 0) size = qstrlen(str); - d = static_cast<Data *>(::malloc(sizeof(Data) + (uint(size) + 1u) * sizeof(QChar))); + d = Data::allocate(size + 1); Q_CHECK_PTR(d); - d->ref.initializeOwned(); d->size = size; - d->alloc = uint(size) + 1u; - d->capacityReserved = false; - d->offset = sizeof(QStringData); d->data()[size] = '\0'; ushort *dst = d->data(); /* SIMD: @@ -4127,7 +4095,7 @@ QString QString::fromLocal8Bit_helper(const char *str, int size) if (!str) return QString(); if (size == 0 || (!*str && size < 0)) { - QStringDataPtr empty = { shared_empty.data_ptr() }; + QStringDataPtr empty = { Data::allocate(0) }; return QString(empty); } #if !defined(QT_NO_TEXTCODEC) @@ -4296,7 +4264,7 @@ QString QString::simplified() const break; if (++from == fromEnd) { // All-whitespace string - QStringDataPtr empty = { shared_empty.data_ptr() }; + QStringDataPtr empty = { Data::allocate(0) }; return QString(empty); } } @@ -4391,7 +4359,7 @@ QString QString::trimmed() const } int l = end - start + 1; if (l <= 0) { - QStringDataPtr empty = { shared_empty.data_ptr() }; + QStringDataPtr empty = { Data::allocate(0) }; return QString(empty); } return QString(s + start, l); @@ -7424,17 +7392,12 @@ QString QString::fromRawData(const QChar *unicode, int size) { Data *x; if (!unicode) { - x = shared_null.data_ptr(); + x = Data::sharedNull(); } else if (!size) { - x = shared_empty.data_ptr(); + x = Data::allocate(0); } else { - x = static_cast<Data *>(::malloc(sizeof(Data))); + x = Data::fromRawData(reinterpret_cast<const ushort *>(unicode), size); Q_CHECK_PTR(x); - x->ref.initializeOwned(); - x->size = size; - x->alloc = 0; - x->capacityReserved = false; - x->offset = reinterpret_cast<const char *>(unicode) - reinterpret_cast<char *>(x); } QStringDataPtr dataPtr = { x }; return QString(dataPtr); diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index 5b6869d111..bbfb31aef3 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -69,17 +69,7 @@ class QLatin1String; class QStringRef; template <typename T> class QVector; -struct QStringData { - QtPrivate::RefCount ref; - int size; - uint alloc : 31; - uint capacityReserved : 1; - - qptrdiff offset; - - inline ushort *data() { return reinterpret_cast<ushort *>(reinterpret_cast<char *>(this) + offset); } - inline const ushort *data() const { return reinterpret_cast<const ushort *>(reinterpret_cast<const char *>(this) + offset); } -}; +typedef QTypedArrayData<ushort> QStringData; #if defined(Q_COMPILER_UNICODE_STRINGS) @@ -113,13 +103,14 @@ Q_STATIC_ASSERT_X(sizeof(qunicodechar) == 2, # if defined(Q_COMPILER_LAMBDA) # define QStringLiteral(str) \ - ([]() -> QStringDataPtr { \ + ([]() -> QString { \ enum { Size = sizeof(QT_UNICODE_LITERAL(str))/2 - 1 }; \ static const QStaticStringData<Size> qstring_literal = { \ Q_STATIC_STRING_DATA_HEADER_INITIALIZER(Size), \ QT_UNICODE_LITERAL(str) }; \ QStringDataPtr holder = { qstring_literal.data_ptr() }; \ - return holder; \ + const QString s(holder); \ + return s; \ }()) \ /**/ @@ -129,14 +120,14 @@ Q_STATIC_ASSERT_X(sizeof(qunicodechar) == 2, // To do that, we need the __extension__ {( )} trick which only GCC supports # define QStringLiteral(str) \ - __extension__ ({ \ + QString(__extension__ ({ \ enum { Size = sizeof(QT_UNICODE_LITERAL(str))/2 - 1 }; \ static const QStaticStringData<Size> qstring_literal = { \ Q_STATIC_STRING_DATA_HEADER_INITIALIZER(Size), \ QT_UNICODE_LITERAL(str) }; \ QStringDataPtr holder = { qstring_literal.data_ptr() }; \ holder; \ - }) \ + })) \ /**/ # endif @@ -144,9 +135,10 @@ Q_STATIC_ASSERT_X(sizeof(qunicodechar) == 2, #ifndef QStringLiteral // no lambdas, not GCC, or GCC in C++98 mode with 4-byte wchar_t -// fallback, uses QLatin1String as next best options +// fallback, return a temporary QString +// source code is assumed to be encoded in UTF-8 -# define QStringLiteral(str) QLatin1String(str) +# define QStringLiteral(str) QString::fromUtf8(str, sizeof(str) - 1) #endif #define Q_STATIC_STRING_DATA_HEADER_INITIALIZER_WITH_OFFSET(size, offset) \ @@ -160,13 +152,13 @@ Q_STATIC_ASSERT_X(sizeof(qunicodechar) == 2, template <int N> struct QStaticStringData { - QStringData str; + QArrayData str; qunicodechar data[N + 1]; QStringData *data_ptr() const { Q_ASSERT(str.ref.isStatic()); - return const_cast<QStringData *>(&str); + return const_cast<QStringData *>(static_cast<const QStringData*>(&str)); } }; @@ -623,9 +615,9 @@ public: // compatibility struct Null { }; static const Null null; - inline QString(const Null &): d(shared_null.data_ptr()) {} + inline QString(const Null &): d(Data::sharedNull()) {} inline QString &operator=(const Null &) { *this = QString(); return *this; } - inline bool isNull() const { return d == &shared_null.str; } + inline bool isNull() const { return d == Data::sharedNull(); } bool isSimpleText() const; @@ -644,11 +636,8 @@ private: QString &operator=(const QByteArray &a); #endif - static const QStaticStringData<1> shared_null; - static const QStaticStringData<1> shared_empty; Data *d; - static void free(Data *); void reallocData(uint alloc, bool grow = false); void expand(int i); void updateProperties() const; @@ -918,8 +907,8 @@ inline void QCharRef::setRow(uchar arow) { QChar(*this).setRow(arow); } inline void QCharRef::setCell(uchar acell) { QChar(*this).setCell(acell); } -inline QString::QString() : d(shared_null.data_ptr()) {} -inline QString::~QString() { if (!d->ref.deref()) free(d); } +inline QString::QString() : d(Data::sharedNull()) {} +inline QString::~QString() { if (!d->ref.deref()) Data::deallocate(d); } inline void QString::reserve(int asize) { @@ -1194,7 +1183,7 @@ public: inline const QChar *unicode() const { if (!m_string) - return reinterpret_cast<const QChar *>(QString::shared_null.str.data()); + return reinterpret_cast<const QChar *>(QString::Data::sharedNull()->data()); return m_string->unicode() + m_position; } inline const QChar *data() const { return unicode(); } diff --git a/src/corelib/tools/qstringbuilder.h b/src/corelib/tools/qstringbuilder.h index 9a1fd6949b..9b1cd1ee7e 100644 --- a/src/corelib/tools/qstringbuilder.h +++ b/src/corelib/tools/qstringbuilder.h @@ -253,19 +253,6 @@ template <> struct QConcatenable<QString> : private QAbstractConcatenable } }; -template <> struct QConcatenable<QStringDataPtr> : private QAbstractConcatenable -{ - typedef QStringDataPtr type; - typedef QString ConvertTo; - enum { ExactSize = true }; - static int size(const type &a) { return a.ptr->size; } - static inline void appendTo(const type &a, QChar *&out) - { - memcpy(out, reinterpret_cast<const char*>(a.ptr->data()), sizeof(QChar) * a.ptr->size); - out += a.ptr->size; - } -}; - template <> struct QConcatenable<QStringRef> : private QAbstractConcatenable { typedef QStringRef type; @@ -358,24 +345,6 @@ template <> struct QConcatenable<QByteArray> : private QAbstractConcatenable } }; -template <> struct QConcatenable<QByteArrayDataPtr> : private QAbstractConcatenable -{ - typedef QByteArrayDataPtr type; - typedef QByteArray ConvertTo; - enum { ExactSize = false }; - static int size(const type &ba) { return ba.ptr->size; } -#ifndef QT_NO_CAST_FROM_ASCII - static inline QT_ASCII_CAST_WARN void appendTo(const type &a, QChar *&out) - { - QAbstractConcatenable::convertFromAscii(a.ptr->data(), a.ptr->size, out); - } -#endif - static inline void appendTo(const type &ba, char *&out) - { - ::memcpy(out, ba.ptr->data(), ba.ptr->size); - out += ba.ptr->size; - } -}; template <typename A, typename B> struct QConcatenable< QStringBuilder<A, B> > diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 7ac5538d6e..266eb143e5 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -2784,19 +2784,14 @@ QShowEvent::~QShowEvent() \note This class is currently supported for Mac OS X only. */ -QFileOpenEventPrivate::~QFileOpenEventPrivate() -{ -} - /*! \internal Constructs a file open event for the given \a file. */ QFileOpenEvent::QFileOpenEvent(const QString &file) - : QEvent(FileOpen), f(file) + : QEvent(FileOpen), f(file), m_url(QUrl::fromLocalFile(file)) { - d = reinterpret_cast<QEventPrivate *>(new QFileOpenEventPrivate(QUrl::fromLocalFile(file))); } /*! @@ -2805,10 +2800,8 @@ QFileOpenEvent::QFileOpenEvent(const QString &file) Constructs a file open event for the given \a url. */ QFileOpenEvent::QFileOpenEvent(const QUrl &url) - : QEvent(FileOpen) + : QEvent(FileOpen), f(url.toLocalFile()), m_url(url) { - d = reinterpret_cast<QEventPrivate *>(new QFileOpenEventPrivate(url)); - f = url.toLocalFile(); } @@ -2816,7 +2809,6 @@ QFileOpenEvent::QFileOpenEvent(const QUrl &url) */ QFileOpenEvent::~QFileOpenEvent() { - delete reinterpret_cast<QFileOpenEventPrivate *>(d); } /*! @@ -2832,10 +2824,6 @@ QFileOpenEvent::~QFileOpenEvent() \since 4.6 */ -QUrl QFileOpenEvent::url() const -{ - return reinterpret_cast<const QFileOpenEventPrivate *>(d)->url; -} /*! \fn bool QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const @@ -3263,25 +3251,16 @@ QDebug operator<<(QDebug dbg, const QEvent *e) { /*! \internal */ -QWindowStateChangeEvent::QWindowStateChangeEvent(Qt::WindowStates s) - : QEvent(WindowStateChange), ostate(s) -{ -} - -/*! \internal - */ QWindowStateChangeEvent::QWindowStateChangeEvent(Qt::WindowStates s, bool isOverride) - : QEvent(WindowStateChange), ostate(s) + : QEvent(WindowStateChange), ostate(s), m_override(isOverride) { - if (isOverride) - d = (QEventPrivate*)(this); } /*! \internal */ bool QWindowStateChangeEvent::isOverride() const { - return (d != 0); + return m_override; } /*! \internal @@ -4037,10 +4016,8 @@ void QTouchEvent::TouchPoint::setFlags(InfoFlags flags) The \a startPos is the position of a touch or mouse event that started the scrolling. */ QScrollPrepareEvent::QScrollPrepareEvent(const QPointF &startPos) - : QEvent(QEvent::ScrollPrepare) + : QEvent(QEvent::ScrollPrepare), m_target(0), m_startPos(startPos) { - d = reinterpret_cast<QEventPrivate *>(new QScrollPrepareEventPrivate()); - d_func()->startPos = startPos; } /*! @@ -4048,7 +4025,6 @@ QScrollPrepareEvent::QScrollPrepareEvent(const QPointF &startPos) */ QScrollPrepareEvent::~QScrollPrepareEvent() { - delete reinterpret_cast<QScrollPrepareEventPrivate *>(d); } /*! @@ -4056,7 +4032,7 @@ QScrollPrepareEvent::~QScrollPrepareEvent() */ QPointF QScrollPrepareEvent::startPos() const { - return d_func()->startPos; + return m_startPos; } /*! @@ -4066,7 +4042,7 @@ QPointF QScrollPrepareEvent::startPos() const */ QSizeF QScrollPrepareEvent::viewportSize() const { - return d_func()->viewportSize; + return m_viewportSize; } /*! @@ -4074,7 +4050,7 @@ QSizeF QScrollPrepareEvent::viewportSize() const */ QRectF QScrollPrepareEvent::contentPosRange() const { - return d_func()->contentPosRange; + return m_contentPosRange; } /*! @@ -4082,7 +4058,7 @@ QRectF QScrollPrepareEvent::contentPosRange() const */ QPointF QScrollPrepareEvent::contentPos() const { - return d_func()->contentPos; + return m_contentPos; } @@ -4093,7 +4069,7 @@ QPointF QScrollPrepareEvent::contentPos() const */ void QScrollPrepareEvent::setViewportSize(const QSizeF &size) { - d_func()->viewportSize = size; + m_viewportSize = size; } /*! @@ -4103,7 +4079,7 @@ void QScrollPrepareEvent::setViewportSize(const QSizeF &size) */ void QScrollPrepareEvent::setContentPosRange(const QRectF &rect) { - d_func()->contentPosRange = rect; + m_contentPosRange = rect; } /*! @@ -4113,27 +4089,11 @@ void QScrollPrepareEvent::setContentPosRange(const QRectF &rect) */ void QScrollPrepareEvent::setContentPos(const QPointF &pos) { - d_func()->contentPos = pos; + m_contentPos = pos; } /*! - \internal -*/ -QScrollPrepareEventPrivate *QScrollPrepareEvent::d_func() -{ - return reinterpret_cast<QScrollPrepareEventPrivate *>(d); -} - -/*! - \internal -*/ -const QScrollPrepareEventPrivate *QScrollPrepareEvent::d_func() const -{ - return reinterpret_cast<const QScrollPrepareEventPrivate *>(d); -} - -/*! \class QScrollEvent \since 4.8 \ingroup events @@ -4170,12 +4130,8 @@ const QScrollPrepareEventPrivate *QScrollPrepareEvent::d_func() const event is the first one, the last one or some event in between. */ QScrollEvent::QScrollEvent(const QPointF &contentPos, const QPointF &overshootDistance, ScrollState scrollState) - : QEvent(QEvent::Scroll) + : QEvent(QEvent::Scroll), m_contentPos(contentPos), m_overshoot(overshootDistance), m_state(scrollState) { - d = reinterpret_cast<QEventPrivate *>(new QScrollEventPrivate()); - d_func()->contentPos = contentPos; - d_func()->overshoot= overshootDistance; - d_func()->state = scrollState; } /*! @@ -4183,7 +4139,6 @@ QScrollEvent::QScrollEvent(const QPointF &contentPos, const QPointF &overshootDi */ QScrollEvent::~QScrollEvent() { - delete reinterpret_cast<QScrollEventPrivate *>(d); } /*! @@ -4191,7 +4146,7 @@ QScrollEvent::~QScrollEvent() */ QPointF QScrollEvent::contentPos() const { - return d_func()->contentPos; + return m_contentPos; } /*! @@ -4202,7 +4157,7 @@ QPointF QScrollEvent::contentPos() const */ QPointF QScrollEvent::overshootDistance() const { - return d_func()->overshoot; + return m_overshoot; } /*! @@ -4215,23 +4170,7 @@ QPointF QScrollEvent::overshootDistance() const */ QScrollEvent::ScrollState QScrollEvent::scrollState() const { - return d_func()->state; -} - -/*! - \internal -*/ -QScrollEventPrivate *QScrollEvent::d_func() -{ - return reinterpret_cast<QScrollEventPrivate *>(d); -} - -/*! - \internal -*/ -const QScrollEventPrivate *QScrollEvent::d_func() const -{ - return reinterpret_cast<const QScrollEventPrivate *>(d); + return m_state; } /*! @@ -4239,11 +4178,8 @@ const QScrollEventPrivate *QScrollEvent::d_func() const \a orientation is the new orientation of the screen. */ QScreenOrientationChangeEvent::QScreenOrientationChangeEvent(QScreen *screen, Qt::ScreenOrientation screenOrientation) - : QEvent(QEvent::OrientationChange) + : QEvent(QEvent::OrientationChange), m_screen(screen), m_orientation(screenOrientation) { - d = reinterpret_cast<QEventPrivate *>(new QScreenOrientationChangeEventPrivate()); - d_func()->screen = screen; - d_func()->orientation = screenOrientation; } /*! @@ -4251,7 +4187,6 @@ QScreenOrientationChangeEvent::QScreenOrientationChangeEvent(QScreen *screen, Qt */ QScreenOrientationChangeEvent::~QScreenOrientationChangeEvent() { - delete reinterpret_cast<QScrollEventPrivate *>(d); } /*! @@ -4259,7 +4194,7 @@ QScreenOrientationChangeEvent::~QScreenOrientationChangeEvent() */ QScreen *QScreenOrientationChangeEvent::screen() const { - return d_func()->screen; + return m_screen; } /*! @@ -4267,23 +4202,7 @@ QScreen *QScreenOrientationChangeEvent::screen() const */ Qt::ScreenOrientation QScreenOrientationChangeEvent::orientation() const { - return d_func()->orientation; -} - -/*! - \internal -*/ -QScreenOrientationChangeEventPrivate *QScreenOrientationChangeEvent::d_func() -{ - return reinterpret_cast<QScreenOrientationChangeEventPrivate *>(d); -} - -/*! - \internal -*/ -const QScreenOrientationChangeEventPrivate *QScreenOrientationChangeEvent::d_func() const -{ - return reinterpret_cast<const QScreenOrientationChangeEventPrivate *>(d); + return m_orientation; } QT_END_NAMESPACE diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index f611fe4ab7..96e630ed0a 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -53,6 +53,7 @@ #include <QtCore/qmap.h> #include <QtCore/qvector.h> #include <QtCore/qset.h> +#include <QtCore/qurl.h> #include <QtCore/qfile.h> #include <QtGui/qvector2d.h> #include <QtGui/qtouchdevice.h> @@ -647,10 +648,11 @@ public: ~QFileOpenEvent(); inline QString file() const { return f; } - QUrl url() const; + QUrl url() const { return m_url; } bool openFile(QFile &file, QIODevice::OpenMode flags) const; private: QString f; + QUrl m_url; }; #ifndef QT_NO_TOOLBAR @@ -686,8 +688,7 @@ protected: class Q_GUI_EXPORT QWindowStateChangeEvent: public QEvent { public: - explicit QWindowStateChangeEvent(Qt::WindowStates aOldState); - QWindowStateChangeEvent(Qt::WindowStates aOldState, bool isOverride); + explicit QWindowStateChangeEvent(Qt::WindowStates aOldState, bool isOverride = false); ~QWindowStateChangeEvent(); inline Qt::WindowStates oldState() const { return ostate; } @@ -695,6 +696,7 @@ public: private: Qt::WindowStates ostate; + bool m_override; }; #ifndef QT_NO_DEBUG_STREAM @@ -837,7 +839,6 @@ protected: Q_DECLARE_TYPEINFO(QTouchEvent::TouchPoint, Q_MOVABLE_TYPE); Q_DECLARE_OPERATORS_FOR_FLAGS(QTouchEvent::TouchPoint::InfoFlags) -class QScrollPrepareEventPrivate; class Q_GUI_EXPORT QScrollPrepareEvent : public QEvent { public: @@ -855,12 +856,14 @@ public: void setContentPos(const QPointF &pos); private: - QScrollPrepareEventPrivate *d_func(); - const QScrollPrepareEventPrivate *d_func() const; + QObject* m_target; + QPointF m_startPos; + QSizeF m_viewportSize; + QRectF m_contentPosRange; + QPointF m_contentPos; }; -class QScrollEventPrivate; class Q_GUI_EXPORT QScrollEvent : public QEvent { public: @@ -879,11 +882,11 @@ public: ScrollState scrollState() const; private: - QScrollEventPrivate *d_func(); - const QScrollEventPrivate *d_func() const; + QPointF m_contentPos; + QPointF m_overshoot; + QScrollEvent::ScrollState m_state; }; -class QScreenOrientationChangeEventPrivate; class Q_GUI_EXPORT QScreenOrientationChangeEvent : public QEvent { public: @@ -894,8 +897,8 @@ public: Qt::ScreenOrientation orientation() const; private: - QScreenOrientationChangeEventPrivate *d_func(); - const QScreenOrientationChangeEventPrivate *d_func() const; + QScreen *m_screen; + Qt::ScreenOrientation m_orientation; }; QT_END_NAMESPACE diff --git a/src/gui/kernel/qevent_p.h b/src/gui/kernel/qevent_p.h index 18a13b73f5..4bf7dda8d2 100644 --- a/src/gui/kernel/qevent_p.h +++ b/src/gui/kernel/qevent_p.h @@ -92,57 +92,6 @@ public: QVector<QPointF> rawScreenPositions; }; -class QFileOpenEventPrivate -{ -public: - inline QFileOpenEventPrivate(const QUrl &url) - : url(url) - { - } - ~QFileOpenEventPrivate(); - - QUrl url; -}; - - -class QScrollPrepareEventPrivate -{ -public: - inline QScrollPrepareEventPrivate() - : target(0) - { - } - - QObject* target; - QPointF startPos; - QSizeF viewportSize; - QRectF contentPosRange; - QPointF contentPos; -}; - -class QScrollEventPrivate -{ -public: - inline QScrollEventPrivate() - { - } - - QPointF contentPos; - QPointF overshoot; - QScrollEvent::ScrollState state; -}; - -class QScreenOrientationChangeEventPrivate -{ -public: - inline QScreenOrientationChangeEventPrivate() - { - } - - QScreen *screen; - Qt::ScreenOrientation orientation; -}; - QT_END_NAMESPACE #endif // QEVENT_P_H diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index e7c2b60305..8fd4d4a2b3 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -2154,12 +2154,20 @@ bool QGuiApplication::desktopSettingsAware() return QGuiApplicationPrivate::obey_desktop_settings; } -QInputMethod *QGuiApplication::inputMethod() const +/*! + returns the input method. + + The input method returns properties about the state and position of + the virtual keyboard. It also provides information about the position of the + current focused input element. + + \sa QInputPanel + */ +QInputMethod *QGuiApplication::inputMethod() { - Q_D(const QGuiApplication); - if (!d->inputMethod) - const_cast<QGuiApplicationPrivate *>(d)->inputMethod = new QInputMethod(); - return d->inputMethod; + if (!qGuiApp->d_func()->inputMethod) + qGuiApp->d_func()->inputMethod = new QInputMethod(); + return qGuiApp->d_func()->inputMethod; } /*! diff --git a/src/gui/kernel/qguiapplication.h b/src/gui/kernel/qguiapplication.h index a741d13eb3..9aad39ed47 100644 --- a/src/gui/kernel/qguiapplication.h +++ b/src/gui/kernel/qguiapplication.h @@ -133,7 +133,7 @@ public: #if QT_DEPRECATED_SINCE(5, 0) QT_DEPRECATED QInputPanel *inputPanel() const { return inputMethod(); } #endif - QInputMethod *inputMethod() const; + static QInputMethod *inputMethod(); static QPlatformNativeInterface *platformNativeInterface(); diff --git a/src/gui/kernel/qguivariant.cpp b/src/gui/kernel/qguivariant.cpp index 436688a295..9d1294d588 100644 --- a/src/gui/kernel/qguivariant.cpp +++ b/src/gui/kernel/qguivariant.cpp @@ -101,22 +101,13 @@ namespace { struct GuiTypesFilter { template<typename T> struct Acceptor { - static const bool IsAccepted = QTypeModuleInfo<T>::IsGui && QtMetaTypePrivate::TypeDefinition<T>::IsAvailable; + static const bool IsAccepted = QModulesPrivate::QTypeModuleInfo<T>::IsGui && QtMetaTypePrivate::TypeDefinition<T>::IsAvailable; }; }; static void construct(QVariant::Private *x, const void *copy) { const int type = x->type; - if (Q_UNLIKELY(type == 62)) { - // small 'trick' to let a QVariant(Qt::blue) create a variant - // of type QColor - // TODO Get rid of this hack. - x->type = QVariant::Color; - QColor color(*reinterpret_cast<const Qt::GlobalColor *>(copy)); - v_construct<QColor>(x, &color); - return; - } QVariantConstructor<GuiTypesFilter> constructor(x, copy); QMetaTypeSwitcher::switcher<void>(constructor, type, 0); } diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index fd271e6d6e..2117835609 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -264,12 +264,6 @@ void QWindow::setVisible(bool visible) } } -/*! - \fn bool QWindow::visible() const - Returns true if the window is set to visible. - \obsolete -*/ - bool QWindow::isVisible() const { Q_D(const QWindow); diff --git a/src/gui/kernel/qwindow.h b/src/gui/kernel/qwindow.h index c2c81fd2d7..e99c062158 100644 --- a/src/gui/kernel/qwindow.h +++ b/src/gui/kernel/qwindow.h @@ -102,10 +102,6 @@ public: void setSurfaceType(SurfaceType surfaceType); SurfaceType surfaceType() const; -#if QT_DEPRECATED_SINCE(5, 0) - QT_DEPRECATED inline bool visible() const { return isVisible(); } -#endif - bool isVisible() const; void create(); diff --git a/src/plugins/platforms/directfb/qdirectfbwindow.cpp b/src/plugins/platforms/directfb/qdirectfbwindow.cpp index dd2d4e488c..a830f1e3db 100644 --- a/src/plugins/platforms/directfb/qdirectfbwindow.cpp +++ b/src/plugins/platforms/directfb/qdirectfbwindow.cpp @@ -87,7 +87,7 @@ QDirectFbWindow::QDirectFbWindow(QWindow *tlw, QDirectFbInput *inputhandler) m_dfbWindow->SetOpacity(m_dfbWindow.data(), 0xff); - setVisible(window()->visible()); + setVisible(window()->isVisible()); m_inputHandler->addWindow(m_dfbWindow.data(), tlw); } @@ -103,7 +103,7 @@ void QDirectFbWindow::setGeometry(const QRect &rect) // bool isMoveOnly = (rect.topLeft() != geometry().topLeft()) && (rect.size() == geometry().size()); QPlatformWindow::setGeometry(rect); - if (window()->visible()) { + if (window()->isVisible()) { m_dfbWindow->SetBounds(m_dfbWindow.data(), rect.x(),rect.y(), rect.width(), rect.height()); // ### TODO port, verify if this is needed diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 385c5caccc..734c737e84 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -3523,7 +3523,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e) ge.t = gestureEvent->t; ge.spont = gestureEvent->spont; ge.m_accept = wasAccepted; - ge.d_func()->accepted = gestureEvent->d_func()->accepted; + ge.m_accepted = gestureEvent->m_accepted; res = d->notify_helper(w, &ge); gestureEvent->spont = false; eventAccepted = ge.isAccepted(); @@ -3533,7 +3533,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e) // packed into a single QEvent depends on not consuming the event if (eventAccepted || ge.isAccepted(g)) { // if the gesture was accepted, mark the target widget for it - gestureEvent->d_func()->targetWidgets[g->gestureType()] = w; + gestureEvent->m_targetWidgets[g->gestureType()] = w; gestureEvent->setAccepted(g, true); } else { // if the gesture was explicitly ignored by the application, diff --git a/src/widgets/kernel/qgesture.cpp b/src/widgets/kernel/qgesture.cpp index 070af65c70..4f899e5644 100644 --- a/src/widgets/kernel/qgesture.cpp +++ b/src/widgets/kernel/qgesture.cpp @@ -846,9 +846,9 @@ int QTapAndHoldGesturePrivate::Timeout = 700; // in ms Creates new QGestureEvent containing a list of \a gestures. */ QGestureEvent::QGestureEvent(const QList<QGesture *> &gestures) - : QEvent(QEvent::Gesture) + : QEvent(QEvent::Gesture), m_gestures(gestures), m_widget(0) + { - d = reinterpret_cast<QEventPrivate *>(new QGestureEventPrivate(gestures)); } /*! @@ -856,7 +856,6 @@ QGestureEvent::QGestureEvent(const QList<QGesture *> &gestures) */ QGestureEvent::~QGestureEvent() { - delete reinterpret_cast<QGestureEventPrivate *>(d); } /*! @@ -864,7 +863,7 @@ QGestureEvent::~QGestureEvent() */ QList<QGesture *> QGestureEvent::gestures() const { - return d_func()->gestures; + return m_gestures; } /*! @@ -872,10 +871,9 @@ QList<QGesture *> QGestureEvent::gestures() const */ QGesture *QGestureEvent::gesture(Qt::GestureType type) const { - const QGestureEventPrivate *d = d_func(); - for(int i = 0; i < d->gestures.size(); ++i) - if (d->gestures.at(i)->gestureType() == type) - return d->gestures.at(i); + for (int i = 0; i < m_gestures.size(); ++i) + if (m_gestures.at(i)->gestureType() == type) + return m_gestures.at(i); return 0; } @@ -885,7 +883,7 @@ QGesture *QGestureEvent::gesture(Qt::GestureType type) const QList<QGesture *> QGestureEvent::activeGestures() const { QList<QGesture *> gestures; - foreach (QGesture *gesture, d_func()->gestures) { + foreach (QGesture *gesture, m_gestures) { if (gesture->state() != Qt::GestureCanceled) gestures.append(gesture); } @@ -898,7 +896,7 @@ QList<QGesture *> QGestureEvent::activeGestures() const QList<QGesture *> QGestureEvent::canceledGestures() const { QList<QGesture *> gestures; - foreach (QGesture *gesture, d_func()->gestures) { + foreach (QGesture *gesture, m_gestures) { if (gesture->state() == Qt::GestureCanceled) gestures.append(gesture); } @@ -980,7 +978,7 @@ bool QGestureEvent::isAccepted(QGesture *gesture) const void QGestureEvent::setAccepted(Qt::GestureType gestureType, bool value) { setAccepted(false); - d_func()->accepted[gestureType] = value; + m_accepted[gestureType] = value; } /*! @@ -1017,7 +1015,7 @@ void QGestureEvent::ignore(Qt::GestureType gestureType) */ bool QGestureEvent::isAccepted(Qt::GestureType gestureType) const { - return d_func()->accepted.value(gestureType, true); + return m_accepted.value(gestureType, true); } /*! @@ -1027,7 +1025,7 @@ bool QGestureEvent::isAccepted(Qt::GestureType gestureType) const */ void QGestureEvent::setWidget(QWidget *widget) { - d_func()->widget = widget; + m_widget = widget; } /*! @@ -1035,7 +1033,7 @@ void QGestureEvent::setWidget(QWidget *widget) */ QWidget *QGestureEvent::widget() const { - return d_func()->widget; + return m_widget; } #ifndef QT_NO_GRAPHICSVIEW @@ -1062,22 +1060,6 @@ QPointF QGestureEvent::mapToGraphicsScene(const QPointF &gesturePoint) const } #endif //QT_NO_GRAPHICSVIEW -/*! - \internal -*/ -QGestureEventPrivate *QGestureEvent::d_func() -{ - return reinterpret_cast<QGestureEventPrivate *>(d); -} - -/*! - \internal -*/ -const QGestureEventPrivate *QGestureEvent::d_func() const -{ - return reinterpret_cast<const QGestureEventPrivate *>(d); -} - #ifdef Q_NO_USING_KEYWORD /*! \fn void QGestureEvent::setAccepted(bool accepted) diff --git a/src/widgets/kernel/qgesture.h b/src/widgets/kernel/qgesture.h index 5e121def41..ec5048089d 100644 --- a/src/widgets/kernel/qgesture.h +++ b/src/widgets/kernel/qgesture.h @@ -310,8 +310,10 @@ public: #endif private: - QGestureEventPrivate *d_func(); - const QGestureEventPrivate *d_func() const; + QList<QGesture *> m_gestures; + QWidget *m_widget; + QMap<Qt::GestureType, bool> m_accepted; + QMap<Qt::GestureType, QWidget *> m_targetWidgets; friend class QApplication; friend class QGestureManager; diff --git a/src/widgets/kernel/qgesture_p.h b/src/widgets/kernel/qgesture_p.h index ceccf17a6c..85793f6f7f 100644 --- a/src/widgets/kernel/qgesture_p.h +++ b/src/widgets/kernel/qgesture_p.h @@ -222,19 +222,6 @@ public: #endif }; -class QGestureEventPrivate -{ -public: - inline QGestureEventPrivate(const QList<QGesture *> &list) - : gestures(list), widget(0) - { - } - - QList<QGesture *> gestures; - QWidget *widget; - QMap<Qt::GestureType, bool> accepted; - QMap<Qt::GestureType, QWidget *> targetWidgets; -}; #endif // QT_NO_GESTURES diff --git a/src/widgets/kernel/qgesturemanager.cpp b/src/widgets/kernel/qgesturemanager.cpp index f4bf667ef8..8ba8904684 100644 --- a/src/widgets/kernel/qgesturemanager.cpp +++ b/src/widgets/kernel/qgesturemanager.cpp @@ -660,7 +660,7 @@ void QGestureManager::deliverEvents(const QSet<QGesture *> &gestures, bool eventAccepted = event.isAccepted(); foreach(QGesture *gesture, event.gestures()) { if (eventAccepted || event.isAccepted(gesture)) { - QWidget *w = event.d_func()->targetWidgets.value(gesture->gestureType(), 0); + QWidget *w = event.m_targetWidgets.value(gesture->gestureType(), 0); Q_ASSERT(w); DEBUG() << "override event: gesture was accepted:" << gesture << w; QList<QGesture *> &gestures = normalStartedGestures[w]; @@ -687,7 +687,7 @@ void QGestureManager::deliverEvents(const QSet<QGesture *> &gestures, foreach (QGesture *gesture, event.gestures()) { if (gesture->state() == Qt::GestureStarted && (eventAccepted || event.isAccepted(gesture))) { - QWidget *w = event.d_func()->targetWidgets.value(gesture->gestureType(), 0); + QWidget *w = event.m_targetWidgets.value(gesture->gestureType(), 0); Q_ASSERT(w); DEBUG() << "started gesture was delivered and accepted by" << w; m_gestureTargets[gesture] = w; |