summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukáš Lalinský <lalinsky@gmail.com>2008-12-13 01:24:32 +0100
committerLukáš Lalinský <lalinsky@gmail.com>2008-12-13 01:24:32 +0100
commit3a95c3cd621e3904d717b591aaa9f2c89959981e (patch)
tree94478030549831f3dcf06ea3abba4b9f521da8d1
parent6f1ca5aaa1bbfe699434b4021b0bc101e5d28e8b (diff)
downloaddbmodel-3a95c3cd621e3904d717b591aaa9f2c89959981e.tar.gz
dbmodel-3a95c3cd621e3904d717b591aaa9f2c89959981e.tar.bz2
Draw non-identifying relationships using a dashed line in the Crow's Foot notation
-rw-r--r--src/diagramconnection.h4
-rw-r--r--src/items/database/databaserelationship.cpp45
-rw-r--r--src/items/database/databaserelationship.h8
-rw-r--r--src/items/database/databasetable.cpp2
4 files changed, 40 insertions, 19 deletions
diff --git a/src/diagramconnection.h b/src/diagramconnection.h
index 9ea97d5..8dcc721 100644
--- a/src/diagramconnection.h
+++ b/src/diagramconnection.h
@@ -27,8 +27,8 @@ class DiagramConnection : public DiagramItem
public:
DiagramConnection(DiagramItem *parent = 0);
- DiagramObject *source() { return m_objects[0]; }
- DiagramObject *target() { return m_objects[1]; }
+ DiagramObject *source() const { return m_objects[0]; }
+ DiagramObject *target() const { return m_objects[1]; }
void setSource(DiagramObject *object);
void setTarget(DiagramObject *object);
diff --git a/src/items/database/databaserelationship.cpp b/src/items/database/databaserelationship.cpp
index b03723c..3be258c 100644
--- a/src/items/database/databaserelationship.cpp
+++ b/src/items/database/databaserelationship.cpp
@@ -17,6 +17,7 @@
#include <QGraphicsScene>
#include <QDebug>
#include "diagramdocument.h"
+#include "column.h"
#include "databasetable.h"
#include "databaserelationship.h"
#include "databaserelationshipproperties.h"
@@ -27,8 +28,8 @@ class DatabaseRelationship::PrivateData
public:
PrivateData() :
cardinality(OneToMany),
- childOptional(false),
- parentOptional(false),
+ childOptional(true),
+ parentOptional(true),
onUpdateAction(NoAction),
onDeleteAction(NoAction),
childColumn(0),
@@ -37,9 +38,9 @@ public:
if (!pathsInitialized) {
pathsInitialized = true;
- paths[1].moveTo(-4.5, 0);
+ paths[1].moveTo(-5, 0);
paths[1].lineTo(0, 8);
- paths[1].lineTo(4.5, 0);
+ paths[1].lineTo(5, 0);
paths[1].moveTo(-4, 10);
paths[1].lineTo(4, 10);
@@ -52,9 +53,9 @@ public:
paths[2].lineTo(4, 5);
paths[2].addEllipse(-3.5, 8, 7, 7);
- paths[0].moveTo(-4.5, 0);
+ paths[0].moveTo(-5, 0);
paths[0].lineTo(0, 8);
- paths[0].lineTo(4.5, 0);
+ paths[0].lineTo(5, 0);
paths[0].addEllipse(-3.5, 8, 7, 7);
paths[4].moveTo(-4.5, 10);
@@ -75,6 +76,7 @@ public:
QPainterPath sourceEnd;
QPainterPath targetEnd;
QPolygonF line;
+ Qt::PenStyle lineStyle;
QPainterPath crowsFootPath(bool toMany, bool optional)
{
@@ -201,6 +203,19 @@ DatabaseRelationship::setParentColumn(Column *column)
}
}
+bool
+DatabaseRelationship::isIdentifying() const
+{
+ DatabaseTable *table = childTable();
+ if (table) {
+ Column *column = childColumn();
+ if (column) {
+ return column->isPrimaryKey();
+ }
+ }
+ return false;
+}
+
QRectF
DatabaseRelationship::boundingRect() const
{
@@ -218,7 +233,7 @@ DatabaseRelationship::shape() const
path.lineTo(d->line[i]);
path.addPath(d->targetEnd);
path.addPath(d->sourceEnd);
- QPen pen(QPen(QColor(0, 0, 0), 1));
+ QPen pen(QPen(QColor(0, 0, 0), 1.5));
pen.setJoinStyle(Qt::MiterJoin);
QPainterPathStroker ps;
ps.setCapStyle(pen.capStyle());
@@ -234,8 +249,9 @@ DatabaseRelationship::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
Q_UNUSED(option);
Q_UNUSED(widget);
- QPen pen(QPen(QColor(0, 0, 0), 1));
+ 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));
@@ -246,6 +262,9 @@ DatabaseRelationship::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
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);
}
@@ -404,11 +423,13 @@ DatabaseRelationship::updateLayout()
d->fillEnds = true;
d->targetEnd = d->arrowHeadPath();
d->sourceEnd = QPainterPath();
+ d->lineStyle = Qt::SolidLine;
break;
case DiagramDocument::CrowsFoot:
d->fillEnds = false;
- d->targetEnd = d->crowsFootPath(d->cardinality != OneToOne, isParentOptional());
- d->sourceEnd = d->crowsFootPath(d->cardinality == ManyToMany, isChildOptional());
+ d->targetEnd = d->crowsFootPath(d->cardinality == ManyToMany, isParentOptional());
+ d->sourceEnd = d->crowsFootPath(d->cardinality != OneToOne, isChildOptional());
+ d->lineStyle = isIdentifying() ? Qt::SolidLine : Qt::DashLine;
break;
}
@@ -441,8 +462,8 @@ DatabaseRelationship::loadFromXml(QDomElement element, DiagramDocument *document
setCardinality(readEnumElement(relationshipeElement, "cardinality", OneToMany, this, "Cardinality"));
QDomElement modalityElement = relationshipeElement.firstChildElement("modality");
if (!modalityElement.isNull()) {
- setChildOptional(readBoolElement(modalityElement, "child", false, "Optional", "Mandatory"));
- setParentOptional(readBoolElement(modalityElement, "parent", false, "Optional", "Mandatory"));
+ setChildOptional(readBoolElement(modalityElement, "child", true, "Optional", "Mandatory"));
+ setParentOptional(readBoolElement(modalityElement, "parent", true, "Optional", "Mandatory"));
}
}
}
diff --git a/src/items/database/databaserelationship.h b/src/items/database/databaserelationship.h
index c4c58a1..5a21c98 100644
--- a/src/items/database/databaserelationship.h
+++ b/src/items/database/databaserelationship.h
@@ -41,11 +41,11 @@ public:
QPainterPath shape() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
- DatabaseTable *sourceTable() { return qobject_cast<DatabaseTable *>(source()); }
- DatabaseTable *targetTable() { return qobject_cast<DatabaseTable *>(target()); }
+ DatabaseTable *sourceTable() const { return qobject_cast<DatabaseTable *>(source()); }
+ DatabaseTable *targetTable() const { return qobject_cast<DatabaseTable *>(target()); }
- DatabaseTable *childTable() { return sourceTable(); }
- DatabaseTable *parentTable() { return targetTable(); }
+ DatabaseTable *childTable() const { return sourceTable(); }
+ DatabaseTable *parentTable() const { return targetTable(); }
enum { Type = DiagramItem::Relation };
virtual int type() const { return Type; }
diff --git a/src/items/database/databasetable.cpp b/src/items/database/databasetable.cpp
index 2e3519a..ca3827b 100644
--- a/src/items/database/databasetable.cpp
+++ b/src/items/database/databasetable.cpp
@@ -65,9 +65,9 @@ DatabaseTable::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QPen pen(QPen(QColor(0, 0, 0)));
pen.setJoinStyle(Qt::MiterJoin);
QPen borderPen(pen);
+ borderPen.setWidth(1.5);
if (!document()->isPrinting() && isSelected()) {
borderPen.setColor(QColor(0, 96, 255));
- //borderPen.setWidth(2);
}
painter->setPen(pen);