forked from qt-creator/qt-creator
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:
@@ -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<TextEditor::BaseTextEditorWidget*>(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;
|
||||
|
@@ -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;
|
||||
|
@@ -56,7 +56,7 @@ public:
|
||||
ViewManager();
|
||||
~ViewManager();
|
||||
|
||||
void attachRewriterView(TextModifier *textModifier);
|
||||
void attachRewriterView();
|
||||
void detachRewriterView();
|
||||
|
||||
void attachComponentView();
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -274,7 +274,7 @@ void QmlDesignerPlugin::activateAutoSynchronization()
|
||||
currentDesignDocument()->loadDocument(currentDesignDocument()->plainTextEdit());
|
||||
}
|
||||
|
||||
currentDesignDocument()->activateDocumentModel();
|
||||
currentDesignDocument()->attachRewriterToModel();
|
||||
|
||||
resetModelSelection();
|
||||
|
||||
|
Reference in New Issue
Block a user