Skip to content

Commit deb1246

Browse files
committedMar 31, 2023
Add repr for layer tree legend nodes
1 parent 1ce4453 commit deb1246

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed
 

‎python/core/auto_generated/layertree/qgslayertreemodellegendnode.sip.in

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ Draws label on the right side of the item
233233
:return: Size of the label (may span multiple lines)
234234
%End
235235

236+
SIP_PYOBJECT __repr__();
237+
%MethodCode
238+
QString str = QStringLiteral( "<QgsLayerTreeModelLegendNode: \"%1\">" ).arg( sipCpp->data( Qt::DisplayRole ).toString() );
239+
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
240+
%End
241+
236242
public slots:
237243

238244
void checkAllItems();
@@ -488,6 +494,14 @@ Evaluates and returns the text label of the current node
488494
.. versionadded:: 3.10
489495
%End
490496

497+
SIP_PYOBJECT __repr__();
498+
%MethodCode
499+
QString str = QStringLiteral( "<QgsSymbolLegendNode: %1 \"%2\"" ).arg(
500+
sipCpp->data( QgsLayerTreeModelLegendNode::RuleKeyRole ).toString(),
501+
sipCpp->data( Qt::DisplayRole ).toString() );
502+
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
503+
%End
504+
491505
};
492506

493507

@@ -518,6 +532,12 @@ Constructor for QgsSimpleLegendNode.
518532
virtual QVariant data( int role ) const;
519533

520534

535+
SIP_PYOBJECT __repr__();
536+
%MethodCode
537+
QString str = QStringLiteral( "<QgsSimpleLegendNode: \"%1\">" ).arg( sipCpp->data( Qt::DisplayRole ).toString() );
538+
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
539+
%End
540+
521541
};
522542

523543

@@ -552,6 +572,12 @@ Constructor for QgsImageLegendNode.
552572
virtual QJsonObject exportSymbolToJson( const QgsLegendSettings &settings, const QgsRenderContext &context ) const;
553573

554574

575+
SIP_PYOBJECT __repr__();
576+
%MethodCode
577+
QString str = QStringLiteral( "<QgsImageLegendNode: \"%1\">" ).arg( sipCpp->data( Qt::DisplayRole ).toString() );
578+
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
579+
%End
580+
555581
};
556582

557583
class QgsRasterSymbolLegendNode : QgsLayerTreeModelLegendNode
@@ -604,6 +630,12 @@ Returns whether the item is user-checkable - whether renderer supports enabling/
604630
.. versionadded:: 3.18
605631
%End
606632

633+
SIP_PYOBJECT __repr__();
634+
%MethodCode
635+
QString str = QStringLiteral( "<QgsRasterSymbolLegendNode: \"%1\">" ).arg( sipCpp->data( Qt::DisplayRole ).toString() );
636+
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
637+
%End
638+
607639
};
608640

609641

@@ -642,6 +674,12 @@ Constructor for QgsWmsLegendNode.
642674
virtual void invalidateMapBasedData();
643675

644676

677+
SIP_PYOBJECT __repr__();
678+
%MethodCode
679+
QString str = QStringLiteral( "<QgsWmsLegendNode: \"%1\">" ).arg( sipCpp->data( Qt::DisplayRole ).toString() );
680+
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
681+
%End
682+
645683
};
646684

647685

@@ -669,6 +707,12 @@ Construct the node using :py:class:`QgsDataDefinedSizeLegend` as definition of t
669707
virtual ItemMetrics draw( const QgsLegendSettings &settings, ItemContext *ctx );
670708

671709

710+
SIP_PYOBJECT __repr__();
711+
%MethodCode
712+
QString str = QStringLiteral( "<QgsDataDefinedSizeLegendNode: \"%1\">" ).arg( sipCpp->data( Qt::DisplayRole ).toString() );
713+
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
714+
%End
715+
672716
};
673717

674718
class QgsVectorLabelLegendNode : QgsLayerTreeModelLegendNode
@@ -727,6 +771,12 @@ exportSymbolToJson
727771
:return: the json object
728772
%End
729773

774+
SIP_PYOBJECT __repr__();
775+
%MethodCode
776+
QString str = QStringLiteral( "<QgsVectorLabelLegendNode: \"%1\">" ).arg( sipCpp->data( Qt::DisplayRole ).toString() );
777+
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
778+
%End
779+
730780
};
731781

732782

‎src/core/layertree/qgslayertreemodellegendnode.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,14 @@ class CORE_EXPORT QgsLayerTreeModelLegendNode : public QObject
301301
*/
302302
virtual QSizeF drawSymbolText( const QgsLegendSettings &settings, ItemContext *ctx, QSizeF symbolSize ) const;
303303

304+
#ifdef SIP_RUN
305+
SIP_PYOBJECT __repr__();
306+
% MethodCode
307+
QString str = QStringLiteral( "<QgsLayerTreeModelLegendNode: \"%1\">" ).arg( sipCpp->data( Qt::DisplayRole ).toString() );
308+
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
309+
% End
310+
#endif
311+
304312
public slots:
305313

