Skip to content

Commit 90d3ab6

Browse files
committedAug 23, 2012
Added converters for QGis:UNitTypes
1 parent 1873866 commit 90d3ab6

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
 

‎src/core/qgis.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,35 @@ const char* QGis::qgisFeatureTypes[] =
6767
"WKBMultiPolygon"
6868
};
6969

70+
7071
const double QGis::DEFAULT_IDENTIFY_RADIUS = 0.5;
7172

73+
// description strings for units
74+
// Order must match enum indices
75+
const char* QGis::qgisUnitTypes[] =
76+
{
77+
"meters",
78+
"feet",
79+
"degrees",
80+
"<unknown>",
81+
"degrees",
82+
"degrees",
83+
"degrees"
84+
};
85+
86+
QGis::UnitType QGis::fromString( QString unitTxt, QGis::UnitType defaultType )
87+
{
88+
for ( int i = 0; i < sizeof( qgisUnitTypes ); i++ )
89+
{
90+
if ( unitTxt == qgisUnitTypes[ i ] )
91+
{
92+
return static_cast<UnitType>( i );
93+
}
94+
}
95+
return defaultType;
96+
}
97+
98+
QString QGis::toString( QGis::UnitType unit )
99+
{
100+
return QString( qgisUnitTypes[ static_cast<int>( unit ) ] );
101+
}

‎src/core/qgis.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ class CORE_EXPORT QGis
9595
DegreesMinutesSeconds = 2, // was 4
9696
DegreesDecimalMinutes = 2, // was 5
9797
};
98+
// Converters for the above type
99+
static QString toString( QGis::UnitType unit );
100+
static UnitType fromString( QString unitTxt, QGis::UnitType defaultType = UnknownUnit );
98101

99102
//! User defined event types
100103
enum UserEvent
@@ -109,6 +112,11 @@ class CORE_EXPORT QGis
109112
};
110113

111114
static const double DEFAULT_IDENTIFY_RADIUS;
115+
116+
private:
117+
// String representation of unit types (set in qgis.cpp)
118+
static const char *qgisUnitTypes[];
119+
112120
};
113121

114122
// hack to workaround warnings when casting void pointers

0 commit comments

Comments
 (0)
Please sign in to comment.