QTfrontend/ui/page/pageroomslist.cpp
changeset 6996 a0052cd32508
parent 6995 6b44c0f11476
child 7003 e118ee168577
equal deleted inserted replaced
6995:6b44c0f11476 6996:a0052cd32508
   150     connect(CBRules, SIGNAL(currentIndexChanged (int)), this, SLOT(onFilterChanged()));
   150     connect(CBRules, SIGNAL(currentIndexChanged (int)), this, SLOT(onFilterChanged()));
   151     connect(CBWeapons, SIGNAL(currentIndexChanged (int)), this, SLOT(onFilterChanged()));
   151     connect(CBWeapons, SIGNAL(currentIndexChanged (int)), this, SLOT(onFilterChanged()));
   152     connect(searchText, SIGNAL(textChanged (const QString &)), this, SLOT(onFilterChanged()));
   152     connect(searchText, SIGNAL(textChanged (const QString &)), this, SLOT(onFilterChanged()));
   153     connect(this, SIGNAL(askJoinConfirmation (const QString &)), this, SLOT(onJoinConfirmation(const QString &)), Qt::QueuedConnection);
   153     connect(this, SIGNAL(askJoinConfirmation (const QString &)), this, SLOT(onJoinConfirmation(const QString &)), Qt::QueuedConnection);
   154 
   154 
   155 
   155     // save header state on change
       
   156     connect(roomsList->horizontalHeader(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)),
       
   157             this, SLOT(saveHeaderState()));
       
   158     connect(roomsList->horizontalHeader(), SIGNAL(sectionResized),
       
   159             this, SLOT(saveHeaderState()));
       
   160 
       
   161     // sorting
   156     connect(roomsList->horizontalHeader(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)),
   162     connect(roomsList->horizontalHeader(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)),
   157             this, SLOT(onSortIndicatorChanged(int, Qt::SortOrder)));
   163             this, SLOT(onSortIndicatorChanged(int, Qt::SortOrder)));
   158 }
   164 }
   159 
   165 
   160 
   166 
   488     chatWidget->setUser(nickname);
   494     chatWidget->setUser(nickname);
   489 }
   495 }
   490 
   496 
   491 void PageRoomsList::setModel(RoomsListModel * model)
   497 void PageRoomsList::setModel(RoomsListModel * model)
   492 {
   498 {
       
   499     // filter chain:
       
   500     // model -> stateFilteredModel -> schemeFilteredModel ->
       
   501     // -> weaponsFilteredModel -> roomsModel (search filter+sorting)
       
   502 
   493     if (roomsModel == NULL)
   503     if (roomsModel == NULL)
   494     {
   504     {
   495         roomsModel = new QSortFilterProxyModel(this);
   505         roomsModel = new QSortFilterProxyModel(this);
   496         roomsModel->setDynamicSortFilter(true);
   506         roomsModel->setDynamicSortFilter(true);
   497         roomsModel->setSortCaseSensitivity(Qt::CaseInsensitive);
   507         roomsModel->setSortCaseSensitivity(Qt::CaseInsensitive);
   512 
   522 
   513         roomsModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
   523         roomsModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
   514         schemeFilteredModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
   524         schemeFilteredModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
   515         weaponsFilteredModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
   525         weaponsFilteredModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
   516 
   526 
   517         stateFilteredModel->setSourceModel(roomsModel);
       
   518         schemeFilteredModel->setSourceModel(stateFilteredModel);
   527         schemeFilteredModel->setSourceModel(stateFilteredModel);
   519         weaponsFilteredModel->setSourceModel(schemeFilteredModel);
   528         weaponsFilteredModel->setSourceModel(schemeFilteredModel);
   520 
   529         roomsModel->setSourceModel(weaponsFilteredModel);
   521         roomsList->setModel(schemeFilteredModel);
   530 
       
   531         // let the table view display the last model in the filter chain
       
   532         roomsList->setModel(roomsModel);
   522     }
   533     }
   523 
   534 
   524     roomsModel->setSourceModel(model);
   535     stateFilteredModel->setSourceModel(model);
   525 
   536 
   526     roomsList->hideColumn(RoomsListModel::StateColumn);
   537     roomsList->hideColumn(RoomsListModel::StateColumn);
   527 
   538 
   528     QHeaderView * h = roomsList->horizontalHeader();
   539     QHeaderView * h = roomsList->horizontalHeader();
   529 
   540 
       
   541     if (!restoreHeaderState())
       
   542     {
       
   543         h->resizeSection(RoomsListModel::PlayerCountColumn, 32);
       
   544         h->resizeSection(RoomsListModel::TeamCountColumn, 32);
       
   545         h->resizeSection(RoomsListModel::OwnerColumn, 100);
       
   546         h->resizeSection(RoomsListModel::MapColumn, 100);
       
   547         h->resizeSection(RoomsListModel::SchemeColumn, 100);
       
   548         h->resizeSection(RoomsListModel::WeaponsColumn, 100);
       
   549     }
       
   550 
   530     h->setSortIndicatorShown(true);
   551     h->setSortIndicatorShown(true);
   531 
       
   532     h->setResizeMode(RoomsListModel::NameColumn, QHeaderView::Stretch);
   552     h->setResizeMode(RoomsListModel::NameColumn, QHeaderView::Stretch);
   533     h->resizeSection(RoomsListModel::PlayerCountColumn, 32);
       
   534     h->resizeSection(RoomsListModel::TeamCountColumn, 32);
       
   535     h->resizeSection(RoomsListModel::OwnerColumn, 100);
       
   536     h->resizeSection(RoomsListModel::MapColumn, 100);
       
   537     h->resizeSection(RoomsListModel::SchemeColumn, 100);
       
   538     h->resizeSection(RoomsListModel::WeaponsColumn, 100);
       
   539 }
   553 }
   540 
   554 
   541 
   555 
   542 void PageRoomsList::onSortIndicatorChanged(int logicalIndex, Qt::SortOrder order)
   556 void PageRoomsList::onSortIndicatorChanged(int logicalIndex, Qt::SortOrder order)
   543 {
   557 {
   578         weaponsFilteredModel->setFilterWildcard("*"); // "any"
   592         weaponsFilteredModel->setFilterWildcard("*"); // "any"
   579     else
   593     else
   580         weaponsFilteredModel->setFilterWildcard(
   594         weaponsFilteredModel->setFilterWildcard(
   581             QString("*%1*").arg(CBWeapons->currentText()));
   595             QString("*%1*").arg(CBWeapons->currentText()));
   582 }
   596 }
       
   597 
       
   598 
       
   599 bool PageRoomsList::restoreHeaderState()
       
   600 {
       
   601     if (!m_gameSettings->contains("roomslist_header"))
       
   602         return false;
       
   603     return roomsList->horizontalHeader()->restoreState(
       
   604         m_gameSettings->value("roomslist_header").toByteArray());
       
   605 }
       
   606 
       
   607 void PageRoomsList::saveHeaderState()
       
   608 {
       
   609     m_gameSettings->setValue(
       
   610         "roomslist_header", roomsList->horizontalHeader()->saveState());
       
   611 }