bool QgsMapToolShowHideLabels::showHide( const QgsLabelPosition &pos, bool show ) { LabelDetails details = LabelDetails( pos ); if ( !details.valid ) return false; QgsVectorLayer *vlayer = details.layer; if ( !vlayer ) return false; int showCol = -1; if ( pos.isDiagram ) { if ( !diagramCanShowHide( vlayer, showCol ) ) { QgsDiagramIndexes indexes; createAuxiliaryFields( details, indexes ); showCol = indexes[ QgsDiagramLayerSettings::Show ]; } } else { if ( !labelCanShowHide( vlayer, showCol ) ) { QgsPalIndexes indexes; createAuxiliaryFields( details, indexes ); showCol = indexes[ QgsPalLayerSettings::Show ]; } } if ( showCol >= 0 ) { int showVal = show ? 1 : 0; vlayer->changeAttributeValue( pos.featureId, showCol, showVal ); return true; } return false; }
bool QgsMapToolLabel::createAuxiliaryFields( QgsDiagramIndexes &indexes ) { return createAuxiliaryFields( mCurrentLabel, indexes ); }
void QgsMapToolMoveLabel::canvasPressEvent( QgsMapMouseEvent *e ) { deleteRubberBands(); QgsLabelPosition labelPos; if ( !labelAtPosition( e, labelPos ) ) { mCurrentLabel = LabelDetails(); return; } mCurrentLabel = LabelDetails( labelPos ); QgsVectorLayer *vlayer = mCurrentLabel.layer; if ( !vlayer ) { return; } int xCol = -1, yCol = -1; if ( !mCurrentLabel.pos.isDiagram && !labelMoveable( vlayer, mCurrentLabel.settings, xCol, yCol ) ) { QgsPalIndexes indexes; if ( createAuxiliaryFields( indexes ) ) return; if ( !labelMoveable( vlayer, mCurrentLabel.settings, xCol, yCol ) ) return; xCol = indexes[ QgsPalLayerSettings::PositionX ]; yCol = indexes[ QgsPalLayerSettings::PositionY ]; } else if ( mCurrentLabel.pos.isDiagram && !diagramMoveable( vlayer, xCol, yCol ) ) { QgsDiagramIndexes indexes; if ( createAuxiliaryFields( indexes ) ) return; if ( !diagramMoveable( vlayer, xCol, yCol ) ) return; xCol = indexes[ QgsDiagramLayerSettings::PositionX ]; yCol = indexes[ QgsDiagramLayerSettings::PositionY ]; } if ( xCol >= 0 && yCol >= 0 ) { mStartPointMapCoords = toMapCoordinates( e->pos() ); QgsPointXY 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(); } }