summaryrefslogtreecommitdiff
path: root/src/plugins/qtsupport
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@qt.io>2017-01-11 14:43:48 +0100
committerTobias Hunger <tobias.hunger@qt.io>2017-01-17 13:13:48 +0000
commit6553c3c99e3a24da95fa6816989083eef45ba5c2 (patch)
tree6c8cfc9425c400b2b6f83be585a8cf96fc0e7a8b /src/plugins/qtsupport
parentdd438a34451053040615e1b67703322b0d6f170b (diff)
downloadqt-creator-6553c3c99e3a24da95fa6816989083eef45ba5c2.tar.gz
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 <tim.jenssen@qt.io> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Diffstat (limited to 'src/plugins/qtsupport')
-rw-r--r--src/plugins/qtsupport/baseqtversion.cpp2
-rw-r--r--src/plugins/qtsupport/baseqtversion.h4
-rw-r--r--src/plugins/qtsupport/exampleslistmodel.cpp12
-rw-r--r--src/plugins/qtsupport/qtkitconfigwidget.cpp2
-rw-r--r--src/plugins/qtsupport/qtkitinformation.cpp16
-rw-r--r--src/plugins/qtsupport/qtoptionspage.cpp2
-rw-r--r--src/plugins/qtsupport/qtprojectimporter.cpp7
-rw-r--r--src/plugins/qtsupport/qtversionmanager.cpp33
-rw-r--r--src/plugins/qtsupport/qtversionmanager.h9
9 files changed, 39 insertions, 48 deletions
diff --git a/src/plugins/qtsupport/baseqtversion.cpp b/src/plugins/qtsupport/baseqtversion.cpp
index da70f32bbb..47ae35e3ee 100644
--- a/src/plugins/qtsupport/baseqtversion.cpp
+++ b/src/plugins/qtsupport/baseqtversion.cpp
@@ -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()) {
diff --git a/src/plugins/qtsupport/baseqtversion.h b/src/plugins/qtsupport/baseqtversion.h
index 603d1f88d6..421d6cab53 100644
--- a/src/plugins/qtsupport/baseqtversion.h
+++ b/src/plugins/qtsupport/baseqtversion.h
@@ -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;
diff --git a/src/plugins/qtsupport/exampleslistmodel.cpp b/src/plugins/qtsupport/exampleslistmodel.cpp
index 45c8f9199b..ad88fe6358 100644
--- a/src/plugins/qtsupport/exampleslistmodel.cpp
+++ b/src/plugins/qtsupport/exampleslistmodel.cpp
@@ -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();
diff --git a/src/plugins/qtsupport/qtkitconfigwidget.cpp b/src/plugins/qtsupport/qtkitconfigwidget.cpp
index 1a6cd65145..3a27c0e486 100644
--- a/src/plugins/qtsupport/qtkitconfigwidget.cpp
+++ b/src/plugins/qtsupport/qtkitconfigwidget.cpp
@@ -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());
diff --git a/src/plugins/qtsupport/qtkitinformation.cpp b/src/plugins/qtsupport/qtkitinformation.cpp
index 00410ed3d9..bef3c55f22 100644
--- a/src/plugins/qtsupport/qtkitinformation.cpp
+++ b/src/plugins/qtsupport/qtkitinformation.cpp
@@ -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;
}
diff --git a/src/plugins/qtsupport/qtoptionspage.cpp b/src/plugins/qtsupport/qtoptionspage.cpp
index 77f58becea..a40ff0f5dd 100644
--- a/src/plugins/qtsupport/qtoptionspage.cpp
+++ b/src/plugins/qtsupport/qtoptionspage.cpp
@@ -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>());
diff --git a/src/plugins/qtsupport/qtprojectimporter.cpp b/src/plugins/qtsupport/qtprojectimporter.cpp
index 8f541370ea..704cd710ad 100644
--- a/src/plugins/qtsupport/qtprojectimporter.cpp
+++ b/src/plugins/qtsupport/qtprojectimporter.cpp
@@ -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();
diff --git a/src/plugins/qtsupport/qtversionmanager.cpp b/src/plugins/qtsupport/qtversionmanager.cpp
index 16b4885e3b..3d951c44d5 100644
--- a/src/plugins/qtsupport/qtversionmanager.cpp
+++ b/src/plugins/qtsupport/qtversionmanager.cpp
@@ -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
diff --git a/src/plugins/qtsupport/qtversionmanager.h b/src/plugins/qtsupport/qtversionmanager.h
index bd0ea28745..f60bf15807 100644
--- a/src/plugins/qtsupport/qtversionmanager.h
+++ b/src/plugins/qtsupport/qtversionmanager.h
@@ -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);