Quantum GIS API Documentation  1.7.4
src/gui/qgsmapcanvas.h
Go to the documentation of this file.
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 /* $Id: qgsmapcanvas.h 5341 2006-04-22 12:11:36Z wonder $ */
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 QgsHighlight;
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     QgsMapLayer* mLayer;
00081 
00083     bool mVisible;
00084 
00086     bool mInOverview;
00087 };
00088 
00089 
00094 class GUI_EXPORT QgsMapCanvas : public QGraphicsView
00095 {
00096     Q_OBJECT
00097 
00098   public:
00099 
00100     enum WheelAction { WheelZoom, WheelZoomAndRecenter, WheelZoomToMouseCursor, WheelNothing };
00101 
00103     QgsMapCanvas( QWidget * parent = 0, const char *name = 0 );
00104 
00106     ~QgsMapCanvas();
00107 
00108     void setLayerSet( QList<QgsMapCanvasLayer>& layers );
00109 
00110     void setCurrentLayer( QgsMapLayer* layer );
00111 
00112     void updateOverview();
00113 
00114     void enableOverviewMode( QgsMapOverviewCanvas* overview );
00115 
00116     QgsMapCanvasMap* map();
00117 
00118     QgsMapRenderer* mapRenderer();
00119 
00122     Q_DECL_DEPRECATED QPixmap& canvasPixmap();
00123 
00125     QPaintDevice &canvasPaintDevice();
00126 
00128     double scale();
00129 
00131     void clear();
00132 
00134     double mapUnitsPerPixel() const;
00135 
00137     QgsRectangle extent() const;
00139     QgsRectangle fullExtent() const;
00140 
00142     void setExtent( QgsRectangle const & r );
00143 
00145     void zoomToFullExtent();
00146 
00148     void zoomToPreviousExtent();
00149 
00151     void zoomToNextExtent();
00152 
00153     // ! Clears the list of extents and sets current extent as first item
00154     void clearExtentHistory();
00155 
00158     void zoomToSelected( QgsVectorLayer* layer = NULL );
00159 
00161     void setMapTool( QgsMapTool* mapTool );
00162 
00169     void unsetMapTool( QgsMapTool* mapTool );
00170 
00172     QgsMapTool* mapTool();
00173 
00175     virtual void setCanvasColor( const QColor & _newVal );
00177     virtual QColor canvasColor() const;
00178 
00180     void updateScale();
00181 
00183     void updateFullExtent();
00184 
00186     QgsMapLayer *layer( int index );
00187 
00189     int layerCount() const;
00190 
00192     QList<QgsMapLayer*> layers() const;
00193 
00199     void freeze( bool frz = true );
00200 
00202     bool isFrozen();
00203 
00205     void setDirty( bool _dirty );
00206 
00208     bool isDirty() const;
00209 
00211     void setMapUnits( QGis::UnitType mapUnits );
00213 
00214     QGis::UnitType mapUnits() const;
00215 
00217     const QgsMapToPixel* getCoordinateTransform();
00218 
00220     bool isDrawing();
00221 
00223     QgsMapLayer* currentLayer();
00224 
00226     void setWheelAction( WheelAction action, double factor = 2 );
00227 
00229     void zoomIn( );
00230 
00232     void zoomOut( );
00233 
00235     // added in 1.5
00236     void zoomScale( double scale );
00237 
00239     void zoomByFactor( double scaleFactor );
00240 
00242     void zoomWithCenter( int x, int y, bool zoomIn );
00243 
00245     void enableAntiAliasing( bool theFlag );
00246 
00248     bool antiAliasingEnabled() const { return mAntiAliasing; }
00249 
00251     void useImageToRender( bool theFlag );
00252 
00253     // following 2 methods should be moved elsewhere or changed to private
00254     // currently used by pan map tool
00256     void panActionEnd( QPoint releasePoint );
00257 
00259     void panAction( QMouseEvent * event );
00260 
00262     QPoint mouseLastXY();
00263 
00264   public slots:
00265 
00267     void refresh();
00268 
00270     void selectionChangedSlot();
00271 
00273     void saveAsImage( QString theFileName, QPixmap * QPixmap = 0, QString = "PNG" );
00274 
00276     void layerStateChange();
00277 
00279     void setRenderFlag( bool theFlag );
00281     bool renderFlag() {return mRenderFlag;};
00282 
00284     bool hasCrsTransformEnabled();
00285 
00287     void mapUnitsChanged();
00288 
00290     void updateMap();
00291 
00293     void showError( QgsMapLayer * mapLayer );
00294 
00296     void readProject( const QDomDocument & );
00297 
00299     void writeProject( QDomDocument & );
00300 
00301   signals:
00303     void setProgress( int, int );
00304 
00307     void xyCoordinates( const QgsPoint & p );
00308 
00310     void scaleChanged( double );
00311 
00313     void extentsChanged();
00314 
00323     void renderComplete( QPainter * );
00324 
00327     void renderStarting();
00328 
00330     void layersChanged();
00331 
00333     void keyPressed( QKeyEvent * e );
00334 
00336     void keyReleased( QKeyEvent * e );
00337 
00339     void mapToolSet( QgsMapTool * tool );
00340 
00342     void selectionChanged( QgsMapLayer * layer );
00343 
00346     void zoomLastStatusChanged( bool );
00347 
00350     void zoomNextStatusChanged( bool );
00351 
00352   protected:
00354     void keyPressEvent( QKeyEvent * e );
00355 
00357     void keyReleaseEvent( QKeyEvent * e );
00358 
00360     void mouseDoubleClickEvent( QMouseEvent * e );
00361 
00363     void mouseMoveEvent( QMouseEvent * e );
00364 
00366     void mousePressEvent( QMouseEvent * e );
00367 
00369     void mouseReleaseEvent( QMouseEvent * e );
00370 
00372     void wheelEvent( QWheelEvent * e );
00373 
00375     void resizeEvent( QResizeEvent * e );
00376 
00378     void paintEvent( QPaintEvent * e );
00379 
00381     void moveCanvasContents( bool reset = false );
00382 
00384     void updateCanvasItemPositions();
00385 
00387     class CanvasProperties;
00388 
00390     std::auto_ptr<CanvasProperties> mCanvasProperties;
00391 
00392   private:
00394 
00400     QgsMapCanvas( QgsMapCanvas const & );
00401 
00403     QgsMapRenderer* mMapRenderer;
00404 
00406     QgsMapCanvasMap* mMap;
00407 
00409     QgsMapOverviewCanvas* mMapOverview;
00410 
00412     bool mDrawing;
00413 
00415     bool mFrozen;
00416 
00426     bool mDirty;
00427 
00429     bool mRenderFlag;
00430 
00434     QList< QPair<int, int> > mResizeQueue;
00435 
00439     void connectNotify( const char * signal );
00440 
00442     QgsMapLayer* mCurrentLayer;
00443 
00445     QGraphicsScene* mScene;
00446 
00448     QgsMapTool* mMapTool;
00449 
00451     QgsMapTool* mLastNonZoomMapTool;
00452 
00454     QList <QgsRectangle> mLastExtent;
00455     int mLastExtentIndex;
00456 
00458     double mWheelZoomFactor;
00459 
00461     WheelAction mWheelAction;
00462 
00464     QSize mNewSize;
00465 
00467     bool mPainting;
00468 
00470     bool mAntiAliasing;
00471 }; // class QgsMapCanvas
00472 
00473 
00474 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines