~ubuntu-branches/ubuntu/trusty/qgis/trusty

« back to all changes in this revision

Viewing changes to python/core/qgsmaplayer.sip

  • 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:
 
1
 
 
2
/** \class QgsMapLayer
 
3
 *  \brief Base class for all map layer types.
 
4
 * This class is the base class for all map layer types (vector, raster).
 
5
 */
 
6
class QgsMapLayer : QObject
 
7
{
 
8
%TypeHeaderCode
 
9
#include <qgsmaplayer.h>
 
10
%End
 
11
 
 
12
%ConvertToSubClassCode
 
13
  if (sipCpp->inherits("QgsMapLayer"))
 
14
  {
 
15
    sipClass = sipClass_QgsMapLayer;
 
16
    QgsMapLayer* layer = qobject_cast<QgsMapLayer*>(sipCpp);
 
17
    if (layer->type() == QgsMapLayer::VectorLayer)
 
18
    {
 
19
      sipClass = sipClass_QgsVectorLayer;
 
20
    }
 
21
    else if (layer->type() == QgsMapLayer::RasterLayer)
 
22
    {
 
23
      sipClass = sipClass_QgsRasterLayer;
 
24
    }
 
25
  }
 
26
  else
 
27
  {
 
28
    sipClass = 0;
 
29
  }
 
30
 
 
31
%End
 
32
 
 
33
public:
 
34
    /** Layers enum defining the types of layers that can be added to a map */
 
35
    enum LayerType
 
36
    {
 
37
        VectorLayer,
 
38
        RasterLayer
 
39
    };
 
40
 
 
41
    /** Constructor
 
42
     * @param type Type of layer as defined in QgsMapLayer::LayerType enum
 
43
     * @param lyrname Display Name of the layer
 
44
     */
 
45
    QgsMapLayer(QgsMapLayer::LayerType type = QgsMapLayer::VectorLayer, QString lyrname = QString::null, QString source = QString::null);
 
46
 
 
47
    /** Destructor */
 
48
    virtual ~QgsMapLayer();
 
49
 
 
50
    /** Get the type of the layer
 
51
     * @return Integer matching a value in the QgsMapLayer::LayerType enum
 
52
     */
 
53
    QgsMapLayer::LayerType type() const;
 
54
 
 
55
    /** Get this layer's unique ID, this ID is used to access this layer from map layer registry */
 
56
    QString getLayerID() const;
 
57
 
 
58
    /** Set the display name of the layer
 
59
     * @param name New name for the layer
 
60
     */
 
61
    void setLayerName(const QString & name);
 
62
 
 
63
    /** Get the display name of the layer
 
64
     * @return the layer name
 
65
     */
 
66
    const QString & name() const;
 
67
 
 
68
    /** Render the layer, to be overridden in child classes
 
69
     */
 
70
    virtual bool draw(QgsRenderContext& rendererContext);
 
71
 
 
72
    /** Draw labels
 
73
     * @TODO to be removed: used only in vector layers
 
74
     */
 
75
    virtual void drawLabels(QgsRenderContext& rendererContext);
 
76
 
 
77
    /** Return the extent of the layer as a QRect */
 
78
    const QgsRectangle extent();
 
79
 
 
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
 
83
     */
 
84
    bool isValid();
 
85
 
 
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. 
 
89
     */ 
 
90
    QString publicSource() const;
 
91
 
 
92
    /** Returns the source for the layer */
 
93
    const QString & source() const;
 
94
 
 
95
    /**
 
96
     * Returns the sublayers of this layer
 
97
     * (Useful for providers that manage their own layers, such as WMS)
 
98
     */
 
99
    virtual QStringList subLayers();
 
100
    
 
101
    /**
 
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)
 
104
     */
 
105
    virtual void setLayerOrder(QStringList layers);
 
106
    
 
107
    /** Set the visibility of the given sublayer name */
 
108
    virtual void setSubLayerVisibility(QString name, bool vis);
 
109
 
 
110
 
 
111
    /** True if the layer can be edited */
 
112
    virtual bool isEditable() const = 0;
 
113
 
 
114
    /** sets state from Dom document
 
115
       @param layer_node is Dom node corresponding to ``maplayer'' tag
 
116
       @note
 
117
 
 
118
       The Dom node corresponds to a Dom document project file XML element read
 
119
       by QgsProject.
 
120
 
 
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.
 
123
 
 
124
       Invoked by QgsProject::read().
 
125
 
 
126
       @returns true if successful
 
127
     */
 
128
    bool readXML(QDomNode & layer_node);
 
129
 
 
130
 
 
131
    /** stores state in Dom node
 
132
       @param layer_node is Dom node corresponding to ``projectlayers'' tag
 
133
       @note
 
134
 
 
135
       The Dom node corresponds to a Dom document project file XML element to be
 
136
       written by QgsProject.
 
137
 
 
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.
 
140
 
 
141
       Invoked by QgsProject::write().
 
142
 
 
143
       @returns true if successful
 
144
    */
 
145
    bool writeXML(QDomNode & layer_node, QDomDocument & document) const;
 
146
 
 
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 );
 
