From 0ea0c2f8769f06a22e34ec9dd55d89865a1697e8 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Thu, 1 Aug 2013 11:48:36 +0200 Subject: [PATCH] QmlDesigner.DesignDocument: simplifying the TextModifers The TextModifers for the sub component and the document are now assigned to the model. This simplfifies the code. The member variables to the TextModifers are only kept for ownership. The DesignDocument still owns the two TextModifers. Change-Id: Idc84a2ba718666ce54683a67635a93352784dddd Reviewed-by: Marco Bubke --- .../components/integration/designdocument.cpp | 27 +++++++------------ .../components/integration/designdocument.h | 5 ++-- .../designercore/include/viewmanager.h | 2 +- .../designercore/model/viewmanager.cpp | 5 ++-- src/plugins/qmldesigner/qmldesignerplugin.cpp | 2 +- 5 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/plugins/qmldesigner/components/integration/designdocument.cpp b/src/plugins/qmldesigner/components/integration/designdocument.cpp index c49a5ffb523..a497c9ec0ba 100644 --- a/src/plugins/qmldesigner/components/integration/designdocument.cpp +++ b/src/plugins/qmldesigner/components/integration/designdocument.cpp @@ -156,10 +156,7 @@ bool DesignDocument::loadInFileComponent(const ModelNode &componentNode) if (!componentNode.isRootNode()) { //change to subcomponent model - - m_inFileComponentTextModifier.reset(createComponentTextModifier(m_documentTextModifier.data(), rewriterView(), componentText, componentNode)); - - changeToInFileComponentModel(); + changeToInFileComponentModel(createComponentTextModifier(m_documentTextModifier.data(), rewriterView(), componentText, componentNode)); } return true; @@ -239,7 +236,6 @@ bool DesignDocument::isDocumentLoaded() const void DesignDocument::resetToDocumentModel() { m_inFileComponentModel.reset(); - m_rewriterView->setTextModifier(m_documentTextModifier.data()); } void DesignDocument::loadDocument(QPlainTextEdit *edit) @@ -254,6 +250,7 @@ void DesignDocument::loadDocument(QPlainTextEdit *edit) this, SIGNAL(dirtyStateChanged(bool))); m_documentTextModifier.reset(new BaseTextEditModifier(dynamic_cast(plainTextEdit()))); + m_documentModel->setTextModifier(m_documentTextModifier.data()); m_inFileComponentTextModifier.reset(); @@ -271,18 +268,20 @@ void DesignDocument::changeToDocumentModel() m_inFileComponentModel.reset(); - viewManager().attachRewriterView(m_documentTextModifier.data()); + viewManager().attachRewriterView(); viewManager().attachViewsExceptRewriterAndComponetView(); } -void DesignDocument::changeToInFileComponentModel() +void DesignDocument::changeToInFileComponentModel(ComponentTextModifier *textModifer) { + m_inFileComponentTextModifier.reset(textModifer); viewManager().detachRewriterView(); viewManager().detachViewsExceptRewriterAndComponetView(); m_inFileComponentModel.reset(createInFileComponentModel()); + m_inFileComponentModel->setTextModifier(m_inFileComponentTextModifier.data()); - viewManager().attachRewriterView(m_inFileComponentTextModifier.data()); + viewManager().attachRewriterView(); viewManager().attachViewsExceptRewriterAndComponetView(); } @@ -304,7 +303,7 @@ void DesignDocument::changeToSubComponent(const ModelNode &componentNode) bool subComponentLoaded = loadInFileComponent(componentNode); if (subComponentLoaded) - activateCurrentModel(m_inFileComponentTextModifier.data()); + attachRewriterToModel(); } void DesignDocument::changeToExternalSubComponent(const QString &fileName) @@ -327,25 +326,19 @@ void DesignDocument::goIntoSelectedComponent() } } -void DesignDocument::activateCurrentModel(TextModifier *textModifier) +void DesignDocument::attachRewriterToModel() { QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); Q_ASSERT(m_documentModel); - viewManager().attachRewriterView(textModifier); + viewManager().attachRewriterView(); Q_ASSERT(m_documentModel); QApplication::restoreOverrideCursor(); } -void DesignDocument::activateDocumentModel() -{ - activateCurrentModel(m_documentTextModifier.data()); -} - bool DesignDocument::isUndoAvailable() const { - if (plainTextEdit()) return plainTextEdit()->document()->isUndoAvailable(); return false; diff --git a/src/plugins/qmldesigner/components/integration/designdocument.h b/src/plugins/qmldesigner/components/integration/designdocument.h index d51db7acabb..2e1b86d4a1e 100644 --- a/src/plugins/qmldesigner/components/integration/designdocument.h +++ b/src/plugins/qmldesigner/components/integration/designdocument.h @@ -70,7 +70,7 @@ public: QString simplfiedDisplayName() const; void loadDocument(QPlainTextEdit *edit); - void activateDocumentModel(); + void attachRewriterToModel(); void close(); void updateSubcomponentManager(); @@ -127,8 +127,7 @@ private slots: void updateFileName(const QString &oldFileName, const QString &newFileName); private: // functions - void changeToInFileComponentModel(); - void activateCurrentModel(TextModifier *textModifier); + void changeToInFileComponentModel(ComponentTextModifier *textModifer); QWidget *centralWidget() const; QString pathToQt() const; diff --git a/src/plugins/qmldesigner/designercore/include/viewmanager.h b/src/plugins/qmldesigner/designercore/include/viewmanager.h index 9643b27fdf3..b155f6c6dee 100644 --- a/src/plugins/qmldesigner/designercore/include/viewmanager.h +++ b/src/plugins/qmldesigner/designercore/include/viewmanager.h @@ -56,7 +56,7 @@ public: ViewManager(); ~ViewManager(); - void attachRewriterView(TextModifier *textModifier); + void attachRewriterView(); void detachRewriterView(); void attachComponentView(); diff --git a/src/plugins/qmldesigner/designercore/model/viewmanager.cpp b/src/plugins/qmldesigner/designercore/model/viewmanager.cpp index 7690ccfa3a3..a17a0e46023 100644 --- a/src/plugins/qmldesigner/designercore/model/viewmanager.cpp +++ b/src/plugins/qmldesigner/designercore/model/viewmanager.cpp @@ -47,12 +47,11 @@ void ViewManager::attachNodeInstanceView() currentModel()->setNodeInstanceView(&m_nodeInstanceView); } -void ViewManager::attachRewriterView(TextModifier *textModifier) +void ViewManager::attachRewriterView() { if (currentDesignDocument()->rewriterView()) { - currentDesignDocument()->rewriterView()->setTextModifier(textModifier); - currentDesignDocument()->rewriterView()->reactivateTextMofifierChangeSignals(); currentModel()->setRewriterView(currentDesignDocument()->rewriterView()); + currentDesignDocument()->rewriterView()->reactivateTextMofifierChangeSignals(); } } diff --git a/src/plugins/qmldesigner/qmldesignerplugin.cpp b/src/plugins/qmldesigner/qmldesignerplugin.cpp index c03a851c959..de69e63c731 100644 --- a/src/plugins/qmldesigner/qmldesignerplugin.cpp +++ b/src/plugins/qmldesigner/qmldesignerplugin.cpp @@ -274,7 +274,7 @@ void QmlDesignerPlugin::activateAutoSynchronization() currentDesignDocument()->loadDocument(currentDesignDocument()->plainTextEdit()); } - currentDesignDocument()->activateDocumentModel(); + currentDesignDocument()->attachRewriterToModel(); resetModelSelection();