30#include <QDesktopServices>
31#include <QRegularExpression>
32#include <QNetworkProxy>
33#include <QNetworkProxyFactory>
48 const QStringList paths = settings.
value( QStringLiteral(
"help/helpSearchPath" ) ).toStringList();
49 if ( paths.isEmpty() )
58 QString helpPath, fullPath;
59 bool helpFound =
false;
61 const auto constPaths = paths;
62 for (
const QString &path : constPaths )
64 if ( path.endsWith( QLatin1String(
"\\" ) ) || path.endsWith( QLatin1Char(
'/' ) ) )
66 fullPath = path.left( path.size() - 1 );
73 const auto constVariableNames = scope->variableNames();
74 for (
const QString &var : constVariableNames )
76 const QRegularExpression rx( QStringLiteral(
"(<!\\$\\$)*(\\$%1)" ).arg( var ) );
77 fullPath.replace( rx, scope->variable( var ).toString() );
79 fullPath.replace( QRegularExpression( QStringLiteral(
"(\\$\\$)" ) ), QStringLiteral(
"$" ) );
81 helpPath = QStringLiteral(
"%1/%2" ).arg( fullPath, key );
83 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 );
85 if ( helpPath.startsWith( QLatin1String(
"http" ) ) )
87 if ( !QgsHelp::urlExists( helpPath ) )
95 const QString filePath = helpPath.mid( 0, helpPath.lastIndexOf( QLatin1Char(
'#' ) ) );
96 if ( !QFileInfo::exists( filePath ) )
100 helpUrl = QUrl::fromLocalFile( filePath );
101 const int pos = helpPath.lastIndexOf( QLatin1Char(
'#' ) );
104 helpUrl.setFragment( helpPath.mid( helpPath.lastIndexOf( QLatin1Char(
'#' ) ) + 1, -1 ) );
112 return helpFound ?
helpUrl : helpNotFound;
115bool QgsHelp::urlExists(
const QString &url )
120 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)