本文整理汇总了C++中QgsVectorLayer::isEditable方法的典型用法代码示例。如果您正苦于以下问题:C++ QgsVectorLayer::isEditable方法的具体用法?C++ QgsVectorLayer::isEditable怎么用?C++ QgsVectorLayer::isEditable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QgsVectorLayer
的用法示例。
在下文中一共展示了QgsVectorLayer::isEditable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: labelMoveable
bool QgsMapToolLabel::labelMoveable( QgsMapLayer *ml, int& xCol, int& yCol ) const
{
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( ml );
if ( !vlayer || !vlayer->isEditable() )
{
return false;
}
bool xColOk = false;
bool yColOk = false;
int xColumn = dataDefinedColumnIndex( QgsPalLayerSettings::PositionX, vlayer );
if ( xColumn != -1 )
{
xCol = xColumn;
xColOk = true;
}
int yColumn = dataDefinedColumnIndex( QgsPalLayerSettings::PositionY, vlayer );
if ( yColumn != -1 )
{
yCol = yColumn;
yColOk = true;
}
if ( xColOk && yColOk )
{
return true;
}
return false;
}
示例2: canvasPressEvent
void QgsMapToolMoveLabel::canvasPressEvent( QgsMapMouseEvent* e )
{
deleteRubberBands();
QgsLabelPosition labelPos;
if ( !labelAtPosition( e, labelPos ) )
{
mCurrentLabel = LabelDetails();
return;
}
mCurrentLabel = LabelDetails( labelPos );
QgsVectorLayer* vlayer = mCurrentLabel.layer;
if ( !vlayer || !vlayer->isEditable() )
{
return;
}
int xCol, yCol;
if ( labelMoveable( vlayer, mCurrentLabel.settings, xCol, yCol ) ||
diagramMoveable( vlayer, xCol, yCol ) )
{
mStartPointMapCoords = toMapCoordinates( e->pos() );
QgsPoint referencePoint;
if ( !currentLabelRotationPoint( referencePoint, !currentLabelPreserveRotation(), false ) )
{
referencePoint.setX( mCurrentLabel.pos.labelRect.xMinimum() );
referencePoint.setY( mCurrentLabel.pos.labelRect.yMinimum() );
}
mClickOffsetX = mStartPointMapCoords.x() - referencePoint.x();
mClickOffsetY = mStartPointMapCoords.y() - referencePoint.y();
createRubberBands();
}
}
示例3: 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;
}
}
示例4: 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" ), Qgis::Warning );
return;
}
startCapturing();
}
else if ( e->button() == Qt::RightButton )
{
deleteTempRubberBand();
//find out bounding box of mCaptureList
if ( size() < 1 )
{
stopCapturing();
return;
}
reshape( vlayer );
stopCapturing();
}
}
示例5: layersModified
bool QgsLayerTreeUtils::layersModified( const QList<QgsLayerTreeLayer *> &layerNodes )
{
const auto constLayerNodes = layerNodes;
for ( QgsLayerTreeLayer *layerNode : constLayerNodes )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layerNode->layer() );
if ( !vl )
continue;
if ( vl->isEditable() && vl->isModified() )
return true;
}
return false;
}
示例6: canvasPressEvent
void QgsMapToolChangeLabelProperties::canvasPressEvent( QMouseEvent * e )
{
deleteRubberBands();
if ( !labelAtPosition( e, mCurrentLabelPos ) )
{
return;
}
QgsVectorLayer* vlayer = currentLayer();
if ( !vlayer || !vlayer->isEditable() )
{
return;
}
createRubberBands();
}
示例7: layerIsRotatable
bool QgsMapToolLabel::layerIsRotatable( QgsMapLayer* layer, int& rotationCol ) const
{
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( layer );
if ( !vlayer || !vlayer->isEditable() )
{
return false;
}
int rotCol = dataDefinedColumnIndex( QgsPalLayerSettings::Rotation, vlayer );
if ( rotCol != -1 )
{
rotationCol = rotCol;
return true;
}
return false;
}
示例8: layerCanShowHide
bool QgsMapToolLabel::layerCanShowHide( QgsMapLayer* ml, int& showCol ) const
{
//QgsDebugMsg( "entered" );
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( ml );
if ( !vlayer || !vlayer->isEditable() )
{
return false;
}
int showColmn = dataDefinedColumnIndex( QgsPalLayerSettings::Show, vlayer );
if ( showColmn != -1 )
{
showCol = showColmn;
return true;
}
return false;
}
示例9: diagramCanShowHide
bool QgsMapToolLabel::diagramCanShowHide( QgsMapLayer* ml, int& showCol ) const
{
bool rc = false;
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( ml );
if ( vlayer && vlayer->isEditable() && vlayer->diagramsEnabled() )
{
const QgsDiagramLayerSettings *dls = vlayer->diagramLayerSettings();
if ( dls && dls->showColumn >= 0 )
{
showCol = dls->showColumn;
rc = true;
}
}
return rc;
}
示例10: mouseReleaseEvent
void QgsMapCanvas::mouseReleaseEvent( QMouseEvent* e )
{
//use middle mouse button for panning, map tools won't receive any events in that case
if ( e->button() == Qt::MidButton )
{
mCanvasProperties->panSelectorDown = false;
panActionEnd( mCanvasProperties->mouseLastXY );
}
else
{
// call handler of current map tool
if ( mMapTool )
{
// right button was pressed in zoom tool? return to previous non zoom tool
if ( e->button() == Qt::RightButton && mMapTool->isTransient() )
{
QgsDebugMsg( "Right click in map tool zoom or pan, last tool is " +
QString( mLastNonZoomMapTool ? "not null." : "null." ) );
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCurrentLayer );
// change to older non-zoom tool
if ( mLastNonZoomMapTool
&& ( !mLastNonZoomMapTool->isEditTool() || ( vlayer && vlayer->isEditable() ) ) )
{
QgsMapTool* t = mLastNonZoomMapTool;
mLastNonZoomMapTool = NULL;
setMapTool( t );
}
return;
}
QScopedPointer<QgsMapMouseEvent> me( new QgsMapMouseEvent( this, e ) );
mMapTool->canvasReleaseEvent( me.data() );
}
}
mCanvasProperties->mouseButtonDown = false;
if ( mCanvasProperties->panSelectorDown )
return;
} // mouseReleaseEvent
示例11: 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 );
//.........这里部分代码省略.........
示例12: 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();
}
}
示例13: 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();
}
示例14: 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();
}
示例15: data
QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
{
if ( !index.isValid() )
return QVariant();
if ( QgsLayerTreeModelLegendNode* sym = index2symnode( index ) )
{
if ( role == Qt::CheckStateRole && !testFlag( AllowSymbologyChangeState ) )
return QVariant();
return sym->data( role );
}
QgsLayerTreeNode* node = index2node( index );
if ( role == Qt::DisplayRole || role == Qt::EditRole )
{
if ( QgsLayerTree::isGroup( node ) )
return QgsLayerTree::toGroup( node )->name();
else if ( QgsLayerTree::isLayer( node ) )
{
QgsLayerTreeLayer* nodeLayer = QgsLayerTree::toLayer( node );
QString name = nodeLayer->layerName();
if ( nodeLayer->customProperty( "showFeatureCount", 0 ).toInt() && role == Qt::DisplayRole )
{
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( nodeLayer->layer() );
if ( vlayer && vlayer->pendingFeatureCount() >= 0 )
name += QString( " [%1]" ).arg( vlayer->pendingFeatureCount() );
}
return name;
}
}
else if ( role == Qt::DecorationRole && index.column() == 0 )
{
if ( QgsLayerTree::isGroup( node ) )
return iconGroup();
else if ( QgsLayerTree::isLayer( node ) )
{
QgsLayerTreeLayer* nodeLayer = QgsLayerTree::toLayer( node );
// if there's just on legend entry that should be embedded in layer - do that!
if ( testFlag( ShowSymbology ) && mSymbologyNodes[nodeLayer].count() == 1 && mSymbologyNodes[nodeLayer][0]->isEmbeddedInParent() )
return mSymbologyNodes[nodeLayer][0]->data( Qt::DecorationRole );
QgsMapLayer* layer = QgsLayerTree::toLayer( node )->layer();
if ( !layer )
return QVariant();
if ( layer->type() == QgsMapLayer::RasterLayer )
{
if ( testFlag( ShowRasterPreviewIcon ) )
{
QgsRasterLayer* rlayer = qobject_cast<QgsRasterLayer *>( layer );
return QIcon( rlayer->previewAsPixmap( QSize( 32, 32 ) ) );
}
else
return QgsLayerItem::iconRaster();
}
else if ( layer->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer* vlayer = static_cast<QgsVectorLayer*>( layer );
if ( vlayer->isEditable() )
{
if ( vlayer->isModified() )
return QIcon( QgsApplication::getThemePixmap( "/mIconEditableEdits.png" ) );
else
return QIcon( QgsApplication::getThemePixmap( "/mIconEditable.png" ) );
}
if ( vlayer->geometryType() == QGis::Point )
return QgsLayerItem::iconPoint();
else if ( vlayer->geometryType() == QGis::Line )
return QgsLayerItem::iconLine();
else if ( vlayer->geometryType() == QGis::Polygon )
return QgsLayerItem::iconPolygon();
else if ( vlayer->geometryType() == QGis::NoGeometry )
return QgsLayerItem::iconTable();
}
return QgsLayerItem::iconDefault();
}
}
else if ( role == Qt::CheckStateRole )
{
if ( !testFlag( AllowNodeChangeVisibility ) )
return QVariant();
if ( QgsLayerTree::isLayer( node ) )
{
QgsLayerTreeLayer* nodeLayer = QgsLayerTree::toLayer( node );
if ( nodeLayer->layer() && nodeLayer->layer()->type() == QgsMapLayer::VectorLayer )
{
if ( qobject_cast<QgsVectorLayer*>( nodeLayer->layer() )->geometryType() == QGis::NoGeometry )
return QVariant(); // do not show checkbox for non-spatial tables
}
return nodeLayer->isVisible();
}
else if ( QgsLayerTree::isGroup( node ) )
{
QgsLayerTreeGroup* nodeGroup = QgsLayerTree::toGroup( node );
return nodeGroup->isVisible();
}
}
else if ( role == Qt::FontRole )
//.........这里部分代码省略.........