nick sorting: give letters priority over all other chars
authorsheepluva
Sat, 29 Jan 2011 05:39:24 +0100
changeset 4877 746ddd590dee
parent 4876 813ef4e8e385
child 4878 c310bab60b94
nick sorting: give letters priority over all other chars
QTfrontend/chatwidget.cpp
--- a/QTfrontend/chatwidget.cpp	Sat Jan 29 01:08:39 2011 +0100
+++ b/QTfrontend/chatwidget.cpp	Sat Jan 29 05:39:24 2011 +0100
@@ -37,7 +37,24 @@
 bool ListWidgetNickItem::operator< (const QListWidgetItem & other) const
 {
     // case in-sensitive comparison of the associated strings
-    return (text().compare(other.text(), Qt::CaseInsensitive) < 0);
+    // chars that are no letters are sorted at the end of the list
+
+    QString txt1 = text().toLower();
+    QString txt2 = other.text().toLower();
+
+    bool firstIsShorter = (txt1.size() < txt2.size());
+    int len = firstIsShorter?txt1.size():txt2.size();
+
+    for (int i = 0; i < len; i++)
+    {
+        if (txt1[i] == txt2[i])
+            continue;
+        if (txt1[i].isLetter() != txt2[i].isLetter())
+            return txt1[i].isLetter();
+        return (txt1[i] < txt2[i]);
+    }
+
+    return firstIsShorter;
 }
 
 HWChatWidget::HWChatWidget(QWidget* parent, QSettings * gameSettings, SDLInteraction * sdli, bool notify) :