Commit 09533783 authored by dt's avatar dt

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.
parent b6c05a33
......@@ -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;
......
......@@ -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>"))
{
......
......@@ -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
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