~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/gui/qgsmaplayer.h

  • 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
 
                          qgsmaplayer.h  -  description
3
 
                             -------------------
4
 
    begin                : Fri Jun 28 2002
5
 
    copyright            : (C) 2002 by Gary E.Sherman
6
 
    email                : sherman at mrcc.com
7
 
***************************************************************************/
8
 
 
9
 
/***************************************************************************
10
 
 *                                                                         *
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.                                   *
15
 
 *                                                                         *
16
 
 ***************************************************************************/
17
 
/* $Id: qgsmaplayer.h 6265 2006-12-15 23:22:01Z g_j_m $ */
18
 
 
19
 
#ifndef QGSMAPLAYER_H
20
 
#define QGSMAPLAYER_H
21
 
 
22
 
#include <vector>
23
 
#include <map>
24
 
 
25
 
#include <QObject>
26
 
#include <QPixmap>
27
 
#include <QMenu> // not forward declared because other .h files
28
 
                 // inherit from us and we're being nice to them.
29
 
 
30
 
#include "qgis.h"
31
 
#include "qgsrect.h"
32
 
#include "qgsfield.h"
33
 
#include "qgscoordinatetransform.h"
34
 
 
35
 
class QAction;
36
 
class QgisApp;
37
 
class QgsMapToPixel;
38
 
class QgsFeature;
39
 
class QgsLegend;
40
 
class QgsLegendLayerFile;
41
 
 
42
 
class QDomNode;
43
 
class QDomDocument;
44
 
class QKeyEvent;
45
 
 
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,
49
 
 * raster, database).
50
 
 */
51
 
class QgsMapLayer : public QObject
52
 
{
53
 
    Q_OBJECT;
54
 
 
55
 
public:
56
 
 
57
 
    /*! Constructor
58
 
     * @param type Type of layer as defined in LAYERS enum
59
 
     * @param lyrname Display Name of the layer
60
 
     */
61
 
    QgsMapLayer(int type = 0, QString lyrname = QString::null, QString source = QString::null);
62
 
 
63
 
    //! Destructor
64
 
    virtual ~ QgsMapLayer();
65
 
 
66
 
    /*! Get the type of the layer
67
 
     * @return Integer matching a value in the LAYERS enum
68
 
     */
69
 
    int type() const;
70
 
 
71
 
    /*! Get this layer's unique ID */
72
 
    QString const & getLayerID() const;
73
 
 
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)
78
 
     */
79
 
    void setLayerName(const QString & name, bool updateLegend=true);
80
 
 
81
 
    /*! Get the display name of the layer
82
 
     * @return the layer name
83
 
     */
84
 
    QString const & name() const;
85
 
 
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
89
 
     */
90
 
    QString const & sourceName() const;
91
 
 
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
95
 
     */
96
 
    virtual QgsRect calculateExtent();
97
 
 
98
 
    /*! Accesor for mShowInOverviewFlag */
99
 
    bool showInOverviewStatus()
100
 
    {
101
 
        return mShowInOverview;
102
 
    }
103
 
 
104
 
 
105
 
    virtual void draw(QPainter *, QgsRect *, int);
106
 
 
107
 
    //! Returns FALSE if an error occurred during drawing
108
 
    virtual bool draw(QPainter *, QgsRect *, QgsMapToPixel *, bool);
109
 
    virtual void drawLabels(QPainter *, QgsRect *, QgsMapToPixel *);
110
 
 
111
 
    /*!Select features on the map canvas by dragging a rectangle */
112
 
    virtual void select(QgsRect *, bool )
113
 
    {}
114
 
    ;
115
 
 
116
 
    //! Display the attribute table for the layer
117
 
    /**
118
 
       \param qgisApp   This should be the QgisApp that spawned this table.
119
 
     */
120
 
    virtual void table(QgisApp * qgisApp)
121
 
    {};
122
 
 
123
 
    /*! Return the extent of the layer as a QRect
124
 
     */
125
 
    const QgsRect extent();
126
 
 
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
130
 
     */
131
 
    bool isValid();
132
 
 
133
 
    /** Write property of QString labelField. */
134
 
    virtual void setLabelField(const QString & _newVal);
135
 
 
136
 
    /** Read property of QString labelField. */
137
 
    virtual const QString & labelField();
