Commit 058e593e authored by Marco Bubke's avatar Marco Bubke
Browse files

Move DefaulDesignerAction in component core



Change-Id: I18ff1a1128a1929c6f8cace42a93d5499c0cebdf
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent 7e5551a2
...@@ -63,9 +63,6 @@ public: ...@@ -63,9 +63,6 @@ public:
virtual Type type() const = 0; virtual Type type() const = 0;
virtual void setCurrentContext(const SelectionContext &selectionState) = 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 } //QmlDesigner
......
VPATH += $$PWD VPATH += $$PWD
INCLUDEPATH += $$PWD INCLUDEPATH += $$PWD
SOURCES += modelnodecontextmenu.cpp SOURCES += modelnodecontextmenu.cpp
SOURCES += defaultdesigneraction.cpp
SOURCES += modelnodecontextmenu_helper.cpp SOURCES += modelnodecontextmenu_helper.cpp
SOURCES += selectioncontext.cpp SOURCES += selectioncontext.cpp
SOURCES += designeractionmanager.cpp SOURCES += designeractionmanager.cpp
SOURCES += modelnodeoperations.cpp SOURCES += modelnodeoperations.cpp
HEADERS += modelnodecontextmenu.h HEADERS += modelnodecontextmenu.h
HEADERS += defaultdesigneraction.h
HEADERS += modelnodecontextmenu_helper.h HEADERS += modelnodecontextmenu_helper.h
HEADERS += selectioncontext.h HEADERS += selectioncontext.h
HEADERS += componentcore_constants.h HEADERS += componentcore_constants.h
......
/****************************************************************************
**
** 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
/****************************************************************************
**
** 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
...@@ -235,17 +235,17 @@ public: ...@@ -235,17 +235,17 @@ public:
{} {}
virtual void updateContext() virtual void updateContext()
{ {
m_action->setSelectionContext(m_selectionContext); defaultAction()->setSelectionContext(selectionContext());
if (m_selectionContext.isValid()) { if (selectionContext().isValid()) {
m_action->setEnabled(isEnabled(m_selectionContext)); defaultAction()->setEnabled(isEnabled(selectionContext()));
m_action->setVisible(isVisible(m_selectionContext)); defaultAction()->setVisible(isVisible(selectionContext()));
m_action->setCheckable(true); defaultAction()->setCheckable(true);
QmlItemNode itemNode = QmlItemNode(m_selectionContext.currentSingleSelectedNode()); QmlItemNode itemNode = QmlItemNode(selectionContext().currentSingleSelectedNode());
if (itemNode.isValid()) if (itemNode.isValid())
m_action->setChecked(itemNode.instanceValue("visible").toBool()); defaultAction()->setChecked(itemNode.instanceValue("visible").toBool());
else else
m_action->setEnabled(false); defaultAction()->setEnabled(false);
} }
} }
}; };
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "modelnodecontextmenu.h" #include "modelnodecontextmenu.h"
#include "modelnodeoperations.h" #include "modelnodeoperations.h"
#include "designeractionmanager.h" #include "designeractionmanager.h"
#include "defaultdesigneraction.h"
#include <QAction> #include <QAction>
#include <QMenu> #include <QMenu>
...@@ -101,29 +102,6 @@ namespace ComponentUtils { ...@@ -101,29 +102,6 @@ namespace ComponentUtils {
void goIntoComponent(const ModelNode &modelNode); 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 class ActionTemplate : public DefaultAction
{ {
...@@ -141,38 +119,6 @@ public /*slots*/: ...@@ -141,38 +119,6 @@ public /*slots*/:
ModelNodeOperations::SelectionAction m_action; 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 class MenuDesignerAction : public AbstractDesignerAction
{ {
public: public:
...@@ -230,7 +176,7 @@ public: ...@@ -230,7 +176,7 @@ public:
m_category(category), m_category(category),
m_priority(priority), m_priority(priority),
m_visibility(&SelectionContextFunctors::always) m_visibility(&SelectionContextFunctors::always)
{ m_action->setSeparator(true); } { defaultAction()->setSeparator(true); }
bool isVisible(const SelectionContext &m_selectionState) const { return m_visibility(m_selectionState); } bool isVisible(const SelectionContext &m_selectionState) const { return m_visibility(m_selectionState); }
bool isEnabled(const SelectionContext &) const { return true; } bool isEnabled(const SelectionContext &) const { return true; }
......
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