Skip to content

Commit

Permalink
allow using expression variables in help path. Currently only from
Browse files Browse the repository at this point in the history
global scope. Syntax should be '$variable_name', e.g. $qgis_version.
When accessing help those variables will be replaced with corresponding
values
  • Loading branch information
alexbruy committed Jan 10, 2017
1 parent c2bd4b9 commit a074343
Showing 1 changed file with 13 additions and 27 deletions.
40 changes: 13 additions & 27 deletions src/gui/qgshelp.cpp
Expand Up @@ -16,7 +16,6 @@
#include "qgshelp.h"

#include <QSettings>
#include <QLocale>
#include <QUrl>
#include <QFileInfo>
#include <QTcpSocket>
Expand All @@ -26,6 +25,7 @@

#include "qgis.h"
#include "qgsapplication.h"
#include "qgsexpressioncontext.h"

void QgsHelp::openHelp( const QString& key )
{
Expand All @@ -43,39 +43,25 @@ QUrl QgsHelp::helpUrl( const QString& key )
return helpNotFound;
}

QString qgisLocale;
bool overrideLocale = settings.value( QStringLiteral( "locale/overrideFlag" ), false ).toBool();
if ( overrideLocale )
{
qgisLocale = settings.value( QStringLiteral( "locale/userLocale" ), QString() ).toString();
}
else
{
qgisLocale = QLocale::system().name().left( 2 );
}

QString qgisVersion;
if ( Qgis::QGIS_VERSION_INT / 100 % 100 == 99 )
{
qgisVersion = QStringLiteral( "testing" );
qgisLocale = QStringLiteral( "en" );
}
else
{
qgisVersion = QStringLiteral( "%1.%2" ).arg( Qgis::QGIS_VERSION_INT / 10000 ).arg( Qgis::QGIS_VERSION_INT / 100 % 100 );
}

QString suffix = QStringLiteral( "%1/%2/docs/user_manual/%3" ).arg( qgisVersion ).arg( qgisLocale ).arg( key );
QgsExpressionContextScope *scope = QgsExpressionContextUtils::globalScope();

QUrl helpUrl;
QString helpPath;
QString helpPath, fullPath;
bool helpFound = false;

Q_FOREACH ( const QString& path, paths )
{
helpPath = QStringLiteral( "%1/%2" ).arg( path ).arg( suffix );
qDebug() << "PATH " << path;
fullPath = path;
Q_FOREACH ( const QString& var, scope->variableNames() )
{
fullPath.replace( QStringLiteral( "$%1" ).arg( var ), scope->variable( var ).toString() );
}

helpPath = QStringLiteral( "%1/%2" ).arg( fullPath ).arg( key );
qDebug() << "HELP " << helpPath;

if ( path.startsWith( QStringLiteral( "http" ) ) )
if ( helpPath.startsWith( QStringLiteral( "http" ) ) )
{
if ( !QgsHelp::urlExists( helpPath ) )
{
Expand Down

0 comments on commit a074343

Please sign in to comment.