void QgsMapToolNodeTool::canvasMoveEvent( QMouseEvent * e ) { if ( !mSelectedFeature || e->buttons() == Qt::NoButton ) return; QgsVectorLayer* vlayer = mSelectedFeature->vlayer(); Q_ASSERT( vlayer ); mSelectAnother = false; if ( mMoving ) { if ( mMoveRubberBands.empty() ) { QgsGeometryRubberBand* rb = new QgsGeometryRubberBand( mCanvas, mSelectedFeature->geometry()->type() ); rb->setOutlineColor( Qt::blue ); rb->setBrushStyle( Qt::NoBrush ); rb->setOutlineWidth( 2 ); QgsAbstractGeometryV2* rbGeom = mSelectedFeature->geometry()->geometry()->clone(); if ( mCanvas->mapSettings().layerTransform( vlayer ) ) rbGeom->transform( *mCanvas->mapSettings().layerTransform( vlayer ) ); rb->setGeometry( rbGeom ); mMoveRubberBands.insert( mSelectedFeature->featureId(), rb ); foreach ( const QgsVertexEntry* vertexEntry, mSelectedFeature->vertexMap() ) { if ( vertexEntry->isSelected() ) mMoveVertices[mSelectedFeature->featureId()].append( qMakePair( vertexEntry->vertexId(), toMapCoordinates( vlayer, vertexEntry->point() ) ) ); } if ( QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 ) ) { createTopologyRubberBands(); } } else {
void QgsMapToolNodeTool::createTopologyRubberBands() { QgsVectorLayer* vlayer = mSelectedFeature->vlayer(); Q_FOREACH ( const QgsVertexEntry* vertexEntry, mSelectedFeature->vertexMap() ) { if ( !vertexEntry->isSelected() ) { continue; } // Snap vertex QMultiMap<double, QgsSnappingResult> snapResults; vlayer->snapWithContext( vertexEntry->pointV1(), ZERO_TOLERANCE, snapResults, QgsSnapper::SnapToVertex ); Q_FOREACH ( const QgsSnappingResult& snapResult, snapResults ) { // Get geometry of snapped feature QgsFeatureId snapFeatureId = snapResult.snappedAtGeometry; QgsFeature feature; if ( !vlayer->getFeatures( QgsFeatureRequest( snapFeatureId ).setSubsetOfAttributes( QgsAttributeList() ) ).nextFeature( feature ) ) { continue; } // Get VertexId of snapped vertex QgsVertexId vid; if ( !feature.geometry().vertexIdFromVertexNr( snapResult.snappedVertexNr, vid ) ) { continue; } // Add rubberband if not already added if ( !mMoveRubberBands.contains( snapFeatureId ) ) { QgsGeometryRubberBand* rb = new QgsGeometryRubberBand( mCanvas, feature.geometry().type() ); QSettings settings; QColor color( settings.value( QStringLiteral( "/qgis/digitizing/line_color_red" ), 255 ).toInt(), settings.value( QStringLiteral( "/qgis/digitizing/line_color_green" ), 0 ).toInt(), settings.value( QStringLiteral( "/qgis/digitizing/line_color_blue" ), 0 ).toInt() ); double myAlpha = settings.value( QStringLiteral( "/qgis/digitizing/line_color_alpha" ), 30 ).toInt() / 255.0 ; color.setAlphaF( myAlpha ); rb->setOutlineColor( color ); rb->setBrushStyle( Qt::NoBrush ); rb->setOutlineWidth( settings.value( QStringLiteral( "/qgis/digitizing/line_width" ), 1 ).toInt() ); QgsAbstractGeometry* rbGeom = feature.geometry().geometry()->clone(); if ( mCanvas->mapSettings().layerTransform( vlayer ).isValid() ) rbGeom->transform( mCanvas->mapSettings().layerTransform( vlayer ) ); rb->setGeometry( rbGeom ); mMoveRubberBands.insert( snapFeatureId, rb ); } // Add to list of vertices to be moved mMoveVertices[snapFeatureId].append( qMakePair( vid, toMapCoordinates( vlayer, feature.geometry().geometry()->vertexAt( vid ) ) ) ); } }
void QgsMapToolNodeTool::createTopologyRubberBands() { QgsVectorLayer* vlayer = mSelectedFeature->vlayer(); foreach ( const QgsVertexEntry* vertexEntry, mSelectedFeature->vertexMap() ) { if ( !vertexEntry->isSelected() ) { continue; } // Snap vertex QMultiMap<double, QgsSnappingResult> snapResults; vlayer->snapWithContext( vertexEntry->pointV1(), ZERO_TOLERANCE, snapResults, QgsSnapper::SnapToVertex ); foreach ( const QgsSnappingResult& snapResult, snapResults.values() ) { // Get geometry of snapped feature QgsFeatureId snapFeatureId = snapResult.snappedAtGeometry; QgsFeature feature; if ( !vlayer->getFeatures( QgsFeatureRequest( snapFeatureId ).setSubsetOfAttributes( QgsAttributeList() ) ).nextFeature( feature ) ) { continue; } // Get VertexId of snapped vertex QgsVertexId vid; if ( !feature.geometry()->vertexIdFromVertexNr( snapResult.snappedVertexNr, vid ) ) { continue; } // Add rubberband if not already added if ( !mMoveRubberBands.contains( snapFeatureId ) ) { QgsGeometryRubberBand* rb = new QgsGeometryRubberBand( mCanvas, feature.geometry()->type() ); rb->setOutlineColor( Qt::blue ); rb->setBrushStyle( Qt::NoBrush ); rb->setOutlineWidth( 2 ); QgsAbstractGeometryV2* rbGeom = feature.geometry()->geometry()->clone(); if ( mCanvas->mapSettings().layerTransform( vlayer ) ) rbGeom->transform( *mCanvas->mapSettings().layerTransform( vlayer ) ); rb->setGeometry( rbGeom ); mMoveRubberBands.insert( snapFeatureId, rb ); } // Add to list of vertices to be moved mMoveVertices[snapFeatureId].append( qMakePair( vid, toMapCoordinates( vlayer, feature.geometry()->geometry()->vertexAt( vid ) ) ) ); } } }
QgsGeometryRubberBand* QgsMapToolEdit::createGeometryRubberBand( QGis::GeometryType geometryType, bool alternativeBand ) const { QSettings settings; QgsGeometryRubberBand* rb = new QgsGeometryRubberBand( mCanvas, geometryType ); QColor color( settings.value( "/qgis/digitizing/line_color_red", 255 ).toInt(), settings.value( "/qgis/digitizing/line_color_green", 0 ).toInt(), settings.value( "/qgis/digitizing/line_color_blue", 0 ).toInt() ); double myAlpha = settings.value( "/qgis/digitizing/line_color_alpha", 200 ).toInt() / 255.0 ; if ( alternativeBand ) { myAlpha = myAlpha * settings.value( "/qgis/digitizing/line_color_alpha_scale", 0.75 ).toDouble(); rb->setLineStyle( Qt::DotLine ); } color.setAlphaF( myAlpha ); rb->setOutlineColor( color ); rb->setFillColor( color ); rb->show(); return rb; }