summaryrefslogtreecommitdiffstats
path: root/examples/uml
diff options
context:
space:
mode:
authorSandro S. Andrade <sandroandrade@kde.org>2013-11-17 14:06:55 -0300
committerSandro S. Andrade <sandroandrade@kde.org>2013-11-17 18:02:50 +0100
commit90d49b82c2f6643cc7e3552471ee8e2fed40c412 (patch)
tree9979ca09d6fa6c5b7871d96e9b3acf2ca9c631b8 /examples/uml
parentdaca62af0f1be83f89368deea4dc9e6877d50420 (diff)
Add concrete syntax for generalization and multiplicities
Change-Id: Ia64fee0ac964b5e969801b81898e93d7b0a9bb83 Reviewed-by: Sandro S. Andrade <sandroandrade@kde.org>
Diffstat (limited to 'examples/uml')
-rw-r--r--examples/uml/duse-mt/src/app/example.xmi9
-rw-r--r--examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/UmlAssociation.qml12
-rw-r--r--examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/UmlGeneralization.qml49
-rw-r--r--examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/qmldir1
-rw-r--r--examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/qmlplugin.pro3
-rw-r--r--examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/relationshipitem.cpp157
-rw-r--r--examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/relationshipitem.h52
7 files changed, 210 insertions, 73 deletions
diff --git a/examples/uml/duse-mt/src/app/example.xmi b/examples/uml/duse-mt/src/app/example.xmi
index 1e561dd5..900c00b0 100644
--- a/examples/uml/duse-mt/src/app/example.xmi
+++ b/examples/uml/duse-mt/src/app/example.xmi
@@ -9,10 +9,12 @@
</elementImport>
<packagedElement xmi:type="uml:Association" name="A_student_professor" xmi:id="MyRootPackage-A_student_professor">
<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">
+ <memberEnd xmi:idref="MyRootPackage-A_student_professor-student"/>
+ <ownedEnd xmi:type="uml:Property" name="student" visibility="public" xmi:id="MyRootPackage-A_student_professor-student">
<type xmi:idref="MyRootPackage-Package1-Student"/>
<association xmi:idref="MyRootPackage-A_student_professor"/>
+ <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="MyRootPackage-A_student_professor-student-_upperValue" value="4"/>
+ <lowerValue xmi:type="uml:LiteralInteger" xmi:id="MyRootPackage-A_student_professor-student-_lowerValue"/>
</ownedEnd>
</packagedElement>
<packagedElement xmi:type="uml:Association" name="A_student_enrollment" xmi:id="MyRootPackage-A_student_enrollment">
@@ -33,6 +35,8 @@
</ownedAttribute>
<ownedAttribute xmi:type="uml:Property" visibility="public" name="advisor" xmi:id="MyRootPackage-Package1-Student-advisor" aggregation="shared">
<type href="MyRootPackage-Package1-Professor"/>
+ <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="MyRootPackage-Package1-Student-advisor-_upperValue" value="*"/>
+ <lowerValue xmi:type="uml:LiteralInteger" xmi:id="MyRootPackage-Package1-Student-advisor-_lowerValue"/>
</ownedAttribute>
<ownedAttribute xmi:type="uml:Property" visibility="public" name="enrollment" xmi:id="MyRootPackage-Package1-Student-enrollment" aggregation="composite">
<type href="MyRootPackage-Package1-Enrollment"/>
@@ -59,6 +63,7 @@
<ownedLiteral xmi:type="uml:EnumerationLiteral" name="DirectionIn" xmi:id="MyRootPackage-Package1-DirectionKind-DirectionIn"/>
</packagedElement>
<packagedElement xmi:type="uml:Class" name="InterStudent" xmi:id="MyRootPackage-Package1-InterStudent">
+ <generalization xmi:type="uml:Generalization" xmi:id="MyRootPackage-Package1-InterStudent-_generalization.0" general="MyRootPackage-Package1-Student"/>
<ownedAttribute xmi:type="uml:Property" name="studentId" xmi:id="MyRootPackage-Package1-InterStudent-studentId"/>
</packagedElement>
</packagedElement>
diff --git a/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/UmlAssociation.qml b/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/UmlAssociation.qml
index 82928ba6..fe3468fe 100644
--- a/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/UmlAssociation.qml
+++ b/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/UmlAssociation.qml
@@ -43,10 +43,14 @@ 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);
+ name: element.name
+ relationshipType: "association"
+ source: Util.findQuickItem(parent, element.memberEnds[0].class_.name)
+ target: Util.findQuickItem(parent, element.memberEnds[0].type.name)
+ sourceAggregation: aggregation(element.memberEnds[0].aggregation);
+ targetAggregation: aggregation(element.memberEnds[1].aggregation);
+ sourceMultiplicity: element.memberEnds[0].lowerValue.value + ".." + element.memberEnds[0].upperValue.value
+ targetMultiplicity: element.memberEnds[1].lowerValue.value + ".." + element.memberEnds[1].upperValue.value
function aggregation(aggregationEnum)
{
switch (aggregationEnum) {
diff --git a/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/UmlGeneralization.qml b/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/UmlGeneralization.qml
new file mode 100644
index 00000000..4928a5ca
--- /dev/null
+++ b/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/UmlGeneralization.qml
@@ -0,0 +1,49 @@
+/****************************************************************************
+**
+** 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 {
+ relationshipType: "generalization"
+ source: Util.findQuickItem(parent, element.specific.name)
+ target: Util.findQuickItem(parent, element.general.name)
+}
diff --git a/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/qmldir b/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/qmldir
index 105ea978..a344dd61 100644
--- a/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/qmldir
+++ b/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/qmldir
@@ -5,4 +5,5 @@ UmlClass 1.0 UmlClass.qml
UmlComponent 1.0 UmlComponent.qml
UmlProperty 1.0 UmlProperty.qml
UmlAssociation 1.0 UmlAssociation.qml
+UmlGeneralization 1.0 UmlGeneralization.qml
plugin qtmodelingumlplugin
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 33fd7d4f..709fd65f 100644
--- a/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/qmlplugin.pro
+++ b/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/qmlplugin.pro
@@ -16,7 +16,8 @@ QML_FILES = \
UmlClass.qml \
UmlComponent.qml \
UmlProperty.qml \
- UmlAssociation.qml
+ UmlAssociation.qml \
+ UmlGeneralization.qml
# JavaScript
diff --git a/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/relationshipitem.cpp b/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/relationshipitem.cpp
index f528436f..47fc8037 100644
--- a/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/relationshipitem.cpp
+++ b/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/relationshipitem.cpp
@@ -42,23 +42,28 @@
#include <QtGui/QPainter>
+#include <QtWidgets/QApplication>
+
#include "private/qquickrectangle_p.h"
RelationshipItem::RelationshipItem(QQuickItem *parent)
: QQuickPaintedItem(parent),
- _end1(0),
- _end2(0)
+ _source(0),
+ _target(0),
+ _relationshipType("association"),
+ _sourceAggregation("none"),
+ _targetAggregation("none")
{
setAntialiasing(true);
}
void RelationshipItem::paint(QPainter *painter)
{
- if (!_end1 || !_end2)
+ if (!_source || !_target)
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();
+ qreal x1 = _source->x(); qreal y1 = _source->y(); qreal w1 = _source->width(); qreal h1 = _source->height();
+ qreal x2 = _target->x(); qreal y2 = _target->y(); qreal w2 = _target->width(); qreal h2 = _target->height();
QLineF originalLine(x1 + w1/2, y1 + h1/2, x2 + w2/2, y2 + h2/2);
QPointF p1, p2;
@@ -74,15 +79,27 @@ void RelationshipItem::paint(QPainter *painter)
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());
- QPolygonF arrow(QVector<QPointF>() << QPointF(-10, -10) << QPointF(0, 0) << QPointF(-10, +10));
+ QPolygonF arrow(QVector<QPointF>() << QPointF(-12, -8) << QPointF(0, 0) << QPointF(-12, 8));
QTransform transform;
transform.translate(p2.x()-x(), p2.y()-y());
transform.rotate(-originalLine.angle());
- painter->drawPolyline(transform.map(arrow));
+ if (_relationshipType == "association") {
+ painter->drawPolyline(transform.map(arrow));
+ QFont font("Korolev");
+ QFontMetrics metrics(font);
+ painter->setFont(font);
+ painter->drawText(p1.x()-x()+(p2.x()-x()-(p1.x()-x()))/2+10, p1.y()-y()+(p2.y()-y()-(p1.y()-y()))/2, _name);
+ painter->drawText(p2.x()-x()+10, p2.y()-y()-10, _sourceMultiplicity);
+ painter->drawText(p1.x()-x()+10, p1.y()-y()-10, _targetMultiplicity);
+ }
+ else if (_relationshipType == "generalization") {
+ painter->setBrush(QBrush(Qt::white));
+ painter->drawPolygon(transform.map(arrow));
+ }
- if (_end1Aggregation == "composite" || _end1Aggregation == "shared") {
- painter->setBrush(QBrush(_end1Aggregation == "composite" ? Qt::black:Qt::white));
- QPolygon diamond(QVector<QPoint>() << QPoint(0, 0) << QPoint(10, -10) << QPoint(20, 0) << QPoint(10, 10));
+ if (_relationshipType == "association" && (_sourceAggregation == "composite" || _sourceAggregation == "shared")) {
+ painter->setBrush(QBrush(_sourceAggregation == "composite" ? Qt::black:Qt::white));
+ QPolygon diamond(QVector<QPoint>() << QPoint(0, 0) << QPoint(12, -8) << QPoint(24, 0) << QPoint(12, 8));
QTransform transform;
transform.translate(p1.x()-x(), p1.y()-y());
transform.rotate(-originalLine.angle());
@@ -90,85 +107,125 @@ void RelationshipItem::paint(QPainter *painter)
}
}
-QQuickRectangle *RelationshipItem::end1() const
+QString RelationshipItem::name() const
+{
+ return _name;
+}
+
+void RelationshipItem::setName(QString name)
+{
+ _name = name;
+}
+
+QQuickRectangle *RelationshipItem::source() const
{
- return _end1;
+ return _source;
}
-void RelationshipItem::setEnd1(QQuickRectangle *end1)
+void RelationshipItem::setSource(QQuickRectangle *source)
{
- if (end1 != _end1) {
- if (_end1) {
- disconnect(end1, &QQuickRectangle::xChanged, this, &RelationshipItem::updateCoordinates);
- disconnect(end1, &QQuickRectangle::yChanged, this, &RelationshipItem::updateCoordinates);
+ if (source != _source) {
+ if (_source) {
+ disconnect(source, &QQuickRectangle::xChanged, this, &RelationshipItem::updateCoordinates);
+ disconnect(source, &QQuickRectangle::yChanged, this, &RelationshipItem::updateCoordinates);
}
- _end1 = end1;
- if (!_end2) {
- setX(_end1->x());
- setY(_end1->y());
+ _source = source;
+ if (!_target) {
+ setX(_source->x());
+ setY(_source->y());
}
else {
updateCoordinates();
}
- connect(end1, &QQuickRectangle::xChanged, this, &RelationshipItem::updateCoordinates);
- connect(end1, &QQuickRectangle::yChanged, this, &RelationshipItem::updateCoordinates);
+ connect(source, &QQuickRectangle::xChanged, this, &RelationshipItem::updateCoordinates);
+ connect(source, &QQuickRectangle::yChanged, this, &RelationshipItem::updateCoordinates);
}
}
-QQuickRectangle *RelationshipItem::end2() const
+QQuickRectangle *RelationshipItem::target() const
{
- return _end2;
+ return _target;
}
-void RelationshipItem::setEnd2(QQuickRectangle *end2)
+void RelationshipItem::setTarget(QQuickRectangle *target)
{
- if (end2 != _end2) {
- if (_end2) {
- disconnect(end2, &QQuickRectangle::xChanged, this, &RelationshipItem::updateCoordinates);
- disconnect(end2, &QQuickRectangle::yChanged, this, &RelationshipItem::updateCoordinates);
+ if (target != _target) {
+ if (_target) {
+ disconnect(target, &QQuickRectangle::xChanged, this, &RelationshipItem::updateCoordinates);
+ disconnect(target, &QQuickRectangle::yChanged, this, &RelationshipItem::updateCoordinates);
}
- _end2 = end2;
- if (!_end1) {
- setX(_end2->x());
- setY(_end2->y());
+ _target = target;
+ if (!_source) {
+ setX(_target->x());
+ setY(_target->y());
}
else {
updateCoordinates();
}
- connect(end2, &QQuickRectangle::xChanged, this, &RelationshipItem::updateCoordinates);
- connect(end2, &QQuickRectangle::yChanged, this, &RelationshipItem::updateCoordinates);
+ connect(target, &QQuickRectangle::xChanged, this, &RelationshipItem::updateCoordinates);
+ connect(target, &QQuickRectangle::yChanged, this, &RelationshipItem::updateCoordinates);
}
}
-QString RelationshipItem::end1Aggregation() const
+QString RelationshipItem::relationshipType() const
+{
+ return _relationshipType;
+}
+
+void RelationshipItem::setRelationshipType(QString relationshipType)
+{
+ _relationshipType = relationshipType;
+}
+
+QString RelationshipItem::sourceAggregation() const
+{
+ return _sourceAggregation;
+}
+
+void RelationshipItem::setSourceAggregation(QString sourceAggregation)
+{
+ _sourceAggregation = sourceAggregation;
+}
+
+QString RelationshipItem::targetAggregation() const
+{
+ return _targetAggregation;
+}
+
+void RelationshipItem::setTargetAggregation(QString targetAggregation)
+{
+ _targetAggregation = targetAggregation;
+}
+
+QString RelationshipItem::sourceMultiplicity() const
{
- return _end1Aggregation;
+ return _sourceMultiplicity;
}
-void RelationshipItem::setEnd1Aggregation(QString end1Aggregation)
+void RelationshipItem::setSourceMultiplicity(QString sourceMultiplicity)
{
- _end1Aggregation = end1Aggregation;
+ _sourceMultiplicity = sourceMultiplicity;
}
-QString RelationshipItem::end2Aggregation() const
+QString RelationshipItem::targetMultiplicity() const
{
- return _end2Aggregation;
+ return _targetMultiplicity;
}
-void RelationshipItem::setEnd2Aggregation(QString end2Aggregation)
+void RelationshipItem::setTargetMultiplicity(QString targetMultiplicity)
{
- _end2Aggregation = end2Aggregation;
+ _targetMultiplicity = targetMultiplicity;
}
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;
+ QQuickRectangle *minRectX = _source->x() < _target->x() ? _source:_target;
+ QQuickRectangle *minRectY = _source->y() < _target->y() ? _source:_target;
+ QQuickRectangle *maxRectX = minRectX == _source ? _target:_source;
+ QQuickRectangle *maxRectY = minRectY == _source ? _target:_source;
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())));
+ setWidth(qMax(maxRectX->x() + maxRectX->width() - minRectX->x(), qMax(_source->width(), _target->width())));
+ setHeight(qMax(maxRectY->y() + maxRectY->height() - minRectY->y(), qMax(_source->height(), _target->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
index a5925617..4dc47770 100644
--- a/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/relationshipitem.h
+++ b/examples/uml/duse-mt/src/plugins/umlconcretesyntax/qmlplugin/relationshipitem.h
@@ -49,36 +49,56 @@ 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)
+ Q_PROPERTY(QString name READ name WRITE setName)
+ Q_PROPERTY(QQuickRectangle * source READ source WRITE setSource)
+ Q_PROPERTY(QQuickRectangle * target READ target WRITE setTarget)
+ Q_PROPERTY(QString relationshipType READ relationshipType WRITE setRelationshipType)
+ Q_PROPERTY(QString sourceAggregation READ sourceAggregation WRITE setSourceAggregation)
+ Q_PROPERTY(QString targetAggregation READ targetAggregation WRITE setTargetAggregation)
+ Q_PROPERTY(QString sourceMultiplicity READ sourceMultiplicity WRITE setSourceMultiplicity)
+ Q_PROPERTY(QString targetMultiplicity READ targetMultiplicity WRITE setTargetMultiplicity)
public:
RelationshipItem(QQuickItem *parent = 0);
void paint(QPainter *painter);
- QQuickRectangle *end1() const;
- void setEnd1(QQuickRectangle *end1);
+ QString name() const;
+ void setName(QString name);
- QQuickRectangle *end2() const;
- void setEnd2(QQuickRectangle *end2);
+ QQuickRectangle *source() const;
+ void setSource(QQuickRectangle *source);
- QString end1Aggregation() const;
- void setEnd1Aggregation(QString end1Aggregation);
+ QQuickRectangle *target() const;
+ void setTarget(QQuickRectangle *target);
- QString end2Aggregation() const;
- void setEnd2Aggregation(QString end2Aggregation);
+ QString relationshipType() const;
+ void setRelationshipType(QString relationshipType);
+
+ QString sourceAggregation() const;
+ void setSourceAggregation(QString sourceAggregation);
+
+ QString targetAggregation() const;
+ void setTargetAggregation(QString targetAggregation);
+
+ QString sourceMultiplicity() const;
+ void setSourceMultiplicity(QString sourceMultiplicity);
+
+ QString targetMultiplicity() const;
+ void setTargetMultiplicity(QString targetMultiplicity);
private Q_SLOTS:
void updateCoordinates();
private:
- QQuickRectangle *_end1;
- QQuickRectangle *_end2;
- QString _end1Aggregation;
- QString _end2Aggregation;
+ QString _name;
+ QQuickRectangle *_source;
+ QQuickRectangle *_target;
+ QString _relationshipType;
+ QString _sourceAggregation;
+ QString _targetAggregation;
+ QString _sourceMultiplicity;
+ QString _targetMultiplicity;
};
#endif // RELATIONSHIPITEM_H