Skip to content

Commit 9af8498

Browse files
committedApr 6, 2014
Re-enable watermark items
1 parent cd01a87 commit 9af8498

File tree

4 files changed

+161
-3
lines changed

4 files changed

+161
-3
lines changed
 

‎src/mapserver/qgsserverprojectparser.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,36 @@ QString QgsServerProjectParser::layerId( const QDomElement& layerElem ) const
299299
return idElem.text();
300300
}
301301

302+
QgsRectangle QgsServerProjectParser::projectExtent() const
303+
{
304+
QgsRectangle extent;
305+
if ( !mXMLDoc )
306+
{
307+
return extent;
308+
}
309+
310+
QDomElement qgisElem = mXMLDoc->documentElement();
311+
QDomElement mapCanvasElem = qgisElem.firstChildElement( "mapcanvas" );
312+
if ( mapCanvasElem.isNull() )
313+
{
314+
return extent;
315+
}
316+
317+
QDomElement extentElem = mapCanvasElem.firstChildElement( "extent" );
318+
bool xminOk, xmaxOk, yminOk, ymaxOk;
319+
double xMin = extentElem.firstChildElement( "xmin" ).text().toDouble( &xminOk );
320+
double xMax = extentElem.firstChildElement( "xmax" ).text().toDouble( &xmaxOk );
321+
double yMin = extentElem.firstChildElement( "ymin" ).text().toDouble( &yminOk );
322+
double yMax = extentElem.firstChildElement( "ymax" ).text().toDouble( &ymaxOk );
323+
324+
if ( xminOk && xmaxOk && yminOk && ymaxOk )
325+
{
326+
extent = QgsRectangle( xMin, yMin, xMax, yMax );
327+
}
328+
329+
return extent;
330+
}
331+
302332
QString QgsServerProjectParser::layerName( const QDomElement& layerElem ) const
303333
{
304334
if ( layerElem.isNull() )

‎src/mapserver/qgsserverprojectparser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ class QgsServerProjectParser
115115
@return id or a null string in case of error*/
116116
QString layerId( const QDomElement& layerElem ) const;
117117

118+
QgsRectangle projectExtent() const;
119+
118120
private:
119121

120122
/**Content of project file*/

‎src/mapserver/qgswmsprojectparser.cpp

Lines changed: 114 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,14 @@ QgsWMSProjectParser::QgsWMSProjectParser( QDomDocument* xmlDoc, const QString& f
4141
{
4242
mLegendLayerFont.fromString( mProjectParser.firstComposerLegendElement().attribute( "layerFont" ) );
4343
mLegendItemFont.fromString( mProjectParser.firstComposerLegendElement().attribute( "itemFont" ) );
44+
createTextAnnotationItems();
45+
createSvgAnnotationItems();
4446
}
4547

4648
QgsWMSProjectParser::~QgsWMSProjectParser()
4749
{
50+
cleanupTextAnnotationItems();
51+
cleanupSvgAnnotationItems();
4852
}
4953

5054
void QgsWMSProjectParser::layersAndStylesCapabilities( QDomElement& parentElement, QDomDocument& doc, const QString& version, bool fullProjectSettings ) const
@@ -1555,13 +1559,12 @@ bool QgsWMSProjectParser::featureInfoFormatSIA2045() const
15551559

15561560
void QgsWMSProjectParser::drawOverlays( QPainter* p, int dpi, int width, int height ) const
15571561
{
1558-
#if 0
15591562
Q_UNUSED( width );
15601563
Q_UNUSED( height );
15611564

15621565
//consider DPI
15631566
double scaleFactor = dpi / 88.0; //assume 88 as standard dpi
1564-
QgsRectangle prjExtent = projectExtent();
1567+
QgsRectangle prjExtent = mProjectParser.projectExtent();
15651568

15661569
//text annotations
15671570
QList< QPair< QTextDocument*, QDomElement > >::const_iterator textIt = mTextAnnotationItems.constBegin();
@@ -1633,7 +1636,6 @@ void QgsWMSProjectParser::drawOverlays( QPainter* p, int dpi, int width, int hei
16331636
renderHeight ) );
16341637
}
16351638
}
1636-
#endif //0
16371639
}
16381640

16391641
QDomElement QgsWMSProjectParser::composerByName( const QString& composerName ) const
@@ -1657,3 +1659,112 @@ QDomElement QgsWMSProjectParser::composerByName( const QString& composerName ) c
16571659

16581660
return composerElem;
16591661
}
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+
}

‎src/mapserver/qgswmsprojectparser.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
#include "qgswmsconfigparser.h"
2222
#include "qgsserverprojectparser.h"
2323

24+
class QTextDocument;
25+
class QSvgRenderer;
26+
2427
class QgsWMSProjectParser: public QgsWMSConfigParser
2528
{
2629
public:
@@ -104,6 +107,11 @@ class QgsWMSProjectParser: public QgsWMSConfigParser
104107

105108
mutable QFont mLegendItemFont;
106109

110+
/**Watermark text items*/
111+
QList< QPair< QTextDocument*, QDomElement > > mTextAnnotationItems;
112+
/**Watermark items (content cached in QgsSVGCache)*/
113+
QList< QPair< QSvgRenderer*, QDomElement > > mSvgAnnotationElems;
114+
107115
/**Returns an ID-list of layers which are not queryable (comes from <properties> -> <Identify> -> <disabledLayers in the project file*/
108116
virtual QStringList identifyDisabledLayers() const;
109117

@@ -126,6 +134,13 @@ class QgsWMSProjectParser: public QgsWMSConfigParser
126134
const QString& strHref, QgsRectangle& combinedBBox, QString strGroup ) const;
127135

128136
QDomElement composerByName( const QString& composerName ) const;
137+
138+
static bool annotationPosition( const QDomElement& elem, double scaleFactor, double& xPos, double& yPos );
139+
static void drawAnnotationRectangle( QPainter* p, const QDomElement& elem, double scaleFactor, double xPos, double yPos, int itemWidth, int itemHeight );
140+
void createTextAnnotationItems();
141+
void createSvgAnnotationItems();
142+
void cleanupSvgAnnotationItems();
143+
void cleanupTextAnnotationItems();
129144
};
130145

131146
#endif // QGSWMSPROJECTPARSER_H

0 commit comments

Comments
 (0)
Please sign in to comment.