src/core/qgsvectorlayer.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           qgsvectorlayer.h  -  description
00003                              -------------------
00004     begin                : Oct 29, 2003
00005     copyright            : (C) 2003 by Gary E.Sherman
00006     email                : sherman at mrcc.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 /* $Id: qgsvectorlayer.h 9781 2008-12-13 11:07:45Z jef $ */
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 "qgsfeature.h"
00032 #include "qgsfield.h"
00033 
00034 class QPainter;
00035 class QImage;
00036 
00037 class QgsAttributeAction;
00038 class QgsCoordinateTransform;
00039 class QgsGeometry;
00040 class QgsGeometryVertexIndex;
00041 class QgsMapToPixel;
00042 class QgsLabel;
00043 class QgsRectangle;
00044 class QgsRenderer;
00045 class QgsVectorDataProvider;
00046 
00047 class QgsGeometry;
00048 class QgsRectangle;
00049 
00050 typedef QList<int> QgsAttributeList;
00051 typedef QSet<int> QgsFeatureIds;
00052 typedef QSet<int> QgsAttributeIds;
00053 
00057 class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
00058 {
00059     Q_OBJECT
00060 
00061   public:
00062     enum EditType
00063     {
00064       LineEdit,
00065       UniqueValues,
00066       UniqueValuesEditable,
00067       ValueMap,
00068       Classification,
00069       EditRange,
00070       SliderRange,
00071       FileName
00072     };
00073 
00074     struct RangeData
00075     {
00076       RangeData() {}
00077       RangeData( QVariant theMin, QVariant theMax, QVariant theStep )
00078           : mMin( theMin ), mMax( theMax ), mStep( theStep ) {}
00079 
00080       QVariant mMin;
00081       QVariant mMax;
00082       QVariant mStep;
00083     };
00084 
00086     QgsVectorLayer( QString path = 0, QString baseName = 0,
00087                     QString providerLib = 0, bool loadDefaultStyleFlag = true );
00088 
00090     virtual ~QgsVectorLayer();
00091 
00093     QString storageType() const;
00094 
00096     QString capabilitiesString() const;
00097 
00099     QString dataComment() const;
00100 
00102     void setDisplayField( QString fldName = 0 );
00103 
00105     const QString displayField() const;
00106 
00108     QgsVectorDataProvider* dataProvider();
00109 
00111     const QgsVectorDataProvider* dataProvider() const;
00112 
00114     void setProviderEncoding( const QString& encoding );
00115 
00117     void setCoordinateSystem();
00118 
00120     QgsLabel *label();
00121 
00122     const QgsLabel *label() const;
00123 
00124     QgsAttributeAction* actions() { return mActions; }
00125 
00127     int selectedFeatureCount();
00128 
00130     void select( QgsRectangle & rect, bool lock );
00131 
00133     void invertSelection();
00134 
00136     void invertSelectionInRectangle( QgsRectangle & rect );
00137 
00139     QgsFeatureList selectedFeatures();
00140 
00142     const QgsFeatureIds& selectedFeaturesIds() const;
00143 
00145     void setSelectedFeatures( const QgsFeatureIds& ids );
00146 
00148     QgsRectangle boundingBoxOfSelected();
00149 
00151     bool copySymbologySettings( const QgsMapLayer& other );
00152 
00154     bool hasCompatibleSymbology( const QgsMapLayer& other ) const;
00155 
00157     const QgsRenderer* renderer() const;
00158 
00160     void setRenderer( QgsRenderer * r );
00161 
00163     QGis::GeometryType geometryType() const;
00164 
00166     QGis::WkbType wkbType() const;
00167 
00169     QString providerType() const;
00170 
00174     virtual bool readXml( QDomNode & layer_node );
00175 
00179     virtual bool writeXml( QDomNode & layer_node, QDomDocument & doc );
00180 
00186     bool readSymbology( const QDomNode& node, QString& errorMessage );
00187 
00194     bool writeSymbology( QDomNode&, QDomDocument& doc, QString& errorMessage ) const;
00195 
00196 
00204     virtual long featureCount() const;
00205 
00209     virtual long updateFeatureCount() const;
00210 
00217     virtual void setSubsetString( QString subset );
00218 
00223     virtual QString subsetString();
00224 
00225     void select( QgsAttributeList fetchAttributes,
00226                  QgsRectangle rect = QgsRectangle(),
00227                  bool fetchGeometry = true,
00228                  bool useIntersect = false );
00229 
00230     bool nextFeature( QgsFeature& feature );
00231 
00234     bool featureAtId( int featureId, QgsFeature &f, bool fetchGeometries = true, bool fetchAttributes = true );
00235 
00240     bool addFeature( QgsFeature& f, bool alsoUpdateExtent = TRUE );
00241 
00242 
00247     bool insertVertex( double x, double y, int atFeatureId, int beforeVertex );
00248 
00253     bool moveVertex( double x, double y, int atFeatureId, int atVertex );
00254 
00257     bool deleteVertex( int atFeatureId, int atVertex );
00258 
00262     bool deleteSelectedFeatures();
00263 
00272     int addRing( const QList<QgsPoint>& ring );
00273 
00283     int addIsland( const QList<QgsPoint>& ring );
00284 
00290     int translateFeature( int featureId, double dx, double dy );
00291 
00296     int splitFeatures( const QList<QgsPoint>& splitLine, bool topologicalEditing = false );
00297 
00302     int removePolygonIntersections( QgsGeometry* geom );
00303 
00309     int addTopologicalPoints( QgsGeometry* geom );
00310 
00317     int addTopologicalPoints( const QgsPoint& p );
00318 
00323     int insertSegmentVerticesForSnap( const QList<QgsSnappingResult>& snapResults );
00324 
00326     void enableLabels( bool on );
00327 
00329     bool hasLabelsEnabled( void ) const;
00330 
00332     virtual bool isEditable() const;
00333 
00335     virtual bool isModified() const;
00336 
00342     bool snapPoint( QgsPoint& point, double tolerance );
00343 
00351     int snapWithContext( const QgsPoint& startPoint,
00352                          double snappingTolerance,
00353                          QMultiMap < double,
00354                          QgsSnappingResult > & snappingResults,
00355                          QgsSnapper::SnappingType snap_to );
00356 
00360     bool draw( QgsRenderContext& rendererContext );
00361 
00363     void drawLabels( QgsRenderContext& rendererContext );
00364 
00366     const QgsFieldMap &pendingFields() const;
00367 
00369     QgsAttributeList pendingAllAttributesList();
00370 
00372     int pendingFeatureCount();
00373 
00375     void setModified( bool modified = TRUE, bool onlyGeometryWasModified = FALSE );
00376 
00378     bool startEditing();
00379 
00381     bool changeAttributeValue( int fid, int field, QVariant value, bool emitSignal = true );
00382 
00385     bool addAttribute( QString name, QString type );
00386 
00388     bool deleteAttribute( int attr );
00389 
00391     bool addFeatures( QgsFeatureList features, bool makeSelected = TRUE );
00392 
00394     bool deleteFeature( int fid );
00395 
00411     bool commitChanges();
00412     const QStringList &commitErrors();
00413 
00415     bool rollBack();
00416 
00418     EditType editType( int idx );
00419 
00421     void setEditType( int idx, EditType edit );
00422 
00424     QMap<QString, QVariant> &valueMap( int idx );
00425 
00427     RangeData &range( int idx );
00428 
00429   public slots:
00431     void select( int featureId, bool emitSignal = TRUE );
00432 
00434     void deselect( int featureId, bool emitSignal = TRUE );
00435 
00437     void removeSelection( bool emitSignal = TRUE );
00438 
00439     void triggerRepaint();
00440 
00444     virtual void updateExtents();
00445 
00446   signals:
00447 
00449     void selectionChanged();
00450 
00452     void layerModified( bool onlyGeometry );
00453 
00454     void editingStarted();
00455     void editingStopped();
00456     void attributeAdded( int idx );
00457     void attributeDeleted( int idx );
00458     void featureDeleted( int fid );
00459     void layerDeleted();
00460 
00461     void attributeValueChanged( int fid, int idx, const QVariant & );
00462 
00463   private:                       // Private methods
00464 
00465     enum VertexMarkerType
00466     {
00467       SemiTransparentCircle,
00468       Cross
00469     };
00470 
00472     QgsVectorLayer( QgsVectorLayer const & rhs );
00473 
00475     QgsVectorLayer & operator=( QgsVectorLayer const & rhs );
00476 
00481     bool setDataProvider( QString const & provider );
00482 
00486     void drawFeature( QPainter* p,
00487                       QgsFeature& fet,
00488                       const QgsMapToPixel* cXf,
00489                       const QgsCoordinateTransform* ct,
00490                       QImage* marker,
00491                       double widthScale,
00492                       double markerScaleFactor,
00493                       bool drawingToEditingCanvas );
00494 
00496     void transformPoint( double& x, double& y,
00497                          const QgsMapToPixel* mtp, const QgsCoordinateTransform* ct );
00498 
00499     void transformPoints( std::vector<double>& x, std::vector<double>& y, std::vector<double>& z,
00500                           const QgsMapToPixel* mtp, const QgsCoordinateTransform* ct );
00501 
00505     unsigned char *drawLineString( unsigned char *WKBlinestring,
00506                                    QPainter *p,
00507                                    const QgsMapToPixel *mtp,
00508                                    const QgsCoordinateTransform *ct,
00509                                    bool drawingToEditingCanvas );
00510 
00514     unsigned char *drawPolygon( unsigned char *WKBpolygon,
00515                                 QPainter *p,
00516                                 const QgsMapToPixel *mtp,
00517                                 const QgsCoordinateTransform *ct,
00518                                 bool drawingToEditingCanvas );
00519 
00521     int findFreeId();
00522 
00524     void deleteCachedGeometries();
00525 
00527     void drawVertexMarker( int x, int y, QPainter& p, QgsVectorLayer::VertexMarkerType type );
00528 
00536     void snapToGeometry( const QgsPoint& startPoint, int featureId, QgsGeometry* geom, double sqrSnappingTolerance,
00537                          QMultiMap<double, QgsSnappingResult>& snappingResults, QgsSnapper::SnappingType snap_to ) const;
00538 
00541     int boundingBoxFromPointList( const QList<QgsPoint>& list, double& xmin, double& ymin, double& xmax, double& ymax ) const;
00542 
00544     QgsVectorLayer::VertexMarkerType currentVertexMarkerType();
00545 
00547     void updateFeatureAttributes( QgsFeature &f );
00548 
00550     void updateFeatureGeometry( QgsFeature &f );
00551 
00552   private:                       // Private attributes
00553 
00557     int mUpdateThreshold;
00558 
00560     QgsVectorDataProvider *mDataProvider;
00561 
00563     QString mDisplayField;
00564 
00566     QString mProviderKey;
00567 
00569     QgsAttributeAction* mActions;
00570 
00572     bool mEditable;
00573 
00575     bool mModified;
00576 
00578     QgsGeometryMap mCachedGeometries;
00579 
00584     QgsFeatureIds mSelectedFeatureIds;
00585 
00590     QgsFeatureIds mDeletedFeatureIds;
00591 
00595     QgsFeatureList mAddedFeatures;
00596 
00598     QgsChangedAttributesMap mChangedAttributeValues;
00599 
00601     QgsAttributeIds mDeletedAttributeIds;
00602 
00604     QgsAttributeIds mAddedAttributeIds;
00605 
00607     QgsGeometryMap mChangedGeometries;
00608 
00610     QgsFieldMap mUpdatedFields;
00611 
00613     int mMaxUpdatedIndex;
00614 
00616     int mWkbType;
00617 
00619     QgsRenderer *mRenderer;
00620 
00622     QgsLabel *mLabel;
00623 
00625     bool mLabelOn;
00626 
00627     QStringList mCommitErrors;
00628 
00629     QMap< QString, EditType > mEditTypes;
00630     QMap< QString, QMap<QString, QVariant> > mValueMaps;
00631     QMap< QString, RangeData > mRanges;
00632 
00633     bool mFetching;
00634     QgsRectangle mFetchRect;
00635     QgsAttributeList mFetchAttributes;
00636     bool mFetchGeometry;
00637 
00638     QSet<int> mFetchConsidered;
00639     QgsGeometryMap::iterator mFetchChangedGeomIt;
00640     QgsFeatureList::iterator mFetchAddedFeaturesIt;
00641 };
00642 
00643 #endif

Generated on Fri Jan 9 16:51:13 2009 for Quantum GIS API Documentation by  doxygen 1.5.1