forked from qt-creator/qt-creator
QmlDesigner: DesignDocument removing m_currentModel
We remove m_currentModel and replace it by currentModel(). If m_inFileComponentModel is nil the current model is the document model, otherwise the current model is the inFileComponentModel. No need to keep m_currentModel around explicitly. Change-Id: I590e02dc03c2319cbf713b880cf43d740d64e942 Reviewed-by: Marco Bubke <marco.bubke@digia.com>
This commit is contained in:
@@ -70,8 +70,6 @@ namespace QmlDesigner {
|
|||||||
DesignDocument::DesignDocument(QObject *parent) :
|
DesignDocument::DesignDocument(QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_documentModel(Model::create("QtQuick.Item", 1, 0)),
|
m_documentModel(Model::create("QtQuick.Item", 1, 0)),
|
||||||
m_inFileComponentModel(Model::create("QtQuick.Item", 1, 0)),
|
|
||||||
m_currentModel(m_documentModel.data()),
|
|
||||||
m_subComponentManager(new SubComponentManager(m_documentModel.data(), this)),
|
m_subComponentManager(new SubComponentManager(m_documentModel.data(), this)),
|
||||||
m_rewriterView (new RewriterView(RewriterView::Amend, m_documentModel.data())),
|
m_rewriterView (new RewriterView(RewriterView::Amend, m_documentModel.data())),
|
||||||
m_documentLoaded(false),
|
m_documentLoaded(false),
|
||||||
@@ -85,7 +83,12 @@ DesignDocument::~DesignDocument()
|
|||||||
|
|
||||||
Model *DesignDocument::currentModel() const
|
Model *DesignDocument::currentModel() const
|
||||||
{
|
{
|
||||||
return m_currentModel.data();
|
Q_ASSERT(m_documentModel);
|
||||||
|
|
||||||
|
if (m_inFileComponentModel)
|
||||||
|
return m_inFileComponentModel.data();
|
||||||
|
|
||||||
|
return m_documentModel.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
Model *DesignDocument::documentModel() const
|
Model *DesignDocument::documentModel() const
|
||||||
@@ -167,6 +170,14 @@ QmlModelView *DesignDocument::qmlModelView()
|
|||||||
return viewManager().qmlModelView();
|
return viewManager().qmlModelView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Model* DesignDocument::createInFileComponentModel()
|
||||||
|
{
|
||||||
|
Model *model = Model::create("QtQuick.Item", 1, 0);
|
||||||
|
model->setFileUrl(m_documentModel->fileUrl());
|
||||||
|
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Returns any errors that happened when parsing the latest qml file.
|
Returns any errors that happened when parsing the latest qml file.
|
||||||
*/
|
*/
|
||||||
@@ -177,7 +188,7 @@ QList<RewriterView::Error> DesignDocument::qmlSyntaxErrors() const
|
|||||||
|
|
||||||
bool DesignDocument::hasQmlSyntaxErrors() const
|
bool DesignDocument::hasQmlSyntaxErrors() const
|
||||||
{
|
{
|
||||||
return m_currentModel->rewriterView() && !m_currentModel->rewriterView()->errors().isEmpty();
|
return currentModel()->rewriterView() && !currentModel()->rewriterView()->errors().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DesignDocument::displayName() const
|
QString DesignDocument::displayName() const
|
||||||
@@ -227,7 +238,7 @@ bool DesignDocument::isDocumentLoaded() const
|
|||||||
|
|
||||||
void DesignDocument::resetToDocumentModel()
|
void DesignDocument::resetToDocumentModel()
|
||||||
{
|
{
|
||||||
m_currentModel = m_documentModel.data();
|
m_inFileComponentModel.reset();
|
||||||
m_rewriterView->setTextModifier(m_documentTextModifier.data());
|
m_rewriterView->setTextModifier(m_documentTextModifier.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,7 +261,7 @@ void DesignDocument::loadDocument(QPlainTextEdit *edit)
|
|||||||
|
|
||||||
updateFileName(QString(), fileName());
|
updateFileName(QString(), fileName());
|
||||||
|
|
||||||
m_subComponentManager->update(QUrl::fromLocalFile(fileName()), m_currentModel->imports());
|
m_subComponentManager->update(QUrl::fromLocalFile(fileName()), currentModel()->imports());
|
||||||
|
|
||||||
m_documentLoaded = true;
|
m_documentLoaded = true;
|
||||||
}
|
}
|
||||||
@@ -260,7 +271,7 @@ void DesignDocument::changeToDocumentModel()
|
|||||||
viewManager().detachRewriterView();
|
viewManager().detachRewriterView();
|
||||||
viewManager().detachViewsExceptRewriterAndComponetView();
|
viewManager().detachViewsExceptRewriterAndComponetView();
|
||||||
|
|
||||||
m_currentModel = m_documentModel.data();
|
m_inFileComponentModel.reset();
|
||||||
|
|
||||||
viewManager().attachRewriterView(m_documentTextModifier.data());
|
viewManager().attachRewriterView(m_documentTextModifier.data());
|
||||||
viewManager().attachViewsExceptRewriterAndComponetView();
|
viewManager().attachViewsExceptRewriterAndComponetView();
|
||||||
@@ -271,7 +282,7 @@ void DesignDocument::changeToInFileComponentModel()
|
|||||||
viewManager().detachRewriterView();
|
viewManager().detachRewriterView();
|
||||||
viewManager().detachViewsExceptRewriterAndComponetView();
|
viewManager().detachViewsExceptRewriterAndComponetView();
|
||||||
|
|
||||||
m_currentModel = m_inFileComponentModel.data();
|
m_inFileComponentModel.reset(createInFileComponentModel());
|
||||||
|
|
||||||
viewManager().attachRewriterView(m_inFileComponentTextModifier.data());
|
viewManager().attachRewriterView(m_inFileComponentTextModifier.data());
|
||||||
viewManager().attachViewsExceptRewriterAndComponetView();
|
viewManager().attachViewsExceptRewriterAndComponetView();
|
||||||
@@ -289,11 +300,7 @@ void DesignDocument::changeToSubComponentAndPushOnCrumblePath(const ModelNode &c
|
|||||||
|
|
||||||
void DesignDocument::changeToSubComponent(const ModelNode &componentNode)
|
void DesignDocument::changeToSubComponent(const ModelNode &componentNode)
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_documentModel);
|
if (m_inFileComponentModel)
|
||||||
QWeakPointer<Model> oldModel = m_currentModel;
|
|
||||||
Q_ASSERT(oldModel.data());
|
|
||||||
|
|
||||||
if (m_currentModel.data() == m_inFileComponentModel.data())
|
|
||||||
changeToDocumentModel();
|
changeToDocumentModel();
|
||||||
|
|
||||||
bool subComponentLoaded = loadInFileComponent(componentNode);
|
bool subComponentLoaded = loadInFileComponent(componentNode);
|
||||||
@@ -309,7 +316,7 @@ void DesignDocument::changeToExternalSubComponent(const QString &fileName)
|
|||||||
|
|
||||||
void DesignDocument::goIntoSelectedComponent()
|
void DesignDocument::goIntoSelectedComponent()
|
||||||
{
|
{
|
||||||
if (!m_currentModel)
|
if (currentModel())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QList<ModelNode> selectedNodes;
|
QList<ModelNode> selectedNodes;
|
||||||
@@ -325,9 +332,7 @@ void DesignDocument::goIntoSelectedComponent()
|
|||||||
void DesignDocument::activateCurrentModel(TextModifier *textModifier)
|
void DesignDocument::activateCurrentModel(TextModifier *textModifier)
|
||||||
{
|
{
|
||||||
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
||||||
|
|
||||||
Q_ASSERT(m_documentModel);
|
Q_ASSERT(m_documentModel);
|
||||||
Q_ASSERT(m_currentModel);
|
|
||||||
|
|
||||||
if (!plainTextEdit()->parent()) // hack to prevent changing owner of external text edit
|
if (!plainTextEdit()->parent()) // hack to prevent changing owner of external text edit
|
||||||
m_stackedWidget->addWidget(plainTextEdit());
|
m_stackedWidget->addWidget(plainTextEdit());
|
||||||
@@ -367,12 +372,12 @@ void DesignDocument::close()
|
|||||||
void DesignDocument::updateSubcomponentManager()
|
void DesignDocument::updateSubcomponentManager()
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_subComponentManager);
|
Q_ASSERT(m_subComponentManager);
|
||||||
m_subComponentManager->update(QUrl::fromLocalFile(fileName()), m_currentModel->imports());
|
m_subComponentManager->update(QUrl::fromLocalFile(fileName()), currentModel()->imports());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesignDocument::deleteSelected()
|
void DesignDocument::deleteSelected()
|
||||||
{
|
{
|
||||||
if (!m_currentModel)
|
if (!currentModel())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -398,7 +403,7 @@ void DesignDocument::copySelected()
|
|||||||
|
|
||||||
DesignDocumentView view;
|
DesignDocumentView view;
|
||||||
|
|
||||||
m_currentModel->attachView(&view);
|
currentModel()->attachView(&view);
|
||||||
|
|
||||||
if (view.selectedModelNodes().isEmpty())
|
if (view.selectedModelNodes().isEmpty())
|
||||||
return;
|
return;
|
||||||
@@ -418,7 +423,7 @@ void DesignDocument::copySelected()
|
|||||||
if (!selectedNode.isValid())
|
if (!selectedNode.isValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_currentModel->detachView(&view);
|
currentModel()->detachView(&view);
|
||||||
|
|
||||||
copyModel->attachView(&view);
|
copyModel->attachView(&view);
|
||||||
view.replaceModel(selectedNode);
|
view.replaceModel(selectedNode);
|
||||||
@@ -428,7 +433,7 @@ void DesignDocument::copySelected()
|
|||||||
|
|
||||||
view.toClipboard();
|
view.toClipboard();
|
||||||
} else { //multi items selected
|
} else { //multi items selected
|
||||||
m_currentModel->detachView(&view);
|
currentModel()->detachView(&view);
|
||||||
copyModel->attachView(&view);
|
copyModel->attachView(&view);
|
||||||
|
|
||||||
foreach (ModelNode node, view.rootModelNode().allDirectSubModelNodes()) {
|
foreach (ModelNode node, view.rootModelNode().allDirectSubModelNodes()) {
|
||||||
@@ -507,7 +512,7 @@ void DesignDocument::paste()
|
|||||||
if (rootNode.id() == "designer__Selection") {
|
if (rootNode.id() == "designer__Selection") {
|
||||||
QList<ModelNode> selectedNodes = rootNode.allDirectSubModelNodes();
|
QList<ModelNode> selectedNodes = rootNode.allDirectSubModelNodes();
|
||||||
pasteModel->detachView(&view);
|
pasteModel->detachView(&view);
|
||||||
m_currentModel->attachView(&view);
|
currentModel()->attachView(&view);
|
||||||
|
|
||||||
ModelNode targetNode;
|
ModelNode targetNode;
|
||||||
|
|
||||||
@@ -552,7 +557,7 @@ void DesignDocument::paste()
|
|||||||
RewriterTransaction transaction(rewriterView());
|
RewriterTransaction transaction(rewriterView());
|
||||||
|
|
||||||
pasteModel->detachView(&view);
|
pasteModel->detachView(&view);
|
||||||
m_currentModel->attachView(&view);
|
currentModel()->attachView(&view);
|
||||||
ModelNode pastedNode(view.insertModel(rootNode));
|
ModelNode pastedNode(view.insertModel(rootNode));
|
||||||
ModelNode targetNode;
|
ModelNode targetNode;
|
||||||
|
|
||||||
@@ -587,11 +592,11 @@ void DesignDocument::paste()
|
|||||||
|
|
||||||
void DesignDocument::selectAll()
|
void DesignDocument::selectAll()
|
||||||
{
|
{
|
||||||
if (!m_currentModel)
|
if (!currentModel())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
DesignDocumentView view;
|
DesignDocumentView view;
|
||||||
m_currentModel->attachView(&view);
|
currentModel()->attachView(&view);
|
||||||
|
|
||||||
|
|
||||||
QList<ModelNode> allNodesExceptRootNode(view.allModelNodes());
|
QList<ModelNode> allNodesExceptRootNode(view.allModelNodes());
|
||||||
@@ -710,7 +715,7 @@ void DesignDocument::updateActiveQtVersion()
|
|||||||
QString DesignDocument::contextHelpId() const
|
QString DesignDocument::contextHelpId() const
|
||||||
{
|
{
|
||||||
DesignDocumentView view;
|
DesignDocumentView view;
|
||||||
m_currentModel->attachView(&view);
|
currentModel()->attachView(&view);
|
||||||
|
|
||||||
QList<ModelNode> nodes = view.selectedModelNodes();
|
QList<ModelNode> nodes = view.selectedModelNodes();
|
||||||
QString helpId;
|
QString helpId;
|
||||||
|
|||||||
@@ -142,11 +142,12 @@ private: // functions
|
|||||||
|
|
||||||
QmlModelView *qmlModelView();
|
QmlModelView *qmlModelView();
|
||||||
|
|
||||||
|
Model *createInFileComponentModel();
|
||||||
|
|
||||||
private: // variables
|
private: // variables
|
||||||
QScopedPointer<QStackedWidget> m_stackedWidget;
|
QScopedPointer<QStackedWidget> m_stackedWidget;
|
||||||
QScopedPointer<Model> m_documentModel;
|
QScopedPointer<Model> m_documentModel;
|
||||||
QScopedPointer<Model> m_inFileComponentModel;
|
QScopedPointer<Model> m_inFileComponentModel;
|
||||||
QWeakPointer<Model> m_currentModel;
|
|
||||||
QWeakPointer<Core::IEditor> m_textEditor;
|
QWeakPointer<Core::IEditor> m_textEditor;
|
||||||
QScopedPointer<BaseTextEditModifier> m_documentTextModifier;
|
QScopedPointer<BaseTextEditModifier> m_documentTextModifier;
|
||||||
QScopedPointer<ComponentTextModifier> m_inFileComponentTextModifier;
|
QScopedPointer<ComponentTextModifier> m_inFileComponentTextModifier;
|
||||||
|
|||||||
Reference in New Issue
Block a user