Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE]: svg- and text items can be used as watermarks in QGIS serv…
…er. Developed for Faunalia ( http://www.faunalia.it) with funding from Regione Toscana \- Settore SISTEMA INFORMATIVO TERRITORIALE ED AMBIENTALE
  • Loading branch information
mhugent committed Nov 6, 2012
2 parents f410e38 + 550a2c6 commit 52dd48e
Show file tree
Hide file tree
Showing 19 changed files with 694 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -79,6 +79,7 @@ SET(QGIS_APP_SRCS
qgsmaptoolselectutils.cpp
qgsmaptoolsimplify.cpp
qgsmaptoolsplitfeatures.cpp
qgsmaptoolsvgannotation.cpp
qgsmaptooltextannotation.cpp
qgsmaptoolvertexedit.cpp

Expand All @@ -104,6 +105,7 @@ SET(QGIS_APP_SRCS
qgsshortcutsmanager.cpp
qgssinglesymboldialog.cpp
qgssnappingdialog.cpp
qgssvgannotationdialog.cpp
qgsundowidget.cpp
qgstipgui.cpp
qgstipfactory.cpp
Expand Down Expand Up @@ -251,6 +253,7 @@ SET (QGIS_APP_MOC_HDRS
qgssinglesymboldialog.h
qgssnappingdialog.h
qgssponsors.h
qgssvgannotationdialog.h
qgstextannotationdialog.h
qgstipgui.h
qgstipfactory.h
Expand Down
34 changes: 28 additions & 6 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 @@ -735,6 +737,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 @@ -939,6 +942,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 @@ -1404,15 +1408,18 @@ void QgisApp::createToolBars()
bt->addAction( mActionTextAnnotation );
bt->addAction( mActionFormAnnotation );
bt->addAction( mActionHtmlAnnotation );
bt->addAction( mActionSvgAnnotation );
bt->addAction( mActionAnnotation );

QAction* defAnnotationAction = mActionTextAnnotation;
switch ( settings.value( "/UI/annotationTool", 0 ).toInt() )
{
case 0: defAnnotationAction = mActionTextAnnotation; break;
case 1: defAnnotationAction = mActionFormAnnotation; break;
case 2: defAnnotationAction = mActionAnnotation; break;
case 3: defAnnotationAction = mActionHtmlAnnotation; break;
case 2: defAnnotationAction = mActionHtmlAnnotation; break;
case 3: defAnnotationAction = mActionSvgAnnotation; break;
case 4: defAnnotationAction = mActionAnnotation; break;

}
bt->setDefaultAction( defAnnotationAction );
QAction* annotationAction = mAttributesToolBar->addWidget( bt );
Expand Down Expand Up @@ -1843,6 +1850,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 @@ -3935,6 +3944,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 @@ -4471,6 +4485,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 Expand Up @@ -8101,11 +8122,12 @@ void QgisApp::toolButtonActionTriggered( QAction *action )
settings.setValue( "/UI/annotationTool", 0 );
else if ( action == mActionFormAnnotation )
settings.setValue( "/UI/annotationTool", 1 );
else if ( action == mActionAnnotation )
settings.setValue( "/UI/annotationTool", 2 );
else if ( action == mActionHtmlAnnotation )
settings.setValue( "/UI/annotationTool", 3 );

settings.setValue( "/UI/annotationTool", 2 );
else if ( action == mActionSvgAnnotation )
settings.setValue( "UI/annotationTool", 3 );
else if ( action == mActionAnnotation )
settings.setValue( "/UI/annotationTool", 4 );
bt->setDefaultAction( action );
}

Expand Down
2 changes: 2 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -830,6 +830,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 @@ -1099,6 +1100,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 52dd48e

Please sign in to comment.