20 changes: 10 additions & 10 deletions python/core/qgsexpression.sip
Original file line number Diff line number Diff line change
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 @@ -177,7 +177,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 @@ -232,7 +232,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 @@ -254,7 +254,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 @@ -276,7 +276,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 @@ -297,7 +297,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 @@ -316,7 +316,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 @@ -335,7 +335,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 @@ -366,7 +366,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
134 changes: 81 additions & 53 deletions python/core/qgsfeature.sip
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// key = field index, value = field value
typedef QMap<int, QVariant> QgsAttributeMap;

typedef QVector<QVariant> QgsAttributes;

// key = feature id, value = changed attributes
typedef QMap<qint64, QMap<int, QVariant> > QgsChangedAttributesMap;

Expand All @@ -14,6 +16,7 @@ typedef QMap<int, QString> QgsFieldNameMap;

typedef QList<QgsFeature> QgsFeatureList;

typedef QMap<int, QgsField> QgsFieldMap;

class QgsFeature
{
Expand All @@ -28,32 +31,63 @@ class QgsFeature

SIP_PYOBJECT __getitem__(int key);
%MethodCode
const QgsAttributeMap& attrMap = sipCpp->attributeMap();
QgsAttributeMap::const_iterator it = attrMap.find(a0);
if (it == attrMap.end())
const QgsAttributes& attrs = sipCpp->attributes();
if (a0 < 0 || a0 >= attrs.count())
PyErr_SetString(PyExc_KeyError, QByteArray::number(a0));
else
{
QVariant* v = new QVariant(it.value());
QVariant* v = new QVariant(attrs[a0]);
sipRes = sipConvertFromInstance(v, sipClass_QVariant, Py_None);
}
%End

SIP_PYOBJECT __getitem__(const QString& name);
%MethodCode
int fieldIdx = sipCpp->fieldNameIndex(*a0);
if (fieldIdx == -1)
PyErr_SetString(PyExc_KeyError, a0->toAscii());
else
{
QVariant* v = new QVariant( sipCpp->attribute(fieldIdx) );
sipRes = sipConvertFromInstance(v, sipClass_QVariant, Py_None);
}
%End

void __setitem__(int key, QVariant value);
%MethodCode
sipCpp->addAttribute(a0, *a1);
sipCpp->setAttribute(a0, *a1);
%End

void __setitem__(const QString& key, QVariant value);
%MethodCode
int fieldIdx = sipCpp->fieldNameIndex(*a0);
if (fieldIdx == -1)
PyErr_SetString(PyExc_KeyError, a0->toAscii());
else
{
sipCpp->setAttribute(fieldIdx, *a1);
}
%End

void __delitem__(int key);
%MethodCode
if (sipCpp->attributeMap().contains(a0))
if (a0 >= 0 && a0 < sipCpp->attributes().count())
sipCpp->deleteAttribute(a0);
else
PyErr_SetString(PyExc_KeyError, QByteArray::number(a0));
%End

void __delitem__(const QString& name);
%MethodCode
int fieldIdx = sipCpp->fieldNameIndex(*a0);
if (fieldIdx == -1)
PyErr_SetString(PyExc_KeyError, a0->toAscii());
else
sipCpp->deleteAttribute(fieldIdx);
%End

//! Constructor
QgsFeature( qint64 id = 0, QString typeName = "" );
QgsFeature( qint64 id = 0 );

/** copy ctor needed due to internal pointer */
QgsFeature( const QgsFeature & rhs );
Expand All @@ -73,44 +107,15 @@ class QgsFeature
*/
void setFeatureId( qint64 id );


/** returns the feature's type name
*/
QString typeName() const;


/** sets the feature's type name
*/
void setTypeName( QString typeName );

/**
* Get the attributes for this feature.
* @return A std::map containing the field name/value mapping
*/
const QMap<int, QVariant> & attributeMap() const;


/**Sets all the attributes in one go*/
void setAttributeMap( const QMap<int, QVariant> & attributeMap );

/** Clear attribute map
* added in 1.5
*/
void clearAttributeMap();

/**
* Add an attribute to the map
*/
void addAttribute( int field, QVariant attr );
const QgsAttributes& attributes() const;
//QgsAttributes& attributes();
void setAttributes(const QgsAttributes& attrs);
void setAttribute( int field, const QVariant& attr );
void initAttributes( int fieldCount );

/**Deletes an attribute and its value*/
void deleteAttribute( int field );

/**Changes an existing attribute value
@param field index of the field
@param attr attribute name and value to be set */
void changeAttribute( int field, QVariant attr );

/**
* Return the validity of this feature. This is normally set by
* the provider to indicate some problem that makes the feature
Expand All @@ -123,18 +128,6 @@ class QgsFeature
*/
void setValid( bool validity );

/**
* Return the dirty state of this feature.
* Dirty is set if (e.g.) the feature's geometry has been modified in-memory.
*/
bool isDirty() const;

/**
* Reset the dirtiness of the feature. (i.e. make clean)
* You would normally do this after it's saved to permanent storage (e.g. disk, an ACID-compliant database)
*/
void clean();

/**
* Get the geometry object associated with this feature
*/
Expand Down Expand Up @@ -162,5 +155,40 @@ class QgsFeature
*/
void setGeometryAndOwnership( unsigned char * geom /Transfer/, size_t length );

/** Assign a field map with the feature to allow attribute access by attribute name
* @note added in 2.0
*/
void setFields( const QgsFields* fields );

/** Get associated field map. may be NULL
* @note added in 2.0
*/
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.
* @note added in 2.0
*/
bool setAttribute( const QString& name, QVariant value );

/** Remove an attribute value. Returns false if attribute name could not be converted to index.
* Field map must be associated to make this work.
* @note added in 2.0
*/
bool deleteAttribute( const QString& name );

/** Lookup attribute value from attribute name. Returns invalid variant if attribute name could not be converted to index.
* Field map must be associated to make this work.
* @note added in 2.0
*/
QVariant attribute( const QString& name ) const;

/** Utility method to get attribute index from name. Returns -1 if field does not exist or field map is not associated.
* Field map must be associated to make this work.
* @note added in 2.0
*/
int fieldNameIndex( const QString& fieldName ) const;


}; // class QgsFeature

47 changes: 47 additions & 0 deletions python/core/qgsfeatureiterator.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@


class QgsFeatureIterator
{
%TypeHeaderCode
#include <qgsfeatureiterator.h>
%End

public:


QgsFeatureIterator* __iter__();
%MethodCode
sipRes = sipCpp;
%End

SIP_PYOBJECT __next__();
%MethodCode
QgsFeature* f = new QgsFeature;
if (sipCpp->nextFeature(*f))
sipRes = sipConvertFromInstance(f, sipClass_QgsFeature, Py_None);
else
{
delete f;
PyErr_SetString(PyExc_StopIteration,"");
}
%End


//! construct invalid iterator
QgsFeatureIterator();
//! construct a valid iterator
//QgsFeatureIterator(QgsAbstractFeatureIterator* iter);
//! copy constructor copies the iterator, increases ref.count
QgsFeatureIterator(const QgsFeatureIterator& fi);
//! destructor deletes the iterator if it has no more references
~QgsFeatureIterator();

//QgsFeatureIterator& operator=(const QgsFeatureIterator& other);

bool nextFeature(QgsFeature& f);
bool rewind();
bool close();

//! find out whether the iterator is still valid or closed already
bool isClosed();
};
50 changes: 50 additions & 0 deletions python/core/qgsfeaturerequest.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

class QgsFeatureRequest
{
%TypeHeaderCode
#include <qgsfeaturerequest.h>
%End

public:
enum Flag
{
NoGeometry = 0x01, //!< Do not fetch geometry
SubsetOfAttributes = 0x02, //!< Fetch only a subset of attributes (setSubsetOfAttributes sets this flag)
ExactIntersect = 0x04 //!< Use exact geometry intersection (slower) instead of bounding boxes
};
typedef QFlags<QgsFeatureRequest::Flag> Flags;

enum FilterType
{
FilterNone, //!< No filter is applied
FilterRect, //!< Filter using a rectangle
FilterFid //!< Filter using feature ID
};

//! construct a default request: for all features get attributes and geometries
QgsFeatureRequest();

FilterType filterType() const;

//! Set rectangle from which features will be taken. Empty rectangle removes the filter.
//!
QgsFeatureRequest& setFilterRect( const QgsRectangle& rect );
const QgsRectangle& filterRect() const;

//! Set feature ID that should be fetched.
QgsFeatureRequest& setFilterFid( qint64 fid );
const qint64& filterFid() const;

//! Set flags that affect how features will be fetched
QgsFeatureRequest& setFlags( Flags flags );
const Flags& flags() const;

//! Set a subset of attributes that will be fetched. Empty list means that all attributes are used.
//! To disable fetching attributes, reset the FetchAttributes flag (which is set by default)
QgsFeatureRequest& setSubsetOfAttributes( const QgsAttributeList& attrs );
const QgsAttributeList& subsetOfAttributes() const;

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

};
66 changes: 66 additions & 0 deletions python/core/qgsfield.sip
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public:
~QgsField();

bool operator==( const QgsField& other ) const;
bool operator!=( const QgsField& other ) const;

//! Gets the name of the field
const QString & name() const;
Expand Down Expand Up @@ -108,3 +109,68 @@ public:
void setComment( const QString & comment );

}; // class QgsField



class QgsFields
{
%TypeHeaderCode
#include <qgsfield.h>
%End

public:

enum FieldOrigin { OriginUnknown, OriginProvider, OriginJoin, OriginEdit };

void clear();
void append( const QgsField& field, FieldOrigin origin = OriginProvider, int originIndex = -1 );
void remove( int fieldIdx );

bool isEmpty() const;
int count() const /__len__/;
int size() const;
//const QgsField& operator[](int i) const;
//QgsField& operator[](int i);
const QgsField& at(int i) const;
QList<QgsField> toList() const;

const QgsField& field( int fieldIdx ) const;
const QgsField& field( const QString& name ) const;
FieldOrigin fieldOrigin( int fieldIdx ) const;
int fieldOriginIndex( int fieldIdx ) const;

int indexFromName( const QString& name ) const;


QgsField& operator[](int i);
%MethodCode
int idx = (int)sipConvertFromSequenceIndex(a0, sipCpp->count());
if (idx < 0)
sipIsErr = 1;
else
sipRes = new QgsField(sipCpp->operator[](idx));
%End

/* SIP_PYOBJECT __getitem__(int key);
%MethodCode
if (a0 = sipConvertFromSequenceIndex(a0, sipCpp->count()) < 0)
sipIsErr = 1;
else
{
qDebug("__getitem__ %d", a0);
QgsField* fld = new QgsField(sipCpp->at(a0));
sipRes = sipConvertFromInstance(fld, sipClass_QgsField, Py_None);
}
%End*/

void __setitem__(int key, const QgsField& field);
%MethodCode
int idx = (int)sipConvertFromSequenceIndex(a0, sipCpp->count());
if (idx < 0)
sipIsErr = 1;
else
(*sipCpp)[idx] = *a1;
%End

};

6 changes: 3 additions & 3 deletions python/core/qgslabel.sip
Original file line number Diff line number Diff line change
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 @@ -67,10 +67,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.
* @note this replaces the to-be-deprecated layerAttributes method.
Expand Down
6 changes: 0 additions & 6 deletions python/core/qgsmaplayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,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
71 changes: 12 additions & 59 deletions python/core/qgsvectordataprovider.sip
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,6 @@ class QgsVectorDataProvider : QgsDataProvider

public:

QgsVectorDataProvider* __iter__();
%MethodCode
sipRes = sipCpp;
%End