138
 
 
139
 
    //! Visibility of the layer
140
 
    bool visible();
141
 
 
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.
145
 
    */
146
 
    QString publicSource() const;
147
 
 
148
 
    //! Returns the source for the layer
149
 
    QString const & source() const;
150
 
 
151
 
    /** Write property of int featureType. */
152
 
    virtual void setFeatureType(const int &_newVal);
153
 
 
154
 
    /** Read property of int featureType. */
155
 
    virtual const int &featureType();
156
 
 
157
 
    /** Return the context menu for the layer */
158
 
    virtual QMenu* contextMenu();
159
 
 
160
 
    /**
161
 
     * Returns the sublayers of this layer
162
 
     *
163
 
     * (Useful for providers that manage their own layers, such as WMS)
164
 
     *
165
 
     */
166
 
    virtual QStringList subLayers()
167
 
    {
168
 
      return QStringList();  // Empty
169
 
    }
170
 
    
171
 
    /**
172
 
     * Reorders the *previously selected* sublayers of this layer from bottom to top
173
 
     *
174
 
     * (Useful for providers that manage their own layers, such as WMS)
175
 
     *
176
 
     */
177
 
    virtual void setLayerOrder(QStringList layers)
178
 
    {
179
 
      // NOOP
180
 
    }
181
 
    
182
 
    /**
183
 
     * Set the visibility of the given sublayer name
184
 
     */
185
 
    virtual void setSubLayerVisibility(QString name, bool vis)
186
 
    {
187
 
      // NOOP
188
 
    }
189
 
 
190
 
    //! Layers enum defining the types of layers that can be added to a map
191
 
    enum LAYERS
192
 
    {
193
 
        VECTOR,
194
 
        RASTER,
195
 
        DATABASE
196
 
    };
197
 
 
198
 
    /**Shows the properties dialog for the map layer*/
199
 
    virtual void showLayerProperties() = 0;
200
 
 
201
 
    /**
202
 
        All inherited layers must be able to display a conext menu if requested
203
 
 
204
 
        @note Calls initContextMenu_()
205
 
    */
206
 
    void initContextMenu(QgisApp * app);
207
 
 
208
 
    /**
209
 
        Allows children to tailor context menu
210
 
 
211
 
        @note Calls initContextMenu_()
212
 
    */
213
 
    virtual void initContextMenu_(QgisApp * app)
214
 
    {
215
 
        // NOP; children can optionally over-ride
216
 
    }
217
 
 
218
 
    void setLegendLayerFile(QgsLegendLayerFile* llf) {mLegendLayerFile = llf;}
219
 
 
220
 
    /**True if the layer can be edited*/
221
 
    virtual bool isEditable() const =0;
222
 
 
223
 
    /** sets state from DOM document
224
 
 
225
 
       @param layer_node is DOM node corresponding to ``maplayer'' tag
226
 
 
227
 
       @note
228
 
 
229
 
       The DOM node corresponds to a DOM document project file XML element read
230
 
       by QgsProject.
231
 
 
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.
234
 
 
235
 
       Invoked by QgsProject::read().
236
 
 
237
 
       @returns true if successful
238
 
 
239
 
     */
240
 
    bool readXML( QDomNode & layer_node );
241
 
 
242
 
 
243
 
    /** stores state in DOM node
244
 
 
245
 
       @param layer_node is DOM node corresponding to ``projectlayers'' tag
246
 
 
247
 
       @note
248
 
 
249
 
       The DOM node corresponds to a DOM document project file XML element to be
250
 
       written by QgsProject.
251
 
 
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.
254
 
 
255
 
       Invoked by QgsProject::write().
256
 
 
257
 
       @returns true if successful
258
 
 
259
 
    */
260
 
    bool writeXML( QDomNode & layer_node, QDomDocument & document );
261
 
 
262
 
    /** Accessor for the coordinate transformation object */
263
 
    QgsCoordinateTransform * coordinateTransform();
264
 
 
265
 
    /** A simple helper method to find out if on the fly projections 
266
 
        are enabled or not */
267
 
    bool projectionsEnabled() const;
268
 
    
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);
275
 
 
276
 
    /**Returns the path to an icon which characterises the type of layer*/
277
 
    virtual QString layerTypeIconPath() = 0;
