Skip to content

Commit d3142f6

Browse files
committed
Merge pull request #798 from 3nids/maptoolcapturerubber
[fix #8395] Add a second rubber band in map tool capture
2 parents 2087de1 + c1cde94 commit d3142f6

12 files changed

Lines changed: 108 additions & 50 deletions

‎src/app/qgsmaptooladdfeature.cpp‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
141141
mCanvas->refresh();
142142
}
143143
}
144+
145+
// LINE AND POLYGON CAPTURING
144146
else if ( mode() == CaptureLine || mode() == CapturePolygon )
145147
{
146148
//check we only use the line tool for line/multiline layers
@@ -181,8 +183,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
181183
else if ( e->button() == Qt::RightButton )
182184
{
183185
// End of string
184-
185-
resetLastVertex();
186+
deleteTempRubberBand();
186187

187188
//lines: bail out if there are not at least two vertices
188189
if ( mode() == CaptureLine && size() < 2 )

‎src/app/qgsmaptooladdpart.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void QgsMapToolAddPart::canvasReleaseEvent( QMouseEvent * e )
112112
}
113113
else if ( e->button() != Qt::RightButton )
114114
{
115-
resetLastVertex();
115+
deleteTempRubberBand();
116116

117117
return;
118118
}

‎src/app/qgsmaptooladdring.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void QgsMapToolAddRing::canvasReleaseEvent( QMouseEvent * e )
6969
}
7070
else if ( e->button() == Qt::RightButton )
7171
{
72-
resetLastVertex();
72+
deleteTempRubberBand();
7373

7474
closePolygon();
7575

‎src/app/qgsmaptoolcapture.cpp‎

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ QgsMapToolCapture::QgsMapToolCapture( QgsMapCanvas* canvas, enum CaptureMode too
3636
: QgsMapToolEdit( canvas )
3737
, mCaptureMode( tool )
3838
, mRubberBand( 0 )
39+
, mTempRubberBand( 0 )
3940
, mValidator( 0 )
4041
{
4142
mCaptureModeFromLayer = tool == CaptureNone;
@@ -100,7 +101,6 @@ void QgsMapToolCapture::currentLayerChanged( QgsMapLayer *layer )
100101
}
101102
}
102103

103-
104104
void QgsMapToolCapture::canvasMoveEvent( QMouseEvent * e )
105105
{
106106
QgsPoint mapPoint;
@@ -120,10 +120,10 @@ void QgsMapToolCapture::canvasMoveEvent( QMouseEvent * e )
120120
mSnappingMarkers << m;
121121
}
122122

123-
if ( mCaptureMode != CapturePoint && mRubberBand && mCapturing )
123+
if ( mCaptureMode != CapturePoint && mTempRubberBand && mCapturing )
124124
{
125125
mapPoint = snapPointFromResults( snapResults, e->pos() );
126-
mRubberBand->movePoint( mapPoint );
126+
mTempRubberBand->movePoint( mapPoint );
127127
}
128128
}
129129
} // mouseMoveEvent
@@ -180,7 +180,6 @@ int QgsMapToolCapture::nextPoint( const QPoint &p, QgsPoint &layerPoint, QgsPoin
180180
return 0;
181181
}
182182

183-
184183
int QgsMapToolCapture::addVertex( const QPoint &p )
185184
{
186185
QgsPoint layerPoint;
@@ -203,10 +202,28 @@ int QgsMapToolCapture::addVertex( const QPoint &p )
203202
{
204203
mRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QGis::Polygon : QGis::Line );
205204
}
206-
207205
mRubberBand->addPoint( mapPoint );
208206
mCaptureList.append( layerPoint );
209207

208+
if ( !mTempRubberBand )
209+
{
210+
mTempRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QGis::Polygon : QGis::Line , true );
211+
}
212+
else{
213+
mTempRubberBand->reset(CapturePolygon ? true : false);
214+
}
215+
if ( mCaptureMode == CaptureLine )
216+
{
217+
mTempRubberBand->addPoint( mapPoint );
218+
}
219+
else if ( mCaptureMode == CapturePolygon )
220+
{
221+
const QgsPoint *firstPoint = mRubberBand->getPoint( 0 , 0 );
222+
mTempRubberBand->addPoint( *firstPoint );
223+
mTempRubberBand->movePoint( mapPoint );
224+
mTempRubberBand->addPoint( mapPoint );
225+
}
226+
210227
validateGeometry();
211228

