qgis / qgis4.0_api

Tracker for QGIS 4.0 API related issues and developer discussion
3 stars 1 forks source link

Idea: don't use QVariant::Type for storing field types #49

Open nyalldawson opened 8 years ago

nyalldawson commented 8 years ago

And instead use our own enum of supported field types. Here's the reasons this may be a good move:

m-kuhn commented 8 years ago

I haven't checked the code but I'm pretty sure it would avoid bugs like this: http://hub.qgis.org/issues/15367

nyalldawson commented 8 years ago

I haven't checked the code but I'm pretty sure it would avoid bugs like this: http://hub.qgis.org/issues/15367

Yes, that's exactly the type of bug this is intended to avoid.

@wonder-sk I'm keen to hear your thoughts on this before I proceed

wonder-sk commented 8 years ago

Is the idea to just switch from QVariant::Type to a constrained enumeration of possible types (and keep QVariant as the storage) or did you mean to replace QVariant completely with our own variant type tailored for attribute values?

nyalldawson commented 8 years ago

the idea to just switch from QVariant::Type to a constrained enumeration of possible types (and keep QVariant as the storage)

Yes, so a subset of Qt's inbuilt types + sensible custom types we've registered as metaphors.

did you mean to replace QVariant completely with our own variant type tailored for attribute values

Oh hell no...! I think I've just done enough search and replace to last me till the next api break :p

3nids commented 8 years ago

@nyalldawson if you're not a pure terminal freak, I like regexxer a lot!

wonder-sk commented 8 years ago

@nyalldawson Sounds good to me...

nyalldawson commented 8 years ago

Here's the ones I'd keep:

Agreed?

m-kuhn commented 8 years ago

Why not merge Int and LongLong UInt and ULongLong ? And maybe even Time and DateTime (nah, forget about that)?

nyalldawson commented 8 years ago

I'd be in favour, but I guess it depends on whether those type differences are important to providers. Time and datetime are very different (eg tab files, postgres types), so I don't want to merge those.

nyalldawson commented 8 years ago

Oh BTW, I was thinking we should have a QgsFields::isNumeric( int index ) constand bool QgsField::isNumeric() const method too.

wonder-sk commented 8 years ago

The list of types looks good, I would probably just skip UInt and ULongLong to keep things simpler...

m-kuhn commented 8 years ago

What do you think about leaving the current type information in place and rename QgsField::type() to QgsField::complexType() while offering a second method QgsField::simpleType() (which internally has a switch over the complex type)?