278
 
 
279
 
    void setLegend(QgsLegend* legend) {mLegend = legend;}
280
 
    const QgsLegend* legend() {return mLegend;}
281
 
 
282
 
    /**Refresh the symbology part of the legend. Specific implementations have to be provided by subclasses*/
283
 
    virtual void refreshLegend() = 0;
284
 
 
285
 
    /**Copies the symbology settings from another layer. Returns true in case of success*/
286
 
    virtual bool copySymbologySettings(const QgsMapLayer& other) = 0;
287
 
 
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;
290
 
 
291
 
    virtual std::vector < QgsField > const &fields() const;
292
 
 
293
 
    /** \brief accessor for transparency level.  */
294
 
    virtual unsigned int getTransparency()=0;
295
 
 
296
 
 
297
 
    /**
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.
302
 
     */
303
 
    virtual QString errorCaptionString();
304
 
  
305
 
    /**
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.
310
 
     */
311
 
    virtual QString errorString();
312
 
 
313
 
public  slots:
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();
318
 
 
319
 
 
320
 
    //! keyPress event so we can check if cancel was pressed
321
 
    void keyPressed ( QKeyEvent * e );
322
 
 
323
 
    //! set visibility
324
 
    void setVisible(bool vis);
325
 
 
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();
329
 
 
330
 
    /**Copies the legend pixmap of this layer to the legenditem and adds an overview glasses if necessary*/
331
 
    void updateItemPixmap();
332
 
 
333
 
    /**Ensures that the overview item in the popup menu is checked/ unchecked correctly*/
334
 
    void updateOverviewPopupItem();
335
 
 
336
 
    /** set whether this layer is in the overview or not
337
 
 
338
 
    @note this will hopefully eventually supercede toggleOverviewStatus() since
339
 
    this makes explicit the state change
340
 
 
341
 
    */
342
 
    virtual void inOverview( bool );
343
 
 
344
 
    /** Accessor and mutator for the minimum scale member */
345
 
    void setMinScale(float theMinScale)
346
 
    {
347
 
        mMinScale=theMinScale;
348
 
    };
349
 
    float minScale()
350
 
    {
351
 
        return mMinScale;
352
 
    };
353
 
 
354
 
    /** Accessor and mutator for the maximum scale member */
355
 
    void setMaxScale(float theMaxScale)
356
 
    {
357
 
        mMaxScale=theMaxScale;
358
 
    };
359
 
    float maxScale()
360
 
    {
361
 
        return mMaxScale;
362
 
    };
363
 
 
364
 
    /** Accessor and mutator for the scale based visilibility flag */
365
 
    void setScaleBasedVisibility( bool theVisibilityFlag)
366
 
    {
367
 
        mScaleBasedVisibility=theVisibilityFlag;
368
 
    };
369
 
    bool scaleBasedVisibility()
370
 
    {
371
 
        return mScaleBasedVisibility;
372
 
    };
373
 
 
374
 
    /** Used to ask the layer for its projection as a WKT string. Must be reimplemented by each provider. */
375
 
    virtual QString getProjectionWKT()  = 0 ;
376
 
signals:
377
 
 
378
 
    void visibilityChanged(void);
379
 
 
380
 
    /** \brief emit a signal to notify of a progress event */
381
 
    void drawingProgress(int theProgress, int theTotalSteps);
382
 
 
383
 
    /** \brief emit a signal to be caught by gisapp and display a msg on status bar */
384
 
    void setStatus(QString theStatusQString);
385
 
 
386
 
    /** This signal should be connected with the slot QgsMapCanvas::refresh() */
387
 
    void repaintRequested();
388
 
 
389
 
    /** This is used to notify the application whether this layer should be shown in overview or not. */
390
 
    //@{
391
 
    //void showInOverview(QString theLayerId, bool);
392
 
    void showInOverview(QgsMapLayer * maplayer, bool);
393
 
    //@}
394
 
 
395
 
    /** This is used to send a request that any mapcanvas using this layer update its extents */
396
 
    void recalculateExtents();
397
 
 
398
 
protected:
399
 
 
400
 
    /** \brief Transparency level for this layer should be 0-255 (255 being opaque)  */
401
 
    unsigned int transparencyLevelInt;
402
 
  
403
 
    /** called by readXML(), used by children to read state specific to them from
404
 
        project files.
405
 
    */
