--- queensgui/src/queensmain.cpp 2007/07/19 22:26:42 2
+++ queensgui/src/queensmain.cpp 2007/07/20 16:58:04 8
@@ -31,15 +31,19 @@
#include "queensmain.h"
#include "board.h"
#include "queens.h"
+
#include "solution.h"
-#include "solutionvector.h"
-#include "solutionlist.h"
-#include "solutionhash.h"
-#include "solutionmnvector.h"
+#include "solutionmatrix.h"
+#include "solutionint.h"
+
+#include "containervector.h"
+#include "containerlist.h"
+#include "containerhash.h"
+#include "containermnvector.h"
#include "config.h"
-#define MatrixSolution Solution
+
QueensMain::QueensMain(QWidget *parent, const char *name)
: QDialog(parent, name)
@@ -82,6 +86,7 @@
m_sortalgo = SortList;
m_solutions = NULL;
m_queens = NULL;
+ m_sol = NULL;
connect(m_quit,
SIGNAL( clicked() ),
@@ -124,6 +129,11 @@
QueensMain::~QueensMain()
{
delete m_board;
+
+ if (m_solutions != NULL)
+ delete m_solutions;
+ if (m_sol != NULL)
+ delete m_sol;
}
void QueensMain::start()
@@ -134,25 +144,28 @@
m_list->clear();
m_status->setText( QString("Searching ...") );
+ m_board->setMatrix(0);
+
if (m_queens != NULL) {
m_queens->wait();
delete m_queens;
+ m_queens = 0;
}
if (m_solutions != NULL)
delete m_solutions;
switch (m_sortalgo) {
case SortList:
- m_solutions = new SolutionList(this);
+ m_solutions = new ContainerList(this);
break;
case SortVector:
- m_solutions = new SolutionVector(this);
+ m_solutions = new ContainerVector(this);
break;
case SortHash:
- m_solutions = new SolutionHash(this);
+ m_solutions = new ContainerHash(this);
break;
case SortMNVector:
- m_solutions = new SolutionMNVector(this);
+ m_solutions = new ContainerMNVector(this);
break;
}
@@ -161,18 +174,17 @@
switch(this->m_storage) {
case StorageInt:
- #warning MatrixSolution<=>IntSolution
- m_sol = new MatrixSolution(m_sizeSelector->value());
+ m_sol = new SolutionInt(m_sizeSelector->value());
break;
case StorageMatrix:
- m_sol = new MatrixSolution(m_sizeSelector->value());
+ m_sol = new SolutionMatrix(m_sizeSelector->value());
break;
}
m_elapsed.start();
m_time.start();
- m_queens = new Queens(this, m_solutions, m_sizeSelector->value() ,false);
+ m_queens = new Queens(this, m_sol, m_solutions, m_sizeSelector->value() ,false);
m_queens->start();
}
@@ -220,7 +232,7 @@
{
int index = m_list->currentItem();
Solution* sol = m_solutions->solution( index );
- m_board->setMatrix( *sol );
+ m_board->setMatrix( sol );
}
void QueensMain::resize(int size)
@@ -273,7 +285,7 @@
{
QPopupMenu *contextMenu = new QPopupMenu( this );
contextMenu->setCheckable( true );
- QLabel *sortCaption = new QLabel("Sort algorithm", this);
+ QLabel *sortCaption = new QLabel("Container class", this);
sortCaption->setAlignment( Qt::AlignCenter );
contextMenu->insertItem( sortCaption );
@@ -282,7 +294,8 @@
contextMenu->insertItem("Hash", this, SLOT( sortHash() ), 0, 3);
contextMenu->insertItem("M*N Vector", this, SLOT(sortMNVector()), 0, 4);
- QLabel *storageCaption = new QLabel("Storage class", this);
+ QLabel *storageCaption = new QLabel("Solution class", this);
+ storageCaption->setAlignment( Qt::AlignCenter );
contextMenu->insertItem( storageCaption );
contextMenu->insertItem("Matrix Solution", this, SLOT( storageMatrix() ), 0, 5);
contextMenu->insertItem("Int Solution", this, SLOT( storageInt() ), 0, 6);