Phonon  4.7.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Pages
Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
Phonon::ObjectDescriptionModel< T > Class Template Reference

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

#include <Phonon/ObjectDescriptionModel>

Inheritance diagram for Phonon::ObjectDescriptionModel< T >:

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
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
 
Qt::ItemFlags flags (const QModelIndex &index) const
 
QList< int > tupleIndexOrder () const
 
int tupleIndexAtPositionIndex (int positionIndex) const
 
QMimeData * mimeData (const QModelIndexList &indexes) const
 
void moveUp (const QModelIndex &index)
 
void moveDown (const QModelIndex &index)
 
 ObjectDescriptionModel (QObject *parent=0)
 
 ObjectDescriptionModel (const QList< ObjectDescription< type > > &data, QObject *parent=0)
 
void setModelData (const QList< ObjectDescription< type > > &data)
 
QList< ObjectDescription< type > > modelData () const
 
ObjectDescription< type > modelData (const QModelIndex &index) const
 
Qt::DropActions supportedDropActions () const
 
bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
 
bool removeRows (int row, int count, const QModelIndex &parent=QModelIndex())
 
QStringList mimeTypes () const
 
template<>
const QMetaObject staticMetaObject
 
template<>
const QMetaObject staticMetaObject
 
template<>
const QMetaObject staticMetaObject
 
template<>
const QMetaObject staticMetaObject
 
template<>
const QMetaObject staticMetaObject
 
template<>
const QMetaObject staticMetaObject
 

Static Public Attributes

static Q_OBJECT_CHECK
PHONON_TEMPLATE_CLASS_MEMBER_EXPORT
const QMetaObject 
staticMetaObject
 

Protected Attributes

ObjectDescriptionModelData *const d
 

Detailed Description

template<ObjectDescriptionType T>
class Phonon::ObjectDescriptionModel< T >

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);
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.nosp@m.@kde.nosp@m..org

Constructor & Destructor Documentation

template<ObjectDescriptionType T>
Phonon::ObjectDescriptionModel< T >::ObjectDescriptionModel ( QObject *  parent = 0)
inlineexplicit

Constructs a ObjectDescription model with the given parent.

template<ObjectDescriptionType T>
Phonon::ObjectDescriptionModel< T >::ObjectDescriptionModel ( const QList< ObjectDescription< type > > &  data,
QObject *  parent = 0 
)
inlineexplicit

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

Member Function Documentation

template<ObjectDescriptionType T>
QVariant Phonon::ObjectDescriptionModel< T >::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
inline

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
template<ObjectDescriptionType T>
bool Phonon::ObjectDescriptionModel< T >::dropMimeData ( const QMimeData *  data,
Qt::DropAction  action,
int  row,
int  column,
const QModelIndex &  parent 
)
inline

Accept drops from other models of the same ObjectDescriptionType.

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

template<ObjectDescriptionType T>
Qt::ItemFlags Phonon::ObjectDescriptionModel< T >::flags ( const QModelIndex &  index) const
inline

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

template<ObjectDescriptionType T>
QMimeData* Phonon::ObjectDescriptionModel< T >::mimeData ( const QModelIndexList &  indexes) const
inline

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

template<ObjectDescriptionType T>
QStringList Phonon::ObjectDescriptionModel< T >::mimeTypes ( ) const
inline

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

template<ObjectDescriptionType T>
QList<ObjectDescription<type> > Phonon::ObjectDescriptionModel< T >::modelData ( ) const
inline

Returns the model data.

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

template<ObjectDescriptionType T>
ObjectDescription<type> Phonon::ObjectDescriptionModel< T >::modelData ( const QModelIndex &  index) const
inline

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

template<ObjectDescriptionType T>
void Phonon::ObjectDescriptionModel< T >::moveDown ( const QModelIndex &  index)
inline

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.

template<ObjectDescriptionType T>
void Phonon::ObjectDescriptionModel< T >::moveUp ( const QModelIndex &  index)
inline

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.

template<ObjectDescriptionType T>
bool Phonon::ObjectDescriptionModel< T >::removeRows ( int  row,
int  count,
const QModelIndex &  parent = QModelIndex() 
)
inline

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.

template<ObjectDescriptionType T>
int Phonon::ObjectDescriptionModel< T >::rowCount ( const QModelIndex &  parent = QModelIndex()) const
inline

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

Parameters
parentThe 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
template<ObjectDescriptionType T>
void Phonon::ObjectDescriptionModel< T >::setModelData ( const QList< ObjectDescription< type > > &  data)
inline

Sets the model data using the list provided by data.

All previous model data is cleared.

template<ObjectDescriptionType T>
Qt::DropActions Phonon::ObjectDescriptionModel< T >::supportedDropActions ( ) const
inline

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

template<ObjectDescriptionType T>
int Phonon::ObjectDescriptionModel< T >::tupleIndexAtPositionIndex ( int  positionIndex) const
inline

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
positionIndexThe position in the list.
template<ObjectDescriptionType T>
QList<int> Phonon::ObjectDescriptionModel< T >::tupleIndexOrder ( ) const
inline

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.


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