diff options
author | Gunnar Sletta <gunnar@trolltech.com> | 2009-10-30 09:06:17 (GMT) |
---|---|---|
committer | Gunnar Sletta <gunnar@trolltech.com> | 2009-10-30 09:06:17 (GMT) |
commit | dc4e074324eb91a8a16e14c86ff41b03647b4cfa (patch) | |
tree | 55bfad60a6c1ea55d75171596ffd019b0906abb1 | |
parent | 7881773800c05c09f0e85a80c1cbb678981bd6c0 (diff) | |
parent | af92a4e78613ee3a0d402d3f67126284d0bb6656 (diff) | |
download | Qt-dc4e074324eb91a8a16e14c86ff41b03647b4cfa.zip Qt-dc4e074324eb91a8a16e14c86ff41b03647b4cfa.tar.gz Qt-dc4e074324eb91a8a16e14c86ff41b03647b4cfa.tar.bz2 |
Merge branch '4.6' of git@scm.dev.nokia.troll.no:qt/qt into 4.6
53 files changed, 1891 insertions, 634 deletions
@@ -431,6 +431,7 @@ elif [ $COMMERCIAL_USER = "yes" ]; then ;; Z4M|R4M|Q4M) LicenseType="Evaluation" + QMakeVar add DEFINES QT_EVAL case $ProductCode in B) Edition="Evaluation" @@ -4068,12 +4069,17 @@ SETTINGS_PATH_STR=`"$relpath/config.tests/unix/padstring" 268 "qt_stngpath=$QT_I EXAMPLES_PATH_STR=`"$relpath/config.tests/unix/padstring" 268 "qt_xmplpath=$QT_INSTALL_EXAMPLES"` DEMOS_PATH_STR=`"$relpath/config.tests/unix/padstring" 268 "qt_demopath=$QT_INSTALL_DEMOS"` +TODAY=`date +%Y-%m-%d` cat > "$outpath/src/corelib/global/qconfig.cpp.new" <<EOF /* License Info */ static const char qt_configure_licensee_str [256 + 12] = "$LICENSE_USER_STR"; static const char qt_configure_licensed_products_str [256 + 12] = "$LICENSE_PRODUCTS_STR"; + +/* Installation date */ +static const char qt_configure_installation [12+11] = "qt_instdate=$TODAY"; EOF + if [ ! -z "$QT_HOST_PREFIX" ]; then HOSTPREFIX_PATH_STR=`"$relpath/config.tests/unix/padstring" 268 "qt_prfxpath=$QT_HOST_PREFIX"` HOSTDOCUMENTATION_PATH_STR=`"$relpath/config.tests/unix/padstring" 268 "qt_docspath=$QT_HOST_PREFIX/doc"` @@ -4155,6 +4161,22 @@ else fi # ----------------------------------------------------------------------------- +if [ "$LicenseType" = "Evaluation" ]; then + EVALKEY=`"$relpath/config.tests/unix/padstring" 524 "qt_qevalkey=$LicenseKeyExt"` +elif echo "$D_FLAGS" | grep QT_EVAL >/dev/null 2>&1; then + EVALKEY=`"$relpath/config.tests/unix/padstring" 524 "qt_qevalkey="` +fi + +if [ -n "$EVALKEY" ]; then + cat > "$outpath/src/corelib/global/qconfig_eval.cpp" <<EOF +/* Evaluation license key */ +static const char qt_eval_key_data [512 + 12] = "$EVALKEY"; +EOF + chmod -w "$outpath/src/corelib/global/qconfig_eval.cpp" +fi + + +# ----------------------------------------------------------------------------- # build qmake # ----------------------------------------------------------------------------- diff --git a/doc/src/frameworks-technologies/eventsandfilters.qdoc b/doc/src/frameworks-technologies/eventsandfilters.qdoc index c769884..52d596a 100644 --- a/doc/src/frameworks-technologies/eventsandfilters.qdoc +++ b/doc/src/frameworks-technologies/eventsandfilters.qdoc @@ -215,7 +215,7 @@ \l{QCoreApplication::}{postEvent()} posts the event on a queue for later dispatch. The next time Qt's main event loop runs, it dispatches all posted events, with some optimization. For example, if there are - several resize events, they are are compressed into one. The same + several resize events, they are compressed into one. The same applies to paint events: QWidget::update() calls \l{QCoreApplication::}{postEvent()}, which eliminates flickering and increases speed by avoiding multiple repaints. diff --git a/mkspecs/unsupported/qnx-g++/qplatformdefs.h b/mkspecs/unsupported/qnx-g++/qplatformdefs.h index f309f81..1bf9ffcb 100644 --- a/mkspecs/unsupported/qnx-g++/qplatformdefs.h +++ b/mkspecs/unsupported/qnx-g++/qplatformdefs.h @@ -167,6 +167,6 @@ inline float strtof(const char *b, char **e) return float(strtod(b, e)); } -#define QT_QWS_TEMP_DIR qgetenv("TMP"); +#define QT_QWS_TEMP_DIR QString::fromLatin1(qgetenv("TMP")) #endif // QPLATFORMDEFS_H diff --git a/mkspecs/unsupported/qws/qnx-i386-g++/qmake.conf b/mkspecs/unsupported/qws/qnx-i386-g++/qmake.conf index 3f24cd9..fffb80f 100644 --- a/mkspecs/unsupported/qws/qnx-i386-g++/qmake.conf +++ b/mkspecs/unsupported/qws/qnx-i386-g++/qmake.conf @@ -56,10 +56,10 @@ QMAKE_PCH_OUTPUT_EXT = .gch QMAKE_LFLAGS_BSYMBOLIC_FUNC = -Wl,-Bsymbolic-functions QMAKE_LFLAGS_DYNAMIC_LIST = -Wl,--dynamic-list, -include(../../common/unix.conf) +include(../../../common/unix.conf) QMAKE_CFLAGS_THREAD = -D_REENTRANT -QMAKE_CXXFLAGS_THREAD = $$QMAKE_CLFAGS_THREAD +QMAKE_CXXFLAGS_THREAD = $$QMAKE_CFLAGS_THREAD QMAKE_INCDIR = QMAKE_LIBDIR = diff --git a/src/3rdparty/webkit/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp b/src/3rdparty/webkit/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp index 80c9d72..100f272 100644 --- a/src/3rdparty/webkit/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp +++ b/src/3rdparty/webkit/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp @@ -586,7 +586,6 @@ private slots: void javaScriptWindowObjectClearedOnEvaluate(); void setHtml(); void setHtmlWithResource(); - void setHtmlWithBaseURL(); void ipv6HostEncoding(); void metaData(); void popupFocus(); @@ -2372,28 +2371,6 @@ void tst_QWebFrame::setHtmlWithResource() QCOMPARE(p.styleProperty("color", QWebElement::CascadedStyle), QLatin1String("red")); } -void tst_QWebFrame::setHtmlWithBaseURL() -{ - QString html("<html><body><p>hello world</p><img src='resources/image2.png'/></body></html>"); - - QWebPage page; - QWebFrame* frame = page.mainFrame(); - - // in few seconds, the image should be completey loaded - QSignalSpy spy(&page, SIGNAL(loadFinished(bool))); - - frame->setHtml(html, QUrl::fromLocalFile(QDir::currentPath())); - QTest::qWait(200); - QCOMPARE(spy.count(), 1); - - QCOMPARE(frame->evaluateJavaScript("document.images.length").toInt(), 1); - QCOMPARE(frame->evaluateJavaScript("document.images[0].width").toInt(), 128); - QCOMPARE(frame->evaluateJavaScript("document.images[0].height").toInt(), 128); - - // no history item has to be added. - QCOMPARE(m_view->page()->history()->count(), 0); -} - class TestNetworkManager : public QNetworkAccessManager { public: diff --git a/src/corelib/corelib.pro b/src/corelib/corelib.pro index f835bee..9a15bf1 100644 --- a/src/corelib/corelib.pro +++ b/src/corelib/corelib.pro @@ -35,4 +35,4 @@ symbian: { # Workaroud for problems with paging this dll MMP_RULES -= PAGED MMP_RULES *= UNPAGED -}
\ No newline at end of file +} diff --git a/src/corelib/eval.pri b/src/corelib/eval.pri new file mode 100644 index 0000000..efda56b --- /dev/null +++ b/src/corelib/eval.pri @@ -0,0 +1,4 @@ +SOURCES += \ + $$QT_SOURCE_TREE/src/corelib/kernel/qtcore_eval.cpp +INCLUDEPATH += \ + $$QT_BUILD_TREE/src/corelib/global diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index e227403..32693e0 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -208,6 +208,18 @@ QLibraryInfo::buildKey() } /*! + \since 4.6 + Returns the installation date for this build of Qt. The install date will + usually be the last time that Qt sources were configured. +*/ +QDate +QLibraryInfo::buildDate() +{ + return QDate(); + //return QDate::fromString(QString::fromLatin1(qt_configure_installation + 12), Qt::ISODate); +} + +/*! Returns the location specified by \a loc. */ @@ -481,12 +493,20 @@ void qt_core_boilerplate() "Contact: Nokia Corporation (qt-info@nokia.com)\n" "\n" "Build key: " QT_BUILD_KEY "\n" + "Build date: %s\n" "Installation prefix: %s\n" "Library path: %s\n" "Include path: %s\n", + qt_configure_installation + 12, qt_configure_prefix_path_str + 12, qt_configure_libraries_path_str + 12, qt_configure_headers_path_str + 12); + +#ifdef QT_EVAL + extern void qt_core_eval_init(uint); + qt_core_eval_init(1); +#endif + exit(0); } diff --git a/src/corelib/global/qlibraryinfo.h b/src/corelib/global/qlibraryinfo.h index 3195777..88e8566 100644 --- a/src/corelib/global/qlibraryinfo.h +++ b/src/corelib/global/qlibraryinfo.h @@ -43,6 +43,7 @@ #define QLIBRARYINFO_H #include <QtCore/qstring.h> +#include <QtCore/QDate> QT_BEGIN_HEADER @@ -59,6 +60,7 @@ public: static QString licensedProducts(); static QString buildKey(); + static QDate buildDate(); enum LibraryLocation { diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 6001d9d..86680a5 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -5556,79 +5556,6 @@ QUrl QUrl::fromEncoded(const QByteArray &input, ParsingMode parsingMode) } /*! - Returns a valid URL from a user supplied \a userInput string if one can be - deducted. In the case that is not possible, an invalid QUrl() is returned. - - \since 4.6 - - Most applications that can browse the web, allow the user to input a URL - in the form of a plain string. This string can be manually typed into - a location bar, obtained from the clipboard, or passed in via command - line arguments. - - When the string is not already a valid URL, a best guess is performed, - making various web related assumptions. - - In the case the string corresponds to a valid file path on the system, - a file:// URL is constructed, using QUrl::fromLocalFile(). - - If that is not the case, an attempt is made to turn the string into a - http:// or ftp:// URL. The latter in the case the string starts with - 'ftp'. The result is then passed through QUrl's tolerant parser, and - in the case or success, a valid QUrl is returned, or else a QUrl(). - - \section1 Examples: - - \list - \o qt.nokia.com becomes http://qt.nokia.com - \o ftp.qt.nokia.com becomes ftp://ftp.qt.nokia.com - \o localhost becomes http://localhost - \o /home/user/test.html becomes file:///home/user/test.html (if exists) - \endlist - - \section2 Tips to avoid erroneous character conversion when dealing with - URLs and strings: - - \list - \o When creating an URL QString from a QByteArray or a char*, always use - QString::fromUtf8(). - \o Favor the use of QUrl::fromEncoded() and QUrl::toEncoded() instead of - QUrl(string) and QUrl::toString() when converting QUrl to/from string. - \endlist -*/ -QUrl QUrl::fromUserInput(const QString &userInput) -{ - QString trimmedString = userInput.trimmed(); - - // Absolute files - if (QDir::isAbsolutePath(trimmedString)) - return QUrl::fromLocalFile(trimmedString); - - // Check the most common case of a valid url with scheme and host first - QUrl url = QUrl::fromEncoded(trimmedString.toUtf8(), QUrl::TolerantMode); - if (url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty()) - return url; - - // If the string is missing the scheme or the scheme is not valid, prepend a scheme - QString scheme = url.scheme(); - if (scheme.isEmpty() || scheme.contains(QLatin1Char('.')) || scheme == QLatin1String("localhost")) { - // Do not do anything for strings such as "foo", only "foo.com" - int dotIndex = trimmedString.indexOf(QLatin1Char('.')); - if (dotIndex != -1 || trimmedString.startsWith(QLatin1String("localhost"))) { - const QString hostscheme = trimmedString.left(dotIndex).toLower(); - QByteArray scheme = (hostscheme == QLatin1String("ftp")) ? "ftp" : "http"; - trimmedString = QLatin1String(scheme) + QLatin1String("://") + trimmedString; - } - url = QUrl::fromEncoded(trimmedString.toUtf8(), QUrl::TolerantMode); - } - - if (url.isValid()) - return url; - - return QUrl(); -} - -/*! Returns a decoded copy of \a input. \a input is first decoded from percent encoding, then converted from UTF-8 to unicode. */ @@ -6227,4 +6154,107 @@ QString QUrl::errorString() const \internal */ +// The following code has the following copyright: +/* + Copyright (C) Research In Motion Limited 2009. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Research In Motion Limited nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY Research In Motion Limited ''AS IS'' AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL Research In Motion Limited BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + + +/*! + Returns a valid URL from a user supplied \a userInput string if one can be + deducted. In the case that is not possible, an invalid QUrl() is returned. + + \since 4.6 + + Most applications that can browse the web, allow the user to input a URL + in the form of a plain string. This string can be manually typed into + a location bar, obtained from the clipboard, or passed in via command + line arguments. + + When the string is not already a valid URL, a best guess is performed, + making various web related assumptions. + + In the case the string corresponds to a valid file path on the system, + a file:// URL is constructed, using QUrl::fromLocalFile(). + + If that is not the case, an attempt is made to turn the string into a + http:// or ftp:// URL. The latter in the case the string starts with + 'ftp'. The result is then passed through QUrl's tolerant parser, and + in the case or success, a valid QUrl is returned, or else a QUrl(). + + \section1 Examples: + + \list + \o qt.nokia.com becomes http://qt.nokia.com + \o ftp.qt.nokia.com becomes ftp://ftp.qt.nokia.com + \o localhost becomes http://localhost + \o /home/user/test.html becomes file:///home/user/test.html (if exists) + \endlist + + \section2 Tips to avoid erroneous character conversion when dealing with + URLs and strings: + + \list + \o When creating an URL QString from a QByteArray or a char*, always use + QString::fromUtf8(). + \o Favor the use of QUrl::fromEncoded() and QUrl::toEncoded() instead of + QUrl(string) and QUrl::toString() when converting QUrl to/from string. + \endlist +*/ +QUrl QUrl::fromUserInput(const QString &userInput) +{ + QString trimmedString = userInput.trimmed(); + + // Check the most common case of a valid url with scheme and host first + QUrl url = QUrl::fromEncoded(trimmedString.toUtf8(), QUrl::TolerantMode); + if (url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty()) + return url; + + // Absolute files that exists + if (QDir::isAbsolutePath(trimmedString) && QFile::exists(trimmedString)) + return QUrl::fromLocalFile(trimmedString); + + // If the string is missing the scheme or the scheme is not valid prepend a scheme + QString scheme = url.scheme(); + if (scheme.isEmpty() || scheme.contains(QLatin1Char('.')) || scheme == QLatin1String("localhost")) { + // Do not do anything for strings such as "foo", only "foo.com" + int dotIndex = trimmedString.indexOf(QLatin1Char('.')); + if (dotIndex != -1 || trimmedString.startsWith(QLatin1String("localhost"))) { + const QString hostscheme = trimmedString.left(dotIndex).toLower(); + QByteArray scheme = (hostscheme == QLatin1String("ftp")) ? "ftp" : "http"; + trimmedString = QLatin1String(scheme) + QLatin1String("://") + trimmedString; + } + url = QUrl::fromEncoded(trimmedString.toUtf8(), QUrl::TolerantMode); + } + + if (url.isValid()) + return url; + + return QUrl(); +} +// end of BSD code + QT_END_NAMESPACE diff --git a/src/corelib/kernel/qtcore_eval.cpp b/src/corelib/kernel/qtcore_eval.cpp new file mode 100644 index 0000000..fe47a30 --- /dev/null +++ b/src/corelib/kernel/qtcore_eval.cpp @@ -0,0 +1,569 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qcoreevent.h> +#include <qdatetime.h> +#include <qlibraryinfo.h> +#include <qobject.h> +#include <qcoreapplication.h> + +#include "stdio.h" +#include "stdlib.h" + +QT_BEGIN_NAMESPACE + +#include "qconfig_eval.cpp" + +static const char boilerplate_unsuported[] = + "\nQt %1 Evaluation License\n" + "Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).\n" + "All rights reserved.\n\n" + "This trial version may only be used for evaluation purposes\n" + "and will shut down after 120 minutes.\n" + "Registered to:\n" + " Licensee: %2\n\n" + "The evaluation expires in %4 days\n\n" + "Contact http://qt.nokia.com/about/contact-us for pricing and purchasing information.\n"; + +static const char boilerplate_supported[] = + "\nQt %1 Evaluation License\n" + "Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).\n" + "All rights reserved.\n\n" + "This trial version may only be used for evaluation purposes\n" + "Registered to:\n" + " Licensee: %2\n\n" + "The evaluation expires in %4 days\n\n" + "Contact http://qt.nokia.com/about/contact-us for pricing and purchasing information.\n"; + +static const char boilerplate_expired[] = + "This software is using the trial version of the Qt GUI toolkit.\n" + "The trial period has expired. If you need more time to\n" + "evaluate Qt, or if you have any questions about Qt, contact us\n" + "at: http://qt.nokia.com/about/contact-us.\n\n"; + +static const char will_shutdown_1min[] = + "\nThe evaluation of Qt will SHUT DOWN in 1 minute.\n" + "Contact http://qt.nokia.com/about/contact-us for pricing and purchasing information.\n"; + +static const char will_shutdown_now[] = + "\nThe evaluation of Qt has now reached its automatic\n" + "timeout and will shut down.\n" + "Contact http://qt.nokia.com/about/contact-us for pricing and purchasing information.\n"; + +static int qt_eval_days_left() +{ + const char *const license_key = qt_eval_key_data + 12; + + // fast fail + if (!qt_eval_key_data[0] || !*license_key) + return -2; + + QDate today = QDate::currentDate(); + QDate build = QLibraryInfo::buildDate(); + return qMax(-1, today.daysTo(build) + 30); +} + +static int qt_eval_is_supported() +{ + const char *const license_key = qt_eval_key_data + 12; + if (!qt_eval_key_data[0] || !*license_key) + return -1; + + // is this an unsupported evaluation? + const char* typecode = license_key; + int field = 2; + for ( ; field && *typecode; ++typecode) + if (*typecode == '-') + --field; + + if (!field && typecode[1] == '4' && typecode[2] == 'M') { + if (typecode[0] == 'Q') + return 0; + else if (typecode[0] == 'R' || typecode[0] == 'Z') + return 1; + } + return -1; +} + +static QString qt_eval_string() +{ + const char *msg; + switch (qt_eval_is_supported()) { + case 0: + msg = boilerplate_unsuported; + break; + case 1: + msg = boilerplate_supported; + break; + default: + return QString(); + msg = 0; + } + + return QString::fromLatin1(msg) + .arg(QLatin1String(QT_VERSION_STR)) + .arg(QLibraryInfo::licensee()) + .arg(qt_eval_days_left()); +} + +#define WARN_TIMEOUT 60 * 1000 * 119 +#define KILL_DELAY 60 * 1000 * 1 + +class QCoreFuriCuri : public QObject +{ +public: + + int warn; + int kill; + + QCoreFuriCuri() : QObject(), warn(-1), kill(-1) + { + if (!qt_eval_is_supported()) { + warn = startTimer(WARN_TIMEOUT); + kill = 0; + } + } + + void timerEvent(QTimerEvent *e) { + if (e->timerId() == warn) { + killTimer(warn); + fprintf(stderr, "%s\n", will_shutdown_1min); + kill = startTimer(KILL_DELAY); + } else if (e->timerId() == kill) { + fprintf(stderr, "%s\n", will_shutdown_now); + QCoreApplication::instance()->quit(); + } + } +}; + +#if defined(QT_BUILD_CORE_LIB) || defined (QT_BOOTSTRAPPED) + +void qt_core_eval_init(uint type) +{ + switch (qt_eval_days_left()) { + case -2: + return; + + case -1: + fprintf(stderr, "%s\n", boilerplate_expired); + if (type == 0) { + // if we're a console app only. + exit(0); + } + + default: + fprintf(stderr, "%s\n", qPrintable(qt_eval_string())); + if (type == 0) { + Q_UNUSED(new QCoreFuriCuri()); + } + } +} +#endif + +#ifdef QT_BUILD_GUI_LIB + +QT_BEGIN_INCLUDE_NAMESPACE +#include <qdialog.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qmessagebox.h> +#include <qpushbutton.h> +#include <qtimer.h> +#include <qapplication.h> +QT_END_INCLUDE_NAMESPACE + + +static const char * const qtlogo_eval_xpm[] = { +/* columns rows colors chars-per-pixel */ +"46 55 174 2", +" c #002E02", +". c #00370D", +"X c #003A0E", +"o c #003710", +"O c #013C13", +"+ c #043E1A", +"@ c #084F0A", +"# c #0B520C", +"$ c #054413", +"% c #0C4C17", +"& c #07421D", +"* c #09451D", +"= c #0D491E", +"- c #125515", +"; c #13541A", +": c #17591B", +"> c #1B5C1D", +", c #1F611F", +"< c #20621E", +"1 c #337B1E", +"2 c #0B4521", +"3 c #0F4923", +"4 c #114B24", +"5 c #154D2A", +"6 c #175323", +"7 c #1C5924", +"8 c #1C532F", +"9 c #1E5432", +"0 c #245936", +"q c #265938", +"w c #295C3B", +"e c #246324", +"r c #266823", +"t c #2A6C24", +"y c #276628", +"u c #2D7026", +"i c #327427", +"p c #367927", +"a c #37782A", +"s c #397C2A", +"d c #2E613E", +"f c #336C37", +"g c #2F6040", +"h c #356545", +"j c #3C6B4E", +"k c #3F6C51", +"l c #406E4F", +"z c #406D52", +"x c #477457", +"c c #497557", +"v c #4B7857", +"b c #517B5E", +"n c #3C8423", +"m c #3E812C", +"M c #53A61D", +"N c #41862C", +"B c #458A2D", +"V c #498F2D", +"C c #479324", +"Z c #489226", +"A c #4D952C", +"S c #478B30", +"D c #488C30", +"F c #4D9232", +"G c #509632", +"H c #549A33", +"J c #589F35", +"K c #56A526", +"L c #57A821", +"P c #5BAA27", +"I c #57A32A", +"U c #5CA72E", +"Y c #5DAB2A", +"T c #5CA336", +"R c #60AD2E", +"E c #63B12D", +"W c #65AF35", +"Q c #62A53F", +"! c #65AE39", +"~ c #66B036", +"^ c #6AB437", +"/ c #67B138", +"( c #6AB339", +") c #6DB838", +"_ c #70BA3C", +"` c #4D8545", +"' c #4E8942", +"] c #548851", +"[ c #6FAF4A", +"{ c #6DB243", +"} c #71B546", +"| c #70B840", +" . c #73B648", +".. c #79BA4E", +"X. c #7CBB53", +"o. c #598266", +"O. c #62886D", +"+. c #6A8F75", +"@. c #6B9173", +"#. c #70937A", +"$. c #799F79", +"%. c #7BAF66", +"&. c #81BD5B", +"*. c #85BF60", +"=. c #85AC7F", +"-. c #8DBA7B", +";. c #87C061", +":. c #8AC364", +">. c #8DC46A", +",. c #90C56E", +"<. c #93C771", +"1. c #96CA73", +"2. c #9ACB7C", +"3. c #9FD07D", +"4. c #779981", +"5. c #7F9F89", +"6. c #809F88", +"7. c #82A18B", +"8. c #86A192", +"9. c #8DA994", +"0. c #8FA998", +"q. c #94AF9B", +"w. c #97B991", +"e. c #97B19E", +"r. c #9DB6A3", +"t. c #A3BCA7", +"y. c #A6BCAB", +"u. c #A9BEB1", +"i. c #9ECD81", +"p. c #A2CF85", +"a. c #A5D284", +"s. c #A6D189", +"d. c #A9D28E", +"f. c #ABD491", +"g. c #B1D797", +"h. c #B1D699", +"j. c #B5D89E", +"k. c #ADC5AC", +"l. c #B1CAAE", +"z. c #B9DAA3", +"x. c #BDDDA8", +"c. c #ADC1B4", +"v. c #B2C6B6", +"b. c #B5C6BC", +"n. c #B6C9BA", +"m. c #BCD1BA", +"M. c #C6E1B4", +"N. c #CDE5BD", +"B. c #C2D2C6", +"V. c #CADEC2", +"C. c #C6D3CC", +"Z. c #C8D7CB", +"A. c #CEDAD2", +"S. c #D2DDD4", +"D. c #D3E9C6", +"F. c #D7EBC9", +"G. c #D9EBCD", +"H. c #DEEED4", +"J. c #D6E0D9", +"K. c #DAE4DC", +"L. c #E0EFD7", +"P. c #E5F2DD", +"I. c #DFE8E0", +"U. c #E4EBE5", +"Y. c #E9EFEA", +"T. c #EDF4EB", +"R. c #F0FAE6", +"E. c #F1F8EC", +"W. c #EDF0F0", +"Q. c #F4F7F3", +"!. c #F6F9F4", +"~. c #F8FAF7", +"^. c #FEFEFE", +"/. c None", +/* pixels */ +"/././././.c h ' Q / W _ &.p././././././././././././././././././././././././././././././././.", +"/././.4 O % Z ~ ~ W ~ W R U R R ( X.>.p././././././././././././././././././././././././././.", +"/./.. * = J _ ~ ~ ~ ~ ~ / / / / W W U P P U W .;.2././././././././././././././././././././.", +"/.= = & a ) W ~ ~ ~ ~ ~ / W / ~ ~ ~ ^ ( ( ^ ~ R R U P Y ~ .;.2././././././././././././././.", +"O.O = = T ^ W ~ ~ ~ ~ ~ ~ W W / W ~ ~ ~ ~ ~ ~ ~ ( ( ( ( ~ W Y Y Y Y W { &.1././././././././.", +"0 = * 7 ~ ~ ~ ~ ~ ~ ~ ~ ~ / / W ~ ~ ~ ~ ~ ~ ~ ~ W W W ~ ~ ~ ~ ( ( ( W W R U P U W { X.1.f./.", +"= = & e ^ W ~ ~ ~ ~ ~ ~ ~ ~ / / ~ ~ ~ ~ ~ ~ ~ ~ W ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ^ ( ( / ~ W R U U Y ", +"= = & e ^ W ~ ~ ~ ~ ~ ~ ~ ~ W W ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ W ( W ~ ~ ~ ^ ^ ( ", +"= = * e ^ W ~ ~ ~ ~ ~ ~ / W / W ! ( / ~ W ^ ( ( ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ W ~ W W ~ ~ ~ ~ ~ ~ ", +"= = & e ^ ! ~ ~ ~ ~ ~ ~ W W ^ _ ~ K Y W W R P Y W ( ~ ~ ~ ~ ~ ~ ~ W / ~ ~ ~ ^ W ~ ~ ~ ~ ~ ~ ", +"= = & e ^ W ~ ~ ~ ~ ~ ~ W ) W 1 ` w.V.L.H.D.z.,.~ Y ^ ~ ~ ~ ~ ~ W ~ ~ ~ ( ~ W W ~ ~ ~ ~ ~ ~ ", +"= = & e ^ W ~ ~ ~ ~ ~ W ) V = 8.~.^.^.^.^.^.^.^.U.<.Y ~ ~ ~ ~ ~ W W ! ~ Y W ^ W ~ ~ ~ ~ ~ ~ ", +"= = & e ^ W ~ ~ ~ ~ W ^ B O u.^.~.^.^.^.^.~.~.^.^.^.h.Y ^ ~ ~ ^ F $ k.R.G.1.Y / ~ ~ ~ ~ ~ ~ ", +"= = & e ^ ~ ~ ~ / W ( J X 7.^.~.^.^.^.^.^.^.^.^.^.^.^.s.Y / W ) a 2 U.^.^.d.U ( ~ ~ ~ ~ ~ ~ ", +"= = & e ^ W / ~ ~ ~ ^ > w ~.^.^.^.^.^.F.%.v c.^.^.^.^.~.X.W ~ ^ > h ^.^.^.d.P ( ~ ~ ~ ~ ~ ~ ", +"= = & e ^ W ~ ~ W ^ H o e.^.^.^.^.^.G.Y E n . y.^.^.^.^.M.Y ( ! $ @.^.~.^.f.U ( / ~ ~ W ~ ~ ", +"= = & e ^ W ~ W ! ) t 4 U.^.^.^.^.^.>.U ( _ , 9 ~.^.^.^.~...^ A y.^.~.^.s.M W Y ~ ~ ~ ~ ~ ", +"= 3 & e ^ W ~ ( ^ ( $ c ^.^.^.^.^.E.) ~ ~ ^ S o n.^.^.^.^.=.- l.v.Y.^.^.^.M.:.:.X.~ ~ ~ ~ ~ ", +"= = & e ^ ! W W ( J X 7.^.^.^.^.^.F.Y ( W ^ T X 6.^.^.~.^.c.. J.^.^.^.^.^.^.^.^.P.~ ~ ~ ~ ~ ", +"= = & r ^ W / W ) B o v.^.~.^.^.^.M.U / ~ ~ ! $ o.^.^.^.^.K.* S.^.^.^.^.^.^.^.^.P.~ ~ ~ ~ ~ ", +"= = & e ^ ! ~ W ) a + S.^.^.^.^.^.z.P ( W ~ ( % z ^.^.^.^.~.f t.U.^.^.^.^.~.^.^.P.~ ~ ~ ~ ~ ", +"* = & e ^ W ~ W ) t 3 Y.^.^.^.^.^.f.P ( ~ ~ ^ ; h ^.^.^.^.^.:.@ j ^.^.^.^.h.{ X.&.~ ~ ~ ~ ~ ", +"3 = & e ^ W ~ ~ ^ e 8 Q.^.^.^.^.^.s.P ~ ~ W ^ > 0 ~.^.^.^.^.1.# z ^.^.^.^.d.L W R ~ ~ ~ ~ ~ ", +"= = & e ^ W ~ ~ ^ > q ~.^.^.^.^.^.p.U ^ ~ W ) e 9 ~.^.^.^.^.3.# k ^.^.^.^.f.Y ( / ~ ~ ~ ~ ~ ", +"= = & e ^ W / W ^ > w ~.^.^.^.^.^.i.Y / ~ W ^ e 8 Q.^.^.^.^.a.# z ^.^.^.^.f.Y / ~ ~ ~ ~ ~ ~ ", +"= = & e ^ W / W ^ > w ^.^.^.^.^.^.2.Y / ~ ~ ) e 8 Q.^.^.^.^.s.# z ^.^.^.^.d.P ( ~ ~ ~ ~ ~ ~ ", +"= = & e ^ W W W ^ > q ^.^.^.^.^.^.p.Y / ~ ~ ^ e 9 Q.^.^.^.^.a.@ z ^.^.^.^.f.U / ~ ~ ~ ~ ~ ~ ", +"= = & e ^ W / W ) 7 9 Q.^.^.^.^.^.a.P / ~ W ) , 9 Q.^.^.^.^.3.# z ^.^.~.^.f.P ^ ~ ~ ~ ~ ~ ~ ", +"= = & e ^ W / W ) r 5 T.^.^.^.^.^.d.Y / ~ W ) > q ~.^.^.^.^.1.# k ^.^.^.^.f.Y ( ~ ~ ~ ~ ~ ~ ", +"= = & e ^ / / W ) i 2 I.^.^.^.^.^.h.P ( ~ W ( > g ^.^.^.^.^.:.# z ^.^.^.^.f.P / ~ ~ ~ ~ ~ ~ ", +"= = & e ( W / W ) m O Z.^.^.^.^.^.x.P / ~ ~ ( ; j ^.^.^.^.~.&.- k ^.^.~.^.f.P / ~ ~ ~ ~ ~ ~ ", +"= = & e ( W / W ) F o y.^.~.^.^.^.N.U ( ~ ~ W $ b ^.^.^.^.R._ - k ^.^.^.^.f.Y ( ~ ~ ~ ~ ~ ~ ", +"= = & e ^ W ~ ~ ^ J X 4.^.^.^.^.^.L.~ ~ W ^ T X #.^.^.^.^.F.~ ; j ^.^.^.^.f.U ( ~ ~ ~ ~ ~ ~ ", +"= = & e ^ ~ ~ ~ / ^ % l ^.^.^.^.^.!. .R ^ ^ G . r.^.~.^.^.j.E : j ^.^.^.^.f.P ) ( ~ ~ ~ ~ ~ ", +"= = & e ^ W ~ ~ W ) u = U.^.^.^.^.^.1.Y ! ) a & K.^.^.^.^.;.~ : j ^.^.~.^.z.M I I / ~ ~ W ~ ", +"= = & e ( W ~ ~ W ( G . q.^.^.^.^.^.D.U ^ ! X o.^.^.^.^.P.~ ^ > g ^.^.^.^.E.-.$.m.X.W ~ ~ ~ ", +"= = & e ^ / ~ ~ ^ ! ( > w ~.^.^.^.^.^.h.T > j T.^.^.~.^.a.Y _ i 3 U.^.^.^.^.^.^.^.X.R ~ ~ ~ ", +"= = & e ^ / ~ ~ W W ^ H . 9.^.~.^.^.^.^.K.C.~.^.^.^.^.H.W W ^ T . q.^.~.^.^.^.^.^.X.R ~ ~ ~ ", +"= = + e ^ W / ~ W W W ) m + B.^.~.^.^.^.^.^.^.^.^.^.E.X.Y ( W ^ B 6 y.^.^.^.E.D.2.( ~ ~ ~ ~ ", +"= = * e ^ ! / ! W ^ W W ) a 4 b.^.^.^.^.^.^.^.^.^.P...Y ( ! W ! ^ W Z [ *.X.{ Y U ~ ~ ~ ~ ~ ", +"= = & e ( W ~ ~ W / W / W ) A < +.A.~.^.^.^.^.!.p.W R ~ ~ ~ ~ ~ W / ) E U W W / ^ ~ ~ ~ ~ ~ ", +"= = & e ^ W ~ ~ / W / / / W ( _ Z X 6.^.^.^.^.E.W ~ ^ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ / ~ ~ ~ ~ ~ ~ ~ ~ ", +"= = & e ^ ~ ~ ~ W W / W ~ ~ ~ ~ ) ; h ^.^.^.^.^.d.M U ~ / ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ W ", +"= = & e ^ W ~ ~ ^ W W / ~ ~ ~ W ) p + S.^.^.^.^.~.M.f. .W ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ .", +"= = & e ^ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ W ( T O +.^.~.^.^.^.^.^.&.Y ( ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ W ( Y 2.", +"= = & e ( W ~ ~ ~ ~ ~ ~ ~ ~ ~ / W ) N + b.^.^.^.^.^.^.&.R ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ W /.", +"= = & e ^ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ W ^ N 7 r.W.^.^.^.!.X.W ~ ~ W ~ W ~ ~ ~ ~ ~ ~ / ( ( K p./.", +"= = & e ( W ~ ~ W ~ ~ ~ ~ ~ ~ ~ ~ ~ W ( W C Q &.:.X.| ~ ~ ~ ~ W ~ / ~ ( / ( ~ W E U P 1././.", +"= = + e ^ / / / ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ W / ) ^ R Y W W ~ ~ ( / ( / W R Y Y U R ( X.,././././.", +"= = * e ( / ~ / ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ W W W ! ( ( ( W W E U P Y W ( X.,.d./././././././././.", +"= = * e ( W ~ ~ ~ ~ W ! ~ W ~ W ~ ( ( / ^ W W U Y P W ( X.,.d./././././././././././././././.", +"8 $ * e ( W ~ ~ ~ ! ( ( ( / ( W R Y Y Y R ( X.>.d./././././././././././././././././././././.", +"/.d . y ^ / / / ( W Y Y P P W ( X.>.d./././././././././././././././././././././././././././.", +"/./.h : ^ R R R W ( X.<.f./././././././././././././././././././././././././././././././././.", +"/././.] _ *.3./././././././././././././././././././././././././././././././././././././././." +}; + +class EvalMessageBox : public QDialog +{ +public: + EvalMessageBox(bool expired) + { + setWindowTitle(QLatin1String(" ")); + + QString str = qt_eval_string(); + if (expired) { + str = QLatin1String(boilerplate_expired); + } else { + str = qt_eval_string(); + } + str = str.trimmed(); + + QFrame *border = new QFrame(this); + + QLabel *pixmap_label = new QLabel(border); + pixmap_label->setPixmap(qtlogo_eval_xpm); + pixmap_label->setAlignment(Qt::AlignTop); + + QLabel *text_label = new QLabel(str, border); + + QHBoxLayout *pm_and_text_layout = new QHBoxLayout(); + pm_and_text_layout->addWidget(pixmap_label); + pm_and_text_layout->addWidget(text_label); + + QVBoxLayout *master_layout = new QVBoxLayout(border); + master_layout->addLayout(pm_and_text_layout); + + QVBoxLayout *border_layout = new QVBoxLayout(this); + border_layout->setMargin(0); + border_layout->addWidget(border); + + if (expired) { + QPushButton *cmd = new QPushButton(QLatin1String("OK"), border); + cmd->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + cmd->setDefault(true); + + QHBoxLayout *button_layout = new QHBoxLayout(); + master_layout->addLayout(button_layout); + button_layout->addWidget(cmd); + + connect(cmd, SIGNAL(clicked()), this, SLOT(close())); + } else { + border->setFrameShape(QFrame::WinPanel); + border->setFrameShadow(QFrame::Raised); + setParent(parentWidget(), Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); + QTimer::singleShot(7000, this, SLOT(close())); + setAttribute(Qt::WA_DeleteOnClose); + } + + setFixedSize(sizeHint()); + } +}; + +class QGuiFuriCuri : public QCoreFuriCuri +{ +public: + void timerEvent(QTimerEvent *e) { + if (e->timerId() == warn) { + killTimer(warn); + QMessageBox::information(0, QLatin1String("Automatic Timeout"), QLatin1String(will_shutdown_1min)); + kill = startTimer(KILL_DELAY); + } else if (e->timerId() == kill) { + killTimer(kill); + QMessageBox::information(0, QLatin1String("Automatic Timeout"), QLatin1String(will_shutdown_now)); + qApp->quit(); + } + } +}; + + +void qt_gui_eval_init(uint) +{ + switch (qt_eval_days_left()) { + case -2: + return; + + case -1: { + EvalMessageBox box(true); + box.exec(); + ::exit(0); + } + + default: { + EvalMessageBox *box = new EvalMessageBox(false); + box->show(); + Q_UNUSED(new QGuiFuriCuri()); + } + } +} + +static QString qt_eval_title_prefix() +{ + return QLatin1String("[Qt Evaluation] "); +} + +QString qt_eval_adapt_window_title(const QString &title) +{ + if (qt_eval_days_left() == -2) + return title; + return qt_eval_title_prefix() + title; +} + +void qt_eval_init_widget(QWidget *w) +{ + if (qt_eval_days_left() == -2) + return; + if (w->isTopLevel()) { + QString windowTitle = w->windowTitle(); + if (windowTitle.isEmpty()) { + w->setWindowTitle(QLatin1String(" ")); + } else if (!windowTitle.startsWith(qt_eval_title_prefix())) { + qt_eval_adapt_window_title(windowTitle); + } + } +} +#endif + +QT_END_NAMESPACE diff --git a/src/corelib/statemachine/qabstractstate.cpp b/src/corelib/statemachine/qabstractstate.cpp index 72d640b..cf67cdd 100644 --- a/src/corelib/statemachine/qabstractstate.cpp +++ b/src/corelib/statemachine/qabstractstate.cpp @@ -78,7 +78,8 @@ QT_BEGIN_NAMESPACE function to perform custom processing when the state is exited. */ -QAbstractStatePrivate::QAbstractStatePrivate() +QAbstractStatePrivate::QAbstractStatePrivate() + : parentState(0) { } @@ -150,7 +151,10 @@ QAbstractState::~QAbstractState() */ QState *QAbstractState::parentState() const { - return qobject_cast<QState*>(parent()); + Q_D(const QAbstractState); + if (d->parentState != parent()) + d->parentState = qobject_cast<QState*>(parent()); + return d->parentState; } /*! diff --git a/src/corelib/statemachine/qabstractstate_p.h b/src/corelib/statemachine/qabstractstate_p.h index 4b1306d..cd57815 100644 --- a/src/corelib/statemachine/qabstractstate_p.h +++ b/src/corelib/statemachine/qabstractstate_p.h @@ -76,6 +76,8 @@ public: void emitEntered(); void emitExited(); + + mutable QState *parentState; }; QT_END_NAMESPACE diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp index a6e4a57..bcd8364 100644 --- a/src/corelib/statemachine/qstate.cpp +++ b/src/corelib/statemachine/qstate.cpp @@ -124,7 +124,8 @@ QT_BEGIN_NAMESPACE */ QStatePrivate::QStatePrivate() - : errorState(0), initialState(0), childMode(QState::ExclusiveStates) + : errorState(0), initialState(0), childMode(QState::ExclusiveStates), + childStatesListNeedsRefresh(true), transitionsListNeedsRefresh(true) { } @@ -180,15 +181,18 @@ QState::~QState() QList<QAbstractState*> QStatePrivate::childStates() const { - QList<QAbstractState*> result; - QList<QObject*>::const_iterator it; - for (it = children.constBegin(); it != children.constEnd(); ++it) { - QAbstractState *s = qobject_cast<QAbstractState*>(*it); - if (!s || qobject_cast<QHistoryState*>(s)) - continue; - result.append(s); + if (childStatesListNeedsRefresh) { + childStatesList.clear(); + QList<QObject*>::const_iterator it; + for (it = children.constBegin(); it != children.constEnd(); ++it) { + QAbstractState *s = qobject_cast<QAbstractState*>(*it); + if (!s || qobject_cast<QHistoryState*>(s)) + continue; + childStatesList.append(s); + } + childStatesListNeedsRefresh = false; } - return result; + return childStatesList; } QList<QHistoryState*> QStatePrivate::historyStates() const @@ -205,14 +209,17 @@ QList<QHistoryState*> QStatePrivate::historyStates() const QList<QAbstractTransition*> QStatePrivate::transitions() const { - QList<QAbstractTransition*> result; - QList<QObject*>::const_iterator it; - for (it = children.constBegin(); it != children.constEnd(); ++it) { - QAbstractTransition *t = qobject_cast<QAbstractTransition*>(*it); - if (t) - result.append(t); + if (transitionsListNeedsRefresh) { + transitionsList.clear(); + QList<QObject*>::const_iterator it; + for (it = children.constBegin(); it != children.constEnd(); ++it) { + QAbstractTransition *t = qobject_cast<QAbstractTransition*>(*it); + if (t) + transitionsList.append(t); + } + transitionsListNeedsRefresh = false; } - return result; + return transitionsList; } #ifndef QT_NO_PROPERTIES @@ -468,6 +475,11 @@ void QState::setChildMode(ChildMode mode) */ bool QState::event(QEvent *e) { + Q_D(QState); + if ((e->type() == QEvent::ChildAdded) || (e->type() == QEvent::ChildRemoved)) { + d->childStatesListNeedsRefresh = true; + d->transitionsListNeedsRefresh = true; + } return QAbstractState::event(e); } diff --git a/src/corelib/statemachine/qstate_p.h b/src/corelib/statemachine/qstate_p.h index 20cda29..34c8838 100644 --- a/src/corelib/statemachine/qstate_p.h +++ b/src/corelib/statemachine/qstate_p.h @@ -99,6 +99,10 @@ public: QAbstractState *errorState; QAbstractState *initialState; QState::ChildMode childMode; + mutable bool childStatesListNeedsRefresh; + mutable QList<QAbstractState*> childStatesList; + mutable bool transitionsListNeedsRefresh; + mutable QList<QAbstractTransition*> transitionsList; QList<QPropertyAssignment> propertyAssignments; }; diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index e182c88..689967a 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -1216,8 +1216,7 @@ void QStateMachinePrivate::_q_process() delete e; e = 0; } - if (enabledTransitions.isEmpty() && !internalEventQueue.isEmpty()) { - e = internalEventQueue.takeFirst(); + if (enabledTransitions.isEmpty() && ((e = dequeueInternalEvent()) != 0)) { #ifdef QSTATEMACHINE_DEBUG qDebug() << q << ": dequeued internal event" << e << "of type" << e->type(); #endif @@ -1228,13 +1227,7 @@ void QStateMachinePrivate::_q_process() } } if (enabledTransitions.isEmpty()) { - if (externalEventQueue.isEmpty()) { - if (internalEventQueue.isEmpty()) { - processing = false; - stopProcessingReason = EventQueueEmpty; - } - } else { - e = externalEventQueue.takeFirst(); + if ((e = dequeueExternalEvent()) != 0) { #ifdef QSTATEMACHINE_DEBUG qDebug() << q << ": dequeued external event" << e << "of type" << e->type(); #endif @@ -1243,6 +1236,11 @@ void QStateMachinePrivate::_q_process() delete e; e = 0; } + } else { + if (isInternalEventQueueEmpty()) { + processing = false; + stopProcessingReason = EventQueueEmpty; + } } } if (!enabledTransitions.isEmpty()) { @@ -1278,17 +1276,60 @@ void QStateMachinePrivate::_q_process() } } +void QStateMachinePrivate::postInternalEvent(QEvent *e) +{ + QMutexLocker locker(&internalEventMutex); + internalEventQueue.append(e); +} + +void QStateMachinePrivate::postExternalEvent(QEvent *e) +{ + QMutexLocker locker(&externalEventMutex); + externalEventQueue.append(e); +} + +QEvent *QStateMachinePrivate::dequeueInternalEvent() +{ + QMutexLocker locker(&internalEventMutex); + if (internalEventQueue.isEmpty()) + return 0; + return internalEventQueue.takeFirst(); +} + +QEvent *QStateMachinePrivate::dequeueExternalEvent() +{ + QMutexLocker locker(&externalEventMutex); + if (externalEventQueue.isEmpty()) + return 0; + return externalEventQueue.takeFirst(); +} + +bool QStateMachinePrivate::isInternalEventQueueEmpty() +{ + QMutexLocker locker(&internalEventMutex); + return internalEventQueue.isEmpty(); +} + +bool QStateMachinePrivate::isExternalEventQueueEmpty() +{ + QMutexLocker locker(&externalEventMutex); + return externalEventQueue.isEmpty(); +} + void QStateMachinePrivate::processEvents(EventProcessingMode processingMode) { + Q_Q(QStateMachine); if ((state != Running) || processing || processingScheduled) return; switch (processingMode) { case DirectProcessing: - _q_process(); - break; + if (QThread::currentThread() == q->thread()) { + _q_process(); + break; + } // fallthrough -- processing must be done in the machine thread case QueuedProcessing: processingScheduled = true; - QMetaObject::invokeMethod(q_func(), "_q_process", Qt::QueuedConnection); + QMetaObject::invokeMethod(q, "_q_process", Qt::QueuedConnection); break; } } @@ -1296,6 +1337,7 @@ void QStateMachinePrivate::processEvents(EventProcessingMode processingMode) void QStateMachinePrivate::cancelAllDelayedEvents() { Q_Q(QStateMachine); + QMutexLocker locker(&delayedEventsMutex); QHash<int, QEvent*>::const_iterator it; for (it = delayedEvents.constBegin(); it != delayedEvents.constEnd(); ++it) { int id = it.key(); @@ -1547,7 +1589,7 @@ void QStateMachinePrivate::handleFilteredEvent(QObject *watched, QEvent *event) { Q_ASSERT(qobjectEvents.contains(watched)); if (qobjectEvents[watched].contains(event->type())) { - internalEventQueue.append(new QStateMachine::WrappedEvent(watched, handler->cloneEvent(event))); + postInternalEvent(new QStateMachine::WrappedEvent(watched, handler->cloneEvent(event))); processEvents(DirectProcessing); } } @@ -1571,7 +1613,7 @@ void QStateMachinePrivate::handleTransitionSignal(QObject *sender, int signalInd qDebug() << q_func() << ": sending signal event ( sender =" << sender << ", signal =" << sender->metaObject()->method(signalIndex).signature() << ')'; #endif - internalEventQueue.append(new QStateMachine::SignalEvent(sender, signalIndex, vargs)); + postInternalEvent(new QStateMachine::SignalEvent(sender, signalIndex, vargs)); processEvents(DirectProcessing); } @@ -1825,6 +1867,8 @@ void QStateMachine::stop() } /*! + \threadsafe + Posts the given \a event of the given \a priority for processing by this state machine. @@ -1852,16 +1896,18 @@ void QStateMachine::postEvent(QEvent *event, EventPriority priority) #endif switch (priority) { case NormalPriority: - d->externalEventQueue.append(event); + d->postExternalEvent(event); break; case HighPriority: - d->internalEventQueue.append(event); + d->postInternalEvent(event); break; } d->processEvents(QStateMachinePrivate::QueuedProcessing); } /*! + \threadsafe + Posts the given \a event for processing by this state machine, with the given \a delay in milliseconds. Returns an identifier associated with the delayed event, or -1 if the event could not be posted. @@ -1893,12 +1939,15 @@ int QStateMachine::postDelayedEvent(QEvent *event, int delay) #ifdef QSTATEMACHINE_DEBUG qDebug() << this << ": posting event" << event << "with delay" << delay; #endif + QMutexLocker locker(&d->delayedEventsMutex); int tid = startTimer(delay); d->delayedEvents[tid] = event; return tid; } /*! + \threadsafe + Cancels the delayed event identified by the given \a id. The id should be a value returned by a call to postDelayedEvent(). Returns true if the event was successfully cancelled, otherwise returns false. @@ -1912,6 +1961,7 @@ bool QStateMachine::cancelDelayedEvent(int id) qWarning("QStateMachine::cancelDelayedEvent: the machine is not running"); return false; } + QMutexLocker locker(&d->delayedEventsMutex); QEvent *e = d->delayedEvents.take(id); if (!e) return false; @@ -1921,8 +1971,6 @@ bool QStateMachine::cancelDelayedEvent(int id) } /*! - \internal - Returns the maximal consistent set of states (including parallel and final states) that this state machine is currently in. If a state \c s is in the configuration, it is always the case that the parent of \c s is also in @@ -1963,18 +2011,23 @@ bool QStateMachine::event(QEvent *e) int tid = te->timerId(); if (d->state != QStateMachinePrivate::Running) { // This event has been cancelled already + QMutexLocker locker(&d->delayedEventsMutex); Q_ASSERT(!d->delayedEvents.contains(tid)); return true; } + d->delayedEventsMutex.lock(); QEvent *ee = d->delayedEvents.take(tid); if (ee != 0) { killTimer(tid); - d->externalEventQueue.append(ee); + d->delayedEventsMutex.unlock(); + d->postExternalEvent(ee); d->processEvents(QStateMachinePrivate::DirectProcessing); return true; + } else { + d->delayedEventsMutex.unlock(); } } - return QObject::event(e); + return QState::event(e); } #ifndef QT_NO_STATEMACHINE_EVENTFILTER diff --git a/src/corelib/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h index cf7a073..69b727d 100644 --- a/src/corelib/statemachine/qstatemachine_p.h +++ b/src/corelib/statemachine/qstatemachine_p.h @@ -58,6 +58,7 @@ #include <QtCore/qcoreevent.h> #include <QtCore/qhash.h> #include <QtCore/qlist.h> +#include <QtCore/qmutex.h> #include <QtCore/qpair.h> #include <QtCore/qset.h> #include <QtCore/qvector.h> @@ -159,6 +160,13 @@ public: void unregisterAllTransitions(); void handleTransitionSignal(QObject *sender, int signalIndex, void **args); + + void postInternalEvent(QEvent *e); + void postExternalEvent(QEvent *e); + QEvent *dequeueInternalEvent(); + QEvent *dequeueExternalEvent(); + bool isInternalEventQueueEmpty(); + bool isExternalEventQueueEmpty(); void processEvents(EventProcessingMode processingMode); void cancelAllDelayedEvents(); @@ -181,6 +189,8 @@ public: QSet<QAbstractState*> configuration; QList<QEvent*> internalEventQueue; QList<QEvent*> externalEventQueue; + QMutex internalEventMutex; + QMutex externalEventMutex; QStateMachine::Error error; QStateMachine::RestorePolicy globalRestorePolicy; @@ -214,6 +224,7 @@ public: QHash<QObject*, QHash<QEvent::Type, int> > qobjectEvents; #endif QHash<int, QEvent*> delayedEvents; + QMutex delayedEventsMutex; typedef QEvent* (*f_cloneEvent)(QEvent*); struct Handler { diff --git a/src/gui/kernel/qdesktopwidget.cpp b/src/gui/kernel/qdesktopwidget.cpp index b1e1008..c6d5000 100644 --- a/src/gui/kernel/qdesktopwidget.cpp +++ b/src/gui/kernel/qdesktopwidget.cpp @@ -40,12 +40,11 @@ ****************************************************************************/ #include "qglobal.h" - -QT_BEGIN_NAMESPACE - #include "qdesktopwidget.h" #include "qwidget_p.h" +QT_BEGIN_NAMESPACE + const QRect QDesktopWidget::screenGeometry(const QWidget *widget) const { QRect rect = QWidgetPrivate::screenGeometry(widget); diff --git a/src/gui/kernel/qt_cocoa_helpers_mac_p.h b/src/gui/kernel/qt_cocoa_helpers_mac_p.h index 62db064..5318d31 100644 --- a/src/gui/kernel/qt_cocoa_helpers_mac_p.h +++ b/src/gui/kernel/qt_cocoa_helpers_mac_p.h @@ -116,7 +116,7 @@ typedef struct CGPoint NSPoint; QT_BEGIN_NAMESPACE Qt::MouseButtons qt_mac_get_buttons(int buttons); Qt::MouseButton qt_mac_get_button(EventMouseButton button); -void macWindowFade(void * /*OSWindowRef*/ window, float durationSeconds = 0); +void macWindowFade(void * /*OSWindowRef*/ window, float durationSeconds = 0.15); bool macWindowIsTextured(void * /*OSWindowRef*/ window); void macWindowToolbarShow(const QWidget *widget, bool show ); void macWindowToolbarSet( void * /*OSWindowRef*/ window, void* toolbarRef ); diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm index 95c0bed..58252ca 100644 --- a/src/gui/kernel/qwidget_mac.mm +++ b/src/gui/kernel/qwidget_mac.mm @@ -2896,6 +2896,7 @@ void QWidgetPrivate::setCursor_sys(const QCursor &) #else Q_Q(QWidget); if (q->testAttribute(Qt::WA_WState_Created)) { + QMacCocoaAutoReleasePool pool; [qt_mac_window_for(q) invalidateCursorRectsForView:qt_mac_nativeview_for(q)]; } #endif @@ -2908,6 +2909,7 @@ void QWidgetPrivate::unsetCursor_sys() #else Q_Q(QWidget); if (q->testAttribute(Qt::WA_WState_Created)) { + QMacCocoaAutoReleasePool pool; [qt_mac_window_for(q) invalidateCursorRectsForView:qt_mac_nativeview_for(q)]; } #endif diff --git a/src/network/socket/qnativesocketengine.cpp b/src/network/socket/qnativesocketengine.cpp index e7f8401..8de821b 100644 --- a/src/network/socket/qnativesocketengine.cpp +++ b/src/network/socket/qnativesocketengine.cpp @@ -194,82 +194,82 @@ void QNativeSocketEnginePrivate::setError(QAbstractSocket::SocketError error, Er switch (errorString) { case NonBlockingInitFailedErrorString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Unable to initialize non-blocking socket")); + socketErrorString = QNativeSocketEngine::tr("Unable to initialize non-blocking socket"); break; case BroadcastingInitFailedErrorString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Unable to initialize broadcast socket")); + socketErrorString = QNativeSocketEngine::tr("Unable to initialize broadcast socket"); break; case NoIpV6ErrorString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Attempt to use IPv6 socket on a platform with no IPv6 support")); + socketErrorString = QNativeSocketEngine::tr("Attempt to use IPv6 socket on a platform with no IPv6 support"); break; case RemoteHostClosedErrorString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "The remote host closed the connection")); + socketErrorString = QNativeSocketEngine::tr("The remote host closed the connection"); break; case TimeOutErrorString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Network operation timed out")); + socketErrorString = QNativeSocketEngine::tr("Network operation timed out"); break; case ResourceErrorString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Out of resources")); + socketErrorString = QNativeSocketEngine::tr("Out of resources"); break; case OperationUnsupportedErrorString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Unsupported socket operation")); + socketErrorString = QNativeSocketEngine::tr("Unsupported socket operation"); break; case ProtocolUnsupportedErrorString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Protocol type not supported")); + socketErrorString = QNativeSocketEngine::tr("Protocol type not supported"); break; case InvalidSocketErrorString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Invalid socket descriptor")); + socketErrorString = QNativeSocketEngine::tr("Invalid socket descriptor"); break; case HostUnreachableErrorString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Host unreachable")); + socketErrorString = QNativeSocketEngine::tr("Host unreachable"); break; case NetworkUnreachableErrorString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Network unreachable")); + socketErrorString = QNativeSocketEngine::tr("Network unreachable"); break; case AccessErrorString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Permission denied")); + socketErrorString = QNativeSocketEngine::tr("Permission denied"); break; case ConnectionTimeOutErrorString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Connection timed out")); + socketErrorString = QNativeSocketEngine::tr("Connection timed out"); break; case ConnectionRefusedErrorString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Connection refused")); + socketErrorString = QNativeSocketEngine::tr("Connection refused"); break; case AddressInuseErrorString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "The bound address is already in use")); + socketErrorString = QNativeSocketEngine::tr("The bound address is already in use"); break; case AddressNotAvailableErrorString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "The address is not available")); + socketErrorString = QNativeSocketEngine::tr("The address is not available"); break; case AddressProtectedErrorString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "The address is protected")); + socketErrorString = QNativeSocketEngine::tr("The address is protected"); break; case DatagramTooLargeErrorString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Datagram was too large to send")); + socketErrorString = QNativeSocketEngine::tr("Datagram was too large to send"); break; case SendDatagramErrorString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Unable to send a message")); + socketErrorString = QNativeSocketEngine::tr("Unable to send a message"); break; case ReceiveDatagramErrorString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Unable to receive a message")); + socketErrorString = QNativeSocketEngine::tr("Unable to receive a message"); break; case WriteErrorString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Unable to write")); + socketErrorString = QNativeSocketEngine::tr("Unable to write"); break; case ReadErrorString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Network error")); + socketErrorString = QNativeSocketEngine::tr("Network error"); break; case PortInuseErrorString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Another socket is already listening on the same port")); + socketErrorString = QNativeSocketEngine::tr("Another socket is already listening on the same port"); break; case NotSocketErrorString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Operation on non-socket")); + socketErrorString = QNativeSocketEngine::tr("Operation on non-socket"); break; case InvalidProxyTypeString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "The proxy type is invalid for this operation")); + socketErrorString = QNativeSocketEngine::tr("The proxy type is invalid for this operation"); break; case UnknownSocketErrorString: - socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Unknown error")); + socketErrorString = QNativeSocketEngine::tr("Unknown error"); break; } } diff --git a/src/network/ssl/qsslerror.cpp b/src/network/ssl/qsslerror.cpp index 62fcd4c..4bb58b1 100644 --- a/src/network/ssl/qsslerror.cpp +++ b/src/network/ssl/qsslerror.cpp @@ -91,6 +91,7 @@ */ #include "qsslerror.h" +#include "qsslsocket.h" #ifndef QT_NO_DEBUG_STREAM #include <QtCore/qdebug.h> @@ -209,81 +210,79 @@ QString QSslError::errorString() const QString errStr; switch (d->error) { case NoError: - errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "No error")); + errStr = QSslSocket::tr("No error"); break; case UnableToGetIssuerCertificate: - errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The issuer certificate could not be found")); + errStr = QSslSocket::tr("The issuer certificate could not be found"); break; case UnableToDecryptCertificateSignature: - errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The certificate signature could not be decrypted")); + errStr = QSslSocket::tr("The certificate signature could not be decrypted"); break; case UnableToDecodeIssuerPublicKey: - errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The public key in the certificate could not be read")); + errStr = QSslSocket::tr("The public key in the certificate could not be read"); break; case CertificateSignatureFailed: - errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The signature of the certificate is invalid")); + errStr = QSslSocket::tr("The signature of the certificate is invalid"); break; case CertificateNotYetValid: - errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The certificate is not yet valid")); + errStr = QSslSocket::tr("The certificate is not yet valid"); break; case CertificateExpired: - errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The certificate has expired")); + errStr = QSslSocket::tr("The certificate has expired"); break; case InvalidNotBeforeField: - errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The certificate's notBefore field contains an invalid time")); + errStr = QSslSocket::tr("The certificate's notBefore field contains an invalid time"); break; case InvalidNotAfterField: - errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The certificate's notAfter field contains an invalid time")); + errStr = QSslSocket::tr("The certificate's notAfter field contains an invalid time"); break; case SelfSignedCertificate: - errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The certificate is self-signed, and untrusted")); + errStr = QSslSocket::tr("The certificate is self-signed, and untrusted"); break; case SelfSignedCertificateInChain: - errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The root certificate of the certificate chain is self-signed, and untrusted")); + errStr = QSslSocket::tr("The root certificate of the certificate chain is self-signed, and untrusted"); break; case UnableToGetLocalIssuerCertificate: - errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The issuer certificate of a locally looked up certificate could not be found")); + errStr = QSslSocket::tr("The issuer certificate of a locally looked up certificate could not be found"); break; case UnableToVerifyFirstCertificate: - errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "No certificates could be verified")); + errStr = QSslSocket::tr("No certificates could be verified"); break; case InvalidCaCertificate: - errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "One of the CA certificates is invalid")); + errStr = QSslSocket::tr("One of the CA certificates is invalid"); break; case PathLengthExceeded: - errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The basicConstraints pathlength parameter has been exceeded")); + errStr = QSslSocket::tr("The basicConstraints pathlength parameter has been exceeded"); break; case InvalidPurpose: - errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The supplied certificate is unsuited for this purpose")); + errStr = QSslSocket::tr("The supplied certificate is unsuited for this purpose"); break; case CertificateUntrusted: - errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The root CA certificate is not trusted for this purpose")); + errStr = QSslSocket::tr("The root CA certificate is not trusted for this purpose"); break; case CertificateRejected: - errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The root CA certificate is marked to reject the specified purpose")); + errStr = QSslSocket::tr("The root CA certificate is marked to reject the specified purpose"); break; case SubjectIssuerMismatch: // hostname mismatch - errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, - "The current candidate issuer certificate was rejected because its" - " subject name did not match the issuer name of the current certificate")); + errStr = QSslSocket::tr("The current candidate issuer certificate was rejected because its" + " subject name did not match the issuer name of the current certificate"); break; case AuthorityIssuerSerialNumberMismatch: - errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The current candidate issuer certificate was rejected because" - " its issuer name and serial number was present and did not match the" - " authority key identifier of the current certificate")); + errStr = QSslSocket::tr("The current candidate issuer certificate was rejected because" + " its issuer name and serial number was present and did not match the" + " authority key identifier of the current certificate"); break; case NoPeerCertificate: - errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The peer did not present any certificate")); + errStr = QSslSocket::tr("The peer did not present any certificate"); break; case HostNameMismatch: - errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, - "The host name did not match any of the valid hosts" - " for this certificate")); + errStr = QSslSocket::tr("The host name did not match any of the valid hosts" + " for this certificate"); break; case NoSslSupport: break; default: - errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "Unknown error")); + errStr = QSslSocket::tr("Unknown error"); break; } diff --git a/src/opengl/gl2paintengineex/qtriangulatingstroker.cpp b/src/opengl/gl2paintengineex/qtriangulatingstroker.cpp index a5a743f..ad18a51 100644 --- a/src/opengl/gl2paintengineex/qtriangulatingstroker.cpp +++ b/src/opengl/gl2paintengineex/qtriangulatingstroker.cpp @@ -42,6 +42,7 @@ #include "qtriangulatingstroker_p.h" #include <qmath.h> +QT_BEGIN_NAMESPACE #define CURVE_FLATNESS Q_PI / 8 @@ -338,3 +339,6 @@ void QDashedStrokeProcessor::process(const QVectorPath &path, const QPen &pen) m_dash_stroker.end(); } + +QT_END_NAMESPACE + diff --git a/src/opengl/gl2paintengineex/qtriangulatingstroker_p.h b/src/opengl/gl2paintengineex/qtriangulatingstroker_p.h index ae56e87..97eabef 100644 --- a/src/opengl/gl2paintengineex/qtriangulatingstroker_p.h +++ b/src/opengl/gl2paintengineex/qtriangulatingstroker_p.h @@ -48,6 +48,7 @@ #include <private/qnumeric_p.h> #include <private/qmath_p.h> +QT_BEGIN_NAMESPACE class QTriangulatingStroker { @@ -304,5 +305,6 @@ void QTriangulatingStroker::join(const qreal *pts) emitLineSegment(m_cx, m_cy, m_nvx, m_nvy); } +QT_END_NAMESPACE #endif diff --git a/src/opengl/qglshaderprogram.cpp b/src/opengl/qglshaderprogram.cpp index d028522..90b496e 100644 --- a/src/opengl/qglshaderprogram.cpp +++ b/src/opengl/qglshaderprogram.cpp @@ -612,95 +612,6 @@ bool QGLShader::compileFile(const QString& fileName) } /*! - Sets the binary code for this shader to the \a length bytes from - the array \a binary. The \a format specifies how the binary data - should be interpreted by the OpenGL engine. Returns true if the - binary was set on the shader; false otherwise. - - This function cannot be used with PartialVertexShader or - PartialFragmentShader. - - If this function succeeds, then the shader will be considered compiled. - - \sa shaderBinaryFormats() -*/ -bool QGLShader::setShaderBinary(GLenum format, const void *binary, int length) -{ - Q_D(QGLShader); -#if !defined(QT_OPENGL_ES_2) - if (!glShaderBinary) - return false; -#endif - GLuint shader = d->shaderGuard.id(); - if (d->isPartial || !shader) - return false; - glGetError(); // Clear error state. - glShaderBinary(1, &shader, format, binary, length); - d->compiled = (glGetError() == GL_NO_ERROR); - return d->compiled; -} - -/*! - Sets the binary code for this shader to the \a length bytes from - the array \a binary. The \a format specifies how the binary data - should be interpreted by the OpenGL engine. Returns true if the - binary was set on the shader; false otherwise. - - The \a otherShader will also have binary code set on it. This is - for the case where \a binary contains both vertex and fragment - shader code. - - This function cannot be used with PartialVertexShader or - PartialFragmentShader. - - If this function succeeds, then the shader will be considered compiled. - - \sa shaderBinaryFormats() -*/ -bool QGLShader::setShaderBinary - (QGLShader& otherShader, GLenum format, const void *binary, int length) -{ - Q_D(QGLShader); -#if !defined(QT_OPENGL_ES_2) - if (!glShaderBinary) - return false; -#endif - if (d->isPartial || !d->shaderGuard.id()) - return false; - if (otherShader.d_func()->isPartial || !otherShader.d_func()->shaderGuard.id()) - return false; - glGetError(); // Clear error state. - GLuint shaders[2]; - shaders[0] = d->shaderGuard.id(); - shaders[1] = otherShader.d_func()->shaderGuard.id(); - glShaderBinary(2, shaders, format, binary, length); - d->compiled = (glGetError() == GL_NO_ERROR); - otherShader.d_func()->compiled = d->compiled; - return d->compiled; -} - -/*! - Returns a list of all binary formats that are supported by - setShaderBinary() on this system. - - \sa setShaderBinary() -*/ -QList<GLenum> QGLShader::shaderBinaryFormats() -{ - GLint num; - QList<GLenum> list; - glGetError(); // Clear error state. - glGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &num); - if (glGetError() != GL_NO_ERROR || num <= 0) - return list; - QVarLengthArray<GLint> formats(num); - glGetIntegerv(GL_SHADER_BINARY_FORMATS, formats.data()); - for (GLint i = 0; i < num; ++i) - list += (GLenum)(formats[i]); - return list; -} - -/*! Returns the source code for this shader. \sa compile() @@ -1068,130 +979,6 @@ void QGLShaderProgram::removeAllShaders() d->removingShaders = false; } -#if defined(QT_OPENGL_ES_2) - -#ifndef GL_PROGRAM_BINARY_LENGTH_OES -#define GL_PROGRAM_BINARY_LENGTH_OES 0x8741 -#endif -#ifndef GL_NUM_PROGRAM_BINARY_FORMATS_OES -#define GL_NUM_PROGRAM_BINARY_FORMATS_OES 0x87FE -#endif -#ifndef GL_PROGRAM_BINARY_FORMATS_OES -#define GL_PROGRAM_BINARY_FORMATS_OES 0x87FF -#endif - -#endif - -/*! - Returns the program binary associated with this shader program. - The numeric identifier of the program binary format is returned - in \a format. The \c OES_get_program_binary extension will need - to be supported by the system for binary retrieval to succeed. - - Returns an empty QByteArray if the program binary cannot be - retrieved on this system, or the shader program has not yet - been linked. - - The returned binary can be supplied to setProgramBinary() on the - same machine at some future point to reload the program. It contains - the compiled code of all of the shaders that were attached to the - program at the time programBinary() is called. - - \sa setProgramBinary(), programBinaryFormats() -*/ -QByteArray QGLShaderProgram::programBinary(int *format) const -{ -#if defined(QT_OPENGL_ES_2) - Q_D(const QGLShaderProgram); - if (!isLinked()) - return QByteArray(); - - // Get the length of the binary data, bailing out if there is none. - GLint length = 0; - GLuint program = d->programGuard.id(); - glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH_OES, &length); - if (length <= 0) - return QByteArray(); - - // Retrieve the binary data. - QByteArray binary(length, 0); - GLenum binaryFormat; - glGetProgramBinaryOES(program, length, 0, &binaryFormat, binary.data()); - if (format) - *format = (int)binaryFormat; - return binary; -#else - Q_UNUSED(format); - return QByteArray(); -#endif -} - -/*! - Sets the \a binary for this shader program according to \a format. - Returns true if the binary was set, or false if the binary format - is not supported or this system does not support program binaries. - The program will be linked if the load succeeds. - - \sa programBinary(), programBinaryFormats(), isLinked() -*/ -bool QGLShaderProgram::setProgramBinary(int format, const QByteArray& binary) -{ -#if defined(QT_OPENGL_ES_2) - // Load the binary and check that it was linked correctly. - Q_D(QGLShaderProgram); - GLuint program = d->programGuard.id(); - if (!program) - return false; - glProgramBinaryOES(program, (GLenum)format, - binary.constData(), binary.size()); - GLint value = 0; - glGetProgramiv(program, GL_LINK_STATUS, &value); - d->linked = (value != 0); - value = 0; - glGetProgramiv(program, GL_INFO_LOG_LENGTH, &value); - d->log = QString(); - if (value > 1) { - char *logbuf = new char [value]; - GLint len; - glGetProgramInfoLog(program, value, &len, logbuf); - d->log = QString::fromLatin1(logbuf); - QString name = objectName(); - if (name.isEmpty()) - qWarning() << "QGLShader::setProgramBinary:" << d->log; - else - qWarning() << "QGLShader::setProgramBinary[" << name << "]:" << d->log; - delete [] logbuf; - } - return d->linked; -#else - Q_UNUSED(format); - Q_UNUSED(binary); - return false; -#endif -} - -/*! - Returns the list of program binary formats that are accepted by - this system for use with setProgramBinary(). - - \sa programBinary(), setProgramBinary() -*/ -QList<int> QGLShaderProgram::programBinaryFormats() -{ -#if defined(QT_OPENGL_ES_2) - GLint count = 0; - glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS_OES, &count); - if (count <= 0) - return QList<int>(); - QVector<int> list; - list.resize(count); - glGetIntegerv(GL_PROGRAM_BINARY_FORMATS_OES, list.data()); - return list.toList(); -#else - return QList<int>(); -#endif -} - /*! Links together the shaders that were added to this program with addShader(). Returns true if the link was successful or diff --git a/src/opengl/qglshaderprogram.h b/src/opengl/qglshaderprogram.h index d8b9a0c..708cf09 100644 --- a/src/opengl/qglshaderprogram.h +++ b/src/opengl/qglshaderprogram.h @@ -88,11 +88,6 @@ public: bool compile(const QString& source); bool compileFile(const QString& fileName); - bool setShaderBinary(GLenum format, const void *binary, int length); - bool setShaderBinary(QGLShader& otherShader, GLenum format, const void *binary, int length); - - static QList<GLenum> shaderBinaryFormats(); - QByteArray sourceCode() const; bool isCompiled() const; @@ -133,10 +128,6 @@ public: void removeAllShaders(); - QByteArray programBinary(int *format) const; - bool setProgramBinary(int format, const QByteArray& binary); - static QList<int> programBinaryFormats(); - virtual bool link(); bool isLinked() const; QString log() const; diff --git a/src/openvg/qpaintengine_vg.cpp b/src/openvg/qpaintengine_vg.cpp index 94e0793..8a485a0 100644 --- a/src/openvg/qpaintengine_vg.cpp +++ b/src/openvg/qpaintengine_vg.cpp @@ -3574,51 +3574,48 @@ void QVGCompositionHelper::fillBackground } } -void QVGCompositionHelper::drawCursorImage - (const QImage& image, const QPoint& offset) +void QVGCompositionHelper::drawCursorPixmap + (const QPixmap& pixmap, const QPoint& offset) { - QImage img = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); + VGImage vgImage = VG_INVALID_HANDLE; - VGImage vgImg = vgCreateImage - (VG_sARGB_8888_PRE, img.width(), img.height(), - VG_IMAGE_QUALITY_FASTER); - vgImageSubData - (vgImg, img.bits() + img.bytesPerLine() * (img.height() - 1), - -(img.bytesPerLine()), VG_sARGB_8888_PRE, 0, 0, - img.width(), img.height()); + // Fetch the VGImage from the pixmap if possible. + QPixmapData *pd = pixmap.pixmapData(); + if (pd->classId() == QPixmapData::OpenVGClass) { + QVGPixmapData *vgpd = static_cast<QVGPixmapData *>(pd); + if (vgpd->isValid()) + vgImage = vgpd->toVGImage(); + } - QTransform transform; - int y = screenSize.height() - (offset.y() + img.height()); - transform.translate(offset.x() + 0.5f, y + 0.5f); + // Set the image transformation and modes. + VGfloat devh = screenSize.height() - 1; + QTransform transform(1.0f, 0.0f, 0.0f, + 0.0f, -1.0f, 0.0f, + -0.5f, devh + 0.5f, 1.0f); + transform.translate(offset.x(), offset.y()); d->setTransform(VG_MATRIX_IMAGE_USER_TO_SURFACE, transform); - d->setImageMode(VG_DRAW_IMAGE_NORMAL); - vgDrawImage(vgImg); - vgDestroyImage(vgImg); -} + // Draw the VGImage. + if (vgImage != VG_INVALID_HANDLE) { + vgDrawImage(vgImage); + } else { + QImage img = pixmap.toImage().convertToFormat + (QImage::Format_ARGB32_Premultiplied); -void QVGCompositionHelper::drawCursorPixmap - (const QPixmap& pixmap, const QPoint& offset) -{ - QPixmapData *pd = pixmap.pixmapData(); - if (pd->classId() == QPixmapData::OpenVGClass) { - QVGPixmapData *vgpd = static_cast<QVGPixmapData *>(pd); - if (vgpd->isValid()) { - VGfloat devh = screenSize.height() - 1; - QTransform transform(1.0f, 0.0f, 0.0f, - 0.0f, -1.0f, 0.0f, - -0.5f, devh + 0.5f, 1.0f); - transform.translate(offset.x(), offset.y()); - d->setTransform(VG_MATRIX_IMAGE_USER_TO_SURFACE, transform); - - d->setImageMode(VG_DRAW_IMAGE_NORMAL); - vgDrawImage(vgpd->toVGImage()); + vgImage = vgCreateImage + (VG_sARGB_8888_PRE, img.width(), img.height(), + VG_IMAGE_QUALITY_FASTER); + if (vgImage == VG_INVALID_HANDLE) return; - } - } + vgImageSubData + (vgImage, img.bits() + img.bytesPerLine() * (img.height() - 1), + -(img.bytesPerLine()), VG_sARGB_8888_PRE, 0, 0, + img.width(), img.height()); - drawCursorImage(pixmap.toImage(), offset); + vgDrawImage(vgImage); + vgDestroyImage(vgImage); + } } void QVGCompositionHelper::setScissor(const QRegion& region) diff --git a/src/openvg/qpixmapfilter_vg_p.h b/src/openvg/qpixmapfilter_vg_p.h index efbbc7b..29dd37e 100644 --- a/src/openvg/qpixmapfilter_vg_p.h +++ b/src/openvg/qpixmapfilter_vg_p.h @@ -61,7 +61,7 @@ QT_BEGIN_NAMESPACE #if !defined(QT_SHIVAVG) -class Q_OPENVG_EXPORT QVGPixmapConvolutionFilter : public QPixmapConvolutionFilter +class QVGPixmapConvolutionFilter : public QPixmapConvolutionFilter { Q_OBJECT public: @@ -71,7 +71,7 @@ public: void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect) const; }; -class Q_OPENVG_EXPORT QVGPixmapColorizeFilter : public QPixmapColorizeFilter +class QVGPixmapColorizeFilter : public QPixmapColorizeFilter { Q_OBJECT public: @@ -81,7 +81,7 @@ public: void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect) const; }; -class Q_OPENVG_EXPORT QVGPixmapDropShadowFilter : public QPixmapDropShadowFilter +class QVGPixmapDropShadowFilter : public QPixmapDropShadowFilter { Q_OBJECT public: @@ -91,7 +91,7 @@ public: void draw(QPainter *p, const QPointF &pos, const QPixmap &px, const QRectF &src) const; }; -class Q_OPENVG_EXPORT QVGPixmapBlurFilter : public QPixmapBlurFilter +class QVGPixmapBlurFilter : public QPixmapBlurFilter { Q_OBJECT public: diff --git a/src/openvg/qvgcompositionhelper_p.h b/src/openvg/qvgcompositionhelper_p.h index 6317c3f..3afe31e 100644 --- a/src/openvg/qvgcompositionhelper_p.h +++ b/src/openvg/qvgcompositionhelper_p.h @@ -74,7 +74,6 @@ public: void blitWindow(QVGEGLWindowSurfacePrivate *surface, const QRect& rect, const QPoint& topLeft, int opacity); void fillBackground(const QRegion& region, const QBrush& brush); - void drawCursorImage(const QImage& image, const QPoint& offset); void drawCursorPixmap(const QPixmap& pixmap, const QPoint& offset); void setScissor(const QRegion& region); void clearScissor(); diff --git a/src/openvg/qwindowsurface_vg.cpp b/src/openvg/qwindowsurface_vg.cpp index 661e06a..f8486a6 100644 --- a/src/openvg/qwindowsurface_vg.cpp +++ b/src/openvg/qwindowsurface_vg.cpp @@ -54,8 +54,8 @@ QT_BEGIN_NAMESPACE QVGWindowSurface::QVGWindowSurface(QWidget *window) : QWindowSurface(window) { - d_ptr = QVGEGLWindowSurfacePrivate::create - (QVGEGLWindowSurfacePrivate::WindowSurface, this); + // Create the default type of EGL window surface for windows. + d_ptr = new QVGEGLWindowSurfaceDirect(this); } QVGWindowSurface::QVGWindowSurface diff --git a/src/openvg/qwindowsurface_vgegl.cpp b/src/openvg/qwindowsurface_vgegl.cpp index d622c1f..29d82c8 100644 --- a/src/openvg/qwindowsurface_vgegl.cpp +++ b/src/openvg/qwindowsurface_vgegl.cpp @@ -101,18 +101,6 @@ QImage::Format qt_vg_config_to_image_format(QEglContext *context) return argbFormat; // XXX } -static void copySubImage(QImage *image, VGImage vgImage, const QRect& rect) -{ - vgGetImageSubData - (vgImage, - image->bits() + rect.bottom() * image->bytesPerLine() + - rect.x() * (image->depth() / 8), - -(image->bytesPerLine()), - qt_vg_image_to_vg_format(image->format()), - rect.x(), (image->height() - 1) - rect.bottom(), - rect.width(), rect.height()); -} - #if !defined(QVG_NO_SINGLE_CONTEXT) class QVGSharedContext @@ -205,6 +193,13 @@ static QEglContext *createContext(QPaintDevice *device) return 0; } + // Set the swap interval for the display. + QByteArray interval = qgetenv("QT_VG_SWAP_INTERVAL"); + if (!interval.isEmpty()) + eglSwapInterval(context->display(), interval.toInt()); + else + eglSwapInterval(context->display(), 1); + // Choose an appropriate configuration for rendering into the device. QEglProperties configProps; configProps.setPaintDeviceFormat(device); @@ -336,20 +331,6 @@ QVGEGLWindowSurfacePrivate::~QVGEGLWindowSurfacePrivate() destroyPaintEngine(); } -QVGEGLWindowSurfacePrivate *QVGEGLWindowSurfacePrivate::create - (SurfaceType type, QWindowSurface *win) -{ -#if defined(QVG_VGIMAGE_BACKBUFFERS) - if (type == VGImageSurface) - return new QVGEGLWindowSurfaceVGImage(win); - else if (type == QImageSurface) - return new QVGEGLWindowSurfaceQImage(win); -#endif - if (type == WindowSurface) - return new QVGEGLWindowSurfaceDirect(win); - return 0; -} - QVGPaintEngine *QVGEGLWindowSurfacePrivate::paintEngine() { if (!engine) @@ -514,39 +495,6 @@ EGLSurface QVGEGLWindowSurfaceVGImage::mainSurface() const return qt_vg_shared_surface(); } -QVGEGLWindowSurfaceQImage::QVGEGLWindowSurfaceQImage(QWindowSurface *win) - : QVGEGLWindowSurfaceVGImage(win) -{ -} - -QVGEGLWindowSurfaceQImage::~QVGEGLWindowSurfaceQImage() -{ -} - -void QVGEGLWindowSurfaceQImage::endPaint - (QWidget *widget, const QRegion& region, QImage *image) -{ - QEglContext *context = ensureContext(widget); - if (context) { - if (backBufferSurface != EGL_NO_SURFACE) { - if (isPaintingActive) - vgFlush(); - context->makeCurrent(mainSurface()); - QRegion rgn = region.intersected - (QRect(0, 0, image->width(), image->height())); - if (rgn.numRects() == 1) { - copySubImage(image, backBuffer, rgn.boundingRect()); - } else { - QVector<QRect> rects = rgn.rects(); - for (int index = 0; index < rects.size(); ++index) - copySubImage(image, backBuffer, rects[index]); - } - context->lazyDoneCurrent(); - } - isPaintingActive = false; - } -} - #endif // QVG_VGIMAGE_BACKBUFFERS QVGEGLWindowSurfaceDirect::QVGEGLWindowSurfaceDirect(QWindowSurface *win) diff --git a/src/openvg/qwindowsurface_vgegl_p.h b/src/openvg/qwindowsurface_vgegl_p.h index fa36b94..7fa60ea 100644 --- a/src/openvg/qwindowsurface_vgegl_p.h +++ b/src/openvg/qwindowsurface_vgegl_p.h @@ -70,16 +70,6 @@ public: QVGEGLWindowSurfacePrivate(QWindowSurface *win); virtual ~QVGEGLWindowSurfacePrivate(); - enum SurfaceType - { - WindowSurface, - VGImageSurface, - QImageSurface - }; - - static QVGEGLWindowSurfacePrivate *create - (SurfaceType type, QWindowSurface *win); - QVGPaintEngine *paintEngine(); virtual QEglContext *ensureContext(QWidget *widget) = 0; virtual void beginPaint(QWidget *widget) = 0; @@ -126,15 +116,6 @@ protected: EGLSurface mainSurface() const; }; -class Q_OPENVG_EXPORT QVGEGLWindowSurfaceQImage : public QVGEGLWindowSurfaceVGImage -{ -public: - QVGEGLWindowSurfaceQImage(QWindowSurface *win); - virtual ~QVGEGLWindowSurfaceQImage(); - - void endPaint(QWidget *widget, const QRegion& region, QImage *image); -}; - #endif // EGL_OPENVG_IMAGE class Q_OPENVG_EXPORT QVGEGLWindowSurfaceDirect : public QVGEGLWindowSurfacePrivate diff --git a/src/script/api/api.pri b/src/script/api/api.pri index 17ec9b6..aebadd5 100644 --- a/src/script/api/api.pri +++ b/src/script/api/api.pri @@ -6,6 +6,7 @@ SOURCES += \ $$PWD/qscriptengine.cpp \ $$PWD/qscriptengineagent.cpp \ $$PWD/qscriptextensionplugin.cpp \ + $$PWD/qscriptprogram.cpp \ $$PWD/qscriptstring.cpp \ $$PWD/qscriptvalue.cpp \ $$PWD/qscriptvalueiterator.cpp \ @@ -23,6 +24,8 @@ HEADERS += \ $$PWD/qscriptengineagent_p.h \ $$PWD/qscriptextensioninterface.h \ $$PWD/qscriptextensionplugin.h \ + $$PWD/qscriptprogram.h \ + $$PWD/qscriptprogram_p.h \ $$PWD/qscriptstring.h \ $$PWD/qscriptstring_p.h \ $$PWD/qscriptvalue.h \ diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index 9288723..2b60a46 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -51,6 +51,8 @@ #include "qscriptvalue_p.h" #include "qscriptvalueiterator.h" #include "qscriptclass.h" +#include "qscriptprogram.h" +#include "qscriptprogram_p.h" #include "qdebug.h" #include <QtCore/qstringlist.h> @@ -1155,6 +1157,73 @@ void QScriptEnginePrivate::agentDeleted(QScriptEngineAgent *agent) } } +JSC::JSValue QScriptEnginePrivate::evaluateHelper(JSC::ExecState *exec, intptr_t sourceId, + JSC::EvalExecutable *executable, + bool &compile) +{ + Q_Q(QScriptEngine); + JSC::JSLock lock(false); // ### hmmm + QBoolBlocker inEvalBlocker(inEval, true); + q->currentContext()->activationObject(); //force the creation of a context for native function; + + JSC::Debugger* debugger = originalGlobalObject()->debugger(); + if (debugger) + debugger->evaluateStart(sourceId); + + q->clearExceptions(); + JSC::DynamicGlobalObjectScope dynamicGlobalObjectScope(exec, exec->scopeChain()->globalObject()); + + if (compile) { + JSC::JSObject* error = executable->compile(exec, exec->scopeChain()); + if (error) { + compile = false; + exec->setException(error); + + if (debugger) { + debugger->exceptionThrow(JSC::DebuggerCallFrame(exec, error), sourceId, false); + debugger->evaluateStop(error, sourceId); + } + + return error; + } + } + + JSC::JSValue thisValue = thisForContext(exec); + JSC::JSObject* thisObject = (!thisValue || thisValue.isUndefinedOrNull()) + ? exec->dynamicGlobalObject() : thisValue.toObject(exec); + JSC::JSValue exceptionValue; + timeoutChecker()->setShouldAbort(false); + if (processEventsInterval > 0) + timeoutChecker()->reset(); + + JSC::JSValue result = exec->interpreter()->execute(executable, exec, thisObject, exec->scopeChain(), &exceptionValue); + + if (timeoutChecker()->shouldAbort()) { + if (abortResult.isError()) + exec->setException(scriptValueToJSCValue(abortResult)); + + if (debugger) + debugger->evaluateStop(scriptValueToJSCValue(abortResult), sourceId); + + return scriptValueToJSCValue(abortResult); + } + + if (exceptionValue) { + exec->setException(exceptionValue); + + if (debugger) + debugger->evaluateStop(exceptionValue, sourceId); + + return exceptionValue; + } + + if (debugger) + debugger->evaluateStop(result, sourceId); + + Q_ASSERT(!exec->hadException()); + return result; +} + #ifndef QT_NO_QOBJECT JSC::JSValue QScriptEnginePrivate::newQObject( @@ -2115,75 +2184,41 @@ QScriptSyntaxCheckResult QScriptEnginePrivate::checkSyntax(const QString &progra QScriptValue QScriptEngine::evaluate(const QString &program, const QString &fileName, int lineNumber) { Q_D(QScriptEngine); - - JSC::JSLock lock(false); // ### hmmm - QBoolBlocker inEval(d->inEval, true); - currentContext()->activationObject(); //force the creation of a context for native function; - - JSC::Debugger* debugger = d->originalGlobalObject()->debugger(); - - JSC::UString jscProgram = program; - JSC::UString jscFileName = fileName; - JSC::ExecState* exec = d->currentFrame; WTF::PassRefPtr<QScript::UStringSourceProviderWithFeedback> provider - = QScript::UStringSourceProviderWithFeedback::create(jscProgram, jscFileName, lineNumber, d); + = QScript::UStringSourceProviderWithFeedback::create(program, fileName, lineNumber, d); intptr_t sourceId = provider->asID(); JSC::SourceCode source(provider, lineNumber); //after construction of SourceCode provider variable will be null. - if (debugger) - debugger->evaluateStart(sourceId); - - clearExceptions(); - JSC::DynamicGlobalObjectScope dynamicGlobalObjectScope(exec, exec->scopeChain()->globalObject()); - + JSC::ExecState* exec = d->currentFrame; JSC::EvalExecutable executable(exec, source); - JSC::JSObject* error = executable.compile(exec, exec->scopeChain()); - if (error) { - exec->setException(error); - - if (debugger) { - debugger->exceptionThrow(JSC::DebuggerCallFrame(exec, error), sourceId, false); - debugger->evaluateStop(error, sourceId); - } - - return d->scriptValueFromJSCValue(error); - } - - JSC::JSValue thisValue = d->thisForContext(exec); - JSC::JSObject* thisObject = (!thisValue || thisValue.isUndefinedOrNull()) ? exec->dynamicGlobalObject() : thisValue.toObject(exec); - JSC::JSValue exceptionValue; - d->timeoutChecker()->setShouldAbort(false); - if (d->processEventsInterval > 0) - d->timeoutChecker()->reset(); - JSC::JSValue result = exec->interpreter()->execute(&executable, exec, thisObject, exec->scopeChain(), &exceptionValue); - - if (d->timeoutChecker()->shouldAbort()) { - if (d->abortResult.isError()) - exec->setException(d->scriptValueToJSCValue(d->abortResult)); - - if (debugger) - debugger->evaluateStop(d->scriptValueToJSCValue(d->abortResult), sourceId); - - return d->abortResult; - } - - if (exceptionValue) { - exec->setException(exceptionValue); - - if (debugger) - debugger->evaluateStop(exceptionValue, sourceId); + bool compile = true; + return d->scriptValueFromJSCValue(d->evaluateHelper(exec, sourceId, &executable, compile)); +} - return d->scriptValueFromJSCValue(exceptionValue); - } +/*! + \internal + \since 4.6 - if (debugger) - debugger->evaluateStop(result, sourceId); + Evaluates the given \a program and returns the result of the + evaluation. +*/ +QScriptValue QScriptEngine::evaluate(const QScriptProgram &program) +{ + Q_D(QScriptEngine); + QScriptProgramPrivate *program_d = QScriptProgramPrivate::get(program); + if (!program_d) + return QScriptValue(); - Q_ASSERT(!exec->hadException()); + JSC::ExecState* exec = d->currentFrame; + JSC::EvalExecutable *executable = program_d->executable(exec, d); + bool compile = !program_d->isCompiled; + JSC::JSValue result = d->evaluateHelper(exec, program_d->sourceId, + executable, compile); + if (compile) + program_d->isCompiled = true; return d->scriptValueFromJSCValue(result); } - /*! Returns the current context. diff --git a/src/script/api/qscriptengine.h b/src/script/api/qscriptengine.h index 701f9c6..3f438da 100644 --- a/src/script/api/qscriptengine.h +++ b/src/script/api/qscriptengine.h @@ -67,6 +67,7 @@ class QDateTime; class QScriptClass; class QScriptEngineAgent; class QScriptEnginePrivate; +class QScriptProgram; #ifndef QT_NO_QOBJECT @@ -166,6 +167,8 @@ public: QScriptValue evaluate(const QString &program, const QString &fileName = QString(), int lineNumber = 1); + QScriptValue evaluate(const QScriptProgram &program); + bool isEvaluating() const; void abortEvaluation(const QScriptValue &result = QScriptValue()); diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h index ec7c144..d12b0f4 100644 --- a/src/script/api/qscriptengine_p.h +++ b/src/script/api/qscriptengine_p.h @@ -70,6 +70,7 @@ namespace JSC { + class EvalExecutable; class ExecState; typedef ExecState CallFrame; class JSCell; @@ -211,6 +212,10 @@ public: const QByteArray &targetType, void **result); + JSC::JSValue evaluateHelper(JSC::ExecState *exec, intptr_t sourceId, + JSC::EvalExecutable *executable, + bool &compile); + QScript::QObjectData *qobjectData(QObject *object); void disposeQObject(QObject *object); void emitSignalHandlerException(); diff --git a/src/script/api/qscriptprogram.cpp b/src/script/api/qscriptprogram.cpp new file mode 100644 index 0000000..c30f381 --- /dev/null +++ b/src/script/api/qscriptprogram.cpp @@ -0,0 +1,225 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtScript module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "config.h" +#include "qscriptprogram.h" +#include "qscriptprogram_p.h" +#include "qscriptengine.h" +#include "qscriptengine_p.h" + +#include "Executable.h" + +QT_BEGIN_NAMESPACE + +/*! + \internal + + \since 4.6 + \class QScriptProgram + + \brief The QScriptProgram class encapsulates a Qt Script program. + + \ingroup script + + QScriptProgram retains the compiled representation of the script if + possible. Thus, QScriptProgram can be used to evaluate the same + script multiple times more efficiently. + + \code + QScriptEngine engine; + QScriptProgram program("1 + 2"); + QScriptValue result = engine.evaluate(program); + \endcode +*/ + +QScriptProgramPrivate::QScriptProgramPrivate(const QString &src, + const QString &fn, + int ln) + : sourceCode(src), fileName(fn), firstLineNumber(ln), + engine(0), _executable(0), sourceId(-1), isCompiled(false) +{ + ref = 0; +} + +QScriptProgramPrivate::~QScriptProgramPrivate() +{ + delete _executable; +} + +QScriptProgramPrivate *QScriptProgramPrivate::get(const QScriptProgram &q) +{ + return const_cast<QScriptProgramPrivate*>(q.d_func()); +} + +JSC::EvalExecutable *QScriptProgramPrivate::executable(JSC::ExecState *exec, + QScriptEnginePrivate *eng) +{ + if (_executable) { + if (eng == engine) + return _executable; + delete _executable; + } + WTF::PassRefPtr<QScript::UStringSourceProviderWithFeedback> provider + = QScript::UStringSourceProviderWithFeedback::create(sourceCode, fileName, firstLineNumber, eng); + sourceId = provider->asID(); + JSC::SourceCode source(provider, firstLineNumber); //after construction of SourceCode provider variable will be null. + _executable = new JSC::EvalExecutable(exec, source); + engine = eng; + isCompiled = false; + return _executable; +} + +/*! + Constructs a null QScriptProgram. +*/ +QScriptProgram::QScriptProgram() + : d_ptr(0) +{ +} + +/*! + Constructs a new QScriptProgram with the given \a sourceCode, \a + fileName and \a firstLineNumber. +*/ +QScriptProgram::QScriptProgram(const QString &sourceCode, + const QString fileName, + int firstLineNumber) + : d_ptr(new QScriptProgramPrivate(sourceCode, fileName, firstLineNumber)) +{ +} + +/*! + Constructs a new QScriptProgram that is a copy of \a other. +*/ +QScriptProgram::QScriptProgram(const QScriptProgram &other) + : d_ptr(other.d_ptr) +{ +} + +/*! + Destroys this QScriptProgram. +*/ +QScriptProgram::~QScriptProgram() +{ + Q_D(QScriptProgram); + // if (d->engine && (d->ref == 1)) + // d->engine->unregisterScriptProgram(d); +} + +/*! + Assigns the \a other value to this QScriptProgram. +*/ +QScriptProgram &QScriptProgram::operator=(const QScriptProgram &other) +{ + // if (d_func() && d_func()->engine && (d_func()->ref == 1)) + // d_func()->engine->unregisterScriptProgram(d_func()); + // } + d_ptr = other.d_ptr; + return *this; +} + +/*! + Returns true if this QScriptProgram is null; otherwise + returns false. +*/ +bool QScriptProgram::isNull() const +{ + Q_D(const QScriptProgram); + return (d == 0); +} + +/*! + Returns the source code of this program. +*/ +QString QScriptProgram::sourceCode() const +{ + Q_D(const QScriptProgram); + if (!d) + return QString(); + return d->sourceCode; +} + +/*! + Returns the filename associated with this program. +*/ +QString QScriptProgram::fileName() const +{ + Q_D(const QScriptProgram); + if (!d) + return QString(); + return d->fileName; +} + +/*! + Returns the line number associated with this program. +*/ +int QScriptProgram::firstLineNumber() const +{ + Q_D(const QScriptProgram); + if (!d) + return -1; + return d->firstLineNumber; +} + +/*! + Returns true if this QScriptProgram is equal to \a other; + otherwise returns false. +*/ +bool QScriptProgram::operator==(const QScriptProgram &other) const +{ + Q_D(const QScriptProgram); + if (d == other.d_func()) + return true; + return (sourceCode() == other.sourceCode()) + && (fileName() == other.fileName()) + && (firstLineNumber() == other.firstLineNumber()); +} + +/*! + Returns true if this QScriptProgram is not equal to \a other; + otherwise returns false. +*/ +bool QScriptProgram::operator!=(const QScriptProgram &other) const +{ + return !operator==(other); +} + +QT_END_NAMESPACE diff --git a/src/script/api/qscriptprogram.h b/src/script/api/qscriptprogram.h new file mode 100644 index 0000000..de891cd --- /dev/null +++ b/src/script/api/qscriptprogram.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtScript module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSCRIPTPROGRAM_H +#define QSCRIPTPROGRAM_H + +#include <QtCore/qsharedpointer.h> + +#include <QtCore/qstring.h> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Script) + +class QScriptProgramPrivate; +class Q_SCRIPT_EXPORT QScriptProgram +{ +public: + QScriptProgram(); + QScriptProgram(const QString &sourceCode, + const QString fileName = QString(), + int firstLineNumber = 1); + QScriptProgram(const QScriptProgram &other); + ~QScriptProgram(); + + QScriptProgram &operator=(const QScriptProgram &other); + + bool isNull() const; + + QString sourceCode() const; + QString fileName() const; + int firstLineNumber() const; + + bool operator==(const QScriptProgram &other) const; + bool operator!=(const QScriptProgram &other) const; + +private: + QExplicitlySharedDataPointer<QScriptProgramPrivate> d_ptr; + Q_DECLARE_PRIVATE(QScriptProgram) +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QSCRIPTPROGRAM_H diff --git a/src/script/api/qscriptprogram_p.h b/src/script/api/qscriptprogram_p.h new file mode 100644 index 0000000..5175079 --- /dev/null +++ b/src/script/api/qscriptprogram_p.h @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtScript module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSCRIPTPROGRAM_P_H +#define QSCRIPTPROGRAM_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/qobjectdefs.h> + +namespace JSC +{ + class EvalExecutable; + class ExecState; +} + +QT_BEGIN_NAMESPACE + +class QScriptEnginePrivate; + +class QScriptProgramPrivate +{ +public: + QScriptProgramPrivate(const QString &sourceCode, + const QString &fileName, + int firstLineNumber); + ~QScriptProgramPrivate(); + + static QScriptProgramPrivate *get(const QScriptProgram &q); + + JSC::EvalExecutable *executable(JSC::ExecState *exec, + QScriptEnginePrivate *engine); + + QBasicAtomicInt ref; + + QString sourceCode; + QString fileName; + int firstLineNumber; + + QScriptEnginePrivate *engine; + JSC::EvalExecutable *_executable; + intptr_t sourceId; + bool isCompiled; +}; + +QT_END_NAMESPACE + +#endif diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp index 8201add..e243e66 100644 --- a/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp +++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp @@ -228,3 +228,22 @@ QT_TRID_NOOP("this_a_id") //~ some thing //% "This needs to be here. Really." QString test = qtTrId("this_another_id", n); + + + +class YetAnotherTest : QObject { + Q_OBJECT + + int function(void) + { + // + //: + //= + //~ + //# + //============= + //~~~~~~~~~~~~~ + //::::::::::::: + tr("nothing"); + } +}; diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result index d63c7c3..26e5a65 100644 --- a/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result +++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result @@ -278,6 +278,14 @@ backslashed \ stuff.</source> </message> </context> <context> + <name>YetAnotherTest</name> + <message> + <location filename="main.cpp" line="247"/> + <source>nothing</source> + <translation type="unfinished"></translation> + </message> +</context> +<context> <name>scope</name> <message numerus="yes"> <location filename="main.cpp" line="187"/> diff --git a/tests/auto/qdatawidgetmapper/tst_qdatawidgetmapper.cpp b/tests/auto/qdatawidgetmapper/tst_qdatawidgetmapper.cpp index 002aeb7..dedc0cb 100644 --- a/tests/auto/qdatawidgetmapper/tst_qdatawidgetmapper.cpp +++ b/tests/auto/qdatawidgetmapper/tst_qdatawidgetmapper.cpp @@ -379,7 +379,7 @@ void tst_QDataWidgetMapper::comboBox() model->setData(model->index(0, 1), QString("read write item z"), Qt::EditRole); QCOMPARE(readOnlyBox.currentIndex(), 2); - QEXPECT_FAIL("", "See tasks 125493 and 147153", Abort); + QEXPECT_FAIL("", "See task 125493 and QTBUG-428", Abort); QCOMPARE(readWriteBox.currentText(), QString("read write item z")); } diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp index dc08d0e..9b5e114 100644 --- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp @@ -3735,7 +3735,7 @@ void tst_QGraphicsView::task259503_scrollingArtifacts() { // qDebug() << event->region(); // qDebug() << updateRegion; - QEXPECT_FAIL("", "The event region doesn't include the original item position region. See task #259503.", Continue); + QEXPECT_FAIL("", "The event region doesn't include the original item position region. See QTBUG-4416", Continue); QCOMPARE(event->region(), updateRegion); } } diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index 25ee00f..804534f 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -44,6 +44,7 @@ #include <qscriptengine.h> #include <qscriptengineagent.h> +#include <qscriptprogram.h> #include <qscriptvalueiterator.h> #include <qgraphicsitem.h> #include <qstandarditemmodel.h> @@ -52,6 +53,7 @@ Q_DECLARE_METATYPE(QList<int>) Q_DECLARE_METATYPE(QObjectList) +Q_DECLARE_METATYPE(QScriptProgram) //TESTED_CLASS= //TESTED_FILES= @@ -151,6 +153,7 @@ private slots: void installTranslatorFunctions(); void functionScopes(); void nativeFunctionScopes(); + void evaluateProgram(); void qRegExpInport_data(); void qRegExpInport(); @@ -4289,6 +4292,152 @@ void tst_QScriptEngine::nativeFunctionScopes() } } +static QScriptValue createProgram(QScriptContext *ctx, QScriptEngine *eng) +{ + QString code = ctx->argument(0).toString(); + QScriptProgram result(code); + return qScriptValueFromValue(eng, result); +} + +void tst_QScriptEngine::evaluateProgram() +{ + QScriptEngine eng; + + { + QString code("1 + 2"); + QString fileName("hello.js"); + int lineNumber(123); + QScriptProgram program(code, fileName, lineNumber); + QVERIFY(!program.isNull()); + QCOMPARE(program.sourceCode(), code); + QCOMPARE(program.fileName(), fileName); + QCOMPARE(program.firstLineNumber(), lineNumber); + + QScriptValue expected = eng.evaluate(code); + for (int x = 0; x < 10; ++x) { + QScriptValue ret = eng.evaluate(program); + QVERIFY(ret.equals(expected)); + } + + // operator= + QScriptProgram sameProgram = program; + QVERIFY(sameProgram == program); + QVERIFY(eng.evaluate(sameProgram).equals(expected)); + + // copy constructor + QScriptProgram sameProgram2(program); + QVERIFY(sameProgram2 == program); + QVERIFY(eng.evaluate(sameProgram2).equals(expected)); + + QScriptProgram differentProgram("2 + 3"); + QVERIFY(differentProgram != program); + QVERIFY(!eng.evaluate(differentProgram).equals(expected)); + } + + // Program that accesses variable in the scope + { + QScriptProgram program("a"); + QVERIFY(!program.isNull()); + { + QScriptValue ret = eng.evaluate(program); + QVERIFY(ret.isError()); + QCOMPARE(ret.toString(), QString::fromLatin1("ReferenceError: Can't find variable: a")); + } + + QScriptValue obj = eng.newObject(); + obj.setProperty("a", 123); + QScriptContext *ctx = eng.currentContext(); + ctx->pushScope(obj); + { + QScriptValue ret = eng.evaluate(program); + QVERIFY(!ret.isError()); + QVERIFY(ret.equals(obj.property("a"))); + } + + obj.setProperty("a", QScriptValue()); + { + QScriptValue ret = eng.evaluate(program); + QVERIFY(ret.isError()); + } + + QScriptValue obj2 = eng.newObject(); + obj2.setProperty("a", 456); + ctx->pushScope(obj2); + { + QScriptValue ret = eng.evaluate(program); + QVERIFY(!ret.isError()); + QVERIFY(ret.equals(obj2.property("a"))); + } + + ctx->popScope(); + } + + // Program that creates closure + { + QScriptProgram program("(function() { var count = 0; return function() { return count++; }; })"); + QVERIFY(!program.isNull()); + QScriptValue createCounter = eng.evaluate(program); + QVERIFY(createCounter.isFunction()); + QScriptValue counter = createCounter.call(); + QVERIFY(counter.isFunction()); + { + QScriptValue ret = counter.call(); + QVERIFY(ret.isNumber()); + } + QScriptValue counter2 = createCounter.call(); + QVERIFY(counter2.isFunction()); + QVERIFY(!counter2.equals(counter)); + { + QScriptValue ret = counter2.call(); + QVERIFY(ret.isNumber()); + } + } + + // Program created in a function call, then executed later + { + QScriptValue fun = eng.newFunction(createProgram); + QScriptProgram program = qscriptvalue_cast<QScriptProgram>( + fun.call(QScriptValue(), QScriptValueList() << "a + 1")); + QVERIFY(!program.isNull()); + eng.globalObject().setProperty("a", QScriptValue()); + { + QScriptValue ret = eng.evaluate(program); + QVERIFY(ret.isError()); + QCOMPARE(ret.toString(), QString::fromLatin1("ReferenceError: Can't find variable: a")); + } + eng.globalObject().setProperty("a", 122); + { + QScriptValue ret = eng.evaluate(program); + QVERIFY(!ret.isError()); + QVERIFY(ret.isNumber()); + QCOMPARE(ret.toInt32(), 123); + } + } + + // Same program run in different engines + { + QString code("1 + 2"); + QScriptProgram program(code); + QVERIFY(!program.isNull()); + double expected = eng.evaluate(program).toNumber(); + for (int x = 0; x < 2; ++x) { + QScriptEngine eng2; + for (int y = 0; y < 2; ++y) { + double ret = eng2.evaluate(program).toNumber(); + QCOMPARE(ret, expected); + } + } + } + + // No program + { + QScriptProgram program; + QVERIFY(program.isNull()); + QScriptValue ret = eng.evaluate(program); + QVERIFY(!ret.isValid()); + } +} + static QRegExp minimal(QRegExp r) { r.setMinimal(true); return r; } void tst_QScriptEngine::qRegExpInport_data() diff --git a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp index 82c8ccd..032c34b 100644 --- a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp +++ b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp @@ -44,6 +44,7 @@ #include <QtScript/qscriptengineagent.h> #include <QtScript/qscriptengine.h> +#include <QtScript/qscriptprogram.h> #include <qscriptvalueiterator.h> //TESTED_CLASS= @@ -110,6 +111,9 @@ private slots: void extension(); void isEvaluatingInExtension(); void hasUncaughtException(); + void evaluateProgram(); + void evaluateProgram_SyntaxError(); + void evaluateNullProgram(); private: double m_testProperty; @@ -2219,6 +2223,88 @@ void tst_QScriptEngineAgent::hasUncaughtException() QVERIFY2(spy->isPass(), "At least one of a functionExit event should set hasUncaughtException flag."); } +void tst_QScriptEngineAgent::evaluateProgram() +{ + QScriptEngine eng; + QScriptProgram program("1 + 2", "foo.js", 123); + ScriptEngineSpy *spy = new ScriptEngineSpy(&eng); + qint64 scriptId = -1; + for (int x = 0; x < 10; ++x) { + spy->clear(); + (void)eng.evaluate(program); + QCOMPARE(spy->count(), (x == 0) ? 4 : 3); + + if (x == 0) { + // script is only loaded on first execution + QCOMPARE(spy->at(0).type, ScriptEngineEvent::ScriptLoad); + scriptId = spy->at(0).scriptId; + QVERIFY(scriptId != -1); + QCOMPARE(spy->at(0).script, program.sourceCode()); + QCOMPARE(spy->at(0).fileName, program.fileName()); + QCOMPARE(spy->at(0).lineNumber, program.firstLineNumber()); + spy->removeFirst(); + } + + QCOMPARE(spy->at(0).type, ScriptEngineEvent::FunctionEntry); // evaluate() + QCOMPARE(spy->at(0).scriptId, scriptId); + + QCOMPARE(spy->at(1).type, ScriptEngineEvent::PositionChange); + QCOMPARE(spy->at(1).scriptId, scriptId); + QCOMPARE(spy->at(1).lineNumber, program.firstLineNumber()); + + QCOMPARE(spy->at(2).type, ScriptEngineEvent::FunctionExit); // evaluate() + QCOMPARE(spy->at(2).scriptId, scriptId); + QVERIFY(spy->at(2).value.isNumber()); + QCOMPARE(spy->at(2).value.toNumber(), qsreal(3)); + } +} + +void tst_QScriptEngineAgent::evaluateProgram_SyntaxError() +{ + QScriptEngine eng; + QScriptProgram program("this is not valid syntax", "foo.js", 123); + ScriptEngineSpy *spy = new ScriptEngineSpy(&eng); + qint64 scriptId = -1; + for (int x = 0; x < 10; ++x) { + spy->clear(); + (void)eng.evaluate(program); + QCOMPARE(spy->count(), (x == 0) ? 8 : 7); + + if (x == 0) { + // script is only loaded on first execution + QCOMPARE(spy->at(0).type, ScriptEngineEvent::ScriptLoad); + scriptId = spy->at(0).scriptId; + QVERIFY(scriptId != -1); + QCOMPARE(spy->at(0).script, program.sourceCode()); + QCOMPARE(spy->at(0).fileName, program.fileName()); + QCOMPARE(spy->at(0).lineNumber, program.firstLineNumber()); + spy->removeFirst(); + } + + QCOMPARE(spy->at(0).type, ScriptEngineEvent::FunctionEntry); // evaluate() + QCOMPARE(spy->at(0).scriptId, scriptId); + + QCOMPARE(spy->at(1).type, ScriptEngineEvent::ContextPush); // SyntaxError constructor + QCOMPARE(spy->at(2).type, ScriptEngineEvent::FunctionEntry); // SyntaxError constructor + QCOMPARE(spy->at(3).type, ScriptEngineEvent::FunctionExit); // SyntaxError constructor + QCOMPARE(spy->at(4).type, ScriptEngineEvent::ContextPop); // SyntaxError constructor + + QCOMPARE(spy->at(5).type, ScriptEngineEvent::ExceptionThrow); + QVERIFY(spy->at(5).value.isError()); + QCOMPARE(spy->at(5).value.toString(), QString::fromLatin1("SyntaxError: Parse error")); + + QCOMPARE(spy->at(6).type, ScriptEngineEvent::FunctionExit); // evaluate() + QCOMPARE(spy->at(6).scriptId, scriptId); + } +} + +void tst_QScriptEngineAgent::evaluateNullProgram() +{ + QScriptEngine eng; + ScriptEngineSpy *spy = new ScriptEngineSpy(&eng); + (void)eng.evaluate(QScriptProgram()); + QCOMPARE(spy->count(), 0); +} QTEST_MAIN(tst_QScriptEngineAgent) #include "tst_qscriptengineagent.moc" diff --git a/tests/auto/qsound/tst_qsound.cpp b/tests/auto/qsound/tst_qsound.cpp index fdbf6a2..56a330b 100644 --- a/tests/auto/qsound/tst_qsound.cpp +++ b/tests/auto/qsound/tst_qsound.cpp @@ -66,7 +66,7 @@ void tst_QSound::checkFinished() QTest::qWait(5000); #if defined(Q_WS_QWS) - QEXPECT_FAIL("", "QSound buggy on embedded (task 122221)", Abort); + QEXPECT_FAIL("", "QSound buggy on embedded (task QTBUG-157)", Abort); #endif QVERIFY(sound.isFinished() ); } diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index 1516346..975b301 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -117,6 +117,7 @@ private slots: void cleanup(); void rootState(); + void machineWithParent(); void addAndRemoveState(); void stateEntryAndExit(); void assignProperty(); @@ -124,6 +125,7 @@ private slots: void postEvent(); void cancelDelayedEvent(); void postDelayedEventAndStop(); + void stopAndPostEvent(); void stateFinished(); void parallelStates(); void parallelRootState(); @@ -205,6 +207,7 @@ private slots: void goToState(); void task260403_clonedSignals(); + void postEventFromOtherThread(); }; tst_QStateMachine::tst_QStateMachine() @@ -1043,6 +1046,14 @@ void tst_QStateMachine::rootState() QCOMPARE(s2->parentState(), static_cast<QState*>(&machine)); } +void tst_QStateMachine::machineWithParent() +{ + QObject object; + QStateMachine *machine = new QStateMachine(&object); + QCOMPARE(machine->parent(), &object); + QCOMPARE(machine->parentState(), (QObject*)0); +} + void tst_QStateMachine::addAndRemoveState() { #ifdef QT_BUILD_INTERNAL @@ -1681,6 +1692,22 @@ void tst_QStateMachine::postDelayedEventAndStop() QVERIFY(machine.configuration().contains(s1)); } +void tst_QStateMachine::stopAndPostEvent() +{ + QStateMachine machine; + QState *s1 = new QState(&machine); + machine.setInitialState(s1); + QSignalSpy startedSpy(&machine, SIGNAL(started())); + machine.start(); + QTRY_COMPARE(startedSpy.count(), 1); + QSignalSpy stoppedSpy(&machine, SIGNAL(stopped())); + machine.stop(); + QCOMPARE(stoppedSpy.count(), 0); + machine.postEvent(new QEvent(QEvent::User)); + QTRY_COMPARE(stoppedSpy.count(), 1); + QCoreApplication::processEvents(); +} + void tst_QStateMachine::stateFinished() { QStateMachine machine; @@ -4188,5 +4215,52 @@ void tst_QStateMachine::task260403_clonedSignals() QCOMPARE(t1->eventSignalIndex, emitter.metaObject()->indexOfSignal("signalWithDefaultArg()")); } +class EventPosterThread : public QThread +{ + Q_OBJECT +public: + EventPosterThread(QStateMachine *machine, QObject *parent = 0) + : QThread(parent), m_machine(machine), m_count(0) + { + moveToThread(this); + QObject::connect(m_machine, SIGNAL(started()), + this, SLOT(postEvent())); + } +protected: + virtual void run() + { + exec(); + } +private Q_SLOTS: + void postEvent() + { + m_machine->postEvent(new QEvent(QEvent::User)); + if (++m_count < 10000) + QTimer::singleShot(0, this, SLOT(postEvent())); + else + quit(); + } +private: + QStateMachine *m_machine; + int m_count; +}; + +void tst_QStateMachine::postEventFromOtherThread() +{ + QStateMachine machine; + EventPosterThread poster(&machine); + StringEventPoster *s1 = new StringEventPoster("foo", &machine); + s1->addTransition(new EventTransition(QEvent::User, s1)); + QFinalState *f = new QFinalState(&machine); + s1->addTransition(&poster, SIGNAL(finished()), f); + machine.setInitialState(s1); + + poster.start(); + + QSignalSpy finishedSpy(&machine, SIGNAL(finished())); + machine.start(); + QTRY_COMPARE(finishedSpy.count(), 1); +} + QTEST_MAIN(tst_QStateMachine) #include "tst_qstatemachine.moc" diff --git a/tests/auto/qurl/tst_qurl.cpp b/tests/auto/qurl/tst_qurl.cpp index 72c13bf..c8fe4e5 100644 --- a/tests/auto/qurl/tst_qurl.cpp +++ b/tests/auto/qurl/tst_qurl.cpp @@ -3679,15 +3679,21 @@ void tst_QUrl::binaryData() void tst_QUrl::fromUserInput_data() { + // + // most of this test is: + // Copyright (C) Research In Motion Limited 2009. All rights reserved. + // Distributed under the BSD license. + // See qurl.cpp + // + QTest::addColumn<QString>("string"); - QTest::addColumn<QUrl>("url"); + QTest::addColumn<QUrl>("guessUrlFromString"); // Null QTest::newRow("null") << QString() << QUrl(); // File QDirIterator it(QDir::homePath()); - QString fileString; int c = 0; while (it.hasNext()) { it.next(); @@ -3695,49 +3701,52 @@ void tst_QUrl::fromUserInput_data() } // basic latin1 - QTest::newRow("unicode-0") << QString::fromUtf8("\xC3\xA5.com/") << QUrl::fromEncoded(QString::fromUtf8("http://\xC3\xA5.com/").toUtf8(), QUrl::TolerantMode); + QTest::newRow("unicode-0") << QString::fromUtf8("\xc3\xa5.com/") << QUrl::fromEncoded(QString::fromUtf8("http://\xc3\xa5.com/").toUtf8(), QUrl::TolerantMode); + QTest::newRow("unicode-0b") << QString::fromUtf8("\xc3\xa5.com/") << QUrl::fromEncoded("http://%C3%A5.com/", QUrl::TolerantMode); + QTest::newRow("unicode-0c") << QString::fromUtf8("\xc3\xa5.com/") << QUrl::fromEncoded("http://xn--5ca.com/", QUrl::TolerantMode); // unicode - QTest::newRow("unicode-1") << QString::fromUtf8("\xCE\xBB.com/") << QUrl::fromEncoded(QString::fromUtf8("http://\xCE\xBB.com/").toUtf8(), QUrl::TolerantMode); + QTest::newRow("unicode-1") << QString::fromUtf8("\xce\xbb.com/") << QUrl::fromEncoded(QString::fromUtf8("http://\xce\xbb.com/").toUtf8(), QUrl::TolerantMode); + QTest::newRow("unicode-1b") << QString::fromUtf8("\xce\xbb.com/") << QUrl::fromEncoded("http://%CE%BB.com/", QUrl::TolerantMode); + QTest::newRow("unicode-1c") << QString::fromUtf8("\xce\xbb.com/") << QUrl::fromEncoded("http://xn--wxa.com/", QUrl::TolerantMode); // no scheme - QTest::newRow("add scheme-0") << "webkit.org" << QUrl("http://webkit.org"); - QTest::newRow("add scheme-1") << "www.webkit.org" << QUrl("http://www.webkit.org"); - QTest::newRow("add scheme-2") << "ftp.webkit.org" << QUrl("ftp://ftp.webkit.org"); + QTest::newRow("add scheme-0") << "example.org" << QUrl("http://example.org"); + QTest::newRow("add scheme-1") << "www.example.org" << QUrl("http://www.example.org"); + QTest::newRow("add scheme-2") << "ftp.example.org" << QUrl("ftp://ftp.example.org"); QTest::newRow("add scheme-3") << "webkit" << QUrl("webkit"); // QUrl's tolerant parser should already handle this - QTest::newRow("not-encoded-0") << "http://webkit.org/test page.html" << QUrl("http://webkit.org/test%20page.html"); + QTest::newRow("not-encoded-0") << "http://example.org/test page.html" << QUrl::fromEncoded("http://example.org/test%20page.html"); // Make sure the :80, i.e. port doesn't screw anything up - QUrl portUrl("http://webkit.org"); + QUrl portUrl("http://example.org"); portUrl.setPort(80); - QTest::newRow("port-0") << "webkit.org:80" << portUrl; - QTest::newRow("port-1") << "http://webkit.org:80" << portUrl; + QTest::newRow("port-0") << "example.org:80" << portUrl; + QTest::newRow("port-1") << "http://example.org:80" << portUrl; // mailto doesn't have a ://, but is valid - QUrl mailto("somebody@somewhere.net"); + QUrl mailto("ben@example.net"); mailto.setScheme("mailto"); - QTest::newRow("mailto") << "mailto:somebody@somewhere.net" << mailto; + QTest::newRow("mailto") << "mailto:ben@example.net" << mailto; // misc QTest::newRow("localhost-0") << "localhost" << QUrl("http://localhost"); QTest::newRow("localhost-1") << "localhost:80" << QUrl("http://localhost:80"); - QTest::newRow("spaces-0") << " http://webkit.org/test page.html " << QUrl("http://webkit.org/test%20page.html"); - QTest::newRow("trash-0") << "webkit.org/test?someData=42%&someOtherData=abcde#anchor" << QUrl::fromEncoded("http://webkit.org/test?someData=42%25&someOtherData=abcde#anchor"); + QTest::newRow("spaces-0") << " http://example.org/test page.html " << QUrl("http://example.org/test%20page.html"); + QTest::newRow("trash-0") << "example.org/test?someData=42%&someOtherData=abcde#anchor" << QUrl::fromEncoded("http://example.org/test?someData=42%25&someOtherData=abcde#anchor"); // FYI: The scheme in the resulting url user QUrl authUrl("user:pass@domain.com"); QTest::newRow("misc-1") << "user:pass@domain.com" << authUrl; } -// public static QUrl guessUrlFromString(QString const& string) void tst_QUrl::fromUserInput() { QFETCH(QString, string); - QFETCH(QUrl, url); + QFETCH(QUrl, guessUrlFromString); - QUrl guessedUrl = QUrl::fromUserInput(string); - QCOMPARE(guessedUrl, url); + QUrl url = QUrl::fromUserInput(string); + QCOMPARE(url, guessUrlFromString); } void tst_QUrl::task_199967() diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index 050d1c5..5630370 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -2982,7 +2982,7 @@ void tst_QWidget::stackUnder() qApp->processEvents(); #endif #ifndef Q_WS_MAC - QEXPECT_FAIL(0, "Task 153869", Continue); + QEXPECT_FAIL(0, "See QTBUG-493", Continue); #endif QCOMPARE(child->numPaintEvents, 0); } else { diff --git a/tests/benchmarks/qscriptengine/tst_qscriptengine.cpp b/tests/benchmarks/qscriptengine/tst_qscriptengine.cpp index 4f011c4..8d5f6e6 100644 --- a/tests/benchmarks/qscriptengine/tst_qscriptengine.cpp +++ b/tests/benchmarks/qscriptengine/tst_qscriptengine.cpp @@ -60,6 +60,8 @@ private slots: void constructor(); void evaluate_data(); void evaluate(); + void evaluateProgram_data(); + void evaluateProgram(); void connectAndDisconnect(); void newObject(); void newQObject(); @@ -153,6 +155,22 @@ void tst_QScriptEngine::connectAndDisconnect() } } +void tst_QScriptEngine::evaluateProgram_data() +{ + evaluate_data(); +} + +void tst_QScriptEngine::evaluateProgram() +{ + QFETCH(QString, code); + QScriptEngine engine; + QScriptProgram program(code); + + QBENCHMARK { + (void)engine.evaluate(program); + } +} + void tst_QScriptEngine::newObject() { QScriptEngine engine; @@ -241,6 +259,5 @@ void tst_QScriptEngine::nativeCall() } } - QTEST_MAIN(tst_QScriptEngine) #include "tst_qscriptengine.moc" diff --git a/tools/assistant/tools/assistant/assistant.qch b/tools/assistant/tools/assistant/assistant.qch Binary files differindex 3e66bd9..78fe9f3 100644 --- a/tools/assistant/tools/assistant/assistant.qch +++ b/tools/assistant/tools/assistant/assistant.qch diff --git a/tools/configure/configureapp.cpp b/tools/configure/configureapp.cpp index f57f3a8..f75b51b 100644 --- a/tools/configure/configureapp.cpp +++ b/tools/configure/configureapp.cpp @@ -3033,7 +3033,11 @@ void Configure::generateConfigfiles() tmpStream.setDevice(&tmpFile2); tmpStream << "/* Licensed */" << endl << "static const char qt_configure_licensee_str [512 + 12] = \"qt_lcnsuser=" << licenseInfo["LICENSEE"] << "\";" << endl - << "static const char qt_configure_licensed_products_str [512 + 12] = \"qt_lcnsprod=" << dictionary["EDITION"] << "\";" << endl; + << "static const char qt_configure_licensed_products_str [512 + 12] = \"qt_lcnsprod=" << dictionary["EDITION"] << "\";" << endl + << endl + << "/* Build date */" << endl + << "static const char qt_configure_installation [11 + 12] = \"" << QDate::currentDate().toString(Qt::ISODate) << "\";" << endl + << endl; if(!dictionary[ "QT_HOST_PREFIX" ].isNull()) tmpStream << "#if !defined(QT_BOOTSTRAPPED) && !defined(QT_BUILD_QMAKE)" << endl; tmpStream << "static const char qt_configure_prefix_path_str [512 + 12] = \"qt_prfxpath=" << QString(dictionary["QT_INSTALL_PREFIX"]).replace( "\\", "\\\\" ) << "\";" << endl @@ -3087,6 +3091,24 @@ void Configure::generateConfigfiles() tmpFile2.copy(outName); tmpFile2.close(); } + + QTemporaryFile tmpFile3; + if (tmpFile3.open()) { + tmpStream.setDevice(&tmpFile3); + tmpStream << "/* Evaluation license key */" << endl + << "static const char qt_eval_key_data [512 + 12] = \"" << licenseInfo["LICENSEKEYEXT"] << "\";" << endl; + + tmpStream.flush(); + tmpFile3.flush(); + + outName = buildPath + "/src/corelib/global/qconfig_eval.cpp"; + ::SetFileAttributes((wchar_t*)outName.utf16(), FILE_ATTRIBUTE_NORMAL ); + QFile::remove( outName ); + + if (dictionary["EDITION"] == "Evaluation" || qmakeDefines.contains("QT_EVAL")) + tmpFile3.copy(outName); + tmpFile3.close(); + } } #endif diff --git a/tools/linguist/lupdate/cpp.cpp b/tools/linguist/lupdate/cpp.cpp index 7a616e3..4d89156 100644 --- a/tools/linguist/lupdate/cpp.cpp +++ b/tools/linguist/lupdate/cpp.cpp @@ -1896,28 +1896,29 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions) prospectiveContext.clear(); } break; - case Tok_Comment: + case Tok_Comment: { if (!tor) goto case_default; - if (yyWord.startsWith(QLatin1Char(':'))) { - yyWord.remove(0, 1); + const QChar *ptr = yyWord.unicode(); + if (*ptr == QLatin1Char(':') && ptr[1].isSpace()) { + yyWord.remove(0, 2); extracomment += yyWord; extracomment.detach(); - } else if (yyWord.startsWith(QLatin1Char('='))) { - yyWord.remove(0, 1); + } else if (*ptr == QLatin1Char('=') && ptr[1].isSpace()) { + yyWord.remove(0, 2); msgid = yyWord.simplified(); msgid.detach(); - } else if (yyWord.startsWith(QLatin1Char('~'))) { - yyWord.remove(0, 1); + } else if (*ptr == QLatin1Char('~') && ptr[1].isSpace()) { + yyWord.remove(0, 2); text = yyWord.trimmed(); int k = text.indexOf(QLatin1Char(' ')); if (k > -1) extra.insert(text.left(k), text.mid(k + 1).trimmed()); text.clear(); - } else if (yyWord.startsWith(QLatin1Char('%'))) { - sourcetext.reserve(sourcetext.length() + yyWord.length()); + } else if (*ptr == QLatin1Char('%') && ptr[1].isSpace()) { + sourcetext.reserve(sourcetext.length() + yyWord.length() - 2); ushort *ptr = (ushort *)sourcetext.data() + sourcetext.length(); - int p = 1, c; + int p = 2, c; forever { if (p >= yyWord.length()) break; @@ -1977,6 +1978,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions) } yyTok = getToken(); break; + } case Tok_Arrow: yyTok = getToken(); if (yyTok == Tok_tr || yyTok == Tok_trUtf8) |