Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgsvectorlayer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorlayer.h - description
3  -------------------
4  begin : Oct 29, 2003
5  copyright : (C) 2003 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$ */
18 
19 #ifndef QGSVECTORLAYER_H
20 #define QGSVECTORLAYER_H
21 
22 #include <QMap>
23 #include <QSet>
24 #include <QList>
25 #include <QStringList>
26 
27 #include "qgis.h"
28 #include "qgsmaplayer.h"
29 #include "qgsfeature.h"
30 #include "qgssnapper.h"
31 #include "qgsfield.h"
32 
33 class QPainter;
34 class QImage;
35 
36 class QgsAttributeAction;
38 class QgsGeometry;
39 class QgsGeometryVertexIndex;
40 class QgsMapToPixel;
41 class QgsLabel;
42 class QgsRectangle;
43 class QgsRenderer;
44 class QgsUndoCommand;
46 class QgsVectorOverlay;
48 class QgsRectangle;
53 
54 typedef QList<int> QgsAttributeList;
55 typedef QSet<int> QgsFeatureIds;
56 typedef QSet<int> QgsAttributeIds;
57 
59 struct CORE_EXPORT QgsVectorJoinInfo
60 {
64  QString joinLayerId;
66  int joinField;
70  QHash< QString, QgsAttributeMap> cachedAttributes;
71 };
72 
77 struct CORE_EXPORT QgsFetchJoinInfo
78 {
80  QgsAttributeList attributes; //attributes to fetch
81  int indexOffset; //index offset between this layer and join layer
82 };
83 
87 class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
88 {
89  Q_OBJECT
90 
91  public:
92  enum EditType
93  {
101  CheckBox, /* added in 1.4 */
104  Immutable, /* The attribute value should not be changed in the attribute form*/
105  Hidden, /* The attribute value should not be shown in the attribute form @added in 1.4 */
106  TextEdit, /* multiline edit @added in 1.4*/
107  Calendar, /* calendar widget @added in 1.5 */
108  DialRange, /* dial range @added in 1.5 */
109  };
110 
111  struct RangeData
112  {
114  RangeData( QVariant theMin, QVariant theMax, QVariant theStep )
115  : mMin( theMin ), mMax( theMax ), mStep( theStep ) {}
116 
117  QVariant mMin;
118  QVariant mMax;
119  QVariant mStep;
120  };
121 
123  QgsVectorLayer( QString path = QString::null, QString baseName = QString::null,
124  QString providerLib = QString::null, bool loadDefaultStyleFlag = true );
125 
127  virtual ~QgsVectorLayer();
128 
130  QString storageType() const;
131 
133  QString capabilitiesString() const;
134 
136  QString dataComment() const;
137 
139  void setDisplayField( QString fldName = "" );
140 
142  const QString displayField() const;
143 
145  QgsVectorDataProvider* dataProvider();
146 
148  const QgsVectorDataProvider* dataProvider() const;
149 
151  void setProviderEncoding( const QString& encoding );
152 
154  void setCoordinateSystem();
155 
159  void addJoin( QgsVectorJoinInfo joinInfo );
160 
163  void removeJoin( const QString& joinLayerId );
164 
166  const QList< QgsVectorJoinInfo >& vectorJoins() const;
167 
169  QgsLabel *label();
170 
171  const QgsLabel *label() const;
172 
173  QgsAttributeAction* actions() { return mActions; }
174 
176  int selectedFeatureCount();
177 
179  void select( QgsRectangle & rect, bool lock );
180 
182  void invertSelection();
183 
185  void invertSelectionInRectangle( QgsRectangle & rect );
186 
188  QgsFeatureList selectedFeatures();
189 
191  const QgsFeatureIds& selectedFeaturesIds() const;
192 
194  void setSelectedFeatures( const QgsFeatureIds& ids );
195 
197  QgsRectangle boundingBoxOfSelected();
198 
200  bool copySymbologySettings( const QgsMapLayer& other );
201 
203  bool hasCompatibleSymbology( const QgsMapLayer& other ) const;
204 
206  const QgsRenderer* renderer() const;
207 
209  void setRenderer( QgsRenderer * r );
210 
212  void setDiagramRenderer( QgsDiagramRendererV2* r );
213  const QgsDiagramRendererV2* diagramRenderer() const { return mDiagramRenderer; }
214 
215  void setDiagramLayerSettings( const QgsDiagramLayerSettings& s );
216  const QgsDiagramLayerSettings *diagramLayerSettings() const { return mDiagramLayerSettings; }
217 
220  QgsFeatureRendererV2* rendererV2();
224  void setRendererV2( QgsFeatureRendererV2* r );
228  bool isUsingRendererV2();
232  void setUsingRendererV2( bool usingRendererV2 );
233 
237  void drawRendererV2( QgsRenderContext& rendererContext, bool labeling );
238 
242  void drawRendererV2Levels( QgsRenderContext& rendererContext, bool labeling );
243 
245  QGis::GeometryType geometryType() const;
246 
249  bool hasGeometryType() const;
250 
252  QGis::WkbType wkbType() const;
253 
255  QString providerType() const;
256 
260  virtual bool readXml( QDomNode & layer_node );
261 
265  virtual bool writeXml( QDomNode & layer_node, QDomDocument & doc );
266 
272  bool readSymbology( const QDomNode& node, QString& errorMessage );
273 
280  bool writeSymbology( QDomNode& node, QDomDocument& doc, QString& errorMessage ) const;
281 
282 
290  virtual long featureCount() const;
291 
295  virtual long updateFeatureCount() const;
296 
304  virtual bool setSubsetString( QString subset );
305 
310  virtual QString subsetString();
311 
319  void select( QgsAttributeList fetchAttributes,
320  QgsRectangle rect = QgsRectangle(),
321  bool fetchGeometry = true,
322  bool useIntersect = false );
323 
329  bool nextFeature( QgsFeature& feature );
330 
333  bool featureAtId( int featureId, QgsFeature &f, bool fetchGeometries = true, bool fetchAttributes = true );
334 
340  bool addFeature( QgsFeature& f, bool alsoUpdateExtent = true );
341 
342 
347  bool insertVertex( double x, double y, int atFeatureId, int beforeVertex );
348 
353  bool moveVertex( double x, double y, int atFeatureId, int atVertex );
354 
357  bool deleteVertex( int atFeatureId, int atVertex );
358 
362  bool deleteSelectedFeatures();
363 
372  int addRing( const QList<QgsPoint>& ring );
373 
383  int addIsland( const QList<QgsPoint>& ring );
384 
390  int translateFeature( int featureId, double dx, double dy );
391 
396  int splitFeatures( const QList<QgsPoint>& splitLine, bool topologicalEditing = false );
397 
402  int removePolygonIntersections( QgsGeometry* geom );
403 
410  int addTopologicalPoints( QgsGeometry* geom );
411 
418  int addTopologicalPoints( const QgsPoint& p );
419 
424  int insertSegmentVerticesForSnap( const QList<QgsSnappingResult>& snapResults );
425 
427  void enableLabels( bool on );
428 
430  bool hasLabelsEnabled( void ) const;
431 
433  virtual bool isEditable() const;
434 
437  virtual bool isReadOnly() const;
438 
440  virtual bool isModified() const;
441 
447  bool snapPoint( QgsPoint& point, double tolerance );
448 
456  int snapWithContext( const QgsPoint& startPoint,
457  double snappingTolerance,
458  QMultiMap < double,
459  QgsSnappingResult > & snappingResults,
460  QgsSnapper::SnappingType snap_to );
461 
464  virtual void reload();
465 
469  bool draw( QgsRenderContext& rendererContext );
470 
472  void drawLabels( QgsRenderContext& rendererContext );
473 
475  const QgsFieldMap &pendingFields() const;
476 
478  QgsAttributeList pendingAllAttributesList();
479 
481  int pendingFeatureCount();
482 
487  bool setReadOnly( bool readonly = true );
488 
490  void setModified( bool modified = true, bool onlyGeometryWasModified = false );
491 
493  bool startEditing();
494 
497  bool changeGeometry( int fid, QgsGeometry* geom );
498 
500  bool changeAttributeValue( int fid, int field, QVariant value, bool emitSignal = true );
501 
505  bool addAttribute( const QgsField &field );
506 
510  Q_DECL_DEPRECATED bool addAttribute( QString name, QString type );
511 
514  void addAttributeAlias( int attIndex, QString aliasString );
515 
518  QString attributeAlias( int attributeIndex ) const;
519 
522  QString attributeDisplayName( int attributeIndex ) const;
523 
525  bool deleteAttribute( int attr );
526 
528  bool addFeatures( QgsFeatureList features, bool makeSelected = true );
529 
531  bool deleteFeature( int fid );
532 
548  bool commitChanges();
549  const QStringList &commitErrors();
550 
552  bool rollBack();
553 
555  EditType editType( int idx );
556 
558  void setEditType( int idx, EditType edit );
559 
561  void setCheckedState( int idx, QString checked, QString notChecked );
562 
564  QPair<QString, QString> checkedState( int idx );
565 
567  QString editForm();
568 
570  void setEditForm( QString ui );
571 
573  QString annotationForm() const { return mAnnotationForm; }
574 
576  void setAnnotationForm( const QString& ui );
577 
579  QString editFormInit();
580 
582  void setEditFormInit( QString function );
583 
585  QMap<QString, QVariant> &valueMap( int idx );
586 
588  RangeData &range( int idx );
589 
593  void addOverlay( QgsVectorOverlay* overlay );
594 
598  void removeOverlay( const QString& typeName );
599 
603  void vectorOverlays( QList<QgsVectorOverlay*>& overlayList );
604 
608  QgsVectorOverlay* findOverlayByType( const QString& typeName );
609 
610 
615  void beginEditCommand( QString text );
616 
618  void endEditCommand();
619 
621  void destroyEditCommand();
622 
624  void undoEditCommand( QgsUndoCommand* cmd );
625 
627  void redoEditCommand( QgsUndoCommand* cmd );
628 
632  int fieldNameIndex( const QString& fieldName ) const;
633 
637  {
640  NoMarker /* added in version 1.1 */
641  };
642 
645  static void drawVertexMarker( double x, double y, QPainter& p, QgsVectorLayer::VertexMarkerType type, int vertexSize );
646 
649  void updateFieldMap();
650 
653  void createJoinCaches();
654 
660  void uniqueValues( int index, QList<QVariant> &uniqueValues, int limit = -1 );
661 
664  QVariant minimumValue( int index );
665 
668  QVariant maximumValue( int index );
669 
670  public slots:
672  void select( int featureId, bool emitSignal = true );
673 
675  void deselect( int featureId, bool emitSignal = true );
676 
678  void removeSelection( bool emitSignal = true );
679 
680  void triggerRepaint();
681 
685  virtual void updateExtents();
686 
689  void checkJoinLayerRemove( QString theLayerId );
690 
691  signals:
692 
694  void selectionChanged();
695 
697  void layerModified( bool onlyGeometry );
698 
699  void editingStarted();
700  void editingStopped();
701  void attributeAdded( int idx );
702  void attributeDeleted( int idx );
703  void featureAdded( int fid ); // added in 1.7
704  void featureDeleted( int fid );
705  void layerDeleted();
706 
707  void attributeValueChanged( int fid, int idx, const QVariant & );
708 
711  void committedAttributesDeleted( const QString& layerId, const QgsAttributeIds& deletedAttributeIds );
712  void committedAttributesAdded( const QString& layerId, const QList<QgsField>& addedAttributes );
713  void committedFeaturesAdded( const QString& layerId, const QgsFeatureList& addedFeatures );
714  void committedFeaturesRemoved( const QString& layerId, const QgsFeatureIds& deletedFeatureIds );
715  void committedAttributeValuesChanges( const QString& layerId, const QgsChangedAttributesMap& changedAttributesValues );
716  void committedGeometriesChanges( const QString& layerId, const QgsGeometryMap& changedGeometries );
717 
718  private: // Private methods
719 
721  QgsVectorLayer( QgsVectorLayer const & rhs );
722 
724  QgsVectorLayer & operator=( QgsVectorLayer const & rhs );
725 
730  bool setDataProvider( QString const & provider );
731 
734  void drawFeature( QgsRenderContext &renderContext,
735  QgsFeature& fet,
736  QImage* marker );
737 
739  void transformPoint( double& x, double& y,
740  const QgsMapToPixel* mtp, const QgsCoordinateTransform* ct );
741 
742  void transformPoints( std::vector<double>& x, std::vector<double>& y, std::vector<double>& z, QgsRenderContext &renderContext );
743 
747  unsigned char *drawLineString( unsigned char *WKBlinestring, QgsRenderContext &renderContext );
748 
752  unsigned char *drawPolygon( unsigned char *WKBpolygon, QgsRenderContext &renderContext );
753 
755  int findFreeId();
756 
758  void deleteCachedGeometries();
759 
768  void snapToGeometry( const QgsPoint& startPoint, int featureId, QgsGeometry* geom, double sqrSnappingTolerance,
769  QMultiMap<double, QgsSnappingResult>& snappingResults, QgsSnapper::SnappingType snap_to ) const;
770 
773  int boundingBoxFromPointList( const QList<QgsPoint>& list, double& xmin, double& ymin, double& xmax, double& ymax ) const;
774 
776  static QgsVectorLayer::VertexMarkerType currentVertexMarkerType();
777 
779  static int currentVertexMarkerSize();
780 
782  void updateFeatureAttributes( QgsFeature &f, bool all = false );
783 
791  void addJoinedFeatureAttributes( QgsFeature& f, const QgsVectorJoinInfo& joinInfo, const QString& joinFieldName, const QVariant& joinValue,
792  const QgsAttributeList& attributes, int attributeIndexOffset );
793 
795  void updateFeatureGeometry( QgsFeature &f );
796 
798  void editGeometryChange( int featureId, QgsGeometry& geometry );
799 
801  void editFeatureAdd( QgsFeature& feature );
802 
804  void editFeatureDelete( int featureId );
805 
807  void editAttributeChange( int featureId, int field, QVariant value );
808 
810  void stopRendererV2( QgsRenderContext& rendererContext, QgsSingleSymbolRendererV2* selRenderer );
811 
813  void updateAttributeMapIndex( QgsAttributeMap& map, int oldIndex, int newIndex ) const;
814 
819  void prepareLabelingAndDiagrams( QgsRenderContext& rendererContext, QgsAttributeList& attributes, bool& labeling );
820 
821  private: // Private attributes
822 
827 
830 
832  QString mDisplayField;
833 
835  QString mProviderKey;
836 
839 
841  bool mEditable;
842 
844  bool mReadOnly;
845 
847  bool mModified;
848 
851 
854 
860 
866 
871 
874 
877 
880 
883 
886 
888  QMap< QString, QString > mAttributeAliasMap;
889 
892 
894  int mWkbType;
895 
897 
900 
903 
906 
909 
911  bool mLabelOn;
912 
915 
918 
921 
923  QList<QgsVectorOverlay*> mOverlays;
924 
925  QStringList mCommitErrors;
926 
927  QMap< QString, EditType > mEditTypes;
928  QMap< QString, QMap<QString, QVariant> > mValueMaps;
929  QMap< QString, RangeData > mRanges;
930  QMap< QString, QPair<QString, QString> > mCheckedStates;
931 
932  QString mEditForm, mEditFormInit;
933  //annotation form for this layer
935 
936  bool mFetching;
941 
942  QSet<int> mFetchConsidered;
943  QgsGeometryMap::iterator mFetchChangedGeomIt;
944  QgsFeatureList::iterator mFetchAddedFeaturesIt;
945 
946  //stores information about joined layers
948 
949  //diagram rendering object. 0 if diagram drawing is disabled
951 
952  //stores infos about diagram placement (placement type, priority, position distance)
954 };
955 
956 #endif