- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Attributes | Protected Attributes

# ObjectDescriptionModel< type > Class Template Reference

Search for all occurrences

## Detailed Description

### template<ObjectDescriptionType type>
class Phonon::ObjectDescriptionModel< type >

The ObjectDescriptionModel class provides a model from a list of ObjectDescription objects.

ObjectDescriptionModel is a readonly model that supplies a list using ObjectDescription::name() for the text and ObjectDescription::description() for the tooltip. If set the properties "icon" and "available" are used to set the decoration and disable the item (disabled only visually, you can still select and drag it).

It also provides the methods moveUp() and moveDown() to order the list. Additionally drag and drop is possible so that QAbstractItemView::InternalMove can be used. The resulting order of the ObjectDescription::index() values can then be retrieved using tupleIndexOrder().

An example use case would be to give the user a QComboBox to select the output device:

     QComboBox *cb = new QComboBox(parentWidget);
     ObjectDescriptionModel *model = new ObjectDescriptionModel(cb);
     model->setModelData(BackendCapabilities::availableAudioOutputDevices());
     cb->setModel(model);
     cb->setCurrentIndex(0); // select first entry

And to retrieve the selected AudioOutputDevice:

     int cbIndex = cb->currentIndex();
     AudioOutputDevice selectedDevice = model->modelData(cbIndex);

Author:
  Matthias Kretz <kretz@kde.org>

Definition at line 193 of file objectdescriptionmodel.h.

`#include <Phonon/ObjectDescriptionModel>`

Inheritance diagram for ObjectDescriptionModel< type >:
[legend]

List of all members.

## Public Member Functions
PHONON_TEMPLATE_CLASS_MEMBER_EXPORT const QMetaObject * | metaObject () const
PHONON_TEMPLATE_CLASS_MEMBER_EXPORT void * | qt_metacast (const char *_clname)
int | rowCount (const QModelIndex &parent=QModelIndex()) const
| Returns the number of rows in the model.
QVariant | data (const QModelIndex &index, int role=Qt::DisplayRole) const
| Returns data from the item with the given `index` for the specified `role`.
Qt::ItemFlags | flags (const QModelIndex &index) const
| Reimplemented to show unavailable devices as disabled (but still selectable).
QList< int > | tupleIndexOrder () const
| Returns a list of indexes in the same order as they are in the model.
int | tupleIndexAtPositionIndex (int positionIndex) const
| Returns the ObjectDescription::index for the tuple at the given position `positionIndex`.
QMimeData * | mimeData (const QModelIndexList &indexes) const
| Returns the MIME data that dropMimeData() can use to create new items.
void | moveUp (const QModelIndex &index)
| Moves the item at the given `index` up.
void | moveDown (const QModelIndex &index)
| Moves the item at the given `index` down.
| ObjectDescriptionModel (QObject *parent=0)
| Constructs a ObjectDescription model with the given `parent`.
| ObjectDescriptionModel (const QList< ObjectDescription< type > > &data, QObject *parent=0)
| Constructs a ObjectDescription model with the given `parent` and the given `data`.
void | setModelData (const QList< ObjectDescription< type > > &data)
| Sets the model data using the list provided by `data`.
QList< ObjectDescription< type > > | modelData () const
| Returns the model data.
ObjectDescription< type > | modelData (const QModelIndex &index) const
| Returns one ObjectDescription of the model data for the given `index`.
Qt::DropActions | supportedDropActions () const
| This model supports drag and drop to copy or move items.
bool | dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
| Accept drops from other models of the same ObjectDescriptionType.
bool | removeRows (int row, int count, const QModelIndex &parent=QModelIndex())
| Removes count rows starting with the given row.
QStringList | mimeTypes () const
| Returns a list of supported drag and drop MIME types.
## Static Public Attributes
static Q_OBJECT_CHECK PHONON_TEMPLATE_CLASS_MEMBER_EXPORT const QMetaObject | staticMetaObject
## Protected Attributes
ObjectDescriptionModelData *const | d

## Constructor & Destructor Documentation

ObjectDescriptionModel | ( | QObject * | parent = `0` | ) | `[inline, explicit]`

