Skip to content
Snippets Groups Projects
Commit 0d23d2d4 authored by Kai Koehne's avatar Kai Koehne
Browse files

Move management of 'selected' Qt version to ExamplesListModel


Change-Id: Ia4c73a0e9985e968265d7698e3a0a3cc58dc7aaa
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent dc72ebd2
No related branches found
No related tags found
No related merge requests found
......@@ -71,60 +71,17 @@ QtVersionsModel::QtVersionsModel(ExamplesListModel *examplesModel, QObject *pare
roleNames[Qt::UserRole + 1] = "text";
roleNames[Qt::UserRole + 2] = "QtId";
setRoleNames(roleNames);
}
int QtVersionsModel::findHighestQtVersion()
{
QList<BaseQtVersion *> qtVersions = examplesModel->qtVersions();
BaseQtVersion *newVersion = 0;
foreach (BaseQtVersion *version, qtVersions) {
if (!newVersion) {
newVersion = version;
} else {
if (version->qtVersion() > newVersion->qtVersion()) {
newVersion = version;
} else if (version->qtVersion() == newVersion->qtVersion()
&& version->uniqueId() < newVersion->uniqueId()) {
newVersion = version;
}
}
}
if (!newVersion && !qtVersions.isEmpty())
newVersion = qtVersions.first();
if (!newVersion)
return noQtVersionsId;
return newVersion->uniqueId();
connect(examplesModel, SIGNAL(qtVersionsUpdated()), this, SLOT(update()));
}
void QtVersionsModel::setupQtVersions()
void QtVersionsModel::update()
{
beginResetModel();
clear();
QList<BaseQtVersion *> qtVersions = examplesModel->qtVersions();
int qtVersionSetting = uniqueQtVersionIdSetting();
int newQtVersionSetting = noQtVersionsId;
if (qtVersionSetting != noQtVersionsId) {
//ensure that the unique Qt id is valid
foreach (BaseQtVersion *version, qtVersions) {
if (version->uniqueId() == qtVersionSetting)
newQtVersionSetting = qtVersionSetting;
}
}
if (newQtVersionSetting == noQtVersionsId)
newQtVersionSetting = findHighestQtVersion();
if (newQtVersionSetting != qtVersionSetting)
setUniqueQtVersionIdSetting(newQtVersionSetting);
foreach (BaseQtVersion *version, qtVersions) {
QStandardItem *newItem = new QStandardItem();
newItem->setData(version->displayName(), Qt::UserRole + 1);
......@@ -458,8 +415,7 @@ void ExamplesListModel::updateExamples()
emit tagsUpdated();
}
QList<QtSupport::BaseQtVersion*> ExamplesListModel::qtVersions() const
void ExamplesListModel::updateQtVersions()
{
QList<BaseQtVersion*> versions = QtVersionManager::validVersions();
......@@ -477,7 +433,59 @@ QList<QtSupport::BaseQtVersion*> ExamplesListModel::qtVersions() const
if (defaultVersion && versions.contains(defaultVersion))
versions.move(versions.indexOf(defaultVersion), 0);
return versions;
if (m_qtVersions == versions)
return;
m_qtVersions = versions;
emit qtVersionsUpdated();
// determine Qt version to show
int newUniqueId = noQtVersionsId;
if (m_uniqueQtId != noQtVersionsId) {
//ensure that the unique Qt id is valid
foreach (BaseQtVersion *version, m_qtVersions) {
if (version->uniqueId() == m_uniqueQtId)
newUniqueId = m_uniqueQtId;
}
}
if (newUniqueId == noQtVersionsId)
newUniqueId = findHighestQtVersion();
if (newUniqueId != m_uniqueQtId) {
m_uniqueQtId = newUniqueId;
setUniqueQtVersionIdSetting(m_uniqueQtId);
emit selectedQtVersionChanged();
}
}
int ExamplesListModel::findHighestQtVersion() const
{
QList<BaseQtVersion *> versions = qtVersions();
BaseQtVersion *newVersion = 0;
foreach (BaseQtVersion *version, versions) {
if (!newVersion) {
newVersion = version;
} else {
if (version->qtVersion() > newVersion->qtVersion()) {
newVersion = version;
} else if (version->qtVersion() == newVersion->qtVersion()
&& version->uniqueId() < newVersion->uniqueId()) {
newVersion = version;
}
}
}
if (!newVersion && !versions.isEmpty())
newVersion = versions.first();
if (!newVersion)
return noQtVersionsId;
return newVersion->uniqueId();
}
QStringList ExamplesListModel::exampleSources(QString *examplesInstallPath, QString *demosInstallPath,
......@@ -650,12 +658,27 @@ QStringList ExamplesListModel::tags() const
return m_tags;
}
void ExamplesListModel::setUniqueQtId(int id)
void ExamplesListModel::update()
{
m_uniqueQtId = id;
updateQtVersions();
updateExamples();
}
int ExamplesListModel::selectedQtVersion() const
{
return m_uniqueQtId;
}
void ExamplesListModel::selectQtVersion(int id)
{
if (m_uniqueQtId != id) {
m_uniqueQtId = id;
setUniqueQtVersionIdSetting(id);
updateExamples();
emit selectedQtVersionChanged();
}
}
ExamplesListModelFilter::ExamplesListModelFilter(ExamplesListModel *sourceModel, QObject *parent) :
QSortFilterProxyModel(parent),
m_showTutorialsOnly(true),
......@@ -676,6 +699,8 @@ ExamplesListModelFilter::ExamplesListModelFilter(ExamplesListModel *sourceModel,
connect(this, SIGNAL(showTutorialsOnlyChanged()), SLOT(updateFilter()));
connect(m_sourceModel, SIGNAL(selectedQtVersionChanged()), this, SIGNAL(qtVersionIndexChanged()));
setSourceModel(m_sourceModel);
}
......@@ -764,8 +789,7 @@ void ExamplesListModelFilter::filterForQtById(int id)
if (m_blockIndexUpdate || !m_initalized)
return;
setUniqueQtVersionIdSetting(id);
m_sourceModel->setUniqueQtId(id);
m_sourceModel->selectQtVersion(id);
}
void ExamplesListModelFilter::setShowTutorialsOnly(bool showTutorialsOnly)
......@@ -777,9 +801,7 @@ void ExamplesListModelFilter::setShowTutorialsOnly(bool showTutorialsOnly)
void ExamplesListModelFilter::handleQtVersionsChanged()
{
m_blockIndexUpdate = true;
m_qtVersionModel->setupQtVersions();
m_sourceModel->updateExamples();
emit qtVersionIndexChanged();
m_sourceModel->update();
m_blockIndexUpdate = false;
}
......@@ -812,7 +834,6 @@ void ExamplesListModelFilter::tryToInitialize()
connect(ProjectExplorer::KitManager::instance(), SIGNAL(defaultkitChanged()),
this, SLOT(handleQtVersionsChanged()));
handleQtVersionsChanged();
m_sourceModel->updateExamples();
}
}
......@@ -826,8 +847,8 @@ void ExamplesListModelFilter::delayedUpdateFilter()
int ExamplesListModelFilter::qtVersionIndex() const
{
int id = uniqueQtVersionIdSetting();
int index = m_qtVersionModel->indexForUniqueId(id);
int id = m_sourceModel->selectedQtVersion();
int index = m_qtVersionModel->indexForUniqueId(id);
return index;
}
......
......@@ -49,11 +49,11 @@ class QtVersionsModel : public QStandardItemModel
public:
QtVersionsModel(ExamplesListModel *examplesModel, QObject *parent);
int findHighestQtVersion();
void setupQtVersions();
int indexForUniqueId(int uniqueId);
public slots:
void update();
QVariant get(int i);
QVariant getId(int i);
......@@ -110,15 +110,25 @@ public:
void beginReset() { beginResetModel(); }
void endReset() { endResetModel(); }
void setUniqueQtId(int id);
void updateExamples();
void update();
int selectedQtVersion() const;
void selectQtVersion(int id);
QList<BaseQtVersion*> qtVersions() const;
QList<BaseQtVersion*> qtVersions() const { return m_qtVersions; }
signals:
void qtVersionsUpdated();
void selectedQtVersionChanged();
void tagsUpdated();
private:
void updateQtVersions();
void updateExamples();
void updateSelectedQtVersion();
int findHighestQtVersion() const;
void parseExamples(QXmlStreamReader *reader, const QString &projectsOffset,
const QString &examplesInstallPath);
void parseDemos(QXmlStreamReader *reader, const QString &projectsOffset,
......@@ -128,6 +138,7 @@ private:
QString *examplesFallback, QString *demosFallback,
QString *sourceFallback);
QList<BaseQtVersion*> m_qtVersions;
QList<ExampleItem> m_exampleItems;
QStringList m_tags;
int m_uniqueQtId;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment