31 |
#include "queensmain.h" |
#include "queensmain.h" |
32 |
#include "board.h" |
#include "board.h" |
33 |
#include "queens.h" |
#include "queens.h" |
34 |
|
|
35 |
#include "solution.h" |
#include "solution.h" |
36 |
#include "solutionvector.h" |
#include "solutionmatrix.h" |
37 |
#include "solutionlist.h" |
#include "solutionint.h" |
38 |
#include "solutionhash.h" |
|
39 |
#include "solutionmnvector.h" |
#include "containervector.h" |
40 |
|
#include "containerlist.h" |
41 |
|
#include "containerhash.h" |
42 |
|
#include "containermnvector.h" |
43 |
|
|
44 |
#include "config.h" |
#include "config.h" |
45 |
|
|
46 |
#define MatrixSolution Solution |
|
47 |
|
|
48 |
QueensMain::QueensMain(QWidget *parent, const char *name) |
QueensMain::QueensMain(QWidget *parent, const char *name) |
49 |
: QDialog(parent, name) |
: QDialog(parent, name) |
86 |
m_sortalgo = SortList; |
m_sortalgo = SortList; |
87 |
m_solutions = NULL; |
m_solutions = NULL; |
88 |
m_queens = NULL; |
m_queens = NULL; |
89 |
|
m_sol = NULL; |
90 |
|
|
91 |
connect(m_quit, |
connect(m_quit, |
92 |
SIGNAL( clicked() ), |
SIGNAL( clicked() ), |
129 |
QueensMain::~QueensMain() |
QueensMain::~QueensMain() |
130 |
{ |
{ |
131 |
delete m_board; |
delete m_board; |
132 |
|
|
133 |
|
if (m_solutions != NULL) |
134 |
|
delete m_solutions; |
135 |
|
if (m_sol != NULL) |
136 |
|
delete m_sol; |
137 |
} |
} |
138 |
|
|
139 |
void QueensMain::start() |
void QueensMain::start() |
144 |
m_list->clear(); |
m_list->clear(); |
145 |
m_status->setText( QString("Searching ...") ); |
m_status->setText( QString("Searching ...") ); |
146 |
|
|
147 |
|
m_board->setMatrix(0); |
148 |
|
|
149 |
if (m_queens != NULL) { |
if (m_queens != NULL) { |
150 |
m_queens->wait(); |
m_queens->wait(); |
151 |
delete m_queens; |
delete m_queens; |
152 |
|
m_queens = 0; |
153 |
} |
} |
154 |
|
|
155 |
if (m_solutions != NULL) |
if (m_solutions != NULL) |
156 |
delete m_solutions; |
delete m_solutions; |
157 |
switch (m_sortalgo) { |
switch (m_sortalgo) { |
158 |
case SortList: |
case SortList: |
159 |
m_solutions = new SolutionList(this); |
m_solutions = new ContainerList(this); |
160 |
break; |
break; |
161 |
case SortVector: |
case SortVector: |
162 |
m_solutions = new SolutionVector(this); |
m_solutions = new ContainerVector(this); |
163 |
break; |
break; |
164 |
case SortHash: |
case SortHash: |
165 |
m_solutions = new SolutionHash(this); |
m_solutions = new ContainerHash(this); |
166 |
break; |
break; |
167 |
case SortMNVector: |
case SortMNVector: |
168 |
m_solutions = new SolutionMNVector(this); |
m_solutions = new ContainerMNVector(this); |
169 |
break; |
break; |
170 |
} |
} |
171 |
|
|
174 |
|
|
175 |
switch(this->m_storage) { |
switch(this->m_storage) { |
176 |
case StorageInt: |
case StorageInt: |
177 |
#warning MatrixSolution<=>IntSolution |
m_sol = new SolutionInt(m_sizeSelector->value()); |
|
m_sol = new MatrixSolution(m_sizeSelector->value()); |
|
178 |
break; |
break; |
179 |
case StorageMatrix: |
case StorageMatrix: |
180 |
m_sol = new MatrixSolution(m_sizeSelector->value()); |
m_sol = new SolutionMatrix(m_sizeSelector->value()); |
181 |
break; |
break; |
182 |
} |
} |
183 |
|
|
184 |
|
|
185 |
m_elapsed.start(); |
m_elapsed.start(); |
186 |
m_time.start(); |
m_time.start(); |
187 |
m_queens = new Queens(this, m_solutions, m_sizeSelector->value() ,false); |
m_queens = new Queens(this, m_sol, m_solutions, m_sizeSelector->value() ,false); |
188 |
m_queens->start(); |
m_queens->start(); |
189 |
} |
} |
190 |
|
|
232 |
{ |
{ |
233 |
int index = m_list->currentItem(); |
int index = m_list->currentItem(); |
234 |
Solution* sol = m_solutions->solution( index ); |
Solution* sol = m_solutions->solution( index ); |
235 |
m_board->setMatrix( *sol ); |
m_board->setMatrix( sol ); |
236 |
} |
} |
237 |
|
|
238 |
void QueensMain::resize(int size) |
void QueensMain::resize(int size) |