/[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 2 by torben, Thu Jul 19 22:26:42 2007 UTC revision 13 by torben, Sun Jul 22 20:19: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 "solutionvector.h"  #include "solutionmatrix.h"
37  #include "solutionlist.h"  #include "solutionint.h"
38  #include "solutionhash.h"  
39  #include "solutionmnvector.h"  #include "containervector.h"
40    #include "containerlist.h"
41    #include "containerhash.h"
42    #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 78  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 = SortList;
88      m_solutions = NULL;      m_solutions = NULL;
89      m_queens = NULL;      m_queens = NULL;
90            m_sol = NULL;
91            
92      connect(m_quit,      connect(m_quit,
93          SIGNAL( clicked() ),          SIGNAL( clicked() ),
# Line 124  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 134  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)
157           delete m_solutions;           delete m_solutions;
158      switch (m_sortalgo) {      switch (m_sortalgo) {
159              case SortList:              case SortList:
160                      m_solutions = new SolutionList(this);                      m_solutions = new ContainerList(this);
161                      break;                      break;
162              case SortVector:              case SortVector:
163                      m_solutions = new SolutionVector(this);                      m_solutions = new ContainerVector(this);
164                      break;                      break;
165              case SortHash:              case SortHash:
166                      m_solutions = new SolutionHash(this);                      m_solutions = new ContainerHash(this);
167                      break;                      break;
168              case SortMNVector:              case SortMNVector:
169                      m_solutions = new SolutionMNVector(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 161  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    
188    
189      m_elapsed.start();      m_elapsed.start();
190      m_time.start();      m_time.start();
191      m_queens = new Queens(this, m_solutions, m_sizeSelector->value() ,false);      m_queens = new Queens(this, m_sol, m_solutions, m_sizeSelector->value() ,false);
192      m_queens->start();      m_queens->start();
193  }  }
194    
# Line 220  void QueensMain::showSolution() Line 236  void QueensMain::showSolution()
236  {  {
237          int index = m_list->currentItem();          int index = m_list->currentItem();
238          Solution* sol = m_solutions->solution( index );          Solution* sol = m_solutions->solution( index );
239          m_board->setMatrix( *sol );          m_board->setMatrix( sol );
240  }  }
241    
242  void QueensMain::resize(int size)  void QueensMain::resize(int size)
# Line 273  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 281  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 301  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 349  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 360  void QueensMain::storageMatrix() Line 387  void QueensMain::storageMatrix()
387  }  }
388    
389    
390    

Legend:
Removed from v.2  
changed lines
  Added in v.13

  ViewVC Help
Powered by ViewVC 1.1.20