212229
return 0;
@@ -231,20 +248,6 @@ void QgsMapToolCapture::undo()
231248
}
232249
}
233250

234-
void QgsMapToolCapture::resetLastVertex()
235-
{
236-
if ( mRubberBand )
237-
{
238-
int rubberBandSize = mRubberBand->numberOfVertices();
239-
if ( rubberBandSize < 2 )
240-
{
241-
return;
242-
}
243-
const QgsPoint *lastPoint = mRubberBand->getPoint(0, rubberBandSize-2);
244-
mRubberBand->movePoint( *lastPoint );
245-
}
246-
}
247-
248251
void QgsMapToolCapture::keyPressEvent( QKeyEvent* e )
249252
{
250253
if ( e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete )
@@ -266,6 +269,12 @@ void QgsMapToolCapture::stopCapturing()
266269
mRubberBand = 0;
267270
}
268271

272+
if ( mTempRubberBand )
273+
{
274+
delete mTempRubberBand;
275+
mTempRubberBand = 0;
276+
}
277+
269278
while ( !mGeomErrorMarkers.isEmpty() )
270279
{
271280
delete mGeomErrorMarkers.takeFirst();
@@ -283,6 +292,15 @@ void QgsMapToolCapture::stopCapturing()
283292
mCanvas->refresh();
284293
}
285294

295+
void QgsMapToolCapture::deleteTempRubberBand()
296+
{
297+
if ( mTempRubberBand )
298+
{
299+
delete mTempRubberBand;
300+
mTempRubberBand = 0;
301+
}
302+
}
303+
286304
void QgsMapToolCapture::closePolygon()
287305
{
288306
mCaptureList.append( mCaptureList[0] );

‎src/app/qgsmaptoolcapture.h‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,9 @@ class QgsMapToolCapture : public QgsMapToolEdit
8282
/**Removes the last vertex from mRubberBand and mCaptureList*/
8383
void undo();
8484

85-
/**Reset the last vertex from RubberBand to the previous one position*/
86-
void resetLastVertex();
87-
8885
void startCapturing();
8986
void stopCapturing();
87+
void deleteTempRubberBand();
9088

9189
CaptureMode mode() { return mCaptureMode; }
9290

@@ -107,6 +105,9 @@ class QgsMapToolCapture : public QgsMapToolEdit
107105
/** rubber band for polylines and polygons */
108106
QgsRubberBand* mRubberBand;
109107

108+
/** temporary rubber band for polylines and polygons. this connects the last added point to the mouse cursor position */
109+
QgsRubberBand* mTempRubberBand;
110+
110111
/** List to store the points of digitised lines and polygons (in layer coordinates)*/
111112
QList<QgsPoint> mCaptureList;
112113

‎src/app/qgsmaptooledit.cpp‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,26 @@ QgsPoint QgsMapToolEdit::snapPointFromResults( const QList<QgsSnappingResult>& s
6868
}
6969
}
7070

71-
QgsRubberBand* QgsMapToolEdit::createRubberBand( QGis::GeometryType geometryType )
71+
QgsRubberBand* QgsMapToolEdit::createRubberBand( QGis::GeometryType geometryType, bool alternativeBand )
7272
{
7373
QSettings settings;
7474
QgsRubberBand* rb = new QgsRubberBand( mCanvas, geometryType );
75+
rb->setWidth( settings.value( "/qgis/digitizing/line_width", 1 ).toInt() );
7576
QColor color( settings.value( "/qgis/digitizing/line_color_red", 255 ).toInt(),
7677
settings.value( "/qgis/digitizing/line_color_green", 0 ).toInt(),
77-
settings.value( "/qgis/digitizing/line_color_blue", 0 ).toInt() );
78+
settings.value( "/qgis/digitizing/line_color_blue", 0 ).toInt());
79+
double myAlpha = settings.value( "/qgis/digitizing/line_color_alpha", 200 ).toInt() / 255.0 ;
80+
if ( alternativeBand )
81+
{
82+
myAlpha = myAlpha * settings.value( "/qgis/digitizing/line_color_alpha_scale" , 0.75 ).toDouble();
83+
rb->setLineStyle( Qt::DotLine );
84+
}
85+
if ( geometryType == QGis::Polygon )
86+
{
87+
color.setAlphaF ( myAlpha );
88+
}
89+
color.setAlphaF ( myAlpha );
7890
rb->setColor( color );
79-
rb->setWidth( settings.value( "/qgis/digitizing/line_width", 1 ).toInt() );
8091
rb->show();
8192
return rb;
8293
}

