Commit a2f9ee87 authored by Eike Ziller's avatar Eike Ziller
Browse files

Delay looking for examples until the information is needed.



E.g. when showing the example or tutorial browser.

Change-Id: I938d38872c455bbfc6f28b759701e84cd57bf354
Reviewed-by: default avatarDaniel Molkentin <daniel.molkentin@nokia.com>
parent 7b708cd3
......@@ -54,7 +54,9 @@ namespace Internal {
ExamplesListModel::ExamplesListModel(QObject *parent) :
QAbstractListModel(parent),
m_updateOnQtVersionsChanged(false)
m_updateOnQtVersionsChanged(false),
m_initialized(false),
m_helpInitialized(false)
{
QHash<int, QByteArray> roleNames;
roleNames[Name] = "name";
......@@ -382,12 +384,13 @@ void ExamplesListModel::addItems(const QList<ExampleItem> &newItems)
int ExamplesListModel::rowCount(const QModelIndex &) const
{
ensureInitialized();
return exampleItems.size();
}
QVariant ExamplesListModel::data(const QModelIndex &index, int role) const
{
ensureInitialized();
if (!index.isValid() || index.row()+1 > exampleItems.count()) {
qDebug() << Q_FUNC_INFO << "invalid index requested";
return QVariant();
......@@ -433,16 +436,33 @@ QVariant ExamplesListModel::data(const QModelIndex &index, int role) const
}
QStringList ExamplesListModel::tags() const
{
ensureInitialized();
return m_tags;
}
void ExamplesListModel::helpInitialized()
{
updateExamples();
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();
}
ExamplesListModelFilter::ExamplesListModelFilter(QObject *parent) :
QSortFilterProxyModel(parent), m_showTutorialsOnly(true)
ExamplesListModelFilter::ExamplesListModelFilter(ExamplesListModel *sourceModel, QObject *parent) :
QSortFilterProxyModel(parent), m_showTutorialsOnly(true), m_sourceModel(sourceModel)
{
connect(this, SIGNAL(showTutorialsOnlyChanged()), SLOT(updateFilter()));
setSourceModel(m_sourceModel);
}
void ExamplesListModelFilter::updateFilter()
......@@ -510,6 +530,18 @@ bool ExamplesListModelFilter::filterAcceptsRow(int sourceRow, const QModelIndex
return true;
}
int ExamplesListModelFilter::rowCount(const QModelIndex &parent) const
{
m_sourceModel->ensureInitialized();
return QSortFilterProxyModel::rowCount(parent);
}
QVariant ExamplesListModelFilter::data(const QModelIndex &index, int role) const
{
m_sourceModel->ensureInitialized();
return QSortFilterProxyModel::data(index, role);
}
void ExamplesListModelFilter::setShowTutorialsOnly(bool showTutorialsOnly)
{
m_showTutorialsOnly = showTutorialsOnly;
......
......@@ -69,13 +69,14 @@ class ExamplesListModel : public QAbstractListModel {
Q_OBJECT
public:
explicit ExamplesListModel(QObject *parent);
void addItems(const QList<ExampleItem> &items);
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QStringList tags() const { return m_tags; }
QStringList tags() const;
void ensureInitialized() const;
signals:
void tagsUpdated();
......@@ -86,6 +87,7 @@ public slots:
void helpInitialized();
private:
void addItems(const QList<ExampleItem> &items);
QList<ExampleItem> parseExamples(QXmlStreamReader* reader, const QString& projectsOffset);
QList<ExampleItem> parseDemos(QXmlStreamReader* reader, const QString& projectsOffset);
QList<ExampleItem> parseTutorials(QXmlStreamReader* reader, const QString& projectsOffset);
......@@ -95,6 +97,8 @@ private:
QList<ExampleItem> exampleItems;
QStringList m_tags;
bool m_updateOnQtVersionsChanged;
bool m_initialized;
bool m_helpInitialized;
};
class ExamplesListModelFilter : public QSortFilterProxyModel {
......@@ -104,7 +108,7 @@ public:
Q_PROPERTY(QStringList filterTags READ filterTags WRITE setFilterTags NOTIFY filterTagsChanged)
Q_PROPERTY(QStringList searchStrings READ searchStrings WRITE setSearchStrings NOTIFY searchStrings)
explicit ExamplesListModelFilter(QObject *parent);
explicit ExamplesListModelFilter(ExamplesListModel *sourceModel, QObject *parent);
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
......@@ -112,6 +116,9 @@ public:
QStringList filterTags() const { return m_filterTags; }
QStringList searchStrings() const { return m_searchString; }
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
public slots:
void setFilterTags(const QStringList& arg)
{
......@@ -145,6 +152,7 @@ private:
bool m_showTutorialsOnly;
QStringList m_filterTags;
QStringList m_searchString;
ExamplesListModel *m_sourceModel;
};
} // namespace Internal
......
......@@ -267,8 +267,7 @@ void ExamplesWelcomePage::facilitateQml(QDeclarativeEngine *engine)
m_engine = engine;
m_engine->addImageProvider(QLatin1String("helpimage"), new HelpImageProvider);
connect (examplesModel(), SIGNAL(tagsUpdated()), SLOT(updateTagsModel()));
ExamplesListModelFilter *proxy = new ExamplesListModelFilter(this);
proxy->setSourceModel(examplesModel());
ExamplesListModelFilter *proxy = new ExamplesListModelFilter(examplesModel(), this);
proxy->setDynamicSortFilter(true);
proxy->sort(0);
......
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