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 <marco.bubke@digia.com>
This commit is contained in:
Thomas Hartmann
2013-08-01 11:48:36 +02:00
parent baed8a12ff
commit 0ea0c2f876
5 changed files with 16 additions and 25 deletions

View File

@@ -156,10 +156,7 @@ bool DesignDocument::loadInFileComponent(const ModelNode &componentNode)
if (!componentNode.isRootNode()) { if (!componentNode.isRootNode()) {
//change to subcomponent model //change to subcomponent model
changeToInFileComponentModel(createComponentTextModifier(m_documentTextModifier.data(), rewriterView(), componentText, componentNode));
m_inFileComponentTextModifier.reset(createComponentTextModifier(m_documentTextModifier.data(), rewriterView(), componentText, componentNode));
changeToInFileComponentModel();
} }
return true; return true;
@@ -239,7 +236,6 @@ bool DesignDocument::isDocumentLoaded() const
void DesignDocument::resetToDocumentModel() void DesignDocument::resetToDocumentModel()
{ {
m_inFileComponentModel.reset(); m_inFileComponentModel.reset();
m_rewriterView->setTextModifier(m_documentTextModifier.data());
} }
void DesignDocument::loadDocument(QPlainTextEdit *edit) void DesignDocument::loadDocument(QPlainTextEdit *edit)
@@ -254,6 +250,7 @@ void DesignDocument::loadDocument(QPlainTextEdit *edit)
this, SIGNAL(dirtyStateChanged(bool))); this, SIGNAL(dirtyStateChanged(bool)));
m_documentTextModifier.reset(new BaseTextEditModifier(dynamic_cast<TextEditor::BaseTextEditorWidget*>(plainTextEdit()))); m_documentTextModifier.reset(new BaseTextEditModifier(dynamic_cast<TextEditor::BaseTextEditorWidget*>(plainTextEdit())));
m_documentModel->setTextModifier(m_documentTextModifier.data());
m_inFileComponentTextModifier.reset(); m_inFileComponentTextModifier.reset();
@@ -271,18 +268,20 @@ void DesignDocument::changeToDocumentModel()
m_inFileComponentModel.reset(); m_inFileComponentModel.reset();
viewManager().attachRewriterView(m_documentTextModifier.data()); viewManager().attachRewriterView();
viewManager().attachViewsExceptRewriterAndComponetView(); viewManager().attachViewsExceptRewriterAndComponetView();
} }
void DesignDocument::changeToInFileComponentModel() void DesignDocument::changeToInFileComponentModel(ComponentTextModifier *textModifer)
{ {
m_inFileComponentTextModifier.reset(textModifer);
viewManager().detachRewriterView(); viewManager().detachRewriterView();
viewManager().detachViewsExceptRewriterAndComponetView(); viewManager().detachViewsExceptRewriterAndComponetView();
m_inFileComponentModel.reset(createInFileComponentModel()); m_inFileComponentModel.reset(createInFileComponentModel());
m_inFileComponentModel->setTextModifier(m_inFileComponentTextModifier.data());
viewManager().attachRewriterView(m_inFileComponentTextModifier.data()); viewManager().attachRewriterView();
viewManager().attachViewsExceptRewriterAndComponetView(); viewManager().attachViewsExceptRewriterAndComponetView();
} }
@@ -304,7 +303,7 @@ void DesignDocument::changeToSubComponent(const ModelNode &componentNode)
bool subComponentLoaded = loadInFileComponent(componentNode); bool subComponentLoaded = loadInFileComponent(componentNode);
if (subComponentLoaded) if (subComponentLoaded)
activateCurrentModel(m_inFileComponentTextModifier.data()); attachRewriterToModel();
} }
void DesignDocument::changeToExternalSubComponent(const QString &fileName) 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)); QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
Q_ASSERT(m_documentModel); Q_ASSERT(m_documentModel);
viewManager().attachRewriterView(textModifier); viewManager().attachRewriterView();
Q_ASSERT(m_documentModel); Q_ASSERT(m_documentModel);
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
} }
void DesignDocument::activateDocumentModel()
{
activateCurrentModel(m_documentTextModifier.data());
}
bool DesignDocument::isUndoAvailable() const bool DesignDocument::isUndoAvailable() const
{ {
if (plainTextEdit()) if (plainTextEdit())
return plainTextEdit()->document()->isUndoAvailable(); return plainTextEdit()->document()->isUndoAvailable();
return false; return false;

View File

@@ -70,7 +70,7 @@ public:
QString simplfiedDisplayName() const; QString simplfiedDisplayName() const;
void loadDocument(QPlainTextEdit *edit); void loadDocument(QPlainTextEdit *edit);
void activateDocumentModel(); void attachRewriterToModel();
void close(); void close();
void updateSubcomponentManager(); void updateSubcomponentManager();
@@ -127,8 +127,7 @@ private slots:
void updateFileName(const QString &oldFileName, const QString &newFileName); void updateFileName(const QString &oldFileName, const QString &newFileName);
private: // functions private: // functions
void changeToInFileComponentModel(); void changeToInFileComponentModel(ComponentTextModifier *textModifer);
void activateCurrentModel(TextModifier *textModifier);
QWidget *centralWidget() const; QWidget *centralWidget() const;
QString pathToQt() const; QString pathToQt() const;

View File

@@ -56,7 +56,7 @@ public:
ViewManager(); ViewManager();
~ViewManager(); ~ViewManager();
void attachRewriterView(TextModifier *textModifier); void attachRewriterView();
void detachRewriterView(); void detachRewriterView();
void attachComponentView(); void attachComponentView();

View File

@@ -47,12 +47,11 @@ void ViewManager::attachNodeInstanceView()
currentModel()->setNodeInstanceView(&m_nodeInstanceView); currentModel()->setNodeInstanceView(&m_nodeInstanceView);
} }
void ViewManager::attachRewriterView(TextModifier *textModifier) void ViewManager::attachRewriterView()
{ {
if (currentDesignDocument()->rewriterView()) { if (currentDesignDocument()->rewriterView()) {
currentDesignDocument()->rewriterView()->setTextModifier(textModifier);
currentDesignDocument()->rewriterView()->reactivateTextMofifierChangeSignals();
currentModel()->setRewriterView(currentDesignDocument()->rewriterView()); currentModel()->setRewriterView(currentDesignDocument()->rewriterView());
currentDesignDocument()->rewriterView()->reactivateTextMofifierChangeSignals();
} }
} }

View File

@@ -274,7 +274,7 @@ void QmlDesignerPlugin::activateAutoSynchronization()
currentDesignDocument()->loadDocument(currentDesignDocument()->plainTextEdit()); currentDesignDocument()->loadDocument(currentDesignDocument()->plainTextEdit());
} }
currentDesignDocument()->activateDocumentModel(); currentDesignDocument()->attachRewriterToModel();
resetModelSelection(); resetModelSelection();