Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Games
KSudoku
Commits
043033ff
Commit
043033ff
authored
Sep 10, 2021
by
Laurent Montel
Browse files
Modernize code
parent
5341ac76
Changes
9
Hide whitespace changes
Inline
Side-by-side
src/generator/sudokuboard.h
View file @
043033ff
...
...
@@ -27,13 +27,13 @@
#include
<QObject>
#include
<QStack>
typedef
qint32
Pair
;
// Two small integers packed into one.
using
Pair
=
qint32
;
// Two small integers packed into one.
typedef
Pair
Move
;
typedef
QList
<
Move
>
MoveList
;
using
Move
=
Pair
;
using
MoveList
=
QList
<
Move
>
;
typedef
Move
Guess
;
typedef
MoveList
Guesses
List
;
using
Guess
=
Move
;
using
GuessesList
=
Move
List
;
enum
GuessingMode
{
Random
,
NotRandom
};
...
...
src/globals.h
View file @
043033ff
...
...
@@ -36,12 +36,12 @@ enum Symmetry {DIAGONAL_1, CENTRAL, LEFT_RIGHT, SPIRAL, FOURWAY,
enum
CageOperator
{
NoOperator
,
Divide
,
Subtract
,
Multiply
,
Add
};
typedef
QVector
<
int
>
BoardContents
;
using
BoardContents
=
QVector
<
int
>
;
// The maximum digit that can be used in a Mathdoku or Killer Sudoku puzzle.
const
int
MaxMathOrder
=
9
;
typedef
struct
{
using
Statistics
=
struct
{
char
*
typeName
;
SudokuType
type
;
int
blockSize
;
...
...
@@ -57,6 +57,6 @@ typedef struct {
int
firstGuessAt
;
float
rating
;
Difficulty
difficulty
;
}
Statistics
;
};
#endif // GLOBALS_H
src/gui/gamevariants.cpp
View file @
043033ff
...
...
@@ -98,7 +98,7 @@ QVariant GameVariantCollection::data(const QModelIndex &index, int role) const {
if
(
!
index
.
internalPointer
())
return
QVariant
();
GameVariant
*
gameVariant
=
static_cast
<
GameVariant
*>
(
index
.
internalPointer
());
auto
*
gameVariant
=
static_cast
<
GameVariant
*>
(
index
.
internalPointer
());
switch
(
role
)
{
case
Qt
::
DisplayRole
:
...
...
@@ -239,7 +239,7 @@ QString GameVariantDelegate::icon(const QModelIndex& index) const {
}
bool
GameVariantDelegate
::
configurable
(
const
QModelIndex
&
index
)
const
{
const
GameVariantCollection
*
collection
=
dynamic_cast
<
const
GameVariantCollection
*>
(
index
.
model
());
const
auto
*
collection
=
dynamic_cast
<
const
GameVariantCollection
*>
(
index
.
model
());
if
(
!
collection
)
return
false
;
return
collection
->
variant
(
index
)
->
canConfigure
();
...
...
@@ -290,7 +290,7 @@ Game SudokuGame::startEmpty() {
m_graph
->
initSudoku
();
}
Puzzle
*
puzzle
=
new
Puzzle
(
m_graph
,
false
);
auto
*
puzzle
=
new
Puzzle
(
m_graph
,
false
);
puzzle
->
init
();
return
Game
(
puzzle
);
...
...
@@ -302,7 +302,7 @@ Game SudokuGame::createGame(int difficulty, int symmetry) {
m_graph
->
initSudoku
();
}
Puzzle
*
puzzle
=
new
Puzzle
(
m_graph
,
true
);
auto
*
puzzle
=
new
Puzzle
(
m_graph
,
true
);
puzzle
->
init
(
difficulty
,
symmetry
);
return
Game
(
puzzle
);
...
...
@@ -347,7 +347,7 @@ Game RoxdokuGame::startEmpty() {
m_graph
->
initRoxdoku
();
}
Puzzle
*
puzzle
=
new
Puzzle
(
m_graph
,
false
);
auto
*
puzzle
=
new
Puzzle
(
m_graph
,
false
);
puzzle
->
init
();
return
Game
(
puzzle
);
...
...
@@ -359,7 +359,7 @@ Game RoxdokuGame::createGame(int difficulty, int symmetry) {
m_graph
->
initRoxdoku
();
}
Puzzle
*
puzzle
=
new
Puzzle
(
m_graph
,
true
);
auto
*
puzzle
=
new
Puzzle
(
m_graph
,
true
);
puzzle
->
init
(
difficulty
,
symmetry
);
return
Game
(
puzzle
);
...
...
@@ -402,7 +402,7 @@ Game CustomGame::startEmpty() {
if
(
!
createSKGraphObject
())
{
return
Game
();
}
Puzzle
*
puzzle
=
new
Puzzle
(
m_graph
,
false
);
auto
*
puzzle
=
new
Puzzle
(
m_graph
,
false
);
puzzle
->
init
();
return
Game
(
puzzle
);
...
...
@@ -412,7 +412,7 @@ Game CustomGame::createGame(int difficulty, int symmetry) {
if
(
!
createSKGraphObject
())
{
return
Game
();
}
Puzzle
*
puzzle
=
new
Puzzle
(
m_graph
,
true
);
auto
*
puzzle
=
new
Puzzle
(
m_graph
,
true
);
puzzle
->
init
(
difficulty
,
symmetry
);
return
Game
(
puzzle
);
...
...
src/gui/ksudoku.cpp
View file @
043033ff
...
...
@@ -122,14 +122,14 @@ KSudoku::KSudoku()
:
KXmlGuiWindow
(),
m_gameVariants
(
new
GameVariantCollection
(
this
,
true
)),
m_puzzlePrinter
(
0
)
m_puzzlePrinter
(
nullptr
)
{
setObjectName
(
QStringLiteral
(
"ksudoku"
));
m_gameWidget
=
0
;
m_gameUI
=
0
;
m_gameWidget
=
nullptr
;
m_gameUI
=
nullptr
;
m_gameActions
=
0
;
m_gameActions
=
nullptr
;
// then, setup our actions
setupActions
();
...
...
@@ -172,7 +172,7 @@ KSudoku::~KSudoku()
void
KSudoku
::
updateShapesList
()
{
// TODO clear the list
GameVariant
*
variant
=
0
;
GameVariant
*
variant
=
nullptr
;
variant
=
new
SudokuGame
(
i18n
(
"Sudoku Standard (9x9)"
),
9
,
m_gameVariants
);
variant
->
setDescription
(
i18n
(
"The classic and fashionable game"
));
...
...
@@ -236,7 +236,7 @@ void KSudoku::startGame(const Game& game) {
endCurrentGame
();
KsView
*
view
=
new
KsView
(
game
,
m_gameActions
,
this
);
auto
*
view
=
new
KsView
(
game
,
m_gameActions
,
this
);
view
->
setValueListWidget
(
m_valueListWidget
);
view
->
createView
();
...
...
@@ -352,7 +352,7 @@ void KSudoku::endCurrentGame() {
m_valueListWidget
->
hide
();
delete
m_gameUI
;
m_gameUI
=
0
;
m_gameUI
=
nullptr
;
adaptActions2View
();
...
...
@@ -466,7 +466,7 @@ void KSudoku::setupActions()
KStandardAction
::
preferences
(
this
,
SLOT
(
optionsPreferences
()),
actionCollection
());
// Settings: enable messages that the user marked "Do not show again".
QAction
*
enableMessagesAct
=
new
QAction
(
i18n
(
"Enable all messages"
),
this
);
auto
*
enableMessagesAct
=
new
QAction
(
i18n
(
"Enable all messages"
),
this
);
actionCollection
()
->
addAction
(
QStringLiteral
(
"enable_messages"
),
enableMessagesAct
);
connect
(
enableMessagesAct
,
&
QAction
::
triggered
,
this
,
&
KSudoku
::
enableMessages
);
...
...
@@ -522,7 +522,7 @@ void KSudoku::setupStatusBar (int difficulty, int symmetry)
// Set up a combo box for symmetry of puzzle layout.
statusBar
()
->
addPermanentWidget
(
new
QLabel
(
i18nc
(
"@option drop down box"
,
"Symmetry:"
)));
QComboBox
*
symmetryBox
=
new
QComboBox
(
this
);
auto
*
symmetryBox
=
new
QComboBox
(
this
);
QObject
::
connect
(
symmetryBox
,
static_cast
<
void
(
QComboBox
::*
)(
int
)
>
(
&
QComboBox
::
activated
),
this
,
&
KSudoku
::
symmetryChanged
);
symmetryBox
->
setToolTip
(
i18nc
(
"Symmetry of layout of clues when puzzle starts"
,
"Symmetry"
));
...
...
@@ -781,9 +781,9 @@ void KSudoku::optionsPreferences()
{
if
(
KConfigDialog
::
showDialog
(
QStringLiteral
(
"settings"
))
)
return
;
KConfigDialog
*
dialog
=
new
KConfigDialog
(
this
,
QStringLiteral
(
"settings"
),
Settings
::
self
());
auto
*
dialog
=
new
KConfigDialog
(
this
,
QStringLiteral
(
"settings"
),
Settings
::
self
());
GameConfig
*
gameConfig
=
new
GameConfig
();
auto
*
gameConfig
=
new
GameConfig
();
dialog
->
addPage
(
gameConfig
,
i18nc
(
"Game Section in Config"
,
"Game"
),
QStringLiteral
(
"games-config-options"
));
dialog
->
addPage
(
new
KGameThemeSelector
(
dialog
,
Settings
::
self
(),
KGameThemeSelector
::
NewStuffDisableDownload
),
i18n
(
"Theme"
),
QStringLiteral
(
"games-config-theme"
));
...
...
src/gui/puzzleprinter.cpp
View file @
043033ff
...
...
@@ -117,7 +117,7 @@ bool PuzzlePrinter::setupOutputDevices (int leastCellsToFit, int puzzleWidth)
// NOTE: Must create painter before using functions like m_printer->width().
if
(
m_printer
==
0
)
{
m_printer
=
new
QPrinter
(
QPrinter
::
HighResolution
);
QPrintDialog
*
dialog
=
new
QPrintDialog
(
m_printer
,
m_parent
);
auto
*
dialog
=
new
QPrintDialog
(
m_printer
,
m_parent
);
dialog
->
setWindowTitle
(
i18n
(
"Print Sudoku Puzzle"
));
if
(
dialog
->
exec
()
!=
QDialog
::
Accepted
)
{
delete
m_printer
;
...
...
src/gui/serializer.cpp
View file @
043033ff
...
...
@@ -147,7 +147,7 @@ Puzzle* Serializer::deserializePuzzle(const QDomElement &element) {
return
0
;
}
Puzzle
*
puzzle
=
new
Puzzle
(
graph
,
hasSolution
);
auto
*
puzzle
=
new
Puzzle
(
graph
,
hasSolution
);
BoardContents
values
;
values
.
resize
(
graph
->
size
());
...
...
@@ -200,11 +200,11 @@ SKGraph* Serializer::deserializeGraph(const QDomElement &element) {
return
0
;
if
(
type
==
QLatin1String
(
"sudoku"
))
{
SKGraph
*
graph
=
new
SKGraph
(
order
,
TypeSudoku
);
auto
*
graph
=
new
SKGraph
(
order
,
TypeSudoku
);
graph
->
initSudoku
();
return
graph
;
}
else
if
(
type
==
QLatin1String
(
"roxdoku"
))
{
SKGraph
*
graph
=
new
SKGraph
(
order
,
TypeRoxdoku
);
auto
*
graph
=
new
SKGraph
(
order
,
TypeRoxdoku
);
graph
->
initRoxdoku
();
return
graph
;
}
else
if
(
type
==
QLatin1String
(
"custom"
))
{
...
...
@@ -241,7 +241,7 @@ SKGraph* Serializer::deserializeGraph(const QDomElement &element) {
if
(
err
==
1
)
return
0
;
if
(
sizeX
<
1
||
sizeY
<
1
||
sizeZ
<
1
)
return
0
;
SKGraph
*
graph
=
new
SKGraph
(
order
,
TypeCustom
);
auto
*
graph
=
new
SKGraph
(
order
,
TypeCustom
);
graph
->
initCustom
(
name
,
puzzleType
,
order
,
sizeX
,
sizeY
,
sizeZ
,
ncliques
);
...
...
src/gui/views/ksview.h
View file @
043033ff
...
...
@@ -36,7 +36,7 @@ enum ViewFlag {
ShowHighlights
=
0x04
};
typedef
QFlags
<
ViewFlag
>
ViewFlags
;
using
ViewFlags
=
QFlags
<
ViewFlag
>
;
class
Game
;
struct
SymbolTable
;
...
...
src/logic/puzzle.cpp
View file @
043033ff
...
...
@@ -63,7 +63,7 @@ bool Puzzle::init() {
bool
Puzzle
::
init
(
int
difficulty
,
int
symmetry
)
{
if
(
m_initialized
)
return
false
;
SudokuBoard
*
board
=
new
SudokuBoard
(
m_graph
);
auto
*
board
=
new
SudokuBoard
(
m_graph
);
// Generate a puzzle and its solution.
bool
success
=
board
->
generatePuzzle
(
m_puzzle
,
m_solution
,
...
...
@@ -90,7 +90,7 @@ int Puzzle::init(const BoardContents & values) {
m_hintList
.
clear
();
if
((
t
!=
Mathdoku
)
&&
(
t
!=
KillerSudoku
))
{
SudokuBoard
*
board
=
new
SudokuBoard
(
m_graph
);
auto
*
board
=
new
SudokuBoard
(
m_graph
);
m_solution
=
board
->
solveBoard
(
m_puzzle
);
// Get SudokuBoard to check the solution.
...
...
src/main.cpp
View file @
043033ff
...
...
@@ -87,7 +87,7 @@ int main(int argc, char **argv)
}
else
{*/
KSudoku
*
widget
=
new
KSudoku
;
auto
*
widget
=
new
KSudoku
;
widget
->
show
();
// no session.. just start up normally
...
...
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