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
@ -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,7 +76,6 @@ QgisPlugin(name_,description_,version_,type_)
|
|||||||
|
|
||||||
Plugin::~Plugin()
|
Plugin::~Plugin()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -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,26 +133,25 @@ void Plugin::refreshCanvas()
|
|||||||
qGisInterface->getMapCanvas()->refresh();
|
qGisInterface->getMapCanvas()->refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plugin::renderNorthArrow()
|
void Plugin::renderNorthArrow(QPainter * theQPainter)
|
||||||
{
|
|
||||||
|
|
||||||
//Large IF statement controlled by enable check box
|
|
||||||
if (mEnable)
|
|
||||||
{
|
{
|
||||||
|
#ifdef QGISDEBUG
|
||||||
|
std::cout << "Rendering n-arrow" << std::endl;
|
||||||
|
#endif
|
||||||
|
//Large IF statement controlled by enable check box
|
||||||
|
if (mEnable)
|
||||||
|
{
|
||||||
QPixmap myQPixmap; //to store the north arrow image in
|
QPixmap myQPixmap; //to store the north arrow image in
|
||||||
QString myFileNameQString = QString(PKGDATAPATH) +
|
QString myFileNameQString = QString(PKGDATAPATH) +
|
||||||
QString("/images/north_arrows/default.png");
|
QString("/images/north_arrows/default.png");
|
||||||
//std::cout << "Trying to load " << myFileNameQString << std::cout;
|
//std::cout << "Trying to load " << myFileNameQString << std::cout;
|
||||||
if (myQPixmap.load(myFileNameQString))
|
if (myQPixmap.load(myFileNameQString))
|
||||||
{
|
{
|
||||||
// myPainterPixmap.fill();
|
|
||||||
QPainter myQPainter;
|
|
||||||
myQPainter.begin(qGisInterface->getMapCanvas()->canvasPixmap());
|
|
||||||
|
|
||||||
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
|
||||||
@ -180,46 +178,41 @@ if (mEnable)
|
|||||||
//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
|
else
|
||||||
{
|
{
|
||||||
//myPainterPixmap.fill();
|
|
||||||
QPainter myQPainter;
|
|
||||||
myQPainter.begin(qGisInterface->getMapCanvas()->canvasPixmap());
|
|
||||||
QFont myQFont("time", 32, QFont::Bold);
|
QFont myQFont("time", 32, QFont::Bold);
|
||||||
myQPainter.setFont(myQFont);
|
theQPainter->setFont(myQFont);
|
||||||
myQPainter.setPen(Qt::black);
|
theQPainter->setPen(Qt::black);
|
||||||
myQPainter.drawText(10, 20, QString("Pixmap Not Found"));
|
theQPainter->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
|
||||||
|
|||||||
@ -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"
|
||||||
|
|
||||||
@ -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