/[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 4 by torben, Thu Jul 19 23:44:01 2007 UTC revision 18 by torben, Sat Jul 28 08:56:43 2007 UTC
# Line 31  Line 31 
31  #include "queensmain.h"  #include "queensmain.h"
32  #include "board.h"  #include "board.h"
33  #include "queens.h"  #include "queens.h"
34    
35  #include "solution.h"  #include "solution.h"
36    #include "solutionmatrix.h"
37    #include "solutionint.h"
38    
39  #include "containervector.h"  #include "containervector.h"
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    
47  #define MatrixSolution Solution  
48    
49  QueensMain::QueensMain(QWidget *parent, const char *name)  QueensMain::QueensMain(QWidget *parent, const char *name)
50   : QDialog(parent, name)   : QDialog(parent, name)
# Line 79  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 126  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 136  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 156  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 163  void QueensMain::start() Line 178  void QueensMain::start()
178                    
179          switch(this->m_storage) {          switch(this->m_storage) {
180                  case StorageInt:                  case StorageInt:
181                          #warning MatrixSolution<=>IntSolution                          m_sol = new SolutionInt(m_sizeSelector->value());
                         m_sol = new MatrixSolution(m_sizeSelector->value());  
182                          break;                          break;
183                  case StorageMatrix:                  case StorageMatrix:
184                          m_sol = new MatrixSolution(m_sizeSelector->value());                          m_sol = new SolutionMatrix(m_sizeSelector->value());
185                          break;                          break;
186          }          }
187    
# Line 201  void QueensMain::stop() Line 215  void QueensMain::stop()
215    
216  void QueensMain::foundSolution()  void QueensMain::foundSolution()
217  {  {
218          int num = m_solutions->numSolutions();          int num = m_solutions->totalSolutions();
219      if (m_elapsed.elapsed() > 500)      if (m_elapsed.elapsed() > 500)
220      {      {
221          m_status->setText( QString("Searching ... found ") + QString::number(num,10).append(" solutions") );          m_status->setText( QString("Searching ... found ") + QString::number(num,10).append(" solutions") );
# Line 252  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 275  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 283  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 303  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 351  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 362  void QueensMain::storageMatrix() Line 387  void QueensMain::storageMatrix()
387  }  }
388    
389    
390    

Legend:
Removed from v.4  
changed lines
  Added in v.18

  ViewVC Help
Powered by ViewVC 1.1.20