145 changes: 75 additions & 70 deletions python/core/qgsvectorlayereditbuffer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -7,99 +7,104 @@ class QgsVectorLayerEditBuffer : QObject
#include "qgsvectorlayereditbuffer.h"
%End

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

/** Returns true if the provider has been modified since the last commit */
bool isModified() const;
/** 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 );
/** 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 );
/** 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 );
/** 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 );
/** 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 );
/** 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 );
/** 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 );
/** 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.
/**
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.
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);
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();
/** 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();
/** New features which are not commited. */
const QgsFeatureMap& addedFeatures();

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

/** added attributes fields which are not commited */
const QList<QgsField>& addedAttributes();
/** deleted attributes fields which are not commited. The list is kept sorted. */
const QgsAttributeList& deletedAttributeIds();

/** Changed geometries which are not commited. */
const QgsGeometryMap& changedGeometries();
/** added attributes fields which are not commited */
const QList<QgsField>& addedAttributes();

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

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

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 );
protected slots:
void undoIndexChanged( int index );

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

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: 2 additions & 0 deletions python/core/qgsvectorlayerimport.sip
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,7 @@ class QProgressDialog;
/** flush the buffer writing the features to the new layer */
bool flushBuffer();

/** create index */
bool createSpatialIndex();
};

21 changes: 0 additions & 21 deletions python/core/raster/qgsrasterlayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -233,22 +233,6 @@ class QgsRasterLayer : QgsMapLayer
/** \brief Accessor for color shader algorithm */
QString colorShadingAlgorithmAsString() const;

/** \brief Wrapper for GDALComputeRasterMinMax with the estimate option */
// void computeMinimumMaximumEstimates( int theBand, double* theMinMax );

/** \brief Wrapper for GDALComputeRasterMinMax with the estimate option */
// void computeMinimumMaximumEstimates( QString theBand, double* theMinMax );

/** \brief Wrapper for GDALComputeRasterMinMax with the estimate option
\note added in v1.6 */
//void computeMinimumMaximumEstimates( int theBand, double& theMin /Out/, double& theMax /Out/ );

/** \brief Compute the actual minimum maximum pixel values based on the current (last) display extent */
// void computeMinimumMaximumFromLastExtent( int theBand, double* theMinMax );

/** \brief Compute the actual minimum maximum pixel values based on the current (last) display extent */
// void computeMinimumMaximumFromLastExtent( QString theBand, double* theMinMax );

/** \brief Compute the actual minimum maximum pixel values based on the current (last) display extent
\note added in v1.6 */
//void computeMinimumMaximumFromLastExtent( int theBand, double& theMin /Out/, double& theMax /Out/ );
Expand Down Expand Up @@ -406,11 +390,6 @@ class QgsRasterLayer : QgsMapLayer
/** \brief Draws a preview of the rasterlayer into a pixmap */
QPixmap previewAsPixmap( QSize size, QColor bgColor = QColor( 255, 255, 255 ) );

/** \brief Draws a thumbnail of the rasterlayer into the supplied QImage pointer
* @note added in QGIS 1.6
* */
/* void thumbnailAsImage( QImage * thepImage ) /Deprecated/; */

/** \brief Emit a signal asking for a repaint. (inherited from maplayer) */
void triggerRepaint();

Expand Down
18 changes: 10 additions & 8 deletions src/app/qgsmaptoolpinlabels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,14 +442,16 @@ bool QgsMapToolPinLabels::pinUnpinLabel( QgsVectorLayer* vlayer,
{
QgsDebugMsg( QString( "Write to attribute table failed" ) );

// QgsDebugMsg( QString( "Undoing and removing failed command from layer's undo stack" ) );
// int lastCmdIndx = vlayer->undoStack()->count();
// const QgsUndoCommand* lastCmd = qobject_cast<const QgsUndoCommand *>( vlayer->undoStack()->command( lastCmdIndx ) );
// if ( lastCmd )
// {
// vlayer->undoEditCommand( lastCmd );
// delete vlayer->undoStack()->command( lastCmdIndx );
// }
#if 0
QgsDebugMsg( QString( "Undoing and removing failed command from layer's undo stack" ) );
int lastCmdIndx = vlayer->undoStack()->count();
const QgsUndoCommand* lastCmd = qobject_cast<const QgsUndoCommand *>( vlayer->undoStack()->command( lastCmdIndx ) );
if ( lastCmd )
{
vlayer->undoEditCommand( lastCmd );
delete vlayer->undoStack()->command( lastCmdIndx );
}
#endif

return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposerlegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
QgsComposerLegend::QgsComposerLegend( QgsComposition* composition )
: QgsComposerItem( composition )
, mTitle( tr( "Legend" ) )
, mFontColor( QColor( 0, 0, 0 ) )
, mBoxSpace( 2 )
, mColumnSpace( 2 )
, mGroupSpace( 2 )
Expand All @@ -43,7 +44,6 @@ QgsComposerLegend::QgsComposerLegend( QgsComposition* composition )
, mComposerMap( 0 )
, mSplitLayer( false )
, mEqualColumnWidth( false )
, mFontColor( QColor( 0, 0, 0 ) )
{
//QStringList idList = layerIdList();
//mLegendModel.setLayerSet( idList );
Expand Down
3 changes: 2 additions & 1 deletion src/core/composer/qgscomposition.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
QPointF snapPointToGrid( const QPointF& scenePoint ) const;

/**Snaps item position to align with other items (left / middle / right or top / middle / bottom
@param itemRectangle current item rectangle
@param item current item
@param alignX x-coordinate of align or -1 if not aligned to x
@param alignY y-coordinate of align or -1 if not aligned to y
@param dx item shift in x direction
Expand All @@ -253,6 +253,7 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene

/**Snaps position to align with the boundaries of other items
@param pos position to snap
@param excludeItem item to exclude
@param alignX snapped x coordinate or -1 if not snapped
@param alignY snapped y coordinate or -1 if not snapped
@return snapped position or original position if no snap*/
Expand Down
14 changes: 14 additions & 0 deletions src/core/qgsfeatureiterator.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgsfeatureiterator.cpp
---------------------
begin : Juli 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsfeatureiterator.h"


Expand Down
14 changes: 14 additions & 0 deletions src/core/qgsfeatureiterator.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgsfeatureiterator.h
---------------------
begin : Juli 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSFEATUREITERATOR_H
#define QGSFEATUREITERATOR_H

Expand Down
14 changes: 14 additions & 0 deletions src/core/qgsfeaturerequest.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgsfeaturerequest.cpp
---------------------
begin : Mai 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsfeaturerequest.h"

#include "qgsfield.h"
Expand Down
14 changes: 14 additions & 0 deletions src/core/qgsfeaturerequest.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgsfeaturerequest.h
---------------------
begin : Mai 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSFEATUREREQUEST_H
#define QGSFEATUREREQUEST_H

Expand Down
10 changes: 6 additions & 4 deletions src/core/qgsvectordataprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
RandomSelectGeometryAtId = 1 << 10,
/** DEPRECATED - do not use */
SequentialSelectGeometryAtId = 1 << 11,
CreateAttributeIndex = 1 << 12,
CreateAttributeIndex = 1 << 12,
/** Uses mEncoding for conversion of 8-bit strings to unicode */
SetEncoding = 1 << 13,
SetEncoding = 1 << 13,
};

/** bitmask of all provider's editing capabilities */
Expand Down Expand Up @@ -292,8 +292,10 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
QString mTypeDesc;
QString mTypeName;
QVariant::Type mType;
int mMinLen, mMaxLen;
int mMinPrec, mMaxPrec;
int mMinLen;
int mMaxLen;
int mMinPrec;
int mMaxPrec;
};

/**
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,
, mLabel( 0 )
, mLabelOn( false )
, mVertexMarkerOnlyForSelection( false )
, mEditorLayout( GeneratedLayout )
, mCache( new QgsVectorLayerCache( this ) )
, mEditBuffer( 0 )
, mEditorLayout( GeneratedLayout )
, mJoinBuffer( 0 )
, mDiagramRenderer( 0 )
, mDiagramLayerSettings( 0 )
Expand Down Expand Up @@ -4310,7 +4310,7 @@ QString QgsVectorLayer::metadata()
{
myMetadata += "<tr><td>";
myMetadata += tr( "Primary key attributes: " );
foreach( int idx, pkAttrList )
foreach ( int idx, pkAttrList )
{
myMetadata += pendingFields()[ idx ].name() + " ";
}
Expand Down
7 changes: 3 additions & 4 deletions src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class QgsMapToPixel;
class QgsLabel;
class QgsRectangle;
class QgsRenderer;
class QgsUndoCommand;
class QgsVectorDataProvider;
class QgsVectorOverlay;
class QgsSingleSymbolRendererV2;
Expand Down Expand Up @@ -449,9 +448,9 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
* @param useIntersect fetch only features that actually intersect the window (not just the bounding box)
*/
Q_DECL_DEPRECATED void select( QgsAttributeList fetchAttributes,
QgsRectangle rect = QgsRectangle(),
bool fetchGeometry = true,
bool useIntersect = false );
QgsRectangle rect = QgsRectangle(),
bool fetchGeometry = true,
bool useIntersect = false );

