Skip to content
Permalink
Browse files
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
  • Loading branch information
timlinux committed Aug 6, 2008
1 parent fb67488 commit 6bc5ab6aed4d49353482c43c4a3b3bfb4337d39f
@@ -20,3 +20,5 @@ INSTALL(FILES qgisplugin.h qgsrendererplugin.h DESTINATION ${QGIS_INCLUDE_DIR})

SUBDIRS (quick_print)


SUBDIRS (coordinate_capture)
@@ -0,0 +1,51 @@

########################################################
# Files

SET (coordinatecapture_SRCS
coordinatecapture.cpp
coordinatecapturegui.cpp
coordinatecapturemaptool.cpp
)

SET (coordinatecapture_UIS coordinatecaptureguibase.ui)

SET (coordinatecapture_MOC_HDRS
coordinatecapture.h
coordinatecapturegui.h
coordinatecapturemaptool.h
)

SET (coordinatecapture_RCCS coordinatecapture.qrc)

########################################################
# Build

QT4_WRAP_UI (coordinatecapture_UIS_H ${coordinatecapture_UIS})

QT4_WRAP_CPP (coordinatecapture_MOC_SRCS ${coordinatecapture_MOC_HDRS})

QT4_ADD_RESOURCES(coordinatecapture_RCC_SRCS ${coordinatecapture_RCCS})

ADD_LIBRARY (coordinatecaptureplugin MODULE ${coordinatecapture_SRCS} ${coordinatecapture_MOC_SRCS} ${coordinatecapture_RCC_SRCS} ${coordinatecapture_UIS_H})

INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
../../core ../../core/raster ../../core/renderer ../../core/symbology
../../gui
..
)

TARGET_LINK_LIBRARIES(coordinatecaptureplugin
qgis_core
qgis_gui
)


########################################################
# Install

INSTALL(TARGETS coordinatecaptureplugin
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})

@@ -0,0 +1,6 @@
Coordinate Capture Plugin for Quantum GIS

Tim Sutton 2008

