/[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 5 by torben, Fri Jul 20 01:22:53 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"  
35  #include "solutionlist.h"  #include "solution.h"
36  #include "solutionhash.h"  #include "solutionmatrix.h"
37  #include "solutionmnvector.h"  #include "solutionint.h"
38    
39    #include "containervector.h"
40    #include "containerlist.h"
41    #include "containerhash.h"
42    #include "containermnvector.h"
43    
44  #include "config.h"  #include "config.h"
45    
46    
47    
48  QueensMain::QueensMain(QWidget *parent, const char *name)  QueensMain::QueensMain(QWidget *parent, const char *name)
49   : QDialog(parent, name)   : QDialog(parent, name)
50  {  {
# Line 74  QueensMain::QueensMain(QWidget *parent, Line 82  QueensMain::QueensMain(QWidget *parent,
82      m_sizeSelector->setValue( 8 );      m_sizeSelector->setValue( 8 );
83      m_board->setSize( 8 );      m_board->setSize( 8 );
84                    
85            m_storage = StorageMatrix;
86      m_sortalgo = SortList;      m_sortalgo = SortList;
87      m_solutions = NULL;      m_solutions = NULL;
88      m_queens = NULL;      m_queens = NULL;
89            m_sol = NULL;
90            
91      connect(m_quit,      connect(m_quit,
92          SIGNAL( clicked() ),          SIGNAL( clicked() ),
# Line 138  void QueensMain::start() Line 148  void QueensMain::start()
148           delete m_solutions;           delete m_solutions;
149      switch (m_sortalgo) {      switch (m_sortalgo) {
150              case SortList:              case SortList:
151                      m_solutions = new SolutionList(this);                      m_solutions = new ContainerList(this);
152                      break;                      break;
153              case SortVector:              case SortVector:
154                      m_solutions = new SolutionVector(this);                      m_solutions = new ContainerVector(this);
155                      break;                      break;
156              case SortHash:              case SortHash:
157                      m_solutions = new SolutionHash(this);                      m_solutions = new ContainerHash(this);
158                      break;                      break;
159              case SortMNVector:              case SortMNVector:
160                      m_solutions = new SolutionMNVector(this);                      m_solutions = new ContainerMNVector(this);
161                      break;                      break;
162      }      }
163            
164            if (m_sol != NULL)
165                    delete m_sol;
166            
167            switch(this->m_storage) {
168                    case StorageInt:
169                            m_sol = new SolutionInt(m_sizeSelector->value());
170                            break;
171                    case StorageMatrix:
172                            m_sol = new SolutionMatrix(m_sizeSelector->value());
173                            break;
174            }
175    
176    
177      m_elapsed.start();      m_elapsed.start();
178      m_time.start();      m_time.start();
179      m_queens = new Queens(this, m_solutions, m_sizeSelector->value() ,false);      m_queens = new Queens(this, m_sol, m_solutions, m_sizeSelector->value() ,false);
180      m_queens->start();      m_queens->start();
181  }  }
182    
# Line 200  void QueensMain::finishedSearch() Line 223  void QueensMain::finishedSearch()
223  void QueensMain::showSolution()  void QueensMain::showSolution()
224  {  {
225          int index = m_list->currentItem();          int index = m_list->currentItem();
226          Solution sol = m_solutions->solution( index );          Solution* sol = m_solutions->solution( index );
227          m_board->setMatrix( sol );          m_board->setMatrix( sol );
228  }  }
229    
# Line 254  void QueensMain::contextMenuEvent( QCont Line 277  void QueensMain::contextMenuEvent( QCont
277  {  {
278          QPopupMenu *contextMenu = new QPopupMenu( this );          QPopupMenu *contextMenu = new QPopupMenu( this );
279          contextMenu->setCheckable( true );          contextMenu->setCheckable( true );
280          QLabel *caption = new QLabel("<b><i>Sort algorithm</i></b>", this);          QLabel *sortCaption = new QLabel("<b><i>Sort algorithm</i></b>", this);
281          caption->setAlignment( Qt::AlignCenter );          sortCaption->setAlignment( Qt::AlignCenter );
282          contextMenu->insertItem( caption );          contextMenu->insertItem( sortCaption );
283    
284          contextMenu->insertItem("List", this, SLOT( sortList() ), 0, 1);          contextMenu->insertItem("List", this, SLOT( sortList() ), 0, 1);
285          contextMenu->insertItem("Vector", this, SLOT( sortVector() ), 0, 2);          contextMenu->insertItem("Vector", this, SLOT( sortVector() ), 0, 2);
286          contextMenu->insertItem("Hash", this, SLOT( sortHash() ), 0, 3);          contextMenu->insertItem("Hash", this, SLOT( sortHash() ), 0, 3);
287          contextMenu->insertItem("M*N Vector", this, SLOT(sortMNVector()), 0, 4);          contextMenu->insertItem("M*N Vector", this, SLOT(sortMNVector()), 0, 4);
288            
289            QLabel *storageCaption = new QLabel("<b><i>Storage class</i></b>", this);
290            contextMenu->insertItem( storageCaption );
291            contextMenu->insertItem("Matrix Solution", this, SLOT( storageMatrix() ), 0, 5);
292            contextMenu->insertItem("Int Solution", this, SLOT( storageInt() ), 0, 6);
293    
294    
295          switch (m_sortalgo) {          switch (m_sortalgo) {
296                  case SortList:                  case SortList:
# Line 278  void QueensMain::contextMenuEvent( QCont Line 307  void QueensMain::contextMenuEvent( QCont
307                          break;                          break;
308          }                }      
309                    
310            switch (m_storage) {
311                    case StorageMatrix:
312                            contextMenu->setItemChecked(5, true);
313                            break;
314                    case StorageInt:
315                            contextMenu->setItemChecked(6, true);
316                            break;
317            }
318    
319            
320          contextMenu->exec( event->globalPos() );          contextMenu->exec( event->globalPos() );
321          delete contextMenu;          delete contextMenu;
322  }  }
# Line 314  void QueensMain::sortMNVector() Line 353  void QueensMain::sortMNVector()
353          m_sortalgo = SortMNVector;          m_sortalgo = SortMNVector;
354  }  }
355    
356    void QueensMain::storageInt()
357    {
358            m_storage = StorageInt;
359    }
360    
361    void QueensMain::storageMatrix()
362    {
363            m_storage = StorageMatrix;
364    }
365    
366    

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

  ViewVC Help
Powered by ViewVC 1.1.20