Esempio n. 1
0
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 );
}
Esempio n. 2
0
bool QgsMapToolLabel::createAuxiliaryFields( LabelDetails &details, QgsPalIndexes &indexes ) const
{
  bool newAuxiliaryLayer = false;
  QgsVectorLayer *vlayer = details.layer;
  QString providerId = details.pos.providerID;

  if ( !vlayer || !vlayer->labelsEnabled() )
    return false;

  if ( !vlayer->auxiliaryLayer() )
  {
    QgsNewAuxiliaryLayerDialog dlg( vlayer );
    dlg.exec();
    newAuxiliaryLayer = true;
  }

  if ( !vlayer->auxiliaryLayer() )
    return false;

  for ( const QgsPalLayerSettings::Property &p : qgis::as_const( mPalProperties ) )
  {
    int index = -1;

    // always use the default activated property
    QgsProperty prop = details.settings.dataDefinedProperties().property( p );
    if ( prop.propertyType() == QgsProperty::FieldBasedProperty && prop.isActive() )
    {
      index = vlayer->fields().lookupField( prop.field() );
    }
    else
    {
      index = QgsAuxiliaryLayer::createProperty( p, vlayer );
    }

    indexes[p] = index;
  }

  details.settings = vlayer->labeling()->settings( providerId );

  return newAuxiliaryLayer;
}
Esempio n. 3
0
bool QgsMapToolLabel::createAuxiliaryFields( LabelDetails &details, QgsDiagramIndexes &indexes )
{
  bool newAuxiliaryLayer = false;
  QgsVectorLayer *vlayer = details.layer;

  if ( !vlayer )
    return newAuxiliaryLayer;

  if ( !vlayer->auxiliaryLayer() )
  {
    QgsNewAuxiliaryLayerDialog dlg( vlayer );
    dlg.exec();
    newAuxiliaryLayer = true;
  }

  if ( !vlayer->auxiliaryLayer() )
    return false;

  for ( const QgsDiagramLayerSettings::Property &p : qgis::as_const( mDiagramProperties ) )
  {
    int index = -1;

    // always use the default activated property
    QgsProperty prop = vlayer->diagramLayerSettings()->dataDefinedProperties().property( p );
    if ( prop.propertyType() == QgsProperty::FieldBasedProperty && prop.isActive() )
    {
      index = vlayer->fields().lookupField( prop.field() );
    }
    else
    {
      index = QgsAuxiliaryLayer::createProperty( p, vlayer );
    }

    indexes[p] = index;
  }

  return newAuxiliaryLayer;
}