forked from qt-creator/qt-creator
Subject: QmlDesigner: prefer visible items when selecting
Ensure nearestFormEditorItem() returns a visible FormEditorItem before considering selection weight. Items without visual content (e.g. MouseArea) remain treated as visible. other refactorings: - Remove redundant qmlItemNode.isValid() guard – helpers validate internally or its not necessary - Early-continue when FormEditorItem is nullptr for clarity. - Compare a single isVisible flag instead of nested if chains. Task-number: QDS-14210 Change-Id: I772586c24b6cd61ef00add6633815b5d9b43b666 Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
committed by
Tim Jenssen
parent
0bc56fec30
commit
d07de22660
@@ -204,30 +204,40 @@ FormEditorItem *AbstractFormEditorTool::topMovableFormEditorItem(const QList<QGr
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
FormEditorItem* AbstractFormEditorTool::nearestFormEditorItem(const QPointF &point, const QList<QGraphicsItem*> &itemList)
|
FormEditorItem *AbstractFormEditorTool::nearestFormEditorItem(const QPointF &point,
|
||||||
|
const QList<QGraphicsItem *> &itemList)
|
||||||
{
|
{
|
||||||
NanotraceHR::Tracer tracer{"abstract form editor tool nearest form editor item", category()};
|
NanotraceHR::Tracer tracer{"abstract form editor tool nearest form editor item", category()};
|
||||||
|
|
||||||
FormEditorItem *nearestItem = nullptr;
|
FormEditorItem *nearestItem = nullptr;
|
||||||
|
|
||||||
for (QGraphicsItem *item : itemList) {
|
for (QGraphicsItem *item : itemList) {
|
||||||
FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item);
|
auto formEditorItem = FormEditorItem::fromQGraphicsItem(item);
|
||||||
|
if (!formEditorItem)
|
||||||
if (formEditorItem && formEditorItem->flowHitTest(point))
|
|
||||||
return formEditorItem;
|
|
||||||
|
|
||||||
if (!formEditorItem || !formEditorItem->qmlItemNode().isValid())
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (formEditorItem->flowHitTest(point))
|
||||||
|
return formEditorItem;
|
||||||
|
|
||||||
if (formEditorItem->parentItem() && !formEditorItem->parentItem()->isContentVisible())
|
if (formEditorItem->parentItem() && !formEditorItem->parentItem()->isContentVisible())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (formEditorItem && ModelUtils::isThisOrAncestorLocked(formEditorItem->qmlItemNode().modelNode()))
|
auto qmlItemNode = formEditorItem->qmlItemNode();
|
||||||
|
if (ModelUtils::isThisOrAncestorLocked(qmlItemNode.modelNode()))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!nearestItem)
|
if (!nearestItem) {
|
||||||
nearestItem = formEditorItem;
|
nearestItem = formEditorItem;
|
||||||
else if (formEditorItem->selectionWeigth(point, 1) < nearestItem->selectionWeigth(point, 0))
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isVisible = qmlItemNode.instanceIsVisible();
|
||||||
|
if (isVisible != nearestItem->qmlItemNode().instanceIsVisible()) {
|
||||||
|
if (isVisible)
|
||||||
nearestItem = formEditorItem;
|
nearestItem = formEditorItem;
|
||||||
|
} else if (formEditorItem->selectionWeigth(point, 1) < nearestItem->selectionWeigth(point, 0)) {
|
||||||
|
nearestItem = formEditorItem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nearestItem && nearestItem->qmlItemNode().isInStackedContainer())
|
if (nearestItem && nearestItem->qmlItemNode().isInStackedContainer())
|
||||||
|
Reference in New Issue
Block a user