|  | Home · All Classes · Main Classes · Grouped Classes · Modules · Functions |

# ObjectDescriptionModel Class Reference
(Phonon::ObjectDescriptionModel)
[Phonon module]

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

Inherits QAbstractListModel.

This class was introduced in Qt 4.4.

- List of all members, including inherited members

### Public Functions

- ObjectDescriptionModel ( QObject * parent = 0 )
- ObjectDescriptionModel ( const QList<ObjectDescription<type> > & data, QObject * parent = 0 )
- virtual QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const
- virtual bool dropMimeData ( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent )
- virtual const QMetaObject * metaObject () const
- virtual QStringList mimeTypes () const
- QList<ObjectDescription<type> > modelData () const
- ObjectDescription<type> modelData ( const QModelIndex & index ) const
- void moveDown ( const QModelIndex & index )
- void moveUp ( const QModelIndex & index )
- void * qt_metacast ( const char * _clname )
- virtual bool removeRows ( int row, int count, const QModelIndex & parent = QModelIndex() )
- virtual int rowCount ( const QModelIndex & parent = QModelIndex() ) const
- void setModelData ( const QList<ObjectDescription<type> > & data )
- virtual Qt::DropActions supportedDropActions () const
- int tupleIndexAtPositionIndex ( int positionIndex ) const
- QList<int> tupleIndexOrder () const

- 1 public function inherited from QAbstractListModel
- 34 public functions inherited from QAbstractItemModel
- 29 public functions inherited from QObject

### Additional Inherited Members

- 1 property inherited from QObject
- 2 public slots inherited from QAbstractItemModel
- 1 public slot inherited from QObject
- 14 signals inherited from QAbstractItemModel
- 1 signal inherited from QObject
- 5 static public members inherited from QObject
- 14 protected functions inherited from QAbstractItemModel
- 7 protected functions inherited from QObject

## Detailed Description

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

ObjectDescriptionModel is a read only 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>

## Member Function Documentation

### ObjectDescriptionModel::ObjectDescriptionModel ( QObject * parent = 0 )

Constructs a ObjectDescription model with the given parent.

### ObjectDescriptionModel::ObjectDescriptionModel ( const QList<ObjectDescription<type> > & data, QObject * parent = 0 )

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

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

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.

Reimplemented from QAbstractItemModel.

See also QAbstractItemModel::data() and Qt::ItemDataRole.

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

Accept drops from other models of the same ObjectDescriptionType.

The data is dropped at the given row and column; you also receive the parent model index.

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

Reimplemented from QAbstractItemModel.

### const QMetaObject * ObjectDescriptionModel::metaObject () const `[virtual]`

### QStringList ObjectDescriptionModel::mimeTypes () const `[virtual]`

Returns a list of supported drag and drop MIME types. Currently it only supports one type used internally.

Reimplemented from QAbstractItemModel.

### QList<ObjectDescription<type> > ObjectDescriptionModel::modelData () const

Returns the model data.

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

See also setModelData().

### ObjectDescription<type> ObjectDescriptionModel::modelData ( const QModelIndex & index ) const

This is an overloaded member function, provided for convenience.

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

### void ObjectDescriptionModel::moveDown ( const QModelIndex & index )

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.

### void ObjectDescriptionModel::moveUp ( const QModelIndex & index )

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.

### void * ObjectDescriptionModel::qt_metacast ( const char * _clname )

### bool ObjectDescriptionModel::removeRows ( int row, int count, const QModelIndex & parent = QModelIndex() ) `[virtual]`

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.

### int ObjectDescriptionModel::rowCount ( const QModelIndex & parent = QModelIndex() ) const `[virtual]`

Returns the number of rows in the model. This value corresponds to the size of the list passed through setModelData.

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.

Reimplemented from QAbstractItemModel.

See also QAbstractItemModel::rowCount().

### void ObjectDescriptionModel::setModelData ( const QList<ObjectDescription<type> > & data )

Sets the model data using the list provided by data.

All previous model data is cleared.

See also modelData().

### Qt::DropActions ObjectDescriptionModel::supportedDropActions () const `[virtual]`

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

Reimplemented from QAbstractItemModel.

### int ObjectDescriptionModel::tupleIndexAtPositionIndex ( int positionIndex ) const

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.

positionIndex The position in the list.

### QList<int> ObjectDescriptionModel::tupleIndexOrder () const

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.