Skip to content

Commit

Permalink
Added capture point plugin to cater for various user requests
Browse files Browse the repository at this point in the history
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 6bc5ab6
Show file tree
Hide file tree
Showing 13 changed files with 874 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/plugins/CMakeLists.txt
Expand Up @@ -20,3 +20,5 @@ INSTALL(FILES qgisplugin.h qgsrendererplugin.h DESTINATION ${QGIS_INCLUDE_DIR})

SUBDIRS (quick_print)


SUBDIRS (coordinate_capture)
51 changes: 51 additions & 0 deletions src/plugins/coordinate_capture/CMakeLists.txt
@@ -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})

6 changes: 6 additions & 0 deletions src/plugins/coordinate_capture/README
@@ -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.
104 changes: 104 additions & 0 deletions src/plugins/coordinate_capture/coordinate_capture.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
227 changes: 227 additions & 0 deletions src/plugins/coordinate_capture/coordinatecapture.cpp
@@ -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.