mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-06 00:03:16 -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
@ -76,7 +76,6 @@ QgisPlugin(name_,description_,version_,type_)
|
||||
|
||||
Plugin::~Plugin()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@ -97,7 +96,7 @@ void Plugin::initGui()
|
||||
// Connect the action to the run
|
||||
connect(myQActionPointer, SIGNAL(activated()), this, SLOT(run()));
|
||||
//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
|
||||
toolBarPointer = new QToolBar((QMainWindow *) qgisMainWindowPointer, "Decorations");
|
||||
toolBarPointer->setLabel("North Arrow");
|
||||
@ -134,9 +133,11 @@ void Plugin::refreshCanvas()
|
||||
qGisInterface->getMapCanvas()->refresh();
|
||||
}
|
||||
|
||||
void Plugin::renderNorthArrow()
|
||||
void Plugin::renderNorthArrow(QPainter * theQPainter)
|
||||
{
|
||||
|
||||
#ifdef QGISDEBUG
|
||||
std::cout << "Rendering n-arrow" << std::endl;
|
||||
#endif
|
||||
//Large IF statement controlled by enable check box
|
||||
if (mEnable)
|
||||
{
|
||||
@ -146,14 +147,11 @@ if (mEnable)
|
||||
//std::cout << "Trying to load " << myFileNameQString << std::cout;
|
||||
if (myQPixmap.load(myFileNameQString))
|
||||
{
|
||||
// myPainterPixmap.fill();
|
||||
QPainter myQPainter;
|
||||
myQPainter.begin(qGisInterface->getMapCanvas()->canvasPixmap());
|
||||
|
||||
double centerXDouble = myQPixmap.width()/2;
|
||||
double centerYDouble = myQPixmap.height()/2;
|
||||
//save the current canvas rotation
|
||||
myQPainter.save();
|
||||
theQPainter->save();
|
||||
//
|
||||
//work out how to shift the image so that it rotates
|
||||
// properly about its center
|
||||
@ -180,44 +178,39 @@ if (mEnable)
|
||||
//Determine placement of label from form combo box
|
||||
if (mPlacement==tr("Bottom Left"))
|
||||
{
|
||||
myQPainter.translate(0,myHeight-myQPixmap.height());
|
||||
theQPainter->translate(0,myHeight-myQPixmap.height());
|
||||
}
|
||||
else if (mPlacement==tr("Top Right"))
|
||||
{
|
||||
myQPainter.translate(myWidth-myQPixmap.width(),0);
|
||||
theQPainter->translate(myWidth-myQPixmap.width(),0);
|
||||
}
|
||||
else if (mPlacement==tr("Bottom Right"))
|
||||
{
|
||||
myQPainter.translate(myWidth-myQPixmap.width(),
|
||||
theQPainter->translate(myWidth-myQPixmap.width(),
|
||||
myHeight-myQPixmap.height());
|
||||
}
|
||||
else // defaulting to top left
|
||||
{
|
||||
//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
|
||||
myQPainter.rotate( mRotationInt );
|
||||
theQPainter->rotate( mRotationInt );
|
||||
//Now we can actually do the drawing
|
||||
myQPainter.drawPixmap(xShift,yShift,myQPixmap);
|
||||
theQPainter->drawPixmap(xShift,yShift,myQPixmap);
|
||||
|
||||
//unrotate the canvase again
|
||||
myQPainter.restore();
|
||||
myQPainter.end();
|
||||
theQPainter->restore();
|
||||
|
||||
//bitBlt ( qGisInterface->getMapCanvas()->canvasPixmap(), 0, 0, &myPainterPixmap, 0, 0, -1 , -1, Qt::CopyROP, false);
|
||||
|
||||
}
|
||||
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();
|
||||
theQPainter->setFont(myQFont);
|
||||
theQPainter->setPen(Qt::black);
|
||||
theQPainter->drawText(10, 20, QString("Pixmap Not Found"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -21,6 +21,8 @@
|
||||
#define PLUGIN
|
||||
#include "../qgisplugin.h"
|
||||
#include <qwidget.h>
|
||||
#include <qpainter.h>
|
||||
|
||||
|
||||
#include "../../src/qgisapp.h"
|
||||
|
||||
@ -47,7 +49,7 @@ class Plugin:public QObject, public QgisPlugin
|
||||
//! Show the dialog box
|
||||
void run();
|
||||
// draw some arbitary text to the screen
|
||||
void renderNorthArrow();
|
||||
void renderNorthArrow(QPainter *);
|
||||
//! Run when the user has set a new rotation
|
||||
void rotationChanged(int);
|
||||
//! Refresh the map display using the mapcanvas exported via the plugin interface
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user