Skip to content
Permalink
Browse files
Applied patch from Jurgen Fischer with some modifications.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7235 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Sep 30, 2007
1 parent a030b22 commit e94e9f62e1dcbe196cf1ee67b77d3670bb63a641
Showing with 60 additions and 6 deletions.
  1. +8 −0 python/gui/qgsrubberband.sip
  2. +43 −4 src/gui/qgsrubberband.cpp
  3. +9 −2 src/gui/qgsrubberband.h
@@ -14,9 +14,17 @@ class QgsRubberBand: QgsMapCanvasItem

void reset(bool isPolygon = false);
void addPoint(const QgsPoint & p);

// ! Remove last point
void removePoint(bool update = true);

void movePoint(const QgsPoint & p);
void movePoint(int index, const QgsPoint& p);

int size() const;
const QList<QgsPoint>& getPoints() const;
const QgsPoint& getPoint(int index) const;

protected:
virtual void paint(QPainter* p);

@@ -56,7 +56,8 @@ void QgsRubberBand::setWidth(int width)
*/
void QgsRubberBand::reset(bool isPolygon)
{
mPoints.resize(1); // addPoint assumes an initial allocated point
mPoints.clear();
mPoints.append(QgsPoint()); // addPoint assumes an initial allocated point
mIsPolygon = isPolygon;
updateRect();
update();
@@ -76,12 +77,50 @@ void QgsRubberBand::addPoint(const QgsPoint & p, bool do_update /* = true */)
}
}

/*!
Remove a point
*/
void QgsRubberBand::removePoint(bool do_update)
{
mPoints.pop_back();
if(do_update)
{
updateRect();
update();
}
}

/*!
Return number of points
*/
int QgsRubberBand::size() const
{
return mPoints.size();
}

/*!
Return the points
*/
const QList<QgsPoint>& QgsRubberBand::getPoints() const
{
return mPoints;
}

/*!
Return a point
*/
const QgsPoint& QgsRubberBand::getPoint(int index) const
{
return mPoints[index];
}


/*!
Update the line between the last added point and the mouse position.
*/
void QgsRubberBand::movePoint(const QgsPoint & p)
{
mPoints[mPoints.size()-1] = p; // Update current mouse position
mPoints[ size()-1 ] = p; // Update current mouse position
updateRect();
update();
}
@@ -101,7 +140,7 @@ void QgsRubberBand::paint(QPainter* p)
if (mPoints.size() > 1)
{
QPolygonF pts;
for (uint i = 0; i < mPoints.size(); i++)
for (int i = 0; i < mPoints.size(); i++)
pts.append(toCanvasCoords(mPoints[i])-pos());

p->setPen(mPen);
@@ -122,7 +161,7 @@ void QgsRubberBand::updateRect()
if (mPoints.size() > 0)
{
QgsRect r(mPoints[0], mPoints[0]);
for (uint i = 1; i < mPoints.size(); i++)
for (int i = 1; i < mPoints.size(); i++)
r.combineExtentWith(mPoints[i].x(), mPoints[i].y());
setRect(r);
}
@@ -17,8 +17,8 @@
#define QGSRUBBERBAND_H

#include "qgsmapcanvasitem.h"
#include <deque>
#include <QBrush>
#include <QList>
#include <QPen>
#include <QPolygon>
class QPaintEvent;
@@ -38,9 +38,16 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
//! If adding more points consider using update=false for better performance
void addPoint(const QgsPoint & p, bool update = true);

// ! Remove last point
void removePoint(bool update = true);

void movePoint(const QgsPoint & p);
void movePoint(int index, const QgsPoint& p);

int size() const;
const QList<QgsPoint>& getPoints() const;
const QgsPoint& getPoint(int index) const;

protected:
virtual void paint(QPainter* p);

@@ -50,7 +57,7 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
private:
QBrush mBrush;
QPen mPen;
std::deque<QgsPoint> mPoints;
QList<QgsPoint> mPoints;
bool mIsPolygon;
};

0 comments on commit e94e9f6

Please sign in to comment.