From cb0f5524be48129c9c55eaffb59f11d434e0aa71 Mon Sep 17 00:00:00 2001 From: Koncord Date: Mon, 30 Jan 2017 07:17:21 +0800 Subject: [PATCH] [Browser] Implement filters --- apps/browser/MainWindow.cpp | 32 +++++++++++++++++++++++++++++--- apps/browser/MainWindow.hpp | 8 ++++++-- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/apps/browser/MainWindow.cpp b/apps/browser/MainWindow.cpp index 2da8736b4..3d5abe7d4 100644 --- a/apps/browser/MainWindow.cpp +++ b/apps/browser/MainWindow.cpp @@ -23,7 +23,7 @@ MainWindow::MainWindow(QWidget *parent) browser = new ServerModel; favorites = new ServerModel; - proxyModel = new QSortFilterProxyModel; + proxyModel = new MySortFilterProxyModel(this); proxyModel->setSourceModel(browser); tblServerBrowser->setModel(proxyModel); tblFavorites->setModel(proxyModel); @@ -41,7 +41,10 @@ MainWindow::MainWindow(QWidget *parent) connect(tblFavorites, SIGNAL(clicked(QModelIndex)), this, SLOT(serverSelected())); connect(tblFavorites, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(play())); connect(tblServerBrowser, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(play())); - + connect(cBoxNotFully, SIGNAL(toggled(bool)), this, SLOT(notFullySwitch(bool))); + connect(cBoxWithPlayers, SIGNAL(toggled(bool)), this, SLOT(havePlayersSwitch(bool))); + connect(comboLatency, SIGNAL(currentIndexChanged(int)), this, SLOT(maxLatencyChanged(int))); + connect(leGamemode, SIGNAL(textChanged(const QString &)), this, SLOT(gamemodeChanged(const QString &))); loadFavorites(); } @@ -186,4 +189,27 @@ void MainWindow::loadFavorites() addServerAndUpdate(server.toString()); file.close(); -} \ No newline at end of file +} + +void MainWindow::notFullySwitch(bool state) +{ + proxyModel->filterFullServer(state); +} + +void MainWindow::havePlayersSwitch(bool state) +{ + proxyModel->filterEmptyServers(state); +} + +void MainWindow::maxLatencyChanged(int index) +{ + int maxLatency = index * 50; + proxyModel->pingLessThan(maxLatency); + +} + +void MainWindow::gamemodeChanged(const QString &text) +{ + proxyModel->setFilterFixedString(text); + proxyModel->setFilterKeyColumn(ServerData::MODNAME); +} diff --git a/apps/browser/MainWindow.hpp b/apps/browser/MainWindow.hpp index 74e882c6d..8f67236f9 100644 --- a/apps/browser/MainWindow.hpp +++ b/apps/browser/MainWindow.hpp @@ -8,7 +8,7 @@ #include "ui_Main.h" #include "ServerModel.hpp" -#include +#include "MySortFilterProxyModel.hpp" #include class MainWindow : public QMainWindow, private Ui::MainWindow @@ -29,10 +29,14 @@ protected slots: void deleteServer(); void play(); void serverSelected(); + void notFullySwitch(bool state); + void havePlayersSwitch(bool state); + void maxLatencyChanged(int index); + void gamemodeChanged(const QString &text); private: Process::ProcessInvoker *mGameInvoker; ServerModel *browser, *favorites; - QSortFilterProxyModel *proxyModel; + MySortFilterProxyModel *proxyModel; void loadFavorites(); };