Beispiel #1
0
QgsMapCanvas::QgsMapCanvas( QWidget * parent )
    : QGraphicsView( parent )
    , mCanvasProperties( new CanvasProperties )
    , mMap( nullptr )
    , mFrozen( false )
    , mRefreshScheduled( false )
    , mRenderFlag( true ) // by default, the canvas is rendered
    , mCurrentLayer( nullptr )
    , mScene( nullptr )
    , mMapTool( nullptr )
    , mLastNonZoomMapTool( nullptr )
    , mLastExtentIndex( -1 )
    , mWheelZoomFactor( 2.0 )
    , mJob( nullptr )
    , mJobCancelled( false )
    , mLabelingResults( nullptr )
    , mUseParallelRendering( false )
    , mDrawRenderingStats( false )
    , mCache( nullptr )
    , mResizeTimer( nullptr )
    , mPreviewEffect( nullptr )
    , mSnappingUtils( nullptr )
    , mScaleLocked( false )
    , mExpressionContextScope( tr( "Map Canvas" ) )
    , mZoomDragging( false )
{
  mScene = new QGraphicsScene();
  setScene( mScene );
  setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
  setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
  setMouseTracking( true );
  setFocusPolicy( Qt::StrongFocus );

  mResizeTimer = new QTimer( this );
  mResizeTimer->setSingleShot( true );
  connect( mResizeTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) );

  // create map canvas item which will show the map
  mMap = new QgsMapCanvasMap( this );

  // project handling
  connect( QgsProject::instance(), SIGNAL( readProject( const QDomDocument & ) ),
           this, SLOT( readProject( const QDomDocument & ) ) );
  connect( QgsProject::instance(), SIGNAL( writeProject( QDomDocument & ) ),
           this, SLOT( writeProject( QDomDocument & ) ) );

  mSettings.setFlag( QgsMapSettings::DrawEditingInfo );
  mSettings.setFlag( QgsMapSettings::UseRenderingOptimization );
  mSettings.setFlag( QgsMapSettings::RenderPartialOutput );

  //segmentation parameters
  QSettings settings;
  double segmentationTolerance = settings.value( QStringLiteral( "/qgis/segmentationTolerance" ), "0.01745" ).toDouble();
  QgsAbstractGeometry::SegmentationToleranceType toleranceType = QgsAbstractGeometry::SegmentationToleranceType( settings.value( QStringLiteral( "/qgis/segmentationToleranceType" ), 0 ).toInt() );
  mSettings.setSegmentationTolerance( segmentationTolerance );
  mSettings.setSegmentationToleranceType( toleranceType );

  mWheelZoomFactor = settings.value( QStringLiteral( "/qgis/zoom_factor" ), 2 ).toDouble();

  QSize s = viewport()->size();
  mSettings.setOutputSize( s );
  setSceneRect( 0, 0, s.width(), s.height() );
  mScene->setSceneRect( QRectF( 0, 0, s.width(), s.height() ) );

  moveCanvasContents( true );

  connect( &mMapUpdateTimer, SIGNAL( timeout() ), SLOT( mapUpdateTimeout() ) );
  mMapUpdateTimer.setInterval( 250 );

#ifdef Q_OS_WIN
  // Enable touch event on Windows.
  // Qt on Windows needs to be told it can take touch events or else it ignores them.
  grabGesture( Qt::PinchGesture );
  viewport()->setAttribute( Qt::WA_AcceptTouchEvents );
#endif

  mPreviewEffect = new QgsPreviewEffect( this );
  viewport()->setGraphicsEffect( mPreviewEffect );

  QPixmap zoomPixmap = QPixmap(( const char ** )( zoom_in ) );
  mZoomCursor = QCursor( zoomPixmap, 7, 7 );

  setInteractive( false );

  refresh();

} // QgsMapCanvas ctor
Beispiel #2
0
QgsMapCanvas::QgsMapCanvas( QWidget * parent, const char *name )
    : QGraphicsView( parent )
    , mCanvasProperties( new CanvasProperties )
    , mJob( 0 )
    , mJobCancelled( false )
    , mLabelingResults( 0 )
    , mUseParallelRendering( false )
    , mDrawRenderingStats( false )
    , mCache( 0 )
    , mPreviewEffect( 0 )
    , mSnappingUtils( 0 )
{
  setObjectName( name );
  mScene = new QGraphicsScene();
  setScene( mScene );
  setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
  setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
  mLastExtentIndex = -1;
  mCurrentLayer = NULL;
  mMapOverview = NULL;
  mMapTool = NULL;
  mLastNonZoomMapTool = NULL;

  mFrozen = false;
  mRefreshScheduled = false;

  setWheelAction( WheelZoom );

  // by default, the canvas is rendered
  mRenderFlag = true;

  setMouseTracking( true );
  setFocusPolicy( Qt::StrongFocus );

  mMapRenderer = new QgsMapRenderer;

  mResizeTimer = new QTimer( this );
  mResizeTimer->setSingleShot( true );
  connect( mResizeTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) );

  // create map canvas item which will show the map
  mMap = new QgsMapCanvasMap( this );

  // project handling
  connect( QgsProject::instance(), SIGNAL( readProject( const QDomDocument & ) ),
           this, SLOT( readProject( const QDomDocument & ) ) );
  connect( QgsProject::instance(), SIGNAL( writeProject( QDomDocument & ) ),
           this, SLOT( writeProject( QDomDocument & ) ) );

  mSettings.setFlag( QgsMapSettings::DrawEditingInfo );
  mSettings.setFlag( QgsMapSettings::UseRenderingOptimization );

  // class that will sync most of the changes between canvas and (legacy) map renderer
  // it is parented to map canvas, will be deleted automatically
  new QgsMapCanvasRendererSync( this, mMapRenderer );

  QSize s = viewport()->size();
  mSettings.setOutputSize( s );
  mMapRenderer->setOutputSize( s, mSettings.outputDpi() );
  setSceneRect( 0, 0, s.width(), s.height() );
  mScene->setSceneRect( QRectF( 0, 0, s.width(), s.height() ) );

  moveCanvasContents( true );

  connect( &mMapUpdateTimer, SIGNAL( timeout() ), SLOT( mapUpdateTimeout() ) );
  mMapUpdateTimer.setInterval( 250 );

#ifdef Q_OS_WIN
  // Enable touch event on Windows.
  // Qt on Windows needs to be told it can take touch events or else it ignores them.
  grabGesture( Qt::PinchGesture );
  viewport()->setAttribute( Qt::WA_AcceptTouchEvents );
#endif

  mPreviewEffect = new QgsPreviewEffect( this );
  viewport()->setGraphicsEffect( mPreviewEffect );

  setInteractive( false );

  refresh();

} // QgsMapCanvas ctor