2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-06-30 17:31:41 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-06-30 17:31:41 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-06-30 17:31:41 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2011-06-30 17:31:41 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-06-30 17:31:41 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
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
|
|
|
#include "screenshotcropper.h"
|
|
|
|
|
|
|
|
|
|
#include <QBuffer>
|
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>
|
2018-01-31 12:14:35 +01:00
|
|
|
#include <utils/fileutils.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
|
|
|
|
|
|
|
|
namespace QtSupport {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2014-03-27 17:50:58 +01:00
|
|
|
static bool debugExamples()
|
|
|
|
|
{
|
2017-04-14 09:48:25 +02:00
|
|
|
static bool isDebugging = qEnvironmentVariableIsSet("QTC_DEBUG_EXAMPLESMODEL");
|
2014-03-27 17:50:58 +01:00
|
|
|
return isDebugging;
|
|
|
|
|
}
|
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;
|
|
|
|
|
}
|
|
|
|
|
m_extraExampleSets.append(set);
|
|
|
|
|
if (debugExamples()) {
|
|
|
|
|
qWarning() << "Adding examples set displayName=" << set.displayName
|
|
|
|
|
<< ", manifestPath=" << set.manifestPath
|
|
|
|
|
<< ", examplesPath=" << set.examplesPath;
|
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
|
2017-05-16 14:58:35 +02:00
|
|
|
void ExampleSetModel::recreateModel(const QList<BaseQtVersion *> &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);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-16 14:58:35 +02:00
|
|
|
foreach (BaseQtVersion *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
|
|
|
|
2014-03-27 17:50:58 +01:00
|
|
|
int ExampleSetModel::indexForQtVersion(BaseQtVersion *qtVersion) const
|
|
|
|
|
{
|
|
|
|
|
// 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
|
|
|
|
2017-01-20 12:24:56 +01:00
|
|
|
ExamplesListModel::ExamplesListModel(QObject *parent)
|
2020-01-16 15:48:32 +01:00
|
|
|
: Core::ListModel(parent)
|
2010-11-11 16:49:17 +01:00
|
|
|
{
|
2017-01-20 12:24:56 +01:00
|
|
|
connect(&m_exampleSetModel, &ExampleSetModel::selectedExampleSetChanged,
|
|
|
|
|
this, &ExamplesListModel::updateExamples);
|
2018-08-31 16:00:32 +02:00
|
|
|
connect(Core::HelpManager::Signals::instance(),
|
|
|
|
|
&Core::HelpManager::Signals::documentationChanged,
|
|
|
|
|
this,
|
|
|
|
|
&ExamplesListModel::updateExamples);
|
2010-11-11 16:49:17 +01:00
|
|
|
}
|
|
|
|
|
|
2012-12-19 10:19:35 +01:00
|
|
|
static QString fixStringForTags(const QString &string)
|
2011-09-28 11:30:30 +02:00
|
|
|
{
|
|
|
|
|
QString returnString = string;
|
2011-09-28 15:25:07 +02:00
|
|
|
returnString.remove(QLatin1String("<i>"));
|
|
|
|
|
returnString.remove(QLatin1String("</i>"));
|
|
|
|
|
returnString.remove(QLatin1String("<tt>"));
|
|
|
|
|
returnString.remove(QLatin1String("</tt>"));
|
2011-09-28 11:30:30 +02:00
|
|
|
return returnString;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-19 10:19:35 +01:00
|
|
|
static QStringList trimStringList(const QStringList &stringlist)
|
2012-03-06 13:14:42 +01:00
|
|
|
{
|
2014-07-29 22:02:56 -07:00
|
|
|
return Utils::transform(stringlist, [](const QString &str) { return str.trimmed(); });
|
2012-03-06 13:14:42 +01:00
|
|
|
}
|
|
|
|
|
|
2012-11-27 17:13:02 +01:00
|
|
|
static QString relativeOrInstallPath(const QString &path, const QString &manifestPath,
|
|
|
|
|
const QString &installPath)
|
|
|
|
|
{
|
|
|
|
|
const QChar slash = QLatin1Char('/');
|
|
|
|
|
const QString relativeResolvedPath = manifestPath + slash + path;
|
|
|
|
|
const QString installResolvedPath = installPath + slash + path;
|
|
|
|
|
if (QFile::exists(relativeResolvedPath))
|
|
|
|
|
return relativeResolvedPath;
|
2012-12-19 10:19:35 +01:00
|
|
|
if (QFile::exists(installResolvedPath))
|
2012-11-27 17:13:02 +01:00
|
|
|
return installResolvedPath;
|
|
|
|
|
// doesn't exist, just return relative
|
|
|
|
|
return relativeResolvedPath;
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
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
|
|
|
}
|
|
|
|
|
|
2012-12-19 10:19:35 +01:00
|
|
|
void ExamplesListModel::parseExamples(QXmlStreamReader *reader,
|
|
|
|
|
const QString &projectsOffset, const QString &examplesInstallPath)
|
2010-11-11 16:49:17 +01:00
|
|
|
{
|
2020-01-22 16:52:27 +01:00
|
|
|
std::unique_ptr<ExampleItem> item;
|
2012-01-06 17:43:27 +01:00
|
|
|
const QChar slash = QLatin1Char('/');
|
2010-11-11 16:49:17 +01:00
|
|
|
while (!reader->atEnd()) {
|
|
|
|
|
switch (reader->readNext()) {
|
|
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
|
if (reader->name() == QLatin1String("example")) {
|
2020-01-22 16:52:27 +01:00
|
|
|
item = std::make_unique<ExampleItem>();
|
2020-01-16 15:48:32 +01:00
|
|
|
item->type = Example;
|
2010-11-11 16:49:17 +01:00
|
|
|
QXmlStreamAttributes attributes = reader->attributes();
|
2020-01-16 15:48:32 +01:00
|
|
|
item->name = attributes.value(QLatin1String("name")).toString();
|
|
|
|
|
item->projectPath = attributes.value(QLatin1String("projectPath")).toString();
|
|
|
|
|
item->hasSourceCode = !item->projectPath.isEmpty();
|
|
|
|
|
item->projectPath = relativeOrInstallPath(item->projectPath, projectsOffset, examplesInstallPath);
|
|
|
|
|
item->imageUrl = attributes.value(QLatin1String("imageUrl")).toString();
|
|
|
|
|
QPixmapCache::remove(item->imageUrl);
|
|
|
|
|
item->docUrl = attributes.value(QLatin1String("docUrl")).toString();
|
|
|
|
|
item->isHighlighted = attributes.value(QLatin1String("isHighlighted")).toString() == QLatin1String("true");
|
2013-02-04 10:16:02 +01:00
|
|
|
|
2010-11-11 16:49:17 +01:00
|
|
|
} else if (reader->name() == QLatin1String("fileToOpen")) {
|
2014-06-16 12:50:32 +02:00
|
|
|
const QString mainFileAttribute = reader->attributes().value(
|
|
|
|
|
QLatin1String("mainFile")).toString();
|
|
|
|
|
const QString filePath = relativeOrInstallPath(
|
|
|
|
|
reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement),
|
|
|
|
|
projectsOffset, examplesInstallPath);
|
2020-01-16 15:48:32 +01:00
|
|
|
item->filesToOpen.append(filePath);
|
2014-06-16 12:50:32 +02:00
|
|
|
if (mainFileAttribute.compare(QLatin1String("true"), Qt::CaseInsensitive) == 0)
|
2020-01-16 15:48:32 +01:00
|
|
|
item->mainFile = filePath;
|
2010-11-11 16:49:17 +01:00
|
|
|
} else if (reader->name() == QLatin1String("description")) {
|
2020-01-16 15:48:32 +01:00
|
|
|
item->description = fixStringForTags(reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement));
|
2011-11-25 13:40:10 +01:00
|
|
|
} else if (reader->name() == QLatin1String("dependency")) {
|
2020-01-16 15:48:32 +01:00
|
|
|
item->dependencies.append(projectsOffset + slash + reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement));
|
2010-11-11 16:49:17 +01:00
|
|
|
} else if (reader->name() == QLatin1String("tags")) {
|
2020-07-21 10:19:36 +02:00
|
|
|
item->tags = trimStringList(reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement).split(QLatin1Char(','), Qt::SkipEmptyParts));
|
2012-03-06 13:14:42 +01:00
|
|
|
} else if (reader->name() == QLatin1String("platforms")) {
|
2020-07-21 10:19:36 +02:00
|
|
|
item->platforms = trimStringList(reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement).split(QLatin1Char(','), Qt::SkipEmptyParts));
|
2012-03-06 13:14:42 +01:00
|
|
|
}
|
2010-11-11 16:49:17 +01:00
|
|
|
break;
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
2012-03-27 18:39:31 +02:00
|
|
|
if (reader->name() == QLatin1String("example")) {
|
2020-01-22 16:52:27 +01:00
|
|
|
if (isValidExampleOrDemo(item.get()))
|
|
|
|
|
m_items.push_back(item.release());
|
2012-03-27 18:39:31 +02:00
|
|
|
} else if (reader->name() == QLatin1String("examples")) {
|
2012-12-19 10:19:35 +01:00
|
|
|
return;
|
2012-03-27 18:39:31 +02:00
|
|
|
}
|
2010-11-11 16:49:17 +01:00
|
|
|
break;
|
|
|
|
|
default: // nothing
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-19 10:19:35 +01:00
|
|
|
void ExamplesListModel::parseDemos(QXmlStreamReader *reader,
|
|
|
|
|
const QString &projectsOffset, const QString &demosInstallPath)
|
2010-11-11 16:49:17 +01:00
|
|
|
{
|
2020-01-27 13:18:42 +01:00
|
|
|
std::unique_ptr<ExampleItem> item;
|
2012-01-06 17:43:27 +01:00
|
|
|
const QChar slash = QLatin1Char('/');
|
2010-11-11 16:49:17 +01:00
|
|
|
while (!reader->atEnd()) {
|
|
|
|
|
switch (reader->readNext()) {
|
|
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
|
if (reader->name() == QLatin1String("demo")) {
|
2020-01-27 13:18:42 +01:00
|
|
|
item = std::make_unique<ExampleItem>();
|
2020-01-16 15:48:32 +01:00
|
|
|
item->type = Demo;
|
2010-11-11 16:49:17 +01:00
|
|
|
QXmlStreamAttributes attributes = reader->attributes();
|
2020-01-16 15:48:32 +01:00
|
|
|
item->name = attributes.value(QLatin1String("name")).toString();
|
|
|
|
|
item->projectPath = attributes.value(QLatin1String("projectPath")).toString();
|
|
|
|
|
item->hasSourceCode = !item->projectPath.isEmpty();
|
|
|
|
|
item->projectPath = relativeOrInstallPath(item->projectPath, projectsOffset, demosInstallPath);
|
|
|
|
|
item->imageUrl = attributes.value(QLatin1String("imageUrl")).toString();
|
|
|
|
|
QPixmapCache::remove(item->imageUrl);
|
|
|
|
|
item->docUrl = attributes.value(QLatin1String("docUrl")).toString();
|
|
|
|
|
item->isHighlighted = attributes.value(QLatin1String("isHighlighted")).toString() == QLatin1String("true");
|
2010-11-11 16:49:17 +01:00
|
|
|
} else if (reader->name() == QLatin1String("fileToOpen")) {
|
2020-01-16 15:48:32 +01:00
|
|
|
item->filesToOpen.append(relativeOrInstallPath(reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement),
|
2012-11-27 17:13:02 +01:00
|
|
|
projectsOffset, demosInstallPath));
|
2010-11-11 16:49:17 +01:00
|
|
|
} else if (reader->name() == QLatin1String("description")) {
|
2020-01-16 15:48:32 +01:00
|
|
|
item->description = fixStringForTags(reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement));
|
2011-11-25 13:40:10 +01:00
|
|
|
} else if (reader->name() == QLatin1String("dependency")) {
|
2020-01-16 15:48:32 +01:00
|
|
|
item->dependencies.append(projectsOffset + slash + reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement));
|
2010-11-11 16:49:17 +01:00
|
|
|
} else if (reader->name() == QLatin1String("tags")) {
|
2020-01-16 15:48:32 +01:00
|
|
|
item->tags = reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement).split(QLatin1Char(','));
|
2010-11-11 16:49:17 +01:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
2012-11-27 17:43:52 +01:00
|
|
|
if (reader->name() == QLatin1String("demo")) {
|
2020-01-27 13:18:42 +01:00
|
|
|
if (isValidExampleOrDemo(item.get()))
|
|
|
|
|
m_items.push_back(item.release());
|
2012-11-27 17:43:52 +01:00
|
|
|
} else if (reader->name() == QLatin1String("demos")) {
|
2012-12-19 10:19:35 +01:00
|
|
|
return;
|
2012-11-27 17:43:52 +01:00
|
|
|
}
|
2010-11-11 16:49:17 +01:00
|
|
|
break;
|
|
|
|
|
default: // nothing
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-19 10:19:35 +01:00
|
|
|
void ExamplesListModel::parseTutorials(QXmlStreamReader *reader, const QString &projectsOffset)
|
2010-11-11 16:49:17 +01:00
|
|
|
{
|
2020-01-27 13:18:42 +01:00
|
|
|
std::unique_ptr<ExampleItem> item;
|
2012-01-06 17:43:27 +01:00
|
|
|
const QChar slash = QLatin1Char('/');
|
2010-11-11 16:49:17 +01:00
|
|
|
while (!reader->atEnd()) {
|
|
|
|
|
switch (reader->readNext()) {
|
|
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
|
if (reader->name() == QLatin1String("tutorial")) {
|
2020-01-27 13:18:42 +01:00
|
|
|
item = std::make_unique<ExampleItem>();
|
2020-01-16 15:48:32 +01:00
|
|
|
item->type = Tutorial;
|
2010-11-11 16:49:17 +01:00
|
|
|
QXmlStreamAttributes attributes = reader->attributes();
|
2020-01-16 15:48:32 +01:00
|
|
|
item->name = attributes.value(QLatin1String("name")).toString();
|
|
|
|
|
item->projectPath = attributes.value(QLatin1String("projectPath")).toString();
|
|
|
|
|
item->hasSourceCode = !item->projectPath.isEmpty();
|
|
|
|
|
item->projectPath.prepend(slash);
|
|
|
|
|
item->projectPath.prepend(projectsOffset);
|
|
|
|
|
item->imageUrl = Utils::StyleHelper::dpiSpecificImageFile(
|
2018-03-14 17:27:02 +01:00
|
|
|
attributes.value(QLatin1String("imageUrl")).toString());
|
2020-01-16 15:48:32 +01:00
|
|
|
QPixmapCache::remove(item->imageUrl);
|
|
|
|
|
item->docUrl = attributes.value(QLatin1String("docUrl")).toString();
|
|
|
|
|
item->isVideo = attributes.value(QLatin1String("isVideo")).toString() == QLatin1String("true");
|
|
|
|
|
item->videoUrl = attributes.value(QLatin1String("videoUrl")).toString();
|
|
|
|
|
item->videoLength = attributes.value(QLatin1String("videoLength")).toString();
|
2010-11-11 16:49:17 +01:00
|
|
|
} else if (reader->name() == QLatin1String("fileToOpen")) {
|
2020-01-16 15:48:32 +01:00
|
|
|
item->filesToOpen.append(projectsOffset + slash + reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement));
|
2010-11-11 16:49:17 +01:00
|
|
|
} else if (reader->name() == QLatin1String("description")) {
|
2020-01-16 15:48:32 +01:00
|
|
|
item->description = fixStringForTags(reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement));
|
2011-11-25 13:40:10 +01:00
|
|
|
} else if (reader->name() == QLatin1String("dependency")) {
|
2020-01-16 15:48:32 +01:00
|
|
|
item->dependencies.append(projectsOffset + slash + reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement));
|
2010-11-11 16:49:17 +01:00
|
|
|
} else if (reader->name() == QLatin1String("tags")) {
|
2020-01-16 15:48:32 +01:00
|
|
|
item->tags = reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement).split(QLatin1Char(','));
|
2010-11-11 16:49:17 +01:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
|
|
|
|
if (reader->name() == QLatin1String("tutorial"))
|
2020-01-27 13:18:42 +01:00
|
|
|
m_items.push_back(item.release());
|
2010-11-11 16:49:17 +01:00
|
|
|
else if (reader->name() == QLatin1String("tutorials"))
|
2012-12-19 10:19:35 +01:00
|
|
|
return;
|
2010-11-11 16:49:17 +01:00
|
|
|
break;
|
|
|
|
|
default: // nothing
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-31 12:14:35 +01:00
|
|
|
static QString resourcePath()
|
|
|
|
|
{
|
|
|
|
|
// normalize paths so QML doesn't freak out if it's wrongly capitalized on Windows
|
2021-04-22 16:15:26 +02:00
|
|
|
return Utils::FileUtils::normalizePathName(Core::ICore::resourcePath().toString());
|
2018-01-31 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2012-01-31 16:36:52 +01:00
|
|
|
void ExamplesListModel::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
|
|
|
|
2017-01-20 12:24:56 +01:00
|
|
|
QStringList sources = m_exampleSetModel.exampleSources(&examplesInstallPath, &demosInstallPath);
|
2012-12-19 10:19:35 +01:00
|
|
|
|
|
|
|
|
beginResetModel();
|
2020-01-16 15:48:32 +01:00
|
|
|
qDeleteAll(m_items);
|
|
|
|
|
m_items.clear();
|
2012-12-19 10:19:35 +01:00
|
|
|
|
|
|
|
|
foreach (const QString &exampleSource, sources) {
|
2010-11-11 16:49:17 +01:00
|
|
|
QFile exampleFile(exampleSource);
|
|
|
|
|
if (!exampleFile.open(QIODevice::ReadOnly)) {
|
2012-12-12 14:01:36 +01:00
|
|
|
if (debugExamples())
|
|
|
|
|
qWarning() << "ERROR: Could not open file" << exampleSource;
|
2012-01-31 16:36:52 +01:00
|
|
|
continue;
|
2010-11-11 16:49:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QFileInfo fi(exampleSource);
|
|
|
|
|
QString offsetPath = fi.path();
|
|
|
|
|
QDir examplesDir(offsetPath);
|
|
|
|
|
QDir demosDir(offsetPath);
|
|
|
|
|
|
2012-12-12 14:01:36 +01:00
|
|
|
if (debugExamples())
|
2014-04-17 14:09:47 +02:00
|
|
|
qWarning() << QString::fromLatin1("Reading file \"%1\"...").arg(fi.absoluteFilePath());
|
2010-11-11 16:49:17 +01:00
|
|
|
QXmlStreamReader reader(&exampleFile);
|
|
|
|
|
while (!reader.atEnd())
|
|
|
|
|
switch (reader.readNext()) {
|
|
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
|
if (reader.name() == QLatin1String("examples"))
|
2012-12-19 10:19:35 +01:00
|
|
|
parseExamples(&reader, examplesDir.path(), examplesInstallPath);
|
2010-11-11 16:49:17 +01:00
|
|
|
else if (reader.name() == QLatin1String("demos"))
|
2012-12-19 10:19:35 +01:00
|
|
|
parseDemos(&reader, demosDir.path(), demosInstallPath);
|
2010-11-11 16:49:17 +01:00
|
|
|
else if (reader.name() == QLatin1String("tutorials"))
|
2012-12-19 10:19:35 +01:00
|
|
|
parseTutorials(&reader, examplesDir.path());
|
2010-11-11 16:49:17 +01:00
|
|
|
break;
|
|
|
|
|
default: // nothing
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-13 17:39:08 +01:00
|
|
|
if (reader.hasError() && debugExamples()) {
|
|
|
|
|
qWarning().noquote().nospace() << "ERROR: Could not parse file as XML document ("
|
|
|
|
|
<< exampleSource << "):" << reader.lineNumber() << ':' << reader.columnNumber()
|
|
|
|
|
<< ": " << reader.errorString();
|
|
|
|
|
}
|
2010-11-11 16:49:17 +01:00
|
|
|
}
|
2012-12-19 10:19:35 +01:00
|
|
|
endResetModel();
|
2010-11-11 16:49:17 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-16 15:48:32 +01:00
|
|
|
QPixmap ExamplesListModel::fetchPixmapAndUpdatePixmapCache(const QString &url) const
|
|
|
|
|
{
|
|
|
|
|
QPixmap pixmap;
|
|
|
|
|
pixmap.load(url);
|
|
|
|
|
if (pixmap.isNull())
|
|
|
|
|
pixmap.load(resourcePath() + "/welcomescreen/widgets/" + url);
|
|
|
|
|
if (pixmap.isNull()) {
|
|
|
|
|
QByteArray fetchedData = Core::HelpManager::fileData(url);
|
|
|
|
|
if (!fetchedData.isEmpty()) {
|
|
|
|
|
QBuffer imgBuffer(&fetchedData);
|
|
|
|
|
imgBuffer.open(QIODevice::ReadOnly);
|
2020-10-27 13:06:58 +01:00
|
|
|
QImageReader reader(&imgBuffer, QFileInfo(url).suffix().toLatin1());
|
2020-01-16 15:48:32 +01:00
|
|
|
QImage img = reader.read();
|
|
|
|
|
img = ScreenshotCropper::croppedImage(img, url, ListModel::defaultImageSize);
|
|
|
|
|
pixmap = QPixmap::fromImage(img);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
QPixmapCache::insert(url, pixmap);
|
|
|
|
|
return pixmap;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-20 12:24:56 +01:00
|
|
|
void ExampleSetModel::updateQtVersionList()
|
2014-02-03 17:17:08 +01:00
|
|
|
{
|
2019-10-08 12:50:16 +02:00
|
|
|
QList<BaseQtVersion *> versions = QtVersionManager::sortVersions(QtVersionManager::versions(
|
|
|
|
|
[](const BaseQtVersion *v) { return v->hasExamples() || v->hasDemos(); }));
|
2014-02-03 17:17:08 +01:00
|
|
|
|
|
|
|
|
// prioritize default qt version
|
|
|
|
|
ProjectExplorer::Kit *defaultKit = ProjectExplorer::KitManager::defaultKit();
|
2019-02-06 12:50:51 +01:00
|
|
|
BaseQtVersion *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
|
2017-05-16 14:58:35 +02:00
|
|
|
BaseQtVersion *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);
|
2017-02-01 15:11:51 +01:00
|
|
|
BaseQtVersion *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
|
|
|
|
|
selectExampleSet(currentIndex);
|
2017-01-20 12:24:56 +01:00
|
|
|
emit selectedExampleSetChanged(currentIndex);
|
2014-02-04 09:29:38 +01:00
|
|
|
}
|
|
|
|
|
|
2017-05-16 14:58:35 +02:00
|
|
|
BaseQtVersion *ExampleSetModel::findHighestQtVersion(const QList<BaseQtVersion *> &versions) const
|
2014-02-04 09:29:38 +01:00
|
|
|
{
|
2017-02-01 15:11:51 +01:00
|
|
|
BaseQtVersion *newVersion = nullptr;
|
|
|
|
|
for (BaseQtVersion *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) {
|
2017-01-20 12:24:56 +01:00
|
|
|
int qtId = getQtId(m_selectedExampleSetIndex);
|
2017-02-01 15:11:51 +01:00
|
|
|
foreach (BaseQtVersion *version, QtVersionManager::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;
|
2014-03-27 17:50:58 +01:00
|
|
|
foreach (QFileInfo subDir, dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot)) {
|
2014-02-04 09:57:17 +01:00
|
|
|
fis << QDir(subDir.absoluteFilePath()).entryInfoList(examplesPattern);
|
|
|
|
|
fis << QDir(subDir.absoluteFilePath()).entryInfoList(demosPattern);
|
|
|
|
|
}
|
2014-03-27 17:50:58 +01:00
|
|
|
foreach (const QFileInfo &fi, fis)
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2020-01-16 15:48:32 +01:00
|
|
|
QString prefixForItem(const ExampleItem *item)
|
2010-11-11 16:49:17 +01:00
|
|
|
{
|
2020-01-16 15:48:32 +01:00
|
|
|
QTC_ASSERT(item, return {});
|
|
|
|
|
if (item->isHighlighted)
|
2013-02-04 10:16:02 +01:00
|
|
|
return QLatin1String("0000 ");
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-11 16:49:17 +01:00
|
|
|
QVariant ExamplesListModel::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
2020-01-16 15:48:32 +01:00
|
|
|
if (!index.isValid() || index.row() >= m_items.count())
|
2010-11-11 16:49:17 +01:00
|
|
|
return QVariant();
|
|
|
|
|
|
2020-01-16 15:48:32 +01:00
|
|
|
ExampleItem *item = static_cast<ExampleItem *>(m_items.at(index.row()));
|
2010-11-11 16:49:17 +01:00
|
|
|
switch (role)
|
|
|
|
|
{
|
|
|
|
|
case Qt::DisplayRole: // for search only
|
2020-01-16 15:48:32 +01:00
|
|
|
return QString(prefixForItem(item) + item->name + ' ' + item->tags.join(' '));
|
2010-11-11 16:49:17 +01:00
|
|
|
default:
|
2020-01-16 15:48:32 +01:00
|
|
|
return ListModel::data(index, role);
|
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) {
|
|
|
|
|
BaseQtVersion *selectedQtVersion = QtVersionManager::version(getQtId(m_selectedExampleSetIndex));
|
|
|
|
|
m_selectedQtTypes = selectedQtVersion->targetDeviceTypes();
|
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
2017-01-20 12:24:56 +01:00
|
|
|
|
2017-01-16 18:06:28 +01:00
|
|
|
ExamplesListModelFilter::ExamplesListModelFilter(ExamplesListModel *sourceModel, bool showTutorialsOnly, QObject *parent) :
|
2020-01-16 15:48:32 +01:00
|
|
|
Core::ListModelFilter(sourceModel, parent),
|
2020-01-21 15:34:33 +02:00
|
|
|
m_showTutorialsOnly(showTutorialsOnly),
|
|
|
|
|
m_examplesListModel(sourceModel)
|
2013-10-15 13:21:17 +02:00
|
|
|
{
|
2010-11-11 16:49:17 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-16 15:48:32 +01:00
|
|
|
bool ExamplesListModelFilter::leaveFilterAcceptsRowBeforeFiltering(const Core::ListItem *item,
|
|
|
|
|
bool *earlyExitResult) const
|
2010-11-11 16:49:17 +01:00
|
|
|
{
|
2020-01-16 15:48:32 +01:00
|
|
|
QTC_ASSERT(earlyExitResult, return false);
|
2011-07-22 14:29:14 +02:00
|
|
|
|
2020-01-21 15:34:33 +02:00
|
|
|
const bool isTutorial = static_cast<const ExampleItem *>(item)->type == Tutorial;
|
|
|
|
|
|
|
|
|
|
if (m_showTutorialsOnly) {
|
|
|
|
|
*earlyExitResult = isTutorial;
|
|
|
|
|
return !isTutorial;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isTutorial) {
|
2020-01-16 15:48:32 +01:00
|
|
|
*earlyExitResult = false;
|
|
|
|
|
return true;
|
2011-07-22 14:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
2020-01-21 15:34:33 +02:00
|
|
|
if (m_examplesListModel->exampleSetModel()->selectedQtSupports(Android::Constants::ANDROID_DEVICE_TYPE)
|
|
|
|
|
&& !item->tags.contains("android")) {
|
2020-01-16 15:48:32 +01:00
|
|
|
*earlyExitResult = false;
|
|
|
|
|
return true;
|
2010-11-11 16:49:17 +01:00
|
|
|
}
|
2020-01-21 15:34:33 +02:00
|
|
|
|
2020-02-13 17:50:33 +02:00
|
|
|
if (m_examplesListModel->exampleSetModel()->selectedQtSupports(Ios::Constants::IOS_DEVICE_TYPE)
|
|
|
|
|
&& !item->tags.contains("ios")) {
|
|
|
|
|
*earlyExitResult = false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-16 15:48:32 +01:00
|
|
|
return false;
|
2011-07-22 14:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
2010-11-11 16:49:17 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QtSupport
|