forked from qt-creator/qt-creator
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 <thomas.hartmann@qt.io>
This commit is contained in:
@@ -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<void(bool)> m_setWidgetStatusCallback;
|
||||
bool m_hasIncompleteTypeInformation = false;
|
||||
bool m_restoringAuxData = false;
|
||||
bool m_modelAttachPending = false;
|
||||
|
||||
mutable QHash<int, ModelNode> m_canonicalIntModelNode;
|
||||
mutable QHash<ModelNode, int> m_canonicalModelNodeInt;
|
||||
|
@@ -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*/
|
||||
|
Reference in New Issue
Block a user