Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow direct QVariant creation from some QGIS metatypes
  • Loading branch information
nyalldawson committed May 19, 2016
1 parent b956874 commit 0fcff9f
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python/core/geometry/qgsgeometry.sip
Expand Up @@ -774,5 +774,8 @@ class QgsGeometry
*/
static void convertPointList( const QList<QgsPointV2>& input, QList<QgsPoint>& output );

//! Allows direct construction of QVariants from geometry.
operator QVariant() const;

}; // class QgsGeometry

3 changes: 3 additions & 0 deletions python/core/qgsfeature.sip
Expand Up @@ -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<qint64> QgsFeatureIds;
7 changes: 7 additions & 0 deletions python/core/qgsfield.sip
Expand Up @@ -167,6 +167,10 @@ class QgsField

return NULL;
%End

//! Allows direct construction of QVariants from fields.
operator QVariant() const;

}; // class QgsField


Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions python/core/qgsinterval.sip
Expand Up @@ -132,5 +132,8 @@ class QgsInterval
*/
static QgsInterval fromString( const QString& string );

//! Allows direct construction of QVariants from intervals.
operator QVariant() const;

};

6 changes: 6 additions & 0 deletions src/core/geometry/qgsgeometry.h
Expand Up @@ -819,6 +819,12 @@ class CORE_EXPORT QgsGeometry
*/
static void convertPointList( const QgsPointSequenceV2 &input, QList<QgsPoint> &output );

//! Allows direct construction of QVariants from geometry.
operator QVariant() const
{
return QVariant::fromValue( *this );
}

private:

QgsGeometryPrivate* d; //implicitely shared data pointer
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsfeature.h
Expand Up @@ -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<QgsFeaturePrivate> d;
Expand Down
12 changes: 12 additions & 0 deletions src/core/qgsfield.h
Expand Up @@ -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<QgsFieldPrivate> d;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsinterval.h
Expand Up @@ -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
Expand Down

1 comment on commit 0fcff9f

@NathanW2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nifty!

Please sign in to comment.