Home · All Classes · Main Classes · Deprecated
Public Member Functions | Static Public Member Functions | Static Public Attributes

MWidgetRecycler Class Reference

MWidgetRecycler allows to reuse widgets when they are created and deleted frequently, for instance in MList. More...

List of all members.

Public Member Functions

 MWidgetRecycler ()
void recycle (MWidget *widget)
MWidgettake (const QString &recycleId)
void setMaxItemsPerClass (int count)
int maxItemsPerClass () const
virtual ~MWidgetRecycler ()

Static Public Member Functions

static MWidgetRecyclerinstance ()

Static Public Attributes

static const char * RecycledObjectIdentifier = "_q_RecycleIdentifier"

Detailed Description

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).


Constructor & Destructor Documentation

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.


Member Function Documentation

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.

Widget ownership is transferred to recycler. If the widget recycler is full, widget will 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.

MWidget * MWidgetRecycler::take ( const QString recycleId  ) 

Returns a widget from the recycler, if available.

Ownership of returned widget is transferred to the user. Returns 0 if no widget of the specified class is available.

See also:
recycle(MWidget *)

Member Data Documentation

const char * MWidgetRecycler::RecycledObjectIdentifier = "_q_RecycleIdentifier" [static]

Copyright © 2010 Nokia Corporation
MeeGo Touch