summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2013-04-26 21:50:40 +0000
committerStijn Buys <ingar@osirion.org>2013-04-26 21:50:40 +0000
commitc9ff1c4b5302440194b8f4f8d200d03b6e263ac4 (patch)
treee11d91ce86aed6f950676ab835b81e74273a7c65 /src
parentfcc2f4044284792ff1c80ab79a084ed97da3f960 (diff)
Updated user interface.
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow.cc22
-rw-r--r--src/mainwindow.h1
-rw-r--r--src/solverwindow.cc36
-rw-r--r--src/sudoku.cc28
4 files changed, 55 insertions, 32 deletions
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index 72b7f60..b929aaa 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -29,13 +29,21 @@ void MainWindow::initActions()
action_load->setStatusTip(tr("Load a previously saved game"));
connect(action_load, SIGNAL(triggered()), mainwindow_solverwindow, SLOT(load()));
+ // Game -> Save
action_save = new QAction(tr("&Save"), this);
action_load->setStatusTip(tr("Save the current game"));
+ //TODO
+ // Game -> Save As
action_saveas = new QAction(tr("Save &As..."), this);
action_load->setStatusTip(tr("Save the current game to a new file"));
connect(action_saveas, SIGNAL(triggered()), mainwindow_solverwindow, SLOT(saveas()));
+ // Game -> Revert
+ action_revert = new QAction(tr("&Revert"), this);
+ action_revert->setStatusTip(tr("Reload the current game from file"));
+ connect(action_revert, SIGNAL(triggered()), mainwindow_solverwindow, SLOT(revert()));
+
// Game -> Quit
action_quit = new QAction(tr("&Quit"), this);
action_quit->setShortcuts(QKeySequence::Quit);
@@ -53,13 +61,13 @@ void MainWindow::initActions()
connect(action_step, SIGNAL(triggered()), mainwindow_solverwindow, SLOT(step()));
// Move -> Solve
- action_solve = new QAction(tr("Solve"), this);
- action_solve->setStatusTip(tr("Solve sudoku constraints"));
+ action_solve = new QAction(tr("Solve rules"), this);
+ action_solve->setStatusTip(tr("Solve sudoku rules"));
connect(action_solve, SIGNAL(triggered()), mainwindow_solverwindow, SLOT(solve()));
// Move -> Search
- action_search = new QAction(tr("Search"), this);
- action_search->setStatusTip(tr("Search for a solution"));
+ action_search = new QAction(tr("Find solution"), this);
+ action_search->setStatusTip(tr("Find a solution"));
connect(action_search, SIGNAL(triggered()), mainwindow_solverwindow, SLOT(search()));
}
@@ -69,12 +77,14 @@ void MainWindow::initMenus()
mainwindow_gamemenu->addAction(action_new);
mainwindow_gamemenu->addAction(action_load);
mainwindow_gamemenu->addSeparator();
- mainwindow_gamemenu->addAction(action_save);
+ //mainwindow_gamemenu->addAction(action_save);
mainwindow_gamemenu->addAction(action_saveas);
+ mainwindow_gamemenu->addAction(action_revert);
+ mainwindow_gamemenu->addSeparator();
mainwindow_gamemenu->addAction(action_quit);
mainwindow_movemenu = menuBar()->addMenu(tr("&Move"));
- mainwindow_movemenu->addAction(action_hint);
+ //mainwindow_movemenu->addAction(action_hint);
mainwindow_movemenu->addAction(action_step);
mainwindow_movemenu->addAction(action_solve);
mainwindow_movemenu->addAction(action_search);
diff --git a/src/mainwindow.h b/src/mainwindow.h
index f18e6df..2467f25 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -31,6 +31,7 @@ private:
QAction *action_load;
QAction *action_save;
QAction *action_saveas;
+ QAction *action_revert;
QAction *action_quit;
// Move menu actions
diff --git a/src/solverwindow.cc b/src/solverwindow.cc
index e7f4633..9947d5d 100644
--- a/src/solverwindow.cc
+++ b/src/solverwindow.cc
@@ -24,7 +24,10 @@ SolverWindow::SolverWindow()
// sidebar
- QVBoxLayout *sidebarlayout = new QVBoxLayout();
+ QVBoxLayout *sidebarlayout = new QVBoxLayout();
+
+ // add stretch
+ sidebarlayout->addStretch(1);
// add load button
QPushButton *loadbutton = new QPushButton(tr("Load"));
@@ -40,30 +43,38 @@ SolverWindow::SolverWindow()
QPushButton *revertbutton = new QPushButton(tr("Revert"));
sidebarlayout->addWidget(revertbutton);
connect(revertbutton, SIGNAL(clicked()), this, SLOT(revert()));
-
- // add step constraints button
- QPushButton *stepconstraintsbutton = new QPushButton(tr("Constraints"));
- sidebarlayout->addWidget(stepconstraintsbutton);
- connect(stepconstraintsbutton, SIGNAL(clicked()), this, SLOT(step_constraints()));
- // add step coverage button
- QPushButton *stepcoveragebutton = new QPushButton(tr("Coverage"));
- sidebarlayout->addWidget(stepcoveragebutton);
- connect(stepcoveragebutton, SIGNAL(clicked()), this, SLOT(step_coverage()));
-
// add validate button
QPushButton *validatebutton = new QPushButton(tr("Validate"));
sidebarlayout->addWidget(validatebutton);
connect(validatebutton, SIGNAL(clicked()), this, SLOT(validate()));
+ // add a step button
+ QPushButton *stepbutton = new QPushButton(tr("Step"));
+ sidebarlayout->addWidget(stepbutton);
+ connect(stepbutton, SIGNAL(clicked()), this, SLOT(step()));
+
// add stretch
- sidebarlayout->addStretch(1);
+ sidebarlayout->addStretch(2);
+
+ // add a solve button
+ QPushButton *solvebutton = new QPushButton(tr("Solve"));
+ sidebarlayout->addWidget(solvebutton);
+ connect(solvebutton, SIGNAL(clicked()), this, SLOT(solve()));
+
+ // add a search button
+ QPushButton *searchbutton = new QPushButton(tr("Search"));
+ sidebarlayout->addWidget(searchbutton);
+ connect(searchbutton, SIGNAL(clicked()), this, SLOT(search()));
// add clear button
QPushButton *clearbutton = new QPushButton(tr("Clear"));
sidebarlayout->addWidget(clearbutton);
connect(clearbutton, SIGNAL(clicked()), this, SLOT(clear()));
+ // add stretch
+ sidebarlayout->addStretch(1);
+
// add sidebar layout
windowlayout->addLayout(sidebarlayout);
@@ -119,6 +130,7 @@ void SolverWindow::load()
void SolverWindow::revert()
{
+ // FIXME this should actually re-load the savegame
solverwindow_sudokuwidget->set_values(solverwindow_revertstate);
}
diff --git a/src/sudoku.cc b/src/sudoku.cc
index 6a01faa..d40a8c8 100644
--- a/src/sudoku.cc
+++ b/src/sudoku.cc
@@ -337,23 +337,23 @@ int Sudoku::solve_search()
bool Sudoku::solve_search_step(int &iterations, Sudoku & solution)
{
+ qDebug() << "iteration " << iterations;
+ for (int row = 0; row < 9; row ++) {
+ qDebug()
+ << cell(row, 0).value()
+ << cell(row, 1).value()
+ << cell(row, 2).value()
+ << cell(row, 3).value()
+ << cell(row, 4).value()
+ << cell(row, 5).value()
+ << cell(row, 6).value()
+ << cell(row, 7).value()
+ << cell(row, 8).value();
+ }
+
if (solved()) {
solution.assign((*this));
return true;
- } else {
- qDebug() << "iteration " << iterations;
- for (int row = 0; row < 9; row ++) {
- qDebug()
- << cell(row, 0).value()
- << cell(row, 1).value()
- << cell(row, 2).value()
- << cell(row, 3).value()
- << cell(row, 4).value()
- << cell(row, 5).value()
- << cell(row, 6).value()
- << cell(row, 7).value()
- << cell(row, 8).value();
- }
}
// find a random empty cell