27 |
#include <qstring.h> |
#include <qstring.h> |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
#include "queensmain.h" |
#include "queensmain.h" |
32 |
#include "board.h" |
#include "board.h" |
33 |
#include "queens.h" |
#include "queens.h" |
34 |
#include "solutionvector.h" |
|
35 |
#include "solutionlist.h" |
#include "solution.h" |
36 |
#include "solutionhash.h" |
#include "solutionmatrix.h" |
37 |
#include "solutionmnvector.h" |
#include "solutionint.h" |
38 |
|
|
39 |
|
#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 |
|
|
47 |
|
|
48 |
QueensMain::QueensMain(QWidget *parent, const char *name) |
QueensMain::QueensMain(QWidget *parent, const char *name) |
49 |
: QDialog(parent, name) |
: QDialog(parent, name) |
50 |
{ |
{ |
82 |
m_sizeSelector->setValue( 8 ); |
m_sizeSelector->setValue( 8 ); |
83 |
m_board->setSize( 8 ); |
m_board->setSize( 8 ); |
84 |
|
|
85 |
|
m_storage = StorageMatrix; |
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() ), |
139 |
m_list->clear(); |
m_list->clear(); |
140 |
m_status->setText( QString("Searching ...") ); |
m_status->setText( QString("Searching ...") ); |
141 |
|
|
142 |
|
m_board->setMatrix(0); |
143 |
|
|
144 |
if (m_queens != NULL) { |
if (m_queens != NULL) { |
145 |
m_queens->wait(); |
m_queens->wait(); |
146 |
delete m_queens; |
delete m_queens; |
150 |
delete m_solutions; |
delete m_solutions; |
151 |
switch (m_sortalgo) { |
switch (m_sortalgo) { |
152 |
case SortList: |
case SortList: |
153 |
m_solutions = new SolutionList(this); |
m_solutions = new ContainerList(this); |
154 |
break; |
break; |
155 |
case SortVector: |
case SortVector: |
156 |
m_solutions = new SolutionVector(this); |
m_solutions = new ContainerVector(this); |
157 |
break; |
break; |
158 |
case SortHash: |
case SortHash: |
159 |
m_solutions = new SolutionHash(this); |
m_solutions = new ContainerHash(this); |
160 |
break; |
break; |
161 |
case SortMNVector: |
case SortMNVector: |
162 |
m_solutions = new SolutionMNVector(this); |
m_solutions = new ContainerMNVector(this); |
163 |
break; |
break; |
164 |
} |
} |
165 |
|
|
166 |
|
if (m_sol != NULL) |
167 |
|
delete m_sol; |
168 |
|
|
169 |
|
switch(this->m_storage) { |
170 |
|
case StorageInt: |
171 |
|
m_sol = new SolutionInt(m_sizeSelector->value()); |
172 |
|
break; |
173 |
|
case StorageMatrix: |
174 |
|
m_sol = new SolutionMatrix(m_sizeSelector->value()); |
175 |
|
break; |
176 |
|
} |
177 |
|
|
178 |
|
|
179 |
m_elapsed.start(); |
m_elapsed.start(); |
180 |
m_time.start(); |
m_time.start(); |
181 |
m_queens = new Queens(this, m_solutions, m_sizeSelector->value() ,false); |
m_queens = new Queens(this, m_sol, m_solutions, m_sizeSelector->value() ,false); |
182 |
m_queens->start(); |
m_queens->start(); |
183 |
} |
} |
184 |
|
|
225 |
void QueensMain::showSolution() |
void QueensMain::showSolution() |
226 |
{ |
{ |
227 |
int index = m_list->currentItem(); |
int index = m_list->currentItem(); |
228 |
Solution sol = m_solutions->solution( index ); |
Solution* sol = m_solutions->solution( index ); |
229 |
m_board->setMatrix( sol ); |
m_board->setMatrix( sol ); |
230 |
} |
} |
231 |
|
|
279 |
{ |
{ |
280 |
QPopupMenu *contextMenu = new QPopupMenu( this ); |
QPopupMenu *contextMenu = new QPopupMenu( this ); |
281 |
contextMenu->setCheckable( true ); |
contextMenu->setCheckable( true ); |
282 |
QLabel *caption = new QLabel("<b><i>Sort algorithm</i></b>", this); |
QLabel *sortCaption = new QLabel("<b><i>Sort algorithm</i></b>", this); |
283 |
caption->setAlignment( Qt::AlignCenter ); |
sortCaption->setAlignment( Qt::AlignCenter ); |
284 |
contextMenu->insertItem( caption ); |
contextMenu->insertItem( sortCaption ); |
285 |
|
|
286 |
contextMenu->insertItem("List", this, SLOT( sortList() ), 0, 1); |
contextMenu->insertItem("List", this, SLOT( sortList() ), 0, 1); |
287 |
contextMenu->insertItem("Vector", this, SLOT( sortVector() ), 0, 2); |
contextMenu->insertItem("Vector", this, SLOT( sortVector() ), 0, 2); |
288 |
contextMenu->insertItem("Hash", this, SLOT( sortHash() ), 0, 3); |
contextMenu->insertItem("Hash", this, SLOT( sortHash() ), 0, 3); |
289 |
contextMenu->insertItem("M*N Vector", this, SLOT(sortMNVector()), 0, 4); |
contextMenu->insertItem("M*N Vector", this, SLOT(sortMNVector()), 0, 4); |
290 |
|
|
291 |
|
QLabel *storageCaption = new QLabel("<b><i>Storage class</i></b>", this); |
292 |
|
contextMenu->insertItem( storageCaption ); |
293 |
|
contextMenu->insertItem("Matrix Solution", this, SLOT( storageMatrix() ), 0, 5); |
294 |
|
contextMenu->insertItem("Int Solution", this, SLOT( storageInt() ), 0, 6); |
295 |
|
|
296 |
|
|
297 |
switch (m_sortalgo) { |
switch (m_sortalgo) { |
298 |
case SortList: |
case SortList: |
309 |
break; |
break; |
310 |
} |
} |
311 |
|
|
312 |
|
switch (m_storage) { |
313 |
|
case StorageMatrix: |
314 |
|
contextMenu->setItemChecked(5, true); |
315 |
|
break; |
316 |
|
case StorageInt: |
317 |
|
contextMenu->setItemChecked(6, true); |
318 |
|
break; |
319 |
|
} |
320 |
|
|
321 |
|
|
322 |
contextMenu->exec( event->globalPos() ); |
contextMenu->exec( event->globalPos() ); |
323 |
delete contextMenu; |
delete contextMenu; |
324 |
} |
} |
355 |
m_sortalgo = SortMNVector; |
m_sortalgo = SortMNVector; |
356 |
} |
} |
357 |
|
|
358 |
|
void QueensMain::storageInt() |
359 |
|
{ |
360 |
|
m_storage = StorageInt; |
361 |
|
} |
362 |
|
|
363 |
|
void QueensMain::storageMatrix() |
364 |
|
{ |
365 |
|
m_storage = StorageMatrix; |
366 |
|
} |
367 |
|
|
368 |
|
|