@@ -123,6 +123,33 @@ class PlaylistDelegate : public QStyledItemDelegate {
123123};
124124#endif
125125
126+ #if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
127+ #include < QCollator>
128+
129+ class PlaylistSortProxy : public QSortFilterProxyModel {
130+ public:
131+ explicit PlaylistSortProxy (QObject *parent = nullptr )
132+ : QSortFilterProxyModel(parent)
133+ {
134+ collator.setNumericMode (true ); // ORDEN NATURAL
135+ collator.setCaseSensitivity (Qt::CaseInsensitive);
136+ }
137+
138+ protected:
139+ bool lessThan (const QModelIndex &left,
140+ const QModelIndex &right) const override
141+ {
142+ QString l = sourceModel ()->data (left, sortRole ()).toString ();
143+ QString r = sourceModel ()->data (right, sortRole ()).toString ();
144+ return collator.compare (l, r) < 0 ;
145+ }
146+
147+ private:
148+ mutable QCollator collator;
149+ };
150+ #endif
151+
152+
126153/* ----------------------------------------------------------- */
127154
128155
@@ -432,7 +459,11 @@ void Playlist::createTable() {
432459 table->setColumnCount (COL_SHUFFLE + 1 );
433460 // table->setSortRole(Qt::UserRole + 1);
434461
462+ #if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
463+ proxy = new PlaylistSortProxy (this );
464+ #else
435465 proxy = new QSortFilterProxyModel (this );
466+ #endif
436467 proxy->setSourceModel (table);
437468 proxy->setSortRole (Qt::UserRole + 1 );
438469 proxy->setFilterRole (Qt::UserRole + 1 );
0 commit comments