/[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 2 by torben, Thu Jul 19 22:26:42 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 "solution.h"
35  #include "solutionvector.h"  #include "solutionvector.h"
36  #include "solutionlist.h"  #include "solutionlist.h"
37  #include "solutionhash.h"  #include "solutionhash.h"
# Line 37  Line 39 
39    
40  #include "config.h"  #include "config.h"
41    
42    #define MatrixSolution Solution
43    
44  QueensMain::QueensMain(QWidget *parent, const char *name)  QueensMain::QueensMain(QWidget *parent, const char *name)
45   : QDialog(parent, name)   : QDialog(parent, name)
46  {  {
# Line 74  QueensMain::QueensMain(QWidget *parent, Line 78  QueensMain::QueensMain(QWidget *parent,
78      m_sizeSelector->setValue( 8 );      m_sizeSelector->setValue( 8 );
79      m_board->setSize( 8 );      m_board->setSize( 8 );
80                    
81            m_storage = StorageMatrix;
82      m_sortalgo = SortList;      m_sortalgo = SortList;
83      m_solutions = NULL;      m_solutions = NULL;
84      m_queens = NULL;      m_queens = NULL;
# Line 150  void QueensMain::start() Line 155  void QueensMain::start()
155                      m_solutions = new SolutionMNVector(this);                      m_solutions = new SolutionMNVector(this);
156                      break;                      break;
157      }      }
158            
159            if (m_sol != NULL)
160                    delete m_sol;
161            
162            switch(this->m_storage) {
163                    case StorageInt:
164                            #warning MatrixSolution<=>IntSolution
165                            m_sol = new MatrixSolution(m_sizeSelector->value());
166                            break;
167                    case StorageMatrix:
168                            m_sol = new MatrixSolution(m_sizeSelector->value());
169                            break;
170            }
171    
172    
173      m_elapsed.start();      m_elapsed.start();
174      m_time.start();      m_time.start();
# Line 200  void QueensMain::finishedSearch() Line 219  void QueensMain::finishedSearch()
219  void QueensMain::showSolution()  void QueensMain::showSolution()
220  {  {
221          int index = m_list->currentItem();          int index = m_list->currentItem();
222          Solution sol = m_solutions->solution( index );          Solution* sol = m_solutions->solution( index );
223          m_board->setMatrix( sol );          m_board->setMatrix( *sol );
224  }  }
225    
226  void QueensMain::resize(int size)  void QueensMain::resize(int size)
# Line 254  void QueensMain::contextMenuEvent( QCont Line 273  void QueensMain::contextMenuEvent( QCont
273  {  {
274          QPopupMenu *contextMenu = new QPopupMenu( this );          QPopupMenu *contextMenu = new QPopupMenu( this );
275          contextMenu->setCheckable( true );          contextMenu->setCheckable( true );
276          QLabel *caption = new QLabel("<b><i>Sort algorithm</i></b>", this);          QLabel *sortCaption = new QLabel("<b><i>Sort algorithm</i></b>", this);
277          caption->setAlignment( Qt::AlignCenter );          sortCaption->setAlignment( Qt::AlignCenter );
278          contextMenu->insertItem( caption );          contextMenu->insertItem( sortCaption );
279    
280          contextMenu->insertItem("List", this, SLOT( sortList() ), 0, 1);          contextMenu->insertItem("List", this, SLOT( sortList() ), 0, 1);
281          contextMenu->insertItem("Vector", this, SLOT( sortVector() ), 0, 2);          contextMenu->insertItem("Vector", this, SLOT( sortVector() ), 0, 2);
282          contextMenu->insertItem("Hash", this, SLOT( sortHash() ), 0, 3);          contextMenu->insertItem("Hash", this, SLOT( sortHash() ), 0, 3);
283          contextMenu->insertItem("M*N Vector", this, SLOT(sortMNVector()), 0, 4);          contextMenu->insertItem("M*N Vector", this, SLOT(sortMNVector()), 0, 4);
284            
285            QLabel *storageCaption = new QLabel("<b><i>Storage class</i></b>", this);
286            contextMenu->insertItem( storageCaption );
287            contextMenu->insertItem("Matrix Solution", this, SLOT( storageMatrix() ), 0, 5);
288            contextMenu->insertItem("Int Solution", this, SLOT( storageInt() ), 0, 6);
289    
290    
291          switch (m_sortalgo) {          switch (m_sortalgo) {
292                  case SortList:                  case SortList:
# Line 278  void QueensMain::contextMenuEvent( QCont Line 303  void QueensMain::contextMenuEvent( QCont
303                          break;                          break;
304          }                }      
305                    
306            switch (m_storage) {
307                    case StorageMatrix:
308                            contextMenu->setItemChecked(5, true);
309                            break;
310                    case StorageInt:
311                            contextMenu->setItemChecked(6, true);
312                            break;
313            }
314    
315            
316          contextMenu->exec( event->globalPos() );          contextMenu->exec( event->globalPos() );
317          delete contextMenu;          delete contextMenu;
318  }  }
# Line 314  void QueensMain::sortMNVector() Line 349  void QueensMain::sortMNVector()
349          m_sortalgo = SortMNVector;          m_sortalgo = SortMNVector;
350  }  }
351    
352    void QueensMain::storageInt()
353    {
354            m_storage = StorageInt;
355    }
356    
357    void QueensMain::storageMatrix()
358    {
359            m_storage = StorageMatrix;
360    }
361    
362    

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

  ViewVC Help
Powered by ViewVC 1.1.20