Skip to content
Permalink
Browse files

Nicer creation of static QMaps

c++11/Qt5 allow us to clean up the creation and initialization
of static QMaps and avoid the need for initialization functions
  • Loading branch information
nyalldawson committed Jan 12, 2017
1 parent dbefbfe commit 3705ff18cef3ee26b60b4b9a18df8bfb68720d37
@@ -23,19 +23,85 @@
* See details in QEP #17
****************************************************************************/

QMap<QgsWkbTypes::Type, QgsWkbTypes::wkbEntry>* QgsWkbTypes::entries()
const QMap<QgsWkbTypes::Type, QgsWkbTypes::wkbEntry> QgsWkbTypes::sEntries
{
static QMap<QgsWkbTypes::Type, QgsWkbTypes::wkbEntry> entries = registerTypes();
return &entries;
}
//register the known wkb types
{ Unknown, wkbEntry( QStringLiteral( "Unknown" ), false, Unknown, Unknown, Unknown, UnknownGeometry, false, false ) },
{ NoGeometry, wkbEntry( QStringLiteral( "NoGeometry" ), false, NoGeometry, NoGeometry, NoGeometry, NullGeometry, false, false ) },
//point
{ Point, wkbEntry( QStringLiteral( "Point" ), false, MultiPoint, Point, Point, PointGeometry, false, false ) },
{ PointZ, wkbEntry( QStringLiteral( "PointZ" ), false, MultiPointZ, PointZ, Point, PointGeometry, true, false ) },
{ PointM, wkbEntry( QStringLiteral( "PointM" ), false, MultiPointM, PointM, Point, PointGeometry, false, true ) },
{ PointZM, wkbEntry( QStringLiteral( "PointZM" ), false, MultiPointZM, PointZM, Point, PointGeometry, true, true ) },
{ Point25D, wkbEntry( QStringLiteral( "Point25D" ), false, MultiPoint25D, Point25D, Point, PointGeometry, true, false ) },
//linestring
{ LineString, wkbEntry( QStringLiteral( "LineString" ), false, MultiLineString, LineString, LineString, LineGeometry, false, false ) },
{ LineStringZ, wkbEntry( QStringLiteral( "LineStringZ" ), false, MultiLineStringZ, LineStringZ, LineString, LineGeometry, true, false ) },
{ LineStringM, wkbEntry( QStringLiteral( "LineStringM" ), false, MultiLineStringM, LineStringM, LineString, LineGeometry, false, true ) },
{ LineStringZM, wkbEntry( QStringLiteral( "LineStringZM" ), false, MultiLineStringZM, LineStringZM, LineString, LineGeometry, true, true ) },
{ LineString25D, wkbEntry( QStringLiteral( "LineString25D" ), false, MultiLineString25D, LineString25D, LineString, LineGeometry, true, false ) },
//circularstring
{ CircularString, wkbEntry( QStringLiteral( "CircularString" ), false, MultiCurve, CircularString, CircularString, LineGeometry, false, false ) },
{ CircularStringZ, wkbEntry( QStringLiteral( "CircularStringZ" ), false, MultiCurveZ, CircularStringZ, CircularString, LineGeometry, true, false ) },
{ CircularStringM, wkbEntry( QStringLiteral( "CircularStringM" ), false, MultiCurveM, CircularStringM, CircularString, LineGeometry, false, true ) },
{ CircularStringZM, wkbEntry( QStringLiteral( "CircularStringZM" ), false, MultiCurveZM, CircularStringZM, CircularString, LineGeometry, true, true ) },
//compoundcurve
{ CompoundCurve, wkbEntry( QStringLiteral( "CompoundCurve" ), false, MultiCurve, CompoundCurve, CompoundCurve, LineGeometry, false, false ) },
{ CompoundCurveZ, wkbEntry( QStringLiteral( "CompoundCurveZ" ), false, MultiCurveZ, CompoundCurveZ, CompoundCurve, LineGeometry, true, false ) },
{ CompoundCurveM, wkbEntry( QStringLiteral( "CompoundCurveM" ), false, MultiCurveM, CompoundCurveM, CompoundCurve, LineGeometry, false, true ) },
{ CompoundCurveZM, wkbEntry( QStringLiteral( "CompoundCurveZM" ), false, MultiCurveZM, CompoundCurveZM, CompoundCurve, LineGeometry, true, true ) },
//polygon
{ Polygon, wkbEntry( QStringLiteral( "Polygon" ), false, MultiPolygon, Polygon, Polygon, PolygonGeometry, false, false ) },
{ PolygonZ, wkbEntry( QStringLiteral( "PolygonZ" ), false, MultiPolygonZ, PolygonZ, Polygon, PolygonGeometry, true, false ) },
{ PolygonM, wkbEntry( QStringLiteral( "PolygonM" ), false, MultiPolygonM, PolygonM, Polygon, PolygonGeometry, false, true ) },
{ PolygonZM, wkbEntry( QStringLiteral( "PolygonZM" ), false, MultiPolygonZM, PolygonZM, Polygon, PolygonGeometry, true, true ) },
{ Polygon25D, wkbEntry( QStringLiteral( "Polygon25D" ), false, MultiPolygon25D, Polygon25D, Polygon, PolygonGeometry, true, false ) },
//curvepolygon
{ CurvePolygon, wkbEntry( QStringLiteral( "CurvePolygon" ), false, MultiSurface, CurvePolygon, CurvePolygon, PolygonGeometry, false, false ) },
{ CurvePolygonZ, wkbEntry( QStringLiteral( "CurvePolygonZ" ), false, MultiSurfaceZ, CurvePolygonZ, CurvePolygon, PolygonGeometry, true, false ) },
{ CurvePolygonM, wkbEntry( QStringLiteral( "CurvePolygonM" ), false, MultiSurfaceM, CurvePolygonM, CurvePolygon, PolygonGeometry, false, true ) },
{ CurvePolygonZM, wkbEntry( QStringLiteral( "CurvePolygonZM" ), false, MultiSurfaceZM, CurvePolygonZM, CurvePolygon, PolygonGeometry, true, true ) },
//multipoint
{ MultiPoint, wkbEntry( QStringLiteral( "MultiPoint" ), true, MultiPoint, Point, MultiPoint, PointGeometry, false, false ) },
{ MultiPointZ, wkbEntry( QStringLiteral( "MultiPointZ" ), true, MultiPointZ, PointZ, MultiPoint, PointGeometry, true, false ) },
{ MultiPointM, wkbEntry( QStringLiteral( "MultiPointM" ), true, MultiPointM, PointM, MultiPoint, PointGeometry, false, true ) },
{ MultiPointZM, wkbEntry( QStringLiteral( "MultiPointZM" ), true, MultiPointZM, PointZM, MultiPoint, PointGeometry, true, true ) },
{ MultiPoint25D, wkbEntry( QStringLiteral( "MultiPoint25D" ), true, MultiPoint25D, Point25D, MultiPoint, PointGeometry, true, false ) },
//multiline
{ MultiLineString, wkbEntry( QStringLiteral( "MultiLineString" ), true, MultiLineString, LineString, MultiLineString, LineGeometry, false, false ) },
{ MultiLineStringZ, wkbEntry( QStringLiteral( "MultiLineStringZ" ), true, MultiLineStringZ, LineStringZ, MultiLineString, LineGeometry, true, false ) },
{ MultiLineStringM, wkbEntry( QStringLiteral( "MultiLineStringM" ), true, MultiLineStringM, LineStringM, MultiLineString, LineGeometry, false, true ) },
{ MultiLineStringZM, wkbEntry( QStringLiteral( "MultiLineStringZM" ), true, MultiLineStringZM, LineStringZM, MultiLineString, LineGeometry, true, true ) },
{ MultiLineString25D, wkbEntry( QStringLiteral( "MultiLineString25D" ), true, MultiLineString25D, LineString25D, MultiLineString, LineGeometry, true, false ) },
//multicurve
{ MultiCurve, wkbEntry( QStringLiteral( "MultiCurve" ), true, MultiCurve, CompoundCurve, MultiCurve, LineGeometry, false, false ) },
{ MultiCurveZ, wkbEntry( QStringLiteral( "MultiCurveZ" ), true, MultiCurveZ, CompoundCurveZ, MultiCurve, LineGeometry, true, false ) },
{ MultiCurveM, wkbEntry( QStringLiteral( "MultiCurveM" ), true, MultiCurveM, CompoundCurveM, MultiCurve, LineGeometry, false, true ) },
{ MultiCurveZM, wkbEntry( QStringLiteral( "MultiCurveZM" ), true, MultiCurveZM, CompoundCurveZM, MultiCurve, LineGeometry, true, true ) },
//multipolygon
{ MultiPolygon, wkbEntry( QStringLiteral( "MultiPolygon" ), true, MultiPolygon, Polygon, MultiPolygon, PolygonGeometry, false, false ) },
{ MultiPolygonZ, wkbEntry( QStringLiteral( "MultiPolygonZ" ), true, MultiPolygonZ, PolygonZ, MultiPolygon, PolygonGeometry, true, false ) },
{ MultiPolygonM, wkbEntry( QStringLiteral( "MultiPolygonM" ), true, MultiPolygonM, PolygonM, MultiPolygon, PolygonGeometry, false, true ) },
{ MultiPolygonZM, wkbEntry( QStringLiteral( "MultiPolygonZM" ), true, MultiPolygonZM, PolygonZM, MultiPolygon, PolygonGeometry, true, true ) },
{ MultiPolygon25D, wkbEntry( QStringLiteral( "MultiPolygon25D" ), true, MultiPolygon25D, Polygon25D, MultiPolygon, PolygonGeometry, true, false ) },
//multisurface
{ MultiSurface, wkbEntry( QStringLiteral( "MultiSurface" ), true, MultiSurface, CurvePolygon, MultiSurface, PolygonGeometry, false, false ) },
{ MultiSurfaceZ, wkbEntry( QStringLiteral( "MultiSurfaceZ" ), true, MultiSurfaceZ, CurvePolygonZ, MultiSurface, PolygonGeometry, true, false ) },
{ MultiSurfaceM, wkbEntry( QStringLiteral( "MultiSurfaceM" ), true, MultiSurfaceM, CurvePolygonM, MultiSurface, PolygonGeometry, false, true ) },
{ MultiSurfaceZM, wkbEntry( QStringLiteral( "MultiSurfaceZM" ), true, MultiSurfaceZM, CurvePolygonZM, MultiSurface, PolygonGeometry, true, true ) },
//geometrycollection
{ GeometryCollection, wkbEntry( QStringLiteral( "GeometryCollection" ), true, GeometryCollection, Unknown, GeometryCollection, UnknownGeometry, false, false ) },
{ GeometryCollectionZ, wkbEntry( QStringLiteral( "GeometryCollectionZ" ), true, GeometryCollectionZ, Unknown, GeometryCollection, UnknownGeometry, true, false ) },
{ GeometryCollectionM, wkbEntry( QStringLiteral( "GeometryCollectionM" ), true, GeometryCollectionM, Unknown, GeometryCollection, UnknownGeometry, false, true ) },
{ GeometryCollectionZM, wkbEntry( QStringLiteral( "GeometryCollectionZM" ), true, GeometryCollectionZM, Unknown, GeometryCollection, UnknownGeometry, true, true ) },
};