306314
/**
@@ -526,6 +534,16 @@ class CORE_EXPORT QgsSymbolLegendNode : public QgsLayerTreeModelLegendNode
526534
*/
527535
QString evaluateLabel( const QgsExpressionContext &context = QgsExpressionContext(), const QString &label = QString() );
528536

537+
#ifdef SIP_RUN
538+
SIP_PYOBJECT __repr__();
539+
% MethodCode
540+
QString str = QStringLiteral( "<QgsSymbolLegendNode: %1 \"%2\"" ).arg(
541+
sipCpp->data( QgsLayerTreeModelLegendNode::RuleKeyRole ).toString(),
542+
sipCpp->data( Qt::DisplayRole ).toString() );
543+
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
544+
% End
545+
#endif
546+
529547
private:
530548
void updateLabel();
531549

@@ -578,6 +596,14 @@ class CORE_EXPORT QgsSimpleLegendNode : public QgsLayerTreeModelLegendNode
578596

579597
QVariant data( int role ) const override;
580598

599+
#ifdef SIP_RUN
600+
SIP_PYOBJECT __repr__();
601+
% MethodCode
602+
QString str = QStringLiteral( "<QgsSimpleLegendNode: \"%1\">" ).arg( sipCpp->data( Qt::DisplayRole ).toString() );
603+
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
604+
% End
605+
#endif
606+
581607
private:
582608
QString mLabel;
583609
QString mId;
@@ -612,6 +638,14 @@ class CORE_EXPORT QgsImageLegendNode : public QgsLayerTreeModelLegendNode
612638

613639
QJsonObject exportSymbolToJson( const QgsLegendSettings &settings, const QgsRenderContext &context ) const override;
614640

641+
#ifdef SIP_RUN
642+
SIP_PYOBJECT __repr__();
643+
% MethodCode
644+
QString str = QStringLiteral( "<QgsImageLegendNode: \"%1\">" ).arg( sipCpp->data( Qt::DisplayRole ).toString() );
645+
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
646+
% End
647+
#endif
648+
615649
private:
616650
QImage mImage;
617651
};
@@ -659,6 +693,14 @@ class CORE_EXPORT QgsRasterSymbolLegendNode : public QgsLayerTreeModelLegendNode
659693
*/
660694
bool isCheckable() const { return mCheckable; }
661695

696+
#ifdef SIP_RUN
697+
SIP_PYOBJECT __repr__();
698+
% MethodCode
699+
QString str = QStringLiteral( "<QgsRasterSymbolLegendNode: \"%1\">" ).arg( sipCpp->data( Qt::DisplayRole ).toString() );
700+
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
701+
% End
702+
#endif
703+
662704
private:
663705
QColor mColor;
664706
QString mLabel;
@@ -697,6 +739,14 @@ class CORE_EXPORT QgsWmsLegendNode : public QgsLayerTreeModelLegendNode
697739

698740
void invalidateMapBasedData() override;
699741

742+
#ifdef SIP_RUN
743+
SIP_PYOBJECT __repr__();
744+
% MethodCode
745+
QString str = QStringLiteral( "<QgsWmsLegendNode: \"%1\">" ).arg( sipCpp->data( Qt::DisplayRole ).toString() );
746+
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
747+
% End
748+
#endif
749+
700750
private slots:
701751

702752
void getLegendGraphicFinished( const QImage & );
@@ -736,6 +786,14 @@ class CORE_EXPORT QgsDataDefinedSizeLegendNode : public QgsLayerTreeModelLegendN
736786

737787
ItemMetrics draw( const QgsLegendSettings &settings, ItemContext *ctx ) override;
738788

789+
#ifdef SIP_RUN
790+
SIP_PYOBJECT __repr__();
791+
% MethodCode
792+
QString str = QStringLiteral( "<QgsDataDefinedSizeLegendNode: \"%1\">" ).arg( sipCpp->data( Qt::DisplayRole ).toString() );
793+
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
794+
% End
795+
#endif
796+
739797
private:
740798
void cacheImage() const;
741799
QgsDataDefinedSizeLegend *mSettings = nullptr;
@@ -785,6 +843,14 @@ class CORE_EXPORT QgsVectorLabelLegendNode : public QgsLayerTreeModelLegendNode
785843
*/
786844
QJsonObject exportSymbolToJson( const QgsLegendSettings &settings, const QgsRenderContext &context ) const override;
787845

846+
#ifdef SIP_RUN
847+
SIP_PYOBJECT __repr__();
848+
% MethodCode
849+
QString str = QStringLiteral( "<QgsVectorLabelLegendNode: \"%1\">" ).arg( sipCpp->data( Qt::DisplayRole ).toString() );
850+
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
851+
% End
852+
#endif
853+
788854
private:
789855
QgsPalLayerSettings mLabelSettings;
790856
QSizeF drawSymbol( const QgsLegendSettings &settings, const QgsRenderContext &renderContext, double xOffset = 0.0, double yOffset = 0.0 ) const;

0 commit comments

Comments
 (0)
Please sign in to comment.