summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLukáš Lalinský <lalinsky@gmail.com>2008-12-12 16:01:05 +0100
committerLukáš Lalinský <lalinsky@gmail.com>2008-12-12 16:01:05 +0100
commit94d6d634c08870614cc1ce22e0f635aa8f3ab881 (patch)
tree481f6ba9d1d6f99fa20e3fe95ff46212940688e0 /src
parent1772e08823194ee25b3ebf444ef05290b6b33c68 (diff)
downloaddbmodel-94d6d634c08870614cc1ce22e0f635aa8f3ab881.tar.xz
Make diagram notation configurable
Diffstat (limited to 'src')
-rw-r--r--src/diagramdocument.cpp27
-rw-r--r--src/diagramdocument.h13
-rw-r--r--src/items/database/databaserelationship.cpp22
-rw-r--r--src/items/database/databaserelationship.h2
-rw-r--r--src/mainwindow.cpp36
-rw-r--r--src/mainwindow.h1
-rw-r--r--src/src.pri1
7 files changed, 88 insertions, 14 deletions
diff --git a/src/diagramdocument.cpp b/src/diagramdocument.cpp
index 9df8b75..ced24bc 100644
--- a/src/diagramdocument.cpp
+++ b/src/diagramdocument.cpp
@@ -37,12 +37,14 @@ public:
gridSize(10),
gridVisible(true),
gridPen(QColor(185, 185, 185), 0),
- printing(false)
+ printing(false),
+ notation(Relational)
{}
int gridSize;
bool gridVisible;
QPen gridPen;
bool printing;
+ Notation notation;
};
DiagramDocument::DiagramDocument(QObject *parent)
@@ -51,6 +53,24 @@ DiagramDocument::DiagramDocument(QObject *parent)
m_undoStack = new QUndoStack(this);
}
+DiagramDocument::Notation
+DiagramDocument::notation() const
+{
+ return d->notation;
+}
+
+void
+DiagramDocument::setNotation(Notation notation)
+{
+ if (d->notation != notation) {
+ d->notation = notation;
+ // FIXME
+ foreach (DatabaseRelationship *connection, itemsByType<DatabaseRelationship>())
+ connection->updateLayout();
+ update();
+ }
+}
+
int
DiagramDocument::gridSize() const
{
@@ -284,6 +304,8 @@ DiagramDocument::save(const QString &fileName)
root.setAttribute("xmlns", "http://oxygene.sk/ns/diagram/1/");
doc.appendChild(root);
+ appendEnumElement(doc, root, "notation", d->notation, this, "Notation");
+
QDomElement itemList = doc.createElement("item-list");
root.appendChild(itemList);
@@ -322,6 +344,9 @@ DiagramDocument::load(const QString &fileName)
}
setFileName(fileName);
QDomElement root = doc.firstChildElement("diagram");
+
+ d->notation = readEnumElement(root, "notation", Relational, this, "Notation");
+
QDomElement itemListElement = root.firstChildElement("item-list");
QDomElement itemElement = itemListElement.firstChildElement("item");
while (!itemElement.isNull()) {
diff --git a/src/diagramdocument.h b/src/diagramdocument.h
index ffb38ac..47d1294 100644
--- a/src/diagramdocument.h
+++ b/src/diagramdocument.h
@@ -34,9 +34,11 @@ class DiagramObject;
class DiagramDocument : public QGraphicsScene
{
Q_OBJECT
+ Q_ENUMS(Notation)
Q_PROPERTY(int gridSize READ gridSize WRITE setGridSize)
Q_PROPERTY(bool gridVisible READ isGridVisible WRITE setGridVisible)
Q_PROPERTY(QColor gridColor READ gridColor WRITE setGridColor)
+ Q_PROPERTY(Notation notation READ notation WRITE setNotation)
public:
DiagramDocument(QObject *parent = 0);
@@ -47,6 +49,17 @@ public:
AddRelation
};
+ enum Notation {
+ Relational,
+ CrowsFoot
+ };
+
+ //! Returns the notation used in the diagram
+ Notation notation() const;
+
+ //! Sets the notation used in the diagram
+ void setNotation(Notation);
+
Mode mode();
void setMode(Mode mode);
diff --git a/src/items/database/databaserelationship.cpp b/src/items/database/databaserelationship.cpp
index d908409..6efe07b 100644
--- a/src/items/database/databaserelationship.cpp
+++ b/src/items/database/databaserelationship.cpp
@@ -329,17 +329,17 @@ DatabaseRelationship::updateLayout()
Q_ASSERT(haveLine);
- // "Relational"
- if (1) {
- d->fillEnds = true;
- d->targetEnd = d->arrowHeadPath();
- d->sourceEnd = QPainterPath();
- }
- // "Crow's Foot"
- else {
- d->fillEnds = false;
- d->targetEnd = d->crowsFootPath(d->cardinality);
- d->sourceEnd = d->crowsFootPath(isRequired() ? One : ZeroOrOne);
+ switch (document()->notation()) {
+ case DiagramDocument::Relational:
+ d->fillEnds = true;
+ d->targetEnd = d->arrowHeadPath();
+ d->sourceEnd = QPainterPath();
+ break;
+ case DiagramDocument::CrowsFoot:
+ d->fillEnds = false;
+ d->targetEnd = d->crowsFootPath(d->cardinality);
+ d->sourceEnd = d->crowsFootPath(isRequired() ? One : ZeroOrOne);
+ break;
}
if (!d->sourceEnd.isEmpty()) {
diff --git a/src/items/database/databaserelationship.h b/src/items/database/databaserelationship.h
index d8762cf..9b5f0af 100644
--- a/src/items/database/databaserelationship.h
+++ b/src/items/database/databaserelationship.h
@@ -90,7 +90,7 @@ public:
static DiagramItemProperties *createPropertiesEditor(QWidget *parent = 0);
-protected slots:
+public slots:
void updateLayout();
protected:
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 80cae48..5edff05 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -51,6 +51,9 @@ public:
QDockWidget *itemPropsDock;
QStackedWidget *propertyEditorsStack;
QMap<QString, int> propertyEditorsIndexes;
+
+ QActionGroup *notationActionGroup;
+ QMenu *notationMenu;
};
MainWindow::MainWindow()
@@ -277,6 +280,19 @@ MainWindow::setupActions()
m_actionShowGrid->setText(tr("Show &Grid"));
m_actionShowGrid->setCheckable(true);
connect(m_actionShowGrid, SIGNAL(triggered(bool)), SLOT(showGrid(bool)));
+
+ d->notationMenu = new QMenu(tr("&Notation"), this);
+ d->notationActionGroup = new QActionGroup(this);
+ QAction *action;
+ action = d->notationActionGroup->addAction(tr("&Relational"));
+ action->setCheckable(true);
+ action->setData(DiagramDocument::Relational);
+ d->notationMenu->addAction(action);
+ action = d->notationActionGroup->addAction(tr("&Crow's Foot"));
+ action->setCheckable(true);
+ action->setData(DiagramDocument::CrowsFoot);
+ d->notationMenu->addAction(action);
+ connect(d->notationActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(setDiagramNotation(QAction*)));
}
void
@@ -370,6 +386,10 @@ MainWindow::setupMenuBar()
viewMenu->addSeparator();
viewMenu->addAction(m_actionShowGrid);
+ QMenu *diagramMenu = menuBar()->addMenu(tr("&Diagram"));
+ diagramMenu->addMenu(d->notationMenu);
+ diagramMenu->addSeparator();
+
menu = menuBar()->addMenu(tr("&Help"));
menu->addAction(m_actionAbout);
}
@@ -510,6 +530,13 @@ MainWindow::newModel(DiagramDocument *newModel)
m_actionShowGrid->setChecked(m_model->isGridVisible());
+ foreach (QAction *action, d->notationActionGroup->actions()) {
+ if (action->data() == m_model->notation()) {
+ action->setChecked(true);
+ break;
+ }
+ }
+
QUndoStack *undoStack = m_model->undoStack();
connect(undoStack, SIGNAL(cleanChanged(bool)), this, SLOT(updateWindowTitle()));
connect(undoStack, SIGNAL(canUndoChanged(bool)), m_actionUndo, SLOT(setEnabled(bool)));
@@ -698,7 +725,7 @@ MainWindow::about()
"<p>\n"
"<b>Database Modeller</b><br />\n"
"<a href=\"http://oxygene.sk/lukas/dbmodel/\">http://oxygene.sk/lukas/dbmodel/</a><br />\n"
- "Copyright (C) 2008 Lukáš Lalinský\n"
+ "Copyright (C) 2008 Lukas Lalinsky\n"
"</p>\n"
));
}
@@ -720,3 +747,10 @@ MainWindow::updateWindowTitle()
setWindowTitle(qApp->applicationName());
}
}
+
+void
+MainWindow::setDiagramNotation(QAction *action)
+{
+ m_model->undoStack()->push(
+ new SetObjectPropertyCommand(m_model, "notation", action->data()));
+}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index eab0868..9cac7ce 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -41,6 +41,7 @@ public slots:
void switchModeSelect();
void switchModeAddTable();
void switchModeAddRelation();
+ void setDiagramNotation(QAction *action);
void updateSelection();
void deleteSelectedItems();
diff --git a/src/src.pri b/src/src.pri
index 592b49c..889f073 100644
--- a/src/src.pri
+++ b/src/src.pri
@@ -27,4 +27,5 @@ HEADERS = \
commands.h
TRANSLATIONS = \
+ ../translations/dbmodel_en.ts \
../translations/dbmodel_sk.ts