summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--databasemodel.cpp18
-rw-r--r--databasemodel.h6
-rw-r--r--databaserelationship.cpp (renamed from databaserelation.cpp)22
-rw-r--r--databaserelationship.h (renamed from databaserelation.h)8
-rw-r--r--databasetable.cpp4
-rw-r--r--databasetable.h8
-rw-r--r--dbmodel.pro12
-rw-r--r--diagramitem.cpp (renamed from databasemodelitem.cpp)4
-rw-r--r--diagramitem.h (renamed from databasemodelitem.h)5
-rw-r--r--diagramobject.cpp22
-rw-r--r--diagramobject.h28
11 files changed, 96 insertions, 41 deletions
diff --git a/databasemodel.cpp b/databasemodel.cpp
index 60a54e0..4068ca5 100644
--- a/databasemodel.cpp
+++ b/databasemodel.cpp
@@ -16,7 +16,7 @@
#include "databasemodel.h"
#include "databasetable.h"
-#include "databaserelation.h"
+#include "databaserelationship.h"
#include "column.h"
#include <QGraphicsItem>
#include <QDebug>
@@ -46,7 +46,7 @@ DatabaseModel::setMode(Mode mode)
void
DatabaseModel::updatePositions(DatabaseTable *table)
{
- foreach (DatabaseRelation *relation, findTableRelations(table)) {
+ foreach (DatabaseRelationship *relation, findTableRelations(table)) {
relation->updatePositions();
}
}
@@ -97,7 +97,7 @@ DatabaseModel::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
DatabaseTable *target = qgraphicsitem_cast<DatabaseTable *>(itemAt(m_line->line().p2()));
if (source && target && source != target) {
//qDebug() << "Add relation between " << source << " and " << target;
- DatabaseRelation *relation = new DatabaseRelation();
+ DatabaseRelationship *relation = new DatabaseRelationship();
relation->setSource(source);
relation->setTarget(target);
relation->setZValue(1.0);
@@ -129,7 +129,7 @@ DatabaseModel::deleteSelectedItems()
foreach (QGraphicsItem *item, selectedItems()) {
DatabaseTable *table = qgraphicsitem_cast<DatabaseTable *>(item);
if (table) {
- foreach (DatabaseRelation *relation, findTableRelations(table)) {
+ foreach (DatabaseRelationship *relation, findTableRelations(table)) {
removeItem(relation);
m_relations.removeAll(relation);
}
@@ -139,11 +139,11 @@ DatabaseModel::deleteSelectedItems()
}
}
-QList<DatabaseRelation *>
+QList<DatabaseRelationship *>
DatabaseModel::findTableRelations(DatabaseTable *table)
{
- QList<DatabaseRelation *> result;
- foreach (DatabaseRelation *relation, m_relations) {
+ QList<DatabaseRelationship *> result;
+ foreach (DatabaseRelationship *relation, m_relations) {
if (relation->source() == table || relation->target() == table) {
result << relation;
}
@@ -212,7 +212,7 @@ DatabaseModel::save(const QString &fileName)
QDomElement relationListElement = doc.createElement("relation-list");
root.appendChild(relationListElement);
- foreach (DatabaseRelation *relation, m_relations) {
+ foreach (DatabaseRelationship *relation, m_relations) {
QDomElement relationElement = doc.createElement("relation");
relationElement.setAttribute("from", QString::number(m_tables.indexOf(relation->source())));
relationElement.setAttribute("to", QString::number(m_tables.indexOf(relation->target())));
@@ -286,7 +286,7 @@ DatabaseModel::load(const QString &fileName)
if (ok) {
int index1 = relationElement.attribute("to").toInt(&ok);
if (ok) {
- DatabaseRelation *relation = new DatabaseRelation();
+ DatabaseRelationship *relation = new DatabaseRelationship();
relation->setSource(m_tables[index0]);
relation->setTarget(m_tables[index1]);
m_relations << relation;
diff --git a/databasemodel.h b/databasemodel.h
index 10efed3..eeb79a1 100644
--- a/databasemodel.h
+++ b/databasemodel.h
@@ -24,7 +24,7 @@
#include <QGraphicsLineItem>
class DatabaseTable;
-class DatabaseRelation;
+class DatabaseRelationship;
class DatabaseModel : public QGraphicsScene
{
@@ -44,7 +44,7 @@ public:
DatabaseTable *selectedTable();
void deleteSelectedItems();
- QList<DatabaseRelation *> findTableRelations(DatabaseTable *table);
+ QList<DatabaseRelationship *> findTableRelations(DatabaseTable *table);
void save(const QString &fileName);
void load(const QString &fileName);
@@ -74,7 +74,7 @@ private:
QString m_fileName;
QGraphicsLineItem *m_line;
QList<DatabaseTable *> m_tables;
- QList<DatabaseRelation *> m_relations;
+ QList<DatabaseRelationship *> m_relations;
};
#endif
diff --git a/databaserelation.cpp b/databaserelationship.cpp
index 4345691..b114a4a 100644
--- a/databaserelation.cpp
+++ b/databaserelationship.cpp
@@ -17,23 +17,23 @@
#include <QGraphicsScene>
#include <QDebug>
#include "databasetable.h"
-#include "databaserelation.h"
+#include "databaserelationship.h"
-DatabaseRelation::DatabaseRelation(QGraphicsItem *parent)
- : DatabaseModelItem(parent), m_source(0), m_target(0)
+DatabaseRelationship::DatabaseRelationship(DiagramItem *parent)
+ : DiagramConnection(parent), m_source(0), m_target(0)
{
setFlag(ItemIsSelectable);
}
QRectF
-DatabaseRelation::boundingRect() const
+DatabaseRelationship::boundingRect() const
{
return shape().boundingRect();
//return QRectF(m_line.p1(), m_line.p2()).normalized();
}
QPainterPath
-DatabaseRelation::shape() const
+DatabaseRelationship::shape() const
{
QPainterPath path;
path.moveTo(m_line.p1());
@@ -50,7 +50,7 @@ DatabaseRelation::shape() const
}
void
-DatabaseRelation::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+DatabaseRelationship::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
@@ -64,7 +64,7 @@ DatabaseRelation::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio
}
void
-DatabaseRelation::setSource(DatabaseTable *source)
+DatabaseRelationship::setSource(DatabaseTable *source)
{
m_source = source;
if (scene()) {
@@ -73,7 +73,7 @@ DatabaseRelation::setSource(DatabaseTable *source)
}
void
-DatabaseRelation::setTarget(DatabaseTable *target)
+DatabaseRelationship::setTarget(DatabaseTable *target)
{
m_target = target;
if (scene()) {
@@ -82,7 +82,7 @@ DatabaseRelation::setTarget(DatabaseTable *target)
}
QVariant
-DatabaseRelation::itemChange(GraphicsItemChange change, const QVariant &value)
+DatabaseRelationship::itemChange(GraphicsItemChange change, const QVariant &value)
{
if (change == ItemSceneHasChanged) {
updateLayout();
@@ -91,13 +91,13 @@ DatabaseRelation::itemChange(GraphicsItemChange change, const QVariant &value)
}
void
-DatabaseRelation::updatePositions()
+DatabaseRelationship::updatePositions()
{
updateLayout();
}
void
-DatabaseRelation::updateLayout()
+DatabaseRelationship::updateLayout()
{
if (!scene())
return;
diff --git a/databaserelation.h b/databaserelationship.h
index f938d28..b761e15 100644
--- a/databaserelation.h
+++ b/databaserelationship.h
@@ -19,14 +19,14 @@
#include <QGraphicsItem>
#include <QPainter>
-#include "databasemodelitem.h"
+#include "diagramconnection.h"
class DatabaseTable;
-class DatabaseRelation : public DatabaseModelItem
+class DatabaseRelationship : public DiagramConnection
{
public:
- DatabaseRelation(QGraphicsItem *parent = 0);
+ DatabaseRelationship(DiagramItem *parent = 0);
QRectF boundingRect() const;
QPainterPath shape() const;
@@ -38,7 +38,7 @@ public:
DatabaseTable *target() { return m_target; }
void setTarget(DatabaseTable *target);
- enum { Type = DatabaseModelItem::Relation };
+ enum { Type = DiagramItem::Relation };
virtual int type() const { return Type; }
void updatePositions();
diff --git a/databasetable.cpp b/databasetable.cpp
index 2623e68..6d406e1 100644
--- a/databasetable.cpp
+++ b/databasetable.cpp
@@ -21,8 +21,8 @@
#include "column.h"
#include "columnlist.h"
-DatabaseTable::DatabaseTable(QGraphicsItem *parent)
- : DatabaseModelItem(parent)
+DatabaseTable::DatabaseTable(DiagramItem *parent)
+ : DiagramObject(parent)
{
setFlag(ItemIsMovable);
setFlag(ItemIsSelectable);
diff --git a/databasetable.h b/databasetable.h
index e11b152..b1711bf 100644
--- a/databasetable.h
+++ b/databasetable.h
@@ -19,19 +19,19 @@
#include <QGraphicsItem>
#include <QPainter>
-#include "databasemodelitem.h"
+#include "diagramobject.h"
class Column;
class ColumnList;
class DatabaseModel;
-class DatabaseTable : public QObject, public DatabaseModelItem
+class DatabaseTable : public DiagramObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName)
public:
- DatabaseTable(QGraphicsItem *parent = 0);
+ DatabaseTable(DiagramItem *parent = 0);
DatabaseModel *model() const;
@@ -48,7 +48,7 @@ public:
// Column *addColumn(const QString &name = QString());
// void swapColumns(int index1, int index2);
- enum { Type = DatabaseModelItem::Table };
+ enum { Type = DiagramItem::Table };
virtual int type() const { return Type; }
signals:
diff --git a/dbmodel.pro b/dbmodel.pro
index be90bbc..db0cf76 100644
--- a/dbmodel.pro
+++ b/dbmodel.pro
@@ -9,9 +9,11 @@ SOURCES = \
mainwindow.cpp \
databasemodelview.cpp \
databasemodel.cpp \
- databasemodelitem.cpp \
databasetable.cpp \
- databaserelation.cpp \
+ databaserelationship.cpp \
+ diagramconnection.cpp \
+ diagramitem.cpp \
+ diagramobject.cpp \
tableproperties.cpp \
commands.cpp
HEADERS = \
@@ -22,9 +24,11 @@ HEADERS = \
mainwindow.h \
databasemodelview.h \
databasemodel.h \
- databasemodelitem.h \
databasetable.h \
- databaserelation.h \
+ databaserelationship.h \
+ diagramconnection.h \
+ diagramitem.h \
+ diagramobject.h \
tableproperties.h \
commands.h
RESOURCES = dbmodel.qrc
diff --git a/databasemodelitem.cpp b/diagramitem.cpp
index ef3e29b..ddb6269 100644
--- a/databasemodelitem.cpp
+++ b/diagramitem.cpp
@@ -14,9 +14,9 @@
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#include "databasemodelitem.h"
+#include "diagramitem.h"
-DatabaseModelItem::DatabaseModelItem(QGraphicsItem *parent)
+DiagramItem::DiagramItem(DiagramItem *parent)
: QGraphicsItem(parent)
{
}
diff --git a/databasemodelitem.h b/diagramitem.h
index 07d399e..f66a48c 100644
--- a/databasemodelitem.h
+++ b/diagramitem.h
@@ -19,14 +19,15 @@
#include <QGraphicsItem>
-class DatabaseModelItem : public QGraphicsItem
+class DiagramItem : public QObject, public QGraphicsItem
{
public:
enum {
Table = UserType + 1,
Relation
};
- DatabaseModelItem(QGraphicsItem *parent = 0);
+
+ DiagramItem(DiagramItem *parent = 0);
};
#endif
diff --git a/diagramobject.cpp b/diagramobject.cpp
new file mode 100644
index 0000000..8b0d5b3
--- /dev/null
+++ b/diagramobject.cpp
@@ -0,0 +1,22 @@
+// Copyright (C) 2008 Lukas Lalinsky
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+#include "diagramobject.h"
+
+DiagramObject::DiagramObject(DiagramItem *parent)
+ : DiagramItem(parent)
+{
+}
diff --git a/diagramobject.h b/diagramobject.h
new file mode 100644
index 0000000..1ca086e
--- /dev/null
+++ b/diagramobject.h
@@ -0,0 +1,28 @@
+// Copyright (C) 2008 Lukas Lalinsky
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+#ifndef DIAGRAMOBJECT_H
+#define DIAGRAMOBJECT_H
+
+#include "diagramitem.h"
+
+class DiagramObject : public DiagramItem
+{
+public:
+ DiagramObject(DiagramItem *parent = 0);
+};
+
+#endif