Ejemplo n.º 1
0
void QgsMapToolAnnotation::canvasPressEvent( QMouseEvent * e )
{
  if ( !mCanvas )
  {
    return;
  }

  QgsAnnotationItem* sItem = selectedItem();
  if ( sItem )
  {
    mCurrentMoveAction = sItem->moveActionForPosition( e->posF() );
    if ( mCurrentMoveAction != QgsAnnotationItem::NoAction )
    {
      return;
    }
  }

  if ( !sItem || mCurrentMoveAction == QgsAnnotationItem::NoAction )
  {
    //select a new item if there is one at this position
    mCanvas->scene()->clearSelection();
    QgsAnnotationItem* existingItem = itemAtPos( e->posF() );
    if ( existingItem )
    {
      existingItem->setSelected( true );
    }
    else
    {
      //otherwise create new one
      createItem( e );
    }
  }
}
Ejemplo n.º 2
0
void QgsMapToolAnnotation::canvasPressEvent( QgsMapMouseEvent *e )
{
  if ( !mCanvas )
  {
    return;
  }

  mLastMousePosition = e->pos();

  QgsMapCanvasAnnotationItem *item = selectedItem();
  if ( item )
  {
    mCurrentMoveAction = item->moveActionForPosition( e->pos() );
    if ( mCurrentMoveAction != QgsMapCanvasAnnotationItem::NoAction )
    {
      return;
    }
  }

  if ( !item || mCurrentMoveAction == QgsMapCanvasAnnotationItem::NoAction )
  {
    //select a new item if there is one at this position
    mCanvas->scene()->clearSelection();
    QgsMapCanvasAnnotationItem *existingItem = itemAtPos( e->pos() );
    if ( existingItem )
    {
      existingItem->setSelected( true );
    }
    else
    {
      //otherwise create new one
      QgsAnnotation *annotation = createItem();
      if ( annotation )
      {
        QgsPointXY mapPos = transformCanvasToAnnotation( toMapCoordinates( e->pos() ), annotation );
        annotation->setMapPosition( mapPos );
        annotation->setMapPositionCrs( mCanvas->mapSettings().destinationCrs() );
        annotation->setRelativePosition( QPointF( e->pos().x() / mCanvas->width(),
                                         e->pos().y() / mCanvas->height() ) );
        annotation->setFrameSizeMm( QSizeF( 50, 25 ) );

        QgsProject::instance()->annotationManager()->addAnnotation( annotation );

        // select newly added item
        const auto constItems = mCanvas->items();
        for ( QGraphicsItem *item : constItems )
        {
          if ( QgsMapCanvasAnnotationItem *annotationItem = dynamic_cast< QgsMapCanvasAnnotationItem * >( item ) )
          {
            if ( annotationItem->annotation() == annotation )
            {
              annotationItem->setSelected( true );
              break;
            }
          }
        }
      }
    }
  }
}
Ejemplo n.º 3
0
void QgsMapToolAnnotation::canvasDoubleClickEvent( QMouseEvent * e )
{
  QgsAnnotationItem* item = itemAtPos( e->posF() );
  if ( !item )
  {
    return;
  }
  QDialog* itemEditor = createItemEditor( item );
  if ( itemEditor )
  {
    itemEditor->exec();
    delete itemEditor;
  }
}
Ejemplo n.º 4
0
void QgsMapToolAnnotation::canvasDoubleClickEvent( QgsMapMouseEvent *e )
{
  QgsMapCanvasAnnotationItem *item = itemAtPos( e->pos() );
  if ( !item )
  {
    return;
  }
  QDialog *itemEditor = createItemEditor( item );
  if ( itemEditor )
  {
    if ( itemEditor->exec() )
      QgsProject::instance()->setDirty( true );
    delete itemEditor;
  }
}