2015-08-31 18:06:36 +02:00
|
|
|
/***************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2015 Jochen Becher
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
|
|
|
|
**
|
|
|
|
|
** 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 The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "modeleditor.h"
|
|
|
|
|
|
2015-09-21 12:11:02 +02:00
|
|
|
#include "actionhandler.h"
|
|
|
|
|
#include "diagramsviewmanager.h"
|
|
|
|
|
#include "dragtool.h"
|
|
|
|
|
#include "editordiagramview.h"
|
|
|
|
|
#include "elementtasks.h"
|
2015-08-31 18:06:36 +02:00
|
|
|
#include "extdocumentcontroller.h"
|
2015-09-21 12:11:02 +02:00
|
|
|
#include "modeldocument.h"
|
|
|
|
|
#include "modeleditor_constants.h"
|
|
|
|
|
#include "modeleditor_plugin.h"
|
|
|
|
|
#include "modelsmanager.h"
|
|
|
|
|
#include "openelementvisitor.h"
|
|
|
|
|
#include "uicontroller.h"
|
2015-08-31 18:06:36 +02:00
|
|
|
|
2015-09-21 12:11:02 +02:00
|
|
|
#include "qmt/controller/undocontroller.h"
|
|
|
|
|
#include "qmt/diagram/dpackage.h"
|
|
|
|
|
#include "qmt/diagram_controller/diagramcontroller.h"
|
|
|
|
|
#include "qmt/diagram_controller/dselection.h"
|
|
|
|
|
#include "qmt/diagram_scene/diagramscenemodel.h"
|
|
|
|
|
#include "qmt/diagram_ui/diagram_mime_types.h"
|
2015-08-31 18:06:36 +02:00
|
|
|
#include "qmt/diagram_ui/diagramsmanager.h"
|
2015-09-21 12:11:02 +02:00
|
|
|
#include "qmt/model/mpackage.h"
|
|
|
|
|
#include "qmt/model/mclass.h"
|
|
|
|
|
#include "qmt/model/mcomponent.h"
|
2015-08-31 18:06:36 +02:00
|
|
|
#include "qmt/model/mcanvasdiagram.h"
|
|
|
|
|
#include "qmt/model_controller/modelcontroller.h"
|
2015-09-21 12:11:02 +02:00
|
|
|
#include "qmt/model_controller/mselection.h"
|
|
|
|
|
#include "qmt/model_ui/treemodel.h"
|
|
|
|
|
#include "qmt/model_ui/treemodelmanager.h"
|
|
|
|
|
#include "qmt/model_widgets_ui/modeltreeview.h"
|
|
|
|
|
#include "qmt/model_widgets_ui/propertiesview.h"
|
|
|
|
|
#include "qmt/stereotype/shapepaintvisitor.h"
|
|
|
|
|
#include "qmt/stereotype/stereotypecontroller.h"
|
|
|
|
|
#include "qmt/stereotype/stereotypeicon.h"
|
|
|
|
|
#include "qmt/stereotype/toolbar.h"
|
|
|
|
|
#include "qmt/style/style.h"
|
|
|
|
|
#include "qmt/style/stylecontroller.h"
|
|
|
|
|
#include "qmt/tasks/diagramscenecontroller.h"
|
2015-09-25 17:18:50 +02:00
|
|
|
#include "qmt/tasks/finddiagramvisitor.h"
|
2015-08-31 18:06:36 +02:00
|
|
|
|
2015-09-21 12:11:02 +02:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <coreplugin/minisplitter.h>
|
|
|
|
|
#include <coreplugin/actionmanager/commandbutton.h>
|
|
|
|
|
#include <utils/styledbar.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
|
|
#include <QAction>
|
2015-09-25 09:47:34 +02:00
|
|
|
#include <QComboBox>
|
2015-09-21 12:11:02 +02:00
|
|
|
#include <QDir>
|
|
|
|
|
#include <QEvent>
|
2015-08-31 18:06:36 +02:00
|
|
|
#include <QFileInfo>
|
2015-09-21 12:11:02 +02:00
|
|
|
#include <QFrame>
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QMap>
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
#include <QPixmap>
|
|
|
|
|
#include <QScrollArea>
|
|
|
|
|
#include <QStackedWidget>
|
|
|
|
|
#include <QStyleFactory>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
#include <QToolBox>
|
|
|
|
|
#include <QUndoStack>
|
|
|
|
|
#include <QVBoxLayout>
|
2015-08-31 18:06:36 +02:00
|
|
|
|
|
|
|
|
namespace ModelEditor {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class ModelEditor::ModelEditorPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
2015-09-21 12:11:02 +02:00
|
|
|
UiController *uiController = 0;
|
|
|
|
|
ActionHandler *actionHandler = 0;
|
2015-08-31 18:06:36 +02:00
|
|
|
ModelDocument *document = 0;
|
2015-09-21 12:11:02 +02:00
|
|
|
qmt::PropertiesView *propertiesView = 0;
|
|
|
|
|
Core::MiniSplitter *rightSplitter = 0;
|
|
|
|
|
QWidget *leftGroup = 0;
|
|
|
|
|
QHBoxLayout *leftGroupLayout = 0;
|
|
|
|
|
QToolBox *leftToolBox = 0;
|
|
|
|
|
QStackedWidget *diagramStack = 0;
|
|
|
|
|
EditorDiagramView *diagramView = 0;
|
|
|
|
|
QLabel *noDiagramLabel = 0;
|
|
|
|
|
DiagramsViewManager *diagramsViewManager = 0;
|
|
|
|
|
Core::MiniSplitter *rightHorizSplitter = 0;
|
|
|
|
|
qmt::ModelTreeView *modelTreeView = 0;
|
|
|
|
|
qmt::TreeModelManager *modelTreeViewServant = 0;
|
|
|
|
|
QScrollArea *propertiesScrollArea = 0;
|
|
|
|
|
QWidget *propertiesGroupWidget = 0;
|
|
|
|
|
QWidget *toolbar = 0;
|
2015-09-25 09:47:34 +02:00
|
|
|
QComboBox *diagramSelector = 0;
|
2015-09-21 12:11:02 +02:00
|
|
|
SelectedArea selectedArea = SelectedArea::Nothing;
|
2015-08-31 18:06:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ModelEditor::ModelEditor(UiController *uiController, ActionHandler *actionHandler, QWidget *parent)
|
2015-09-21 12:11:02 +02:00
|
|
|
: IEditor(parent),
|
2015-08-31 18:06:36 +02:00
|
|
|
d(new ModelEditorPrivate)
|
|
|
|
|
{
|
|
|
|
|
setContext(Core::Context(Constants::MODEL_EDITOR_ID));
|
2015-09-21 12:11:02 +02:00
|
|
|
d->uiController = uiController;
|
|
|
|
|
d->actionHandler = actionHandler;
|
2015-08-31 18:06:36 +02:00
|
|
|
d->document = new ModelDocument(this);
|
|
|
|
|
connect(d->document, &ModelDocument::contentSet, this, &ModelEditor::onContentSet);
|
|
|
|
|
init(parent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ModelEditor::~ModelEditor()
|
|
|
|
|
{
|
2015-09-25 15:25:23 +02:00
|
|
|
closeCurrentDiagram(false);
|
2015-09-21 12:11:02 +02:00
|
|
|
delete d->toolbar;
|
2015-08-31 18:06:36 +02:00
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::IDocument *ModelEditor::document()
|
|
|
|
|
{
|
|
|
|
|
return d->document;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 12:11:02 +02:00
|
|
|
QWidget *ModelEditor::toolBar()
|
|
|
|
|
{
|
|
|
|
|
return d->toolbar;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-25 15:25:23 +02:00
|
|
|
QByteArray ModelEditor::saveState() const
|
|
|
|
|
{
|
|
|
|
|
return saveState(currentDiagram());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ModelEditor::restoreState(const QByteArray &state)
|
|
|
|
|
{
|
|
|
|
|
QDataStream stream(state);
|
|
|
|
|
int version = 0;
|
|
|
|
|
stream >> version;
|
|
|
|
|
if (version == 1) {
|
|
|
|
|
qmt::Uid uid;
|
|
|
|
|
stream >> uid;
|
|
|
|
|
if (uid.isValid()) {
|
2015-11-04 22:44:41 +01:00
|
|
|
qmt::MDiagram *diagram = d->document->documentController()->modelController()->findObject<qmt::MDiagram>(uid);
|
2015-09-25 15:25:23 +02:00
|
|
|
if (diagram) {
|
|
|
|
|
openDiagram(diagram, false);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 12:11:02 +02:00
|
|
|
void ModelEditor::init(QWidget *parent)
|
|
|
|
|
{
|
|
|
|
|
// create and configure properties view
|
|
|
|
|
d->propertiesView = new qmt::PropertiesView(this);
|
|
|
|
|
|
|
|
|
|
// create and configure editor ui
|
|
|
|
|
d->rightSplitter = new Core::MiniSplitter(parent);
|
|
|
|
|
connect(d->rightSplitter, &QSplitter::splitterMoved,
|
|
|
|
|
this, &ModelEditor::onRightSplitterMoved);
|
|
|
|
|
connect(d->uiController, &UiController::rightSplitterChanged,
|
|
|
|
|
this, &ModelEditor::onRightSplitterChanged);
|
|
|
|
|
|
|
|
|
|
d->leftGroup = new QWidget(d->rightSplitter);
|
|
|
|
|
d->leftGroupLayout = new QHBoxLayout(d->leftGroup);
|
|
|
|
|
d->leftGroupLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
d->leftGroupLayout->setSpacing(0);
|
|
|
|
|
|
|
|
|
|
d->leftToolBox = new QToolBox(d->leftGroup);
|
|
|
|
|
// Windows style does not truncate the tab label to a very small width (GTK+ does)
|
|
|
|
|
static QStyle *windowsStyle = QStyleFactory().create(QStringLiteral("Windows"));
|
|
|
|
|
if (windowsStyle)
|
|
|
|
|
d->leftToolBox->setStyle(windowsStyle);
|
|
|
|
|
// TODO improve this (and the diagram colors) for use with dark theme
|
|
|
|
|
d->leftToolBox->setStyleSheet(
|
|
|
|
|
QLatin1String("QToolBox::tab {"
|
|
|
|
|
" margin-left: 2px;"
|
|
|
|
|
" background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
|
|
|
|
|
" stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,"
|
|
|
|
|
" stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);"
|
|
|
|
|
" color: #606060;"
|
|
|
|
|
"}"
|
|
|
|
|
""
|
|
|
|
|
"QToolBox::tab:selected {"
|
|
|
|
|
" font: italic;"
|
|
|
|
|
" color: black;"
|
|
|
|
|
"}"));
|
|
|
|
|
QFont font = d->leftToolBox->font();
|
|
|
|
|
font.setPointSizeF(font.pointSizeF() * 0.8);
|
|
|
|
|
d->leftToolBox->setFont(font);
|
|
|
|
|
|
|
|
|
|
d->diagramStack = new QStackedWidget(d->leftGroup);
|
|
|
|
|
|
|
|
|
|
d->diagramView = new EditorDiagramView(d->diagramStack);
|
|
|
|
|
d->diagramStack->addWidget(d->diagramView);
|
|
|
|
|
|
|
|
|
|
d->noDiagramLabel = new QLabel(d->diagramStack);
|
|
|
|
|
const QString placeholderText = tr("<html><body style=\"color:#909090; font-size:14px\">"
|
|
|
|
|
"<div align='center'>"
|
|
|
|
|
"<div style=\"font-size:20px\">Open a diagram</div>"
|
|
|
|
|
"<table><tr><td>"
|
|
|
|
|
"<hr/>"
|
|
|
|
|
"<div style=\"margin-top: 5px\">• Double-click on diagram in model tree</div>"
|
|
|
|
|
"<div style=\"margin-top: 5px\">• Select \"Open Diagram\" from package's context menu in model tree</div>"
|
|
|
|
|
"</td></tr></table>"
|
|
|
|
|
"</div>"
|
|
|
|
|
"</body></html>");
|
|
|
|
|
d->noDiagramLabel->setText(placeholderText);
|
|
|
|
|
d->diagramStack->addWidget(d->noDiagramLabel);
|
|
|
|
|
d->diagramStack->setCurrentWidget(d->noDiagramLabel);
|
|
|
|
|
|
|
|
|
|
d->leftGroupLayout->addWidget(d->leftToolBox, 0);
|
|
|
|
|
auto frame = new QFrame(d->leftGroup);
|
|
|
|
|
frame->setFrameShape(QFrame::VLine);
|
|
|
|
|
d->leftGroupLayout->addWidget(frame, 0);
|
|
|
|
|
d->leftGroupLayout->addWidget(d->diagramStack, 1);
|
|
|
|
|
|
|
|
|
|
d->rightHorizSplitter = new Core::MiniSplitter(d->rightSplitter);
|
|
|
|
|
d->rightHorizSplitter->setOrientation(Qt::Vertical);
|
|
|
|
|
connect(d->rightHorizSplitter, &QSplitter::splitterMoved,
|
|
|
|
|
this, &ModelEditor::onRightHorizSplitterMoved);
|
|
|
|
|
connect(d->uiController, &UiController::rightHorizSplitterChanged,
|
|
|
|
|
this, &ModelEditor::onRightHorizSplitterChanged);
|
|
|
|
|
|
|
|
|
|
d->modelTreeView = new qmt::ModelTreeView(d->rightHorizSplitter);
|
|
|
|
|
d->modelTreeView->setFrameShape(QFrame::NoFrame);
|
|
|
|
|
|
|
|
|
|
d->modelTreeViewServant = new qmt::TreeModelManager(this);
|
|
|
|
|
d->modelTreeViewServant->setModelTreeView(d->modelTreeView);
|
|
|
|
|
|
|
|
|
|
d->propertiesScrollArea = new QScrollArea(d->rightHorizSplitter);
|
|
|
|
|
d->propertiesScrollArea->setFrameShape(QFrame::NoFrame);
|
|
|
|
|
d->propertiesScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
2015-10-06 20:35:07 +02:00
|
|
|
d->propertiesScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
2015-09-21 12:11:02 +02:00
|
|
|
d->propertiesScrollArea->setWidgetResizable(true);
|
|
|
|
|
|
|
|
|
|
d->rightHorizSplitter->insertWidget(0, d->modelTreeView);
|
|
|
|
|
d->rightHorizSplitter->insertWidget(1, d->propertiesScrollArea);
|
|
|
|
|
d->rightHorizSplitter->setStretchFactor(0, 2); // magic stretch factors for equal sizing
|
|
|
|
|
d->rightHorizSplitter->setStretchFactor(1, 3);
|
|
|
|
|
|
|
|
|
|
d->rightSplitter->insertWidget(0, d->leftGroup);
|
|
|
|
|
d->rightSplitter->insertWidget(1, d->rightHorizSplitter);
|
|
|
|
|
d->rightSplitter->setStretchFactor(0, 1);
|
|
|
|
|
d->rightSplitter->setStretchFactor(1, 0);
|
|
|
|
|
|
|
|
|
|
setWidget(d->rightSplitter);
|
|
|
|
|
|
|
|
|
|
// restore splitter sizes after any stretch factor has been set as fallback
|
|
|
|
|
if (d->uiController->hasRightSplitterState())
|
|
|
|
|
d->rightSplitter->restoreState(d->uiController->rightSplitterState());
|
|
|
|
|
if (d->uiController->hasRightHorizSplitterState())
|
|
|
|
|
d->rightHorizSplitter->restoreState(d->uiController->rightHorizSplitterState());
|
|
|
|
|
|
|
|
|
|
// create and configure toolbar
|
|
|
|
|
d->toolbar = new QWidget();
|
|
|
|
|
auto toolbarLayout = new QHBoxLayout(d->toolbar);
|
|
|
|
|
toolbarLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
toolbarLayout->setSpacing(0);
|
2015-09-25 17:18:50 +02:00
|
|
|
|
|
|
|
|
auto openParentButton = new Core::CommandButton(Constants::OPEN_PARENT_DIAGRAM, d->toolbar);
|
|
|
|
|
openParentButton->setDefaultAction(d->actionHandler->openParentDiagramAction());
|
|
|
|
|
toolbarLayout->addWidget(openParentButton);
|
|
|
|
|
|
2015-09-25 09:47:34 +02:00
|
|
|
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);
|
2015-09-25 17:18:50 +02:00
|
|
|
|
2015-09-21 12:11:02 +02:00
|
|
|
toolbarLayout->addWidget(createToolbarCommandButton(
|
|
|
|
|
Constants::ACTION_ADD_PACKAGE, [this]() { onAddPackage(); },
|
|
|
|
|
QIcon(QStringLiteral(":/modelinglib/48x48/package.png")),
|
|
|
|
|
tr("Add Package"), d->toolbar));
|
|
|
|
|
toolbarLayout->addWidget(createToolbarCommandButton(
|
|
|
|
|
Constants::ACTION_ADD_COMPONENT, [this]() { onAddComponent(); },
|
|
|
|
|
QIcon(QStringLiteral(":/modelinglib/48x48/component.png")),
|
|
|
|
|
tr("Add Component"), d->toolbar));
|
|
|
|
|
toolbarLayout->addWidget(createToolbarCommandButton(
|
|
|
|
|
Constants::ACTION_ADD_CLASS, [this]() { onAddClass(); },
|
|
|
|
|
QIcon(QStringLiteral(":/modelinglib/48x48/class.png")),
|
|
|
|
|
tr("Add Class"), d->toolbar));
|
|
|
|
|
toolbarLayout->addWidget(createToolbarCommandButton(
|
|
|
|
|
Constants::ACTION_ADD_CANVAS_DIAGRAM, [this]() { onAddCanvasDiagram(); },
|
|
|
|
|
QIcon(QStringLiteral(":/modelinglib/48x48/canvas-diagram.png")),
|
|
|
|
|
tr("Add Canvas Diagram"), d->toolbar));
|
2015-09-25 09:47:34 +02:00
|
|
|
toolbarLayout->addSpacing(20);
|
2015-09-21 12:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::initDocument()
|
|
|
|
|
{
|
|
|
|
|
initToolbars();
|
|
|
|
|
|
|
|
|
|
ExtDocumentController *documentController = d->document->documentController();
|
|
|
|
|
|
|
|
|
|
d->diagramView->setPxNodeController(documentController->pxNodeController());
|
|
|
|
|
|
|
|
|
|
QTC_CHECK(!d->diagramsViewManager);
|
|
|
|
|
d->diagramsViewManager = new DiagramsViewManager(this);
|
|
|
|
|
//connect(diagramsViewManager, &DiagramsViewManager::someDiagramOpened,
|
2015-11-04 22:44:41 +01:00
|
|
|
// documentController->diagramsManager(), &qmt::DiagramsManager::someDiagramOpened);
|
2015-09-21 12:11:02 +02:00
|
|
|
connect(d->diagramsViewManager, &DiagramsViewManager::openNewDiagram,
|
|
|
|
|
this, &ModelEditor::showDiagram);
|
|
|
|
|
connect(d->diagramsViewManager, &DiagramsViewManager::closeOpenDiagram,
|
|
|
|
|
this, &ModelEditor::closeDiagram);
|
|
|
|
|
connect(d->diagramsViewManager, &DiagramsViewManager::closeAllOpenDiagrams,
|
|
|
|
|
this, &ModelEditor::closeAllDiagrams);
|
2015-11-04 22:44:41 +01:00
|
|
|
documentController->diagramsManager()->setDiagramsView(d->diagramsViewManager);
|
2015-09-21 12:11:02 +02:00
|
|
|
|
2015-11-04 22:44:41 +01:00
|
|
|
d->propertiesView->setDiagramController(documentController->diagramController());
|
|
|
|
|
d->propertiesView->setModelController(documentController->modelController());
|
|
|
|
|
d->propertiesView->setStereotypeController(documentController->stereotypeController());
|
|
|
|
|
d->propertiesView->setStyleController(documentController->styleController());
|
2015-09-21 12:11:02 +02:00
|
|
|
|
2015-11-04 22:44:41 +01:00
|
|
|
d->modelTreeView->setTreeModel(documentController->sortedTreeModel());
|
2015-09-21 12:11:02 +02:00
|
|
|
d->modelTreeView->setElementTasks(documentController->elementTasks());
|
|
|
|
|
|
2015-11-04 22:44:41 +01:00
|
|
|
d->modelTreeViewServant->setTreeModel(documentController->treeModel());
|
2015-09-21 12:11:02 +02:00
|
|
|
|
|
|
|
|
connect(documentController, &qmt::DocumentController::diagramClipboardChanged,
|
|
|
|
|
this, &ModelEditor::onDiagramClipboardChanged, Qt::QueuedConnection);
|
2015-11-04 22:44:41 +01:00
|
|
|
connect(documentController->undoController()->undoStack(), &QUndoStack::canUndoChanged,
|
2015-09-21 12:11:02 +02:00
|
|
|
this, &ModelEditor::onCanUndoChanged, Qt::QueuedConnection);
|
2015-11-04 22:44:41 +01:00
|
|
|
connect(documentController->undoController()->undoStack(), &QUndoStack::canRedoChanged,
|
2015-09-21 12:11:02 +02:00
|
|
|
this, &ModelEditor::onCanRedoChanged, Qt::QueuedConnection);
|
2015-11-04 22:44:41 +01:00
|
|
|
connect(documentController->treeModel(), &qmt::TreeModel::modelReset,
|
2015-09-21 12:11:02 +02:00
|
|
|
this, &ModelEditor::onTreeModelReset, Qt::QueuedConnection);
|
2015-11-04 22:44:41 +01:00
|
|
|
connect(documentController->diagramController(), &qmt::DiagramController::modified,
|
2015-09-21 12:11:02 +02:00
|
|
|
this, &ModelEditor::onDiagramModified, Qt::QueuedConnection);
|
2015-11-04 22:44:41 +01:00
|
|
|
connect(documentController->diagramsManager(), &qmt::DiagramsManager::diagramSelectionChanged,
|
2015-09-21 12:11:02 +02:00
|
|
|
this, &ModelEditor::onDiagramSelectionChanged, Qt::QueuedConnection);
|
2015-11-04 22:44:41 +01:00
|
|
|
connect(documentController->diagramsManager(), &qmt::DiagramsManager::diagramActivated,
|
2015-09-21 12:11:02 +02:00
|
|
|
this, &ModelEditor::onDiagramActivated, Qt::QueuedConnection);
|
2015-11-04 22:44:41 +01:00
|
|
|
connect(documentController->diagramSceneController(), &qmt::DiagramSceneController::newElementCreated,
|
2015-09-21 12:11:02 +02:00
|
|
|
this, &ModelEditor::onNewElementCreated, Qt::QueuedConnection);
|
|
|
|
|
|
|
|
|
|
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged,
|
|
|
|
|
this, &ModelEditor::onCurrentEditorChanged, Qt::QueuedConnection);
|
|
|
|
|
|
|
|
|
|
connect(d->modelTreeView->selectionModel(), &QItemSelectionModel::selectionChanged,
|
|
|
|
|
this, &ModelEditor::onTreeViewSelectionChanged, Qt::QueuedConnection);
|
|
|
|
|
connect(d->modelTreeView, &qmt::ModelTreeView::treeViewActivated,
|
|
|
|
|
this, &ModelEditor::onTreeViewActivated, Qt::QueuedConnection);
|
|
|
|
|
connect(d->modelTreeView, &QAbstractItemView::doubleClicked,
|
|
|
|
|
this, &ModelEditor::onTreeViewDoubleClicked, Qt::QueuedConnection);
|
|
|
|
|
|
2015-11-04 22:44:41 +01:00
|
|
|
connect(documentController->modelController(), &qmt::ModelController::endMoveObject,
|
2015-09-25 09:47:34 +02:00
|
|
|
this, &ModelEditor::updateDiagramSelector);
|
2015-11-04 22:44:41 +01:00
|
|
|
connect(documentController->modelController(), &qmt::ModelController::endRemoveObject,
|
2015-09-25 09:47:34 +02:00
|
|
|
this, &ModelEditor::updateDiagramSelector);
|
2015-11-04 22:44:41 +01:00
|
|
|
connect(documentController->modelController(), &qmt::ModelController::endResetModel,
|
2015-09-25 09:47:34 +02:00
|
|
|
this, &ModelEditor::updateDiagramSelector);
|
2015-11-04 22:44:41 +01:00
|
|
|
connect(documentController->modelController(), &qmt::ModelController::endUpdateObject,
|
2015-09-25 09:47:34 +02:00
|
|
|
this, &ModelEditor::updateDiagramSelector);
|
|
|
|
|
|
2015-09-21 12:11:02 +02:00
|
|
|
updateSelectedArea(SelectedArea::Nothing);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qmt::MDiagram *ModelEditor::currentDiagram() const
|
|
|
|
|
{
|
2015-11-04 22:44:41 +01:00
|
|
|
if (!d->diagramView->diagramSceneModel())
|
2015-09-21 12:11:02 +02:00
|
|
|
return 0;
|
2015-11-04 22:44:41 +01:00
|
|
|
return d->diagramView->diagramSceneModel()->diagram();
|
2015-09-21 12:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::showDiagram(qmt::MDiagram *diagram)
|
|
|
|
|
{
|
2015-09-25 15:25:23 +02:00
|
|
|
openDiagram(diagram, true);
|
2015-09-21 12:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::undo()
|
|
|
|
|
{
|
2015-11-04 22:44:41 +01:00
|
|
|
d->document->documentController()->undoController()->undoStack()->undo();
|
2015-09-21 12:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::redo()
|
|
|
|
|
{
|
2015-11-04 22:44:41 +01:00
|
|
|
d->document->documentController()->undoController()->undoStack()->redo();
|
2015-09-21 12:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::cut()
|
|
|
|
|
{
|
|
|
|
|
ExtDocumentController *documentController = d->document->documentController();
|
|
|
|
|
|
|
|
|
|
switch (d->selectedArea) {
|
|
|
|
|
case SelectedArea::Nothing:
|
|
|
|
|
break;
|
|
|
|
|
case SelectedArea::Diagram:
|
|
|
|
|
documentController->cutFromDiagram(currentDiagram());
|
|
|
|
|
break;
|
|
|
|
|
case SelectedArea::TreeView:
|
2015-11-04 22:44:41 +01:00
|
|
|
documentController->cutFromModel(d->modelTreeViewServant->selectedObjects());
|
2015-09-21 12:11:02 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::copy()
|
|
|
|
|
{
|
|
|
|
|
ExtDocumentController *documentController = d->document->documentController();
|
|
|
|
|
|
|
|
|
|
switch (d->selectedArea) {
|
|
|
|
|
case SelectedArea::Nothing:
|
|
|
|
|
break;
|
|
|
|
|
case SelectedArea::Diagram:
|
|
|
|
|
if (documentController->hasDiagramSelection(currentDiagram()))
|
|
|
|
|
documentController->copyFromDiagram(currentDiagram());
|
|
|
|
|
else
|
|
|
|
|
documentController->copyDiagram(currentDiagram());
|
|
|
|
|
break;
|
|
|
|
|
case SelectedArea::TreeView:
|
2015-11-04 22:44:41 +01:00
|
|
|
documentController->copyFromModel(d->modelTreeViewServant->selectedObjects());
|
2015-09-21 12:11:02 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::paste()
|
|
|
|
|
{
|
|
|
|
|
ExtDocumentController *documentController = d->document->documentController();
|
|
|
|
|
|
|
|
|
|
switch (d->selectedArea) {
|
|
|
|
|
case SelectedArea::Nothing:
|
|
|
|
|
break;
|
|
|
|
|
case SelectedArea::Diagram:
|
|
|
|
|
documentController->pasteIntoDiagram(currentDiagram());
|
|
|
|
|
break;
|
|
|
|
|
case SelectedArea::TreeView:
|
2015-11-04 22:44:41 +01:00
|
|
|
documentController->pasteIntoModel(d->modelTreeViewServant->selectedObject());
|
2015-09-21 12:11:02 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::removeSelectedElements()
|
|
|
|
|
{
|
|
|
|
|
switch (d->selectedArea) {
|
|
|
|
|
case SelectedArea::Nothing:
|
|
|
|
|
break;
|
|
|
|
|
case SelectedArea::Diagram:
|
|
|
|
|
d->document->documentController()->removeFromDiagram(currentDiagram());
|
|
|
|
|
break;
|
|
|
|
|
case SelectedArea::TreeView:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::deleteSelectedElements()
|
|
|
|
|
{
|
|
|
|
|
ExtDocumentController *documentController = d->document->documentController();
|
|
|
|
|
|
|
|
|
|
switch (d->selectedArea) {
|
|
|
|
|
case SelectedArea::Nothing:
|
|
|
|
|
break;
|
|
|
|
|
case SelectedArea::Diagram:
|
|
|
|
|
documentController->deleteFromDiagram(currentDiagram());
|
|
|
|
|
break;
|
|
|
|
|
case SelectedArea::TreeView:
|
2015-11-04 22:44:41 +01:00
|
|
|
documentController->deleteFromModel(d->modelTreeViewServant->selectedObjects());
|
2015-09-21 12:11:02 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::selectAll()
|
|
|
|
|
{
|
|
|
|
|
d->document->documentController()->selectAllOnDiagram(currentDiagram());
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-25 17:18:50 +02:00
|
|
|
void ModelEditor::openParentDiagram()
|
|
|
|
|
{
|
|
|
|
|
qmt::MDiagram *diagram = currentDiagram();
|
|
|
|
|
if (diagram)
|
|
|
|
|
d->document->documentController()->elementTasks()->openParentDiagram(diagram);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 12:11:02 +02:00
|
|
|
void ModelEditor::editProperties()
|
|
|
|
|
{
|
|
|
|
|
d->propertiesView->editSelectedElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qmt::MPackage *ModelEditor::guessSelectedPackage() const
|
|
|
|
|
{
|
|
|
|
|
qmt::MPackage *package = 0;
|
|
|
|
|
switch (d->selectedArea) {
|
|
|
|
|
case SelectedArea::Nothing:
|
2015-11-04 22:44:41 +01:00
|
|
|
package = d->modelTreeViewServant->selectedPackage();
|
2015-09-21 12:11:02 +02:00
|
|
|
break;
|
|
|
|
|
case SelectedArea::Diagram:
|
|
|
|
|
{
|
|
|
|
|
qmt::DocumentController *documentController = d->document->documentController();
|
2015-11-04 22:44:41 +01:00
|
|
|
qmt::DiagramsManager *diagramsManager = documentController->diagramsManager();
|
2015-09-21 12:11:02 +02:00
|
|
|
qmt::MDiagram *diagram = currentDiagram();
|
2015-11-04 22:44:41 +01:00
|
|
|
qmt::DSelection selection = diagramsManager->diagramSceneModel(diagram)->selectedElements();
|
|
|
|
|
if (selection.indices().size() == 1) {
|
|
|
|
|
qmt::DPackage *diagramElement = documentController->diagramController()->findElement<qmt::DPackage>(selection.indices().at(0).elementKey(), diagram);
|
2015-09-21 12:11:02 +02:00
|
|
|
if (diagramElement)
|
2015-11-04 22:44:41 +01:00
|
|
|
package = documentController->modelController()->findObject<qmt::MPackage>(diagramElement->modelUid());
|
2015-09-21 12:11:02 +02:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SelectedArea::TreeView:
|
2015-11-04 22:44:41 +01:00
|
|
|
package = d->modelTreeViewServant->selectedPackage();
|
2015-09-21 12:11:02 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return package;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::updateSelectedArea(SelectedArea selectedArea)
|
|
|
|
|
{
|
|
|
|
|
d->selectedArea = selectedArea;
|
|
|
|
|
|
|
|
|
|
qmt::DocumentController *documentController = d->document->documentController();
|
|
|
|
|
bool canCutCopyDelete = false;
|
|
|
|
|
bool canRemove = false;
|
|
|
|
|
bool canPaste = false;
|
|
|
|
|
bool canSelectAll = false;
|
|
|
|
|
bool canCopyDiagram = false;
|
2015-09-25 17:18:50 +02:00
|
|
|
bool canOpenParentDiagram = false;
|
2015-09-21 12:11:02 +02:00
|
|
|
QList<qmt::MElement *> propertiesModelElements;
|
|
|
|
|
QList<qmt::DElement *> propertiesDiagramElements;
|
|
|
|
|
qmt::MDiagram *propertiesDiagram = 0;
|
|
|
|
|
|
|
|
|
|
qmt::MDiagram *activeDiagram = currentDiagram();
|
|
|
|
|
switch (d->selectedArea) {
|
|
|
|
|
case SelectedArea::Nothing:
|
2015-11-04 22:44:41 +01:00
|
|
|
canSelectAll = activeDiagram && !activeDiagram->diagramElements().isEmpty();
|
2015-09-21 12:11:02 +02:00
|
|
|
break;
|
|
|
|
|
case SelectedArea::Diagram:
|
|
|
|
|
{
|
|
|
|
|
if (activeDiagram) {
|
2015-11-04 22:44:41 +01:00
|
|
|
bool hasSelection = documentController->diagramsManager()->diagramSceneModel(activeDiagram)->hasSelection();
|
2015-09-21 12:11:02 +02:00
|
|
|
canCutCopyDelete = hasSelection;
|
|
|
|
|
canRemove = hasSelection;
|
|
|
|
|
canPaste = !documentController->isDiagramClipboardEmpty();
|
2015-11-04 22:44:41 +01:00
|
|
|
canSelectAll = !activeDiagram->diagramElements().isEmpty();
|
2015-09-21 12:11:02 +02:00
|
|
|
canCopyDiagram = !hasSelection;
|
|
|
|
|
if (hasSelection) {
|
2015-11-04 22:44:41 +01:00
|
|
|
qmt::DSelection selection = documentController->diagramsManager()->diagramSceneModel(activeDiagram)->selectedElements();
|
2015-09-21 12:11:02 +02:00
|
|
|
if (!selection.isEmpty()) {
|
2015-11-04 22:44:41 +01:00
|
|
|
foreach (qmt::DSelection::Index index, selection.indices()) {
|
|
|
|
|
qmt::DElement *diagramElement = documentController->diagramController()->findElement(index.elementKey(), activeDiagram);
|
2015-09-21 12:11:02 +02:00
|
|
|
if (diagramElement)
|
|
|
|
|
propertiesDiagramElements.append(diagramElement);
|
|
|
|
|
}
|
|
|
|
|
if (!propertiesDiagramElements.isEmpty())
|
|
|
|
|
propertiesDiagram = activeDiagram;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SelectedArea::TreeView:
|
|
|
|
|
{
|
2015-11-04 22:44:41 +01:00
|
|
|
bool hasSelection = !d->modelTreeViewServant->selectedObjects().isEmpty();
|
|
|
|
|
bool hasSingleSelection = d->modelTreeViewServant->selectedObjects().indices().size() == 1;
|
2015-09-21 12:11:02 +02:00
|
|
|
canCutCopyDelete = hasSelection && !d->modelTreeViewServant->isRootPackageSelected();
|
|
|
|
|
canPaste = hasSingleSelection && !documentController->isModelClipboardEmpty();
|
2015-11-04 22:44:41 +01:00
|
|
|
canSelectAll = activeDiagram && !activeDiagram->diagramElements().isEmpty();
|
|
|
|
|
QModelIndexList indexes = d->modelTreeView->selectedSourceModelIndexes();
|
2015-09-21 12:11:02 +02:00
|
|
|
if (!indexes.isEmpty()) {
|
|
|
|
|
foreach (const QModelIndex &propertiesIndex, indexes) {
|
|
|
|
|
if (propertiesIndex.isValid()) {
|
2015-11-04 22:44:41 +01:00
|
|
|
qmt::MElement *modelElement = documentController->treeModel()->element(propertiesIndex);
|
2015-09-21 12:11:02 +02:00
|
|
|
if (modelElement)
|
|
|
|
|
propertiesModelElements.append(modelElement);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-09-25 17:18:50 +02:00
|
|
|
canOpenParentDiagram = d->document->documentController()->elementTasks()->hasParentDiagram(currentDiagram());
|
2015-09-21 12:11:02 +02:00
|
|
|
|
|
|
|
|
d->actionHandler->cutAction()->setEnabled(canCutCopyDelete);
|
|
|
|
|
d->actionHandler->copyAction()->setEnabled(canCutCopyDelete || canCopyDiagram);
|
|
|
|
|
d->actionHandler->pasteAction()->setEnabled(canPaste);
|
|
|
|
|
d->actionHandler->removeAction()->setEnabled(canRemove);
|
|
|
|
|
d->actionHandler->deleteAction()->setEnabled(canCutCopyDelete);
|
|
|
|
|
d->actionHandler->selectAllAction()->setEnabled(canSelectAll);
|
2015-09-25 17:18:50 +02:00
|
|
|
d->actionHandler->openParentDiagramAction()->setEnabled(canOpenParentDiagram);
|
2015-09-21 12:11:02 +02:00
|
|
|
|
|
|
|
|
if (!propertiesModelElements.isEmpty())
|
|
|
|
|
showProperties(propertiesModelElements);
|
|
|
|
|
else if (!propertiesDiagramElements.isEmpty())
|
|
|
|
|
showProperties(propertiesDiagram, propertiesDiagramElements);
|
|
|
|
|
else
|
|
|
|
|
clearProperties();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::showProperties(const QList<qmt::MElement *> &modelElements)
|
|
|
|
|
{
|
2015-11-04 22:44:41 +01:00
|
|
|
if (modelElements != d->propertiesView->selectedModelElements()) {
|
2015-09-21 12:11:02 +02:00
|
|
|
clearProperties();
|
|
|
|
|
if (modelElements.size() > 0) {
|
|
|
|
|
d->propertiesView->setSelectedModelElements(modelElements);
|
2015-11-04 22:44:41 +01:00
|
|
|
d->propertiesGroupWidget = d->propertiesView->widget();
|
2015-09-21 12:11:02 +02:00
|
|
|
d->propertiesScrollArea->setWidget(d->propertiesGroupWidget);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::showProperties(qmt::MDiagram *diagram,
|
|
|
|
|
const QList<qmt::DElement *> &diagramElements)
|
|
|
|
|
{
|
2015-11-04 22:44:41 +01:00
|
|
|
if (diagram != d->propertiesView->selectedDiagram()
|
|
|
|
|
|| diagramElements != d->propertiesView->selectedDiagramElements())
|
2015-09-21 12:11:02 +02:00
|
|
|
{
|
|
|
|
|
clearProperties();
|
|
|
|
|
if (diagram && diagramElements.size() > 0) {
|
|
|
|
|
d->propertiesView->setSelectedDiagramElements(diagramElements, diagram);
|
2015-11-04 22:44:41 +01:00
|
|
|
d->propertiesGroupWidget = d->propertiesView->widget();
|
2015-09-21 12:11:02 +02:00
|
|
|
d->propertiesScrollArea->setWidget(d->propertiesGroupWidget);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::clearProperties()
|
|
|
|
|
{
|
|
|
|
|
d->propertiesView->clearSelection();
|
|
|
|
|
if (d->propertiesGroupWidget) {
|
|
|
|
|
QWidget *scrollWidget = d->propertiesScrollArea->takeWidget();
|
|
|
|
|
Q_UNUSED(scrollWidget); // avoid warning in release mode
|
|
|
|
|
QTC_CHECK(scrollWidget == d->propertiesGroupWidget);
|
|
|
|
|
d->propertiesGroupWidget->deleteLater();
|
|
|
|
|
d->propertiesGroupWidget = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::expandModelTreeToDepth(int depth)
|
|
|
|
|
{
|
|
|
|
|
d->modelTreeView->expandToDepth(depth);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *ModelEditor::createToolbarCommandButton(const Core::Id &id, const std::function<void()> &slot,
|
|
|
|
|
const QIcon &icon, const QString &toolTipBase,
|
|
|
|
|
QWidget *parent)
|
|
|
|
|
{
|
|
|
|
|
auto button = new Core::CommandButton(id, parent);
|
|
|
|
|
button->setIcon(icon);
|
|
|
|
|
button->setToolTipBase(toolTipBase);
|
|
|
|
|
connect(button, &Core::CommandButton::clicked, this, slot);
|
|
|
|
|
return button;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Tries to change the \a button icon to the icon specified by \a name
|
|
|
|
|
from the current theme. Returns \c true if icon is updated, \c false
|
|
|
|
|
otherwise.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
bool ModelEditor::updateButtonIconByTheme(QAbstractButton *button, const QString &name)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(button, return false);
|
|
|
|
|
QTC_ASSERT(!name.isEmpty(), return false);
|
|
|
|
|
|
|
|
|
|
if (QIcon::hasThemeIcon(name)) {
|
|
|
|
|
button->setIcon(QIcon::fromTheme(name));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::onAddPackage()
|
|
|
|
|
{
|
|
|
|
|
ExtDocumentController *documentController = d->document->documentController();
|
|
|
|
|
|
2015-11-04 22:44:41 +01:00
|
|
|
qmt::MPackage *package = documentController->createNewPackage(d->modelTreeViewServant->selectedPackage());
|
|
|
|
|
d->modelTreeView->selectFromSourceModelIndex(documentController->treeModel()->index(package));
|
2015-09-21 12:11:02 +02:00
|
|
|
QTimer::singleShot(0, this, [this]() { onEditSelectedElement(); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::onAddComponent()
|
|
|
|
|
{
|
|
|
|
|
ExtDocumentController *documentController = d->document->documentController();
|
|
|
|
|
|
2015-11-04 22:44:41 +01:00
|
|
|
qmt::MComponent *component = documentController->createNewComponent(d->modelTreeViewServant->selectedPackage());
|
|
|
|
|
d->modelTreeView->selectFromSourceModelIndex(documentController->treeModel()->index(component));
|
2015-09-21 12:11:02 +02:00
|
|
|
QTimer::singleShot(0, this, [this]() { onEditSelectedElement(); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::onAddClass()
|
|
|
|
|
{
|
|
|
|
|
ExtDocumentController *documentController = d->document->documentController();
|
|
|
|
|
|
2015-11-04 22:44:41 +01:00
|
|
|
qmt::MClass *klass = documentController->createNewClass(d->modelTreeViewServant->selectedPackage());
|
|
|
|
|
d->modelTreeView->selectFromSourceModelIndex(documentController->treeModel()->index(klass));
|
2015-09-21 12:11:02 +02:00
|
|
|
QTimer::singleShot(0, this, [this]() { onEditSelectedElement(); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::onAddCanvasDiagram()
|
|
|
|
|
{
|
|
|
|
|
ExtDocumentController *documentController = d->document->documentController();
|
|
|
|
|
|
2015-11-04 22:44:41 +01:00
|
|
|
qmt::MDiagram *diagram = documentController->createNewCanvasDiagram(d->modelTreeViewServant->selectedPackage());
|
|
|
|
|
d->modelTreeView->selectFromSourceModelIndex(documentController->treeModel()->index(diagram));
|
2015-09-21 12:11:02 +02:00
|
|
|
QTimer::singleShot(0, this, [this]() { onEditSelectedElement(); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::onCurrentEditorChanged(Core::IEditor *editor)
|
|
|
|
|
{
|
|
|
|
|
if (this == editor) {
|
2015-11-04 22:44:41 +01:00
|
|
|
QUndoStack *undoStack = d->document->documentController()->undoController()->undoStack();
|
|
|
|
|
d->actionHandler->undoAction()->setDisabled(!undoStack->canUndo());
|
|
|
|
|
d->actionHandler->redoAction()->setDisabled(!undoStack->canRedo());
|
2015-09-21 12:11:02 +02:00
|
|
|
|
|
|
|
|
updateSelectedArea(SelectedArea::Nothing);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::onCanUndoChanged(bool canUndo)
|
|
|
|
|
{
|
|
|
|
|
if (this == Core::EditorManager::currentEditor())
|
|
|
|
|
d->actionHandler->undoAction()->setEnabled(canUndo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::onCanRedoChanged(bool canRedo)
|
|
|
|
|
{
|
|
|
|
|
if (this == Core::EditorManager::currentEditor())
|
|
|
|
|
d->actionHandler->redoAction()->setEnabled(canRedo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::onTreeModelReset()
|
|
|
|
|
{
|
|
|
|
|
updateSelectedArea(SelectedArea::Nothing);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::onTreeViewSelectionChanged(const QItemSelection &selected,
|
|
|
|
|
const QItemSelection &deselected)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(selected);
|
|
|
|
|
Q_UNUSED(deselected);
|
|
|
|
|
|
|
|
|
|
updateSelectedArea(SelectedArea::TreeView);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::onTreeViewActivated()
|
|
|
|
|
{
|
|
|
|
|
updateSelectedArea(SelectedArea::TreeView);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::onTreeViewDoubleClicked(const QModelIndex &index)
|
|
|
|
|
{
|
|
|
|
|
ExtDocumentController *documentController = d->document->documentController();
|
|
|
|
|
|
|
|
|
|
QModelIndex treeModelIndex = d->modelTreeView->mapToSourceModelIndex(index);
|
2015-11-04 22:44:41 +01:00
|
|
|
qmt::MElement *melement = documentController->treeModel()->element(treeModelIndex);
|
2015-09-21 12:11:02 +02:00
|
|
|
// double click on package is already used for toggeling tree
|
|
|
|
|
if (melement && !dynamic_cast<qmt::MPackage *>(melement))
|
|
|
|
|
documentController->elementTasks()->openElement(melement);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::onCurrentDiagramChanged(const qmt::MDiagram *diagram)
|
|
|
|
|
{
|
|
|
|
|
if (diagram == currentDiagram()) {
|
|
|
|
|
updateSelectedArea(SelectedArea::Diagram);
|
|
|
|
|
} else {
|
|
|
|
|
updateSelectedArea(SelectedArea::Nothing);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::onDiagramActivated(const qmt::MDiagram *diagram)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(diagram);
|
|
|
|
|
|
|
|
|
|
updateSelectedArea(SelectedArea::Diagram);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::onDiagramClipboardChanged(bool isEmpty)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(isEmpty);
|
|
|
|
|
|
|
|
|
|
if (this == Core::EditorManager::currentEditor())
|
|
|
|
|
updateSelectedArea(d->selectedArea);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::onNewElementCreated(qmt::DElement *element, qmt::MDiagram *diagram)
|
|
|
|
|
{
|
|
|
|
|
if (diagram == currentDiagram()) {
|
|
|
|
|
ExtDocumentController *documentController = d->document->documentController();
|
|
|
|
|
|
2015-11-04 22:44:41 +01:00
|
|
|
documentController->diagramsManager()->diagramSceneModel(diagram)->selectElement(element);
|
|
|
|
|
qmt::MElement *melement = documentController->modelController()->findElement(element->modelUid());
|
|
|
|
|
if (!(melement && melement->flags().testFlag(qmt::MElement::REVERSE_ENGINEERED)))
|
2015-09-21 12:11:02 +02:00
|
|
|
QTimer::singleShot(0, this, [this]() { onEditSelectedElement(); });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::onDiagramSelectionChanged(const qmt::MDiagram *diagram)
|
|
|
|
|
{
|
|
|
|
|
if (diagram == currentDiagram())
|
|
|
|
|
updateSelectedArea(SelectedArea::Diagram);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::onDiagramModified(const qmt::MDiagram *diagram)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(diagram);
|
|
|
|
|
|
|
|
|
|
updateSelectedArea(d->selectedArea);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::onRightSplitterMoved(int pos, int index)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(pos);
|
|
|
|
|
Q_UNUSED(index);
|
|
|
|
|
|
|
|
|
|
d->uiController->onRightSplitterChanged(d->rightSplitter->saveState());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::onRightSplitterChanged(const QByteArray &state)
|
|
|
|
|
{
|
|
|
|
|
d->rightSplitter->restoreState(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::onRightHorizSplitterMoved(int pos, int index)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(pos);
|
|
|
|
|
Q_UNUSED(index);
|
|
|
|
|
|
|
|
|
|
d->uiController->onRightHorizSplitterChanged(d->rightHorizSplitter->saveState());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::onRightHorizSplitterChanged(const QByteArray &state)
|
|
|
|
|
{
|
|
|
|
|
d->rightHorizSplitter->restoreState(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::initToolbars()
|
|
|
|
|
{
|
|
|
|
|
QHash<QString, QWidget *> toolBars;
|
|
|
|
|
// TODO add toolbars sorted by prio
|
|
|
|
|
qmt::DocumentController *documentController = d->document->documentController();
|
2015-11-04 22:44:41 +01:00
|
|
|
qmt::StereotypeController *stereotypeController = documentController->stereotypeController();
|
|
|
|
|
foreach (const qmt::Toolbar &toolbar, stereotypeController->toolbars()) {
|
|
|
|
|
QWidget *toolBar = toolBars.value(toolbar.id());
|
2015-09-21 12:11:02 +02:00
|
|
|
QLayout *toolBarLayout = 0;
|
|
|
|
|
if (!toolBar) {
|
|
|
|
|
toolBar = new QWidget(d->leftToolBox);
|
|
|
|
|
toolBarLayout = new QVBoxLayout(toolBar);
|
|
|
|
|
toolBarLayout->setContentsMargins(2, 2, 2, 2);
|
|
|
|
|
toolBarLayout->setSpacing(6);
|
2015-11-04 22:44:41 +01:00
|
|
|
d->leftToolBox->addItem(toolBar, toolbar.id());
|
|
|
|
|
toolBars.insert(toolbar.id(), toolBar);
|
2015-09-21 12:11:02 +02:00
|
|
|
} else {
|
|
|
|
|
toolBarLayout = toolBar->layout();
|
|
|
|
|
QTC_ASSERT(toolBarLayout, continue);
|
|
|
|
|
}
|
2015-11-04 22:44:41 +01:00
|
|
|
foreach (const qmt::Toolbar::Tool &tool, toolbar.tools()) {
|
2015-11-03 22:30:46 +01:00
|
|
|
switch (tool.m_toolType) {
|
2015-09-21 12:11:02 +02:00
|
|
|
case qmt::Toolbar::TOOLTYPE_TOOL:
|
|
|
|
|
{
|
|
|
|
|
QString iconPath;
|
|
|
|
|
qmt::StereotypeIcon::Element stereotypeIconElement = qmt::StereotypeIcon::ELEMENT_ANY;
|
|
|
|
|
qmt::StyleEngine::ElementType styleEngineElementType = qmt::StyleEngine::TYPE_OTHER;
|
2015-11-03 22:30:46 +01:00
|
|
|
if (tool.m_elementType == QLatin1String(qmt::ELEMENT_TYPE_PACKAGE)) {
|
2015-09-21 12:11:02 +02:00
|
|
|
iconPath = QStringLiteral(":/modelinglib/48x48/package.png");
|
|
|
|
|
stereotypeIconElement = qmt::StereotypeIcon::ELEMENT_PACKAGE;
|
|
|
|
|
styleEngineElementType = qmt::StyleEngine::TYPE_PACKAGE;
|
2015-11-03 22:30:46 +01:00
|
|
|
} else if (tool.m_elementType == QLatin1String(qmt::ELEMENT_TYPE_COMPONENT)) {
|
2015-09-21 12:11:02 +02:00
|
|
|
iconPath = QStringLiteral(":/modelinglib/48x48/component.png");
|
|
|
|
|
stereotypeIconElement = qmt::StereotypeIcon::ELEMENT_COMPONENT;
|
|
|
|
|
styleEngineElementType = qmt::StyleEngine::TYPE_COMPONENT;
|
2015-11-03 22:30:46 +01:00
|
|
|
} else if (tool.m_elementType == QLatin1String(qmt::ELEMENT_TYPE_CLASS)) {
|
2015-09-21 12:11:02 +02:00
|
|
|
iconPath = QStringLiteral(":/modelinglib/48x48/class.png");
|
|
|
|
|
stereotypeIconElement = qmt::StereotypeIcon::ELEMENT_CLASS;
|
|
|
|
|
styleEngineElementType = qmt::StyleEngine::TYPE_CLASS;
|
2015-11-03 22:30:46 +01:00
|
|
|
} else if (tool.m_elementType == QLatin1String(qmt::ELEMENT_TYPE_ITEM)) {
|
2015-09-21 12:11:02 +02:00
|
|
|
iconPath = QStringLiteral(":/modelinglib/48x48/item.png");
|
|
|
|
|
stereotypeIconElement = qmt::StereotypeIcon::ELEMENT_ITEM;
|
|
|
|
|
styleEngineElementType = qmt::StyleEngine::TYPE_ITEM;
|
2015-11-03 22:30:46 +01:00
|
|
|
} else if (tool.m_elementType == QLatin1String(qmt::ELEMENT_TYPE_ANNOTATION)) {
|
2015-09-21 12:11:02 +02:00
|
|
|
iconPath = QStringLiteral(":/modelinglib/48x48/annotation.png");
|
|
|
|
|
styleEngineElementType = qmt::StyleEngine::TYPE_ANNOTATION;
|
2015-11-03 22:30:46 +01:00
|
|
|
} else if (tool.m_elementType == QLatin1String(qmt::ELEMENT_TYPE_BOUNDARY)) {
|
2015-09-21 12:11:02 +02:00
|
|
|
iconPath = QStringLiteral(":/modelinglib/48x48/boundary.png");
|
|
|
|
|
styleEngineElementType = qmt::StyleEngine::TYPE_BOUNDARY;
|
|
|
|
|
}
|
|
|
|
|
QIcon icon;
|
2015-11-03 22:30:46 +01:00
|
|
|
if (!tool.m_stereotype.isEmpty() && stereotypeIconElement != qmt::StereotypeIcon::ELEMENT_ANY) {
|
2015-11-04 22:44:41 +01:00
|
|
|
const qmt::Style *style = documentController->styleController()->adaptStyle(styleEngineElementType);
|
2015-09-21 12:11:02 +02:00
|
|
|
icon = stereotypeController->createIcon(
|
2015-11-03 22:30:46 +01:00
|
|
|
stereotypeIconElement, QStringList() << tool.m_stereotype,
|
2015-09-21 12:11:02 +02:00
|
|
|
QString(), style, QSize(48, 48), QMarginsF(3.0, 2.0, 3.0, 4.0));
|
|
|
|
|
}
|
|
|
|
|
if (icon.isNull())
|
|
|
|
|
icon = QIcon(iconPath);
|
|
|
|
|
if (!icon.isNull()) {
|
2015-11-03 22:30:46 +01:00
|
|
|
toolBarLayout->addWidget(new DragTool(icon, tool.m_name, tool.m_elementType,
|
|
|
|
|
tool.m_stereotype, toolBar));
|
2015-09-21 12:11:02 +02:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case qmt::Toolbar::TOOLTYPE_SEPARATOR:
|
|
|
|
|
{
|
|
|
|
|
auto horizLine1 = new QFrame(d->leftToolBox);
|
|
|
|
|
horizLine1->setFrameShape(QFrame::HLine);
|
|
|
|
|
toolBarLayout->addWidget(horizLine1);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// fallback if no toolbar was defined
|
|
|
|
|
if (!toolBars.isEmpty()) {
|
|
|
|
|
QString generalId = QStringLiteral("General");
|
|
|
|
|
auto toolBar = new QWidget(d->leftToolBox);
|
|
|
|
|
auto toolBarLayout = new QVBoxLayout(toolBar);
|
|
|
|
|
toolBarLayout->setContentsMargins(2, 2, 2, 2);
|
|
|
|
|
toolBarLayout->setSpacing(6);
|
|
|
|
|
d->leftToolBox->insertItem(0, toolBar, generalId);
|
|
|
|
|
toolBars.insert(generalId, toolBar);
|
|
|
|
|
toolBarLayout->addWidget(
|
|
|
|
|
new DragTool(QIcon(QStringLiteral(":/modelinglib/48x48/package.png")),
|
|
|
|
|
tr("Package"), QLatin1String(qmt::ELEMENT_TYPE_PACKAGE),
|
|
|
|
|
QString(), toolBar));
|
|
|
|
|
toolBarLayout->addWidget(
|
|
|
|
|
new DragTool(QIcon(QStringLiteral(":/modelinglib/48x48/component.png")),
|
|
|
|
|
tr("Component"), QLatin1String(qmt::ELEMENT_TYPE_COMPONENT),
|
|
|
|
|
QString(), toolBar));
|
|
|
|
|
toolBarLayout->addWidget(
|
|
|
|
|
new DragTool(QIcon(QStringLiteral(":/modelinglib/48x48/class.png")),
|
|
|
|
|
tr("Class"), QLatin1String(qmt::ELEMENT_TYPE_CLASS),
|
|
|
|
|
QString(), toolBar));
|
|
|
|
|
toolBarLayout->addWidget(
|
|
|
|
|
new DragTool(QIcon(QStringLiteral(":/modelinglib/48x48/item.png")),
|
|
|
|
|
tr("Item"), QLatin1String(qmt::ELEMENT_TYPE_ITEM),
|
|
|
|
|
QString(), toolBar));
|
|
|
|
|
auto horizLine1 = new QFrame(d->leftToolBox);
|
|
|
|
|
horizLine1->setFrameShape(QFrame::HLine);
|
|
|
|
|
toolBarLayout->addWidget(horizLine1);
|
|
|
|
|
toolBarLayout->addWidget(
|
|
|
|
|
new DragTool(QIcon(QStringLiteral(":/modelinglib/48x48/annotation.png")),
|
|
|
|
|
tr("Annotation"), QLatin1String(qmt::ELEMENT_TYPE_ANNOTATION),
|
|
|
|
|
QString(), toolBar));
|
|
|
|
|
toolBarLayout->addWidget(
|
|
|
|
|
new DragTool(QIcon(QStringLiteral(":/modelinglib/48x48/boundary.png")),
|
|
|
|
|
tr("Boundary"), QLatin1String(qmt::ELEMENT_TYPE_BOUNDARY),
|
|
|
|
|
QString(), toolBar));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// add stretch to all layouts and calculate width of tool bar
|
|
|
|
|
int maxWidth = 48;
|
|
|
|
|
foreach (QWidget *toolBar, toolBars) {
|
|
|
|
|
QTC_ASSERT(toolBar, continue);
|
|
|
|
|
auto layout = qobject_cast<QBoxLayout *>(toolBar->layout());
|
|
|
|
|
QTC_ASSERT(layout, continue);
|
|
|
|
|
layout->addStretch(1);
|
|
|
|
|
toolBar->adjustSize();
|
|
|
|
|
if (maxWidth < toolBar->width())
|
|
|
|
|
maxWidth = toolBar->width();
|
|
|
|
|
}
|
|
|
|
|
d->leftToolBox->setFixedWidth(maxWidth);
|
|
|
|
|
|
|
|
|
|
d->leftToolBox->setCurrentIndex(0);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-25 15:25:23 +02:00
|
|
|
void ModelEditor::openDiagram(qmt::MDiagram *diagram, bool addToHistory)
|
|
|
|
|
{
|
|
|
|
|
closeCurrentDiagram(addToHistory);
|
|
|
|
|
if (diagram) {
|
2015-11-04 22:44:41 +01:00
|
|
|
qmt::DiagramSceneModel *diagramSceneModel = d->document->documentController()->diagramsManager()->bindDiagramSceneModel(diagram);
|
2015-09-25 15:25:23 +02:00
|
|
|
d->diagramView->setDiagramSceneModel(diagramSceneModel);
|
|
|
|
|
d->diagramStack->setCurrentWidget(d->diagramView);
|
|
|
|
|
updateSelectedArea(SelectedArea::Nothing);
|
|
|
|
|
addDiagramToSelector(diagram);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::closeCurrentDiagram(bool addToHistory)
|
2015-09-21 12:11:02 +02:00
|
|
|
{
|
|
|
|
|
ExtDocumentController *documentController = d->document->documentController();
|
2015-11-04 22:44:41 +01:00
|
|
|
qmt::DiagramsManager *diagramsManager = documentController->diagramsManager();
|
|
|
|
|
qmt::DiagramSceneModel *sceneModel = d->diagramView->diagramSceneModel();
|
2015-09-21 12:11:02 +02:00
|
|
|
if (sceneModel) {
|
2015-11-04 22:44:41 +01:00
|
|
|
qmt::MDiagram *diagram = sceneModel->diagram();
|
2015-09-21 12:11:02 +02:00
|
|
|
if (diagram) {
|
2015-09-25 15:25:23 +02:00
|
|
|
if (addToHistory)
|
|
|
|
|
addToNavigationHistory(diagram);
|
2015-09-21 12:11:02 +02:00
|
|
|
d->diagramStack->setCurrentWidget(d->noDiagramLabel);
|
|
|
|
|
d->diagramView->setDiagramSceneModel(0);
|
|
|
|
|
diagramsManager->unbindDiagramSceneModel(diagram);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::closeDiagram(const qmt::MDiagram *diagram)
|
|
|
|
|
{
|
|
|
|
|
ExtDocumentController *documentController = d->document->documentController();
|
2015-11-04 22:44:41 +01:00
|
|
|
qmt::DiagramsManager *diagramsManager = documentController->diagramsManager();
|
|
|
|
|
qmt::DiagramSceneModel *sceneModel = d->diagramView->diagramSceneModel();
|
|
|
|
|
if (sceneModel && diagram == sceneModel->diagram()) {
|
2015-09-25 15:25:23 +02:00
|
|
|
addToNavigationHistory(diagram);
|
2015-09-21 12:11:02 +02:00
|
|
|
d->diagramStack->setCurrentWidget(d->noDiagramLabel);
|
|
|
|
|
d->diagramView->setDiagramSceneModel(0);
|
|
|
|
|
diagramsManager->unbindDiagramSceneModel(diagram);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::closeAllDiagrams()
|
|
|
|
|
{
|
2015-09-25 15:25:23 +02:00
|
|
|
closeCurrentDiagram(true);
|
2015-09-21 12:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
2015-08-31 18:06:36 +02:00
|
|
|
void ModelEditor::onContentSet()
|
|
|
|
|
{
|
2015-09-21 12:11:02 +02:00
|
|
|
initDocument();
|
2015-08-31 18:06:36 +02:00
|
|
|
|
|
|
|
|
// open diagram
|
2015-09-21 12:11:02 +02:00
|
|
|
ExtDocumentController *documentController = d->document->documentController();
|
|
|
|
|
qmt::MDiagram *rootDiagram = documentController->findOrCreateRootDiagram();
|
2015-08-31 18:06:36 +02:00
|
|
|
showDiagram(rootDiagram);
|
2015-09-21 12:11:02 +02:00
|
|
|
// select diagram in model tree view
|
2015-11-04 22:44:41 +01:00
|
|
|
QModelIndex modelIndex = documentController->treeModel()->index(rootDiagram);
|
2015-09-21 12:11:02 +02:00
|
|
|
if (modelIndex.isValid())
|
|
|
|
|
d->modelTreeView->selectFromSourceModelIndex(modelIndex);
|
2015-08-31 18:06:36 +02:00
|
|
|
|
|
|
|
|
expandModelTreeToDepth(0);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-25 09:47:34 +02:00
|
|
|
void ModelEditor::addDiagramToSelector(const qmt::MDiagram *diagram)
|
|
|
|
|
{
|
|
|
|
|
QString diagramLabel = buildDiagramLabel(diagram);
|
2015-11-04 22:44:41 +01:00
|
|
|
QVariant diagramUid = QVariant::fromValue(diagram->uid());
|
2015-09-25 09:47:34 +02:00
|
|
|
int i = d->diagramSelector->findData(diagramUid);
|
|
|
|
|
if (i >= 0)
|
|
|
|
|
d->diagramSelector->removeItem(i);
|
|
|
|
|
d->diagramSelector->insertItem(0, QIcon(QStringLiteral(":/modelinglib/48x48/canvas-diagram.png")), diagramLabel, diagramUid);
|
|
|
|
|
d->diagramSelector->setCurrentIndex(0);
|
|
|
|
|
while (d->diagramSelector->count() > 20)
|
|
|
|
|
d->diagramSelector->removeItem(d->diagramSelector->count() - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::updateDiagramSelector()
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
while (i < d->diagramSelector->count()) {
|
|
|
|
|
qmt::Uid diagramUid = d->diagramSelector->itemData(i).value<qmt::Uid>();
|
|
|
|
|
if (diagramUid.isValid()) {
|
2015-11-04 22:44:41 +01:00
|
|
|
qmt::MDiagram *diagram = d->document->documentController()->modelController()->findObject<qmt::MDiagram>(diagramUid);
|
2015-09-25 09:47:34 +02:00
|
|
|
if (diagram) {
|
|
|
|
|
QString diagramLabel = buildDiagramLabel(diagram);
|
|
|
|
|
if (diagramLabel != d->diagramSelector->itemText(i))
|
|
|
|
|
d->diagramSelector->setItemText(i, diagramLabel);
|
|
|
|
|
++i;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
d->diagramSelector->removeItem(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelEditor::onDiagramSelectorSelected(int index)
|
|
|
|
|
{
|
|
|
|
|
qmt::Uid diagramUid = d->diagramSelector->itemData(index).value<qmt::Uid>();
|
|
|
|
|
if (diagramUid.isValid()) {
|
2015-11-04 22:44:41 +01:00
|
|
|
qmt::MDiagram *diagram = d->document->documentController()->modelController()->findObject<qmt::MDiagram>(diagramUid);
|
2015-09-25 09:47:34 +02:00
|
|
|
if (diagram) {
|
|
|
|
|
showDiagram(diagram);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
d->diagramSelector->setCurrentIndex(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ModelEditor::buildDiagramLabel(const qmt::MDiagram *diagram)
|
|
|
|
|
{
|
2015-11-04 22:44:41 +01:00
|
|
|
QString label = diagram->name();
|
|
|
|
|
qmt::MObject *owner = diagram->owner();
|
2015-09-25 09:47:34 +02:00
|
|
|
QStringList path;
|
|
|
|
|
while (owner) {
|
2015-11-04 22:44:41 +01:00
|
|
|
path.append(owner->name());
|
|
|
|
|
owner = owner->owner();
|
2015-09-25 09:47:34 +02:00
|
|
|
}
|
|
|
|
|
if (!path.isEmpty()) {
|
|
|
|
|
label += QStringLiteral(" [");
|
|
|
|
|
label += path.last();
|
|
|
|
|
for (int i = path.count() - 2; i >= 0; --i) {
|
|
|
|
|
label += QLatin1Char('.');
|
|
|
|
|
label += path.at(i);
|
|
|
|
|
}
|
|
|
|
|
label += QLatin1Char(']');
|
|
|
|
|
}
|
|
|
|
|
return label;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-25 15:25:23 +02:00
|
|
|
void ModelEditor::addToNavigationHistory(const qmt::MDiagram *diagram)
|
|
|
|
|
{
|
|
|
|
|
if (Core::EditorManager::currentEditor() == this)
|
|
|
|
|
Core::EditorManager::cutForwardNavigationHistory();
|
|
|
|
|
Core::EditorManager::addCurrentPositionToNavigationHistory(saveState(diagram));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QByteArray ModelEditor::saveState(const qmt::MDiagram *diagram) const
|
|
|
|
|
{
|
|
|
|
|
QByteArray state;
|
|
|
|
|
QDataStream stream(&state, QIODevice::WriteOnly);
|
|
|
|
|
stream << 1; // version number
|
|
|
|
|
if (diagram)
|
2015-11-04 22:44:41 +01:00
|
|
|
stream << diagram->uid();
|
2015-09-25 15:25:23 +02:00
|
|
|
else
|
2015-11-04 22:44:41 +01:00
|
|
|
stream << qmt::Uid::invalidUid();
|
2015-09-25 15:25:23 +02:00
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-25 09:47:34 +02:00
|
|
|
void ModelEditor::onEditSelectedElement()
|
|
|
|
|
{
|
|
|
|
|
// TODO introduce similar method for selected elements in model tree
|
|
|
|
|
// currently this method is called on adding new elements in model tree
|
|
|
|
|
// but the method is a no-op in that case.
|
2015-11-04 22:44:41 +01:00
|
|
|
qmt::MDiagram *diagram = d->propertiesView->selectedDiagram();
|
|
|
|
|
QList<qmt::DElement *> elements = d->propertiesView->selectedDiagramElements();
|
2015-09-25 09:47:34 +02:00
|
|
|
if (diagram && !elements.isEmpty()) {
|
|
|
|
|
qmt::DElement *element = elements.at(0);
|
|
|
|
|
if (element) {
|
2015-11-04 22:44:41 +01:00
|
|
|
qmt::DiagramSceneModel *diagramSceneModel = d->document->documentController()->diagramsManager()->diagramSceneModel(diagram);
|
2015-09-25 09:47:34 +02:00
|
|
|
if (diagramSceneModel->isElementEditable(element)) {
|
|
|
|
|
diagramSceneModel->editElement(element);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
d->propertiesView->editSelectedElement();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 18:06:36 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ModelEditor
|