forked from qt-creator/qt-creator
QmlDesigner: Start optimizing action notifications
We get more and more actions and notifying those slowly becomes a bottleneck. I guess we have to add an enum to the context that tells the action which notifier on the view was called, so that the action only react to relevant notifiers. Change-Id: Ic05999b5855e4823659ff1520484242e0c957f1e Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -173,6 +173,11 @@ DesignerActionManager &DesignerActionManager::instance()
|
||||
return QmlDesignerPlugin::instance()->viewManager().designerActionManager();
|
||||
}
|
||||
|
||||
void DesignerActionManager::setupContext()
|
||||
{
|
||||
m_designerActionManagerView->setupContext();
|
||||
}
|
||||
|
||||
class VisiblityModelNodeAction : public ModelNodeContextMenuAction
|
||||
{
|
||||
public:
|
||||
|
@@ -71,6 +71,10 @@ public:
|
||||
QGraphicsWidget *createFormEditorToolBar(QGraphicsItem *parent);
|
||||
|
||||
static DesignerActionManager &instance();
|
||||
void setupContext();
|
||||
|
||||
DesignerActionManager(const DesignerActionManager&) = delete;
|
||||
DesignerActionManager & operator=(const DesignerActionManager&) = delete;
|
||||
|
||||
private:
|
||||
QList<QSharedPointer<ActionInterface> > m_designerActions;
|
||||
|
@@ -147,7 +147,7 @@ void DesignerActionManagerView::bindingPropertiesChanged(const QList<BindingProp
|
||||
void DesignerActionManagerView::instancePropertyChanged(const QList<QPair<ModelNode, PropertyName> > &)
|
||||
{
|
||||
if (hasSingleSelectedModelNode())
|
||||
setupContext();
|
||||
setupContext(SelectionContext::UpdateMode::Fast);
|
||||
}
|
||||
|
||||
DesignerActionManager &DesignerActionManagerView::designerActionManager()
|
||||
@@ -168,13 +168,14 @@ void DesignerActionManagerView::emitSelectionChanged()
|
||||
|
||||
/* We should consider compressing this. */
|
||||
/* One update every 100ms should be enough. */
|
||||
void DesignerActionManagerView::setupContext()
|
||||
void DesignerActionManagerView::setupContext(SelectionContext::UpdateMode updateMode)
|
||||
{
|
||||
if (m_isInRewriterTransaction) {
|
||||
m_setupContextDirty = true;
|
||||
return;
|
||||
}
|
||||
SelectionContext selectionContext(this);
|
||||
selectionContext.setUpdateMode(updateMode);
|
||||
foreach (ActionInterface* action, m_designerActionList) {
|
||||
action->currentContextChanged(selectionContext);
|
||||
}
|
||||
|
@@ -26,6 +26,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <abstractview.h>
|
||||
#include <selectioncontext.h>
|
||||
|
||||
#include "designeractionmanager.h"
|
||||
|
||||
@@ -69,13 +70,11 @@ public:
|
||||
DesignerActionManager &designerActionManager();
|
||||
const DesignerActionManager &designerActionManager() const;
|
||||
void emitSelectionChanged();
|
||||
void setupContext(SelectionContext::UpdateMode updateMode = SelectionContext::UpdateMode::Normal);
|
||||
|
||||
signals:
|
||||
void selectionChanged(bool itemsSelected, bool rootItemIsSelected);
|
||||
|
||||
protected:
|
||||
void setupContext();
|
||||
|
||||
private:
|
||||
DesignerActionManager m_designerActionManager;
|
||||
QList<ActionInterface* > m_designerActionList;
|
||||
|
@@ -96,9 +96,12 @@ void ModelNodeContextMenu::execute(const QPoint &position, bool selectionMenuBoo
|
||||
m_selectionContext.setShowSelectionTools(selectionMenuBool);
|
||||
m_selectionContext.setScenePosition(m_scenePos);
|
||||
|
||||
auto &manager = QmlDesignerPlugin::instance()->designerActionManager();
|
||||
|
||||
manager.setupContext();
|
||||
|
||||
QSet<ActionInterface* > factories =
|
||||
QSet<ActionInterface* >::fromList(QmlDesignerPlugin::instance()->designerActionManager().designerActions());
|
||||
QSet<ActionInterface* >::fromList(manager.designerActions());
|
||||
|
||||
populateMenu(factories, QByteArray(), mainMenu, m_selectionContext);
|
||||
|
||||
|
@@ -117,4 +117,14 @@ bool SelectionContext::isValid() const
|
||||
return view() && view()->model();
|
||||
}
|
||||
|
||||
bool SelectionContext::fastUpdate() const
|
||||
{
|
||||
return m_updateMode == UpdateMode::Fast;
|
||||
}
|
||||
|
||||
void SelectionContext::setUpdateMode(UpdateMode mode)
|
||||
{
|
||||
m_updateMode = mode;
|
||||
}
|
||||
|
||||
} //QmlDesigner
|
||||
|
@@ -35,6 +35,8 @@ namespace QmlDesigner {
|
||||
class QMLDESIGNERCORE_EXPORT SelectionContext {
|
||||
|
||||
public:
|
||||
enum class UpdateMode {Normal, Fast};
|
||||
|
||||
SelectionContext();
|
||||
SelectionContext(AbstractView *view);
|
||||
|
||||
@@ -62,12 +64,16 @@ public:
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
bool fastUpdate() const;
|
||||
void setUpdateMode(UpdateMode mode);
|
||||
|
||||
private:
|
||||
QPointer<AbstractView> m_view;
|
||||
ModelNode m_targetNode;
|
||||
QPointF m_scenePosition;
|
||||
bool m_showSelectionTools = false;
|
||||
bool m_toggled = false;
|
||||
UpdateMode m_updateMode = UpdateMode::Normal;
|
||||
};
|
||||
|
||||
} //QmlDesigner
|
||||
|
Reference in New Issue
Block a user