Commit 6553c3c9 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

BaseQtVersion: Allow for a predicate when retrieving Qt versions



Make methods used to retrieve Qt versions from the Qt versions manager
take a predicate to select the interesting version.

Change-Id: I9218c57bae6d5033d49d618dfc0da41fe578444d
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
Reviewed-by: Eike Ziller's avatarEike Ziller <eike.ziller@qt.io>
parent dd438a34
......@@ -1269,7 +1269,7 @@ void AndroidConfigurations::updateAutomaticKitList()
QHash<Abi, QList<const QtSupport::BaseQtVersion *> > qtVersionsForArch;
const QList<QtSupport::BaseQtVersion *> qtVersions
= Utils::filtered(QtSupport::QtVersionManager::unsortedVersions(), [](const QtSupport::BaseQtVersion *v) {
= QtSupport::QtVersionManager::unsortedVersions([](const QtSupport::BaseQtVersion *v) {
return v->type() == Constants::ANDROIDQT;
});
for (const QtSupport::BaseQtVersion *qtVersion : qtVersions) {
......
......@@ -74,15 +74,9 @@ bool AndroidPotentialKit::isEnabled() const
}
}
bool found = false;
foreach (QtSupport::BaseQtVersion *version, QtSupport::QtVersionManager::validVersions()) {
if (version->type() == QLatin1String(Constants::ANDROIDQT)) {
found = true;
break;
}
}
return found;
return QtSupport::QtVersionManager::version([](const QtSupport::BaseQtVersion *v) {
return v->isValid() && v->type() == QString::fromLatin1(Constants::ANDROIDQT);
});
}
AndroidPotentialKitWidget::AndroidPotentialKitWidget(QWidget *parent)
......
......@@ -336,12 +336,13 @@ void AndroidSettingsWidget::check(AndroidSettingsWidget::Mode mode)
toolchainsForAbi.insert(ati.abi);
}
const QList<QtSupport::BaseQtVersion *> androidQts
= QtSupport::QtVersionManager::unsortedVersions([](const QtSupport::BaseQtVersion *v) {
return v->type() == QLatin1String(Constants::ANDROIDQT) && !v->qtAbis().isEmpty();
});
QSet<ProjectExplorer::Abi> qtVersionsForAbi;
foreach (QtSupport::BaseQtVersion *qtVersion, QtSupport::QtVersionManager::unsortedVersions()) {
if (qtVersion->type() != QLatin1String(Constants::ANDROIDQT) || qtVersion->qtAbis().isEmpty())
continue;
foreach (QtSupport::BaseQtVersion *qtVersion, androidQts)
qtVersionsForAbi.insert(qtVersion->qtAbis().first());
}
QSet<ProjectExplorer::Abi> missingQtArchs = toolchainsForAbi.subtract(qtVersionsForAbi);
if (missingQtArchs.isEmpty()) {
......
......@@ -151,10 +151,12 @@ static QHash<Platform, ToolChainPair> findToolChains(const QList<Platform> &plat
static QHash<Abi::Architecture, QSet<BaseQtVersion *>> iosQtVersions()
{
const QList<BaseQtVersion *> iosVersions
= QtVersionManager::unsortedVersions([](const BaseQtVersion *v) {
return v->isValid() && v->type() == Constants::IOSQT;
});
QHash<Abi::Architecture, QSet<BaseQtVersion *>> versions;
foreach (BaseQtVersion *qtVersion, QtVersionManager::unsortedVersions()) {
if (!qtVersion->isValid() || qtVersion->type() != QLatin1String(Constants::IOSQT))
continue;
foreach (BaseQtVersion *qtVersion, iosVersions) {
foreach (const Abi &abi, qtVersion->qtAbis())
versions[abi.architecture()].insert(qtVersion);
}
......
......@@ -1446,17 +1446,12 @@ void QmakeProject::collectLibraryData(const QmakeProFileNode *node, DeploymentDa
bool QmakeProject::matchesKit(const Kit *kit)
{
QList<QtSupport::BaseQtVersion *> parentQts;
FileName filePath = projectFilePath();
foreach (QtSupport::BaseQtVersion *version, QtSupport::QtVersionManager::validVersions()) {
if (version->isSubProject(filePath))
parentQts.append(version);
}
QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(kit);
if (!parentQts.isEmpty())
return parentQts.contains(version);
return false;
return QtSupport::QtVersionManager::version([&filePath, version](const QtSupport::BaseQtVersion *v) {
return v->isValid() && v->isSubProject(filePath) && v == version;
});
}
static Utils::FileName getFullPathOf(const QmakeProFileNode *pro, QmakeVariable variable,
......
......@@ -266,16 +266,15 @@ QnxQtVersion* QnxConfiguration::qnxQtVersion(QnxArchitecture arch) const
{
QnxQtVersion *qnxQt;
foreach (BaseQtVersion *version,
QtVersionManager::instance()->versions()) {
if (version->type() == QLatin1String(Constants::QNX_QNX_QT)) {
QtVersionManager::instance()->unsortedVersions(Utils::equal(&BaseQtVersion::type,
QString::fromLatin1(Constants::QNX_QNX_QT)))) {
qnxQt = dynamic_cast<QnxQtVersion*>(version);
if (qnxQt && qnxQt->architecture() == arch) {
return qnxQt;
}
}
}
return 0;
return nullptr;
}
QList<ToolChain *> QnxConfiguration::autoDetect(const QList<ToolChain *> &alreadyKnown)
......
......@@ -26,12 +26,15 @@
#include "qnxdeployqtlibrariesdialog.h"
#include "ui_qnxdeployqtlibrariesdialog.h"
#include "qnxconstants.h"
#include "qnxqtversion.h"
#include <projectexplorer/deployablefile.h>
#include <qtsupport/qtversionmanager.h>
#include <remotelinux/genericdirectuploadservice.h>
#include <ssh/sshremoteprocessrunner.h>
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
#include <QDir>
......@@ -54,14 +57,11 @@ QnxDeployQtLibrariesDialog::QnxDeployQtLibrariesDialog(const IDevice::ConstPtr &
{
m_ui->setupUi(this);
QList<BaseQtVersion*> qtVersions = QtVersionManager::validVersions();
foreach (BaseQtVersion *qtVersion, qtVersions) {
QnxQtVersion *qnxQt = dynamic_cast<QnxQtVersion *>(qtVersion);
if (!qnxQt)
continue;
m_ui->qtLibraryCombo->addItem(qnxQt->displayName(), qnxQt->uniqueId());
}
const QList<BaseQtVersion*> qtVersions
= QtVersionManager::validVersions(Utils::equal(&BaseQtVersion::type,
QString::fromLatin1(Constants::QNX_QNX_QT)));
for (BaseQtVersion *v : qtVersions)
m_ui->qtLibraryCombo->addItem(v->displayName(), v->uniqueId());
m_ui->basePathLabel->setText(QString());
m_ui->remoteDirectory->setText(QLatin1String("/qt"));
......
......@@ -1591,7 +1591,7 @@ bool BaseQtVersion::isInSourceDirectory(const Utils::FileName &filePath)
return filePath.isChildOf(dir);
}
bool BaseQtVersion::isSubProject(const Utils::FileName &filePath)
bool BaseQtVersion::isSubProject(const Utils::FileName &filePath) const
{
const Utils::FileName &source = sourcePath();
if (!source.isEmpty()) {
......
......@@ -87,6 +87,8 @@ class QTSUPPORT_EXPORT BaseQtVersion
friend class QtVersionManager;
friend class QtSupport::Internal::QtOptionsPageWidget;
public:
using Predicate = std::function<bool(const BaseQtVersion *)>;
virtual ~BaseQtVersion();
virtual void fromMap(const QVariantMap &map);
......@@ -125,7 +127,7 @@ public:
virtual Utils::FileName sourcePath() const;
bool isInSourceDirectory(const Utils::FileName &filePath);
bool isSubProject(const Utils::FileName &filePath);
bool isSubProject(const Utils::FileName &filePath) const;
// used by UiCodeModelSupport
virtual QString uicCommand() const;
......
......@@ -487,15 +487,9 @@ void ExamplesListModel::updateExamples()
void ExamplesListModel::updateQtVersions()
{
QList<BaseQtVersion*> versions = QtVersionManager::validVersions();
QMutableListIterator<BaseQtVersion*> iter(versions);
while (iter.hasNext()) {
BaseQtVersion *version = iter.next();
if (!version->hasExamples()
&& !version->hasDemos())
iter.remove();
}
QList<BaseQtVersion*> versions = QtVersionManager::validVersions([](const BaseQtVersion *v) {
return v->hasExamples() || v->hasDemos();
});
// prioritize default qt version
ProjectExplorer::Kit *defaultKit = ProjectExplorer::KitManager::defaultKit();
......
......@@ -47,7 +47,7 @@ QtKitConfigWidget::QtKitConfigWidget(ProjectExplorer::Kit *k, const ProjectExplo
m_combo = new QComboBox;
m_combo->addItem(tr("None"), -1);
QList<int> versionIds = Utils::transform(QtVersionManager::versions(), &BaseQtVersion::uniqueId);
QList<int> versionIds = Utils::transform(QtVersionManager::unsortedVersions(), &BaseQtVersion::uniqueId);
versionsChanged(versionIds, QList<int>(), QList<int>());
m_manageButton = new QPushButton(KitConfigWidget::msgManage());
......
......@@ -58,15 +58,14 @@ QVariant QtKitInformation::defaultValue(const Kit *k) const
Q_UNUSED(k);
// find "Qt in PATH":
QList<BaseQtVersion *> versionList = QtVersionManager::unsortedVersions();
BaseQtVersion *result = findOrDefault(versionList, equal(&BaseQtVersion::autodetectionSource,
QString::fromLatin1("PATH")));
BaseQtVersion *result = QtVersionManager::version(equal(&BaseQtVersion::autodetectionSource,
QString::fromLatin1("PATH")));
if (result)
return result->uniqueId();
// Use *any* desktop Qt:
result = findOrDefault(versionList, equal(&BaseQtVersion::type,
QString::fromLatin1(QtSupport::Constants::DESKTOPQT)));
result = QtVersionManager::version(equal(&BaseQtVersion::type,
QString::fromLatin1(QtSupport::Constants::DESKTOPQT)));
return result ? result->uniqueId() : -1;
}
......@@ -161,12 +160,9 @@ int QtKitInformation::qtVersionId(const ProjectExplorer::Kit *k)
id = -1;
} else {
QString source = data.toString();
foreach (BaseQtVersion *v, QtVersionManager::unsortedVersions()) {
if (v->autodetectionSource() != source)
continue;
BaseQtVersion *v = QtVersionManager::version([source](const BaseQtVersion *v) { return v->autodetectionSource() == source; });
if (v)
id = v->uniqueId();
break;
}
}
return id;
}
......
......@@ -235,7 +235,7 @@ QtOptionsPageWidget::QtOptionsPageWidget(QWidget *parent)
m_ui->qtdirList->setTextElideMode(Qt::ElideMiddle);
m_ui->qtdirList->sortByColumn(0, Qt::AscendingOrder);
QList<int> additions = transform(QtVersionManager::versions(), &BaseQtVersion::uniqueId);
QList<int> additions = transform(QtVersionManager::unsortedVersions(), &BaseQtVersion::uniqueId);
updateQtVersions(additions, QList<int>(), QList<int>());
......
......@@ -55,12 +55,7 @@ QtProjectImporter::QtVersionData
QtProjectImporter::findOrCreateQtVersion(const Utils::FileName &qmakePath) const
{
QtVersionData result;
result.qt
= Utils::findOrDefault(QtVersionManager::unsortedVersions(),
[&qmakePath](BaseQtVersion *v) -> bool {
return qmakePath == v->qmakeCommand();
});
result.qt = QtVersionManager::version(Utils::equal(&BaseQtVersion::qmakeCommand, qmakePath));
if (result.qt) {
// Check if version is a temporary qt
const int qtId = result.qt->uniqueId();
......
......@@ -501,33 +501,31 @@ int QtVersionManager::getUniqueId()
return m_idcount++;
}
QList<BaseQtVersion *> QtVersionManager::unsortedVersions()
QList<BaseQtVersion *> QtVersionManager::unsortedVersions(const BaseQtVersion::Predicate &predicate)
{
QList<BaseQtVersion *> versions;
QTC_ASSERT(isLoaded(), return versions);
return m_versions.values();
if (predicate)
return Utils::filtered(m_versions.values(), predicate);
else
return m_versions.values();
}
QList<BaseQtVersion *> QtVersionManager::versions()
QList<BaseQtVersion *> QtVersionManager::versions(const BaseQtVersion::Predicate &predicate)
{
QList<BaseQtVersion *> versions;
QTC_ASSERT(isLoaded(), return versions);
foreach (BaseQtVersion *version, m_versions)
versions << version;
versions = unsortedVersions(predicate);
Utils::sort(versions, qtVersionNumberCompare);
return versions;
}
QList<BaseQtVersion *> QtVersionManager::validVersions()
QList<BaseQtVersion *> QtVersionManager::validVersions(const BaseQtVersion::Predicate &predicate)
{
QList<BaseQtVersion *> results;
QTC_ASSERT(isLoaded(), return results);
foreach (BaseQtVersion *v, m_versions) {
if (v->isValid())
results.append(v);
}
Utils::sort(results, qtVersionNumberCompare);
return results;
QTC_ASSERT(isLoaded(), return { });
auto superPredicate
= [predicate](const BaseQtVersion *v) { return v->isValid() && (!predicate || predicate(v)); };
return versions(superPredicate);
}
bool QtVersionManager::isValidId(int id)
......@@ -545,6 +543,11 @@ BaseQtVersion *QtVersionManager::version(int id)
return it.value();
}
BaseQtVersion *QtVersionManager::version(const BaseQtVersion::Predicate &predicate)
{
return Utils::findOrDefault(m_versions.values(), predicate);
}
// This function is really simplistic...
static bool equals(BaseQtVersion *a, BaseQtVersion *b)
{
......@@ -615,7 +618,7 @@ void QtVersionManager::setNewQtVersions(QList<BaseQtVersion *> newVersions)
BaseQtVersion *QtVersionManager::qtVersionForQMakeBinary(const FileName &qmakePath)
{
return Utils::findOrDefault(unsortedVersions(), Utils::equal(&BaseQtVersion::qmakeCommand, qmakePath));
return version(Utils::equal(&BaseQtVersion::qmakeCommand, qmakePath));
}
} // namespace QtVersion
......@@ -46,16 +46,17 @@ public:
// This will *always* return at least one (Qt in Path), even if that is
// unconfigured.
static QList<BaseQtVersion *> versions();
static QList<BaseQtVersion *> validVersions();
// Sorting is slow due to needing to potentially run qmake --query for each version
static QList<BaseQtVersion *> unsortedVersions();
static QList<BaseQtVersion *> versions(const BaseQtVersion::Predicate &predicate = BaseQtVersion::Predicate());
static QList<BaseQtVersion *> validVersions(const BaseQtVersion::Predicate &predicate = BaseQtVersion::Predicate());
static QList<BaseQtVersion *> unsortedVersions(const BaseQtVersion::Predicate &predicate = BaseQtVersion::Predicate());
// Note: DO NOT STORE THIS POINTER!
// The QtVersionManager will delete it at random times and you will
// need to get a new pointer by calling this function again!
static BaseQtVersion *version(int id);
static BaseQtVersion *version(const BaseQtVersion::Predicate &predicate);
static BaseQtVersion *qtVersionForQMakeBinary(const Utils::FileName &qmakePath);
......
......@@ -170,14 +170,15 @@ bool WinRtDeviceFactory::allPrerequisitesLoaded()
QString WinRtDeviceFactory::findRunnerFilePath() const
{
const QString winRtQtType = QLatin1String(Constants::WINRT_WINRTQT);
const QString winPhoneQtType = QLatin1String(Constants::WINRT_WINPHONEQT);
const QString winRtRunnerExe = QStringLiteral("/winrtrunner.exe");
const QList<BaseQtVersion *> winrtVersions
= QtVersionManager::validVersions([](const BaseQtVersion *v) {
return v->type() == QLatin1String(Constants::WINRT_WINRTQT)
|| v->type() == QLatin1String(Constants::WINRT_WINPHONEQT);
});
QString filePath;
BaseQtVersion *qt = 0;
foreach (BaseQtVersion *v, QtVersionManager::versions()) {
if (!v->isValid() || (v->type() != winRtQtType && v->type() != winPhoneQtType))
continue;
BaseQtVersion *qt = nullptr;
for (BaseQtVersion *v : winrtVersions) {
if (!qt || qt->qtVersion() < v->qtVersion()) {
QFileInfo fi(v->binPath().toString() + winRtRunnerExe);
if (fi.isFile() && fi.isExecutable()) {
......
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