QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsexpression_p.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsexpression_p.h
3 
4  ---------------------
5  begin : 9.12.2015
6  copyright : (C) 2015 by Matthias Kuhn
7  email : [email protected]
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #ifndef QGSEXPRESSIONPRIVATE_H
18 #define QGSEXPRESSIONPRIVATE_H
19 
20 #include <QString>
21 #include <memory>
22 
23 #include "qgsexpression.h"
24 #include "qgsdistancearea.h"
25 #include "qgsunittypes.h"
26 #include "qgsexpressionnode.h"
27 
29 
35 class QgsExpressionPrivate
36 {
37  public:
38  QgsExpressionPrivate()
39  : ref( 1 )
40  {}
41 
42  QgsExpressionPrivate( const QgsExpressionPrivate &other )
43  : ref( 1 )
44  , mRootNode( other.mRootNode ? other.mRootNode->clone() : nullptr )
45  , mParserErrorString( other.mParserErrorString )
46  , mEvalErrorString( other.mEvalErrorString )
47  , mParserErrors( other.mParserErrors )
48  , mExp( other.mExp )
49  , mDaEllipsoid( other.mDaEllipsoid )
50  , mCalc( other.mCalc )
51  , mDistanceUnit( other.mDistanceUnit )
52  , mAreaUnit( other.mAreaUnit )
53  {
54  if ( other.mDaCrs )
55  mDaCrs = std::make_unique<QgsCoordinateReferenceSystem>( *other.mDaCrs.get() );
56  if ( other.mDaTransformContext )
57  mDaTransformContext = std::make_unique<QgsCoordinateTransformContext>( *other.mDaTransformContext.get() );
58  }
59 
60  ~QgsExpressionPrivate()
61  {
62  delete mRootNode;
63  }
64 
65  QAtomicInt ref;
66 
67  QgsExpressionNode *mRootNode = nullptr;
68 
69  QString mParserErrorString;
70  QString mEvalErrorString;
71 
72  QList<QgsExpression::ParserError> mParserErrors;
73 
74  QString mExp;
75 
76  QString mDaEllipsoid;
77  std::unique_ptr<QgsCoordinateReferenceSystem> mDaCrs;
78  std::unique_ptr<QgsCoordinateTransformContext> mDaTransformContext;
79 
80  std::shared_ptr<QgsDistanceArea> mCalc;
83 
85  bool mIsPrepared = false;
86 
87  QgsExpressionPrivate &operator= ( const QgsExpressionPrivate & ) = delete;
88 };
89 
90 
91 struct HelpArg
92 {
93  HelpArg( const QString &arg, const QString &desc, bool descOnly = false, bool syntaxOnly = false,
94  bool optional = false, const QString &defaultVal = QString() )
95  : mArg( arg )
96  , mDescription( desc )
97  , mDescOnly( descOnly )
98  , mSyntaxOnly( syntaxOnly )
99  , mOptional( optional )
100  , mDefaultVal( defaultVal )
101  {}
102 
103  QString mArg;
104  QString mDescription;
105  bool mDescOnly;
106  bool mSyntaxOnly;
107  bool mOptional;
108  QString mDefaultVal;
109 };
110 
111 struct HelpExample
112 {
113  HelpExample( const QString &expression, const QString &returns, const QString &note = QString() )
114  : mExpression( expression )
115  , mReturns( returns )
116  , mNote( note )
117  {}
118 
119  QString mExpression;
120  QString mReturns;
121  QString mNote;
122 };
123 
124 
125 struct HelpVariant
126 {
127  HelpVariant( const QString &name, const QString &description,
128  const QList<HelpArg> &arguments = QList<HelpArg>(),
129  bool variableLenArguments = false,
130  const QList<HelpExample> &examples = QList<HelpExample>(),
131  const QString &notes = QString(),
132  const QStringList &tags = QStringList() )
133  : mName( name )
134  , mDescription( description )
135  , mArguments( arguments )
136  , mVariableLenArguments( variableLenArguments )
137  , mExamples( examples )
138  , mNotes( notes )
139  , mTags( tags )
140  {}
141 
142  QString mName;
143  QString mDescription;
144  QList<HelpArg> mArguments;
145  bool mVariableLenArguments;
146  QList<HelpExample> mExamples;
147  QString mNotes;
148  QStringList mTags;
149 };
150 
151 
152 struct Help
153 {
155  Help() = default;
156 
157  Help( const QString &name, const QString &type, const QString &description, const QList<HelpVariant> &variants )
158  : mName( name )
159  , mType( type )
160  , mDescription( description )
161  , mVariants( variants )
162  {}
163 
164  QString mName;
165  QString mType;
166  QString mDescription;
167  QList<HelpVariant> mVariants;
168 };
169 
170 typedef QHash<QString, Help> HelpTextHash;
171 
172 HelpTextHash &functionHelpTexts();
173 
175 
176 #endif // QGSEXPRESSIONPRIVATE_H
QgsUnitTypes::DistanceUnknownUnit
@ DistanceUnknownUnit
Unknown distance unit.
Definition: qgsunittypes.h:78
qgsexpression.h
qgsunittypes.h
QgsUnitTypes::DistanceUnit
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:67
qgsexpressionnode.h
QgsUnitTypes::AreaUnit
AreaUnit
Units of area.
Definition: qgsunittypes.h:93
QgsExpressionNode
Abstract base class for all nodes that can appear in an expression.
Definition: qgsexpressionnode.h:34
functionHelpTexts
HelpTextHash & functionHelpTexts()
Definition: qgsexpression.cpp:38
qgsdistancearea.h
QgsUnitTypes::AreaUnknownUnit
@ AreaUnknownUnit
Unknown areal unit.
Definition: qgsunittypes.h:106