Constructs a ObjectDescription model with the given `parent`.

Definition at line 286 of file objectdescriptionmodel.h.

    : QAbstractListModel(parent), d(new ObjectDescriptionModelData(this)) {} //krazy:exclude=inline

ObjectDescriptionModel | ( | const QList< ObjectDescription< type > > & | data,
|  | QObject * | parent = `0`
| ) |  | `[inline, explicit]`

Constructs a ObjectDescription model with the given `parent` and the given `data`.

Definition at line 292 of file objectdescriptionmodel.h.

                    : QAbstractListModel(parent), d(new ObjectDescriptionModelData(this)) { setModelData(data); }

## Member Function Documentation

PHONON_TEMPLATE_CLASS_MEMBER_EXPORT const QMetaObject* metaObject | ( |  | ) | const

Search for all occurrences

PHONON_TEMPLATE_CLASS_MEMBER_EXPORT void* qt_metacast | ( | const char * | _clname | ) |

Search for all occurrences

int rowCount | ( | const QModelIndex & | parent = `QModelIndex()` | ) | const `[inline, virtual]`

Search for all occurrences

Returns the number of rows in the model.

This value corresponds to the size of the list passed through setModelData.

Parameters:

  parent | The optional `parent` argument is used in most models to specify the parent of the rows to be counted. Because this is a list if a valid parent is specified the result will always be 0.

Reimplemented from QAbstractItemModel.

See also:
  QAbstractItemModel::rowCount

Implements QAbstractItemModel.

Definition at line 218 of file objectdescriptionmodel.h.

    { return d->rowCount(parent); } //krazy:exclude=inline

QVariant data | ( | const QModelIndex & | index,
|  | int | role = `Qt::DisplayRole`
| ) |  | const `[inline, virtual]`

Search for all occurrences

Returns data from the item with the given `index` for the specified `role`.

If the view requests an invalid index, an invalid variant is returned.

Reimplemented from QAbstractItemModel.

See also:
  QAbstractItemModel::data
  Qt::ItemDataRole

Implements QAbstractItemModel.

Definition at line 231 of file objectdescriptionmodel.h.

    { return d->data(index, role); } //krazy:exclude=inline

Qt::ItemFlags flags | ( | const QModelIndex & | index | ) | const `[inline, virtual]`

Search for all occurrences

Reimplemented to show unavailable devices as disabled (but still selectable).

Reimplemented from QAbstractItemModel.

Definition at line 237 of file objectdescriptionmodel.h.

    { return d->flags(index); } //krazy:exclude=inline

QList<int> tupleIndexOrder | ( |  | ) | const `[inline]`

Search for all occurrences

Returns a list of indexes in the same order as they are in the model.

The indexes come from the ObjectDescription::index method.

This is useful to let the user define a list of preference.

Definition at line 246 of file objectdescriptionmodel.h.

    { return d->tupleIndexOrder(); } //krazy:exclude=inline

int tupleIndexAtPositionIndex | ( | int | positionIndex | ) | const `[inline]`

Search for all occurrences

Returns the ObjectDescription::index for the tuple at the given position `positionIndex`.

For example a QComboBox will give you the currentIndex as the position in the list. But to select the according AudioOutputDevice using AudioOutputDevice::fromIndex you can use this method.

Parameters:

  positionIndex | The position in the list.

Definition at line 258 of file objectdescriptionmodel.h.

    { return d->tupleIndexAtPositionIndex(positionIndex); } //krazy:exclude=inline

QMimeData* mimeData | ( | const QModelIndexList & | indexes | ) | const `[inline, virtual]`

Search for all occurrences

Returns the MIME data that dropMimeData() can use to create new items.

Reimplemented from QAbstractItemModel.

Definition at line 264 of file objectdescriptionmodel.h.

    { return d->mimeData(type, indexes); } //krazy:exclude=inline

void moveUp | ( | const QModelIndex & | index | ) | `[inline]`

Search for all occurrences

Moves the item at the given `index` up.

In the resulting list the items at index.row() and index.row() - 1 are swapped.

Connected views are updated automatically.

Definition at line 272 of file objectdescriptionmodel.h.

    { d->moveUp(index); } //krazy:exclude=inline

