Commit 7b18db2c authored by Marco Bubke's avatar Marco Bubke Committed by Thomas Hartmann
Browse files

QmlDesigner: Refactor designer actions



Change-Id: Ie9c71e564e66874b0715ed35cfacc578ad8b58b0
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
(cherry picked from commit 27f261f0

)
Reviewed-by: default avatarMarco Bubke <marco.bubke@digia.com>
parent 240d20a2
...@@ -61,7 +61,7 @@ public: ...@@ -61,7 +61,7 @@ public:
virtual QString menuId() const = 0; virtual QString menuId() const = 0;
virtual int priority() const = 0; virtual int priority() const = 0;
virtual Type type() const = 0; virtual Type type() const = 0;
virtual void setCurrentContext(const SelectionContext &selectionState) = 0; virtual void currentContextChanged(const SelectionContext &selectionState) = 0;
}; };
......
...@@ -42,7 +42,7 @@ DefaultDesignerAction::DefaultDesignerAction(DefaultAction *action) ...@@ -42,7 +42,7 @@ DefaultDesignerAction::DefaultDesignerAction(DefaultAction *action)
{ {
} }
void DefaultDesignerAction::setCurrentContext(const SelectionContext &selectionContext) void DefaultDesignerAction::currentContextChanged(const SelectionContext &selectionContext)
{ {
m_selectionContext = selectionContext; m_selectionContext = selectionContext;
updateContext(); updateContext();
......
...@@ -59,12 +59,12 @@ public: ...@@ -59,12 +59,12 @@ public:
DefaultDesignerAction(DefaultAction *action); DefaultDesignerAction(DefaultAction *action);
QAction *action() const { return m_action; } QAction *action() const { return m_action; }
void setCurrentContext(const SelectionContext &selectionContext); void currentContextChanged(const SelectionContext &selectionContext);
protected: protected:
virtual void updateContext(); virtual void updateContext();
virtual bool isVisible(const SelectionContext &selectionState) const = 0; virtual bool isVisible(const SelectionContext &selectionContext) const = 0;
virtual bool isEnabled(const SelectionContext &selectionState) const = 0; virtual bool isEnabled(const SelectionContext &selectionContext) const = 0;
DefaultAction *defaultAction() const; DefaultAction *defaultAction() const;
SelectionContext selectionContext() const; SelectionContext selectionContext() const;
......
...@@ -195,7 +195,7 @@ protected: ...@@ -195,7 +195,7 @@ protected:
} }
SelectionContext selectionContext(this); SelectionContext selectionContext(this);
foreach (AbstractDesignerAction* action, m_designerActionList) { foreach (AbstractDesignerAction* action, m_designerActionList) {
action->setCurrentContext(selectionContext); action->currentContextChanged(selectionContext);
} }
m_setupContextDirty = false; m_setupContextDirty = false;
} }
...@@ -270,7 +270,7 @@ public: ...@@ -270,7 +270,7 @@ public:
} }
if (m_action->isEnabled()) { if (m_action->isEnabled()) {
ModelNode parentNode; 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); ActionTemplate *selectionAction = new ActionTemplate(QString(), &ModelNodeOperations::select);
selectionAction->setParent(m_menu.data()); selectionAction->setParent(m_menu.data());
...@@ -282,7 +282,7 @@ public: ...@@ -282,7 +282,7 @@ public:
m_menu->addAction(selectionAction); 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() if (node != m_selectionContext.currentSingleSelectedNode()
&& node != parentNode && node != parentNode
&& contains(node, m_selectionContext.scenePos()) && contains(node, m_selectionContext.scenePos())
......
...@@ -89,7 +89,7 @@ void populateMenu(QSet<AbstractDesignerAction* > &abstractDesignerActions, ...@@ -89,7 +89,7 @@ void populateMenu(QSet<AbstractDesignerAction* > &abstractDesignerActions,
foreach (AbstractDesignerAction* designerAction, matchingFactoriesList) { foreach (AbstractDesignerAction* designerAction, matchingFactoriesList) {
if (designerAction->type() == AbstractDesignerAction::Menu) { if (designerAction->type() == AbstractDesignerAction::Menu) {
designerAction->setCurrentContext(selectionContext); designerAction->currentContextChanged(selectionContext);
QMenu *newMenu = designerAction->action()->menu(); QMenu *newMenu = designerAction->action()->menu();
menu->addMenu(newMenu); menu->addMenu(newMenu);
...@@ -98,7 +98,7 @@ void populateMenu(QSet<AbstractDesignerAction* > &abstractDesignerActions, ...@@ -98,7 +98,7 @@ void populateMenu(QSet<AbstractDesignerAction* > &abstractDesignerActions,
populateMenu(abstractDesignerActions, designerAction->menuId(), newMenu, selectionContext); populateMenu(abstractDesignerActions, designerAction->menuId(), newMenu, selectionContext);
} else if (designerAction->type() == AbstractDesignerAction::Action) { } else if (designerAction->type() == AbstractDesignerAction::Action) {
QAction* action = designerAction->action(); QAction* action = designerAction->action();
designerAction->setCurrentContext(selectionContext); designerAction->currentContextChanged(selectionContext);
menu->addAction(action); menu->addAction(action);
} }
} }
......
...@@ -56,7 +56,7 @@ inline bool inBaseState(const SelectionContext &selectionState) ...@@ -56,7 +56,7 @@ inline bool inBaseState(const SelectionContext &selectionState)
inline bool singleSelection(const SelectionContext &selectionState) inline bool singleSelection(const SelectionContext &selectionState)
{ {
return selectionState.singleSelected(); return selectionState.isSingleNodeIsSelected();
} }
inline bool selectionEnabled(const SelectionContext &selectionState) inline bool selectionEnabled(const SelectionContext &selectionState)
...@@ -71,7 +71,7 @@ inline bool selectionNotEmpty(const SelectionContext &selectionState) ...@@ -71,7 +71,7 @@ inline bool selectionNotEmpty(const SelectionContext &selectionState)
inline bool singleSelectionNotRoot(const SelectionContext &selectionState) inline bool singleSelectionNotRoot(const SelectionContext &selectionState)
{ {
return selectionState.singleSelected() return selectionState.isSingleNodeIsSelected()
&& !selectionState.currentSingleSelectedNode().isRootNode(); && !selectionState.currentSingleSelectedNode().isRootNode();
} }
...@@ -144,7 +144,7 @@ public: ...@@ -144,7 +144,7 @@ public:
AbstractDesignerAction::Type type() const { return AbstractDesignerAction::Menu; } AbstractDesignerAction::Type type() const { return AbstractDesignerAction::Menu; }
QAction *action() const { return m_action; } QAction *action() const { return m_action; }
virtual void setCurrentContext(const SelectionContext &selectionContext) virtual void currentContextChanged(const SelectionContext &selectionContext)
{ {
m_selectionContext = selectionContext; m_selectionContext = selectionContext;
updateContext(); updateContext();
...@@ -184,7 +184,7 @@ public: ...@@ -184,7 +184,7 @@ public:
QString menuId() const { return QString(); } QString menuId() const { return QString(); }
int priority() const { return m_priority; } int priority() const { return m_priority; }
Type type() const { return Action; } Type type() const { return Action; }
void setCurrentContext(const SelectionContext &) {} void currentContextChanged(const SelectionContext &) {}
private: private:
const QString m_category; const QString m_category;
......
...@@ -122,19 +122,19 @@ void goIntoComponent(const ModelNode &modelNode) ...@@ -122,19 +122,19 @@ void goIntoComponent(const ModelNode &modelNode)
void select(const SelectionContext &selectionState) void select(const SelectionContext &selectionState)
{ {
if (selectionState.view()) if (selectionState.qmlModelView())
selectionState.view()->setSelectedModelNodes(QList<ModelNode>() << selectionState.targetNode()); selectionState.qmlModelView()->setSelectedModelNodes(QList<ModelNode>() << selectionState.targetNode());
} }
void deSelect(const SelectionContext &selectionState) void deSelect(const SelectionContext &selectionState)
{ {
if (selectionState.view()) { if (selectionState.qmlModelView()) {
QList<ModelNode> selectedNodes = selectionState.view()->selectedModelNodes(); QList<ModelNode> selectedNodes = selectionState.qmlModelView()->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.view()->setSelectedModelNodes(selectedNodes); selectionState.qmlModelView()->setSelectedModelNodes(selectedNodes);
} }
} }
...@@ -153,7 +153,7 @@ void deleteSelection(const SelectionContext &) ...@@ -153,7 +153,7 @@ void deleteSelection(const SelectionContext &)
void toFront(const SelectionContext &selectionState) void toFront(const SelectionContext &selectionState)
{ {
if (!selectionState.view()) if (!selectionState.qmlModelView())
return; return;
try { try {
...@@ -171,7 +171,7 @@ void toFront(const SelectionContext &selectionState) ...@@ -171,7 +171,7 @@ void toFront(const SelectionContext &selectionState)
void toBack(const SelectionContext &selectionState) void toBack(const SelectionContext &selectionState)
{ {
if (!selectionState.view()) if (!selectionState.qmlModelView())
return; return;
try { try {
QmlItemNode node = selectionState.selectedModelNodes().first(); QmlItemNode node = selectionState.selectedModelNodes().first();
...@@ -188,11 +188,11 @@ void toBack(const SelectionContext &selectionState) ...@@ -188,11 +188,11 @@ void toBack(const SelectionContext &selectionState)
void raise(const SelectionContext &selectionState) void raise(const SelectionContext &selectionState)
{ {
if (!selectionState.view()) if (!selectionState.qmlModelView())
return; return;
try { try {
RewriterTransaction transaction(selectionState.view()); RewriterTransaction transaction(selectionState.qmlModelView());
foreach (ModelNode modelNode, selectionState.selectedModelNodes()) { foreach (ModelNode modelNode, selectionState.selectedModelNodes()) {
QmlItemNode node = modelNode; QmlItemNode node = modelNode;
if (node.isValid()) { if (node.isValid()) {
...@@ -209,11 +209,11 @@ void raise(const SelectionContext &selectionState) ...@@ -209,11 +209,11 @@ void raise(const SelectionContext &selectionState)
void lower(const SelectionContext &selectionState) void lower(const SelectionContext &selectionState)
{ {
if (!selectionState.view()) if (!selectionState.qmlModelView())
return; return;
try { try {
RewriterTransaction transaction(selectionState.view()); RewriterTransaction transaction(selectionState.qmlModelView());
foreach (ModelNode modelNode, selectionState.selectedModelNodes()) { foreach (ModelNode modelNode, selectionState.selectedModelNodes()) {
QmlItemNode node = modelNode; QmlItemNode node = modelNode;
if (node.isValid()) { if (node.isValid()) {
...@@ -241,7 +241,7 @@ void redo(const SelectionContext &) ...@@ -241,7 +241,7 @@ void redo(const SelectionContext &)
void setVisible(const SelectionContext &selectionState) void setVisible(const SelectionContext &selectionState)
{ {
if (!selectionState.view()) if (!selectionState.qmlModelView())
return; return;
try { try {
...@@ -254,11 +254,11 @@ void setVisible(const SelectionContext &selectionState) ...@@ -254,11 +254,11 @@ void setVisible(const SelectionContext &selectionState)
void resetSize(const SelectionContext &selectionState) void resetSize(const SelectionContext &selectionState)
{ {
if (!selectionState.view()) if (!selectionState.qmlModelView())
return; return;
try { try {
RewriterTransaction transaction(selectionState.view()); RewriterTransaction transaction(selectionState.qmlModelView());
foreach (ModelNode node, selectionState.selectedModelNodes()) { foreach (ModelNode node, selectionState.selectedModelNodes()) {
node.removeProperty("width"); node.removeProperty("width");
node.removeProperty("height"); node.removeProperty("height");
...@@ -270,11 +270,11 @@ void resetSize(const SelectionContext &selectionState) ...@@ -270,11 +270,11 @@ void resetSize(const SelectionContext &selectionState)
void resetPosition(const SelectionContext &selectionState) void resetPosition(const SelectionContext &selectionState)
{ {
if (!selectionState.view()) if (!selectionState.qmlModelView())
return; return;
try { try {
RewriterTransaction transaction(selectionState.view()); RewriterTransaction transaction(selectionState.qmlModelView());
foreach (ModelNode node, selectionState.selectedModelNodes()) { foreach (ModelNode node, selectionState.selectedModelNodes()) {
node.removeProperty("x"); node.removeProperty("x");
node.removeProperty("y"); node.removeProperty("y");
...@@ -295,10 +295,10 @@ void setId(const SelectionContext &) ...@@ -295,10 +295,10 @@ void setId(const SelectionContext &)
void resetZ(const SelectionContext &selectionState) void resetZ(const SelectionContext &selectionState)
{ {
if (!selectionState.view()) if (!selectionState.qmlModelView())
return; return;
RewriterTransaction transaction(selectionState.view()); RewriterTransaction transaction(selectionState.qmlModelView());
foreach (ModelNode node, selectionState.selectedModelNodes()) { foreach (ModelNode node, selectionState.selectedModelNodes()) {
node.removeProperty("z"); node.removeProperty("z");
} }
...@@ -326,10 +326,10 @@ static inline void restoreProperty(ModelNode node, const PropertyName &propertyN ...@@ -326,10 +326,10 @@ static inline void restoreProperty(ModelNode node, const PropertyName &propertyN
void anchorsFill(const SelectionContext &selectionState) void anchorsFill(const SelectionContext &selectionState)
{ {
if (!selectionState.view()) if (!selectionState.qmlModelView())
return; return;
RewriterTransaction transaction(selectionState.view()); RewriterTransaction transaction(selectionState.qmlModelView());
ModelNode modelNode = selectionState.currentSingleSelectedNode(); ModelNode modelNode = selectionState.currentSingleSelectedNode();
...@@ -345,10 +345,10 @@ void anchorsFill(const SelectionContext &selectionState) ...@@ -345,10 +345,10 @@ void anchorsFill(const SelectionContext &selectionState)
void anchorsReset(const SelectionContext &selectionState) void anchorsReset(const SelectionContext &selectionState)
{ {
if (!selectionState.view()) if (!selectionState.qmlModelView())
return; return;
RewriterTransaction transaction(selectionState.view()); RewriterTransaction transaction(selectionState.qmlModelView());
ModelNode modelNode = selectionState.currentSingleSelectedNode(); ModelNode modelNode = selectionState.currentSingleSelectedNode();
...@@ -428,10 +428,10 @@ static inline QPoint getUpperLeftPosition(const QList<ModelNode> &modelNodeList) ...@@ -428,10 +428,10 @@ static inline QPoint getUpperLeftPosition(const QList<ModelNode> &modelNodeList)
void layoutRow(const SelectionContext &selectionState) void layoutRow(const SelectionContext &selectionState)
{ {
if (!selectionState.view()) if (!selectionState.qmlModelView())
return; return;
NodeMetaInfo rowMetaInfo = selectionState.view()->model()->metaInfo("QtQuick.Row"); NodeMetaInfo rowMetaInfo = selectionState.qmlModelView()->model()->metaInfo("QtQuick.Row");
if (!rowMetaInfo.isValid()) if (!rowMetaInfo.isValid())
return; return;
...@@ -440,7 +440,7 @@ void layoutRow(const SelectionContext &selectionState) ...@@ -440,7 +440,7 @@ void layoutRow(const SelectionContext &selectionState)
ModelNode row; ModelNode row;
{ {
RewriterTransaction transaction(selectionState.view()); RewriterTransaction transaction(selectionState.qmlModelView());
QmlItemNode parent = QmlItemNode(modelNodeList.first()).instanceParent().toQmlItemNode(); QmlItemNode parent = QmlItemNode(modelNodeList.first()).instanceParent().toQmlItemNode();
if (!parent.isValid()) if (!parent.isValid())
...@@ -448,13 +448,13 @@ void layoutRow(const SelectionContext &selectionState) ...@@ -448,13 +448,13 @@ void layoutRow(const SelectionContext &selectionState)
qDebug() << parent.modelNode().majorQtQuickVersion(); 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); reparentTo(row, parent);
} }
{ {
RewriterTransaction transaction(selectionState.view()); RewriterTransaction transaction(selectionState.qmlModelView());
QPoint pos = getUpperLeftPosition(modelNodeList); QPoint pos = getUpperLeftPosition(modelNodeList);
row.variantProperty("x") = pos.x(); row.variantProperty("x") = pos.x();
...@@ -473,10 +473,10 @@ void layoutRow(const SelectionContext &selectionState) ...@@ -473,10 +473,10 @@ void layoutRow(const SelectionContext &selectionState)
void layoutColumn(const SelectionContext &selectionState) void layoutColumn(const SelectionContext &selectionState)
{ {
if (!selectionState.view()) if (!selectionState.qmlModelView())
return; return;
NodeMetaInfo columnMetaInfo = selectionState.view()->model()->metaInfo("QtQuick.Column"); NodeMetaInfo columnMetaInfo = selectionState.qmlModelView()->model()->metaInfo("QtQuick.Column");
if (!columnMetaInfo.isValid()) if (!columnMetaInfo.isValid())
return; return;
...@@ -485,19 +485,19 @@ void layoutColumn(const SelectionContext &selectionState) ...@@ -485,19 +485,19 @@ void layoutColumn(const SelectionContext &selectionState)
ModelNode column; ModelNode column;
{ {
RewriterTransaction transaction(selectionState.view()); RewriterTransaction transaction(selectionState.qmlModelView());
QmlItemNode parent = QmlItemNode(modelNodeList.first()).instanceParent().toQmlItemNode(); QmlItemNode parent = QmlItemNode(modelNodeList.first()).instanceParent().toQmlItemNode();
if (!parent.isValid()) if (!parent.isValid())
return; return;
column = selectionState.view()->createModelNode("QtQuick.Column", columnMetaInfo.majorVersion(), columnMetaInfo.minorVersion()); column = selectionState.qmlModelView()->createModelNode("QtQuick.Column", columnMetaInfo.majorVersion(), columnMetaInfo.minorVersion());
reparentTo(column, parent); reparentTo(column, parent);
} }
{ {
RewriterTransaction transaction(selectionState.view()); RewriterTransaction transaction(selectionState.qmlModelView());
QPoint pos = getUpperLeftPosition(modelNodeList); QPoint pos = getUpperLeftPosition(modelNodeList);
column.variantProperty("x") = pos.x(); column.variantProperty("x") = pos.x();
...@@ -516,10 +516,10 @@ void layoutColumn(const SelectionContext &selectionState) ...@@ -516,10 +516,10 @@ void layoutColumn(const SelectionContext &selectionState)
void layoutGrid(const SelectionContext &selectionState) void layoutGrid(const SelectionContext &selectionState)
{ {
if (!selectionState.view()) if (!selectionState.qmlModelView())
return; return;
NodeMetaInfo gridMetaInfo = selectionState.view()->model()->metaInfo("QtQuick.Grid"); NodeMetaInfo gridMetaInfo = selectionState.qmlModelView()->model()->metaInfo("QtQuick.Grid");
if (!gridMetaInfo.isValid()) if (!gridMetaInfo.isValid())
return; return;
...@@ -528,20 +528,20 @@ void layoutGrid(const SelectionContext &selectionState) ...@@ -528,20 +528,20 @@ void layoutGrid(const SelectionContext &selectionState)
ModelNode grid; ModelNode grid;
{ {
RewriterTransaction transaction(selectionState.view()); RewriterTransaction transaction(selectionState.qmlModelView());
QmlItemNode parent = QmlItemNode(modelNodeList.first()).instanceParent().toQmlItemNode(); QmlItemNode parent = QmlItemNode(modelNodeList.first()).instanceParent().toQmlItemNode();
if (!parent.isValid()) if (!parent.isValid())
return; 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()))); grid.variantProperty("columns") = int(sqrt(double(modelNodeList.count())));
reparentTo(grid, parent); reparentTo(grid, parent);
} }
{ {
RewriterTransaction transaction(selectionState.view()); RewriterTransaction transaction(selectionState.qmlModelView());
QPoint pos = getUpperLeftPosition(modelNodeList); QPoint pos = getUpperLeftPosition(modelNodeList);
grid.variantProperty("x") = pos.x(); grid.variantProperty("x") = pos.x();
...@@ -560,10 +560,10 @@ void layoutGrid(const SelectionContext &selectionState) ...@@ -560,10 +560,10 @@ void layoutGrid(const SelectionContext &selectionState)
void layoutFlow(const SelectionContext &selectionState) void layoutFlow(const SelectionContext &selectionState)
{ {
if (!selectionState.view()) if (!selectionState.qmlModelView())
return; return;
NodeMetaInfo flowMetaInfo = selectionState.view()->model()->metaInfo("QtQuick.Flow"); NodeMetaInfo flowMetaInfo = selectionState.qmlModelView()->model()->metaInfo("QtQuick.Flow");
if (!flowMetaInfo.isValid()) if (!flowMetaInfo.isValid())
return; return;
...@@ -572,19 +572,19 @@ void layoutFlow(const SelectionContext &selectionState) ...@@ -572,19 +572,19 @@ void layoutFlow(const SelectionContext &selectionState)