summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukáš Lalinský <lalinsky@gmail.com>2008-12-07 17:52:36 +0100
committerLukáš Lalinský <lalinsky@gmail.com>2008-12-07 17:52:36 +0100
commit0092b62413fa6a5727530f0eb5c5044a322870d3 (patch)
tree78939cf9c2c03988ae05408f238bf5658a4002c7
parent6b42618de7c3be2681ad4e49eb412e56b700d59e (diff)
downloaddbmodel-0092b62413fa6a5727530f0eb5c5044a322870d3.tar.gz
dbmodel-0092b62413fa6a5727530f0eb5c5044a322870d3.tar.bz2
Refactored XML processing, improved copy&paste, new file format
-rw-r--r--src/databaserelationship.cpp14
-rw-r--r--src/databaserelationship.h6
-rw-r--r--src/databasetable.cpp47
-rw-r--r--src/databasetable.h8
-rw-r--r--src/diagramconnection.cpp31
-rw-r--r--src/diagramconnection.h3
-rw-r--r--src/diagramdocument.cpp148
-rw-r--r--src/diagramdocument.h3
-rw-r--r--src/diagramitem.cpp89
-rw-r--r--src/diagramitem.h25
-rw-r--r--src/diagramitemregistry.cpp46
-rw-r--r--src/diagramitemregistry.h36
-rw-r--r--src/diagramobject.cpp19
-rw-r--r--src/diagramobject.h6
-rw-r--r--src/domutils.h43
-rw-r--r--src/mainwindow.cpp16
-rw-r--r--src/src.pro2
17 files changed, 397 insertions, 145 deletions
diff --git a/src/databaserelationship.cpp b/src/databaserelationship.cpp
index 2858f60..02540c5 100644
--- a/src/databaserelationship.cpp
+++ b/src/databaserelationship.cpp
@@ -228,3 +228,17 @@ DatabaseRelationship::updateLayout()
m_arrowHead = matrix.map(m_arrowHead);
m_arrowHead.translate(lastSegment.p2());
}
+
+#include "domutils.h"
+
+void
+DatabaseRelationship::loadFromXml(QDomElement element, DiagramDocument *document)
+{
+ DiagramConnection::loadFromXml(element, document);
+}
+
+void
+DatabaseRelationship::saveToXml(QDomDocument doc, QDomElement element)
+{
+ DiagramConnection::saveToXml(doc, element);
+}
diff --git a/src/databaserelationship.h b/src/databaserelationship.h
index f0edd68..e9e26d0 100644
--- a/src/databaserelationship.h
+++ b/src/databaserelationship.h
@@ -39,6 +39,12 @@ public:
enum { Type = DiagramItem::Relation };
virtual int type() const { return Type; }
+ static const char *staticTypeName() { return "database-relationship"; }
+ virtual const char *typeName() { return staticTypeName(); }
+
+ void loadFromXml(QDomElement element, DiagramDocument *document = 0);
+ void saveToXml(QDomDocument doc, QDomElement element);
+
void updatePositions();
protected slots:
diff --git a/src/databasetable.cpp b/src/databasetable.cpp
index cfbeb5d..911457f 100644
--- a/src/databasetable.cpp
+++ b/src/databasetable.cpp
@@ -183,11 +183,46 @@ DatabaseTable::updateLayout()
update();
}
-QMimeData *
-DatabaseTable::toMimeData()
+#include "domutils.h"
+
+void
+DatabaseTable::loadFromXml(QDomElement element, DiagramDocument *document)
{
- QMimeData *mimeData = new QMimeData();
- QByteArray data = name().toUtf8();
- mimeData->setData("application/dbmodel.object", data);
- return mimeData;
+ DiagramItem::loadFromXml(element, document);
+ QDomElement tableElement = element.firstChildElement("table");
+ if (!tableElement.isNull()) {
+ setName(readStringElement(tableElement, "name"));
+ QDomElement columnListElement = tableElement.firstChildElement("column-list");
+ QDomElement columnElement = columnListElement.firstChildElement("column");
+ while (!columnElement.isNull()) {
+ Column *column = new Column();
+ column->setName(readStringElement(columnElement, "name"));
+ column->setDataType(readStringElement(columnElement, "data-type"));
+ column->setRequired(readStringElement(columnElement, "required") == "yes");
+ column->setPrimaryKey(readStringElement(columnElement, "primary-key") == "yes");
+ column->setNotes(readStringElement(columnElement, "notes"));
+ columnList()->appendColumn(column);
+ columnElement = columnElement.nextSiblingElement("column");
+ }
+ }
+}
+
+void
+DatabaseTable::saveToXml(QDomDocument doc, QDomElement element)
+{
+ DiagramItem::saveToXml(doc, element);
+ QDomElement tableElement = doc.createElement("table");
+ element.appendChild(tableElement);
+ appendStringElement(doc, tableElement, "name", name());
+ QDomElement columnListElement = doc.createElement("column-list");
+ tableElement.appendChild(columnListElement);
+ foreach (Column *column, columnList()->columns()) {
+ QDomElement columnElement = doc.createElement("column");
+ columnListElement.appendChild(columnElement);
+ appendStringElement(doc, columnElement, "name", column->name());
+ appendStringElement(doc, columnElement, "data-type", column->dataType());
+ appendStringElement(doc, columnElement, "required", column->isRequired() ? "yes" : QString());
+ appendStringElement(doc, columnElement, "primary-key", column->isPrimaryKey() ? "yes" : QString());
+ appendStringElement(doc, columnElement, "notes", column->notes());
+ }
}
diff --git a/src/databasetable.h b/src/databasetable.h
index 9268b0d..8be1ee5 100644
--- a/src/databasetable.h
+++ b/src/databasetable.h
@@ -51,7 +51,13 @@ public:
enum { Type = DiagramItem::Table };
virtual int type() const { return Type; }
- QMimeData *toMimeData();
+ static const char *staticTypeName() { return "database-table"; }
+ virtual const char *typeName() { return staticTypeName(); }
+
+ void loadFromXml(QDomElement element, DiagramDocument *document = 0);
+ void saveToXml(QDomDocument doc, QDomElement element);
+
+// QMimeData *toMimeData();
signals:
void propertyChanged(const QString &name, const QVariant &value);
diff --git a/src/diagramconnection.cpp b/src/diagramconnection.cpp
index 1b1865a..545f9bf 100644
--- a/src/diagramconnection.cpp
+++ b/src/diagramconnection.cpp
@@ -15,6 +15,8 @@
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include "diagramconnection.h"
+#include "diagramdocument.h"
+#include "diagramobject.h"
DiagramConnection::DiagramConnection(DiagramItem *parent)
: DiagramItem(parent)
@@ -42,3 +44,32 @@ void
DiagramConnection::updatePositions()
{
}
+
+#include "domutils.h"
+
+void
+DiagramConnection::loadFromXml(QDomElement element, DiagramDocument *document)
+{
+ DiagramItem::loadFromXml(element, document);
+ QDomElement connectionElement = element.firstChildElement("connection");
+ if (!connectionElement.isNull()) {
+ QString sourceId = readStringElement(connectionElement, "source");
+ QString targetId = readStringElement(connectionElement, "target");
+ if (document) {
+ setSource(qobject_cast<DiagramObject *>(document->itemById(sourceId)));
+ setTarget(qobject_cast<DiagramObject *>(document->itemById(targetId)));
+ }
+ }
+}
+
+void
+DiagramConnection::saveToXml(QDomDocument doc, QDomElement element)
+{
+ DiagramItem::saveToXml(doc, element);
+ QDomElement connectionElement = doc.createElement("connection");
+ element.appendChild(connectionElement);
+ if (m_objects[0] != NULL)
+ appendStringElement(doc, connectionElement, "source", m_objects[0]->id());
+ if (m_objects[1] != NULL)
+ appendStringElement(doc, connectionElement, "target", m_objects[1]->id());
+}
diff --git a/src/diagramconnection.h b/src/diagramconnection.h
index 1ad52e5..9ea97d5 100644
--- a/src/diagramconnection.h
+++ b/src/diagramconnection.h
@@ -35,6 +35,9 @@ public:
virtual void updatePositions();
+ virtual void loadFromXml(QDomElement element, DiagramDocument *document = 0);
+ void saveToXml(QDomDocument doc, QDomElement element);
+
signals:
void endPointChanged();
diff --git a/src/diagramdocument.cpp b/src/diagramdocument.cpp
index b8ad744..d1ae22e 100644
--- a/src/diagramdocument.cpp
+++ b/src/diagramdocument.cpp
@@ -91,6 +91,7 @@ DiagramDocument::mousePressEvent(QGraphicsSceneMouseEvent *event)
m_trackingMoves = true;
if (m_mode == AddTable && event->button() == Qt::LeftButton) {
DatabaseTable *table = new DatabaseTable();
+ table->createId();
table->setPos(event->scenePos());
undoStack()->push(new AddItemCommand(this, table));
clearSelection();
@@ -135,6 +136,7 @@ DiagramDocument::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
DatabaseTable *target = qgraphicsitem_cast<DatabaseTable *>(itemAt(m_line->line().p2()));
if (source && target && source != target) {
DatabaseRelationship *relation = new DatabaseRelationship();
+ relation->createId();
relation->setSource(source);
relation->setTarget(target);
undoStack()->push(new AddItemCommand(this, relation));
@@ -185,73 +187,33 @@ DiagramDocument::findConnections(DiagramObject *object)
return result;
}
-void
-appendStringElement(QDomDocument &doc, QDomElement &parent, const QString &name, const QString &value)
-{
- if (!value.isEmpty()) {
- QDomElement element = doc.createElement(name);
- element.appendChild(doc.createTextNode(value));
- parent.appendChild(element);
- }
-}
-
-QString
-readStringElement(QDomElement &parent, const QString &name, const QString &defaultValue = QString())
-{
- QDomElement element = parent.firstChildElement(name);
- if (!element.isNull()) {
- return element.text();
- }
- return defaultValue;
-}
+#include "domutils.h"
void
DiagramDocument::save(const QString &fileName)
{
QDomDocument doc;
- QDomElement root = doc.createElement("database-model");
- doc.appendChild(root);
-
- QDomElement tableListElement = doc.createElement("table-list");
- root.appendChild(tableListElement);
-
- QList<DatabaseTable *> tables = itemsByType<DatabaseTable>();
- foreach (DatabaseTable *table, tables) {
- QDomElement tableElement = doc.createElement("table");
- tableListElement.appendChild(tableElement);
-
- QDomElement positionElement = doc.createElement("position");
- positionElement.setAttribute("x", table->pos().x());
- positionElement.setAttribute("y", table->pos().y());
- tableElement.appendChild(positionElement);
+ QDomProcessingInstruction xml = doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");
+ doc.appendChild(xml);
- QDomElement nameElement = doc.createElement("name");
- nameElement.appendChild(doc.createTextNode(table->name()));
- tableElement.appendChild(nameElement);
+ QDomElement root = doc.createElement("diagram");
+ root.setAttribute("xmlns", "http://oxygene.sk/ns/diagram/1/");
+ doc.appendChild(root);
- QDomElement columnListElement = doc.createElement("column-list");
- tableElement.appendChild(columnListElement);
+ QDomElement itemList = doc.createElement("item-list");
+ root.appendChild(itemList);
- foreach (Column *column, table->columnList()->columns()) {
- QDomElement columnElement = doc.createElement("column");
- columnListElement.appendChild(columnElement);
- appendStringElement(doc, columnElement, "name", column->name());
- appendStringElement(doc, columnElement, "data-type", column->dataType());
- appendStringElement(doc, columnElement, "required", column->isRequired() ? "yes" : QString());
- appendStringElement(doc, columnElement, "primary-key", column->isPrimaryKey() ? "yes" : QString());
- appendStringElement(doc, columnElement, "notes", column->notes());
- }
+ foreach (DiagramObject *item, itemsByType<DiagramObject>()) {
+ QDomElement element = doc.createElement("item");
+ itemList.appendChild(element);
+ item->saveToXml(doc, element);
}
-
- QDomElement relationListElement = doc.createElement("relation-list");
- root.appendChild(relationListElement);
- foreach (DatabaseRelationship *relation, itemsByType<DatabaseRelationship>()) {
- QDomElement relationElement = doc.createElement("relation");
- relationElement.setAttribute("from", QString::number(tables.indexOf(relation->sourceTable())));
- relationElement.setAttribute("to", QString::number(tables.indexOf(relation->targetTable())));
- relationListElement.appendChild(relationElement);
+ foreach (DiagramConnection *item, itemsByType<DiagramConnection>()) {
+ QDomElement element = doc.createElement("item");
+ itemList.appendChild(element);
+ item->saveToXml(doc, element);
}
QFile file(fileName);
@@ -264,6 +226,8 @@ DiagramDocument::save(const QString &fileName)
setFileName(fileName);
}
+#include "diagramitemregistry.h"
+
void
DiagramDocument::load(const QString &fileName)
{
@@ -273,61 +237,29 @@ DiagramDocument::load(const QString &fileName)
doc.setContent(&file);
file.close();
}
-
setFileName(fileName);
-
- QDomElement root = doc.firstChildElement("database-model");
-
- QList<DatabaseTable *> tables;
-
- QDomElement tableListElement = root.firstChildElement("table-list");
- QDomElement tableElement = tableListElement.firstChildElement("table");
- while (!tableElement.isNull()) {
- DatabaseTable *table = new DatabaseTable;
-
- QDomElement positionElement = tableElement.firstChildElement("position");
- if (!positionElement.isNull()) {
- QPoint pos;
- pos.setX(positionElement.attribute("x", "0").toInt());
- pos.setY(positionElement.attribute("y", "0").toInt());
- table->setPos(pos);
+ QDomElement root = doc.firstChildElement("diagram");
+ QDomElement itemListElement = root.firstChildElement("item-list");
+ QDomElement itemElement = itemListElement.firstChildElement("item");
+ while (!itemElement.isNull()) {
+ QString itemTypeName = itemElement.attribute("type");
+ DiagramItem *item = DiagramItemRegistry::createItem(itemTypeName);
+ if (item == NULL) {
+ qWarning() << "Unknown item type:" << itemTypeName;
}
-
- table->setName(readStringElement(tableElement, "name"));
-
- QDomElement columnListElement = tableElement.firstChildElement("column-list");
- QDomElement columnElement = columnListElement.firstChildElement("column");
- while (!columnElement.isNull()) {
- Column *column = new Column();
- column->setName(readStringElement(columnElement, "name"));
- column->setDataType(readStringElement(columnElement, "data-type"));
- column->setRequired(readStringElement(columnElement, "required") == "yes");
- column->setPrimaryKey(readStringElement(columnElement, "primary-key") == "yes");
- column->setNotes(readStringElement(columnElement, "notes"));
- table->columnList()->appendColumn(column);
- columnElement = columnElement.nextSiblingElement("column");
+ else {
+ item->loadFromXml(itemElement, this);
+ addItem(item);
}
-
- addItem(table);
- tables.append(table);
-
- tableElement = tableElement.nextSiblingElement("table");
+ itemElement = itemElement.nextSiblingElement("item");
}
+}
- QDomElement relationListElement = root.firstChildElement("relation-list");
- QDomElement relationElement = relationListElement.firstChildElement("relation");
- while (!relationElement.isNull()) {
- relationElement = relationElement.nextSiblingElement("relation");
- bool ok;
- int index0 = relationElement.attribute("from").toInt(&ok);
- if (ok) {
- int index1 = relationElement.attribute("to").toInt(&ok);
- if (ok) {
- DatabaseRelationship *relation = new DatabaseRelationship();
- relation->setSource(tables[index0]);
- relation->setTarget(tables[index1]);
- addItem(relation);
- }
- }
- }
+DiagramItem *
+DiagramDocument::itemById(const QUuid &id)
+{
+ foreach (DiagramItem *item, itemsByType<DiagramItem>())
+ if (item->id() == id)
+ return item;
+ return 0;
}
diff --git a/src/diagramdocument.h b/src/diagramdocument.h
index 79d38d9..747508b 100644
--- a/src/diagramdocument.h
+++ b/src/diagramdocument.h
@@ -23,6 +23,7 @@
#include <QDomDocument>
#include <QGraphicsLineItem>
#include <QSet>
+#include <QUuid>
class DatabaseTable;
class DatabaseRelationship;
@@ -55,6 +56,8 @@ public:
QString fileName() { return m_fileName; }
void setFileName(const QString &fileName) { m_fileName = fileName; }
+ DiagramItem *itemById(const QUuid &id);
+
QUndoStack *undoStack() const { return m_undoStack; }
void itemMoved(DiagramItem *table);
diff --git a/src/diagramitem.cpp b/src/diagramitem.cpp
index ddb6269..bcb5e24 100644
--- a/src/diagramitem.cpp
+++ b/src/diagramitem.cpp
@@ -14,9 +14,98 @@
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#include <QMimeData>
+#include <QDomProcessingInstruction>
+#include <QDebug>
+#include "diagramdocument.h"
#include "diagramitem.h"
+#include "diagramitemregistry.h"
DiagramItem::DiagramItem(DiagramItem *parent)
: QGraphicsItem(parent)
{
}
+
+void
+DiagramItem::setId(QUuid id)
+{
+ m_id = id;
+}
+
+void
+DiagramItem::createId()
+{
+ m_id = QUuid::createUuid();
+}
+
+DiagramDocument *
+DiagramItem::document() const
+{
+ return qobject_cast<DiagramDocument *>(scene());
+}
+
+void
+DiagramItem::loadFromXml(QDomElement element, DiagramDocument *)
+{
+ setId(element.attribute("id", QUuid()));
+ QDomElement positionElement = element.firstChildElement("position");
+ if (!positionElement.isNull()) {
+ QPoint pos;
+ pos.setX(positionElement.attribute("x", "0").toInt());
+ pos.setY(positionElement.attribute("y", "0").toInt());
+ setPos(pos);
+ }
+}
+
+void
+DiagramItem::saveToXml(QDomDocument doc, QDomElement element)
+{
+ element.setAttribute("type", typeName());
+ element.setAttribute("id", id());
+ QDomElement positionElement = doc.createElement("position");
+ positionElement.setAttribute("x", pos().x());
+ positionElement.setAttribute("y", pos().y());
+ element.appendChild(positionElement);
+}
+
+QMimeData *
+DiagramItem::toMimeData()
+{
+ QDomDocument doc;
+ QDomProcessingInstruction xml = doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");
+ doc.appendChild(xml);
+ QDomElement element = doc.createElement("item");
+ doc.appendChild(element);
+ saveToXml(doc, element);
+
+ QByteArray data;
+ QTextStream stream(&data);
+ doc.save(stream, 0);
+
+ QMimeData *mimeData = new QMimeData();
+ mimeData->setData("application/dbmodel.item", data);
+ return mimeData;
+}
+
+DiagramItem *
+DiagramItem::fromMimeData(const QMimeData *mimeData)
+{
+ QByteArray data = mimeData->data("application/dbmodel.item");
+ if (data.isNull())
+ return 0;
+
+ QDomDocument doc;
+ doc.setContent(data);
+
+ QDomElement element = doc.firstChildElement("item");
+ if (element.isNull())
+ return 0;
+
+ DiagramItem *item = DiagramItemRegistry::createItem(element.attribute("type"));
+ if (item == NULL)
+ return 0;
+
+ item->loadFromXml(element);
+ item->createId();
+ return item;
+}
diff --git a/src/diagramitem.h b/src/diagramitem.h
index f66a48c..3444f8d 100644
--- a/src/diagramitem.h
+++ b/src/diagramitem.h
@@ -18,16 +18,41 @@
#define DATABASEMODELITEM_H
#include <QGraphicsItem>
+#include <QDomDocument>
+#include <QDomElement>
+#include <QUuid>
+class QMimeData;
+class DiagramDocument;
class DiagramItem : public QObject, public QGraphicsItem
{
+ Q_OBJECT
+
public:
enum {
Table = UserType + 1,
Relation
};
+ DiagramDocument *document() const;
+
+ QUuid id() const { return m_id; }
+ void setId(QUuid id);
+ void createId();
+
DiagramItem(DiagramItem *parent = 0);
+
+ static const char *staticTypeName() { return ""; }
+ virtual const char *typeName() = 0;
+
+ virtual void loadFromXml(QDomElement element, DiagramDocument *document = 0);
+ virtual void saveToXml(QDomDocument doc, QDomElement element);
+
+ virtual QMimeData *toMimeData();
+ static DiagramItem *fromMimeData(const QMimeData *mimeData);
+
+public:
+ QUuid m_id;
};
#endif
diff --git a/src/diagramitemregistry.cpp b/src/diagramitemregistry.cpp
new file mode 100644
index 0000000..ebc4f10
--- /dev/null
+++ b/src/diagramitemregistry.cpp
@@ -0,0 +1,46 @@
+// 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 <QDebug>
+#include "diagramitem.h"
+#include "diagramitemregistry.h"
+
+DiagramItemRegistry *DiagramItemRegistry::m_registry = 0;
+
+template <class T> DiagramItem *__createItem() { return new T(); }
+#define ADD_TYPE(x) m_map[x::staticTypeName()] = &(__createItem<x>);
+
+DiagramItem *
+DiagramItemRegistry::createItem(const QString &typeName)
+{
+ if (!DiagramItemRegistry::m_registry)
+ DiagramItemRegistry::m_registry = new DiagramItemRegistry();
+ if (!DiagramItemRegistry::m_registry->m_map.contains(typeName))
+ return 0;
+ return DiagramItemRegistry::m_registry->m_map[typeName]();
+}
+
+// =========================================================================
+// =========================================================================
+
+#include "databasetable.h"
+#include "databaserelationship.h"
+
+DiagramItemRegistry::DiagramItemRegistry()
+{
+ ADD_TYPE(DatabaseTable);
+ ADD_TYPE(DatabaseRelationship);
+}
diff --git a/src/diagramitemregistry.h b/src/diagramitemregistry.h
new file mode 100644
index 0000000..7806574
--- /dev/null
+++ b/src/diagramitemregistry.h
@@ -0,0 +1,36 @@
+// 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 DIAGRAMITEMREGISTRY_H
+#define DIAGRAMITEMREGISTRY_H
+
+#include <QString>
+class DiagramItem;
+
+typedef DiagramItem *(*createItemFunc)();
+
+class DiagramItemRegistry
+{
+public:
+ static DiagramItem *createItem(const QString &typeName);
+
+private:
+ DiagramItemRegistry();
+ static DiagramItemRegistry *m_registry;
+ QMap<QString, createItemFunc> m_map;
+};
+
+#endif
diff --git a/src/diagramobject.cpp b/src/diagramobject.cpp
index 1bc6300..e0d6c17 100644
--- a/src/diagramobject.cpp
+++ b/src/diagramobject.cpp
@@ -14,29 +14,10 @@
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#include <QMimeData>
#include "diagramobject.h"
-#include "databasetable.h"
DiagramObject::DiagramObject(DiagramItem *parent)
: DiagramItem(parent)
{
setZValue(100.0);
}
-
-QMimeData *
-DiagramObject::toMimeData()
-{
- return 0;
-}
-
-DiagramObject *
-DiagramObject::fromMimeData(const QMimeData *mimeData)
-{
- QByteArray data = mimeData->data("application/dbmodel.object");
- if (data.isNull())
- return 0;
- DatabaseTable *table = new DatabaseTable();
- table->setName(data);
- return table;
-}
diff --git a/src/diagramobject.h b/src/diagramobject.h
index c7b4dd3..6650968 100644
--- a/src/diagramobject.h
+++ b/src/diagramobject.h
@@ -18,15 +18,13 @@
#define DIAGRAMOBJECT_H
#include "diagramitem.h"
-class QMimeData;
class DiagramObject : public DiagramItem
{
+ Q_OBJECT
+
public:
DiagramObject(DiagramItem *parent = 0);
-
- virtual QMimeData *toMimeData();
- static DiagramObject *fromMimeData(const QMimeData *mimeData);
};
#endif
diff --git a/src/domutils.h b/src/domutils.h
new file mode 100644
index 0000000..045f0bb
--- /dev/null
+++ b/src/domutils.h
@@ -0,0 +1,43 @@
+// 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 DOMUTILS_H
+#define DOMUTILS_H
+
+#include <QDomDocument>
+#include <QDomElement>
+
+inline void
+appendStringElement(QDomDocument &doc, QDomElement &parent, const QString &name, const QString &value)
+{
+ if (!value.isEmpty()) {
+ QDomElement element = doc.createElement(name);
+ element.appendChild(doc.createTextNode(value));
+ parent.appendChild(element);
+ }
+}
+
+inline QString
+readStringElement(QDomElement &parent, const QString &name, const QString &defaultValue = QString())
+{
+ QDomElement element = parent.firstChildElement(name);
+ if (!element.isNull()) {
+ return element.text();
+ }
+ return defaultValue;
+}
+
+#endif
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 8cd8cab..81d23e9 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -157,17 +157,17 @@ MainWindow::setupActions()
m_actionSave->setText(tr("&Save"));
m_actionSave->setIcon(QIcon(":/icons/16x16/document-save.png"));
m_actionSave->setShortcut(QKeySequence(tr("Ctrl+S")));
- m_actionSave->setDisabled(true);
+ //m_actionSave->setDisabled(true);
connect(m_actionSave, SIGNAL(triggered(bool)), SLOT(save()));
m_actionSaveAs = new QAction(this);
m_actionSaveAs->setText(tr("Save &As..."));
m_actionSaveAs->setIcon(QIcon(":/icons/16x16/document-save-as.png"));
- m_actionSaveAs->setDisabled(true);
+ //m_actionSaveAs->setDisabled(true);
connect(m_actionSaveAs, SIGNAL(triggered(bool)), SLOT(saveAs()));
- connect(m_undoGroup, SIGNAL(cleanChanged(bool)), m_actionSave, SLOT(setDisabled(bool)));
- connect(m_undoGroup, SIGNAL(cleanChanged(bool)), m_actionSaveAs, SLOT(setDisabled(bool)));
+ //connect(m_undoGroup, SIGNAL(cleanChanged(bool)), m_actionSave, SLOT(setDisabled(bool)));
+ //connect(m_undoGroup, SIGNAL(cleanChanged(bool)), m_actionSaveAs, SLOT(setDisabled(bool)));
m_actionExportPNG = new QAction(this);
m_actionExportPNG->setText(tr("Export..."));
@@ -547,8 +547,10 @@ MainWindow::paste()
{
const QMimeData *mimeData = QApplication::clipboard()->mimeData(QClipboard::Clipboard);
if (mimeData) {
- DiagramObject *object = DiagramObject::fromMimeData(mimeData);
- m_model->undoStack()->push(new AddItemCommand(m_model, object));
+ DiagramItem *item = DiagramItem::fromMimeData(mimeData);
+ if (item) {
+ m_model->undoStack()->push(new AddItemCommand(m_model, item));
+ }
}
}
@@ -558,7 +560,7 @@ MainWindow::updateClipboard(QClipboard::Mode mode)
if (mode != QClipboard::Clipboard)
return;
const QMimeData *mimeData = QApplication::clipboard()->mimeData(QClipboard::Clipboard);
- if (mimeData && mimeData->formats().contains("application/dbmodel.object"))
+ if (mimeData && mimeData->formats().contains("application/dbmodel.item"))
m_actionPaste->setEnabled(true);
else
m_actionPaste->setEnabled(false);
diff --git a/src/src.pro b/src/src.pro
index 6a6fa5a..bb398dd 100644
--- a/src/src.pro
+++ b/src/src.pro
@@ -15,6 +15,7 @@ SOURCES = \
databaserelationship.cpp \
diagramconnection.cpp \
diagramitem.cpp \
+ diagramitemregistry.cpp \
diagramobject.cpp \
tableproperties.cpp \
commands.cpp
@@ -30,6 +31,7 @@ HEADERS = \
databaserelationship.h \
diagramconnection.h \
diagramitem.h \
+ diagramitemregistry.h \
diagramobject.h \
tableproperties.h \
range.h \