SIP_PYOBJECT __next__();
%MethodCode
QgsFeature* f = new QgsFeature;
if (sipCpp->nextFeature(*f))
sipRes = sipConvertFromInstance(f, sipClass_QgsFeature, Py_None);
else
{
delete f;
PyErr_SetString(PyExc_StopIteration,"");
}
%End

// If you add to this, please also add to capabilitiesString()
/**
* enumeration with capabilities that providers might implement
Expand Down Expand Up @@ -66,40 +49,10 @@ class QgsVectorDataProvider : QgsDataProvider
*/
virtual QString storageType() const;

/** Select features based on a bounding rectangle. Features can be retrieved with calls to nextFeature.
* @param fetchAttributes list of attributes which should be fetched
* @param rect spatial filter
* @param fetchGeometry true if the feature geometry should be fetched
* @param useIntersect true if an accurate intersection test should be used,
* false if a test based on bounding box is sufficient
*/
virtual void select( QList<int> fetchAttributes = QList<int>(),
QgsRectangle rect = QgsRectangle(),
bool fetchGeometry = true,
bool useIntersect = false ) = 0;

/**
* Gets the feature at the given feature ID.
* @param featureId id of the feature
* @param feature feature which will receive the data
* @param fetchGeometry if true, geometry will be fetched from the provider
* @param fetchAttributes a list containing the indexes of the attribute fields to copy
* @return True when feature was found, otherwise false
*
* Default implementation traverses all features until it finds the one with correct ID.
* In case the provider supports reading the feature directly, override this function.
* Query the provider for features specified in request.
*/
virtual bool featureAtId( qint64 featureId,
QgsFeature& feature,
bool fetchGeometry = true,
QList<int> fetchAttributes = QList<int>());

/**
* Get the next feature resulting from a select operation.
* @param feature feature which will receive data from the provider
* @return true when there was a feature to fetch, false when end was hit
*/
virtual bool nextFeature( QgsFeature& feature ) = 0;
virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request = QgsFeatureRequest() ) = 0;

/**
* Get feature type.
Expand All @@ -113,27 +66,19 @@ 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
* providing access to (e.g. the comment for postgres table).
*/
virtual QString dataComment() const;

/** Restart reading features from previous select operation */
virtual void rewind() = 0;

/**
* Returns the minimum value of an attribute
* @param index the index of the attribute
Expand Down Expand Up @@ -277,7 +222,15 @@ class QgsVectorDataProvider : QgsDataProvider

struct NativeType
{
NativeType( QString typeDesc, QString typeName, QVariant::Type type, int minLen = 0, int maxLen = 0, int minPrec = 0, int maxPrec = 0 );
NativeType( QString typeDesc, QString typeName, QVariant::Type type, int minLen = 0, int maxLen = 0, int minPrec = 0, int maxPrec = 0 );

QString mTypeDesc;
QString mTypeName;
QVariant::Type mType;
int mMinLen;
int mMaxLen;
int mMinPrec;
int mMaxPrec;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsvectorfilewriter.sip
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,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
37 changes: 16 additions & 21 deletions python/core/qgsvectorlayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ struct QgsVectorJoinInfo
%End

/**Join field in the target layer*/
int targetField;
QString targetFieldName;
/**Source layer*/
QString joinLayerId;
/**Join field in the source layer*/
int joinField;
QString joinFieldName;
/**True if the join is cached in virtual memory*/
bool memoryCache;
/**Cache for joined attributes to provide fast lookup (size is 0 if no memory caching)
Expand Down Expand Up @@ -187,12 +187,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 @@ -308,18 +302,23 @@ class QgsVectorLayer : QgsMapLayer
void select( QList<int> fetchAttributes,
QgsRectangle rect = QgsRectangle(),
bool fetchGeometry = true,
bool useIntersect = false );
bool useIntersect = false ) /Deprecated/;

/**
* Query the provider for features specified in request.
*/
QgsFeatureIterator getFeatures( const QgsFeatureRequest& request = QgsFeatureRequest() );

/**
* fetch a feature (after select)
* @param feature buffer to read the feature into
* @return true, if a feature was fetched, false, if there are no more features
*/
bool nextFeature( QgsFeature& feature );
bool nextFeature( QgsFeature& feature ) /Deprecated/;

/**Gets the feature at the given feature id. Considers the changed, added, deleted and permanent features
@return true in case of success*/
bool featureAtId( QgsFeatureId featureId, QgsFeature &f, bool fetchGeometries = true, bool fetchAttributes = true );
bool featureAtId( QgsFeatureId featureId, QgsFeature &f, bool fetchGeometries = true, bool fetchAttributes = true ) /Deprecated/;

/** Adds a feature
@param f feature to add
Expand Down Expand Up @@ -477,7 +476,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 All @@ -491,9 +490,6 @@ class QgsVectorLayer : QgsMapLayer
*/
bool setReadOnly( bool readonly = true );

/** Sets whether some features are modified or not */
void setModified( bool modified = true, bool onlyGeometryWasModified = false );

/** Make layer editable */
bool startEditing();

Expand Down Expand Up @@ -630,6 +626,9 @@ class QgsVectorLayer : QgsMapLayer
QgsVectorOverlay* findOverlayByType( const QString& typeName );


//! Buffer with uncommitted editing operations. Only valid after editing has been turned on.
QgsVectorLayerEditBuffer* editBuffer();

/**
* Create edit command for undo/redo operations
* @param text text which is to be displayed in undo window
Expand Down Expand Up @@ -670,10 +669,6 @@ class QgsVectorLayer : QgsMapLayer
@note public and static from version 1.4 */
static void drawVertexMarker( double x, double y, QPainter& p, QgsVectorLayer::VertexMarkerType type, int vertexSize );

/** Assembles mUpdatedFields considering provider fields, joined fields and added fields
@note added in 1.7 */
void updateFieldMap();

/** Caches joined attributes if required (and not already done)
@note added in 1.7 */
void createJoinCaches();
Expand Down Expand Up @@ -722,7 +717,7 @@ class QgsVectorLayer : QgsMapLayer
void selectionChanged();

/** This signal is emitted when modifications has been done on layer */
void layerModified( bool onlyGeometry );
void layerModified();

void editingStarted();
void editingStopped();
Expand All @@ -737,7 +732,7 @@ class QgsVectorLayer : QgsMapLayer

/** Signals emitted after committing changes
\note added in v1.6 */
void committedAttributesDeleted( const QString& layerId, const QgsAttributeIds& deletedAttributeIds );
void committedAttributesDeleted( const QString& layerId, const QgsAttributeList& deletedAttributeIds );
void committedAttributesAdded( const QString& layerId, const QList<QgsField>& addedAttributes );
void committedFeaturesAdded( const QString& layerId, const QgsFeatureList& addedFeatures );
void committedFeaturesRemoved( const QString& layerId, const QgsFeatureIds& deletedFeatureIds );
Expand Down
105 changes: 105 additions & 0 deletions python/core/qgsvectorlayereditbuffer.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@

typedef QMap<qint64, QgsFeature> QgsFeatureMap;

class QgsVectorLayerEditBuffer : QObject
{
%TypeHeaderCode
#include "qgsvectorlayereditbuffer.h"
%End

public:
QgsVectorLayerEditBuffer(QgsVectorLayer* layer);
~QgsVectorLayerEditBuffer();

/** Returns true if the provider has been modified since the last commit */
bool isModified() const;


/** Adds a feature
@param f feature to add
@param alsoUpdateExtent If True, will also go to the effort of e.g. updating the extents.
@return True in case of success and False in case of error
*/
bool addFeature( QgsFeature& f );

/** Insert a copy of the given features into the layer (but does not commit it) */
bool addFeatures( QgsFeatureList& features );

/** delete a feature from the layer (but does not commit it) */
bool deleteFeature( QgsFeatureId fid );

/** change feature's geometry
@note added in version 1.2 */
bool changeGeometry( QgsFeatureId fid, QgsGeometry* geom );

/** changed an attribute value (but does not commit it) */
bool changeAttributeValue( QgsFeatureId fid, int field, QVariant value );

/** add an attribute field (but does not commit it)
returns true if the field was added
@note added in version 1.2 */
bool addAttribute( const QgsField &field );

/** delete an attribute field (but does not commit it) */
bool deleteAttribute( int attr );


/**
Attempts to commit any changes to disk. Returns the result of the attempt.
If a commit fails, the in-memory changes are left alone.

This allows editing to continue if the commit failed on e.g. a
disallowed value in a Postgres database - the user can re-edit and try
again.

The commits occur in distinct stages,
(add attributes, add features, change attribute values, change
geometries, delete features, delete attributes)
so if a stage fails, it's difficult to roll back cleanly.
Therefore any error message also includes which stage failed so
that the user has some chance of repairing the damage cleanly.
*/
bool commitChanges(QStringList& commitErrors);

/** Stop editing and discard the edits */
void rollBack();


/** New features which are not commited. */
const QgsFeatureMap& addedFeatures();

/** Changed attributes values which are not commited */
const QgsChangedAttributesMap& changedAttributeValues();

/** deleted attributes fields which are not commited. The list is kept sorted. */
const QgsAttributeList& deletedAttributeIds();

/** added attributes fields which are not commited */
const QList<QgsField>& addedAttributes();

/** Changed geometries which are not commited. */
const QgsGeometryMap& changedGeometries();

//QString dumpEditBuffer();

signals:
/** This signal is emitted when modifications has been done on layer */
void layerModified( bool onlyGeometry );

void featureAdded( QgsFeatureId fid );
void featureDeleted( QgsFeatureId fid );
void geometryChanged( QgsFeatureId fid, QgsGeometry &geom );
void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant & );
void attributeAdded( int idx );
void attributeDeleted( int idx );

/** Signals emitted after committing changes
\note added in v1.6 */
void committedAttributesDeleted( const QString& layerId, const QgsAttributeList& deletedAttributes );
void committedAttributesAdded( const QString& layerId, const QList<QgsField>& addedAttributes );
void committedFeaturesAdded( const QString& layerId, const QgsFeatureList& addedFeatures );
void committedFeaturesRemoved( const QString& layerId, const QgsFeatureIds& deletedFeatureIds );
void committedAttributeValuesChanges( const QString& layerId, const QgsChangedAttributesMap& changedAttributesValues );
void committedGeometriesChanges( const QString& layerId, const QgsGeometryMap& changedGeometries );

};
2 changes: 1 addition & 1 deletion python/core/qgsvectorlayerimport.sip
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class QProgressDialog;
/** 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
25 changes: 6 additions & 19 deletions python/core/qgsvectorlayerjoinbuffer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,10 @@ class QgsVectorLayerJoinBuffer
/**Removes a vector layer join*/
void removeJoin( const QString& joinLayerId );

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

/**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 );

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

/**Calls cacheJoinLayer() for all vector joins*/
void createJoinCaches();
Expand All @@ -37,19 +30,13 @@ class QgsVectorLayerJoinBuffer

/**Quick way to test if there is any join at all*/
bool containsJoins() const;
/**Quick way to test if there is a join to be fetched*/
bool containsFetchJoins() const;

const QList< QgsVectorJoinInfo >& vectorJoins() const;

