Skip to content

Commit 6bc5ab6

Browse files
author
timlinux
committed
Added capture point plugin to cater for various user requests
git-svn-id: http://svn.osgeo.org/qgis/trunk@8998 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent fb67488 commit 6bc5ab6

13 files changed

+874
-0
lines changed

src/plugins/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ INSTALL(FILES qgisplugin.h qgsrendererplugin.h DESTINATION ${QGIS_INCLUDE_DIR})
2020

2121
SUBDIRS (quick_print)
2222

23+
24+
SUBDIRS (coordinate_capture)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
########################################################
3+
# Files
4+
5+
SET (coordinatecapture_SRCS
6+
coordinatecapture.cpp
7+
coordinatecapturegui.cpp
8+
coordinatecapturemaptool.cpp
9+
)
10+
11+
SET (coordinatecapture_UIS coordinatecaptureguibase.ui)
12+
13+
SET (coordinatecapture_MOC_HDRS
14+
coordinatecapture.h
15+
coordinatecapturegui.h
16+
coordinatecapturemaptool.h
17+
)
18+
19+
SET (coordinatecapture_RCCS coordinatecapture.qrc)
20+
21+
########################################################
22+
# Build
23+
24+
QT4_WRAP_UI (coordinatecapture_UIS_H ${coordinatecapture_UIS})
25+
26+
QT4_WRAP_CPP (coordinatecapture_MOC_SRCS ${coordinatecapture_MOC_HDRS})
27+
28+
QT4_ADD_RESOURCES(coordinatecapture_RCC_SRCS ${coordinatecapture_RCCS})
29+
30+
ADD_LIBRARY (coordinatecaptureplugin MODULE ${coordinatecapture_SRCS} ${coordinatecapture_MOC_SRCS} ${coordinatecapture_RCC_SRCS} ${coordinatecapture_UIS_H})
31+
32+
INCLUDE_DIRECTORIES(
33+
${CMAKE_CURRENT_BINARY_DIR}
34+
../../core ../../core/raster ../../core/renderer ../../core/symbology
35+
../../gui
36+
..
37+
)
38+
39+
TARGET_LINK_LIBRARIES(coordinatecaptureplugin
40+
qgis_core
41+
qgis_gui
42+
)
43+
44+
45+
########################################################
46+
# Install
47+
48+
INSTALL(TARGETS coordinatecaptureplugin
49+
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
50+
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})
51+

