|
Quantum GIS API Documentation
master-693a1fe
|
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 "qgsconfig.h" 00022 00023 #include <list> 00024 #include <memory> 00025 #include <deque> 00026 00027 #include "qgsrectangle.h" 00028 #include "qgspoint.h" 00029 #include "qgis.h" 00030 00031 #include <QDomDocument> 00032 #include <QGraphicsView> 00033 #include <QtCore> 00034 00035 #ifdef HAVE_TOUCH 00036 #include <QGestureEvent> 00037 #endif 00038 00039 class QWheelEvent; 00040 class QPixmap; 00041 class QPaintEvent; 00042 class QKeyEvent; 00043 class ResizeEvent; 00044 00045 class QColor; 00046 class QDomDocument; 00047 class QPaintDevice; 00048 class QMouseEvent; 00049 class QRubberBand; 00050 class QGraphicsScene; 00051 00052 class QgsMapToPixel; 00053 class QgsMapLayer; 00054 class QgsLegend; 00055 class QgsLegendView; 00056 class QgsHighlight; 00057 class QgsVectorLayer; 00058 00059 class QgsMapRenderer; 00060 class QgsMapCanvasMap; 00061 class QgsMapOverviewCanvas; 00062 class QgsMapTool; 00063 00069 class GUI_EXPORT QgsMapCanvasLayer 00070 { 00071 public: 00072 QgsMapCanvasLayer( QgsMapLayer* layer, bool visible = true, bool isInOverview = false ) 00073 : mLayer( layer ), mVisible( visible ), mInOverview( isInOverview ) {} 00074 00075 void setVisible( bool visible ) { mVisible = visible; } 00076 void setInOverview( bool isInOverview ) { mInOverview = isInOverview; } 00077 00078 bool isVisible() const { return mVisible; } 00079 bool isInOverview() const { return mInOverview; } 00080 00081 QgsMapLayer* layer() { return mLayer; } 00082 const QgsMapLayer* layer() const { return mLayer; } 00083 00084 private: 00085 QgsMapLayer* mLayer; 00086 00088 bool mVisible; 00089 00091 bool mInOverview; 00092 }; 00093 00094 00099 class GUI_EXPORT QgsMapCanvas : public QGraphicsView 00100 { 00101 Q_OBJECT 00102 00103 public: 00104 00105 enum WheelAction { WheelZoom, WheelZoomAndRecenter, WheelZoomToMouseCursor, WheelNothing }; 00106 00108 QgsMapCanvas( QWidget * parent = 0, const char *name = 0 ); 00109 00111 ~QgsMapCanvas(); 00112 00113 void setLayerSet( QList<QgsMapCanvasLayer>& layers ); 00114 00115 void setCurrentLayer( QgsMapLayer* layer ); 00116 00117 void updateOverview(); 00118 00119 void enableOverviewMode( QgsMapOverviewCanvas* overview ); 00120 00121 QgsMapCanvasMap* map(); 00122 00123 QgsMapRenderer* mapRenderer(); 00124 00126 QPaintDevice &canvasPaintDevice(); 00127 00129 double scale(); 00130 00132 void clear(); 00133 00135 double mapUnitsPerPixel() const; 00136 00138 QgsRectangle extent() const; 00140 QgsRectangle fullExtent() const; 00141 00143 void setExtent( const QgsRectangle &r ); 00144 00146 void zoomToFullExtent(); 00147 00149 void zoomToPreviousExtent(); 00150 00152 void zoomToNextExtent(); 00153 00154 // ! Clears the list of extents and sets current extent as first item 00155 void clearExtentHistory(); 00156 00159 void zoomToSelected( QgsVectorLayer* layer = NULL ); 00160 00163 void panToSelected( QgsVectorLayer* layer = NULL ); 00164 00166 void setMapTool( QgsMapTool* mapTool ); 00167 00174 void unsetMapTool( QgsMapTool* mapTool ); 00175 00177 QgsMapTool* mapTool(); 00178 00180 virtual void setCanvasColor( const QColor & _newVal ); 00182 virtual QColor canvasColor() const; 00183 00185 void updateScale(); 00186 00188 void updateFullExtent(); 00189 00191 QgsMapLayer *layer( int index ); 00192 00194 int layerCount() const; 00195 00197 QList<QgsMapLayer*> layers() const; 00198 00204 void freeze( bool frz = true ); 00205 00207 bool isFrozen(); 00208 00210 void setDirty( bool _dirty ); 00211 00213 bool isDirty() const; 00214 00216 void setMapUnits( QGis::UnitType mapUnits ); 00218 00219 QGis::UnitType mapUnits() const; 00220 00222 const QgsMapToPixel* getCoordinateTransform(); 00223 00225 bool isDrawing(); 00226 00228 QgsMapLayer* currentLayer(); 00229 00231 void setWheelAction( WheelAction action, double factor = 2 ); 00232 00234 void zoomIn( ); 00235 00237 void zoomOut( ); 00238 00240 // added in 1.5 00241 void zoomScale( double scale ); 00242 00244 void zoomByFactor( double scaleFactor ); 00245 00247 void zoomWithCenter( int x, int y, bool zoomIn ); 00248 00250 void enableAntiAliasing( bool theFlag ); 00251 00253 bool antiAliasingEnabled() const { return mAntiAliasing; } 00254 00256 void useImageToRender( bool theFlag ); 00257 00258 // following 2 methods should be moved elsewhere or changed to private 00259 // currently used by pan map tool 00261 void panActionEnd( QPoint releasePoint ); 00262 00264 void panAction( QMouseEvent * event ); 00265 00267 QPoint mouseLastXY(); 00268 00269 public slots: 00270 00272 void refresh(); 00273 00275 void selectionChangedSlot(); 00276 00278 void saveAsImage( QString theFileName, QPixmap * QPixmap = 0, QString = "PNG" ); 00279 00281 void layerStateChange(); 00282 00284 void setRenderFlag( bool theFlag ); 00286 bool renderFlag() {return mRenderFlag;}; 00287 00289 bool hasCrsTransformEnabled(); 00290 00292 void mapUnitsChanged(); 00293 00295 void updateMap(); 00296 00298 void showError( QgsMapLayer * mapLayer ); 00299 00301 void readProject( const QDomDocument & ); 00302 00304 void writeProject( QDomDocument & ); 00305 00306 private slots: 00308 void mapToolDestroyed(); 00309 00310 signals: 00312 void setProgress( int, int ); 00313 00316 void xyCoordinates( const QgsPoint &p ); 00317 00319 void scaleChanged( double ); 00320 00322 void extentsChanged(); 00323 00332 void renderComplete( QPainter * ); 00333 00336 void mapCanvasRefreshed(); 00337 00340 void renderStarting(); 00341 00343 void layersChanged(); 00344 00346 void keyPressed( QKeyEvent * e ); 00347 00349 void keyReleased( QKeyEvent * e ); 00350 00352 void mapToolSet( QgsMapTool *tool ); 00353 00355 void selectionChanged( QgsMapLayer * layer ); 00356 00359 void zoomLastStatusChanged( bool ); 00360 00363 void zoomNextStatusChanged( bool ); 00364 00365 protected: 00366 #ifdef HAVE_TOUCH 00367 00368 bool event( QEvent * e ); 00369 #endif 00370 00372 void keyPressEvent( QKeyEvent * e ); 00373 00375 void keyReleaseEvent( QKeyEvent * e ); 00376 00378 void mouseDoubleClickEvent( QMouseEvent * e ); 00379 00381 void mouseMoveEvent( QMouseEvent * e ); 00382 00384 void mousePressEvent( QMouseEvent * e ); 00385 00387 void mouseReleaseEvent( QMouseEvent * e ); 00388 00390 void wheelEvent( QWheelEvent * e ); 00391 00393 void resizeEvent( QResizeEvent * e ); 00394 00396 void paintEvent( QPaintEvent * e ); 00397 00399 void dragEnterEvent( QDragEnterEvent * e ); 00400 00402 void moveCanvasContents( bool reset = false ); 00403 00405 void updateCanvasItemPositions(); 00406 00408 class CanvasProperties; 00409 00411 std::auto_ptr<CanvasProperties> mCanvasProperties; 00412 00413 private slots: 00414 void crsTransformEnabled( bool ); 00415 00416 private: 00418 00424 QgsMapCanvas( QgsMapCanvas const & ); 00425 00427 QgsMapRenderer* mMapRenderer; 00428 00430 QgsMapCanvasMap* mMap; 00431 00433 QgsMapOverviewCanvas* mMapOverview; 00434 00436 bool mBackbufferEnabled; 00438 bool mDrawing; 00439 00441 bool mFrozen; 00442 00452 bool mDirty; 00453 00455 bool mRenderFlag; 00456 00460 QList< QPair<int, int> > mResizeQueue; 00461 00465 void connectNotify( const char * signal ); 00466 00468 QgsMapLayer* mCurrentLayer; 00469 00471 QGraphicsScene* mScene; 00472 00474 QgsMapTool* mMapTool; 00475 00477 QgsMapTool* mLastNonZoomMapTool; 00478 00480 QList <QgsRectangle> mLastExtent; 00481 int mLastExtentIndex; 00482 00484 double mWheelZoomFactor; 00485 00487 WheelAction mWheelAction; 00488 00490 QSize mNewSize; 00491 00493 bool mPainting; 00494 00496 bool mAntiAliasing; 00497 }; // class QgsMapCanvas 00498 00499 00500 #endif