forked from qt-creator/qt-creator
QtSupport: Simplify welcome page examples model handling further
Use the ExampleSetModel directly in the combobox, rely on normal model reset behavior behavior for gui updates. Change-Id: Icdb34ff0f572caaf92259530823e90bfd783b933 Task-number: QTCREATORBUG-17678 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -33,11 +33,13 @@
|
||||
|
||||
#include <coreplugin/helpmanager.h>
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <qtsupport/qtkitinformation.h>
|
||||
#include <qtsupport/qtversionmanager.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@@ -68,22 +70,54 @@ int ExampleSetModel::readCurrentIndexFromSettings() const
|
||||
return -1;
|
||||
}
|
||||
|
||||
ExampleSetModel::ExampleSetModel(ExamplesListModel *examplesModel, QObject *parent) :
|
||||
QStandardItemModel(parent),
|
||||
examplesModel(examplesModel)
|
||||
ExampleSetModel::ExampleSetModel()
|
||||
{
|
||||
// read extra example sets settings
|
||||
QSettings *settings = Core::ICore::settings();
|
||||
const QStringList list = settings->value("Help/InstalledExamples", QStringList()).toStringList();
|
||||
if (debugExamples())
|
||||
qWarning() << "Reading Help/InstalledExamples from settings:" << list;
|
||||
for (const QString &item : list) {
|
||||
const QStringList &parts = item.split(QLatin1Char('|'));
|
||||
if (parts.size() < 3) {
|
||||
if (debugExamples())
|
||||
qWarning() << "Item" << item << "has less than 3 parts (separated by '|'):" << parts;
|
||||
continue;
|
||||
}
|
||||
ExtraExampleSet set;
|
||||
set.displayName = parts.at(0);
|
||||
set.manifestPath = parts.at(1);
|
||||
set.examplesPath = parts.at(2);
|
||||
QFileInfo fi(set.manifestPath);
|
||||
if (!fi.isDir() || !fi.isReadable()) {
|
||||
if (debugExamples())
|
||||
qWarning() << "Manifest path " << set.manifestPath << "is not a readable directory, ignoring";
|
||||
continue;
|
||||
}
|
||||
m_extraExampleSets.append(set);
|
||||
if (debugExamples()) {
|
||||
qWarning() << "Adding examples set displayName=" << set.displayName
|
||||
<< ", manifestPath=" << set.manifestPath
|
||||
<< ", examplesPath=" << set.examplesPath;
|
||||
}
|
||||
}
|
||||
|
||||
connect(QtVersionManager::instance(), &QtVersionManager::qtVersionsLoaded,
|
||||
this, &ExampleSetModel::qtVersionManagerLoaded);
|
||||
connect(Core::HelpManager::instance(), &Core::HelpManager::setupFinished,
|
||||
this, &ExampleSetModel::helpManagerInitialized);
|
||||
}
|
||||
|
||||
void ExampleSetModel::update()
|
||||
void ExampleSetModel::recreateModel()
|
||||
{
|
||||
beginResetModel();
|
||||
clear();
|
||||
|
||||
QSet<QString> extraManifestDirs;
|
||||
QList<ExamplesListModel::ExtraExampleSet> extraExampleSets = examplesModel->extraExampleSets();
|
||||
for (int i = 0; i < extraExampleSets.size(); ++i) {
|
||||
ExamplesListModel::ExtraExampleSet set = extraExampleSets.at(i);
|
||||
for (int i = 0; i < m_extraExampleSets.size(); ++i) {
|
||||
const ExtraExampleSet &set = m_extraExampleSets.at(i);
|
||||
QStandardItem *newItem = new QStandardItem();
|
||||
newItem->setData(set.displayName, Qt::DisplayRole);
|
||||
newItem->setData(set.displayName, Qt::UserRole + 1);
|
||||
newItem->setData(QVariant(), Qt::UserRole + 2);
|
||||
newItem->setData(i, Qt::UserRole + 3);
|
||||
@@ -102,6 +136,7 @@ void ExampleSetModel::update()
|
||||
continue;
|
||||
}
|
||||
QStandardItem *newItem = new QStandardItem();
|
||||
newItem->setData(version->displayName(), Qt::DisplayRole);
|
||||
newItem->setData(version->displayName(), Qt::UserRole + 1);
|
||||
newItem->setData(version->uniqueId(), Qt::UserRole + 2);
|
||||
newItem->setData(QVariant(), Qt::UserRole + 3);
|
||||
@@ -122,13 +157,12 @@ int ExampleSetModel::indexForQtVersion(BaseQtVersion *qtVersion) const
|
||||
if (getType(i) == QtExampleSet && getQtId(i) == qtVersion->uniqueId())
|
||||
return i;
|
||||
}
|
||||
|
||||
// check for extra set
|
||||
const QList<ExamplesListModel::ExtraExampleSet> &extraExamples
|
||||
= examplesModel->extraExampleSets();
|
||||
const QString &documentationPath = qtVersion->documentationPath();
|
||||
for (int i = 0; i < rowCount(); ++i) {
|
||||
if (getType(i) == ExtraExampleSet
|
||||
&& extraExamples.at(getExtraExampleSetIndex(i)).manifestPath == documentationPath)
|
||||
if (getType(i) == ExtraExampleSetType
|
||||
&& m_extraExampleSets.at(getExtraExampleSetIndex(i)).manifestPath == documentationPath)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
@@ -161,7 +195,7 @@ ExampleSetModel::ExampleSetType ExampleSetModel::getType(int i) const
|
||||
QVariant variant = data(modelIndex, Qt::UserRole + 2); /*Qt version uniqueId*/
|
||||
if (variant.isValid())
|
||||
return QtExampleSet;
|
||||
return ExtraExampleSet;
|
||||
return ExtraExampleSetType;
|
||||
}
|
||||
|
||||
int ExampleSetModel::getQtId(int i) const
|
||||
@@ -184,40 +218,11 @@ int ExampleSetModel::getExtraExampleSetIndex(int i) const
|
||||
return variant.toInt();
|
||||
}
|
||||
|
||||
ExamplesListModel::ExamplesListModel(QObject *parent) :
|
||||
QAbstractListModel(parent),
|
||||
m_exampleSetModel(new ExampleSetModel(this, this))
|
||||
ExamplesListModel::ExamplesListModel(QObject *parent)
|
||||
: QAbstractListModel(parent)
|
||||
{
|
||||
// read extra example sets settings
|
||||
QSettings *settings = Core::ICore::settings();
|
||||
QStringList list = settings->value(QLatin1String("Help/InstalledExamples"),
|
||||
QStringList()).toStringList();
|
||||
if (debugExamples())
|
||||
qWarning() << "Reading Help/InstalledExamples from settings:" << list;
|
||||
foreach (const QString &item, list) {
|
||||
const QStringList &parts = item.split(QLatin1Char('|'));
|
||||
if (parts.size() < 3) {
|
||||
if (debugExamples())
|
||||
qWarning() << "Item" << item << "has less than 3 parts (separated by '|'):" << parts;
|
||||
continue;
|
||||
}
|
||||
ExtraExampleSet set;
|
||||
set.displayName = parts.at(0);
|
||||
set.manifestPath = parts.at(1);
|
||||
set.examplesPath = parts.at(2);
|
||||
QFileInfo fi(set.manifestPath);
|
||||
if (!fi.isDir() || !fi.isReadable()) {
|
||||
if (debugExamples())
|
||||
qWarning() << "Manifest path " << set.manifestPath << "is not a readable directory, ignoring";
|
||||
continue;
|
||||
}
|
||||
m_extraExampleSets.append(set);
|
||||
if (debugExamples()) {
|
||||
qWarning() << "Adding examples set displayName=" << set.displayName
|
||||
<< ", manifestPath=" << set.manifestPath
|
||||
<< ", examplesPath=" << set.examplesPath;
|
||||
}
|
||||
}
|
||||
connect(&m_exampleSetModel, &ExampleSetModel::selectedExampleSetChanged,
|
||||
this, &ExamplesListModel::updateExamples);
|
||||
}
|
||||
|
||||
static QString fixStringForTags(const QString &string)
|
||||
@@ -431,7 +436,7 @@ void ExamplesListModel::updateExamples()
|
||||
QString examplesInstallPath;
|
||||
QString demosInstallPath;
|
||||
|
||||
QStringList sources = exampleSources(&examplesInstallPath, &demosInstallPath);
|
||||
QStringList sources = m_exampleSetModel.exampleSources(&examplesInstallPath, &demosInstallPath);
|
||||
|
||||
beginResetModel();
|
||||
m_exampleItems.clear();
|
||||
@@ -472,7 +477,7 @@ void ExamplesListModel::updateExamples()
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void ExamplesListModel::updateQtVersions()
|
||||
void ExampleSetModel::updateQtVersionList()
|
||||
{
|
||||
QList<BaseQtVersion*> versions
|
||||
= QtVersionManager::sortVersions(
|
||||
@@ -486,35 +491,34 @@ void ExamplesListModel::updateQtVersions()
|
||||
if (defaultVersion && versions.contains(defaultVersion))
|
||||
versions.move(versions.indexOf(defaultVersion), 0);
|
||||
|
||||
m_exampleSetModel->update();
|
||||
recreateModel();
|
||||
|
||||
int currentIndex = m_selectedExampleSetIndex;
|
||||
if (currentIndex < 0) // reset from settings
|
||||
currentIndex = m_exampleSetModel->readCurrentIndexFromSettings();
|
||||
currentIndex = readCurrentIndexFromSettings();
|
||||
|
||||
ExampleSetModel::ExampleSetType currentType
|
||||
= m_exampleSetModel->getType(currentIndex);
|
||||
ExampleSetModel::ExampleSetType currentType = getType(currentIndex);
|
||||
|
||||
if (currentType == ExampleSetModel::InvalidExampleSet) {
|
||||
// select examples corresponding to 'highest' Qt version
|
||||
BaseQtVersion *highestQt = findHighestQtVersion();
|
||||
currentIndex = m_exampleSetModel->indexForQtVersion(highestQt);
|
||||
currentIndex = indexForQtVersion(highestQt);
|
||||
} else if (currentType == ExampleSetModel::QtExampleSet) {
|
||||
// try to select the previously selected Qt version, or
|
||||
// select examples corresponding to 'highest' Qt version
|
||||
int currentQtId = m_exampleSetModel->getQtId(currentIndex);
|
||||
int currentQtId = getQtId(currentIndex);
|
||||
BaseQtVersion *newQtVersion = QtVersionManager::version(currentQtId);
|
||||
if (!newQtVersion)
|
||||
newQtVersion = findHighestQtVersion();
|
||||
currentIndex = m_exampleSetModel->indexForQtVersion(newQtVersion);
|
||||
currentIndex = indexForQtVersion(newQtVersion);
|
||||
} // nothing to do for extra example sets
|
||||
selectExampleSet(currentIndex);
|
||||
emit selectedExampleSetChanged(currentIndex);
|
||||
}
|
||||
|
||||
BaseQtVersion *ExamplesListModel::findHighestQtVersion() const
|
||||
BaseQtVersion *ExampleSetModel::findHighestQtVersion() const
|
||||
{
|
||||
BaseQtVersion *newVersion = nullptr;
|
||||
|
||||
const QList<BaseQtVersion *> versions = QtVersionManager::versions();
|
||||
for (BaseQtVersion *version : versions) {
|
||||
if (!newVersion) {
|
||||
@@ -535,7 +539,7 @@ BaseQtVersion *ExamplesListModel::findHighestQtVersion() const
|
||||
return newVersion;
|
||||
}
|
||||
|
||||
QStringList ExamplesListModel::exampleSources(QString *examplesInstallPath, QString *demosInstallPath)
|
||||
QStringList ExampleSetModel::exampleSources(QString *examplesInstallPath, QString *demosInstallPath)
|
||||
{
|
||||
QStringList sources;
|
||||
|
||||
@@ -546,16 +550,15 @@ QStringList ExamplesListModel::exampleSources(QString *examplesInstallPath, QStr
|
||||
QString demosPath;
|
||||
QString manifestScanPath;
|
||||
|
||||
ExampleSetModel::ExampleSetType currentType
|
||||
= m_exampleSetModel->getType(m_selectedExampleSetIndex);
|
||||
if (currentType == ExampleSetModel::ExtraExampleSet) {
|
||||
int index = m_exampleSetModel->getExtraExampleSetIndex(m_selectedExampleSetIndex);
|
||||
ExampleSetModel::ExampleSetType currentType = getType(m_selectedExampleSetIndex);
|
||||
if (currentType == ExampleSetModel::ExtraExampleSetType) {
|
||||
int index = getExtraExampleSetIndex(m_selectedExampleSetIndex);
|
||||
ExtraExampleSet exampleSet = m_extraExampleSets.at(index);
|
||||
manifestScanPath = exampleSet.manifestPath;
|
||||
examplesPath = exampleSet.examplesPath;
|
||||
demosPath = exampleSet.examplesPath;
|
||||
} else if (currentType == ExampleSetModel::QtExampleSet) {
|
||||
int qtId = m_exampleSetModel->getQtId(m_selectedExampleSetIndex);
|
||||
int qtId = getQtId(m_selectedExampleSetIndex);
|
||||
foreach (BaseQtVersion *version, QtVersionManager::versions()) {
|
||||
if (version->uniqueId() == qtId) {
|
||||
manifestScanPath = version->documentationPath();
|
||||
@@ -615,67 +618,54 @@ QVariant ExamplesListModel::data(const QModelIndex &index, int role) const
|
||||
}
|
||||
}
|
||||
|
||||
void ExamplesListModel::update()
|
||||
{
|
||||
updateQtVersions();
|
||||
updateExamples();
|
||||
}
|
||||
|
||||
int ExamplesListModel::selectedExampleSet() const
|
||||
{
|
||||
return m_selectedExampleSetIndex;
|
||||
}
|
||||
|
||||
void ExamplesListModel::selectExampleSet(int index)
|
||||
void ExampleSetModel::selectExampleSet(int index)
|
||||
{
|
||||
if (index != m_selectedExampleSetIndex) {
|
||||
m_selectedExampleSetIndex = index;
|
||||
m_exampleSetModel->writeCurrentIdToSettings(m_selectedExampleSetIndex);
|
||||
updateExamples();
|
||||
writeCurrentIdToSettings(m_selectedExampleSetIndex);
|
||||
emit selectedExampleSetChanged(m_selectedExampleSetIndex);
|
||||
}
|
||||
}
|
||||
|
||||
QStringList ExamplesListModel::exampleSets() const
|
||||
void ExampleSetModel::qtVersionManagerLoaded()
|
||||
{
|
||||
return Utils::transform(QtVersionManager::versions(), &BaseQtVersion::displayName);
|
||||
m_qtVersionManagerInitialized = true;
|
||||
tryToInitialize();
|
||||
}
|
||||
|
||||
void ExampleSetModel::helpManagerInitialized()
|
||||
{
|
||||
m_helpManagerInitialized = true;
|
||||
tryToInitialize();
|
||||
}
|
||||
|
||||
|
||||
void ExampleSetModel::tryToInitialize()
|
||||
{
|
||||
if (m_initalized || !m_qtVersionManagerInitialized || !m_helpManagerInitialized)
|
||||
return;
|
||||
|
||||
m_initalized = true;
|
||||
|
||||
connect(QtVersionManager::instance(), &QtVersionManager::qtVersionsChanged,
|
||||
this, &ExampleSetModel::updateQtVersionList);
|
||||
connect(ProjectExplorer::KitManager::instance(), &ProjectExplorer::KitManager::defaultkitChanged,
|
||||
this, &ExampleSetModel::updateQtVersionList);
|
||||
|
||||
updateQtVersionList();
|
||||
}
|
||||
|
||||
|
||||
ExamplesListModelFilter::ExamplesListModelFilter(ExamplesListModel *sourceModel, bool showTutorialsOnly, QObject *parent) :
|
||||
QSortFilterProxyModel(parent),
|
||||
m_showTutorialsOnly(showTutorialsOnly),
|
||||
m_sourceModel(sourceModel)
|
||||
m_showTutorialsOnly(showTutorialsOnly)
|
||||
{
|
||||
// initialization hooks
|
||||
connect(QtVersionManager::instance(), &QtVersionManager::qtVersionsLoaded,
|
||||
this, &ExamplesListModelFilter::qtVersionManagerLoaded);
|
||||
connect(Core::HelpManager::instance(), &Core::HelpManager::setupFinished,
|
||||
this, &ExamplesListModelFilter::helpManagerInitialized);
|
||||
|
||||
setSourceModel(m_sourceModel);
|
||||
setSourceModel(sourceModel);
|
||||
setDynamicSortFilter(true);
|
||||
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||
sort(0);
|
||||
}
|
||||
|
||||
void ExamplesListModelFilter::updateFilter()
|
||||
{
|
||||
ExamplesListModel *exampleListModel = qobject_cast<ExamplesListModel*>(sourceModel());
|
||||
if (exampleListModel) {
|
||||
exampleListModel->beginReset();
|
||||
invalidateFilter();
|
||||
exampleListModel->endReset();
|
||||
}
|
||||
}
|
||||
|
||||
void ExamplesListModelFilter::setFilterStrings(const QStringList &arg)
|
||||
{
|
||||
if (m_filterStrings != arg) {
|
||||
m_filterStrings = arg;
|
||||
delayedUpdateFilter();
|
||||
}
|
||||
}
|
||||
|
||||
bool ExamplesListModelFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
||||
{
|
||||
const ExampleItem item = sourceModel()->index(sourceRow, 0, sourceParent).data(Qt::UserRole).value<ExampleItem>();
|
||||
@@ -711,63 +701,6 @@ bool ExamplesListModelFilter::filterAcceptsRow(int sourceRow, const QModelIndex
|
||||
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
|
||||
}
|
||||
|
||||
int ExamplesListModelFilter::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
exampleDataRequested();
|
||||
return QSortFilterProxyModel::rowCount(parent);
|
||||
}
|
||||
|
||||
QVariant ExamplesListModelFilter::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
exampleDataRequested();
|
||||
return QSortFilterProxyModel::data(index, role);
|
||||
}
|
||||
|
||||
void ExamplesListModelFilter::setFilterTags(const QStringList &arg)
|
||||
{
|
||||
if (m_filterTags != arg) {
|
||||
m_filterTags = arg;
|
||||
emit filterTagsChanged(arg);
|
||||
}
|
||||
}
|
||||
|
||||
void ExamplesListModelFilter::handleQtVersionsChanged()
|
||||
{
|
||||
m_sourceModel->update();
|
||||
}
|
||||
|
||||
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(), &QtVersionManager::qtVersionsChanged,
|
||||
this, &ExamplesListModelFilter::handleQtVersionsChanged);
|
||||
connect(ProjectExplorer::KitManager::instance(), &ProjectExplorer::KitManager::defaultkitChanged,
|
||||
this, &ExamplesListModelFilter::handleQtVersionsChanged);
|
||||
handleQtVersionsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void ExamplesListModelFilter::delayedUpdateFilter()
|
||||
{
|
||||
if (m_timerId != 0)
|
||||
@@ -779,7 +712,7 @@ void ExamplesListModelFilter::delayedUpdateFilter()
|
||||
void ExamplesListModelFilter::timerEvent(QTimerEvent *timerEvent)
|
||||
{
|
||||
if (m_timerId == timerEvent->timerId()) {
|
||||
updateFilter();
|
||||
invalidateFilter();
|
||||
killTimer(m_timerId);
|
||||
m_timerId = 0;
|
||||
}
|
||||
@@ -871,32 +804,31 @@ void ExamplesListModelFilter::setSearchString(const QString &arg)
|
||||
{
|
||||
if (m_searchString == arg)
|
||||
return;
|
||||
|
||||
m_searchString = arg;
|
||||
emit searchStringChanged(m_searchString);
|
||||
m_filterTags.clear();
|
||||
m_filterStrings.clear();
|
||||
|
||||
// parse and update
|
||||
QStringList tags;
|
||||
QStringList searchTerms;
|
||||
SearchStringLexer lex(arg);
|
||||
bool isTag = false;
|
||||
while (int tk = lex()) {
|
||||
if (tk == SearchStringLexer::TAG) {
|
||||
isTag = true;
|
||||
searchTerms.append(lex.yytext);
|
||||
m_filterStrings.append(lex.yytext);
|
||||
}
|
||||
|
||||
if (tk == SearchStringLexer::STRING_LITERAL) {
|
||||
if (isTag) {
|
||||
searchTerms.pop_back();
|
||||
tags.append(lex.yytext);
|
||||
m_filterStrings.pop_back();
|
||||
m_filterTags.append(lex.yytext);
|
||||
isTag = false;
|
||||
} else {
|
||||
searchTerms.append(lex.yytext);
|
||||
m_filterStrings.append(lex.yytext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setFilterStrings(searchTerms);
|
||||
setFilterTags(tags);
|
||||
delayedUpdateFilter();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,12 +25,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <qtsupport/baseqtversion.h>
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QStandardItemModel>
|
||||
#include <QStringList>
|
||||
#include <QXmlStreamReader>
|
||||
#include <qtsupport/baseqtversion.h>
|
||||
|
||||
namespace QtSupport {
|
||||
namespace Internal {
|
||||
@@ -42,28 +43,54 @@ class ExampleSetModel : public QStandardItemModel
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ExampleSetModel();
|
||||
|
||||
int selectedExampleSet() const { return m_selectedExampleSetIndex; }
|
||||
void selectExampleSet(int index);
|
||||
QStringList exampleSources(QString *examplesInstallPath, QString *demosInstallPath);
|
||||
|
||||
signals:
|
||||
void selectedExampleSetChanged(int);
|
||||
|
||||
private:
|
||||
struct ExtraExampleSet {
|
||||
QString displayName;
|
||||
QString manifestPath;
|
||||
QString examplesPath;
|
||||
};
|
||||
|
||||
enum ExampleSetType {
|
||||
InvalidExampleSet,
|
||||
QtExampleSet,
|
||||
ExtraExampleSet
|
||||
ExtraExampleSetType
|
||||
};
|
||||
|
||||
ExampleSetModel(ExamplesListModel *examplesModel, QObject *parent);
|
||||
|
||||
void writeCurrentIdToSettings(int currentIndex) const;
|
||||
int readCurrentIndexFromSettings() const;
|
||||
|
||||
int indexForQtVersion(BaseQtVersion *qtVersion) const;
|
||||
void update();
|
||||
|
||||
QVariant getDisplayName(int index) const;
|
||||
QVariant getId(int index) const;
|
||||
ExampleSetType getType(int i) const;
|
||||
int getQtId(int index) const;
|
||||
int getExtraExampleSetIndex(int index) const;
|
||||
|
||||
private:
|
||||
ExamplesListModel *examplesModel;
|
||||
BaseQtVersion *findHighestQtVersion() const;
|
||||
|
||||
int indexForQtVersion(BaseQtVersion *qtVersion) const;
|
||||
void recreateModel();
|
||||
void updateQtVersionList();
|
||||
|
||||
void qtVersionManagerLoaded();
|
||||
void helpManagerInitialized();
|
||||
void tryToInitialize();
|
||||
|
||||
QList<ExtraExampleSet> m_extraExampleSets;
|
||||
QList<BaseQtVersion*> m_qtVersions;
|
||||
int m_selectedExampleSetIndex = -1;
|
||||
|
||||
bool m_qtVersionManagerInitialized = false;
|
||||
bool m_helpManagerInitialized = false;
|
||||
bool m_initalized = false;
|
||||
};
|
||||
|
||||
enum InstructionalType
|
||||
@@ -98,49 +125,30 @@ class ExamplesListModel : public QAbstractListModel
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
struct ExtraExampleSet {
|
||||
QString displayName;
|
||||
QString manifestPath;
|
||||
QString examplesPath;
|
||||
};
|
||||
|
||||
explicit ExamplesListModel(QObject *parent);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const final;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const final;
|
||||
|
||||
void beginReset() { beginResetModel(); }
|
||||
void endReset() { endResetModel(); }
|
||||
void updateExamples();
|
||||
|
||||
void update();
|
||||
|
||||
int selectedExampleSet() const;
|
||||
void selectExampleSet(int index);
|
||||
|
||||
QList<ExtraExampleSet> extraExampleSets() const { return m_extraExampleSets; }
|
||||
QStringList exampleSets() const;
|
||||
ExampleSetModel *exampleSetModel() { return &m_exampleSetModel; }
|
||||
|
||||
signals:
|
||||
void selectedExampleSetChanged(int);
|
||||
|
||||
private:
|
||||
void updateQtVersions();
|
||||
void updateExamples();
|
||||
|
||||
void updateSelectedQtVersion();
|
||||
BaseQtVersion *findHighestQtVersion() const;
|
||||
|
||||
void parseExamples(QXmlStreamReader *reader, const QString &projectsOffset,
|
||||
const QString &examplesInstallPath);
|
||||
void parseDemos(QXmlStreamReader *reader, const QString &projectsOffset,
|
||||
const QString &demosInstallPath);
|
||||
void parseTutorials(QXmlStreamReader *reader, const QString &projectsOffset);
|
||||
QStringList exampleSources(QString *examplesInstallPath, QString *demosInstallPath);
|
||||
|
||||
ExampleSetModel* m_exampleSetModel;
|
||||
QList<ExtraExampleSet> m_extraExampleSets;
|
||||
ExampleSetModel m_exampleSetModel;
|
||||
QList<ExampleItem> m_exampleItems;
|
||||
int m_selectedExampleSetIndex = -1;
|
||||
};
|
||||
|
||||
class ExamplesListModelFilter : public QSortFilterProxyModel
|
||||
@@ -150,41 +158,19 @@ class ExamplesListModelFilter : public QSortFilterProxyModel
|
||||
public:
|
||||
ExamplesListModelFilter(ExamplesListModel *sourceModel, bool showTutorialsOnly, QObject *parent);
|
||||
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const final;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const final;
|
||||
|
||||
void setSearchString(const QString &arg);
|
||||
void setFilterTags(const QStringList &arg);
|
||||
void updateFilter();
|
||||
|
||||
void handleQtVersionsChanged();
|
||||
|
||||
signals:
|
||||
void filterTagsChanged(const QStringList &arg);
|
||||
void searchStringChanged(const QString &arg);
|
||||
|
||||
private:
|
||||
void setFilterStrings(const QStringList &arg);
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const final;
|
||||
void timerEvent(QTimerEvent *event) final;
|
||||
|
||||
void qtVersionManagerLoaded();
|
||||
void helpManagerInitialized();
|
||||
|
||||
void exampleDataRequested() const;
|
||||
void tryToInitialize();
|
||||
void timerEvent(QTimerEvent *event);
|
||||
void delayedUpdateFilter();
|
||||
|
||||
const bool m_showTutorialsOnly;
|
||||
QString m_searchString;
|
||||
QStringList m_filterTags;
|
||||
QStringList m_filterStrings;
|
||||
ExamplesListModel *m_sourceModel;
|
||||
int m_timerId = 0;
|
||||
bool m_qtVersionManagerInitialized = false;
|
||||
bool m_helpManagerInitialized = false;
|
||||
bool m_initalized = false;
|
||||
bool m_exampleDataRequested = false;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -247,7 +247,7 @@ static QString resourcePath()
|
||||
class SearchBox : public QFrame
|
||||
{
|
||||
public:
|
||||
SearchBox(const QString &placeHolderText, QWidget *parent)
|
||||
SearchBox(QWidget *parent)
|
||||
: QFrame(parent)
|
||||
{
|
||||
setFrameShape(QFrame::Box);
|
||||
@@ -257,7 +257,6 @@ public:
|
||||
pal.setColor(QPalette::Base, themeColor(Theme::Welcome_BackgroundColor));
|
||||
|
||||
m_lineEdit = new QLineEdit;
|
||||
m_lineEdit->setPlaceholderText(placeHolderText);
|
||||
m_lineEdit->setFrame(false);
|
||||
m_lineEdit->setFont(sizedFont(14, this));
|
||||
m_lineEdit->setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||
@@ -586,44 +585,48 @@ public:
|
||||
static ExamplesListModel *s_examplesModel = new ExamplesListModel(this);
|
||||
m_examplesModel = s_examplesModel;
|
||||
|
||||
m_filteredModel = new ExamplesListModelFilter(m_examplesModel, !m_isExamples, this);
|
||||
auto filteredModel = new ExamplesListModelFilter(m_examplesModel, !m_isExamples, this);
|
||||
|
||||
auto searchBox = new SearchBox(this);
|
||||
m_searcher = searchBox->m_lineEdit;
|
||||
|
||||
auto vbox = new QVBoxLayout(this);
|
||||
vbox->setContentsMargins(30, 27, 20, 20);
|
||||
if (m_isExamples) {
|
||||
m_qtVersionSelector = new QComboBox(this);
|
||||
m_qtVersionSelector->setMinimumWidth(itemWidth);
|
||||
m_qtVersionSelector->setMaximumWidth(itemWidth);
|
||||
m_searchBox = new SearchBox(tr("Search in Examples..."), this);
|
||||
m_searcher->setPlaceholderText(tr("Search in Examples..."));
|
||||
|
||||
auto exampleSetSelector = new QComboBox(this);
|
||||
exampleSetSelector->setMinimumWidth(itemWidth);
|
||||
exampleSetSelector->setMaximumWidth(itemWidth);
|
||||
ExampleSetModel *exampleSetModel = m_examplesModel->exampleSetModel();
|
||||
exampleSetSelector->setModel(exampleSetModel);
|
||||
exampleSetSelector->setCurrentIndex(exampleSetModel->selectedExampleSet());
|
||||
connect(exampleSetSelector, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated),
|
||||
exampleSetModel, &ExampleSetModel::selectExampleSet);
|
||||
connect(exampleSetModel, &ExampleSetModel::selectedExampleSetChanged,
|
||||
exampleSetSelector, &QComboBox::setCurrentIndex);
|
||||
|
||||
auto hbox = new QHBoxLayout;
|
||||
hbox->setSpacing(17);
|
||||
hbox->addWidget(m_qtVersionSelector);
|
||||
hbox->addWidget(m_searchBox);
|
||||
hbox->addWidget(exampleSetSelector);
|
||||
hbox->addWidget(searchBox);
|
||||
vbox->addItem(hbox);
|
||||
connect(m_qtVersionSelector, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated),
|
||||
m_examplesModel, &ExamplesListModel::selectExampleSet);
|
||||
connect(m_examplesModel, &ExamplesListModel::selectedExampleSetChanged,
|
||||
this, &ExamplesPageWidget::updateStuff);
|
||||
} else {
|
||||
m_searchBox = new SearchBox(tr("Search in Tutorials..."), this);
|
||||
vbox->addWidget(m_searchBox);
|
||||
m_searcher->setPlaceholderText(tr("Search in Tutorials..."));
|
||||
vbox->addWidget(searchBox);
|
||||
}
|
||||
|
||||
m_gridModel.setSourceModel(m_filteredModel);
|
||||
m_gridModel.setSourceModel(filteredModel);
|
||||
|
||||
m_gridView = new GridView(this);
|
||||
m_gridView->setModel(&m_gridModel);
|
||||
m_gridView->setItemDelegate(&m_exampleDelegate);
|
||||
vbox->addWidget(m_gridView);
|
||||
auto gridView = new GridView(this);
|
||||
gridView->setModel(&m_gridModel);
|
||||
gridView->setItemDelegate(&m_exampleDelegate);
|
||||
vbox->addWidget(gridView);
|
||||
|
||||
connect(&m_exampleDelegate, &ExampleDelegate::tagClicked,
|
||||
this, &ExamplesPageWidget::onTagClicked);
|
||||
connect(m_filteredModel, &ExamplesListModelFilter::filterTagsChanged,
|
||||
this, &ExamplesPageWidget::updateStuff);
|
||||
connect(m_filteredModel, &ExamplesListModelFilter::searchStringChanged,
|
||||
this, &ExamplesPageWidget::updateStuff);
|
||||
connect(m_searchBox->m_lineEdit, &QLineEdit::textChanged,
|
||||
m_filteredModel, &ExamplesListModelFilter::setSearchString);
|
||||
connect(m_searcher, &QLineEdit::textChanged,
|
||||
filteredModel, &ExamplesListModelFilter::setSearchString);
|
||||
}
|
||||
|
||||
int bestColumnCount() const
|
||||
@@ -639,26 +642,14 @@ public:
|
||||
|
||||
void onTagClicked(const QString &tag)
|
||||
{
|
||||
QString text = m_searchBox->m_lineEdit->text();
|
||||
m_searchBox->m_lineEdit->setText(text + QString("tag:\"%1\" ").arg(tag));
|
||||
}
|
||||
|
||||
void updateStuff()
|
||||
{
|
||||
if (m_isExamples) {
|
||||
m_qtVersionSelector->clear();
|
||||
m_qtVersionSelector->addItems(m_examplesModel->exampleSets());
|
||||
m_qtVersionSelector->setCurrentIndex(m_examplesModel->selectedExampleSet());
|
||||
}
|
||||
QString text = m_searcher->text();
|
||||
m_searcher->setText(text + QString("tag:\"%1\" ").arg(tag));
|
||||
}
|
||||
|
||||
const bool m_isExamples;
|
||||
ExampleDelegate m_exampleDelegate;
|
||||
QPointer<ExamplesListModel> m_examplesModel;
|
||||
ExamplesListModelFilter *m_filteredModel;
|
||||
SearchBox *m_searchBox;
|
||||
QComboBox *m_qtVersionSelector = nullptr;
|
||||
GridView *m_gridView;
|
||||
QLineEdit *m_searcher;
|
||||
GridProxyModel m_gridModel;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user