4
/** \class QgsMapCanvasLayer
5
\brief class that stores additional layer's flags together with pointer to the layer
7
class QgsMapCanvasLayer
10
#include <qgsmapcanvas.h>
14
QgsMapCanvasLayer(QgsMapLayer* layer, bool visible = TRUE, bool isInOverview = FALSE);
16
void setVisible(bool visible);
17
void setInOverview(bool isInOverview);
19
bool isVisible() const;
20
bool isInOverview() const;
23
//const QgsMapLayer* layer() const;
28
/*! \class QgsMapCanvas
29
* \brief Map canvas class for displaying all GIS data types.
32
class QgsMapCanvas : QGraphicsView
35
#include <qgsmapcanvas.h>
38
%ConvertToSubClassCode
39
if (dynamic_cast<QgsMapCanvas*>(sipCpp) != NULL)
40
sipClass = sipClass_QgsMapCanvas;
47
enum WheelAction { WheelZoom, WheelZoomAndRecenter, WheelZoomToMouseCursor, WheelNothing };
50
QgsMapCanvas(QWidget * parent /TransferThis/ = 0, const char *name = 0);
55
void setLayerSet(QList<QgsMapCanvasLayer>& layers);
57
void setCurrentLayer(QgsMapLayer* layer);
59
void updateOverview();
61
void enableOverviewMode(QgsMapOverviewCanvas* overview);
63
QgsMapCanvasMap* map();
65
QgsMapRenderer* mapRenderer();
67
//! Accessor for the canvas pixmap
68
QPixmap& canvasPixmap();
70
//! Get the last reported scale of the canvas
73
//! Clear the map canvas
76
//! Returns the mapUnitsPerPixel (map units per pixel) for the canvas
77
double mapUnitsPerPixel() const;
79
//! Returns the current zoom exent of the map canvas
80
QgsRectangle extent() const;
81
//! Returns the combined exent for all layers on the map canvas
82
QgsRectangle fullExtent() const;
84
//! Set the extent of the map canvas
85
void setExtent(const QgsRectangle & r);
87
//! Zoom to the full extent of all layers
88
void zoomToFullExtent();
90
//! Zoom to the previous extent (view)
91
void zoomToPreviousExtent();
93
//! Zoom to the next extent (view)
94
void zoomToNextExtent();
96
// ! Clears the list of extents and sets current extent as first item
97
void clearExtentHistory();
99
/** Zoom to the extent of the selected features of current (vector) layer.
100
Added in version 1.2: optionally specify different than current layer */
101
void zoomToSelected(QgsVectorLayer* layer = NULL);
103
/** \brief Sets the map tool currently being used on the canvas */
104
void setMapTool(QgsMapTool* mapTool);
106
/** \brief Unset the current mapset tool or last non zoom tool if
107
* it the same as passed map tool pointer. The tool is not
108
* referenced/used any more, but the instance is not deleted
111
void unsetMapTool(QgsMapTool* mapTool);
113
/**Returns the currently active tool*/
114
QgsMapTool* mapTool();
116
/** Write property of QColor bgColor. */
117
virtual void setCanvasColor(const QColor & _newVal);
119
/** Emits signal scalChanged to update scale in main window */
122
/** Updates the full extent */
123
void updateFullExtent();
125
//! return the map layer at position index in the layer stack
126
QgsMapLayer *layer(int index);
128
//! return number of layers on the map
129
int layerCount() const;
131
/*! Freeze/thaw the map canvas. This is used to prevent the canvas from
132
* responding to events while layers are being added/removed etc.
133
* @param frz Boolean specifying if the canvas should be frozen (true) or
134
* thawed (false). Default is true.
136
void freeze(bool frz = true);
138
/*! Accessor for frozen status of canvas */
141
//! Flag the canvas as dirty and needed a refresh
142
void setDirty(bool _dirty);
144
//! Return the state of the canvas (dirty or not)
145
bool isDirty() const;
147
//! Set map units (needed by project properties dialog)
148
void setMapUnits(QGis::UnitType mapUnits);
149
//! Get the current canvas map units
151
QGis::UnitType mapUnits() const;
153
//! Get the current coordinate transform
154
const QgsMapToPixel * getCoordinateTransform();
156
//! true if canvas currently drawing
159
//! returns current layer (set by legend widget)
160
QgsMapLayer* currentLayer();
162
//! set wheel action and zoom factor (should be greater than 1)
163
void setWheelAction(WheelAction action, double factor = 2);
165
//! Zoom in with fixed factor
168
//! Zoom out with fixed factor
171
//! Zoom with the factor supplied. Factor > 1 zooms in
172
void zoomByFactor( double scaleFactor );
174
//! Zooms in/out with a given center
175
void zoomWithCenter(int x, int y, bool zoomIn);
177
//! used to determine if anti-aliasing is enabled or not
178
void enableAntiAliasing(bool theFlag);
180
//! Select which Qt class to render with
181
void useImageToRender(bool theFlag);
183
// following 2 methods should be moved elsewhere or changed to private
184
// currently used by pan map tool
185
//! Ends pan action and redraws the canvas.
186
void panActionEnd(QPoint releasePoint);
187
//! Called when mouse is moving and pan is activated
188
void panAction(QMouseEvent * event);
190
//! returns last position of mouse cursor
191
QPoint mouseLastXY();
195
/**Sets dirty=true and calls render()*/
198
//! Save the convtents of the map canvas to disk as an image
199
void saveAsImage(QString theFileName,QPixmap * QPixmap=0, QString="PNG" );
201
//! This slot is connected to the visibility change of one or more layers
202
void layerStateChange();
204
//! Whether to suppress rendering or not
205
void setRenderFlag(bool theFlag);
206
//! State of render suppression flag
209
/** A simple helper method to find out if on the fly projections are enabled or not */
210
bool hasCrsTransformEnabled();
212
/** The map units may have changed, so cope with that */
213
void mapUnitsChanged();
215
/** updates pixmap on render progress */
218
//! show whatever error is exposed by the QgsMapLayer.
219
void showError(QgsMapLayer * mapLayer);
221
//! called to read map canvas settings from project
222
void readProject(const QDomDocument &);
224
//! called to write map canvas settings to project
225
void writeProject(QDomDocument &);
228
/** Let the owner know how far we are with render operations */
229
void setProgress(int,int);
231
/** emits current mouse position
232
\note changed in 1.3 */
233
void xyCoordinates(const QgsPoint &p);
235
//! Emitted when the scale of the map changes
236
void scaleChanged(QString);
238
//! Emitted when the extents of the map change
239
void extentsChanged();
241
/** Emitted when the canvas has rendered.
243
Passes a pointer to the painter on which the map was drawn. This is
244
useful for plugins that wish to draw on the map after it has been
245
rendered. Passing the painter allows plugins to work when the map is
246
being rendered onto a pixmap other than the mapCanvas own pixmap member.
249
void renderComplete(QPainter *);
251
//! Emitted when a new set of layers has been received
252
void layersChanged();
254
//! Emit key press event
255
void keyPressed(QKeyEvent * e);
257
//! Emit key release event
258
void keyReleased(QKeyEvent * e);
260
//! Emit map tool changed event
261
void mapToolSet(QgsMapTool *tool);
263
//! Emitted when zoom last status changed
264
//! @note: this signal was added in version 1.4
265
void zoomLastStatusChanged( bool );
267
//! Emitted when zoom next status changed
268
//! @note: this signal was added in version 1.4
269
void zoomNextStatusChanged( bool );
273
//! Overridden key press event
274
void keyPressEvent(QKeyEvent * e);
276
//! Overridden key release event
277
void keyReleaseEvent(QKeyEvent * e);
279
//! Overridden mouse move event
280
void mouseMoveEvent(QMouseEvent * e);
282
//! Overridden mouse press event
283
void mousePressEvent(QMouseEvent * e);
285
//! Overridden mouse release event
286
void mouseReleaseEvent(QMouseEvent * e);
288
//! Overridden mouse wheel event
289
void wheelEvent(QWheelEvent * e);
291
//! Overridden resize event
292
void resizeEvent(QResizeEvent * e);
294
//! called when panning is in action, reset indicates end of panning
295
void moveCanvasContents(bool reset = FALSE);
297
//! called on resize or changed extent to notify canvas items to change their rectangle
298
void updateCanvasItemPositions();
301
}; // class QgsMapCanvas