Skip to content

Commit cca386f

Browse files
committed
[FEATURE]: Use text annotations as watermarks in QGIS server. Developed for Faunalia (http://www.faunalia.it) with funding from Regione Toscana - Settore SISTEMA INFORMATIVO TERRITORIALE ED AMBIENTALE
1 parent 234709d commit cca386f

19 files changed

+606
-2
lines changed

src/app/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ SET(QGIS_APP_SRCS
7777
qgsmaptoolselectutils.cpp
7878
qgsmaptoolsimplify.cpp
7979
qgsmaptoolsplitfeatures.cpp
80+
qgsmaptoolsvgannotation.cpp
8081
qgsmaptooltextannotation.cpp
8182
qgsmaptoolvertexedit.cpp
8283

@@ -102,6 +103,7 @@ SET(QGIS_APP_SRCS
102103
qgsshortcutsmanager.cpp
103104
qgssinglesymboldialog.cpp
104105
qgssnappingdialog.cpp
106+
qgssvgannotationdialog.cpp
105107
qgsundowidget.cpp
106108
qgstipgui.cpp
107109
qgstipfactory.cpp
@@ -247,6 +249,7 @@ SET (QGIS_APP_MOC_HDRS
247249
qgssinglesymboldialog.h
248250
qgssnappingdialog.h
249251
qgssponsors.h
252+
qgssvgannotationdialog.h
250253
qgstextannotationdialog.h
251254
qgstipgui.h
252255
qgstipfactory.h

src/app/qgisapp.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
#include "qgssinglebandgrayrenderer.h"
178178
#include "qgssnappingdialog.h"
179179
#include "qgssponsors.h"
180+
#include "qgssvgannotationitem.h"
180181
#include "qgstextannotationitem.h"
181182
#include "qgstipgui.h"
182183
#include "qgsundowidget.h"
@@ -233,6 +234,7 @@
233234
#include "qgsmaptoolselectfreehand.h"
234235
#include "qgsmaptoolselectpolygon.h"
235236
#include "qgsmaptoolselectradius.h"
237+
#include "qgsmaptoolsvgannotation.h"
236238
#include "qgsmaptoolreshape.h"
237239
#include "qgsmaptoolrotatepointsymbols.h"
238240
#include "qgsmaptoolsplitfeatures.h"
@@ -734,6 +736,7 @@ QgisApp::~QgisApp()
734736
delete mMapTools.mTextAnnotation;
735737
delete mMapTools.mFormAnnotation;
736738
delete mMapTools.mHtmlAnnotation;
739+
delete mMapTools.mSvgAnnotation;
737740
delete mMapTools.mAnnotation;
738741
delete mMapTools.mAddFeature;
739742
delete mMapTools.mMoveFeature;
@@ -938,6 +941,7 @@ void QgisApp::createActions()
938941
connect( mActionTextAnnotation, SIGNAL( triggered() ), this, SLOT( addTextAnnotation() ) );
939942
connect( mActionFormAnnotation, SIGNAL( triggered() ), this, SLOT( addFormAnnotation() ) );
940943
connect( mActionHtmlAnnotation, SIGNAL( triggered() ), this, SLOT( addHtmlAnnotation() ) );
944+
connect( mActionSvgAnnotation, SIGNAL( triggered() ), this, SLOT( addSvgAnnotation() ) );
941945
connect( mActionAnnotation, SIGNAL( triggered() ), this, SLOT( modifyAnnotation() ) );
942946
connect( mActionLabeling, SIGNAL( triggered() ), this, SLOT( labeling() ) );
943947

@@ -1402,6 +1406,7 @@ void QgisApp::createToolBars()
14021406
bt->addAction( mActionTextAnnotation );
14031407
bt->addAction( mActionFormAnnotation );
14041408
bt->addAction( mActionHtmlAnnotation );
1409+
bt->addAction( mActionSvgAnnotation );
14051410
bt->addAction( mActionAnnotation );
14061411

14071412
QAction* defAnnotationAction = mActionTextAnnotation;
@@ -1840,6 +1845,8 @@ void QgisApp::createCanvasTools()
18401845
mMapTools.mFormAnnotation->setAction( mActionFormAnnotation );
18411846
mMapTools.mHtmlAnnotation = new QgsMapToolHtmlAnnotation( mMapCanvas );
18421847
mMapTools.mHtmlAnnotation->setAction( mActionHtmlAnnotation );
1848+
mMapTools.mSvgAnnotation = new QgsMapToolSvgAnnotation( mMapCanvas );
1849+
mMapTools.mSvgAnnotation->setAction( mActionSvgAnnotation );
18431850
mMapTools.mAnnotation = new QgsMapToolAnnotation( mMapCanvas );
18441851
mMapTools.mAnnotation->setAction( mActionAnnotation );
18451852
mMapTools.mAddFeature = new QgsMapToolAddFeature( mMapCanvas );
@@ -3932,6 +3939,11 @@ void QgisApp::addTextAnnotation()
39323939
mMapCanvas->setMapTool( mMapTools.mTextAnnotation );
39333940
}
39343941

3942+
void QgisApp::addSvgAnnotation()
3943+
{
3944+
mMapCanvas->setMapTool( mMapTools.mSvgAnnotation );
3945+
}
3946+
39353947
void QgisApp::modifyAnnotation()
39363948
{
39373949
mMapCanvas->setMapTool( mMapTools.mAnnotation );
@@ -4468,6 +4480,13 @@ bool QgisApp::loadAnnotationItemsFromProject( const QDomDocument& doc )
44684480
QgsHtmlAnnotationItem* newHtmlItem = new QgsHtmlAnnotationItem( mMapCanvas );
44694481
newHtmlItem->readXML( doc, htmlItemList.at( i ).toElement() );
44704482
}
4483+
4484+
QDomNodeList svgItemList = doc.elementsByTagName( "SVGAnnotationItem" );
4485+
for ( int i = 0; i < svgItemList.size(); ++i )
4486+
{
4487+
QgsSVGAnnotationItem* newSvgItem = new QgsSVGAnnotationItem( mMapCanvas );
4488+
newSvgItem->readXML( doc, svgItemList.at( i ).toElement() );
4489+
}
44714490
return true;
44724491
}
44734492

src/app/qgisapp.h

+2
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
825825
void addFormAnnotation();
826826
void addTextAnnotation();
827827
void addHtmlAnnotation();
828+
void addSvgAnnotation();
828829
void modifyAnnotation();
829830

830831
//! shows label settings dialog (for labeling-ng)
@@ -1094,6 +1095,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
10941095
QgsMapTool* mAnnotation;
10951096
QgsMapTool* mFormAnnotation;
10961097
QgsMapTool* mHtmlAnnotation;
1098+
QgsMapTool* mSvgAnnotation;
10971099
QgsMapTool* mTextAnnotation;
10981100
QgsMapTool* mPinLabels;
10991101
QgsMapTool* mShowHideLabels;

src/app/qgsmaptoolannotation.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "qgsmapcanvas.h"
2525
#include "qgstextannotationdialog.h"
2626
#include "qgstextannotationitem.h"
27+
#include "qgssvgannotationdialog.h"
28+
#include "qgssvgannotationitem.h"
2729
#include <QDialog>
2830
#include <QMouseEvent>
2931

@@ -68,6 +70,12 @@ QDialog* QgsMapToolAnnotation::createItemEditor( QgsAnnotationItem *item )
6870
return new QgsHtmlAnnotationDialog( hItem );
6971
}
7072

73+
QgsSVGAnnotationItem* sItem = dynamic_cast<QgsSVGAnnotationItem*>( item );
74+
if ( sItem )
75+
{
76+
return new QgsSVGAnnotationDialog( sItem );
77+
}
78+
7179
return 0;
7280
}
7381

