ObjectDescriptionModel< type > Class Template Reference

ObjectDescriptionModel< type > Class Template Reference

#include <Phonon/ObjectDescriptionModel>

Class 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);
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

Definition at line 166 of file objectdescription.h.

+ Inheritance diagram for ObjectDescriptionModel< type >:

Public Member Functions

PHONON_TEMPLATE_CLASS_MEMBER_EXPORT const QMetaObjectmetaObject () const
 
PHONON_TEMPLATE_CLASS_MEMBER_EXPORT voidqt_metacast (const char *_clname)
 
int rowCount (const QModelIndex &parent=QModelIndex()) const
 Returns the number of rows in the model. More...
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
 Returns data from the item with the given index for the specified role. More...
 
Qt::ItemFlags flags (const QModelIndex &index) const
 Reimplemented to show unavailable devices as disabled (but still selectable). More...
 
QList< inttupleIndexOrder () const
 Returns a list of indexes in the same order as they are in the model. More...
 
int tupleIndexAtPositionIndex (int positionIndex) const
 Returns the ObjectDescription::index for the tuple at the given position positionIndex. More...
 
QMimeDatamimeData (const QModelIndexList &indexes) const
 Returns the MIME data that dropMimeData() can use to create new items. More...
 
void moveUp (const QModelIndex &index)
 Moves the item at the given index up. More...
 
void moveDown (const QModelIndex &index)
 Moves the item at the given index down. More...
 
 ObjectDescriptionModel (QObject *parent=0)
 Constructs a ObjectDescription model with the given parent. More...
 
 ObjectDescriptionModel (const QList< ObjectDescription< type > > &data, QObject *parent=0)
 Constructs a ObjectDescription model with the given parent and the given data. More...
 
void setModelData (const QList< ObjectDescription< type > > &data)
 Sets the model data using the list provided by data. More...
 
QList< ObjectDescription< type > > modelData () const
 Returns the model data. More...
 
ObjectDescription< typemodelData (const QModelIndex &index) const
 Returns one ObjectDescription of the model data for the given index. More...
 
Qt::DropActions supportedDropActions () const
 This model supports drag and drop to copy or move items. More...
 
bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
 Accept drops from other models of the same ObjectDescriptionType. More...
 
bool removeRows (int row, int count, const QModelIndex &parent=QModelIndex())
 Removes count rows starting with the given row. More...
 
QStringList mimeTypes () const
 Returns a list of supported drag and drop MIME types. More...
 
- Public Member Functions inherited from QAbstractListModel
 QAbstractListModel (QObject *parent=0)
 
 ~QAbstractListModel ()
 
QModelIndex index (int row, int column=0, const QModelIndex &parent=QModelIndex()) const
 
bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
 
- Public Member Functions inherited from QAbstractItemModel
 QAbstractItemModel (QObject *parent=0)
 
virtual ~QAbstractItemModel ()
 
bool hasIndex (int row, int column, const QModelIndex &parent=QModelIndex()) const
 
QModelIndex sibling (int row, int column, const QModelIndex &idx) const
 
virtual bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
 
virtual QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
 
virtual bool setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole)
 
virtual QMap< int, QVariantitemData (const QModelIndex &index) const
 
virtual bool setItemData (const QModelIndex &index, const QMap< int, QVariant > &roles)
 
Qt::DropActions supportedDragActions () const
 
void setSupportedDragActions (Qt::DropActions)
 
virtual bool insertRows (int row, int count, const QModelIndex &parent=QModelIndex())
 
virtual bool insertColumns (int column, int count, const QModelIndex &parent=QModelIndex())
 
virtual bool removeColumns (int column, int count, const QModelIndex &parent=QModelIndex())
 
bool insertRow (int row, const QModelIndex &parent=QModelIndex())
 
bool insertColumn (int column, const QModelIndex &parent=QModelIndex())
 
bool removeRow (int row, const QModelIndex &parent=QModelIndex())
 
