1
/***************************************************************************
2
qgsmaplayer.h - description
4
begin : Fri Jun 28 2002
5
copyright : (C) 2002 by Gary E.Sherman
6
email : sherman at mrcc.com
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
***************************************************************************/
17
/* $Id: qgsmaplayer.h 6265 2006-12-15 23:22:01Z g_j_m $ */
27
#include <QMenu> // not forward declared because other .h files
28
// inherit from us and we're being nice to them.
33
#include "qgscoordinatetransform.h"
40
class QgsLegendLayerFile;
46
/** \class QgsMapLayer
47
* \brief Base class for all map layer types.
48
* This class is the base class for all map layer types (shapefile,
51
class QgsMapLayer : public QObject
58
* @param type Type of layer as defined in LAYERS enum
59
* @param lyrname Display Name of the layer
61
QgsMapLayer(int type = 0, QString lyrname = QString::null, QString source = QString::null);
64
virtual ~ QgsMapLayer();
66
/*! Get the type of the layer
67
* @return Integer matching a value in the LAYERS enum
71
/*! Get this layer's unique ID */
72
QString const & getLayerID() const;
74
/*! Set the display name of the layer
75
# @param name New name for the layer
76
# @param updateLegend false if legend should not be updated
77
(to avoid infinite recursion when this function is called from the legend itself)
79
void setLayerName(const QString & name, bool updateLegend=true);
81
/*! Get the display name of the layer
82
* @return the layer name
84
QString const & name() const;
86
/*! Get the internal name of the layer. This is the name used to created the
87
* layer from the data source
88
* @return internal datasource name of the layer
90
QString const & sourceName() const;
92
/*! Virtual function to calculate the extent of the current layer.
93
* This function must be overridden in all child classes and implemented
94
* based on the layer type
96
virtual QgsRect calculateExtent();
98
/*! Accesor for mShowInOverviewFlag */
99
bool showInOverviewStatus()
101
return mShowInOverview;
105
virtual void draw(QPainter *, QgsRect *, int);
107
//! Returns FALSE if an error occurred during drawing
108
virtual bool draw(QPainter *, QgsRect *, QgsMapToPixel *, bool);
109
virtual void drawLabels(QPainter *, QgsRect *, QgsMapToPixel *);
111
/*!Select features on the map canvas by dragging a rectangle */
112
virtual void select(QgsRect *, bool )
116
//! Display the attribute table for the layer
118
\param qgisApp This should be the QgisApp that spawned this table.
120
virtual void table(QgisApp * qgisApp)
123
/*! Return the extent of the layer as a QRect
125
const QgsRect extent();
127
/*! Returns the status of the layer. An invalid layer is one which has a bad datasource
128
* or other problem. Child classes set this flag when intialized
129
*@return True if the layer is valid and can be accessed
133
/** Write property of QString labelField. */
134
virtual void setLabelField(const QString & _newVal);
136
/** Read property of QString labelField. */
137
virtual const QString & labelField();
139
//! Visibility of the layer
142
/*! Gets a version of the internal layer definition that has sensitive
143
* bits removed (for example, the password). This function should
144
* be used when displaying the source name for general viewing.
146
QString publicSource() const;
148
//! Returns the source for the layer
149
QString const & source() const;
151
/** Write property of int featureType. */
152
virtual void setFeatureType(const int &_newVal);
154
/** Read property of int featureType. */
155
virtual const int &featureType();
157
/** Return the context menu for the layer */
158
virtual QMenu* contextMenu();
161
* Returns the sublayers of this layer
163
* (Useful for providers that manage their own layers, such as WMS)
166
virtual QStringList subLayers()
168
return QStringList(); // Empty
172
* Reorders the *previously selected* sublayers of this layer from bottom to top
174
* (Useful for providers that manage their own layers, such as WMS)
177
virtual void setLayerOrder(QStringList layers)
183
* Set the visibility of the given sublayer name
185
virtual void setSubLayerVisibility(QString name, bool vis)
190
//! Layers enum defining the types of layers that can be added to a map
198
/**Shows the properties dialog for the map layer*/
199
virtual void showLayerProperties() = 0;
202
All inherited layers must be able to display a conext menu if requested
204
@note Calls initContextMenu_()
206
void initContextMenu(QgisApp * app);
209
Allows children to tailor context menu
211
@note Calls initContextMenu_()
213
virtual void initContextMenu_(QgisApp * app)
215
// NOP; children can optionally over-ride
218
void setLegendLayerFile(QgsLegendLayerFile* llf) {mLegendLayerFile = llf;}
220
/**True if the layer can be edited*/
221
virtual bool isEditable() const =0;
223
/** sets state from DOM document
225
@param layer_node is DOM node corresponding to ``maplayer'' tag
229
The DOM node corresponds to a DOM document project file XML element read
232
This, in turn, calls readXML_(), which is over-rideable by sub-classes so
233
that they can read their own specific state from the given DOM node.
235
Invoked by QgsProject::read().
237
@returns true if successful
240
bool readXML( QDomNode & layer_node );
243
/** stores state in DOM node
245
@param layer_node is DOM node corresponding to ``projectlayers'' tag
249
The DOM node corresponds to a DOM document project file XML element to be
250
written by QgsProject.
252
This, in turn, calls writeXML_(), which is over-rideable by sub-classes so
253
that they can write their own specific state to the given DOM node.
255
Invoked by QgsProject::write().
257
@returns true if successful
260
bool writeXML( QDomNode & layer_node, QDomDocument & document );
262
/** Accessor for the coordinate transformation object */
263
QgsCoordinateTransform * coordinateTransform();
265
/** A simple helper method to find out if on the fly projections
266
are enabled or not */
267
bool projectionsEnabled() const;
269
// Convenience function to project an extent into the layer source
270
// SRS, but also split it into two extents if it crosses
271
// the +/- 180 degree line. Modifies the given extent to be in the
272
// source SRS coordinates, and if it was split, returns true, and
273
// also sets the contents of the r2 parameter
274
bool projectExtent(QgsRect& extent, QgsRect& r2);
276
/**Returns the path to an icon which characterises the type of layer*/
277
virtual QString layerTypeIconPath() = 0;
279
void setLegend(QgsLegend* legend) {mLegend = legend;}
280
const QgsLegend* legend() {return mLegend;}
282
/**Refresh the symbology part of the legend. Specific implementations have to be provided by subclasses*/
283
virtual void refreshLegend() = 0;
285
/**Copies the symbology settings from another layer. Returns true in case of success*/
286
virtual bool copySymbologySettings(const QgsMapLayer& other) = 0;
288
/**Returns true if this layer can be in the same symbology group with another layer*/
289
virtual bool isSymbologyCompatible(const QgsMapLayer& other) const = 0;
291
virtual std::vector < QgsField > const &fields() const;
293
/** \brief accessor for transparency level. */
294
virtual unsigned int getTransparency()=0;
298
* If an operation returns 0 (e.g. draw()), this function
299
* returns the text of the error associated with the failure.
300
* Interactive users of this provider can then, for example,
301
* call a QMessageBox to display the contents.
303
virtual QString errorCaptionString();
306
* If an operation returns 0 (e.g. draw()), this function
307
* returns the text of the error associated with the failure.
308
* Interactive users of this provider can then, for example,
309
* call a QMessageBox to display the contents.
311
virtual QString errorString();
314
/** \brief Mutator for transparency level. Should be between 0 and 255 */
315
virtual void setTransparency(unsigned int)=0;
316
//! event handler for when a coordinate transofrm fails due to bad vertex error
317
virtual void invalidTransformInput();
320
//! keyPress event so we can check if cancel was pressed
321
void keyPressed ( QKeyEvent * e );
324
void setVisible(bool vis);
326
/*! Slot connected to popup menus of derived classes. Used to indicate whether this layer
327
* should be shown or hidden in the map overview. */
328
//virtual void toggleShowInOverview();
330
/**Copies the legend pixmap of this layer to the legenditem and adds an overview glasses if necessary*/
331
void updateItemPixmap();
333
/**Ensures that the overview item in the popup menu is checked/ unchecked correctly*/
334
void updateOverviewPopupItem();
336
/** set whether this layer is in the overview or not
338
@note this will hopefully eventually supercede toggleOverviewStatus() since
339
this makes explicit the state change
342
virtual void inOverview( bool );
344
/** Accessor and mutator for the minimum scale member */
345
void setMinScale(float theMinScale)
347
mMinScale=theMinScale;
354
/** Accessor and mutator for the maximum scale member */
355
void setMaxScale(float theMaxScale)
357
mMaxScale=theMaxScale;
364
/** Accessor and mutator for the scale based visilibility flag */
365
void setScaleBasedVisibility( bool theVisibilityFlag)
367
mScaleBasedVisibility=theVisibilityFlag;
369
bool scaleBasedVisibility()
371
return mScaleBasedVisibility;
374
/** Used to ask the layer for its projection as a WKT string. Must be reimplemented by each provider. */
375
virtual QString getProjectionWKT() = 0 ;
378
void visibilityChanged(void);
380
/** \brief emit a signal to notify of a progress event */
381
void drawingProgress(int theProgress, int theTotalSteps);
383
/** \brief emit a signal to be caught by gisapp and display a msg on status bar */
384
void setStatus(QString theStatusQString);
386
/** This signal should be connected with the slot QgsMapCanvas::refresh() */
387
void repaintRequested();
389
/** This is used to notify the application whether this layer should be shown in overview or not. */
391
//void showInOverview(QString theLayerId, bool);
392
void showInOverview(QgsMapLayer * maplayer, bool);
395
/** This is used to send a request that any mapcanvas using this layer update its extents */
396
void recalculateExtents();
400
/** \brief Transparency level for this layer should be 0-255 (255 being opaque) */
401
unsigned int transparencyLevelInt;
403
/** called by readXML(), used by children to read state specific to them from
406
virtual bool readXML_( QDomNode & layer_node );
408
/** called by writeXML(), used by children to write state specific to them to
411
virtual bool writeXML_( QDomNode & layer_node, QDomDocument & document );
414
//! Extent of the layer
417
//! Indicates if the layer is valid and can be drawn
420
//! data source description string, varies by layer type
423
//! Geometry type as defined in enum WKBTYPE (qgis.h)
426
/** Pixmap to show a bogus vertex was encoutnered in this layer (applies to vector layers only) */
427
QPixmap mProjectionErrorPixmap;
429
//! A little pixmap to show if this layer is represented in overview or now
430
QPixmap mInOverviewPixmap;
432
QPixmap mEditablePixmap;
434
/** Internal name of the layer. Derived from the datasource */
435
QString internalName;
440
//! the action in popmenu that sets overview status
441
QAction* mShowInOverviewAction;
443
/** Whether this layer is to be shown in the overview map or not */
444
bool mShowInOverview;
446
// /** action item for pop-up menu
448
// @note obviously should be in synch with mShowInOverview
450
// Is set in context menu.
452
// @todo this is a GUI element and should not be here
454
// QAction* mActionInOverview;
455
/** A flag to let the draw() render loop know if the user has requested drawing be cancelled */
456
bool mDrawingCancelled;
458
//! A QgsCoordinateTransform is used for on the fly reprojection of map layers
459
QgsCoordinateTransform * mCoordinateTransform;
461
/**Pointer to the legend layer item of the legend*/
464
/**Pointer to the legend layer file of the legend. It is used to modify the pixmap with overview
465
glasses, editing or pyramid symbols*/
466
QgsLegendLayerFile* mLegendLayerFile;
468
private: // Private attributes
470
/// QgsMapLayer not copyable
471
QgsMapLayer( QgsMapLayer const & );
473
/// QgsMapLayer not copyable
474
QgsMapLayer & operator=( QgsMapLayer const & );
476
/// A convenience function to capitalise the layer name
477
static QString capitaliseLayerName(const QString name);
479
/** Unique ID of this layer - used to refer to this layer in QGIS code */
482
/** Type of the layer (eg. vector, raster, database */
485
//! Tag for embedding additional information
488
/** Name of the layer - used for display */
491
/** true if visible ? */
495
invoked when a connect() is made to this object
497
void connectNotify( const char * signal );
499
// Calculates the bounding box of the given extent in the inverse
500
// projected spatial reference system.
501
QgsRect calcProjectedBoundingBox(QgsRect& extent);
503
/** Minimum scale at which this layer should be displayed */
505
/** Maximum scale at which this layer should be displayed */
507
/** A flag that tells us whether to use the above vars to restrict layer visibility */
508
bool mScaleBasedVisibility;
510
public: // Public attributes
513
QString m_labelField;