diff options
author | Jochen Becher <jochen_becher@gmx.de> | 2018-01-07 20:31:02 +0100 |
---|---|---|
committer | Jochen Becher <jochen_becher@gmx.de> | 2018-01-10 15:39:45 +0000 |
commit | 4d99f47974a5afaecffba354a58fe897ffb9f9c3 (patch) | |
tree | 370c333d92e362fad88f8688059a057ce391d969 /src/libs/modelinglib/qmt/model_controller | |
parent | bcc550a4e25121c836ce5f6c83a80bcfa9973548 (diff) | |
download | qt-creator-4d99f47974a5afaecffba354a58fe897ffb9f9c3.tar.gz |
ModelEditor: Implement shared clipboard between all open model-editors
Change-Id: Id2eb6f78f8aa1a698a49d35db6cfceab14a38e0b
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Diffstat (limited to 'src/libs/modelinglib/qmt/model_controller')
-rw-r--r-- | src/libs/modelinglib/qmt/model_controller/modelcontroller.cpp | 27 | ||||
-rw-r--r-- | src/libs/modelinglib/qmt/model_controller/modelcontroller.h | 12 |
2 files changed, 29 insertions, 10 deletions
diff --git a/src/libs/modelinglib/qmt/model_controller/modelcontroller.cpp b/src/libs/modelinglib/qmt/model_controller/modelcontroller.cpp index fc3072da27..ff74d61ff3 100644 --- a/src/libs/modelinglib/qmt/model_controller/modelcontroller.cpp +++ b/src/libs/modelinglib/qmt/model_controller/modelcontroller.cpp @@ -604,16 +604,24 @@ void ModelController::setUndoController(UndoController *undoController) m_undoController = undoController; } +Uid ModelController::ownerKey(const Uid &key) const +{ + MElement *element = findElement(key); + if (!element) + return Uid::invalidUid(); + return ownerKey(element); +} + Uid ModelController::ownerKey(const MElement *element) const { QMT_ASSERT(element, return Uid()); MObject *owner = element->owner(); if (!owner) - return Uid(); + return Uid::invalidUid(); return owner->uid(); } -MElement *ModelController::findElement(const Uid &key) +MElement *ModelController::findElement(const Uid &key) const { if (MObject *object = findObject(key)) return object; @@ -915,17 +923,20 @@ MContainer ModelController::copyElements(const MSelection &modelSelection) return copiedElements; } -void ModelController::pasteElements(MObject *owner, const MContainer &modelContainer) +void ModelController::pasteElements(MObject *owner, const MReferences &modelContainer, PasteOption option) { // clone all elements and renew their keys QHash<Uid, Uid> renewedKeys; QList<MElement *> clonedElements; foreach (MElement *element, modelContainer.elements()) { - MCloneDeepVisitor visitor; - element->accept(&visitor); - MElement *clonedElement = visitor.cloned(); - renewElementKey(clonedElement, &renewedKeys); - clonedElements.append(clonedElement); + if (option == PasteAlwaysWithNewKeys || option == PasteAlwaysAndKeepKeys || !findElement(element->uid())) { + MCloneDeepVisitor visitor; + element->accept(&visitor); + MElement *clonedElement = visitor.cloned(); + if (option == PasteAlwaysWithNewKeys || (option == PasteAlwaysAndKeepKeys && findElement(element->uid()))) + renewElementKey(clonedElement, &renewedKeys); + clonedElements.append(clonedElement); + } } // fix all keys referencing between pasting elements foreach (MElement *clonedElement, clonedElements) diff --git a/src/libs/modelinglib/qmt/model_controller/modelcontroller.h b/src/libs/modelinglib/qmt/model_controller/modelcontroller.h index 345d5c0ce9..5b95d2a575 100644 --- a/src/libs/modelinglib/qmt/model_controller/modelcontroller.h +++ b/src/libs/modelinglib/qmt/model_controller/modelcontroller.h @@ -61,6 +61,13 @@ class QMT_EXPORT ModelController : public QObject class MoveRelationCommand; public: + + enum PasteOption { + PasteAlwaysWithNewKeys, + PasteAlwaysAndKeepKeys, + PasteOnlyNewElements + }; + explicit ModelController(QObject *parent = nullptr); ~ModelController() override; @@ -93,8 +100,9 @@ public: UndoController *undoController() const { return m_undoController; } void setUndoController(UndoController *undoController); + Uid ownerKey(const Uid &key) const; Uid ownerKey(const MElement *element) const; - MElement *findElement(const Uid &key); + MElement *findElement(const Uid &key) const; template<class T> T *findElement(const Uid &key) { return dynamic_cast<T *>(findElement(key)); } @@ -124,7 +132,7 @@ public: MContainer cutElements(const MSelection &modelSelection); MContainer copyElements(const MSelection &modelSelection); - void pasteElements(MObject *owner, const MContainer &modelContainer); + void pasteElements(MObject *owner, const MReferences &modelContainer, PasteOption option); void deleteElements(const MSelection &modelSelection); private: |