mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
Less global statics in expressions
This commit is contained in:
parent
ce8f25a806
commit
ad22e6386a
@ -13,12 +13,11 @@ sys.path.append(
|
|||||||
cpp = open(sys.argv[1], "w", encoding="utf-8")
|
cpp = open(sys.argv[1], "w", encoding="utf-8")
|
||||||
cpp.write(
|
cpp.write(
|
||||||
"#include \"qgsexpression.h\"\n"
|
"#include \"qgsexpression.h\"\n"
|
||||||
"\n"
|
"#include \"qgsexpression_p.h\"\n"
|
||||||
"QHash<QString, QgsExpression::Help> QgsExpression::sFunctionHelpTexts;\n"
|
|
||||||
"\n"
|
"\n"
|
||||||
"void QgsExpression::initFunctionHelp()\n"
|
"void QgsExpression::initFunctionHelp()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" if( !sFunctionHelpTexts.isEmpty() )\n"
|
" if( !sFunctionHelpTexts()->isEmpty() )\n"
|
||||||
" return;"
|
" 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:
|
if len(list(v['arguments'])) < 1 or len(list(v['arguments'])) > 2:
|
||||||
raise BaseException("%s: 1 or 2 arguments expected for operator")
|
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 sFunctionHelpTexts()->insert( {0},\n Help( {0}, tr( \"{1}\" ), tr( \"{2}\" ),\n QList<HelpVariant>()".format(
|
||||||
name, json_params['type'], json_params['description'])
|
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)
|
n = os.path.basename(f)
|
||||||
|
|
||||||
with open(f) as content:
|
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 sFunctionHelpTexts()->insert( \"{0}\",\n Help( tr( \"{0}\" ), tr( \"group\" ), tr( \"{1}\" ), QList<HelpVariant>() ) );\n".format(
|
||||||
n, content.read().replace("\\", "\").replace('\\', '\\\\').replace('"', '\\"').replace('\n', '\\n')))
|
n, content.read().replace("\\", "\").replace('\\', '\\\\').replace('"', '\\"').replace('\n', '\\n')))
|
||||||
|
|
||||||
cpp.write("\n}\n")
|
cpp.write("\n}\n")
|
||||||
|
@ -24,89 +24,11 @@
|
|||||||
#include "qgsgeometry.h"
|
#include "qgsgeometry.h"
|
||||||
#include "qgsproject.h"
|
#include "qgsproject.h"
|
||||||
#include "qgsexpressioncontextutils.h"
|
#include "qgsexpressioncontextutils.h"
|
||||||
|
#include "qgsexpression_p.h"
|
||||||
|
|
||||||
// from parser
|
// from parser
|
||||||
extern QgsExpressionNode *parseExpression( const QString &str, QString &parserErrorMsg, QList<QgsExpression::ParserError> &parserErrors );
|
extern QgsExpressionNode *parseExpression( const QString &str, QString &parserErrorMsg, QList<QgsExpression::ParserError> &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<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;
|
|
||||||
Q_GLOBAL_STATIC( HelpTextHash, sFunctionHelpTexts )
|
|
||||||
Q_GLOBAL_STATIC( QgsStringMap, sVariableHelpTexts )
|
Q_GLOBAL_STATIC( QgsStringMap, sVariableHelpTexts )
|
||||||
Q_GLOBAL_STATIC( QgsStringMap, sGroups )
|
Q_GLOBAL_STATIC( QgsStringMap, sGroups )
|
||||||
|
|
||||||
|
111
src/core/expression/qgsexpression_p.h
Normal file
111
src/core/expression/qgsexpression_p.h
Normal file
@ -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<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;
|
||||||
|
Q_GLOBAL_STATIC( HelpTextHash, sFunctionHelpTexts )
|
||||||
|
#endif // QGSEXPRESSIONPRIVATE_H
|
Loading…
x
Reference in New Issue
Block a user