forked from qt-creator/qt-creator
ModelEditor: Add new button to open parent diagram
If the currently open diagram has a parent diagram (that is: a diagram in the package one hierarchy step up) it can now be opened by pressing a button in the toolbar. Default short cut is Ctrl+Shift+P. This change completes the navigation features. Change-Id: Ie073676644a6283842b2bbb0d14aca1dfe2706e7 Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
@@ -70,6 +70,11 @@ public:
|
||||
virtual void openDiagram(const MElement *) = 0;
|
||||
virtual void openDiagram(const DElement *, const MDiagram *) = 0;
|
||||
|
||||
virtual bool hasParentDiagram(const MElement *) const = 0;
|
||||
virtual bool hasParentDiagram(const DElement *, const MDiagram *) const = 0;
|
||||
virtual void openParentDiagram(const MElement *) = 0;
|
||||
virtual void openParentDiagram(const DElement *, const MElement *) = 0;
|
||||
|
||||
virtual bool mayCreateDiagram(const MElement *) const = 0;
|
||||
virtual bool mayCreateDiagram(const DElement *, const MDiagram *) const = 0;
|
||||
virtual void createAndOpenDiagram(const MElement *) = 0;
|
||||
|
||||
@@ -138,6 +138,24 @@ void VoidElementTasks::openDiagram(const DElement *, const MDiagram *)
|
||||
{
|
||||
}
|
||||
|
||||
bool VoidElementTasks::hasParentDiagram(const MElement *) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VoidElementTasks::hasParentDiagram(const DElement *, const MDiagram *) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void VoidElementTasks::openParentDiagram(const MElement *)
|
||||
{
|
||||
}
|
||||
|
||||
void VoidElementTasks::openParentDiagram(const DElement *, const MElement *)
|
||||
{
|
||||
}
|
||||
|
||||
bool VoidElementTasks::mayCreateDiagram(const MElement *) const
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -72,6 +72,11 @@ public:
|
||||
void openDiagram(const MElement *);
|
||||
void openDiagram(const DElement *, const MDiagram *);
|
||||
|
||||
bool hasParentDiagram(const MElement *) const;
|
||||
bool hasParentDiagram(const DElement *, const MDiagram *) const;
|
||||
void openParentDiagram(const MElement *);
|
||||
void openParentDiagram(const DElement *, const MElement *);
|
||||
|
||||
bool mayCreateDiagram(const qmt::MElement *) const;
|
||||
bool mayCreateDiagram(const qmt::DElement *, const qmt::MDiagram *) const;
|
||||
void createAndOpenDiagram(const qmt::MElement *);
|
||||
|
||||
@@ -56,6 +56,7 @@ public:
|
||||
QAction *removeAction = 0;
|
||||
QAction *deleteAction = 0;
|
||||
QAction *selectAllAction = 0;
|
||||
QAction *openParentDiagramAction = 0;
|
||||
};
|
||||
|
||||
ActionHandler::ActionHandler(const Core::Context &context, QObject *parent)
|
||||
@@ -110,6 +111,11 @@ QAction *ActionHandler::selectAllAction() const
|
||||
return d->selectAllAction;
|
||||
}
|
||||
|
||||
QAction *ActionHandler::openParentDiagramAction() const
|
||||
{
|
||||
return d->openParentDiagramAction;
|
||||
}
|
||||
|
||||
void ActionHandler::createActions()
|
||||
{
|
||||
Core::ActionContainer *medit = Core::ActionManager::actionContainer(Core::Constants::M_EDIT);
|
||||
@@ -130,6 +136,10 @@ void ActionHandler::createActions()
|
||||
medit->addAction(deleteCommand, Core::Constants::G_EDIT_COPYPASTE);
|
||||
d->deleteAction = deleteCommand->action();
|
||||
d->selectAllAction = registerCommand(Core::Constants::SELECTALL, [this]() { selectAll(); })->action();
|
||||
d->openParentDiagramAction = registerCommand(
|
||||
Constants::OPEN_PARENT_DIAGRAM, [this]() { openParentDiagram(); }, true,
|
||||
tr("Open Parent Diagram"), QKeySequence(QStringLiteral("Ctrl+Shift+P")))->action();
|
||||
d->openParentDiagramAction->setIcon(QIcon(QStringLiteral(":/modeleditor/up.png")));
|
||||
registerCommand(Constants::ACTION_ADD_PACKAGE, nullptr);
|
||||
registerCommand(Constants::ACTION_ADD_COMPONENT, nullptr);
|
||||
registerCommand(Constants::ACTION_ADD_CLASS, nullptr);
|
||||
@@ -201,6 +211,13 @@ void ActionHandler::selectAll()
|
||||
editor->selectAll();
|
||||
}
|
||||
|
||||
void ActionHandler::openParentDiagram()
|
||||
{
|
||||
auto editor = dynamic_cast<ModelEditor *>(Core::EditorManager::currentEditor());
|
||||
if (editor)
|
||||
editor->openParentDiagram();
|
||||
}
|
||||
|
||||
void ActionHandler::onEditProperties()
|
||||
{
|
||||
auto editor = qobject_cast<ModelEditor *>(Core::EditorManager::currentEditor());
|
||||
|
||||
@@ -68,6 +68,7 @@ public:
|
||||
QAction *removeAction() const;
|
||||
QAction *deleteAction() const;
|
||||
QAction *selectAllAction() const;
|
||||
QAction *openParentDiagramAction() const;
|
||||
|
||||
void createActions();
|
||||
void createEditPropertiesShortcut(const Core::Id &shortcutId);
|
||||
@@ -81,6 +82,7 @@ private slots:
|
||||
void removeSelectedElements();
|
||||
void deleteSelectedElements();
|
||||
void selectAll();
|
||||
void openParentDiagram();
|
||||
void onEditProperties();
|
||||
|
||||
private:
|
||||
|
||||
@@ -302,6 +302,66 @@ void ElementTasks::openDiagram(const qmt::DElement *element, const qmt::MDiagram
|
||||
openDiagram(melement);
|
||||
}
|
||||
|
||||
bool ElementTasks::hasParentDiagram(const qmt::MElement *element) const
|
||||
{
|
||||
if (element && element->getOwner()) {
|
||||
qmt::MObject *parentObject = element->getOwner()->getOwner();
|
||||
if (parentObject) {
|
||||
qmt::FindDiagramVisitor visitor;
|
||||
parentObject->accept(&visitor);
|
||||
const qmt::MDiagram *parentDiagram = visitor.getDiagram();
|
||||
if (parentDiagram) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ElementTasks::hasParentDiagram(const qmt::DElement *element, const qmt::MDiagram *diagram) const
|
||||
{
|
||||
Q_UNUSED(diagram);
|
||||
|
||||
if (!element)
|
||||
return false;
|
||||
|
||||
qmt::MElement *melement = d->documentController->getModelController()->findElement(element->getModelUid());
|
||||
if (!melement)
|
||||
return false;
|
||||
return hasParentDiagram(melement);
|
||||
}
|
||||
|
||||
void ElementTasks::openParentDiagram(const qmt::MElement *element)
|
||||
{
|
||||
if (element && element->getOwner()) {
|
||||
qmt::MObject *parentObject = element->getOwner()->getOwner();
|
||||
if (parentObject) {
|
||||
qmt::FindDiagramVisitor visitor;
|
||||
parentObject->accept(&visitor);
|
||||
const qmt::MDiagram *parentDiagram = visitor.getDiagram();
|
||||
if (parentDiagram) {
|
||||
ModelEditorPlugin::modelsManager()->openDiagram(
|
||||
d->documentController->getProjectController()->getProject()->getUid(),
|
||||
parentDiagram->getUid());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ElementTasks::openParentDiagram(const qmt::DElement *element, const qmt::MElement *diagram)
|
||||
{
|
||||
Q_UNUSED(diagram);
|
||||
|
||||
if (!element)
|
||||
return;
|
||||
|
||||
qmt::MElement *melement = d->documentController->getModelController()->findElement(element->getModelUid());
|
||||
if (!melement)
|
||||
return;
|
||||
openParentDiagram(melement);
|
||||
}
|
||||
|
||||
bool ElementTasks::mayCreateDiagram(const qmt::MElement *element) const
|
||||
{
|
||||
return dynamic_cast<const qmt::MPackage *>(element) != 0;
|
||||
|
||||
@@ -77,6 +77,11 @@ public:
|
||||
void openDiagram(const qmt::MElement *element) override;
|
||||
void openDiagram(const qmt::DElement *element, const qmt::MDiagram *diagram) override;
|
||||
|
||||
bool hasParentDiagram(const qmt::MElement *element) const;
|
||||
bool hasParentDiagram(const qmt::DElement *element, const qmt::MDiagram *diagram) const;
|
||||
void openParentDiagram(const qmt::MElement *element);
|
||||
void openParentDiagram(const qmt::DElement *element, const qmt::MElement *diagram);
|
||||
|
||||
bool mayCreateDiagram(const qmt::MElement *element) const override;
|
||||
bool mayCreateDiagram(const qmt::DElement *element,
|
||||
const qmt::MDiagram *diagram) const override;
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
#include "qmt/style/style.h"
|
||||
#include "qmt/style/stylecontroller.h"
|
||||
#include "qmt/tasks/diagramscenecontroller.h"
|
||||
#include "qmt/tasks/finddiagramvisitor.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
@@ -283,11 +284,17 @@ void ModelEditor::init(QWidget *parent)
|
||||
auto toolbarLayout = new QHBoxLayout(d->toolbar);
|
||||
toolbarLayout->setContentsMargins(0, 0, 0, 0);
|
||||
toolbarLayout->setSpacing(0);
|
||||
|
||||
auto openParentButton = new Core::CommandButton(Constants::OPEN_PARENT_DIAGRAM, d->toolbar);
|
||||
openParentButton->setDefaultAction(d->actionHandler->openParentDiagramAction());
|
||||
toolbarLayout->addWidget(openParentButton);
|
||||
|
||||
d->diagramSelector = new QComboBox(d->toolbar);
|
||||
connect(d->diagramSelector, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated),
|
||||
this, &ModelEditor::onDiagramSelectorSelected);
|
||||
toolbarLayout->addWidget(d->diagramSelector, 1);
|
||||
toolbarLayout->addStretch(1);
|
||||
|
||||
toolbarLayout->addWidget(createToolbarCommandButton(
|
||||
Constants::ACTION_ADD_PACKAGE, [this]() { onAddPackage(); },
|
||||
QIcon(QStringLiteral(":/modelinglib/48x48/package.png")),
|
||||
@@ -483,6 +490,13 @@ void ModelEditor::selectAll()
|
||||
d->document->documentController()->selectAllOnDiagram(currentDiagram());
|
||||
}
|
||||
|
||||
void ModelEditor::openParentDiagram()
|
||||
{
|
||||
qmt::MDiagram *diagram = currentDiagram();
|
||||
if (diagram)
|
||||
d->document->documentController()->elementTasks()->openParentDiagram(diagram);
|
||||
}
|
||||
|
||||
void ModelEditor::editProperties()
|
||||
{
|
||||
d->propertiesView->editSelectedElement();
|
||||
@@ -525,6 +539,7 @@ void ModelEditor::updateSelectedArea(SelectedArea selectedArea)
|
||||
bool canPaste = false;
|
||||
bool canSelectAll = false;
|
||||
bool canCopyDiagram = false;
|
||||
bool canOpenParentDiagram = false;
|
||||
QList<qmt::MElement *> propertiesModelElements;
|
||||
QList<qmt::DElement *> propertiesDiagramElements;
|
||||
qmt::MDiagram *propertiesDiagram = 0;
|
||||
@@ -578,6 +593,7 @@ void ModelEditor::updateSelectedArea(SelectedArea selectedArea)
|
||||
break;
|
||||
}
|
||||
}
|
||||
canOpenParentDiagram = d->document->documentController()->elementTasks()->hasParentDiagram(currentDiagram());
|
||||
|
||||
d->actionHandler->cutAction()->setEnabled(canCutCopyDelete);
|
||||
d->actionHandler->copyAction()->setEnabled(canCutCopyDelete || canCopyDiagram);
|
||||
@@ -585,6 +601,7 @@ void ModelEditor::updateSelectedArea(SelectedArea selectedArea)
|
||||
d->actionHandler->removeAction()->setEnabled(canRemove);
|
||||
d->actionHandler->deleteAction()->setEnabled(canCutCopyDelete);
|
||||
d->actionHandler->selectAllAction()->setEnabled(canSelectAll);
|
||||
d->actionHandler->openParentDiagramAction()->setEnabled(canOpenParentDiagram);
|
||||
|
||||
if (!propertiesModelElements.isEmpty())
|
||||
showProperties(propertiesModelElements);
|
||||
|
||||
@@ -88,6 +88,7 @@ public:
|
||||
void removeSelectedElements();
|
||||
void deleteSelectedElements();
|
||||
void selectAll();
|
||||
void openParentDiagram();
|
||||
void editProperties();
|
||||
qmt::MPackage *guessSelectedPackage() const;
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ const char MODEL_EDITOR_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("OpenWith::Editors",
|
||||
|
||||
const char REMOVE_SELECTED_ELEMENTS[] = "ModelEditor.RemoveSelectedElements";
|
||||
const char DELETE_SELECTED_ELEMENTS[] = "ModelEditor.DeleteSelectedElements";
|
||||
const char OPEN_PARENT_DIAGRAM[] = "ModelEditor.OpenParentDiagram";
|
||||
const char ACTION_ADD_PACKAGE[] = "ModelEditor.Action.AddPackage";
|
||||
const char ACTION_ADD_COMPONENT[] = "ModelEditor.Action.AddComponent";
|
||||
const char ACTION_ADD_CLASS[] = "ModelEditor.Action.AddClass";
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<RCC>
|
||||
<qresource prefix="/modeleditor">
|
||||
<file>modeleditor.mimetypes.xml</file>
|
||||
<file>up.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
BIN
src/plugins/modeleditor/resources/up.png
Normal file
BIN
src/plugins/modeleditor/resources/up.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 889 B |
Reference in New Issue
Block a user