small tweaks/fixes to room list header saving and restore...
authorsheepluva
Thu, 03 May 2012 03:18:10 +0200
changeset 7011 f6f09a0954ea
parent 7008 25563f054ef3
child 7012 8ca19b467e2f
small tweaks/fixes to room list header saving and restore... setModel should be really done in the constructor of the page IMO btw
QTfrontend/ui/page/pageroomslist.cpp
--- a/QTfrontend/ui/page/pageroomslist.cpp	Thu May 03 02:45:08 2012 +0200
+++ b/QTfrontend/ui/page/pageroomslist.cpp	Thu May 03 03:18:10 2012 +0200
@@ -152,12 +152,6 @@
     connect(searchText, SIGNAL(textChanged (const QString &)), this, SLOT(onFilterChanged()));
     connect(this, SIGNAL(askJoinConfirmation (const QString &)), this, SLOT(onJoinConfirmation(const QString &)), Qt::QueuedConnection);
 
-    // save header state on change
-    connect(roomsList->horizontalHeader(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)),
-            this, SLOT(saveHeaderState()));
-    connect(roomsList->horizontalHeader(), SIGNAL(sectionResized),
-            this, SLOT(saveHeaderState()));
-
     // sorting
     connect(roomsList->horizontalHeader(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)),
             this, SLOT(onSortIndicatorChanged(int, Qt::SortOrder)));
@@ -538,6 +532,10 @@
 
     QHeaderView * h = roomsList->horizontalHeader();
 
+    h->setSortIndicatorShown(true);
+    h->setSortIndicator(RoomsListModel::StateColumn, Qt::AscendingOrder);
+    h->setResizeMode(RoomsListModel::NameColumn, QHeaderView::Stretch);
+
     if (!restoreHeaderState())
     {
         h->resizeSection(RoomsListModel::PlayerCountColumn, 32);
@@ -548,8 +546,12 @@
         h->resizeSection(RoomsListModel::WeaponsColumn, 100);
     }
 
-    h->setSortIndicatorShown(true);
-    h->setResizeMode(RoomsListModel::NameColumn, QHeaderView::Stretch);
+
+    // save header state on change
+    connect(roomsList->horizontalHeader(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)),
+            this, SLOT(saveHeaderState()));
+    connect(roomsList->horizontalHeader(), SIGNAL(sectionResized(int, int, int)),
+            this, SLOT(saveHeaderState()));
 }
 
 
@@ -558,6 +560,12 @@
     if (roomsModel == NULL)
         return;
 
+    if (logicalIndex == 0)
+    {
+        roomsModel->sort(0, Qt::AscendingOrder);
+        return;
+    }
+
     // three state sorting: asc -> dsc -> default (by room state)
     if ((order == Qt::AscendingOrder) && (logicalIndex == roomsModel->sortColumn()))
         roomsList->horizontalHeader()->setSortIndicator(
@@ -600,12 +608,12 @@
 {
     if (!m_gameSettings->contains("frontend/roomslist_header"))
         return false;
-    return roomsList->horizontalHeader()->restoreState(QByteArray::fromHex(
-        (m_gameSettings->value("frontend/roomslist_header").toByteArray())));
+    return roomsList->horizontalHeader()->restoreState(QByteArray::fromBase64(
+        (m_gameSettings->value("frontend/roomslist_header").toString().toAscii())));
 }
 
 void PageRoomsList::saveHeaderState()
 {
     m_gameSettings->setValue("frontend/roomslist_header",
-        roomsList->horizontalHeader()->saveState().toHex());
+        QString(roomsList->horizontalHeader()->saveState().toBase64()));
 }