--- queensgui/src/queensmain.cpp 2007/07/19 23:44:01 4 +++ queensgui/src/queensmain.cpp 2009/09/16 18:53:22 327 @@ -20,8 +20,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -29,23 +29,31 @@ #include "queensmain.h" +//Added by qt3to4: +#include +#include +#include #include "board.h" #include "queens.h" + #include "solution.h" +#include "solutionmatrix.h" +#include "solutionint.h" #include "containervector.h" #include "containerlist.h" #include "containerhash.h" #include "containermnvector.h" +#include "containerminimalvector.h" #include "config.h" -#define MatrixSolution Solution + QueensMain::QueensMain(QWidget *parent, const char *name) : QDialog(parent, name) { - QVBoxLayout *mainlayout = new QVBoxLayout( this ); + Q3VBoxLayout *mainlayout = new Q3VBoxLayout( this ); m_board = new Board( this ); @@ -54,11 +62,11 @@ m_stop = new QPushButton("Stop", this); m_stop->setEnabled( false ); - QHBoxLayout *upperlayout = new QHBoxLayout( mainlayout ); - QVBoxLayout *left = new QVBoxLayout( upperlayout ); + Q3HBoxLayout *upperlayout = new Q3HBoxLayout( mainlayout ); + Q3VBoxLayout *left = new Q3VBoxLayout( upperlayout ); upperlayout->add( m_board ); - m_list = new QListBox( this ); + m_list = new Q3ListBox( this ); m_list->setMinimumWidth( 180 ); m_sizeSelector = new QSpinBox( this ); @@ -67,7 +75,7 @@ left->add( m_list ); left->add( m_sizeSelector ); - QHBoxLayout *buttons = new QHBoxLayout( mainlayout ); + Q3HBoxLayout *buttons = new Q3HBoxLayout( mainlayout ); buttons->add( m_start ); buttons->add( m_stop ); buttons->add( m_quit ); @@ -79,8 +87,8 @@ m_sizeSelector->setValue( 8 ); m_board->setSize( 8 ); - m_storage = StorageMatrix; - m_sortalgo = SortList; + m_storage = StorageInt; + m_sortalgo = SortMinimalVector; m_solutions = NULL; m_queens = NULL; m_sol = NULL; @@ -126,6 +134,11 @@ QueensMain::~QueensMain() { delete m_board; + + if (m_solutions != NULL) + delete m_solutions; + if (m_sol != NULL) + delete m_sol; } void QueensMain::start() @@ -136,9 +149,12 @@ 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) @@ -156,6 +172,9 @@ case SortMNVector: m_solutions = new ContainerMNVector(this); break; + case SortMinimalVector: + m_solutions = new ContainerMinimalVector(this); + break; } if (m_sol != NULL) @@ -163,11 +182,10 @@ 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; } @@ -201,7 +219,7 @@ void QueensMain::foundSolution() { - int num = m_solutions->numSolutions(); + int num = m_solutions->totalSolutions(); if (m_elapsed.elapsed() > 500) { m_status->setText( QString("Searching ... found ") + QString::number(num,10).append(" solutions") ); @@ -252,7 +270,7 @@ void QueensMain::uniqueSolutions() { - m_totalcount = m_solutions->numSolutions(); + m_totalcount = m_solutions->totalSolutions(); m_status->setText( QString("sorting ") + QString::number(m_totalcount,10).append(" solutions...") ); m_elapsed.restart(); @@ -273,21 +291,19 @@ void QueensMain::contextMenuEvent( QContextMenuEvent *event) { - QPopupMenu *contextMenu = new QPopupMenu( this ); + Q3PopupMenu *contextMenu = new Q3PopupMenu( this ); contextMenu->setCheckable( true ); - QLabel *sortCaption = new QLabel("Sort algorithm", this); - sortCaption->setAlignment( Qt::AlignCenter ); - contextMenu->insertItem( sortCaption ); + contextMenu->insertItem( "---Container class---" ); 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); + contextMenu->insertItem("Minimal Vector", this, SLOT(sortMinimalVector()), 0, 5); - 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); + contextMenu->insertItem( "---Solution Class---" ); + contextMenu->insertItem("Matrix Solution", this, SLOT( storageMatrix() ), 0, 6); + contextMenu->insertItem("Int Solution", this, SLOT( storageInt() ), 0, 7); switch (m_sortalgo) { @@ -303,14 +319,17 @@ case SortMNVector: contextMenu->setItemChecked( 4, true); break; + case SortMinimalVector: + contextMenu->setItemChecked( 5, true); + break; } switch (m_storage) { case StorageMatrix: - contextMenu->setItemChecked(5, true); + contextMenu->setItemChecked(6, true); break; case StorageInt: - contextMenu->setItemChecked(6, true); + contextMenu->setItemChecked(7, true); break; } @@ -351,6 +370,12 @@ m_sortalgo = SortMNVector; } +void QueensMain::sortMinimalVector() +{ + m_sortalgo = SortMinimalVector; +} + + void QueensMain::storageInt() { m_storage = StorageInt; @@ -362,3 +387,4 @@ } +