Commit ee17a71a authored by Jochen Becher's avatar Jochen Becher

Modeling: add separate function to update include dependencies

Change-Id: Icdcec9beac4b889ef22941824b993ddd2b26cf56
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
parent 7a18978e
......@@ -304,14 +304,11 @@ bool ClassItem::extendContextMenu(QMenu *menu)
return extended;
}
bool ClassItem::handleSelectedContextMenuAction(QAction *action)
bool ClassItem::handleSelectedContextMenuAction(const QString &id)
{
auto klassAction = dynamic_cast<ContextMenuAction *>(action);
if (klassAction) {
if (klassAction->id() == QStringLiteral("showDefinition")) {
diagramSceneModel()->diagramSceneController()->elementTasks()->openClassDefinition(object(), diagramSceneModel()->diagram());
return true;
}
if (id == QStringLiteral("showDefinition")) {
diagramSceneModel()->diagramSceneController()->elementTasks()->openClassDefinition(object(), diagramSceneModel()->diagram());
return true;
}
return false;
}
......
......@@ -67,7 +67,7 @@ public:
protected:
bool extendContextMenu(QMenu *menu) override;
bool handleSelectedContextMenuAction(QAction *action) override;
bool handleSelectedContextMenuAction(const QString &id) override;
QString buildDisplayName() const override;
void setFromDisplayName(const QString &displayName) override;
......
......@@ -697,9 +697,9 @@ bool ObjectItem::extendContextMenu(QMenu *menu)
return false;
}
bool ObjectItem::handleSelectedContextMenuAction(QAction *action)
bool ObjectItem::handleSelectedContextMenuAction(const QString &id)
{
Q_UNUSED(action);
Q_UNUSED(id);
return false;
}
......@@ -736,17 +736,20 @@ void ObjectItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
void ObjectItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
QMenu menu;
IElementTasks *element_tasks = diagramSceneModel()->diagramSceneController()->elementTasks();
bool addSeparator = false;
if (diagramSceneModel()->diagramSceneController()->elementTasks()->hasDiagram(m_object, m_diagramSceneModel->diagram())) {
if (element_tasks->hasDiagram(m_object, m_diagramSceneModel->diagram())) {
menu.addAction(new ContextMenuAction(tr("Open Diagram"), QStringLiteral("openDiagram"), &menu));
addSeparator = true;
} else if (diagramSceneModel()->diagramSceneController()->elementTasks()->mayCreateDiagram(m_object, m_diagramSceneModel->diagram())) {
} else if (element_tasks->mayCreateDiagram(m_object, m_diagramSceneModel->diagram())) {
menu.addAction(new ContextMenuAction(tr("Create Diagram"), QStringLiteral("createDiagram"), &menu));
addSeparator = true;
}
if (extendContextMenu(&menu))
addSeparator = true;
if (element_tasks->extendContextMenu(object(), diagramSceneModel()->diagram(), &menu))
addSeparator = true;
if (addSeparator)
menu.addSeparator();
menu.addAction(new ContextMenuAction(tr("Remove"), QStringLiteral("remove"),
......@@ -774,9 +777,11 @@ void ObjectItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
QAction *selectedAction = menu.exec(event->screenPos());
if (selectedAction) {
if (!handleSelectedContextMenuAction(selectedAction)) {
auto action = dynamic_cast<ContextMenuAction *>(selectedAction);
QMT_CHECK(action);
auto action = dynamic_cast<ContextMenuAction *>(selectedAction);
QMT_CHECK(action);
bool handled = handleSelectedContextMenuAction(action->id());
handled |= element_tasks->handleContextMenuAction(object(), diagramSceneModel()->diagram(), action->id());
if (!handled) {
if (action->id() == QStringLiteral("openDiagram")) {
m_diagramSceneModel->diagramSceneController()->elementTasks()->openDiagram(m_object, m_diagramSceneModel->diagram());
} else if (action->id() == QStringLiteral("createDiagram")) {
......
......@@ -147,7 +147,7 @@ protected:
bool showContext() const;
virtual bool extendContextMenu(QMenu *menu);
virtual bool handleSelectedContextMenuAction(QAction *action);
virtual bool handleSelectedContextMenuAction(const QString &id);
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
......
......@@ -25,11 +25,12 @@
#pragma once
#include "qmt_global.h"
#include <QAction>
namespace qmt {
class ContextMenuAction : public QAction
class QMT_EXPORT ContextMenuAction : public QAction
{
public:
ContextMenuAction(const QString &label, const QString &id, QObject *parent = 0);
......
......@@ -25,6 +25,9 @@
#pragma once
class QMenu;
class QString;
namespace qmt {
class MElement;
......@@ -73,6 +76,9 @@ public:
virtual bool mayCreateDiagram(const DElement *, const MDiagram *) const = 0;
virtual void createAndOpenDiagram(const MElement *) = 0;
virtual void createAndOpenDiagram(const DElement *, const MDiagram *) = 0;
virtual bool extendContextMenu(const DElement *, const MDiagram *, QMenu *) = 0;
virtual bool handleContextMenuAction(const DElement *, const MDiagram *, const QString &) = 0;
};
} // namespace qmt
......@@ -169,4 +169,14 @@ void VoidElementTasks::createAndOpenDiagram(const DElement *, const MDiagram *)
{
}
bool VoidElementTasks::extendContextMenu(const DElement *, const MDiagram *, QMenu *)
{
return false;
}
bool VoidElementTasks::handleContextMenuAction(const DElement *, const MDiagram *, const QString &)
{
return false;
}
} // namespace qmt
......@@ -68,10 +68,13 @@ public:
void openParentDiagram(const MElement *) override;
void openParentDiagram(const DElement *, const MElement *) override;
bool mayCreateDiagram(const qmt::MElement *) const override;
bool mayCreateDiagram(const qmt::DElement *, const qmt::MDiagram *) const override;
void createAndOpenDiagram(const qmt::MElement *) override;
void createAndOpenDiagram(const qmt::DElement *, const qmt::MDiagram *) override;
bool mayCreateDiagram(const MElement *) const override;
bool mayCreateDiagram(const DElement *, const MDiagram *) const override;
void createAndOpenDiagram(const MElement *) override;
void createAndOpenDiagram(const DElement *, const MDiagram *) override;
bool extendContextMenu(const DElement *, const MDiagram *, QMenu *) override;
bool handleContextMenuAction(const DElement *, const MDiagram *, const QString &) override;
};
} // namespace qmt
......@@ -46,7 +46,8 @@
#include <QFileInfo>
// TODO this class is experimental and not finished. Code needs fixes and to be cleaned up!
// TODO implement removing include dependencies that are not longer used
// TODO refactor add/remove relations between ancestor packages into extra controller class
namespace ModelEditor {
namespace Internal {
......@@ -209,6 +210,7 @@ void UpdateIncludeDependenciesVisitor::visitMComponent(qmt::MComponent *componen
if (!haveDependency(componentAncestors.at(index1), includeComponentAncestors.at(index2))) {
auto dependency = new qmt::MDependency;
dependency->setFlags(qmt::MElement::ReverseEngineered);
// TODO set stereotype for testing purpose
dependency->setStereotypes(QStringList() << QStringLiteral("same stereotype"));
dependency->setDirection(qmt::MDependency::AToB);
dependency->setSource(componentAncestors.at(index1)->uid());
......@@ -229,6 +231,7 @@ void UpdateIncludeDependenciesVisitor::visitMComponent(qmt::MComponent *componen
if (!haveDependency(componentAncestors.at(componentHighestAncestorIndex), includeComponentAncestors)) {
auto dependency = new qmt::MDependency;
dependency->setFlags(qmt::MElement::ReverseEngineered);
// TODO set stereotype for testing purpose
dependency->setStereotypes(QStringList() << QStringLiteral("ancestor"));
dependency->setDirection(qmt::MDependency::AToB);
dependency->setSource(componentAncestors.at(componentHighestAncestorIndex)->uid());
......@@ -243,6 +246,7 @@ void UpdateIncludeDependenciesVisitor::visitMComponent(qmt::MComponent *componen
if (!haveDependency(componentAncestors.at(0), includeComponentAncestors)) {
auto dependency = new qmt::MDependency;
dependency->setFlags(qmt::MElement::ReverseEngineered);
// TODO set stereotype for testing purpose
dependency->setStereotypes(QStringList() << QStringLiteral("parents"));
dependency->setDirection(qmt::MDependency::AToB);
dependency->setSource(componentAncestors.at(0)->uid());
......
......@@ -28,9 +28,12 @@
#include "modelsmanager.h"
#include "openelementvisitor.h"
#include "modeleditor_plugin.h"
#include "componentviewcontroller.h"
#include "qmt/diagram/delement.h"
#include "qmt/diagram/dpackage.h"
#include "qmt/document_controller/documentcontroller.h"
#include "qmt/infrastructure/contextmenuaction.h"
#include "qmt/model/melement.h"
#include "qmt/model/mclass.h"
#include "qmt/model/mdiagram.h"
......@@ -49,16 +52,20 @@
#include <coreplugin/locator/ilocatorfilter.h>
#include <utils/qtcassert.h>
#include <QMenu>
namespace ModelEditor {
namespace Internal {
class ElementTasks::ElementTasksPrivate {
public:
qmt::DocumentController *documentController = 0;
ComponentViewController *componentViewController = 0;
};
ElementTasks::ElementTasks()
: d(new ElementTasksPrivate)
ElementTasks::ElementTasks(QObject *parent)
: QObject(parent),
d(new ElementTasksPrivate)
{
}
......@@ -72,6 +79,11 @@ void ElementTasks::setDocumentController(qmt::DocumentController *documentContro
d->documentController = documentController;
}
void ElementTasks::setComponentViewController(ComponentViewController *componentViewController)
{
d->componentViewController = componentViewController;
}
void ElementTasks::openElement(const qmt::MElement *element)
{
OpenModelElementVisitor visitor;
......@@ -408,5 +420,26 @@ void ElementTasks::createAndOpenDiagram(const qmt::DElement *element, const qmt:
createAndOpenDiagram(melement);
}
bool ElementTasks::extendContextMenu(const qmt::DElement *delement, const qmt::MDiagram *, QMenu *menu)
{
bool extended = false;
if (dynamic_cast<const qmt::DPackage *>(delement)) {
menu->addAction(new qmt::ContextMenuAction(tr("Update Include Dependencies"), QStringLiteral("updateIncludeDependencies"), menu));
extended = true;
}
return extended;
}
bool ElementTasks::handleContextMenuAction(const qmt::DElement *element, const qmt::MDiagram *, const QString &id)
{
if (id == "updateIncludeDependencies") {
qmt::MPackage *mpackage = d->documentController->modelController()->findElement<qmt::MPackage>(element->modelUid());
if (mpackage)
d->componentViewController->updateIncludeDependencies(mpackage);
return true;
}
return false;
}
} // namespace Internal
} // namespace ModelEditor
......@@ -25,6 +25,7 @@
#pragma once
#include <QObject>
#include "qmt/tasks/ielementtasks.h"
namespace qmt { class DocumentController; }
......@@ -32,16 +33,21 @@ namespace qmt { class DocumentController; }
namespace ModelEditor {
namespace Internal {
class ComponentViewController;
class ElementTasks :
public qmt::IElementTasks
public QObject, public qmt::IElementTasks
{
Q_OBJECT
class ElementTasksPrivate;
public:
ElementTasks();
ElementTasks(QObject *parent = 0);
~ElementTasks();
void setDocumentController(qmt::DocumentController *documentController);
void setComponentViewController(ComponentViewController *componentViewController);
void openElement(const qmt::MElement *element) override;
void openElement(const qmt::DElement *element, const qmt::MDiagram *diagram) override;
......@@ -82,6 +88,9 @@ public:
void createAndOpenDiagram(const qmt::MElement *element) override;
void createAndOpenDiagram(const qmt::DElement *element, const qmt::MDiagram *diagram) override;
bool extendContextMenu(const qmt::DElement *delement, const qmt::MDiagram *, QMenu *menu) override;
bool handleContextMenuAction(const qmt::DElement *element, const qmt::MDiagram *, const QString &id) override;
private:
ElementTasksPrivate *d;
};
......
......@@ -46,9 +46,10 @@ ExtDocumentController::ExtDocumentController(QObject *parent)
: qmt::DocumentController(parent),
d(new ExtDocumentControllerPrivate)
{
d->elementTasks = new ElementTasks;
d->elementTasks = new ElementTasks(this);
d->pxNodeController = new PxNodeController(this);
d->elementTasks->setDocumentController(this);
d->elementTasks->setComponentViewController(d->pxNodeController->componentViewController());
diagramSceneController()->setElementTasks(d->elementTasks);
d->pxNodeController->setDiagramSceneController(diagramSceneController());
......@@ -59,7 +60,6 @@ ExtDocumentController::ExtDocumentController(QObject *parent)
ExtDocumentController::~ExtDocumentController()
{
delete d->elementTasks;
delete d;
}
......
......@@ -113,6 +113,11 @@ PxNodeController::~PxNodeController()
delete d;
}
ComponentViewController *PxNodeController::componentViewController() const
{
return d->componentViewController;
}
void PxNodeController::setDiagramSceneController(
qmt::DiagramSceneController *diagramSceneController)
{
......
......@@ -39,6 +39,8 @@ class DiagramSceneController;
namespace ModelEditor {
namespace Internal {
class ComponentViewController;
class PxNodeController :
public QObject
{
......@@ -50,6 +52,8 @@ public:
explicit PxNodeController(QObject *parent = 0);
~PxNodeController();
ComponentViewController *componentViewController() const;
void setDiagramSceneController(qmt::DiagramSceneController *diagramSceneController);
void setAnchorFolder(const QString &anchorFolder);
......
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