Skip to content

Commit 3e83faf

Browse files
committed
Expose QgsUnitTypes to QML
1 parent 58be4fc commit 3e83faf

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

src/core/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ SET(QGIS_CORE_MOC_HDRS
488488
qgstracer.h
489489
qgstransaction.h
490490
qgstransactiongroup.h
491+
qgsunittypes.h
491492
qgsvectordataprovider.h
492493
qgsvectorlayercache.h
493494
qgsvectorlayereditbuffer.h
@@ -705,7 +706,6 @@ SET(QGIS_CORE_HDRS
705706
qgstextlabelfeature.h
706707
qgstolerance.h
707708
qgstracer.h
708-
qgsunittypes.h
709709

710710
qgsvectordataprovider.h
711711
qgsvectorlayercache.h

src/core/qgsunittypes.h

+22-20
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
class CORE_EXPORT QgsUnitTypes
3636
{
37+
Q_GADGET
38+
3739
public:
3840

3941
//! Units of distance
@@ -102,89 +104,89 @@ class CORE_EXPORT QgsUnitTypes
102104

103105
/** Returns the type for a distance unit.
104106
*/
105-
static DistanceUnitType unitType( DistanceUnit unit );
107+
Q_INVOKABLE static DistanceUnitType unitType( DistanceUnit unit );
106108

107109
/** Encodes a distance unit to a string.
108110
* @param unit unit to encode
109111
* @returns encoded string
110112
* @see decodeDistanceUnit()
111113
*/
112-
static QString encodeUnit( QgsUnitTypes::DistanceUnit unit );
114+
Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::DistanceUnit unit );
113115

114116
/** Decodes a distance unit from a string.
115117
* @param string string to decode
116118
* @param ok optional boolean, will be set to true if string was converted successfully
117119
* @returns decoded units
118120
* @see encodeUnit()
119121
*/
120-
static QgsUnitTypes::DistanceUnit decodeDistanceUnit( const QString& string, bool *ok = 0 );
122+
Q_INVOKABLE static QgsUnitTypes::DistanceUnit decodeDistanceUnit( const QString& string, bool *ok = 0 );
121123

122124
/** Returns a translated string representing a distance unit.
123125
* @param unit unit to convert to string
124126
* @see stringToDistanceUnit()
125127
*/
126-
static QString toString( QgsUnitTypes::DistanceUnit unit );
128+
Q_INVOKABLE static QString toString( QgsUnitTypes::DistanceUnit unit );
127129

128130
/** Converts a translated string to a distance unit.
129131
* @param string string representing a distance unit
130132
* @param ok optional boolean, will be set to true if string was converted successfully
131133
* @see toString()
132134
*/
133-
static QgsUnitTypes::DistanceUnit stringToDistanceUnit( const QString& string, bool *ok = 0 );
135+
Q_INVOKABLE static QgsUnitTypes::DistanceUnit stringToDistanceUnit( const QString& string, bool *ok = 0 );
134136

135137
/** Returns the conversion factor between the specified distance units.
136138
* @param fromUnit distance unit to convert from
137139
* @param toUnit distance unit to convert to
138140
* @returns multiplication factor to convert between units
139141
*/
140-
static double fromUnitToUnitFactor( QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit );
142+
Q_INVOKABLE static double fromUnitToUnitFactor( QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit );
141143

142144
// AREAL UNITS
143145

144146
/** Returns the type for an areal unit.
145147
*/
146-
static DistanceUnitType unitType( AreaUnit unit );
148+
Q_INVOKABLE static DistanceUnitType unitType( AreaUnit unit );
147149

148150
/** Encodes an areal unit to a string.
149151
* @param unit unit to encode
150152
* @returns encoded string
151153
* @see decodeAreaUnit()
152154
*/
153-
static QString encodeUnit( AreaUnit unit );
155+
Q_INVOKABLE static QString encodeUnit( AreaUnit unit );
154156

155157
/** Decodes an areal unit from a string.
156158
* @param string string to decode
157159
* @param ok optional boolean, will be set to true if string was converted successfully
158160
* @returns decoded units
159161
* @see encodeUnit()
160162
*/
161-
static AreaUnit decodeAreaUnit( const QString& string, bool *ok = 0 );
163+
Q_INVOKABLE static AreaUnit decodeAreaUnit( const QString& string, bool *ok = 0 );
162164

163165
/** Returns a translated string representing an areal unit.
164166
* @param unit unit to convert to string
165167
* @see stringToAreaUnit()
166168
*/
167-
static QString toString( AreaUnit unit );
169+
Q_INVOKABLE static QString toString( AreaUnit unit );
168170

169171
/** Converts a translated string to an areal unit.
170172
* @param string string representing an areal unit
171173
* @param ok optional boolean, will be set to true if string was converted successfully
172174
* @see toString()
173175
*/
174-
static AreaUnit stringToAreaUnit( const QString& string, bool *ok = 0 );
176+
Q_INVOKABLE static AreaUnit stringToAreaUnit( const QString& string, bool *ok = 0 );
175177

176178
/** Returns the conversion factor between the specified areal units.
177179
* @param fromUnit area unit to convert from
178180
* @param toUnit area unit to convert to
179181
* @returns multiplication factor to convert between units
180182
*/
181-
static double fromUnitToUnitFactor( AreaUnit fromUnit, AreaUnit toUnit );
183+
Q_INVOKABLE static double fromUnitToUnitFactor( AreaUnit fromUnit, AreaUnit toUnit );
182184

183185
/** Converts a distance unit to its corresponding area unit, eg meters to square meters
184186
* @param distanceUnit distance unit to convert
185187
* @return matching areal unit
186188
*/
187-
static AreaUnit distanceToAreaUnit( QgsUnitTypes::DistanceUnit distanceUnit );
189+
Q_INVOKABLE static AreaUnit distanceToAreaUnit( QgsUnitTypes::DistanceUnit distanceUnit );
188190

189191
// ANGULAR UNITS
190192

@@ -193,35 +195,35 @@ class CORE_EXPORT QgsUnitTypes
193195
* @returns encoded string
194196
* @see decodeAngleUnit()
195197
*/
196-
static QString encodeUnit( AngleUnit unit );
198+
Q_INVOKABLE static QString encodeUnit( AngleUnit unit );
197199

198200
/** Decodes an angular unit from a string.
199201
* @param string string to decode
200202
* @param ok optional boolean, will be set to true if string was converted successfully
201203
* @returns decoded units
202204
* @see encodeUnit()
203205
*/
204-
static AngleUnit decodeAngleUnit( const QString& string, bool *ok = 0 );
206+
Q_INVOKABLE static AngleUnit decodeAngleUnit( const QString& string, bool *ok = 0 );
205207

206208
/** Returns a translated string representing an angular unit.
207209
* @param unit unit to convert to string
208210
*/
209-
static QString toString( AngleUnit unit );
211+
Q_INVOKABLE static QString toString( AngleUnit unit );
210212

211213
/** Returns the conversion factor between the specified angular units.
212214
* @param fromUnit angle unit to convert from
213215
* @param toUnit angle unit to convert to
214216
* @returns multiplication factor to convert between units
215217
*/
216-
static double fromUnitToUnitFactor( AngleUnit fromUnit, AngleUnit toUnit );
218+
Q_INVOKABLE static double fromUnitToUnitFactor( AngleUnit fromUnit, AngleUnit toUnit );
217219

218220
/** Returns an angle formatted as a friendly string.
219221
* @param angle angle to format
220222
* @param decimals number of decimal places to show
221223
* @param unit unit of angle
222224
* @returns formatted angle string
223225
*/
224-
static QString formatAngle( double angle, int decimals, AngleUnit unit );
226+
Q_INVOKABLE static QString formatAngle( double angle, int decimals, AngleUnit unit );
225227

226228
// RENDER UNITS
227229

@@ -230,15 +232,15 @@ class CORE_EXPORT QgsUnitTypes
230232
* @returns encoded string
231233
* @see decodeRenderUnit()
232234
*/
233-
static QString encodeUnit( RenderUnit unit );
235+
Q_INVOKABLE static QString encodeUnit( RenderUnit unit );
234236

235237
/** Decodes a render unit from a string.
236238
* @param string string to decode
237239
* @param ok optional boolean, will be set to true if string was converted successfully
238240
* @returns decoded units
239241
* @see encodeUnit()
240242
*/
241-
static RenderUnit decodeRenderUnit( const QString& string, bool *ok = 0 );
243+
Q_INVOKABLE static RenderUnit decodeRenderUnit( const QString& string, bool *ok = 0 );
242244

243245
};
244246

0 commit comments

Comments
 (0)