QTfrontend/ui/page/pageroomslist.cpp
changeset 15878 fc3cb23fd26f
parent 14836 b9437746bffb
equal deleted inserted replaced
15877:6cb7330113d8 15878:fc3cb23fd26f
    82     showPassword->setCheckable(true);
    82     showPassword->setCheckable(true);
    83     showPassword->setChecked(true);
    83     showPassword->setChecked(true);
    84     showJoinRestricted = new QAction(QAction::tr("Show join restricted"), stateMenu);
    84     showJoinRestricted = new QAction(QAction::tr("Show join restricted"), stateMenu);
    85     showJoinRestricted->setCheckable(true);
    85     showJoinRestricted->setCheckable(true);
    86     showJoinRestricted->setChecked(true);
    86     showJoinRestricted->setChecked(true);
       
    87     showIncompatible = new QAction(QAction::tr("Show incompatible"), stateMenu);
       
    88     showIncompatible->setCheckable(true);
       
    89     showIncompatible->setChecked(true);
    87     stateMenu->addAction(showGamesInLobby);
    90     stateMenu->addAction(showGamesInLobby);
    88     stateMenu->addAction(showGamesInProgress);
    91     stateMenu->addAction(showGamesInProgress);
    89     stateMenu->addAction(showPassword);
    92     stateMenu->addAction(showPassword);
    90     stateMenu->addAction(showJoinRestricted);
    93     stateMenu->addAction(showJoinRestricted);
       
    94     stateMenu->addAction(showIncompatible);
    91     btnState->setMenu(stateMenu);
    95     btnState->setMenu(stateMenu);
    92 
    96 
    93     // Help/prompt message at top
    97     // Help/prompt message at top
    94     QLabel * lblDesc = new QLabel(tr("Search for a room:"));
    98     QLabel * lblDesc = new QLabel(tr("Search for a room:"));
    95     lblDesc->setObjectName("lblDesc");
    99     lblDesc->setObjectName("lblDesc");
   197     connect(roomsList, SIGNAL(clicked (const QModelIndex &)), searchText, SLOT(setFocus()));
   201     connect(roomsList, SIGNAL(clicked (const QModelIndex &)), searchText, SLOT(setFocus()));
   198     connect(showGamesInLobby, SIGNAL(triggered()), this, SLOT(onFilterChanged()));
   202     connect(showGamesInLobby, SIGNAL(triggered()), this, SLOT(onFilterChanged()));
   199     connect(showGamesInProgress, SIGNAL(triggered()), this, SLOT(onFilterChanged()));
   203     connect(showGamesInProgress, SIGNAL(triggered()), this, SLOT(onFilterChanged()));
   200     connect(showPassword, SIGNAL(triggered()), this, SLOT(onFilterChanged()));
   204     connect(showPassword, SIGNAL(triggered()), this, SLOT(onFilterChanged()));
   201     connect(showJoinRestricted, SIGNAL(triggered()), this, SLOT(onFilterChanged()));
   205     connect(showJoinRestricted, SIGNAL(triggered()), this, SLOT(onFilterChanged()));
       
   206     connect(showIncompatible, SIGNAL(triggered()), this, SLOT(onFilterChanged()));
   202     connect(searchText, SIGNAL(textChanged (const QString &)), this, SLOT(onFilterChanged()));
   207     connect(searchText, SIGNAL(textChanged (const QString &)), this, SLOT(onFilterChanged()));
   203     connect(this, SIGNAL(askJoinConfirmation (const QString &)), this, SLOT(onJoinConfirmation(const QString &)), Qt::QueuedConnection);
   208     connect(this, SIGNAL(askJoinConfirmation (const QString &)), this, SLOT(onJoinConfirmation(const QString &)), Qt::QueuedConnection);
   204 
   209 
   205     // Set focus on search box
   210     // Set focus on search box
   206     connect(this, SIGNAL(pageEnter()), searchText, SLOT(setFocus()));
   211     connect(this, SIGNAL(pageEnter()), searchText, SLOT(setFocus()));
   230 PageRoomsList::PageRoomsList(QWidget* parent) :
   235 PageRoomsList::PageRoomsList(QWidget* parent) :
   231     AbstractPage(parent)
   236     AbstractPage(parent)
   232 {
   237 {
   233     roomsModel = NULL;
   238     roomsModel = NULL;
   234     stateFilteredModel = NULL;
   239     stateFilteredModel = NULL;
       
   240     versionFilteredModel = NULL;
   235 
   241 
   236     initPage();
   242     initPage();
   237 }
   243 }
   238 
   244 
   239 
   245 
   552 }
   558 }
   553 
   559 
   554 void PageRoomsList::setModel(RoomsListModel * model)
   560 void PageRoomsList::setModel(RoomsListModel * model)
   555 {
   561 {
   556     // filter chain:
   562     // filter chain:
   557     // model -> stateFilteredModel -> schemeFilteredModel ->
   563     // model -> versionFilteredModel -> stateFilteredModel -> schemeFilteredModel ->
   558     // -> weaponsFilteredModel -> roomsModel (search filter+sorting)
   564     // -> weaponsFilteredModel -> roomsModel (search filter+sorting)
   559 
   565 
   560     if (roomsModel == NULL)
   566     if (roomsModel == NULL)
   561     {
   567     {
   562         roomsModel = new QSortFilterProxyModel(this);
   568         roomsModel = new QSortFilterProxyModel(this);
   563         roomsModel->setDynamicSortFilter(true);
   569         roomsModel->setDynamicSortFilter(true);
   564         roomsModel->setSortCaseSensitivity(Qt::CaseInsensitive);
   570         roomsModel->setSortCaseSensitivity(Qt::CaseInsensitive);
   565         roomsModel->sort(RoomsListModel::StateColumn, Qt::AscendingOrder);
   571         roomsModel->sort(RoomsListModel::StateColumn, Qt::AscendingOrder);
   566 
   572 
       
   573         versionFilteredModel = new QSortFilterProxyModel(this);
       
   574         versionFilteredModel->setDynamicSortFilter(true);
       
   575         versionFilteredModel->setFilterKeyColumn(RoomsListModel::VersionColumn);
       
   576         versionFilteredModel->setFilterRole(Qt::UserRole);
       
   577 
   567         stateFilteredModel = new QSortFilterProxyModel(this);
   578         stateFilteredModel = new QSortFilterProxyModel(this);
   568 
       
   569         stateFilteredModel->setDynamicSortFilter(true);
   579         stateFilteredModel->setDynamicSortFilter(true);
       
   580         stateFilteredModel->setFilterKeyColumn(RoomsListModel::StateColumn);
       
   581         stateFilteredModel->setSourceModel(versionFilteredModel);
   570 
   582 
   571         roomsModel->setFilterKeyColumn(-1); // search in all columns
   583         roomsModel->setFilterKeyColumn(-1); // search in all columns
   572         stateFilteredModel->setFilterKeyColumn(RoomsListModel::StateColumn);
       
   573 
   584 
   574         roomsModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
   585         roomsModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
   575 
   586 
   576         roomsModel->setSourceModel(stateFilteredModel);
   587         roomsModel->setSourceModel(stateFilteredModel);
   577 
   588 
   583 
   594 
   584         // When a selection changes
   595         // When a selection changes
   585         connect(roomsList->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(roomSelectionChanged(const QModelIndex &, const QModelIndex &)));
   596         connect(roomsList->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(roomSelectionChanged(const QModelIndex &, const QModelIndex &)));
   586     }
   597     }
   587 
   598 
   588     stateFilteredModel->setSourceModel(model);
   599     versionFilteredModel->setSourceModel(model);
   589 
   600 
   590     QHeaderView * h = roomsList->horizontalHeader();
   601     QHeaderView * h = roomsList->horizontalHeader();
   591 
   602 
   592     h->setSortIndicatorShown(true);
   603     h->setSortIndicatorShown(true);
   593     h->setSortIndicator(RoomsListModel::StateColumn, Qt::AscendingOrder);
   604     h->setSortIndicator(RoomsListModel::StateColumn, Qt::AscendingOrder);
   636 
   647 
   637     bool stateLobby = showGamesInLobby->isChecked();
   648     bool stateLobby = showGamesInLobby->isChecked();
   638     bool stateProgress = showGamesInProgress->isChecked();
   649     bool stateProgress = showGamesInProgress->isChecked();
   639     bool statePassword = showPassword->isChecked();
   650     bool statePassword = showPassword->isChecked();
   640     bool stateJoinRestricted = showJoinRestricted->isChecked();
   651     bool stateJoinRestricted = showJoinRestricted->isChecked();
       
   652     bool stateIncompatible = showIncompatible->isChecked();
       
   653 
       
   654     if (!stateIncompatible)
       
   655         versionFilteredModel->setFilterFixedString(*cProtoVer);
       
   656     else
       
   657         versionFilteredModel->setFilterFixedString("");
   641 
   658 
   642     QString filter;
   659     QString filter;
   643     if (!stateLobby && !stateProgress)
   660     if (!stateLobby && !stateProgress)
   644         filter = "O_o";
   661         filter = "O_o";
   645     else if (stateLobby && stateProgress && statePassword && stateJoinRestricted)
   662     else if (stateLobby && stateProgress && statePassword && stateJoinRestricted)