31#include <QDesktopServices>
32#include <QRegularExpression>
33#include <QNetworkProxy>
34#include <QNetworkProxyFactory>
49 const QStringList paths = settings.
value( QStringLiteral(
"help/helpSearchPath" ) ).toStringList();
50 if ( paths.isEmpty() )
59 QString helpPath, fullPath;
60 bool helpFound =
false;
62 const auto constPaths = paths;
63 for (
const QString &path : constPaths )
65 if ( path.endsWith( QLatin1String(
"\\" ) ) || path.endsWith( QLatin1Char(
'/' ) ) )
67 fullPath = path.left( path.size() - 1 );
74 const auto constVariableNames = scope->variableNames();
75 for (
const QString &var : constVariableNames )
77 const QRegularExpression rx( QStringLiteral(
"(<!\\$\\$)*(\\$%1)" ).arg( var ) );
78 fullPath.replace( rx, scope->variable( var ).toString() );
80 const thread_local QRegularExpression pathRx( QStringLiteral(
"(\\$\\$)" ) );
81 fullPath.replace( pathRx, QStringLiteral(
"$" ) );
83 helpPath = QStringLiteral(
"%1/%2" ).arg( fullPath, key );
85 QgsMessageLog::logMessage( QObject::tr(
"Trying to open help using key '%1'. Full URI is '%2'…" ).arg( key ).arg( helpPath ), QObject::tr(
"QGIS Help" ), Qgis::MessageLevel::Info );
87 if ( helpPath.startsWith( QLatin1String(
"http" ) ) )
89 if ( !QgsHelp::urlExists( helpPath ) )
97 const QString filePath = helpPath.mid( 0, helpPath.lastIndexOf( QLatin1Char(
'#' ) ) );
98 if ( !QFileInfo::exists( filePath ) )
102 helpUrl = QUrl::fromLocalFile( filePath );
103 const int pos = helpPath.lastIndexOf( QLatin1Char(
'#' ) );
106 helpUrl.setFragment( helpPath.mid( helpPath.lastIndexOf( QLatin1Char(
'#' ) ) + 1, -1 ) );
114 return helpFound ?
helpUrl : helpNotFound;
117bool QgsHelp::urlExists(
const QString &url )
122 QNetworkRequest req(
helpUrl );
static QString pkgDataPath()
Returns the common root path of all application data directories.
A thread safe class for performing blocking (sync) network requests, with full support for QGIS proxy...
ErrorCode head(QNetworkRequest &request, bool forceRefresh=false, QgsFeedback *feedback=nullptr)
Performs a "head" operation on the specified request.
@ NoError
No error was encountered.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
static QUrl helpUrl(const QString &key)
Returns URI of the help topic for the given key.
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
#define QgsSetRequestInitiatorClass(request, _class)