Home · All Classes · Main Classes · Deprecated |
MWidgetRecycler allows to reuse widgets when they are created and deleted frequently, for instance in MList. More...
Public Member Functions | |
MWidgetRecycler () | |
void | recycle (MWidget *widget) |
MWidget * | take (const QString &recycleId) |
void | setMaxItemsPerClass (int count) |
int | maxItemsPerClass () const |
virtual | ~MWidgetRecycler () |
Static Public Member Functions | |
static MWidgetRecycler * | instance () |
Static Public Attributes | |
static const char * | RecycledObjectIdentifier = "_q_RecycleIdentifier" |
MWidgetRecycler allows to reuse widgets when they are created and deleted frequently, for instance in MList.
When widgets in MList become invisible during panning, they are added to the recycler. New widgets that become visible are not constructed from scratch, instead the widgets that have been added to the recycler are reused.
MWidgetRecycler "replaces" new
and delete
keywords. E.g. when object needs to be delete it should be added to recycler:
.... // Checking if recycler has any objects with classname "MWidget". MWidget * newItem = qobject_cast<MWidget*>(recycler->take(MWidget::metaObject()->className())); if(newItem == NULL) { newItem = new MWidget; } .... recycler->recycle(someItem); // item is not needed anymore, saving for future use ...
To use non default identifier (or identifiers) for recycled widgets following syntax could be used:
.... // Checking if recycler has any objects with identifier "myItem" MWidget * newItem = qobject_cast<MWidget*>(recycler->take("myItem")); if(newItem == NULL) { newItem = new MWidget; newItem->setProperty(MWidgetRecycler::RecycledObjectIdentifier, "myItem"); } .... recycler->recycle(someItem); // item is not needed anymore, saving for future use ...
MWidgetRecycler will delete widgets if there is not enough space. To change maximum number of widgets in recycler check setMaxItemsPerClass(int).
MWidgetRecycler::MWidgetRecycler | ( | ) |
MWidgetRecycler constructor. To get system wide recycler please check instance(), however it's perfectly fine to create recycler for special cases.
MWidgetRecycler::~MWidgetRecycler | ( | ) | [virtual] |
Destructor.
MWidgetRecycler * MWidgetRecycler::instance | ( | ) | [static] |
Returns the unique instance of MWidgetRecycler.
int MWidgetRecycler::maxItemsPerClass | ( | ) | const |
Returns possible maximum amount of widgets in the recycler per class, e.g. each class has the same limit.
void MWidgetRecycler::recycle | ( | MWidget * | widget | ) |
Puts a new widget to the recycler.
If the widget recycler is full, widget will be deleted. Widget ownership is transferred to recycler but, due to performance reasons, the item parent is not effectively changed, so the application must ensure that the widget doesn't get deleted once put into the recycler (for example, resetting the item's parent if the parent is going to be deleted).
Recycler will check if widget has a property MWidgetRecycler::RecycledObjectIdentifier it will use it's value as a identifier, otherwise recycler will use class name.
void MWidgetRecycler::setMaxItemsPerClass | ( | int | count | ) |
Sets the maximum number of widgets the recycler holds at one time per class. Each class has the same limit.
Returns a widget from the recycler, if available.
Ownership of returned widget is transferred to the user. If the previous parent of the widget is not valid, the caller is responsible for setting a new appropriate parent to it.
Returns 0 if no widget of the specified class is available.
const char * MWidgetRecycler::RecycledObjectIdentifier = "_q_RecycleIdentifier" [static] |
Copyright © 2010 Nokia Corporation | MeeGo Touch |