-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqgssosplugin.cpp
152 lines (126 loc) · 3.85 KB
/
qgssosplugin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/***************************************************************************
qgssosplugin.cpp - description
------------------------------
begin : June 2013
copyright : (C) 2013 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 "qgssosplugin.h"
#include "qgsmapcanvas.h"
#include "qgsmaptoolsensorinfo.h"
#include "qgssossourceselect.h"
#include "qgis.h"
#include "qgisinterface.h"
#include <QAction>
static const QString name_ = QObject::tr( "SOS plugin" );
static const QString description_ = QObject::tr( "A plugin to access sensor observation services" );
static const QString version_ = QObject::tr( "Version 0.1" );
//static const QString icon_ = ":/raster/dem.png";
static const QString category_ = QObject::tr( "Vector" );
QgsSOSPlugin::QgsSOSPlugin( QgisInterface* iface ): mIface( iface ), mAction( 0 ), mSensorInfoAction( 0 ), mMapToolSensorInfo( 0 )
{
}
QgsSOSPlugin::~QgsSOSPlugin()
{
unload();
}
void QgsSOSPlugin::initGui()
{
if ( mIface )
{
mAction = new QAction( QIcon( ":/sos.png" ), tr( "Sensor observation service" ), 0 );
QObject::connect( mAction, SIGNAL( triggered() ), this, SLOT( showSOSDialog() ) );
mIface->addWebToolBarIcon( mAction );
mIface->addPluginToWebMenu( tr( "Sensor observation service" ), mAction );
mSensorInfoAction = new QAction( QIcon( ":/sensor_info.png" ), tr( "Sensor info" ), 0 );
QObject::connect( mSensorInfoAction, SIGNAL( toggled( bool ) ), this, SLOT( toggleSensorInfo( bool ) ) );
mSensorInfoAction->setCheckable( true );
mIface->addWebToolBarIcon( mSensorInfoAction );
mMapToolSensorInfo = new QgsMapToolSensorInfo( mIface->mapCanvas() );
mMapToolSensorInfo->setAction( mSensorInfoAction );
}
}
void QgsSOSPlugin::unload()
{
if ( mAction && mIface )
{
mIface->removeWebToolBarIcon( mAction );
mIface->removePluginWebMenu( tr( "Sensor ovservation service" ), mAction );
}
delete mAction;
mAction = 0;
if ( mSensorInfoAction && mIface )
{
mIface->removeWebToolBarIcon( mSensorInfoAction );
}
delete mMapToolSensorInfo;
mMapToolSensorInfo = 0;
delete mSensorInfoAction;
mSensorInfoAction = 0;
}
void QgsSOSPlugin::showSOSDialog()
{
QgsSOSSourceSelect dialog( mIface );
dialog.exec();
}
void QgsSOSPlugin::toggleSensorInfo( bool checked )
{
if ( !mIface )
{
return;
}
QgsMapCanvas* canvas = mIface->mapCanvas();
if ( !canvas )
{
return;
}
if ( checked )
{
canvas->setMapTool( mMapToolSensorInfo );
}
else
{
canvas->unsetMapTool( mMapToolSensorInfo );
}
}
//global methods for the plugin manager
QGISEXTERN QgisPlugin* classFactory( QgisInterface * ifacePointer )
{
return new QgsSOSPlugin( ifacePointer );
}
QGISEXTERN QString name()
{
return name_;
}
QGISEXTERN QString description()
{
return description_;
}
QGISEXTERN QString version()
{
return version_;
}
/*QGISEXTERN QString icon()
{
return icon_;
}*/
QGISEXTERN int type()
{
return QgisPlugin::UI;
}
QGISEXTERN void unload( QgisPlugin* pluginPointer )
{
delete pluginPointer;
}
QGISEXTERN QString category()
{
return category_;
}