forked from qt-creator/qt-creator
Welcome: Fix the order of Qt versions for examples
There are two sources for examples: Qt versions directly, and "example sets", which are just a tuple of display name, documentation path, examples path. The Qt installer registers an "example set" for Qt versions, so to avoid duplicate entries we match Qt versions to example sets, if found. This destroys any order the Qt versions might have been in before. Order the results by Qt version (and other sets last) by first creating all the items regardless of origin (noting their Qt version in the user data), and sorting them before adding to the model. Also use constants for the different user data fields. Fixes: QTCREATORBUG-31108 Change-Id: I827be892a3abe17fa6afcd3c6f39bf225f7af494 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -28,12 +28,14 @@
|
|||||||
#include <utils/stylehelper.h>
|
#include <utils/stylehelper.h>
|
||||||
|
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
#include <algorithm>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
|
const int kQtVersionIdRole = Qt::UserRole;
|
||||||
|
const int kExtraSetIndexRole = Qt::UserRole + 1;
|
||||||
|
const int kVersionRole = Qt::UserRole + 2;
|
||||||
|
|
||||||
namespace QtSupport {
|
namespace QtSupport {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -112,43 +114,66 @@ ExampleSetModel::ExampleSetModel()
|
|||||||
&ExampleSetModel::helpManagerInitialized);
|
&ExampleSetModel::helpManagerInitialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExampleSetModel::recreateModel(const QtVersions &qtVersions)
|
void ExampleSetModel::recreateModel(const QtVersions &qtVersionsIn)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
QHash<FilePath, int> extraManifestDirs;
|
QHash<FilePath, int> extraManifestDirs;
|
||||||
|
for (int i = 0; i < m_extraExampleSets.size(); ++i)
|
||||||
|
extraManifestDirs.insert(FilePath::fromUserInput(m_extraExampleSets.at(i).manifestPath), i);
|
||||||
|
|
||||||
|
// Sanitize away qt versions that have already been added through extra sets.
|
||||||
|
// This way we do not have entries for Qt/Android, Qt/Desktop, Qt/MinGW etc pp,
|
||||||
|
// but only the one "QtX X.Y.Z" entry that is registered as an example set by the installer.
|
||||||
|
const QtVersions qtVersions
|
||||||
|
= Utils::filtered(qtVersionsIn, [this, &extraManifestDirs](QtVersion *v) {
|
||||||
|
if (extraManifestDirs.contains(v->docsPath())) {
|
||||||
|
m_extraExampleSets[extraManifestDirs.value(v->docsPath())].qtVersion
|
||||||
|
= v->qtVersion();
|
||||||
|
qCDebug(log) << "Not showing Qt version because manifest path is already added "
|
||||||
|
"through InstalledExamples settings:"
|
||||||
|
<< v->displayName();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
QList<QStandardItem *> items;
|
||||||
for (int i = 0; i < m_extraExampleSets.size(); ++i) {
|
for (int i = 0; i < m_extraExampleSets.size(); ++i) {
|
||||||
const ExtraExampleSet &set = m_extraExampleSets.at(i);
|
const ExtraExampleSet &set = m_extraExampleSets.at(i);
|
||||||
auto newItem = new QStandardItem();
|
auto newItem = new QStandardItem();
|
||||||
newItem->setData(set.displayName, Qt::DisplayRole);
|
newItem->setData(set.displayName, Qt::DisplayRole);
|
||||||
newItem->setData(set.displayName, Qt::UserRole + 1);
|
newItem->setData(QVariant(), kQtVersionIdRole);
|
||||||
newItem->setData(QVariant(), Qt::UserRole + 2);
|
newItem->setData(i, kExtraSetIndexRole);
|
||||||
newItem->setData(i, Qt::UserRole + 3);
|
newItem->setData(QVariant::fromValue(set.qtVersion), kVersionRole);
|
||||||
appendRow(newItem);
|
items.append(newItem);
|
||||||
|
|
||||||
extraManifestDirs.insert(FilePath::fromUserInput(set.manifestPath), i);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (QtVersion *version : qtVersions) {
|
|
||||||
// Sanitize away qt versions that have already been added through extra sets.
|
|
||||||
// This way we do not have entries for Qt/Android, Qt/Desktop, Qt/MinGW etc pp,
|
|
||||||
// but only the one "QtX X.Y.Z" entry that is registered as an example set by the installer.
|
|
||||||
if (extraManifestDirs.contains(version->docsPath())) {
|
|
||||||
m_extraExampleSets[extraManifestDirs.value(version->docsPath())].qtVersion
|
|
||||||
= version->qtVersion();
|
|
||||||
qCDebug(log) << "Not showing Qt version because manifest path is already added "
|
|
||||||
"through InstalledExamples settings:"
|
|
||||||
<< version->displayName();
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
items += Utils::transform(qtVersions, [](QtVersion *v) {
|
||||||
auto newItem = new QStandardItem();
|
auto newItem = new QStandardItem();
|
||||||
newItem->setData(version->displayName(), Qt::DisplayRole);
|
newItem->setData(v->displayName(), Qt::DisplayRole);
|
||||||
newItem->setData(version->displayName(), Qt::UserRole + 1);
|
newItem->setData(v->uniqueId(), kQtVersionIdRole);
|
||||||
newItem->setData(version->uniqueId(), Qt::UserRole + 2);
|
newItem->setData(QVariant(), kExtraSetIndexRole);
|
||||||
newItem->setData(QVariant(), Qt::UserRole + 3);
|
newItem->setData(QVariant::fromValue(v->qtVersion()), kVersionRole);
|
||||||
appendRow(newItem);
|
return newItem;
|
||||||
}
|
});
|
||||||
|
|
||||||
|
// Sort by Qt version, example sets not associated to Qt last
|
||||||
|
Utils::sort(items, [](QStandardItem *a, QStandardItem *b) {
|
||||||
|
const QVersionNumber versionB = b->data(kVersionRole).value<QVersionNumber>();
|
||||||
|
if (versionB.isNull())
|
||||||
|
return true;
|
||||||
|
const QVersionNumber versionA = a->data(kVersionRole).value<QVersionNumber>();
|
||||||
|
if (versionA.isNull())
|
||||||
|
return false;
|
||||||
|
if (versionA == versionB)
|
||||||
|
return a->data(Qt::DisplayRole).toString() < b->data(Qt::DisplayRole).toString();
|
||||||
|
return versionA < versionB;
|
||||||
|
});
|
||||||
|
|
||||||
|
for (QStandardItem *item : std::as_const(items))
|
||||||
|
appendRow(item);
|
||||||
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,7 +204,7 @@ QVariant ExampleSetModel::getDisplayName(int i) const
|
|||||||
{
|
{
|
||||||
if (i < 0 || i >= rowCount())
|
if (i < 0 || i >= rowCount())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
return data(index(i, 0), Qt::UserRole + 1);
|
return data(index(i, 0), Qt::DisplayRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
// id is either the Qt version uniqueId, or the display name of the extra example set
|
// id is either the Qt version uniqueId, or the display name of the extra example set
|
||||||
@@ -188,7 +213,7 @@ QVariant ExampleSetModel::getId(int i) const
|
|||||||
if (i < 0 || i >= rowCount())
|
if (i < 0 || i >= rowCount())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
QModelIndex modelIndex = index(i, 0);
|
QModelIndex modelIndex = index(i, 0);
|
||||||
QVariant variant = data(modelIndex, Qt::UserRole + 2);
|
QVariant variant = data(modelIndex, kQtVersionIdRole);
|
||||||
if (variant.isValid()) // set from qt version
|
if (variant.isValid()) // set from qt version
|
||||||
return variant;
|
return variant;
|
||||||
return getDisplayName(i);
|
return getDisplayName(i);
|
||||||
@@ -199,7 +224,7 @@ ExampleSetModel::ExampleSetType ExampleSetModel::getType(int i) const
|
|||||||
if (i < 0 || i >= rowCount())
|
if (i < 0 || i >= rowCount())
|
||||||
return InvalidExampleSet;
|
return InvalidExampleSet;
|
||||||
QModelIndex modelIndex = index(i, 0);
|
QModelIndex modelIndex = index(i, 0);
|
||||||
QVariant variant = data(modelIndex, Qt::UserRole + 2); /*Qt version uniqueId*/
|
QVariant variant = data(modelIndex, kQtVersionIdRole); /*Qt version uniqueId*/
|
||||||
if (variant.isValid())
|
if (variant.isValid())
|
||||||
return QtExampleSet;
|
return QtExampleSet;
|
||||||
return ExtraExampleSetType;
|
return ExtraExampleSetType;
|
||||||
@@ -209,7 +234,7 @@ int ExampleSetModel::getQtId(int i) const
|
|||||||
{
|
{
|
||||||
QTC_ASSERT(i >= 0, return -1);
|
QTC_ASSERT(i >= 0, return -1);
|
||||||
QModelIndex modelIndex = index(i, 0);
|
QModelIndex modelIndex = index(i, 0);
|
||||||
QVariant variant = data(modelIndex, Qt::UserRole + 2);
|
QVariant variant = data(modelIndex, kQtVersionIdRole);
|
||||||
QTC_ASSERT(variant.isValid(), return -1);
|
QTC_ASSERT(variant.isValid(), return -1);
|
||||||
QTC_ASSERT(variant.canConvert<int>(), return -1);
|
QTC_ASSERT(variant.canConvert<int>(), return -1);
|
||||||
return variant.toInt();
|
return variant.toInt();
|
||||||
@@ -224,7 +249,7 @@ int ExampleSetModel::getExtraExampleSetIndex(int i) const
|
|||||||
{
|
{
|
||||||
QTC_ASSERT(i >= 0, return -1);
|
QTC_ASSERT(i >= 0, return -1);
|
||||||
QModelIndex modelIndex = index(i, 0);
|
QModelIndex modelIndex = index(i, 0);
|
||||||
QVariant variant = data(modelIndex, Qt::UserRole + 3);
|
QVariant variant = data(modelIndex, kExtraSetIndexRole);
|
||||||
QTC_ASSERT(variant.isValid(), return -1);
|
QTC_ASSERT(variant.isValid(), return -1);
|
||||||
QTC_ASSERT(variant.canConvert<int>(), return -1);
|
QTC_ASSERT(variant.canConvert<int>(), return -1);
|
||||||
return variant.toInt();
|
return variant.toInt();
|
||||||
|
Reference in New Issue
Block a user