00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef QGSMAPCANVAS_H
00020 #define QGSMAPCANVAS_H
00021
00022 #include <list>
00023 #include <memory>
00024 #include <deque>
00025
00026 #include "qgsrectangle.h"
00027 #include "qgspoint.h"
00028 #include "qgis.h"
00029
00030 #include <QDomDocument>
00031 #include <QGraphicsView>
00032 #include <QtCore>
00033
00034 class QWheelEvent;
00035 class QPixmap;
00036 class QPaintEvent;
00037 class QKeyEvent;
00038 class ResizeEvent;
00039
00040 class QColor;
00041 class QDomDocument;
00042 class QPaintDevice;
00043 class QMouseEvent;
00044 class QRubberBand;
00045 class QGraphicsScene;
00046
00047 class QgsMapToPixel;
00048 class QgsMapLayer;
00049 class QgsLegend;
00050 class QgsLegendView;
00051 class QgsRubberBand;
00052 class QgsVectorLayer;
00053
00054 class QgsMapRenderer;
00055 class QgsMapCanvasMap;
00056 class QgsMapOverviewCanvas;
00057 class QgsMapTool;
00058
00064 class GUI_EXPORT QgsMapCanvasLayer
00065 {
00066 public:
00067 QgsMapCanvasLayer( QgsMapLayer* layer, bool visible = true, bool isInOverview = false )
00068 : mLayer( layer ), mVisible( visible ), mInOverview( isInOverview ) {}
00069
00070 void setVisible( bool visible ) { mVisible = visible; }
00071 void setInOverview( bool isInOverview ) { mInOverview = isInOverview; }
00072
00073 bool isVisible() const { return mVisible; }
00074 bool isInOverview() const { return mInOverview; }
00075
00076 QgsMapLayer* layer() { return mLayer; }
00077 const QgsMapLayer* layer() const { return mLayer; }
00078
00079 private:
00080
00081 QgsMapLayer* mLayer;
00082
00084 bool mVisible;
00085
00087 bool mInOverview;
00088 };
00089
00090
00095 class GUI_EXPORT QgsMapCanvas : public QGraphicsView
00096 {
00097 Q_OBJECT
00098
00099 public:
00100
00101 enum WheelAction { WheelZoom, WheelZoomAndRecenter, WheelZoomToMouseCursor, WheelNothing };
00102
00104 QgsMapCanvas( QWidget * parent = 0, const char *name = 0 );
00105
00107 ~QgsMapCanvas();
00108
00109 void setLayerSet( QList<QgsMapCanvasLayer>& layers );
00110
00111 void setCurrentLayer( QgsMapLayer* layer );
00112
00113 void updateOverview();
00114
00115 void enableOverviewMode( QgsMapOverviewCanvas* overview );
00116
00117 QgsMapCanvasMap* map();
00118
00119 QgsMapRenderer* mapRenderer();
00120
00122 QPixmap& canvasPixmap();
00123
00125 double scale();
00126
00128 void clear();
00129
00131 double mapUnitsPerPixel() const;
00132
00134 QgsRectangle extent() const;
00136 QgsRectangle fullExtent() const;
00137
00139 void setExtent( QgsRectangle const & r );
00140
00142 void zoomToFullExtent();
00143
00145 void zoomToPreviousExtent();
00146
00148 void zoomToNextExtent();
00149
00150
00151 void clearExtentHistory();
00152
00155 void zoomToSelected( QgsVectorLayer* layer = NULL );
00156
00158 void setMapTool( QgsMapTool* mapTool );
00159
00166 void unsetMapTool( QgsMapTool* mapTool );
00167
00169 QgsMapTool* mapTool();
00170
00172 virtual void setCanvasColor( const QColor & _newVal );
00174 virtual QColor canvasColor() const;
00175
00177 void updateScale();
00178
00180 void updateFullExtent();
00181
00183 QgsMapLayer *layer( int index );
00184
00186 int layerCount() const;
00187
00189 QList<QgsMapLayer*> layers() const;
00190
00196 void freeze( bool frz = true );
00197
00199 bool isFrozen();
00200
00202 void setDirty( bool _dirty );
00203
00205 bool isDirty() const;
00206
00208 void setMapUnits( QGis::UnitType mapUnits );
00210
00211 QGis::UnitType mapUnits() const;
00212
00214 const QgsMapToPixel* getCoordinateTransform();
00215
00217 bool isDrawing();
00218
00220 QgsMapLayer* currentLayer();
00221
00223 void setWheelAction( WheelAction action, double factor = 2 );
00224
00226 void zoomIn( );
00227
00229 void zoomOut( );
00230
00232
00233 void zoomScale( double scale );
00234
00236 void zoomByFactor( double scaleFactor );
00237
00239 void zoomWithCenter( int x, int y, bool zoomIn );
00240
00242 void enableAntiAliasing( bool theFlag );
00243
00245 void useImageToRender( bool theFlag );
00246
00247
00248
00250 void panActionEnd( QPoint releasePoint );
00251
00253 void panAction( QMouseEvent * event );
00254
00256 QPoint mouseLastXY();
00257
00258 public slots:
00259
00261 void refresh();
00262
00264 void selectionChangedSlot();
00265
00267 void saveAsImage( QString theFileName, QPixmap * QPixmap = 0, QString = "PNG" );
00268
00270 void layerStateChange();
00271
00273 void setRenderFlag( bool theFlag );
00275 bool renderFlag() {return mRenderFlag;};
00276
00278 bool hasCrsTransformEnabled();
00279
00281 void mapUnitsChanged();
00282
00284 void updateMap();
00285
00287 void showError( QgsMapLayer * mapLayer );
00288
00290 void readProject( const QDomDocument & );
00291
00293 void writeProject( QDomDocument & );
00294
00295 signals:
00297 void setProgress( int, int );
00298
00301 void xyCoordinates( const QgsPoint & p );
00302
00304 void scaleChanged( double );
00305
00307 void extentsChanged();
00308
00317 void renderComplete( QPainter * );
00318
00321 void renderStarting();
00322
00324 void layersChanged();
00325
00327 void keyPressed( QKeyEvent * e );
00328
00330 void keyReleased( QKeyEvent * e );
00331
00333 void mapToolSet( QgsMapTool * tool );
00334
00336 void selectionChanged( QgsMapLayer * layer );
00337
00340 void zoomLastStatusChanged( bool );
00341
00344 void zoomNextStatusChanged( bool );
00345
00346 protected:
00348 void keyPressEvent( QKeyEvent * e );
00349
00351 void keyReleaseEvent( QKeyEvent * e );
00352
00354 void mouseDoubleClickEvent( QMouseEvent * e );
00355
00357 void mouseMoveEvent( QMouseEvent * e );
00358
00360 void mousePressEvent( QMouseEvent * e );
00361
00363 void mouseReleaseEvent( QMouseEvent * e );
00364
00366 void wheelEvent( QWheelEvent * e );
00367
00369 void resizeEvent( QResizeEvent * e );
00370
00372 void moveCanvasContents( bool reset = false );
00373
00375 void updateCanvasItemPositions();
00376
00378 class CanvasProperties;
00379
00381 std::auto_ptr<CanvasProperties> mCanvasProperties;
00382
00383 private:
00385
00391 QgsMapCanvas( QgsMapCanvas const & );
00392
00394 QgsMapRenderer* mMapRenderer;
00395
00397 QgsMapCanvasMap* mMap;
00398
00400 QgsMapOverviewCanvas* mMapOverview;
00401
00403 bool mDrawing;
00404
00406 bool mFrozen;
00407
00417 bool mDirty;
00418
00420 bool mRenderFlag;
00421
00425 QList< QPair<int, int> > mResizeQueue;
00426
00430 void connectNotify( const char * signal );
00431
00433 QgsMapLayer* mCurrentLayer;
00434
00436 QGraphicsScene* mScene;
00437
00439 QgsMapTool* mMapTool;
00440
00442 QgsMapTool* mLastNonZoomMapTool;
00443
00445 QList <QgsRectangle> mLastExtent;
00446 int mLastExtentIndex;
00447
00449 double mWheelZoomFactor;
00450
00452 WheelAction mWheelAction;
00453
00454 };
00455
00456
00457 #endif