Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/library/basesqltablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ QVariant BaseSqlTableModel::headerData(int section, Qt::Orientation orientation,
return widthValue;
} else if (role == TrackModel::kHeaderNameRole && orientation == Qt::Horizontal) {
return m_headerInfo.value(section).value(role);
} else if (role == Qt::ToolTipRole && orientation == Qt::Horizontal) {
QVariant tooltip = m_headerInfo.value(section).value(role);
if (tooltip.isValid()) return tooltip;
}
return QAbstractTableModel::headerData(section, orientation, role);
}
Expand Down
4 changes: 2 additions & 2 deletions src/library/basesqltablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class BaseSqlTableModel : public QAbstractTableModel, public TrackModel {
void search(const QString& searchText, const QString& extraFilter = QString());
void setSearch(const QString& searchText, const QString& extraFilter = QString());
const QString currentSearch() const;
void setSort(int column, Qt::SortOrder order);
virtual void setSort(int column, Qt::SortOrder order);
void hideTracks(const QModelIndexList& indices);

int fieldIndex(ColumnCache::Column column) const;
Expand Down Expand Up @@ -95,6 +95,7 @@ class BaseSqlTableModel : public QAbstractTableModel, public TrackModel {

QString m_previewDeckGroup;
TrackId m_previewDeckTrackId;
QString m_tableOrderBy;

private slots:
virtual void tracksChanged(QSet<TrackId> trackIds);
Expand Down Expand Up @@ -157,7 +158,6 @@ class BaseSqlTableModel : public QAbstractTableModel, public TrackModel {
QString m_currentSearchFilter;
QVector<QHash<int, QVariant> > m_headerInfo;
QString m_trackSourceOrderBy;
QString m_tableOrderBy;
int m_trackSourceSortColumn;
Qt::SortOrder m_trackSourceSortOrder;

Expand Down
13 changes: 13 additions & 0 deletions src/library/librarytablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ void LibraryTableModel::setTableModel(int id) {
m_pTrackCollection->getTrackSource());
setSearch("");
setDefaultSort(fieldIndex("artist"), Qt::AscendingOrder);

// Set tooltip for random sorting
int fi = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW);
setHeaderData(fi, Qt::Horizontal, tr("Sort items randomly"), Qt::ToolTipRole);
}


Expand Down Expand Up @@ -101,3 +105,12 @@ TrackModel::CapabilitiesFlags LibraryTableModel::getCapabilities() const {
| TRACKMODELCAPS_CLEAR_BEATS
| TRACKMODELCAPS_RESETPLAYED;
}

void LibraryTableModel::setSort(int column, Qt::SortOrder order) {
BaseSqlTableModel::setSort(column, order);

// Random sort easter egg, only in library view
if (column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW)) {
m_tableOrderBy = "ORDER BY RANDOM()";
}
}
2 changes: 2 additions & 0 deletions src/library/librarytablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class LibraryTableModel : public BaseSqlTableModel {
int addTracks(const QModelIndex& index, const QList<QString>& locations);
TrackModel::CapabilitiesFlags getCapabilities() const;
static const QString DEFAULT_LIBRARYFILTER;

void setSort(int column, Qt::SortOrder order) override;
};

#endif