Examples: Use Qt logging instead of environment variable

Use logging category qtc.examples instead of a custom
QTC_DEBUG_EXAMPLESMODEL environment variable.

Change-Id: Idbd6d4b29dbd7b9e8c5976eca6efeb232bf7fa5f
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Eike Ziller
2023-05-08 10:58:05 +02:00
parent d0881f5542
commit 07934fadcf

View File

@@ -29,6 +29,7 @@
#include <utils/stringutils.h> #include <utils/stringutils.h>
#include <utils/stylehelper.h> #include <utils/stylehelper.h>
#include <QLoggingCategory>
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
@@ -38,6 +39,8 @@ using namespace Utils;
namespace QtSupport { namespace QtSupport {
namespace Internal { namespace Internal {
static QLoggingCategory log = QLoggingCategory("qtc.examples", QtWarningMsg);
static bool debugExamples() static bool debugExamples()
{ {
return qtcEnvironmentVariableIsSet("QTC_DEBUG_EXAMPLESMODEL"); return qtcEnvironmentVariableIsSet("QTC_DEBUG_EXAMPLESMODEL");
@@ -64,16 +67,16 @@ int ExampleSetModel::readCurrentIndexFromSettings() const
ExampleSetModel::ExampleSetModel() ExampleSetModel::ExampleSetModel()
{ {
if (debugExamples() && !log().isDebugEnabled())
log().setEnabled(QtDebugMsg, true);
// read extra example sets settings // read extra example sets settings
QSettings *settings = Core::ICore::settings(); QSettings *settings = Core::ICore::settings();
const QStringList list = settings->value("Help/InstalledExamples", QStringList()).toStringList(); const QStringList list = settings->value("Help/InstalledExamples", QStringList()).toStringList();
if (debugExamples()) qCDebug(log) << "Reading Help/InstalledExamples from settings:" << list;
qWarning() << "Reading Help/InstalledExamples from settings:" << list;
for (const QString &item : list) { for (const QString &item : list) {
const QStringList &parts = item.split(QLatin1Char('|')); const QStringList &parts = item.split(QLatin1Char('|'));
if (parts.size() < 3) { if (parts.size() < 3) {
if (debugExamples()) qCDebug(log) << "Item" << item << "has less than 3 parts (separated by '|'):" << parts;
qWarning() << "Item" << item << "has less than 3 parts (separated by '|'):" << parts;
continue; continue;
} }
ExtraExampleSet set; ExtraExampleSet set;
@@ -82,15 +85,13 @@ ExampleSetModel::ExampleSetModel()
set.examplesPath = parts.at(2); set.examplesPath = parts.at(2);
QFileInfo fi(set.manifestPath); QFileInfo fi(set.manifestPath);
if (!fi.isDir() || !fi.isReadable()) { if (!fi.isDir() || !fi.isReadable()) {
if (debugExamples()) qCDebug(log) << "Manifest path " << set.manifestPath
qWarning() << "Manifest path " << set.manifestPath << "is not a readable directory, ignoring"; << "is not a readable directory, ignoring";
continue; continue;
} }
if (debugExamples()) { qCDebug(log) << "Adding examples set displayName=" << set.displayName
qWarning() << "Adding examples set displayName=" << set.displayName
<< ", manifestPath=" << set.manifestPath << ", manifestPath=" << set.manifestPath
<< ", examplesPath=" << set.examplesPath; << ", examplesPath=" << set.examplesPath;
}
if (!Utils::anyOf(m_extraExampleSets, [&set](const ExtraExampleSet &s) { if (!Utils::anyOf(m_extraExampleSets, [&set](const ExtraExampleSet &s) {
return FilePath::fromString(s.examplesPath).cleanPath() return FilePath::fromString(s.examplesPath).cleanPath()
== FilePath::fromString(set.examplesPath).cleanPath() == FilePath::fromString(set.examplesPath).cleanPath()
@@ -98,8 +99,8 @@ ExampleSetModel::ExampleSetModel()
== FilePath::fromString(set.manifestPath).cleanPath(); == FilePath::fromString(set.manifestPath).cleanPath();
})) { })) {
m_extraExampleSets.append(set); m_extraExampleSets.append(set);
} else if (debugExamples()) { } else {
qWarning() << "Not adding, because example set with same directories exists"; qCDebug(log) << "Not adding, because example set with same directories exists";
} }
} }
m_extraExampleSets += pluginRegisteredExampleSets(); m_extraExampleSets += pluginRegisteredExampleSets();
@@ -138,11 +139,9 @@ void ExampleSetModel::recreateModel(const QtVersions &qtVersions)
if (extraManifestDirs.contains(version->docsPath())) { if (extraManifestDirs.contains(version->docsPath())) {
m_extraExampleSets[extraManifestDirs.value(version->docsPath())].qtVersion m_extraExampleSets[extraManifestDirs.value(version->docsPath())].qtVersion
= version->qtVersion(); = version->qtVersion();
if (debugExamples()) { qCDebug(log) << "Not showing Qt version because manifest path is already added "
qWarning() << "Not showing Qt version because manifest path is already added "
"through InstalledExamples settings:" "through InstalledExamples settings:"
<< version->displayName(); << version->displayName();
}
continue; continue;
} }
auto newItem = new QStandardItem(); auto newItem = new QStandardItem();
@@ -319,11 +318,11 @@ static bool isValidExampleOrDemo(ExampleItem *item)
} }
if (!ok) { if (!ok) {
item->tags.append(QLatin1String("broken")); item->tags.append(QLatin1String("broken"));
if (debugExamples()) qCDebug(log) << QString::fromLatin1("ERROR: Item \"%1\" broken: %2").arg(item->name, reason);
qWarning() << QString::fromLatin1("ERROR: Item \"%1\" broken: %2").arg(item->name, reason);
} }
if (debugExamples() && item->description.isEmpty()) if (item->description.isEmpty())
qWarning() << QString::fromLatin1("WARNING: Item \"%1\" has no description").arg(item->name); qCDebug(log) << QString::fromLatin1("WARNING: Item \"%1\" has no description")
.arg(item->name);
return ok || debugExamples(); return ok || debugExamples();
} }
@@ -396,10 +395,8 @@ void ExamplesViewController::updateExamples()
QList<ExampleItem *> items; QList<ExampleItem *> items;
for (const QString &exampleSource : sources) { for (const QString &exampleSource : sources) {
const auto manifest = FilePath::fromUserInput(exampleSource); const auto manifest = FilePath::fromUserInput(exampleSource);
if (debugExamples()) { qCDebug(log) << QString::fromLatin1("Reading file \"%1\"...")
qWarning() << QString::fromLatin1("Reading file \"%1\"...")
.arg(manifest.absoluteFilePath().toUserOutput()); .arg(manifest.absoluteFilePath().toUserOutput());
}
const expected_str<QList<ExampleItem *>> result const expected_str<QList<ExampleItem *>> result
= parseExamples(manifest, = parseExamples(manifest,
@@ -407,10 +404,8 @@ void ExamplesViewController::updateExamples()
FilePath::fromUserInput(demosInstallPath), FilePath::fromUserInput(demosInstallPath),
m_isExamples); m_isExamples);
if (!result) { if (!result) {
if (debugExamples()) { qCDebug(log) << "ERROR: Could not read examples from" << exampleSource << ":"
qWarning() << "ERROR: Could not read examples from" << exampleSource << ":"
<< result.error(); << result.error();
}
continue; continue;
} }
items += filtered(*result, isValidExampleOrDemo); items += filtered(*result, isValidExampleOrDemo);