Skip to content

Commit

Permalink
[FEATURE]: Use text annotations as watermarks in QGIS server. Develop…
Browse files Browse the repository at this point in the history
…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 cca386f
Show file tree
Hide file tree
Showing 19 changed files with 606 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -77,6 +77,7 @@ SET(QGIS_APP_SRCS
qgsmaptoolselectutils.cpp
qgsmaptoolsimplify.cpp
qgsmaptoolsplitfeatures.cpp
qgsmaptoolsvgannotation.cpp
qgsmaptooltextannotation.cpp
qgsmaptoolvertexedit.cpp

Expand All @@ -102,6 +103,7 @@ SET(QGIS_APP_SRCS
qgsshortcutsmanager.cpp
qgssinglesymboldialog.cpp
qgssnappingdialog.cpp
qgssvgannotationdialog.cpp
qgsundowidget.cpp
qgstipgui.cpp
qgstipfactory.cpp
Expand Down Expand Up @@ -247,6 +249,7 @@ SET (QGIS_APP_MOC_HDRS
qgssinglesymboldialog.h
qgssnappingdialog.h
qgssponsors.h
qgssvgannotationdialog.h
qgstextannotationdialog.h
qgstipgui.h
qgstipfactory.h
Expand Down
19 changes: 19 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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() ) );

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/app/qgsmaptoolannotation.cpp
Expand Up @@ -24,6 +24,8 @@
#include "qgsmapcanvas.h"
#include "qgstextannotationdialog.h"
#include "qgstextannotationitem.h"
#include "qgssvgannotationdialog.h"
#include "qgssvgannotationitem.h"
#include <QDialog>
#include <QMouseEvent>

Expand Down Expand Up @@ -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;
}

Expand Down
39 changes: 39 additions & 0 deletions src/app/qgsmaptoolsvgannotation.cpp
@@ -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;
}
32 changes: 32 additions & 0 deletions src/app/qgsmaptoolsvgannotation.h
@@ -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
91 changes: 91 additions & 0 deletions src/app/qgssvgannotationdialog.cpp
@@ -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;
}
45 changes: 45 additions & 0 deletions src/app/qgssvgannotationdialog.h
@@ -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
4 changes: 4 additions & 0 deletions src/app/qgssvgannotationitemdialog.h
@@ -0,0 +1,4 @@
#ifndef QGSSVGANNOTATIONITEMDIALOG_H
#define QGSSVGANNOTATIONITEMDIALOG_H

#endif // QGSSVGANNOTATIONITEMDIALOG_H
1 change: 1 addition & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -89,6 +89,7 @@ qgsrasterformatsaveoptionswidget.cpp
qgsrasterpyramidsoptionswidget.cpp
qgsrubberband.cpp
qgsscalecombobox.cpp
qgssvgannotationitem.cpp
qgstextannotationitem.cpp
qgsvertexmarker.cpp
qgsludialog.cpp
Expand Down

0 comments on commit cca386f

Please sign in to comment.