src/app/qgsmaptoolsvgannotation.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/***************************************************************************
2+
qgsmaptoolsvgannotation.cpp
3+
---------------------------
4+
begin : November, 2012
5+
copyright : (C) 2012 by Marco Hugentobler
6+
email : marco dot hugentobler at sourcepole dot ch
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgsmaptoolsvgannotation.h"
19+
#include "qgssvgannotationitem.h"
20+
#include <QMouseEvent>
21+
22+
QgsMapToolSvgAnnotation::QgsMapToolSvgAnnotation( QgsMapCanvas* canvas ): QgsMapToolAnnotation( canvas )
23+
{
24+
25+
}
26+
27+
QgsMapToolSvgAnnotation::~QgsMapToolSvgAnnotation()
28+
{
29+
30+
}
31+
32+
QgsAnnotationItem* QgsMapToolSvgAnnotation::createItem( QMouseEvent* e )
33+
{
34+
QgsSVGAnnotationItem* svgItem = new QgsSVGAnnotationItem( mCanvas );
35+
svgItem->setMapPosition( toMapCoordinates( e->pos() ) );
36+
svgItem->setSelected( true );
37+
svgItem->setFrameSize( QSizeF( 200, 100 ) );
38+
return svgItem;
39+
}

src/app/qgsmaptoolsvgannotation.h

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/***************************************************************************
2+
qgsmaptoolsvgannotation.h
3+
-------------------------
4+
begin : November, 2012
5+
copyright : (C) 2012 by Marco Hugentobler
6+
email : marco dot hugentobler at sourcepole dot ch
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSMAPTOOLSVGANNOTATION_H
19+
#define QGSMAPTOOLSVGANNOTATION_H
20+
21+
#include "qgsmaptoolannotation.h"
22+
23+
class QgsMapToolSvgAnnotation: public QgsMapToolAnnotation
24+
{
25+
public:
26+
QgsMapToolSvgAnnotation( QgsMapCanvas* canvas );
27+
~QgsMapToolSvgAnnotation();
28+
protected:
29+
QgsAnnotationItem* createItem( QMouseEvent* e );
30+
};
31+
32+
#endif // QGSMAPTOOLSVGANNOTATION_H

src/app/qgssvgannotationdialog.cpp

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/***************************************************************************
2+
qgssvgannotationdialog.cpp
3+
--------------------------
4+
begin : November, 2012
5+
copyright : (C) 2012 by Marco Hugentobler
6+
email : marco dot hugentobler at sourcepole dot ch
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgssvgannotationdialog.h"
19+
#include "qgsannotationwidget.h"
20+
#include "qgssvgannotationitem.h"
21+
#include <QFileDialog>
22+
#include <QFileInfo>
23+
#include <QGraphicsScene>
24+
25+
QgsSVGAnnotationDialog::QgsSVGAnnotationDialog( QgsSVGAnnotationItem* item, QWidget * parent, Qt::WindowFlags f):
26+
QDialog( parent, f ), mItem( item ), mEmbeddedWidget( 0 )
27+
{
28+
setupUi( this );
29+
mEmbeddedWidget = new QgsAnnotationWidget( mItem );
30+
mEmbeddedWidget->show();
31+
mStackedWidget->addWidget( mEmbeddedWidget );
32+
mStackedWidget->setCurrentWidget( mEmbeddedWidget );
33+
34+
if( mItem )
35+
{
36+
mFileLineEdit->setText( mItem->filePath() );
37+
}
38+
39+
QObject::connect( mButtonBox, SIGNAL( accepted() ), this, SLOT( applySettingsToItem() ) );
40+
QPushButton* deleteButton = new QPushButton( tr( "Delete" ) );
41+
QObject::connect( deleteButton, SIGNAL( clicked() ), this, SLOT( deleteItem() ) );
42+
mButtonBox->addButton( deleteButton, QDialogButtonBox::RejectRole );
43+
}
44+
45+
QgsSVGAnnotationDialog::QgsSVGAnnotationDialog(): QDialog(), mItem( 0 ), mEmbeddedWidget( 0 )
46+
{
47+
48+
}
49+
50+
QgsSVGAnnotationDialog::~QgsSVGAnnotationDialog()
51+
{
52+
53+
}
54+
55+
void QgsSVGAnnotationDialog::on_mBrowseToolButton_clicked()
56+
{
57+
QString directory;
58+
QFileInfo fi( mFileLineEdit->text() );
59+
if ( fi.exists() )
60+
{
61+
directory = fi.absolutePath();
62+
}
63+
QString filename = QFileDialog::getOpenFileName( 0, tr( "html" ), directory, "*.html" );
64+
mFileLineEdit->setText( filename );
65+
}
66+
67+
void QgsSVGAnnotationDialog::applySettingsToItem()
68+
{
69+
if ( mEmbeddedWidget )
70+
{
71+
mEmbeddedWidget->apply();
72+
}
73+
74+
if( mItem )
75+
{
76+
mItem->setFilePath( mFileLineEdit->text() );
77+
mItem->update();
78+
}
79+
80+
}
81+
82+
void QgsSVGAnnotationDialog::deleteItem()
83+
{
84+
QGraphicsScene* scene = mItem->scene();
85+
if ( scene )
86+
{
87+
scene->removeItem( mItem );
88+
}
89+
delete mItem;
90+
mItem = 0;
91+
}

src/app/qgssvgannotationdialog.h

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/***************************************************************************
2+
qgssvgannotationdialog.h
3+
------------------------
4+
begin : November, 2012
5+
copyright : (C) 2012 by Marco Hugentobler
6+
email : marco dot hugentobler at sourcepole dot ch
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSSVGANNOTATIONDIALOG_H
19+
#define QGSSVGANNOTATIONDIALOG_H
20+
21+
#include "ui_qgsformannotationdialogbase.h"
22+
23+
class QgsSVGAnnotationItem;
24+
class QgsAnnotationWidget;
25+
26+
class QgsSVGAnnotationDialog: public QDialog, private Ui::QgsFormAnnotationDialogBase
27+
{
28+
Q_OBJECT
29+
public:
30+
QgsSVGAnnotationDialog( QgsSVGAnnotationItem* item, QWidget * parent = 0, Qt::WindowFlags f = 0);
31+
~QgsSVGAnnotationDialog();
32+
33+
private slots:
34+
void on_mBrowseToolButton_clicked();
35+
void applySettingsToItem();
36+
void deleteItem();
37+
38+
private:
39+
QgsSVGAnnotationDialog(); //forbidden
40+
41+
QgsSVGAnnotationItem* mItem;
42+
QgsAnnotationWidget* mEmbeddedWidget;
43+
};
44+
45+
#endif // QGSSVGANNOTATIONDIALOG_H

src/app/qgssvgannotationitemdialog.h

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#ifndef QGSSVGANNOTATIONITEMDIALOG_H
2+
#define QGSSVGANNOTATIONITEMDIALOG_H
3+
4+
#endif // QGSSVGANNOTATIONITEMDIALOG_H

src/gui/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ qgsrasterformatsaveoptionswidget.cpp
8989
qgsrasterpyramidsoptionswidget.cpp
9090
qgsrubberband.cpp
9191
qgsscalecombobox.cpp
92+
qgssvgannotationitem.cpp
9293
qgstextannotationitem.cpp
9394
qgsvertexmarker.cpp
9495
qgsludialog.cpp

0 commit comments

Comments
 (0)