summaryrefslogtreecommitdiff
path: root/src/items/database/databaserelationship.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/items/database/databaserelationship.cpp')
-rw-r--r--src/items/database/databaserelationship.cpp115
1 files changed, 22 insertions, 93 deletions
diff --git a/src/items/database/databaserelationship.cpp b/src/items/database/databaserelationship.cpp
index aacacf6..c1cddce 100644
--- a/src/items/database/databaserelationship.cpp
+++ b/src/items/database/databaserelationship.cpp
@@ -62,9 +62,10 @@ public:
paths[0].lineTo(5, 0);
paths[0].addEllipse(-3.5, 8, 7, 7);
- paths[4].moveTo(-4.5, 10);
+ paths[4].moveTo(-4.5, 9);
paths[4].lineTo(0, 0);
- paths[4].lineTo(4.5, 10);
+ paths[4].lineTo(4.5, 9);
+ paths[4].lineTo(-4.5, 9);
}
}
@@ -76,12 +77,6 @@ public:
Column *childColumn;
Column *parentColumn;
- bool fillEnds;
- QPainterPath sourceEnd;
- QPainterPath targetEnd;
- QPolygonF line;
- Qt::PenStyle lineStyle;
-
QPainterPath crowsFootPath(bool toMany, bool optional)
{
if (toMany) {
@@ -220,59 +215,6 @@ DatabaseRelationship::isIdentifying() const
return false;
}
-QRectF
-DatabaseRelationship::boundingRect() const
-{
- return shape().controlPointRect();
-}
-
-QPainterPath
-DatabaseRelationship::shape() const
-{
- QPainterPath path;
- if (d->line.isEmpty())
- return path;
- path.moveTo(d->line[0]);
- for (int i = 1; i < d->line.size(); i++)
- path.lineTo(d->line[i]);
- path.addPath(d->targetEnd);
- path.addPath(d->sourceEnd);
- QPen pen(QPen(QColor(0, 0, 0), 1.33));
- pen.setJoinStyle(Qt::MiterJoin);
- QPainterPathStroker ps;
- ps.setCapStyle(pen.capStyle());
- ps.setWidth(pen.widthF() + 2);
- ps.setJoinStyle(pen.joinStyle());
- ps.setMiterLimit(pen.miterLimit());
- return ps.createStroke(path);
-}
-
-void
-DatabaseRelationship::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
-{
- Q_UNUSED(option);
- Q_UNUSED(widget);
-
- QPen pen(QPen(QColor(0, 0, 0), 1.5));
- pen.setJoinStyle(Qt::MiterJoin);
- pen.setStyle(d->lineStyle);
-
- if (!document()->isPrinting() && isSelected()) {
- pen.setColor(QColor(0, 96, 255));
-// pen.setWidth(2);
- }
-
- painter->setPen(pen);
- painter->drawPolyline(d->line);
- if (d->fillEnds)
- painter->setBrush(pen.color());
-
- pen.setStyle(Qt::SolidLine);
- painter->setPen(pen);
- painter->drawPath(d->sourceEnd);
- painter->drawPath(d->targetEnd);
-}
-
QVariant
DatabaseRelationship::itemChange(GraphicsItemChange change, const QVariant &value)
{
@@ -290,35 +232,20 @@ DatabaseRelationship::updateEnds()
switch (document()->notation()) {
case DiagramDocument::Relational:
- d->fillEnds = true;
- d->targetEnd = d->arrowHeadPath();
- d->sourceEnd = QPainterPath();
- d->lineStyle = Qt::SolidLine;
+ setFillStartArrow(false);
+ setFillEndArrow(true);
+ setStartArrow(QPainterPath());
+ setEndArrow(d->arrowHeadPath());
+ setLineStyle(Qt::SolidLine);
break;
case DiagramDocument::CrowsFoot:
- d->fillEnds = false;
- d->targetEnd = d->crowsFootPath(d->cardinality == ManyToMany, isParentOptional());
- d->sourceEnd = d->crowsFootPath(d->cardinality != OneToOne, isChildOptional());
- d->lineStyle = isIdentifying() ? Qt::SolidLine : Qt::DashLine;
+ setFillStartArrow(false);
+ setFillEndArrow(false);
+ setStartArrow(d->crowsFootPath(d->cardinality != OneToOne, isChildOptional()));
+ setEndArrow(d->crowsFootPath(d->cardinality == ManyToMany, isParentOptional()));
+ setLineStyle(isIdentifying() ? Qt::SolidLine : Qt::DashLine);
break;
}
-
- if (!d->sourceEnd.isEmpty()) {
- QLineF firstSegment(d->line[0], d->line[1]);
- QMatrix matrix;
- matrix.translate(firstSegment.p1().x(), firstSegment.p1().y());
- matrix.rotate(360 - firstSegment.angle() + 90 + 180);
- d->sourceEnd = matrix.map(d->sourceEnd);
- }
-
- if (!d->targetEnd.isEmpty()) {
- int size = d->line.size();
- QLineF lastSegment(d->line[size-2], d->line[size-1]);
- QMatrix matrix;
- matrix.translate(lastSegment.p2().x(), lastSegment.p2().y());
- matrix.rotate(-lastSegment.angle() + 90);
- d->targetEnd = matrix.map(d->targetEnd);
- }
}
void
@@ -331,6 +258,8 @@ DatabaseRelationship::updateLayout()
bool haveLine = false;
+ QPolygonF line;
+
// Orthogonal line
if (!haveLine) {
QPointF p1 = connector1->pos();
@@ -341,24 +270,23 @@ DatabaseRelationship::updateLayout()
QLineF line1 = QLineF::fromPolar(1, a1).translated(p1);
QLineF line2 = QLineF::fromPolar(1, a2).translated(p2);
QPointF intersection;
- d->line.clear();
- d->line << p1;
+ line << p1;
if (line1.intersect(line2, &intersection) != QLineF::NoIntersection) {
// 2-segment line
- d->line << intersection;
+ line << intersection;
}
else {
if (line1.intersect(line2.normalVector(), &intersection) != QLineF::NoIntersection) {
// 3-segment line
qreal len = QLineF(p1, intersection).length() * 0.5;
- d->line << QLineF::fromPolar(len, a1).translated(p1).p2();
- d->line << QLineF::fromPolar(len, a2).translated(p2).p2();
+ line << QLineF::fromPolar(len, a1).translated(p1).p2();
+ line << QLineF::fromPolar(len, a2).translated(p2).p2();
}
else {
qFatal("No line?");
}
}
- d->line << p2;
+ line << p2;
haveLine = true;
}
@@ -366,10 +294,11 @@ DatabaseRelationship::updateLayout()
if (!haveLine) {
QPointF p1 = connector1->pos();
QPointF p2 = connector2->pos();
- d->line = QPolygonF() << p1 << p2;
+ line << p1 << p2;
haveLine = true;
}
+ setLinePoints(line);
updateEnds();
}