Commit 6e518da4 authored by Michael Pyne's avatar Michael Pyne

Prefer QVector to QList for most auxiliary lists.

Includes template-template parameter usage in playlist.h's createItems
until all usages of QList gone.
parent 13505df0
......@@ -27,9 +27,9 @@ class PlaylistCollection;
class FileHandle;
template<class T>
class QList;
class QVector;
typedef QList<Playlist *> PlaylistList;
typedef QVector<Playlist *> PlaylistList;
/**
* A simple QDataStream subclass that has an extra field to indicate the cache
......
......@@ -16,7 +16,6 @@
#include "directoryloader.h"
#include <QList> // for FileHandleList
#include <QFileInfo>
#include "mediafiles.h"
......
......@@ -19,7 +19,7 @@
#include "playlist.h"
#include <QList>
#include <QVector>
/**
* A Playlist that is a union of other playlists that is created dynamically.
......@@ -100,7 +100,7 @@ private:
void checkUpdateItems();
private:
QList<PlaylistObserver *> m_observers;
QVector<PlaylistObserver *> m_observers;
PlaylistItemList m_siblings;
PlaylistList m_playlists;
bool m_dirty;
......
......@@ -18,7 +18,7 @@
#define JUK_FILEHANDLE_H
#include <QExplicitlySharedDataPointer>
#include <QList>
#include <QVector>
#include <QMetaType>
class QString;
......@@ -77,7 +77,7 @@ private:
QExplicitlySharedDataPointer<FileHandlePrivate> d;
};
typedef QList<FileHandle> FileHandleList;
typedef QVector<FileHandle> FileHandleList;
Q_DECLARE_METATYPE(FileHandle);
Q_DECLARE_METATYPE(FileHandleList);
......
......@@ -34,10 +34,7 @@ class QUrl;
class ExampleOptionsDialog;
class PlaylistItem;
template<class T>
class QList;
typedef QList<PlaylistItem *> PlaylistItemList;
typedef QVector<PlaylistItem *> PlaylistItemList;
// Used to decide what direction the FileRenamerWidget will move rows in.
enum MovementDirection { MoveUp, MoveDown };
......
......@@ -56,7 +56,7 @@ HistoryPlaylistItem *HistoryPlaylist::createItem(const FileHandle &file, QTreeWi
void HistoryPlaylist::createItems(const PlaylistItemList &siblings)
{
Playlist::createItems<HistoryPlaylistItem, PlaylistItem>(siblings);
Playlist::createItems<QVector, HistoryPlaylistItem, PlaylistItem>(siblings);
}
////////////////////////////////////////////////////////////////////////////////
......
......@@ -303,10 +303,10 @@ void Playlist::playPrevious()
bool random = action("randomPlay") && action<KToggleAction>("randomPlay")->isChecked();
PlaylistItem *previous = 0;
PlaylistItem *previous = nullptr;
if(random && !m_history.isEmpty()) {
PlaylistItemList::Iterator last = --m_history.end();
PlaylistItemList::Iterator last = m_history.end() - 1;
previous = *last;
m_history.erase(last);
}
......@@ -782,35 +782,8 @@ void Playlist::removeFromDisk(const PlaylistItemList &items)
void Playlist::synchronizeItemsTo(const PlaylistItemList &itemList)
{
const auto &existingItems = items();
if(qAbs(itemList.count() - existingItems.count()) >
qMax(itemList.count(), existingItems.count()) / 2)
{
// Large imbalance in list sizes, just clear all and add without
// figuring out the diff also
clearItems(existingItems);
createItems(itemList);
return;
}
// Determine differences between existing playlist items and patch up
QHash<CollectionListItem *, PlaylistItem *> oldItems;
oldItems.reserve(qMax(existingItems.count(), itemList.count()));
for(const auto &item : existingItems) {
oldItems.insert(item->collectionItem(), item);
}
PlaylistItemList newItems;
for(const auto &item : itemList) {
if(oldItems.remove(item->collectionItem()) == 0) {
newItems.append(item->collectionItem());
}
}
clearItems(PlaylistItemList(oldItems.values()));
createItems(newItems);
clearItems(items());
createItems(itemList);
}
void Playlist::dragEnterEvent(QDragEnterEvent *e)
......@@ -1131,7 +1104,7 @@ PlaylistItem *Playlist::createItem(const FileHandle &file, QTreeWidgetItem *afte
void Playlist::createItems(const PlaylistItemList &siblings, PlaylistItem *after)
{
createItems<PlaylistItem, PlaylistItem>(siblings, after);
createItems<QVector, PlaylistItem, PlaylistItem>(siblings, after);
}
void Playlist::addFiles(const QStringList &files, PlaylistItem *after)
......@@ -1563,8 +1536,7 @@ void Playlist::calculateColumnWeights()
if(m_disableColumnWidthUpdates)
return;
PlaylistItemList l = items();
QList<int>::Iterator columnIt;
const PlaylistItemList l = items();
QVector<double> averageWidth(columnCount());
double itemCount = l.size();
......
......@@ -45,7 +45,7 @@ class PlaylistCollection;
class PlaylistToolTip;
class CollectionListItem;
typedef QList<PlaylistItem *> PlaylistItemList;
typedef QVector<PlaylistItem *> PlaylistItemList;
class Playlist : public QTreeWidget, public PlaylistInterface
{
......@@ -466,8 +466,8 @@ protected:
* As a template this allows us to use the same code to initialize the items
* in subclasses. ItemType should be a PlaylistItem subclass.
*/
template <class ItemType, class SiblingType>
void createItems(const QList<SiblingType *> &siblings, ItemType *after = nullptr);
template <template <typename> class Container, class ItemType, class SiblingType>
void createItems(const Container<SiblingType *> &siblings, ItemType *after = nullptr);
protected slots:
void slotPopulateBackMenu() const;
......@@ -659,7 +659,7 @@ private:
bool m_applySharedSettings;
bool m_columnWidthModeChanged;
QList<int> m_weightDirty;
QVector<int> m_weightDirty;
bool m_disableColumnWidthUpdates;
mutable int m_time;
......@@ -711,7 +711,7 @@ private:
static QVector<PlaylistItem *> m_backMenuItems;
};
typedef QList<Playlist *> PlaylistList;
typedef QVector<Playlist *> PlaylistList;
bool processEvents();
......@@ -757,8 +757,8 @@ ItemType *Playlist::createItem(SiblingType *sibling, ItemType *after)
return after;
}
template <class ItemType, class SiblingType>
void Playlist::createItems(const QList<SiblingType *> &siblings, ItemType *after)
template <template <typename> class Container, class ItemType, class SiblingType>
void Playlist::createItems(const Container<SiblingType *> &siblings, ItemType *after)
{
if(siblings.isEmpty())
return;
......
......@@ -29,9 +29,9 @@ class ViewMode;
class QMenu;
template<class T>
class QList;
class QVector;
typedef QList<Playlist *> PlaylistList;
typedef QVector<Playlist *> PlaylistList;
/**
* This is the play list selection box that is by default on the left side of
......
......@@ -184,8 +184,8 @@ QStringList PlaylistCollection::playlists() const
QStringList l;
//(or qFindChildren() if you need MSVC 6 compatibility)
const QList<Playlist *> childList = m_playlistStack->findChildren<Playlist *>("Playlist");
foreach(Playlist *p, childList) {
const auto childList = m_playlistStack->findChildren<Playlist *>("Playlist");
for(Playlist *p : childList) {
l.append(p->name());
}
......
......@@ -41,10 +41,10 @@ class PlayerManager;
class FileHandle;
template<class T>
class QList;
class QVector;
typedef QList<PlaylistItem *> PlaylistItemList;
typedef QList<Playlist *> PlaylistList;
typedef QVector<PlaylistItem *> PlaylistItemList;
typedef QVector<Playlist *> PlaylistList;
class PlaylistCollection : public PlaylistInterface
{
......
......@@ -17,7 +17,7 @@
#ifndef PLAYLISTINTERFACE_H
#define PLAYLISTINTERFACE_H
#include <QList>
#include <QVector>
class FileHandle;
class PlaylistObserver;
......@@ -55,7 +55,7 @@ protected:
virtual ~Watched();
private:
QList<PlaylistObserver *> m_observers;
QVector<PlaylistObserver *> m_observers;
};
/**
......
......@@ -383,7 +383,7 @@ void PlaylistItem::setup(CollectionListItem *item)
// PlaylistItem::Pointer implementation
////////////////////////////////////////////////////////////////////////////////
QMap<PlaylistItem *, QList<PlaylistItem::Pointer *> > PlaylistItem::Pointer::m_map; // static
QMap<PlaylistItem *, QVector<PlaylistItem::Pointer *> > PlaylistItem::Pointer::m_map; // static
PlaylistItem::Pointer::Pointer(PlaylistItem *item) :
m_item(item)
......@@ -441,7 +441,7 @@ void PlaylistItem::Pointer::clear(PlaylistItem *item) // static
if(!item)
return;
QList<Pointer *> l = m_map[item];
QVector<Pointer *> l = m_map[item];
foreach(Pointer *pointer, l)
pointer->m_item = 0;
m_map.remove(item);
......
......@@ -19,8 +19,6 @@
#include <QExplicitlySharedDataPointer>
#include <QVector>
#include <QPixmap>
#include <QList>
#include <QTreeWidgetItem>
#include "tagguesser.h"
......@@ -32,7 +30,7 @@ class PlaylistItem;
class CollectionListItem;
class CollectionList;
typedef QList<PlaylistItem *> PlaylistItemList;
typedef QVector<PlaylistItem *> PlaylistItemList;
/**
* Items for the Playlist and the baseclass for CollectionListItem.
......@@ -86,7 +84,7 @@ public:
private:
PlaylistItem *m_item;
static QMap<PlaylistItem *, QList<Pointer *> > m_map;
static QMap<PlaylistItem *, QVector<Pointer *> > m_map;
};
friend class Pointer;
......
......@@ -18,20 +18,20 @@
#define PLAYLISTSEARCH_H
#include <QRegExp>
#include <QList>
#include <QVector>
class Playlist;
class PlaylistItem;
typedef QList<int> ColumnList;
typedef QList<PlaylistItem *> PlaylistItemList;
typedef QList<Playlist *> PlaylistList;
typedef QVector<int> ColumnList;
typedef QVector<PlaylistItem *> PlaylistItemList;
typedef QVector<Playlist *> PlaylistList;
class PlaylistSearch
{
public:
class Component;
typedef QList<Component> ComponentList;
typedef QVector<Component> ComponentList;
enum SearchMode { MatchAny = 0, MatchAll = 1 };
......
......@@ -88,7 +88,7 @@ PlaylistSearch::Component SearchLine::searchComponent() const
Playlist *playlist = CollectionList::instance();
QList<int> searchedColumns;
QVector<int> searchedColumns;
if(!m_searchFieldsBox || m_searchFieldsBox->currentIndex() == 0) {
foreach(int column, m_columnList) {
......
......@@ -18,25 +18,21 @@
#define JUK_TAGEDITOR_H
#include <QWidget>
#include <QList>
#include <QVector>
#include <QMap>
#include "ui_tageditor.h"
class KComboBox;
class KLineEdit;
class KIntSpinBox;
class KTextEdit;
class KConfigGroup;
class QCheckBox;
class QBoxLayout;
class CollectionObserver;
class Playlist;
class PlaylistItem;
typedef QList<PlaylistItem *> PlaylistItemList;
typedef QVector<PlaylistItem *> PlaylistItemList;
class TagEditor : public QWidget, public Ui::TagEditor
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment