--- queensgui/src/queensmain.cpp 2007/07/19 21:34:15 1 +++ queensgui/src/queensmain.cpp 2007/07/19 23:44:01 4 @@ -27,16 +27,21 @@ #include + #include "queensmain.h" #include "board.h" #include "queens.h" -#include "solutionvector.h" -#include "solutionlist.h" -#include "solutionhash.h" -#include "solutionmnvector.h" +#include "solution.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) { @@ -74,9 +79,11 @@ m_sizeSelector->setValue( 8 ); m_board->setSize( 8 ); + m_storage = StorageMatrix; m_sortalgo = SortList; m_solutions = NULL; m_queens = NULL; + m_sol = NULL; connect(m_quit, SIGNAL( clicked() ), @@ -138,22 +145,36 @@ 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; } + + if (m_sol != NULL) + delete m_sol; + + switch(this->m_storage) { + case StorageInt: + #warning MatrixSolution<=>IntSolution + m_sol = new MatrixSolution(m_sizeSelector->value()); + break; + case StorageMatrix: + m_sol = new MatrixSolution(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(); } @@ -200,7 +221,7 @@ void QueensMain::showSolution() { int index = m_list->currentItem(); - Solution sol = m_solutions->solution( index ); + Solution* sol = m_solutions->solution( index ); m_board->setMatrix( sol ); } @@ -254,14 +275,20 @@ { QPopupMenu *contextMenu = new QPopupMenu( this ); contextMenu->setCheckable( true ); - QLabel *caption = new QLabel("Sort algorithm", this); - caption->setAlignment( Qt::AlignCenter ); - contextMenu->insertItem( caption ); + QLabel *sortCaption = new QLabel("Sort algorithm", this); + sortCaption->setAlignment( Qt::AlignCenter ); + contextMenu->insertItem( sortCaption ); contextMenu->insertItem("List", this, SLOT( sortList() ), 0, 1); contextMenu->insertItem("Vector", this, SLOT( sortVector() ), 0, 2); 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); + contextMenu->insertItem( storageCaption ); + contextMenu->insertItem("Matrix Solution", this, SLOT( storageMatrix() ), 0, 5); + contextMenu->insertItem("Int Solution", this, SLOT( storageInt() ), 0, 6); + switch (m_sortalgo) { case SortList: @@ -278,6 +305,16 @@ break; } + switch (m_storage) { + case StorageMatrix: + contextMenu->setItemChecked(5, true); + break; + case StorageInt: + contextMenu->setItemChecked(6, true); + break; + } + + contextMenu->exec( event->globalPos() ); delete contextMenu; } @@ -314,3 +351,14 @@ m_sortalgo = SortMNVector; } +void QueensMain::storageInt() +{ + m_storage = StorageInt; +} + +void QueensMain::storageMatrix() +{ + m_storage = StorageMatrix; +} + +