/**Finds the vector join for a layer field index.
@param index this layers attribute index
@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;

/** 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 );
@param fields fields of the vector layer (including joined fields)
@param sourceFieldIndex Output: field's index in source layer */
const QgsVectorJoinInfo* joinForFieldIndex( int index, const QgsFields& fields, int& sourceFieldIndex /Out/ ) const;

};
88 changes: 0 additions & 88 deletions python/core/qgsvectorlayerundocommand.sip
Original file line number Diff line number Diff line change
@@ -1,89 +1 @@
class QgsUndoCommand : QUndoCommand
{
%TypeHeaderCode
#include <qgsvectorlayerundocommand.h>
%End
public:

/** change structure for attribute for undo/redo purpose */
class AttributeChangeEntry
{
public:
bool isFirstChange;
QVariant original;
QVariant target;
};

typedef QMap<int, QgsUndoCommand::AttributeChangeEntry> AttributeChanges;

/** change structure to geometry for undo/redo purpose */
class GeometryChangeEntry
{
public:
GeometryChangeEntry();
~GeometryChangeEntry();

void setOriginalGeometry( QgsGeometry& orig );
void setTargetGeometry( QgsGeometry& target );

QgsGeometry* original;
QgsGeometry* target;
};


QgsUndoCommand( QgsVectorLayer* layer, QString text );

/**
* Necessary function to provide undo operation
*/
void undo();

/**
* Necessary function to provide redo operation
*/
void redo();

/**
* Function to store changes in geometry to be returned to this state after undo/redo
* @param featureId id of feature edited
* @param original original geometry of feature which was changed
* @param target changed geometry which was changed
*/
void storeGeometryChange( QgsFeatureId featureId, QgsGeometry& original, QgsGeometry& target );

/**
* Stores changes of attributes for the feature to be returned to this state after undo/redo
* @param featureId id of feature for which this chaged is stored
* @param field field identifier of field which was changed
* @param original original value of attribute before change
* @param target target value of attribute after change
* @param isFirstChange flag if this change is the first one
*/
void storeAttributeChange( QgsFeatureId featureId, int field, QVariant original, QVariant target, bool isFirstChange );

/**
* Add id of feature to deleted list to be reverted if needed afterwards
* @param featureId id of feature which is to be deleted
*/
void storeFeatureDelete( QgsFeatureId featureId );

/**
* Add new feature to list of new features to be stored for undo/redo operations.
* @param feature feature which is to be added
*/
void storeFeatureAdd( QgsFeature& feature );

/**
* Add new attribute to list of attributes to be used for attributes of features for undo/redo operations.
* @param index index of attribute which is to be added
* @param value field description which is to be stored
*/
void storeAttributeAdd( int index, const QgsField & value );

/**
* Add deleted attribute which is to be stored for undo/redo operations.
* @param index index od attribute definition which is to be deleted
* @param orig deleted field's description
*/
void storeAttributeDelete( int index, const QgsField & orig );
};
6 changes: 0 additions & 6 deletions python/core/raster/qgsrasterlayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,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 @@ -292,9 +289,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
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class QgsExpressionBuilderWidget : QWidget
*/
void loadFieldNames();

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

