From 095337836ad9b947d3e7d61ae0948537d2517285 Mon Sep 17 00:00:00 2001 From: dt <qtc-committer@nokia.com> Date: Wed, 22 Apr 2009 18:05:55 +0200 Subject: [PATCH] Refactoring: Split up QtVersionManager into gui and non gui The settings page does not need to be exported and should be seperate from the actual manager. This also makes further refactorings of QtVersionManager easier and of QtDirWidget. More to come. --- .../projectexplorer/projectexplorer.cpp | 2 + .../projectexplorer/qtversionmanager.cpp | 147 ++++++++++-------- .../projectexplorer/qtversionmanager.h | 41 ++--- 3 files changed, 108 insertions(+), 82 deletions(-) diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 6fbb3cc32b8..af4beb1ecbc 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -198,6 +198,8 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er m_versionManager = new QtVersionManager(); addAutoReleasedObject(m_versionManager); + addAutoReleasedObject(new QtOptionsPage()); + addAutoReleasedObject(new CoreListenerCheckingForRunningBuild(m_buildManager)); m_outputPane = new OutputPane; diff --git a/src/plugins/projectexplorer/qtversionmanager.cpp b/src/plugins/projectexplorer/qtversionmanager.cpp index 67a8ffbb658..acaa49e359b 100644 --- a/src/plugins/projectexplorer/qtversionmanager.cpp +++ b/src/plugins/projectexplorer/qtversionmanager.cpp @@ -115,7 +115,7 @@ QtVersionManager::~QtVersionManager() m_emptyVersion = 0; } -QtVersionManager::QtVersionManager *instance() +QtVersionManager *QtVersionManager::instance() { return ProjectExplorerPlugin::instance()->qtVersionManager(); } @@ -147,32 +147,6 @@ int QtVersionManager::getUniqueId() return m_idcount++; } -QString QtVersionManager::id() const -{ - return QLatin1String(Constants::QTVERSION_PAGE); -} - -QString QtVersionManager::trName() const -{ - return tr(Constants::QTVERSION_PAGE); -} - -QString QtVersionManager::category() const -{ - return Constants::QT_CATEGORY; -} - -QString QtVersionManager::trCategory() const -{ - return tr(Constants::QT_CATEGORY); -} - -QWidget *QtVersionManager::createPage(QWidget *parent) -{ - m_widget = new QtDirWidget(parent, m_versions, m_defaultVersion); - return m_widget; -} - void QtVersionManager::updateUniqueIdToIndexMap() { m_uniqueIdToIndex.clear(); @@ -180,40 +154,6 @@ void QtVersionManager::updateUniqueIdToIndexMap() m_uniqueIdToIndex.insert(m_versions.at(i)->uniqueId(), i); } -void QtVersionManager::apply() -{ - m_widget->finish(); - QList<QtVersion*> newVersions = m_widget->versions(); - bool versionPathsChanged = m_versions.size() != newVersions.size(); - if (!versionPathsChanged) { - for (int i = 0; i < m_versions.size(); ++i) { - if (m_versions.at(i)->path() != newVersions.at(i)->path()) { - versionPathsChanged = true; - break; - } - } - } - qDeleteAll(m_versions); - m_versions.clear(); - foreach(QtVersion *version, m_widget->versions()) - m_versions.append(new QtVersion(*version)); - if (versionPathsChanged) - updateDocumentation(); - updateUniqueIdToIndexMap(); - - bool emitDefaultChanged = false; - if (m_defaultVersion != m_widget->defaultVersion()) { - m_defaultVersion = m_widget->defaultVersion(); - emitDefaultChanged = true; - } - - emit qtVersionsChanged(); - if (emitDefaultChanged) - emit defaultQtVersionChanged(); - - writeVersionsIntoSettings(); -} - void QtVersionManager::writeVersionsIntoSettings() { QSettings *s = Core::ICore::instance()->settings(); @@ -383,10 +323,91 @@ QtVersion *QtVersionManager::currentQtVersion() const return m_emptyVersion; } +void QtVersionManager::setNewQtVersions(QList<QtVersion *> newVersions, int newDefaultVersion) +{ + bool versionPathsChanged = m_versions.size() != newVersions.size(); + if (!versionPathsChanged) { + for (int i = 0; i < m_versions.size(); ++i) { + if (m_versions.at(i)->path() != newVersions.at(i)->path()) { + versionPathsChanged = true; + break; + } + } + } + qDeleteAll(m_versions); + m_versions.clear(); + foreach(QtVersion *version, newVersions) + m_versions.append(new QtVersion(*version)); + if (versionPathsChanged) + updateDocumentation(); + updateUniqueIdToIndexMap(); + + bool emitDefaultChanged = false; + if (m_defaultVersion != newDefaultVersion) { + m_defaultVersion = newDefaultVersion; + emitDefaultChanged = true; + } + + emit qtVersionsChanged(); + if (emitDefaultChanged) + emit defaultQtVersionChanged(); + + writeVersionsIntoSettings(); +} + +/// +// QtOptionsPage +/// + +QtOptionsPage::QtOptionsPage() +{ + +} + +QtOptionsPage::~QtOptionsPage() +{ + +} + +QString QtOptionsPage::id() const +{ + return QLatin1String(Constants::QTVERSION_PAGE); +} + +QString QtOptionsPage::trName() const +{ + return tr(Constants::QTVERSION_PAGE); +} + +QString QtOptionsPage::category() const +{ + return Constants::QT_CATEGORY; +} + +QString QtOptionsPage::trCategory() const +{ + return tr(Constants::QT_CATEGORY); +} + +QWidget *QtOptionsPage::createPage(QWidget *parent) +{ + QtVersionManager *vm = QtVersionManager::instance(); + m_widget = new QtDirWidget(parent, vm->versions(), vm->currentQtVersion()); + return m_widget; +} + +void QtOptionsPage::apply() +{ + m_widget->finish(); + + QtVersionManager *vm = QtVersionManager::instance(); + vm->setNewQtVersions(m_widget->versions(), m_widget->defaultVersion()); +} + //----------------------------------------------------- -QtDirWidget::QtDirWidget(QWidget *parent, QList<QtVersion *> versions, int defaultVersion) +QtDirWidget::QtDirWidget(QWidget *parent, QList<QtVersion *> versions, QtVersion *defaultVersion) : QWidget(parent) - , m_defaultVersion(defaultVersion) + , m_defaultVersion(versions.indexOf(defaultVersion)) , m_specifyNameString(tr("<specify a name>")) , m_specifyPathString(tr("<specify a path>")) { diff --git a/src/plugins/projectexplorer/qtversionmanager.h b/src/plugins/projectexplorer/qtversionmanager.h index 1721719c1a2..c1db4c5a2b2 100644 --- a/src/plugins/projectexplorer/qtversionmanager.h +++ b/src/plugins/projectexplorer/qtversionmanager.h @@ -135,7 +135,7 @@ class QtDirWidget : public QWidget { Q_OBJECT public: - QtDirWidget(QWidget *parent, QList<QtVersion *> versions, int defaultVersion); + QtDirWidget(QWidget *parent, QList<QtVersion *> versions, QtVersion *defaultVersion); ~QtDirWidget(); QList<QtVersion *> versions() const; int defaultVersion() const; @@ -168,45 +168,33 @@ private slots: void showDebuggingBuildLog(); }; -class PROJECTEXPLORER_EXPORT QtVersionManager : public Core::IOptionsPage +class PROJECTEXPLORER_EXPORT QtVersionManager : public QObject { Q_OBJECT public: + static QtVersionManager *instance(); QtVersionManager(); ~QtVersionManager(); - - static QtVersionManager *instance(); - - QString id() const; - QString trName() const; - QString category() const; - QString trCategory() const; - - QWidget *createPage(QWidget *parent); - void apply(); - void finish() { } - void writeVersionsIntoSettings(); QList<QtVersion *> versions() const; QtVersion * version(int id) const; QtVersion * currentQtVersion() const; - // internal int getUniqueId(); QtVersion::QmakeBuildConfig scanMakefileForQmakeConfig(const QString &directory, QtVersion::QmakeBuildConfig defaultBuildConfig); QString findQtVersionFromMakefile(const QString &directory); QtVersion *qtVersionForDirectory(const QString &directory); - // Used by the projectloadwizard void addVersion(QtVersion *version); - + // returns something like qmake4, qmake, qmake-qt4 or whatever distributions have chosen (used by QtVersion) static QStringList possibleQMakeCommands(); // return true if the qmake at qmakePath is qt4 (used by QtVersion) static QString qtVersionForQMake(const QString &qmakePath); + void setNewQtVersions(QList<QtVersion *> newVersions, int newDefaultVersion); signals: void defaultQtVersionChanged(); void qtVersionsChanged(); @@ -218,14 +206,29 @@ private: static int indexOfVersionInList(const QtVersion * const version, const QList<QtVersion *> &list); void updateUniqueIdToIndexMap(); - QtDirWidget *m_widget; - QtVersion *m_emptyVersion; int m_defaultVersion; QList<QtVersion *> m_versions; QMap<int, int> m_uniqueIdToIndex; int m_idcount; }; + +class PROJECTEXPLORER_EXPORT QtOptionsPage : public Core::IOptionsPage +{ + Q_OBJECT +public: + QtOptionsPage(); + ~QtOptionsPage(); + QString id() const; + QString trName() const; + QString category() const; + QString trCategory() const; + QWidget *createPage(QWidget *parent); + void apply(); + void finish() { } +private: + QtDirWidget *m_widget; +}; } // namespace ProjectExplorer #endif // QTVERSIONMANAGER_H -- GitLab