QmlJSEditor: cleanup updateOutlineIndexNow

It was called to often - it was already connected in setEditor method.
Change outlineModelIndex() to be just a getter and call the
updateOutlineIndexNow() where an update is necessary.

Change-Id: I6f30bfaff74237416c1aef5418860179c1f8ebf7
Reviewed-by: Marco Benelli <marco.benelli@qt.io>
This commit is contained in:
Tim Jenssen
2017-04-06 17:22:52 +02:00
committed by Robert Loehning
parent 2c1c51bbea
commit c643095f17
3 changed files with 5 additions and 7 deletions

View File

@@ -157,7 +157,6 @@ QModelIndex QmlJSEditorWidget::outlineModelIndex()
{ {
if (!m_outlineModelIndex.isValid()) { if (!m_outlineModelIndex.isValid()) {
m_outlineModelIndex = indexForPosition(position()); m_outlineModelIndex = indexForPosition(position());
emit outlineModelIndexChanged(m_outlineModelIndex);
} }
return m_outlineModelIndex; return m_outlineModelIndex;
} }
@@ -249,6 +248,7 @@ void QmlJSEditorWidget::updateOutlineIndexNow()
m_outlineModelIndex = QModelIndex(); // invalidate m_outlineModelIndex = QModelIndex(); // invalidate
QModelIndex comboIndex = outlineModelIndex(); QModelIndex comboIndex = outlineModelIndex();
emit outlineModelIndexChanged(m_outlineModelIndex);
if (comboIndex.isValid()) { if (comboIndex.isValid()) {
bool blocked = m_outlineCombo->blockSignals(true); bool blocked = m_outlineCombo->blockSignals(true);
@@ -530,8 +530,6 @@ void QmlJSEditorWidget::createToolBar()
this, &QmlJSEditorWidget::jumpToOutlineElement); this, &QmlJSEditorWidget::jumpToOutlineElement);
connect(m_qmlJsEditorDocument->outlineModel(), &QmlOutlineModel::updated, connect(m_qmlJsEditorDocument->outlineModel(), &QmlOutlineModel::updated,
static_cast<QTreeView *>(m_outlineCombo->view()), &QTreeView::expandAll); static_cast<QTreeView *>(m_outlineCombo->view()), &QTreeView::expandAll);
connect(m_qmlJsEditorDocument->outlineModel(), &QmlOutlineModel::updated,
this, &QmlJSEditorWidget::updateOutlineIndexNow);
connect(this, &QmlJSEditorWidget::cursorPositionChanged, connect(this, &QmlJSEditorWidget::cursorPositionChanged,
&m_updateOutlineIndexTimer, static_cast<void (QTimer::*)()>(&QTimer::start)); &m_updateOutlineIndexTimer, static_cast<void (QTimer::*)()>(&QTimer::start));

View File

@@ -66,6 +66,7 @@ public:
QmlJSEditorDocument *qmlJsEditorDocument() const; QmlJSEditorDocument *qmlJsEditorDocument() const;
QModelIndex outlineModelIndex(); QModelIndex outlineModelIndex();
void updateOutlineIndexNow();
TextEditor::AssistInterface *createAssistInterface(TextEditor::AssistKind assistKind, TextEditor::AssistInterface *createAssistInterface(TextEditor::AssistKind assistKind,
TextEditor::AssistReason reason) const override; TextEditor::AssistReason reason) const override;
@@ -84,7 +85,6 @@ private:
void modificationChanged(bool); void modificationChanged(bool);
void jumpToOutlineElement(int index); void jumpToOutlineElement(int index);
void updateOutlineIndexNow();
void updateContextPane(); void updateContextPane();
void showTextMarker(); void showTextMarker();

View File

@@ -136,6 +136,7 @@ void QmlJSOutlineWidget::setEditor(QmlJSEditorWidget *editor)
this, &QmlJSOutlineWidget::updateSelectionInTree); this, &QmlJSOutlineWidget::updateSelectionInTree);
connect(m_editor->qmlJsEditorDocument()->outlineModel(), &QmlOutlineModel::updated, [this] () { connect(m_editor->qmlJsEditorDocument()->outlineModel(), &QmlOutlineModel::updated, [this] () {
m_treeView->expandAll(); m_treeView->expandAll();
m_editor->updateOutlineIndexNow();
}); });
} }
@@ -147,8 +148,7 @@ QList<QAction*> QmlJSOutlineWidget::filterMenuActions() const
void QmlJSOutlineWidget::setCursorSynchronization(bool syncWithCursor) void QmlJSOutlineWidget::setCursorSynchronization(bool syncWithCursor)
{ {
m_enableCursorSync = syncWithCursor; m_enableCursorSync = syncWithCursor;
if (m_enableCursorSync) m_editor->updateOutlineIndexNow();
updateSelectionInTree(m_editor->outlineModelIndex());
} }
void QmlJSOutlineWidget::restoreSettings(const QVariantMap &map) void QmlJSOutlineWidget::restoreSettings(const QVariantMap &map)
@@ -227,7 +227,7 @@ void QmlJSOutlineWidget::setShowBindings(bool showBindings)
{ {
m_filterModel->setFilterBindings(!showBindings); m_filterModel->setFilterBindings(!showBindings);
m_treeView->expandAll(); m_treeView->expandAll();
updateSelectionInTree(m_editor->outlineModelIndex()); m_editor->updateOutlineIndexNow();
} }
bool QmlJSOutlineWidget::syncCursor() bool QmlJSOutlineWidget::syncCursor()