Skip to content
Permalink
Browse files

QgsField serialization

  • Loading branch information
blazek committed May 17, 2015
1 parent 6e3cbe3 commit e474e09658c1aa62915e6989135290c2c53d7b9d
Showing with 58 additions and 0 deletions.
  1. +49 −0 src/core/qgsfield.cpp
  2. +9 −0 src/core/qgsfield.h
@@ -176,6 +176,31 @@ bool QgsField::convertCompatible( QVariant& v ) const
return true;
}

QDataStream& operator<<( QDataStream& out, const QgsField& field )
{
out << field.name();
out << ( quint32 )field.type();
out << field.typeName();
out << field.length();
out << field.precision();
out << field.comment();
return out;
}

QDataStream& operator>>( QDataStream& in, QgsField& field )
{
quint32 type, length, precision;
QString name, typeName, comment;
in >> name >> type >> typeName >> length >> precision >> comment;
field.setName( name );
field.setType(( QVariant::Type )type );
field.setTypeName( typeName );
field.setLength(( int )length );
field.setPrecision(( int )precision );
field.setComment( comment );
return in;
}

////////////////////////////////////////////////////////////////////////////

QgsFields::QgsFields()
@@ -341,3 +366,27 @@ QgsAttributeList QgsFields::allAttributesList() const
lst.append( i );
return lst;
}

QDataStream& operator<<( QDataStream& out, const QgsFields& fields )
{
out << ( quint32 )fields.size();
for ( int i = 0; i < fields.size(); i++ )
{
out << fields.field( i );
}
return out;
}

QDataStream& operator>>( QDataStream& in, QgsFields& fields )
{
fields.clear();
quint32 size;
in >> size;
for ( quint32 i = 0; i < size; i++ )
{
QgsField field;
in >> field;
fields.append( field );
}
return in;
}
@@ -156,6 +156,10 @@ class CORE_EXPORT QgsField

Q_DECLARE_METATYPE( QgsField );

/** Writes the field to stream out. QGIS version compatibility is not guaranteed. */
CORE_EXPORT QDataStream& operator<<( QDataStream& out, const QgsField& field );
/** Reads a field from stream in into field. QGIS version compatibility is not guaranteed. */
CORE_EXPORT QDataStream& operator>>( QDataStream& in, QgsField& field );

/** \class QgsFields
* \ingroup core
@@ -274,4 +278,9 @@ class CORE_EXPORT QgsFields

Q_DECLARE_METATYPE( QgsFields );

/** Writes the fields to stream out. QGIS version compatibility is not guaranteed. */
CORE_EXPORT QDataStream& operator<<( QDataStream& out, const QgsFields& fields );
/** Reads fields from stream in into fields. QGIS version compatibility is not guaranteed. */
CORE_EXPORT QDataStream& operator>>( QDataStream& in, QgsFields& fields );

#endif

0 comments on commit e474e09

Please sign in to comment.
You can’t perform that action at this time.