Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Store attributes and fields in vectors instead of maps
  • Loading branch information
wonder-sk committed Oct 20, 2012
1 parent 8bf9590 commit 51122d2
Show file tree
Hide file tree
Showing 134 changed files with 805 additions and 1,134 deletions.
20 changes: 10 additions & 10 deletions python/core/qgsexpression.sip
Expand Up @@ -14,7 +14,7 @@ class QgsExpression
QString parserErrorString() const;

//! Get the expression ready for evaluation - find out column indexes.
bool prepare( const QMap<int, QgsField> &fields );
bool prepare( const QgsFields &fields );

//! Get list of columns referenced by the expression
QStringList referencedColumns();
Expand All @@ -29,7 +29,7 @@ class QgsExpression

//! Evaluate the feature and return the result
//! @note this method does not expect that prepare() has been called on this instance
QVariant evaluate( QgsFeature* f, const QMap<int, QgsField>& fields );
QVariant evaluate( QgsFeature* f, const QgsFields& fields );

//! Returns true if an error occurred when evaluating last input
bool hasEvalError() const;
Expand Down Expand Up @@ -169,7 +169,7 @@ class QgsExpression

// abstract virtual preparation function
// errors are reported to the parent
virtual bool prepare( QgsExpression* parent, const QMap<int, QgsField> &fields ) = 0;
virtual bool prepare( QgsExpression* parent, const QgsFields &fields ) = 0;

virtual QString dump() const = 0;

Expand Down Expand Up @@ -224,7 +224,7 @@ class QgsExpression
QgsExpression::UnaryOperator op();
QgsExpression::Node* operand();

virtual bool prepare( QgsExpression* parent, const QMap<int, QgsField> &fields );
virtual bool prepare( QgsExpression* parent, const QgsFields &fields );
virtual QVariant eval( QgsExpression* parent, QgsFeature* f );
virtual QString dump() const;

Expand All @@ -246,7 +246,7 @@ class QgsExpression
QgsExpression::Node* opLeft();
QgsExpression::Node* opRight();

virtual bool prepare( QgsExpression* parent, const QMap<int, QgsField> &fields );
virtual bool prepare( QgsExpression* parent, const QgsFields &fields );
virtual QVariant eval( QgsExpression* parent, QgsFeature* f );
virtual QString dump() const;

Expand All @@ -268,7 +268,7 @@ class QgsExpression
bool isNotIn();
QgsExpression::NodeList* list();

virtual bool prepare( QgsExpression* parent, const QMap<int, QgsField> &fields );
virtual bool prepare( QgsExpression* parent, const QgsFields &fields );
virtual QVariant eval( QgsExpression* parent, QgsFeature* f );
virtual QString dump() const;

Expand All @@ -289,7 +289,7 @@ class QgsExpression
int fnIndex();
QgsExpression::NodeList* args();

virtual bool prepare( QgsExpression* parent, const QMap<int, QgsField> &fields );
virtual bool prepare( QgsExpression* parent, const QgsFields &fields );
virtual QVariant eval( QgsExpression* parent, QgsFeature* f );
virtual QString dump() const;

Expand All @@ -308,7 +308,7 @@ class QgsExpression

QVariant value();

virtual bool prepare( QgsExpression* parent, const QMap<int, QgsField> &fields );
virtual bool prepare( QgsExpression* parent, const QgsFields &fields );
virtual QVariant eval( QgsExpression* parent, QgsFeature* f );
virtual QString dump() const;

Expand All @@ -327,7 +327,7 @@ class QgsExpression

QString name();

virtual bool prepare( QgsExpression* parent, const QMap<int, QgsField> &fields );
virtual bool prepare( QgsExpression* parent, const QgsFields &fields );
virtual QVariant eval( QgsExpression* parent, QgsFeature* f );
virtual QString dump() const;

Expand Down Expand Up @@ -358,7 +358,7 @@ class QgsExpression
~NodeCondition();

virtual QVariant eval( QgsExpression* parent, QgsFeature* f );
virtual bool prepare( QgsExpression* parent, const QMap<int, QgsField> &fields );
virtual bool prepare( QgsExpression* parent, const QgsFields &fields );
virtual QString dump() const;

virtual void toOgcFilter( QDomDocument &doc, QDomElement &element ) const;
Expand Down
6 changes: 3 additions & 3 deletions python/core/qgsfeature.sip
Expand Up @@ -17,7 +17,7 @@ typedef QMap<int, QString> QgsFieldNameMap;
typedef QList<QgsFeature> QgsFeatureList;

typedef QMap<int, QgsField> QgsFieldMap;

typedef QVector<QgsField> QgsFields;