QgsWkbTypes::Type QgsWkbTypes::parseType( const QString &wktStr )
{
QString typestr = wktStr.left( wktStr.indexOf( '(' ) ).simplified().remove( ' ' );

QMap<QgsWkbTypes::Type, QgsWkbTypes::wkbEntry>* knownTypes = entries();
QMap<QgsWkbTypes::Type, QgsWkbTypes::wkbEntry>::const_iterator it = knownTypes->constBegin();
for ( ; it != knownTypes->constEnd(); ++it )
QMap<QgsWkbTypes::Type, QgsWkbTypes::wkbEntry>::const_iterator it = sEntries.constBegin();
for ( ; it != sEntries.constEnd(); ++it )
{
if ( it.value().mName.compare( typestr, Qt::CaseInsensitive ) == 0 )
{
@@ -47,8 +113,8 @@ QgsWkbTypes::Type QgsWkbTypes::parseType( const QString &wktStr )

QString QgsWkbTypes::displayString( Type type )
{
QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
if ( it == entries()->constEnd() )
QMap< Type, wkbEntry >::const_iterator it = sEntries.constFind( type );
if ( it == sEntries.constEnd() )
{
return QString::null;
}
@@ -82,78 +148,3 @@ QString QgsWkbTypes::geometryDisplayString( QgsWkbTypes::GeometryType type )
* full unit tests.
* See details in QEP #17
****************************************************************************/

QMap<QgsWkbTypes::Type, QgsWkbTypes::wkbEntry> QgsWkbTypes::registerTypes()
{
QMap<QgsWkbTypes::Type, QgsWkbTypes::wkbEntry> entries;
//register the known wkb types
entries.insert( Unknown, wkbEntry( QStringLiteral( "Unknown" ), false, Unknown, Unknown, Unknown, UnknownGeometry, false, false ) );
entries.insert( NoGeometry, wkbEntry( QStringLiteral( "NoGeometry" ), false, NoGeometry, NoGeometry, NoGeometry, NullGeometry, false, false ) );
//point
entries.insert( Point, wkbEntry( QStringLiteral( "Point" ), false, MultiPoint, Point, Point, PointGeometry, false, false ) );
entries.insert( PointZ, wkbEntry( QStringLiteral( "PointZ" ), false, MultiPointZ, PointZ, Point, PointGeometry, true, false ) );
entries.insert( PointM, wkbEntry( QStringLiteral( "PointM" ), false, MultiPointM, PointM, Point, PointGeometry, false, true ) );
entries.insert( PointZM, wkbEntry( QStringLiteral( "PointZM" ), false, MultiPointZM, PointZM, Point, PointGeometry, true, true ) );
entries.insert( Point25D, wkbEntry( QStringLiteral( "Point25D" ), false, MultiPoint25D, Point25D, Point, PointGeometry, true, false ) );
//linestring
entries.insert( LineString, wkbEntry( QStringLiteral( "LineString" ), false, MultiLineString, LineString, LineString, LineGeometry, false, false ) );
entries.insert( LineStringZ, wkbEntry( QStringLiteral( "LineStringZ" ), false, MultiLineStringZ, LineStringZ, LineString, LineGeometry, true, false ) );
entries.insert( LineStringM, wkbEntry( QStringLiteral( "LineStringM" ), false, MultiLineStringM, LineStringM, LineString, LineGeometry, false, true ) );
entries.insert( LineStringZM, wkbEntry( QStringLiteral( "LineStringZM" ), false, MultiLineStringZM, LineStringZM, LineString, LineGeometry, true, true ) );
entries.insert( LineString25D, wkbEntry( QStringLiteral( "LineString25D" ), false, MultiLineString25D, LineString25D, LineString, LineGeometry, true, false ) );
//circularstring
entries.insert( CircularString, wkbEntry( QStringLiteral( "CircularString" ), false, MultiCurve, CircularString, CircularString, LineGeometry, false, false ) );
entries.insert( CircularStringZ, wkbEntry( QStringLiteral( "CircularStringZ" ), false, MultiCurveZ, CircularStringZ, CircularString, LineGeometry, true, false ) );
entries.insert( CircularStringM, wkbEntry( QStringLiteral( "CircularStringM" ), false, MultiCurveM, CircularStringM, CircularString, LineGeometry, false, true ) );
entries.insert( CircularStringZM, wkbEntry( QStringLiteral( "CircularStringZM" ), false, MultiCurveZM, CircularStringZM, CircularString, LineGeometry, true, true ) );
//compoundcurve
entries.insert( CompoundCurve, wkbEntry( QStringLiteral( "CompoundCurve" ), false, MultiCurve, CompoundCurve, CompoundCurve, LineGeometry, false, false ) );
entries.insert( CompoundCurveZ, wkbEntry( QStringLiteral( "CompoundCurveZ" ), false, MultiCurveZ, CompoundCurveZ, CompoundCurve, LineGeometry, true, false ) );
entries.insert( CompoundCurveM, wkbEntry( QStringLiteral( "CompoundCurveM" ), false, MultiCurveM, CompoundCurveM, CompoundCurve, LineGeometry, false, true ) );
entries.insert( CompoundCurveZM, wkbEntry( QStringLiteral( "CompoundCurveZM" ), false, MultiCurveZM, CompoundCurveZM, CompoundCurve, LineGeometry, true, true ) );
//polygon
entries.insert( Polygon, wkbEntry( QStringLiteral( "Polygon" ), false, MultiPolygon, Polygon, Polygon, PolygonGeometry, false, false ) );
entries.insert( PolygonZ, wkbEntry( QStringLiteral( "PolygonZ" ), false, MultiPolygonZ, PolygonZ, Polygon, PolygonGeometry, true, false ) );
entries.insert( PolygonM, wkbEntry( QStringLiteral( "PolygonM" ), false, MultiPolygonM, PolygonM, Polygon, PolygonGeometry, false, true ) );
entries.insert( PolygonZM, wkbEntry( QStringLiteral( "PolygonZM" ), false, MultiPolygonZM, PolygonZM, Polygon, PolygonGeometry, true, true ) );
entries.insert( Polygon25D, wkbEntry( QStringLiteral( "Polygon25D" ), false, MultiPolygon25D, Polygon25D, Polygon, PolygonGeometry, true, false ) );
//curvepolygon
entries.insert( CurvePolygon, wkbEntry( QStringLiteral( "CurvePolygon" ), false, MultiSurface, CurvePolygon, CurvePolygon, PolygonGeometry, false, false ) );
entries.insert( CurvePolygonZ, wkbEntry( QStringLiteral( "CurvePolygonZ" ), false, MultiSurfaceZ, CurvePolygonZ, CurvePolygon, PolygonGeometry, true, false ) );
entries.insert( CurvePolygonM, wkbEntry( QStringLiteral( "CurvePolygonM" ), false, MultiSurfaceM, CurvePolygonM, CurvePolygon, PolygonGeometry, false, true ) );
entries.insert( CurvePolygonZM, wkbEntry( QStringLiteral( "CurvePolygonZM" ), false, MultiSurfaceZM, CurvePolygonZM, CurvePolygon, PolygonGeometry, true, true ) );
//multipoint
entries.insert( MultiPoint, wkbEntry( QStringLiteral( "MultiPoint" ), true, MultiPoint, Point, MultiPoint, PointGeometry, false, false ) );
entries.insert( MultiPointZ, wkbEntry( QStringLiteral( "MultiPointZ" ), true, MultiPointZ, PointZ, MultiPoint, PointGeometry, true, false ) );
entries.insert( MultiPointM, wkbEntry( QStringLiteral( "MultiPointM" ), true, MultiPointM, PointM, MultiPoint, PointGeometry, false, true ) );
entries.insert( MultiPointZM, wkbEntry( QStringLiteral( "MultiPointZM" ), true, MultiPointZM, PointZM, MultiPoint, PointGeometry, true, true ) );
entries.insert( MultiPoint25D, wkbEntry( QStringLiteral( "MultiPoint25D" ), true, MultiPoint25D, Point25D, MultiPoint, PointGeometry, true, false ) );
//multiline
entries.insert( MultiLineString, wkbEntry( QStringLiteral( "MultiLineString" ), true, MultiLineString, LineString, MultiLineString, LineGeometry, false, false ) );
entries.insert( MultiLineStringZ, wkbEntry( QStringLiteral( "MultiLineStringZ" ), true, MultiLineStringZ, LineStringZ, MultiLineString, LineGeometry, true, false ) );
entries.insert( MultiLineStringM, wkbEntry( QStringLiteral( "MultiLineStringM" ), true, MultiLineStringM, LineStringM, MultiLineString, LineGeometry, false, true ) );
entries.insert( MultiLineStringZM, wkbEntry( QStringLiteral( "MultiLineStringZM" ), true, MultiLineStringZM, LineStringZM, MultiLineString, LineGeometry, true, true ) );
entries.insert( MultiLineString25D, wkbEntry( QStringLiteral( "MultiLineString25D" ), true, MultiLineString25D, LineString25D, MultiLineString, LineGeometry, true, false ) );
//multicurve
entries.insert( MultiCurve, wkbEntry( QStringLiteral( "MultiCurve" ), true, MultiCurve, CompoundCurve, MultiCurve, LineGeometry, false, false ) );
entries.insert( MultiCurveZ, wkbEntry( QStringLiteral( "MultiCurveZ" ), true, MultiCurveZ, CompoundCurveZ, MultiCurve, LineGeometry, true, false ) );
entries.insert( MultiCurveM, wkbEntry( QStringLiteral( "MultiCurveM" ), true, MultiCurveM, CompoundCurveM, MultiCurve, LineGeometry, false, true ) );
entries.insert( MultiCurveZM, wkbEntry( QStringLiteral( "MultiCurveZM" ), true, MultiCurveZM, CompoundCurveZM, MultiCurve, LineGeometry, true, true ) );
//multipolygon
entries.insert( MultiPolygon, wkbEntry( QStringLiteral( "MultiPolygon" ), true, MultiPolygon, Polygon, MultiPolygon, PolygonGeometry, false, false ) );
entries.insert( MultiPolygonZ, wkbEntry( QStringLiteral( "MultiPolygonZ" ), true, MultiPolygonZ, PolygonZ, MultiPolygon, PolygonGeometry, true, false ) );
entries.insert( MultiPolygonM, wkbEntry( QStringLiteral( "MultiPolygonM" ), true, MultiPolygonM, PolygonM, MultiPolygon, PolygonGeometry, false, true ) );
entries.insert( MultiPolygonZM, wkbEntry( QStringLiteral( "MultiPolygonZM" ), true, MultiPolygonZM, PolygonZM, MultiPolygon, PolygonGeometry, true, true ) );
entries.insert( MultiPolygon25D, wkbEntry( QStringLiteral( "MultiPolygon25D" ), true, MultiPolygon25D, Polygon25D, MultiPolygon, PolygonGeometry, true, false ) );
//multisurface
entries.insert( MultiSurface, wkbEntry( QStringLiteral( "MultiSurface" ), true, MultiSurface, CurvePolygon, MultiSurface, PolygonGeometry, false, false ) );
entries.insert( MultiSurfaceZ, wkbEntry( QStringLiteral( "MultiSurfaceZ" ), true, MultiSurfaceZ, CurvePolygonZ, MultiSurface, PolygonGeometry, true, false ) );
entries.insert( MultiSurfaceM, wkbEntry( QStringLiteral( "MultiSurfaceM" ), true, MultiSurfaceM, CurvePolygonM, MultiSurface, PolygonGeometry, false, true ) );
entries.insert( MultiSurfaceZM, wkbEntry( QStringLiteral( "MultiSurfaceZM" ), true, MultiSurfaceZM, CurvePolygonZM, MultiSurface, PolygonGeometry, true, true ) );
//geometrycollection
entries.insert( GeometryCollection, wkbEntry( QStringLiteral( "GeometryCollection" ), true, GeometryCollection, Unknown, GeometryCollection, UnknownGeometry, false, false ) );
entries.insert( GeometryCollectionZ, wkbEntry( QStringLiteral( "GeometryCollectionZ" ), true, GeometryCollectionZ, Unknown, GeometryCollection, UnknownGeometry, true, false ) );
entries.insert( GeometryCollectionM, wkbEntry( QStringLiteral( "GeometryCollectionM" ), true, GeometryCollectionM, Unknown, GeometryCollection, UnknownGeometry, false, true ) );
entries.insert( GeometryCollectionZM, wkbEntry( QStringLiteral( "GeometryCollectionZM" ), true, GeometryCollectionZM, Unknown, GeometryCollection, UnknownGeometry, true, true ) );
return entries;
}
@@ -926,8 +926,7 @@ class CORE_EXPORT QgsWkbTypes
bool mHasM;
};

static QMap<Type, wkbEntry> registerTypes();
static QMap<Type, wkbEntry>* entries();
static const QMap<Type, wkbEntry> sEntries;
};

#endif // QGSWKBTYPES_H
@@ -1261,9 +1261,6 @@ class CORE_EXPORT QgsExpression
protected:
void initGeomCalculator();

static QMap<QString, QVariant> gmSpecialColumns;
static QMap<QString, QString> gmSpecialColumnGroups;

struct HelpArg
{
HelpArg( const QString& arg, const QString& desc, bool descOnly = false, bool syntaxOnly = false,

0 comments on commit 3705ff1

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