--- queensgui/src/queensmain.cpp 2007/07/19 21:34:15 1 +++ queensgui/src/queensmain.cpp 2007/07/19 22:26:42 2 @@ -27,9 +27,11 @@ #include + #include "queensmain.h" #include "board.h" #include "queens.h" +#include "solution.h" #include "solutionvector.h" #include "solutionlist.h" #include "solutionhash.h" @@ -37,6 +39,8 @@ #include "config.h" +#define MatrixSolution Solution + QueensMain::QueensMain(QWidget *parent, const char *name) : QDialog(parent, name) { @@ -74,6 +78,7 @@ m_sizeSelector->setValue( 8 ); m_board->setSize( 8 ); + m_storage = StorageMatrix; m_sortalgo = SortList; m_solutions = NULL; m_queens = NULL; @@ -150,6 +155,20 @@ m_solutions = new SolutionMNVector(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(); @@ -200,8 +219,8 @@ void QueensMain::showSolution() { int index = m_list->currentItem(); - Solution sol = m_solutions->solution( index ); - m_board->setMatrix( sol ); + Solution* sol = m_solutions->solution( index ); + m_board->setMatrix( *sol ); } void QueensMain::resize(int size) @@ -254,14 +273,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 +303,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 +349,14 @@ m_sortalgo = SortMNVector; } +void QueensMain::storageInt() +{ + m_storage = StorageInt; +} + +void QueensMain::storageMatrix() +{ + m_storage = StorageMatrix; +} + +