mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Applied patch from Jurgen Fischer with some modifications.
git-svn-id: http://svn.osgeo.org/qgis/trunk@7235 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
5f1925f738
commit
c5b914a0b6
@ -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;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user