From 1bfa31849d3a23bfdc3b60aec7f645de2e1f81d5 Mon Sep 17 00:00:00 2001 From: Paul Wicking Date: Thu, 18 Jul 2019 08:41:34 +0200 Subject: Doc: Fix typos in code snippets Fixes: QTBUG-77094 Change-Id: Ia974c4d8abeab48a206fb868ee5532d4aeae7319 Reviewed-by: Mitch Curtis --- src/qml/doc/src/cppintegration/definetypes.qdoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qml/doc/src/cppintegration/definetypes.qdoc b/src/qml/doc/src/cppintegration/definetypes.qdoc index 41bc9fd140..b7199393f7 100644 --- a/src/qml/doc/src/cppintegration/definetypes.qdoc +++ b/src/qml/doc/src/cppintegration/definetypes.qdoc @@ -471,7 +471,7 @@ will be accessible to the \e attachee: class MessageBoardAttachedType : public QObject { Q_OBJECT - Q_PROPERTY(bool expired READ expired WRITE expired NOTIFY expiredChanged) + Q_PROPERTY(bool expired READ setExpired WRITE expired NOTIFY expiredChanged) public: MessageBoardAttachedType(QObject *parent); bool expired() const; @@ -493,7 +493,7 @@ class MessageBoard : public QObject { Q_OBJECT public: - static MessageBoard *qmlAttachedProperties(QObject *object) + static MessageBoardAttachedType *qmlAttachedProperties(QObject *object) { return new MessageBoardAttachedType(object); } -- cgit v1.2.3 From 35acf29a38d4b631dd27ce767466533223e8b2c4 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Fri, 5 Jul 2019 13:08:21 +0200 Subject: Support text color for color fonts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In order to support pen color for color fonts, we have to bake the color into the cache (since the cache contains actual color data and not alpha values). This is equivalent of 78caba7ae637bf4b33631c3425eb92ec3946c99e in Qt Base. [ChangeLog][Text] Added support for text color when using color fonts. Task-number: QTBUG-74761 Change-Id: I5910636c240bd4c0ec3f0b13db4e2f78d4b062ff Reviewed-by: Tor Arne Vestbø --- src/quick/scenegraph/qsgdefaultglyphnode.cpp | 2 +- src/quick/scenegraph/qsgdefaultglyphnode_p.cpp | 30 +++++++++++++++++++++----- src/quick/scenegraph/qsgdefaultglyphnode_p_p.h | 7 +++--- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/quick/scenegraph/qsgdefaultglyphnode.cpp b/src/quick/scenegraph/qsgdefaultglyphnode.cpp index 0d42102f36..cae0eda3f4 100644 --- a/src/quick/scenegraph/qsgdefaultglyphnode.cpp +++ b/src/quick/scenegraph/qsgdefaultglyphnode.cpp @@ -75,7 +75,7 @@ void QSGDefaultGlyphNode::update() QMargins margins(0, 0, 0, 0); if (m_style == QQuickText::Normal) { - m_material = new QSGTextMaskMaterial(font); + m_material = new QSGTextMaskMaterial(QVector4D(m_color.redF(), m_color.greenF(), m_color.blueF(), m_color.alphaF()), font); } else if (m_style == QQuickText::Outline) { QSGOutlinedTextMaterial *material = new QSGOutlinedTextMaterial(font); material->setStyleColor(m_styleColor); diff --git a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp index ce706d76f7..b9a22dd44b 100644 --- a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp +++ b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp @@ -399,10 +399,11 @@ public: } }; -QSGTextMaskMaterial::QSGTextMaskMaterial(const QRawFont &font, QFontEngine::GlyphFormat glyphFormat) +QSGTextMaskMaterial::QSGTextMaskMaterial(const QVector4D &color, const QRawFont &font, QFontEngine::GlyphFormat glyphFormat) : m_texture(nullptr) , m_glyphCache(nullptr) , m_font(font) + , m_color(color) { init(glyphFormat); } @@ -412,12 +413,30 @@ QSGTextMaskMaterial::~QSGTextMaskMaterial() delete m_texture; } +void QSGTextMaskMaterial::setColor(const QVector4D &color) +{ + if (m_color == color) + return; + + m_color = color; + + // If it is an RGB cache, then the pen color is actually part of the cache key + // so it has to be updated + if (m_glyphCache != nullptr && m_glyphCache->glyphFormat() == QFontEngine::Format_ARGB) + updateCache(QFontEngine::Format_ARGB); +} + void QSGTextMaskMaterial::init(QFontEngine::GlyphFormat glyphFormat) { Q_ASSERT(m_font.isValid()); setFlag(Blending, true); + updateCache(glyphFormat); +} + +void QSGTextMaskMaterial::updateCache(QFontEngine::GlyphFormat glyphFormat) +{ QOpenGLContext *ctx = const_cast(QOpenGLContext::currentContext()); Q_ASSERT(ctx != nullptr); @@ -437,20 +456,21 @@ void QSGTextMaskMaterial::init(QFontEngine::GlyphFormat glyphFormat) qreal devicePixelRatio = qsg_device_pixel_ratio(ctx); - QTransform glyphCacheTransform = QTransform::fromScale(devicePixelRatio, devicePixelRatio); if (!fontEngine->supportsTransformation(glyphCacheTransform)) glyphCacheTransform = QTransform(); - m_glyphCache = fontEngine->glyphCache(ctx, glyphFormat, glyphCacheTransform); + QColor color = glyphFormat == QFontEngine::Format_ARGB ? QColor::fromRgbF(m_color.x(), m_color.y(), m_color.z(), m_color.w()) : QColor(); + m_glyphCache = fontEngine->glyphCache(ctx, glyphFormat, glyphCacheTransform, color); if (!m_glyphCache || int(m_glyphCache->glyphFormat()) != glyphFormat) { - m_glyphCache = new QOpenGLTextureGlyphCache(glyphFormat, glyphCacheTransform); + m_glyphCache = new QOpenGLTextureGlyphCache(glyphFormat, glyphCacheTransform, color); fontEngine->setGlyphCache(ctx, m_glyphCache.data()); auto sg = QSGDefaultRenderContext::from(ctx); Q_ASSERT(sg); sg->registerFontengineForCleanup(fontEngine); } } + } void QSGTextMaskMaterial::populate(const QPointF &p, @@ -629,7 +649,7 @@ int QSGTextMaskMaterial::cacheTextureHeight() const QSGStyledTextMaterial::QSGStyledTextMaterial(const QRawFont &font) - : QSGTextMaskMaterial(font, QFontEngine::Format_A8) + : QSGTextMaskMaterial(QVector4D(), font, QFontEngine::Format_A8) { } diff --git a/src/quick/scenegraph/qsgdefaultglyphnode_p_p.h b/src/quick/scenegraph/qsgdefaultglyphnode_p_p.h index b0a2788dd8..56084dea96 100644 --- a/src/quick/scenegraph/qsgdefaultglyphnode_p_p.h +++ b/src/quick/scenegraph/qsgdefaultglyphnode_p_p.h @@ -68,15 +68,15 @@ class Geometry; class QSGTextMaskMaterial: public QSGMaterial { public: - QSGTextMaskMaterial(const QRawFont &font, QFontEngine::GlyphFormat glyphFormat = QFontEngine::Format_None); + QSGTextMaskMaterial(const QVector4D &color, const QRawFont &font, QFontEngine::GlyphFormat glyphFormat = QFontEngine::Format_None); virtual ~QSGTextMaskMaterial(); QSGMaterialType *type() const override; QSGMaterialShader *createShader() const override; int compare(const QSGMaterial *other) const override; - void setColor(const QColor &c) { m_color = QVector4D(c.redF(), c.greenF(), c.blueF(), c.alphaF()); } - void setColor(const QVector4D &color) { m_color = color; } + void setColor(const QColor &c) { setColor(QVector4D(c.redF(), c.greenF(), c.blueF(), c.alphaF())); } + void setColor(const QVector4D &color); const QVector4D &color() const { return m_color; } QSGTexture *texture() const { return m_texture; } @@ -94,6 +94,7 @@ public: private: void init(QFontEngine::GlyphFormat glyphFormat); + void updateCache(QFontEngine::GlyphFormat glyphFormat); QSGPlainTexture *m_texture; QExplicitlySharedDataPointer m_glyphCache; -- cgit v1.2.3 From a95f3795ae94616fb7b3d72ac71b0b38c6bba341 Mon Sep 17 00:00:00 2001 From: Paul Wicking Date: Fri, 19 Jul 2019 06:53:12 +0200 Subject: Doc: fix code snippet Task-number: QTBUG-77094 Change-Id: I9058bf7b65e8d390327af0624df611de4965f1e4 Reviewed-by: Mitch Curtis --- src/qml/doc/src/cppintegration/definetypes.qdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qml/doc/src/cppintegration/definetypes.qdoc b/src/qml/doc/src/cppintegration/definetypes.qdoc index b7199393f7..2e8102bd65 100644 --- a/src/qml/doc/src/cppintegration/definetypes.qdoc +++ b/src/qml/doc/src/cppintegration/definetypes.qdoc @@ -471,7 +471,7 @@ will be accessible to the \e attachee: class MessageBoardAttachedType : public QObject { Q_OBJECT - Q_PROPERTY(bool expired READ setExpired WRITE expired NOTIFY expiredChanged) + Q_PROPERTY(bool expired READ expired WRITE setExpired NOTIFY expiredChanged) public: MessageBoardAttachedType(QObject *parent); bool expired() const; -- cgit v1.2.3 From 1dad2029a5bdbc40b244f72f995d70d27ed98e62 Mon Sep 17 00:00:00 2001 From: Dimitrios Apostolou Date: Fri, 19 Jul 2019 14:02:31 +0200 Subject: Always waitForWindow after centerOnScreen() Because centerOnScreen asks the window manager to move the window, but does not wait for it. This is applied in the same spirit as this change in qtquickcontrols2: https://codereview.qt-project.org/c/qt/qtquickcontrols2/+/268200 These tests appear slightly flaky on the Grafana dashboard, this commit might help. Change-Id: I30d3f4717aca435c94fb1a447c4b5c51021da3be Reviewed-by: Shawn Rutledge --- tests/auto/quick/qquickflickable/tst_qquickflickable.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp index 65a08ce87f..2314b82e8c 100644 --- a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp +++ b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp @@ -1652,6 +1652,7 @@ void tst_qquickflickable::flickTwiceUsingTouches() QQuickViewTestUtil::moveMouseAway(window.data()); window->show(); QVERIFY(window->rootObject() != nullptr); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QQuickFlickable *flickable = qobject_cast(window->rootObject()); QVERIFY(flickable != nullptr); @@ -1994,6 +1995,7 @@ void tst_qquickflickable::nestedMouseAreaUsingTouch() QQuickViewTestUtil::moveMouseAway(window.data()); window->show(); QVERIFY(window->rootObject() != nullptr); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QQuickFlickable *flickable = qobject_cast(window->rootObject()); QVERIFY(flickable != nullptr); @@ -2489,6 +2491,7 @@ void tst_qquickflickable::synchronousDrag() QQuickViewTestUtil::moveMouseAway(window); window->show(); QVERIFY(window->rootObject() != nullptr); + QVERIFY(QTest::qWaitForWindowActive(window)); QQuickFlickable *flickable = qobject_cast(window->rootObject()); QVERIFY(flickable != nullptr); -- cgit v1.2.3 From d94dd247ecd6753150dc2a7ef6be4ccb482e9423 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Thu, 18 Jul 2019 16:06:26 +0200 Subject: Do not search for Singletons from more recent versions This would break importing older versions of a module, as we would try to locate a singleton which does not exist in this version. Fixes: QTBUG-77102 Change-Id: I78be1ec111d2be26a14b2a94bbf743cf6238cddd Reviewed-by: Qt CI Bot Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlimport.cpp | 13 ++++++- .../imports/MyPlugin/MyComponent_0_9.qml | 14 +++++++ .../imports/MyPlugin/MyComponent_1_0.qml | 15 ++++++++ .../imports/MyPlugin/MySettings_1_0.qml | 7 ++++ .../data/QTBUG-77102/imports/MyPlugin/qmldir | 6 +++ .../qqmlimport/data/QTBUG-77102/main.0.9.fail.qml | 11 ++++++ .../qml/qqmlimport/data/QTBUG-77102/main.0.9.qml | 11 ++++++ .../qml/qqmlimport/data/QTBUG-77102/main.1.0.qml | 11 ++++++ .../qqmlimport/data/QTBUG-77102/main.nonumber.qml | 11 ++++++ tests/auto/qml/qqmlimport/tst_qqmlimport.cpp | 45 ++++++++++++++++++++++ 10 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 tests/auto/qml/qqmlimport/data/QTBUG-77102/imports/MyPlugin/MyComponent_0_9.qml create mode 100644 tests/auto/qml/qqmlimport/data/QTBUG-77102/imports/MyPlugin/MyComponent_1_0.qml create mode 100644 tests/auto/qml/qqmlimport/data/QTBUG-77102/imports/MyPlugin/MySettings_1_0.qml create mode 100644 tests/auto/qml/qqmlimport/data/QTBUG-77102/imports/MyPlugin/qmldir create mode 100644 tests/auto/qml/qqmlimport/data/QTBUG-77102/main.0.9.fail.qml create mode 100644 tests/auto/qml/qqmlimport/data/QTBUG-77102/main.0.9.qml create mode 100644 tests/auto/qml/qqmlimport/data/QTBUG-77102/main.1.0.qml create mode 100644 tests/auto/qml/qqmlimport/data/QTBUG-77102/main.nonumber.qml diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp index 5a1364473e..ba8dce4b6e 100644 --- a/src/qml/qml/qqmlimport.cpp +++ b/src/qml/qml/qqmlimport.cpp @@ -465,9 +465,18 @@ void findCompositeSingletons(const QQmlImportNamespace &set, QListqmlDirComponents; + const int importMajorVersion = import->majversion; + const int importMinorVersion = import->minversion; + auto shouldSkipSingleton = [importMajorVersion, importMinorVersion](int singletonMajorVersion, int singletonMinorVersion) -> bool { + return importMajorVersion != -1 && + (singletonMajorVersion > importMajorVersion || (singletonMajorVersion == importMajorVersion && singletonMinorVersion > importMinorVersion)); + }; + ConstIterator cend = components.constEnd(); for (ConstIterator cit = components.constBegin(); cit != cend; ++cit) { if (cit->singleton && excludeBaseUrl(import->url, cit->fileName, baseUrl.toString())) { + if (shouldSkipSingleton(cit->majorVersion, cit->minorVersion)) + continue; QQmlImports::CompositeSingletonReference ref; ref.typeName = cit->typeName; ref.prefix = set.prefix; @@ -478,7 +487,9 @@ void findCompositeSingletons(const QQmlImportNamespace &set, QListuri, import->majversion)) { - module->walkCompositeSingletons([&resultList, &set](const QQmlType &singleton) { + module->walkCompositeSingletons([&resultList, &set, &shouldSkipSingleton](const QQmlType &singleton) { + if (shouldSkipSingleton(singleton.majorVersion(), singleton.minorVersion())) + return; QQmlImports::CompositeSingletonReference ref; ref.typeName = singleton.elementName(); ref.prefix = set.prefix; diff --git a/tests/auto/qml/qqmlimport/data/QTBUG-77102/imports/MyPlugin/MyComponent_0_9.qml b/tests/auto/qml/qqmlimport/data/QTBUG-77102/imports/MyPlugin/MyComponent_0_9.qml new file mode 100644 index 0000000000..a63e2d121c --- /dev/null +++ b/tests/auto/qml/qqmlimport/data/QTBUG-77102/imports/MyPlugin/MyComponent_0_9.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 + +Rectangle { + width: 50 + height: 50 + + color: "yellow" + + Text { + anchors.centerIn: parent + text: "0.9" + + } +} diff --git a/tests/auto/qml/qqmlimport/data/QTBUG-77102/imports/MyPlugin/MyComponent_1_0.qml b/tests/auto/qml/qqmlimport/data/QTBUG-77102/imports/MyPlugin/MyComponent_1_0.qml new file mode 100644 index 0000000000..d9cff582bb --- /dev/null +++ b/tests/auto/qml/qqmlimport/data/QTBUG-77102/imports/MyPlugin/MyComponent_1_0.qml @@ -0,0 +1,15 @@ + +import QtQuick 2.0 + +Rectangle { + width: 50 + height: 50 + + color: "orange" + + Text { + anchors.centerIn: parent + text: "1.0" + + } +} diff --git a/tests/auto/qml/qqmlimport/data/QTBUG-77102/imports/MyPlugin/MySettings_1_0.qml b/tests/auto/qml/qqmlimport/data/QTBUG-77102/imports/MyPlugin/MySettings_1_0.qml new file mode 100644 index 0000000000..63ad6ba1a5 --- /dev/null +++ b/tests/auto/qml/qqmlimport/data/QTBUG-77102/imports/MyPlugin/MySettings_1_0.qml @@ -0,0 +1,7 @@ +pragma Singleton + +import QtQuick 2.0 + +Item { + property int baseWidth: 50 +} diff --git a/tests/auto/qml/qqmlimport/data/QTBUG-77102/imports/MyPlugin/qmldir b/tests/auto/qml/qqmlimport/data/QTBUG-77102/imports/MyPlugin/qmldir new file mode 100644 index 0000000000..57b8c55f81 --- /dev/null +++ b/tests/auto/qml/qqmlimport/data/QTBUG-77102/imports/MyPlugin/qmldir @@ -0,0 +1,6 @@ +module MyPlugin + +MyComponent 0.9 MyComponent_0_9.qml + +MyComponent 1.0 MyComponent_1_0.qml +singleton MySettings 1.0 MySettings_1_0.qml diff --git a/tests/auto/qml/qqmlimport/data/QTBUG-77102/main.0.9.fail.qml b/tests/auto/qml/qqmlimport/data/QTBUG-77102/main.0.9.fail.qml new file mode 100644 index 0000000000..0fbcec607a --- /dev/null +++ b/tests/auto/qml/qqmlimport/data/QTBUG-77102/main.0.9.fail.qml @@ -0,0 +1,11 @@ +import QtQuick 2.12 +import MyPlugin 0.9 + +Item { + width: MySettings.baseWidth + height: 100 + + MyComponent { + anchors.centerIn: parent + } +} diff --git a/tests/auto/qml/qqmlimport/data/QTBUG-77102/main.0.9.qml b/tests/auto/qml/qqmlimport/data/QTBUG-77102/main.0.9.qml new file mode 100644 index 0000000000..53fc25699c --- /dev/null +++ b/tests/auto/qml/qqmlimport/data/QTBUG-77102/main.0.9.qml @@ -0,0 +1,11 @@ +import QtQuick 2.12 +import MyPlugin 0.9 + +Item { + width: 100 + height: 100 + + MyComponent { + anchors.centerIn: parent + } +} diff --git a/tests/auto/qml/qqmlimport/data/QTBUG-77102/main.1.0.qml b/tests/auto/qml/qqmlimport/data/QTBUG-77102/main.1.0.qml new file mode 100644 index 0000000000..1f6244068b --- /dev/null +++ b/tests/auto/qml/qqmlimport/data/QTBUG-77102/main.1.0.qml @@ -0,0 +1,11 @@ +import QtQuick 2.12 +import MyPlugin 1.0 + +Item { + width: MySettings.baseWidth + height: 100 + + MyComponent { + anchors.centerIn: parent + } +} diff --git a/tests/auto/qml/qqmlimport/data/QTBUG-77102/main.nonumber.qml b/tests/auto/qml/qqmlimport/data/QTBUG-77102/main.nonumber.qml new file mode 100644 index 0000000000..dea00c0163 --- /dev/null +++ b/tests/auto/qml/qqmlimport/data/QTBUG-77102/main.nonumber.qml @@ -0,0 +1,11 @@ +import QtQuick 2.12 +import "imports/MyPlugin" + +Item { + width: MySettings.baseWidth + height: 100 + + MyComponent { + anchors.centerIn: parent + } +} diff --git a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp index a3cb68fdcb..a9657eba1d 100644 --- a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp +++ b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp @@ -45,6 +45,7 @@ private slots: void completeQmldirPaths_data(); void completeQmldirPaths(); void interceptQmldir(); + void singletonVersionResolution(); void cleanup(); }; @@ -212,6 +213,50 @@ void tst_QQmlImport::interceptQmldir() QVERIFY(!obj.isNull()); } +// QTBUG-77102 +void tst_QQmlImport::singletonVersionResolution() +{ + QQmlEngine engine; + engine.addImportPath(testFile("QTBUG-77102/imports")); + { + // Singleton with higher version is simply ignored when importing lower version of plugin + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("QTBUG-77102/main.0.9.qml")); + QVERIFY(component.isReady()); + QScopedPointer obj(component.create()); + QVERIFY(!obj.isNull()); + } + { + // but the singleton is not accessible + QQmlComponent component(&engine); + QTest::ignoreMessage(QtMsgType::QtWarningMsg, QRegularExpression {".*ReferenceError: MySettings is not defined$"} ); + component.loadUrl(testFileUrl("QTBUG-77102/main.0.9.fail.qml")); + QVERIFY(component.isReady()); + QScopedPointer obj(component.create()); + QVERIFY(!obj.isNull()); + } + { + // unless a version which is high enough is imported + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("QTBUG-77102/main.1.0.qml")); + QVERIFY(component.isReady()); + QScopedPointer obj(component.create()); + QVERIFY(!obj.isNull()); + auto item = qobject_cast(obj.get()); + QCOMPARE(item->width(), 50); + } + { + // or when there is no number because we are importing from a path + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("QTBUG-77102/main.nonumber.qml")); + QVERIFY(component.isReady()); + QScopedPointer obj(component.create()); + QVERIFY(!obj.isNull()); + auto item = qobject_cast(obj.get()); + QCOMPARE(item->width(), 50); + } +} + QTEST_MAIN(tst_QQmlImport) -- cgit v1.2.3