本文整理汇总了C++中QgsVectorLayer::destroyEditCommand方法的典型用法代码示例。如果您正苦于以下问题:C++ QgsVectorLayer::destroyEditCommand方法的具体用法?C++ QgsVectorLayer::destroyEditCommand怎么用?C++ QgsVectorLayer::destroyEditCommand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QgsVectorLayer
的用法示例。
在下文中一共展示了QgsVectorLayer::destroyEditCommand方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: canvasReleaseEvent
void QgsMapToolOffsetCurve::canvasReleaseEvent( QMouseEvent * e )
{
Q_UNUSED( e );
QgsVectorLayer* vlayer = currentVectorLayer();
if ( !vlayer )
{
deleteRubberBandAndGeometry();
return;
}
if ( !mGeometryModified )
{
deleteRubberBandAndGeometry();
vlayer->destroyEditCommand();
return;
}
if ( mMultiPartGeometry )
{
mModifiedGeometry.convertToMultiType();
}
vlayer->beginEditCommand( tr( "Offset curve" ) );
bool editOk;
if ( mSourceLayerId == vlayer->id() && !mForceCopy )
{
editOk = vlayer->changeGeometry( mModifiedFeature, &mModifiedGeometry );
}
else
{
QgsFeature f;
f.setGeometry( mModifiedGeometry );
//add empty values for all fields (allows inserting attribute values via the feature form in the same session)
QgsAttributes attrs( vlayer->pendingFields().count() );
const QgsFields& fields = vlayer->pendingFields();
for ( int idx = 0; idx < fields.count(); ++idx )
{
attrs[idx] = QVariant();
}
f.setAttributes( attrs );
editOk = vlayer->addFeature( f );
}
if ( editOk )
{
vlayer->endEditCommand();
}
else
{
vlayer->destroyEditCommand();
}
deleteRubberBandAndGeometry();
deleteDistanceItem();
delete mSnapVertexMarker; mSnapVertexMarker = 0;
mForceCopy = false;
mCanvas->refresh();
}
示例2: showHideLabels
void QgsMapToolShowHideLabels::showHideLabels( QMouseEvent * e )
{
QgsMapLayer* layer = mCanvas->currentLayer();
QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>( layer );
if ( !vlayer )
{
QgsDebugMsg( "Failed to cast label layer to vector layer" );
return;
}
if ( !vlayer->isEditable() )
{
QgsDebugMsg( "Vector layer not editable, skipping label" );
return;
}
bool doHide = e->modifiers() & Qt::ShiftModifier;
bool labelChanged = false;
QString editTxt = doHide ? tr( "Hid labels" ) : tr( "Showed labels" );
vlayer->beginEditCommand( editTxt );
if ( !doHide )
{
QgsDebugMsg( "Showing labels operation" );
QgsFeatureIds selectedFeatIds;
if ( !selectedFeatures( vlayer, selectedFeatIds ) )
{
vlayer->destroyEditCommand();
return;
}
QgsDebugMsg( "Number of selected labels or features: " + QString::number( selectedFeatIds.size() ) );
if ( selectedFeatIds.isEmpty() )
{
vlayer->destroyEditCommand();
return;
}
Q_FOREACH ( QgsFeatureId fid, selectedFeatIds )
{
mCurrentLabel.pos.featureId = fid;
mCurrentLabel.pos.isDiagram = false;
bool labChanged = showHide( vlayer, true );
mCurrentLabel.pos.isDiagram = true;
bool diagChanged = showHide( vlayer, true );
if ( labChanged || diagChanged )
{
// TODO: highlight features (maybe with QTimer?)
labelChanged = labelChanged || true;
}
}
示例3: showHideLabels
void QgsMapToolShowHideLabels::showHideLabels( QMouseEvent *e )
{
QgsMapLayer *layer = mCanvas->currentLayer();
QgsVectorLayer *vlayer = dynamic_cast<QgsVectorLayer *>( layer );
if ( !vlayer )
return;
bool doHide = e->modifiers() & Qt::ShiftModifier;
QString editTxt = doHide ? tr( "Hid labels" ) : tr( "Showed labels" );
vlayer->beginEditCommand( editTxt );
bool labelChanged = false;
if ( doHide )
{
QList<QgsLabelPosition> positions;
if ( selectedLabelFeatures( vlayer, positions ) )
{
for ( const QgsLabelPosition &pos : qgis::as_const( positions ) )
{
if ( showHide( pos, false ) )
labelChanged = true;
}
}
}
else
{
QgsFeatureIds fids;
if ( selectedFeatures( vlayer, fids ) )
{
for ( const QgsFeatureId &fid : qgis::as_const( fids ) )
{
QgsLabelPosition pos;
pos.featureId = fid;
pos.layerID = vlayer->id();
// we want to show labels...
pos.isDiagram = false;
if ( showHide( pos, true ) )
labelChanged = true;
// ... and diagrams
pos.isDiagram = true;
if ( showHide( pos, true ) )
labelChanged = true;
}
}
}
if ( labelChanged )
{
vlayer->endEditCommand();
vlayer->triggerRepaint();
}
else
{
vlayer->destroyEditCommand();
}
}
示例4: cadCanvasReleaseEvent
//.........这里部分代码省略.........
{
closePolygon();
}
//does compoundcurve contain circular strings?
//does provider support circular strings?
bool hasCurvedSegments = captureCurve()->hasCurvedSegments();
bool providerSupportsCurvedSegments = vlayer->dataProvider()->capabilities() & QgsVectorDataProvider::CircularGeometries;
QgsCurve *curveToAdd = nullptr;
if ( hasCurvedSegments && providerSupportsCurvedSegments )
{
curveToAdd = captureCurve()->clone();
}
else
{
curveToAdd = captureCurve()->curveToLine();
}
vlayer->beginEditCommand( tr( "Part added" ) );
if ( mode() == CapturePolygon )
{
//avoid intersections
QgsCurvePolygon *cp = new QgsCurvePolygon();
cp->setExteriorRing( curveToAdd );
QgsGeometry *geom = new QgsGeometry( cp );
geom->avoidIntersections( QgsProject::instance()->avoidIntersectionsLayers() );
const QgsCurvePolygon *cpGeom = qgsgeometry_cast<const QgsCurvePolygon *>( geom->constGet() );
if ( !cpGeom )
{
stopCapturing();
delete geom;
vlayer->destroyEditCommand();
return;
}
errorCode = vlayer->addPart( cpGeom->exteriorRing()->clone() );
delete geom;
}
else
{
errorCode = vlayer->addPart( curveToAdd );
}
stopCapturing();
}
break;
default:
Q_ASSERT( !"invalid capture mode" );
errorCode = 6;
break;
}
QString errorMessage;
switch ( errorCode )
{
case 0:
{
// remove previous message
emit messageDiscarded();
//add points to other features to keep topology up-to-date
bool topologicalEditing = QgsProject::instance()->topologicalEditing();
if ( topologicalEditing )
{
addTopologicalPoints( points() );
示例5: canvasReleaseEvent
void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
{
QgsDebugMsg( "entered." );
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
if ( !vlayer )
{
notifyNotVectorLayer();
return;
}
QGis::WkbType layerWKBType = vlayer->wkbType();
QgsVectorDataProvider* provider = vlayer->dataProvider();
if ( !( provider->capabilities() & QgsVectorDataProvider::AddFeatures ) )
{
QMessageBox::information( 0, tr( "Layer cannot be added to" ),
tr( "The data provider for this layer does not support the addition of features." ) );
return;
}
if ( !vlayer->isEditable() )
{
notifyNotEditableLayer();
return;
}
// POINT CAPTURING
if ( mode() == CapturePoint )
{
//check we only use this tool for point/multipoint layers
if ( vlayer->geometryType() != QGis::Point )
{
QMessageBox::information( 0, tr( "Wrong editing tool" ),
tr( "Cannot apply the 'capture point' tool on this vector layer" ) );
return;
}
QgsPoint idPoint; //point in map coordinates
QList<QgsSnappingResult> snapResults;
QgsPoint savePoint; //point in layer coordinates
if ( mSnapper.snapToBackgroundLayers( e->pos(), snapResults ) == 0 )
{
idPoint = snapPointFromResults( snapResults, e->pos() );
try
{
savePoint = toLayerCoordinates( vlayer, idPoint );
QgsDebugMsg( "savePoint = " + savePoint.toString() );
}
catch ( QgsCsException &cse )
{
Q_UNUSED( cse );
QMessageBox::information( 0, tr( "Coordinate transform error" ),
tr( "Cannot transform the point to the layers coordinate system" ) );
return;
}
}
//only do the rest for provider with feature addition support
//note that for the grass provider, this will return false since
//grass provider has its own mechanism of feature addition
if ( provider->capabilities() & QgsVectorDataProvider::AddFeatures )
{
QgsFeature* f = new QgsFeature( 0, "WKBPoint" );
QgsGeometry *g = 0;
if ( layerWKBType == QGis::WKBPoint || layerWKBType == QGis::WKBPoint25D )
{
g = QgsGeometry::fromPoint( savePoint );
}
else if ( layerWKBType == QGis::WKBMultiPoint || layerWKBType == QGis::WKBMultiPoint25D )
{
g = QgsGeometry::fromMultiPoint( QgsMultiPoint() << savePoint );
}
f->setGeometry( g );
vlayer->beginEditCommand( tr( "Feature added" ) );
if ( addFeature( vlayer, f ) )
{
vlayer->endEditCommand();
}
else
{
delete f;
vlayer->destroyEditCommand();
}
mCanvas->refresh();
}
}
else if ( mode() == CaptureLine || mode() == CapturePolygon )
{
//check we only use the line tool for line/multiline layers
if ( mode() == CaptureLine && vlayer->geometryType() != QGis::Line )
//.........这里部分代码省略.........
示例6: cadCanvasReleaseEvent
void QgsMapToolFillRing::cadCanvasReleaseEvent( QgsMapMouseEvent * 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;
}
//add point to list and to rubber band
if ( e->button() == Qt::LeftButton )
{
int error = addVertex( e->mapPoint() );
if ( error == 1 )
{
//current layer is not a vector layer
return;
}
else if ( error == 2 )
{
//problem with coordinate transformation
emit messageEmitted( tr( "Cannot transform the point to the layers coordinate system" ), QgsMessageBar::WARNING );
return;
}
startCapturing();
}
else if ( e->button() == Qt::RightButton )
{
if ( !isCapturing() )
return;
deleteTempRubberBand();
closePolygon();
vlayer->beginEditCommand( tr( "Ring added and filled" ) );
QList< QgsPoint > pointList = points();
QgsFeatureId modifiedFid;
int addRingReturnCode = vlayer->addRing( pointList, &modifiedFid );
if ( addRingReturnCode != 0 )
{
QString errorMessage;
//todo: open message box to communicate errors
if ( addRingReturnCode == 1 )
{
errorMessage = tr( "a problem with geometry type occured" );
}
else if ( addRingReturnCode == 2 )
{
errorMessage = tr( "the inserted Ring is not closed" );
}
else if ( addRingReturnCode == 3 )
{
errorMessage = tr( "the inserted Ring is not a valid geometry" );
}
else if ( addRingReturnCode == 4 )
{
errorMessage = tr( "the inserted Ring crosses existing rings" );
}
else if ( addRingReturnCode == 5 )
{
errorMessage = tr( "the inserted Ring is not contained in a feature" );
}
else
{
errorMessage = tr( "an unknown error occured" );
}
emit messageEmitted( tr( "could not add ring since %1." ).arg( errorMessage ), QgsMessageBar::CRITICAL );
vlayer->destroyEditCommand();
}
else
{
// find parent feature and get it attributes
double xMin, xMax, yMin, yMax;
QgsRectangle bBox;
xMin = std::numeric_limits<double>::max();
xMax = -std::numeric_limits<double>::max();
yMin = std::numeric_limits<double>::max();
yMax = -std::numeric_limits<double>::max();
Q_FOREACH ( const QgsPoint& point, pointList )
{
xMin = qMin( xMin, point.x() );
xMax = qMax( xMax, point.x() );
yMin = qMin( yMin, point.y() );
yMax = qMax( yMax, point.y() );
}
bBox.setXMinimum( xMin );
//.........这里部分代码省略.........
示例7: 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();
//.........这里部分代码省略.........
示例8: canvasReleaseEvent
void QgsMapToolReshape::canvasReleaseEvent( QMouseEvent * e )
{
//check if we operate on a vector layer //todo: move this to a function in parent class to avoid duplication
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
if ( !vlayer )
{
notifyNotVectorLayer();
return;
}
if ( !vlayer->isEditable() )
{
notifyNotEditableLayer();
return;
}
//add point to list and to rubber band
if ( e->button() == Qt::LeftButton )
{
int error = addVertex( e->pos() );
if ( error == 1 )
{
//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();
}
else if ( e->button() == Qt::RightButton )
{
deleteTempRubberBand();
//find out bounding box of mCaptureList
if ( size() < 1 )
{
stopCapturing();
return;
}
QgsPoint firstPoint = points().at( 0 );
QgsRectangle bbox( firstPoint.x(), firstPoint.y(), firstPoint.x(), firstPoint.y() );
for ( int i = 1; i < size(); ++i )
{
bbox.combineExtentWith( points().at( i ).x(), points().at( i ).y() );
}
//query all the features that intersect bounding box of capture line
QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest().setFilterRect( bbox ).setSubsetOfAttributes( QgsAttributeList() ) );
QgsFeature f;
int reshapeReturn;
bool reshapeDone = false;
vlayer->beginEditCommand( tr( "Reshape" ) );
while ( fit.nextFeature( f ) )
{
//query geometry
//call geometry->reshape(mCaptureList)
//register changed geometry in vector layer
QgsGeometry* geom = f.geometry();
if ( geom )
{
reshapeReturn = geom->reshapeGeometry( points() );
if ( reshapeReturn == 0 )
{
vlayer->changeGeometry( f.id(), geom );
reshapeDone = true;
}
}
}
if ( reshapeDone )
{
vlayer->endEditCommand();
}
else
{
vlayer->destroyEditCommand();
}
stopCapturing();
}
}
示例9: canvasReleaseEvent
void QgsMapToolAddRing::canvasReleaseEvent( QMouseEvent * e )
{
emit messageDiscarded();
//check if we operate on a vector layer
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
if ( !vlayer )
{
notifyNotVectorLayer();
return;
}
if ( !vlayer->isEditable() )
{
notifyNotEditableLayer();
return;
}
//add point to list and to rubber band
if ( e->button() == Qt::LeftButton )
{
int error = addVertex( e->pos() );
if ( error == 1 )
{
//current layer is not a vector layer
return;
}
else if ( error == 2 )
{
//problem with coordinate transformation
emit messageEmitted( tr( "Cannot transform the point to the layers coordinate system" ), QgsMessageBar::WARNING );
return;
}
startCapturing();
}
else if ( e->button() == Qt::RightButton )
{
if ( !isCapturing() )
return;
deleteTempRubberBand();
closePolygon();
vlayer->beginEditCommand( tr( "Ring added" ) );
int addRingReturnCode = vlayer->addRing( points() );
if ( addRingReturnCode != 0 )
{
QString errorMessage;
//todo: open message box to communicate errors
if ( addRingReturnCode == 1 )
{
errorMessage = tr( "a problem with geometry type occured" );
}
else if ( addRingReturnCode == 2 )
{
errorMessage = tr( "the inserted ring is not closed" );
}
else if ( addRingReturnCode == 3 )
{
errorMessage = tr( "the inserted ring is not a valid geometry" );
}
else if ( addRingReturnCode == 4 )
{
errorMessage = tr( "the inserted ring crosses existing rings" );
}
else if ( addRingReturnCode == 5 )
{
errorMessage = tr( "the inserted ring is not contained in a feature" );
}
else
{
errorMessage = tr( "an unknown error occured" );
}
emit messageEmitted( tr( "could not add ring since %1." ).arg( errorMessage ), QgsMessageBar::CRITICAL );
vlayer->destroyEditCommand();
}
else
{
vlayer->endEditCommand();
}
stopCapturing();
}
}
示例10: canvasReleaseEvent
void QgsMapToolFillRing::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;
}
//add point to list and to rubber band
if ( e->button() == Qt::LeftButton )
{
int error = addVertex( e->pos() );
if ( error == 1 )
{
//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();
}
else if ( e->button() == Qt::RightButton )
{
deleteTempRubberBand();
closePolygon();
vlayer->beginEditCommand( tr( "Ring added and filled" ) );
int addRingReturnCode = vlayer->addRing( points() );
if ( addRingReturnCode != 0 )
{
QString errorMessage;
//todo: open message box to communicate errors
if ( addRingReturnCode == 1 )
{
errorMessage = tr( "A problem with geometry type occured" );
}
else if ( addRingReturnCode == 2 )
{
errorMessage = tr( "The inserted Ring is not closed" );
}
else if ( addRingReturnCode == 3 )
{
errorMessage = tr( "The inserted Ring is not a valid geometry" );
}
else if ( addRingReturnCode == 4 )
{
errorMessage = tr( "The inserted Ring crosses existing rings" );
}
else if ( addRingReturnCode == 5 )
{
errorMessage = tr( "The inserted Ring is not contained in a feature" );
}
else
{
errorMessage = tr( "An unknown error occured" );
}
QMessageBox::critical( 0, tr( "Error, could not add ring" ), errorMessage );
vlayer->destroyEditCommand();
}
else
{
// find parent feature and get it attributes
double xMin, xMax, yMin, yMax;
QgsRectangle bBox;
xMin = std::numeric_limits<double>::max();
xMax = -std::numeric_limits<double>::max();
yMin = std::numeric_limits<double>::max();
yMax = -std::numeric_limits<double>::max();
for ( QList<QgsPoint>::const_iterator it = points().constBegin(); it != points().constEnd(); ++it )
{
if ( it->x() < xMin )
{
xMin = it->x();
}
if ( it->x() > xMax )
{
xMax = it->x();
}
if ( it->y() < yMin )
{
yMin = it->y();
}
//.........这里部分代码省略.........
示例11: cadCanvasReleaseEvent
void QgsMapToolAddRing::cadCanvasReleaseEvent( QgsMapMouseEvent * e )
{
emit messageDiscarded();
//check if we operate on a vector layer
QgsVectorLayer *vlayer = currentVectorLayer();
if ( !vlayer )
{
notifyNotVectorLayer();
return;
}
if ( !vlayer->isEditable() )
{
notifyNotEditableLayer();
return;
}
//add point to list and to rubber band
if ( e->button() == Qt::LeftButton )
{
int error = addVertex( e->mapPoint() );
if ( error == 1 )
{
//current layer is not a vector layer
return;
}
else if ( error == 2 )
{
//problem with coordinate transformation
emit messageEmitted( tr( "Cannot transform the point to the layers coordinate system" ), QgsMessageBar::WARNING );
return;
}
startCapturing();
}
else if ( e->button() == Qt::RightButton )
{
if ( !isCapturing() )
return;
deleteTempRubberBand();
closePolygon();
vlayer->beginEditCommand( tr( "Ring added" ) );
//does compoundcurve contain circular strings?
//does provider support circular strings?
bool hasCurvedSegments = captureCurve()->hasCurvedSegments();
bool providerSupportsCurvedSegments = vlayer->dataProvider()->capabilities() & QgsVectorDataProvider::CircularGeometries;
QgsCurveV2* curveToAdd = 0;
if ( hasCurvedSegments && providerSupportsCurvedSegments )
{
curveToAdd = dynamic_cast<QgsCurveV2*>( captureCurve()->clone() );
}
else
{
curveToAdd = captureCurve()->curveToLine();
}
int addRingReturnCode = vlayer->addRing( curveToAdd );
if ( addRingReturnCode != 0 )
{
QString errorMessage;
//todo: open message box to communicate errors
if ( addRingReturnCode == 1 )
{
errorMessage = tr( "a problem with geometry type occured" );
}
else if ( addRingReturnCode == 2 )
{
errorMessage = tr( "the inserted ring is not closed" );
}
else if ( addRingReturnCode == 3 )
{
errorMessage = tr( "the inserted ring is not a valid geometry" );
}
else if ( addRingReturnCode == 4 )
{
errorMessage = tr( "the inserted ring crosses existing rings" );
}
else if ( addRingReturnCode == 5 )
{
errorMessage = tr( "the inserted ring is not contained in a feature" );
}
else
{
errorMessage = tr( "an unknown error occured" );
}
emit messageEmitted( tr( "could not add ring since %1." ).arg( errorMessage ), QgsMessageBar::CRITICAL );
vlayer->destroyEditCommand();
}
else
{
vlayer->endEditCommand();
}
//.........这里部分代码省略.........
示例12: showHideLabels
void QgsMapToolShowHideLabels::showHideLabels( QMouseEvent * e )
{
QgsMapLayer* layer = mCanvas->currentLayer();
QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>( layer );
if ( !vlayer )
{
QgsDebugMsg( "Failed to cast label layer to vector layer" );
return;
}
if ( !vlayer->isEditable() )
{
QgsDebugMsg( "Vector layer not editable, skipping label" );
return;
}
bool doHide = e->modifiers() & Qt::ShiftModifier ? true : false;
QgsFeatureIds selectedFeatIds;
if ( !doHide )
{
QgsDebugMsg( "Showing labels operation" );
if ( !selectedFeatures( vlayer, selectedFeatIds ) )
{
return;
}
}
else
{
QgsDebugMsg( "Hiding labels operation" );
if ( !selectedLabelFeatures( vlayer, selectedFeatIds ) )
{
return;
}
}
QgsDebugMsg( "Number of selected labels or features: " + QString::number( selectedFeatIds.size() ) );
if ( selectedFeatIds.isEmpty() )
{
return;
}
bool labelChanged = false;
QString editTxt = doHide ? tr( "Hid labels" ) : tr( "Showed labels" );
vlayer->beginEditCommand( editTxt );
foreach ( const QgsFeatureId &fid, selectedFeatIds )
{
if ( showHideLabel( vlayer, fid, doHide ) )
{
// TODO: highlight features (maybe with QTimer?)
labelChanged = true;
}
}
if ( labelChanged )
{
vlayer->endEditCommand();
mCanvas->refresh();
}
else
{
vlayer->destroyEditCommand();
}
}
示例13: cadCanvasReleaseEvent
void QgsMapToolReshape::cadCanvasReleaseEvent( QgsMapMouseEvent * e )
{
//check if we operate on a vector layer //todo: move this to a function in parent class to avoid duplication
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
if ( !vlayer )
{
notifyNotVectorLayer();
return;
}
if ( !vlayer->isEditable() )
{
notifyNotEditableLayer();
return;
}
//add point to list and to rubber band
if ( e->button() == Qt::LeftButton )
{
int error = addVertex( e->mapPoint(), e->mapPointMatch() );
if ( error == 1 )
{
//current layer is not a vector layer
return;
}
else if ( error == 2 )
{
//problem with coordinate transformation
emit messageEmitted( tr( "Cannot transform the point to the layers coordinate system" ), QgsMessageBar::WARNING );
return;
}
startCapturing();
}
else if ( e->button() == Qt::RightButton )
{
deleteTempRubberBand();
//find out bounding box of mCaptureList
if ( size() < 1 )
{
stopCapturing();
return;
}
QgsPoint firstPoint = points().at( 0 );
QgsRectangle bbox( firstPoint.x(), firstPoint.y(), firstPoint.x(), firstPoint.y() );
for ( int i = 1; i < size(); ++i )
{
bbox.combineExtentWith( points().at( i ).x(), points().at( i ).y() );
}
//query all the features that intersect bounding box of capture line
QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest().setFilterRect( bbox ).setSubsetOfAttributes( QgsAttributeList() ) );
QgsFeature f;
int reshapeReturn;
bool reshapeDone = false;
vlayer->beginEditCommand( tr( "Reshape" ) );
while ( fit.nextFeature( f ) )
{
//query geometry
//call geometry->reshape(mCaptureList)
//register changed geometry in vector layer
QgsGeometry* geom = f.geometry();
if ( geom )
{
reshapeReturn = geom->reshapeGeometry( points() );
if ( reshapeReturn == 0 )
{
//avoid intersections on polygon layers
if ( vlayer->geometryType() == QGis::Polygon )
{
//ignore all current layer features as they should be reshaped too
QMap<QgsVectorLayer*, QSet<QgsFeatureId> > ignoreFeatures;
ignoreFeatures.insert( vlayer, vlayer->allFeatureIds() );
if ( geom->avoidIntersections( ignoreFeatures ) != 0 )
{
emit messageEmitted( tr( "An error was reported during intersection removal" ), QgsMessageBar::CRITICAL );
vlayer->destroyEditCommand();
stopCapturing();
return;
}
if ( geom->isGeosEmpty() ) //intersection removal might have removed the whole geometry
{
emit messageEmitted( tr( "The feature cannot be reshaped because the resulting geometry is empty" ), QgsMessageBar::CRITICAL );
vlayer->destroyEditCommand();
stopCapturing();
return;
}
}
vlayer->changeGeometry( f.id(), geom );
reshapeDone = true;
}
}
}
//.........这里部分代码省略.........
示例14: applyOffset
void QgsMapToolOffsetCurve::applyOffset()
{
QgsVectorLayer* layer = currentVectorLayer();
if ( !layer )
{
deleteRubberBandAndGeometry();
notifyNotVectorLayer();
return;
}
// no modification
if ( !mGeometryModified )
{
deleteRubberBandAndGeometry();
layer->destroyEditCommand();
deleteDistanceWidget();
return;
}
if ( mMultiPartGeometry )
{
mModifiedGeometry.convertToMultiType();
}
layer->beginEditCommand( tr( "Offset curve" ) );
bool editOk;
if ( mSourceLayerId == layer->id() && !mForceCopy )
{
editOk = layer->changeGeometry( mModifiedFeature, &mModifiedGeometry );
}
else
{
QgsFeature f;
f.setGeometry( mModifiedGeometry );
//add empty values for all fields (allows inserting attribute values via the feature form in the same session)
QgsAttributes attrs( layer->fields().count() );
const QgsFields& fields = layer->fields();
for ( int idx = 0; idx < fields.count(); ++idx )
{
attrs[idx] = QVariant();
}
f.setAttributes( attrs );
editOk = layer->addFeature( f );
}
if ( editOk )
{
layer->endEditCommand();
}
else
{
layer->destroyEditCommand();
}
deleteRubberBandAndGeometry();
deleteDistanceWidget();
delete mSnapVertexMarker;
mSnapVertexMarker = nullptr;
mForceCopy = false;
mCanvas->refresh();
}