class QgsFeature
{
Expand Down Expand Up @@ -159,12 +159,12 @@ class QgsFeature
/** Assign a field map with the feature to allow attribute access by attribute name
* @note added in 2.0
*/
void setFieldMap( const QgsFieldMap* fields );
void setFields( const QgsFields* fields );

/** Get associated field map. may be NULL
* @note added in 2.0
*/
const QgsFieldMap* fieldMap() const;
const QgsFields* fields() const;

/** Insert a value into attribute. Returns false if attribute name could not be converted to index.
* Field map must be associated to make this work.
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsfeaturerequest.sip
Expand Up @@ -45,6 +45,6 @@ class QgsFeatureRequest
const QgsAttributeList& subsetOfAttributes() const;

//! Set a subset of attributes by names that will be fetched
QgsFeatureRequest& setSubsetOfAttributes( const QStringList& attrNames, const QgsFieldMap& fields );
QgsFeatureRequest& setSubsetOfAttributes( const QStringList& attrNames, const QgsFields& fields );

};
6 changes: 3 additions & 3 deletions python/core/qgslabel.sip
Expand Up @@ -7,7 +7,7 @@ class QgsLabel
%End

public:
QgsLabel( const QMap<int, QgsField> & fields );
QgsLabel( const QgsFields & fields );

~QgsLabel();

Expand Down Expand Up @@ -85,10 +85,10 @@ class QgsLabel
void addRequiredFields( QList<int> & fields ) const;

//! Set available fields
void setFields( const QMap<int, QgsField> & fields );
void setFields( const QgsFields & fields );

//! Available vector fields
QMap<int, QgsField> & fields();
const QgsFields & fields();

/** Pointer to default attributes.
* @deprecated in version 2 as it is badly named. Rather use attributes.
Expand Down
6 changes: 0 additions & 6 deletions python/core/qgsmaplayer.sip
Expand Up @@ -181,12 +181,6 @@ class QgsMapLayer : QObject
* @note Added in v1.4 */
void removeCustomProperty( const QString& key );

/** Copies the symbology settings from another layer. Returns true in case of success */
virtual bool copySymbologySettings( const QgsMapLayer& other ) = 0;

/** Returns true if this layer can be in the same symbology group with another layer */
virtual bool hasCompatibleSymbology( const QgsMapLayer& other ) const = 0;

/** Accessor for transparency level. */
unsigned int getTransparency();

Expand Down
7 changes: 1 addition & 6 deletions python/core/qgsvectordataprovider.sip
Expand Up @@ -78,17 +78,12 @@ class QgsVectorDataProvider : QgsDataProvider
*/
virtual long featureCount() const = 0;

/**
* Number of attribute fields for a feature in the layer
*/
virtual uint fieldCount() const = 0;

/**
* Return a map of indexes with field names for this layer
* @return map of fields
* @see QgsFieldMap
*/
virtual const QMap<int, QgsField> &fields() const = 0;
virtual const QgsFields &fields() const = 0;

/**
* Return a short comment for the data that this provider is
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsvectorfilewriter.sip
Expand Up @@ -57,7 +57,7 @@ class QgsVectorFileWriter
/** create shapefile and initialize it */
QgsVectorFileWriter( const QString& vectorFileName,
const QString& fileEncoding,
const QMap<int, QgsField>& fields,
const QgsFields& fields,
QGis::WkbType geometryType,
const QgsCoordinateReferenceSystem* srs,
const QString& driverName = "ESRI Shapefile",
Expand Down
8 changes: 1 addition & 7 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -180,12 +180,6 @@ class QgsVectorLayer : QgsMapLayer
/** Returns the bounding box of the selected features. If there is no selection, QgsRectangle(0,0,0,0) is returned */
QgsRectangle boundingBoxOfSelected();

/** Copies the symbology settings from another layer. Returns true in case of success */
bool copySymbologySettings( const QgsMapLayer& other );

/** Returns true if this layer can be in the same symbology group with another layer */
bool hasCompatibleSymbology( const QgsMapLayer& other ) const;

/** Returns a pointer to the renderer */
const QgsRenderer* renderer() const;

Expand Down Expand Up @@ -476,7 +470,7 @@ class QgsVectorLayer : QgsMapLayer
QgsRectangle extent();

/** returns field list in the to-be-committed state */
const QMap<int, QgsField> &pendingFields() const;
const QgsFields &pendingFields() const;

/** returns list of attributes */
QList<int> pendingAllAttributesList();
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsvectorlayerimport.sip
Expand Up @@ -43,7 +43,7 @@ class QgsVectorLayerImport
/** create a empty layer and add fields to it */
QgsVectorLayerImport( const QString &uri,
const QString &provider,
const QMap<int, QgsField> &fields,
const QgsFields &fields,
QGis::WkbType geometryType,
const QgsCoordinateReferenceSystem* crs,
bool overwrite = false,
Expand Down
13 changes: 5 additions & 8 deletions python/core/qgsvectorlayerjoinbuffer.sip
Expand Up @@ -16,15 +16,15 @@ class QgsVectorLayerJoinBuffer

/**Creates QgsVectorLayerJoinBuffer for the joins containing attributes to fetch*/
void select( const QgsAttributeList& fetchAttributes,
QgsAttributeList& sourceJoinFields, int maxProviderIndex );
QgsAttributeList& sourceJoinFields, int providerFieldCount );

/**Updates field map with joined attributes
@param fields map to append joined attributes
@param maxIndex in/out: maximum attribute index*/
void updateFieldMap( QMap<int, QgsField> &fields, int& maxIndex );
*/
void updateFields( QgsFields& fields );

/**Update feature with uncommited attribute updates and joined attributes*/
void updateFeatureAttributes( QgsFeature &f, int maxProviderIndex, bool all = false );
void updateFeatureAttributes( QgsFeature &f, int providerFieldCount, bool all = false );

/**Calls cacheJoinLayer() for all vector joins*/
void createJoinCaches();
Expand All @@ -47,9 +47,6 @@ class QgsVectorLayerJoinBuffer
@param maxProviderIndex maximum attribute index of the vectorlayer provider
@param indexOffset out: offset between layer index and original provider index
@return pointer to the join if the index belongs to a joined field, otherwise 0 (possibily provider field or added field)*/
const QgsVectorJoinInfo* joinForFieldIndex( int index, int maxProviderIndex, int& indexOffset ) const;
const QgsVectorJoinInfo* joinForFieldIndex( int index, int providerFieldCount, int& indexOffset ) const;

/** Helper function to find out the maximum index of a field map
@return true in case of success, otherwise false (e.g. empty map)*/
static bool maximumIndex( const QMap<int, QgsField> &fMap, int& index );
};
6 changes: 0 additions & 6 deletions python/core/raster/qgsrasterlayer.sip
Expand Up @@ -267,9 +267,6 @@ class QgsRasterLayer : QgsMapLayer

const QgsContrastEnhancement* constContrastEnhancement( unsigned int theBand ) const;

/**Copies the symbology settings from another layer. Returns true in case of success*/
bool copySymbologySettings( const QgsMapLayer& theOther );

/** \brief Get a pointer to the color table */
QList<QgsColorRampShader::ColorRampItem> colorTable( int theBandNoInt );

Expand Down Expand Up @@ -301,9 +298,6 @@ class QgsRasterLayer : QgsMapLayer
* */
QString drawingStyleAsString() const;

/** \brief Checks if symbology is the same as another layers */
bool hasCompatibleSymbology( const QgsMapLayer& theOther ) const;

/** \brief Identify raster value(s) found on the point position */
bool identify( const QgsPoint & point, QMap<QString, QString>& results /Out/ );

Expand Down
2 changes: 1 addition & 1 deletion python/gui/qgsexpressionbuilderwidget.sip
Expand Up @@ -82,7 +82,7 @@ class QgsExpressionBuilderWidget : QWidget
*/
void loadFieldNames();

void loadFieldNames( QMap<int, QgsField> fields );
void loadFieldNames( const QgsFields& fields );

/** Gets the expression string that has been set in the expression area.
* @returns The expression as a string. */
Expand Down
4 changes: 2 additions & 2 deletions src/analysis/interpolation/DualEdgeTriangulation.cc
Expand Up @@ -3083,8 +3083,8 @@ bool DualEdgeTriangulation::saveAsShapefile( const QString& fileName ) const
{
QString shapeFileName = fileName;

QgsFieldMap fields;
fields.insert( 0, QgsField( "type", QVariant::String, "String" ) );
QgsFields fields;
fields.append( QgsField( "type", QVariant::String, "String" ) );

// add the extension if not present
if ( shapeFileName.indexOf( ".shp" ) == -1 )
Expand Down
40 changes: 20 additions & 20 deletions src/analysis/vector/qgsgeometryanalyzer.cpp
Expand Up @@ -47,7 +47,7 @@ bool QgsGeometryAnalyzer::simplify( QgsVectorLayer* layer,
QGis::WkbType outputType = dp->geometryType();
const QgsCoordinateReferenceSystem crs = layer->crs();

QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), dp->fields(), outputType, &crs );
QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), layer->pendingFields(), outputType, &crs );
QgsFeature currentFeature;

