[mythtv] mythmusic patch - trivial
Matt Zimmerman
mdz at debian.org
Sun Apr 6 23:58:32 EDT 2003
On Sun, Apr 06, 2003 at 07:09:11PM -0700, Brent Hills wrote:
> The idea was to zero left pad the string so that I could sort the table by
> the song # column using the default sort routine. Everytime the playlist
> is shuffled the songs are renumbered and sorted by the column number.
>
> To use the default sort routine I needed the column left zero padded or I
> would have to introduce a comparison routine for the sort (QT doesn't sort
> numerically by default).
Ahh, now I see. In that case, how about this (untested):
--
- mdz
Index: playbackbox.cpp
===================================================================
RCS file: /var/lib/cvs/mythmusic/mythmusic/playbackbox.cpp,v
retrieving revision 1.38
diff -u -r1.38 playbackbox.cpp
--- playbackbox.cpp 6 Apr 2003 15:53:17 -0000 1.38
+++ playbackbox.cpp 7 Apr 2003 02:56:29 -0000
@@ -43,6 +43,27 @@
#include "res/rateup.xpm"
#include "res/ratedn.xpm"
+class PlaybackListViewItem: public QListViewItem {
+public:
+ PlaybackListViewItem(QListView * parent,
+ QString label1, QString label2 = QString::null,
+ QString label3 = QString::null, QString label4 = QString::null,
+ QString label5 = QString::null, QString label6 = QString::null,
+ QString label7 = QString::null, QString label8 = QString::null):
+ QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) {};
+
+ virtual int compare(QListViewItem* i, int col, bool ascending) {
+ (void)ascending;
+ int a = text(col).toInt();
+ int b = i->text(col).toInt();
+ if (a < b)
+ return -1;
+ if (a > b)
+ return 1;
+ return 0;
+ };
+};
+
PlaybackBox::PlaybackBox(PlaylistsContainer *the_playlists,
AllMusic *the_music,
QWidget *parent, const char *name)
@@ -583,12 +605,12 @@
rating.append("|");
if (showrating)
- litem = new QListViewItem(playview, position, rating,
- searcher->Artist(),
- searcher->Title(), timestr);
+ litem = new PlaybackListViewItem(playview, position, rating,
+ searcher->Artist(),
+ searcher->Title(), timestr);
else
- litem = new QListViewItem(playview, position, searcher->Artist(),
- searcher->Title(), timestr);
+ litem = new PlaybackListViewItem(playview, position, searcher->Artist(),
+ searcher->Title(), timestr);
listlist.prepend(litem);
count--;
}
@@ -639,20 +661,10 @@
void PlaybackBox::sortListAsShuffled(void)
{
- QListViewItem *litem;
int max = playlistorder.size();
- int digits,by10;
-
- for (digits=1, by10=10; (max / by10) >= 1; by10 *= 10, digits++)
- ;
-
- QString temp(QString().sprintf("%%0%ii", digits));
for(int x = 0; x < max; x++)
- {
- litem = listlist.at(playlistorder[x]);
- litem->setText(0, QString().sprintf(temp.ascii(), x));
- }
+ listlist.at(playlistorder[x])->setText(0, QString::number(x));
playview->setSorting(0);
playview->sort();
More information about the mythtv-dev
mailing list