Skip to content
Permalink
Browse files

re-add vector attribute method removed in r10863

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10982 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Jun 26, 2009
1 parent 80fd596 commit ccea9767319610aa847a9656dac912cff0b95fea
@@ -168,11 +168,19 @@ class QgsVectorDataProvider : QgsDataProvider

/**
* Adds new attributes
* @param attributes map with attribute name as key and type as value
* @param attributes list of new attribute fields
* @return true in case of success and false in case of failure
* @note changed in 1.2
*/
virtual bool addAttributes(const QList<QgsField> & attributes);
virtual bool addAttributes(const QList<QgsField> &attributes);

/**
* Adds new attributes
* @param attributes map with attribute name as key and type as value
* @return true in case of success and false in case of failure
* @note deprecated
*/
virtual bool addAttributes(const QMap<QString, QString> &attributes);

/**
* Deletes existing attributes
@@ -324,9 +324,17 @@ public:
bool changeAttributeValue(int fid, int field, QVariant value, bool emitSignal = true);

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

/** add an attribute field (but does not commit it)
returns true in case of success
@note deprecated
*/
bool addAttribute( QString name, QString type );

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

@@ -83,6 +83,22 @@ bool QgsVectorDataProvider::addAttributes( const QList<QgsField> & attributes )
return false;
}

bool QgsVectorDataProvider::addAttributes( const QMap<QString, QString> &attributes )
{
const QMap<QString, QVariant::Type> &map = supportedNativeTypes();
QList< QgsField > list;

for ( QMap<QString, QString>::const_iterator it = attributes.constBegin(); it != attributes.constEnd(); it++ )
{
if ( !map.contains( it.value() ) )
return false;

list << QgsField( it.key(), map[ it.value()], it.value() );
}

return addAttributes( list );
}

bool QgsVectorDataProvider::deleteAttributes( const QgsAttributeIds& attributes )
{
return false;
@@ -267,6 +283,22 @@ const QList< QgsVectorDataProvider::NativeType > &QgsVectorDataProvider::nativeT
return mNativeTypes;
}

const QMap<QString, QVariant::Type> &QgsVectorDataProvider::supportedNativeTypes() const
{
if ( mOldTypeList.size() > 0 )
return mOldTypeList;

QgsVectorDataProvider *p = ( QgsVectorDataProvider * )this;

const QList< QgsVectorDataProvider::NativeType > &types = nativeTypes();

for ( QList< QgsVectorDataProvider::NativeType >::const_iterator it = types.constBegin(); it != types.constEnd(); it++ )
{
p->mOldTypeList.insert( it->mTypeName, it->mType );
}

return p->mOldTypeList;
}

bool QgsVectorDataProvider::supportedType( const QgsField &field ) const
{
@@ -209,12 +209,20 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider

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

/**
* Add new attributes
* @param attributes map of attributes name as key and type as value
* @return true in case of success and false in case of failure
* @note deprecated
*/
virtual bool addAttributes( const QMap<QString, QString> &attributes );

/**
* Deletes existing attributes
* @param attributes a set containing names of attributes
@@ -310,11 +318,18 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider


/**
* Returns the names of the numerical types
* Returns the names of the supported types
* @note added in 1.2
*/
const QList< NativeType > &nativeTypes() const;


/**
* Returns the names of the supported types
* @note deprecated
*/
const QMap<QString, QVariant::Type> &supportedNativeTypes() const;

protected:
QVariant convertValue( QVariant::Type type, QString value );

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

/**The names of the providers native types*/
QList< NativeType > mNativeTypes;

private:
/** old notation **/
QMap<QString, QVariant::Type> mOldTypeList;
};

#endif
@@ -752,23 +752,19 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
// TODO: create a mechanism to let layer know whether it's current layer or not [MD]
bool sel = mSelectedFeatureIds.contains( fet.id() );

mCurrentVertexMarkerType = QgsVectorLayer::NoMarker;

if ( mEditable )
{
// Cache this for the use of (e.g.) modifying the feature's uncommitted geometry.
mCachedGeometries[fet.id()] = *fet.geometry();

if ( mVertexMarkerOnlyForSelection && !sel )
{
mCurrentVertexMarkerType = QgsVectorLayer::NoMarker;
}
else
if ( !mVertexMarkerOnlyForSelection || sel )
{
mCurrentVertexMarkerType = vertexMarker;
}
}



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

bool QgsVectorLayer::addAttribute( QString name, QString type )
{
const QMap<QString, QVariant::Type> &map = mDataProvider->supportedNativeTypes();

if ( !map.contains( type ) )
return false;

return addAttribute( QgsField( name, map[ type ], type ) );
}

bool QgsVectorLayer::deleteAttribute( int index )
{
if ( !isEditable() )
@@ -396,6 +396,11 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
@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 deprecated */
bool addAttribute( QString name, QString type );

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

0 comments on commit ccea976

Please sign in to comment.
You can’t perform that action at this time.