~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/gui/qgsmapcanvas.h

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 *   (at your option) any later version.                                   *
15
15
 *                                                                         *
16
16
 ***************************************************************************/
17
 
/* $Id: qgsmapcanvas.h 6177 2006-12-03 21:29:01Z wonder $ */
 
17
/* $Id: qgsmapcanvas.h 5341 2006-04-22 12:11:36Z wonder $ */
18
18
 
19
19
#ifndef QGSMAPCANVAS_H
20
20
#define QGSMAPCANVAS_H
23
23
#include <memory>
24
24
#include <deque>
25
25
 
26
 
#include "qgsrect.h"
 
26
#include "qgsrectangle.h"
27
27
#include "qgspoint.h"
28
28
#include "qgis.h"
29
29
 
30
30
#include <QDomDocument>
31
 
#include <Q3CanvasView>
 
31
#include <QGraphicsView>
 
32
#include <QtCore>
32
33
 
33
34
class QWheelEvent;
34
35
class QPixmap;
35
36
class QPaintEvent;
36
37
class QKeyEvent;
37
 
class QResizeEvent;
 
38
class ResizeEvent;
38
39
 
39
40
class QColor;
 
41
class QDomDocument;
40
42
class QPaintDevice;
41
43
class QMouseEvent;
42
44
class QRubberBand;
43
 
class Q3Canvas;
 
45
class QGraphicsScene;
44
46
 
45
47
class QgsMapToPixel;
46
48
class QgsMapLayer;
47
 
class QgsMapLayerInterface;
48
49
class QgsLegend;
49
50
class QgsLegendView;
50
 
class QgsMeasure;
51
51
class QgsRubberBand;
 
52
class QgsVectorLayer;
52
53
 
53
 
class QgsMapRender;
 
54
class QgsMapRenderer;
54
55
class QgsMapCanvasMap;
55
56
class QgsMapOverviewCanvas;
56
 
class QgsMapCanvasMapImage;
57
57
class QgsMapTool;
58
58
 
59
 
/*! \class QgsMapCanvas
60
 
 * \brief Map canvas class for displaying all GIS data types.
 
59
/** \ingroup gui
 
60
  * A class that stores visibility and presence in overview flags together
 
61
  * with pointer to the layer.
 
62
  *
 
63
*/
 
64
class GUI_EXPORT QgsMapCanvasLayer
 
65
{
 
66
  public:
 
67
    QgsMapCanvasLayer( QgsMapLayer* layer, bool visible = TRUE, bool isInOverview = FALSE )
 
68
        : mLayer( layer ), mVisible( visible ), mInOverview( isInOverview ) {}
 
69
 
 
70
    void setVisible( bool visible ) { mVisible = visible; }
 
71
    void setInOverview( bool isInOverview ) { mInOverview = isInOverview; }
 
72
 
 
73
    bool isVisible() const { return mVisible; }
 
74
    bool isInOverview() const { return mInOverview; }
 
75
 
 
76
    QgsMapLayer* layer() { return mLayer; }
 
77
    const QgsMapLayer* layer() const { return mLayer; }
 
78
 
 
79
  private:
 
80
 
 
81
    QgsMapLayer* mLayer;
 
82
 
 
83
    /** Flag whether layer is visible */
 
84
    bool mVisible;
 
85
 
 
86
    /** Flag whether layer is shown in overview */
 
87
    bool mInOverview;
 
88
};
 
89
 
 
90
 
 
91
/** \ingroup gui
 
92
 * Map canvas is a class for displaying all GIS data types on a canvas.
61
93
 */
62
94
 
63
 
class QgsMapCanvas : public Q3CanvasView
 
