Commit 0ebd74d6 authored by Tobias Hunger's avatar Tobias Hunger

Qt4: Pick up Qt versions as they are updated by the installer

Pick up Qt version changes as they are written into the qtversion.xml
file by the installer.

Change-Id: I6cf9f96242d2a7af08c6207be32beeb15e7891df
Reviewed-by: default avatarDaniel Teske <daniel.teske@nokia.com>
parent 10fef6a3
......@@ -101,8 +101,7 @@ QIcon QtOptionsPage::categoryIcon() const
QWidget *QtOptionsPage::createPage(QWidget *parent)
{
QtVersionManager *vm = QtVersionManager::instance();
m_widget = new QtOptionsPageWidget(parent, vm->versions());
m_widget = new QtOptionsPageWidget(parent);
if (m_searchKeywords.isEmpty())
m_searchKeywords = m_widget->searchKeywords();
return m_widget;
......@@ -126,7 +125,7 @@ bool QtOptionsPage::matches(const QString &s) const
//-----------------------------------------------------
QtOptionsPageWidget::QtOptionsPageWidget(QWidget *parent, QList<BaseQtVersion *> versions)
QtOptionsPageWidget::QtOptionsPageWidget(QWidget *parent)
: QWidget(parent)
, m_specifyNameString(tr("<specify a name>"))
, m_ui(new Internal::Ui::QtVersionManager())
......@@ -135,11 +134,9 @@ QtOptionsPageWidget::QtOptionsPageWidget(QWidget *parent, QList<BaseQtVersion *>
, m_invalidVersionIcon(QLatin1String(":/projectexplorer/images/compile_error.png"))
, m_warningVersionIcon(QLatin1String(":/projectexplorer/images/compile_warning.png"))
, m_configurationWidget(0)
, m_autoItem(0)
, m_manualItem(0)
{
// Initialize m_versions
foreach (BaseQtVersion *version, versions)
m_versions.push_back(version->clone());
QWidget *versionInfoWidget = new QWidget();
m_versionUi->setupUi(versionInfoWidget);
m_versionUi->editPathPushButton->setText(tr(Utils::PathChooser::browseButtonLabel));
......@@ -160,26 +157,23 @@ QtOptionsPageWidget::QtOptionsPageWidget(QWidget *parent, QList<BaseQtVersion *>
m_ui->qtdirList->header()->setResizeMode(QHeaderView::ResizeToContents);
m_ui->qtdirList->header()->setStretchLastSection(false);
m_ui->qtdirList->setTextElideMode(Qt::ElideNone);
QTreeWidgetItem *autoItem = new QTreeWidgetItem(m_ui->qtdirList);
m_autoItem = new QTreeWidgetItem(m_ui->qtdirList);
m_ui->qtdirList->installEventFilter(this);
autoItem->setText(0, tr("Auto-detected"));
autoItem->setFirstColumnSpanned(true);
autoItem->setFlags(Qt::ItemIsEnabled);
QTreeWidgetItem *manualItem = new QTreeWidgetItem(m_ui->qtdirList);
manualItem->setText(0, tr("Manual"));
manualItem->setFirstColumnSpanned(true);
manualItem->setFlags(Qt::ItemIsEnabled);
m_autoItem->setText(0, tr("Auto-detected"));
m_autoItem->setFirstColumnSpanned(true);
m_autoItem->setFlags(Qt::ItemIsEnabled);
m_manualItem = new QTreeWidgetItem(m_ui->qtdirList);
m_manualItem->setText(0, tr("Manual"));
m_manualItem->setFirstColumnSpanned(true);
m_manualItem->setFlags(Qt::ItemIsEnabled);
QList<int> additions;
QList<BaseQtVersion *> versions = QtVersionManager::instance()->versions();
foreach (BaseQtVersion *v, versions)
additions.append(v->uniqueId());
updateQtVersions(additions, QList<int>(), QList<int>());
for (int i = 0; i < m_versions.count(); ++i) {
BaseQtVersion *version = m_versions.at(i);
QTreeWidgetItem *item = new QTreeWidgetItem(version->isAutodetected()? autoItem : manualItem);
item->setText(0, version->displayName());
item->setText(1, version->qmakeCommand().toUserOutput());
item->setData(0, VersionIdRole, version->uniqueId());
item->setData(0, ToolChainIdRole, defaultToolChainId(version));
const ValidityInfo info = validInformation(version);
item->setIcon(0, info.icon);
}
m_ui->qtdirList->expandAll();
connect(m_versionUi->nameEdit, SIGNAL(textEdited(QString)),
......@@ -219,6 +213,9 @@ QtOptionsPageWidget::QtOptionsPageWidget(QWidget *parent, QList<BaseQtVersion *>
connect(QtVersionManager::instance(), SIGNAL(dumpUpdatedFor(Utils::FileName)),
this, SLOT(qtVersionsDumpUpdated(Utils::FileName)));
connect(QtVersionManager::instance(), SIGNAL(qtVersionsChanged(QList<int>,QList<int>,QList<int>)),
this, SLOT(updateQtVersions(QList<int>,QList<int>,QList<int>)));
connect(ProjectExplorer::ToolChainManager::instance(), SIGNAL(toolChainsChanged()),
this, SLOT(toolChainsUpdated()));
}
......@@ -567,6 +564,73 @@ void QtOptionsPageWidget::showDebuggingBuildLog(const QTreeWidgetItem *currentIt
dialog->show();
}
void QtOptionsPageWidget::updateQtVersions(const QList<int> &additions, const QList<int> &removals,
const QList<int> &changes)
{
QtVersionManager *vm = QtVersionManager::instance();
QList<QTreeWidgetItem *> toRemove;
QList<int> toAdd = additions;
// Generate list of all existing items:
QList<QTreeWidgetItem *> itemList;
for (int i = 0; i < m_autoItem->childCount(); ++i)
itemList.append(m_autoItem->child(i));
for (int i = 0; i < m_manualItem->childCount(); ++i)
itemList.append(m_manualItem->child(i));
// Find existing items to remove/change:
foreach (QTreeWidgetItem *item, itemList) {
int id = item->data(0, VersionIdRole).toInt();
if (removals.contains(id)) {
toRemove.append(item);
continue;
}
if (changes.contains(id)) {
toAdd.append(id);
toRemove.append(item);
continue;
}
}
// Remove changed/removed items:
foreach (QTreeWidgetItem *item, toRemove) {
int index = indexForTreeItem(item);
delete m_versions.at(index);
m_versions.removeAt(index);
delete item;
}
// Add changed/added items:
foreach (int a, toAdd) {
BaseQtVersion *version = vm->version(a)->clone();
m_versions.append(version);
QTreeWidgetItem *item = new QTreeWidgetItem;
item->setText(0, version->displayName());
item->setText(1, version->qmakeCommand().toUserOutput());
item->setData(0, VersionIdRole, version->uniqueId());
item->setData(0, ToolChainIdRole, defaultToolChainId(version));
const ValidityInfo info = validInformation(version);
item->setIcon(0, info.icon);
// Insert in the right place:
QTreeWidgetItem *parent = version->isAutodetected()? m_autoItem : m_manualItem;
for (int i = 0; i < parent->childCount(); ++i) {
BaseQtVersion *currentVersion = m_versions.at(indexForTreeItem(parent->child(i)));
if (currentVersion->qtVersion() > version->qtVersion())
continue;
parent->insertChild(i, item);
parent = 0;
break;
}
if (parent)
parent->addChild(item);
}
}
QtOptionsPageWidget::~QtOptionsPageWidget()
{
delete m_ui;
......
......@@ -64,7 +64,7 @@ class QtOptionsPageWidget : public QWidget
Q_OBJECT
public:
QtOptionsPageWidget(QWidget *parent, QList<BaseQtVersion *> versions);
QtOptionsPageWidget(QWidget *parent);
~QtOptionsPageWidget();
QList<BaseQtVersion *> versions() const;
void finish();
......@@ -97,6 +97,7 @@ private:
QtConfigWidget *m_configurationWidget;
private slots:
void updateQtVersions(const QList<int> &, const QList<int> &, const QList<int> &);
void qtVersionChanged();
void versionChanged(QTreeWidgetItem *item, QTreeWidgetItem *old);
void addQtDir();
......@@ -129,6 +130,9 @@ private:
ValidityInfo validInformation(const BaseQtVersion *version);
QList<ProjectExplorer::ToolChain*> toolChains(const BaseQtVersion *version);
QString defaultToolChainId(const BaseQtVersion *verison);
QTreeWidgetItem *m_autoItem;
QTreeWidgetItem *m_manualItem;
};
class QtOptionsPage : public Core::IOptionsPage
......
......@@ -48,6 +48,7 @@
#include <extensionsystem/pluginmanager.h>
#include <utils/filesystemwatcher.h>
#include <utils/persistentsettings.h>
#include <utils/qtcprocess.h>
#include <utils/qtcassert.h>
......@@ -98,6 +99,13 @@ static T *createToolChain(const QString &id)
return 0;
}
static QString globalSettingsFileName()
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
return QFileInfo(pm->globalSettings()->fileName()).absolutePath()
+ QLatin1String(QTVERSION_FILENAME);
}
static QString settingsFileName()
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
......@@ -139,6 +147,12 @@ void QtVersionManager::extensionsInitialized()
}
saveQtVersions();
m_configFileWatcher = new Utils::FileSystemWatcher(this);
connect(m_configFileWatcher, SIGNAL(fileChanged(QString)),
this, SLOT(updateFromInstaller()));
m_configFileWatcher->addFile(globalSettingsFileName(), Utils::FileSystemWatcher::WatchModifiedDate);
}
bool QtVersionManager::delayedInitialize()
......@@ -211,11 +225,17 @@ bool QtVersionManager::restoreQtVersions()
void QtVersionManager::updateFromInstaller()
{
// Handle overwritting of data:
if (m_configFileWatcher) {
const QString path = globalSettingsFileName();
m_configFileWatcher->removeFile(path);
m_configFileWatcher->addFile(path, Utils::FileSystemWatcher::WatchModifiedDate);
}
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
QList<QtVersionFactory *> factories = pm->getObjects<QtVersionFactory>();
Utils::PersistentSettingsReader reader;
if (!reader.load(QFileInfo(pm->globalSettings()->fileName()).absolutePath()
+ QLatin1String(QTVERSION_FILENAME)))
if (!reader.load(globalSettingsFileName()))
return;
QVariantMap data = reader.restoreValues();
......
......@@ -39,6 +39,8 @@
#include <QSet>
#include <QStringList>
namespace Utils { class FileSystemWatcher; }
namespace QtSupport {
namespace Internal {
class QtOptionsPage;
......@@ -113,6 +115,9 @@ signals:
public slots:
void updateDumpFor(const Utils::FileName &qmakeCommand);
private slots:
void updateFromInstaller();
private:
// This function is really simplistic...
static bool equals(BaseQtVersion *a, BaseQtVersion *b);
......@@ -127,7 +132,6 @@ private:
bool restoreQtVersions();
bool legacyRestore();
void findSystemQt();
void updateFromInstaller();
void saveQtVersions();
void updateDocumentation();
// Used by QtOptionsPage
......@@ -147,6 +151,8 @@ private:
// Compatibility with pre-2.2:
QStringList m_pendingMwcUpdates;
QStringList m_pendingGcceUpdates;
Utils::FileSystemWatcher *m_configFileWatcher;
};
namespace Internal {
......
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