forked from qt-creator/qt-creator
QtSupport: Move QtVersionManager closer to "new" singleton pattern
Not 100%, as there are a few more local variables involved. Change-Id: I15458d614c381862aa6f9e1c54d56c045bac8941 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -46,8 +46,6 @@ namespace Internal {
|
|||||||
class QtSupportPluginPrivate
|
class QtSupportPluginPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QtVersionManager qtVersionManager;
|
|
||||||
|
|
||||||
DesktopQtVersionFactory desktopQtVersionFactory;
|
DesktopQtVersionFactory desktopQtVersionFactory;
|
||||||
EmbeddedLinuxQtVersionFactory embeddedLinuxQtVersionFactory;
|
EmbeddedLinuxQtVersionFactory embeddedLinuxQtVersionFactory;
|
||||||
|
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
|
using namespace ProjectExplorer;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace QtSupport {
|
namespace QtSupport {
|
||||||
@@ -49,13 +50,8 @@ static VersionMap m_versions;
|
|||||||
|
|
||||||
const char DOCUMENTATION_SETTING_KEY[] = "QtSupport/DocumentationSetting";
|
const char DOCUMENTATION_SETTING_KEY[] = "QtSupport/DocumentationSetting";
|
||||||
|
|
||||||
static int m_idcount = 0;
|
QVector<ExampleSetModel::ExtraExampleSet> m_pluginRegisteredExampleSets;
|
||||||
// managed by QtProjectManagerPlugin
|
|
||||||
static QtVersionManager *m_instance = nullptr;
|
|
||||||
static FileSystemWatcher *m_configFileWatcher = nullptr;
|
|
||||||
static QTimer *m_fileWatcherTimer = nullptr;
|
|
||||||
static PersistentSettingsWriter *m_writer = nullptr;
|
|
||||||
static QVector<ExampleSetModel::ExtraExampleSet> m_pluginRegisteredExampleSets;
|
|
||||||
|
|
||||||
static Q_LOGGING_CATEGORY(log, "qtc.qt.versions", QtWarningMsg);
|
static Q_LOGGING_CATEGORY(log, "qtc.qt.versions", QtWarningMsg);
|
||||||
|
|
||||||
@@ -69,47 +65,77 @@ static FilePath settingsFileName(const QString &path)
|
|||||||
return Core::ICore::userResourcePath(path);
|
return Core::ICore::userResourcePath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// prefer newer qts otherwise compare on id
|
// prefer newer qts otherwise compare on id
|
||||||
bool qtVersionNumberCompare(QtVersion *a, QtVersion *b)
|
bool qtVersionNumberCompare(QtVersion *a, QtVersion *b)
|
||||||
{
|
{
|
||||||
return a->qtVersion() > b->qtVersion() || (a->qtVersion() == b->qtVersion() && a->uniqueId() < b->uniqueId());
|
return a->qtVersion() > b->qtVersion() || (a->qtVersion() == b->qtVersion() && a->uniqueId() < b->uniqueId());
|
||||||
}
|
}
|
||||||
static bool restoreQtVersions();
|
|
||||||
static void findSystemQt();
|
|
||||||
static void saveQtVersions();
|
|
||||||
|
|
||||||
QVector<ExampleSetModel::ExtraExampleSet> ExampleSetModel::pluginRegisteredExampleSets()
|
QVector<ExampleSetModel::ExtraExampleSet> ExampleSetModel::pluginRegisteredExampleSets()
|
||||||
{
|
{
|
||||||
return m_pluginRegisteredExampleSets;
|
return m_pluginRegisteredExampleSets;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
// QtVersionManager
|
// QtVersionManager
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
|
|
||||||
QtVersionManager::QtVersionManager()
|
class QtVersionManagerImpl : public QtVersionManager
|
||||||
{
|
{
|
||||||
m_instance = this;
|
public:
|
||||||
m_configFileWatcher = nullptr;
|
QtVersionManagerImpl()
|
||||||
m_fileWatcherTimer = new QTimer(this);
|
{
|
||||||
m_writer = nullptr;
|
|
||||||
m_idcount = 1;
|
|
||||||
|
|
||||||
qRegisterMetaType<FilePath>();
|
qRegisterMetaType<FilePath>();
|
||||||
|
|
||||||
// Give the file a bit of time to settle before reading it...
|
// Give the file a bit of time to settle before reading it...
|
||||||
m_fileWatcherTimer->setInterval(2000);
|
m_fileWatcherTimer.setInterval(2000);
|
||||||
connect(m_fileWatcherTimer, &QTimer::timeout, this, [this] { updateFromInstaller(); });
|
connect(&m_fileWatcherTimer, &QTimer::timeout, this, [this] { updateFromInstaller(); });
|
||||||
|
|
||||||
|
connect(ToolChainManager::instance(), &ToolChainManager::toolChainsLoaded,
|
||||||
|
this, &QtVersionManagerImpl::triggerQtVersionRestore);
|
||||||
|
}
|
||||||
|
|
||||||
|
~QtVersionManagerImpl()
|
||||||
|
{
|
||||||
|
delete m_writer;
|
||||||
|
qDeleteAll(m_versions);
|
||||||
|
m_versions.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateFromInstaller(bool emitSignal = true);
|
||||||
|
void triggerQtVersionRestore();
|
||||||
|
|
||||||
|
bool restoreQtVersions();
|
||||||
|
void findSystemQt();
|
||||||
|
void saveQtVersions();
|
||||||
|
|
||||||
|
void updateDocumentation(const QtVersions &added,
|
||||||
|
const QtVersions &removed,
|
||||||
|
const QtVersions &allNew);
|
||||||
|
|
||||||
|
void setNewQtVersions(const QtVersions &newVersions);
|
||||||
|
QString qmakePath(const QString &qtchooser, const QString &version);
|
||||||
|
|
||||||
|
QList<QByteArray> runQtChooser(const QString &qtchooser, const QStringList &arguments);
|
||||||
|
FilePaths gatherQmakePathsFromQtChooser();
|
||||||
|
|
||||||
|
int m_idcount = 1;
|
||||||
|
// managed by QtProjectManagerPlugin
|
||||||
|
FileSystemWatcher *m_configFileWatcher = nullptr;
|
||||||
|
QTimer m_fileWatcherTimer;
|
||||||
|
PersistentSettingsWriter *m_writer = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
QtVersionManagerImpl &qtVersionManagerImpl()
|
||||||
|
{
|
||||||
|
static QtVersionManagerImpl theQtVersionManager;
|
||||||
|
return theQtVersionManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtVersionManager::triggerQtVersionRestore()
|
void QtVersionManagerImpl::triggerQtVersionRestore()
|
||||||
{
|
{
|
||||||
disconnect(ProjectExplorer::ToolChainManager::instance(), &ProjectExplorer::ToolChainManager::toolChainsLoaded,
|
disconnect(ToolChainManager::instance(), &ToolChainManager::toolChainsLoaded,
|
||||||
this, &QtVersionManager::triggerQtVersionRestore);
|
this, &QtVersionManagerImpl::triggerQtVersionRestore);
|
||||||
|
|
||||||
bool success = restoreQtVersions();
|
bool success = restoreQtVersions();
|
||||||
m_instance->updateFromInstaller(false);
|
updateFromInstaller(false);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
// We did neither restore our settings or upgraded
|
// We did neither restore our settings or upgraded
|
||||||
// in that case figure out if there's a qt in path
|
// in that case figure out if there's a qt in path
|
||||||
@@ -117,45 +143,38 @@ void QtVersionManager::triggerQtVersionRestore()
|
|||||||
findSystemQt();
|
findSystemQt();
|
||||||
}
|
}
|
||||||
|
|
||||||
emit m_instance->qtVersionsLoaded();
|
emit qtVersionsLoaded();
|
||||||
emit m_instance->qtVersionsChanged(m_versions.keys(), QList<int>(), QList<int>());
|
emit qtVersionsChanged(m_versions.keys(), QList<int>(), QList<int>());
|
||||||
|
|
||||||
const FilePath configFileName = globalSettingsFileName();
|
const FilePath configFileName = globalSettingsFileName();
|
||||||
if (configFileName.exists()) {
|
if (configFileName.exists()) {
|
||||||
m_configFileWatcher = new FileSystemWatcher(m_instance);
|
m_configFileWatcher = new FileSystemWatcher(this);
|
||||||
connect(m_configFileWatcher, &FileSystemWatcher::fileChanged,
|
connect(m_configFileWatcher, &FileSystemWatcher::fileChanged,
|
||||||
m_fileWatcherTimer, QOverload<>::of(&QTimer::start));
|
&m_fileWatcherTimer, QOverload<>::of(&QTimer::start));
|
||||||
m_configFileWatcher->addFile(configFileName, FileSystemWatcher::WatchModifiedDate);
|
m_configFileWatcher->addFile(configFileName, FileSystemWatcher::WatchModifiedDate);
|
||||||
} // exists
|
} // exists
|
||||||
|
|
||||||
const QtVersions vs = versions();
|
const QtVersions vs = versions();
|
||||||
updateDocumentation(vs, {}, vs);
|
qtVersionManagerImpl().updateDocumentation(vs, {}, vs);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QtVersionManager::isLoaded()
|
bool QtVersionManager::isLoaded()
|
||||||
{
|
{
|
||||||
return m_writer;
|
return qtVersionManagerImpl().m_writer;
|
||||||
}
|
|
||||||
|
|
||||||
QtVersionManager::~QtVersionManager()
|
|
||||||
{
|
|
||||||
delete m_writer;
|
|
||||||
qDeleteAll(m_versions);
|
|
||||||
m_versions.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QtVersionManager::initialized()
|
|
||||||
{
|
|
||||||
connect(ProjectExplorer::ToolChainManager::instance(), &ProjectExplorer::ToolChainManager::toolChainsLoaded,
|
|
||||||
QtVersionManager::instance(), &QtVersionManager::triggerQtVersionRestore);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QtVersionManager *QtVersionManager::instance()
|
QtVersionManager *QtVersionManager::instance()
|
||||||
{
|
{
|
||||||
return m_instance;
|
return &qtVersionManagerImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool restoreQtVersions()
|
void QtVersionManager::initialized()
|
||||||
|
{
|
||||||
|
// Force creation. FIXME: Remove.
|
||||||
|
qtVersionManagerImpl();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QtVersionManagerImpl::restoreQtVersions()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(!m_writer, return false);
|
QTC_ASSERT(!m_writer, return false);
|
||||||
m_writer = new PersistentSettingsWriter(settingsFileName(QTVERSION_FILENAME),
|
m_writer = new PersistentSettingsWriter(settingsFileName(QTVERSION_FILENAME),
|
||||||
@@ -216,9 +235,9 @@ static bool restoreQtVersions()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtVersionManager::updateFromInstaller(bool emitSignal)
|
void QtVersionManagerImpl::updateFromInstaller(bool emitSignal)
|
||||||
{
|
{
|
||||||
m_fileWatcherTimer->stop();
|
m_fileWatcherTimer.stop();
|
||||||
|
|
||||||
const FilePath path = globalSettingsFileName();
|
const FilePath path = globalSettingsFileName();
|
||||||
// Handle overwritting of data:
|
// Handle overwritting of data:
|
||||||
@@ -344,7 +363,7 @@ void QtVersionManager::updateFromInstaller(bool emitSignal)
|
|||||||
emit qtVersionsChanged(added, removed, changed);
|
emit qtVersionsChanged(added, removed, changed);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void saveQtVersions()
|
void QtVersionManagerImpl::saveQtVersions()
|
||||||
{
|
{
|
||||||
if (!m_writer)
|
if (!m_writer)
|
||||||
return;
|
return;
|
||||||
@@ -365,7 +384,7 @@ static void saveQtVersions()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Executes qtchooser with arguments in a process and returns its output
|
// Executes qtchooser with arguments in a process and returns its output
|
||||||
static QList<QByteArray> runQtChooser(const QString &qtchooser, const QStringList &arguments)
|
QList<QByteArray> QtVersionManagerImpl::runQtChooser(const QString &qtchooser, const QStringList &arguments)
|
||||||
{
|
{
|
||||||
Process p;
|
Process p;
|
||||||
p.setCommand({FilePath::fromString(qtchooser), arguments});
|
p.setCommand({FilePath::fromString(qtchooser), arguments});
|
||||||
@@ -376,7 +395,7 @@ static QList<QByteArray> runQtChooser(const QString &qtchooser, const QStringLis
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Asks qtchooser for the qmake path of a given version
|
// Asks qtchooser for the qmake path of a given version
|
||||||
static QString qmakePath(const QString &qtchooser, const QString &version)
|
QString QtVersionManagerImpl::qmakePath(const QString &qtchooser, const QString &version)
|
||||||
{
|
{
|
||||||
const QList<QByteArray> outputs = runQtChooser(qtchooser,
|
const QList<QByteArray> outputs = runQtChooser(qtchooser,
|
||||||
{QStringLiteral("-qt=%1").arg(version),
|
{QStringLiteral("-qt=%1").arg(version),
|
||||||
@@ -392,7 +411,7 @@ static QString qmakePath(const QString &qtchooser, const QString &version)
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
static FilePaths gatherQmakePathsFromQtChooser()
|
FilePaths QtVersionManagerImpl::gatherQmakePathsFromQtChooser()
|
||||||
{
|
{
|
||||||
const QString qtchooser = QStandardPaths::findExecutable(QStringLiteral("qtchooser"));
|
const QString qtchooser = QStandardPaths::findExecutable(QStringLiteral("qtchooser"));
|
||||||
if (qtchooser.isEmpty())
|
if (qtchooser.isEmpty())
|
||||||
@@ -409,7 +428,7 @@ static FilePaths gatherQmakePathsFromQtChooser()
|
|||||||
return Utils::toList(foundQMakes);
|
return Utils::toList(foundQMakes);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void findSystemQt()
|
void QtVersionManagerImpl::findSystemQt()
|
||||||
{
|
{
|
||||||
FilePaths systemQMakes
|
FilePaths systemQMakes
|
||||||
= BuildableHelperLibrary::findQtsInEnvironment(Environment::systemEnvironment());
|
= BuildableHelperLibrary::findQtsInEnvironment(Environment::systemEnvironment());
|
||||||
@@ -432,7 +451,6 @@ static void findSystemQt()
|
|||||||
|
|
||||||
void QtVersionManager::addVersion(QtVersion *version)
|
void QtVersionManager::addVersion(QtVersion *version)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_writer, return);
|
|
||||||
QTC_ASSERT(version, return);
|
QTC_ASSERT(version, return);
|
||||||
if (m_versions.contains(version->uniqueId()))
|
if (m_versions.contains(version->uniqueId()))
|
||||||
return;
|
return;
|
||||||
@@ -440,16 +458,16 @@ void QtVersionManager::addVersion(QtVersion *version)
|
|||||||
int uniqueId = version->uniqueId();
|
int uniqueId = version->uniqueId();
|
||||||
m_versions.insert(uniqueId, version);
|
m_versions.insert(uniqueId, version);
|
||||||
|
|
||||||
emit m_instance->qtVersionsChanged(QList<int>() << uniqueId, QList<int>(), QList<int>());
|
emit qtVersionManagerImpl().qtVersionsChanged(QList<int>() << uniqueId, QList<int>(), QList<int>());
|
||||||
saveQtVersions();
|
qtVersionManagerImpl().saveQtVersions();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtVersionManager::removeVersion(QtVersion *version)
|
void QtVersionManager::removeVersion(QtVersion *version)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(version, return);
|
QTC_ASSERT(version, return);
|
||||||
m_versions.remove(version->uniqueId());
|
m_versions.remove(version->uniqueId());
|
||||||
emit m_instance->qtVersionsChanged(QList<int>(), QList<int>() << version->uniqueId(), QList<int>());
|
emit qtVersionManagerImpl().qtVersionsChanged(QList<int>(), QList<int>() << version->uniqueId(), QList<int>());
|
||||||
saveQtVersions();
|
qtVersionManagerImpl().saveQtVersions();
|
||||||
delete version;
|
delete version;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -495,7 +513,7 @@ static QStringList documentationFiles(const QtVersions &vs, bool highestOnly = f
|
|||||||
return filePaths.values();
|
return filePaths.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtVersionManager::updateDocumentation(const QtVersions &added,
|
void QtVersionManagerImpl::updateDocumentation(const QtVersions &added,
|
||||||
const QtVersions &removed,
|
const QtVersions &removed,
|
||||||
const QtVersions &allNew)
|
const QtVersions &allNew)
|
||||||
{
|
{
|
||||||
@@ -519,7 +537,7 @@ void QtVersionManager::updateDocumentation(const QtVersions &added,
|
|||||||
|
|
||||||
int QtVersionManager::getUniqueId()
|
int QtVersionManager::getUniqueId()
|
||||||
{
|
{
|
||||||
return m_idcount++;
|
return qtVersionManagerImpl().m_idcount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
QtVersions QtVersionManager::versions(const QtVersion::Predicate &predicate)
|
QtVersions QtVersionManager::versions(const QtVersion::Predicate &predicate)
|
||||||
@@ -557,6 +575,11 @@ static bool equals(QtVersion *a, QtVersion *b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void QtVersionManager::setNewQtVersions(const QtVersions &newVersions)
|
void QtVersionManager::setNewQtVersions(const QtVersions &newVersions)
|
||||||
|
{
|
||||||
|
qtVersionManagerImpl().setNewQtVersions(newVersions);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QtVersionManagerImpl::setNewQtVersions(const QtVersions &newVersions)
|
||||||
{
|
{
|
||||||
// We want to preserve the same order as in the settings dialog
|
// We want to preserve the same order as in the settings dialog
|
||||||
// so we sort a copy
|
// so we sort a copy
|
||||||
@@ -627,7 +650,7 @@ void QtVersionManager::setNewQtVersions(const QtVersions &newVersions)
|
|||||||
saveQtVersions();
|
saveQtVersions();
|
||||||
|
|
||||||
if (!changedVersions.isEmpty() || !addedVersions.isEmpty() || !removedVersions.isEmpty())
|
if (!changedVersions.isEmpty() || !addedVersions.isEmpty() || !removedVersions.isEmpty())
|
||||||
emit m_instance->qtVersionsChanged(addedIds, removedIds, changedIds);
|
emit qtVersionManagerImpl().qtVersionsChanged(addedIds, removedIds, changedIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtVersionManager::setDocumentationSetting(const QtVersionManager::DocumentationSetting &setting)
|
void QtVersionManager::setDocumentationSetting(const QtVersionManager::DocumentationSetting &setting)
|
||||||
@@ -638,7 +661,7 @@ void QtVersionManager::setDocumentationSetting(const QtVersionManager::Documenta
|
|||||||
// force re-evaluating which documentation should be registered
|
// force re-evaluating which documentation should be registered
|
||||||
// by claiming that all are removed and re-added
|
// by claiming that all are removed and re-added
|
||||||
const QtVersions vs = versions();
|
const QtVersions vs = versions();
|
||||||
updateDocumentation(vs, vs, vs);
|
qtVersionManagerImpl().updateDocumentation(vs, vs, vs);
|
||||||
}
|
}
|
||||||
|
|
||||||
QtVersionManager::DocumentationSetting QtVersionManager::documentationSetting()
|
QtVersionManager::DocumentationSetting QtVersionManager::documentationSetting()
|
||||||
|
@@ -14,12 +14,11 @@ class QTSUPPORT_EXPORT QtVersionManager : public QObject
|
|||||||
// for getUniqueId();
|
// for getUniqueId();
|
||||||
friend class QtVersion;
|
friend class QtVersion;
|
||||||
friend class QtVersionFactory;
|
friend class QtVersionFactory;
|
||||||
|
friend class QtVersionManagerImpl;
|
||||||
friend class Internal::QtOptionsPageWidget;
|
friend class Internal::QtOptionsPageWidget;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static QtVersionManager *instance();
|
static QtVersionManager *instance();
|
||||||
QtVersionManager();
|
|
||||||
~QtVersionManager() override;
|
|
||||||
static void initialized();
|
static void initialized();
|
||||||
|
|
||||||
static bool isLoaded();
|
static bool isLoaded();
|
||||||
@@ -51,15 +50,12 @@ signals:
|
|||||||
void qtVersionsChanged(const QList<int> &addedIds, const QList<int> &removedIds, const QList<int> &changedIds);
|
void qtVersionsChanged(const QList<int> &addedIds, const QList<int> &removedIds, const QList<int> &changedIds);
|
||||||
void qtVersionsLoaded();
|
void qtVersionsLoaded();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QtVersionManager() = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum class DocumentationSetting { HighestOnly, All, None };
|
enum class DocumentationSetting { HighestOnly, All, None };
|
||||||
|
|
||||||
static void updateDocumentation(const QtVersions &added,
|
|
||||||
const QtVersions &removed,
|
|
||||||
const QtVersions &allNew);
|
|
||||||
void updateFromInstaller(bool emitSignal = true);
|
|
||||||
void triggerQtVersionRestore();
|
|
||||||
|
|
||||||
// Used by QtOptionsPage
|
// Used by QtOptionsPage
|
||||||
static void setNewQtVersions(const QtVersions &newVersions);
|
static void setNewQtVersions(const QtVersions &newVersions);
|
||||||
static void setDocumentationSetting(const DocumentationSetting &setting);
|
static void setDocumentationSetting(const DocumentationSetting &setting);
|
||||||
|
Reference in New Issue
Block a user