void DFlatAssignmentVisitor::visitDObject(const DObject *object)
{
    visitDElement(object);
    auto target = dynamic_cast<DObject *>(m_target);
    QMT_CHECK(target);
    target->setStereotypes(object->stereotypes());
    target->setName(object->name());
    target->setPos(object->pos());
    target->setRect(object->rect());
    target->setAutoSized(object->isAutoSized());
    target->setDepth(object->depth());
    target->setVisualPrimaryRole(object->visualPrimaryRole());
    target->setVisualSecondaryRole(object->visualSecondaryRole());
    target->setVisualEmphasized(object->isVisualEmphasized());
    target->setStereotypeDisplay(object->stereotypeDisplay());
}
Exemple #2
0
void DiagramsView::openDiagram(MDiagram *diagram)
{
    QMT_CHECK(diagram);
    DiagramView *diagramView = m_diagramViews.value(diagram->uid());
    if (!diagramView) {
        DiagramSceneModel *diagramSceneModel = m_diagramsManager->bindDiagramSceneModel(diagram);
        DiagramView *diagramView = new DiagramView(this);
        diagramView->setDiagramSceneModel(diagramSceneModel);
        int tabIndex = addTab(diagramView, diagram->name());
        setCurrentIndex(tabIndex);
        m_diagramViews.insert(diagram->uid(), diagramView);
    } else {
        setCurrentWidget(diagramView);
    }
    emit someDiagramOpened(!m_diagramViews.isEmpty());
}
void BoundaryItem::onContentsChanged()
{
    QMT_CHECK(!_on_changed);
    _on_changed = true;

    if (!_on_update) {
        QString plain_text = _text_item->toPlainText();
        if (_boundary->getText() != plain_text) {
            _diagram_scene_model->getDiagramController()->startUpdateElement(_boundary, _diagram_scene_model->getDiagram(), DiagramController::UPDATE_MINOR);
            _boundary->setText(plain_text);
            _diagram_scene_model->getDiagramController()->finishUpdateElement(_boundary, _diagram_scene_model->getDiagram(), false);
        }
    }

    _on_changed = false;
}
Exemple #4
0
void AnnotationItem::onContentsChanged()
{
    QMT_CHECK(!m_isChanged);
    m_isChanged = true;

    if (!m_isUpdating) {
        QString plainText = m_textItem->toPlainText();
        if (m_annotation->text() != plainText) {
            m_diagramSceneModel->diagramController()->startUpdateElement(m_annotation, m_diagramSceneModel->diagram(), DiagramController::UpdateMinor);
            m_annotation->setText(plainText);
            m_diagramSceneModel->diagramController()->finishUpdateElement(m_annotation, m_diagramSceneModel->diagram(), false);
        }
    }

    m_isChanged = false;
}
Exemple #5
0
void RelationItem::setHandlePos(int index, const QPointF &pos)
{
    if (index == 0) {
        // TODO implement
    } else if (index == m_relation->intermediatePoints().size() + 1) {
        // TODO implement
    } else {
        QList<DRelation::IntermediatePoint> intermediatePoints = m_relation->intermediatePoints();
        --index;
        QMT_CHECK(index >= 0 && index < intermediatePoints.size());
        intermediatePoints[index].setPos(pos);

        m_diagramSceneModel->diagramController()->startUpdateElement(m_relation, m_diagramSceneModel->diagram(), DiagramController::UpdateMinor);
        m_relation->setIntermediatePoints(intermediatePoints);
        m_diagramSceneModel->diagramController()->finishUpdateElement(m_relation, m_diagramSceneModel->diagram(), false);
    }
}
StereotypeIcon::Display StereotypeDisplayVisitor::stereotypeIconDisplay() const
{
    switch (m_stereotypeDisplay) {
    case DObject::StereotypeNone:
        return StereotypeIcon::DisplayNone;
    case DObject::StereotypeLabel:
        return StereotypeIcon::DisplayLabel;
    case DObject::StereotypeDecoration:
        return StereotypeIcon::DisplayDecoration;
    case DObject::StereotypeIcon:
        return StereotypeIcon::DisplayIcon;
    case DObject::StereotypeSmart:
        QMT_CHECK(false);
        return StereotypeIcon::DisplaySmart;
    }
    return StereotypeIcon::DisplayLabel;
}
int StereotypeDefinitionParser::parseIntExpression()
{
    Token token;
    token = d->m_scanner->read();
    if (token.type() == Token::TokenOperator && token.subtype() == OPERATOR_MINUS) {
        return -parseIntExpression();
    } else {
        bool ok = false;
        if (token.type() == Token::TokenInteger) {
            int value = token.text().toInt(&ok);
            QMT_CHECK(ok);
            return value;
        } else {
            throw StereotypeDefinitionParserError(QStringLiteral("Expected integer constant."), token.sourcePos());
        }
    }
}
 void redo()
 {
     if (canRedo()) {
         bool inserted = false;
         for (int i = m_clonedElements.count() - 1; i >= 0; --i) {
             Clone &clone = m_clonedElements[i];
             QMT_CHECK(clone.m_clonedElement);
             QMT_CHECK(clone.m_clonedElement->uid() == clone.m_elementKey);
             MObject *owner = m_modelController->findObject<MObject>(clone.m_ownerKey);
             QMT_CHECK(owner);
             QMT_CHECK(clone.m_indexOfElement >= 0);
             switch (clone.m_elementType) {
             case TypeObject:
             {
                 emit m_modelController->beginInsertObject(clone.m_indexOfElement, owner);
                 MObject *object = dynamic_cast<MObject *>(clone.m_clonedElement);
                 QMT_CHECK(object);
                 m_modelController->mapObject(object);
                 owner->insertChild(clone.m_indexOfElement, object);
                 clone.m_clonedElement = 0;
                 emit m_modelController->endInsertObject(clone.m_indexOfElement, owner);
                 inserted = true;
                 break;
             }
             case TypeRelation:
             {
                 emit m_modelController->beginInsertRelation(clone.m_indexOfElement, owner);
                 MRelation *relation = dynamic_cast<MRelation *>(clone.m_clonedElement);
                 QMT_CHECK(relation);
                 m_modelController->mapRelation(relation);
                 owner->insertRelation(clone.m_indexOfElement, relation);
                 clone.m_clonedElement = 0;
                 emit m_modelController->endInsertRelation(clone.m_indexOfElement, owner);
                 inserted = true;
                 break;
             }
             default:
                 QMT_CHECK(false);
                 break;
             }
         }
         if (inserted) {
             emit m_modelController->modified();
         }
         m_modelController->verifyModelIntegrity();
         UndoCommand::redo();
     }
 }
