37
|
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 |
|
|
213 |
|
|
214 |
|
|
215 |
// Obtain the current system of measurement
|
|
216 |
TInt sysOfMeasurement = EAknUnitEditorMeter;
|
|
217 |
if( !IsSystemUnitMetric())
|
|
218 |
{
|
|
219 |
sysOfMeasurement = EAknUnitEditorFoot;
|
|
220 |
}
|
|
221 |
|
|
222 |
//read control from resource file.
|
|
223 |
TResourceReader reader;
|
|
224 |
if( sysOfMeasurement == EAknUnitEditorMeter)
|
|
225 |
{
|
|
226 |
iEnv->CreateResourceReaderLC(reader, R_LMK_UNIT_EDITOR_METRIC);
|
|
227 |
}
|
|
228 |
else
|
|
229 |
{
|
|
230 |
iEnv->CreateResourceReaderLC(reader, R_LMK_UNIT_EDITOR_IMPERIAL);
|
|
231 |
}
|
|
232 |
|
|
233 |
iControl->ConstructFromResourceL(reader);
|
|
234 |
CleanupStack::PopAndDestroy(); //reader
|
|
235 |
ResolveUnitL();
|
|
236 |
|
|
237 |
/*
|
|
238 |
if ( LandmarkItemField().FieldType() == EPositionAccuracy ||
|
|
239 |
LandmarkItemField().FieldType() == EAltitudeAccuracy )
|
|
240 |
{
|
|
241 |
if( EAknUnitEditorMeter == sysOfMeasurement )
|
|
242 |
{
|
|
243 |
iControl->SetMinimumAndMaximum(KMinAccuracy, KMaxAccuracy);
|
|
244 |
}
|
|
245 |
else
|
|
246 |
{
|
|
247 |
iControl->SetMinimumAndMaximum( KMinAccuracy / KFootToMeterFraction,
|
|
248 |
KMaxAccuracy / KFootToMeterFraction );
|
|
249 |
}
|
|
250 |
|
|
251 |
}
|
|
252 |
else if ( LandmarkItemField().FieldType() == EAltitude )
|
|
253 |
{
|
|
254 |
if( EAknUnitEditorMeter == sysOfMeasurement )
|
|
255 |
{
|
|
256 |
iControl->SetMinimumAndMaximum( KMinAltitude, KMaxAltitude );
|
|
257 |
}
|
|
258 |
else
|
|
259 |
{
|
|
260 |
iControl->SetMinimumAndMaximum( KMinAltitude / KFootToMeterFraction,
|
|
261 |
KMaxAltitude / KFootToMeterFraction );
|
|
262 |
}
|
|
263 |
}
|
|
264 |
*/
|
|
265 |
|
|
266 |
TReal32 fieldData = LandmarkItemField().FloatData();
|
|
267 |
iDbData = fieldData;
|
|
268 |
iConvertedData = fieldData;
|
|
269 |
|
|
270 |
if( EAknUnitEditorFoot == sysOfMeasurement )
|
|
271 |
{
|
|
272 |
//Imperial
|
|
273 |
ConvertFromMetersToFoot( fieldData);
|
|
274 |
iConvertedData = fieldData;
|
|
275 |
}
|
|
276 |
iControl->SetValue(iConvertedData);
|
|
277 |
}
|
|
278 |
|
|
279 |
// -----------------------------------------------------------------------------
|
|
280 |
//CLmkEditorNumberField::FieldValue()
|
|
281 |
// -----------------------------------------------------------------------------
|
|
282 |
//
|
|
283 |
TReal CLmkEditorNumberField::FieldValue() const
|
|
284 |
{
|
|
285 |
return iControl->Value();
|
|
286 |
}
|
|
287 |
|
|
288 |
// -----------------------------------------------------------------------------
|
|
289 |
//CLmkEditorNumberField::ResolveUnitL()
|
|
290 |
// -----------------------------------------------------------------------------
|
|
291 |
//
|
|
292 |
void CLmkEditorNumberField::ResolveUnitL()
|
|
293 |
{
|
|
294 |
TReal fieldData = LandmarkItemField().FloatData();
|
|
295 |
|
|
296 |
if( IsSystemUnitMetric())
|
|
297 |
{
|
|
298 |
TInt fieldUnit = EAknUnitEditorMeter;
|
|
299 |
iControl->SetUnitL( fieldUnit );
|
|
300 |
}
|
|
301 |
else
|
|
302 |
{
|
|
303 |
TInt fieldUnit = EAknUnitEditorFoot;
|
|
304 |
iControl->SetUnitL( fieldUnit );
|
|
305 |
}
|
|
306 |
}
|
|
307 |
|
|
308 |
// -----------------------------------------------------------------------------
|
|
309 |
//CLmkEditorNumberField::ConvertFromFootToMeters()
|
|
310 |
// -----------------------------------------------------------------------------
|
|
311 |
//
|
|
312 |
void CLmkEditorNumberField::ConvertFromFootToMeters(TReal32& aValue)
|
|
313 |
{
|
|
314 |
|
|
315 |
aValue *= KFootToMeterFraction;
|
|
316 |
|
|
317 |
}
|
|
318 |
|
|
319 |
// -----------------------------------------------------------------------------
|
|
320 |
//CLmkEditorNumberField::ConvertFromMetersToFoot()
|
|
321 |
// -----------------------------------------------------------------------------
|
|
322 |
//
|
|
323 |
void CLmkEditorNumberField::ConvertFromMetersToFoot(TReal32& aValue)
|
|
324 |
{
|
|
325 |
|
|
326 |
aValue /= KFootToMeterFraction;
|
|
327 |
|
|
328 |
}
|
|
329 |
|
|
330 |
// -----------------------------------------------------------------------------
|
|
331 |
//CLmkEditorNumberField::IsSystemUnitMetric()
|
|
332 |
// -----------------------------------------------------------------------------
|
|
333 |
//
|
|
334 |
TBool CLmkEditorNumberField::IsSystemUnitMetric()
|
|
335 |
{
|
|
336 |
TBool result = EFalse;
|
|
337 |
TInt keyValue;
|
|
338 |
TInt err = iRepository->GetKeyValue( KLocSystemofMeasurements, keyValue );
|
|
339 |
if( keyValue == EUnitsMetric )
|
|
340 |
{
|
|
341 |
result = ETrue;
|
|
342 |
}
|
|
343 |
return result;
|
|
344 |
}
|
|
345 |
|
|
346 |
|
|
347 |
// -----------------------------------------------------------------------------
|
|
348 |
//CLmkEditorNumberField::HandleUnitChangeL()
|
|
349 |
// -----------------------------------------------------------------------------
|
|
350 |
//
|
|
351 |
void CLmkEditorNumberField::HandleUnitChangeL()
|
|
352 |
{
|
|
353 |
// Obtain the current system of measurement
|
|
354 |
TInt sysOfMeasurement = EAknUnitEditorMeter;
|
|
355 |
if( !IsSystemUnitMetric())
|
|
356 |
{
|
|
357 |
sysOfMeasurement = EAknUnitEditorFoot;
|
|
358 |
}
|
|
359 |
|
|
360 |
TReal32 controlData = iControl->Value();
|
|
361 |
if( controlData != iConvertedData)
|
|
362 |
{
|
|
363 |
iConvertedData = controlData;
|
|
364 |
}
|
|
365 |
|
|
366 |
if( EAknUnitEditorMeter == sysOfMeasurement )
|
|
367 |
{
|
|
368 |
|
|
369 |
//Imperial to metric
|
|
370 |
ConvertFromFootToMeters( iConvertedData );
|
|
371 |
}
|
|
372 |
else
|
|
373 |
{
|
|
374 |
//metric to imperial
|
|
375 |
ConvertFromMetersToFoot( iConvertedData );
|
|
376 |
}
|
|
377 |
|
|
378 |
if ( LandmarkItemField().FieldType() == EPositionAccuracy ||
|
|
379 |
LandmarkItemField().FieldType() == EAltitudeAccuracy )
|
|
380 |
{
|
|
381 |
if( EAknUnitEditorMeter == sysOfMeasurement )
|
|
382 |
{
|
|
383 |
iControl->SetMinimumAndMaximum(KMinAccuracy, KMaxAccuracy);
|
|
384 |
}
|
|
385 |
else
|
|
386 |
{
|
|
387 |
iControl->SetMinimumAndMaximum( KMinAccuracy / KFootToMeterFraction,
|
|
388 |
KMaxAccuracy / KFootToMeterFraction );
|
|
389 |
}
|
|
390 |
}
|
|
391 |
else if ( LandmarkItemField().FieldType() == EAltitude )
|
|
392 |
{
|
|
393 |
if( EAknUnitEditorMeter == sysOfMeasurement )
|
|
394 |
{
|
|
395 |
iControl->SetMinimumAndMaximum( KMinAltitude, KMaxAltitude );
|
|
396 |
}
|
|
397 |
else
|
|
398 |
{
|
|
399 |
iControl->SetMinimumAndMaximum( KMinAltitude / KFootToMeterFraction,
|
|
400 |
KMaxAltitude / KFootToMeterFraction );
|
|
401 |
}
|
|
402 |
}
|
|
403 |
ResolveUnitL();
|
|
404 |
iControl->SetValue( iConvertedData );
|
|
405 |
}
|
|
406 |
|
|
407 |
// -----------------------------------------------------------------------------
|
|
408 |
//CLmkEditorFieldBase::ResetL()
|
|
409 |
// -----------------------------------------------------------------------------
|
|
410 |
//
|
|
411 |
void CLmkEditorNumberField::ResetL()
|
|
412 |
{
|
|
413 |
TRealX temp;
|
|
414 |
temp.SetNaN();
|
|
415 |
iControl->SetValue(temp);
|
|
416 |
}
|
|
417 |
// End of File
|