diff --git a/scripts/process_function_template.py b/scripts/process_function_template.py index 6e1fdf77051..c8cf87df3a6 100644 --- a/scripts/process_function_template.py +++ b/scripts/process_function_template.py @@ -13,12 +13,11 @@ sys.path.append( cpp = open(sys.argv[1], "w", encoding="utf-8") cpp.write( "#include \"qgsexpression.h\"\n" - "\n" - "QHash QgsExpression::sFunctionHelpTexts;\n" + "#include \"qgsexpression_p.h\"\n" "\n" "void QgsExpression::initFunctionHelp()\n" "{\n" - " if( !sFunctionHelpTexts.isEmpty() )\n" + " if( !sFunctionHelpTexts()->isEmpty() )\n" " return;" ) @@ -77,7 +76,7 @@ for f in sorted(glob.glob('resources/function_help/json/*')): if len(list(v['arguments'])) < 1 or len(list(v['arguments'])) > 2: raise BaseException("%s: 1 or 2 arguments expected for operator") - cpp.write("\n\n sFunctionHelpTexts.insert( {0},\n Help( {0}, tr( \"{1}\" ), tr( \"{2}\" ),\n QList()".format( + cpp.write("\n\n sFunctionHelpTexts()->insert( {0},\n Help( {0}, tr( \"{1}\" ), tr( \"{2}\" ),\n QList()".format( name, json_params['type'], json_params['description']) ) @@ -121,7 +120,7 @@ for f in sorted(glob.glob('resources/function_help/text/*')): n = os.path.basename(f) with open(f) as content: - cpp.write("\n\n sFunctionHelpTexts.insert( \"{0}\",\n Help( tr( \"{0}\" ), tr( \"group\" ), tr( \"{1}\" ), QList() ) );\n".format( + cpp.write("\n\n sFunctionHelpTexts()->insert( \"{0}\",\n Help( tr( \"{0}\" ), tr( \"group\" ), tr( \"{1}\" ), QList() ) );\n".format( n, content.read().replace("\\", "\").replace('\\', '\\\\').replace('"', '\\"').replace('\n', '\\n'))) cpp.write("\n}\n") diff --git a/src/core/expression/qgsexpression.cpp b/src/core/expression/qgsexpression.cpp index 60b7568e659..587dcffdf29 100644 --- a/src/core/expression/qgsexpression.cpp +++ b/src/core/expression/qgsexpression.cpp @@ -24,89 +24,11 @@ #include "qgsgeometry.h" #include "qgsproject.h" #include "qgsexpressioncontextutils.h" +#include "qgsexpression_p.h" // from parser extern QgsExpressionNode *parseExpression( const QString &str, QString &parserErrorMsg, QList &parserErrors ); - -struct HelpArg -{ - HelpArg( const QString &arg, const QString &desc, bool descOnly = false, bool syntaxOnly = false, - bool optional = false, const QString &defaultVal = QString() ) - : mArg( arg ) - , mDescription( desc ) - , mDescOnly( descOnly ) - , mSyntaxOnly( syntaxOnly ) - , mOptional( optional ) - , mDefaultVal( defaultVal ) - {} - - QString mArg; - QString mDescription; - bool mDescOnly; - bool mSyntaxOnly; - bool mOptional; - QString mDefaultVal; -}; - -struct HelpExample -{ - HelpExample( const QString &expression, const QString &returns, const QString ¬e = QString() ) - : mExpression( expression ) - , mReturns( returns ) - , mNote( note ) - {} - - QString mExpression; - QString mReturns; - QString mNote; -}; - - -struct HelpVariant -{ - HelpVariant( const QString &name, const QString &description, - const QList &arguments = QList(), - bool variableLenArguments = false, - const QList &examples = QList(), - const QString ¬es = QString() ) - : mName( name ) - , mDescription( description ) - , mArguments( arguments ) - , mVariableLenArguments( variableLenArguments ) - , mExamples( examples ) - , mNotes( notes ) - {} - - QString mName; - QString mDescription; - QList mArguments; - bool mVariableLenArguments; - QList mExamples; - QString mNotes; -}; - - -struct Help -{ - //! Constructor for expression help - Help() = default; - - Help( const QString &name, const QString &type, const QString &description, const QList &variants ) - : mName( name ) - , mType( type ) - , mDescription( description ) - , mVariants( variants ) - {} - - QString mName; - QString mType; - QString mDescription; - QList mVariants; -}; - -typedef QHash HelpTextHash; -Q_GLOBAL_STATIC( HelpTextHash, sFunctionHelpTexts ) Q_GLOBAL_STATIC( QgsStringMap, sVariableHelpTexts ) Q_GLOBAL_STATIC( QgsStringMap, sGroups ) diff --git a/src/core/expression/qgsexpression_p.h b/src/core/expression/qgsexpression_p.h new file mode 100644 index 00000000000..26279995f68 --- /dev/null +++ b/src/core/expression/qgsexpression_p.h @@ -0,0 +1,111 @@ +/*************************************************************************** + qgsexpression_p.h + --------------- + Date : October 2019 + Copyright : (C) 2019 by Matthias Kuhn + Email : matthias@opengis.ch + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#ifndef QGSEXPRESSIONPRIVATE_H +#define QGSEXPRESSIONPRIVATE_H + +/// @cond PRIVATE + +// +// W A R N I N G +// ------------- +// +// This file is not part of the QGIS API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// + +#define SIP_NO_FILE + +#include "qgsexpression.h" + +struct HelpArg +{ + HelpArg( const QString &arg, const QString &desc, bool descOnly = false, bool syntaxOnly = false, + bool optional = false, const QString &defaultVal = QString() ) + : mArg( arg ) + , mDescription( desc ) + , mDescOnly( descOnly ) + , mSyntaxOnly( syntaxOnly ) + , mOptional( optional ) + , mDefaultVal( defaultVal ) + {} + + QString mArg; + QString mDescription; + bool mDescOnly; + bool mSyntaxOnly; + bool mOptional; + QString mDefaultVal; +}; + +struct HelpExample +{ + HelpExample( const QString &expression, const QString &returns, const QString ¬e = QString() ) + : mExpression( expression ) + , mReturns( returns ) + , mNote( note ) + {} + + QString mExpression; + QString mReturns; + QString mNote; +}; + + +struct HelpVariant +{ + HelpVariant( const QString &name, const QString &description, + const QList &arguments = QList(), + bool variableLenArguments = false, + const QList &examples = QList(), + const QString ¬es = QString() ) + : mName( name ) + , mDescription( description ) + , mArguments( arguments ) + , mVariableLenArguments( variableLenArguments ) + , mExamples( examples ) + , mNotes( notes ) + {} + + QString mName; + QString mDescription; + QList mArguments; + bool mVariableLenArguments; + QList mExamples; + QString mNotes; +}; + + +struct Help +{ + //! Constructor for expression help + Help() = default; + + Help( const QString &name, const QString &type, const QString &description, const QList &variants ) + : mName( name ) + , mType( type ) + , mDescription( description ) + , mVariants( variants ) + {} + + QString mName; + QString mType; + QString mDescription; + QList mVariants; +}; + +typedef QHash HelpTextHash; +Q_GLOBAL_STATIC( HelpTextHash, sFunctionHelpTexts ) +#endif // QGSEXPRESSIONPRIVATE_H