/[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 8 by torben, Fri Jul 20 16:58:04 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 119  QueensMain::QueensMain(QWidget *parent, Line 129  QueensMain::QueensMain(QWidget *parent,
129  QueensMain::~QueensMain()  QueensMain::~QueensMain()
130  {  {
131      delete m_board;      delete m_board;
132            
133            if (m_solutions != NULL)
134                    delete m_solutions;
135            if (m_sol != NULL)
136                    delete m_sol;
137  }  }
138    
139  void QueensMain::start()  void QueensMain::start()
# Line 129  void QueensMain::start() Line 144  void QueensMain::start()
144      m_list->clear();      m_list->clear();
145      m_status->setText( QString("Searching ...") );      m_status->setText( QString("Searching ...") );
146            
147            m_board->setMatrix(0);
148            
149      if (m_queens != NULL) {      if (m_queens != NULL) {
150          m_queens->wait();          m_queens->wait();
151          delete m_queens;          delete m_queens;
152                    m_queens = 0;
153      }          }    
154            
155      if (m_solutions != NULL)      if (m_solutions != NULL)
156           delete m_solutions;           delete m_solutions;
157      switch (m_sortalgo) {      switch (m_sortalgo) {
158              case SortList:              case SortList:
159                      m_solutions = new SolutionList(this);                      m_solutions = new ContainerList(this);
160                      break;                      break;
161              case SortVector:              case SortVector:
162                      m_solutions = new SolutionVector(this);                      m_solutions = new ContainerVector(this);
163                      break;                      break;
164              case SortHash:              case SortHash:
165                      m_solutions = new SolutionHash(this);                      m_solutions = new ContainerHash(this);
166                      break;                      break;
167              case SortMNVector:              case SortMNVector:
168                      m_solutions = new SolutionMNVector(this);                      m_solutions = new ContainerMNVector(this);
169                      break;                      break;
170      }      }
171            
172            if (m_sol != NULL)
173                    delete m_sol;
174            
175            switch(this->m_storage) {
176                    case StorageInt:
177                            m_sol = new SolutionInt(m_sizeSelector->value());
178                            break;
179                    case StorageMatrix:
180                            m_sol = new SolutionMatrix(m_sizeSelector->value());
181                            break;
182            }
183    
184    
185      m_elapsed.start();      m_elapsed.start();
186      m_time.start();      m_time.start();
187      m_queens = new Queens(this, m_solutions, m_sizeSelector->value() ,false);      m_queens = new Queens(this, m_sol, m_solutions, m_sizeSelector->value() ,false);
188      m_queens->start();      m_queens->start();
189  }  }
190    
# Line 200  void QueensMain::finishedSearch() Line 231  void QueensMain::finishedSearch()
231  void QueensMain::showSolution()  void QueensMain::showSolution()
232  {  {
233          int index = m_list->currentItem();          int index = m_list->currentItem();
234          Solution sol = m_solutions->solution( index );          Solution* sol = m_solutions->solution( index );
235          m_board->setMatrix( sol );          m_board->setMatrix( sol );
236  }  }
237    
# Line 254  void QueensMain::contextMenuEvent( QCont Line 285  void QueensMain::contextMenuEvent( QCont
285  {  {
286          QPopupMenu *contextMenu = new QPopupMenu( this );          QPopupMenu *contextMenu = new QPopupMenu( this );
287          contextMenu->setCheckable( true );          contextMenu->setCheckable( true );
288          QLabel *caption = new QLabel("<b><i>Sort algorithm</i></b>", this);          QLabel *sortCaption = new QLabel("<b><i>Container class</i></b>", this);
289          caption->setAlignment( Qt::AlignCenter );          sortCaption->setAlignment( Qt::AlignCenter );
290          contextMenu->insertItem( caption );          contextMenu->insertItem( sortCaption );
291    
292          contextMenu->insertItem("List", this, SLOT( sortList() ), 0, 1);          contextMenu->insertItem("List", this, SLOT( sortList() ), 0, 1);
293          contextMenu->insertItem("Vector", this, SLOT( sortVector() ), 0, 2);          contextMenu->insertItem("Vector", this, SLOT( sortVector() ), 0, 2);
294          contextMenu->insertItem("Hash", this, SLOT( sortHash() ), 0, 3);          contextMenu->insertItem("Hash", this, SLOT( sortHash() ), 0, 3);
295          contextMenu->insertItem("M*N Vector", this, SLOT(sortMNVector()), 0, 4);          contextMenu->insertItem("M*N Vector", this, SLOT(sortMNVector()), 0, 4);
296            
297            QLabel *storageCaption = new QLabel("<b><i>Solution class</i></b>", this);
298            storageCaption->setAlignment( Qt::AlignCenter );
299            contextMenu->insertItem( storageCaption );
300            contextMenu->insertItem("Matrix Solution", this, SLOT( storageMatrix() ), 0, 5);
301            contextMenu->insertItem("Int Solution", this, SLOT( storageInt() ), 0, 6);
302    
303    
304          switch (m_sortalgo) {          switch (m_sortalgo) {
305                  case SortList:                  case SortList:
# Line 278  void QueensMain::contextMenuEvent( QCont Line 316  void QueensMain::contextMenuEvent( QCont
316                          break;                          break;
317          }                }      
318                    
319            switch (m_storage) {
320                    case StorageMatrix:
321                            contextMenu->setItemChecked(5, true);
322                            break;
323                    case StorageInt:
324                            contextMenu->setItemChecked(6, true);
325                            break;
326            }
327    
328            
329          contextMenu->exec( event->globalPos() );          contextMenu->exec( event->globalPos() );
330          delete contextMenu;          delete contextMenu;
331  }  }
# Line 314  void QueensMain::sortMNVector() Line 362  void QueensMain::sortMNVector()
362          m_sortalgo = SortMNVector;          m_sortalgo = SortMNVector;
363  }  }
364    
365    void QueensMain::storageInt()
366    {
367            m_storage = StorageInt;
368    }
369    
370    void QueensMain::storageMatrix()
371    {
372            m_storage = StorageMatrix;
373    }
374    
375    

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

  ViewVC Help
Powered by ViewVC 1.1.20