Skip to content

Commit ccea976

Browse files
author
jef
committed
re-add vector attribute method removed in r10863
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10982 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 80fd596 commit ccea976

6 files changed

+91
-13
lines changed

python/core/qgsvectordataprovider.sip

+10-2
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,19 @@ class QgsVectorDataProvider : QgsDataProvider
168168

169169
/**
170170
* Adds new attributes
171-
* @param attributes map with attribute name as key and type as value
171+
* @param attributes list of new attribute fields
172172
* @return true in case of success and false in case of failure
173173
* @note changed in 1.2
174174
*/
175-
virtual bool addAttributes(const QList<QgsField> & attributes);
175+
virtual bool addAttributes(const QList<QgsField> &attributes);
176+
177+
/**
178+
* Adds new attributes
179+
* @param attributes map with attribute name as key and type as value
180+
* @return true in case of success and false in case of failure
181+
* @note deprecated
182+
*/
183+
virtual bool addAttributes(const QMap<QString, QString> &attributes);
176184

177185
/**
178186
* Deletes existing attributes

python/core/qgsvectorlayer.sip

+9-1
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,17 @@ public:
324324
bool changeAttributeValue(int fid, int field, QVariant value, bool emitSignal = true);
325325

326326
/** add an attribute field (but does not commit it)
327-
returns the field index or -1 in case of failure */
327+
returns true in case of success
328+
@note added in 1.2
329+
*/
328330
bool addAttribute( const QgsField &field );
329331

332+
/** add an attribute field (but does not commit it)
333+
returns true in case of success
334+
@note deprecated
335+
*/
336+
bool addAttribute( QString name, QString type );
337+
330338
/** delete an attribute field (but does not commit it) */
331339
bool deleteAttribute(int attr);
332340

src/core/qgsvectordataprovider.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,22 @@ bool QgsVectorDataProvider::addAttributes( const QList<QgsField> & attributes )
8383
return false;
8484
}
8585

86+
bool QgsVectorDataProvider::addAttributes( const QMap<QString, QString> &attributes )
87+
{
88+
const QMap<QString, QVariant::Type> &map = supportedNativeTypes();
89+
QList< QgsField > list;
90+
91+
for ( QMap<QString, QString>::const_iterator it = attributes.constBegin(); it != attributes.constEnd(); it++ )
92+
{
93+
if ( !map.contains( it.value() ) )
94+
return false;
95+
96+
list << QgsField( it.key(), map[ it.value()], it.value() );
97+
}
98+
99+
return addAttributes( list );
100+
}
101+
86102
bool QgsVectorDataProvider::deleteAttributes( const QgsAttributeIds& attributes )
87103
{
88104
return false;
@@ -267,6 +283,22 @@ const QList< QgsVectorDataProvider::NativeType > &QgsVectorDataProvider::nativeT
267283
return mNativeTypes;
268284
}
269285

286+
const QMap<QString, QVariant::Type> &QgsVectorDataProvider::supportedNativeTypes() const
287+
{
288+
if ( mOldTypeList.size() > 0 )
289+
return mOldTypeList;
290+
291+
QgsVectorDataProvider *p = ( QgsVectorDataProvider * )this;
292+
293+
const QList< QgsVectorDataProvider::NativeType > &types = nativeTypes();
294+
295+
for ( QList< QgsVectorDataProvider::NativeType >::const_iterator it = types.constBegin(); it != types.constEnd(); it++ )
296+
{
297+
p->mOldTypeList.insert( it->mTypeName, it->mType );
298+
}
299+
300+
return p->mOldTypeList;
301+
}
270302

271303
bool QgsVectorDataProvider::supportedType( const QgsField &field ) const
272304
{

src/core/qgsvectordataprovider.h

+22-3
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,20 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
209209

210210
/**
211211
* Adds new attributes
212-
* @param attributes map with attribute name as key and type as value
212+
* @param attributes list of new attributes
213213
* @return true in case of success and false in case of failure
214-
* @note changed in 1.2
214+
* @note added in 1.2
215215
*/
216216
virtual bool addAttributes( const QList<QgsField> &attributes );
217217

218+
/**
219+
* Add new attributes
220+
* @param attributes map of attributes name as key and type as value
221+
* @return true in case of success and false in case of failure
222+
* @note deprecated
223+
*/
224+
virtual bool addAttributes( const QMap<QString, QString> &attributes );
225+
218226
/**
219227
* Deletes existing attributes
220228
* @param attributes a set containing names of attributes
@@ -310,11 +318,18 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
310318

311319

312320
/**
313-
* Returns the names of the numerical types
321+
* Returns the names of the supported types
314322
* @note added in 1.2
315323
*/
316324
const QList< NativeType > &nativeTypes() const;
317325

326+
327+
/**
328+
* Returns the names of the supported types
329+
* @note deprecated
330+
*/
331+
const QMap<QString, QVariant::Type> &supportedNativeTypes() const;
332+
318333
protected:
319334
QVariant convertValue( QVariant::Type type, QString value );
320335

@@ -337,6 +352,10 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
337352

338353
/**The names of the providers native types*/
339354
QList< NativeType > mNativeTypes;
355+
356+
private:
357+
/** old notation **/
358+
QMap<QString, QVariant::Type> mOldTypeList;
340359
};
341360

342361
#endif

src/core/qgsvectorlayer.cpp

+13-7
Original file line numberDiff line numberDiff line change
@@ -752,23 +752,19 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
752752
// TODO: create a mechanism to let layer know whether it's current layer or not [MD]
753753
bool sel = mSelectedFeatureIds.contains( fet.id() );
754754

755+
mCurrentVertexMarkerType = QgsVectorLayer::NoMarker;
756+
755757
if ( mEditable )
756758
{
757759
// Cache this for the use of (e.g.) modifying the feature's uncommitted geometry.
758760
mCachedGeometries[fet.id()] = *fet.geometry();
759761

760-
if ( mVertexMarkerOnlyForSelection && !sel )
761-
{
762-
mCurrentVertexMarkerType = QgsVectorLayer::NoMarker;
763-
}
764-
else
762+
if ( !mVertexMarkerOnlyForSelection || sel )
765763
{
766764
mCurrentVertexMarkerType = vertexMarker;
767765
}
768766
}
769767

770-
771-
772768
//QgsDebugMsg(QString("markerScale before renderFeature(): %1").arg(markerScaleFactor));
773769
// markerScalerFactore reflects the wanted scaling of the marker
774770
mRenderer->renderFeature(
@@ -2673,6 +2669,16 @@ bool QgsVectorLayer::addAttribute( const QgsField &field )
26732669
return true;
26742670
}
26752671

2672+
bool QgsVectorLayer::addAttribute( QString name, QString type )
2673+
{
2674+
const QMap<QString, QVariant::Type> &map = mDataProvider->supportedNativeTypes();
2675+
2676+
if ( !map.contains( type ) )
2677+
return false;
2678+
2679+
return addAttribute( QgsField( name, map[ type ], type ) );
2680+
}
2681+
26762682
bool QgsVectorLayer::deleteAttribute( int index )
26772683
{
26782684
if ( !isEditable() )

src/core/qgsvectorlayer.h

+5
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,11 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
396396
@note added in version 1.2 */
397397
bool addAttribute( const QgsField &field );
398398

399+
/** add an attribute field (but does not commit it)
400+
returns true if the field was added
401+
@note deprecated */
402+
bool addAttribute( QString name, QString type );
403+
399404
/** delete an attribute field (but does not commit it) */
400405
bool deleteAttribute( int attr );
401406

0 commit comments

Comments
 (0)