/[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 6 by torben, Fri Jul 20 09:54:09 2007 UTC revision 655 by torben, Fri Apr 23 05:57:28 2010 UTC
# Line 20  Line 20 
20  #include <qapplication.h>  #include <qapplication.h>
21  #include <qlabel.h>  #include <qlabel.h>
22  #include <qlayout.h>  #include <qlayout.h>
23  #include <qlistbox.h>  #include <q3listbox.h>
24  #include <qpopupmenu.h>  #include <q3popupmenu.h>
25  #include <qpushbutton.h>  #include <qpushbutton.h>
26  #include <qspinbox.h>  #include <qspinbox.h>
27  #include <qstring.h>  #include <qstring.h>
# Line 29  Line 29 
29    
30    
31  #include "queensmain.h"  #include "queensmain.h"
32    //Added by qt3to4:
33    #include <Q3HBoxLayout>
34    #include <QContextMenuEvent>
35    #include <Q3VBoxLayout>
36  #include "board.h"  #include "board.h"
37  #include "queens.h"  #include "queens.h"
38    
# Line 40  Line 44 
44  #include "containerlist.h"  #include "containerlist.h"
45  #include "containerhash.h"  #include "containerhash.h"
46  #include "containermnvector.h"  #include "containermnvector.h"
47    #include "containerminimalvector.h"
48    
49  #include "config.h"  #include "config.h"
50    
# Line 48  Line 53 
53  QueensMain::QueensMain(QWidget *parent, const char *name)  QueensMain::QueensMain(QWidget *parent, const char *name)
54   : QDialog(parent, name)   : QDialog(parent, name)
55  {  {
56      QVBoxLayout *mainlayout = new QVBoxLayout( this );      Q3VBoxLayout *mainlayout = new Q3VBoxLayout( this );
57            
58      m_board = new Board( this );      m_board = new Board( this );
59                
# Line 57  QueensMain::QueensMain(QWidget *parent, Line 62  QueensMain::QueensMain(QWidget *parent,
62      m_stop = new QPushButton("Stop", this);      m_stop = new QPushButton("Stop", this);
63      m_stop->setEnabled( false );      m_stop->setEnabled( false );
64            
65      QHBoxLayout *upperlayout = new QHBoxLayout( mainlayout );      Q3HBoxLayout *upperlayout = new Q3HBoxLayout( mainlayout );
66      QVBoxLayout *left = new QVBoxLayout( upperlayout );      Q3VBoxLayout *left = new Q3VBoxLayout( upperlayout );
67    
68      upperlayout->add( m_board );              upperlayout->add( m_board );        
69      m_list = new QListBox( this );      m_list = new Q3ListBox( this );
70    
71      m_list->setMinimumWidth( 180 );      m_list->setMinimumWidth( 180 );
72      m_sizeSelector = new QSpinBox( this );      m_sizeSelector = new QSpinBox( this );
# Line 70  QueensMain::QueensMain(QWidget *parent, Line 75  QueensMain::QueensMain(QWidget *parent,
75      left->add( m_list );      left->add( m_list );
76      left->add( m_sizeSelector );      left->add( m_sizeSelector );
77            
78      QHBoxLayout *buttons = new QHBoxLayout( mainlayout );          Q3HBoxLayout *buttons = new Q3HBoxLayout( mainlayout );    
79      buttons->add( m_start );      buttons->add( m_start );
80      buttons->add( m_stop );      buttons->add( m_stop );
81      buttons->add( m_quit );      buttons->add( m_quit );
# Line 82  QueensMain::QueensMain(QWidget *parent, Line 87  QueensMain::QueensMain(QWidget *parent,
87      m_sizeSelector->setValue( 8 );      m_sizeSelector->setValue( 8 );
88      m_board->setSize( 8 );      m_board->setSize( 8 );
89                    
90          m_storage = StorageMatrix;          m_storage = StorageInt;
91      m_sortalgo = SortList;      m_sortalgo = SortMinimalVector;
92      m_solutions = NULL;      m_solutions = NULL;
93      m_queens = NULL;      m_queens = NULL;
94          m_sol = NULL;          m_sol = NULL;
# Line 129  QueensMain::QueensMain(QWidget *parent, Line 134  QueensMain::QueensMain(QWidget *parent,
134  QueensMain::~QueensMain()  QueensMain::~QueensMain()
135  {  {
136      delete m_board;      delete m_board;
137            
138            if (m_solutions != NULL)
139                    delete m_solutions;
140            if (m_sol != NULL)
141                    delete m_sol;
142  }  }
143    
144  void QueensMain::start()  void QueensMain::start()
# Line 144  void QueensMain::start() Line 154  void QueensMain::start()
154      if (m_queens != NULL) {      if (m_queens != NULL) {
155          m_queens->wait();          m_queens->wait();
156          delete m_queens;          delete m_queens;
157                    m_queens = 0;
158      }          }    
159            
160      if (m_solutions != NULL)      if (m_solutions != NULL)
# Line 161  void QueensMain::start() Line 172  void QueensMain::start()
172              case SortMNVector:              case SortMNVector:
173                      m_solutions = new ContainerMNVector(this);                      m_solutions = new ContainerMNVector(this);
174                      break;                      break;
175                    case SortMinimalVector:
176                            m_solutions = new ContainerMinimalVector(this);
177                            break;
178      }      }
179                    
180          if (m_sol != NULL)          if (m_sol != NULL)
181                  delete m_sol;                  delete m_sol;
182                    /*
183          switch(this->m_storage) {          switch(this->m_storage) {
184                  case StorageInt:                  case StorageInt:
185                          m_sol = new SolutionInt(m_sizeSelector->value());                          m_sol = new SolutionInt(m_sizeSelector->value());
# Line 173  void QueensMain::start() Line 187  void QueensMain::start()
187                  case StorageMatrix:                  case StorageMatrix:
188                          m_sol = new SolutionMatrix(m_sizeSelector->value());                          m_sol = new SolutionMatrix(m_sizeSelector->value());
189                          break;                          break;
190          }          }*/
191    
192        m_sol = new Solution( m_sizeSelector->value() );
193    
194    
195      m_elapsed.start();      m_elapsed.start();
# Line 205  void QueensMain::stop() Line 221  void QueensMain::stop()
221    
222  void QueensMain::foundSolution()  void QueensMain::foundSolution()
223  {  {
224          int num = m_solutions->numSolutions();          int num = m_solutions->totalSolutions();
225      if (m_elapsed.elapsed() > 500)      if (m_elapsed.elapsed() > 500)
226      {      {
227          m_status->setText( QString("Searching ... found ") + QString::number(num,10).append(" solutions") );          m_status->setText( QString("Searching ... found ") + QString::number(num,10).append(" solutions") );
# Line 256  QString QueensMain::elapsed() Line 272  QString QueensMain::elapsed()
272    
273  void QueensMain::uniqueSolutions()  void QueensMain::uniqueSolutions()
274  {  {
275          m_totalcount = m_solutions->numSolutions();          m_totalcount = m_solutions->totalSolutions();
276          m_status->setText( QString("sorting ") + QString::number(m_totalcount,10).append(" solutions...") );          m_status->setText( QString("sorting ") + QString::number(m_totalcount,10).append(" solutions...") );
277                    
278          m_elapsed.restart();          m_elapsed.restart();
# Line 277  void QueensMain::uniqueSolutions() Line 293  void QueensMain::uniqueSolutions()
293    
294  void QueensMain::contextMenuEvent( QContextMenuEvent *event)  void QueensMain::contextMenuEvent( QContextMenuEvent *event)
295  {  {
296          QPopupMenu *contextMenu = new QPopupMenu( this );          Q3PopupMenu *contextMenu = new Q3PopupMenu( this );
297          contextMenu->setCheckable( true );          contextMenu->setCheckable( true );
298          QLabel *sortCaption = new QLabel("<b><i>Sort algorithm</i></b>", this);          contextMenu->insertItem( "---Container class---" );
         sortCaption->setAlignment( Qt::AlignCenter );  
         contextMenu->insertItem( sortCaption );  
299    
300          contextMenu->insertItem("List", this, SLOT( sortList() ), 0, 1);          contextMenu->insertItem("List", this, SLOT( sortList() ), 0, 1);
301          contextMenu->insertItem("Vector", this, SLOT( sortVector() ), 0, 2);          contextMenu->insertItem("Vector", this, SLOT( sortVector() ), 0, 2);
302          contextMenu->insertItem("Hash", this, SLOT( sortHash() ), 0, 3);          contextMenu->insertItem("Hash", this, SLOT( sortHash() ), 0, 3);
303          contextMenu->insertItem("M*N Vector", this, SLOT(sortMNVector()), 0, 4);          contextMenu->insertItem("M*N Vector", this, SLOT(sortMNVector()), 0, 4);
304            contextMenu->insertItem("Minimal Vector", this, SLOT(sortMinimalVector()), 0, 5);
305                    
306          QLabel *storageCaption = new QLabel("<b><i>Storage class</i></b>", this);          contextMenu->insertItem( "---Solution Class---" );
307          contextMenu->insertItem( storageCaption );          contextMenu->insertItem("Matrix Solution", this, SLOT( storageMatrix() ), 0, 6);
308          contextMenu->insertItem("Matrix Solution", this, SLOT( storageMatrix() ), 0, 5);          contextMenu->insertItem("Int Solution", this, SLOT( storageInt() ), 0, 7);
         contextMenu->insertItem("Int Solution", this, SLOT( storageInt() ), 0, 6);  
309    
310    
311          switch (m_sortalgo) {          switch (m_sortalgo) {
# Line 307  void QueensMain::contextMenuEvent( QCont Line 321  void QueensMain::contextMenuEvent( QCont
321                  case SortMNVector:                  case SortMNVector:
322                          contextMenu->setItemChecked( 4, true);                          contextMenu->setItemChecked( 4, true);
323                          break;                          break;
324                    case SortMinimalVector:
325                            contextMenu->setItemChecked( 5, true);
326                            break;
327          }                }      
328                    
329          switch (m_storage) {          switch (m_storage) {
330                  case StorageMatrix:                  case StorageMatrix:
331                          contextMenu->setItemChecked(5, true);                          contextMenu->setItemChecked(6, true);
332                          break;                          break;
333                  case StorageInt:                  case StorageInt:
334                          contextMenu->setItemChecked(6, true);                          contextMenu->setItemChecked(7, true);
335                          break;                          break;
336          }          }
337    
# Line 355  void QueensMain::sortMNVector() Line 372  void QueensMain::sortMNVector()
372          m_sortalgo = SortMNVector;          m_sortalgo = SortMNVector;
373  }  }
374    
375    void QueensMain::sortMinimalVector()
376    {
377            m_sortalgo = SortMinimalVector;
378    }
379    
380    
381  void QueensMain::storageInt()  void QueensMain::storageInt()
382  {  {
383          m_storage = StorageInt;          m_storage = StorageInt;
# Line 366  void QueensMain::storageMatrix() Line 389  void QueensMain::storageMatrix()
389  }  }
390    
391    
392    

Legend:
Removed from v.6  
changed lines
  Added in v.655

  ViewVC Help
Powered by ViewVC 1.1.20