blob: 7d756ae7d7b3bbf4606167469f18f174e2881a10 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#include "sudokuwidget.h"
#include <QLineEdit>
#include <QGridLayout>
#include <QString>
SudokuWidget::SudokuWidget()
{
QGridLayout *gridlayout = new QGridLayout();
for (int row = 0; row < 9; row++) {
for (int column = 0; column < 9 ; column++) {
sudokuwidget_value[row][column] = new QLineEdit();
sudokuwidget_value[row][column]->setFrame(false);
sudokuwidget_value[row][column]->setAlignment(Qt::AlignCenter);
gridlayout->addWidget(sudokuwidget_value[row][column], row, column);
}
}
setLayout(gridlayout);
}
QSize SudokuWidget::sizeHint () const
{
return QSize(512, 512);
}
void SudokuWidget::set_values(const Sudoku & values)
{
for (int row = 0; row < 9; row++) {
for (int column = 0; column < 9 ; column++) {
int i = values.value(row, column);
if (i > 0) {
QString str = QString::number(i);
sudokuwidget_value[row][column]->setText(str);
} else {
sudokuwidget_value[row][column]->clear();
}
}
}
}
void SudokuWidget::get_values(Sudoku & values)
{
for (int row = 0; row < 9; row++) {
for (int column = 0; column < 9 ; column++) {
bool ok;
QString str(sudokuwidget_value[row][column]->text());
int i = str.toInt(&ok);
if (ok && (i > 0) && (i <= 9)) {
values.set_value(row, column, i);
} else {
values.set_value(row, column, 0);
}
}
}
}
|