forked from qt-creator/qt-creator
QmlJSEditor: Support sorting of outline
Change-Id: Ia73f7007c22fd19e9f387084ad7a67bd47173095 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
@@ -53,6 +53,14 @@ QmlJSOutlineFilterModel::QmlJSOutlineFilterModel(QObject *parent) :
|
||||
setDynamicSortFilter(true);
|
||||
}
|
||||
|
||||
Qt::ItemFlags QmlJSOutlineFilterModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
Qt::ItemFlags f = sourceModel()->flags(index);
|
||||
if (m_sorted)
|
||||
f.setFlag(Qt::ItemIsDropEnabled, false);
|
||||
return f;
|
||||
}
|
||||
|
||||
bool QmlJSOutlineFilterModel::filterAcceptsRow(int sourceRow,
|
||||
const QModelIndex &sourceParent) const
|
||||
{
|
||||
@@ -65,6 +73,15 @@ bool QmlJSOutlineFilterModel::filterAcceptsRow(int sourceRow,
|
||||
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
|
||||
}
|
||||
|
||||
bool QmlJSOutlineFilterModel::lessThan(const QModelIndex &sourceLeft,
|
||||
const QModelIndex &sourceRight) const
|
||||
{
|
||||
if (!m_sorted)
|
||||
return sourceLeft.row() > sourceRight.row();
|
||||
|
||||
return sourceLeft.data().toString() > sourceRight.data().toString();
|
||||
}
|
||||
|
||||
QVariant QmlJSOutlineFilterModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role == QmlOutlineModel::AnnotationRole) {
|
||||
@@ -93,6 +110,12 @@ void QmlJSOutlineFilterModel::setFilterBindings(bool filterBindings)
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
void QmlJSOutlineFilterModel::setSorted(bool sorted)
|
||||
{
|
||||
m_sorted = sorted;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
QmlJSOutlineWidget::QmlJSOutlineWidget(QWidget *parent)
|
||||
: TextEditor::IOutlineWidget(parent)
|
||||
, m_treeView(new QmlJSOutlineTreeView(this))
|
||||
@@ -101,6 +124,8 @@ QmlJSOutlineWidget::QmlJSOutlineWidget(QWidget *parent)
|
||||
m_filterModel->setFilterBindings(false);
|
||||
|
||||
m_treeView->setModel(m_filterModel);
|
||||
m_treeView->setSortingEnabled(true);
|
||||
|
||||
setFocusProxy(m_treeView);
|
||||
|
||||
auto layout = new QVBoxLayout;
|
||||
@@ -158,15 +183,25 @@ void QmlJSOutlineWidget::setCursorSynchronization(bool syncWithCursor)
|
||||
m_editor->updateOutlineIndexNow();
|
||||
}
|
||||
|
||||
void QmlJSOutlineWidget::setSorted(bool sorted)
|
||||
{
|
||||
m_sorted = sorted;
|
||||
m_filterModel->setSorted(m_sorted);
|
||||
}
|
||||
|
||||
void QmlJSOutlineWidget::restoreSettings(const QVariantMap &map)
|
||||
{
|
||||
bool showBindings = map.value(QString::fromLatin1("QmlJSOutline.ShowBindings"), true).toBool();
|
||||
m_showBindingsAction->setChecked(showBindings);
|
||||
setSorted(map.value(QString("QmlJSOutline.Sort"), false).toBool());
|
||||
}
|
||||
|
||||
QVariantMap QmlJSOutlineWidget::settings() const
|
||||
{
|
||||
return {{QLatin1String("QmlJSOutline.ShowBindings"), m_showBindingsAction->isChecked()}};
|
||||
return {
|
||||
{QString("QmlJSOutline.ShowBindings"), m_showBindingsAction->isChecked()},
|
||||
{QString("QmlJSOutline.Sort"), m_sorted}
|
||||
};
|
||||
}
|
||||
|
||||
void QmlJSOutlineWidget::updateSelectionInTree(const QModelIndex &index)
|
||||
|
@@ -51,15 +51,19 @@ class QmlJSOutlineFilterModel : public QSortFilterProxyModel
|
||||
public:
|
||||
QmlJSOutlineFilterModel(QObject *parent);
|
||||
// QSortFilterProxyModel
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
bool filterAcceptsRow(int sourceRow,
|
||||
const QModelIndex &sourceParent) const override;
|
||||
bool lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const override;
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
Qt::DropActions supportedDragActions() const override;
|
||||
|
||||
bool filterBindings() const;
|
||||
void setFilterBindings(bool filterBindings);
|
||||
void setSorted(bool sorted);
|
||||
private:
|
||||
bool m_filterBindings = false;
|
||||
bool m_sorted = false;
|
||||
};
|
||||
|
||||
class QmlJSOutlineWidget : public TextEditor::IOutlineWidget
|
||||
@@ -73,6 +77,8 @@ public:
|
||||
// IOutlineWidget
|
||||
QList<QAction*> filterMenuActions() const override;
|
||||
void setCursorSynchronization(bool syncWithCursor) override;
|
||||
bool isSorted() const override { return m_sorted; };
|
||||
void setSorted(bool sorted) override;
|
||||
void restoreSettings(const QVariantMap &map) override;
|
||||
QVariantMap settings() const override;
|
||||
|
||||
@@ -93,6 +99,7 @@ private:
|
||||
|
||||
bool m_enableCursorSync = true;
|
||||
bool m_blockCursorSync = false;
|
||||
bool m_sorted = false;
|
||||
};
|
||||
|
||||
class QmlJSOutlineWidgetFactory : public TextEditor::IOutlineWidgetFactory
|
||||
@@ -100,6 +107,7 @@ class QmlJSOutlineWidgetFactory : 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