Commit 7450a09a authored by Eike Ziller's avatar Eike Ziller Committed by hjk

Plugin view: Fix sorting

Broke after moving to Utils::TreeModel. Use QSortFilterProxyModel on top
of TreeModel (can later be used for filtering as well).
Additionally we need to make sure to report changes only for the changed
column now, because otherwise QSortFilterProxyModel thinks that the
change could make re-sorting necessary, and does that in a non-stable
way.

Change-Id: I9fd12c55a45aba4c05f8e318ae8ea9a4ab9f3310
Task-number: QTCREATORBUG-14107
Reviewed-by: default avatarRobert Loehning <robert.loehning@theqtcompany.com>
Reviewed-by: default avatarhjk <hjk@theqtcompany.com>
parent deae570c
......@@ -41,8 +41,9 @@
#include <QDir>
#include <QGridLayout>
#include <QHeaderView>
#include <QSet>
#include <QItemSelectionModel>
#include <QSet>
#include <QSortFilterProxyModel>
/*!
\class ExtensionSystem::PluginView
......@@ -153,8 +154,8 @@ public:
{
if (column == LoadedColumn && role == Qt::CheckStateRole) {
m_spec->setEnabled(data.toBool());
update();
parent()->update();
updateColumn(column);
parent()->updateColumn(column);
emit m_view->pluginSettingsChanged(m_spec);
return true;
}
......@@ -280,13 +281,17 @@ PluginView::PluginView(QWidget *parent)
m_categoryView->setColumnWidth(LoadedColumn, 40);
m_categoryView->header()->setDefaultSectionSize(120);
m_categoryView->header()->setMinimumSectionSize(35);
m_categoryView->header()->setSortIndicator(0, Qt::AscendingOrder);
m_categoryView->setActivationMode(DoubleClickActivation);
m_categoryView->setSelectionMode(QAbstractItemView::SingleSelection);
m_categoryView->setSelectionBehavior(QAbstractItemView::SelectRows);
m_model = new TreeModel(this);
m_model->setHeader(QStringList() << tr("Name") << tr("Load") << tr("Version") << tr("Vendor"));
m_categoryView->setModel(m_model);
m_sortModel = new QSortFilterProxyModel(this);
m_sortModel->setSourceModel(m_model);
m_categoryView->setModel(m_sortModel);
QGridLayout *gridLayout = new QGridLayout(this);
gridLayout->setContentsMargins(2, 2, 2, 2);
......@@ -325,7 +330,8 @@ PluginSpec *PluginView::currentPlugin() const
PluginSpec *PluginView::pluginForIndex(const QModelIndex &index) const
{
auto item = dynamic_cast<PluginItem *>(m_model->itemFromIndex(index));
const QModelIndex &sourceIndex = m_sortModel->mapToSource(index);
auto item = dynamic_cast<PluginItem *>(m_model->itemFromIndex(sourceIndex));
return item ? item->m_spec: 0;
}
......
......@@ -37,6 +37,10 @@
#include <QSet>
#include <QHash>
QT_BEGIN_NAMESPACE
class QSortFilterProxyModel;
QT_END_NAMESPACE
namespace Utils {
class TreeItem;
class TreeModel;
......@@ -71,6 +75,7 @@ private:
Utils::TreeView *m_categoryView;
Utils::TreeModel *m_model;
QSortFilterProxyModel *m_sortModel;
friend class CollectionItem;
friend class PluginItem;
......
......@@ -733,6 +733,14 @@ void TreeItem::update()
}
}
void TreeItem::updateColumn(int column)
{
if (m_model) {
QModelIndex idx = index();
m_model->dataChanged(idx.sibling(idx.row(), column), idx.sibling(idx.row(), column));
}
}
TreeItem *TreeItem::firstChild() const
{
return m_children.isEmpty() ? 0 : m_children.first();
......
......@@ -89,6 +89,7 @@ public:
void insertChild(int pos, TreeItem *item);
void removeChildren();
void update();
void updateColumn(int column);
void expand();
TreeItem *firstChild() const;
TreeItem *lastChild() const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment