forked from qt-creator/qt-creator
About Plugins: Fix sorting by "Load" column
Change-Id: I705a717ff13e23bafcffb0d41edceab95d3607e6 Task-number: QTCREATORBUG-14107 Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
@@ -81,6 +81,8 @@ enum Columns { NameColumn, LoadedColumn, VersionColumn, VendorColumn, };
|
|||||||
|
|
||||||
enum IconIndex { OkIcon, ErrorIcon, NotLoadedIcon };
|
enum IconIndex { OkIcon, ErrorIcon, NotLoadedIcon };
|
||||||
|
|
||||||
|
static const int SortRole = Qt::UserRole + 1;
|
||||||
|
|
||||||
static const QIcon &icon(int num)
|
static const QIcon &icon(int num)
|
||||||
{
|
{
|
||||||
static QIcon icons[] = {
|
static QIcon icons[] = {
|
||||||
@@ -104,7 +106,7 @@ public:
|
|||||||
{
|
{
|
||||||
switch (column) {
|
switch (column) {
|
||||||
case NameColumn:
|
case NameColumn:
|
||||||
if (role == Qt::DisplayRole)
|
if (role == Qt::DisplayRole || role == SortRole)
|
||||||
return m_spec->name();
|
return m_spec->name();
|
||||||
if (role == Qt::ToolTipRole)
|
if (role == Qt::ToolTipRole)
|
||||||
return QDir::toNativeSeparators(m_spec->filePath());
|
return QDir::toNativeSeparators(m_spec->filePath());
|
||||||
@@ -119,17 +121,17 @@ public:
|
|||||||
|
|
||||||
case LoadedColumn:
|
case LoadedColumn:
|
||||||
if (!m_spec->isAvailableForHostPlatform()) {
|
if (!m_spec->isAvailableForHostPlatform()) {
|
||||||
if (role == Qt::CheckStateRole)
|
if (role == Qt::CheckStateRole || role == SortRole)
|
||||||
return Qt::Unchecked;
|
return Qt::Unchecked;
|
||||||
if (role == Qt::ToolTipRole)
|
if (role == Qt::ToolTipRole)
|
||||||
return PluginView::tr("Plugin is not available on this platform.");
|
return PluginView::tr("Plugin is not available on this platform.");
|
||||||
} else if (m_spec->isRequired()) {
|
} else if (m_spec->isRequired()) {
|
||||||
if (role == Qt::CheckStateRole)
|
if (role == Qt::CheckStateRole || role == SortRole)
|
||||||
return Qt::Checked;
|
return Qt::Checked;
|
||||||
if (role == Qt::ToolTipRole)
|
if (role == Qt::ToolTipRole)
|
||||||
return PluginView::tr("Plugin is required.");
|
return PluginView::tr("Plugin is required.");
|
||||||
} else {
|
} else {
|
||||||
if (role == Qt::CheckStateRole)
|
if (role == Qt::CheckStateRole || role == SortRole)
|
||||||
return m_spec->isEnabledInSettings() ? Qt::Checked : Qt::Unchecked;
|
return m_spec->isEnabledInSettings() ? Qt::Checked : Qt::Unchecked;
|
||||||
if (role == Qt::ToolTipRole)
|
if (role == Qt::ToolTipRole)
|
||||||
return PluginView::tr("Load on startup");
|
return PluginView::tr("Load on startup");
|
||||||
@@ -137,12 +139,12 @@ public:
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case VersionColumn:
|
case VersionColumn:
|
||||||
if (role == Qt::DisplayRole)
|
if (role == Qt::DisplayRole || role == SortRole)
|
||||||
return QString::fromLatin1("%1 (%2)").arg(m_spec->version(), m_spec->compatVersion());
|
return QString::fromLatin1("%1 (%2)").arg(m_spec->version(), m_spec->compatVersion());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VendorColumn:
|
case VendorColumn:
|
||||||
if (role == Qt::DisplayRole)
|
if (role == Qt::DisplayRole || role == SortRole)
|
||||||
return m_spec->vendor();
|
return m_spec->vendor();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -207,7 +209,7 @@ public:
|
|||||||
QVariant data(int column, int role) const
|
QVariant data(int column, int role) const
|
||||||
{
|
{
|
||||||
if (column == NameColumn) {
|
if (column == NameColumn) {
|
||||||
if (role == Qt::DisplayRole)
|
if (role == Qt::DisplayRole || role == SortRole)
|
||||||
return m_name;
|
return m_name;
|
||||||
if (role == Qt::DecorationRole) {
|
if (role == Qt::DecorationRole) {
|
||||||
foreach (PluginSpec *spec, m_plugins) {
|
foreach (PluginSpec *spec, m_plugins) {
|
||||||
@@ -223,7 +225,7 @@ public:
|
|||||||
if (column == LoadedColumn) {
|
if (column == LoadedColumn) {
|
||||||
if (role == Qt::ToolTipRole)
|
if (role == Qt::ToolTipRole)
|
||||||
return PluginView::tr("Load on Startup");
|
return PluginView::tr("Load on Startup");
|
||||||
if (role == Qt::CheckStateRole) {
|
if (role == Qt::CheckStateRole || role == SortRole) {
|
||||||
int checkedCount = 0;
|
int checkedCount = 0;
|
||||||
foreach (PluginSpec *spec, m_plugins) {
|
foreach (PluginSpec *spec, m_plugins) {
|
||||||
if (spec->isEnabledInSettings())
|
if (spec->isEnabledInSettings())
|
||||||
@@ -291,6 +293,7 @@ PluginView::PluginView(QWidget *parent)
|
|||||||
|
|
||||||
m_sortModel = new QSortFilterProxyModel(this);
|
m_sortModel = new QSortFilterProxyModel(this);
|
||||||
m_sortModel->setSourceModel(m_model);
|
m_sortModel->setSourceModel(m_model);
|
||||||
|
m_sortModel->setSortRole(SortRole);
|
||||||
m_categoryView->setModel(m_sortModel);
|
m_categoryView->setModel(m_sortModel);
|
||||||
|
|
||||||
QGridLayout *gridLayout = new QGridLayout(this);
|
QGridLayout *gridLayout = new QGridLayout(this);
|
||||||
|
Reference in New Issue
Block a user