‎src/app/qgsmaptooledit.h‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,13 @@ class QgsMapToolEdit: public QgsMapTool
5050
@return the snapped point in map coordinates*/
5151
QgsPoint snapPointFromResults( const QList<QgsSnappingResult>& snapResults, const QPoint& screenCoords );
5252

53-
/**Creates a rubber band with the color/line width from
54-
the QGIS settings. The caller takes ownership of the
55-
returned object*/
56-
QgsRubberBand* createRubberBand( QGis::GeometryType geometryType = QGis::Line );
53+
/** Creates a rubber band with the color/line width from
54+
* the QGIS settings. The caller takes ownership of the
55+
* returned object
56+
* @param geometryType
57+
* @param alternativeBand if true, rubber band will be set with more transparency and a dash pattern. defaut is false.
58+
*/
59+
QgsRubberBand* createRubberBand(QGis::GeometryType geometryType = QGis::Line , bool alternativeBand = false );
5760

5861
/**Returns the current vector layer of the map canvas or 0*/
5962
QgsVectorLayer* currentVectorLayer();

‎src/app/qgsmaptoolreshape.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void QgsMapToolReshape::canvasReleaseEvent( QMouseEvent * e )
6868
}
6969
else if ( e->button() == Qt::RightButton )
7070
{
71-
resetLastVertex();
71+
deleteTempRubberBand();
7272

7373
//find out bounding box of mCaptureList
7474
if ( size() < 1 )

‎src/app/qgsmaptoolsplitfeatures.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void QgsMapToolSplitFeatures::canvasReleaseEvent( QMouseEvent * e )
7474
}
7575
else if ( e->button() == Qt::RightButton )
7676
{
77-
resetLastVertex();
77+
deleteTempRubberBand();
7878

7979
//bring up dialog if a split was not possible (polygon) or only done once (line)
8080
int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );

‎src/app/qgsoptions.cpp‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,9 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
638638
myRed = settings.value( "/qgis/digitizing/line_color_red", 255 ).toInt();
639639
myGreen = settings.value( "/qgis/digitizing/line_color_green", 0 ).toInt();
640640
myBlue = settings.value( "/qgis/digitizing/line_color_blue", 0 ).toInt();
641-
mLineColorToolButton->setColor( QColor( myRed, myGreen, myBlue ) );
641+
myAlpha = settings.value( "/qgis/digitizing/line_color_alpha", 200 ).toInt();
642+
mLineColorToolButton->setColor( QColor( myRed, myGreen, myBlue, myAlpha ) );
643+
mLineColorToolButton->setColorDialogOptions(QColorDialog::ShowAlphaChannel);
642644

643645
//default snap mode
644646
mDefaultSnapModeComboBox->insertItem( 0, tr( "To vertex" ), "to vertex" );
@@ -1083,6 +1085,7 @@ void QgsOptions::saveOptions()
10831085
settings.setValue( "/qgis/digitizing/line_color_red", digitizingColor.red() );
10841086
settings.setValue( "/qgis/digitizing/line_color_green", digitizingColor.green() );
10851087
settings.setValue( "/qgis/digitizing/line_color_blue", digitizingColor.blue() );
1088+
settings.setValue( "/qgis/digitizing/line_color_alpha", digitizingColor.alpha() );
10861089

10871090
//default snap mode
10881091
QString defaultSnapModeString = mDefaultSnapModeComboBox->itemData( mDefaultSnapModeComboBox->currentIndex() ).toString();

0 commit comments

Comments
 (0)