[Qgis-developer] API changes

Martin Dobias wonder.sk at gmail.com
Sat Mar 24 19:37:00 EDT 2007


Hi devs,

in commit 6833 I've done some API changes to trunk. The most important
one is how feature attributes are handled. Until now, there was
QgsFeatureAttribute class which contained field name and field value
(both strings). This approach had some flaws:
- field name was redundant (one can find out field name from field index)
- field value was represented as string, making it difficult to
represent other types

About a year ago we had a discussion on qgis-dev list and spoken about
the usage of QVariant instead of QString for field values. I decided
to remove QgsFeatureAttribute class and use just QVariant for values.
So, now when you access attributes it should look like this:

const QgsAttributeMap& attrs = feature.attributeMap();
int myIntAttribute = attrs[0].toInt();
QString myStringAttribute = attrs[1].toString();
double myDoubleAttribute = attrs[2].toDouble();

You can use QgsField::type() to find out what QVariant type you should
expect for the field values. Currently QGIS supports String, Int and
Double. It will be useful to add also DateTime type later. Variant
type is decided by vector providers. Besides this, there's also
QgsField::typeName() which reports type as a provider-specific string.

I hope that I haven't caused regressions with these changes, just keep
in mind that if something with vector layers is not working well that
might be my fault :-) My other hope is that this pushes QGIS API
another small step further to be simpler and easier to use. I have in
mind more changes but these should wait for next release as further
changes might destabilize trunk rapidly.

Regards,
Martin



More information about the Qgis-developer mailing list