diff options
author | Sandro S. Andrade <sandroandrade@kde.org> | 2013-11-17 01:58:41 -0300 |
---|---|---|
committer | Sandro S. Andrade <sandroandrade@kde.org> | 2013-11-17 05:54:29 +0100 |
commit | 5df612493f17895780134ed0c3feae5150645571 (patch) | |
tree | 80100e59b287a12bd23010ab9a2f9ad94fb014bd /examples/uml/duse-mt | |
parent | 48d19821a52312b18b9b80ff81679cc4ab224f9e (diff) |
Add initial implementation of QML element for UML associations
Change-Id: Ice14c82f392cf7855f27166e254f3c57a0af9607
Reviewed-by: Sandro S. Andrade <sandroandrade@kde.org>
Diffstat (limited to 'examples/uml/duse-mt')
7 files changed, 331 insertions, 4 deletions
diff --git a/examples/uml/duse-mt/src/app/example.xmi b/examples/uml/duse-mt/src/app/example.xmi index aa6c9f50..e733ab01 100644 --- a/examples/uml/duse-mt/src/app/example.xmi +++ b/examples/uml/duse-mt/src/app/example.xmi @@ -11,7 +11,7 @@ <memberEnd xmi:idref="MyRootPackage-Package1-Student-advisor"/> <memberEnd xmi:idref="A_student_professor-student"/> <ownedEnd xmi:type="uml:Property" name="student" visibility="public" xmi:id="A_student_professor-student"> - <type xmi:idref="Student"/> + <type xmi:idref="MyRootPackage-Package1-Student"/> <association xmi:idref="MyRootPackage-A_student_professor"/> </ownedEnd> </packagedElement> diff --git a/examples/uml/duse-mt/src/plugins/concretesyntaxview/concretesyntaxviewplugin.cpp b/examples/uml/duse-mt/src/plugins/concretesyntaxview/concretesyntaxviewplugin.cpp index f90e57cd..6f0a76ab 100644 --- a/examples/uml/duse-mt/src/plugins/concretesyntaxview/concretesyntaxviewplugin.cpp +++ b/examples/uml/duse-mt/src/plugins/concretesyntaxview/concretesyntaxviewplugin.cpp @@ -74,7 +74,7 @@ bool ConcreteSyntaxViewPlugin::initialize(DuSE::ICore *core) void ConcreteSyntaxViewPlugin::addToView(QObject *selectedModelingObject, QQuickItem *parent) { QQmlContext *context = new QQmlContext(_concreteSyntaxQuickView->engine()->rootContext()); - context->setContextProperty(QStringLiteral("element"), selectedModelingObject); + context->setContextProperty("element", selectedModelingObject); QQmlComponent *qmlComponent = new QQmlComponent(_concreteSyntaxQuickView->engine()); int x = qrand() % 400; int y = qrand() % 400; @@ -83,13 +83,14 @@ void ConcreteSyntaxViewPlugin::addToView(QObject *selectedModelingObject, QQuick if (qmlComponent->isError()) { qWarning() << qmlComponent->errors(); } else { - QQuickItem *item = qobject_cast<QQuickItem *>(qmlComponent->create(context)); + QQuickItem *item = qobject_cast<QQuickItem *>(qmlComponent->beginCreate(context)); if (item) { - item->setParent(parent ? parent:(qobject_cast<QQuickFlickable *>(_concreteSyntaxQuickView->rootObject()))->contentItem()); item->setParentItem(parent ? parent:(qobject_cast<QQuickFlickable *>(_concreteSyntaxQuickView->rootObject()))->contentItem()); + qmlComponent->completeCreate(); } } +// _concreteSyntaxQuickView->rootObject()->dumpObjectTree(); qmlComponent->deleteLater(); } diff --git a/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/UmlAssociation.qml b/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/UmlAssociation.qml new file mode 100644 index 00000000..82928ba6 --- /dev/null +++ b/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/UmlAssociation.qml @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Sandro S. Andrade <sandroandrade@kde.org> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtUml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.0 +import QtModeling.Uml 1.0 +import "util.js" as Util + +Relationship { + end1: Util.findQuickItem(parent, element.memberEnds[0].class_.name) + end2: Util.findQuickItem(parent, element.memberEnds[0].type.name) + end1Aggregation: aggregation(element.memberEnds[0].aggregation); + end2Aggregation: aggregation(element.memberEnds[1].aggregation); + function aggregation(aggregationEnum) + { + switch (aggregationEnum) { + case 0: return "none" + case 1: return "shared" + case 2: return "composite" + } + } +} diff --git a/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/qmlplugin.pro b/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/qmlplugin.pro index 27668cf7..33fd7d4f 100644 --- a/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/qmlplugin.pro +++ b/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/qmlplugin.pro @@ -18,6 +18,11 @@ QML_FILES = \ UmlProperty.qml \ UmlAssociation.qml +# JavaScript + +QML_FILES += \ + util.js + # Images QML_FILES += \ images/resize-mark.png \ diff --git a/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/relationshipitem.cpp b/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/relationshipitem.cpp new file mode 100644 index 00000000..807ad3f4 --- /dev/null +++ b/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/relationshipitem.cpp @@ -0,0 +1,165 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Sandro S. Andrade <sandroandrade@kde.org> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtUml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "relationshipitem.h" + +#include <QtGui/QPainter> + +#include "private/qquickrectangle_p.h" + +RelationshipItem::RelationshipItem(QQuickItem *parent) + : QQuickPaintedItem(parent), + _end1(0), + _end2(0) +{ + setAntialiasing(true); +} + +void RelationshipItem::paint(QPainter *painter) +{ + if (!_end1 || !_end2) + return; + + qreal x1 = _end1->x(); qreal y1 = _end1->y(); qreal w1 = _end1->width(); qreal h1 = _end1->height(); + qreal x2 = _end2->x(); qreal y2 = _end2->y(); qreal w2 = _end2->width(); qreal h2 = _end2->height(); + + QLineF originalLine(x1 + w1/2, y1 + h1/2, x2 + w2/2, y2 + h2/2); + QPointF p1, p2; + + if (originalLine.intersect(QLineF(x1 , y1 , x1 + w1, y1 ), &p1) == QLineF::BoundedIntersection) {} else + if (originalLine.intersect(QLineF(x1 , y1 + h1, x1 + w1, y1 + h1), &p1) == QLineF::BoundedIntersection) {} else + if (originalLine.intersect(QLineF(x1 , y1 , x1 , y1 + h1), &p1) == QLineF::BoundedIntersection) {} else + if (originalLine.intersect(QLineF(x1 + w1, y1 , x1 + w1, y1 + h1), &p1) == QLineF::BoundedIntersection) {} + + if (originalLine.intersect(QLineF(x2 , y2 , x2 + w2, y2 ), &p2) == QLineF::BoundedIntersection) {} else + if (originalLine.intersect(QLineF(x2 , y2 + h2, x2 + w2, y2 + h2), &p2) == QLineF::BoundedIntersection) {} else + if (originalLine.intersect(QLineF(x2 , y2 , x2 , y2 + h2), &p2) == QLineF::BoundedIntersection) {} else + if (originalLine.intersect(QLineF(x2 + w2, y2 , x2 + w2, y2 + h2), &p2) == QLineF::BoundedIntersection) {} + + painter->drawLine(p1.x()-x(), p1.y()-y(), p2.x()-x(), p2.y()-y()); + QTransform transform; + transform.translate(p2.x()-x(), p2.y()-y()); + transform.rotate(-originalLine.angle()); + QPolygonF arrow(QVector<QPointF>() << QPointF(-10, -10) << QPointF(0, 0) << QPointF(-10, +10)); + painter->drawPolyline(transform.map(arrow)); +} + +QQuickRectangle *RelationshipItem::end1() const +{ + return _end1; +} + +void RelationshipItem::setEnd1(QQuickRectangle *end1) +{ + if (end1 != _end1) { + if (_end1) { + disconnect(end1, &QQuickRectangle::xChanged, this, &RelationshipItem::updateCoordinates); + disconnect(end1, &QQuickRectangle::yChanged, this, &RelationshipItem::updateCoordinates); + } + _end1 = end1; + if (!_end2) { + setX(_end1->x()); + setY(_end1->y()); + } + else { + updateCoordinates(); + } + connect(end1, &QQuickRectangle::xChanged, this, &RelationshipItem::updateCoordinates); + connect(end1, &QQuickRectangle::yChanged, this, &RelationshipItem::updateCoordinates); + } +} + +QQuickRectangle *RelationshipItem::end2() const +{ + return _end2; +} + +void RelationshipItem::setEnd2(QQuickRectangle *end2) +{ + if (end2 != _end2) { + if (_end2) { + disconnect(end2, &QQuickRectangle::xChanged, this, &RelationshipItem::updateCoordinates); + disconnect(end2, &QQuickRectangle::yChanged, this, &RelationshipItem::updateCoordinates); + } + _end2 = end2; + if (!_end1) { + setX(_end2->x()); + setY(_end2->y()); + } + else { + updateCoordinates(); + } + connect(end2, &QQuickRectangle::xChanged, this, &RelationshipItem::updateCoordinates); + connect(end2, &QQuickRectangle::yChanged, this, &RelationshipItem::updateCoordinates); + } +} + +QString RelationshipItem::end1Aggregation() const +{ + return _end1Aggregation; +} + +void RelationshipItem::setEnd1Aggregation(QString end1Aggregation) +{ + _end1Aggregation = end1Aggregation; +} + +QString RelationshipItem::end2Aggregation() const +{ + return _end2Aggregation; +} + +void RelationshipItem::setEnd2Aggregation(QString end2Aggregation) +{ + _end2Aggregation = end2Aggregation; +} + +void RelationshipItem::updateCoordinates() +{ + QQuickRectangle *minRectX = _end1->x() < _end2->x() ? _end1:_end2; + QQuickRectangle *minRectY = _end1->y() < _end2->y() ? _end1:_end2; + QQuickRectangle *maxRectX = minRectX == _end1 ? _end2:_end1; + QQuickRectangle *maxRectY = minRectY == _end1 ? _end2:_end1; + setX(minRectX->x()); + setY(minRectY->y()); + setWidth(qMax(maxRectX->x() + maxRectX->width() - minRectX->x(), qMax(_end1->width(), _end2->width()))); + setHeight(qMax(maxRectY->y() + maxRectY->height() - minRectY->y(), qMax(_end1->height(), _end2->height()))); +} + diff --git a/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/relationshipitem.h b/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/relationshipitem.h new file mode 100644 index 00000000..a5925617 --- /dev/null +++ b/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/relationshipitem.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Sandro S. Andrade <sandroandrade@kde.org> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtUml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef RELATIONSHIPITEM_H +#define RELATIONSHIPITEM_H + +#include <QtQuick/QQuickPaintedItem> + +class QQuickRectangle; + +class RelationshipItem : public QQuickPaintedItem +{ + Q_OBJECT + + Q_PROPERTY(QQuickRectangle * end1 READ end1 WRITE setEnd1) + Q_PROPERTY(QQuickRectangle * end2 READ end2 WRITE setEnd2) + Q_PROPERTY(QString end1Aggregation READ end1Aggregation WRITE setEnd1Aggregation) + Q_PROPERTY(QString end2Aggregation READ end2Aggregation WRITE setEnd2Aggregation) + +public: + RelationshipItem(QQuickItem *parent = 0); + + void paint(QPainter *painter); + + QQuickRectangle *end1() const; + void setEnd1(QQuickRectangle *end1); + + QQuickRectangle *end2() const; + void setEnd2(QQuickRectangle *end2); + + QString end1Aggregation() const; + void setEnd1Aggregation(QString end1Aggregation); + + QString end2Aggregation() const; + void setEnd2Aggregation(QString end2Aggregation); + +private Q_SLOTS: + void updateCoordinates(); + +private: + QQuickRectangle *_end1; + QQuickRectangle *_end2; + QString _end1Aggregation; + QString _end2Aggregation; +}; + +#endif // RELATIONSHIPITEM_H + diff --git a/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/util.js b/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/util.js index f422aca6..b8438d3f 100644 --- a/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/util.js +++ b/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/util.js @@ -52,3 +52,16 @@ function findElement(owner, elementName) { ret = owner; return ret; } + +function findQuickItem(parent, objectName) { + var ret = null; + for (var i = 0; i < parent.children.length; ++i) { + ret = findQuickItem(parent.children[i], objectName); + if (ret != null) + break; + } + if (ret == null && parent.objectName == objectName) { + ret = parent; + } + return ret; +} |