A simple plugin that allows you to copy the
coordinates of mouse clicks to the clipboard.
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="32"
height="32"
id="svg2"
sodipodi:version="0.32"
inkscape:version="0.46"
version="1.0"
sodipodi:docname="coordinate_capture.svg"
inkscape:output_extension="org.inkscape.output.svg.inkscape">
<defs
id="defs4">
<marker
inkscape:stockid="Arrow1Lend"
orient="auto"
refY="0.0"
refX="0.0"
id="Arrow1Lend"
style="overflow:visible;">
<path
id="path3161"
d="M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z "
style="fill-rule:evenodd;stroke:#000000;stroke-width:1.0pt;marker-start:none;"
transform="scale(0.8) rotate(180) translate(12.5,0)" />
</marker>
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 526.18109 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="744.09448 : 526.18109 : 1"
inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
id="perspective10" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
gridtolerance="10000"
guidetolerance="10"
objecttolerance="10"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="25"
inkscape:cx="9.06"
inkscape:cy="16"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1680"
inkscape:window-height="986"
inkscape:window-x="0"
inkscape:window-y="0" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<path
sodipodi:type="arc"
style="opacity:0.92642139999999995;fill:#171717;fill-opacity:0.90980392000000021;fill-rule:nonzero;stroke:#409fcc;stroke-width:0.69999999000000002;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="path3939"
sodipodi:cx="16.879999"
sodipodi:cy="15.5"
sodipodi:rx="7.1599998"
sodipodi:ry="6.6599998"
d="M 24.039999,15.5 A 7.1599998,6.6599998 0 1 1 9.7199993,15.5 A 7.1599998,6.6599998 0 1 1 24.039999,15.5 z"
transform="translate(-0.52,0)" />
<path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.83856803px;stroke-linecap:butt;stroke-linejoin:miter;marker-end:url(#Arrow1Lend);stroke-opacity:1"
d="M 16.280361,5.9152738 L 16.361976,13.800716"
id="path2383" />
<path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.83856803px;stroke-linecap:butt;stroke-linejoin:miter;marker-end:url(#Arrow1Lend);stroke-opacity:1"
d="M 16.319888,25.918422 L 16.401503,18.03298"
id="path3933" />
<path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.83856803px;stroke-linecap:butt;stroke-linejoin:miter;marker-end:url(#Arrow1Lend);stroke-opacity:1"
d="M 26.318423,15.839888 L 18.432981,15.921503"
id="path3935" />
<path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.83856803px;stroke-linecap:butt;stroke-linejoin:miter;marker-end:url(#Arrow1Lend);stroke-opacity:1"
d="M 6.2815774,16.120112 L 14.167019,16.038497"
id="path3937" />
</g>
</svg>
@@ -0,0 +1,227 @@
/***************************************************************************
coordinatecapture.cpp
Capture mouse coordinates in different CRS
-------------------
begin : [PluginDate]
copyright : [(C) Your Name and Date]
email : [Your Email]
***************************************************************************
* *
* 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. *
* *
***************************************************************************/
/* $Id: plugin.cpp 8053 2008-01-26 13:59:53Z timlinux $ */

//
// QGIS Specific includes
//

#include <qgisinterface.h>
#include <qgisgui.h>
#include <qgspoint.h>
#include <qgsmapcanvas.h>

#include "coordinatecapture.h"
#include "coordinatecapturegui.h"

//
// Qt4 Related Includes
//

#include <QAction>
#include <QToolBar>
#include <QDockWidget>
#include <QLayout>
#include <QLineEdit>
#include <QClipboard>
#include <QPushButton>

static const char * const sIdent = "$Id: plugin.cpp 8053 2008-01-26 13:59:53Z timlinux $";
static const QString sName = QObject::tr("Coordinate Capture");
static const QString sDescription = QObject::tr("Capture mouse coordinates in different CRS");
static const QString sPluginVersion = QObject::tr("Version 0.1");
static const QgisPlugin::PLUGINTYPE sPluginType = QgisPlugin::UI;

//////////////////////////////////////////////////////////////////////
//
// THE FOLLOWING METHODS ARE MANDATORY FOR ALL PLUGINS
//
//////////////////////////////////////////////////////////////////////

/**
* Constructor for the plugin. The plugin is passed a pointer
* an interface object that provides access to exposed functions in QGIS.
* @param theQGisInterface - Pointer to the QGIS interface object
*/
CoordinateCapture::CoordinateCapture(QgisInterface * theQgisInterface):
QgisPlugin(sName,sDescription,sPluginVersion,sPluginType),
mQGisIface(theQgisInterface)
{
}

CoordinateCapture::~CoordinateCapture()
{

}

/*
* Initialize the GUI interface for the plugin - this is only called once when the plugin is
* added to the plugin registry in the QGIS application.
*/
void CoordinateCapture::initGui()
{

// Create the action for tool
mQActionPointer = new QAction(QIcon(":/coordinatecapture/coordinatecapture.png"),tr("Coordinate Capture"), this);
// Set the what's this text
mQActionPointer->setWhatsThis(tr("Click on the map to view coordinates and capture to clipboard."));
// Connect the action to the run
connect(mQActionPointer, SIGNAL(triggered()), this, SLOT(run()));
// Add the icon to the toolbar
mQGisIface->addToolBarIcon(mQActionPointer);
mQGisIface->addPluginMenu(tr("&Coordinate Capture"), mQActionPointer);

// create our map tool
mpMapTool = new CoordinateCaptureMapTool(mQGisIface->getMapCanvas());
connect(mpMapTool, SIGNAL(pointCaptured(QgsPoint)), this, SLOT(update(QgsPoint)));


// create a little widget with x and y display to put into our dock widget
QWidget * mypWidget = new QWidget();
QLayout * mypLayout = new QVBoxLayout();
mypWidget->setLayout(mypLayout);

mpXEdit = new QLineEdit(mypWidget);
mpYEdit = new QLineEdit(mypWidget);
QPushButton * mypCopyButton = new QPushButton(mypWidget);
mypCopyButton->setText(tr("Copy to clipboard"));
connect(mypCopyButton, SIGNAL(clicked()), this, SLOT(copy()));

mypLayout->addWidget(mpXEdit);
mypLayout->addWidget(mpYEdit);
mypLayout->addWidget(mypCopyButton);


//create the dock widget
mpDockWidget = new QDockWidget(tr("Coordinate Capture"),mQGisIface->getMainWindow());
mpDockWidget->setObjectName("CoordinateCapture");
mpDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
mQGisIface->addDockWidget(Qt::LeftDockWidgetArea, mpDockWidget);

// now add our custom widget to the dock - ownership of the widget is passed to the dock
mpDockWidget->setWidget(mypWidget);


}
//method defined in interface
void CoordinateCapture::help()
{
//implement me!
}

void CoordinateCapture::update(QgsPoint thePoint)
{
mpXEdit->setText(QString::number( thePoint.x(),'f'));
mpYEdit->setText(QString::number( thePoint.y(),'f'));
}
void CoordinateCapture::copy()
{
QClipboard *myClipboard = QApplication::clipboard();
//if we are on x11 system put text into selection ready for middle button pasting
if (myClipboard->supportsSelection())
{
myClipboard->setText(mpXEdit->text() + "," + mpYEdit->text(),QClipboard::Selection);
//QString myMessage = tr("Clipboard contents set to: ");
//statusBar()->showMessage(myMessage + myClipboard->text(QClipboard::Selection));
}
else
{
//user has an inferior operating system....
myClipboard->setText(mpXEdit->text() + "," + mpYEdit->text(),QClipboard::Clipboard );
//QString myMessage = tr("Clipboard contents set to: ");
//statusBar()->showMessage(myMessage + myClipboard->text(QClipboard::Clipboard));
}
}


// Slot called when the menu item is triggered
// If you created more menu items / toolbar buttons in initiGui, you should
// create a separate handler for each action - this single run() method will
// not be enough
void CoordinateCapture::run()
{
mQGisIface->getMapCanvas()->setMapTool(mpMapTool);
//CoordinateCaptureGui *myPluginGui=new CoordinateCaptureGui(mQGisIface->getMainWindow(), QgisGui::ModalDialogFlags);
//myPluginGui->setAttribute(Qt::WA_DeleteOnClose);

//myPluginGui->show();
}

// Unload the plugin by cleaning up the GUI
void CoordinateCapture::unload()
{
// remove the GUI
mQGisIface->removePluginMenu("&Coordinate Capture",mQActionPointer);
mQGisIface->removeToolBarIcon(mQActionPointer);
mpMapTool->deactivate();
delete mpMapTool;
delete mpDockWidget;
delete mQActionPointer;
}


//////////////////////////////////////////////////////////////////////////
//
//
// 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
//
//
//////////////////////////////////////////////////////////////////////////


/**
* Required extern functions needed for every plugin
* These functions can be called prior to creating an instance
* of the plugin class
*/
// Class factory to return a new instance of the plugin class
QGISEXTERN QgisPlugin * classFactory(QgisInterface * theQgisInterfacePointer)
{
return new CoordinateCapture(theQgisInterfacePointer);
}
// Return the name of the plugin - note that we do not user class members as
// the class may not yet be insantiated when this method is called.
QGISEXTERN QString name()
{
return sName;
}

// Return the description
QGISEXTERN QString description()
{
return sDescription;
}

// Return the type (either UI or MapLayer plugin)
QGISEXTERN int type()
{
return sPluginType;
}

// Return the version number for the plugin
QGISEXTERN QString version()
{
return sPluginVersion;
}

// Delete ourself
QGISEXTERN void unload(QgisPlugin * thePluginPointer)
{
delete thePluginPointer;
}

0 comments on commit 6bc5ab6

Please sign in to comment.