406
 
    virtual bool readXML_( QDomNode & layer_node );
407
 
 
408
 
    /** called by writeXML(), used by children to write state specific to them to
409
 
        project files.
410
 
    */
411
 
    virtual bool writeXML_( QDomNode & layer_node, QDomDocument & document );
412
 
 
413
 
 
414
 
    //! Extent of the layer
415
 
    QgsRect layerExtent;
416
 
 
417
 
    //! Indicates if the layer is valid and can be drawn
418
 
    bool valid;
419
 
 
420
 
    //! data source description string, varies by layer type
421
 
    QString dataSource;
422
 
 
423
 
    //! Geometry type as defined in enum WKBTYPE (qgis.h)
424
 
    int geometryType;
425
 
 
426
 
    /** Pixmap to show a bogus vertex was encoutnered in this layer (applies to vector layers only) */
427
 
    QPixmap mProjectionErrorPixmap;
428
 
 
429
 
    //! A little pixmap to show if this layer is represented in overview or now
430
 
    QPixmap mInOverviewPixmap;
431
 
 
432
 
    QPixmap mEditablePixmap;
433
 
 
434
 
    /** Internal name of the layer. Derived from the datasource */
435
 
    QString internalName;
436
 
 
437
 
    //! context menu
438
 
    QMenu* popMenu;
439
 
 
440
 
    //! the action in popmenu that sets overview status
441
 
    QAction* mShowInOverviewAction;
442
 
 
443
 
    /** Whether this layer is to be shown in the overview map or not */
444
 
    bool mShowInOverview;
445
 
 
446
 
    //   /** action item for pop-up menu
447
 
 
448
 
    //       @note obviously should be in synch with mShowInOverview
449
 
 
450
 
    //       Is set in context menu.
451
 
 
452
 
    //       @todo this is a GUI element and should not be here
453
 
    //   */
454
 
    //   QAction* mActionInOverview;
455
 
    /** A flag to let the draw() render loop know if the user has requested drawing be cancelled */
456
 
    bool mDrawingCancelled;
457
 
 
458
 
    //! A QgsCoordinateTransform is used for on the fly reprojection of map layers
459
 
    QgsCoordinateTransform * mCoordinateTransform; 
460
 
 
461
 
    /**Pointer to the legend layer item of the legend*/
462
 
    QgsLegend* mLegend;
463
 
 
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;
467
 
 
468
 
private:                       // Private attributes
469
 
 
470
 
    /// QgsMapLayer not copyable
471
 
    QgsMapLayer( QgsMapLayer const & );
472
 
 
473
 
    /// QgsMapLayer not copyable
474
 
    QgsMapLayer & operator=( QgsMapLayer const & );
475
 
 
476
 
    /// A convenience function to capitalise the layer name
477
 
    static QString capitaliseLayerName(const QString name);
478
 
 
479
 
    /** Unique ID of this layer - used to refer to this layer  in QGIS code */
480
 
    QString ID;
481
 
 
482
 
    /** Type of the layer (eg. vector, raster, database  */
483
 
    int layerType;
484
 
 
485
 
    //! Tag for embedding additional information
486
 
    QString tag;
487
 
 
488
 
    /** Name of the layer - used for display  */
489
 
    QString layerName;
490
 
    
491
 
    /**  true if visible ? */
492
 
    bool m_visible;
493
 
 
494
 
    /** debugging member
495
 
        invoked when a connect() is made to this object
496
 
    */
497
 
    void connectNotify( const char * signal );
498
 
 
499
 
    // Calculates the bounding box of the given extent in the inverse
500
 
    // projected spatial reference system.
501
 
    QgsRect calcProjectedBoundingBox(QgsRect& extent);
502
 
 
503
 
    /** Minimum scale at which this layer should be displayed */
504
 
    float mMinScale;
505
 
    /** Maximum scale at which this layer should be displayed */
506
 
    float mMaxScale;
507
 
    /** A flag that tells us whether to use the above vars to restrict layer visibility */
508
 
    bool mScaleBasedVisibility;
509
 
 
510
 
public:                        // Public attributes
511
 
 
512
 
    /** map label ? */
513
 
    QString m_labelField;
514
 
 
515
 
};
516
 
 
517
 
#endif