/** Sets geometry calculator used in distance/area calculations.
* @note added in version 2.0
Expand Down
4 changes: 4 additions & 0 deletions python/gui/qgslegendinterface.sip
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class QgsLegendInterface : QObject
//! @note added in 1.5
virtual bool isGroupVisible( int groupIndex ) = 0;

//! Check if a layer is expanded
//! @note added in 2.0
virtual bool isLayerExpanded( QgsMapLayer * ml ) = 0;

//! Check if a layer is visible
//! @note added in 1.5
virtual bool isLayerVisible( QgsMapLayer * ml ) = 0;
Expand Down
2 changes: 1 addition & 1 deletion python/gui/qgsmessagelogviewer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ class QgsMessageLogViewer: QDialog
~QgsMessageLogViewer();

public slots:
void logMessage( QString message, QString tag, int level );
void logMessage( QString message, QString tag, QgsMessageLog::MessageLevel level );
};
17 changes: 7 additions & 10 deletions python/plugins/osm/OsmDatabaseManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ def findFeature(self,mapPoint):
lay=self.pointLayers[self.currentKey]
lay.select([],area,True,True)
result=lay.nextFeature(feat)
lay.dataProvider().rewind()

if result:
return (feat,'Point')
Expand All @@ -332,7 +331,6 @@ def findFeature(self,mapPoint):
lay=self.lineLayers[self.currentKey]
lay.select([],area,True,True)
result=lay.nextFeature(feat)
lay.dataProvider().rewind()

if result:
# line vertices
Expand All @@ -341,7 +339,7 @@ def findFeature(self,mapPoint):
,{"minLat":area.yMinimum(),"maxLat":area.yMaximum(),"minLon":area.xMinimum(),"maxLon":area.xMaximum(),"lineId":str(feat.id())})

for rec in c:
feat2=QgsFeature(rec[0],"Point")
feat2=QgsFeature(rec[0])
feat2.setGeometry(QgsGeometry.fromPoint(QgsPoint(rec[2],rec[1])))
# without features' attributes here! we don't need them...
c.close()
Expand All @@ -354,7 +352,6 @@ def findFeature(self,mapPoint):
lay=self.polygonLayers[self.currentKey]
lay.select([],area,True,True)
result=lay.nextFeature(feat)
lay.dataProvider().rewind()

if result:
# polygon vertices
Expand All @@ -363,7 +360,7 @@ def findFeature(self,mapPoint):
,{"minLat":area.yMinimum(),"maxLat":area.yMaximum(),"minLon":area.xMinimum(),"maxLon":area.xMaximum(),"polygonId":str(feat.id())})

for rec in c:
feat2=QgsFeature(rec[0],"Point")
feat2=QgsFeature(rec[0])
feat2.setGeometry(QgsGeometry.fromPoint(QgsPoint(rec[2],rec[1])))
# without features' attributes here! we don't need them...
c.close()
Expand Down Expand Up @@ -416,7 +413,7 @@ def findAllFeatures(self,mapPoint):
,{"minLat":area.yMinimum(),"maxLat":area.yMaximum(),"minLon":area.xMinimum(),"maxLon":area.xMaximum(),"lineId":str(feat.id())})

for rec in c:
feat2=QgsFeature(rec[0],"Point")
feat2=QgsFeature(rec[0])
feat2.setGeometry(QgsGeometry.fromPoint(QgsPoint(rec[2],rec[1])))
# without features' attributes here! we don't need them...
featMap[feat2.id()]=feat2
Expand All @@ -439,7 +436,7 @@ def findAllFeatures(self,mapPoint):
,{"minLat":area.yMinimum(),"maxLat":area.yMaximum(),"minLon":area.xMinimum(),"maxLon":area.xMaximum(),"polygonId":str(feat.id())})

for rec in c:
feat2=QgsFeature(rec[0],"Point")
feat2=QgsFeature(rec[0])
feat2.setGeometry(QgsGeometry.fromPoint(QgsPoint(rec[2],rec[1])))
# without features' attributes here! we don't need them...
featMap[feat2.id()]=feat2
Expand Down Expand Up @@ -471,7 +468,7 @@ def createPoint(self,mapPoint,snapFeat,snapFeatType,doCommit=True):
nodeId=self.__getFreeFeatureId()

affected=set()
feat=QgsFeature(nodeId,"Point")
feat=QgsFeature(nodeId)
feat.setGeometry(QgsGeometry.fromPoint(QgsPoint(mapPoint.x(),mapPoint.y())))

# should snapping be done? if not, everything's easy
Expand Down Expand Up @@ -612,7 +609,7 @@ def createLine(self,mapPoints, doCommit=True):

# finishing...
c.close()
feat=QgsFeature(lineId,"Line")
feat=QgsFeature(lineId)
feat.setGeometry(QgsGeometry.fromPolyline(pline))

if doCommit:
Expand Down Expand Up @@ -691,7 +688,7 @@ def createPolygon(self,mapPoints, doCommit=True):

# finish
c.close()
feat=QgsFeature(polygonId,"Polygon")
feat=QgsFeature(polygonId)
polygon=[]
polygon.append(pline)
feat.setGeometry(QgsGeometry.fromPolygon(polygon))
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ IF (WITH_BINDINGS)
ENDIF (WITH_BINDINGS)

IF (WITH_MAPSERVER)
ADD_SUBDIRECTORY(mapserver)
ADD_SUBDIRECTORY(mapserver) # TODO: enable again once compilation is fixed
ENDIF (WITH_MAPSERVER)

IF (WITH_ASTYLE)
Expand Down
7 changes: 4 additions & 3 deletions src/analysis/interpolation/DualEdgeTriangulation.cc
Original file line number Diff line number Diff line change
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 Expand Up @@ -3134,6 +3134,7 @@ bool DualEdgeTriangulation::saveAsShapefile( const QString& fileName ) const
lineGeom.push_back( QgsPoint( p2->getX(), p2->getY() ) );
QgsGeometry* geom = QgsGeometry::fromPolyline( lineGeom );
edgeLineFeature.setGeometry( geom );
edgeLineFeature.initAttributes( 1 );

//attributes
QString attributeString;
Expand All @@ -3148,7 +3149,7 @@ bool DualEdgeTriangulation::saveAsShapefile( const QString& fileName ) const
attributeString = "structure line";
}
}
edgeLineFeature.addAttribute( 0, attributeString );
edgeLineFeature.setAttribute( 0, attributeString );

writer.addFeature( edgeLineFeature );
}
Expand Down
15 changes: 7 additions & 8 deletions src/analysis/interpolation/qgsinterpolator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ int QgsInterpolator::cacheBaseData()
continue;
}

QgsVectorDataProvider* provider = v_it->vectorLayer->dataProvider();
if ( !provider )
QgsVectorLayer* vlayer = v_it->vectorLayer;
if ( !vlayer )
{
return 2;
}
Expand All @@ -67,23 +67,22 @@ int QgsInterpolator::cacheBaseData()
attList.push_back( v_it->interpolationAttribute );
}

provider->select( attList );
vlayer->select( attList );

QgsFeature theFeature;
double attributeValue = 0.0;
bool attributeConversionOk = false;

while ( provider->nextFeature( theFeature ) )
while ( vlayer->nextFeature( theFeature ) )
{
if ( !v_it->zCoordInterpolation )
{
QgsAttributeMap attMap = theFeature.attributeMap();
QgsAttributeMap::const_iterator att_it = attMap.find( v_it->interpolationAttribute );
if ( att_it == attMap.end() ) //attribute not found, something must be wrong (e.g. NULL value)
QVariant attributeVariant = theFeature.attribute( v_it->interpolationAttribute );
if ( !attributeVariant.isValid() ) //attribute not found, something must be wrong (e.g. NULL value)
{
continue;
}
attributeValue = att_it.value().toDouble( &attributeConversionOk );
attributeValue = attributeVariant.toDouble( &attributeConversionOk );
if ( !attributeConversionOk || qIsNaN( attributeValue ) ) //don't consider vertices with attributes like 'nan' for the interpolation
{
continue;
Expand Down
7 changes: 3 additions & 4 deletions src/analysis/interpolation/qgstininterpolator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,12 @@ int QgsTINInterpolator::insertData( QgsFeature* f, bool zCoord, int attr, InputT
bool attributeConversionOk = false;
if ( !zCoord )
{
QgsAttributeMap attMap = f->attributeMap();
QgsAttributeMap::const_iterator att_it = attMap.find( attr );
if ( att_it == attMap.end() ) //attribute not found, something must be wrong (e.g. NULL value)
QVariant attributeVariant = f->attribute( attr );
if ( !attributeVariant.isValid() ) //attribute not found, something must be wrong (e.g. NULL value)
{
return 3;
}
attributeValue = att_it.value().toDouble( &attributeConversionOk );
attributeValue = attributeVariant.toDouble( &attributeConversionOk );
if ( !attributeConversionOk || qIsNaN( attributeValue ) ) //don't consider vertices with attributes like 'nan' for the interpolation
{
return 4;
Expand Down
32 changes: 12 additions & 20 deletions src/analysis/network/qgslinevectorlayerdirector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,29 +280,21 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
vl->select( la );
while ( vl->nextFeature( feature ) )
{
QgsAttributeMap attr = feature.attributeMap();
int directionType = mDefaultDirection;
QgsAttributeMap::const_iterator it;

// What direction have feature?
for ( it = attr.constBegin(); it != attr.constEnd(); ++it )
QString str = feature.attribute( mDirectionFieldId ).toString();
if ( str == mBothDirectionValue )
{
if ( it.key() != mDirectionFieldId )
{
continue;
}
QString str = it.value().toString();
if ( str == mBothDirectionValue )
{
directionType = 3;
}
else if ( str == mDirectDirectionValue )
{
directionType = 1;
}
else if ( str == mReverseDirectionValue )
{
directionType = 2;
}
directionType = 3;
}
else if ( str == mDirectDirectionValue )
{
directionType = 1;
}
else if ( str == mReverseDirectionValue )
{
directionType = 2;
}

// begin features segments and add arc to the Graph;
Expand Down
114 changes: 57 additions & 57 deletions src/analysis/vector/qgsgeometryanalyzer.cpp
Original file line number Diff line number Diff line change
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 @@ -135,7 +135,7 @@ void QgsGeometryAnalyzer::simplifyFeature( QgsFeature& f, QgsVectorFileWriter* v

QgsFeature newFeature;
newFeature.setGeometry( tmpGeometry );
newFeature.setAttributeMap( f.attributeMap() );
newFeature.setAttributes( f.attributes() );

//add it to vector file writer
if ( vfw )
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 @@ -251,7 +251,7 @@ void QgsGeometryAnalyzer::centroidFeature( QgsFeature& f, QgsVectorFileWriter* v

QgsFeature newFeature;
newFeature.setGeometry( tmpGeometry );
newFeature.setAttributeMap( f.attributeMap() );
newFeature.setAttributes( f.attributes() );

//add it to vector file writer
if ( vfw )
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 All @@ -315,18 +315,18 @@ bool QgsGeometryAnalyzer::extent( QgsVectorLayer* layer,
double perim = ( 2 * width ) + ( 2 * height );

QgsFeature feat;
QgsAttributeMap map;
map.insert( 0 , QVariant( minx ) );
map.insert( 1 , QVariant( miny ) );
map.insert( 2 , QVariant( maxx ) );
map.insert( 3 , QVariant( maxy ) );
map.insert( 4 , QVariant( cntx ) );
map.insert( 5 , QVariant( cnty ) );
map.insert( 6 , QVariant( area ) );
map.insert( 7 , QVariant( perim ) );
map.insert( 8 , QVariant( height ) );
map.insert( 9 , QVariant( width ) );
feat.setAttributeMap( map );
QgsAttributes attrs( 10 );
attrs[0] = QVariant( minx );
attrs[1] = QVariant( miny );
attrs[2] = QVariant( maxx );
attrs[3] = QVariant( maxy );
attrs[4] = QVariant( cntx );
attrs[5] = QVariant( cnty );
attrs[6] = QVariant( area );
attrs[7] = QVariant( perim );
attrs[8] = QVariant( height );
attrs[9] = QVariant( width );
feat.setAttributes( attrs );
feat.setGeometry( QgsGeometry::fromRect( rect ) );
vWriter.addFeature( feat );
return true;
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 @@ -439,7 +439,7 @@ bool QgsGeometryAnalyzer::convexHull( QgsVectorLayer* layer, const QString& shap
{
continue;
}
map.insert( currentFeature.attributeMap()[ uniqueIdField ].toString(), currentFeature.id() );
map.insert( currentFeature.attribute( uniqueIdField ).toString(), currentFeature.id() );
}
}
else
Expand All @@ -458,7 +458,7 @@ bool QgsGeometryAnalyzer::convexHull( QgsVectorLayer* layer, const QString& shap
return false;
}
#endif
map.insert( currentFeature.attributeMap()[ uniqueIdField ].toString(), currentFeature.id() );
map.insert( currentFeature.attribute( uniqueIdField ).toString(), currentFeature.id() );
}
}

Expand Down Expand Up @@ -506,12 +506,12 @@ bool QgsGeometryAnalyzer::convexHull( QgsVectorLayer* layer, const QString& shap
}
dissolveGeometry = dissolveGeometry->convexHull();
values = simpleMeasure( dissolveGeometry );
QgsAttributeMap attributeMap;
attributeMap.insert( 0 , QVariant( currentKey ) );
attributeMap.insert( 1 , values[ 0 ] );
attributeMap.insert( 2 , values[ 1 ] );
QgsAttributes attributes( 3 );
attributes[0] = QVariant( currentKey );
attributes[1] = values[ 0 ];
attributes[2] = values[ 1 ];
QgsFeature dissolveFeature;
dissolveFeature.setAttributeMap( attributeMap );
dissolveFeature.setAttributes( attributes );
dissolveFeature.setGeometry( dissolveGeometry );
vWriter.addFeature( dissolveFeature );
}
Expand Down Expand Up @@ -553,12 +553,12 @@ bool QgsGeometryAnalyzer::convexHull( QgsVectorLayer* layer, const QString& shap
dissolveGeometry = dissolveGeometry->convexHull();
// values = simpleMeasure( tmpGeometry );
values = simpleMeasure( dissolveGeometry );
QgsAttributeMap attributeMap;
attributeMap.insert( 0 , QVariant( currentKey ) );
attributeMap.insert( 1 , QVariant( values[ 0 ] ) );
attributeMap.insert( 2 , QVariant( values[ 1 ] ) );
QgsAttributes attributes;
attributes[0] = QVariant( currentKey );
attributes[1] = QVariant( values[ 0 ] );
attributes[2] = QVariant( values[ 1 ] );
QgsFeature dissolveFeature;
dissolveFeature.setAttributeMap( attributeMap );
dissolveFeature.setAttributes( attributes );
dissolveFeature.setGeometry( dissolveGeometry );
vWriter.addFeature( dissolveFeature );
}
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 All @@ -633,15 +633,15 @@ bool QgsGeometryAnalyzer::dissolve( QgsVectorLayer* layer, const QString& shapef
{
continue;
}
map.insert( currentFeature.attributeMap()[ uniqueIdField ].toString(), currentFeature.id() );
map.insert( currentFeature.attribute( uniqueIdField ).toString(), currentFeature.id() );
}
}
else
{
layer->select( layer->pendingAllAttributesList(), QgsRectangle(), true, false );
while ( layer->nextFeature( currentFeature ) )
{
map.insert( currentFeature.attributeMap()[ uniqueIdField ].toString(), currentFeature.id() );
map.insert( currentFeature.attribute( uniqueIdField ).toString(), currentFeature.id() );
}
}

Expand Down Expand Up @@ -680,7 +680,7 @@ bool QgsGeometryAnalyzer::dissolve( QgsVectorLayer* layer, const QString& shapef
}
if ( first )
{
outputFeature.setAttributeMap( currentFeature.attributeMap() );
outputFeature.setAttributes( currentFeature.attributes() );
first = false;
}
dissolveFeature( currentFeature, processedFeatures, &dissolveGeometry );
Expand Down Expand Up @@ -713,7 +713,7 @@ bool QgsGeometryAnalyzer::dissolve( QgsVectorLayer* layer, const QString& shapef
continue;
}
{
outputFeature.setAttributeMap( currentFeature.attributeMap() );
outputFeature.setAttributes( currentFeature.attributes() );
first = false;
}
dissolveFeature( currentFeature, processedFeatures, &dissolveGeometry );
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 @@ -877,7 +877,7 @@ void QgsGeometryAnalyzer::bufferFeature( QgsFeature& f, int nProcessedFeatures,
}
else
{
currentBufferDistance = f.attributeMap()[bufferDistanceField].toDouble();
currentBufferDistance = f.attribute( bufferDistanceField ).toDouble();
}
bufferGeometry = featureGeometry->buffer( currentBufferDistance, 5 );

Expand All @@ -899,7 +899,7 @@ void QgsGeometryAnalyzer::bufferFeature( QgsFeature& f, int nProcessedFeatures,
{
QgsFeature newFeature;
newFeature.setGeometry( bufferGeometry );
newFeature.setAttributeMap( f.attributeMap() );
newFeature.setAttributes( f.attributes() );

//add it to vector file writer
if ( vfw )
Expand All @@ -925,7 +925,7 @@ bool QgsGeometryAnalyzer::eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer*
QgsFeature fet;
while ( lineLayer->nextFeature( fet ) )
{
lineLayerIdMap.insert( fet.attributeMap()[lineField].toString(), fet.id() );
lineLayerIdMap.insert( fet.attribute( lineField ).toString(), fet.id() );
}

//create output datasource or attributes in memory provider
Expand All @@ -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 Expand Up @@ -986,13 +986,13 @@ bool QgsGeometryAnalyzer::eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer*
++featureCounter;
}

measure1 = fet.attributeMap()[locationField1].toDouble();
measure1 = fet.attribute( locationField1 ).toDouble();
if ( locationField2 != -1 )
{
measure2 = fet.attributeMap()[locationField2].toDouble();
measure2 = fet.attribute( locationField2 ).toDouble();
}

QList<QgsFeatureId> featureIdList = lineLayerIdMap.values( fet.attributeMap()[eventField].toString() );
QList<QgsFeatureId> featureIdList = lineLayerIdMap.values( fet.attribute( eventField ).toString() );
QList<QgsFeatureId>::const_iterator featureIdIt = featureIdList.constBegin();
for ( ; featureIdIt != featureIdList.constEnd(); ++featureIdIt )
{
Expand Down Expand Up @@ -1059,7 +1059,7 @@ void QgsGeometryAnalyzer::addEventLayerFeature( QgsFeature& feature, QgsGeometry
//consider offset
if ( offsetField >= 0 )
{
double offsetVal = feature.attributeMap()[offsetField].toDouble();
double offsetVal = feature.attribute( offsetField ).toDouble();
offsetVal *= offsetScale;
createOffsetGeometry( *geomIt, lineGeom, offsetVal );
}
Expand Down
54 changes: 18 additions & 36 deletions src/analysis/vector/qgsoverlayanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ bool QgsOverlayAnalyzer::intersection( QgsVectorLayer* layerA, QgsVectorLayer* l

QGis::WkbType outputType = dpA->geometryType();
const QgsCoordinateReferenceSystem crs = layerA->crs();
QgsFieldMap fieldsA = dpA->fields();
QgsFieldMap fieldsB = dpB->fields();
QgsFields fieldsA = layerA->pendingFields();
QgsFields fieldsB = layerB->pendingFields();
combineFieldLists( fieldsA, fieldsB );

QgsVectorFileWriter vWriter( shapefileName, dpA->encoding(), fieldsA, outputType, &crs );
Expand Down Expand Up @@ -166,10 +166,10 @@ void QgsOverlayAnalyzer::intersectFeature( QgsFeature& f, QgsVectorFileWriter* v
intersectGeometry = featureGeometry->intersection( overlayFeature.geometry() );

outFeature.setGeometry( intersectGeometry );
QgsAttributeMap attributeMapA = f.attributeMap();
QgsAttributeMap attributeMapB = overlayFeature.attributeMap();
combineAttributeMaps( attributeMapA, attributeMapB );
outFeature.setAttributeMap( attributeMapA );
QgsAttributes attributesA = f.attributes();
QgsAttributes attributesB = overlayFeature.attributes();
combineAttributeMaps( attributesA, attributesB );
outFeature.setAttributes( attributesA );

//add it to vector file writer
if ( vfw )
Expand All @@ -180,47 +180,29 @@ void QgsOverlayAnalyzer::intersectFeature( QgsFeature& f, QgsVectorFileWriter* v
}
}

void QgsOverlayAnalyzer::combineFieldLists( QgsFieldMap& fieldListA, QgsFieldMap fieldListB )
void QgsOverlayAnalyzer::combineFieldLists( QgsFields& fieldListA, const QgsFields& fieldListB )
{
QList<QString> names;
QMap<int, QgsField>::const_iterator j = fieldListA.constBegin();
while ( j != fieldListA.constEnd() )
{
names.append( j.value().name() );
++j;
}
QMap<int, QgsField>::const_iterator i = fieldListB.constBegin();
int count = 0;
int fcount = fieldListA.size();
QgsField field;
while ( i != fieldListB.constEnd() )
for ( int idx = 0; idx < fieldListA.count(); ++idx )
names.append( fieldListA[idx].name() );

for ( int idx = 0; idx < fieldListB.count(); ++idx )
{
field = i.value();
QgsField field = fieldListB[idx];
int count = 0;
while ( names.contains( field.name() ) )
{
QString name = field.name();
name.append( "_" ).append( QString( count ) );
QString name = QString("%1_%2").arg( field.name() ).arg( count );
field = QgsField( name, field.type() );
++count;
}
fieldListA.insert( fcount, field );
count = 0;
++fcount;
++i;
fieldListA.append( field );
names.append( field.name() );
}
}

void QgsOverlayAnalyzer::combineAttributeMaps( QgsAttributeMap& attributeMapA, QgsAttributeMap attributeMapB )
void QgsOverlayAnalyzer::combineAttributeMaps( QgsAttributes& attributesA, const QgsAttributes& attributesB )
{
QMap<int, QVariant>::const_iterator i = attributeMapB.constBegin();
QVariant attribute;
int fcount = attributeMapA.size();
while ( i != attributeMapB.constEnd() )
{
attribute = i.value();
attributeMapA.insert( fcount, attribute );
++i;
++fcount;
}
attributesA += attributesB;
}

4 changes: 2 additions & 2 deletions src/analysis/vector/qgsoverlayanalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ class ANALYSIS_EXPORT QgsOverlayAnalyzer

private:

void combineFieldLists( QgsFieldMap& fieldListA, QgsFieldMap fieldListB );
void combineFieldLists( QgsFields& fieldListA, const QgsFields& fieldListB );
void intersectFeature( QgsFeature& f, QgsVectorFileWriter* vfw, QgsVectorLayer* dp, QgsSpatialIndex* index );
void combineAttributeMaps( QgsAttributeMap& attributeMapA, QgsAttributeMap attributeMapB );
void combineAttributeMaps( QgsAttributes& attributesA, const QgsAttributes& attributesB );
};
#endif //QGSVECTORANALYZER
8 changes: 5 additions & 3 deletions src/analysis/vector/qgszonalstatistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,17 @@ int QgsZonalStatistics::calculateStatistics( QProgressDialog* p )


//iterate over each polygon
vectorProvider->select( QgsAttributeList(), QgsRectangle(), true, false );
QgsFeatureRequest request;
request.setSubsetOfAttributes( QgsAttributeList() );
QgsFeatureIterator fi = vectorProvider->getFeatures( request );
//vectorProvider->select( QgsAttributeList(), QgsRectangle(), true, false );
QgsFeature f;
double count = 0;
double sum = 0;
double mean = 0;
int featureCounter = 0;

while ( vectorProvider->nextFeature( f ) )
while ( fi.nextFeature( f ) )
{
if ( p )
{
Expand Down Expand Up @@ -225,7 +228,6 @@ int QgsZonalStatistics::calculateStatistics( QProgressDialog* p )
}

GDALClose( inputDataset );
mPolygonLayer->updateFieldMap();

if ( p && p->wasCanceled() )
{
Expand Down
14 changes: 7 additions & 7 deletions src/app/composer/qgsattributeselectiondialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ QgsAttributeSelectionDialog::QgsAttributeSelectionDialog( const QgsVectorLayer*
setupUi( this );
if ( vLayer )
{
QgsFieldMap fieldMap = vLayer->pendingFields();
QgsFieldMap::const_iterator fieldIt = fieldMap.constBegin();
const QgsFields& fieldMap = vLayer->pendingFields();
int layoutRowCounter = 1;
for ( ; fieldIt != fieldMap.constEnd(); ++fieldIt )
for ( int idx = 0; idx < fieldMap.count(); ++idx )
{
QString fieldName = fieldMap[idx].name();
//insert field into sorting combo first
mSortColumnComboBox->addItem( fieldIt.value().name(), QVariant( fieldIt.key() ) );
mSortColumnComboBox->addItem( fieldName, QVariant( idx ) );

//and into enabled / alias list
QCheckBox* attributeCheckBox = new QCheckBox( fieldIt.value().name(), this );
if ( enabledAttributes.size() < 1 || enabledAttributes.contains( fieldIt.key() ) )
QCheckBox* attributeCheckBox = new QCheckBox( fieldName, this );
if ( enabledAttributes.size() < 1 || enabledAttributes.contains( idx ) )
{
attributeCheckBox->setCheckState( Qt::Checked );
}
Expand All @@ -52,7 +52,7 @@ QgsAttributeSelectionDialog::QgsAttributeSelectionDialog( const QgsVectorLayer*
mAttributeGridLayout->addWidget(( QWidget* )attributeCheckBox, layoutRowCounter, 0, 1, 1 );

QLineEdit* attributeLineEdit = new QLineEdit( this );
QMap<int, QString>::const_iterator aliasIt = aliasMap.find( fieldIt.key() );
QMap<int, QString>::const_iterator aliasIt = aliasMap.find( idx );
if ( aliasIt != aliasMap.constEnd() )
{
attributeLineEdit->setText( aliasIt.value() );
Expand Down
4 changes: 2 additions & 2 deletions src/app/gps/qgsgpsinformationwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ void QgsGPSInformationWidget::on_mBtnCloseFeature_clicked( )
//
if ( layerWKBType == QGis::WKBPoint )
{
QgsFeature* f = new QgsFeature( 0, "WKBPoint" );
QgsFeature* f = new QgsFeature( 0 );

int size = 0;
char end = QgsApplication::endian();
Expand Down Expand Up @@ -850,7 +850,7 @@ void QgsGPSInformationWidget::on_mBtnCloseFeature_clicked( )
mNmea->disconnect( this, SLOT( displayGPSInformation( const QgsGPSInformation& ) ) );

//create QgsFeature with wkb representation
QgsFeature* f = new QgsFeature( 0, "WKBLineString" );
QgsFeature* f = new QgsFeature( 0 );
unsigned char* wkb;
int size;
char end = QgsApplication::endian();
Expand Down
5 changes: 5 additions & 0 deletions src/app/legend/qgsapplegendinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ bool QgsAppLegendInterface::isGroupVisible( int groupIndex )
return ( Qt::Checked == getItem( groupIndex )->checkState( 0 ) );
}

bool QgsAppLegendInterface::isLayerExpanded( QgsMapLayer * ml )
{
return mLegend->layerIsExpanded( ml );
}

bool QgsAppLegendInterface::isLayerVisible( QgsMapLayer * ml )
{
return ( Qt::Checked == mLegend->layerCheckState( ml ) );
Expand Down
3 changes: 3 additions & 0 deletions src/app/legend/qgsapplegendinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class QgsAppLegendInterface : public QgsLegendInterface
//! Check if a group is visible
bool isGroupVisible( int groupIndex );

//! Check if a layer is expanded
bool isLayerExpanded( QgsMapLayer * ml );

//! Check if a layer is visible
bool isLayerVisible( QgsMapLayer * ml );

Expand Down
7 changes: 7 additions & 0 deletions src/app/legend/qgslegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,13 @@ Qt::CheckState QgsLegend::layerCheckState( QgsMapLayer * layer )
return ll ? ll->checkState( 0 ) : Qt::Unchecked;
}

bool QgsLegend::layerIsExpanded( QgsMapLayer * layer )
{
QgsLegendLayer * ll = findLegendLayer( layer );

return ll->isExpanded();
}

QgsLegendGroup* QgsLegend::addEmbeddedGroup( const QString& groupName, const QString& projectFilePath, QgsLegendItem* parent )
{
mEmbeddedGroups.insert( groupName, projectFilePath );
Expand Down
3 changes: 3 additions & 0 deletions src/app/legend/qgslegend.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ class QgsLegend : public QTreeWidget
/**Returns a layers check state*/
Qt::CheckState layerCheckState( QgsMapLayer * layer );

