Skip to content

Commit

Permalink
Use QgsRubberBand class for capturing lines and polygons. Move some m…
Browse files Browse the repository at this point in the history
…ethods into the slots section of the header to enable the capture tools.

Only the capture functions and not the vertex editing functions are working and the user-selected color is still not used by QgsRubberBand.


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@4658 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
telwertowski committed Jan 12, 2006
1 parent a0d6413 commit 8e0fa7b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 19 deletions.
16 changes: 8 additions & 8 deletions src/gui/qgisapp.h
Expand Up @@ -292,6 +292,14 @@ public slots:
void showBookmarks();
//! Create a new spatial bookmark
void newBookmark();
//! activates the capture point tool
void capturePoint();
//! activates the capture line tool
void captureLine();
//! activates the capture polygon tool
void capturePolygon();
//! activates the selection tool
void select();

public slots:
void showProgress(int theProgress, int theTotalSteps);
Expand Down Expand Up @@ -385,14 +393,6 @@ public slots:
void drawLayers();
//! test function
void testButton();
//! activates the capture point tool
void capturePoint();
//! activates the capture line tool
void captureLine();
//! activates the capture polygon tool
void capturePolygon();
//! activates the selection tool
void select();
//! activates the add vertex tool
void addVertex();
//! activates the move vertex tool
Expand Down
64 changes: 53 additions & 11 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -100,6 +100,7 @@ email : sherman at mrcc.com
#include "qgsproject.h"
#include "qgsmaplayerregistry.h"
#include "qgsmeasure.h"
#include "qgsrubberband.h"

#include "qgsmapcanvasproperties.h"

Expand Down Expand Up @@ -814,6 +815,8 @@ void QgsMapCanvas::render(QPaintDevice * theQPaintDevice)
ai++;
}

// TODO: Qt4 will have to do this a different way, using QRubberBand ...
#if QT_VERSION < 0x040000
//draw mCaptureList with color and width stored in QgsProject
QColor digitcolor(QgsProject::instance()->readNumEntry("Digitizing","/LineColorRedPart",255),
QgsProject::instance()->readNumEntry("Digitizing","/LineColorGreenPart",0),
Expand Down Expand Up @@ -845,8 +848,6 @@ void QgsMapCanvas::render(QPaintDevice * theQPaintDevice)
//and also the connection to mDigitMovePoint
if((mLineEditing || mPolygonEditing) && mCaptureList.size()>0)
{
// TODO: Qt4 will have to do this a different way, using QRubberBand ...
#if QT_VERSION < 0x040000
paint->setRasterOp(Qt::XorROP);
try
{
Expand All @@ -868,9 +869,28 @@ void QgsMapCanvas::render(QPaintDevice * theQPaintDevice)
// we need this to keep windows from wanted to send
// a bug report to Bill
}
#endif
}
}
#else
if(mCaptureList.size() > 0)
{
mRubberBand2->setGeometry(rect());
mRubberBand2->reset(mPolygonEditing);
try
{
for (std::list<QgsPoint>::iterator it = mCaptureList.begin(); it != mCaptureList.end(); ++it)
{
QgsPoint point = mCanvasProperties->coordXForm->transform(*it);
mRubberBand2->addPoint(QPoint(int(point.x()), int(point.y())));
}
}
catch(QgsException &e)
{
// ignore this exception at present
std::cout << "QgsException: " << __FILE__ << __LINE__ << std::endl;
}
}
#endif


// notify any listeners that rendering is complete
Expand Down Expand Up @@ -2010,14 +2030,14 @@ void QgsMapCanvas::mouseReleaseEvent(QMouseEvent * e)
case QGis::CapturePolygon:
{

// TODO: Qt4 will have to do this a different way, using QRubberBand ...
#if QT_VERSION < 0x040000
if (mCanvasProperties->rubberStartPoint != mCanvasProperties->rubberStopPoint)
{
// TODO: Qt4 will have to do this a different way, using QRubberBand ...
#if QT_VERSION < 0x040000
// XOR-out the old line
paint.drawLine(mCanvasProperties->rubberStartPoint, mCanvasProperties->rubberStopPoint);
#endif
}
#endif

mCanvasProperties->rubberStopPoint = e->pos();

Expand All @@ -2042,20 +2062,31 @@ void QgsMapCanvas::mouseReleaseEvent(QMouseEvent * e)
return;
}

// TODO: Qt4 will have to do this a different way, using QRubberBand ...
#if QT_VERSION < 0x040000
//prevent clearing of the line between the first and the second polygon vertex
//during the next mouse move event
if(mCaptureList.size() == 1 && mCanvasProperties->mapTool == QGis::CapturePolygon)
{
QPainter paint(mCanvasProperties->pmCanvas);
drawLineToDigitisingCursor(&paint);
}
#else
if (mCaptureList.size() == 0)
{
mRubberBand2 = new QgsRubberBand(this, mPolygonEditing);
mRubberBand2->show();
}
#endif

