/[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 1 by torben, Thu Jul 19 21:34:15 2007 UTC revision 4 by torben, Thu Jul 19 23:44:01 2007 UTC
# Line 27  Line 27 
27  #include <qstring.h>  #include <qstring.h>
28    
29    
30    
31  #include "queensmain.h"  #include "queensmain.h"
32  #include "board.h"  #include "board.h"
33  #include "queens.h"  #include "queens.h"
34  #include "solutionvector.h"  #include "solution.h"
35  #include "solutionlist.h"  
36  #include "solutionhash.h"  #include "containervector.h"
37  #include "solutionmnvector.h"  #include "containerlist.h"
38    #include "containerhash.h"
39    #include "containermnvector.h"
40    
41  #include "config.h"  #include "config.h"
42    
43    #define MatrixSolution Solution
44    
45  QueensMain::QueensMain(QWidget *parent, const char *name)  QueensMain::QueensMain(QWidget *parent, const char *name)
46   : QDialog(parent, name)   : QDialog(parent, name)
47  {  {
# Line 74  QueensMain::QueensMain(QWidget *parent, Line 79  QueensMain::QueensMain(QWidget *parent,
79      m_sizeSelector->setValue( 8 );      m_sizeSelector->setValue( 8 );
80      m_board->setSize( 8 );      m_board->setSize( 8 );
81                    
82            m_storage = StorageMatrix;
83      m_sortalgo = SortList;      m_sortalgo = SortList;
84      m_solutions = NULL;      m_solutions = NULL;
85      m_queens = NULL;      m_queens = NULL;
86            m_sol = NULL;
87            
88      connect(m_quit,      connect(m_quit,
89          SIGNAL( clicked() ),          SIGNAL( clicked() ),
# Line 138  void QueensMain::start() Line 145  void QueensMain::start()
145           delete m_solutions;           delete m_solutions;
146      switch (m_sortalgo) {      switch (m_sortalgo) {
147              case SortList:              case SortList:
148                      m_solutions = new SolutionList(this);                      m_solutions = new ContainerList(this);
149                      break;                      break;
150              case SortVector:              case SortVector:
151                      m_solutions = new SolutionVector(this);                      m_solutions = new ContainerVector(this);
152                      break;                      break;
153              case SortHash:              case SortHash:
154                      m_solutions = new SolutionHash(this);                      m_solutions = new ContainerHash(this);
155                      break;                      break;
156              case SortMNVector:              case SortMNVector:
157                      m_solutions = new SolutionMNVector(this);                      m_solutions = new ContainerMNVector(this);
158                      break;                      break;
159      }      }
160            
161            if (m_sol != NULL)
162                    delete m_sol;
163            
164            switch(this->m_storage) {
165                    case StorageInt:
166                            #warning MatrixSolution<=>IntSolution
167                            m_sol = new MatrixSolution(m_sizeSelector->value());
168                            break;
169                    case StorageMatrix:
170                            m_sol = new MatrixSolution(m_sizeSelector->value());
171                            break;
172            }
173    
174    
175      m_elapsed.start();      m_elapsed.start();
176      m_time.start();      m_time.start();
177      m_queens = new Queens(this, m_solutions, m_sizeSelector->value() ,false);      m_queens = new Queens(this, m_sol, m_solutions, m_sizeSelector->value() ,false);
178      m_queens->start();      m_queens->start();
179  }  }
180    
# Line 200  void QueensMain::finishedSearch() Line 221  void QueensMain::finishedSearch()
221  void QueensMain::showSolution()  void QueensMain::showSolution()
222  {  {
223          int index = m_list->currentItem();          int index = m_list->currentItem();
224          Solution sol = m_solutions->solution( index );          Solution* sol = m_solutions->solution( index );
225          m_board->setMatrix( sol );          m_board->setMatrix( sol );
226  }  }
227    
# Line 254  void QueensMain::contextMenuEvent( QCont Line 275  void QueensMain::contextMenuEvent( QCont
275  {  {
276          QPopupMenu *contextMenu = new QPopupMenu( this );          QPopupMenu *contextMenu = new QPopupMenu( this );
277          contextMenu->setCheckable( true );          contextMenu->setCheckable( true );
278          QLabel *caption = new QLabel("<b><i>Sort algorithm</i></b>", this);          QLabel *sortCaption = new QLabel("<b><i>Sort algorithm</i></b>", this);
279          caption->setAlignment( Qt::AlignCenter );          sortCaption->setAlignment( Qt::AlignCenter );
280          contextMenu->insertItem( caption );          contextMenu->insertItem( sortCaption );
281    
282          contextMenu->insertItem("List", this, SLOT( sortList() ), 0, 1);          contextMenu->insertItem("List", this, SLOT( sortList() ), 0, 1);
283          contextMenu->insertItem("Vector", this, SLOT( sortVector() ), 0, 2);          contextMenu->insertItem("Vector", this, SLOT( sortVector() ), 0, 2);
284          contextMenu->insertItem("Hash", this, SLOT( sortHash() ), 0, 3);          contextMenu->insertItem("Hash", this, SLOT( sortHash() ), 0, 3);
285          contextMenu->insertItem("M*N Vector", this, SLOT(sortMNVector()), 0, 4);          contextMenu->insertItem("M*N Vector", this, SLOT(sortMNVector()), 0, 4);
286            
287            QLabel *storageCaption = new QLabel("<b><i>Storage class</i></b>", this);
288            contextMenu->insertItem( storageCaption );
289            contextMenu->insertItem("Matrix Solution", this, SLOT( storageMatrix() ), 0, 5);
290            contextMenu->insertItem("Int Solution", this, SLOT( storageInt() ), 0, 6);
291    
292    
293          switch (m_sortalgo) {          switch (m_sortalgo) {
294                  case SortList:                  case SortList:
# Line 278  void QueensMain::contextMenuEvent( QCont Line 305  void QueensMain::contextMenuEvent( QCont
305                          break;                          break;
306          }                }      
307                    
308            switch (m_storage) {
309                    case StorageMatrix:
310                            contextMenu->setItemChecked(5, true);
311                            break;
312                    case StorageInt:
313                            contextMenu->setItemChecked(6, true);
314                            break;
315            }
316    
317            
318          contextMenu->exec( event->globalPos() );          contextMenu->exec( event->globalPos() );
319          delete contextMenu;          delete contextMenu;
320  }  }
# Line 314  void QueensMain::sortMNVector() Line 351  void QueensMain::sortMNVector()
351          m_sortalgo = SortMNVector;          m_sortalgo = SortMNVector;
352  }  }
353    
354    void QueensMain::storageInt()
355    {
356            m_storage = StorageInt;
357    }
358    
359    void QueensMain::storageMatrix()
360    {
361            m_storage = StorageMatrix;
362    }
363    
364    

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

  ViewVC Help
Powered by ViewVC 1.1.20