Skip to content
Permalink
Browse files

100% test coverage for QgsWKBTypes, add missing docs

  • Loading branch information
nyalldawson committed Nov 11, 2015
1 parent fd31770 commit 87168c14a502ab07eed7c5a72a2be318def09d65
@@ -75,25 +75,67 @@ class QgsWKBTypes
NullGeometry
};

/*struct wkbEntry
{
wkbEntry( const QString& name, bool isMultiType, Type multiType, Type singleType, Type flatType, GeometryType geometryType );
QString mName;
bool mIsMultiType;
Type mMultiType;
Type mSingleType;
Type mFlatType;
GeometryType mGeometryType;
};*/

/** Returns the single type for a WKB type. Eg, for MultiPolygon WKB types the single type would be Polygon.
* @see isSingleType()
* @see multiType()
* @see flatType()
*/
static Type singleType( Type type );

/** Returns the multi type for a WKB type. Eg, for Polygon WKB types the multi type would be MultiPolygon.
* @see isMultiType()
* @see singleType()
* @see flatType()
*/
static Type multiType( Type type );

/** Returns the flat type for a WKB type. This is the WKB type minus any Z or M dimensions.
* Eg, for PolygonZM WKB types the single type would be Polygon.
* @see singleType()
* @see multiType()
*/
static Type flatType( Type type );

/** Attempts to extract the WKB type from a WKT string.
* @param wktStr a valid WKT string
*/
static Type parseType( const QString& wktStr );

/** Returns true if the WKB type is a single type.
* @see isMultiType()
* @see singleType()
*/
static bool isSingleType( Type type );

/** Returns true if the WKB type is a multi type.
* @see isSingleType()
* @see multiType()
*/
static bool isMultiType( Type type );

/** Returns the inherent dimension of the geometry type as an integer. Returned value will
* always be less than or equal to the coordinate dimension.
* @returns 0 for point geometries, 1 for line geometries, 2 for polygon geometries
* Invalid geometry types will return a dimension of 0.
* @see coordDimensions()
*/
static int wkbDimensions( Type type );

/** Returns the coordinate dimension of the geometry type as an integer. Returned value will
* be between 2-4, depending on whether the geometry type contains the Z or M dimensions.
* Invalid geometry types will return a dimension of 0.
* @note added in QGIS 2.14
* @see wkbDimensions()
*/
static int coordDimensions( Type type );

/** Returns the geometry type for a WKB type, eg both MultiPolygon and CurvePolygon would have a
* PolygonGeometry geometry type.
*/
static GeometryType geometryType( Type type );

/** Returns a display string type for a WKB type, eg the geometry name used in WKT geometry representations.
*/
static QString displayString( Type type );

/** Tests whether a WKB type contains the z-dimension.
@@ -96,6 +96,19 @@ int QgsWKBTypes::wkbDimensions( Type type )
}
}

int QgsWKBTypes::coordDimensions( QgsWKBTypes::Type type )
{
if ( type == Unknown || type == NoGeometry )
return 0;

QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
if ( it == entries()->constEnd() )
{
return 0;
}
return 2 + it->mHasZ + it->mHasM;
}

QgsWKBTypes::GeometryType QgsWKBTypes::geometryType( Type type )
{
QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
@@ -21,7 +21,12 @@
#include <QMap>
#include <QString>

/** Class to store information about wkb types.*/
/** \ingroup core
* \class QgsWKBTypes
* \brief Handles storage of information regarding WKB types and their properties.
* \note Added in version 2.10
*/

class CORE_EXPORT QgsWKBTypes
{
public:
@@ -95,30 +100,67 @@ class CORE_EXPORT QgsWKBTypes
NullGeometry
};

struct wkbEntry
{
wkbEntry( const QString& name, bool isMultiType, Type multiType, Type singleType, Type flatType, GeometryType geometryType,
bool hasZ, bool hasM ):
mName( name ), mIsMultiType( isMultiType ), mMultiType( multiType ), mSingleType( singleType ), mFlatType( flatType ), mGeometryType( geometryType ),
mHasZ( hasZ ), mHasM( hasM ) {}
QString mName;
bool mIsMultiType;
Type mMultiType;
Type mSingleType;
Type mFlatType;
GeometryType mGeometryType;
bool mHasZ;
bool mHasM;
};

/** Returns the single type for a WKB type. Eg, for MultiPolygon WKB types the single type would be Polygon.
* @see isSingleType()
* @see multiType()
* @see flatType()
*/
static Type singleType( Type type );

/** Returns the multi type for a WKB type. Eg, for Polygon WKB types the multi type would be MultiPolygon.
* @see isMultiType()
* @see singleType()
* @see flatType()
*/
static Type multiType( Type type );

/** Returns the flat type for a WKB type. This is the WKB type minus any Z or M dimensions.
* Eg, for PolygonZM WKB types the single type would be Polygon.
* @see singleType()
* @see multiType()
*/
static Type flatType( Type type );

/** Attempts to extract the WKB type from a WKT string.
* @param wktStr a valid WKT string
*/
static Type parseType( const QString& wktStr );

/** Returns true if the WKB type is a single type.
* @see isMultiType()
* @see singleType()
*/
static bool isSingleType( Type type );

/** Returns true if the WKB type is a multi type.
* @see isSingleType()
* @see multiType()
*/
static bool isMultiType( Type type );

/** Returns the inherent dimension of the geometry type as an integer. Returned value will
* always be less than or equal to the coordinate dimension.
* @returns 0 for point geometries, 1 for line geometries, 2 for polygon geometries
* Invalid geometry types will return a dimension of 0.
* @see coordDimensions()
*/
static int wkbDimensions( Type type );

/** Returns the coordinate dimension of the geometry type as an integer. Returned value will
* be between 2-4, depending on whether the geometry type contains the Z or M dimensions.
* Invalid geometry types will return a dimension of 0.
* @note added in QGIS 2.14
* @see wkbDimensions()
*/
static int coordDimensions( Type type );

/** Returns the geometry type for a WKB type, eg both MultiPolygon and CurvePolygon would have a
* PolygonGeometry geometry type.
*/
static GeometryType geometryType( Type type );

/** Returns a display string type for a WKB type, eg the geometry name used in WKT geometry representations.
*/
static QString displayString( Type type );

/** Tests whether a WKB type contains the z-dimension.
@@ -152,6 +194,23 @@ class CORE_EXPORT QgsWKBTypes
static Type addM( Type type );

private:

struct wkbEntry
{
wkbEntry( const QString& name, bool isMultiType, Type multiType, Type singleType, Type flatType, GeometryType geometryType,
bool hasZ, bool hasM ):
mName( name ), mIsMultiType( isMultiType ), mMultiType( multiType ), mSingleType( singleType ), mFlatType( flatType ), mGeometryType( geometryType ),
mHasZ( hasZ ), mHasM( hasM ) {}
QString mName;
bool mIsMultiType;
Type mMultiType;
Type mSingleType;
Type mFlatType;
GeometryType mGeometryType;
bool mHasZ;
bool mHasM;
};

static QMap<Type, wkbEntry> registerTypes();
static QMap<Type, wkbEntry>* entries();
};
@@ -27,7 +27,7 @@
# DON'T RAISE THIS THRESHOLD!!!
# (changes which lower this threshold are welcomed though!)

ACCEPTABLE_MISSING_DOCS = 3933
ACCEPTABLE_MISSING_DOCS = 3924


class TestQgsDocCoverage(TestCase):

0 comments on commit 87168c1

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