[QGIS Commit] r10982 - in trunk/qgis: python/core src/core
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Fri Jun 26 13:04:31 EDT 2009
Author: jef
Date: 2009-06-26 13:04:31 -0400 (Fri, 26 Jun 2009)
New Revision: 10982
Modified:
trunk/qgis/python/core/qgsvectordataprovider.sip
trunk/qgis/python/core/qgsvectorlayer.sip
trunk/qgis/src/core/qgsvectordataprovider.cpp
trunk/qgis/src/core/qgsvectordataprovider.h
trunk/qgis/src/core/qgsvectorlayer.cpp
trunk/qgis/src/core/qgsvectorlayer.h
Log:
re-add vector attribute method removed in r10863
Modified: trunk/qgis/python/core/qgsvectordataprovider.sip
===================================================================
--- trunk/qgis/python/core/qgsvectordataprovider.sip 2009-06-26 15:29:46 UTC (rev 10981)
+++ trunk/qgis/python/core/qgsvectordataprovider.sip 2009-06-26 17:04:31 UTC (rev 10982)
@@ -168,13 +168,21 @@
/**
* 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
* @param attributes a set containing indexes of attributes
* @return true in case of success and false in case of failure
Modified: trunk/qgis/python/core/qgsvectorlayer.sip
===================================================================
--- trunk/qgis/python/core/qgsvectorlayer.sip 2009-06-26 15:29:46 UTC (rev 10981)
+++ trunk/qgis/python/core/qgsvectorlayer.sip 2009-06-26 17:04:31 UTC (rev 10982)
@@ -324,9 +324,17 @@
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);
Modified: trunk/qgis/src/core/qgsvectordataprovider.cpp
===================================================================
--- trunk/qgis/src/core/qgsvectordataprovider.cpp 2009-06-26 15:29:46 UTC (rev 10981)
+++ trunk/qgis/src/core/qgsvectordataprovider.cpp 2009-06-26 17:04:31 UTC (rev 10982)
@@ -83,6 +83,22 @@
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,7 +283,23 @@
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
{
int i;
Modified: trunk/qgis/src/core/qgsvectordataprovider.h
===================================================================
--- trunk/qgis/src/core/qgsvectordataprovider.h 2009-06-26 15:29:46 UTC (rev 10981)
+++ trunk/qgis/src/core/qgsvectordataprovider.h 2009-06-26 17:04:31 UTC (rev 10982)
@@ -209,13 +209,21 @@
/**
* 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
* @return true in case of success and false in case of failure
@@ -310,11 +318,18 @@
/**
- * 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 @@
/**The names of the providers native types*/
QList< NativeType > mNativeTypes;
+
+ private:
+ /** old notation **/
+ QMap<QString, QVariant::Type> mOldTypeList;
};
#endif
Modified: trunk/qgis/src/core/qgsvectorlayer.cpp
===================================================================
--- trunk/qgis/src/core/qgsvectorlayer.cpp 2009-06-26 15:29:46 UTC (rev 10981)
+++ trunk/qgis/src/core/qgsvectorlayer.cpp 2009-06-26 17:04:31 UTC (rev 10982)
@@ -752,23 +752,19 @@
// 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 )
+ if ( !mVertexMarkerOnlyForSelection || sel )
{
- mCurrentVertexMarkerType = QgsVectorLayer::NoMarker;
- }
- else
- {
mCurrentVertexMarkerType = vertexMarker;
}
}
-
-
//QgsDebugMsg(QString("markerScale before renderFeature(): %1").arg(markerScaleFactor));
// markerScalerFactore reflects the wanted scaling of the marker
mRenderer->renderFeature(
@@ -2673,6 +2669,16 @@
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() )
Modified: trunk/qgis/src/core/qgsvectorlayer.h
===================================================================
--- trunk/qgis/src/core/qgsvectorlayer.h 2009-06-26 15:29:46 UTC (rev 10981)
+++ trunk/qgis/src/core/qgsvectorlayer.h 2009-06-26 17:04:31 UTC (rev 10982)
@@ -396,6 +396,11 @@
@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 );
More information about the QGIS-commit
mailing list