00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef QGSVECTORLAYER_H
00020 #define QGSVECTORLAYER_H
00021
00022 #include <QMap>
00023 #include <QSet>
00024 #include <QList>
00025 #include <QStringList>
00026
00027 #include "qgis.h"
00028 #include "qgsmaplayer.h"
00029 #include "qgsfeature.h"
00030 #include "qgssnapper.h"
00031 #include "qgsfield.h"
00032
00033 class QPainter;
00034 class QImage;
00035
00036 class QgsAttributeAction;
00037 class QgsCoordinateTransform;
00038 class QgsGeometry;
00039 class QgsGeometryVertexIndex;
00040 class QgsMapToPixel;
00041 class QgsLabel;
00042 class QgsRectangle;
00043 class QgsRenderer;
00044 class QgsUndoCommand;
00045 class QgsVectorDataProvider;
00046 class QgsVectorOverlay;
00047 class QgsSingleSymbolRendererV2;
00048
00049 class QgsRectangle;
00050
00051 class QgsFeatureRendererV2;
00052
00053 typedef QList<int> QgsAttributeList;
00054 typedef QSet<int> QgsFeatureIds;
00055 typedef QSet<int> QgsAttributeIds;
00056
00057
00061 class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
00062 {
00063 Q_OBJECT
00064
00065 public:
00066 enum EditType
00067 {
00068 LineEdit,
00069 UniqueValues,
00070 UniqueValuesEditable,
00071 ValueMap,
00072 Classification,
00073 EditRange,
00074 SliderRange,
00075 CheckBox,
00076 FileName,
00077 Enumeration,
00078 Immutable,
00079 Hidden,
00080 TextEdit,
00081 Calendar,
00082 DialRange,
00083 };
00084
00085 struct RangeData
00086 {
00087 RangeData() {}
00088 RangeData( QVariant theMin, QVariant theMax, QVariant theStep )
00089 : mMin( theMin ), mMax( theMax ), mStep( theStep ) {}
00090
00091 QVariant mMin;
00092 QVariant mMax;
00093 QVariant mStep;
00094 };
00095
00097 QgsVectorLayer( QString path = QString::null, QString baseName = QString::null,
00098 QString providerLib = QString::null, bool loadDefaultStyleFlag = true );
00099
00101 virtual ~QgsVectorLayer();
00102
00104 QString storageType() const;
00105
00107 QString capabilitiesString() const;
00108
00110 QString dataComment() const;
00111
00113 void setDisplayField( QString fldName = "" );
00114
00116 const QString displayField() const;
00117
00119 QgsVectorDataProvider* dataProvider();
00120
00122 const QgsVectorDataProvider* dataProvider() const;
00123
00125 void setProviderEncoding( const QString& encoding );
00126
00128 void setCoordinateSystem();
00129
00131 QgsLabel *label();
00132
00133 const QgsLabel *label() const;
00134
00135 QgsAttributeAction* actions() { return mActions; }
00136
00138 int selectedFeatureCount();
00139
00141 void select( QgsRectangle & rect, bool lock );
00142
00144 void invertSelection();
00145
00147 void invertSelectionInRectangle( QgsRectangle & rect );
00148
00150 QgsFeatureList selectedFeatures();
00151
00153 const QgsFeatureIds& selectedFeaturesIds() const;
00154
00156 void setSelectedFeatures( const QgsFeatureIds& ids );
00157
00159 QgsRectangle boundingBoxOfSelected();
00160
00162 bool copySymbologySettings( const QgsMapLayer& other );
00163
00165 bool hasCompatibleSymbology( const QgsMapLayer& other ) const;
00166
00168 const QgsRenderer* renderer() const;
00169
00171 void setRenderer( QgsRenderer * r );
00172
00175 QgsFeatureRendererV2* rendererV2();
00179 void setRendererV2( QgsFeatureRendererV2* r );
00183 bool isUsingRendererV2();
00187 void setUsingRendererV2( bool usingRendererV2 );
00188
00192 void drawRendererV2( QgsRenderContext& rendererContext, bool labeling );
00193
00197 void drawRendererV2Levels( QgsRenderContext& rendererContext, bool labeling );
00198
00200 QGis::GeometryType geometryType() const;
00201
00203 QGis::WkbType wkbType() const;
00204
00206 QString providerType() const;
00207
00211 virtual bool readXml( QDomNode & layer_node );
00212
00216 virtual bool writeXml( QDomNode & layer_node, QDomDocument & doc );
00217
00223 bool readSymbology( const QDomNode& node, QString& errorMessage );
00224
00231 bool writeSymbology( QDomNode& node, QDomDocument& doc, QString& errorMessage ) const;
00232
00233
00241 virtual long featureCount() const;
00242
00246 virtual long updateFeatureCount() const;
00247
00255 virtual bool setSubsetString( QString subset );
00256
00261 virtual QString subsetString();
00262
00270 void select( QgsAttributeList fetchAttributes,
00271 QgsRectangle rect = QgsRectangle(),
00272 bool fetchGeometry = true,
00273 bool useIntersect = false );
00274
00280 bool nextFeature( QgsFeature& feature );
00281
00284 bool featureAtId( int featureId, QgsFeature &f, bool fetchGeometries = true, bool fetchAttributes = true );
00285
00291 bool addFeature( QgsFeature& f, bool alsoUpdateExtent = true );
00292
00293
00298 bool insertVertex( double x, double y, int atFeatureId, int beforeVertex );
00299
00304 bool moveVertex( double x, double y, int atFeatureId, int atVertex );
00305
00308 bool deleteVertex( int atFeatureId, int atVertex );
00309
00313 bool deleteSelectedFeatures();
00314
00323 int addRing( const QList<QgsPoint>& ring );
00324
00334 int addIsland( const QList<QgsPoint>& ring );
00335
00341 int translateFeature( int featureId, double dx, double dy );
00342
00347 int splitFeatures( const QList<QgsPoint>& splitLine, bool topologicalEditing = false );
00348
00353 int removePolygonIntersections( QgsGeometry* geom );
00354
00360 int addTopologicalPoints( QgsGeometry* geom );
00361
00368 int addTopologicalPoints( const QgsPoint& p );
00369
00374 int insertSegmentVerticesForSnap( const QList<QgsSnappingResult>& snapResults );
00375
00377 void enableLabels( bool on );
00378
00380 bool hasLabelsEnabled( void ) const;
00381
00383 virtual bool isEditable() const;
00384
00387 virtual bool isReadOnly() const;
00388
00390 virtual bool isModified() const;
00391
00397 bool snapPoint( QgsPoint& point, double tolerance );
00398
00406 int snapWithContext( const QgsPoint& startPoint,
00407 double snappingTolerance,
00408 QMultiMap < double,
00409 QgsSnappingResult > & snappingResults,
00410 QgsSnapper::SnappingType snap_to );
00411
00414 virtual void reload();
00415
00419 bool draw( QgsRenderContext& rendererContext );
00420
00422 void drawLabels( QgsRenderContext& rendererContext );
00423
00425 const QgsFieldMap &pendingFields() const;
00426
00428 QgsAttributeList pendingAllAttributesList();
00429
00431 int pendingFeatureCount();
00432
00437 bool setReadOnly( bool readonly = true );
00438
00440 void setModified( bool modified = true, bool onlyGeometryWasModified = false );
00441
00443 bool startEditing();
00444
00447 bool changeGeometry( int fid, QgsGeometry* geom );
00448
00450 bool changeAttributeValue( int fid, int field, QVariant value, bool emitSignal = true );
00451
00455 bool addAttribute( const QgsField &field );
00456
00460 bool addAttribute( QString name, QString type );
00461
00464 void addAttributeAlias( int attIndex, QString aliasString );
00465
00468 QString attributeAlias( int attributeIndex ) const;
00469
00472 QString attributeDisplayName( int attributeIndex ) const;
00473
00475 bool deleteAttribute( int attr );
00476
00478 bool addFeatures( QgsFeatureList features, bool makeSelected = true );
00479
00481 bool deleteFeature( int fid );
00482
00498 bool commitChanges();
00499 const QStringList &commitErrors();
00500
00502 bool rollBack();
00503
00505 EditType editType( int idx );
00506
00508 void setEditType( int idx, EditType edit );
00509
00511 void setCheckedState( int idx, QString checked, QString notChecked );
00512
00514 QPair<QString, QString> checkedState( int idx );
00515
00517 QString editForm();
00518
00520 void setEditForm( QString ui );
00521
00523 QString annotationForm() const { return mAnnotationForm; }
00524
00526 void setAnnotationForm( const QString& ui );
00527
00529 QString editFormInit();
00530
00532 void setEditFormInit( QString function );
00533
00535 QMap<QString, QVariant> &valueMap( int idx );
00536
00538 RangeData &range( int idx );
00539
00543 void addOverlay( QgsVectorOverlay* overlay );
00544
00548 void removeOverlay( const QString& typeName );
00549
00553 void vectorOverlays( QList<QgsVectorOverlay*>& overlayList );
00554
00558 QgsVectorOverlay* findOverlayByType( const QString& typeName );
00559
00560
00565 void beginEditCommand( QString text );
00566
00568 void endEditCommand();
00569
00571 void destroyEditCommand();
00572
00574 void undoEditCommand( QgsUndoCommand* cmd );
00575
00577 void redoEditCommand( QgsUndoCommand* cmd );
00578
00582 int fieldNameIndex( const QString& fieldName ) const;
00583
00586 enum VertexMarkerType
00587 {
00588 SemiTransparentCircle,
00589 Cross,
00590 NoMarker
00591 };
00592
00595 static void drawVertexMarker( double x, double y, QPainter& p, QgsVectorLayer::VertexMarkerType type, int vertexSize );
00596
00597 public slots:
00599 void select( int featureId, bool emitSignal = true );
00600
00602 void deselect( int featureId, bool emitSignal = true );
00603
00605 void removeSelection( bool emitSignal = true );
00606
00607 void triggerRepaint();
00608
00612 virtual void updateExtents();
00613
00614 signals:
00615
00617 void selectionChanged();
00618
00620 void layerModified( bool onlyGeometry );
00621
00622 void editingStarted();
00623 void editingStopped();
00624 void attributeAdded( int idx );
00625 void attributeDeleted( int idx );
00626 void featureDeleted( int fid );
00627 void layerDeleted();
00628
00629 void attributeValueChanged( int fid, int idx, const QVariant & );
00630
00632 void committedAttributesDeleted( const QString& layerId, const QgsAttributeIds& deletedAttributeIds );
00633 void committedAttributesAdded( const QString& layerId, const QList<QgsField>& addedAttributes );
00634 void committedFeaturesAdded( const QString& layerId, const QgsFeatureList& addedFeatures );
00635 void committedFeaturesRemoved( const QString& layerId, const QgsFeatureIds& deletedFeatureIds );
00636 void committedAttributeValuesChanges( const QString& layerId, const QgsChangedAttributesMap& changedAttributesValues );
00637 void committedGeometriesChanges( const QString& layerId, const QgsGeometryMap& changedGeometries );
00638
00639 private:
00640
00642 QgsVectorLayer( QgsVectorLayer const & rhs );
00643
00645 QgsVectorLayer & operator=( QgsVectorLayer const & rhs );
00646
00651 bool setDataProvider( QString const & provider );
00652
00655 void drawFeature( QgsRenderContext &renderContext,
00656 QgsFeature& fet,
00657 QImage* marker );
00658
00660 void transformPoint( double& x, double& y,
00661 const QgsMapToPixel* mtp, const QgsCoordinateTransform* ct );
00662
00663 void transformPoints( std::vector<double>& x, std::vector<double>& y, std::vector<double>& z, QgsRenderContext &renderContext );
00664
00668 unsigned char *drawLineString( unsigned char *WKBlinestring, QgsRenderContext &renderContext );
00669
00673 unsigned char *drawPolygon( unsigned char *WKBpolygon, QgsRenderContext &renderContext );
00674
00676 int findFreeId();
00677
00679 void deleteCachedGeometries();
00680
00689 void snapToGeometry( const QgsPoint& startPoint, int featureId, QgsGeometry* geom, double sqrSnappingTolerance,
00690 QMultiMap<double, QgsSnappingResult>& snappingResults, QgsSnapper::SnappingType snap_to ) const;
00691
00694 int boundingBoxFromPointList( const QList<QgsPoint>& list, double& xmin, double& ymin, double& xmax, double& ymax ) const;
00695
00697 static QgsVectorLayer::VertexMarkerType currentVertexMarkerType();
00698
00700 static int currentVertexMarkerSize();
00701
00703 void updateFeatureAttributes( QgsFeature &f, bool all = false );
00704
00706 void updateFeatureGeometry( QgsFeature &f );
00707
00709 void editGeometryChange( int featureId, QgsGeometry& geometry );
00710
00712 void editFeatureAdd( QgsFeature& feature );
00713
00715 void editFeatureDelete( int featureId );
00716
00718 void editAttributeChange( int featureId, int field, QVariant value );
00719
00721 void stopRendererV2( QgsRenderContext& rendererContext, QgsSingleSymbolRendererV2* selRenderer );
00722
00723 private:
00724
00728 int mUpdateThreshold;
00729
00731 QgsVectorDataProvider *mDataProvider;
00732
00734 QString mDisplayField;
00735
00737 QString mProviderKey;
00738
00740 QgsAttributeAction* mActions;
00741
00743 bool mEditable;
00744
00746 bool mReadOnly;
00747
00749 bool mModified;
00750
00752 QgsGeometryMap mCachedGeometries;
00753
00755 QgsRectangle mCachedGeometriesRect;
00756
00761 QgsFeatureIds mSelectedFeatureIds;
00762
00767 QgsFeatureIds mDeletedFeatureIds;
00768
00772 QgsFeatureList mAddedFeatures;
00773
00775 QgsChangedAttributesMap mChangedAttributeValues;
00776
00778 QgsAttributeIds mDeletedAttributeIds;
00779
00781 QgsAttributeIds mAddedAttributeIds;
00782
00784 QgsGeometryMap mChangedGeometries;
00785
00787 QgsFieldMap mUpdatedFields;
00788
00790 QMap<int, QString> mAttributeAliasMap;
00791
00793 int mMaxUpdatedIndex;
00794
00796 int mWkbType;
00797
00798 QgsUndoCommand * mActiveCommand;
00799
00801 QgsRenderer *mRenderer;
00802
00804 QgsFeatureRendererV2 *mRendererV2;
00805
00807 bool mUsingRendererV2;
00808
00810 QgsLabel *mLabel;
00811
00813 bool mLabelOn;
00814
00816 QgsVectorLayer::VertexMarkerType mCurrentVertexMarkerType;
00817
00819 int mCurrentVertexMarkerSize;
00820
00822 bool mVertexMarkerOnlyForSelection;
00823
00825 QList<QgsVectorOverlay*> mOverlays;
00826
00827 QStringList mCommitErrors;
00828
00829 QMap< QString, EditType > mEditTypes;
00830 QMap< QString, QMap<QString, QVariant> > mValueMaps;
00831 QMap< QString, RangeData > mRanges;
00832 QMap< QString, QPair<QString, QString> > mCheckedStates;
00833
00834 QString mEditForm, mEditFormInit;
00835
00836 QString mAnnotationForm;
00837
00838 bool mFetching;
00839 QgsRectangle mFetchRect;
00840 QgsAttributeList mFetchAttributes;
00841 QgsAttributeList mFetchProvAttributes;
00842 bool mFetchGeometry;
00843
00844 QSet<int> mFetchConsidered;
00845 QgsGeometryMap::iterator mFetchChangedGeomIt;
00846 QgsFeatureList::iterator mFetchAddedFeaturesIt;
00847 };
00848
00849 #endif