DesignerActionManager: relax anchor fill condition

The anchor fill parent action is now always available (unless the
anchor.fill property is already defined), to be consistent with the
property editor behavior.

Task-number: QDS-10434
Change-Id: Iedd0c3f0cb1131626fbd1c7b29a01ca86a971c0b
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Rafal Stawarski
2025-02-06 12:43:26 +01:00
committed by Thomas Hartmann
parent 88dd120ee5
commit 0a2b613183
5 changed files with 36 additions and 9 deletions

View File

@@ -1112,6 +1112,12 @@ bool singleSelectionItemIsNotAnchoredAndSingleSelectionNotRoot(const SelectionCo
&& singleSelectionNotRoot(context);
}
bool singleSelectionItemHasNoFillAnchorAndSingleSelectionNotRoot(const SelectionContext &context)
{
return singleSelection(context) && !singleSelectionItemHasAnchor(context, AnchorLineFill)
&& singleSelectionNotRoot(context);
}
bool selectionNotEmptyAndHasXorYProperty(const SelectionContext &context)
{
return selectionNotEmpty(context)
@@ -1536,7 +1542,7 @@ void DesignerActionManager::createDefaultDesignerActions()
QKeySequence(QKeySequence("shift+f")),
2,
&anchorsFill,
&singleSelectionItemIsNotAnchoredAndSingleSelectionNotRoot));
&singleSelectionItemHasNoFillAnchorAndSingleSelectionNotRoot));
addDesignerAction(new ModelNodeAction(
anchorsResetCommandId,

View File

@@ -68,6 +68,16 @@ bool singleSelectionItemIsNotAnchored(const SelectionContext &selectionState)
return false;
}
bool singleSelectionItemHasAnchor(const SelectionContext &selectionState, AnchorLineType anchor)
{
QmlItemNode itemNode(selectionState.currentSingleSelectedNode());
if (selectionState.isInBaseState() && itemNode.isValid()) {
bool hasAnchor = itemNode.instanceHasAnchor(anchor);
return hasAnchor;
}
return false;
}
bool selectionHasSameParent(const SelectionContext &selectionState)
{
return !selectionState.selectedModelNodes().isEmpty() && itemsHaveSameParent(selectionState.selectedModelNodes());

View File

@@ -178,6 +178,7 @@ bool selectionIsEditableComponent(const SelectionContext &selectionState);
bool singleSelectionItemIsAnchored(const SelectionContext &selectionState);
bool singleSelectionItemIsNotAnchored(const SelectionContext &selectionState);
bool selectionIsImported3DAsset(const SelectionContext &selectionState);
bool singleSelectionItemHasAnchor(const SelectionContext &selectionState, AnchorLineType anchor);
} // namespace SelectionStateFunctors

View File

@@ -398,6 +398,11 @@ void anchorsFill(const SelectionContext &selectionState)
backupPropertyAndRemove(modelNode, "y");
backupPropertyAndRemove(modelNode, "width");
backupPropertyAndRemove(modelNode, "height");
node.anchors().removeMargin(AnchorLineRight);
node.anchors().removeMargin(AnchorLineLeft);
node.anchors().removeMargin(AnchorLineTop);
node.anchors().removeMargin(AnchorLineBottom);
}
});
}

View File

@@ -325,6 +325,11 @@ bool QmlItemNode::hasResources() const
return !resources().isEmpty();
}
bool QmlItemNode::instanceHasAnchor(AnchorLineType sourceAnchorLineType) const
{
return anchors().instanceHasAnchor(sourceAnchorLineType);
}
bool QmlItemNode::instanceHasAnchors() const
{
return anchors().instanceHasAnchors();