|
1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Methods for Landmark editor number field. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 // INCLUDE FILES |
|
25 #include "CLmkEditorNumberField.h" |
|
26 #include "MLmkEditorUiBuilder.h" |
|
27 #include "LmkConsts.h" |
|
28 #include "landmarks.hrh" |
|
29 #include <eikcapc.h> |
|
30 #include <e32math.h> |
|
31 #include <aknuniteditor.h> |
|
32 #include <barsread.h> |
|
33 #include <lmkui.rsg> |
|
34 #include "clmkcentralrepository.h" |
|
35 #include <locnotprefplugindomaincrkeys.h> |
|
36 #include <centralrepository.h> |
|
37 #include <CLmkEditorDlg.h> |
|
38 |
|
39 //================== CONSTANTS=============================== |
|
40 const TReal KFootToMeterFraction = 0.3048; |
|
41 // ================= MEMBER FUNCTIONS ======================= |
|
42 |
|
43 // ---------------------------------------------------- |
|
44 // CLmkEditorNumberField::CLmkEditorNumberField |
|
45 // ---------------------------------------------------- |
|
46 // |
|
47 CLmkEditorNumberField::CLmkEditorNumberField |
|
48 ( MLmkFieldData& aField, |
|
49 MLmkEditorUiBuilder& aUiBuilder ) : |
|
50 CLmkEditorFieldBase( aField, aUiBuilder ) |
|
51 { |
|
52 } |
|
53 |
|
54 // ---------------------------------------------------- |
|
55 // CLmkEditorNumberField::ConstructL |
|
56 // ---------------------------------------------------- |
|
57 // |
|
58 void CLmkEditorNumberField::ConstructL() |
|
59 { |
|
60 iRepository = CLmkCentralRepository::NewL(); |
|
61 CreateAvkonUnitEditorL(); |
|
62 iCaptionedCtrl = iUiBuilder.LineControl( ControlId() ); |
|
63 iCaptionedCtrl->SetTakesEnterKey( ETrue ); |
|
64 } |
|
65 |
|
66 // ---------------------------------------------------- |
|
67 // CLmkEditorNumberField::NewL |
|
68 // ---------------------------------------------------- |
|
69 // |
|
70 CLmkEditorNumberField* CLmkEditorNumberField::NewL |
|
71 ( MLmkFieldData& aField, |
|
72 MLmkEditorUiBuilder& aUiBuilder ) |
|
73 { |
|
74 CLmkEditorNumberField* self = |
|
75 new(ELeave) CLmkEditorNumberField( aField, aUiBuilder ); |
|
76 CleanupStack::PushL( self ); |
|
77 self->ConstructL(); |
|
78 CleanupStack::Pop( self ); |
|
79 return self; |
|
80 } |
|
81 |
|
82 // ---------------------------------------------------- |
|
83 // CLmkEditorNumberField::~CLmkEditorNumberField |
|
84 // ---------------------------------------------------- |
|
85 // |
|
86 CLmkEditorNumberField::~CLmkEditorNumberField() |
|
87 { |
|
88 delete iRepository; |
|
89 } |
|
90 |
|
91 // ---------------------------------------------------- |
|
92 // CLmkEditorNumberField::SaveFieldL |
|
93 // ---------------------------------------------------- |
|
94 // |
|
95 TBool CLmkEditorNumberField::SaveFieldL() |
|
96 { |
|
97 TBool result = EFalse; |
|
98 TReal32 oldData = LandmarkItemField().FloatData(); |
|
99 TReal32 currData = iControl->Value(); |
|
100 if( oldData != currData) |
|
101 { |
|
102 if (!IsSystemUnitMetric()) |
|
103 { |
|
104 if (LandmarkItemField().FieldType() == EPositionAccuracy |
|
105 || LandmarkItemField().FieldType() == EAltitudeAccuracy) |
|
106 { |
|
107 if (currData < (KMinAccuracy / KFootToMeterFraction)) |
|
108 { |
|
109 currData = (KMinAccuracy / KFootToMeterFraction); |
|
110 } |
|
111 else if (currData > (KMaxAccuracy / KFootToMeterFraction)) |
|
112 { |
|
113 currData = (KMaxAccuracy / KFootToMeterFraction); |
|
114 } |
|
115 } |
|
116 else if (LandmarkItemField().FieldType() == EAltitude) |
|
117 { |
|
118 if (currData < (KMinAltitude / KFootToMeterFraction)) |
|
119 { |
|
120 currData = (KMinAltitude / KFootToMeterFraction); |
|
121 } |
|
122 else if (currData > (KMaxAltitude / KFootToMeterFraction)) |
|
123 { |
|
124 currData = (KMaxAltitude / KFootToMeterFraction); |
|
125 } |
|
126 } |
|
127 |
|
128 ConvertFromFootToMeters(currData); |
|
129 } |
|
130 else |
|
131 { |
|
132 if (LandmarkItemField().FieldType() == EPositionAccuracy |
|
133 || LandmarkItemField().FieldType() == EAltitudeAccuracy) |
|
134 { |
|
135 if (currData < KMinAccuracy) |
|
136 { |
|
137 currData = KMinAccuracy; |
|
138 } |
|
139 else if (currData > KMaxAccuracy) |
|
140 { |
|
141 currData = KMaxAccuracy; |
|
142 } |
|
143 } |
|
144 |
|
145 else if (LandmarkItemField().FieldType() == EAltitude) |
|
146 { |
|
147 if (currData < KMinAltitude) |
|
148 { |
|
149 currData = KMinAltitude; |
|
150 } |
|
151 else if (currData > KMaxAltitude) |
|
152 { |
|
153 currData = KMaxAltitude; |
|
154 } |
|
155 } |
|
156 } |
|
157 |
|
158 LandmarkItemField().SetTReal(currData); |
|
159 result = ETrue; |
|
160 } |
|
161 return result; |
|
162 } |
|
163 |
|
164 // ---------------------------------------------------- |
|
165 // CLmkEditorNumberField::ActivateL |
|
166 // ---------------------------------------------------- |
|
167 // |
|
168 void CLmkEditorNumberField::ActivateL() |
|
169 { |
|
170 iCaptionedCtrl->ActivateL(); |
|
171 } |
|
172 |
|
173 // ---------------------------------------------------- |
|
174 // CLmkEditorNumberField::UpdateL |
|
175 // ---------------------------------------------------- |
|
176 // |
|
177 void CLmkEditorNumberField::UpdateL() |
|
178 { |
|
179 TReal32 fieldData = LandmarkItemField().FloatData(); |
|
180 TReal32 dispData = fieldData; |
|
181 if( fieldData == iDbData) |
|
182 { |
|
183 dispData = iConvertedData; |
|
184 } |
|
185 else |
|
186 { |
|
187 if( !IsSystemUnitMetric()) |
|
188 { |
|
189 //Imperial |
|
190 iDbData = fieldData; |
|
191 ConvertFromMetersToFoot( fieldData); |
|
192 iConvertedData = fieldData; |
|
193 dispData = iConvertedData; |
|
194 } |
|
195 } |
|
196 |
|
197 ResolveUnitL(); |
|
198 iControl->SetValue( dispData ); |
|
199 } |
|
200 |
|
201 // ---------------------------------------------------- |
|
202 // CLmkEditorNumberField::CreateAvkonUnitEditorL |
|
203 // ---------------------------------------------------- |
|
204 // |
|
205 void CLmkEditorNumberField::CreateAvkonUnitEditorL() |
|
206 { |
|
207 // Create Distance editor using AVKON's unit editor |
|
208 // and insert a line in the dialog |
|
209 iControl = static_cast<CAknUnitEditor*>( iUiBuilder.CreateLineL( |
|
210 FieldLabel(), LandmarkItemField().UniqueFieldIdentity(), |
|
211 EAknCtUnitEditor ) ); |
|
212 //read control from resource file. |
|
213 TResourceReader reader; |
|
214 iEnv->CreateResourceReaderLC(reader, R_LMK_UNIT_EDITOR); |
|
215 iControl->ConstructFromResourceL(reader); |
|
216 CleanupStack::PopAndDestroy();// reader |
|
217 ResolveUnitL(); |
|
218 |
|
219 // Obtain the current system of measurement |
|
220 TInt sysOfMeasurement = EAknUnitEditorMeter; |
|
221 if( !IsSystemUnitMetric()) |
|
222 { |
|
223 sysOfMeasurement = EAknUnitEditorFoot; |
|
224 } |
|
225 |
|
226 /* |
|
227 if ( LandmarkItemField().FieldType() == EPositionAccuracy || |
|
228 LandmarkItemField().FieldType() == EAltitudeAccuracy ) |
|
229 { |
|
230 if( EAknUnitEditorMeter == sysOfMeasurement ) |
|
231 { |
|
232 iControl->SetMinimumAndMaximum(KMinAccuracy, KMaxAccuracy); |
|
233 } |
|
234 else |
|
235 { |
|
236 iControl->SetMinimumAndMaximum( KMinAccuracy / KFootToMeterFraction, |
|
237 KMaxAccuracy / KFootToMeterFraction ); |
|
238 } |
|
239 |
|
240 } |
|
241 else if ( LandmarkItemField().FieldType() == EAltitude ) |
|
242 { |
|
243 if( EAknUnitEditorMeter == sysOfMeasurement ) |
|
244 { |
|
245 iControl->SetMinimumAndMaximum( KMinAltitude, KMaxAltitude ); |
|
246 } |
|
247 else |
|
248 { |
|
249 iControl->SetMinimumAndMaximum( KMinAltitude / KFootToMeterFraction, |
|
250 KMaxAltitude / KFootToMeterFraction ); |
|
251 } |
|
252 } |
|
253 */ |
|
254 |
|
255 TReal32 fieldData = LandmarkItemField().FloatData(); |
|
256 iDbData = fieldData; |
|
257 iConvertedData = fieldData; |
|
258 |
|
259 if( EAknUnitEditorFoot == sysOfMeasurement ) |
|
260 { |
|
261 //Imperial |
|
262 ConvertFromMetersToFoot( fieldData); |
|
263 iConvertedData = fieldData; |
|
264 } |
|
265 iControl->SetValue(iConvertedData); |
|
266 } |
|
267 |
|
268 // ----------------------------------------------------------------------------- |
|
269 //CLmkEditorNumberField::FieldValue() |
|
270 // ----------------------------------------------------------------------------- |
|
271 // |
|
272 TReal CLmkEditorNumberField::FieldValue() const |
|
273 { |
|
274 return iControl->Value(); |
|
275 } |
|
276 |
|
277 // ----------------------------------------------------------------------------- |
|
278 //CLmkEditorNumberField::ResolveUnitL() |
|
279 // ----------------------------------------------------------------------------- |
|
280 // |
|
281 void CLmkEditorNumberField::ResolveUnitL() |
|
282 { |
|
283 TReal fieldData = LandmarkItemField().FloatData(); |
|
284 |
|
285 if( IsSystemUnitMetric()) |
|
286 { |
|
287 TInt fieldUnit = EAknUnitEditorMeter; |
|
288 iControl->SetUnitL( fieldUnit ); |
|
289 } |
|
290 else |
|
291 { |
|
292 TInt fieldUnit = EAknUnitEditorFoot; |
|
293 iControl->SetUnitL( fieldUnit ); |
|
294 } |
|
295 } |
|
296 |
|
297 // ----------------------------------------------------------------------------- |
|
298 //CLmkEditorNumberField::ConvertFromFootToMeters() |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 void CLmkEditorNumberField::ConvertFromFootToMeters(TReal32& aValue) |
|
302 { |
|
303 |
|
304 aValue *= KFootToMeterFraction; |
|
305 |
|
306 } |
|
307 |
|
308 // ----------------------------------------------------------------------------- |
|
309 //CLmkEditorNumberField::ConvertFromMetersToFoot() |
|
310 // ----------------------------------------------------------------------------- |
|
311 // |
|
312 void CLmkEditorNumberField::ConvertFromMetersToFoot(TReal32& aValue) |
|
313 { |
|
314 |
|
315 aValue /= KFootToMeterFraction; |
|
316 |
|
317 } |
|
318 |
|
319 // ----------------------------------------------------------------------------- |
|
320 //CLmkEditorNumberField::IsSystemUnitMetric() |
|
321 // ----------------------------------------------------------------------------- |
|
322 // |
|
323 TBool CLmkEditorNumberField::IsSystemUnitMetric() |
|
324 { |
|
325 TBool result = EFalse; |
|
326 TInt keyValue; |
|
327 TInt err = iRepository->GetKeyValue( KLocSystemofMeasurements, keyValue ); |
|
328 if( keyValue == EUnitsMetric ) |
|
329 { |
|
330 result = ETrue; |
|
331 } |
|
332 return result; |
|
333 } |
|
334 |
|
335 |
|
336 // ----------------------------------------------------------------------------- |
|
337 //CLmkEditorNumberField::HandleUnitChangeL() |
|
338 // ----------------------------------------------------------------------------- |
|
339 // |
|
340 void CLmkEditorNumberField::HandleUnitChangeL() |
|
341 { |
|
342 // Obtain the current system of measurement |
|
343 TInt sysOfMeasurement = EAknUnitEditorMeter; |
|
344 if( !IsSystemUnitMetric()) |
|
345 { |
|
346 sysOfMeasurement = EAknUnitEditorFoot; |
|
347 } |
|
348 |
|
349 TReal32 controlData = iControl->Value(); |
|
350 if( controlData != iConvertedData) |
|
351 { |
|
352 iConvertedData = controlData; |
|
353 } |
|
354 |
|
355 if( EAknUnitEditorMeter == sysOfMeasurement ) |
|
356 { |
|
357 |
|
358 //Imperial to metric |
|
359 ConvertFromFootToMeters( iConvertedData ); |
|
360 } |
|
361 else |
|
362 { |
|
363 //metric to imperial |
|
364 ConvertFromMetersToFoot( iConvertedData ); |
|
365 } |
|
366 |
|
367 if ( LandmarkItemField().FieldType() == EPositionAccuracy || |
|
368 LandmarkItemField().FieldType() == EAltitudeAccuracy ) |
|
369 { |
|
370 if( EAknUnitEditorMeter == sysOfMeasurement ) |
|
371 { |
|
372 iControl->SetMinimumAndMaximum(KMinAccuracy, KMaxAccuracy); |
|
373 } |
|
374 else |
|
375 { |
|
376 iControl->SetMinimumAndMaximum( KMinAccuracy / KFootToMeterFraction, |
|
377 KMaxAccuracy / KFootToMeterFraction ); |
|
378 } |
|
379 } |
|
380 else if ( LandmarkItemField().FieldType() == EAltitude ) |
|
381 { |
|
382 if( EAknUnitEditorMeter == sysOfMeasurement ) |
|
383 { |
|
384 iControl->SetMinimumAndMaximum( KMinAltitude, KMaxAltitude ); |
|
385 } |
|
386 else |
|
387 { |
|
388 iControl->SetMinimumAndMaximum( KMinAltitude / KFootToMeterFraction, |
|
389 KMaxAltitude / KFootToMeterFraction ); |
|
390 } |
|
391 } |
|
392 ResolveUnitL(); |
|
393 iControl->SetValue( iConvertedData ); |
|
394 } |
|
395 |
|
396 // ----------------------------------------------------------------------------- |
|
397 //CLmkEditorFieldBase::ResetL() |
|
398 // ----------------------------------------------------------------------------- |
|
399 // |
|
400 void CLmkEditorNumberField::ResetL() |
|
401 { |
|
402 TRealX temp; |
|
403 temp.SetNaN(); |
|
404 iControl->SetValue(temp); |
|
405 } |
|
406 // End of File |