forked from qt-creator/qt-creator
Outline: Make recalculation of current model index more robust
This commit is contained in:
@@ -832,6 +832,7 @@ void CPPEditor::onDocumentUpdated(Document::Ptr doc)
|
||||
}
|
||||
|
||||
m_overviewModel->rebuild(doc);
|
||||
|
||||
OverviewTreeView *treeView = static_cast<OverviewTreeView *>(m_methodCombo->view());
|
||||
treeView->sync();
|
||||
updateMethodBoxIndexNow();
|
||||
@@ -1092,14 +1093,9 @@ void CPPEditor::updateMethodBoxIndexNow()
|
||||
|
||||
m_updateMethodBoxTimer->stop();
|
||||
|
||||
int line = 0, column = 0;
|
||||
convertPosition(position(), &line, &column);
|
||||
|
||||
QModelIndex overviewModelIndex = indexForPosition(line, column);
|
||||
emit overviewModelIndexChanged(overviewModelIndex);
|
||||
|
||||
m_overviewModelIndex = QModelIndex(); //invalidate
|
||||
// ComboBox only let's you select top level indexes!
|
||||
QModelIndex comboIndex = overviewModelIndex;
|
||||
QModelIndex comboIndex = overviewModelIndex();
|
||||
while (comboIndex.parent().isValid())
|
||||
comboIndex = comboIndex.parent();
|
||||
|
||||
@@ -1444,8 +1440,15 @@ CPlusPlus::OverviewModel *CPPEditor::overviewModel() const
|
||||
return m_overviewModel;
|
||||
}
|
||||
|
||||
QModelIndex CPPEditor::overviewModelIndex() const
|
||||
QModelIndex CPPEditor::overviewModelIndex()
|
||||
{
|
||||
if (!m_overviewModelIndex.isValid()) {
|
||||
int line = 0, column = 0;
|
||||
convertPosition(position(), &line, &column);
|
||||
m_overviewModelIndex = indexForPosition(line, column);
|
||||
emit overviewModelIndexChanged(m_overviewModelIndex);
|
||||
}
|
||||
|
||||
return m_overviewModelIndex;
|
||||
}
|
||||
|
||||
@@ -2194,7 +2197,7 @@ SemanticInfo SemanticHighlighter::semanticInfo(const Source &source)
|
||||
return semanticInfo;
|
||||
}
|
||||
|
||||
QModelIndex CPPEditor::indexForPosition(int line, int column, const QModelIndex &rootIndex)
|
||||
QModelIndex CPPEditor::indexForPosition(int line, int column, const QModelIndex &rootIndex) const
|
||||
{
|
||||
QModelIndex lastIndex = rootIndex;
|
||||
|
||||
|
||||
@@ -168,7 +168,7 @@ public:
|
||||
SemanticInfo semanticInfo() const;
|
||||
|
||||
CPlusPlus::OverviewModel *overviewModel() const;
|
||||
QModelIndex overviewModelIndex() const;
|
||||
QModelIndex overviewModelIndex();
|
||||
|
||||
virtual void paste(); // reimplemented from BaseTextEditor
|
||||
virtual void cut(); // reimplemented from BaseTextEditor
|
||||
@@ -265,7 +265,7 @@ private:
|
||||
bool openLink(const Link &link) { return openCppEditorAt(link); }
|
||||
bool openCppEditorAt(const Link &);
|
||||
|
||||
QModelIndex indexForPosition(int line, int column, const QModelIndex &rootIndex = QModelIndex());
|
||||
QModelIndex indexForPosition(int line, int column, const QModelIndex &rootIndex = QModelIndex()) const;
|
||||
|
||||
static Link linkToSymbol(CPlusPlus::Symbol *symbol);
|
||||
|
||||
|
||||
@@ -90,7 +90,6 @@ void CppOutlineWidget::setCursorSynchronization(bool syncWithCursor)
|
||||
void CppOutlineWidget::modelUpdated()
|
||||
{
|
||||
m_treeView->expandAll();
|
||||
updateSelectionInTree(m_editor->overviewModelIndex());
|
||||
}
|
||||
|
||||
void CppOutlineWidget::updateSelectionInTree(const QModelIndex &index)
|
||||
|
||||
@@ -697,8 +697,12 @@ QmlOutlineModel *QmlJSTextEditor::outlineModel() const
|
||||
return m_outlineModel;
|
||||
}
|
||||
|
||||
QModelIndex QmlJSTextEditor::outlineModelIndex() const
|
||||
QModelIndex QmlJSTextEditor::outlineModelIndex()
|
||||
{
|
||||
if (!m_outlineModelIndex.isValid()) {
|
||||
m_outlineModelIndex = indexForPosition(position());
|
||||
emit outlineModelIndexChanged(m_outlineModelIndex);
|
||||
}
|
||||
return m_outlineModelIndex;
|
||||
}
|
||||
|
||||
@@ -822,10 +826,8 @@ void QmlJSTextEditor::jumpToMethod(int /*index*/)
|
||||
|
||||
void QmlJSTextEditor::updateMethodBoxIndex()
|
||||
{
|
||||
m_outlineModelIndex = indexForPosition(position());
|
||||
emit outlineModelIndexChanged(m_outlineModelIndex);
|
||||
|
||||
QModelIndex comboIndex = m_outlineModelIndex;
|
||||
m_outlineModelIndex = QModelIndex(); // invalidate
|
||||
QModelIndex comboIndex = outlineModelIndex();
|
||||
|
||||
if (comboIndex.isValid()) {
|
||||
bool blocked = m_methodCombo->blockSignals(true);
|
||||
@@ -1364,8 +1366,6 @@ void QmlJSTextEditor::updateSemanticInfo(const SemanticInfo &semanticInfo)
|
||||
|
||||
QTreeView *treeView = static_cast<QTreeView*>(m_methodCombo->view());
|
||||
treeView->expandAll();
|
||||
// ComboBox only let's you select top level indexes for a QAbstractItemModel!
|
||||
// therefore we've to fake a treeview by listview + indentation
|
||||
|
||||
if (m_contextPane) {
|
||||
Node *newNode = m_semanticInfo.declaringMember(position());
|
||||
@@ -1542,3 +1542,4 @@ void SemanticHighlighter::setModelManager(QmlJS::ModelManagerInterface *modelMan
|
||||
{
|
||||
m_modelManager = modelManager;
|
||||
}
|
||||
|
||||
|
||||
@@ -217,7 +217,7 @@ public:
|
||||
bool isOutdated() const;
|
||||
|
||||
QmlOutlineModel *outlineModel() const;
|
||||
QModelIndex outlineModelIndex() const;
|
||||
QModelIndex outlineModelIndex();
|
||||
|
||||
public slots:
|
||||
void followSymbolUnderCursor();
|
||||
|
||||
@@ -67,7 +67,6 @@ void QmlJSOutlineWidget::setCursorSynchronization(bool syncWithCursor)
|
||||
void QmlJSOutlineWidget::modelUpdated()
|
||||
{
|
||||
m_treeView->expandAll();
|
||||
updateSelectionInTree(m_editor.data()->outlineModelIndex());
|
||||
}
|
||||
|
||||
void QmlJSOutlineWidget::updateSelectionInTree(const QModelIndex &index)
|
||||
|
||||
Reference in New Issue
Block a user