summaryrefslogtreecommitdiff
path: root/src/items/database
diff options
context:
space:
mode:
authorLukáš Lalinský <lalinsky@gmail.com>2008-12-30 10:26:14 +0100
committerLukáš Lalinský <lalinsky@gmail.com>2008-12-30 10:26:14 +0100
commit033bf7a0b5baa26af94ad006f6576d04c8609e9e (patch)
tree499e36f09515f2bc3f23cf09e2364666888002bb /src/items/database
parent3a95c3cd621e3904d717b591aaa9f2c89959981e (diff)
downloaddbmodel-033bf7a0b5baa26af94ad006f6576d04c8609e9e.tar.xz
Implement orthogonal line drawing
Diffstat (limited to 'src/items/database')
-rw-r--r--src/items/database/column.h3
-rw-r--r--src/items/database/databasecommands.cpp4
-rw-r--r--src/items/database/databaserelationship.cpp95
-rw-r--r--src/items/database/databaserelationship.h8
-rw-r--r--src/items/database/databasetable.cpp2
5 files changed, 40 insertions, 72 deletions
diff --git a/src/items/database/column.h b/src/items/database/column.h
index 36e6680..bbf4fff 100644
--- a/src/items/database/column.h
+++ b/src/items/database/column.h
@@ -20,8 +20,9 @@
#include <QObject>
#include <QString>
#include "columnlist.h"
+#include "identifiableobject.h"
-class Column : public QObject
+class Column : public QObject, public IdentifiableObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName)
diff --git a/src/items/database/databasecommands.cpp b/src/items/database/databasecommands.cpp
index 7156d4a..eae59db 100644
--- a/src/items/database/databasecommands.cpp
+++ b/src/items/database/databasecommands.cpp
@@ -26,8 +26,10 @@
AddColumnCommand::AddColumnCommand(ColumnList *columnList, Column *column, QUndoCommand *parent)
: QUndoCommand(parent), m_columnList(columnList), m_column(column)
{
- if (!m_column)
+ if (!m_column) {
m_column = new Column();
+ m_column->createId();
+ }
m_index = columnList->columnCount();
}
diff --git a/src/items/database/databaserelationship.cpp b/src/items/database/databaserelationship.cpp
index 3be258c..a95ac6e 100644
--- a/src/items/database/databaserelationship.cpp
+++ b/src/items/database/databaserelationship.cpp
@@ -291,8 +291,11 @@ DatabaseRelationship::updateLayout()
if (!scene())
return;
- DatabaseTable *source = sourceTable();
- DatabaseTable *target = targetTable();
+ Connector *connector1 = connector(0);
+ Connector *connector2 = connector(1);
+
+ DatabaseTable *source = childTable();
+ DatabaseTable *target = parentTable();
if (!source || !target)
return;
@@ -339,80 +342,42 @@ DatabaseRelationship::updateLayout()
}
}
- // Two-segment line
- if (0 && !haveLine) {
-
- qreal x1, x2, x3, y1, y2, y3;
-
- if (rect1.right() < rect2.left()) {
- x1 = rect1.right();
- y1 = verticalRange1.center();
-
- x2 = horizontalRange2.center();
- y2 = verticalRange1.center();
-
- if (rect1.bottom() < rect2.top()) {
- x3 = horizontalRange2.center();
- y3 = rect2.top();
- }
- else {
- x3 = horizontalRange2.center();
- y3 = rect2.bottom();
- }
+ // Orthogonal line
+ if (!haveLine) {
+ QPointF p1 = connector1->pos();
+ QPointF p2 = connector2->pos();
+ qreal a1 = connector1->angle();
+ qreal a2 = connector2->angle();
+
+ QLineF line1 = QLineF::fromPolar(1, a1).translated(p1);
+ QLineF line2 = QLineF::fromPolar(1, a2).translated(p2);
+ QPointF intersection;
+ d->line.clear();
+ d->line << p1;
+ if (line1.intersect(line2, &intersection) != QLineF::NoIntersection) {
+ // 2-segment line
+ d->line << intersection;
}
else {
- x1 = rect1.left();
- y1 = verticalRange1.center();
-
- x2 = horizontalRange2.center();
- y2 = verticalRange1.center();
-
- if (rect1.bottom() < rect2.top()) {
- x3 = horizontalRange2.center();
- y3 = rect2.top();
+ 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();
}
else {
- x3 = horizontalRange2.center();
- y3 = rect2.bottom();
+ qFatal("No line?");
}
}
-
- d->line = QPolygonF()
- << QPointF(x1, y1)
- << QPointF(x2, y2)
- << QPointF(x3, y3);
+ d->line << p2;
haveLine = true;
}
// Simple center<->center line
if (!haveLine) {
- QPointF p1 = rect1.center();
- QPointF p2 = rect2.center();
- QLineF finalLine = QLineF(p1, p2);
-
- QPolygonF polygon;
-
- polygon = rect1;
- for (int i = 0; i < 4; i++) {
- QLineF line(polygon[i], polygon[(i+1)%4]);
- QPointF intersectionPoint;
- if (finalLine.intersect(line, &intersectionPoint) == QLineF::BoundedIntersection) {
- finalLine.setP1(intersectionPoint);
- break;
- }
- }
-
- polygon = rect2;
- for (int i = 0; i < 4; i++) {
- QLineF line(polygon[i], polygon[(i+1)%4]);
- QPointF intersectionPoint;
- if (finalLine.intersect(line, &intersectionPoint) == QLineF::BoundedIntersection) {
- finalLine.setP2(intersectionPoint);
- break;
- }
- }
-
- d->line = QPolygonF() << finalLine.p1() << finalLine.p2();
+ QPointF p1 = connector1->pos();
+ QPointF p2 = connector2->pos();
+ d->line = QPolygonF() << p1 << p2;
haveLine = true;
}
diff --git a/src/items/database/databaserelationship.h b/src/items/database/databaserelationship.h
index 5a21c98..f8f381e 100644
--- a/src/items/database/databaserelationship.h
+++ b/src/items/database/databaserelationship.h
@@ -22,6 +22,7 @@
#include <QPainter>
#include "diagramconnection.h"
#include "databasetable.h"
+#include "connector.h"
class DatabaseRelationship : public DiagramConnection
{
@@ -41,11 +42,8 @@ public:
QPainterPath shape() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
- DatabaseTable *sourceTable() const { return qobject_cast<DatabaseTable *>(source()); }
- DatabaseTable *targetTable() const { return qobject_cast<DatabaseTable *>(target()); }
-
- DatabaseTable *childTable() const { return sourceTable(); }
- DatabaseTable *parentTable() const { return targetTable(); }
+ DatabaseTable *childTable() const { return qobject_cast<DatabaseTable *>(connector(0)->connectedObject()); }
+ DatabaseTable *parentTable() const { return qobject_cast<DatabaseTable *>(connector(1)->connectedObject()); }
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 ca3827b..3c6318a 100644
--- a/src/items/database/databasetable.cpp
+++ b/src/items/database/databasetable.cpp
@@ -22,12 +22,14 @@
#include "diagramdocument.h"
#include "column.h"
#include "columnlist.h"
+#include "boxsidehub.h"
DatabaseTable::DatabaseTable(DiagramItem *parent)
: DiagramObject(parent)
{
setFlag(ItemIsMovable);
setFlag(ItemIsSelectable);
+ setHub(new BoxSideHub(this));
m_columnList = new ColumnList(this);
connect(m_columnList, SIGNAL(columnInserted(int)), this, SLOT(updateLayout()));
connect(m_columnList, SIGNAL(columnRemoved(int)), this, SLOT(updateLayout()));