本文整理汇总了C++中QgsVectorLayer::selectedFeatureCount方法的典型用法代码示例。如果您正苦于以下问题:C++ QgsVectorLayer::selectedFeatureCount方法的具体用法?C++ QgsVectorLayer::selectedFeatureCount怎么用?C++ QgsVectorLayer::selectedFeatureCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QgsVectorLayer
的用法示例。
在下文中一共展示了QgsVectorLayer::selectedFeatureCount方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addToPopupMenu
void QgsLegendLayerFile::addToPopupMenu( QMenu& theMenu, QAction* toggleEditingAction )
{
QgsMapLayer* lyr = layer();
// zoom to layer extent
theMenu.addAction( QgisApp::getThemeIcon( "/mActionZoomToLayer.png" ),
tr( "&Zoom to layer extent" ), legend(), SLOT( legendLayerZoom() ) );
// show in overview
QAction* showInOverviewAction = theMenu.addAction( tr( "&Show in overview" ), this, SLOT( showInOverview() ) );
showInOverviewAction->setCheckable( true );
showInOverviewAction->blockSignals( true );
showInOverviewAction->setChecked( mLyr.isInOverview() );
showInOverviewAction->blockSignals( false );
// remove from canvas
theMenu.addAction( QgisApp::getThemeIcon( "/mActionRemove.png" ),
tr( "&Remove" ), legend(), SLOT( legendLayerRemove() ) );
theMenu.addSeparator();
if ( lyr->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>( lyr );
// attribute table
theMenu.addAction( tr( "&Open attribute table" ), this, SLOT( table() ) );
// editing
int cap = vlayer->dataProvider()->capabilities();
if ( cap & QgsVectorDataProvider::EditingCapabilities )
{
if ( toggleEditingAction )
{
theMenu.addAction( toggleEditingAction );
}
}
// save as shapefile
theMenu.addAction( tr( "Save as shapefile..." ), this, SLOT( saveAsShapefile() ) );
QAction* saveSelectionAction = theMenu.addAction( tr( "Save selection as shapefile..." ), this, SLOT( saveSelectionAsShapefile() ) );
if ( vlayer->selectedFeatureCount() == 0 )
{
saveSelectionAction->setEnabled( false );
}
theMenu.addSeparator();
}
else if ( lyr->type() == QgsMapLayer::RasterLayer )
{
// TODO: what was this for?
//QgsRasterLayer* rlayer = dynamic_cast<QgsRasterLayer*>(lyr);
//theMenu.addAction(tr("&Convert to..."), rlayer, SLOT(convertTo()));
}
// properties goes on bottom of menu for consistency with normal ui standards
// e.g. kde stuff
theMenu.addAction( tr( "&Properties" ), legend(), SLOT( legendLayerShowProperties() ) );
}
示例2: checkSelection
bool QgsMapToolAddPart::checkSelection()
{
//check if we operate on a vector layer
QgsVectorLayer *vlayer = currentVectorLayer();
if ( !vlayer )
{
notifyNotVectorLayer();
return false;
}
//inform user at the begin of the digitizing action that the island tool only works if exactly one feature is selected
int nSelectedFeatures = vlayer->selectedFeatureCount();
QString selectionErrorMsg;
if ( nSelectedFeatures < 1 )
{
selectionErrorMsg = tr( "No feature selected. Please select a feature with the selection tool or in the attribute table" );
}
else if ( nSelectedFeatures > 1 )
{
selectionErrorMsg = tr( "Several features are selected. Please select only one feature to which an part should be added." );
}
if ( !selectionErrorMsg.isEmpty() )
{
emit messageEmitted( tr( "Could not add part. %1" ).arg( selectionErrorMsg ), Qgis::Warning );
}
return selectionErrorMsg.isEmpty();
}
示例3: getDescriptionLayerShow
QString QgsSpatialQueryDialog::getDescriptionLayerShow( bool isTarget )
{
QgsVectorLayer* lyr = NULL;
QCheckBox * checkBox = NULL;
if ( isTarget )
{
lyr = mLayerTarget;
checkBox = ckbUsingSelectedTarget;
}
else
{
lyr = mLayerReference;
checkBox = ckbUsingSelectedReference;
}
QString sDescFeatures = checkBox->isChecked()
? tr( "%1 of %2" ).arg( lyr->selectedFeatureCount() ).arg( lyr->featureCount() )
: tr( "all = %1" ).arg( lyr->featureCount() );
return QString( "%1 (%2)" ).arg( lyr->name() ).arg( sDescFeatures );
} // QString QgsSpatialQueryDialog::getDescriptionLayerShow(bool isTarget)
示例4: evaluateCheckBoxLayer
void QgsSpatialQueryDialog::evaluateCheckBoxLayer( bool isTarget )
{
QgsVectorLayer* lyr = NULL;
QCheckBox* checkbox = NULL;
if ( isTarget )
{
lyr = mLayerTarget;
checkbox = ckbUsingSelectedTarget;
}
else
{
lyr = mLayerReference;
checkbox = ckbUsingSelectedReference;
}
int selectedCount = lyr->selectedFeatureCount();
bool isCheckBoxValid = ( lyr != NULL && selectedCount > 0 );
checkbox->setChecked( isCheckBoxValid );
checkbox->setEnabled( isCheckBoxValid );
QString textCheckBox = isCheckBoxValid
? tr( "%n selected geometries", "selected geometries", selectedCount )
: tr( "Selected geometries" );
checkbox->setText( textCheckBox );
} // void QgsSpatialQueryDialog::evaluateCheckBoxLayer(bool isTarget)
示例5: addToPopupMenu
void QgsLegendLayer::addToPopupMenu( QMenu& theMenu )
{
QgsMapLayer *lyr = layer();
QAction *toggleEditingAction = QgisApp::instance()->actionToggleEditing();
QAction *saveLayerEditsAction = QgisApp::instance()->actionSaveActiveLayerEdits();
QAction *allEditsAction = QgisApp::instance()->actionAllEdits();
// zoom to layer extent
theMenu.addAction( QgsApplication::getThemeIcon( "/mActionZoomToLayer.svg" ),
tr( "&Zoom to Layer Extent" ), legend(), SLOT( legendLayerZoom() ) );
if ( lyr->type() == QgsMapLayer::RasterLayer )
{
theMenu.addAction( tr( "&Zoom to Best Scale (100%)" ), legend(), SLOT( legendLayerZoomNative() ) );
QgsRasterLayer *rasterLayer = qobject_cast<QgsRasterLayer *>( lyr );
if ( rasterLayer && rasterLayer->rasterType() != QgsRasterLayer::Palette )
{
theMenu.addAction( tr( "&Stretch Using Current Extent" ), legend(), SLOT( legendLayerStretchUsingCurrentExtent() ) );
}
}
// show in overview
QAction* showInOverviewAction = theMenu.addAction( tr( "&Show in Overview" ), this, SLOT( showInOverview() ) );
showInOverviewAction->setCheckable( true );
showInOverviewAction->blockSignals( true );
showInOverviewAction->setChecked( mLyr.isInOverview() );
showInOverviewAction->blockSignals( false );
// remove from canvas
theMenu.addAction( QgsApplication::getThemeIcon( "/mActionRemoveLayer.svg" ), tr( "&Remove" ), QgisApp::instance(), SLOT( removeLayer() ) );
// duplicate layer
QAction* duplicateLayersAction = theMenu.addAction( QgsApplication::getThemeIcon( "/mActionDuplicateLayer.svg" ), tr( "&Duplicate" ), QgisApp::instance(), SLOT( duplicateLayers() ) );
// set layer crs
theMenu.addAction( QgsApplication::getThemeIcon( "/mActionSetCRS.png" ), tr( "&Set Layer CRS" ), QgisApp::instance(), SLOT( setLayerCRS() ) );
// assign layer crs to project
theMenu.addAction( QgsApplication::getThemeIcon( "/mActionSetProjectCRS.png" ), tr( "Set &Project CRS from Layer" ), QgisApp::instance(), SLOT( setProjectCRSFromLayer() ) );
theMenu.addSeparator();
if ( lyr->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( lyr );
// attribute table
theMenu.addAction( QgsApplication::getThemeIcon( "/mActionOpenTable.png" ), tr( "&Open Attribute Table" ),
QgisApp::instance(), SLOT( attributeTable() ) );
// allow editing
int cap = vlayer->dataProvider()->capabilities();
if ( cap & QgsVectorDataProvider::EditingCapabilities )
{
if ( toggleEditingAction )
{
theMenu.addAction( toggleEditingAction );
toggleEditingAction->setChecked( vlayer->isEditable() );
}
if ( saveLayerEditsAction && vlayer->isModified() )
{
theMenu.addAction( saveLayerEditsAction );
}
}
if ( allEditsAction->isEnabled() )
{
theMenu.addAction( allEditsAction );
}
// disable duplication of memory layers
if ( vlayer->storageType() == "Memory storage" && legend()->selectedLayers().count() == 1 )
{
duplicateLayersAction->setEnabled( false );
}
// save as vector file
theMenu.addAction( tr( "Save As..." ), QgisApp::instance(), SLOT( saveAsFile() ) );
// save selection as vector file
QAction* saveSelectionAsAction = theMenu.addAction( tr( "Save Selection As..." ), QgisApp::instance(), SLOT( saveSelectionAsVectorFile() ) );
if ( vlayer->selectedFeatureCount() == 0 )
{
saveSelectionAsAction->setEnabled( false );
}
if ( !vlayer->isEditable() && vlayer->dataProvider()->supportsSubsetString() && vlayer->vectorJoins().isEmpty() )
theMenu.addAction( tr( "&Filter..." ), QgisApp::instance(), SLOT( layerSubsetString() ) );
//show number of features in legend if requested
QAction* showNFeaturesAction = new QAction( tr( "Show Feature Count" ), &theMenu );
showNFeaturesAction->setCheckable( true );
showNFeaturesAction->setChecked( mShowFeatureCount );
QObject::connect( showNFeaturesAction, SIGNAL( toggled( bool ) ), this, SLOT( setShowFeatureCount( bool ) ) );
theMenu.addAction( showNFeaturesAction );
theMenu.addSeparator();
}
示例6: canvasReleaseEvent
void QgsMapToolAddPart::canvasReleaseEvent( QMouseEvent * e )
{
//check if we operate on a vector layer
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
if ( !vlayer )
{
notifyNotVectorLayer();
return;
}
if ( !vlayer->isEditable() )
{
notifyNotEditableLayer();
return;
}
//inform user at the begin of the digitising action that the island tool only works if exactly one feature is selected
int nSelectedFeatures = vlayer->selectedFeatureCount();
QString selectionErrorMsg;
if ( nSelectedFeatures < 1 )
{
selectionErrorMsg = tr( "No feature selected. Please select a feature with the selection tool or in the attribute table" );
}
else if ( nSelectedFeatures > 1 )
{
selectionErrorMsg = tr( "Several features are selected. Please select only one feature to which an part should be added." );
}
if ( !selectionErrorMsg.isEmpty() )
{
QMessageBox::critical( 0, tr( "Error. Could not add part." ), selectionErrorMsg );
stopCapturing();
return;
}
int errorCode;
switch ( mode() )
{
case CapturePoint:
{
QgsPoint layerPoint;
QgsPoint mapPoint;
if ( nextPoint( e->pos(), layerPoint, mapPoint ) != 0 )
{
QgsDebugMsg( "nextPoint failed" );
return;
}
vlayer->beginEditCommand( tr( "Part added" ) );
errorCode = vlayer->addPart( QList<QgsPoint>() << layerPoint );
}
break;
case CaptureLine:
case CapturePolygon:
{
//add point to list and to rubber band
if ( e->button() == Qt::LeftButton )
{
int error = addVertex( e->pos() );
if ( error == 1 )
{
QgsDebugMsg( "current layer is not a vector layer" );
return;
}
else if ( error == 2 )
{
//problem with coordinate transformation
QMessageBox::information( 0,
tr( "Coordinate transform error" ),
tr( "Cannot transform the point to the layers coordinate system" ) );
return;
}
startCapturing();
return;
}
else if ( e->button() != Qt::RightButton )
{
deleteTempRubberBand();
return;
}
if ( mode() == CapturePolygon )
{
//close polygon
closePolygon();
//avoid intersections
QgsGeometry* geom = QgsGeometry::fromPolygon( QgsPolygon() << points().toVector() );
if ( geom )
{
geom->avoidIntersections();
QgsPolygon poly = geom->asPolygon();
if ( poly.size() < 1 )
{
stopCapturing();
delete geom;
vlayer->destroyEditCommand();
//.........这里部分代码省略.........
示例7: canvasReleaseEvent
void QgsMapToolRotateFeature::canvasReleaseEvent( QgsMapMouseEvent *e )
{
if ( !mCanvas )
{
return;
}
QgsVectorLayer *vlayer = currentVectorLayer();
if ( !vlayer )
{
deleteRotationWidget();
deleteRubberband();
notifyNotVectorLayer();
return;
}
if ( e->button() == Qt::RightButton )
{
cancel();
return;
}
// place anchor point on CTRL + click
if ( e->modifiers() & Qt::ControlModifier )
{
if ( !mAnchorPoint )
{
return;
}
mAnchorPoint->setCenter( toMapCoordinates( e->pos() ) );
mStartPointMapCoords = toMapCoordinates( e->pos() );
mStPoint = e->pos();
return;
}
deleteRotationWidget();
// Initialize rotation if not yet active
if ( !mRotationActive )
{
mRotation = 0;
mRotationOffset = 0;
deleteRubberband();
mInitialPos = e->pos();
if ( !vlayer->isEditable() )
{
notifyNotEditableLayer();
return;
}
QgsPointXY layerCoords = toLayerCoordinates( vlayer, e->pos() );
double searchRadius = QgsTolerance::vertexSearchRadius( mCanvas->currentLayer(), mCanvas->mapSettings() );
QgsRectangle selectRect( layerCoords.x() - searchRadius, layerCoords.y() - searchRadius,
layerCoords.x() + searchRadius, layerCoords.y() + searchRadius );
if ( vlayer->selectedFeatureCount() == 0 )
{
QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest().setFilterRect( selectRect ).setNoAttributes() );
//find the closest feature
QgsGeometry pointGeometry = QgsGeometry::fromPointXY( layerCoords );
if ( pointGeometry.isNull() )
{
return;
}
double minDistance = std::numeric_limits<double>::max();
QgsFeature cf;
QgsFeature f;
while ( fit.nextFeature( f ) )
{
if ( f.hasGeometry() )
{
double currentDistance = pointGeometry.distance( f.geometry() );
if ( currentDistance < minDistance )
{
minDistance = currentDistance;
cf = f;
}
}
}
if ( minDistance == std::numeric_limits<double>::max() )
{
emit messageEmitted( tr( "Could not find a nearby feature in the current layer." ) );
return;
}
QgsRectangle bound = cf.geometry().boundingBox();
mStartPointMapCoords = toMapCoordinates( vlayer, bound.center() );
if ( !mAnchorPoint )
{
mAnchorPoint = qgis::make_unique<QgsVertexMarker>( mCanvas );
}
mAnchorPoint->setIconType( QgsVertexMarker::ICON_CROSS );
//.........这里部分代码省略.........
示例8: canvasPressEvent
void QgsMapToolMoveFeature::canvasPressEvent( QgsMapMouseEvent* e )
{
delete mRubberBand;
mRubberBand = nullptr;
QgsVectorLayer* vlayer = currentVectorLayer();
if ( !vlayer )
{
notifyNotVectorLayer();
return;
}
if ( !vlayer->isEditable() )
{
notifyNotEditableLayer();
return;
}
//find first geometry under mouse cursor and store iterator to it
QgsPoint layerCoords = toLayerCoordinates( vlayer, e->pos() );
QSettings settings;
double searchRadius = QgsTolerance::vertexSearchRadius( mCanvas->currentLayer(), mCanvas->mapSettings() );
QgsRectangle selectRect( layerCoords.x() - searchRadius, layerCoords.y() - searchRadius,
layerCoords.x() + searchRadius, layerCoords.y() + searchRadius );
if ( vlayer->selectedFeatureCount() == 0 )
{
QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest().setFilterRect( selectRect ).setSubsetOfAttributes( QgsAttributeList() ) );
//find the closest feature
QgsGeometry* pointGeometry = QgsGeometry::fromPoint( layerCoords );
if ( !pointGeometry )
{
return;
}
double minDistance = std::numeric_limits<double>::max();
QgsFeature cf;
QgsFeature f;
while ( fit.nextFeature( f ) )
{
if ( f.constGeometry() )
{
double currentDistance = pointGeometry->distance( *f.constGeometry() );
if ( currentDistance < minDistance )
{
minDistance = currentDistance;
cf = f;
}
}
}
delete pointGeometry;
if ( minDistance == std::numeric_limits<double>::max() )
{
return;
}
mMovedFeatures.clear();
mMovedFeatures << cf.id(); //todo: take the closest feature, not the first one...
mRubberBand = createRubberBand( vlayer->geometryType() );
mRubberBand->setToGeometry( cf.constGeometry(), vlayer );
}
else
{
mMovedFeatures = vlayer->selectedFeaturesIds();
mRubberBand = createRubberBand( vlayer->geometryType() );
QgsFeature feat;
QgsFeatureIterator it = vlayer->selectedFeaturesIterator( QgsFeatureRequest().setSubsetOfAttributes( QgsAttributeList() ) );
while ( it.nextFeature( feat ) )
{
mRubberBand->addGeometry( feat.constGeometry(), vlayer );
}
}
mStartPointMapCoords = toMapCoordinates( e->pos() );
mRubberBand->setColor( QColor( 255, 0, 0, 65 ) );
mRubberBand->setWidth( 2 );
mRubberBand->show();
}
示例9: getDescriptionInvalidFeaturesShow
QString QgsSpatialQueryDialog::getDescriptionInvalidFeaturesShow( bool isTarget )
{
QgsVectorLayer* lyr = NULL;
QCheckBox* checkBox = NULL;
int totalInvalid = 0;
if ( isTarget )
{
lyr = mLayerTarget;
checkBox = ckbUsingSelectedTarget;
totalInvalid = mFeatureInvalidTarget.size();
}
else
{
lyr = mLayerReference;
checkBox = ckbUsingSelectedReference;
totalInvalid = mFeatureInvalidReference.size();
}
QString sDescFeatures = checkBox->isChecked()
? tr( "%1 of %2(selected features)" ).arg( totalInvalid ).arg( lyr->selectedFeatureCount() )
: tr( "%1 of %2" ).arg( totalInvalid ).arg( lyr->featureCount() );
return QString( "%1: %2" ).arg( lyr->name() ).arg( sDescFeatures );
} // QString QgsSpatialQueryDialog::getDescriptionInvalidFeatures(bool isTarget)
示例10: if
//.........这里部分代码省略.........
if ( layer && layer->isSpatial() )
{
// set layer scale visibility
menu->addAction( tr( "&Set Layer Scale Visibility…" ), QgisApp::instance(), SLOT( setLayerScaleVisibility() ) );
if ( !layer->isInScaleRange( mCanvas->scale() ) )
menu->addAction( tr( "Zoom to &Visible Scale" ), QgisApp::instance(), SLOT( zoomToLayerScale() ) );
QMenu *menuSetCRS = new QMenu( tr( "Set CRS" ), menu );
// set layer crs
QAction *actionSetLayerCrs = new QAction( tr( "Set Layer CRS…" ), menuSetCRS );
connect( actionSetLayerCrs, &QAction::triggered, QgisApp::instance(), &QgisApp::setLayerCrs );
menuSetCRS->addAction( actionSetLayerCrs );
// assign layer crs to project
QAction *actionSetProjectCrs = new QAction( tr( "Set &Project CRS from Layer" ), menuSetCRS );
connect( actionSetProjectCrs, &QAction::triggered, QgisApp::instance(), &QgisApp::setProjectCrsFromLayer );
menuSetCRS->addAction( actionSetProjectCrs );
menu->addMenu( menuSetCRS );
}
menu->addSeparator();
if ( vlayer )
{
// save as vector file
QMenu *menuExportVector = new QMenu( tr( "Export" ), menu );
QAction *actionSaveAs = new QAction( tr( "Save Features As…" ), menuExportVector );
connect( actionSaveAs, &QAction::triggered, QgisApp::instance(), [ = ] { QgisApp::instance()->saveAsFile(); } );
menuExportVector->addAction( actionSaveAs );
QAction *actionSaveSelectedFeaturesAs = new QAction( tr( "Save Selected Features As…" ), menuExportVector );
connect( actionSaveSelectedFeaturesAs, &QAction::triggered, QgisApp::instance(), [ = ] { QgisApp::instance()->saveAsFile( nullptr, true ); } );
actionSaveSelectedFeaturesAs->setEnabled( vlayer->selectedFeatureCount() > 0 );
menuExportVector->addAction( actionSaveSelectedFeaturesAs );
QAction *actionSaveAsDefinitionLayer = new QAction( tr( "Save as Layer Definition File…" ), menuExportVector );
connect( actionSaveAsDefinitionLayer, &QAction::triggered, QgisApp::instance(), &QgisApp::saveAsLayerDefinition );
menuExportVector->addAction( actionSaveAsDefinitionLayer );
if ( vlayer->isSpatial() )
{
QAction *actionSaveStyle = new QAction( tr( "Save as QGIS Layer Style File…" ), menuExportVector );
connect( actionSaveStyle, &QAction::triggered, QgisApp::instance(), [ = ] { QgisApp::instance()->saveStyleFile(); } );
menuExportVector->addAction( actionSaveStyle );
}
menu->addMenu( menuExportVector );
}
else if ( rlayer )
{
QMenu *menuExportRaster = new QMenu( tr( "Export" ), menu );
QAction *actionSaveAs = new QAction( tr( "Save As…" ), menuExportRaster );
QAction *actionSaveAsDefinitionLayer = new QAction( tr( "Save as Layer Definition File…" ), menuExportRaster );
QAction *actionSaveStyle = new QAction( tr( "Save as QGIS Layer Style File…" ), menuExportRaster );
connect( actionSaveAs, &QAction::triggered, QgisApp::instance(), [ = ] { QgisApp::instance()->saveAsFile(); } );
menuExportRaster->addAction( actionSaveAs );
connect( actionSaveAsDefinitionLayer, &QAction::triggered, QgisApp::instance(), &QgisApp::saveAsLayerDefinition );
menuExportRaster->addAction( actionSaveAsDefinitionLayer );
connect( actionSaveStyle, &QAction::triggered, QgisApp::instance(), [ = ] { QgisApp::instance()->saveStyleFile(); } );
menuExportRaster->addAction( actionSaveStyle );
menu->addMenu( menuExportRaster );
}
else if ( layer && layer->type() == QgsMapLayer::PluginLayer && mView->selectedLayerNodes().count() == 1 )
{
// disable duplication of plugin layers
duplicateLayersAction->setEnabled( false );
}
示例11: cadCanvasReleaseEvent
void QgsMapToolMoveFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
{
QgsVectorLayer *vlayer = currentVectorLayer();
if ( !vlayer || !vlayer->isEditable() )
{
delete mRubberBand;
mRubberBand = nullptr;
mSnapIndicator->setMatch( QgsPointLocator::Match() );
cadDockWidget()->clear();
notifyNotEditableLayer();
return;
}
if ( !mRubberBand )
{
//find first geometry under mouse cursor and store iterator to it
QgsPointXY layerCoords = toLayerCoordinates( vlayer, e->mapPoint() );
double searchRadius = QgsTolerance::vertexSearchRadius( mCanvas->currentLayer(), mCanvas->mapSettings() );
QgsRectangle selectRect( layerCoords.x() - searchRadius, layerCoords.y() - searchRadius,
layerCoords.x() + searchRadius, layerCoords.y() + searchRadius );
if ( vlayer->selectedFeatureCount() == 0 )
{
QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest().setFilterRect( selectRect ).setNoAttributes() );
//find the closest feature
QgsGeometry pointGeometry = QgsGeometry::fromPointXY( layerCoords );
if ( pointGeometry.isNull() )
{
cadDockWidget()->clear();
return;
}
double minDistance = std::numeric_limits<double>::max();
QgsFeature cf;
QgsFeature f;
while ( fit.nextFeature( f ) )
{
if ( f.hasGeometry() )
{
double currentDistance = pointGeometry.distance( f.geometry() );
if ( currentDistance < minDistance )
{
minDistance = currentDistance;
cf = f;
}
}
}
if ( minDistance == std::numeric_limits<double>::max() )
{
cadDockWidget()->clear();
return;
}
mMovedFeatures.clear();
mMovedFeatures << cf.id(); //todo: take the closest feature, not the first one...
mRubberBand = createRubberBand( vlayer->geometryType() );
mRubberBand->setToGeometry( cf.geometry(), vlayer );
}
else
{
mMovedFeatures = vlayer->selectedFeatureIds();
mRubberBand = createRubberBand( vlayer->geometryType() );
QgsFeature feat;
QgsFeatureIterator it = vlayer->getSelectedFeatures( QgsFeatureRequest().setNoAttributes() );
bool allFeaturesInView = true;
QgsRectangle viewRect = mCanvas->mapSettings().mapToLayerCoordinates( vlayer, mCanvas->extent() );
while ( it.nextFeature( feat ) )
{
mRubberBand->addGeometry( feat.geometry(), vlayer );
if ( allFeaturesInView && !viewRect.intersects( feat.geometry().boundingBox() ) )
allFeaturesInView = false;
}
if ( !allFeaturesInView )
{
// for extra safety to make sure we are not modifying geometries by accident
int res = QMessageBox::warning( mCanvas, tr( "Move features" ),
tr( "Some of the selected features are outside of the current map view. Would you still like to continue?" ),
QMessageBox::Yes | QMessageBox::No );
if ( res != QMessageBox::Yes )
{
mMovedFeatures.clear();
delete mRubberBand;
mRubberBand = nullptr;
mSnapIndicator->setMatch( QgsPointLocator::Match() );
return;
}
}
}
mStartPointMapCoords = e->mapPoint();
//.........这里部分代码省略.........