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
6a4384f9
Commit
6a4384f9
authored
Jan 02, 2015
by
Jeffrey Oliver
Browse files
WIP: Refactor gamesproxymodel to own the persistence layer.
parent
16bbc5e8
Changes
5
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/dlg_filter_games.cpp
View file @
6a4384f9
#include
"dlg_filter_games.h"
#include
"dlg_filter_games.h"
#include
<QDebug>
#include
<QCheckBox>
#include
<QCheckBox>
#include
<QPushButton>
#include
<QPushButton>
#include
<QLabel>
#include
<QLabel>
...
@@ -12,49 +13,38 @@
...
@@ -12,49 +13,38 @@
#include
<QSettings>
#include
<QSettings>
#include
<QCryptographicHash>
#include
<QCryptographicHash>
DlgFilterGames
::
DlgFilterGames
(
const
QMap
<
int
,
QString
>
&
_allGameTypes
,
QWidget
*
parent
)
DlgFilterGames
::
DlgFilterGames
(
const
QMap
<
int
,
QString
>
&
_allGameTypes
,
GamesProxyModel
*
_gamesProxyModel
,
QWidget
*
parent
)
:
QDialog
(
parent
),
:
QDialog
(
parent
),
allGameTypes
(
_allGameTypes
)
allGameTypes
(
_allGameTypes
),
gamesProxyModel
(
_gamesProxyModel
)
{
{
QSettings
settings
;
QSettings
settings
;
settings
.
beginGroup
(
"filter_games"
);
settings
.
beginGroup
(
"filter_games"
);
unavailableGamesVisibleCheckBox
=
new
QCheckBox
(
tr
(
"Show &unavailable games"
));
unavailableGamesVisibleCheckBox
=
new
QCheckBox
(
tr
(
"Show &unavailable games"
));
unavailableGamesVisibleCheckBox
->
setChecked
(
qDebug
()
<<
"getUnavailableGamesVisible() == "
<<
gamesProxyModel
->
getUnavailableGamesVisible
();
settings
.
value
(
"unavailable_games_visible"
,
false
).
toBool
()
unavailableGamesVisibleCheckBox
->
setChecked
(
gamesProxyModel
->
getUnavailableGamesVisible
());
);
passwordProtectedGamesVisibleCheckBox
=
new
QCheckBox
(
tr
(
"Show &password protected games"
));
passwordProtectedGamesVisibleCheckBox
=
new
QCheckBox
(
tr
(
"Show &password protected games"
));
passwordProtectedGamesVisibleCheckBox
->
setChecked
(
passwordProtectedGamesVisibleCheckBox
->
setChecked
(
gamesProxyModel
->
getPasswordProtectedGamesVisible
());
settings
.
value
(
"password_protected_games_visible"
,
false
).
toBool
()
);
gameNameFilterEdit
=
new
QLineEdit
;
gameNameFilterEdit
=
new
QLineEdit
;
gameNameFilterEdit
->
setText
(
gameNameFilterEdit
->
setText
(
gamesProxyModel
->
getGameNameFilter
());
settings
.
value
(
"game_name_filter"
,
""
).
toString
()
);
QLabel
*
gameNameFilterLabel
=
new
QLabel
(
tr
(
"Game &description:"
));
QLabel
*
gameNameFilterLabel
=
new
QLabel
(
tr
(
"Game &description:"
));
gameNameFilterLabel
->
setBuddy
(
gameNameFilterEdit
);
gameNameFilterLabel
->
setBuddy
(
gameNameFilterEdit
);
creatorNameFilterEdit
=
new
QLineEdit
;
creatorNameFilterEdit
=
new
QLineEdit
;
creatorNameFilterEdit
->
setText
(
creatorNameFilterEdit
->
setText
(
gamesProxyModel
->
getCreatorNameFilter
());
settings
.
value
(
"creator_name_filter"
,
""
).
toString
()
);
QLabel
*
creatorNameFilterLabel
=
new
QLabel
(
tr
(
"&Creator name:"
));
QLabel
*
creatorNameFilterLabel
=
new
QLabel
(
tr
(
"&Creator name:"
));
creatorNameFilterLabel
->
setBuddy
(
creatorNameFilterEdit
);
creatorNameFilterLabel
->
setBuddy
(
creatorNameFilterEdit
);
QVBoxLayout
*
gameTypeFilterLayout
=
new
QVBoxLayout
;
QVBoxLayout
*
gameTypeFilterLayout
=
new
QVBoxLayout
;
QMapIterator
<
int
,
QString
>
gameTypesIterator
(
allGameTypes
);
QMapIterator
<
int
,
QString
>
gameTypesIterator
(
allGameTypes
);
while
(
gameTypesIterator
.
hasNext
())
{
while
(
gameTypesIterator
.
hasNext
())
{
gameTypesIterator
.
next
();
gameTypesIterator
.
next
();
QCheckBox
*
temp
=
new
QCheckBox
(
gameTypesIterator
.
value
());
QCheckBox
*
temp
=
new
QCheckBox
(
gameTypesIterator
.
value
());
temp
->
setChecked
(
temp
->
setChecked
(
gamesProxyModel
->
getGameTypeFilter
().
contains
(
gameTypesIterator
.
key
()));
settings
.
value
(
"game_type/"
+
hashGameType
(
gameTypesIterator
.
value
()),
false
).
toBool
()
);
gameTypeFilterCheckBoxes
.
insert
(
gameTypesIterator
.
key
(),
temp
);
gameTypeFilterCheckBoxes
.
insert
(
gameTypesIterator
.
key
(),
temp
);
gameTypeFilterLayout
->
addWidget
(
temp
);
gameTypeFilterLayout
->
addWidget
(
temp
);
...
@@ -65,34 +55,30 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &_allGameTypes, QWidget
...
@@ -65,34 +55,30 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &_allGameTypes, QWidget
gameTypeFilterGroupBox
->
setLayout
(
gameTypeFilterLayout
);
gameTypeFilterGroupBox
->
setLayout
(
gameTypeFilterLayout
);
}
else
}
else
gameTypeFilterGroupBox
=
0
;
gameTypeFilterGroupBox
=
0
;
QLabel
*
maxPlayersFilterMinLabel
=
new
QLabel
(
tr
(
"at &least:"
));
QLabel
*
maxPlayersFilterMinLabel
=
new
QLabel
(
tr
(
"at &least:"
));
maxPlayersFilterMinSpinBox
=
new
QSpinBox
;
maxPlayersFilterMinSpinBox
=
new
QSpinBox
;
maxPlayersFilterMinSpinBox
->
setMinimum
(
1
);
maxPlayersFilterMinSpinBox
->
setMinimum
(
1
);
maxPlayersFilterMinSpinBox
->
setMaximum
(
99
);
maxPlayersFilterMinSpinBox
->
setMaximum
(
99
);
maxPlayersFilterMinSpinBox
->
setValue
(
maxPlayersFilterMinSpinBox
->
setValue
(
gamesProxyModel
->
getMaxPlayersFilterMin
());
settings
.
value
(
"min_players"
,
1
).
toInt
()
);
maxPlayersFilterMinLabel
->
setBuddy
(
maxPlayersFilterMinSpinBox
);
maxPlayersFilterMinLabel
->
setBuddy
(
maxPlayersFilterMinSpinBox
);
QLabel
*
maxPlayersFilterMaxLabel
=
new
QLabel
(
tr
(
"at &most:"
));
QLabel
*
maxPlayersFilterMaxLabel
=
new
QLabel
(
tr
(
"at &most:"
));
maxPlayersFilterMaxSpinBox
=
new
QSpinBox
;
maxPlayersFilterMaxSpinBox
=
new
QSpinBox
;
maxPlayersFilterMaxSpinBox
->
setMinimum
(
1
);
maxPlayersFilterMaxSpinBox
->
setMinimum
(
1
);
maxPlayersFilterMaxSpinBox
->
setMaximum
(
99
);
maxPlayersFilterMaxSpinBox
->
setMaximum
(
99
);
maxPlayersFilterMaxSpinBox
->
setValue
(
maxPlayersFilterMaxSpinBox
->
setValue
(
gamesProxyModel
->
getMaxPlayersFilterMax
());
settings
.
value
(
"max_players"
,
99
).
toInt
()
);
maxPlayersFilterMaxLabel
->
setBuddy
(
maxPlayersFilterMaxSpinBox
);
maxPlayersFilterMaxLabel
->
setBuddy
(
maxPlayersFilterMaxSpinBox
);
QGridLayout
*
maxPlayersFilterLayout
=
new
QGridLayout
;
QGridLayout
*
maxPlayersFilterLayout
=
new
QGridLayout
;
maxPlayersFilterLayout
->
addWidget
(
maxPlayersFilterMinLabel
,
0
,
0
);
maxPlayersFilterLayout
->
addWidget
(
maxPlayersFilterMinLabel
,
0
,
0
);
maxPlayersFilterLayout
->
addWidget
(
maxPlayersFilterMinSpinBox
,
0
,
1
);
maxPlayersFilterLayout
->
addWidget
(
maxPlayersFilterMinSpinBox
,
0
,
1
);
maxPlayersFilterLayout
->
addWidget
(
maxPlayersFilterMaxLabel
,
1
,
0
);
maxPlayersFilterLayout
->
addWidget
(
maxPlayersFilterMaxLabel
,
1
,
0
);
maxPlayersFilterLayout
->
addWidget
(
maxPlayersFilterMaxSpinBox
,
1
,
1
);
maxPlayersFilterLayout
->
addWidget
(
maxPlayersFilterMaxSpinBox
,
1
,
1
);
QGroupBox
*
maxPlayersGroupBox
=
new
QGroupBox
(
tr
(
"Maximum player count"
));
QGroupBox
*
maxPlayersGroupBox
=
new
QGroupBox
(
tr
(
"Maximum player count"
));
maxPlayersGroupBox
->
setLayout
(
maxPlayersFilterLayout
);
maxPlayersGroupBox
->
setLayout
(
maxPlayersFilterLayout
);
QGridLayout
*
leftGrid
=
new
QGridLayout
;
QGridLayout
*
leftGrid
=
new
QGridLayout
;
leftGrid
->
addWidget
(
gameNameFilterLabel
,
0
,
0
);
leftGrid
->
addWidget
(
gameNameFilterLabel
,
0
,
0
);
leftGrid
->
addWidget
(
gameNameFilterEdit
,
0
,
1
);
leftGrid
->
addWidget
(
gameNameFilterEdit
,
0
,
1
);
...
@@ -101,26 +87,26 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &_allGameTypes, QWidget
...
@@ -101,26 +87,26 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &_allGameTypes, QWidget
leftGrid
->
addWidget
(
maxPlayersGroupBox
,
2
,
0
,
1
,
2
);
leftGrid
->
addWidget
(
maxPlayersGroupBox
,
2
,
0
,
1
,
2
);
leftGrid
->
addWidget
(
unavailableGamesVisibleCheckBox
,
3
,
0
,
1
,
2
);
leftGrid
->
addWidget
(
unavailableGamesVisibleCheckBox
,
3
,
0
,
1
,
2
);
leftGrid
->
addWidget
(
passwordProtectedGamesVisibleCheckBox
,
4
,
0
,
1
,
2
);
leftGrid
->
addWidget
(
passwordProtectedGamesVisibleCheckBox
,
4
,
0
,
1
,
2
);
QVBoxLayout
*
leftColumn
=
new
QVBoxLayout
;
QVBoxLayout
*
leftColumn
=
new
QVBoxLayout
;
leftColumn
->
addLayout
(
leftGrid
);
leftColumn
->
addLayout
(
leftGrid
);
leftColumn
->
addStretch
();
leftColumn
->
addStretch
();
QVBoxLayout
*
rightColumn
=
new
QVBoxLayout
;
QVBoxLayout
*
rightColumn
=
new
QVBoxLayout
;
rightColumn
->
addWidget
(
gameTypeFilterGroupBox
);
rightColumn
->
addWidget
(
gameTypeFilterGroupBox
);
QHBoxLayout
*
hbox
=
new
QHBoxLayout
;
QHBoxLayout
*
hbox
=
new
QHBoxLayout
;
hbox
->
addLayout
(
leftColumn
);
hbox
->
addLayout
(
leftColumn
);
hbox
->
addLayout
(
rightColumn
);
hbox
->
addLayout
(
rightColumn
);
QDialogButtonBox
*
buttonBox
=
new
QDialogButtonBox
(
QDialogButtonBox
::
Ok
|
QDialogButtonBox
::
Cancel
);
QDialogButtonBox
*
buttonBox
=
new
QDialogButtonBox
(
QDialogButtonBox
::
Ok
|
QDialogButtonBox
::
Cancel
);
connect
(
buttonBox
,
SIGNAL
(
accepted
()),
this
,
SLOT
(
actOk
()));
connect
(
buttonBox
,
SIGNAL
(
accepted
()),
this
,
SLOT
(
actOk
()));
connect
(
buttonBox
,
SIGNAL
(
rejected
()),
this
,
SLOT
(
reject
()));
connect
(
buttonBox
,
SIGNAL
(
rejected
()),
this
,
SLOT
(
reject
()));
QVBoxLayout
*
mainLayout
=
new
QVBoxLayout
;
QVBoxLayout
*
mainLayout
=
new
QVBoxLayout
;
mainLayout
->
addLayout
(
hbox
);
mainLayout
->
addLayout
(
hbox
);
mainLayout
->
addWidget
(
buttonBox
);
mainLayout
->
addWidget
(
buttonBox
);
setLayout
(
mainLayout
);
setLayout
(
mainLayout
);
setWindowTitle
(
tr
(
"Filter games"
));
setWindowTitle
(
tr
(
"Filter games"
));
}
}
...
...
cockatrice/src/dlg_filter_games.h
View file @
6a4384f9
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#include
<QDialog>
#include
<QDialog>
#include
<QSet>
#include
<QSet>
#include
<QMap>
#include
<QMap>
#include
"gamesmodel.h"
class
QCheckBox
;
class
QCheckBox
;
class
QLineEdit
;
class
QLineEdit
;
...
@@ -21,6 +22,8 @@ private:
...
@@ -21,6 +22,8 @@ private:
QSpinBox
*
maxPlayersFilterMaxSpinBox
;
QSpinBox
*
maxPlayersFilterMaxSpinBox
;
const
QMap
<
int
,
QString
>
&
allGameTypes
;
const
QMap
<
int
,
QString
>
&
allGameTypes
;
// This needs a const someplace
GamesProxyModel
*
gamesProxyModel
;
/*
/*
* The game type might contain special characters, so to use it in
* The game type might contain special characters, so to use it in
...
@@ -30,8 +33,8 @@ private:
...
@@ -30,8 +33,8 @@ private:
private
slots
:
private
slots
:
void
actOk
();
void
actOk
();
public:
public:
DlgFilterGames
(
const
QMap
<
int
,
QString
>
&
allGameTypes
,
QWidget
*
parent
=
0
);
DlgFilterGames
(
const
QMap
<
int
,
QString
>
&
_
allGameTypes
,
GamesProxyModel
*
_gamesProxyModel
,
QWidget
*
parent
=
0
);
bool
getUnavailableGamesVisible
()
const
;
bool
getUnavailableGamesVisible
()
const
;
void
setUnavailableGamesVisible
(
bool
_unavailableGamesVisible
);
void
setUnavailableGamesVisible
(
bool
_unavailableGamesVisible
);
bool
getPasswordProtectedGamesVisible
()
const
;
bool
getPasswordProtectedGamesVisible
()
const
;
...
...
cockatrice/src/gameselector.cpp
View file @
6a4384f9
#include
<QDebug>
#include
<QTreeView>
#include
<QTreeView>
#include
<QCheckBox>
#include
<QCheckBox>
#include
<QPushButton>
#include
<QPushButton>
...
@@ -32,8 +33,17 @@ GameSelector::GameSelector(AbstractClient *_client, const TabSupervisor *_tabSup
...
@@ -32,8 +33,17 @@ GameSelector::GameSelector(AbstractClient *_client, const TabSupervisor *_tabSup
gameListView
->
setRootIsDecorated
(
true
);
gameListView
->
setRootIsDecorated
(
true
);
if
(
_room
)
if
(
_room
)
gameListView
->
header
()
->
hideSection
(
gameListModel
->
roomColIndex
());
gameListView
->
header
()
->
hideSection
(
gameListModel
->
roomColIndex
());
else
gameListProxyModel
->
setUnavailableGamesVisible
(
true
);
GameTypeMap
gameTypeMap
;
if
(
room
)
gameTypeMap
=
gameListModel
->
getGameTypes
().
value
(
room
->
getRoomId
());
gameListProxyModel
->
loadFilterParameters
(
gameTypeMap
);
qDebug
()
<<
"Check unavailable"
<<
gameListProxyModel
->
getUnavailableGamesVisible
();
// set the reset filter button enabled
#if QT_VERSION < 0x050000
#if QT_VERSION < 0x050000
gameListView
->
header
()
->
setResizeMode
(
0
,
QHeaderView
::
ResizeToContents
);
gameListView
->
header
()
->
setResizeMode
(
0
,
QHeaderView
::
ResizeToContents
);
#else
#else
...
@@ -82,16 +92,17 @@ GameSelector::GameSelector(AbstractClient *_client, const TabSupervisor *_tabSup
...
@@ -82,16 +92,17 @@ GameSelector::GameSelector(AbstractClient *_client, const TabSupervisor *_tabSup
void
GameSelector
::
actSetFilter
()
void
GameSelector
::
actSetFilter
()
{
{
GameTypeMap
gameTypeMap
;
GameTypeMap
gameTypeMap
;
if
(
room
)
if
(
room
)
gameTypeMap
=
gameListModel
->
getGameTypes
().
value
(
room
->
getRoomId
());
gameTypeMap
=
gameListModel
->
getGameTypes
().
value
(
room
->
getRoomId
());
DlgFilterGames
dlg
(
gameTypeMap
,
this
);
qDebug
()
<<
"Check unavailable"
<<
gameListProxyModel
->
getUnavailableGamesVisible
();
DlgFilterGames
dlg
(
gameTypeMap
,
gameListProxyModel
,
this
);
if
(
!
dlg
.
exec
())
if
(
!
dlg
.
exec
())
return
;
return
;
clearFilterButton
->
setEnabled
(
true
);
clearFilterButton
->
setEnabled
(
true
);
gameListProxyModel
->
setUnavailableGamesVisible
(
dlg
.
getUnavailableGamesVisible
());
gameListProxyModel
->
setUnavailableGamesVisible
(
dlg
.
getUnavailableGamesVisible
());
gameListProxyModel
->
setPasswordProtectedGamesVisible
(
dlg
.
getPasswordProtectedGamesVisible
());
gameListProxyModel
->
setPasswordProtectedGamesVisible
(
dlg
.
getPasswordProtectedGamesVisible
());
gameListProxyModel
->
setGameNameFilter
(
dlg
.
getGameNameFilter
());
gameListProxyModel
->
setGameNameFilter
(
dlg
.
getGameNameFilter
());
...
@@ -103,7 +114,7 @@ void GameSelector::actSetFilter()
...
@@ -103,7 +114,7 @@ void GameSelector::actSetFilter()
void
GameSelector
::
actClearFilter
()
void
GameSelector
::
actClearFilter
()
{
{
clearFilterButton
->
setEnabled
(
false
);
clearFilterButton
->
setEnabled
(
false
);
gameListProxyModel
->
resetFilterParameters
();
gameListProxyModel
->
resetFilterParameters
();
}
}
...
@@ -136,7 +147,7 @@ void GameSelector::checkResponse(const Response &response)
...
@@ -136,7 +147,7 @@ void GameSelector::checkResponse(const Response &response)
void
GameSelector
::
actJoin
()
void
GameSelector
::
actJoin
()
{
{
bool
spectator
=
sender
()
==
spectateButton
;
bool
spectator
=
sender
()
==
spectateButton
;
QModelIndex
ind
=
gameListView
->
currentIndex
();
QModelIndex
ind
=
gameListView
->
currentIndex
();
if
(
!
ind
.
isValid
())
if
(
!
ind
.
isValid
())
return
;
return
;
...
@@ -149,19 +160,19 @@ void GameSelector::actJoin()
...
@@ -149,19 +160,19 @@ void GameSelector::actJoin()
if
(
!
ok
)
if
(
!
ok
)
return
;
return
;
}
}
Command_JoinGame
cmd
;
Command_JoinGame
cmd
;
cmd
.
set_game_id
(
game
.
game_id
());
cmd
.
set_game_id
(
game
.
game_id
());
cmd
.
set_password
(
password
.
toStdString
());
cmd
.
set_password
(
password
.
toStdString
());
cmd
.
set_spectator
(
spectator
);
cmd
.
set_spectator
(
spectator
);
cmd
.
set_override_restrictions
(
overrideRestrictions
);
cmd
.
set_override_restrictions
(
overrideRestrictions
);
TabRoom
*
r
=
tabSupervisor
->
getRoomTabs
().
value
(
game
.
room_id
());
TabRoom
*
r
=
tabSupervisor
->
getRoomTabs
().
value
(
game
.
room_id
());
if
(
!
r
)
{
if
(
!
r
)
{
QMessageBox
::
critical
(
this
,
tr
(
"Error"
),
tr
(
"Please join the respective room first."
));
QMessageBox
::
critical
(
this
,
tr
(
"Error"
),
tr
(
"Please join the respective room first."
));
return
;
return
;
}
}
PendingCommand
*
pend
=
r
->
prepareRoomCommand
(
cmd
);
PendingCommand
*
pend
=
r
->
prepareRoomCommand
(
cmd
);
connect
(
pend
,
SIGNAL
(
finished
(
Response
,
CommandContainer
,
QVariant
)),
this
,
SLOT
(
checkResponse
(
Response
)));
connect
(
pend
,
SIGNAL
(
finished
(
Response
,
CommandContainer
,
QVariant
)),
this
,
SLOT
(
checkResponse
(
Response
)));
r
->
sendRoomCommand
(
pend
);
r
->
sendRoomCommand
(
pend
);
...
...
cockatrice/src/gamesmodel.cpp
View file @
6a4384f9
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
#include
<QDebug>
#include
<QDebug>
#include
<QStringList>
#include
<QStringList>
#include
<QDateTime>
#include
<QDateTime>
#include
<QSettings>
#include
<QCryptographicHash>
namespace
{
namespace
{
const
unsigned
SECS_PER_MIN
=
60
;
const
unsigned
SECS_PER_MIN
=
60
;
...
@@ -10,7 +12,7 @@ namespace {
...
@@ -10,7 +12,7 @@ namespace {
/**
/**
* Pretty print an integer number of seconds ago. Accurate to only one unit,
* Pretty print an integer number of seconds ago. Accurate to only one unit,
* rounded; <5 minutes and >5 hours are displayed as such. As a special case,
* rounded; <5 minutes and >5 hours are displayed as such. As a special case,
* time between 60 and 90 minutes will display both the hours and minutes.
* time between 60 and 90 minutes will display both the hours and minutes.
*
*
* For example...
* For example...
...
@@ -85,7 +87,7 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
...
@@ -85,7 +87,7 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
QDateTime
then
;
QDateTime
then
;
then
.
setTime_t
(
g
.
start_time
());
then
.
setTime_t
(
g
.
start_time
());
unsigned
int
secs
=
then
.
secsTo
(
QDateTime
::
currentDateTime
());
unsigned
int
secs
=
then
.
secsTo
(
QDateTime
::
currentDateTime
());
switch
(
role
)
{
switch
(
role
)
{
case
Qt
::
DisplayRole
:
return
prettyPrintSecsAgo
(
secs
);
case
Qt
::
DisplayRole
:
return
prettyPrintSecsAgo
(
secs
);
case
SORT_ROLE
:
return
QVariant
(
secs
);
case
SORT_ROLE
:
return
QVariant
(
secs
);
...
@@ -221,8 +223,32 @@ void GamesProxyModel::resetFilterParameters()
...
@@ -221,8 +223,32 @@ void GamesProxyModel::resetFilterParameters()
gameNameFilter
=
QString
();
gameNameFilter
=
QString
();
creatorNameFilter
=
QString
();
creatorNameFilter
=
QString
();
gameTypeFilter
.
clear
();
gameTypeFilter
.
clear
();
maxPlayersFilterMin
=
-
1
;
maxPlayersFilterMin
=
1
;
maxPlayersFilterMax
=
-
1
;
maxPlayersFilterMax
=
99
;
invalidateFilter
();
}
void
GamesProxyModel
::
loadFilterParameters
(
const
QMap
<
int
,
QString
>
&
allGameTypes
)
{
QSettings
settings
;
settings
.
beginGroup
(
"filter_games"
);
unavailableGamesVisible
=
settings
.
value
(
"unavailable_games_visible"
,
false
).
toBool
();
qDebug
()
<<
"Load unavailable = "
<<
unavailableGamesVisible
;
passwordProtectedGamesVisible
=
settings
.
value
(
"password_protected_games_visible"
,
false
).
toBool
();
gameNameFilter
=
settings
.
value
(
"game_name_filter"
,
""
).
toString
();
creatorNameFilter
=
settings
.
value
(
"creator_name_filter"
,
""
).
toString
();
maxPlayersFilterMin
=
settings
.
value
(
"min_players"
,
1
).
toInt
();
maxPlayersFilterMax
=
settings
.
value
(
"max_players"
,
99
).
toInt
();
QMapIterator
<
int
,
QString
>
gameTypesIterator
(
allGameTypes
);
while
(
gameTypesIterator
.
hasNext
())
{
gameTypesIterator
.
next
();
if
(
settings
.
value
(
"game_type/"
+
hashGameType
(
gameTypesIterator
.
value
()),
false
).
toBool
())
{
gameTypeFilter
.
insert
(
gameTypesIterator
.
key
());
}
}
invalidateFilter
();
invalidateFilter
();
}
}
...
@@ -265,3 +291,7 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &/*sourc
...
@@ -265,3 +291,7 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &/*sourc
return
true
;
return
true
;
}
}
QString
GamesProxyModel
::
hashGameType
(
const
QString
&
gameType
)
const
{
return
QCryptographicHash
::
hash
(
gameType
.
toUtf8
(),
QCryptographicHash
::
Md5
).
toHex
();
}
cockatrice/src/gamesmodel.h
View file @
6a4384f9
...
@@ -49,6 +49,12 @@ private:
...
@@ -49,6 +49,12 @@ private:
QString
gameNameFilter
,
creatorNameFilter
;
QString
gameNameFilter
,
creatorNameFilter
;
QSet
<
int
>
gameTypeFilter
;
QSet
<
int
>
gameTypeFilter
;
int
maxPlayersFilterMin
,
maxPlayersFilterMax
;
int
maxPlayersFilterMin
,
maxPlayersFilterMax
;
/*
* The game type might contain special characters, so to use it in
* QSettings we just hash it.
*/
QString
hashGameType
(
const
QString
&
gameType
)
const
;
public:
public:
GamesProxyModel
(
QObject
*
parent
=
0
,
ServerInfo_User
*
_ownUser
=
0
);
GamesProxyModel
(
QObject
*
parent
=
0
,
ServerInfo_User
*
_ownUser
=
0
);
...
@@ -66,6 +72,8 @@ public:
...
@@ -66,6 +72,8 @@ public:
int
getMaxPlayersFilterMax
()
const
{
return
maxPlayersFilterMax
;
}
int
getMaxPlayersFilterMax
()
const
{
return
maxPlayersFilterMax
;
}
void
setMaxPlayersFilter
(
int
_maxPlayersFilterMin
,
int
_maxPlayersFilterMax
);
void
setMaxPlayersFilter
(
int
_maxPlayersFilterMin
,
int
_maxPlayersFilterMax
);
void
resetFilterParameters
();
void
resetFilterParameters
();
void
loadFilterParameters
(
const
QMap
<
int
,
QString
>
&
allGameTypes
);
void
saveFilterParameters
();
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