1 /***************************************************************************
2                       sipifyheader.h - Demo for sipify.pl
3                      --------------------------------------
4 Date                 : 28.03.2017
5 Copyright            : (C) 2017 Denis Rouzaud
6 email                : denis.rouzaud@gmail.com
7  ***************************************************************************
8  *                                                                         *
9  *   This program is free software; you can redistribute it and/or modify  *
10  *   it under the terms of the GNU General Public License as published by  *
11  *   the Free Software Foundation; either version 2 of the License, or     *
12  *   (at your option) any later version.                                   *
13  *                                                                         *
14  ***************************************************************************/
15 
16 #ifndef SIPIFYHEADER_H
17 #define SIPIFYHEADER_H
18 
19 #include "qgis_core.h"
20 #include <QtClass>
21 
22 #ifdef SIP_RUN
23 % ModuleHeaderCode
24 #include <qgsnetworkspeedstrategy.h>
25 #include <qgsnetworkdistancestrategy.h>
26 % End
27 #endif
28 
29 #include "sipifyheader.h"
30 
31 // one shall include qgis.h to use SIP annotations
32 #include "qgis.h"
33 
34 class QgsForwardDeclaration;
35 
36 
37 
38 
39 /***************************************************************************
40  * This is some random block comment that will not be displayed.
41  * Block comments shall will placed upon class, method, enum without
42  * any blank lines in between.
43  ****************************************************************************/
44 
45 // typedef have no Docstring, so commenting here will not be used
46 #ifdef SIP_RUN
47 typedef qint64 QgsFeatureId;
48 #else
49 typedef WhatEver ShouldNotBeDisplayed;
50 #endif
51 
52 typedef QSet<QgsFeatureId SIP_PYALTERNATIVETYPE( qint64 )> QgsFeatureIds;
53 typedef QMap<QgsFeatureId SIP_PYALTERNATIVETYPE( qint64 ), QgsAttributeMap SIP_PYALTERNATIVETYPE( 'QMap<int, QVariant>' )> QgsChangedAttributesMap;
54 typedef QMap<QgsFeatureId, QgsAttributeMap> SIP_PYALTERNATIVETYPE( 'QMap<qint64, QMap<int, QVariant> >' ) QgsChangedAttributesMap;
55 typedef QMap<QgsFeatureId, QPair<QMap<Something, Complex> >>  SIP_PYALTERNATIVETYPE( 'QMap<qint64, QMap<int, QVariant>>' ) QgsChangedAttributesMap;
56 
57 /**
58  * \ingroup core
59  * A super QGIS class
60  */
61 #ifndef SIP_RUN // following will be hidden
62 class CORE_EXPORT QgsSuperClass : public QtClass<QVariant>
63 {
64   public:
65     //! A constructor with definition in header
QgsSuperClass()66     QgsSuperClass()
67       : QtClass<QVariant>()
68     {}
69 };
70 #else // following will be displayed in generated file
71 typedef QVector<QVariant> QgsSuperClass;
72 
73 % MappedType QgsSuperClass
74 {
75   // The annotations are modified by astyle (these will be fixed by sipify.pl)
76   % TypeHeaderCode
77 #include <qgssipifyheader.h>
78   % End
79 
80   % ConvertFromTypeCode
81   // Create the list.
82   PyObject *l;
83   return l;
84   % End
85 }
86 #endif
87 
88 /**
89  * \ingroup core
90  * Documentation goes here
91  *
92  * Here's some comment mentioning another class QgsAutoAwesomemater::makeAwesome.
93  * \note some other note
94  * \since QGIS 3.0
95  */
96 class CORE_EXPORT QgsSipifyHeader : public QtClass<QVariant>, private Ui::QgsBaseClass
97 {
98 
99 #ifdef SIP_RUN
100     SIP_CONVERT_TO_SUBCLASS_CODE
101     if ( sipCpp->headerType() == QgsSipifyHeader::Special )
102       sipType = sipType_QgsSpecialSipifyHeader;
103     else
104       sipType = sipType_QgsStandardSipifyHeader;
105     SIP_END
106 #endif
107 
108   public:
109     //! This is an enum
110     enum MyEnum
111     {
112       Success = 0, //!< Edit operation was successful
113       NoSuccess = 1, //!< Edit operation resulted in an empty geometry
114       ImaginarySuccess = 1 << 3, //!< Edit operation resulted in an imaginary geometry
115       RecursiveSuccess = 1 << 4, //!< Edit operation resulted in an n-dimensional wormhole
116       SuccessCombination = Success | ImaginarySuccess, //!< Holy Graal
117       PythonName SIP_PYNAME( DifferentName ), //!< Different python name
118       MonkeyName SIP_MONKEYPATCH_COMPAT_NAME( MonkeyPatchName ), //!< Monkey patched compatibility name
119     };
120     Q_DECLARE_FLAGS( Flags, MyEnum )
121 
122     enum OneLiner { Success, NoSuccess };
123 
124     static const inline QgsSettingsEntryEnumFlag<QgsSnappingConfig::SnappingTypes> settingsDigitizingDefaultSnapType = QgsSettingsEntryEnumFlag<QgsSnappingConfig::SnappingTypes>( QStringLiteral( "/qgis/digitizing/default_snap_type" ), QgsSettings::NoSection, QgsSnappingConfig::VertexFlag );
125 
126     /**
127      * Docstring headers for structs are not supported by sip (as of 4.18) and
128      * therefore this docstring must not to be copied to the sipfile.
129      */
130     struct Data
131     {
DataData132       Data( QgsMapLayer *layer, Qstring name )
133         : mLayer( layer )
134         , mName( name )
135       {}
136 
137       QString mName;
138       int mCount = 100;
139       QgsMapLayer *mLayer = nullptr;
140       QList<QAction *> contextMenuActions = QList<QAction *>();
141     };
142 
143     static const int MONTHS = 60 * 60 * 24 * 30; // something
144 
145     //! A constructor with definition in header
QgsSipifyHeader()146     explicit QgsSipifyHeader()
147       : QtClass<QVariant>()
148       , QgsBaseClass()
149     {}
150 
151     /*
152      * A classic constructor with arguments
153      */
154     QgsSipifyHeader( QWidget *parent SIP_TRANSFERTHIS = nullptr );
155 
156     //! A constructor with no empty `()`
157     QgsSipifyHeader( bool a = true )
mMember(nullptr)158       : mMember( nullptr )
159     {}
160 
161     //! A constructor with some special character types
162     QgsSipifyHeader( QList<Point> a, const Issues &b = Issues::weDontHaveIssues(), QgsClass *b = nullptr )
mMember(nullptr)163       : mMember( nullptr )
164     {}
165 
Constructor()166     Constructor()
167       : mHasNamedNodes( false )
168     {}
169 
~Destructor()170     virtual ~Destructor() { qDeleteAll( mList ); }
171 
172     Constructor( const QString &name,
173                  bool optional = false,
174                  const QVariant &defaultValue = QVariant() )
mName(name)175       : mName( name )
176       , mOptional( optional )
177       , mDefaultValue( defaultValue )
178     {}
179 
180     //! Default constructor
181     QgsSipifyHeader() = default;
182 
183     //! Assignment operator should be removed in sip
184     QgsSipifyHeader &operator=( const QgsSipifyHeader other );
185 
186     //! Comparison operator should be kept
187     bool operator==( const QgsSipifyHeader other );
188 
189     //! A multiline method signature
190     void multilineMethod( const QgsPointXY &startPoint,
191                           QgsFeatureId featureId,
192                           QgsVectorLayer *vl,
193                           QgsSnappingResult::SnappingType snap_to ) const;
194 
195     // Adding SIP_SKIP at the end of a line will discard this line
196     bool thisShouldBeSkipped() const SIP_SKIP;
197 
198     void nonAnnotatedMethodFollowingSkip();
199 
200     bool myMultiLineSkipped( const QList<int, QString> &list1,
201                              const QList<int, QString> &list2,
202                              const QList<int, QString> &list3 ) SIP_SKIP;
203 
204     //! Factory annotation
205     virtual QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
206 
createAnother()207     SomeObject *createAnother() SIP_FACTORY { return something; }
208 
createAnother2()209     SomeObject *createAnother2() override SIP_FACTORY { return something; }
210 
211     /**
212      * My long doc string
213      * is not very interesting!
214      */
215     void LongDocStringMethod();
216 
217     /**
218      * \brief some brief
219      * My long doc \a string
220      * is not very interesting!
221      * Here's some comment mentioning another class QgsAutoAwesomemater::makeLessAwesome.
222      */
223     void LongDocStringMethodWithBrief();
224 
225     /**
226      * I return a pointer. If something bad happens, I return NULLPTR.
227     * \returns pointer to something cool
228      */
229     MyPointer *pointerReturnValue();
230 
231     bool isOKwithErrMesg( QString &ErrMsg SIP_OUT );
232 
233     void InOutParam( bool &ok = true SIP_INOUT );
234 
235     void setDiagramRenderer( QgsDiagramRenderer *r SIP_TRANSFER );
236 
237     void differentDefaultValue( bool defaultValue = true SIP_PYARGDEFAULT( false ), QWidget *parent = nullptr, QString msg = QString() SIP_PYARGDEFAULT( "hello" ) );
238 
239     void differentType( QList<QgsFeatureId> SIP_PYALTERNATIVETYPE( QList<qint64> ) & list );
240 
241     //! complex default value and type (i.e. containing commas) should be given as a string with single quotes
242     void complexDefaultValueAndType( QList<QPair<QgsFeatureId SIP_PYALTERNATIVETYPE( qint64 ), QMap<int, QString>>> list = QList<QPair<QgsFeatureId, QMap<int, QString>>>() SIP_PYARGDEFAULT( 'QList<QPair<qint64, QMap<int, QString>>>()' ) );
243 
244     inline int inlineKeyWordShouldNotAppear();
245 
246     QString labelForRange( double lower, double upper ) const SIP_PYNAME( labelForLowerUpper );
247 
248     void setComposition( QgsComposition *c SIP_KEEPREFERENCE );
249 
250     void removeProxyFactory( QNetworkProxyFactory *factory SIP_TRANSFERBACK );
251 
252     bool removeFunctionBody( const QList<int, QString> &list, QgsVectorLayer *vl, Some::Thing _part = -1 /*default =-1*/ ) { doSomething; return true; }   // some comments
253 
skippedMethodWithBody()254     static inline QgsMapLayer *skippedMethodWithBody() SIP_SKIP
255     {
256       OhNoYouShouldnotHaveReadThis();
257       if ( ThisIsTrue() )
258       {
259         return false;
260       }
261     }
262 
263     void multilineBodyAndDefinition( const QList<int,
264                                      QString> &list,
265                                      QgsVectorLayer *vl,
266                                      Some::Thing _part = -1 /*default =-1*/ )
267     {
268       doSomething;
269       return true;
270     }
271 
272     //! Removing function body with namespaced return value
buildPyramidsFlag()273     QgsRaster::RasterBuildPyramids buildPyramidsFlag() const { return mBuildPyramidsFlag; }
274 
275     //! Removing function body with virtual const reference
metadata()276     virtual const QgsLayerMetadata &metadata() const { return mMetadata; }
277 
278     //! Mulitline body
myMultiLineBody()279     bool myMultiLineBody()
280     {
281       if ( isTrue() )
282       {
283         return false;
284       }
285       else
286       {
287         return true;
288       }
289     }
290 
291     bool deletedFunction() = delete; // some comments
292 
overriddenProperty()293     virtual int overriddenProperty() override { return 42; } // if in doubt, comment it out
294 
295     int overrideWithoutVirtual() override;
296 
297     void overrideWithoutVirtualMultLine( const QList<int, QString> &list1,
298                                          const QList<int, QString> &list2 ) override;
299 
300     QString returnTypeString() const;
301 
302     double returnTypeDouble() const;
303 
304     QList< QgsAnnotation * > returnTypeList();
305 
306     QVector< QgsAnnotation > returnTypeVector();
307 
308     QStringList returnTypeStringList();
309 
310     QSet<QgsActionScope> returnTypeSet();
311 
312     This<Member> shouldBeIncluded;
313 
314     Q_INVOKABLE static QString invokableMethod();
315 
316     bool initializedMember{ false };
317 
318     struct CORE_EXPORT PublicStruct
319     {
320       explicit PublicStruct( int _part = -1, int _ring = -1, int _vertex = -1, VertexType _type = SegmentVertex )
partPublicStruct321         : part( _part )
322         , ring( _ring )
323         , vertex( _vertex )
324         , type( _type )
325       {}
326 
isValidPublicStruct327       bool isValid( const QgsAbstractGeometry *geom ) const
328       {
329         return ( part >= 0 && part < geom->partCount() ) &&
330                ( ring < geom->ringCount( part ) ) &&
331                ( vertex < 0 || vertex < geom->vertexCount( part, ring ) );
332       }
333 
334       int part;
335       int ring;
336       int vertex;
337       VertexType type;
338     }
339 
340     void combinedAnnotations() SIP_FACTORY SIP_PYNAME( otherName );
341     void multiAnnotationArg( SomeClass **object SIP_OUT SIP_TRANSFERBACK, int &another SIP_OUT );
342 
343     //! remove argument
344     void simple( bool test SIP_PYARGREMOVE );
345     void method( bool myArg SIP_PYARGREMOVE = test );
346     void test( QgsMapLayer *vl SIP_PYARGREMOVE = nullptr );
347     void avoidIntersections( const QList<QgsVectorLayer *> &avoidIntersectionsLayers,
348                              const QHash<QgsVectorLayer *, QSet<QgsFeatureId> > &ignoreFeatures SIP_PYARGREMOVE = ( QHash<QgsVectorLayer *, QSet<QgsFeatureId> >() ) );
349     void position( bool single_remove SIP_PYARGREMOVE );
350     void position( bool first_remove SIP_PYARGREMOVE, bool keep );
351     void position( bool keep, bool middle_remove SIP_PYARGREMOVE, bool keep );
352     void position( bool keep, bool last_remove SIP_PYARGREMOVE );
353 
354     static void SIP_PYALTERNATIVETYPE( SIP_PYLIST ) changeReturnType( QVector<int> *resultTree = 0, QVector<double> &resultCost = 0 );
355 
356     //! Some comment
357     Whatever &operator[]( int i ) SIP_FACTORY;
358 #ifdef SIP_RUN
359     % MethodCode
360     ....
361     % End
362 #endif
363 
364 #if 0
365 #if Whatever
366     void X();
367 #else
368     void Y();
369 #endif
370 #else
371     void ZshouldBeShown();
372 #endif
373 
374     void methodCodeWithMultiLineDef();
375 #ifdef SIP_RUN
376     % MethodCode
377     if ( QgsWkbTypes::flatType( a0 ) != QgsWkbTypes::Point )
378     {
379       multiLineDef( PyExc_ValueError,
380                     QString( "%1 is not nice" ).arg( QgsWkbTypes::displayString( a0 ) ).toUtf8().constData() );
381     }
382     else
383     {
384       sipCpp = new sipQgsPoint( a0, a1, a2, a3, a4 );
385     }
386     % End
387 #endif
388 
389   protected:
390     bool thisShouldBeListed();
391 
392     Whatever skipMember;
393     Whatever::Something *alsoSkipMember = nullptr;
394     mutable Whatever alsoSkipThis;
395     Some<Other> memberToSkip;
396     QList<QgsMapLayer *> list2skip;
397     QMap<QString, Qt::CheckState> map2skip;
398     FilterType mFilter = FilterNone;
399     QgsFeatureId mFilterFid = -1;
400     QgsFeatureIds mFilterFids;
401     std::unique_ptr< QgsExpression > mFilterExpression;
402     long mLimit = -1;
403     InvalidGeometryCheck mInvalidGeometryFilter = GeometryNoCheck;
404     std::function< void( const QgsFeature & ) > mInvalidGeometryCallback;
405     static QHash<QString, Help> sFunctionHelpTexts;
406     friend class QgsOgcUtils;
407     template<typename> friend class QgsAbstractFeatureIteratorFromSource;
408     const QgsAbstractGeometry *mGeometry = 0;
409     mutable unsigned char *mP;
410 
411   private:
412     void privateMethodAreNotShown();
413 #ifdef SIP_RUN
414     void privateMethodSIPRUNareShown();
415 #endif
416   public:
417     void FallBackToPublic();
418 
419   private:
420     void PrivateAgain();
421     /* Single line block comments shouldn't break the parser */
422 
423     void ShowThisPrivateOne() SIP_FORCE;
424 
425     struct ProcessFeatureWrapper
426     {
427       QgsGeometrySnapper *instance = nullptr;
428       double snapTolerance;
429       SnapMode mode;
ProcessFeatureWrapperProcessFeatureWrapper430       explicit ProcessFeatureWrapper( QgsGeometrySnapper *_instance, double snapTolerance, SnapMode mode )
431         : instance( _instance )
432         , snapTolerance( snapTolerance )
433         , mode( mode )
434       {}
operatorProcessFeatureWrapper435       void operator()( QgsFeature &feature ) { return instance->processFeature( feature, snapTolerance, mode ); }
436     };
437 
438     enum PointFlag { SnappedToRefNode, SnappedToRefSegment, Unsnapped };
439 };
440 
441 /**
442  * \class ClassWithPrivateInheritanceOnly
443  * \ingroup core
444  * Documentation goes here
445  */
446 class CORE_EXPORT ClassWithPrivateInheritanceOnly : private QgsBaseClass SIP_ABSTRACT
447 {
448   public:
449     //! A constructor with definition in header on several lines
ClassWithPrivateInheritanceOnly()450     explicit ClassWithPrivateInheritanceOnly()
451       : QtClass<QVariant>()
452       , QgsBaseClass()
453     {
454       doWhatYouLike();
455       haveFun();
456     }
457 };
458 
459 /**
460  * \class AbstractClass
461  * \ingroup core
462  * Documentation goes here
463  */
464 
465 class CORE_EXPORT AbstractClass SIP_ABSTRACT
466 {
467   public:
468     //! A constructor
AbstractClass()469     explicit AbstractClass()
470     {
471     }
472 
473   private:
474 
475     /**
476      * This method should be overridden by subclasses but not exposed to the public
477      * or protected API.
478      */
479     virtual QString reason() = 0;
480 };
481 
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsSipifyHeader::Flags)482 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsSipifyHeader::Flags )
483 
484 class CORE_EXPORT TemplateInheritance1 : public QgsTemplate<Something>
485 {
486 }
487 class CORE_EXPORT TemplateInheritance2 : public QList<Something>, private SomethingElse
488 {
489 }
490 class CORE_EXPORT TemplateInheritance3 : public QgsTemplate<Something>, public SomethingElse
491 {
492 }
493 class CORE_EXPORT TemplateInheritance4 : public SomethingElse1, public QList<Something>, public SomethingElse2
494 {
495 }
496 class CORE_EXPORT TemplateInheritance5 : public SomethingElse, public QList<Something>
497 {
498 }
499 
500 
501 #endif
502