Replace qSort/qStableSort/qSwap

This commit is contained in:
Jonas Kvinge
2018-10-19 20:18:46 +02:00
parent 0969e7f504
commit 0cda4e27aa
24 changed files with 115 additions and 35 deletions

View File

@@ -94,6 +94,10 @@ using std::placeholders::_1;
using std::placeholders::_2;
using std::shared_ptr;
using std::unordered_map;
using std::sort;
using std::stable_sort;
using std::greater;
using std::swap;
const char *Playlist::kCddaMimeType = "x-content/audio-cdda";
const char *Playlist::kRowsMimetype = "application/x-strawberry-playlist-rows";
@@ -684,7 +688,7 @@ bool Playlist::dropMimeData(const QMimeData *data, Qt::DropAction action, int ro
pid = !own_pid;
}
qStableSort(source_rows); // Make sure we take them in order
std::stable_sort(source_rows.begin(), source_rows.end()); // Make sure we take them in order
if (source_playlist == this) {
// Dragged from this playlist - rearrange the items
@@ -1194,17 +1198,17 @@ void Playlist::sort(int column, Qt::SortOrder order) {
if (column == Column_Album) {
// When sorting by album, also take into account discs and tracks.
qStableSort(begin, new_items.end(), std::bind(&Playlist::CompareItems, Column_Track, order, _1, _2));
qStableSort(begin, new_items.end(), std::bind(&Playlist::CompareItems, Column_Disc, order, _1, _2));
qStableSort(begin, new_items.end(), std::bind(&Playlist::CompareItems, Column_Album, order, _1, _2));
std::stable_sort(begin, new_items.end(), std::bind(&Playlist::CompareItems, Column_Track, order, _1, _2));
std::stable_sort(begin, new_items.end(), std::bind(&Playlist::CompareItems, Column_Disc, order, _1, _2));
std::stable_sort(begin, new_items.end(), std::bind(&Playlist::CompareItems, Column_Album, order, _1, _2));
}
else if (column == Column_Filename) {
// When sorting by full paths we also expect a hierarchical order. This returns a breath-first ordering of paths.
qStableSort(begin, new_items.end(), std::bind(&Playlist::CompareItems, Column_Filename, order, _1, _2));
qStableSort(begin, new_items.end(), std::bind(&Playlist::ComparePathDepths, order, _1, _2));
std::stable_sort(begin, new_items.end(), std::bind(&Playlist::CompareItems, Column_Filename, order, _1, _2));
std::stable_sort(begin, new_items.end(), std::bind(&Playlist::ComparePathDepths, order, _1, _2));
}
else {
qStableSort(begin, new_items.end(), std::bind(&Playlist::CompareItems, column, order, _1, _2));
std::stable_sort(begin, new_items.end(), std::bind(&Playlist::CompareItems, column, order, _1, _2));
}
undo_stack_->push(new PlaylistUndoCommands::SortItems(this, column, order, new_items));
@@ -1321,7 +1325,7 @@ void Playlist::RemoveItemsWithoutUndo(const QList<int> &indicesIn) {
// Sort the indices descending because removing elements 'backwards' is easier - indices don't 'move' in the process.
QList<int> indices = indicesIn;
qSort(indices.begin(), indices.end(), DescendingIntLessThan);
std::sort(indices.begin(), indices.end(), DescendingIntLessThan);
for (int j = 0; j < indices.count(); j++) {
int beginning = indices[j], end = indices[j];
@@ -1367,7 +1371,7 @@ bool Playlist::removeRows(QList<int> &rows) {
}
// Start from the end to be sure that indices won't 'move' during the removal process
qSort(rows.begin(), rows.end(), qGreater<int>());
std::sort(rows.begin(), rows.end(), std::greater<int>());
QList<int> part;
while (!rows.isEmpty()) {

View File

@@ -21,6 +21,7 @@
#include "config.h"
#include <math.h>
#include <algorithm>
#include <QApplication>
#include <QObject>
@@ -77,6 +78,8 @@
#include "settings/playbacksettingspage.h"
#include "settings/playlistsettingspage.h"
using std::sort;
const int PlaylistView::kStateVersion = 6;
const int PlaylistView::kGlowIntensitySteps = 24;
const int PlaylistView::kAutoscrollGraceTimeout = 30; // seconds
@@ -572,7 +575,7 @@ void PlaylistView::RemoveSelected(bool deleting_from_disk) {
int last_row = selection.last().top();
// Sort the selection so we remove the items at the *bottom* first, ensuring we don't have to mess around with changing row numbers
qSort(selection.begin(), selection.end(), CompareSelectionRanges);
std::sort(selection.begin(), selection.end(), CompareSelectionRanges);
for (const QItemSelectionRange &range : selection) {
if (range.top() < last_row) rows_removed += range.height();
@@ -613,7 +616,7 @@ QList<int> PlaylistView::GetEditableColumns() {
QModelIndex index = model()->index(0, col);
if (index.flags() & Qt::ItemIsEditable) columns << h->visualIndex(col);
}
qSort(columns);
std::sort(columns.begin(), columns.end());
return columns;
}

View File

@@ -20,6 +20,8 @@
#include "config.h"
#include <algorithm>
#include <QObject>
#include <QIODevice>
#include <QDataStream>
@@ -39,6 +41,8 @@
#include "playlist.h"
#include "queue.h"
using std::stable_sort;
const char *Queue::kRowsMimetype = "application/x-strawberry-queue-rows";
Queue::Queue(QObject *parent) : QAbstractProxyModel(parent) {}
@@ -279,7 +283,9 @@ bool Queue::dropMimeData(const QMimeData *data, Qt::DropAction action, int row,
QList<int> proxy_rows;
QDataStream stream(data->data(kRowsMimetype));
stream >> proxy_rows;
qStableSort(proxy_rows); // Make sure we take them in order
// Make sure we take them in order
std::stable_sort(proxy_rows.begin(), proxy_rows.end());
Move(proxy_rows, row);
}
@@ -355,7 +361,7 @@ QVariant Queue::headerData(int section, Qt::Orientation orientation, int role) c
void Queue::Remove(QList<int> &proxy_rows) {
// Order the rows
qStableSort(proxy_rows);
std::stable_sort(proxy_rows.begin(), proxy_rows.end());
// Reflects immediately changes in the playlist
layoutAboutToBeChanged();

View File

@@ -19,6 +19,7 @@
*/
#include <stdbool.h>
#include <algorithm>
#include <QWidget>
#include <QDialog>
@@ -39,6 +40,8 @@
#include "queuemanager.h"
#include "ui_queuemanager.h"
using std::stable_sort;
QueueManager::QueueManager(QWidget *parent)
: QDialog(parent),
ui_(new Ui_QueueManager),
@@ -105,7 +108,7 @@ void QueueManager::CurrentPlaylistChanged(Playlist *playlist) {
void QueueManager::MoveUp() {
QModelIndexList indexes = ui_->list->selectionModel()->selectedRows();
qStableSort(indexes);
std::stable_sort(indexes.begin(), indexes.end());
if (indexes.isEmpty() || indexes.first().row() == 0) return;
@@ -118,7 +121,7 @@ void QueueManager::MoveUp() {
void QueueManager::MoveDown() {
QModelIndexList indexes = ui_->list->selectionModel()->selectedRows();
qStableSort(indexes);
std::stable_sort(indexes.begin(), indexes.end());
if (indexes.isEmpty() || indexes.last().row() == current_playlist_->queue()->rowCount()-1)
return;