void QgsMapToolShowHideLabels::canvasPressEvent( QgsMapMouseEvent *e )
{
  Q_UNUSED( e );

  QgsMapLayer *layer = mCanvas->currentLayer();
  QgsVectorLayer *vlayer = dynamic_cast<QgsVectorLayer *>( layer );
  if ( !vlayer )
    return;

  int showCol;
  if ( !labelCanShowHide( vlayer, showCol )
       || !diagramCanShowHide( vlayer, showCol ) )
  {
    if ( !vlayer->auxiliaryLayer() )
    {
      QgsNewAuxiliaryLayerDialog dlg( vlayer );
      dlg.exec();
      return;
    }
  }

  mSelectRect.setRect( 0, 0, 0, 0 );
  mSelectRect.setTopLeft( e->pos() );
  mSelectRect.setBottomRight( e->pos() );
  mRubberBand = new QgsRubberBand( mCanvas, QgsWkbTypes::PolygonGeometry );
}
示例#2
0
bool QgsMapToolLabel::dataDefinedShowHide( QgsVectorLayer *vlayer, QgsFeatureId featureId, int &show, bool &showSuccess, int &showCol ) const
{
  showSuccess = false;
  if ( !vlayer )
  {
    return false;
  }

  if ( mCurrentLabel.pos.isDiagram )
  {
    if ( ! diagramCanShowHide( vlayer, showCol ) )
    {
      return false;
    }
  }
  else if ( ! labelCanShowHide( vlayer, showCol ) )
  {
    return false;
  }

  QgsFeature f;
  if ( !vlayer->getFeatures( QgsFeatureRequest().setFilterFid( featureId ).setFlags( QgsFeatureRequest::NoGeometry ) ).nextFeature( f ) )
  {
    return false;
  }

  show = f.attribute( showCol ).toInt( &showSuccess );
  return true;
}
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;
}