| Home · All Classes · Main Classes · Deprecated |
MList implements a list view. More...


MList implements a list view.
MList provides support for data that inherits QAbstractItemModel and can be set by setItemModel().
Unlike, Qt model/view widgets, MList only shows one "view" column. To show multiple model columns in a MList, you should create a custom widget in your MCellCreator::createCell() implementation and use your MCellCreator::updateCell() implementation to show the various items of data from each column in one widget.
See http://doc.trolltech.com/4.5/model-view-creating-models.html#a-read-only-example-model for how to build a custom item model that can be used with MList.
A very minimal basic item model example is shown below. The example model has 1 items and that item is MContentItem.
Important thing to remember is model defines protocol between model and list. Model defines the way data will be passed to MCellCreator which will create widgets.
Model will look like this:
class TestModel : public QAbstractListModel { Q_OBJECT public: TestModel(QObject *parent = 0) : QAbstractListModel(parent) {} int rowCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index, int role) const; }; int TestModel::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent); return 1; } QVariant TestModel::data(const QModelIndex &index, int role) const { if (role == Qt::DisplayRole) { QStringList rowData; rowData << "Angelina"; // first name rowData << "Joli"; // last name return QVariant(rowData); } return QVariant(); }
Model doesn't tell MList how to create actual widgets, we need MCellCreator for that. MAbstractCellCreator is the best candidate for simple case (keep in mind that you can change style of MContentItem only in it's constructor, so if other style is needed, MAbstractCellCreator will not work, MCellCreator should be used instead):
class MContentItemCreator : public MAbstractCellCreator<MContentItem> { public: void updateCell(const QModelIndex& index, MWidget * cell) const { MContentItem * contentItem = qobject_cast<MContentItem *>(cell); QVariant data = index.data(Qt::DisplayRole); QStringList rowData = data.value<QStringList>(); contentItem->setTitle(rowData[0]); contentItem->setSubtitle(rowData[1]); } };
And finally it can be combined in a list:
MList * list = new MList(panel); MContentItemCreator * cellCreator = new MContentItemCreator; list->setCellCreator(cellCreator); TestModel * model = new TestModel; list->setItemModel(model);
See also MListView, MWidgetFactory.
Definition at line 127 of file corelib/widgets/mlist.h.
| enum MList::DisplayMode |
Definition at line 188 of file corelib/widgets/mlist.h.
| DontCallCreateCellDuringUpdate |
MAbstractCellCreator::createCell() will be called only on new items. If items receives update only MAbstractCellCreate::updateCell() will be called. Enabled by default. |
Definition at line 209 of file corelib/widgets/mlist.h.
{
DontCallCreateCellDuringUpdate = 0x1
};
| enum MList::ScrollHint |
Definition at line 169 of file corelib/widgets/mlist.h.
{
EnsureVisibleHint,
PositionAtTopHint,
PositionAtBottomHint,
PositionAtCenterHint
};
| enum MList::SelectionMode |
This enumerated type is used by MList to indicate how it reacts to selection by the user.
Definition at line 154 of file corelib/widgets/mlist.h.
{
NoSelection,
SingleSelection,
MultiSelection
};
| MList::MList | ( | QGraphicsItem * | parent = 0 |
) |
Constructor for creating an empty object.
| parent | Parent object. |
Definition at line 74 of file mlist.cpp.
: MWidgetController(new MListPrivate, new MListModel, parent) { Q_D(MList); d->init(); }
| MList::~MList | ( | ) | [virtual] |
| MList::MList | ( | MListPrivate * | dd, | |
| MListModel * | model, | |||
| QGraphicsItem * | parent | |||
| ) | [protected] |
Definition at line 67 of file mlist.cpp.
: MWidgetController(dd, model, parent) { Q_D(MList); d->init(); }
| const MCellCreator * MList::cellCreator | ( | ) | const |
| int MList::columns | ( | ) | const |
| void MList::connectNotify | ( | const char * | signal | ) | [protected, virtual] |
Handler of notifications of new receivers connected to MList signals.
Definition at line 307 of file mlist.cpp.
{
Q_D(MList);
if (QLatin1String(signal) == SIGNAL(itemLongTapped(QModelIndex)) ||
QLatin1String(signal) == SIGNAL(itemLongTapped(QModelIndex,QPointF))) {
d->updateLongTapConnections();
}
}

| void MList::contextMenuEvent | ( | QGraphicsSceneContextMenuEvent * | event | ) | [protected, virtual] |
Notification of context menu event.
Reimplemented from MWidget.
Definition at line 98 of file mlist.cpp.
{
MWidgetController::contextMenuEvent(event);
}
| void MList::disconnectNotify | ( | const char * | signal | ) | [protected, virtual] |
Handler of notifications of receivers disconnecting from MList signals.
Definition at line 316 of file mlist.cpp.
{
Q_D(MList);
if (QLatin1String(signal) == SIGNAL(itemLongTapped(QModelIndex)) ||
QLatin1String(signal) == SIGNAL(itemLongTapped(QModelIndex,QPointF))) {
d->updateLongTapConnections();
}
}

| MListFilter * MList::filtering | ( | ) | const |
Definition at line 287 of file mlist.cpp.
{
MListPrivate* d = static_cast<MListPrivate*>(d_ptr);
if (d->listFilter == 0) {
// Postpone the creation of the list filter until it is requested
// to speedup the startup performance
d->listFilter = new MListFilter(const_cast<MList*>(this));
d->listFilter->setEnabled(false);
}
return d->listFilter;
}
| const QModelIndex MList::firstVisibleItem | ( | ) | const |
| const MCellCreator * MList::headerCreator | ( | ) | const |
| MList::DisplayMode MList::indexDisplayMode | ( | ) | const [slot] |
Returns visibility mode of list index.
Definition at line 250 of file mlist.cpp.
{
return static_cast<MList::DisplayMode>(model()->listIndexDisplayMode());
}

| bool MList::indexVisible | ( | ) |
Definition at line 255 of file mlist.cpp.
{
return model()->listIndexVisible();
}

| void MList::itemClicked | ( | const QModelIndex & | index | ) | [signal] |
Emitted when an item is clicked.
| void MList::itemLongTapped | ( | const QModelIndex & | index | ) | [signal] |
Emitted when an item is long tapped.
| void MList::itemLongTapped | ( | const QModelIndex & | index, | |
| const QPointF & | position | |||
| ) | [signal] |
Emitted when an item is long tapped. Also provides tap location.
| QAbstractItemModel * MList::itemModel | ( | ) | const |
| void MList::keyPressEvent | ( | QKeyEvent * | event | ) | [protected, virtual] |
| const QModelIndex MList::lastVisibleItem | ( | ) | const |
| void MList::longTapItem | ( | const QModelIndex & | index | ) | [slot] |
Convenience function - Emits a long tap event for an item.
Definition at line 179 of file mlist.cpp.
{
longTapItem(index, QPointF());
}
| void MList::longTapItem | ( | const QModelIndex & | index, | |
| const QPointF & | position | |||
| ) | [slot] |
Convenience function - Emits a long tap event for an item. Also provides tap location.
Definition at line 184 of file mlist.cpp.
{
emit itemLongTapped(index);
emit itemLongTapped(index, position);
}

| MList::ListOptimizationFlags MList::optimizationFlags | ( | ) | const |
| void MList::panningStarted | ( | ) | [signal] |
Emitted when list is moving, e.g. pannable by user.
| void MList::panningStopped | ( | ) | [signal] |
Emitted when list stopped moving.
| void MList::scrollTo | ( | const QModelIndex & | index | ) | [slot] |
Scrolls list to a specific index. Call to function will ensure that item with specified index becomes visible.
Definition at line 123 of file mlist.cpp.
{
scrollTo(index, MList::EnsureVisibleHint);
}
| void MList::scrollTo | ( | const QModelIndex & | index, | |
| ScrollHint | hint | |||
| ) | [slot] |
Scrolls list to a specific index with specified hint.
Definition at line 128 of file mlist.cpp.
{
emit scrollToIndex(index);
model()->beginTransaction();
model()->setScrollHint(hint);
model()->setScrollToIndex(index);
model()->commitTransaction();
}

| void MList::scrollToIndex | ( | const QModelIndex & | index | ) | [signal] |
Emitted when scrollTo(index) is called to tell the view to scroll to the given item index.
| MList::SelectionMode MList::selectionMode | ( | ) | const |
| QItemSelectionModel * MList::selectionModel | ( | ) | const |
| void MList::selectionModelChanged | ( | QItemSelectionModel * | selectionModel | ) | [signal] |
Emitted when the selection model has changed.
| void MList::selectItem | ( | const QModelIndex & | index | ) | [slot] |
Convenience function - Select the given item. If index is not valid, the current selection is not changed.
Definition at line 153 of file mlist.cpp.
{
QItemSelectionModel *sModel = selectionModel();
if (index.isValid() && sModel->model() != index.model()) {
qWarning("MList::selectItem() failed: "
"Trying to select an item that is for"
" a different model than the view ");
return;
}
if (sModel != NULL) {
if (selectionMode() == MList::MultiSelection) {
if (sModel->isSelected(index)) {
sModel->select(index, QItemSelectionModel::Deselect);
} else {
sModel->select(index, QItemSelectionModel::Select);
}
} else if (selectionMode() == MList::SingleSelection) {
sModel->select(index, QItemSelectionModel::ClearAndSelect);
}
}
emit itemClicked(index);
}

| void MList::setCellCreator | ( | MCellCreator * | cellCreator | ) |
Set's cell creator which will map data from model to widgets which will be displayed by MList. Ownership is transferred to MList.
Definition at line 190 of file mlist.cpp.

| void MList::setColumns | ( | int | columns | ) |
Sets the amount of columns to be used for presenting list items. Set to 1 by default.
When columns is > 1, the rows will be split vertically, making the cell widget narrower, with rows flowing from top-to-bottom into the next column. For instance, this could be used to create a "grid" list.
Definition at line 265 of file mlist.cpp.

| void MList::setHeaderCreator | ( | MCellCreator * | cellCreator | ) |
Set's header creator which will map data from model to widgets which will be displayed by MList in the header. Ownership is transferred to MList.
Definition at line 202 of file mlist.cpp.
{
model()->setHeaderCreator(headerCreator);
}

| void MList::setIndexDisplayMode | ( | MList::DisplayMode | displayMode | ) | [slot] |
Specifies fi the list index bar for a grouped model should be visible or not, or automatically to appear on list panning.
Definition at line 240 of file mlist.cpp.
{
model()->setListIndexDisplayMode(displayMode);
if(displayMode == MList::Hide)
model()->setListIndexVisible(false);
else
model()->setListIndexVisible(true);
}

| void MList::setIndexVisible | ( | bool | visible | ) | [slot] |
Specifies whether the list index for a grouped model should be visible or not.
Definition at line 232 of file mlist.cpp.
{
if (visible)
setIndexDisplayMode(MList::Show);
else
setIndexDisplayMode(MList::Hide);
}

| void MList::setItemModel | ( | QAbstractItemModel * | itemModel | ) |
Sets object to fetch displayed items from. Similar to 'setModel' method in QListView.
Sets the model for the view to present. This function will create and set a new selection model, replacing any model that was previously set with setSelectionModel(). However, the old selection model will not be deleted as it may be shared between several views. We recommend that you delete the old selection model if it is no longer required. This is done with the following code:
QItemSelectionModel *m = view->selectionModel(); view->setModel(new model); delete m;
If both the old model and the old selection model do not have parents, or if their parents are long-lived objects, it may be preferable to call their deleteLater() functions to explicitly delete them.
MList does not take ownership of the model unless it is the model's parent object because the view may be shared between many different MList(s).
Definition at line 103 of file mlist.cpp.
{
Q_D(MList);
if (d->listFilter && d->listFilter->enabled())
itemModel = d->listFilter->updateItemModel(itemModel);
setSelectionModel(NULL);
if (itemModel)
setSelectionModel(new QItemSelectionModel(itemModel));
model()->setItemModel(itemModel);
}

| void MList::setOptimizationFlag | ( | ListOptimizationFlag | optimizationFlag, | |
| bool | enabled = true | |||
| ) |
Sets one optimization flag to enabled if enabled is true, otherwise to disabled.
Definition at line 331 of file mlist.cpp.
{
Q_D(MList);
if (enabled)
setOptimizationFlags(ListOptimizationFlags(d->optimizationFlags) | optimizationFlag);
else
setOptimizationFlags(ListOptimizationFlags(d->optimizationFlags) & ~optimizationFlag);
}

| void MList::setOptimizationFlags | ( | ListOptimizationFlags | optimizationFlags | ) |
| void MList::setSelectionMode | ( | MList::SelectionMode | mode | ) |
Sets selection mode. By default NoSelection is set. Check SelectionMode enumeration for details.
Definition at line 270 of file mlist.cpp.
{
Q_D(MList);
d->selectionMode = mode;
QItemSelectionModel *sModel = selectionModel();
if (sModel)
sModel->clearSelection();
}

| void MList::setSelectionModel | ( | QItemSelectionModel * | selectionModel | ) |
Sets selection model.
Definition at line 143 of file mlist.cpp.
{
if (selectionModel == this->selectionModel()) {
return;
}
model()->setSelectionModel(selectionModel);
emit selectionModelChanged(selectionModel);
}

| void MList::setShowGroups | ( | bool | showGroups | ) |
Specifies whether list should show groups or not.
MList will handle item model as a 2 level tree. First level will be headers and second level items for that header.
Customization of the group header's appearance in the list is done through group-header-object-name. Group header is a label, so all styles of label applies to group header. Example: Application.css
MList#customList { group-header-object-name : "redLabelOnWhiteBackground"; } #redLabelOnWhiteBackground { color : #FF0000; background-color : #FFFFFF; }
Application.cpp
MList * list = ....; ... list->setObjectName("customList"); ...
Definition at line 227 of file mlist.cpp.
{
model()->setShowGroups(showGroups);
}

| bool MList::showGroups | ( | ) | const |
true if MList shows groups, otherwise false | void MList::updateData | ( | const QList< const char * > & | modifications | ) | [protected, virtual] |
Notification of model data modifications.
Reimplemented from MWidgetController.
Definition at line 87 of file mlist.cpp.
{
const char *member;
for (int i = 0; i < modifications.count(); i++) {
member = modifications[i];
if (member == MListModel::ListIsMoving) {
model()->listIsMoving() ? emit panningStarted() : emit panningStopped();
}
}
}

int MList::columns [read, write] |
Definition at line 140 of file corelib/widgets/mlist.h.
MList::SelectionMode MList::selectionMode [read, write] |
Definition at line 145 of file corelib/widgets/mlist.h.
bool MList::showGroups [read, write] |
Definition at line 135 of file corelib/widgets/mlist.h.
| Copyright © 2010 Nokia Corporation | Generated on Thu Nov 4 2010 18:14:25 (PDT) Doxygen 1.7.1 |
MeeGo Touch |