Skip to content

Commit c5b914a

Browse files
author
wonder
committed
Applied patch from Jurgen Fischer with some modifications.
git-svn-id: http://svn.osgeo.org/qgis/trunk@7235 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 5f1925f commit c5b914a

File tree

3 files changed

+60
-6
lines changed

3 files changed

+60
-6
lines changed

python/gui/qgsrubberband.sip

+8
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,17 @@ class QgsRubberBand: QgsMapCanvasItem
1414

1515
void reset(bool isPolygon = false);
1616
void addPoint(const QgsPoint & p);
17+
18+
// ! Remove last point
19+
void removePoint(bool update = true);
20+
1721
void movePoint(const QgsPoint & p);
1822
void movePoint(int index, const QgsPoint& p);
1923

24+
int size() const;
25+
const QList<QgsPoint>& getPoints() const;
26+
const QgsPoint& getPoint(int index) const;
27+
2028
protected:
2129
virtual void paint(QPainter* p);
2230

src/gui/qgsrubberband.cpp

+43-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ void QgsRubberBand::setWidth(int width)
5656
*/
5757
void QgsRubberBand::reset(bool isPolygon)
5858
{
59-
mPoints.resize(1); // addPoint assumes an initial allocated point
59+
mPoints.clear();
60+
mPoints.append(QgsPoint()); // addPoint assumes an initial allocated point
6061
mIsPolygon = isPolygon;
6162
updateRect();
6263
update();
@@ -76,12 +77,50 @@ void QgsRubberBand::addPoint(const QgsPoint & p, bool do_update /* = true */)
7677
}
7778
}
7879

80+
/*!
81+
Remove a point
82+
*/
83+
void QgsRubberBand::removePoint(bool do_update)
84+
{
85+
mPoints.pop_back();
86+
if(do_update)
87+
{
88+
updateRect();
89+
update();
90+
}
91+
}
92+
93+
/*!
94+
Return number of points
95+
*/
96+
int QgsRubberBand::size() const
97+
{
98+
return mPoints.size();
99+
}
100+
101+
/*!
102+
Return the points
103+
*/
104+
const QList<QgsPoint>& QgsRubberBand::getPoints() const
105+
{
106+
return mPoints;
107+
}
108+
109+
/*!
110+
Return a point
111+
*/
112+
const QgsPoint& QgsRubberBand::getPoint(int index) const
113+
{
114+
return mPoints[index];
115+
}
116+
117+
79118
/*!
80119
Update the line between the last added point and the mouse position.
81120
*/
82121
void QgsRubberBand::movePoint(const QgsPoint & p)
83122
{
84-
mPoints[mPoints.size()-1] = p; // Update current mouse position
123+
mPoints[ size()-1 ] = p; // Update current mouse position
85124
updateRect();
86125
update();
87126
}
@@ -101,7 +140,7 @@ void QgsRubberBand::paint(QPainter* p)
101140
if (mPoints.size() > 1)
102141
{
103142
QPolygonF pts;
104-
for (uint i = 0; i < mPoints.size(); i++)
143+
for (int i = 0; i < mPoints.size(); i++)
105144
pts.append(toCanvasCoords(mPoints[i])-pos());
106145

107146
p->setPen(mPen);
@@ -122,7 +161,7 @@ void QgsRubberBand::updateRect()
122161
if (mPoints.size() > 0)
123162
{
124163
QgsRect r(mPoints[0], mPoints[0]);
125-
for (uint i = 1; i < mPoints.size(); i++)
164+
for (int i = 1; i < mPoints.size(); i++)
126165
r.combineExtentWith(mPoints[i].x(), mPoints[i].y());
127166
setRect(r);
128167
}

src/gui/qgsrubberband.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#define QGSRUBBERBAND_H
1818

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

41+
// ! Remove last point
42+
void removePoint(bool update = true);
43+
4144
void movePoint(const QgsPoint & p);
4245
void movePoint(int index, const QgsPoint& p);
4346

47+
int size() const;
48+
const QList<QgsPoint>& getPoints() const;
49+
const QgsPoint& getPoint(int index) const;
50+
4451
protected:
4552
virtual void paint(QPainter* p);
4653

@@ -50,7 +57,7 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
5057
private:
5158
QBrush mBrush;
5259
QPen mPen;
53-
std::deque<QgsPoint> mPoints;
60+
QList<QgsPoint> mPoints;
5461
bool mIsPolygon;
5562
};
5663

0 commit comments

Comments
 (0)