/**
* Query the provider for features specified in request.
Expand Down
20 changes: 17 additions & 3 deletions src/core/qgsvectorlayercache.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
/***************************************************************************
qgsvectorlayercache.cpp
---------------------
begin : Dezember 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsvectorlayercache.h"

#include "qgsvectorlayereditbuffer.h"

QgsVectorLayerCache::QgsVectorLayerCache(QgsVectorLayer* layer)
: L(layer)
QgsVectorLayerCache::QgsVectorLayerCache( QgsVectorLayer* layer )
: L( layer )
{
}

Expand All @@ -13,7 +27,7 @@ QgsVectorLayerCache::~QgsVectorLayerCache()
deleteCachedGeometries();
}

bool QgsVectorLayerCache::geometry(QgsFeatureId fid, QgsGeometry& geometry)
bool QgsVectorLayerCache::geometry( QgsFeatureId fid, QgsGeometry& geometry )
{
// no need to check changed geometries because all changed geometries are also cached

Expand Down
56 changes: 35 additions & 21 deletions src/core/qgsvectorlayercache.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgsvectorlayercache.h
---------------------
begin : Dezember 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSVECTORLAYERCACHE_H
#define QGSVECTORLAYERCACHE_H

Expand All @@ -7,39 +21,39 @@

class QgsVectorLayerCache
{
public:
QgsVectorLayerCache(QgsVectorLayer* layer);
~QgsVectorLayerCache();
public:
QgsVectorLayerCache( QgsVectorLayer* layer );
~QgsVectorLayerCache();

inline QgsGeometryMap& cachedGeometries() { return mCachedGeometries; }
inline QgsGeometryMap& cachedGeometries() { return mCachedGeometries; }

//! fetch geometry from cache, return true if successful
bool geometry(QgsFeatureId fid, QgsGeometry& geometry);
//! fetch geometry from cache, return true if successful
bool geometry( QgsFeatureId fid, QgsGeometry& geometry );

//! store a geometry in the cache
void cacheGeometry( QgsFeatureId fid, const QgsGeometry& geom );
//! store a geometry in the cache
void cacheGeometry( QgsFeatureId fid, const QgsGeometry& geom );

//! get rid of the cached geometry
void removeGeometry( QgsFeatureId fid ) { mCachedGeometries.remove(fid); }
//! get rid of the cached geometry
void removeGeometry( QgsFeatureId fid ) { mCachedGeometries.remove( fid ); }


/** Deletes the geometries in mCachedGeometries */
void deleteCachedGeometries();
/** Deletes the geometries in mCachedGeometries */
void deleteCachedGeometries();

void setCachedGeometriesRect( const QgsRectangle& extent ) { mCachedGeometriesRect = extent; }
const QgsRectangle& cachedGeometriesRect() { return mCachedGeometriesRect; }
void setCachedGeometriesRect( const QgsRectangle& extent ) { mCachedGeometriesRect = extent; }
const QgsRectangle& cachedGeometriesRect() { return mCachedGeometriesRect; }

protected:
protected:

inline QgsVectorLayerEditBuffer* editBuffer() { return L->editBuffer(); }
inline QgsVectorLayerEditBuffer* editBuffer() { return L->editBuffer(); }

QgsVectorLayer* L;
QgsVectorLayer* L;

/** cache of the committed geometries retrieved *for the current display* */
QgsGeometryMap mCachedGeometries;
/** cache of the committed geometries retrieved *for the current display* */
QgsGeometryMap mCachedGeometries;

/** extent for which there are cached geometries */
QgsRectangle mCachedGeometriesRect;
/** extent for which there are cached geometries */
QgsRectangle mCachedGeometriesRect;

};

Expand Down
50 changes: 32 additions & 18 deletions src/core/qgsvectorlayereditbuffer.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgsvectorlayereditbuffer.cpp
---------------------
begin : Dezember 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsvectorlayereditbuffer.h"

#include "qgsgeometry.h"
Expand All @@ -7,10 +21,10 @@
#include "qgsvectorlayer.h"


QgsVectorLayerEditBuffer::QgsVectorLayerEditBuffer(QgsVectorLayer* layer)
: L(layer)
QgsVectorLayerEditBuffer::QgsVectorLayerEditBuffer( QgsVectorLayer* layer )
: L( layer )
{
connect(L->undoStack(), SIGNAL(indexChanged(int)), this, SLOT(undoIndexChanged(int))); // TODO[MD]: queued?
connect( L->undoStack(), SIGNAL( indexChanged( int ) ), this, SLOT( undoIndexChanged( int ) ) ); // TODO[MD]: queued?
}

QgsVectorLayerEditBuffer::~QgsVectorLayerEditBuffer()
Expand All @@ -26,8 +40,8 @@ bool QgsVectorLayerEditBuffer::isModified() const

void QgsVectorLayerEditBuffer::undoIndexChanged( int index )
{
qDebug("undo index changed %d", index);
Q_UNUSED(index);
qDebug( "undo index changed %d", index );
Q_UNUSED( index );
emit layerModified();
}

Expand All @@ -40,7 +54,7 @@ void QgsVectorLayerEditBuffer::updateFields( QgsFields& fields )
fields.remove( mDeletedAttributeIds[i] );
}
// add new fields
for (int i = 0; i < mAddedAttributes.count(); ++i)
for ( int i = 0; i < mAddedAttributes.count(); ++i )
{
fields.append( mAddedAttributes[i], QgsFields::OriginEdit, i );
}
Expand Down Expand Up @@ -87,7 +101,7 @@ bool QgsVectorLayerEditBuffer::addFeature( QgsFeature& f )
}

int layerFieldCount = L->dataProvider()->fields().count() + mAddedAttributes.count() - mDeletedAttributeIds.count();
if (layerFieldCount != f.attributes().count())
if ( layerFieldCount != f.attributes().count() )
return false;

// TODO: check correct geometry type
Expand Down Expand Up @@ -120,7 +134,7 @@ bool QgsVectorLayerEditBuffer::deleteFeature( QgsFeatureId fid )

if ( FID_IS_NEW( fid ) )
{
if (!mAddedFeatures.contains(fid))
if ( !mAddedFeatures.contains( fid ) )
return false;
}
else // existing feature
Expand All @@ -146,7 +160,7 @@ bool QgsVectorLayerEditBuffer::changeGeometry( QgsFeatureId fid, QgsGeometry* ge

if ( FID_IS_NEW( fid ) )
{
if (!mAddedFeatures.contains(fid))
if ( !mAddedFeatures.contains( fid ) )
return false;
}

Expand All @@ -164,12 +178,12 @@ bool QgsVectorLayerEditBuffer::changeAttributeValue( QgsFeatureId fid, int field

if ( FID_IS_NEW( fid ) )
{
if (!mAddedFeatures.contains(fid))
if ( !mAddedFeatures.contains( fid ) )
return false;
}

if ( field < 0 || field >= L->pendingFields().count() ||
L->pendingFields().fieldOrigin(field) == QgsFields::OriginJoin )
L->pendingFields().fieldOrigin( field ) == QgsFields::OriginJoin )
return false;

L->undoStack()->push( new QgsVectorLayerUndoCommandChangeAttribute( this, fid, field, value ) );
Expand Down Expand Up @@ -209,11 +223,11 @@ bool QgsVectorLayerEditBuffer::deleteAttribute( int index )
return false;

// find out source of the field
QgsFields::FieldOrigin origin = L->pendingFields().fieldOrigin(index);
int originIndex = L->pendingFields().fieldOriginIndex(index);
QgsFields::FieldOrigin origin = L->pendingFields().fieldOrigin( index );
int originIndex = L->pendingFields().fieldOriginIndex( index );

if ( origin == QgsFields::OriginProvider && mDeletedAttributeIds.contains( originIndex ) )
return false;
return false;

if ( origin == QgsFields::OriginJoin )
return false;
Expand All @@ -223,7 +237,7 @@ bool QgsVectorLayerEditBuffer::deleteAttribute( int index )
}