156
 
 
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.
 
161
    */
 
162
    virtual bool readSymbology(const QDomNode& node, QString& errorMessage) = 0;
 
163
 
 
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.
 
169
     */
 
170
    virtual bool writeSymbology(QDomNode&, QDomDocument& doc, QString& errorMessage) const = 0;
 
171
 
 
172
 
 
173
    /** Copies the symbology settings from another layer. Returns true in case of success */
 
174
    virtual bool copySymbologySettings(const QgsMapLayer& other) = 0;
 
175
 
 
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;
 
178
 
 
179
    /** Accessor for transparency level. */
 
180
    unsigned int getTransparency();
 
181
 
 
182
    /** Mutator for transparency level. Should be between 0 and 255 */
 
183
    void setTransparency(unsigned int);
 
184
    
 
185
    /**
 
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.
 
190
     */
 
191
    virtual QString lastErrorTitle();
 
192
  
 
193
    /**
 
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.
 
198
     */
 
199
    virtual QString lastError();
 
200
 
 
201
    /** Returns layer's spatial reference system
 
202
    @note This was introduced in QGIS 1.4
 
203
    */
 
204
    
 
205
    const QgsCoordinateReferenceSystem& crs();
 
206
 
 
207
    /** Returns layer's spatial reference system
 
208
    @note This method is here for API compatibility
 
209
    and will be deprecited in 2.0
 
210
    @see crs()
 
211
    */
 
212
    const QgsCoordinateReferenceSystem& srs();
 
213
    
 
214
    /** Sets layer's spatial reference system
 
215
    @note emitSignal added in 1.4 */
 
216
    void setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal = true );
 
217
 
 
218
    /** A convenience function to capitalise the layer name */
 
219
    static QString capitaliseLayerName(const QString name);
 
220
 
 
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 ();
 
228
     */
 
229
    virtual QString loadDefaultStyle( bool & theResultFlag );
 
230
 
 
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 ();
 
243
     */
 
244
    virtual QString loadNamedStyle( const QString theURI, bool & theResultFlag );
 
245
 
 
246
    virtual bool loadNamedStyleFromDb( const QString db, const QString theURI, QString &qml );
 
247
 
 
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()
 
255
     */
 
256
    virtual QString saveDefaultStyle( bool & theResultFlag );
 
257
 
 
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 ();
 
270
     */
 
271
    virtual QString saveNamedStyle( const QString theURI, bool & theResultFlag );       
 
272
    
 
273
    /** Return pointer to layer's undo stack */
 
274
    QUndoStack* undoStack();
 
275
 
 
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 ); 
 
282
 
 
283
public slots:
 
284
 
 
285
    /** Event handler for when a coordinate transform fails due to bad vertex error */
 
286
    virtual void invalidTransformInput();
 
287
 
 
288
    /** Accessor and mutator for the minimum scale member */
 
289
    void setMinimumScale(float theMinScale);
 
290
    float minimumScale();
 
291
 
 
292
    /** Accessor and mutator for the maximum scale member */
 
293
    void setMaximumScale(float theMaxScale);
 
294
    float maximumScale();
 
295
 
 
296
    /** Accessor and mutator for the scale based visilibility flag */
 
297
    void toggleScaleBasedVisibility( bool theVisibilityFlag);
 
298
    bool hasScaleBasedVisibility();
 
299
 
 
300
signals:
 
301
 
 
302
    /** Emit a signal to notify of a progress event */
 
303
    void setProgress(int theProgress, int theTotalSteps);
 
304
 
 
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);
 
307
 
 
308
    /** Emit a signal that the layer name has been changed */
 
309
    void layerNameChanged();
 
310
 
 
311
    /** Emit a signal that layer's CRS has been reset
 
312
     added in 1.4
 
313
     */
 
314
    void layerCrsChanged();
 
315
 
 
316
    /** This signal should be connected with the slot QgsMapCanvas::refresh()
 
317
     * @TODO: to be removed - GUI dependency
 
318
     */
 
319
    void repaintRequested();
 
320
 
 
321
    /** This is used to send a request that any mapcanvas using this layer update its extents */
 
322
    void recalculateExtents();
 
323
 
 
324
protected:
 
325
 
 
326
    /** called by readXML(), used by children to read state specific to them from
 
327
        project files.
 
328
    */
 
329
    virtual bool readXml( QDomNode & layer_node );
 
330
 
 
331
    /** called by writeXML(), used by children to write state specific to them to
 
332
        project files.
 
333
    */
 
334
    virtual bool writeXml( QDomNode & layer_node, QDomDocument & document );
 
335
 
 
336
    /** debugging member - invoked when a connect() is made to this object */
 
337
    void connectNotify( const char * signal );
 
338
 
 
339
private:
 
340
 
 
341
    /** private copy constructor - QgsMapLayer not copyable */
 
342
    QgsMapLayer( const QgsMapLayer & );
 
343
 
 
344
 
 
345
};
 
346