//take only selection
Expand Down Expand Up @@ -163,7 +163,7 @@ bool QgsGeometryAnalyzer::centroids( QgsVectorLayer* layer, const QString& shape
QGis::WkbType outputType = QGis::WKBPoint;
const QgsCoordinateReferenceSystem crs = layer->crs();

QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), dp->fields(), outputType, &crs );
QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), layer->pendingFields(), outputType, &crs );
QgsFeature currentFeature;

//take only selection
Expand Down Expand Up @@ -279,17 +279,17 @@ bool QgsGeometryAnalyzer::extent( QgsVectorLayer* layer,
QGis::WkbType outputType = QGis::WKBPolygon;
const QgsCoordinateReferenceSystem crs = layer->crs();

QgsFieldMap fields;
fields.insert( 0 , QgsField( QString( "MINX" ), QVariant::Double ) );
fields.insert( 1 , QgsField( QString( "MINY" ), QVariant::Double ) );
fields.insert( 2 , QgsField( QString( "MAXX" ), QVariant::Double ) );
fields.insert( 3 , QgsField( QString( "MAXY" ), QVariant::Double ) );
fields.insert( 4 , QgsField( QString( "CNTX" ), QVariant::Double ) );
fields.insert( 5 , QgsField( QString( "CNTY" ), QVariant::Double ) );
fields.insert( 6 , QgsField( QString( "AREA" ), QVariant::Double ) );
fields.insert( 7 , QgsField( QString( "PERIM" ), QVariant::Double ) );
fields.insert( 8 , QgsField( QString( "HEIGHT" ), QVariant::Double ) );
fields.insert( 9 , QgsField( QString( "WIDTH" ), QVariant::Double ) );
QgsFields fields;
fields.append( QgsField( QString( "MINX" ), QVariant::Double ) );
fields.append( QgsField( QString( "MINY" ), QVariant::Double ) );
fields.append( QgsField( QString( "MAXX" ), QVariant::Double ) );
fields.append( QgsField( QString( "MAXY" ), QVariant::Double ) );
fields.append( QgsField( QString( "CNTX" ), QVariant::Double ) );
fields.append( QgsField( QString( "CNTY" ), QVariant::Double ) );
fields.append( QgsField( QString( "AREA" ), QVariant::Double ) );
fields.append( QgsField( QString( "PERIM" ), QVariant::Double ) );
fields.append( QgsField( QString( "HEIGHT" ), QVariant::Double ) );
fields.append( QgsField( QString( "WIDTH" ), QVariant::Double ) );

QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), fields, outputType, &crs );