void RelationStarter::addArrow(const QString &id, ArrowItem::Shaft shaft,
                               ArrowItem::Head endHead, ArrowItem::Head startHead)
{
    QMT_CHECK(!id.isEmpty());
    prepareGeometryChange();
    ArrowItem *arrow = new ArrowItem(this);
    arrow->setArrowSize(10.0);
    arrow->setDiamondSize(15.0);
    arrow->setShaft(shaft);
    arrow->setStartHead(startHead);
    arrow->setEndHead(endHead);
    arrow->setPoints(QList<QPointF>() << QPointF(0.0, 10.0) << QPointF(15.0, 0.0));
    arrow->setPos(6.0, m_arrows.size() * 20.0 + 8.0);
    arrow->update(m_diagramSceneModel->styleController()->relationStarterStyle());
    m_arrows.append(arrow);
    m_arrowIds.insert(arrow, id);
    setRect(0.0, 0.0, 26.0, m_arrows.size() * 20.0 + 6.0);
}
Exemple #10
0
QString ClassItem::buildDisplayName() const
{
    auto diagramClass = dynamic_cast<DClass *>(object());
    QMT_CHECK(diagramClass);

    QString name;
    if (templateDisplay() == DClass::TemplateName && !diagramClass->templateParameters().isEmpty()) {
        name = object()->name();
        name += QLatin1Char('<');
        bool first = true;
        foreach (const QString &p, diagramClass->templateParameters()) {
            if (!first)
                name += QLatin1Char(',');
            name += p;
            first = false;
        }
        name += QLatin1Char('>');
    } else {
void RelationStarter::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    m_currentPreviewArrow = 0;
    foreach (ArrowItem *item, m_arrows) {
        if (item->boundingRect().contains(mapToItem(item, event->pos()))) {
            prepareGeometryChange();
            m_currentPreviewArrowIntermediatePoints.clear();
            m_currentPreviewArrowId = m_arrowIds.value(item);
            QMT_CHECK(!m_currentPreviewArrowId.isEmpty());
            m_currentPreviewArrow = new ArrowItem(*item);
            m_currentPreviewArrow->setPoints(QList<QPointF>() << m_owner->relationStartPos() << mapToScene(event->pos()));
            m_currentPreviewArrow->update(m_diagramSceneModel->styleController()->relationStarterStyle());
            m_currentPreviewArrow->setZValue(PREVIEW_RELATION_ZVALUE);
            scene()->addItem(m_currentPreviewArrow);
            setFocus(); // receive keyboard events
            break;
        }
    }
}
void DUpdateVisitor::visitMAssociation(const MAssociation *association)
{
    auto dassociation = dynamic_cast<DAssociation *>(m_target);
    QMT_CHECK(dassociation);
    DAssociationEnd endA;
    endA.setName(association->endA().name());
    endA.setCardinatlity(association->endA().cardinality());
    endA.setNavigable(association->endA().isNavigable());
    endA.setKind(association->endA().kind());
    if (isUpdating(endA != dassociation->endA()))
        dassociation->setEndA(endA);
    DAssociationEnd endB;
    endB.setName(association->endB().name());
    endB.setCardinatlity(association->endB().cardinality());
    endB.setNavigable(association->endB().isNavigable());
    endB.setKind(association->endB().kind());
    if (isUpdating(endB != dassociation->endB()))
        dassociation->setEndB(endB);
    visitMRelation(association);
}
Exemple #13
0
void RelationItem::alignHandleToRaster(int index, double rasterWidth, double rasterHeight)
{
    if (index == 0) {
        // TODO implement
    } else if (index ==m_relation->intermediatePoints().size() + 1) {
        // TODO implement
    } else {
        QList<DRelation::IntermediatePoint> intermediatePoints = m_relation->intermediatePoints();
        --index;
        QMT_CHECK(index >= 0 && index < intermediatePoints.size());

        QPointF pos = intermediatePoints.at(index).pos();
        double x = qRound(pos.x() / rasterWidth) * rasterWidth;
        double y = qRound(pos.y() / rasterHeight) * rasterHeight;
        intermediatePoints[index].setPos(QPointF(x, y));

        m_diagramSceneModel->diagramController()->startUpdateElement(m_relation, m_diagramSceneModel->diagram(), DiagramController::UpdateMinor);
        m_relation->setIntermediatePoints(intermediatePoints);
        m_diagramSceneModel->diagramController()->finishUpdateElement(m_relation, m_diagramSceneModel->diagram(), false);
    }
}
void AnnotationItem::update()
{
    QMT_CHECK(!_on_update);
    _on_update = true;

    prepareGeometryChange();

    const Style *style = getAdaptedStyle();

    // text
    if (!_text_item) {
        _text_item = new AnnotationTextItem(this);
        _text_item->setTextInteractionFlags(Qt::TextEditorInteraction);
        _text_item->installSceneEventFilter(this);
        QObject::connect(_text_item->document(), &QTextDocument::contentsChanged, _text_item,
                         [=]() { this->onContentsChanged(); } );
    }
    _text_item->setFont(style->getNormalFont());
    _text_item->setDefaultTextColor(style->getTextBrush().color());
    if (!_on_changed) {
        _text_item->setPlainText(getAnnotation()->getText());
    }

    // item shown if annotation has no text and is not selected
    if (!_no_text_item) {
        _no_text_item = new QGraphicsRectItem(this);
    }
    _no_text_item->setPen(QPen(QBrush(QColor(192, 192, 192)), 1, Qt::DashDotLine));
    _no_text_item->setVisible(!isSelected() && _text_item->document()->isEmpty());

    updateSelectionMarker();

    updateGeometry();

    setZValue(ANNOTATION_ITEMS_ZVALUE);

    _on_update = false;
}
Exemple #15
0
void ModelIndexer::scanProject(ProjectExplorer::Project *project)
{
    if (!project->rootProjectNode())
        return;

    // TODO harmonize following code with findFirstModel()?
    const Utils::FileNameList files = project->files(ProjectExplorer::Project::SourceFiles);
    QQueue<QueuedFile> filesQueue;
    QSet<QueuedFile> filesSet;

    for (const Utils::FileName &file : files) {
        QFileInfo fileInfo = file.toFileInfo();
        Utils::MimeType mimeType = Utils::mimeTypeForFile(fileInfo);
        if (mimeType.name() == QLatin1String(Constants::MIME_TYPE_MODEL)) {
            QueuedFile queuedFile(file.toString(), project, fileInfo.lastModified());
            filesQueue.append(queuedFile);
            filesSet.insert(queuedFile);
        }
    }

    QString defaultModelFile = findFirstModel(project->rootProjectNode());

    bool filesAreQueued = false;
    {
        QMutexLocker locker(&d->indexerMutex);

        // remove deleted files from queue
        for (int i = 0; i < d->filesQueue.size();) {
            if (d->filesQueue.at(i).project() == project) {
                if (filesSet.contains(d->filesQueue.at(i))) {
                    ++i;
                } else {
                    d->queuedFilesSet.remove(d->filesQueue.at(i));
                    d->filesQueue.removeAt(i);
                }
            }
        }

        // remove deleted files from indexed models
        foreach (const QString &file, d->indexedModels.keys()) {
            if (!filesSet.contains(QueuedFile(file, project)))
                removeModelFile(file, project);
        }

        // remove deleted files from indexed diagrams
        foreach (const QString &file, d->indexedDiagramReferences.keys()) {
            if (!filesSet.contains(QueuedFile(file, project)))
                removeDiagramReferenceFile(file, project);
        }

        // queue files
        while (!filesQueue.isEmpty()) {
            QueuedFile queuedFile = filesQueue.takeFirst();
            if (!d->queuedFilesSet.contains(queuedFile)) {
                QMT_CHECK(!d->filesQueue.contains(queuedFile));
                d->filesQueue.append(queuedFile);
                d->queuedFilesSet.insert(queuedFile);
                filesAreQueued = true;
            }
        }

        // auto-open model file only if project is already configured
        if (!defaultModelFile.isEmpty() && !project->targets().isEmpty()) {
            d->defaultModelFiles.insert(QueuedFile(defaultModelFile, project, QDateTime()));
        }
    }

    if (filesAreQueued)
        emit filesQueued();
}
bool GeometryUtilities::placeRectAtLine(const QRectF &rect, const QLineF &line, double lineOffset, double distance,
                                        const QLineF &intersectionLine, QPointF *placement, Side *horizontalAlignedSide)
{
    QMT_CHECK(placement);

    QList<Candidate> candidates;
    candidates << Candidate(QVector2D(rect.topRight() - rect.topLeft()), QPointF(0.0, 0.0), SideTop)
               << Candidate(QVector2D(rect.topLeft() - rect.topRight()), rect.topRight() - rect.topLeft(), SideTop)
               << Candidate(QVector2D(rect.bottomLeft() - rect.topLeft()), QPointF(0.0, 0.0), SideLeft)
               << Candidate(QVector2D(rect.topLeft() - rect.bottomLeft()), rect.bottomLeft() - rect.topLeft(), SideLeft)
               << Candidate(QVector2D(rect.bottomRight() - rect.bottomLeft()), rect.bottomLeft() - rect.topLeft(), SideBottom)
               << Candidate(QVector2D(rect.bottomLeft() - rect.bottomRight()), rect.bottomRight() - rect.topLeft(), SideBottom)
               << Candidate(QVector2D(rect.bottomRight() - rect.topRight()), rect.topRight() - rect.topLeft(), SideRight)
               << Candidate(QVector2D(rect.topRight() - rect.bottomRight()), rect.bottomRight() - rect.topLeft(), SideRight);

    QVector<QVector2D> rectEdgeVectors;
    rectEdgeVectors << QVector2D(rect.topLeft() - rect.topLeft())
                    << QVector2D(rect.topRight() - rect.topLeft())
                    << QVector2D(rect.bottomLeft() - rect.topLeft())
                    << QVector2D(rect.bottomRight() -rect.topLeft());

    QVector2D directionVector(line.p2() - line.p1());
    directionVector.normalize();

    QVector2D sideVector(directionVector.y(), -directionVector.x());

    QVector2D intersectionVector(intersectionLine.p2() - intersectionLine.p1());
    intersectionVector.normalize();

    QVector2D outsideVector = QVector2D(intersectionVector.y(), -intersectionVector.x());
    double p = QVector2D::dotProduct(directionVector, outsideVector);
    if (p < 0.0)
        outsideVector = outsideVector * -1.0;

    double smallestA = -1.0;
    QPointF rectTranslation;
    Side side = SideUnspecified;
    int bestSign = 0;

    foreach (const Candidate &candidate, candidates) {
        // solve equation a * directionVector + candidate.first = b * intersectionVector to find smallest a
        double r = directionVector.x() * intersectionVector.y() - directionVector.y() * intersectionVector.x();
        if (r <= -1e-5 || r >= 1e-5) {
            double a = (candidate.first.y() * intersectionVector.x()
                        - candidate.first.x() * intersectionVector.y()) / r;
            if (a >= 0.0 && (smallestA < 0.0 || a < smallestA)) {
                // verify that all rectangle edges lay outside of shape (by checking for positiv projection to intersection)
                bool ok = true;
                int sign = 0;
                QVector2D rectOriginVector = directionVector * a - QVector2D(candidate.second);
                foreach (const QVector2D &rectEdgeVector, rectEdgeVectors) {
                    QVector2D edgeVector = rectOriginVector + rectEdgeVector;
                    double aa = QVector2D::dotProduct(outsideVector, edgeVector);
                    if (aa < 0.0) {
                        ok = false;
                        break;
                    }
                    int s = sgn(QVector2D::dotProduct(sideVector, edgeVector));
                    if (s) {
                        if (sign) {
                            if (s != sign) {
                                ok = false;
                                break;
                            }
                        } else {
                            sign = s;
                        }
                    }
                }
Exemple #17
0
QLineF ArrowItem::lastLineSegment() const
{
    QMT_CHECK(m_points.size() >= 2);
    return QLineF(m_points[m_points.size() - 1], m_points[m_points.size() - 2]);
}
StereotypeIcon StereotypeController::findStereotypeIcon(const QString &stereotypeIconId) const
{
    QMT_CHECK(d->m_iconIdToStereotypeIconsMap.contains(stereotypeIconId));
    return d->m_iconIdToStereotypeIconsMap.value(stereotypeIconId);
}
DiagramSceneModel *DiagramsManager::diagramSceneModel(const MDiagram *diagram) const
{
    const ManagedDiagram *managedDiagram = m_diagramUidToManagedDiagramMap.value(diagram->uid());
    QMT_CHECK(managedDiagram);
    return managedDiagram->diagramSceneModel();
}
MFlatAssignmentVisitor::MFlatAssignmentVisitor(MElement *target)
    : m_target(target)
{
    QMT_CHECK(m_target);
}
void AlignOnRasterVisitor::visitDElement(DElement *element)
{
    Q_UNUSED(element);

    QMT_CHECK(false);
}
Exemple #22
0
QLineF ArrowItem::firstLineSegment() const
{
    QMT_CHECK(m_points.size() >= 2);
    return QLineF(m_points[0], m_points[1]);
}
DFlatAssignmentVisitor::DFlatAssignmentVisitor(DElement *target)
    : m_target(target)
{
    QMT_CHECK(target);
}
void DUpdateVisitor::visitMElement(const MElement *element)
{
    Q_UNUSED(element);

    QMT_CHECK(m_target);
}