コード例 #1
0
QgsFormAnnotationItem::QgsFormAnnotationItem( QgsMapCanvas* canvas, QgsVectorLayer* vlayer, bool hasFeature, int feature )
    : QgsAnnotationItem( canvas ), mWidgetContainer( 0 ), mDesignerWidget( 0 ), mVectorLayer( vlayer ),
    mHasAssociatedFeature( hasFeature ), mFeature( feature )
{
  mWidgetContainer = new QGraphicsProxyWidget( this );
  if ( mVectorLayer && mMapCanvas ) //default to the layers edit form
  {
    mDesignerForm = mVectorLayer->annotationForm();
    QObject::connect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( setFeatureForMapPosition() ) );
    QObject::connect( mMapCanvas, SIGNAL( renderComplete( QPainter* ) ), this, SLOT( setFeatureForMapPosition() ) );
    QObject::connect( mMapCanvas, SIGNAL( layersChanged() ), this, SLOT( updateVisibility() ) );
  }
コード例 #2
0
QgsFormAnnotationItem::QgsFormAnnotationItem( QgsMapCanvas* canvas, QgsVectorLayer* vlayer, bool hasFeature, int feature )
    : QgsAnnotationItem( canvas )
    , mWidgetContainer( nullptr )
    , mDesignerWidget( nullptr )
    , mVectorLayer( vlayer )
    , mHasAssociatedFeature( hasFeature )
    , mFeature( feature )
{
  mWidgetContainer = new QGraphicsProxyWidget( this );
  mWidgetContainer->setData( 0, "AnnotationItem" ); //mark embedded widget as belonging to an annotation item (composer knows it needs to be printed)
  if ( mVectorLayer && mMapCanvas ) //default to the layers edit form
  {
    mDesignerForm = mVectorLayer->annotationForm();
    QObject::connect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( setFeatureForMapPosition() ) );
    QObject::connect( mMapCanvas, SIGNAL( renderComplete( QPainter* ) ), this, SLOT( setFeatureForMapPosition() ) );
    QObject::connect( mMapCanvas, SIGNAL( layersChanged() ), this, SLOT( updateVisibility() ) );
  }
コード例 #3
0
QgsHtmlAnnotationItem::QgsHtmlAnnotationItem( QgsMapCanvas* canvas, QgsVectorLayer* vlayer, bool hasFeature, int feature )
    : QgsAnnotationItem( canvas )
    , mWidgetContainer( 0 )
    , mWebView( 0 )
    , mVectorLayer( vlayer )
    , mHasAssociatedFeature( hasFeature )
    , mFeatureId( feature )
{
  mWebView = new QgsWebView();
  mWebView->page()->setNetworkAccessManager( QgsNetworkAccessManager::instance() );

  mWidgetContainer = new QGraphicsProxyWidget( this );
  mWidgetContainer->setWidget( mWebView );

  QObject::connect( mWebView->page()->mainFrame(), SIGNAL( javaScriptWindowObjectCleared() ), this, SLOT( javascript() ) );

  if ( mVectorLayer && mMapCanvas )
  {
    QObject::connect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( setFeatureForMapPosition() ) );
    QObject::connect( mMapCanvas, SIGNAL( renderComplete( QPainter* ) ), this, SLOT( setFeatureForMapPosition() ) );
    QObject::connect( mMapCanvas, SIGNAL( layersChanged() ), this, SLOT( updateVisibility() ) );
  }
コード例 #4
0
QgsMapCanvasAnnotationItem::QgsMapCanvasAnnotationItem( QgsAnnotation *annotation, QgsMapCanvas *mapCanvas )
  : QgsMapCanvasItem( mapCanvas )
  , mAnnotation( annotation )
{
  setFlag( QGraphicsItem::ItemIsSelectable, true );
  if ( mapCanvas && !mapCanvas->annotationsVisible() )
    setVisible( false );

  connect( mAnnotation, &QgsAnnotation::appearanceChanged, this, [this] { update(); } );
  connect( mAnnotation, &QgsAnnotation::moved, this, [this] { updatePosition(); } );
  connect( mAnnotation, &QgsAnnotation::moved, this, &QgsMapCanvasAnnotationItem::setFeatureForMapPosition );
  connect( mMapCanvas, &QgsMapCanvas::destinationCrsChanged, this, [ = ] { updatePosition(); } );

  connect( mAnnotation, &QgsAnnotation::appearanceChanged, this, &QgsMapCanvasAnnotationItem::updateBoundingRect );

  connect( mMapCanvas, &QgsMapCanvas::layersChanged, this, &QgsMapCanvasAnnotationItem::onCanvasLayersChanged );
  connect( mAnnotation, &QgsAnnotation::mapLayerChanged, this, &QgsMapCanvasAnnotationItem::onCanvasLayersChanged );

  //lifetime is tied to annotation!
  connect( mAnnotation, &QgsAnnotation::destroyed, this, &QgsMapCanvasAnnotationItem::deleteLater );

  updatePosition();
  setFeatureForMapPosition();
}