Home · All Classes · Main Classes · Deprecated |
MAbstractCellCreator is a helper class for implementing creators. More...
Inherits MCellCreator.
Public Member Functions | |
MAbstractCellCreator () | |
virtual | ~MAbstractCellCreator () |
virtual MWidget * | createCell (const QModelIndex &index, MWidgetRecycler &recycler) const |
virtual QSizeF | cellSize () const |
void | setCellViewType (const QString &viewType) |
void | setCellObjectName (const QString &objectName) |
MAbstractCellCreator is a helper class for implementing creators.
MAbstractCellCreator implements cellSize() function from MCellCreator interface by creating one instance of a widget and asking its preferred size. Also it automatically creates widgets of specified type specified by the template parameter. It asks recycler first and allocates memory only if there is no object in a recycler. With a template parameter you control which objects should be created, with setCellViewType(const QString&viewType) you may specify what view type should be assigned and with setObjectName(const QString& objectName) you may specify object name of constructed cell.
If you wish to intitialize the cell widget differntly, or if you wish to create different widget types for some rows, you should do so in an override of the createCell() function. You may call the base class's createCell() when you still want the default implementation for a particular row.
Only updateCell() function should be reimplemented to provide data to widget(cell).
Constructing a creator for MContentItem widget:
class MContentItemCreator : public MAbstractCellCreator<MContentItem> { public: MContentItemCreator() { // in css corresponding selector would be: // MContentItem[myCustomViewType]#myObjectName { .... setCellViewType("myCustomViewType"); setCellObjectName("myObjectName"); } void updateCell(const QModelIndex& index, MWidget * cell) const { // Casting to MContentItem is safe because createCell will create only MContentItem(s). MContentItem * contentItem = qobject_cast<MContentItem *>(cell); QVariant data = index.data(Qt::DisplayRole); // We are assuming here that model returns data in a QStringList: [<title>, <subtitle>, <pictureid>] QStringList rowData = data.value<QStringList>(); contentItem->setTitle(rowData[0]); if(rowData.count() > 1) contentItem->setSubtitle(rowData[1]); if(rowData.count() > 2){ // Pictures is a storage for pictures which we add as a thumbnails contentItem->setPixmap(Pictures::picture([rowData[2]); } } };
MAbstractCellCreator< T >::MAbstractCellCreator | ( | ) | [inline] |
virtual MAbstractCellCreator< T >::~MAbstractCellCreator | ( | ) | [inline, virtual] |
virtual QSizeF MAbstractCellCreator< T >::cellSize | ( | ) | const [inline, virtual] |
This function should return cell size. Minimum and maximum sizes of cell widget will be updated if returned size bigger then maximum size or smaller then minimum size. Only height will be taken into account, width of item will be calculate by MList.
Implements MCellCreator.
virtual MWidget* MAbstractCellCreator< T >::createCell | ( | const QModelIndex & | index, | |
MWidgetRecycler & | recycler | |||
) | const [inline, virtual] |
When MList needs a cell, it will call this function to get a pointer to a widget. MList keeps ownership of a pointer and will delete object when it's not needed. It's not required but highly recommended to use recycler. This function will be called very often during panning and to make panning smooth creator shouldn't allocate memory.
Function should return fully constructed and initialized object. All data has to be set.
index | is a model index of the row for which widget should be created | |
recycler | is a MWidgetRecycler which allows widget reusage. MList will put widgets to this recycler and its possible to get recycled widget from it | |
pointer | to fully created widget |
Implements MCellCreator.
void MAbstractCellCreator< T >::setCellObjectName | ( | const QString & | objectName | ) | [inline] |
void MAbstractCellCreator< T >::setCellViewType | ( | const QString & | viewType | ) | [inline] |
Copyright © 2010 Nokia Corporation | MeeGo Touch |