Expand Down Expand Up @@ -404,10 +404,10 @@ bool QgsGeometryAnalyzer::convexHull( QgsVectorLayer* layer, const QString& shap
{
useField = true;
}
QgsFieldMap fields;
fields.insert( 0 , QgsField( QString( "UID" ), QVariant::String ) );
fields.insert( 1 , QgsField( QString( "AREA" ), QVariant::Double ) );
fields.insert( 2 , QgsField( QString( "PERIM" ), QVariant::Double ) );
QgsFields fields;
fields.append( QgsField( QString( "UID" ), QVariant::String ) );
fields.append( QgsField( QString( "AREA" ), QVariant::Double ) );
fields.append( QgsField( QString( "PERIM" ), QVariant::Double ) );

QGis::WkbType outputType = QGis::WKBPolygon;
const QgsCoordinateReferenceSystem crs = layer->crs();
Expand Down Expand Up @@ -618,7 +618,7 @@ bool QgsGeometryAnalyzer::dissolve( QgsVectorLayer* layer, const QString& shapef
QGis::WkbType outputType = dp->geometryType();
const QgsCoordinateReferenceSystem crs = layer->crs();

QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), dp->fields(), outputType, &crs );
QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), layer->pendingFields(), outputType, &crs );
QgsFeature currentFeature;
QMultiMap<QString, QgsFeatureId> map;

Expand Down Expand Up @@ -771,7 +771,7 @@ bool QgsGeometryAnalyzer::buffer( QgsVectorLayer* layer, const QString& shapefil
}
const QgsCoordinateReferenceSystem crs = layer->crs();

QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), dp->fields(), outputType, &crs );
QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), layer->pendingFields(), outputType, &crs );
QgsFeature currentFeature;
QgsGeometry *dissolveGeometry = 0; //dissolve geometry (if dissolve enabled)

Expand Down Expand Up @@ -951,7 +951,7 @@ bool QgsGeometryAnalyzer::eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer*
}
else
{
memoryProvider->addAttributes( eventLayer->pendingFields().values() );
memoryProvider->addAttributes( eventLayer->pendingFields().toList() );
}

//iterate over eventLayer and write new features to output file or layer
Expand Down

0 comments on commit 51122d2

Please sign in to comment.