Skip to content

Commit a074343

Browse files
committed
allow using expression variables in help path. Currently only from
global scope. Syntax should be '$variable_name', e.g. $qgis_version. When accessing help those variables will be replaced with corresponding values
1 parent c2bd4b9 commit a074343

File tree

1 file changed

+13
-27
lines changed

1 file changed

+13
-27
lines changed

src/gui/qgshelp.cpp

+13-27
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "qgshelp.h"
1717

1818
#include <QSettings>
19-
#include <QLocale>
2019
#include <QUrl>
2120
#include <QFileInfo>
2221
#include <QTcpSocket>
@@ -26,6 +25,7 @@
2625

2726
#include "qgis.h"
2827
#include "qgsapplication.h"
28+
#include "qgsexpressioncontext.h"
2929

3030
void QgsHelp::openHelp( const QString& key )
3131
{
@@ -43,39 +43,25 @@ QUrl QgsHelp::helpUrl( const QString& key )
4343
return helpNotFound;
4444
}
4545

46-
QString qgisLocale;
47-
bool overrideLocale = settings.value( QStringLiteral( "locale/overrideFlag" ), false ).toBool();
48-
if ( overrideLocale )
49-
{
50-
qgisLocale = settings.value( QStringLiteral( "locale/userLocale" ), QString() ).toString();
51-
}
52-
else
53-
{
54-
qgisLocale = QLocale::system().name().left( 2 );
55-
}
56-
57-
QString qgisVersion;
58-
if ( Qgis::QGIS_VERSION_INT / 100 % 100 == 99 )
59-
{
60-
qgisVersion = QStringLiteral( "testing" );
61-
qgisLocale = QStringLiteral( "en" );
62-
}
63-
else
64-
{
65-
qgisVersion = QStringLiteral( "%1.%2" ).arg( Qgis::QGIS_VERSION_INT / 10000 ).arg( Qgis::QGIS_VERSION_INT / 100 % 100 );
66-
}
67-
68-
QString suffix = QStringLiteral( "%1/%2/docs/user_manual/%3" ).arg( qgisVersion ).arg( qgisLocale ).arg( key );
46+
QgsExpressionContextScope *scope = QgsExpressionContextUtils::globalScope();
6947

7048
QUrl helpUrl;
71-
QString helpPath;
49+
QString helpPath, fullPath;
7250
bool helpFound = false;
7351

7452
Q_FOREACH ( const QString& path, paths )
7553
{
76-
helpPath = QStringLiteral( "%1/%2" ).arg( path ).arg( suffix );
54+
qDebug() << "PATH " << path;
55+
fullPath = path;
56+
Q_FOREACH ( const QString& var, scope->variableNames() )
57+
{
58+
fullPath.replace( QStringLiteral( "$%1" ).arg( var ), scope->variable( var ).toString() );
59+
}
60+
61+
helpPath = QStringLiteral( "%1/%2" ).arg( fullPath ).arg( key );
62+
qDebug() << "HELP " << helpPath;
7763

78-
if ( path.startsWith( QStringLiteral( "http" ) ) )
64+
if ( helpPath.startsWith( QStringLiteral( "http" ) ) )
7965
{
8066
if ( !QgsHelp::urlExists( helpPath ) )
8167
{

0 commit comments

Comments
 (0)