Nokia N97 SDK
Example Applications Guide

CUEExForm Class Reference

#include <ueexform.h>

Inheritance diagram for CUEExForm:

List of all members.

Detailed Description

CUEExForm

This is a subclass of CAknForm. In this example it is used as a simple container for unit editor. The class' ProcessCommandL() contains some usual use cases for the editor. The unit editor itself is created by dialog/form, see resource file ueex.rss for details on that. Unit editor can also be created dynamically using CAknUnitEditor::NewL() and CAknUnitEditor::ConstructL() without the need for any resources. In this example the unit editor is created with the flag EAknUnitEditorAllowUninitialized which in practice means that setting a not a number value to the editor is allowed.

Once the unit editor is created, its usage is pretty straightforward. See the private DoSet and DoGet functions for details.

Definition at line 38 of file ueexform.h.


Public Member Functions

void  ProcessCommandL (TInt aCommandId)
void  DynInitMenuPaneL (TInt aResourceId, CEikMenuPane *aMenuPane)
TBool  QuerySaveChangesL ()

Private Member Functions

void  DoSetValue (CAknUnitEditor *aUnitEditor)
void  DoSetNaN (CAknUnitEditor *aUnitEditor)
void  DoSetMinMax (CAknUnitEditor *aUnitEditor)
void  DoSetUnit (CAknUnitEditor *aUnitEditor)
void  DoSetCustomUnit (CAknUnitEditor *aUnitEditor)
void  DoSetMaxFractionalDigits (CAknUnitEditor *aUnitEditor)
void  DoGetValue (CAknUnitEditor *aUnitEditor)


Member Function Documentation

void CUEExForm::ProcessCommandL (  TInt  aCommandId  ) 
 

Function from MEikCommandObserver. Handle user menu commands. If a leave occurs the framework generates a Symbian Leave code.

Parameters:
aCommandId  The command identifier to process.

Definition at line 34 of file ueexform.cpp.

References DoGetValue(), DoSetCustomUnit(), DoSetMaxFractionalDigits(), DoSetMinMax(), DoSetNaN(), DoSetUnit(), and DoSetValue().

00035     {
00036     CAknUnitEditor* unitEditor =
00037         static_cast<CAknUnitEditor*>( ControlOrNull( EUEExUnitEditor ) );
00038     
00039     if ( unitEditor )
00040         {
00041         switch ( aCommandId )
00042             {
00043             case ECmdSetValue:
00044                 DoSetValue( unitEditor );
00045             break;
00046             case ECmdSetNan:
00047                 DoSetNaN( unitEditor );
00048             break;
00049             case ECmdSetMinMax:
00050                 DoSetMinMax( unitEditor );
00051             break;
00052             case ECmdSetUnit:
00053                 DoSetUnit( unitEditor );
00054             break;
00055             case ECmdSetCustomUnit:
00056                 DoSetCustomUnit( unitEditor );
00057             break;
00058             case ECmdSetMaxFractionalDigits:
00059                 DoSetMaxFractionalDigits( unitEditor );
00060             break;
00061             case ECmdGetValue:
00062                 DoGetValue( unitEditor );
00063             break;
00064             default:
00065             break;
00066             }
00067         }
00068 
00069     // Exit form gracefully
00070     if ( aCommandId == EAknCmdExit )
00071         {
00072         TryExitL( EAknSoftkeyBack );
00073         }
00074     else
00075         {
00076         CAknForm::ProcessCommandL( aCommandId );
00077         }
00078     }

void CUEExForm::DynInitMenuPaneL (  TInt  aResourceId,
CEikMenuPane *  aMenuPane
) 
 

Function from MEikMenuObserver. The framework calls this function. It removes the unused default form options. If a leave occurs the framework generates a Symbian Leave code.

Parameters:
aResourceId  The ID of the menu pane.
aMenuPane  The menu pane itself.

Definition at line 85 of file ueexform.cpp.

00086     {
00087     CAknForm::DynInitMenuPaneL( aResourceId, aMenuPane );
00088     
00089     if ( aResourceId == R_AVKON_FORM_MENUPANE )
00090         {
00091         // Disable the Label, Add, Delete, and Save Field
00092         aMenuPane->SetItemDimmed( EAknFormCmdLabel, ETrue );
00093         aMenuPane->SetItemDimmed( EAknFormCmdAdd, ETrue );
00094         aMenuPane->SetItemDimmed( EAknFormCmdDelete, ETrue );
00095         aMenuPane->SetItemDimmed( EAknFormCmdSave, ETrue );
00096         }
00097     }    

TBool CUEExForm::QuerySaveChangesL (   ) 
 

Overriden from CAknForm not to display the save changes query.

Returns:
ETrue if changes are requested to be saved and then are successfully saved. Save of data is not performed here but in SaveFormDataL().

Definition at line 103 of file ueexform.cpp.

00104     {
00105     return EFalse;
00106     }

void CUEExForm::DoSetValue (  CAknUnitEditor *  aUnitEditor  )  [private]
 

Shows a query and sets the value to the editor. This shows how to use the function CAknUnitEditor::SetValue().

Parameters:
aUnitEditor  Pointer to the unit editor to modify

Definition at line 113 of file ueexform.cpp.

Referenced by ProcessCommandL().

00114     {
00115     TInt number( 0 );
00116     CAknNumberQueryDialog* dlg = CAknNumberQueryDialog::NewL( number );
00117     dlg->PrepareLC( R_AVKON_DIALOG_QUERY_VALUE_NUMBER );
00118     dlg->SetMinimumAndMaximum( KMinTInt, KMaxTInt );
00119     if ( dlg->RunLD() )
00120         {
00121         aUnitEditor->SetValue( number );
00122         }    
00123     }

