summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhjk <hjk121@nokiamail.com>2014-09-01 12:54:03 +0200
committerhjk <hjk121@nokiamail.com>2014-09-01 15:34:16 +0200
commitc587f0b241efed7ea9d301aedb3fddbc3afbb3d9 (patch)
tree83466d9fc9994af20f9af3ea60eaab79cf04263b
parenta59fdc8096061f5feee2d5d4ff7ae1d9fd2fc723 (diff)
downloadqt-creator-c587f0b241efed7ea9d301aedb3fddbc3afbb3d9.tar.gz
QmlJSEditor: Use EditorWidget instead of Editor in QuickToolBar
This reduces the use of the 'editor()' "back link" which we'd like to phase out (and also actually simplifies the user code). Change-Id: I8aa13e88459d4e9cf44de683e8efd189238cc684 Reviewed-by: Christian Stenger <christian.stenger@digia.com> Reviewed-by: Fawzi Mohamed <fawzi.mohamed@digia.com>
-rw-r--r--src/libs/qmljs/qmljsicontextpane.h6
-rw-r--r--src/plugins/qmljseditor/qmljseditor.cpp16
-rw-r--r--src/plugins/qmljseditor/quicktoolbar.cpp45
-rw-r--r--src/plugins/qmljseditor/quicktoolbar.h8
4 files changed, 36 insertions, 39 deletions
diff --git a/src/libs/qmljs/qmljsicontextpane.h b/src/libs/qmljs/qmljsicontextpane.h
index 8f9cd7271a..1f32cc1c12 100644
--- a/src/libs/qmljs/qmljsicontextpane.h
+++ b/src/libs/qmljs/qmljsicontextpane.h
@@ -37,7 +37,7 @@
#include <qmljs/qmljsdocument.h>
#include <qmljs/parser/qmljsastfwd_p.h>
-namespace TextEditor { class BaseTextEditor; }
+namespace TextEditor { class BaseTextEditorWidget; }
namespace QmlJS {
@@ -50,9 +50,9 @@ class QMLJS_EXPORT IContextPane : public QObject
public:
IContextPane(QObject *parent = 0) : QObject(parent) {}
virtual ~IContextPane() {}
- virtual void apply(TextEditor::BaseTextEditor *editor, Document::Ptr document, const ScopeChain *scopeChain, AST::Node *node, bool update, bool force = false) = 0;
+ virtual void apply(TextEditor::BaseTextEditorWidget *editorWidget, Document::Ptr document, const ScopeChain *scopeChain, AST::Node *node, bool update, bool force = false) = 0;
virtual void setEnabled(bool) = 0;
- virtual bool isAvailable(TextEditor::BaseTextEditor *editor, Document::Ptr document, AST::Node *node) = 0;
+ virtual bool isAvailable(TextEditor::BaseTextEditorWidget *editorWidget, Document::Ptr document, AST::Node *node) = 0;
virtual QWidget* widget() = 0;
signals:
void closed();
diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp
index 75bed88a6b..084b9e9644 100644
--- a/src/plugins/qmljseditor/qmljseditor.cpp
+++ b/src/plugins/qmljseditor/qmljseditor.cpp
@@ -306,9 +306,9 @@ void QmlJSEditorWidget::updateContextPane()
Node *oldNode = info.declaringMemberNoProperties(m_oldCursorPosition);
Node *newNode = info.declaringMemberNoProperties(position());
if (oldNode != newNode && m_oldCursorPosition != -1)
- m_contextPane->apply(editor(), info.document, 0, newNode, false);
+ m_contextPane->apply(this, info.document, 0, newNode, false);
- if (m_contextPane->isAvailable(editor(), info.document, newNode) &&
+ if (m_contextPane->isAvailable(this, info.document, newNode) &&
!m_contextPane->widget()->isVisible()) {
QList<RefactorMarker> markers = removeMarkersOfType<QtQuickToolbarMarker>(refactorMarkers());
if (UiObjectMember *m = newNode->uiObjectMemberCast()) {
@@ -663,7 +663,7 @@ void QmlJSEditorWidget::showContextPane()
if (m_contextPane && info.isValid()) {
Node *newNode = info.declaringMemberNoProperties(position());
ScopeChain scopeChain = info.scopeChain(info.rangePath(position()));
- m_contextPane->apply(editor(), info.document,
+ m_contextPane->apply(this, info.document,
&scopeChain,
newNode, false, true);
m_oldCursorPosition = position();
@@ -716,7 +716,7 @@ void QmlJSEditorWidget::contextMenuEvent(QContextMenuEvent *e)
menu->addMenu(refactoringMenu);
if (action->objectName() == QLatin1String(Constants::SHOW_QT_QUICK_HELPER)) {
bool enabled = m_contextPane->isAvailable(
- editor(), m_qmlJsEditorDocument->semanticInfo().document,
+ this, m_qmlJsEditorDocument->semanticInfo().document,
m_qmlJsEditorDocument->semanticInfo().declaringMemberNoProperties(position()));
action->setEnabled(enabled);
}
@@ -760,7 +760,7 @@ void QmlJSEditorWidget::wheelEvent(QWheelEvent *event)
BaseTextEditorWidget::wheelEvent(event);
if (visible)
- m_contextPane->apply(editor(), m_qmlJsEditorDocument->semanticInfo().document, 0,
+ m_contextPane->apply(this, m_qmlJsEditorDocument->semanticInfo().document, 0,
m_qmlJsEditorDocument->semanticInfo().declaringMemberNoProperties(m_oldCursorPosition),
false, true);
}
@@ -792,7 +792,7 @@ void QmlJSEditorWidget::semanticInfoUpdated(const SemanticInfo &semanticInfo)
if (m_contextPane) {
Node *newNode = semanticInfo.declaringMemberNoProperties(position());
if (newNode) {
- m_contextPane->apply(editor(), semanticInfo.document, 0, newNode, true);
+ m_contextPane->apply(this, semanticInfo.document, 0, newNode, true);
m_contextPaneTimer.start(); //update text marker
}
}
@@ -834,7 +834,7 @@ bool QmlJSEditorWidget::hideContextPane()
{
bool b = (m_contextPane) && m_contextPane->widget()->isVisible();
if (b)
- m_contextPane->apply(editor(), m_qmlJsEditorDocument->semanticInfo().document, 0, 0, false);
+ m_contextPane->apply(this, m_qmlJsEditorDocument->semanticInfo().document, 0, 0, false);
return b;
}
@@ -845,7 +845,7 @@ IAssistInterface *QmlJSEditorWidget::createAssistInterface(
if (assistKind == TextEditor::Completion) {
return new QmlJSCompletionAssistInterface(document(),
position(),
- editor()->document()->filePath(),
+ textDocument()->filePath(),
reason,
m_qmlJsEditorDocument->semanticInfo());
} else if (assistKind == TextEditor::QuickFix) {
diff --git a/src/plugins/qmljseditor/quicktoolbar.cpp b/src/plugins/qmljseditor/quicktoolbar.cpp
index f4a39733c0..45d13bb49e 100644
--- a/src/plugins/qmljseditor/quicktoolbar.cpp
+++ b/src/plugins/qmljseditor/quicktoolbar.cpp
@@ -79,7 +79,7 @@ static inline const ObjectValue * getPropertyChangesTarget(Node *node, const Sco
QuickToolBar::QuickToolBar(QObject *parent)
: ::QmlJS::IContextPane(parent)
- , m_editor(0)
+ , m_editorWidget(0)
, m_blockWriting(false)
{
m_node = 0;
@@ -115,7 +115,7 @@ QuickToolBar::~QuickToolBar()
m_widget = 0;
}
-void QuickToolBar::apply(TextEditor::BaseTextEditor *editor, Document::Ptr document, const ScopeChain *scopeChain, AST::Node *node, bool update, bool force)
+void QuickToolBar::apply(TextEditor::BaseTextEditorWidget *editorWidget, Document::Ptr document, const ScopeChain *scopeChain, AST::Node *node, bool update, bool force)
{
if (!QuickToolBarSettings::get().enableContextPane && !force && !update) {
contextWidget()->hide();
@@ -125,7 +125,7 @@ void QuickToolBar::apply(TextEditor::BaseTextEditor *editor, Document::Ptr docum
if (document.isNull())
return;
- if (update && editor != m_editor)
+ if (update && editorWidget != m_editorWidget)
return; //do not update for different editor
m_blockWriting = true;
@@ -155,9 +155,9 @@ void QuickToolBar::apply(TextEditor::BaseTextEditor *editor, Document::Ptr docum
}
setEnabled(document->isParsedCorrectly());
- m_editor = editor;
- contextWidget()->setParent(editor->widget()->parentWidget());
- contextWidget()->colorDialog()->setParent(editor->widget()->parentWidget());
+ m_editorWidget = editorWidget;
+ contextWidget()->setParent(editorWidget->parentWidget());
+ contextWidget()->colorDialog()->setParent(editorWidget->parentWidget());
if (cast<UiObjectDefinition*>(node) || cast<UiObjectBinding*>(node)) {
UiObjectDefinition *objectDefinition = cast<UiObjectDefinition*>(node);
@@ -192,12 +192,12 @@ void QuickToolBar::apply(TextEditor::BaseTextEditor *editor, Document::Ptr docum
int column1;
int line2;
int column2;
- m_editor->convertPosition(offset, &line1, &column1); //get line
- m_editor->convertPosition(end, &line2, &column2); //get line
+ m_editorWidget->convertPosition(offset, &line1, &column1); //get line
+ m_editorWidget->convertPosition(end, &line2, &column2); //get line
QRegion reg;
if (line1 > -1 && line2 > -1)
- reg = m_editor->editorWidget()->translatedLineRegion(line1 - 1, line2);
+ reg = m_editorWidget->translatedLineRegion(line1 - 1, line2);
QRect rect;
rect.setHeight(widget()->height() + 10);
@@ -208,16 +208,15 @@ void QuickToolBar::apply(TextEditor::BaseTextEditor *editor, Document::Ptr docum
if (contextWidget()->acceptsType(m_prototypes)) {
m_node = 0;
PropertyReader propertyReader(document, initializer);
- QTextCursor tc = editor->textCursor();
- QPlainTextEdit *editorWidget = editor->editorWidget();
+ QTextCursor tc = m_editorWidget->textCursor();
tc.setPosition(offset);
- QPoint p1 = editorWidget->mapToParent(editorWidget->viewport()->mapToParent(editorWidget->cursorRect(tc).topLeft()) - QPoint(0, contextWidget()->height() + 10));
+ QPoint p1 = m_editorWidget->mapToParent(m_editorWidget->viewport()->mapToParent(m_editorWidget->cursorRect(tc).topLeft()) - QPoint(0, contextWidget()->height() + 10));
tc.setPosition(end);
- QPoint p2 = editorWidget->mapToParent(editorWidget->viewport()->mapToParent(editorWidget->cursorRect(tc).bottomLeft()) + QPoint(0, 10));
+ QPoint p2 = m_editorWidget->mapToParent(m_editorWidget->viewport()->mapToParent(m_editorWidget->cursorRect(tc).bottomLeft()) + QPoint(0, 10));
QPoint offset = QPoint(10, 0);
if (reg.boundingRect().width() < 400)
offset = QPoint(400 - reg.boundingRect().width() + 10 ,0);
- QPoint p3 = editorWidget->mapToParent(editorWidget->viewport()->mapToParent(reg.boundingRect().topRight()) + offset);
+ QPoint p3 = m_editorWidget->mapToParent(m_editorWidget->viewport()->mapToParent(reg.boundingRect().topRight()) + offset);
p2.setX(p1.x());
contextWidget()->setIsPropertyChanges(isPropertyChanges);
if (!update)
@@ -246,7 +245,7 @@ void QuickToolBar::apply(TextEditor::BaseTextEditor *editor, Document::Ptr docum
}
-bool QuickToolBar::isAvailable(TextEditor::BaseTextEditor *, Document::Ptr document, AST::Node *node)
+bool QuickToolBar::isAvailable(TextEditor::BaseTextEditorWidget *, Document::Ptr document, AST::Node *node)
{
if (document.isNull())
return false;
@@ -319,12 +318,12 @@ void QuickToolBar::setProperty(const QString &propertyName, const QVariant &valu
int changeSetPos = changeSet.operationList().last().pos1;
int changeSetLength = changeSet.operationList().last().text.length();
- QTextCursor tc = m_editor->editorWidget()->textCursor();
+ QTextCursor tc = m_editorWidget->textCursor();
tc.beginEditBlock();
changeSet.apply(&tc);
- m_editor->convertPosition(changeSetPos, &line, &column); //get line
- m_editor->convertPosition(changeSetPos + changeSetLength, &endLine, &column); //get line
+ m_editorWidget->convertPosition(changeSetPos, &line, &column); //get line
+ m_editorWidget->convertPosition(changeSetPos + changeSetLength, &endLine, &column); //get line
indentLines(line, endLine);
tc.endEditBlock();
@@ -348,7 +347,7 @@ void QuickToolBar::removeProperty(const QString &propertyName)
Utils::ChangeSet changeSet;
Rewriter rewriter(m_doc->source(), &changeSet, m_propertyOrder);
rewriter.removeBindingByName(initializer, propertyName);
- QTextCursor tc(m_editor->editorWidget()->document());
+ QTextCursor tc(m_editorWidget->document());
changeSet.apply(&tc);
}
}
@@ -388,7 +387,7 @@ void QuickToolBar::onPropertyRemovedAndChange(const QString &remove, const QStri
if (!m_doc)
return;
- QTextCursor tc = m_editor->textCursor();
+ QTextCursor tc = m_editorWidget->textCursor();
tc.beginEditBlock();
if (removeFirst) {
@@ -424,13 +423,13 @@ void QuickToolBar::onEnabledChanged(bool b)
void QuickToolBar::indentLines(int startLine, int endLine)
{
if (startLine > 0) {
- TextEditor::TabSettings tabSettings = m_editor->textDocument()->tabSettings();
+ TextEditor::TabSettings tabSettings = m_editorWidget->textDocument()->tabSettings();
for (int i = startLine; i <= endLine; i++) {
- QTextBlock start = m_editor->qdocument()->findBlockByNumber(i);
+ QTextBlock start = m_editorWidget->document()->findBlockByNumber(i);
if (start.isValid()) {
QmlJSEditor::Internal::Indenter indenterMy;
- indenterMy.indentBlock(m_editor->qdocument(), start, QChar::Null, tabSettings);
+ indenterMy.indentBlock(m_editorWidget->document(), start, QChar::Null, tabSettings);
}
}
}
diff --git a/src/plugins/qmljseditor/quicktoolbar.h b/src/plugins/qmljseditor/quicktoolbar.h
index 46e10abb81..38c28d73ad 100644
--- a/src/plugins/qmljseditor/quicktoolbar.h
+++ b/src/plugins/qmljseditor/quicktoolbar.h
@@ -34,8 +34,6 @@
#include <QPointer>
-namespace TextEditor { class BaseTextEditor; }
-
namespace QmlEditorWidgets { class ContextPaneWidget; }
namespace QmlJSEditor {
@@ -47,8 +45,8 @@ class QuickToolBar : public QmlJS::IContextPane
public:
QuickToolBar(QObject *parent = 0);
~QuickToolBar();
- void apply(TextEditor::BaseTextEditor *editor, QmlJS::Document::Ptr document, const QmlJS::ScopeChain *scopeChain, QmlJS::AST::Node *node, bool update, bool force = false);
- bool isAvailable(TextEditor::BaseTextEditor *editor, QmlJS::Document::Ptr document, QmlJS::AST::Node *node);
+ void apply(TextEditor::BaseTextEditorWidget *widget, QmlJS::Document::Ptr document, const QmlJS::ScopeChain *scopeChain, QmlJS::AST::Node *node, bool update, bool force = false);
+ bool isAvailable(TextEditor::BaseTextEditorWidget *widget, QmlJS::Document::Ptr document, QmlJS::AST::Node *node);
void setProperty(const QString &propertyName, const QVariant &value);
void removeProperty(const QString &propertyName);
void setEnabled(bool);
@@ -68,7 +66,7 @@ private:
QPointer<QmlEditorWidgets::ContextPaneWidget> m_widget;
QmlJS::Document::Ptr m_doc;
QmlJS::AST::Node *m_node;
- TextEditor::BaseTextEditor *m_editor;
+ TextEditor::BaseTextEditorWidget *m_editorWidget;
bool m_blockWriting;
QStringList m_propertyOrder;
QStringList m_prototypes;