forked from qt-creator/qt-creator
QmlDesigner.ComponentCore: Refactor and export AbstractActionGroup
The classes in modelnodecontextmenu_helper.h are used to create a huge bunch of AbstractDesignerAction objects in a prototype based way using function pointers. This patch adds AbstractActionGroup which makes adding sub menus easier, but does not use function pointers. Change-Id: I5674493c16acf6fb86abd0f56c318ceff021e1b5 Reviewed-by: Marco Bubke <marco.bubke@digia.com>
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "abstractactiongroup.h"
|
||||
|
||||
#include <QMenu>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
AbstractActionGroup::AbstractActionGroup(const QString &displayName) :
|
||||
m_displayName(displayName),
|
||||
m_menu(new QMenu)
|
||||
{
|
||||
m_menu->setTitle(displayName);
|
||||
m_action = m_menu->menuAction();
|
||||
}
|
||||
|
||||
AbstractDesignerAction::Type AbstractActionGroup::type() const
|
||||
{
|
||||
return AbstractDesignerAction::Menu;
|
||||
}
|
||||
|
||||
QAction *AbstractActionGroup::action() const
|
||||
{
|
||||
return m_action;
|
||||
}
|
||||
|
||||
QMenu *AbstractActionGroup::menu() const
|
||||
{
|
||||
return m_menu.data();
|
||||
}
|
||||
|
||||
void AbstractActionGroup::currentContextChanged(const SelectionContext &selectionContext)
|
||||
{
|
||||
m_selectionContext = selectionContext;
|
||||
updateContext();
|
||||
}
|
||||
|
||||
void AbstractActionGroup::updateContext()
|
||||
{
|
||||
if (m_selectionContext.isValid()) {
|
||||
m_action->setEnabled(isEnabled(m_selectionContext));
|
||||
m_action->setVisible(isVisible(m_selectionContext));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace QmlDesigner
|
@@ -0,0 +1,64 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef MENUDESIGNERACTION_H
|
||||
#define MENUDESIGNERACTION_H
|
||||
|
||||
#include "abstractdesigneraction.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
#include <QScopedPointer>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
class QMLDESIGNERCORE_EXPORT AbstractActionGroup : public AbstractDesignerAction
|
||||
{
|
||||
public:
|
||||
AbstractActionGroup(const QString &displayName);
|
||||
|
||||
virtual bool isVisible(const SelectionContext &m_selectionState) const = 0;
|
||||
virtual bool isEnabled(const SelectionContext &m_selectionState) const = 0;
|
||||
AbstractDesignerAction::Type type() const QTC_OVERRIDE;
|
||||
QAction *action() const QTC_OVERRIDE;
|
||||
QMenu *menu() const;
|
||||
|
||||
virtual void currentContextChanged(const SelectionContext &selectionContext) QTC_OVERRIDE;
|
||||
virtual void updateContext();
|
||||
|
||||
protected:
|
||||
const QString m_displayName;
|
||||
SelectionContext m_selectionContext;
|
||||
QScopedPointer<QMenu> m_menu;
|
||||
QAction *m_action;
|
||||
};
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
||||
#endif // MENUDESIGNERACTION_H
|
@@ -1,6 +1,7 @@
|
||||
VPATH += $$PWD
|
||||
|
||||
SOURCES += modelnodecontextmenu.cpp
|
||||
SOURCES += abstractactiongroup.cpp
|
||||
SOURCES += designeractionmanagerview.cpp
|
||||
SOURCES += defaultdesigneraction.cpp
|
||||
SOURCES += modelnodecontextmenu_helper.cpp
|
||||
@@ -10,6 +11,7 @@ SOURCES += modelnodeoperations.cpp
|
||||
SOURCES += crumblebar.cpp
|
||||
|
||||
HEADERS += modelnodecontextmenu.h
|
||||
HEADERS += abstractactiongroup.h
|
||||
HEADERS += designeractionmanagerview.h
|
||||
HEADERS += defaultdesigneraction.h
|
||||
HEADERS += modelnodecontextmenu_helper.h
|
||||
|
@@ -139,11 +139,11 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class SelectionModelNodeAction : public MenuDesignerAction
|
||||
class SelectionModelNodeAction : public ActionGroup
|
||||
{
|
||||
public:
|
||||
SelectionModelNodeAction(const QString &displayName, const QByteArray &menuId, int priority) :
|
||||
MenuDesignerAction(displayName, menuId, priority,
|
||||
ActionGroup(displayName, menuId, priority,
|
||||
&SelectionContextFunctors::always, &SelectionContextFunctors::selectionEnabled)
|
||||
|
||||
{}
|
||||
@@ -321,7 +321,7 @@ void DesignerActionManager::createDefaultDesignerActions()
|
||||
|
||||
addDesignerAction(new SelectionModelNodeAction(selectionCategoryDisplayName, selectionCategory, prioritySelectionCategory));
|
||||
|
||||
addDesignerAction(new MenuDesignerAction(stackCategoryDisplayName, stackCategory, priorityStackCategory, &selectionNotEmpty));
|
||||
addDesignerAction(new ActionGroup(stackCategoryDisplayName, stackCategory, priorityStackCategory, &selectionNotEmpty));
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(toFrontDisplayName, stackCategory, 200, &toFront, &singleSelection));
|
||||
addDesignerAction(new ModelNodeAction
|
||||
@@ -334,7 +334,7 @@ void DesignerActionManager::createDefaultDesignerActions()
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(resetZDisplayName, stackCategory, 100, &resetZ, &selectionNotEmptyAndHasZProperty));
|
||||
|
||||
addDesignerAction(new MenuDesignerAction(editCategoryDisplayName, editCategory, priorityEditCategory, &selectionNotEmpty));
|
||||
addDesignerAction(new ActionGroup(editCategoryDisplayName, editCategory, priorityEditCategory, &selectionNotEmpty));
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(resetPositionDisplayName, editCategory, 200, &resetPosition, &selectionNotEmptyAndHasXorYProperty));
|
||||
addDesignerAction(new ModelNodeAction
|
||||
@@ -342,14 +342,14 @@ void DesignerActionManager::createDefaultDesignerActions()
|
||||
addDesignerAction(new VisiblityModelNodeAction
|
||||
(visibilityDisplayName, editCategory, 160, &setVisible, &singleSelectedItem));
|
||||
|
||||
addDesignerAction(new MenuDesignerAction(anchorsCategoryDisplayName, anchorsCategory,
|
||||
addDesignerAction(new ActionGroup(anchorsCategoryDisplayName, anchorsCategory,
|
||||
priorityAnchorsCategory, &singleSelectionAndInBaseState));
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(anchorsFillDisplayName, anchorsCategory, 200, &anchorsFill, &singleSelectionItemIsNotAnchoredAndSingleSelectionNotRoot));
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(anchorsResetDisplayName, anchorsCategory, 180, &anchorsReset, &singleSelectionItemIsAnchored));
|
||||
|
||||
addDesignerAction(new MenuDesignerAction(layoutCategoryDisplayName, layoutCategory,
|
||||
addDesignerAction(new ActionGroup(layoutCategoryDisplayName, layoutCategory,
|
||||
priorityLayoutCategory, &layoutOptionVisible));
|
||||
addDesignerAction(new ModelNodeAction
|
||||
(layoutRowPositionerDisplayName,
|
||||
|
@@ -32,6 +32,7 @@
|
||||
|
||||
#include "modelnodeoperations.h"
|
||||
#include "defaultdesigneraction.h"
|
||||
#include "abstractactiongroup.h"
|
||||
#include "qmlitemnode.h"
|
||||
|
||||
#include <QAction>
|
||||
@@ -113,21 +114,18 @@ public /*slots*/:
|
||||
ModelNodeOperations::SelectionAction m_action;
|
||||
};
|
||||
|
||||
class MenuDesignerAction : public AbstractDesignerAction
|
||||
class ActionGroup : public AbstractActionGroup
|
||||
{
|
||||
public:
|
||||
MenuDesignerAction(const QString &displayName, const QByteArray &menuId, int priority,
|
||||
ActionGroup(const QString &displayName, const QByteArray &menuId, int priority,
|
||||
SelectionContextFunction enabled = &SelectionContextFunctors::always,
|
||||
SelectionContextFunction visibility = &SelectionContextFunctors::always) :
|
||||
m_displayName(displayName),
|
||||
AbstractActionGroup(displayName),
|
||||
m_menuId(menuId),
|
||||
m_priority(priority),
|
||||
m_menu(new QMenu),
|
||||
m_enabled(enabled),
|
||||
m_visibility(visibility)
|
||||
{
|
||||
m_menu->setTitle(displayName);
|
||||
m_action = m_menu->menuAction();
|
||||
}
|
||||
|
||||
bool isVisible(const SelectionContext &m_selectionState) const { return m_visibility(m_selectionState); }
|
||||
@@ -138,27 +136,9 @@ public:
|
||||
AbstractDesignerAction::Type type() const { return AbstractDesignerAction::Menu; }
|
||||
QAction *action() const { return m_action; }
|
||||
|
||||
virtual void currentContextChanged(const SelectionContext &selectionContext)
|
||||
{
|
||||
m_selectionContext = selectionContext;
|
||||
updateContext();
|
||||
}
|
||||
|
||||
virtual void updateContext()
|
||||
{
|
||||
if (m_selectionContext.isValid()) {
|
||||
m_action->setEnabled(isEnabled(m_selectionContext));
|
||||
m_action->setVisible(isVisible(m_selectionContext));
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
const QString m_displayName;
|
||||
const QByteArray m_menuId;
|
||||
const int m_priority;
|
||||
SelectionContext m_selectionContext;
|
||||
QScopedPointer<QMenu> m_menu;
|
||||
QAction *m_action;
|
||||
SelectionContextFunction m_enabled;
|
||||
SelectionContextFunction m_visibility;
|
||||
};
|
||||
|
Reference in New Issue
Block a user