00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef QGSVECTORLAYER_H
00019 #define QGSVECTORLAYER_H
00020
00021 #include <QMap>
00022 #include <QSet>
00023 #include <QList>
00024 #include <QStringList>
00025
00026 #include "qgis.h"
00027 #include "qgsmaplayer.h"
00028 #include "qgsfeature.h"
00029 #include "qgssnapper.h"
00030 #include "qgsfield.h"
00031
00032 class QPainter;
00033 class QImage;
00034
00035 class QgsAttributeAction;
00036 class QgsCoordinateTransform;
00037 class QgsGeometry;
00038 class QgsGeometryVertexIndex;
00039 class QgsMapToPixel;
00040 class QgsLabel;
00041 class QgsRectangle;
00042 class QgsRenderer;
00043 class QgsUndoCommand;
00044 class QgsVectorDataProvider;
00045 class QgsVectorOverlay;
00046 class QgsSingleSymbolRendererV2;
00047 class QgsRectangle;
00048 class QgsVectorLayerJoinBuffer;
00049 class QgsFeatureRendererV2;
00050 class QgsDiagramRendererV2;
00051 struct QgsDiagramLayerSettings;
00052
00053 typedef QList<int> QgsAttributeList;
00054 typedef QSet<int> QgsAttributeIds;
00055
00057 struct CORE_EXPORT QgsVectorJoinInfo
00058 {
00060 int targetField;
00062 QString joinLayerId;
00064 int joinField;
00066 bool memoryCache;
00068 QHash< QString, QgsAttributeMap> cachedAttributes;
00069 };
00070
00075 struct CORE_EXPORT QgsFetchJoinInfo
00076 {
00077 const QgsVectorJoinInfo* joinInfo;
00078 QgsAttributeList attributes;
00079 int indexOffset;
00080 };
00081
00085 class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
00086 {
00087 Q_OBJECT
00088
00089 public:
00090 enum EditType
00091 {
00092 LineEdit,
00093 UniqueValues,
00094 UniqueValuesEditable,
00095 ValueMap,
00096 Classification,
00097 EditRange,
00098 SliderRange,
00099 CheckBox,
00100 FileName,
00101 Enumeration,
00102 Immutable,
00103 Hidden,
00104 TextEdit,
00105 Calendar,
00106 DialRange,
00107 ValueRelation,
00108 UuidGenerator,
00109 };
00110
00111 struct RangeData
00112 {
00113 RangeData() {}
00114 RangeData( QVariant theMin, QVariant theMax, QVariant theStep )
00115 : mMin( theMin ), mMax( theMax ), mStep( theStep ) {}
00116
00117 QVariant mMin;
00118 QVariant mMax;
00119 QVariant mStep;
00120 };
00121
00122 struct ValueRelationData
00123 {
00124 ValueRelationData() {}
00125 ValueRelationData( QString layer, QString key, QString value, bool allowNull, bool orderByValue )
00126 : mLayer( layer ), mKey( key ), mValue( value ), mAllowNull( allowNull ), mOrderByValue( orderByValue ) {}
00127
00128 QString mLayer;
00129 QString mKey;
00130 QString mValue;
00131 bool mAllowNull;
00132 bool mOrderByValue;
00133 };
00134
00136 QgsVectorLayer( QString path = QString::null, QString baseName = QString::null,
00137 QString providerLib = QString::null, bool loadDefaultStyleFlag = true );
00138
00140 virtual ~QgsVectorLayer();
00141
00143 QString storageType() const;
00144
00146 QString capabilitiesString() const;
00147
00149 QString dataComment() const;
00150
00152 void setDisplayField( QString fldName = "" );
00153
00155 const QString displayField() const;
00156
00158 QgsVectorDataProvider* dataProvider();
00159
00161 const QgsVectorDataProvider* dataProvider() const;
00162
00164 void setProviderEncoding( const QString& encoding );
00165
00167 void setCoordinateSystem();
00168
00172 void addJoin( QgsVectorJoinInfo joinInfo );
00173
00176 void removeJoin( const QString& joinLayerId );
00177
00179 const QList< QgsVectorJoinInfo >& vectorJoins() const;
00180
00182 QgsLabel *label();
00183
00184 const QgsLabel *label() const;
00185
00186 QgsAttributeAction* actions() { return mActions; }
00187
00189 int selectedFeatureCount();
00190
00192 void select( QgsRectangle & rect, bool lock );
00193
00195 void invertSelection();
00196
00198 void invertSelectionInRectangle( QgsRectangle & rect );
00199
00201 QgsFeatureList selectedFeatures();
00202
00204 const QgsFeatureIds& selectedFeaturesIds() const;
00205
00207 void setSelectedFeatures( const QgsFeatureIds& ids );
00208
00210 QgsRectangle boundingBoxOfSelected();
00211
00213 bool copySymbologySettings( const QgsMapLayer& other );
00214
00216 bool hasCompatibleSymbology( const QgsMapLayer& other ) const;
00217
00219 const QgsRenderer* renderer() const;
00220
00222 void setRenderer( QgsRenderer * r );
00223
00225 void setDiagramRenderer( QgsDiagramRendererV2* r );
00226 const QgsDiagramRendererV2* diagramRenderer() const { return mDiagramRenderer; }
00227
00228 void setDiagramLayerSettings( const QgsDiagramLayerSettings& s );
00229 const QgsDiagramLayerSettings *diagramLayerSettings() const { return mDiagramLayerSettings; }
00230
00233 QgsFeatureRendererV2* rendererV2();
00237 void setRendererV2( QgsFeatureRendererV2* r );
00241 bool isUsingRendererV2();
00245 void setUsingRendererV2( bool usingRendererV2 );
00246
00250 void drawRendererV2( QgsRenderContext& rendererContext, bool labeling );
00251
00255 void drawRendererV2Levels( QgsRenderContext& rendererContext, bool labeling );
00256
00258 QGis::GeometryType geometryType() const;
00259
00262 bool hasGeometryType() const;
00263
00265 QGis::WkbType wkbType() const;
00266
00268 QString providerType() const;
00269
00273 virtual bool readXml( const QDomNode& layer_node );
00274
00278 virtual bool writeXml( QDomNode & layer_node, QDomDocument & doc );
00279
00285 bool readSymbology( const QDomNode& node, QString& errorMessage );
00286
00293 bool writeSymbology( QDomNode& node, QDomDocument& doc, QString& errorMessage ) const;
00294
00295 bool writeSld( QDomNode& node, QDomDocument& doc, QString& errorMessage ) const;
00296 bool readSld( const QDomNode& node, QString& errorMessage );
00297
00305 virtual long featureCount() const;
00306
00310 virtual long updateFeatureCount() const;
00311
00319 virtual bool setSubsetString( QString subset );
00320
00325 virtual QString subsetString();
00326
00334 void select( QgsAttributeList fetchAttributes,
00335 QgsRectangle rect = QgsRectangle(),
00336 bool fetchGeometry = true,
00337 bool useIntersect = false );
00338
00344 bool nextFeature( QgsFeature& feature );
00345
00348 bool featureAtId( QgsFeatureId featureId, QgsFeature &f, bool fetchGeometries = true, bool fetchAttributes = true );
00349
00355 bool addFeature( QgsFeature& f, bool alsoUpdateExtent = true );
00356
00362 bool updateFeature( QgsFeature &f );
00363
00368 bool insertVertex( double x, double y, QgsFeatureId atFeatureId, int beforeVertex );
00369
00374 bool moveVertex( double x, double y, QgsFeatureId atFeatureId, int atVertex );
00375
00378 bool deleteVertex( QgsFeatureId atFeatureId, int atVertex );
00379
00383 bool deleteSelectedFeatures();
00384
00393 int addRing( const QList<QgsPoint>& ring );
00394
00404 int addPart( const QList<QgsPoint>& ring );
00405 Q_DECL_DEPRECATED int addIsland( const QList<QgsPoint>& ring ) { return addPart( ring ); }
00406
00412 int translateFeature( QgsFeatureId featureId, double dx, double dy );
00413
00418 int splitFeatures( const QList<QgsPoint>& splitLine, bool topologicalEditing = false );
00419
00424 int removePolygonIntersections( QgsGeometry* geom );
00425
00432 int addTopologicalPoints( QgsGeometry* geom );
00433
00440 int addTopologicalPoints( const QgsPoint& p );
00441
00446 int insertSegmentVerticesForSnap( const QList<QgsSnappingResult>& snapResults );
00447
00449 void enableLabels( bool on );
00450
00452 bool hasLabelsEnabled( void ) const;
00453
00455 virtual bool isEditable() const;
00456
00459 virtual bool isReadOnly() const;
00460
00462 virtual bool isModified() const;
00463
00469 bool snapPoint( QgsPoint& point, double tolerance );
00470
00478 int snapWithContext( const QgsPoint& startPoint,
00479 double snappingTolerance,
00480 QMultiMap < double, QgsSnappingResult > &snappingResults,
00481 QgsSnapper::SnappingType snap_to );
00482
00485 virtual void reload();
00486
00490 bool draw( QgsRenderContext& rendererContext );
00491
00493 void drawLabels( QgsRenderContext& rendererContext );
00494
00496 const QgsFieldMap &pendingFields() const;
00497
00499 QgsAttributeList pendingAllAttributesList();
00500
00502 int pendingFeatureCount();
00503
00508 bool setReadOnly( bool readonly = true );
00509
00511 void setModified( bool modified = true, bool onlyGeometryWasModified = false );
00512
00514 bool startEditing();
00515
00518 bool changeGeometry( QgsFeatureId fid, QgsGeometry* geom );
00519
00521 bool changeAttributeValue( QgsFeatureId fid, int field, QVariant value, bool emitSignal = true );
00522
00526 bool addAttribute( const QgsField &field );
00527
00531 Q_DECL_DEPRECATED bool addAttribute( QString name, QString type );
00532
00535 void addAttributeAlias( int attIndex, QString aliasString );
00536
00539 QString attributeAlias( int attributeIndex ) const;
00540
00543 QString attributeDisplayName( int attributeIndex ) const;
00544
00546 bool deleteAttribute( int attr );
00547
00549 bool addFeatures( QgsFeatureList features, bool makeSelected = true );
00550
00552 bool deleteFeature( QgsFeatureId fid );
00553
00569 bool commitChanges();
00570 const QStringList &commitErrors();
00571
00573 bool rollBack();
00574
00576 EditType editType( int idx );
00577
00579 void setEditType( int idx, EditType edit );
00580
00582 void setCheckedState( int idx, QString checked, QString notChecked );
00583
00585 QPair<QString, QString> checkedState( int idx );
00586
00588 QString editForm();
00589
00591 void setEditForm( QString ui );
00592
00594 QString annotationForm() const { return mAnnotationForm; }
00595
00597 void setAnnotationForm( const QString& ui );
00598
00600 QString editFormInit();
00601
00603 void setEditFormInit( QString function );
00604
00606 QMap<QString, QVariant> &valueMap( int idx );
00607
00609 RangeData &range( int idx );
00610
00614 ValueRelationData &valueRelation( int idx );
00615
00619 void addOverlay( QgsVectorOverlay* overlay );
00620
00624 void removeOverlay( const QString& typeName );
00625
00629 void vectorOverlays( QList<QgsVectorOverlay*>& overlayList );
00630
00634 QgsVectorOverlay* findOverlayByType( const QString& typeName );
00635
00636
00641 void beginEditCommand( QString text );
00642
00644 void endEditCommand();
00645
00647 void destroyEditCommand();
00648
00650 void undoEditCommand( QgsUndoCommand* cmd );
00651
00653 void redoEditCommand( QgsUndoCommand* cmd );
00654
00658 int fieldNameIndex( const QString& fieldName ) const;
00659
00662 enum VertexMarkerType
00663 {
00664 SemiTransparentCircle,
00665 Cross,
00666 NoMarker
00667 };
00668
00671 static void drawVertexMarker( double x, double y, QPainter& p, QgsVectorLayer::VertexMarkerType type, int vertexSize );
00672
00675 void updateFieldMap();
00676
00679 void createJoinCaches();
00680
00686 void uniqueValues( int index, QList<QVariant> &uniqueValues, int limit = -1 );
00687
00690 QVariant minimumValue( int index );
00691
00694 QVariant maximumValue( int index );
00695
00696 public slots:
00698 void select( QgsFeatureId featureId, bool emitSignal = true );
00699
00701 void deselect( QgsFeatureId featureId, bool emitSignal = true );
00702
00704 void removeSelection( bool emitSignal = true );
00705
00706 void triggerRepaint();
00707
00711 virtual void updateExtents();
00712
00715 void checkJoinLayerRemove( QString theLayerId );
00716
00717 QString metadata();
00718
00719 signals:
00720
00722 void selectionChanged();
00723
00725 void layerModified( bool onlyGeometry );
00726
00727 void editingStarted();
00728 void editingStopped();
00729 void attributeAdded( int idx );
00730 void attributeDeleted( int idx );
00731 void featureAdded( QgsFeatureId fid );
00732 void featureDeleted( QgsFeatureId fid );
00733 void layerDeleted();
00734
00735 void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant & );
00736 void geometryChanged( QgsFeatureId fid, QgsGeometry &geom );
00737
00740 void committedAttributesDeleted( const QString& layerId, const QgsAttributeIds& deletedAttributeIds );
00741 void committedAttributesAdded( const QString& layerId, const QList<QgsField>& addedAttributes );
00742 void committedFeaturesAdded( const QString& layerId, const QgsFeatureList& addedFeatures );
00743 void committedFeaturesRemoved( const QString& layerId, const QgsFeatureIds& deletedFeatureIds );
00744 void committedAttributeValuesChanges( const QString& layerId, const QgsChangedAttributesMap& changedAttributesValues );
00745 void committedGeometriesChanges( const QString& layerId, const QgsGeometryMap& changedGeometries );
00746
00747 private:
00748
00750 QgsVectorLayer( QgsVectorLayer const & rhs );
00751
00753 QgsVectorLayer & operator=( QgsVectorLayer const & rhs );
00754
00759 bool setDataProvider( QString const & provider );
00760
00763 void drawFeature( QgsRenderContext &renderContext,
00764 QgsFeature& fet,
00765 QImage* marker );
00766
00768 void transformPoint( double& x, double& y,
00769 const QgsMapToPixel* mtp, const QgsCoordinateTransform* ct );
00770
00771 void transformPoints( std::vector<double>& x, std::vector<double>& y, std::vector<double>& z, QgsRenderContext &renderContext );
00772
00776 unsigned char *drawLineString( unsigned char *WKBlinestring, QgsRenderContext &renderContext );
00777
00781 unsigned char *drawPolygon( unsigned char *WKBpolygon, QgsRenderContext &renderContext );
00782
00784 QgsFeatureId findFreeId();
00785
00787 void deleteCachedGeometries();
00788
00797 void snapToGeometry( const QgsPoint& startPoint,
00798 QgsFeatureId featureId,
00799 QgsGeometry* geom,
00800 double sqrSnappingTolerance,
00801 QMultiMap<double, QgsSnappingResult>& snappingResults,
00802 QgsSnapper::SnappingType snap_to ) const;
00803
00806 int boundingBoxFromPointList( const QList<QgsPoint>& list, double& xmin, double& ymin, double& xmax, double& ymax ) const;
00807
00809 static QgsVectorLayer::VertexMarkerType currentVertexMarkerType();
00810
00812 static int currentVertexMarkerSize();
00813
00815 void updateFeatureAttributes( QgsFeature &f, bool all = false );
00816
00824 void addJoinedFeatureAttributes( QgsFeature& f, const QgsVectorJoinInfo& joinInfo, const QString& joinFieldName, const QVariant& joinValue,
00825 const QgsAttributeList& attributes, int attributeIndexOffset );
00826
00828 void updateFeatureGeometry( QgsFeature &f );
00829
00831 void editGeometryChange( QgsFeatureId featureId, QgsGeometry& geometry );
00832
00834 void editFeatureAdd( QgsFeature& feature );
00835
00837 void editFeatureDelete( QgsFeatureId featureId );
00838
00840 void editAttributeChange( QgsFeatureId featureId, int field, QVariant value );
00841
00843 void stopRendererV2( QgsRenderContext& rendererContext, QgsSingleSymbolRendererV2* selRenderer );
00844
00846 void updateAttributeMapIndex( QgsAttributeMap& map, int oldIndex, int newIndex ) const;
00847
00852 void prepareLabelingAndDiagrams( QgsRenderContext& rendererContext, QgsAttributeList& attributes, bool& labeling );
00853
00854 private:
00855
00859 int mUpdateThreshold;
00860
00862 QgsVectorDataProvider *mDataProvider;
00863
00865 QString mDisplayField;
00866
00868 QString mProviderKey;
00869
00871 QgsAttributeAction* mActions;
00872
00874 bool mEditable;
00875
00877 bool mReadOnly;
00878
00880 bool mModified;
00881
00883 QgsGeometryMap mCachedGeometries;
00884
00886 QgsRectangle mCachedGeometriesRect;
00887
00892 QgsFeatureIds mSelectedFeatureIds;
00893
00898 QgsFeatureIds mDeletedFeatureIds;
00899
00903 QgsFeatureList mAddedFeatures;
00904
00906 QgsChangedAttributesMap mChangedAttributeValues;
00907
00909 QgsAttributeIds mDeletedAttributeIds;
00910
00912 QgsAttributeIds mAddedAttributeIds;
00913
00915 QgsGeometryMap mChangedGeometries;
00916
00918 QgsFieldMap mUpdatedFields;
00919
00921 QMap< QString, QString > mAttributeAliasMap;
00922
00924 int mMaxUpdatedIndex;
00925
00927 int mWkbType;
00928
00929 QgsUndoCommand * mActiveCommand;
00930
00932 QgsRenderer *mRenderer;
00933
00935 QgsFeatureRendererV2 *mRendererV2;
00936
00938 bool mUsingRendererV2;
00939
00941 QgsLabel *mLabel;
00942
00944 bool mLabelOn;
00945
00947 QgsVectorLayer::VertexMarkerType mCurrentVertexMarkerType;
00948
00950 int mCurrentVertexMarkerSize;
00951
00953 bool mVertexMarkerOnlyForSelection;
00954
00956 QList<QgsVectorOverlay*> mOverlays;
00957
00958 QStringList mCommitErrors;
00959
00960 QMap< QString, EditType > mEditTypes;
00961 QMap< QString, QMap<QString, QVariant> > mValueMaps;
00962 QMap< QString, RangeData > mRanges;
00963 QMap< QString, QPair<QString, QString> > mCheckedStates;
00964 QMap< QString, ValueRelationData > mValueRelations;
00965
00966 QString mEditForm, mEditFormInit;
00967
00968 QString mAnnotationForm;
00969
00970 bool mFetching;
00971 QgsRectangle mFetchRect;
00972 QgsAttributeList mFetchAttributes;
00973 QgsAttributeList mFetchProvAttributes;
00974 bool mFetchGeometry;
00975
00976 QSet<QgsFeatureId> mFetchConsidered;
00977 QgsGeometryMap::iterator mFetchChangedGeomIt;
00978 QgsFeatureList::iterator mFetchAddedFeaturesIt;
00979
00980
00981 QgsVectorLayerJoinBuffer* mJoinBuffer;
00982
00983
00984 QgsDiagramRendererV2* mDiagramRenderer;
00985
00986
00987 QgsDiagramLayerSettings *mDiagramLayerSettings;
00988 };
00989
00990 #endif