diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2014-10-23 18:49:56 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2014-10-23 18:49:56 +0000 |
| commit | 2d71ff30445c455492b976c753ef72a9c048d497 (patch) | |
| tree | b74cf2eb4fa2021618c935c39eb45d11c0e08825 /src/qmmpui | |
| parent | 01bb81fdc905c2ec6d4ff97a528453eeda26df5f (diff) | |
| download | qmmp-2d71ff30445c455492b976c753ef72a9c048d497.tar.gz qmmp-2d71ff30445c455492b976c753ef72a9c048d497.tar.bz2 qmmp-2d71ff30445c455492b976c753ef72a9c048d497.zip | |
refactoring
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@4593 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/qmmpui')
| -rw-r--r-- | src/qmmpui/groupedcontainer.cpp | 120 | ||||
| -rw-r--r-- | src/qmmpui/groupedcontainer_p.h | 2 | ||||
| -rw-r--r-- | src/qmmpui/playlistcontainer_p.h | 2 | ||||
| -rw-r--r-- | src/qmmpui/playlistgroup.cpp | 2 | ||||
| -rw-r--r-- | src/qmmpui/playlistgroup.h | 2 |
5 files changed, 69 insertions, 59 deletions
diff --git a/src/qmmpui/groupedcontainer.cpp b/src/qmmpui/groupedcontainer.cpp index 34d48a09f..0da706183 100644 --- a/src/qmmpui/groupedcontainer.cpp +++ b/src/qmmpui/groupedcontainer.cpp @@ -70,13 +70,25 @@ void GroupedContainer::addTracks(QList<PlayListTrack *> tracks) void GroupedContainer::insertTrack(int index, PlayListTrack *track) { + int firstIndex = 0, lastIndex = 0; //insert if possible - foreach(PlayListGroup *group, m_groups) + for(int i = 0; i < m_groups.count(); ++i) { - if(track->groupName() == group->formattedTitle() && - index > group->firstIndex && index <= group->lastIndex + 1) + if(i == 0) + { + firstIndex = 0; + lastIndex = m_groups[i]->count(); + } + else + { + firstIndex = lastIndex + 1; + lastIndex = firstIndex + m_groups[i]->count(); + } + + if(track->groupName() == m_groups[i]->formattedTitle() && + index > firstIndex && index <= lastIndex + 1) { - group->trackList.insert(index - group->firstIndex - 1, track); + m_groups[i]->trackList.insert(index - firstIndex - 1, track); m_update = true; return; } @@ -92,25 +104,25 @@ QList<PlayListGroup *> GroupedContainer::groups() const QList<PlayListItem *> GroupedContainer::items() const { - updateIndex(); + updateCache(); return m_items; } int GroupedContainer::count() const { - updateIndex(); + updateCache(); return m_items.count(); } int GroupedContainer::trackCount() const { - updateIndex(); + updateCache(); return m_items.count() - m_groups.count(); } QList<PlayListItem *> GroupedContainer::mid(int pos, int count) const { - updateIndex(); + updateCache(); return m_items.mid(pos, count); } @@ -121,7 +133,7 @@ bool GroupedContainer::isEmpty() const bool GroupedContainer::isSelected(int index) const { - updateIndex(); + updateCache(); if (0 <= index && index < m_items.count()) return m_items.at(index)->isSelected(); return false; @@ -129,14 +141,14 @@ bool GroupedContainer::isSelected(int index) const void GroupedContainer::setSelected(int index, bool selected) { - updateIndex(); + updateCache(); if (0 <= index && index < m_items.count())// && !m_items.at(index)->isGroup()) m_items.at(index)->setSelected(selected); } void GroupedContainer::clearSelection() { - updateIndex(); + updateCache(); foreach (PlayListItem *item, m_items) { item->setSelected(false); @@ -145,13 +157,13 @@ void GroupedContainer::clearSelection() int GroupedContainer::indexOf(PlayListItem *item) const { - updateIndex(); + updateCache(); return m_items.indexOf(item); } PlayListItem *GroupedContainer::item(int index) const { - updateIndex(); + updateCache(); if(index >= count() || index < 0) { qWarning("GroupedContainer: index is out of range"); @@ -162,7 +174,7 @@ PlayListItem *GroupedContainer::item(int index) const PlayListTrack *GroupedContainer::track(int index) const { - updateIndex(); + updateCache(); PlayListItem *i = item(index); if(!i || i->isGroup()) return 0; @@ -179,16 +191,27 @@ PlayListGroup *GroupedContainer::group(int index) const bool GroupedContainer::contains(PlayListItem *item) const { - updateIndex(); + updateCache(); return m_items.contains(item); } int GroupedContainer::numberOfTrack(int index) const { - updateIndex(); + int firstIndex = 0, lastIndex = 0; for(int i = 0; i < m_groups.count(); ++i) { - if(index >= m_groups[i]->firstIndex && index <= m_groups[i]->lastIndex) + if(i == 0) + { + firstIndex = 0; + lastIndex = m_groups[i]->count(); + } + else + { + firstIndex = lastIndex + 1; + lastIndex = firstIndex + m_groups[i]->count(); + } + + if(index >= firstIndex && index <= lastIndex) { return index - (i+1); } @@ -198,7 +221,6 @@ int GroupedContainer::numberOfTrack(int index) const PlayListTrack *GroupedContainer::findTrack(int number) const { - updateIndex(); int firstNumber = 0; foreach (PlayListGroup *group, m_groups) { @@ -213,7 +235,6 @@ PlayListTrack *GroupedContainer::findTrack(int number) const void GroupedContainer::removeTrack(int index) { - updateIndex(); PlayListTrack *t = track(index); if(t) { @@ -255,15 +276,26 @@ void GroupedContainer::removeTracks(QList<PlayListTrack *> tracks) bool GroupedContainer::move(QList<int> indexes, int from, int to) { - updateIndex(); + updateCache(); PlayListGroup *group = 0; + int firstIndex = 0, lastIndex = 0; - foreach (PlayListGroup *g, m_groups) + for(int i = 0; i < m_groups.count(); ++i) { - if(from > g->firstIndex && from <= g->lastIndex && - to > g->firstIndex && to <= g->lastIndex) + if(i == 0) { - group = g; + firstIndex = 0; + lastIndex = m_groups[i]->count(); + } + else + { + firstIndex = lastIndex + 1; + lastIndex = firstIndex + m_groups[i]->count(); + } + + if(from > firstIndex && from <= lastIndex && to > firstIndex && to <= lastIndex) + { + group = m_groups.at(i); break; } } @@ -273,11 +305,11 @@ bool GroupedContainer::move(QList<int> indexes, int from, int to) foreach (int i, indexes) { - if(i <= group->firstIndex || i > group->lastIndex) + if(i <= firstIndex || i > lastIndex) return false; - if(i + to - from - group->firstIndex - 1 >= group->count()) + if(i + to - from - firstIndex - 1 >= group->count()) return false; - if(i + to - from - group->firstIndex - 1 < 0) + if(i + to - from - firstIndex - 1 < 0) return false; if(i + to - from < 0) return false; @@ -291,9 +323,9 @@ bool GroupedContainer::move(QList<int> indexes, int from, int to) break; else { - //m_items.move(i,i + to - from); - group->trackList.move(i - group->firstIndex - 1, - i + to - from - group->firstIndex - 1); + m_items.move(i,i + to - from); + group->trackList.move(i - firstIndex - 1, + i + to - from - firstIndex - 1); } } } @@ -305,13 +337,12 @@ bool GroupedContainer::move(QList<int> indexes, int from, int to) break; else { - //m_items.move(indexes[i], indexes[i] + to - from); - group->trackList.move(indexes[i] - group->firstIndex - 1, - indexes[i] + to - from - group->firstIndex - 1); + m_items.move(indexes[i], indexes[i] + to - from); + group->trackList.move(indexes[i] - firstIndex - 1, + indexes[i] + to - from - firstIndex - 1); } } } - m_update = true; return true; } @@ -367,17 +398,11 @@ void GroupedContainer::sort(int mode) } else { - m_items.clear(); foreach (PlayListGroup *g, m_groups) { doSort(mode, g->trackList, m_reverted); - m_items.append(g); - foreach (PlayListTrack *t, g->trackList) - { - m_items.append(t); - } } - updateIndex(); + m_update = true; } m_reverted = !m_reverted; } @@ -405,7 +430,7 @@ void GroupedContainer::sortSelection(int mode) m_reverted = !m_reverted; } -void GroupedContainer::updateIndex() const +void GroupedContainer::updateCache() const { if(!m_update) return; @@ -414,17 +439,6 @@ void GroupedContainer::updateIndex() const for(int i = 0; i < m_groups.count(); ++i) { - if(i == 0) - { - m_groups[i]->firstIndex = 0; - m_groups[i]->lastIndex = m_groups[i]->count(); - } - else - { - m_groups[i]->firstIndex = m_groups[i-1]->lastIndex + 1; - m_groups[i]->lastIndex = m_groups[i]->firstIndex + m_groups[i]->count(); - } - m_items.append(m_groups.at(i)); foreach (PlayListTrack *track, m_groups.at(i)->trackList) { diff --git a/src/qmmpui/groupedcontainer_p.h b/src/qmmpui/groupedcontainer_p.h index 260af3fab..fa293a077 100644 --- a/src/qmmpui/groupedcontainer_p.h +++ b/src/qmmpui/groupedcontainer_p.h @@ -66,7 +66,7 @@ public: private: void addGroup(PlayListGroup *group); - void updateIndex() const; + void updateCache() const; mutable QList<PlayListGroup *> m_groups; bool m_reverted; diff --git a/src/qmmpui/playlistcontainer_p.h b/src/qmmpui/playlistcontainer_p.h index f7c884d0e..4d3f546f2 100644 --- a/src/qmmpui/playlistcontainer_p.h +++ b/src/qmmpui/playlistcontainer_p.h @@ -38,7 +38,7 @@ public: PlayListContainer(){} virtual ~PlayListContainer(){} - void addTrack(PlayListTrack *track); + virtual 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; diff --git a/src/qmmpui/playlistgroup.cpp b/src/qmmpui/playlistgroup.cpp index 5fa9bf97b..d5d5ba42b 100644 --- a/src/qmmpui/playlistgroup.cpp +++ b/src/qmmpui/playlistgroup.cpp @@ -23,8 +23,6 @@ PlayListGroup::PlayListGroup(const QString &name) { m_name = name; - firstIndex = 0; - lastIndex = 0; } PlayListGroup::~PlayListGroup() diff --git a/src/qmmpui/playlistgroup.h b/src/qmmpui/playlistgroup.h index 51166d18f..2a9f3be3a 100644 --- a/src/qmmpui/playlistgroup.h +++ b/src/qmmpui/playlistgroup.h @@ -73,8 +73,6 @@ public: bool isGroup() const; private: - int firstIndex; //First index of the group. - int lastIndex; //Last index of the group. QList<PlayListTrack *> trackList; //A list of tracks friend class GroupedContainer; |
