From 66b87a178595f00516a081b86bfae997f8e4f64a Mon Sep 17 00:00:00 2001
From: Erik Verbruggen <erik.verbruggen@nokia.com>
Date: Thu, 25 Mar 2010 11:27:12 +0100
Subject: [PATCH] Changed certain error cases to throw exceptions, as the
 higher-levels expect.

---
 src/plugins/qmldesigner/core/model/rewriterview.cpp | 6 +++++-
 tests/auto/qml/qmldesigner/coretests/testcore.cpp   | 4 ++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/plugins/qmldesigner/core/model/rewriterview.cpp b/src/plugins/qmldesigner/core/model/rewriterview.cpp
index 361e459bb3d..9fa5b1e46c3 100644
--- a/src/plugins/qmldesigner/core/model/rewriterview.cpp
+++ b/src/plugins/qmldesigner/core/model/rewriterview.cpp
@@ -396,6 +396,8 @@ void RewriterView::applyModificationGroupChanges()
 
 void RewriterView::applyChanges()
 {
+    clearErrors();
+
     if (inErrorState()) {
         qDebug() << "RewriterView::applyChanges() got called while in error state. Will do a quick-exit now.";
         throw RewritingException(__LINE__, __FUNCTION__, __FILE__, "RewriterView::applyChanges() already in error state");
@@ -403,6 +405,9 @@ void RewriterView::applyChanges()
 
     try {
         modelToTextMerger()->applyChanges();
+        if (!errors().isEmpty()) {
+            enterErrorState(errors().first().description());
+        }
     } catch (Exception &e) {
         enterErrorState(e.description());
     }
@@ -445,7 +450,6 @@ void RewriterView::resetToLastCorrectQml()
     m_textModifier->textDocument()->undo();
     m_textModifier->textDocument()->clearUndoRedoStacks(QTextDocument::RedoStack);
     ModelAmender differenceHandler(m_textToModelMerger.data());
-//    m_textToModelMerger->load(lastCorrectQmlSource.toUtf8(), differenceHandler);
     m_textToModelMerger->load(m_textModifier->text().toUtf8(), differenceHandler);
 
     leaveErrorState();
diff --git a/tests/auto/qml/qmldesigner/coretests/testcore.cpp b/tests/auto/qml/qmldesigner/coretests/testcore.cpp
index 25604f4b8cd..dcdc8713cbe 100644
--- a/tests/auto/qml/qmldesigner/coretests/testcore.cpp
+++ b/tests/auto/qml/qmldesigner/coretests/testcore.cpp
@@ -2562,7 +2562,7 @@ void TestCore::testRewriterExceptionHandling()
     textEdit.setPlainText(qmlString);
     NotIndentingTextEditModifier textModifier(&textEdit);
 
-    QScopedPointer<Model> model(Model::create("Qt/Item", 4, 6));
+    QScopedPointer<Model> model(Model::create("Qt/Text", 4, 6));
     QVERIFY(model.data());
 
     QScopedPointer<TestView> view(new TestView);
@@ -2580,8 +2580,8 @@ void TestCore::testRewriterExceptionHandling()
     try
     {
         RewriterTransaction transaction = view->beginRewriterTransaction();
-        rootNode.variantProperty("bla") = QVariant("blah\"");
         rootNode.variantProperty("text") = QVariant("text");
+        rootNode.variantProperty("bla") = QVariant("blah");
         transaction.commit();
         QFAIL("RewritingException should be thrown");
     } catch (RewritingException &e) {
-- 
GitLab