26
#include "qgsrectangle.h"
27
27
#include "qgspoint.h"
30
30
#include <QDomDocument>
31
#include <Q3CanvasView>
31
#include <QGraphicsView>
40
42
class QPaintDevice;
45
47
class QgsMapToPixel;
47
class QgsMapLayerInterface;
49
50
class QgsLegendView;
51
51
class QgsRubberBand;
54
55
class QgsMapCanvasMap;
55
56
class QgsMapOverviewCanvas;
56
class QgsMapCanvasMapImage;
59
/*! \class QgsMapCanvas
60
* \brief Map canvas class for displaying all GIS data types.
60
* A class that stores visibility and presence in overview flags together
61
* with pointer to the layer.
64
class GUI_EXPORT QgsMapCanvasLayer
67
QgsMapCanvasLayer( QgsMapLayer* layer, bool visible = TRUE, bool isInOverview = FALSE )
68
: mLayer( layer ), mVisible( visible ), mInOverview( isInOverview ) {}
70
void setVisible( bool visible ) { mVisible = visible; }
71
void setInOverview( bool isInOverview ) { mInOverview = isInOverview; }
73
bool isVisible() const { return mVisible; }
74
bool isInOverview() const { return mInOverview; }
76
QgsMapLayer* layer() { return mLayer; }
77
const QgsMapLayer* layer() const { return mLayer; }
83
/** Flag whether layer is visible */
86
/** Flag whether layer is shown in overview */
92
* Map canvas is a class for displaying all GIS data types on a canvas.
63
class QgsMapCanvas : public Q3CanvasView
95
class GUI_EXPORT QgsMapCanvas : public QGraphicsView
69
enum WheelAction { WheelZoom, WheelZoomAndRecenter, WheelNothing };
101
enum WheelAction { WheelZoom, WheelZoomAndRecenter, WheelZoomToMouseCursor, WheelNothing };
72
QgsMapCanvas(QWidget * parent = 0, const char *name = 0);
104
QgsMapCanvas( QWidget * parent = 0, const char *name = 0 );
77
void setLayerSet(std::deque<QString>& layerSet);
79
void setCurrentLayer(QgsMapLayer* layer);
109
void setLayerSet( QList<QgsMapCanvasLayer>& layers );
111
void setCurrentLayer( QgsMapLayer* layer );
81
113
void updateOverview();
83
void setOverview(QgsMapOverviewCanvas* overview);
115
void enableOverviewMode( QgsMapOverviewCanvas* overview );
85
117
QgsMapCanvasMap* map();
87
QgsMapRender* mapRender();
119
QgsMapRenderer* mapRenderer();
89
121
//! Accessor for the canvas pixmap
90
QPixmap * canvasPixmap();
122
QPixmap& canvasPixmap();
92
124
//! Get the last reported scale of the canvas
95
127
//! Clear the map canvas
98
//! Returns the mupp (map units per pixel) for the canvas
130
//! Returns the mapUnitsPerPixel (map units per pixel) for the canvas
131
double mapUnitsPerPixel() const;
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;
106
138
//! Set the extent of the map canvas
107
void setExtent(QgsRect const & r);
139
void setExtent( QgsRectangle const & r );
109
141
//! Zoom to the full extent of all layers
110
void zoomFullExtent();
142
void zoomToFullExtent();
112
144
//! Zoom to the previous extent (view)
113
void zoomPreviousExtent();
115
/**Zooms to the extend of the selected features*/
116
void zoomToSelected();
145
void zoomToPreviousExtent();
147
//! Zoom to the Next extent (view)
148
void zoomToNextExtent();
150
// ! Clears the list of extents and sets current extent as first item
151
void clearExtentHistory();
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 );
118
157
/** \brief Sets the map tool currently being used on the canvas */
119
void setMapTool(QgsMapTool* mapTool);
158
void setMapTool( QgsMapTool* mapTool );
121
160
/** \brief Unset the current map tool or last non zoom tool
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.
127
void unsetMapTool(QgsMapTool* mapTool);
166
void unsetMapTool( QgsMapTool* mapTool );
129
168
/**Returns the currently active tool*/
130
169
QgsMapTool* mapTool();
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;
135
176
/** Emits signal scalChanged to update scale in main window */
136
177
void updateScale();
152
190
* @param frz Boolean specifying if the canvas should be frozen (true) or
153
191
* thawed (false). Default is true.
155
void freeze(bool frz = true);
193
void freeze( bool frz = true );
157
195
/*! Accessor for frozen status of canvas */
160
198
//! Flag the canvas as dirty and needed a refresh
161
void setDirty(bool _dirty);
199
void setDirty( bool _dirty );
163
201
//! Return the state of the canvas (dirty or not)
164
202
bool isDirty() const;
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
170
QGis::units mapUnits() const;
208
QGis::UnitType mapUnits() const;
172
210
//! Get the current coordinate transform
173
QgsMapToPixel * getCoordinateTransform();
175
/** stores state in DOM node
176
layerNode is DOM node corresponding to ``qgis'' tag
178
The DOM node corresponds to a DOM document project file XML element to be
179
written by QgsProject.
181
Invoked by QgsProject::write().
183
returns true if successful
185
bool writeXML( QDomNode & layerNode, QDomDocument & doc );
211
const QgsMapToPixel* getCoordinateTransform();
187
213
//! true if canvas currently drawing
188
214
bool isDrawing();
190
216
//! returns current layer (set by legend widget)
191
217
QgsMapLayer* currentLayer();
193
219
//! set wheel action and zoom factor (should be greater than 1)
194
void setWheelAction(WheelAction action, double factor = 2);
196
//! Zooms in/out preserving
197
void zoom(bool zoomIn);
220
void setWheelAction( WheelAction action, double factor = 2 );
222
//! Zoom in with fixed factor
225
//! Zoom out with fixed factor
228
//! Zoom with the factor supplied. Factor > 1 zooms out, interval (0,1) zooms in
229
void zoomByFactor( double scaleFactor );
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 );
202
234
//! used to determine if anti-aliasing is enabled or not
203
void enableAntiAliasing(bool theFlag);
235
void enableAntiAliasing( bool theFlag );
205
237
//! Select which Qt class to render with
206
void useQImageToRender(bool theFlag);
238
void useImageToRender( bool theFlag );
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 );
212
245
//! Called when mouse is moving and pan is activated
213
void panAction(QMouseEvent * event);
246
void panAction( QMouseEvent * event );
215
248
//! returns last position of mouse cursor
216
249
QPoint mouseLastXY();
220
/**Sets dirty=true and calls render()*/
253
/**Repaints the canvas map*/
223
virtual void render();
256
//! Receives signal about selection change, and pass it on with layer info
257
void selectionChangedSlot();
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" );
228
262
//! This slot is connected to the visibility change of one or more layers
229
263
void layerStateChange();
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;};
236
270
/** A simple helper method to find out if on the fly projections are enabled or not */
237
bool projectionsEnabled();
271
bool hasCrsTransformEnabled();
239
273
/** The map units may have changed, so cope with that */
240
274
void mapUnitsChanged();
242
276
/** updates pixmap on render progress */
243
277
void updateMap();
245
279
//! show whatever error is exposed by the QgsMapLayer.
246
void showError(QgsMapLayer * mapLayer);
280
void showError( QgsMapLayer * mapLayer );
282
//! called to read map canvas settings from project
283
void readProject( const QDomDocument & );
285
//! called to write map canvas settings to project
286
void writeProject( QDomDocument & );
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 );
292
/** emits current mouse position
293
\note changed in 1.3 */
294
void xyCoordinates( const QgsPoint & p );
255
296
//! Emitted when the scale of the map changes
256
void scaleChanged(QString);
297
void scaleChanged( double );
258
299
//! Emitted when the extents of the map change
259
void extentsChanged(QgsRect);
300
void extentsChanged();
261
302
/** Emitted when the canvas has rendered.
266
307
being rendered onto a pixmap other than the mapCanvas own pixmap member.
269
void renderComplete(QPainter *);
310
void renderComplete( QPainter * );
271
312
//! Emitted when a new set of layers has been received
272
313
void layersChanged();
274
315
//! Emit key press event
275
void keyPressed(QKeyEvent * e);
316
void keyPressed( QKeyEvent * e );
277
318
//! Emit key release event
278
void keyReleased(QKeyEvent * e);
319
void keyReleased( QKeyEvent * e );
321
//! Emit map tool changed event
322
void mapToolSet( QgsMapTool * tool );
324
//! Emitted when selection in any layer gets changed
325
void selectionChanged( QgsMapLayer * layer );
327
//! Emitted when zoom last status changed
328
//! @note: this signal was added in version 1.4
329
void zoomLastStatusChanged( bool );
331
//! Emitted when zoom next status changed
332
//! @note: this signal was added in version 1.4
333
void zoomNextStatusChanged( bool );
336
//! Overridden key press event
337
void keyPressEvent( QKeyEvent * e );
339
//! Overridden key release event
340
void keyReleaseEvent( QKeyEvent * e );
342
//! Overridden mouse double click event
343
void mouseDoubleClickEvent( QMouseEvent * e );
345
//! Overridden mouse move event
346
void mouseMoveEvent( QMouseEvent * e );
348
//! Overridden mouse press event
349
void mousePressEvent( QMouseEvent * e );
351
//! Overridden mouse release event
352
void mouseReleaseEvent( QMouseEvent * e );
354
//! Overridden mouse wheel event
355
void wheelEvent( QWheelEvent * e );
357
//! Overridden resize event
358
void resizeEvent( QResizeEvent * e );
360
//! called when panning is in action, reset indicates end of panning
361
void moveCanvasContents( bool reset = FALSE );
363
//! called on resize or changed extent to notify canvas items to change their rectangle
364
void updateCanvasItemPositions();
281
366
/// implementation struct
282
367
class CanvasProperties;
284
369
/// Handle pattern for implementation object
285
370
std::auto_ptr<CanvasProperties> mCanvasProperties;
288
373
/// this class is non-copyable
324
404
* when no real change has occurred
328
//! Overridden key press event
329
void keyPressEvent(QKeyEvent * e);
331
//! Overridden key release event
332
void keyReleaseEvent(QKeyEvent * e);
334
//! Overridden mouse move event
335
void contentsMouseMoveEvent(QMouseEvent * e);
337
//! Overridden mouse press event
338
void contentsMousePressEvent(QMouseEvent * e);
340
//! Overridden mouse release event
341
void contentsMouseReleaseEvent(QMouseEvent * e);
343
//! Overridden mouse wheel event
344
void wheelEvent(QWheelEvent * e);
346
//! Overridden resize event
347
void resizeEvent(QResizeEvent * e);
349
//! Overridden draw contents from canvas view
350
void drawContents(QPainter * p, int cx, int cy, int cw, int ch);
352
//! called when panning is in action, reset indicates end of panning
353
void moveCanvasContents(bool reset = FALSE);
355
//! called on resize or changed extent to notify canvas items to change their rectangle
356
void updateCanvasItemsPositions();
358
408
//! determines whether user has requested to suppress rendering
359
409
bool mRenderFlag;
362
invoked when a connect() is made to this object
364
void connectNotify( const char * signal );
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;
417
invoked when a connect() is made to this object
419
void connectNotify( const char * signal );
366
421
//! current layer in legend
367
422
QgsMapLayer* mCurrentLayer;
424
//! graphics scene manages canvas items
425
QGraphicsScene* mScene;
371
427
//! pointer to current map tool
372
428
QgsMapTool* mMapTool;
374
430
//! previous tool if current is for zooming/panning
375
431
QgsMapTool* mLastNonZoomMapTool;
377
433
//! recently used extent
434
QList <QgsRectangle> mLastExtent;
435
int mLastExtentIndex;
380
437
//! Scale factor multiple for default zoom in/out
381
438
double mWheelZoomFactor;
383
440
//! Mouse wheel action
384
441
WheelAction mWheelAction;