forked from qt-creator/qt-creator
CppEditor: Support sorting of outline
Change-Id: Icf31991327800dbcb2c5c2e8076011dfa85d6f2a Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -101,7 +101,8 @@ CppOutlineWidget::CppOutlineWidget(CppEditorWidget *editor) :
|
||||
m_editor(editor),
|
||||
m_treeView(new CppOutlineTreeView(this)),
|
||||
m_enableCursorSync(true),
|
||||
m_blockCursorSync(false)
|
||||
m_blockCursorSync(false),
|
||||
m_sorted(false)
|
||||
{
|
||||
CppTools::AbstractOverviewModel *model = m_editor->outline()->model();
|
||||
m_proxyModel = new CppOutlineFilterModel(*model, this);
|
||||
@@ -114,6 +115,7 @@ CppOutlineWidget::CppOutlineWidget(CppEditorWidget *editor) :
|
||||
setLayout(layout);
|
||||
|
||||
m_treeView->setModel(m_proxyModel);
|
||||
m_treeView->setSortingEnabled(true);
|
||||
setFocusProxy(m_treeView);
|
||||
|
||||
connect(model, &QAbstractItemModel::modelReset, this, &CppOutlineWidget::modelUpdated);
|
||||
@@ -137,6 +139,27 @@ void CppOutlineWidget::setCursorSynchronization(bool syncWithCursor)
|
||||
updateSelectionInTree(m_editor->outline()->modelIndex());
|
||||
}
|
||||
|
||||
bool CppOutlineWidget::isSorted() const
|
||||
{
|
||||
return m_sorted;
|
||||
}
|
||||
|
||||
void CppOutlineWidget::setSorted(bool sorted)
|
||||
{
|
||||
m_sorted = sorted;
|
||||
m_proxyModel->sort(m_sorted ? 0 : -1);
|
||||
}
|
||||
|
||||
void CppOutlineWidget::restoreSettings(const QVariantMap &map)
|
||||
{
|
||||
setSorted(map.value(QString("CppOutline.Sort"), false).toBool());
|
||||
}
|
||||
|
||||
QVariantMap CppOutlineWidget::settings() const
|
||||
{
|
||||
return {{QString("CppOutline.Sort"), m_sorted}};
|
||||
}
|
||||
|
||||
void CppOutlineWidget::modelUpdated()
|
||||
{
|
||||
m_treeView->expandAll();
|
||||
|
@@ -68,7 +68,11 @@ public:
|
||||
// IOutlineWidget
|
||||
QList<QAction*> filterMenuActions() const override;
|
||||
void setCursorSynchronization(bool syncWithCursor) override;
|
||||
bool isSorted() const override;
|
||||
void setSorted(bool sorted) override;
|
||||
|
||||
void restoreSettings(const QVariantMap &map) override;
|
||||
QVariantMap settings() const override;
|
||||
private:
|
||||
void modelUpdated();
|
||||
void updateSelectionInTree(const QModelIndex &index);
|
||||
@@ -83,6 +87,7 @@ private:
|
||||
|
||||
bool m_enableCursorSync;
|
||||
bool m_blockCursorSync;
|
||||
bool m_sorted;
|
||||
};
|
||||
|
||||
class CppOutlineWidgetFactory : public TextEditor::IOutlineWidgetFactory
|
||||
@@ -90,6 +95,7 @@ class CppOutlineWidgetFactory : public TextEditor::IOutlineWidgetFactory
|
||||
Q_OBJECT
|
||||
public:
|
||||
bool supportsEditor(Core::IEditor *editor) const override;
|
||||
bool supportsSorting() const override { return true; }
|
||||
TextEditor::IOutlineWidget *createWidget(Core::IEditor *editor) override;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user