aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-11-08 01:00:09 +0100
committerFabian Kosmale <fabian.kosmale@qt.io>2019-11-08 08:16:27 +0100
commit53db1ef8d6a40484a1fc8633b2bad9fb2405c08a (patch)
treefd922515894c0c0c6c565bb6dad655b62d84cd90 /src
parent8e380f6199df1cbaf5d88d929e648a5368f6e0ef (diff)
parent210f4271e8946c0da0cefff0c07af80081df20f1 (diff)
Merge remote-tracking branch 'origin/5.15' into dev
Conflicts: tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp Change-Id: I1c0c7c44053bf3d5f8f9723662bd0fe67253c8ae
Diffstat (limited to 'src')
-rw-r--r--src/imports/layouts/qquicklinearlayout.cpp6
-rw-r--r--src/qml/qml/qqmlengine.cpp6
-rw-r--r--src/qml/qml/qqmlmetatype.cpp4
-rw-r--r--src/qml/qml/qqmlmetatype_p.h2
-rw-r--r--src/qml/qml/qqmlmetatypedata.cpp7
-rw-r--r--src/qml/qml/qqmlmetatypedata_p.h2
-rw-r--r--src/qml/qml/qqmlnotifier.cpp4
-rw-r--r--src/qml/qml/qqmlproperty.cpp12
-rw-r--r--src/qml/qml/qqmltypeloader.cpp3
-rw-r--r--src/quick/items/qquickanimatedsprite.cpp29
-rw-r--r--src/quick/items/qquickdrag.cpp2
-rw-r--r--src/quick/items/qquickevents.cpp8
-rw-r--r--src/quick/items/qquickitem.cpp22
-rw-r--r--src/quick/items/qquickitemview.cpp34
-rw-r--r--src/quick/items/qquickitemview_p_p.h2
-rw-r--r--src/quick/items/qquickloader.cpp3
-rw-r--r--src/quick/items/qquicktext.cpp79
-rw-r--r--src/quick/items/qquicktext_p.h6
-rw-r--r--src/quick/items/qquicktext_p_p.h2
-rw-r--r--src/quickwidgets/qquickwidget.cpp4
20 files changed, 182 insertions, 55 deletions
diff --git a/src/imports/layouts/qquicklinearlayout.cpp b/src/imports/layouts/qquicklinearlayout.cpp
index af7b1b7340..c6c9685ae2 100644
--- a/src/imports/layouts/qquicklinearlayout.cpp
+++ b/src/imports/layouts/qquicklinearlayout.cpp
@@ -283,8 +283,11 @@ Qt::LayoutDirection QQuickGridLayoutBase::layoutDirection() const
void QQuickGridLayoutBase::setLayoutDirection(Qt::LayoutDirection dir)
{
Q_D(QQuickGridLayoutBase);
+ if (d->m_layoutDirection == dir)
+ return;
d->m_layoutDirection = dir;
invalidate();
+ emit layoutDirectionChanged();
}
Qt::LayoutDirection QQuickGridLayoutBase::effectiveLayoutDirection() const
@@ -524,6 +527,7 @@ void QQuickGridLayout::setColumnSpacing(qreal spacing)
d->engine.setSpacing(spacing, Qt::Horizontal);
invalidate();
+ emit columnSpacingChanged();
}
/*!
@@ -546,6 +550,7 @@ void QQuickGridLayout::setRowSpacing(qreal spacing)
d->engine.setSpacing(spacing, Qt::Vertical);
invalidate();
+ emit rowSpacingChanged();
}
/*!
@@ -817,6 +822,7 @@ void QQuickLinearLayout::setSpacing(qreal space)
d->engine.setSpacing(space, Qt::Horizontal | Qt::Vertical);
invalidate();
+ emit spacingChanged();
}
void QQuickLinearLayout::insertLayoutItems()
diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp
index 6e1365ea9f..0bdba313f3 100644
--- a/src/qml/qml/qqmlengine.cpp
+++ b/src/qml/qml/qqmlengine.cpp
@@ -784,9 +784,9 @@ void QQmlData::signalEmitted(QAbstractDeclarativeData *, QObject *object, int in
// marshalled back onto the QObject's thread and handled by QML from there. This is tested
// by the qqmlecmascript::threadSignal() autotest.
if (ddata->notifyList &&
- QThread::currentThreadId() != QObjectPrivate::get(object)->threadData->threadId.loadRelaxed()) {
+ QThread::currentThreadId() != QObjectPrivate::get(object)->getThreadData()->threadId.loadRelaxed()) {
- if (!QObjectPrivate::get(object)->threadData->thread.loadAcquire())
+ if (!QObjectPrivate::get(object)->getThreadData()->thread.loadAcquire())
return;
QMetaMethod m = QMetaObjectPrivate::signal(object->metaObject(), index);
@@ -818,7 +818,7 @@ void QQmlData::signalEmitted(QAbstractDeclarativeData *, QObject *object, int in
QQmlThreadNotifierProxyObject *mpo = new QQmlThreadNotifierProxyObject;
mpo->target = object;
- mpo->moveToThread(QObjectPrivate::get(object)->threadData->thread.loadAcquire());
+ mpo->moveToThread(QObjectPrivate::get(object)->getThreadData()->thread.loadAcquire());
QCoreApplication::postEvent(mpo, ev.take());
} else {
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp
index af43bfc921..b8c17c9374 100644
--- a/src/qml/qml/qqmlmetatype.cpp
+++ b/src/qml/qml/qqmlmetatype.cpp
@@ -278,10 +278,10 @@ void QQmlMetaType::qmlInsertModuleRegistration(const QString &uri, int majorVers
data->moduleTypeRegistrationFunctions.insert(versionedUri, registerFunction);
}
-void QQmlMetaType::qmlRegisterModuleTypes(const QString &uri, int majorVersion)
+bool QQmlMetaType::qmlRegisterModuleTypes(const QString &uri, int majorVersion)
{
QQmlMetaTypeDataPtr data;
- data->registerModuleTypes(QQmlMetaTypeData::VersionedUri(uri, majorVersion));
+ return data->registerModuleTypes(QQmlMetaTypeData::VersionedUri(uri, majorVersion));
}
void QQmlMetaType::clearTypeRegistrations()
diff --git a/src/qml/qml/qqmlmetatype_p.h b/src/qml/qml/qqmlmetatype_p.h
index 146a5ab136..ed4675046d 100644
--- a/src/qml/qml/qqmlmetatype_p.h
+++ b/src/qml/qml/qqmlmetatype_p.h
@@ -200,7 +200,7 @@ public:
static void qmlInsertModuleRegistration(const QString &uri, int majorVersion,
void (*registerFunction)());
- static void qmlRegisterModuleTypes(const QString &uri, int majorVersion);
+ static bool qmlRegisterModuleTypes(const QString &uri, int majorVersion);
};
Q_DECLARE_TYPEINFO(QQmlMetaType, Q_MOVABLE_TYPE);
diff --git a/src/qml/qml/qqmlmetatypedata.cpp b/src/qml/qml/qqmlmetatypedata.cpp
index c2150225c3..ed885eaa97 100644
--- a/src/qml/qml/qqmlmetatypedata.cpp
+++ b/src/qml/qml/qqmlmetatypedata.cpp
@@ -78,11 +78,14 @@ void QQmlMetaTypeData::registerType(QQmlTypePrivate *priv)
priv->release();
}
-void QQmlMetaTypeData::registerModuleTypes(const QQmlMetaTypeData::VersionedUri &versionedUri)
+bool QQmlMetaTypeData::registerModuleTypes(const QQmlMetaTypeData::VersionedUri &versionedUri)
{
auto function = moduleTypeRegistrationFunctions.constFind(versionedUri);
- if (function != moduleTypeRegistrationFunctions.constEnd())
+ if (function != moduleTypeRegistrationFunctions.constEnd()) {
(*function)();
+ return true;
+ }
+ return false;
}
QQmlPropertyCache *QQmlMetaTypeData::propertyCacheForMinorVersion(int index, int minorVersion) const
diff --git a/src/qml/qml/qqmlmetatypedata_p.h b/src/qml/qml/qqmlmetatypedata_p.h
index 755a51a16e..f193e51f5a 100644
--- a/src/qml/qml/qqmlmetatypedata_p.h
+++ b/src/qml/qml/qqmlmetatypedata_p.h
@@ -101,7 +101,7 @@ struct QQmlMetaTypeData
TypeModules uriToModule;
QHash<VersionedUri, void (*)()> moduleTypeRegistrationFunctions;
- void registerModuleTypes(const VersionedUri &versionedUri);
+ bool registerModuleTypes(const VersionedUri &versionedUri);
QBitArray objects;
QBitArray interfaces;
diff --git a/src/qml/qml/qqmlnotifier.cpp b/src/qml/qml/qqmlnotifier.cpp
index 1359586b31..fe839a50dc 100644
--- a/src/qml/qml/qqmlnotifier.cpp
+++ b/src/qml/qml/qqmlnotifier.cpp
@@ -118,8 +118,8 @@ void QQmlNotifierEndpoint::connect(QObject *source, int sourceSignal, QQmlEngine
disconnect();
Q_ASSERT(engine);
- if (QObjectPrivate::get(source)->threadData->threadId.loadRelaxed() !=
- QObjectPrivate::get(engine)->threadData->threadId.loadRelaxed()) {
+ if (QObjectPrivate::get(source)->getThreadData()->threadId.loadRelaxed() !=
+ QObjectPrivate::get(engine)->getThreadData()->threadId.loadRelaxed()) {
QString sourceName;
QDebug(&sourceName) << source;
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp
index 9e6819891c..27667de678 100644
--- a/src/qml/qml/qqmlproperty.cpp
+++ b/src/qml/qml/qqmlproperty.cpp
@@ -63,6 +63,7 @@
#include <private/qqmlvaluetypewrapper_p.h>
#include <QtCore/qdebug.h>
#include <cmath>
+#include <QtQml/QQmlPropertyMap>
Q_DECLARE_METATYPE(QList<int>)
Q_DECLARE_METATYPE(QList<qreal>)
@@ -331,10 +332,15 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name)
return;
} else {
- if (!property->isQObject())
- return; // Not an object property
+ if (!property->isQObject()) {
+ if (auto asPropertyMap = qobject_cast<QQmlPropertyMap*>(currentObject))
+ currentObject = asPropertyMap->value(path.at(ii).toString()).value<QObject*>();
+ else
+ return; // Not an object property, and not a property map
+ } else {
+ property->readProperty(currentObject, &currentObject);
+ }
- property->readProperty(currentObject, &currentObject);
if (!currentObject) return; // No value
}
diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp
index c2870396b0..b164f5873c 100644
--- a/src/qml/qml/qqmltypeloader.cpp
+++ b/src/qml/qml/qqmltypeloader.cpp
@@ -598,7 +598,8 @@ bool QQmlTypeLoader::Blob::addImport(QQmlTypeLoader::Blob::PendingImportPtr impo
}
} else {
// Is this a module?
- if (QQmlMetaType::isAnyModule(import->uri)) {
+ if (QQmlMetaType::isAnyModule(import->uri)
+ || QQmlMetaType::qmlRegisterModuleTypes(import->uri, import->majorVersion)) {
if (!m_importCache.addLibraryImport(importDatabase, import->uri, import->qualifier, import->majorVersion,
import->minorVersion, QString(), QString(), false, errors))
return false;
diff --git a/src/quick/items/qquickanimatedsprite.cpp b/src/quick/items/qquickanimatedsprite.cpp
index d22e77c8ad..21c09f898d 100644
--- a/src/quick/items/qquickanimatedsprite.cpp
+++ b/src/quick/items/qquickanimatedsprite.cpp
@@ -395,20 +395,34 @@ void QQuickAnimatedSprite::reloadImage()
void QQuickAnimatedSprite::componentComplete()
{
- Q_D(const QQuickAnimatedSprite);
+ Q_D(QQuickAnimatedSprite);
createEngine();
QQuickItem::componentComplete();
- if (d->m_running)
+ if (d->m_running) {
+ d->m_running = false;
start();
+ }
}
+/*!
+ \qmlmethod QtQuick::AnimatedSprite::start()
+ \since 5.15
+
+ Starts the sprite animation. If the animation is already running, calling
+ this method has no effect.
+
+ \sa stop()
+*/
void QQuickAnimatedSprite::start()
{
Q_D(QQuickAnimatedSprite);
+ if (d->m_running)
+ return;
d->m_running = true;
if (!isComponentComplete())
return;
d->m_curLoop = 0;
+ d->m_curFrame = 0;
d->m_timestamp.start();
if (d->m_spriteEngine) {
d->m_spriteEngine->stop(0);
@@ -420,9 +434,20 @@ void QQuickAnimatedSprite::start()
maybeUpdate();
}
+/*!
+ \qmlmethod QtQuick::AnimatedSprite::stop()
+ \since 5.15
+
+ Stops the sprite animation. If the animation is not running, calling this
+ method has no effect.
+
+ \sa start()
+*/
void QQuickAnimatedSprite::stop()
{
Q_D(QQuickAnimatedSprite);
+ if (!d->m_running)
+ return;
d->m_running = false;
if (!isComponentComplete())
return;
diff --git a/src/quick/items/qquickdrag.cpp b/src/quick/items/qquickdrag.cpp
index ff4d9b0fd1..737b7ffe24 100644
--- a/src/quick/items/qquickdrag.cpp
+++ b/src/quick/items/qquickdrag.cpp
@@ -442,7 +442,7 @@ void QQuickDragAttached::setImageSource(const QUrl &url)
if (url.isEmpty()) {
d->pixmapLoader.clear();
} else {
- d->pixmapLoader.load(qmlEngine(this), url);
+ d->pixmapLoader.load(qmlEngine(parent()), url);
}
Q_EMIT imageSourceChanged();
diff --git a/src/quick/items/qquickevents.cpp b/src/quick/items/qquickevents.cpp
index f2d419da31..89340dd992 100644
--- a/src/quick/items/qquickevents.cpp
+++ b/src/quick/items/qquickevents.cpp
@@ -1942,6 +1942,10 @@ Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug dbg, const QQuickPointerEvent *e
{
QDebugStateSaver saver(dbg);
dbg.nospace();
+ if (!event) {
+ dbg << "QQuickPointerEvent(0)";
+ return dbg;
+ }
dbg << "QQuickPointerEvent(";
dbg << event->timestamp();
dbg << " dev:";
@@ -1962,6 +1966,10 @@ Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug dbg, const QQuickEventPoint *eve
{
QDebugStateSaver saver(dbg);
dbg.nospace();
+ if (!event) {
+ dbg << "QQuickEventPoint(0)";
+ return dbg;
+ }
dbg << "QQuickEventPoint(accepted:" << event->isAccepted()
<< " state:";
QtDebugUtils::formatQEnum(dbg, event->state());
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index c6a19219ff..4c20b7e2e1 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -2748,22 +2748,36 @@ void QQuickItem::setParentItem(QQuickItem *parentItem)
}
QQuickWindow *parentWindow = parentItem ? QQuickItemPrivate::get(parentItem)->window : nullptr;
+ bool alreadyAddedChild = false;
if (d->window == parentWindow) {
// Avoid freeing and reallocating resources if the window stays the same.
d->parentItem = parentItem;
} else {
- if (d->window)
- d->derefWindow();
+ auto oldParentItem = d->parentItem;
d->parentItem = parentItem;
+ if (d->parentItem) {
+ QQuickItemPrivate::get(d->parentItem)->addChild(this);
+ alreadyAddedChild = true;
+ }
+ if (d->window) {
+ d->derefWindow();
+ // as we potentially changed d->parentWindow above
+ // the check in derefWindow could not work
+ // thus, we redo it here with the old parent
+ // Also, the window may have been deleted by derefWindow()
+ if (!oldParentItem && d->window) {
+ QQuickWindowPrivate::get(d->window)->parentlessItems.remove(this);
+ }
+ }
if (parentWindow)
d->refWindow(parentWindow);
}
d->dirty(QQuickItemPrivate::ParentChanged);
- if (d->parentItem)
+ if (d->parentItem && !alreadyAddedChild)
QQuickItemPrivate::get(d->parentItem)->addChild(this);
- else if (d->window)
+ else if (d->window && !alreadyAddedChild)
QQuickWindowPrivate::get(d->window)->parentlessItems.insert(this);
d->setEffectiveVisibleRecur(d->calcEffectiveVisible());
diff --git a/src/quick/items/qquickitemview.cpp b/src/quick/items/qquickitemview.cpp
index fccd467274..661f19509a 100644
--- a/src/quick/items/qquickitemview.cpp
+++ b/src/quick/items/qquickitemview.cpp
@@ -1581,9 +1581,7 @@ FxViewItem *QQuickItemViewPrivate::visibleItem(int modelIndex) const {
return nullptr;
}
-// should rename to firstItemInView() to avoid confusion with other "*visible*" methods
-// that don't look at the view position and size
-FxViewItem *QQuickItemViewPrivate::firstVisibleItem() const {
+FxViewItem *QQuickItemViewPrivate::firstItemInView() const {
const qreal pos = isContentFlowReversed() ? -position()-size() : position();
for (FxViewItem *item : visibleItems) {
if (item->index != -1 && item->endPosition() > pos)
@@ -1955,22 +1953,22 @@ bool QQuickItemViewPrivate::applyModelChanges(ChangeResult *totalInsertionResult
bool viewportChanged = !currentChanges.pendingChanges.removes().isEmpty()
|| !currentChanges.pendingChanges.inserts().isEmpty();
- FxViewItem *prevFirstVisible = firstVisibleItem();
- QQmlNullableValue<qreal> prevViewPos;
- int prevFirstVisibleIndex = -1;
- if (prevFirstVisible) {
- prevViewPos = prevFirstVisible->position();
- prevFirstVisibleIndex = prevFirstVisible->index;
+ FxViewItem *prevFirstItemInView = firstItemInView();
+ QQmlNullableValue<qreal> prevFirstItemInViewPos;
+ int prevFirstItemInViewIndex = -1;
+ if (prevFirstItemInView) {
+ prevFirstItemInViewPos = prevFirstItemInView->position();
+ prevFirstItemInViewIndex = prevFirstItemInView->index;
}
qreal prevVisibleItemsFirstPos = visibleItems.count() ? visibleItems.constFirst()->position() : 0.0;
- totalInsertionResult->visiblePos = prevViewPos;
- totalRemovalResult->visiblePos = prevViewPos;
+ totalInsertionResult->visiblePos = prevFirstItemInViewPos;
+ totalRemovalResult->visiblePos = prevFirstItemInViewPos;
const QVector<QQmlChangeSet::Change> &removals = currentChanges.pendingChanges.removes();
const QVector<QQmlChangeSet::Change> &insertions = currentChanges.pendingChanges.inserts();
- ChangeResult insertionResult(prevViewPos);
- ChangeResult removalResult(prevViewPos);
+ ChangeResult insertionResult(prevFirstItemInViewPos);
+ ChangeResult removalResult(prevFirstItemInViewPos);
int removedCount = 0;
for (const QQmlChangeSet::Change &r : removals) {
@@ -1979,7 +1977,7 @@ bool QQuickItemViewPrivate::applyModelChanges(ChangeResult *totalInsertionResult
visibleAffected = true;
if (!visibleAffected && needsRefillForAddedOrRemovedIndex(r.index))
visibleAffected = true;
- const int correctedFirstVisibleIndex = prevFirstVisibleIndex - removalResult.countChangeBeforeVisible;
+ const int correctedFirstVisibleIndex = prevFirstItemInViewIndex - removalResult.countChangeBeforeVisible;
if (correctedFirstVisibleIndex >= 0 && r.index < correctedFirstVisibleIndex) {
if (r.index + r.count < correctedFirstVisibleIndex)
removalResult.countChangeBeforeVisible += r.count;
@@ -2006,7 +2004,7 @@ bool QQuickItemViewPrivate::applyModelChanges(ChangeResult *totalInsertionResult
// set positions correctly for the next insertion
if (!insertions.isEmpty()) {
- repositionFirstItem(prevVisibleItemsFirst, prevVisibleItemsFirstPos, prevFirstVisible, &insertionResult, &removalResult);
+ repositionFirstItem(prevVisibleItemsFirst, prevVisibleItemsFirstPos, prevFirstItemInView, &insertionResult, &removalResult);
layoutVisibleItems(removals.first().index);
}
}
@@ -2026,7 +2024,7 @@ bool QQuickItemViewPrivate::applyModelChanges(ChangeResult *totalInsertionResult
// set positions correctly for the next insertion
if (i < insertions.count() - 1) {
- repositionFirstItem(prevVisibleItemsFirst, prevVisibleItemsFirstPos, prevFirstVisible, &insertionResult, &removalResult);
+ repositionFirstItem(prevVisibleItemsFirst, prevVisibleItemsFirstPos, prevFirstItemInView, &insertionResult, &removalResult);
layoutVisibleItems(insertions[i].index);
}
itemCount += insertions[i].count;
@@ -2043,7 +2041,7 @@ bool QQuickItemViewPrivate::applyModelChanges(ChangeResult *totalInsertionResult
for (const MovedItem &m : qAsConst(movingIntoView)) {
int fromIndex = findMoveKeyIndex(m.moveKey, removals);
if (fromIndex >= 0) {
- if (prevFirstVisibleIndex >= 0 && fromIndex < prevFirstVisibleIndex)
+ if (prevFirstItemInViewIndex >= 0 && fromIndex < prevFirstItemInViewIndex)
repositionItemAt(m.item, fromIndex, -totalInsertionResult->sizeChangesAfterVisiblePos);
else
repositionItemAt(m.item, fromIndex, totalInsertionResult->sizeChangesAfterVisiblePos);
@@ -2054,7 +2052,7 @@ bool QQuickItemViewPrivate::applyModelChanges(ChangeResult *totalInsertionResult
// reposition visibleItems.first() correctly so that the content y doesn't jump
if (removedCount != prevVisibleItemsCount)
- repositionFirstItem(prevVisibleItemsFirst, prevVisibleItemsFirstPos, prevFirstVisible, &insertionResult, &removalResult);
+ repositionFirstItem(prevVisibleItemsFirst, prevVisibleItemsFirstPos, prevFirstItemInView, &insertionResult, &removalResult);
// Whatever removed/moved items remain are no longer visible items.
prepareRemoveTransitions(&currentChanges.removedItems);
diff --git a/src/quick/items/qquickitemview_p_p.h b/src/quick/items/qquickitemview_p_p.h
index 860cf5fa20..6442fee27d 100644
--- a/src/quick/items/qquickitemview_p_p.h
+++ b/src/quick/items/qquickitemview_p_p.h
@@ -158,7 +158,7 @@ public:
qreal contentStartOffset() const;
int findLastVisibleIndex(int defaultValue = -1) const;
FxViewItem *visibleItem(int modelIndex) const;
- FxViewItem *firstVisibleItem() const;
+ FxViewItem *firstItemInView() const;
int findLastIndexInView() const;
int mapFromModel(int modelIndex) const;
diff --git a/src/quick/items/qquickloader.cpp b/src/quick/items/qquickloader.cpp
index 819a3a73e3..8722a45373 100644
--- a/src/quick/items/qquickloader.cpp
+++ b/src/quick/items/qquickloader.cpp
@@ -591,8 +591,8 @@ void QQuickLoader::setSource(QQmlV4Function *args)
d->clear();
QUrl sourceUrl = d->resolveSourceUrl(args);
+ d->disposeInitialPropertyValues();
if (!ipv->isUndefined()) {
- d->disposeInitialPropertyValues();
d->initialPropertyValues.set(args->v4engine(), ipv);
}
d->qmlCallingContext.set(scope.engine, scope.engine->qmlContext());
@@ -602,6 +602,7 @@ void QQuickLoader::setSource(QQmlV4Function *args)
void QQuickLoaderPrivate::disposeInitialPropertyValues()
{
+ initialPropertyValues.clear();
}
void QQuickLoaderPrivate::load()
diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp
index ae849aeb4b..31df4fdff3 100644
--- a/src/quick/items/qquicktext.cpp
+++ b/src/quick/items/qquicktext.cpp
@@ -517,6 +517,11 @@ void QQuickTextLine::setLineOffset(int offset)
m_lineOffset = offset;
}
+void QQuickTextLine::setFullLayoutTextLength(int length)
+{
+ m_fullLayoutTextLength = length;
+}
+
int QQuickTextLine::number() const
{
if (m_line)
@@ -524,6 +529,24 @@ int QQuickTextLine::number() const
return 0;
}
+qreal QQuickTextLine::implicitWidth() const
+{
+ if (m_line)
+ return m_line->naturalTextWidth();
+ return 0;
+}
+
+bool QQuickTextLine::isLast() const
+{
+ if (m_line && (m_line->textStart() + m_line->textLength()) == m_fullLayoutTextLength) {
+ // Ensure that isLast will change if the user reduced the width of the line
+ // so that the text no longer fits.
+ return m_line->width() >= m_line->naturalTextWidth();
+ }
+
+ return false;
+}
+
qreal QQuickTextLine::width() const
{
if (m_line)
@@ -585,12 +608,13 @@ bool QQuickTextPrivate::isLineLaidOutConnected()
IS_SIGNAL_CONNECTED(q, QQuickText, lineLaidOut, (QQuickTextLine *));
}
-void QQuickTextPrivate::setupCustomLineGeometry(QTextLine &line, qreal &height, int lineOffset)
+void QQuickTextPrivate::setupCustomLineGeometry(QTextLine &line, qreal &height, int fullLayoutTextLength, int lineOffset)
{
Q_Q(QQuickText);
if (!textLine)
textLine = new QQuickTextLine;
+ textLine->setFullLayoutTextLength(fullLayoutTextLength);
textLine->setLine(&line);
textLine->setY(height);
textLine->setHeight(0);
@@ -790,7 +814,7 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const baseline)
if (noBreakLastLine && visibleCount == maxLineCount)
layout.engine()->option.setWrapMode(QTextOption::WrapAnywhere);
if (customLayout) {
- setupCustomLineGeometry(line, naturalHeight);
+ setupCustomLineGeometry(line, naturalHeight, layoutText.length());
} else {
setLineGeometry(line, lineWidth, naturalHeight);
}
@@ -1128,7 +1152,7 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const baseline)
QTextLine elidedLine = elideLayout->createLine();
elidedLine.setPosition(QPointF(0, height));
if (customLayout) {
- setupCustomLineGeometry(elidedLine, height, visibleCount - 1);
+ setupCustomLineGeometry(elidedLine, height, elideText.length(), visibleCount - 1);
} else {
setLineGeometry(elidedLine, lineWidth, height);
}
@@ -1335,20 +1359,43 @@ QQuickText::~QQuickText()
\qmlsignal QtQuick::Text::lineLaidOut(object line)
This signal is emitted for each line of text that is laid out during the layout
- process. The specified \a line object provides more details about the line that
+ process in plain text or styled text mode. It is not emitted in rich text mode.
+ The specified \a line object provides more details about the line that
is currently being laid out.
This gives the opportunity to position and resize a line as it is being laid out.
It can for example be used to create columns or lay out text around objects.
The properties of the specified \a line object are:
- \list
- \li number (read-only)
- \li x
- \li y
- \li width
- \li height
- \endlist
+
+ \table
+ \header
+ \li Property name
+ \li Description
+ \row
+ \li number (read-only)
+ \li Line number, starts with zero.
+ \row
+ \li x
+ \li Specifies the line's x position inside the \c Text element.
+ \row
+ \li y
+ \li Specifies the line's y position inside the \c Text element.
+ \row
+ \li width
+ \li Specifies the width of the line.
+ \row
+ \li height
+ \li Specifies the height of the line.
+ \row
+ \li implicitWidth (read-only)
+ \li The width that the line would naturally occupy based on its contents,
+ not taking into account any modifications made to \a width.
+ \row
+ \li isLast (read-only)
+ \li Whether the line is the last. This property can change if you
+ set the \a width property to a different value.
+ \endtable
For example, this will move the first 5 lines of a Text item by 100 pixels to the right:
\code
@@ -1360,6 +1407,16 @@ QQuickText::~QQuickText()
}
\endcode
+ The following example will allow you to position an item at the end of the last line:
+ \code
+ onLineLaidOut: {
+ if (line.isLast) {
+ lastLineMarker.x = line.x + line.implicitWidth
+ lastLineMarker.y = line.y + (line.height - lastLineMarker.height) / 2
+ }
+ }
+ \endcode
+
The corresponding handler is \c onLineLaidOut.
*/
diff --git a/src/quick/items/qquicktext_p.h b/src/quick/items/qquicktext_p.h
index 394ea25b83..d310db508e 100644
--- a/src/quick/items/qquicktext_p.h
+++ b/src/quick/items/qquicktext_p.h
@@ -330,6 +330,8 @@ class QQuickTextLine : public QObject
Q_PROPERTY(qreal height READ height WRITE setHeight)
Q_PROPERTY(qreal x READ x WRITE setX)
Q_PROPERTY(qreal y READ y WRITE setY)
+ Q_PROPERTY(qreal implicitWidth READ implicitWidth)
+ Q_PROPERTY(bool isLast READ isLast)
QML_ANONYMOUS
public:
@@ -337,7 +339,10 @@ public:
void setLine(QTextLine* line);
void setLineOffset(int offset);
+ void setFullLayoutTextLength(int length);
int number() const;
+ qreal implicitWidth() const;
+ bool isLast() const;
qreal width() const;
void setWidth(qreal width);
@@ -355,6 +360,7 @@ private:
QTextLine *m_line;
qreal m_height;
int m_lineOffset;
+ int m_fullLayoutTextLength;
};
QT_END_NAMESPACE
diff --git a/src/quick/items/qquicktext_p_p.h b/src/quick/items/qquicktext_p_p.h
index c01998b100..1fbf942130 100644
--- a/src/quick/items/qquicktext_p_p.h
+++ b/src/quick/items/qquicktext_p_p.h
@@ -195,7 +195,7 @@ public:
void ensureDoc();
QRectF setupTextLayout(qreal * const baseline);
- void setupCustomLineGeometry(QTextLine &line, qreal &height, int lineOffset = 0);
+ void setupCustomLineGeometry(QTextLine &line, qreal &height, int fullLayoutTextLength, int lineOffset = 0);
bool isLinkActivatedConnected();
bool isLinkHoveredConnected();
static QString anchorAt(const QTextLayout *layout, const QPointF &mousePos);
diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp
index 4d2914ff6c..3854a8bd0b 100644
--- a/src/quickwidgets/qquickwidget.cpp
+++ b/src/quickwidgets/qquickwidget.cpp
@@ -885,7 +885,9 @@ void QQuickWidgetPrivate::createContext()
context = new QOpenGLContext;
context->setFormat(offscreenWindow->requestedFormat());
-
+ const QWindow *win = q->window()->windowHandle();
+ if (win && win->screen())
+ context->setScreen(win->screen());
QOpenGLContext *shareContext = qt_gl_global_share_context();
if (!shareContext)
shareContext = QWidgetPrivate::get(q->window())->shareContext();