From 058e593e4723b705ecd9b88c273daff7cbdd33f4 Mon Sep 17 00:00:00 2001 From: Marco Bubke <marco.bubke@digia.com> Date: Mon, 18 Mar 2013 18:17:38 +0100 Subject: [PATCH] Move DefaulDesignerAction in component core Change-Id: I18ff1a1128a1929c6f8cace42a93d5499c0cebdf Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> --- .../componentcore/abstractdesigneraction.h | 3 - .../componentcore/componentcore.pri | 2 + .../componentcore/defaultdesigneraction.cpp | 85 +++++++++++++++++++ .../componentcore/defaultdesigneraction.h | 78 +++++++++++++++++ .../componentcore/designeractionmanager.cpp | 16 ++-- .../modelnodecontextmenu_helper.h | 58 +------------ 6 files changed, 175 insertions(+), 67 deletions(-) create mode 100644 src/plugins/qmldesigner/components/componentcore/defaultdesigneraction.cpp create mode 100644 src/plugins/qmldesigner/components/componentcore/defaultdesigneraction.h diff --git a/src/plugins/qmldesigner/components/componentcore/abstractdesigneraction.h b/src/plugins/qmldesigner/components/componentcore/abstractdesigneraction.h index 2675ad512d..9182fd9c66 100644 --- a/src/plugins/qmldesigner/components/componentcore/abstractdesigneraction.h +++ b/src/plugins/qmldesigner/components/componentcore/abstractdesigneraction.h @@ -63,9 +63,6 @@ public: virtual Type type() const = 0; virtual void setCurrentContext(const SelectionContext &selectionState) = 0; -protected: - virtual bool isVisible(const SelectionContext &selectionState) const = 0; - virtual bool isEnabled(const SelectionContext &selectionState) const = 0; }; } //QmlDesigner diff --git a/src/plugins/qmldesigner/components/componentcore/componentcore.pri b/src/plugins/qmldesigner/components/componentcore/componentcore.pri index 271a585736..1b83834213 100644 --- a/src/plugins/qmldesigner/components/componentcore/componentcore.pri +++ b/src/plugins/qmldesigner/components/componentcore/componentcore.pri @@ -1,12 +1,14 @@ VPATH += $$PWD INCLUDEPATH += $$PWD SOURCES += modelnodecontextmenu.cpp +SOURCES += defaultdesigneraction.cpp SOURCES += modelnodecontextmenu_helper.cpp SOURCES += selectioncontext.cpp SOURCES += designeractionmanager.cpp SOURCES += modelnodeoperations.cpp HEADERS += modelnodecontextmenu.h +HEADERS += defaultdesigneraction.h HEADERS += modelnodecontextmenu_helper.h HEADERS += selectioncontext.h HEADERS += componentcore_constants.h diff --git a/src/plugins/qmldesigner/components/componentcore/defaultdesigneraction.cpp b/src/plugins/qmldesigner/components/componentcore/defaultdesigneraction.cpp new file mode 100644 index 0000000000..e9a1500948 --- /dev/null +++ b/src/plugins/qmldesigner/components/componentcore/defaultdesigneraction.cpp @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 "defaultdesigneraction.h" + +namespace QmlDesigner { + +DefaultDesignerAction::DefaultDesignerAction() + : m_action(new DefaultAction(QString())) +{ +} + +DefaultDesignerAction::DefaultDesignerAction(DefaultAction *action) + : m_action(action) +{ +} + +void DefaultDesignerAction::setCurrentContext(const SelectionContext &selectionContext) +{ + m_selectionContext = selectionContext; + updateContext(); +} + +void DefaultDesignerAction::updateContext() +{ + m_action->setSelectionContext(m_selectionContext); + if (m_selectionContext.isValid()) { + m_action->setEnabled(isEnabled(m_selectionContext)); + m_action->setVisible(isVisible(m_selectionContext)); + } +} + +DefaultAction *DefaultDesignerAction::defaultAction() const +{ + return m_action; +} + +SelectionContext DefaultDesignerAction::selectionContext() const +{ + return m_selectionContext; +} + +DefaultAction::DefaultAction(const QString &description) + : QAction(description, 0) +{ + connect(this, SIGNAL(triggered(bool)), this, SLOT(actionTriggered(bool))); +} + +void DefaultAction::actionTriggered(bool) +{ +} + +void DefaultAction::setSelectionContext(const SelectionContext &selectionContext) +{ + m_selectionContext = selectionContext; +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/componentcore/defaultdesigneraction.h b/src/plugins/qmldesigner/components/componentcore/defaultdesigneraction.h new file mode 100644 index 0000000000..fa0e287bdc --- /dev/null +++ b/src/plugins/qmldesigner/components/componentcore/defaultdesigneraction.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 QMLDESIGNER_DEFAULTDESIGNERACTION_H +#define QMLDESIGNER_DEFAULTDESIGNERACTION_H + +#include "abstractdesigneraction.h" + +#include <QAction> + +namespace QmlDesigner { + +class DefaultAction : public QAction +{ + Q_OBJECT + +public: + DefaultAction(const QString &description); + +public slots: //virtual method instead of slot + virtual void actionTriggered(bool); + void setSelectionContext(const SelectionContext &selectionContext); + +protected: + SelectionContext m_selectionContext; +}; + +class DefaultDesignerAction : public AbstractDesignerAction +{ +public: + DefaultDesignerAction(); + DefaultDesignerAction(DefaultAction *action); + + QAction *action() const { return m_action; } + void setCurrentContext(const SelectionContext &selectionContext); + +protected: + virtual void updateContext(); + virtual bool isVisible(const SelectionContext &selectionState) const = 0; + virtual bool isEnabled(const SelectionContext &selectionState) const = 0; + DefaultAction *defaultAction() const; + SelectionContext selectionContext() const; + +private: + DefaultAction *m_action; + SelectionContext m_selectionContext; +}; + +} // namespace QmlDesigner + +#endif // QMLDESIGNER_DEFAULTDESIGNERACTION_H diff --git a/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp b/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp index 819e2358d1..788eb7b7d8 100644 --- a/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp +++ b/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp @@ -235,17 +235,17 @@ public: {} virtual void updateContext() { - m_action->setSelectionContext(m_selectionContext); - if (m_selectionContext.isValid()) { - m_action->setEnabled(isEnabled(m_selectionContext)); - m_action->setVisible(isVisible(m_selectionContext)); + defaultAction()->setSelectionContext(selectionContext()); + if (selectionContext().isValid()) { + defaultAction()->setEnabled(isEnabled(selectionContext())); + defaultAction()->setVisible(isVisible(selectionContext())); - m_action->setCheckable(true); - QmlItemNode itemNode = QmlItemNode(m_selectionContext.currentSingleSelectedNode()); + defaultAction()->setCheckable(true); + QmlItemNode itemNode = QmlItemNode(selectionContext().currentSingleSelectedNode()); if (itemNode.isValid()) - m_action->setChecked(itemNode.instanceValue("visible").toBool()); + defaultAction()->setChecked(itemNode.instanceValue("visible").toBool()); else - m_action->setEnabled(false); + defaultAction()->setEnabled(false); } } }; diff --git a/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu_helper.h b/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu_helper.h index 3589943ba4..02399226c1 100644 --- a/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu_helper.h +++ b/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu_helper.h @@ -33,6 +33,7 @@ #include "modelnodecontextmenu.h" #include "modelnodeoperations.h" #include "designeractionmanager.h" +#include "defaultdesigneraction.h" #include <QAction> #include <QMenu> @@ -101,29 +102,6 @@ namespace ComponentUtils { void goIntoComponent(const ModelNode &modelNode); } -class DefaultAction : public QAction -{ - Q_OBJECT - -public: - DefaultAction(const QString &description) : QAction(description, 0) - { - connect(this, SIGNAL(triggered(bool)), this, SLOT(actionTriggered(bool))); - } - -public slots: //virtual method instead of slot - virtual void actionTriggered(bool) - { } - - void setSelectionContext(const SelectionContext &selectionContext) - { - m_selectionContext = selectionContext; - } - -protected: - SelectionContext m_selectionContext; -}; - class ActionTemplate : public DefaultAction { @@ -141,38 +119,6 @@ public /*slots*/: ModelNodeOperations::SelectionAction m_action; }; - -class DefaultDesignerAction : public AbstractDesignerAction -{ -public: - DefaultDesignerAction() : m_action(new DefaultAction(QString())) - {} - - DefaultDesignerAction(DefaultAction *action) : m_action(action) - {} - - QAction *action() const { return m_action; } - - void setCurrentContext(const SelectionContext &selectionContext) - { - m_selectionContext = selectionContext; - updateContext(); - } - - virtual void updateContext() - { - m_action->setSelectionContext(m_selectionContext); - if (m_selectionContext.isValid()) { - m_action->setEnabled(isEnabled(m_selectionContext)); - m_action->setVisible(isVisible(m_selectionContext)); - } - } - -protected: - DefaultAction *m_action; - SelectionContext m_selectionContext; -}; - class MenuDesignerAction : public AbstractDesignerAction { public: @@ -230,7 +176,7 @@ public: m_category(category), m_priority(priority), m_visibility(&SelectionContextFunctors::always) - { m_action->setSeparator(true); } + { defaultAction()->setSeparator(true); } bool isVisible(const SelectionContext &m_selectionState) const { return m_visibility(m_selectionState); } bool isEnabled(const SelectionContext &) const { return true; } -- GitLab