forked from qt-creator/qt-creator
Delay looking for examples until the information is needed.
E.g. when showing the example or tutorial browser. Change-Id: I938d38872c455bbfc6f28b759701e84cd57bf354 Reviewed-by: Daniel Molkentin <daniel.molkentin@nokia.com>
This commit is contained in:
@@ -54,7 +54,9 @@ namespace Internal {
|
|||||||
|
|
||||||
ExamplesListModel::ExamplesListModel(QObject *parent) :
|
ExamplesListModel::ExamplesListModel(QObject *parent) :
|
||||||
QAbstractListModel(parent),
|
QAbstractListModel(parent),
|
||||||
m_updateOnQtVersionsChanged(false)
|
m_updateOnQtVersionsChanged(false),
|
||||||
|
m_initialized(false),
|
||||||
|
m_helpInitialized(false)
|
||||||
{
|
{
|
||||||
QHash<int, QByteArray> roleNames;
|
QHash<int, QByteArray> roleNames;
|
||||||
roleNames[Name] = "name";
|
roleNames[Name] = "name";
|
||||||
@@ -382,12 +384,13 @@ void ExamplesListModel::addItems(const QList<ExampleItem> &newItems)
|
|||||||
|
|
||||||
int ExamplesListModel::rowCount(const QModelIndex &) const
|
int ExamplesListModel::rowCount(const QModelIndex &) const
|
||||||
{
|
{
|
||||||
|
ensureInitialized();
|
||||||
return exampleItems.size();
|
return exampleItems.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
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 > exampleItems.count()) {
|
if (!index.isValid() || index.row()+1 > exampleItems.count()) {
|
||||||
qDebug() << Q_FUNC_INFO << "invalid index requested";
|
qDebug() << Q_FUNC_INFO << "invalid index requested";
|
||||||
return QVariant();
|
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()
|
void ExamplesListModel::helpInitialized()
|
||||||
{
|
{
|
||||||
|
m_helpInitialized = true;
|
||||||
|
if (m_initialized) // if we are already initialized we need to update nevertheless
|
||||||
updateExamples();
|
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) :
|
ExamplesListModelFilter::ExamplesListModelFilter(ExamplesListModel *sourceModel, QObject *parent) :
|
||||||
QSortFilterProxyModel(parent), m_showTutorialsOnly(true)
|
QSortFilterProxyModel(parent), m_showTutorialsOnly(true), m_sourceModel(sourceModel)
|
||||||
{
|
{
|
||||||
connect(this, SIGNAL(showTutorialsOnlyChanged()), SLOT(updateFilter()));
|
connect(this, SIGNAL(showTutorialsOnlyChanged()), SLOT(updateFilter()));
|
||||||
|
setSourceModel(m_sourceModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExamplesListModelFilter::updateFilter()
|
void ExamplesListModelFilter::updateFilter()
|
||||||
@@ -510,6 +530,18 @@ bool ExamplesListModelFilter::filterAcceptsRow(int sourceRow, const QModelIndex
|
|||||||
return true;
|
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)
|
void ExamplesListModelFilter::setShowTutorialsOnly(bool showTutorialsOnly)
|
||||||
{
|
{
|
||||||
m_showTutorialsOnly = showTutorialsOnly;
|
m_showTutorialsOnly = showTutorialsOnly;
|
||||||
|
|||||||
@@ -69,14 +69,15 @@ class ExamplesListModel : public QAbstractListModel {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ExamplesListModel(QObject *parent);
|
explicit ExamplesListModel(QObject *parent);
|
||||||
void addItems(const QList<ExampleItem> &items);
|
|
||||||
|
|
||||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) 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:
|
signals:
|
||||||
void tagsUpdated();
|
void tagsUpdated();
|
||||||
|
|
||||||
@@ -86,6 +87,7 @@ public slots:
|
|||||||
void helpInitialized();
|
void helpInitialized();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void addItems(const QList<ExampleItem> &items);
|
||||||
QList<ExampleItem> parseExamples(QXmlStreamReader* reader, const QString& projectsOffset);
|
QList<ExampleItem> parseExamples(QXmlStreamReader* reader, const QString& projectsOffset);
|
||||||
QList<ExampleItem> parseDemos(QXmlStreamReader* reader, const QString& projectsOffset);
|
QList<ExampleItem> parseDemos(QXmlStreamReader* reader, const QString& projectsOffset);
|
||||||
QList<ExampleItem> parseTutorials(QXmlStreamReader* reader, const QString& projectsOffset);
|
QList<ExampleItem> parseTutorials(QXmlStreamReader* reader, const QString& projectsOffset);
|
||||||
@@ -95,6 +97,8 @@ private:
|
|||||||
QList<ExampleItem> exampleItems;
|
QList<ExampleItem> exampleItems;
|
||||||
QStringList m_tags;
|
QStringList m_tags;
|
||||||
bool m_updateOnQtVersionsChanged;
|
bool m_updateOnQtVersionsChanged;
|
||||||
|
bool m_initialized;
|
||||||
|
bool m_helpInitialized;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ExamplesListModelFilter : public QSortFilterProxyModel {
|
class ExamplesListModelFilter : public QSortFilterProxyModel {
|
||||||
@@ -104,7 +108,7 @@ public:
|
|||||||
Q_PROPERTY(QStringList filterTags READ filterTags WRITE setFilterTags NOTIFY filterTagsChanged)
|
Q_PROPERTY(QStringList filterTags READ filterTags WRITE setFilterTags NOTIFY filterTagsChanged)
|
||||||
Q_PROPERTY(QStringList searchStrings READ searchStrings WRITE setSearchStrings NOTIFY searchStrings)
|
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;
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
||||||
|
|
||||||
@@ -112,6 +116,9 @@ public:
|
|||||||
QStringList filterTags() const { return m_filterTags; }
|
QStringList filterTags() const { return m_filterTags; }
|
||||||
QStringList searchStrings() const { return m_searchString; }
|
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:
|
public slots:
|
||||||
void setFilterTags(const QStringList& arg)
|
void setFilterTags(const QStringList& arg)
|
||||||
{
|
{
|
||||||
@@ -145,6 +152,7 @@ private:
|
|||||||
bool m_showTutorialsOnly;
|
bool m_showTutorialsOnly;
|
||||||
QStringList m_filterTags;
|
QStringList m_filterTags;
|
||||||
QStringList m_searchString;
|
QStringList m_searchString;
|
||||||
|
ExamplesListModel *m_sourceModel;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -267,8 +267,7 @@ void ExamplesWelcomePage::facilitateQml(QDeclarativeEngine *engine)
|
|||||||
m_engine = engine;
|
m_engine = engine;
|
||||||
m_engine->addImageProvider(QLatin1String("helpimage"), new HelpImageProvider);
|
m_engine->addImageProvider(QLatin1String("helpimage"), new HelpImageProvider);
|
||||||
connect (examplesModel(), SIGNAL(tagsUpdated()), SLOT(updateTagsModel()));
|
connect (examplesModel(), SIGNAL(tagsUpdated()), SLOT(updateTagsModel()));
|
||||||
ExamplesListModelFilter *proxy = new ExamplesListModelFilter(this);
|
ExamplesListModelFilter *proxy = new ExamplesListModelFilter(examplesModel(), this);
|
||||||
proxy->setSourceModel(examplesModel());
|
|
||||||
|
|
||||||
proxy->setDynamicSortFilter(true);
|
proxy->setDynamicSortFilter(true);
|
||||||
proxy->sort(0);
|
proxy->sort(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user