Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
facfc3cc
Commit
facfc3cc
authored
Mar 28, 2012
by
Max-Wilhelm Bruker
Browse files
added more filter options to GamesProxyModel, user interface still missing (related to issue #32)
parent
deaebddb
Changes
2
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/gamesmodel.cpp
View file @
facfc3cc
...
@@ -99,7 +99,11 @@ void GamesModel::updateGameList(const ServerInfo_Game &game)
...
@@ -99,7 +99,11 @@ void GamesModel::updateGameList(const ServerInfo_Game &game)
}
}
GamesProxyModel
::
GamesProxyModel
(
QObject
*
parent
,
ServerInfo_User
*
_ownUser
)
GamesProxyModel
::
GamesProxyModel
(
QObject
*
parent
,
ServerInfo_User
*
_ownUser
)
:
QSortFilterProxyModel
(
parent
),
ownUser
(
_ownUser
),
unavailableGamesVisible
(
false
)
:
QSortFilterProxyModel
(
parent
),
ownUser
(
_ownUser
),
unavailableGamesVisible
(
false
),
maxPlayersFilterMin
(
-
1
),
maxPlayersFilterMax
(
-
1
)
{
{
setDynamicSortFilter
(
true
);
setDynamicSortFilter
(
true
);
}
}
...
@@ -110,6 +114,41 @@ void GamesProxyModel::setUnavailableGamesVisible(bool _unavailableGamesVisible)
...
@@ -110,6 +114,41 @@ void GamesProxyModel::setUnavailableGamesVisible(bool _unavailableGamesVisible)
invalidateFilter
();
invalidateFilter
();
}
}
void
GamesProxyModel
::
setGameNameFilter
(
const
QString
&
_gameNameFilter
)
{
gameNameFilter
=
_gameNameFilter
;
invalidateFilter
();
}
void
GamesProxyModel
::
setCreatorNameFilter
(
const
QString
&
_creatorNameFilter
)
{
creatorNameFilter
=
_creatorNameFilter
;
invalidateFilter
();
}
void
GamesProxyModel
::
setGameTypeFilter
(
const
QSet
<
int
>
&
_gameTypeFilter
)
{
gameTypeFilter
=
_gameTypeFilter
;
invalidateFilter
();
}
void
GamesProxyModel
::
setMaxPlayersFilter
(
int
_maxPlayersFilterMin
,
int
_maxPlayersFilterMax
)
{
maxPlayersFilterMin
=
_maxPlayersFilterMin
;
maxPlayersFilterMax
=
_maxPlayersFilterMax
;
invalidateFilter
();
}
void
GamesProxyModel
::
resetFilterParameters
()
{
unavailableGamesVisible
=
false
;
gameNameFilter
=
QString
();
creatorNameFilter
=
QString
();
gameTypeFilter
.
clear
();
maxPlayersFilterMin
=
-
1
;
maxPlayersFilterMax
=
-
1
;
}
bool
GamesProxyModel
::
filterAcceptsRow
(
int
sourceRow
,
const
QModelIndex
&
/*sourceParent*/
)
const
bool
GamesProxyModel
::
filterAcceptsRow
(
int
sourceRow
,
const
QModelIndex
&
/*sourceParent*/
)
const
{
{
GamesModel
*
model
=
qobject_cast
<
GamesModel
*>
(
sourceModel
());
GamesModel
*
model
=
qobject_cast
<
GamesModel
*>
(
sourceModel
());
...
@@ -126,6 +165,23 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &/*sourc
...
@@ -126,6 +165,23 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &/*sourc
if
(
game
.
only_registered
())
if
(
game
.
only_registered
())
return
false
;
return
false
;
}
}
if
(
!
gameNameFilter
.
isEmpty
())
if
(
!
QString
::
fromStdString
(
game
.
description
()).
contains
(
gameNameFilter
,
Qt
::
CaseInsensitive
))
return
false
;
if
(
!
creatorNameFilter
.
isEmpty
())
if
(
!
QString
::
fromStdString
(
game
.
creator_info
().
name
()).
contains
(
creatorNameFilter
,
Qt
::
CaseInsensitive
))
return
false
;
QSet
<
int
>
gameTypes
;
for
(
int
i
=
0
;
i
<
game
.
game_types_size
();
++
i
)
gameTypes
.
insert
(
game
.
game_types
(
i
));
if
(
!
gameTypeFilter
.
isEmpty
()
&&
gameTypes
.
intersect
(
gameTypeFilter
).
isEmpty
())
return
false
;
if
((
maxPlayersFilterMin
!=
-
1
)
&&
(
game
.
max_players
()
<
maxPlayersFilterMin
))
return
false
;
if
((
maxPlayersFilterMax
!=
-
1
)
&&
(
game
.
max_players
()
>
maxPlayersFilterMax
))
return
false
;
return
true
;
return
true
;
}
}
cockatrice/src/gamesmodel.h
View file @
facfc3cc
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#include
<QAbstractTableModel>
#include
<QAbstractTableModel>
#include
<QSortFilterProxyModel>
#include
<QSortFilterProxyModel>
#include
<QList>
#include
<QList>
#include
<QSet>
#include
"gametypemap.h"
#include
"gametypemap.h"
class
ServerInfo_Game
;
class
ServerInfo_Game
;
...
@@ -32,9 +33,18 @@ class GamesProxyModel : public QSortFilterProxyModel {
...
@@ -32,9 +33,18 @@ class GamesProxyModel : public QSortFilterProxyModel {
private:
private:
ServerInfo_User
*
ownUser
;
ServerInfo_User
*
ownUser
;
bool
unavailableGamesVisible
;
bool
unavailableGamesVisible
;
QString
gameNameFilter
,
creatorNameFilter
;
QSet
<
int
>
gameTypeFilter
;
int
maxPlayersFilterMin
,
maxPlayersFilterMax
;
public:
public:
GamesProxyModel
(
QObject
*
parent
=
0
,
ServerInfo_User
*
_ownUser
=
0
);
GamesProxyModel
(
QObject
*
parent
=
0
,
ServerInfo_User
*
_ownUser
=
0
);
void
setUnavailableGamesVisible
(
bool
_unavailableGamesVisible
);
void
setUnavailableGamesVisible
(
bool
_unavailableGamesVisible
);
void
setGameNameFilter
(
const
QString
&
_gameNameFilter
);
void
setCreatorNameFilter
(
const
QString
&
_creatorNameFilter
);
void
setGameTypeFilter
(
const
QSet
<
int
>
&
_gameTypeFilter
);
void
setMaxPlayersFilter
(
int
_maxPlayersFilterMin
,
int
_maxPlayersFilterMax
);
void
resetFilterParameters
();
protected:
protected:
bool
filterAcceptsRow
(
int
sourceRow
,
const
QModelIndex
&
sourceParent
)
const
;
bool
filterAcceptsRow
(
int
sourceRow
,
const
QModelIndex
&
sourceParent
)
const
;
};
};
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment