forked from qt-creator/qt-creator
WelcomePage: Support additional (non-qt) example sets
Added with setting "Help/InstalledExamples" which is a string list, each string is a triple of (display name, manifest parse path, examples path), joined with '|'. If a documentationPath for a Qt version is already added through the InstalledExamples setting, we do not show an extra combo box item for it. That makes it possible for an installer to register a single example set for the same Qt version in different variants (e.g. iOS, Android x86, Android arm) Change-Id: I42dd8f9ca9cb6cee247e3dc8ce9d014e56852e79 Reviewed-by: Kai Koehne <kai.koehne@digia.com>
This commit is contained in:
@@ -68,7 +68,7 @@ Rectangle {
|
|||||||
width: 200
|
width: 200
|
||||||
anchors.rightMargin: 80
|
anchors.rightMargin: 80
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
model: qtVersionModel
|
model: exampleSetModel
|
||||||
textRole: "text"
|
textRole: "text"
|
||||||
|
|
||||||
|
|
||||||
@@ -76,16 +76,16 @@ Rectangle {
|
|||||||
if (comboBox.model === undefined)
|
if (comboBox.model === undefined)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
examplesModel.filterForQtById(comboBox.model.getId(currentIndex))
|
examplesModel.filterForExampleSet(currentIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
property int qtIndex: examplesModel.qtVersionIndex
|
property int theIndex: examplesModel.exampleSetIndex
|
||||||
|
|
||||||
onQtIndexChanged: {
|
onTheIndexChanged: {
|
||||||
if (comboBox.model === undefined)
|
if (comboBox.model === undefined)
|
||||||
return;
|
return;
|
||||||
if (qtIndex != currentIndex)
|
if (theIndex != currentIndex)
|
||||||
currentIndex = qtIndex;
|
currentIndex = theIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,75 +47,154 @@
|
|||||||
namespace QtSupport {
|
namespace QtSupport {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
const int noQtVersionsId = -0xff;
|
static bool debugExamples()
|
||||||
static const char currentQtVersionFilterSettingsKeyC[] = "WelcomePageQtVersionFilter";
|
|
||||||
|
|
||||||
int uniqueQtVersionIdSetting()
|
|
||||||
{
|
{
|
||||||
QSettings *settings = Core::ICore::settings();
|
static bool isDebugging = !qgetenv("QTC_DEBUG_EXAMPLESMODEL").isEmpty();
|
||||||
int id = settings->value(QLatin1String(currentQtVersionFilterSettingsKeyC), noQtVersionsId).toInt();
|
return isDebugging;
|
||||||
return id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setUniqueQtVersionIdSetting(int id)
|
static const char kSelectedExampleSetKey[] = "WelcomePage/SelectedExampleSet";
|
||||||
|
|
||||||
|
void ExampleSetModel::writeCurrentIdToSettings(int currentIndex) const
|
||||||
{
|
{
|
||||||
QSettings *settings = Core::ICore::settings();
|
QSettings *settings = Core::ICore::settings();
|
||||||
settings->setValue(QLatin1String(currentQtVersionFilterSettingsKeyC), id);
|
settings->setValue(QLatin1String(kSelectedExampleSetKey), getId(currentIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
QtVersionsModel::QtVersionsModel(ExamplesListModel *examplesModel, QObject *parent) :
|
int ExampleSetModel::readCurrentIndexFromSettings() const
|
||||||
|
{
|
||||||
|
QVariant id = Core::ICore::settings()->value(QLatin1String(kSelectedExampleSetKey));
|
||||||
|
for (int i=0; i < rowCount(); i++) {
|
||||||
|
if (id == getId(i))
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ExampleSetModel::ExampleSetModel(ExamplesListModel *examplesModel, QObject *parent) :
|
||||||
QStandardItemModel(parent),
|
QStandardItemModel(parent),
|
||||||
examplesModel(examplesModel)
|
examplesModel(examplesModel)
|
||||||
{
|
{
|
||||||
QHash<int, QByteArray> roleNames;
|
QHash<int, QByteArray> roleNames;
|
||||||
roleNames[Qt::UserRole + 1] = "text";
|
roleNames[Qt::UserRole + 1] = "text";
|
||||||
roleNames[Qt::UserRole + 2] = "QtId";
|
roleNames[Qt::UserRole + 2] = "QtId";
|
||||||
|
roleNames[Qt::UserRole + 3] = "extraSetIndex";
|
||||||
setRoleNames(roleNames);
|
setRoleNames(roleNames);
|
||||||
|
|
||||||
connect(examplesModel, SIGNAL(qtVersionsUpdated()), this, SLOT(update()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtVersionsModel::update()
|
void ExampleSetModel::update()
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
|
QSet<QString> extraManifestDirs;
|
||||||
|
QList<ExamplesListModel::ExtraExampleSet> extraExampleSets = examplesModel->extraExampleSets();
|
||||||
|
for (int i = 0; i < extraExampleSets.size(); ++i) {
|
||||||
|
ExamplesListModel::ExtraExampleSet set = extraExampleSets.at(i);
|
||||||
|
QStandardItem *newItem = new QStandardItem();
|
||||||
|
newItem->setData(set.displayName, Qt::UserRole + 1);
|
||||||
|
newItem->setData(QVariant(), Qt::UserRole + 2);
|
||||||
|
newItem->setData(i, Qt::UserRole + 3);
|
||||||
|
appendRow(newItem);
|
||||||
|
|
||||||
|
extraManifestDirs.insert(set.manifestPath);
|
||||||
|
}
|
||||||
|
|
||||||
QList<BaseQtVersion *> qtVersions = examplesModel->qtVersions();
|
QList<BaseQtVersion *> qtVersions = examplesModel->qtVersions();
|
||||||
|
|
||||||
foreach (BaseQtVersion *version, qtVersions) {
|
foreach (BaseQtVersion *version, qtVersions) {
|
||||||
|
// sanitize away qt versions that have already been added through extra sets
|
||||||
|
if (extraManifestDirs.contains(version->documentationPath())) {
|
||||||
|
if (debugExamples()) {
|
||||||
|
qWarning() << "Not showing Qt version because manifest path is already added through InstalledExamples settings:"
|
||||||
|
<< version->displayName();
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
QStandardItem *newItem = new QStandardItem();
|
QStandardItem *newItem = new QStandardItem();
|
||||||
newItem->setData(version->displayName(), Qt::UserRole + 1);
|
newItem->setData(version->displayName(), Qt::UserRole + 1);
|
||||||
newItem->setData(version->uniqueId(), Qt::UserRole + 2);
|
newItem->setData(version->uniqueId(), Qt::UserRole + 2);
|
||||||
|
newItem->setData(QVariant(), Qt::UserRole + 3);
|
||||||
appendRow(newItem);
|
appendRow(newItem);
|
||||||
}
|
}
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
int QtVersionsModel::indexForUniqueId(int uniqueId) {
|
int ExampleSetModel::indexForQtVersion(BaseQtVersion *qtVersion) const
|
||||||
for (int i=0; i < rowCount(); i++) {
|
{
|
||||||
if (uniqueId == getId(i).toInt())
|
// return either the entry with the same QtId, or an extra example set with same path
|
||||||
|
|
||||||
|
// check for Qt version
|
||||||
|
for (int i = 0; i < rowCount(); ++i) {
|
||||||
|
if (getType(i) == QtExampleSet && getQtId(i) == qtVersion->uniqueId())
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
return 0;
|
// 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)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant QtVersionsModel::get(int i)
|
QVariant ExampleSetModel::getDisplayName(int i) const
|
||||||
{
|
{
|
||||||
QModelIndex modelIndex = index(i,0);
|
if (i < 0 || i >= rowCount())
|
||||||
QVariant variant = data(modelIndex, Qt::UserRole + 1);
|
return QVariant();
|
||||||
return variant;
|
return data(index(i, 0), Qt::UserRole + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant QtVersionsModel::getId(int i)
|
// id is either the Qt version uniqueId, or the display name of the extra example set
|
||||||
|
QVariant ExampleSetModel::getId(int i) const
|
||||||
{
|
{
|
||||||
|
if (i < 0 || i >= rowCount())
|
||||||
|
return QVariant();
|
||||||
QModelIndex modelIndex = index(i, 0);
|
QModelIndex modelIndex = index(i, 0);
|
||||||
QVariant variant = data(modelIndex, Qt::UserRole + 2);
|
QVariant variant = data(modelIndex, Qt::UserRole + 2);
|
||||||
|
if (variant.isValid()) // set from qt version
|
||||||
return variant;
|
return variant;
|
||||||
|
return getDisplayName(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
ExampleSetModel::ExampleSetType ExampleSetModel::getType(int i) const
|
||||||
|
{
|
||||||
|
if (i < 0 || i >= rowCount())
|
||||||
|
return InvalidExampleSet;
|
||||||
|
QModelIndex modelIndex = index(i, 0);
|
||||||
|
QVariant variant = data(modelIndex, Qt::UserRole + 2); /*Qt version uniqueId*/
|
||||||
|
if (variant.isValid())
|
||||||
|
return QtExampleSet;
|
||||||
|
return ExtraExampleSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ExampleSetModel::getQtId(int i) const
|
||||||
|
{
|
||||||
|
QTC_ASSERT(i >= 0, return -1);
|
||||||
|
QModelIndex modelIndex = index(i, 0);
|
||||||
|
QVariant variant = data(modelIndex, Qt::UserRole + 2);
|
||||||
|
QTC_ASSERT(variant.isValid(), return -1);
|
||||||
|
QTC_ASSERT(variant.canConvert<int>(), return -1);
|
||||||
|
return variant.toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
int ExampleSetModel::getExtraExampleSetIndex(int i) const
|
||||||
|
{
|
||||||
|
QTC_ASSERT(i >= 0, return -1);
|
||||||
|
QModelIndex modelIndex = index(i, 0);
|
||||||
|
QVariant variant = data(modelIndex, Qt::UserRole + 3);
|
||||||
|
QTC_ASSERT(variant.isValid(), return -1);
|
||||||
|
QTC_ASSERT(variant.canConvert<int>(), return -1);
|
||||||
|
return variant.toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
ExamplesListModel::ExamplesListModel(QObject *parent) :
|
ExamplesListModel::ExamplesListModel(QObject *parent) :
|
||||||
QAbstractListModel(parent),
|
QAbstractListModel(parent),
|
||||||
m_uniqueQtId(uniqueQtVersionIdSetting())
|
m_exampleSetModel(new ExampleSetModel(this, this)),
|
||||||
|
m_selectedExampleSetIndex(-1)
|
||||||
{
|
{
|
||||||
QHash<int, QByteArray> roleNames;
|
QHash<int, QByteArray> roleNames;
|
||||||
roleNames[Name] = "name";
|
roleNames[Name] = "name";
|
||||||
@@ -135,6 +214,37 @@ ExamplesListModel::ExamplesListModel(QObject *parent) :
|
|||||||
roleNames[Platforms] = "platforms";
|
roleNames[Platforms] = "platforms";
|
||||||
roleNames[IsHighlighted] = "isHighlighted";
|
roleNames[IsHighlighted] = "isHighlighted";
|
||||||
setRoleNames(roleNames);
|
setRoleNames(roleNames);
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString fixStringForTags(const QString &string)
|
static QString fixStringForTags(const QString &string)
|
||||||
@@ -170,12 +280,6 @@ static QString relativeOrInstallPath(const QString &path, const QString &manifes
|
|||||||
return relativeResolvedPath;
|
return relativeResolvedPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool debugExamples()
|
|
||||||
{
|
|
||||||
static bool isDebugging = !qgetenv("QTC_DEBUG_EXAMPLESMODEL").isEmpty();
|
|
||||||
return isDebugging;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool isValidExampleOrDemo(ExampleItem &item)
|
static bool isValidExampleOrDemo(ExampleItem &item)
|
||||||
{
|
{
|
||||||
static QString invalidPrefix = QLatin1String("qthelp:////"); /* means that the qthelp url
|
static QString invalidPrefix = QLatin1String("qthelp:////"); /* means that the qthelp url
|
||||||
@@ -417,34 +521,43 @@ void ExamplesListModel::updateQtVersions()
|
|||||||
if (defaultVersion && versions.contains(defaultVersion))
|
if (defaultVersion && versions.contains(defaultVersion))
|
||||||
versions.move(versions.indexOf(defaultVersion), 0);
|
versions.move(versions.indexOf(defaultVersion), 0);
|
||||||
|
|
||||||
if (m_qtVersions == versions)
|
if (m_qtVersions == versions && m_selectedExampleSetIndex >= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_qtVersions = versions;
|
m_qtVersions = versions;
|
||||||
emit qtVersionsUpdated();
|
|
||||||
|
|
||||||
// determine Qt version to show
|
m_exampleSetModel->update();
|
||||||
int newUniqueId = noQtVersionsId;
|
|
||||||
if (m_uniqueQtId != noQtVersionsId) {
|
int currentIndex = m_selectedExampleSetIndex;
|
||||||
//ensure that the unique Qt id is valid
|
if (currentIndex < 0) // reset from settings
|
||||||
|
currentIndex = m_exampleSetModel->readCurrentIndexFromSettings();
|
||||||
|
|
||||||
|
ExampleSetModel::ExampleSetType currentType
|
||||||
|
= m_exampleSetModel->getType(currentIndex);
|
||||||
|
|
||||||
|
if (currentType == ExampleSetModel::InvalidExampleSet) {
|
||||||
|
// select examples corresponding to 'highest' Qt version
|
||||||
|
BaseQtVersion *highestQt = findHighestQtVersion();
|
||||||
|
currentIndex = m_exampleSetModel->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);
|
||||||
|
BaseQtVersion *newQtVersion = 0;
|
||||||
foreach (BaseQtVersion *version, m_qtVersions) {
|
foreach (BaseQtVersion *version, m_qtVersions) {
|
||||||
if (version->uniqueId() == m_uniqueQtId)
|
if (version->uniqueId() == currentQtId) {
|
||||||
newUniqueId = m_uniqueQtId;
|
newQtVersion = version;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!newQtVersion)
|
||||||
if (newUniqueId == noQtVersionsId)
|
newQtVersion = findHighestQtVersion();
|
||||||
newUniqueId = findHighestQtVersion();
|
currentIndex = m_exampleSetModel->indexForQtVersion(newQtVersion);
|
||||||
|
} // nothing to do for extra example sets
|
||||||
if (newUniqueId != m_uniqueQtId) {
|
selectExampleSet(currentIndex);
|
||||||
m_uniqueQtId = newUniqueId;
|
|
||||||
setUniqueQtVersionIdSetting(m_uniqueQtId);
|
|
||||||
emit selectedQtVersionChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
BaseQtVersion *ExamplesListModel::findHighestQtVersion() const
|
||||||
|
|
||||||
int ExamplesListModel::findHighestQtVersion() const
|
|
||||||
{
|
{
|
||||||
QList<BaseQtVersion *> versions = qtVersions();
|
QList<BaseQtVersion *> versions = qtVersions();
|
||||||
|
|
||||||
@@ -467,9 +580,9 @@ int ExamplesListModel::findHighestQtVersion() const
|
|||||||
newVersion = versions.first();
|
newVersion = versions.first();
|
||||||
|
|
||||||
if (!newVersion)
|
if (!newVersion)
|
||||||
return noQtVersionsId;
|
return 0;
|
||||||
|
|
||||||
return newVersion->uniqueId();
|
return newVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList ExamplesListModel::exampleSources(QString *examplesInstallPath, QString *demosInstallPath)
|
QStringList ExamplesListModel::exampleSources(QString *examplesInstallPath, QString *demosInstallPath)
|
||||||
@@ -477,55 +590,49 @@ QStringList ExamplesListModel::exampleSources(QString *examplesInstallPath, QStr
|
|||||||
QStringList sources;
|
QStringList sources;
|
||||||
QString resourceDir = Core::ICore::resourcePath() + QLatin1String("/welcomescreen/");
|
QString resourceDir = Core::ICore::resourcePath() + QLatin1String("/welcomescreen/");
|
||||||
|
|
||||||
// overriding examples with a custom XML file
|
|
||||||
QString exampleFileEnvKey = QLatin1String("QTC_EXAMPLE_FILE");
|
|
||||||
if (Utils::Environment::systemEnvironment().hasKey(exampleFileEnvKey)) {
|
|
||||||
QString filePath = Utils::Environment::systemEnvironment().value(exampleFileEnvKey);
|
|
||||||
if (filePath.endsWith(QLatin1String(".xml")) && QFileInfo(filePath).exists()) {
|
|
||||||
sources.append(filePath);
|
|
||||||
return sources;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Qt Creator shipped tutorials
|
// Qt Creator shipped tutorials
|
||||||
sources << (resourceDir + QLatin1String("/qtcreator_tutorials.xml"));
|
sources << (resourceDir + QLatin1String("/qtcreator_tutorials.xml"));
|
||||||
|
|
||||||
// Read keys from SDK installer
|
QString examplesPath;
|
||||||
QSettings *settings = Core::ICore::settings(QSettings::SystemScope);
|
QString demosPath;
|
||||||
int size = settings->beginReadArray(QLatin1String("ExampleManifests"));
|
QString manifestScanPath;
|
||||||
for (int i = 0; i < size; ++i) {
|
|
||||||
settings->setArrayIndex(i);
|
|
||||||
sources.append(settings->value(QLatin1String("Location")).toString());
|
|
||||||
}
|
|
||||||
settings->endArray();
|
|
||||||
// if the installer set something, that's enough for us
|
|
||||||
if (size > 0)
|
|
||||||
return sources;
|
|
||||||
|
|
||||||
|
ExampleSetModel::ExampleSetType currentType
|
||||||
|
= m_exampleSetModel->getType(m_selectedExampleSetIndex);
|
||||||
|
if (currentType == ExampleSetModel::ExtraExampleSet) {
|
||||||
|
int index = m_exampleSetModel->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);
|
||||||
foreach (BaseQtVersion *version, qtVersions()) {
|
foreach (BaseQtVersion *version, qtVersions()) {
|
||||||
//filter for qt versions
|
if (version->uniqueId() == qtId) {
|
||||||
if (version->uniqueId() != m_uniqueQtId && m_uniqueQtId != noQtVersionsId)
|
manifestScanPath = version->documentationPath();
|
||||||
continue;
|
examplesPath = version->examplesPath();
|
||||||
|
demosPath = version->demosPath();
|
||||||
// search for examples-manifest.xml, demos-manifest.xml in doc/*/
|
break;
|
||||||
QDir qt5docPath = QDir(version->documentationPath());
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!manifestScanPath.isEmpty()) {
|
||||||
|
// search for examples-manifest.xml, demos-manifest.xml in <path>/*/
|
||||||
|
QDir dir = QDir(manifestScanPath);
|
||||||
const QStringList examplesPattern(QLatin1String("examples-manifest.xml"));
|
const QStringList examplesPattern(QLatin1String("examples-manifest.xml"));
|
||||||
const QStringList demosPattern(QLatin1String("demos-manifest.xml"));
|
const QStringList demosPattern(QLatin1String("demos-manifest.xml"));
|
||||||
QFileInfoList fis;
|
QFileInfoList fis;
|
||||||
foreach (QFileInfo subDir, qt5docPath.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot)) {
|
foreach (QFileInfo subDir, dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot)) {
|
||||||
fis << QDir(subDir.absoluteFilePath()).entryInfoList(examplesPattern);
|
fis << QDir(subDir.absoluteFilePath()).entryInfoList(examplesPattern);
|
||||||
fis << QDir(subDir.absoluteFilePath()).entryInfoList(demosPattern);
|
fis << QDir(subDir.absoluteFilePath()).entryInfoList(demosPattern);
|
||||||
}
|
}
|
||||||
if (!fis.isEmpty()) {
|
|
||||||
foreach (const QFileInfo &fi, fis)
|
foreach (const QFileInfo &fi, fis)
|
||||||
sources.append(fi.filePath());
|
sources.append(fi.filePath());
|
||||||
|
}
|
||||||
if (examplesInstallPath)
|
if (examplesInstallPath)
|
||||||
*examplesInstallPath = version->examplesPath();
|
*examplesInstallPath = examplesPath;
|
||||||
if (demosInstallPath)
|
if (demosInstallPath)
|
||||||
*demosInstallPath = version->demosPath();
|
*demosInstallPath = demosPath;
|
||||||
return sources;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return sources;
|
return sources;
|
||||||
}
|
}
|
||||||
@@ -604,18 +711,18 @@ void ExamplesListModel::update()
|
|||||||
updateExamples();
|
updateExamples();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ExamplesListModel::selectedQtVersion() const
|
int ExamplesListModel::selectedExampleSet() const
|
||||||
{
|
{
|
||||||
return m_uniqueQtId;
|
return m_selectedExampleSetIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExamplesListModel::selectQtVersion(int id)
|
void ExamplesListModel::selectExampleSet(int index)
|
||||||
{
|
{
|
||||||
if (m_uniqueQtId != id) {
|
if (index != m_selectedExampleSetIndex) {
|
||||||
m_uniqueQtId = id;
|
m_selectedExampleSetIndex = index;
|
||||||
setUniqueQtVersionIdSetting(id);
|
m_exampleSetModel->writeCurrentIdToSettings(m_selectedExampleSetIndex);
|
||||||
updateExamples();
|
updateExamples();
|
||||||
emit selectedQtVersionChanged();
|
emit selectedExampleSetChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -624,7 +731,6 @@ ExamplesListModelFilter::ExamplesListModelFilter(ExamplesListModel *sourceModel,
|
|||||||
m_showTutorialsOnly(true),
|
m_showTutorialsOnly(true),
|
||||||
m_sourceModel(sourceModel),
|
m_sourceModel(sourceModel),
|
||||||
m_timerId(0),
|
m_timerId(0),
|
||||||
m_qtVersionModel(new QtVersionsModel(sourceModel, this)),
|
|
||||||
m_blockIndexUpdate(false),
|
m_blockIndexUpdate(false),
|
||||||
m_qtVersionManagerInitialized(false),
|
m_qtVersionManagerInitialized(false),
|
||||||
m_helpManagerInitialized(false),
|
m_helpManagerInitialized(false),
|
||||||
@@ -639,7 +745,7 @@ ExamplesListModelFilter::ExamplesListModelFilter(ExamplesListModel *sourceModel,
|
|||||||
|
|
||||||
connect(this, SIGNAL(showTutorialsOnlyChanged()), SLOT(updateFilter()));
|
connect(this, SIGNAL(showTutorialsOnlyChanged()), SLOT(updateFilter()));
|
||||||
|
|
||||||
connect(m_sourceModel, SIGNAL(selectedQtVersionChanged()), this, SIGNAL(qtVersionIndexChanged()));
|
connect(m_sourceModel, SIGNAL(selectedExampleSetChanged()), this, SIGNAL(exampleSetIndexChanged()));
|
||||||
|
|
||||||
setSourceModel(m_sourceModel);
|
setSourceModel(m_sourceModel);
|
||||||
}
|
}
|
||||||
@@ -719,17 +825,17 @@ QVariant ExamplesListModelFilter::data(const QModelIndex &index, int role) const
|
|||||||
return QSortFilterProxyModel::data(index, role);
|
return QSortFilterProxyModel::data(index, role);
|
||||||
}
|
}
|
||||||
|
|
||||||
QAbstractItemModel* ExamplesListModelFilter::qtVersionModel()
|
QAbstractItemModel* ExamplesListModelFilter::exampleSetModel()
|
||||||
{
|
{
|
||||||
return m_qtVersionModel;
|
return m_sourceModel->exampleSetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExamplesListModelFilter::filterForQtById(int id)
|
void ExamplesListModelFilter::filterForExampleSet(int index)
|
||||||
{
|
{
|
||||||
if (m_blockIndexUpdate || !m_initalized)
|
if (m_blockIndexUpdate || !m_initalized)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_sourceModel->selectQtVersion(id);
|
m_sourceModel->selectExampleSet(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExamplesListModelFilter::setShowTutorialsOnly(bool showTutorialsOnly)
|
void ExamplesListModelFilter::setShowTutorialsOnly(bool showTutorialsOnly)
|
||||||
@@ -785,11 +891,9 @@ void ExamplesListModelFilter::delayedUpdateFilter()
|
|||||||
m_timerId = startTimer(320);
|
m_timerId = startTimer(320);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ExamplesListModelFilter::qtVersionIndex() const
|
int ExamplesListModelFilter::exampleSetIndex() const
|
||||||
{
|
{
|
||||||
int id = m_sourceModel->selectedQtVersion();
|
return m_sourceModel->selectedExampleSet();
|
||||||
int index = m_qtVersionModel->indexForUniqueId(id);
|
|
||||||
return index;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExamplesListModelFilter::timerEvent(QTimerEvent *timerEvent)
|
void ExamplesListModelFilter::timerEvent(QTimerEvent *timerEvent)
|
||||||
|
|||||||
@@ -42,20 +42,30 @@ namespace Internal {
|
|||||||
|
|
||||||
class ExamplesListModel;
|
class ExamplesListModel;
|
||||||
|
|
||||||
class QtVersionsModel : public QStandardItemModel
|
class ExampleSetModel : public QStandardItemModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QtVersionsModel(ExamplesListModel *examplesModel, QObject *parent);
|
enum ExampleSetType {
|
||||||
|
InvalidExampleSet,
|
||||||
|
QtExampleSet,
|
||||||
|
ExtraExampleSet
|
||||||
|
};
|
||||||
|
|
||||||
int indexForUniqueId(int uniqueId);
|
ExampleSetModel(ExamplesListModel *examplesModel, QObject *parent);
|
||||||
|
|
||||||
public slots:
|
void writeCurrentIdToSettings(int currentIndex) const;
|
||||||
|
int readCurrentIndexFromSettings() const;
|
||||||
|
|
||||||
|
int indexForQtVersion(BaseQtVersion *qtVersion) const;
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
QVariant get(int i);
|
QVariant getDisplayName(int index) const;
|
||||||
QVariant getId(int i);
|
QVariant getId(int index) const;
|
||||||
|
ExampleSetType getType(int i) const;
|
||||||
|
int getQtId(int index) const;
|
||||||
|
int getExtraExampleSetIndex(int index) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ExamplesListModel *examplesModel;
|
ExamplesListModel *examplesModel;
|
||||||
@@ -100,6 +110,12 @@ class ExamplesListModel : public QAbstractListModel
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
struct ExtraExampleSet {
|
||||||
|
QString displayName;
|
||||||
|
QString manifestPath;
|
||||||
|
QString examplesPath;
|
||||||
|
};
|
||||||
|
|
||||||
explicit ExamplesListModel(QObject *parent);
|
explicit ExamplesListModel(QObject *parent);
|
||||||
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
@@ -112,14 +128,15 @@ public:
|
|||||||
|
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
int selectedQtVersion() const;
|
int selectedExampleSet() const;
|
||||||
void selectQtVersion(int id);
|
void selectExampleSet(int index);
|
||||||
|
|
||||||
QList<BaseQtVersion*> qtVersions() const { return m_qtVersions; }
|
QList<BaseQtVersion*> qtVersions() const { return m_qtVersions; }
|
||||||
|
QList<ExtraExampleSet> extraExampleSets() const { return m_extraExampleSets; }
|
||||||
|
QAbstractItemModel* exampleSetModel() { return m_exampleSetModel; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void qtVersionsUpdated();
|
void selectedExampleSetChanged();
|
||||||
void selectedQtVersionChanged();
|
|
||||||
void tagsUpdated();
|
void tagsUpdated();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -127,7 +144,7 @@ private:
|
|||||||
void updateExamples();
|
void updateExamples();
|
||||||
|
|
||||||
void updateSelectedQtVersion();
|
void updateSelectedQtVersion();
|
||||||
int findHighestQtVersion() const;
|
BaseQtVersion *findHighestQtVersion() const;
|
||||||
|
|
||||||
void parseExamples(QXmlStreamReader *reader, const QString &projectsOffset,
|
void parseExamples(QXmlStreamReader *reader, const QString &projectsOffset,
|
||||||
const QString &examplesInstallPath);
|
const QString &examplesInstallPath);
|
||||||
@@ -136,10 +153,12 @@ private:
|
|||||||
void parseTutorials(QXmlStreamReader *reader, const QString &projectsOffset);
|
void parseTutorials(QXmlStreamReader *reader, const QString &projectsOffset);
|
||||||
QStringList exampleSources(QString *examplesInstallPath, QString *demosInstallPath);
|
QStringList exampleSources(QString *examplesInstallPath, QString *demosInstallPath);
|
||||||
|
|
||||||
|
ExampleSetModel* m_exampleSetModel;
|
||||||
QList<BaseQtVersion*> m_qtVersions;
|
QList<BaseQtVersion*> m_qtVersions;
|
||||||
|
QList<ExtraExampleSet> m_extraExampleSets;
|
||||||
QList<ExampleItem> m_exampleItems;
|
QList<ExampleItem> m_exampleItems;
|
||||||
QStringList m_tags;
|
QStringList m_tags;
|
||||||
int m_uniqueQtId;
|
int m_selectedExampleSetIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ExamplesListModelFilter : public QSortFilterProxyModel
|
class ExamplesListModelFilter : public QSortFilterProxyModel
|
||||||
@@ -151,8 +170,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)
|
||||||
|
|
||||||
Q_PROPERTY(QAbstractItemModel* qtVersionModel READ qtVersionModel)
|
Q_PROPERTY(int exampleSetIndex READ exampleSetIndex NOTIFY exampleSetIndexChanged)
|
||||||
Q_PROPERTY(int qtVersionIndex READ qtVersionIndex NOTIFY qtVersionIndexChanged)
|
|
||||||
|
|
||||||
explicit ExamplesListModelFilter(ExamplesListModel *sourceModel, QObject *parent);
|
explicit ExamplesListModelFilter(ExamplesListModel *sourceModel, QObject *parent);
|
||||||
|
|
||||||
@@ -164,9 +182,9 @@ public:
|
|||||||
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||||
QAbstractItemModel* qtVersionModel();
|
QAbstractItemModel* exampleSetModel();
|
||||||
|
|
||||||
Q_INVOKABLE void filterForQtById(int id);
|
Q_INVOKABLE void filterForExampleSet(int index);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setFilterTags(const QStringList &arg)
|
void setFilterTags(const QStringList &arg)
|
||||||
@@ -195,7 +213,7 @@ signals:
|
|||||||
void showTutorialsOnlyChanged();
|
void showTutorialsOnlyChanged();
|
||||||
void filterTagsChanged(const QStringList &arg);
|
void filterTagsChanged(const QStringList &arg);
|
||||||
void searchStrings(const QStringList &arg);
|
void searchStrings(const QStringList &arg);
|
||||||
void qtVersionIndexChanged();
|
void exampleSetIndexChanged();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void qtVersionManagerLoaded();
|
void qtVersionManagerLoaded();
|
||||||
@@ -206,14 +224,13 @@ private:
|
|||||||
void tryToInitialize();
|
void tryToInitialize();
|
||||||
void timerEvent(QTimerEvent *event);
|
void timerEvent(QTimerEvent *event);
|
||||||
void delayedUpdateFilter();
|
void delayedUpdateFilter();
|
||||||
int qtVersionIndex() const;
|
int exampleSetIndex() const;
|
||||||
|
|
||||||
bool m_showTutorialsOnly;
|
bool m_showTutorialsOnly;
|
||||||
QStringList m_filterTags;
|
QStringList m_filterTags;
|
||||||
QStringList m_searchString;
|
QStringList m_searchString;
|
||||||
ExamplesListModel *m_sourceModel;
|
ExamplesListModel *m_sourceModel;
|
||||||
int m_timerId;
|
int m_timerId;
|
||||||
QtVersionsModel* m_qtVersionModel;
|
|
||||||
bool m_blockIndexUpdate;
|
bool m_blockIndexUpdate;
|
||||||
bool m_qtVersionManagerInitialized;
|
bool m_qtVersionManagerInitialized;
|
||||||
bool m_helpManagerInitialized;
|
bool m_helpManagerInitialized;
|
||||||
|
|||||||
@@ -268,7 +268,7 @@ void ExamplesWelcomePage::facilitateQml(QQmlEngine *engine)
|
|||||||
if (m_showExamples) {
|
if (m_showExamples) {
|
||||||
proxy->setShowTutorialsOnly(false);
|
proxy->setShowTutorialsOnly(false);
|
||||||
rootContenxt->setContextProperty(QLatin1String("examplesModel"), proxy);
|
rootContenxt->setContextProperty(QLatin1String("examplesModel"), proxy);
|
||||||
rootContenxt->setContextProperty(QLatin1String("qtVersionModel"), proxy->qtVersionModel());
|
rootContenxt->setContextProperty(QLatin1String("exampleSetModel"), proxy->exampleSetModel());
|
||||||
} else {
|
} else {
|
||||||
rootContenxt->setContextProperty(QLatin1String("tutorialsModel"), proxy);
|
rootContenxt->setContextProperty(QLatin1String("tutorialsModel"), proxy);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user