/**Returns a layers expanded state*/
bool layerIsExpanded( QgsMapLayer * layer );

/**Add group from other project file. Returns a pointer to the new group in case of success or 0 in case of error*/
QgsLegendGroup* addEmbeddedGroup( const QString& groupName, const QString& projectFilePath, QgsLegendItem* parent = 0 );

Expand Down
24 changes: 8 additions & 16 deletions src/app/legend/qgslegendlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ QgsLegendLayer::QgsLegendLayer( QgsMapLayer* layer )
QgsDebugMsg( "Connecting signals for updating icons, layer " + layer->name() );
connect( layer, SIGNAL( editingStarted() ), this, SLOT( updateIcon() ) );
connect( layer, SIGNAL( editingStopped() ), this, SLOT( updateIcon() ) );
connect( layer, SIGNAL( layerModified( bool ) ), this, SLOT( updateAfterLayerModification( bool ) ) );
connect( layer, SIGNAL( layerModified() ), this, SLOT( updateAfterLayerModification() ) ); // TODO[MD]: should have symbologyChanged signal
}
if ( qobject_cast<QgsRasterLayer *>( layer ) )
{
Expand Down Expand Up @@ -207,13 +207,16 @@ void QgsLegendLayer::vectorLayerSymbology( QgsVectorLayer* layer, double widthSc
if ( renderer->needsAttributes() )
{
QgsAttributeList classfieldlist = renderer->classificationAttributes();
const QgsFieldMap& fields = layer->pendingFields();
const QgsFields& fields = layer->pendingFields();
for ( QgsAttributeList::iterator it = classfieldlist.begin(); it != classfieldlist.end(); ++it )
{
QString classfieldname = layer->attributeAlias( *it );
int idx = *it;
if ( idx < 0 || idx >= fields.count() )
continue;
QString classfieldname = layer->attributeAlias( idx );
if ( classfieldname.isEmpty() )
{
classfieldname = fields[*it].name();
classfieldname = fields[idx].name();
}
itemList.append( qMakePair( classfieldname, QPixmap() ) );
}
Expand Down Expand Up @@ -617,17 +620,6 @@ QString QgsLegendLayer::layerName()

void QgsLegendLayer::updateAfterLayerModification()
{
updateAfterLayerModification( false );
}

void QgsLegendLayer::updateAfterLayerModification( bool onlyGeomChanged )
{
if ( onlyGeomChanged )
{
updateIcon();
return;
}

double widthScale = 1.0;
QgsMapCanvas* canvas = QgisApp::instance()->mapCanvas();
if ( canvas && canvas->map() )
Expand Down Expand Up @@ -738,7 +730,7 @@ void QgsLegendLayer::setShowFeatureCount( bool show, bool update )
mShowFeatureCount = show;
if ( update )
{
updateAfterLayerModification( false );
updateAfterLayerModification();
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/app/legend/qgslegendlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ class QgsLegendLayer : public QgsLegendItem
void layerNameChanged();

/**Update symbology (e.g. to update feature count in the legend after editing operations)*/
void updateAfterLayerModification( bool onlyGeomChanged );
void updateAfterLayerModification();

void setShowFeatureCount( bool show, bool update = true );
Expand Down
27 changes: 14 additions & 13 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4692,13 +4692,13 @@ void QgisApp::mergeAttributesOfSelectedFeatures()

vl->beginEditCommand( tr( "Merged feature attributes" ) );

const QgsAttributeMap &merged = d.mergedAttributesMap();
const QgsAttributes &merged = d.mergedAttributes();

foreach ( QgsFeatureId fid, vl->selectedFeaturesIds() )
{
for ( QgsAttributeMap::const_iterator it = merged.begin(); it != merged.end(); it++ )
for ( int i = 0; i < merged.count(); ++i )
{
vl->changeAttributeValue( fid, it.key(), it.value() );
vl->changeAttributeValue( fid, i, merged.at( i ) );
}
}

Expand Down Expand Up @@ -4812,7 +4812,7 @@ void QgisApp::mergeSelectedFeatures()
//create new feature
QgsFeature newFeature;
newFeature.setGeometry( unionGeom );
newFeature.setAttributeMap( d.mergedAttributesMap() );
newFeature.setAttributes( d.mergedAttributes() );

QgsFeatureList::const_iterator feature_it = featureListAfter.constBegin();
for ( ; feature_it != featureListAfter.constEnd(); ++feature_it )
Expand Down Expand Up @@ -4993,35 +4993,36 @@ void QgisApp::editPaste( QgsMapLayer *destinationLayer )
}

QHash<int, int> remap;
const QgsFieldMap &fields = clipboard()->fields();
const QgsFields &fields = clipboard()->fields();
QgsAttributeList pkAttrList = pasteVectorLayer->pendingPkAttributesList();
for ( QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); it++ )
for ( int idx = 0; idx < fields.count(); ++idx )
{
int dst = pasteVectorLayer->fieldNameIndex( it->name() );
int dst = pasteVectorLayer->fieldNameIndex( fields[idx].name() );
if ( dst < 0 || pkAttrList.contains( dst ) )
{
// skip primary key attributes
continue;
}
remap.insert( it.key(), dst );
remap.insert( idx, dst );
}

int dstAttrCount = pasteVectorLayer->pendingFields().count();
for ( int i = 0; i < features.size(); i++ )
{
QgsFeature &f = features[i];
const QgsAttributeMap &srcMap = f.attributeMap();
QgsAttributeMap dstMap;
const QgsAttributes &srcAttr = f.attributes();
QgsAttributes dstAttr( dstAttrCount );

foreach ( int src, srcMap.keys() )
for ( int src = 0; src < srcAttr.count(); ++src )
{
int dst = remap.value( src, -1 );
if ( dst < 0 )
continue;

dstMap.insert( dst, srcMap[ src ] );
dstAttr[ dst ] = srcAttr[ src ];
}

f.setAttributeMap( dstMap );
f.setAttributes( dstAttr );
}

pasteVectorLayer->addFeatures( features );
Expand Down
24 changes: 6 additions & 18 deletions src/app/qgsaddjoindialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ QgsAddJoinDialog::QgsAddJoinDialog( QgsVectorLayer* layer, QWidget * parent, Qt:
QgsVectorDataProvider* provider = mLayer->dataProvider();
if ( provider )
{
const QgsFieldMap& layerFieldMap = provider->fields();
QgsFieldMap::const_iterator fieldIt = layerFieldMap.constBegin();
for ( ; fieldIt != layerFieldMap.constEnd(); ++fieldIt )
const QgsFields& layerFields = provider->fields();
for ( int idx = 0; idx < layerFields.count(); ++idx )
{
mTargetFieldComboBox->addItem( fieldIt.value().name(), fieldIt.key() );
mTargetFieldComboBox->addItem( layerFields[idx].name(), idx );
}
}

Expand All @@ -75,21 +74,11 @@ QString QgsAddJoinDialog::joinedLayerId() const
return mJoinLayerComboBox->itemData( mJoinLayerComboBox->currentIndex() ).toString();
}

int QgsAddJoinDialog::joinField() const
{
return mJoinFieldComboBox->itemData( mJoinFieldComboBox->currentIndex() ).toInt();
}

QString QgsAddJoinDialog::joinFieldName() const
{
return mJoinFieldComboBox->itemText( mJoinFieldComboBox->currentIndex() );
}

int QgsAddJoinDialog::targetField() const
{
return mTargetFieldComboBox->itemData( mTargetFieldComboBox->currentIndex() ).toInt();
}

QString QgsAddJoinDialog::targetFieldName() const
{
return mTargetFieldComboBox->itemText( mTargetFieldComboBox->currentIndex() );
Expand Down Expand Up @@ -120,11 +109,10 @@ void QgsAddJoinDialog::on_mJoinLayerComboBox_currentIndexChanged( int index )
return;
}

const QgsFieldMap& layerFieldMap = vLayer->pendingFields();
QgsFieldMap::const_iterator fieldIt = layerFieldMap.constBegin();
for ( ; fieldIt != layerFieldMap.constEnd(); ++fieldIt )
const QgsFields& layerFields = vLayer->pendingFields();
for ( int idx = 0; idx < layerFields.count(); ++idx )
{
mJoinFieldComboBox->addItem( fieldIt.value().name(), fieldIt.key() );
mJoinFieldComboBox->addItem( layerFields[idx].name(), idx );
}

//does provider support creation of attribute indices?
Expand Down
4 changes: 0 additions & 4 deletions src/app/qgsaddjoindialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,8 @@ class QgsAddJoinDialog: public QDialog, private Ui::QgsAddJoinDialogBase

/**Get the id of the layer to join*/
QString joinedLayerId() const;
/**Returns the index of the join field*/
int joinField() const;
/**Returns the name of the join field*/
QString joinFieldName() const;
/**Returns the index of the target field (join-to field)*/
int targetField() const;
/**Returns the name of the target field (join-to field)*/
QString targetFieldName() const;
/**True if joined layer should be cached in virtual memory*/
Expand Down
6 changes: 3 additions & 3 deletions src/app/qgsattributeactiondialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ back to QgsVectorLayer.
#include <QSettings>

QgsAttributeActionDialog::QgsAttributeActionDialog( QgsAttributeAction* actions,
const QgsFieldMap& fields,
const QgsFields& fields,
QWidget* parent ):
QWidget( parent ), mActions( actions )
{
Expand Down Expand Up @@ -65,8 +65,8 @@ QgsAttributeActionDialog::QgsAttributeActionDialog( QgsAttributeAction* actions,
// Populate the combo box with the field names. Will the field names
// change? If so, they need to be passed into the init() call, or
// some access to them retained in this class.
for ( QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); it++ )
fieldComboBox->addItem( it->name() );
for ( int idx = 0; idx < fields.count(); ++idx )
fieldComboBox->addItem( fields[idx].name() );
}

void QgsAttributeActionDialog::init()
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsattributeactiondialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class QgsAttributeActionDialog: public QWidget, private Ui::QgsAttributeActionDi

public:
QgsAttributeActionDialog( QgsAttributeAction* actions,
const QgsFieldMap& fields,
const QgsFields& fields,
QWidget* parent = 0 );

~QgsAttributeActionDialog() {};
Expand Down
32 changes: 15 additions & 17 deletions src/app/qgsattributedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
if ( !mFeature || !vl->dataProvider() )
return;

const QgsFieldMap &theFieldMap = vl->pendingFields();
if ( theFieldMap.isEmpty() )
const QgsFields &theFields = vl->pendingFields();
if ( theFields.isEmpty() )
return;

QgsAttributeMap myAttributes = mFeature->attributeMap();
QgsAttributes myAttributes = mFeature->attributes();

QDialogButtonBox *buttonBox = NULL;

Expand Down Expand Up @@ -172,13 +172,13 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
QGridLayout *mypInnerLayout = new QGridLayout( mypInnerFrame );

int index = 0;
for ( QgsFieldMap::const_iterator it = theFieldMap.begin(); it != theFieldMap.end(); ++it )
for ( int fldIdx = 0; fldIdx < theFields.count(); ++fldIdx )
{
//show attribute alias if available
QString myFieldName = vl->attributeDisplayName( it.key() );
int myFieldType = it->type();
QString myFieldName = vl->attributeDisplayName( fldIdx );
int myFieldType = theFields[fldIdx].type();

QWidget *myWidget = QgsAttributeEditor::createAttributeEditor( 0, 0, vl, it.key(), myAttributes.value( it.key(), QVariant() ), mProxyWidgets );
QWidget *myWidget = QgsAttributeEditor::createAttributeEditor( 0, 0, vl, fldIdx, myAttributes[fldIdx], mProxyWidgets );
if ( !myWidget )
continue;

Expand All @@ -202,7 +202,7 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
mypLabel->setText( myFieldName );
}

if ( vl->editType( it.key() ) != QgsVectorLayer::Immutable )
if ( vl->editType( fldIdx ) != QgsVectorLayer::Immutable )
{
myWidget->setEnabled( vl->isEditable() );
}
Expand All @@ -221,24 +221,23 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
}
else
{

QgsDistanceArea myDa;

myDa.setSourceCrs( vl->crs().srsid() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() );
myDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );

for ( QgsFieldMap::const_iterator it = theFieldMap.begin(); it != theFieldMap.end(); ++it )
for ( int fldIdx = 0; fldIdx < theFields.count(); ++fldIdx )
{
QList<QWidget *> myWidgets = mDialog->findChildren<QWidget*>( it->name() );
QList<QWidget *> myWidgets = mDialog->findChildren<QWidget*>( theFields[fldIdx].name() );
if ( !myWidgets.size() )
continue;

for ( QList<QWidget *>::const_iterator itw = myWidgets.begin(); itw != myWidgets.end(); ++itw )
{
QgsAttributeEditor::createAttributeEditor( mDialog, *itw, vl, it.key(), myAttributes.value( it.key(), QVariant() ), mProxyWidgets );
QgsAttributeEditor::createAttributeEditor( mDialog, *itw, vl, fldIdx, myAttributes[fldIdx], mProxyWidgets );

if ( vl->editType( it.key() ) != QgsVectorLayer::Immutable )
if ( vl->editType( fldIdx ) != QgsVectorLayer::Immutable )
{
( *itw )->setEnabled(( *itw )->isEnabled() && vl->isEditable() );
}
Expand Down Expand Up @@ -401,14 +400,13 @@ void QgsAttributeDialog::accept()
return;

//write the new values back to the feature
for ( QgsFieldMap::const_iterator it = mLayer->pendingFields().begin(); it != mLayer->pendingFields().end(); ++it )
const QgsFields& fields = mLayer->pendingFields();
for ( int idx = 0; idx < fields.count(); ++idx )
{
int idx = it.key();

QVariant value;

if ( QgsAttributeEditor::retrieveValue( mProxyWidgets.value( idx ), mLayer, idx, value ) )
mFeature->changeAttribute( idx, value );
mFeature->setAttribute( idx, value );
}
}

Expand Down
20 changes: 9 additions & 11 deletions src/app/qgsattributetabledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,26 +262,24 @@ void QgsAttributeTableDialog::on_cbxShowSelectedOnly_toggled( bool theFlag )

void QgsAttributeTableDialog::columnBoxInit()
{
QgsFieldMap fieldMap = mLayer->pendingFields();
QgsFieldMap::Iterator it = fieldMap.begin();
const QgsFields& fields = mLayer->pendingFields();

mColumnBox->clear();

for ( ; it != fieldMap.end(); ++it )
if ( mLayer->editType( it.key() ) != QgsVectorLayer::Hidden )
mColumnBox->addItem( it.value().name() );
for ( int idx = 0; idx < fields.count(); ++idx )
if ( mLayer->editType( idx ) != QgsVectorLayer::Hidden )
mColumnBox->addItem( fields[idx].name() );

mColumnBox->setCurrentIndex( mColumnBox->findText( mLayer->displayField() ) );
}

int QgsAttributeTableDialog::columnBoxColumnId()
{
QgsFieldMap fieldMap = mLayer->pendingFields();
QgsFieldMap::Iterator it = fieldMap.begin();
const QgsFields& fields = mLayer->pendingFields();

for ( ; it != fieldMap.end(); ++it )
if ( it.value().name() == mColumnBox->currentText() )
return it.key();
for ( int idx = 0; idx < fields.count(); ++idx )
if ( fields[idx].name() == mColumnBox->currentText() )
return idx;

return 0;
}
Expand Down Expand Up @@ -620,7 +618,7 @@ void QgsAttributeTableDialog::search()
{

QString fieldName = mColumnBox->currentText();
const QgsFieldMap& flds = mLayer->pendingFields();
const QgsFields& flds = mLayer->pendingFields();
int fldIndex = mLayer->fieldNameIndex( fieldName );
QVariant::Type fldType = flds[fldIndex].type();
bool numeric = ( fldType == QVariant::Int || fldType == QVariant::Double );
Expand Down
15 changes: 8 additions & 7 deletions src/app/qgsattributetypedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ void QgsAttributeTypeDialog::setIndex( int index, QgsVectorLayer::EditType editT
int max = INT_MAX;
while ( mLayer->nextFeature( f ) )
{
QVariant val = f.attributeMap()[index];
QVariant val = f.attribute( index );
if ( val.isValid() && !val.isNull() )
{
int valInt = val.toInt();
Expand All @@ -344,7 +344,7 @@ void QgsAttributeTypeDialog::setIndex( int index, QgsVectorLayer::EditType editT
rangeWidget->addItems( QStringList() << tr( "Editable" ) << tr( "Slider" ) );
while ( mLayer->nextFeature( f ) )
{
QVariant val = f.attributeMap()[index];
QVariant val = f.attribute( index );
if ( val.isValid() && !val.isNull() )
{
double dVal = val.toDouble();
Expand Down Expand Up @@ -644,12 +644,13 @@ void QgsAttributeTypeDialog::updateLayerColumns( int idx )

valueRelationFilterColumn->addItem( tr( "No filter" ), -1 );

const QgsFieldMap &fields = vl->pendingFields();
for ( QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it )
const QgsFields &fields = vl->pendingFields();
for ( int idx = 0; idx < fields.count(); ++idx )
{
valueRelationKeyColumn->addItem( it->name() );
valueRelationValueColumn->addItem( it->name() );
valueRelationFilterColumn->addItem( it->name(), it.key() );
QString fieldName = fields[idx].name();
valueRelationKeyColumn->addItem( fieldName );
valueRelationValueColumn->addItem( fieldName );
valueRelationFilterColumn->addItem( fieldName, idx );
}

valueRelationKeyColumn->setCurrentIndex( valueRelationKeyColumn->findText( mValueRelationData.mKey ) );
Expand Down
8 changes: 4 additions & 4 deletions src/app/qgsattributetypeloaddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ void QgsAttributeTypeLoadDialog::createPreview( int fieldIndex, bool full )
QMap<QString, QVariant> valueMap;
while ( vLayer->nextFeature( f ) )
{
QVariant val1 = f.attributeMap()[idx];
QVariant val2 = f.attributeMap()[idx2];
QVariant val1 = f.attribute( idx );
QVariant val2 = f.attribute( idx2 );
if ( val1.isValid() && !val1.isNull() && !val1.toString().isEmpty()
&& val2.isValid() && !val2.isNull() && !val2.toString().isEmpty() )
{
Expand Down Expand Up @@ -188,10 +188,10 @@ void QgsAttributeTypeLoadDialog::loadDataToValueMap()
QgsFeature f;
while ( vLayer->nextFeature( f ) )
{
QVariant val = f.attributeMap()[idx];
QVariant val = f.attribute( idx );
if ( val.isValid() && !val.isNull() && !val.toString().isEmpty() )
{
mValueMap.insert( f.attributeMap()[idx2].toString(), val );
mValueMap.insert( f.attribute( idx2 ).toString(), val );
}
}
dataProvider->enableGeometrylessFeatures( false );
Expand Down
10 changes: 5 additions & 5 deletions src/app/qgsclipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ void QgsClipboard::replaceWithCopyOf( QgsVectorLayer *src )
textFields += "wkt_geom";
}

for ( QgsFieldMap::const_iterator fit = mFeatureFields.begin(); fit != mFeatureFields.end(); ++fit )
for ( int idx = 0; idx < mFeatureFields.count(); ++idx )
{
textFields += fit->name();
textFields += mFeatureFields[idx].name();
}
textLines += textFields.join( "\t" );
textFields.clear();

// then the field contents
for ( QgsFeatureList::iterator it = mFeatureClipboard.begin(); it != mFeatureClipboard.end(); ++it )
{
QgsAttributeMap attributes = it->attributeMap();
const QgsAttributes& attributes = it->attributes();

// TODO: Set up Paste Transformations to specify the order in which fields are added.
if ( copyWKT )
Expand All @@ -91,10 +91,10 @@ void QgsClipboard::replaceWithCopyOf( QgsVectorLayer *src )
}

// QgsDebugMsg("about to traverse fields.");
for ( QgsAttributeMap::iterator it2 = attributes.begin(); it2 != attributes.end(); ++it2 )
for ( int idx = 0; idx < attributes.count(); ++idx )
{
// QgsDebugMsg(QString("inspecting field '%1'.").arg(it2->toString()));
textFields += it2->toString();
textFields += attributes[idx].toString();
}

textLines += textFields.join( "\t" );
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsclipboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class QgsClipboard
/*
* source fields
*/
const QgsFieldMap &fields() { return mFeatureFields; }
const QgsFields &fields() { return mFeatureFields; }

private:

Expand All @@ -139,7 +139,7 @@ class QgsClipboard
involves a deep copy anyway.
*/
QgsFeatureList mFeatureClipboard;
QgsFieldMap mFeatureFields;
QgsFields mFeatureFields;
QgsCoordinateReferenceSystem mCRS;
};

Expand Down
10 changes: 5 additions & 5 deletions src/app/qgscontinuouscolordialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ QgsContinuousColorDialog::QgsContinuousColorDialog( QgsVectorLayer * layer )
QObject::connect( btnMaxValue, SIGNAL( clicked() ), this, SLOT( selectMaximumColor() ) );

//find out the numerical fields of mVectorLayer
const QgsFieldMap & fields = mVectorLayer->pendingFields();
const QgsFields & fields = mVectorLayer->pendingFields();
QString displayName;

for ( QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it )
for ( int idx = 0; idx < fields.count(); ++idx )
{
QVariant::Type type = it->type();
QVariant::Type type = fields[idx].type();
if ( type == QVariant::Int || type == QVariant::Double || type == QVariant::LongLong )
{
displayName = mVectorLayer->attributeDisplayName( it.key() );
classificationComboBox->addItem( displayName, it.key() );
displayName = mVectorLayer->attributeDisplayName( idx );
classificationComboBox->addItem( displayName, idx );
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/app/qgsdelattrdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ QgsDelAttrDialog::QgsDelAttrDialog( const QgsVectorLayer* vl ): QDialog()
if ( vl )
{
listBox2->clear();
const QgsFieldMap layerAttributes = vl->pendingFields();
QgsFieldMap::const_iterator attIt = layerAttributes.constBegin();
for ( ; attIt != layerAttributes.constEnd(); ++attIt )
const QgsFields& layerAttributes = vl->pendingFields();
for ( int idx = 0; idx < layerAttributes.count(); ++idx )
{
QListWidgetItem* item = new QListWidgetItem( attIt.value().name(), listBox2 );
item->setData( Qt::UserRole, attIt.key() );
QListWidgetItem* item = new QListWidgetItem( layerAttributes[idx].name(), listBox2 );
item->setData( Qt::UserRole, idx );
}
}
}
Expand Down
28 changes: 11 additions & 17 deletions src/app/qgsdiagramproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,30 +103,24 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
mScaleDependencyComboBox->addItem( tr( "Area" ), true );
mScaleDependencyComboBox->addItem( tr( "Diameter" ), false );

mDataDefinedXComboBox->addItem( tr( "None" ), -1 );
mDataDefinedYComboBox->addItem( tr( "None" ), -1 );

//insert all attributes into the combo boxes
const QgsFieldMap& layerFields = layer->pendingFields();
QgsFieldMap::const_iterator fieldIt = layerFields.constBegin();
for ( ; fieldIt != layerFields.constEnd(); ++fieldIt )
const QgsFields& layerFields = layer->pendingFields();
for ( int idx = 0; idx < layerFields.count(); ++idx )
{
QTreeWidgetItem *newItem = new QTreeWidgetItem( mAttributesTreeWidget );
newItem->setText( 0, fieldIt.value().name() );
newItem->setData( 0, Qt::UserRole, fieldIt.key() );
newItem->setText( 0, layerFields[idx].name() );
newItem->setData( 0, Qt::UserRole, idx );
newItem->setFlags( newItem->flags() & ~Qt::ItemIsDropEnabled );
if ( fieldIt.value().type() != QVariant::String )
if ( layerFields[idx].type() != QVariant::String )
{
mSizeAttributeComboBox->addItem( fieldIt.value().name(), fieldIt.key() );
mSizeAttributeComboBox->addItem( layerFields[idx].name(), idx );
}
}

mDataDefinedXComboBox->addItem( tr( "None" ), -1 );
for ( fieldIt = layerFields.constBegin(); fieldIt != layerFields.constEnd(); ++fieldIt )
{
mDataDefinedXComboBox->addItem( fieldIt.value().name(), fieldIt.key() );
}
mDataDefinedYComboBox->addItem( tr( "None" ), -1 );
for ( fieldIt = layerFields.constBegin(); fieldIt != layerFields.constEnd(); ++fieldIt )
{
mDataDefinedYComboBox->addItem( fieldIt.value().name(), fieldIt.key() );
mDataDefinedXComboBox->addItem( layerFields[idx].name(), idx );
mDataDefinedYComboBox->addItem( layerFields[idx].name(), idx );
}

const QgsDiagramRendererV2* dr = layer->diagramRenderer();
Expand Down
39 changes: 19 additions & 20 deletions src/app/qgsfeatureaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,18 @@ bool QgsFeatureAction::editFeature()
}
else
{
QgsAttributeMap src = mFeature.attributeMap();
QgsAttributes src = mFeature.attributes();

if ( dialog->exec() )
{
mLayer->beginEditCommand( text() );

const QgsAttributeMap &dst = mFeature.attributeMap();
for ( QgsAttributeMap::const_iterator it = dst.begin(); it != dst.end(); it++ )
const QgsAttributes &dst = mFeature.attributes();
for ( int i = 0; i < dst.count(); ++i )
{
if ( !src.contains( it.key() ) || it.value() != src[it.key()] )
if ( dst[i] != src[i] )
{
mLayer->changeAttributeValue( mFeature.id(), it.key(), it.value() );
mLayer->changeAttributeValue( mFeature.id(), i, dst[i] );
}
}

Expand Down Expand Up @@ -139,17 +139,18 @@ bool QgsFeatureAction::addFeature()
QgsDebugMsg( QString( "reuseLastValues: %1" ).arg( reuseLastValues ) );

// add the fields to the QgsFeature
const QgsFieldMap fields = mLayer->pendingFields();
for ( QgsFieldMap::const_iterator it = fields.constBegin(); it != fields.constEnd(); ++it )
const QgsFields& fields = mLayer->pendingFields();
mFeature.initAttributes( fields.count() );
for ( int idx = 0; idx < fields.count(); ++idx )
{
if ( reuseLastValues && mLastUsedValues.contains( mLayer ) && mLastUsedValues[ mLayer ].contains( it.key() ) )
if ( reuseLastValues && mLastUsedValues.contains( mLayer ) && mLastUsedValues[ mLayer ].contains( idx ) )
{
QgsDebugMsg( QString( "reusing %1 for %2" ).arg( mLastUsedValues[ mLayer ][ it.key()].toString() ).arg( it.key() ) );
mFeature.addAttribute( it.key(), mLastUsedValues[ mLayer ][ it.key()] );
QgsDebugMsg( QString( "reusing %1 for %2" ).arg( mLastUsedValues[ mLayer ][idx].toString() ).arg( idx ) );
mFeature.setAttribute( idx, mLastUsedValues[ mLayer ][idx] );
}
else
{
mFeature.addAttribute( it.key(), provider->defaultValue( it.key() ) );
mFeature.setAttribute( idx, provider->defaultValue( idx ) );
}
}

Expand All @@ -165,24 +166,22 @@ bool QgsFeatureAction::addFeature()
}
else
{
QgsAttributeMap origValues;
QgsAttributes origValues;
if ( reuseLastValues )
origValues = mFeature.attributeMap();
origValues = mFeature.attributes();

QgsAttributeDialog *dialog = newDialog( false );
if ( dialog->exec() )
{
if ( reuseLastValues )
{
for ( QgsFieldMap::const_iterator it = fields.constBegin(); it != fields.constEnd(); ++it )
for ( int idx = 0; idx < fields.count(); ++idx )
{
const QgsAttributeMap &newValues = mFeature.attributeMap();
if ( newValues.contains( it.key() )
&& origValues.contains( it.key() )
&& origValues[ it.key()] != newValues[ it.key()] )
const QgsAttributes &newValues = mFeature.attributes();
if ( origValues[idx] != newValues[idx] )
{
QgsDebugMsg( QString( "saving %1 for %2" ).arg( mLastUsedValues[ mLayer ][ it.key()].toString() ).arg( it.key() ) );
mLastUsedValues[ mLayer ][ it.key()] = newValues[ it.key()];
QgsDebugMsg( QString( "saving %1 for %2" ).arg( mLastUsedValues[ mLayer ][idx].toString() ).arg( idx ) );
mLastUsedValues[ mLayer ][idx] = newValues[idx];
}
}
}
Expand Down
24 changes: 8 additions & 16 deletions src/app/qgsfieldcalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,13 @@ void QgsFieldCalculator::accept()
}

//get index of the new field
const QgsFieldMap fieldList = mVectorLayer->pendingFields();
const QgsFields& fields = mVectorLayer->pendingFields();

QgsFieldMap::const_iterator it = fieldList.constBegin();
for ( ; it != fieldList.constEnd(); ++it )
for ( int idx = 0; idx < fields.count(); ++idx )
{
if ( it.value().name() == mOutputFieldNameLineEdit->text() )
if ( fields[idx].name() == mOutputFieldNameLineEdit->text() )
{
mAttributeId = it.key();
mAttributeId = idx;
break;
}
}
Expand All @@ -159,9 +158,6 @@ void QgsFieldCalculator::accept()
bool onlySelected = mOnlyUpdateSelectedCheckBox->isChecked();
QgsFeatureIds selectedIds = mVectorLayer->selectedFeaturesIds();

// block layerModified signals (that would trigger table update)
mVectorLayer->blockSignals( true );

bool useGeometry = exp.needsGeometry();
int rownum = 1;

Expand Down Expand Up @@ -194,9 +190,6 @@ void QgsFieldCalculator::accept()
rownum++;
}

// stop blocking layerModified signals and make sure that one layerModified signal is emitted
mVectorLayer->blockSignals( false );
mVectorLayer->setModified( true, false );

if ( !calculationSuccess )
{
Expand Down Expand Up @@ -282,15 +275,14 @@ void QgsFieldCalculator::populateFields()
if ( !mVectorLayer )
return;

const QgsFieldMap fieldMap = mVectorLayer->pendingFields();
QgsFieldMap::const_iterator fieldIt = fieldMap.constBegin();
for ( ; fieldIt != fieldMap.constEnd(); ++fieldIt )
const QgsFields& fields = mVectorLayer->pendingFields();
for ( int idx = 0; idx < fields.count(); ++idx )
{

QString fieldName = fieldIt.value().name();
QString fieldName = fields[idx].name();

//insert into field list and field combo box
mFieldMap.insert( fieldName, fieldIt.key() );
mFieldMap.insert( fieldName, idx );
mExistingFieldComboBox->addItem( fieldName );
}
}
Expand Down
13 changes: 6 additions & 7 deletions src/app/qgsfieldsproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ void QgsFieldsProperties::loadAttributeEditorTree()
void QgsFieldsProperties::loadRows()
{
disconnect( mAttributesList, SIGNAL( cellChanged( int, int ) ), this, SLOT( attributesListCellChanged( int, int ) ) );
const QgsFieldMap &fields = mLayer->pendingFields();
const QgsFields &fields = mLayer->pendingFields();

mAttributesList->clear();

Expand All @@ -324,9 +324,8 @@ void QgsFieldsProperties::loadRows()
mAttributesList->setSelectionMode( QAbstractItemView::ExtendedSelection );
mAttributesList->verticalHeader()->hide();

int row = 0;
for ( QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); it++, row++ )
setRow( row, it.key(), it.value() );
for ( int i = 0; i < fields.count(); ++i )
setRow( i, i, fields[i] );

mAttributesList->resizeColumnsToContents();
connect( mAttributesList, SIGNAL( cellChanged( int, int ) ), this, SLOT( attributesListCellChanged( int, int ) ) );
Expand Down Expand Up @@ -534,7 +533,7 @@ void QgsFieldsProperties::attributeTypeDialog()

void QgsFieldsProperties::attributeAdded( int idx )
{
const QgsFieldMap &fields = mLayer->pendingFields();
const QgsFields &fields = mLayer->pendingFields();
int row = mAttributesList->rowCount();
mAttributesList->insertRow( row );
setRow( row, idx, fields[idx] );
Expand Down Expand Up @@ -679,9 +678,9 @@ void QgsFieldsProperties::attributesListCellChanged( int row, int column )
{
int idx = mAttributesList->item( row, attrIdCol )->text().toInt();

const QgsFieldMap &fields = mLayer->pendingFields();
const QgsFields &fields = mLayer->pendingFields();

if ( !fields.contains( idx ) )
if ( idx >= fields.count() )
{
return; // index must be wrong
}
Expand Down
13 changes: 6 additions & 7 deletions src/app/qgsgraduatedsymboldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ QgsGraduatedSymbolDialog::QgsGraduatedSymbolDialog( QgsVectorLayer * layer ): QD
setOrientation( Qt::Vertical );

//find out the numerical fields of mVectorLayer
const QgsFieldMap & fields = layer->pendingFields();
const QgsFields & fields = layer->pendingFields();
QString displayName;

for ( QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it )
for ( int idx = 0; idx < fields.count(); ++idx )
{
QVariant::Type type = ( *it ).type();
QVariant::Type type = fields[idx].type();
if ( type == QVariant::Int || type == QVariant::Double || type == QVariant::LongLong )
{
displayName = layer->attributeDisplayName( it.key() );
displayName = layer->attributeDisplayName( idx );
classificationComboBox->addItem( displayName );
mFieldMap.insert( std::make_pair( displayName, it.key() ) );
mFieldMap.insert( std::make_pair( displayName, idx ) );
}
}

Expand Down Expand Up @@ -503,8 +503,7 @@ int QgsGraduatedSymbolDialog::quantilesFromVectorLayer( std::list<double>& resul
mVectorLayer->select( attList, QgsRectangle(), false );
while ( mVectorLayer->nextFeature( currentFeature ) )
{
currentAttributeMap = currentFeature.attributeMap();
currentValue = currentAttributeMap[attributeIndex].toDouble();
currentValue = currentFeature.attribute( attributeIndex ).toDouble();
attributeValues[index] = currentValue;
++index;
}
Expand Down
45 changes: 21 additions & 24 deletions src/app/qgsidentifyresults.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,35 +204,31 @@ void QgsIdentifyResults::addFeature( QgsVectorLayer *vlayer,
mFeatures << f;
layItem->addChild( featItem );

for ( QgsAttributeMap::const_iterator it = f.attributeMap().begin(); it != f.attributeMap().end(); it++ )
const QgsFields &fields = vlayer->pendingFields();
const QgsAttributes& attrs = f.attributes();
for ( int i = 0; i < attrs.count(); ++i )
{
QTreeWidgetItem *attrItem = new QTreeWidgetItem( QStringList() << QString::number( it.key() ) << it.value().toString() );

const QgsFieldMap &fields = vlayer->pendingFields();

QgsFieldMap::const_iterator fit = fields.find( it.key() );
if ( fit == fields.constEnd() )
{
delete attrItem;
if ( i >= fields.count() )
continue;
}

attrItem->setData( 0, Qt::DisplayRole, vlayer->attributeDisplayName( it.key() ) );
attrItem->setData( 0, Qt::UserRole, fit->name() );
attrItem->setData( 0, Qt::UserRole + 1, it.key() );
QTreeWidgetItem *attrItem = new QTreeWidgetItem( QStringList() << QString::number( i ) << attrs[i].toString() );

attrItem->setData( 0, Qt::DisplayRole, vlayer->attributeDisplayName( i ) );
attrItem->setData( 0, Qt::UserRole, fields[i].name() );
attrItem->setData( 0, Qt::UserRole + 1, i );

QVariant value = it.value();
QVariant value = attrs[i];
attrItem->setData( 1, Qt::UserRole, value );

switch ( vlayer->editType( it.key() ) )
switch ( vlayer->editType( i ) )
{
case QgsVectorLayer::Hidden:
// skip the item
delete attrItem;
continue;

case QgsVectorLayer::ValueMap:
value = vlayer->valueMap( it.key() ).key( it->toString(), QString( "(%1)" ).arg( it->toString() ) );
value = vlayer->valueMap( i ).key( value.toString(), QString( "(%1)" ).arg( value.toString() ) );
break;

default:
Expand All @@ -241,7 +237,7 @@ void QgsIdentifyResults::addFeature( QgsVectorLayer *vlayer,

attrItem->setData( 1, Qt::DisplayRole, value );

if ( fit->name() == vlayer->displayField() )
if ( fields[i].name() == vlayer->displayField() )
{
featItem->setText( 0, attrItem->text( 0 ) );
featItem->setText( 1, attrItem->text( 1 ) );
Expand Down Expand Up @@ -622,11 +618,12 @@ void QgsIdentifyResults::doAction( QTreeWidgetItem *item, int action )
{
QString fieldName = item->data( 0, Qt::DisplayRole ).toString();

for ( QgsFieldMap::const_iterator it = layer->pendingFields().begin(); it != layer->pendingFields().end(); it++ )
const QgsFields& fields = layer->pendingFields();
for ( int fldIdx = 0; fldIdx < fields.count(); ++fldIdx )
{
if ( it->name() == fieldName )
if ( fields[fldIdx].name() == fieldName )
{
idx = it.key();
idx = fldIdx;
break;
}
}
Expand Down Expand Up @@ -1042,15 +1039,15 @@ void QgsIdentifyResults::copyFeatureAttributes()
QgsAttributeMap attributes;
retrieveAttributes( lstResults->currentItem(), attributes, idx );

const QgsFieldMap &fields = vlayer->pendingFields();
const QgsFields &fields = vlayer->pendingFields();

for ( QgsAttributeMap::const_iterator it = attributes.begin(); it != attributes.end(); it++ )
{
QgsFieldMap::const_iterator fit = fields.find( it.key() );
if ( fit == fields.constEnd() )
int attrIdx = it.key();
if ( attrIdx < 0 || attrIdx >= fields.count() )
continue;

text += QString( "%1: %2\n" ).arg( fit->name() ).arg( it.value().toString() );
text += QString( "%1: %2\n" ).arg( fields[attrIdx].name() ).arg( it.value().toString() );
}

QgsDebugMsg( QString( "set clipboard: %1" ).arg( text ) );
Expand Down
Loading