From a9619b53f36209036306e8d2738995edbc13d92b Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Tue, 19 May 2020 11:54:46 +0300 Subject: [PATCH] QmlDesigner: Keep possible imports updated QmlJS resolves available libraries at its own pace on the background, which means all possible imports are not necessarily known at the time the model is attached. Listen to QmlJS::ModelManagerInterface::libraryInfoUpdated to trigger reload of document when available libraries change to keep possible imports list up to date. Change-Id: Id605a6ee1fe2c43735bb30c9446d2a31ef52fe99 Fixes: QDS-1592 Reviewed-by: Thomas Hartmann --- .../designercore/include/rewriterview.h | 2 ++ .../designercore/model/rewriterview.cpp | 20 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/plugins/qmldesigner/designercore/include/rewriterview.h b/src/plugins/qmldesigner/designercore/include/rewriterview.h index a1513128d79..dcd85c950d0 100644 --- a/src/plugins/qmldesigner/designercore/include/rewriterview.h +++ b/src/plugins/qmldesigner/designercore/include/rewriterview.h @@ -189,6 +189,7 @@ protected: // functions private: //variables ModelNode nodeAtTextCursorPositionHelper(const ModelNode &root, int cursorPosition) const; void setupCanonicalHashes() const; + void handleLibraryInfoUpdate(); TextModifier *m_textModifier = nullptr; int transactionLevel = 0; @@ -209,6 +210,7 @@ private: //variables std::function m_setWidgetStatusCallback; bool m_hasIncompleteTypeInformation = false; bool m_restoringAuxData = false; + bool m_modelAttachPending = false; mutable QHash m_canonicalIntModelNode; mutable QHash m_canonicalModelNodeInt; diff --git a/src/plugins/qmldesigner/designercore/model/rewriterview.cpp b/src/plugins/qmldesigner/designercore/model/rewriterview.cpp index 4d8ebd43152..f2f7f02e64f 100644 --- a/src/plugins/qmldesigner/designercore/model/rewriterview.cpp +++ b/src/plugins/qmldesigner/designercore/model/rewriterview.cpp @@ -70,7 +70,12 @@ RewriterView::RewriterView(DifferenceHandling differenceHandling, QObject *paren m_textToModelMerger(new Internal::TextToModelMerger(this)) { m_amendTimer.setSingleShot(true); + m_amendTimer.setInterval(400); connect(&m_amendTimer, &QTimer::timeout, this, &RewriterView::amendQmlText); + + QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance(); + connect(modelManager, &QmlJS::ModelManagerInterface::libraryInfoUpdated, + this, &RewriterView::handleLibraryInfoUpdate, Qt::QueuedConnection); } RewriterView::~RewriterView() = default; @@ -87,6 +92,8 @@ Internal::TextToModelMerger *RewriterView::textToModelMerger() const void RewriterView::modelAttached(Model *model) { + m_modelAttachPending = false; + if (model && model->textModifier()) setTextModifier(model->textModifier()); @@ -100,10 +107,12 @@ void RewriterView::modelAttached(Model *model) if (!(m_errors.isEmpty() && m_warnings.isEmpty())) notifyErrorsAndWarnings(m_errors); - if (hasIncompleteTypeInformation()) + if (hasIncompleteTypeInformation()) { + m_modelAttachPending = true; QTimer::singleShot(1000, this, [this, model](){ modelAttached(model); }); + } } void RewriterView::modelAboutToBeDetached(Model * /*model*/) @@ -796,6 +805,13 @@ void RewriterView::setupCanonicalHashes() const } } +void RewriterView::handleLibraryInfoUpdate() +{ + // Trigger dummy amend to reload document when library info changes + if (isAttached() && !m_modelAttachPending) + m_amendTimer.start(); +} + ModelNode RewriterView::nodeAtTextCursorPosition(int cursorPosition) const { return nodeAtTextCursorPositionHelper(rootModelNode(), cursorPosition); @@ -995,7 +1011,7 @@ void RewriterView::qmlTextChanged() auto &viewManager = QmlDesignerPlugin::instance()->viewManager(); if (viewManager.usesRewriterView(this)) { QmlDesignerPlugin::instance()->viewManager().disableWidgets(); - m_amendTimer.start(400); + m_amendTimer.start(); } #else /*Keep test synchronous*/