mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-08 00:06:51 -05:00
Updated renderNorthArrow slot to receive and draw to the qpainter pointer passed by the mapcanvas::renderComplete signal. This allows the north arrow plugin to draw onto the map even when it is being rendered to a device other than the mapCanvas' own pixmap member.
git-svn-id: http://svn.osgeo.org/qgis/trunk@1502 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
f4f5e228ed
commit
c20fc2ecf9
@ -1,5 +1,5 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
plugin.cpp
|
plugin.cpp
|
||||||
Import tool for various worldmap analysis output files
|
Import tool for various worldmap analysis output files
|
||||||
Functions:
|
Functions:
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ email : tim@linfiniti.com
|
|||||||
|
|
||||||
// xpm for creating the toolbar icon
|
// xpm for creating the toolbar icon
|
||||||
#include "icon.xpm"
|
#include "icon.xpm"
|
||||||
//
|
//
|
||||||
static const char * const ident_ = "$Id$";
|
static const char * const ident_ = "$Id$";
|
||||||
|
|
||||||
static const char * const name_ = "NorthArrow";
|
static const char * const name_ = "NorthArrow";
|
||||||
@ -66,9 +66,9 @@ static const QgisPlugin::PLUGINTYPE type_ = QgisPlugin::UI;
|
|||||||
* @param _qI Pointer to the QGIS interface object
|
* @param _qI Pointer to the QGIS interface object
|
||||||
*/
|
*/
|
||||||
Plugin::Plugin(QgisApp * theQGisApp, QgisIface * theQgisInterFace):
|
Plugin::Plugin(QgisApp * theQGisApp, QgisIface * theQgisInterFace):
|
||||||
qgisMainWindowPointer(theQGisApp),
|
qgisMainWindowPointer(theQGisApp),
|
||||||
qGisInterface(theQgisInterFace),
|
qGisInterface(theQgisInterFace),
|
||||||
QgisPlugin(name_,description_,version_,type_)
|
QgisPlugin(name_,description_,version_,type_)
|
||||||
{
|
{
|
||||||
mRotationInt=0;
|
mRotationInt=0;
|
||||||
mPlacement=tr("Bottom Left");
|
mPlacement=tr("Bottom Left");
|
||||||
@ -76,11 +76,10 @@ QgisPlugin(name_,description_,version_,type_)
|
|||||||
|
|
||||||
Plugin::~Plugin()
|
Plugin::~Plugin()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the GUI interface for the plugin
|
* Initialize the GUI interface for the plugin
|
||||||
*/
|
*/
|
||||||
void Plugin::initGui()
|
void Plugin::initGui()
|
||||||
{
|
{
|
||||||
@ -97,7 +96,7 @@ void Plugin::initGui()
|
|||||||
// Connect the action to the run
|
// Connect the action to the run
|
||||||
connect(myQActionPointer, SIGNAL(activated()), this, SLOT(run()));
|
connect(myQActionPointer, SIGNAL(activated()), this, SLOT(run()));
|
||||||
//render the arrow each time the map is rendered
|
//render the arrow each time the map is rendered
|
||||||
connect(qGisInterface->getMapCanvas(), SIGNAL(renderComplete()), this, SLOT(renderNorthArrow()));
|
connect(qGisInterface->getMapCanvas(), SIGNAL(renderComplete(QPainter *)), this, SLOT(renderNorthArrow(QPainter *)));
|
||||||
// Add the toolbar
|
// Add the toolbar
|
||||||
toolBarPointer = new QToolBar((QMainWindow *) qgisMainWindowPointer, "Decorations");
|
toolBarPointer = new QToolBar((QMainWindow *) qgisMainWindowPointer, "Decorations");
|
||||||
toolBarPointer->setLabel("North Arrow");
|
toolBarPointer->setLabel("North Arrow");
|
||||||
@ -134,92 +133,86 @@ void Plugin::refreshCanvas()
|
|||||||
qGisInterface->getMapCanvas()->refresh();
|
qGisInterface->getMapCanvas()->refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plugin::renderNorthArrow()
|
void Plugin::renderNorthArrow(QPainter * theQPainter)
|
||||||
{
|
{
|
||||||
|
#ifdef QGISDEBUG
|
||||||
//Large IF statement controlled by enable check box
|
std::cout << "Rendering n-arrow" << std::endl;
|
||||||
if (mEnable)
|
#endif
|
||||||
{
|
//Large IF statement controlled by enable check box
|
||||||
QPixmap myQPixmap; //to store the north arrow image in
|
if (mEnable)
|
||||||
QString myFileNameQString = QString(PKGDATAPATH) +
|
|
||||||
QString("/images/north_arrows/default.png");
|
|
||||||
//std::cout << "Trying to load " << myFileNameQString << std::cout;
|
|
||||||
if (myQPixmap.load(myFileNameQString))
|
|
||||||
{
|
{
|
||||||
// myPainterPixmap.fill();
|
QPixmap myQPixmap; //to store the north arrow image in
|
||||||
QPainter myQPainter;
|
QString myFileNameQString = QString(PKGDATAPATH) +
|
||||||
myQPainter.begin(qGisInterface->getMapCanvas()->canvasPixmap());
|
QString("/images/north_arrows/default.png");
|
||||||
|
//std::cout << "Trying to load " << myFileNameQString << std::cout;
|
||||||
|
if (myQPixmap.load(myFileNameQString))
|
||||||
|
{
|
||||||
|
|
||||||
double centerXDouble = myQPixmap.width()/2;
|
double centerXDouble = myQPixmap.width()/2;
|
||||||
double centerYDouble = myQPixmap.height()/2;
|
double centerYDouble = myQPixmap.height()/2;
|
||||||
//save the current canvas rotation
|
//save the current canvas rotation
|
||||||
myQPainter.save();
|
theQPainter->save();
|
||||||
//
|
//
|
||||||
//work out how to shift the image so that it rotates
|
//work out how to shift the image so that it rotates
|
||||||
// properly about its center
|
// properly about its center
|
||||||
//(x cos a + y sin a - x, -x sin a + y cos a - y)
|
//(x cos a + y sin a - x, -x sin a + y cos a - y)
|
||||||
//
|
//
|
||||||
const double PI = 3.14159265358979323846;
|
const double PI = 3.14159265358979323846;
|
||||||
double myRadiansDouble = (PI/180) * mRotationInt;
|
double myRadiansDouble = (PI/180) * mRotationInt;
|
||||||
int xShift = static_cast<int>((
|
int xShift = static_cast<int>((
|
||||||
(centerXDouble * cos(myRadiansDouble)) +
|
(centerXDouble * cos(myRadiansDouble)) +
|
||||||
(centerYDouble * sin(myRadiansDouble))
|
(centerYDouble * sin(myRadiansDouble))
|
||||||
) - centerXDouble);
|
) - centerXDouble);
|
||||||
int yShift = static_cast<int>((
|
int yShift = static_cast<int>((
|
||||||
(-centerXDouble * sin(myRadiansDouble)) +
|
(-centerXDouble * sin(myRadiansDouble)) +
|
||||||
(centerYDouble * cos(myRadiansDouble))
|
(centerYDouble * cos(myRadiansDouble))
|
||||||
) - centerYDouble);
|
) - centerYDouble);
|
||||||
|
|
||||||
//Get canvas dimensions
|
//Get canvas dimensions
|
||||||
int myHeight = qGisInterface->getMapCanvas()->height();
|
int myHeight = qGisInterface->getMapCanvas()->height();
|
||||||
int myWidth = qGisInterface->getMapCanvas()->width();
|
int myWidth = qGisInterface->getMapCanvas()->width();
|
||||||
|
|
||||||
#ifdef QGISDEBUG
|
#ifdef QGISDEBUG
|
||||||
std::cout << "Rendering n-arrow at " << mPlacement << std::endl;
|
std::cout << "Rendering n-arrow at " << mPlacement << std::endl;
|
||||||
#endif
|
#endif
|
||||||
//Determine placement of label from form combo box
|
//Determine placement of label from form combo box
|
||||||
if (mPlacement==tr("Bottom Left"))
|
if (mPlacement==tr("Bottom Left"))
|
||||||
{
|
{
|
||||||
myQPainter.translate(0,myHeight-myQPixmap.height());
|
theQPainter->translate(0,myHeight-myQPixmap.height());
|
||||||
}
|
}
|
||||||
else if (mPlacement==tr("Top Right"))
|
else if (mPlacement==tr("Top Right"))
|
||||||
{
|
{
|
||||||
myQPainter.translate(myWidth-myQPixmap.width(),0);
|
theQPainter->translate(myWidth-myQPixmap.width(),0);
|
||||||
}
|
}
|
||||||
else if (mPlacement==tr("Bottom Right"))
|
else if (mPlacement==tr("Bottom Right"))
|
||||||
{
|
{
|
||||||
myQPainter.translate(myWidth-myQPixmap.width(),
|
theQPainter->translate(myWidth-myQPixmap.width(),
|
||||||
myHeight-myQPixmap.height());
|
myHeight-myQPixmap.height());
|
||||||
}
|
}
|
||||||
else // defaulting to top left
|
else // defaulting to top left
|
||||||
{
|
{
|
||||||
//no need to translate for TL corner because we're already at the origin
|
//no need to translate for TL corner because we're already at the origin
|
||||||
myQPainter.translate(0, 0);
|
theQPainter->translate(0, 0);
|
||||||
}
|
}
|
||||||
//rotate the canvas by the north arrow rotation amount
|
//rotate the canvas by the north arrow rotation amount
|
||||||
myQPainter.rotate( mRotationInt );
|
theQPainter->rotate( mRotationInt );
|
||||||
//Now we can actually do the drawing
|
//Now we can actually do the drawing
|
||||||
myQPainter.drawPixmap(xShift,yShift,myQPixmap);
|
theQPainter->drawPixmap(xShift,yShift,myQPixmap);
|
||||||
|
|
||||||
//unrotate the canvase again
|
//unrotate the canvase again
|
||||||
myQPainter.restore();
|
theQPainter->restore();
|
||||||
myQPainter.end();
|
|
||||||
|
|
||||||
//bitBlt ( qGisInterface->getMapCanvas()->canvasPixmap(), 0, 0, &myPainterPixmap, 0, 0, -1 , -1, Qt::CopyROP, false);
|
//bitBlt ( qGisInterface->getMapCanvas()->canvasPixmap(), 0, 0, &myPainterPixmap, 0, 0, -1 , -1, Qt::CopyROP, false);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QFont myQFont("time", 32, QFont::Bold);
|
||||||
|
theQPainter->setFont(myQFont);
|
||||||
|
theQPainter->setPen(Qt::black);
|
||||||
|
theQPainter->drawText(10, 20, QString("Pixmap Not Found"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
//myPainterPixmap.fill();
|
|
||||||
QPainter myQPainter;
|
|
||||||
myQPainter.begin(qGisInterface->getMapCanvas()->canvasPixmap());
|
|
||||||
QFont myQFont("time", 32, QFont::Bold);
|
|
||||||
myQPainter.setFont(myQFont);
|
|
||||||
myQPainter.setPen(Qt::black);
|
|
||||||
myQPainter.drawText(10, 20, QString("Pixmap Not Found"));
|
|
||||||
myQPainter.end();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// Unload the plugin by cleaning up the GUI
|
// Unload the plugin by cleaning up the GUI
|
||||||
@ -255,8 +248,8 @@ void Plugin::setEnabled(bool theBool)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Required extern functions needed for every plugin
|
* Required extern functions needed for every plugin
|
||||||
* These functions can be called prior to creating an instance
|
* These functions can be called prior to creating an instance
|
||||||
* of the plugin class
|
* of the plugin class
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
plugin.h
|
plugin.h
|
||||||
Functions:
|
Functions:
|
||||||
-------------------
|
-------------------
|
||||||
begin : Jan 21, 2004
|
begin : Jan 21, 2004
|
||||||
copyright : (C) 2004 by Tim Sutton
|
copyright : (C) 2004 by Tim Sutton
|
||||||
email : tim@linfiniti.com
|
email : tim@linfiniti.com
|
||||||
|
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
@ -21,6 +21,8 @@
|
|||||||
#define PLUGIN
|
#define PLUGIN
|
||||||
#include "../qgisplugin.h"
|
#include "../qgisplugin.h"
|
||||||
#include <qwidget.h>
|
#include <qwidget.h>
|
||||||
|
#include <qpainter.h>
|
||||||
|
|
||||||
|
|
||||||
#include "../../src/qgisapp.h"
|
#include "../../src/qgisapp.h"
|
||||||
|
|
||||||
@ -32,11 +34,11 @@
|
|||||||
class Plugin:public QObject, public QgisPlugin
|
class Plugin:public QObject, public QgisPlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT public:
|
Q_OBJECT public:
|
||||||
/**
|
/**
|
||||||
* Constructor for a plugin. The QgisApp and QgisIface pointers are passed by
|
* Constructor for a plugin. The QgisApp and QgisIface pointers are passed by
|
||||||
* QGIS when it attempts to instantiate the plugin.
|
* QGIS when it attempts to instantiate the plugin.
|
||||||
* @param qgis Pointer to the QgisApp object
|
* @param qgis Pointer to the QgisApp object
|
||||||
* @param qI Pointer to the QgisIface object.
|
* @param qI Pointer to the QgisIface object.
|
||||||
*/
|
*/
|
||||||
Plugin(QgisApp * , QgisIface * );
|
Plugin(QgisApp * , QgisIface * );
|
||||||
//! init the gui
|
//! init the gui
|
||||||
@ -47,7 +49,7 @@ class Plugin:public QObject, public QgisPlugin
|
|||||||
//! Show the dialog box
|
//! Show the dialog box
|
||||||
void run();
|
void run();
|
||||||
// draw some arbitary text to the screen
|
// draw some arbitary text to the screen
|
||||||
void renderNorthArrow();
|
void renderNorthArrow(QPainter *);
|
||||||
//! Run when the user has set a new rotation
|
//! Run when the user has set a new rotation
|
||||||
void rotationChanged(int);
|
void rotationChanged(int);
|
||||||
//! Refresh the map display using the mapcanvas exported via the plugin interface
|
//! Refresh the map display using the mapcanvas exported via the plugin interface
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user