mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Less global statics in expressions
This commit is contained in:
parent
ad22e6386a
commit
2b20c61eaf
@ -13,11 +13,11 @@ sys.path.append(
|
||||
cpp = open(sys.argv[1], "w", encoding="utf-8")
|
||||
cpp.write(
|
||||
"#include \"qgsexpression.h\"\n"
|
||||
"#include \"qgsexpression_p.h\"\n"
|
||||
"#include \"qgsexpressionprivate.h\"\n"
|
||||
"\n"
|
||||
"void QgsExpression::initFunctionHelp()\n"
|
||||
"{\n"
|
||||
" if( !sFunctionHelpTexts()->isEmpty() )\n"
|
||||
" if( functionHelpTexts().isEmpty() )\n"
|
||||
" return;"
|
||||
)
|
||||
|
||||
@ -76,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<HelpVariant>()".format(
|
||||
cpp.write("\n\n functionHelpTexts().insert( {0},\n Help( {0}, tr( \"{1}\" ), tr( \"{2}\" ),\n QList<HelpVariant>()".format(
|
||||
name, json_params['type'], json_params['description'])
|
||||
)
|
||||
|
||||
@ -120,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<HelpVariant>() ) );\n".format(
|
||||
cpp.write("\n\n functionHelpTexts().insert( \"{0}\",\n Help( tr( \"{0}\" ), tr( \"group\" ), tr( \"{1}\" ), QList<HelpVariant>() ) );\n".format(
|
||||
n, content.read().replace("\\", "\").replace('\\', '\\\\').replace('"', '\\"').replace('\n', '\\n')))
|
||||
|
||||
cpp.write("\n}\n")
|
||||
|
@ -29,9 +29,15 @@
|
||||
// from parser
|
||||
extern QgsExpressionNode *parseExpression( const QString &str, QString &parserErrorMsg, QList<QgsExpression::ParserError> &parserErrors );
|
||||
|
||||
Q_GLOBAL_STATIC( HelpTextHash, sFunctionHelpTexts )
|
||||
Q_GLOBAL_STATIC( QgsStringMap, sVariableHelpTexts )
|
||||
Q_GLOBAL_STATIC( QgsStringMap, sGroups )
|
||||
|
||||
HelpTextHash &functionHelpTexts()
|
||||
{
|
||||
return *sFunctionHelpTexts();
|
||||
}
|
||||
|
||||
bool QgsExpression::checkExpression( const QString &text, const QgsExpressionContext *context, QString &errorMessage )
|
||||
{
|
||||
QgsExpression exp( text );
|
||||
|
@ -74,6 +74,88 @@ class QgsExpressionPrivate
|
||||
//! Whether prepare() has been called before evaluate()
|
||||
bool mIsPrepared = false;
|
||||
};
|
||||
|
||||
|
||||
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<HelpArg> &arguments = QList<HelpArg>(),
|
||||
bool variableLenArguments = false,
|
||||
const QList<HelpExample> &examples = QList<HelpExample>(),
|
||||
const QString ¬es = QString() )
|
||||
: mName( name )
|
||||
, mDescription( description )
|
||||
, mArguments( arguments )
|
||||
, mVariableLenArguments( variableLenArguments )
|
||||
, mExamples( examples )
|
||||
, mNotes( notes )
|
||||
{}
|
||||
|
||||
QString mName;
|
||||
QString mDescription;
|
||||
QList<HelpArg> mArguments;
|
||||
bool mVariableLenArguments;
|
||||
QList<HelpExample> mExamples;
|
||||
QString mNotes;
|
||||
};
|
||||
|
||||
|
||||
struct Help
|
||||
{
|
||||
//! Constructor for expression help
|
||||
Help() = default;
|
||||
|
||||
Help( const QString &name, const QString &type, const QString &description, const QList<HelpVariant> &variants )
|
||||
: mName( name )
|
||||
, mType( type )
|
||||
, mDescription( description )
|
||||
, mVariants( variants )
|
||||
{}
|
||||
|
||||
QString mName;
|
||||
QString mType;
|
||||
QString mDescription;
|
||||
QList<HelpVariant> mVariants;
|
||||
};
|
||||
|
||||
typedef QHash<QString, Help> HelpTextHash;
|
||||
|
||||
HelpTextHash &functionHelpTexts();
|
||||
|
||||
///@endcond
|
||||
|
||||
#endif // QGSEXPRESSIONPRIVATE_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user