bool QgsVectorLayerEditBuffer::commitChanges(QStringList& commitErrors)
bool QgsVectorLayerEditBuffer::commitChanges( QStringList& commitErrors )
{
QgsVectorDataProvider* provider = L->dataProvider();
commitErrors.clear();
Expand Down Expand Up @@ -470,7 +484,7 @@ void QgsVectorLayerEditBuffer::handleAttributeAdded( int index )
// go through the changed attributes map and adapt indices
for ( int i = 0; i < mChangedAttributeValues.size(); ++i )
{
updateAttributeMapIndex( mChangedAttributeValues[i], index, +1 );
updateAttributeMapIndex( mChangedAttributeValues[i], index, + 1 );
}

// go through added features and adapt attributes
Expand All @@ -489,7 +503,7 @@ void QgsVectorLayerEditBuffer::handleAttributeDeleted( int index )
{
QgsAttributeMap& attrMap = mChangedAttributeValues[i];
// remove the attribute
if (attrMap.contains(index))
if ( attrMap.contains( index ) )
attrMap.remove( index );

// update attribute indices
Expand All @@ -513,7 +527,7 @@ void QgsVectorLayerEditBuffer::updateAttributeMapIndex( QgsAttributeMap& map, in
for ( QgsAttributeMap::const_iterator it = map.begin(); it != map.end(); ++it )
{
int attrIndex = it.key();
updatedMap.insert( attrIndex < index ? attrIndex : attrIndex+offset, it.value() );
updatedMap.insert( attrIndex < index ? attrIndex : attrIndex + offset, it.value() );
}
map = updatedMap;
}
Expand Down
238 changes: 125 additions & 113 deletions src/core/qgsvectorlayereditbuffer.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgsvectorlayereditbuffer.h
---------------------
begin : Dezember 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSVECTORLAYEREDITBUFFER_H
#define QGSVECTORLAYEREDITBUFFER_H

Expand All @@ -10,7 +24,6 @@
#include "qgsrectangle.h"
#include "qgssnapper.h"

class QgsUndoCommand;
class QgsVectorLayer;

typedef QList<int> QgsAttributeList;
Expand All @@ -19,162 +32,161 @@ typedef QMap<QgsFeatureId, QgsFeature> QgsFeatureMap;

class CORE_EXPORT QgsVectorLayerEditBuffer : public QObject
{
Q_OBJECT
public:
QgsVectorLayerEditBuffer(QgsVectorLayer* layer);
~QgsVectorLayerEditBuffer();
Q_OBJECT
public:
QgsVectorLayerEditBuffer( QgsVectorLayer* layer );
~QgsVectorLayerEditBuffer();

/** Returns true if the provider has been modified since the last commit */
bool isModified() const;
/** 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 );
/** Adds a feature
@param f feature to add
@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 );
/** 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 );
/** 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 );
/** 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 );
/** 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 );
/** 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 );
/** 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.
/**
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.
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);
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();
/** Stop editing and discard the edits */
void rollBack();



/** New features which are not commited. */
inline const QgsFeatureMap& addedFeatures() { return mAddedFeatures; }
/** New features which are not commited. */
inline const QgsFeatureMap& addedFeatures() { return mAddedFeatures; }

/** Changed attributes values which are not commited */
inline const QgsChangedAttributesMap& changedAttributeValues() { return mChangedAttributeValues; }
/** Changed attributes values which are not commited */
inline const QgsChangedAttributesMap& changedAttributeValues() { return mChangedAttributeValues; }

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

/** added attributes fields which are not commited */
inline const QList<QgsField>& addedAttributes() { return mAddedAttributes; }
/** added attributes fields which are not commited */
inline const QList<QgsField>& addedAttributes() { return mAddedAttributes; }

/** Changed geometries which are not commited. */
inline const QgsGeometryMap& changedGeometries() { return mChangedGeometries; }
/** Changed geometries which are not commited. */
inline const QgsGeometryMap& changedGeometries() { return mChangedGeometries; }

//QString dumpEditBuffer();
//QString dumpEditBuffer();


protected slots:
void undoIndexChanged( int index );
protected slots:
void undoIndexChanged( int index );

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

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

protected:
protected:

void updateFields( QgsFields& fields );
void updateFields( QgsFields& fields );

/** Update feature with uncommited geometry updates */
void updateFeatureGeometry( QgsFeature &f );
/** Update feature with uncommited geometry updates */
void updateFeatureGeometry( QgsFeature &f );

/** Update feature with uncommited attribute updates */
void updateChangedAttributes( QgsFeature &f );
/** Update feature with uncommited attribute updates */
void updateChangedAttributes( QgsFeature &f );

/** update added and changed features after addition of an attribute */
void handleAttributeAdded( int index );
/** update added and changed features after addition of an attribute */
void handleAttributeAdded( int index );

/** update added and changed features after removal of an attribute */
void handleAttributeDeleted( int index );
/** update added and changed features after removal of an attribute */
void handleAttributeDeleted( int index );


/** Updates an index in an attribute map to a new value (for updates of changed attributes) */
void updateAttributeMapIndex( QgsAttributeMap& attrs, int index, int offset ) const;
/** Updates an index in an attribute map to a new value (for updates of changed attributes) */
void updateAttributeMapIndex( QgsAttributeMap& attrs, int index, int offset ) const;

void updateLayerFields();
void updateLayerFields();

protected:
QgsVectorLayer* L;
friend class QgsVectorLayer;
friend class QgsVectorLayerFeatureIterator;
protected:
QgsVectorLayer* L;
friend class QgsVectorLayer;
friend class QgsVectorLayerFeatureIterator;

friend class QgsVectorLayerUndoCommand;
friend class QgsVectorLayerUndoCommandAddFeature;
friend class QgsVectorLayerUndoCommandDeleteFeature;
friend class QgsVectorLayerUndoCommandChangeGeometry;
friend class QgsVectorLayerUndoCommandChangeAttribute;
friend class QgsVectorLayerUndoCommandAddAttribute;
friend class QgsVectorLayerUndoCommandDeleteAttribute;
friend class QgsVectorLayerUndoCommand;
friend class QgsVectorLayerUndoCommandAddFeature;
friend class QgsVectorLayerUndoCommandDeleteFeature;
friend class QgsVectorLayerUndoCommandChangeGeometry;
friend class QgsVectorLayerUndoCommandChangeAttribute;
friend class QgsVectorLayerUndoCommandAddAttribute;
friend class QgsVectorLayerUndoCommandDeleteAttribute;

/** Deleted feature IDs which are not commited. Note a feature can be added and then deleted
again before the change is committed - in that case the added feature would be removed
from mAddedFeatures only and *not* entered here.
*/
QgsFeatureIds mDeletedFeatureIds;
/** Deleted feature IDs which are not commited. Note a feature can be added and then deleted
again before the change is committed - in that case the added feature would be removed
from mAddedFeatures only and *not* entered here.
*/
QgsFeatureIds mDeletedFeatureIds;

/** New features which are not commited. */
QgsFeatureMap mAddedFeatures;
/** New features which are not commited. */
QgsFeatureMap mAddedFeatures;

/** Changed attributes values which are not commited */
QgsChangedAttributesMap mChangedAttributeValues;
/** Changed attributes values which are not commited */
QgsChangedAttributesMap mChangedAttributeValues;

/** deleted attributes fields which are not commited. The list is kept sorted. */
QgsAttributeList mDeletedAttributeIds;
/** deleted attributes fields which are not commited. The list is kept sorted. */
QgsAttributeList mDeletedAttributeIds;

/** added attributes fields which are not commited */
QList<QgsField> mAddedAttributes;
/** added attributes fields which are not commited */
QList<QgsField> mAddedAttributes;

/** Changed geometries which are not commited. */
QgsGeometryMap mChangedGeometries;
/** Changed geometries which are not commited. */
QgsGeometryMap mChangedGeometries;

};

Expand Down
28 changes: 21 additions & 7 deletions src/core/qgsvectorlayereditutils.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgsvectorlayereditutils.cpp
---------------------
begin : Dezember 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsvectorlayereditutils.h"

#include "qgsvectordataprovider.h"
Expand All @@ -7,8 +21,8 @@
#include <limits>


QgsVectorLayerEditUtils::QgsVectorLayerEditUtils(QgsVectorLayer* layer)
: L(layer)
QgsVectorLayerEditUtils::QgsVectorLayerEditUtils( QgsVectorLayer* layer )
: L( layer )
{
}

Expand All @@ -19,7 +33,7 @@ bool QgsVectorLayerEditUtils::insertVertex( double x, double y, QgsFeatureId atF
return false;

QgsGeometry geometry;
if (!cache()->geometry(atFeatureId, geometry))
if ( !cache()->geometry( atFeatureId, geometry ) )
return false; // TODO: support also uncached geometries

geometry.insertVertex( x, y, beforeVertex );
Expand All @@ -35,7 +49,7 @@ bool QgsVectorLayerEditUtils::moveVertex( double x, double y, QgsFeatureId atFea
return false;

QgsGeometry geometry;
if (!cache()->geometry(atFeatureId, geometry))
if ( !cache()->geometry( atFeatureId, geometry ) )
return false; // TODO: support also uncached geometries

geometry.moveVertex( x, y, atVertex );
Expand All @@ -51,7 +65,7 @@ bool QgsVectorLayerEditUtils::deleteVertex( QgsFeatureId atFeatureId, int atVert
return false;

QgsGeometry geometry;
if (!cache()->geometry(atFeatureId, geometry))
if ( !cache()->geometry( atFeatureId, geometry ) )
return false; // TODO: support also uncached geometries

if ( !geometry.deleteVertex( atVertex ) )
Expand Down Expand Up @@ -106,7 +120,7 @@ int QgsVectorLayerEditUtils::addPart( const QList<QgsPoint> &points, QgsFeatureI
return 6;

QgsGeometry geometry;
if (!cache()->geometry(featureId, geometry)) // maybe it's in cache
if ( !cache()->geometry( featureId, geometry ) ) // maybe it's in cache
{
// it's not in cache: let's fetch it from layer
QgsFeature f;
Expand All @@ -132,7 +146,7 @@ int QgsVectorLayerEditUtils::translateFeature( QgsFeatureId featureId, double dx
return 1;

QgsGeometry geometry;
if (!cache()->geometry(featureId, geometry)) // maybe it's in cache
if ( !cache()->geometry( featureId, geometry ) ) // maybe it's in cache
{
// it's not in cache: let's fetch it from layer
QgsFeature f;
Expand Down
192 changes: 103 additions & 89 deletions src/core/qgsvectorlayereditutils.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgsvectorlayereditutils.h
---------------------
begin : Dezember 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSVECTORLAYEREDITUTILS_H
#define QGSVECTORLAYEREDITUTILS_H

Expand All @@ -9,95 +23,95 @@

class CORE_EXPORT QgsVectorLayerEditUtils
{
public:
QgsVectorLayerEditUtils(QgsVectorLayer* layer);

inline QgsVectorLayerCache* cache() { return L->cache(); }


/** Insert a new vertex before the given vertex number,
* in the given ring, item (first number is index 0), and feature
* Not meaningful for Point geometries
*/
bool insertVertex( double x, double y, QgsFeatureId atFeatureId, int beforeVertex );

/** Moves the vertex at the given position number,
* ring and item (first number is index 0), and feature
* to the given coordinates
*/
bool moveVertex( double x, double y, QgsFeatureId atFeatureId, int atVertex );

/** Deletes a vertex from a feature
*/
bool deleteVertex( QgsFeatureId atFeatureId, int atVertex );

/** Adds a ring to polygon/multipolygon features
@return
0 in case of success,
1 problem with feature type,
2 ring not closed,
3 ring not valid,
4 ring crosses existing rings,
5 no feature found where ring can be inserted*/
int addRing( const QList<QgsPoint>& ring );

/** Adds a new part polygon to a multipart feature
@return
0 in case of success,
1 if selected feature is not multipart,
2 if ring is not a valid geometry,
3 if new polygon ring not disjoint with existing rings,
4 if no feature was selected,
5 if several features are selected,
6 if selected geometry not found*/
int addPart( const QList<QgsPoint>& ring, QgsFeatureId featureId );

/** Translates feature by dx, dy
@param featureId id of the feature to translate
@param dx translation of x-coordinate
@param dy translation of y-coordinate
@return 0 in case of success*/
int translateFeature( QgsFeatureId featureId, double dx, double dy );

/** Splits features cut by the given line
* @param splitLine line that splits the layer features
* @param topologicalEditing true if topological editing is enabled
* @return
* 0 in case of success,
* 4 if there is a selection but no feature split
*/
int splitFeatures( const QList<QgsPoint>& splitLine, bool topologicalEditing = false );

/** Adds topological points for every vertex of the geometry.
* @param geom the geometry where each vertex is added to segments of other features
* @note geom is not going to be modified by the function
* @return 0 in case of success
*/
int addTopologicalPoints( QgsGeometry* geom );

/** Adds a vertex to segments which intersect point p but don't
* already have a vertex there. If a feature already has a vertex at position p,
* no additional vertex is inserted. This method is useful for topological
* editing.
* @param p position of the vertex
* @return 0 in case of success
*/
int addTopologicalPoints( const QgsPoint& p );

/** Inserts vertices to the snapped segments.
* This is useful for topological editing if snap to segment is enabled.
* @param snapResults results collected from the snapping operation
* @return 0 in case of success
*/
int insertSegmentVerticesForSnap( const QList<QgsSnappingResult>& snapResults );

protected:

/** Little helper function that gives bounding box from a list of points.
@return 0 in case of success */
int boundingBoxFromPointList( const QList<QgsPoint>& list, double& xmin, double& ymin, double& xmax, double& ymax ) const;

QgsVectorLayer* L;
public:
QgsVectorLayerEditUtils( QgsVectorLayer* layer );

inline QgsVectorLayerCache* cache() { return L->cache(); }


/** Insert a new vertex before the given vertex number,
* in the given ring, item (first number is index 0), and feature
* Not meaningful for Point geometries
*/
bool insertVertex( double x, double y, QgsFeatureId atFeatureId, int beforeVertex );

/** Moves the vertex at the given position number,
* ring and item (first number is index 0), and feature
* to the given coordinates
*/
bool moveVertex( double x, double y, QgsFeatureId atFeatureId, int atVertex );

/** Deletes a vertex from a feature
*/
bool deleteVertex( QgsFeatureId atFeatureId, int atVertex );

/** Adds a ring to polygon/multipolygon features
@return
0 in case of success,
1 problem with feature type,
2 ring not closed,
3 ring not valid,
4 ring crosses existing rings,
5 no feature found where ring can be inserted*/
int addRing( const QList<QgsPoint>& ring );

/** Adds a new part polygon to a multipart feature
@return
0 in case of success,
1 if selected feature is not multipart,
2 if ring is not a valid geometry,
3 if new polygon ring not disjoint with existing rings,
4 if no feature was selected,
5 if several features are selected,
6 if selected geometry not found*/
int addPart( const QList<QgsPoint>& ring, QgsFeatureId featureId );

/** Translates feature by dx, dy
@param featureId id of the feature to translate
@param dx translation of x-coordinate
@param dy translation of y-coordinate
@return 0 in case of success*/
int translateFeature( QgsFeatureId featureId, double dx, double dy );

/** Splits features cut by the given line
* @param splitLine line that splits the layer features
* @param topologicalEditing true if topological editing is enabled
* @return
* 0 in case of success,
* 4 if there is a selection but no feature split
*/
int splitFeatures( const QList<QgsPoint>& splitLine, bool topologicalEditing = false );

/** Adds topological points for every vertex of the geometry.
* @param geom the geometry where each vertex is added to segments of other features
* @note geom is not going to be modified by the function
* @return 0 in case of success
*/
int addTopologicalPoints( QgsGeometry* geom );

/** Adds a vertex to segments which intersect point p but don't
* already have a vertex there. If a feature already has a vertex at position p,
* no additional vertex is inserted. This method is useful for topological
* editing.
* @param p position of the vertex
* @return 0 in case of success
*/
int addTopologicalPoints( const QgsPoint& p );

/** Inserts vertices to the snapped segments.
* This is useful for topological editing if snap to segment is enabled.
* @param snapResults results collected from the snapping operation
* @return 0 in case of success
*/
int insertSegmentVerticesForSnap( const QList<QgsSnappingResult>& snapResults );

protected:

/** Little helper function that gives bounding box from a list of points.
@return 0 in case of success */
int boundingBoxFromPointList( const QList<QgsPoint>& list, double& xmin, double& ymin, double& xmax, double& ymax ) const;

QgsVectorLayer* L;
};

#endif // QGSVECTORLAYEREDITUTILS_H
28 changes: 21 additions & 7 deletions src/core/qgsvectorlayerfeatureiterator.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgsvectorlayerfeatureiterator.cpp
---------------------
begin : Dezember 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsvectorlayerfeatureiterator.h"

#include "qgsmaplayerregistry.h"
Expand All @@ -7,7 +21,7 @@
#include "qgsvectorlayerjoinbuffer.h"

QgsVectorLayerFeatureIterator::QgsVectorLayerFeatureIterator( QgsVectorLayer* layer, const QgsFeatureRequest& request )
: QgsAbstractFeatureIterator( request ), L( layer )
: QgsAbstractFeatureIterator( request ), L( layer )
{

QgsVectorLayerJoinBuffer* joinBuffer = L->mJoinBuffer;
Expand Down Expand Up @@ -232,18 +246,18 @@ void QgsVectorLayerFeatureIterator::useChangedAttributeFeature( QgsFeatureId fid
if ( !( mRequest.flags() & QgsFeatureRequest::NoGeometry ) )
f.setGeometry( geom );

bool subsetAttrs = (mRequest.flags() & QgsFeatureRequest::SubsetOfAttributes);
if ( !subsetAttrs || (subsetAttrs && mRequest.subsetOfAttributes().count() > 0) )
bool subsetAttrs = ( mRequest.flags() & QgsFeatureRequest::SubsetOfAttributes );
if ( !subsetAttrs || ( subsetAttrs && mRequest.subsetOfAttributes().count() > 0 ) )
{
// retrieve attributes from provider
QgsFeature tmp;
//mDataProvider->featureAtId( fid, tmp, false, mFetchProvAttributes );
QgsFeatureRequest request;
request.setFilterFid( fid ).setFlags(QgsFeatureRequest::NoGeometry).setSubsetOfAttributes( mProviderRequest.subsetOfAttributes() );
request.setFilterFid( fid ).setFlags( QgsFeatureRequest::NoGeometry ).setSubsetOfAttributes( mProviderRequest.subsetOfAttributes() );
QgsFeatureIterator fi = L->dataProvider()->getFeatures( request );
if ( fi.nextFeature( tmp ) )
{
if (L->editBuffer())
if ( L->editBuffer() )
L->editBuffer()->updateChangedAttributes( tmp );
f.setAttributes( tmp.attributes() );
}
Expand Down Expand Up @@ -272,7 +286,7 @@ void QgsVectorLayerFeatureIterator::rewindEditBuffer()

void QgsVectorLayerFeatureIterator::prepareJoins()
{
QgsAttributeList fetchAttributes = (mRequest.flags() & QgsFeatureRequest::SubsetOfAttributes) ? mRequest.subsetOfAttributes() : L->pendingAllAttributesList();
QgsAttributeList fetchAttributes = ( mRequest.flags() & QgsFeatureRequest::SubsetOfAttributes ) ? mRequest.subsetOfAttributes() : L->pendingAllAttributesList();
QgsAttributeList sourceJoinFields; // attributes that also need to be fetched from this layer in order to have joins working

mFetchJoinInfo.clear();
Expand All @@ -282,7 +296,7 @@ void QgsVectorLayerFeatureIterator::prepareJoins()

for ( QgsAttributeList::const_iterator attIt = fetchAttributes.constBegin(); attIt != fetchAttributes.constEnd(); ++attIt )
{
if ( fields.fieldOrigin(*attIt) != QgsFields::OriginJoin )
if ( fields.fieldOrigin( *attIt ) != QgsFields::OriginJoin )
continue;

int sourceLayerIndex;
Expand Down
140 changes: 77 additions & 63 deletions src/core/qgsvectorlayerfeatureiterator.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgsvectorlayerfeatureiterator.h
---------------------
begin : Dezember 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSVECTORLAYERFEATUREITERATOR_H
#define QGSVECTORLAYERFEATUREITERATOR_H

Expand All @@ -12,69 +26,69 @@ struct QgsVectorJoinInfo;

class CORE_EXPORT QgsVectorLayerFeatureIterator : public QgsAbstractFeatureIterator
{
public:
QgsVectorLayerFeatureIterator( QgsVectorLayer* layer, const QgsFeatureRequest& request );

~QgsVectorLayerFeatureIterator();

//! fetch next feature, return true on success
virtual bool nextFeature( QgsFeature& feature );

//! reset the iterator to the starting position
virtual bool rewind();

//! end of iterating: free the resources / lock
virtual bool close();

protected:
QgsVectorLayer* L;

QgsFeatureRequest mProviderRequest;
QgsFeatureIterator mProviderIterator;

// general stuff
//bool mFetching;
//QgsRectangle mFetchRect;
//QgsAttributeList mFetchAttributes;
//QgsAttributeList mFetchProvAttributes;
//bool mFetchGeometry;

// only related to editing
QSet<QgsFeatureId> mFetchConsidered;
QgsGeometryMap::iterator mFetchChangedGeomIt;
QgsFeatureMap::iterator mFetchAddedFeaturesIt;

bool mFetchedFid; // when iterating by FID: indicator whether it has been fetched yet or not

void rewindEditBuffer();
void prepareJoins();
bool fetchNextAddedFeature( QgsFeature& f );
bool fetchNextChangedGeomFeature( QgsFeature& f );
void useAddedFeature( const QgsFeature& src, QgsFeature& f );
void useChangedAttributeFeature( QgsFeatureId fid, const QgsGeometry& geom, QgsFeature& f );
bool nextFeatureFid( QgsFeature& f );
void addJoinedAttributes( QgsFeature &f );

/** Join information prepared for fast attribute id mapping in QgsVectorLayerJoinBuffer::updateFeatureAttributes().
Created in the select() method of QgsVectorLayerJoinBuffer for the joins that contain fetched attributes
*/
struct FetchJoinInfo
{
const QgsVectorJoinInfo* joinInfo;//!< cannonical source of information about the join
QgsAttributeList attributes; //!< attributes to fetch
int indexOffset; //!< at what position the joined fields start
QgsVectorLayer* joinLayer; //!< resolved pointer to the joined layer
int targetField; //!< index of field (of this layer) that drives the join
int joinField; //!< index of field (of the joined layer) must have equal value

void addJoinedAttributesCached( QgsFeature& f, const QVariant& joinValue ) const;
void addJoinedAttributesDirect( QgsFeature& f, const QVariant& joinValue ) const;
};


/** Informations about joins used in the current select() statement.
Allows faster mapping of attribute ids compared to mVectorJoins */
QMap<QgsVectorLayer*, FetchJoinInfo> mFetchJoinInfo;
public:
QgsVectorLayerFeatureIterator( QgsVectorLayer* layer, const QgsFeatureRequest& request );

~QgsVectorLayerFeatureIterator();

//! fetch next feature, return true on success
virtual bool nextFeature( QgsFeature& feature );

//! reset the iterator to the starting position
virtual bool rewind();

//! end of iterating: free the resources / lock
virtual bool close();

protected:
QgsVectorLayer* L;

QgsFeatureRequest mProviderRequest;
QgsFeatureIterator mProviderIterator;

// general stuff
//bool mFetching;
//QgsRectangle mFetchRect;
//QgsAttributeList mFetchAttributes;
//QgsAttributeList mFetchProvAttributes;
//bool mFetchGeometry;

// only related to editing
QSet<QgsFeatureId> mFetchConsidered;
QgsGeometryMap::iterator mFetchChangedGeomIt;
QgsFeatureMap::iterator mFetchAddedFeaturesIt;

bool mFetchedFid; // when iterating by FID: indicator whether it has been fetched yet or not

void rewindEditBuffer();
void prepareJoins();
bool fetchNextAddedFeature( QgsFeature& f );
bool fetchNextChangedGeomFeature( QgsFeature& f );
void useAddedFeature( const QgsFeature& src, QgsFeature& f );
void useChangedAttributeFeature( QgsFeatureId fid, const QgsGeometry& geom, QgsFeature& f );
bool nextFeatureFid( QgsFeature& f );
void addJoinedAttributes( QgsFeature &f );

/** Join information prepared for fast attribute id mapping in QgsVectorLayerJoinBuffer::updateFeatureAttributes().
Created in the select() method of QgsVectorLayerJoinBuffer for the joins that contain fetched attributes
*/
struct FetchJoinInfo
{
const QgsVectorJoinInfo* joinInfo;//!< cannonical source of information about the join
QgsAttributeList attributes; //!< attributes to fetch
int indexOffset; //!< at what position the joined fields start
QgsVectorLayer* joinLayer; //!< resolved pointer to the joined layer
int targetField; //!< index of field (of this layer) that drives the join
int joinField; //!< index of field (of the joined layer) must have equal value

void addJoinedAttributesCached( QgsFeature& f, const QVariant& joinValue ) const;
void addJoinedAttributesDirect( QgsFeature& f, const QVariant& joinValue ) const;
};


/** Informations about joins used in the current select() statement.
Allows faster mapping of attribute ids compared to mVectorJoins */
QMap<QgsVectorLayer*, FetchJoinInfo> mFetchJoinInfo;

};

Expand Down
2 changes: 0 additions & 2 deletions src/core/qgswfsdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ class CORE_EXPORT QgsWFSData: public QObject
/**Creates a set of points from a coordinate string.
@param points list that will contain the created points
@param coordString the text containing the coordinates
@param cs coortinate separator
@param ts tuple separator
@return 0 in case of success*/
int pointsFromCoordinateString( std::list<QgsPoint>& points, const QString& coordString ) const;

Expand Down
32 changes: 0 additions & 32 deletions src/core/raster/qgsrasterlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,30 +395,6 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
/** \brief Accessor for color shader algorithm */
QString colorShadingAlgorithmAsString() const;

/** \brief Wrapper for GDALComputeRasterMinMax with the estimate option
@note python bindings not available
*/
//void computeMinimumMaximumEstimates( int theBand, double* theMinMax );

/** \brief Wrapper for GDALComputeRasterMinMax with the estimate option
@note python bindings not available
*/
//void computeMinimumMaximumEstimates( QString theBand, double* theMinMax );

/** \brief Wrapper for GDALComputeRasterMinMax with the estimate option
\note added in v1.6 */
//void computeMinimumMaximumEstimates( int theBand, double& theMin, double& theMax );

/** \brief Compute the actual minimum maximum pixel values based on the current (last) display extent
@note python bindings not available
*/
//void computeMinimumMaximumFromLastExtent( int theBand, double* theMinMax );

/** \brief Compute the actual minimum maximum pixel values based on the current (last) display extent
@note python bindings not available
*/
//void computeMinimumMaximumFromLastExtent( QString theBand, double* theMinMax );

/** \brief Compute the actual minimum maximum pixel values based on the current (last) display extent
\note added in v1.6 */
//void computeMinimumMaximumFromLastExtent( int theBand, double& theMin, double& theMax );
Expand Down Expand Up @@ -521,9 +497,6 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
/** \brief Simple reset function that set the noDataValue back to the value stored in the first raster band */
//void resetNoDataValue();

/** \brief Mutator for blue band name mapping */
void setBlueBandName( const QString & theBandName );

static QString contrastEnhancementLimitsAsString( QgsRasterLayer::ContrastEnhancementLimits theLimits );
static ContrastEnhancementLimits contrastEnhancementLimitsFromString( QString theLimits );

Expand Down Expand Up @@ -580,11 +553,6 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
/** \brief Draws a preview of the rasterlayer into a pixmap */
QPixmap previewAsPixmap( QSize size, QColor bgColor = Qt::white );

/** \brief Draws a thumbnail of the rasterlayer into the supplied QImage pointer
* @note added in QGIS 1.6
* */
/* Q_DECL_DEPRECATED void thumbnailAsImage( QImage * thepImage ); */

/** \brief Emit a signal asking for a repaint. (inherited from maplayer) */
void triggerRepaint();

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/grass/qgsgrasstoolsbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<attribute name="title">
<string>Direct Modules Tree</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QTreeWidget" name="mDirectModulesTree">
<property name="indentation">
Expand Down
36 changes: 25 additions & 11 deletions src/providers/delimitedtext/qgsdelimitedtextfeatureiterator.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgsdelimitedtextfeatureiterator.cpp
---------------------
begin : Oktober 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsdelimitedtextfeatureiterator.h"

#include "qgsdelimitedtextprovider.h"
Expand Down Expand Up @@ -74,14 +88,14 @@ bool QgsDelimitedTextFeatureIterator::nextFeature( QgsFeature& feature )

if ( mRequest.flags() & QgsFeatureRequest::SubsetOfAttributes )
{
const QgsAttributeList& attrs = mRequest.subsetOfAttributes();
for ( QgsAttributeList::const_iterator i = attrs.begin(); i != attrs.end(); ++i )
{
int fieldIdx = *i;
if ( fieldIdx < 0 || fieldIdx >= P->attributeColumns.count() )
continue; // ignore non-existant fields
fetchAttribute( feature, fieldIdx, tokens );
}
const QgsAttributeList& attrs = mRequest.subsetOfAttributes();
for ( QgsAttributeList::const_iterator i = attrs.begin(); i != attrs.end(); ++i )
{
int fieldIdx = *i;
if ( fieldIdx < 0 || fieldIdx >= P->attributeColumns.count() )
continue; // ignore non-existant fields
fetchAttribute( feature, fieldIdx, tokens );
}
}
else
{
Expand Down Expand Up @@ -131,7 +145,7 @@ bool QgsDelimitedTextFeatureIterator::close()
}


QgsGeometry* QgsDelimitedTextFeatureIterator::loadGeometryWkt(const QStringList& tokens)
QgsGeometry* QgsDelimitedTextFeatureIterator::loadGeometryWkt( const QStringList& tokens )
{
QgsGeometry* geom = 0;
try
Expand Down Expand Up @@ -197,7 +211,7 @@ QgsGeometry* QgsDelimitedTextFeatureIterator::loadGeometryXY( const QStringList&
bool QgsDelimitedTextFeatureIterator::boundsCheck( double x, double y )
{
// no selection rectangle or geometry => always in the bounds
if ( mRequest.filterType() != QgsFeatureRequest::FilterRect || (mRequest.flags() & QgsFeatureRequest::NoGeometry) )
if ( mRequest.filterType() != QgsFeatureRequest::FilterRect || ( mRequest.flags() & QgsFeatureRequest::NoGeometry ) )
return true;

return mRequest.filterRect().contains( QgsPoint( x, y ) );
Expand All @@ -209,7 +223,7 @@ bool QgsDelimitedTextFeatureIterator::boundsCheck( double x, double y )
bool QgsDelimitedTextFeatureIterator::boundsCheck( QgsGeometry *geom )
{
// no selection rectangle or geometry => always in the bounds
if ( mRequest.filterType() != QgsFeatureRequest::FilterRect || (mRequest.flags() & QgsFeatureRequest::NoGeometry) )
if ( mRequest.filterType() != QgsFeatureRequest::FilterRect || ( mRequest.flags() & QgsFeatureRequest::NoGeometry ) )
return true;

if ( mRequest.flags() & QgsFeatureRequest::ExactIntersect )
Expand Down
16 changes: 15 additions & 1 deletion src/providers/delimitedtext/qgsdelimitedtextfeatureiterator.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgsdelimitedtextfeatureiterator.h
---------------------
begin : Oktober 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSDELIMITEDTEXTFEATUREITERATOR_H
#define QGSDELIMITEDTEXTFEATUREITERATOR_H

Expand All @@ -7,7 +21,7 @@ class QgsDelimitedTextProvider;

class QgsDelimitedTextFeatureIterator : public QgsAbstractFeatureIterator
{
public:
public:
QgsDelimitedTextFeatureIterator( QgsDelimitedTextProvider* p, const QgsFeatureRequest& request );

~QgsDelimitedTextFeatureIterator();
Expand Down
42 changes: 28 additions & 14 deletions src/providers/gpx/qgsgpxfeatureiterator.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgsgpxfeatureiterator.cpp
---------------------
begin : Dezember 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsgpxfeatureiterator.h"

#include "qgsgpxprovider.h"
Expand All @@ -11,7 +25,7 @@


QgsGPXFeatureIterator::QgsGPXFeatureIterator( QgsGPXProvider* p, const QgsFeatureRequest& request )
: QgsAbstractFeatureIterator( request ), P( p )
: QgsAbstractFeatureIterator( request ), P( p )
{
// make sure that only one iterator is active
if ( P->mActiveIterator )
Expand Down Expand Up @@ -172,7 +186,7 @@ bool QgsGPXFeatureIterator::readFid( QgsFeature& feature )
}


bool QgsGPXFeatureIterator::readWaypoint(const QgsWaypoint& wpt, QgsFeature& feature)
bool QgsGPXFeatureIterator::readWaypoint( const QgsWaypoint& wpt, QgsFeature& feature )
{
if ( mRequest.filterType() == QgsFeatureRequest::FilterRect )
{
Expand All @@ -182,9 +196,9 @@ bool QgsGPXFeatureIterator::readWaypoint(const QgsWaypoint& wpt, QgsFeature& fea
}

// some wkb voodoo
if ( !(mRequest.flags() & QgsFeatureRequest::NoGeometry) )
if ( !( mRequest.flags() & QgsFeatureRequest::NoGeometry ) )
{
feature.setGeometry( readWaypointGeometry(wpt) );
feature.setGeometry( readWaypointGeometry( wpt ) );
}
feature.setFeatureId( wpt.id );
feature.setValid( true );
Expand All @@ -197,12 +211,12 @@ bool QgsGPXFeatureIterator::readWaypoint(const QgsWaypoint& wpt, QgsFeature& fea
}


bool QgsGPXFeatureIterator::readRoute(const QgsRoute& rte, QgsFeature& feature)
bool QgsGPXFeatureIterator::readRoute( const QgsRoute& rte, QgsFeature& feature )
{
if ( rte.points.size() == 0 )
return false;

QgsGeometry* theGeometry = readRouteGeometry(rte);
QgsGeometry* theGeometry = readRouteGeometry( rte );

if ( mRequest.filterType() == QgsFeatureRequest::FilterRect )
{
Expand All @@ -218,7 +232,7 @@ bool QgsGPXFeatureIterator::readRoute(const QgsRoute& rte, QgsFeature& feature)
}
}

if ( !(mRequest.flags() & QgsFeatureRequest::NoGeometry) )
if ( !( mRequest.flags() & QgsFeatureRequest::NoGeometry ) )
{
feature.setGeometry( theGeometry );
}
Expand All @@ -237,11 +251,11 @@ bool QgsGPXFeatureIterator::readRoute(const QgsRoute& rte, QgsFeature& feature)
}


bool QgsGPXFeatureIterator::readTrack(const QgsTrack& trk, QgsFeature& feature)
bool QgsGPXFeatureIterator::readTrack( const QgsTrack& trk, QgsFeature& feature )
{
//QgsDebugMsg( QString( "GPX feature track segments: %1" ).arg( trk.segments.size() ) );

QgsGeometry* theGeometry = readTrackGeometry(trk);
QgsGeometry* theGeometry = readTrackGeometry( trk );

if ( mRequest.filterType() == QgsFeatureRequest::FilterRect )
{
Expand All @@ -257,7 +271,7 @@ bool QgsGPXFeatureIterator::readTrack(const QgsTrack& trk, QgsFeature& feature)
}
}

if ( !(mRequest.flags() & QgsFeatureRequest::NoGeometry) )
if ( !( mRequest.flags() & QgsFeatureRequest::NoGeometry ) )
{
feature.setGeometry( theGeometry );
}
Expand Down Expand Up @@ -382,7 +396,7 @@ void QgsGPXFeatureIterator::readAttributes( QgsFeature& feature, const QgsTrack&



QgsGeometry* QgsGPXFeatureIterator::readWaypointGeometry(const QgsWaypoint& wpt)
QgsGeometry* QgsGPXFeatureIterator::readWaypointGeometry( const QgsWaypoint& wpt )
{
char* geo = new char[21];
std::memset( geo, 0, 21 );
Expand All @@ -391,12 +405,12 @@ QgsGeometry* QgsGPXFeatureIterator::readWaypointGeometry(const QgsWaypoint& wpt)
std::memcpy( geo + 5, &wpt.lon, sizeof( double ) );
std::memcpy( geo + 13, &wpt.lat, sizeof( double ) );
QgsGeometry *g = new QgsGeometry();
g->fromWkb( ( unsigned char * )geo, 21 );
g->fromWkb(( unsigned char * )geo, 21 );
return g;
}


QgsGeometry* QgsGPXFeatureIterator::readRouteGeometry(const QgsRoute& rte)
QgsGeometry* QgsGPXFeatureIterator::readRouteGeometry( const QgsRoute& rte )
{
// some wkb voodoo
int nPoints = rte.points.size();
Expand All @@ -418,7 +432,7 @@ QgsGeometry* QgsGPXFeatureIterator::readRouteGeometry(const QgsRoute& rte)
return theGeometry;
}

QgsGeometry* QgsGPXFeatureIterator::readTrackGeometry(const QgsTrack& trk)
QgsGeometry* QgsGPXFeatureIterator::readTrackGeometry( const QgsTrack& trk )
{
// TODO: support multi line string for segments

Expand Down
26 changes: 20 additions & 6 deletions src/providers/gpx/qgsgpxfeatureiterator.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgsgpxfeatureiterator.h
---------------------
begin : Dezember 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSGPXFEATUREITERATOR_H
#define QGSGPXFEATUREITERATOR_H

Expand Down Expand Up @@ -27,13 +41,13 @@ class QgsGPXFeatureIterator : public QgsAbstractFeatureIterator

bool readFid( QgsFeature& feature );

bool readWaypoint(const QgsWaypoint& wpt, QgsFeature& feature);
bool readRoute(const QgsRoute& rte, QgsFeature& feature);
bool readTrack(const QgsTrack& trk, QgsFeature& feature);
bool readWaypoint( const QgsWaypoint& wpt, QgsFeature& feature );
bool readRoute( const QgsRoute& rte, QgsFeature& feature );
bool readTrack( const QgsTrack& trk, QgsFeature& feature );

QgsGeometry* readWaypointGeometry(const QgsWaypoint& wpt);
QgsGeometry* readRouteGeometry(const QgsRoute& rte);
QgsGeometry* readTrackGeometry(const QgsTrack& trk);
QgsGeometry* readWaypointGeometry( const QgsWaypoint& wpt );
QgsGeometry* readRouteGeometry( const QgsRoute& rte );
QgsGeometry* readTrackGeometry( const QgsTrack& trk );

void readAttributes( QgsFeature& feature, const QgsWaypoint& wpt );
void readAttributes( QgsFeature& feature, const QgsRoute& rte );
Expand Down
14 changes: 14 additions & 0 deletions src/providers/grass/qgsgrassfeatureiterator.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgsgrassfeatureiterator.cpp
---------------------
begin : Juli 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsgrassfeatureiterator.h"
#include "qgsgrassprovider.h"

Expand Down
14 changes: 14 additions & 0 deletions src/providers/grass/qgsgrassfeatureiterator.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgsgrassfeatureiterator.h
---------------------
begin : Juli 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSGRASSFEATUREITERATOR_H
#define QGSGRASSFEATUREITERATOR_H

Expand Down
14 changes: 14 additions & 0 deletions src/providers/memory/qgsmemoryfeatureiterator.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgsmemoryfeatureiterator.cpp
---------------------
begin : Juli 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsmemoryfeatureiterator.h"
#include "qgsmemoryprovider.h"

Expand Down
14 changes: 14 additions & 0 deletions src/providers/memory/qgsmemoryfeatureiterator.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgsmemoryfeatureiterator.h
---------------------
begin : Juli 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSMEMORYFEATUREITERATOR_H
#define QGSMEMORYFEATUREITERATOR_H

Expand Down
14 changes: 14 additions & 0 deletions src/providers/ogr/qgsogrfeatureiterator.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgsogrfeatureiterator.cpp
---------------------
begin : Juli 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsogrfeatureiterator.h"

#include "qgsogrprovider.h"
Expand Down
14 changes: 14 additions & 0 deletions src/providers/ogr/qgsogrfeatureiterator.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgsogrfeatureiterator.h
---------------------
begin : Juli 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSOGRFEATUREITERATOR_H
#define QGSOGRFEATUREITERATOR_H

Expand Down
30 changes: 22 additions & 8 deletions src/providers/osm/osmfeatureiterator.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
osmfeatureiterator.cpp
---------------------
begin : Januar 2013
copyright : (C) 2013 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "osmfeatureiterator.h"

#include "osmprovider.h"
Expand All @@ -7,8 +21,8 @@
#include "qgslogger.h"

QgsOSMFeatureIterator::QgsOSMFeatureIterator( QgsOSMDataProvider* p, const QgsFeatureRequest& request )
: QgsAbstractFeatureIterator( request ), P( p )
, mRectGeom(0)
: QgsAbstractFeatureIterator( request ), P( p )
, mRectGeom( 0 )
{
// make sure that only one iterator is active
if ( P->mActiveIterator )
Expand All @@ -27,9 +41,9 @@ QgsOSMFeatureIterator::QgsOSMFeatureIterator( QgsOSMDataProvider* p, const QgsFe
const char* sqlSelectNode = "SELECT id, lat, lon, timestamp, user FROM node WHERE id=? AND usage=0 AND status<>'R' AND u=1";
const char* sqlSelectPoints = "SELECT id, lat, lon, timestamp, user FROM node WHERE usage=0 AND status<>'R' AND u=1";
const char* sqlSelectPointsIn = "SELECT id, lat, lon, timestamp, user FROM node WHERE usage=0 AND status<>'R' AND u=1 "
"AND lat>=? AND lat<=? AND lon>=? AND lon<=?";
"AND lat>=? AND lat<=? AND lon>=? AND lon<=?";

const char* sql = hasFilterFid ? sqlSelectNode : (hasFilterRect ? sqlSelectPointsIn : sqlSelectPoints);
const char* sql = hasFilterFid ? sqlSelectNode : ( hasFilterRect ? sqlSelectPointsIn : sqlSelectPoints );

if ( sqlite3_prepare_v2( P->mDatabase, sql, -1, &mSelectStmt, 0 ) != SQLITE_OK )
{
Expand All @@ -55,8 +69,8 @@ QgsOSMFeatureIterator::QgsOSMFeatureIterator( QgsOSMDataProvider* p, const QgsFe
const char* sqlSelectWay = "SELECT id, wkb, timestamp, user FROM way WHERE id=? AND status<>'R' AND u=1";
const char* sqlSelectLines = "SELECT w.id, w.wkb, w.timestamp, w.user FROM way w WHERE w.closed=0 AND w.status<>'R' AND w.u=1";
const char* sqlSelectLinesIn = "SELECT w.id, w.wkb, w.timestamp, w.user FROM way w WHERE w.closed=0 AND w.status<>'R' AND w.u=1 "
"AND (((w.max_lat between ? AND ?) OR (w.min_lat between ? AND ?) OR (w.min_lat<? AND w.max_lat>?)) "
"AND ((w.max_lon between ? AND ?) OR (w.min_lon between ? AND ?) OR (w.min_lon<? AND w.max_lon>?)))";
"AND (((w.max_lat between ? AND ?) OR (w.min_lat between ? AND ?) OR (w.min_lat<? AND w.max_lat>?)) "
"AND ((w.max_lon between ? AND ?) OR (w.min_lon between ? AND ?) OR (w.min_lon<? AND w.max_lon>?)))";
const char* sql = hasFilterFid ? sqlSelectWay : ( hasFilterRect ? sqlSelectLinesIn : sqlSelectLines );

if ( sqlite3_prepare_v2( P->mDatabase, sql, -1, &mSelectStmt, 0 ) != SQLITE_OK )
Expand Down Expand Up @@ -92,8 +106,8 @@ QgsOSMFeatureIterator::QgsOSMFeatureIterator( QgsOSMDataProvider* p, const QgsFe
const char* sqlSelectWay = "SELECT id, wkb, timestamp, user FROM way WHERE id=? AND status<>'R' AND u=1";
const char* sqlSelectPolys = "SELECT w.id, w.wkb, w.timestamp, w.user FROM way w WHERE w.closed=1 AND w.status<>'R' AND w.u=1";
const char* sqlSelectPolysIn = "SELECT w.id, w.wkb, w.timestamp, w.user FROM way w WHERE w.closed=1 AND w.status<>'R' AND w.u=1 "
"AND (((w.max_lat between ? AND ?) OR (w.min_lat between ? AND ?) OR (w.min_lat<? AND w.max_lat>?)) "
"AND ((w.max_lon between ? AND ?) OR (w.min_lon between ? AND ?) OR (w.min_lon<? AND w.max_lon>?)))";
"AND (((w.max_lat between ? AND ?) OR (w.min_lat between ? AND ?) OR (w.min_lat<? AND w.max_lat>?)) "
"AND ((w.max_lon between ? AND ?) OR (w.min_lon between ? AND ?) OR (w.min_lon<? AND w.max_lon>?)))";
const char* sql = hasFilterFid ? sqlSelectWay : ( hasFilterRect ? sqlSelectPolysIn : sqlSelectPolys );

if ( sqlite3_prepare_v2( P->mDatabase, sql, -1, &mSelectStmt, 0 ) != SQLITE_OK )
Expand Down
14 changes: 14 additions & 0 deletions src/providers/osm/osmfeatureiterator.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
osmfeatureiterator.h
---------------------
begin : Januar 2013
copyright : (C) 2013 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef OSMFEATUREITERATOR_H
#define OSMFEATUREITERATOR_H

Expand Down
30 changes: 22 additions & 8 deletions src/providers/postgres/qgspostgresfeatureiterator.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgspostgresfeatureiterator.cpp
---------------------
begin : Juli 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgspostgresfeatureiterator.h"
#include "qgspostgresprovider.h"

Expand Down Expand Up @@ -246,7 +260,7 @@ QString QgsPostgresFeatureIterator::whereClauseRect()
.arg( qBox );
if ( mRequest.flags() & QgsFeatureRequest::ExactIntersect )
{
whereClause += QString( " AND %1(%2%3,%4)" )
whereClause += QString( " AND %1(%2%3,%4)" )
.arg( P->mConnectionRO->majorVersion() < 2 ? "intersects" : "st_intersects" )
.arg( P->quotedIdentifier( P->mGeometryColumn ) )
.arg( P->mSpatialColType == sctGeography ? "::geometry" : "" )
Expand All @@ -257,10 +271,10 @@ QString QgsPostgresFeatureIterator::whereClauseRect()
if ( !P->mRequestedSrid.isEmpty() && P->mRequestedSrid != P->mDetectedSrid )
{
whereClause += QString( " AND %1(%2%3)=%4" )
.arg( P->mConnectionRO->majorVersion() < 2 ? "srid" : "st_srid" )
.arg( P->quotedIdentifier( P->mGeometryColumn ) )
.arg( P->mSpatialColType == sctGeography ? "::geography" : "" )
.arg( P->mRequestedSrid );
.arg( P->mConnectionRO->majorVersion() < 2 ? "srid" : "st_srid" )
.arg( P->quotedIdentifier( P->mGeometryColumn ) )
.arg( P->mSpatialColType == sctGeography ? "::geography" : "" )
.arg( P->mRequestedSrid );
}

if ( P->mRequestedGeomType != QGis::WKBUnknown && P->mRequestedGeomType != P->mDetectedGeomType )
Expand Down Expand Up @@ -433,12 +447,12 @@ bool QgsPostgresFeatureIterator::getFeature( QgsPostgresResult &queryResult, int
if ( subsetOfAttributes )
{
foreach ( int idx, fetchAttributes )
getFeatureAttribute(idx, queryResult, row, col, feature );
getFeatureAttribute( idx, queryResult, row, col, feature );
}
else
{
for (int idx = 0; idx < P->mAttributeFields.count(); ++idx )
getFeatureAttribute(idx, queryResult, row, col, feature );
for ( int idx = 0; idx < P->mAttributeFields.count(); ++idx )
getFeatureAttribute( idx, queryResult, row, col, feature );
}

return true;
Expand Down
14 changes: 14 additions & 0 deletions src/providers/postgres/qgspostgresfeatureiterator.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgspostgresfeatureiterator.h
---------------------
begin : Juli 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSPOSTGRESFEATUREITERATOR_H
#define QGSPOSTGRESFEATUREITERATOR_H

Expand Down
14 changes: 14 additions & 0 deletions src/providers/spatialite/qgsspatialitefeatureiterator.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgsspatialitefeatureiterator.cpp
---------------------
begin : Juli 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsspatialitefeatureiterator.h"

#include "qgsspatialiteprovider.h"
Expand Down
14 changes: 14 additions & 0 deletions src/providers/spatialite/qgsspatialitefeatureiterator.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgsspatialitefeatureiterator.h
---------------------
begin : Juli 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSSPATIALITEFEATUREITERATOR_H
#define QGSSPATIALITEFEATUREITERATOR_H

Expand Down
16 changes: 16 additions & 0 deletions src/providers/wfs/qgswfsfeatureiterator.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgswfsfeatureiterator.cpp
---------------------
begin : Januar 2013
copyright : (C) 2013 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgswfsfeatureiterator.h"
#include "qgsspatialindex.h"
#include "qgswfsprovider.h"
Expand Down Expand Up @@ -84,6 +98,8 @@ bool QgsWFSFeatureIterator::rewind()
}

mFeatureIterator = mSelectedFeatures.constBegin();

return true;
}

bool QgsWFSFeatureIterator::close()
Expand Down
14 changes: 14 additions & 0 deletions src/providers/wfs/qgswfsfeatureiterator.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/***************************************************************************
qgswfsfeatureiterator.h
---------------------
begin : Januar 2013
copyright : (C) 2013 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSWFSFEATUREITERATOR_H
#define QGSWFSFEATUREITERATOR_H

Expand Down