Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
sip: convert to subclass + __repr__ for tree elements
  • Loading branch information
3nids committed Jan 16, 2023
1 parent d695ca3 commit 25259b4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
16 changes: 16 additions & 0 deletions python/core/auto_generated/settings/qgssettingstreeelement.sip.in
Expand Up @@ -30,6 +30,14 @@ to automatically register a settings entry on its creation when a parent is prov

%TypeHeaderCode
#include "qgssettingstreeelement.h"
%End
%ConvertToSubClassCode
if ( dynamic_cast< QgsSettingsTreeNamedListElement * >( sipCpp ) )
sipType = sipType_QgsSettingsTreeNamedListElement;
else if ( dynamic_cast< QgsSettingsTreeElement * >( sipCpp ) )
sipType = sipType_QgsSettingsTreeElement;
else
sipType = NULL;
%End
public:
static const QMetaObject staticMetaObject;
Expand Down Expand Up @@ -137,6 +145,14 @@ Returns the complete key of the element (including its parents)
Returns the number of named elements in the complete key
%End

SIP_PYOBJECT __repr__();
%MethodCode
const QMetaEnum metaEnum = QMetaEnum::fromType<QgsSettingsTreeElement::Type>();

QString str = QStringLiteral( "<QgsSettingsTreeElement (%1): %2>" ).arg( metaEnum.valueToKey( static_cast<int>( sipCpp->type() ) ), sipCpp->key() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

protected:
void registerChildElement( QgsSettingsTreeElement *element ) throw( QgsSettingsException );
%Docstring
Expand Down
22 changes: 22 additions & 0 deletions src/core/settings/qgssettingstreeelement.h
Expand Up @@ -44,6 +44,18 @@ class QgsSettingsEntryString;
*/
class CORE_EXPORT QgsSettingsTreeElement
{

#ifdef SIP_RUN
SIP_CONVERT_TO_SUBCLASS_CODE
if ( dynamic_cast< QgsSettingsTreeNamedListElement * >( sipCpp ) )
sipType = sipType_QgsSettingsTreeNamedListElement;
else if ( dynamic_cast< QgsSettingsTreeElement * >( sipCpp ) )
sipType = sipType_QgsSettingsTreeElement;
else
sipType = NULL;
SIP_END
#endif

Q_GADGET

public:
Expand Down Expand Up @@ -131,6 +143,16 @@ class CORE_EXPORT QgsSettingsTreeElement
//! Returns the number of named elements in the complete key
int namedElementsCount() const {return mNamedElementsCount;}

#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
const QMetaEnum metaEnum = QMetaEnum::fromType<QgsSettingsTreeElement::Type>();

QString str = QStringLiteral( "<QgsSettingsTreeElement (%1): %2>" ).arg( metaEnum.valueToKey( static_cast<int>( sipCpp->type() ) ), sipCpp->key() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif

protected:
//! Registers a child elements
void registerChildElement( QgsSettingsTreeElement *element ) SIP_THROW( QgsSettingsException );
Expand Down

0 comments on commit 25259b4

Please sign in to comment.