/[projects]/queensgui/src/queensmain.cpp
ViewVC logotype

Diff of /queensgui/src/queensmain.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 5 by torben, Fri Jul 20 01:22:53 2007 UTC revision 17 by torben, Sat Jul 28 08:49:40 2007 UTC
# Line 40  Line 40 
40  #include "containerlist.h"  #include "containerlist.h"
41  #include "containerhash.h"  #include "containerhash.h"
42  #include "containermnvector.h"  #include "containermnvector.h"
43    #include "containerminimalvector.h"
44    
45  #include "config.h"  #include "config.h"
46    
# Line 82  QueensMain::QueensMain(QWidget *parent, Line 83  QueensMain::QueensMain(QWidget *parent,
83      m_sizeSelector->setValue( 8 );      m_sizeSelector->setValue( 8 );
84      m_board->setSize( 8 );      m_board->setSize( 8 );
85                    
86          m_storage = StorageMatrix;          m_storage = StorageInt;
87      m_sortalgo = SortList;      m_sortalgo = SortMinimalVector;
88      m_solutions = NULL;      m_solutions = NULL;
89      m_queens = NULL;      m_queens = NULL;
90          m_sol = NULL;          m_sol = NULL;
# Line 129  QueensMain::QueensMain(QWidget *parent, Line 130  QueensMain::QueensMain(QWidget *parent,
130  QueensMain::~QueensMain()  QueensMain::~QueensMain()
131  {  {
132      delete m_board;      delete m_board;
133            
134            if (m_solutions != NULL)
135                    delete m_solutions;
136            if (m_sol != NULL)
137                    delete m_sol;
138  }  }
139    
140  void QueensMain::start()  void QueensMain::start()
# Line 139  void QueensMain::start() Line 145  void QueensMain::start()
145      m_list->clear();      m_list->clear();
146      m_status->setText( QString("Searching ...") );      m_status->setText( QString("Searching ...") );
147            
148            m_board->setMatrix(0);
149            
150      if (m_queens != NULL) {      if (m_queens != NULL) {
151          m_queens->wait();          m_queens->wait();
152          delete m_queens;          delete m_queens;
153                    m_queens = 0;
154      }          }    
155            
156      if (m_solutions != NULL)      if (m_solutions != NULL)
# Line 159  void QueensMain::start() Line 168  void QueensMain::start()
168              case SortMNVector:              case SortMNVector:
169                      m_solutions = new ContainerMNVector(this);                      m_solutions = new ContainerMNVector(this);
170                      break;                      break;
171                    case SortMinimalVector:
172                            m_solutions = new ContainerMinimalVector(this);
173                            break;
174      }      }
175                    
176          if (m_sol != NULL)          if (m_sol != NULL)
# Line 254  QString QueensMain::elapsed() Line 266  QString QueensMain::elapsed()
266    
267  void QueensMain::uniqueSolutions()  void QueensMain::uniqueSolutions()
268  {  {
269          m_totalcount = m_solutions->numSolutions();          m_totalcount = m_solutions->totalSolutions();
270          m_status->setText( QString("sorting ") + QString::number(m_totalcount,10).append(" solutions...") );          m_status->setText( QString("sorting ") + QString::number(m_totalcount,10).append(" solutions...") );
271                    
272          m_elapsed.restart();          m_elapsed.restart();
# Line 277  void QueensMain::contextMenuEvent( QCont Line 289  void QueensMain::contextMenuEvent( QCont
289  {  {
290          QPopupMenu *contextMenu = new QPopupMenu( this );          QPopupMenu *contextMenu = new QPopupMenu( this );
291          contextMenu->setCheckable( true );          contextMenu->setCheckable( true );
292          QLabel *sortCaption = new QLabel("<b><i>Sort algorithm</i></b>", this);          QLabel *sortCaption = new QLabel("<b><i>Container class</i></b>", this);
293          sortCaption->setAlignment( Qt::AlignCenter );          sortCaption->setAlignment( Qt::AlignCenter );
294          contextMenu->insertItem( sortCaption );          contextMenu->insertItem( sortCaption );
295    
# Line 285  void QueensMain::contextMenuEvent( QCont Line 297  void QueensMain::contextMenuEvent( QCont
297          contextMenu->insertItem("Vector", this, SLOT( sortVector() ), 0, 2);          contextMenu->insertItem("Vector", this, SLOT( sortVector() ), 0, 2);
298          contextMenu->insertItem("Hash", this, SLOT( sortHash() ), 0, 3);          contextMenu->insertItem("Hash", this, SLOT( sortHash() ), 0, 3);
299          contextMenu->insertItem("M*N Vector", this, SLOT(sortMNVector()), 0, 4);          contextMenu->insertItem("M*N Vector", this, SLOT(sortMNVector()), 0, 4);
300            contextMenu->insertItem("Minimal Vector", this, SLOT(sortMinimalVector()), 0, 5);
301                    
302          QLabel *storageCaption = new QLabel("<b><i>Storage class</i></b>", this);          QLabel *storageCaption = new QLabel("<b><i>Solution class</i></b>", this);
303            storageCaption->setAlignment( Qt::AlignCenter );
304          contextMenu->insertItem( storageCaption );          contextMenu->insertItem( storageCaption );
305          contextMenu->insertItem("Matrix Solution", this, SLOT( storageMatrix() ), 0, 5);          contextMenu->insertItem("Matrix Solution", this, SLOT( storageMatrix() ), 0, 6);
306          contextMenu->insertItem("Int Solution", this, SLOT( storageInt() ), 0, 6);          contextMenu->insertItem("Int Solution", this, SLOT( storageInt() ), 0, 7);
307    
308    
309          switch (m_sortalgo) {          switch (m_sortalgo) {
# Line 305  void QueensMain::contextMenuEvent( QCont Line 319  void QueensMain::contextMenuEvent( QCont
319                  case SortMNVector:                  case SortMNVector:
320                          contextMenu->setItemChecked( 4, true);                          contextMenu->setItemChecked( 4, true);
321                          break;                          break;
322                    case SortMinimalVector:
323                            contextMenu->setItemChecked( 5, true);
324                            break;
325          }                }      
326                    
327          switch (m_storage) {          switch (m_storage) {
328                  case StorageMatrix:                  case StorageMatrix:
329                          contextMenu->setItemChecked(5, true);                          contextMenu->setItemChecked(6, true);
330                          break;                          break;
331                  case StorageInt:                  case StorageInt:
332                          contextMenu->setItemChecked(6, true);                          contextMenu->setItemChecked(7, true);
333                          break;                          break;
334          }          }
335    
# Line 353  void QueensMain::sortMNVector() Line 370  void QueensMain::sortMNVector()
370          m_sortalgo = SortMNVector;          m_sortalgo = SortMNVector;
371  }  }
372    
373    void QueensMain::sortMinimalVector()
374    {
375            m_sortalgo = SortMinimalVector;
376    }
377    
378    
379  void QueensMain::storageInt()  void QueensMain::storageInt()
380  {  {
381          m_storage = StorageInt;          m_storage = StorageInt;
# Line 364  void QueensMain::storageMatrix() Line 387  void QueensMain::storageMatrix()
387  }  }
388    
389    
390    

Legend:
Removed from v.5  
changed lines
  Added in v.17

  ViewVC Help
Powered by ViewVC 1.1.20