本文整理汇总了C++中QgsVectorLayer::triggerRepaint方法的典型用法代码示例。如果您正苦于以下问题:C++ QgsVectorLayer::triggerRepaint方法的具体用法?C++ QgsVectorLayer::triggerRepaint怎么用?C++ QgsVectorLayer::triggerRepaint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QgsVectorLayer
的用法示例。
在下文中一共展示了QgsVectorLayer::triggerRepaint方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}
}
示例2: checkAll
void QgsSymbolLegendNode::checkAll( bool state )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mLayerNode->layer() );
if ( !vlayer || !vlayer->renderer() )
return;
const QgsLegendSymbolList symbolList = vlayer->renderer()->legendSymbolItems();
for ( const auto &item : symbolList )
{
vlayer->renderer()->checkLegendSymbolItem( item.ruleKey(), state );
}
emit dataChanged();
vlayer->triggerRepaint();
}
示例3: setSymbol
void QgsSymbolLegendNode::setSymbol( QgsSymbol *symbol )
{
if ( !symbol )
return;
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mLayerNode->layer() );
if ( !vlayer || !vlayer->renderer() )
return;
mItem.setSymbol( symbol );
vlayer->renderer()->setLegendSymbolItem( mItem.ruleKey(), symbol );
mPixmap = QPixmap();
emit dataChanged();
vlayer->triggerRepaint();
}
示例4: setSymbol
void QgsSymbolLegendNode::setSymbol( QgsSymbol *symbol )
{
if ( !symbol )
return;
std::unique_ptr< QgsSymbol > s( symbol ); // this method takes ownership of symbol
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mLayerNode->layer() );
if ( !vlayer || !vlayer->renderer() )
return;
mItem.setSymbol( s.get() ); // doesn't transfer ownership
vlayer->renderer()->setLegendSymbolItem( mItem.ruleKey(), s.release() ); // DOES transfer ownership!
mPixmap = QPixmap();
emit dataChanged();
vlayer->triggerRepaint();
}
示例5: dataChanged
bool QgsSymbolV2LegendNode::setData( const QVariant& value, int role )
{
if ( role != Qt::CheckStateRole )
return false;
if ( !mItem.isCheckable() )
return false;
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( mLayerNode->layer() );
if ( !vlayer || !vlayer->rendererV2() )
return false;
vlayer->rendererV2()->checkLegendSymbolItem( mItem.ruleKey(), value == Qt::Checked );
emit dataChanged();
vlayer->triggerRepaint();
return true;
}
示例6: 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();
}
}
示例7: fixError
void QgsGeometryValidationService::fixError( QgsGeometryCheckError *error, int method )
{
QgsGeometryCheck::Changes changes;
error->check()->fixError( mFeaturePools, error, method, QMap<QString, int>(), changes );
error->setFixed( method );
QgsFeaturePool *featurePool = mFeaturePools.value( error->layerId() );
QgsVectorLayer *layer = nullptr;
if ( featurePool )
layer = featurePool->layer();
else
{
// Some checks don't tell us on which layer they are because they are able to do cross-layer checks.
// E.g. the gap check will report in such a way
for ( auto layerCheck = mLayerChecks.constBegin(); layerCheck != mLayerChecks.constEnd(); ++layerCheck )
{
const QList<std::shared_ptr<QgsGeometryCheckError>> &topologyCheckErrors = layerCheck.value().topologyCheckErrors;
for ( const auto &checkError : topologyCheckErrors )
{
if ( checkError.get() == error )
{
layer = layerCheck.key();
break;
}
}
}
}
if ( layer )
{
layer->triggerRepaint();
emit topologyErrorUpdated( layer, error );
}
}
示例8: 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();
}
示例9: cadCanvasReleaseEvent
//.........这里部分代码省略.........
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() );
}
vlayer->endEditCommand();
vlayer->triggerRepaint();
if ( ( !isGeometryEmpty ) && QgsWkbTypes::isSingleType( vlayer->wkbType() ) )
{
emit messageEmitted( tr( "Add part: Feature geom is single part and you've added more than one" ), Qgis::Warning );
}
return;
}
case 1:
errorMessage = tr( "Selected feature is not multi part." );
break;
case 2:
errorMessage = tr( "New part's geometry is not valid." );
break;
case 3:
errorMessage = tr( "New polygon ring not disjoint with existing polygons." );
break;
case 4:
errorMessage = tr( "No feature selected. Please select a feature with the selection tool or in the attribute table" );
break;
case 5:
errorMessage = tr( "Several features are selected. Please select only one feature to which an island should be added." );
break;
case 6:
errorMessage = tr( "Selected geometry could not be found" );
break;
}
emit messageEmitted( errorMessage, Qgis::Warning );
vlayer->destroyEditCommand();
}
示例10: cadCanvasReleaseEvent
//.........这里部分代码省略.........
{
QgsFeature f( vlayer->fields(), 0 );
QgsGeometry g;
if ( layerWKBType == QgsWkbTypes::Point )
{
g = QgsGeometry::fromPoint( savePoint );
}
else if ( layerWKBType == QgsWkbTypes::Point25D )
{
g = QgsGeometry( new QgsPointV2( QgsWkbTypes::PointZ, savePoint.x(), savePoint.y(), 0.0 ) );
}
else if ( layerWKBType == QgsWkbTypes::MultiPoint )
{
g = QgsGeometry::fromMultiPoint( QgsMultiPoint() << savePoint );
}
else if ( layerWKBType == QgsWkbTypes::MultiPoint25D )
{
QgsMultiPointV2* mp = new QgsMultiPointV2();
mp->addGeometry( new QgsPointV2( QgsWkbTypes::PointZ, savePoint.x(), savePoint.y(), 0.0 ) );
g = QgsGeometry( mp );
}
else
{
// if layer supports more types (mCheckGeometryType is false)
g = QgsGeometry::fromPoint( savePoint );
}
f.setGeometry( g );
f.setValid( true );
addFeature( vlayer, &f, false );
vlayer->triggerRepaint();
}
}
// LINE AND POLYGON CAPTURING
else if ( mode() == CaptureLine || mode() == CapturePolygon )
{
//check we only use the line tool for line/multiline layers
if ( mode() == CaptureLine && vlayer->geometryType() != QgsWkbTypes::LineGeometry && mCheckGeometryType )
{
emit messageEmitted( tr( "Wrong editing tool, cannot apply the 'capture line' tool on this vector layer" ), QgsMessageBar::WARNING );
return;
}
//check we only use the polygon tool for polygon/multipolygon layers
if ( mode() == CapturePolygon && vlayer->geometryType() != QgsWkbTypes::PolygonGeometry && mCheckGeometryType )
{
emit messageEmitted( tr( "Wrong editing tool, cannot apply the 'capture polygon' tool on this vector layer" ), QgsMessageBar::WARNING );
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
示例11: cadCanvasReleaseEvent
//.........这里部分代码省略.........
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();
mRubberBand->show();
}
else
{
// copy and move mode
if ( e->button() != Qt::LeftButton )
{
cadDockWidget()->clear();
delete mRubberBand;
mRubberBand = nullptr;
mSnapIndicator->setMatch( QgsPointLocator::Match() );
return;
}
QgsPointXY startPointLayerCoords = toLayerCoordinates( ( QgsMapLayer * )vlayer, mStartPointMapCoords );
QgsPointXY stopPointLayerCoords = toLayerCoordinates( ( QgsMapLayer * )vlayer, e->mapPoint() );
double dx = stopPointLayerCoords.x() - startPointLayerCoords.x();
double dy = stopPointLayerCoords.y() - startPointLayerCoords.y();
vlayer->beginEditCommand( mMode == Move ? tr( "Feature moved" ) : tr( "Feature copied and moved" ) );
switch ( mMode )
{
case Move:
Q_FOREACH ( QgsFeatureId id, mMovedFeatures )
{
vlayer->translateFeature( id, dx, dy );
}
delete mRubberBand;
mRubberBand = nullptr;
mSnapIndicator->setMatch( QgsPointLocator::Match() );
cadDockWidget()->clear();
break;
case CopyMove:
QgsFeatureRequest request;
request.setFilterFids( mMovedFeatures );
QString *errorMsg = new QString();
if ( !QgisApp::instance()->vectorLayerTools()->copyMoveFeatures( vlayer, request, dx, dy, errorMsg ) )
{
emit messageEmitted( *errorMsg, Qgis::Critical );
delete mRubberBand;
mRubberBand = nullptr;
mSnapIndicator->setMatch( QgsPointLocator::Match() );
}
break;
}
vlayer->endEditCommand();
vlayer->triggerRepaint();
}
示例12: canvasReleaseEvent
void QgsMapToolMoveLabel::canvasReleaseEvent( QgsMapMouseEvent *e )
{
if ( !mLabelRubberBand )
{
return;
}
deleteRubberBands();
QgsVectorLayer *vlayer = mCurrentLabel.layer;
if ( !vlayer )
{
return;
}
QgsPointXY 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 ( !currentLabelDataDefinedPosition( 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();
QgsPointXY transformedPoint = ms.layerToMapCoordinates( vlayer, QgsPointXY( 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();
QgsPointXY transformedPoint = s.mapToLayerCoordinates( vlayer, QgsPointXY( xPosNew, yPosNew ) );
xPosNew = transformedPoint.x();
yPosNew = transformedPoint.y();
}
vlayer->beginEditCommand( tr( "Moved label" ) + QStringLiteral( " '%1'" ).arg( currentLabelText( 24 ) ) );
vlayer->changeAttributeValue( mCurrentLabel.pos.featureId, xCol, xPosNew );
vlayer->changeAttributeValue( mCurrentLabel.pos.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
if ( !mCurrentLabel.pos.isDiagram
&& !mCurrentLabel.pos.isPinned
&& !currentLabelPreserveRotation() )
{
double defRot;
bool rSuccess;
int rCol;
if ( currentLabelDataDefinedRotation( defRot, rSuccess, rCol ) )
{
double labelRot = mCurrentLabel.pos.rotation * 180 / M_PI;
vlayer->changeAttributeValue( mCurrentLabel.pos.featureId, rCol, labelRot );
}
}
vlayer->endEditCommand();
vlayer->triggerRepaint();
}