95
class GUI_EXPORT QgsMapCanvas : public QGraphicsView
64
96
{
65
 
    Q_OBJECT;
 
97
    Q_OBJECT
66
98
 
67
99
  public:
68
 
    
69
 
    enum WheelAction { WheelZoom, WheelZoomAndRecenter, WheelNothing };
70
 
        
 
100
 
 
101
    enum WheelAction { WheelZoom, WheelZoomAndRecenter, WheelZoomToMouseCursor, WheelNothing };
 
102
 
71
103
    //! Constructor
72
 
    QgsMapCanvas(QWidget * parent = 0, const char *name = 0);
 
104
    QgsMapCanvas( QWidget * parent = 0, const char *name = 0 );
73
105
 
74
106
    //! Destructor
75
107
    ~QgsMapCanvas();
76
108
 
77
 
    void setLayerSet(std::deque<QString>& layerSet);
78
 
    
79
 
    void setCurrentLayer(QgsMapLayer* layer);
80
 
    
 
109
    void setLayerSet( QList<QgsMapCanvasLayer>& layers );
 
110
 
 
111
    void setCurrentLayer( QgsMapLayer* layer );
 
112
 
81
113
    void updateOverview();
82
 
    
83
 
    void setOverview(QgsMapOverviewCanvas* overview);
84
 
    
 
114
 
 
115
    void enableOverviewMode( QgsMapOverviewCanvas* overview );
 
116
 
85
117
    QgsMapCanvasMap* map();
86
 
    
87
 
    QgsMapRender* mapRender();
88
 
    
 
118
 
 
119
    QgsMapRenderer* mapRenderer();
 
120
 
89
121
    //! Accessor for the canvas pixmap
90
 
    QPixmap * canvasPixmap();
 
122
    QPixmap& canvasPixmap();
91
123
 
92
124
    //! Get the last reported scale of the canvas
93
 
    double getScale();
 
125
    double scale();
94
126
 
95
127
    //! Clear the map canvas
96
128
    void clear();
97
129
 
98
 
    //! Returns the mupp (map units per pixel) for the canvas
99
 
    double mupp() const;
 
130
    //! Returns the mapUnitsPerPixel (map units per pixel) for the canvas
 
131
    double mapUnitsPerPixel() const;
100
132
 
101
133
    //! Returns the current zoom exent of the map canvas
102
 
    QgsRect extent() const;
 
134
    QgsRectangle extent() const;
103
135
    //! Returns the combined exent for all layers on the map canvas
104
 
    QgsRect fullExtent() const;
 
136
    QgsRectangle fullExtent() const;
105
137
 
106
138
    //! Set the extent of the map canvas
107
 
    void setExtent(QgsRect const & r);
 
139
    void setExtent( QgsRectangle const & r );
108
140
 
109
141
    //! Zoom to the full extent of all layers
110
 
    void zoomFullExtent();
 
142
    void zoomToFullExtent();
111
143
 
112
144
    //! Zoom to the previous extent (view)
113
 
    void zoomPreviousExtent();
114
 
 
115
 
    /**Zooms to the extend of the selected features*/
116
 
    void zoomToSelected();
 
145
    void zoomToPreviousExtent();
 
146
 
 
147
    //! Zoom to the Next extent (view)
 
148
    void zoomToNextExtent();
 
149
 
 
150
    // ! Clears the list of extents and sets current extent as first item
 
151
    void clearExtentHistory();
 
152
 
 
153
    /** Zoom to the extent of the selected features of current (vector) layer.
 
154
      Added in version 1.2: optionally specify different than current layer */
 
155
    void zoomToSelected( QgsVectorLayer* layer = NULL );
117
156
 
118
157
    /** \brief Sets the map tool currently being used on the canvas */
119
 
    void setMapTool(QgsMapTool* mapTool);
120
 
    
 
158
    void setMapTool( QgsMapTool* mapTool );
 
159
 
121
160
    /** \brief Unset the current map tool or last non zoom tool
122
161
     *
123
162
     * This is called from destructor of map tools to make sure
124
163
     * that this map tool won't be used any more.
125
164
     * You don't have to call it manualy, QgsMapTool takes care of it.
126
165
     */
127
 
    void unsetMapTool(QgsMapTool* mapTool);
 
166
    void unsetMapTool( QgsMapTool* mapTool );
128
167
 
129
168
    /**Returns the currently active tool*/
130
169
    QgsMapTool* mapTool();
131
170
 
132
171
    /** Write property of QColor bgColor. */
133
 
    virtual void setCanvasColor(const QColor & _newVal);
 
172
    virtual void setCanvasColor( const QColor & _newVal );
 
173
    /** Read property of QColor bgColor. */
 
174
    virtual QColor canvasColor() const;
134
175
 
135
176
    /** Emits signal scalChanged to update scale in main window */
136
177
    void updateScale();
138
179
    /** Updates the full extent */
139
180
    void updateFullExtent();
140
181
 
141
 
    //! return the map layer at postion index in the layer stack
142
 
    QgsMapLayer *getZpos(int index);
143
 
    
144
 
    //! return the layer by name
145
 
    QgsMapLayer *layerByName(QString n);
 
182
    //! return the map layer at position index in the layer stack
 
183
    QgsMapLayer *layer( int index );
146
184
 
147
185
    //! return number of layers on the map
148
186
    int layerCount() const;
152
190
     * @param frz Boolean specifying if the canvas should be frozen (true) or
153
191
     * thawed (false). Default is true.
154
192
     */
155
 
    void freeze(bool frz = true);
 
193
    void freeze( bool frz = true );
156
194
 
157
195
    /*! Accessor for frozen status of canvas */
158
196
    bool isFrozen();
159
197
 
160
198
    //! Flag the canvas as dirty and needed a refresh
161
 
    void setDirty(bool _dirty);
 
199
    void setDirty( bool _dirty );
162
200
 
163
201
    //! Return the state of the canvas (dirty or not)
164
202
    bool isDirty() const;
165
203
 
166
204
    //! Set map units (needed by project properties dialog)
167
 
    void setMapUnits(QGis::units mapUnits);
 
205
    void setMapUnits( QGis::UnitType mapUnits );
168
206
    //! Get the current canvas map units
169
207
 
170
 
    QGis::units mapUnits() const;
 
208
    QGis::UnitType mapUnits() const;
171
209
 
172
210
    //! Get the current coordinate transform
173
 
    QgsMapToPixel * getCoordinateTransform();
174
 
 
175
 
    /** stores state in DOM node
176
 
        layerNode is DOM node corresponding to ``qgis'' tag
177
 
 
178
 
        The DOM node corresponds to a DOM document project file XML element to be
179
 
        written by QgsProject.
180
 
 
181
 
        Invoked by QgsProject::write().
182
 
 
183
 
        returns true if successful
184
 
    */
185
 
    bool writeXML( QDomNode & layerNode, QDomDocument & doc );
 
211
    const QgsMapToPixel* getCoordinateTransform();
186
212
 
187
213
    //! true if canvas currently drawing
188
214
    bool isDrawing();
189
 
    
 
215
 
190
216
    //! returns current layer (set by legend widget)
191
217
    QgsMapLayer* currentLayer();
192
 
    
 
218
 
193
219
    //! set wheel action and zoom factor (should be greater than 1)
194
 
    void setWheelAction(WheelAction action, double factor = 2);
195
 
 
196
 
    //! Zooms in/out preserving
197
 
    void zoom(bool zoomIn);
 
220
    void setWheelAction( WheelAction action, double factor = 2 );
 
221
 
 
222
    //! Zoom in with fixed factor
 
223
    void zoomIn( );
 
224
 
 
225
    //! Zoom out with fixed factor
 
226
    void zoomOut( );
 
227
 
 
228
    //! Zoom with the factor supplied. Factor > 1 zooms out, interval (0,1) zooms in
 
229
    void zoomByFactor( double scaleFactor );
198
230
 
199
231
    //! Zooms in/out with a given center
200
 
    void zoomWithCenter(int x, int y, bool zoomIn);
 
232
    void zoomWithCenter( int x, int y, bool zoomIn );
201
233
 
202
234
    //! used to determine if anti-aliasing is enabled or not
203
 
    void enableAntiAliasing(bool theFlag);
204
 
    
 
235
    void enableAntiAliasing( bool theFlag );
 
236
 
205
237
    //! Select which Qt class to render with
206
 
    void useQImageToRender(bool theFlag);
 
238
    void useImageToRender( bool theFlag );
207
239
 
208
240
    // following 2 methods should be moved elsewhere or changed to private
209
241
    // currently used by pan map tool
210
242
    //! Ends pan action and redraws the canvas.
211
 
    void panActionEnd(QPoint releasePoint);
 
243
    void panActionEnd( QPoint releasePoint );
 
244
 
212
245
    //! Called when mouse is moving and pan is activated
213
 
    void panAction(QMouseEvent * event);
214
 
    
 
246
    void panAction( QMouseEvent * event );
 
247
 
215
248
    //! returns last position of mouse cursor
216
249
    QPoint mouseLastXY();
217
 
  
 
250
 
218
251
  public slots:
219
252
 
220
 
    /**Sets dirty=true and calls render()*/
 
253
    /**Repaints the canvas map*/
221
254
    void refresh();
222
255
 
223
 
    virtual void render();
 
256
    //! Receives signal about selection change, and pass it on with layer info
 
257
    void selectionChangedSlot();
224
258
 
225
259
    //! Save the convtents of the map canvas to disk as an image
226
 
    void saveAsImage(QString theFileName,QPixmap * QPixmap=0, QString="PNG" );
 
260
    void saveAsImage( QString theFileName, QPixmap * QPixmap = 0, QString = "PNG" );
227
261
 
228
262
    //! This slot is connected to the visibility change of one or more layers
229
263
    void layerStateChange();
230
264
 
231
265
    //! Whether to suppress rendering or not
232
 
    void setRenderFlag(bool theFlag);
 
266
    void setRenderFlag( bool theFlag );
233
267
    //! State of render suppression flag
234
268
    bool renderFlag() {return mRenderFlag;};
235
269
 
236
270
    /** A simple helper method to find out if on the fly projections are enabled or not */
237
 
    bool projectionsEnabled();
 
271
    bool hasCrsTransformEnabled();
238
272
 
239
273
    /** The map units may have changed, so cope with that */
240
274
    void mapUnitsChanged();
241
 
    
 
275
 
242
276
    /** updates pixmap on render progress */
243
277
    void updateMap();
244
 
    
 
278
 
245
279
    //! show whatever error is exposed by the QgsMapLayer.
246
 
    void showError(QgsMapLayer * mapLayer);
247
 
    
248
 
    
249
 
signals:
 
280
    void showError( QgsMapLayer * mapLayer );
 
281
 
 
282
    //! called to read map canvas settings from project
 
283
    void readProject( const QDomDocument & );
 
284
 
 
285
    //! called to write map canvas settings to project
 
286
    void writeProject( QDomDocument & );
 
287
 
 
288
  signals:
250
289
    /** Let the owner know how far we are with render operations */
251
 
    void setProgress(int,int);
252
 
    /** emits current mouse position */
253
 
    void xyCoordinates(QgsPoint & p);
 
290
    void setProgress( int, int );
 
291
 
 
292
    /** emits current mouse position
 
293
        \note changed in 1.3 */
 
294
    void xyCoordinates( const QgsPoint & p );
254
295
 
255
296
    //! Emitted when the scale of the map changes
256
 
    void scaleChanged(QString);
 
297
    void scaleChanged( double );
257
298
 
258
299
    //! Emitted when the extents of the map change
259
 
    void extentsChanged(QgsRect);
 
300
    void extentsChanged();
260
301
 
261
302
    /** Emitted when the canvas has rendered.
262
303
 
266
307
     being rendered onto a pixmap other than the mapCanvas own pixmap member.
267
308
 
268
309
    */
269
 
    void renderComplete(QPainter *);
270
 
    
 
310
    void renderComplete( QPainter * );
 
311
 
271
312
    //! Emitted when a new set of layers has been received
272
313
    void layersChanged();
273
314
 
274
315
    //! Emit key press event
275
 
    void keyPressed(QKeyEvent * e);
 
316
    void keyPressed( QKeyEvent * e );
276
317
 
277
318
    //! Emit key release event
278
 
    void keyReleased(QKeyEvent * e);
279
 
    
280
 
protected:
 
319
    void keyReleased( QKeyEvent * e );
 
320
 
 
321
    //! Emit map tool changed event
 
322
    void mapToolSet( QgsMapTool * tool );
 
323
 
 
324
    //! Emitted when selection in any layer gets changed
 
325
    void selectionChanged( QgsMapLayer * layer );
 
326
 
 
327
    //! Emitted when zoom last status changed
 
328
    //! @note: this signal was added in version 1.4
 
329
    void zoomLastStatusChanged( bool );
 
330
 
 
331
    //! Emitted when zoom next status changed
 
332
    //! @note: this signal was added in version 1.4
 
333
    void zoomNextStatusChanged( bool );
 
334
 
 
335
  protected:
 
336
    //! Overridden key press event
 
337
    void keyPressEvent( QKeyEvent * e );
 
338
 
 
339
    //! Overridden key release event
 
340
    void keyReleaseEvent( QKeyEvent * e );
 
341
 
 
342
    //! Overridden mouse double click event
 
343
    void mouseDoubleClickEvent( QMouseEvent * e );
 
344
 
 
345
    //! Overridden mouse move event
 
346
    void mouseMoveEvent( QMouseEvent * e );
 
347
 
 
348
    //! Overridden mouse press event
 
349
    void mousePressEvent( QMouseEvent * e );
 
350
 
 
351
    //! Overridden mouse release event
 
352
    void mouseReleaseEvent( QMouseEvent * e );
 
353
 
 
354
    //! Overridden mouse wheel event
 
355
    void wheelEvent( QWheelEvent * e );
 
356
 
 
357
    //! Overridden resize event
 
358
    void resizeEvent( QResizeEvent * e );
 
359
 
 
360
    //! called when panning is in action, reset indicates end of panning
 
361
    void moveCanvasContents( bool reset = FALSE );
 
362
 
 
363
    //! called on resize or changed extent to notify canvas items to change their rectangle
 
364
    void updateCanvasItemPositions();
 
365
 
281
366
    /// implementation struct
282
367
    class CanvasProperties;
283
368
 
284
369
    /// Handle pattern for implementation object
285
370
    std::auto_ptr<CanvasProperties> mCanvasProperties;
286
371
 
287
 
private:
 
372
  private:
288
373
    /// this class is non-copyable
289
374
    /**
290
375
       @note
294
379
     */
295
380
    QgsMapCanvas( QgsMapCanvas const & );
296
381
 
297
 
    /**
298
 
       private to force use of ctor with arguments
299
 
     */
300
 
    QgsMapCanvas();
301
 
 
302
382
    //! all map rendering is done in this class
303
 
    QgsMapRender* mMapRender;
304
 
    
 
383
    QgsMapRenderer* mMapRenderer;
 
384
 
305
385
    //! owns pixmap with rendered map and controls rendering
306
386
    QgsMapCanvasMap* mMap;
307
 
    
 
387
 
308
388
    //! map overview widget - it's controlled by QgsMapCanvas
309
389
    QgsMapOverviewCanvas* mMapOverview;
310
 
    
 
390
 
311
391
    //! Flag indicating a map refresh is in progress
312
392
    bool mDrawing;
313
393
 
324
404
     * when no real change has occurred
325
405
     */
326
406
    bool mDirty;
327
 
    
328
 
    //! Overridden key press event
329
 
    void keyPressEvent(QKeyEvent * e);
330
 
 
331
 
    //! Overridden key release event
332
 
    void keyReleaseEvent(QKeyEvent * e);
333
 
 
334
 
    //! Overridden mouse move event
335
 
    void contentsMouseMoveEvent(QMouseEvent * e);
336
 
 
337
 
    //! Overridden mouse press event
338
 
    void contentsMousePressEvent(QMouseEvent * e);
339
 
 
340
 
    //! Overridden mouse release event
341
 
    void contentsMouseReleaseEvent(QMouseEvent * e);
342
 
 
343
 
    //! Overridden mouse wheel event
344
 
    void wheelEvent(QWheelEvent * e);
345
 
 
346
 
    //! Overridden resize event
347
 
    void resizeEvent(QResizeEvent * e);
348
 
 
349
 
    //! Overridden draw contents from canvas view
350
 
    void drawContents(QPainter * p, int cx, int cy, int cw, int ch);
351
 
        
352
 
    //! called when panning is in action, reset indicates end of panning
353
 
    void moveCanvasContents(bool reset = FALSE);
354
 
    
355
 
    //! called on resize or changed extent to notify canvas items to change their rectangle
356
 
    void updateCanvasItemsPositions();
357
407
 
358
408
    //! determines whether user has requested to suppress rendering
359
409
    bool mRenderFlag;
360
 
    
361
 
  /** debugging member
362
 
      invoked when a connect() is made to this object
363
 
  */
364
 
  void connectNotify( const char * signal );
 
410
 
 
411
    /**Resize events that have been ignored because the canvas is busy with
 
412
       rendering may put their sizes into this list. The canvas then picks up
 
413
       the last entry in case a lot of resize events arrive in short time*/
 
414
    QList< QPair<int, int> > mResizeQueue;
 
415
 
 
416
    /**debugging member
 
417
       invoked when a connect() is made to this object
 
418
    */
 
419
    void connectNotify( const char * signal );
365
420
 
366
421
    //! current layer in legend
367
422
    QgsMapLayer* mCurrentLayer;
368
423
 
369
 
    Q3Canvas* mCanvas;
370
 
    
 
424
    //! graphics scene manages canvas items
 
425
    QGraphicsScene* mScene;
 
426
 
371
427
    //! pointer to current map tool
372
428
    QgsMapTool* mMapTool;
373
 
    
 
429
 
374
430
    //! previous tool if current is for zooming/panning
375
431
    QgsMapTool* mLastNonZoomMapTool;
376
432
 
377
433
    //! recently used extent
378
 
    QgsRect mLastExtent;
379
 
    
 
434
    QList <QgsRectangle> mLastExtent;
 
435
    int mLastExtentIndex;
 
436
 
380
437
    //! Scale factor multiple for default zoom in/out
381
438
    double mWheelZoomFactor;
382
 
    
 
439
 
383
440
    //! Mouse wheel action
384
441
    WheelAction mWheelAction;
385
442