forked from malamioute/agileplugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
agileplugin.cpp
123 lines (102 loc) · 3.22 KB
/
agileplugin.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
#include "agileplugin.h"
#include "qgisinterface.h"
#include "qgsmessagelog.h"
#include "qgsmapcanvas.h"
#include "qgsrasterlayer.h"
#include "qgsmaplayerregistry.h"
#include <QAction>
#include <QList>
// Static variables for plugin description
static const QString sName = QObject::tr("AgilePlugin");
static const QString sDescription = QObject::tr("This is a very agile plugin");
static const QString sCategory = QObject::tr("Agile projects");
static const QString sPluginVersion = QObject::tr("Version 1.0");
static const QgisPlugin::PLUGINTYPE sPluginType = QgisPlugin::UI;
static const QString sPluginIcon = "";
AgilePlugin::AgilePlugin(QgisInterface * interface)
: QgisPlugin(sName, sDescription, sCategory, sPluginVersion, sPluginType)
, m_GISInterface(interface)
, m_action(nullptr)
{
}
void AgilePlugin::initGui()
{
std::cout << "AgilePlugin::initGui" << std::endl;
// Creates the action
m_action = new QAction(QIcon(""), tr("Agile Plugin"), this);
m_action->setWhatsThis(tr("Launches the agile plugin"));
// Connects the triggered signal to the slot
connect(m_action, SIGNAL(triggered()), this, SLOT(run()));
// Adds the action to the menu
m_GISInterface->addRasterToolBarIcon(m_action);
m_GISInterface->addPluginToMenu(tr("&Agile Plugin"), m_action);
}
void AgilePlugin::run()
{
QgsMessageLog::instance()->logMessage("Agile Plugin launched", "AgilePlugin", QgsMessageLog::INFO);
// Gets the map canvas
QgsMapCanvas * canvas = m_GISInterface->mapCanvas();
// Creates a raster layer
QgsRasterLayer * rasterLayer = new QgsRasterLayer("/home/matthieu/Downloads/land_shallow_topo_2048.tif");
if (rasterLayer->isValid())
{
// Registers the layer
QgsMapLayerRegistry::instance()->addMapLayer(rasterLayer);
// Setups the canvas
canvas->setExtent(rasterLayer->extent());
canvas->enableAntiAliasing(true);
canvas->setCanvasColor(QColor(255, 255, 255));
canvas->freeze(false);
// Adds the layer in the canvas
QList <QgsMapCanvasLayer> layerSet;
layerSet.append(QgsMapCanvasLayer(rasterLayer));
canvas->setLayerSet(layerSet);
canvas->setVisible(true);
canvas->refresh();
}
}
void AgilePlugin::unload()
{
QgsMessageLog::instance()->logMessage("Agile Plugin unloaded", "AgilePlugin", QgsMessageLog::INFO);
}
//////////////////////////////////////////////////////////////////////////
//
//
// THE FOLLOWING CODE IS AUTOGENERATED BY THE PLUGIN BUILDER SCRIPT
// YOU WOULD NORMALLY NOT NEED TO MODIFY THIS, AND YOUR PLUGIN
// MAY NOT WORK PROPERLY IF YOU MODIFY THIS INCORRECTLY
//
//
//////////////////////////////////////////////////////////////////////////
QGISEXTERN QgisPlugin * classFactory(QgisInterface * theQgisInterfacePointer)
{
return new AgilePlugin(theQgisInterfacePointer);
}
QGISEXTERN QString name()
{
return sName;
}
QGISEXTERN QString description()
{
return sDescription;
}
QGISEXTERN QString category()
{
return sCategory;
}
QGISEXTERN int type()
{
return sPluginType;
}
QGISEXTERN QString version()
{
return sPluginVersion;
}
QGISEXTERN QString icon()
{
return sPluginIcon;
}
QGISEXTERN void unload( QgisPlugin * thePluginPointer )
{
delete thePluginPointer;
}