forked from qt-creator/qt-creator
QuickToolBar: reduce usage of lookup context
Getting the lookup context is expensive. So it is now done only on user interaction. Reviewed-by: Roberto Raggi
This commit is contained in:
@@ -52,9 +52,9 @@ class QMLJS_EXPORT IContextPane : public QObject
|
||||
public:
|
||||
IContextPane(QObject *parent = 0) : QObject(parent) {}
|
||||
virtual ~IContextPane() {}
|
||||
virtual void apply(TextEditor::BaseTextEditorEditable *editor, LookupContext::Ptr lookupContext, AST::Node *node, bool update, bool force = false) = 0;
|
||||
virtual void apply(TextEditor::BaseTextEditorEditable *editor, Document::Ptr document, LookupContext::Ptr lookupContext, AST::Node *node, bool update, bool force = false) = 0;
|
||||
virtual void setEnabled(bool) = 0;
|
||||
virtual bool isAvailable(TextEditor::BaseTextEditorEditable *editor, LookupContext::Ptr lookupContext, AST::Node *node) = 0;
|
||||
virtual bool isAvailable(TextEditor::BaseTextEditorEditable *editor, Document::Ptr document, AST::Node *node) = 0;
|
||||
virtual QWidget* widget() = 0;
|
||||
signals:
|
||||
void closed();
|
||||
|
@@ -985,8 +985,8 @@ void QmlJSTextEditor::updateCursorPositionNow()
|
||||
Node *oldNode = m_semanticInfo.declaringMemberNoProperties(m_oldCursorPosition);
|
||||
Node *newNode = m_semanticInfo.declaringMemberNoProperties(position());
|
||||
if (oldNode != newNode && m_oldCursorPosition != -1)
|
||||
m_contextPane->apply(editableInterface(), m_semanticInfo.lookupContext(), newNode, false);
|
||||
if (m_contextPane->isAvailable(editableInterface(), m_semanticInfo.lookupContext(), newNode) &&
|
||||
m_contextPane->apply(editableInterface(), semanticInfo().document, LookupContext::Ptr(),newNode, false);
|
||||
if (m_contextPane->isAvailable(editableInterface(), semanticInfo().document, newNode) &&
|
||||
!m_contextPane->widget()->isVisible()) {
|
||||
QList<TextEditor::Internal::RefactorMarker> markers;
|
||||
if (UiObjectMember *m = newNode->uiObjectMemberCast()) {
|
||||
@@ -1456,7 +1456,7 @@ void QmlJSTextEditor::showContextPane()
|
||||
{
|
||||
if (m_contextPane && m_semanticInfo.isValid()) {
|
||||
Node *newNode = m_semanticInfo.declaringMemberNoProperties(position());
|
||||
m_contextPane->apply(editableInterface(), m_semanticInfo.lookupContext(), newNode, false, true);
|
||||
m_contextPane->apply(editableInterface(), m_semanticInfo.document, m_semanticInfo.lookupContext(), newNode, false, true);
|
||||
m_oldCursorPosition = position();
|
||||
QList<TextEditor::Internal::RefactorMarker> markers;
|
||||
setRefactorMarkers(markers);
|
||||
@@ -1551,7 +1551,7 @@ void QmlJSTextEditor::wheelEvent(QWheelEvent *event)
|
||||
LookupContext::Ptr lookupContext;
|
||||
if (m_semanticInfo.isValid())
|
||||
lookupContext = m_semanticInfo.lookupContext();
|
||||
m_contextPane->apply(editableInterface(), lookupContext, m_semanticInfo.declaringMemberNoProperties(m_oldCursorPosition), false, true);
|
||||
m_contextPane->apply(editableInterface(), semanticInfo().document, QmlJS::LookupContext::Ptr(), m_semanticInfo.declaringMemberNoProperties(m_oldCursorPosition), false, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1801,7 +1801,7 @@ void QmlJSTextEditor::updateSemanticInfo(const SemanticInfo &semanticInfo)
|
||||
if (m_contextPane) {
|
||||
Node *newNode = m_semanticInfo.declaringMemberNoProperties(position());
|
||||
if (newNode) {
|
||||
m_contextPane->apply(editableInterface(), m_semanticInfo.lookupContext(), newNode, true);
|
||||
m_contextPane->apply(editableInterface(), semanticInfo.document, LookupContext::Ptr(), newNode, true);
|
||||
m_cursorPositionTimer->start(); //update text marker
|
||||
}
|
||||
}
|
||||
@@ -1854,10 +1854,7 @@ bool QmlJSTextEditor::hideContextPane()
|
||||
{
|
||||
bool b = (m_contextPane) && m_contextPane->widget()->isVisible();
|
||||
if (b) {
|
||||
LookupContext::Ptr lookupContext;
|
||||
if (m_semanticInfo.isValid())
|
||||
lookupContext = m_semanticInfo.lookupContext();
|
||||
m_contextPane->apply(editableInterface(), lookupContext, 0, false);
|
||||
m_contextPane->apply(editableInterface(), semanticInfo().document, LookupContext::Ptr(), 0, false);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
@@ -98,17 +98,14 @@ QuickToolBar::~QuickToolBar()
|
||||
m_widget.clear();
|
||||
}
|
||||
|
||||
void QuickToolBar::apply(TextEditor::BaseTextEditorEditable *editor, LookupContext::Ptr lookupContext, AST::Node *node, bool update, bool force)
|
||||
void QuickToolBar::apply(TextEditor::BaseTextEditorEditable *editor, Document::Ptr document, LookupContext::Ptr lookupContext, AST::Node *node, bool update, bool force)
|
||||
{
|
||||
if (!QuickToolBarSettings::get().enableContextPane && !force && !update) {
|
||||
contextWidget()->hide();
|
||||
return;
|
||||
}
|
||||
|
||||
if (lookupContext.isNull())
|
||||
return;
|
||||
Document::Ptr doc = lookupContext->document();
|
||||
if (doc.isNull())
|
||||
if (document.isNull())
|
||||
return;
|
||||
|
||||
if (update && editor != m_editor)
|
||||
@@ -116,24 +113,26 @@ void QuickToolBar::apply(TextEditor::BaseTextEditorEditable *editor, LookupConte
|
||||
|
||||
m_blockWriting = true;
|
||||
|
||||
const Interpreter::ObjectValue *scopeObject = doc->bind()->findQmlObject(node);
|
||||
const Interpreter::ObjectValue *scopeObject = document->bind()->findQmlObject(node);
|
||||
|
||||
QStringList prototypes;
|
||||
while (scopeObject) {
|
||||
prototypes.append(scopeObject->className());
|
||||
scopeObject = scopeObject->prototype(lookupContext->context());
|
||||
}
|
||||
if (!lookupContext.isNull()) {
|
||||
m_prototypes.clear();
|
||||
while (scopeObject) {
|
||||
m_prototypes.append(scopeObject->className());
|
||||
scopeObject = scopeObject->prototype(lookupContext->context());
|
||||
}
|
||||
|
||||
if (prototypes.contains("PropertyChanges")) {
|
||||
const Interpreter::ObjectValue *targetObject = getPropertyChangesTarget(node, lookupContext);
|
||||
prototypes.clear();
|
||||
while (targetObject) {
|
||||
prototypes.append(targetObject->className());
|
||||
targetObject = targetObject->prototype(lookupContext->context());
|
||||
if (m_prototypes.contains("PropertyChanges")) {
|
||||
const Interpreter::ObjectValue *targetObject = getPropertyChangesTarget(node, lookupContext);
|
||||
m_prototypes.clear();
|
||||
while (targetObject) {
|
||||
m_prototypes.append(targetObject->className());
|
||||
targetObject = targetObject->prototype(lookupContext->context());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setEnabled(doc->isParsedCorrectly());
|
||||
setEnabled(document->isParsedCorrectly());
|
||||
m_editor = editor;
|
||||
contextWidget()->setParent(editor->widget()->parentWidget());
|
||||
contextWidget()->colorDialog()->setParent(editor->widget()->parentWidget());
|
||||
@@ -158,6 +157,8 @@ void QuickToolBar::apply(TextEditor::BaseTextEditorEditable *editor, LookupConte
|
||||
end = objectBinding->lastSourceLocation().end();
|
||||
}
|
||||
|
||||
m_prototypes.append(name);
|
||||
|
||||
int line1;
|
||||
int column1;
|
||||
int line2;
|
||||
@@ -175,9 +176,9 @@ void QuickToolBar::apply(TextEditor::BaseTextEditorEditable *editor, LookupConte
|
||||
rect.moveTo(reg.boundingRect().topLeft());
|
||||
reg = reg.intersect(rect);
|
||||
|
||||
if (contextWidget()->acceptsType(prototypes)) {
|
||||
if (contextWidget()->acceptsType(m_prototypes)) {
|
||||
m_node = 0;
|
||||
PropertyReader propertyReader(doc, initializer);
|
||||
PropertyReader propertyReader(document, initializer);
|
||||
QTextCursor tc(editor->editor()->document());
|
||||
tc.setPosition(offset);
|
||||
QPoint p1 = editor->editor()->mapToParent(editor->editor()->viewport()->mapToParent(editor->editor()->cursorRect(tc).topLeft()) - QPoint(0, contextWidget()->height() + 10));
|
||||
@@ -188,15 +189,15 @@ void QuickToolBar::apply(TextEditor::BaseTextEditorEditable *editor, LookupConte
|
||||
offset = QPoint(400 - reg.boundingRect().width() + 10 ,0);
|
||||
QPoint p3 = editor->editor()->mapToParent(editor->editor()->viewport()->mapToParent(reg.boundingRect().topRight()) + offset);
|
||||
p2.setX(p1.x());
|
||||
contextWidget()->setType(prototypes);
|
||||
contextWidget()->setType(m_prototypes);
|
||||
if (!update)
|
||||
contextWidget()->activate(p3 , p1, p2, QuickToolBarSettings::get().pinContextPane);
|
||||
else
|
||||
contextWidget()->rePosition(p3 , p1, p2, QuickToolBarSettings::get().pinContextPane);
|
||||
contextWidget()->setOptions(QuickToolBarSettings::get().enableContextPane, QuickToolBarSettings::get().pinContextPane);
|
||||
contextWidget()->setPath(doc->path());
|
||||
contextWidget()->setPath(document->path());
|
||||
contextWidget()->setProperties(&propertyReader);
|
||||
m_doc = doc;
|
||||
m_doc = document;
|
||||
m_node = node;
|
||||
} else {
|
||||
contextWidget()->setParent(0);
|
||||
@@ -213,34 +214,27 @@ void QuickToolBar::apply(TextEditor::BaseTextEditorEditable *editor, LookupConte
|
||||
|
||||
}
|
||||
|
||||
bool QuickToolBar::isAvailable(TextEditor::BaseTextEditorEditable *, LookupContext::Ptr lookupContext, AST::Node *node)
|
||||
bool QuickToolBar::isAvailable(TextEditor::BaseTextEditorEditable *editor, Document::Ptr document, AST::Node *node)
|
||||
{
|
||||
if (lookupContext.isNull())
|
||||
return false;
|
||||
Document::Ptr doc = lookupContext->document();
|
||||
if (doc.isNull())
|
||||
if (document.isNull())
|
||||
return false;
|
||||
|
||||
if (!node)
|
||||
return false;
|
||||
|
||||
const Interpreter::ObjectValue *scopeObject = doc->bind()->findQmlObject(node);
|
||||
QString name;
|
||||
|
||||
UiObjectDefinition *objectDefinition = cast<UiObjectDefinition*>(node);
|
||||
UiObjectBinding *objectBinding = cast<UiObjectBinding*>(node);
|
||||
if (objectDefinition) {
|
||||
name = objectDefinition->qualifiedTypeNameId->name->asString();
|
||||
|
||||
} else if (objectBinding) {
|
||||
name = objectBinding->qualifiedTypeNameId->name->asString();
|
||||
}
|
||||
|
||||
QStringList prototypes;
|
||||
|
||||
while (scopeObject) {
|
||||
prototypes.append(scopeObject->className());
|
||||
scopeObject = scopeObject->prototype(lookupContext->context());
|
||||
}
|
||||
|
||||
if (prototypes.contains("PropertyChanges")) {
|
||||
const Interpreter::ObjectValue *targetObject = getPropertyChangesTarget(node, lookupContext);
|
||||
prototypes.clear();
|
||||
while (targetObject) {
|
||||
prototypes.append(targetObject->className());
|
||||
targetObject = targetObject->prototype(lookupContext->context());
|
||||
}
|
||||
}
|
||||
prototypes.append(name);
|
||||
|
||||
if (prototypes.contains("Rectangle") ||
|
||||
prototypes.contains("Image") ||
|
||||
@@ -248,7 +242,9 @@ bool QuickToolBar::isAvailable(TextEditor::BaseTextEditorEditable *, LookupConte
|
||||
prototypes.contains("TextEdit") ||
|
||||
prototypes.contains("TextInput") ||
|
||||
prototypes.contains("PropertyAnimation") ||
|
||||
prototypes.contains("Text"))
|
||||
prototypes.contains("NumberAnimation") ||
|
||||
prototypes.contains("Text") ||
|
||||
prototypes.contains("PropertyChanges"))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@@ -30,8 +30,8 @@ class QuickToolBar : public QmlJS::IContextPane
|
||||
public:
|
||||
QuickToolBar(QObject *parent = 0);
|
||||
~QuickToolBar();
|
||||
void apply(TextEditor::BaseTextEditorEditable *editor, QmlJS::LookupContext::Ptr lookupContext, QmlJS::AST::Node *node, bool update, bool force = 0);
|
||||
bool isAvailable(TextEditor::BaseTextEditorEditable *editor, QmlJS::LookupContext::Ptr lookupContext, QmlJS::AST::Node *node);
|
||||
void apply(TextEditor::BaseTextEditorEditable *editor, QmlJS::Document::Ptr document, QmlJS::LookupContext::Ptr lookupContext, QmlJS::AST::Node *node, bool update, bool force = false);
|
||||
bool isAvailable(TextEditor::BaseTextEditorEditable *editor, QmlJS::Document::Ptr document, QmlJS::AST::Node *node);
|
||||
void setProperty(const QString &propertyName, const QVariant &value);
|
||||
void removeProperty(const QString &propertyName);
|
||||
void setEnabled(bool);
|
||||
@@ -52,6 +52,7 @@ private:
|
||||
TextEditor::BaseTextEditorEditable *m_editor;
|
||||
bool m_blockWriting;
|
||||
QStringList m_propertyOrder;
|
||||
QStringList m_prototypes;
|
||||
};
|
||||
|
||||
} //QmlDesigner
|
||||
|
Reference in New Issue
Block a user