Commit 724db926 authored by Marco Bubke's avatar Marco Bubke
Browse files

QmlDesigner: reuse code from AbstractFormEditorTool



Change-Id: I84ece6344cde0841f489f959cad6ec1f13e7fabc
Reviewed-by: default avatarTim Jenssen <tim.jenssen@digia.com>
parent 25a6a811
......@@ -281,11 +281,10 @@ FormEditorItem *AbstractFormEditorTool::containerFormEditorItem(const QList<QGra
foreach (QGraphicsItem* item, itemUnderMouseList) {
FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item);
if (formEditorItem
&& !selectedItemList.contains(formEditorItem)
&& isNotAncestorOfItemInList(formEditorItem, selectedItemList)
&& formEditorItem->isContainer())
return formEditorItem;
&& !selectedItemList.contains(formEditorItem)
&& isNotAncestorOfItemInList(formEditorItem, selectedItemList)
&& formEditorItem->isContainer())
return formEditorItem;
}
return 0;
......
......@@ -170,22 +170,14 @@ static inline bool isAncestorOf(FormEditorItem *formEditorItem, FormEditorItem *
return false;
}
FormEditorItem* DragTool::calculateTargetContainer(const QList<QGraphicsItem*> &itemList, FormEditorItem * currentItem)
{
foreach (QGraphicsItem *item, itemList) {
FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item);
if (formEditorItem
&& formEditorItem != currentItem
&& formEditorItem->isContainer()
&& !formEditorItem->qmlItemNode().modelNode().metaInfo().isLayoutable()
&& !isAncestorOf(currentItem, formEditorItem))
return formEditorItem;
}
FormEditorItem* DragTool::targetContainerOrRootItem(const QList<QGraphicsItem*> &itemList, FormEditorItem * currentItem)
{
FormEditorItem *formEditorItem = containerFormEditorItem(itemList, QList<FormEditorItem*>() << currentItem);
if (scene()->rootFormEditorItem())
return scene()->rootFormEditorItem();
if (!formEditorItem)
formEditorItem = scene()->rootFormEditorItem();
return 0;
return formEditorItem;
}
void DragTool::formEditorItemsChanged(const QList<FormEditorItem*> & itemList)
......@@ -323,7 +315,7 @@ static QString libraryResourceImageName(const QMimeData *mimeData)
void DragTool::createDragNode(const QMimeData *mimeData, const QPointF &scenePosition, const QList<QGraphicsItem*> &itemList)
{
if (!m_dragNode.hasModelNode()) {
FormEditorItem *targetContainerFormEditorItem = calculateTargetContainer(itemList);
FormEditorItem *targetContainerFormEditorItem = targetContainerOrRootItem(itemList);
if (targetContainerFormEditorItem) {
QmlItemNode targetContainerQmlItemNode;
if (targetContainerFormEditorItem)
......@@ -348,7 +340,7 @@ void DragTool::dragMoveEvent(const QList<QGraphicsItem*> &itemList, QGraphicsSce
if (canHandleMimeData(event->mimeData())) {
event->accept();
if (m_dragNode.isValid()) {
FormEditorItem *targetContainerItem = calculateTargetContainer(itemList);
FormEditorItem *targetContainerItem = targetContainerOrRootItem(itemList);
if (targetContainerItem) {
move(event->scenePos(), itemList);
} else {
......@@ -380,7 +372,7 @@ void DragTool::end(Snapper::Snapping useSnapping)
void DragTool::move(const QPointF &scenePos, const QList<QGraphicsItem*> &itemList)
{
if (m_movingItem) {
FormEditorItem *containerItem = calculateTargetContainer(itemList, m_movingItem.data());
FormEditorItem *containerItem = targetContainerOrRootItem(itemList, m_movingItem.data());
if (containerItem && m_movingItem->parentItem() &&
containerItem != m_movingItem->parentItem()) {
......
......@@ -103,7 +103,7 @@ protected:
void abort();
void createQmlItemNode(const ItemLibraryEntry &itemLibraryEntry, const QmlItemNode &parentNode, const QPointF &scenePos);
void createQmlItemNodeFromImage(const QString &imageName, const QmlItemNode &parentNode, const QPointF &scenePos);
FormEditorItem *calculateTargetContainer(const QList<QGraphicsItem*> &itemList, FormEditorItem *urrentItem = 0);
FormEditorItem *targetContainerOrRootItem(const QList<QGraphicsItem*> &itemList, FormEditorItem *urrentItem = 0);
void begin(QPointF scenePos);
void end();
void end(Snapper::Snapping useSnapping);
......
......@@ -426,7 +426,7 @@ bool FormEditorItem::isContainer() const
NodeMetaInfo nodeMetaInfo = qmlItemNode().modelNode().metaInfo();
if (nodeMetaInfo.isValid())
return !nodeMetaInfo.defaultPropertyIsComponent();
return !nodeMetaInfo.defaultPropertyIsComponent() && !nodeMetaInfo.isLayoutable();
return true;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment