diff options
| -rw-r--r-- | src/qmmpui/groupedcontainer.cpp | 80 | ||||
| -rw-r--r-- | src/qmmpui/groupedcontainer_p.h | 2 | ||||
| -rw-r--r-- | src/qmmpui/normalcontainer.cpp | 7 | ||||
| -rw-r--r-- | src/qmmpui/normalcontainer_p.h | 2 | ||||
| -rw-r--r-- | src/qmmpui/playlistcontainer.cpp | 5 | ||||
| -rw-r--r-- | src/qmmpui/playlistcontainer_p.h | 4 | ||||
| -rw-r--r-- | src/qmmpui/playlistgroup.cpp | 46 | ||||
| -rw-r--r-- | src/qmmpui/playlistgroup.h | 42 |
8 files changed, 76 insertions, 112 deletions
diff --git a/src/qmmpui/groupedcontainer.cpp b/src/qmmpui/groupedcontainer.cpp index aebd9f22c..e412825a8 100644 --- a/src/qmmpui/groupedcontainer.cpp +++ b/src/qmmpui/groupedcontainer.cpp @@ -18,6 +18,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ +#include <QTime> #include "playlistmodel.h" #include "groupedcontainer_p.h" @@ -35,37 +36,57 @@ void GroupedContainer::addGroup(PlayListGroup *group) { m_groups.append(group); m_items.append(group); - foreach (PlayListTrack *item, group->tracks()) + foreach (PlayListTrack *item, group->trackList) { m_items.append(item); } updateIndex(); } -void GroupedContainer::addTrack(PlayListTrack *track) +void GroupedContainer::addTracks(QList<PlayListTrack *> tracks) { - if(!m_groups.isEmpty() && track->groupName() == m_groups.last()->formattedTitle()) + QTime time; + time.restart(); + //qDebug("%s", Q_FUNC_INFO); + PlayListGroup *group = m_groups.isEmpty() ? 0 : m_groups.last(); + //m_items.clear(); + foreach (PlayListTrack *track, tracks) { - PlayListGroup *group = m_groups.last(); - group->addTrack(track); - m_items.insert(group->lastIndex + 1, track); - updateIndex(); - return; - } - foreach(PlayListGroup *group, m_groups) - { - if(track->groupName() == group->formattedTitle()) + if(!group || track->groupName() != group->formattedTitle()) { - group->addTrack(track); + group = 0; + foreach(PlayListGroup *g, m_groups) + { + if(track->groupName() == g->formattedTitle()) + { + group = g; + break; + } + } + } + + if(group) + { + group->trackList.append(track); m_items.insert(group->lastIndex + 1, track); updateIndex(); - return; + continue; } - } - PlayListGroup *group = new PlayListGroup(track->groupName()); - group->addTrack(track); - addGroup(group); + group = new PlayListGroup(track->groupName()); + group->trackList.append(track); + addGroup(group); + } + /*foreach(PlayListGroup *g, m_groups) + { + //m_groups.append(g); + m_items.append(g); + foreach (PlayListTrack *item, g->trackList) + { + m_items.append(item); + } + }*/ + qDebug("%s-%d", Q_FUNC_INFO, time.elapsed()); } void GroupedContainer::insertTrack(int index, PlayListTrack *track) @@ -76,7 +97,7 @@ void GroupedContainer::insertTrack(int index, PlayListTrack *track) if(track->groupName() == group->formattedTitle() && index > group->firstIndex && index <= group->lastIndex + 1) { - group->insertTrack(index - group->firstIndex - 1, track); + group->trackList.insert(index - group->firstIndex - 1, track); m_items.insert(index, track); updateIndex(); return; @@ -192,7 +213,7 @@ PlayListTrack *GroupedContainer::findTrack(int number) const { if(number >= firstNumber && number < firstNumber + group->count()) { - return group->tracks().at(number - firstNumber); + return group->trackList.at(number - firstNumber); } firstNumber += group->count(); } @@ -224,7 +245,7 @@ void GroupedContainer::removeTrack(PlayListTrack *track) { if(group->contains(track)) { - group->remove(track); + group->trackList.removeAll(track); if(group->isEmpty()) { m_groups.removeAll(group); @@ -281,8 +302,8 @@ bool GroupedContainer::move(QList<int> indexes, int from, int to) else { m_items.move(i,i + to - from); - group->move(i - group->firstIndex - 1, - i + to - from - group->firstIndex - 1); + group->trackList.move(i - group->firstIndex - 1, + i + to - from - group->firstIndex - 1); } } } @@ -295,8 +316,8 @@ bool GroupedContainer::move(QList<int> indexes, int from, int to) else { m_items.move(indexes[i], indexes[i] + to - from); - group->move(indexes[i] - group->firstIndex - 1, - indexes[i] + to - from - group->firstIndex - 1); + group->trackList.move(indexes[i] - group->firstIndex - 1, + indexes[i] + to - from - group->firstIndex - 1); } } } @@ -308,7 +329,8 @@ QList<PlayListTrack *> GroupedContainer::takeAllTracks() QList<PlayListTrack *> tracks; foreach (PlayListGroup *g, m_groups) { - tracks.append(g->takeAll()); + tracks.append(g->trackList); + g->trackList.clear(); } clear(); return tracks; @@ -357,11 +379,9 @@ void GroupedContainer::sort(int mode) m_items.clear(); foreach (PlayListGroup *g, m_groups) { - QList<PlayListTrack *> tracks = g->takeAll(); - doSort(mode, tracks, m_reverted); - g->addTracks(tracks); + doSort(mode, g->trackList, m_reverted); m_items.append(g); - foreach (PlayListTrack *t, tracks) + foreach (PlayListTrack *t, g->trackList) { m_items.append(t); } diff --git a/src/qmmpui/groupedcontainer_p.h b/src/qmmpui/groupedcontainer_p.h index 642eba4b3..897572363 100644 --- a/src/qmmpui/groupedcontainer_p.h +++ b/src/qmmpui/groupedcontainer_p.h @@ -34,7 +34,7 @@ public: virtual ~GroupedContainer(); - void addTrack(PlayListTrack *track); + void addTracks(QList<PlayListTrack *> tracks); void insertTrack(int index, PlayListTrack *track); QList<PlayListGroup *> groups() const; QList<PlayListItem *> items() const; diff --git a/src/qmmpui/normalcontainer.cpp b/src/qmmpui/normalcontainer.cpp index 0bcba32e5..16c0b74cb 100644 --- a/src/qmmpui/normalcontainer.cpp +++ b/src/qmmpui/normalcontainer.cpp @@ -30,9 +30,12 @@ NormalContainer::~NormalContainer() clear(); } -void NormalContainer::addTrack(PlayListTrack *track) +void NormalContainer::addTracks(QList<PlayListTrack *> tracks) { - m_items.append(track); + foreach (PlayListTrack *track, tracks) + { + m_items.append(track); + } } void NormalContainer::insertTrack(int index, PlayListTrack *track) diff --git a/src/qmmpui/normalcontainer_p.h b/src/qmmpui/normalcontainer_p.h index c57fce5ac..1b0bc20e9 100644 --- a/src/qmmpui/normalcontainer_p.h +++ b/src/qmmpui/normalcontainer_p.h @@ -34,7 +34,7 @@ public: NormalContainer(); virtual ~NormalContainer(); - void addTrack(PlayListTrack *item); + void addTracks(QList<PlayListTrack *> tracks); void insertTrack(int index, PlayListTrack *track); QList<PlayListGroup *> groups() const; QList<PlayListItem *> items() const; diff --git a/src/qmmpui/playlistcontainer.cpp b/src/qmmpui/playlistcontainer.cpp index a717f9677..7772d1b3e 100644 --- a/src/qmmpui/playlistcontainer.cpp +++ b/src/qmmpui/playlistcontainer.cpp @@ -24,10 +24,9 @@ #include "playlistmodel.h" #include "playlistcontainer_p.h" -void PlayListContainer::addTracks(QList<PlayListTrack *> tracks) +void PlayListContainer::addTrack(PlayListTrack *track) { - foreach(PlayListTrack *t, tracks) - addTrack(t); + addTracks(QList<PlayListTrack *> () << track); } ////===============THE BEGINNING OF SORT IMPLEMENTATION =======================//// diff --git a/src/qmmpui/playlistcontainer_p.h b/src/qmmpui/playlistcontainer_p.h index 46a5c8e9d..f7c884d0e 100644 --- a/src/qmmpui/playlistcontainer_p.h +++ b/src/qmmpui/playlistcontainer_p.h @@ -38,8 +38,8 @@ public: PlayListContainer(){} virtual ~PlayListContainer(){} - virtual void addTrack(PlayListTrack *track) = 0; - void addTracks(QList<PlayListTrack *> tracks); + void addTrack(PlayListTrack *track); + virtual void addTracks(QList<PlayListTrack *> tracks) = 0; virtual void insertTrack(int index, PlayListTrack *track) = 0; virtual QList<PlayListGroup *> groups() const = 0; virtual QList<PlayListItem *> items() const = 0; diff --git a/src/qmmpui/playlistgroup.cpp b/src/qmmpui/playlistgroup.cpp index 1278b200a..5fa9bf97b 100644 --- a/src/qmmpui/playlistgroup.cpp +++ b/src/qmmpui/playlistgroup.cpp @@ -29,9 +29,9 @@ PlayListGroup::PlayListGroup(const QString &name) PlayListGroup::~PlayListGroup() { - while(!m_tracks.isEmpty()) + while(!trackList.isEmpty()) { - PlayListTrack* mf = m_tracks.takeFirst(); + PlayListTrack* mf = trackList.takeFirst(); if (mf->flag() == PlayListTrack::FREE) { @@ -49,59 +49,27 @@ const QString PlayListGroup::formattedTitle() return m_name; } -void PlayListGroup::addTrack(PlayListTrack *track) -{ - m_tracks.append(track); -} - -void PlayListGroup::addTracks(QList<PlayListTrack *> tracks) -{ - m_tracks.append(tracks); -} - -void PlayListGroup::insertTrack(int pos, PlayListTrack *track) -{ - m_tracks.insert(pos, track); -} - bool PlayListGroup::contains(PlayListTrack *track) const { - return m_tracks.contains(track); + return trackList.contains(track); } bool PlayListGroup::isEmpty() const { - return m_tracks.isEmpty(); + return trackList.isEmpty(); } -void PlayListGroup::remove(PlayListTrack *track) +QList<PlayListTrack *> PlayListGroup::tracks() const { - m_tracks.removeAll(track); -} - -QList<PlayListTrack *> PlayListGroup::tracks() -{ - return m_tracks; + return trackList; } int PlayListGroup::count() const { - return m_tracks.count(); + return trackList.count(); } bool PlayListGroup::isGroup() const { return true; } - -void PlayListGroup::move(int from, int to) -{ - m_tracks.move(from, to); -} - -QList<PlayListTrack *> PlayListGroup::takeAll() -{ - QList<PlayListTrack *> t = m_tracks; - m_tracks.clear(); - return t; -} diff --git a/src/qmmpui/playlistgroup.h b/src/qmmpui/playlistgroup.h index 8146b5aff..51166d18f 100644 --- a/src/qmmpui/playlistgroup.h +++ b/src/qmmpui/playlistgroup.h @@ -24,6 +24,8 @@ #include "playlisttrack.h" #include "playlistitem.h" +class GroupedContainer; + /** @brief The PlayListTrack class provides a group for use with the PlayListModel class. * @author Ilya Kotov <forkotov02@hotmail.ru> */ @@ -40,30 +42,10 @@ public: */ virtual ~PlayListGroup(); /*! - * First index of the group. - */ - int firstIndex; - /*! - * Last index of the group. - */ - int lastIndex; - /*! * Returns formatted title of the group. */ const QString formattedTitle(); /*! - * Adds track \b track to the the group. - */ - void addTrack(PlayListTrack *track); - /*! - * Adds a list of tracks \b tracks to the the group. - */ - void addTracks(QList<PlayListTrack *> tracks); - /*! - * Inserts a track \b tracks to the the group at the position \b pos. - */ - void insertTrack(int pos, PlayListTrack *track); - /*! * Returns \b true if the group contains track \b track. * Otherwise returns \b false. */ @@ -74,13 +56,9 @@ public: */ bool isEmpty() const; /*! - * Returns track \b track from the group. - */ - void remove(PlayListTrack *track); - /*! * Returns a list of tracks if the group. */ - QList<PlayListTrack *> tracks(); + QList<PlayListTrack *> tracks() const; /*! * Returns number of tracks if the group. */ @@ -93,17 +71,13 @@ public: * Returns \b true. */ bool isGroup() const; - /*! - * Moves the track from position \b from to position \b to. - */ - void move(int from, int to); - /*! - * Removes all tracks from the group and returns a list of them. - */ - QList<PlayListTrack *> takeAll(); private: - QList<PlayListTrack *> m_tracks; + int firstIndex; //First index of the group. + int lastIndex; //Last index of the group. + QList<PlayListTrack *> trackList; //A list of tracks + friend class GroupedContainer; + QString m_name; }; |
