forked from qt-creator/qt-creator
QmlDesigner: Add remove group action
Task-number: QDS-2228 Change-Id: I4174a51b3de1c7ea82b69b85bef19e62a878aa28 Reviewed-by: Henning Gründl <henning.gruendl@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -83,6 +83,9 @@ const char decreaseIndexOfStackedContainerCommandId[] = "DecreaseIndexOfStackedC
|
||||
const char flowAssignEffectCommandId[] = "AssignFlowEffect";
|
||||
const char flowAssignCustomEffectCommandId[] = "AssignFlowCustomEffect";
|
||||
const char addToGroupItemCommandId[] = "AddToGroupItem";
|
||||
const char removeGroupItemCommandId[] = "RemoveToGroupItem";
|
||||
const char fitRootToScreenCommandId[] = "FitRootToScreen";
|
||||
const char fitSelectionToScreenCommandId[] = "FitSelectionToScreen";
|
||||
|
||||
const char selectionCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Selection");
|
||||
const char flowConnectionCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Connect");
|
||||
@@ -139,6 +142,8 @@ const char setFlowStartDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu
|
||||
const char removeLayoutDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Remove Layout");
|
||||
|
||||
const char addToGroupItemDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Group in GroupItem");
|
||||
const char removeGroupItemDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu",
|
||||
"Remove GroupItem");
|
||||
|
||||
const char addItemToStackedContainerDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Add Item");
|
||||
const char addTabBarToStackedContainerDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Add Tab Bar");
|
||||
|
@@ -660,6 +660,27 @@ bool isStackedContainerAndIndexCanBeIncreased(const SelectionContext &context)
|
||||
return value < maxValue;
|
||||
}
|
||||
|
||||
bool isGroup(const SelectionContext &context)
|
||||
{
|
||||
if (!inBaseState(context))
|
||||
return false;
|
||||
|
||||
if (!singleSelection(context))
|
||||
return false;
|
||||
|
||||
ModelNode currentSelectedNode = context.currentSingleSelectedNode();
|
||||
|
||||
if (!currentSelectedNode.isValid())
|
||||
return false;
|
||||
|
||||
NodeMetaInfo metaInfo = currentSelectedNode.metaInfo();
|
||||
|
||||
if (!metaInfo.isValid())
|
||||
return false;
|
||||
|
||||
return metaInfo.isSubclassOf("QtQuick.Studio.Components.GroupItem");
|
||||
}
|
||||
|
||||
bool isLayout(const SelectionContext &context)
|
||||
{
|
||||
if (!inBaseState(context))
|
||||
@@ -937,11 +958,9 @@ void DesignerActionManager::createDefaultDesignerActions()
|
||||
priorityLayoutCategory,
|
||||
&layoutOptionVisible));
|
||||
|
||||
addDesignerAction(new ActionGroup(
|
||||
groupCategoryDisplayName,
|
||||
addDesignerAction(new ActionGroup(groupCategoryDisplayName,
|
||||
groupCategory,
|
||||
priorityGroupCategory,
|
||||
&positionOptionVisible,
|
||||
&studioComponentsAvailable));
|
||||
|
||||
addDesignerAction(new ActionGroup(
|
||||
@@ -1085,20 +1104,25 @@ void DesignerActionManager::createDefaultDesignerActions()
|
||||
&isLayout,
|
||||
&isLayout));
|
||||
|
||||
addDesignerAction(new ModelNodeContextMenuAction(
|
||||
addToGroupItemCommandId,
|
||||
addDesignerAction(new ModelNodeContextMenuAction(addToGroupItemCommandId,
|
||||
addToGroupItemDisplayName,
|
||||
{},
|
||||
groupCategory,
|
||||
QKeySequence("Ctrl+Shift+g"),
|
||||
110,
|
||||
&addToGroupItem,
|
||||
&selectionCanBeLayouted));
|
||||
|
||||
addDesignerAction(new ModelNodeContextMenuAction(removeGroupItemCommandId,
|
||||
removeGroupItemDisplayName,
|
||||
{},
|
||||
groupCategory,
|
||||
QKeySequence(),
|
||||
110,
|
||||
&addToGroupItem,
|
||||
&selectionCanBeLayouted,
|
||||
&selectionCanBeLayouted));
|
||||
&removeGroup,
|
||||
&isGroup));
|
||||
|
||||
|
||||
addDesignerAction(new ModelNodeFormEditorAction(
|
||||
addItemToStackedContainerCommandId,
|
||||
addDesignerAction(new ModelNodeFormEditorAction(addItemToStackedContainerCommandId,
|
||||
addItemToStackedContainerDisplayName,
|
||||
addIcon.icon(),
|
||||
addItemToStackedContainerToolTip,
|
||||
|
@@ -1482,6 +1482,42 @@ void mergeWithTemplate(const SelectionContext &selectionContext)
|
||||
styleMerge(selectionContext, templateFile);
|
||||
}
|
||||
|
||||
} // namespace Mode
|
||||
void removeGroup(const SelectionContext &selectionContext)
|
||||
{
|
||||
if (!selectionContext.view() || !selectionContext.hasSingleSelectedModelNode())
|
||||
return;
|
||||
|
||||
ModelNode group = selectionContext.currentSingleSelectedNode();
|
||||
|
||||
if (!QmlItemNode::isValidQmlItemNode(group))
|
||||
return;
|
||||
|
||||
QmlItemNode groupItem(group);
|
||||
|
||||
QmlItemNode parent = groupItem.instanceParentItem();
|
||||
|
||||
if (!parent.isValid())
|
||||
return;
|
||||
|
||||
selectionContext.view()->executeInTransaction(
|
||||
"DesignerActionManager::removeGroup", [selectionContext, &groupItem, parent]() {
|
||||
for (const ModelNode &modelNode :
|
||||
selectionContext.currentSingleSelectedNode().directSubModelNodes()) {
|
||||
if (modelNode.isValid()) {
|
||||
QmlItemNode qmlItem(modelNode);
|
||||
|
||||
QPointF pos = qmlItem.instancePosition();
|
||||
pos = groupItem.instanceTransform().map(pos);
|
||||
modelNode.variantProperty("x").setValue(pos.x());
|
||||
modelNode.variantProperty("y").setValue(pos.y());
|
||||
|
||||
parent.modelNode().defaultNodeListProperty().reparentHere(modelNode);
|
||||
}
|
||||
}
|
||||
groupItem.destroy();
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace ModelNodeOperations
|
||||
|
||||
} //QmlDesigner
|
||||
|
@@ -82,6 +82,7 @@ void setFlowStartItem(const SelectionContext &selectionContext);
|
||||
void addToGroupItem(const SelectionContext &selectionContext);
|
||||
void selectFlowEffect(const SelectionContext &selectionContext);
|
||||
void mergeWithTemplate(const SelectionContext &selectionContext);
|
||||
void removeGroup(const SelectionContext &selectionContext);
|
||||
|
||||
} // namespace ModelNodeOperationso
|
||||
} //QmlDesigner
|
||||
|
Reference in New Issue
Block a user