UIQ Technology
 Developer Library

UIQ 3 SDK

UIQ developer portal

FEEDBACK 

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



Location: MQikListBoxModel.h
Link against: qiklbx.lib

Class MQikListBoxModel

class MQikListBoxModel;

Description

Base class for listbox data model classes.

The inherited class is responsible for calling ReportModelEventL to notify the observer (i.e. CQikListBox when items are inserted, removed, swapped, updated, etc). There can only be at most one observer per model.

Make sure that you always report EQikListBoxModelBeginUpdate before any data is updated and EQikListBoxModelEndUpdate after the data has been updated. It is ok to make several updates in a row and then send the EQikListBoxModelEndUpdate message. If you don't have access to the inside of a model, one can always call ModelBeginUpdateLC() and ModelEndUpdateL() instead. It simply sends the message.

All MQikListBoxData that is returned from the model should be Open() before it is returned, and when the data is no longer used it needs to be Close() and then the pointer discarded. The data is reference counted. The model needs to keep all of its data objects opened since it has pointers to them. In case of a caching model, it needs to send a data updated message if it removes an item from the cache, so any item left in the listbox is set to dirty and requests fresh data if it is used again. Otherwise you will end up with one data object for the item (which you can not access) and another data object in your model.

Simple example use of the model (Remove etc are similar):

void CExample::PopulateListboxL()
    {
    MQikListBoxModel& model = iListBox->Model();
    model.ModelBeginUpdateLC();

    TRAPD(error, AddAllFooL(model));
    if(error == KErrNone)
        {
        // Tell the model we are done. Do not do anything not related to the
        // model between the Begin and End call, as the listbox is considered to be in a
        // volatile state between ModelBeginUpdateLC and the ModelEndUpdateL call.
        model.ModelEndUpdateL();
        }
    else
        {
        // We failed, need to do some form of cleaning / error handling.
        model.ModelEndUpdateL();
        model.RemoveAllDataL();
        }
    }

void CExample::AddAllFooL(MQikListBoxModel& aModel)
    {
    const TInt count = iExampleList.Count();
    for(TInt i=0; i<count; i++)
        {
        AddFooL(aModel, iExampleList[i]);
        }
    }

void CExample::AddFooL(MQikListBoxModel& aModel, const CYourSpecialData* aData)
    {
    // Get a new data item (Open() and owned by the model), it is Open() again
    // before returned, so your MQikListBoxData pointer is Open() and needs to
    // be Close(). Only Open() pointers should be operated upon. Discard after
    // Close().
    MQikListBoxData* data = aModel.NewDataL(MQikListBoxModel::EDataNormal);

    // Must make sure the data is closed if AddTextL leaves.
    CleanupClosePushL(*data);

    // Add some text to this data item.
    data->AddTextL(aData->YourText(), EYourSlot);
    data->AddTextL(aData->AnotherText(), EAnotherSlot);

    // We are done with the data, close it.
    CleanupStack::PopAndDestroy(data);
    }

Remember that RetrieveDataL does an Open() on the data before returning it, so one has to make a Close(). Also remember to push the data object on the stack properly with CleanupClosePushL and ending it with a CleanupStack::PopAndDestroy.

Remember to report EQikListBoxDataUpdated with the index of the updated data after you have updated an existing data item. This can also be done by calling DataUpdatedL, which simply sends the message.

Members

Defined in MQikListBoxModel:
Count(), DataUpdatedL(), EDataNormal, EDataSeparator, EDataUnselectable, FindMatchIndexL(), ItemIdIndex(), MQikListBoxModel(), MQikListBoxModelDataType, ModelBeginUpdateLC(), ModelEndUpdateL(), NewDataL(), NewDataL(), NewDataLC(), NewDataLC(), ReleaseModel(), RemoveAllDataL(), RemoveDataL(), ReportModelEventL(), RetrieveDataL(), SetModelObserver(), Sort()


Construction and destruction


MQikListBoxModel()

