Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickplaylist.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qquickplaylist_p.h"
5
7
34
36{
37 return m_source;
38}
39
41{
42 m_source = source;
43}
44
101void QQuickPlaylist::_q_mediaAboutToBeInserted(int start, int end)
102{
104
106}
107
108void QQuickPlaylist::_q_mediaInserted(int start, int end)
109{
111
114}
115
116void QQuickPlaylist::_q_mediaAboutToBeRemoved(int start, int end)
117{
119
121}
122
123void QQuickPlaylist::_q_mediaRemoved(int start, int end)
124{
126
129}
130
131void QQuickPlaylist::_q_mediaChanged(int start, int end)
132{
135}
136
137void QQuickPlaylist::_q_loadFailed()
138{
139 m_error = m_playlist->error();
140 m_errorString = m_playlist->errorString();
141
142 emit error(Error(m_error), m_errorString);
145}
146
148 : QAbstractListModel(parent)
149 , m_playlist(nullptr)
150 , m_error(QMediaPlaylist::NoError)
151{
152}
153
155{
156 delete m_playlist;
157}
158
181{
182 return PlaybackMode(m_playlist->playbackMode());
183}
184
186{
187 if (playbackMode() == mode)
188 return;
189
190 m_playlist->setPlaybackMode(QMediaPlaylist::PlaybackMode(mode));
191}
192
199{
200 return m_playlist->currentMedia();
201}
202
209{
210 return m_playlist->currentIndex();
211}
212
214{
215 if (currentIndex() == index)
216 return;
217
218 m_playlist->setCurrentIndex(index);
219}
220
227{
228 return m_playlist->mediaCount();
229}
230
251{
252 return Error(m_error);
253}
254
261{
262 return m_errorString;
263}
264
271{
272 return m_playlist->media(index);
273}
274
286{
287 return m_playlist->nextIndex(steps);
288}
289
301{
302 return m_playlist->previousIndex(steps);
303}
304
311{
312 m_playlist->next();
313}
314
321{
322 m_playlist->previous();
323}
324
331{
332 m_playlist->shuffle();
333}
334
347{
348 m_error = QMediaPlaylist::NoError;
349 m_errorString = QString();
351 m_playlist->load(location, format.toLatin1().constData());
352}
353
363{
364 return m_playlist->save(location, format.toLatin1().constData());
365}
366
375{
376 m_playlist->addMedia(QUrl(source));
377}
378
388void QQuickPlaylist::addItems(const QList<QUrl> &sources)
389{
390 if (sources.isEmpty())
391 return;
392
393 QList<QUrl> contents;
395 while (it != sources.constEnd()) {
396 contents.push_back(QUrl(*it));
397 ++it;
398 }
399 m_playlist->addMedia(contents);
400}
401
410{
411 return m_playlist->insertMedia(index, QUrl(source));
412}
413
423bool QQuickPlaylist::insertItems(int index, const QList<QUrl> &sources)
424{
425 if (sources.empty())
426 return false;
427
428 QList<QUrl> contents;
430 while (it != sources.constEnd()) {
431 contents.push_back(QUrl(*it));
432 ++it;
433 }
434 return m_playlist->insertMedia(index, contents);
435}
436
446bool QQuickPlaylist::moveItem(int from, int to)
447{
448 return m_playlist->moveMedia(from, to);
449}
450
459{
460 return m_playlist->removeMedia(index);
461}
462
472bool QQuickPlaylist::removeItems(int start, int end)
473{
474 return m_playlist->removeMedia(start, end);
475}
476
485{
486 m_playlist->clear();
487}
488
489int QQuickPlaylist::rowCount(const QModelIndex &parent) const
490{
491 if (parent.isValid())
492 return 0;
493
494 return m_playlist->mediaCount();
495}
496
498{
499 Q_UNUSED(role);
500
501 if (!index.isValid())
502 return QVariant();
503
504 return m_playlist->media(index.row());
505}
506
507QHash<int, QByteArray> QQuickPlaylist::roleNames() const
508{
509 QHash<int, QByteArray> roleNames;
510 roleNames[SourceRole] = "source";
511 return roleNames;
512}
513
515{
516 m_playlist = new QMediaPlaylist(this);
517
518 connect(m_playlist, SIGNAL(currentIndexChanged(int)),
519 this, SIGNAL(currentIndexChanged()));
520 connect(m_playlist, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode)),
521 this, SIGNAL(playbackModeChanged()));
522 connect(m_playlist, SIGNAL(currentMediaChanged(QUrl)),
524 connect(m_playlist, SIGNAL(mediaAboutToBeInserted(int,int)),
525 this, SLOT(_q_mediaAboutToBeInserted(int,int)));
526 connect(m_playlist, SIGNAL(mediaInserted(int,int)),
527 this, SLOT(_q_mediaInserted(int,int)));
528 connect(m_playlist, SIGNAL(mediaAboutToBeRemoved(int,int)),
529 this, SLOT(_q_mediaAboutToBeRemoved(int,int)));
530 connect(m_playlist, SIGNAL(mediaRemoved(int,int)),
531 this, SLOT(_q_mediaRemoved(int,int)));
532 connect(m_playlist, SIGNAL(mediaChanged(int,int)),
533 this, SLOT(_q_mediaChanged(int,int)));
534 connect(m_playlist, SIGNAL(loaded()),
535 this, SIGNAL(loaded()));
536 connect(m_playlist, SIGNAL(loadFailed()),
537 this, SLOT(_q_loadFailed()));
538}
539
543
593
594#include "moc_qquickplaylist_p.cpp"
void endRemoveRows()
Ends a row removal operation.
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >())
This signal is emitted whenever the data in an existing item changes.
void endInsertRows()
Ends a row insertion operation.
QModelIndex createIndex(int row, int column, const void *data=nullptr) const
Creates a model index for the given row and column with the internal pointer ptr.
void beginRemoveRows(const QModelIndex &parent, int first, int last)
Begins a row removal operation.
void beginInsertRows(const QModelIndex &parent, int first, int last)
Begins a row insertion operation.
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
\inmodule QtCore
\inmodule QtCore
Definition qobject.h:103
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
QQuickPlaylistItem(QObject *parent=0)
\qmltype PlaylistItem \instantiates QQuickPlaylistItem
void setSource(const QUrl &source)
void shuffle()
\qmlmethod QtMultimedia::Playlist::shuffle()
QHash< int, QByteArray > roleNames() const override
bool insertItem(int index, const QUrl &source)
\qmlmethod bool QtMultimedia::Playlist::insertItem(index, source)
void itemAboutToBeInserted(int start, int end)
void setPlaybackMode(PlaybackMode playbackMode)
void currentIndexChanged()
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of rows under the given parent.
QQuickPlaylist(QObject *parent=0)
void next()
\qmlmethod QtMultimedia::Playlist::next()
void itemAboutToBeRemoved(int start, int end)
bool removeItem(int index)
\qmlmethod bool QtMultimedia::Playlist::removeItem(index)
QUrl itemSource(int index)
\qmlmethod url QtMultimedia::Playlist::itemSource(index)
void playbackModeChanged()
void currentItemSourceChanged()
void errorChanged()
bool save(const QUrl &location, const QString &format=QString())
\qmlmethod bool QtMultimedia::Playlist::save(location, format)
void itemCountChanged()
int nextIndex(int steps=1)
\qmlmethod int QtMultimedia::Playlist::nextIndex(steps)
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void itemRemoved(int start, int end)
void addItem(const QUrl &source)
\qmlmethod bool QtMultimedia::Playlist::addItem(source)
void previous()
\qmlmethod QtMultimedia::Playlist::previous()
void itemChanged(int start, int end)
void classBegin() override
Invoked after class creation, but before any properties have been set.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Returns the data stored under the given role for the item referred to by the index.
void itemInserted(int start, int end)
void clear()
\qmlmethod bool QtMultimedia::Playlist::clear()
void load(const QUrl &location, const QString &format=QString())
\qmlmethod QtMultimedia::Playlist::load(location, format)
PlaybackMode playbackMode
int previousIndex(int steps=1)
\qmlmethod int QtMultimedia::Playlist::previousIndex(steps)
void setCurrentIndex(int currentIndex)
const_iterator constBegin() const noexcept
Definition qset.h:139
const_iterator constEnd() const noexcept
Definition qset.h:143
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qurl.h:94
\inmodule QtCore
Definition qvariant.h:65
QSet< QString >::iterator it
Combined button and popup list for selecting options.
#define SLOT(a)
Definition qobjectdefs.h:52
#define SIGNAL(a)
Definition qobjectdefs.h:53
GLint location
GLenum mode
GLuint index
[2]
GLuint GLuint end
GLuint start
GLsizei GLenum * sources
GLint GLsizei GLsizei GLenum format
GLsizei GLsizei GLchar * source
@ NoError
Definition main.cpp:34
#define emit
#define Q_UNUSED(x)
QObject::connect nullptr