mDigitMovePoint.setX(e->x());
mDigitMovePoint.setY(e->y());
mDigitMovePoint=mCanvasProperties->coordXForm->toMapCoordinates(e->x(), e->y());
QgsPoint digitisedpoint=mCanvasProperties->coordXForm->toMapCoordinates(e->x(), e->y());
vlayer->snapPoint(digitisedpoint,QgsProject::instance()->readDoubleEntry("Digitizing","/Tolerance",0));
mCaptureList.push_back(digitisedpoint);
// TODO: Qt4 will have to do this a different way, using QRubberBand ...
#if QT_VERSION < 0x040000
if(mCaptureList.size()>1)
{
QPainter paint(this);
Expand All @@ -2081,12 +2112,18 @@ void QgsMapCanvas::mouseReleaseEvent(QMouseEvent * e)
}
repaint();
}
#else
mRubberBand2->addPoint(e->pos());
#endif

if (e->button() == Qt::RightButton)
{
// End of string

mCanvasProperties->capturing = FALSE;
#if !(QT_VERSION < 0x040000)
delete mRubberBand2;
#endif

//create QgsFeature with wkb representation
QgsFeature* f=new QgsFeature(0,"WKBLineString");
Expand Down Expand Up @@ -2453,10 +2490,10 @@ void QgsMapCanvas::mouseMoveEvent(QMouseEvent * e)
case QGis::ZoomIn:
case QGis::ZoomOut:
// draw the rubber band box as the user drags the mouse
// TODO: Qt4 will have to do this a different way, using QRubberBand ...
#if QT_VERSION < 0x040000
mCanvasProperties->dragging = true;

// TODO: Qt4 will have to do this a different way, using QRubberBand ...
paint.begin(this);
paint.setPen(pen);
paint.setRasterOp(Qt::XorROP);
Expand Down Expand Up @@ -2540,11 +2577,11 @@ void QgsMapCanvas::mouseMoveEvent(QMouseEvent * e)

// show the rubber-band from the last click

// TODO: Qt4 will have to do this a different way, using QRubberBand ...
#if QT_VERSION < 0x040000
QPainter paint;
QPen pen(Qt::gray);

// TODO: Qt4 will have to do this a different way, using QRubberBand ...
#if QT_VERSION < 0x040000
paint.begin(this);
paint.setPen(pen);
paint.setRasterOp(Qt::XorROP);
Expand All @@ -2559,13 +2596,17 @@ void QgsMapCanvas::mouseMoveEvent(QMouseEvent * e)

paint.drawLine(mCanvasProperties->rubberStartPoint, mCanvasProperties->rubberStopPoint);
paint.end();
#else
mRubberBand2->movePoint(e->pos());
#endif

}

break;
}

// TODO: Qt4 will have to do this a different way, using QRubberBand ...
#if QT_VERSION < 0x040000
//draw a line to the cursor position in line/polygon editing mode
if ( mCanvasProperties->mapTool == QGis::CaptureLine || mCanvasProperties->mapTool == QGis::CapturePolygon )
{
Expand Down Expand Up @@ -2593,6 +2634,7 @@ void QgsMapCanvas::mouseMoveEvent(QMouseEvent * e)
}
}
}
#endif

// show x y on status bar
QPoint xy = e->pos();
Expand All @@ -2602,13 +2644,13 @@ void QgsMapCanvas::mouseMoveEvent(QMouseEvent * e)

void QgsMapCanvas::drawLineToDigitisingCursor(QPainter* paint, bool last)
{
// TODO: Qt4 will have to do this a different way, using QRubberBand ...
#if QT_VERSION < 0x040000
QColor digitcolor(QgsProject::instance()->readNumEntry("Digitizing","/LineColorRedPart",255),\
QgsProject::instance()->readNumEntry("Digitizing","/LineColorGreenPart",0),\
QgsProject::instance()->readNumEntry("Digitizing","/LineColorBluePart",0));
paint->setPen(QPen(digitcolor,QgsProject::instance()->readNumEntry("Digitizing","/LineWidth",1),Qt::SolidLine));

// TODO: Qt4 will have to do this a different way, using QRubberBand ...
#if QT_VERSION < 0x040000
paint->setRasterOp(Qt::XorROP);
std::list<QgsPoint>::iterator it;
if(last)
Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgsmapcanvas.h
Expand Up @@ -60,6 +60,7 @@ class QgsLegend;
class QgsLegendView;
class QgsAcetateObject;
class QgsMeasure;
class QgsRubberBand;


/*! \class QgsMapCanvas
Expand Down Expand Up @@ -422,6 +423,9 @@ public slots:
//! Rubberband used when selecting
QRubberBand *mRubberBand;

//! Rubberband used when drawing
QgsRubberBand *mRubberBand2;

//! Measure tool
QgsMeasure *mMeasure;

Expand Down

0 comments on commit 8e0fa7b

Please sign in to comment.