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; bool isEnabled() const;
void setEnabled(bool b); 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: protected:
void setModel(Model * model); void setModel(Model * model);
void removeModel(); void removeModel();
@@ -296,10 +313,11 @@ protected:
private: //functions private: //functions
QList<ModelNode> toModelNodeList(const QList<Internal::InternalNodePointer> &nodeList) const; QList<ModelNode> toModelNodeList(const QList<Internal::InternalNodePointer> &nodeList) const;
bool m_enabled = true;
private: private:
QPointer<Model> m_model; QPointer<Model> m_model;
bool m_enabled = true;
bool m_isBlockingNotifications = false;
}; };
QMLDESIGNERCORE_EXPORT QList<Internal::InternalNodePointer> toInternalNodeList(const QList<ModelNode> &nodeList); QMLDESIGNERCORE_EXPORT QList<Internal::InternalNodePointer> toInternalNodeList(const QList<ModelNode> &nodeList);

View File

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