IMPORT_C MQikListBoxModel();

Description

Constructor to ensure that iModelObserver is NULL.

[Top]


Member functions


ReleaseModel()

virtual void ReleaseModel()=0;

Description

Called when the listbox does not need the model any longer. The listbox considers the model dead after this, and the model is responsible for cleaning itself up.


DataUpdatedL()

virtual IMPORT_C void DataUpdatedL(TInt aIndex);

Description

Call when you have updated the data of the model from outside a model.

Use ReportModelEventL when updating data from within a model.

Parameters

TInt aIndex

The index for which data has been altered.


ModelBeginUpdateLC()

virtual IMPORT_C void ModelBeginUpdateLC();

Description

Call before updating the model, for example inserting, removing, sorting, or updating data (<see-also>DataUpdated()</see-also>).

ModelBeginUpdateLC calls can not be nestled, each call must be ended with a call to ModelEndUpdateL . These calls must be balanced. A EQikListBoxPanicModelUpdatedNotCalledAfterChangingData panic typically indicates a second call to ModelBeginUpdateLC has been made when a ModelEndUpdateL call was expected.

Use ReportModelEventL when updating data from within a model.


ModelEndUpdateL()

virtual IMPORT_C void ModelEndUpdateL();

Description

Call after updating the model, for example inserting, removing, sorting, or updating data (<see-also>DataUpdated()</see-also>).

Use ReportModelEventL when updating data from within a model.


SetModelObserver()

IMPORT_C void SetModelObserver(MQikListBoxModelObserver *aObserver);

Description

Sets the model observer. This is exclusively used by CQikListBox .

Parameters

MQikListBoxModelObserver *aObserver

The model observer


Count()

virtual TInt Count() const=0;

Description

Returns the number of elements in the data model. It is recomended that the count is cached if getting the real data storage count is time consuming, since this method is frequently called from within CQikListBox .

Return value

TInt

The number of elements in the data model


NewDataL()

virtual MQikListBoxData *NewDataL(MQikListBoxModelDataType aDataType)=0;

Description

Creates a new data object.

OBS. The data returned is Open(). When done using the data you must call Close() and after that you can not continue to use that data object.

Parameters

MQikListBoxModelDataType aDataType

The type of data created, can't be changed later on.

Return value

MQikListBoxData *

An interface to the newly created data.


NewDataL()

virtual MQikListBoxData *NewDataL(MQikListBoxModelDataType aDataType, TInt aItemIndex)=0;

Description

Creates a new data object at an index.

OBS. The data returned is Open(). When done using the data you must call Close() and after that you can not continue to use that data object.

Parameters

MQikListBoxModelDataType aDataType

The type of data created, can't be changed later on.

TInt aItemIndex

The index to insert the newly created data.

Return value

MQikListBoxData *

An interface to the newly created data.


NewDataLC()

virtual MQikListBoxData *NewDataLC(MQikListBoxModelDataType aDataType)=0;

Description

Creates a new data object.

OBS. The data returned is Open() and put on the stack. When done using the data it must be Close() and it's done by calling CleanupStack::PopAndDestroy().

Parameters

MQikListBoxModelDataType aDataType

The type of data created, can't be changed later on.

Return value

MQikListBoxData *

An interface to the newly created data.


NewDataLC()

virtual MQikListBoxData *NewDataLC(MQikListBoxModelDataType aDataType, TInt aItemIndex)=0;

Description

Creates a new data object at an index.

OBS. The data returned is Open() and put on the stack. When done using the data it must be Close() and it's done by calling CleanupStack::PopAndDestroy().

Parameters

MQikListBoxModelDataType aDataType

The type of data created, can't be changed later on.

TInt aItemIndex

The index to insert the newly created data.

Return value

MQikListBoxData *

An interface to the newly created data.


RetrieveDataL()

virtual MQikListBoxData *RetrieveDataL(TInt aItemIndex)=0;

Description

