objectdescriptionmodel.h

Go to the documentation of this file.
00001 /*  This file is part of the KDE project
00002     Copyright (C) 2006-2007 Matthias Kretz <kretz@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Lesser General Public
00006     License as published by the Free Software Foundation; either
00007     version 2.1 of the License, or (at your option) version 3, or any
00008     later version accepted by the membership of KDE e.V. (or its
00009     successor approved by the membership of KDE e.V.), Nokia Corporation 
00010     (or its successors, if any) and the KDE Free Qt Foundation, which shall
00011     act as a proxy defined in Section 6 of version 3 of the license.
00012 
00013     This library is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016     Lesser General Public License for more details.
00017 
00018     You should have received a copy of the GNU Lesser General Public 
00019     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #ifndef PHONON_OBJECTDESCRIPTIONMODEL_H
00024 #define PHONON_OBJECTDESCRIPTIONMODEL_H
00025 
00026 #include "phonon_export.h"
00027 #include "phonondefs.h"
00028 #include "objectdescription.h"
00029 #include <QtCore/QList>
00030 #include <QtCore/QModelIndex>
00031 #include <QtCore/QStringList>
00032 
00033 QT_BEGIN_HEADER
00034 QT_BEGIN_NAMESPACE
00035 
00036 #ifndef QT_NO_PHONON_OBJECTDESCRIPTIONMODEL
00037 
00038 namespace Phonon
00039 {
00040     class ObjectDescriptionModelDataPrivate;
00041 
00048     class PHONON_EXPORT ObjectDescriptionModelData
00049     {
00050         public:
00063             int rowCount(const QModelIndex &parent = QModelIndex()) const;
00064 
00076             QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
00077 
00082             Qt::ItemFlags flags(const QModelIndex &index) const;
00083 
00091             QList<int> tupleIndexOrder() const;
00092 
00103             int tupleIndexAtPositionIndex(int positionIndex) const;
00104 
00109             QMimeData *mimeData(ObjectDescriptionType type, const QModelIndexList &indexes) const;
00110 
00117             void moveUp(const QModelIndex &index);
00118 
00125             void moveDown(const QModelIndex &index);
00126 
00127             void setModelData(const QList<QExplicitlySharedDataPointer<ObjectDescriptionData> > &data);
00128             QList<QExplicitlySharedDataPointer<ObjectDescriptionData> > modelData() const;
00129             QExplicitlySharedDataPointer<ObjectDescriptionData> modelData(const QModelIndex &index) const;
00130             Qt::DropActions supportedDropActions() const;
00131             bool dropMimeData(ObjectDescriptionType type, const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
00132             bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
00133             QStringList mimeTypes(ObjectDescriptionType type) const;
00134 
00135             ObjectDescriptionModelData(QAbstractListModel *);
00136         protected:
00137             ~ObjectDescriptionModelData();
00138             //ObjectDescriptionModelData(ObjectDescriptionModelDataPrivate *dd);
00139             ObjectDescriptionModelDataPrivate *const d;
00140     };
00141 
00142 /* Required to ensure template class vtables are exported on both symbian
00143 and existing builds. */
00144 #if defined(Q_OS_SYMBIAN) && defined(Q_CC_RVCT)
00145 // RVCT compiler (2.2.686) requires the export declaration to be on the class to export vtables
00146 // MWC compiler works both ways
00147 // GCCE compiler is unknown (it can't compile QtCore yet)
00148 #define PHONON_TEMPLATE_CLASS_EXPORT PHONON_EXPORT
00149 #define PHONON_TEMPLATE_CLASS_MEMBER_EXPORT
00150 #else
00151 // Windows builds (at least) do not support export declaration on templated class
00152 // But if you export a member function, the vtable is implicitly exported
00153 #define PHONON_TEMPLATE_CLASS_EXPORT
00154 #define PHONON_TEMPLATE_CLASS_MEMBER_EXPORT PHONON_EXPORT
00155 #endif
00156 
00192     template<ObjectDescriptionType type>
00193     class PHONON_TEMPLATE_CLASS_EXPORT ObjectDescriptionModel : public QAbstractListModel
00194     {
00195         public:
00196             Q_OBJECT_CHECK
00197 
00199             static PHONON_TEMPLATE_CLASS_MEMBER_EXPORT const QMetaObject staticMetaObject;
00201             PHONON_TEMPLATE_CLASS_MEMBER_EXPORT const QMetaObject *metaObject() const;
00203             PHONON_TEMPLATE_CLASS_MEMBER_EXPORT void *qt_metacast(const char *_clname);
00204             //int qt_metacall(QMetaObject::Call _c, int _id, void **_a);
00205 
00218             inline int rowCount(const QModelIndex &parent = QModelIndex()) const { return d->rowCount(parent); } //krazy:exclude=inline
00219 
00231             inline QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const { return d->data(index, role); } //krazy:exclude=inline
00232 
00237             inline Qt::ItemFlags flags(const QModelIndex &index) const { return d->flags(index); } //krazy:exclude=inline
00238 
00246             inline QList<int> tupleIndexOrder() const { return d->tupleIndexOrder(); } //krazy:exclude=inline
00247 
00258             inline int tupleIndexAtPositionIndex(int positionIndex) const { return d->tupleIndexAtPositionIndex(positionIndex); } //krazy:exclude=inline
00259 
00264             inline QMimeData *mimeData(const QModelIndexList &indexes) const { return d->mimeData(type, indexes); } //krazy:exclude=inline
00265 
00272             inline void moveUp(const QModelIndex &index) { d->moveUp(index); } //krazy:exclude=inline
00273 
00280             inline void moveDown(const QModelIndex &index) { d->moveDown(index); } //krazy:exclude=inline
00281 
00286             explicit inline ObjectDescriptionModel(QObject *parent = 0) : QAbstractListModel(parent), d(new ObjectDescriptionModelData(this)) {} //krazy:exclude=inline
00287 
00292             explicit inline ObjectDescriptionModel(const QList<ObjectDescription<type> > &data, QObject *parent = 0) //krazy:exclude=inline
00293                 : QAbstractListModel(parent), d(new ObjectDescriptionModelData(this)) { setModelData(data); }
00294 
00300             inline void setModelData(const QList<ObjectDescription<type> > &data) { //krazy:exclude=inline
00301                 QList<QExplicitlySharedDataPointer<ObjectDescriptionData> > list;
00302                 for (int i = 0; i < data.count(); ++i) {
00303                     list += data.at(i).d;
00304                 }
00305                 d->setModelData(list);
00306             }
00307 
00314             inline QList<ObjectDescription<type> > modelData() const { //krazy:exclude=inline
00315                 QList<ObjectDescription<type> > ret;
00316                 QList<QExplicitlySharedDataPointer<ObjectDescriptionData> > list = d->modelData();
00317                 for (int i = 0; i < list.count(); ++i) {
00318                     ret << ObjectDescription<type>(list.at(i));
00319                 }
00320                 return ret;
00321             }
00322 
00326             inline ObjectDescription<type> modelData(const QModelIndex &index) const { return ObjectDescription<type>(d->modelData(index)); } //krazy:exclude=inline
00327 
00332             inline Qt::DropActions supportedDropActions() const { return d->supportedDropActions(); } //krazy:exclude=inline
00333 
00340             inline bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) { //krazy:exclude=inline
00341                 return d->dropMimeData(type, data, action, row, column, parent);
00342             }
00343 
00352             inline bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) { //krazy:exclude=inline
00353                 return d->removeRows(row, count, parent);
00354             }
00355 
00360             inline QStringList mimeTypes() const { return d->mimeTypes(type); } //krazy:exclude=inline
00361 
00362         protected:
00363             ObjectDescriptionModelData *const d;
00364     };
00365 
00366     typedef ObjectDescriptionModel<AudioOutputDeviceType> AudioOutputDeviceModel;
00367     typedef ObjectDescriptionModel<AudioCaptureDeviceType> AudioCaptureDeviceModel;
00368     typedef ObjectDescriptionModel<EffectType> EffectDescriptionModel;
00369     typedef ObjectDescriptionModel<AudioChannelType> AudioChannelDescriptionModel;
00370     typedef ObjectDescriptionModel<SubtitleType> SubtitleDescriptionModel;
00371 /*
00372     typedef ObjectDescriptionModel<VideoOutputDeviceType> VideoOutputDeviceModel;
00373     typedef ObjectDescriptionModel<VideoCaptureDeviceType> VideoCaptureDeviceModel;
00374     typedef ObjectDescriptionModel<AudioCodecType> AudioCodecDescriptionModel;
00375     typedef ObjectDescriptionModel<VideoCodecType> VideoCodecDescriptionModel;
00376     typedef ObjectDescriptionModel<ContainerFormatType> ContainerFormatDescriptionModel;
00377     typedef ObjectDescriptionModel<VisualizationType> VisualizationDescriptionModel;*/
00378 
00379 }
00380 
00381 #endif //QT_NO_PHONON_OBJECTDESCRIPTIONMODEL
00382 
00383 QT_END_NAMESPACE
00384 QT_END_HEADER
00385 
00386 #endif // PHONON_OBJECTDESCRIPTIONMODEL_H
00387 // vim: sw=4 ts=4 tw=80