diff --git a/src/plugins/qmldesigner/components/componentcore/abstractdesigneraction.h b/src/plugins/qmldesigner/components/componentcore/abstractdesigneraction.h index f50fa16d560245257fa28a3358ac9b6da484fd0e..10d92cff15acf11f8f9b8227eb2101d42c8629a9 100644 --- a/src/plugins/qmldesigner/components/componentcore/abstractdesigneraction.h +++ b/src/plugins/qmldesigner/components/componentcore/abstractdesigneraction.h @@ -61,7 +61,7 @@ public: virtual QString menuId() const = 0; virtual int priority() const = 0; virtual Type type() const = 0; - virtual void setCurrentContext(const SelectionContext &selectionState) = 0; + virtual void currentContextChanged(const SelectionContext &selectionState) = 0; }; diff --git a/src/plugins/qmldesigner/components/componentcore/defaultdesigneraction.cpp b/src/plugins/qmldesigner/components/componentcore/defaultdesigneraction.cpp index e9a150094866bc725380fe01b61bada5302aa86c..5ae93e46f6271012eb344aa61188e11ca7f35ff8 100644 --- a/src/plugins/qmldesigner/components/componentcore/defaultdesigneraction.cpp +++ b/src/plugins/qmldesigner/components/componentcore/defaultdesigneraction.cpp @@ -42,7 +42,7 @@ DefaultDesignerAction::DefaultDesignerAction(DefaultAction *action) { } -void DefaultDesignerAction::setCurrentContext(const SelectionContext &selectionContext) +void DefaultDesignerAction::currentContextChanged(const SelectionContext &selectionContext) { m_selectionContext = selectionContext; updateContext(); diff --git a/src/plugins/qmldesigner/components/componentcore/defaultdesigneraction.h b/src/plugins/qmldesigner/components/componentcore/defaultdesigneraction.h index 780dd343616da837e6f613f36e7babc37f0f7fd3..52df23025012a972c05589e4964a8ea0dc0a5170 100644 --- a/src/plugins/qmldesigner/components/componentcore/defaultdesigneraction.h +++ b/src/plugins/qmldesigner/components/componentcore/defaultdesigneraction.h @@ -59,12 +59,12 @@ public: DefaultDesignerAction(DefaultAction *action); QAction *action() const { return m_action; } - void setCurrentContext(const SelectionContext &selectionContext); + void currentContextChanged(const SelectionContext &selectionContext); protected: virtual void updateContext(); - virtual bool isVisible(const SelectionContext &selectionState) const = 0; - virtual bool isEnabled(const SelectionContext &selectionState) const = 0; + virtual bool isVisible(const SelectionContext &selectionContext) const = 0; + virtual bool isEnabled(const SelectionContext &selectionContext) const = 0; DefaultAction *defaultAction() const; SelectionContext selectionContext() const; diff --git a/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp b/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp index 788eb7b7d8244c5a9165df128b96a5dc16fe05b5..2861e41808b2e590042ba69b54e768c3de78f2be 100644 --- a/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp +++ b/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp @@ -195,7 +195,7 @@ protected: } SelectionContext selectionContext(this); foreach (AbstractDesignerAction* action, m_designerActionList) { - action->setCurrentContext(selectionContext); + action->currentContextChanged(selectionContext); } m_setupContextDirty = false; } @@ -270,7 +270,7 @@ public: } if (m_action->isEnabled()) { ModelNode parentNode; - if (m_selectionContext.singleSelected() && !m_selectionContext.currentSingleSelectedNode().isRootNode()) { + if (m_selectionContext.isSingleNodeIsSelected() && !m_selectionContext.currentSingleSelectedNode().isRootNode()) { ActionTemplate *selectionAction = new ActionTemplate(QString(), &ModelNodeOperations::select); selectionAction->setParent(m_menu.data()); @@ -282,7 +282,7 @@ public: m_menu->addAction(selectionAction); } - foreach (const ModelNode &node, m_selectionContext.view()->allModelNodes()) { + foreach (const ModelNode &node, m_selectionContext.qmlModelView()->allModelNodes()) { if (node != m_selectionContext.currentSingleSelectedNode() && node != parentNode && contains(node, m_selectionContext.scenePos()) diff --git a/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu.cpp b/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu.cpp index e3e9a708f7029a7a8ef959deb3eda4c95748646d..909bf2bfab69654c0944da36055fe15f25e183b6 100644 --- a/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu.cpp +++ b/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu.cpp @@ -89,7 +89,7 @@ void populateMenu(QSet<AbstractDesignerAction* > &abstractDesignerActions, foreach (AbstractDesignerAction* designerAction, matchingFactoriesList) { if (designerAction->type() == AbstractDesignerAction::Menu) { - designerAction->setCurrentContext(selectionContext); + designerAction->currentContextChanged(selectionContext); QMenu *newMenu = designerAction->action()->menu(); menu->addMenu(newMenu); @@ -98,7 +98,7 @@ void populateMenu(QSet<AbstractDesignerAction* > &abstractDesignerActions, populateMenu(abstractDesignerActions, designerAction->menuId(), newMenu, selectionContext); } else if (designerAction->type() == AbstractDesignerAction::Action) { QAction* action = designerAction->action(); - designerAction->setCurrentContext(selectionContext); + designerAction->currentContextChanged(selectionContext); menu->addAction(action); } } diff --git a/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu_helper.h b/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu_helper.h index 02399226c17b40710e0a7c610a91dc72a0c8507d..4e67b310884995f42484851f02830c805a17a45c 100644 --- a/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu_helper.h +++ b/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu_helper.h @@ -56,7 +56,7 @@ inline bool inBaseState(const SelectionContext &selectionState) inline bool singleSelection(const SelectionContext &selectionState) { - return selectionState.singleSelected(); + return selectionState.isSingleNodeIsSelected(); } inline bool selectionEnabled(const SelectionContext &selectionState) @@ -71,7 +71,7 @@ inline bool selectionNotEmpty(const SelectionContext &selectionState) inline bool singleSelectionNotRoot(const SelectionContext &selectionState) { - return selectionState.singleSelected() + return selectionState.isSingleNodeIsSelected() && !selectionState.currentSingleSelectedNode().isRootNode(); } @@ -144,7 +144,7 @@ public: AbstractDesignerAction::Type type() const { return AbstractDesignerAction::Menu; } QAction *action() const { return m_action; } - virtual void setCurrentContext(const SelectionContext &selectionContext) + virtual void currentContextChanged(const SelectionContext &selectionContext) { m_selectionContext = selectionContext; updateContext(); @@ -184,7 +184,7 @@ public: QString menuId() const { return QString(); } int priority() const { return m_priority; } Type type() const { return Action; } - void setCurrentContext(const SelectionContext &) {} + void currentContextChanged(const SelectionContext &) {} private: const QString m_category; diff --git a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp index 1ca3d332647eba42e58c0631af9960771751e815..c7159094175fa81d84f43ca4abd5b0822ccbd50a 100644 --- a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp +++ b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp @@ -122,19 +122,19 @@ void goIntoComponent(const ModelNode &modelNode) void select(const SelectionContext &selectionState) { - if (selectionState.view()) - selectionState.view()->setSelectedModelNodes(QList<ModelNode>() << selectionState.targetNode()); + if (selectionState.qmlModelView()) + selectionState.qmlModelView()->setSelectedModelNodes(QList<ModelNode>() << selectionState.targetNode()); } void deSelect(const SelectionContext &selectionState) { - if (selectionState.view()) { - QList<ModelNode> selectedNodes = selectionState.view()->selectedModelNodes(); + if (selectionState.qmlModelView()) { + QList<ModelNode> selectedNodes = selectionState.qmlModelView()->selectedModelNodes(); foreach (const ModelNode &node, selectionState.selectedModelNodes()) { if (selectedNodes.contains(node)) selectedNodes.removeAll(node); } - selectionState.view()->setSelectedModelNodes(selectedNodes); + selectionState.qmlModelView()->setSelectedModelNodes(selectedNodes); } } @@ -153,7 +153,7 @@ void deleteSelection(const SelectionContext &) void toFront(const SelectionContext &selectionState) { - if (!selectionState.view()) + if (!selectionState.qmlModelView()) return; try { @@ -171,7 +171,7 @@ void toFront(const SelectionContext &selectionState) void toBack(const SelectionContext &selectionState) { - if (!selectionState.view()) + if (!selectionState.qmlModelView()) return; try { QmlItemNode node = selectionState.selectedModelNodes().first(); @@ -188,11 +188,11 @@ void toBack(const SelectionContext &selectionState) void raise(const SelectionContext &selectionState) { - if (!selectionState.view()) + if (!selectionState.qmlModelView()) return; try { - RewriterTransaction transaction(selectionState.view()); + RewriterTransaction transaction(selectionState.qmlModelView()); foreach (ModelNode modelNode, selectionState.selectedModelNodes()) { QmlItemNode node = modelNode; if (node.isValid()) { @@ -209,11 +209,11 @@ void raise(const SelectionContext &selectionState) void lower(const SelectionContext &selectionState) { - if (!selectionState.view()) + if (!selectionState.qmlModelView()) return; try { - RewriterTransaction transaction(selectionState.view()); + RewriterTransaction transaction(selectionState.qmlModelView()); foreach (ModelNode modelNode, selectionState.selectedModelNodes()) { QmlItemNode node = modelNode; if (node.isValid()) { @@ -241,7 +241,7 @@ void redo(const SelectionContext &) void setVisible(const SelectionContext &selectionState) { - if (!selectionState.view()) + if (!selectionState.qmlModelView()) return; try { @@ -254,11 +254,11 @@ void setVisible(const SelectionContext &selectionState) void resetSize(const SelectionContext &selectionState) { - if (!selectionState.view()) + if (!selectionState.qmlModelView()) return; try { - RewriterTransaction transaction(selectionState.view()); + RewriterTransaction transaction(selectionState.qmlModelView()); foreach (ModelNode node, selectionState.selectedModelNodes()) { node.removeProperty("width"); node.removeProperty("height"); @@ -270,11 +270,11 @@ void resetSize(const SelectionContext &selectionState) void resetPosition(const SelectionContext &selectionState) { - if (!selectionState.view()) + if (!selectionState.qmlModelView()) return; try { - RewriterTransaction transaction(selectionState.view()); + RewriterTransaction transaction(selectionState.qmlModelView()); foreach (ModelNode node, selectionState.selectedModelNodes()) { node.removeProperty("x"); node.removeProperty("y"); @@ -295,10 +295,10 @@ void setId(const SelectionContext &) void resetZ(const SelectionContext &selectionState) { - if (!selectionState.view()) + if (!selectionState.qmlModelView()) return; - RewriterTransaction transaction(selectionState.view()); + RewriterTransaction transaction(selectionState.qmlModelView()); foreach (ModelNode node, selectionState.selectedModelNodes()) { node.removeProperty("z"); } @@ -326,10 +326,10 @@ static inline void restoreProperty(ModelNode node, const PropertyName &propertyN void anchorsFill(const SelectionContext &selectionState) { - if (!selectionState.view()) + if (!selectionState.qmlModelView()) return; - RewriterTransaction transaction(selectionState.view()); + RewriterTransaction transaction(selectionState.qmlModelView()); ModelNode modelNode = selectionState.currentSingleSelectedNode(); @@ -345,10 +345,10 @@ void anchorsFill(const SelectionContext &selectionState) void anchorsReset(const SelectionContext &selectionState) { - if (!selectionState.view()) + if (!selectionState.qmlModelView()) return; - RewriterTransaction transaction(selectionState.view()); + RewriterTransaction transaction(selectionState.qmlModelView()); ModelNode modelNode = selectionState.currentSingleSelectedNode(); @@ -428,10 +428,10 @@ static inline QPoint getUpperLeftPosition(const QList<ModelNode> &modelNodeList) void layoutRow(const SelectionContext &selectionState) { - if (!selectionState.view()) + if (!selectionState.qmlModelView()) return; - NodeMetaInfo rowMetaInfo = selectionState.view()->model()->metaInfo("QtQuick.Row"); + NodeMetaInfo rowMetaInfo = selectionState.qmlModelView()->model()->metaInfo("QtQuick.Row"); if (!rowMetaInfo.isValid()) return; @@ -440,7 +440,7 @@ void layoutRow(const SelectionContext &selectionState) ModelNode row; { - RewriterTransaction transaction(selectionState.view()); + RewriterTransaction transaction(selectionState.qmlModelView()); QmlItemNode parent = QmlItemNode(modelNodeList.first()).instanceParent().toQmlItemNode(); if (!parent.isValid()) @@ -448,13 +448,13 @@ void layoutRow(const SelectionContext &selectionState) qDebug() << parent.modelNode().majorQtQuickVersion(); - row = selectionState.view()->createModelNode("QtQuick.Row", rowMetaInfo.majorVersion(), rowMetaInfo.minorVersion()); + row = selectionState.qmlModelView()->createModelNode("QtQuick.Row", rowMetaInfo.majorVersion(), rowMetaInfo.minorVersion()); reparentTo(row, parent); } { - RewriterTransaction transaction(selectionState.view()); + RewriterTransaction transaction(selectionState.qmlModelView()); QPoint pos = getUpperLeftPosition(modelNodeList); row.variantProperty("x") = pos.x(); @@ -473,10 +473,10 @@ void layoutRow(const SelectionContext &selectionState) void layoutColumn(const SelectionContext &selectionState) { - if (!selectionState.view()) + if (!selectionState.qmlModelView()) return; - NodeMetaInfo columnMetaInfo = selectionState.view()->model()->metaInfo("QtQuick.Column"); + NodeMetaInfo columnMetaInfo = selectionState.qmlModelView()->model()->metaInfo("QtQuick.Column"); if (!columnMetaInfo.isValid()) return; @@ -485,19 +485,19 @@ void layoutColumn(const SelectionContext &selectionState) ModelNode column; { - RewriterTransaction transaction(selectionState.view()); + RewriterTransaction transaction(selectionState.qmlModelView()); QmlItemNode parent = QmlItemNode(modelNodeList.first()).instanceParent().toQmlItemNode(); if (!parent.isValid()) return; - column = selectionState.view()->createModelNode("QtQuick.Column", columnMetaInfo.majorVersion(), columnMetaInfo.minorVersion()); + column = selectionState.qmlModelView()->createModelNode("QtQuick.Column", columnMetaInfo.majorVersion(), columnMetaInfo.minorVersion()); reparentTo(column, parent); } { - RewriterTransaction transaction(selectionState.view()); + RewriterTransaction transaction(selectionState.qmlModelView()); QPoint pos = getUpperLeftPosition(modelNodeList); column.variantProperty("x") = pos.x(); @@ -516,10 +516,10 @@ void layoutColumn(const SelectionContext &selectionState) void layoutGrid(const SelectionContext &selectionState) { - if (!selectionState.view()) + if (!selectionState.qmlModelView()) return; - NodeMetaInfo gridMetaInfo = selectionState.view()->model()->metaInfo("QtQuick.Grid"); + NodeMetaInfo gridMetaInfo = selectionState.qmlModelView()->model()->metaInfo("QtQuick.Grid"); if (!gridMetaInfo.isValid()) return; @@ -528,20 +528,20 @@ void layoutGrid(const SelectionContext &selectionState) ModelNode grid; { - RewriterTransaction transaction(selectionState.view()); + RewriterTransaction transaction(selectionState.qmlModelView()); QmlItemNode parent = QmlItemNode(modelNodeList.first()).instanceParent().toQmlItemNode(); if (!parent.isValid()) return; - grid = selectionState.view()->createModelNode("QtQuick.Grid", gridMetaInfo.majorVersion(), gridMetaInfo.minorVersion()); + grid = selectionState.qmlModelView()->createModelNode("QtQuick.Grid", gridMetaInfo.majorVersion(), gridMetaInfo.minorVersion()); grid.variantProperty("columns") = int(sqrt(double(modelNodeList.count()))); reparentTo(grid, parent); } { - RewriterTransaction transaction(selectionState.view()); + RewriterTransaction transaction(selectionState.qmlModelView()); QPoint pos = getUpperLeftPosition(modelNodeList); grid.variantProperty("x") = pos.x(); @@ -560,10 +560,10 @@ void layoutGrid(const SelectionContext &selectionState) void layoutFlow(const SelectionContext &selectionState) { - if (!selectionState.view()) + if (!selectionState.qmlModelView()) return; - NodeMetaInfo flowMetaInfo = selectionState.view()->model()->metaInfo("QtQuick.Flow"); + NodeMetaInfo flowMetaInfo = selectionState.qmlModelView()->model()->metaInfo("QtQuick.Flow"); if (!flowMetaInfo.isValid()) return; @@ -572,19 +572,19 @@ void layoutFlow(const SelectionContext &selectionState) ModelNode flow; { - RewriterTransaction transaction(selectionState.view()); + RewriterTransaction transaction(selectionState.qmlModelView()); QmlItemNode parent = QmlItemNode(modelNodeList.first()).instanceParent().toQmlItemNode(); if (!parent.isValid()) return; - flow = selectionState.view()->createModelNode("QtQuick.Flow", flowMetaInfo.majorVersion(), flowMetaInfo.minorVersion()); + flow = selectionState.qmlModelView()->createModelNode("QtQuick.Flow", flowMetaInfo.majorVersion(), flowMetaInfo.minorVersion()); reparentTo(flow, parent); } { - RewriterTransaction transaction(selectionState.view()); + RewriterTransaction transaction(selectionState.qmlModelView()); QPoint pos = getUpperLeftPosition(modelNodeList); flow.variantProperty("x") = pos.x(); diff --git a/src/plugins/qmldesigner/components/componentcore/selectioncontext.cpp b/src/plugins/qmldesigner/components/componentcore/selectioncontext.cpp index 7d9c8e9d27a14d087486ee6b3f6fe95f0f1e3240..42f045f234227e04eab57df4c6934067587320c2 100644 --- a/src/plugins/qmldesigner/components/componentcore/selectioncontext.cpp +++ b/src/plugins/qmldesigner/components/componentcore/selectioncontext.cpp @@ -33,27 +33,92 @@ namespace QmlDesigner { SelectionContext::SelectionContext() : - m_view(0), m_isInBaseState(false), m_toggled(false) { } -SelectionContext::SelectionContext(QmlModelView *view) : - m_view(view), - m_isInBaseState(view->currentState().isBaseState()), +SelectionContext::SelectionContext(QmlModelView *qmlModelView) : + m_qmlModelView(qmlModelView), + m_isInBaseState(qmlModelView->currentState().isBaseState()), m_toggled(false) { - if (m_view && m_view->model()) - m_selectedModelNodes = view->selectedModelNodes(); + if (qmlModelView && qmlModelView->model()) + m_selectedModelNodes = qmlModelView->selectedModelNodes(); +} + +void SelectionContext::setTargetNode(const ModelNode &modelNode) +{ + m_targetNode = modelNode; +} + +ModelNode SelectionContext::targetNode() const +{ + return m_targetNode; +} + +bool SelectionContext::isSingleNodeIsSelected() const +{ + return m_selectedModelNodes.count() == 1; +} + +bool SelectionContext::isInBaseState() const +{ + return m_isInBaseState; +} + +ModelNode SelectionContext::currentSingleSelectedNode() const +{ + if (m_selectedModelNodes.count() != 1) + return ModelNode(); + + return m_selectedModelNodes.first(); +} + +QList<ModelNode> SelectionContext::selectedModelNodes() const +{ + return m_selectedModelNodes; +} + +QmlModelView *SelectionContext::qmlModelView() const +{ + return m_qmlModelView.data(); +} + +void SelectionContext::setShowSelectionTools(bool show) +{ + m_showSelectionTools = show; +} + +bool SelectionContext::showSelectionTools() const +{ + return m_showSelectionTools; +} + +void SelectionContext::setScenePos(const QPoint &postition) +{ + m_scenePosition = postition; +} - if (m_selectedModelNodes.count()== 1) { - m_singleSelected = true; - m_currentSingleSelectedNode = m_selectedModelNodes.first(); - } else { - m_singleSelected = false; - } +QPoint SelectionContext::scenePos() const +{ + return m_scenePosition; +} + +void SelectionContext::setToggled(bool toggled) +{ + m_toggled = toggled; +} + +bool SelectionContext::toggled() const +{ + return m_toggled; +} + +bool SelectionContext::isValid() const +{ + return qmlModelView() && qmlModelView()->model() && qmlModelView()->nodeInstanceView(); } } //QmlDesigner diff --git a/src/plugins/qmldesigner/components/componentcore/selectioncontext.h b/src/plugins/qmldesigner/components/componentcore/selectioncontext.h index 8cea6da07109c782f160eb46286cf1bd8c508507..4144d1d028deca298420d38aa574a2f499cd4bf3 100644 --- a/src/plugins/qmldesigner/components/componentcore/selectioncontext.h +++ b/src/plugins/qmldesigner/components/componentcore/selectioncontext.h @@ -39,59 +39,37 @@ class QMLDESIGNERCORE_EXPORT SelectionContext { public: SelectionContext(); - SelectionContext(QmlModelView *view); + SelectionContext(QmlModelView *qmlModelView); - void setTargetNode(const ModelNode &modelNode) - { m_targetNode = modelNode; } + void setTargetNode(const ModelNode &modelNode); + ModelNode targetNode() const; - bool singleSelected() const - { return m_singleSelected; } + bool isSingleNodeIsSelected() const; + bool isInBaseState() const; - bool isInBaseState() const - { return m_isInBaseState; } + ModelNode currentSingleSelectedNode() const; + QList<ModelNode> selectedModelNodes() const; - ModelNode targetNode() const - { return m_targetNode; } + QmlModelView *qmlModelView() const; - ModelNode currentSingleSelectedNode() const - { return m_currentSingleSelectedNode; } + void setShowSelectionTools(bool show); + bool showSelectionTools() const; - QList<ModelNode> selectedModelNodes() const - { return m_selectedModelNodes; } + void setScenePos(const QPoint &postition); + QPoint scenePos() const; - QmlModelView *view() const - { return m_view; } + void setToggled(bool toggled); + bool toggled() const; - void setShowSelectionTools(bool show) - { m_showSelectionTools = show; } - - bool showSelectionTools() const - { return m_showSelectionTools; } - - QPoint scenePos() const - { return m_scenePos; } - - void setScenePos(const QPoint &pos) - { m_scenePos = pos; } - - void setToggled(bool b) - { m_toggled = b; } - - bool toggled() const - { return m_toggled; } - - bool isValid() const - { return view() && view()->model() && view()->nodeInstanceView(); } + bool isValid() const; private: - QmlModelView *m_view; - bool m_singleSelected; - ModelNode m_currentSingleSelectedNode; + QWeakPointer<QmlModelView> m_qmlModelView; ModelNode m_targetNode; bool m_isInBaseState; QList<ModelNode> m_selectedModelNodes; bool m_showSelectionTools; - QPoint m_scenePos; + QPoint m_scenePosition; bool m_toggled; };