From 94d6d634c08870614cc1ce22e0f635aa8f3ab881 Mon Sep 17 00:00:00 2001 From: Lukáš Lalinský Date: Fri, 12 Dec 2008 16:01:05 +0100 Subject: Make diagram notation configurable --- src/diagramdocument.cpp | 27 ++- src/diagramdocument.h | 13 + src/items/database/databaserelationship.cpp | 22 +- src/items/database/databaserelationship.h | 2 +- src/mainwindow.cpp | 36 ++- src/mainwindow.h | 1 + src/src.pri | 1 + translations/dbmodel_en.ts | 362 ++++++++++++++++++++++++++++ translations/dbmodel_sk.ts | 196 ++++++++------- 9 files changed, 563 insertions(+), 97 deletions(-) create mode 100644 translations/dbmodel_en.ts 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()) + 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 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() "

\n" "Database Modeller
\n" "http://oxygene.sk/lukas/dbmodel/
\n" - "Copyright (C) 2008 Lukáš Lalinský\n" + "Copyright (C) 2008 Lukas Lalinsky\n" "

\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 diff --git a/translations/dbmodel_en.ts b/translations/dbmodel_en.ts new file mode 100644 index 0000000..cbcffbd --- /dev/null +++ b/translations/dbmodel_en.ts @@ -0,0 +1,362 @@ + + + + + ColumnListModel + + + Name + + + + + Data Type + + + + + Req'd + + + + + PK + + + + + Notes + + + + + DatabaseRelationshipProperties + + + &Relationship + + + + + Name: + + + + + Generated + + + + + Cardinality: + + + + + DatabaseTableProperties + + + &Table + + + + + &Columns + + + + + Name: + + + + + &Add + + + + + &Remove + + + + + Move &Up + + + + + Move &Down + + + + + MainWindow + + + &Properties + + + + + &New + + + + + Ctrl+N + + + + + &Open... + + + + + Ctrl+O + + + + + &Save + + + + + Ctrl+S + + + + + Save &As... + + + + + Export... + + + + + Select + + + + + Add new table + + + + + Add new relation + + + + + &Undo + + + + + Ctrl+Z + + + + + Re&do + + + + + Ctrl+Shift+Z + + + + + Cu&t + + + + + Ctrl+X + + + + + &Copy + + + + + Ctrl+C + + + + + &Paste + + + + + Ctrl+V + + + + + &Delete + + + + + Del + + + + + &About... + + + + + &Close + + + + + Ctrl+W + + + + + &Quit + + + + + Ctrl+Q + + + + + Show &Grid + + + + + &Notation + + + + + &Relational + + + + + &Crow's Foot + + + + + &File + + + + + &Mode + + + + + 50% + + + + + 70% + + + + + 85% + + + + + 100% + + + + + 125% + + + + + 150% + + + + + &View + + + + + &Edit + + + + + &Diagram + + + + + &Help + + + + + The document has been modified. +Do you want to save your changes? + + + + + Error + + + + + Unknown format. + + + + + &%1. %2 + + + + + About + + + + + <p> +<b>Database Modeller</b><br /> +<a href="http://oxygene.sk/lukas/dbmodel/">http://oxygene.sk/lukas/dbmodel/</a><br /> +Copyright (C) 2008 Lukas Lalinsky +</p> + + <p><b>Database Modeller</b><br /><a href="http://oxygene.sk/lukas/dbmodel/">http://oxygene.sk/lukas/dbmodel/</a><br />Copyright (C) 2008 Lukáš Lalinský</p> + + + + Untitled + + + + diff --git a/translations/dbmodel_sk.ts b/translations/dbmodel_sk.ts index 2617dbd..92e69c6 100644 --- a/translations/dbmodel_sk.ts +++ b/translations/dbmodel_sk.ts @@ -1,30 +1,29 @@ - ColumnListModel - + Name Názov - + Data Type Dátový typ - + Req'd Požadovaný - + PK Primárny kľúč - + Notes Poznámky @@ -32,50 +31,60 @@ DatabaseRelationshipProperties - + &Relationship &Vzťah - + Name: Názov: + + + Generated + + + + + Cardinality: + Kardinalita: + DatabaseTableProperties - + &Table &Tabuľka - + &Columns Stĺ&ce - + Name: Názov: - + Move &Up Posunúť &hore - + Move &Down Posunúť &dole - + &Add Prid&ať - + &Remove Odst&rániť @@ -83,309 +92,330 @@ MainWindow - + &New &Nový - + Ctrl+N - + &Open... &Otvoriť... - + Ctrl+O - + &Save &Uložiť - + Ctrl+S - + Save &As... Uložiť &ako... - + Export... Exportovať... - + Select Výber - + Add new table Pridať novú tabuľku - + Add new relation Pridať nový vzťah - + &Undo Vrátit &späť - + Ctrl+Z - + Re&do &Opakovať vrátené - + Ctrl+Shift+Z - + &File &Súbor - + &Mode &Mód - + 50% - + 70% - + 85% - + 100% - + 125% - + 150% - + &Quit &Koniec - + Ctrl+Q - + &Delete &Odstrániť - + Del - + Error Chyba - + Unknown format. Neznámy formát. - + &Edit &Upraviť - + Cu&t Vystri&hnúť - + Ctrl+X - + &Copy &Kopírovať - + Ctrl+C - + &Paste &Vložiť - + Ctrl+V - + &View &Zobraziť - + The document has been modified. Do you want to save your changes? Dokument bol zmenený. Chcete uložiť Vaše zmeny? - + &%1. %2 - + &About... &O aplikácii... - + &Help &Pomocník - + About O aplikácii - - - <p> -<b>Database Modeller</b><br /> -<a href="http://oxygene.sk/lukas/dbmodel/">http://oxygene.sk/lukas/dbmodel/</a><br /> -Copyright (C) 2008 Lukáš Lalinský -</p> - - - - + &Properties &Vlastnosti - + &Close Za&vrieť - + Ctrl+W - + Show &Grid Zobraziť m&riežku - + Untitled Nepomenované + + + &Notation + &Notácia + + + + &Relational + &Relačná + + + + &Crow's Foot + + + + + &Diagram + + + + + <p> +<b>Database Modeller</b><br /> +<a href="http://oxygene.sk/lukas/dbmodel/">http://oxygene.sk/lukas/dbmodel/</a><br /> +Copyright (C) 2008 Lukas Lalinsky +</p> + + <p><b>Database Modeller</b><br /><a href="http://oxygene.sk/lukas/dbmodel/">http://oxygene.sk/lukas/dbmodel/</a><br />Copyright (C) 2008 Lukáš Lalinský</p> + + TableProperties &Definition - &Definícia + &Definícia Name: - Názov: + Názov: &Columns - Stĺ&ce + Stĺ&ce Add new column - Pridať nový stĺpec + Pridať nový stĺpec &Add - Prid&ať + Prid&ať Remove selected column - Odstrániť vybraný stĺpec + Odstrániť vybraný stĺpec &Remove - Odst&rániť + Odst&rániť Move selected column up - Posunúť vybraný stĺpec hore + Posunúť vybraný stĺpec hore Move &Up - Posunúť &hore + Posunúť &hore Move selected column down - Posunúť vybraný stĺpec dole + Posunúť vybraný stĺpec dole Move &Down - Posunúť &dole + Posunúť &dole -- cgit v1.2.3-54-g00ecf