本文整理汇总了C++中QgsVectorLayer::endEditCommand方法的典型用法代码示例。如果您正苦于以下问题:C++ QgsVectorLayer::endEditCommand方法的具体用法?C++ QgsVectorLayer::endEditCommand怎么用?C++ QgsVectorLayer::endEditCommand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QgsVectorLayer
的用法示例。
在下文中一共展示了QgsVectorLayer::endEditCommand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pinUnpinCurrentDiagram
bool QgsMapToolPinLabels::pinUnpinCurrentDiagram( bool pin )
{
// skip diagrams
if ( ! mCurrentLabel.pos.isDiagram )
return false;
// verify attribute table has x, y fields mapped
int xCol, yCol;
double xPosOrig, yPosOrig;
bool xSuccess, ySuccess;
if ( !currentLabelDataDefinedPosition( xPosOrig, xSuccess, yPosOrig, ySuccess, xCol, yCol ) )
return false;
// edit attribute table
QgsVectorLayer *vlayer = mCurrentLabel.layer;
int fid = mCurrentLabel.pos.featureId;
bool writeFailed = false;
QString labelText = currentLabelText( 24 );
if ( pin )
{
QgsPointXY referencePoint = mCurrentLabel.pos.labelRect.center();
double labelX = referencePoint.x();
double labelY = referencePoint.y();
// transform back to layer crs
QgsPointXY transformedPoint = mCanvas->mapSettings().mapToLayerCoordinates( vlayer, referencePoint );
labelX = transformedPoint.x();
labelY = transformedPoint.y();
vlayer->beginEditCommand( tr( "Pinned diagram" ) + QStringLiteral( " '%1'" ).arg( labelText ) );
writeFailed = !vlayer->changeAttributeValue( fid, xCol, labelX );
if ( !vlayer->changeAttributeValue( fid, yCol, labelY ) )
writeFailed = true;
vlayer->endEditCommand();
}
else
{
vlayer->beginEditCommand( tr( "Unpinned diagram" ) + QStringLiteral( " '%1'" ).arg( labelText ) );
writeFailed = !vlayer->changeAttributeValue( fid, xCol, QVariant( QString() ) );
if ( !vlayer->changeAttributeValue( fid, yCol, QVariant( QString() ) ) )
writeFailed = true;
vlayer->endEditCommand();
}
return !writeFailed;
}
示例2: canvasReleaseEvent
void QgsMapToolChangeLabelProperties::canvasReleaseEvent( QMouseEvent *e )
{
Q_UNUSED( e );
QgsVectorLayer* vlayer = currentLayer();
if ( mLabelRubberBand && mCanvas && vlayer )
{
QString labeltext = QString(); // NULL QString signifies no expression
bool settingsOk;
QgsPalLayerSettings& labelSettings = currentLabelSettings( &settingsOk );
if ( settingsOk && labelSettings.isExpression )
{
labeltext = mCurrentLabelPos.labelText;
}
QgsLabelPropertyDialog d( mCurrentLabelPos.layerID, mCurrentLabelPos.featureId, mCurrentLabelPos.labelFont, labeltext, 0 );
if ( d.exec() == QDialog::Accepted )
{
const QgsAttributeMap& changes = d.changedProperties();
if ( changes.size() > 0 )
{
vlayer->beginEditCommand( tr( "Changed properties for label" ) + QString( " '%1'" ).arg( currentLabelText( 24 ) ) );
QgsAttributeMap::const_iterator changeIt = changes.constBegin();
for ( ; changeIt != changes.constEnd(); ++changeIt )
{
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, changeIt.key(), changeIt.value() );
}
vlayer->endEditCommand();
mCanvas->refresh();
}
}
deleteRubberBands();
}
}
示例3: canvasReleaseEvent
void QgsMapToolChangeLabelProperties::canvasReleaseEvent( QMouseEvent * e )
{
QgsVectorLayer* vlayer = currentLayer();
if ( mLabelRubberBand && mCanvas && vlayer )
{
QgsLabelPropertyDialog d( mCurrentLabelPos.layerID, mCurrentLabelPos.featureId, mCanvas->mapRenderer() );
if ( d.exec() == QDialog::Accepted )
{
const QgsAttributeMap& changes = d.changedProperties();
if ( changes.size() > 0 )
{
vlayer->beginEditCommand( tr( "Label properties changed" ) );
QgsAttributeMap::const_iterator changeIt = changes.constBegin();
for ( ; changeIt != changes.constEnd(); ++changeIt )
{
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, changeIt.key(), changeIt.value(), false );
}
vlayer->endEditCommand();
mCanvas->refresh();
}
}
deleteRubberBands();
}
}
示例4: 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();
}
示例5: setModelData
void QgsAttributeTableDelegate::setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const
{
QgsVectorLayer *vl = layer( model );
if ( !vl )
return;
int fieldIdx = model->data( index, QgsAttributeTableModel::FieldIndexRole ).toInt();
QgsFeatureId fid = model->data( index, QgsAttributeTableModel::FeatureIdRole ).toLongLong();
QVariant oldValue = model->data( index, Qt::EditRole );
QVariant newValue;
QgsEditorWidgetWrapper *eww = QgsEditorWidgetWrapper::fromWidget( editor );
if ( !eww )
return;
newValue = eww->value();
if ( ( oldValue != newValue && newValue.isValid() ) || oldValue.isNull() != newValue.isNull() )
{
// This fixes https://issues.qgis.org/issues/16492
QgsFeatureRequest request( fid );
request.setFlags( QgsFeatureRequest::NoGeometry );
request.setSubsetOfAttributes( QgsAttributeList() );
QgsFeature feature;
vl->getFeatures( request ).nextFeature( feature );
if ( feature.isValid() )
{
vl->beginEditCommand( tr( "Attribute changed" ) );
vl->changeAttributeValue( fid, fieldIdx, newValue, oldValue );
vl->endEditCommand();
}
}
}
示例6: 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();
}
}
示例7: setModelData
void QgsAttributeTableDelegate::setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const
{
QgsVectorLayer *vl = layer( model );
if ( vl == NULL )
return;
int fieldIdx = model->data( index, QgsAttributeTableModel::FieldIndexRole ).toInt();
QgsFeatureId fid = model->data( index, QgsAttributeTableModel::FeatureIdRole ).toInt();
QVariant value;
if ( !QgsAttributeEditor::retrieveValue( editor, vl, fieldIdx, value ) )
return;
vl->beginEditCommand( tr( "Attribute changed" ) );
vl->changeAttributeValue( fid, fieldIdx, value, true );
vl->endEditCommand();
}
示例8: storeSimplified
void QgsMapToolSimplify::storeSimplified()
{
QgsVectorLayer * vlayer = currentVectorLayer();
if ( mSelectedFeature.geometry()->type() == QGis::Line )
{
QgsSimplifyFeature::simplifyLine( mSelectedFeature, mTolerance );
}
else
{
QgsSimplifyFeature::simplifyPolygon( mSelectedFeature, mTolerance );
}
vlayer->beginEditCommand( tr( "Geometry simplified" ) );
vlayer->changeGeometry( mSelectedFeature.id(), mSelectedFeature.geometry() );
vlayer->endEditCommand();
mCanvas->refresh();
}
示例9: applyChanges
void QgsMapToolChangeLabelProperties::applyChanges( const QgsAttributeMap& changes )
{
QgsVectorLayer* vlayer = mCurrentLabel.layer;
if ( !vlayer )
return;
if ( !changes.isEmpty() )
{
vlayer->beginEditCommand( tr( "Changed properties for label" ) + QStringLiteral( " '%1'" ).arg( currentLabelText( 24 ) ) );
QgsAttributeMap::const_iterator changeIt = changes.constBegin();
for ( ; changeIt != changes.constEnd(); ++changeIt )
{
vlayer->changeAttributeValue( mCurrentLabel.pos.featureId, changeIt.key(), changeIt.value() );
}
vlayer->endEditCommand();
vlayer->triggerRepaint();
}
}
示例10: canvasReleaseEvent
void QgsMapToolRotateLabel::canvasReleaseEvent( QgsMapMouseEvent* e )
{
Q_UNUSED( e );
if ( !mLabelRubberBand ) //no rubber band created (most likely because the current label cannot be rotated )
{
return;
}
deleteRubberBands();
delete mRotationItem;
mRotationItem = nullptr;
delete mRotationPreviewBox;
mRotationPreviewBox = nullptr;
QgsVectorLayer* vlayer = mCurrentLabel.layer;
if ( !vlayer )
{
return;
}
int rotationCol;
if ( !labelIsRotatable( vlayer, mCurrentLabel.settings, rotationCol ) )
{
return;
}
double rotation = mCtrlPressed ? roundTo15Degrees( mCurrentRotation ) : mCurrentRotation;
if ( rotation == mStartRotation ) //mouse button pressed / released, but no rotation
{
return;
}
vlayer->beginEditCommand( tr( "Rotated label" ) + QString( " '%1'" ).arg( currentLabelText( 24 ) ) );
vlayer->changeAttributeValue( mCurrentLabel.pos.featureId, rotationCol, rotation );
vlayer->endEditCommand();
vlayer->triggerRepaint();
}
示例11: setModelData
void QgsAttributeTableDelegate::setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const
{
QgsVectorLayer *vl = layer( model );
if ( vl == NULL )
return;
int fieldIdx = model->data( index, QgsAttributeTableModel::FieldIndexRole ).toInt();
QgsFeatureId fid = model->data( index, QgsAttributeTableModel::FeatureIdRole ).toLongLong();
QVariant oldValue = model->data( index, Qt::EditRole );
QVariant newValue;
QgsEditorWidgetWrapper* eww = QgsEditorWidgetWrapper::fromWidget( editor );
if ( !eww )
return;
newValue = eww->value();
if (( oldValue != newValue && newValue.isValid() ) || oldValue.isNull() != newValue.isNull() )
{
vl->beginEditCommand( tr( "Attribute changed" ) );
vl->changeAttributeValue( fid, fieldIdx, newValue, oldValue );
vl->endEditCommand();
}
}
示例12: canvasReleaseEvent
void QgsMapToolMoveLabel::canvasReleaseEvent( QgsMapMouseEvent* e )
{
if ( !mLabelRubberBand )
{
return;
}
deleteRubberBands();
QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( mCurrentLabelPos.layerID );
if ( !layer )
{
return;
}
QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>( layer );
if ( !vlayer )
{
return;
}
if ( !vlayer->isEditable() )
{
return;
}
QgsPoint releaseCoords = toMapCoordinates( e->pos() );
double xdiff = releaseCoords.x() - mStartPointMapCoords.x();
double ydiff = releaseCoords.y() - mStartPointMapCoords.y();
int xCol, yCol;
double xPosOrig, yPosOrig;
bool xSuccess, ySuccess;
if ( !dataDefinedPosition( vlayer, mCurrentLabelPos.featureId, xPosOrig, xSuccess, yPosOrig, ySuccess, xCol, yCol ) )
{
return;
}
double xPosNew, yPosNew;
if ( !xSuccess || !ySuccess )
{
xPosNew = releaseCoords.x() - mClickOffsetX;
yPosNew = releaseCoords.y() - mClickOffsetY;
}
else
{
//transform to map crs first, because xdiff,ydiff are in map coordinates
const QgsMapSettings& ms = mCanvas->mapSettings();
if ( ms.hasCrsTransformEnabled() )
{
QgsPoint transformedPoint = ms.layerToMapCoordinates( vlayer, QgsPoint( xPosOrig, yPosOrig ) );
xPosOrig = transformedPoint.x();
yPosOrig = transformedPoint.y();
}
xPosNew = xPosOrig + xdiff;
yPosNew = yPosOrig + ydiff;
}
//transform back to layer crs
if ( mCanvas )
{
const QgsMapSettings& s = mCanvas->mapSettings();
if ( s.hasCrsTransformEnabled() )
{
QgsPoint transformedPoint = s.mapToLayerCoordinates( vlayer, QgsPoint( xPosNew, yPosNew ) );
xPosNew = transformedPoint.x();
yPosNew = transformedPoint.y();
}
}
vlayer->beginEditCommand( tr( "Moved label" ) + QString( " '%1'" ).arg( currentLabelText( 24 ) ) );
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, xCol, xPosNew );
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, yCol, yPosNew );
// set rotation to that of label, if data-defined and no rotation set yet
// honor whether to preserve preexisting data on pin
// must come after setting x and y positions
int rCol;
if ( !mCurrentLabelPos.isDiagram
&& !mCurrentLabelPos.isPinned
&& !preserveRotation()
&& layerIsRotatable( vlayer, rCol ) )
{
double defRot;
bool rSuccess;
if ( dataDefinedRotation( vlayer, mCurrentLabelPos.featureId, defRot, rSuccess ) )
{
double labelRot = mCurrentLabelPos.rotation * 180 / M_PI;
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, rCol, labelRot );
}
}
vlayer->endEditCommand();
if ( mCanvas )
mCanvas->refresh();
}
示例13: cadCanvasReleaseEvent
//.........这里部分代码省略.........
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 );
bBox.setYMinimum( yMin );
bBox.setXMaximum( xMax );
bBox.setYMaximum( yMax );
QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest().setFilterFid( modifiedFid ) );
QgsFeature f;
bool res = false;
if ( fit.nextFeature( f ) )
{
//create QgsFeature with wkb representation
QgsFeature* ft = new QgsFeature( vlayer->fields(), 0 );
ft->setGeometry( QgsGeometry::fromPolygon( QgsPolygon() << pointList.toVector() ) );
ft->setAttributes( f.attributes() );
if ( QApplication::keyboardModifiers() == Qt::ControlModifier )
{
res = vlayer->addFeature( *ft );
}
else
{
QgsAttributeDialog *dialog = new QgsAttributeDialog( vlayer, ft, false, NULL, true );
dialog->setIsAddDialog( true );
res = dialog->exec(); // will also add the feature
}
if ( res )
{
vlayer->endEditCommand();
}
else
{
delete ft;
vlayer->destroyEditCommand();
}
res = false;
}
}
stopCapturing();
}
示例14: cadCanvasReleaseEvent
//.........这里部分代码省略.........
{
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;
}
}
}
if ( reshapeDone )
{
vlayer->endEditCommand();
}
else
{
vlayer->destroyEditCommand();
}
stopCapturing();
}
}
示例15: canvasReleaseEvent
void OptMapToolSplitLink::canvasReleaseEvent( QMouseEvent * e )
{
//check if we operate on a vector layer
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
if ( !vlayer )
{
QMessageBox::information( 0, tr( "Not a vector layer" ),
tr( "The current layer is not a vector layer" ) );
return;
}
if ( !vlayer->isEditable() )
{
QMessageBox::information( 0, tr( "Layer not editable" ),
tr( "Cannot edit the vector layer. Use 'Toggle Editing' to make it editable." )
);
return;
}
//add point to list and to rubber band
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;
}
if ( e->button() == Qt::LeftButton )
{
startCapturing();
}
else if ( e->button() == Qt::RightButton )
{
//bring up dialog if a split was not possible (polygon) or only done once (line)
int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
vlayer->beginEditCommand( tr( "Features split" ) );
int returnCode = vlayer->splitFeatures( points(), topologicalEditing );
vlayer->endEditCommand();
if ( returnCode == 4 )
{
QMessageBox::warning( 0, tr( "No feature split done" ), tr( "If there are selected features, the split tool only applies to the selected ones. If you like to split all features under the split line, clear the selection" ) );
}
else if ( returnCode == 3 )
{
QMessageBox::warning( 0, tr( "No feature split done" ), tr( "Cut edges detected. Make sure the line splits features into multiple parts." ) );
}
else if ( returnCode == 7 )
{
QMessageBox::warning( 0, tr( "No feature split done" ), tr( "The geometry is invalid. Please repair before trying to split it." ) );
}
else if ( returnCode != 0 )
{
//several intersections but only one split (most likely line)
QMessageBox::warning( 0, tr( "Split error" ), tr( "An error occured during feature splitting" ) );
}
stopCapturing();
}
}