Called when the listbox needs more data for the view. The model always owns the data, but can supply the data in two ways: 1) All data are instantiated by the model at construction time and occupies memoryspace. The returned data object is simply a pointer into that memory space. Small lists are most suited for this kind of data handling. Use MQikListBoxData::Open() on the data object before it is returned. 2) Only a small fraction of the data is kept in memory at the same time (i.e. using a cache) and new data needs to be loaded/constructed and old data deleted. It is the responsibility of the model to keep track of the data items and make sure they are cleared from the cache when neccesary. To see if an object is currently in use outside the model, use the reference counting functionality of the MQikListBoxData class. Use MQikListBoxData::Open() on the data object before it is returned and use MQikListBoxData::ReferenceCount() on the data objects in the cache to see if they can be removed.

Parameters

TInt aItemIndex

The item index

Return value

MQikListBoxData *

A data object


RemoveDataL()

virtual void RemoveDataL(TInt aItemIndex)=0;

Description

Removes an item from the model and deletes the item data. The model is responsible for notifying the observer about items that are being removed. The base class implementation is empty and needs to be overridden by a subclass if support for data removal is wanted.

Parameters

TInt aItemIndex

Index of the item to remove.


RemoveAllDataL()

virtual void RemoveAllDataL()=0;

Description

Removes all items from the model and deletes the item's data. The model is responsible for notifying the observer about items that are being removed.

The remove all call needs to report a EQikListBoxModelBeginUpdate, a EQikListBoxAllDataRemoved, and a EQikListBoxModelEndUpdate event.


Sort()

virtual void Sort(TLinearOrder< MQikListBoxData > aOrder)=0;

Description

Sorts the items in the model. The model is responsible for notifying the observer about items that are being swapped.

Parameters

TLinearOrder< MQikListBoxData > aOrder

A package encapsulating the function which determines the order of two MQikListBoxData objects


FindMatchIndexL()

virtual TInt FindMatchIndexL(const TDesC &aMatchBuffer, TInt aStartIndex, TInt aIncrementalMatchSlot) const=0;

Description

Called by listbox view when incremental matching is enabled and needs to match a string in the list. The base class implementation is empty and needs to be overridden by a subclass if support for incremental matching is wanted.

The function shall start searching for a match starting on, and including, aStartIndex (i.e. if aStartIndex itself matches then aStartIndex should be returned). The routine shall search from aStartIndex to the end of the list, then wrap to search from the very first item down to aStartIndex.

Parameters

const TDesC &aMatchBuffer

Buffer with text that should be matched

TInt aStartIndex

The index (inclusive) to start searching a match from. May be out of model count bounds.

TInt aIncrementalMatchSlot

The slot to use when matching

Return value

TInt

The index of the next match or KErrNotFound if no new match was found


ItemIdIndex()

virtual TInt ItemIdIndex(TInt aItemId) const=0;

Description

Returns the index of the data with a certain item id.

Parameters

TInt aItemId

The item id to get the index from.

Return value

TInt

The index of the item, or KErrNotFound if not found.


ReportModelEventL()

protected: IMPORT_C void ReportModelEventL(MQikListBoxModelObserver::TModelEvent aEvent, TInt aItemIndex, TInt aItemSecond);

Description

Method for reporting model events to the observer.

Parameters

MQikListBoxModelObserver::TModelEvent aEvent

The event.

TInt aItemIndex

The index of the affected item.

TInt aItemSecond

See also:

[Top]


Member enumerations


Enum MQikListBoxModelDataType

MQikListBoxModelDataType

Description

Used to give the item representing a data object certain characteristics.

EDataNormal

Normal data to be shown.

EDataSeparator

The data represents a separator, unselectable and unhighlightable. A separator can have a text line added to it, such a text line should be added to slot MQikListBoxData::EDefaultSlot .

EDataUnselectable

The resulting item will be unselectable, i.e in a multiple select enabled List Box this item´s checkbox will be dimmed and cannot be checked by pen tap or by issuing any mark-related commands.

Terms and conditions of use of the material