diff options
author | Lukáš Lalinský <lalinsky@gmail.com> | 2009-01-01 08:57:48 +0100 |
---|---|---|
committer | Lukáš Lalinský <lalinsky@gmail.com> | 2009-01-01 08:57:48 +0100 |
commit | a02fbb306009ab27ab91867d0736e133d4d42b45 (patch) | |
tree | 260dc67e6d999e3561668e104b69fab35aa7a6fe /src/diagramdocument.cpp | |
parent | e40be8a9658095b5d7e87afdf4a95762885e7aab (diff) | |
download | dbmodel-a02fbb306009ab27ab91867d0736e133d4d42b45.tar.gz dbmodel-a02fbb306009ab27ab91867d0736e133d4d42b45.tar.bz2 |
Fix adding and removing of all items
Diffstat (limited to 'src/diagramdocument.cpp')
-rw-r--r-- | src/diagramdocument.cpp | 74 |
1 files changed, 57 insertions, 17 deletions
diff --git a/src/diagramdocument.cpp b/src/diagramdocument.cpp index bab359b..3c73df6 100644 --- a/src/diagramdocument.cpp +++ b/src/diagramdocument.cpp @@ -41,7 +41,8 @@ public: gridVisible(true), gridPen(QColor(185, 185, 185), 0), printing(false), - notation(Relational) + notation(Relational), + updateTimerIsRunning(false) {} int gridSize; bool gridVisible; @@ -49,10 +50,12 @@ public: bool printing; Notation notation; + bool updateTimerIsRunning; QTimer *updateTimer; - QList<Line *> linesToAdd; - QSet<DiagramObject *> objectsToUpdate; + QList<DiagramItem *> itemsToShow; + QList<DiagramItem *> itemsToRemove; QSet<Line *> linesToUpdate; + QSet<DiagramObject *> objectsToUpdate; QMap<QString, int> counters; }; @@ -78,8 +81,10 @@ DiagramDocument::setNotation(Notation notation) if (d->notation != notation) { d->notation = notation; // FIXME - foreach (DatabaseRelationship *connection, itemsByType<DatabaseRelationship>()) - connection->updateLayout(); + foreach (Line *line, itemsByType<Line>()) { + updateLineLayout(line); + qDebug() << (void *)line; + } update(); } } @@ -167,9 +172,11 @@ DiagramDocument::updateLineLayout(Line *line) void DiagramDocument::_updateLines() { + d->updateTimerIsRunning = true; QSet<DiagramObject *> objectsToUpdate(d->objectsToUpdate); d->objectsToUpdate.clear(); updateLines(objectsToUpdate); + d->updateTimerIsRunning = false; } void @@ -187,11 +194,39 @@ DiagramDocument::updateLines(QSet<DiagramObject *> objectsToUpdate) } foreach (Line *line, d->linesToUpdate) { line->updateLayout(); - line->update(); // XXX why is this necessary? + line->update(); } d->linesToUpdate.clear(); + + foreach (DiagramItem *item, d->itemsToShow) { + item->show(); + } + d->itemsToShow.clear(); + + foreach (DiagramItem *item, d->itemsToRemove) { + removeItem(item); + } + d->itemsToRemove.clear(); +} + +void +DiagramDocument::addItemLater(DiagramItem *item) +{ + Q_ASSERT(d->updateTimerIsRunning == false); + item->hide(); + addItem(item); + d->itemsToShow.append(item); + d->updateTimer->start(0); } +void +DiagramDocument::removeItemLater(DiagramItem *item) +{ + Q_ASSERT(d->updateTimerIsRunning == false); + item->hide(); + d->itemsToRemove.append(item); + d->updateTimer->start(0); +} template <class T> QList<T *> DiagramDocument::itemsByType() @@ -251,7 +286,7 @@ DiagramDocument::mousePressEvent(QGraphicsSceneMouseEvent *event) table->createId(); table->setInitialName(1 + d->counters[table->typeName()]++); table->setPos(event->scenePos()); - undoStack()->push(new AddItemCommand(this, table)); + undoStack()->push(new AddObjectCommand(this, table)); clearSelection(); table->setSelected(true); setMode(Select); @@ -293,12 +328,11 @@ DiagramDocument::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) DatabaseTable *source = qgraphicsitem_cast<DatabaseTable *>(itemAt(m_line->line().p1())); DatabaseTable *target = qgraphicsitem_cast<DatabaseTable *>(itemAt(m_line->line().p2())); if (source && target && source != target) { - DatabaseRelationship *relation = new DatabaseRelationship(); - relation->createId(); - relation->connector(0)->setHub(source->hub()); - relation->connector(1)->setHub(target->hub()); - updateLines(QSet<DiagramObject *>() << source); - undoStack()->push(new AddItemCommand(this, relation)); + Line *line = new DatabaseRelationship(); + line->createId(); + line->connector(0)->setHub(source->hub()); + line->connector(1)->setHub(target->hub()); + undoStack()->push(new AddLineCommand(this, line)); } delete m_line; m_line = NULL; @@ -328,10 +362,16 @@ DiagramDocument::selectedTable() void DiagramDocument::deleteSelectedItems() { - foreach (QGraphicsItem *item, selectedItems()) { - DatabaseTable *table = qgraphicsitem_cast<DatabaseTable *>(item); - if (table) { - undoStack()->push(new RemoveObjectCommand(this, table)); + foreach (DiagramItem *item, selectedItems()) { + DiagramObject *obj = qobject_cast<DiagramObject *>(item); + if (obj) { + undoStack()->push(new RemoveObjectCommand(this, obj)); + } + else { + Line *line = qobject_cast<Line *>(item); + if (line) { + undoStack()->push(new RemoveLineCommand(this, line)); + } } } } |