[Browser] Add "no password" filter to browser

This commit is contained in:
Koncord 2017-10-21 12:42:38 +08:00
parent fb67180809
commit ba8613a179
5 changed files with 26 additions and 1 deletions

View file

@ -54,6 +54,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(tblServerBrowser, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(play())); connect(tblServerBrowser, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(play()));
connect(cBoxNotFull, SIGNAL(toggled(bool)), this, SLOT(notFullSwitch(bool))); connect(cBoxNotFull, SIGNAL(toggled(bool)), this, SLOT(notFullSwitch(bool)));
connect(cBoxWithPlayers, SIGNAL(toggled(bool)), this, SLOT(havePlayersSwitch(bool))); connect(cBoxWithPlayers, SIGNAL(toggled(bool)), this, SLOT(havePlayersSwitch(bool)));
connect(cBBoxWOPass, SIGNAL(toggled(bool)), this, SLOT(noPasswordSwitch(bool)));
connect(comboLatency, SIGNAL(currentIndexChanged(int)), this, SLOT(maxLatencyChanged(int))); connect(comboLatency, SIGNAL(currentIndexChanged(int)), this, SLOT(maxLatencyChanged(int)));
connect(leGamemode, SIGNAL(textChanged(const QString &)), this, SLOT(gamemodeChanged(const QString &))); connect(leGamemode, SIGNAL(textChanged(const QString &)), this, SLOT(gamemodeChanged(const QString &)));
loadFavorites(); loadFavorites();
@ -229,6 +230,11 @@ void MainWindow::havePlayersSwitch(bool state)
proxyModel->filterEmptyServers(state); proxyModel->filterEmptyServers(state);
} }
void MainWindow::noPasswordSwitch(bool state)
{
proxyModel->filterPassworded(state);
}
void MainWindow::maxLatencyChanged(int index) void MainWindow::maxLatencyChanged(int index)
{ {
int maxLatency = index * 50; int maxLatency = index * 50;

View file

@ -31,6 +31,7 @@ protected slots:
void serverSelected(); void serverSelected();
void notFullSwitch(bool state); void notFullSwitch(bool state);
void havePlayersSwitch(bool state); void havePlayersSwitch(bool state);
void noPasswordSwitch(bool state);
void maxLatencyChanged(int index); void maxLatencyChanged(int index);
void gamemodeChanged(const QString &text); void gamemodeChanged(const QString &text);
private: private:

View file

@ -14,6 +14,7 @@ bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &
QModelIndex pingIndex = sourceModel()->index(sourceRow, ServerData::PING, sourceParent); QModelIndex pingIndex = sourceModel()->index(sourceRow, ServerData::PING, sourceParent);
QModelIndex plIndex = sourceModel()->index(sourceRow, ServerData::PLAYERS, sourceParent); QModelIndex plIndex = sourceModel()->index(sourceRow, ServerData::PLAYERS, sourceParent);
QModelIndex maxPlIndex = sourceModel()->index(sourceRow, ServerData::MAX_PLAYERS, sourceParent); QModelIndex maxPlIndex = sourceModel()->index(sourceRow, ServerData::MAX_PLAYERS, sourceParent);
QModelIndex passwordIndex = sourceModel()->index(sourceRow, ServerData::PASSW, sourceParent);
bool pingOk; bool pingOk;
int ping = sourceModel()->data(pingIndex).toInt(&pingOk); int ping = sourceModel()->data(pingIndex).toInt(&pingOk);
@ -26,6 +27,8 @@ bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &
return false; return false;
if (filterFull && players >= maxPlayers) if (filterFull && players >= maxPlayers)
return false; return false;
if(filterPasswEnabled && sourceModel()->data(passwordIndex).toString() == "Yes")
return false;
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent); return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
} }
@ -51,6 +54,7 @@ MySortFilterProxyModel::MySortFilterProxyModel(QObject *parent) : QSortFilterPro
{ {
filterEmpty = false; filterEmpty = false;
filterFull = false; filterFull = false;
filterPasswEnabled = false;
maxPing = 0; maxPing = 0;
setSortCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive); setSortCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive);
} }
@ -72,3 +76,9 @@ void MySortFilterProxyModel::pingLessThan(int maxPing)
this->maxPing = maxPing; this->maxPing = maxPing;
invalidateFilter(); invalidateFilter();
} }
void MySortFilterProxyModel::filterPassworded(bool state)
{
filterPasswEnabled = state;
invalidateFilter();
}

View file

@ -18,9 +18,10 @@ public:
explicit MySortFilterProxyModel(QObject *parent); explicit MySortFilterProxyModel(QObject *parent);
void filterFullServer(bool state); void filterFullServer(bool state);
void filterEmptyServers(bool state); void filterEmptyServers(bool state);
void filterPassworded(bool state);
void pingLessThan(int maxPing); void pingLessThan(int maxPing);
private: private:
bool filterEmpty, filterFull; bool filterEmpty, filterFull, filterPasswEnabled;
int maxPing; int maxPing;
}; };

View file

@ -166,6 +166,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="cBBoxWOPass">
<property name="text">
<string>No password</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="horizontalSpacer"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">