bool removeColumn (int column, const QModelIndex &parent=QModelIndex())
 
virtual void fetchMore (const QModelIndex &parent)
 
virtual bool canFetchMore (const QModelIndex &parent) const
 
virtual void sort (int column, Qt::SortOrder order=Qt::AscendingOrder)
 
virtual QModelIndex buddy (const QModelIndex &index) const
 
virtual QModelIndexList match (const QModelIndex &start, int role, const QVariant &value, int hits=1, Qt::MatchFlags flags=Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const
 
virtual QSize span (const QModelIndex &index) const
 
const QHash< int, QByteArray > & roleNames () const
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=0)
 
virtual ~QObject ()
 
virtual bool event (QEvent *)
 
virtual bool eventFilter (QObject *, QEvent *)
 
QString objectName () const
 
void setObjectName (const QString &name)
 
bool isWidgetType () const
 
bool signalsBlocked () const
 
bool blockSignals (bool b)
 
QThreadthread () const
 
void moveToThread (QThread *thread)
 
int startTimer (int interval)
 
void killTimer (int id)
 
template<typename T >
findChild (const QString &aName=QString()) const
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
const QObjectListchildren () const
 
void setParent (QObject *)
 
void installEventFilter (QObject *)
 
void removeEventFilter (QObject *)
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectTree ()
 
void dumpObjectInfo ()
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const
 
QList< QByteArraydynamicPropertyNames () const
 
void setUserData (uint id, QObjectUserData *data)
 
QObjectUserDatauserData (uint id) const
 
QObjectparent () const
 
bool inherits (const char *classname) const
 

Static Public Attributes

static Q_OBJECT_CHECK PHONON_TEMPLATE_CLASS_MEMBER_EXPORT const QMetaObject staticMetaObject
 

Protected Attributes

ObjectDescriptionModelData *const d
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 

Additional Inherited Members

- Public Slots inherited from QAbstractItemModel
virtual bool submit ()
 
virtual void revert ()
 
- Public Slots inherited from QObject
void deleteLater ()
 
- Signals inherited from QAbstractItemModel
void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight)
 
void headerDataChanged (Qt::Orientation orientation, int first, int last)
 
void layoutChanged ()
 
void layoutAboutToBeChanged ()
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 
- Static Public Member Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
- Protected Slots inherited from QAbstractItemModel
void resetInternalData ()
 
- Protected Member Functions inherited from QAbstractListModel
 QAbstractListModel (QAbstractItemModelPrivate &dd, QObject *parent)
 
- Protected Member Functions inherited from QAbstractItemModel
 QAbstractItemModel (QAbstractItemModelPrivate &dd, QObject *parent=0)
 
QModelIndex createIndex (int row, int column, void *data=0) const
 
QModelIndex createIndex (int row, int column, int id) const
 
QModelIndex createIndex (int row, int column, quint32 id) const
 
void encodeData (const QModelIndexList &indexes, QDataStream &stream) const
 
bool decodeData (int row, int column, const QModelIndex &parent, QDataStream &stream)
 
void beginInsertRows (const QModelIndex &parent, int first, int last)
 
void endInsertRows ()
 
void beginRemoveRows (const QModelIndex &parent, int first, int last)
 
void endRemoveRows ()
 
bool beginMoveRows (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationRow)
 
void endMoveRows ()
 
void beginInsertColumns (const QModelIndex &parent, int first, int last)
 
void endInsertColumns ()
 
void beginRemoveColumns (const QModelIndex &parent, int first, int last)
 
void endRemoveColumns ()
 
bool beginMoveColumns (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationColumn)
 
void endMoveColumns ()
 
void reset ()
 
void beginResetModel ()
 
void endResetModel ()
 
void changePersistentIndex (const QModelIndex &from, const QModelIndex &to)
 
void changePersistentIndexList (const QModelIndexList &from, const QModelIndexList &to)
 
QModelIndexList persistentIndexList () const
 
