QTfrontend/ui/page/pageroomslist.cpp
changeset 6993 47830cf50574
parent 6991 1ec44dde5eb9
child 6995 6b44c0f11476
equal deleted inserted replaced
6992:b8f3d8991e92 6993:47830cf50574
    25 #include <QMessageBox>
    25 #include <QMessageBox>
    26 #include <QHeaderView>
    26 #include <QHeaderView>
    27 #include <QTableView>
    27 #include <QTableView>
    28 
    28 
    29 #include <QSortFilterProxyModel>
    29 #include <QSortFilterProxyModel>
       
    30 
       
    31 #include "roomslistmodel.h"
    30 
    32 
    31 #include "ammoSchemeModel.h"
    33 #include "ammoSchemeModel.h"
    32 #include "pageroomslist.h"
    34 #include "pageroomslist.h"
    33 #include "hwconsts.h"
    35 #include "hwconsts.h"
    34 #include "chatwidget.h"
    36 #include "chatwidget.h"
   475 void PageRoomsList::setUser(const QString & nickname)
   477 void PageRoomsList::setUser(const QString & nickname)
   476 {
   478 {
   477     chatWidget->setUser(nickname);
   479     chatWidget->setUser(nickname);
   478 }
   480 }
   479 
   481 
   480 void PageRoomsList::setModel(QAbstractTableModel *model)
   482 void PageRoomsList::setModel(RoomsListModel *model)
   481 {
   483 {
   482     roomsModel = new QSortFilterProxyModel(this);
   484     roomsModel = new QSortFilterProxyModel(this);
   483     roomsModel->setSourceModel(model);
   485     roomsModel->setSourceModel(model);
   484     roomsModel->setDynamicSortFilter(true);
   486     roomsModel->setDynamicSortFilter(true);
   485     roomsModel->setSortCaseSensitivity(Qt::CaseInsensitive);
   487     roomsModel->setSortCaseSensitivity(Qt::CaseInsensitive);
   486     roomsModel->sort(0, Qt::AscendingOrder);
   488     roomsModel->sort(RoomsListModel::StateColumn, Qt::AscendingOrder);
   487     roomsList->setModel(roomsModel);
   489     roomsList->setModel(roomsModel);
   488 
   490 
   489     roomsList->hideColumn(0);
   491     roomsList->hideColumn(RoomsListModel::StateColumn);
   490 
   492 
   491     QHeaderView * h = roomsList->horizontalHeader();
   493     QHeaderView * h = roomsList->horizontalHeader();
   492 
   494 
   493     h->setSortIndicatorShown(true);
   495     h->setSortIndicatorShown(true);
   494 
   496 
   495     h->setResizeMode(1, QHeaderView::Stretch);
   497     h->setResizeMode(RoomsListModel::NameColumn, QHeaderView::Stretch);
   496     h->resizeSection(2, 32);
   498     h->resizeSection(RoomsListModel::PlayerCountColumn, 32);
   497     h->resizeSection(3, 32);
   499     h->resizeSection(RoomsListModel::TeamCountColumn, 32);
   498     h->resizeSection(4, 100);
   500     h->resizeSection(RoomsListModel::OwnerColumn, 100);
   499     h->resizeSection(5, 100);
   501     h->resizeSection(RoomsListModel::MapColumn, 100);
   500     h->resizeSection(6, 100);
   502     h->resizeSection(RoomsListModel::SchemeColumn, 100);
   501     h->resizeSection(7, 100);
   503     h->resizeSection(RoomsListModel::WeaponsColumn, 100);
   502 
   504 
   503     connect(h, SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)),
   505     connect(h, SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)),
   504             this, SLOT(onSortIndicatorChanged(int, Qt::SortOrder)));
   506             this, SLOT(onSortIndicatorChanged(int, Qt::SortOrder)));
   505 
   507 
   506 }
   508 }
   507 
   509 
   508 void PageRoomsList::onSortIndicatorChanged(int logicalIndex, Qt::SortOrder order)
   510 void PageRoomsList::onSortIndicatorChanged(int logicalIndex, Qt::SortOrder order)
   509 {
   511 {
   510     // three state sorting: asc -> dsc -> default (by room state)
   512     // three state sorting: asc -> dsc -> default (by room state)
   511     if ((order == Qt::AscendingOrder) && (logicalIndex == roomsModel->sortColumn()))
   513     if ((order == Qt::AscendingOrder) && (logicalIndex == roomsModel->sortColumn()))
   512         roomsList->horizontalHeader()->setSortIndicator(0, Qt::AscendingOrder);
   514         roomsList->horizontalHeader()->setSortIndicator(
       
   515             RoomsListModel::StateColumn, Qt::AscendingOrder);
   513     else
   516     else
   514         roomsModel->sort(logicalIndex, order);
   517         roomsModel->sort(logicalIndex, order);
   515 }
   518 }