Skip to content
Permalink
Browse files

[FEATURE]: Use text annotations as watermarks in QGIS server. Develop…

…ed for Faunalia (http://www.faunalia.it) with funding from Regione Toscana - Settore SISTEMA INFORMATIVO TERRITORIALE ED AMBIENTALE
  • Loading branch information
mhugent committed Nov 2, 2012
1 parent 234709d commit cca386f53e20666b294d1c46162a909be640ddb2
@@ -77,6 +77,7 @@ SET(QGIS_APP_SRCS
qgsmaptoolselectutils.cpp
qgsmaptoolsimplify.cpp
qgsmaptoolsplitfeatures.cpp
qgsmaptoolsvgannotation.cpp
qgsmaptooltextannotation.cpp
qgsmaptoolvertexedit.cpp

@@ -102,6 +103,7 @@ SET(QGIS_APP_SRCS
qgsshortcutsmanager.cpp
qgssinglesymboldialog.cpp
qgssnappingdialog.cpp
qgssvgannotationdialog.cpp
qgsundowidget.cpp
qgstipgui.cpp
qgstipfactory.cpp
@@ -247,6 +249,7 @@ SET (QGIS_APP_MOC_HDRS
qgssinglesymboldialog.h
qgssnappingdialog.h
qgssponsors.h
qgssvgannotationdialog.h
qgstextannotationdialog.h
qgstipgui.h
qgstipfactory.h
@@ -177,6 +177,7 @@
#include "qgssinglebandgrayrenderer.h"
#include "qgssnappingdialog.h"
#include "qgssponsors.h"
#include "qgssvgannotationitem.h"
#include "qgstextannotationitem.h"
#include "qgstipgui.h"
#include "qgsundowidget.h"
@@ -233,6 +234,7 @@
#include "qgsmaptoolselectfreehand.h"
#include "qgsmaptoolselectpolygon.h"
#include "qgsmaptoolselectradius.h"
#include "qgsmaptoolsvgannotation.h"
#include "qgsmaptoolreshape.h"
#include "qgsmaptoolrotatepointsymbols.h"
#include "qgsmaptoolsplitfeatures.h"
@@ -734,6 +736,7 @@ QgisApp::~QgisApp()
delete mMapTools.mTextAnnotation;
delete mMapTools.mFormAnnotation;
delete mMapTools.mHtmlAnnotation;
delete mMapTools.mSvgAnnotation;
delete mMapTools.mAnnotation;
delete mMapTools.mAddFeature;
delete mMapTools.mMoveFeature;
@@ -938,6 +941,7 @@ void QgisApp::createActions()
connect( mActionTextAnnotation, SIGNAL( triggered() ), this, SLOT( addTextAnnotation() ) );
connect( mActionFormAnnotation, SIGNAL( triggered() ), this, SLOT( addFormAnnotation() ) );
connect( mActionHtmlAnnotation, SIGNAL( triggered() ), this, SLOT( addHtmlAnnotation() ) );
connect( mActionSvgAnnotation, SIGNAL( triggered() ), this, SLOT( addSvgAnnotation() ) );
connect( mActionAnnotation, SIGNAL( triggered() ), this, SLOT( modifyAnnotation() ) );
connect( mActionLabeling, SIGNAL( triggered() ), this, SLOT( labeling() ) );

@@ -1402,6 +1406,7 @@ void QgisApp::createToolBars()
bt->addAction( mActionTextAnnotation );
bt->addAction( mActionFormAnnotation );
bt->addAction( mActionHtmlAnnotation );
bt->addAction( mActionSvgAnnotation );
bt->addAction( mActionAnnotation );

QAction* defAnnotationAction = mActionTextAnnotation;
@@ -1840,6 +1845,8 @@ void QgisApp::createCanvasTools()
mMapTools.mFormAnnotation->setAction( mActionFormAnnotation );
mMapTools.mHtmlAnnotation = new QgsMapToolHtmlAnnotation( mMapCanvas );
mMapTools.mHtmlAnnotation->setAction( mActionHtmlAnnotation );
mMapTools.mSvgAnnotation = new QgsMapToolSvgAnnotation( mMapCanvas );
mMapTools.mSvgAnnotation->setAction( mActionSvgAnnotation );
mMapTools.mAnnotation = new QgsMapToolAnnotation( mMapCanvas );
mMapTools.mAnnotation->setAction( mActionAnnotation );
mMapTools.mAddFeature = new QgsMapToolAddFeature( mMapCanvas );
@@ -3932,6 +3939,11 @@ void QgisApp::addTextAnnotation()
mMapCanvas->setMapTool( mMapTools.mTextAnnotation );
}

void QgisApp::addSvgAnnotation()
{
mMapCanvas->setMapTool( mMapTools.mSvgAnnotation );
}

void QgisApp::modifyAnnotation()
{
mMapCanvas->setMapTool( mMapTools.mAnnotation );
@@ -4468,6 +4480,13 @@ bool QgisApp::loadAnnotationItemsFromProject( const QDomDocument& doc )
QgsHtmlAnnotationItem* newHtmlItem = new QgsHtmlAnnotationItem( mMapCanvas );
newHtmlItem->readXML( doc, htmlItemList.at( i ).toElement() );
}

QDomNodeList svgItemList = doc.elementsByTagName( "SVGAnnotationItem" );
for ( int i = 0; i < svgItemList.size(); ++i )
{
QgsSVGAnnotationItem* newSvgItem = new QgsSVGAnnotationItem( mMapCanvas );
newSvgItem->readXML( doc, svgItemList.at( i ).toElement() );
}
return true;
}

@@ -825,6 +825,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
void addFormAnnotation();
void addTextAnnotation();
void addHtmlAnnotation();
void addSvgAnnotation();
void modifyAnnotation();

//! shows label settings dialog (for labeling-ng)
@@ -1094,6 +1095,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
QgsMapTool* mAnnotation;
QgsMapTool* mFormAnnotation;
QgsMapTool* mHtmlAnnotation;
QgsMapTool* mSvgAnnotation;
QgsMapTool* mTextAnnotation;
QgsMapTool* mPinLabels;
QgsMapTool* mShowHideLabels;
@@ -24,6 +24,8 @@
#include "qgsmapcanvas.h"
#include "qgstextannotationdialog.h"
#include "qgstextannotationitem.h"
#include "qgssvgannotationdialog.h"
#include "qgssvgannotationitem.h"
#include <QDialog>
#include <QMouseEvent>

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

QgsSVGAnnotationItem* sItem = dynamic_cast<QgsSVGAnnotationItem*>( item );
if ( sItem )
{
return new QgsSVGAnnotationDialog( sItem );
}

return 0;
}

@@ -0,0 +1,39 @@
/***************************************************************************
qgsmaptoolsvgannotation.cpp
---------------------------
begin : November, 2012
copyright : (C) 2012 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsmaptoolsvgannotation.h"
#include "qgssvgannotationitem.h"
#include <QMouseEvent>

QgsMapToolSvgAnnotation::QgsMapToolSvgAnnotation( QgsMapCanvas* canvas ): QgsMapToolAnnotation( canvas )
{

}

QgsMapToolSvgAnnotation::~QgsMapToolSvgAnnotation()
{

}

QgsAnnotationItem* QgsMapToolSvgAnnotation::createItem( QMouseEvent* e )
{
QgsSVGAnnotationItem* svgItem = new QgsSVGAnnotationItem( mCanvas );
svgItem->setMapPosition( toMapCoordinates( e->pos() ) );
svgItem->setSelected( true );
svgItem->setFrameSize( QSizeF( 200, 100 ) );
return svgItem;
}
@@ -0,0 +1,32 @@
/***************************************************************************
qgsmaptoolsvgannotation.h
-------------------------
begin : November, 2012
copyright : (C) 2012 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSMAPTOOLSVGANNOTATION_H
#define QGSMAPTOOLSVGANNOTATION_H

#include "qgsmaptoolannotation.h"

class QgsMapToolSvgAnnotation: public QgsMapToolAnnotation
{
public:
QgsMapToolSvgAnnotation( QgsMapCanvas* canvas );
~QgsMapToolSvgAnnotation();
protected:
QgsAnnotationItem* createItem( QMouseEvent* e );
};

#endif // QGSMAPTOOLSVGANNOTATION_H
@@ -0,0 +1,91 @@
/***************************************************************************
qgssvgannotationdialog.cpp
--------------------------
begin : November, 2012
copyright : (C) 2012 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgssvgannotationdialog.h"
#include "qgsannotationwidget.h"
#include "qgssvgannotationitem.h"
#include <QFileDialog>
#include <QFileInfo>
#include <QGraphicsScene>

QgsSVGAnnotationDialog::QgsSVGAnnotationDialog( QgsSVGAnnotationItem* item, QWidget * parent, Qt::WindowFlags f):
QDialog( parent, f ), mItem( item ), mEmbeddedWidget( 0 )
{
setupUi( this );
mEmbeddedWidget = new QgsAnnotationWidget( mItem );
mEmbeddedWidget->show();
mStackedWidget->addWidget( mEmbeddedWidget );
mStackedWidget->setCurrentWidget( mEmbeddedWidget );

if( mItem )
{
mFileLineEdit->setText( mItem->filePath() );
}

QObject::connect( mButtonBox, SIGNAL( accepted() ), this, SLOT( applySettingsToItem() ) );
QPushButton* deleteButton = new QPushButton( tr( "Delete" ) );
QObject::connect( deleteButton, SIGNAL( clicked() ), this, SLOT( deleteItem() ) );
mButtonBox->addButton( deleteButton, QDialogButtonBox::RejectRole );
}

QgsSVGAnnotationDialog::QgsSVGAnnotationDialog(): QDialog(), mItem( 0 ), mEmbeddedWidget( 0 )
{

}

QgsSVGAnnotationDialog::~QgsSVGAnnotationDialog()
{

}

void QgsSVGAnnotationDialog::on_mBrowseToolButton_clicked()
{
QString directory;
QFileInfo fi( mFileLineEdit->text() );
if ( fi.exists() )
{
directory = fi.absolutePath();
}
QString filename = QFileDialog::getOpenFileName( 0, tr( "html" ), directory, "*.html" );
mFileLineEdit->setText( filename );
}

void QgsSVGAnnotationDialog::applySettingsToItem()
{
if ( mEmbeddedWidget )
{
mEmbeddedWidget->apply();
}

if( mItem )
{
mItem->setFilePath( mFileLineEdit->text() );
mItem->update();
}

}

void QgsSVGAnnotationDialog::deleteItem()
{
QGraphicsScene* scene = mItem->scene();
if ( scene )
{
scene->removeItem( mItem );
}
delete mItem;
mItem = 0;
}
@@ -0,0 +1,45 @@
/***************************************************************************
qgssvgannotationdialog.h
------------------------
begin : November, 2012
copyright : (C) 2012 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSSVGANNOTATIONDIALOG_H
#define QGSSVGANNOTATIONDIALOG_H

#include "ui_qgsformannotationdialogbase.h"

class QgsSVGAnnotationItem;
class QgsAnnotationWidget;

class QgsSVGAnnotationDialog: public QDialog, private Ui::QgsFormAnnotationDialogBase
{
Q_OBJECT
public:
QgsSVGAnnotationDialog( QgsSVGAnnotationItem* item, QWidget * parent = 0, Qt::WindowFlags f = 0);
~QgsSVGAnnotationDialog();

private slots:
void on_mBrowseToolButton_clicked();
void applySettingsToItem();
void deleteItem();

private:
QgsSVGAnnotationDialog(); //forbidden

QgsSVGAnnotationItem* mItem;
QgsAnnotationWidget* mEmbeddedWidget;
};

#endif // QGSSVGANNOTATIONDIALOG_H
@@ -0,0 +1,4 @@
#ifndef QGSSVGANNOTATIONITEMDIALOG_H
#define QGSSVGANNOTATIONITEMDIALOG_H

#endif // QGSSVGANNOTATIONITEMDIALOG_H
@@ -89,6 +89,7 @@ qgsrasterformatsaveoptionswidget.cpp
qgsrasterpyramidsoptionswidget.cpp
qgsrubberband.cpp
qgsscalecombobox.cpp
qgssvgannotationitem.cpp
qgstextannotationitem.cpp
qgsvertexmarker.cpp
qgsludialog.cpp

0 comments on commit cca386f

Please sign in to comment.
You can’t perform that action at this time.