diff --git a/python/core/geometry/qgsgeometry.sip b/python/core/geometry/qgsgeometry.sip index 7514e1cbbd96..22bf6406c3d6 100644 --- a/python/core/geometry/qgsgeometry.sip +++ b/python/core/geometry/qgsgeometry.sip @@ -774,5 +774,8 @@ class QgsGeometry */ static void convertPointList( const QList& input, QList& output ); + //! Allows direct construction of QVariants from geometry. + operator QVariant() const; + }; // class QgsGeometry diff --git a/python/core/qgsfeature.sip b/python/core/qgsfeature.sip index 95af0af971ee..596f8a839feb 100644 --- a/python/core/qgsfeature.sip +++ b/python/core/qgsfeature.sip @@ -496,6 +496,9 @@ class QgsFeature */ int fieldNameIndex( const QString& fieldName ) const; + //! Allows direct construction of QVariants from features. + operator QVariant() const; + }; // class QgsFeature typedef QSet QgsFeatureIds; diff --git a/python/core/qgsfield.sip b/python/core/qgsfield.sip index c377c86511a9..ce63bdc41f2d 100644 --- a/python/core/qgsfield.sip +++ b/python/core/qgsfield.sip @@ -167,6 +167,10 @@ class QgsField return NULL; %End + + //! Allows direct construction of QVariants from fields. + operator QVariant() const; + }; // class QgsField @@ -364,6 +368,9 @@ class QgsFields } %End + //! Allows direct construction of QVariants from fields. + operator QVariant() const; + /* SIP_PYOBJECT __getitem__(int key); %MethodCode if (a0 = sipConvertFromSequenceIndex(a0, sipCpp->count()) < 0) diff --git a/python/core/qgsinterval.sip b/python/core/qgsinterval.sip index 6d332d137c19..59d39ef449d9 100644 --- a/python/core/qgsinterval.sip +++ b/python/core/qgsinterval.sip @@ -132,5 +132,8 @@ class QgsInterval */ static QgsInterval fromString( const QString& string ); + //! Allows direct construction of QVariants from intervals. + operator QVariant() const; + }; diff --git a/src/core/geometry/qgsgeometry.h b/src/core/geometry/qgsgeometry.h index 2bd5d6d4152b..8e7a6c186c85 100644 --- a/src/core/geometry/qgsgeometry.h +++ b/src/core/geometry/qgsgeometry.h @@ -819,6 +819,12 @@ class CORE_EXPORT QgsGeometry */ static void convertPointList( const QgsPointSequenceV2 &input, QList &output ); + //! Allows direct construction of QVariants from geometry. + operator QVariant() const + { + return QVariant::fromValue( *this ); + } + private: QgsGeometryPrivate* d; //implicitely shared data pointer diff --git a/src/core/qgsfeature.h b/src/core/qgsfeature.h index ffb5808c3f9f..36d56c1d6a4e 100644 --- a/src/core/qgsfeature.h +++ b/src/core/qgsfeature.h @@ -413,6 +413,12 @@ class CORE_EXPORT QgsFeature */ int fieldNameIndex( const QString& fieldName ) const; + //! Allows direct construction of QVariants from features. + operator QVariant() const + { + return QVariant::fromValue( *this ); + } + private: QExplicitlySharedDataPointer d; diff --git a/src/core/qgsfield.h b/src/core/qgsfield.h index 8732045ad4ec..13efb9276c3c 100644 --- a/src/core/qgsfield.h +++ b/src/core/qgsfield.h @@ -153,6 +153,12 @@ class CORE_EXPORT QgsField */ bool convertCompatible( QVariant& v ) const; + //! Allows direct construction of QVariants from fields. + operator QVariant() const + { + return QVariant::fromValue( *this ); + } + private: QSharedDataPointer d; @@ -288,6 +294,12 @@ class CORE_EXPORT QgsFields */ QIcon iconForField( int fieldIdx ) const; + //! Allows direct construction of QVariants from fields. + operator QVariant() const + { + return QVariant::fromValue( *this ); + } + ///@cond PRIVATE class const_iterator; diff --git a/src/core/qgsinterval.h b/src/core/qgsinterval.h index a5e9c7f751fb..f3762c052dd2 100644 --- a/src/core/qgsinterval.h +++ b/src/core/qgsinterval.h @@ -155,6 +155,12 @@ class CORE_EXPORT QgsInterval */ static QgsInterval fromString( const QString& string ); + //! Allows direct construction of QVariants from intervals. + operator QVariant() const + { + return QVariant::fromValue( *this ); + } + private: //! Duration of interval in seconds