예제 #1
0
void ClassItem::relationDrawn(const QString &id, const QPointF &toScenePos, const QList<QPointF> &intermediatePoints)
{
    DElement *targetElement = diagramSceneModel()->findTopmostElement(toScenePos);
    if (targetElement) {
        if (id == QLatin1String("inheritance")) {
            auto baseClass = dynamic_cast<DClass *>(targetElement);
            if (baseClass) {
                auto derivedClass = dynamic_cast<DClass *>(object());
                QMT_CHECK(derivedClass);
                diagramSceneModel()->diagramSceneController()->createInheritance(derivedClass, baseClass, intermediatePoints, diagramSceneModel()->diagram());
            }
        } else if (id == QLatin1String("dependency")) {
            auto dependantObject = dynamic_cast<DObject *>(targetElement);
            if (dependantObject)
                diagramSceneModel()->diagramSceneController()->createDependency(object(), dependantObject, intermediatePoints, diagramSceneModel()->diagram());
        } else if (id == QLatin1String("association")) {
            auto assoziatedClass = dynamic_cast<DClass *>(targetElement);
            if (assoziatedClass) {
                auto derivedClass = dynamic_cast<DClass *>(object());
                QMT_CHECK(derivedClass);
                diagramSceneModel()->diagramSceneController()->createAssociation(derivedClass, assoziatedClass, intermediatePoints, diagramSceneModel()->diagram());
            }
        }
    }
}
예제 #2
0
bool ClassItem::extendContextMenu(QMenu *menu)
{
    bool extended = false;
    if (diagramSceneModel()->diagramSceneController()->elementTasks()->hasClassDefinition(object(), diagramSceneModel()->diagram())) {
        menu->addAction(new ContextMenuAction(QObject::tr("Show Definition"), QStringLiteral("showDefinition"), menu));
        extended = true;
    }
    return extended;
}
예제 #3
0
void DiagramItem::update()
{
    prepareGeometryChange();
    updateStereotypeIconDisplay();

    const Style *style = adaptedStyle(stereotypeIconId());

    // custom icon
    if (stereotypeIconDisplay() == StereotypeIcon::DisplayIcon) {
        if (!m_customIcon)
            m_customIcon = new CustomIconItem(diagramSceneModel(), this);
        m_customIcon->setStereotypeIconId(stereotypeIconId());
        m_customIcon->setBaseSize(stereotypeIconMinimumSize(m_customIcon->stereotypeIcon(), CUSTOM_ICON_MINIMUM_AUTO_WIDTH, CUSTOM_ICON_MINIMUM_AUTO_HEIGHT));
        m_customIcon->setBrush(style->fillBrush());
        m_customIcon->setPen(style->outerLinePen());
        m_customIcon->setZValue(SHAPE_ZVALUE);
    } else if (m_customIcon) {
        m_customIcon->scene()->removeItem(m_customIcon);
        delete m_customIcon;
        m_customIcon = 0;
    }

    // shape
    if (!m_customIcon) {
        if (!m_body)
            m_body = new QGraphicsPolygonItem(this);
        m_body->setBrush(style->fillBrush());
        m_body->setPen(style->outerLinePen());
        m_body->setZValue(SHAPE_ZVALUE);
        if (!m_fold)
            m_fold = new QGraphicsPolygonItem(this);
        m_fold->setBrush(style->extraFillBrush());
        m_fold->setPen(style->outerLinePen());
        m_fold->setZValue(SHAPE_DETAILS_ZVALUE);
    } else {
        if (m_fold) {
            m_fold->scene()->removeItem(m_fold);
            delete m_fold;
            m_fold = 0;
        }
        if (m_body) {
            m_body->scene()->removeItem(m_body);
            delete m_body;
            m_body = 0;
        }
    }

    // stereotypes
    updateStereotypes(stereotypeIconId(), stereotypeIconDisplay(), style);

    // diagram name
    updateNameItem(style);

    updateSelectionMarker(m_customIcon);
    updateAlignmentButtons();
    updateGeometry();
}
예제 #4
0
bool ClassItem::handleSelectedContextMenuAction(QAction *action)
{
    auto klassAction = dynamic_cast<ContextMenuAction *>(action);
    if (klassAction) {
        if (klassAction->id() == QStringLiteral("showDefinition")) {
            diagramSceneModel()->diagramSceneController()->elementTasks()->openClassDefinition(object(), diagramSceneModel()->diagram());
            return true;
        }
    }
    return false;
}
예제 #5
0
void ClassItem::relationDrawn(const QString &id, ObjectItem *targetItem, const QList<QPointF> &intermediatePoints)
{
    DiagramSceneController *diagramSceneController = diagramSceneModel()->diagramSceneController();
    if (id == INHERITANCE) {
        auto baseClass = dynamic_cast<DClass *>(targetItem->object());
        if (baseClass) {
            auto derivedClass = dynamic_cast<DClass *>(object());
            QMT_ASSERT(derivedClass, return);
            diagramSceneController->createInheritance(derivedClass, baseClass, intermediatePoints, diagramSceneModel()->diagram());
        }
        return;
    } else if (id == ASSOCIATION) {
예제 #6
0
DiagramSceneModel *DiagramsManager::bindDiagramSceneModel(MDiagram *diagram)
{
    if (!m_diagramUidToManagedDiagramMap.contains(diagram->uid())) {
        auto diagramSceneModel = new DiagramSceneModel();
        diagramSceneModel->setDiagramController(m_diagramController);
        diagramSceneModel->setDiagramSceneController(m_diagramSceneController);
        diagramSceneModel->setStyleController(m_styleController);
        diagramSceneModel->setStereotypeController(m_stereotypeController);
        diagramSceneModel->setDiagram(diagram);
        connect(diagramSceneModel, &DiagramSceneModel::diagramSceneActivated,
                this, &DiagramsManager::diagramActivated);
        connect(diagramSceneModel, &DiagramSceneModel::selectionHasChanged,
                this, &DiagramsManager::diagramSelectionChanged);
        auto managedDiagram = new ManagedDiagram(diagramSceneModel, diagram->name());
        m_diagramUidToManagedDiagramMap.insert(diagram->uid(), managedDiagram);
    }
    return diagramSceneModel(diagram);
}