@@ -41,10 +41,14 @@ QgsWMSProjectParser::QgsWMSProjectParser( QDomDocument* xmlDoc, const QString& f
41
41
{
42
42
mLegendLayerFont .fromString ( mProjectParser .firstComposerLegendElement ().attribute ( " layerFont" ) );
43
43
mLegendItemFont .fromString ( mProjectParser .firstComposerLegendElement ().attribute ( " itemFont" ) );
44
+ createTextAnnotationItems ();
45
+ createSvgAnnotationItems ();
44
46
}
45
47
46
48
QgsWMSProjectParser::~QgsWMSProjectParser ()
47
49
{
50
+ cleanupTextAnnotationItems ();
51
+ cleanupSvgAnnotationItems ();
48
52
}
49
53
50
54
void QgsWMSProjectParser::layersAndStylesCapabilities ( QDomElement& parentElement, QDomDocument& doc, const QString& version, bool fullProjectSettings ) const
@@ -1555,13 +1559,12 @@ bool QgsWMSProjectParser::featureInfoFormatSIA2045() const
1555
1559
1556
1560
void QgsWMSProjectParser::drawOverlays ( QPainter* p, int dpi, int width, int height ) const
1557
1561
{
1558
- #if 0
1559
1562
Q_UNUSED ( width );
1560
1563
Q_UNUSED ( height );
1561
1564
1562
1565
// consider DPI
1563
1566
double scaleFactor = dpi / 88.0 ; // assume 88 as standard dpi
1564
- QgsRectangle prjExtent = projectExtent();
1567
+ QgsRectangle prjExtent = mProjectParser . projectExtent ();
1565
1568
1566
1569
// text annotations
1567
1570
QList< QPair< QTextDocument*, QDomElement > >::const_iterator textIt = mTextAnnotationItems .constBegin ();
@@ -1633,7 +1636,6 @@ void QgsWMSProjectParser::drawOverlays( QPainter* p, int dpi, int width, int hei
1633
1636
renderHeight ) );
1634
1637
}
1635
1638
}
1636
- #endif // 0
1637
1639
}
1638
1640
1639
1641
QDomElement QgsWMSProjectParser::composerByName ( const QString& composerName ) const
@@ -1657,3 +1659,112 @@ QDomElement QgsWMSProjectParser::composerByName( const QString& composerName ) c
1657
1659
1658
1660
return composerElem;
1659
1661
}
1662
+
1663
+ bool QgsWMSProjectParser::annotationPosition ( const QDomElement& elem, double scaleFactor, double & xPos, double & yPos )
1664
+ {
1665
+ Q_UNUSED ( scaleFactor );
1666
+
1667
+ xPos = elem.attribute ( " canvasPosX" ).toDouble () / scaleFactor;
1668
+ yPos = elem.attribute ( " canvasPosY" ).toDouble () / scaleFactor;
1669
+ return true ;
1670
+ }
1671
+
1672
+ void QgsWMSProjectParser::drawAnnotationRectangle ( QPainter* p, const QDomElement& elem, double scaleFactor, double xPos, double yPos, int itemWidth, int itemHeight )
1673
+ {
1674
+ Q_UNUSED ( scaleFactor );
1675
+ if ( !p )
1676
+ {
1677
+ return ;
1678
+ }
1679
+
1680
+ QColor backgroundColor ( elem.attribute ( " frameBackgroundColor" , " #000000" ) );
1681
+ backgroundColor.setAlpha ( elem.attribute ( " frameBackgroundColorAlpha" , " 255" ).toInt () );
1682
+ p->setBrush ( QBrush ( backgroundColor ) );
1683
+ QColor frameColor ( elem.attribute ( " frameColor" , " #000000" ) );
1684
+ frameColor.setAlpha ( elem.attribute ( " frameColorAlpha" , " 255" ).toInt () );
1685
+ QPen framePen ( frameColor );
1686
+ framePen.setWidth ( elem.attribute ( " frameBorderWidth" , " 1" ).toInt () );
1687
+ p->setPen ( framePen );
1688
+
1689
+ p->drawRect ( QRectF ( xPos, yPos, itemWidth, itemHeight ) );
1690
+ }
1691
+
1692
+ void QgsWMSProjectParser::createTextAnnotationItems ()
1693
+ {
1694
+ cleanupTextAnnotationItems ();
1695
+
1696
+ const QDomDocument* xmlDoc = mProjectParser .xmlDocument ();
1697
+ if ( !xmlDoc )
1698
+ {
1699
+ return ;
1700
+ }
1701
+
1702
+ // text annotations
1703
+ QDomElement qgisElem = xmlDoc->documentElement ();
1704
+ QDomNodeList textAnnotationList = qgisElem.elementsByTagName ( " TextAnnotationItem" );
1705
+ QDomElement textAnnotationElem;
1706
+ QDomElement annotationElem;
1707
+ for ( int i = 0 ; i < textAnnotationList.size (); ++i )
1708
+ {
1709
+ textAnnotationElem = textAnnotationList.at ( i ).toElement ();
1710
+ annotationElem = textAnnotationElem.firstChildElement ( " AnnotationItem" );
1711
+ if ( !annotationElem.isNull () && annotationElem.attribute ( " mapPositionFixed" ) != " 1" )
1712
+ {
1713
+ QTextDocument* textDoc = new QTextDocument ();
1714
+ textDoc->setHtml ( textAnnotationElem.attribute ( " document" ) );
1715
+ mTextAnnotationItems .push_back ( qMakePair ( textDoc, annotationElem ) );
1716
+ }
1717
+ }
1718
+ }
1719
+
1720
+ void QgsWMSProjectParser::createSvgAnnotationItems ()
1721
+ {
1722
+ mSvgAnnotationElems .clear ();
1723
+ const QDomDocument* xmlDoc = mProjectParser .xmlDocument ();
1724
+ if ( !xmlDoc )
1725
+ {
1726
+ return ;
1727
+ }
1728
+
1729
+ QDomElement qgisElem = xmlDoc->documentElement ();
1730
+ QDomNodeList svgAnnotationList = qgisElem.elementsByTagName ( " SVGAnnotationItem" );
1731
+ QDomElement svgAnnotationElem;
1732
+ QDomElement annotationElem;
1733
+ for ( int i = 0 ; i < svgAnnotationList.size (); ++i )
1734
+ {
1735
+ svgAnnotationElem = svgAnnotationList.at ( i ).toElement ();
1736
+ annotationElem = svgAnnotationElem.firstChildElement ( " AnnotationItem" );
1737
+ if ( !annotationElem.isNull () && annotationElem.attribute ( " mapPositionFixed" ) != " 1" )
1738
+ {
1739
+ QSvgRenderer* svg = new QSvgRenderer ();
1740
+ if ( svg->load ( mProjectParser .convertToAbsolutePath ( svgAnnotationElem.attribute ( " file" ) ) ) )
1741
+ {
1742
+ mSvgAnnotationElems .push_back ( qMakePair ( svg, annotationElem ) );
1743
+ }
1744
+ else
1745
+ {
1746
+ delete svg;
1747
+ }
1748
+ }
1749
+ }
1750
+ }
1751
+
1752
+ void QgsWMSProjectParser::cleanupSvgAnnotationItems ()
1753
+ {
1754
+ QList< QPair< QSvgRenderer*, QDomElement > >::const_iterator it = mSvgAnnotationElems .constBegin ();
1755
+ for ( ; it != mSvgAnnotationElems .constEnd (); ++it )
1756
+ {
1757
+ delete it->first ;
1758
+ }
1759
+ mSvgAnnotationElems .clear ();
1760
+ }
1761
+
1762
+ void QgsWMSProjectParser::cleanupTextAnnotationItems ()
1763
+ {
1764
+ QList< QPair< QTextDocument*, QDomElement > >::const_iterator it = mTextAnnotationItems .constBegin ();
1765
+ for ( ; it != mTextAnnotationItems .constEnd (); ++it )
1766
+ {
1767
+ delete it->first ;
1768
+ }
1769
+ mTextAnnotationItems .clear ();
1770
+ }
0 commit comments