| 1 |
/* This file is part of the KDE project |
| 2 |
Copyright (C) 2006-2007 Matthias Kretz <kretz@kde.org> |
| 3 |
|
| 4 |
This library is free software; you can redistribute it and/or |
| 5 |
modify it under the terms of the GNU Lesser General Public |
| 6 |
License as published by the Free Software Foundation; either |
| 7 |
version 2.1 of the License, or (at your option) version 3, or any |
| 8 |
later version accepted by the membership of KDE e.V. (or its |
| 9 |
successor approved by the membership of KDE e.V.), Nokia Corporation |
| 10 |
(or its successors, if any) and the KDE Free Qt Foundation, which shall |
| 11 |
act as a proxy defined in Section 6 of version 3 of the license. |
| 12 |
|
| 13 |
This library is distributed in the hope that it will be useful, |
| 14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
Lesser General Public License for more details. |
| 17 |
|
| 18 |
You should have received a copy of the GNU Lesser General Public |
| 19 |
License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
|
| 21 |
*/ |
| 22 |
|
| 23 |
#ifndef PHONON_OBJECTDESCRIPTIONMODEL_H |
| 24 |
#define PHONON_OBJECTDESCRIPTIONMODEL_H |
| 25 |
|
| 26 |
#include "phonon_export.h" |
| 27 |
#include "phonondefs.h" |
| 28 |
#include "objectdescription.h" |
| 29 |
#include <QtCore/QList> |
| 30 |
#include <QtCore/QModelIndex> |
| 31 |
#include <QtCore/QStringList> |
| 32 |
|
| 33 |
QT_BEGIN_HEADER |
| 34 |
QT_BEGIN_NAMESPACE |
| 35 |
|
| 36 |
#ifndef QT_NO_PHONON_OBJECTDESCRIPTIONMODEL |
| 37 |
|
| 38 |
namespace Phonon |
| 39 |
{ |
| 40 |
class ObjectDescriptionModelDataPrivate; |
| 41 |
|
| 42 |
/** \internal |
| 43 |
* \class ObjectDescriptionModelData objectdescriptionmodel.h Phonon/ObjectDescriptionModelData |
| 44 |
* \brief Data class for models for ObjectDescription objects. |
| 45 |
* |
| 46 |
* \author Matthias Kretz <kretz@kde.org> |
| 47 |
*/ |
| 48 |
class PHONON_EXPORT ObjectDescriptionModelData |
| 49 |
{ |
| 50 |
public: |
| 51 |
/** |
| 52 |
* Returns the number of rows in the model. This value corresponds |
| 53 |
* to the size of the list passed through setModelData. |
| 54 |
* |
| 55 |
* \param parent The optional \p parent argument is used in most models to specify |
| 56 |
* the parent of the rows to be counted. Because this is a list if a |
| 57 |
* valid parent is specified the result will always be 0. |
| 58 |
* |
| 59 |
* Reimplemented from QAbstractItemModel. |
| 60 |
* |
| 61 |
* \see QAbstractItemModel::rowCount |
| 62 |
*/ |
| 63 |
int rowCount(const QModelIndex &parent = QModelIndex()) const; |
| 64 |
|
| 65 |
/** |
| 66 |
* Returns data from the item with the given \p index for the specified |
| 67 |
* \p role. |
| 68 |
* If the view requests an invalid index, an invalid variant is |
| 69 |
* returned. |
| 70 |
* |
| 71 |
* Reimplemented from QAbstractItemModel. |
| 72 |
* |
| 73 |
* \see QAbstractItemModel::data |
| 74 |
* \see Qt::ItemDataRole |
| 75 |
*/ |
| 76 |
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; |
| 77 |
|
| 78 |
/** |
| 79 |
* Reimplemented to show unavailable devices as disabled (but still |
| 80 |
* selectable). |
| 81 |
*/ |
| 82 |
Qt::ItemFlags flags(const QModelIndex &index) const; |
| 83 |
|
| 84 |
/** |
| 85 |
* Returns a list of indexes in the same order as they are in the |
| 86 |
* model. The indexes come from the ObjectDescription::index |
| 87 |
* method. |
| 88 |
* |
| 89 |
* This is useful to let the user define a list of preference. |
| 90 |
*/ |
| 91 |
QList<int> tupleIndexOrder() const; |
| 92 |
|
| 93 |
/** |
| 94 |
* Returns the ObjectDescription::index for the tuple |
| 95 |
* at the given position \p positionIndex. For example a |
| 96 |
* QComboBox will give you the currentIndex as the |
| 97 |
* position in the list. But to select the according |
| 98 |
* AudioOutputDevice using AudioOutputDevice::fromIndex |
| 99 |
* you can use this method. |
| 100 |
* |
| 101 |
* \param positionIndex The position in the list. |
| 102 |
*/ |
| 103 |
int tupleIndexAtPositionIndex(int positionIndex) const; |
| 104 |
|
| 105 |
/** |
| 106 |
* Returns the MIME data that dropMimeData() can use to create new |
| 107 |
* items. |
| 108 |
*/ |
| 109 |
QMimeData *mimeData(ObjectDescriptionType type, const QModelIndexList &indexes) const; |
| 110 |
|
| 111 |
/** |
| 112 |
* Moves the item at the given \p index up. In the resulting list |
| 113 |
* the items at index.row() and index.row() - 1 are swapped. |
| 114 |
* |
| 115 |
* Connected views are updated automatically. |
| 116 |
*/ |
| 117 |
void moveUp(const QModelIndex &index); |
| 118 |
|
| 119 |
/** |
| 120 |
* Moves the item at the given \p index down. In the resulting list |
| 121 |
* the items at index.row() and index.row() + 1 are swapped. |
| 122 |
* |
| 123 |
* Connected views are updated automatically. |
| 124 |
*/ |
| 125 |
void moveDown(const QModelIndex &index); |
| 126 |
|
| 127 |
void setModelData(const QList<QExplicitlySharedDataPointer<ObjectDescriptionData> > &data); |
| 128 |
QList<QExplicitlySharedDataPointer<ObjectDescriptionData> > modelData() const; |
| 129 |
QExplicitlySharedDataPointer<ObjectDescriptionData> modelData(const QModelIndex &index) const; |
| 130 |
Qt::DropActions supportedDropActions() const; |
| 131 |
bool dropMimeData(ObjectDescriptionType type, const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); |
| 132 |
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); |
| 133 |
QStringList mimeTypes(ObjectDescriptionType type) const; |
| 134 |
|
| 135 |
ObjectDescriptionModelData(QAbstractListModel *); |
| 136 |
protected: |
| 137 |
~ObjectDescriptionModelData(); |
| 138 |
//ObjectDescriptionModelData(ObjectDescriptionModelDataPrivate *dd); |
| 139 |
ObjectDescriptionModelDataPrivate *const d; |
| 140 |
}; |
| 141 |
|
| 142 |
/* Required to ensure template class vtables are exported on both symbian |
| 143 |
and existing builds. */ |
| 144 |
#if (defined(Q_OS_SYMBIAN) && defined(Q_CC_RVCT)) || defined(Q_CC_CLANG) |
| 145 |
// RVCT compiler (2.2.686) requires the export declaration to be on the class to export vtables |
| 146 |
// MWC compiler works both ways |
| 147 |
// GCCE compiler is unknown (it can't compile QtCore yet) |
| 148 |
// Clang also requires the export declaration to be on the class to export vtables |
| 149 |
#define PHONON_TEMPLATE_CLASS_EXPORT PHONON_EXPORT |
| 150 |
#define PHONON_TEMPLATE_CLASS_MEMBER_EXPORT |
| 151 |
#else |
| 152 |
// Windows builds (at least) do not support export declaration on templated class |
| 153 |
// But if you export a member function, the vtable is implicitly exported |
| 154 |
#define PHONON_TEMPLATE_CLASS_EXPORT |
| 155 |
#define PHONON_TEMPLATE_CLASS_MEMBER_EXPORT PHONON_EXPORT |
| 156 |
#endif |
| 157 |
|
| 158 |
/** \class ObjectDescriptionModel objectdescriptionmodel.h Phonon/ObjectDescriptionModel |
| 159 |
* \short The ObjectDescriptionModel class provides a model from |
| 160 |
* a list of ObjectDescription objects. |
| 161 |
* |
| 162 |
* ObjectDescriptionModel is a readonly model that supplies a list |
| 163 |
* using ObjectDescription::name() for the text and |
| 164 |
* ObjectDescription::description() for the tooltip. If set the properties |
| 165 |
* "icon" and "available" are used to set the decoration and disable the |
| 166 |
* item (disabled only visually, you can still select and drag it). |
| 167 |
* |
| 168 |
* It also provides the methods moveUp() and moveDown() to order the list. |
| 169 |
* Additionally drag and drop is possible so that |
| 170 |
* QAbstractItemView::InternalMove can be used. |
| 171 |
* The resulting order of the ObjectDescription::index() values can then be |
| 172 |
* retrieved using tupleIndexOrder(). |
| 173 |
* |
| 174 |
* An example use case would be to give the user a QComboBox to select |
| 175 |
* the output device: |
| 176 |
* \code |
| 177 |
* QComboBox *cb = new QComboBox(parentWidget); |
| 178 |
* ObjectDescriptionModel *model = new ObjectDescriptionModel(cb); |
| 179 |
* model->setModelData(BackendCapabilities::availableAudioOutputDevices()); |
| 180 |
* cb->setModel(model); |
| 181 |
* cb->setCurrentIndex(0); // select first entry |
| 182 |
* \endcode |
| 183 |
* |
| 184 |
* And to retrieve the selected AudioOutputDevice: |
| 185 |
* \code |
| 186 |
* int cbIndex = cb->currentIndex(); |
| 187 |
* AudioOutputDevice selectedDevice = model->modelData(cbIndex); |
| 188 |
* \endcode |
| 189 |
* |
| 190 |
* \ingroup Frontend |
| 191 |
* \author Matthias Kretz <kretz@kde.org> |
| 192 |
*/ |
| 193 |
template<ObjectDescriptionType type> |
| 194 |
class PHONON_TEMPLATE_CLASS_EXPORT ObjectDescriptionModel : public QAbstractListModel |
| 195 |
{ |
| 196 |
public: |
| 197 |
Q_OBJECT_CHECK |
| 198 |
|
| 199 |
/** \internal */ |
| 200 |
static PHONON_TEMPLATE_CLASS_MEMBER_EXPORT const QMetaObject staticMetaObject; |
| 201 |
/** \internal */ |
| 202 |
PHONON_TEMPLATE_CLASS_MEMBER_EXPORT const QMetaObject *metaObject() const; |
| 203 |
/** \internal */ |
| 204 |
PHONON_TEMPLATE_CLASS_MEMBER_EXPORT void *qt_metacast(const char *_clname); |
| 205 |
//int qt_metacall(QMetaObject::Call _c, int _id, void **_a); |
| 206 |
|
| 207 |
/** |
| 208 |
* Returns the number of rows in the model. This value corresponds |
| 209 |
* to the size of the list passed through setModelData. |
| 210 |
* |
| 211 |
* \param parent The optional \p parent argument is used in most models to specify |
| 212 |
* the parent of the rows to be counted. Because this is a list if a |
| 213 |
* valid parent is specified the result will always be 0. |
| 214 |
* |
| 215 |
* Reimplemented from QAbstractItemModel. |
| 216 |
* |
| 217 |
* \see QAbstractItemModel::rowCount |
| 218 |
*/ |
| 219 |
inline int rowCount(const QModelIndex &parent = QModelIndex()) const { return d->rowCount(parent); } //krazy:exclude=inline |
| 220 |
|
| 221 |
/** |
| 222 |
* Returns data from the item with the given \p index for the specified |
| 223 |
* \p role. |
| 224 |
* If the view requests an invalid index, an invalid variant is |
| 225 |
* returned. |
| 226 |
* |
| 227 |
* Reimplemented from QAbstractItemModel. |
| 228 |
* |
| 229 |
* \see QAbstractItemModel::data |
| 230 |
* \see Qt::ItemDataRole |
| 231 |
*/ |
| 232 |
inline QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const { return d->data(index, role); } //krazy:exclude=inline |
| 233 |
|
| 234 |
/** |
| 235 |
* Reimplemented to show unavailable devices as disabled (but still |
| 236 |
* selectable). |
| 237 |
*/ |
| 238 |
inline Qt::ItemFlags flags(const QModelIndex &index) const { return d->flags(index); } //krazy:exclude=inline |
| 239 |
|
| 240 |
/** |
| 241 |
* Returns a list of indexes in the same order as they are in the |
| 242 |
* model. The indexes come from the ObjectDescription::index |
| 243 |
* method. |
| 244 |
* |
| 245 |
* This is useful to let the user define a list of preference. |
| 246 |
*/ |
| 247 |
inline QList<int> tupleIndexOrder() const { return d->tupleIndexOrder(); } //krazy:exclude=inline |
| 248 |
|
| 249 |
/** |
| 250 |
* Returns the ObjectDescription::index for the tuple |
| 251 |
* at the given position \p positionIndex. For example a |
| 252 |
* QComboBox will give you the currentIndex as the |
| 253 |
* position in the list. But to select the according |
| 254 |
* AudioOutputDevice using AudioOutputDevice::fromIndex |
| 255 |
* you can use this method. |
| 256 |
* |
| 257 |
* \param positionIndex The position in the list. |
| 258 |
*/ |
| 259 |
inline int tupleIndexAtPositionIndex(int positionIndex) const { return d->tupleIndexAtPositionIndex(positionIndex); } //krazy:exclude=inline |
| 260 |
|
| 261 |
/** |
| 262 |
* Returns the MIME data that dropMimeData() can use to create new |
| 263 |
* items. |
| 264 |
*/ |
| 265 |
inline QMimeData *mimeData(const QModelIndexList &indexes) const { return d->mimeData(type, indexes); } //krazy:exclude=inline |
| 266 |
|
| 267 |
/** |
| 268 |
* Moves the item at the given \p index up. In the resulting list |
| 269 |
* the items at index.row() and index.row() - 1 are swapped. |
| 270 |
* |
| 271 |
* Connected views are updated automatically. |
| 272 |
*/ |
| 273 |
inline void moveUp(const QModelIndex &index) { d->moveUp(index); } //krazy:exclude=inline |
| 274 |
|
| 275 |
/** |
| 276 |
* Moves the item at the given \p index down. In the resulting list |
| 277 |
* the items at index.row() and index.row() + 1 are swapped. |
| 278 |
* |
| 279 |
* Connected views are updated automatically. |
| 280 |
*/ |
| 281 |
inline void moveDown(const QModelIndex &index) { d->moveDown(index); } //krazy:exclude=inline |
| 282 |
|
| 283 |
/** |
| 284 |
* Constructs a ObjectDescription model with the |
| 285 |
* given \p parent. |
| 286 |
*/ |
| 287 |
explicit inline ObjectDescriptionModel(QObject *parent = 0) : QAbstractListModel(parent), d(new ObjectDescriptionModelData(this)) {} //krazy:exclude=inline |
| 288 |
|
| 289 |
/** |
| 290 |
* Constructs a ObjectDescription model with the |
| 291 |
* given \p parent and the given \p data. |
| 292 |
*/ |
| 293 |
explicit inline ObjectDescriptionModel(const QList<ObjectDescription<type> > &data, QObject *parent = 0) //krazy:exclude=inline |
| 294 |
: QAbstractListModel(parent), d(new ObjectDescriptionModelData(this)) { setModelData(data); } |
| 295 |
|
| 296 |
/** |
| 297 |
* Sets the model data using the list provided by \p data. |
| 298 |
* |
| 299 |
* All previous model data is cleared. |
| 300 |
*/ |
| 301 |
inline void setModelData(const QList<ObjectDescription<type> > &data) { //krazy:exclude=inline |
| 302 |
QList<QExplicitlySharedDataPointer<ObjectDescriptionData> > list; |
| 303 |
for (int i = 0; i < data.count(); ++i) { |
| 304 |
list += data.at(i).d; |
| 305 |
} |
| 306 |
d->setModelData(list); |
| 307 |
} |
| 308 |
|
| 309 |
/** |
| 310 |
* Returns the model data. |
| 311 |
* |
| 312 |
* As the order of the list might have changed this can be different |
| 313 |
* to what was set using setModelData(). |
| 314 |
*/ |
| 315 |
inline QList<ObjectDescription<type> > modelData() const { //krazy:exclude=inline |
| 316 |
QList<ObjectDescription<type> > ret; |
| 317 |
QList<QExplicitlySharedDataPointer<ObjectDescriptionData> > list = d->modelData(); |
| 318 |
for (int i = 0; i < list.count(); ++i) { |
| 319 |
ret << ObjectDescription<type>(list.at(i)); |
| 320 |
} |
| 321 |
return ret; |
| 322 |
} |
| 323 |
|
| 324 |
/** |
| 325 |
* Returns one ObjectDescription of the model data for the given \p index. |
| 326 |
*/ |
| 327 |
inline ObjectDescription<type> modelData(const QModelIndex &index) const { return ObjectDescription<type>(d->modelData(index)); } //krazy:exclude=inline |
| 328 |
|
| 329 |
/** |
| 330 |
* This model supports drag and drop to copy or move |
| 331 |
* items. |
| 332 |
*/ |
| 333 |
inline Qt::DropActions supportedDropActions() const { return d->supportedDropActions(); } //krazy:exclude=inline |
| 334 |
|
| 335 |
/** |
| 336 |
* Accept drops from other models of the same ObjectDescriptionType. |
| 337 |
* |
| 338 |
* If a valid \p parent is given the dropped items will be inserted |
| 339 |
* above that item. |
| 340 |
*/ |
| 341 |
inline bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) { //krazy:exclude=inline |
| 342 |
return d->dropMimeData(type, data, action, row, column, parent); |
| 343 |
} |
| 344 |
|
| 345 |
/** |
| 346 |
* Removes count rows starting with the given row. |
| 347 |
* |
| 348 |
* If a valid \p parent is given no rows are removed since this is a |
| 349 |
* list model. |
| 350 |
* |
| 351 |
* Returns true if the rows were successfully removed; otherwise returns false. |
| 352 |
*/ |
| 353 |
inline bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) { //krazy:exclude=inline |
| 354 |
return d->removeRows(row, count, parent); |
| 355 |
} |
| 356 |
|
| 357 |
/** |
| 358 |
* Returns a list of supported drag and drop MIME types. Currently |
| 359 |
* it only supports one type used internally. |
| 360 |
*/ |
| 361 |
inline QStringList mimeTypes() const { return d->mimeTypes(type); } //krazy:exclude=inline |
| 362 |
|
| 363 |
protected: |
| 364 |
ObjectDescriptionModelData *const d; |
| 365 |
}; |
| 366 |
|
| 367 |
typedef ObjectDescriptionModel<AudioOutputDeviceType> AudioOutputDeviceModel; |
| 368 |
typedef ObjectDescriptionModel<AudioCaptureDeviceType> AudioCaptureDeviceModel; |
| 369 |
typedef ObjectDescriptionModel<EffectType> EffectDescriptionModel; |
| 370 |
typedef ObjectDescriptionModel<AudioChannelType> AudioChannelDescriptionModel; |
| 371 |
typedef ObjectDescriptionModel<SubtitleType> SubtitleDescriptionModel; |
| 372 |
/* |
| 373 |
typedef ObjectDescriptionModel<VideoOutputDeviceType> VideoOutputDeviceModel; |
| 374 |
typedef ObjectDescriptionModel<VideoCaptureDeviceType> VideoCaptureDeviceModel; |
| 375 |
typedef ObjectDescriptionModel<AudioCodecType> AudioCodecDescriptionModel; |
| 376 |
typedef ObjectDescriptionModel<VideoCodecType> VideoCodecDescriptionModel; |
| 377 |
typedef ObjectDescriptionModel<ContainerFormatType> ContainerFormatDescriptionModel; |
| 378 |
typedef ObjectDescriptionModel<VisualizationType> VisualizationDescriptionModel;*/ |
| 379 |
|
| 380 |
} |
| 381 |
|
| 382 |
#endif //QT_NO_PHONON_OBJECTDESCRIPTIONMODEL |
| 383 |
|
| 384 |
QT_END_NAMESPACE |
| 385 |
QT_END_HEADER |
| 386 |
|
| 387 |
#endif // PHONON_OBJECTDESCRIPTIONMODEL_H |
| 388 |
// vim: sw=4 ts=4 tw=80 |