void moveDown | ( | const QModelIndex & | index | ) | `[inline]`

Search for all occurrences

Moves the item at the given `index` down.

In the resulting list the items at index.row() and index.row() + 1 are swapped.

Connected views are updated automatically.

Definition at line 280 of file objectdescriptionmodel.h.

    { d->moveDown(index); } //krazy:exclude=inline

void setModelData | ( | const QList< ObjectDescription< type > > & | data | ) | `[inline]`

Search for all occurrences

Sets the model data using the list provided by `data`.

All previous model data is cleared.

Definition at line 300 of file objectdescriptionmodel.h.

                                                                                      { //krazy:exclude=inline
                    QList<QExplicitlySharedDataPointer<ObjectDescriptionData> > list;
                    for (int i = 0; i < data.count(); ++i) {
                        list += data.at(i).d;
                    }
                    d->setModelData(list);
                }

QList<ObjectDescription<type> > modelData | ( |  | ) | const `[inline]`

Search for all occurrences

Returns the model data.

As the order of the list might have changed this can be different to what was set using setModelData().

Definition at line 314 of file objectdescriptionmodel.h.

                                                                         { //krazy:exclude=inline
                    QList<ObjectDescription<type> > ret;
                    QList<QExplicitlySharedDataPointer<ObjectDescriptionData> > list = d->modelData();
                    for (int i = 0; i < list.count(); ++i) {
                        ret << ObjectDescription<type>(list.at(i));
                    }
                    return ret;
                }

ObjectDescription<type> modelData | ( | const QModelIndex & | index | ) | const `[inline]`

Search for all occurrences

Returns one ObjectDescription of the model data for the given `index`.

Definition at line 326 of file objectdescriptionmodel.h.

    { return ObjectDescription<type>(d->modelData(index)); } //krazy:exclude=inline

Qt::DropActions supportedDropActions | ( |  | ) | const `[inline, virtual]`

Search for all occurrences

This model supports drag and drop to copy or move items.

Reimplemented from QAbstractItemModel.

Definition at line 332 of file objectdescriptionmodel.h.

    { return d->supportedDropActions(); } //krazy:exclude=inline

bool dropMimeData | ( | const QMimeData * | data,
|  | Qt::DropAction | action,
|  | int | row,
|  | int | column,
|  | const QModelIndex & | parent
| ) |  | `[inline, virtual]`

Search for all occurrences

Accept drops from other models of the same ObjectDescriptionType.

If a valid `parent` is given the dropped items will be inserted above that item.

Reimplemented from QAbstractListModel.

Definition at line 340 of file objectdescriptionmodel.h.

                                                                                                                                     { //krazy:exclude=inline
                    return d->dropMimeData(type, data, action, row, column, parent);
                }

bool removeRows | ( | int | row,
|  | int | count,
|  | const QModelIndex & | parent = `QModelIndex()`
| ) |  | `[inline, virtual]`

Search for all occurrences

Removes count rows starting with the given row.

If a valid `parent` is given no rows are removed since this is a list model.

Returns true if the rows were successfully removed; otherwise returns false.

Reimplemented from QAbstractItemModel.

Definition at line 352 of file objectdescriptionmodel.h.

                                                                                                      { //krazy:exclude=inline
                    return d->removeRows(row, count, parent);
                }

QStringList mimeTypes | ( |  | ) | const `[inline, virtual]`

Search for all occurrences

Returns a list of supported drag and drop MIME types.

Currently it only supports one type used internally.

Reimplemented from QAbstractItemModel.

Definition at line 360 of file objectdescriptionmodel.h.

    { return d->mimeTypes(type); } //krazy:exclude=inline

## Member Data Documentation

Q_OBJECT_CHECK PHONON_TEMPLATE_CLASS_MEMBER_EXPORT const QMetaObject staticMetaObject `[static]`

Search for all occurrences

Definition at line 199 of file objectdescriptionmodel.h.

ObjectDescriptionModelData* const d `[protected]`

Search for all occurrences

Definition at line 363 of file objectdescriptionmodel.h.

The documentation for this class was generated from the following file:

- phonon/objectdescriptionmodel.h