Quantum GIS API Documentation
1.8
|
00001 /*************************************************************************** 00002 qgsmapcanvas.h - description 00003 ------------------- 00004 begin : Sun Jun 30 2002 00005 copyright : (C) 2002 by Gary E.Sherman 00006 email : sherman at mrcc.com 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef QGSMAPCANVAS_H 00019 #define QGSMAPCANVAS_H 00020 00021 #include <list> 00022 #include <memory> 00023 #include <deque> 00024 00025 #include "qgsrectangle.h" 00026 #include "qgspoint.h" 00027 #include "qgis.h" 00028 00029 #include <QDomDocument> 00030 #include <QGraphicsView> 00031 #include <QtCore> 00032 00033 #ifdef HAVE_TOUCH 00034 #include <QGestureEvent> 00035 #endif 00036 00037 class QWheelEvent; 00038 class QPixmap; 00039 class QPaintEvent; 00040 class QKeyEvent; 00041 class ResizeEvent; 00042 00043 class QColor; 00044 class QDomDocument; 00045 class QPaintDevice; 00046 class QMouseEvent; 00047 class QRubberBand; 00048 class QGraphicsScene; 00049 00050 class QgsMapToPixel; 00051 class QgsMapLayer; 00052 class QgsLegend; 00053 class QgsLegendView; 00054 class QgsHighlight; 00055 class QgsVectorLayer; 00056 00057 class QgsMapRenderer; 00058 class QgsMapCanvasMap; 00059 class QgsMapOverviewCanvas; 00060 class QgsMapTool; 00061 00067 class GUI_EXPORT QgsMapCanvasLayer 00068 { 00069 public: 00070 QgsMapCanvasLayer( QgsMapLayer* layer, bool visible = true, bool isInOverview = false ) 00071 : mLayer( layer ), mVisible( visible ), mInOverview( isInOverview ) {} 00072 00073 void setVisible( bool visible ) { mVisible = visible; } 00074 void setInOverview( bool isInOverview ) { mInOverview = isInOverview; } 00075 00076 bool isVisible() const { return mVisible; } 00077 bool isInOverview() const { return mInOverview; } 00078 00079 QgsMapLayer* layer() { return mLayer; } 00080 const QgsMapLayer* layer() const { return mLayer; } 00081 00082 private: 00083 QgsMapLayer* mLayer; 00084 00086 bool mVisible; 00087 00089 bool mInOverview; 00090 }; 00091 00092 00097 class GUI_EXPORT QgsMapCanvas : public QGraphicsView 00098 { 00099 Q_OBJECT 00100 00101 public: 00102 00103 enum WheelAction { WheelZoom, WheelZoomAndRecenter, WheelZoomToMouseCursor, WheelNothing }; 00104 00106 QgsMapCanvas( QWidget * parent = 0, const char *name = 0 ); 00107 00109 ~QgsMapCanvas(); 00110 00111 void setLayerSet( QList<QgsMapCanvasLayer>& layers ); 00112 00113 void setCurrentLayer( QgsMapLayer* layer ); 00114 00115 void updateOverview(); 00116 00117 void enableOverviewMode( QgsMapOverviewCanvas* overview ); 00118 00119 QgsMapCanvasMap* map(); 00120 00121 QgsMapRenderer* mapRenderer(); 00122 00125 Q_DECL_DEPRECATED QPixmap& canvasPixmap(); 00126 00128 QPaintDevice &canvasPaintDevice(); 00129 00131 double scale(); 00132 00134 void clear(); 00135 00137 double mapUnitsPerPixel() const; 00138 00140 QgsRectangle extent() const; 00142 QgsRectangle fullExtent() const; 00143 00145 void setExtent( QgsRectangle const & r ); 00146 00148 void zoomToFullExtent(); 00149 00151 void zoomToPreviousExtent(); 00152 00154 void zoomToNextExtent(); 00155 00156 // ! Clears the list of extents and sets current extent as first item 00157 void clearExtentHistory(); 00158 00161 void zoomToSelected( QgsVectorLayer* layer = NULL ); 00162 00165 void panToSelected( QgsVectorLayer* layer = NULL ); 00166 00168 void setMapTool( QgsMapTool* mapTool ); 00169 00176 void unsetMapTool( QgsMapTool* mapTool ); 00177 00179 QgsMapTool* mapTool(); 00180 00182 virtual void setCanvasColor( const QColor & _newVal ); 00184 virtual QColor canvasColor() const; 00185 00187 void updateScale(); 00188 00190 void updateFullExtent(); 00191 00193 QgsMapLayer *layer( int index ); 00194 00196 int layerCount() const; 00197 00199 QList<QgsMapLayer*> layers() const; 00200 00206 void freeze( bool frz = true ); 00207 00209 bool isFrozen(); 00210 00212 void setDirty( bool _dirty ); 00213 00215 bool isDirty() const; 00216 00218 void setMapUnits( QGis::UnitType mapUnits ); 00220 00221 QGis::UnitType mapUnits() const; 00222 00224 const QgsMapToPixel* getCoordinateTransform(); 00225 00227 bool isDrawing(); 00228 00230 QgsMapLayer* currentLayer(); 00231 00233 void setWheelAction( WheelAction action, double factor = 2 ); 00234 00236 void zoomIn( ); 00237 00239 void zoomOut( ); 00240 00242 // added in 1.5 00243 void zoomScale( double scale ); 00244 00246 void zoomByFactor( double scaleFactor ); 00247 00249 void zoomWithCenter( int x, int y, bool zoomIn ); 00250 00252 void enableAntiAliasing( bool theFlag ); 00253 00255 bool antiAliasingEnabled() const { return mAntiAliasing; } 00256 00258 void useImageToRender( bool theFlag ); 00259 00260 // following 2 methods should be moved elsewhere or changed to private 00261 // currently used by pan map tool 00263 void panActionEnd( QPoint releasePoint ); 00264 00266 void panAction( QMouseEvent * event ); 00267 00269 QPoint mouseLastXY(); 00270 00271 public slots: 00272 00274 void refresh(); 00275 00277 void selectionChangedSlot(); 00278 00280 void saveAsImage( QString theFileName, QPixmap * QPixmap = 0, QString = "PNG" ); 00281 00283 void layerStateChange(); 00284 00286 void setRenderFlag( bool theFlag ); 00288 bool renderFlag() {return mRenderFlag;}; 00289 00291 bool hasCrsTransformEnabled(); 00292 00294 void mapUnitsChanged(); 00295 00297 void updateMap(); 00298 00300 void showError( QgsMapLayer * mapLayer ); 00301 00303 void readProject( const QDomDocument & ); 00304 00306 void writeProject( QDomDocument & ); 00307 00308 private slots: 00310 void mapToolDestroyed(); 00311 00312 signals: 00314 void setProgress( int, int ); 00315 00318 void xyCoordinates( const QgsPoint & p ); 00319 00321 void scaleChanged( double ); 00322 00324 void extentsChanged(); 00325 00334 void renderComplete( QPainter * ); 00335 00338 void renderStarting(); 00339 00341 void layersChanged(); 00342 00344 void keyPressed( QKeyEvent * e ); 00345 00347 void keyReleased( QKeyEvent * e ); 00348 00350 void mapToolSet( QgsMapTool * tool ); 00351 00353 void selectionChanged( QgsMapLayer * layer ); 00354 00357 void zoomLastStatusChanged( bool ); 00358 00361 void zoomNextStatusChanged( bool ); 00362 00363 protected: 00364 #ifdef HAVE_TOUCH 00365 00366 bool event( QEvent * e ); 00367 #endif 00368 00370 void keyPressEvent( QKeyEvent * e ); 00371 00373 void keyReleaseEvent( QKeyEvent * e ); 00374 00376 void mouseDoubleClickEvent( QMouseEvent * e ); 00377 00379 void mouseMoveEvent( QMouseEvent * e ); 00380 00382 void mousePressEvent( QMouseEvent * e ); 00383 00385 void mouseReleaseEvent( QMouseEvent * e ); 00386 00388 void wheelEvent( QWheelEvent * e ); 00389 00391 void resizeEvent( QResizeEvent * e ); 00392 00394 void paintEvent( QPaintEvent * e ); 00395 00397 void dragEnterEvent( QDragEnterEvent * e ); 00398 00400 void moveCanvasContents( bool reset = false ); 00401 00403 void updateCanvasItemPositions(); 00404 00406 class CanvasProperties; 00407 00409 std::auto_ptr<CanvasProperties> mCanvasProperties; 00410 00411 private slots: 00412 void crsTransformEnabled( bool ); 00413 00414 private: 00416 00422 QgsMapCanvas( QgsMapCanvas const & ); 00423 00425 QgsMapRenderer* mMapRenderer; 00426 00428 QgsMapCanvasMap* mMap; 00429 00431 QgsMapOverviewCanvas* mMapOverview; 00432 00434 bool mDrawing; 00435 00437 bool mFrozen; 00438 00448 bool mDirty; 00449 00451 bool mRenderFlag; 00452 00456 QList< QPair<int, int> > mResizeQueue; 00457 00461 void connectNotify( const char * signal ); 00462 00464 QgsMapLayer* mCurrentLayer; 00465 00467 QGraphicsScene* mScene; 00468 00470 QgsMapTool* mMapTool; 00471 00473 QgsMapTool* mLastNonZoomMapTool; 00474 00476 QList <QgsRectangle> mLastExtent; 00477 int mLastExtentIndex; 00478 00480 double mWheelZoomFactor; 00481 00483 WheelAction mWheelAction; 00484 00486 QSize mNewSize; 00487 00489 bool mPainting; 00490 00492 bool mAntiAliasing; 00493 }; // class QgsMapCanvas 00494 00495 00496 #endif