@@ -68,6 +68,15 @@ void QgsDecorationLayoutExtent::projectRead()
6868 QgsSimpleLineSymbolLayer *layer = new QgsSimpleLineSymbolLayer ( QColor ( 0 , 0 , 0 , 100 ), 0 , Qt::DashLine );
6969 mSymbol ->changeSymbolLayer ( 0 , layer );
7070 }
71+
72+ QString textXml = QgsProject::instance ()->readEntry ( mNameConfig , QStringLiteral ( " /Font" ) );
73+ if ( !textXml.isEmpty () )
74+ {
75+ doc.setContent ( textXml );
76+ elem = doc.documentElement ();
77+ mTextFormat .readXml ( elem, rwContext );
78+ }
79+ mLabelExtents = QgsProject::instance ()->readBoolEntry ( mNameConfig , QStringLiteral ( " /Labels" ), true );
7180}
7281
7382void QgsDecorationLayoutExtent::saveToProject ()
@@ -85,6 +94,12 @@ void QgsDecorationLayoutExtent::saveToProject()
8594 // FIXME this works, but XML will not be valid as < is replaced by <
8695 QgsProject::instance ()->writeEntry ( mNameConfig , QStringLiteral ( " /Symbol" ), doc.toString () );
8796 }
97+
98+ QDomDocument textDoc;
99+ QDomElement textElem = mTextFormat .writeXml ( textDoc, rwContext );
100+ textDoc.appendChild ( textElem );
101+ QgsProject::instance ()->writeEntry ( mNameConfig , QStringLiteral ( " /Font" ), textDoc.toString () );
102+ QgsProject::instance ()->writeEntry ( mNameConfig , QStringLiteral ( " /Labels" ), mLabelExtents );
88103}
89104
90105void QgsDecorationLayoutExtent::run ()
@@ -116,6 +131,7 @@ void QgsDecorationLayoutExtent::render( const QgsMapSettings &mapSettings, QgsRe
116131 Q_FOREACH ( const QgsComposerMap *map, composition->composerMapItems () )
117132 {
118133 QPolygonF extent = map->visibleExtentPolygon ();
134+ QPointF labelPoint = extent.at ( 1 );
119135 QgsGeometry g = QgsGeometry::fromQPolygonF ( extent );
120136
121137 if ( map->crs () !=
@@ -128,21 +144,39 @@ void QgsDecorationLayoutExtent::render( const QgsMapSettings &mapSettings, QgsRe
128144 try
129145 {
130146 g.transform ( ct );
147+ labelPoint = ct.transform ( labelPoint.x (), labelPoint.y () ).toQPointF ();
131148 }
132149 catch ( QgsCsException & )
133150 {
134151 }
135152 }
136153
137154 g.transform ( transform );
155+ labelPoint = transform.map ( labelPoint );
138156 extent = g.asQPolygonF ();
139157 mSymbol ->renderPolygon ( extent, nullptr , nullptr , context );
158+
159+ if ( mLabelExtents )
160+ {
161+ QgsTextRenderer::drawText ( labelPoint, ( map->mapRotation () - mapSettings.rotation () ) * M_PI / 180.0 , QgsTextRenderer::AlignRight, QStringList () << tr ( " %1: %2" ).arg ( composition->name (), map->displayName () ),
162+ context, mTextFormat );
163+ }
140164 }
141165 }
142166 mSymbol ->stopRender ( context );
143167 context.painter ()->restore ();
144168}
145169
170+ bool QgsDecorationLayoutExtent::labelExtents () const
171+ {
172+ return mLabelExtents ;
173+ }
174+
175+ void QgsDecorationLayoutExtent::setLabelExtents ( bool labelExtents )
176+ {
177+ mLabelExtents = labelExtents;
178+ }
179+
146180QgsFillSymbol *QgsDecorationLayoutExtent::symbol () const
147181{
148182 return mSymbol .get ();
0 commit comments