Ejemplo n.º 1
0
QVariant MPDSongModel::data(const QModelIndex &index, int role) const {
	Q_ASSERT(m_header);
	if (!index.isValid() || index.row() < 0 || index.row() >= m_visible.size() || index.column() >= m_header->columns().size())
		return QVariant();

	MPDSong song = m_visible.at(index.row());
	if (song.isNull())
		return QVariant();

	if (role == Qt::DisplayRole) {
		switch (m_header->columns().at(index.column())) {
			case HeaderView::TRACK:
				return song.track();
			case HeaderView::TITLE:
				return song.title();
			case HeaderView::LENGTH:
				return song.time();
			case HeaderView::ALBUM:
				return song.album();
			case HeaderView::ARTIST:
				return song.artist();
			case HeaderView::FILENAME:
				return song.filename();
			case HeaderView::URL:
				return song.url();
			case HeaderView::GENRE:
				return song.genre();
			case HeaderView::DATE:
				return song.date();
			case HeaderView::COMPOSER:
				return song.composer();
			case HeaderView::PERFORMER:
				return song.performer();
			case HeaderView::COMMENT:
				return song.comment();
			case HeaderView::DISC:
				return song.disc();
			default:
				return "?";
		}
	}

	if (role == Qt::TextAlignmentRole && m_header->columns().at(index.column()) == HeaderView::LENGTH)
		return Qt::AlignRight;

	return QVariant();
}
Ejemplo n.º 2
0
	int compareRows(MPDSong l, MPDSong r) const {
		int res = 0;

		switch (m_sortColumn) {
			case HeaderView::TRACK:
				res = compareTrack(l, r);
				if (!res) res = compareCols(l.artist(), r.artist());
				if (!res) res = compareCols(l.album(), r.album());
				if (!res) res = compareCols(l.title(), r.title());
				break;

			case HeaderView::LENGTH:
				res = compareCols(l.secs(), r.secs());
				// Fall through
			case HeaderView::ARTIST:
				if (!res) res = compareCols(l.artist(), r.artist());
				if (!res) res = compareCols(l.album(), r.album());
				if (!res) res = compareTrack(l, r);
				if (!res) res = compareCols(l.title(), r.title());
				break;

			case HeaderView::COMPOSER:
				res = compareCols(l.composer(), r.composer());
				if (!res) res = compareCols(l.album(), r.album());
				if (!res) res = compareTrack(l, r);
				if (!res) res = compareCols(l.title(), r.title());
				break;

			case HeaderView::TITLE:
				res = normalizedCompareCols(l.title(), r.title());
				if (!res) res = compareCols(l.artist(), r.artist());
				if (!res) res = compareCols(l.album(), r.album());
				if (!res) res = compareTrack(l, r);
				break;

			case HeaderView::URL:
				res = compareCols(l.url(), r.url());
				break;

			// Similar ones..
			case HeaderView::FILENAME:
				STD_COMP(filename);
				break;

			case HeaderView::GENRE:
				STD_COMP(genre);
				break;

			case HeaderView::DATE:
				STD_COMP(date);
				res = compareCols(l.date(), r.date());
				break;

			case HeaderView::COMMENT:
				STD_COMP(comment);
				break;

			case HeaderView::DISC:
				STD_COMP(disc);
				break;

			case HeaderView::PERFORMER:
				STD_COMP(performer);
				break;

			default: // ALBUM
				res = normalizedCompareCols(l.album(), r.album());
				if (!res) res = compareCols(l.artist(), r.artist());
				if (!res) res = compareTrack(l, r);
				if (!res) res = compareCols(l.title(), r.title());
		}
		if (m_sortOrder != Qt::AscendingOrder)
			res = res * -1;
		return res;
	}