QmlDesigner: de-templatize

Since the templates add unnecessary complexity, we use
function pointers instead.

Change-Id: I023b3907ad8826c25d985aba0fed1d5a69265b15
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
Thomas Hartmann
2013-01-16 15:51:22 +01:00
committed by hjk
parent 23a56bb071
commit df5cd3d6f5
5 changed files with 297 additions and 325 deletions

View File

@@ -224,45 +224,39 @@ QmlModelView *DesignerActionManager::view()
return instance()->m_view.data();
}
template <class ACTION,
class ENABLED = SelectionContextFunctors::Always,
class VISIBILITY = SelectionContextFunctors::Always>
class VisiblityModelNodeActionFactory : public ModelNodeActionFactory<ACTION, ENABLED, VISIBILITY>
class VisiblityModelNodeAction : public ModelNodeAction
{
public:
VisiblityModelNodeActionFactory(const QString &description, const QString &category, int priority) :
ModelNodeActionFactory<ACTION, ENABLED, VISIBILITY>(description, category, priority)
VisiblityModelNodeAction(const QString &description, const QString &category, int priority,
ModelNodeOperations::SelectionAction action,
SelectionContextFunction enabled = &SelectionContextFunctors::always,
SelectionContextFunction visibility = &SelectionContextFunctors::always) :
ModelNodeAction(description, category, priority, action, enabled, visibility)
{}
virtual void updateContext()
{
this->m_action->setSelectionContext(this->m_selectionContext);
if (this->m_selectionContext.isValid()) {
this->m_action->setEnabled(this->isEnabled(this->m_selectionContext));
this->m_action->setVisible(this->isVisible(this->m_selectionContext));
m_action->setSelectionContext(m_selectionContext);
if (m_selectionContext.isValid()) {
m_action->setEnabled(isEnabled(m_selectionContext));
m_action->setVisible(isVisible(m_selectionContext));
this->m_action->setCheckable(true);
QmlItemNode itemNode = QmlItemNode(this->m_selectionContext.currentSingleSelectedNode());
m_action->setCheckable(true);
QmlItemNode itemNode = QmlItemNode(m_selectionContext.currentSingleSelectedNode());
if (itemNode.isValid())
this->m_action->setChecked(itemNode.instanceValue("visible").toBool());
m_action->setChecked(itemNode.instanceValue("visible").toBool());
else
this->m_action->setEnabled(false);
m_action->setEnabled(false);
}
}
};
template <void (*T)(const SelectionContext &)>
struct Functor {
void operator() (const SelectionContext &selectionState) { T(selectionState); }
};
class SelectionModelNodeAction : public MenuDesignerAction<SelectionContextFunctors::Always, SelectionContextFunctors::SelectionEnabled>
class SelectionModelNodeAction : public MenuDesignerAction
{
typedef ActionTemplate<Functor<ModelNodeOperations::select> > SelectionAction;
typedef QSharedPointer<SelectionAction> SelectionActionPtr;
public:
SelectionModelNodeAction(const QString &displayName, const QString &menuId, int priority) :
MenuDesignerAction<SelectionContextFunctors::Always, SelectionContextFunctors::SelectionEnabled>(displayName, menuId, priority)
MenuDesignerAction(displayName, menuId, priority,
&SelectionContextFunctors::always, &SelectionContextFunctors::selectionEnabled)
{}
virtual void updateContext()
@@ -277,7 +271,7 @@ public:
if (m_action->isEnabled()) {
ModelNode parentNode;
if (m_selectionContext.singleSelected() && !m_selectionContext.currentSingleSelectedNode().isRootNode()) {
SelectionAction* selectionAction = new SelectionAction(QString());
ActionTemplate *selectionAction = new ActionTemplate(QString(), &ModelNodeOperations::select);
selectionAction->setParent(m_menu.data());
parentNode = m_selectionContext.currentSingleSelectedNode().parentProperty().parentModelNode();
@@ -294,8 +288,8 @@ public:
&& contains(node, m_selectionContext.scenePos())
&& !node.isRootNode()) {
m_selectionContext.setTargetNode(node);
SelectionAction* selectionAction =
new SelectionAction(QString(QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Select: %1")).arg(captionForModelNode(node)));
QString what = QString(QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Select: %1")).arg(captionForModelNode(node));
ActionTemplate *selectionAction = new ActionTemplate(what, &ModelNodeOperations::select);
selectionAction->setSelectionContext(m_selectionContext);
m_menu->addAction(selectionAction);
@@ -311,68 +305,105 @@ char zProperty[] = "z";
char widthProperty[] = "width";
char heightProperty[] = "height";
using namespace SelectionContextFunctors;
bool multiSelection(const SelectionContext &context)
{
return !singleSelection(context);
}
bool singleSelectionAndInBaseState(const SelectionContext &context)
{
return singleSelection(context) && inBaseState(context);
}
bool multiSelectionAndInBaseState(const SelectionContext &context)
{
return multiSelection(context) && inBaseState(context);
}
bool selectionHasProperty1or2(const SelectionContext &context, const char *x, const char *y)
{
return selectionHasProperty(context, x) || selectionHasProperty(context, y);
}
bool selectionHasSameParentAndInBaseState(const SelectionContext &context)
{
return selectionHasSameParent(context) && inBaseState(context);
}
bool selectionCanBeLayouted(const SelectionContext &context)
{
return selectionHasSameParentAndInBaseState(context) && inBaseState(context);
}
bool selectionNotEmptyAndHasZProperty(const SelectionContext &context)
{
return selectionNotEmpty(context) && selectionHasProperty(context, zProperty);
}
bool selectionNotEmptyAndHasWidthOrHeightProperty(const SelectionContext &context)
{
return selectionNotEmpty(context)
&& selectionHasProperty1or2(context, widthProperty, heightProperty);
}
bool selectionNotEmptyAndHasXorYProperty(const SelectionContext &context)
{
return selectionNotEmpty(context)
&& selectionHasProperty1or2(context, xProperty, yProperty);
}
void DesignerActionManager::createDefaultDesignerActions()
{
typedef Functor<ModelNodeOperations::resetPosition> resetPositionFunctor;
using namespace SelectionContextFunctors;
using namespace ComponentCoreConstants;
typedef Not<SingleSelection> MultiSelection;
typedef And<SingleSelection, InBaseState> SingleSelection_And_InBaseState;
typedef And<MultiSelection, InBaseState> MultiSelection_And_InBaseState;
typedef Or<SelectionHasProperty<xProperty>, SelectionHasProperty<yProperty> >
SelectionHasPropertyX_Or_SelectionHasPropertyY;
typedef Or<SelectionHasProperty<widthProperty>, SelectionHasProperty<heightProperty> >
SelectionHasPropertyWidth_Or_SelectionHasPropertyHeight;
typedef And<SelectionHasSameParent, InBaseState> SelectionHasSameParent_And_InBaseState;
typedef And<SelectionHasSameParent_And_InBaseState, MultiSelection> SelectionCanBeLayouted;
using namespace ModelNodeOperations;
addDesignerAction(new SelectionModelNodeAction(selectionCategoryDisplayName, selectionCategory, prioritySelectionCategory));
addDesignerAction(new MenuDesignerAction<Always>(stackCategoryDisplayName, stackCategory, priorityStackCategory));
addDesignerAction(new ModelNodeActionFactory<Functor<ModelNodeOperations::toFront>, SingleSelection>
(toFrontDisplayName, stackCategory, 200));
addDesignerAction(new ModelNodeActionFactory<Functor<ModelNodeOperations::toBack>, SingleSelection>
(toBackDisplayName, stackCategory, 180));
addDesignerAction(new ModelNodeActionFactory<Functor<ModelNodeOperations::raise>, SelectionNotEmpty>
(raiseDisplayName, stackCategory, 160));
addDesignerAction(new ModelNodeActionFactory<Functor<ModelNodeOperations::lower>, SelectionNotEmpty>
(lowerDisplayName, stackCategory, 140));
addDesignerAction(new SeperatorDesignerAction<>(stackCategory, 120));
addDesignerAction(new ModelNodeActionFactory<Functor<ModelNodeOperations::resetZ>,
And<SelectionNotEmpty, SelectionHasProperty<zProperty> > >
(resetZDisplayName, stackCategory, 100));
addDesignerAction(new MenuDesignerAction(stackCategoryDisplayName, stackCategory, priorityStackCategory, &always));
addDesignerAction(new ModelNodeAction
(toFrontDisplayName, stackCategory, 200, &toFront, &singleSelection));
addDesignerAction(new ModelNodeAction
(toBackDisplayName, stackCategory, 180, &toBack, &singleSelection));
addDesignerAction(new ModelNodeAction
(raiseDisplayName, stackCategory, 160, &raise, &selectionNotEmpty));
addDesignerAction(new ModelNodeAction
(lowerDisplayName, stackCategory, 140, &lower, &selectionNotEmpty));
addDesignerAction(new SeperatorDesignerAction(stackCategory, 120));
addDesignerAction(new ModelNodeAction
(resetZDisplayName, stackCategory, 100, &resetZ, &selectionNotEmptyAndHasZProperty));
addDesignerAction(new MenuDesignerAction<SelectionNotEmpty>(editCategoryDisplayName, editCategory, priorityEditCategory));
addDesignerAction(new ModelNodeActionFactory<Functor<ModelNodeOperations::resetPosition>,
And<SelectionNotEmpty, SelectionHasPropertyWidth_Or_SelectionHasPropertyHeight> >
(resetPositionDisplayName, editCategory, 200));
addDesignerAction(new ModelNodeActionFactory<Functor<ModelNodeOperations::resetSize>,
And<SelectionNotEmpty, SelectionHasPropertyX_Or_SelectionHasPropertyY> >
(resetSizeDisplayName, editCategory, 180));
addDesignerAction(new VisiblityModelNodeActionFactory<Functor<ModelNodeOperations::setVisible>, SingleSelectedItem>
(visibilityDisplayName, editCategory, 160));
addDesignerAction(new MenuDesignerAction(editCategoryDisplayName, editCategory, priorityEditCategory, &selectionNotEmpty));
addDesignerAction(new ModelNodeAction
(resetPositionDisplayName, editCategory, 200, &resetPosition, &selectionNotEmptyAndHasXorYProperty));
addDesignerAction(new ModelNodeAction
(resetSizeDisplayName, editCategory, 180, &resetSize, &selectionNotEmptyAndHasWidthOrHeightProperty));
addDesignerAction(new VisiblityModelNodeAction
(visibilityDisplayName, editCategory, 160, &setVisible, &singleSelectedItem));
addDesignerAction(new MenuDesignerAction<SingleSelection_And_InBaseState>(anchorsCategoryDisplayName, anchorsCategory, priorityAnchorsCategory));
addDesignerAction(new ModelNodeActionFactory<Functor<ModelNodeOperations::anchorsFill>, SingleSelectionItemNotAnchored>
(anchorsFillDisplayName, anchorsCategory, 200));
addDesignerAction(new ModelNodeActionFactory<Functor<ModelNodeOperations::anchorsReset>,
SingleSelectionItemIsAnchored>(anchorsResetDisplayName, anchorsCategory, 180));
addDesignerAction(new MenuDesignerAction(anchorsCategoryDisplayName, anchorsCategory,
priorityAnchorsCategory, &singleSelectionAndInBaseState));
addDesignerAction(new ModelNodeAction
(anchorsFillDisplayName, anchorsCategory, 200, &anchorsFill, &singleSelectionItemIsNotAnchored));
addDesignerAction(new ModelNodeAction
(anchorsResetDisplayName, anchorsCategory, 180, &anchorsReset, &singleSelectionItemIsAnchored));
addDesignerAction(new MenuDesignerAction<MultiSelection_And_InBaseState>(layoutCategoryDisplayName, layoutCategory, priorityLayoutCategory));
addDesignerAction(new ModelNodeActionFactory<Functor<ModelNodeOperations::layoutRow>, SelectionCanBeLayouted>
(layoutRowDisplayName, layoutCategory, 200));
addDesignerAction(new ModelNodeActionFactory<Functor<ModelNodeOperations::layoutColumn>, SelectionCanBeLayouted>
(layoutColumnDisplayName, layoutCategory, 180));
addDesignerAction(new ModelNodeActionFactory<Functor<ModelNodeOperations::layoutColumn>, SelectionCanBeLayouted>
(layoutGridDisplayName, layoutCategory, 160));
addDesignerAction(new ModelNodeActionFactory<Functor<ModelNodeOperations::layoutFlow>, SelectionCanBeLayouted>
(layoutFlowDisplayName, layoutCategory, 140));
addDesignerAction(new MenuDesignerAction(layoutCategoryDisplayName, layoutCategory,
priorityLayoutCategory, &multiSelectionAndInBaseState));
addDesignerAction(new ModelNodeAction
(layoutRowDisplayName, layoutCategory, 200, &layoutRow, &selectionCanBeLayouted));
addDesignerAction(new ModelNodeAction
(layoutColumnDisplayName, layoutCategory, 180, &layoutColumn, &selectionCanBeLayouted));
addDesignerAction(new ModelNodeAction
(layoutGridDisplayName, layoutCategory, 160, &layoutGrid, &selectionCanBeLayouted));
addDesignerAction(new ModelNodeAction
(layoutFlowDisplayName, layoutCategory, 140, &layoutFlow, &selectionCanBeLayouted));
addDesignerAction(new SeperatorDesignerAction<>(rootCategory, priorityTopLevelSeperator));
addDesignerAction(new ModelNodeActionFactory<Functor<ModelNodeOperations::goIntoComponent>,
SelectionIsComponent>(goIntoComponentDisplayName, rootCategory, priorityGoIntoComponent));
addDesignerAction(new SeperatorDesignerAction(rootCategory, priorityTopLevelSeperator));
addDesignerAction(new ModelNodeAction
(goIntoComponentDisplayName, rootCategory, priorityGoIntoComponent, &goIntoComponent, &selectionIsComponent));
}
DesignerActionManager *DesignerActionManager::instance()

View File

@@ -219,9 +219,10 @@ static inline void openInlineComponent(const ModelNode &node)
//rootModelNode.setAuxiliaryData("height", height);
}
void ComponentUtils::goIntoComponent(const ModelNode &modelNode)
{
namespace ComponentUtils {
void goIntoComponent(const ModelNode &modelNode)
{
if (modelNode.isValid() && modelNodeIsComponent(modelNode)) {
if (isFileComponent(modelNode))
openFileForComponent(modelNode);
@@ -230,9 +231,12 @@ void ComponentUtils::goIntoComponent(const ModelNode &modelNode)
}
}
} // namespace ComponentUtils
namespace SelectionContextFunctors {
bool SingleSelectionItemIsAnchored::operator() (const SelectionContext &selectionState) {
bool singleSelectionItemIsAnchored(const SelectionContext &selectionState)
{
QmlItemNode itemNode(selectionState.currentSingleSelectedNode());
if (selectionState.isInBaseState() && itemNode.isValid()) {
bool anchored = itemNode.instanceHasAnchors();
@@ -241,7 +245,8 @@ bool SingleSelectionItemIsAnchored::operator() (const SelectionContext &selectio
return false;
}
bool SingleSelectionItemNotAnchored::operator() (const SelectionContext &selectionState) {
bool singleSelectionItemIsNotAnchored(const SelectionContext &selectionState)
{
QmlItemNode itemNode(selectionState.currentSingleSelectedNode());
if (selectionState.isInBaseState() && itemNode.isValid()) {
bool anchored = itemNode.instanceHasAnchors();
@@ -250,12 +255,12 @@ bool SingleSelectionItemNotAnchored::operator() (const SelectionContext &selecti
return false;
}
bool SelectionHasSameParent::operator() (const SelectionContext &selectionState)
bool selectionHasSameParent(const SelectionContext &selectionState)
{
return !selectionState.selectedModelNodes().isEmpty() && itemsHaveSameParent(selectionState.selectedModelNodes());
}
bool SelectionIsComponent::operator() (const SelectionContext &selectionState)
bool selectionIsComponent(const SelectionContext &selectionState)
{
return modelNodeIsComponent(selectionState.currentSingleSelectedNode());
}

View File

@@ -31,6 +31,7 @@
#define MODELNODECONTEXTMENU_HELPER_H
#include "modelnodecontextmenu.h"
#include "modelnodeoperations.h"
#include "designeractionmanager.h"
#include <QAction>
@@ -38,114 +39,70 @@
namespace QmlDesigner {
typedef bool (*SelectionContextFunction)(const SelectionContext &);
namespace SelectionContextFunctors {
struct Always {
bool operator() (const SelectionContext &) {
inline bool always(const SelectionContext &)
{
return true;
}
};
struct InBaseState {
bool operator() (const SelectionContext &selectionState) {
inline bool inBaseState(const SelectionContext &selectionState)
{
return selectionState.isInBaseState();
}
};
struct SingleSelection {
bool operator() (const SelectionContext &selectionState) {
inline bool singleSelection(const SelectionContext &selectionState)
{
return selectionState.singleSelected();
}
};
struct SelectionEnabled {
bool operator() (const SelectionContext &selectionState) {
inline bool selectionEnabled(const SelectionContext &selectionState)
{
return selectionState.showSelectionTools();
}
};
struct SelectionNotEmpty {
bool operator() (const SelectionContext &selectionState) {
inline bool selectionNotEmpty(const SelectionContext &selectionState)
{
return !selectionState.selectedModelNodes().isEmpty();
}
};
struct SingleSelectionNotRoot {
bool operator() (const SelectionContext &selectionState) {
inline bool singleSelectionNotRoot(const SelectionContext &selectionState)
{
return selectionState.singleSelected()
&& !selectionState.currentSingleSelectedNode().isRootNode();
}
};
template <class T1, class T2>
struct And {
bool operator() (const SelectionContext &selectionState) {
T1 t1;
T2 t2;
return t1(selectionState) && t2(selectionState);
}
};
template <class T1, class T2>
struct Or {
bool operator() (const SelectionContext &selectionState) {
T1 t1;
T2 t2;
return t1(selectionState) || t2(selectionState);
}
};
template <class T1>
struct Not {
bool operator() (const SelectionContext &selectionState) {
T1 t1;
return !t1(selectionState);
}
};
template <char* PROPERTYNAME>
struct SelectionHasProperty {
bool operator() (const SelectionContext &selectionState) {
inline bool selectionHasProperty(const SelectionContext &selectionState, const char *property)
{
foreach (const ModelNode &modelNode, selectionState.selectedModelNodes())
if (modelNode.hasProperty(QLatin1String(PROPERTYNAME)))
if (modelNode.hasProperty(QLatin1String(property)))
return true;
return false;
}
};
struct SelectionHasSameParent {
bool operator() (const SelectionContext &selectionState);
};
struct SelectionIsComponent {
bool operator() (const SelectionContext &selectionState);
};
struct SingleSelectionItemIsAnchored {
bool operator() (const SelectionContext &selectionState);
};
struct SingleSelectionItemNotAnchored {
bool operator() (const SelectionContext &selectionState);
};
struct SingleSelectedItem {
bool operator() (const SelectionContext &selectionState) {
inline bool singleSelectedItem(const SelectionContext &selectionState)
{
QmlItemNode itemNode(selectionState.currentSingleSelectedNode());
return itemNode.isValid();
}
};
} //SelectionStateFunctors
bool selectionHasSameParent(const SelectionContext &selectionState);
bool selectionIsComponent(const SelectionContext &selectionState);
bool selectionIsComponent(const SelectionContext &selectionState);
bool singleSelectionItemIsAnchored(const SelectionContext &selectionState);
bool singleSelectionItemIsNotAnchored(const SelectionContext &selectionState);
} // namespace SelectionStateFunctors
class ComponentUtils {
public:
static void goIntoComponent(const ModelNode &modelNode);
};
class DefaultAction : public QAction {
namespace ComponentUtils {
void goIntoComponent(const ModelNode &modelNode);
}
class DefaultAction : public QAction
{
Q_OBJECT
public:
@@ -167,19 +124,36 @@ protected:
SelectionContext m_selectionContext;
};
class ActionTemplate : public DefaultAction
{
public:
ActionTemplate(const QString &description, ModelNodeOperations::SelectionAction action)
: DefaultAction(description), m_action(action)
{ }
public /*slots*/:
virtual void actionTriggered(bool b)
{
m_selectionContext.setToggled(b);
return m_action(m_selectionContext);
}
ModelNodeOperations::SelectionAction m_action;
};
class DefaultDesignerAction : public AbstractDesignerAction
{
public:
DefaultDesignerAction(const QString &description) : m_action(new DefaultAction(description))
DefaultDesignerAction() : m_action(new DefaultAction(QString()))
{}
DefaultDesignerAction(DefaultAction *action) : m_action(action)
{}
virtual QAction *action() const
{ return m_action; }
QAction *action() const { return m_action; }
virtual void setCurrentContext(const SelectionContext &selectionContext)
void setCurrentContext(const SelectionContext &selectionContext)
{
m_selectionContext = selectionContext;
updateContext();
@@ -199,41 +173,30 @@ protected:
SelectionContext m_selectionContext;
};
template <class ENABLED = SelectionContextFunctors::Always,
class VISIBILITY = SelectionContextFunctors::Always>
class MenuDesignerAction : public AbstractDesignerAction
{
public:
MenuDesignerAction(const QString &displayName, const QString &menuId, int priority) :
MenuDesignerAction(const QString &displayName, const QString &menuId, int priority,
SelectionContextFunction enabled = &SelectionContextFunctors::always,
SelectionContextFunction visibility = &SelectionContextFunctors::always) :
m_displayName(displayName),
m_menuId(menuId),
m_priority(priority),
m_menu(new QMenu)
m_menu(new QMenu),
m_enabled(enabled),
m_visibility(visibility)
{
m_menu->setTitle(displayName);
m_action = m_menu->menuAction();
}
virtual bool isVisible(const SelectionContext &m_selectionState) const
{ VISIBILITY visibility; return visibility(m_selectionState); }
virtual bool isEnabled(const SelectionContext &m_selectionState) const
{ ENABLED enabled; return enabled(m_selectionState); }
virtual QString category() const
{ return QString(""); }
virtual QString menuId() const
{ return m_menuId; }
virtual int priority() const
{ return m_priority; }
virtual AbstractDesignerAction::Type type() const
{ return AbstractDesignerAction::Menu; }
virtual QAction *action() const
{ return m_action; }
bool isVisible(const SelectionContext &m_selectionState) const { return m_visibility(m_selectionState); }
bool isEnabled(const SelectionContext &m_selectionState) const { return m_enabled(m_selectionState); }
QString category() const { return QString(); }
QString menuId() const { return m_menuId; }
int priority() const { return m_priority; }
AbstractDesignerAction::Type type() const { return AbstractDesignerAction::Menu; }
QAction *action() const { return m_action; }
virtual void setCurrentContext(const SelectionContext &selectionContext)
{
@@ -256,91 +219,59 @@ protected:
SelectionContext m_selectionContext;
QScopedPointer<QMenu> m_menu;
QAction *m_action;
SelectionContextFunction m_enabled;
SelectionContextFunction m_visibility;
};
template <class VISIBILITY = SelectionContextFunctors::Always>
class SeperatorDesignerAction : public DefaultDesignerAction
{
public:
SeperatorDesignerAction(const QString &category, int priority) :
DefaultDesignerAction(QString()),
m_category(category), m_priority(priority)
m_category(category),
m_priority(priority),
m_visibility(&SelectionContextFunctors::always)
{ m_action->setSeparator(true); }
virtual bool isVisible(const SelectionContext &m_selectionState) const
{ VISIBILITY visibility; return visibility(m_selectionState); }
bool isVisible(const SelectionContext &m_selectionState) const { return m_visibility(m_selectionState); }
bool isEnabled(const SelectionContext &) const { return true; }
QString category() const { return m_category; }
QString menuId() const { return QString(); }
int priority() const { return m_priority; }
Type type() const { return Action; }
void setCurrentContext(const SelectionContext &) {}
virtual bool isEnabled(const SelectionContext &) const
{ return true; }
virtual QString category() const
{ return m_category; }
virtual QString menuId() const
{ return QString(); }
virtual int priority() const
{ return m_priority; }
virtual Type type() const
{ return Action; }
virtual void setCurrentContext(const SelectionContext &)
{}
private:
const QString m_category;
const int m_priority;
SelectionContextFunction m_visibility;
};
template <class ACTION>
class ActionTemplate : public DefaultAction {
public:
ActionTemplate(const QString &description) : DefaultAction(description)
{ }
public /*slots*/:
virtual void actionTriggered(bool b)
{
m_selectionContext.setToggled(b);
ACTION action;
return action(m_selectionContext);
}
};
template <class ACTION,
class ENABLED = SelectionContextFunctors::Always,
class VISIBILITY = SelectionContextFunctors::Always>
class ModelNodeActionFactory : public DefaultDesignerAction
class ModelNodeAction : public DefaultDesignerAction
{
public:
ModelNodeActionFactory(const QString &description, const QString &category, int priority) :
DefaultDesignerAction(new ActionTemplate<ACTION>(description)),
ModelNodeAction(const QString &description, const QString &category, int priority,
ModelNodeOperations::SelectionAction selectionAction,
SelectionContextFunction enabled = &SelectionContextFunctors::always,
SelectionContextFunction visibility = &SelectionContextFunctors::always) :
DefaultDesignerAction(new ActionTemplate(description, selectionAction)),
m_category(category),
m_priority(priority)
m_priority(priority),
m_enabled(enabled),
m_visibility(visibility)
{}
virtual bool isVisible(const SelectionContext &selectionState) const
{ VISIBILITY visibility; return visibility(selectionState); }
virtual bool isEnabled(const SelectionContext &selectionState) const
{ ENABLED enabled; return enabled(selectionState); }
virtual QString category() const
{ return m_category; }
virtual QString menuId() const
{ return QString(); }
virtual int priority() const
{ return m_priority; }
virtual Type type() const
{ return Action; }
bool isVisible(const SelectionContext &selectionState) const { return m_visibility(selectionState); }
bool isEnabled(const SelectionContext &selectionState) const { return m_enabled(selectionState); }
QString category() const { return m_category; }
QString menuId() const { return QString(); }
int priority() const { return m_priority; }
Type type() const { return Action; }
private:
const QString m_category;
const int m_priority;
const SelectionContextFunction m_enabled;
const SelectionContextFunction m_visibility;
};

View File

@@ -112,18 +112,21 @@ static inline bool modelNodesHaveProperty(const QList<ModelNode> &modelNodeList,
return false;
}
void ModelNodeOperations::goIntoComponent(const ModelNode &modelNode)
namespace ModelNodeOperations {
void goIntoComponent(const ModelNode &modelNode)
{
ComponentUtils::goIntoComponent(modelNode);
}
void ModelNodeOperations::select(const SelectionContext &selectionState)
void select(const SelectionContext &selectionState)
{
if (selectionState.view())
selectionState.view()->setSelectedModelNodes(QList<ModelNode>() << selectionState.targetNode());
}
void ModelNodeOperations::deSelect(const SelectionContext &selectionState)
void deSelect(const SelectionContext &selectionState)
{
if (selectionState.view()) {
QList<ModelNode> selectedNodes = selectionState.view()->selectedModelNodes();
@@ -135,20 +138,20 @@ void ModelNodeOperations::deSelect(const SelectionContext &selectionState)
}
}
void ModelNodeOperations::cut(const SelectionContext &)
void cut(const SelectionContext &)
{
}
void ModelNodeOperations::copy(const SelectionContext &)
void copy(const SelectionContext &)
{
}
void ModelNodeOperations::deleteSelection(const SelectionContext &)
void deleteSelection(const SelectionContext &)
{
}
void ModelNodeOperations::toFront(const SelectionContext &selectionState)
void toFront(const SelectionContext &selectionState)
{
if (!selectionState.view())
return;
@@ -166,7 +169,7 @@ void ModelNodeOperations::toFront(const SelectionContext &selectionState)
}
void ModelNodeOperations::toBack(const SelectionContext &selectionState)
void toBack(const SelectionContext &selectionState)
{
if (!selectionState.view())
return;
@@ -183,7 +186,7 @@ void ModelNodeOperations::toBack(const SelectionContext &selectionState)
}
}
void ModelNodeOperations::raise(const SelectionContext &selectionState)
void raise(const SelectionContext &selectionState)
{
if (!selectionState.view())
return;
@@ -203,7 +206,7 @@ void ModelNodeOperations::raise(const SelectionContext &selectionState)
}
}
void ModelNodeOperations::lower(const SelectionContext &selectionState)
void lower(const SelectionContext &selectionState)
{
if (!selectionState.view())
@@ -224,19 +227,19 @@ void ModelNodeOperations::lower(const SelectionContext &selectionState)
}
}
void ModelNodeOperations::paste(const SelectionContext &)
void paste(const SelectionContext &)
{
}
void ModelNodeOperations::undo(const SelectionContext &)
void undo(const SelectionContext &)
{
}
void ModelNodeOperations::redo(const SelectionContext &)
void redo(const SelectionContext &)
{
}
void ModelNodeOperations::setVisible(const SelectionContext &selectionState)
void setVisible(const SelectionContext &selectionState)
{
if (!selectionState.view())
return;
@@ -249,7 +252,7 @@ void ModelNodeOperations::setVisible(const SelectionContext &selectionState)
}
void ModelNodeOperations::resetSize(const SelectionContext &selectionState)
void resetSize(const SelectionContext &selectionState)
{
if (!selectionState.view())
return;
@@ -265,7 +268,7 @@ void ModelNodeOperations::resetSize(const SelectionContext &selectionState)
}
}
void ModelNodeOperations::resetPosition(const SelectionContext &selectionState)
void resetPosition(const SelectionContext &selectionState)
{
if (!selectionState.view())
return;
@@ -281,16 +284,16 @@ void ModelNodeOperations::resetPosition(const SelectionContext &selectionState)
}
}
void ModelNodeOperations::goIntoComponent(const SelectionContext &selectionState)
void goIntoComponent(const SelectionContext &selectionState)
{
goIntoComponent(selectionState.currentSingleSelectedNode());
}
void ModelNodeOperations::setId(const SelectionContext &)
void setId(const SelectionContext &)
{
}
void ModelNodeOperations::resetZ(const SelectionContext &selectionState)
void resetZ(const SelectionContext &selectionState)
{
if (!selectionState.view())
return;
@@ -321,7 +324,7 @@ static inline void restoreProperty(ModelNode node, const QString &propertyName)
node.variantProperty(propertyName) = node.auxiliaryData(auxDataString + propertyName);
}
void ModelNodeOperations::anchorsFill(const SelectionContext &selectionState)
void anchorsFill(const SelectionContext &selectionState)
{
if (!selectionState.view())
return;
@@ -340,7 +343,7 @@ void ModelNodeOperations::anchorsFill(const SelectionContext &selectionState)
}
}
void ModelNodeOperations::anchorsReset(const SelectionContext &selectionState)
void anchorsReset(const SelectionContext &selectionState)
{
if (!selectionState.view())
return;
@@ -423,7 +426,7 @@ static inline QPoint getUpperLeftPosition(const QList<ModelNode> &modelNodeList)
return p;
}
void ModelNodeOperations::layoutRow(const SelectionContext &selectionState)
void layoutRow(const SelectionContext &selectionState)
{
if (!selectionState.view())
return;
@@ -468,7 +471,7 @@ void ModelNodeOperations::layoutRow(const SelectionContext &selectionState)
}
}
void ModelNodeOperations::layoutColumn(const SelectionContext &selectionState)
void layoutColumn(const SelectionContext &selectionState)
{
if (!selectionState.view())
return;
@@ -511,7 +514,7 @@ void ModelNodeOperations::layoutColumn(const SelectionContext &selectionState)
}
}
void ModelNodeOperations::layoutGrid(const SelectionContext &selectionState)
void layoutGrid(const SelectionContext &selectionState)
{
if (!selectionState.view())
return;
@@ -555,7 +558,7 @@ void ModelNodeOperations::layoutGrid(const SelectionContext &selectionState)
}
}
void ModelNodeOperations::layoutFlow(const SelectionContext &selectionState)
void layoutFlow(const SelectionContext &selectionState)
{
if (!selectionState.view())
return;
@@ -598,4 +601,6 @@ void ModelNodeOperations::layoutFlow(const SelectionContext &selectionState)
}
}
} // namespace Mode
} //QmlDesigner

View File

@@ -33,38 +33,38 @@
#include "selectioncontext.h"
namespace QmlDesigner {
namespace ModelNodeOperations {
class ModelNodeOperations
{
public:
static void goIntoComponent(const ModelNode &modelNode);
void goIntoComponent(const ModelNode &modelNode);
static void select(const SelectionContext &selectionState);
static void deSelect(const SelectionContext &selectionState);
static void cut(const SelectionContext &selectionState);
static void copy(const SelectionContext &selectionState);
static void deleteSelection(const SelectionContext &selectionState);
static void toFront(const SelectionContext &selectionState);
static void toBack(const SelectionContext &selectionState);
static void raise(const SelectionContext &selectionState);
static void lower(const SelectionContext &selectionState);
static void paste(const SelectionContext &selectionState);
static void undo(const SelectionContext &selectionState);
static void redo(const SelectionContext &selectionState);
static void setVisible(const SelectionContext &selectionState);
static void resetSize(const SelectionContext &selectionState);
static void resetPosition(const SelectionContext &selectionState);
static void goIntoComponent(const SelectionContext &selectionState);
static void setId(const SelectionContext &selectionState);
static void resetZ(const SelectionContext &selectionState);
static void anchorsFill(const SelectionContext &selectionState);
static void anchorsReset(const SelectionContext &selectionState);
static void layoutRow(const SelectionContext &selectionState);
static void layoutColumn(const SelectionContext &selectionState);
static void layoutGrid(const SelectionContext &selectionState);
static void layoutFlow(const SelectionContext &selectionState);
};
typedef void (*SelectionAction)(const SelectionContext &);
void select(const SelectionContext &selectionState);
void deSelect(const SelectionContext &selectionState);
void cut(const SelectionContext &selectionState);
void copy(const SelectionContext &selectionState);
void deleteSelection(const SelectionContext &selectionState);
void toFront(const SelectionContext &selectionState);
void toBack(const SelectionContext &selectionState);
void raise(const SelectionContext &selectionState);
void lower(const SelectionContext &selectionState);
void paste(const SelectionContext &selectionState);
void undo(const SelectionContext &selectionState);
void redo(const SelectionContext &selectionState);
void setVisible(const SelectionContext &selectionState);
void resetSize(const SelectionContext &selectionState);
void resetPosition(const SelectionContext &selectionState);
void goIntoComponent(const SelectionContext &selectionState);
void setId(const SelectionContext &selectionState);
void resetZ(const SelectionContext &selectionState);
void anchorsFill(const SelectionContext &selectionState);
void anchorsReset(const SelectionContext &selectionState);
void layoutRow(const SelectionContext &selectionState);
void layoutColumn(const SelectionContext &selectionState);
void layoutGrid(const SelectionContext &selectionState);
void layoutFlow(const SelectionContext &selectionState);
} // namespace ModelNodeOperationso
} //QmlDesigner
#endif //MODELNODEOPERATIONS_H