2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2011-06-30 17:31:41 +02:00
|
|
|
|
2010-11-11 16:49:17 +01:00
|
|
|
#include "exampleslistmodel.h"
|
2018-01-31 12:14:35 +01:00
|
|
|
|
2023-02-21 14:11:40 +01:00
|
|
|
#include "examplesparser.h"
|
2023-01-17 10:35:24 +01:00
|
|
|
#include "qtsupporttr.h"
|
|
|
|
|
|
2018-01-31 12:14:35 +01:00
|
|
|
#include <QBuffer>
|
2022-05-24 12:02:26 +02:00
|
|
|
#include <QApplication>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDir>
|
2012-12-19 10:19:35 +01:00
|
|
|
#include <QFile>
|
2018-01-31 12:14:35 +01:00
|
|
|
#include <QImageReader>
|
|
|
|
|
#include <QPixmapCache>
|
2012-12-05 14:04:55 +01:00
|
|
|
#include <QUrl>
|
2010-11-11 16:49:17 +01:00
|
|
|
|
2020-01-21 15:34:33 +02:00
|
|
|
#include <android/androidconstants.h>
|
2020-02-13 17:50:33 +02:00
|
|
|
#include <ios/iosconstants.h>
|
2011-07-01 18:28:56 +02:00
|
|
|
#include <coreplugin/helpmanager.h>
|
2012-12-19 10:19:35 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2017-01-20 12:24:56 +01:00
|
|
|
|
2012-12-19 10:19:35 +01:00
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2010-11-11 16:49:17 +01:00
|
|
|
#include <qtsupport/qtversionmanager.h>
|
2017-01-20 12:24:56 +01:00
|
|
|
|
|
|
|
|
#include <utils/algorithm.h>
|
2022-08-24 14:56:40 +02:00
|
|
|
#include <utils/environment.h>
|
2022-04-05 11:20:23 +02:00
|
|
|
#include <utils/filepath.h>
|
2012-01-31 16:36:52 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2020-06-17 06:35:31 +02:00
|
|
|
#include <utils/stringutils.h>
|
2018-02-28 15:35:18 +01:00
|
|
|
#include <utils/stylehelper.h>
|
2010-11-11 16:49:17 +01:00
|
|
|
|
|
|
|
|
#include <algorithm>
|
2020-01-22 16:52:27 +01:00
|
|
|
#include <memory>
|
2010-11-11 16:49:17 +01:00
|
|
|
|
2023-01-16 17:20:56 +01:00
|
|
|
using namespace Core;
|
2022-04-05 11:20:23 +02:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2010-11-11 16:49:17 +01:00
|
|
|
namespace QtSupport {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2014-03-27 17:50:58 +01:00
|
|
|
static bool debugExamples()
|
|
|
|
|
{
|
2022-08-24 14:56:40 +02:00
|
|
|
return qtcEnvironmentVariableIsSet("QTC_DEBUG_EXAMPLESMODEL");
|
2014-03-27 17:50:58 +01:00
|
|
|
}
|
2013-02-04 10:28:16 +01:00
|
|
|
|
2014-03-27 17:50:58 +01:00
|
|
|
static const char kSelectedExampleSetKey[] = "WelcomePage/SelectedExampleSet";
|
|
|
|
|
|
|
|
|
|
void ExampleSetModel::writeCurrentIdToSettings(int currentIndex) const
|
2013-02-04 10:28:16 +01:00
|
|
|
{
|
|
|
|
|
QSettings *settings = Core::ICore::settings();
|
2014-03-27 17:50:58 +01:00
|
|
|
settings->setValue(QLatin1String(kSelectedExampleSetKey), getId(currentIndex));
|
2013-02-04 10:28:16 +01:00
|
|
|
}
|
|
|
|
|
|
2014-03-27 17:50:58 +01:00
|
|
|
int ExampleSetModel::readCurrentIndexFromSettings() const
|
2013-02-04 10:28:16 +01:00
|
|
|
{
|
2014-03-27 17:50:58 +01:00
|
|
|
QVariant id = Core::ICore::settings()->value(QLatin1String(kSelectedExampleSetKey));
|
|
|
|
|
for (int i=0; i < rowCount(); i++) {
|
|
|
|
|
if (id == getId(i))
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
2013-02-04 10:28:16 +01:00
|
|
|
}
|
|
|
|
|
|
2017-01-20 12:24:56 +01:00
|
|
|
ExampleSetModel::ExampleSetModel()
|
2013-02-04 10:28:16 +01:00
|
|
|
{
|
2017-01-20 12:24:56 +01:00
|
|
|
// 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;
|
|
|
|
|
}
|
|
|
|
|
if (debugExamples()) {
|
|
|
|
|
qWarning() << "Adding examples set displayName=" << set.displayName
|
|
|
|
|
<< ", manifestPath=" << set.manifestPath
|
|
|
|
|
<< ", examplesPath=" << set.examplesPath;
|
|
|
|
|
}
|
2022-04-05 11:20:23 +02:00
|
|
|
if (!Utils::anyOf(m_extraExampleSets, [&set](const ExtraExampleSet &s) {
|
|
|
|
|
return FilePath::fromString(s.examplesPath).cleanPath()
|
|
|
|
|
== FilePath::fromString(set.examplesPath).cleanPath()
|
|
|
|
|
&& FilePath::fromString(s.manifestPath).cleanPath()
|
|
|
|
|
== FilePath::fromString(set.manifestPath).cleanPath();
|
|
|
|
|
})) {
|
|
|
|
|
m_extraExampleSets.append(set);
|
|
|
|
|
} else if (debugExamples()) {
|
|
|
|
|
qWarning() << "Not adding, because example set with same directories exists";
|
|
|
|
|
}
|
2017-01-20 12:24:56 +01:00
|
|
|
}
|
2019-12-16 14:24:15 +01:00
|
|
|
m_extraExampleSets += pluginRegisteredExampleSets();
|
2017-01-20 12:24:56 +01:00
|
|
|
|
|
|
|
|
connect(QtVersionManager::instance(), &QtVersionManager::qtVersionsLoaded,
|
|
|
|
|
this, &ExampleSetModel::qtVersionManagerLoaded);
|
2017-02-08 10:57:10 +01:00
|
|
|
|
2018-08-31 16:00:32 +02:00
|
|
|
connect(Core::HelpManager::Signals::instance(),
|
|
|
|
|
&Core::HelpManager::Signals::setupFinished,
|
|
|
|
|
this,
|
|
|
|
|
&ExampleSetModel::helpManagerInitialized);
|
2014-02-03 15:56:57 +01:00
|
|
|
}
|
2013-02-04 10:28:16 +01:00
|
|
|
|
2022-01-24 13:25:48 +01:00
|
|
|
void ExampleSetModel::recreateModel(const QtVersions &qtVersions)
|
2014-02-03 15:56:57 +01:00
|
|
|
{
|
|
|
|
|
beginResetModel();
|
|
|
|
|
clear();
|
2013-06-17 14:22:55 +02:00
|
|
|
|
2014-03-27 17:50:58 +01:00
|
|
|
QSet<QString> extraManifestDirs;
|
2017-01-20 12:24:56 +01:00
|
|
|
for (int i = 0; i < m_extraExampleSets.size(); ++i) {
|
|
|
|
|
const ExtraExampleSet &set = m_extraExampleSets.at(i);
|
2018-11-24 15:05:19 +01:00
|
|
|
auto newItem = new QStandardItem();
|
2017-01-20 12:24:56 +01:00
|
|
|
newItem->setData(set.displayName, Qt::DisplayRole);
|
2014-03-27 17:50:58 +01:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 22:27:42 +01:00
|
|
|
for (QtVersion *version : qtVersions) {
|
2014-03-27 17:50:58 +01:00
|
|
|
// sanitize away qt versions that have already been added through extra sets
|
2019-09-30 15:54:11 +02:00
|
|
|
if (extraManifestDirs.contains(version->docsPath().toString())) {
|
2014-03-27 17:50:58 +01:00
|
|
|
if (debugExamples()) {
|
|
|
|
|
qWarning() << "Not showing Qt version because manifest path is already added through InstalledExamples settings:"
|
|
|
|
|
<< version->displayName();
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2018-11-24 15:05:19 +01:00
|
|
|
auto newItem = new QStandardItem();
|
2017-01-20 12:24:56 +01:00
|
|
|
newItem->setData(version->displayName(), Qt::DisplayRole);
|
2014-02-03 17:17:08 +01:00
|
|
|
newItem->setData(version->displayName(), Qt::UserRole + 1);
|
|
|
|
|
newItem->setData(version->uniqueId(), Qt::UserRole + 2);
|
2014-03-27 17:50:58 +01:00
|
|
|
newItem->setData(QVariant(), Qt::UserRole + 3);
|
2014-02-03 17:17:08 +01:00
|
|
|
appendRow(newItem);
|
2013-02-04 10:28:16 +01:00
|
|
|
}
|
2014-02-03 15:56:57 +01:00
|
|
|
endResetModel();
|
|
|
|
|
}
|
2013-02-04 10:28:16 +01:00
|
|
|
|
2022-01-21 16:06:36 +01:00
|
|
|
int ExampleSetModel::indexForQtVersion(QtVersion *qtVersion) const
|
2014-03-27 17:50:58 +01:00
|
|
|
{
|
|
|
|
|
// return either the entry with the same QtId, or an extra example set with same path
|
|
|
|
|
|
2014-04-01 16:37:49 +02:00
|
|
|
if (!qtVersion)
|
|
|
|
|
return -1;
|
|
|
|
|
|
2014-03-27 17:50:58 +01:00
|
|
|
// check for Qt version
|
|
|
|
|
for (int i = 0; i < rowCount(); ++i) {
|
|
|
|
|
if (getType(i) == QtExampleSet && getQtId(i) == qtVersion->uniqueId())
|
2014-02-03 15:56:57 +01:00
|
|
|
return i;
|
2013-02-04 10:28:16 +01:00
|
|
|
}
|
2017-01-20 12:24:56 +01:00
|
|
|
|
2014-03-27 17:50:58 +01:00
|
|
|
// check for extra set
|
2019-09-30 15:54:11 +02:00
|
|
|
const QString &documentationPath = qtVersion->docsPath().toString();
|
2014-03-27 17:50:58 +01:00
|
|
|
for (int i = 0; i < rowCount(); ++i) {
|
2017-01-20 12:24:56 +01:00
|
|
|
if (getType(i) == ExtraExampleSetType
|
|
|
|
|
&& m_extraExampleSets.at(getExtraExampleSetIndex(i)).manifestPath == documentationPath)
|
2014-03-27 17:50:58 +01:00
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
2014-02-03 15:56:57 +01:00
|
|
|
}
|
2013-02-04 10:28:16 +01:00
|
|
|
|
2014-03-27 17:50:58 +01:00
|
|
|
QVariant ExampleSetModel::getDisplayName(int i) const
|
2014-02-03 15:56:57 +01:00
|
|
|
{
|
2014-03-27 17:50:58 +01:00
|
|
|
if (i < 0 || i >= rowCount())
|
|
|
|
|
return QVariant();
|
|
|
|
|
return data(index(i, 0), Qt::UserRole + 1);
|
2014-02-03 15:56:57 +01:00
|
|
|
}
|
|
|
|
|
|
2014-03-27 17:50:58 +01:00
|
|
|
// id is either the Qt version uniqueId, or the display name of the extra example set
|
|
|
|
|
QVariant ExampleSetModel::getId(int i) const
|
2014-02-03 15:56:57 +01:00
|
|
|
{
|
2014-03-27 17:50:58 +01:00
|
|
|
if (i < 0 || i >= rowCount())
|
|
|
|
|
return QVariant();
|
|
|
|
|
QModelIndex modelIndex = index(i, 0);
|
2014-02-03 15:56:57 +01:00
|
|
|
QVariant variant = data(modelIndex, Qt::UserRole + 2);
|
2014-03-27 17:50:58 +01:00
|
|
|
if (variant.isValid()) // set from qt version
|
|
|
|
|
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;
|
2017-01-20 12:24:56 +01:00
|
|
|
return ExtraExampleSetType;
|
2014-03-27 17:50:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
bool ExampleSetModel::selectedQtSupports(const Utils::Id &target) const
|
2020-01-21 15:34:33 +02:00
|
|
|
{
|
|
|
|
|
return m_selectedQtTypes.contains(target);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-27 17:50:58 +01:00
|
|
|
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();
|
2014-02-03 15:56:57 +01:00
|
|
|
}
|
2013-02-04 10:28:16 +01:00
|
|
|
|
2023-01-12 16:10:09 +01:00
|
|
|
static QString resourcePath()
|
|
|
|
|
{
|
|
|
|
|
// normalize paths so QML doesn't freak out if it's wrongly capitalized on Windows
|
|
|
|
|
return Core::ICore::resourcePath().normalizedPathName().toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QPixmap fetchPixmapAndUpdatePixmapCache(const QString &url)
|
|
|
|
|
{
|
|
|
|
|
QPixmap pixmap;
|
|
|
|
|
if (QPixmapCache::find(url, &pixmap))
|
|
|
|
|
return pixmap;
|
|
|
|
|
|
|
|
|
|
if (url.startsWith("qthelp://")) {
|
|
|
|
|
QByteArray fetchedData = Core::HelpManager::fileData(url);
|
|
|
|
|
if (!fetchedData.isEmpty()) {
|
|
|
|
|
QBuffer imgBuffer(&fetchedData);
|
|
|
|
|
imgBuffer.open(QIODevice::ReadOnly);
|
|
|
|
|
QImageReader reader(&imgBuffer, QFileInfo(url).suffix().toLatin1());
|
|
|
|
|
QImage img = reader.read();
|
|
|
|
|
img.convertTo(QImage::Format_RGB32);
|
|
|
|
|
const int dpr = qApp->devicePixelRatio();
|
|
|
|
|
// boundedTo -> don't scale thumbnails up
|
|
|
|
|
const QSize scaledSize = Core::ListModel::defaultImageSize.boundedTo(img.size()) * dpr;
|
|
|
|
|
pixmap = QPixmap::fromImage(
|
|
|
|
|
img.scaled(scaledSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
|
|
|
|
pixmap.setDevicePixelRatio(dpr);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
pixmap.load(url);
|
|
|
|
|
|
|
|
|
|
if (pixmap.isNull())
|
|
|
|
|
pixmap.load(resourcePath() + "/welcomescreen/widgets/" + url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QPixmapCache::insert(url, pixmap);
|
|
|
|
|
|
|
|
|
|
return pixmap;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-17 10:35:24 +01:00
|
|
|
ExamplesViewController::ExamplesViewController(ExampleSetModel *exampleSetModel,
|
|
|
|
|
SectionedGridView *view,
|
|
|
|
|
bool isExamples,
|
|
|
|
|
QObject *parent)
|
|
|
|
|
: QObject(parent)
|
2023-01-16 18:44:54 +01:00
|
|
|
, m_exampleSetModel(exampleSetModel)
|
2023-01-17 10:35:24 +01:00
|
|
|
, m_view(view)
|
2023-01-16 18:44:54 +01:00
|
|
|
, m_isExamples(isExamples)
|
|
|
|
|
{
|
|
|
|
|
if (isExamples) {
|
|
|
|
|
connect(m_exampleSetModel,
|
|
|
|
|
&ExampleSetModel::selectedExampleSetChanged,
|
|
|
|
|
this,
|
2023-01-17 10:35:24 +01:00
|
|
|
&ExamplesViewController::updateExamples);
|
2023-01-16 18:44:54 +01:00
|
|
|
}
|
2018-08-31 16:00:32 +02:00
|
|
|
connect(Core::HelpManager::Signals::instance(),
|
|
|
|
|
&Core::HelpManager::Signals::documentationChanged,
|
|
|
|
|
this,
|
2023-01-17 10:35:24 +01:00
|
|
|
&ExamplesViewController::updateExamples);
|
|
|
|
|
view->setPixmapFunction(fetchPixmapAndUpdatePixmapCache);
|
2023-01-16 18:44:54 +01:00
|
|
|
updateExamples();
|
2010-11-11 16:49:17 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-16 15:48:32 +01:00
|
|
|
static bool isValidExampleOrDemo(ExampleItem *item)
|
2012-12-05 14:04:55 +01:00
|
|
|
{
|
2020-01-16 15:48:32 +01:00
|
|
|
QTC_ASSERT(item, return false);
|
2023-02-21 14:11:40 +01:00
|
|
|
if (item->type == Tutorial)
|
|
|
|
|
return true;
|
2012-12-05 14:04:55 +01:00
|
|
|
static QString invalidPrefix = QLatin1String("qthelp:////"); /* means that the qthelp url
|
|
|
|
|
doesn't have any namespace */
|
2012-12-12 14:01:36 +01:00
|
|
|
QString reason;
|
2012-12-05 14:04:55 +01:00
|
|
|
bool ok = true;
|
2020-01-16 15:48:32 +01:00
|
|
|
if (!item->hasSourceCode || !QFileInfo::exists(item->projectPath)) {
|
2012-12-05 14:04:55 +01:00
|
|
|
ok = false;
|
2020-01-16 15:48:32 +01:00
|
|
|
reason = QString::fromLatin1("projectPath \"%1\" empty or does not exist").arg(item->projectPath);
|
|
|
|
|
} else if (item->imageUrl.startsWith(invalidPrefix) || !QUrl(item->imageUrl).isValid()) {
|
2012-12-05 14:04:55 +01:00
|
|
|
ok = false;
|
2020-01-16 15:48:32 +01:00
|
|
|
reason = QString::fromLatin1("imageUrl \"%1\" not valid").arg(item->imageUrl);
|
|
|
|
|
} else if (!item->docUrl.isEmpty()
|
|
|
|
|
&& (item->docUrl.startsWith(invalidPrefix) || !QUrl(item->docUrl).isValid())) {
|
2012-12-05 14:04:55 +01:00
|
|
|
ok = false;
|
2020-01-16 15:48:32 +01:00
|
|
|
reason = QString::fromLatin1("docUrl \"%1\" non-empty but not valid").arg(item->docUrl);
|
2012-12-12 14:01:36 +01:00
|
|
|
}
|
|
|
|
|
if (!ok) {
|
2020-01-16 15:48:32 +01:00
|
|
|
item->tags.append(QLatin1String("broken"));
|
2012-12-12 14:01:36 +01:00
|
|
|
if (debugExamples())
|
2020-01-16 15:48:32 +01:00
|
|
|
qWarning() << QString::fromLatin1("ERROR: Item \"%1\" broken: %2").arg(item->name, reason);
|
2012-12-12 14:01:36 +01:00
|
|
|
}
|
2020-01-16 15:48:32 +01:00
|
|
|
if (debugExamples() && item->description.isEmpty())
|
|
|
|
|
qWarning() << QString::fromLatin1("WARNING: Item \"%1\" has no description").arg(item->name);
|
2012-12-12 14:01:36 +01:00
|
|
|
return ok || debugExamples();
|
2012-12-05 14:04:55 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-17 10:35:24 +01:00
|
|
|
void ExamplesViewController::updateExamples()
|
2010-11-11 16:49:17 +01:00
|
|
|
{
|
2012-11-27 17:13:02 +01:00
|
|
|
QString examplesInstallPath;
|
|
|
|
|
QString demosInstallPath;
|
2012-12-19 10:19:35 +01:00
|
|
|
|
2023-01-16 18:44:54 +01:00
|
|
|
const QStringList sources = m_exampleSetModel->exampleSources(&examplesInstallPath,
|
|
|
|
|
&demosInstallPath);
|
2012-12-19 10:19:35 +01:00
|
|
|
|
2023-01-17 10:35:24 +01:00
|
|
|
m_view->clear();
|
2023-01-16 17:20:56 +01:00
|
|
|
|
2023-01-16 18:44:54 +01:00
|
|
|
QList<ExampleItem *> items;
|
2022-11-23 22:27:42 +01:00
|
|
|
for (const QString &exampleSource : sources) {
|
2023-02-21 14:11:40 +01:00
|
|
|
if (debugExamples()) {
|
|
|
|
|
qWarning() << QString::fromLatin1("Reading file \"%1\"...")
|
|
|
|
|
.arg(QFileInfo(exampleSource).absoluteFilePath());
|
2010-11-11 16:49:17 +01:00
|
|
|
}
|
|
|
|
|
|
2023-02-21 14:11:40 +01:00
|
|
|
const expected_str<QList<ExampleItem *>> result
|
|
|
|
|
= parseExamples(exampleSource, examplesInstallPath, demosInstallPath, m_isExamples);
|
|
|
|
|
if (!result) {
|
|
|
|
|
if (debugExamples()) {
|
|
|
|
|
qWarning() << "ERROR: Could not read examples from" << exampleSource << ":"
|
|
|
|
|
<< result.error();
|
2010-11-11 16:49:17 +01:00
|
|
|
}
|
2023-02-21 14:11:40 +01:00
|
|
|
continue;
|
2020-01-13 17:39:08 +01:00
|
|
|
}
|
2023-02-21 14:11:40 +01:00
|
|
|
items += filtered(*result, isValidExampleOrDemo);
|
2010-11-11 16:49:17 +01:00
|
|
|
}
|
2023-02-21 14:11:40 +01:00
|
|
|
|
2023-01-16 18:44:54 +01:00
|
|
|
if (m_isExamples) {
|
|
|
|
|
if (m_exampleSetModel->selectedQtSupports(Android::Constants::ANDROID_DEVICE_TYPE)) {
|
|
|
|
|
items = Utils::filtered(items, [](ExampleItem *item) {
|
|
|
|
|
return item->tags.contains("android");
|
|
|
|
|
});
|
|
|
|
|
} else if (m_exampleSetModel->selectedQtSupports(Ios::Constants::IOS_DEVICE_TYPE)) {
|
|
|
|
|
items = Utils::filtered(items,
|
|
|
|
|
[](ExampleItem *item) { return item->tags.contains("ios"); });
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-17 10:35:24 +01:00
|
|
|
Utils::sort(items, [](ExampleItem *first, ExampleItem *second) {
|
|
|
|
|
return first->name.compare(second->name, Qt::CaseInsensitive) < 0;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
QList<ExampleItem *> featured;
|
|
|
|
|
QList<ExampleItem *> other;
|
|
|
|
|
std::tie(featured, other) = Utils::partition(items,
|
|
|
|
|
[](ExampleItem *i) { return i->isHighlighted; });
|
|
|
|
|
|
|
|
|
|
if (!featured.isEmpty()) {
|
|
|
|
|
m_view->addSection({Tr::tr("Featured", "Category for highlighted examples"), 0},
|
|
|
|
|
static_container_cast<ListItem *>(featured));
|
|
|
|
|
}
|
|
|
|
|
m_view->addSection({Tr::tr("Other", "Category for all other examples"), 1},
|
|
|
|
|
static_container_cast<ListItem *>(other));
|
2010-11-11 16:49:17 +01:00
|
|
|
}
|
|
|
|
|
|
2017-01-20 12:24:56 +01:00
|
|
|
void ExampleSetModel::updateQtVersionList()
|
2014-02-03 17:17:08 +01:00
|
|
|
{
|
2022-01-24 13:25:48 +01:00
|
|
|
QtVersions versions = QtVersionManager::sortVersions(QtVersionManager::versions(
|
2022-01-21 16:06:36 +01:00
|
|
|
[](const QtVersion *v) { return v->hasExamples() || v->hasDemos(); }));
|
2014-02-03 17:17:08 +01:00
|
|
|
|
|
|
|
|
// prioritize default qt version
|
|
|
|
|
ProjectExplorer::Kit *defaultKit = ProjectExplorer::KitManager::defaultKit();
|
2022-01-21 16:06:36 +01:00
|
|
|
QtVersion *defaultVersion = QtKitAspect::qtVersion(defaultKit);
|
2014-02-03 17:17:08 +01:00
|
|
|
if (defaultVersion && versions.contains(defaultVersion))
|
|
|
|
|
versions.move(versions.indexOf(defaultVersion), 0);
|
|
|
|
|
|
2017-05-16 14:58:35 +02:00
|
|
|
recreateModel(versions);
|
2014-02-04 09:29:38 +01:00
|
|
|
|
2014-03-27 17:50:58 +01:00
|
|
|
int currentIndex = m_selectedExampleSetIndex;
|
|
|
|
|
if (currentIndex < 0) // reset from settings
|
2017-01-20 12:24:56 +01:00
|
|
|
currentIndex = readCurrentIndexFromSettings();
|
2014-02-04 09:29:38 +01:00
|
|
|
|
2017-01-20 12:24:56 +01:00
|
|
|
ExampleSetModel::ExampleSetType currentType = getType(currentIndex);
|
2014-02-04 09:29:38 +01:00
|
|
|
|
2014-03-27 17:50:58 +01:00
|
|
|
if (currentType == ExampleSetModel::InvalidExampleSet) {
|
|
|
|
|
// select examples corresponding to 'highest' Qt version
|
2022-01-21 16:06:36 +01:00
|
|
|
QtVersion *highestQt = findHighestQtVersion(versions);
|
2017-01-20 12:24:56 +01:00
|
|
|
currentIndex = indexForQtVersion(highestQt);
|
2014-03-27 17:50:58 +01:00
|
|
|
} else if (currentType == ExampleSetModel::QtExampleSet) {
|
|
|
|
|
// try to select the previously selected Qt version, or
|
|
|
|
|
// select examples corresponding to 'highest' Qt version
|
2017-01-20 12:24:56 +01:00
|
|
|
int currentQtId = getQtId(currentIndex);
|
2022-01-21 16:06:36 +01:00
|
|
|
QtVersion *newQtVersion = QtVersionManager::version(currentQtId);
|
2014-03-27 17:50:58 +01:00
|
|
|
if (!newQtVersion)
|
2017-05-16 14:58:35 +02:00
|
|
|
newQtVersion = findHighestQtVersion(versions);
|
2017-01-20 12:24:56 +01:00
|
|
|
currentIndex = indexForQtVersion(newQtVersion);
|
2014-03-27 17:50:58 +01:00
|
|
|
} // nothing to do for extra example sets
|
2022-04-05 12:07:33 +02:00
|
|
|
// Make sure to select something even if the above failed
|
|
|
|
|
if (currentIndex < 0 && rowCount() > 0)
|
|
|
|
|
currentIndex = 0; // simply select first
|
2014-03-27 17:50:58 +01:00
|
|
|
selectExampleSet(currentIndex);
|
2017-01-20 12:24:56 +01:00
|
|
|
emit selectedExampleSetChanged(currentIndex);
|
2014-02-04 09:29:38 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-24 13:25:48 +01:00
|
|
|
QtVersion *ExampleSetModel::findHighestQtVersion(const QtVersions &versions) const
|
2014-02-04 09:29:38 +01:00
|
|
|
{
|
2022-01-21 16:06:36 +01:00
|
|
|
QtVersion *newVersion = nullptr;
|
|
|
|
|
for (QtVersion *version : versions) {
|
2014-02-04 09:29:38 +01:00
|
|
|
if (!newVersion) {
|
|
|
|
|
newVersion = version;
|
|
|
|
|
} else {
|
|
|
|
|
if (version->qtVersion() > newVersion->qtVersion()) {
|
|
|
|
|
newVersion = version;
|
|
|
|
|
} else if (version->qtVersion() == newVersion->qtVersion()
|
|
|
|
|
&& version->uniqueId() < newVersion->uniqueId()) {
|
|
|
|
|
newVersion = version;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!newVersion && !versions.isEmpty())
|
|
|
|
|
newVersion = versions.first();
|
|
|
|
|
|
2014-03-27 17:50:58 +01:00
|
|
|
return newVersion;
|
2014-02-03 17:17:08 +01:00
|
|
|
}
|
|
|
|
|
|
2017-01-20 12:24:56 +01:00
|
|
|
QStringList ExampleSetModel::exampleSources(QString *examplesInstallPath, QString *demosInstallPath)
|
2010-11-11 16:49:17 +01:00
|
|
|
{
|
2012-01-31 16:36:52 +01:00
|
|
|
QStringList sources;
|
|
|
|
|
|
|
|
|
|
// Qt Creator shipped tutorials
|
2017-01-26 16:23:04 +01:00
|
|
|
sources << ":/qtsupport/qtcreator_tutorials.xml";
|
2010-11-11 16:49:17 +01:00
|
|
|
|
2014-03-27 17:50:58 +01:00
|
|
|
QString examplesPath;
|
|
|
|
|
QString demosPath;
|
|
|
|
|
QString manifestScanPath;
|
|
|
|
|
|
2017-01-20 12:24:56 +01:00
|
|
|
ExampleSetModel::ExampleSetType currentType = getType(m_selectedExampleSetIndex);
|
|
|
|
|
if (currentType == ExampleSetModel::ExtraExampleSetType) {
|
|
|
|
|
int index = getExtraExampleSetIndex(m_selectedExampleSetIndex);
|
2014-03-27 17:50:58 +01:00
|
|
|
ExtraExampleSet exampleSet = m_extraExampleSets.at(index);
|
|
|
|
|
manifestScanPath = exampleSet.manifestPath;
|
|
|
|
|
examplesPath = exampleSet.examplesPath;
|
|
|
|
|
demosPath = exampleSet.examplesPath;
|
|
|
|
|
} else if (currentType == ExampleSetModel::QtExampleSet) {
|
2022-11-23 22:27:42 +01:00
|
|
|
const int qtId = getQtId(m_selectedExampleSetIndex);
|
|
|
|
|
const QtVersions versions = QtVersionManager::versions();
|
|
|
|
|
for (QtVersion *version : versions) {
|
2014-03-27 17:50:58 +01:00
|
|
|
if (version->uniqueId() == qtId) {
|
2019-09-30 15:54:11 +02:00
|
|
|
manifestScanPath = version->docsPath().toString();
|
2019-09-30 15:44:52 +02:00
|
|
|
examplesPath = version->examplesPath().toString();
|
2019-09-30 15:48:31 +02:00
|
|
|
demosPath = version->demosPath().toString();
|
2014-03-27 17:50:58 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-08-03 14:19:10 +02:00
|
|
|
}
|
2014-03-27 17:50:58 +01:00
|
|
|
if (!manifestScanPath.isEmpty()) {
|
|
|
|
|
// search for examples-manifest.xml, demos-manifest.xml in <path>/*/
|
|
|
|
|
QDir dir = QDir(manifestScanPath);
|
2014-02-04 09:57:17 +01:00
|
|
|
const QStringList examplesPattern(QLatin1String("examples-manifest.xml"));
|
|
|
|
|
const QStringList demosPattern(QLatin1String("demos-manifest.xml"));
|
|
|
|
|
QFileInfoList fis;
|
2022-11-23 22:27:42 +01:00
|
|
|
const QFileInfoList subDirs = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
|
|
|
|
|
for (QFileInfo subDir : subDirs) {
|
2014-02-04 09:57:17 +01:00
|
|
|
fis << QDir(subDir.absoluteFilePath()).entryInfoList(examplesPattern);
|
|
|
|
|
fis << QDir(subDir.absoluteFilePath()).entryInfoList(demosPattern);
|
|
|
|
|
}
|
2022-11-23 22:27:42 +01:00
|
|
|
for (const QFileInfo &fi : std::as_const(fis))
|
2014-03-27 17:50:58 +01:00
|
|
|
sources.append(fi.filePath());
|
2010-11-11 16:49:17 +01:00
|
|
|
}
|
2014-03-27 17:50:58 +01:00
|
|
|
if (examplesInstallPath)
|
|
|
|
|
*examplesInstallPath = examplesPath;
|
|
|
|
|
if (demosInstallPath)
|
|
|
|
|
*demosInstallPath = demosPath;
|
2010-11-11 16:49:17 +01:00
|
|
|
|
2012-01-31 16:36:52 +01:00
|
|
|
return sources;
|
2010-11-11 16:49:17 +01:00
|
|
|
}
|
|
|
|
|
|
2017-01-20 12:24:56 +01:00
|
|
|
void ExampleSetModel::selectExampleSet(int index)
|
2012-02-01 13:15:08 +01:00
|
|
|
{
|
2017-01-20 12:24:56 +01:00
|
|
|
if (index != m_selectedExampleSetIndex) {
|
|
|
|
|
m_selectedExampleSetIndex = index;
|
|
|
|
|
writeCurrentIdToSettings(m_selectedExampleSetIndex);
|
2020-01-21 15:34:33 +02:00
|
|
|
if (getType(m_selectedExampleSetIndex) == ExampleSetModel::QtExampleSet) {
|
2022-01-21 16:06:36 +01:00
|
|
|
QtVersion *selectedQtVersion = QtVersionManager::version(getQtId(m_selectedExampleSetIndex));
|
2020-01-21 15:34:33 +02:00
|
|
|
m_selectedQtTypes = selectedQtVersion->targetDeviceTypes();
|
2022-09-02 12:13:31 +02:00
|
|
|
} else {
|
|
|
|
|
m_selectedQtTypes.clear();
|
2020-01-21 15:34:33 +02:00
|
|
|
}
|
2017-01-20 12:24:56 +01:00
|
|
|
emit selectedExampleSetChanged(m_selectedExampleSetIndex);
|
|
|
|
|
}
|
2012-02-01 13:15:08 +01:00
|
|
|
}
|
2011-07-01 18:28:56 +02:00
|
|
|
|
2017-01-20 12:24:56 +01:00
|
|
|
void ExampleSetModel::qtVersionManagerLoaded()
|
2014-02-04 09:29:38 +01:00
|
|
|
{
|
2017-01-20 12:24:56 +01:00
|
|
|
m_qtVersionManagerInitialized = true;
|
|
|
|
|
tryToInitialize();
|
2014-02-04 09:29:38 +01:00
|
|
|
}
|
|
|
|
|
|
2017-01-20 12:24:56 +01:00
|
|
|
void ExampleSetModel::helpManagerInitialized()
|
2014-02-04 09:29:38 +01:00
|
|
|
{
|
2017-01-20 12:24:56 +01:00
|
|
|
m_helpManagerInitialized = true;
|
|
|
|
|
tryToInitialize();
|
2014-02-04 09:29:38 +01:00
|
|
|
}
|
|
|
|
|
|
2017-01-20 12:24:56 +01:00
|
|
|
|
|
|
|
|
void ExampleSetModel::tryToInitialize()
|
2017-01-16 18:06:28 +01:00
|
|
|
{
|
2017-02-28 09:36:18 +01:00
|
|
|
if (m_initalized)
|
|
|
|
|
return;
|
|
|
|
|
if (!m_qtVersionManagerInitialized)
|
|
|
|
|
return;
|
2018-08-31 16:00:32 +02:00
|
|
|
if (!m_helpManagerInitialized)
|
2017-01-20 12:24:56 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_initalized = true;
|
|
|
|
|
|
|
|
|
|
connect(QtVersionManager::instance(), &QtVersionManager::qtVersionsChanged,
|
|
|
|
|
this, &ExampleSetModel::updateQtVersionList);
|
|
|
|
|
connect(ProjectExplorer::KitManager::instance(), &ProjectExplorer::KitManager::defaultkitChanged,
|
|
|
|
|
this, &ExampleSetModel::updateQtVersionList);
|
|
|
|
|
|
|
|
|
|
updateQtVersionList();
|
2017-01-16 18:06:28 +01:00
|
|
|
}
|
|
|
|
|
|
2010-11-11 16:49:17 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QtSupport
|