UIQ Technology
Symbian OS Library

UIQ 3.1 SDK        UIQ developer portal

[Index] [Spacer] [Previous] [Next]



How to create the document class

The document class represents the data model for the application. Minimally the purpose of the document class is to create an application UI object to handle editing the document. Additionally, the document class handles storing and restoring of the application's data.

To create a minimal document class:

The definition and implementation of a minimal document class is given below.

class CExampleDocument : public CQikDocument
    {
public:
    // Constructor.
    CExampleDocument(CEikApplication& aApp);
private: // From CEikDocument.
    CEikAppUi* CreateAppUiL();
    };

// 1. Document constructor.
CExampleDocument::CExampleDocument(CEikApplication& aApp)
        : CQikDocument(aApp)
    {
    }

// 2. Create App UI.
CEikAppUi* CExampleDocument::CreateAppUiL()
    {
    return new (ELeave) CExampleAppUi;
    }


Creating the model

The model is owned by the document; when the document is constructed it must also create the model. This requires two-phase construction which is implemented in the document's NewL(). NewL() creates the document from the application class.

A model class, or usually a set of related classes, encapsulates the purely algorithmic behavior of the application. It presents a well defined API to other parts of an application. See Application Models.

Define and implement NewL as follows:

static CExampleDocument* NewL(CEikApplication& aApp);

CExampleDocument* CExampleDocument::NewL(CEikApplication& aApp)
    {
    CExampleDocument* self=new (ELeave) CExampleDocument(aApp);
    CleanupStack::PushL(self);
    self->ConstructL();
    self->ResetModelL();
    CleanupStack::Pop(self);
    return self;
    }

void CExampleDocument::ConstructL()
    {
    iModel = new (ELeave) CBigDot;
    }