QmlDesigner: Add notification blocker

Change-Id: I9609437a7190f92cc208d56cff57c5b35ef57beb
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Marco Bubke
2020-10-22 17:45:27 +02:00
parent bed1c073db
commit 2d561f8603
2 changed files with 35 additions and 11 deletions

View File

@@ -284,6 +284,23 @@ public:
bool isEnabled() const;
void setEnabled(bool b);
bool isBlockingNotifications() const { return m_isBlockingNotifications; }
class NotificationBlocker
{
public:
NotificationBlocker(AbstractView *view)
: m_view{view}
{
m_view->m_isBlockingNotifications = true;
}
~NotificationBlocker() { m_view->m_isBlockingNotifications = false; }
private:
AbstractView *m_view;
};
protected:
void setModel(Model * model);
void removeModel();
@@ -296,10 +313,11 @@ protected:
private: //functions
QList<ModelNode> toModelNodeList(const QList<Internal::InternalNodePointer> &nodeList) const;
bool m_enabled = true;
private:
QPointer<Model> m_model;
bool m_enabled = true;
bool m_isBlockingNotifications = false;
};
QMLDESIGNERCORE_EXPORT QList<Internal::InternalNodePointer> toInternalNodeList(const QList<ModelNode> &nodeList);

View File

@@ -397,17 +397,19 @@ void ModelPrivate::notifyNodeInstanceViewLast(Callable call)
QString description;
try {
if (rewriterView())
if (rewriterView() && !rewriterView()->isBlockingNotifications())
call(rewriterView());
} catch (const RewritingException &e) {
description = e.description();
resetModel = true;
}
for (QPointer<AbstractView> view : enabledViews())
for (QPointer<AbstractView> view : enabledViews()) {
if (!view->isBlockingNotifications())
call(view.data());
}
if (nodeInstanceView())
if (nodeInstanceView() && !nodeInstanceView()->isBlockingNotifications())
call(nodeInstanceView());
if (resetModel)
@@ -421,18 +423,20 @@ void ModelPrivate::notifyNormalViewsLast(Callable call)
QString description;
try {
if (rewriterView())
if (rewriterView() && !rewriterView()->isBlockingNotifications())
call(rewriterView());
} catch (const RewritingException &e) {
description = e.description();
resetModel = true;
}
if (nodeInstanceView())
if (nodeInstanceView() && !nodeInstanceView()->isBlockingNotifications())
call(nodeInstanceView());
for (QPointer<AbstractView> view : enabledViews())
for (QPointer<AbstractView> view : enabledViews()) {
if (!view->isBlockingNotifications())
call(view.data());
}
if (resetModel)
resetModelByRewriter(description);
@@ -441,8 +445,10 @@ void ModelPrivate::notifyNormalViewsLast(Callable call)
template<typename Callable>
void ModelPrivate::notifyInstanceChanges(Callable call)
{
for (QPointer<AbstractView> view : enabledViews())
for (QPointer<AbstractView> view : enabledViews()) {
if (!view->isBlockingNotifications())
call(view.data());
}
}
void ModelPrivate::notifyAuxiliaryDataChanged(const InternalNodePointer &internalNode,