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 flowAssignEffectCommandId[] = "AssignFlowEffect";
|
||||||
const char flowAssignCustomEffectCommandId[] = "AssignFlowCustomEffect";
|
const char flowAssignCustomEffectCommandId[] = "AssignFlowCustomEffect";
|
||||||
const char addToGroupItemCommandId[] = "AddToGroupItem";
|
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 selectionCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Selection");
|
||||||
const char flowConnectionCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Connect");
|
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 removeLayoutDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Remove Layout");
|
||||||
|
|
||||||
const char addToGroupItemDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Group in GroupItem");
|
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 addItemToStackedContainerDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Add Item");
|
||||||
const char addTabBarToStackedContainerDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Add Tab Bar");
|
const char addTabBarToStackedContainerDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Add Tab Bar");
|
||||||
|
@@ -660,6 +660,27 @@ bool isStackedContainerAndIndexCanBeIncreased(const SelectionContext &context)
|
|||||||
return value < maxValue;
|
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)
|
bool isLayout(const SelectionContext &context)
|
||||||
{
|
{
|
||||||
if (!inBaseState(context))
|
if (!inBaseState(context))
|
||||||
@@ -937,12 +958,10 @@ void DesignerActionManager::createDefaultDesignerActions()
|
|||||||
priorityLayoutCategory,
|
priorityLayoutCategory,
|
||||||
&layoutOptionVisible));
|
&layoutOptionVisible));
|
||||||
|
|
||||||
addDesignerAction(new ActionGroup(
|
addDesignerAction(new ActionGroup(groupCategoryDisplayName,
|
||||||
groupCategoryDisplayName,
|
groupCategory,
|
||||||
groupCategory,
|
priorityGroupCategory,
|
||||||
priorityGroupCategory,
|
&studioComponentsAvailable));
|
||||||
&positionOptionVisible,
|
|
||||||
&studioComponentsAvailable));
|
|
||||||
|
|
||||||
addDesignerAction(new ActionGroup(
|
addDesignerAction(new ActionGroup(
|
||||||
flowCategoryDisplayName,
|
flowCategoryDisplayName,
|
||||||
@@ -1085,29 +1104,34 @@ void DesignerActionManager::createDefaultDesignerActions()
|
|||||||
&isLayout,
|
&isLayout,
|
||||||
&isLayout));
|
&isLayout));
|
||||||
|
|
||||||
addDesignerAction(new ModelNodeContextMenuAction(
|
addDesignerAction(new ModelNodeContextMenuAction(addToGroupItemCommandId,
|
||||||
addToGroupItemCommandId,
|
addToGroupItemDisplayName,
|
||||||
addToGroupItemDisplayName,
|
{},
|
||||||
{},
|
groupCategory,
|
||||||
groupCategory,
|
QKeySequence("Ctrl+Shift+g"),
|
||||||
QKeySequence(),
|
110,
|
||||||
110,
|
&addToGroupItem,
|
||||||
&addToGroupItem,
|
&selectionCanBeLayouted));
|
||||||
&selectionCanBeLayouted,
|
|
||||||
&selectionCanBeLayouted));
|
|
||||||
|
|
||||||
|
addDesignerAction(new ModelNodeContextMenuAction(removeGroupItemCommandId,
|
||||||
|
removeGroupItemDisplayName,
|
||||||
|
{},
|
||||||
|
groupCategory,
|
||||||
|
QKeySequence(),
|
||||||
|
110,
|
||||||
|
&removeGroup,
|
||||||
|
&isGroup));
|
||||||
|
|
||||||
addDesignerAction(new ModelNodeFormEditorAction(
|
addDesignerAction(new ModelNodeFormEditorAction(addItemToStackedContainerCommandId,
|
||||||
addItemToStackedContainerCommandId,
|
addItemToStackedContainerDisplayName,
|
||||||
addItemToStackedContainerDisplayName,
|
addIcon.icon(),
|
||||||
addIcon.icon(),
|
addItemToStackedContainerToolTip,
|
||||||
addItemToStackedContainerToolTip,
|
stackedContainerCategory,
|
||||||
stackedContainerCategory,
|
QKeySequence("Ctrl+Shift+a"),
|
||||||
QKeySequence("Ctrl+Shift+a"),
|
110,
|
||||||
110,
|
&addItemToStackedContainer,
|
||||||
&addItemToStackedContainer,
|
&isStackedContainer,
|
||||||
&isStackedContainer,
|
&isStackedContainer));
|
||||||
&isStackedContainer));
|
|
||||||
|
|
||||||
addDesignerAction(new ModelNodeContextMenuAction(
|
addDesignerAction(new ModelNodeContextMenuAction(
|
||||||
addTabBarToStackedContainerCommandId,
|
addTabBarToStackedContainerCommandId,
|
||||||
|
@@ -1482,6 +1482,42 @@ void mergeWithTemplate(const SelectionContext &selectionContext)
|
|||||||
styleMerge(selectionContext, templateFile);
|
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
|
} //QmlDesigner
|
||||||
|
@@ -82,6 +82,7 @@ void setFlowStartItem(const SelectionContext &selectionContext);
|
|||||||
void addToGroupItem(const SelectionContext &selectionContext);
|
void addToGroupItem(const SelectionContext &selectionContext);
|
||||||
void selectFlowEffect(const SelectionContext &selectionContext);
|
void selectFlowEffect(const SelectionContext &selectionContext);
|
||||||
void mergeWithTemplate(const SelectionContext &selectionContext);
|
void mergeWithTemplate(const SelectionContext &selectionContext);
|
||||||
|
void removeGroup(const SelectionContext &selectionContext);
|
||||||
|
|
||||||
} // namespace ModelNodeOperationso
|
} // namespace ModelNodeOperationso
|
||||||
} //QmlDesigner
|
} //QmlDesigner
|
||||||
|
Reference in New Issue
Block a user