3
* \brief Base class for all map layer types.
4
* This class is the base class for all map layer types (vector, raster).
6
class QgsMapLayer : QObject
9
#include <qgsmaplayer.h>
12
%ConvertToSubClassCode
13
if (sipCpp->inherits("QgsMapLayer"))
15
sipClass = sipClass_QgsMapLayer;
16
QgsMapLayer* layer = qobject_cast<QgsMapLayer*>(sipCpp);
17
if (layer->type() == QgsMapLayer::VectorLayer)
19
sipClass = sipClass_QgsVectorLayer;
21
else if (layer->type() == QgsMapLayer::RasterLayer)
23
sipClass = sipClass_QgsRasterLayer;
34
/** Layers enum defining the types of layers that can be added to a map */
42
* @param type Type of layer as defined in QgsMapLayer::LayerType enum
43
* @param lyrname Display Name of the layer
45
QgsMapLayer(QgsMapLayer::LayerType type = QgsMapLayer::VectorLayer, QString lyrname = QString::null, QString source = QString::null);
48
virtual ~QgsMapLayer();
50
/** Get the type of the layer
51
* @return Integer matching a value in the QgsMapLayer::LayerType enum
53
QgsMapLayer::LayerType type() const;
55
/** Get this layer's unique ID, this ID is used to access this layer from map layer registry */
56
QString getLayerID() const;
58
/** Set the display name of the layer
59
* @param name New name for the layer
61
void setLayerName(const QString & name);
63
/** Get the display name of the layer
64
* @return the layer name
66
const QString & name() const;
68
/** Render the layer, to be overridden in child classes
70
virtual bool draw(QgsRenderContext& rendererContext);
73
* @TODO to be removed: used only in vector layers
75
virtual void drawLabels(QgsRenderContext& rendererContext);
77
/** Return the extent of the layer as a QRect */
78
const QgsRectangle extent();
80
/*! Return the status of the layer. An invalid layer is one which has a bad datasource
81
* or other problem. Child classes set this flag when intialized
82
* @return True if the layer is valid and can be accessed
86
/*! Gets a version of the internal layer definition that has sensitive
87
* bits removed (for example, the password). This function should
88
* be used when displaying the source name for general viewing.
90
QString publicSource() const;
92
/** Returns the source for the layer */
93
const QString & source() const;
96
* Returns the sublayers of this layer
97
* (Useful for providers that manage their own layers, such as WMS)
99
virtual QStringList subLayers();
102
* Reorders the *previously selected* sublayers of this layer from bottom to top
103
* (Useful for providers that manage their own layers, such as WMS)
105
virtual void setLayerOrder(QStringList layers);
107
/** Set the visibility of the given sublayer name */
108
virtual void setSubLayerVisibility(QString name, bool vis);
111
/** True if the layer can be edited */
112
virtual bool isEditable() const = 0;
114
/** sets state from Dom document
115
@param layer_node is Dom node corresponding to ``maplayer'' tag
118
The Dom node corresponds to a Dom document project file XML element read
121
This, in turn, calls readXml(), which is over-rideable by sub-classes so
122
that they can read their own specific state from the given Dom node.
124
Invoked by QgsProject::read().
126
@returns true if successful
128
bool readXML(QDomNode & layer_node);
131
/** stores state in Dom node
132
@param layer_node is Dom node corresponding to ``projectlayers'' tag
135
The Dom node corresponds to a Dom document project file XML element to be
136
written by QgsProject.
138
This, in turn, calls writeXml(), which is over-rideable by sub-classes so
139
that they can write their own specific state to the given Dom node.
141
Invoked by QgsProject::write().
143
@returns true if successful
145
bool writeXML(QDomNode & layer_node, QDomDocument & document) const;
147
/** Set a custom property for layer. Properties are stored in a map and saved in project file.
148
* @note Added in v1.4 */
149
void setCustomProperty( const QString& key, const QVariant& value );
150
/** Read a custom property from layer. Properties are stored in a map and saved in project file.
151
* @note Added in v1.4 */
152
QVariant customProperty( const QString& value, const QVariant& defaultValue = QVariant() ) const;
153
/** Remove a custom property from layer. Properties are stored in a map and saved in project file.
154
* @note Added in v1.4 */
155
void removeCustomProperty( const QString& key );
157
/** Read the symbology for the current layer from the Dom node supplied.
158
* @param QDomNode node that will contain the symbology definition for this layer.
159
* @param errorMessage reference to string that will be updated with any error messages
160
* @return true in case of success.
162
virtual bool readSymbology(const QDomNode& node, QString& errorMessage) = 0;
164
/** Write the symbology for the layer into the docment provided.
165
* @param QDomNode the node that will have the style element added to it.
166
* @param QDomDocument the document that will have the QDomNode added.
167
* @param errorMessage reference to string that will be updated with any error messages
168
* @return true in case of success.
170
virtual bool writeSymbology(QDomNode&, QDomDocument& doc, QString& errorMessage) const = 0;
173
/** Copies the symbology settings from another layer. Returns true in case of success */
174
virtual bool copySymbologySettings(const QgsMapLayer& other) = 0;
176
/** Returns true if this layer can be in the same symbology group with another layer */
177
virtual bool hasCompatibleSymbology(const QgsMapLayer& other) const = 0;
179
/** Accessor for transparency level. */
180
unsigned int getTransparency();
182
/** Mutator for transparency level. Should be between 0 and 255 */
183
void setTransparency(unsigned int);
186
* If an operation returns 0 (e.g. draw()), this function
187
* returns the text of the error associated with the failure.
188
* Interactive users of this provider can then, for example,
189
* call a QMessageBox to display the contents.
191
virtual QString lastErrorTitle();
194
* If an operation returns 0 (e.g. draw()), this function
195
* returns the text of the error associated with the failure.
196
* Interactive users of this provider can then, for example,
197
* call a QMessageBox to display the contents.
199
virtual QString lastError();
201
/** Returns layer's spatial reference system
202
@note This was introduced in QGIS 1.4
205
const QgsCoordinateReferenceSystem& crs();
207
/** Returns layer's spatial reference system
208
@note This method is here for API compatibility
209
and will be deprecited in 2.0
212
const QgsCoordinateReferenceSystem& srs();
214
/** Sets layer's spatial reference system
215
@note emitSignal added in 1.4 */
216
void setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal = true );
218
/** A convenience function to capitalise the layer name */
219
static QString capitaliseLayerName(const QString name);
221
/** Retrieve the default style for this layer if one
222
* exists (either as a .qml file on disk or as a
223
* record in the users style table in their personal qgis.db)
224
* @param a reference to a flag that will be set to false if
225
* we did not manage to load the default style.
226
* @return a QString with any status messages
227
* @see also loadNamedStyle ();
229
virtual QString loadDefaultStyle( bool & theResultFlag );
231
/** Retrieve a named style for this layer if one
232
* exists (either as a .qml file on disk or as a
233
* record in the users style table in their personal qgis.db)
234
* @param QString theURI - the file name or other URI for the
235
* style file. First an attempt will be made to see if this
236
* is a file and load that, if that fails the qgis.db styles
237
* table will be consulted to see if there is a style who's
238
* key matches the URI.
239
* @param a reference to a flag that will be set to false if
240
* we did not manage to load the default style.
241
* @return a QString with any status messages
242
* @see also loadDefaultStyle ();
244
virtual QString loadNamedStyle( const QString theURI, bool & theResultFlag );
246
virtual bool loadNamedStyleFromDb( const QString db, const QString theURI, QString &qml );
248
/** Save the properties of this layer as the default style
249
* (either as a .qml file on disk or as a
250
* record in the users style table in their personal qgis.db)
251
* @param a reference to a flag that will be set to false if
252
* we did not manage to save the default style.
253
* @return a QString with any status messages
254
* @see also loadNamedStyle () and saveNamedStyle()
256
virtual QString saveDefaultStyle( bool & theResultFlag );
258
/** Save the properties of this layer as a named style
259
* (either as a .qml file on disk or as a
260
* record in the users style table in their personal qgis.db)
261
* @param QString theURI - the file name or other URI for the
262
* style file. First an attempt will be made to see if this
263
* is a file and save to that, if that fails the qgis.db styles
264
* table will be used to create a style entry who's
265
* key matches the URI.
266
* @param a reference to a flag that will be set to false if
267
* we did not manage to save the default style.
268
* @return a QString with any status messages
269
* @see also saveDefaultStyle ();
271
virtual QString saveNamedStyle( const QString theURI, bool & theResultFlag );
273
/** Return pointer to layer's undo stack */
274
QUndoStack* undoStack();
276
/** Get the QImage used for caching render operations
277
* @note This method was added in QGIS 1.4 **/
278
QImage *cacheImage();
279
/** Set the QImage used for caching render operations
280
* @note This method was added in QGIS 1.4 **/
281
void setCacheImage( QImage * thepImage );
285
/** Event handler for when a coordinate transform fails due to bad vertex error */
286
virtual void invalidTransformInput();
288
/** Accessor and mutator for the minimum scale member */
289
void setMinimumScale(float theMinScale);
290
float minimumScale();
292
/** Accessor and mutator for the maximum scale member */
293
void setMaximumScale(float theMaxScale);
294
float maximumScale();
296
/** Accessor and mutator for the scale based visilibility flag */
297
void toggleScaleBasedVisibility( bool theVisibilityFlag);
298
bool hasScaleBasedVisibility();
302
/** Emit a signal to notify of a progress event */
303
void setProgress(int theProgress, int theTotalSteps);
305
/** Emit a signal with status (e.g. to be caught by QgiAapp and display a msg on status bar) */
306
void setStatus(QString theStatusQString);
308
/** Emit a signal that the layer name has been changed */
309
void layerNameChanged();
311
/** Emit a signal that layer's CRS has been reset
314
void layerCrsChanged();
316
/** This signal should be connected with the slot QgsMapCanvas::refresh()
317
* @TODO: to be removed - GUI dependency
319
void repaintRequested();
321
/** This is used to send a request that any mapcanvas using this layer update its extents */
322
void recalculateExtents();
326
/** called by readXML(), used by children to read state specific to them from
329
virtual bool readXml( QDomNode & layer_node );
331
/** called by writeXML(), used by children to write state specific to them to
334
virtual bool writeXml( QDomNode & layer_node, QDomDocument & document );
336
/** debugging member - invoked when a connect() is made to this object */
337
void connectNotify( const char * signal );
341
/** private copy constructor - QgsMapLayer not copyable */
342
QgsMapLayer( const QgsMapLayer & );