|
|
|
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:
Derive a document class from
CQikDocument.
Create a constructor that takes the application object as an
argument. The application should be passed to the CQikDocument
constructor.
Implement CEikDocument::CreateAppUiL().
This function is called by the application architecture to handle editing the document. The function implementation must return an application UI object. Note that it is only necessary to first-phase construct the App UI; the second phase constructor is called automatically by the application architecture.
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;
}
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;
}