2004-06-09 16:03:02 +00:00
|
|
|
/***************************************************************************
|
|
|
|
plugin.cpp
|
|
|
|
Plugin to draw scale bar on map
|
|
|
|
Functions:
|
|
|
|
|
|
|
|
-------------------
|
|
|
|
begin : Jun 1, 2004
|
|
|
|
copyright : (C) 2004 by Peter Brewer
|
|
|
|
email : sbr00pwb@users.sourceforge.net
|
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* *
|
|
|
|
* 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$ */
|
|
|
|
|
|
|
|
// includes
|
|
|
|
|
|
|
|
#include <qgisapp.h>
|
|
|
|
#include <qgsmaplayer.h>
|
|
|
|
#include <qgsrasterlayer.h>
|
|
|
|
#include "plugin.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <qtoolbar.h>
|
|
|
|
#include <qmenubar.h>
|
|
|
|
#include <qmessagebox.h>
|
|
|
|
#include <qpopupmenu.h>
|
|
|
|
#include <qlineedit.h>
|
|
|
|
#include <qaction.h>
|
|
|
|
#include <qapplication.h>
|
|
|
|
#include <qcursor.h>
|
|
|
|
#include <qpen.h>
|
|
|
|
#include <qgspoint.h>
|
|
|
|
#include <qpointarray.h>
|
|
|
|
#include <qgscoordinatetransform.h>
|
|
|
|
#include <qstring.h>
|
|
|
|
#include <qfontmetrics.h>
|
|
|
|
#include <qfont.h>
|
|
|
|
#include <qpaintdevicemetrics.h>
|
|
|
|
#include <qspinbox.h>
|
2004-06-10 15:41:40 +00:00
|
|
|
#include <qcolor.h>
|
|
|
|
#include <qcolordialog.h>
|
2004-06-09 16:03:02 +00:00
|
|
|
|
|
|
|
//non qt includes
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
//the gui subclass
|
|
|
|
#include "plugingui.h"
|
|
|
|
|
|
|
|
// xpm for creating the toolbar icon
|
|
|
|
#include "icon.xpm"
|
|
|
|
//
|
2004-06-14 04:35:20 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
#define QGISEXTERN extern "C" __declspec( dllexport )
|
|
|
|
#else
|
|
|
|
#define QGISEXTERN extern "C"
|
|
|
|
#endif
|
|
|
|
|
2004-06-09 16:03:02 +00:00
|
|
|
static const char * const ident_ = "$Id$";
|
|
|
|
|
|
|
|
static const char * const name_ = "ScaleBar";
|
|
|
|
static const char * const description_ = "Plugin to draw scale bar on map";
|
|
|
|
static const char * const version_ = "Version 0.1";
|
|
|
|
static const QgisPlugin::PLUGINTYPE type_ = QgisPlugin::UI;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor for the plugin. The plugin is passed a pointer to the main app
|
|
|
|
* and an interface object that provides access to exposed functions in QGIS.
|
|
|
|
* @param qgis Pointer to the QGIS main window
|
|
|
|
* @param _qI Pointer to the QGIS interface object
|
|
|
|
*/
|
|
|
|
Plugin::Plugin(QgisApp * theQGisApp, QgisIface * theQgisInterFace):
|
2004-06-19 12:36:16 +00:00
|
|
|
qgisMainWindowPointer(theQGisApp),
|
|
|
|
qGisInterface(theQgisInterFace),
|
|
|
|
QgisPlugin(name_,description_,version_,type_)
|
2004-06-09 16:03:02 +00:00
|
|
|
{
|
|
|
|
mPreferredSize = 100;
|
|
|
|
mPlacement = "Top Left";
|
|
|
|
mStyle = "Tick Down";
|
|
|
|
}
|
|
|
|
|
|
|
|
Plugin::~Plugin()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the GUI interface for the plugin
|
|
|
|
*/
|
|
|
|
void Plugin::initGui()
|
|
|
|
{
|
|
|
|
// add a menu with 2 items
|
|
|
|
QPopupMenu *pluginMenu = new QPopupMenu(qgisMainWindowPointer);
|
|
|
|
|
|
|
|
pluginMenu->insertItem(QIconSet(icon),"&ScaleBar", this, SLOT(run()));
|
|
|
|
|
|
|
|
menuBarPointer = ((QMainWindow *) qgisMainWindowPointer)->menuBar();
|
|
|
|
|
|
|
|
menuIdInt = qGisInterface->addMenu("&Scale Bar", pluginMenu);
|
|
|
|
// Create the action for tool
|
|
|
|
QAction *myQActionPointer = new QAction("Scale Bar", QIconSet(icon), "&Wmi",0, this, "run");
|
|
|
|
// Connect the action to the run
|
|
|
|
connect(myQActionPointer, SIGNAL(activated()), this, SLOT(run()));
|
|
|
|
//render the scale bar each time the map is rendered
|
|
|
|
connect(qGisInterface->getMapCanvas(), SIGNAL(renderComplete(QPainter *)), this, SLOT(renderScaleBar(QPainter *)));
|
|
|
|
// Add the toolbar
|
|
|
|
toolBarPointer = new QToolBar((QMainWindow *) qgisMainWindowPointer, "Scale Bar");
|
|
|
|
toolBarPointer->setLabel("Scale Bar");
|
|
|
|
// Add the zoom previous tool to the toolbar
|
|
|
|
myQActionPointer->addTo(toolBarPointer);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//method defined in interface
|
|
|
|
void Plugin::help()
|
|
|
|
{
|
|
|
|
//implement me!
|
|
|
|
}
|
|
|
|
|
2004-06-19 15:44:02 +00:00
|
|
|
// Slot called when the menu item is activated
|
2004-06-09 16:03:02 +00:00
|
|
|
void Plugin::run()
|
|
|
|
{
|
|
|
|
PluginGui *myPluginGui=new PluginGui(qgisMainWindowPointer,"Scale Bar",true,0);
|
|
|
|
myPluginGui->setPreferredSize(mPreferredSize);
|
2004-06-18 15:06:55 +00:00
|
|
|
myPluginGui->setSnapping(mSnapping);
|
2004-06-09 16:03:02 +00:00
|
|
|
myPluginGui->setPlacement(mPlacement);
|
|
|
|
myPluginGui->setEnabled(mEnabled);
|
|
|
|
myPluginGui->setStyle(mStyle);
|
2004-06-10 15:41:40 +00:00
|
|
|
myPluginGui->setColour(mColour);
|
2004-06-09 16:03:02 +00:00
|
|
|
connect(myPluginGui, SIGNAL(changePreferredSize(int)), this, SLOT(setPreferredSize(int)));
|
2004-06-18 15:06:55 +00:00
|
|
|
connect(myPluginGui, SIGNAL(changeSnapping(bool)), this, SLOT(setSnapping(bool)));
|
2004-06-09 16:03:02 +00:00
|
|
|
connect(myPluginGui, SIGNAL(changePlacement(QString)), this, SLOT(setPlacement(QString)));
|
|
|
|
connect(myPluginGui, SIGNAL(changeEnabled(bool)), this, SLOT(setEnabled(bool)));
|
|
|
|
connect(myPluginGui, SIGNAL(changeStyle(QString)), this, SLOT(setStyle(QString)));
|
2004-06-10 15:41:40 +00:00
|
|
|
connect(myPluginGui, SIGNAL(changeColour(QColor)), this, SLOT(setColour(QColor)));
|
|
|
|
connect(myPluginGui, SIGNAL(refreshCanvas()), this, SLOT(refreshCanvas()));
|
2004-06-09 16:03:02 +00:00
|
|
|
myPluginGui->show();
|
2004-06-19 12:36:16 +00:00
|
|
|
|
2004-06-09 16:03:02 +00:00
|
|
|
//set the map units in the spin box
|
|
|
|
int myUnits=qGisInterface->getMapCanvas()->mapUnits();
|
|
|
|
switch (myUnits)
|
2004-06-19 12:36:16 +00:00
|
|
|
{
|
2004-06-09 16:03:02 +00:00
|
|
|
case 0: myPluginGui->spnSize->setSuffix(tr(" metres")); break;
|
|
|
|
case 1: myPluginGui->spnSize->setSuffix(tr(" feet")); break;
|
|
|
|
case 2: myPluginGui->spnSize->setSuffix(tr(" degrees")); break;
|
|
|
|
default: std::cout << "Error: not picked up map units - actual value = " << myUnits << std::endl;
|
2004-06-19 12:36:16 +00:00
|
|
|
};
|
2004-06-09 16:03:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Plugin::refreshCanvas()
|
|
|
|
{
|
2004-06-19 12:36:16 +00:00
|
|
|
qGisInterface->getMapCanvas()->refresh();
|
2004-06-09 16:03:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Actual drawing of Scale Bar
|
|
|
|
void Plugin::renderScaleBar(QPainter * theQPainter)
|
|
|
|
{
|
2004-06-19 15:44:02 +00:00
|
|
|
int myBufferSize=1; //softcode this later
|
2004-06-19 12:36:16 +00:00
|
|
|
// Exit if there are no layers loaded otherwise QGIS will freeze
|
|
|
|
int myLayerCount=qGisInterface->getMapCanvas()->layerCount();
|
|
|
|
if (!myLayerCount) return;
|
|
|
|
|
|
|
|
//Large if statement which determines whether to render the scale bar
|
|
|
|
if (mEnabled)
|
|
|
|
{
|
2004-06-09 16:03:02 +00:00
|
|
|
// Hard coded sizes
|
|
|
|
int myMajorTickSize=8;
|
|
|
|
int myTextOffsetX=3;
|
|
|
|
int myTextOffsetY=3;
|
2004-06-10 15:41:40 +00:00
|
|
|
double myActualSize=mPreferredSize;
|
2004-06-09 16:03:02 +00:00
|
|
|
int myMargin=20;
|
|
|
|
|
|
|
|
//Get canvas dimensions
|
|
|
|
QPaintDeviceMetrics myMetrics( theQPainter->device() );
|
2004-06-19 12:36:16 +00:00
|
|
|
int myCanvasHeight = myMetrics.height();
|
|
|
|
int myCanvasWidth = myMetrics.width();
|
|
|
|
|
2004-06-09 16:03:02 +00:00
|
|
|
//Get map units per pixel
|
2004-06-11 15:22:19 +00:00
|
|
|
double myMuppDouble=qGisInterface->getMapCanvas()->mupp();
|
2004-06-19 12:36:16 +00:00
|
|
|
|
2004-06-09 16:03:02 +00:00
|
|
|
//Calculate size of scale bar for preferred number of map units
|
2004-06-10 15:41:40 +00:00
|
|
|
double myScaleBarWidth = mPreferredSize / myMuppDouble;
|
2004-06-09 16:03:02 +00:00
|
|
|
|
|
|
|
//If scale bar is very small reset to 1/4 of the canvas wide
|
|
|
|
if (myScaleBarWidth < 30)
|
|
|
|
{
|
2004-06-10 15:41:40 +00:00
|
|
|
myScaleBarWidth = myMuppDouble * (myCanvasWidth/4);
|
|
|
|
myActualSize = myScaleBarWidth * myMuppDouble;
|
2004-06-09 16:03:02 +00:00
|
|
|
};
|
2004-06-19 12:36:16 +00:00
|
|
|
|
2004-06-09 16:03:02 +00:00
|
|
|
//if scale bar is more than half the canvas wide keep halving until not
|
|
|
|
while (myScaleBarWidth > myCanvasWidth/2)
|
|
|
|
{
|
2004-06-10 15:41:40 +00:00
|
|
|
myScaleBarWidth = myScaleBarWidth /2;
|
2004-06-18 15:06:55 +00:00
|
|
|
};
|
|
|
|
myActualSize = myScaleBarWidth * myMuppDouble;
|
2004-06-19 12:36:16 +00:00
|
|
|
|
2004-06-18 15:06:55 +00:00
|
|
|
// snap to integer < 10 times power of 10
|
|
|
|
if (mSnapping) {
|
|
|
|
int myPowerOf10 = pow(10, int(log(myActualSize) / log(10)));
|
|
|
|
myActualSize = round(myActualSize / myPowerOf10) * myPowerOf10;
|
|
|
|
myScaleBarWidth = myActualSize / myMuppDouble;
|
|
|
|
}
|
2004-06-19 12:36:16 +00:00
|
|
|
|
2004-06-10 15:41:40 +00:00
|
|
|
//Get type of map units and set scale bar unit label text
|
2004-06-09 16:03:02 +00:00
|
|
|
int myMapUnits=qGisInterface->getMapCanvas()->mapUnits();
|
|
|
|
QString myScaleBarUnitLabel;
|
|
|
|
switch (myMapUnits)
|
|
|
|
{
|
2004-06-19 12:36:16 +00:00
|
|
|
case 0: myScaleBarUnitLabel=tr(" metres"); break;
|
|
|
|
case 1: myScaleBarUnitLabel=tr(" feet"); break;
|
|
|
|
case 2: myScaleBarUnitLabel=tr(" degrees"); break;
|
|
|
|
default: std::cout << "Error: not picked up map units - actual value = " << myMapUnits << std::endl;
|
2004-06-09 16:03:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//Set font and calculate width of unit label
|
2004-06-19 12:36:16 +00:00
|
|
|
int myFontSize = 10; //we use this later for buffering
|
|
|
|
QFont myFont( "helvetica", myFontSize );
|
2004-06-09 16:03:02 +00:00
|
|
|
theQPainter->setFont(myFont);
|
2004-06-19 12:36:16 +00:00
|
|
|
QFontMetrics myFontMetrics( myFont );
|
|
|
|
double myFontWidth = myFontMetrics.width( myScaleBarUnitLabel );
|
|
|
|
double myFontHeight = myFontMetrics.height();
|
|
|
|
|
2004-06-09 16:03:02 +00:00
|
|
|
//Set the maximum label
|
|
|
|
QString myScaleBarMaxLabel=QString::number(myActualSize);
|
2004-06-19 12:36:16 +00:00
|
|
|
|
2004-06-09 16:03:02 +00:00
|
|
|
//Calculate total width of scale bar and label
|
2004-06-10 15:41:40 +00:00
|
|
|
double myTotalScaleBarWidth = myScaleBarWidth + myFontWidth;
|
2004-06-09 16:03:02 +00:00
|
|
|
|
|
|
|
//determine the origin of scale bar depending on placement selected
|
2004-06-10 15:41:40 +00:00
|
|
|
int myOriginX=myMargin;
|
|
|
|
int myOriginY=myMargin;
|
2004-06-09 16:03:02 +00:00
|
|
|
if (mPlacement==tr("Top Left"))
|
|
|
|
{
|
2004-06-19 12:36:16 +00:00
|
|
|
myOriginX=myMargin;
|
|
|
|
myOriginY=myMargin;
|
2004-06-09 16:03:02 +00:00
|
|
|
}
|
|
|
|
else if (mPlacement==tr("Bottom Left"))
|
|
|
|
{
|
2004-06-19 12:36:16 +00:00
|
|
|
myOriginX=myMargin;
|
|
|
|
myOriginY=myCanvasHeight - myMargin;
|
2004-06-09 16:03:02 +00:00
|
|
|
}
|
|
|
|
else if (mPlacement==tr("Top Right"))
|
|
|
|
{
|
2004-06-19 12:36:16 +00:00
|
|
|
myOriginX=myCanvasWidth - ((int) myTotalScaleBarWidth) - myMargin;
|
|
|
|
myOriginY=myMargin;
|
2004-06-09 16:03:02 +00:00
|
|
|
}
|
2004-06-10 15:41:40 +00:00
|
|
|
else if (mPlacement==tr("Bottom Right"))
|
2004-06-09 16:03:02 +00:00
|
|
|
{
|
2004-06-19 12:36:16 +00:00
|
|
|
myOriginX=myCanvasWidth - ((int) myTotalScaleBarWidth) - myMargin;
|
|
|
|
myOriginY=myCanvasHeight - myMargin;
|
2004-06-09 16:03:02 +00:00
|
|
|
}
|
2004-06-10 15:41:40 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cout << "Unable to determine where to put scale bar so defaulting to top left" << std::endl;
|
|
|
|
}
|
2004-06-19 12:36:16 +00:00
|
|
|
|
2004-06-09 16:03:02 +00:00
|
|
|
//Set pen to draw with
|
|
|
|
//Perhaps enable colour selection in future?
|
2004-06-10 15:41:40 +00:00
|
|
|
QPen pen( mColour, 2 );
|
2004-06-09 16:03:02 +00:00
|
|
|
theQPainter->setPen( pen );
|
2004-06-19 12:36:16 +00:00
|
|
|
|
2004-06-10 15:41:40 +00:00
|
|
|
//Cast myScaleBarWidth to int for drawing
|
|
|
|
int myScaleBarWidthInt = (int) myScaleBarWidth;
|
2004-06-19 12:36:16 +00:00
|
|
|
|
2004-06-09 16:03:02 +00:00
|
|
|
//Create array of vertices for scale bar depending on style
|
|
|
|
if (mStyle==tr("Tick Down"))
|
|
|
|
{
|
2004-06-19 12:36:16 +00:00
|
|
|
QPointArray myTickDownArray(4);
|
|
|
|
myTickDownArray.putPoints(0,4,
|
|
|
|
myOriginX , (myOriginY + myMajorTickSize) ,
|
|
|
|
myOriginX , myOriginY ,
|
|
|
|
(myScaleBarWidthInt + myOriginX), myOriginY ,
|
|
|
|
(myScaleBarWidthInt + myOriginX), (myOriginY + myMajorTickSize)
|
|
|
|
);
|
|
|
|
theQPainter->drawPolyline(myTickDownArray);
|
2004-06-09 16:03:02 +00:00
|
|
|
}
|
|
|
|
else if (mStyle==tr("Tick Up"))
|
|
|
|
{
|
2004-06-19 12:36:16 +00:00
|
|
|
QPointArray myTickUpArray(4);
|
|
|
|
myTickUpArray.putPoints(0,4,
|
|
|
|
myOriginX , myOriginY ,
|
|
|
|
myOriginX , myOriginY + myMajorTickSize ,
|
|
|
|
(myScaleBarWidthInt + myOriginX), myOriginY + myMajorTickSize ,
|
|
|
|
(myScaleBarWidthInt + myOriginX), myOriginY
|
|
|
|
);
|
|
|
|
theQPainter->drawPolyline(myTickUpArray);
|
2004-06-09 16:03:02 +00:00
|
|
|
}
|
|
|
|
else if (mStyle==tr("Bar"))
|
|
|
|
{
|
2004-06-19 12:36:16 +00:00
|
|
|
QPointArray myBarArray(2);
|
|
|
|
myBarArray.putPoints(0,2,
|
|
|
|
myOriginX , (myOriginY + (myMajorTickSize/2)),
|
|
|
|
(myScaleBarWidthInt + myOriginX), (myOriginY + (myMajorTickSize/2))
|
|
|
|
);
|
|
|
|
theQPainter->drawPolyline(myBarArray);
|
2004-06-09 16:03:02 +00:00
|
|
|
}
|
|
|
|
else if (mStyle==tr("Box"))
|
|
|
|
{
|
2004-06-19 12:36:16 +00:00
|
|
|
QPointArray myBoxArray(5);
|
|
|
|
myBoxArray.putPoints(0,5,
|
|
|
|
myOriginX , myOriginY,
|
|
|
|
(myScaleBarWidthInt + myOriginX), myOriginY,
|
|
|
|
(myScaleBarWidthInt + myOriginX), (myOriginY+myMajorTickSize),
|
|
|
|
myOriginX , (myOriginY+myMajorTickSize),
|
|
|
|
myOriginX , myOriginY
|
|
|
|
);
|
|
|
|
theQPainter->drawPolyline(myBoxArray);
|
2004-06-09 16:03:02 +00:00
|
|
|
}
|
2004-06-19 12:36:16 +00:00
|
|
|
|
2004-06-09 16:03:02 +00:00
|
|
|
//Do actual drawing of scale bar
|
2004-06-19 12:36:16 +00:00
|
|
|
|
|
|
|
//
|
2004-06-09 16:03:02 +00:00
|
|
|
//Do drawing of scale bar text
|
2004-06-19 12:36:16 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
QColor myBackColor = Qt::white;
|
|
|
|
QColor myForeColor = Qt::black;
|
|
|
|
|
|
|
|
//Draw the minimum label buffer
|
|
|
|
theQPainter->setPen( myBackColor );
|
|
|
|
myFontWidth = myFontMetrics.width( "0" );
|
|
|
|
myFontHeight = myFontMetrics.height();
|
|
|
|
|
2004-06-19 15:44:02 +00:00
|
|
|
for (int i = 0-myBufferSize; i <= myBufferSize; i++)
|
2004-06-19 12:36:16 +00:00
|
|
|
{
|
2004-06-19 15:44:02 +00:00
|
|
|
for (int j = 0-myBufferSize; j <= myBufferSize; j++)
|
2004-06-19 12:36:16 +00:00
|
|
|
{
|
|
|
|
theQPainter->drawText( i +(myOriginX-(myFontWidth/2)),
|
|
|
|
j + (myOriginY-(myFontHeight/4)),
|
|
|
|
"0");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-09 16:03:02 +00:00
|
|
|
//Draw minimum label
|
2004-06-19 12:36:16 +00:00
|
|
|
theQPainter->setPen( myForeColor );
|
|
|
|
|
2004-06-09 16:03:02 +00:00
|
|
|
theQPainter->drawText(
|
2004-06-19 12:36:16 +00:00
|
|
|
(myOriginX-(myFontWidth/2)),(myOriginY-(myFontHeight/4)),
|
|
|
|
"0"
|
|
|
|
);
|
|
|
|
|
|
|
|
//
|
2004-06-09 16:03:02 +00:00
|
|
|
//Draw maximum label
|
2004-06-19 12:36:16 +00:00
|
|
|
//
|
|
|
|
theQPainter->setPen( myBackColor );
|
|
|
|
myFontWidth = myFontMetrics.width( myScaleBarMaxLabel );
|
|
|
|
myFontHeight = myFontMetrics.height();
|
|
|
|
//first the buffer
|
2004-06-19 15:44:02 +00:00
|
|
|
for (int i = 0-myBufferSize; i <= myBufferSize; i++)
|
2004-06-19 12:36:16 +00:00
|
|
|
{
|
2004-06-19 15:44:02 +00:00
|
|
|
for (int j = 0-myBufferSize; j <= myBufferSize; j++)
|
2004-06-19 12:36:16 +00:00
|
|
|
{
|
|
|
|
theQPainter->drawText( i + (myOriginX+myScaleBarWidthInt-(myFontWidth/2)),
|
|
|
|
j + (myOriginY-(myFontHeight/4)),
|
|
|
|
myScaleBarMaxLabel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//then the text itself
|
|
|
|
theQPainter->setPen( myForeColor );
|
2004-06-09 16:03:02 +00:00
|
|
|
theQPainter->drawText(
|
2004-06-19 12:36:16 +00:00
|
|
|
(myOriginX+myScaleBarWidthInt-(myFontWidth/2)),(myOriginY-(myFontHeight/4)),
|
|
|
|
myScaleBarMaxLabel
|
|
|
|
);
|
|
|
|
|
|
|
|
//
|
2004-06-09 16:03:02 +00:00
|
|
|
//Draw unit label
|
2004-06-19 12:36:16 +00:00
|
|
|
//
|
|
|
|
theQPainter->setPen( myBackColor );
|
|
|
|
myFontWidth = myFontMetrics.width( myScaleBarUnitLabel );
|
|
|
|
myFontHeight = myFontMetrics.height();
|
|
|
|
//first the buffer
|
2004-06-19 15:44:02 +00:00
|
|
|
for (int i = 0-myBufferSize; i <= myBufferSize; i++)
|
2004-06-19 12:36:16 +00:00
|
|
|
{
|
2004-06-19 15:44:02 +00:00
|
|
|
for (int j = 0-myBufferSize; j <= myBufferSize; j++)
|
2004-06-19 12:36:16 +00:00
|
|
|
{
|
|
|
|
theQPainter->drawText( i + (myOriginX+myScaleBarWidthInt+myTextOffsetX),
|
|
|
|
j + (myOriginY+myMajorTickSize),
|
|
|
|
myScaleBarUnitLabel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//then the text itself
|
|
|
|
theQPainter->setPen( myForeColor );
|
2004-06-09 16:03:02 +00:00
|
|
|
theQPainter->drawText(
|
2004-06-19 12:36:16 +00:00
|
|
|
(myOriginX+myScaleBarWidthInt+myTextOffsetX),(myOriginY+myMajorTickSize),
|
|
|
|
myScaleBarUnitLabel
|
|
|
|
);
|
|
|
|
}
|
2004-06-09 16:03:02 +00:00
|
|
|
}
|
|
|
|
|
2004-06-10 15:41:40 +00:00
|
|
|
|
2004-06-09 16:03:02 +00:00
|
|
|
|
|
|
|
// Unload the plugin by cleaning up the GUI
|
|
|
|
void Plugin::unload()
|
|
|
|
{
|
|
|
|
// remove the GUI
|
|
|
|
menuBarPointer->removeItem(menuIdInt);
|
|
|
|
delete toolBarPointer;
|
|
|
|
}
|
|
|
|
|
2004-06-19 12:36:16 +00:00
|
|
|
//! set placement of scale bar
|
|
|
|
void Plugin::setPlacement(QString theQString)
|
|
|
|
{
|
|
|
|
mPlacement = theQString;
|
|
|
|
}
|
2004-06-09 16:03:02 +00:00
|
|
|
|
2004-06-19 12:36:16 +00:00
|
|
|
//! set preferred size of scale bar
|
|
|
|
void Plugin::setPreferredSize(int thePreferredSize)
|
|
|
|
{
|
|
|
|
mPreferredSize = thePreferredSize;
|
|
|
|
}
|
2004-06-09 16:03:02 +00:00
|
|
|
|
2004-06-19 12:36:16 +00:00
|
|
|
//! set whether the scale bar length should snap to the closes A*10^B
|
|
|
|
void Plugin::setSnapping(bool theSnapping)
|
|
|
|
{
|
|
|
|
mSnapping = theSnapping;
|
|
|
|
}
|
2004-06-09 16:03:02 +00:00
|
|
|
|
2004-06-19 12:36:16 +00:00
|
|
|
//! set scale bar enable
|
|
|
|
void Plugin::setEnabled(bool theBool)
|
|
|
|
{
|
|
|
|
mEnabled = theBool;
|
|
|
|
}
|
|
|
|
//! set scale bar enable
|
|
|
|
void Plugin::setStyle(QString theStyleQString)
|
|
|
|
{
|
|
|
|
mStyle = theStyleQString;
|
|
|
|
}
|
|
|
|
//! set the scale bar colour
|
|
|
|
void Plugin::setColour(QColor theQColor)
|
|
|
|
{
|
|
|
|
mColour = theQColor;
|
|
|
|
}
|
2004-06-09 16:03:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2004-06-14 04:35:20 +00:00
|
|
|
QGISEXTERN QgisPlugin * classFactory(QgisApp * theQGisAppPointer, QgisIface * theQgisInterfacePointer)
|
2004-06-09 16:03:02 +00:00
|
|
|
{
|
|
|
|
return new Plugin(theQGisAppPointer, 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.
|
2004-06-14 04:35:20 +00:00
|
|
|
QGISEXTERN QString name()
|
2004-06-09 16:03:02 +00:00
|
|
|
{
|
2004-06-19 12:36:16 +00:00
|
|
|
return name_;
|
2004-06-09 16:03:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the description
|
2004-06-14 04:35:20 +00:00
|
|
|
QGISEXTERN QString description()
|
2004-06-09 16:03:02 +00:00
|
|
|
{
|
2004-06-19 12:36:16 +00:00
|
|
|
return description_;
|
2004-06-09 16:03:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the type (either UI or MapLayer plugin)
|
2004-06-14 04:35:20 +00:00
|
|
|
QGISEXTERN int type()
|
2004-06-09 16:03:02 +00:00
|
|
|
{
|
2004-06-19 12:36:16 +00:00
|
|
|
return type_;
|
2004-06-09 16:03:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the version number for the plugin
|
2004-06-14 04:35:20 +00:00
|
|
|
QGISEXTERN QString version()
|
2004-06-09 16:03:02 +00:00
|
|
|
{
|
|
|
|
return version_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete ourself
|
2004-06-14 04:35:20 +00:00
|
|
|
QGISEXTERN void unload(QgisPlugin * thePluginPointer)
|
2004-06-09 16:03:02 +00:00
|
|
|
{
|
|
|
|
delete thePluginPointer;
|
|
|
|
}
|