void CUEExForm::DoSetNaN (  CAknUnitEditor *  aUnitEditor  )  [private]
 

Sets a not a number value to the editor. This shows how to set a not a number value to the editor. Note that this requires the editor to have the flag EAknUnitEditorAllowUninitialized set.

Parameters:
aUnitEditor  Pointer to the unit editor to modify

Definition at line 129 of file ueexform.cpp.

Referenced by ProcessCommandL().

00130     {
00131     TRealX nan;
00132     nan.SetNaN();
00133     aUnitEditor->SetValue( nan );    
00134     }

void CUEExForm::DoSetMinMax (  CAknUnitEditor *  aUnitEditor  )  [private]
 

Shows two queries and sets the editor's min and max values accordingly. This shows how to use CAknUnitEditor::SetMinimumAndMaximum().

Parameters:
aUnitEditor  Pointer to the unit editor to modify

Definition at line 140 of file ueexform.cpp.

Referenced by ProcessCommandL().

00141     {
00142     TInt newMin( 0 );
00143     TInt newMax( 0 );
00144     TInt ret;
00145     
00146     CAknNumberQueryDialog* dlg = CAknNumberQueryDialog::NewL( newMin );
00147     dlg->PrepareLC( R_NEWMINQUERY );
00148     dlg->SetMinimumAndMaximum( KMinTInt, KMaxTInt );
00149     ret = dlg->RunLD();
00150     
00151     if ( ret == EAknSoftkeyOk )
00152         {
00153         dlg = CAknNumberQueryDialog::NewL( newMax );
00154         dlg->PrepareLC( R_NEWMAXQUERY );
00155         dlg->SetMinimumAndMaximum( KMinTInt, KMaxTInt );
00156         ret = dlg->RunLD();
00157         
00158         if ( ret == EAknSoftkeyOk )
00159             {
00160             aUnitEditor->SetMinimumAndMaximum( newMin, newMax ); 
00161             }
00162         }
00163     }

void CUEExForm::DoSetUnit (  CAknUnitEditor *  aUnitEditor  )  [private]
 

Sets a hardcoded localized unit to the editor. There exists a set a predefined localized units for use with the unit editor. These are listed in enum TAknUnitEditorUnits in eikon.hrh. Although not used in this example, there's TBool CAknUnitEditor::SupportsUnit() which can be used to check if the editor supports a certain localized unit in case the localized units are extended in future versions.

Parameters:
aUnitEditor  Pointer to the unit editor to modify

Definition at line 169 of file ueexform.cpp.

Referenced by ProcessCommandL().

00170     {
00171     TRAP_IGNORE( aUnitEditor->SetUnitL( EAknUnitEditorMetricSpeed ) );
00172     }

void CUEExForm::DoSetCustomUnit (  CAknUnitEditor *  aUnitEditor  )  [private]
 

Sets a hardcoded custom unit to the editor. This shows how to set a custom string as the unit. It also automatically sets the unit type (obtainable with CAknUnitEditor::Unit()) as EAknUnitEditorCustomUnit.

Parameters:
aUnitEditor  Pointer to the unit editor to modify

Definition at line 178 of file ueexform.cpp.

Referenced by ProcessCommandL().

00179     {
00180     TRAP_IGNORE( aUnitEditor->SetUnitL( KCustomUnit ) );    
00181     }

void CUEExForm::DoSetMaxFractionalDigits (  CAknUnitEditor *  aUnitEditor  )  [private]
 

Shows a query and sets the maximum fractional digits of the editor. The maximum number of fractional digits supported in the editor is 8. In debug builds, when CAknUnitEditor::SetMaxFractionalDigits() is called with a larger (or negative) value, the editor panics with AKNUNITEDIT 1.

Parameters:
aUnitEditor  Pointer to the unit editor to modify

Definition at line 187 of file ueexform.cpp.

Referenced by ProcessCommandL().

00188     {
00189     TInt number( 0 );
00190     CAknNumberQueryDialog* dlg = CAknNumberQueryDialog::NewL( number );
00191     dlg->PrepareLC( R_AVKON_DIALOG_QUERY_VALUE_NUMBER );
00192     dlg->SetMinimumAndMaximum( 0, KMaxFractionalDigits );
00193     if ( dlg->RunLD() )
00194         {
00195         aUnitEditor->SetMaxFractionalDigits( number );
00196         }
00197     }

void CUEExForm::DoGetValue (  CAknUnitEditor *  aUnitEditor  )  [private]
 

Shows a query with the current value of the editor. This uses how to get the value in the editor and how to format it to a string. To recreate the whole string the editor is displaying, use CAknUnitEditor::Value() and CAknUnitEditor::GetUnit().

Parameters:
aUnitEditor  Pointer to the unit editor to get the value from

Definition at line 203 of file ueexform.cpp.

Referenced by ProcessCommandL().

00204     {
00205     TReal realValue = aUnitEditor->Value();
00206     TBuf<32> buf;
00207     TRealFormat format( 10, aUnitEditor->MaxFractionalDigits() );
00208     buf.Num( realValue, format );
00209     CAknInformationNote* note = new ( ELeave ) CAknInformationNote;
00210     note->ExecuteLD( buf );    
00211     }


The documentation for this class was generated from the following files:

© Nokia 2009

Back to top