WelcomePage: bug fix for example view

We have to wait for all of the QtVersionManager and HelpManager to
be initialized, and some data actually being requested from the
examples model, before showing any examples.

Task-number: QTBUG-33924

Change-Id: I189710374f4af8d7d9cbe4731fa3faafd0623ffb
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
This commit is contained in:
Thomas Hartmann
2013-10-15 13:21:17 +02:00
committed by Eike Ziller
parent 94b8695575
commit fe47725ae6
2 changed files with 80 additions and 84 deletions

View File

@@ -110,11 +110,6 @@ public:
void setupQtVersions() void setupQtVersions()
{ {
if (!QtVersionManager::isLoaded()) {
connect(QtVersionManager::instance(), SIGNAL(qtVersionsLoaded()), this, SLOT(qtVersionManagerLoaded()));
return;
}
beginResetModel(); beginResetModel();
clear(); clear();
@@ -178,18 +173,10 @@ public slots:
QVariant variant = data(modelIndex, Qt::UserRole + 2); QVariant variant = data(modelIndex, Qt::UserRole + 2);
return variant; return variant;
} }
void qtVersionManagerLoaded()
{
disconnect(QtVersionManager::instance(), SIGNAL(qtVersionsLoaded()), this, SLOT(qtVersionManagerLoaded()));
setupQtVersions();
}
}; };
ExamplesListModel::ExamplesListModel(QObject *parent) : ExamplesListModel::ExamplesListModel(QObject *parent) :
QAbstractListModel(parent), QAbstractListModel(parent),
m_updateOnQtVersionsChanged(false),
m_initialized(false),
m_helpInitialized(false),
m_uniqueQtId(noQtVersionsId) m_uniqueQtId(noQtVersionsId)
{ {
QHash<int, QByteArray> roleNames; QHash<int, QByteArray> roleNames;
@@ -210,13 +197,6 @@ ExamplesListModel::ExamplesListModel(QObject *parent) :
roleNames[Platforms] = "platforms"; roleNames[Platforms] = "platforms";
roleNames[IsHighlighted] = "isHighlighted"; roleNames[IsHighlighted] = "isHighlighted";
setRoleNames(roleNames); setRoleNames(roleNames);
connect(Core::HelpManager::instance(), SIGNAL(setupFinished()),
SLOT(helpInitialized()));
connect(QtVersionManager::instance(), SIGNAL(qtVersionsChanged(QList<int>,QList<int>,QList<int>)),
this, SLOT(handleQtVersionsChanged()));
connect(ProjectExplorer::KitManager::instance(), SIGNAL(defaultkitChanged()),
SLOT(handleQtVersionsChanged()));
} }
static QString fixStringForTags(const QString &string) static QString fixStringForTags(const QString &string)
@@ -430,14 +410,6 @@ void ExamplesListModel::parseTutorials(QXmlStreamReader *reader, const QString &
} }
} }
void ExamplesListModel::handleQtVersionsChanged()
{
if (m_updateOnQtVersionsChanged) {
emit qtVersionsChanged();
updateExamples();
}
}
void ExamplesListModel::updateExamples() void ExamplesListModel::updateExamples()
{ {
QString examplesInstallPath; QString examplesInstallPath;
@@ -541,7 +513,6 @@ QStringList ExamplesListModel::exampleSources(QString *examplesInstallPath, QStr
return sources; return sources;
// try to find a suitable Qt version // try to find a suitable Qt version
m_updateOnQtVersionsChanged = true; // this must be updated when the Qt versions change
// fallbacks are passed back if no example manifest is found // fallbacks are passed back if no example manifest is found
// and we fallback to Qt Creator's shipped manifest (e.g. only old Qt Versions found) // and we fallback to Qt Creator's shipped manifest (e.g. only old Qt Versions found)
QString potentialExamplesFallback; QString potentialExamplesFallback;
@@ -623,7 +594,6 @@ QStringList ExamplesListModel::exampleSources(QString *examplesInstallPath, QStr
int ExamplesListModel::rowCount(const QModelIndex &) const int ExamplesListModel::rowCount(const QModelIndex &) const
{ {
ensureInitialized();
return m_exampleItems.size(); return m_exampleItems.size();
} }
@@ -636,7 +606,6 @@ QString prefixForItem(const ExampleItem &item)
QVariant ExamplesListModel::data(const QModelIndex &index, int role) const QVariant ExamplesListModel::data(const QModelIndex &index, int role) const
{ {
ensureInitialized();
if (!index.isValid() || index.row()+1 > m_exampleItems.count()) { if (!index.isValid() || index.row()+1 > m_exampleItems.count()) {
qDebug() << Q_FUNC_INFO << "invalid index requested"; qDebug() << Q_FUNC_INFO << "invalid index requested";
return QVariant(); return QVariant();
@@ -685,37 +654,17 @@ QVariant ExamplesListModel::data(const QModelIndex &index, int role) const
} }
} }
// TODO global tag list is unused, remove
QStringList ExamplesListModel::tags() const QStringList ExamplesListModel::tags() const
{ {
ensureInitialized();
return m_tags; return m_tags;
} }
void ExamplesListModel::helpInitialized() void ExamplesListModel::setUniqueQtId(int id)
{ {
m_helpInitialized = true;
if (m_initialized) // if we are already initialized we need to update nevertheless
updateExamples();
}
void ExamplesListModel::ensureInitialized() const
{
if (m_initialized || !m_helpInitialized)
return;
ExamplesListModel *that = const_cast<ExamplesListModel *>(this);
that->m_initialized = true;
that->updateExamples();
emit that->qtVersionsChanged();
}
void ExamplesListModel::filterForQtById(int id)
{
if (QtVersionManager::isLoaded()) {
m_uniqueQtId = id; m_uniqueQtId = id;
setUniqueQtVersionIdSetting(id);
updateExamples(); updateExamples();
} }
}
ExamplesListModelFilter::ExamplesListModelFilter(ExamplesListModel *sourceModel, QObject *parent) : ExamplesListModelFilter::ExamplesListModelFilter(ExamplesListModel *sourceModel, QObject *parent) :
QSortFilterProxyModel(parent), QSortFilterProxyModel(parent),
@@ -723,12 +672,21 @@ ExamplesListModelFilter::ExamplesListModelFilter(ExamplesListModel *sourceModel,
m_sourceModel(sourceModel), m_sourceModel(sourceModel),
m_timerId(0), m_timerId(0),
m_qtVersionModel(new QtVersionsModel(this)), m_qtVersionModel(new QtVersionsModel(this)),
m_blockIndexUpdate(false) m_blockIndexUpdate(false),
m_qtVersionManagerInitialized(false),
m_helpManagerInitialized(false),
m_initalized(false),
m_exampleDataRequested(false)
{ {
// initialization hooks
connect(QtVersionManager::instance(), SIGNAL(qtVersionsLoaded()),
this, SLOT(qtVersionManagerLoaded()));
connect(Core::HelpManager::instance(), SIGNAL(setupFinished()),
this, SLOT(helpManagerInitialized()));
connect(this, SIGNAL(showTutorialsOnlyChanged()), SLOT(updateFilter())); connect(this, SIGNAL(showTutorialsOnlyChanged()), SLOT(updateFilter()));
connect(sourceModel, SIGNAL(qtVersionsChanged()), SLOT(handleQtVersionsChanged()));
setSourceModel(m_sourceModel); setSourceModel(m_sourceModel);
m_qtVersionModel->setupQtVersions();
} }
void ExamplesListModelFilter::updateFilter() void ExamplesListModelFilter::updateFilter()
@@ -796,13 +754,13 @@ bool ExamplesListModelFilter::filterAcceptsRow(int sourceRow, const QModelIndex
int ExamplesListModelFilter::rowCount(const QModelIndex &parent) const int ExamplesListModelFilter::rowCount(const QModelIndex &parent) const
{ {
m_sourceModel->ensureInitialized(); exampleDataRequested();
return QSortFilterProxyModel::rowCount(parent); return QSortFilterProxyModel::rowCount(parent);
} }
QVariant ExamplesListModelFilter::data(const QModelIndex &index, int role) const QVariant ExamplesListModelFilter::data(const QModelIndex &index, int role) const
{ {
m_sourceModel->ensureInitialized(); exampleDataRequested();
return QSortFilterProxyModel::data(index, role); return QSortFilterProxyModel::data(index, role);
} }
@@ -811,6 +769,15 @@ QAbstractItemModel* ExamplesListModelFilter::qtVersionModel()
return m_qtVersionModel; return m_qtVersionModel;
} }
void ExamplesListModelFilter::filterForQtById(int id)
{
if (m_blockIndexUpdate || !m_initalized)
return;
setUniqueQtVersionIdSetting(id);
m_sourceModel->setUniqueQtId(id);
}
void ExamplesListModelFilter::setShowTutorialsOnly(bool showTutorialsOnly) void ExamplesListModelFilter::setShowTutorialsOnly(bool showTutorialsOnly)
{ {
m_showTutorialsOnly = showTutorialsOnly; m_showTutorialsOnly = showTutorialsOnly;
@@ -821,10 +788,44 @@ void ExamplesListModelFilter::handleQtVersionsChanged()
{ {
m_blockIndexUpdate = true; m_blockIndexUpdate = true;
m_qtVersionModel->setupQtVersions(); m_qtVersionModel->setupQtVersions();
m_sourceModel->updateExamples();
emit qtVersionIndexChanged(); emit qtVersionIndexChanged();
m_blockIndexUpdate = false; m_blockIndexUpdate = false;
} }
void ExamplesListModelFilter::qtVersionManagerLoaded()
{
m_qtVersionManagerInitialized = true;
tryToInitialize();
}
void ExamplesListModelFilter::helpManagerInitialized()
{
m_helpManagerInitialized = true;
tryToInitialize();
}
void ExamplesListModelFilter::exampleDataRequested() const
{
ExamplesListModelFilter *that = const_cast<ExamplesListModelFilter *>(this);
that->m_exampleDataRequested = true;
that->tryToInitialize();
}
void ExamplesListModelFilter::tryToInitialize()
{
if (!m_initalized
&& m_qtVersionManagerInitialized && m_helpManagerInitialized && m_exampleDataRequested) {
m_initalized = true;
connect(QtVersionManager::instance(), SIGNAL(qtVersionsChanged(QList<int>,QList<int>,QList<int>)),
this, SLOT(handleQtVersionsChanged()));
connect(ProjectExplorer::KitManager::instance(), SIGNAL(defaultkitChanged()),
this, SLOT(handleQtVersionsChanged()));
handleQtVersionsChanged();
m_sourceModel->updateExamples();
}
}
void ExamplesListModelFilter::delayedUpdateFilter() void ExamplesListModelFilter::delayedUpdateFilter()
{ {
if (m_timerId != 0) if (m_timerId != 0)

View File

@@ -85,21 +85,15 @@ public:
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QStringList tags() const; QStringList tags() const;
void ensureInitialized() const;
void beginReset() { beginResetModel(); } void beginReset() { beginResetModel(); }
void endReset() { endResetModel(); } void endReset() { endResetModel(); }
void filterForQtById(int id); void setUniqueQtId(int id);
void updateExamples();
signals: signals:
void tagsUpdated(); void tagsUpdated();
void qtVersionsChanged();
public slots:
void handleQtVersionsChanged();
void updateExamples();
void helpInitialized();
private: private:
void parseExamples(QXmlStreamReader *reader, const QString &projectsOffset, void parseExamples(QXmlStreamReader *reader, const QString &projectsOffset,
@@ -113,9 +107,6 @@ private:
QList<ExampleItem> m_exampleItems; QList<ExampleItem> m_exampleItems;
QStringList m_tags; QStringList m_tags;
bool m_updateOnQtVersionsChanged;
bool m_initialized;
bool m_helpInitialized;
int m_uniqueQtId; int m_uniqueQtId;
}; };
@@ -143,13 +134,7 @@ public:
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QAbstractItemModel* qtVersionModel(); QAbstractItemModel* qtVersionModel();
Q_INVOKABLE void filterForQtById(int id) Q_INVOKABLE void filterForQtById(int id);
{
if (m_blockIndexUpdate)
return;
m_sourceModel->filterForQtById(id);
}
public slots: public slots:
void setFilterTags(const QStringList &arg) void setFilterTags(const QStringList &arg)
@@ -180,7 +165,13 @@ signals:
void searchStrings(const QStringList &arg); void searchStrings(const QStringList &arg);
void qtVersionIndexChanged(); void qtVersionIndexChanged();
private slots:
void qtVersionManagerLoaded();
void helpManagerInitialized();
private: private:
void exampleDataRequested() const;
void tryToInitialize();
void timerEvent(QTimerEvent *event); void timerEvent(QTimerEvent *event);
void delayedUpdateFilter(); void delayedUpdateFilter();
int qtVersionIndex() const; int qtVersionIndex() const;
@@ -192,6 +183,10 @@ private:
int m_timerId; int m_timerId;
QtVersionsModel* m_qtVersionModel; QtVersionsModel* m_qtVersionModel;
bool m_blockIndexUpdate; bool m_blockIndexUpdate;
bool m_qtVersionManagerInitialized;
bool m_helpManagerInitialized;
bool m_initalized;
bool m_exampleDataRequested;
}; };
} // namespace Internal } // namespace Internal