void setRoleNames (const QHash< int, QByteArray > &roleNames)
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 
virtual void timerEvent (QTimerEvent *)
 
virtual void childEvent (QChildEvent *)
 
virtual void customEvent (QEvent *)
 
virtual void connectNotify (const char *signal)
 
virtual void disconnectNotify (const char *signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
- Static Protected Attributes inherited from QObject
static const QMetaObject staticQtMetaObject
 
- Properties inherited from QObject
QString objectName
 

Constructor & Destructor Documentation

ObjectDescriptionModel ( QObject parent = 0)
inlineexplicit

Constructs a ObjectDescription model with the given parent.

Definition at line 287 of file objectdescriptionmodel.h.

287 : QAbstractListModel(parent), d(new ObjectDescriptionModelData(this)) {} //krazy:exclude=inline
QAbstractListModel(QObject *parent=0)
ObjectDescriptionModelData *const d
ObjectDescriptionModel ( const QList< ObjectDescription< type > > &  data,
QObject parent = 0 
)
inlineexplicit

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

Definition at line 293 of file objectdescriptionmodel.h.

294  : QAbstractListModel(parent), d(new ObjectDescriptionModelData(this)) { setModelData(data); }
void setModelData(const QList< ObjectDescription< type > > &data)
Sets the model data using the list provided by data.
QAbstractListModel(QObject *parent=0)
ObjectDescriptionModelData *const d

Member Function Documentation

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
inlinevirtual

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

Implements QAbstractItemModel.

Definition at line 219 of file objectdescriptionmodel.h.

219 { return d->rowCount(parent); } //krazy:exclude=inline
int rowCount(const QModelIndex &parent=QModelIndex()) const
Returns the number of rows in the model.
ObjectDescriptionModelData *const d
QVariant data ( const QModelIndex index,
int  role = Qt::DisplayRole 
) const
inlinevirtual

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 232 of file objectdescriptionmodel.h.

232 { return d->data(index, role); } //krazy:exclude=inline
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Returns data from the item with the given index for the specified role.
ObjectDescriptionModelData *const d
Qt::ItemFlags flags ( const QModelIndex index) const
inlinevirtual

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

Reimplemented from QAbstractItemModel.

Definition at line 238 of file objectdescriptionmodel.h.

238 { return d->flags(index); } //krazy:exclude=inline
Qt::ItemFlags flags(const QModelIndex &index) const
Reimplemented to show unavailable devices as disabled (but still selectable).
ObjectDescriptionModelData *const d
QList<int> 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.

Definition at line 247 of file objectdescriptionmodel.h.

247 { return d->tupleIndexOrder(); } //krazy:exclude=inline
QList< int > tupleIndexOrder() const
Returns a list of indexes in the same order as they are in the model.
ObjectDescriptionModelData *const d
int 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.

Definition at line 259 of file objectdescriptionmodel.h.

259 { return d->tupleIndexAtPositionIndex(positionIndex); } //krazy:exclude=inline
int tupleIndexAtPositionIndex(int positionIndex) const
Returns the ObjectDescription::index for the tuple at the given position positionIndex.
ObjectDescriptionModelData *const d
QMimeData* mimeData ( const QModelIndexList indexes) const
inlinevirtual

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

Reimplemented from QAbstractItemModel.

Definition at line 265 of file objectdescriptionmodel.h.

265 { return d->mimeData(type, indexes); } //krazy:exclude=inline
GLuint GLuint GLsizei GLenum type
Definition: GLee.h:872
QMimeData * mimeData(ObjectDescriptionType type, const QModelIndexList &indexes) const
Returns the MIME data that dropMimeData() can use to create new items.
ObjectDescriptionModelData *const d
void 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.

Definition at line 273 of file objectdescriptionmodel.h.

273 { d->moveUp(index); } //krazy:exclude=inline
void moveUp(const QModelIndex &index)
Moves the item at the given index up.
ObjectDescriptionModelData *const d
void 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.

Definition at line 281 of file objectdescriptionmodel.h.

281 { d->moveDown(index); } //krazy:exclude=inline
void moveDown(const QModelIndex &index)
Moves the item at the given index down.
ObjectDescriptionModelData *const d
void setModelData ( const QList< ObjectDescription< type > > &  data)
inline

Sets the model data using the list provided by data.

All previous model data is cleared.

Definition at line 301 of file objectdescriptionmodel.h.

301  { //krazy:exclude=inline
303  for (int i = 0; i < data.count(); ++i) {
304  list += data.at(i).d;
305  }
306  d->setModelData(list);
307  }
const T & at(int i) const
Definition: qlist.h:468
int count(const T &t) const
Definition: qlist.h:891
void setModelData(const QList< QExplicitlySharedDataPointer< ObjectDescriptionData > > &data)
ObjectDescriptionModelData *const d
QList<ObjectDescription<type> > 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().

Definition at line 315 of file objectdescriptionmodel.h.

315  { //krazy:exclude=inline
318  for (int i = 0; i < list.count(); ++i) {
319  ret << ObjectDescription<type>(list.at(i));
320  }
321  return ret;
322  }
const T & at(int i) const
Definition: qlist.h:468
QList< QExplicitlySharedDataPointer< ObjectDescriptionData > > modelData() const
int count(const T &t) const
Definition: qlist.h:891
ObjectDescriptionModelData *const d
ObjectDescription<type> modelData ( const QModelIndex index) const
inline

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

Definition at line 327 of file objectdescriptionmodel.h.

327 { return ObjectDescription<type>(d->modelData(index)); } //krazy:exclude=inline
QList< QExplicitlySharedDataPointer< ObjectDescriptionData > > modelData() const
ObjectDescriptionModelData *const d
Qt::DropActions supportedDropActions ( ) const
inlinevirtual

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

Reimplemented from QAbstractItemModel.

Definition at line 333 of file objectdescriptionmodel.h.

333 { return d->supportedDropActions(); } //krazy:exclude=inline
Qt::DropActions supportedDropActions() const
ObjectDescriptionModelData *const d
bool dropMimeData ( const QMimeData data,
Qt::DropAction  action,
int  row,
int  column,
const QModelIndex parent 
)
inlinevirtual

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

Definition at line 341 of file objectdescriptionmodel.h.

341  { //krazy:exclude=inline
342  return d->dropMimeData(type, data, action, row, column, parent);
343  }
GLuint GLuint GLsizei GLenum type
Definition: GLee.h:872
GLenum GLenum GLvoid * row
Definition: GLee.h:893
bool dropMimeData(ObjectDescriptionType type, const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
GLenum GLenum GLvoid GLvoid * column
Definition: GLee.h:893
ObjectDescriptionModelData *const d
bool removeRows ( int  row,
int  count,
const QModelIndex parent = QModelIndex() 
)
inlinevirtual

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 353 of file objectdescriptionmodel.h.

353  { //krazy:exclude=inline
354  return d->removeRows(row, count, parent);
355  }
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
GLenum GLenum GLvoid * row
Definition: GLee.h:893
GLuint GLuint GLsizei count
Definition: GLee.h:872
ObjectDescriptionModelData *const d
QStringList mimeTypes ( ) const
inlinevirtual

Returns a list of supported drag and drop MIME types.

Currently it only supports one type used internally.

Reimplemented from QAbstractItemModel.

Definition at line 361 of file objectdescriptionmodel.h.

361 { return d->mimeTypes(type); } //krazy:exclude=inline
GLuint GLuint GLsizei GLenum type
Definition: GLee.h:872
QStringList mimeTypes(ObjectDescriptionType type) const
ObjectDescriptionModelData *const d

Member Data Documentation

Definition at line 200 of file objectdescriptionmodel.h.

ObjectDescriptionModelData* const d
protected

Definition at line 364 of file objectdescriptionmodel.h.


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