diff options
author | Laszlo Agocs <[email protected]> | 2016-05-24 11:08:09 +0200 |
---|---|---|
committer | Laszlo Agocs <[email protected]> | 2016-05-24 11:33:42 +0200 |
commit | 9ff09fb283cd130fb717769b44f54bfbb28efd8a (patch) | |
tree | 711f70b4b494bd996d54bdab5c44f3c89b37a6d1 /src/quick | |
parent | 592b5b49b6c0043fae5db7721689813ebd226032 (diff) | |
parent | ec2b2a5f5d804095b6b2b8575b1cd1b75a8335ff (diff) |
Merge remote-tracking branch 'origin/dev' into wip/scenegraphng
Conflicts:
src/quick/items/qquickopenglshadereffectnode.cpp
src/quick/items/qquickshadereffect.cpp
src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h
src/quick/scenegraph/qsgdefaultglyphnode_p.h
Change-Id: I3d6874b4e4231a89d2836c04fe8e7f2ef2d698c4
Diffstat (limited to 'src/quick')
50 files changed, 972 insertions, 557 deletions
diff --git a/src/quick/designer/qqmldesignermetaobject.cpp b/src/quick/designer/qqmldesignermetaobject.cpp index 46808f978b..63b4102b10 100644 --- a/src/quick/designer/qqmldesignermetaobject.cpp +++ b/src/quick/designer/qqmldesignermetaobject.cpp @@ -79,23 +79,9 @@ struct MetaPropertyData { QVector<QPair<QVariant, bool> > m_data; }; -static bool constructedMetaData(const QQmlVMEMetaData* data) -{ - return data->propertyCount == 0 - && data->aliasCount == 0 - && data->signalCount == 0 - && data->methodCount == 0; -} - static QQmlVMEMetaData* fakeMetaData() { - QQmlVMEMetaData* data = new QQmlVMEMetaData; - data->propertyCount = 0; - data->aliasCount = 0; - data->signalCount = 0; - data->methodCount = 0; - - return data; + return new QQmlVMEMetaData; } static const QQmlVMEMetaData* vMEMetaDataForObject(QObject *object) @@ -125,7 +111,15 @@ QQmlDesignerMetaObject* QQmlDesignerMetaObject::getNodeInstanceMetaObject(QObjec return static_cast<QQmlDesignerMetaObject *>(parent); // we just create one and the ownership goes automatically to the object in nodeinstance see init method - return new QQmlDesignerMetaObject(object, engine); + + QQmlData *ddata = QQmlData::get(object, false); + + const bool hadVMEMetaObject = ddata ? ddata->hasVMEMetaObject : false; + QQmlDesignerMetaObject *mo = new QQmlDesignerMetaObject(object, engine); + //If our parent is not a VMEMetaObject we just set the flag to false again + if (ddata) + ddata->hasVMEMetaObject = hadVMEMetaObject; + return mo; } void QQmlDesignerMetaObject::init(QObject *object, QQmlEngine *engine) @@ -140,20 +134,20 @@ void QQmlDesignerMetaObject::init(QObject *object, QQmlEngine *engine) QObjectPrivate *op = QObjectPrivate::get(object); op->metaObject = this; - //create cache - cache = m_cache = QQmlEnginePrivate::get(engine)->cache(this); - cache->addref(); + m_cache = QQmlEnginePrivate::get(engine)->cache(this); - //If our parent is not a VMEMetaObject we just se the flag to false again - if (constructedMetaData(metaData)) - QQmlData::get(object)->hasVMEMetaObject = false; + if (m_cache != cache) { + m_cache->addref(); + cache->release(); + cache = m_cache; + } nodeInstanceMetaObjectList.insert(this, true); hasAssignedMetaObjectData = true; } QQmlDesignerMetaObject::QQmlDesignerMetaObject(QObject *object, QQmlEngine *engine) - : QQmlVMEMetaObject(object, cacheForObject(object, engine), vMEMetaDataForObject(object)), + : QQmlVMEMetaObject(object, cacheForObject(object, engine), vMEMetaDataForObject(object), /*qml compilation unit*/nullptr, /*qmlObjectId*/-1), m_context(engine->contextForObject(object)), m_data(new MetaPropertyData), m_cache(0) @@ -161,22 +155,20 @@ QQmlDesignerMetaObject::QQmlDesignerMetaObject(QObject *object, QQmlEngine *engi init(object, engine); QQmlData *ddata = QQmlData::get(object, false); - //Assign cache to object if (ddata && ddata->propertyCache) { cache->setParent(ddata->propertyCache); cache->invalidate(engine, this); + ddata->propertyCache->release(); ddata->propertyCache = m_cache; + m_cache->addref(); } } QQmlDesignerMetaObject::~QQmlDesignerMetaObject() { - if (cache->count() > 1) // qml is crashing because the property cache is not removed from the engine - cache->release(); - else - m_type->release(); + m_type->release(); nodeInstanceMetaObjectList.remove(this); } diff --git a/src/quick/designer/qqmldesignermetaobject_p.h b/src/quick/designer/qqmldesignermetaobject_p.h index c45f83dc1e..a5402ccbc4 100644 --- a/src/quick/designer/qqmldesignermetaobject_p.h +++ b/src/quick/designer/qqmldesignermetaobject_p.h @@ -70,7 +70,6 @@ public: static void registerNotifyPropertyChangeCallBack(void (*callback)(QObject*, const QQuickDesignerSupport::PropertyName &propertyName)); protected: - QQmlDesignerMetaObject(QObject *object, QQmlEngine *engine); static QQmlDesignerMetaObject* getNodeInstanceMetaObject(QObject *object, QQmlEngine *engine); void createNewDynamicProperty(const QString &name); @@ -95,6 +94,7 @@ protected: void copyTypeMetaObject(); private: + QQmlDesignerMetaObject(QObject *object, QQmlEngine *engine); void init(QObject *, QQmlEngine *engine); QPointer<QQmlContext> m_context; diff --git a/src/quick/designer/qquickdesignersupport.cpp b/src/quick/designer/qquickdesignersupport.cpp index ec00eed18a..f063cd3a81 100644 --- a/src/quick/designer/qquickdesignersupport.cpp +++ b/src/quick/designer/qquickdesignersupport.cpp @@ -189,17 +189,17 @@ QTransform QQuickDesignerSupport::parentTransform(QQuickItem *referencedItem) return parentTransform; } -QString propertyNameForAnchorLine(const QQuickAnchorLine::AnchorLine &anchorLine) +QString propertyNameForAnchorLine(const QQuickAnchors::Anchor &anchorLine) { switch (anchorLine) { - case QQuickAnchorLine::Left: return QLatin1String("left"); - case QQuickAnchorLine::Right: return QLatin1String("right"); - case QQuickAnchorLine::Top: return QLatin1String("top"); - case QQuickAnchorLine::Bottom: return QLatin1String("bottom"); - case QQuickAnchorLine::HCenter: return QLatin1String("horizontalCenter"); - case QQuickAnchorLine::VCenter: return QLatin1String("verticalCenter"); - case QQuickAnchorLine::Baseline: return QLatin1String("baseline"); - case QQuickAnchorLine::Invalid: + case QQuickAnchors::LeftAnchor: return QLatin1String("left"); + case QQuickAnchors::RightAnchor: return QLatin1String("right"); + case QQuickAnchors::TopAnchor: return QLatin1String("top"); + case QQuickAnchors::BottomAnchor: return QLatin1String("bottom"); + case QQuickAnchors::HCenterAnchor: return QLatin1String("horizontalCenter"); + case QQuickAnchors::VCenterAnchor: return QLatin1String("verticalCenter"); + case QQuickAnchors::BaselineAnchor: return QLatin1String("baseline"); + case QQuickAnchors::InvalidAnchor: // fallthrough: default: return QString(); } } @@ -345,7 +345,7 @@ QPair<QString, QObject*> QQuickDesignerSupport::anchorLineTarget(QQuickItem *ite return QPair<QString, QObject*>(); QQuickAnchorLine anchorLine = metaProperty.read().value<QQuickAnchorLine>(); - if (anchorLine.anchorLine != QQuickAnchorLine::Invalid) { + if (anchorLine.anchorLine != QQuickAnchors::InvalidAnchor) { targetObject = anchorLine.item; targetName = propertyNameForAnchorLine(anchorLine.anchorLine); } diff --git a/src/quick/doc/snippets/qml/externaldrag.qml b/src/quick/doc/snippets/qml/externaldrag.qml new file mode 100644 index 0000000000..096a7702b4 --- /dev/null +++ b/src/quick/doc/snippets/qml/externaldrag.qml @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +//![0] +import QtQuick 2.8 + +Item { + width: 200; height: 200 + + Rectangle { + anchors.centerIn: parent + width: text.implicitWidth + 20; height: text.implicitHeight + 10 + color: "green" + radius: 5 + + Drag.active: dragArea.drag.active + Drag.dragType: Drag.Automatic + Drag.supportedActions: Qt.CopyAction + Drag.mimeData: { + "text/plain": "Copied text" + } + + Text { + id: text + anchors.centerIn: parent + text: "Drag me" + } + + MouseArea { + id: dragArea + anchors.fill: parent + + drag.target: parent + onPressed: parent.grabToImage(function(result) { + parent.Drag.imageSource = result.url + }) + } + } +} +//![0] diff --git a/src/quick/items/context2d/qquickcontext2d.cpp b/src/quick/items/context2d/qquickcontext2d.cpp index b43adac0c5..7e7b1fa062 100644 --- a/src/quick/items/context2d/qquickcontext2d.cpp +++ b/src/quick/items/context2d/qquickcontext2d.cpp @@ -66,6 +66,7 @@ #include <private/qv4scopedvalue_p.h> #include <QtCore/qmath.h> +#include <QtCore/qvector.h> #include <QtCore/private/qnumeric_p.h> #include <QtCore/QRunnable> #include <QtGui/qguiapplication.h> @@ -205,7 +206,7 @@ QColor qt_color_from_string(const QV4::Value &name) return QColor(); } -static int qParseFontSizeFromToken(const QString &fontSizeToken, bool &ok) +static int qParseFontSizeFromToken(const QStringRef &fontSizeToken, bool &ok) { ok = false; float size = fontSizeToken.trimmed().toFloat(&ok); @@ -221,11 +222,11 @@ static int qParseFontSizeFromToken(const QString &fontSizeToken, bool &ok) \c true if successful. If the font size is invalid, \c false is returned and a warning is printed. */ -static bool qSetFontSizeFromToken(QFont &font, const QString &fontSizeToken) +static bool qSetFontSizeFromToken(QFont &font, const QStringRef &fontSizeToken) { - const QString trimmedToken = fontSizeToken.trimmed(); - const QString unitStr = trimmedToken.right(2); - const QString value = trimmedToken.left(trimmedToken.size() - 2); + const QStringRef trimmedToken = fontSizeToken.trimmed(); + const QStringRef unitStr = trimmedToken.right(2); + const QStringRef value = trimmedToken.left(trimmedToken.size() - 2); bool ok = false; int size = 0; if (unitStr == QLatin1String("px")) { @@ -251,7 +252,7 @@ static bool qSetFontSizeFromToken(QFont &font, const QString &fontSizeToken) each family is separated by spaces. Families with spaces in their name must be quoted. */ -static QStringList qExtractFontFamiliesFromString(const QString &fontFamiliesString) +static QStringList qExtractFontFamiliesFromString(const QStringRef &fontFamiliesString) { QStringList extractedFamilies; int quoteIndex = -1; @@ -264,7 +265,7 @@ static QStringList qExtractFontFamiliesFromString(const QString &fontFamiliesStr } else { if (ch == fontFamiliesString.at(quoteIndex)) { // Found the matching quote. +1/-1 because we don't want the quote as part of the name. - const QString family = fontFamiliesString.mid(quoteIndex + 1, index - quoteIndex - 1); + const QString family = fontFamiliesString.mid(quoteIndex + 1, index - quoteIndex - 1).toString(); extractedFamilies.push_back(family); currentFamily.clear(); quoteIndex = -1; @@ -395,16 +396,17 @@ static QFont qt_font_from_string(const QString& fontString, const QFont ¤t fontSizeEnd += 3; QFont newFont; - if (!qSetFontSizeFromToken(newFont, fontString.mid(fontSizeStart, fontSizeEnd - fontSizeStart))) + if (!qSetFontSizeFromToken(newFont, fontString.midRef(fontSizeStart, fontSizeEnd - fontSizeStart))) return currentFont; // We don't want to parse the size twice, so remove it now. QString remainingFontString = fontString; remainingFontString.remove(fontSizeStart, fontSizeEnd - fontSizeStart); + QStringRef remainingFontStringRef(&remainingFontString); // Next, we have to take any font families out, as QString::split() will ruin quoted family names. - const QString fontFamiliesString = remainingFontString.mid(fontSizeStart); - remainingFontString.chop(remainingFontString.length() - fontSizeStart); + const QStringRef fontFamiliesString = remainingFontStringRef.mid(fontSizeStart); + remainingFontStringRef.truncate(fontSizeStart); QStringList fontFamilies = qExtractFontFamiliesFromString(fontFamiliesString); if (fontFamilies.isEmpty()) { return currentFont; @@ -413,16 +415,16 @@ static QFont qt_font_from_string(const QString& fontString, const QFont ¤t return currentFont; // Now that we've removed the messy parts, we can split the font string on spaces. - const QString trimmedTokensStr = remainingFontString.trimmed(); + const QStringRef trimmedTokensStr = remainingFontStringRef.trimmed(); if (trimmedTokensStr.isEmpty()) { // No optional properties. return newFont; } - const QStringList tokens = trimmedTokensStr.split(QLatin1Char(' ')); + const auto tokens = trimmedTokensStr.split(QLatin1Char(' ')); int usedTokens = NoTokens; // Optional properties can be in any order, but font-size and font-family must be last. - for (const QString &token : tokens) { + for (const QStringRef &token : tokens) { if (token.compare(QLatin1String("normal")) == 0) { if (!(usedTokens & FontStyle) || !(usedTokens & FontVariant) || !(usedTokens & FontWeight)) { // Could be font-style, font-variant or font-weight. @@ -943,7 +945,7 @@ static QV4::ReturnedValue qt_create_image_data(qreal w, qreal h, QV4::ExecutionE pixelData->d()->image = QImage(w, h, QImage::Format_ARGB32); pixelData->d()->image.fill(0x00000000); } else { - Q_ASSERT(image.width() == int(w) && image.height() == int(h)); + Q_ASSERT(image.width() == qRound(w) && image.height() == qRound(h)); pixelData->d()->image = image.format() == QImage::Format_ARGB32 ? image : image.convertToFormat(QImage::Format_ARGB32); } @@ -1263,7 +1265,7 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_globalAlpha(QV4::CallContext *c double globalAlpha = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan(); - if (!qIsFinite(globalAlpha)) + if (!qt_is_finite(globalAlpha)) return QV4::Encode::undefined(); if (globalAlpha >= 0.0 && globalAlpha <= 1.0 && r->d()->context->state.globalAlpha != globalAlpha) { @@ -1547,10 +1549,10 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_createLinearGradient(QV4:: qreal x1 = ctx->args()[2].toNumber(); qreal y1 = ctx->args()[3].toNumber(); - if (!qIsFinite(x0) - || !qIsFinite(y0) - || !qIsFinite(x1) - || !qIsFinite(y1)) { + if (!qt_is_finite(x0) + || !qt_is_finite(y0) + || !qt_is_finite(x1) + || !qt_is_finite(y1)) { V4THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "createLinearGradient(): Incorrect arguments") } QQuickContext2DEngineData *ed = engineData(scope.engine); @@ -1592,12 +1594,12 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_createRadialGradient(QV4:: qreal y1 = ctx->args()[4].toNumber(); qreal r1 = ctx->args()[5].toNumber(); - if (!qIsFinite(x0) - || !qIsFinite(y0) - || !qIsFinite(x1) - || !qIsFinite(r0) - || !qIsFinite(r1) - || !qIsFinite(y1)) { + if (!qt_is_finite(x0) + || !qt_is_finite(y0) + || !qt_is_finite(x1) + || !qt_is_finite(r0) + || !qt_is_finite(r1) + || !qt_is_finite(y1)) { V4THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "createRadialGradient(): Incorrect arguments") } @@ -1639,11 +1641,11 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_createConicalGradient(QV4: qreal x = ctx->args()[0].toNumber(); qreal y = ctx->args()[1].toNumber(); qreal angle = DEGREES(ctx->args()[2].toNumber()); - if (!qIsFinite(x) || !qIsFinite(y)) { + if (!qt_is_finite(x) || !qt_is_finite(y)) { V4THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "createConicalGradient(): Incorrect arguments"); } - if (!qIsFinite(angle)) { + if (!qt_is_finite(angle)) { V4THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "createConicalGradient(): Incorrect arguments"); } @@ -1894,7 +1896,7 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_lineWidth(QV4::CallContext *ctx qreal w = ctx->argc() ? ctx->args()[0].toNumber() : -1; - if (w > 0 && qIsFinite(w) && w != r->d()->context->state.lineWidth) { + if (w > 0 && qt_is_finite(w) && w != r->d()->context->state.lineWidth) { r->d()->context->state.lineWidth = w; r->d()->context->buffer()->setLineWidth(w); } @@ -1923,7 +1925,7 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_miterLimit(QV4::CallContext *ct qreal ml = ctx->argc() ? ctx->args()[0].toNumber() : -1; - if (ml > 0 && qIsFinite(ml) && ml != r->d()->context->state.miterLimit) { + if (ml > 0 && qt_is_finite(ml) && ml != r->d()->context->state.miterLimit) { r->d()->context->state.miterLimit = ml; r->d()->context->buffer()->setMiterLimit(ml); } @@ -1952,7 +1954,7 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_shadowBlur(QV4::CallContext *ct qreal blur = ctx->argc() ? ctx->args()[0].toNumber() : -1; - if (blur > 0 && qIsFinite(blur) && blur != r->d()->context->state.shadowBlur) { + if (blur > 0 && qt_is_finite(blur) && blur != r->d()->context->state.shadowBlur) { r->d()->context->state.shadowBlur = blur; r->d()->context->buffer()->setShadowBlur(blur); } @@ -2012,7 +2014,7 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_shadowOffsetX(QV4::CallContext CHECK_CONTEXT_SETTER(r) qreal offsetX = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan(); - if (qIsFinite(offsetX) && offsetX != r->d()->context->state.shadowOffsetX) { + if (qt_is_finite(offsetX) && offsetX != r->d()->context->state.shadowOffsetX) { r->d()->context->state.shadowOffsetX = offsetX; r->d()->context->buffer()->setShadowOffsetX(offsetX); } @@ -2040,7 +2042,7 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_shadowOffsetY(QV4::CallContext CHECK_CONTEXT_SETTER(r) qreal offsetY = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan(); - if (qIsFinite(offsetY) && offsetY != r->d()->context->state.shadowOffsetY) { + if (qt_is_finite(offsetY) && offsetY != r->d()->context->state.shadowOffsetY) { r->d()->context->state.shadowOffsetY = offsetY; r->d()->context->buffer()->setShadowOffsetY(offsetY); } @@ -2170,7 +2172,7 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_arc(QV4::CallContext *ctx) qreal radius = ctx->args()[2].toNumber(); - if (qIsFinite(radius) && radius < 0) + if (qt_is_finite(radius) && radius < 0) V4THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "Incorrect argument radius"); r->d()->context->arc(ctx->args()[0].toNumber(), @@ -2216,7 +2218,7 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_arcTo(QV4::CallContext *ct if (ctx->argc() >= 5) { qreal radius = ctx->args()[4].toNumber(); - if (qIsFinite(radius) && radius < 0) + if (qt_is_finite(radius) && radius < 0) V4THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "Incorrect argument radius"); r->d()->context->arcTo(ctx->args()[0].toNumber(), @@ -2279,7 +2281,7 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_bezierCurveTo(QV4::CallCon qreal x = ctx->args()[4].toNumber(); qreal y = ctx->args()[5].toNumber(); - if (!qIsFinite(cp1x) || !qIsFinite(cp1y) || !qIsFinite(cp2x) || !qIsFinite(cp2y) || !qIsFinite(x) || !qIsFinite(y)) + if (!qt_is_finite(cp1x) || !qt_is_finite(cp1y) || !qt_is_finite(cp2x) || !qt_is_finite(cp2y) || !qt_is_finite(x) || !qt_is_finite(y)) return ctx->thisObject().asReturnedValue(); r->d()->context->bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y); @@ -2375,7 +2377,7 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_lineTo(QV4::CallContext *c qreal x = ctx->args()[0].toNumber(); qreal y = ctx->args()[1].toNumber(); - if (!qIsFinite(x) || !qIsFinite(y)) + if (!qt_is_finite(x) || !qt_is_finite(y)) return ctx->thisObject().asReturnedValue(); r->d()->context->lineTo(x, y); @@ -2399,7 +2401,7 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_moveTo(QV4::CallContext *c qreal x = ctx->args()[0].toNumber(); qreal y = ctx->args()[1].toNumber(); - if (!qIsFinite(x) || !qIsFinite(y)) + if (!qt_is_finite(x) || !qt_is_finite(y)) return ctx->thisObject().asReturnedValue(); r->d()->context->moveTo(x, y); } @@ -2425,7 +2427,7 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_quadraticCurveTo(QV4::Call qreal x = ctx->args()[2].toNumber(); qreal y = ctx->args()[3].toNumber(); - if (!qIsFinite(cpx) || !qIsFinite(cpy) || !qIsFinite(x) || !qIsFinite(y)) + if (!qt_is_finite(cpx) || !qt_is_finite(cpy) || !qt_is_finite(x) || !qt_is_finite(y)) return ctx->thisObject().asReturnedValue(); r->d()->context->quadraticCurveTo(cpx, cpy, x, y); @@ -2509,7 +2511,7 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_text(QV4::CallContext *ctx qreal x = ctx->args()[1].toNumber(); qreal y = ctx->args()[2].toNumber(); - if (!qIsFinite(x) || !qIsFinite(y)) + if (!qt_is_finite(x) || !qt_is_finite(y)) return ctx->thisObject().asReturnedValue(); r->d()->context->text(ctx->args()[0].toQStringNoThrow(), x, y); } @@ -2774,7 +2776,7 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_fillText(QV4::CallContext if (ctx->argc() >= 3) { qreal x = ctx->args()[1].toNumber(); qreal y = ctx->args()[2].toNumber(); - if (!qIsFinite(x) || !qIsFinite(y)) + if (!qt_is_finite(x) || !qt_is_finite(y)) return ctx->thisObject().asReturnedValue(); QPainterPath textPath = r->d()->context->createTextGlyphs(x, y, ctx->args()[0].toQStringNoThrow()); r->d()->context->buffer()->fill(textPath); @@ -2973,14 +2975,14 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_drawImage(QV4::CallContext return ctx->thisObject().asReturnedValue(); } - if (!qIsFinite(sx) - || !qIsFinite(sy) - || !qIsFinite(sw) - || !qIsFinite(sh) - || !qIsFinite(dx) - || !qIsFinite(dy) - || !qIsFinite(dw) - || !qIsFinite(dh)) + if (!qt_is_finite(sx) + || !qt_is_finite(sy) + || !qt_is_finite(sw) + || !qt_is_finite(sh) + || !qt_is_finite(dx) + || !qt_is_finite(dy) + || !qt_is_finite(dw) + || !qt_is_finite(dh)) return ctx->thisObject().asReturnedValue(); if (sx < 0 @@ -3201,7 +3203,7 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_createImageData(QV4::CallC qreal w = ctx->args()[0].toNumber(); qreal h = ctx->args()[1].toNumber(); - if (!qIsFinite(w) || !qIsFinite(h)) + if (!qt_is_finite(w) || !qt_is_finite(h)) V4THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "createImageData(): invalid arguments"); if (w > 0 && h > 0) @@ -3227,7 +3229,7 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_getImageData(QV4::CallCont qreal y = ctx->args()[1].toNumber(); qreal w = ctx->args()[2].toNumber(); qreal h = ctx->args()[3].toNumber(); - if (!qIsFinite(x) || !qIsFinite(y) || !qIsFinite(w) || !qIsFinite(h)) + if (!qt_is_finite(x) || !qt_is_finite(y) || !qt_is_finite(w) || !qt_is_finite(h)) V4THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "getImageData(): Invalid arguments"); if (w <= 0 || h <= 0) @@ -3259,7 +3261,7 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_putImageData(QV4::CallCont qreal dy = ctx->args()[2].toNumber(); qreal w, h, dirtyX, dirtyY, dirtyWidth, dirtyHeight; - if (!qIsFinite(dx) || !qIsFinite(dy)) + if (!qt_is_finite(dx) || !qt_is_finite(dy)) V4THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "putImageData() : Invalid arguments"); QV4::Scoped<QQuickJSContext2DImageData> imageData(scope, arg0); @@ -3277,7 +3279,7 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_putImageData(QV4::CallCont dirtyWidth = ctx->args()[5].toNumber(); dirtyHeight = ctx->args()[6].toNumber(); - if (!qIsFinite(dirtyX) || !qIsFinite(dirtyY) || !qIsFinite(dirtyWidth) || !qIsFinite(dirtyHeight)) + if (!qt_is_finite(dirtyX) || !qt_is_finite(dirtyY) || !qt_is_finite(dirtyWidth) || !qt_is_finite(dirtyHeight)) V4THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "putImageData() : Invalid arguments"); @@ -3364,7 +3366,7 @@ QV4::ReturnedValue QQuickContext2DStyle::gradient_proto_addColorStop(QV4::CallCo } else { color = qt_color_from_string(ctx->args()[1]); } - if (pos < 0.0 || pos > 1.0 || !qIsFinite(pos)) { + if (pos < 0.0 || pos > 1.0 || !qt_is_finite(pos)) { V4THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "CanvasGradient: parameter offset out of range"); } @@ -3384,7 +3386,7 @@ void QQuickContext2D::scale(qreal x, qreal y) if (!state.invertibleCTM) return; - if (!qIsFinite(x) || !qIsFinite(y)) + if (!qt_is_finite(x) || !qt_is_finite(y)) return; QTransform newTransform = state.matrix; @@ -3405,7 +3407,7 @@ void QQuickContext2D::rotate(qreal angle) if (!state.invertibleCTM) return; - if (!qIsFinite(angle)) + if (!qt_is_finite(angle)) return; QTransform newTransform =state.matrix; @@ -3426,7 +3428,7 @@ void QQuickContext2D::shear(qreal h, qreal v) if (!state.invertibleCTM) return; - if (!qIsFinite(h) || !qIsFinite(v)) + if (!qt_is_finite(h) || !qt_is_finite(v)) return ; QTransform newTransform = state.matrix; @@ -3447,7 +3449,7 @@ void QQuickContext2D::translate(qreal x, qreal y) if (!state.invertibleCTM) return; - if (!qIsFinite(x) || !qIsFinite(y)) + if (!qt_is_finite(x) || !qt_is_finite(y)) return ; QTransform newTransform = state.matrix; @@ -3468,7 +3470,7 @@ void QQuickContext2D::transform(qreal a, qreal b, qreal c, qreal d, qreal e, qre if (!state.invertibleCTM) return; - if (!qIsFinite(a) || !qIsFinite(b) || !qIsFinite(c) || !qIsFinite(d) || !qIsFinite(e) || !qIsFinite(f)) + if (!qt_is_finite(a) || !qt_is_finite(b) || !qt_is_finite(c) || !qt_is_finite(d) || !qt_is_finite(e) || !qt_is_finite(f)) return; QTransform transform(a, b, c, d, e, f); @@ -3485,7 +3487,7 @@ void QQuickContext2D::transform(qreal a, qreal b, qreal c, qreal d, qreal e, qre void QQuickContext2D::setTransform(qreal a, qreal b, qreal c, qreal d, qreal e, qreal f) { - if (!qIsFinite(a) || !qIsFinite(b) || !qIsFinite(c) || !qIsFinite(d) || !qIsFinite(e) || !qIsFinite(f)) + if (!qt_is_finite(a) || !qt_is_finite(b) || !qt_is_finite(c) || !qt_is_finite(d) || !qt_is_finite(e) || !qt_is_finite(f)) return; QTransform ctm = state.matrix; @@ -3542,7 +3544,7 @@ void QQuickContext2D::fillRect(qreal x, qreal y, qreal w, qreal h) if (!state.invertibleCTM) return; - if (!qIsFinite(x) || !qIsFinite(y) || !qIsFinite(w) || !qIsFinite(h)) + if (!qt_is_finite(x) || !qt_is_finite(y) || !qt_is_finite(w) || !qt_is_finite(h)) return; buffer()->fillRect(QRectF(x, y, w, h)); @@ -3553,7 +3555,7 @@ void QQuickContext2D::strokeRect(qreal x, qreal y, qreal w, qreal h) if (!state.invertibleCTM) return; - if (!qIsFinite(x) || !qIsFinite(y) || !qIsFinite(w) || !qIsFinite(h)) + if (!qt_is_finite(x) || !qt_is_finite(y) || !qt_is_finite(w) || !qt_is_finite(h)) return; buffer()->strokeRect(QRectF(x, y, w, h)); @@ -3564,7 +3566,7 @@ void QQuickContext2D::clearRect(qreal x, qreal y, qreal w, qreal h) if (!state.invertibleCTM) return; - if (!qIsFinite(x) || !qIsFinite(y) || !qIsFinite(w) || !qIsFinite(h)) + if (!qt_is_finite(x) || !qt_is_finite(y) || !qt_is_finite(w) || !qt_is_finite(h)) return; buffer()->clearRect(QRectF(x, y, w, h)); @@ -3575,7 +3577,7 @@ void QQuickContext2D::drawText(const QString& text, qreal x, qreal y, bool fill) if (!state.invertibleCTM) return; - if (!qIsFinite(x) || !qIsFinite(y)) + if (!qt_is_finite(x) || !qt_is_finite(y)) return; QPainterPath textPath = createTextGlyphs(x, y, text); @@ -3721,7 +3723,7 @@ void QQuickContext2D::arcTo(qreal x1, qreal y1, if (!state.invertibleCTM) return; - if (!qIsFinite(x1) || !qIsFinite(y1) || !qIsFinite(x2) || !qIsFinite(y2) || !qIsFinite(radius)) + if (!qt_is_finite(x1) || !qt_is_finite(y1) || !qt_is_finite(x2) || !qt_is_finite(y2) || !qt_is_finite(radius)) return; QPointF st(x1, y1); @@ -3739,7 +3741,7 @@ void QQuickContext2D::rect(qreal x, qreal y, qreal w, qreal h) { if (!state.invertibleCTM) return; - if (!qIsFinite(x) || !qIsFinite(y) || !qIsFinite(w) || !qIsFinite(h)) + if (!qt_is_finite(x) || !qt_is_finite(y) || !qt_is_finite(w) || !qt_is_finite(h)) return; if (!w && !h) { @@ -3756,7 +3758,7 @@ void QQuickContext2D::roundedRect(qreal x, qreal y, if (!state.invertibleCTM) return; - if (!qIsFinite(x) || !qIsFinite(y) || !qIsFinite(w) || !qIsFinite(h) || !qIsFinite(xr) || !qIsFinite(yr)) + if (!qt_is_finite(x) || !qt_is_finite(y) || !qt_is_finite(w) || !qt_is_finite(h) || !qt_is_finite(xr) || !qt_is_finite(yr)) return; if (!w && !h) { @@ -3772,7 +3774,7 @@ void QQuickContext2D::ellipse(qreal x, qreal y, if (!state.invertibleCTM) return; - if (!qIsFinite(x) || !qIsFinite(y) || !qIsFinite(w) || !qIsFinite(h)) + if (!qt_is_finite(x) || !qt_is_finite(y) || !qt_is_finite(w) || !qt_is_finite(h)) return; if (!w && !h) { @@ -3798,7 +3800,7 @@ void QQuickContext2D::arc(qreal xc, qreal yc, qreal radius, qreal sar, qreal ear if (!state.invertibleCTM) return; - if (!qIsFinite(xc) || !qIsFinite(yc) || !qIsFinite(sar) || !qIsFinite(ear) || !qIsFinite(radius)) + if (!qt_is_finite(xc) || !qt_is_finite(yc) || !qt_is_finite(sar) || !qt_is_finite(ear) || !qt_is_finite(radius)) return; if (sar == ear) @@ -3937,13 +3939,13 @@ bool QQuickContext2D::isPointInPath(qreal x, qreal y) const if (!m_path.elementCount()) return false; - if (!qIsFinite(x) || !qIsFinite(y)) + if (!qt_is_finite(x) || !qt_is_finite(y)) return false; QPointF point(x, y); QTransform ctm = state.matrix; QPointF p = ctm.inverted().map(point); - if (!qIsFinite(p.x()) || !qIsFinite(p.y())) + if (!qt_is_finite(p.x()) || !qt_is_finite(p.y())) return false; const_cast<QQuickContext2D *>(this)->m_path.setFillRule(state.fillRule); diff --git a/src/quick/items/qquickanchors.cpp b/src/quick/items/qquickanchors.cpp index d87669df56..4cbd41106e 100644 --- a/src/quick/items/qquickanchors.cpp +++ b/src/quick/items/qquickanchors.cpp @@ -39,19 +39,48 @@ #include "qquickanchors_p_p.h" -#include "qquickitem.h" #include "qquickitem_p.h" #include <qqmlinfo.h> QT_BEGIN_NAMESPACE +static Q_ALWAYS_INLINE QQuickItem *readParentItem(const QQuickItem *item) +{ + return QQuickItemPrivate::get(item)->parentItem; +} + +static Q_ALWAYS_INLINE qreal readX(const QQuickItem *item) +{ + return QQuickItemPrivate::get(item)->x; +} + +static Q_ALWAYS_INLINE qreal readY(const QQuickItem *item) +{ + return QQuickItemPrivate::get(item)->y; +} + +static Q_ALWAYS_INLINE qreal readWidth(const QQuickItem *item) +{ + return QQuickItemPrivate::get(item)->width; +} + +static Q_ALWAYS_INLINE qreal readHeight(const QQuickItem *item) +{ + return QQuickItemPrivate::get(item)->height; +} + +static Q_ALWAYS_INLINE qreal readBaselineOffset(const QQuickItem *item) +{ + return QQuickItemPrivate::get(item)->baselineOffset; +} + //TODO: should we cache relationships, so we don't have to check each time (parent-child or sibling)? //TODO: support non-parent, non-sibling (need to find lowest common ancestor) -static inline qreal hcenter(QQuickItem const *item) +static inline qreal hcenter(const QQuickItem *item) { - qreal width = item->width(); + qreal width = readWidth(item); if (QQuickAnchors *anchors = QQuickItemPrivate::get(item)->_anchors) { if (!QQuickAnchorsPrivate::get(anchors)->centerAligned) return width / 2; @@ -63,9 +92,9 @@ static inline qreal hcenter(QQuickItem const *item) return width / 2; } -static inline qreal vcenter(QQuickItem const *item) +static inline qreal vcenter(const QQuickItem *item) { - qreal height = item->height(); + qreal height = readHeight(item); if (QQuickAnchors *anchors = QQuickItemPrivate::get(item)->_anchors) { if (!QQuickAnchorsPrivate::get(anchors)->centerAligned) return height / 2; @@ -78,30 +107,30 @@ static inline qreal vcenter(QQuickItem const *item) } //local position -static qreal position(QQuickItem const *item, QQuickAnchorLine::AnchorLine anchorLine) +static inline qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine) { qreal ret = 0.0; switch (anchorLine) { - case QQuickAnchorLine::Left: - ret = item->x(); + case QQuickAnchors::LeftAnchor: + ret = readX(item); break; - case QQuickAnchorLine::Right: - ret = item->x() + item->width(); + case QQuickAnchors::RightAnchor: + ret = readX(item) + readWidth(item); break; - case QQuickAnchorLine::Top: - ret = item->y(); + case QQuickAnchors::TopAnchor: + ret = readY(item); break; - case QQuickAnchorLine::Bottom: - ret = item->y() + item->height(); + case QQuickAnchors::BottomAnchor: + ret = readY(item) + readHeight(item); break; - case QQuickAnchorLine::HCenter: - ret = item->x() + hcenter(item); + case QQuickAnchors::HCenterAnchor: + ret = readX(item) + hcenter(item); break; - case QQuickAnchorLine::VCenter: - ret = item->y() + vcenter(item); + case QQuickAnchors::VCenterAnchor: + ret = readY(item) + vcenter(item); break; - case QQuickAnchorLine::Baseline: - ret = item->y() + item->baselineOffset(); + case QQuickAnchors::BaselineAnchor: + ret = readY(item) + readBaselineOffset(item); break; default: break; @@ -111,30 +140,30 @@ static qreal position(QQuickItem const *item, QQuickAnchorLine::AnchorLine ancho } //position when origin is 0,0 -static qreal adjustedPosition(QQuickItem *item, QQuickAnchorLine::AnchorLine anchorLine) +static inline qreal adjustedPosition(QQuickItem *item, QQuickAnchors::Anchor anchorLine) { qreal ret = 0.0; switch (anchorLine) { - case QQuickAnchorLine::Left: + case QQuickAnchors::LeftAnchor: ret = 0.0; break; - case QQuickAnchorLine::Right: - ret = item->width(); + case QQuickAnchors::RightAnchor: + ret = readWidth(item); break; - case QQuickAnchorLine::Top: + case QQuickAnchors::TopAnchor: ret = 0.0; break; - case QQuickAnchorLine::Bottom: - ret = item->height(); + case QQuickAnchors::BottomAnchor: + ret = readHeight(item); break; - case QQuickAnchorLine::HCenter: + case QQuickAnchors::HCenterAnchor: ret = hcenter(item); break; - case QQuickAnchorLine::VCenter: + case QQuickAnchors::VCenterAnchor: ret = vcenter(item); break; - case QQuickAnchorLine::Baseline: - ret = item->baselineOffset(); + case QQuickAnchors::BaselineAnchor: + ret = readBaselineOffset(item); break; default: break; @@ -154,13 +183,13 @@ QQuickAnchors::~QQuickAnchors() d->inDestructor = true; d->remDepend(d->fill); d->remDepend(d->centerIn); - d->remDepend(d->left.item); - d->remDepend(d->right.item); - d->remDepend(d->top.item); - d->remDepend(d->bottom.item); - d->remDepend(d->vCenter.item); - d->remDepend(d->hCenter.item); - d->remDepend(d->baseline.item); + d->remDepend(d->leftAnchorItem); + d->remDepend(d->rightAnchorItem); + d->remDepend(d->topAnchorItem); + d->remDepend(d->bottomAnchorItem); + d->remDepend(d->vCenterAnchorItem); + d->remDepend(d->hCenterAnchorItem); + d->remDepend(d->baselineAnchorItem); } void QQuickAnchorsPrivate::fillChanged() @@ -174,12 +203,13 @@ void QQuickAnchorsPrivate::fillChanged() qreal horizontalMargin = q->mirrored() ? rightMargin : leftMargin; - if (fill == item->parentItem()) { //child-parent + if (fill == readParentItem(item)) { //child-parent setItemPos(QPointF(horizontalMargin, topMargin)); - } else if (fill->parentItem() == item->parentItem()) { //siblings - setItemPos(QPointF(fill->x()+horizontalMargin, fill->y()+topMargin)); + } else if (readParentItem(fill) == readParentItem(item)) { //siblings + setItemPos(QPointF(readX(fill)+horizontalMargin, readY(fill) + topMargin)); } - setItemSize(QSizeF(fill->width()-leftMargin-rightMargin, fill->height()-topMargin-bottomMargin)); + setItemSize(QSizeF(readWidth(fill) - leftMargin - rightMargin, + readHeight(fill) - topMargin - bottomMargin)); --updatingFill; } else { @@ -199,12 +229,12 @@ void QQuickAnchorsPrivate::centerInChanged() ++updatingCenterIn; qreal effectiveHCenterOffset = q->mirrored() ? -hCenterOffset : hCenterOffset; - if (centerIn == item->parentItem()) { - QPointF p(hcenter(item->parentItem()) - hcenter(item) + effectiveHCenterOffset, - vcenter(item->parentItem()) - vcenter(item) + vCenterOffset); + if (centerIn == readParentItem(item)) { + QPointF p(hcenter(readParentItem(item)) - hcenter(item) + effectiveHCenterOffset, + vcenter(readParentItem(item)) - vcenter(item) + vCenterOffset); setItemPos(p); - } else if (centerIn->parentItem() == item->parentItem()) { + } else if (readParentItem(centerIn) == readParentItem(item)) { QPointF p(centerIn->x() + hcenter(centerIn) - hcenter(item) + effectiveHCenterOffset, centerIn->y() + vcenter(centerIn) - vcenter(item) + vCenterOffset); setItemPos(p); @@ -225,32 +255,32 @@ void QQuickAnchorsPrivate::clearItem(QQuickItem *item) fill = 0; if (centerIn == item) centerIn = 0; - if (left.item == item) { - left.item = 0; + if (leftAnchorItem == item) { + leftAnchorItem = 0; usedAnchors &= ~QQuickAnchors::LeftAnchor; } - if (right.item == item) { - right.item = 0; + if (rightAnchorItem == item) { + rightAnchorItem = 0; usedAnchors &= ~QQuickAnchors::RightAnchor; } - if (top.item == item) { - top.item = 0; + if (topAnchorItem == item) { + topAnchorItem = 0; usedAnchors &= ~QQuickAnchors::TopAnchor; } - if (bottom.item == item) { - bottom.item = 0; + if (bottomAnchorItem == item) { + bottomAnchorItem = 0; usedAnchors &= ~QQuickAnchors::BottomAnchor; } - if (vCenter.item == item) { - vCenter.item = 0; + if (vCenterAnchorItem == item) { + vCenterAnchorItem = 0; usedAnchors &= ~QQuickAnchors::VCenterAnchor; } - if (hCenter.item == item) { - hCenter.item = 0; + if (hCenterAnchorItem == item) { + hCenterAnchorItem = 0; usedAnchors &= ~QQuickAnchors::HCenterAnchor; } - if (baseline.item == item) { - baseline.item = 0; + if (baselineAnchorItem == item) { + baselineAnchorItem = 0; usedAnchors &= ~QQuickAnchors::BaselineAnchor; } } @@ -263,7 +293,7 @@ int QQuickAnchorsPrivate::calculateDependency(QQuickItem *controlItem) return dependency; if (fill == controlItem) { - if (controlItem == item->parentItem()) + if (controlItem == readParentItem(item)) dependency |= QQuickItemPrivate::SizeChange; else //sibling dependency |= QQuickItemPrivate::GeometryChange; @@ -271,27 +301,27 @@ int QQuickAnchorsPrivate::calculateDependency(QQuickItem *controlItem) } if (centerIn == controlItem) { - if (controlItem == item->parentItem()) + if (controlItem == readParentItem(item)) dependency |= QQuickItemPrivate::SizeChange; else //sibling dependency |= QQuickItemPrivate::GeometryChange; return dependency; //exit early } - if ((usedAnchors & QQuickAnchors::LeftAnchor && left.item == controlItem) || - (usedAnchors & QQuickAnchors::RightAnchor && right.item == controlItem) || - (usedAnchors & QQuickAnchors::HCenterAnchor && hCenter.item == controlItem)) { - if (controlItem == item->parentItem()) + if ((usedAnchors & QQuickAnchors::LeftAnchor && leftAnchorItem == controlItem) || + (usedAnchors & QQuickAnchors::RightAnchor && rightAnchorItem == controlItem) || + (usedAnchors & QQuickAnchors::HCenterAnchor && hCenterAnchorItem == controlItem)) { + if (controlItem == readParentItem(item)) dependency |= QQuickItemPrivate::WidthChange; else //sibling dependency |= QFlags<QQuickItemPrivate::GeometryChangeType>(QQuickItemPrivate::XChange | QQuickItemPrivate::WidthChange); } - if ((usedAnchors & QQuickAnchors::TopAnchor && top.item == controlItem) || - (usedAnchors & QQuickAnchors::BottomAnchor && bottom.item == controlItem) || - (usedAnchors & QQuickAnchors::VCenterAnchor && vCenter.item == controlItem) || - (usedAnchors & QQuickAnchors::BaselineAnchor && baseline.item == controlItem)) { - if (controlItem == item->parentItem()) + if ((usedAnchors & QQuickAnchors::TopAnchor && topAnchorItem == controlItem) || + (usedAnchors & QQuickAnchors::BottomAnchor && bottomAnchorItem == controlItem) || + (usedAnchors & QQuickAnchors::VCenterAnchor && vCenterAnchorItem == controlItem) || + (usedAnchors & QQuickAnchors::BaselineAnchor && baselineAnchorItem == controlItem)) { + if (controlItem == readParentItem(item)) dependency |= QQuickItemPrivate::HeightChange; else //sibling dependency |= QFlags<QQuickItemPrivate::GeometryChangeType>(QQuickItemPrivate::YChange | QQuickItemPrivate::HeightChange); @@ -422,13 +452,13 @@ void QQuickAnchorsPrivate::updateOnComplete() QQuickItem *dependencies[9]; dependencies[0] = fill; dependencies[1] = centerIn; - dependencies[2] = left.item; - dependencies[3] = right.item; - dependencies[4] = hCenter.item; - dependencies[5] = top.item; - dependencies[6] = bottom.item; - dependencies[7] = vCenter.item; - dependencies[8] = baseline.item; + dependencies[2] = leftAnchorItem; + dependencies[3] = rightAnchorItem; + dependencies[4] = hCenterAnchorItem; + dependencies[5] = topAnchorItem; + dependencies[6] = bottomAnchorItem; + dependencies[7] = vCenterAnchorItem; + dependencies[8] = baselineAnchorItem; std::sort(dependencies, dependencies + 9); @@ -447,22 +477,38 @@ void QQuickAnchorsPrivate::updateOnComplete() void QQuickAnchorsPrivate::update() { - fillChanged(); - centerInChanged(); - if (usedAnchors & QQuickAnchorLine::Horizontal_Mask) - updateHorizontalAnchors(); - if (usedAnchors & QQuickAnchorLine::Vertical_Mask) - updateVerticalAnchors(); + if (!isItemComplete()) + return; + + if (fill) { + fillChanged(); + } else if (centerIn) { + centerInChanged(); + } else { + if (usedAnchors & QQuickAnchors::Horizontal_Mask) + updateHorizontalAnchors(); + if (usedAnchors & QQuickAnchors::Vertical_Mask) + updateVerticalAnchors(); + } } void QQuickAnchorsPrivate::itemGeometryChanged(QQuickItem *, const QRectF &newG, const QRectF &oldG) { - fillChanged(); - centerInChanged(); - if ((usedAnchors & QQuickAnchorLine::Horizontal_Mask) && (newG.x() != oldG.x() || newG.width() != oldG.width())) - updateHorizontalAnchors(); - if ((usedAnchors & QQuickAnchorLine::Vertical_Mask) && (newG.y() != oldG.y() || newG.height() != oldG.height())) - updateVerticalAnchors(); + if (!isItemComplete()) + return; + + if (fill) { + fillChanged(); + } else if (centerIn) { + centerInChanged(); + } else { + if ((usedAnchors & QQuickAnchors::Horizontal_Mask) + && (newG.x() != oldG.x() || newG.width() != oldG.width())) + updateHorizontalAnchors(); + if ((usedAnchors & QQuickAnchors::Vertical_Mask) + && (newG.y() != oldG.y() || newG.height() != oldG.height())) + updateVerticalAnchors(); + } } QQuickItem *QQuickAnchors::fill() const @@ -484,7 +530,7 @@ void QQuickAnchors::setFill(QQuickItem *f) emit fillChanged(); return; } - if (f != d->item->parentItem() && f->parentItem() != d->item->parentItem()){ + if (f != readParentItem(d->item) && readParentItem(f) != readParentItem(d->item)){ qmlInfo(d->item) << tr("Cannot anchor to an item that isn't a parent or sibling."); return; } @@ -520,7 +566,7 @@ void QQuickAnchors::setCenterIn(QQuickItem* c) emit centerInChanged(); return; } - if (c != d->item->parentItem() && c->parentItem() != d->item->parentItem()){ + if (c != readParentItem(d->item) && readParentItem(c) != readParentItem(d->item)){ qmlInfo(d->item) << tr("Cannot anchor to an item that isn't a parent or sibling."); return; } @@ -537,29 +583,31 @@ void QQuickAnchors::resetCenterIn() setCenterIn(0); } -bool QQuickAnchorsPrivate::calcStretch(const QQuickAnchorLine &edge1, - const QQuickAnchorLine &edge2, - qreal offset1, - qreal offset2, - QQuickAnchorLine::AnchorLine line, - qreal &stretch) +bool QQuickAnchorsPrivate::calcStretch(QQuickItem *edge1Item, + QQuickAnchors::Anchor edge1Line, + QQuickItem *edge2Item, + QQuickAnchors::Anchor edge2Line, + qreal offset1, + qreal offset2, + QQuickAnchors::Anchor line, + qreal &stretch) { - bool edge1IsParent = (edge1.item == item->parentItem()); - bool edge2IsParent = (edge2.item == item->parentItem()); - bool edge1IsSibling = (edge1.item->parentItem() == item->parentItem()); - bool edge2IsSibling = (edge2.item->parentItem() == item->parentItem()); + bool edge1IsParent = (edge1Item == readParentItem(item)); + bool edge2IsParent = (edge2Item == readParentItem(item)); + bool edge1IsSibling = (readParentItem(edge1Item) == readParentItem(item)); + bool edge2IsSibling = (readParentItem(edge2Item) == readParentItem(item)); bool invalid = false; if ((edge2IsParent && edge1IsParent) || (edge2IsSibling && edge1IsSibling)) { - stretch = (position(edge2.item, edge2.anchorLine) + offset2) - - (position(edge1.item, edge1.anchorLine) + offset1); + stretch = (position(edge2Item, edge2Line) + offset2) + - (position(edge1Item, edge1Line) + offset1); } else if (edge2IsParent && edge1IsSibling) { - stretch = (position(edge2.item, edge2.anchorLine) + offset2) - - (position(item->parentItem(), line) - + position(edge1.item, edge1.anchorLine) + offset1); + stretch = (position(edge2Item, edge2Line) + offset2) + - (position(readParentItem(item), line) + + position(edge1Item, edge1Line) + offset1); } else if (edge2IsSibling && edge1IsParent) { - stretch = (position(item->parentItem(), line) + position(edge2.item, edge2.anchorLine) + offset2) - - (position(edge1.item, edge1.anchorLine) + offset1); + stretch = (position(readParentItem(item), line) + position(edge2Item, edge2Line) + offset2) + - (position(edge1Item, edge1Line) + offset1); } else invalid = true; @@ -578,52 +626,60 @@ void QQuickAnchorsPrivate::updateVerticalAnchors() bool invalid = true; qreal height = 0.0; if (usedAnchors & QQuickAnchors::BottomAnchor) { - invalid = calcStretch(top, bottom, topMargin, -bottomMargin, QQuickAnchorLine::Top, height); + invalid = calcStretch(topAnchorItem, topAnchorLine, + bottomAnchorItem, bottomAnchorLine, + topMargin, -bottomMargin, QQuickAnchors::TopAnchor, height); } else if (usedAnchors & QQuickAnchors::VCenterAnchor) { - invalid = calcStretch(top, vCenter, topMargin, vCenterOffset, QQuickAnchorLine::Top, height); + invalid = calcStretch(topAnchorItem, topAnchorLine, + vCenterAnchorItem, vCenterAnchorLine, + topMargin, vCenterOffset, QQuickAnchors::TopAnchor, height); height *= 2; } if (!invalid) setItemHeight(height); //Handle top - if (top.item == item->parentItem()) { - setItemY(adjustedPosition(top.item, top.anchorLine) + topMargin); - } else if (top.item->parentItem() == item->parentItem()) { - setItemY(position(top.item, top.anchorLine) + topMargin); + if (topAnchorItem == readParentItem(item)) { + setItemY(adjustedPosition(topAnchorItem, topAnchorLine) + topMargin); + } else if (readParentItem(topAnchorItem) == readParentItem(item)) { + setItemY(position(topAnchorItem, topAnchorLine) + topMargin); } } else if (usedAnchors & QQuickAnchors::BottomAnchor) { //Handle stretching (top + bottom case is handled above) if (usedAnchors & QQuickAnchors::VCenterAnchor) { qreal height = 0.0; - bool invalid = calcStretch(vCenter, bottom, vCenterOffset, -bottomMargin, - QQuickAnchorLine::Top, height); + bool invalid = calcStretch(vCenterAnchorItem, vCenterAnchorLine, + bottomAnchorItem, bottomAnchorLine, + vCenterOffset, -bottomMargin, QQuickAnchors::TopAnchor, + height); if (!invalid) setItemHeight(height*2); } //Handle bottom - if (bottom.item == item->parentItem()) { - setItemY(adjustedPosition(bottom.item, bottom.anchorLine) - item->height() - bottomMargin); - } else if (bottom.item->parentItem() == item->parentItem()) { - setItemY(position(bottom.item, bottom.anchorLine) - item->height() - bottomMargin); + if (bottomAnchorItem == readParentItem(item)) { + setItemY(adjustedPosition(bottomAnchorItem, bottomAnchorLine) - readHeight(item) - bottomMargin); + } else if (readParentItem(bottomAnchorItem) == readParentItem(item)) { + setItemY(position(bottomAnchorItem, bottomAnchorLine) - readHeight(item) - bottomMargin); } } else if (usedAnchors & QQuickAnchors::VCenterAnchor) { //(stetching handled above) //Handle vCenter - if (vCenter.item == item->parentItem()) { - setItemY(adjustedPosition(vCenter.item, vCenter.anchorLine) + if (vCenterAnchorItem == readParentItem(item)) { + setItemY(adjustedPosition(vCenterAnchorItem, vCenterAnchorLine) - vcenter(item) + vCenterOffset); - } else if (vCenter.item->parentItem() == item->parentItem()) { - setItemY(position(vCenter.item, vCenter.anchorLine) - vcenter(item) + vCenterOffset); + } else if (readParentItem(vCenterAnchorItem) == readParentItem(item)) { + setItemY(position(vCenterAnchorItem, vCenterAnchorLine) - vcenter(item) + vCenterOffset); } } else if (usedAnchors & QQuickAnchors::BaselineAnchor) { //Handle baseline - if (baseline.item == item->parentItem()) { - setItemY(adjustedPosition(baseline.item, baseline.anchorLine) - item->baselineOffset() + baselineOffset); - } else if (baseline.item->parentItem() == item->parentItem()) { - setItemY(position(baseline.item, baseline.anchorLine) - item->baselineOffset() + baselineOffset); + if (baselineAnchorItem == readParentItem(item)) { + setItemY(adjustedPosition(baselineAnchorItem, baselineAnchorLine) + - readBaselineOffset(item) + baselineOffset); + } else if (readParentItem(baselineAnchorItem) == readParentItem(item)) { + setItemY(position(baselineAnchorItem, baselineAnchorLine) + - readBaselineOffset(item) + baselineOffset); } } --updatingVerticalAnchor; @@ -633,12 +689,12 @@ void QQuickAnchorsPrivate::updateVerticalAnchors() } } -inline QQuickAnchorLine::AnchorLine reverseAnchorLine(QQuickAnchorLine::AnchorLine anchorLine) +static inline QQuickAnchors::Anchor reverseAnchorLine(QQuickAnchors::Anchor anchorLine) { - if (anchorLine == QQuickAnchorLine::Left) { - return QQuickAnchorLine::Right; - } else if (anchorLine == QQuickAnchorLine::Right) { - return QQuickAnchorLine::Left; + if (anchorLine == QQuickAnchors::LeftAnchor) { + return QQuickAnchors::RightAnchor; + } else if (anchorLine == QQuickAnchors::RightAnchor) { + return QQuickAnchors::LeftAnchor; } else { return anchorLine; } @@ -653,26 +709,30 @@ void QQuickAnchorsPrivate::updateHorizontalAnchors() if (updatingHorizontalAnchor < 3) { ++updatingHorizontalAnchor; qreal effectiveRightMargin, effectiveLeftMargin, effectiveHorizontalCenterOffset; - QQuickAnchorLine effectiveLeft, effectiveRight, effectiveHorizontalCenter; + QQuickItem *effectiveLeftItem, *effectiveRightItem, *effectiveHorizontalCenterItem; + QQuickAnchors::Anchor effectiveLeftLine, effectiveRightLine, effectiveHorizontalCenterLine; QQuickAnchors::Anchor effectiveLeftAnchor, effectiveRightAnchor; if (q->mirrored()) { effectiveLeftAnchor = QQuickAnchors::RightAnchor; effectiveRightAnchor = QQuickAnchors::LeftAnchor; - effectiveLeft.item = right.item; - effectiveLeft.anchorLine = reverseAnchorLine(right.anchorLine); - effectiveRight.item = left.item; - effectiveRight.anchorLine = reverseAnchorLine(left.anchorLine); - effectiveHorizontalCenter.item = hCenter.item; - effectiveHorizontalCenter.anchorLine = reverseAnchorLine(hCenter.anchorLine); + effectiveLeftItem = rightAnchorItem; + effectiveLeftLine = reverseAnchorLine(rightAnchorLine); + effectiveRightItem = leftAnchorItem; + effectiveRightLine = reverseAnchorLine(leftAnchorLine); + effectiveHorizontalCenterItem = hCenterAnchorItem; + effectiveHorizontalCenterLine = reverseAnchorLine(hCenterAnchorLine); effectiveLeftMargin = rightMargin; effectiveRightMargin = leftMargin; effectiveHorizontalCenterOffset = -hCenterOffset; } else { effectiveLeftAnchor = QQuickAnchors::LeftAnchor; effectiveRightAnchor = QQuickAnchors::RightAnchor; - effectiveLeft = left; - effectiveRight = right; - effectiveHorizontalCenter = hCenter; + effectiveLeftItem = leftAnchorItem; + effectiveLeftLine = leftAnchorLine; + effectiveRightItem = rightAnchorItem; + effectiveRightLine = rightAnchorLine; + effectiveHorizontalCenterItem = hCenterAnchorItem; + effectiveHorizontalCenterLine = hCenterAnchorLine; effectiveLeftMargin = leftMargin; effectiveRightMargin = rightMargin; effectiveHorizontalCenterOffset = hCenterOffset; @@ -683,42 +743,53 @@ void QQuickAnchorsPrivate::updateHorizontalAnchors() bool invalid = true; qreal width = 0.0; if (usedAnchors & effectiveRightAnchor) { - invalid = calcStretch(effectiveLeft, effectiveRight, effectiveLeftMargin, -effectiveRightMargin, QQuickAnchorLine::Left, width); + invalid = calcStretch(effectiveLeftItem, effectiveLeftLine, + effectiveRightItem, effectiveRightLine, + effectiveLeftMargin, -effectiveRightMargin, + QQuickAnchors::LeftAnchor, width); } else if (usedAnchors & QQuickAnchors::HCenterAnchor) { - invalid = calcStretch(effectiveLeft, effectiveHorizontalCenter, effectiveLeftMargin, effectiveHorizontalCenterOffset, QQuickAnchorLine::Left, width); + invalid = calcStretch(effectiveLeftItem, effectiveLeftLine, + effectiveHorizontalCenterItem, effectiveHorizontalCenterLine, + effectiveLeftMargin, effectiveHorizontalCenterOffset, + QQuickAnchors::LeftAnchor, width); width *= 2; } if (!invalid) setItemWidth(width); //Handle left - if (effectiveLeft.item == item->parentItem()) { - setItemX(adjustedPosition(effectiveLeft.item, effectiveLeft.anchorLine) + effectiveLeftMargin); - } else if (effectiveLeft.item->parentItem() == item->parentItem()) { - setItemX(position(effectiveLeft.item, effectiveLeft.anchorLine) + effectiveLeftMargin); + if (effectiveLeftItem == readParentItem(item)) { + setItemX(adjustedPosition(effectiveLeftItem, effectiveLeftLine) + effectiveLeftMargin); + } else if (readParentItem(effectiveLeftItem) == readParentItem(item)) { + setItemX(position(effectiveLeftItem, effectiveLeftLine) + effectiveLeftMargin); } } else if (usedAnchors & effectiveRightAnchor) { //Handle stretching (left + right case is handled in updateLeftAnchor) if (usedAnchors & QQuickAnchors::HCenterAnchor) { qreal width = 0.0; - bool invalid = calcStretch(effectiveHorizontalCenter, effectiveRight, effectiveHorizontalCenterOffset, -effectiveRightMargin, - QQuickAnchorLine::Left, width); + bool invalid = calcStretch(effectiveHorizontalCenterItem, + effectiveHorizontalCenterLine, + effectiveRightItem, effectiveRightLine, + effectiveHorizontalCenterOffset, -effectiveRightMargin, + QQuickAnchors::LeftAnchor, width); if (!invalid) setItemWidth(width*2); } //Handle right - if (effectiveRight.item == item->parentItem()) { - setItemX(adjustedPosition(effectiveRight.item, effectiveRight.anchorLine) - item->width() - effectiveRightMargin); - } else if (effectiveRight.item->parentItem() == item->parentItem()) { - setItemX(position(effectiveRight.item, effectiveRight.anchorLine) - item->width() - effectiveRightMargin); + if (effectiveRightItem == readParentItem(item)) { + setItemX(adjustedPosition(effectiveRightItem, effectiveRightLine) + - readWidth(item) - effectiveRightMargin); + } else if (readParentItem(effectiveRightItem) == readParentItem(item)) { + setItemX(position(effectiveRightItem, effectiveRightLine) + - readWidth(item) - effectiveRightMargin); } } else if (usedAnchors & QQuickAnchors::HCenterAnchor) { //Handle hCenter - if (effectiveHorizontalCenter.item == item->parentItem()) { - setItemX(adjustedPosition(effectiveHorizontalCenter.item, effectiveHorizontalCenter.anchorLine) - hcenter(item) + effectiveHorizontalCenterOffset); - } else if (effectiveHorizontalCenter.item->parentItem() == item->parentItem()) { - setItemX(position(effectiveHorizontalCenter.item, effectiveHorizontalCenter.anchorLine) - hcenter(item) + effectiveHorizontalCenterOffset); + if (effectiveHorizontalCenterItem == readParentItem(item)) { + setItemX(adjustedPosition(effectiveHorizontalCenterItem, effectiveHorizontalCenterLine) - hcenter(item) + effectiveHorizontalCenterOffset); + } else if (readParentItem(effectiveHorizontalCenterItem) == readParentItem(item)) { + setItemX(position(effectiveHorizontalCenterItem, effectiveHorizontalCenterLine) - hcenter(item) + effectiveHorizontalCenterOffset); } } --updatingHorizontalAnchor; @@ -731,13 +802,14 @@ void QQuickAnchorsPrivate::updateHorizontalAnchors() QQuickAnchorLine QQuickAnchors::top() const { Q_D(const QQuickAnchors); - return d->top; + return QQuickAnchorLine(d->topAnchorItem, d->topAnchorLine); } void QQuickAnchors::setTop(const QQuickAnchorLine &edge) { Q_D(QQuickAnchors); - if (!d->checkVAnchorValid(edge) || d->top == edge) + if (!d->checkVAnchorValid(edge) || + (d->topAnchorItem == edge.item && d->topAnchorLine == edge.anchorLine)) return; d->usedAnchors |= TopAnchor; @@ -747,10 +819,11 @@ void QQuickAnchors::setTop(const QQuickAnchorLine &edge) return; } - QQuickItem *oldTop = d->top.item; - d->top = edge; + QQuickItem *oldTop = d->topAnchorItem; + d->topAnchorItem = edge.item; + d->topAnchorLine = edge.anchorLine; d->remDepend(oldTop); - d->addDepend(d->top.item); + d->addDepend(d->topAnchorItem); emit topChanged(); d->updateVerticalAnchors(); } @@ -759,8 +832,9 @@ void QQuickAnchors::resetTop() { Q_D(QQuickAnchors); d->usedAnchors &= ~TopAnchor; - d->remDepend(d->top.item); - d->top = QQuickAnchorLine(); + d->remDepend(d->topAnchorItem); + d->topAnchorItem = Q_NULLPTR; + d->topAnchorLine = QQuickAnchors::InvalidAnchor; emit topChanged(); d->updateVerticalAnchors(); } @@ -768,13 +842,14 @@ void QQuickAnchors::resetTop() QQuickAnchorLine QQuickAnchors::bottom() const { Q_D(const QQuickAnchors); - return d->bottom; + return QQuickAnchorLine(d->bottomAnchorItem, d->bottomAnchorLine); } void QQuickAnchors::setBottom(const QQuickAnchorLine &edge) { Q_D(QQuickAnchors); - if (!d->checkVAnchorValid(edge) || d->bottom == edge) + if (!d->checkVAnchorValid(edge) || + (d->bottomAnchorItem == edge.item && d->bottomAnchorLine == edge.anchorLine)) return; d->usedAnchors |= BottomAnchor; @@ -784,10 +859,11 @@ void QQuickAnchors::setBottom(const QQuickAnchorLine &edge) return; } - QQuickItem *oldBottom = d->bottom.item; - d->bottom = edge; + QQuickItem *oldBottom = d->bottomAnchorItem; + d->bottomAnchorItem = edge.item; + d->bottomAnchorLine = edge.anchorLine; d->remDepend(oldBottom); - d->addDepend(d->bottom.item); + d->addDepend(d->bottomAnchorItem); emit bottomChanged(); d->updateVerticalAnchors(); } @@ -796,8 +872,9 @@ void QQuickAnchors::resetBottom() { Q_D(QQuickAnchors); d->usedAnchors &= ~BottomAnchor; - d->remDepend(d->bottom.item); - d->bottom = QQuickAnchorLine(); + d->remDepend(d->bottomAnchorItem); + d->bottomAnchorItem = Q_NULLPTR; + d->bottomAnchorLine = QQuickAnchors::InvalidAnchor; emit bottomChanged(); d->updateVerticalAnchors(); } @@ -805,13 +882,14 @@ void QQuickAnchors::resetBottom() QQuickAnchorLine QQuickAnchors::verticalCenter() const { Q_D(const QQuickAnchors); - return d->vCenter; + return QQuickAnchorLine(d->vCenterAnchorItem, d->vCenterAnchorLine); } void QQuickAnchors::setVerticalCenter(const QQuickAnchorLine &edge) { Q_D(QQuickAnchors); - if (!d->checkVAnchorValid(edge) || d->vCenter == edge) + if (!d->checkVAnchorValid(edge) || + (d->vCenterAnchorItem == edge.item && d->vCenterAnchorLine == edge.anchorLine)) return; d->usedAnchors |= VCenterAnchor; @@ -821,10 +899,11 @@ void QQuickAnchors::setVerticalCenter(const QQuickAnchorLine &edge) return; } - QQuickItem *oldVCenter = d->vCenter.item; - d->vCenter = edge; + QQuickItem *oldVCenter = d->vCenterAnchorItem; + d->vCenterAnchorItem = edge.item; + d->vCenterAnchorLine = edge.anchorLine; d->remDepend(oldVCenter); - d->addDepend(d->vCenter.item); + d->addDepend(d->vCenterAnchorItem); emit verticalCenterChanged(); d->updateVerticalAnchors(); } @@ -833,8 +912,9 @@ void QQuickAnchors::resetVerticalCenter() { Q_D(QQuickAnchors); d->usedAnchors &= ~VCenterAnchor; - d->remDepend(d->vCenter.item); - d->vCenter = QQuickAnchorLine(); + d->remDepend(d->vCenterAnchorItem); + d->vCenterAnchorItem = Q_NULLPTR; + d->vCenterAnchorLine = QQuickAnchors::InvalidAnchor; emit verticalCenterChanged(); d->updateVerticalAnchors(); } @@ -842,13 +922,14 @@ void QQuickAnchors::resetVerticalCenter() QQuickAnchorLine QQuickAnchors::baseline() const { Q_D(const QQuickAnchors); - return d->baseline; + return QQuickAnchorLine(d->baselineAnchorItem, d->baselineAnchorLine); } void QQuickAnchors::setBaseline(const QQuickAnchorLine &edge) { Q_D(QQuickAnchors); - if (!d->checkVAnchorValid(edge) || d->baseline == edge) + if (!d->checkVAnchorValid(edge) || + (d->baselineAnchorItem == edge.item && d->baselineAnchorLine == edge.anchorLine)) return; d->usedAnchors |= BaselineAnchor; @@ -858,10 +939,11 @@ void QQuickAnchors::setBaseline(const QQuickAnchorLine &edge) return; } - QQuickItem *oldBaseline = d->baseline.item; - d->baseline = edge; + QQuickItem *oldBaseline = d->baselineAnchorItem; + d->baselineAnchorItem = edge.item; + d->baselineAnchorLine = edge.anchorLine; d->remDepend(oldBaseline); - d->addDepend(d->baseline.item); + d->addDepend(d->baselineAnchorItem); emit baselineChanged(); d->updateVerticalAnchors(); } @@ -870,8 +952,9 @@ void QQuickAnchors::resetBaseline() { Q_D(QQuickAnchors); d->usedAnchors &= ~BaselineAnchor; - d->remDepend(d->baseline.item); - d->baseline = QQuickAnchorLine(); + d->remDepend(d->baselineAnchorItem); + d->baselineAnchorItem = Q_NULLPTR; + d->baselineAnchorLine = QQuickAnchors::InvalidAnchor; emit baselineChanged(); d->updateVerticalAnchors(); } @@ -879,13 +962,14 @@ void QQuickAnchors::resetBaseline() QQuickAnchorLine QQuickAnchors::left() const { Q_D(const QQuickAnchors); - return d->left; + return QQuickAnchorLine(d->leftAnchorItem, d->leftAnchorLine); } void QQuickAnchors::setLeft(const QQuickAnchorLine &edge) { Q_D(QQuickAnchors); - if (!d->checkHAnchorValid(edge) || d->left == edge) + if (!d->checkHAnchorValid(edge) || + (d->leftAnchorItem == edge.item && d->leftAnchorLine == edge.anchorLine)) return; d->usedAnchors |= LeftAnchor; @@ -895,10 +979,11 @@ void QQuickAnchors::setLeft(const QQuickAnchorLine &edge) return; } - QQuickItem *oldLeft = d->left.item; - d->left = edge; + QQuickItem *oldLeft = d->leftAnchorItem; + d->leftAnchorItem = edge.item; + d->leftAnchorLine = edge.anchorLine; d->remDepend(oldLeft); - d->addDepend(d->left.item); + d->addDepend(d->leftAnchorItem); emit leftChanged(); d->updateHorizontalAnchors(); } @@ -907,8 +992,9 @@ void QQuickAnchors::resetLeft() { Q_D(QQuickAnchors); d->usedAnchors &= ~LeftAnchor; - d->remDepend(d->left.item); - d->left = QQuickAnchorLine(); + d->remDepend(d->leftAnchorItem); + d->leftAnchorItem = Q_NULLPTR; + d->leftAnchorLine = QQuickAnchors::InvalidAnchor; emit leftChanged(); d->updateHorizontalAnchors(); } @@ -916,13 +1002,14 @@ void QQuickAnchors::resetLeft() QQuickAnchorLine QQuickAnchors::right() const { Q_D(const QQuickAnchors); - return d->right; + return QQuickAnchorLine(d->rightAnchorItem, d->rightAnchorLine); } void QQuickAnchors::setRight(const QQuickAnchorLine &edge) { Q_D(QQuickAnchors); - if (!d->checkHAnchorValid(edge) || d->right == edge) + if (!d->checkHAnchorValid(edge) || + (d->rightAnchorItem == edge.item && d->rightAnchorLine == edge.anchorLine)) return; d->usedAnchors |= RightAnchor; @@ -932,10 +1019,11 @@ void QQuickAnchors::setRight(const QQuickAnchorLine &edge) return; } - QQuickItem *oldRight = d->right.item; - d->right = edge; + QQuickItem *oldRight = d->rightAnchorItem; + d->rightAnchorItem = edge.item; + d->rightAnchorLine = edge.anchorLine; d->remDepend(oldRight); - d->addDepend(d->right.item); + d->addDepend(d->rightAnchorItem); emit rightChanged(); d->updateHorizontalAnchors(); } @@ -944,8 +1032,9 @@ void QQuickAnchors::resetRight() { Q_D(QQuickAnchors); d->usedAnchors &= ~RightAnchor; - d->remDepend(d->right.item); - d->right = QQuickAnchorLine(); + d->remDepend(d->rightAnchorItem); + d->rightAnchorItem = Q_NULLPTR; + d->rightAnchorLine = QQuickAnchors::InvalidAnchor; emit rightChanged(); d->updateHorizontalAnchors(); } @@ -953,13 +1042,14 @@ void QQuickAnchors::resetRight() QQuickAnchorLine QQuickAnchors::horizontalCenter() const { Q_D(const QQuickAnchors); - return d->hCenter; + return QQuickAnchorLine(d->hCenterAnchorItem, d->hCenterAnchorLine); } void QQuickAnchors::setHorizontalCenter(const QQuickAnchorLine &edge) { Q_D(QQuickAnchors); - if (!d->checkHAnchorValid(edge) || d->hCenter == edge) + if (!d->checkHAnchorValid(edge) || + (d->hCenterAnchorItem == edge.item && d->hCenterAnchorLine == edge.anchorLine)) return; d->usedAnchors |= HCenterAnchor; @@ -969,10 +1059,11 @@ void QQuickAnchors::setHorizontalCenter(const QQuickAnchorLine &edge) return; } - QQuickItem *oldHCenter = d->hCenter.item; - d->hCenter = edge; + QQuickItem *oldHCenter = d->hCenterAnchorItem; + d->hCenterAnchorItem = edge.item; + d->hCenterAnchorLine = edge.anchorLine; d->remDepend(oldHCenter); - d->addDepend(d->hCenter.item); + d->addDepend(d->hCenterAnchorItem); emit horizontalCenterChanged(); d->updateHorizontalAnchors(); } @@ -981,8 +1072,9 @@ void QQuickAnchors::resetHorizontalCenter() { Q_D(QQuickAnchors); d->usedAnchors &= ~HCenterAnchor; - d->remDepend(d->hCenter.item); - d->hCenter = QQuickAnchorLine(); + d->remDepend(d->hCenterAnchorItem); + d->hCenterAnchorItem = Q_NULLPTR; + d->hCenterAnchorLine = QQuickAnchors::InvalidAnchor; emit horizontalCenterChanged(); d->updateHorizontalAnchors(); } @@ -1230,7 +1322,7 @@ void QQuickAnchors::setBaselineOffset(qreal offset) QQuickAnchors::Anchors QQuickAnchors::usedAnchors() const { Q_D(const QQuickAnchors); - return d->usedAnchors; + return static_cast<QQuickAnchors::Anchors>(d->usedAnchors); } bool QQuickAnchorsPrivate::checkHValid() const @@ -1250,10 +1342,11 @@ bool QQuickAnchorsPrivate::checkHAnchorValid(QQuickAnchorLine anchor) const if (!anchor.item) { qmlInfo(item) << QQuickAnchors::tr("Cannot anchor to a null item."); return false; - } else if (anchor.anchorLine & QQuickAnchorLine::Vertical_Mask) { + } else if (anchor.anchorLine & QQuickAnchors::Vertical_Mask) { qmlInfo(item) << QQuickAnchors::tr("Cannot anchor a horizontal edge to a vertical edge."); return false; - } else if (anchor.item != item->parentItem() && anchor.item->parentItem() != item->parentItem()){ + } else if (anchor.item != readParentItem(item) + && readParentItem(anchor.item) != readParentItem(item)) { qmlInfo(item) << QQuickAnchors::tr("Cannot anchor to an item that isn't a parent or sibling."); return false; } else if (anchor.item == item) { @@ -1287,10 +1380,11 @@ bool QQuickAnchorsPrivate::checkVAnchorValid(QQuickAnchorLine anchor) const if (!anchor.item) { qmlInfo(item) << QQuickAnchors::tr("Cannot anchor to a null item."); return false; - } else if (anchor.anchorLine & QQuickAnchorLine::Horizontal_Mask) { + } else if (anchor.anchorLine & QQuickAnchors::Horizontal_Mask) { qmlInfo(item) << QQuickAnchors::tr("Cannot anchor a vertical edge to a horizontal edge."); return false; - } else if (anchor.item != item->parentItem() && anchor.item->parentItem() != item->parentItem()){ + } else if (anchor.item != readParentItem(item) + && readParentItem(anchor.item) != readParentItem(item)) { qmlInfo(item) << QQuickAnchors::tr("Cannot anchor to an item that isn't a parent or sibling."); return false; } else if (anchor.item == item){ diff --git a/src/quick/items/qquickanchors_p.h b/src/quick/items/qquickanchors_p.h index 0e02d80ae8..f00b8b5ba7 100644 --- a/src/quick/items/qquickanchors_p.h +++ b/src/quick/items/qquickanchors_p.h @@ -89,7 +89,14 @@ public: QQuickAnchors(QQuickItem *item, QObject *parent=0); virtual ~QQuickAnchors(); - enum Anchor { + enum Anchor +#if defined(Q_CC_CLANG) || !defined(Q_CC_GNU) // meaning: clang and msvc, but NOT gcc proper (because, you know, Q_CC_CLANG implies Q_CC_GNU) + // Not specifying the enum base type will have MSVC 'interpret' it as signed instead of an unsigned bit-field. + // However, specifying the enum base type breaks many GCCs, which complain that it can't store all values in a 7 bit bitfield. + : uint +#endif + { + InvalidAnchor = 0x0, LeftAnchor = 0x01, RightAnchor = 0x02, TopAnchor = 0x04, diff --git a/src/quick/items/qquickanchors_p_p.h b/src/quick/items/qquickanchors_p_p.h index 205d9a40da..da659946c0 100644 --- a/src/quick/items/qquickanchors_p_p.h +++ b/src/quick/items/qquickanchors_p_p.h @@ -60,24 +60,15 @@ QT_BEGIN_NAMESPACE class QQuickAnchorLine { public: - enum AnchorLine { - Invalid = 0x0, - Left = 0x01, - Right = 0x02, - Top = 0x04, - Bottom = 0x08, - HCenter = 0x10, - VCenter = 0x20, - Baseline = 0x40, - Horizontal_Mask = Left | Right | HCenter, - Vertical_Mask = Top | Bottom | VCenter | Baseline - }; - - QQuickAnchorLine() : item(0), anchorLine(Invalid) {} - QQuickAnchorLine(QQuickItem *i, AnchorLine l) : item(i), anchorLine(l) {} + QQuickAnchorLine() : item(0), anchorLine(QQuickAnchors::InvalidAnchor) {} + QQuickAnchorLine(QQuickItem *i, QQuickAnchors::Anchor l) : item(i), anchorLine(l) {} + QQuickAnchorLine(QQuickItem *i, uint l) + : item(i) + , anchorLine(static_cast<QQuickAnchors::Anchor>(l)) + { Q_ASSERT(l < ((QQuickAnchors::BaselineAnchor << 1) - 1)); } QQuickItem *item; - AnchorLine anchorLine; + QQuickAnchors::Anchor anchorLine; }; inline bool operator==(const QQuickAnchorLine& a, const QQuickAnchorLine& b) @@ -90,13 +81,44 @@ class QQuickAnchorsPrivate : public QObjectPrivate, public QQuickItemChangeListe Q_DECLARE_PUBLIC(QQuickAnchors) public: QQuickAnchorsPrivate(QQuickItem *i) - : componentComplete(true), updatingMe(false), inDestructor(false), centerAligned(true), - leftMarginExplicit(false), rightMarginExplicit(false), topMarginExplicit(false), - bottomMarginExplicit(false), updatingHorizontalAnchor(0), - updatingVerticalAnchor(0), updatingFill(0), updatingCenterIn(0), item(i), usedAnchors(0), fill(0), - centerIn(0), leftMargin(0), rightMargin(0), topMargin(0), bottomMargin(0), - margins(0), vCenterOffset(0), hCenterOffset(0), baselineOffset(0) - + : leftMargin(0) + , rightMargin(0) + , topMargin(0) + , bottomMargin(0) + , margins(0) + , vCenterOffset(0) + , hCenterOffset(0) + , baselineOffset(0) + , item(i) + , fill(Q_NULLPTR) + , centerIn(Q_NULLPTR) + , leftAnchorItem(Q_NULLPTR) + , rightAnchorItem(Q_NULLPTR) + , topAnchorItem(Q_NULLPTR) + , bottomAnchorItem(Q_NULLPTR) + , vCenterAnchorItem(Q_NULLPTR) + , hCenterAnchorItem(Q_NULLPTR) + , baselineAnchorItem(Q_NULLPTR) + , leftAnchorLine(QQuickAnchors::InvalidAnchor) + , leftMarginExplicit(false) + , rightAnchorLine(QQuickAnchors::InvalidAnchor) + , rightMarginExplicit(false) + , topAnchorLine(QQuickAnchors::InvalidAnchor) + , topMarginExplicit(false) + , bottomAnchorLine(QQuickAnchors::InvalidAnchor) + , bottomMarginExplicit(false) + , vCenterAnchorLine(QQuickAnchors::InvalidAnchor) + , updatingMe(false) + , hCenterAnchorLine(QQuickAnchors::InvalidAnchor) + , inDestructor(false) + , baselineAnchorLine(QQuickAnchors::InvalidAnchor) + , centerAligned(true) + , updatingFill(0) + , updatingCenterIn(0) + , updatingHorizontalAnchor(0) + , updatingVerticalAnchor(0) + , componentComplete(true) + , usedAnchors(QQuickAnchors::InvalidAnchor) { } @@ -107,19 +129,6 @@ public: void remDepend(QQuickItem *); bool isItemComplete() const; - bool componentComplete:1; - bool updatingMe:1; - bool inDestructor:1; - bool centerAligned:1; - bool leftMarginExplicit : 1; - bool rightMarginExplicit : 1; - bool topMarginExplicit : 1; - bool bottomMarginExplicit : 1; - uint updatingHorizontalAnchor:2; - uint updatingVerticalAnchor:2; - uint updatingFill:2; - uint updatingCenterIn:2; - void setItemHeight(qreal); void setItemWidth(qreal); void setItemX(qreal); @@ -139,7 +148,9 @@ public: bool checkVValid() const; bool checkHAnchorValid(QQuickAnchorLine anchor) const; bool checkVAnchorValid(QQuickAnchorLine anchor) const; - bool calcStretch(const QQuickAnchorLine &edge1, const QQuickAnchorLine &edge2, qreal offset1, qreal offset2, QQuickAnchorLine::AnchorLine line, qreal &stretch); + bool calcStretch(QQuickItem *edge1Item, QQuickAnchors::Anchor edge1Line, + QQuickItem *edge2Item, QQuickAnchors::Anchor edge2Line, + qreal offset1, qreal offset2, QQuickAnchors::Anchor line, qreal &stretch); bool isMirrored() const; void updateHorizontalAnchors(); @@ -147,20 +158,6 @@ public: void fillChanged(); void centerInChanged(); - QQuickItem *item; - QQuickAnchors::Anchors usedAnchors; - - QQuickItem *fill; - QQuickItem *centerIn; - - QQuickAnchorLine left; - QQuickAnchorLine right; - QQuickAnchorLine top; - QQuickAnchorLine bottom; - QQuickAnchorLine vCenter; - QQuickAnchorLine hCenter; - QQuickAnchorLine baseline; - qreal leftMargin; qreal rightMargin; qreal topMargin; @@ -170,6 +167,44 @@ public: qreal hCenterOffset; qreal baselineOffset; + QQuickItem *item; + + QQuickItem *fill; + QQuickItem *centerIn; + + QQuickItem *leftAnchorItem; + QQuickItem *rightAnchorItem; + QQuickItem *topAnchorItem; + QQuickItem *bottomAnchorItem; + QQuickItem *vCenterAnchorItem; + QQuickItem *hCenterAnchorItem; + QQuickItem *baselineAnchorItem; + + // The bit fields below are carefully laid out in chunks of 1 byte, so the compiler doesn't + // need to generate 2 loads (and combining shifts/ors) to create a single field. + + QQuickAnchors::Anchor leftAnchorLine : 7; + uint leftMarginExplicit : 1; + QQuickAnchors::Anchor rightAnchorLine : 7; + uint rightMarginExplicit : 1; + QQuickAnchors::Anchor topAnchorLine : 7; + uint topMarginExplicit : 1; + QQuickAnchors::Anchor bottomAnchorLine : 7; + uint bottomMarginExplicit : 1; + + QQuickAnchors::Anchor vCenterAnchorLine : 7; + uint updatingMe : 1; + QQuickAnchors::Anchor hCenterAnchorLine : 7; + uint inDestructor : 1; + QQuickAnchors::Anchor baselineAnchorLine : 7; + uint centerAligned : 1; + uint updatingFill : 2; + uint updatingCenterIn : 2; + uint updatingHorizontalAnchor : 2; + uint updatingVerticalAnchor : 2; + + uint componentComplete : 1; + uint usedAnchors : 7; // QQuickAnchors::Anchors static inline QQuickAnchorsPrivate *get(QQuickAnchors *o) { return static_cast<QQuickAnchorsPrivate *>(QObjectPrivate::get(o)); diff --git a/src/quick/items/qquickanimatedimage.cpp b/src/quick/items/qquickanimatedimage.cpp index 42033b6135..6f14bf15fe 100644 --- a/src/quick/items/qquickanimatedimage.cpp +++ b/src/quick/items/qquickanimatedimage.cpp @@ -306,8 +306,9 @@ void QQuickAnimatedImage::load() d->status = Null; emit statusChanged(d->status); - if (sourceSize() != d->oldSourceSize) { - d->oldSourceSize = sourceSize(); + d->currentSourceSize = QSize(0, 0); + if (d->currentSourceSize != d->oldSourceSize) { + d->oldSourceSize = d->currentSourceSize; emit sourceSizeChanged(); } if (isPlaying() != d->oldPlaying) @@ -383,8 +384,9 @@ void QQuickAnimatedImage::movieRequestFinished() d->status = Error; emit statusChanged(d->status); - if (sourceSize() != d->oldSourceSize) { - d->oldSourceSize = sourceSize(); + d->currentSourceSize = QSize(0, 0); + if (d->currentSourceSize != d->oldSourceSize) { + d->oldSourceSize = d->currentSourceSize; emit sourceSizeChanged(); } if (isPlaying() != d->oldPlaying) @@ -421,8 +423,14 @@ void QQuickAnimatedImage::movieRequestFinished() if (isPlaying() != d->oldPlaying) emit playingChanged(); - if (sourceSize() != d->oldSourceSize) { - d->oldSourceSize = sourceSize(); + + if (d->_movie) + d->currentSourceSize = d->_movie->currentPixmap().size(); + else + d->currentSourceSize = QSize(0, 0); + + if (d->currentSourceSize != d->oldSourceSize) { + d->oldSourceSize = d->currentSourceSize; emit sourceSizeChanged(); } } @@ -475,9 +483,7 @@ void QQuickAnimatedImage::onCacheChanged() QSize QQuickAnimatedImage::sourceSize() { Q_D(QQuickAnimatedImage); - if (!d->_movie) - return QSize(0, 0); - return QSize(d->_movie->currentPixmap().size()); + return d->currentSourceSize; } void QQuickAnimatedImage::componentComplete() diff --git a/src/quick/items/qquickanimatedimage_p_p.h b/src/quick/items/qquickanimatedimage_p_p.h index 9b284f966d..ed735d1c9c 100644 --- a/src/quick/items/qquickanimatedimage_p_p.h +++ b/src/quick/items/qquickanimatedimage_p_p.h @@ -72,6 +72,7 @@ public: #ifndef QT_NO_NETWORK , reply(0), redirectCount(0) #endif + , currentSourceSize(0, 0) { } @@ -87,6 +88,7 @@ public: int redirectCount; #endif QMap<int, QQuickPixmap *> frameMap; + QSize currentSourceSize; }; QT_END_NAMESPACE diff --git a/src/quick/items/qquickdrag.cpp b/src/quick/items/qquickdrag.cpp index 4aa54b71df..cc30199253 100644 --- a/src/quick/items/qquickdrag.cpp +++ b/src/quick/items/qquickdrag.cpp @@ -45,6 +45,7 @@ #include <private/qquickitem_p.h> #include <QtQuick/private/qquickevents_p_p.h> #include <private/qquickitemchangelistener_p.h> +#include <private/qquickpixmapcache_p.h> #include <private/qv8engine_p.h> #include <private/qv4scopedvalue_p.h> #include <QtCore/qmimedata.h> @@ -110,6 +111,8 @@ public: bool eventQueued : 1; bool overrideActions : 1; QPointF hotSpot; + QUrl imageSource; + QQuickPixmap pixmapLoader; QStringList keys; QVariantMap externalMimeData; QQuickDrag::DragType dragType; @@ -307,13 +310,14 @@ void QQuickDragAttached::setActive(bool active) else if (active) { if (d->dragType == QQuickDrag::Internal) { d->start(d->supportedActions); - } - else if (d->dragType == QQuickDrag::Automatic) { - // There are different semantics than start() since startDrag() - // may be called after an internal drag is already started. - active = true; + } else { + d->active = true; emit activeChanged(); - d->startDrag(d->supportedActions); + if (d->dragType == QQuickDrag::Automatic) { + // There are different semantics than start() since startDrag() + // may be called after an internal drag is already started. + d->startDrag(d->supportedActions); + } } } else @@ -408,6 +412,43 @@ void QQuickDragAttached::setHotSpot(const QPointF &hotSpot) } /*! + \qmlattachedproperty QUrl QtQuick::Drag::imageSource + \since 5.8 + + This property holds the URL of the image which will be used to represent + the data during the drag and drop operation. Changing this property after + the drag operation has started will have no effect. + + The example below uses an item's contents as a drag image: + + \snippet qml/externaldrag.qml 0 + + \sa Item::grabToImage() +*/ + +QUrl QQuickDragAttached::imageSource() const +{ + Q_D(const QQuickDragAttached); + return d->imageSource; +} + +void QQuickDragAttached::setImageSource(const QUrl &url) +{ + Q_D(QQuickDragAttached); + if (d->imageSource != url) { + d->imageSource = url; + + if (url.isEmpty()) { + d->pixmapLoader.clear(); + } else { + d->pixmapLoader.load(qmlEngine(this), url); + } + + Q_EMIT imageSourceChanged(); + } +} + +/*! \qmlattachedproperty stringlist QtQuick::Drag::keys This property holds a list of keys that can be used by a DropArea to filter drag events. @@ -726,9 +767,9 @@ Qt::DropAction QQuickDragAttachedPrivate::startDrag(Qt::DropActions supportedAct mimeData->setData(it.key(), it.value().toString().toUtf8()); drag->setMimeData(mimeData); - - // TODO: how to handle drag image? - // drag->setPixmap(iconPixmap); + if (pixmapLoader.isReady()) { + drag->setPixmap(QPixmap::fromImage(pixmapLoader.image())); + } emit q->dragStarted(); diff --git a/src/quick/items/qquickdrag_p.h b/src/quick/items/qquickdrag_p.h index c1695e49f0..17721251d9 100644 --- a/src/quick/items/qquickdrag_p.h +++ b/src/quick/items/qquickdrag_p.h @@ -58,6 +58,7 @@ #include <QtCore/qmimedata.h> #include <QtCore/qstringlist.h> +#include <QtCore/qurl.h> #ifndef QT_NO_DRAGANDDROP @@ -247,6 +248,7 @@ class QQuickDragAttached : public QObject Q_PROPERTY(QObject *source READ source WRITE setSource NOTIFY sourceChanged RESET resetSource) Q_PROPERTY(QObject *target READ target NOTIFY targetChanged) Q_PROPERTY(QPointF hotSpot READ hotSpot WRITE setHotSpot NOTIFY hotSpotChanged) + Q_PROPERTY(QUrl imageSource READ imageSource WRITE setImageSource NOTIFY imageSourceChanged REVISION 8) Q_PROPERTY(QStringList keys READ keys WRITE setKeys NOTIFY keysChanged) Q_PROPERTY(QVariantMap mimeData READ mimeData WRITE setMimeData NOTIFY mimeDataChanged) Q_PROPERTY(Qt::DropActions supportedActions READ supportedActions WRITE setSupportedActions NOTIFY supportedActionsChanged) @@ -268,6 +270,9 @@ public: QPointF hotSpot() const; void setHotSpot(const QPointF &hotSpot); + QUrl imageSource() const; + void setImageSource(const QUrl &url); + QStringList keys() const; void setKeys(const QStringList &keys); @@ -300,6 +305,7 @@ Q_SIGNALS: void sourceChanged(); void targetChanged(); void hotSpotChanged(); + void imageSourceChanged(); void keysChanged(); void mimeDataChanged(); void supportedActionsChanged(); diff --git a/src/quick/items/qquickflickable.cpp b/src/quick/items/qquickflickable.cpp index b0245f402b..ae138d7ceb 100644 --- a/src/quick/items/qquickflickable.cpp +++ b/src/quick/items/qquickflickable.cpp @@ -881,6 +881,10 @@ QQuickFlickableVisibleArea *QQuickFlickable::visibleArea() \e contentHeight is not equal to the \e height of the Flickable. Allows flicking horizontally if the \e contentWidth is not equal to the \e width of the Flickable. + \li Flickable.AutoFlickIfNeeded - allows flicking vertically if the + \e contentHeight is greater than the \e height of the Flickable. + Allows flicking horizontally if the \e contentWidth is greater than + to the \e width of the Flickable. \li Flickable.HorizontalFlick - allows flicking horizontally. \li Flickable.VerticalFlick - allows flicking vertically. \li Flickable.HorizontalAndVerticalFlick - allows flicking in both directions. @@ -2167,6 +2171,8 @@ qreal QQuickFlickable::vHeight() const bool QQuickFlickable::xflick() const { Q_D(const QQuickFlickable); + if ((d->flickableDirection & QQuickFlickable::AutoFlickIfNeeded) && (vWidth() > width())) + return true; if (d->flickableDirection == QQuickFlickable::AutoFlickDirection) return std::floor(qAbs(vWidth() - width())); return d->flickableDirection & QQuickFlickable::HorizontalFlick; @@ -2175,6 +2181,8 @@ bool QQuickFlickable::xflick() const bool QQuickFlickable::yflick() const { Q_D(const QQuickFlickable); + if ((d->flickableDirection & QQuickFlickable::AutoFlickIfNeeded) && (vHeight() > height())) + return true; if (d->flickableDirection == QQuickFlickable::AutoFlickDirection) return std::floor(qAbs(vHeight() - height())); return d->flickableDirection & QQuickFlickable::VerticalFlick; diff --git a/src/quick/items/qquickflickable_p.h b/src/quick/items/qquickflickable_p.h index 6cf78dcf63..318b8ce473 100644 --- a/src/quick/items/qquickflickable_p.h +++ b/src/quick/items/qquickflickable_p.h @@ -192,7 +192,8 @@ public: QQuickItem *contentItem(); - enum FlickableDirection { AutoFlickDirection=0x00, HorizontalFlick=0x01, VerticalFlick=0x02, HorizontalAndVerticalFlick=0x03 }; + enum FlickableDirection { AutoFlickDirection=0x0, HorizontalFlick=0x1, VerticalFlick=0x2, HorizontalAndVerticalFlick=0x3, + AutoFlickIfNeeded=0xc }; Q_ENUM(FlickableDirection) FlickableDirection flickableDirection() const; void setFlickableDirection(FlickableDirection); diff --git a/src/quick/items/qquickimage.cpp b/src/quick/items/qquickimage.cpp index 34b8f0ac49..c04a526bd0 100644 --- a/src/quick/items/qquickimage.cpp +++ b/src/quick/items/qquickimage.cpp @@ -714,9 +714,9 @@ QSGNode *QQuickImage::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) sourceRect.height() / nsHeight); if (targetRect.isEmpty() - || !qIsFinite(targetRect.width()) || !qIsFinite(targetRect.height()) + || !qt_is_finite(targetRect.width()) || !qt_is_finite(targetRect.height()) || nsrect.isEmpty() - || !qIsFinite(nsrect.width()) || !qIsFinite(nsrect.height())) { + || !qt_is_finite(nsrect.width()) || !qt_is_finite(nsrect.height())) { delete node; return 0; } diff --git a/src/quick/items/qquickimagebase.cpp b/src/quick/items/qquickimagebase.cpp index 8117baa2fe..60e31631c0 100644 --- a/src/quick/items/qquickimagebase.cpp +++ b/src/quick/items/qquickimagebase.cpp @@ -225,7 +225,7 @@ void QQuickImageBase::load() // sourceSize is set. If sourceSize is not set then the provider default size // will be used, as usual. bool setDevicePixelRatio = false; - if (!d->sourcesize.isValid()) { + if (d->sourcesize.isValid()) { if (loadUrl.scheme() == QLatin1String("image")) { setDevicePixelRatio = true; } else { diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp index 1100b12cbc..d6fdf5795e 100644 --- a/src/quick/items/qquickitem.cpp +++ b/src/quick/items/qquickitem.cpp @@ -1632,7 +1632,7 @@ void QQuickItemPrivate::setLayoutMirror(bool mirror) */ /*! - \qmlproperty enumeration QtQuick::EnterKey::type + \qmlattachedproperty enumeration QtQuick::EnterKey::type Holds the type of the Enter key. @@ -2647,7 +2647,7 @@ void QQuickItem::setParentItem(QQuickItem *parentItem) QQuickItem *scopeItem = 0; - if (hasFocus()) + if (hasFocus() || op->subFocusItem == this) scopeFocusedItem = this; else if (!isFocusScope() && d->subFocusItem) scopeFocusedItem = d->subFocusItem; @@ -3117,7 +3117,6 @@ QQuickItemPrivate::QQuickItemPrivate() , flags(0) , widthValid(false) , heightValid(false) - , baselineOffsetValid(false) , componentComplete(true) , keepMouse(false) , keepTouch(false) @@ -3192,7 +3191,7 @@ void QQuickItemPrivate::init(QQuickItem *parent) registerAccessorProperties(); - baselineOffsetValid = false; + baselineOffset = 0.0; if (parent) { q->setParentItem(parent); @@ -4168,6 +4167,23 @@ QVariant QQuickItem::inputMethodQuery(Qt::InputMethodQuery query) const if (d->extra.isAllocated() && d->extra->enterKeyAttached) v = d->extra->enterKeyAttached->type(); break; + case Qt::ImInputItemClipRectangle: + if (!(!window() ||!isVisible() || qFuzzyIsNull(opacity()))) { + QRectF rect = QRectF(0,0, width(), height()); + const QQuickItem *par = this; + while (QQuickItem *parpar = par->parentItem()) { + rect = parpar->mapRectFromItem(par, rect); + if (parpar->clip()) + rect = rect.intersected(parpar->clipRect()); + par = parpar; + } + rect = par->mapRectToScene(rect); + // once we have the rect in scene coordinates, clip to window + rect = rect.intersected(QRectF(QPoint(0,0), window()->size())); + // map it back to local coordinates + v = mapRectFromScene(rect); + } + break; default: break; } @@ -4179,43 +4195,43 @@ QVariant QQuickItem::inputMethodQuery(Qt::InputMethodQuery query) const QQuickAnchorLine QQuickItemPrivate::left() const { Q_Q(const QQuickItem); - return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchorLine::Left); + return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchors::LeftAnchor); } QQuickAnchorLine QQuickItemPrivate::right() const { Q_Q(const QQuickItem); - return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchorLine::Right); + return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchors::RightAnchor); } QQuickAnchorLine QQuickItemPrivate::horizontalCenter() const { Q_Q(const QQuickItem); - return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchorLine::HCenter); + return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchors::HCenterAnchor); } QQuickAnchorLine QQuickItemPrivate::top() const { Q_Q(const QQuickItem); - return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchorLine::Top); + return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchors::TopAnchor); } QQuickAnchorLine QQuickItemPrivate::bottom() const { Q_Q(const QQuickItem); - return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchorLine::Bottom); + return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchors::BottomAnchor); } QQuickAnchorLine QQuickItemPrivate::verticalCenter() const { Q_Q(const QQuickItem); - return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchorLine::VCenter); + return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchors::VCenterAnchor); } QQuickAnchorLine QQuickItemPrivate::baseline() const { Q_Q(const QQuickItem); - return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchorLine::Baseline); + return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchors::BaselineAnchor); } /*! @@ -4243,11 +4259,7 @@ QQuickAnchorLine QQuickItemPrivate::baseline() const qreal QQuickItem::baselineOffset() const { Q_D(const QQuickItem); - if (d->baselineOffsetValid) { - return d->baselineOffset; - } else { - return 0.0; - } + return d->baselineOffset; } void QQuickItem::setBaselineOffset(qreal offset) @@ -4257,7 +4269,6 @@ void QQuickItem::setBaselineOffset(qreal offset) return; d->baselineOffset = offset; - d->baselineOffsetValid = true; for (int ii = 0; ii < d->changeListeners.count(); ++ii) { const QQuickItemPrivate::ChangeListener &change = d->changeListeners.at(ii); @@ -6253,6 +6264,8 @@ QPointF QQuickItem::position() const void QQuickItem::setX(qreal v) { Q_D(QQuickItem); + if (qIsNaN(v)) + return; if (d->x == v) return; @@ -6268,6 +6281,8 @@ void QQuickItem::setX(qreal v) void QQuickItem::setY(qreal v) { Q_D(QQuickItem); + if (qIsNaN(v)) + return; if (d->y == v) return; diff --git a/src/quick/items/qquickitem_p.h b/src/quick/items/qquickitem_p.h index 46b08b11fb..846063a58b 100644 --- a/src/quick/items/qquickitem_p.h +++ b/src/quick/items/qquickitem_p.h @@ -401,7 +401,6 @@ public: quint32 flags:5; bool widthValid:1; bool heightValid:1; - bool baselineOffsetValid:1; bool componentComplete:1; bool keepMouse:1; bool keepTouch:1; @@ -410,8 +409,8 @@ public: bool antialiasing:1; bool focus:1; bool activeFocus:1; - // Bit 16 bool notifiedFocus:1; + // Bit 16 bool notifiedActiveFocus:1; bool filtersChildMouseEvents:1; bool explicitVisible:1; @@ -427,8 +426,8 @@ public: bool isAccessible:1; bool culled:1; bool hasCursor:1; - // Bit 32 bool hasCursorInChild:1; + // Bit 32 bool hasHoverInChild:1; bool activeFocusOnTab:1; bool implicitAntialiasing:1; diff --git a/src/quick/items/qquickitemgrabresult.cpp b/src/quick/items/qquickitemgrabresult.cpp index f69b5b3f4b..807a2ae304 100644 --- a/src/quick/items/qquickitemgrabresult.cpp +++ b/src/quick/items/qquickitemgrabresult.cpp @@ -59,6 +59,7 @@ class QQuickItemGrabResultPrivate : public QObjectPrivate public: QQuickItemGrabResultPrivate() : cacheEntry(0) + , qmlEngine(0) , texture(0) { } diff --git a/src/quick/items/qquickitemsmodule.cpp b/src/quick/items/qquickitemsmodule.cpp index fb5bc3683f..3ccbf4b140 100644 --- a/src/quick/items/qquickitemsmodule.cpp +++ b/src/quick/items/qquickitemsmodule.cpp @@ -292,6 +292,7 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor) qmlRegisterType<QQuickGridView, 7>(uri, 2, 7, "GridView"); qmlRegisterType<QQuickTextInput, 7>(uri, 2, 7, "TextInput"); qmlRegisterType<QQuickTextEdit, 7>(uri, 2, 7, "TextEdit"); + qmlRegisterType<QQuickPathView, 7>(uri, 2, 7, "PathView"); qmlRegisterUncreatableType<QQuickMouseEvent, 7>(uri, 2, 7, nullptr, QQuickMouseEvent::tr("MouseEvent is only available within handlers in MouseArea")); diff --git a/src/quick/items/qquickopenglshadereffect.cpp b/src/quick/items/qquickopenglshadereffect.cpp index f6f2503cd0..312721ed04 100644 --- a/src/quick/items/qquickopenglshadereffect.cpp +++ b/src/quick/items/qquickopenglshadereffect.cpp @@ -774,7 +774,6 @@ QSGNode *QQuickOpenGLShaderEffect::handleUpdatePaintNode(QSGNode *oldNode, QQuic builder.appendSourceFile(QStringLiteral(":/qt-project.org/items/shaders/shadereffect.vert")); s.sourceCode[Key::VertexShader] = builder.source(); } - s.className = metaObject()->className(); material->setProgramSource(s); material->attributes = m_common.attributes; diff --git a/src/quick/items/qquickopenglshadereffectnode.cpp b/src/quick/items/qquickopenglshadereffectnode.cpp index 864c968505..c4dd8d5c63 100644 --- a/src/quick/items/qquickopenglshadereffectnode.cpp +++ b/src/quick/items/qquickopenglshadereffectnode.cpp @@ -334,8 +334,6 @@ const char *QQuickCustomMaterialShader::fragmentShader() const bool QQuickOpenGLShaderEffectMaterialKey::operator == (const QQuickOpenGLShaderEffectMaterialKey &other) const { - if (className != other.className) - return false; for (int shaderType = 0; shaderType < ShaderTypeCount; ++shaderType) { if (sourceCode[shaderType] != other.sourceCode[shaderType]) return false; @@ -350,7 +348,7 @@ bool QQuickOpenGLShaderEffectMaterialKey::operator != (const QQuickOpenGLShaderE uint qHash(const QQuickOpenGLShaderEffectMaterialKey &key) { - uint hash = qHash((const void *)key.className); + uint hash = 1; typedef QQuickOpenGLShaderEffectMaterialKey Key; for (int shaderType = 0; shaderType < Key::ShaderTypeCount; ++shaderType) hash = hash * 31337 + qHash(key.sourceCode[shaderType]); diff --git a/src/quick/items/qquickopenglshadereffectnode_p.h b/src/quick/items/qquickopenglshadereffectnode_p.h index 1adfa4dd29..adf5ef730b 100644 --- a/src/quick/items/qquickopenglshadereffectnode_p.h +++ b/src/quick/items/qquickopenglshadereffectnode_p.h @@ -72,7 +72,6 @@ struct QQuickOpenGLShaderEffectMaterialKey { }; QByteArray sourceCode[ShaderTypeCount]; - const char *className; bool operator == (const QQuickOpenGLShaderEffectMaterialKey &other) const; bool operator != (const QQuickOpenGLShaderEffectMaterialKey &other) const; diff --git a/src/quick/items/qquickpainteditem.cpp b/src/quick/items/qquickpainteditem.cpp index 5813b4b115..d21eb93dbf 100644 --- a/src/quick/items/qquickpainteditem.cpp +++ b/src/quick/items/qquickpainteditem.cpp @@ -674,4 +674,11 @@ QSGTextureProvider *QQuickPaintedItem::textureProvider() const return d->textureProvider; } +void QQuickPaintedItem::itemChange(ItemChange change, const ItemChangeData &value) +{ + if (change == ItemDevicePixelRatioHasChanged) + update(); + QQuickItem::itemChange(change, value); +} + QT_END_NAMESPACE diff --git a/src/quick/items/qquickpainteditem.h b/src/quick/items/qquickpainteditem.h index f9e3c91a42..e8b471ac01 100644 --- a/src/quick/items/qquickpainteditem.h +++ b/src/quick/items/qquickpainteditem.h @@ -121,6 +121,7 @@ protected: QQuickPaintedItem(QQuickPaintedItemPrivate &dd, QQuickItem *parent = Q_NULLPTR); QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) Q_DECL_OVERRIDE; void releaseResources() Q_DECL_OVERRIDE; + void itemChange(ItemChange, const ItemChangeData &) Q_DECL_OVERRIDE; private Q_SLOTS: void invalidateSceneGraph(); diff --git a/src/quick/items/qquickpathview.cpp b/src/quick/items/qquickpathview.cpp index f0bbb1e732..e3d218ff01 100644 --- a/src/quick/items/qquickpathview.cpp +++ b/src/quick/items/qquickpathview.cpp @@ -105,7 +105,8 @@ QQuickPathViewPrivate::QQuickPathViewPrivate() , dragMargin(0), deceleration(100), maximumFlickVelocity(QML_FLICK_DEFAULTMAXVELOCITY) , moveOffset(this, &QQuickPathViewPrivate::setAdjustedOffset), flickDuration(0) , pathItems(-1), requestedIndex(-1), cacheSize(0), requestedZ(0) - , moveReason(Other), moveDirection(Shortest), attType(0), highlightComponent(0), highlightItem(0) + , moveReason(Other), movementDirection(QQuickPathView::Shortest), moveDirection(QQuickPathView::Shortest) + , attType(0), highlightComponent(0), highlightItem(0) , moveHighlight(this, &QQuickPathViewPrivate::setHighlightPosition) , highlightPosition(0) , highlightRangeStart(0), highlightRangeEnd(0) @@ -790,7 +791,7 @@ QQuickItem *QQuickPathView::currentItem() const void QQuickPathView::incrementCurrentIndex() { Q_D(QQuickPathView); - d->moveDirection = QQuickPathViewPrivate::Positive; + d->moveDirection = QQuickPathView::Positive; setCurrentIndex(currentIndex()+1); } @@ -804,7 +805,7 @@ void QQuickPathView::incrementCurrentIndex() void QQuickPathView::decrementCurrentIndex() { Q_D(QQuickPathView); - d->moveDirection = QQuickPathViewPrivate::Negative; + d->moveDirection = QQuickPathView::Negative; setCurrentIndex(currentIndex()-1); } @@ -1373,6 +1374,48 @@ void QQuickPathView::setSnapMode(SnapMode mode) } /*! + \qmlproperty enumeration QtQuick::PathView::movementDirection + \since 5.7 + + This property determines the direction in which items move when setting the current index. + The possible values are: + + \list + \li PathView.Shortest (default) - the items move in the direction that requires the least + movement, which could be either \c Negative or \c Positive. + \li PathView.Negative - the items move backwards towards their destination. + \li PathView.Positive - the items move forwards towards their destination. + \endlist + + For example, suppose that there are 5 items in the model, and \l currentIndex is \c 0. + If currentIndex is set to \c 2, + + \list + \li a \c Positive movement direction will result in the following order: 0, 1, 2 + \li a \c Negative movement direction will result in the following order: 0, 5, 4, 3, 2 + \li a \c Shortest movement direction will result in same order with \c Positive . + \endlist + + \note this property doesn't affect the movement of \l incrementCurrentIndex() and \l decrementCurrentIndex(). +*/ +QQuickPathView::MovementDirection QQuickPathView::movementDirection() const +{ + Q_D(const QQuickPathView); + return d->movementDirection; +} + +void QQuickPathView::setMovementDirection(QQuickPathView::MovementDirection dir) +{ + Q_D(QQuickPathView); + if (dir == d->movementDirection) + return; + d->movementDirection = dir; + if (!d->tl.isActive()) + d->moveDirection = d->movementDirection; + emit movementDirectionChanged(); +} + +/*! \qmlmethod QtQuick::PathView::positionViewAtIndex(int index, PositionMode mode) Positions the view such that the \a index is at the position specified by @@ -1910,7 +1953,7 @@ void QQuickPathView::refill() if (lcItemViewDelegateLifecycle().isDebugEnabled()) { QQuickText *text = qmlobject_cast<QQuickText*>(item); if (text) - qCDebug(lcItemViewDelegateLifecycle) << "idx" << idx << "@" << pos << ": QQuickText" << text->objectName() << text->text().left(40); + qCDebug(lcItemViewDelegateLifecycle) << "idx" << idx << "@" << pos << ": QQuickText" << text->objectName() << text->text().leftRef(40); else qCDebug(lcItemViewDelegateLifecycle) << "idx" << idx << "@" << pos << ":" << item; } @@ -2231,6 +2274,7 @@ void QQuickPathView::movementEnding() emit movingChanged(); emit movementEnded(); } + d->moveDirection = d->movementDirection; } // find the item closest to the snap position @@ -2340,7 +2384,7 @@ void QQuickPathViewPrivate::snapToIndex(int index, MovementReason reason) if (!duration) { tl.set(moveOffset, targetOffset); - } else if (moveDirection == Positive || (moveDirection == Shortest && targetOffset - offset > modelCount/2.0)) { + } else if (moveDirection == QQuickPathView::Positive || (moveDirection == QQuickPathView::Shortest && targetOffset - offset > modelCount/2.0)) { qreal distance = modelCount - targetOffset + offset; if (targetOffset > moveOffset) { tl.move(moveOffset, 0.0, QEasingCurve(QEasingCurve::InQuad), int(duration * offset / distance)); @@ -2349,7 +2393,7 @@ void QQuickPathViewPrivate::snapToIndex(int index, MovementReason reason) } else { tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InOutQuad), duration); } - } else if (moveDirection == Negative || targetOffset - offset <= -modelCount/2.0) { + } else if (moveDirection == QQuickPathView::Negative || targetOffset - offset <= -modelCount/2.0) { qreal distance = modelCount - offset + targetOffset; if (targetOffset < moveOffset) { tl.move(moveOffset, modelCount, QEasingCurve(targetOffset == 0 ? QEasingCurve::InOutQuad : QEasingCurve::InQuad), int(duration * (modelCount-offset) / distance)); @@ -2361,7 +2405,6 @@ void QQuickPathViewPrivate::snapToIndex(int index, MovementReason reason) } else { tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InOutQuad), duration); } - moveDirection = Shortest; } QQuickPathViewAttached *QQuickPathView::qmlAttachedProperties(QObject *obj) diff --git a/src/quick/items/qquickpathview_p.h b/src/quick/items/qquickpathview_p.h index 341af02013..daec965f02 100644 --- a/src/quick/items/qquickpathview_p.h +++ b/src/quick/items/qquickpathview_p.h @@ -92,6 +92,7 @@ class Q_AUTOTEST_EXPORT QQuickPathView : public QQuickItem Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) Q_PROPERTY(int pathItemCount READ pathItemCount WRITE setPathItemCount RESET resetPathItemCount NOTIFY pathItemCountChanged) Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged) + Q_PROPERTY(MovementDirection movementDirection READ movementDirection WRITE setMovementDirection NOTIFY movementDirectionChanged REVISION 7) Q_PROPERTY(int cacheItemCount READ cacheItemCount WRITE setCacheItemCount NOTIFY cacheItemCountChanged) @@ -164,6 +165,11 @@ public: SnapMode snapMode() const; void setSnapMode(SnapMode mode); + enum MovementDirection { Shortest, Negative, Positive }; + Q_ENUM(MovementDirection) + MovementDirection movementDirection() const; + void setMovementDirection(MovementDirection dir); + enum PositionMode { Beginning, Center, End, Contain=4, SnapPosition }; // 3 == Visible in other views Q_ENUM(PositionMode) Q_INVOKABLE void positionViewAtIndex(int index, int mode); @@ -201,6 +207,7 @@ Q_SIGNALS: void highlightMoveDurationChanged(); void movementStarted(); void movementEnded(); + Q_REVISION(7) void movementDirectionChanged(); void flickStarted(); void flickEnded(); void dragStarted(); diff --git a/src/quick/items/qquickpathview_p_p.h b/src/quick/items/qquickpathview_p_p.h index 8236d9efd2..d9c4baf572 100644 --- a/src/quick/items/qquickpathview_p_p.h +++ b/src/quick/items/qquickpathview_p_p.h @@ -171,8 +171,8 @@ public: QPointer<QQmlInstanceModel> model; QVariant modelVariant; MovementReason moveReason; - enum MovementDirection { Shortest, Negative, Positive }; - MovementDirection moveDirection; + QQuickPathView::MovementDirection movementDirection; // default + QQuickPathView::MovementDirection moveDirection; // next movement QQmlOpenMetaObjectType *attType; QQmlComponent *highlightComponent; QQuickItem *highlightItem; diff --git a/src/quick/items/qquickrectangle.cpp b/src/quick/items/qquickrectangle.cpp index 74ca0f482a..b8c680433e 100644 --- a/src/quick/items/qquickrectangle.cpp +++ b/src/quick/items/qquickrectangle.cpp @@ -44,7 +44,6 @@ #include <private/qsgadaptationlayer_p.h> #include <QtGui/qpixmapcache.h> -#include <QtCore/qstringbuilder.h> #include <QtCore/qmath.h> #include <QtCore/qmetaobject.h> diff --git a/src/quick/items/qquickscalegrid.cpp b/src/quick/items/qquickscalegrid.cpp index f860c08bad..d7a0f1b681 100644 --- a/src/quick/items/qquickscalegrid.cpp +++ b/src/quick/items/qquickscalegrid.cpp @@ -136,39 +136,38 @@ QQuickGridScaledImage::QQuickGridScaledImage(QIODevice *data) if (colonId <= 0) return; - QStringList list; - list.append(line.left(colonId).trimmed()); - list.append(line.mid(colonId+1).trimmed()); - - if (list[0] == QLatin1String("border.left")) - l = list[1].toInt(); - else if (list[0] == QLatin1String("border.right")) - r = list[1].toInt(); - else if (list[0] == QLatin1String("border.top")) - t = list[1].toInt(); - else if (list[0] == QLatin1String("border.bottom")) - b = list[1].toInt(); - else if (list[0] == QLatin1String("source")) - imgFile = list[1]; - else if (list[0] == QLatin1String("horizontalTileRule") || list[0] == QLatin1String("horizontalTileMode")) - _h = stringToRule(list[1]); - else if (list[0] == QLatin1String("verticalTileRule") || list[0] == QLatin1String("verticalTileMode")) - _v = stringToRule(list[1]); + const QStringRef property = line.leftRef(colonId).trimmed(); + QStringRef value = line.midRef(colonId + 1).trimmed(); + + if (property == QLatin1String("border.left")) { + l = value.toInt(); + } else if (property == QLatin1String("border.right")) { + r = value.toInt(); + } else if (property == QLatin1String("border.top")) { + t = value.toInt(); + } else if (property == QLatin1String("border.bottom")) { + b = value.toInt(); + } else if (property == QLatin1String("source")) { + if (value.startsWith(QLatin1Char('"')) && value.endsWith(QLatin1Char('"'))) + value = value.mid(1, value.size() - 2); // remove leading/trailing quotes. + imgFile = value.toString(); + } else if (property == QLatin1String("horizontalTileRule") || property == QLatin1String("horizontalTileMode")) { + _h = stringToRule(value); + } else if (property == QLatin1String("verticalTileRule") || property == QLatin1String("verticalTileMode")) { + _v = stringToRule(value); + } } if (l < 0 || r < 0 || t < 0 || b < 0 || imgFile.isEmpty()) return; _l = l; _r = r; _t = t; _b = b; - _pix = imgFile; - if (_pix.startsWith(QLatin1Char('"')) && _pix.endsWith(QLatin1Char('"'))) - _pix = _pix.mid(1, _pix.size() - 2); // remove leading/trailing quotes. } -QQuickBorderImage::TileMode QQuickGridScaledImage::stringToRule(const QString &s) +QQuickBorderImage::TileMode QQuickGridScaledImage::stringToRule(const QStringRef &s) { - QString string = s; + QStringRef string = s; if (string.startsWith(QLatin1Char('"')) && string.endsWith(QLatin1Char('"'))) string = string.mid(1, string.size() - 2); // remove leading/trailing quotes. diff --git a/src/quick/items/qquickscalegrid_p_p.h b/src/quick/items/qquickscalegrid_p_p.h index a424002dfb..7f6a31a7bd 100644 --- a/src/quick/items/qquickscalegrid_p_p.h +++ b/src/quick/items/qquickscalegrid_p_p.h @@ -116,7 +116,7 @@ public: QString pixmapUrl() const; private: - static QQuickBorderImage::TileMode stringToRule(const QString &); + static QQuickBorderImage::TileMode stringToRule(const QStringRef &); private: int _l; diff --git a/src/quick/items/qquicktext_p.h b/src/quick/items/qquicktext_p.h index 0b35ad5f91..40dbd51f39 100644 --- a/src/quick/items/qquicktext_p.h +++ b/src/quick/items/qquicktext_p.h @@ -254,16 +254,16 @@ Q_SIGNALS: void fontChanged(const QFont &font); void colorChanged(); void linkColorChanged(); - void styleChanged(TextStyle style); + void styleChanged(QQuickText::TextStyle style); void styleColorChanged(); - void horizontalAlignmentChanged(HAlignment alignment); - void verticalAlignmentChanged(VAlignment alignment); + void horizontalAlignmentChanged(QQuickText::HAlignment alignment); + void verticalAlignmentChanged(QQuickText::VAlignment alignment); void wrapModeChanged(); void lineCountChanged(); void truncatedChanged(); void maximumLineCountChanged(); - void textFormatChanged(TextFormat textFormat); - void elideModeChanged(TextElideMode mode); + void textFormatChanged(QQuickText::TextFormat textFormat); + void elideModeChanged(QQuickText::TextElideMode mode); void contentSizeChanged(); void lineHeightChanged(qreal lineHeight); void lineHeightModeChanged(LineHeightMode mode); diff --git a/src/quick/items/qquicktextcontrol.cpp b/src/quick/items/qquicktextcontrol.cpp index 8b6cc221d5..45238e2d0c 100644 --- a/src/quick/items/qquicktextcontrol.cpp +++ b/src/quick/items/qquicktextcontrol.cpp @@ -109,6 +109,7 @@ QQuickTextControlPrivate::QQuickTextControlPrivate() overwriteMode(false), acceptRichText(true), cursorVisible(false), + cursorBlinkingEnabled(false), hasFocus(false), hadSelectionOnMousePress(false), wordSelectionEnabled(false), @@ -463,14 +464,30 @@ void QQuickTextControlPrivate::_q_updateCursorPosChanged(const QTextCursor &some void QQuickTextControlPrivate::setBlinkingCursorEnabled(bool enable) { - Q_Q(QQuickTextControl); + if (cursorBlinkingEnabled == enable) + return; + + cursorBlinkingEnabled = enable; + updateCursorFlashTime(); - if (enable && QGuiApplication::styleHints()->cursorFlashTime() > 0) - cursorBlinkTimer.start(QGuiApplication::styleHints()->cursorFlashTime() / 2, q); + if (enable) + connect(qApp->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QQuickTextControlPrivate::updateCursorFlashTime); else - cursorBlinkTimer.stop(); + disconnect(qApp->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QQuickTextControlPrivate::updateCursorFlashTime); +} - cursorOn = enable; +void QQuickTextControlPrivate::updateCursorFlashTime() +{ + // Note: cursorOn represents the current blinking state controlled by a timer, and + // should not be confused with cursorVisible or cursorBlinkingEnabled. However, we + // interpretate a cursorFlashTime of 0 to mean "always on, never blink". + cursorOn = true; + int flashTime = QGuiApplication::styleHints()->cursorFlashTime(); + + if (cursorBlinkingEnabled && flashTime >= 2) + cursorBlinkTimer.start(flashTime / 2, q_func()); + else + cursorBlinkTimer.stop(); repaintCursor(); } diff --git a/src/quick/items/qquicktextcontrol_p_p.h b/src/quick/items/qquicktextcontrol_p_p.h index f312fcb1ce..0f78feb5de 100644 --- a/src/quick/items/qquicktextcontrol_p_p.h +++ b/src/quick/items/qquicktextcontrol_p_p.h @@ -97,6 +97,7 @@ public: void _q_updateCursorPosChanged(const QTextCursor &someCursor); void setBlinkingCursorEnabled(bool enable); + void updateCursorFlashTime(); void extendWordwiseSelection(int suggestedNewPosition, qreal mouseXPosition); void extendBlockwiseSelection(int suggestedNewPosition); @@ -156,6 +157,7 @@ public: bool overwriteMode : 1; bool acceptRichText : 1; bool cursorVisible : 1; // used to hide the cursor in the preedit area + bool cursorBlinkingEnabled : 1; bool hasFocus : 1; bool hadSelectionOnMousePress : 1; bool wordSelectionEnabled : 1; diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp index 8bb788d008..36eb5d3cde 100644 --- a/src/quick/items/qquicktextedit.cpp +++ b/src/quick/items/qquicktextedit.cpp @@ -1901,6 +1901,9 @@ QVariant QQuickTextEdit::inputMethodQuery(Qt::InputMethodQuery property, QVarian case Qt::ImHints: v = (int)d->effectiveInputMethodHints(); break; + case Qt::ImInputItemClipRectangle: + v = QQuickItem::inputMethodQuery(property); + break; default: if (property == Qt::ImCursorPosition && !argument.isNull()) argument = QVariant(argument.toPointF() - QPointF(d->xoff, d->yoff)); diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index f361d46424..9b7eb4ea4b 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -792,12 +792,8 @@ void QQuickTextInput::setCursorVisible(bool on) d->cursorVisible = on; if (on && isComponentComplete()) QQuickTextUtil::createCursor(d); - if (!d->cursorItem) { - d->setCursorBlinkPeriod(on ? QGuiApplication::styleHints()->cursorFlashTime() : 0); - d->updateType = QQuickTextInputPrivate::UpdatePaintNode; - polish(); - update(); - } + if (!d->cursorItem) + d->updateCursorBlinking(); emit cursorVisibleChanged(d->cursorVisible); } @@ -1858,7 +1854,7 @@ QSGNode *QQuickTextInput::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData node = new QQuickTextNode(this); d->textNode = node; - const bool showCursor = !isReadOnly() && d->cursorItem == 0 && d->cursorVisible && (d->m_blinkStatus || d->m_blinkPeriod == 0); + const bool showCursor = !isReadOnly() && d->cursorItem == 0 && d->cursorVisible && d->m_blinkStatus; if (!d->textLayoutDirty && oldNode != 0) { if (showCursor) @@ -1954,7 +1950,7 @@ QVariant QQuickTextInput::inputMethodQuery(Qt::InputMethodQuery property, QVaria return QVariant(d->m_text.mid(d->m_cursor)); case Qt::ImTextBeforeCursor: if (argument.isValid()) - return QVariant(d->m_text.left(d->m_cursor).right(argument.toInt())); + return QVariant(d->m_text.leftRef(d->m_cursor).right(argument.toInt()).toString()); return QVariant(d->m_text.left(d->m_cursor)); default: return QQuickItem::inputMethodQuery(property); @@ -2594,8 +2590,10 @@ void QQuickTextInputPrivate::handleFocusEvent(QFocusEvent *event) { Q_Q(QQuickTextInput); bool focus = event->gotFocus(); - if (!m_readOnly) + if (!m_readOnly) { q->setCursorVisible(focus); + setBlinkingCursorEnabled(focus); + } if (focus) { q->q_updateAlignment(); #ifndef QT_NO_IM @@ -4295,26 +4293,39 @@ bool QQuickTextInputPrivate::emitCursorPositionChanged() } -void QQuickTextInputPrivate::setCursorBlinkPeriod(int msec) +void QQuickTextInputPrivate::setBlinkingCursorEnabled(bool enable) { - Q_Q(QQuickTextInput); - if (msec == m_blinkPeriod) + if (enable == m_blinkEnabled) return; + + m_blinkEnabled = enable; + updateCursorBlinking(); + + if (enable) + connect(qApp->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QQuickTextInputPrivate::updateCursorBlinking); + else + disconnect(qApp->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QQuickTextInputPrivate::updateCursorBlinking); +} + +void QQuickTextInputPrivate::updateCursorBlinking() +{ + Q_Q(QQuickTextInput); + if (m_blinkTimer) { q->killTimer(m_blinkTimer); - } - if (msec) { - m_blinkTimer = q->startTimer(msec / 2); - m_blinkStatus = 1; - } else { m_blinkTimer = 0; - if (m_blinkStatus == 1) { - updateType = UpdatePaintNode; - q->polish(); - q->update(); - } } - m_blinkPeriod = msec; + + if (m_blinkEnabled && cursorVisible && !cursorItem && !m_readOnly) { + int flashTime = QGuiApplication::styleHints()->cursorFlashTime(); + if (flashTime >= 2) + m_blinkTimer = q->startTimer(flashTime / 2); + } + + m_blinkStatus = 1; + updateType = UpdatePaintNode; + q->polish(); + q->update(); } void QQuickTextInput::timerEvent(QTimerEvent *event) @@ -4351,20 +4362,8 @@ void QQuickTextInputPrivate::processKeyEvent(QKeyEvent* event) return; } - if (m_blinkPeriod > 0) { - if (m_blinkTimer) - q->killTimer(m_blinkTimer); - - m_blinkTimer = q->startTimer(m_blinkPeriod / 2); - - if (m_blinkStatus == 0) { - m_blinkStatus = 1; - - updateType = UpdatePaintNode; - q->polish(); - q->update(); - } - } + if (m_blinkEnabled) + updateCursorBlinking(); if (m_echoMode == QQuickTextInput::PasswordEchoOnEdit && !m_passwordEchoEditing diff --git a/src/quick/items/qquicktextinput_p.h b/src/quick/items/qquicktextinput_p.h index d2dee2c284..d0461f551e 100644 --- a/src/quick/items/qquicktextinput_p.h +++ b/src/quick/items/qquicktextinput_p.h @@ -323,8 +323,8 @@ Q_SIGNALS: void selectionColorChanged(); void selectedTextColorChanged(); void fontChanged(const QFont &font); - void horizontalAlignmentChanged(HAlignment alignment); - void verticalAlignmentChanged(VAlignment alignment); + void horizontalAlignmentChanged(QQuickTextInput::HAlignment alignment); + void verticalAlignmentChanged(QQuickTextInput::VAlignment alignment); void wrapModeChanged(); void readOnlyChanged(bool isReadOnly); void cursorVisibleChanged(bool isCursorVisible); @@ -333,7 +333,7 @@ Q_SIGNALS: void maximumLengthChanged(int maximumLength); void validatorChanged(); void inputMaskChanged(const QString &inputMask); - void echoModeChanged(EchoMode echoMode); + void echoModeChanged(QQuickTextInput::EchoMode echoMode); void passwordCharacterChanged(); Q_REVISION(3) void passwordMaskDelayChanged(int delay); void displayTextChanged(); @@ -341,7 +341,7 @@ Q_SIGNALS: void activeFocusOnPressChanged(bool activeFocusOnPress); void autoScrollChanged(bool autoScroll); void selectByMouseChanged(bool selectByMouse); - void mouseSelectionModeChanged(SelectionMode mode); + void mouseSelectionModeChanged(QQuickTextInput::SelectionMode mode); void persistentSelectionChanged(); void canPasteChanged(); void canUndoChanged(); diff --git a/src/quick/items/qquicktextinput_p_p.h b/src/quick/items/qquicktextinput_p_p.h index e6bd29bf67..93a8778c40 100644 --- a/src/quick/items/qquicktextinput_p_p.h +++ b/src/quick/items/qquicktextinput_p_p.h @@ -107,7 +107,7 @@ public: #ifndef QT_NO_IM , m_preeditCursor(0) #endif - , m_blinkPeriod(0) + , m_blinkEnabled(false) , m_blinkTimer(0) , m_maxLength(32767) , m_lastCursorPos(-1) @@ -243,7 +243,7 @@ public: #ifndef QT_NO_IM int m_preeditCursor; #endif - int m_blinkPeriod; // 0 for non-blinking cursor + bool m_blinkEnabled; int m_blinkTimer; int m_maxLength; int m_lastCursorPos; @@ -309,8 +309,9 @@ public: return !tripleClickTimer.hasExpired(QGuiApplication::styleHints()->mouseDoubleClickInterval()); } - void setNativeCursorEnabled(bool enabled) { - setCursorBlinkPeriod(enabled && cursorVisible ? QGuiApplication::styleHints()->cursorFlashTime() : 0); } + void setNativeCursorEnabled(bool) { + updateCursorBlinking(); + } int nextMaskBlank(int pos) { @@ -445,7 +446,8 @@ public: #endif void processKeyEvent(QKeyEvent* ev); - void setCursorBlinkPeriod(int msec); + void setBlinkingCursorEnabled(bool enable); + void updateCursorBlinking(); void updateLayout(); void updateBaselineOffset(); diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index f38b3e7693..cdde780932 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -102,6 +102,7 @@ void QQuickWindowPrivate::updateFocusItemTransform() QQuickItemPrivate *focusPrivate = QQuickItemPrivate::get(focus); QGuiApplication::inputMethod()->setInputItemTransform(focusPrivate->itemToWindowTransform()); QGuiApplication::inputMethod()->setInputItemRectangle(QRectF(0, 0, focusPrivate->width, focusPrivate->height)); + focus->updateInputMethod(Qt::ImInputItemClipRectangle); } #endif } @@ -260,6 +261,26 @@ void QQuickWindow::focusInEvent(QFocusEvent *ev) d->updateFocusItemTransform(); } +#ifndef QT_NO_IM +static bool transformDirtyOnItemOrAncestor(const QQuickItem *item) +{ + while (item) { + if (QQuickItemPrivate::get(item)->dirtyAttributes & ( + QQuickItemPrivate::TransformOrigin | + QQuickItemPrivate::Transform | + QQuickItemPrivate::BasicTransform | + QQuickItemPrivate::Position | + QQuickItemPrivate::Size | + QQuickItemPrivate::ParentChanged | + QQuickItemPrivate::Clip)) { + return true; + } + item = item->parentItem(); + } + return false; +} +#endif + void QQuickWindowPrivate::polishItems() { // An item can trigger polish on another item, or itself for that matter, @@ -279,7 +300,17 @@ void QQuickWindowPrivate::polishItems() if (recursionSafeguard == 0) qWarning("QQuickWindow: possible QQuickItem::polish() loop"); - updateFocusItemTransform(); +#ifndef QT_NO_IM + if (QQuickItem *focusItem = q_func()->activeFocusItem()) { + // If the current focus item, or any of its anchestors, has changed location + // inside the window, we need inform IM about it. This to ensure that overlays + // such as selection handles will be updated. + const bool isActiveFocusItem = (focusItem == QGuiApplication::focusObject()); + const bool hasImEnabled = focusItem->inputMethodQuery(Qt::ImEnabled).toBool(); + if (isActiveFocusItem && hasImEnabled && transformDirtyOnItemOrAncestor(focusItem)) + updateFocusItemTransform(); + } +#endif } /*! @@ -4083,6 +4114,12 @@ void QQuickWindow::resetOpenGLState() */ /*! + \qmlproperty Item Window::contentItem + \readonly + \brief The invisible root item of the scene. +*/ + +/*! \qmlproperty Qt::ScreenOrientation Window::contentOrientation This is a hint to the window manager in case it needs to display diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp index f277475dbf..5af79747a7 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp @@ -496,11 +496,6 @@ void Updater::visitGeometryNode(Node *n) if (e->batch) renderer->invalidateBatchAndOverlappingRenderOrders(e->batch); } - if (n->dirtyState & QSGNode::DirtyMaterial) { - Element *e = n->element(); - if (e->batch && e->batch->isMaterialCompatible(e) == BatchBreaksOnCompare) - renderer->invalidateBatchAndOverlappingRenderOrders(e->batch); - } } SHADOWNODE_TRAVERSE(n) visitNode(child); @@ -598,13 +593,13 @@ void Element::computeBounds() } bounds.map(*node->matrix()); - if (!qIsFinite(bounds.tl.x) || bounds.tl.x == FLT_MAX) + if (!qt_is_finite(bounds.tl.x) || bounds.tl.x == FLT_MAX) bounds.tl.x = -FLT_MAX; - if (!qIsFinite(bounds.tl.y) || bounds.tl.y == FLT_MAX) + if (!qt_is_finite(bounds.tl.y) || bounds.tl.y == FLT_MAX) bounds.tl.y = -FLT_MAX; - if (!qIsFinite(bounds.br.x) || bounds.br.x == -FLT_MAX) + if (!qt_is_finite(bounds.br.x) || bounds.br.x == -FLT_MAX) bounds.br.x = FLT_MAX; - if (!qIsFinite(bounds.br.y) || bounds.br.y == -FLT_MAX) + if (!qt_is_finite(bounds.br.y) || bounds.br.y == -FLT_MAX) bounds.br.y = FLT_MAX; Q_ASSERT(bounds.tl.x <= bounds.br.x); @@ -1241,7 +1236,10 @@ void Renderer::nodeChanged(QSGNode *node, QSGNode::DirtyState state) if (e->isMaterialBlended != blended) { m_rebuild |= Renderer::FullRebuild; e->isMaterialBlended = blended; - } else if (!e->batch) { + } else if (e->batch) { + if (e->batch->isMaterialCompatible(e) == BatchBreaksOnCompare) + invalidateBatchAndOverlappingRenderOrders(e->batch); + } else { m_rebuild |= Renderer::BuildBatches; } } diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h index c56f15d655..01e517e65b 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h @@ -529,7 +529,7 @@ public: float lastOpacity; }; - ShaderManager(QSGDefaultRenderContext *ctx) : blitProgram(0), visualizeProgram(0), context(ctx) { } + ShaderManager(QSGDefaultRenderContext *ctx) : visualizeProgram(0), blitProgram(0), context(ctx) { } ~ShaderManager() { qDeleteAll(rewrittenShaders); qDeleteAll(stockShaders); @@ -542,11 +542,13 @@ public: Shader *prepareMaterial(QSGMaterial *material); Shader *prepareMaterialNoRewrite(QSGMaterial *material); + QOpenGLShaderProgram *visualizeProgram; + +private: QHash<QSGMaterialType *, Shader *> rewrittenShaders; QHash<QSGMaterialType *, Shader *> stockShaders; QOpenGLShaderProgram *blitProgram; - QOpenGLShaderProgram *visualizeProgram; QSGDefaultRenderContext *context; }; diff --git a/src/quick/scenegraph/util/qsgatlastexture.cpp b/src/quick/scenegraph/util/qsgatlastexture.cpp index 06c4129a33..098a4a666b 100644 --- a/src/quick/scenegraph/util/qsgatlastexture.cpp +++ b/src/quick/scenegraph/util/qsgatlastexture.cpp @@ -128,6 +128,7 @@ Atlas::Atlas(const QSize &size) : m_allocator(size) , m_texture_id(0) , m_size(size) + , m_atlas_transient_image_threshold(0) , m_allocated(false) { @@ -177,6 +178,11 @@ Atlas::Atlas(const QSize &size) m_use_bgra_fallback = qEnvironmentVariableIsSet("QSG_ATLAS_USE_BGRA_FALLBACK"); m_debug_overlay = qEnvironmentVariableIsSet("QSG_ATLAS_OVERLAY"); + + // images smaller than this will retain their QImage. + // by default no images are retained (favoring memory) + // set to a very large value to retain all images (allowing quick removal from the atlas) + m_atlas_transient_image_threshold = qt_sg_envInt("QSG_ATLAS_TRANSIENT_IMAGE_THRESHOLD", 0); } Atlas::~Atlas() @@ -399,7 +405,10 @@ void Atlas::bind(QSGTexture::Filtering filtering) } else { upload(t); } - t->releaseImage(); + const QSize textureSize = t->textureSize(); + if (textureSize.width() > m_atlas_transient_image_threshold || + textureSize.height() > m_atlas_transient_image_threshold) + t->releaseImage(); qCDebug(QSG_LOG_TIME_TEXTURE).nospace() << "atlastexture uploaded in: " << qsg_renderer_timer.elapsed() << "ms (" << t->textureSize().width() << "x" diff --git a/src/quick/scenegraph/util/qsgatlastexture_p.h b/src/quick/scenegraph/util/qsgatlastexture_p.h index da5acb3fea..cd24645fcf 100644 --- a/src/quick/scenegraph/util/qsgatlastexture_p.h +++ b/src/quick/scenegraph/util/qsgatlastexture_p.h @@ -116,6 +116,8 @@ private: uint m_internalFormat; uint m_externalFormat; + int m_atlas_transient_image_threshold; + uint m_allocated : 1; uint m_use_bgra_fallback: 1; diff --git a/src/quick/scenegraph/util/qsgshadersourcebuilder.cpp b/src/quick/scenegraph/util/qsgshadersourcebuilder.cpp index ec1d316f78..caa296451e 100644 --- a/src/quick/scenegraph/util/qsgshadersourcebuilder.cpp +++ b/src/quick/scenegraph/util/qsgshadersourcebuilder.cpp @@ -382,9 +382,9 @@ QString QSGShaderSourceBuilder::resolveShaderPath(const QString &path) const int idx = path.lastIndexOf(QLatin1Char('.')); QString resolvedPath; if (idx != -1) - resolvedPath = path.left(idx) - + QStringLiteral("_core") - + path.right(path.length() - idx); + resolvedPath = path.leftRef(idx) + + QLatin1String("_core") + + path.rightRef(path.length() - idx); return resolvedPath; } } diff --git a/src/quick/util/qquickanimation.cpp b/src/quick/util/qquickanimation.cpp index adf8f600a0..741a583803 100644 --- a/src/quick/util/qquickanimation.cpp +++ b/src/quick/util/qquickanimation.cpp @@ -986,7 +986,7 @@ void QQuickScriptActionPrivate::debugAction(QDebug d, int indentLevel) const QByteArray ind(indentLevel, ' '); QString exprStr = expr.expression(); int endOfFirstLine = exprStr.indexOf('\n'); - d << "\n" << ind.constData() << exprStr.left(endOfFirstLine); + d << "\n" << ind.constData() << exprStr.leftRef(endOfFirstLine); if (endOfFirstLine != -1 && endOfFirstLine < exprStr.length()) d << "..."; } diff --git a/src/quick/util/qquickglobal.cpp b/src/quick/util/qquickglobal.cpp index 4ad6fdd854..7692cc79f9 100644 --- a/src/quick/util/qquickglobal.cpp +++ b/src/quick/util/qquickglobal.cpp @@ -172,8 +172,8 @@ public: int index = s.indexOf(QLatin1Char(',')); bool xGood, yGood; - float xCoord = s.left(index).toFloat(&xGood); - float yCoord = s.mid(index+1).toFloat(&yGood); + float xCoord = s.leftRef(index).toFloat(&xGood); + float yCoord = s.midRef(index + 1).toFloat(&yGood); if (xGood && yGood) { if (ok) *ok = true; @@ -192,9 +192,9 @@ public: int index2 = s.indexOf(QLatin1Char(','), index+1); bool xGood, yGood, zGood; - float xCoord = s.left(index).toFloat(&xGood); - float yCoord = s.mid(index+1, index2-index-1).toFloat(&yGood); - float zCoord = s.mid(index2+1).toFloat(&zGood); + float xCoord = s.leftRef(index).toFloat(&xGood); + float yCoord = s.midRef(index + 1, index2 - index - 1).toFloat(&yGood); + float zCoord = s.midRef(index2 + 1).toFloat(&zGood); if (xGood && yGood && zGood) { if (ok) *ok = true; @@ -214,10 +214,10 @@ public: int index3 = s.indexOf(QLatin1Char(','), index2+1); bool xGood, yGood, zGood, wGood; - float xCoord = s.left(index).toFloat(&xGood); - float yCoord = s.mid(index+1, index2-index-1).toFloat(&yGood); - float zCoord = s.mid(index2+1, index3-index2-1).toFloat(&zGood); - float wCoord = s.mid(index3+1).toFloat(&wGood); + float xCoord = s.leftRef(index).toFloat(&xGood); + float yCoord = s.midRef(index + 1, index2 - index - 1).toFloat(&yGood); + float zCoord = s.midRef(index2 + 1, index3 - index2 - 1).toFloat(&zGood); + float wCoord = s.midRef(index3 + 1).toFloat(&wGood); if (xGood && yGood && zGood && wGood) { if (ok) *ok = true; @@ -257,10 +257,10 @@ public: if (s.count(QLatin1Char(',')) == 15) { float matValues[16]; bool vOK = true; - QString mutableStr = s; + QStringRef mutableStr(&s); for (int i = 0; vOK && i < 16; ++i) { int cidx = mutableStr.indexOf(QLatin1Char(',')); - matValues[i] = mutableStr.leftRef(cidx).toDouble(&vOK); + matValues[i] = mutableStr.left(cidx).toDouble(&vOK); mutableStr = mutableStr.mid(cidx + 1); } diff --git a/src/quick/util/qquickpath_p.h b/src/quick/util/qquickpath_p.h index d554e2156a..e2c99de44e 100644 --- a/src/quick/util/qquickpath_p.h +++ b/src/quick/util/qquickpath_p.h @@ -335,7 +335,7 @@ class Q_AUTOTEST_EXPORT QQuickPathPercent : public QQuickPathElement Q_OBJECT Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged) public: - QQuickPathPercent(QObject *parent=0) : QQuickPathElement(parent) {} + QQuickPathPercent(QObject *parent=0) : QQuickPathElement(parent), _value(0) {} qreal value() const; void setValue(qreal value); diff --git a/src/quick/util/qquickpixmapcache.cpp b/src/quick/util/qquickpixmapcache.cpp index 2b6e8f68c3..597613c9fd 100644 --- a/src/quick/util/qquickpixmapcache.cpp +++ b/src/quick/util/qquickpixmapcache.cpp @@ -455,13 +455,19 @@ QQuickPixmapReader::~QQuickPixmapReader() } jobs.clear(); #ifndef QT_NO_NETWORK - QList<QQuickPixmapReply*> activeJobs = networkJobs.values() + asyncResponses.values(); - foreach (QQuickPixmapReply *reply, activeJobs ) { + + const auto cancelJob = [this](QQuickPixmapReply *reply) { if (reply->loading) { cancelled.append(reply); reply->data = 0; } - } + }; + + for (auto *reply : qAsConst(networkJobs)) + cancelJob(reply); + + for (auto *reply : qAsConst(asyncResponses)) + cancelJob(reply); #endif if (threadObject) threadObject->processJobs(); mutex.unlock(); diff --git a/src/quick/util/qquicksmoothedanimation.cpp b/src/quick/util/qquicksmoothedanimation.cpp index b7eadf5e30..d4956983fb 100644 --- a/src/quick/util/qquicksmoothedanimation.cpp +++ b/src/quick/util/qquicksmoothedanimation.cpp @@ -377,9 +377,8 @@ QQuickSmoothedAnimation::~QQuickSmoothedAnimation() } QQuickSmoothedAnimationPrivate::QQuickSmoothedAnimationPrivate() - : anim(0) + : anim(new QSmoothedAnimation) { - anim = new QSmoothedAnimation; } QQuickSmoothedAnimationPrivate::~QQuickSmoothedAnimationPrivate() diff --git a/src/quick/util/qquickstategroup.cpp b/src/quick/util/qquickstategroup.cpp index 791e38e45d..200f243a1b 100644 --- a/src/quick/util/qquickstategroup.cpp +++ b/src/quick/util/qquickstategroup.cpp @@ -44,9 +44,9 @@ #include <private/qqmlbinding_p.h> #include <private/qqmlglobal_p.h> -#include <QtCore/qstringbuilder.h> #include <QtCore/qstringlist.h> #include <QtCore/qdebug.h> +#include <QtCore/qvector.h> #include <private/qobject_p.h> #include <qqmlinfo.h> @@ -305,7 +305,7 @@ void QQuickStateGroup::componentComplete() for (int ii = 0; ii < d->states.count(); ++ii) { QQuickState *state = d->states.at(ii); if (!state->isNamed()) - state->setName(QLatin1String("anonymousState") % QString::number(++d->unnamedCount)); + state->setName(QLatin1String("anonymousState") + QString::number(++d->unnamedCount)); } if (d->updateAutoState()) { @@ -379,28 +379,29 @@ QQuickTransition *QQuickStateGroupPrivate::findTransition(const QString &from, c (t->fromState() == QLatin1String("*") && t->toState() == QLatin1String("*")))) break; - QStringList fromState; - QStringList toState; + const QString fromStateStr = t->fromState(); + const QString toStateStr = t->toState(); - fromState = t->fromState().split(QLatin1Char(',')); + QVector<QStringRef> fromState = fromStateStr.splitRef(QLatin1Char(',')); for (int jj = 0; jj < fromState.count(); ++jj) fromState[jj] = fromState.at(jj).trimmed(); - toState = t->toState().split(QLatin1Char(',')); + QVector<QStringRef> toState = toStateStr.splitRef(QLatin1Char(',')); for (int jj = 0; jj < toState.count(); ++jj) toState[jj] = toState.at(jj).trimmed(); if (ii == 1) qSwap(fromState, toState); int tScore = 0; - if (fromState.contains(from)) + const QString asterisk = QStringLiteral("*"); + if (fromState.contains(QStringRef(&from))) tScore += 2; - else if (fromState.contains(QLatin1String("*"))) + else if (fromState.contains(QStringRef(&asterisk))) tScore += 1; else continue; - if (toState.contains(to)) + if (toState.contains(QStringRef(&to))) tScore += 2; - else if (toState.contains(QLatin1String("*"))) + else if (toState.contains(QStringRef(&asterisk))) tScore += 1; else continue; |