Commit 27f261f0 authored by Marco Bubke's avatar Marco Bubke

QmlDesigner: Refactor designer actions

Change-Id: Ie9c71e564e66874b0715ed35cfacc578ad8b58b0
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent 46960958
......@@ -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;
};
......
......@@ -42,7 +42,7 @@ DefaultDesignerAction::DefaultDesignerAction(DefaultAction *action)
{
}
void DefaultDesignerAction::setCurrentContext(const SelectionContext &selectionContext)
void DefaultDesignerAction::currentContextChanged(const SelectionContext &selectionContext)
{
m_selectionContext = selectionContext;
updateContext();
......
......@@ -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;
......
......@@ -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())
......
......@@ -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);
}
}
......
......@@ -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;
......
......@@ -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
......@@ -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;
};
......
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