Commit e5b9ff2e authored by Marco Bubke's avatar Marco Bubke
Browse files

QmlDesigner: Use AbstractView instead of QmlModelView



Change-Id: I12ad584f8cdc8decb3fd4489a8b8ec820ff2be91
Reviewed-by: default avatarTim Jenssen <tim.jenssen@digia.com>
parent ff96f520
...@@ -338,7 +338,7 @@ public: ...@@ -338,7 +338,7 @@ public:
m_menu->addAction(selectionAction); m_menu->addAction(selectionAction);
} }
foreach (const ModelNode &node, m_selectionContext.qmlModelView()->allModelNodes()) { foreach (const ModelNode &node, m_selectionContext.view()->allModelNodes()) {
if (node != m_selectionContext.currentSingleSelectedNode() if (node != m_selectionContext.currentSingleSelectedNode()
&& node != parentNode && node != parentNode
&& contains(node, m_selectionContext.scenePos()) && contains(node, m_selectionContext.scenePos())
...@@ -413,9 +413,9 @@ bool selectionCanBeLayouted(const SelectionContext &context) ...@@ -413,9 +413,9 @@ bool selectionCanBeLayouted(const SelectionContext &context)
bool hasQtQuickLayoutImport(const SelectionContext &context) bool hasQtQuickLayoutImport(const SelectionContext &context)
{ {
if (context.qmlModelView() && context.qmlModelView()->model()) { if (context.view() && context.view()->model()) {
Import import = Import::createLibraryImport(QLatin1String("QtQuick.Layouts"), QLatin1String("1.0")); Import import = Import::createLibraryImport(QLatin1String("QtQuick.Layouts"), QLatin1String("1.0"));
return context.qmlModelView()->model()->hasImport(import, true, true); return context.view()->model()->hasImport(import, true, true);
} }
return false; return false;
......
...@@ -116,19 +116,19 @@ void goIntoComponent(const ModelNode &modelNode) ...@@ -116,19 +116,19 @@ void goIntoComponent(const ModelNode &modelNode)
void select(const SelectionContext &selectionState) void select(const SelectionContext &selectionState)
{ {
if (selectionState.qmlModelView()) if (selectionState.view())
selectionState.qmlModelView()->setSelectedModelNodes(QList<ModelNode>() << selectionState.targetNode()); selectionState.view()->setSelectedModelNodes(QList<ModelNode>() << selectionState.targetNode());
} }
void deSelect(const SelectionContext &selectionState) void deSelect(const SelectionContext &selectionState)
{ {
if (selectionState.qmlModelView()) { if (selectionState.view()) {
QList<ModelNode> selectedNodes = selectionState.qmlModelView()->selectedModelNodes(); QList<ModelNode> selectedNodes = selectionState.view()->selectedModelNodes();
foreach (const ModelNode &node, selectionState.selectedModelNodes()) { foreach (const ModelNode &node, selectionState.selectedModelNodes()) {
if (selectedNodes.contains(node)) if (selectedNodes.contains(node))
selectedNodes.removeAll(node); selectedNodes.removeAll(node);
} }
selectionState.qmlModelView()->setSelectedModelNodes(selectedNodes); selectionState.view()->setSelectedModelNodes(selectedNodes);
} }
} }
...@@ -147,7 +147,7 @@ void deleteSelection(const SelectionContext &) ...@@ -147,7 +147,7 @@ void deleteSelection(const SelectionContext &)
void toFront(const SelectionContext &selectionState) void toFront(const SelectionContext &selectionState)
{ {
if (!selectionState.qmlModelView()) if (!selectionState.view())
return; return;
try { try {
...@@ -165,7 +165,7 @@ void toFront(const SelectionContext &selectionState) ...@@ -165,7 +165,7 @@ void toFront(const SelectionContext &selectionState)
void toBack(const SelectionContext &selectionState) void toBack(const SelectionContext &selectionState)
{ {
if (!selectionState.qmlModelView()) if (!selectionState.view())
return; return;
try { try {
QmlItemNode node = selectionState.selectedModelNodes().first(); QmlItemNode node = selectionState.selectedModelNodes().first();
...@@ -182,11 +182,11 @@ void toBack(const SelectionContext &selectionState) ...@@ -182,11 +182,11 @@ void toBack(const SelectionContext &selectionState)
void raise(const SelectionContext &selectionState) void raise(const SelectionContext &selectionState)
{ {
if (!selectionState.qmlModelView()) if (!selectionState.view())
return; return;
try { try {
RewriterTransaction transaction(selectionState.qmlModelView()); RewriterTransaction transaction(selectionState.view());
foreach (ModelNode modelNode, selectionState.selectedModelNodes()) { foreach (ModelNode modelNode, selectionState.selectedModelNodes()) {
QmlItemNode node = modelNode; QmlItemNode node = modelNode;
if (node.isValid()) { if (node.isValid()) {
...@@ -203,11 +203,11 @@ void raise(const SelectionContext &selectionState) ...@@ -203,11 +203,11 @@ void raise(const SelectionContext &selectionState)
void lower(const SelectionContext &selectionState) void lower(const SelectionContext &selectionState)
{ {
if (!selectionState.qmlModelView()) if (!selectionState.view())
return; return;
try { try {
RewriterTransaction transaction(selectionState.qmlModelView()); RewriterTransaction transaction(selectionState.view());
foreach (ModelNode modelNode, selectionState.selectedModelNodes()) { foreach (ModelNode modelNode, selectionState.selectedModelNodes()) {
QmlItemNode node = modelNode; QmlItemNode node = modelNode;
if (node.isValid()) { if (node.isValid()) {
...@@ -235,7 +235,7 @@ void redo(const SelectionContext &) ...@@ -235,7 +235,7 @@ void redo(const SelectionContext &)
void setVisible(const SelectionContext &selectionState) void setVisible(const SelectionContext &selectionState)
{ {
if (!selectionState.qmlModelView()) if (!selectionState.view())
return; return;
try { try {
...@@ -247,7 +247,7 @@ void setVisible(const SelectionContext &selectionState) ...@@ -247,7 +247,7 @@ void setVisible(const SelectionContext &selectionState)
void setFillWidth(const SelectionContext &selectionState) void setFillWidth(const SelectionContext &selectionState)
{ {
if (!selectionState.qmlModelView() if (!selectionState.view()
|| selectionState.selectedModelNodes().isEmpty()) || selectionState.selectedModelNodes().isEmpty())
return; return;
...@@ -260,7 +260,7 @@ void setFillWidth(const SelectionContext &selectionState) ...@@ -260,7 +260,7 @@ void setFillWidth(const SelectionContext &selectionState)
void setFillHeight(const SelectionContext &selectionState) void setFillHeight(const SelectionContext &selectionState)
{ {
if (!selectionState.qmlModelView() if (!selectionState.view()
|| selectionState.selectedModelNodes().isEmpty()) || selectionState.selectedModelNodes().isEmpty())
return; return;
...@@ -273,11 +273,11 @@ void setFillHeight(const SelectionContext &selectionState) ...@@ -273,11 +273,11 @@ void setFillHeight(const SelectionContext &selectionState)
void resetSize(const SelectionContext &selectionState) void resetSize(const SelectionContext &selectionState)
{ {
if (!selectionState.qmlModelView()) if (!selectionState.view())
return; return;
try { try {
RewriterTransaction transaction(selectionState.qmlModelView()); RewriterTransaction transaction(selectionState.view());
foreach (ModelNode node, selectionState.selectedModelNodes()) { foreach (ModelNode node, selectionState.selectedModelNodes()) {
node.removeProperty("width"); node.removeProperty("width");
node.removeProperty("height"); node.removeProperty("height");
...@@ -289,11 +289,11 @@ void resetSize(const SelectionContext &selectionState) ...@@ -289,11 +289,11 @@ void resetSize(const SelectionContext &selectionState)
void resetPosition(const SelectionContext &selectionState) void resetPosition(const SelectionContext &selectionState)
{ {
if (!selectionState.qmlModelView()) if (!selectionState.view())
return; return;
try { try {
RewriterTransaction transaction(selectionState.qmlModelView()); RewriterTransaction transaction(selectionState.view());
foreach (ModelNode node, selectionState.selectedModelNodes()) { foreach (ModelNode node, selectionState.selectedModelNodes()) {
node.removeProperty("x"); node.removeProperty("x");
node.removeProperty("y"); node.removeProperty("y");
...@@ -314,10 +314,10 @@ void setId(const SelectionContext &) ...@@ -314,10 +314,10 @@ void setId(const SelectionContext &)
void resetZ(const SelectionContext &selectionState) void resetZ(const SelectionContext &selectionState)
{ {
if (!selectionState.qmlModelView()) if (!selectionState.view())
return; return;
RewriterTransaction transaction(selectionState.qmlModelView()); RewriterTransaction transaction(selectionState.view());
foreach (ModelNode node, selectionState.selectedModelNodes()) { foreach (ModelNode node, selectionState.selectedModelNodes()) {
node.removeProperty("z"); node.removeProperty("z");
} }
...@@ -345,10 +345,10 @@ static inline void restoreProperty(ModelNode node, const PropertyName &propertyN ...@@ -345,10 +345,10 @@ static inline void restoreProperty(ModelNode node, const PropertyName &propertyN
void anchorsFill(const SelectionContext &selectionState) void anchorsFill(const SelectionContext &selectionState)
{ {
if (!selectionState.qmlModelView()) if (!selectionState.view())
return; return;
RewriterTransaction transaction(selectionState.qmlModelView()); RewriterTransaction transaction(selectionState.view());
ModelNode modelNode = selectionState.currentSingleSelectedNode(); ModelNode modelNode = selectionState.currentSingleSelectedNode();
...@@ -364,10 +364,10 @@ void anchorsFill(const SelectionContext &selectionState) ...@@ -364,10 +364,10 @@ void anchorsFill(const SelectionContext &selectionState)
void anchorsReset(const SelectionContext &selectionState) void anchorsReset(const SelectionContext &selectionState)
{ {
if (!selectionState.qmlModelView()) if (!selectionState.view())
return; return;
RewriterTransaction transaction(selectionState.qmlModelView()); RewriterTransaction transaction(selectionState.view());
ModelNode modelNode = selectionState.currentSingleSelectedNode(); ModelNode modelNode = selectionState.currentSingleSelectedNode();
...@@ -447,10 +447,10 @@ static inline QPoint getUpperLeftPosition(const QList<ModelNode> &modelNodeList) ...@@ -447,10 +447,10 @@ static inline QPoint getUpperLeftPosition(const QList<ModelNode> &modelNodeList)
void layoutRowPositioner(const SelectionContext &selectionState) void layoutRowPositioner(const SelectionContext &selectionState)
{ {
if (!selectionState.qmlModelView()) if (!selectionState.view())
return; return;
NodeMetaInfo rowMetaInfo = selectionState.qmlModelView()->model()->metaInfo("QtQuick.Row"); NodeMetaInfo rowMetaInfo = selectionState.view()->model()->metaInfo("QtQuick.Row");
if (!rowMetaInfo.isValid()) if (!rowMetaInfo.isValid())
return; return;
...@@ -459,7 +459,7 @@ void layoutRowPositioner(const SelectionContext &selectionState) ...@@ -459,7 +459,7 @@ void layoutRowPositioner(const SelectionContext &selectionState)
ModelNode row; ModelNode row;
{ {
RewriterTransaction transaction(selectionState.qmlModelView()); RewriterTransaction transaction(selectionState.view());
QmlItemNode parent = QmlItemNode(modelNodeList.first()).instanceParent().toQmlItemNode(); QmlItemNode parent = QmlItemNode(modelNodeList.first()).instanceParent().toQmlItemNode();
if (!parent.isValid()) if (!parent.isValid())
...@@ -467,13 +467,13 @@ void layoutRowPositioner(const SelectionContext &selectionState) ...@@ -467,13 +467,13 @@ void layoutRowPositioner(const SelectionContext &selectionState)
qDebug() << parent.modelNode().majorQtQuickVersion(); qDebug() << parent.modelNode().majorQtQuickVersion();
row = selectionState.qmlModelView()->createModelNode("QtQuick.Row", rowMetaInfo.majorVersion(), rowMetaInfo.minorVersion()); row = selectionState.view()->createModelNode("QtQuick.Row", rowMetaInfo.majorVersion(), rowMetaInfo.minorVersion());
reparentTo(row, parent); reparentTo(row, parent);
} }
{ {
RewriterTransaction transaction(selectionState.qmlModelView()); RewriterTransaction transaction(selectionState.view());
QPoint pos = getUpperLeftPosition(modelNodeList); QPoint pos = getUpperLeftPosition(modelNodeList);
row.variantProperty("x") = pos.x(); row.variantProperty("x") = pos.x();
...@@ -492,10 +492,10 @@ void layoutRowPositioner(const SelectionContext &selectionState) ...@@ -492,10 +492,10 @@ void layoutRowPositioner(const SelectionContext &selectionState)
void layoutColumnPositioner(const SelectionContext &selectionState) void layoutColumnPositioner(const SelectionContext &selectionState)
{ {
if (!selectionState.qmlModelView()) if (!selectionState.view())
return; return;
NodeMetaInfo columnMetaInfo = selectionState.qmlModelView()->model()->metaInfo("QtQuick.Column"); NodeMetaInfo columnMetaInfo = selectionState.view()->model()->metaInfo("QtQuick.Column");
if (!columnMetaInfo.isValid()) if (!columnMetaInfo.isValid())
return; return;
...@@ -504,19 +504,19 @@ void layoutColumnPositioner(const SelectionContext &selectionState) ...@@ -504,19 +504,19 @@ void layoutColumnPositioner(const SelectionContext &selectionState)
ModelNode column; ModelNode column;
{ {
RewriterTransaction transaction(selectionState.qmlModelView()); RewriterTransaction transaction(selectionState.view());
QmlItemNode parent = QmlItemNode(modelNodeList.first()).instanceParent().toQmlItemNode(); QmlItemNode parent = QmlItemNode(modelNodeList.first()).instanceParent().toQmlItemNode();
if (!parent.isValid()) if (!parent.isValid())
return; return;
column = selectionState.qmlModelView()->createModelNode("QtQuick.Column", columnMetaInfo.majorVersion(), columnMetaInfo.minorVersion()); column = selectionState.view()->createModelNode("QtQuick.Column", columnMetaInfo.majorVersion(), columnMetaInfo.minorVersion());
reparentTo(column, parent); reparentTo(column, parent);
} }
{ {
RewriterTransaction transaction(selectionState.qmlModelView()); RewriterTransaction transaction(selectionState.view());
QPoint pos = getUpperLeftPosition(modelNodeList); QPoint pos = getUpperLeftPosition(modelNodeList);
column.variantProperty("x") = pos.x(); column.variantProperty("x") = pos.x();
...@@ -535,10 +535,10 @@ void layoutColumnPositioner(const SelectionContext &selectionState) ...@@ -535,10 +535,10 @@ void layoutColumnPositioner(const SelectionContext &selectionState)
void layoutGridPositioner(const SelectionContext &selectionState) void layoutGridPositioner(const SelectionContext &selectionState)
{ {
if (!selectionState.qmlModelView()) if (!selectionState.view())
return; return;
NodeMetaInfo gridMetaInfo = selectionState.qmlModelView()->model()->metaInfo("QtQuick.Grid"); NodeMetaInfo gridMetaInfo = selectionState.view()->model()->metaInfo("QtQuick.Grid");
if (!gridMetaInfo.isValid()) if (!gridMetaInfo.isValid())
return; return;
...@@ -547,20 +547,20 @@ void layoutGridPositioner(const SelectionContext &selectionState) ...@@ -547,20 +547,20 @@ void layoutGridPositioner(const SelectionContext &selectionState)
ModelNode grid; ModelNode grid;
{ {
RewriterTransaction transaction(selectionState.qmlModelView()); RewriterTransaction transaction(selectionState.view());
QmlItemNode parent = QmlItemNode(modelNodeList.first()).instanceParent().toQmlItemNode(); QmlItemNode parent = QmlItemNode(modelNodeList.first()).instanceParent().toQmlItemNode();
if (!parent.isValid()) if (!parent.isValid())
return; return;
grid = selectionState.qmlModelView()->createModelNode("QtQuick.Grid", gridMetaInfo.majorVersion(), gridMetaInfo.minorVersion()); grid = selectionState.view()->createModelNode("QtQuick.Grid", gridMetaInfo.majorVersion(), gridMetaInfo.minorVersion());
grid.variantProperty("columns") = int(sqrt(double(modelNodeList.count()))); grid.variantProperty("columns") = int(sqrt(double(modelNodeList.count())));
reparentTo(grid, parent); reparentTo(grid, parent);
} }
{ {
RewriterTransaction transaction(selectionState.qmlModelView()); RewriterTransaction transaction(selectionState.view());
QPoint pos = getUpperLeftPosition(modelNodeList); QPoint pos = getUpperLeftPosition(modelNodeList);
grid.variantProperty("x") = pos.x(); grid.variantProperty("x") = pos.x();
...@@ -579,10 +579,10 @@ void layoutGridPositioner(const SelectionContext &selectionState) ...@@ -579,10 +579,10 @@ void layoutGridPositioner(const SelectionContext &selectionState)
void layoutFlowPositioner(const SelectionContext &selectionState) void layoutFlowPositioner(const SelectionContext &selectionState)
{ {
if (!selectionState.qmlModelView()) if (!selectionState.view())
return; return;
NodeMetaInfo flowMetaInfo = selectionState.qmlModelView()->model()->metaInfo("QtQuick.Flow"); NodeMetaInfo flowMetaInfo = selectionState.view()->model()->metaInfo("QtQuick.Flow");
if (!flowMetaInfo.isValid()) if (!flowMetaInfo.isValid())
return; return;
...@@ -591,19 +591,19 @@ void layoutFlowPositioner(const SelectionContext &selectionState) ...@@ -591,19 +591,19 @@ void layoutFlowPositioner(const SelectionContext &selectionState)
ModelNode flow; ModelNode flow;
{ {
RewriterTransaction transaction(selectionState.qmlModelView()); RewriterTransaction transaction(selectionState.view());
QmlItemNode parent = QmlItemNode(modelNodeList.first()).instanceParent().toQmlItemNode(); QmlItemNode parent = QmlItemNode(modelNodeList.first()).instanceParent().toQmlItemNode();
if (!parent.isValid()) if (!parent.isValid())
return; return;
flow = selectionState.qmlModelView()->createModelNode("QtQuick.Flow", flowMetaInfo.majorVersion(), flowMetaInfo.minorVersion()); flow = selectionState.view()->createModelNode("QtQuick.Flow", flowMetaInfo.majorVersion(), flowMetaInfo.minorVersion());
reparentTo(flow, parent); reparentTo(flow, parent);
} }
{ {
RewriterTransaction transaction(selectionState.qmlModelView()); RewriterTransaction transaction(selectionState.view());
QPoint pos = getUpperLeftPosition(modelNodeList); QPoint pos = getUpperLeftPosition(modelNodeList);
flow.variantProperty("x") = pos.x(); flow.variantProperty("x") = pos.x();
...@@ -622,16 +622,16 @@ void layoutFlowPositioner(const SelectionContext &selectionState) ...@@ -622,16 +622,16 @@ void layoutFlowPositioner(const SelectionContext &selectionState)
void layoutRowLayout(const SelectionContext &selectionState) void layoutRowLayout(const SelectionContext &selectionState)
{ {
if (!selectionState.qmlModelView() if (!selectionState.view()
|| selectionState.selectedModelNodes().isEmpty()) || selectionState.selectedModelNodes().isEmpty())
return; return;
static TypeName rowLayoutType = "QtQuick.Layouts.RowLayout"; static TypeName rowLayoutType = "QtQuick.Layouts.RowLayout";
if (!selectionState.qmlModelView()->model()->hasNodeMetaInfo(rowLayoutType)) if (!selectionState.view()->model()->hasNodeMetaInfo(rowLayoutType))
return; return;
NodeMetaInfo rowMetaInfo = selectionState.qmlModelView()->model()->metaInfo(rowLayoutType); NodeMetaInfo rowMetaInfo = selectionState.view()->model()->metaInfo(rowLayoutType);
QList<ModelNode> selectedNodeList = selectionState.selectedModelNodes(); QList<ModelNode> selectedNodeList = selectionState.selectedModelNodes();
QmlItemNode qmlItemNode = QmlItemNode(selectedNodeList.first()); QmlItemNode qmlItemNode = QmlItemNode(selectedNodeList.first());
...@@ -640,17 +640,17 @@ void layoutRowLayout(const SelectionContext &selectionState) ...@@ -640,17 +640,17 @@ void layoutRowLayout(const SelectionContext &selectionState)
ModelNode rowNode; ModelNode rowNode;
{ {
RewriterTransaction transaction(selectionState.qmlModelView()); RewriterTransaction transaction(selectionState.view());
QmlItemNode parentNode = qmlItemNode.instanceParentItem(); QmlItemNode parentNode = qmlItemNode.instanceParentItem();
rowNode = selectionState.qmlModelView()->createModelNode(rowLayoutType, rowMetaInfo.majorVersion(), rowMetaInfo.minorVersion()); rowNode = selectionState.view()->createModelNode(rowLayoutType, rowMetaInfo.majorVersion(), rowMetaInfo.minorVersion());
reparentTo(rowNode, parentNode); reparentTo(rowNode, parentNode);
} }
{ {
RewriterTransaction transaction(selectionState.qmlModelView()); RewriterTransaction transaction(selectionState.view());
QPoint upperLeftPosition = getUpperLeftPosition(selectedNodeList); QPoint upperLeftPosition = getUpperLeftPosition(selectedNodeList);
rowNode.variantProperty("x") = upperLeftPosition.x(); rowNode.variantProperty("x") = upperLeftPosition.x();
...@@ -670,16 +670,16 @@ void layoutRowLayout(const SelectionContext &selectionState) ...@@ -670,16 +670,16 @@ void layoutRowLayout(const SelectionContext &selectionState)
void layoutColumnLayout(const SelectionContext &selectionState) void layoutColumnLayout(const SelectionContext &selectionState)
{ {
if (!selectionState.qmlModelView() if (!selectionState.view()
|| selectionState.selectedModelNodes().isEmpty()) || selectionState.selectedModelNodes().isEmpty())
return; return;
static TypeName columnLayoutType = "QtQuick.Layouts.ColumnLayout"; static TypeName columnLayoutType = "QtQuick.Layouts.ColumnLayout";
if (!selectionState.qmlModelView()->model()->hasNodeMetaInfo(columnLayoutType)) if (!selectionState.view()->model()->hasNodeMetaInfo(columnLayoutType))
return; return;
NodeMetaInfo columnMetaInfo = selectionState.qmlModelView()->model()->metaInfo(columnLayoutType); NodeMetaInfo columnMetaInfo = selectionState.view()->model()->metaInfo(columnLayoutType);
QList<ModelNode> selectedNodeList = selectionState.selectedModelNodes(); QList<ModelNode> selectedNodeList = selectionState.selectedModelNodes();
QmlItemNode qmlItemNode = QmlItemNode(selectedNodeList.first());