From 5cfcb54cc6a94b5be50d751c659f0b55e090d35b Mon Sep 17 00:00:00 2001 From: Venugopal Shivashankar Date: Mon, 18 May 2015 12:50:13 +0200 Subject: Doc: Added the missing examples \group page for Qt QML The QHP meta info. was trying to link to the Qt Quick page, which failed. This should fix the issue. Task-number: QTBUG-46163 Change-Id: Ib012f8f73b74a51b7a8d4e849070742e94d40973 Reviewed-by: Venugopal Shivashankar --- src/qml/doc/qtqml.qdocconf | 2 +- src/qml/doc/src/examples.qdoc | 35 +++++++++++++++++++++++++++++++++++ src/qml/doc/src/qtqml.qdoc | 1 + 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/qml/doc/src/examples.qdoc diff --git a/src/qml/doc/qtqml.qdocconf b/src/qml/doc/qtqml.qdocconf index 5729a60ea3..f95764f471 100644 --- a/src/qml/doc/qtqml.qdocconf +++ b/src/qml/doc/qtqml.qdocconf @@ -23,7 +23,7 @@ qhp.QtQml.subprojects.classes.indexTitle = Qt QML C++ Classes qhp.QtQml.subprojects.classes.selectors = class fake:headerfile qhp.QtQml.subprojects.classes.sortPages = true qhp.QtQml.subprojects.examples.title = Examples -qhp.QtQml.subprojects.examples.indexTitle = Qt Quick Examples and Tutorials +qhp.QtQml.subprojects.examples.indexTitle = Qt QML Examples qhp.QtQml.subprojects.examples.selectors = fake:example qhp.QtQml.subprojects.qmltypes.title = QML Types qhp.QtQml.subprojects.qmltypes.indexTitle = Qt QML QML Types diff --git a/src/qml/doc/src/examples.qdoc b/src/qml/doc/src/examples.qdoc new file mode 100644 index 0000000000..29424053a4 --- /dev/null +++ b/src/qml/doc/src/examples.qdoc @@ -0,0 +1,35 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! +\group qmlextendingexamples +\title Qt QML Examples +\brief List of Qt QML examples for reference. + +The list of examples demonstrating how to extend C++ to QML or the other way +around. +*/ diff --git a/src/qml/doc/src/qtqml.qdoc b/src/qml/doc/src/qtqml.qdoc index ae2cac7275..7350f65024 100644 --- a/src/qml/doc/src/qtqml.qdoc +++ b/src/qml/doc/src/qtqml.qdoc @@ -148,6 +148,7 @@ Further information for writing QML applications: \list \li \l{Qt QML C++ Classes}{C++ Classes} \li \l{Qt QML QML Types}{QML Types} +\li \l{Qt QML Examples}{Examples} \endlist */ -- cgit v1.2.3 From 72c042fa3e23fa1aa4579df801e3cd4411d80bbd Mon Sep 17 00:00:00 2001 From: Venugopal Shivashankar Date: Fri, 15 May 2015 15:35:24 +0200 Subject: Doc: Added the missing \brief and \image to the example docs Task-number: QTBUG-41996 Change-Id: Ica6e069c7753a2004a4a4c0e93a49d1f240569d3 Reviewed-by: Martin Smith --- .../doc/src/networkaccessmanagerfactory.qdoc | 3 ++- src/qml/doc/qtqml.qdocconf | 3 ++- src/quick/doc/qtquick.qdocconf | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/qml/networkaccessmanagerfactory/doc/src/networkaccessmanagerfactory.qdoc b/examples/qml/networkaccessmanagerfactory/doc/src/networkaccessmanagerfactory.qdoc index a4d4acd715..d0ebc76ffc 100644 --- a/examples/qml/networkaccessmanagerfactory/doc/src/networkaccessmanagerfactory.qdoc +++ b/examples/qml/networkaccessmanagerfactory/doc/src/networkaccessmanagerfactory.qdoc @@ -26,8 +26,9 @@ ****************************************************************************/ /*! - \title C++ Extensions: Network Access Manager Factory Example \example networkaccessmanagerfactory + \title C++ Extensions: Network Access Manager Factory Example + \brief Implements a custom network access manager for the QML engine This example shows how to use QQmlNetworkAccessManagerFactory to create a QNetworkAccessManager with a proxy. diff --git a/src/qml/doc/qtqml.qdocconf b/src/qml/doc/qtqml.qdocconf index f95764f471..74b61fd6e1 100644 --- a/src/qml/doc/qtqml.qdocconf +++ b/src/qml/doc/qtqml.qdocconf @@ -50,7 +50,8 @@ imagedirs += images # Add a thumbnail for examples that do not have images manifestmeta.thumbnail.names += "QtQml/Chapter 4*" \ - "QtQml/Chapter 6*" + "QtQml/Chapter 6*" \ + "QtQml/C++ Extensions: *" navigation.landingpage = "Qt QML" navigation.cppclassespage = "Qt QML C++ Classes" diff --git a/src/quick/doc/qtquick.qdocconf b/src/quick/doc/qtquick.qdocconf index afe1b9708f..7f43dc2c31 100644 --- a/src/quick/doc/qtquick.qdocconf +++ b/src/quick/doc/qtquick.qdocconf @@ -67,7 +67,8 @@ excludedirs += ../../imports/models \ examples.fileextensions += "*.qm" -manifestmeta.thumbnail.names += "QtQuick/Threaded ListModel Example" +manifestmeta.thumbnail.names += "QtQuick/Threaded ListModel Example" \ + "QtQuick/QML Dynamic View Ordering Tutorial*" navigation.landingpage = "Qt Quick" navigation.cppclassespage = "Qt Quick C++ Classes" -- cgit v1.2.3 From 2c860b9c4de8a1f423a1a6c10a3460552e959d95 Mon Sep 17 00:00:00 2001 From: Alan Alpert <416365416c@gmail.com> Date: Mon, 30 Mar 2015 18:06:44 -0700 Subject: Remove testing of active window change on hide We don't actually control where the window manager assigns focus if the currently active window is hidden, so don't test for specific behavior. We can now remove the blacklist entry for this test. Change-Id: Ie09fc91c6317f6bb2d4b91000641ef241556fddf Reviewed-by: Frederik Gladhorn --- tests/auto/quick/qquickwindow/BLACKLIST | 2 -- tests/auto/quick/qquickwindow/tst_qquickwindow.cpp | 8 -------- 2 files changed, 10 deletions(-) delete mode 100644 tests/auto/quick/qquickwindow/BLACKLIST diff --git a/tests/auto/quick/qquickwindow/BLACKLIST b/tests/auto/quick/qquickwindow/BLACKLIST deleted file mode 100644 index 1201ef12f0..0000000000 --- a/tests/auto/quick/qquickwindow/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -[testWindowVisibilityOrder] -osx diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp index 7c94cf6d17..f638505c72 100644 --- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp +++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp @@ -1716,14 +1716,6 @@ void tst_qquickwindow::testWindowVisibilityOrder() QTest::qWaitForWindowExposed(window5); QVERIFY(window4->isVisible()); QVERIFY(window5->isVisible()); - window4->hide(); - window5->hide(); - - window3->hide(); - QTRY_COMPARE(window2 == QGuiApplication::focusWindow(), true); - - window2->hide(); - QTRY_COMPARE(window1 == QGuiApplication::focusWindow(), true); } void tst_qquickwindow::blockClosing() -- cgit v1.2.3 From 2556b97ab22cfde606d2b77d6e816fd282741291 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Thu, 21 May 2015 13:10:36 +0200 Subject: Doc: Document limits of QSGGeometry::setLineWidth Task-number: QTBUG-46260 Change-Id: Ib84a41da10d38391c3248a209a851f5b603d46b0 Reviewed-by: Gunnar Sletta --- src/quick/scenegraph/coreapi/qsggeometry.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/quick/scenegraph/coreapi/qsggeometry.cpp b/src/quick/scenegraph/coreapi/qsggeometry.cpp index 7be926ad81..7e43541ef7 100644 --- a/src/quick/scenegraph/coreapi/qsggeometry.cpp +++ b/src/quick/scenegraph/coreapi/qsggeometry.cpp @@ -522,7 +522,8 @@ void QSGGeometry::setDrawingMode(GLenum mode) /*! Gets the current line or point width or to be used for this geometry. This property only applies to line width when the drawingMode is \c GL_LINES, \c GL_LINE_STRIP, or - \c GL_LINE_LOOP, and only applies to point size when the drawingMode is \c GL_POINTS. + \c GL_LINE_LOOP. For desktop OpenGL, it also applies to point size when the drawingMode + is \c GL_POINTS. The default value is \c 1.0 @@ -536,7 +537,12 @@ float QSGGeometry::lineWidth() const /*! Sets the line or point width to be used for this geometry to \a width. This property only applies to line width when the drawingMode is \c GL_LINES, \c GL_LINE_STRIP, or - \c GL_LINE_LOOP, and only applies to point size when the drawingMode is \c GL_POINTS. + \c GL_LINE_LOOP. For Desktop OpenGL, it also applies to point size when the drawingMode + is \c GL_POINTS. + + \note How line width and point size are treated is implementation dependent: The application + should not rely on these, but rather create triangles or similar to draw areas. On OpenGL ES, + line width support is limited and point size is unsupported. \sa lineWidth(), drawingMode() */ -- cgit v1.2.3 From 8b205fd05dcdc4a0e7ec6b25429f691a0a9099fe Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Wed, 27 May 2015 10:52:59 +0200 Subject: Improve support for HTML entities in StyledText This adds support for the non-breaking space character ( ) and properly handling entities that do not end with a semicolon, such as a stray ampersand in a text. Change-Id: I2f157c9aa651b27511809d5a47ac07660949a290 Task-number: QTBUG-44869 Task-number: QTBUG-31816 Task-number: QTBUG-33368 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/quick/util/qquickstyledtext.cpp | 6 ++++++ tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/quick/util/qquickstyledtext.cpp b/src/quick/util/qquickstyledtext.cpp index 5efe65ef44..6ed32c10e2 100644 --- a/src/quick/util/qquickstyledtext.cpp +++ b/src/quick/util/qquickstyledtext.cpp @@ -542,6 +542,12 @@ void QQuickStyledTextPrivate::parseEntity(const QChar *&ch, const QString &textI textOut += QChar(38); else if (entity == QLatin1String("quot")) textOut += QChar(34); + else if (entity == QLatin1String("nbsp")) + textOut += QChar(QChar::Nbsp); + return; + } else if (*ch == QLatin1Char(' ')) { + QStringRef entity(&textIn, entityStart - 1, entityLength + 1); + textOut += entity + *ch; return; } ++entityLength; diff --git a/tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp b/tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp index b76218edb9..816440b191 100644 --- a/tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp +++ b/tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp @@ -153,6 +153,8 @@ void tst_qquickstyledtext::textOutput_data() QTest::newRow("space trailing bold") << "this is bold " << "this is bold " << (FormatList() << Format(Format::Bold, 8, 5)) << false; QTest::newRow("img") << "ab" << "a b" << FormatList() << false; QTest::newRow("tag mix") << "dsgfhghjdfgdfgewrqjklhj" << "dsgfhghjdfgdfgewrqjklhj" << (FormatList() << Format(Format::Bold, 2, 3)) << false; + QTest::newRow("named html entities") << "> < & "  " << QLatin1String("> < & \" ") + QChar(QChar::Nbsp) << FormatList() << false; + QTest::newRow("invalid html entities") << "a &hello & a &goodbye;" << "a &hello & a " << FormatList() << false; } void tst_qquickstyledtext::textOutput() -- cgit v1.2.3 From eeee9f1466ffaf17f81d635c2e43dca76ce5b021 Mon Sep 17 00:00:00 2001 From: Tobias Koenig Date: Fri, 3 Jul 2015 10:55:35 +0200 Subject: QSGSimpleTextureNode: Fix ownership of QSGTexture Make sure the QSGSimpleTextureNode deletes the old QSGTexture if a new one is set via setTexture() and the ownsTexture flag is true. [ChangeLog][QtQuick][SceneGraph] QSGSimpleTextureNode will now delete the currently set QSGTexture object, if a new QSGTexture is set and the ownsTexture flag is on. Change-Id: Iabfbccd390e16948d4575baf29e6c8b4a184a404 Reviewed-by: Gunnar Sletta --- src/quick/scenegraph/util/qsgsimpletexturenode.cpp | 4 +++- tests/auto/quick/nodes/tst_nodestest.cpp | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/quick/scenegraph/util/qsgsimpletexturenode.cpp b/src/quick/scenegraph/util/qsgsimpletexturenode.cpp index 8d38e83029..d9f3c44374 100644 --- a/src/quick/scenegraph/util/qsgsimpletexturenode.cpp +++ b/src/quick/scenegraph/util/qsgsimpletexturenode.cpp @@ -223,9 +223,11 @@ QRectF QSGSimpleTextureNode::sourceRect() const void QSGSimpleTextureNode::setTexture(QSGTexture *texture) { Q_ASSERT(texture); + Q_D(QSGSimpleTextureNode); + if (d->ownsTexture) + delete m_material.texture(); m_material.setTexture(texture); m_opaque_material.setTexture(texture); - Q_D(QSGSimpleTextureNode); qsgsimpletexturenode_update(&m_geometry, texture, m_rect, d->sourceRect, d->texCoordMode); DirtyState dirty = DirtyMaterial; diff --git a/tests/auto/quick/nodes/tst_nodestest.cpp b/tests/auto/quick/nodes/tst_nodestest.cpp index b49ce34951..c49f01d5a7 100644 --- a/tests/auto/quick/nodes/tst_nodestest.cpp +++ b/tests/auto/quick/nodes/tst_nodestest.cpp @@ -283,7 +283,7 @@ void NodesTest::textureNodeTextureOwnership() QVERIFY(!texture.isNull()); } - { // Check that it is deleted when we so desire + { // Check that it is deleted on destruction when we so desire QPointer texture(new QSGPlainTexture()); QSGSimpleTextureNode *tn = new QSGSimpleTextureNode(); @@ -294,6 +294,25 @@ void NodesTest::textureNodeTextureOwnership() delete tn; QVERIFY(texture.isNull()); } + + { // Check that it is deleted on update when we so desire + QPointer oldTexture(new QSGPlainTexture()); + QPointer newTexture(new QSGPlainTexture()); + + QSGSimpleTextureNode *tn = new QSGSimpleTextureNode(); + tn->setOwnsTexture(true); + QVERIFY(tn->ownsTexture()); + + tn->setTexture(oldTexture); + QVERIFY(!oldTexture.isNull()); + QVERIFY(!newTexture.isNull()); + + tn->setTexture(newTexture); + QVERIFY(oldTexture.isNull()); + QVERIFY(!newTexture.isNull()); + + delete tn; + } } void NodesTest::textureNodeRect() -- cgit v1.2.3 From 982fa2225b7d69181344a00816cad19042a922e6 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Thu, 2 Jul 2015 15:54:43 +0200 Subject: Delete QQuickWindow's animator driver at the right time. For the non-threaded renderloops, we there might be a timer firing before the animationController is cleaned up through deleteLater() which will then reference the deleted QQuickWindow. Rely instead on direct and explicit cleanup at the right time in each render loop. Change-Id: Id81daddae78ce3922d6a932fb21200f2dc7955bb Task-number: QTBUG-33723 Reviewed-by: Liang Qi Reviewed-by: Robin Burchell --- src/quick/items/qquickwindow.cpp | 1 - src/quick/scenegraph/qsgrenderloop.cpp | 3 +++ src/quick/scenegraph/qsgthreadedrenderloop.cpp | 5 ++++- src/quick/scenegraph/qsgwindowsrenderloop.cpp | 6 ++++-- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index 84b585e3b5..4238787cc8 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -1112,7 +1112,6 @@ QQuickWindow::~QQuickWindow() { Q_D(QQuickWindow); - d->animationController->deleteLater(); if (d->renderControl) { QQuickRenderControlPrivate::get(d->renderControl)->windowDestroyed(); } else if (d->windowManager) { diff --git a/src/quick/scenegraph/qsgrenderloop.cpp b/src/quick/scenegraph/qsgrenderloop.cpp index ec9c3c39f9..4d3f34c71c 100644 --- a/src/quick/scenegraph/qsgrenderloop.cpp +++ b/src/quick/scenegraph/qsgrenderloop.cpp @@ -34,6 +34,7 @@ #include "qsgrenderloop_p.h" #include "qsgthreadedrenderloop_p.h" #include "qsgwindowsrenderloop_p.h" +#include #include #include @@ -305,6 +306,8 @@ void QSGGuiThreadRenderLoop::windowDestroyed(QQuickWindow *window) } else if (gl && window == gl->surface() && current) { gl->doneCurrent(); } + + delete d->animationController; } void QSGGuiThreadRenderLoop::renderWindow(QQuickWindow *window) diff --git a/src/quick/scenegraph/qsgthreadedrenderloop.cpp b/src/quick/scenegraph/qsgthreadedrenderloop.cpp index 56637387df..2cebbaf484 100644 --- a/src/quick/scenegraph/qsgthreadedrenderloop.cpp +++ b/src/quick/scenegraph/qsgthreadedrenderloop.cpp @@ -451,11 +451,12 @@ void QSGRenderThread::invalidateOpenGL(QQuickWindow *window, bool inDestructor, qCDebug(QSG_LOG_RENDERLOOP) << QSG_RT_PAD << "- cleanup without an OpenGL context"; } + QQuickWindowPrivate *dd = QQuickWindowPrivate::get(window); + QQuickShaderEffectMaterial::cleanupMaterialCache(); // The canvas nodes must be cleaned up regardless if we are in the destructor.. if (wipeSG) { - QQuickWindowPrivate *dd = QQuickWindowPrivate::get(window); dd->cleanupNodesOnShutdown(); } else { qCDebug(QSG_LOG_RENDERLOOP) << QSG_RT_PAD << "- persistent SG, avoiding cleanup"; @@ -467,6 +468,8 @@ void QSGRenderThread::invalidateOpenGL(QQuickWindow *window, bool inDestructor, sgrc->invalidate(); QCoreApplication::processEvents(); QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); + if (inDestructor) + delete dd->animationController; if (current) gl->doneCurrent(); qCDebug(QSG_LOG_RENDERLOOP) << QSG_RT_PAD << "- invalidating scene graph"; diff --git a/src/quick/scenegraph/qsgwindowsrenderloop.cpp b/src/quick/scenegraph/qsgwindowsrenderloop.cpp index c571e60018..7fd9651618 100644 --- a/src/quick/scenegraph/qsgwindowsrenderloop.cpp +++ b/src/quick/scenegraph/qsgwindowsrenderloop.cpp @@ -32,7 +32,6 @@ ****************************************************************************/ #include "qsgwindowsrenderloop_p.h" - #include #include #include @@ -47,8 +46,8 @@ #include #include - #include +#include QT_BEGIN_NAMESPACE @@ -219,6 +218,7 @@ void QSGWindowsRenderLoop::windowDestroyed(QQuickWindow *window) hide(window); QQuickWindowPrivate *d = QQuickWindowPrivate::get(window); + bool current = false; QScopedPointer offscreenSurface; if (m_gl) { @@ -245,6 +245,8 @@ void QSGWindowsRenderLoop::windowDestroyed(QQuickWindow *window) } else if (m_gl && current) { m_gl->doneCurrent(); } + + delete d->animationController; } bool QSGWindowsRenderLoop::anyoneShowing() const -- cgit v1.2.3 From c802a8582258ca9ad1cc800a9c8e6e46b2ff6f0e Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 27 Mar 2015 22:12:56 -0700 Subject: Fix ICC warning about change of sign qv4typedarray.cpp(87): error #68: integer conversion resulted in a change of sign Change-Id: Iee8cbc07c4434ce9b560ffff13cf917dd8f9012e Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4typedarray.cpp | 2 +- src/quick/util/qquickprofiler_p.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qml/jsruntime/qv4typedarray.cpp b/src/qml/jsruntime/qv4typedarray.cpp index 429ec96f0b..c355207d94 100644 --- a/src/qml/jsruntime/qv4typedarray.cpp +++ b/src/qml/jsruntime/qv4typedarray.cpp @@ -84,7 +84,7 @@ void UInt8ClampedArrayWrite(ExecutionEngine *e, char *data, int index, const Val return; } if (d >= 255) { - data[index] = (unsigned char)(255); + data[index] = (char)(255); return; } double f = std::floor(d); diff --git a/src/quick/util/qquickprofiler_p.h b/src/quick/util/qquickprofiler_p.h index 85a03fb57b..aaed4bd60e 100644 --- a/src/quick/util/qquickprofiler_p.h +++ b/src/quick/util/qquickprofiler_p.h @@ -259,7 +259,7 @@ public: } template - static void reportSceneGraphFrame(quint64 payload = -1) + static void reportSceneGraphFrame(quint64 payload = ~0) { qint64 *timings = s_instance->m_sceneGraphData.timings(); int &offset = s_instance->m_sceneGraphData.offset(); @@ -275,7 +275,7 @@ public: } template - static void reportSceneGraphFrame(quint64 payload = -1) + static void reportSceneGraphFrame(quint64 payload = ~0) { reportSceneGraphFrame(payload); s_instance->m_sceneGraphData.offset() = 0; -- cgit v1.2.3 From b69449b0a148d1546205cd8ca36ba87f88b449e6 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 14 May 2015 06:20:57 +0900 Subject: Fix more casts that dropped the constness. Found with GCC's -Wcast-qual Change-Id: I66a35ce5f88941f29aa6ffff13dde502fccefb1d Reviewed-by: Simon Hausmann --- src/quick/util/qquickanimatorjob.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/quick/util/qquickanimatorjob.cpp b/src/quick/util/qquickanimatorjob.cpp index 8b617e5e3f..2a8e3c281c 100644 --- a/src/quick/util/qquickanimatorjob.cpp +++ b/src/quick/util/qquickanimatorjob.cpp @@ -136,7 +136,7 @@ void QQuickAnimatorProxyJob::updateState(QAbstractAnimationJob::State newState, void QQuickAnimatorProxyJob::debugAnimation(QDebug d) const { - d << "QuickAnimatorProxyJob("<< hex << (void *) this << dec + d << "QuickAnimatorProxyJob("<< hex << (const void *) this << dec << "state:" << state() << "duration:" << duration() << "proxying: (" << job() << ')'; } @@ -225,7 +225,7 @@ QQuickAnimatorJob::QQuickAnimatorJob() void QQuickAnimatorJob::debugAnimation(QDebug d) const { - d << "QuickAnimatorJob(" << hex << (void *) this << dec + d << "QuickAnimatorJob(" << hex << (const void *) this << dec << ") state:" << state() << "duration:" << duration() << "target:" << m_target << "value:" << m_value; } -- cgit v1.2.3 From f558bc48585c69de36151248c969a484a969ebb4 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Tue, 7 Jul 2015 14:13:22 +0300 Subject: Fix encoding of QV4::Value in host builds When building on a 64-bit host targeting a 32-bit architecture, we would use QT_POINTER_SIZE == 4 from qconfig.h, which is unfortunately shared. However on 64-bit hosts the 32-bit encoding appears to result in gcc/clang to miscompile simple QV4::Value uses - when optimizations are enabled. As a workaround, let's use 64-bit encoding in all host scenarios. Change-Id: I000cf13abcc9240c931191d6361b6dee578cb5d4 Task-number: QTBUG-45364 Reviewed-by: Erik Verbruggen --- src/qml/jsruntime/qv4value_inl_p.h | 4 ++-- src/qml/jsruntime/qv4value_p.h | 24 ++++++++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/qml/jsruntime/qv4value_inl_p.h b/src/qml/jsruntime/qv4value_inl_p.h index 3a4c5c4822..f3026900d6 100644 --- a/src/qml/jsruntime/qv4value_inl_p.h +++ b/src/qml/jsruntime/qv4value_inl_p.h @@ -82,7 +82,7 @@ inline void Value::mark(ExecutionEngine *e) const inline Primitive Primitive::nullValue() { Primitive v; -#if QT_POINTER_SIZE == 8 +#ifdef QV4_USE_64_BIT_VALUE_ENCODING v.val = quint64(_Null_Type) << Tag_Shift; #else v.tag = _Null_Type; @@ -181,7 +181,7 @@ inline bool Value::toBoolean() const #ifndef V4_BOOTSTRAP inline uint Value::asArrayIndex() const { -#if QT_POINTER_SIZE == 8 +#ifdef QV4_USE_64_BIT_VALUE_ENCODING if (!isNumber()) return UINT_MAX; if (isInteger()) diff --git a/src/qml/jsruntime/qv4value_p.h b/src/qml/jsruntime/qv4value_p.h index cd1aef86d7..628950784a 100644 --- a/src/qml/jsruntime/qv4value_p.h +++ b/src/qml/jsruntime/qv4value_p.h @@ -38,6 +38,14 @@ #include #include "qv4global_p.h" +/* We cannot rely on QT_POINTER_SIZE to be set correctly on host builds. In qmldevtools the Value objects + are only used to store primitives, never object pointers. So we can use the 64-bit encoding. */ +#ifdef V4_BOOTSTRAP +#define QV4_USE_64_BIT_VALUE_ENCODING +#elif QT_POINTER_SIZE == 8 +#define QV4_USE_64_BIT_VALUE_ENCODING +#endif + QT_BEGIN_NAMESPACE namespace QV4 { @@ -119,7 +127,7 @@ struct Q_QML_PRIVATE_EXPORT Value union { quint64 val; -#if QT_POINTER_SIZE == 8 +#ifdef QV4_USE_64_BIT_VALUE_ENCODING Heap::Base *m; #else double dbl; @@ -131,7 +139,7 @@ struct Q_QML_PRIVATE_EXPORT Value union { uint uint_32; int int_32; -#if QT_POINTER_SIZE == 4 +#ifndef QV4_USE_64_BIT_VALUE_ENCODING Heap::Base *m; #endif }; @@ -141,7 +149,7 @@ struct Q_QML_PRIVATE_EXPORT Value }; }; -#if QT_POINTER_SIZE == 4 +#ifndef QV4_USE_64_BIT_VALUE_ENCODING enum Masks { SilentNaNBit = 0x00040000, NaN_Mask = 0x7ff80000, @@ -221,7 +229,7 @@ struct Q_QML_PRIVATE_EXPORT Value inline bool isUndefined() const { return tag == Undefined_Type; } inline bool isNull() const { return tag == _Null_Type; } inline bool isBoolean() const { return tag == _Boolean_Type; } -#if QT_POINTER_SIZE == 8 +#ifdef QV4_USE_64_BIT_VALUE_ENCODING inline bool isInteger() const { return (val >> IsNumber_Shift) == 1; } inline bool isDouble() const { return (val >> IsDouble_Shift); } inline bool isNumber() const { return (val >> IsNumber_Shift); } @@ -320,7 +328,7 @@ struct Q_QML_PRIVATE_EXPORT Value { Value v; v.m = m; -#if QT_POINTER_SIZE == 4 +#ifndef QV4_USE_64_BIT_VALUE_ENCODING v.tag = Managed_Type; #endif return v; @@ -386,7 +394,7 @@ struct Q_QML_PRIVATE_EXPORT Value } Value &operator=(Heap::Base *o) { m = o; -#if QT_POINTER_SIZE == 4 +#ifndef QV4_USE_64_BIT_VALUE_ENCODING tag = Managed_Type; #endif return *this; @@ -428,7 +436,7 @@ struct Q_QML_PRIVATE_EXPORT Primitive : public Value inline Primitive Primitive::undefinedValue() { Primitive v; -#if QT_POINTER_SIZE == 8 +#ifdef QV4_USE_64_BIT_VALUE_ENCODING v.val = quint64(Undefined_Type) << Tag_Shift; #else v.tag = Undefined_Type; @@ -451,7 +459,7 @@ struct TypedValue : public Value template TypedValue &operator =(X *x) { m = x; -#if QT_POINTER_SIZE == 4 +#ifndef QV4_USE_64_BIT_VALUE_ENCODING tag = Managed_Type; #endif return *this; -- cgit v1.2.3 From f35be0bc5afe940bb95695a319176e45fec1f594 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sat, 7 Mar 2015 14:35:47 -0800 Subject: QtQml: Fix const correctness in old style casts Found with GCC's -Wcast-qual. Change-Id: Ia0aac2f09e9245339951ffff13c958364a2e9859 Reviewed-by: Simon Hausmann --- src/qml/animations/qabstractanimationjob.cpp | 2 +- src/qml/animations/qcontinuinganimationgroupjob.cpp | 2 +- src/qml/animations/qparallelanimationgroupjob.cpp | 2 +- src/qml/animations/qpauseanimationjob.cpp | 2 +- src/qml/animations/qsequentialanimationgroupjob.cpp | 2 +- src/qml/jsruntime/qv4engine.cpp | 4 ++-- src/qml/jsruntime/qv4serialize.cpp | 10 +++++----- src/qml/jsruntime/qv4typedarray.cpp | 12 ++++++------ src/qml/jsruntime/qv4vme_moth.cpp | 8 ++++---- src/qml/qml/ftw/qbitfield_p.h | 11 ++++++----- src/qml/qml/ftw/qhashedstring_p.h | 4 ++-- src/qml/qml/qqmlcontext.cpp | 2 +- src/qml/qml/qqmlengine.cpp | 2 +- src/qml/qml/qqmlmetatype.cpp | 2 +- src/qml/qml/qqmlproperty.cpp | 10 +++++----- src/qml/qml/qqmlpropertycache.cpp | 2 +- src/qml/qml/qqmlvaluetype.cpp | 2 +- src/qml/qml/qqmlvmemetaobject.cpp | 4 ++-- src/qml/qml/qqmlvmemetaobject_p.h | 2 +- src/qml/util/qqmllistaccessor.cpp | 4 ++-- 20 files changed, 45 insertions(+), 44 deletions(-) diff --git a/src/qml/animations/qabstractanimationjob.cpp b/src/qml/animations/qabstractanimationjob.cpp index 7fcf383bcb..d301c43822 100644 --- a/src/qml/animations/qabstractanimationjob.cpp +++ b/src/qml/animations/qabstractanimationjob.cpp @@ -652,7 +652,7 @@ void QAbstractAnimationJob::removeAnimationChangeListener(QAnimationJobChangeLis void QAbstractAnimationJob::debugAnimation(QDebug d) const { - d << "AbstractAnimationJob(" << hex << (void *) this << dec << ") state:" + d << "AbstractAnimationJob(" << hex << (const void *) this << dec << ") state:" << m_state << "duration:" << duration(); } diff --git a/src/qml/animations/qcontinuinganimationgroupjob.cpp b/src/qml/animations/qcontinuinganimationgroupjob.cpp index c77448f153..88005baf12 100644 --- a/src/qml/animations/qcontinuinganimationgroupjob.cpp +++ b/src/qml/animations/qcontinuinganimationgroupjob.cpp @@ -115,7 +115,7 @@ void QContinuingAnimationGroupJob::uncontrolledAnimationFinished(QAbstractAnimat void QContinuingAnimationGroupJob::debugAnimation(QDebug d) const { - d << "ContinuingAnimationGroupJob(" << hex << (void *) this << dec << ")"; + d << "ContinuingAnimationGroupJob(" << hex << (const void *) this << dec << ")"; debugChildren(d); } diff --git a/src/qml/animations/qparallelanimationgroupjob.cpp b/src/qml/animations/qparallelanimationgroupjob.cpp index 0153794d6f..fe56f2b1e8 100644 --- a/src/qml/animations/qparallelanimationgroupjob.cpp +++ b/src/qml/animations/qparallelanimationgroupjob.cpp @@ -233,7 +233,7 @@ void QParallelAnimationGroupJob::uncontrolledAnimationFinished(QAbstractAnimatio void QParallelAnimationGroupJob::debugAnimation(QDebug d) const { - d << "ParallelAnimationGroupJob(" << hex << (void *) this << dec << ")"; + d << "ParallelAnimationGroupJob(" << hex << (const void *) this << dec << ")"; debugChildren(d); } diff --git a/src/qml/animations/qpauseanimationjob.cpp b/src/qml/animations/qpauseanimationjob.cpp index 8e35c58999..0e95645f41 100644 --- a/src/qml/animations/qpauseanimationjob.cpp +++ b/src/qml/animations/qpauseanimationjob.cpp @@ -62,7 +62,7 @@ void QPauseAnimationJob::updateCurrentTime(int) void QPauseAnimationJob::debugAnimation(QDebug d) const { - d << "PauseAnimationJob(" << hex << (void *) this << dec << ")" << "duration:" << m_duration; + d << "PauseAnimationJob(" << hex << (const void *) this << dec << ")" << "duration:" << m_duration; } QT_END_NAMESPACE diff --git a/src/qml/animations/qsequentialanimationgroupjob.cpp b/src/qml/animations/qsequentialanimationgroupjob.cpp index 5060b7f6cd..b92caf3bc4 100644 --- a/src/qml/animations/qsequentialanimationgroupjob.cpp +++ b/src/qml/animations/qsequentialanimationgroupjob.cpp @@ -411,7 +411,7 @@ void QSequentialAnimationGroupJob::animationRemoved(QAbstractAnimationJob *anim, void QSequentialAnimationGroupJob::debugAnimation(QDebug d) const { - d << "SequentialAnimationGroupJob(" << hex << (void *) this << dec << ")" << "currentAnimation:" << (void *)m_currentAnimation; + d << "SequentialAnimationGroupJob(" << hex << (const void *) this << dec << ")" << "currentAnimation:" << (void *)m_currentAnimation; debugChildren(d); } diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index ba6f5a3b79..2dbdcfc526 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -1447,7 +1447,7 @@ QV4::ReturnedValue QV4::ExecutionEngine::fromVariant(const QVariant &variant) QV4::Scope scope(this); if (type == qMetaTypeId()) { typedef QQmlListReferencePrivate QDLRP; - QDLRP *p = QDLRP::get((QQmlListReference*)ptr); + QDLRP *p = QDLRP::get((QQmlListReference*)const_cast(ptr)); if (p->object) { return QV4::QmlListWrapper::create(scope.engine, p->property, p->propertyType); } else { @@ -1459,7 +1459,7 @@ QV4::ReturnedValue QV4::ExecutionEngine::fromVariant(const QVariant &variant) } else if (type == qMetaTypeId >()) { // XXX Can this be made more by using Array as a prototype and implementing // directly against QList? - const QList &list = *(QList*)ptr; + const QList &list = *(const QList*)ptr; QV4::ScopedArrayObject a(scope, newArrayObject()); a->arrayReserve(list.count()); QV4::ScopedValue v(scope); diff --git a/src/qml/jsruntime/qv4serialize.cpp b/src/qml/jsruntime/qv4serialize.cpp index e669924d4a..31d85df13e 100644 --- a/src/qml/jsruntime/qv4serialize.cpp +++ b/src/qml/jsruntime/qv4serialize.cpp @@ -116,21 +116,21 @@ static inline void reserve(QByteArray &data, int extra) static inline quint32 popUint32(const char *&data) { - quint32 rv = *((quint32 *)data); + quint32 rv = *((const quint32 *)data); data += sizeof(quint32); return rv; } static inline double popDouble(const char *&data) { - double rv = *((double *)data); + double rv = *((const double *)data); data += sizeof(double); return rv; } static inline void *popPtr(const char *&data) { - void *rv = *((void **)data); + void *rv = *((void *const *)data); data += sizeof(void *); return rv; } @@ -297,7 +297,7 @@ ReturnedValue Serialize::deserialize(const char *&data, ExecutionEngine *engine) case WorkerString: { quint32 size = headersize(header); - QString qstr((QChar *)data, size); + QString qstr((const QChar *)data, size); data += ALIGN(size * sizeof(quint16)); return QV4::Encode(engine->newString(qstr)); } @@ -342,7 +342,7 @@ ReturnedValue Serialize::deserialize(const char *&data, ExecutionEngine *engine) { quint32 flags = headersize(header); quint32 length = popUint32(data); - QString pattern = QString((QChar *)data, length - 1); + QString pattern = QString((const QChar *)data, length - 1); data += ALIGN(length * sizeof(quint16)); return Encode(engine->newRegExpObject(pattern, flags)); } diff --git a/src/qml/jsruntime/qv4typedarray.cpp b/src/qml/jsruntime/qv4typedarray.cpp index c355207d94..19e541dba8 100644 --- a/src/qml/jsruntime/qv4typedarray.cpp +++ b/src/qml/jsruntime/qv4typedarray.cpp @@ -106,7 +106,7 @@ void UInt8ClampedArrayWrite(ExecutionEngine *e, char *data, int index, const Val ReturnedValue Int16ArrayRead(const char *data, int index) { - return Encode((int)*(short *)(data + index)); + return Encode((int)*(const short *)(data + index)); } void Int16ArrayWrite(ExecutionEngine *e, char *data, int index, const Value &value) @@ -119,7 +119,7 @@ void Int16ArrayWrite(ExecutionEngine *e, char *data, int index, const Value &val ReturnedValue UInt16ArrayRead(const char *data, int index) { - return Encode((int)*(unsigned short *)(data + index)); + return Encode((int)*(const unsigned short *)(data + index)); } void UInt16ArrayWrite(ExecutionEngine *e, char *data, int index, const Value &value) @@ -132,7 +132,7 @@ void UInt16ArrayWrite(ExecutionEngine *e, char *data, int index, const Value &va ReturnedValue Int32ArrayRead(const char *data, int index) { - return Encode(*(int *)(data + index)); + return Encode(*(const int *)(data + index)); } void Int32ArrayWrite(ExecutionEngine *e, char *data, int index, const Value &value) @@ -145,7 +145,7 @@ void Int32ArrayWrite(ExecutionEngine *e, char *data, int index, const Value &val ReturnedValue UInt32ArrayRead(const char *data, int index) { - return Encode(*(unsigned int *)(data + index)); + return Encode(*(const unsigned int *)(data + index)); } void UInt32ArrayWrite(ExecutionEngine *e, char *data, int index, const Value &value) @@ -158,7 +158,7 @@ void UInt32ArrayWrite(ExecutionEngine *e, char *data, int index, const Value &va ReturnedValue Float32ArrayRead(const char *data, int index) { - return Encode(*(float *)(data + index)); + return Encode(*(const float *)(data + index)); } void Float32ArrayWrite(ExecutionEngine *e, char *data, int index, const Value &value) @@ -171,7 +171,7 @@ void Float32ArrayWrite(ExecutionEngine *e, char *data, int index, const Value &v ReturnedValue Float64ArrayRead(const char *data, int index) { - return Encode(*(double *)(data + index)); + return Encode(*(const double *)(data + index)); } void Float64ArrayWrite(ExecutionEngine *e, char *data, int index, const Value &value) diff --git a/src/qml/jsruntime/qv4vme_moth.cpp b/src/qml/jsruntime/qv4vme_moth.cpp index dda5848f0b..390bbf5ee3 100644 --- a/src/qml/jsruntime/qv4vme_moth.cpp +++ b/src/qml/jsruntime/qv4vme_moth.cpp @@ -593,7 +593,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_END_INSTR(CallGlobalLookup) MOTH_BEGIN_INSTR(SetExceptionHandler) - exceptionHandler = instr.offset ? ((uchar *)&instr.offset) + instr.offset : 0; + exceptionHandler = instr.offset ? ((const uchar *)&instr.offset) + instr.offset : 0; MOTH_END_INSTR(SetExceptionHandler) MOTH_BEGIN_INSTR(CallBuiltinThrow) @@ -727,21 +727,21 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_END_INSTR(ConstructGlobalLookup) MOTH_BEGIN_INSTR(Jump) - code = ((uchar *)&instr.offset) + instr.offset; + code = ((const uchar *)&instr.offset) + instr.offset; MOTH_END_INSTR(Jump) MOTH_BEGIN_INSTR(JumpEq) bool cond = VALUEPTR(instr.condition)->toBoolean(); TRACE(condition, "%s", cond ? "TRUE" : "FALSE"); if (cond) - code = ((uchar *)&instr.offset) + instr.offset; + code = ((const uchar *)&instr.offset) + instr.offset; MOTH_END_INSTR(JumpEq) MOTH_BEGIN_INSTR(JumpNe) bool cond = VALUEPTR(instr.condition)->toBoolean(); TRACE(condition, "%s", cond ? "TRUE" : "FALSE"); if (!cond) - code = ((uchar *)&instr.offset) + instr.offset; + code = ((const uchar *)&instr.offset) + instr.offset; MOTH_END_INSTR(JumpNe) MOTH_BEGIN_INSTR(UNot) diff --git a/src/qml/qml/ftw/qbitfield_p.h b/src/qml/qml/ftw/qbitfield_p.h index 0b7d507b11..e3b6b0e498 100644 --- a/src/qml/qml/ftw/qbitfield_p.h +++ b/src/qml/qml/ftw/qbitfield_p.h @@ -129,15 +129,16 @@ QBitField QBitField::united(const QBitField &o) rv.bits = max; rv.ownData = new quint32[length + 1]; *(rv.ownData) = 1; - rv.data = rv.ownData + 1; + quint32 *rvdata; + rv.data = rvdata = rv.ownData + 1; if (bits > o.bits) { - ::memcpy((quint32 *)rv.data, data, length * sizeof(quint32)); + ::memcpy(rvdata, data, length * sizeof(quint32)); for (quint32 ii = 0; ii < (o.bits + quint32(31)) / 32; ++ii) - ((quint32 *)rv.data)[ii] |= o.data[ii]; + (rvdata)[ii] |= o.data[ii]; } else { - ::memcpy((quint32 *)rv.data, o.data, length * sizeof(quint32)); + ::memcpy(rvdata, o.data, length * sizeof(quint32)); for (quint32 ii = 0; ii < (bits + quint32(31)) / 32; ++ii) - ((quint32 *)rv.data)[ii] |= data[ii]; + (rvdata)[ii] |= data[ii]; } return rv; } diff --git a/src/qml/qml/ftw/qhashedstring_p.h b/src/qml/qml/ftw/qhashedstring_p.h index 6ae2e17267..d38fd668f3 100644 --- a/src/qml/qml/ftw/qhashedstring_p.h +++ b/src/qml/qml/ftw/qhashedstring_p.h @@ -252,14 +252,14 @@ public: inline bool equals(const QHashedStringRef &string) const { return length == string.length() && hash == string.hash() && - (isQString()?QHashedString::compare(string.constData(), (QChar *)utf16Data(), length): + (isQString()?QHashedString::compare(string.constData(), (const QChar *)utf16Data(), length): QHashedString::compare(string.constData(), cStrData(), length)); } inline bool equals(const QHashedCStringRef &string) const { return length == string.length() && hash == string.hash() && - (isQString()?QHashedString::compare((QChar *)utf16Data(), string.constData(), length): + (isQString()?QHashedString::compare((const QChar *)utf16Data(), string.constData(), length): QHashedString::compare(string.constData(), cStrData(), length)); } }; diff --git a/src/qml/qml/qqmlcontext.cpp b/src/qml/qml/qqmlcontext.cpp index f08f650913..fb51bad3a7 100644 --- a/src/qml/qml/qqmlcontext.cpp +++ b/src/qml/qml/qqmlcontext.cpp @@ -783,7 +783,7 @@ QString QQmlContextData::findObjectId(const QObject *obj) const if (publicContext) { QQmlContextPrivate *p = QQmlContextPrivate::get(publicContext); for (int ii = 0; ii < p->propertyValues.count(); ++ii) - if (p->propertyValues.at(ii) == QVariant::fromValue((QObject *)obj)) + if (p->propertyValues.at(ii) == QVariant::fromValue(const_cast(obj))) return properties.findId(ii); } diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index 8cf3d2064d..1f27e4ecb3 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -2228,7 +2228,7 @@ QObject *QQmlEnginePrivate::toQObject(const QVariant &v, bool *ok) const int t = v.userType(); if (t == QMetaType::QObjectStar || m_compositeTypes.contains(t)) { if (ok) *ok = true; - return *(QObject **)(v.constData()); + return *(QObject *const *)(v.constData()); } else { return QQmlMetaType::toQObject(v, ok); } diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp index 2f7834fa41..41d44a821a 100644 --- a/src/qml/qml/qqmlmetatype.cpp +++ b/src/qml/qml/qqmlmetatype.cpp @@ -1508,7 +1508,7 @@ QObject *QQmlMetaType::toQObject(const QVariant &v, bool *ok) if (ok) *ok = true; - return *(QObject **)v.constData(); + return *(QObject *const *)v.constData(); } bool QQmlMetaType::isQObject(int userType) diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp index ae452b727e..800f650075 100644 --- a/src/qml/qml/qqmlproperty.cpp +++ b/src/qml/qml/qqmlproperty.cpp @@ -1304,12 +1304,12 @@ bool QQmlPropertyPrivate::write(QObject *object, QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, argv); } else if (variantType == propertyType) { - void *a[] = { (void *)value.constData(), 0, &status, &flags }; + void *a[] = { const_cast(value.constData()), 0, &status, &flags }; QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); } else if (qMetaTypeId() == propertyType) { - void *a[] = { (void *)&value, 0, &status, &flags }; + void *a[] = { const_cast(&value), 0, &status, &flags }; QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); } else if (property.isQObject()) { @@ -1319,7 +1319,7 @@ bool QQmlPropertyPrivate::write(QObject *object, if (valMo.isNull()) return false; - QObject *o = *(QObject **)value.constData(); + QObject *o = *(QObject *const *)value.constData(); QQmlMetaObject propMo = rawMetaObjectForType(enginePriv, propertyType); if (o) valMo = o; @@ -1465,7 +1465,7 @@ bool QQmlPropertyPrivate::write(QObject *object, } if (ok) { - void *a[] = { (void *)v.constData(), 0, &status, &flags}; + void *a[] = { const_cast(v.constData()), 0, &status, &flags}; QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); } else { return false; @@ -1603,7 +1603,7 @@ bool QQmlPropertyPrivate::writeBinding(QObject *object, const char *propertyType = 0; if (value.userType() == QMetaType::QObjectStar) { - if (QObject *o = *(QObject **)value.constData()) { + if (QObject *o = *(QObject *const *)value.constData()) { valueType = o->metaObject()->className(); QQmlMetaObject propertyMetaObject = rawMetaObjectForType(QQmlEnginePrivate::get(engine), type); diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp index dd1f93ec00..0018275b95 100644 --- a/src/qml/qml/qqmlpropertycache.cpp +++ b/src/qml/qml/qqmlpropertycache.cpp @@ -271,7 +271,7 @@ QQmlPropertyCache::~QQmlPropertyCache() stringCache.clear(); if (_parent) _parent->release(); - if (_ownMetaObject) free((void *)_metaObject); + if (_ownMetaObject) free(const_cast(_metaObject)); _metaObject = 0; _parent = 0; engine = 0; diff --git a/src/qml/qml/qqmlvaluetype.cpp b/src/qml/qml/qqmlvaluetype.cpp index b147266080..10eaae0c77 100644 --- a/src/qml/qml/qqmlvaluetype.cpp +++ b/src/qml/qml/qqmlvaluetype.cpp @@ -202,7 +202,7 @@ QQmlValueType::~QQmlValueType() QObjectPrivate *op = QObjectPrivate::get(this); Q_ASSERT(op->metaObject == this); op->metaObject = 0; - ::free((void*)_metaObject); + ::free(const_cast(_metaObject)); metaType.destroy(gadgetPtr); } diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 5b1be15869..97fc382c33 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -772,7 +772,7 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) int listIndex = data[id].asInt(); const List *list = &listProperties.at(listIndex); *reinterpret_cast *>(a[0]) = - QQmlListProperty(object, (void *)list, + QQmlListProperty(object, const_cast(list), list_append, list_count, list_at, list_clear); } @@ -1090,7 +1090,7 @@ void QQmlVMEMetaObject::writeProperty(int id, const QVariant &value) } else { bool needActivate = false; if (value.userType() == QMetaType::QObjectStar) { - QObject *o = *(QObject **)value.data(); + QObject *o = *(QObject *const *)value.data(); needActivate = (data[id].dataType() != QMetaType::QObjectStar || data[id].asQObject() != o); data[id].setValue(o, this, id); } else { diff --git a/src/qml/qml/qqmlvmemetaobject_p.h b/src/qml/qml/qqmlvmemetaobject_p.h index d0e2e34ff1..f3048d426a 100644 --- a/src/qml/qml/qqmlvmemetaobject_p.h +++ b/src/qml/qml/qqmlvmemetaobject_p.h @@ -119,7 +119,7 @@ struct QQmlVMEMetaData }; PropertyData *propertyData() const { - return (PropertyData *)(((const char *)this) + sizeof(QQmlVMEMetaData)); + return (PropertyData *)(((char *)const_cast(this)) + sizeof(QQmlVMEMetaData)); } AliasData *aliasData() const { diff --git a/src/qml/util/qqmllistaccessor.cpp b/src/qml/util/qqmllistaccessor.cpp index 55b745ab6d..bebab80d28 100644 --- a/src/qml/util/qqmllistaccessor.cpp +++ b/src/qml/util/qqmllistaccessor.cpp @@ -96,7 +96,7 @@ int QQmlListAccessor::count() const case VariantList: return qvariant_cast(d).count(); case ListProperty: - return ((QQmlListReference *)d.constData())->count(); + return ((const QQmlListReference *)d.constData())->count(); case Instance: return 1; case Integer: @@ -116,7 +116,7 @@ QVariant QQmlListAccessor::at(int idx) const case VariantList: return qvariant_cast(d).at(idx); case ListProperty: - return QVariant::fromValue(((QQmlListReference *)d.constData())->at(idx)); + return QVariant::fromValue(((const QQmlListReference *)d.constData())->at(idx)); case Instance: return d; case Integer: -- cgit v1.2.3 From ea6be7e47cce456a5a838d14925bff01f664a01f Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Fri, 26 Jun 2015 18:14:31 +0200 Subject: Flickable: drag-over-bounds is not velocity-sensitive The inspiration for velocity sensitivity was to make it feel more like native trackpad flicking on OS X. But on touchscreens it doesn't make as much sense, and it became too difficult to intentionally overshoot in applications that depend on pull-to-refresh functionality. Task-number: QTBUG-46108 Change-Id: I3fea5324aaac1f003ead200e14b0c76bd8c0ece6 Reviewed-by: J-P Nurmi --- src/quick/items/qquickflickable.cpp | 47 ++++++++++++++++++++++++----------- src/quick/items/qquickflickable_p_p.h | 3 ++- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/quick/items/qquickflickable.cpp b/src/quick/items/qquickflickable.cpp index 52142346ab..19fb66c19c 100644 --- a/src/quick/items/qquickflickable.cpp +++ b/src/quick/items/qquickflickable.cpp @@ -1004,7 +1004,8 @@ void QQuickFlickablePrivate::maybeBeginDrag(qint64 currentTimestamp, const QPoin } void QQuickFlickablePrivate::drag(qint64 currentTimestamp, QEvent::Type eventType, const QPointF &localPos, - const QVector2D &deltas, bool overThreshold, bool momentum, const QVector2D &velocity) + const QVector2D &deltas, bool overThreshold, bool momentum, + bool velocitySensitiveOverBounds, const QVector2D &velocity) { Q_Q(QQuickFlickable); bool rejectY = false; @@ -1061,9 +1062,13 @@ void QQuickFlickablePrivate::drag(qint64 currentTimestamp, QEvent::Type eventTyp } return; } - qreal overshoot = (newY - minY) * vData.velocity / QML_FLICK_DEFAULTMAXVELOCITY / QML_FLICK_OVERSHOOTFRICTION; - overshoot = QML_FLICK_OVERSHOOT * devicePixelRatio() * EaseOvershoot(overshoot / QML_FLICK_OVERSHOOT / devicePixelRatio()); - newY = minY + overshoot; + if (velocitySensitiveOverBounds) { + qreal overshoot = (newY - minY) * vData.velocity / QML_FLICK_DEFAULTMAXVELOCITY / QML_FLICK_OVERSHOOTFRICTION; + overshoot = QML_FLICK_OVERSHOOT * devicePixelRatio() * EaseOvershoot(overshoot / QML_FLICK_OVERSHOOT / devicePixelRatio()); + newY = minY + overshoot; + } else { + newY = minY + (newY - minY) / 2; + } } else if (newY < maxY && maxY - minY <= 0) { // Overshoot beyond the bottom. But don't wait for momentum phase to end before returning to bounds. if (momentum && vData.atEnd) { @@ -1073,9 +1078,13 @@ void QQuickFlickablePrivate::drag(qint64 currentTimestamp, QEvent::Type eventTyp } return; } - qreal overshoot = (newY - maxY) * vData.velocity / QML_FLICK_DEFAULTMAXVELOCITY / QML_FLICK_OVERSHOOTFRICTION; - overshoot = QML_FLICK_OVERSHOOT * devicePixelRatio() * EaseOvershoot(overshoot / QML_FLICK_OVERSHOOT / devicePixelRatio()); - newY = maxY - overshoot; + if (velocitySensitiveOverBounds) { + qreal overshoot = (newY - maxY) * vData.velocity / QML_FLICK_DEFAULTMAXVELOCITY / QML_FLICK_OVERSHOOTFRICTION; + overshoot = QML_FLICK_OVERSHOOT * devicePixelRatio() * EaseOvershoot(overshoot / QML_FLICK_OVERSHOOT / devicePixelRatio()); + newY = maxY - overshoot; + } else { + newY = maxY + (newY - maxY) / 2; + } } } if (!rejectY && stealMouse && dy != 0.0 && dy != vData.previousDragDelta) { @@ -1126,9 +1135,13 @@ void QQuickFlickablePrivate::drag(qint64 currentTimestamp, QEvent::Type eventTyp } return; } - qreal overshoot = (newX - minX) * hData.velocity / QML_FLICK_DEFAULTMAXVELOCITY / QML_FLICK_OVERSHOOTFRICTION; - overshoot = QML_FLICK_OVERSHOOT * devicePixelRatio() * EaseOvershoot(overshoot / QML_FLICK_OVERSHOOT / devicePixelRatio()); - newX = minX + overshoot; + if (velocitySensitiveOverBounds) { + qreal overshoot = (newX - minX) * hData.velocity / QML_FLICK_DEFAULTMAXVELOCITY / QML_FLICK_OVERSHOOTFRICTION; + overshoot = QML_FLICK_OVERSHOOT * devicePixelRatio() * EaseOvershoot(overshoot / QML_FLICK_OVERSHOOT / devicePixelRatio()); + newX = minX + overshoot; + } else { + newX = minX + (newX - minX) / 2; + } } else if (newX < maxX && maxX - minX <= 0) { // Overshoot beyond the right. But don't wait for momentum phase to end before returning to bounds. if (momentum && hData.atEnd) { @@ -1138,9 +1151,13 @@ void QQuickFlickablePrivate::drag(qint64 currentTimestamp, QEvent::Type eventTyp } return; } - qreal overshoot = (newX - maxX) * hData.velocity / QML_FLICK_DEFAULTMAXVELOCITY / QML_FLICK_OVERSHOOTFRICTION; - overshoot = QML_FLICK_OVERSHOOT * devicePixelRatio() * EaseOvershoot(overshoot / QML_FLICK_OVERSHOOT / devicePixelRatio()); - newX = maxX - overshoot; + if (velocitySensitiveOverBounds) { + qreal overshoot = (newX - maxX) * hData.velocity / QML_FLICK_DEFAULTMAXVELOCITY / QML_FLICK_OVERSHOOTFRICTION; + overshoot = QML_FLICK_OVERSHOOT * devicePixelRatio() * EaseOvershoot(overshoot / QML_FLICK_OVERSHOOT / devicePixelRatio()); + newX = maxX - overshoot; + } else { + newX = maxX + (newX - maxX) / 2; + } } } @@ -1210,7 +1227,7 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event) if (q->xflick()) overThreshold |= QQuickWindowPrivate::dragOverThreshold(deltas.x(), Qt::XAxis, event); - drag(currentTimestamp, event->type(), event->localPos(), deltas, overThreshold, false, velocity); + drag(currentTimestamp, event->type(), event->localPos(), deltas, overThreshold, false, false, velocity); } void QQuickFlickablePrivate::handleMouseReleaseEvent(QMouseEvent *event) @@ -1433,7 +1450,7 @@ void QQuickFlickable::wheelEvent(QWheelEvent *event) QVector2D velocity(xDelta / elapsed, yDelta / elapsed); d->lastPosTime = currentTimestamp; d->accumulatedWheelPixelDelta += QVector2D(event->pixelDelta()); - d->drag(currentTimestamp, event->type(), event->posF(), d->accumulatedWheelPixelDelta, true, !d->scrollingPhase, velocity); + d->drag(currentTimestamp, event->type(), event->posF(), d->accumulatedWheelPixelDelta, true, !d->scrollingPhase, true, velocity); } if (!event->isAccepted()) diff --git a/src/quick/items/qquickflickable_p_p.h b/src/quick/items/qquickflickable_p_p.h index d7148ca57a..65bb3e802d 100644 --- a/src/quick/items/qquickflickable_p_p.h +++ b/src/quick/items/qquickflickable_p_p.h @@ -250,7 +250,8 @@ public: void maybeBeginDrag(qint64 currentTimestamp, const QPointF &pressPosn); void drag(qint64 currentTimestamp, QEvent::Type eventType, const QPointF &localPos, - const QVector2D &deltas, bool overThreshold, bool momentum, const QVector2D &velocity); + const QVector2D &deltas, bool overThreshold, bool momentum, + bool velocitySensitiveOverBounds, const QVector2D &velocity); qint64 computeCurrentTime(QInputEvent *event); qreal devicePixelRatio(); -- cgit v1.2.3 From 0c7fe9a33e696b8a319f96daaaf730ed03e9b233 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Thu, 2 Jul 2015 15:30:47 +0200 Subject: doc: fix copy/paste error in warning Change-Id: I4a9a46913b589b14c879620848d76b31e435ee02 Reviewed-by: Robin Burchell --- src/quick/items/qquickwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index 4238787cc8..a17d4a4357 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -3530,7 +3530,7 @@ QQmlIncubationController *QQuickWindow::incubationController() const slot function needs to finish before execution continues, you must make sure that the connection is direct (see Qt::ConnectionType). - \warning Make very sure that a signal handler for afterRendering() leaves the GL + \warning Make very sure that a signal handler for sceneGraphAboutToStop() leaves the GL context in the same state as it was when the signal handler was entered. Failing to do so can result in the scene not rendering properly. -- cgit v1.2.3 From c749f37c83cbb458e25a7d5200facf8634ac959e Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Fri, 3 Jul 2015 13:20:18 +0200 Subject: V4: track C++ heap usage for Strings in the MemoryManager ... and do a GC run when it exceeds a threshold. The issue with Strings is that they hold on to QString instances that store the real content. However, the GC only sees the light-weight JS handle, and doesn't take the size of the backing content into account. So it could happen that big QStrings accumulate in the heap as long as the GC didn't reach its threshold. The newly introduced unmanaged heap threshold is upped by a factor of two when exceeded, and lowered by a factor of 2 when the used heap space falls below a quarter of the threshold. Also grow the threshold if there is enough space after running the GC, but another GC run would be triggered for the next allocation. There is a special case for Heap::String::append, because this method will copy the data from the left and right substrings into a new QString. To track this, append notifies the memory manager directly of the new length. The pointer to the memory manager is stored in Heap::String, growing it from 40 bytes to 48 bytes (which makes it still fit in the same bucket, so no extra memory is allocated). Task-number: QTBUG-42002 Change-Id: I71313915e593a9908a2b227b0bc4d768e375ee17 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4engine.cpp | 2 +- src/qml/jsruntime/qv4function.cpp | 3 ++- src/qml/jsruntime/qv4mm.cpp | 48 +++++++++++++++++++++++++++++++++------ src/qml/jsruntime/qv4mm_p.h | 17 +++++++++++--- src/qml/jsruntime/qv4runtime.cpp | 9 +++++--- src/qml/jsruntime/qv4string.cpp | 7 ++++-- src/qml/jsruntime/qv4string_p.h | 8 +++++-- 7 files changed, 75 insertions(+), 19 deletions(-) diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 2dbdcfc526..0f2b44fac6 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -538,7 +538,7 @@ Heap::Object *ExecutionEngine::newObject(InternalClass *internalClass, QV4::Obje Heap::String *ExecutionEngine::newString(const QString &s) { Scope scope(this); - return ScopedString(scope, memoryManager->alloc(s))->d(); + return ScopedString(scope, memoryManager->allocWithStringData(s.length() * sizeof(QChar), s))->d(); } Heap::String *ExecutionEngine::newIdentifier(const QString &text) diff --git a/src/qml/jsruntime/qv4function.cpp b/src/qml/jsruntime/qv4function.cpp index efe6c7c226..be63b31e1e 100644 --- a/src/qml/jsruntime/qv4function.cpp +++ b/src/qml/jsruntime/qv4function.cpp @@ -66,7 +66,8 @@ Function::Function(ExecutionEngine *engine, CompiledData::CompilationUnit *unit, break; } // duplicate arguments, need some trick to store them - arg = engine->memoryManager->alloc(arg->d(), engine->newString(QString(0xfffe))); + MemoryManager *mm = engine->memoryManager; + arg = mm->alloc(mm, arg->d(), engine->newString(QString(0xfffe))); } } diff --git a/src/qml/jsruntime/qv4mm.cpp b/src/qml/jsruntime/qv4mm.cpp index d5576b400a..64491e1376 100644 --- a/src/qml/jsruntime/qv4mm.cpp +++ b/src/qml/jsruntime/qv4mm.cpp @@ -95,6 +95,8 @@ struct MemoryManager::Data uint maxShift; std::size_t maxChunkSize; QVector heapChunks; + std::size_t unmanagedHeapSize; // the amount of bytes of heap that is not managed by the memory manager, but which is held onto by managed items. + std::size_t unmanagedHeapSizeGCLimit; struct LargeItem { LargeItem *next; @@ -123,6 +125,8 @@ struct MemoryManager::Data , totalAlloc(0) , maxShift(6) , maxChunkSize(32*1024) + , unmanagedHeapSize(0) + , unmanagedHeapSizeGCLimit(64 * 1024) , largeItems(0) , totalLargeItemsAllocated(0) , deletable(0) @@ -157,8 +161,10 @@ struct MemoryManager::Data namespace { -bool sweepChunk(MemoryManager::Data::ChunkHeader *header, uint *itemsInUse, ExecutionEngine *engine) +bool sweepChunk(MemoryManager::Data::ChunkHeader *header, uint *itemsInUse, ExecutionEngine *engine, std::size_t *unmanagedHeapSize) { + Q_ASSERT(unmanagedHeapSize); + bool isEmpty = true; Heap::Base *tail = &header->freeItems; // qDebug("chunkStart @ %p, size=%x, pos=%x", header->itemStart, header->itemSize, header->itemSize>>4); @@ -167,8 +173,8 @@ bool sweepChunk(MemoryManager::Data::ChunkHeader *header, uint *itemsInUse, Exec #endif for (char *item = header->itemStart; item <= header->itemEnd; item += header->itemSize) { Heap::Base *m = reinterpret_cast(item); -// qDebug("chunk @ %p, size = %lu, in use: %s, mark bit: %s", -// item, m->size, (m->inUse ? "yes" : "no"), (m->markBit ? "true" : "false")); +// qDebug("chunk @ %p, in use: %s, mark bit: %s", +// item, (m->inUse() ? "yes" : "no"), (m->isMarked() ? "true" : "false")); Q_ASSERT((qintptr) item % 16 == 0); @@ -183,6 +189,13 @@ bool sweepChunk(MemoryManager::Data::ChunkHeader *header, uint *itemsInUse, Exec #ifdef V4_USE_VALGRIND VALGRIND_ENABLE_ERROR_REPORTING; #endif + if (std::size_t(header->itemSize) == MemoryManager::align(sizeof(Heap::String)) && m->gcGetVtable()->isString) { + std::size_t heapBytes = static_cast(m)->retainedTextSize(); + Q_ASSERT(*unmanagedHeapSize >= heapBytes); +// qDebug() << "-- it's a string holding on to" << heapBytes << "bytes"; + *unmanagedHeapSize -= heapBytes; + } + if (m->gcGetVtable()->destroy) m->gcGetVtable()->destroy(m); @@ -219,7 +232,7 @@ MemoryManager::MemoryManager(ExecutionEngine *engine) m_d->engine = engine; } -Heap::Base *MemoryManager::allocData(std::size_t size) +Heap::Base *MemoryManager::allocData(std::size_t size, std::size_t unmanagedSize) { if (m_d->aggressiveGC) runGC(); @@ -230,11 +243,27 @@ Heap::Base *MemoryManager::allocData(std::size_t size) Q_ASSERT(size >= 16); Q_ASSERT(size % 16 == 0); +// qDebug() << "unmanagedHeapSize:" << m_d->unmanagedHeapSize << "limit:" << m_d->unmanagedHeapSizeGCLimit << "unmanagedSize:" << unmanagedSize; + m_d->unmanagedHeapSize += unmanagedSize; + bool didGCRun = false; + if (m_d->unmanagedHeapSize > m_d->unmanagedHeapSizeGCLimit) { + runGC(); + + if (m_d->unmanagedHeapSizeGCLimit <= m_d->unmanagedHeapSize) + m_d->unmanagedHeapSizeGCLimit = std::max(m_d->unmanagedHeapSizeGCLimit, m_d->unmanagedHeapSize) * 2; + else if (m_d->unmanagedHeapSize * 4 <= m_d->unmanagedHeapSizeGCLimit) + m_d->unmanagedHeapSizeGCLimit /= 2; + else if (m_d->unmanagedHeapSizeGCLimit - m_d->unmanagedHeapSize < 5 * unmanagedSize) + // try preventing running the GC all the time when we're just below the threshold limit and manage to collect just enough to do this one allocation + m_d->unmanagedHeapSizeGCLimit += std::max(std::size_t(8 * 1024), 5 * unmanagedSize); + didGCRun = true; + } + size_t pos = size >> 4; // doesn't fit into a small bucket if (size >= MemoryManager::Data::MaxItemSize) { - if (m_d->totalLargeItemsAllocated > 8 * 1024 * 1024) + if (!didGCRun && m_d->totalLargeItemsAllocated > 8 * 1024 * 1024) runGC(); // we use malloc for this @@ -257,7 +286,7 @@ Heap::Base *MemoryManager::allocData(std::size_t size) } // try to free up space, otherwise allocate - if (m_d->allocCount[pos] > (m_d->availableItems[pos] >> 1) && m_d->totalAlloc > (m_d->totalItems >> 1) && !m_d->aggressiveGC) { + if (!didGCRun && m_d->allocCount[pos] > (m_d->availableItems[pos] >> 1) && m_d->totalAlloc > (m_d->totalItems >> 1) && !m_d->aggressiveGC) { runGC(); header = m_d->nonFullChunks[pos]; if (header) { @@ -404,7 +433,7 @@ void MemoryManager::sweep(bool lastSweep) for (int i = 0; i < m_d->heapChunks.size(); ++i) { Data::ChunkHeader *header = reinterpret_cast(m_d->heapChunks[i].base()); - chunkIsEmpty[i] = sweepChunk(header, &itemsInUse[header->itemSize >> 4], m_d->engine); + chunkIsEmpty[i] = sweepChunk(header, &itemsInUse[header->itemSize >> 4], m_d->engine, &m_d->unmanagedHeapSize); } QVector::iterator chunkIter = m_d->heapChunks.begin(); @@ -553,6 +582,11 @@ size_t MemoryManager::getLargeItemsMem() const return total; } +void MemoryManager::growUnmanagedHeapSizeUsage(size_t delta) +{ + m_d->unmanagedHeapSize += delta; +} + MemoryManager::~MemoryManager() { delete m_persistentValues; diff --git a/src/qml/jsruntime/qv4mm_p.h b/src/qml/jsruntime/qv4mm_p.h index 00b41b796a..7f6d2edba3 100644 --- a/src/qml/jsruntime/qv4mm_p.h +++ b/src/qml/jsruntime/qv4mm_p.h @@ -83,10 +83,10 @@ public: { return (size + 15) & ~0xf; } template - inline typename ManagedType::Data *allocManaged(std::size_t size) + inline typename ManagedType::Data *allocManaged(std::size_t size, std::size_t unmanagedSize = 0) { size = align(size); - Heap::Base *o = allocData(size); + Heap::Base *o = allocData(size, unmanagedSize); o->vtable = ManagedType::staticVTable(); return static_cast(o); } @@ -109,6 +109,15 @@ public: return t->d(); } + template + typename ManagedType::Data *allocWithStringData(std::size_t unmanagedSize, Arg1 arg1) + { + Scope scope(engine()); + Scoped t(scope, allocManaged(sizeof(typename ManagedType::Data), unmanagedSize)); + (void)new (t->d()) typename ManagedType::Data(this, arg1); + return t->d(); + } + template typename ManagedType::Data *alloc(Arg1 arg1, Arg2 arg2) { @@ -159,10 +168,12 @@ public: size_t getAllocatedMem() const; size_t getLargeItemsMem() const; + void growUnmanagedHeapSizeUsage(size_t delta); // called when a JS object grows itself. Specifically: Heap::String::append + protected: /// expects size to be aligned // TODO: try to inline - Heap::Base *allocData(std::size_t size); + Heap::Base *allocData(std::size_t size, std::size_t unmanagedSize); #ifdef DETAILED_MM_STATS void willAllocate(std::size_t size); diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index c31de6a9f0..b66e917b87 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -521,7 +521,8 @@ QV4::ReturnedValue RuntimeHelpers::addHelper(ExecutionEngine *engine, const Valu return pright->asReturnedValue(); if (!pright->stringValue()->d()->length()) return pleft->asReturnedValue(); - return (engine->memoryManager->alloc(pleft->stringValue()->d(), pright->stringValue()->d()))->asReturnedValue(); + MemoryManager *mm = engine->memoryManager; + return (mm->alloc(mm, pleft->stringValue()->d(), pright->stringValue()->d()))->asReturnedValue(); } double x = RuntimeHelpers::toNumber(pleft); double y = RuntimeHelpers::toNumber(pright); @@ -537,7 +538,8 @@ QV4::ReturnedValue Runtime::addString(ExecutionEngine *engine, const Value &left return right.asReturnedValue(); if (!right.stringValue()->d()->length()) return left.asReturnedValue(); - return (engine->memoryManager->alloc(left.stringValue()->d(), right.stringValue()->d()))->asReturnedValue(); + MemoryManager *mm = engine->memoryManager; + return (mm->alloc(mm, left.stringValue()->d(), right.stringValue()->d()))->asReturnedValue(); } Scope scope(engine); @@ -554,7 +556,8 @@ QV4::ReturnedValue Runtime::addString(ExecutionEngine *engine, const Value &left return pright->asReturnedValue(); if (!pright->stringValue()->d()->length()) return pleft->asReturnedValue(); - return (engine->memoryManager->alloc(pleft->stringValue()->d(), pright->stringValue()->d()))->asReturnedValue(); + MemoryManager *mm = engine->memoryManager; + return (mm->alloc(mm, pleft->stringValue()->d(), pright->stringValue()->d()))->asReturnedValue(); } void Runtime::setProperty(ExecutionEngine *engine, const Value &object, int nameIndex, const Value &value) diff --git a/src/qml/jsruntime/qv4string.cpp b/src/qml/jsruntime/qv4string.cpp index 20dd84420c..6d55eb2c18 100644 --- a/src/qml/jsruntime/qv4string.cpp +++ b/src/qml/jsruntime/qv4string.cpp @@ -117,7 +117,8 @@ bool String::isEqualTo(Managed *t, Managed *o) } -Heap::String::String(const QString &t) +Heap::String::String(MemoryManager *mm, const QString &t) + : mm(mm) { subtype = String::StringType_Unknown; @@ -129,7 +130,8 @@ Heap::String::String(const QString &t) len = text->size; } -Heap::String::String(String *l, String *r) +Heap::String::String(MemoryManager *mm, String *l, String *r) + : mm(mm) { subtype = String::StringType_Unknown; @@ -187,6 +189,7 @@ void Heap::String::simplifyString() const text->ref.ref(); identifier = 0; largestSubLength = 0; + mm->growUnmanagedHeapSizeUsage(size_t(text->size) * sizeof(QChar)); } void Heap::String::createHashValue() const diff --git a/src/qml/jsruntime/qv4string_p.h b/src/qml/jsruntime/qv4string_p.h index 5a0c83b4b9..1cf8f51a29 100644 --- a/src/qml/jsruntime/qv4string_p.h +++ b/src/qml/jsruntime/qv4string_p.h @@ -53,8 +53,8 @@ struct Q_QML_PRIVATE_EXPORT String : Base { StringType_ArrayIndex }; - String(const QString &text); - String(String *l, String *n); + String(MemoryManager *mm, const QString &text); + String(MemoryManager *mm, String *l, String *n); ~String() { if (!largestSubLength && !text->ref.deref()) QStringData::deallocate(text); @@ -66,6 +66,9 @@ struct Q_QML_PRIVATE_EXPORT String : Base { len == (uint)text->size); return len; } + std::size_t retainedTextSize() const { + return largestSubLength ? 0 : (std::size_t(text->size) * sizeof(QChar)); + } void createHashValue() const; inline unsigned hashValue() const { if (subtype == StringType_Unknown) @@ -107,6 +110,7 @@ struct Q_QML_PRIVATE_EXPORT String : Base { mutable uint stringHash; mutable uint largestSubLength; uint len; + MemoryManager *mm; private: static void append(const String *data, QChar *ch); }; -- cgit v1.2.3 From 34f9b8d322f74793221029ef8a6e1053f2a0d2ae Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Fri, 10 Jul 2015 14:30:05 +0200 Subject: Fix QML/JS debugging. Converting from any ScopedObject to Object* resulted in the same pointer value. Prevent this by not using either, but instead use the QV4::Value directly. Task-number: QTBUG-47061 Change-Id: I98d3889f5504dbd5962099d30d4af9d57bc518f9 Reviewed-by: Ulf Hermann --- src/qml/debugger/qv4debugservice.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/qml/debugger/qv4debugservice.cpp b/src/qml/debugger/qv4debugservice.cpp index 32b7b38285..cefb29e031 100644 --- a/src/qml/debugger/qv4debugservice.cpp +++ b/src/qml/debugger/qv4debugservice.cpp @@ -330,14 +330,14 @@ private: refsToInclude.append(value); } - void cacheObjectRef(QV4::Object *obj, int ref) + void cacheObjectRef(QV4::Value obj, int ref) { - objectRefs.insert(obj, ref); + objectRefs.insert(obj.val, ref); } - int cachedObjectRef(QV4::Object *obj) const + int cachedObjectRef(QV4::Value obj) const { - return objectRefs.value(obj, -1); + return objectRefs.value(obj.val, -1); } private: @@ -347,7 +347,7 @@ private: QJsonArray *destination; QSet usedRefs; QHash > refsByHandle; - QHash objectRefs; + QHash objectRefs; }; class QV4DebugServicePrivate : public QQmlConfigurableDebugServicePrivate -- cgit v1.2.3 From 6a21d5e36771bdd3e8b5915402e5cbe663469aba Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Wed, 15 Jul 2015 10:24:53 +0300 Subject: Test if the state machine reacts to a QObject signal. Change-Id: I4987e10ac0b31977249ce9ebe00e26de334db30d Reviewed-by: Simon Hausmann --- tests/auto/qml/qml.pro | 3 +- tests/auto/qml/qqmlstatemachine/data/cppsignal.qml | 70 ++++++++++++ .../auto/qml/qqmlstatemachine/qqmlstatemachine.pro | 11 ++ .../qml/qqmlstatemachine/tst_qqmlstatemachine.cpp | 118 +++++++++++++++++++++ 4 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 tests/auto/qml/qqmlstatemachine/data/cppsignal.qml create mode 100644 tests/auto/qml/qqmlstatemachine/qqmlstatemachine.pro create mode 100644 tests/auto/qml/qqmlstatemachine/tst_qqmlstatemachine.cpp diff --git a/tests/auto/qml/qml.pro b/tests/auto/qml/qml.pro index a5c3211f0d..430a90b800 100644 --- a/tests/auto/qml/qml.pro +++ b/tests/auto/qml/qml.pro @@ -25,7 +25,8 @@ PUBLICTESTS += \ qtqmlmodules \ qquickfolderlistmodel \ qqmlapplicationengine \ - qqmlsettings + qqmlsettings \ + qqmlstatemachine PRIVATETESTS += \ animation \ diff --git a/tests/auto/qml/qqmlstatemachine/data/cppsignal.qml b/tests/auto/qml/qqmlstatemachine/data/cppsignal.qml new file mode 100644 index 0000000000..3d06d823e2 --- /dev/null +++ b/tests/auto/qml/qqmlstatemachine/data/cppsignal.qml @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Ford Motor Company +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** 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 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQml 2.0 + +import QtQml.StateMachine 1.0 + +import CppObjectEnum 1.0 + +StateMachine { + id: stateMachine + initialState: state0 + + State { + id: state0 + SignalTransition { + targetState: state1 + signal: _cppObject.mySignal + // signalState is mySignal's parameter + guard: signalState === CppObject.State1 + } + } + + State { + id: state1 + SignalTransition { + targetState: state2 + signal: _cppObject.mySignal + // signalState is mySignal's parameter + guard: signalState === CppObject.State2 + } + onEntered: _cppObject.objectState = CppObject.State1 + } + + FinalState { + id: state2 + onEntered: _cppObject.objectState = CppObject.State2 + } + Component.onCompleted: stateMachine.running = true +} diff --git a/tests/auto/qml/qqmlstatemachine/qqmlstatemachine.pro b/tests/auto/qml/qqmlstatemachine/qqmlstatemachine.pro new file mode 100644 index 0000000000..002af1d707 --- /dev/null +++ b/tests/auto/qml/qqmlstatemachine/qqmlstatemachine.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qqmlstatemachine +osx:CONFIG -= app_bundle + +SOURCES += tst_qqmlstatemachine.cpp + +include (../../shared/util.pri) + +CONFIG += parallel_test +QT += core-private gui-private qml-private quick-private gui testlib +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/qml/qqmlstatemachine/tst_qqmlstatemachine.cpp b/tests/auto/qml/qqmlstatemachine/tst_qqmlstatemachine.cpp new file mode 100644 index 0000000000..0d36b66e3f --- /dev/null +++ b/tests/auto/qml/qqmlstatemachine/tst_qqmlstatemachine.cpp @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Ford Motor Company +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** 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 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include +#include "../../shared/util.h" + +class tst_qqmlstatemachine : public QQmlDataTest +{ + Q_OBJECT +public: + tst_qqmlstatemachine(); + +private slots: + void tst_cppObjectSignal(); +}; + + +class CppObject : public QObject +{ + Q_OBJECT + Q_PROPERTY(ObjectState objectState READ objectState WRITE setObjectState NOTIFY objectStateChanged) + Q_ENUMS(ObjectState) +public: + enum ObjectState { + State0, + State1, + State2 + }; + +public: + CppObject() + : QObject() + , m_objectState(State0) + {} + + ObjectState objectState() const { return m_objectState; } + void setObjectState(ObjectState objectState) { m_objectState = objectState; emit objectStateChanged();} + +signals: + void objectStateChanged(); + void mySignal(int signalState); + +private: + ObjectState m_objectState; +}; + +tst_qqmlstatemachine::tst_qqmlstatemachine() +{ + QVERIFY(-1 != qmlRegisterUncreatableType("CppObjectEnum", 1, 0, "CppObject", QString())); +} + +void tst_qqmlstatemachine::tst_cppObjectSignal() +{ + CppObject cppObject; + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("cppsignal.qml")); + QVERIFY(!component.isError()); + + QQmlContext *ctxt = engine.rootContext(); + ctxt->setContextProperty("_cppObject", &cppObject); + QScopedPointer rootObject(component.create()); + QVERIFY(rootObject != 0); + + // wait for state machine to start + QTRY_VERIFY(rootObject->property("running").toBool()); + + // emit signal from cpp + emit cppObject.mySignal(CppObject::State1); + + // check if the signal was propagated + QTRY_COMPARE(cppObject.objectState(), CppObject::State1); + + // emit signal from cpp + emit cppObject.mySignal(CppObject::State2); + + // check if the signal was propagated + QTRY_COMPARE(cppObject.objectState(), CppObject::State2); + + // wait for state machine to finish + QTRY_VERIFY(!rootObject->property("running").toBool()); +} + + +QTEST_MAIN(tst_qqmlstatemachine) + +#include "tst_qqmlstatemachine.moc" -- cgit v1.2.3 From a169d310e4ecf54ce3577ae46cfc45eb9d308a13 Mon Sep 17 00:00:00 2001 From: Nico Vertriest Date: Wed, 15 Jul 2015 15:04:20 +0200 Subject: Doc: replace Mac OS X with OS X Task-number: QTBUG-40759 Change-Id: If21b4551eb95af3370cc21edd7a6721fc06e1346 Reviewed-by: Martin Smith --- src/particles/qquickimageparticle.cpp | 2 +- src/qml/qml/qqmlimport.cpp | 2 +- src/quick/items/qquickevents.cpp | 2 +- src/quick/items/qquicktextcontrol.cpp | 2 +- src/quick/items/qquicktextinput.cpp | 2 +- .../auto/quick/qquickanimationcontroller/data/tst_parallelanimation.qml | 2 +- tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/particles/qquickimageparticle.cpp b/src/particles/qquickimageparticle.cpp index c0e1b4e422..7df3299325 100644 --- a/src/particles/qquickimageparticle.cpp +++ b/src/particles/qquickimageparticle.cpp @@ -1271,7 +1271,7 @@ void QQuickImageParticle::finishBuildParticleNodes(QSGNode** node) #endif #ifdef Q_OS_MAC - // Mac OS X 10.8.3 introduced a bug in the AMD drivers, for at least the 2011 macbook pros, + // OS X 10.8.3 introduced a bug in the AMD drivers, for at least the 2011 macbook pros, // causing point sprites who read gl_PointCoord in the frag shader to come out as // green-red blobs. if (perfLevel < Deformable && strstr((char *) glGetString(GL_VENDOR), "ATI")) { diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp index 5a54609e12..ff48a10d95 100644 --- a/src/qml/qml/qqmlimport.cpp +++ b/src/qml/qml/qqmlimport.cpp @@ -1641,7 +1641,7 @@ QString QQmlImportDatabase::resolvePlugin(QQmlTypeLoader *typeLoader, \row \li Unix/Linux \li \c .so \row \li AIX \li \c .a \row \li HP-UX \li \c .sl, \c .so (HP-UXi) - \row \li Mac OS X \li \c .dylib, \c .bundle, \c .so + \row \li OS X \li \c .dylib, \c .bundle, \c .so \endtable Version number on unix are ignored. diff --git a/src/quick/items/qquickevents.cpp b/src/quick/items/qquickevents.cpp index 3ce4a8cb49..1380452718 100644 --- a/src/quick/items/qquickevents.cpp +++ b/src/quick/items/qquickevents.cpp @@ -323,7 +323,7 @@ Item { \qmlproperty point QtQuick::WheelEvent::pixelDelta This property holds the delta in screen pixels and is available in plataforms that - have high-resolution trackpads, such as Mac OS X. + have high-resolution trackpads, such as OS X. The x and y cordinate of this property holds the delta in horizontal and vertical orientation. The value should be used directly to scroll content on screen. diff --git a/src/quick/items/qquicktextcontrol.cpp b/src/quick/items/qquicktextcontrol.cpp index 95d2e7c995..6929bb44a2 100644 --- a/src/quick/items/qquicktextcontrol.cpp +++ b/src/quick/items/qquicktextcontrol.cpp @@ -225,7 +225,7 @@ bool QQuickTextControlPrivate::cursorMoveKeyEvent(QKeyEvent *e) return false; } -// Except for pageup and pagedown, Mac OS X has very different behavior, we don't do it all, but +// Except for pageup and pagedown, OS X has very different behavior, we don't do it all, but // here's the breakdown: // Shift still works as an anchor, but only one of the other keys can be down Ctrl (Command), // Alt (Option), or Meta (Control). diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index a4c61209f2..5c67d914a5 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -78,7 +78,7 @@ DEFINE_BOOL_CONFIG_OPTION(qmlDisableDistanceField, QML_DISABLE_DISTANCEFIELD) and setting \l echoMode to an appropriate value enables TextInput to be used for a password input field. - On Mac OS X, the Up/Down key bindings for Home/End are explicitly disabled. + On OS X, the Up/Down key bindings for Home/End are explicitly disabled. If you want such bindings (on any platform), you will need to construct them in QML. \sa TextEdit, Text diff --git a/tests/auto/quick/qquickanimationcontroller/data/tst_parallelanimation.qml b/tests/auto/quick/qquickanimationcontroller/data/tst_parallelanimation.qml index 87cba880af..cd0f95bc7a 100644 --- a/tests/auto/quick/qquickanimationcontroller/data/tst_parallelanimation.qml +++ b/tests/auto/quick/qquickanimationcontroller/data/tst_parallelanimation.qml @@ -24,7 +24,7 @@ Rectangle { name:"AnimationController" when:windowShown function test_parallelAnimation_data() { - //FIXME:the commented lines fail on MAC OS X + //FIXME:the commented lines fail on OS X return [ {tag:"0.1",progress:0.1, x:5, y:10, color:"#e50019", width:14, height:14}, //{tag:"0.2",progress:0.2, x:10, y:20, color:"#cb0033", width:18, height:18}, diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index 88cac92864..d87054ac9e 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -2417,7 +2417,7 @@ void tst_qquicktextinput::navigation() simulateKey(&window, Qt::Key_Left); QVERIFY(input->hasActiveFocus() == true); - // Up and Down should NOT do Home/End, even on Mac OS X (QTBUG-10438). + // Up and Down should NOT do Home/End, even on OS X (QTBUG-10438). input->setCursorPosition(2); QCOMPARE(input->cursorPosition(),2); simulateKey(&window, Qt::Key_Up); -- cgit v1.2.3 From 2d8bf9eed72cff041a235160fe14a7f424475610 Mon Sep 17 00:00:00 2001 From: Nobuaki Sukegawa Date: Tue, 14 Jul 2015 01:04:20 +0900 Subject: Fix trivial bug where ArrayBuffer.isView never returned false Change-Id: I168d2ec54997d057e3d32463c2b153df38073838 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4arraybuffer.cpp | 2 +- tests/manual/v4/typedarrays.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/qml/jsruntime/qv4arraybuffer.cpp b/src/qml/jsruntime/qv4arraybuffer.cpp index 11664f1194..dc65b5d21a 100644 --- a/src/qml/jsruntime/qv4arraybuffer.cpp +++ b/src/qml/jsruntime/qv4arraybuffer.cpp @@ -78,7 +78,7 @@ ReturnedValue ArrayBufferCtor::method_isView(CallContext *ctx) QV4::Scoped v(scope, ctx->argument(0)); if (!!v) return Encode(true); - return Encode(true); + return Encode(false); } diff --git a/tests/manual/v4/typedarrays.js b/tests/manual/v4/typedarrays.js index d7a863e573..d52fd6bab0 100644 --- a/tests/manual/v4/typedarrays.js +++ b/tests/manual/v4/typedarrays.js @@ -67,6 +67,15 @@ function assertArrayEquals(a, b) assertEquals(a[i], b[i]) } +function TestIsViewFalse() { + assertTrue(!ArrayBuffer.isView()); + assertTrue(!ArrayBuffer.isView(42)); + assertTrue(!ArrayBuffer.isView('foo')); + assertTrue(!ArrayBuffer.isView(new ArrayBuffer())); +} + +TestIsViewFalse(); + function TestByteLength(param, expectedByteLength) { var ab = new ArrayBuffer(param); assertSame(expectedByteLength, ab.byteLength); -- cgit v1.2.3 From e1141c858c397d2c27e4a6681b9300f65cf396f2 Mon Sep 17 00:00:00 2001 From: Topi Reinio Date: Wed, 15 Jul 2015 12:18:57 +0200 Subject: StocQt demo: Fix text layout issues The precision of the data received from the stock feed has changed, and so we must round it before assigning to Text objects to avoid overflow. This change also rearranges the layout of the StockInfo element, using Flow and proper word wrap and eliding for long company names to improve the look of the stock info view on narrow screens. Change-Id: I53aaefd1cdc984fcceae9874e5ca2f66b47a190d Task-number: QTBUG-47207 Reviewed-by: Venugopal Shivashankar --- examples/quick/demos/stocqt/content/StockInfo.qml | 126 ++++++++++----------- .../quick/demos/stocqt/content/StockListView.qml | 4 +- 2 files changed, 65 insertions(+), 65 deletions(-) diff --git a/examples/quick/demos/stocqt/content/StockInfo.qml b/examples/quick/demos/stocqt/content/StockInfo.qml index 337cc79f70..50f6b9107e 100644 --- a/examples/quick/demos/stocqt/content/StockInfo.qml +++ b/examples/quick/demos/stocqt/content/StockInfo.qml @@ -48,72 +48,72 @@ Rectangle { property var stock: null - Text { - id: stockIdText - anchors.left: parent.left - anchors.leftMargin: 5 - anchors.top: parent.top - anchors.topMargin: 15 - color: "#000000" - font.family: "Open Sans" - font.pointSize: 38 - font.weight: Font.DemiBold - text: root.stock.stockId - } + Column { + id: stockColumn + anchors.fill: parent + spacing: 4 - Text { - id: stockNameText - anchors.left: parent.left - anchors.leftMargin: 5 - anchors.bottom: priceChangePercentage.bottom - anchors.right: priceChangePercentage.left - anchors.rightMargin: 15 - color: "#000000" - font.family: "Open Sans" - font.pointSize: 16 - elide: Text.ElideRight - text: root.stock.stockName - } + Flow { + anchors { left: parent.left; right: parent.right } + spacing: 12 - Text { - id: price - anchors.right: parent.right - anchors.rightMargin: 5 - anchors.top: parent.top - anchors.topMargin: 15 - horizontalAlignment: Text.AlignRight - color: "#000000" - font.family: "Open Sans" - font.pointSize: 30 - font.weight: Font.DemiBold - text: root.stock.stockPrice - } + Text { + id: stockIdText + color: "#000000" + font.family: "Open Sans" + font.pointSize: 28 + font.weight: Font.DemiBold + text: root.stock.stockId + } - Text { - id: priceChange - anchors.right: parent.right - anchors.rightMargin: 20 - anchors.top: price.bottom - anchors.topMargin: 5 - horizontalAlignment: Text.AlignRight - color: root.stock.stockPriceChanged < 0 ? "#d40000" : "#328930" - font.family: "Open Sans" - font.pointSize: 20 - font.weight: Font.Bold - text: root.stock.stockPriceChanged - } + Text { + id: price + color: "#6d6d6d" + font.family: "Open Sans" + font.pointSize: 28 + font.weight: Font.DemiBold + text: parseFloat(Math.round(root.stock.stockPrice * 100) / 100).toFixed(2); + } + } + + Text { + id: stockNameText + color: "#0c0c0c" + font.family: "Open Sans" + font.pointSize: 16 + width: stockColumn.width + elide: Text.ElideRight + maximumLineCount: 3 + wrapMode: Text.WordWrap + text: root.stock.stockName + } + + Flow { + anchors { left: parent.left; right: parent.right } + spacing: 12 + + Text { + id: priceChange + horizontalAlignment: Text.AlignRight + color: root.stock.stockPriceChanged < 0 ? "#d40000" : "#328930" + font.family: "Open Sans" + font.pointSize: 18 + text: parseFloat(Math.round(root.stock.stockPriceChanged * 100) / 100).toFixed(2); + } - Text { - id: priceChangePercentage - anchors.right: parent.right - anchors.rightMargin: 20 - anchors.top: priceChange.bottom - anchors.topMargin: 5 - horizontalAlignment: Text.AlignRight - color: root.stock.stockPriceChanged < 0 ? "#d40000" : "#328930" - font.family: "Open Sans" - font.pointSize: 18 - font.weight: Font.Bold - text: Math.abs(Math.round(root.stock.stockPriceChanged/(root.stock.stockPrice - root.stock.stockPriceChanged) * 100))/100 +"%" + Text { + id: priceChangePercentage + horizontalAlignment: Text.AlignRight + color: root.stock.stockPriceChanged < 0 ? "#d40000" : "#328930" + font.family: "Open Sans" + font.pointSize: 18 + font.weight: Font.DemiBold + text: "(" + + Math.abs(Math.round( + root.stock.stockPriceChanged / + (root.stock.stockPrice - root.stock.stockPriceChanged) * 100)) / 100 + + "%)" + } + } } } diff --git a/examples/quick/demos/stocqt/content/StockListView.qml b/examples/quick/demos/stocqt/content/StockListView.qml index 53e345db59..470531a21e 100644 --- a/examples/quick/demos/stocqt/content/StockListView.qml +++ b/examples/quick/demos/stocqt/content/StockListView.qml @@ -96,9 +96,9 @@ Rectangle { var records = xhr.responseText.split('\n'); if (records.length > 0) { var r = records[1].split(','); - model.setProperty(index, "value", r[4]); - var today = parseFloat(r[4]); + model.setProperty(index, "value", today.toFixed(2)); + r = records[2].split(','); var yesterday = parseFloat(r[4]); var change = today - yesterday; -- cgit v1.2.3 From 71c357e416c37c7b7d7cd2efa95635018bd105f5 Mon Sep 17 00:00:00 2001 From: Sune Vuorela Date: Thu, 16 Jul 2015 20:36:31 +0200 Subject: Let unit tests pass if xmlpatterns is not around The blacklist for xmlpatterns tests is not applied unless xmlpatterns specifically has been disabled, but code builds anyways. Fix up the blacklist. Change-Id: I013701e787e8ec28f1282a911270dd7a158d6f01 Reviewed-by: Simon Hausmann --- tests/auto/quick/examples/examples.pro | 2 ++ tests/auto/quick/examples/tst_examples.cpp | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/auto/quick/examples/examples.pro b/tests/auto/quick/examples/examples.pro index 6543aa1b2b..3d821fc13d 100644 --- a/tests/auto/quick/examples/examples.pro +++ b/tests/auto/quick/examples/examples.pro @@ -10,3 +10,5 @@ CONFIG += parallel_test #temporary QT += core-private gui-private qml-private quick-private testlib DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 +!qtHaveModule(xmlpatterns): DEFINES += QT_NO_XMLPATTERNS + diff --git a/tests/auto/quick/examples/tst_examples.cpp b/tests/auto/quick/examples/tst_examples.cpp index 175955d663..90c78ec942 100644 --- a/tests/auto/quick/examples/tst_examples.cpp +++ b/tests/auto/quick/examples/tst_examples.cpp @@ -104,7 +104,9 @@ tst_examples::tst_examples() excludedDirs << "demos/twitter"; excludedDirs << "demos/flickr"; excludedDirs << "demos/photoviewer"; - excludedDirs << "snippets/qml/xmlrole.qml"; + excludedFiles << "snippets/qml/xmlrole.qml"; + excludedFiles << "particles/itemparticle/particleview.qml"; + excludedFiles << "views/visualdatamodel/slideshow.qml"; #endif } -- cgit v1.2.3 From 7da45b21b76965e021e8a049715b1dee34081f7c Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 6 Jul 2015 12:11:19 +0200 Subject: Fix warning about returning address of local variable by MSVC2015 in qv4engine.cpp. qtdeclarative\src\qml\jsruntime\qv4engine.cpp(179) : warning C4172: returning address of local variable or temporary: dummy Disable warning as using the address is intended. Change-Id: Ide894a8dc2fb94f11d0455723c46567c84d91f8d Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4engine.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 0f2b44fac6..e1282eeca9 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -108,6 +108,9 @@ static ReturnedValue throwTypeError(CallContext *ctx) const int MinimumStackSize = 256; // in kbytes +QT_WARNING_PUSH +QT_WARNING_DISABLE_MSVC(4172) // MSVC 2015: warning C4172: returning address of local variable or temporary: dummy + quintptr getStackLimit() { quintptr stackLimit; @@ -172,6 +175,7 @@ quintptr getStackLimit() int dummy; // this is inexact, as part of the stack is used when being called here, // but let's simply default to 1MB from where the stack is right now + // (Note: triggers warning C4172 as of MSVC 2015, returning address of local variable) stackLimit = reinterpret_cast(&dummy) - 1024*1024; #endif @@ -179,6 +183,7 @@ quintptr getStackLimit() return stackLimit + MinimumStackSize*1024; } +QT_WARNING_POP QJSEngine *ExecutionEngine::jsEngine() const { -- cgit v1.2.3 From 74e2ed4841ac35c9af806eeb0555d492ffc82cb8 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sat, 18 Jul 2015 21:33:33 -0700 Subject: Consistently use the override keyword Clang doesn't like when it's inconsistent. Change-Id: Ib306f8f647014b399b87ffff13f23eebda07757b Reviewed-by: Simon Hausmann --- src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp | 8 ++++---- src/quick/items/qquickdrag.cpp | 2 +- src/quick/items/qquickgridview.cpp | 8 ++++---- src/quick/items/qquickimage_p.h | 2 +- src/quick/items/qquickitemview_p_p.h | 2 +- src/quick/items/qquicklistview.cpp | 8 ++++---- src/quick/items/qquickwindow.cpp | 2 +- src/quick/util/qquickanimatorjob_p.h | 8 ++++---- src/quickwidgets/qquickwidget_p.h | 4 ++-- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp b/src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp index 782d03f9f9..4a2c137aa1 100644 --- a/src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp +++ b/src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp @@ -92,7 +92,7 @@ namespace { { } - void paint(QPainter *p) const { p->fillRect(m_rect, m_brush); } + void paint(QPainter *p) const Q_DECL_OVERRIDE { p->fillRect(m_rect, m_brush); } QRectF boundingRect() const Q_DECL_OVERRIDE { return m_rect; } private: @@ -109,7 +109,7 @@ namespace { { } - void paint(QPainter *p) const { p->fillPath(m_path, m_brush); } + void paint(QPainter *p) const Q_DECL_OVERRIDE { p->fillPath(m_path, m_brush); } QRectF boundingRect() const Q_DECL_OVERRIDE { return m_path.boundingRect(); } private: @@ -126,7 +126,7 @@ namespace { { } - void paint(QPainter *p) const { p->strokePath(m_path, m_pen); } + void paint(QPainter *p) const Q_DECL_OVERRIDE { p->strokePath(m_path, m_pen); } QRectF boundingRect() const Q_DECL_OVERRIDE { @@ -148,7 +148,7 @@ namespace { { } - void paint(QPainter *p) const { p->drawImage(m_offset, m_image); } + void paint(QPainter *p) const Q_DECL_OVERRIDE { p->drawImage(m_offset, m_image); } QRectF boundingRect() const Q_DECL_OVERRIDE { return QRectF(m_image.rect()).translated(m_offset); } diff --git a/src/quick/items/qquickdrag.cpp b/src/quick/items/qquickdrag.cpp index 4d46485718..2612b855bd 100644 --- a/src/quick/items/qquickdrag.cpp +++ b/src/quick/items/qquickdrag.cpp @@ -75,7 +75,7 @@ public: } void itemGeometryChanged(QQuickItem *, const QRectF &, const QRectF &) Q_DECL_OVERRIDE; - void itemParentChanged(QQuickItem *, QQuickItem *parent); + void itemParentChanged(QQuickItem *, QQuickItem *parent) Q_DECL_OVERRIDE; void updatePosition(); void restartDrag(); void deliverEnterEvent(); diff --git a/src/quick/items/qquickgridview.cpp b/src/quick/items/qquickgridview.cpp index 3cc0a28b87..99c77488f4 100644 --- a/src/quick/items/qquickgridview.cpp +++ b/src/quick/items/qquickgridview.cpp @@ -60,19 +60,19 @@ public: { } - qreal position() const { + qreal position() const Q_DECL_OVERRIDE { return rowPos(); } - qreal endPosition() const { + qreal endPosition() const Q_DECL_OVERRIDE { return endRowPos(); } - qreal size() const { + qreal size() const Q_DECL_OVERRIDE { return view->flow() == QQuickGridView::FlowLeftToRight ? view->cellHeight() : view->cellWidth(); } - qreal sectionSize() const { + qreal sectionSize() const Q_DECL_OVERRIDE { return 0.0; } diff --git a/src/quick/items/qquickimage_p.h b/src/quick/items/qquickimage_p.h index 8edf153ca3..be514ae2f5 100644 --- a/src/quick/items/qquickimage_p.h +++ b/src/quick/items/qquickimage_p.h @@ -88,7 +88,7 @@ public: bool mipmap() const; void setMipmap(bool use); - virtual void emitAutoTransformBaseChanged() { emit autoTransformChanged(); } + virtual void emitAutoTransformBaseChanged() Q_DECL_OVERRIDE { emit autoTransformChanged(); } Q_SIGNALS: void fillModeChanged(); diff --git a/src/quick/items/qquickitemview_p_p.h b/src/quick/items/qquickitemview_p_p.h index 5ac88a7585..a8352b229e 100644 --- a/src/quick/items/qquickitemview_p_p.h +++ b/src/quick/items/qquickitemview_p_p.h @@ -178,7 +178,7 @@ public: void regenerate(bool orientationChanged=false); void layout(); - virtual void animationFinished(QAbstractAnimationJob *); + virtual void animationFinished(QAbstractAnimationJob *) Q_DECL_OVERRIDE; void refill(); void refill(qreal from, qreal to); void mirrorChange() Q_DECL_OVERRIDE; diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp index cc500956f5..20b6dd5b36 100644 --- a/src/quick/items/qquicklistview.cpp +++ b/src/quick/items/qquicklistview.cpp @@ -255,7 +255,7 @@ public: static_cast(attached)->m_sectionItem = s; } - qreal position() const { + qreal position() const Q_DECL_OVERRIDE { if (section()) { if (view->orientation() == QQuickListView::Vertical) return (view->verticalLayoutDirection() == QQuickItemView::BottomToTop ? -section()->height()-section()->y() : section()->y()); @@ -271,7 +271,7 @@ public: else return (view->effectiveLayoutDirection() == Qt::RightToLeft ? -item->width()-itemX() : itemX()); } - qreal size() const { + qreal size() const Q_DECL_OVERRIDE { if (section()) return (view->orientation() == QQuickListView::Vertical ? item->height()+section()->height() : item->width()+section()->width()); else @@ -280,12 +280,12 @@ public: qreal itemSize() const { return (view->orientation() == QQuickListView::Vertical ? item->height() : item->width()); } - qreal sectionSize() const { + qreal sectionSize() const Q_DECL_OVERRIDE { if (section()) return (view->orientation() == QQuickListView::Vertical ? section()->height() : section()->width()); return 0.0; } - qreal endPosition() const { + qreal endPosition() const Q_DECL_OVERRIDE { if (view->orientation() == QQuickListView::Vertical) { return (view->verticalLayoutDirection() == QQuickItemView::BottomToTop ? -itemY() diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index a17d4a4357..5958edf29f 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -113,7 +113,7 @@ public: } protected: - void timerEvent(QTimerEvent *) + void timerEvent(QTimerEvent *) Q_DECL_OVERRIDE { killTimer(m_timer); m_timer = 0; diff --git a/src/quick/util/qquickanimatorjob_p.h b/src/quick/util/qquickanimatorjob_p.h index 1cffae17db..f8f40b4705 100644 --- a/src/quick/util/qquickanimatorjob_p.h +++ b/src/quick/util/qquickanimatorjob_p.h @@ -63,7 +63,7 @@ public: QQuickAnimatorProxyJob(QAbstractAnimationJob *job, QObject *item); ~QQuickAnimatorProxyJob(); - int duration() const { return m_duration; } + int duration() const Q_DECL_OVERRIDE { return m_duration; } QAbstractAnimationJob *job() const { return m_job; } @@ -72,8 +72,8 @@ public: void markJobManagedByController() { m_jobManagedByController = true; } protected: - void updateCurrentTime(int); - void updateState(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState); + void updateCurrentTime(int) Q_DECL_OVERRIDE; + void updateState(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState) Q_DECL_OVERRIDE; void debugAnimation(QDebug d) const Q_DECL_OVERRIDE; public Q_SLOTS: @@ -116,7 +116,7 @@ public: qreal to() const { return m_to; } void setDuration(int duration) { m_duration = duration; } - int duration() const { return m_duration; } + int duration() const Q_DECL_OVERRIDE { return m_duration; } QEasingCurve easingCurve() const { return m_easing; } void setEasingCurve(const QEasingCurve &curve) { m_easing = curve; } diff --git a/src/quickwidgets/qquickwidget_p.h b/src/quickwidgets/qquickwidget_p.h index dd0da96c3d..e8d1f714f3 100644 --- a/src/quickwidgets/qquickwidget_p.h +++ b/src/quickwidgets/qquickwidget_p.h @@ -70,7 +70,7 @@ public: ~QQuickWidgetPrivate(); void execute(); - void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry); + void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; void initResize(); void updateSize(); void updatePosition(); @@ -82,7 +82,7 @@ public: void destroyContext(); void handleContextCreationFailure(const QSurfaceFormat &format, bool isEs); - QObject *focusObject(); + QObject *focusObject() Q_DECL_OVERRIDE; GLuint textureId() const Q_DECL_OVERRIDE; QImage grabFramebuffer() Q_DECL_OVERRIDE; -- cgit v1.2.3 From 2c2eb24975bbf5c698d4d23c6a5060729339d9f3 Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Fri, 10 Jul 2015 15:46:55 +0200 Subject: qquicktext: Fix using CSS line-height with RichText Only if lineHeight has explicitly been set it will override the block format. Task-number: QTBUG-45204 Change-Id: I6e0d6dd70460cbf436dda3e5640bb9b1d16d7e5a Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/quick/items/qquicktext.cpp | 5 ++++- src/quick/items/qquicktext_p_p.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp index dd4f57bfdb..205571f2e7 100644 --- a/src/quick/items/qquicktext.cpp +++ b/src/quick/items/qquicktext.cpp @@ -91,6 +91,7 @@ QQuickTextPrivate::ExtraData::ExtraData() , minimumPointSize(12) , nbActiveDownloads(0) , maximumLineCount(INT_MAX) + , lineHeightValid(false) , lineHeightMode(QQuickText::ProportionalHeight) , fontSizeMode(QQuickText::FixedSize) { @@ -344,7 +345,7 @@ void QQuickTextPrivate::updateLayout() } textHasChanged = false; } - } else { + } else if (extra.isAllocated() && extra->lineHeightValid) { ensureDoc(); QTextBlockFormat::LineHeightTypes type; type = lineHeightMode() == QQuickText::FixedHeight ? QTextBlockFormat::FixedHeight : QTextBlockFormat::ProportionalHeight; @@ -2386,6 +2387,7 @@ void QQuickText::setLineHeight(qreal lineHeight) if ((d->lineHeight() == lineHeight) || (lineHeight < 0.0)) return; + d->extra.value().lineHeightValid = true; d->extra.value().lineHeight = lineHeight; d->implicitHeightValid = false; d->updateLayout(); @@ -2417,6 +2419,7 @@ void QQuickText::setLineHeightMode(LineHeightMode mode) return; d->implicitHeightValid = false; + d->extra.value().lineHeightValid = true; d->extra.value().lineHeightMode = mode; d->updateLayout(); diff --git a/src/quick/items/qquicktext_p_p.h b/src/quick/items/qquicktext_p_p.h index 9a6da3736e..cd14008728 100644 --- a/src/quick/items/qquicktext_p_p.h +++ b/src/quick/items/qquicktext_p_p.h @@ -95,6 +95,7 @@ public: int minimumPointSize; int nbActiveDownloads; int maximumLineCount; + bool lineHeightValid : 1; QQuickText::LineHeightMode lineHeightMode; QQuickText::FontSizeMode fontSizeMode; QList imgTags; -- cgit v1.2.3 From 96c35a84d30b5b5cdf8feac4959891ad0bfed6a8 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 20 Jul 2015 14:21:08 +0200 Subject: fix readonly metaproperties (revealed by compiler warning) Found thanks to -Wparentheses + gcc 5.1 Change-Id: Iad784a26d268b85f7c67623fd63f0b097a9f29f9 Reviewed-by: Simon Hausmann --- src/qml/compiler/qqmltypecompiler.cpp | 4 ++-- .../auto/qml/qqmlproperty/data/readonlyPrimitiveVsVar.qml | 8 ++++++++ tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 tests/auto/qml/qqmlproperty/data/readonlyPrimitiveVsVar.qml diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp index 46b67d5983..4e9817aa0d 100644 --- a/src/qml/compiler/qqmltypecompiler.cpp +++ b/src/qml/compiler/qqmltypecompiler.cpp @@ -836,7 +836,7 @@ bool QQmlPropertyCacheCreator::createMetaObject(int objectIndex, const QmlIR::Ob propertyFlags |= QQmlPropertyData::IsQList; } - if ((!p->flags & QV4::CompiledData::Property::IsReadOnly) && p->type != QV4::CompiledData::Property::CustomList) + if (!(p->flags & QV4::CompiledData::Property::IsReadOnly) && p->type != QV4::CompiledData::Property::CustomList) propertyFlags |= QQmlPropertyData::IsWritable; @@ -860,7 +860,7 @@ bool QQmlPropertyCacheCreator::createMetaObject(int objectIndex, const QmlIR::Ob continue; quint32 propertyFlags = QQmlPropertyData::IsVarProperty; - if (!p->flags & QV4::CompiledData::Property::IsReadOnly) + if (!(p->flags & QV4::CompiledData::Property::IsReadOnly)) propertyFlags |= QQmlPropertyData::IsWritable; VMD *vmd = (QQmlVMEMetaData *)dynamicData.data(); diff --git a/tests/auto/qml/qqmlproperty/data/readonlyPrimitiveVsVar.qml b/tests/auto/qml/qqmlproperty/data/readonlyPrimitiveVsVar.qml new file mode 100644 index 0000000000..253d61d1da --- /dev/null +++ b/tests/auto/qml/qqmlproperty/data/readonlyPrimitiveVsVar.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 + +QtObject { + readonly property var r_var: 1; + readonly property int r_int: 1; + property var w_var: 1; + property int w_int: 1; +} diff --git a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp index c4b2325843..a8b06ffa71 100644 --- a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp +++ b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp @@ -146,6 +146,7 @@ private slots: void warnOnInvalidBinding(); void registeredCompositeTypeProperty(); void deeplyNestedObject(); + void readOnlyDynamicProperties(); void copy(); private: @@ -2039,6 +2040,20 @@ void tst_qqmlproperty::deeplyNestedObject() QCOMPARE(p.read(), QVariant(14)); } +void tst_qqmlproperty::readOnlyDynamicProperties() +{ + QQmlComponent comp(&engine, testFileUrl("readonlyPrimitiveVsVar.qml")); + QObject *obj = comp.create(); + QVERIFY(obj != 0); + + QVERIFY(!obj->metaObject()->property(obj->metaObject()->indexOfProperty("r_var")).isWritable()); + QVERIFY(!obj->metaObject()->property(obj->metaObject()->indexOfProperty("r_int")).isWritable()); + QVERIFY(obj->metaObject()->property(obj->metaObject()->indexOfProperty("w_var")).isWritable()); + QVERIFY(obj->metaObject()->property(obj->metaObject()->indexOfProperty("w_int")).isWritable()); + + delete obj; +} + void tst_qqmlproperty::initTestCase() { QQmlDataTest::initTestCase(); -- cgit v1.2.3 From 40b9fb8946837a01710814c28fd0f04edba631ad Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Mon, 13 Jul 2015 14:57:16 +0200 Subject: Fix possible stack overflow with many property bindings When there are a lot of bindings to the same property (like 20 000), we would get stack overflows because the notify list for the changed signal was traversed recursively. Changing this also speeds up the traversal. I see something like ~40% reduction in the case of layout() for a notify list of around 200 items. Note: To make it possible to traverse the double-linked list backwards, the next-pointer needs to be moved to the beginning of the struct, because the implementation pattern assumes this (node->next->prev = &node->next). I think this code has rotted after it was added, since the prev pointer was never actually used anywhere before. Change-Id: Icdfac50b7c8584a908efa65694c7f5f416cb153b Reviewed-by: Lars Knoll --- src/qml/qml/qqmlengine.cpp | 28 ++++++++---- src/qml/qml/qqmlnotifier.cpp | 56 +++++++++++++++++------- src/qml/qml/qqmlnotifier_p.h | 7 ++- tests/auto/qml/qqmlnotifier/tst_qqmlnotifier.cpp | 34 ++++++++++++++ 4 files changed, 96 insertions(+), 29 deletions(-) diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index 1f27e4ecb3..392cbe9371 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -1540,16 +1540,28 @@ QQmlDataExtended::~QQmlDataExtended() void QQmlData::NotifyList::layout(QQmlNotifierEndpoint *endpoint) { - if (endpoint->next) - layout(endpoint->next); + // Add a temporary sentinel at beginning of list. This will be overwritten + // when the end point is inserted into the notifies further down. + endpoint->prev = 0; - int index = endpoint->sourceSignal; - index = qMin(index, 0xFFFF - 1); + while (endpoint->next) { + Q_ASSERT(reinterpret_cast(endpoint->next->prev) == endpoint); + endpoint = endpoint->next; + } + + while (endpoint) { + QQmlNotifierEndpoint *ep = (QQmlNotifierEndpoint *) endpoint->prev; + + int index = endpoint->sourceSignal; + index = qMin(index, 0xFFFF - 1); - endpoint->next = notifies[index]; - if (endpoint->next) endpoint->next->prev = &endpoint->next; - endpoint->prev = ¬ifies[index]; - notifies[index] = endpoint; + endpoint->next = notifies[index]; + if (endpoint->next) endpoint->next->prev = &endpoint->next; + endpoint->prev = ¬ifies[index]; + notifies[index] = endpoint; + + endpoint = ep; + } } void QQmlData::NotifyList::layout() diff --git a/src/qml/qml/qqmlnotifier.cpp b/src/qml/qml/qqmlnotifier.cpp index 4ce5be4d1a..ea3f7a1530 100644 --- a/src/qml/qml/qqmlnotifier.cpp +++ b/src/qml/qml/qqmlnotifier.cpp @@ -51,30 +51,52 @@ static Callback QQmlNotifier_callbacks[] = { QQmlVMEMetaObjectEndpoint_callback }; +namespace { + struct NotifyListTraversalData { + NotifyListTraversalData(QQmlNotifierEndpoint *ep = 0) + : originalSenderPtr(0) + , disconnectWatch(0) + , endpoint(ep) + {} + + qintptr originalSenderPtr; + qintptr *disconnectWatch; + QQmlNotifierEndpoint *endpoint; + }; +} + void QQmlNotifier::emitNotify(QQmlNotifierEndpoint *endpoint, void **a) { - qintptr originalSenderPtr; - qintptr *disconnectWatch; - - if (!endpoint->isNotifying()) { - originalSenderPtr = endpoint->senderPtr; - disconnectWatch = &originalSenderPtr; - endpoint->senderPtr = qintptr(disconnectWatch) | 0x1; - } else { - disconnectWatch = (qintptr *)(endpoint->senderPtr & ~0x1); + QVarLengthArray stack; + while (endpoint) { + stack.append(NotifyListTraversalData(endpoint)); + endpoint = endpoint->next; } - if (endpoint->next) - emitNotify(endpoint->next, a); + int i = 0; + for (; i < stack.size(); ++i) { + NotifyListTraversalData &data = stack[i]; + + if (!data.endpoint->isNotifying()) { + data.originalSenderPtr = data.endpoint->senderPtr; + data.disconnectWatch = &data.originalSenderPtr; + data.endpoint->senderPtr = qintptr(data.disconnectWatch) | 0x1; + } else { + data.disconnectWatch = (qintptr *)(data.endpoint->senderPtr & ~0x1); + } + } - if (*disconnectWatch) { + while (--i >= 0) { + const NotifyListTraversalData &data = stack.at(i); + if (*data.disconnectWatch) { - Q_ASSERT(QQmlNotifier_callbacks[endpoint->callback]); - QQmlNotifier_callbacks[endpoint->callback](endpoint, a); + Q_ASSERT(QQmlNotifier_callbacks[data.endpoint->callback]); + QQmlNotifier_callbacks[data.endpoint->callback](data.endpoint, a); - if (disconnectWatch == &originalSenderPtr && originalSenderPtr) { - // End of notifying, restore values - endpoint->senderPtr = originalSenderPtr; + if (data.disconnectWatch == &data.originalSenderPtr && data.originalSenderPtr) { + // End of notifying, restore values + data.endpoint->senderPtr = data.originalSenderPtr; + } } } } diff --git a/src/qml/qml/qqmlnotifier_p.h b/src/qml/qml/qqmlnotifier_p.h index 2a35dcda12..2742bfc84b 100644 --- a/src/qml/qml/qqmlnotifier_p.h +++ b/src/qml/qml/qqmlnotifier_p.h @@ -60,6 +60,8 @@ private: class QQmlEngine; class QQmlNotifierEndpoint { + QQmlNotifierEndpoint *next; + QQmlNotifierEndpoint **prev; public: inline QQmlNotifierEndpoint(); inline ~QQmlNotifierEndpoint(); @@ -103,9 +105,6 @@ private: // The index is in the range returned by QObjectPrivate::signalIndex(). // This is different from QMetaMethod::methodIndex(). signed int sourceSignal:28; - - QQmlNotifierEndpoint *next; - QQmlNotifierEndpoint **prev; }; QQmlNotifier::QQmlNotifier() @@ -137,7 +136,7 @@ void QQmlNotifier::notify() } QQmlNotifierEndpoint::QQmlNotifierEndpoint() -: senderPtr(0), callback(None), sourceSignal(-1), next(0), prev(0) +: next(0), prev(0), senderPtr(0), callback(None), sourceSignal(-1) { } diff --git a/tests/auto/qml/qqmlnotifier/tst_qqmlnotifier.cpp b/tests/auto/qml/qqmlnotifier/tst_qqmlnotifier.cpp index 81215f7a18..4f1c9ae53e 100644 --- a/tests/auto/qml/qqmlnotifier/tst_qqmlnotifier.cpp +++ b/tests/auto/qml/qqmlnotifier/tst_qqmlnotifier.cpp @@ -165,6 +165,7 @@ private slots: void readProperty(); void propertyChange(); void disconnectOnDestroy(); + void lotsOfBindings(); private: void createObjects(); @@ -312,6 +313,39 @@ void tst_qqmlnotifier::disconnectOnDestroy() exportedObject->verifyReceiverCount(); } +class TestObject : public QObject +{ + Q_OBJECT + Q_PROPERTY(int a READ a NOTIFY aChanged) + +public: + int a() const { return 0; } + +signals: + void aChanged(); +}; + +void tst_qqmlnotifier::lotsOfBindings() +{ + TestObject o; + QQmlEngine *e = new QQmlEngine; + + e->rootContext()->setContextProperty(QStringLiteral("test"), &o); + + QList components; + for (int i = 0; i < 20000; ++i) { + QQmlComponent *component = new QQmlComponent(e); + component->setData("import QtQuick 2.0; Item { width: test.a; }", QUrl()); + component->create(e->rootContext()); + components.append(component); + } + + o.aChanged(); + + qDeleteAll(components); + delete e; +} + QTEST_MAIN(tst_qqmlnotifier) #include "tst_qqmlnotifier.moc" -- cgit v1.2.3 From 38a9e94e0ee5ca8bf163fd3ed8d5d6e7fda31252 Mon Sep 17 00:00:00 2001 From: Tasuku Suzuki Date: Tue, 7 Jul 2015 23:08:30 +0900 Subject: add null check for qmlRegisterSingletonType() When the callback passed to the function returns nullptr, QQmlData::ensurePropertyCache(e, o) crashes. Change-Id: I11efd7e9d6c5f18611e796d896384dd14a280303 Reviewed-by: Michael Brasser Reviewed-by: Christopher Adams Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlmetatype.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp index 41d44a821a..cb8c2bd3b5 100644 --- a/src/qml/qml/qqmlmetatype.cpp +++ b/src/qml/qml/qqmlmetatype.cpp @@ -225,6 +225,9 @@ void QQmlType::SingletonInstanceInfo::init(QQmlEngine *e) v4->pushGlobalContext(); QObject *o = qobjectCallback(e, e); setQObjectApi(e, o); + if (!o) { + qFatal("qmlRegisterSingletonType(): \"%s\" is not available because the callback function returns a null pointer.", qPrintable(typeName)); + } // if this object can use a property cache, create it now QQmlData::ensurePropertyCache(e, o); v4->popContext(); -- cgit v1.2.3 From 6d040b2f5e028dbe9efe066bb3f0cf96ad46dcdb Mon Sep 17 00:00:00 2001 From: Andrew Knight Date: Sat, 25 Jul 2015 09:50:19 +0300 Subject: Instantiator: fix typo in docs The method is objectAt(), not itemAt(). Change-Id: Ie37636a6f9a641edfe3ec2b47def8806b9b10aa8 Reviewed-by: Martin Smith --- src/qml/types/qqmlinstantiator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qml/types/qqmlinstantiator.cpp b/src/qml/types/qqmlinstantiator.cpp index 7626ba5a05..735463a058 100644 --- a/src/qml/types/qqmlinstantiator.cpp +++ b/src/qml/types/qqmlinstantiator.cpp @@ -321,7 +321,7 @@ int QQmlInstantiator::count() const Note that an extra variable, index, will be available inside instances of the delegate. This variable refers to the index of the instance inside the Instantiator, - and can be used to obtain the object through the itemAt method of the Instantiator. + and can be used to obtain the object through the objectAt method of the Instantiator. If this property is changed, all instances using the old delegate will be destroyed and new instances will be created using the new delegate. -- cgit v1.2.3 From 4f7d58c9eb3e6bdf5b7e1d3737066fc0b60d8196 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Mon, 27 Jul 2015 12:57:19 +0200 Subject: Fix typo in QSGGeometryNode documentation. Change-Id: I0138aa116abdf890060e868fb95e866db1c7a398 Reviewed-by: Venugopal Shivashankar --- src/quick/scenegraph/coreapi/qsgnode.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/quick/scenegraph/coreapi/qsgnode.cpp b/src/quick/scenegraph/coreapi/qsgnode.cpp index 71f4f62db9..51f3976ed9 100644 --- a/src/quick/scenegraph/coreapi/qsgnode.cpp +++ b/src/quick/scenegraph/coreapi/qsgnode.cpp @@ -806,7 +806,7 @@ void QSGBasicGeometryNode::setGeometry(QSGGeometry *geometry) the vertices and their structure, to be drawn. The Material defines how the shape is filled. - The following is a code snipped illustrating how to create a red + The following is a code snippet illustrating how to create a red line using a QSGGeometryNode: \code QSGGeometry *geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 2); -- cgit v1.2.3 From 7a0dba0225de4c498f65898595d072c322fe1526 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Mon, 27 Jul 2015 12:54:53 +0200 Subject: Fix typo in squircle example. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I352de9cdd6842f11395982212889b6f0ed3ecc70 Reviewed-by: Venugopal Shivashankar Reviewed-by: Topi Reiniö --- examples/quick/canvas/squircle/squircle.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/quick/canvas/squircle/squircle.qml b/examples/quick/canvas/squircle/squircle.qml index 7c62ef5d02..04c9df42d3 100644 --- a/examples/quick/canvas/squircle/squircle.qml +++ b/examples/quick/canvas/squircle/squircle.qml @@ -90,9 +90,9 @@ Item { onFillChanged: requestPaint(); onStrokeChanged: requestPaint(); - onPaint: squcirle(); + onPaint: squircle(); - function squcirle() { + function squircle() { var ctx = canvas.getContext("2d"); var N = canvas.nSize; var R = canvas.radius; -- cgit v1.2.3 From 65ff4e1e88d24430c762a89074027b73782e4a8e Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 28 Jul 2015 15:58:07 +0200 Subject: qmlprofiler: Add missing #include . Fixes the build with VS 2008 (Desktop). Change-Id: I8c9682526754586ea6f597f540a4d5b42363f052 Reviewed-by: Ulf Hermann --- tools/qmlprofiler/qmlprofilerclient.cpp | 2 ++ tools/qmlprofiler/qmlprofilerdata.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tools/qmlprofiler/qmlprofilerclient.cpp b/tools/qmlprofiler/qmlprofilerclient.cpp index 711ddbd862..e9298f226a 100644 --- a/tools/qmlprofiler/qmlprofilerclient.cpp +++ b/tools/qmlprofiler/qmlprofilerclient.cpp @@ -36,6 +36,8 @@ #include #include +#include + ProfilerClient::ProfilerClient(const QString &clientName, QQmlDebugConnection *client) : QQmlDebugClient(clientName, client), diff --git a/tools/qmlprofiler/qmlprofilerdata.cpp b/tools/qmlprofiler/qmlprofilerdata.cpp index c5992652f8..76d06cf564 100644 --- a/tools/qmlprofiler/qmlprofilerdata.cpp +++ b/tools/qmlprofiler/qmlprofilerdata.cpp @@ -39,6 +39,8 @@ #include #include +#include + const char PROFILER_FILE_VERSION[] = "1.02"; static const char *RANGE_TYPE_STRINGS[] = { -- cgit v1.2.3 From 60007e4a9db9ead75a533ca6bff369716fe70dda Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 30 Oct 2014 22:58:18 -0700 Subject: Use the new macros for disabling warnings in qtdeclarative Change-Id: I476da50ba23598c7ca98651477fb701f74053b82 Reviewed-by: Jake Petroules --- src/qml/jsruntime/qv4numberobject.cpp | 10 +++------- src/qml/jsruntime/qv4qobjectwrapper.cpp | 7 +------ src/qml/qml/qqml.h | 10 +++------- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/qml/jsruntime/qv4numberobject.cpp b/src/qml/jsruntime/qv4numberobject.cpp index 89ff110b20..4a1a94e872 100644 --- a/src/qml/jsruntime/qv4numberobject.cpp +++ b/src/qml/jsruntime/qv4numberobject.cpp @@ -75,14 +75,10 @@ void NumberPrototype::init(ExecutionEngine *engine, Object *ctor) ctor->defineReadonlyProperty(QStringLiteral("POSITIVE_INFINITY"), Primitive::fromDouble(qInf())); ctor->defineReadonlyProperty(QStringLiteral("MAX_VALUE"), Primitive::fromDouble(1.7976931348623158e+308)); -#ifdef __INTEL_COMPILER -# pragma warning( push ) -# pragma warning(disable: 239) -#endif +QT_WARNING_PUSH +QT_WARNING_DISABLE_INTEL(239) ctor->defineReadonlyProperty(QStringLiteral("MIN_VALUE"), Primitive::fromDouble(5e-324)); -#ifdef __INTEL_COMPILER -# pragma warning( pop ) -#endif +QT_WARNING_POP defineDefaultProperty(QStringLiteral("constructor"), (o = ctor)); defineDefaultProperty(engine->id_toString, method_toString); diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index 1e4718c208..0a1aa56aab 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -70,14 +70,9 @@ QT_BEGIN_NAMESPACE -#if defined(__GNUC__) && !defined(__INTEL_COMPILER) -# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 405 // The code in this file does not violate strict aliasing, but GCC thinks it does // so turn off the warnings for us to have a clean build -# pragma GCC diagnostic ignored "-Wstrict-aliasing" -# endif -#endif - +QT_WARNING_DISABLE_GCC("-Wstrict-aliasing") using namespace QV4; diff --git a/src/qml/qml/qqml.h b/src/qml/qml/qqml.h index d6fd7b96f6..23cb69e2f1 100644 --- a/src/qml/qml/qqml.h +++ b/src/qml/qml/qqml.h @@ -502,17 +502,13 @@ namespace QtQml { } #endif -#if defined(Q_CC_CLANG) && !defined(Q_CC_INTEL) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wheader-hygiene" -#endif +QT_WARNING_PUSH +QT_WARNING_DISABLE_CLANG("-Wheader-hygiene") // This is necessary to allow for QtQuick1 and QtQuick2 scenes in a single application. using namespace QtQml; -#if defined(Q_CC_CLANG) && !defined(Q_CC_INTEL) -#pragma clang diagnostic pop -#endif +QT_WARNING_POP //The C++ version of protected namespaces in qmldir Q_QML_EXPORT bool qmlProtectModule(const char* uri, int majVersion); -- cgit v1.2.3 From f446a79410b81067c982dc48563e2acccded1247 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 31 Jul 2015 00:30:00 -0700 Subject: Work around ICC 16 beta compiler bug in SFINAE expansion Calling std::vector's constructor (or assign()) with two ints can select one of two different overloads: the (size_t, value_type) overload which fills with n copies of the value or (iterator, iterator) overload, which would copy a range. libstdc++ had some workarounds for this scenario, by using an indirect dispatch to determine whether it was a pair of integrals or not. But ever since the resolution of DR1234 (https://gcc.gnu.org/bugzilla/ show_bug.cgi?id=43813) with C++11's more expressive SFINAE, the dispatching is done actually by the outer template by adding an extra template parameter that requires std::iterator_traite to expand. That's where ICC fails: it expands std::iterator_traits and that fails. It should have ignored the expansion and discarded that overload. The workaround is simple: pass different types as the parameters, which means the compiler cannot select the overload containing a pair of iterators. /usr/include/c++/5/bits/stl_iterator_base_types.h(154): error: name followed by "::" must be a class or namespace name typedef typename _Iterator::iterator_category iterator_category; ^ detected during: instantiation of class "std::__iterator_traits<_Iterator, void> [with _Iterator=int]" at line 163 instantiation of class "std::iterator_traits<_Iterator> [with _Iterator=int]" at line 876 of "compiler/qv4ssa.cpp" Change-Id: I52dd43c12685407bb9a6ffff13f5f783820213a5 Reviewed-by: Erik Verbruggen --- src/qml/compiler/qv4ssa.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qml/compiler/qv4ssa.cpp b/src/qml/compiler/qv4ssa.cpp index e61a602e64..c0669d3e47 100644 --- a/src/qml/compiler/qv4ssa.cpp +++ b/src/qml/compiler/qv4ssa.cpp @@ -530,7 +530,7 @@ class DominatorTree const int bbCount = function->basicBlockCount(); d->vertex = std::vector(bbCount, InvalidBasicBlockIndex); d->parent = std::vector(bbCount, InvalidBasicBlockIndex); - d->dfnum = std::vector(bbCount, 0); + d->dfnum = std::vector(size_t(bbCount), 0); d->semi = std::vector(bbCount, InvalidBasicBlockIndex); d->ancestor = std::vector(bbCount, InvalidBasicBlockIndex); idom = std::vector(bbCount, InvalidBasicBlockIndex); @@ -873,7 +873,7 @@ private: // - set the current node's depth to that of immediate dominator + 1 std::vector calculateNodeDepths() const { - std::vector nodeDepths(function->basicBlockCount(), -1); + std::vector nodeDepths(size_t(function->basicBlockCount()), -1); nodeDepths[0] = 0; foreach (BasicBlock *bb, function->basicBlocks()) { if (bb->isRemoved()) -- cgit v1.2.3 From c318fceaccb1ee23a567f1bb032df45417217e09 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 29 Jul 2015 13:47:45 +0200 Subject: Fix disappearing selection spanning different scripts Due to the way itemization is currently done in Qt, Cyrillic text (and other writing systems) separated by spaces will become separate items because the spaces are itemized as Script_Common. In the Scenegraph's text node engine, we should merge these items into a single node as long as the same font is used for all the text. But a bug in the engine caused this to fail when the text was selected. The symptom of this was that in some rare cases one of the items would vanish if it were in the middle of a selection. In order to support the bearing of selected text leaning outside the selection rect, I previously added a hack which would add all selected text as unselected text as well in b0783c21fb54b939f07ddf5658cc51113b8014e6. This was an awkward way of doing it and caused said regression. A less intrusive way is just to add the text to the scene graph twice, as this does not interfere with the logic needed to support selecting part of ligatures nor the engine's ability to merge nodes correctly. [ChangeLog][Text] Fixed regression with selections spanning different scripts. Task-number: QTBUG-46829 Change-Id: I0faed76fb2cd1ac0b2e5cc54b81008b5e2550733 Reviewed-by: Gunnar Sletta --- src/quick/items/qquicktextnodeengine.cpp | 6 ++---- .../data/text/textedit_cyrillic_selected_all.qml | 13 +++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 tests/manual/scenegraph_lancelot/data/text/textedit_cyrillic_selected_all.qml diff --git a/src/quick/items/qquicktextnodeengine.cpp b/src/quick/items/qquicktextnodeengine.cpp index 7903f79e89..5140ccb68f 100644 --- a/src/quick/items/qquicktextnodeengine.cpp +++ b/src/quick/items/qquicktextnodeengine.cpp @@ -596,7 +596,6 @@ void QQuickTextNodeEngine::addGlyphsInRange(int rangeStart, int rangeLength, for (int j=0; jaddRectangleNode(rect, color); } - // Add all unselected text first + // Add all text with unselected color first for (int i = 0; i < nodes.size(); ++i) { const BinaryTreeNode *node = nodes.at(i); - if (node->selectionState == Unselected) - parentNode->addGlyphs(node->position, node->glyphRun, node->color, style, styleColor, 0); + parentNode->addGlyphs(node->position, node->glyphRun, node->color, style, styleColor, 0); } for (int i = 0; i < imageNodes.size(); ++i) { diff --git a/tests/manual/scenegraph_lancelot/data/text/textedit_cyrillic_selected_all.qml b/tests/manual/scenegraph_lancelot/data/text/textedit_cyrillic_selected_all.qml new file mode 100644 index 0000000000..9580f28e29 --- /dev/null +++ b/tests/manual/scenegraph_lancelot/data/text/textedit_cyrillic_selected_all.qml @@ -0,0 +1,13 @@ +import QtQuick 2.0 + +Item { + width: 320 + height: 480 + TextEdit { + id: textEdit + text: "и в у" + anchors.centerIn: parent + Component.onCompleted: textEdit.selectAll() + font.pixelSize: 14 + } +} -- cgit v1.2.3 From d218d8c8538e47cf32a06b4bdd9f60bd16a8cf50 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 29 Jul 2015 14:27:58 +0200 Subject: Fix selecting single character in middle of string The fix for QTBUG-46829 revealed a bug in the code to handle selecting part of ligatures. The ranges were assumed to be [start, end], while they are in fact [start, end>. This would cause the engine to assume the previous node overlapped completely with the selected node and that the node had thus already been added to the graph. Due to the bug in QTBUG-46829, this accidentally worked before, but when that bug was fixed, this bug appeared. Change-Id: I517d260de9f58db4504dd4320b7113fbbe305a81 Reviewed-by: Gunnar Sletta --- src/quick/items/qquicktextnodeengine.cpp | 10 +++++----- .../data/text/textedit_cyrillic_selected.qml | 13 +++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 tests/manual/scenegraph_lancelot/data/text/textedit_cyrillic_selected.qml diff --git a/src/quick/items/qquicktextnodeengine.cpp b/src/quick/items/qquicktextnodeengine.cpp index 5140ccb68f..efe79b382e 100644 --- a/src/quick/items/qquicktextnodeengine.cpp +++ b/src/quick/items/qquicktextnodeengine.cpp @@ -821,14 +821,14 @@ void QQuickTextNodeEngine::addToSceneGraph(QQuickTextNode *parentNode, for (int i = 0; i < node->ranges.size(); ++i) { const QPair &range = node->ranges.at(i); - int rangeLength = range.second - range.first + 1; + int rangeLength = range.second - range.first; if (previousNode != 0) { for (int j = 0; j < previousNode->ranges.size(); ++j) { const QPair &otherRange = previousNode->ranges.at(j); - if (range.first <= otherRange.second && range.second >= otherRange.first) { + if (range.first < otherRange.second && range.second > otherRange.first) { int start = qMax(range.first, otherRange.first); int end = qMin(range.second, otherRange.second); - rangeLength -= end - start + 1; + rangeLength -= end - start; if (rangeLength == 0) break; } @@ -839,10 +839,10 @@ void QQuickTextNodeEngine::addToSceneGraph(QQuickTextNode *parentNode, for (int j = 0; j < nextNode->ranges.size(); ++j) { const QPair &otherRange = nextNode->ranges.at(j); - if (range.first <= otherRange.second && range.second >= otherRange.first) { + if (range.first < otherRange.second && range.second > otherRange.first) { int start = qMax(range.first, otherRange.first); int end = qMin(range.second, otherRange.second); - rangeLength -= end - start + 1; + rangeLength -= end - start; if (rangeLength == 0) break; } diff --git a/tests/manual/scenegraph_lancelot/data/text/textedit_cyrillic_selected.qml b/tests/manual/scenegraph_lancelot/data/text/textedit_cyrillic_selected.qml new file mode 100644 index 0000000000..849e4b8597 --- /dev/null +++ b/tests/manual/scenegraph_lancelot/data/text/textedit_cyrillic_selected.qml @@ -0,0 +1,13 @@ +import QtQuick 2.0 + +Item { + width: 320 + height: 480 + TextEdit { + id: textEdit + text: "и в у" + anchors.centerIn: parent + Component.onCompleted: textEdit.select(2, 3) + font.pixelSize: 14 + } +} -- cgit v1.2.3 From 97202b4eedb08b38633cec4060fb6f6c6a6381f2 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Mon, 3 Aug 2015 13:03:36 +0200 Subject: Fix typo in plugin documentation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I5cd851e493b6663bd0a7d09a1c5435c37a4ad7d6 Reviewed-by: Topi Reiniö --- src/qml/doc/src/qmllanguageref/modules/cppplugins.qdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qml/doc/src/qmllanguageref/modules/cppplugins.qdoc b/src/qml/doc/src/qmllanguageref/modules/cppplugins.qdoc index 79bd3df9d9..90e432a8ef 100644 --- a/src/qml/doc/src/qmllanguageref/modules/cppplugins.qdoc +++ b/src/qml/doc/src/qmllanguageref/modules/cppplugins.qdoc @@ -32,7 +32,7 @@ \section1 Creating a Plugin - The \l{QQmlEngine}{QML engine} load C++ plugins for QML. + The \l{QQmlEngine}{QML engine} loads C++ plugins for QML. Such plugins are usually provided in a QML extension module, and can provide types for use by clients in QML documents which import the module. A module requires at least one type registered in order to be considered -- cgit v1.2.3 From 16b716dc9f943313b5f75e0a9a374d496ffda1b8 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Mon, 3 Aug 2015 13:37:28 +0200 Subject: Consolidate duplicated QQmlExtensionPlugin documentation. There have already been doc improvements made to one of the duplicated pieces and not the other. This patch uses the improved one. Change-Id: I12a6cb013e61f63e67fb9d691ee58ba12e21054d Reviewed-by: Venugopal Shivashankar --- .../doc/src/qmllanguageref/modules/cppplugins.qdoc | 85 +--------------------- .../modules/qqmlextensionplugin.qdocinc | 83 +++++++++++++++++++++ src/qml/qml/qqmlextensionplugin.cpp | 66 +---------------- 3 files changed, 85 insertions(+), 149 deletions(-) create mode 100644 src/qml/doc/src/qmllanguageref/modules/qqmlextensionplugin.qdocinc diff --git a/src/qml/doc/src/qmllanguageref/modules/cppplugins.qdoc b/src/qml/doc/src/qmllanguageref/modules/cppplugins.qdoc index 90e432a8ef..a2397b6cfb 100644 --- a/src/qml/doc/src/qmllanguageref/modules/cppplugins.qdoc +++ b/src/qml/doc/src/qmllanguageref/modules/cppplugins.qdoc @@ -38,90 +38,7 @@ A module requires at least one type registered in order to be considered valid. - QQmlExtensionPlugin is a plugin interface that makes it possible to - create QML extensions that can be loaded dynamically into QML applications. - These extensions allow custom QML types to be made available to the - QML engine. - - To write a QML extension plugin: - \list 1 - \li Subclass QQmlExtensionPlugin - \list - \li Use the Q_PLUGIN_METADATA() macro to register the plugin with - the Qt meta object system - \li Override the \l{QQmlExtensionPlugin::}{registerTypes()} method - and call qmlRegisterType() to register the types to be exported - by the plugin - \endlist - \li Write a project file for the plugin - \li Create a \l{Module Definition qmldir Files}{qmldir file} to - describe the plugin - \endlist - - QML extension plugins are for either application-specific or library-like - plugins. Library plugins should limit themselves to registering types, as - any manipulation of the engine's root context may cause conflicts or other - issues in the library user's code. - -\section1 Plugin Example - - Suppose there is a new \c TimeModel C++ class that should be made available - as a new QML type. It provides the current time through \c hour and \c minute - properties. - - \snippet qmlextensionplugins/plugin.cpp 0 - \dots - - To make this type available, we create a plugin class named \c QExampleQmlPlugin - which is a subclass of \l QQmlExtensionPlugin. It overrides the - \l{QQmlExtensionPlugin::}{registerTypes()} method in order to register the \c TimeModel - type using qmlRegisterType(). It also uses the Q_PLUGIN_METADATA() macro in the class - definition to register the plugin with the Qt meta object system using a unique - identifier for the plugin. - - \snippet qmlextensionplugins/plugin.cpp plugin - - The \c TimeModel class receives a \c{1.0} version of this plugin library, as - a QML type called \c Time. The Q_ASSERT() macro can ensure the type namespace is - imported correctly by any QML components that use this plugin. The - \l{Defining QML Types from C++} article has more information about registering C++ - types into the runtime. - - For this example, the TimeExample source directory is in - \c{imports/TimeExample}. The plugin's type namespace will mirror - this structure, so the types are registered into the namespace - "TimeExample". - - Additionally, the project file, in a \c .pro file, defines the project as a plugin library, - specifies it should be built into the \c imports/TimeExample directory, and registers - the plugin target name and various other details: - - \code - TEMPLATE = lib - CONFIG += qt plugin - QT += qml - - DESTDIR = imports/TimeExample - TARGET = qmlqtimeexampleplugin - SOURCES += qexampleqmlplugin.cpp - \endcode - - Finally, a \l{Module Definition qmldir Files}{qmldir file} is required - in the \c imports/TimeExample directory to describe the plugin and the types that it - exports. The plugin includes a \c Clock.qml file along with the \c qmlqtimeexampleplugin - that is built by the project (as shown above in the \c .pro file) so both of these - need to be specified in the \c qmldir file: - - \quotefile qmlextensionplugins/imports/TimeExample/qmldir - - Once the project is built and installed, the new \c Time component is - accessible by any QML component that imports the \c TimeExample - module - - \snippet qmlextensionplugins/plugins.qml 0 - - The full source code is available in the \l {qmlextensionplugins}{plugins example}. - + \include qqmlextensionplugin.qdocinc \section1 Reference diff --git a/src/qml/doc/src/qmllanguageref/modules/qqmlextensionplugin.qdocinc b/src/qml/doc/src/qmllanguageref/modules/qqmlextensionplugin.qdocinc new file mode 100644 index 0000000000..9bb863a90b --- /dev/null +++ b/src/qml/doc/src/qmllanguageref/modules/qqmlextensionplugin.qdocinc @@ -0,0 +1,83 @@ +QQmlExtensionPlugin is a plugin interface that makes it possible to +create QML extensions that can be loaded dynamically into QML applications. +These extensions allow custom QML types to be made available to the +QML engine. + +To write a QML extension plugin: +\list 1 +\li Subclass QQmlExtensionPlugin + \list + \li Use the Q_PLUGIN_METADATA() macro to register the plugin with + the Qt meta object system + \li Override the \l{QQmlExtensionPlugin::}{registerTypes()} method + and call qmlRegisterType() to register the types to be exported + by the plugin + \endlist +\li Write a project file for the plugin +\li Create a \l{Module Definition qmldir Files}{qmldir file} to + describe the plugin +\endlist + +QML extension plugins are for either application-specific or library-like +plugins. Library plugins should limit themselves to registering types, as +any manipulation of the engine's root context may cause conflicts or other +issues in the library user's code. + +\section1 Plugin Example + +Suppose there is a new \c TimeModel C++ class that should be made available +as a new QML type. It provides the current time through \c hour and \c minute +properties. + +\snippet qmlextensionplugins/plugin.cpp 0 +\dots + +To make this type available, we create a plugin class named \c QExampleQmlPlugin +which is a subclass of \l QQmlExtensionPlugin. It overrides the +\l{QQmlExtensionPlugin::}{registerTypes()} method in order to register the \c TimeModel +type using qmlRegisterType(). It also uses the Q_PLUGIN_METADATA() macro in the class +definition to register the plugin with the Qt meta object system using a unique +identifier for the plugin. + +\snippet qmlextensionplugins/plugin.cpp plugin + +The \c TimeModel class receives a \c{1.0} version of this plugin library, as +a QML type called \c Time. The Q_ASSERT() macro can ensure the type namespace is +imported correctly by any QML components that use this plugin. The +\l{Defining QML Types from C++} article has more information about registering C++ +types into the runtime. + +For this example, the TimeExample source directory is in +\c{imports/TimeExample}. The plugin's type namespace will mirror +this structure, so the types are registered into the namespace +"TimeExample". + +Additionally, the project file, in a \c .pro file, defines the project as a plugin library, +specifies it should be built into the \c imports/TimeExample directory, and registers +the plugin target name and various other details: + +\code +TEMPLATE = lib +CONFIG += qt plugin +QT += qml + +DESTDIR = imports/TimeExample +TARGET = qmlqtimeexampleplugin +SOURCES += qexampleqmlplugin.cpp +\endcode + +Finally, a \l{Module Definition qmldir Files}{qmldir file} is required +in the \c imports/TimeExample directory to describe the plugin and the types that it +exports. The plugin includes a \c Clock.qml file along with the \c qmlqtimeexampleplugin +that is built by the project (as shown above in the \c .pro file) so both of these +need to be specified in the \c qmldir file: + +\quotefile qmlextensionplugins/imports/TimeExample/qmldir + +Once the project is built and installed, the new \c Time component is +accessible by any QML component that imports the \c TimeExample +module + +\snippet qmlextensionplugins/plugins.qml 0 + +The full source code is available in the \l {qmlextensionplugins}{plugins example}. diff --git a/src/qml/qml/qqmlextensionplugin.cpp b/src/qml/qml/qqmlextensionplugin.cpp index 7b560268ba..d86fbc5999 100644 --- a/src/qml/qml/qqmlextensionplugin.cpp +++ b/src/qml/qml/qqmlextensionplugin.cpp @@ -44,71 +44,7 @@ QT_BEGIN_NAMESPACE \ingroup plugins - QQmlExtensionPlugin is a plugin interface that makes it possible to - create QML extensions that can be loaded dynamically into QML applications. - These extensions allow custom QML types to be made available to the QML engine. - - To write a QML extension plugin: - - \list - \li Subclass QQmlExtensionPlugin, implement registerTypes() method to register types - using qmlRegisterType(), and export the class using the Q_PLUGIN_METADATA() macro - \li Write an appropriate project file for the plugin - \li Create a \l{Module Definition qmldir Files}{qmldir file} to describe the plugin - \endlist - - QML extension plugins can be used to provide either application-specific or - library-like plugins. Library plugins should limit themselves to registering types, - as any manipulation of the engine's root context may cause conflicts - or other issues in the library user's code. - - - \section1 An Example - - Suppose there is a new \c TimeModel C++ class that should be made available - as a new QML element. It provides the current time through \c hour and \c minute - properties, like this: - - \snippet qmlextensionplugins/plugin.cpp 0 - \dots - - To make this class available as a QML type, create a plugin that registers - this type with a specific \l {QML Modules}{module} using qmlRegisterType(). For this example the plugin - module will be named \c TimeExample (as defined in the project - file further below). - - \snippet qmlextensionplugins/plugin.cpp plugin - - This registers the \c TimeModel class with the 1.0 version of this - plugin library, as a QML type called \c Time. The Q_ASSERT statement - ensures the module is imported correctly by any QML components that use this plugin. - - The project file defines the project as a plugin library and specifies - it should be built into the \c imports/TimeExample directory: - - \code - TEMPLATE = lib - CONFIG += qt plugin - QT += qml - - DESTDIR = imports/TimeExample - TARGET = qmlqtimeexampleplugin - ... - \endcode - - Finally, a \l{Module Definition qmldir Files}{qmldir file} is required in the \c imports/TimeExample directory - that describes the plugin. This directory includes a \c Clock.qml file that - should be bundled with the plugin, so it needs to be specified in the \c qmldir - file: - - \quotefile qmlextensionplugins/imports/TimeExample/qmldir - - Once the project is built and installed, the new \c Time element can be - used by any QML component that imports the \c TimeExample module: - - \snippet qmlextensionplugins/plugins.qml 0 - - The full source code is available in the \l {qmlextensionplugins}{plugins example}. + \include qqmlextensionplugin.qdocinc The \l {Writing QML Extensions with C++} tutorial also contains a chapter on creating QML plugins. -- cgit v1.2.3 From 3efe416da236828010a446f415583a9777e4712d Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Mon, 3 Aug 2015 13:44:10 +0200 Subject: Rephrase sentence about versioning in QQmlExtensionPlugin documentation The original sentence (885735d0) is better than the new one (2c4c7a38). Some small adjustments were made in this patch as well. Change-Id: I2cc62c2ffcde7df289b07486439456350a2f60ab Reviewed-by: Venugopal Shivashankar --- src/qml/doc/src/qmllanguageref/modules/qqmlextensionplugin.qdocinc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qml/doc/src/qmllanguageref/modules/qqmlextensionplugin.qdocinc b/src/qml/doc/src/qmllanguageref/modules/qqmlextensionplugin.qdocinc index 9bb863a90b..2274617f77 100644 --- a/src/qml/doc/src/qmllanguageref/modules/qqmlextensionplugin.qdocinc +++ b/src/qml/doc/src/qmllanguageref/modules/qqmlextensionplugin.qdocinc @@ -41,7 +41,7 @@ identifier for the plugin. \snippet qmlextensionplugins/plugin.cpp plugin -The \c TimeModel class receives a \c{1.0} version of this plugin library, as +This registers the \c TimeModel class with version \c{1.0} of this plugin library, as a QML type called \c Time. The Q_ASSERT() macro can ensure the type namespace is imported correctly by any QML components that use this plugin. The \l{Defining QML Types from C++} article has more information about registering C++ -- cgit v1.2.3 From d296ebfe6585010a38db0e3043ef5ceaa6a30883 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 28 Jul 2015 13:00:48 +0200 Subject: Fix selections in tables that span over several cells In the code that converts text layouts to subtrees in the scene graph specifically for TextEdit, there was a cutoff to treat text tables as single nodes in the graph (for simplicity). However, this breaks selections, since the ranges spanned by each cell will be interpreted as overlapping, messing up the selection merging logic. We need the same approach here as for any other text frame where we check frame boundaries. [ChangeLog][TextEdit] Fixed issues with selections that spanned several cells in a table. Change-Id: I789041d84b5d163e209488f8f2f1f83a6471389f Task-number: QTBUG-46928 Reviewed-by: Pierre Rossi --- src/quick/items/qquicktextedit.cpp | 7 ---- .../data/text/textedit_table_selected.qml | 40 ++++++++++++++++++++++ 2 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 tests/manual/scenegraph_lancelot/data/text/textedit_table_selected.qml diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp index 8237ad10e4..cd1cf5eef1 100644 --- a/src/quick/items/qquicktextedit.cpp +++ b/src/quick/items/qquicktextedit.cpp @@ -1873,13 +1873,6 @@ QSGNode *QQuickTextEdit::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData * node->m_engine->addTextObject(QPointF(0, 0), format, QQuickTextNodeEngine::Unselected, d->document, pos, textFrame->frameFormat().position()); nodeStart = pos; - } else if (qobject_cast(textFrame)) { // To keep things simple, map text tables as one text node - QTextFrame::iterator it = textFrame->begin(); - nodeOffset = d->document->documentLayout()->frameBoundingRect(textFrame).topLeft(); - updateNodeTransform(node, nodeOffset); - while (!it.atEnd()) - node->m_engine->addTextBlock(d->document, (it++).currentBlock(), -nodeOffset, d->color, QColor(), selectionStart(), selectionEnd() - 1); - nodeStart = textFrame->firstPosition(); } else { // Having nodes spanning across frame boundaries will break the current bookkeeping mechanism. We need to prevent that. QList frameBoundaries; diff --git a/tests/manual/scenegraph_lancelot/data/text/textedit_table_selected.qml b/tests/manual/scenegraph_lancelot/data/text/textedit_table_selected.qml new file mode 100644 index 0000000000..749c37904e --- /dev/null +++ b/tests/manual/scenegraph_lancelot/data/text/textedit_table_selected.qml @@ -0,0 +1,40 @@ +import QtQuick 2.0 + +Item { + width: 320 + height: 480 + + TextEdit { + id: textEdit + anchors.centerIn: parent + verticalAlignment: Text.AlignBottom + font.family: "Arial" + font.pixelSize: 16 + textFormat: Text.RichText + Component.onCompleted: textEdit.selectAll() + text: + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "
\n" + + "Cell 1\n" + + "
\n" + + "Cell 2\n" + + "
\n" + + "Cell 3\n" + + "
\n" + + "\n" + + "\n" + + } +} -- cgit v1.2.3 From 372804f1f64918e281a29cd2f849f7e1b1488eee Mon Sep 17 00:00:00 2001 From: Nico Vertriest Date: Thu, 30 Jul 2015 12:33:32 +0200 Subject: Doc: added documentation to undocumented methods Task-number: QTBUG-36985 Change-Id: Idc6f7961f4f02f66dc3d4a8e5d09dd15d43b7757 Reviewed-by: Venugopal Shivashankar --- src/qml/qml/qqmlabstracturlinterceptor.cpp | 2 +- src/qml/qml/qqmlengine.cpp | 15 +++++++++++++++ src/qml/qml/qqmlfileselector.cpp | 3 +++ src/quick/items/qquickframebufferobject.cpp | 9 +++++++++ src/quick/items/qquickitem.cpp | 25 ++++++++++++++++++++++++- src/quick/items/qquickpainteditem.cpp | 9 +++++++++ src/quick/items/qquickrendercontrol.cpp | 4 ++++ 7 files changed, 65 insertions(+), 2 deletions(-) diff --git a/src/qml/qml/qqmlabstracturlinterceptor.cpp b/src/qml/qml/qqmlabstracturlinterceptor.cpp index e64b33b181..cb57bc2146 100644 --- a/src/qml/qml/qqmlabstracturlinterceptor.cpp +++ b/src/qml/qml/qqmlabstracturlinterceptor.cpp @@ -58,7 +58,7 @@ To implement support for a custom networked scheme, see setNetworkAccessManagerFactory. */ -/* +/*! \enum QQmlAbstractUrlInterceptor::DataType Specifies where URL interception is taking place. diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index 392cbe9371..ffc890a2cf 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -260,6 +260,18 @@ void QQmlEnginePrivate::activateDesignerMode() on producing the image without blocking the main thread. */ +/*! + \fn QQmlImageProviderBase::imageType() const + + Implement this method to return the image type supported by this image provider. +*/ + +/*! + \fn QQmlImageProviderBase::flags() const + + Implement this to return the properties of this image provider. +*/ + /*! \internal */ QQmlImageProviderBase::QQmlImageProviderBase() { @@ -1354,6 +1366,9 @@ QQmlEngine::ObjectOwnership QQmlEngine::objectOwnership(QObject *object) return ddata->indestructible?CppOwnership:JavaScriptOwnership; } +/*! + \reimp +*/ bool QQmlEngine::event(QEvent *e) { Q_D(QQmlEngine); diff --git a/src/qml/qml/qqmlfileselector.cpp b/src/qml/qml/qqmlfileselector.cpp index 3ee7bb3040..8597e8a5c7 100644 --- a/src/qml/qml/qqmlfileselector.cpp +++ b/src/qml/qml/qqmlfileselector.cpp @@ -102,6 +102,9 @@ QQmlFileSelector::QQmlFileSelector(QQmlEngine* engine, QObject* parent) d->engine->setUrlInterceptor(d->myInstance.data()); } +/*! + Destroys the QQmlFileSelector object. +*/ QQmlFileSelector::~QQmlFileSelector() { Q_D(QQmlFileSelector); diff --git a/src/quick/items/qquickframebufferobject.cpp b/src/quick/items/qquickframebufferobject.cpp index c3e5b97baf..6031315b90 100644 --- a/src/quick/items/qquickframebufferobject.cpp +++ b/src/quick/items/qquickframebufferobject.cpp @@ -298,11 +298,17 @@ QSGNode *QQuickFramebufferObject::updatePaintNode(QSGNode *node, UpdatePaintNode return n; } +/*! + \reimp +*/ bool QQuickFramebufferObject::isTextureProvider() const { return true; } +/*! + \reimp +*/ QSGTextureProvider *QQuickFramebufferObject::textureProvider() const { Q_D(const QQuickFramebufferObject); @@ -316,6 +322,9 @@ QSGTextureProvider *QQuickFramebufferObject::textureProvider() const return d->node; } +/*! + \reimp +*/ void QQuickFramebufferObject::releaseResources() { // When release resources is called on the GUI thread, we only need to diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp index 3d0f550d14..5fd1882216 100644 --- a/src/quick/items/qquickitem.cpp +++ b/src/quick/items/qquickitem.cpp @@ -4237,7 +4237,6 @@ void QQuickItem::mapToItem(QQmlV4Function *args) const /*! \qmlmethod QtQuick::Item::forceActiveFocus() - \overload Forces active focus on the item. @@ -4250,6 +4249,18 @@ void QQuickItem::mapToItem(QQmlV4Function *args) const \sa activeFocus */ +/*! + Forces active focus on the item. + + This method sets focus on the item and ensures that all ancestor + FocusScope objects in the object hierarchy are also given \l focus. + + The reason for the focus change will be \l [CPP] Qt::OtherFocusReason. Use + the overloaded method to specify the focus reason to enable better + handling of the focus change. + + \sa activeFocus +*/ void QQuickItem::forceActiveFocus() { forceActiveFocus(Qt::OtherFocusReason); @@ -4257,7 +4268,19 @@ void QQuickItem::forceActiveFocus() /*! \qmlmethod QtQuick::Item::forceActiveFocus(Qt::FocusReason reason) + \overload + + Forces active focus on the item with the given \a reason. + + This method sets focus on the item and ensures that all ancestor + FocusScope objects in the object hierarchy are also given \l focus. + \since 5.1 + + \sa activeFocus, Qt::FocusReason +*/ +/*! + \overload Forces active focus on the item with the given \a reason. This method sets focus on the item and ensures that all ancestor diff --git a/src/quick/items/qquickpainteditem.cpp b/src/quick/items/qquickpainteditem.cpp index b3e4906c41..8d93c577ab 100644 --- a/src/quick/items/qquickpainteditem.cpp +++ b/src/quick/items/qquickpainteditem.cpp @@ -549,6 +549,9 @@ QSGNode *QQuickPaintedItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeDat return node; } +/*! + \reimp +*/ void QQuickPaintedItem::releaseResources() { Q_D(QQuickPaintedItem); @@ -567,11 +570,17 @@ void QQuickPaintedItem::invalidateSceneGraph() d->node = 0; // Managed by the scene graph, just clear the pointer } +/*! + \reimp +*/ bool QQuickPaintedItem::isTextureProvider() const { return true; } +/*! + \reimp +*/ QSGTextureProvider *QQuickPaintedItem::textureProvider() const { Q_D(const QQuickPaintedItem); diff --git a/src/quick/items/qquickrendercontrol.cpp b/src/quick/items/qquickrendercontrol.cpp index fd4787be98..6b0b9c3a06 100644 --- a/src/quick/items/qquickrendercontrol.cpp +++ b/src/quick/items/qquickrendercontrol.cpp @@ -141,6 +141,10 @@ void QQuickRenderControlPrivate::cleanup() sg = 0; } +/*! + Constructs a QQuickRenderControl object, with parent + object \a parent. +*/ QQuickRenderControl::QQuickRenderControl(QObject *parent) : QObject(*(new QQuickRenderControlPrivate), parent) { -- cgit v1.2.3 From 98ff203205ec77a3f4afbbe0ca3e34afb90274bd Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Wed, 5 Aug 2015 10:47:38 +0200 Subject: Make QQmlExtensionPlugin documentation clearer. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I spent too long wondering why my plugin wasn't being loaded, until I realized that the directory I was installing the qmldir into was not named the same as the module. This is already documented in the "Module Definition qmldir Files" documentation: http://doc.qt.io/qt-5/qtqml-modules-qmldir.html#contents-of-a-module-definition-qmldir-file But as I was writing a plugin, I was following this documentation: http://doc.qt.io/qt-5/qtqml-modules-cppplugins.html Where it was not at all obvious that they should be named the same. Change-Id: I3e20bc31f8b42c7141b4c22c8cb1750ba9782971 Reviewed-by: Topi Reiniö --- .../modules/qqmlextensionplugin.qdocinc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/qml/doc/src/qmllanguageref/modules/qqmlextensionplugin.qdocinc b/src/qml/doc/src/qmllanguageref/modules/qqmlextensionplugin.qdocinc index 2274617f77..7c1d65b095 100644 --- a/src/qml/doc/src/qmllanguageref/modules/qqmlextensionplugin.qdocinc +++ b/src/qml/doc/src/qmllanguageref/modules/qqmlextensionplugin.qdocinc @@ -47,12 +47,7 @@ imported correctly by any QML components that use this plugin. The \l{Defining QML Types from C++} article has more information about registering C++ types into the runtime. -For this example, the TimeExample source directory is in -\c{imports/TimeExample}. The plugin's type namespace will mirror -this structure, so the types are registered into the namespace -"TimeExample". - -Additionally, the project file, in a \c .pro file, defines the project as a plugin library, +Additionally, the project file (\c .pro) defines the project as a plugin library, specifies it should be built into the \c imports/TimeExample directory, and registers the plugin target name and various other details: @@ -74,6 +69,18 @@ need to be specified in the \c qmldir file: \quotefile qmlextensionplugins/imports/TimeExample/qmldir +To make things easier for this example, the TimeExample source directory is in +\c{imports/TimeExample}, and we build +\l{Source, Build, and Install Directories}{in-source}. However, the structure +of the source directory is not so important, as the \c qmldir file can specify +paths to installed QML files. + +What is important is the name of the directory that the qmldir is installed +into. When the user imports our module, the QML engine uses the +\l{Contents of a Module Definition qmldir File}{module identifier} +(\c TimeExample) to find the plugin, and so the directory in which it is +installed must match the module identifier. + Once the project is built and installed, the new \c Time component is accessible by any QML component that imports the \c TimeExample module -- cgit v1.2.3 From 42054d0b6c3b906ba7b3815974c9d7738b49a9ea Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 11 Aug 2015 12:49:10 +0200 Subject: Fix incorrectly formatted code in QQmlEngine documentation. Change-Id: I70832871cbd697b77cfcbbe425ba5936be1c01d5 Reviewed-by: Venugopal Shivashankar --- src/qml/doc/src/qmlfunctions.qdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qml/doc/src/qmlfunctions.qdoc b/src/qml/doc/src/qmlfunctions.qdoc index 25bb0d6068..4203cca8b3 100644 --- a/src/qml/doc/src/qmlfunctions.qdoc +++ b/src/qml/doc/src/qmlfunctions.qdoc @@ -470,8 +470,8 @@ as any other item). Usage: - // First, define your QML singleton type which provides the functionality. \qml + // First, define your QML singleton type which provides the functionality. pragma Singleton import QtQuick 2.0 Item { -- cgit v1.2.3 From 5762738fce7306120c1d93da84ef9c2693d95881 Mon Sep 17 00:00:00 2001 From: Tobias Koenig Date: Tue, 11 Aug 2015 17:55:00 +0200 Subject: Fix crash in QQuickCanvasItem::updatePaintNode() QQuickCanvasItem manages the life time of the texture already, so it shouldn't set the ownsTexture flag on the QSGSimpleTextureNode, because that would result in a double deletion when QSGSimpleTextureNode::setTexture() is called. Change-Id: I7c1cc949b664d1a8b64bab092250439171e66233 Task-number: QTBUG-47714 Reviewed-by: Gunnar Sletta --- src/quick/items/context2d/qquickcanvasitem.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/quick/items/context2d/qquickcanvasitem.cpp b/src/quick/items/context2d/qquickcanvasitem.cpp index cb694c499a..75507c68d2 100644 --- a/src/quick/items/context2d/qquickcanvasitem.cpp +++ b/src/quick/items/context2d/qquickcanvasitem.cpp @@ -57,7 +57,11 @@ class QQuickCanvasNode : public QSGSimpleTextureNode public: QQuickCanvasNode() { qsgnode_set_description(this, QStringLiteral("canvasnode")); - setOwnsTexture(true); + setOwnsTexture(false); + } + + ~QQuickCanvasNode() { + delete texture(); } }; -- cgit v1.2.3 From cdc0916f60753f3dd6f97b504a27d49d3567f6b0 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Wed, 12 Aug 2015 10:27:07 +0200 Subject: Canvas: add a testcase for QSGSimpleTextureNode crash. Task-number: QTBUG-47714 Change-Id: I8ecf2673ebc5de3d0fe1dec8a67bee81f5d4fb8f Reviewed-by: Gabriel de Dietrich --- .../quick/qquickcanvasitem/data/tst_canvas.qml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/auto/quick/qquickcanvasitem/data/tst_canvas.qml b/tests/auto/quick/qquickcanvasitem/data/tst_canvas.qml index 5960e53557..93f85107a7 100644 --- a/tests/auto/quick/qquickcanvasitem/data/tst_canvas.qml +++ b/tests/auto/quick/qquickcanvasitem/data/tst_canvas.qml @@ -677,5 +677,27 @@ CanvasTestCase { waitForRendering(implicitlySizedItem); comparePixel(implicitlySizedItem.canvas.context, xCenter, yCenter, 0, 0, 0, 255); } + + Component { + id: simpleTextureNodeUsageComponent + + Canvas { + id: canvas + anchors.fill: parent + + onPaint: { + var ctx = canvas.getContext("2d"); + ctx.clearRect(0, 0, 200, 200); + } + } + } + + function test_simpleTextureNodeUsage() { + var canvas = simpleTextureNodeUsageComponent.createObject(container); + verify(canvas); + wait(0); + // Shouldn't crash. + canvas.requestPaint(); + } } } -- cgit v1.2.3 From e3a875dedc63163c595df2d4ea642a53f5e6eb4a Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 7 Jul 2015 17:35:11 -0700 Subject: Add the GPLv3 license text LGPLv3 refers to it but does not include it in its body. Change-Id: Ib056b47dde3341ef9a52ffff13eed18cf3504738 Reviewed-by: Lars Knoll --- LICENSE.GPLv3 | 686 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ LICENSE.LGPLv3 | 2 + 2 files changed, 688 insertions(+) create mode 100644 LICENSE.GPLv3 diff --git a/LICENSE.GPLv3 b/LICENSE.GPLv3 new file mode 100644 index 0000000000..4e49b122ae --- /dev/null +++ b/LICENSE.GPLv3 @@ -0,0 +1,686 @@ + GNU GENERAL PUBLIC LICENSE + + The Qt Toolkit is Copyright (C) 2015 The Qt Company Ltd. + Contact: http://www.qt.io/licensing/ + + You may use, distribute and copy the Qt GUI Toolkit under the terms of + GNU Lesser General Public License version 3. That license references + the General Public License version 3, that is displayed below. Other + portions of the Qt Toolkit may be licensed directly under this license. + +------------------------------------------------------------------------- + + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/LICENSE.LGPLv3 b/LICENSE.LGPLv3 index 8fbb74390c..4d67bac0b4 100644 --- a/LICENSE.LGPLv3 +++ b/LICENSE.LGPLv3 @@ -5,6 +5,8 @@ You may use, distribute and copy the Qt GUI Toolkit under the terms of GNU Lesser General Public License version 3, which is displayed below. + This license makes reference to the version 3 of the GNU General + Public License, which you can find in the LICENSE.GPLv3 file. ------------------------------------------------------------------------- -- cgit v1.2.3 From 4336566e48e7853bcf91d768c70d20db5de9e174 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Tue, 11 Aug 2015 18:33:01 +0200 Subject: Support QSGGeometry::lineWidth also in the batched code path. Change-Id: Ifc664b9c718744b9549953e42ac3450a88403dea Task-number: QTBUG-47090 Reviewed-by: Laszlo Agocs --- src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp | 43 +++++++++++++---------- src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h | 1 + 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp index 63938d50a9..42b9f526d0 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp @@ -1518,6 +1518,7 @@ void Renderer::prepareOpaqueBatches() if (gni->clipList() == gnj->clipList() && gni->geometry()->drawingMode() == gnj->geometry()->drawingMode() + && (gni->geometry()->drawingMode() != GL_LINES || gni->geometry()->lineWidth() == gnj->geometry()->lineWidth()) && gni->geometry()->attributes() == gnj->geometry()->attributes() && gni->inheritedOpacity() == gnj->inheritedOpacity() && gni->activeMaterial()->type() == gnj->activeMaterial()->type() @@ -1616,6 +1617,7 @@ void Renderer::prepareAlphaBatches() if (gni->clipList() == gnj->clipList() && gni->geometry()->drawingMode() == gnj->geometry()->drawingMode() + && (gni->geometry()->drawingMode() != GL_LINES || gni->geometry()->lineWidth() == gnj->geometry()->lineWidth()) && gni->geometry()->attributes() == gnj->geometry()->attributes() && gni->inheritedOpacity() == gnj->inheritedOpacity() && gni->activeMaterial()->type() == gnj->activeMaterial()->type() @@ -2278,6 +2280,7 @@ void Renderer::renderMergedBatch(const Batch *batch) m_currentMaterial = material; QSGGeometry* g = gn->geometry(); + updateLineWidth(g); char const *const *attrNames = program->attributeNames(); for (int i=0; idrawSets.size(); ++i) { const DrawSet &draw = batch->drawSets.at(i); @@ -2408,24 +2411,7 @@ void Renderer::renderUnmergedBatch(const Batch *batch) offset += a.tupleSize * size_of_type(a.type); } - if (g->drawingMode() == GL_LINE_STRIP || g->drawingMode() == GL_LINE_LOOP || g->drawingMode() == GL_LINES) - glLineWidth(g->lineWidth()); -#if !defined(QT_OPENGL_ES_2) - else if (!QOpenGLContext::currentContext()->isOpenGLES() && g->drawingMode() == GL_POINTS) { - QOpenGLFunctions_1_0 *gl1funcs = 0; - QOpenGLFunctions_3_2_Core *gl3funcs = 0; - if (QOpenGLContext::currentContext()->format().profile() == QSurfaceFormat::CoreProfile) - gl3funcs = QOpenGLContext::currentContext()->versionFunctions(); - else - gl1funcs = QOpenGLContext::currentContext()->versionFunctions(); - Q_ASSERT(gl1funcs || gl3funcs); - if (gl1funcs) - gl1funcs->glPointSize(g->lineWidth()); - else - gl3funcs->glPointSize(g->lineWidth()); - } -#endif - + updateLineWidth(g); if (g->indexCount()) glDrawElements(g->drawingMode(), g->indexCount(), g->indexType(), iOffset); else @@ -2441,6 +2427,27 @@ void Renderer::renderUnmergedBatch(const Batch *batch) } } +void Renderer::updateLineWidth(QSGGeometry *g) +{ + if (g->drawingMode() == GL_LINE_STRIP || g->drawingMode() == GL_LINE_LOOP || g->drawingMode() == GL_LINES) + glLineWidth(g->lineWidth()); +#if !defined(QT_OPENGL_ES_2) + else if (!QOpenGLContext::currentContext()->isOpenGLES() && g->drawingMode() == GL_POINTS) { + QOpenGLFunctions_1_0 *gl1funcs = 0; + QOpenGLFunctions_3_2_Core *gl3funcs = 0; + if (QOpenGLContext::currentContext()->format().profile() == QSurfaceFormat::CoreProfile) + gl3funcs = QOpenGLContext::currentContext()->versionFunctions(); + else + gl1funcs = QOpenGLContext::currentContext()->versionFunctions(); + Q_ASSERT(gl1funcs || gl3funcs); + if (gl1funcs) + gl1funcs->glPointSize(g->lineWidth()); + else + gl3funcs->glPointSize(g->lineWidth()); + } +#endif +} + void Renderer::renderBatches() { if (Q_UNLIKELY(debug_render())) { diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h index f87dd75c8c..6b494dbaeb 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h @@ -591,6 +591,7 @@ private: void nodeWasRemoved(Node *node); void nodeWasAdded(QSGNode *node, Node *shadowParent); BatchRootInfo *batchRootInfo(Node *node); + void updateLineWidth(QSGGeometry *g); inline Batch *newBatch(); void invalidateAndRecycleBatch(Batch *b); -- cgit v1.2.3 From 521ace713d8e5230d47f3da8cd941699ca085af2 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Fri, 14 Aug 2015 11:02:28 +0200 Subject: Fix casing in Models and Views documentation. Change-Id: I461c5a55e3dbb2dc713640ec4d7aa00397a4415d Reviewed-by: Venugopal Shivashankar --- src/quick/doc/src/concepts/modelviewsdata/modelview.qdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/quick/doc/src/concepts/modelviewsdata/modelview.qdoc b/src/quick/doc/src/concepts/modelviewsdata/modelview.qdoc index 4e894e5a33..e03b3a9bf8 100644 --- a/src/quick/doc/src/concepts/modelviewsdata/modelview.qdoc +++ b/src/quick/doc/src/concepts/modelviewsdata/modelview.qdoc @@ -187,7 +187,7 @@ To visualize data, bind the view's \c model property to a model and the QML provides several types of data models among the built-in set of QML types. In addition, models can be created with Qt C++ and then made - available to the \l{QQmlEngine}{QMLEngine} for use by + available to \l{QQmlEngine} for use by QML components. For information about creating these models, visit the \l{Using C++ Models with Qt Quick Views} and \l{qtqml-typesystem-topic.html#qml-object-types} -- cgit v1.2.3 From f245fc543c479cbc69be886c5d04d4738b491060 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 17 Aug 2015 17:08:26 +0200 Subject: QmlDevTools: Define QML export macros as empty. Since QmlDevTools is a static library, no exports (Q_QML_EXPORT/Q_QML_PRIVATE_EXPORT) should be specified. Fixes link errors in qmlimportscanner and lupdate with MSVC2015: Qt5QmlDevToolsd.lib(qv4value.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: struct QV4::VTable * __cdecl QV4::Heap::Base::vtable(void)const " (__imp_?vtable@Base@Heap@QV4@@QEBAPEAUVTable@3@XZ) referenced in function "public: bool __cdecl QV4::Managed::isEqualTo(struct QV4::Managed const *)const " (?isEqualTo@Managed@QV4@@QEBA_NPEBU12@@Z) D:\dev\5-vs15-56\qt-56\qtbase\bin\qmlimportscanner.exe : fatal error LNK1120: 1 unresolved externals Change-Id: I6125b3d1eaacadba65a90047867779252dab6fbc Reviewed-by: Simon Hausmann --- src/qmldevtools/qtqmldevtoolsglobal_p.h | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/qmldevtools/qtqmldevtoolsglobal_p.h b/src/qmldevtools/qtqmldevtoolsglobal_p.h index fa8731deb6..5cbb5ece72 100644 --- a/src/qmldevtools/qtqmldevtoolsglobal_p.h +++ b/src/qmldevtools/qtqmldevtoolsglobal_p.h @@ -49,21 +49,8 @@ QT_BEGIN_NAMESPACE -#ifndef QT_STATIC -# if defined(QT_BUILD_QML_LIB) -# define Q_QML_EXPORT Q_DECL_EXPORT -# else -# define Q_QML_EXPORT Q_DECL_IMPORT -# endif -#else -# define Q_QML_EXPORT -#endif - -#if defined(QT_BUILD_QMLDEVTOOLS_LIB) || defined(QT_QMLDEVTOOLS_LIB) -# define Q_QML_PRIVATE_EXPORT -#else -# define Q_QML_PRIVATE_EXPORT Q_QML_EXPORT -#endif +#define Q_QML_EXPORT +#define Q_QML_PRIVATE_EXPORT QT_END_NAMESPACE #endif // QTQMLGLOBAL_P_H -- cgit v1.2.3 From 7e61bc92a3dccbd4c04d0a69da950cfdc32e487b Mon Sep 17 00:00:00 2001 From: Frank Meerkoetter Date: Tue, 14 Jul 2015 22:38:51 +0200 Subject: Store int/bool/double/string and sizef as QV4::Value in a Javascript array This is the first patch in a series of patches removing the QQmlVMEVariant used for the storage of non-var properties. The overall goal is to reduce the memory usage of QML. The QQmlVMEVariant has a size of 8*sizeof(void*) + sizeof(int) which is quite an overhead for types such as int/bool or double. Change-Id: I301661d134724300942911a3d75258fe45356a7a Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlvmemetaobject.cpp | 185 ++++++++++++++++++++++++++++++++++---- src/qml/qml/qqmlvmemetaobject_p.h | 20 +++++ 2 files changed, 189 insertions(+), 16 deletions(-) diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 9f02c905fc..5d8d5d0d54 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -516,7 +516,7 @@ QQmlVMEMetaObject::QQmlVMEMetaObject(QObject *obj, : object(obj), ctxt(QQmlData::get(obj, true)->outerContext), cache(cache), metaData(meta), hasAssignedMetaObjectData(false), data(0), aliasEndpoints(0), firstVarPropertyIndex(-1), - varPropertiesInitialized(false), interceptors(0), v8methods(0) + varPropertiesInitialized(false), propertiesInitialized(false), interceptors(0), v8methods(0) { QObjectPrivate *op = QObjectPrivate::get(obj); @@ -583,6 +583,134 @@ QQmlVMEMetaObject::~QQmlVMEMetaObject() qDeleteAll(varObjectGuards); } +void QQmlVMEMetaObject::writeProperty(int id, int v) +{ + if (!ensurePropertiesAllocated()) + return; + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + vp->putIndexed(id, QV4::Primitive::fromInt32(v)); +} + +void QQmlVMEMetaObject::writeProperty(int id, bool v) +{ + if (!ensurePropertiesAllocated()) + return; + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + vp->putIndexed(id, QV4::Primitive::fromBoolean(v)); +} + +void QQmlVMEMetaObject::writeProperty(int id, double v) +{ + if (!ensurePropertiesAllocated()) + return; + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + vp->putIndexed(id, QV4::Primitive::fromDouble(v)); +} + +void QQmlVMEMetaObject::writeProperty(int id, const QString& v) +{ + if (!ensurePropertiesAllocated()) + return; + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue s(scope, properties.engine()->newString(v)); + vp->putIndexed(id, s); +} + +void QQmlVMEMetaObject::writeProperty(int id, const QSizeF& v) +{ + if (!ensurePropertiesAllocated()) + return; + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, properties.engine()->newVariantObject(QVariant::fromValue(v))); + vp->putIndexed(id, sv); +} + +int QQmlVMEMetaObject::readPropertyAsInt(int id) +{ + if (!ensurePropertiesAllocated()) + return 0; + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, vp->getIndexed(id)); + if (!sv->isInt32()) { + writeProperty(id, int(0)); + return 0; + } + return sv->integerValue(); +} + +bool QQmlVMEMetaObject::readPropertyAsBool(int id) +{ + if (!ensurePropertiesAllocated()) + return false; + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, vp->getIndexed(id)); + if (!sv->isBoolean()) { + writeProperty(id, false); + return false; + } + return sv->booleanValue(); +} + +double QQmlVMEMetaObject::readPropertyAsDouble(int id) +{ + if (!ensurePropertiesAllocated()) + return 0.0; + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, vp->getIndexed(id)); + if (!sv->isDouble()) { + writeProperty(id, 0.0); + return 0.0; + } + return sv->doubleValue(); +} + +QString QQmlVMEMetaObject::readPropertyAsString(int id) +{ + if (!ensurePropertiesAllocated()) + return QString(); + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, vp->getIndexed(id)); + if (!sv->isString()) { + writeProperty(id, QString()); + return QString(); + } + return sv->stringValue()->toQString(); +} + +QSizeF QQmlVMEMetaObject::readPropertyAsSizeF(int id) +{ + if (!ensurePropertiesAllocated()) + return QSizeF(); + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, vp->getIndexed(id)); + const QV4::VariantObject *v = sv->as(); + if (!v || v->d()->data.type() != QVariant::SizeF) { + writeProperty(id, QSizeF()); + return QSizeF(); + } + return v->d()->data.value(); +} + int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) { int id = _id; @@ -689,16 +817,16 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) if (c == QMetaObject::ReadProperty) { switch(t) { case QVariant::Int: - *reinterpret_cast(a[0]) = data[id].asInt(); + *reinterpret_cast(a[0]) = readPropertyAsInt(id); break; case QVariant::Bool: - *reinterpret_cast(a[0]) = data[id].asBool(); + *reinterpret_cast(a[0]) = readPropertyAsBool(id); break; case QVariant::Double: - *reinterpret_cast(a[0]) = data[id].asDouble(); + *reinterpret_cast(a[0]) = readPropertyAsDouble(id); break; case QVariant::String: - *reinterpret_cast(a[0]) = data[id].asQString(); + *reinterpret_cast(a[0]) = readPropertyAsString(id); break; case QVariant::Url: *reinterpret_cast(a[0]) = data[id].asQUrl(); @@ -713,7 +841,7 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) *reinterpret_cast(a[0]) = data[id].asQRectF(); break; case QVariant::SizeF: - *reinterpret_cast(a[0]) = data[id].asQSizeF(); + *reinterpret_cast(a[0]) = readPropertyAsSizeF(id); break; case QVariant::PointF: *reinterpret_cast(a[0]) = data[id].asQPointF(); @@ -741,20 +869,20 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) switch(t) { case QVariant::Int: - needActivate = *reinterpret_cast(a[0]) != data[id].asInt(); - data[id].setValue(*reinterpret_cast(a[0])); + needActivate = *reinterpret_cast(a[0]) != readPropertyAsInt(id); + writeProperty(id, *reinterpret_cast(a[0])); break; case QVariant::Bool: - needActivate = *reinterpret_cast(a[0]) != data[id].asBool(); - data[id].setValue(*reinterpret_cast(a[0])); + needActivate = *reinterpret_cast(a[0]) != readPropertyAsBool(id); + writeProperty(id, *reinterpret_cast(a[0])); break; case QVariant::Double: - needActivate = *reinterpret_cast(a[0]) != data[id].asDouble(); - data[id].setValue(*reinterpret_cast(a[0])); + needActivate = *reinterpret_cast(a[0]) != readPropertyAsDouble(id); + writeProperty(id, *reinterpret_cast(a[0])); break; case QVariant::String: - needActivate = *reinterpret_cast(a[0]) != data[id].asQString(); - data[id].setValue(*reinterpret_cast(a[0])); + needActivate = *reinterpret_cast(a[0]) != readPropertyAsString(id); + writeProperty(id, *reinterpret_cast(a[0])); break; case QVariant::Url: needActivate = *reinterpret_cast(a[0]) != data[id].asQUrl(); @@ -773,8 +901,8 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) data[id].setValue(*reinterpret_cast(a[0])); break; case QVariant::SizeF: - needActivate = *reinterpret_cast(a[0]) != data[id].asQSizeF(); - data[id].setValue(*reinterpret_cast(a[0])); + needActivate = *reinterpret_cast(a[0]) != readPropertyAsSizeF(id); + writeProperty(id, *reinterpret_cast(a[0])); break; case QVariant::PointF: needActivate = *reinterpret_cast(a[0]) != data[id].asQPointF(); @@ -1176,6 +1304,19 @@ bool QQmlVMEMetaObject::ensureVarPropertiesAllocated() return !varProperties.isUndefined(); } +bool QQmlVMEMetaObject::ensurePropertiesAllocated() +{ + if (!propertiesInitialized) + allocatePropertiesArray(); + + // in some situations, the QObject's v8object (and associated v8 data, + // such as the varProperties array) will have been cleaned up, but the + // QObject ptr will not yet have been deleted (eg, waiting on deleteLater). + // In this situation, the varProperties handle will be (and should remain) + // empty. + return !properties.isUndefined(); +} + void QQmlVMEMetaObject::ensureQObjectWrapper() { Q_ASSERT(ctxt && ctxt->engine); @@ -1192,6 +1333,7 @@ void QQmlVMEMetaObject::mark(QV4::ExecutionEngine *e) return; varProperties.markOnce(e); + properties.markOnce(e); // add references created by VMEVariant properties int maxDataIdx = metaData->propertyCount - metaData->varPropertyCount; @@ -1217,6 +1359,17 @@ void QQmlVMEMetaObject::allocateVarPropertiesArray() varPropertiesInitialized = true; } +void QQmlVMEMetaObject::allocatePropertiesArray() +{ + QQmlEngine *qml = qmlEngine(object); + Q_ASSERT(qml); + QV4::ExecutionEngine *v4 = QV8Engine::getV4(qml->handle()); + QV4::Scope scope(v4); + properties.set(scope.engine, v4->newArrayObject(metaData->propertyCount - metaData->varPropertyCount)); + propertiesInitialized = true; +} + + bool QQmlVMEMetaObject::aliasTarget(int index, QObject **target, int *coreIndex, int *valueTypeIndex) const { Q_ASSERT(index >= propOffset() + metaData->propertyCount); diff --git a/src/qml/qml/qqmlvmemetaobject_p.h b/src/qml/qml/qqmlvmemetaobject_p.h index a320163f23..a87feec043 100644 --- a/src/qml/qml/qqmlvmemetaobject_p.h +++ b/src/qml/qml/qqmlvmemetaobject_p.h @@ -204,6 +204,26 @@ public: inline void allocateVarPropertiesArray(); inline bool ensureVarPropertiesAllocated(); + // temporary solution so I can experiment with storing + // properties in a JS array. Should be switched over to also + // use the 'varProperties' in the end. + QV4::WeakValue properties; + bool propertiesInitialized; + inline void allocatePropertiesArray(); + inline bool ensurePropertiesAllocated(); + + int readPropertyAsInt(int id); + bool readPropertyAsBool(int id); + double readPropertyAsDouble(int id); + QString readPropertyAsString(int id); + QSizeF readPropertyAsSizeF(int id); + + void writeProperty(int id, int v); + void writeProperty(int id, bool v); + void writeProperty(int id, double v); + void writeProperty(int id, const QString& v); + void writeProperty(int id, const QSizeF& v); + void ensureQObjectWrapper(); void mark(QV4::ExecutionEngine *e); -- cgit v1.2.3 From 496b69a6c73c354c0a440a3fc4779eb8325abc4a Mon Sep 17 00:00:00 2001 From: Frank Meerkoetter Date: Wed, 15 Jul 2015 23:13:48 +0200 Subject: Store all properties in one Javascript array Store both "normal" properties and var properties in the same js array. The second array which is removed by this patch was scaffolding for the initial brinup. Change-Id: I24f72a1d880a54f68f5562e5077dbc26e7db864a Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlvmemetaobject.cpp | 77 +++++++++++++-------------------------- src/qml/qml/qqmlvmemetaobject_p.h | 12 +----- 2 files changed, 28 insertions(+), 61 deletions(-) diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 5d8d5d0d54..a359cb72b8 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -63,14 +63,14 @@ QQmlVMEVariantQObjectPtr::~QQmlVMEVariantQObjectPtr() void QQmlVMEVariantQObjectPtr::objectDestroyed(QObject *) { if (m_target && m_index >= 0) { - if (m_isVar && m_target->varPropertiesInitialized && !m_target->varProperties.isUndefined()) { + if (m_isVar && m_target->propertiesInitialized && !m_target->properties.isUndefined()) { // Set the var property to NULL - QV4::ExecutionEngine *v4 = m_target->varProperties.engine(); + QV4::ExecutionEngine *v4 = m_target->properties.engine(); if (v4) { QV4::Scope scope(v4); - QV4::ScopedArrayObject a(scope, m_target->varProperties.value()); + QV4::ScopedArrayObject a(scope, m_target->properties.value()); if (a) - a->putIndexed(m_index - m_target->firstVarPropertyIndex, QV4::ScopedValue(scope, QV4::Primitive::nullValue())); + a->putIndexed(m_index, QV4::ScopedValue(scope, QV4::Primitive::nullValue())); } } @@ -516,7 +516,7 @@ QQmlVMEMetaObject::QQmlVMEMetaObject(QObject *obj, : object(obj), ctxt(QQmlData::get(obj, true)->outerContext), cache(cache), metaData(meta), hasAssignedMetaObjectData(false), data(0), aliasEndpoints(0), firstVarPropertyIndex(-1), - varPropertiesInitialized(false), propertiesInitialized(false), interceptors(0), v8methods(0) + propertiesInitialized(false), interceptors(0), v8methods(0) { QObjectPrivate *op = QObjectPrivate::get(obj); @@ -1074,10 +1074,10 @@ QV4::ReturnedValue QQmlVMEMetaObject::readVarProperty(int id) { Q_ASSERT(id >= firstVarPropertyIndex); - if (ensureVarPropertiesAllocated()) { - QV4::Scope scope(varProperties.engine()); - QV4::ScopedObject o(scope, varProperties.value()); - return o->getIndexed(id - firstVarPropertyIndex); + if (ensurePropertiesAllocated()) { + QV4::Scope scope(properties.engine()); + QV4::ScopedObject o(scope, properties.value()); + return o->getIndexed(id); } return QV4::Primitive::undefinedValue().asReturnedValue(); } @@ -1085,11 +1085,11 @@ QV4::ReturnedValue QQmlVMEMetaObject::readVarProperty(int id) QVariant QQmlVMEMetaObject::readPropertyAsVariant(int id) { if (id >= firstVarPropertyIndex) { - if (ensureVarPropertiesAllocated()) { - QV4::ExecutionEngine *v4 = varProperties.engine(); + if (ensurePropertiesAllocated()) { + QV4::ExecutionEngine *v4 = properties.engine(); QV4::Scope scope(v4); - QV4::ScopedObject o(scope, varProperties.value()); - QV4::ScopedValue val(scope, o->getIndexed(id - firstVarPropertyIndex)); + QV4::ScopedObject o(scope, properties.value()); + QV4::ScopedValue val(scope, o->getIndexed(id)); return scope.engine->toVariant(val, -1); } return QVariant(); @@ -1105,14 +1105,14 @@ QVariant QQmlVMEMetaObject::readPropertyAsVariant(int id) void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::Value &value) { Q_ASSERT(id >= firstVarPropertyIndex); - if (!ensureVarPropertiesAllocated()) + if (!ensurePropertiesAllocated()) return; - QV4::Scope scope(varProperties.engine()); + QV4::Scope scope(properties.engine()); // Importantly, if the current value is a scarce resource, we need to ensure that it // gets automatically released by the engine if no other references to it exist. - QV4::ScopedObject vp(scope, varProperties.value()); - QV4::Scoped oldv(scope, vp->getIndexed(id - firstVarPropertyIndex)); + QV4::ScopedObject vp(scope, properties.value()); + QV4::Scoped oldv(scope, vp->getIndexed(id)); if (!!oldv) oldv->removeVmePropertyReference(); @@ -1142,22 +1142,22 @@ void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::Value &value) } // Write the value and emit change signal as appropriate. - vp->putIndexed(id - firstVarPropertyIndex, value); + vp->putIndexed(id, value); activate(object, methodOffset() + id, 0); } void QQmlVMEMetaObject::writeProperty(int id, const QVariant &value) { if (id >= firstVarPropertyIndex) { - if (!ensureVarPropertiesAllocated()) + if (!ensurePropertiesAllocated()) return; - QV4::Scope scope(varProperties.engine()); + QV4::Scope scope(properties.engine()); // Importantly, if the current value is a scarce resource, we need to ensure that it // gets automatically released by the engine if no other references to it exist. - QV4::ScopedObject vp(scope, varProperties.value()); - QV4::Scoped oldv(scope, vp->getIndexed(id - firstVarPropertyIndex)); + QV4::ScopedObject vp(scope, properties.value()); + QV4::Scoped oldv(scope, vp->getIndexed(id)); if (!!oldv) oldv->removeVmePropertyReference(); @@ -1170,7 +1170,7 @@ void QQmlVMEMetaObject::writeProperty(int id, const QVariant &value) // Write the value and emit change signal as appropriate. QVariant currentValue = readPropertyAsVariant(id); - vp->putIndexed(id - firstVarPropertyIndex, newv); + vp->putIndexed(id, newv); if ((currentValue.userType() != value.userType() || currentValue != value)) activate(object, methodOffset() + id, 0); } else { @@ -1291,23 +1291,10 @@ void QQmlVMEMetaObject::setVMEProperty(int index, const QV4::Value &v) return writeVarProperty(index - propOffset(), v); } -bool QQmlVMEMetaObject::ensureVarPropertiesAllocated() -{ - if (!varPropertiesInitialized) - allocateVarPropertiesArray(); - - // in some situations, the QObject's v8object (and associated v8 data, - // such as the varProperties array) will have been cleaned up, but the - // QObject ptr will not yet have been deleted (eg, waiting on deleteLater). - // In this situation, the varProperties handle will be (and should remain) - // empty. - return !varProperties.isUndefined(); -} - bool QQmlVMEMetaObject::ensurePropertiesAllocated() { if (!propertiesInitialized) - allocatePropertiesArray(); + allocateProperties(); // in some situations, the QObject's v8object (and associated v8 data, // such as the varProperties array) will have been cleaned up, but the @@ -1332,7 +1319,6 @@ void QQmlVMEMetaObject::mark(QV4::ExecutionEngine *e) if (v4 != e) return; - varProperties.markOnce(e); properties.markOnce(e); // add references created by VMEVariant properties @@ -1349,27 +1335,16 @@ void QQmlVMEMetaObject::mark(QV4::ExecutionEngine *e) parent->mark(e); } -void QQmlVMEMetaObject::allocateVarPropertiesArray() -{ - QQmlEngine *qml = qmlEngine(object); - Q_ASSERT(qml); - QV4::ExecutionEngine *v4 = QV8Engine::getV4(qml->handle()); - QV4::Scope scope(v4); - varProperties.set(scope.engine, v4->newArrayObject(metaData->varPropertyCount)); - varPropertiesInitialized = true; -} - -void QQmlVMEMetaObject::allocatePropertiesArray() +void QQmlVMEMetaObject::allocateProperties() { QQmlEngine *qml = qmlEngine(object); Q_ASSERT(qml); QV4::ExecutionEngine *v4 = QV8Engine::getV4(qml->handle()); QV4::Scope scope(v4); - properties.set(scope.engine, v4->newArrayObject(metaData->propertyCount - metaData->varPropertyCount)); + properties.set(scope.engine, v4->newArrayObject(metaData->propertyCount)); propertiesInitialized = true; } - bool QQmlVMEMetaObject::aliasTarget(int index, QObject **target, int *coreIndex, int *valueTypeIndex) const { Q_ASSERT(index >= propOffset() + metaData->propertyCount); diff --git a/src/qml/qml/qqmlvmemetaobject_p.h b/src/qml/qml/qqmlvmemetaobject_p.h index a87feec043..c4ca128e87 100644 --- a/src/qml/qml/qqmlvmemetaobject_p.h +++ b/src/qml/qml/qqmlvmemetaobject_p.h @@ -198,18 +198,10 @@ public: QQmlVMEVariant *data; QQmlVMEMetaObjectEndpoint *aliasEndpoints; - QV4::WeakValue varProperties; - int firstVarPropertyIndex; - bool varPropertiesInitialized; - inline void allocateVarPropertiesArray(); - inline bool ensureVarPropertiesAllocated(); - - // temporary solution so I can experiment with storing - // properties in a JS array. Should be switched over to also - // use the 'varProperties' in the end. QV4::WeakValue properties; + int firstVarPropertyIndex; bool propertiesInitialized; - inline void allocatePropertiesArray(); + inline void allocateProperties(); inline bool ensurePropertiesAllocated(); int readPropertyAsInt(int id); -- cgit v1.2.3 From 0cbab3b17fb70208476b910d7d82ae653a9a1050 Mon Sep 17 00:00:00 2001 From: Frank Meerkoetter Date: Thu, 16 Jul 2015 22:04:39 +0200 Subject: Port QUrl/QSizeF away from QQmlVmeVariant Store QUrl/QSizeF in a javascript array. The values are wrapped inside a QV4::Variant. This is part of a series sliming down the memory usage of properties. Change-Id: I62338fe7fe101496340a8d89f33030d0df5121b7 Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlvmemetaobject.cpp | 67 +++++++++++++++++++++++++++++++++++---- src/qml/qml/qqmlvmemetaobject_p.h | 4 +++ 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index a359cb72b8..60f56dff5f 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -624,6 +624,28 @@ void QQmlVMEMetaObject::writeProperty(int id, const QString& v) vp->putIndexed(id, s); } +void QQmlVMEMetaObject::writeProperty(int id, const QUrl& v) +{ + if (!ensurePropertiesAllocated()) + return; + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, properties.engine()->newVariantObject(QVariant::fromValue(v))); + vp->putIndexed(id, sv); +} + +void QQmlVMEMetaObject::writeProperty(int id, const QPointF& v) +{ + if (!ensurePropertiesAllocated()) + return; + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, properties.engine()->newVariantObject(QVariant::fromValue(v))); + vp->putIndexed(id, sv); +} + void QQmlVMEMetaObject::writeProperty(int id, const QSizeF& v) { if (!ensurePropertiesAllocated()) @@ -695,6 +717,22 @@ QString QQmlVMEMetaObject::readPropertyAsString(int id) return sv->stringValue()->toQString(); } +QUrl QQmlVMEMetaObject::readPropertyAsUrl(int id) +{ + if (!ensurePropertiesAllocated()) + return QUrl(); + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, vp->getIndexed(id)); + const QV4::VariantObject *v = sv->as(); + if (!v || v->d()->data.type() != QVariant::Url) { + writeProperty(id, QUrl()); + return QUrl(); + } + return v->d()->data.value(); +} + QSizeF QQmlVMEMetaObject::readPropertyAsSizeF(int id) { if (!ensurePropertiesAllocated()) @@ -711,6 +749,23 @@ QSizeF QQmlVMEMetaObject::readPropertyAsSizeF(int id) return v->d()->data.value(); } +QPointF QQmlVMEMetaObject::readPropertyAsPointF(int id) +{ + if (!ensurePropertiesAllocated()) + return QPointF(); + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, vp->getIndexed(id)); + const QV4::VariantObject *v = sv->as(); + if (!v || v->d()->data.type() != QVariant::PointF) { + writeProperty(id, QPointF()); + return QPointF(); + } + return v->d()->data.value(); +} + + int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) { int id = _id; @@ -829,7 +884,7 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) *reinterpret_cast(a[0]) = readPropertyAsString(id); break; case QVariant::Url: - *reinterpret_cast(a[0]) = data[id].asQUrl(); + *reinterpret_cast(a[0]) = readPropertyAsUrl(id); break; case QVariant::Date: *reinterpret_cast(a[0]) = data[id].asQDate(); @@ -844,7 +899,7 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) *reinterpret_cast(a[0]) = readPropertyAsSizeF(id); break; case QVariant::PointF: - *reinterpret_cast(a[0]) = data[id].asQPointF(); + *reinterpret_cast(a[0]) = readPropertyAsPointF(id); break; case QMetaType::QObjectStar: *reinterpret_cast(a[0]) = data[id].asQObject(); @@ -885,8 +940,8 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) writeProperty(id, *reinterpret_cast(a[0])); break; case QVariant::Url: - needActivate = *reinterpret_cast(a[0]) != data[id].asQUrl(); - data[id].setValue(*reinterpret_cast(a[0])); + needActivate = *reinterpret_cast(a[0]) != readPropertyAsUrl(id); + writeProperty(id, *reinterpret_cast(a[0])); break; case QVariant::Date: needActivate = *reinterpret_cast(a[0]) != data[id].asQDate(); @@ -905,8 +960,8 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) writeProperty(id, *reinterpret_cast(a[0])); break; case QVariant::PointF: - needActivate = *reinterpret_cast(a[0]) != data[id].asQPointF(); - data[id].setValue(*reinterpret_cast(a[0])); + needActivate = *reinterpret_cast(a[0]) != readPropertyAsPointF(id); + writeProperty(id, *reinterpret_cast(a[0])); break; case QMetaType::QObjectStar: needActivate = *reinterpret_cast(a[0]) != data[id].asQObject(); diff --git a/src/qml/qml/qqmlvmemetaobject_p.h b/src/qml/qml/qqmlvmemetaobject_p.h index c4ca128e87..445b54e61c 100644 --- a/src/qml/qml/qqmlvmemetaobject_p.h +++ b/src/qml/qml/qqmlvmemetaobject_p.h @@ -209,12 +209,16 @@ public: double readPropertyAsDouble(int id); QString readPropertyAsString(int id); QSizeF readPropertyAsSizeF(int id); + QPointF readPropertyAsPointF(int id); + QUrl readPropertyAsUrl(int id); void writeProperty(int id, int v); void writeProperty(int id, bool v); void writeProperty(int id, double v); void writeProperty(int id, const QString& v); + void writeProperty(int id, const QPointF& v); void writeProperty(int id, const QSizeF& v); + void writeProperty(int id, const QUrl& v); void ensureQObjectWrapper(); -- cgit v1.2.3 From 0720dea139e735b3438968f42c9abf7b198cd69b Mon Sep 17 00:00:00 2001 From: Frank Meerkoetter Date: Thu, 16 Jul 2015 22:34:42 +0200 Subject: Port QDate/QDateTime/QRectF away from QQmlVmeVariant Store QDate/QDateTime/QRectF in a javascript array. The values are wrapped inside a QV4::Variant. This is part of a series sliming down the memory usage of properties. Change-Id: I1b5c4e24c1e46d19c5c861941655efb7a972a6a5 Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlvmemetaobject.cpp | 99 +++++++++++++++++++++++++++++++++++---- src/qml/qml/qqmlvmemetaobject_p.h | 6 +++ 2 files changed, 96 insertions(+), 9 deletions(-) diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 60f56dff5f..d4ad0f2a9a 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -635,6 +635,29 @@ void QQmlVMEMetaObject::writeProperty(int id, const QUrl& v) vp->putIndexed(id, sv); } +// TODO: can we store the QDate in a QV4::Value primitive? +void QQmlVMEMetaObject::writeProperty(int id, const QDate& v) +{ + if (!ensurePropertiesAllocated()) + return; + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, properties.engine()->newVariantObject(QVariant::fromValue(v))); + vp->putIndexed(id, sv); +} + +void QQmlVMEMetaObject::writeProperty(int id, const QDateTime& v) +{ + if (!ensurePropertiesAllocated()) + return; + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, properties.engine()->newVariantObject(QVariant::fromValue(v))); + vp->putIndexed(id, sv); +} + void QQmlVMEMetaObject::writeProperty(int id, const QPointF& v) { if (!ensurePropertiesAllocated()) @@ -657,6 +680,17 @@ void QQmlVMEMetaObject::writeProperty(int id, const QSizeF& v) vp->putIndexed(id, sv); } +void QQmlVMEMetaObject::writeProperty(int id, const QRectF& v) +{ + if (!ensurePropertiesAllocated()) + return; + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, properties.engine()->newVariantObject(QVariant::fromValue(v))); + vp->putIndexed(id, sv); +} + int QQmlVMEMetaObject::readPropertyAsInt(int id) { if (!ensurePropertiesAllocated()) @@ -733,6 +767,38 @@ QUrl QQmlVMEMetaObject::readPropertyAsUrl(int id) return v->d()->data.value(); } +QDate QQmlVMEMetaObject::readPropertyAsDate(int id) +{ + if (!ensurePropertiesAllocated()) + return QDate(); + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, vp->getIndexed(id)); + const QV4::VariantObject *v = sv->as(); + if (!v || v->d()->data.type() != QVariant::Date) { + writeProperty(id, QDate()); + return QDate(); + } + return v->d()->data.value(); +} + +QDateTime QQmlVMEMetaObject::readPropertyAsDateTime(int id) +{ + if (!ensurePropertiesAllocated()) + return QDateTime(); + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, vp->getIndexed(id)); + const QV4::VariantObject *v = sv->as(); + if (!v || v->d()->data.type() != QVariant::DateTime) { + writeProperty(id, QDateTime()); + return QDateTime(); + } + return v->d()->data.value(); +} + QSizeF QQmlVMEMetaObject::readPropertyAsSizeF(int id) { if (!ensurePropertiesAllocated()) @@ -765,6 +831,21 @@ QPointF QQmlVMEMetaObject::readPropertyAsPointF(int id) return v->d()->data.value(); } +QRectF QQmlVMEMetaObject::readPropertyAsRectF(int id) +{ + if (!ensurePropertiesAllocated()) + return QRectF(); + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, vp->getIndexed(id)); + const QV4::VariantObject *v = sv->as(); + if (!v || v->d()->data.type() != QVariant::RectF) { + writeProperty(id, QRectF()); + return QRectF(); + } + return v->d()->data.value(); +} int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) { @@ -887,13 +968,13 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) *reinterpret_cast(a[0]) = readPropertyAsUrl(id); break; case QVariant::Date: - *reinterpret_cast(a[0]) = data[id].asQDate(); + *reinterpret_cast(a[0]) = readPropertyAsDate(id); break; case QVariant::DateTime: - *reinterpret_cast(a[0]) = data[id].asQDateTime(); + *reinterpret_cast(a[0]) = readPropertyAsDateTime(id); break; case QVariant::RectF: - *reinterpret_cast(a[0]) = data[id].asQRectF(); + *reinterpret_cast(a[0]) = readPropertyAsRectF(id); break; case QVariant::SizeF: *reinterpret_cast(a[0]) = readPropertyAsSizeF(id); @@ -944,16 +1025,16 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) writeProperty(id, *reinterpret_cast(a[0])); break; case QVariant::Date: - needActivate = *reinterpret_cast(a[0]) != data[id].asQDate(); - data[id].setValue(*reinterpret_cast(a[0])); + needActivate = *reinterpret_cast(a[0]) != readPropertyAsDate(id); + writeProperty(id, *reinterpret_cast(a[0])); break; case QVariant::DateTime: - needActivate = *reinterpret_cast(a[0]) != data[id].asQDateTime(); - data[id].setValue(*reinterpret_cast(a[0])); + needActivate = *reinterpret_cast(a[0]) != readPropertyAsDateTime(id); + writeProperty(id, *reinterpret_cast(a[0])); break; case QVariant::RectF: - needActivate = *reinterpret_cast(a[0]) != data[id].asQRectF(); - data[id].setValue(*reinterpret_cast(a[0])); + needActivate = *reinterpret_cast(a[0]) != readPropertyAsRectF(id); + writeProperty(id, *reinterpret_cast(a[0])); break; case QVariant::SizeF: needActivate = *reinterpret_cast(a[0]) != readPropertyAsSizeF(id); diff --git a/src/qml/qml/qqmlvmemetaobject_p.h b/src/qml/qml/qqmlvmemetaobject_p.h index 445b54e61c..96b606203a 100644 --- a/src/qml/qml/qqmlvmemetaobject_p.h +++ b/src/qml/qml/qqmlvmemetaobject_p.h @@ -211,6 +211,9 @@ public: QSizeF readPropertyAsSizeF(int id); QPointF readPropertyAsPointF(int id); QUrl readPropertyAsUrl(int id); + QDate readPropertyAsDate(int id); + QDateTime readPropertyAsDateTime(int id); + QRectF readPropertyAsRectF(int id); void writeProperty(int id, int v); void writeProperty(int id, bool v); @@ -219,6 +222,9 @@ public: void writeProperty(int id, const QPointF& v); void writeProperty(int id, const QSizeF& v); void writeProperty(int id, const QUrl& v); + void writeProperty(int id, const QDate& v); + void writeProperty(int id, const QDateTime& v); + void writeProperty(int id, const QRectF& v); void ensureQObjectWrapper(); -- cgit v1.2.3 From 7a4967986ed5cfa3418bdd53a8ea8a34e100241a Mon Sep 17 00:00:00 2001 From: Frank Meerkoetter Date: Mon, 20 Jul 2015 20:35:34 +0200 Subject: Port list properties away from QQmlVmeVariant The index into the list of list properties (an int) is now also stored as a QV4::Value. Change-Id: I16809c5027ed3c4264aab6dfed8b4519adf83e2a Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlvmemetaobject.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index d4ad0f2a9a..1e60b593f1 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -546,7 +546,7 @@ QQmlVMEMetaObject::QQmlVMEMetaObject(QObject *obj, int t = (metaData->propertyData() + ii)->propertyType; if (t == list_type) { listProperties.append(List(methodOffset() + ii, this)); - data[ii].setValue(listProperties.count() - 1); + writeProperty(ii, listProperties.count() - 1); } else if (!needsJSWrapper && (t == qobject_type || t == variant_type)) { needsJSWrapper = true; } @@ -993,7 +993,7 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) break; } if (t == qMetaTypeId >()) { - int listIndex = data[id].asInt(); + const int listIndex = readPropertyAsInt(id); const List *list = &listProperties.at(listIndex); *reinterpret_cast *>(a[0]) = QQmlListProperty(object, const_cast(list), -- cgit v1.2.3 From eeb466a3b9208dd25b2bd7003d03c264f0a4f4a7 Mon Sep 17 00:00:00 2001 From: Frank Meerkoetter Date: Mon, 20 Jul 2015 20:47:22 +0200 Subject: Remove QQmlValueTypeProvider::copyValueType While reworking the QQmlValueTypeProvider interface I noticed that this code isn't used. Change-Id: I30a279ffabf3a1c70eaa1327e69b774f5e5981f0 Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlglobal.cpp | 15 -------------- src/qml/qml/qqmlglobal_p.h | 2 -- src/quick/util/qquickglobal.cpp | 43 ----------------------------------------- 3 files changed, 60 deletions(-) diff --git a/src/qml/qml/qqmlglobal.cpp b/src/qml/qml/qqmlglobal.cpp index 0a2f4079c2..2e772eaaf0 100644 --- a/src/qml/qml/qqmlglobal.cpp +++ b/src/qml/qml/qqmlglobal.cpp @@ -88,20 +88,6 @@ bool QQmlValueTypeProvider::destroyValueType(int type, void *data, size_t n) return false; } -bool QQmlValueTypeProvider::copyValueType(int type, const void *src, void *dst, size_t n) -{ - Q_ASSERT(src); - Q_ASSERT(dst); - - QQmlValueTypeProvider *p = this; - do { - if (p->copy(type, src, dst, n)) - return true; - } while ((p = p->next)); - - return false; -} - QVariant QQmlValueTypeProvider::createValueType(int type, int argc, const void *argv[]) { QVariant v; @@ -247,7 +233,6 @@ bool QQmlValueTypeProvider::writeValueType(int type, const void *src, void *dst, const QMetaObject *QQmlValueTypeProvider::getMetaObjectForMetaType(int) { return 0; } bool QQmlValueTypeProvider::init(int, void *, size_t) { return false; } bool QQmlValueTypeProvider::destroy(int, void *, size_t) { return false; } -bool QQmlValueTypeProvider::copy(int, const void *, void *, size_t) { return false; } bool QQmlValueTypeProvider::create(int, int, const void *[], QVariant *) { return false; } bool QQmlValueTypeProvider::createFromString(int, const QString &, void *, size_t) { return false; } bool QQmlValueTypeProvider::createStringFrom(int, const void *, QString *) { return false; } diff --git a/src/qml/qml/qqmlglobal_p.h b/src/qml/qml/qqmlglobal_p.h index 7856d85376..8ed044d2c9 100644 --- a/src/qml/qml/qqmlglobal_p.h +++ b/src/qml/qml/qqmlglobal_p.h @@ -226,7 +226,6 @@ public: bool initValueType(int, void *, size_t); bool destroyValueType(int, void *, size_t); - bool copyValueType(int, const void *, void *, size_t); QVariant createValueType(int, int, const void *[]); bool createValueFromString(int, const QString &, void *, size_t); @@ -245,7 +244,6 @@ private: virtual const QMetaObject *getMetaObjectForMetaType(int); virtual bool init(int, void *, size_t); virtual bool destroy(int, void *, size_t); - virtual bool copy(int, const void *, void *, size_t); virtual bool create(int, int, const void *[], QVariant *); virtual bool createFromString(int, const QString &, void *, size_t); diff --git a/src/quick/util/qquickglobal.cpp b/src/quick/util/qquickglobal.cpp index 0680a49d6d..fd172006e0 100644 --- a/src/quick/util/qquickglobal.cpp +++ b/src/quick/util/qquickglobal.cpp @@ -479,49 +479,6 @@ public: return false; } - template - bool typedCopyConstruct(const void *src, void *dst, size_t dstSize) - { - ASSERT_VALID_SIZE(dstSize, sizeof(T)); - const T *srcT = reinterpret_cast(src); - T *destT = reinterpret_cast(dst); - new (destT) T(*srcT); - return true; - } - - bool copy(int type, const void *src, void *dst, size_t dstSize) - { - switch (type) { - case QMetaType::QColor: - return typedCopyConstruct(src, dst, dstSize); - case QMetaType::QFont: - return typedCopyConstruct(src, dst, dstSize); - case QMetaType::QVector2D: - return typedCopyConstruct(src, dst, dstSize); - case QMetaType::QVector3D: - return typedCopyConstruct(src, dst, dstSize); - case QMetaType::QVector4D: - return typedCopyConstruct(src, dst, dstSize); - case QMetaType::QQuaternion: - return typedCopyConstruct(src, dst, dstSize); - case QMetaType::QMatrix4x4: - { - if (dstSize >= sizeof(QMatrix4x4)) - return typedCopyConstruct(src, dst, dstSize); - - // special case: copying matrix into variant. - Q_ASSERT(dstSize >= sizeof(QVariant)); - const QMatrix4x4 *srcMatrix = reinterpret_cast(src); - QVariant *dstMatrixVar = reinterpret_cast(dst); - new (dstMatrixVar) QVariant(*srcMatrix); - return true; - } - default: break; - } - - return false; - } - bool create(int type, int argc, const void *argv[], QVariant *v) { switch (type) { -- cgit v1.2.3 From d40b206b734ca001819129b92ff270bfe2ea1942 Mon Sep 17 00:00:00 2001 From: Frank Meerkoetter Date: Mon, 20 Jul 2015 22:06:40 +0200 Subject: Port QObject* away from QQmlVMEVariant QObjects are now stored as QV4::QObjectWrapper in a javascript array. This is part of a series of patches slimming down the memory usage of QML properties. Change-Id: I270831d0f0f7bc17842cd2f8d2eb9661e09a3364 Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlvmemetaobject.cpp | 70 ++++++++++++++++++++++++++++----------- src/qml/qml/qqmlvmemetaobject_p.h | 4 ++- 2 files changed, 54 insertions(+), 20 deletions(-) diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 1e60b593f1..39ddaa5e32 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -691,6 +691,27 @@ void QQmlVMEMetaObject::writeProperty(int id, const QRectF& v) vp->putIndexed(id, sv); } +void QQmlVMEMetaObject::writeProperty(int id, QObject* v) +{ + if (!ensurePropertiesAllocated()) + return; + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + + QQmlEnginePrivate *ep = QQmlEnginePrivate::get(ctxt->engine); + QV4::ExecutionEngine *v4 = ep->v4engine(); + vp->putIndexed(id, QV4::ScopedObject(scope, QV4::QObjectWrapper::wrap(v4, v))); + + QQmlVMEVariantQObjectPtr *guard = getQObjectGuardForProperty(id); + if (v && !guard) { + guard = new QQmlVMEVariantQObjectPtr(true); + varObjectGuards.append(guard); + } + if (guard) + guard->setGuardedValue(v, this, id); +} + int QQmlVMEMetaObject::readPropertyAsInt(int id) { if (!ensurePropertiesAllocated()) @@ -831,6 +852,22 @@ QPointF QQmlVMEMetaObject::readPropertyAsPointF(int id) return v->d()->data.value(); } +QObject* QQmlVMEMetaObject::readPropertyAsQObject(int id) +{ + if (!ensurePropertiesAllocated()) + return 0; + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, vp->getIndexed(id)); + const QV4::QObjectWrapper *wrapper = sv->as(); + if (!wrapper) { + writeProperty(id, static_cast(Q_NULLPTR)); + return 0; + } + return wrapper->object(); +} + QRectF QQmlVMEMetaObject::readPropertyAsRectF(int id) { if (!ensurePropertiesAllocated()) @@ -983,7 +1020,7 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) *reinterpret_cast(a[0]) = readPropertyAsPointF(id); break; case QMetaType::QObjectStar: - *reinterpret_cast(a[0]) = data[id].asQObject(); + *reinterpret_cast(a[0]) = readPropertyAsQObject(id); break; case QMetaType::QVariant: *reinterpret_cast(a[0]) = readPropertyAsVariant(id); @@ -1045,8 +1082,8 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) writeProperty(id, *reinterpret_cast(a[0])); break; case QMetaType::QObjectStar: - needActivate = *reinterpret_cast(a[0]) != data[id].asQObject(); - data[id].setValue(*reinterpret_cast(a[0]), this, id); + needActivate = *reinterpret_cast(a[0]) != readPropertyAsQObject(id); + writeProperty(id, *reinterpret_cast(a[0])); break; case QMetaType::QVariant: writeProperty(id, *reinterpret_cast(a[0])); @@ -1230,11 +1267,16 @@ QVariant QQmlVMEMetaObject::readPropertyAsVariant(int id) } return QVariant(); } else { - if (data[id].dataType() == QMetaType::QObjectStar) { - return QVariant::fromValue(data[id].asQObject()); - } else { - return data[id].asQVariant(); + if (ensurePropertiesAllocated()) { + QV4::ExecutionEngine *v4 = properties.engine(); + QV4::Scope scope(v4); + QV4::ScopedObject o(scope, properties.value()); + QV4::ScopedValue sv(scope, o->getIndexed(id)); + const QV4::QObjectWrapper *wrapper = sv->as(); + if (wrapper) + return QVariant::fromValue(wrapper->object()); } + return data[id].asQVariant(); } } @@ -1313,8 +1355,8 @@ void QQmlVMEMetaObject::writeProperty(int id, const QVariant &value) bool needActivate = false; if (value.userType() == QMetaType::QObjectStar) { QObject *o = *(QObject *const *)value.data(); - needActivate = (data[id].dataType() != QMetaType::QObjectStar || data[id].asQObject() != o); - data[id].setValue(o, this, id); + needActivate = readPropertyAsQObject(id) != o; // TODO: still correct? + writeProperty(id, o); } else { needActivate = (data[id].dataType() != qMetaTypeId() || data[id].asQVariant().userType() != value.userType() || @@ -1457,16 +1499,6 @@ void QQmlVMEMetaObject::mark(QV4::ExecutionEngine *e) properties.markOnce(e); - // add references created by VMEVariant properties - int maxDataIdx = metaData->propertyCount - metaData->varPropertyCount; - for (int ii = 0; ii < maxDataIdx; ++ii) { // XXX TODO: optimize? - if (data[ii].dataType() == QMetaType::QObjectStar) { - // possible QObject reference. - if (QObject *ref = data[ii].asQObject()) - QV4::QObjectWrapper::markWrapper(ref, e); - } - } - if (QQmlVMEMetaObject *parent = parentVMEMetaObject()) parent->mark(e); } diff --git a/src/qml/qml/qqmlvmemetaobject_p.h b/src/qml/qml/qqmlvmemetaobject_p.h index 96b606203a..7009b47a5f 100644 --- a/src/qml/qml/qqmlvmemetaobject_p.h +++ b/src/qml/qml/qqmlvmemetaobject_p.h @@ -142,7 +142,7 @@ public: inline void setGuardedValue(QObject *obj, QQmlVMEMetaObject *target, int index); QQmlVMEMetaObject *m_target; - unsigned m_isVar : 1; + unsigned m_isVar : 1; // TODO: remove? int m_index : 31; }; @@ -214,6 +214,7 @@ public: QDate readPropertyAsDate(int id); QDateTime readPropertyAsDateTime(int id); QRectF readPropertyAsRectF(int id); + QObject* readPropertyAsQObject(int id); void writeProperty(int id, int v); void writeProperty(int id, bool v); @@ -225,6 +226,7 @@ public: void writeProperty(int id, const QDate& v); void writeProperty(int id, const QDateTime& v); void writeProperty(int id, const QRectF& v); + void writeProperty(int id, QObject *v); void ensureQObjectWrapper(); -- cgit v1.2.3 From 44ac9e797ce30c1c9f6af704a7677fe0c9ac5794 Mon Sep 17 00:00:00 2001 From: Frank Meerkoetter Date: Fri, 24 Jul 2015 22:33:23 +0200 Subject: Port QVariant away from QQmlVMEVariant QVariants are now stored as QV4::VariantObject inside a javascript array. Change-Id: Idcc65eed6845b561038e224d74e5efdf0c9e1c28 Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlvmemetaobject.cpp | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 39ddaa5e32..0d10550fab 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -1265,7 +1265,6 @@ QVariant QQmlVMEMetaObject::readPropertyAsVariant(int id) QV4::ScopedValue val(scope, o->getIndexed(id)); return scope.engine->toVariant(val, -1); } - return QVariant(); } else { if (ensurePropertiesAllocated()) { QV4::ExecutionEngine *v4 = properties.engine(); @@ -1275,9 +1274,15 @@ QVariant QQmlVMEMetaObject::readPropertyAsVariant(int id) const QV4::QObjectWrapper *wrapper = sv->as(); if (wrapper) return QVariant::fromValue(wrapper->object()); + const QV4::VariantObject *v = sv->as(); + if (!v) { + writeProperty(id, QVariant()); + return QVariant(); + } + return v->d()->data; } - return data[id].asQVariant(); } + return QVariant(); } void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::Value &value) @@ -1358,10 +1363,22 @@ void QQmlVMEMetaObject::writeProperty(int id, const QVariant &value) needActivate = readPropertyAsQObject(id) != o; // TODO: still correct? writeProperty(id, o); } else { - needActivate = (data[id].dataType() != qMetaTypeId() || - data[id].asQVariant().userType() != value.userType() || - data[id].asQVariant() != value); - data[id].setValue(value); + if (ensurePropertiesAllocated()) { + QV4::ExecutionEngine *v4 = properties.engine(); + QV4::Scope scope(v4); + QV4::ScopedObject o(scope, properties.value()); + QV4::ScopedValue sv(scope, o->getIndexed(id)); + QV4::VariantObject *v = sv->as(); + needActivate = (!v || + v->d()->data.userType() != value.userType() || + v->d()->data != value); + if (v) + v->removeVmePropertyReference(); + + QV4::Scoped svo(scope, properties.engine()->newVariantObject(value)); + svo->addVmePropertyReference(); + o->putIndexed(id, svo); + } } if (needActivate) -- cgit v1.2.3 From 37fbe667e6b5a528592b244124189981ba4aada9 Mon Sep 17 00:00:00 2001 From: Frank Meerkoetter Date: Sat, 25 Jul 2015 19:43:43 +0200 Subject: Adapt the ValueTypeProvider interface and port its types The ValueTypeProvider system allows non-QML modules to add new basic QML types. It needs to be changed when porting away from QQmlVmeVariant as underlying type of properties. Change-Id: I2b52d7e6f578647a39832896c28553404b9a679f Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlglobal.cpp | 29 ++++----- src/qml/qml/qqmlglobal_p.h | 16 ++--- src/qml/qml/qqmlvmemetaobject.cpp | 35 ++++++++-- src/quick/util/qquickglobal.cpp | 132 ++++++++++++-------------------------- 4 files changed, 90 insertions(+), 122 deletions(-) diff --git a/src/qml/qml/qqmlglobal.cpp b/src/qml/qml/qqmlglobal.cpp index 2e772eaaf0..17de696af3 100644 --- a/src/qml/qml/qqmlglobal.cpp +++ b/src/qml/qml/qqmlglobal.cpp @@ -62,13 +62,11 @@ const QMetaObject *QQmlValueTypeProvider::metaObjectForMetaType(int type) return 0; } -bool QQmlValueTypeProvider::initValueType(int type, void *data, size_t n) +bool QQmlValueTypeProvider::initValueType(int type, QVariant& dst) { - Q_ASSERT(data); - QQmlValueTypeProvider *p = this; do { - if (p->init(type, data, n)) + if (p->init(type, dst)) return true; } while ((p = p->next)); @@ -174,14 +172,13 @@ QVariant QQmlValueTypeProvider::createVariantFromJsObject(int type, QQmlV4Handle return QVariant(); } -bool QQmlValueTypeProvider::equalValueType(int type, const void *lhs, const void *rhs, size_t rhsSize) +bool QQmlValueTypeProvider::equalValueType(int type, const void *lhs, const QVariant& rhs) { Q_ASSERT(lhs); - Q_ASSERT(rhs); QQmlValueTypeProvider *p = this; do { - if (p->equal(type, lhs, rhs, rhsSize)) + if (p->equal(type, lhs, rhs)) return true; } while ((p = p->next)); @@ -202,28 +199,26 @@ bool QQmlValueTypeProvider::storeValueType(int type, const void *src, void *dst, return false; } -bool QQmlValueTypeProvider::readValueType(int srcType, const void *src, size_t srcSize, int dstType, void *dst) +bool QQmlValueTypeProvider::readValueType(const QVariant& src, void *dst, int dstType) { - Q_ASSERT(src); Q_ASSERT(dst); QQmlValueTypeProvider *p = this; do { - if (p->read(srcType, src, srcSize, dstType, dst)) + if (p->read(src, dst, dstType)) return true; } while ((p = p->next)); return false; } -bool QQmlValueTypeProvider::writeValueType(int type, const void *src, void *dst, size_t n) +bool QQmlValueTypeProvider::writeValueType(int type, const void *src, QVariant& dst) { Q_ASSERT(src); - Q_ASSERT(dst); QQmlValueTypeProvider *p = this; do { - if (p->write(type, src, dst, n)) + if (p->write(type, src, dst)) return true; } while ((p = p->next)); @@ -231,7 +226,7 @@ bool QQmlValueTypeProvider::writeValueType(int type, const void *src, void *dst, } const QMetaObject *QQmlValueTypeProvider::getMetaObjectForMetaType(int) { return 0; } -bool QQmlValueTypeProvider::init(int, void *, size_t) { return false; } +bool QQmlValueTypeProvider::init(int, QVariant&) { return false; } bool QQmlValueTypeProvider::destroy(int, void *, size_t) { return false; } bool QQmlValueTypeProvider::create(int, int, const void *[], QVariant *) { return false; } bool QQmlValueTypeProvider::createFromString(int, const QString &, void *, size_t) { return false; } @@ -239,10 +234,10 @@ bool QQmlValueTypeProvider::createStringFrom(int, const void *, QString *) { ret bool QQmlValueTypeProvider::variantFromString(const QString &, QVariant *) { return false; } bool QQmlValueTypeProvider::variantFromString(int, const QString &, QVariant *) { return false; } bool QQmlValueTypeProvider::variantFromJsObject(int, QQmlV4Handle, QV4::ExecutionEngine *, QVariant *) { return false; } -bool QQmlValueTypeProvider::equal(int, const void *, const void *, size_t) { return false; } +bool QQmlValueTypeProvider::equal(int, const void *, const QVariant&) { return false; } bool QQmlValueTypeProvider::store(int, const void *, void *, size_t) { return false; } -bool QQmlValueTypeProvider::read(int, const void *, size_t, int, void *) { return false; } -bool QQmlValueTypeProvider::write(int, const void *, void *, size_t) { return false; } +bool QQmlValueTypeProvider::read(const QVariant&, void *, int) { return false; } +bool QQmlValueTypeProvider::write(int, const void *, QVariant&) { return false; } Q_GLOBAL_STATIC(QQmlValueTypeProvider, nullValueTypeProvider) static QQmlValueTypeProvider *valueTypeProvider = 0; diff --git a/src/qml/qml/qqmlglobal_p.h b/src/qml/qml/qqmlglobal_p.h index 8ed044d2c9..c19f7dab64 100644 --- a/src/qml/qml/qqmlglobal_p.h +++ b/src/qml/qml/qqmlglobal_p.h @@ -224,7 +224,7 @@ public: const QMetaObject *metaObjectForMetaType(int); - bool initValueType(int, void *, size_t); + bool initValueType(int, QVariant&); bool destroyValueType(int, void *, size_t); QVariant createValueType(int, int, const void *[]); @@ -235,14 +235,14 @@ public: QVariant createVariantFromString(int, const QString &, bool *); QVariant createVariantFromJsObject(int, QQmlV4Handle, QV4::ExecutionEngine *, bool*); - bool equalValueType(int, const void *, const void *, size_t); + bool equalValueType(int, const void *, const QVariant&); bool storeValueType(int, const void *, void *, size_t); - bool readValueType(int, const void *, size_t, int, void *); - bool writeValueType(int, const void *, void *, size_t); + bool readValueType(const QVariant&, void *, int); + bool writeValueType(int, const void *, QVariant&); private: virtual const QMetaObject *getMetaObjectForMetaType(int); - virtual bool init(int, void *, size_t); + virtual bool init(int, QVariant&); virtual bool destroy(int, void *, size_t); virtual bool create(int, int, const void *[], QVariant *); @@ -253,10 +253,10 @@ private: virtual bool variantFromString(int, const QString &, QVariant *); virtual bool variantFromJsObject(int, QQmlV4Handle, QV4::ExecutionEngine *, QVariant *); - virtual bool equal(int, const void *, const void *, size_t); + virtual bool equal(int, const void *, const QVariant&); virtual bool store(int, const void *, void *, size_t); - virtual bool read(int, const void *, size_t, int, void *); - virtual bool write(int, const void *, void *, size_t); + virtual bool read(const QVariant&, void *, int); + virtual bool write(int, const void *, QVariant&); friend Q_QML_PRIVATE_EXPORT void QQml_addValueTypeProvider(QQmlValueTypeProvider *); friend Q_QML_PRIVATE_EXPORT void QQml_removeValueTypeProvider(QQmlValueTypeProvider *); diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 0d10550fab..a960797626 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -1026,9 +1026,20 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) *reinterpret_cast(a[0]) = readPropertyAsVariant(id); break; default: - QQml_valueTypeProvider()->readValueType(data[id].dataType(), data[id].dataPtr(), data->dataSize(), t, a[0]); + { + if (ensurePropertiesAllocated()) { + QV4::ExecutionEngine *v4 = properties.engine(); + QV4::Scope scope(v4); + QV4::ScopedObject o(scope, properties.value()); + QV4::ScopedValue sv(scope, o->getIndexed(id)); + const QV4::VariantObject *v = sv->as(); + if (v) { + QQml_valueTypeProvider()->readValueType(v->d()->data, a[0], t); + } + } break; } + } if (t == qMetaTypeId >()) { const int listIndex = readPropertyAsInt(id); const List *list = &listProperties.at(listIndex); @@ -1088,12 +1099,26 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) case QMetaType::QVariant: writeProperty(id, *reinterpret_cast(a[0])); break; - default: - data[id].ensureValueType(t); - needActivate = !QQml_valueTypeProvider()->equalValueType(t, a[0], data[id].dataPtr(), data[id].dataSize()); - QQml_valueTypeProvider()->writeValueType(t, a[0], data[id].dataPtr(), data[id].dataSize()); + default: { + if (ensurePropertiesAllocated()) { + QV4::ExecutionEngine *v4 = properties.engine(); + QV4::Scope scope(v4); + QV4::ScopedObject o(scope, properties.value()); + QV4::ScopedValue sv(scope, o->getIndexed(id)); + QV4::VariantObject *v = sv->as(); + if (!v) { + QV4::ScopedValue svo(scope, properties.engine()->newVariantObject(QVariant())); + o->putIndexed(id, svo); + svo = o->getIndexed(id); + v = svo->as(); + } + QQmlValueTypeProvider().initValueType(t, v->d()->data); + needActivate = !QQml_valueTypeProvider()->equalValueType(t, a[0], v->d()->data); + QQml_valueTypeProvider()->writeValueType(t, a[0], v->d()->data); + } break; } + } } } diff --git a/src/quick/util/qquickglobal.cpp b/src/quick/util/qquickglobal.cpp index fd172006e0..adf3a68e92 100644 --- a/src/quick/util/qquickglobal.cpp +++ b/src/quick/util/qquickglobal.cpp @@ -397,41 +397,30 @@ public: return 0; } - template - bool typedInit(void *data, size_t dataSize) - { - ASSERT_VALID_SIZE(dataSize, sizeof(T)); - T *t = reinterpret_cast(data); - new (t) T(); - return true; - } - - bool init(int type, void *data, size_t dataSize) + bool init(int type, QVariant& dst) { switch (type) { case QMetaType::QColor: - return typedInit(data, dataSize); + dst.setValue(QColor()); + return true; case QMetaType::QFont: - return typedInit(data, dataSize); + dst.setValue(QFont()); + return true; case QMetaType::QVector2D: - return typedInit(data, dataSize); + dst.setValue(QVector2D()); + return true; case QMetaType::QVector3D: - return typedInit(data, dataSize); + dst.setValue(QVector3D()); + return true; case QMetaType::QVector4D: - return typedInit(data, dataSize); + dst.setValue(QVector4D()); + return true; case QMetaType::QQuaternion: - return typedInit(data, dataSize); + dst.setValue(QQuaternion()); + return true; case QMetaType::QMatrix4x4: - { - if (dataSize >= sizeof(QMatrix4x4)) - return typedInit(data, dataSize); - - // special case: init matrix-containing qvariant. - Q_ASSERT(dataSize >= sizeof(QVariant)); - QVariant *matvar = reinterpret_cast(data); - new (matvar) QVariant(QMatrix4x4()); + dst.setValue(QMatrix4x4()); return true; - } default: break; } @@ -691,12 +680,12 @@ public: } template - bool typedEqual(const void *lhs, const void *rhs) + bool typedEqual(const void *lhs, const QVariant& rhs) { - return (*(reinterpret_cast(lhs)) == *(reinterpret_cast(rhs))); + return (*(reinterpret_cast(lhs)) == rhs.value()); } - bool equal(int type, const void *lhs, const void *rhs, size_t rhsSize) + bool equal(int type, const void *lhs, const QVariant &rhs) { switch (type) { case QMetaType::QColor: @@ -712,14 +701,7 @@ public: case QMetaType::QQuaternion: return typedEqual(lhs, rhs); case QMetaType::QMatrix4x4: - { - if (rhsSize >= sizeof(QMatrix4x4)) - return typedEqual(lhs, rhs); - - Q_ASSERT(rhsSize >= sizeof(QVariant)); - QMatrix4x4 rhsmat = reinterpret_cast(rhs)->value(); - return typedEqual(lhs, &rhsmat); - } + return typedEqual(lhs, rhs); default: break; } @@ -778,50 +760,34 @@ public: } template - bool typedRead(int srcType, const void *src, size_t srcSize, int dstType, void *dst) + bool typedRead(const QVariant& src, int dstType, void *dst) { T *dstT = reinterpret_cast(dst); - if (srcType == dstType) { - ASSERT_VALID_SIZE(srcSize, sizeof(T)); - const T *srcT = reinterpret_cast(src); - *dstT = *srcT; + if (src.type() == static_cast(dstType)) { + *dstT = src.value(); } else { *dstT = T(); } return true; } - bool read(int srcType, const void *src, size_t srcSize, int dstType, void *dst) + bool read(const QVariant &src, void *dst, int dstType) { switch (dstType) { case QMetaType::QColor: - return typedRead(srcType, src, srcSize, dstType, dst); + return typedRead(src, dstType, dst); case QMetaType::QFont: - return typedRead(srcType, src, srcSize, dstType, dst); + return typedRead(src, dstType, dst); case QMetaType::QVector2D: - return typedRead(srcType, src, srcSize, dstType, dst); + return typedRead(src, dstType, dst); case QMetaType::QVector3D: - return typedRead(srcType, src, srcSize, dstType, dst); + return typedRead(src, dstType, dst); case QMetaType::QVector4D: - return typedRead(srcType, src, srcSize, dstType, dst); + return typedRead(src, dstType, dst); case QMetaType::QQuaternion: - return typedRead(srcType, src, srcSize, dstType, dst); + return typedRead(src, dstType, dst); case QMetaType::QMatrix4x4: - { - if (srcSize >= sizeof(QMatrix4x4)) - return typedRead(srcType, src, srcSize, dstType, dst); - - // the source data may be stored in a QVariant. - QMatrix4x4 *dstMat = reinterpret_cast(dst); - if (srcType == dstType) { - Q_ASSERT(srcSize >= sizeof(QVariant)); - const QVariant *srcMatVar = reinterpret_cast(src); - *dstMat = srcMatVar->value(); - } else { - *dstMat = QMatrix4x4(); - } - return true; - } + return typedRead(src, dstType, dst); default: break; } @@ -829,51 +795,33 @@ public: } template - bool typedWrite(const void *src, void *dst, size_t dstSize) + bool typedWrite(const void *src, QVariant& dst) { - ASSERT_VALID_SIZE(dstSize, sizeof(T)); const T *srcT = reinterpret_cast(src); - T *dstT = reinterpret_cast(dst); - if (*dstT != *srcT) { - *dstT = *srcT; + if (dst.value() != *srcT) { + dst = *srcT; return true; } return false; } - bool write(int type, const void *src, void *dst, size_t dstSize) + bool write(int type, const void *src, QVariant& dst) { switch (type) { case QMetaType::QColor: - return typedWrite(src, dst, dstSize); + return typedWrite(src, dst); case QMetaType::QFont: - return typedWrite(src, dst, dstSize); + return typedWrite(src, dst); case QMetaType::QVector2D: - return typedWrite(src, dst, dstSize); + return typedWrite(src, dst); case QMetaType::QVector3D: - return typedWrite(src, dst, dstSize); + return typedWrite(src, dst); case QMetaType::QVector4D: - return typedWrite(src, dst, dstSize); + return typedWrite(src, dst); case QMetaType::QQuaternion: - return typedWrite(src, dst, dstSize); + return typedWrite(src, dst); case QMetaType::QMatrix4x4: - { - if (dstSize >= sizeof(QMatrix4x4)) - return typedWrite(src, dst, dstSize); - - // special case: storing matrix into variant - // eg, QVMEMO QVMEVariant data cell is big enough to store - // QVariant, but not large enough to store QMatrix4x4. - Q_ASSERT(dstSize >= sizeof(QVariant)); - const QMatrix4x4 *srcMat = reinterpret_cast(src); - QVariant *dstMatVar = reinterpret_cast(dst); - QMatrix4x4 dstMatVal = dstMatVar->value(); - if (dstMatVal != *srcMat) { - *dstMatVar = QVariant(*srcMat); - return true; - } - return false; - } + return typedWrite(src, dst); default: break; } -- cgit v1.2.3 From a6e4c64812ee4846677608f2334d8fd3eee76756 Mon Sep 17 00:00:00 2001 From: Frank Meerkoetter Date: Sat, 25 Jul 2015 19:57:11 +0200 Subject: Remove the QQmlVMEVariant array member All properties have been move into the varProperties JS array. Change-Id: Ib39a603d43ab5ef23aad3e6ccbdbc9b981c9da18 Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlvmemetaobject.cpp | 5 +---- src/qml/qml/qqmlvmemetaobject_p.h | 1 - 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index a960797626..0873bef993 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -515,7 +515,7 @@ QQmlVMEMetaObject::QQmlVMEMetaObject(QObject *obj, const QQmlVMEMetaData *meta, QV4::ExecutionContext *qmlBindingContext, QQmlCompiledData *compiledData) : object(obj), ctxt(QQmlData::get(obj, true)->outerContext), cache(cache), metaData(meta), - hasAssignedMetaObjectData(false), data(0), aliasEndpoints(0), firstVarPropertyIndex(-1), + hasAssignedMetaObjectData(false), aliasEndpoints(0), firstVarPropertyIndex(-1), propertiesInitialized(false), interceptors(0), v8methods(0) { QObjectPrivate *op = QObjectPrivate::get(obj); @@ -530,8 +530,6 @@ QQmlVMEMetaObject::QQmlVMEMetaObject(QObject *obj, op->metaObject = this; QQmlData::get(obj)->hasVMEMetaObject = true; - data = new QQmlVMEVariant[metaData->propertyCount - metaData->varPropertyCount]; - aConnected.resize(metaData->aliasCount); int list_type = qMetaTypeId >(); int qobject_type = qMetaTypeId(); @@ -576,7 +574,6 @@ QQmlVMEMetaObject::QQmlVMEMetaObject(QObject *obj, QQmlVMEMetaObject::~QQmlVMEMetaObject() { if (parent.isT1()) parent.asT1()->objectDestroyed(object); - delete [] data; delete [] aliasEndpoints; delete [] v8methods; diff --git a/src/qml/qml/qqmlvmemetaobject_p.h b/src/qml/qml/qqmlvmemetaobject_p.h index 7009b47a5f..7c881f1350 100644 --- a/src/qml/qml/qqmlvmemetaobject_p.h +++ b/src/qml/qml/qqmlvmemetaobject_p.h @@ -195,7 +195,6 @@ public: inline int signalCount() const; bool hasAssignedMetaObjectData; - QQmlVMEVariant *data; QQmlVMEMetaObjectEndpoint *aliasEndpoints; QV4::WeakValue properties; -- cgit v1.2.3 From a9ef319e154c0a0b9a3455c3d10459ddc866b36d Mon Sep 17 00:00:00 2001 From: Frank Meerkoetter Date: Fri, 24 Jul 2015 20:57:17 +0200 Subject: Remove the QQmlVMEVariant implementation This code is now obsolete. Change-Id: Id34e8663d0398286e8ce34db7d83c6957e779c30 Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlvmemetaobject.cpp | 363 -------------------------------------- 1 file changed, 363 deletions(-) diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 0873bef993..aaa72fe1ae 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -86,53 +86,6 @@ void QQmlVMEVariantQObjectPtr::setGuardedValue(QObject *obj, QQmlVMEMetaObject * setObject(obj); } -class QQmlVMEVariant -{ -public: - inline QQmlVMEVariant(); - inline ~QQmlVMEVariant(); - - inline const void *dataPtr() const; - inline void *dataPtr(); - inline int dataType() const; - inline size_t dataSize() const; - - inline QObject *asQObject(); - inline const QVariant &asQVariant(); - inline int asInt(); - inline bool asBool(); - inline double asDouble(); - inline const QString &asQString(); - inline const QUrl &asQUrl(); - inline const QDate &asQDate(); - inline const QDateTime &asQDateTime(); - inline const QRectF &asQRectF(); - inline const QPointF &asQPointF(); - inline const QSizeF &asQSizeF(); - - inline void setValue(QObject *v, QQmlVMEMetaObject *target, int index); - inline void setValue(const QVariant &); - inline void setValue(int); - inline void setValue(bool); - inline void setValue(double); - inline void setValue(const QString &); - inline void setValue(const QUrl &); - inline void setValue(const QTime &); - inline void setValue(const QDate &); - inline void setValue(const QDateTime &); - inline void setValue(const QRectF &); - inline void setValue(const QPointF &); - inline void setValue(const QSizeF &); - - inline void ensureValueType(int); - -private: - int type; - void *data[8]; // Large enough to hold all types - - inline void cleanup(); -}; - class QQmlVMEMetaObjectEndpoint : public QQmlNotifierEndpoint { public: @@ -143,322 +96,6 @@ public: QFlagPointer metaObject; }; - -QQmlVMEVariant::QQmlVMEVariant() -: type(QVariant::Invalid) -{ -} - -QQmlVMEVariant::~QQmlVMEVariant() -{ - cleanup(); -} - -void QQmlVMEVariant::cleanup() -{ - if (type == QVariant::Invalid) { - } else if (type == QMetaType::Int || - type == QMetaType::Bool || - type == QMetaType::Double) { - type = QVariant::Invalid; - } else if (type == QMetaType::QObjectStar) { - ((QQmlVMEVariantQObjectPtr*)dataPtr())->~QQmlVMEVariantQObjectPtr(); - type = QVariant::Invalid; - } else if (type == QMetaType::QString) { - ((QString *)dataPtr())->~QString(); - type = QVariant::Invalid; - } else if (type == QMetaType::QUrl) { - ((QUrl *)dataPtr())->~QUrl(); - type = QVariant::Invalid; - } else if (type == QMetaType::QTime) { - ((QTime *)dataPtr())->~QTime(); - type = QVariant::Invalid; - } else if (type == QMetaType::QDate) { - ((QDate *)dataPtr())->~QDate(); - type = QVariant::Invalid; - } else if (type == QMetaType::QDateTime) { - ((QDateTime *)dataPtr())->~QDateTime(); - type = QVariant::Invalid; - } else if (type == QMetaType::QRectF) { - ((QRectF *)dataPtr())->~QRectF(); - type = QVariant::Invalid; - } else if (type == QMetaType::QPointF) { - ((QPointF *)dataPtr())->~QPointF(); - type = QVariant::Invalid; - } else if (type == QMetaType::QSizeF) { - ((QSizeF *)dataPtr())->~QSizeF(); - type = QVariant::Invalid; - } else if (type == qMetaTypeId()) { - ((QVariant *)dataPtr())->~QVariant(); - type = QVariant::Invalid; - } else { - if (QQml_valueTypeProvider()->destroyValueType(type, dataPtr(), dataSize())) { - type = QVariant::Invalid; - } - } -} - -int QQmlVMEVariant::dataType() const -{ - return type; -} - -const void *QQmlVMEVariant::dataPtr() const -{ - return &data; -} - -void *QQmlVMEVariant::dataPtr() -{ - return &data; -} - -size_t QQmlVMEVariant::dataSize() const -{ - return sizeof(data); -} - -QObject *QQmlVMEVariant::asQObject() -{ - if (type != QMetaType::QObjectStar) - setValue((QObject *)0, 0, -1); - - return *(QQmlGuard *)(dataPtr()); -} - -const QVariant &QQmlVMEVariant::asQVariant() -{ - if (type != QMetaType::QVariant) - setValue(QVariant()); - - return *(QVariant *)(dataPtr()); -} - -int QQmlVMEVariant::asInt() -{ - if (type != QMetaType::Int) - setValue(int(0)); - - return *(int *)(dataPtr()); -} - -bool QQmlVMEVariant::asBool() -{ - if (type != QMetaType::Bool) - setValue(bool(false)); - - return *(bool *)(dataPtr()); -} - -double QQmlVMEVariant::asDouble() -{ - if (type != QMetaType::Double) - setValue(double(0)); - - return *(double *)(dataPtr()); -} - -const QString &QQmlVMEVariant::asQString() -{ - if (type != QMetaType::QString) - setValue(QString()); - - return *(QString *)(dataPtr()); -} - -const QUrl &QQmlVMEVariant::asQUrl() -{ - if (type != QMetaType::QUrl) - setValue(QUrl()); - - return *(QUrl *)(dataPtr()); -} - -const QDate &QQmlVMEVariant::asQDate() -{ - if (type != QMetaType::QDate) - setValue(QDate()); - - return *(QDate *)(dataPtr()); -} - -const QDateTime &QQmlVMEVariant::asQDateTime() -{ - if (type != QMetaType::QDateTime) - setValue(QDateTime()); - - return *(QDateTime *)(dataPtr()); -} - -const QRectF &QQmlVMEVariant::asQRectF() -{ - if (type != QMetaType::QRectF) - setValue(QRectF()); - - return *(QRectF *)(dataPtr()); -} - -const QSizeF &QQmlVMEVariant::asQSizeF() -{ - if (type != QMetaType::QSizeF) - setValue(QSizeF()); - - return *(QSizeF *)(dataPtr()); -} - -const QPointF &QQmlVMEVariant::asQPointF() -{ - if (type != QMetaType::QPointF) - setValue(QPointF()); - - return *(QPointF *)(dataPtr()); -} - -void QQmlVMEVariant::setValue(QObject *v, QQmlVMEMetaObject *target, int index) -{ - if (type != QMetaType::QObjectStar) { - cleanup(); - type = QMetaType::QObjectStar; - new (dataPtr()) QQmlVMEVariantQObjectPtr(false); - } - reinterpret_cast(dataPtr())->setGuardedValue(v, target, index); -} - -void QQmlVMEVariant::setValue(const QVariant &v) -{ - if (type != qMetaTypeId()) { - cleanup(); - type = qMetaTypeId(); - new (dataPtr()) QVariant(v); - } else { - *(QVariant *)(dataPtr()) = v; - } -} - -void QQmlVMEVariant::setValue(int v) -{ - if (type != QMetaType::Int) { - cleanup(); - type = QMetaType::Int; - } - *(int *)(dataPtr()) = v; -} - -void QQmlVMEVariant::setValue(bool v) -{ - if (type != QMetaType::Bool) { - cleanup(); - type = QMetaType::Bool; - } - *(bool *)(dataPtr()) = v; -} - -void QQmlVMEVariant::setValue(double v) -{ - if (type != QMetaType::Double) { - cleanup(); - type = QMetaType::Double; - } - *(double *)(dataPtr()) = v; -} - -void QQmlVMEVariant::setValue(const QString &v) -{ - if (type != QMetaType::QString) { - cleanup(); - type = QMetaType::QString; - new (dataPtr()) QString(v); - } else { - *(QString *)(dataPtr()) = v; - } -} - -void QQmlVMEVariant::setValue(const QUrl &v) -{ - if (type != QMetaType::QUrl) { - cleanup(); - type = QMetaType::QUrl; - new (dataPtr()) QUrl(v); - } else { - *(QUrl *)(dataPtr()) = v; - } -} - -void QQmlVMEVariant::setValue(const QTime &v) -{ - if (type != QMetaType::QTime) { - cleanup(); - type = QMetaType::QTime; - new (dataPtr()) QTime(v); - } else { - *(QTime *)(dataPtr()) = v; - } -} - -void QQmlVMEVariant::setValue(const QDate &v) -{ - if (type != QMetaType::QDate) { - cleanup(); - type = QMetaType::QDate; - new (dataPtr()) QDate(v); - } else { - *(QDate *)(dataPtr()) = v; - } -} - -void QQmlVMEVariant::setValue(const QDateTime &v) -{ - if (type != QMetaType::QDateTime) { - cleanup(); - type = QMetaType::QDateTime; - new (dataPtr()) QDateTime(v); - } else { - *(QDateTime *)(dataPtr()) = v; - } -} - -void QQmlVMEVariant::setValue(const QRectF &v) -{ - if (type != QMetaType::QRectF) { - cleanup(); - type = QMetaType::QRectF; - new (dataPtr()) QRectF(v); - } else { - *(QRectF *)(dataPtr()) = v; - } -} - -void QQmlVMEVariant::setValue(const QPointF &v) -{ - if (type != QMetaType::QPointF) { - cleanup(); - type = QMetaType::QPointF; - new (dataPtr()) QPointF(v); - } else { - *(QPointF *)(dataPtr()) = v; - } -} - -void QQmlVMEVariant::setValue(const QSizeF &v) -{ - if (type != QMetaType::QSizeF) { - cleanup(); - type = QMetaType::QSizeF; - new (dataPtr()) QSizeF(v); - } else { - *(QSizeF *)(dataPtr()) = v; - } -} - -void QQmlVMEVariant::ensureValueType(int t) -{ - if (type != t) { - cleanup(); - type = t; - QQml_valueTypeProvider()->initValueType(t, dataPtr(), dataSize()); - } -} - QQmlVMEMetaObjectEndpoint::QQmlVMEMetaObjectEndpoint() : QQmlNotifierEndpoint(QQmlNotifierEndpoint::QQmlVMEMetaObjectEndpoint) { -- cgit v1.2.3 From 8049154bd57394118a3eefdd63ab00940161e785 Mon Sep 17 00:00:00 2001 From: Frank Meerkoetter Date: Thu, 30 Jul 2015 21:57:24 +0200 Subject: Also remove the QQmlValueTypeProvider::destroyValueType interface After the removeal of the QQmlVMEVariant there is no user left. Change-Id: I97224127aac57aba9a80827f9292018d03609b85 Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlglobal.cpp | 14 -------------- src/qml/qml/qqmlglobal_p.h | 2 -- src/quick/util/qquickglobal.cpp | 41 ----------------------------------------- 3 files changed, 57 deletions(-) diff --git a/src/qml/qml/qqmlglobal.cpp b/src/qml/qml/qqmlglobal.cpp index 17de696af3..aa2b4b6aee 100644 --- a/src/qml/qml/qqmlglobal.cpp +++ b/src/qml/qml/qqmlglobal.cpp @@ -73,19 +73,6 @@ bool QQmlValueTypeProvider::initValueType(int type, QVariant& dst) return false; } -bool QQmlValueTypeProvider::destroyValueType(int type, void *data, size_t n) -{ - Q_ASSERT(data); - - QQmlValueTypeProvider *p = this; - do { - if (p->destroy(type, data, n)) - return true; - } while ((p = p->next)); - - return false; -} - QVariant QQmlValueTypeProvider::createValueType(int type, int argc, const void *argv[]) { QVariant v; @@ -227,7 +214,6 @@ bool QQmlValueTypeProvider::writeValueType(int type, const void *src, QVariant& const QMetaObject *QQmlValueTypeProvider::getMetaObjectForMetaType(int) { return 0; } bool QQmlValueTypeProvider::init(int, QVariant&) { return false; } -bool QQmlValueTypeProvider::destroy(int, void *, size_t) { return false; } bool QQmlValueTypeProvider::create(int, int, const void *[], QVariant *) { return false; } bool QQmlValueTypeProvider::createFromString(int, const QString &, void *, size_t) { return false; } bool QQmlValueTypeProvider::createStringFrom(int, const void *, QString *) { return false; } diff --git a/src/qml/qml/qqmlglobal_p.h b/src/qml/qml/qqmlglobal_p.h index c19f7dab64..d09ae21f56 100644 --- a/src/qml/qml/qqmlglobal_p.h +++ b/src/qml/qml/qqmlglobal_p.h @@ -225,7 +225,6 @@ public: const QMetaObject *metaObjectForMetaType(int); bool initValueType(int, QVariant&); - bool destroyValueType(int, void *, size_t); QVariant createValueType(int, int, const void *[]); bool createValueFromString(int, const QString &, void *, size_t); @@ -243,7 +242,6 @@ public: private: virtual const QMetaObject *getMetaObjectForMetaType(int); virtual bool init(int, QVariant&); - virtual bool destroy(int, void *, size_t); virtual bool create(int, int, const void *[], QVariant *); virtual bool createFromString(int, const QString &, void *, size_t); diff --git a/src/quick/util/qquickglobal.cpp b/src/quick/util/qquickglobal.cpp index adf3a68e92..d7f1158a6b 100644 --- a/src/quick/util/qquickglobal.cpp +++ b/src/quick/util/qquickglobal.cpp @@ -427,47 +427,6 @@ public: return false; } - template - bool typedDestroy(void *data, size_t dataSize) - { - ASSERT_VALID_SIZE(dataSize, sizeof(T)); - T *t = reinterpret_cast(data); - t->~T(); - return true; - } - - bool destroy(int type, void *data, size_t dataSize) - { - switch (type) { - case QMetaType::QColor: - return typedDestroy(data, dataSize); - case QMetaType::QFont: - return typedDestroy(data, dataSize); - case QMetaType::QVector2D: - return typedDestroy(data, dataSize); - case QMetaType::QVector3D: - return typedDestroy(data, dataSize); - case QMetaType::QVector4D: - return typedDestroy(data, dataSize); - case QMetaType::QQuaternion: - return typedDestroy(data, dataSize); - case QMetaType::QMatrix4x4: - { - if (dataSize >= sizeof(QMatrix4x4)) - return typedDestroy(data, dataSize); - - // special case: destroying matrix-containing qvariant. - Q_ASSERT(dataSize >= sizeof(QVariant)); - QVariant *matvar = reinterpret_cast(data); - matvar->~QVariant(); - return true; - } - default: break; - } - - return false; - } - bool create(int type, int argc, const void *argv[], QVariant *v) { switch (type) { -- cgit v1.2.3 From e5c70545a4c8479a9bc6ee1bae296d39e1a35d2e Mon Sep 17 00:00:00 2001 From: Frank Meerkoetter Date: Thu, 30 Jul 2015 22:16:29 +0200 Subject: Mark methods as overrides Let the compiler help to catch interface changes Change-Id: Ic4add183ca95ef287df41f35bd25c3e9eb15032f Reviewed-by: Simon Hausmann --- src/quick/util/qquickglobal.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/quick/util/qquickglobal.cpp b/src/quick/util/qquickglobal.cpp index d7f1158a6b..55544b1ea8 100644 --- a/src/quick/util/qquickglobal.cpp +++ b/src/quick/util/qquickglobal.cpp @@ -397,7 +397,7 @@ public: return 0; } - bool init(int type, QVariant& dst) + bool init(int type, QVariant& dst) Q_DECL_OVERRIDE { switch (type) { case QMetaType::QColor: @@ -427,7 +427,7 @@ public: return false; } - bool create(int type, int argc, const void *argv[], QVariant *v) + bool create(int type, int argc, const void *argv[], QVariant *v) Q_DECL_OVERRIDE { switch (type) { case QMetaType::QFont: // must specify via js-object. @@ -490,7 +490,7 @@ public: return true; } - bool createFromString(int type, const QString &s, void *data, size_t dataSize) + bool createFromString(int type, const QString &s, void *data, size_t dataSize) Q_DECL_OVERRIDE { bool ok = false; @@ -521,7 +521,7 @@ public: return false; } - bool createStringFrom(int type, const void *data, QString *s) + bool createStringFrom(int type, const void *data, QString *s) Q_DECL_OVERRIDE { if (type == QMetaType::QColor) { const QColor *color = reinterpret_cast(data); @@ -532,7 +532,7 @@ public: return false; } - bool variantFromString(const QString &s, QVariant *v) + bool variantFromString(const QString &s, QVariant *v) Q_DECL_OVERRIDE { QColor c(s); if (c.isValid()) { @@ -575,7 +575,7 @@ public: return false; } - bool variantFromString(int type, const QString &s, QVariant *v) + bool variantFromString(int type, const QString &s, QVariant *v) Q_DECL_OVERRIDE { bool ok = false; @@ -618,7 +618,7 @@ public: return false; } - bool variantFromJsObject(int type, QQmlV4Handle object, QV4::ExecutionEngine *v4, QVariant *v) + bool variantFromJsObject(int type, QQmlV4Handle object, QV4::ExecutionEngine *v4, QVariant *v) Q_DECL_OVERRIDE { QV4::Scope scope(v4); #ifndef QT_NO_DEBUG @@ -644,7 +644,7 @@ public: return (*(reinterpret_cast(lhs)) == rhs.value()); } - bool equal(int type, const void *lhs, const QVariant &rhs) + bool equal(int type, const void *lhs, const QVariant &rhs) Q_DECL_OVERRIDE { switch (type) { case QMetaType::QColor: @@ -677,7 +677,7 @@ public: return true; } - bool store(int type, const void *src, void *dst, size_t dstSize) + bool store(int type, const void *src, void *dst, size_t dstSize) Q_DECL_OVERRIDE { switch (type) { case QMetaType::QColor: @@ -730,7 +730,7 @@ public: return true; } - bool read(const QVariant &src, void *dst, int dstType) + bool read(const QVariant &src, void *dst, int dstType) Q_DECL_OVERRIDE { switch (dstType) { case QMetaType::QColor: @@ -764,7 +764,7 @@ public: return false; } - bool write(int type, const void *src, QVariant& dst) + bool write(int type, const void *src, QVariant& dst) Q_DECL_OVERRIDE { switch (type) { case QMetaType::QColor: -- cgit v1.2.3 From bb3dc5116ef11d2be82757e623916e025bb03d76 Mon Sep 17 00:00:00 2001 From: Frank Meerkoetter Date: Thu, 30 Jul 2015 22:24:35 +0200 Subject: Remove unused code The QQmlObjectCreator is the only user left. It is using it only with QVariant::Color. Change-Id: I5091fd160841118bee5d6cf6e30798f66c277b69 Reviewed-by: Simon Hausmann --- src/quick/util/qquickglobal.cpp | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/src/quick/util/qquickglobal.cpp b/src/quick/util/qquickglobal.cpp index 55544b1ea8..cc908142ab 100644 --- a/src/quick/util/qquickglobal.cpp +++ b/src/quick/util/qquickglobal.cpp @@ -679,6 +679,7 @@ public: bool store(int type, const void *src, void *dst, size_t dstSize) Q_DECL_OVERRIDE { + Q_UNUSED(dstSize); switch (type) { case QMetaType::QColor: { @@ -688,31 +689,7 @@ public: new (color) QColor(QColor::fromRgba(*rgb)); return true; } - case QMetaType::QFont: - return typedStore(src, dst, dstSize); - case QMetaType::QVector2D: - return typedStore(src, dst, dstSize); - case QMetaType::QVector3D: - return typedStore(src, dst, dstSize); - case QMetaType::QVector4D: - return typedStore(src, dst, dstSize); - case QMetaType::QQuaternion: - return typedStore(src, dst, dstSize); - case QMetaType::QMatrix4x4: - { - if (dstSize >= sizeof(QMatrix4x4)) - return typedStore(src, dst, dstSize); - - // special case: storing matrix into variant - // eg, QVMEMO QVMEVariant data cell is big enough to store - // QVariant, but not large enough to store QMatrix4x4. - Q_ASSERT(dstSize >= sizeof(QVariant)); - const QMatrix4x4 *srcMat = reinterpret_cast(src); - QVariant *dstMatVar = reinterpret_cast(dst); - new (dstMatVar) QVariant(*srcMat); - return true; - } - default: break; + default: break; } return false; -- cgit v1.2.3 From 214e987fb4f4a18d7c4a755d3d50ce72af603c9e Mon Sep 17 00:00:00 2001 From: Frank Meerkoetter Date: Thu, 30 Jul 2015 22:54:17 +0200 Subject: Remove QQmlVMEVariant specific workaround A Q4x4Matrix wouldn't fit inside a QQmlVMEVariant. Therefore it was wrapped in a QVariant. Change-Id: I68864e456a4fd76143277d5a10d1a3f307e833f2 Reviewed-by: Simon Hausmann --- src/quick/util/qquickglobal.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/quick/util/qquickglobal.cpp b/src/quick/util/qquickglobal.cpp index cc908142ab..f9300545df 100644 --- a/src/quick/util/qquickglobal.cpp +++ b/src/quick/util/qquickglobal.cpp @@ -506,15 +506,7 @@ public: case QMetaType::QQuaternion: return createFromStringTyped(data, dataSize, quaternionFromString(s, &ok)); case QMetaType::QMatrix4x4: - { - if (dataSize >= sizeof(QMatrix4x4)) - return createFromStringTyped(data, dataSize, matrix4x4FromString(s, &ok)); - - Q_ASSERT(dataSize >= sizeof(QVariant)); - QVariant *matVar = reinterpret_cast(data); - new (matVar) QVariant(matrix4x4FromString(s, &ok)); - return true; - } + return createFromStringTyped(data, dataSize, matrix4x4FromString(s, &ok)); default: break; } -- cgit v1.2.3 From b4427f6abd19f58b53f3e96bcba1de5486b5cbd9 Mon Sep 17 00:00:00 2001 From: Frank Meerkoetter Date: Fri, 7 Aug 2015 11:10:19 +0200 Subject: Update copyright notice. Update the copyright notice on files containing larger changes from me. Change-Id: I46cb83161331ef2f49a6ec92c078d6dc8019081e Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlvmemetaobject.cpp | 1 + src/qml/qml/qqmlvmemetaobject_p.h | 1 + src/quick/util/qquickglobal.cpp | 1 + 3 files changed, 3 insertions(+) diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index aaa72fe1ae..e218e69ed6 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2015 BasysKom GmbH. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtQml module of the Qt Toolkit. diff --git a/src/qml/qml/qqmlvmemetaobject_p.h b/src/qml/qml/qqmlvmemetaobject_p.h index 7c881f1350..a399b072ff 100644 --- a/src/qml/qml/qqmlvmemetaobject_p.h +++ b/src/qml/qml/qqmlvmemetaobject_p.h @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2015 BasysKom GmbH. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtQml module of the Qt Toolkit. diff --git a/src/quick/util/qquickglobal.cpp b/src/quick/util/qquickglobal.cpp index f9300545df..391e0b7347 100644 --- a/src/quick/util/qquickglobal.cpp +++ b/src/quick/util/qquickglobal.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2015 BasysKom GmbH. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtQuick module of the Qt Toolkit. -- cgit v1.2.3 From 1b8106bc2516a66c4f721deaf4470da8b805ac3d Mon Sep 17 00:00:00 2001 From: Frank Meerkoetter Date: Fri, 7 Aug 2015 14:22:08 +0200 Subject: Use QV4::MemberData for property storage Unlike the Array type the QV4::MemberData can be sized exactly so no memory is wasted. Change-Id: Ia7b9b846a7b8017787324e5243ccf6233568d41c Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlvmemetaobject.cpp | 322 +++++++++++++++----------------------- src/qml/qml/qqmlvmemetaobject_p.h | 1 + 2 files changed, 129 insertions(+), 194 deletions(-) diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index e218e69ed6..6a12674fb0 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -64,14 +64,13 @@ QQmlVMEVariantQObjectPtr::~QQmlVMEVariantQObjectPtr() void QQmlVMEVariantQObjectPtr::objectDestroyed(QObject *) { if (m_target && m_index >= 0) { + // Set the var property to NULL if (m_isVar && m_target->propertiesInitialized && !m_target->properties.isUndefined()) { - // Set the var property to NULL QV4::ExecutionEngine *v4 = m_target->properties.engine(); if (v4) { QV4::Scope scope(v4); - QV4::ScopedArrayObject a(scope, m_target->properties.value()); - if (a) - a->putIndexed(m_index, QV4::ScopedValue(scope, QV4::Primitive::nullValue())); + QV4::Scoped sp(scope, m_target->properties.value()); + *(sp->data() + m_index) = QV4::Primitive::nullValue(); } } @@ -218,125 +217,89 @@ QQmlVMEMetaObject::~QQmlVMEMetaObject() qDeleteAll(varObjectGuards); } -void QQmlVMEMetaObject::writeProperty(int id, int v) +QV4::MemberData *QQmlVMEMetaObject::propertiesAsMemberData() { if (!ensurePropertiesAllocated()) - return; + return 0; - QV4::Scope scope(properties.engine()); - QV4::ScopedObject vp(scope, properties.value()); - vp->putIndexed(id, QV4::Primitive::fromInt32(v)); + return static_cast(properties.asManaged()); } -void QQmlVMEMetaObject::writeProperty(int id, bool v) +void QQmlVMEMetaObject::writeProperty(int id, int v) { - if (!ensurePropertiesAllocated()) - return; + QV4::MemberData *md = propertiesAsMemberData(); + if (md) + *(md->data() + id) = QV4::Primitive::fromInt32(v); +} - QV4::Scope scope(properties.engine()); - QV4::ScopedObject vp(scope, properties.value()); - vp->putIndexed(id, QV4::Primitive::fromBoolean(v)); +void QQmlVMEMetaObject::writeProperty(int id, bool v) +{ + QV4::MemberData *md = propertiesAsMemberData(); + if (md) + *(md->data() + id) = QV4::Primitive::fromBoolean(v); } void QQmlVMEMetaObject::writeProperty(int id, double v) { - if (!ensurePropertiesAllocated()) - return; - - QV4::Scope scope(properties.engine()); - QV4::ScopedObject vp(scope, properties.value()); - vp->putIndexed(id, QV4::Primitive::fromDouble(v)); + QV4::MemberData *md = propertiesAsMemberData(); + if (md) + *(md->data() + id) = QV4::Primitive::fromDouble(v); } void QQmlVMEMetaObject::writeProperty(int id, const QString& v) { - if (!ensurePropertiesAllocated()) - return; - - QV4::Scope scope(properties.engine()); - QV4::ScopedObject vp(scope, properties.value()); - QV4::ScopedValue s(scope, properties.engine()->newString(v)); - vp->putIndexed(id, s); + QV4::MemberData *md = propertiesAsMemberData(); + if (md) + *(md->data() + id) = properties.engine()->newString(v); } void QQmlVMEMetaObject::writeProperty(int id, const QUrl& v) { - if (!ensurePropertiesAllocated()) - return; - - QV4::Scope scope(properties.engine()); - QV4::ScopedObject vp(scope, properties.value()); - QV4::ScopedValue sv(scope, properties.engine()->newVariantObject(QVariant::fromValue(v))); - vp->putIndexed(id, sv); + QV4::MemberData *md = propertiesAsMemberData(); + if (md) + *(md->data() + id) = properties.engine()->newVariantObject(QVariant::fromValue(v)); } -// TODO: can we store the QDate in a QV4::Value primitive? void QQmlVMEMetaObject::writeProperty(int id, const QDate& v) { - if (!ensurePropertiesAllocated()) - return; - - QV4::Scope scope(properties.engine()); - QV4::ScopedObject vp(scope, properties.value()); - QV4::ScopedValue sv(scope, properties.engine()->newVariantObject(QVariant::fromValue(v))); - vp->putIndexed(id, sv); + QV4::MemberData *md = propertiesAsMemberData(); + if (md) + *(md->data() + id) = properties.engine()->newVariantObject(QVariant::fromValue(v)); } void QQmlVMEMetaObject::writeProperty(int id, const QDateTime& v) { - if (!ensurePropertiesAllocated()) - return; - - QV4::Scope scope(properties.engine()); - QV4::ScopedObject vp(scope, properties.value()); - QV4::ScopedValue sv(scope, properties.engine()->newVariantObject(QVariant::fromValue(v))); - vp->putIndexed(id, sv); + QV4::MemberData *md = propertiesAsMemberData(); + if (md) + *(md->data() + id) = properties.engine()->newVariantObject(QVariant::fromValue(v)); } void QQmlVMEMetaObject::writeProperty(int id, const QPointF& v) { - if (!ensurePropertiesAllocated()) - return; - - QV4::Scope scope(properties.engine()); - QV4::ScopedObject vp(scope, properties.value()); - QV4::ScopedValue sv(scope, properties.engine()->newVariantObject(QVariant::fromValue(v))); - vp->putIndexed(id, sv); + QV4::MemberData *md = propertiesAsMemberData(); + if (md) + *(md->data() + id) = properties.engine()->newVariantObject(QVariant::fromValue(v)); } void QQmlVMEMetaObject::writeProperty(int id, const QSizeF& v) { - if (!ensurePropertiesAllocated()) - return; - - QV4::Scope scope(properties.engine()); - QV4::ScopedObject vp(scope, properties.value()); - QV4::ScopedValue sv(scope, properties.engine()->newVariantObject(QVariant::fromValue(v))); - vp->putIndexed(id, sv); + QV4::MemberData *md = propertiesAsMemberData(); + if (md) + *(md->data() + id) = properties.engine()->newVariantObject(QVariant::fromValue(v)); } void QQmlVMEMetaObject::writeProperty(int id, const QRectF& v) { - if (!ensurePropertiesAllocated()) - return; - - QV4::Scope scope(properties.engine()); - QV4::ScopedObject vp(scope, properties.value()); - QV4::ScopedValue sv(scope, properties.engine()->newVariantObject(QVariant::fromValue(v))); - vp->putIndexed(id, sv); + QV4::MemberData *md = propertiesAsMemberData(); + if (md) + *(md->data() + id) = properties.engine()->newVariantObject(QVariant::fromValue(v)); } void QQmlVMEMetaObject::writeProperty(int id, QObject* v) { - if (!ensurePropertiesAllocated()) - return; - - QV4::Scope scope(properties.engine()); - QV4::ScopedObject vp(scope, properties.value()); - - QQmlEnginePrivate *ep = QQmlEnginePrivate::get(ctxt->engine); - QV4::ExecutionEngine *v4 = ep->v4engine(); - vp->putIndexed(id, QV4::ScopedObject(scope, QV4::QObjectWrapper::wrap(v4, v))); + QV4::MemberData *md = propertiesAsMemberData(); + if (md) + *(md->data() + id) = QV4::QObjectWrapper::wrap(properties.engine(), v); QQmlVMEVariantQObjectPtr *guard = getQObjectGuardForProperty(id); if (v && !guard) { @@ -349,12 +312,12 @@ void QQmlVMEMetaObject::writeProperty(int id, QObject* v) int QQmlVMEMetaObject::readPropertyAsInt(int id) { - if (!ensurePropertiesAllocated()) + QV4::MemberData *md = propertiesAsMemberData(); + if (!md) return 0; QV4::Scope scope(properties.engine()); - QV4::ScopedObject vp(scope, properties.value()); - QV4::ScopedValue sv(scope, vp->getIndexed(id)); + QV4::ScopedValue sv(scope, *(md->data() + id)); if (!sv->isInt32()) { writeProperty(id, int(0)); return 0; @@ -364,12 +327,12 @@ int QQmlVMEMetaObject::readPropertyAsInt(int id) bool QQmlVMEMetaObject::readPropertyAsBool(int id) { - if (!ensurePropertiesAllocated()) + QV4::MemberData *md = propertiesAsMemberData(); + if (!md) return false; QV4::Scope scope(properties.engine()); - QV4::ScopedObject vp(scope, properties.value()); - QV4::ScopedValue sv(scope, vp->getIndexed(id)); + QV4::ScopedValue sv(scope, *(md->data() + id)); if (!sv->isBoolean()) { writeProperty(id, false); return false; @@ -379,12 +342,12 @@ bool QQmlVMEMetaObject::readPropertyAsBool(int id) double QQmlVMEMetaObject::readPropertyAsDouble(int id) { - if (!ensurePropertiesAllocated()) + QV4::MemberData *md = propertiesAsMemberData(); + if (!md) return 0.0; QV4::Scope scope(properties.engine()); - QV4::ScopedObject vp(scope, properties.value()); - QV4::ScopedValue sv(scope, vp->getIndexed(id)); + QV4::ScopedValue sv(scope, *(md->data() + id)); if (!sv->isDouble()) { writeProperty(id, 0.0); return 0.0; @@ -394,12 +357,12 @@ double QQmlVMEMetaObject::readPropertyAsDouble(int id) QString QQmlVMEMetaObject::readPropertyAsString(int id) { - if (!ensurePropertiesAllocated()) + QV4::MemberData *md = propertiesAsMemberData(); + if (!md) return QString(); QV4::Scope scope(properties.engine()); - QV4::ScopedObject vp(scope, properties.value()); - QV4::ScopedValue sv(scope, vp->getIndexed(id)); + QV4::ScopedValue sv(scope, *(md->data() + id)); if (!sv->isString()) { writeProperty(id, QString()); return QString(); @@ -409,12 +372,12 @@ QString QQmlVMEMetaObject::readPropertyAsString(int id) QUrl QQmlVMEMetaObject::readPropertyAsUrl(int id) { - if (!ensurePropertiesAllocated()) + QV4::MemberData *md = propertiesAsMemberData(); + if (!md) return QUrl(); QV4::Scope scope(properties.engine()); - QV4::ScopedObject vp(scope, properties.value()); - QV4::ScopedValue sv(scope, vp->getIndexed(id)); + QV4::ScopedValue sv(scope, *(md->data() + id)); const QV4::VariantObject *v = sv->as(); if (!v || v->d()->data.type() != QVariant::Url) { writeProperty(id, QUrl()); @@ -425,12 +388,12 @@ QUrl QQmlVMEMetaObject::readPropertyAsUrl(int id) QDate QQmlVMEMetaObject::readPropertyAsDate(int id) { - if (!ensurePropertiesAllocated()) + QV4::MemberData *md = propertiesAsMemberData(); + if (!md) return QDate(); QV4::Scope scope(properties.engine()); - QV4::ScopedObject vp(scope, properties.value()); - QV4::ScopedValue sv(scope, vp->getIndexed(id)); + QV4::ScopedValue sv(scope, *(md->data() + id)); const QV4::VariantObject *v = sv->as(); if (!v || v->d()->data.type() != QVariant::Date) { writeProperty(id, QDate()); @@ -441,12 +404,12 @@ QDate QQmlVMEMetaObject::readPropertyAsDate(int id) QDateTime QQmlVMEMetaObject::readPropertyAsDateTime(int id) { - if (!ensurePropertiesAllocated()) + QV4::MemberData *md = propertiesAsMemberData(); + if (!md) return QDateTime(); QV4::Scope scope(properties.engine()); - QV4::ScopedObject vp(scope, properties.value()); - QV4::ScopedValue sv(scope, vp->getIndexed(id)); + QV4::ScopedValue sv(scope, *(md->data() + id)); const QV4::VariantObject *v = sv->as(); if (!v || v->d()->data.type() != QVariant::DateTime) { writeProperty(id, QDateTime()); @@ -457,12 +420,12 @@ QDateTime QQmlVMEMetaObject::readPropertyAsDateTime(int id) QSizeF QQmlVMEMetaObject::readPropertyAsSizeF(int id) { - if (!ensurePropertiesAllocated()) + QV4::MemberData *md = propertiesAsMemberData(); + if (!md) return QSizeF(); QV4::Scope scope(properties.engine()); - QV4::ScopedObject vp(scope, properties.value()); - QV4::ScopedValue sv(scope, vp->getIndexed(id)); + QV4::ScopedValue sv(scope, *(md->data() + id)); const QV4::VariantObject *v = sv->as(); if (!v || v->d()->data.type() != QVariant::SizeF) { writeProperty(id, QSizeF()); @@ -473,12 +436,12 @@ QSizeF QQmlVMEMetaObject::readPropertyAsSizeF(int id) QPointF QQmlVMEMetaObject::readPropertyAsPointF(int id) { - if (!ensurePropertiesAllocated()) + QV4::MemberData *md = propertiesAsMemberData(); + if (!md) return QPointF(); QV4::Scope scope(properties.engine()); - QV4::ScopedObject vp(scope, properties.value()); - QV4::ScopedValue sv(scope, vp->getIndexed(id)); + QV4::ScopedValue sv(scope, *(md->data() + id)); const QV4::VariantObject *v = sv->as(); if (!v || v->d()->data.type() != QVariant::PointF) { writeProperty(id, QPointF()); @@ -489,12 +452,12 @@ QPointF QQmlVMEMetaObject::readPropertyAsPointF(int id) QObject* QQmlVMEMetaObject::readPropertyAsQObject(int id) { - if (!ensurePropertiesAllocated()) + QV4::MemberData *md = propertiesAsMemberData(); + if (!md) return 0; QV4::Scope scope(properties.engine()); - QV4::ScopedObject vp(scope, properties.value()); - QV4::ScopedValue sv(scope, vp->getIndexed(id)); + QV4::ScopedValue sv(scope, *(md->data() + id)); const QV4::QObjectWrapper *wrapper = sv->as(); if (!wrapper) { writeProperty(id, static_cast(Q_NULLPTR)); @@ -505,12 +468,12 @@ QObject* QQmlVMEMetaObject::readPropertyAsQObject(int id) QRectF QQmlVMEMetaObject::readPropertyAsRectF(int id) { - if (!ensurePropertiesAllocated()) + QV4::MemberData *md = propertiesAsMemberData(); + if (!md) return QRectF(); QV4::Scope scope(properties.engine()); - QV4::ScopedObject vp(scope, properties.value()); - QV4::ScopedValue sv(scope, vp->getIndexed(id)); + QV4::ScopedValue sv(scope, *(md->data() + id)); const QV4::VariantObject *v = sv->as(); if (!v || v->d()->data.type() != QVariant::RectF) { writeProperty(id, QRectF()); @@ -662,15 +625,11 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) break; default: { - if (ensurePropertiesAllocated()) { - QV4::ExecutionEngine *v4 = properties.engine(); - QV4::Scope scope(v4); - QV4::ScopedObject o(scope, properties.value()); - QV4::ScopedValue sv(scope, o->getIndexed(id)); - const QV4::VariantObject *v = sv->as(); - if (v) { + QV4::MemberData *md = propertiesAsMemberData(); + if (md) { + QV4::VariantObject *v = (md->data() + id)->as(); + if (v) QQml_valueTypeProvider()->readValueType(v->d()->data, a[0], t); - } } break; } @@ -735,17 +694,12 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) writeProperty(id, *reinterpret_cast(a[0])); break; default: { - if (ensurePropertiesAllocated()) { - QV4::ExecutionEngine *v4 = properties.engine(); - QV4::Scope scope(v4); - QV4::ScopedObject o(scope, properties.value()); - QV4::ScopedValue sv(scope, o->getIndexed(id)); - QV4::VariantObject *v = sv->as(); + QV4::MemberData *md = propertiesAsMemberData(); + if (md) { + QV4::VariantObject *v = (md->data() + id)->as(); if (!v) { - QV4::ScopedValue svo(scope, properties.engine()->newVariantObject(QVariant())); - o->putIndexed(id, svo); - svo = o->getIndexed(id); - v = svo->as(); + *(md->data() + id) = properties.engine()->newVariantObject(QVariant()); + v = (md->data() + id)->as(); } QQmlValueTypeProvider().initValueType(t, v->d()->data); needActivate = !QQml_valueTypeProvider()->equalValueType(t, a[0], v->d()->data); @@ -907,34 +861,25 @@ QV4::ReturnedValue QQmlVMEMetaObject::readVarProperty(int id) { Q_ASSERT(id >= firstVarPropertyIndex); - if (ensurePropertiesAllocated()) { - QV4::Scope scope(properties.engine()); - QV4::ScopedObject o(scope, properties.value()); - return o->getIndexed(id); - } + QV4::MemberData *md = propertiesAsMemberData(); + if (md) + return (md->data() + id)->asReturnedValue(); return QV4::Primitive::undefinedValue().asReturnedValue(); } QVariant QQmlVMEMetaObject::readPropertyAsVariant(int id) { if (id >= firstVarPropertyIndex) { - if (ensurePropertiesAllocated()) { - QV4::ExecutionEngine *v4 = properties.engine(); - QV4::Scope scope(v4); - QV4::ScopedObject o(scope, properties.value()); - QV4::ScopedValue val(scope, o->getIndexed(id)); - return scope.engine->toVariant(val, -1); - } + QV4::MemberData *md = propertiesAsMemberData(); + if (md) + return properties.engine()->toVariant(*(md->data() + id), -1); } else { - if (ensurePropertiesAllocated()) { - QV4::ExecutionEngine *v4 = properties.engine(); - QV4::Scope scope(v4); - QV4::ScopedObject o(scope, properties.value()); - QV4::ScopedValue sv(scope, o->getIndexed(id)); - const QV4::QObjectWrapper *wrapper = sv->as(); + QV4::MemberData *md = propertiesAsMemberData(); + if (md) { + const QV4::QObjectWrapper *wrapper = (md->data() + id)->as(); if (wrapper) return QVariant::fromValue(wrapper->object()); - const QV4::VariantObject *v = sv->as(); + const QV4::VariantObject *v = (md->data() + id)->as(); if (!v) { writeProperty(id, QVariant()); return QVariant(); @@ -948,72 +893,66 @@ QVariant QQmlVMEMetaObject::readPropertyAsVariant(int id) void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::Value &value) { Q_ASSERT(id >= firstVarPropertyIndex); - if (!ensurePropertiesAllocated()) + QV4::MemberData *md = propertiesAsMemberData(); + if (!md) return; - QV4::Scope scope(properties.engine()); // Importantly, if the current value is a scarce resource, we need to ensure that it // gets automatically released by the engine if no other references to it exist. - QV4::ScopedObject vp(scope, properties.value()); - QV4::Scoped oldv(scope, vp->getIndexed(id)); - if (!!oldv) - oldv->removeVmePropertyReference(); + QV4::VariantObject *oldVariant = (md->data() + id)->as(); + if (oldVariant) + oldVariant->removeVmePropertyReference(); QObject *valueObject = 0; QQmlVMEVariantQObjectPtr *guard = getQObjectGuardForProperty(id); - QV4::ScopedObject o(scope, value); - if (o) { - // And, if the new value is a scarce resource, we need to ensure that it does not get - // automatically released by the engine until no other references to it exist. - if (QV4::VariantObject *v = o->as()) { - v->addVmePropertyReference(); - } else if (QV4::QObjectWrapper *wrapper = o->as()) { - // We need to track this QObject to signal its deletion - valueObject = wrapper->object(); - - // Do we already have a QObject guard for this property? - if (valueObject && !guard) { - guard = new QQmlVMEVariantQObjectPtr(true); - varObjectGuards.append(guard); - } + // And, if the new value is a scarce resource, we need to ensure that it does not get + // automatically released by the engine until no other references to it exist. + if (QV4::VariantObject *v = const_cast(value.as())) { + v->addVmePropertyReference(); + } else if (QV4::QObjectWrapper *wrapper = const_cast(value.as())) { + // We need to track this QObject to signal its deletion + valueObject = wrapper->object(); + + // Do we already have a QObject guard for this property? + if (valueObject && !guard) { + guard = new QQmlVMEVariantQObjectPtr(true); + varObjectGuards.append(guard); } } - if (guard) { + if (guard) guard->setGuardedValue(valueObject, this, id); - } // Write the value and emit change signal as appropriate. - vp->putIndexed(id, value); + *(md->data() + id) = value; activate(object, methodOffset() + id, 0); } void QQmlVMEMetaObject::writeProperty(int id, const QVariant &value) { if (id >= firstVarPropertyIndex) { - if (!ensurePropertiesAllocated()) + QV4::MemberData *md = propertiesAsMemberData(); + if (!md) return; - QV4::Scope scope(properties.engine()); - // Importantly, if the current value is a scarce resource, we need to ensure that it // gets automatically released by the engine if no other references to it exist. - QV4::ScopedObject vp(scope, properties.value()); - QV4::Scoped oldv(scope, vp->getIndexed(id)); - if (!!oldv) + QV4::VariantObject *oldv = (md->data() + id)->as(); + if (oldv) oldv->removeVmePropertyReference(); // And, if the new value is a scarce resource, we need to ensure that it does not get // automatically released by the engine until no other references to it exist. - QV4::ScopedValue newv(scope, scope.engine->fromVariant(value)); + QV4::Scope scope(properties.engine()); + QV4::ScopedValue newv(scope, properties.engine()->fromVariant(value)); QV4::Scoped v(scope, newv); if (!!v) v->addVmePropertyReference(); // Write the value and emit change signal as appropriate. QVariant currentValue = readPropertyAsVariant(id); - vp->putIndexed(id, newv); + *(md->data() + id) = newv; if ((currentValue.userType() != value.userType() || currentValue != value)) activate(object, methodOffset() + id, 0); } else { @@ -1023,21 +962,17 @@ void QQmlVMEMetaObject::writeProperty(int id, const QVariant &value) needActivate = readPropertyAsQObject(id) != o; // TODO: still correct? writeProperty(id, o); } else { - if (ensurePropertiesAllocated()) { - QV4::ExecutionEngine *v4 = properties.engine(); - QV4::Scope scope(v4); - QV4::ScopedObject o(scope, properties.value()); - QV4::ScopedValue sv(scope, o->getIndexed(id)); - QV4::VariantObject *v = sv->as(); + QV4::MemberData *md = propertiesAsMemberData(); + if (md) { + QV4::VariantObject *v = (md->data() + id)->as(); needActivate = (!v || v->d()->data.userType() != value.userType() || v->d()->data != value); if (v) v->removeVmePropertyReference(); - - QV4::Scoped svo(scope, properties.engine()->newVariantObject(value)); - svo->addVmePropertyReference(); - o->putIndexed(id, svo); + *(md->data() + id) = properties.engine()->newVariantObject(value); + v = static_cast(md->data() + id); + v->addVmePropertyReference(); } } @@ -1185,8 +1120,7 @@ void QQmlVMEMetaObject::allocateProperties() QQmlEngine *qml = qmlEngine(object); Q_ASSERT(qml); QV4::ExecutionEngine *v4 = QV8Engine::getV4(qml->handle()); - QV4::Scope scope(v4); - properties.set(scope.engine, v4->newArrayObject(metaData->propertyCount)); + properties.set(v4, QV4::MemberData::reallocate(v4, 0, metaData->propertyCount)); propertiesInitialized = true; } diff --git a/src/qml/qml/qqmlvmemetaobject_p.h b/src/qml/qml/qqmlvmemetaobject_p.h index a399b072ff..5f688fe2e7 100644 --- a/src/qml/qml/qqmlvmemetaobject_p.h +++ b/src/qml/qml/qqmlvmemetaobject_p.h @@ -203,6 +203,7 @@ public: bool propertiesInitialized; inline void allocateProperties(); inline bool ensurePropertiesAllocated(); + QV4::MemberData *propertiesAsMemberData(); int readPropertyAsInt(int id); bool readPropertyAsBool(int id); -- cgit v1.2.3 From 3d4795b7d109d99726e17446d933bae1e22bb751 Mon Sep 17 00:00:00 2001 From: Frank Meerkoetter Date: Fri, 7 Aug 2015 22:47:40 +0200 Subject: Allocate a JS wrapper if there are any properties Properties are now stored as QV4::Values. Change-Id: I586ccacbeb3c131ff4af2e5913c484dc4f4b7462 Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlvmemetaobject.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 6a12674fb0..c7993e6ec7 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -171,10 +171,10 @@ QQmlVMEMetaObject::QQmlVMEMetaObject(QObject *obj, int list_type = qMetaTypeId >(); int qobject_type = qMetaTypeId(); int variant_type = qMetaTypeId(); - // Need JS wrapper to ensure variant and var properties are marked. + // Need JS wrapper to ensure properties are marked. // ### FIXME: I hope that this can be removed once we have the proper scope chain // set up and the JS wrappers always exist. - bool needsJSWrapper = (metaData->varPropertyCount > 0); + bool needsJSWrapper = (metaData->propertyCount > 0); // ### Optimize for (int ii = 0; ii < metaData->propertyCount - metaData->varPropertyCount; ++ii) { -- cgit v1.2.3 From 92ec000e5581b22b0313c9fc80c258feeb7a025f Mon Sep 17 00:00:00 2001 From: Frank Meerkoetter Date: Fri, 7 Aug 2015 22:55:52 +0200 Subject: Remove special case for var properties In the new world order all the properties are QV4::Values. Therefore this special handling can be removed. Change-Id: Ia4d703256db7330936cd16a835d16d140adfe20e Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlvmemetaobject.cpp | 11 +++++------ src/qml/qml/qqmlvmemetaobject_p.h | 5 ++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index c7993e6ec7..89e8792b9f 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -52,8 +52,8 @@ QT_BEGIN_NAMESPACE -QQmlVMEVariantQObjectPtr::QQmlVMEVariantQObjectPtr(bool isVar) - : QQmlGuard(0), m_target(0), m_isVar(isVar), m_index(-1) +QQmlVMEVariantQObjectPtr::QQmlVMEVariantQObjectPtr() + : QQmlGuard(0), m_target(0), m_index(-1) { } @@ -64,8 +64,7 @@ QQmlVMEVariantQObjectPtr::~QQmlVMEVariantQObjectPtr() void QQmlVMEVariantQObjectPtr::objectDestroyed(QObject *) { if (m_target && m_index >= 0) { - // Set the var property to NULL - if (m_isVar && m_target->propertiesInitialized && !m_target->properties.isUndefined()) { + if (m_target->propertiesInitialized && !m_target->properties.isUndefined()) { QV4::ExecutionEngine *v4 = m_target->properties.engine(); if (v4) { QV4::Scope scope(v4); @@ -303,7 +302,7 @@ void QQmlVMEMetaObject::writeProperty(int id, QObject* v) QQmlVMEVariantQObjectPtr *guard = getQObjectGuardForProperty(id); if (v && !guard) { - guard = new QQmlVMEVariantQObjectPtr(true); + guard = new QQmlVMEVariantQObjectPtr(); varObjectGuards.append(guard); } if (guard) @@ -916,7 +915,7 @@ void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::Value &value) // Do we already have a QObject guard for this property? if (valueObject && !guard) { - guard = new QQmlVMEVariantQObjectPtr(true); + guard = new QQmlVMEVariantQObjectPtr(); varObjectGuards.append(guard); } } diff --git a/src/qml/qml/qqmlvmemetaobject_p.h b/src/qml/qml/qqmlvmemetaobject_p.h index 5f688fe2e7..5d4d7055a1 100644 --- a/src/qml/qml/qqmlvmemetaobject_p.h +++ b/src/qml/qml/qqmlvmemetaobject_p.h @@ -136,15 +136,14 @@ class QQmlVMEMetaObject; class QQmlVMEVariantQObjectPtr : public QQmlGuard { public: - inline QQmlVMEVariantQObjectPtr(bool isVar); + inline QQmlVMEVariantQObjectPtr(); inline ~QQmlVMEVariantQObjectPtr(); inline void objectDestroyed(QObject *); inline void setGuardedValue(QObject *obj, QQmlVMEMetaObject *target, int index); QQmlVMEMetaObject *m_target; - unsigned m_isVar : 1; // TODO: remove? - int m_index : 31; + int m_index; }; class QQmlVMEVariant; -- cgit v1.2.3 From eadad29f9c71135378c9b92f97e140837542a469 Mon Sep 17 00:00:00 2001 From: Frank Meerkoetter Date: Fri, 7 Aug 2015 23:14:21 +0200 Subject: Use the proper static ValueTypeProvider as intended This was triggering an assertion while running the unit tests. Change-Id: I53a0216a6861a7ab7e3ec89a2b8bda0605b38aaa Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlvmemetaobject.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 89e8792b9f..56d566687b 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -700,7 +700,7 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) *(md->data() + id) = properties.engine()->newVariantObject(QVariant()); v = (md->data() + id)->as(); } - QQmlValueTypeProvider().initValueType(t, v->d()->data); + QQml_valueTypeProvider()->initValueType(t, v->d()->data); needActivate = !QQml_valueTypeProvider()->equalValueType(t, a[0], v->d()->data); QQml_valueTypeProvider()->writeValueType(t, a[0], v->d()->data); } -- cgit v1.2.3 From 0ed9784082b1e21cd8fcc49ef4afbe52af3fdef4 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 10 Aug 2015 11:54:51 +0200 Subject: Properly initialize the memberdata to undefined This avoids running into assertions in other places. Change-Id: Ia7f9dbdccdd6d3a338845754801e881d44efebb7 Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlvmemetaobject.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 56d566687b..08c5ed4f9e 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -1119,7 +1119,10 @@ void QQmlVMEMetaObject::allocateProperties() QQmlEngine *qml = qmlEngine(object); Q_ASSERT(qml); QV4::ExecutionEngine *v4 = QV8Engine::getV4(qml->handle()); - properties.set(v4, QV4::MemberData::reallocate(v4, 0, metaData->propertyCount)); + QV4::Heap::MemberData *data = QV4::MemberData::reallocate(v4, 0, metaData->propertyCount); + properties.set(v4, data); + for (uint i = 0; i < data->size; ++i) + data->data[i] = QV4::Encode::undefined(); propertiesInitialized = true; } -- cgit v1.2.3 From 6cd0001054faa9c7c20dcd5e9c7512367b2c1f5f Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 10 Aug 2015 13:39:32 +0200 Subject: Get rid of special handling of var properties These can be handled in a simple way now by using a special propertyType value indicating that we have a var property. Also remove the additional write calls in the different readProperty implementations. If the stored data doesn't match, we can simply return the default value directly. Change-Id: I3823a971df24bd78f0acdc4c0042776277b3c55f Reviewed-by: Simon Hausmann --- src/qml/compiler/qqmltypecompiler.cpp | 33 ++------- src/qml/qml/qqmlvmemetaobject.cpp | 84 +++++++--------------- src/qml/qml/qqmlvmemetaobject_p.h | 6 +- src/quick/designer/qqmldesignermetaobject.cpp | 4 +- .../auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 6 ++ 5 files changed, 43 insertions(+), 90 deletions(-) diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp index 307f945d20..80aa617c53 100644 --- a/src/qml/compiler/qqmltypecompiler.cpp +++ b/src/qml/compiler/qqmltypecompiler.cpp @@ -780,15 +780,18 @@ bool QQmlPropertyCacheCreator::createMetaObject(int objectIndex, const QmlIR::Ob int propertyIdx = 0; for (const QmlIR::Property *p = obj->firstProperty(); p; p = p->next, ++propertyIdx) { - if (p->type == QV4::CompiledData::Property::Alias || - p->type == QV4::CompiledData::Property::Var) + if (p->type == QV4::CompiledData::Property::Alias) continue; int propertyType = 0; int vmePropertyType = 0; quint32 propertyFlags = 0; - if (p->type < builtinTypeCount) { + if (p->type == QV4::CompiledData::Property::Var) { + propertyType = QMetaType::QVariant; + vmePropertyType = QQmlVMEMetaData::VarPropertyType; + propertyFlags = QQmlPropertyData::IsVarProperty; + } else if (p->type < builtinTypeCount) { propertyType = builtinTypes[p->type].metaType; vmePropertyType = propertyType; @@ -852,30 +855,6 @@ bool QQmlPropertyCacheCreator::createMetaObject(int objectIndex, const QmlIR::Ob vmd->propertyCount++; } - // Now do var properties - propertyIdx = 0; - for (const QmlIR::Property *p = obj->firstProperty(); p; p = p->next, ++propertyIdx) { - - if (p->type != QV4::CompiledData::Property::Var) - continue; - - quint32 propertyFlags = QQmlPropertyData::IsVarProperty; - if (!(p->flags & QV4::CompiledData::Property::IsReadOnly)) - propertyFlags |= QQmlPropertyData::IsWritable; - - VMD *vmd = (QQmlVMEMetaData *)dynamicData.data(); - (vmd->propertyData() + vmd->propertyCount)->propertyType = QMetaType::QVariant; - vmd->propertyCount++; - ((QQmlVMEMetaData *)dynamicData.data())->varPropertyCount++; - - QString propertyName = stringAt(p->nameIndex); - if (propertyIdx == obj->indexOfDefaultProperty) cache->_defaultPropertyName = propertyName; - cache->appendProperty(propertyName, propertyFlags, effectivePropertyIndex++, - QMetaType::QVariant, effectiveSignalIndex); - - effectiveSignalIndex++; - } - // Alias property count. Actual data is setup in buildDynamicMetaAliases ((QQmlVMEMetaData *)dynamicData.data())->aliasCount = aliasCount; diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 08c5ed4f9e..ab3303769f 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -151,7 +151,7 @@ QQmlVMEMetaObject::QQmlVMEMetaObject(QObject *obj, const QQmlVMEMetaData *meta, QV4::ExecutionContext *qmlBindingContext, QQmlCompiledData *compiledData) : object(obj), ctxt(QQmlData::get(obj, true)->outerContext), cache(cache), metaData(meta), - hasAssignedMetaObjectData(false), aliasEndpoints(0), firstVarPropertyIndex(-1), + hasAssignedMetaObjectData(false), aliasEndpoints(0), propertiesInitialized(false), interceptors(0), v8methods(0) { QObjectPrivate *op = QObjectPrivate::get(obj); @@ -176,7 +176,7 @@ QQmlVMEMetaObject::QQmlVMEMetaObject(QObject *obj, bool needsJSWrapper = (metaData->propertyCount > 0); // ### Optimize - for (int ii = 0; ii < metaData->propertyCount - metaData->varPropertyCount; ++ii) { + for (int ii = 0; ii < metaData->propertyCount; ++ii) { int t = (metaData->propertyData() + ii)->propertyType; if (t == list_type) { listProperties.append(List(methodOffset() + ii, this)); @@ -186,8 +186,6 @@ QQmlVMEMetaObject::QQmlVMEMetaObject(QObject *obj, } } - firstVarPropertyIndex = metaData->propertyCount - metaData->varPropertyCount; - if (needsJSWrapper) ensureQObjectWrapper(); @@ -317,10 +315,8 @@ int QQmlVMEMetaObject::readPropertyAsInt(int id) QV4::Scope scope(properties.engine()); QV4::ScopedValue sv(scope, *(md->data() + id)); - if (!sv->isInt32()) { - writeProperty(id, int(0)); + if (!sv->isInt32()) return 0; - } return sv->integerValue(); } @@ -332,10 +328,8 @@ bool QQmlVMEMetaObject::readPropertyAsBool(int id) QV4::Scope scope(properties.engine()); QV4::ScopedValue sv(scope, *(md->data() + id)); - if (!sv->isBoolean()) { - writeProperty(id, false); + if (!sv->isBoolean()) return false; - } return sv->booleanValue(); } @@ -347,10 +341,8 @@ double QQmlVMEMetaObject::readPropertyAsDouble(int id) QV4::Scope scope(properties.engine()); QV4::ScopedValue sv(scope, *(md->data() + id)); - if (!sv->isDouble()) { - writeProperty(id, 0.0); + if (!sv->isDouble()) return 0.0; - } return sv->doubleValue(); } @@ -362,10 +354,8 @@ QString QQmlVMEMetaObject::readPropertyAsString(int id) QV4::Scope scope(properties.engine()); QV4::ScopedValue sv(scope, *(md->data() + id)); - if (!sv->isString()) { - writeProperty(id, QString()); + if (!sv->isString()) return QString(); - } return sv->stringValue()->toQString(); } @@ -378,10 +368,8 @@ QUrl QQmlVMEMetaObject::readPropertyAsUrl(int id) QV4::Scope scope(properties.engine()); QV4::ScopedValue sv(scope, *(md->data() + id)); const QV4::VariantObject *v = sv->as(); - if (!v || v->d()->data.type() != QVariant::Url) { - writeProperty(id, QUrl()); + if (!v || v->d()->data.type() != QVariant::Url) return QUrl(); - } return v->d()->data.value(); } @@ -394,10 +382,8 @@ QDate QQmlVMEMetaObject::readPropertyAsDate(int id) QV4::Scope scope(properties.engine()); QV4::ScopedValue sv(scope, *(md->data() + id)); const QV4::VariantObject *v = sv->as(); - if (!v || v->d()->data.type() != QVariant::Date) { - writeProperty(id, QDate()); + if (!v || v->d()->data.type() != QVariant::Date) return QDate(); - } return v->d()->data.value(); } @@ -410,10 +396,8 @@ QDateTime QQmlVMEMetaObject::readPropertyAsDateTime(int id) QV4::Scope scope(properties.engine()); QV4::ScopedValue sv(scope, *(md->data() + id)); const QV4::VariantObject *v = sv->as(); - if (!v || v->d()->data.type() != QVariant::DateTime) { - writeProperty(id, QDateTime()); + if (!v || v->d()->data.type() != QVariant::DateTime) return QDateTime(); - } return v->d()->data.value(); } @@ -426,10 +410,8 @@ QSizeF QQmlVMEMetaObject::readPropertyAsSizeF(int id) QV4::Scope scope(properties.engine()); QV4::ScopedValue sv(scope, *(md->data() + id)); const QV4::VariantObject *v = sv->as(); - if (!v || v->d()->data.type() != QVariant::SizeF) { - writeProperty(id, QSizeF()); + if (!v || v->d()->data.type() != QVariant::SizeF) return QSizeF(); - } return v->d()->data.value(); } @@ -442,10 +424,8 @@ QPointF QQmlVMEMetaObject::readPropertyAsPointF(int id) QV4::Scope scope(properties.engine()); QV4::ScopedValue sv(scope, *(md->data() + id)); const QV4::VariantObject *v = sv->as(); - if (!v || v->d()->data.type() != QVariant::PointF) { - writeProperty(id, QPointF()); + if (!v || v->d()->data.type() != QVariant::PointF) return QPointF(); - } return v->d()->data.value(); } @@ -458,10 +438,8 @@ QObject* QQmlVMEMetaObject::readPropertyAsQObject(int id) QV4::Scope scope(properties.engine()); QV4::ScopedValue sv(scope, *(md->data() + id)); const QV4::QObjectWrapper *wrapper = sv->as(); - if (!wrapper) { - writeProperty(id, static_cast(Q_NULLPTR)); + if (!wrapper) return 0; - } return wrapper->object(); } @@ -474,10 +452,8 @@ QRectF QQmlVMEMetaObject::readPropertyAsRectF(int id) QV4::Scope scope(properties.engine()); QV4::ScopedValue sv(scope, *(md->data() + id)); const QV4::VariantObject *v = sv->as(); - if (!v || v->d()->data.type() != QVariant::RectF) { - writeProperty(id, QRectF()); + if (!v || v->d()->data.type() != QVariant::RectF) return QRectF(); - } return v->d()->data.value(); } @@ -566,8 +542,7 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) int t = (metaData->propertyData() + id)->propertyType; bool needActivate = false; - if (id >= firstVarPropertyIndex) { - Q_ASSERT(t == QMetaType::QVariant); + if (t == QQmlVMEMetaData::VarPropertyType) { // the context can be null if accessing var properties from cpp after re-parenting an item. QQmlEnginePrivate *ep = (ctxt == 0 || ctxt->engine == 0) ? 0 : QQmlEnginePrivate::get(ctxt->engine); QV8Engine *v8e = (ep == 0) ? 0 : ep->v8engine(); @@ -858,7 +833,7 @@ QV4::ReturnedValue QQmlVMEMetaObject::method(int index) QV4::ReturnedValue QQmlVMEMetaObject::readVarProperty(int id) { - Q_ASSERT(id >= firstVarPropertyIndex); + Q_ASSERT((metaData->propertyData() + id)->propertyType == QQmlVMEMetaData::VarPropertyType); QV4::MemberData *md = propertiesAsMemberData(); if (md) @@ -868,30 +843,23 @@ QV4::ReturnedValue QQmlVMEMetaObject::readVarProperty(int id) QVariant QQmlVMEMetaObject::readPropertyAsVariant(int id) { - if (id >= firstVarPropertyIndex) { - QV4::MemberData *md = propertiesAsMemberData(); - if (md) - return properties.engine()->toVariant(*(md->data() + id), -1); - } else { - QV4::MemberData *md = propertiesAsMemberData(); - if (md) { - const QV4::QObjectWrapper *wrapper = (md->data() + id)->as(); - if (wrapper) - return QVariant::fromValue(wrapper->object()); - const QV4::VariantObject *v = (md->data() + id)->as(); - if (!v) { - writeProperty(id, QVariant()); - return QVariant(); - } + QV4::MemberData *md = propertiesAsMemberData(); + if (md) { + const QV4::QObjectWrapper *wrapper = (md->data() + id)->as(); + if (wrapper) + return QVariant::fromValue(wrapper->object()); + const QV4::VariantObject *v = (md->data() + id)->as(); + if (v) return v->d()->data; - } + return properties.engine()->toVariant(*(md->data() + id), -1); } return QVariant(); } void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::Value &value) { - Q_ASSERT(id >= firstVarPropertyIndex); + Q_ASSERT((metaData->propertyData() + id)->propertyType == QQmlVMEMetaData::VarPropertyType); + QV4::MemberData *md = propertiesAsMemberData(); if (!md) return; @@ -930,7 +898,7 @@ void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::Value &value) void QQmlVMEMetaObject::writeProperty(int id, const QVariant &value) { - if (id >= firstVarPropertyIndex) { + if ((metaData->propertyData() + id)->propertyType == QQmlVMEMetaData::VarPropertyType) { QV4::MemberData *md = propertiesAsMemberData(); if (!md) return; diff --git a/src/qml/qml/qqmlvmemetaobject_p.h b/src/qml/qml/qqmlvmemetaobject_p.h index 5d4d7055a1..3f289c2cc6 100644 --- a/src/qml/qml/qqmlvmemetaobject_p.h +++ b/src/qml/qml/qqmlvmemetaobject_p.h @@ -72,7 +72,6 @@ QT_BEGIN_NAMESPACE struct QQmlVMEMetaData { - short varPropertyCount; short propertyCount; short aliasCount; short signalCount; @@ -109,6 +108,10 @@ struct QQmlVMEMetaData } }; + enum { + VarPropertyType = -1 + }; + struct PropertyData { int propertyType; }; @@ -198,7 +201,6 @@ public: QQmlVMEMetaObjectEndpoint *aliasEndpoints; QV4::WeakValue properties; - int firstVarPropertyIndex; bool propertiesInitialized; inline void allocateProperties(); inline bool ensurePropertiesAllocated(); diff --git a/src/quick/designer/qqmldesignermetaobject.cpp b/src/quick/designer/qqmldesignermetaobject.cpp index 4273c0fbc2..e80012ba35 100644 --- a/src/quick/designer/qqmldesignermetaobject.cpp +++ b/src/quick/designer/qqmldesignermetaobject.cpp @@ -75,8 +75,7 @@ struct MetaPropertyData { static bool constructedMetaData(const QQmlVMEMetaData* data) { - return data->varPropertyCount == 0 - && data->propertyCount == 0 + return data->propertyCount == 0 && data->aliasCount == 0 && data->signalCount == 0 && data->methodCount == 0; @@ -85,7 +84,6 @@ static bool constructedMetaData(const QQmlVMEMetaData* data) static QQmlVMEMetaData* fakeMetaData() { QQmlVMEMetaData* data = new QQmlVMEMetaData; - data->varPropertyCount = 0; data->propertyCount = 0; data->aliasCount = 0; data->signalCount = 0; diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 8bb9ddc07e..b524b30e1a 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -5007,6 +5007,12 @@ void tst_qqmlecmascript::propertyVarCircular() QObject *object = component.create(); QVERIFY(object != 0); QMetaObject::invokeMethod(object, "assignCircular"); // cause assignment and gc + { + QCOMPARE(object->property("canaryInt"), QVariant(5)); + QVariant canaryResourceVariant = object->property("canaryResource"); + QVERIFY(canaryResourceVariant.isValid()); + } + QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); // process deleteLater() events from QV8QObjectWrapper. QCoreApplication::processEvents(); QCOMPARE(object->property("canaryInt"), QVariant(5)); -- cgit v1.2.3 From 7fccfc4663c362d717383493732849237562f0c7 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 10 Aug 2015 14:49:07 +0200 Subject: Fix test case After the latest changes to the VMEMO, JS declared properties will not be available after the engine is deleted. Change-Id: Ifc6034bd0dff18d26863ca9bcf7a19e1c7d68ff6 Reviewed-by: Simon Hausmann --- tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index b524b30e1a..133fadb69a 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -5709,9 +5709,10 @@ void tst_qqmlecmascript::deletedEngine() delete engine; - QCOMPARE(object->property("a").toInt(), 117); + QCOMPARE(object->property("a").toInt(), 0); object->setProperty("b", QVariant(10)); - QCOMPARE(object->property("a").toInt(), 117); + object->setProperty("b", QVariant()); + QCOMPARE(object->property("a").toInt(), 0); delete object; } -- cgit v1.2.3 From 4876ea6a18ccdfd72014582aa5d50ab9f6b6ec9e Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Sat, 15 Aug 2015 01:31:13 +0200 Subject: Fix performance of ListModel::get() When called, the function would return a full-fledged QObject that maps the list element addressed. It would contain a _copy_ of all values in the list item and it would create a new meta-object for each list element. This function exists for the JavaScript API, and therefore we now return a much more lightweight object. For compatbility reasons it still has to be a QObject, but the meta-object of it is created on-demand, i.e. only when accessing properties from the C++ side or when connecting to the changed signal of a property. Otherwise the JavaScript wrapper will return the live values from the model without copying them. Change-Id: Iabf3ca22192d2aee06ae9d4b4cfb2fcde2a021b1 Reviewed-by: Lars Knoll Reviewed-by: Michael Brasser Reviewed-by: Spencer Schumann --- src/qml/jsruntime/qv4qobjectwrapper_p.h | 1 - src/qml/memory/qv4mm.cpp | 6 +- src/qml/qml/qqmlopenmetaobject.cpp | 30 +++++++ src/qml/qml/qqmlopenmetaobject_p.h | 3 + src/qml/types/qqmllistmodel.cpp | 154 +++++++++++++++++++++++++------- src/qml/types/qqmllistmodel_p.h | 5 ++ src/qml/types/qqmllistmodel_p_p.h | 77 ++++++++++------ 7 files changed, 213 insertions(+), 63 deletions(-) diff --git a/src/qml/jsruntime/qv4qobjectwrapper_p.h b/src/qml/jsruntime/qv4qobjectwrapper_p.h index 2d10006d97..542d908194 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper_p.h +++ b/src/qml/jsruntime/qv4qobjectwrapper_p.h @@ -123,7 +123,6 @@ struct Q_QML_EXPORT QObjectWrapper : public Object protected: static bool isEqualTo(Managed *that, Managed *o); -private: static ReturnedValue getProperty(ExecutionEngine *engine, QObject *object, QQmlPropertyData *property, bool captureRequired = true); static void setProperty(ExecutionEngine *engine, QObject *object, QQmlPropertyData *property, const Value &value); diff --git a/src/qml/memory/qv4mm.cpp b/src/qml/memory/qv4mm.cpp index 38b4e1eaf1..b880c9c8d5 100644 --- a/src/qml/memory/qv4mm.cpp +++ b/src/qml/memory/qv4mm.cpp @@ -373,7 +373,7 @@ void MemoryManager::mark() for (PersistentValueStorage::Iterator it = m_weakValues->begin(); it != m_weakValues->end(); ++it) { if (!(*it).isManaged()) continue; - if ((*it).managed()->d()->vtable() != QObjectWrapper::staticVTable()) + if (!(*it).as()) continue; QObjectWrapper *qobjectWrapper = static_cast((*it).managed()); QObject *qobject = qobjectWrapper->object(); @@ -410,10 +410,8 @@ void MemoryManager::sweep(bool lastSweep) continue; // we need to call detroyObject on qobjectwrappers now, so that they can emit the destroyed // signal before we start sweeping the heap - if ((*it).managed()->d()->vtable() == QObjectWrapper::staticVTable()) { - QObjectWrapper *qobjectWrapper = static_cast((*it).managed()); + if (QObjectWrapper *qobjectWrapper = (*it).as()) qobjectWrapper->destroyObject(lastSweep); - } (*it) = Primitive::undefinedValue(); } diff --git a/src/qml/qml/qqmlopenmetaobject.cpp b/src/qml/qml/qqmlopenmetaobject.cpp index c6d2d44ee1..777bb0c5e1 100644 --- a/src/qml/qml/qqmlopenmetaobject.cpp +++ b/src/qml/qml/qqmlopenmetaobject.cpp @@ -106,6 +106,28 @@ QMetaObject *QQmlOpenMetaObjectType::metaObject() const return d->mem; } +void QQmlOpenMetaObjectType::createProperties(const QVector &names) +{ + for (int i = 0; i < names.count(); ++i) { + const QByteArray &name = names.at(i); + const int id = d->mob.propertyCount(); + d->mob.addSignal("__" + QByteArray::number(id) + "()"); + QMetaPropertyBuilder build = d->mob.addProperty(name, "QVariant", id); + propertyCreated(id, build); + d->names.insert(name, id); + } + free(d->mem); + d->mem = d->mob.toMetaObject(); + QSet::iterator it = d->referers.begin(); + while (it != d->referers.end()) { + QQmlOpenMetaObject *omo = *it; + *static_cast(omo) = *d->mem; + if (d->cache) + d->cache->update(omo); + ++it; + } +} + int QQmlOpenMetaObjectType::createProperty(const QByteArray &name) { int id = d->mob.propertyCount(); @@ -230,6 +252,14 @@ QQmlOpenMetaObjectType *QQmlOpenMetaObject::type() const return d->type; } +void QQmlOpenMetaObject::emitPropertyNotification(const QByteArray &propertyName) +{ + QHash::ConstIterator iter = d->type->d->names.constFind(propertyName); + if (iter == d->type->d->names.constEnd()) + return; + activate(d->object, *iter + d->type->d->signalOffset, 0); +} + int QQmlOpenMetaObject::metaCall(QMetaObject::Call c, int id, void **a) { if (( c == QMetaObject::ReadProperty || c == QMetaObject::WriteProperty) diff --git a/src/qml/qml/qqmlopenmetaobject_p.h b/src/qml/qml/qqmlopenmetaobject_p.h index 6a29d08d4e..75ce9addd6 100644 --- a/src/qml/qml/qqmlopenmetaobject_p.h +++ b/src/qml/qml/qqmlopenmetaobject_p.h @@ -54,6 +54,7 @@ public: QQmlOpenMetaObjectType(const QMetaObject *base, QQmlEngine *engine); ~QQmlOpenMetaObjectType(); + void createProperties(const QVector &names); int createProperty(const QByteArray &name); int propertyOffset() const; @@ -101,6 +102,8 @@ public: QQmlOpenMetaObjectType *type() const; + void emitPropertyNotification(const QByteArray &propertyName); + protected: virtual int metaCall(QMetaObject::Call _c, int _id, void **_a); virtual int createProperty(const char *, const char *); diff --git a/src/qml/types/qqmllistmodel.cpp b/src/qml/types/qqmllistmodel.cpp index de46020ad8..799f7a0b8a 100644 --- a/src/qml/types/qqmllistmodel.cpp +++ b/src/qml/types/qqmllistmodel.cpp @@ -242,11 +242,12 @@ const ListLayout::Role *ListLayout::getExistingRole(QV4::String *key) return r; } -ModelObject *ListModel::getOrCreateModelObject(QQmlListModel *model, int elementIndex) +QObject *ListModel::getOrCreateModelObject(QQmlListModel *model, int elementIndex) { ListElement *e = elements[elementIndex]; if (e->m_objectCache == 0) { - e->m_objectCache = new ModelObject(model, elementIndex); + e->m_objectCache = new QObject; + (void)new ModelNodeMetaObject(e->m_objectCache, model, elementIndex); } return e->m_objectCache; } @@ -317,8 +318,8 @@ void ListModel::sync(ListModel *src, ListModel *target, QHash // Update values stored in target meta objects for (int i=0 ; i < target->elements.count() ; ++i) { ListElement *e = target->elements[i]; - if (e->m_objectCache) - e->m_objectCache->updateValues(); + if (ModelNodeMetaObject *mo = e->objectCache()) + mo->updateValues(); } } @@ -384,9 +385,8 @@ void ListModel::updateCacheIndices() { for (int i=0 ; i < elements.count() ; ++i) { ListElement *e = elements.at(i); - if (e->m_objectCache) { - e->m_objectCache->m_elementIndex = i; - } + if (ModelNodeMetaObject *mo = e->objectCache()) + mo->m_elementIndex = i; } } @@ -470,9 +470,8 @@ void ListModel::set(int elementIndex, QV4::Object *object, QVector *roles) roles->append(roleIndex); } - if (e->m_objectCache) { - e->m_objectCache->updateValues(*roles); - } + if (ModelNodeMetaObject *mo = e->objectCache()) + mo->updateValues(*roles); } void ListModel::set(int elementIndex, QV4::Object *object) @@ -591,10 +590,12 @@ int ListModel::setOrCreateProperty(int elementIndex, const QString &key, const Q if (r) { roleIndex = e->setVariantProperty(*r, data); - if (roleIndex != -1 && e->m_objectCache) { + ModelNodeMetaObject *cache = e->objectCache(); + + if (roleIndex != -1 && cache) { QVector roles; roles << roleIndex; - e->m_objectCache->updateValues(roles); + cache->updateValues(roles); } } } @@ -633,6 +634,13 @@ inline char *ListElement::getPropertyMemory(const ListLayout::Role &role) return mem; } +ModelNodeMetaObject *ListElement::objectCache() +{ + if (!m_objectCache) + return 0; + return ModelNodeMetaObject::get(m_objectCache); +} + QString *ListElement::getStringProperty(const ListLayout::Role &role) { char *mem = getPropertyMemory(role); @@ -1209,15 +1217,48 @@ int ListElement::setJsProperty(const ListLayout::Role &role, const QV4::Value &d return roleIndex; } -ModelObject::ModelObject(QQmlListModel *model, int elementIndex) -: m_model(model), m_elementIndex(elementIndex), m_meta(new ModelNodeMetaObject(this)) +ModelNodeMetaObject::ModelNodeMetaObject(QObject *object, QQmlListModel *model, int elementIndex) +: QQmlOpenMetaObject(object), m_enabled(false), m_model(model), m_elementIndex(elementIndex), m_initialized(false) +{} + +void ModelNodeMetaObject::initialize() { + const int roleCount = m_model->m_listModel->roleCount(); + QVector properties; + properties.reserve(roleCount); + for (int i = 0 ; i < roleCount ; ++i) { + const ListLayout::Role &role = m_model->m_listModel->getExistingRole(i); + QByteArray name = role.name.toUtf8(); + properties << name; + } + type()->createProperties(properties); updateValues(); - setNodeUpdatesEnabled(true); + m_enabled = true; +} + +ModelNodeMetaObject::~ModelNodeMetaObject() +{ +} + +QAbstractDynamicMetaObject *ModelNodeMetaObject::toDynamicMetaObject(QObject *object) +{ + if (!m_initialized) { + m_initialized = true; + initialize(); + } + return QQmlOpenMetaObject::toDynamicMetaObject(object); +} + +ModelNodeMetaObject *ModelNodeMetaObject::get(QObject *obj) +{ + QObjectPrivate *op = QObjectPrivate::get(obj); + return static_cast(op->metaObject); } -void ModelObject::updateValues() +void ModelNodeMetaObject::updateValues() { + if (!m_initialized) + return; int roleCount = m_model->m_listModel->roleCount(); for (int i=0 ; i < roleCount ; ++i) { const ListLayout::Role &role = m_model->m_listModel->getExistingRole(i); @@ -1227,8 +1268,10 @@ void ModelObject::updateValues() } } -void ModelObject::updateValues(const QVector &roles) +void ModelNodeMetaObject::updateValues(const QVector &roles) { + if (!m_initialized) + return; int roleCount = roles.count(); for (int i=0 ; i < roleCount ; ++i) { int roleIndex = roles.at(i); @@ -1239,15 +1282,6 @@ void ModelObject::updateValues(const QVector &roles) } } -ModelNodeMetaObject::ModelNodeMetaObject(ModelObject *object) -: QQmlOpenMetaObject(object), m_enabled(false), m_obj(object) -{ -} - -ModelNodeMetaObject::~ModelNodeMetaObject() -{ -} - void ModelNodeMetaObject::propertyWritten(int index) { if (!m_enabled) @@ -1256,17 +1290,75 @@ void ModelNodeMetaObject::propertyWritten(int index) QString propName = QString::fromUtf8(name(index)); QVariant value = operator[](index); - QV4::Scope scope(m_obj->m_model->engine()); + QV4::Scope scope(m_model->engine()); QV4::ScopedValue v(scope, scope.engine->fromVariant(value)); - int roleIndex = m_obj->m_model->m_listModel->setExistingProperty(m_obj->m_elementIndex, propName, v, scope.engine); + int roleIndex = m_model->m_listModel->setExistingProperty(m_elementIndex, propName, v, scope.engine); + if (roleIndex != -1) { + QVector roles; + roles << roleIndex; + m_model->emitItemsChanged(m_elementIndex, 1, roles); + } +} + +namespace QV4 { + +void ModelObject::put(Managed *m, String *name, const Value &value) +{ + ModelObject *that = static_cast(m); + + ExecutionEngine *eng = that->engine(); + const int elementIndex = that->d()->m_elementIndex; + const QString propName = name->toQString(); + int roleIndex = that->d()->m_model->m_listModel->setExistingProperty(elementIndex, propName, value, eng); if (roleIndex != -1) { QVector roles; roles << roleIndex; - m_obj->m_model->emitItemsChanged(m_obj->m_elementIndex, 1, roles); + that->d()->m_model->emitItemsChanged(elementIndex, 1, roles); + } + + ModelNodeMetaObject *mo = ModelNodeMetaObject::get(that->object()); + if (mo->initialized()) + mo->emitPropertyNotification(name->toQString().toUtf8()); +} + +ReturnedValue ModelObject::get(const Managed *m, String *name, bool *hasProperty) +{ + const ModelObject *that = static_cast(m); + const ListLayout::Role *role = that->d()->m_model->m_listModel->getExistingRole(name); + if (!role) + return QObjectWrapper::get(m, name, hasProperty); + if (hasProperty) + *hasProperty = true; + const int elementIndex = that->d()->m_elementIndex; + QVariant value = that->d()->m_model->data(elementIndex, role->index); + return that->engine()->fromVariant(value); +} + +void ModelObject::advanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attributes) +{ + ModelObject *that = static_cast(m); + ExecutionEngine *v4 = that->engine(); + name->setM(0); + *index = UINT_MAX; + if (it->arrayIndex < uint(that->d()->m_model->m_listModel->roleCount())) { + Scope scope(that->engine()); + const ListLayout::Role &role = that->d()->m_model->m_listModel->getExistingRole(it->arrayIndex); + ++it->arrayIndex; + ScopedString roleName(scope, v4->newString(role.name)); + name->setM(roleName->d()); + *attributes = QV4::Attr_Data; + QVariant value = that->d()->m_model->data(that->d()->m_elementIndex, role.index); + p->value = v4->fromVariant(value); + return; } + QV4::QObjectWrapper::advanceIterator(m, it, name, index, p, attributes); } +DEFINE_OBJECT_VTABLE(ModelObject); + +} // namespace QV4 + DynamicRoleModelNode::DynamicRoleModelNode(QQmlListModel *owner, int uid) : m_owner(owner), m_uid(uid), m_meta(new DynamicRoleModelNodeMetaObject(this)) { setNodeUpdatesEnabled(true); @@ -2159,8 +2251,8 @@ QQmlV4Handle QQmlListModel::get(int index) const DynamicRoleModelNode *object = m_modelObjects[index]; result = QV4::QObjectWrapper::wrap(scope.engine, object); } else { - ModelObject *object = m_listModel->getOrCreateModelObject(const_cast(this), index); - result = QV4::QObjectWrapper::wrap(scope.engine, object); + QObject *object = m_listModel->getOrCreateModelObject(const_cast(this), index); + result = scope.engine->memoryManager->alloc(scope.engine, object, const_cast(this), index); } } diff --git a/src/qml/types/qqmllistmodel_p.h b/src/qml/types/qqmllistmodel_p.h index 75373be47c..b5a5ef3265 100644 --- a/src/qml/types/qqmllistmodel_p.h +++ b/src/qml/types/qqmllistmodel_p.h @@ -54,6 +54,10 @@ class QQmlListModelWorkerAgent; class ListModel; class ListLayout; +namespace QV4 { +struct ModelObject; +} + class Q_QML_PRIVATE_EXPORT QQmlListModel : public QAbstractListModel { Q_OBJECT @@ -94,6 +98,7 @@ private: friend class QQmlListModelParser; friend class QQmlListModelWorkerAgent; friend class ModelObject; + friend struct QV4::ModelObject; friend class ModelNodeMetaObject; friend class ListModel; friend class ListElement; diff --git a/src/qml/types/qqmllistmodel_p_p.h b/src/qml/types/qqmllistmodel_p_p.h index 4e3132b860..bd0f028e7a 100644 --- a/src/qml/types/qqmllistmodel_p_p.h +++ b/src/qml/types/qqmllistmodel_p_p.h @@ -111,56 +111,72 @@ private: friend class DynamicRoleModelNodeMetaObject; }; -class ModelObject; - class ModelNodeMetaObject : public QQmlOpenMetaObject { public: - ModelNodeMetaObject(ModelObject *object); + ModelNodeMetaObject(QObject *object, QQmlListModel *model, int elementIndex); ~ModelNodeMetaObject(); + virtual QAbstractDynamicMetaObject *toDynamicMetaObject(QObject *object); + + static ModelNodeMetaObject *get(QObject *obj); + bool m_enabled; + QQmlListModel *m_model; + int m_elementIndex; + + void updateValues(); + void updateValues(const QVector &roles); + + bool initialized() const { return m_initialized; } protected: void propertyWritten(int index); private: - - ModelObject *m_obj; -}; - -class ModelObject : public QObject -{ - Q_OBJECT -public: - ModelObject(QQmlListModel *model, int elementIndex); - + using QQmlOpenMetaObject::setValue; void setValue(const QByteArray &name, const QVariant &val, bool force) { if (force) { - QVariant existingValue = m_meta->value(name); + QVariant existingValue = value(name); if (existingValue.isValid()) { - (*m_meta)[name] = QVariant(); + (*this)[name] = QVariant(); } } - m_meta->setValue(name, val); + setValue(name, val); } - void setNodeUpdatesEnabled(bool enable) - { - m_meta->m_enabled = enable; - } + void initialize(); + bool m_initialized; +}; - void updateValues(); - void updateValues(const QVector &roles); +namespace QV4 { + +namespace Heap { +struct ModelObject : public QObjectWrapper { + ModelObject(QV4::ExecutionEngine *engine, QObject *object, QQmlListModel *model, int elementIndex) + : QObjectWrapper(engine, object) + , m_model(model) + , m_elementIndex(elementIndex) + {} QQmlListModel *m_model; int m_elementIndex; +}; -private: - ModelNodeMetaObject *m_meta; +} + +struct ModelObject : public QObjectWrapper +{ + static void put(Managed *m, String *name, const Value& value); + static ReturnedValue get(const Managed *m, String *name, bool *hasProperty); + static void advanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attributes); + + V4_OBJECT2(ModelObject, QObjectWrapper) }; +} // namespace QV4 + class ListLayout { public: @@ -236,7 +252,7 @@ public: enum { - BLOCK_SIZE = 64 - sizeof(int) - sizeof(ListElement *) - sizeof(ModelObject *) + BLOCK_SIZE = 64 - sizeof(int) - sizeof(ListElement *) - sizeof(ModelNodeMetaObject *) }; private: @@ -278,11 +294,13 @@ private: int getUid() const { return uid; } + ModelNodeMetaObject *objectCache(); + char data[BLOCK_SIZE]; ListElement *next; int uid; - ModelObject *m_objectCache; + QObject *m_objectCache; friend class ListModel; }; @@ -315,6 +333,11 @@ public: return m_layout->getExistingRole(index); } + const ListLayout::Role *getExistingRole(QV4::String *key) + { + return m_layout->getExistingRole(key); + } + const ListLayout::Role &getOrCreateListRole(const QString &name) { return m_layout->getRoleOrCreate(name, ListLayout::Role::List); @@ -343,7 +366,7 @@ public: static void sync(ListModel *src, ListModel *target, QHash *srcModelHash); - ModelObject *getOrCreateModelObject(QQmlListModel *model, int elementIndex); + QObject *getOrCreateModelObject(QQmlListModel *model, int elementIndex); private: QPODVector elements; -- cgit v1.2.3 From 653f4d6ce5851011e52c37b01ef81c7fbc16c26c Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Fri, 14 Aug 2015 14:49:54 +0200 Subject: Fix memory leak when using async image providers Change-Id: I08392ab0a3edb1ac162110ebc349ad457800c788 Reviewed-by: Robin Burchell --- src/quick/util/qquickpixmapcache.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/quick/util/qquickpixmapcache.cpp b/src/quick/util/qquickpixmapcache.cpp index 6f6e91ec99..a77bfd17d3 100644 --- a/src/quick/util/qquickpixmapcache.cpp +++ b/src/quick/util/qquickpixmapcache.cpp @@ -579,6 +579,7 @@ void QQuickPixmapReader::processJobs() if (asyncResponse) { asyncResponses.remove(asyncResponse); asyncResponse->cancel(); + asyncResponse->deleteLater(); } } PIXMAP_PROFILE(pixmapStateChanged(job->url)); -- cgit v1.2.3 From cfc73960f2d55fa141edbadea7616a7f7f947877 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Fri, 14 Aug 2015 14:51:34 +0200 Subject: Improve QQuickImageResponse::textureFactory documentation Change-Id: Id754f1f1454af566cb3cf20f5ca947f972ef2caf Reviewed-by: Robin Burchell --- src/quick/util/qquickimageprovider.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/quick/util/qquickimageprovider.cpp b/src/quick/util/qquickimageprovider.cpp index 89615a2079..5d492a4e75 100644 --- a/src/quick/util/qquickimageprovider.cpp +++ b/src/quick/util/qquickimageprovider.cpp @@ -194,8 +194,11 @@ void QQuickImageResponse::cancel() \fn QQuickTextureFactory *QQuickImageResponse::textureFactory() const Returns the texture factory for the job. You can use QQuickTextureFactory::textureFactoryForImage - if your provider works with QImage. This method is only called when the error string is not empty and the - engine takes ownership of the returned QQuickTextureFactory. + if your provider works with QImage. The engine takes ownership of the returned QQuickTextureFactory. + + \note This method will be called only when needed. For example, it may not be called if there is an + error or the job is cancelled. Therefore, allocate the QQuickTextureFactory instance only in this + method or otherwise ensure its deletion. */ -- cgit v1.2.3 From c21bc1cdef5ae0f1e6bd43ac0a6c324a59d4e34b Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 17 Aug 2015 16:54:36 +0200 Subject: V4 Debugger: Avoid special refs when looking up normal ones The "values" of "special" refs are always JavaScript "undefined"s. Thus, when trying to deduplicate an actual "undefined" we'd accidentally hit the special refs. Avoid this by checking if a found ref is special. In an ideal world we'd get rid of the special refs altogether and save QV4::FunctionObject in the values array, but that is not quite trivial as long as the QV4::ExecutionEngine::stackTrace() doesn't give us FunctionObjects. Task-number: QTBUG-47788 Change-Id: Idf358c285f40930220fad2207c6ab5c9101573b2 Reviewed-by: Simon Hausmann --- src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp index 64ee5c3b96..a44acdd370 100644 --- a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp +++ b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp @@ -236,7 +236,7 @@ QV4DataCollector::Ref QV4DataCollector::addRef(QV4::Value value, bool deduplicat QV4::ScopedObject array(scope, values.value()); if (deduplicate) { for (Ref i = 0; i < array->getLength(); ++i) { - if (array->getIndexed(i) == value.rawValue()) + if (array->getIndexed(i) == value.rawValue() && !specialRefs.contains(i)) return i; } } -- cgit v1.2.3 From b7521acd2c77f9f7ace8d49cf1e11affe2ccbd21 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 18 Aug 2015 11:14:56 +0200 Subject: V4 debugger: Fix expression evaluation We need to collect the refs in the debugService's list in order for them to show up on addRefs() and we need to generate proper error responses if either the debugger is not stopped or the evaluation throws an exception. Task-number: QTBUG-47797 Task-number: QTBUG-47816 Change-Id: I98f17c1f3976859ee50b9bfac41091276ff60982 Reviewed-by: Simon Hausmann --- .../qmldbg_debugger/qv4datacollector.cpp | 7 +++ .../qmltooling/qmldbg_debugger/qv4datacollector.h | 2 + .../qmltooling/qmldbg_debugger/qv4debugservice.cpp | 51 ++++++++++++---------- .../qmltooling/qmldbg_debugger/qv4debugservice.h | 1 + src/qml/jsruntime/qv4debugging.cpp | 10 ++++- src/qml/jsruntime/qv4debugging_p.h | 2 + 6 files changed, 48 insertions(+), 25 deletions(-) diff --git a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp index a44acdd370..01d2a98a74 100644 --- a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp +++ b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp @@ -317,9 +317,16 @@ ExpressionEvalJob::ExpressionEvalJob(QV4::ExecutionEngine *engine, int frameNr, void ExpressionEvalJob::handleResult(QV4::ScopedValue &result) { + if (hasExeption()) + exception = result->toQStringNoThrow(); collector->collect(result); } +const QString &ExpressionEvalJob::exceptionMessage() const +{ + return exception; +} + GatherSourcesJob::GatherSourcesJob(QV4::ExecutionEngine *engine, int seq) : engine(engine) , seq(seq) diff --git a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.h b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.h index c91b77cb93..ebdde8f968 100644 --- a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.h +++ b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.h @@ -104,11 +104,13 @@ private: class ExpressionEvalJob: public QV4::Debugging::Debugger::JavaScriptJob { QV4DataCollector *collector; + QString exception; public: ExpressionEvalJob(QV4::ExecutionEngine *engine, int frameNr, const QString &expression, QV4DataCollector *collector); virtual void handleResult(QV4::ScopedValue &result); + const QString &exceptionMessage() const; }; class GatherSourcesJob: public QV4::Debugging::Debugger::Job diff --git a/src/plugins/qmltooling/qmldbg_debugger/qv4debugservice.cpp b/src/plugins/qmltooling/qmldbg_debugger/qv4debugservice.cpp index 6b68f9518e..89820c9f56 100644 --- a/src/plugins/qmltooling/qmldbg_debugger/qv4debugservice.cpp +++ b/src/plugins/qmltooling/qmldbg_debugger/qv4debugservice.cpp @@ -549,31 +549,29 @@ public: virtual void handleRequest() { - //decypher the payload: - QJsonObject arguments = req.value(QStringLiteral("arguments")).toObject(); - QString expression = arguments.value(QStringLiteral("expression")).toString(); - const int frame = arguments.value(QStringLiteral("frame")).toInt(0); - QV4::Debugging::Debugger *debugger = debugService->debuggerAgent.firstDebugger(); - Q_ASSERT(debugger->state() == QV4::Debugging::Debugger::Paused); - - QV4DataCollector *collector = debugService->collector(); - QV4DataCollector::Refs refs; - RefHolder holder(collector, &refs); - Q_ASSERT(debugger->state() == QV4::Debugging::Debugger::Paused); - - ExpressionEvalJob job(debugger->engine(), frame, expression, collector); - debugger->runInEngine(&job); - - Q_ASSERT(refs.size() == 1); - - // response: - addCommand(); - addRequestSequence(); - addSuccess(true); - addRunning(); - addBody(collector->lookupRef(refs.first())); - addRefs(); + if (debugger->state() == QV4::Debugging::Debugger::Paused) { + QJsonObject arguments = req.value(QStringLiteral("arguments")).toObject(); + QString expression = arguments.value(QStringLiteral("expression")).toString(); + const int frame = arguments.value(QStringLiteral("frame")).toInt(0); + + QV4DataCollector *collector = debugService->collector(); + RefHolder holder(collector, debugService->refs()); + ExpressionEvalJob job(debugger->engine(), frame, expression, collector); + debugger->runInEngine(&job); + if (job.hasExeption()) { + createErrorResponse(job.exceptionMessage()); + } else { + addCommand(); + addRequestSequence(); + addSuccess(true); + addRunning(); + addBody(collector->lookupRef(debugService->refs()->last())); + addRefs(); + } + } else { + createErrorResponse(QStringLiteral("Debugger has to be paused for evaluate to work.")); + } } }; } // anonymous namespace @@ -894,6 +892,11 @@ QV4DataCollector *QV4DebugServiceImpl::collector() const return theCollector.data(); } +QV4DataCollector::Refs *QV4DebugServiceImpl::refs() +{ + return &collectedRefs; +} + void QV4DebugServiceImpl::selectFrame(int frameNr) { theSelectedFrame = frameNr; diff --git a/src/plugins/qmltooling/qmldbg_debugger/qv4debugservice.h b/src/plugins/qmltooling/qmldbg_debugger/qv4debugservice.h index c80ad78cc8..6c2950de8c 100644 --- a/src/plugins/qmltooling/qmldbg_debugger/qv4debugservice.h +++ b/src/plugins/qmltooling/qmldbg_debugger/qv4debugservice.h @@ -90,6 +90,7 @@ public: QV4DataCollector *collector() const; QV4DebuggerAgent debuggerAgent; + QV4DataCollector::Refs *refs(); protected: void messageReceived(const QByteArray &); diff --git a/src/qml/jsruntime/qv4debugging.cpp b/src/qml/jsruntime/qv4debugging.cpp index ceeef80b9f..6efc3793ce 100644 --- a/src/qml/jsruntime/qv4debugging.cpp +++ b/src/qml/jsruntime/qv4debugging.cpp @@ -59,6 +59,7 @@ Debugger::JavaScriptJob::JavaScriptJob(QV4::ExecutionEngine *engine, int frameNr : engine(engine) , frameNr(frameNr) , script(script) + , resultIsException(false) {} void Debugger::JavaScriptJob::run() @@ -85,11 +86,18 @@ void Debugger::JavaScriptJob::run() QV4::ScopedValue result(scope); if (!scope.engine->hasException) result = script.run(); - if (scope.engine->hasException) + if (scope.engine->hasException) { result = scope.engine->catchException(); + resultIsException = true; + } handleResult(result); } +bool Debugger::JavaScriptJob::hasExeption() const +{ + return resultIsException; +} + class EvalJob: public Debugger::JavaScriptJob { bool result; diff --git a/src/qml/jsruntime/qv4debugging_p.h b/src/qml/jsruntime/qv4debugging_p.h index ac0c934d42..86faba45f7 100644 --- a/src/qml/jsruntime/qv4debugging_p.h +++ b/src/qml/jsruntime/qv4debugging_p.h @@ -95,10 +95,12 @@ public: QV4::ExecutionEngine *engine; int frameNr; const QString &script; + bool resultIsException; public: JavaScriptJob(QV4::ExecutionEngine *engine, int frameNr, const QString &script); void run(); + bool hasExeption() const; protected: virtual void handleResult(QV4::ScopedValue &result) = 0; -- cgit v1.2.3 From 8fe2e6795d9030a7c6f660a0e57b0d85fc36a1f1 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 14 Aug 2015 18:10:38 +0200 Subject: Clean up data format for V4 debug connection This changes the type announced for functions to the actual JavaScript type "function". The type for null is also wrong: it should be "object". However, older QtCreators cannot distinguish between null and {} if null gets the correct type, unless you explicitly compare x === null in an expression evaluator. For this reason the fake "null" type is kept for now. Also, the value field of undefined is now set as QJsonValue::Undefined which causes it to be omitted when sent over the wire. This is the logical thing to do. In addition we add type and value fields for all data members mentioned in a response, not only the ones specifically asked for. The value field is the actual value for any primitives (including strings), or the number of properties for composite types: objects, arrays, functions. In turn, the "ref" members are omitted for primitive types, so that we don't have to hold references to them in the debug service anymore. Even old QtCreators can deal with verbatim data members without "ref". Task-number: QTBUG-47746 Task-number: QTBUG-47747 Change-Id: I773e6418c39cd9814aadb5fb5ef7e109f9a4e618 Reviewed-by: Simon Hausmann --- .../qmldbg_debugger/qv4datacollector.cpp | 107 ++++++++++++--------- .../qmltooling/qmldbg_debugger/qv4datacollector.h | 2 +- tests/auto/qml/qv4debugger/tst_qv4debugger.cpp | 18 ++-- 3 files changed, 71 insertions(+), 56 deletions(-) diff --git a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp index 01d2a98a74..2ef7713ac7 100644 --- a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp +++ b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include @@ -109,51 +110,78 @@ void QV4DataCollector::collect(const QV4::ScopedValue &value) m_collectedRefs->append(addRef(value)); } -QJsonObject QV4DataCollector::lookupRef(Ref ref) +const QV4::Object *collectProperty(const QV4::ScopedValue &value, QV4::ExecutionEngine *engine, + QJsonObject &dict) { - QJsonObject dict; - if (lookupSpecialRef(ref, &dict)) - return dict; - - dict.insert(QStringLiteral("handle"), qint64(ref)); + QV4::Scope scope(engine); + QV4::ScopedValue typeString(scope, QV4::Runtime::typeofValue(engine, value)); + dict.insert(QStringLiteral("type"), typeString->toQStringNoThrow()); - QV4::Scope scope(engine()); - QV4::ScopedValue value(scope, getValue(ref)); + const QLatin1String valueKey("value"); switch (value->type()) { case QV4::Value::Empty_Type: Q_ASSERT(!"empty Value encountered"); - break; + return 0; case QV4::Value::Undefined_Type: - dict.insert(QStringLiteral("type"), QStringLiteral("undefined")); - break; + dict.insert(valueKey, QJsonValue::Undefined); + return 0; case QV4::Value::Null_Type: + // "null" is not the correct type, but we leave this in until QtC can deal with "object" dict.insert(QStringLiteral("type"), QStringLiteral("null")); - break; + dict.insert(valueKey, QJsonValue::Null); + return 0; case QV4::Value::Boolean_Type: - dict.insert(QStringLiteral("type"), QStringLiteral("boolean")); - dict.insert(QStringLiteral("value"), value->booleanValue() ? QStringLiteral("true") - : QStringLiteral("false")); - break; + dict.insert(valueKey, value->booleanValue()); + return 0; case QV4::Value::Managed_Type: - if (QV4::String *s = value->as()) { - dict.insert(QStringLiteral("type"), QStringLiteral("string")); - dict.insert(QStringLiteral("value"), s->toQString()); - } else if (QV4::Object *o = value->as()) { - dict.insert(QStringLiteral("type"), QStringLiteral("object")); - dict.insert(QStringLiteral("properties"), collectProperties(o)); + if (const QV4::String *s = value->as()) { + dict.insert(valueKey, s->toQString()); + } else if (const QV4::ArrayObject *a = value->as()) { + // size of an array is number of its numerical properties; We don't consider free form + // object properties here. + dict.insert(valueKey, qint64(a->getLength())); + return a; + } else if (const QV4::Object *o = value->as()) { + int numProperties = 0; + QV4::ObjectIterator it(scope, o, QV4::ObjectIterator::EnumerableOnly); + QV4::PropertyAttributes attrs; + uint index; + QV4::ScopedProperty p(scope); + QV4::ScopedString name(scope); + while (true) { + it.next(name.getRef(), &index, p, &attrs); + if (attrs.isEmpty()) + break; + else + ++numProperties; + } + dict.insert(valueKey, numProperties); + return o; } else { Q_UNREACHABLE(); } - break; + return 0; case QV4::Value::Integer_Type: - dict.insert(QStringLiteral("type"), QStringLiteral("number")); - dict.insert(QStringLiteral("value"), value->integerValue()); - break; + dict.insert(valueKey, value->integerValue()); + return 0; default: // double - dict.insert(QStringLiteral("type"), QStringLiteral("number")); - dict.insert(QStringLiteral("value"), value->doubleValue()); - break; + dict.insert(valueKey, value->doubleValue()); + return 0; } +} + +QJsonObject QV4DataCollector::lookupRef(Ref ref) +{ + QJsonObject dict; + if (lookupSpecialRef(ref, &dict)) + return dict; + + dict.insert(QStringLiteral("handle"), qint64(ref)); + QV4::Scope scope(engine()); + QV4::ScopedValue value(scope, getValue(ref)); + + if (const QV4::Object *o = collectProperty(value, engine(), dict)) + dict.insert(QStringLiteral("properties"), collectProperties(o)); return dict; } @@ -165,7 +193,6 @@ QV4DataCollector::Ref QV4DataCollector::addFunctionRef(const QString &functionNa QJsonObject dict; dict.insert(QStringLiteral("handle"), qint64(ref)); dict.insert(QStringLiteral("type"), QStringLiteral("function")); - dict.insert(QStringLiteral("className"), QStringLiteral("Function")); dict.insert(QStringLiteral("name"), functionName); specialRefs.insert(ref, dict); @@ -264,7 +291,7 @@ bool QV4DataCollector::lookupSpecialRef(Ref ref, QJsonObject *dict) return true; } -QJsonArray QV4DataCollector::collectProperties(QV4::Object *object) +QJsonArray QV4DataCollector::collectProperties(const QV4::Object *object) { QJsonArray res; @@ -290,20 +317,14 @@ QJsonObject QV4DataCollector::collectAsJson(const QString &name, const QV4::Scop QJsonObject dict; if (!name.isNull()) dict.insert(QStringLiteral("name"), name); - Ref ref = addRef(value); - dict.insert(QStringLiteral("ref"), qint64(ref)); - if (m_collectedRefs) - m_collectedRefs->append(ref); - - // TODO: enable this when creator can handle it. - if (false) { - if (value->isManaged() && !value->isString()) { - QV4::Scope scope(engine()); - QV4::ScopedObject obj(scope, value->as()); - dict.insert(QStringLiteral("propertycount"), qint64(obj->getLength())); - } + if (value->isManaged() && !value->isString()) { + Ref ref = addRef(value); + dict.insert(QStringLiteral("ref"), qint64(ref)); + if (m_collectedRefs) + m_collectedRefs->append(ref); } + collectProperty(value, engine(), dict); return dict; } diff --git a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.h b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.h index ebdde8f968..7d26d71bdf 100644 --- a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.h +++ b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.h @@ -72,7 +72,7 @@ private: QV4::ReturnedValue getValue(Ref ref); bool lookupSpecialRef(Ref ref, QJsonObject *dict); - QJsonArray collectProperties(QV4::Object *object); + QJsonArray collectProperties(const QV4::Object *object); QJsonObject collectAsJson(const QString &name, const QV4::ScopedValue &value); void collectArgumentsInContext(); diff --git a/tests/auto/qml/qv4debugger/tst_qv4debugger.cpp b/tests/auto/qml/qv4debugger/tst_qv4debugger.cpp index ca308a4f49..7772d16234 100644 --- a/tests/auto/qml/qv4debugger/tst_qv4debugger.cpp +++ b/tests/auto/qml/qv4debugger/tst_qv4debugger.cpp @@ -564,10 +564,8 @@ void tst_qv4debugger::readObject() QVERIFY(b_props.at(0).isObject()); QJsonObject b_head = b_props.at(0).toObject(); QCOMPARE(b_head.value("name").toString(), QStringLiteral("head")); - QVERIFY(b_head.contains("ref")); - QJsonObject b_head_value = frame0.collector->lookupRef(b_head.value("ref").toInt()); - QCOMPARE(b_head_value.value("type").toString(), QStringLiteral("number")); - QCOMPARE(b_head_value.value("value").toDouble(), 1.0); + QCOMPARE(b_head.value("type").toString(), QStringLiteral("number")); + QCOMPARE(b_head.value("value").toDouble(), 1.0); QVERIFY(b_props.at(1).isObject()); QJsonObject b_tail = b_props.at(1).toObject(); QCOMPARE(b_tail.value("name").toString(), QStringLiteral("tail")); @@ -580,16 +578,12 @@ void tst_qv4debugger::readObject() QCOMPARE(b_tail_props.size(), 2); QJsonObject b_tail_head = b_tail_props.at(0).toObject(); QCOMPARE(b_tail_head.value("name").toString(), QStringLiteral("head")); - QVERIFY(b_tail_head.contains("ref")); - QJsonObject b_tail_head_value = frame0.collector->lookupRef(b_tail_head.value("ref").toInt()); - QCOMPARE(b_tail_head_value.value("type").toString(), QStringLiteral("string")); - QCOMPARE(b_tail_head_value.value("value").toString(), QStringLiteral("asdf")); + QCOMPARE(b_tail_head.value("type").toString(), QStringLiteral("string")); + QCOMPARE(b_tail_head.value("value").toString(), QStringLiteral("asdf")); QJsonObject b_tail_tail = b_tail_props.at(1).toObject(); QCOMPARE(b_tail_tail.value("name").toString(), QStringLiteral("tail")); - QVERIFY(b_tail_tail.contains("ref")); - - QJsonObject b_tail_tail_value = frame0.collector->lookupRef(b_tail_tail.value("ref").toInt()); - QCOMPARE(b_tail_tail_value.value("type").toString(), QStringLiteral("null")); + QCOMPARE(b_tail_tail.value("type").toString(), QStringLiteral("null")); + QVERIFY(b_tail_tail.value("value").isNull()); } void tst_qv4debugger::readContextInAllFrames() -- cgit v1.2.3 From ef4ad30e7f16185b9bd299457836a27b56ce1fa5 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 11 Aug 2015 10:19:37 +0200 Subject: Switch to the non compat metacall overload This one passes in the qobject that the metacall is being applied to. The long term goal is to make the vme meta object independent of the QObject instance. Change-Id: Ide34b8637b9963bdb5e87e4aa6e9c2ee825293f7 Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlvmemetaobject.cpp | 5 ++++- src/qml/qml/qqmlvmemetaobject_p.h | 2 +- src/quick/designer/qqmldesignermetaobject.cpp | 12 +++++++----- src/quick/designer/qqmldesignermetaobject_p.h | 4 ++-- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index ab3303769f..6021b1ae79 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -457,8 +457,11 @@ QRectF QQmlVMEMetaObject::readPropertyAsRectF(int id) return v->d()->data.value(); } -int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) +int QQmlVMEMetaObject::metaCall(QObject *o, QMetaObject::Call c, int _id, void **a) { + Q_ASSERT(o == object); + Q_UNUSED(o); + int id = _id; if (c == QMetaObject::WriteProperty && interceptors && !(*reinterpret_cast(a[3]) & QQmlPropertyPrivate::BypassInterceptor)) { diff --git a/src/qml/qml/qqmlvmemetaobject_p.h b/src/qml/qml/qqmlvmemetaobject_p.h index 3f289c2cc6..5a4c3d234e 100644 --- a/src/qml/qml/qqmlvmemetaobject_p.h +++ b/src/qml/qml/qqmlvmemetaobject_p.h @@ -180,7 +180,7 @@ public: static QQmlVMEMetaObject *getForSignal(QObject *o, int coreIndex); protected: - virtual int metaCall(QMetaObject::Call _c, int _id, void **_a); + virtual int metaCall(QObject *o, QMetaObject::Call _c, int _id, void **_a); public: friend class QQmlVMEMetaObjectEndpoint; diff --git a/src/quick/designer/qqmldesignermetaobject.cpp b/src/quick/designer/qqmldesignermetaobject.cpp index e80012ba35..76c94b242d 100644 --- a/src/quick/designer/qqmldesignermetaobject.cpp +++ b/src/quick/designer/qqmldesignermetaobject.cpp @@ -226,7 +226,7 @@ int QQmlDesignerMetaObject::propertyOffset() const return cache->propertyOffset(); } -int QQmlDesignerMetaObject::openMetaCall(QMetaObject::Call call, int id, void **a) +int QQmlDesignerMetaObject::openMetaCall(QObject *o, QMetaObject::Call call, int id, void **a) { if ((call == QMetaObject::ReadProperty || call == QMetaObject::WriteProperty) && id >= m_type->propertyOffset()) { @@ -248,14 +248,16 @@ int QQmlDesignerMetaObject::openMetaCall(QMetaObject::Call call, int id, void ** } else { QAbstractDynamicMetaObject *directParent = parent(); if (directParent) - return directParent->metaCall(call, id, a); + return directParent->metaCall(o, call, id, a); else return myObject()->qt_metacall(call, id, a); } } -int QQmlDesignerMetaObject::metaCall(QMetaObject::Call call, int id, void **a) +int QQmlDesignerMetaObject::metaCall(QObject *o, QMetaObject::Call call, int id, void **a) { + Q_ASSERT(myObject() == o); + int metaCallReturnValue = -1; const QMetaProperty propertyById = QQmlVMEMetaObject::property(id); @@ -288,9 +290,9 @@ int QQmlDesignerMetaObject::metaCall(QMetaObject::Call call, int id, void **a) QAbstractDynamicMetaObject *directParent = parent(); if (directParent && id < directParent->propertyOffset()) { - metaCallReturnValue = directParent->metaCall(call, id, a); + metaCallReturnValue = directParent->metaCall(o, call, id, a); } else { - openMetaCall(call, id, a); + openMetaCall(o, call, id, a); } diff --git a/src/quick/designer/qqmldesignermetaobject_p.h b/src/quick/designer/qqmldesignermetaobject_p.h index eca4fb6a99..47f4baad2b 100644 --- a/src/quick/designer/qqmldesignermetaobject_p.h +++ b/src/quick/designer/qqmldesignermetaobject_p.h @@ -68,8 +68,8 @@ protected: static QQmlDesignerMetaObject* getNodeInstanceMetaObject(QObject *object, QQmlEngine *engine); void createNewDynamicProperty(const QString &name); - int openMetaCall(QMetaObject::Call _c, int _id, void **_a); - int metaCall(QMetaObject::Call _c, int _id, void **_a); + int openMetaCall(QObject *o, QMetaObject::Call _c, int _id, void **_a); + int metaCall(QObject *o, QMetaObject::Call _c, int _id, void **_a); void notifyPropertyChange(int id); void setValue(int id, const QVariant &value); QVariant propertyWriteValue(int, const QVariant &); -- cgit v1.2.3 From fec775d221efcf55986aec7ca0250c7e63cfba0c Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 11 Aug 2015 15:43:30 +0200 Subject: Hold a pointer to the QV4::ExecutionEngine in the property cache This makes more sense than a pointer to the QQmlEngine. Change-Id: Ic6037b0df63b6cf1585539bc3ac78822f0e69d02 Reviewed-by: Simon Hausmann --- src/qml/jsapi/qjsengine.cpp | 2 +- src/qml/qml/qqmlopenmetaobject.cpp | 3 ++- src/qml/qml/qqmlpropertycache.cpp | 20 ++++++++++---------- src/qml/qml/qqmlpropertycache_p.h | 6 +++--- src/qml/qml/qqmlvmemetaobject.cpp | 1 - src/qml/util/qqmladaptormodel.cpp | 2 +- .../qml/qqmlpropertycache/tst_qqmlpropertycache.cpp | 19 +++++++++++++------ 7 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/qml/jsapi/qjsengine.cpp b/src/qml/jsapi/qjsengine.cpp index d9615d496f..4910b6a1c6 100644 --- a/src/qml/jsapi/qjsengine.cpp +++ b/src/qml/jsapi/qjsengine.cpp @@ -580,7 +580,7 @@ QJSEnginePrivate::~QJSEnginePrivate() QQmlPropertyCache *QJSEnginePrivate::createCache(const QMetaObject *mo) { if (!mo->superClass()) { - QQmlPropertyCache *rv = new QQmlPropertyCache(q_func(), mo); + QQmlPropertyCache *rv = new QQmlPropertyCache(QV8Engine::getV4(q_func()), mo); propertyCache.insert(mo, rv); return rv; } else { diff --git a/src/qml/qml/qqmlopenmetaobject.cpp b/src/qml/qml/qqmlopenmetaobject.cpp index 777bb0c5e1..16138508dd 100644 --- a/src/qml/qml/qqmlopenmetaobject.cpp +++ b/src/qml/qml/qqmlopenmetaobject.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -367,7 +368,7 @@ void QQmlOpenMetaObject::setCached(bool c) QQmlData *qmldata = QQmlData::get(d->object, true); if (d->cacheProperties) { if (!d->type->d->cache) - d->type->d->cache = new QQmlPropertyCache(d->type->d->engine, this); + d->type->d->cache = new QQmlPropertyCache(QV8Engine::getV4(d->type->d->engine), this); qmldata->propertyCache = d->type->d->cache; d->type->d->cache->addref(); } else { diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp index cd8eb0d3e2..9a935ed55f 100644 --- a/src/qml/qml/qqmlpropertycache.cpp +++ b/src/qml/qml/qqmlpropertycache.cpp @@ -231,10 +231,10 @@ void QQmlPropertyData::lazyLoad(const QMetaMethod &m) /*! Creates a new empty QQmlPropertyCache. */ -QQmlPropertyCache::QQmlPropertyCache(QJSEngine *e) -: engine(e), _parent(0), propertyIndexCacheStart(0), methodIndexCacheStart(0), - signalHandlerIndexCacheStart(0), _hasPropertyOverrides(false), _ownMetaObject(false), - _metaObject(0), argumentsCache(0) +QQmlPropertyCache::QQmlPropertyCache(QV4::ExecutionEngine *e) + : engine(e), _parent(0), propertyIndexCacheStart(0), methodIndexCacheStart(0), + signalHandlerIndexCacheStart(0), _hasPropertyOverrides(false), _ownMetaObject(false), + _metaObject(0), argumentsCache(0) { Q_ASSERT(engine); } @@ -242,10 +242,10 @@ QQmlPropertyCache::QQmlPropertyCache(QJSEngine *e) /*! Creates a new QQmlPropertyCache of \a metaObject. */ -QQmlPropertyCache::QQmlPropertyCache(QJSEngine *e, const QMetaObject *metaObject) -: engine(e), _parent(0), propertyIndexCacheStart(0), methodIndexCacheStart(0), - signalHandlerIndexCacheStart(0), _hasPropertyOverrides(false), _ownMetaObject(false), - _metaObject(0), argumentsCache(0) +QQmlPropertyCache::QQmlPropertyCache(QV4::ExecutionEngine *e, const QMetaObject *metaObject) + : engine(e), _parent(0), propertyIndexCacheStart(0), methodIndexCacheStart(0), + signalHandlerIndexCacheStart(0), _hasPropertyOverrides(false), _ownMetaObject(false), + _metaObject(0), argumentsCache(0) { Q_ASSERT(engine); Q_ASSERT(metaObject); @@ -818,7 +818,7 @@ void QQmlPropertyCache::resolve(QQmlPropertyData *data) const data->propType = registerResult == -1 ? QMetaType::UnknownType : registerResult; } } - data->flags |= flagsForPropertyType(data->propType, qobject_cast(engine)); + data->flags |= flagsForPropertyType(data->propType, engine->qmlEngine()); } data->flags &= ~QQmlPropertyData::NotFullyResolved; @@ -1134,7 +1134,7 @@ QString QQmlPropertyCache::signalParameterStringForJS(int index, QString *errorS } QString error; - QString parameters = signalParameterStringForJS(QV8Engine::getV4(engine), parameterNameList, &error); + QString parameters = signalParameterStringForJS(engine, parameterNameList, &error); A *arguments = static_cast(signalData->arguments); arguments->signalParameterStringForJS = new QString(!error.isEmpty() ? error : parameters); diff --git a/src/qml/qml/qqmlpropertycache_p.h b/src/qml/qml/qqmlpropertycache_p.h index 4d8c6dd9a5..4f203a837c 100644 --- a/src/qml/qml/qqmlpropertycache_p.h +++ b/src/qml/qml/qqmlpropertycache_p.h @@ -243,8 +243,8 @@ class QQmlPropertyCacheMethodArguments; class Q_QML_PRIVATE_EXPORT QQmlPropertyCache : public QQmlRefCount, public QQmlCleanup { public: - QQmlPropertyCache(QJSEngine *); - QQmlPropertyCache(QJSEngine *, const QMetaObject *); + QQmlPropertyCache(QV4::ExecutionEngine *); + QQmlPropertyCache(QV4::ExecutionEngine *, const QMetaObject *); virtual ~QQmlPropertyCache(); void update(const QMetaObject *); @@ -377,7 +377,7 @@ private: _hasPropertyOverrides |= isOverride; } - QJSEngine *engine; + QV4::ExecutionEngine *engine; QQmlPropertyCache *_parent; int propertyIndexCacheStart; diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 6021b1ae79..0085fdee00 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -89,7 +89,6 @@ class QQmlVMEMetaObjectEndpoint : public QQmlNotifierEndpoint { public: QQmlVMEMetaObjectEndpoint(); - static void vmecallback(QQmlNotifierEndpoint *, void **); void tryConnect(); QFlagPointer metaObject; diff --git a/src/qml/util/qqmladaptormodel.cpp b/src/qml/util/qqmladaptormodel.cpp index 17f4ffd62b..f83798488c 100644 --- a/src/qml/util/qqmladaptormodel.cpp +++ b/src/qml/util/qqmladaptormodel.cpp @@ -547,7 +547,7 @@ public: metaObject = builder.toMetaObject(); *static_cast(this) = *metaObject; - propertyCache = new QQmlPropertyCache(engine, metaObject); + propertyCache = new QQmlPropertyCache(QV8Engine::getV4(engine), metaObject); } }; diff --git a/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp b/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp index ce2aab49c3..a5ae27d446 100644 --- a/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp +++ b/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include "../../shared/util.h" class tst_qqmlpropertycache : public QObject @@ -102,10 +103,11 @@ QQmlPropertyData *cacheProperty(QQmlPropertyCache *cache, const char *name) void tst_qqmlpropertycache::properties() { QQmlEngine engine; + QV4::ExecutionEngine *v4 = QV8Engine::getV4(&engine); DerivedObject object; const QMetaObject *metaObject = object.metaObject(); - QQmlRefPointer cache(new QQmlPropertyCache(&engine, metaObject)); + QQmlRefPointer cache(new QQmlPropertyCache(v4, metaObject)); QQmlPropertyData *data; QVERIFY(data = cacheProperty(cache, "propertyA")); @@ -124,10 +126,11 @@ void tst_qqmlpropertycache::properties() void tst_qqmlpropertycache::propertiesDerived() { QQmlEngine engine; + QV4::ExecutionEngine *v4 = QV8Engine::getV4(&engine); DerivedObject object; const QMetaObject *metaObject = object.metaObject(); - QQmlRefPointer parentCache(new QQmlPropertyCache(&engine, &BaseObject::staticMetaObject)); + QQmlRefPointer parentCache(new QQmlPropertyCache(v4, &BaseObject::staticMetaObject)); QQmlRefPointer cache(parentCache->copyAndAppend(object.metaObject())); QQmlPropertyData *data; @@ -147,10 +150,11 @@ void tst_qqmlpropertycache::propertiesDerived() void tst_qqmlpropertycache::methods() { QQmlEngine engine; + QV4::ExecutionEngine *v4 = QV8Engine::getV4(&engine); DerivedObject object; const QMetaObject *metaObject = object.metaObject(); - QQmlRefPointer cache(new QQmlPropertyCache(&engine, metaObject)); + QQmlRefPointer cache(new QQmlPropertyCache(v4, metaObject)); QQmlPropertyData *data; QVERIFY(data = cacheProperty(cache, "slotA")); @@ -181,10 +185,11 @@ void tst_qqmlpropertycache::methods() void tst_qqmlpropertycache::methodsDerived() { QQmlEngine engine; + QV4::ExecutionEngine *v4 = QV8Engine::getV4(&engine); DerivedObject object; const QMetaObject *metaObject = object.metaObject(); - QQmlRefPointer parentCache(new QQmlPropertyCache(&engine, &BaseObject::staticMetaObject)); + QQmlRefPointer parentCache(new QQmlPropertyCache(v4, &BaseObject::staticMetaObject)); QQmlRefPointer cache(parentCache->copyAndAppend(object.metaObject())); QQmlPropertyData *data; @@ -216,10 +221,11 @@ void tst_qqmlpropertycache::methodsDerived() void tst_qqmlpropertycache::signalHandlers() { QQmlEngine engine; + QV4::ExecutionEngine *v4 = QV8Engine::getV4(&engine); DerivedObject object; const QMetaObject *metaObject = object.metaObject(); - QQmlRefPointer cache(new QQmlPropertyCache(&engine, metaObject)); + QQmlRefPointer cache(new QQmlPropertyCache(v4, metaObject)); QQmlPropertyData *data; QVERIFY(data = cacheProperty(cache, "onSignalA")); @@ -244,10 +250,11 @@ void tst_qqmlpropertycache::signalHandlers() void tst_qqmlpropertycache::signalHandlersDerived() { QQmlEngine engine; + QV4::ExecutionEngine *v4 = QV8Engine::getV4(&engine); DerivedObject object; const QMetaObject *metaObject = object.metaObject(); - QQmlRefPointer parentCache(new QQmlPropertyCache(&engine, &BaseObject::staticMetaObject)); + QQmlRefPointer parentCache(new QQmlPropertyCache(v4, &BaseObject::staticMetaObject)); QQmlRefPointer cache(parentCache->copyAndAppend(object.metaObject())); QQmlPropertyData *data; -- cgit v1.2.3 From 88cfe493381e9daea55f660d49ea989e351cdce4 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 11 Aug 2015 16:05:24 +0200 Subject: Cleanup code in the VMEMO Change-Id: Idc1da41586161f1c824c608198e232ba52a0d9d7 Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlpropertycache_p.h | 2 + src/qml/qml/qqmlvmemetaobject.cpp | 85 +++++++++++++++++++-------------------- src/qml/qml/qqmlvmemetaobject_p.h | 2 +- 3 files changed, 44 insertions(+), 45 deletions(-) diff --git a/src/qml/qml/qqmlpropertycache_p.h b/src/qml/qml/qqmlpropertycache_p.h index 4f203a837c..2ee399c496 100644 --- a/src/qml/qml/qqmlpropertycache_p.h +++ b/src/qml/qml/qqmlpropertycache_p.h @@ -377,8 +377,10 @@ private: _hasPropertyOverrides |= isOverride; } +public: QV4::ExecutionEngine *engine; +private: QQmlPropertyCache *_parent; int propertyIndexCacheStart; int methodIndexCacheStart; diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 0085fdee00..0ffeddbabc 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -65,7 +65,7 @@ void QQmlVMEVariantQObjectPtr::objectDestroyed(QObject *) { if (m_target && m_index >= 0) { if (m_target->propertiesInitialized && !m_target->properties.isUndefined()) { - QV4::ExecutionEngine *v4 = m_target->properties.engine(); + QV4::ExecutionEngine *v4 = m_target->cache->engine; if (v4) { QV4::Scope scope(v4); QV4::Scoped sp(scope, m_target->properties.value()); @@ -151,7 +151,7 @@ QQmlVMEMetaObject::QQmlVMEMetaObject(QObject *obj, : object(obj), ctxt(QQmlData::get(obj, true)->outerContext), cache(cache), metaData(meta), hasAssignedMetaObjectData(false), aliasEndpoints(0), - propertiesInitialized(false), interceptors(0), v8methods(0) + propertiesInitialized(false), interceptors(0), methods(0) { QObjectPrivate *op = QObjectPrivate::get(obj); @@ -189,17 +189,17 @@ QQmlVMEMetaObject::QQmlVMEMetaObject(QObject *obj, ensureQObjectWrapper(); if (qmlBindingContext && metaData->methodCount) { - v8methods = new QV4::PersistentValue[metaData->methodCount]; + methods = new QV4::PersistentValue[metaData->methodCount]; QV4::CompiledData::CompilationUnit *compilationUnit = compiledData->compilationUnit; - QV4::Scope scope(QQmlEnginePrivate::get(ctxt->engine)->v4engine()); + QV4::Scope scope(cache->engine); QV4::ScopedObject o(scope); for (int index = 0; index < metaData->methodCount; ++index) { QQmlVMEMetaData::MethodData *data = metaData->methodData() + index; QV4::Function *runtimeFunction = compilationUnit->runtimeFunctions[data->runtimeFunctionIndex]; o = QV4::FunctionObject::createScriptFunction(qmlBindingContext, runtimeFunction); - v8methods[index].set(qmlBindingContext->engine(), o); + methods[index].set(qmlBindingContext->engine(), o); } } } @@ -208,7 +208,7 @@ QQmlVMEMetaObject::~QQmlVMEMetaObject() { if (parent.isT1()) parent.asT1()->objectDestroyed(object); delete [] aliasEndpoints; - delete [] v8methods; + delete [] methods; qDeleteAll(varObjectGuards); } @@ -246,56 +246,56 @@ void QQmlVMEMetaObject::writeProperty(int id, const QString& v) { QV4::MemberData *md = propertiesAsMemberData(); if (md) - *(md->data() + id) = properties.engine()->newString(v); + *(md->data() + id) = cache->engine->newString(v); } void QQmlVMEMetaObject::writeProperty(int id, const QUrl& v) { QV4::MemberData *md = propertiesAsMemberData(); if (md) - *(md->data() + id) = properties.engine()->newVariantObject(QVariant::fromValue(v)); + *(md->data() + id) = cache->engine->newVariantObject(QVariant::fromValue(v)); } void QQmlVMEMetaObject::writeProperty(int id, const QDate& v) { QV4::MemberData *md = propertiesAsMemberData(); if (md) - *(md->data() + id) = properties.engine()->newVariantObject(QVariant::fromValue(v)); + *(md->data() + id) = cache->engine->newVariantObject(QVariant::fromValue(v)); } void QQmlVMEMetaObject::writeProperty(int id, const QDateTime& v) { QV4::MemberData *md = propertiesAsMemberData(); if (md) - *(md->data() + id) = properties.engine()->newVariantObject(QVariant::fromValue(v)); + *(md->data() + id) = cache->engine->newVariantObject(QVariant::fromValue(v)); } void QQmlVMEMetaObject::writeProperty(int id, const QPointF& v) { QV4::MemberData *md = propertiesAsMemberData(); if (md) - *(md->data() + id) = properties.engine()->newVariantObject(QVariant::fromValue(v)); + *(md->data() + id) = cache->engine->newVariantObject(QVariant::fromValue(v)); } void QQmlVMEMetaObject::writeProperty(int id, const QSizeF& v) { QV4::MemberData *md = propertiesAsMemberData(); if (md) - *(md->data() + id) = properties.engine()->newVariantObject(QVariant::fromValue(v)); + *(md->data() + id) = cache->engine->newVariantObject(QVariant::fromValue(v)); } void QQmlVMEMetaObject::writeProperty(int id, const QRectF& v) { QV4::MemberData *md = propertiesAsMemberData(); if (md) - *(md->data() + id) = properties.engine()->newVariantObject(QVariant::fromValue(v)); + *(md->data() + id) = cache->engine->newVariantObject(QVariant::fromValue(v)); } void QQmlVMEMetaObject::writeProperty(int id, QObject* v) { QV4::MemberData *md = propertiesAsMemberData(); if (md) - *(md->data() + id) = QV4::QObjectWrapper::wrap(properties.engine(), v); + *(md->data() + id) = QV4::QObjectWrapper::wrap(cache->engine, v); QQmlVMEVariantQObjectPtr *guard = getQObjectGuardForProperty(id); if (v && !guard) { @@ -312,7 +312,7 @@ int QQmlVMEMetaObject::readPropertyAsInt(int id) if (!md) return 0; - QV4::Scope scope(properties.engine()); + QV4::Scope scope(cache->engine); QV4::ScopedValue sv(scope, *(md->data() + id)); if (!sv->isInt32()) return 0; @@ -325,7 +325,7 @@ bool QQmlVMEMetaObject::readPropertyAsBool(int id) if (!md) return false; - QV4::Scope scope(properties.engine()); + QV4::Scope scope(cache->engine); QV4::ScopedValue sv(scope, *(md->data() + id)); if (!sv->isBoolean()) return false; @@ -338,7 +338,7 @@ double QQmlVMEMetaObject::readPropertyAsDouble(int id) if (!md) return 0.0; - QV4::Scope scope(properties.engine()); + QV4::Scope scope(cache->engine); QV4::ScopedValue sv(scope, *(md->data() + id)); if (!sv->isDouble()) return 0.0; @@ -351,7 +351,7 @@ QString QQmlVMEMetaObject::readPropertyAsString(int id) if (!md) return QString(); - QV4::Scope scope(properties.engine()); + QV4::Scope scope(cache->engine); QV4::ScopedValue sv(scope, *(md->data() + id)); if (!sv->isString()) return QString(); @@ -364,7 +364,7 @@ QUrl QQmlVMEMetaObject::readPropertyAsUrl(int id) if (!md) return QUrl(); - QV4::Scope scope(properties.engine()); + QV4::Scope scope(cache->engine); QV4::ScopedValue sv(scope, *(md->data() + id)); const QV4::VariantObject *v = sv->as(); if (!v || v->d()->data.type() != QVariant::Url) @@ -378,7 +378,7 @@ QDate QQmlVMEMetaObject::readPropertyAsDate(int id) if (!md) return QDate(); - QV4::Scope scope(properties.engine()); + QV4::Scope scope(cache->engine); QV4::ScopedValue sv(scope, *(md->data() + id)); const QV4::VariantObject *v = sv->as(); if (!v || v->d()->data.type() != QVariant::Date) @@ -392,7 +392,7 @@ QDateTime QQmlVMEMetaObject::readPropertyAsDateTime(int id) if (!md) return QDateTime(); - QV4::Scope scope(properties.engine()); + QV4::Scope scope(cache->engine); QV4::ScopedValue sv(scope, *(md->data() + id)); const QV4::VariantObject *v = sv->as(); if (!v || v->d()->data.type() != QVariant::DateTime) @@ -406,7 +406,7 @@ QSizeF QQmlVMEMetaObject::readPropertyAsSizeF(int id) if (!md) return QSizeF(); - QV4::Scope scope(properties.engine()); + QV4::Scope scope(cache->engine); QV4::ScopedValue sv(scope, *(md->data() + id)); const QV4::VariantObject *v = sv->as(); if (!v || v->d()->data.type() != QVariant::SizeF) @@ -420,7 +420,7 @@ QPointF QQmlVMEMetaObject::readPropertyAsPointF(int id) if (!md) return QPointF(); - QV4::Scope scope(properties.engine()); + QV4::Scope scope(cache->engine); QV4::ScopedValue sv(scope, *(md->data() + id)); const QV4::VariantObject *v = sv->as(); if (!v || v->d()->data.type() != QVariant::PointF) @@ -434,7 +434,7 @@ QObject* QQmlVMEMetaObject::readPropertyAsQObject(int id) if (!md) return 0; - QV4::Scope scope(properties.engine()); + QV4::Scope scope(cache->engine); QV4::ScopedValue sv(scope, *(md->data() + id)); const QV4::QObjectWrapper *wrapper = sv->as(); if (!wrapper) @@ -448,7 +448,7 @@ QRectF QQmlVMEMetaObject::readPropertyAsRectF(int id) if (!md) return QRectF(); - QV4::Scope scope(properties.engine()); + QV4::Scope scope(cache->engine); QV4::ScopedValue sv(scope, *(md->data() + id)); const QV4::VariantObject *v = sv->as(); if (!v || v->d()->data.type() != QVariant::RectF) @@ -674,7 +674,7 @@ int QQmlVMEMetaObject::metaCall(QObject *o, QMetaObject::Call c, int _id, void * if (md) { QV4::VariantObject *v = (md->data() + id)->as(); if (!v) { - *(md->data() + id) = properties.engine()->newVariantObject(QVariant()); + *(md->data() + id) = cache->engine->newVariantObject(QVariant()); v = (md->data() + id)->as(); } QQml_valueTypeProvider()->initValueType(t, v->d()->data); @@ -827,10 +827,10 @@ QV4::ReturnedValue QQmlVMEMetaObject::method(int index) return QV4::Primitive::undefinedValue().asReturnedValue(); } - if (!v8methods) - v8methods = new QV4::PersistentValue[metaData->methodCount]; + if (!methods) + methods = new QV4::PersistentValue[metaData->methodCount]; - return v8methods[index].value(); + return methods[index].value(); } QV4::ReturnedValue QQmlVMEMetaObject::readVarProperty(int id) @@ -853,7 +853,7 @@ QVariant QQmlVMEMetaObject::readPropertyAsVariant(int id) const QV4::VariantObject *v = (md->data() + id)->as(); if (v) return v->d()->data; - return properties.engine()->toVariant(*(md->data() + id), -1); + return cache->engine->toVariant(*(md->data() + id), -1); } return QVariant(); } @@ -913,8 +913,8 @@ void QQmlVMEMetaObject::writeProperty(int id, const QVariant &value) // And, if the new value is a scarce resource, we need to ensure that it does not get // automatically released by the engine until no other references to it exist. - QV4::Scope scope(properties.engine()); - QV4::ScopedValue newv(scope, properties.engine()->fromVariant(value)); + QV4::Scope scope(cache->engine); + QV4::ScopedValue newv(scope, cache->engine->fromVariant(value)); QV4::Scoped v(scope, newv); if (!!v) v->addVmePropertyReference(); @@ -939,7 +939,7 @@ void QQmlVMEMetaObject::writeProperty(int id, const QVariant &value) v->d()->data != value); if (v) v->removeVmePropertyReference(); - *(md->data() + id) = properties.engine()->newVariantObject(value); + *(md->data() + id) = cache->engine->newVariantObject(value); v = static_cast(md->data() + id); v->addVmePropertyReference(); } @@ -1024,11 +1024,11 @@ void QQmlVMEMetaObject::setVmeMethod(int index, const QV4::Value &function) int plainSignals = metaData->signalCount + metaData->propertyCount + metaData->aliasCount; Q_ASSERT(index >= (methodOffset() + plainSignals) && index < (methodOffset() + plainSignals + metaData->methodCount)); - if (!v8methods) - v8methods = new QV4::PersistentValue[metaData->methodCount]; + if (!methods) + methods = new QV4::PersistentValue[metaData->methodCount]; int methodIndex = index - methodOffset() - plainSignals; - v8methods[methodIndex].set(function.as()->engine(), function); + methods[methodIndex].set(function.as()->engine(), function); } QV4::ReturnedValue QQmlVMEMetaObject::vmeProperty(int index) @@ -1065,16 +1065,14 @@ bool QQmlVMEMetaObject::ensurePropertiesAllocated() void QQmlVMEMetaObject::ensureQObjectWrapper() { - Q_ASSERT(ctxt && ctxt->engine); - QQmlEnginePrivate *ep = QQmlEnginePrivate::get(ctxt->engine); - QV4::ExecutionEngine *v4 = ep->v4engine(); + Q_ASSERT(cache && cache->engine); + QV4::ExecutionEngine *v4 = cache->engine; QV4::QObjectWrapper::wrap(v4, object); } void QQmlVMEMetaObject::mark(QV4::ExecutionEngine *e) { - QQmlEnginePrivate *ep = (ctxt == 0 || ctxt->engine == 0) ? 0 : QQmlEnginePrivate::get(ctxt->engine); - QV4::ExecutionEngine *v4 = (ep == 0) ? 0 : ep->v4engine(); + QV4::ExecutionEngine *v4 = cache ? cache->engine : 0; if (v4 != e) return; @@ -1086,9 +1084,8 @@ void QQmlVMEMetaObject::mark(QV4::ExecutionEngine *e) void QQmlVMEMetaObject::allocateProperties() { - QQmlEngine *qml = qmlEngine(object); - Q_ASSERT(qml); - QV4::ExecutionEngine *v4 = QV8Engine::getV4(qml->handle()); + Q_ASSERT(cache && cache->engine); + QV4::ExecutionEngine *v4 = cache->engine; QV4::Heap::MemberData *data = QV4::MemberData::reallocate(v4, 0, metaData->propertyCount); properties.set(v4, data); for (uint i = 0; i < data->size; ++i) diff --git a/src/qml/qml/qqmlvmemetaobject_p.h b/src/qml/qml/qqmlvmemetaobject_p.h index 5a4c3d234e..427e751f5d 100644 --- a/src/qml/qml/qqmlvmemetaobject_p.h +++ b/src/qml/qml/qqmlvmemetaobject_p.h @@ -239,7 +239,7 @@ public: QQmlPropertyValueInterceptor *interceptors; - QV4::PersistentValue *v8methods; + QV4::PersistentValue *methods; QV4::ReturnedValue method(int); QV4::ReturnedValue readVarProperty(int); -- cgit v1.2.3 From 04f30db289225e700fe99c163f53f0dd7e920caf Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Fri, 26 Jun 2015 11:56:05 +0200 Subject: QQuickImageBase: Use QUrl::path() instead of QUrl::toString(). This copies less data, which is faster. Increases creation/delegates_image from 560 ops/frame to 600 ops/frame for me. Change-Id: I9c230bb9fa82fd631020881fb741857285589bca Suggested-by: Michael Brasser Reviewed-by: Michael Brasser Reviewed-by: Gunnar Sletta --- src/quick/items/qquickimagebase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/quick/items/qquickimagebase.cpp b/src/quick/items/qquickimagebase.cpp index e54f5bb9c9..1ad37ef414 100644 --- a/src/quick/items/qquickimagebase.cpp +++ b/src/quick/items/qquickimagebase.cpp @@ -222,7 +222,7 @@ void QQuickImageBase::load() if (loadUrl.scheme() == QStringLiteral("image")) { setDevicePixelRatio = true; } else { - QString stringUrl = loadUrl.toString(); + QString stringUrl = loadUrl.path(QUrl::PrettyDecoded); if (stringUrl.endsWith(QLatin1String("svg")) || stringUrl.endsWith(QLatin1String("svgz"))) { setDevicePixelRatio = true; -- cgit v1.2.3 From 3f4d7a755585f1b79c7e9675220b8210f10f358e Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Mon, 10 Aug 2015 14:33:14 +0300 Subject: Add possibility to mirror ShaderEffectSource generated textures Using textures generated by ShaderEffectSource items (or Item.layer) with custom OpenGL code was non-intuitive due to mismatching coordinate systems, so added a possibility to control the generated texture orientation. [ChangeLog][QtQuick][ShaderEffectSource] Added possibility to mirror generated OpenGL texture. Change-Id: I7c03d8b6fbfc43d69812c15d244200fb8e7c7bb9 Reviewed-by: Gunnar Sletta --- src/quick/items/qquickitem.cpp | 31 ++++ src/quick/items/qquickitem_p.h | 6 + src/quick/items/qquickitemsmodule.cpp | 1 + src/quick/items/qquickshadereffectsource.cpp | 34 +++++ src/quick/items/qquickshadereffectsource_p.h | 13 ++ src/quick/scenegraph/qsgadaptationlayer_p.h | 2 + src/quick/scenegraph/qsgdefaultlayer.cpp | 25 +++- src/quick/scenegraph/qsgdefaultlayer_p.h | 10 ++ .../qquickitemlayer/data/TextureMirroring.qml | 159 +++++++++++++++++++++ .../auto/quick/qquickitemlayer/qquickitemlayer.pro | 3 +- .../quick/qquickitemlayer/tst_qquickitemlayer.cpp | 93 ++++++++++++ 11 files changed, 375 insertions(+), 2 deletions(-) create mode 100644 tests/auto/quick/qquickitemlayer/data/TextureMirroring.qml diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp index 32c3e651dd..0c9ee4fe73 100644 --- a/src/quick/items/qquickitem.cpp +++ b/src/quick/items/qquickitem.cpp @@ -7488,6 +7488,7 @@ QQuickItemLayer::QQuickItemLayer(QQuickItem *item) , m_effectComponent(0) , m_effect(0) , m_effectSource(0) + , m_textureMirroring(QQuickShaderEffectSource::MirrorVertically) { } @@ -7559,6 +7560,7 @@ void QQuickItemLayer::activate() m_effectSource->setMipmap(m_mipmap); m_effectSource->setWrapMode(m_wrapMode); m_effectSource->setFormat(m_format); + m_effectSource->setTextureMirroring(m_textureMirroring); if (m_effectComponent) activateEffect(); @@ -7811,6 +7813,35 @@ void QQuickItemLayer::setWrapMode(QQuickShaderEffectSource::WrapMode mode) emit wrapModeChanged(mode); } +/*! + \qmlproperty enumeration QtQuick::Item::layer.textureMirroring + \since 5.6 + + This property defines how the generated OpenGL texture should be mirrored. + The default value is \c{ShaderEffectSource.MirrorVertically}. + Custom mirroring can be useful if the generated texture is directly accessed by custom shaders, + such as those specified by ShaderEffect. If no effect is specified for the layered + item, mirroring has no effect on the UI representation of the item. + + \list + \li ShaderEffectSource.NoMirroring - No mirroring + \li ShaderEffectSource.MirrorHorizontally - The generated texture is flipped along X-axis. + \li ShaderEffectSource.MirrorVertically - The generated texture is flipped along Y-axis. + \endlist + */ + +void QQuickItemLayer::setTextureMirroring(QQuickShaderEffectSource::TextureMirroring mirroring) +{ + if (mirroring == m_textureMirroring) + return; + m_textureMirroring = mirroring; + + if (m_effectSource) + m_effectSource->setTextureMirroring(m_textureMirroring); + + emit textureMirroringChanged(mirroring); +} + /*! \qmlproperty string QtQuick::Item::layer.samplerName diff --git a/src/quick/items/qquickitem_p.h b/src/quick/items/qquickitem_p.h index 5e0246c32e..942b51bf68 100644 --- a/src/quick/items/qquickitem_p.h +++ b/src/quick/items/qquickitem_p.h @@ -143,6 +143,7 @@ class QQuickItemLayer : public QObject, public QQuickItemChangeListener Q_PROPERTY(QQuickShaderEffectSource::Format format READ format WRITE setFormat NOTIFY formatChanged) Q_PROPERTY(QByteArray samplerName READ name WRITE setName NOTIFY nameChanged) Q_PROPERTY(QQmlComponent *effect READ effect WRITE setEffect NOTIFY effectChanged) + Q_PROPERTY(QQuickShaderEffectSource::TextureMirroring textureMirroring READ textureMirroring WRITE setTextureMirroring NOTIFY textureMirroringChanged) public: QQuickItemLayer(QQuickItem *item); ~QQuickItemLayer(); @@ -177,6 +178,9 @@ public: QQmlComponent *effect() const { return m_effectComponent; } void setEffect(QQmlComponent *effect); + QQuickShaderEffectSource::TextureMirroring textureMirroring() const { return m_textureMirroring; } + void setTextureMirroring(QQuickShaderEffectSource::TextureMirroring mirroring); + QQuickShaderEffectSource *effectSource() const { return m_effectSource; } void itemGeometryChanged(QQuickItem *, const QRectF &, const QRectF &) Q_DECL_OVERRIDE; @@ -200,6 +204,7 @@ Q_SIGNALS: void smoothChanged(bool smooth); void formatChanged(QQuickShaderEffectSource::Format format); void sourceRectChanged(const QRectF &sourceRect); + void textureMirroringChanged(QQuickShaderEffectSource::TextureMirroring mirroring); private: friend class QQuickTransformAnimatorJob; @@ -223,6 +228,7 @@ private: QQmlComponent *m_effectComponent; QQuickItem *m_effect; QQuickShaderEffectSource *m_effectSource; + QQuickShaderEffectSource::TextureMirroring m_textureMirroring; }; class Q_QUICK_PRIVATE_EXPORT QQuickItemPrivate : public QObjectPrivate diff --git a/src/quick/items/qquickitemsmodule.cpp b/src/quick/items/qquickitemsmodule.cpp index 4df1ef038c..62e0adcb0a 100644 --- a/src/quick/items/qquickitemsmodule.cpp +++ b/src/quick/items/qquickitemsmodule.cpp @@ -273,6 +273,7 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor) qmlRegisterType(uri, 2, 6, "Flow"); qmlRegisterUncreatableType(uri, 2, 6, "EnterKey", QQuickEnterKeyAttached::tr("EnterKey is only available via attached properties")); + qmlRegisterType(uri, 2, 6, "ShaderEffectSource"); } static void initResources() diff --git a/src/quick/items/qquickshadereffectsource.cpp b/src/quick/items/qquickshadereffectsource.cpp index bf69fe4277..2effc0d0ae 100644 --- a/src/quick/items/qquickshadereffectsource.cpp +++ b/src/quick/items/qquickshadereffectsource.cpp @@ -189,6 +189,7 @@ QQuickShaderEffectSource::QQuickShaderEffectSource(QQuickItem *parent) , m_mipmap(false) , m_recursive(false) , m_grab(true) + , m_textureMirroring(MirrorVertically) { setFlag(ItemHasContents); } @@ -542,6 +543,37 @@ void QQuickShaderEffectSource::setRecursive(bool enabled) emit recursiveChanged(); } +/*! + \qmlproperty enumeration QtQuick::ShaderEffectSource::textureMirroring + \since 5.6 + + This property defines how the generated OpenGL texture should be mirrored. + The default value is \c{ShaderEffectSource.MirrorVertically}. + Custom mirroring can be useful if the generated texture is directly accessed by custom shaders, + such as those specified by ShaderEffect. Mirroring has no effect on the UI representation of + the ShaderEffectSource item itself. + + \list + \li ShaderEffectSource.NoMirroring - No mirroring + \li ShaderEffectSource.MirrorHorizontally - The generated texture is flipped along X-axis. + \li ShaderEffectSource.MirrorVertically - The generated texture is flipped along Y-axis. + \endlist +*/ + +QQuickShaderEffectSource::TextureMirroring QQuickShaderEffectSource::textureMirroring() const +{ + return QQuickShaderEffectSource::TextureMirroring(m_textureMirroring); +} + +void QQuickShaderEffectSource::setTextureMirroring(TextureMirroring mirroring) +{ + if (mirroring == QQuickShaderEffectSource::TextureMirroring(m_textureMirroring)) + return; + m_textureMirroring = mirroring; + update(); + emit textureMirroringChanged(); +} + /*! \qmlmethod QtQuick::ShaderEffectSource::scheduleUpdate() @@ -642,6 +674,8 @@ QSGNode *QQuickShaderEffectSource::updatePaintNode(QSGNode *oldNode, UpdatePaint m_texture->setRecursive(m_recursive); m_texture->setFormat(GLenum(m_format)); m_texture->setHasMipmaps(m_mipmap); + m_texture->setMirrorHorizontal(m_textureMirroring & MirrorHorizontally); + m_texture->setMirrorVertical(m_textureMirroring & MirrorVertically); if (m_grab) m_texture->scheduleUpdate(); diff --git a/src/quick/items/qquickshadereffectsource_p.h b/src/quick/items/qquickshadereffectsource_p.h index 94bb315566..629acf0f55 100644 --- a/src/quick/items/qquickshadereffectsource_p.h +++ b/src/quick/items/qquickshadereffectsource_p.h @@ -66,6 +66,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickShaderEffectSource : public QQuickItem, publi Q_PROPERTY(bool hideSource READ hideSource WRITE setHideSource NOTIFY hideSourceChanged) Q_PROPERTY(bool mipmap READ mipmap WRITE setMipmap NOTIFY mipmapChanged) Q_PROPERTY(bool recursive READ recursive WRITE setRecursive NOTIFY recursiveChanged) + Q_PROPERTY(TextureMirroring textureMirroring READ textureMirroring WRITE setTextureMirroring NOTIFY textureMirroringChanged REVISION 1) public: enum WrapMode { @@ -83,6 +84,13 @@ public: }; Q_ENUM(Format) + enum TextureMirroring { + NoMirroring = 0x00, + MirrorHorizontally = 0x01, + MirrorVertically = 0x02 + }; + Q_ENUM(TextureMirroring) + QQuickShaderEffectSource(QQuickItem *parent = 0); ~QQuickShaderEffectSource(); @@ -113,6 +121,9 @@ public: bool recursive() const; void setRecursive(bool enabled); + TextureMirroring textureMirroring() const; + void setTextureMirroring(TextureMirroring mirroring); + bool isTextureProvider() const Q_DECL_OVERRIDE { return true; } QSGTextureProvider *textureProvider() const Q_DECL_OVERRIDE; @@ -128,6 +139,7 @@ Q_SIGNALS: void hideSourceChanged(); void mipmapChanged(); void recursiveChanged(); + void textureMirroringChanged(); void scheduledUpdateCompleted(); @@ -157,6 +169,7 @@ private: uint m_mipmap : 1; uint m_recursive : 1; uint m_grab : 1; + uint m_textureMirroring : 2; // Stores TextureMirroring enum }; QT_END_NAMESPACE diff --git a/src/quick/scenegraph/qsgadaptationlayer_p.h b/src/quick/scenegraph/qsgadaptationlayer_p.h index 1253711a94..fde3fa06b2 100644 --- a/src/quick/scenegraph/qsgadaptationlayer_p.h +++ b/src/quick/scenegraph/qsgadaptationlayer_p.h @@ -195,6 +195,8 @@ public: virtual void setFormat(GLenum format) = 0; virtual void setHasMipmaps(bool mipmap) = 0; virtual void setDevicePixelRatio(qreal ratio) = 0; + virtual void setMirrorHorizontal(bool mirror) = 0; + virtual void setMirrorVertical(bool mirror) = 0; Q_SLOT virtual void markDirtyTexture() = 0; Q_SLOT virtual void invalidated() = 0; diff --git a/src/quick/scenegraph/qsgdefaultlayer.cpp b/src/quick/scenegraph/qsgdefaultlayer.cpp index cca0712ece..fa69f911dd 100644 --- a/src/quick/scenegraph/qsgdefaultlayer.cpp +++ b/src/quick/scenegraph/qsgdefaultlayer.cpp @@ -97,6 +97,8 @@ QSGDefaultLayer::QSGDefaultLayer(QSGRenderContext *context) , m_multisamplingChecked(false) , m_multisampling(false) , m_grab(false) + , m_mirrorHorizontal(false) + , m_mirrorVertical(true) { } @@ -259,6 +261,16 @@ void QSGDefaultLayer::setRecursive(bool recursive) m_recursive = recursive; } +void QSGDefaultLayer::setMirrorHorizontal(bool mirror) +{ + m_mirrorHorizontal = mirror; +} + +void QSGDefaultLayer::setMirrorVertical(bool mirror) +{ + m_mirrorVertical = mirror; +} + void QSGDefaultLayer::markDirtyTexture() { m_dirtyTexture = true; @@ -365,7 +377,10 @@ void QSGDefaultLayer::grab() m_renderer->setDeviceRect(m_size); m_renderer->setViewportRect(m_size); - QRectF mirrored(m_rect.left(), m_rect.bottom(), m_rect.width(), -m_rect.height()); + QRectF mirrored(m_mirrorHorizontal ? m_rect.right() : m_rect.left(), + m_mirrorVertical ? m_rect.bottom() : m_rect.top(), + m_mirrorHorizontal ? -m_rect.width() : m_rect.width(), + m_mirrorVertical ? -m_rect.height() : m_rect.height()); m_renderer->setProjectionMatrixToRect(mirrored); m_renderer->setClearColor(Qt::transparent); @@ -428,3 +443,11 @@ QImage QSGDefaultLayer::toImage() const return QImage(); } + +QRectF QSGDefaultLayer::normalizedTextureSubRect() const +{ + return QRectF(m_mirrorHorizontal ? 1 : 0, + m_mirrorVertical ? 0 : 1, + m_mirrorHorizontal ? -1 : 1, + m_mirrorVertical ? 1 : -1); +} diff --git a/src/quick/scenegraph/qsgdefaultlayer_p.h b/src/quick/scenegraph/qsgdefaultlayer_p.h index 0ba7109ef6..7baaed5f67 100644 --- a/src/quick/scenegraph/qsgdefaultlayer_p.h +++ b/src/quick/scenegraph/qsgdefaultlayer_p.h @@ -78,10 +78,18 @@ public: void setDevicePixelRatio(qreal ratio) Q_DECL_OVERRIDE { m_device_pixel_ratio = ratio; } + bool mirrorHorizontal() const { return bool(m_mirrorHorizontal); } + void setMirrorHorizontal(bool mirror) Q_DECL_OVERRIDE; + + bool mirrorVertical() const { return bool(m_mirrorVertical); } + void setMirrorVertical(bool mirror) Q_DECL_OVERRIDE; + void scheduleUpdate() Q_DECL_OVERRIDE; QImage toImage() const Q_DECL_OVERRIDE; + QRectF normalizedTextureSubRect() const Q_DECL_OVERRIDE; + public Q_SLOTS: void markDirtyTexture() Q_DECL_OVERRIDE; void invalidated() Q_DECL_OVERRIDE; @@ -115,6 +123,8 @@ private: uint m_multisamplingChecked : 1; uint m_multisampling : 1; uint m_grab : 1; + uint m_mirrorHorizontal : 1; + uint m_mirrorVertical : 1; }; #endif // QSGDEFAULTLAYER_P_H diff --git a/tests/auto/quick/qquickitemlayer/data/TextureMirroring.qml b/tests/auto/quick/qquickitemlayer/data/TextureMirroring.qml new file mode 100644 index 0000000000..2827960153 --- /dev/null +++ b/tests/auto/quick/qquickitemlayer/data/TextureMirroring.qml @@ -0,0 +1,159 @@ +import QtQuick 2.6 + +Item +{ + width: 250 + height: 50 + + property int mirroring: 0 + + // Layered box without effect. Mirroring should not affect how it looks. + Rectangle { + x: 0 + y: 0 + width: 50 + height: 50 + layer.enabled: true + layer.textureMirroring: mirroring + Rectangle { + x: 0 + y: 0 + width: 25 + height: 25 + color: "#000000" + } + Rectangle { + x: 25 + y: 0 + width: 25 + height: 25 + color: "#ff0000" + } + Rectangle { + x: 0 + y: 25 + width: 25 + height: 25 + color: "#00ff00" + } + Rectangle { + x: 25 + y: 25 + width: 25 + height: 25 + color: "#0000ff" + } + } + + // Layered box with effect. Mirroring should affect how it looks. + Rectangle { + id: layeredEffectBox + x: 50 + y: 0 + width: 50 + height: 50 + layer.enabled: true + layer.textureMirroring: mirroring + layer.samplerName: "source" + layer.effect: ShaderEffect { + property variant source: layeredEffectBox + fragmentShader: " + uniform lowp sampler2D source; + varying highp vec2 qt_TexCoord0; + void main() { + gl_FragColor = texture2D(source, qt_TexCoord0); + }" + + } + + Rectangle { + x: 0 + y: 0 + width: 25 + height: 25 + color: "#000000" + } + Rectangle { + x: 25 + y: 0 + width: 25 + height: 25 + color: "#ff0000" + } + Rectangle { + x: 0 + y: 25 + width: 25 + height: 25 + color: "#00ff00" + } + Rectangle { + x: 25 + y: 25 + width: 25 + height: 25 + color: "#0000ff" + } + } + + // Non-layered source item for ShaderEffectSource. Mirroring should not affect how it looks. + Rectangle { + id: box2 + x: 100 + y: 0 + width: 50 + height: 50 + Rectangle { + x: 0 + y: 0 + width: 25 + height: 25 + color: "#000000" + } + Rectangle { + x: 25 + y: 0 + width: 25 + height: 25 + color: "#ff0000" + } + Rectangle { + x: 0 + y: 25 + width: 25 + height: 25 + color: "#00ff00" + } + Rectangle { + x: 25 + y: 25 + width: 25 + height: 25 + color: "#0000ff" + } + } + // ShaderEffectSource item. Mirroring should not affect how it looks. + ShaderEffectSource { + id: theSource + x: 150 + y: 0 + width: 50 + height: 50 + sourceItem: box2 + textureMirroring: mirroring + } + // ShaderEffect item. Mirroring should affect how it looks. + ShaderEffect { + x: 200 + y: 0 + width: 50 + height: 50 + property variant source: theSource + fragmentShader: " + uniform lowp sampler2D source; + varying highp vec2 qt_TexCoord0; + void main() { + gl_FragColor = texture2D(source, qt_TexCoord0); + }" + } +} diff --git a/tests/auto/quick/qquickitemlayer/qquickitemlayer.pro b/tests/auto/quick/qquickitemlayer/qquickitemlayer.pro index 999f0cf23d..a087948f6d 100644 --- a/tests/auto/quick/qquickitemlayer/qquickitemlayer.pro +++ b/tests/auto/quick/qquickitemlayer/qquickitemlayer.pro @@ -25,5 +25,6 @@ OTHER_FILES += \ data/DisableLayer.qml \ data/SamplerNameChange.qml \ data/ItemEffect.qml \ - data/RectangleEffect.qml + data/RectangleEffect.qml \ + data/TextureMirroring.qml DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp b/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp index 25a75c0580..094b69c07f 100644 --- a/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp +++ b/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp @@ -87,7 +87,12 @@ private slots: void itemEffect(); void rectangleEffect(); + void textureMirroring_data(); + void textureMirroring(); + private: + void mirroringCheck(int mirroring, int x, bool shouldMirror, const QImage &fb); + bool m_isMesaSoftwareRasterizer; int m_mesaVersion; }; @@ -434,6 +439,94 @@ void tst_QQuickItemLayer::rectangleEffect() QCOMPARE(fb.pixel(0, 100), qRgb(0, 0, 0xff)); } +void tst_QQuickItemLayer::textureMirroring_data() +{ + QTest::addColumn("mirroring"); + + QTest::newRow("no mirroring") << 0; + QTest::newRow("horizontal") << 1; + QTest::newRow("vertical") << 2; + QTest::newRow("horizontal | vertical") << 3; +} + +void tst_QQuickItemLayer::textureMirroring() +{ + QFETCH(int, mirroring); + + QQuickView view; + view.setSource(testFileUrl("TextureMirroring.qml")); + + QQuickItem *child = view.contentItem()->childItems().at(0); + child->setProperty("mirroring", mirroring); + + view.show(); + + QTest::qWaitForWindowExposed(&view); + + QImage fb = view.grabWindow(); + + // Mirroring should have no visual effect on layered item without shader effect + mirroringCheck(mirroring, 0, false, fb); + + // Mirroring should have visual effect on layered item with shader effect + mirroringCheck(mirroring, 50, true, fb); + + // Mirroring should have no visual effect on source item for ShaderEffectSource + mirroringCheck(mirroring, 100, false, fb); + + // Mirroring should have no visual effect on ShaderEffectSource item + mirroringCheck(mirroring, 150, false, fb); + + // Mirroring should have visual effect on ShaderEffect item itself + mirroringCheck(mirroring, 200, true, fb); +} + +void tst_QQuickItemLayer::mirroringCheck(int mirroring, int x, bool shouldMirror, const QImage &fb) +{ + int offset = 10; + int spacing = 25; + + if (shouldMirror) { + switch (mirroring) { + case 0: { // No mirroring -> Visually Y gets swapped, X is default + QCOMPARE(fb.pixel(x + offset, offset), qRgb(0, 0xff, 0)); + QCOMPARE(fb.pixel(x + offset + spacing, offset), qRgb(0, 0, 0xff)); + QCOMPARE(fb.pixel(x + offset, offset + spacing), qRgb(0, 0, 0)); + QCOMPARE(fb.pixel(x + offset + spacing, offset + spacing), qRgb(0xff, 0, 0)); + break; + } + case 1: { // Horizontal mirroring -> Visually both X and Y get swapped, as neither is default + QCOMPARE(fb.pixel(x + offset, offset), qRgb(0, 0, 0xff)); + QCOMPARE(fb.pixel(x + offset + spacing, offset), qRgb(0, 0xff, 0)); + QCOMPARE(fb.pixel(x + offset, offset + spacing), qRgb(0xff, 0, 0)); + QCOMPARE(fb.pixel(x + offset + spacing, offset + spacing), qRgb(0, 0, 0)); + break; + } + case 2: { // Vertical mirroring -> The default case, nothing gets swapped + QCOMPARE(fb.pixel(x + offset, offset), qRgb(0, 0, 0)); + QCOMPARE(fb.pixel(x + offset + spacing, offset), qRgb(0xff, 0, 0)); + QCOMPARE(fb.pixel(x + offset, offset + spacing), qRgb(0, 0xff, 0)); + QCOMPARE(fb.pixel(x + offset + spacing, offset + spacing), qRgb(0, 0, 0xff)); + break; + } + case 3: { // Both axes mirrored -> Visually X gets swapped, Y is default + QCOMPARE(fb.pixel(x + offset, offset), qRgb(0xff, 0, 0)); + QCOMPARE(fb.pixel(x + offset + spacing, offset), qRgb(0, 0, 0)); + QCOMPARE(fb.pixel(x + offset, offset + spacing), qRgb(0, 0, 0xff)); + QCOMPARE(fb.pixel(x + offset + spacing, offset + spacing), qRgb(0, 0xff, 0)); + break; + } + default: + qWarning() << "Invalid case!"; + break; + } + } else { + QCOMPARE(fb.pixel(x + offset, offset), qRgb(0, 0, 0)); + QCOMPARE(fb.pixel(x + offset + spacing, offset), qRgb(0xff, 0, 0)); + QCOMPARE(fb.pixel(x + offset, offset + spacing), qRgb(0, 0xff, 0)); + QCOMPARE(fb.pixel(x + offset + spacing, offset + spacing), qRgb(0, 0, 0xff)); + } +} QTEST_MAIN(tst_QQuickItemLayer) -- cgit v1.2.3 From 6dda1b425867b76fb001b11f43836c56e24ab7a4 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Thu, 20 Aug 2015 14:16:15 +0200 Subject: Fix rendering to QQuickWindow::renderTarget. When setting an FBO, the size of the window should be irrelevant, so we need to use the renderTargetSize to specify the viewport and device rect. Change-Id: Id76736cfaf6c511439bb8af80e3c641025d9d547 Reviewed-by: Laszlo Agocs --- src/quick/items/qquickwindow.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index 99dbf1d83e..8ab910f299 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -368,12 +368,15 @@ void QQuickWindowPrivate::renderSceneGraph(const QSize &size) if (!customRenderStage || !customRenderStage->render()) { int fboId = 0; const qreal devicePixelRatio = q->effectiveDevicePixelRatio(); - renderer->setDeviceRect(QRect(QPoint(0, 0), size * devicePixelRatio)); if (renderTargetId) { + QRect rect(QPoint(0, 0), renderTargetSize); fboId = renderTargetId; - renderer->setViewportRect(QRect(QPoint(0, 0), renderTargetSize)); + renderer->setDeviceRect(rect); + renderer->setViewportRect(rect); } else { - renderer->setViewportRect(QRect(QPoint(0, 0), size * devicePixelRatio)); + QRect rect(QPoint(0, 0), devicePixelRatio * size); + renderer->setDeviceRect(rect); + renderer->setViewportRect(rect); } renderer->setProjectionMatrixToRect(QRect(QPoint(0, 0), size)); renderer->setDevicePixelRatio(devicePixelRatio); -- cgit v1.2.3 From cc98678f404cd49750076795f39b31bfa36c80c3 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 12 Aug 2015 12:15:47 +0200 Subject: Use the QmlContext as the scope for QQmlV4Function calls This further reduces our dependency on the QQmlContextWrapper and reduces storage requirements in the QObjectMethod. Change-Id: I2c12d0a8818d81d45139f482caac8510ad8dfddc Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4qobjectwrapper.cpp | 18 +++++------------- src/qml/jsruntime/qv4qobjectwrapper_p.h | 5 ++--- src/qml/jsruntime/qv4script.cpp | 2 +- src/qml/qml/v8/qv8engine_p.h | 13 ++++++------- 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index e5946d8be6..d1796f5fd4 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -333,9 +333,8 @@ ReturnedValue QObjectWrapper::getProperty(ExecutionEngine *engine, QObject *obje Q_ASSERT(vmemo); return vmemo->vmeMethod(property->coreIndex); } else if (property->isV4Function()) { - QV4::ScopedObject qmlcontextobject(scope, engine->qmlContextObject()); - ScopedContext global(scope, scope.engine->rootContext()); - return QV4::QObjectMethod::create(global, object, property->coreIndex, qmlcontextobject); + ScopedContext global(scope, scope.engine->qmlContext()); + return QV4::QObjectMethod::create(global, object, property->coreIndex); } else if (property->isSignalHandler()) { QV4::Scoped handler(scope, scope.engine->memoryManager->alloc(engine, object, property->coreIndex)); @@ -1726,7 +1725,7 @@ QV4::ReturnedValue CallArgument::toValue(QV4::ExecutionEngine *engine) } } -ReturnedValue QObjectMethod::create(ExecutionContext *scope, QObject *object, int index, const Value &qmlGlobal) +ReturnedValue QObjectMethod::create(ExecutionContext *scope, QObject *object, int index) { Scope valueScope(scope); Scoped method(valueScope, scope->d()->engine->memoryManager->alloc(scope)); @@ -1736,18 +1735,16 @@ ReturnedValue QObjectMethod::create(ExecutionContext *scope, QObject *object, in method->d()->propertyCache = ddata->propertyCache; method->d()->index = index; - method->d()->qmlGlobal = qmlGlobal; method->d()->valueTypeWrapper = Primitive::undefinedValue(); return method.asReturnedValue(); } -ReturnedValue QObjectMethod::create(ExecutionContext *scope, const QQmlValueTypeWrapper *valueType, int index, const Value &qmlGlobal) +ReturnedValue QObjectMethod::create(ExecutionContext *scope, const QQmlValueTypeWrapper *valueType, int index) { Scope valueScope(scope); Scoped method(valueScope, scope->d()->engine->memoryManager->alloc(scope)); method->d()->propertyCache = valueType->d()->propertyCache; method->d()->index = index; - method->d()->qmlGlobal = qmlGlobal; method->d()->valueTypeWrapper = *valueType; return method.asReturnedValue(); } @@ -1863,11 +1860,7 @@ ReturnedValue QObjectMethod::callInternal(CallData *callData) const if (method.isV4Function()) { QV4::ScopedValue rv(scope, QV4::Primitive::undefinedValue()); - - QV4::ScopedValue qmlGlobal(scope, d()->qmlGlobal); - QQmlV4Function func(callData, rv, qmlGlobal, - QmlContextWrapper::getContext(qmlGlobal), - scope.engine); + QQmlV4Function func(callData, rv, scope.engine); QQmlV4Function *funcptr = &func; void *args[] = { 0, &funcptr }; @@ -1886,7 +1879,6 @@ ReturnedValue QObjectMethod::callInternal(CallData *callData) const void QObjectMethod::markObjects(Heap::Base *that, ExecutionEngine *e) { QObjectMethod::Data *This = static_cast(that); - This->qmlGlobal.mark(e); This->valueTypeWrapper.mark(e); FunctionObject::markObjects(that, e); diff --git a/src/qml/jsruntime/qv4qobjectwrapper_p.h b/src/qml/jsruntime/qv4qobjectwrapper_p.h index 542d908194..da24c81f40 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper_p.h +++ b/src/qml/jsruntime/qv4qobjectwrapper_p.h @@ -79,7 +79,6 @@ struct QObjectMethod : FunctionObject { QPointer object; QQmlRefPointer propertyCache; int index; - Value qmlGlobal; Value valueTypeWrapper; @@ -149,8 +148,8 @@ struct Q_QML_EXPORT QObjectMethod : public QV4::FunctionObject enum { DestroyMethod = -1, ToStringMethod = -2 }; - static ReturnedValue create(QV4::ExecutionContext *scope, QObject *object, int index, const Value &qmlGlobal = Primitive::undefinedValue()); - static ReturnedValue create(QV4::ExecutionContext *scope, const QQmlValueTypeWrapper *valueType, int index, const Value &qmlGlobal = Primitive::undefinedValue()); + static ReturnedValue create(QV4::ExecutionContext *scope, QObject *object, int index); + static ReturnedValue create(QV4::ExecutionContext *scope, const QQmlValueTypeWrapper *valueType, int index); int methodIndex() const { return d()->index; } QObject *object() const { return d()->object.data(); } diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp index 0bf4f21acb..d619c1a7c8 100644 --- a/src/qml/jsruntime/qv4script.cpp +++ b/src/qml/jsruntime/qv4script.cpp @@ -379,7 +379,7 @@ ReturnedValue Script::qmlBinding() return v.asReturnedValue(); } -QV4::ReturnedValue Script::evaluate(ExecutionEngine *engine, const QString &script, Object *scopeObject) +QV4::ReturnedValue Script::evaluate(ExecutionEngine *engine, const QString &script, Object *scopeObject) { QV4::Scope scope(engine); QV4::Script qmlScript(engine, scopeObject, script, QString()); diff --git a/src/qml/qml/v8/qv8engine_p.h b/src/qml/qml/v8/qv8engine_p.h index 5d12244dcb..08bbbb8548 100644 --- a/src/qml/qml/v8/qv8engine_p.h +++ b/src/qml/qml/v8/qv8engine_p.h @@ -63,6 +63,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -119,8 +120,8 @@ class QQmlV4Function public: int length() const { return callData->argc; } QV4::ReturnedValue operator[](int idx) { return (idx < callData->argc ? callData->args[idx].asReturnedValue() : QV4::Encode::undefined()); } - QQmlContextData *context() { return ctx; } - QV4::ReturnedValue qmlGlobal() { return callData->thisObject.asReturnedValue(); } + QQmlContextData *context() { return e->qmlContextObject()->context.contextData(); } + QV4::ReturnedValue qmlGlobal() { return e->qmlContextObject()->asReturnedValue(); } void setReturnValue(QV4::ReturnedValue rv) { *retVal = rv; } QV4::ExecutionEngine *v4engine() const { return e; } private: @@ -129,16 +130,14 @@ private: QQmlV4Function(const QQmlV4Function &); QQmlV4Function &operator=(const QQmlV4Function &); - QQmlV4Function(QV4::CallData *callData, QV4::Value *retVal, - const QV4::Value &global, QQmlContextData *c, QV4::ExecutionEngine *e) - : callData(callData), retVal(retVal), ctx(c), e(e) + QQmlV4Function(QV4::CallData *callData, QV4::Value *retVal, QV4::ExecutionEngine *e) + : callData(callData), retVal(retVal), e(e) { - callData->thisObject = QV4::Value::fromReturnedValue(global.asReturnedValue()); + callData->thisObject = QV4::Encode::undefined(); } QV4::CallData *callData; QV4::Value *retVal; - QQmlContextData *ctx; QV4::ExecutionEngine *e; }; -- cgit v1.2.3 From 04d3a95dea37cbc79348147eebac9916cc8b4c79 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 12 Aug 2015 14:02:19 +0200 Subject: Move the registerQmlDependencies method into QQmlPropertyCapture This is where the method logically belongs, and removes one more thing from the context wrapper. Change-Id: Ibc076c9b31903a484ad4517402eca2a3b7f0d660 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4functionobject.cpp | 10 ++++---- src/qml/qml/qqmlcontextwrapper.cpp | 43 ------------------------------- src/qml/qml/qqmlcontextwrapper_p.h | 2 -- src/qml/qml/qqmljavascriptexpression.cpp | 44 ++++++++++++++++++++++++++++++++ src/qml/qml/qqmljavascriptexpression_p.h | 2 ++ 5 files changed, 51 insertions(+), 50 deletions(-) diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index da01592c0d..6412e65fa9 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -46,7 +46,7 @@ #include #include #include -#include +#include #include #include #include "private/qlocale_tools_p.h" @@ -430,7 +430,7 @@ ReturnedValue ScriptFunction::construct(const Managed *that, CallData *callData) ScopedValue result(scope, Q_V4_PROFILE(v4, f->function())); if (f->function()->compiledFunction->hasQmlDependencies()) - QmlContextWrapper::registerQmlDependencies(v4, f->function()->compiledFunction); + QQmlPropertyCapture::registerQmlDependencies(v4, f->function()->compiledFunction); if (v4->hasException) return Encode::undefined(); @@ -457,7 +457,7 @@ ReturnedValue ScriptFunction::call(const Managed *that, CallData *callData) ScopedValue result(scope, Q_V4_PROFILE(v4, f->function())); if (f->function()->compiledFunction->hasQmlDependencies()) - QmlContextWrapper::registerQmlDependencies(scope.engine, f->function()->compiledFunction); + QQmlPropertyCapture::registerQmlDependencies(scope.engine, f->function()->compiledFunction); return result->asReturnedValue(); } @@ -531,7 +531,7 @@ ReturnedValue SimpleScriptFunction::construct(const Managed *that, CallData *cal ScopedObject result(scope, Q_V4_PROFILE(v4, f->function())); if (f->function()->compiledFunction->hasQmlDependencies()) - QmlContextWrapper::registerQmlDependencies(v4, f->function()->compiledFunction); + QQmlPropertyCapture::registerQmlDependencies(v4, f->function()->compiledFunction); if (!result) return callData->thisObject.asReturnedValue(); @@ -569,7 +569,7 @@ ReturnedValue SimpleScriptFunction::call(const Managed *that, CallData *callData ScopedValue result(scope, Q_V4_PROFILE(v4, f->function())); if (f->function()->compiledFunction->hasQmlDependencies()) - QmlContextWrapper::registerQmlDependencies(v4, f->function()->compiledFunction); + QQmlPropertyCapture::registerQmlDependencies(v4, f->function()->compiledFunction); return result->asReturnedValue(); } diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp index 23084fb202..be06c596c2 100644 --- a/src/qml/qml/qqmlcontextwrapper.cpp +++ b/src/qml/qml/qqmlcontextwrapper.cpp @@ -323,49 +323,6 @@ void QmlContextWrapper::put(Managed *m, String *name, const Value &value) Object::put(m, name, value); } -void QmlContextWrapper::registerQmlDependencies(ExecutionEngine *engine, const CompiledData::Function *compiledFunction) -{ - // Let the caller check and avoid the function call :) - Q_ASSERT(compiledFunction->hasQmlDependencies()); - - QQmlEnginePrivate *ep = engine->qmlEngine() ? QQmlEnginePrivate::get(engine->qmlEngine()) : 0; - if (!ep) - return; - QQmlPropertyCapture *capture = ep->propertyCapture; - if (!capture) - return; - - QV4::Scope scope(engine); - QV4::Scoped context(scope, engine->qmlContext()); - QQmlContextData *qmlContext = context->qmlContext(); - - const quint32 *idObjectDependency = compiledFunction->qmlIdObjectDependencyTable(); - const int idObjectDependencyCount = compiledFunction->nDependingIdObjects; - for (int i = 0; i < idObjectDependencyCount; ++i, ++idObjectDependency) { - Q_ASSERT(int(*idObjectDependency) < qmlContext->idValueCount); - capture->captureProperty(&qmlContext->idValues[*idObjectDependency].bindings); - } - - Q_ASSERT(qmlContext->contextObject); - const quint32 *contextPropertyDependency = compiledFunction->qmlContextPropertiesDependencyTable(); - const int contextPropertyDependencyCount = compiledFunction->nDependingContextProperties; - for (int i = 0; i < contextPropertyDependencyCount; ++i) { - const int propertyIndex = *contextPropertyDependency++; - const int notifyIndex = *contextPropertyDependency++; - capture->captureProperty(qmlContext->contextObject, propertyIndex, notifyIndex); - } - - QObject *scopeObject = context->qmlScope(); - const quint32 *scopePropertyDependency = compiledFunction->qmlScopePropertiesDependencyTable(); - const int scopePropertyDependencyCount = compiledFunction->nDependingScopeProperties; - for (int i = 0; i < scopePropertyDependencyCount; ++i) { - const int propertyIndex = *scopePropertyDependency++; - const int notifyIndex = *scopePropertyDependency++; - capture->captureProperty(scopeObject, propertyIndex, notifyIndex); - } - -} - ReturnedValue QmlContextWrapper::qmlSingletonWrapper(ExecutionEngine *v4, String *name) { if (!d()->context->imports) diff --git a/src/qml/qml/qqmlcontextwrapper_p.h b/src/qml/qml/qqmlcontextwrapper_p.h index 7b5d3216df..d7a4a10468 100644 --- a/src/qml/qml/qqmlcontextwrapper_p.h +++ b/src/qml/qml/qqmlcontextwrapper_p.h @@ -99,8 +99,6 @@ struct Q_QML_EXPORT QmlContextWrapper : Object static ReturnedValue get(const Managed *m, String *name, bool *hasProperty); static void put(Managed *m, String *name, const Value &value); - static void registerQmlDependencies(ExecutionEngine *context, const CompiledData::Function *compiledFunction); - ReturnedValue qmlSingletonWrapper(ExecutionEngine *e, String *name); }; diff --git a/src/qml/qml/qqmljavascriptexpression.cpp b/src/qml/qml/qqmljavascriptexpression.cpp index 5f30eac066..967a7e75d7 100644 --- a/src/qml/qml/qqmljavascriptexpression.cpp +++ b/src/qml/qml/qqmljavascriptexpression.cpp @@ -287,6 +287,50 @@ void QQmlPropertyCapture::captureProperty(QObject *o, int c, int n) } } +void QQmlPropertyCapture::registerQmlDependencies(QV4::ExecutionEngine *engine, const QV4::CompiledData::Function *compiledFunction) +{ + // Let the caller check and avoid the function call :) + Q_ASSERT(compiledFunction->hasQmlDependencies()); + + QQmlEnginePrivate *ep = engine->qmlEngine() ? QQmlEnginePrivate::get(engine->qmlEngine()) : 0; + if (!ep) + return; + QQmlPropertyCapture *capture = ep->propertyCapture; + if (!capture) + return; + + QV4::Scope scope(engine); + QV4::Scoped context(scope, engine->qmlContext()); + QQmlContextData *qmlContext = context->qmlContext(); + + const quint32 *idObjectDependency = compiledFunction->qmlIdObjectDependencyTable(); + const int idObjectDependencyCount = compiledFunction->nDependingIdObjects; + for (int i = 0; i < idObjectDependencyCount; ++i, ++idObjectDependency) { + Q_ASSERT(int(*idObjectDependency) < qmlContext->idValueCount); + capture->captureProperty(&qmlContext->idValues[*idObjectDependency].bindings); + } + + Q_ASSERT(qmlContext->contextObject); + const quint32 *contextPropertyDependency = compiledFunction->qmlContextPropertiesDependencyTable(); + const int contextPropertyDependencyCount = compiledFunction->nDependingContextProperties; + for (int i = 0; i < contextPropertyDependencyCount; ++i) { + const int propertyIndex = *contextPropertyDependency++; + const int notifyIndex = *contextPropertyDependency++; + capture->captureProperty(qmlContext->contextObject, propertyIndex, notifyIndex); + } + + QObject *scopeObject = context->qmlScope(); + const quint32 *scopePropertyDependency = compiledFunction->qmlScopePropertiesDependencyTable(); + const int scopePropertyDependencyCount = compiledFunction->nDependingScopeProperties; + for (int i = 0; i < scopePropertyDependencyCount; ++i) { + const int propertyIndex = *scopePropertyDependency++; + const int notifyIndex = *scopePropertyDependency++; + capture->captureProperty(scopeObject, propertyIndex, notifyIndex); + } + +} + + void QQmlJavaScriptExpression::clearError() { if (m_error) diff --git a/src/qml/qml/qqmljavascriptexpression_p.h b/src/qml/qml/qqmljavascriptexpression_p.h index dfcf8b2d68..f0a3741588 100644 --- a/src/qml/qml/qqmljavascriptexpression_p.h +++ b/src/qml/qml/qqmljavascriptexpression_p.h @@ -176,6 +176,8 @@ public: void captureProperty(QQmlNotifier *); void captureProperty(QObject *, int, int); + static void registerQmlDependencies(QV4::ExecutionEngine *engine, const QV4::CompiledData::Function *compiledFunction); + QQmlEngine *engine; QQmlJavaScriptExpression *expression; QQmlJavaScriptExpression::DeleteWatcher *watcher; -- cgit v1.2.3 From ad55f5fd249296de8871545f6d4cf463bd5ed1c9 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 12 Aug 2015 14:14:40 +0200 Subject: Move the qmlSingletonWrapper method out of the contextwrapper One more step towards removing the class alltogether. Change-Id: Ic9f6794eb3c5c6605ee43ad23a6d432ebbf321a1 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4engine.cpp | 21 +++++++++++++++++++++ src/qml/jsruntime/qv4engine_p.h | 1 + src/qml/jsruntime/qv4runtime.cpp | 3 +-- src/qml/qml/qqmlcontextwrapper.cpp | 21 --------------------- src/qml/qml/qqmlcontextwrapper_p.h | 2 -- 5 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 7424dc4e4c..caf07e8b0b 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -759,6 +759,27 @@ QObject *ExecutionEngine::qmlScopeObject() const return qmlContextObject()->scopeObject; } +ReturnedValue ExecutionEngine::qmlSingletonWrapper(String *name) +{ + QQmlContextData *ctx = callingQmlContext(); + if (!ctx->imports) + return Encode::undefined(); + // Search for attached properties, enums and imported scripts + QQmlTypeNameCache::Result r = ctx->imports->query(name); + + Q_ASSERT(r.isValid()); + Q_ASSERT(r.type); + Q_ASSERT(r.type->isSingleton()); + + QQmlType::SingletonInstanceInfo *siinfo = r.type->singletonInstanceInfo(); + QQmlEngine *e = qmlEngine(); + siinfo->init(e); + + if (QObject *qobjectSingleton = siinfo->qobjectApi(e)) + return QV4::QObjectWrapper::wrap(this, qobjectSingleton); + return QJSValuePrivate::convertedToValue(this, siinfo->scriptApi(e)); +} + QQmlContextData *ExecutionEngine::callingQmlContext() const { Heap::QmlContextWrapper *w = qmlContextObject(); diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index 9f44745e4c..90564a9652 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -390,6 +390,7 @@ public: Heap::QmlContext *qmlContext() const; QV4::Heap::QmlContextWrapper *qmlContextObject() const; QObject *qmlScopeObject() const; + ReturnedValue qmlSingletonWrapper(String *name); QQmlContextData *callingQmlContext() const; diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index b8ea6d7a87..9316223696 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -1460,8 +1460,7 @@ QV4::ReturnedValue Runtime::getQmlSingleton(QV4::NoThrowEngine *engine, int name { Scope scope(engine); ScopedString name(scope, engine->currentContext()->compilationUnit->runtimeStrings[nameIndex]); - Scoped wrapper(scope, engine->qmlContextObject()); - return wrapper->qmlSingletonWrapper(engine, name); + return engine->qmlSingletonWrapper(name); } void Runtime::convertThisToObject(ExecutionEngine *engine) diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp index be06c596c2..4fee3d8fef 100644 --- a/src/qml/qml/qqmlcontextwrapper.cpp +++ b/src/qml/qml/qqmlcontextwrapper.cpp @@ -323,25 +323,4 @@ void QmlContextWrapper::put(Managed *m, String *name, const Value &value) Object::put(m, name, value); } -ReturnedValue QmlContextWrapper::qmlSingletonWrapper(ExecutionEngine *v4, String *name) -{ - if (!d()->context->imports) - return Encode::undefined(); - // Search for attached properties, enums and imported scripts - QQmlTypeNameCache::Result r = d()->context->imports->query(name); - - Q_ASSERT(r.isValid()); - Q_ASSERT(r.type); - Q_ASSERT(r.type->isSingleton()); - Q_ASSERT(v4); - - QQmlEngine *e = v4->qmlEngine(); - QQmlType::SingletonInstanceInfo *siinfo = r.type->singletonInstanceInfo(); - siinfo->init(e); - - if (QObject *qobjectSingleton = siinfo->qobjectApi(e)) - return QV4::QObjectWrapper::wrap(engine(), qobjectSingleton); - return QJSValuePrivate::convertedToValue(engine(), siinfo->scriptApi(e)); -} - QT_END_NAMESPACE diff --git a/src/qml/qml/qqmlcontextwrapper_p.h b/src/qml/qml/qqmlcontextwrapper_p.h index d7a4a10468..cbba35f5d1 100644 --- a/src/qml/qml/qqmlcontextwrapper_p.h +++ b/src/qml/qml/qqmlcontextwrapper_p.h @@ -98,8 +98,6 @@ struct Q_QML_EXPORT QmlContextWrapper : Object static ReturnedValue get(const Managed *m, String *name, bool *hasProperty); static void put(Managed *m, String *name, const Value &value); - - ReturnedValue qmlSingletonWrapper(ExecutionEngine *e, String *name); }; } -- cgit v1.2.3 From 88cc9b233435f5e9085faefa6e671f1c5e4d2b95 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 12 Aug 2015 15:08:54 +0200 Subject: Cleanup qmlcontextwrapper usage in XHR Get rid of the static getContext overload and simplify the signature of the dispatchCallback method in XHR. Get rid of the m_me object, and instead store a pointer to the thisObject and the context data directly. Turn all internal errors into assertions. Change-Id: I5427b2009c64f54b67cce1c130eace47201624bd Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlcontextwrapper.cpp | 13 -- src/qml/qml/qqmlcontextwrapper_p.h | 1 - src/qml/qml/qqmlxmlhttprequest.cpp | 146 +++++++-------------- .../auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 6 +- 4 files changed, 50 insertions(+), 116 deletions(-) diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp index 4fee3d8fef..1007029416 100644 --- a/src/qml/qml/qqmlcontextwrapper.cpp +++ b/src/qml/qml/qqmlcontextwrapper.cpp @@ -93,19 +93,6 @@ ReturnedValue QmlContextWrapper::urlScope(ExecutionEngine *v4, const QUrl &url) return w.asReturnedValue(); } -QQmlContextData *QmlContextWrapper::getContext(const Value &value) -{ - if (!value.isObject()) - return 0; - - QV4::ExecutionEngine *v4 = value.as()->engine(); - Scope scope(v4); - QV4::Scoped c(scope, value); - - return c ? c->getContext() : 0; -} - - ReturnedValue QmlContextWrapper::get(const Managed *m, String *name, bool *hasProperty) { Q_ASSERT(m->as()); diff --git a/src/qml/qml/qqmlcontextwrapper_p.h b/src/qml/qml/qqmlcontextwrapper_p.h index cbba35f5d1..192df9aed6 100644 --- a/src/qml/qml/qqmlcontextwrapper_p.h +++ b/src/qml/qml/qqmlcontextwrapper_p.h @@ -92,7 +92,6 @@ struct Q_QML_EXPORT QmlContextWrapper : Object inline QObject *getScopeObject() const { return d()->scopeObject; } inline QQmlContextData *getContext() const { return d()->context; } - static QQmlContextData *getContext(const Value &value); void setReadOnly(bool b) { d()->readOnly = b; } diff --git a/src/qml/qml/qqmlxmlhttprequest.cpp b/src/qml/qml/qqmlxmlhttprequest.cpp index 0edb672517..0870e2b2c5 100644 --- a/src/qml/qml/qqmlxmlhttprequest.cpp +++ b/src/qml/qml/qqmlxmlhttprequest.cpp @@ -95,16 +95,6 @@ static inline QQmlXMLHttpRequestData *xhrdata(ExecutionEngine *v4) return (QQmlXMLHttpRequestData *)v4->v8Engine->xmlHttpRequestData(); } -static ReturnedValue constructMeObject(const Value &thisObj, ExecutionEngine *v4) -{ - Scope scope(v4); - ScopedObject meObj(scope, v4->newObject()); - meObj->put(ScopedString(scope, v4->newString(QStringLiteral("ThisObject"))), thisObj); - ScopedValue v(scope, QmlContextWrapper::qmlScope(v4, v4->callingQmlContext(), 0)); - meObj->put(ScopedString(scope, v4->newString(QStringLiteral("ActivationObject"))), v); - return meObj.asReturnedValue(); -} - QQmlXMLHttpRequestData::QQmlXMLHttpRequestData() { } @@ -1015,7 +1005,7 @@ public: Opened = 1, HeadersReceived = 2, Loading = 3, Done = 4 }; - QQmlXMLHttpRequest(ExecutionEngine *engine, QNetworkAccessManager *manager); + QQmlXMLHttpRequest(QNetworkAccessManager *manager); virtual ~QQmlXMLHttpRequest(); bool sendFlag() const; @@ -1024,9 +1014,9 @@ public: int replyStatus() const; QString replyStatusText() const; - ReturnedValue open(const Value &me, const QString &, const QUrl &, LoadType); - ReturnedValue send(const Value &me, const QByteArray &); - ReturnedValue abort(const Value &me); + ReturnedValue open(Object *thisObject, QQmlContextData *context, const QString &, const QUrl &, LoadType); + ReturnedValue send(Object *thisObject, QQmlContextData *context, const QByteArray &); + ReturnedValue abort(Object *thisObject, QQmlContextData *context); void addHeader(const QString &, const QString &); QString header(const QString &name); @@ -1049,7 +1039,6 @@ private slots: private: void requestFromUrl(const QUrl &url); - ExecutionEngine *v4; State m_state; bool m_errorFlag; bool m_sendFlag; @@ -1073,12 +1062,11 @@ private: #endif void readEncoding(); - ReturnedValue getMe() const; - void setMe(const Value &me); - PersistentValue m_me; + PersistentValue m_thisObject; + QQmlGuardedContextData m_qmlContext; - void dispatchCallbackImpl(const Value &me); - void dispatchCallback(const Value &me); + static void dispatchCallback(Object *thisObj, QQmlContextData *context); + void dispatchCallback(); int m_status; QString m_statusText; @@ -1094,9 +1082,8 @@ private: QV4::PersistentValue m_parsedDocument; }; -QQmlXMLHttpRequest::QQmlXMLHttpRequest(ExecutionEngine *engine, QNetworkAccessManager *manager) - : v4(engine) - , m_state(Unsent), m_errorFlag(false), m_sendFlag(false) +QQmlXMLHttpRequest::QQmlXMLHttpRequest(QNetworkAccessManager *manager) + : m_state(Unsent), m_errorFlag(false), m_sendFlag(false) , m_redirectCount(0), m_gotXml(false), m_textCodec(0), m_network(0), m_nam(manager) , m_responseType() , m_parsedDocument() @@ -1133,7 +1120,7 @@ QString QQmlXMLHttpRequest::replyStatusText() const return m_statusText; } -ReturnedValue QQmlXMLHttpRequest::open(const Value &me, const QString &method, const QUrl &url, LoadType loadType) +ReturnedValue QQmlXMLHttpRequest::open(Object *thisObject, QQmlContextData *context, const QString &method, const QUrl &url, LoadType loadType) { destroyNetwork(); m_sendFlag = false; @@ -1144,7 +1131,7 @@ ReturnedValue QQmlXMLHttpRequest::open(const Value &me, const QString &method, c m_request.setAttribute(QNetworkRequest::SynchronousRequestAttribute, loadType == SynchronousLoad); m_state = Opened; m_addedHeaders.clear(); - dispatchCallback(me); + dispatchCallback(thisObject, context); return Encode::undefined(); } @@ -1279,21 +1266,22 @@ void QQmlXMLHttpRequest::requestFromUrl(const QUrl &url) } } -ReturnedValue QQmlXMLHttpRequest::send(const Value &me, const QByteArray &data) +ReturnedValue QQmlXMLHttpRequest::send(Object *thisObject, QQmlContextData *context, const QByteArray &data) { m_errorFlag = false; m_sendFlag = true; m_redirectCount = 0; m_data = data; - setMe(me); + m_thisObject = thisObject; + m_qmlContext = context; requestFromUrl(m_url); return Encode::undefined(); } -ReturnedValue QQmlXMLHttpRequest::abort(const Value &me) +ReturnedValue QQmlXMLHttpRequest::abort(Object *thisObject, QQmlContextData *context) { destroyNetwork(); m_responseEntityBody = QByteArray(); @@ -1306,7 +1294,7 @@ ReturnedValue QQmlXMLHttpRequest::abort(const Value &me) m_state = Done; m_sendFlag = false; - dispatchCallback(me); + dispatchCallback(thisObject, context); } m_state = Unsent; @@ -1314,16 +1302,6 @@ ReturnedValue QQmlXMLHttpRequest::abort(const Value &me) return Encode::undefined(); } -ReturnedValue QQmlXMLHttpRequest::getMe() const -{ - return m_me.value(); -} - -void QQmlXMLHttpRequest::setMe(const Value &me) -{ - m_me.set(v4, me); -} - void QQmlXMLHttpRequest::readyRead() { m_status = @@ -1331,14 +1309,11 @@ void QQmlXMLHttpRequest::readyRead() m_statusText = QString::fromUtf8(m_network->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toByteArray()); - Scope scope(v4); - ScopedValue me(scope, m_me.value()); - // ### We assume if this is called the headers are now available if (m_state < HeadersReceived) { m_state = HeadersReceived; fillHeadersList (); - dispatchCallback(me); + dispatchCallback(); } bool wasEmpty = m_responseEntityBody.isEmpty(); @@ -1346,7 +1321,7 @@ void QQmlXMLHttpRequest::readyRead() if (wasEmpty && !m_responseEntityBody.isEmpty()) m_state = Loading; - dispatchCallback(me); + dispatchCallback(); } static const char *errorToString(QNetworkReply::NetworkError error) @@ -1377,9 +1352,6 @@ void QQmlXMLHttpRequest::error(QNetworkReply::NetworkError error) qWarning().nospace() << " " << error << ' ' << errorToString(error) << ' ' << m_statusText; } - Scope scope(v4); - ScopedValue me(scope, m_me.value()); - if (error == QNetworkReply::ContentAccessDenied || error == QNetworkReply::ContentOperationNotPermittedError || error == QNetworkReply::ContentNotFoundError || @@ -1388,15 +1360,14 @@ void QQmlXMLHttpRequest::error(QNetworkReply::NetworkError error) error == QNetworkReply::UnknownContentError || error == QNetworkReply::ProtocolInvalidOperationError) { m_state = Loading; - dispatchCallback(me); + dispatchCallback(); } else { m_errorFlag = true; m_responseEntityBody = QByteArray(); } m_state = Done; - - dispatchCallback(me); + dispatchCallback(); } #define XMLHTTPREQUEST_MAXIMUM_REDIRECT_RECURSION 15 @@ -1428,7 +1399,7 @@ void QQmlXMLHttpRequest::finished() if (m_state < HeadersReceived) { m_state = HeadersReceived; fillHeadersList (); - dispatchCallback(*m_me.valueRef()); + dispatchCallback(); } m_responseEntityBody.append(m_network->readAll()); readEncoding(); @@ -1445,15 +1416,14 @@ void QQmlXMLHttpRequest::finished() destroyNetwork(); if (m_state < Loading) { m_state = Loading; - dispatchCallback(*m_me.valueRef()); + dispatchCallback(); } m_state = Done; - dispatchCallback(*m_me.valueRef()); + dispatchCallback(); - Scope scope(v4); - ScopedValue v(scope, Primitive::undefinedValue()); - setMe(v); + m_thisObject.clear(); + m_qmlContext.setContextData(0); } @@ -1567,57 +1537,38 @@ const QByteArray &QQmlXMLHttpRequest::rawResponseBody() const return m_responseEntityBody; } -void QQmlXMLHttpRequest::dispatchCallbackImpl(const Value &me) +void QQmlXMLHttpRequest::dispatchCallback(Object *thisObj, QQmlContextData *context) { - QV4::Scope scope(v4); - ScopedObject o(scope, me); - if (!o) { - v4->throwError(QStringLiteral("QQmlXMLHttpRequest: internal error: empty ThisObject")); - return; - } + Q_ASSERT(thisObj); - ScopedString s(scope, v4->newString(QStringLiteral("ThisObject"))); - ScopedObject thisObj(scope, o->get(s)); - if (!thisObj) { - v4->throwError(QStringLiteral("QQmlXMLHttpRequest: internal error: empty ThisObject")); + if (!context) + // if the calling context object is no longer valid, then it has been + // deleted explicitly (e.g., by a Loader deleting the itemContext when + // the source is changed). We do nothing in this case, as the evaluation + // cannot succeed. return; - } - s = v4->newString(QStringLiteral("onreadystatechange")); + QV4::Scope scope(thisObj->engine()); + ScopedString s(scope, scope.engine->newString(QStringLiteral("onreadystatechange"))); ScopedFunctionObject callback(scope, thisObj->get(s)); if (!callback) { // not an error, but no onreadystatechange function to call. return; } - s = v4->newString(QStringLiteral("ActivationObject")); - ScopedObject activationObject(scope, o->get(s)); - if (!activationObject) { - v4->throwError(QStringLiteral("QQmlXMLHttpRequest: internal error: empty ActivationObject")); - return; - } + QV4::ScopedCallData callData(scope); + callData->thisObject = Encode::undefined(); + callback->call(callData); - QQmlContextData *callingContext = QmlContextWrapper::getContext(activationObject); - if (callingContext) { - QV4::ScopedCallData callData(scope); - callData->thisObject = activationObject.asReturnedValue(); - callback->call(callData); + if (scope.engine->hasException) { + QQmlError error = scope.engine->catchExceptionAsQmlError(); + QQmlEnginePrivate::warning(QQmlEnginePrivate::get(scope.engine->qmlEngine()), error); } - - // if the callingContext object is no longer valid, then it has been - // deleted explicitly (e.g., by a Loader deleting the itemContext when - // the source is changed). We do nothing in this case, as the evaluation - // cannot succeed. - } -void QQmlXMLHttpRequest::dispatchCallback(const Value &me) +void QQmlXMLHttpRequest::dispatchCallback() { - dispatchCallbackImpl(me); - if (v4->hasException) { - QQmlError error = v4->catchExceptionAsQmlError(); - QQmlEnginePrivate::warning(QQmlEnginePrivate::get(v4->qmlEngine()), error); - } + dispatchCallback(m_thisObject.as(), m_qmlContext.contextData()); } void QQmlXMLHttpRequest::destroyNetwork() @@ -1676,7 +1627,7 @@ struct QQmlXMLHttpRequestCtor : public FunctionObject if (!ctor) return scope.engine->throwTypeError(); - QQmlXMLHttpRequest *r = new QQmlXMLHttpRequest(scope.engine, scope.engine->v8Engine->networkAccessManager()); + QQmlXMLHttpRequest *r = new QQmlXMLHttpRequest(scope.engine->v8Engine->networkAccessManager()); Scoped w(scope, scope.engine->memoryManager->alloc(scope.engine, r)); ScopedObject proto(scope, ctor->d()->proto); w->setPrototype(proto); @@ -1813,8 +1764,7 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_open(CallContext *ctx) if (!username.isNull()) url.setUserName(username); if (!password.isNull()) url.setPassword(password); - ScopedValue meObject(scope, constructMeObject(ctx->thisObject(), scope.engine)); - return r->open(meObject, method, url, async ? QQmlXMLHttpRequest::AsynchronousLoad : QQmlXMLHttpRequest::SynchronousLoad); + return r->open(w, scope.engine->callingQmlContext(), method, url, async ? QQmlXMLHttpRequest::AsynchronousLoad : QQmlXMLHttpRequest::SynchronousLoad); } ReturnedValue QQmlXMLHttpRequestCtor::method_setRequestHeader(CallContext *ctx) @@ -1880,8 +1830,7 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_send(CallContext *ctx) if (ctx->argc() > 0) data = ctx->args()[0].toQStringNoThrow().toUtf8(); - ScopedValue meObject(scope, constructMeObject(ctx->thisObject(), scope.engine)); - return r->send(meObject, data); + return r->send(w, scope.engine->callingQmlContext(), data); } ReturnedValue QQmlXMLHttpRequestCtor::method_abort(CallContext *ctx) @@ -1892,8 +1841,7 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_abort(CallContext *ctx) V4THROW_REFERENCE("Not an XMLHttpRequest object"); QQmlXMLHttpRequest *r = w->d()->request; - ScopedValue meObject(scope, constructMeObject(ctx->thisObject(), scope.engine)); - return r->abort(meObject); + return r->abort(w, scope.engine->callingQmlContext()); } ReturnedValue QQmlXMLHttpRequestCtor::method_getResponseHeader(CallContext *ctx) diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 133fadb69a..222e594d1a 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -3941,12 +3941,12 @@ void tst_qqmlecmascript::verifyContextLifetime(QQmlContextData *ctxt) { QV4::ExecutionEngine *v4 = QV8Engine::getV4(engine); QV4::Scope scope(v4); QV4::ScopedArrayObject scripts(scope, ctxt->importedScripts.value()); - QV4::ScopedValue qml(scope); + QV4::Scoped qml(scope); for (quint32 i = 0; i < scripts->getLength(); ++i) { QQmlContextData *scriptContext, *newContext; qml = scripts->getIndexed(i); - scriptContext = QV4::QmlContextWrapper::getContext(qml); + scriptContext = qml ? qml->getContext() : 0; qml = QV4::Encode::undefined(); { @@ -3957,7 +3957,7 @@ void tst_qqmlecmascript::verifyContextLifetime(QQmlContextData *ctxt) { ctxt->engine->collectGarbage(); qml = scripts->getIndexed(i); - newContext = QV4::QmlContextWrapper::getContext(qml); + newContext = qml ? qml->getContext() : 0; QCOMPARE(scriptContext, newContext); } } -- cgit v1.2.3 From 3c63ac03ed262b59962b45ac974b82edc7c83880 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Thu, 13 Aug 2015 08:14:37 +0200 Subject: Remove unused pointer to the context wrapper THe binding wrapper doesn't use that pointer anymore. Change-Id: Ie04fff448b9647927219936a62c67ac0b4853eec Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4script.cpp | 10 ---------- src/qml/jsruntime/qv4script_p.h | 2 -- 2 files changed, 12 deletions(-) diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp index d619c1a7c8..14b8b878bd 100644 --- a/src/qml/jsruntime/qv4script.cpp +++ b/src/qml/jsruntime/qv4script.cpp @@ -90,7 +90,6 @@ DEFINE_OBJECT_VTABLE(CompilationUnitHolder); Heap::QmlBindingWrapper::QmlBindingWrapper(QV4::ExecutionContext *scope, Function *f, QV4::QmlContextWrapper *qml) : Heap::FunctionObject(scope, scope->d()->engine->id_eval(), /*createProto = */ false) - , qml(qml->d()) { Q_ASSERT(scope->inUse()); @@ -107,7 +106,6 @@ Heap::QmlBindingWrapper::QmlBindingWrapper(QV4::ExecutionContext *scope, Functio Heap::QmlBindingWrapper::QmlBindingWrapper(QV4::ExecutionContext *scope, QV4::QmlContextWrapper *qml) : Heap::FunctionObject(scope, scope->d()->engine->id_eval(), /*createProto = */ false) - , qml(qml->d()) { Q_ASSERT(scope->inUse()); @@ -140,14 +138,6 @@ ReturnedValue QmlBindingWrapper::call(const Managed *that, CallData *callData) return result->asReturnedValue(); } -void QmlBindingWrapper::markObjects(Heap::Base *m, ExecutionEngine *e) -{ - QmlBindingWrapper::Data *wrapper = static_cast(m); - if (wrapper->qml) - wrapper->qml->mark(e); - FunctionObject::markObjects(m, e); -} - static ReturnedValue signalParameterGetter(QV4::CallContext *ctx, uint parameterIndex) { QV4::Scope scope(ctx); diff --git a/src/qml/jsruntime/qv4script_p.h b/src/qml/jsruntime/qv4script_p.h index 77784dfc4f..22714496f8 100644 --- a/src/qml/jsruntime/qv4script_p.h +++ b/src/qml/jsruntime/qv4script_p.h @@ -90,7 +90,6 @@ struct QmlBindingWrapper : Heap::FunctionObject { QmlBindingWrapper(QV4::ExecutionContext *scope, Function *f, QV4::QmlContextWrapper *qml); // Constructor for QML functions and signal handlers, resulting binding wrapper is not callable! QmlBindingWrapper(QV4::ExecutionContext *scope, QV4::QmlContextWrapper *qml); - Pointer qml; }; } @@ -99,7 +98,6 @@ struct Q_QML_EXPORT QmlBindingWrapper : FunctionObject { V4_OBJECT2(QmlBindingWrapper, FunctionObject) static ReturnedValue call(const Managed *that, CallData *callData); - static void markObjects(Heap::Base *m, ExecutionEngine *e); Heap::QmlContext *context() const { return static_cast(d()->scope.ptr); } -- cgit v1.2.3 From 80ff6ded28ea40dd4d017f2406743e5dc35d87ac Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 20 Aug 2015 11:50:59 +0200 Subject: Remove unused member variable QQmlDebugServerThread::m_block. Fix CLANG build error: qqmldebugserver.cpp:115:10: error: private field 'm_block' is not used [-Werror,-Wunused-private-field] bool m_block; Change-Id: I3be87c1ec0347b46e90e40c8769aeb507cf22c26 Reviewed-by: Ulf Hermann --- src/plugins/qmltooling/qmldbg_server/qqmldebugserver.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/qmltooling/qmldbg_server/qqmldebugserver.cpp b/src/plugins/qmltooling/qmldbg_server/qqmldebugserver.cpp index 1cfebea03c..93e1d0c030 100644 --- a/src/plugins/qmltooling/qmldbg_server/qqmldebugserver.cpp +++ b/src/plugins/qmltooling/qmldbg_server/qqmldebugserver.cpp @@ -112,7 +112,6 @@ private: QString m_pluginName; int m_portFrom; int m_portTo; - bool m_block; QString m_hostAddress; QString m_fileName; }; -- cgit v1.2.3 From 6328dd2d2743ed540efea89742261f24552d7611 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Thu, 2 Jul 2015 18:20:41 +0200 Subject: Add isTabFence private flag When an item has this flag set, the user can't tab-navigate either out of it, or enter it. We use this flag to implement QQuickPanel as an item for platforms that only support one single top-level window. Change-Id: I1f4313912ae1c70217af0d4d21064932b50a9438 Reviewed-by: Mitch Curtis --- src/quick/items/qquickitem.cpp | 89 +++++++++++++++++++------ src/quick/items/qquickitem_p.h | 8 +++ tests/auto/quick/qquickitem2/data/tabFence.qml | 49 ++++++++++++++ tests/auto/quick/qquickitem2/tst_qquickitem.cpp | 72 ++++++++++++++++++++ 4 files changed, 199 insertions(+), 19 deletions(-) create mode 100644 tests/auto/quick/qquickitem2/data/tabFence.qml diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp index 0c9ee4fe73..80bad4dc27 100644 --- a/src/quick/items/qquickitem.cpp +++ b/src/quick/items/qquickitem.cpp @@ -2422,6 +2422,50 @@ bool QQuickItemPrivate::focusNextPrev(QQuickItem *item, bool forward) return true; } +QQuickItem *QQuickItemPrivate::nextTabChildItem(const QQuickItem *item, int start) +{ + if (!item) { + qWarning() << "QQuickItemPrivate::nextTabChildItem called with null item."; + return Q_NULLPTR; + } + const QList &children = item->childItems(); + const int count = children.count(); + if (start < 0 || start >= count) { + qWarning() << "QQuickItemPrivate::nextTabChildItem: Start index value out of range for item" << item; + return Q_NULLPTR; + } + while (start < count) { + QQuickItem *child = children.at(start); + if (!child->d_func()->isTabFence) + return child; + ++start; + } + return Q_NULLPTR; +} + +QQuickItem *QQuickItemPrivate::prevTabChildItem(const QQuickItem *item, int start) +{ + if (!item) { + qWarning() << "QQuickItemPrivate::prevTabChildItem called with null item."; + return Q_NULLPTR; + } + const QList &children = item->childItems(); + const int count = children.count(); + if (start == -1) + start = count - 1; + if (start < 0 || start >= count) { + qWarning() << "QQuickItemPrivate::prevTabChildItem: Start index value out of range for item" << item; + return Q_NULLPTR; + } + while (start >= 0) { + QQuickItem *child = children.at(start); + if (!child->d_func()->isTabFence) + return child; + --start; + } + return Q_NULLPTR; +} + QQuickItem* QQuickItemPrivate::nextPrevItemInTabFocusChain(QQuickItem *item, bool forward) { Q_ASSERT(item); @@ -2444,7 +2488,6 @@ QQuickItem* QQuickItemPrivate::nextPrevItemInTabFocusChain(QQuickItem *item, boo from = item->parentItem(); } bool skip = false; - const QQuickItem * const originalItem = item; QQuickItem * startItem = item; QQuickItem * firstFromItem = from; QQuickItem *current = item; @@ -2453,46 +2496,53 @@ QQuickItem* QQuickItemPrivate::nextPrevItemInTabFocusChain(QQuickItem *item, boo QQuickItem *last = current; bool hasChildren = !current->childItems().isEmpty() && current->isEnabled() && current->isVisible(); + QQuickItem *firstChild = Q_NULLPTR; + QQuickItem *lastChild = Q_NULLPTR; + if (hasChildren) { + firstChild = nextTabChildItem(current, 0); + if (!firstChild) + hasChildren = false; + else + lastChild = prevTabChildItem(current, -1); + } + bool isTabFence = current->d_func()->isTabFence; // coming from parent: check children if (hasChildren && from == current->parentItem()) { if (forward) { - current = current->childItems().first(); + current = firstChild; } else { - current = current->childItems().last(); + current = lastChild; if (!current->childItems().isEmpty()) skip = true; } - } else if (hasChildren && forward && from != current->childItems().last()) { + } else if (hasChildren && forward && from != lastChild) { // not last child going forwards int nextChild = current->childItems().indexOf(from) + 1; - current = current->childItems().at(nextChild); - } else if (hasChildren && !forward && from != current->childItems().first()) { + current = nextTabChildItem(current, nextChild); + } else if (hasChildren && !forward && from != firstChild) { // not first child going backwards int prevChild = current->childItems().indexOf(from) - 1; - current = current->childItems().at(prevChild); + current = prevTabChildItem(current, prevChild); if (!current->childItems().isEmpty()) skip = true; // back to the parent - } else if (current->parentItem()) { - current = current->parentItem(); + } else if (QQuickItem *parent = !isTabFence ? current->parentItem() : Q_NULLPTR) { // we would evaluate the parent twice, thus we skip if (forward) { skip = true; - } else if (!forward && !current->childItems().isEmpty()) { - if (last != current->childItems().first()) { - skip = true; - } else if (last == current->childItems().first()) { - if (current->isFocusScope() && current->activeFocusOnTab() && current->hasActiveFocus()) + } else if (QQuickItem *firstSibling = !forward ? nextTabChildItem(parent, 0) : Q_NULLPTR) { + if (last != firstSibling + || (parent->isFocusScope() && parent->activeFocusOnTab() && parent->hasActiveFocus())) skip = true; - } } + current = parent; } else if (hasChildren) { // Wrap around after checking all items forward if (forward) { - current = current->childItems().first(); + current = firstChild; } else { - current = current->childItems().last(); + current = lastChild; if (!current->childItems().isEmpty()) skip = true; } @@ -2500,9 +2550,9 @@ QQuickItem* QQuickItemPrivate::nextPrevItemInTabFocusChain(QQuickItem *item, boo from = last; if (current == startItem && from == firstFromItem) { // wrapped around, avoid endless loops - if (originalItem == contentItem) { + if (item == contentItem) { qCDebug(DBG_FOCUS) << "QQuickItemPrivate::nextPrevItemInTabFocusChain: looped, return contentItem"; - return item->window()->contentItem(); + return item; } else { qCDebug(DBG_FOCUS) << "QQuickItemPrivate::nextPrevItemInTabFocusChain: looped, return " << startItem; return startItem; @@ -3026,6 +3076,7 @@ QQuickItemPrivate::QQuickItemPrivate() , activeFocusOnTab(false) , implicitAntialiasing(false) , antialiasingValid(false) + , isTabFence(false) , dirtyAttributes(0) , nextDirtyItem(0) , prevDirtyItem(0) diff --git a/src/quick/items/qquickitem_p.h b/src/quick/items/qquickitem_p.h index 942b51bf68..6670975f20 100644 --- a/src/quick/items/qquickitem_p.h +++ b/src/quick/items/qquickitem_p.h @@ -427,6 +427,12 @@ public: bool activeFocusOnTab:1; bool implicitAntialiasing:1; bool antialiasingValid:1; + // isTabFence: When true, the item acts as a fence within the tab focus chain. + // This means that the item and its children will be skipped from the tab focus + // chain when navigating from its parent or any of its siblings. Similarly, + // when any of the item's descendants gets focus, the item constrains the tab + // focus chain and prevents tabbing outside. + bool isTabFence:1; enum DirtyType { TransformOrigin = 0x00000001, @@ -498,6 +504,8 @@ public: void itemToParentTransform(QTransform &) const; static bool focusNextPrev(QQuickItem *item, bool forward); + static QQuickItem *nextTabChildItem(const QQuickItem *item, int start); + static QQuickItem *prevTabChildItem(const QQuickItem *item, int start); static QQuickItem *nextPrevItemInTabFocusChain(QQuickItem *item, bool forward); static bool canAcceptTabFocus(QQuickItem *item); diff --git a/tests/auto/quick/qquickitem2/data/tabFence.qml b/tests/auto/quick/qquickitem2/data/tabFence.qml new file mode 100644 index 0000000000..fcf69b418b --- /dev/null +++ b/tests/auto/quick/qquickitem2/data/tabFence.qml @@ -0,0 +1,49 @@ +import QtQuick 2.1 +import Test 1.0 + +Item { + objectName: "root" + focus: true + width: 800 + height: 600 + + TabFence { + objectName: "fence1" + + TextInput { + objectName: "input11" + activeFocusOnTab: true + } + TextInput { + objectName: "input12" + activeFocusOnTab: true + } + TextInput { + objectName: "input13" + activeFocusOnTab: true + } + } + + TextInput { + objectName: "input1" + activeFocusOnTab: true + } + + TextInput { + objectName: "input2" + activeFocusOnTab: true + } + + TabFence { + objectName: "fence2" + } + + TextInput { + objectName: "input3" + activeFocusOnTab: true + } + + TabFence { + objectName: "fence3" + } +} diff --git a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp index 396f183860..9f3de8292f 100644 --- a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp +++ b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp @@ -73,6 +73,8 @@ private slots: void nextItemInFocusChain2(); void nextItemInFocusChain3(); + void tabFence(); + void keys(); void standardKeys_data(); void standardKeys(); @@ -289,6 +291,20 @@ private: QML_DECLARE_TYPE(HollowTestItem); +class TabFenceItem : public QQuickItem +{ + Q_OBJECT + +public: + TabFenceItem(QQuickItem *parent = Q_NULLPTR) + : QQuickItem(parent) + { + QQuickItemPrivate *d = QQuickItemPrivate::get(this); + d->isTabFence = true; + } +}; + +QML_DECLARE_TYPE(TabFenceItem); tst_QQuickItem::tst_QQuickItem() { @@ -299,6 +315,7 @@ void tst_QQuickItem::initTestCase() QQmlDataTest::initTestCase(); qmlRegisterType("Test",1,0,"KeyTestItem"); qmlRegisterType("Test", 1, 0, "HollowTestItem"); + qmlRegisterType("Test", 1, 0, "TabFence"); } void tst_QQuickItem::cleanup() @@ -1120,6 +1137,61 @@ void tst_QQuickItem::nextItemInFocusChain3() QCOMPARE(QGuiApplication::focusWindow(), window); } +void verifyTabFocusChain(QQuickView *window, const char **focusChain, bool forward) +{ + int idx = 0; + for (const char **objectName = focusChain; *objectName; ++objectName, ++idx) { + const QString &descrStr = QString("idx=%1 objectName=\"%2\"").arg(idx).arg(*objectName); + const char *descr = descrStr.toLocal8Bit().data(); + QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, forward ? Qt::NoModifier : Qt::ShiftModifier); + QGuiApplication::sendEvent(window, &key); + QVERIFY2(key.isAccepted(), descr); + + QQuickItem *item = findItem(window->rootObject(), *objectName); + QVERIFY2(item, descr); + QVERIFY2(item->hasActiveFocus(), descr); + } +} + +void tst_QQuickItem::tabFence() +{ + QQuickView *window = new QQuickView(0); + window->setBaseSize(QSize(800,600)); + + window->setSource(testFileUrl("tabFence.qml")); + window->show(); + window->requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(window)); + QVERIFY(QGuiApplication::focusWindow() == window); + QVERIFY(window->rootObject()->hasActiveFocus()); + + const char *rootTabFocusChain[] = { + "input1", "input2", "input3", "input1", Q_NULLPTR + }; + verifyTabFocusChain(window, rootTabFocusChain, true /* forward */); + + const char *rootBacktabFocusChain[] = { + "input3", "input2", "input1", "input3", Q_NULLPTR + }; + verifyTabFocusChain(window, rootBacktabFocusChain, false /* forward */); + + // Give focus to input11 in fence1 + QQuickItem *item = findItem(window->rootObject(), "input11"); + item->setFocus(true); + QVERIFY(item); + QVERIFY(item->hasActiveFocus()); + + const char *fence1TabFocusChain[] = { + "input12", "input13", "input11", "input12", Q_NULLPTR + }; + verifyTabFocusChain(window, fence1TabFocusChain, true /* forward */); + + const char *fence1BacktabFocusChain[] = { + "input11", "input13", "input12", "input11", Q_NULLPTR + }; + verifyTabFocusChain(window, fence1BacktabFocusChain, false /* forward */); +} + void tst_QQuickItem::keys() { QQuickView *window = new QQuickView(0); -- cgit v1.2.3 From 45ea8df187d5dbe2776d793752d1eb3bf34b8fb3 Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Tue, 28 Jul 2015 12:41:31 +0000 Subject: Implement support for providing information to Linux's perf JIT interface. For more information on what this is, see: https://github.com/torvalds/linux/blob/master/tools/perf/Documentation/jit-interface.txt [ChangeLog][QtQml][Profiling] QtQml can now write additional information so that perf is able to give function names of JavaScript methods when profiling. To enable this, set the environment variable QV4_PROFILE_WRITE_PERF_MAP=1 when running the process in question. Change-Id: I187c9b0792f40d93c89a986c0edb3c4487095cb7 Reviewed-by: Ulf Hermann --- src/qml/jit/qv4isel_masm.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/src/qml/jit/qv4isel_masm.cpp b/src/qml/jit/qv4isel_masm.cpp index acead2088b..5dfd891b80 100644 --- a/src/qml/jit/qv4isel_masm.cpp +++ b/src/qml/jit/qv4isel_masm.cpp @@ -45,6 +45,7 @@ #include "qv4binop_p.h" #include +#include #include #include @@ -120,6 +121,19 @@ static void printDisassembledOutputWithCalls(QByteArray processedOutput, const Q qDebug("%s", processedOutput.constData()); } +#if defined(Q_OS_LINUX) +static FILE *pmap; + +static void qt_closePmap() +{ + if (pmap) { + fclose(pmap); + pmap = 0; + } +} + +#endif + JSC::MacroAssemblerCodeRef Assembler::link(int *codeSize) { Label endOfCode = label(); @@ -167,6 +181,8 @@ JSC::MacroAssemblerCodeRef Assembler::link(int *codeSize) *codeSize = linkBuffer.offsetOf(endOfCode); + QByteArray name; + JSC::MacroAssemblerCodeRef codeRef; static bool showCode = !qgetenv("QV4_SHOW_ASM").isNull(); @@ -175,7 +191,7 @@ JSC::MacroAssemblerCodeRef Assembler::link(int *codeSize) buf.open(QIODevice::WriteOnly); WTF::setDataFile(new QIODevicePrintStream(&buf)); - QByteArray name = _function->name->toUtf8(); + name = _function->name->toUtf8(); if (name.isEmpty()) { name = QByteArray::number(quintptr(_function), 16); name.prepend("IR::Function(0x"); @@ -189,6 +205,50 @@ JSC::MacroAssemblerCodeRef Assembler::link(int *codeSize) codeRef = linkBuffer.finalizeCodeWithoutDisassembly(); } +#if defined(Q_OS_LINUX) + // This implements writing of JIT'd addresses so that perf can find the + // symbol names. + // + // Perf expects the mapping to be in a certain place and have certain + // content, for more information, see: + // https://github.com/torvalds/linux/blob/master/tools/perf/Documentation/jit-interface.txt + static bool doProfile = !qEnvironmentVariableIsEmpty("QV4_PROFILE_WRITE_PERF_MAP"); + static bool profileInitialized = false; + if (doProfile && !profileInitialized) { + profileInitialized = true; + + char pname[PATH_MAX]; + snprintf(pname, PATH_MAX - 1, "/tmp/perf-%lu.map", + (unsigned long)QCoreApplication::applicationPid()); + + pmap = fopen(pname, "w"); + if (!pmap) + qWarning("QV4: Can't write %s, call stacks will not contain JavaScript function names", pname); + + // make sure we clean up nicely + std::atexit(qt_closePmap); + } + + if (pmap) { + // this may have been pre-populated, if QV4_SHOW_ASM was on + if (name.isEmpty()) { + name = _function->name->toUtf8(); + if (name.isEmpty()) { + name = QByteArray::number(quintptr(_function), 16); + name.prepend("IR::Function(0x"); + name.append(")"); + } + } + + fprintf(pmap, "%llx %x %.*s\n", + (long long unsigned int)codeRef.code().executableAddress(), + *codeSize, + name.length(), + name.constData()); + fflush(pmap); + } +#endif + return codeRef; } -- cgit v1.2.3 From c907eb1b5bfc22ffcee1cc37ecfa762d7a3edd0a Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Sun, 16 Aug 2015 15:26:40 +0200 Subject: Fix use of function expressions with signal handlers Writing onClicked: function(mouseEvent) { ... } would get silently "accepted" by the engine, but it wouldn't do anything. We basically wrapped it in a new function, so that it became onClicked: function(mouse){ function(mouseEvent() {} } which is a noop. With older versions this used to produce a syntax error. However the better fix is to simply support this kind of assignment for more expressive signal handlers, because now the names of the signal parameters can be explicitly named (with names of your choice). Change-Id: I96369f8805fab97509784222f614ee17cf681aba Reviewed-by: Lars Knoll Reviewed-by: Michael Brasser --- src/qml/compiler/qqmltypecompiler.cpp | 29 ++++++++++++++++------ .../data/assignSignalFunctionExpression.qml | 5 ++++ tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 12 +++++++++ 3 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 tests/auto/qml/qqmllanguage/data/assignSignalFunctionExpression.qml diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp index 80aa617c53..c02b91f300 100644 --- a/src/qml/compiler/qqmltypecompiler.cpp +++ b/src/qml/compiler/qqmltypecompiler.cpp @@ -1046,16 +1046,29 @@ bool SignalHandlerConverter::convertSignalHandlerExpressionsToFunctionDeclaratio paramList = paramList->finish(); QmlIR::CompiledFunctionOrExpression *foe = obj->functionsAndExpressions->slowAt(binding->value.compiledScriptIndex); - QQmlJS::AST::Statement *statement = static_cast(foe->node); - QQmlJS::AST::SourceElement *sourceElement = new (pool) QQmlJS::AST::StatementSourceElement(statement); - QQmlJS::AST::SourceElements *elements = new (pool) QQmlJS::AST::SourceElements(sourceElement); - elements = elements->finish(); - - QQmlJS::AST::FunctionBody *body = new (pool) QQmlJS::AST::FunctionBody(elements); + QQmlJS::AST::FunctionDeclaration *functionDeclaration = 0; + if (QQmlJS::AST::ExpressionStatement *es = QQmlJS::AST::cast(foe->node)) { + if (QQmlJS::AST::FunctionExpression *fe = QQmlJS::AST::cast(es->expression)) { + functionDeclaration = new (pool) QQmlJS::AST::FunctionDeclaration(fe->name, fe->formals, fe->body); + functionDeclaration->functionToken = fe->functionToken; + functionDeclaration->identifierToken = fe->identifierToken; + functionDeclaration->lparenToken = fe->lparenToken; + functionDeclaration->rparenToken = fe->rparenToken; + functionDeclaration->lbraceToken = fe->lbraceToken; + functionDeclaration->rbraceToken = fe->rbraceToken; + } + } + if (!functionDeclaration) { + QQmlJS::AST::Statement *statement = static_cast(foe->node); + QQmlJS::AST::SourceElement *sourceElement = new (pool) QQmlJS::AST::StatementSourceElement(statement); + QQmlJS::AST::SourceElements *elements = new (pool) QQmlJS::AST::SourceElements(sourceElement); + elements = elements->finish(); - QQmlJS::AST::FunctionDeclaration *functionDeclaration = new (pool) QQmlJS::AST::FunctionDeclaration(compiler->newStringRef(stringAt(binding->propertyNameIndex)), paramList, body); - functionDeclaration->functionToken = foe->node->firstSourceLocation(); + QQmlJS::AST::FunctionBody *body = new (pool) QQmlJS::AST::FunctionBody(elements); + functionDeclaration = new (pool) QQmlJS::AST::FunctionDeclaration(compiler->newStringRef(stringAt(binding->propertyNameIndex)), paramList, body); + functionDeclaration->functionToken = foe->node->firstSourceLocation(); + } foe->node = functionDeclaration; binding->propertyNameIndex = compiler->registerString(propertyName); binding->flags |= QV4::CompiledData::Binding::IsSignalHandlerExpression; diff --git a/tests/auto/qml/qqmllanguage/data/assignSignalFunctionExpression.qml b/tests/auto/qml/qqmllanguage/data/assignSignalFunctionExpression.qml new file mode 100644 index 0000000000..bf8f8556c1 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/assignSignalFunctionExpression.qml @@ -0,0 +1,5 @@ +import Test 1.0 +MyQmlObject { + onBasicSignal: function() { basicSlot() } + onBasicParameterizedSignal: function(param) { basicSlotWithArgs(param) } +} diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 152b7510d2..97501118dd 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -117,6 +117,7 @@ private slots: void idProperty(); void autoNotifyConnection(); void assignSignal(); + void assignSignalFunctionExpression(); void overrideSignal_data(); void overrideSignal(); void dynamicProperties(); @@ -1263,6 +1264,17 @@ void tst_qqmllanguage::assignSignal() emit object->basicParameterizedSignal(9); } +void tst_qqmllanguage::assignSignalFunctionExpression() +{ + QQmlComponent component(&engine, testFileUrl("assignSignalFunctionExpression.qml")); + VERIFY_ERRORS(0); + MyQmlObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + QTest::ignoreMessage(QtWarningMsg, "MyQmlObject::basicSlot"); + emit object->basicSignal(); + QTest::ignoreMessage(QtWarningMsg, "MyQmlObject::basicSlotWithArgs(9)"); + emit object->basicParameterizedSignal(9); +} void tst_qqmllanguage::overrideSignal_data() { -- cgit v1.2.3 From 4898ddfcc1822dbffc179f77a2fe768d231cbc6c Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 24 Aug 2015 10:42:18 +0200 Subject: Make iteration over persistent values safer This makes it safe to destruct persistents while we are iterating over them. Change-Id: I8797d0c553d3201859cdf03fb25df28836e55691 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4persistent.cpp | 63 ++++++++++++++++++++++++++++++++----- src/qml/jsruntime/qv4persistent_p.h | 8 +++-- 2 files changed, 61 insertions(+), 10 deletions(-) diff --git a/src/qml/jsruntime/qv4persistent.cpp b/src/qml/jsruntime/qv4persistent.cpp index 4ec7103644..4a0f84b685 100644 --- a/src/qml/jsruntime/qv4persistent.cpp +++ b/src/qml/jsruntime/qv4persistent.cpp @@ -93,6 +93,43 @@ Page *allocatePage(PersistentValueStorage *storage) } +PersistentValueStorage::Iterator::Iterator(void *p, int idx) + : p(p), index(idx) +{ + Page *page = static_cast(p); + if (page) + ++page->header.refCount; +} + +PersistentValueStorage::Iterator::Iterator(const PersistentValueStorage::Iterator &o) + : p(o.p), index(o.index) +{ + Page *page = static_cast(p); + if (page) + ++page->header.refCount; +} + +PersistentValueStorage::Iterator &PersistentValueStorage::Iterator::operator=(const PersistentValueStorage::Iterator &o) +{ + Page *page = static_cast(p); + if (page && !--page->header.refCount) + freePage(p); + p = o.p; + index = o.index; + page = static_cast(p); + if (page) + ++page->header.refCount; + + return *this; +} + +PersistentValueStorage::Iterator::~Iterator() +{ + Page *page = static_cast(p); + if (page && !--page->header.refCount) + freePage(page); +} + PersistentValueStorage::Iterator &PersistentValueStorage::Iterator::operator++() { while (p) { while (index < kEntriesPerPage - 1) { @@ -101,7 +138,12 @@ PersistentValueStorage::Iterator &PersistentValueStorage::Iterator::operator++() return *this; } index = -1; - p = static_cast(p)->header.next; + Page *next = static_cast(p)->header.next; + if (!--static_cast(p)->header.refCount) + freePage(p); + p = next; + if (next) + ++next->header.refCount; } index = 0; return *this; @@ -165,13 +207,8 @@ void PersistentValueStorage::free(Value *v) v->setTag(QV4::Value::Empty_Type); v->setInt_32(p->header.freeList); p->header.freeList = v - p->values; - if (!--p->header.refCount) { - if (p->header.prev) - *p->header.prev = p->header.next; - if (p->header.next) - p->header.next->header.prev = p->header.prev; - p->header.alloc.deallocate(); - } + if (!--p->header.refCount) + freePage(p); } static void drainMarkStack(QV4::ExecutionEngine *engine, Value *markBase) @@ -204,6 +241,16 @@ ExecutionEngine *PersistentValueStorage::getEngine(Value *v) return getPage(v)->header.engine; } +void PersistentValueStorage::freePage(void *page) +{ + Page *p = static_cast(page); + if (p->header.prev) + *p->header.prev = p->header.next; + if (p->header.next) + p->header.next->header.prev = p->header.prev; + p->header.alloc.deallocate(); +} + PersistentValue::PersistentValue(const PersistentValue &other) : val(0) diff --git a/src/qml/jsruntime/qv4persistent_p.h b/src/qml/jsruntime/qv4persistent_p.h index 858734e9ed..67a76742d1 100644 --- a/src/qml/jsruntime/qv4persistent_p.h +++ b/src/qml/jsruntime/qv4persistent_p.h @@ -51,8 +51,10 @@ struct Q_QML_EXPORT PersistentValueStorage void mark(ExecutionEngine *e); struct Iterator { - Q_DECL_CONSTEXPR Iterator(void *p, int idx) - : p(p), index(idx) {} + Iterator(void *p, int idx); + Iterator(const Iterator &o); + Iterator & operator=(const Iterator &o); + ~Iterator(); void *p; int index; Iterator &operator++(); @@ -68,6 +70,8 @@ struct Q_QML_EXPORT PersistentValueStorage ExecutionEngine *engine; void *firstPage; +private: + static void freePage(void *page); }; class Q_QML_EXPORT PersistentValue -- cgit v1.2.3 From 9dd496c069154ac655be9b85b72a6eb409bfa223 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 24 Aug 2015 12:38:18 +0200 Subject: Fix incorrect signal emission for QML declared properties After commit 6cd0001054faa9c7c20dcd5e9c7512367b2c1f5f we also need to remove the special var handling for signal indicies assigned to QML declared properties, in order to emit the right signal when the property changes. Change-Id: Ibdaba0435d8878e1e16dabe20559c484b217d82a Reviewed-by: Lars Knoll --- src/qml/compiler/qqmltypecompiler.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp index c02b91f300..80ffafda72 100644 --- a/src/qml/compiler/qqmltypecompiler.cpp +++ b/src/qml/compiler/qqmltypecompiler.cpp @@ -667,17 +667,14 @@ bool QQmlPropertyCacheCreator::createMetaObject(int objectIndex, const QmlIR::Ob } // First set up notify signals for properties - first normal, then var, then alias - enum { NSS_Normal = 0, NSS_Var = 1, NSS_Alias = 2 }; + enum { NSS_Normal = 0, NSS_Alias = 1 }; for (int ii = NSS_Normal; ii <= NSS_Alias; ++ii) { // 0 == normal, 1 == var, 2 == alias - if (ii == NSS_Var && varPropCount == 0) continue; - else if (ii == NSS_Alias && aliasCount == 0) continue; + if (ii == NSS_Alias && aliasCount == 0) continue; for (const QmlIR::Property *p = obj->firstProperty(); p; p = p->next) { - if ((ii == NSS_Normal && (p->type == QV4::CompiledData::Property::Alias || - p->type == QV4::CompiledData::Property::Var)) || - ((ii == NSS_Var) && (p->type != QV4::CompiledData::Property::Var)) || - ((ii == NSS_Alias) && (p->type != QV4::CompiledData::Property::Alias))) + if ((ii == NSS_Normal && p->type == QV4::CompiledData::Property::Alias) || + (ii == NSS_Alias && p->type != QV4::CompiledData::Property::Alias)) continue; quint32 flags = QQmlPropertyData::IsSignal | QQmlPropertyData::IsFunction | -- cgit v1.2.3