src/plugins/coordinate_capture/README

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Coordinate Capture Plugin for Quantum GIS
2+
3+
Tim Sutton 2008
4+
5+
A simple plugin that allows you to copy the
6+
coordinates of mouse clicks to the clipboard.
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
/***************************************************************************
2+
coordinatecapture.cpp
3+
Capture mouse coordinates in different CRS
4+
-------------------
5+
begin : [PluginDate]
6+
copyright : [(C) Your Name and Date]
7+
email : [Your Email]
8+
9+
***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
/* $Id: plugin.cpp 8053 2008-01-26 13:59:53Z timlinux $ */
18+
19+
//
20+
// QGIS Specific includes
21+
//
22+
23+
#include <qgisinterface.h>
24+
#include <qgisgui.h>
25+
#include <qgspoint.h>
26+
#include <qgsmapcanvas.h>
27+
28+
#include "coordinatecapture.h"
29+
#include "coordinatecapturegui.h"
30+
31+
//
32+
// Qt4 Related Includes
33+
//
34+
35+
#include <QAction>
36+
#include <QToolBar>
37+
#include <QDockWidget>
38+
#include <QLayout>
39+
#include <QLineEdit>
40+
#include <QClipboard>
41+
#include <QPushButton>
42+
43+
static const char * const sIdent = "$Id: plugin.cpp 8053 2008-01-26 13:59:53Z timlinux $";
44+
static const QString sName = QObject::tr("Coordinate Capture");
45+
static const QString sDescription = QObject::tr("Capture mouse coordinates in different CRS");
46+
static const QString sPluginVersion = QObject::tr("Version 0.1");
47+
static const QgisPlugin::PLUGINTYPE sPluginType = QgisPlugin::UI;
48+
49+
//////////////////////////////////////////////////////////////////////
50+
//
51+
// THE FOLLOWING METHODS ARE MANDATORY FOR ALL PLUGINS
52+
//
53+
//////////////////////////////////////////////////////////////////////
54+
55+
/**
56+
* Constructor for the plugin. The plugin is passed a pointer
57+
* an interface object that provides access to exposed functions in QGIS.
58+
* @param theQGisInterface - Pointer to the QGIS interface object
59+
*/
60+
CoordinateCapture::CoordinateCapture(QgisInterface * theQgisInterface):
61+
QgisPlugin(sName,sDescription,sPluginVersion,sPluginType),
62+
mQGisIface(theQgisInterface)
63+
{
64+
}
65+
66+
CoordinateCapture::~CoordinateCapture()
67+
{
68+
69+
}
70+
71+
/*
72+
* Initialize the GUI interface for the plugin - this is only called once when the plugin is
73+
* added to the plugin registry in the QGIS application.
74+
*/
75+
void CoordinateCapture::initGui()
76+
{
77+
78+
// Create the action for tool
79+
mQActionPointer = new QAction(QIcon(":/coordinatecapture/coordinatecapture.png"),tr("Coordinate Capture"), this);
80+
// Set the what's this text
81+
mQActionPointer->setWhatsThis(tr("Click on the map to view coordinates and capture to clipboard."));
82+
// Connect the action to the run
83+
connect(mQActionPointer, SIGNAL(triggered()), this, SLOT(run()));
84+
// Add the icon to the toolbar
85+
mQGisIface->addToolBarIcon(mQActionPointer);
86+
mQGisIface->addPluginMenu(tr("&Coordinate Capture"), mQActionPointer);
87+
88+
// create our map tool
89+
mpMapTool = new CoordinateCaptureMapTool(mQGisIface->getMapCanvas());
90+
connect(mpMapTool, SIGNAL(pointCaptured(QgsPoint)), this, SLOT(update(QgsPoint)));
91+
92+
93+
// create a little widget with x and y display to put into our dock widget
94+
QWidget * mypWidget = new QWidget();
95+
QLayout * mypLayout = new QVBoxLayout();
96+
mypWidget->setLayout(mypLayout);
97+
98+
mpXEdit = new QLineEdit(mypWidget);
99+
mpYEdit = new QLineEdit(mypWidget);
100+
QPushButton * mypCopyButton = new QPushButton(mypWidget);
101+
mypCopyButton->setText(tr("Copy to clipboard"));
102+
connect(mypCopyButton, SIGNAL(clicked()), this, SLOT(copy()));
103+
104+
mypLayout->addWidget(mpXEdit);
105+
mypLayout->addWidget(mpYEdit);
106+
mypLayout->addWidget(mypCopyButton);
107+
108+
109+
//create the dock widget
110+
mpDockWidget = new QDockWidget(tr("Coordinate Capture"),mQGisIface->getMainWindow());
111+
mpDockWidget->setObjectName("CoordinateCapture");
112+
mpDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
113+
mQGisIface->addDockWidget(Qt::LeftDockWidgetArea, mpDockWidget);
114+
115+
// now add our custom widget to the dock - ownership of the widget is passed to the dock
116+
mpDockWidget->setWidget(mypWidget);
117+
118+
119+
}
120+
//method defined in interface
121+
void CoordinateCapture::help()
122+
{
123+
//implement me!
124+
}
125+
126+
void CoordinateCapture::update(QgsPoint thePoint)
127+
{
128+
mpXEdit->setText(QString::number( thePoint.x(),'f'));
129+
mpYEdit->setText(QString::number( thePoint.y(),'f'));
130+
}
131+
void CoordinateCapture::copy()
132+
{
133+
QClipboard *myClipboard = QApplication::clipboard();
134+
//if we are on x11 system put text into selection ready for middle button pasting
135+
if (myClipboard->supportsSelection())
136+
{
137+
myClipboard->setText(mpXEdit->text() + "," + mpYEdit->text(),QClipboard::Selection);
138+
//QString myMessage = tr("Clipboard contents set to: ");
139+
//statusBar()->showMessage(myMessage + myClipboard->text(QClipboard::Selection));
140+
}
141+
else
142+
{
143+
//user has an inferior operating system....
144+
myClipboard->setText(mpXEdit->text() + "," + mpYEdit->text(),QClipboard::Clipboard );
145+
//QString myMessage = tr("Clipboard contents set to: ");
146+
//statusBar()->showMessage(myMessage + myClipboard->text(QClipboard::Clipboard));
147+
}
148+
}
149+
150+
151+
// Slot called when the menu item is triggered
152+
// If you created more menu items / toolbar buttons in initiGui, you should
153+
// create a separate handler for each action - this single run() method will
154+
// not be enough
155+
void CoordinateCapture::run()
156+
{
157+
mQGisIface->getMapCanvas()->setMapTool(mpMapTool);
158+
//CoordinateCaptureGui *myPluginGui=new CoordinateCaptureGui(mQGisIface->getMainWindow(), QgisGui::ModalDialogFlags);
159+
//myPluginGui->setAttribute(Qt::WA_DeleteOnClose);
160+
161+
//myPluginGui->show();
162+
}
163+
164+
// Unload the plugin by cleaning up the GUI
165+
void CoordinateCapture::unload()
166+
{
167+
// remove the GUI
168+
mQGisIface->removePluginMenu("&Coordinate Capture",mQActionPointer);
169+
mQGisIface->removeToolBarIcon(mQActionPointer);
170+
mpMapTool->deactivate();
171+
delete mpMapTool;
172+
delete mpDockWidget;
173+
delete mQActionPointer;
174+
}
175+
176+
177+
//////////////////////////////////////////////////////////////////////////
178+
//
179+
//
180+
// THE FOLLOWING CODE IS AUTOGENERATED BY THE PLUGIN BUILDER SCRIPT
181+
// YOU WOULD NORMALLY NOT NEED TO MODIFY THIS, AND YOUR PLUGIN
182+
// MAY NOT WORK PROPERLY IF YOU MODIFY THIS INCORRECTLY
183+
//
184+
//
185+
//////////////////////////////////////////////////////////////////////////
186+
187+
188+
/**
189+
* Required extern functions needed for every plugin
190+
* These functions can be called prior to creating an instance
191+
* of the plugin class
192+
*/
193+
// Class factory to return a new instance of the plugin class
194+
QGISEXTERN QgisPlugin * classFactory(QgisInterface * theQgisInterfacePointer)
195+
{
196+
return new CoordinateCapture(theQgisInterfacePointer);
197+
}
198+
// Return the name of the plugin - note that we do not user class members as
199+
// the class may not yet be insantiated when this method is called.
200+
QGISEXTERN QString name()
201+
{
202+
return sName;
203+
}
204+
205+
// Return the description
206+
QGISEXTERN QString description()
207+
{
208+
return sDescription;
209+
}
210+
211+
// Return the type (either UI or MapLayer plugin)
212+
QGISEXTERN int type()
213+
{
214+
return sPluginType;
215+
}
216+
217+
// Return the version number for the plugin
218+
QGISEXTERN QString version()
219+
{
220+
return sPluginVersion;
221+
}
222+
223+
// Delete ourself
224+
QGISEXTERN void unload(QgisPlugin * thePluginPointer)
225+
{
226+
delete thePluginPointer;
227+
}

0 commit comments

Comments
 (0)