From 84c30ea99ead230641b12d14623dda9682980bda Mon Sep 17 00:00:00 2001
From: Kai Koehne <kai.koehne@nokia.com>
Date: Wed, 13 Jan 2010 11:44:13 +0100
Subject: [PATCH] Let the DesignMode recover when the qml contains an error on
 first load

If the qml contains an error on frist call of
DesignDocumentController::loadMaster, we did not wire up the components
to the model. If the user then fixed the qml, the Design mode widgets
were 'enabled', but didn't contain any meaningful input.

Fixed by always wiring up the components. Unfortunately this shows the
'default' model with just a Rectangle.
---
 .../integration/designdocumentcontroller.cpp         | 12 ++++--------
 src/plugins/qmldesigner/designmodewidget.cpp         |  8 +++++++-
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/plugins/qmldesigner/components/integration/designdocumentcontroller.cpp b/src/plugins/qmldesigner/components/integration/designdocumentcontroller.cpp
index 06ff7462437..b24792f5990 100644
--- a/src/plugins/qmldesigner/components/integration/designdocumentcontroller.cpp
+++ b/src/plugins/qmldesigner/components/integration/designdocumentcontroller.cpp
@@ -332,10 +332,10 @@ QList<RewriterView::Error> DesignDocumentController::loadMaster(QPlainTextEdit *
 
     //m_d->masterModel = Model::create(m_d->textModifier, m_d->searchPath, errors);
 
-    m_d->masterModel = Model::create("Item", 4, 6);
+    m_d->masterModel = Model::create("Qt/Rectangle", 4, 6);
     m_d->masterModel->setFileUrl(m_d->searchPath);
 
-    m_d->subComponentModel = Model::create("Item", 4, 6);
+    m_d->subComponentModel = Model::create("Qt/Rectangle", 4, 6);
     m_d->subComponentModel->setFileUrl(m_d->searchPath);
 
     m_d->subComponentManager = new SubComponentManager(m_d->masterModel->metaInfo(), this);
@@ -354,13 +354,9 @@ QList<RewriterView::Error> DesignDocumentController::loadMaster(QPlainTextEdit *
     m_d->masterModel->attachView(m_d->viewLogger.data());
 #endif
 
-    // m_d->masterModel->detachView(m_d->rewriterView.data());
-
-    QList<RewriterView::Error> errors = m_d->rewriterView->errors();
-    if (errors.isEmpty())
-        loadCurrentModel();
+    loadCurrentModel();
 
-    return errors;
+    return m_d->rewriterView->errors();
 }
 
 void DesignDocumentController::changeCurrentModelTo(const ModelNode &componentNode)
diff --git a/src/plugins/qmldesigner/designmodewidget.cpp b/src/plugins/qmldesigner/designmodewidget.cpp
index 3202bf3aff2..71ec441507c 100644
--- a/src/plugins/qmldesigner/designmodewidget.cpp
+++ b/src/plugins/qmldesigner/designmodewidget.cpp
@@ -356,6 +356,9 @@ void DocumentWidget::disable(const QList<RewriterView::Error> &errors)
 
 void DocumentWidget::updateErrorStatus(const QList<RewriterView::Error> &errors)
 {
+    if (debug)
+        qDebug() << Q_FUNC_INFO << errors.count();
+
     if (m_isDisabled && errors.isEmpty()) {
         enable();
     } else if (!errors.isEmpty()) {
@@ -526,7 +529,6 @@ void DesignModeWidget::showEditor(Core::IEditor *editor)
     if (textEdit && textEditor && fileName.endsWith(".qml")) {
         if (m_documentHash.contains(textEdit)) {
             documentWidget = m_documentHash.value(textEdit);
-            documentWidget->setAutoSynchronization(true);
         } else {
             DesignDocumentController *newDocument = new DesignDocumentController(0);
             newDocument->setFileName(fileName);
@@ -659,6 +661,10 @@ void DesignModeWidget::setCurrentDocumentWidget(DocumentWidget *newDocumentWidge
 {
     if (debug)
         qDebug() << Q_FUNC_INFO << newDocumentWidget;
+
+    if (m_currentDocumentWidget == newDocumentWidget)
+        return;
+
     if (m_currentDocumentWidget) {
         m_currentDocumentWidget->setAutoSynchronization(false);
         m_currentDocumentWidget->saveSettings();
-- 
GitLab