diff --git a/plugins/outlineview/outlinewidget.cpp b/plugins/outlineview/outlinewidget.cpp index 56c1e4436f..2fbbeb9d27 100644 --- a/plugins/outlineview/outlinewidget.cpp +++ b/plugins/outlineview/outlinewidget.cpp @@ -1,92 +1,106 @@ /* * KDevelop outline view * Copyright 2010, 2015 Alex Richardson * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "outlinewidget.h" #include #include #include #include #include #include +#include #include #include #include #include #include "outlineviewplugin.h" #include "outlinemodel.h" using namespace KDevelop; OutlineWidget::OutlineWidget(QWidget* parent, OutlineViewPlugin* plugin) : QWidget(parent) , m_plugin(plugin) , m_model(new OutlineModel(this)) , m_tree(new QTreeView(this)) , m_proxy(new KRecursiveFilterProxyModel(this)) , m_filter(new QLineEdit(this)) { setObjectName("Outline View"); setWindowTitle(i18n("Outline")); setWhatsThis(i18n("Outline View")); setWindowIcon(QIcon::fromTheme("code-class")); //TODO: better icon? m_proxy->setSourceModel(m_model); m_proxy->setFilterCaseSensitivity(Qt::CaseInsensitive); + m_proxy->setSortCaseSensitivity(Qt::CaseInsensitive); + m_proxy->setDynamicSortFilter(false); m_tree->setModel(m_proxy); m_tree->setHeaderHidden(true); //filter connect(m_filter, &QLineEdit::textChanged, m_proxy, &KRecursiveFilterProxyModel::setFilterFixedString); connect(m_tree, &QTreeView::activated, this, &OutlineWidget::activated); QHBoxLayout* filterLayout = new QHBoxLayout(); m_filter->setPlaceholderText(i18n("Filter...")); + m_sortAlphabetically = new QPushButton(QIcon::fromTheme("view-sort-ascending"), QString(), this); + m_sortAlphabetically->setToolTip(i18n("Sort alphabetically")); + m_sortAlphabetically->setCheckable(true); + connect(m_sortAlphabetically, &QPushButton::toggled, this, [this](bool sort) { + qDebug("Set sorting: %d", sort); + // calling sort with -1 will restore the original order + m_proxy->sort(sort ? 0 : -1, Qt::AscendingOrder); + m_sortAlphabetically->setChecked(sort); + }); + + filterLayout->addWidget(m_sortAlphabetically); filterLayout->addWidget(m_filter); setFocusProxy(m_filter); QVBoxLayout* vbox = new QVBoxLayout(this); vbox->setMargin(0); vbox->addLayout(filterLayout); vbox->addWidget(m_tree); setLayout(vbox); expandFirstLevel(); connect(m_model, &QAbstractItemModel::modelReset, this, &OutlineWidget::expandFirstLevel); } void OutlineWidget::activated(QModelIndex index) { QModelIndex realIndex = m_proxy->mapToSource(index); m_model->activate(realIndex); } OutlineWidget::~OutlineWidget() { } void OutlineWidget::expandFirstLevel() { for (int i = 0; i < m_proxy->rowCount(); i++) { m_tree->expand(m_proxy->index(i, 0)); } } diff --git a/plugins/outlineview/outlinewidget.h b/plugins/outlineview/outlinewidget.h index 3535ac8fce..c7dd510738 100644 --- a/plugins/outlineview/outlinewidget.h +++ b/plugins/outlineview/outlinewidget.h @@ -1,49 +1,51 @@ /* * KDevelop outline view * Copyright 2010, 2015 Alex Richardson * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #pragma once #include #include class KRecursiveFilterProxyModel; class QTreeView; +class QPushButton; class QLineEdit; class OutlineModel; class OutlineViewPlugin; class OutlineWidget : public QWidget { Q_OBJECT public: OutlineWidget(QWidget* parent, OutlineViewPlugin* plugin); virtual ~OutlineWidget(); private: OutlineViewPlugin* m_plugin; OutlineModel* m_model; QTreeView* m_tree; KRecursiveFilterProxyModel* m_proxy; QLineEdit* m_filter; + QPushButton* m_sortAlphabetically; Q_DISABLE_COPY(OutlineWidget) public slots: void activated(QModelIndex); void expandFirstLevel(); };